Module schema
Expand description
Schema IR — the parsed shape of a .cstack file. Every IR node
carries source-span back-pointers so consumers can map errors to
positions in the original text.
Modules§
- attribute_
text - Lexical scanning of
.cstackattribute text: where string literals are, where a trailing//comment starts, and where one attribute ends and the next begins. - authn_
attribute - The procedure attribute
@authn(maxAge: 300, amr: ["hwk"], acr: ["aal2"])(ADR 0022, cratestack#1244): how recently and how strongly the caller must have authenticated. - composite_
key - Parsing for the model-level
@@id([...])composite-primary-key attribute (Prisma’s spelling). Mirrorscrate::events::parse_emit_attribute’s shape: syntax parsing lives here incratestack-coreso both the parser’s semantic checker and any other consumer share one implementation. The bracketed-field-list syntax itself lives in [super::field_list] —@@id([...])is that module’s only caller now that@@unique([...])/@@index([...])parse their own bracket- plus-keyword-arguments shape via [super::attribute_syntax] instead (cratestack#156/#742’swhere:/using:/opclass:arguments; see [super::field_list]’s module doc for why). - composite_
unique - Parsing for the model-level
@@unique([...], where: "...")composite unique attribute (Prisma’s spelling for the field list, extended with a partial-index predicate by cratestack#742). Its bracketed field-list syntax is shared with@@index([...])/@@id([...])only via [super::field_list::is_valid_field_name] (the identifier rule) — the split/keyword-argument parsing itself is shared with@@index([...], where: "...")(cratestack#156) through [super::attribute_syntax] instead, since unlike@@id([...])this attribute also takes a trailingwhere:keyword argument. What differs from@@id([...])’s plain form is the semantics — a composite unique constraint, not the primary key — and the error text pointing at the single-field alternative. - computed_
attribute - Parsing for the
@computed(params: <Type>?)field attribute’s parenthesized argument. Bare@computedneeds no parsing; this module only handles the parameterized form. Mirrorssuper::composite_key’s shape: syntax parsing lives here incratestack-coresocratestack-parser’s semantic checker and any other consumer (codegen, later) share one implementation. - default_
functions - Which functions a
@default(...)may call (cratestack#1209). - default_
literal - What a literal
@default(...)means for its field (cratestack#1234). - default_
markers - The
@default(...)marker functions — spellings that are not real database functions and must never reach aDEFAULTclause verbatim. - enum_
ordinal - Explicit enum ordinals (
Pending = 1,@@reserved(4)), the IR half ofdocs/design/enum-ordinals.md. The parser fills these in and checks rules R1–R5; the macros,cratestack-migrateand the client generators read them back throughEnumDecl::is_ordinal. - index_
attribute - Parsing for the model-level
@@index([...], using: ..., opclass: "...", where: "...")attribute (cratestack#156, cratestack#742) — a general secondary index, optionally naming a non-default Postgres access method (e.g.ivfflat/hnswfor pgvector approximate-nearest-neighbor search), operator class, and a partial-index predicate. - internal_
attribute - Parsing for the model-level
@@internal("action")attribute (cratestack#743, implementing the accepted design indocs/design/route-suppression.md) — an author declaration that a model action must never be reachable from the wire: no REST route, no RPC dispatch arm, no client stub, on any surface. Shares its action vocabulary with@@allow/@@deny(cratestack-macros/src/policy/model.rs’sparse_rule_action), but unlike those this attribute takes exactly one action per declaration and carries no policy expression — it is purely a generation-time routing decision (design doc §2.2: “this must never be reachable from the wire, independent of whether some future policy edit would make it satisfiable”). - mcp
- Typed IR for a schema’s MCP operator surface (ADR 0002, cratestack#1033 phase 1, cratestack#1036).
- model
- Model / mixin / type / enum / field IR nodes parsed out of a
.cstackfile. Every IR node carriesSourceSpanback-pointers so consumers (parser, LSP, generators) can map errors to source positions. - positions
- Source positions are the one part of a
Schemathat differs between a schema split across files and the single file it is equivalent to. - procedure
- Procedure / query-mutation IR nodes parsed out of a
.cstackfile. - query
queryIR — the declarative, parameterized custom-SQL read block (cratestack#867; accepted designdocs/design/declarative-custom-query.md, adopted by epic cratestack#488’s 2026-09-02 decision comment).- rename_
attribute - The argument of a rename marker,
@@rename(from = "<old_table>")on a model and@rename(from = "<old_column>")on a field. - selection
- Field selection / include shape used by the column-projection path.
- spatial
- The PostGIS geometry vocabulary shared by the parser (which validates what a schema may write) and the migrate emitter (which renders the Postgres type modifier). Keeping the closed set here rather than in either crate means the two can never drift into accepting and emitting different spellings.
- topic
topicIR node (docs/design/subscriptions-websocket.md§3.4, slice S4): a typed, keyed, cross-replica publish/subscribe channel, declared once astopic RoomMessage(roomId: String): ChatMessage.- view
- View IR — the
view <Name> from <Model>, ... { ... }block.
Structs§
- Attribute
- Auth
Block - Config
Block - Config
Entry - Datasource
- Enum
Decl - Enum
Variant - Field
- McpConfig
- The top-level
mcp { }block. - McpName
- The
name = "..."entry of themcp { }block. - Mixin
Decl - Model
- Model
McpExposure @@mcp(resource: "...")on a model: expose it as a read-only MCP resource.- Owned
Schema Summary - Parsed
Authn - What an
@authnattribute requires. - Parsed
Composite Unique - The parsed shape of an
@@unique([...], where: "...")attribute. - Parsed
Index Attribute - The parsed shape of an
@@index([...], using: ..., opclass: "...", where: "...")attribute. - Procedure
- Procedure
Arg - Procedure
McpExposure @mcp(tool ...)on a procedure: expose it as an MCP tool.- Query
- Reserved
Ordinals - An enum’s
@@reserved(n, …)line: ordinals no variant may use, ever. - Schema
- Schema
Summary - Selection
Query - Source
Span - Topic
- Type
Decl - TypeRef
- View
- View
Source
Enums§
- Computed
Params Arg - The parenthesized argument of a
@computed(...)attribute, however it parses. - Extension
Kind - An opt-in framework/database capability a schema announces via a
top-level
extension <name> { }block (cratestack#153). Declaring an extension only unlocks schema-visible syntax for that capability (e.g.@no_rate_limit, theVector(n)scalar type) — it never gates codegen or runtime behavior by itself; that’s a separate, same-named Cargo feature per consuming crate (cratestack#161, out of scope here). - Procedure
Kind - Transport
Style - Wire-shape the schema generates for. Picked once per schema (via
the top-level
transport rest|rpcdirective) so generated servers and clients only carry one binding’s worth of surface. - Type
Arity
Constants§
- AUTHN_
ATTRIBUTE - The attribute’s name.
- AUTHN_
KEYS - The keys
@authntakes, in the order its error messages list them. - AUTHN_
MAX_ AGE_ LIMIT - The largest
maxAge: one year, in seconds. - ENUM_
ORDINAL_ MAX - The largest ordinal a variant may carry: the column is a
SMALLINT. - ENUM_
RESERVED_ ATTRIBUTE - The block attribute that retires ordinals, so a removed variant’s number can never be handed to a new one.
- INTERNAL_
ACTIONS - Action names
@@internal(...)accepts — identical to@@allow’s vocabulary (list/detail/read/create/update/delete/all; seecratestack-macros/src/policy/model.rs’sparse_rule_actionandmodel/descriptor.rs’s action groupings) so an author never has to learn a second action vocabulary to suppress what@@allowalready describes. - MCP_
MAX_ PAGE_ SIZE - Hard ceiling on a collection resource’s page size (ADR 0002 Q3). A model
may lower its own maximum with
max_page_size:, never raise it past this; a larger value is a validation error, not a clamp. - PRIMARY_
KEY_ ATTRIBUTE - The one spelling that marks a field as its model’s (or view’s) primary key.
- QUERY_
SQL_ ATTRIBUTE - The attribute a
queryblock’s SQL body is written in. - RENAME_
ARGUMENT_ FORM - The one argument shape a rename marker takes, for error messages.
Functions§
- authn_
attribute - The
@authnamongattributes, if any (the first, when a schema repeats it; the parser refuses a repeat). - canonical_
geometry_ subtype - Normalises a schema-written geometry subtype to its canonical
PostGIS casing, or
Noneif it isn’t a recognised subtype. - computed_
params_ type_ name - The params type name off a field’s
@computed(params: <Type>?)attribute, orNonefor a bare@computedfield (or a field with no@computedattribute at all). Assumes the attribute is already well-formed — per-declaration validation (e.g.cratestack-parser’svalidate_computed_field_attribute) must run first and reject anything else. Callers that still need to validate the argument form should parse the raw attribute text withparse_computed_params_arginstead. - field_
attribute_ name - The bare name of a field-level attribute, with the
@sigil and any(...)argument list removed:@length(min: 1)->Some("length").Nonefor model-level@@...text or text without the sigil. - geometry_
subtype_ names - Every accepted subtype spelling, for building “expected one of: …” diagnostics. Ordered base-major so the common 2D names lead.
- is_
computed_ attribute - True when a single attribute’s raw text is either spelling of
@computed— bare@computedor the parameterized@computed(...)form (whatever its argument, valid or not; argument-shape validation is a separate concern — seecratestack-parser’svalidate_computed_field_attribute). Anchored withstarts_with("@computed(")rather than the looserstarts_with("@computed")deliberately: the latter would also match a hypothetical unrelated attribute merely prefixed with the same characters (e.g.@computedSomethingElse). - is_
computed_ field - True for a field carrying either spelling of
@computed— bare or@computed(params: <Type>?). Seeis_computed_attributefor why this must be the only place the string comparison is written. - is_
primary_ key_ attribute - Whether
attributemarks its field as the primary key. Exact match onPRIMARY_KEY_ATTRIBUTE:@identity,@idxand@id_fooare other (unknown) attributes, not a primary key. - is_
relation_ attribute - Whether
attributeis a@relation/@relation(...)declaration — by name, so a bare@relationcounts too.@relationshipdoes not. - model_
internal_ actions - The single shared source of truth every surface consults exactly
once: the set of wire verbs (
"list","get","create","update","delete") a model’s@@internal(...)attributes suppress. Assumes every attribute already parsed successfully viaparse_internal_attribute— per-declaration validation (cratestack-parser’svalidate_internal_attribute) must run first and reject anything else, mirroringcomputed_params_type_name’s same assume-validated contract. Malformed or unrecognized attributes are silently skipped here rather than panicking: a caller reaching this function after a failed parse would already have surfaced the error at schema validation time, and this function must stay infallible so every codegen surface can call it without threading aResultthrough unrelated emission code. - parse_
authn_ attribute - Reads a whole
@authn(...)attribute. - parse_
composite_ id_ attribute - Parses
@@id([field1, field2, ...])into its ordered list of local field names. Callers are responsible for checking that each name resolves to a real scalar field on the model. - parse_
composite_ unique_ attribute - Parses
@@unique([field1, field2, ...], where: "...")into its ordered list of local field names plus an optional partial-index predicate. Callers are responsible for checking that each name resolves to a real scalar field on the model. - parse_
computed_ params_ arg - Parses the text between (but not including) the parens of a
@computed(...)attribute into its recognized shape. Whitespace-tolerant around the:and before the trailing?. - parse_
index_ attribute - Parses
@@index([field1, field2, ...]), optionally followed byusing: <method>,opclass: "<name>", and/orwhere: "<predicate>". Callers are responsible for checking that each field name resolves to a real scalar field on the model. - parse_
internal_ attribute - Parses one
@@internal("action")attribute’s action name and validates it againstINTERNAL_ACTIONS. ReturnsErrnaming the model and the bad action for anything else — the compile-error case the design’s acceptance criteria requires (“@@internalnaming an action that is not a valid action verb ⇒ compile error naming the model and the bad action”). - parse_
rename_ from - The old name in
arguments, the text inside a rename marker’s parentheses:from,=, then one double-quoted, non-empty name with no"or\in it, whitespace allowed around each part.Nonefor anything else. - rename_
marker_ from - The old name in a whole rename marker
raw, ascratestack-migratereads it:marker("@rename"or"@@rename"), directly its(, argumentsparse_rename_fromtakes, and a)that ends the text.Nonefor anything else — which the migrator treats as no marker. - scan_
sql_ placeholders - Every distinct
Nin a$Ntoken appearing insqlas an actual parameter reference, ascending. - without_
source_ positions schemawith everySourceSpanzeroed.