Skip to content

Data: optional per-collection JSON Schema validation#77

Merged
jwicks31 merged 1 commit into
mainfrom
claude/collection-schemas
Jun 13, 2026
Merged

Data: optional per-collection JSON Schema validation#77
jwicks31 merged 1 commit into
mainfrom
claude/collection-schemas

Conversation

@jwicks31

Copy link
Copy Markdown
Owner

What

Optional per-collection JSON Schema validation. A collection opts in by declaring a schema; writes that violate it then fail with 422 and 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 }] }.
  • Validation covers create, bulk (all-or-nothing — the whole batch is checked before any insert), PUT (replace), and PATCH (the merged result is validated). Restore/import is intentionally exempt (trusted data, schema may have changed).
  • SchemaStore compiles 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 new collection_schemas table on both SQLite and Postgres.
  • SDK: data(c).getSchema() / setSchema() / clearSchema() — plus getIndexes() / setIndexes(), which were missing from the SDK when indexes shipped. Types in sdk.d.ts; discovery (/v1) advertises the endpoint.

Verification

  • SQLite 63/63 including a new test: schemaless→declare→valid create→invalid create (422 with errors)→PATCH violation→all-or-nothing bulk rejection→malformed-schema 400→clear→freeform again.
  • Postgres 45/45 (Postgres 16); the Redis suite stays green.
  • Docs updated: README (data section) and /docs (REST table).

Next per your steer: cursor pagination, built on the declared indexes.

https://claude.ai/code/session_018efxvWw3MRjdtvE5xgBqya


Generated by Claude Code

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).
@jwicks31 jwicks31 merged commit 25a0466 into main Jun 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants