@prisma-next/sql-contract 0.16.0-dev.25 → 0.16.0-dev.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/canonicalization-hooks.d.mts.map +1 -1
- package/dist/canonicalization-hooks.mjs +10 -0
- package/dist/canonicalization-hooks.mjs.map +1 -1
- package/dist/contract-view.d.mts +1 -1
- package/dist/{entity-kinds-La8Jg-jW.mjs → entity-kinds-CdHJQGi0.mjs} +9 -5
- package/dist/entity-kinds-CdHJQGi0.mjs.map +1 -0
- package/dist/entity-kinds.d.mts +1 -1
- package/dist/entity-kinds.mjs +1 -1
- package/dist/factories.d.mts +10 -4
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +11 -3
- package/dist/factories.mjs.map +1 -1
- package/dist/foreign-key-materialization.d.mts +7 -6
- package/dist/foreign-key-materialization.d.mts.map +1 -1
- package/dist/foreign-key-materialization.mjs +12 -9
- package/dist/foreign-key-materialization.mjs.map +1 -1
- package/dist/index-naming-DsnarUVW.mjs +43 -0
- package/dist/index-naming-DsnarUVW.mjs.map +1 -0
- package/dist/index-naming.d.mts +25 -0
- package/dist/index-naming.d.mts.map +1 -0
- package/dist/index-naming.mjs +2 -0
- package/dist/index-type-validation.d.mts +2 -2
- package/dist/index-type-validation.mjs +3 -3
- package/dist/index-type-validation.mjs.map +1 -1
- package/dist/resolve-storage-table.d.mts +2 -2
- package/dist/sql-index-Wzbj2nbH.d.mts +79 -0
- package/dist/sql-index-Wzbj2nbH.d.mts.map +1 -0
- package/dist/{sql-storage-BIErcfFA.d.mts → sql-storage-DjqU3XXV.d.mts} +2 -2
- package/dist/{sql-storage-BIErcfFA.d.mts.map → sql-storage-DjqU3XXV.d.mts.map} +1 -1
- package/dist/{storage-table-9O0ZNiMs.mjs → storage-table-DKTrkwZt.mjs} +28 -5
- package/dist/storage-table-DKTrkwZt.mjs.map +1 -0
- package/dist/{storage-table-mNGckl3_.d.mts → storage-table-zrxIuCJ3.d.mts} +3 -2
- package/dist/storage-table-zrxIuCJ3.d.mts.map +1 -0
- package/dist/{storage-value-set-DiGJT-LT.mjs → storage-value-set-DdL4oin-.mjs} +2 -2
- package/dist/{storage-value-set-DiGJT-LT.mjs.map → storage-value-set-DdL4oin-.mjs.map} +1 -1
- package/dist/{types-lpzJtKpv.d.mts → types-Bxa1Pyzg.d.mts} +5 -4
- package/dist/types-Bxa1Pyzg.d.mts.map +1 -0
- package/dist/types.d.mts +5 -4
- package/dist/types.d.mts.map +1 -1
- package/dist/types.mjs +2 -2
- package/dist/unique-constraint-Bp-q-mr-.d.mts +31 -0
- package/dist/unique-constraint-Bp-q-mr-.d.mts.map +1 -0
- package/dist/validators.d.mts +15 -7
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +8 -5
- package/dist/validators.mjs.map +1 -1
- package/package.json +9 -8
- package/src/canonicalization-hooks.ts +4 -0
- package/src/exports/index-naming.ts +1 -0
- package/src/factories.ts +19 -2
- package/src/foreign-key-materialization.ts +18 -11
- package/src/index-naming.ts +65 -0
- package/src/index-type-validation.ts +3 -3
- package/src/ir/sql-index.ts +94 -11
- package/src/ir/storage-entry-schemas.ts +6 -2
- package/src/validators.ts +7 -4
- package/dist/entity-kinds-La8Jg-jW.mjs.map +0 -1
- package/dist/storage-table-9O0ZNiMs.mjs.map +0 -1
- package/dist/storage-table-mNGckl3_.d.mts.map +0 -1
- package/dist/types-lpzJtKpv.d.mts.map +0 -1
- package/dist/unique-constraint-WHfanEUq.d.mts +0 -54
- package/dist/unique-constraint-WHfanEUq.d.mts.map +0 -1
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { IRNodeBase, freezeNode } from "@prisma-next/framework-components/ir";
|
|
2
2
|
import { InternalError } from "@prisma-next/utils/internal-error";
|
|
3
3
|
import { asNamespaceId } from "@prisma-next/contract/types";
|
|
4
|
+
import { ContractValidationError } from "@prisma-next/contract/contract-validation-error";
|
|
5
|
+
import { formatWireName, parseWireName } from "@prisma-next/sql-schema-ir/naming";
|
|
4
6
|
//#region src/ir/sql-node.ts
|
|
5
7
|
/**
|
|
6
8
|
* SQL family IR node base. Carries the family-level `kind` discriminator
|
|
@@ -157,7 +159,17 @@ var PrimaryKey = class extends SqlNode {
|
|
|
157
159
|
//#endregion
|
|
158
160
|
//#region src/ir/sql-index.ts
|
|
159
161
|
/**
|
|
160
|
-
* SQL Contract IR node for a table-level secondary index
|
|
162
|
+
* SQL Contract IR node for a table-level secondary index, name-identified:
|
|
163
|
+
* `name` is the full physical name; a present `prefix` marks the index as
|
|
164
|
+
* managed (`name` is `formatWireName(prefix, <8hex>)`), an absent `prefix`
|
|
165
|
+
* marks it exact (the name is adopted verbatim).
|
|
166
|
+
*
|
|
167
|
+
* `expression`, `where`, and `unique` are genuine SQL-family attributes —
|
|
168
|
+
* functional and partial indexes are standard SQL supported natively by
|
|
169
|
+
* Postgres and SQLite alike, and the family IR must be able to represent
|
|
170
|
+
* anything any SQL target can introspect. A target declining to AUTHOR them
|
|
171
|
+
* (SQLite's rejection at namespace construction) is a capability decision,
|
|
172
|
+
* not evidence of target-specificity.
|
|
161
173
|
*
|
|
162
174
|
* Note that this class shadows the global TypeScript `Index` lib type
|
|
163
175
|
* at the family-shared name; consumer files that need both should
|
|
@@ -165,11 +177,22 @@ var PrimaryKey = class extends SqlNode {
|
|
|
165
177
|
* `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).
|
|
166
178
|
*/
|
|
167
179
|
var Index = class extends SqlNode {
|
|
168
|
-
|
|
180
|
+
name;
|
|
181
|
+
unique;
|
|
169
182
|
constructor(input) {
|
|
170
183
|
super();
|
|
171
|
-
|
|
172
|
-
if (input.
|
|
184
|
+
if (input.name === void 0 || input.name.length === 0) throw new ContractValidationError("Index: every index carries a full physical name; an expression index must be explicitly named (a default name cannot be derived from an expression).", "storage");
|
|
185
|
+
if (input.columns === void 0 === (input.expression === void 0)) throw new ContractValidationError(`Index "${input.name}": exactly one of columns or expression must be set.`, "storage");
|
|
186
|
+
if (input.prefix !== void 0) {
|
|
187
|
+
const parsed = parseWireName(input.name);
|
|
188
|
+
if (parsed === void 0 || parsed.prefix !== input.prefix) throw new ContractValidationError(`Index "${input.name}": prefix "${input.prefix}" does not match the wire name (expected "${formatWireName(input.prefix, "<8hex>")}").`, "storage");
|
|
189
|
+
}
|
|
190
|
+
this.name = input.name;
|
|
191
|
+
this.unique = input.unique;
|
|
192
|
+
if (input.prefix !== void 0) this.prefix = input.prefix;
|
|
193
|
+
if (input.columns !== void 0) this.columns = input.columns;
|
|
194
|
+
if (input.expression !== void 0) this.expression = input.expression;
|
|
195
|
+
if (input.where !== void 0) this.where = input.where;
|
|
173
196
|
if (input.type !== void 0) this.type = input.type;
|
|
174
197
|
if (input.options !== void 0) this.options = input.options;
|
|
175
198
|
freezeNode(this);
|
|
@@ -270,4 +293,4 @@ var StorageTable = class StorageTable extends SqlNode {
|
|
|
270
293
|
//#endregion
|
|
271
294
|
export { PrimaryKey as a, CheckConstraint as c, Index as i, SqlNode as l, UniqueConstraint as n, ForeignKey as o, StorageColumn as r, ForeignKeyReference as s, StorageTable as t };
|
|
272
295
|
|
|
273
|
-
//# sourceMappingURL=storage-table-
|
|
296
|
+
//# sourceMappingURL=storage-table-DKTrkwZt.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-table-DKTrkwZt.mjs","names":[],"sources":["../src/ir/sql-node.ts","../src/ir/check-constraint.ts","../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts","../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/storage-column.ts","../src/ir/unique-constraint.ts","../src/ir/storage-table.ts"],"sourcesContent":["import { IRNodeBase } from '@prisma-next/framework-components/ir';\n\n/**\n * SQL family IR node base. Carries the family-level `kind` discriminator\n * `'sql'` and inherits the framework's `freezeNode` affordance.\n *\n * Single family-level discriminator (not per-leaf) reflects the fact that\n * SQL IR has no polymorphic dispatch today — verifiers and serializers\n * walk by structural position (`storage.tables[name].columns[name]`),\n * not by inspecting `kind`. The abstract bar for per-leaf discriminators\n * isn't earned until a future polymorphic consumer arrives.\n *\n * `kind` is installed as a non-enumerable own property on every instance,\n * which keeps three things clean simultaneously:\n *\n * - `JSON.stringify(node)` produces the canonical pre-lift JSON envelope\n * shape (no `kind` field), so emitted contract.json files and the\n * `validateSqlContractFully` arktype schemas stay unchanged.\n * - Test assertions that use `toEqual({...})` against the pre-lift flat\n * shape continue to pass — only enumerable own properties are\n * compared.\n * - Direct access (`node.kind`) and runtime narrowing\n * (`if (node.kind === 'sql')`) still work, so future polymorphic\n * dispatch can begin reading `kind` without a runtime change.\n *\n * Future per-leaf overrides land cleanly: a class that gains a\n * polymorphic-dispatch consumer (e.g. an enum type instance walked\n * alongside other types) overrides `kind` with its narrower literal\n * at that leaf level. Per-leaf overrides will use enumerable kind\n * (matching the Mongo per-class-discriminator precedent) because they\n * encode dispatch-relevant information that callers need to see in\n * JSON envelopes; the family-level `'sql'` is uniform across all SQL\n * IR and carries no dispatch-relevant information.\n */\nexport abstract class SqlNode extends IRNodeBase {\n readonly kind?: string;\n\n constructor() {\n super();\n Object.defineProperty(this, 'kind', {\n value: 'sql',\n writable: false,\n enumerable: false,\n // configurable so per-leaf subclasses (e.g. StorageValueSet)\n // can override `kind` with their narrower\n // enumerable literal via a class-field initializer. SqlNode\n // itself never needs to mutate the property again, so\n // configurability has no surface impact at this layer.\n configurable: true,\n });\n }\n}\n","import type { ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link CheckConstraint}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface CheckConstraintInput {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a table-level check constraint that restricts\n * a column to the permitted values of a value-set.\n *\n * The constraint is **structured** (names a column and a value-set\n * reference), not a raw SQL expression. Each target renders its own DDL\n * from the structured form, keeping the contract target-agnostic.\n *\n * Construction is idempotent: passing an existing `CheckConstraint`\n * instance as input produces a new instance with identical fields.\n * The constructor does not use `instanceof` for input discrimination —\n * it reads plain named properties, which is sufficient since\n * `CheckConstraintInput` is a structural type.\n */\nexport class CheckConstraint extends SqlNode {\n readonly name: string;\n readonly column: string;\n readonly valueSet: ValueSetRef;\n\n constructor(input: CheckConstraintInput) {\n super();\n this.name = input.name;\n this.column = input.column;\n this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { asNamespaceId, type NamespaceId } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Input for a foreign-key reference (one side of a foreign-key declaration).\n *\n * When `spaceId` is absent the reference is local — the referenced table lives\n * in the same contract-space. When `spaceId` is present the reference is\n * cross-space — the referenced table lives in a different contract-space\n * identified by `spaceId`.\n *\n * Presence-based discrimination keeps local FK JSON byte-identical to\n * contracts authored before cross-space support was added.\n */\nexport interface ForeignKeyReferenceInput {\n readonly namespaceId: string;\n readonly tableName: string;\n readonly columns: readonly string[];\n readonly spaceId?: string;\n}\n\n/**\n * SQL Contract IR node for one side (source or target) of a foreign-key\n * declaration. Carries the full coordinate: namespace, table, and columns.\n *\n * Cross-space discrimination is based on `spaceId` presence: absent means\n * local (same contract-space); present means cross-space (the referenced\n * table lives in the contract-space identified by `spaceId`).\n *\n * For local references `spaceId` is absent from JSON, keeping the serialized\n * shape byte-identical to contracts authored before cross-space support was\n * added. For cross-space references `spaceId` appears in JSON so round-trips\n * are lossless.\n *\n * Use `UNBOUND_NAMESPACE_ID` from `@prisma-next/framework-components/ir`\n * as the sentinel `namespaceId` for single-namespace (unbound) references.\n */\nexport class ForeignKeyReference extends SqlNode {\n readonly namespaceId: NamespaceId;\n readonly tableName: string;\n readonly columns: readonly string[];\n declare readonly spaceId?: string;\n\n constructor(input: ForeignKeyReferenceInput) {\n super();\n this.namespaceId = asNamespaceId(input.namespaceId);\n this.tableName = input.tableName;\n this.columns = input.columns;\n if (input.spaceId !== undefined) this.spaceId = input.spaceId;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { ForeignKeyReference, type ForeignKeyReferenceInput } from './foreign-key-reference';\nimport { SqlNode } from './sql-node';\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport interface ForeignKeyInput {\n readonly source: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly target: ForeignKeyReference | ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n}\n\n/**\n * SQL Contract IR node for a table-level foreign-key declaration — the\n * referential constraint only (source, target, `onDelete`/`onUpdate`).\n *\n * A persisted `foreignKeys[]` entry always denotes a real constraint: whether\n * to emit the constraint at all, and whether to back it with an index, are\n * authoring-time decisions (PSL `@relation(index:)`, TS `fk({ constraint,\n * index })`) resolved once at `contract emit` — a `constraint: false` FK\n * simply has no entry here, and a backing index (if any) is its own discrete,\n * named entry in the table's `indexes[]`.\n *\n * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}\n * coordinates (namespace, table, columns). For single-namespace contracts the\n * sentinel `UNBOUND_NAMESPACE_ID` appears on both sides.\n *\n * The nested references are normalised to {@link ForeignKeyReference}\n * instances inside the constructor so downstream walks see a uniform AST\n * regardless of whether the input was a JSON literal or an already-constructed\n * class instance.\n */\nexport class ForeignKey extends SqlNode {\n readonly source: ForeignKeyReference;\n readonly target: ForeignKeyReference;\n declare readonly name?: string;\n declare readonly onDelete?: ReferentialAction;\n declare readonly onUpdate?: ReferentialAction;\n\n constructor(input: ForeignKeyInput) {\n super();\n this.source =\n input.source instanceof ForeignKeyReference\n ? input.source\n : new ForeignKeyReference(input.source);\n this.target =\n input.target instanceof ForeignKeyReference\n ? input.target\n : new ForeignKeyReference(input.target);\n if (input.name !== undefined) this.name = input.name;\n if (input.onDelete !== undefined) this.onDelete = input.onDelete;\n if (input.onUpdate !== undefined) this.onUpdate = input.onUpdate;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface PrimaryKeyInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table's primary-key constraint.\n */\nexport class PrimaryKey extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: PrimaryKeyInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { formatWireName, parseWireName } from '@prisma-next/sql-schema-ir/naming';\nimport { SqlNode } from './sql-node';\n\n/**\n * An index's element structure — exactly one of a column tuple or an opaque\n * expression, made unrepresentable-otherwise at the type level. No\n * discriminant is stored: the JSON shape stays flat (`columns` or\n * `expression`, never both), and the runtime xor guard in the constructor\n * remains as the backstop for JSON loads that bypass this input type.\n */\nexport type IndexElements =\n | {\n /** Column-tuple elements. */\n readonly columns: readonly string[];\n readonly expression?: never;\n }\n | {\n readonly columns?: never;\n /**\n * Opaque SQL: the entire element list between the parens of CREATE\n * INDEX — one string, never parsed.\n */\n readonly expression: string;\n };\n\n/**\n * Construction input for {@link Index}. Internal seam (built by lowering and\n * FK materialization, not by end users), so every non-element key is\n * required and absence is stated explicitly as `undefined` — matching the\n * `SqlIndexIRInput` convention.\n */\nexport type IndexInput = IndexElements & {\n /** Full wire name (managed) or verbatim physical name (exact). Always present. */\n readonly name: string;\n /**\n * The managed-mode name prefix — its PRESENCE is the naming-mode\n * discriminator (there is no stored enum). Present ⇔ managed: the\n * toolchain owns the physical name and `name === formatWireName(prefix,\n * <8hex content hash>)`, so the author chooses the prefix but never the\n * whole name. Absent ⇔ exact: `name` is an adopted verbatim physical name\n * (PSL `map:`) whose identity the author owns entirely.\n */\n readonly prefix: string | undefined;\n /** Opaque SQL: partial-index predicate (WHERE body, without the keyword). */\n readonly where: string | undefined;\n /** Rendered as CREATE UNIQUE INDEX. */\n readonly unique: boolean;\n readonly type: string | undefined;\n readonly options: Record<string, unknown> | undefined;\n};\n\n/**\n * SQL Contract IR node for a table-level secondary index, name-identified:\n * `name` is the full physical name; a present `prefix` marks the index as\n * managed (`name` is `formatWireName(prefix, <8hex>)`), an absent `prefix`\n * marks it exact (the name is adopted verbatim).\n *\n * `expression`, `where`, and `unique` are genuine SQL-family attributes —\n * functional and partial indexes are standard SQL supported natively by\n * Postgres and SQLite alike, and the family IR must be able to represent\n * anything any SQL target can introspect. A target declining to AUTHOR them\n * (SQLite's rejection at namespace construction) is a capability decision,\n * not evidence of target-specificity.\n *\n * Note that this class shadows the global TypeScript `Index` lib type\n * at the family-shared name; consumer files that need both should\n * alias one (e.g.\n * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).\n */\nexport class Index extends SqlNode {\n readonly name: string;\n readonly unique: boolean;\n /** See {@link IndexInput.prefix} — presence is the naming-mode discriminator. */\n declare readonly prefix?: string;\n declare readonly columns?: readonly string[];\n declare readonly expression?: string;\n declare readonly where?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n if (input.name === undefined || input.name.length === 0) {\n throw new ContractValidationError(\n 'Index: every index carries a full physical name; an expression index must be explicitly named (a default name cannot be derived from an expression).',\n 'storage',\n );\n }\n if ((input.columns === undefined) === (input.expression === undefined)) {\n throw new ContractValidationError(\n `Index \"${input.name}\": exactly one of columns or expression must be set.`,\n 'storage',\n );\n }\n if (input.prefix !== undefined) {\n const parsed = parseWireName(input.name);\n if (parsed === undefined || parsed.prefix !== input.prefix) {\n throw new ContractValidationError(\n `Index \"${input.name}\": prefix \"${input.prefix}\" does not match the wire name (expected \"${formatWireName(input.prefix, '<8hex>')}\").`,\n 'storage',\n );\n }\n }\n this.name = input.name;\n this.unique = input.unique;\n if (input.prefix !== undefined) this.prefix = input.prefix;\n if (input.columns !== undefined) this.columns = input.columns;\n if (input.expression !== undefined) this.expression = input.expression;\n if (input.where !== undefined) this.where = input.where;\n if (input.type !== undefined) this.type = input.type;\n if (input.options !== undefined) this.options = input.options;\n freezeNode(this);\n }\n}\n","import type { ColumnDefault, ControlPolicy, ValueSetRef } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageColumn}. Mirrors\n * the on-disk storage JSON envelope exactly so the family-base\n * serializer's hydration walker can hand an arktype-validated literal\n * straight to `new`.\n *\n * `typeParams` and `typeRef` remain mutually exclusive (one or the\n * other, not both); the constructor preserves whichever caller-side\n * choice the input encodes.\n */\nexport interface StorageColumnInput {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n readonly many?: boolean;\n readonly typeParams?: Record<string, unknown>;\n readonly typeRef?: string;\n readonly default?: ColumnDefault;\n readonly control?: ControlPolicy;\n readonly valueSet?: ValueSetRef;\n}\n\n/**\n * SQL Contract IR node for a single column entry in `StorageTable.columns`.\n *\n * Single concrete family-shared class — every SQL target reads the\n * same column shape today, so there is no per-target subclass. The\n * class type accepts any caller that constructs via\n * `new StorageColumn(input)`; literal construction sites must pass\n * through the constructor or the family-base hydration walker.\n *\n * The column's `name` is not on the class — columns are keyed by name\n * in the parent `StorageTable.columns: Record<string, StorageColumn>`\n * map, so a `name` field would be redundant with the key.\n */\nexport class StorageColumn extends SqlNode {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n declare readonly many?: boolean;\n declare readonly typeParams?: Record<string, unknown>;\n declare readonly typeRef?: string;\n declare readonly default?: ColumnDefault;\n declare readonly control?: ControlPolicy;\n declare readonly valueSet?: ValueSetRef;\n\n constructor(input: StorageColumnInput) {\n super();\n this.nativeType = input.nativeType;\n this.codecId = input.codecId;\n this.nullable = input.nullable;\n if (input.many !== undefined) this.many = input.many;\n if (input.typeParams !== undefined) this.typeParams = input.typeParams;\n if (input.typeRef !== undefined) this.typeRef = input.typeRef;\n if (input.default !== undefined) this.default = input.default;\n if (input.control !== undefined) this.control = input.control;\n if (input.valueSet !== undefined) this.valueSet = input.valueSet;\n freezeNode(this);\n }\n}\n","import { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface UniqueConstraintInput {\n readonly columns: readonly string[];\n readonly name?: string;\n}\n\n/**\n * SQL Contract IR node for a table-level unique constraint.\n */\nexport class UniqueConstraint extends SqlNode {\n readonly columns: readonly string[];\n declare readonly name?: string;\n\n constructor(input: UniqueConstraintInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\n freezeNode(this);\n }\n}\n","import type { ControlPolicy } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { InternalError } from '@prisma-next/utils/internal-error';\nimport { CheckConstraint, type CheckConstraintInput } from './check-constraint';\nimport { ForeignKey, type ForeignKeyInput } from './foreign-key';\nimport { PrimaryKey, type PrimaryKeyInput } from './primary-key';\nimport { Index, type IndexInput } from './sql-index';\nimport { SqlNode } from './sql-node';\nimport { StorageColumn, type StorageColumnInput } from './storage-column';\nimport { UniqueConstraint, type UniqueConstraintInput } from './unique-constraint';\n\nexport interface StorageTableInput {\n readonly columns: Record<string, StorageColumn | StorageColumnInput>;\n readonly primaryKey?: PrimaryKey | PrimaryKeyInput;\n readonly uniques: ReadonlyArray<UniqueConstraint | UniqueConstraintInput>;\n readonly indexes: ReadonlyArray<Index | IndexInput>;\n readonly foreignKeys: ReadonlyArray<ForeignKey | ForeignKeyInput>;\n readonly control?: ControlPolicy;\n readonly checks?: ReadonlyArray<CheckConstraint | CheckConstraintInput>;\n}\n\n/**\n * SQL Contract IR node for a single table entry in a namespace's\n * `tables` map.\n *\n * The constructor normalises nested IR-class fields (columns, primary\n * key, uniques, indexes, foreign keys) into the appropriate class\n * instances so downstream walks see a uniform AST regardless of whether\n * the input was a JSON literal or an already-constructed class.\n *\n * The table's `name` is not on the class — tables are keyed by name in\n * the parent namespace's `tables: Record<string, StorageTable>` map.\n */\nexport class StorageTable extends SqlNode {\n readonly columns: Readonly<Record<string, StorageColumn>>;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n declare readonly primaryKey?: PrimaryKey;\n declare readonly control?: ControlPolicy;\n declare readonly checks?: ReadonlyArray<CheckConstraint>;\n\n constructor(input: StorageTableInput) {\n super();\n this.columns = Object.freeze(\n Object.fromEntries(\n Object.entries(input.columns).map(([name, col]) => [\n name,\n col instanceof StorageColumn ? col : new StorageColumn(col),\n ]),\n ),\n );\n if (input.primaryKey !== undefined) {\n this.primaryKey =\n input.primaryKey instanceof PrimaryKey\n ? input.primaryKey\n : new PrimaryKey(input.primaryKey);\n }\n this.uniques = Object.freeze(\n input.uniques.map((u) => (u instanceof UniqueConstraint ? u : new UniqueConstraint(u))),\n );\n this.indexes = Object.freeze(input.indexes.map((i) => (i instanceof Index ? i : new Index(i))));\n this.foreignKeys = Object.freeze(\n input.foreignKeys.map((fk) => (fk instanceof ForeignKey ? fk : new ForeignKey(fk))),\n );\n if (input.control !== undefined) this.control = input.control;\n if (input.checks !== undefined && input.checks.length > 0) {\n this.checks = Object.freeze(input.checks.map((cc) => new CheckConstraint(cc)));\n }\n freezeNode(this);\n }\n\n /**\n * Runtime guard that a namespace `table` entry is really a `StorageTable`.\n * The compiler already types the entry as `StorageTable`, but a\n * freshly-deserialized contract may carry plain JSON at that slot until\n * hydration; this duck-types the structural shape. Accepts `undefined` so\n * optional-chained entry lookups pass straight through.\n */\n static is(value: StorageTable | undefined): value is StorageTable {\n if (typeof value !== 'object' || value === null) return false;\n return 'columns' in value && 'uniques' in value && 'indexes' in value && 'foreignKeys' in value;\n }\n\n static assert(\n value: StorageTable | undefined,\n coordinate: string,\n ): asserts value is StorageTable {\n if (!StorageTable.is(value)) {\n throw new InternalError(`Expected a StorageTable at ${coordinate}`);\n }\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { t as SqlNode } from "./sql-node-QXu33IeX.mjs";
|
|
2
2
|
import { n as ForeignKeyInput, t as ForeignKey } from "./foreign-key-CWCEM2IT.mjs";
|
|
3
|
-
import {
|
|
3
|
+
import { i as PrimaryKeyInput, n as UniqueConstraintInput, r as PrimaryKey, t as UniqueConstraint } from "./unique-constraint-Bp-q-mr-.mjs";
|
|
4
|
+
import { n as IndexInput, t as Index } from "./sql-index-Wzbj2nbH.mjs";
|
|
4
5
|
import { ColumnDefault, ControlPolicy, ValueSetRef } from "@prisma-next/contract/types";
|
|
5
6
|
//#region src/ir/check-constraint.d.ts
|
|
6
7
|
/**
|
|
@@ -125,4 +126,4 @@ declare class StorageTable extends SqlNode {
|
|
|
125
126
|
}
|
|
126
127
|
//#endregion
|
|
127
128
|
export { CheckConstraint as a, StorageColumnInput as i, StorageTableInput as n, CheckConstraintInput as o, StorageColumn as r, StorageTable as t };
|
|
128
|
-
//# sourceMappingURL=storage-table-
|
|
129
|
+
//# sourceMappingURL=storage-table-zrxIuCJ3.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storage-table-zrxIuCJ3.d.mts","names":[],"sources":["../src/ir/check-constraint.ts","../src/ir/storage-column.ts","../src/ir/storage-table.ts"],"mappings":";;;;;;;;;;;UASiB;WACN;WACA;WACA,UAAU;;;;;;;;;;;;;;;;cAiBR,wBAAwB;WAC1B;WACA;WACA,UAAU;cAEP,OAAO;;;;;;;;;;;;;;UCpBJ;WACN;WACA;WACA;WACA;WACA,aAAa;WACb;WACA,UAAU;WACV,UAAU;WACV,WAAW;;;;;;;;;;;;;;;cAgBT,sBAAsB;WACxB;WACA;WACA;WACQ;WACA,aAAa;WACb;WACA,UAAU;WACV,UAAU;WACV,WAAW;cAEhB,OAAO;;;;UCvCJ;WACN,SAAS,eAAe,gBAAgB;WACxC,aAAa,aAAa;WAC1B,SAAS,cAAc,mBAAmB;WAC1C,SAAS,cAAc,QAAQ;WAC/B,aAAa,cAAc,aAAa;WACxC,UAAU;WACV,SAAS,cAAc,kBAAkB;;;;;;;;;;;;;;cAevC,qBAAqB;WACvB,SAAS,SAAS,eAAe;WACjC,SAAS,cAAc;WACvB,SAAS,cAAc;WACvB,aAAa,cAAc;WACnB,aAAa;WACb,UAAU;WACV,SAAS,cAAc;cAE5B,OAAO;;;;;;;;SAqCZ,GAAG,OAAO,2BAA2B,SAAS;SAK9C,OACL,OAAO,0BACP,6BACS,SAAS"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { l as SqlNode } from "./storage-table-
|
|
1
|
+
import { l as SqlNode } from "./storage-table-DKTrkwZt.mjs";
|
|
2
2
|
import { freezeNode } from "@prisma-next/framework-components/ir";
|
|
3
3
|
//#region src/ir/storage-value-set.ts
|
|
4
4
|
/**
|
|
@@ -35,4 +35,4 @@ function isStorageValueSet(value) {
|
|
|
35
35
|
//#endregion
|
|
36
36
|
export { isStorageValueSet as n, StorageValueSet as t };
|
|
37
37
|
|
|
38
|
-
//# sourceMappingURL=storage-value-set-
|
|
38
|
+
//# sourceMappingURL=storage-value-set-DdL4oin-.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"storage-value-set-
|
|
1
|
+
{"version":3,"file":"storage-value-set-DdL4oin-.mjs","names":[],"sources":["../src/ir/storage-value-set.ts"],"sourcesContent":["import type { JsonValue } from '@prisma-next/contract/types';\nimport { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\n/**\n * Hydration / construction input shape for {@link StorageValueSet}.\n * Mirrors the on-disk storage JSON envelope so the serializer hydration\n * walker can hand a validated literal straight to `new`.\n */\nexport interface StorageValueSetInput {\n readonly kind: 'valueSet';\n /** Ordered permitted values, codec-encoded. Declaration order is preserved. */\n readonly values: readonly JsonValue[];\n}\n\n/**\n * SQL Contract IR node for a value-set entry in a namespace's `valueSet`\n * map (`SqlNamespace.entries.valueSet`).\n *\n * A value-set records the ordered set of permitted codec-encoded values for\n * an enum-like column restriction. It does not carry a `codecId` — the\n * column that references it already holds the codec; the value-set holds\n * only the permitted values.\n *\n * The node's `kind` is enumerable (`'valueSet'`) so the JSON envelope\n * carries the discriminator and the serializer hydration walker can\n * dispatch on it. This follows the per-leaf enumerable-kind convention\n * established in the SQL-node comment (future polymorphic dispatch on\n * namespace entries needs the discriminator in JSON).\n *\n * The entry's name is not on the class — value-sets are keyed by name in\n * the parent namespace's `valueSet: Record<string, StorageValueSet>` map.\n */\nexport class StorageValueSet extends SqlNode {\n override readonly kind = 'valueSet' as const;\n readonly values: readonly JsonValue[];\n\n constructor(input: StorageValueSetInput) {\n super();\n this.values = Object.freeze([...input.values]);\n freezeNode(this);\n }\n}\n\nexport function isStorageValueSet(value: unknown): value is StorageValueSet {\n if (typeof value !== 'object' || value === null) return false;\n return 'kind' in value && value.kind === 'valueSet' && 'values' in value;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,kBAAb,cAAqC,QAAQ;CAC3C,OAAyB;CACzB;CAEA,YAAY,OAA6B;EACvC,MAAM;EACN,KAAK,SAAS,OAAO,OAAO,CAAC,GAAG,MAAM,MAAM,CAAC;EAC7C,WAAW,IAAI;CACjB;AACF;AAEA,SAAgB,kBAAkB,OAA0C;CAC1E,IAAI,OAAO,UAAU,YAAY,UAAU,MAAM,OAAO;CACxD,OAAO,UAAU,SAAS,MAAM,SAAS,cAAc,YAAY;AACrE"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import "./sql-node-QXu33IeX.mjs";
|
|
2
|
-
import "./storage-table-
|
|
2
|
+
import "./storage-table-zrxIuCJ3.mjs";
|
|
3
3
|
import { r as ReferentialAction } from "./foreign-key-CWCEM2IT.mjs";
|
|
4
|
-
import "./unique-constraint-
|
|
5
|
-
import "./sql-
|
|
4
|
+
import "./unique-constraint-Bp-q-mr-.mjs";
|
|
5
|
+
import "./sql-index-Wzbj2nbH.mjs";
|
|
6
|
+
import "./sql-storage-DjqU3XXV.mjs";
|
|
6
7
|
import "./storage-value-set-DPHvvSdB.mjs";
|
|
7
8
|
import { CodecTrait } from "@prisma-next/framework-components/codec";
|
|
8
9
|
import { ControlDriverInstance } from "@prisma-next/framework-components/control";
|
|
@@ -128,4 +129,4 @@ type ExtractStorageColumnInputTypes<T> = StorageColumnInputTypesOf<ExtractTypeMa
|
|
|
128
129
|
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
|
|
129
130
|
//#endregion
|
|
130
131
|
export { TypeMapsPhantomKey as A, SqlControlDriverInstance as C, StorageColumnInputTypesOf as D, SqlQueryOperationTypes as E, StorageColumnTypesOf as O, ResolveCodecTypes as S, SqlModelStorage as T, QueryOperationReturn as _, ExtractCodecTypes as a, QueryOperationTypesBase as b, ExtractQueryOperationTypes as c, ExtractTypeMapsFromContract as d, FieldInputTypesOf as f, NamespacedStorageColumnTypeMap as g, NamespacedFieldTypeMap as h, DEFAULT_FK_INDEX as i, applyFkDefaults as j, TypeMaps as k, ExtractStorageColumnInputTypes as l, ForeignKeyOptions as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, FieldOutputTypesOf as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, ExtractStorageColumnTypes as u, QueryOperationSelfSpec as v, SqlModelFieldStorage as w, QueryOperationTypesOf as x, QueryOperationTypeEntry as y };
|
|
131
|
-
//# sourceMappingURL=types-
|
|
132
|
+
//# sourceMappingURL=types-Bxa1Pyzg.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-Bxa1Pyzg.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;;;;;UAIiB,yBAAyB,mCAChC,6BAA6B;EACrC,MAAM,MAAM,yBACV,aACA,8BACC;aAAmB,MAAM;;;KAgDlB;WACD;WACA,WAAW;WACX,WAAW;;KAGV;WACD;WACA;WACA;;KAGC;WACD;WACA;WACA,QAAQ,eAAe;;cAGrB;cACA;iBAEG,gBACd;EAAM;EAAkC;GACxC;EAAqB;EAAkC;;EACpD;EAAqB;;KASd,yBAAyB,eAAe,eAAe;KAEvD,iCAAiC,eAE3C,eAAe;KAGL,SACV,oBAAoB;EAAiB;KAAqB,uBAC1D,6BAA6B,0BAA0B,uBACvD,0BAA0B,yBAAyB,uBACnD,yBAAyB,yBAAyB,uBAClD,4BAA4B,iCAAiC,uBAC7D,iCAAiC,iCAAiC;WAEzD,YAAY;WACZ,qBAAqB;WACrB,kBAAkB;WAClB,iBAAiB;WACjB,oBAAoB;WACpB,yBAAyB;;KAGxB,aAAa,MAAM,qBAC3B,wBACA;WAAqB,kBAAkB;IACrC,UAAU;EAAiB;KACzB,IACA,wBACF;;;;;;;;;KAUM;WACG;WAA0B;WAAyB;;WACnD,iBAAiB;WAAuB;WAA0B;;WAElE;WACA,yBAAyB;WACzB;WACA;;;;;;;;;;KAWH;WACD;aAAuB;aAA0B;;;KAGhD;WACD,OAAO;WACP,UAAU,kBAAkB;;KAG3B,uBACV,YAAY;WAA0B;WAAyB;IAC/D,UAAU,eAAe,4BACvB;KAEQ,0BAA0B,eAAe;KAEzC,sBAAsB,MAAM,qBACpC,wBACA;WAAqB,2BAA2B;IAC9C,UAAU,0BACR,IACA,wBACF;KAEM;KAEA,qBAAqB,WAAW,aAAa,wBAC7C,KAAK,sBAAsB;KAG3B,4BAA4B,KAAK,iCAAiC,IAC1E,YAAY,EAAE,2BAA2B;KAGjC,mBAAmB,MAAM,qBACjC,wBACA;WAAqB,wBAAwB;IAC3C,UAAU,yBACR,IACA,wBACF;KAEM,kBAAkB,MAAM,qBAChC,wBACA;WAAqB,uBAAuB;IAC1C,UAAU,yBACR,IACA,wBACF;KAEM,qBAAqB,MAAM,qBACnC,wBACA;WAAqB,0BAA0B;IAC7C,UAAU,iCACR,IACA,wBACF;KAEM,0BAA0B,MAAM,qBACxC,wBACA;WAAqB,+BAA+B;IAClD,UAAU,iCACR,IACA,wBACF;KAEM,kBAAkB,KAAK,aAAa,4BAA4B;KAChE,2BAA2B,KAAK,sBAAsB,4BAA4B;KAClF,wBAAwB,KAAK,mBAAmB,4BAA4B;KAC5E,uBAAuB,KAAK,kBAAkB,4BAA4B;KAC1E,0BAA0B,KAAK,qBAAqB,4BAA4B;KAChF,+BAA+B,KAAK,0BAC9C,4BAA4B;KAGlB,kBAAkB,WAAW,cAAc,6BACnD,kBAAkB,aAClB,aAAa"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { t as SqlNode } from "./sql-node-QXu33IeX.mjs";
|
|
2
|
-
import { a as CheckConstraint, i as StorageColumnInput, n as StorageTableInput, o as CheckConstraintInput, r as StorageColumn, t as StorageTable } from "./storage-table-
|
|
2
|
+
import { a as CheckConstraint, i as StorageColumnInput, n as StorageTableInput, o as CheckConstraintInput, r as StorageColumn, t as StorageTable } from "./storage-table-zrxIuCJ3.mjs";
|
|
3
3
|
import { a as ForeignKeyReferenceInput, i as ForeignKeyReference, n as ForeignKeyInput, r as ReferentialAction, t as ForeignKey } from "./foreign-key-CWCEM2IT.mjs";
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
4
|
+
import { i as PrimaryKeyInput, n as UniqueConstraintInput, r as PrimaryKey, t as UniqueConstraint } from "./unique-constraint-Bp-q-mr-.mjs";
|
|
5
|
+
import { n as IndexInput, t as Index } from "./sql-index-Wzbj2nbH.mjs";
|
|
6
|
+
import { a as SqlNamespaceFactory, c as SqlStorageInput, d as isSqlAuthoringContributions, f as CODEC_INSTANCE_KIND, g as toStorageTypeInstance, h as isStorageTypeInstance, i as SqlNamespaceEntries, l as SqlStorageTypeEntry, m as StorageTypeInstanceInput, n as SqlNamespace, o as SqlNamespaceInput, p as StorageTypeInstance, r as SqlNamespaceBase, s as SqlStorage, t as SqlAuthoringContributions, u as isMaterializedSqlNamespace } from "./sql-storage-DjqU3XXV.mjs";
|
|
6
7
|
import { n as StorageValueSetInput, r as isStorageValueSet, t as StorageValueSet } from "./storage-value-set-DPHvvSdB.mjs";
|
|
7
|
-
import { A as TypeMapsPhantomKey, C as SqlControlDriverInstance, D as StorageColumnInputTypesOf, E as SqlQueryOperationTypes, O as StorageColumnTypesOf, S as ResolveCodecTypes, T as SqlModelStorage, _ as QueryOperationReturn, a as ExtractCodecTypes, b as QueryOperationTypesBase, c as ExtractQueryOperationTypes, d as ExtractTypeMapsFromContract, f as FieldInputTypesOf, g as NamespacedStorageColumnTypeMap, h as NamespacedFieldTypeMap, i as DEFAULT_FK_INDEX, j as applyFkDefaults, k as TypeMaps, l as ExtractStorageColumnInputTypes, m as ForeignKeyOptions, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as FieldOutputTypesOf, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as ExtractStorageColumnTypes, v as QueryOperationSelfSpec, w as SqlModelFieldStorage, x as QueryOperationTypesOf, y as QueryOperationTypeEntry } from "./types-
|
|
8
|
+
import { A as TypeMapsPhantomKey, C as SqlControlDriverInstance, D as StorageColumnInputTypesOf, E as SqlQueryOperationTypes, O as StorageColumnTypesOf, S as ResolveCodecTypes, T as SqlModelStorage, _ as QueryOperationReturn, a as ExtractCodecTypes, b as QueryOperationTypesBase, c as ExtractQueryOperationTypes, d as ExtractTypeMapsFromContract, f as FieldInputTypesOf, g as NamespacedStorageColumnTypeMap, h as NamespacedFieldTypeMap, i as DEFAULT_FK_INDEX, j as applyFkDefaults, k as TypeMaps, l as ExtractStorageColumnInputTypes, m as ForeignKeyOptions, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as FieldOutputTypesOf, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as ExtractStorageColumnTypes, v as QueryOperationSelfSpec, w as SqlModelFieldStorage, x as QueryOperationTypesOf, y as QueryOperationTypeEntry } from "./types-Bxa1Pyzg.mjs";
|
|
8
9
|
//#region src/column-type-resolution.d.ts
|
|
9
10
|
type StorageColumnMapAt<SCT, NsId extends string, TableName extends string> = string extends keyof SCT ? never : NsId extends keyof SCT ? string extends keyof SCT[NsId] ? never : TableName extends keyof SCT[NsId] ? SCT[NsId][TableName] : never : never;
|
|
10
11
|
type StorageColumnTypeAcrossNamespaces<SCT, TableName extends string, ColumnName extends string> = { [Ns in keyof SCT]: TableName extends keyof SCT[Ns] ? ColumnName extends keyof SCT[Ns][TableName] ? SCT[Ns][TableName][ColumnName] : never : never; }[keyof SCT];
|
package/dist/types.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/column-type-resolution.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.d.mts","names":[],"sources":["../src/column-type-resolution.ts"],"mappings":";;;;;;;;;KACY,mBACV,KACA,qBACA,iDACuB,cAErB,mBAAmB,2BACI,IAAI,gBAEvB,wBAAwB,IAAI,QAC1B,IAAI,MAAM;KAIR,kCACV,KACA,0BACA,gCAEC,YAAY,MAAM,wBAAwB,IAAI,MAC3C,yBAAyB,IAAI,IAAI,aAC/B,IAAI,IAAI,WAAW,qCAGnB"}
|
package/dist/types.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as PrimaryKey, c as CheckConstraint, i as Index, l as SqlNode, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, s as ForeignKeyReference, t as StorageTable } from "./storage-table-
|
|
2
|
-
import { n as isStorageValueSet, t as StorageValueSet } from "./storage-value-set-
|
|
1
|
+
import { a as PrimaryKey, c as CheckConstraint, i as Index, l as SqlNode, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, s as ForeignKeyReference, t as StorageTable } from "./storage-table-DKTrkwZt.mjs";
|
|
2
|
+
import { n as isStorageValueSet, t as StorageValueSet } from "./storage-value-set-DdL4oin-.mjs";
|
|
3
3
|
import { NamespaceBase, freezeNode, isPlainRecord } from "@prisma-next/framework-components/ir";
|
|
4
4
|
import { InternalError } from "@prisma-next/utils/internal-error";
|
|
5
5
|
//#region src/ir/storage-type-instance.ts
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { t as SqlNode } from "./sql-node-QXu33IeX.mjs";
|
|
2
|
+
//#region src/ir/primary-key.d.ts
|
|
3
|
+
interface PrimaryKeyInput {
|
|
4
|
+
readonly columns: readonly string[];
|
|
5
|
+
readonly name?: string;
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* SQL Contract IR node for a table's primary-key constraint.
|
|
9
|
+
*/
|
|
10
|
+
declare class PrimaryKey extends SqlNode {
|
|
11
|
+
readonly columns: readonly string[];
|
|
12
|
+
readonly name?: string;
|
|
13
|
+
constructor(input: PrimaryKeyInput);
|
|
14
|
+
}
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/ir/unique-constraint.d.ts
|
|
17
|
+
interface UniqueConstraintInput {
|
|
18
|
+
readonly columns: readonly string[];
|
|
19
|
+
readonly name?: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* SQL Contract IR node for a table-level unique constraint.
|
|
23
|
+
*/
|
|
24
|
+
declare class UniqueConstraint extends SqlNode {
|
|
25
|
+
readonly columns: readonly string[];
|
|
26
|
+
readonly name?: string;
|
|
27
|
+
constructor(input: UniqueConstraintInput);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { PrimaryKeyInput as i, UniqueConstraintInput as n, PrimaryKey as r, UniqueConstraint as t };
|
|
31
|
+
//# sourceMappingURL=unique-constraint-Bp-q-mr-.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unique-constraint-Bp-q-mr-.d.mts","names":[],"sources":["../src/ir/primary-key.ts","../src/ir/unique-constraint.ts"],"mappings":";;UAGiB;WACN;WACA;;;;;cAME,mBAAmB;WACrB;WACQ;cAEL,OAAO;;;;UCZJ;WACN;WACA;;;;;cAME,yBAAyB;WAC3B;WACQ;cAEL,OAAO"}
|
package/dist/validators.d.mts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-CWCEM2IT.mjs";
|
|
2
|
-
import {
|
|
3
|
-
import { s as SqlStorage } from "./sql-storage-
|
|
4
|
-
import "./types-
|
|
2
|
+
import { i as PrimaryKeyInput, n as UniqueConstraintInput } from "./unique-constraint-Bp-q-mr-.mjs";
|
|
3
|
+
import { s as SqlStorage } from "./sql-storage-DjqU3XXV.mjs";
|
|
4
|
+
import "./types-Bxa1Pyzg.mjs";
|
|
5
5
|
import { AnyEntityKindDescriptor } from "@prisma-next/framework-components/ir";
|
|
6
6
|
import { Type } from "arktype";
|
|
7
7
|
import { Contract } from "@prisma-next/contract/types";
|
|
@@ -27,8 +27,12 @@ declare const StorageValueSetSchema: import("arktype/internal/variants/object.ts
|
|
|
27
27
|
values: readonly (string | number | boolean | Record<string, unknown> | unknown[] | null)[];
|
|
28
28
|
}, {}>;
|
|
29
29
|
declare const IndexSchema: import("arktype/internal/variants/object.ts").ObjectType<{
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
name: string;
|
|
31
|
+
unique: boolean;
|
|
32
|
+
prefix?: string;
|
|
33
|
+
columns?: readonly string[];
|
|
34
|
+
expression?: string;
|
|
35
|
+
where?: string;
|
|
32
36
|
type?: string;
|
|
33
37
|
options?: Record<string, unknown>;
|
|
34
38
|
}, {}>;
|
|
@@ -78,8 +82,12 @@ declare const StorageTableSchema: import("arktype/internal/variants/object.ts").
|
|
|
78
82
|
};
|
|
79
83
|
uniques: readonly UniqueConstraintInput[];
|
|
80
84
|
indexes: readonly {
|
|
81
|
-
|
|
82
|
-
|
|
85
|
+
name: string;
|
|
86
|
+
unique: boolean;
|
|
87
|
+
prefix?: string;
|
|
88
|
+
columns?: readonly string[];
|
|
89
|
+
expression?: string;
|
|
90
|
+
where?: string;
|
|
83
91
|
type?: string;
|
|
84
92
|
options?: Record<string, unknown>;
|
|
85
93
|
}[];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/validators.ts"],"mappings":";;;;;;;;KAMK;WACM;WACA,mCAAmC;;KAEzC;WAAmC;WAA2B;;cAMtD,0EAA0B,WAAA;cAK1B,2EAA2B,WAAA;cAK3B,mEAAmB,WAAA,uBAAA;;;;;;cAiCnB,qEAAqB;;gDAArB;;cAiBA,2DAAW
|
|
1
|
+
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/validators.ts"],"mappings":";;;;;;;;KAMK;WACM;WACA,mCAAmC;;KAEzC;WAAmC;WAA2B;;cAMtD,0EAA0B,WAAA;cAK1B,2EAA2B,WAAA;cAK3B,mEAAmB,WAAA,uBAAA;;;;;;cAiCnB,qEAAqB;;gDAArB;;cAiBA,2DAAW;;;;;;;;YAAX;;cAWA,yEAAyB;;;;;;cAQzB,sEAAsB;;;;;cAOtB,uEAAuB,WAAA;cAIvB,gEAAgB,WAAA;cAQhB,qEAAqB;;;;;;;;;;;cAOrB,kEAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;cChBlB,kEAAkB;;;;mDAAlB;;;;;;;;;;;iBA+BG,2BACd,OAAO,oBAAoB,2BAC1B;;;;;;;iBA4Ca,uBACd,OAAO,oBAAoB,2BAC1B;;;;;;iBAwJa,wBACd,OAAO,oBAAoB,2BAC1B;;;;;;;;;;iBAsCa,gBAAgB;iBAchB,cAAc;;;;;;;;;;;;;;iBAoEd,yBAAyB,SAAS;;;;;;;iBAsKlC,+BAA+B,UAAU,SAAS;;;;;;;iBA4DlD,8BAA8B,UAAU,SAAS;UAwGhD;;;;;;;;;WASN,iBAAiB;;;;;;;;;;iBAWZ,yBAAyB,UAAU,SAAS,aAC1D,gBACA,UAAU,kCACT"}
|
package/dist/validators.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as contractError } from "./contract-errors-CPZcBw8G.mjs";
|
|
2
|
-
import { a as ColumnDefaultFunctionSchema, c as ForeignKeyReferenceSchema, d as IndexSchema, f as ReferentialActionSchema, i as CheckConstraintSchema, l as ForeignKeySchema, m as StorageValueSetSchema, o as ColumnDefaultLiteralSchema, p as StorageTableSchema, s as ColumnDefaultSchema, t as composeSqlEntityKinds, u as ForeignKeySourceSchema } from "./entity-kinds-
|
|
2
|
+
import { a as ColumnDefaultFunctionSchema, c as ForeignKeyReferenceSchema, d as IndexSchema, f as ReferentialActionSchema, i as CheckConstraintSchema, l as ForeignKeySchema, m as StorageValueSetSchema, o as ColumnDefaultLiteralSchema, p as StorageTableSchema, s as ColumnDefaultSchema, t as composeSqlEntityKinds, u as ForeignKeySourceSchema } from "./entity-kinds-CdHJQGi0.mjs";
|
|
3
3
|
import { isPlainRecord } from "@prisma-next/framework-components/ir";
|
|
4
4
|
import { type } from "arktype";
|
|
5
5
|
import { CrossReferenceSchema } from "@prisma-next/contract/types";
|
|
@@ -320,15 +320,18 @@ function validateStorageSemantics(storage) {
|
|
|
320
320
|
const sortOptions = (o) => o ? Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b))) : null;
|
|
321
321
|
const seenIndexDefinitions = /* @__PURE__ */ new Set();
|
|
322
322
|
for (const index of table.indexes) {
|
|
323
|
-
const duplicateColumn = findDuplicateValue(index.columns);
|
|
323
|
+
const duplicateColumn = findDuplicateValue(index.columns ?? []);
|
|
324
324
|
if (duplicateColumn !== void 0) errors.push(`Namespace "${namespaceId}" table "${tableName}": index contains duplicate column "${duplicateColumn}"`);
|
|
325
325
|
const signature = JSON.stringify({
|
|
326
|
-
columns: index.columns,
|
|
326
|
+
columns: index.columns ?? null,
|
|
327
|
+
expression: index.expression ?? null,
|
|
328
|
+
where: index.where ?? null,
|
|
329
|
+
unique: index.unique,
|
|
327
330
|
type: index.type ?? null,
|
|
328
331
|
options: sortOptions(index.options)
|
|
329
332
|
});
|
|
330
333
|
if (seenIndexDefinitions.has(signature)) {
|
|
331
|
-
errors.push(`Namespace "${namespaceId}" table "${tableName}": duplicate index definition on columns [${index.columns.join(", ")}]`);
|
|
334
|
+
errors.push(`Namespace "${namespaceId}" table "${tableName}": duplicate index definition on columns [${(index.columns ?? []).join(", ")}]`);
|
|
332
335
|
continue;
|
|
333
336
|
}
|
|
334
337
|
seenIndexDefinitions.add(signature);
|
|
@@ -415,7 +418,7 @@ function validateSqlStorageConsistency(contract) {
|
|
|
415
418
|
for (const colName of table.primaryKey.columns) if (!columnNames.has(colName)) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" primaryKey references non-existent column "${colName}"`, "storage");
|
|
416
419
|
}
|
|
417
420
|
for (const unique of table.uniques) for (const colName of unique.columns) if (!columnNames.has(colName)) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" unique constraint references non-existent column "${colName}"`, "storage");
|
|
418
|
-
for (const index of table.indexes) for (const colName of index.columns) if (!columnNames.has(colName)) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index references non-existent column "${colName}"`, "storage");
|
|
421
|
+
for (const index of table.indexes) for (const colName of index.columns ?? []) if (!columnNames.has(colName)) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" index references non-existent column "${colName}"`, "storage");
|
|
419
422
|
for (const check of table.checks ?? []) if (!columnNames.has(check.column)) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" check constraint "${check.name}" references non-existent column "${check.column}"`, "storage");
|
|
420
423
|
for (const [colName, column] of Object.entries(table.columns)) if (!column.nullable && column.default?.kind === "literal" && column.default.value === null) throw new ContractValidationError(`Namespace "${namespaceId}" table "${tableName}" column "${colName}" is NOT NULL but has a literal null default`, "storage");
|
|
421
424
|
for (const fk of table.foreignKeys) {
|