Dataset kind document schemas in Rust (vs Zod)
Research for Finalize Dataset kind schema packaging.
Question: what can the Host and App authors use instead of TypeScript Zod for JSON Schema authoring/validation?
Executive finding
Do not run TypeScript on the Host. Treat JSON Schema documents as the interchange format in the App package. Validate in Rust with a JSON Schema crate. Author schemas as:
- hand-written
.schema.json, or - schemars from Rust types (Host standard kinds / Rust Apps), or
- any language that emits JSON Schema at build time (including Zod offline for TS App authors — Host never executes Zod).
WIT/wit-bindgen type-check the Wasm boundary; they do not replace JSON Schema for stored record validation.
Roles (no TS required on Host)
| Role | Tooling | Runs where |
|---|---|---|
| Validate records | jsonschema Rust crate |
Host (and optionally App CI) |
| Author schema from Rust types | schemars #[derive(JsonSchema)] → JSON Schema 2020-12-ish |
Host repo / Rust App build |
| Author schema from JSON Schema → Rust types | typify (Draft-7 oriented historically; 2020-12 improving) |
Optional codegen for Host adapters |
| Guest API types | WIT + wit-bindgen / Wasmtime bindgen! |
Component boundary — not document validation |
| TS App authors (optional) | Zod → JSON Schema export in their toolchain | App package build only |
Zod is fine as an App-side authoring DX for TypeScript App developers; the shipped artifact is still JSON Schema. The Host only needs Rust validation.
jsonschema (Rust validator)
- High-performance validator; draft detection; reusable
validator_for; structured errors (docs.rs/jsonschema). - Fits: load kind’s schema at install, validate every write against it.
- Supports
additionalProperties/ open objects — enables “strict common fields + loose JSON bag” patterns.
schemars (Rust → JSON Schema)
#[derive(JsonSchema)]+ Serde attributes → schema document (docs.rs/schemars).- Defaults aim at JSON Schema 2020-12.
- Ideal for Host-defined standard kinds (contacts, events) maintained as Rust structs in the Host repo, then exported as schemas Apps/Externals see.
- Not a substitute for accepting App-shipped
.schema.jsonfor custom kinds.
typify (JSON Schema → Rust)
- Oxide-origin tooling: compile schemas to Rust types for typed Host code (typify).
- Useful for adapters; validation should still use
jsonschema(or serde into generated types). - Draft coverage historically Draft-7-heavy; treat as helper, not the interchange format.
WIT vs document schema
- WIT: Host↔App function/record types at the component boundary (
wit-bindgen). - JSON Schema: persistent Dataset documents (validation, Shell forms, CardDAV/CalDAV field maps).
- There is no BA-standard “WIT is the only schema”; niche converters (e.g. WIT record→JSON Schema in some crates) exist but dual representation remains the right concept — matches ticket 06.
Recommendation for the concept lock
- Interchange: JSON Schema in the package (pin draft later, prefer 2020-12).
- Host runtime: validate with Rust
jsonschema. - Framework support without TS: schemars for Host standard kinds; Apps may ship JSON Schema from any generator.
- Mention Zod only as optional guest App authoring for TS Apps — never Host dependency.