atomicdata-dev / atomic-data-docs

Atomic Data is a specification to make it easier to exchange data.
https://docs.atomicdata.dev
MIT License
17 stars 7 forks source link

Have a way to easily validate JSON-AD #110

Open joepio opened 2 years ago

joepio commented 2 years ago

I'd like users to be able to validate JSON-AD in their browsers. It should not be too hard to build this, but it would be useful to have this and link to it from the Atomic Data Docs.

Approaches:

Part of atomic-data-rust (Rust, CLI + Server)

Part of @tomic/lib (Typescript, data-browser)

jonassmedegaard commented 2 years ago

Please consider writing this validation logic as a separate project, with a library and a simple command-line application. Atomic Server can then integrate the library for that endpoint you envision (without pulling in CLI-specific dependencies), while the command-line tool can be used e.g. in a git commit hook where you would not want to require online access for a syntax validator.

joepio commented 2 years ago

It will be an extremely small wrapper around functions that already exist in atomic_lib, so it will be part of that library. But I can also add it as a command to atomic-cli (which is pretty lightweight, and uses atomic_lib), that sounds reasonable.

jonassmedegaard commented 2 years ago

ok, I thought of atomic-cli as a helper tool for Atomic Server, but realize now that helper functions like --initialize are instead tied to command-line tool atomic-server.

Makes sense to add this to atomic-cli then, I guess.

For options convenient for using atomic-cli as a Code Quality Meta Tool, I recommend to read this blog post which was a precursor for its author abanding his old perl-based project tidyall and begin new Rust-based project precious.

joepio commented 2 years ago

Thanks! It also make sense to keep Git management in consideration here, since running these checks on commit would prevent issues #97

jonassmedegaard commented 2 years ago

For in-browser validating the ideal would again be to not depend on network access, by implementing a validator in JavaScript and shipping that both as an NPM library and wrapped as a plugin for Mozilla- and Chromium-based browsers.

jonassmedegaard commented 2 years ago

...or use that fancy WASM-based sandboxed compilation you have talked about, I guess :-)

joepio commented 2 years ago

For in-browser validating the ideal would again be to not depend on network access, by implementing a validator in JavaScript and shipping that both as an NPM library and wrapped as a plugin for Mozilla- and Chromium-based browsers.

It would still kind of depend on net access, though, since it will need to check if the properties are online and match the datatypes.

...or use that fancy WASM-based sandboxed compilation you have talked about, I guess :-)

Would be the coolest, but I don't have any of that working yet...

I think the rust approach seems the most realistic, although adding a validate function in @tomic/lib typescript is probably not that much extra work.

jonassmedegaard commented 2 years ago

It would still kind of depend on net access, though, since it will need to check if the properties are online and match the datatypes.

Ah, right. That information could be cached, though - spewing a warning if cached data becomes stale (and either option --no-network or env variable ATOMIC_NO_NETWORK is set, or auto-refresh of cache fails e.g. at a failing or missing network connection).