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§
- 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. - 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”). - 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. - 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).- 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.
- view
- View IR — the
view <Name> from <Model>, ... { ... }block.
Structs§
- Attribute
- Auth
Block - Config
Block - Config
Entry - Datasource
- Enum
Decl - Enum
Variant - Field
- Mixin
Decl - Model
- Owned
Schema Summary - 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 - Query
- Schema
- Schema
Summary - Selection
Query - Source
Span - 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§
- 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. - QUERY_
SQL_ ATTRIBUTE - The attribute a
queryblock’s SQL body is written in.
Functions§
- 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. - 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. - 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_
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”). - scan_
sql_ placeholders - Every distinct
Nin a$Ntoken appearing insqlas an actual parameter reference, ascending.