@prisma-next/sql-schema-ir
Advanced tools
| import { IRNodeBase } from "@prisma-next/framework-components/ir"; | ||
| import { DiffSubjectGranularity, DiffableNode, SchemaNodeRef } from "@prisma-next/framework-components/control"; | ||
| import { ColumnDefault } from "@prisma-next/contract/types"; | ||
| import { CodecRef } from "@prisma-next/framework-components/codec"; | ||
| //#region src/ir/sql-schema-ir-node.d.ts | ||
| /** | ||
| * SQL Schema IR node base. Carries the family-level | ||
| * `kind = 'sql-schema-ir'` discriminator and inherits the framework's | ||
| * `freezeNode` affordance. | ||
| * | ||
| * SQL Schema IR represents the actual database state as discovered by | ||
| * introspection (the parallel to SQL Contract IR, which represents the | ||
| * desired state). | ||
| * | ||
| * The discriminator is installed as a non-enumerable own property, | ||
| * matching the SqlNode pattern. This keeps `JSON.stringify(node)` | ||
| * canonical (no `kind` field), keeps `toEqual({...})` test assertions | ||
| * against pre-lift flat shapes passing, and keeps `node.kind` readable | ||
| * for dispatch. | ||
| * | ||
| * Both `kind` and `nodeKind` are required: every concrete leaf is a node | ||
| * the generic differ can pair and compare, so every leaf must declare which | ||
| * node it is. `nodeKind` has no default here — every direct subclass sets its | ||
| * own literal value (the relational leaves via `RelationalSchemaNodeKind`, | ||
| * target concretions via their own vocabulary, e.g. `PostgresSchemaNodeKind`). | ||
| */ | ||
| declare abstract class SqlSchemaIRNode extends IRNodeBase { | ||
| readonly kind: string; | ||
| /** | ||
| * Enumerable discriminant identifying which node this is (column / primary | ||
| * key / foreign key / unique / index / check / database / namespace / | ||
| * table / policy / role / …). Concretions set a unique value; the | ||
| * `.is`/`.assert` guards compare against it. Unlike `kind`, it is | ||
| * enumerable, so it survives a spread that flattens a node into a plain | ||
| * object. | ||
| */ | ||
| abstract readonly nodeKind: string; | ||
| constructor(); | ||
| } | ||
| /** | ||
| * Asserts `node` matches `predicate`, narrowing its type to `T`. The one | ||
| * shared implementation every node class's `static assert` and `isEqualTo` | ||
| * reach for, instead of each hand-writing its own throw: the message names | ||
| * the class the caller expected. | ||
| */ | ||
| declare function assertNode<T extends SqlSchemaIRNode>(node: SqlSchemaIRNode | undefined, className: string, predicate: (node: SqlSchemaIRNode) => node is T): asserts node is T; | ||
| /** | ||
| * Defines a non-enumerable own property, the same treatment `kind` gets | ||
| * above: a derivation-time render-support field stays out of | ||
| * `JSON.stringify`, `toEqual({...})` structural assertions, and spreads, | ||
| * while remaining directly readable (`node.field`) for the one consumer | ||
| * that resolves it at plan time. A no-op when `value` is `undefined` — the | ||
| * property is simply absent, matching every other optional field on these | ||
| * nodes. | ||
| */ | ||
| declare function defineNonEnumerable<T extends object>(target: T, key: string, value: unknown): void; | ||
| //#endregion | ||
| //#region src/ir/primary-key.d.ts | ||
| interface PrimaryKeyInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| /** | ||
| * The key's own column nodes, as root-anchored chains. The derivation | ||
| * stamps them so the primary key is dropped before the columns it is built | ||
| * on. Never compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Primary-key Schema IR node. Mirrors the Contract IR `PrimaryKey` | ||
| * shape (same `columns` + optional `name`) so verification can compare | ||
| * intent and actual structurally. Defined here independently to avoid | ||
| * a sql-schema-ir -> sql-contract dependency. | ||
| * | ||
| * Implements `DiffableNode` so a primary key is directly a table's diff-tree | ||
| * child. `id` is a fixed sentinel — a table has at most one primary key, so | ||
| * there is never a sibling to disambiguate against. `isEqualTo` compares the | ||
| * column tuple; the PK's own `name` is a database-assigned label with no | ||
| * semantic weight, so it is not compared (mirrors the policy node's | ||
| * name-insensitivity to non-identifying detail). | ||
| */ | ||
| declare class PrimaryKey extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-primary-key"; | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| /** See {@link PrimaryKeyInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: PrimaryKeyInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is PrimaryKey; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/schema-node-kinds.d.ts | ||
| /** | ||
| * The `nodeKind` discriminant for each relational schema-diff leaf node. | ||
| * Each node carries a unique value; the differ pairs siblings by `id`, and | ||
| * these kinds distinguish the node types that appear as `PostgresTableSchemaNode` | ||
| * children (columns, primary key, foreign keys, uniques, indexes, checks) from | ||
| * each other and from the RLS policy/role kinds a target defines separately. | ||
| */ | ||
| declare const RelationalSchemaNodeKind: { | ||
| readonly schema: "sql-schema"; | ||
| readonly table: "sql-table"; | ||
| readonly column: "sql-column"; | ||
| readonly columnDefault: "sql-column-default"; | ||
| readonly primaryKey: "sql-primary-key"; | ||
| readonly foreignKey: "sql-foreign-key"; | ||
| readonly unique: "sql-unique"; | ||
| readonly index: "sql-index"; | ||
| readonly check: "sql-check-constraint"; | ||
| }; | ||
| type RelationalSchemaNodeKind = (typeof RelationalSchemaNodeKind)[keyof typeof RelationalSchemaNodeKind]; | ||
| /** | ||
| * Looks up the subject granularity for a relational `nodeKind`. Throws for a | ||
| * `nodeKind` outside this map (a target-specific kind, e.g. Postgres's | ||
| * namespace/table/policy/role) — those map their own kinds directly rather | ||
| * than through this family-level map. | ||
| */ | ||
| declare function relationalNodeGranularity(nodeKind: string): DiffSubjectGranularity; | ||
| /** | ||
| * Looks up the storage `entityKind` for a relational `nodeKind` — sibling of | ||
| * {@link relationalNodeGranularity}, resolved by `nodeKind` equality against | ||
| * {@link RELATIONAL_NODE_ENTITY_KIND}. `undefined` for a target-specific kind | ||
| * (targets map their own kinds directly) or a relational kind with no entity | ||
| * of its own. | ||
| */ | ||
| declare function relationalNodeEntityKind(nodeKind: string): string | undefined; | ||
| //#endregion | ||
| //#region src/ir/sql-check-constraint-ir.d.ts | ||
| interface SqlCheckConstraintIRInput { | ||
| /** Constraint name as stored in the database catalog. */ | ||
| readonly name: string; | ||
| /** Column the check restricts. */ | ||
| readonly column: string; | ||
| /** Permitted values the column must be IN. */ | ||
| readonly permittedValues: readonly string[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a table-level check constraint that restricts a | ||
| * column to a set of permitted values (an enum-style `IN (...)` check). | ||
| * | ||
| * Carries the **resolved values** rather than a raw SQL predicate so | ||
| * callers can compare value-sets without parsing SQL. | ||
| * | ||
| * Implements `DiffableNode` so a check constraint is directly a table's | ||
| * diff-tree child: `id` is the constraint name. `isEqualTo` compares | ||
| * `column` and the permitted-value set (order-insensitive — the database | ||
| * does not guarantee `IN (...)` ordering). | ||
| */ | ||
| declare class SqlCheckConstraintIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-check-constraint"; | ||
| readonly name: string; | ||
| readonly column: string; | ||
| readonly permittedValues: readonly string[]; | ||
| constructor(input: SqlCheckConstraintIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlCheckConstraintIR; | ||
| /** | ||
| * Compares the permitted-value sets only (unordered), matching the | ||
| * relational walk's `verifyCheckConstraints`: two checks pairing by name | ||
| * compare their value sets — the `column` field is descriptive, not part | ||
| * of the comparison, so a name-paired check with equal values verifies | ||
| * regardless of which column carries it. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-column-default-ir.d.ts | ||
| interface SqlColumnDefaultIRInput { | ||
| /** Structured resolved default (contract-declared or normalizer-parsed). */ | ||
| readonly resolved?: ColumnDefault; | ||
| /** Raw database default expression, when known (introspected side). */ | ||
| readonly raw?: string; | ||
| /** | ||
| * Native-type context for temporal literal normalization — the owning | ||
| * column's resolved native type. | ||
| */ | ||
| readonly nativeTypeContext?: string; | ||
| /** | ||
| * The owning column's array-ness, threaded through so the planner's | ||
| * set-default op-builder can render an array-literal default (e.g. | ||
| * `ARRAY[...]`) the same way the pre-`plan(start, end)` op-path did. See | ||
| * {@link import('./sql-column-ir').SqlColumnIRInput.many}. | ||
| */ | ||
| readonly many?: boolean; | ||
| } | ||
| /** | ||
| * Schema-diff node for a column's default value. The default is the one | ||
| * column attribute with an extra/missing/drift lifecycle of its own, so it | ||
| * is a child node of the column rather than a compared attribute: an | ||
| * undeclared live default surfaces as `not-expected`, a declared default the | ||
| * database lacks as `not-found`, and a divergent value as `not-equal` — the | ||
| * three reasons cover the legacy `extra_default` / `default_missing` / | ||
| * `default_mismatch` vocabulary with no attribute inspection. | ||
| * | ||
| * `id` is a fixed sentinel — a column has at most one default. Built | ||
| * transiently by `SqlColumnIR.children()` from the column's own fields; | ||
| * never constructed by derivation or introspection directly. | ||
| */ | ||
| declare class SqlColumnDefaultIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-column-default"; | ||
| readonly resolved?: ColumnDefault; | ||
| readonly raw?: string; | ||
| readonly nativeTypeContext?: string; | ||
| /** See {@link SqlColumnDefaultIRInput.many}. Non-enumerable so it stays out of JSON and structural equality. */ | ||
| readonly many?: boolean; | ||
| constructor(input: SqlColumnDefaultIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlColumnDefaultIR; | ||
| /** | ||
| * Structured comparison with `this` as the expected side: both sides | ||
| * resolved compare per the relational walk's `columnDefaultsEqual` | ||
| * semantics; a declared expected default against an unparseable actual | ||
| * (raw present, no resolved parse) is a mismatch; two raw-only nodes fall | ||
| * back to raw string equality. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-column-ir.d.ts | ||
| /** | ||
| * Namespaced annotations for extensibility. Each namespace | ||
| * (e.g. `pg`, `pgvector`) owns its annotations subtree. | ||
| */ | ||
| type SqlAnnotations = { | ||
| readonly [namespace: string]: unknown; | ||
| }; | ||
| interface SqlColumnIRInput { | ||
| readonly name: string; | ||
| readonly nativeType: string; | ||
| readonly nullable: boolean; | ||
| /** Raw database default expression (e.g. `'hello'::text`, `nextval('seq')`). */ | ||
| readonly default?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** True when the column is a native array (e.g. `text[]`, `int4[]`). The `nativeType` carries the element type only (e.g. `text`, `int4`). */ | ||
| readonly many?: boolean; | ||
| /** | ||
| * Fully resolved native type, comparable across the two diff sides: | ||
| * the contract-derived side stamps the codec-expanded type (typeRef | ||
| * resolved, parameterized types expanded, `[]` appended for arrays); | ||
| * the introspected side stamps the target-normalized type with the same | ||
| * `[]` convention. Stamped at construction by derivation/introspection; | ||
| * absent on raw hand-built nodes. | ||
| */ | ||
| readonly resolvedNativeType?: string; | ||
| /** | ||
| * Structured default, comparable across the two diff sides: the | ||
| * contract-derived side stamps the contract's `ColumnDefault`; the | ||
| * introspected side stamps the target default-normalizer's parse of the | ||
| * raw expression. Absent when the column declares no default, or when | ||
| * the introspected raw default could not be parsed. | ||
| */ | ||
| readonly resolvedDefault?: ColumnDefault; | ||
| /** | ||
| * The column's resolved codec reference — the identity the migration | ||
| * planner's op-builders resolve DDL type rendering against at plan time | ||
| * (parameterized type expansion, e.g. `character` + `{ length: 36 }` → | ||
| * `character(36)`), calling the same codec hooks the pre-`plan(start, | ||
| * end)` op-path called. Carried the same way the query AST carries | ||
| * `CodecRef` (TML-2456) and the migration DDL renderer (TML-2918). | ||
| * Stamped on the EXPECTED (contract-derived) column at derivation, | ||
| * post-`typeRef` resolution (the referenced storage type's own | ||
| * codec/params, not the column's `typeRef` pointer). Absent on | ||
| * introspected/hand-built nodes — the actual side never renders DDL — | ||
| * and never compared by `isEqualTo`. | ||
| */ | ||
| readonly codecRef?: CodecRef; | ||
| /** | ||
| * The column's resolved BASE native type: pre-parameter-expansion, | ||
| * pre-array-suffix (e.g. `character`, not `character(36)` or | ||
| * `character[]`). Distinct from {@link resolvedNativeType} (the EXPANDED | ||
| * comparison value) — DDL rendering re-expands a parameterized type at | ||
| * plan time from this base, so it must not already carry the expansion. | ||
| * Stamped alongside {@link codecRef}. | ||
| */ | ||
| readonly codecBaseNativeType?: string; | ||
| /** | ||
| * True when the contract column declared its type via a named | ||
| * `storage.types` reference (`typeRef`) rather than inline fields — the | ||
| * migration planner quotes the base native type as an identifier in this | ||
| * case (e.g. a native enum's type name), matching the pre-`plan(start, | ||
| * end)` rendering exactly. | ||
| */ | ||
| readonly codecNamedType?: boolean; | ||
| } | ||
| /** | ||
| * Schema IR node for a single column on a table, as observed by | ||
| * introspection. Unlike the Contract IR `StorageColumn`, this carries | ||
| * the column's `name` (Schema IR columns are returned as arrays from | ||
| * introspection queries; the parent table re-keys them into a record | ||
| * for downstream consumers). | ||
| * | ||
| * Implements `DiffableNode` so a column is directly a table's diff-tree | ||
| * child: `id` is the column name (unique among a table's columns); `isEqualTo` | ||
| * compares this column's own attributes only — never children, since a | ||
| * column is a leaf. When both sides carry `resolvedNativeType` (stamped at | ||
| * derivation/introspection), the comparison uses the resolved values — | ||
| * resolved native type, nullability, and structured default equality per | ||
| * the relational walk's `columnDefaultsEqual` semantics, with `this` as the | ||
| * expected side. Otherwise it falls back to comparing raw fields. | ||
| */ | ||
| declare class SqlColumnIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-column"; | ||
| readonly name: string; | ||
| readonly nativeType: string; | ||
| readonly nullable: boolean; | ||
| readonly default?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** True when the column is a native array (e.g. `text[]`, `int4[]`). The `nativeType` carries the element type only (e.g. `text`, `int4`). */ | ||
| readonly many?: boolean; | ||
| readonly resolvedNativeType?: string; | ||
| readonly resolvedDefault?: ColumnDefault; | ||
| /** See {@link SqlColumnIRInput.codecRef}. Non-enumerable so it stays out of JSON and structural equality. */ | ||
| readonly codecRef?: CodecRef; | ||
| /** See {@link SqlColumnIRInput.codecBaseNativeType}. Non-enumerable, same reason as {@link codecRef}. */ | ||
| readonly codecBaseNativeType?: string; | ||
| /** See {@link SqlColumnIRInput.codecNamedType}. Non-enumerable, same reason as {@link codecRef}. */ | ||
| readonly codecNamedType?: boolean; | ||
| constructor(input: SqlColumnIRInput); | ||
| get id(): string; | ||
| /** | ||
| * The column's default, when declared/present, is the column's one child | ||
| * node — it has an extra/missing/drift lifecycle of its own, so the differ | ||
| * recurses to it rather than `isEqualTo` comparing it. Built transiently | ||
| * from this column's own fields. | ||
| */ | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlColumnIR; | ||
| /** | ||
| * Compares the column's own attributes only — the default lives on the | ||
| * child node. When both sides carry `resolvedNativeType`, the resolved | ||
| * value governs (array-ness rides on its `[]` suffix); otherwise raw | ||
| * fields compare. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-foreign-key-ir.d.ts | ||
| type SqlReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'; | ||
| interface SqlForeignKeyIRInput { | ||
| readonly columns: readonly string[]; | ||
| readonly referencedTable: string; | ||
| readonly referencedColumns: readonly string[]; | ||
| /** Schema (namespace) of the referenced table — populated by adapters that introspect cross-schema FKs. */ | ||
| readonly referencedSchema?: string; | ||
| readonly name?: string; | ||
| readonly onDelete?: SqlReferentialAction; | ||
| readonly onUpdate?: SqlReferentialAction; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** | ||
| * The real live DDL namespace of the referenced table, comparable across | ||
| * the two diff sides. Contract-derived trees stamp it explicitly (resolving | ||
| * namespace ids — including the unbound sentinel — to the DDL namespace); | ||
| * introspected FKs default it to `referencedSchema`, whose value already | ||
| * is the live namespace. Folded into `id` in place of the raw value so an | ||
| * unbound-namespace contract FK pairs with its introspected counterpart. | ||
| */ | ||
| readonly resolvedReferencedNamespace?: string; | ||
| /** | ||
| * The referenced table's node, as the root-anchored chain the differ pairs | ||
| * siblings with. Stamped by the derivation, which holds the parent | ||
| * (database/namespace) context the chain's shape depends on. Never | ||
| * compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a foreign-key constraint as observed by | ||
| * introspection. The `referencedTable` / `referencedColumns` field | ||
| * names match the introspection vocabulary (`pg_constraint.confkey`, | ||
| * etc.) and intentionally differ from the Contract IR's nested | ||
| * `references: { table, columns }` shape so that the verifier's | ||
| * structural comparison stays explicit about which side it's reading. | ||
| * | ||
| * Implements `DiffableNode` so a foreign key is directly a table's diff-tree | ||
| * child. Foreign keys are frequently unnamed (introspection may not carry a | ||
| * constraint name, and the contract side never invents one), so `id` is | ||
| * derived from the referencing/referenced coordinates rather than `name` — | ||
| * the same tuple that makes two FK constraints the same constraint. This | ||
| * also serves as the comparison key: two FKs with the same coordinates are | ||
| * paired by the differ, and `isEqualTo` then compares the remaining | ||
| * attribute — the referential actions. | ||
| */ | ||
| declare class SqlForeignKeyIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-foreign-key"; | ||
| readonly columns: readonly string[]; | ||
| readonly referencedTable: string; | ||
| readonly referencedColumns: readonly string[]; | ||
| readonly referencedSchema?: string; | ||
| readonly name?: string; | ||
| readonly onDelete?: SqlReferentialAction; | ||
| readonly onUpdate?: SqlReferentialAction; | ||
| readonly annotations?: SqlAnnotations; | ||
| readonly resolvedReferencedNamespace?: string; | ||
| /** See {@link SqlForeignKeyIRInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: SqlForeignKeyIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlForeignKeyIR; | ||
| /** | ||
| * Referential-action comparison with `this` as the expected side, matching | ||
| * the relational walk's `getReferentialActionMismatches`: `noAction` is the | ||
| * database default and equivalent to an undeclared action, and drift is | ||
| * flagged only when the expected side declares a (normalized) action. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-index-ir.d.ts | ||
| interface SqlIndexIRInput { | ||
| readonly columns: readonly string[]; | ||
| readonly unique: boolean; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** | ||
| * The index's own column nodes, as root-anchored chains. The derivation | ||
| * stamps them so an index is dropped before the columns it is built on | ||
| * (Postgres auto-drops the index when a covered column goes). Never | ||
| * compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a secondary index as observed by introspection. | ||
| * Unlike the Contract IR `Index`, the Schema IR carries an explicit | ||
| * `unique` field — introspection sees the underlying index regardless | ||
| * of whether the user expressed it as `@@index` or `@@unique`, and the | ||
| * verifier needs to distinguish them when comparing to the Contract. | ||
| * | ||
| * Implements `DiffableNode` so an index is directly a table's diff-tree | ||
| * child. Indexes are frequently unnamed, so `id` is derived from the column | ||
| * tuple — the same tuple that makes two indexes the same index, so it | ||
| * doubles as the pairing key. `isEqualTo` is symmetric structural equality | ||
| * on the remaining attributes: `unique`, `type`, and `options`. A unique | ||
| * index and a non-unique index on the same columns are different objects | ||
| * and are not equal — there is no "stronger satisfies weaker". | ||
| * | ||
| * Deliberately column-tuple-only (not `unique`): a contract `@@index` | ||
| * (non-unique) must still pair against a live unique index of the same | ||
| * columns so the differ can report the mismatch as an incompatible index | ||
| * change rather than a spurious missing+extra pair — see | ||
| * `planner.unique-index-structural.test.ts`. The corollary is that two | ||
| * indexes legitimately coexisting on one table with the *same* column tuple | ||
| * (e.g. a unique index and a redundant plain index Postgres has no problem | ||
| * hosting side by side) collide on this id; the postgres control adapter's | ||
| * introspection keeps only one such index per table+column-tuple rather | ||
| * than handing the differ two same-tree siblings it cannot represent. | ||
| */ | ||
| declare class SqlIndexIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-index"; | ||
| readonly columns: readonly string[]; | ||
| readonly unique: boolean; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** See {@link SqlIndexIRInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: SqlIndexIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlIndexIR; | ||
| /** | ||
| * Symmetric structural equality: two paired index nodes are equal iff their | ||
| * `unique` flag, `type`, and (loosely-compared) `options` all match. There | ||
| * is no satisfaction — a unique index does not equal a non-unique index. | ||
| * `options` compares loosely (introspection stringifies reloptions); `type` | ||
| * compares strictly after the introspection-side btree→undefined | ||
| * normalization done at construction. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-unique-ir.d.ts | ||
| interface SqlUniqueIRInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** | ||
| * The constraint's own column nodes, as root-anchored chains. The | ||
| * derivation stamps them so a unique constraint is dropped before the | ||
| * columns it is built on. Never compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a table-level unique constraint as observed by | ||
| * introspection. | ||
| * | ||
| * Implements `DiffableNode` so a unique constraint is directly a table's | ||
| * diff-tree child. Unique constraints are frequently unnamed, so `id` is | ||
| * derived from the column tuple rather than `name` — the column tuple is | ||
| * also what makes two unique constraints the same constraint, so it doubles | ||
| * as the pairing key. There are no further attributes to compare once | ||
| * columns are equal (the differ pairs on `id`), so `isEqualTo` is identity. | ||
| */ | ||
| declare class SqlUniqueIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-unique"; | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** See {@link SqlUniqueIRInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: SqlUniqueIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlUniqueIR; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-table-ir.d.ts | ||
| interface SqlTableIRInput { | ||
| readonly name: string; | ||
| readonly columns: Record<string, SqlColumnIR | SqlColumnIRInput>; | ||
| readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR | SqlForeignKeyIRInput>; | ||
| readonly uniques: ReadonlyArray<SqlUniqueIR | SqlUniqueIRInput>; | ||
| readonly indexes: ReadonlyArray<SqlIndexIR | SqlIndexIRInput>; | ||
| readonly primaryKey?: PrimaryKey | PrimaryKeyInput; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** Optional check constraints for enum-restricted columns. Omitted when none present. */ | ||
| readonly checks?: ReadonlyArray<SqlCheckConstraintIR | SqlCheckConstraintIRInput>; | ||
| } | ||
| /** | ||
| * Schema IR node for a single table as observed by introspection. | ||
| * | ||
| * Unlike the Contract IR `StorageTable`, this carries the table's | ||
| * `name` — introspection queries return tables as arrays and the | ||
| * verifier keys them into `SqlSchemaIR.tables` afterwards, so the name | ||
| * stays on the table object for downstream call sites that walk | ||
| * `Object.values(schema.tables)`. | ||
| * | ||
| * The constructor normalises nested IR-class fields so downstream | ||
| * walks see a uniform AST regardless of whether the input was a | ||
| * plain-data literal (from introspection) or already-constructed | ||
| * class instances. | ||
| * | ||
| * Implements `DiffableNode` so a flat (single-schema) tree is directly | ||
| * diffable: `id` is the table name; `isEqualTo` is identity (the table's | ||
| * structural drift is entirely expressed by its children); `children()` | ||
| * yields every column, the primary key (when present), every foreign key, | ||
| * unique, index, and check constraint — the same composition and order as | ||
| * the Postgres table node, minus policies. | ||
| */ | ||
| declare class SqlTableIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-table"; | ||
| readonly name: string; | ||
| readonly columns: Readonly<Record<string, SqlColumnIR>>; | ||
| readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>; | ||
| readonly uniques: ReadonlyArray<SqlUniqueIR>; | ||
| readonly indexes: ReadonlyArray<SqlIndexIR>; | ||
| readonly primaryKey?: PrimaryKey; | ||
| readonly annotations?: SqlAnnotations; | ||
| readonly checks?: ReadonlyArray<SqlCheckConstraintIR>; | ||
| constructor(input: SqlTableIRInput); | ||
| get id(): string; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| children(): readonly DiffableNode[]; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-schema-ir.d.ts | ||
| interface SqlSchemaIRInput { | ||
| readonly tables: Record<string, SqlTableIR | SqlTableIRInput>; | ||
| readonly annotations?: SqlAnnotations; | ||
| } | ||
| /** | ||
| * Root Schema IR node representing the complete database schema as | ||
| * observed by introspection. Target-agnostic; used by both verifiers | ||
| * (compare against intended Contract storage) and migration planners | ||
| * (derive operations needed to reconcile). | ||
| * | ||
| * The constructor normalises nested `SqlTableIR` instances so | ||
| * downstream walks see a uniform AST regardless of whether the input | ||
| * was a plain-data literal or already-constructed class instances. | ||
| * | ||
| * Implements `DiffableNode` as the root of a flat (single-schema) diff | ||
| * tree: `id` is the fixed sentinel `'database'` (roots have no siblings), | ||
| * `isEqualTo` is identity (a container has no own attributes), and | ||
| * `children()` yields the table nodes. | ||
| */ | ||
| declare class SqlSchemaIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-schema"; | ||
| readonly tables: Readonly<Record<string, SqlTableIR>>; | ||
| readonly annotations?: SqlAnnotations; | ||
| constructor(input: SqlSchemaIRInput); | ||
| get id(): string; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| children(): readonly DiffableNode[]; | ||
| } | ||
| //#endregion | ||
| //#region src/types.d.ts | ||
| /** | ||
| * SQL type metadata for control-plane and execution-plane type | ||
| * availability and mapping. Read-only view of type information | ||
| * without encode/decode behavior. | ||
| */ | ||
| interface SqlTypeMetadata { | ||
| /** Namespaced type identifier, e.g. `pg/int4@1`, `pg/text@1`. */ | ||
| readonly typeId: string; | ||
| /** Contract scalar type IDs this type can handle. */ | ||
| readonly targetTypes: readonly string[]; | ||
| /** | ||
| * Native database type name (target-specific). Optional because | ||
| * not all types have a native database representation. | ||
| */ | ||
| readonly nativeType?: string; | ||
| } | ||
| /** | ||
| * Registry interface for SQL type metadata. Provides read-only | ||
| * iteration over type metadata entries. | ||
| */ | ||
| interface SqlTypeMetadataRegistry { | ||
| values(): IterableIterator<SqlTypeMetadata>; | ||
| } | ||
| //#endregion | ||
| export { relationalNodeGranularity as C, assertNode as D, SqlSchemaIRNode as E, defineNonEnumerable as O, relationalNodeEntityKind as S, PrimaryKeyInput as T, SqlColumnDefaultIR as _, SqlTableIR as a, SqlCheckConstraintIRInput as b, SqlUniqueIRInput as c, SqlForeignKeyIR as d, SqlForeignKeyIRInput as f, SqlColumnIRInput as g, SqlColumnIR as h, SqlSchemaIRInput as i, SqlIndexIR as l, SqlAnnotations as m, SqlTypeMetadataRegistry as n, SqlTableIRInput as o, SqlReferentialAction as p, SqlSchemaIR as r, SqlUniqueIR as s, SqlTypeMetadata as t, SqlIndexIRInput as u, SqlColumnDefaultIRInput as v, PrimaryKey as w, RelationalSchemaNodeKind as x, SqlCheckConstraintIR as y }; | ||
| //# sourceMappingURL=types-Bnh1XTEx.d.mts.map |
| {"version":3,"file":"types-Bnh1XTEx.d.mts","names":[],"sources":["../src/ir/sql-schema-ir-node.ts","../src/ir/primary-key.ts","../src/ir/schema-node-kinds.ts","../src/ir/sql-check-constraint-ir.ts","../src/ir/sql-column-default-ir.ts","../src/ir/sql-column-ir.ts","../src/ir/sql-foreign-key-ir.ts","../src/ir/sql-index-ir.ts","../src/ir/sql-unique-ir.ts","../src/ir/sql-table-ir.ts","../src/ir/sql-schema-ir.ts","../src/types.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;uBAuBsB,wBAAwB;WAC3B;;;;;;;;;oBAUC;;;;;;;;;iBAmBJ,WAAW,UAAU,iBACnC,MAAM,6BACN,mBACA,YAAY,MAAM,oBAAoB,QAAQ,YACrC,QAAQ;;;;;;;;;;iBAeH,oBAAoB,kBAClC,QAAQ,GACR,aACA;;;UCrEe;WACN;WACA;;;;;;WAMA,qBAAqB;;;;;;;;;;;;;;;cAgBnB,mBAAmB,2BAA2B;WACvC;WAET;WACQ;;WAEA,qBAAqB;cAE1B,OAAO;MAQf;EAIJ,qBAAqB;SAId,GAAG,MAAM,kBAAkB,QAAQ;EAI1C,UAAU,OAAO;;;;;;;;;;;cCjDN;;;;;;;;;;;KAYD,mCACF,uCAAuC;;;;;;;iBAoCjC,0BAA0B,mBAAmB;;;;;;;;iBAyB7C,yBAAyB;;;UC7ExB;;WAEN;;WAEA;;WAEA;;;;;;;;;;;;;;cAeE,6BAA6B,2BAA2B;WACjD;WAET;WACA;WACA;cAEG,OAAO;MAQf;EAIJ,qBAAqB;SAId,GAAG,MAAM,kBAAkB,QAAQ;;;;;;;;EAW1C,UAAU,OAAO;;;;UCrDF;;WAEN,WAAW;;WAEX;;;;;WAKA;;;;;;;WAOA;;;;;;;;;;;;;;;cAgBE,2BAA2B,2BAA2B;WAC/C;WAED,WAAW;WACX;WACA;;WAEA;cAEL,OAAO;MASf;EAIJ,qBAAqB;SAId,GAAG,MAAM,kBAAkB,QAAQ;;;;;;;;EAW1C,UAAU,OAAO;;;;;;;;KC/DP;YACA;;UAGK;WACN;WACA;WACA;;WAEA;WACA,cAAc;;WAEd;;;;;;;;;WASA;;;;;;;;WAQA,kBAAkB;;;;;;;;;;;;;;WAclB,WAAW;;;;;;;;;W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aAAa;WAC1B,cAAc;;WAEd,SAAS,cAAc,uBAAuB;;;;;;;;;;;;;;;;;;;;;;;cAwB5C,mBAAmB,2BAA2B;WACvC;WAET;WACA,SAAS,SAAS,eAAe;WACjC,aAAa,cAAc;WAC3B,SAAS,cAAc;WACvB,SAAS,cAAc;WACf,aAAa;WACb,cAAc;WACd,SAAS,cAAc;cAE5B,OAAO;MAqCf;EAIJ,UAAU,OAAO;EAIjB,qBAAqB;;;;UC9FN;WACN,QAAQ,eAAe,aAAa;WACpC,cAAc;;;;;;;;;;;;;;;;;cAkBZ,oBAAoB,2BAA2B;WACxC;WAET,QAAQ,SAAS,eAAe;WACxB,cAAc;cAEnB,OAAO;MAcf;EAIJ,UAAU,OAAO;EAIjB,qBAAqB;;;;;;;;;UCTN;;WAEN;;WAGA;;;;;WAMA;;;;;;UAOM;EACf,UAAU,iBAAiB"} |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"naming.d.mts","names":[],"sources":["../../src/exports/naming.ts"],"mappings":";iBAAgB,gBAAA,CAAiB,SAAA,UAAmB,OAA0B"} | ||
| {"version":3,"file":"naming.d.mts","names":[],"sources":["../../src/exports/naming.ts"],"mappings":";iBAAgB,iBAAiB,mBAAmB"} |
@@ -1,2 +0,2 @@ | ||
| import { C as relationalNodeGranularity, D as assertNode, E as SqlSchemaIRNode, O as defineNonEnumerable, S as relationalNodeEntityKind, T as PrimaryKeyInput, _ as SqlColumnDefaultIR, a as SqlTableIR, b as SqlCheckConstraintIRInput, c as SqlUniqueIRInput, d as SqlForeignKeyIR, f as SqlForeignKeyIRInput, g as SqlColumnIRInput, h as SqlColumnIR, i as SqlSchemaIRInput, l as SqlIndexIR, m as SqlAnnotations, n as SqlTypeMetadataRegistry, o as SqlTableIRInput, p as SqlReferentialAction, r as SqlSchemaIR, s as SqlUniqueIR, t as SqlTypeMetadata, u as SqlIndexIRInput, v as SqlColumnDefaultIRInput, w as PrimaryKey, x as RelationalSchemaNodeKind, y as SqlCheckConstraintIR } from "../types-CeJhPT7f.mjs"; | ||
| import { C as relationalNodeGranularity, D as assertNode, E as SqlSchemaIRNode, O as defineNonEnumerable, S as relationalNodeEntityKind, T as PrimaryKeyInput, _ as SqlColumnDefaultIR, a as SqlTableIR, b as SqlCheckConstraintIRInput, c as SqlUniqueIRInput, d as SqlForeignKeyIR, f as SqlForeignKeyIRInput, g as SqlColumnIRInput, h as SqlColumnIR, i as SqlSchemaIRInput, l as SqlIndexIR, m as SqlAnnotations, n as SqlTypeMetadataRegistry, o as SqlTableIRInput, p as SqlReferentialAction, r as SqlSchemaIR, s as SqlUniqueIR, t as SqlTypeMetadata, u as SqlIndexIRInput, v as SqlColumnDefaultIRInput, w as PrimaryKey, x as RelationalSchemaNodeKind, y as SqlCheckConstraintIR } from "../types-Bnh1XTEx.mjs"; | ||
| export { PrimaryKey, type PrimaryKeyInput, RelationalSchemaNodeKind, type SqlAnnotations, SqlCheckConstraintIR, type SqlCheckConstraintIRInput, SqlColumnDefaultIR, type SqlColumnDefaultIRInput, SqlColumnIR, type SqlColumnIRInput, SqlForeignKeyIR, type SqlForeignKeyIRInput, SqlIndexIR, type SqlIndexIRInput, type SqlReferentialAction, SqlSchemaIR, type SqlSchemaIRInput, SqlSchemaIRNode, SqlTableIR, type SqlTableIRInput, type SqlTypeMetadata, type SqlTypeMetadataRegistry, SqlUniqueIR, type SqlUniqueIRInput, assertNode, defineNonEnumerable, relationalNodeEntityKind, relationalNodeGranularity }; |
+1
-1
@@ -1,2 +0,2 @@ | ||
| import { C as relationalNodeGranularity, D as assertNode, E as SqlSchemaIRNode, O as defineNonEnumerable, S as relationalNodeEntityKind, T as PrimaryKeyInput, _ as SqlColumnDefaultIR, a as SqlTableIR, b as SqlCheckConstraintIRInput, c as SqlUniqueIRInput, d as SqlForeignKeyIR, f as SqlForeignKeyIRInput, g as SqlColumnIRInput, h as SqlColumnIR, i as SqlSchemaIRInput, l as SqlIndexIR, m as SqlAnnotations, n as SqlTypeMetadataRegistry, o as SqlTableIRInput, p as SqlReferentialAction, r as SqlSchemaIR, s as SqlUniqueIR, t as SqlTypeMetadata, u as SqlIndexIRInput, v as SqlColumnDefaultIRInput, w as PrimaryKey, x as RelationalSchemaNodeKind, y as SqlCheckConstraintIR } from "./types-CeJhPT7f.mjs"; | ||
| import { C as relationalNodeGranularity, D as assertNode, E as SqlSchemaIRNode, O as defineNonEnumerable, S as relationalNodeEntityKind, T as PrimaryKeyInput, _ as SqlColumnDefaultIR, a as SqlTableIR, b as SqlCheckConstraintIRInput, c as SqlUniqueIRInput, d as SqlForeignKeyIR, f as SqlForeignKeyIRInput, g as SqlColumnIRInput, h as SqlColumnIR, i as SqlSchemaIRInput, l as SqlIndexIR, m as SqlAnnotations, n as SqlTypeMetadataRegistry, o as SqlTableIRInput, p as SqlReferentialAction, r as SqlSchemaIR, s as SqlUniqueIR, t as SqlTypeMetadata, u as SqlIndexIRInput, v as SqlColumnDefaultIRInput, w as PrimaryKey, x as RelationalSchemaNodeKind, y as SqlCheckConstraintIR } from "./types-Bnh1XTEx.mjs"; | ||
| export { PrimaryKey, type PrimaryKeyInput, RelationalSchemaNodeKind, type SqlAnnotations, SqlCheckConstraintIR, type SqlCheckConstraintIRInput, SqlColumnDefaultIR, type SqlColumnDefaultIRInput, SqlColumnIR, type SqlColumnIRInput, SqlForeignKeyIR, type SqlForeignKeyIRInput, SqlIndexIR, type SqlIndexIRInput, type SqlReferentialAction, SqlSchemaIR, type SqlSchemaIRInput, SqlSchemaIRNode, SqlTableIR, type SqlTableIRInput, type SqlTypeMetadata, type SqlTypeMetadataRegistry, SqlUniqueIR, type SqlUniqueIRInput, assertNode, defineNonEnumerable, relationalNodeEntityKind, relationalNodeGranularity }; |
+8
-8
| { | ||
| "name": "@prisma-next/sql-schema-ir", | ||
| "version": "0.15.0-dev.16", | ||
| "version": "0.15.0-dev.22", | ||
| "license": "Apache-2.0", | ||
@@ -9,11 +9,11 @@ "type": "module", | ||
| "dependencies": { | ||
| "@prisma-next/contract": "0.15.0-dev.16", | ||
| "@prisma-next/framework-components": "0.15.0-dev.16", | ||
| "@prisma-next/utils": "0.15.0-dev.16" | ||
| "@prisma-next/contract": "0.15.0-dev.22", | ||
| "@prisma-next/framework-components": "0.15.0-dev.22", | ||
| "@prisma-next/utils": "0.15.0-dev.22" | ||
| }, | ||
| "devDependencies": { | ||
| "@prisma-next/test-utils": "0.15.0-dev.16", | ||
| "@prisma-next/tsconfig": "0.15.0-dev.16", | ||
| "@prisma-next/tsdown": "0.15.0-dev.16", | ||
| "tsdown": "0.22.3", | ||
| "@prisma-next/test-utils": "0.15.0-dev.22", | ||
| "@prisma-next/tsconfig": "0.15.0-dev.22", | ||
| "@prisma-next/tsdown": "0.15.0-dev.22", | ||
| "tsdown": "0.22.8", | ||
| "typescript": "5.9.3", | ||
@@ -20,0 +20,0 @@ "vitest": "4.1.10" |
| import { IRNodeBase } from "@prisma-next/framework-components/ir"; | ||
| import { DiffSubjectGranularity, DiffableNode, SchemaNodeRef } from "@prisma-next/framework-components/control"; | ||
| import { ColumnDefault } from "@prisma-next/contract/types"; | ||
| import { CodecRef } from "@prisma-next/framework-components/codec"; | ||
| //#region src/ir/sql-schema-ir-node.d.ts | ||
| /** | ||
| * SQL Schema IR node base. Carries the family-level | ||
| * `kind = 'sql-schema-ir'` discriminator and inherits the framework's | ||
| * `freezeNode` affordance. | ||
| * | ||
| * SQL Schema IR represents the actual database state as discovered by | ||
| * introspection (the parallel to SQL Contract IR, which represents the | ||
| * desired state). | ||
| * | ||
| * The discriminator is installed as a non-enumerable own property, | ||
| * matching the SqlNode pattern. This keeps `JSON.stringify(node)` | ||
| * canonical (no `kind` field), keeps `toEqual({...})` test assertions | ||
| * against pre-lift flat shapes passing, and keeps `node.kind` readable | ||
| * for dispatch. | ||
| * | ||
| * Both `kind` and `nodeKind` are required: every concrete leaf is a node | ||
| * the generic differ can pair and compare, so every leaf must declare which | ||
| * node it is. `nodeKind` has no default here — every direct subclass sets its | ||
| * own literal value (the relational leaves via `RelationalSchemaNodeKind`, | ||
| * target concretions via their own vocabulary, e.g. `PostgresSchemaNodeKind`). | ||
| */ | ||
| declare abstract class SqlSchemaIRNode extends IRNodeBase { | ||
| readonly kind: string; | ||
| /** | ||
| * Enumerable discriminant identifying which node this is (column / primary | ||
| * key / foreign key / unique / index / check / database / namespace / | ||
| * table / policy / role / …). Concretions set a unique value; the | ||
| * `.is`/`.assert` guards compare against it. Unlike `kind`, it is | ||
| * enumerable, so it survives a spread that flattens a node into a plain | ||
| * object. | ||
| */ | ||
| abstract readonly nodeKind: string; | ||
| constructor(); | ||
| } | ||
| /** | ||
| * Asserts `node` matches `predicate`, narrowing its type to `T`. The one | ||
| * shared implementation every node class's `static assert` and `isEqualTo` | ||
| * reach for, instead of each hand-writing its own throw: the message names | ||
| * the class the caller expected. | ||
| */ | ||
| declare function assertNode<T extends SqlSchemaIRNode>(node: SqlSchemaIRNode | undefined, className: string, predicate: (node: SqlSchemaIRNode) => node is T): asserts node is T; | ||
| /** | ||
| * Defines a non-enumerable own property, the same treatment `kind` gets | ||
| * above: a derivation-time render-support field stays out of | ||
| * `JSON.stringify`, `toEqual({...})` structural assertions, and spreads, | ||
| * while remaining directly readable (`node.field`) for the one consumer | ||
| * that resolves it at plan time. A no-op when `value` is `undefined` — the | ||
| * property is simply absent, matching every other optional field on these | ||
| * nodes. | ||
| */ | ||
| declare function defineNonEnumerable<T extends object>(target: T, key: string, value: unknown): void; | ||
| //#endregion | ||
| //#region src/ir/primary-key.d.ts | ||
| interface PrimaryKeyInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| /** | ||
| * The key's own column nodes, as root-anchored chains. The derivation | ||
| * stamps them so the primary key is dropped before the columns it is built | ||
| * on. Never compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Primary-key Schema IR node. Mirrors the Contract IR `PrimaryKey` | ||
| * shape (same `columns` + optional `name`) so verification can compare | ||
| * intent and actual structurally. Defined here independently to avoid | ||
| * a sql-schema-ir -> sql-contract dependency. | ||
| * | ||
| * Implements `DiffableNode` so a primary key is directly a table's diff-tree | ||
| * child. `id` is a fixed sentinel — a table has at most one primary key, so | ||
| * there is never a sibling to disambiguate against. `isEqualTo` compares the | ||
| * column tuple; the PK's own `name` is a database-assigned label with no | ||
| * semantic weight, so it is not compared (mirrors the policy node's | ||
| * name-insensitivity to non-identifying detail). | ||
| */ | ||
| declare class PrimaryKey extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-primary-key"; | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| /** See {@link PrimaryKeyInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: PrimaryKeyInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is PrimaryKey; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/schema-node-kinds.d.ts | ||
| /** | ||
| * The `nodeKind` discriminant for each relational schema-diff leaf node. | ||
| * Each node carries a unique value; the differ pairs siblings by `id`, and | ||
| * these kinds distinguish the node types that appear as `PostgresTableSchemaNode` | ||
| * children (columns, primary key, foreign keys, uniques, indexes, checks) from | ||
| * each other and from the RLS policy/role kinds a target defines separately. | ||
| */ | ||
| declare const RelationalSchemaNodeKind: { | ||
| readonly schema: "sql-schema"; | ||
| readonly table: "sql-table"; | ||
| readonly column: "sql-column"; | ||
| readonly columnDefault: "sql-column-default"; | ||
| readonly primaryKey: "sql-primary-key"; | ||
| readonly foreignKey: "sql-foreign-key"; | ||
| readonly unique: "sql-unique"; | ||
| readonly index: "sql-index"; | ||
| readonly check: "sql-check-constraint"; | ||
| }; | ||
| type RelationalSchemaNodeKind = (typeof RelationalSchemaNodeKind)[keyof typeof RelationalSchemaNodeKind]; | ||
| /** | ||
| * Looks up the subject granularity for a relational `nodeKind`. Throws for a | ||
| * `nodeKind` outside this map (a target-specific kind, e.g. Postgres's | ||
| * namespace/table/policy/role) — those map their own kinds directly rather | ||
| * than through this family-level map. | ||
| */ | ||
| declare function relationalNodeGranularity(nodeKind: string): DiffSubjectGranularity; | ||
| /** | ||
| * Looks up the storage `entityKind` for a relational `nodeKind` — sibling of | ||
| * {@link relationalNodeGranularity}, resolved by `nodeKind` equality against | ||
| * {@link RELATIONAL_NODE_ENTITY_KIND}. `undefined` for a target-specific kind | ||
| * (targets map their own kinds directly) or a relational kind with no entity | ||
| * of its own. | ||
| */ | ||
| declare function relationalNodeEntityKind(nodeKind: string): string | undefined; | ||
| //#endregion | ||
| //#region src/ir/sql-check-constraint-ir.d.ts | ||
| interface SqlCheckConstraintIRInput { | ||
| /** Constraint name as stored in the database catalog. */ | ||
| readonly name: string; | ||
| /** Column the check restricts. */ | ||
| readonly column: string; | ||
| /** Permitted values the column must be IN. */ | ||
| readonly permittedValues: readonly string[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a table-level check constraint that restricts a | ||
| * column to a set of permitted values (an enum-style `IN (...)` check). | ||
| * | ||
| * Carries the **resolved values** rather than a raw SQL predicate so | ||
| * callers can compare value-sets without parsing SQL. | ||
| * | ||
| * Implements `DiffableNode` so a check constraint is directly a table's | ||
| * diff-tree child: `id` is the constraint name. `isEqualTo` compares | ||
| * `column` and the permitted-value set (order-insensitive — the database | ||
| * does not guarantee `IN (...)` ordering). | ||
| */ | ||
| declare class SqlCheckConstraintIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-check-constraint"; | ||
| readonly name: string; | ||
| readonly column: string; | ||
| readonly permittedValues: readonly string[]; | ||
| constructor(input: SqlCheckConstraintIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlCheckConstraintIR; | ||
| /** | ||
| * Compares the permitted-value sets only (unordered), matching the | ||
| * relational walk's `verifyCheckConstraints`: two checks pairing by name | ||
| * compare their value sets — the `column` field is descriptive, not part | ||
| * of the comparison, so a name-paired check with equal values verifies | ||
| * regardless of which column carries it. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-column-default-ir.d.ts | ||
| interface SqlColumnDefaultIRInput { | ||
| /** Structured resolved default (contract-declared or normalizer-parsed). */ | ||
| readonly resolved?: ColumnDefault; | ||
| /** Raw database default expression, when known (introspected side). */ | ||
| readonly raw?: string; | ||
| /** | ||
| * Native-type context for temporal literal normalization — the owning | ||
| * column's resolved native type. | ||
| */ | ||
| readonly nativeTypeContext?: string; | ||
| /** | ||
| * The owning column's array-ness, threaded through so the planner's | ||
| * set-default op-builder can render an array-literal default (e.g. | ||
| * `ARRAY[...]`) the same way the pre-`plan(start, end)` op-path did. See | ||
| * {@link import('./sql-column-ir').SqlColumnIRInput.many}. | ||
| */ | ||
| readonly many?: boolean; | ||
| } | ||
| /** | ||
| * Schema-diff node for a column's default value. The default is the one | ||
| * column attribute with an extra/missing/drift lifecycle of its own, so it | ||
| * is a child node of the column rather than a compared attribute: an | ||
| * undeclared live default surfaces as `not-expected`, a declared default the | ||
| * database lacks as `not-found`, and a divergent value as `not-equal` — the | ||
| * three reasons cover the legacy `extra_default` / `default_missing` / | ||
| * `default_mismatch` vocabulary with no attribute inspection. | ||
| * | ||
| * `id` is a fixed sentinel — a column has at most one default. Built | ||
| * transiently by `SqlColumnIR.children()` from the column's own fields; | ||
| * never constructed by derivation or introspection directly. | ||
| */ | ||
| declare class SqlColumnDefaultIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-column-default"; | ||
| readonly resolved?: ColumnDefault; | ||
| readonly raw?: string; | ||
| readonly nativeTypeContext?: string; | ||
| /** See {@link SqlColumnDefaultIRInput.many}. Non-enumerable so it stays out of JSON and structural equality. */ | ||
| readonly many?: boolean; | ||
| constructor(input: SqlColumnDefaultIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlColumnDefaultIR; | ||
| /** | ||
| * Structured comparison with `this` as the expected side: both sides | ||
| * resolved compare per the relational walk's `columnDefaultsEqual` | ||
| * semantics; a declared expected default against an unparseable actual | ||
| * (raw present, no resolved parse) is a mismatch; two raw-only nodes fall | ||
| * back to raw string equality. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-column-ir.d.ts | ||
| /** | ||
| * Namespaced annotations for extensibility. Each namespace | ||
| * (e.g. `pg`, `pgvector`) owns its annotations subtree. | ||
| */ | ||
| type SqlAnnotations = { | ||
| readonly [namespace: string]: unknown; | ||
| }; | ||
| interface SqlColumnIRInput { | ||
| readonly name: string; | ||
| readonly nativeType: string; | ||
| readonly nullable: boolean; | ||
| /** Raw database default expression (e.g. `'hello'::text`, `nextval('seq')`). */ | ||
| readonly default?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** True when the column is a native array (e.g. `text[]`, `int4[]`). The `nativeType` carries the element type only (e.g. `text`, `int4`). */ | ||
| readonly many?: boolean; | ||
| /** | ||
| * Fully resolved native type, comparable across the two diff sides: | ||
| * the contract-derived side stamps the codec-expanded type (typeRef | ||
| * resolved, parameterized types expanded, `[]` appended for arrays); | ||
| * the introspected side stamps the target-normalized type with the same | ||
| * `[]` convention. Stamped at construction by derivation/introspection; | ||
| * absent on raw hand-built nodes. | ||
| */ | ||
| readonly resolvedNativeType?: string; | ||
| /** | ||
| * Structured default, comparable across the two diff sides: the | ||
| * contract-derived side stamps the contract's `ColumnDefault`; the | ||
| * introspected side stamps the target default-normalizer's parse of the | ||
| * raw expression. Absent when the column declares no default, or when | ||
| * the introspected raw default could not be parsed. | ||
| */ | ||
| readonly resolvedDefault?: ColumnDefault; | ||
| /** | ||
| * The column's resolved codec reference — the identity the migration | ||
| * planner's op-builders resolve DDL type rendering against at plan time | ||
| * (parameterized type expansion, e.g. `character` + `{ length: 36 }` → | ||
| * `character(36)`), calling the same codec hooks the pre-`plan(start, | ||
| * end)` op-path called. Carried the same way the query AST carries | ||
| * `CodecRef` (TML-2456) and the migration DDL renderer (TML-2918). | ||
| * Stamped on the EXPECTED (contract-derived) column at derivation, | ||
| * post-`typeRef` resolution (the referenced storage type's own | ||
| * codec/params, not the column's `typeRef` pointer). Absent on | ||
| * introspected/hand-built nodes — the actual side never renders DDL — | ||
| * and never compared by `isEqualTo`. | ||
| */ | ||
| readonly codecRef?: CodecRef; | ||
| /** | ||
| * The column's resolved BASE native type: pre-parameter-expansion, | ||
| * pre-array-suffix (e.g. `character`, not `character(36)` or | ||
| * `character[]`). Distinct from {@link resolvedNativeType} (the EXPANDED | ||
| * comparison value) — DDL rendering re-expands a parameterized type at | ||
| * plan time from this base, so it must not already carry the expansion. | ||
| * Stamped alongside {@link codecRef}. | ||
| */ | ||
| readonly codecBaseNativeType?: string; | ||
| /** | ||
| * True when the contract column declared its type via a named | ||
| * `storage.types` reference (`typeRef`) rather than inline fields — the | ||
| * migration planner quotes the base native type as an identifier in this | ||
| * case (e.g. a native enum's type name), matching the pre-`plan(start, | ||
| * end)` rendering exactly. | ||
| */ | ||
| readonly codecNamedType?: boolean; | ||
| } | ||
| /** | ||
| * Schema IR node for a single column on a table, as observed by | ||
| * introspection. Unlike the Contract IR `StorageColumn`, this carries | ||
| * the column's `name` (Schema IR columns are returned as arrays from | ||
| * introspection queries; the parent table re-keys them into a record | ||
| * for downstream consumers). | ||
| * | ||
| * Implements `DiffableNode` so a column is directly a table's diff-tree | ||
| * child: `id` is the column name (unique among a table's columns); `isEqualTo` | ||
| * compares this column's own attributes only — never children, since a | ||
| * column is a leaf. When both sides carry `resolvedNativeType` (stamped at | ||
| * derivation/introspection), the comparison uses the resolved values — | ||
| * resolved native type, nullability, and structured default equality per | ||
| * the relational walk's `columnDefaultsEqual` semantics, with `this` as the | ||
| * expected side. Otherwise it falls back to comparing raw fields. | ||
| */ | ||
| declare class SqlColumnIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-column"; | ||
| readonly name: string; | ||
| readonly nativeType: string; | ||
| readonly nullable: boolean; | ||
| readonly default?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** True when the column is a native array (e.g. `text[]`, `int4[]`). The `nativeType` carries the element type only (e.g. `text`, `int4`). */ | ||
| readonly many?: boolean; | ||
| readonly resolvedNativeType?: string; | ||
| readonly resolvedDefault?: ColumnDefault; | ||
| /** See {@link SqlColumnIRInput.codecRef}. Non-enumerable so it stays out of JSON and structural equality. */ | ||
| readonly codecRef?: CodecRef; | ||
| /** See {@link SqlColumnIRInput.codecBaseNativeType}. Non-enumerable, same reason as {@link codecRef}. */ | ||
| readonly codecBaseNativeType?: string; | ||
| /** See {@link SqlColumnIRInput.codecNamedType}. Non-enumerable, same reason as {@link codecRef}. */ | ||
| readonly codecNamedType?: boolean; | ||
| constructor(input: SqlColumnIRInput); | ||
| get id(): string; | ||
| /** | ||
| * The column's default, when declared/present, is the column's one child | ||
| * node — it has an extra/missing/drift lifecycle of its own, so the differ | ||
| * recurses to it rather than `isEqualTo` comparing it. Built transiently | ||
| * from this column's own fields. | ||
| */ | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlColumnIR; | ||
| /** | ||
| * Compares the column's own attributes only — the default lives on the | ||
| * child node. When both sides carry `resolvedNativeType`, the resolved | ||
| * value governs (array-ness rides on its `[]` suffix); otherwise raw | ||
| * fields compare. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-foreign-key-ir.d.ts | ||
| type SqlReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'; | ||
| interface SqlForeignKeyIRInput { | ||
| readonly columns: readonly string[]; | ||
| readonly referencedTable: string; | ||
| readonly referencedColumns: readonly string[]; | ||
| /** Schema (namespace) of the referenced table — populated by adapters that introspect cross-schema FKs. */ | ||
| readonly referencedSchema?: string; | ||
| readonly name?: string; | ||
| readonly onDelete?: SqlReferentialAction; | ||
| readonly onUpdate?: SqlReferentialAction; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** | ||
| * The real live DDL namespace of the referenced table, comparable across | ||
| * the two diff sides. Contract-derived trees stamp it explicitly (resolving | ||
| * namespace ids — including the unbound sentinel — to the DDL namespace); | ||
| * introspected FKs default it to `referencedSchema`, whose value already | ||
| * is the live namespace. Folded into `id` in place of the raw value so an | ||
| * unbound-namespace contract FK pairs with its introspected counterpart. | ||
| */ | ||
| readonly resolvedReferencedNamespace?: string; | ||
| /** | ||
| * The referenced table's node, as the root-anchored chain the differ pairs | ||
| * siblings with. Stamped by the derivation, which holds the parent | ||
| * (database/namespace) context the chain's shape depends on. Never | ||
| * compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a foreign-key constraint as observed by | ||
| * introspection. The `referencedTable` / `referencedColumns` field | ||
| * names match the introspection vocabulary (`pg_constraint.confkey`, | ||
| * etc.) and intentionally differ from the Contract IR's nested | ||
| * `references: { table, columns }` shape so that the verifier's | ||
| * structural comparison stays explicit about which side it's reading. | ||
| * | ||
| * Implements `DiffableNode` so a foreign key is directly a table's diff-tree | ||
| * child. Foreign keys are frequently unnamed (introspection may not carry a | ||
| * constraint name, and the contract side never invents one), so `id` is | ||
| * derived from the referencing/referenced coordinates rather than `name` — | ||
| * the same tuple that makes two FK constraints the same constraint. This | ||
| * also serves as the comparison key: two FKs with the same coordinates are | ||
| * paired by the differ, and `isEqualTo` then compares the remaining | ||
| * attribute — the referential actions. | ||
| */ | ||
| declare class SqlForeignKeyIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-foreign-key"; | ||
| readonly columns: readonly string[]; | ||
| readonly referencedTable: string; | ||
| readonly referencedColumns: readonly string[]; | ||
| readonly referencedSchema?: string; | ||
| readonly name?: string; | ||
| readonly onDelete?: SqlReferentialAction; | ||
| readonly onUpdate?: SqlReferentialAction; | ||
| readonly annotations?: SqlAnnotations; | ||
| readonly resolvedReferencedNamespace?: string; | ||
| /** See {@link SqlForeignKeyIRInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: SqlForeignKeyIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlForeignKeyIR; | ||
| /** | ||
| * Referential-action comparison with `this` as the expected side, matching | ||
| * the relational walk's `getReferentialActionMismatches`: `noAction` is the | ||
| * database default and equivalent to an undeclared action, and drift is | ||
| * flagged only when the expected side declares a (normalized) action. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-index-ir.d.ts | ||
| interface SqlIndexIRInput { | ||
| readonly columns: readonly string[]; | ||
| readonly unique: boolean; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** | ||
| * The index's own column nodes, as root-anchored chains. The derivation | ||
| * stamps them so an index is dropped before the columns it is built on | ||
| * (Postgres auto-drops the index when a covered column goes). Never | ||
| * compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a secondary index as observed by introspection. | ||
| * Unlike the Contract IR `Index`, the Schema IR carries an explicit | ||
| * `unique` field — introspection sees the underlying index regardless | ||
| * of whether the user expressed it as `@@index` or `@@unique`, and the | ||
| * verifier needs to distinguish them when comparing to the Contract. | ||
| * | ||
| * Implements `DiffableNode` so an index is directly a table's diff-tree | ||
| * child. Indexes are frequently unnamed, so `id` is derived from the column | ||
| * tuple — the same tuple that makes two indexes the same index, so it | ||
| * doubles as the pairing key. `isEqualTo` is symmetric structural equality | ||
| * on the remaining attributes: `unique`, `type`, and `options`. A unique | ||
| * index and a non-unique index on the same columns are different objects | ||
| * and are not equal — there is no "stronger satisfies weaker". | ||
| * | ||
| * Deliberately column-tuple-only (not `unique`): a contract `@@index` | ||
| * (non-unique) must still pair against a live unique index of the same | ||
| * columns so the differ can report the mismatch as an incompatible index | ||
| * change rather than a spurious missing+extra pair — see | ||
| * `planner.unique-index-structural.test.ts`. The corollary is that two | ||
| * indexes legitimately coexisting on one table with the *same* column tuple | ||
| * (e.g. a unique index and a redundant plain index Postgres has no problem | ||
| * hosting side by side) collide on this id; the postgres control adapter's | ||
| * introspection keeps only one such index per table+column-tuple rather | ||
| * than handing the differ two same-tree siblings it cannot represent. | ||
| */ | ||
| declare class SqlIndexIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-index"; | ||
| readonly columns: readonly string[]; | ||
| readonly unique: boolean; | ||
| readonly name?: string; | ||
| readonly type?: string; | ||
| readonly options?: Record<string, unknown>; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** See {@link SqlIndexIRInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: SqlIndexIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlIndexIR; | ||
| /** | ||
| * Symmetric structural equality: two paired index nodes are equal iff their | ||
| * `unique` flag, `type`, and (loosely-compared) `options` all match. There | ||
| * is no satisfaction — a unique index does not equal a non-unique index. | ||
| * `options` compares loosely (introspection stringifies reloptions); `type` | ||
| * compares strictly after the introspection-side btree→undefined | ||
| * normalization done at construction. | ||
| */ | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-unique-ir.d.ts | ||
| interface SqlUniqueIRInput { | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** | ||
| * The constraint's own column nodes, as root-anchored chains. The | ||
| * derivation stamps them so a unique constraint is dropped before the | ||
| * columns it is built on. Never compared by `isEqualTo`. | ||
| */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| } | ||
| /** | ||
| * Schema IR node for a table-level unique constraint as observed by | ||
| * introspection. | ||
| * | ||
| * Implements `DiffableNode` so a unique constraint is directly a table's | ||
| * diff-tree child. Unique constraints are frequently unnamed, so `id` is | ||
| * derived from the column tuple rather than `name` — the column tuple is | ||
| * also what makes two unique constraints the same constraint, so it doubles | ||
| * as the pairing key. There are no further attributes to compare once | ||
| * columns are equal (the differ pairs on `id`), so `isEqualTo` is identity. | ||
| */ | ||
| declare class SqlUniqueIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-unique"; | ||
| readonly columns: readonly string[]; | ||
| readonly name?: string; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** See {@link SqlUniqueIRInput.dependsOn}. Non-enumerable so it stays out of JSON and structural equality, matching `SqlColumnIR.codecRef`. */ | ||
| readonly dependsOn?: readonly SchemaNodeRef[]; | ||
| constructor(input: SqlUniqueIRInput); | ||
| get id(): string; | ||
| children(): readonly DiffableNode[]; | ||
| static is(node: SqlSchemaIRNode): node is SqlUniqueIR; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-table-ir.d.ts | ||
| interface SqlTableIRInput { | ||
| readonly name: string; | ||
| readonly columns: Record<string, SqlColumnIR | SqlColumnIRInput>; | ||
| readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR | SqlForeignKeyIRInput>; | ||
| readonly uniques: ReadonlyArray<SqlUniqueIR | SqlUniqueIRInput>; | ||
| readonly indexes: ReadonlyArray<SqlIndexIR | SqlIndexIRInput>; | ||
| readonly primaryKey?: PrimaryKey | PrimaryKeyInput; | ||
| readonly annotations?: SqlAnnotations; | ||
| /** Optional check constraints for enum-restricted columns. Omitted when none present. */ | ||
| readonly checks?: ReadonlyArray<SqlCheckConstraintIR | SqlCheckConstraintIRInput>; | ||
| } | ||
| /** | ||
| * Schema IR node for a single table as observed by introspection. | ||
| * | ||
| * Unlike the Contract IR `StorageTable`, this carries the table's | ||
| * `name` — introspection queries return tables as arrays and the | ||
| * verifier keys them into `SqlSchemaIR.tables` afterwards, so the name | ||
| * stays on the table object for downstream call sites that walk | ||
| * `Object.values(schema.tables)`. | ||
| * | ||
| * The constructor normalises nested IR-class fields so downstream | ||
| * walks see a uniform AST regardless of whether the input was a | ||
| * plain-data literal (from introspection) or already-constructed | ||
| * class instances. | ||
| * | ||
| * Implements `DiffableNode` so a flat (single-schema) tree is directly | ||
| * diffable: `id` is the table name; `isEqualTo` is identity (the table's | ||
| * structural drift is entirely expressed by its children); `children()` | ||
| * yields every column, the primary key (when present), every foreign key, | ||
| * unique, index, and check constraint — the same composition and order as | ||
| * the Postgres table node, minus policies. | ||
| */ | ||
| declare class SqlTableIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-table"; | ||
| readonly name: string; | ||
| readonly columns: Readonly<Record<string, SqlColumnIR>>; | ||
| readonly foreignKeys: ReadonlyArray<SqlForeignKeyIR>; | ||
| readonly uniques: ReadonlyArray<SqlUniqueIR>; | ||
| readonly indexes: ReadonlyArray<SqlIndexIR>; | ||
| readonly primaryKey?: PrimaryKey; | ||
| readonly annotations?: SqlAnnotations; | ||
| readonly checks?: ReadonlyArray<SqlCheckConstraintIR>; | ||
| constructor(input: SqlTableIRInput); | ||
| get id(): string; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| children(): readonly DiffableNode[]; | ||
| } | ||
| //#endregion | ||
| //#region src/ir/sql-schema-ir.d.ts | ||
| interface SqlSchemaIRInput { | ||
| readonly tables: Record<string, SqlTableIR | SqlTableIRInput>; | ||
| readonly annotations?: SqlAnnotations; | ||
| } | ||
| /** | ||
| * Root Schema IR node representing the complete database schema as | ||
| * observed by introspection. Target-agnostic; used by both verifiers | ||
| * (compare against intended Contract storage) and migration planners | ||
| * (derive operations needed to reconcile). | ||
| * | ||
| * The constructor normalises nested `SqlTableIR` instances so | ||
| * downstream walks see a uniform AST regardless of whether the input | ||
| * was a plain-data literal or already-constructed class instances. | ||
| * | ||
| * Implements `DiffableNode` as the root of a flat (single-schema) diff | ||
| * tree: `id` is the fixed sentinel `'database'` (roots have no siblings), | ||
| * `isEqualTo` is identity (a container has no own attributes), and | ||
| * `children()` yields the table nodes. | ||
| */ | ||
| declare class SqlSchemaIR extends SqlSchemaIRNode implements DiffableNode { | ||
| readonly nodeKind: "sql-schema"; | ||
| readonly tables: Readonly<Record<string, SqlTableIR>>; | ||
| readonly annotations?: SqlAnnotations; | ||
| constructor(input: SqlSchemaIRInput); | ||
| get id(): string; | ||
| isEqualTo(other: DiffableNode): boolean; | ||
| children(): readonly DiffableNode[]; | ||
| } | ||
| //#endregion | ||
| //#region src/types.d.ts | ||
| /** | ||
| * SQL type metadata for control-plane and execution-plane type | ||
| * availability and mapping. Read-only view of type information | ||
| * without encode/decode behavior. | ||
| */ | ||
| interface SqlTypeMetadata { | ||
| /** Namespaced type identifier, e.g. `pg/int4@1`, `pg/text@1`. */ | ||
| readonly typeId: string; | ||
| /** Contract scalar type IDs this type can handle. */ | ||
| readonly targetTypes: readonly string[]; | ||
| /** | ||
| * Native database type name (target-specific). Optional because | ||
| * not all types have a native database representation. | ||
| */ | ||
| readonly nativeType?: string; | ||
| } | ||
| /** | ||
| * Registry interface for SQL type metadata. Provides read-only | ||
| * iteration over type metadata entries. | ||
| */ | ||
| interface SqlTypeMetadataRegistry { | ||
| values(): IterableIterator<SqlTypeMetadata>; | ||
| } | ||
| //#endregion | ||
| export { relationalNodeGranularity as C, assertNode as D, SqlSchemaIRNode as E, defineNonEnumerable as O, relationalNodeEntityKind as S, PrimaryKeyInput as T, SqlColumnDefaultIR as _, SqlTableIR as a, SqlCheckConstraintIRInput as b, SqlUniqueIRInput as c, SqlForeignKeyIR as d, SqlForeignKeyIRInput as f, SqlColumnIRInput as g, SqlColumnIR as h, SqlSchemaIRInput as i, SqlIndexIR as l, SqlAnnotations as m, SqlTypeMetadataRegistry as n, SqlTableIRInput as o, SqlReferentialAction as p, SqlSchemaIR as r, SqlUniqueIR as s, SqlTypeMetadata as t, SqlIndexIRInput as u, SqlColumnDefaultIRInput as v, PrimaryKey as w, RelationalSchemaNodeKind as x, SqlCheckConstraintIR as y }; | ||
| //# sourceMappingURL=types-CeJhPT7f.d.mts.map |
| {"version":3,"file":"types-CeJhPT7f.d.mts","names":[],"sources":["../src/ir/sql-schema-ir-node.ts","../src/ir/primary-key.ts","../src/ir/schema-node-kinds.ts","../src/ir/sql-check-constraint-ir.ts","../src/ir/sql-column-default-ir.ts","../src/ir/sql-column-ir.ts","../src/ir/sql-foreign-key-ir.ts","../src/ir/sql-index-ir.ts","../src/ir/sql-unique-ir.ts","../src/ir/sql-table-ir.ts","../src/ir/sql-schema-ir.ts","../src/types.ts"],"mappings":";;;;;;;;;;;AAuBA;;;;;;;;;;AA8BA;;;;;;uBA9BsB,eAAA,SAAwB,UAAU;EAAA,SACrC,IAAA;EAiCC;;;;;;;;EAAA,kBAvBA,QAAA;;;;;;;AAuBA;AAepB;iBAnBgB,UAAA,WAAqB,eAAA,EACnC,IAAA,EAAM,eAAA,cACN,SAAA,UACA,SAAA,GAAY,IAAA,EAAM,eAAA,KAAoB,IAAA,IAAQ,CAAA,WACrC,IAAA,IAAQ,CAAA;;;;;;;;;AAkBH;iBAHA,mBAAA,mBACd,MAAA,EAAQ,CAAC,EACT,GAAA,UACA,KAAA;;;UCrEe,eAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;;ADeX;;;;WCTW,SAAA,YAAqB,aAAa;AAAA;;;;;ADuC7C;;;;;;;;;cCvBa,UAAA,SAAmB,eAAA,YAA2B,YAAA;EAAA,SACvC,QAAA;EAAA,SAET,OAAA;EAAA,SACQ,IAAA;ED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