4 ms·
This looks super promising, but I'm a coding and Cuelang newbie. I'm confused as to how to use it. Let's say I'm building a tool for people to upload a lot of
by yawnxyz 5y ago
This looks super promising, but I'm a coding and Cuelang newbie. I'm confused as to how to use it.
Let's say I'm building a tool for people to upload a lot of data, in the form of CSVs and JSON files, POSTing them into my node API. I'm writing those files to a document database.
I'm trying to figure out how to use Cue in this process. I'm planning on using JSON Schema definitions, and Ajv as the validator — would I purely be using Cue to generate and maintain my JSON schemas, which I use to validate with Ajv?
Or can Cue be used more directly in my node API, e.g. using some npm validation tool that lets me use Cue to validate a bunch of CSV files converted to JSON?
Thanks so much in advance!
- 0xFACEFEED 5y agoI think Cue is more aimed at configuration file management. Think Kubernetes, Ansible, Puppet, Chef, and Salt. There you have tens to hundreds to thousands of YAML/JSON files that describe your server configuration and there's no way to validate any of it out of the box. Even more broadly, most configuration files in general don't have any validation. For example things in the /etc/ directory on a Linux server. That fits under configuration file management too. I'm not sure about your specific use case, but if you haven't considered something like Protocol Buffers -- I'd highly recommend at least looking into it. JSON sucks, sometimes.
- verdverm 5y agoExecute is in the name. There is a DAG engine (tool/flow) that automatically calculated dependencies. It powers the scripting layer and https://dagger.io https://dagger.io
- Kinrany 5y agoIn theory you could use CUE to validate requests and insert defaults and implied data, replacing Ajv. 1. Get the CUE value representing the schema endpoint 2. Convert the JSON request into a CUE value 3. Unify the request with the schema If unification fails, return 400 Bad Request. If it succeeds, deserialize the resulting third CUE value into a programming language value. CUE will fill fields missing from JSON by either using the default values from schema or inferring fields that have only one possible value (which may depend on all the other fields of request and schema).
- verdverm 5y agoYou can generate OpenAPI from CUE, though the path section is not done yet. You can also compile CUE to wasm, but CUE is still not concurrency safe yet, so you'd have to lock certain (an evolving set) of the function calls. If you shell out, converting csv to json is pretty straight forward. Good questions for GitHub Discussions https://github.com/cue-lang/cue/discussions https://github.com/cue-lang/cue/discussions