Data: optional per-collection JSON Schema validation#77
Merged
Conversation
Let a collection opt into validation by declaring a JSON Schema; writes that
violate it fail with 422 and a structured errors list. Collections stay
schemaless by default — zero-config is preserved.
- GET/PUT/DELETE /v1/data/:collection/schema (key-gated, never anonymous).
A schema that doesn't compile is a 400; a document that violates a set schema
is a 422 ({ error:'validation_failed', errors:[{field,message}] }).
- Validation covers create, bulk (all-or-nothing, checked up front), PUT
(replace), and PATCH (the merged result is validated). Restore/import is
intentionally exempt.
- SchemaStore compiles with Ajv and caches the compiled validator with a short
TTL, so validation is correct across processes without a DB read per write
(the setting process refreshes its own cache immediately). Backed by a new
collection_schemas table (both SQLite and Postgres).
- SDK: data(c).getSchema()/setSchema()/clearSchema() (+ getIndexes/setIndexes,
which were missing); types in sdk.d.ts. Discovery advertises the endpoint.
Verification: 63/63 SQLite (+ a test covering valid/invalid create, PATCH,
all-or-nothing bulk, malformed-schema 400, and clearing), 45/45 Postgres 16,
Redis suite still green. Docs updated (README, /docs).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Optional per-collection JSON Schema validation. A collection opts in by declaring a schema; writes that violate it then fail with
422and a structured error list. Collections stay schemaless by default, so zero-config is untouched.How
GET/PUT/DELETE /v1/data/:collection/schema(key-gated, never anonymous). A schema that doesn't compile →400; a document that violates a set schema →422{ error:'validation_failed', errors:[{ field, message }] }.importis intentionally exempt (trusted data, schema may have changed).SchemaStorecompiles with Ajv and caches the compiled validator with a short TTL, so validation stays correct across processes without a DB read on every write (the process that sets a schema refreshes its own cache immediately → single-VM is never stale). Backed by a newcollection_schemastable on both SQLite and Postgres.data(c).getSchema()/setSchema()/clearSchema()— plusgetIndexes()/setIndexes(), which were missing from the SDK when indexes shipped. Types insdk.d.ts; discovery (/v1) advertises the endpoint.Verification
422with errors)→PATCHviolation→all-or-nothing bulk rejection→malformed-schema400→clear→freeform again./docs(REST table).Next per your steer: cursor pagination, built on the declared indexes.
https://claude.ai/code/session_018efxvWw3MRjdtvE5xgBqya
Generated by Claude Code