1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! `cratefield-tables` is the schema a venture declares in its manifest,
//! and the artifacts derived from that one declaration.
//!
//! A venture edits `[tables]` in `venture.toml` and redeploys without a
//! rebuild, so the schema is a runtime value: rows are dynamic values
//! checked by an interpreter reading that value, not typed structs fixed
//! at compile time. Rust cannot infer a compile-time type from a runtime
//! value, so the two do not mix, and this is the representation for every
//! declared table.
//!
//! The schema type is a small purpose-built enum, not JSON Schema. JSON
//! Schema is sprawling and says nothing about the SQLite and Postgres DDL
//! mapping, so it is emitted as a derived view instead.
//!
//! # What one declaration produces
//!
//! - [`Schema::validate`] checks the declaration itself and reports every
//! violation together.
//! - [`Schema::ddl`] renders forward-only, deterministic SQLite and
//! Postgres DDL.
//! - [`validate_row`] checks a `serde_json` object against a table and
//! answers with a [`cratefield_core::Problem`].
//! - [`json_schema`] renders a table as JSON Schema, for interop only.
//!
//! # The bound on a declaration
//!
//! A field can say required, length, range, format, enum, uniqueness,
//! foreign key, default and index. Anything that has to read another row
//! or another request is a function, not a field: overlap checks, state
//! machines and side effects belong in a module or a sidecar. Uniqueness
//! is on that list because the database enforces it, not the validator.
//!
//! # Where the rules are pinned
//!
//! `corpus/rows.json` holds triples of table, input and expected verdict,
//! run by `tests/corpus.rs`. It is a plain data file so a second
//! implementation in another language can be run over the same cases.
//! That is what keeps this validator and a generated client from
//! disagreeing about empty versus absent, number coercion, null versus
//! missing, Unicode length and whitespace.
//!
//! # Pure logic
//!
//! No I/O, no driver, no clock and no randomness. SQL is generated as
//! strings, so the crate builds for `wasm32-unknown-unknown` alongside
//! `cratefield-core`.
//!
//! # Not built here
//!
//! This crate is the schema definition and nothing downstream of it. The
//! following are deliberately absent, each its own follow-up:
//!
//! - CRUD route handlers, the access vocabulary and the batched read
//! endpoint.
//! - The migration diff between two versions of a definition. Everything
//! here only creates.
//! - The generated `@cratefield/client` TypeScript package, and the
//! second run of `corpus/rows.json` against its Zod schemas.
//! - Publishing the declared tables on `/__surface`, and any control
//! plane or manifest generator wiring.
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;