Skip to main content

Module schema

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). Mirrors crate::events::parse_emit_attribute’s shape: syntax parsing lives here in cratestack-core so 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’s where:/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 trailing where: 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 @computed needs no parsing; this module only handles the parameterized form. Mirrors super::composite_key’s shape: syntax parsing lives here in cratestack-core so cratestack-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/hnsw for 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 in docs/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’s parse_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 .cstack file. Every IR node carries SourceSpan back-pointers so consumers (parser, LSP, generators) can map errors to source positions.
procedure
Procedure / query-mutation IR nodes parsed out of a .cstack file.
query
query IR — the declarative, parameterized custom-SQL read block (cratestack#867; accepted design docs/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
AuthBlock
ConfigBlock
ConfigEntry
Datasource
EnumDecl
EnumVariant
Field
MixinDecl
Model
OwnedSchemaSummary
ParsedCompositeUnique
The parsed shape of an @@unique([...], where: "...") attribute.
ParsedIndexAttribute
The parsed shape of an @@index([...], using: ..., opclass: "...", where: "...") attribute.
Procedure
ProcedureArg
Query
Schema
SchemaSummary
SelectionQuery
SourceSpan
TypeDecl
TypeRef
View
ViewSource

Enums§

ComputedParamsArg
The parenthesized argument of a @computed(...) attribute, however it parses.
ExtensionKind
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, the Vector(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).
ProcedureKind
TransportStyle
Wire-shape the schema generates for. Picked once per schema (via the top-level transport rest|rpc directive) so generated servers and clients only carry one binding’s worth of surface.
TypeArity

Constants§

INTERNAL_ACTIONS
Action names @@internal(...) accepts — identical to @@allow’s vocabulary (list/detail/read/create/update/delete/ all; see cratestack-macros/src/policy/model.rs’s parse_rule_action and model/descriptor.rs’s action groupings) so an author never has to learn a second action vocabulary to suppress what @@allow already describes.
QUERY_SQL_ATTRIBUTE
The attribute a query block’s SQL body is written in.

Functions§

canonical_geometry_subtype
Normalises a schema-written geometry subtype to its canonical PostGIS casing, or None if it isn’t a recognised subtype.
computed_params_type_name
The params type name off a field’s @computed(params: <Type>?) attribute, or None for a bare @computed field (or a field with no @computed attribute at all). Assumes the attribute is already well-formed — per-declaration validation (e.g. cratestack-parser’s validate_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 with parse_computed_params_arg instead.
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 @computed or the parameterized @computed(...) form (whatever its argument, valid or not; argument-shape validation is a separate concern — see cratestack-parser’s validate_computed_field_attribute). Anchored with starts_with("@computed(") rather than the looser starts_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>?). See is_computed_attribute for 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 via parse_internal_attribute — per-declaration validation (cratestack-parser’s validate_internal_attribute) must run first and reject anything else, mirroring computed_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 a Result through 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 by using: <method>, opclass: "<name>", and/or where: "<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 against INTERNAL_ACTIONS. Returns Err naming the model and the bad action for anything else — the compile-error case the design’s acceptance criteria requires (“@@internal naming an action that is not a valid action verb ⇒ compile error naming the model and the bad action”).
scan_sql_placeholders
Every distinct N in a $N token appearing in sql as an actual parameter reference, ascending.