@prisma-next/sql-contract 0.15.0-dev.8 → 0.15.0

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.
Files changed (55) hide show
  1. package/dist/canonicalization-hooks.d.mts.map +1 -1
  2. package/dist/canonicalization-hooks.mjs +10 -0
  3. package/dist/canonicalization-hooks.mjs.map +1 -1
  4. package/dist/contract-view.d.mts +1 -1
  5. package/dist/{entity-kinds-CVg6HzG2.mjs → entity-kinds-BEPZdFBN.mjs} +6 -4
  6. package/dist/entity-kinds-BEPZdFBN.mjs.map +1 -0
  7. package/dist/entity-kinds.d.mts +1 -1
  8. package/dist/entity-kinds.mjs +1 -1
  9. package/dist/factories.d.mts +5 -4
  10. package/dist/factories.d.mts.map +1 -1
  11. package/dist/factories.mjs +9 -2
  12. package/dist/factories.mjs.map +1 -1
  13. package/dist/{foreign-key-DuCoGJCf.d.mts → foreign-key-DM1UTydh.d.mts} +8 -10
  14. package/dist/{foreign-key-DuCoGJCf.d.mts.map → foreign-key-DM1UTydh.d.mts.map} +1 -1
  15. package/dist/index-type-validation.d.mts +1 -1
  16. package/dist/referential-action-sql.d.mts +1 -1
  17. package/dist/resolve-storage-table.d.mts +2 -2
  18. package/dist/{sql-storage-p-Wzt_MO.d.mts → sql-storage-Dt5ipcRl.d.mts} +2 -2
  19. package/dist/{sql-storage-p-Wzt_MO.d.mts.map → sql-storage-Dt5ipcRl.d.mts.map} +1 -1
  20. package/dist/{storage-table-CE-Ns6wa.d.mts → storage-table-Bj1ZN1P7.d.mts} +54 -4
  21. package/dist/storage-table-Bj1ZN1P7.d.mts.map +1 -0
  22. package/dist/{storage-table-DBpYBmty.mjs → storage-table-y6R6pxyI.mjs} +6 -10
  23. package/dist/storage-table-y6R6pxyI.mjs.map +1 -0
  24. package/dist/{storage-value-set-3BKuha5q.mjs → storage-value-set-Tx3CFoS_.mjs} +2 -2
  25. package/dist/{storage-value-set-3BKuha5q.mjs.map → storage-value-set-Tx3CFoS_.mjs.map} +1 -1
  26. package/dist/types-Hkxybhdj.mjs +13 -0
  27. package/dist/types-Hkxybhdj.mjs.map +1 -0
  28. package/dist/{types-3vOIrnvp.d.mts → types-zBvpNCmg.d.mts} +2 -2
  29. package/dist/types-zBvpNCmg.d.mts.map +1 -0
  30. package/dist/types.d.mts +4 -5
  31. package/dist/types.d.mts.map +1 -1
  32. package/dist/types.mjs +3 -12
  33. package/dist/types.mjs.map +1 -1
  34. package/dist/validators.d.mts +3 -3
  35. package/dist/validators.d.mts.map +1 -1
  36. package/dist/validators.mjs +4 -2
  37. package/dist/validators.mjs.map +1 -1
  38. package/package.json +7 -9
  39. package/src/canonicalization-hooks.ts +1 -0
  40. package/src/factories.ts +5 -1
  41. package/src/ir/foreign-key.ts +9 -9
  42. package/src/ir/storage-entry-schemas.ts +2 -0
  43. package/src/validators.ts +2 -0
  44. package/dist/entity-kinds-CVg6HzG2.mjs.map +0 -1
  45. package/dist/foreign-key-materialization.d.mts +0 -64
  46. package/dist/foreign-key-materialization.d.mts.map +0 -1
  47. package/dist/foreign-key-materialization.mjs +0 -67
  48. package/dist/foreign-key-materialization.mjs.map +0 -1
  49. package/dist/storage-table-CE-Ns6wa.d.mts.map +0 -1
  50. package/dist/storage-table-DBpYBmty.mjs.map +0 -1
  51. package/dist/types-3vOIrnvp.d.mts.map +0 -1
  52. package/dist/unique-constraint-C0De4sLU.d.mts +0 -55
  53. package/dist/unique-constraint-C0De4sLU.d.mts.map +0 -1
  54. package/src/exports/foreign-key-materialization.ts +0 -8
  55. package/src/foreign-key-materialization.ts +0 -107
@@ -1,64 +0,0 @@
1
- import { a as ForeignKeyReferenceInput, n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-DuCoGJCf.mjs";
2
- import { i as IndexInput, n as UniqueConstraintInput, o as PrimaryKeyInput } from "./unique-constraint-C0De4sLU.mjs";
3
-
4
- //#region src/foreign-key-materialization.d.ts
5
- type BackingIndexCandidates = {
6
- readonly indexes: readonly {
7
- readonly columns: readonly string[];
8
- }[];
9
- readonly uniques: readonly {
10
- readonly columns: readonly string[];
11
- }[];
12
- readonly primaryKey?: {
13
- readonly columns: readonly string[];
14
- } | undefined;
15
- };
16
- /**
17
- * The column-list keys (`"colA,colB"`, order preserved) a table's own
18
- * indexes, unique constraints, and primary key already back. A foreign key
19
- * whose source columns join to one of these keys needs no separately
20
- * derived backing index.
21
- *
22
- * Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
23
- * (deriving the discrete backing-index entities persisted at `contract emit`)
24
- * and the postgres PSL inferrer (deciding whether an introspected relation
25
- * needs an explicit `index: false`).
26
- */
27
- declare function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[];
28
- /**
29
- * Whether `columns`, in order, matches one of `backingKeys` (see
30
- * {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
31
- * satisfy a backing index declared as `(b, a)`.
32
- */
33
- declare function isBackedByColumnKeys(columns: readonly string[], backingKeys: readonly string[]): boolean;
34
- /**
35
- * A foreign key as authored, before FK1 materialization: the referential
36
- * coordinates plus the `constraint`/`index` intent booleans that drive
37
- * whether — and how — it survives into the persisted contract.
38
- */
39
- interface ForeignKeyAuthoringInput {
40
- readonly source: ForeignKeyReferenceInput;
41
- readonly target: ForeignKeyReferenceInput;
42
- readonly name?: string;
43
- readonly onDelete?: ReferentialAction;
44
- readonly onUpdate?: ReferentialAction;
45
- readonly constraint: boolean;
46
- readonly index: boolean;
47
- }
48
- interface MaterializedTableConstraints {
49
- readonly foreignKeys: readonly ForeignKeyInput[];
50
- readonly indexes: readonly IndexInput[];
51
- }
52
- /**
53
- * Lowers a table's authored foreign keys into the discrete entities
54
- * `contract.json` persists: a `constraint: false` FK contributes no
55
- * `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
56
- * backed by a declared index/unique/primary-key contributes a named
57
- * `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
58
- * unchanged; a second FK sharing already-synthesized backing columns does not
59
- * mint a duplicate index.
60
- */
61
- declare function materializeForeignKeysAndIndexes(tableName: string, foreignKeys: readonly ForeignKeyAuthoringInput[], declaredIndexes: readonly IndexInput[], uniques: readonly UniqueConstraintInput[], primaryKey: PrimaryKeyInput | undefined): MaterializedTableConstraints;
62
- //#endregion
63
- export { type BackingIndexCandidates, type ForeignKeyAuthoringInput, type MaterializedTableConstraints, backingIndexColumnKeys, isBackedByColumnKeys, materializeForeignKeysAndIndexes };
64
- //# sourceMappingURL=foreign-key-materialization.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"foreign-key-materialization.d.mts","names":[],"sources":["../src/foreign-key-materialization.ts"],"mappings":";;;;KAOY,sBAAA;EAAA,SACD,OAAA;IAAA,SAA6B,OAAA;EAAA;EAAA,SAC7B,OAAA;IAAA,SAA6B,OAAA;EAAA;EAAA,SAC7B,UAAA;IAAA,SAAwB,OAAA;EAAA;AAAA;AAcnC;;;;AAAoE;AAapE;;;;AAEgC;AAUhC;AAzBA,iBAAgB,sBAAA,CAAuB,KAA6B,EAAtB,sBAAsB;;;;;;iBAapD,oBAAA,CACd,OAAA,qBACA,WAA8B;;;;;;UAUf,wBAAA;EAAA,SACN,MAAA,EAAQ,wBAAA;EAAA,SACR,MAAA,EAAQ,wBAAA;EAAA,SACR,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;EAAA,SACX,UAAA;EAAA,SACA,KAAA;AAAA;AAAA,UAGM,4BAAA;EAAA,SACN,WAAA,WAAsB,eAAA;EAAA,SACtB,OAAA,WAAkB,UAAU;AAAA;;;;;;AAAA;AAYvC;;;iBAAgB,gCAAA,CACd,SAAA,UACA,WAAA,WAAsB,wBAAA,IACtB,eAAA,WAA0B,UAAA,IAC1B,OAAA,WAAkB,qBAAA,IAClB,UAAA,EAAY,eAAA,eACX,4BAAA"}
@@ -1,67 +0,0 @@
1
- import { defaultIndexName } from "@prisma-next/sql-schema-ir/naming";
2
- //#region src/foreign-key-materialization.ts
3
- /**
4
- * The column-list keys (`"colA,colB"`, order preserved) a table's own
5
- * indexes, unique constraints, and primary key already back. A foreign key
6
- * whose source columns join to one of these keys needs no separately
7
- * derived backing index.
8
- *
9
- * Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
10
- * (deriving the discrete backing-index entities persisted at `contract emit`)
11
- * and the postgres PSL inferrer (deciding whether an introspected relation
12
- * needs an explicit `index: false`).
13
- */
14
- function backingIndexColumnKeys(table) {
15
- return [
16
- ...table.indexes.map((index) => index.columns.join(",")),
17
- ...table.uniques.map((unique) => unique.columns.join(",")),
18
- ...table.primaryKey ? [table.primaryKey.columns.join(",")] : []
19
- ];
20
- }
21
- /**
22
- * Whether `columns`, in order, matches one of `backingKeys` (see
23
- * {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
24
- * satisfy a backing index declared as `(b, a)`.
25
- */
26
- function isBackedByColumnKeys(columns, backingKeys) {
27
- return backingKeys.includes(columns.join(","));
28
- }
29
- /**
30
- * Lowers a table's authored foreign keys into the discrete entities
31
- * `contract.json` persists: a `constraint: false` FK contributes no
32
- * `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
33
- * backed by a declared index/unique/primary-key contributes a named
34
- * `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
35
- * unchanged; a second FK sharing already-synthesized backing columns does not
36
- * mint a duplicate index.
37
- */
38
- function materializeForeignKeysAndIndexes(tableName, foreignKeys, declaredIndexes, uniques, primaryKey) {
39
- const satisfiedIndexColumns = new Set(backingIndexColumnKeys({
40
- indexes: declaredIndexes,
41
- uniques,
42
- primaryKey
43
- }));
44
- const synthesizedIndexes = [];
45
- const materializedForeignKeys = [];
46
- for (const { constraint, index, ...reference } of foreignKeys) {
47
- if (constraint !== false) materializedForeignKeys.push(reference);
48
- if (index !== false) {
49
- const key = reference.source.columns.join(",");
50
- if (!satisfiedIndexColumns.has(key)) {
51
- synthesizedIndexes.push({
52
- columns: reference.source.columns,
53
- name: defaultIndexName(tableName, reference.source.columns)
54
- });
55
- satisfiedIndexColumns.add(key);
56
- }
57
- }
58
- }
59
- return {
60
- foreignKeys: materializedForeignKeys,
61
- indexes: [...declaredIndexes, ...synthesizedIndexes]
62
- };
63
- }
64
- //#endregion
65
- export { backingIndexColumnKeys, isBackedByColumnKeys, materializeForeignKeysAndIndexes };
66
-
67
- //# sourceMappingURL=foreign-key-materialization.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"foreign-key-materialization.mjs","names":[],"sources":["../src/foreign-key-materialization.ts"],"sourcesContent":["import { defaultIndexName } from '@prisma-next/sql-schema-ir/naming';\nimport type { ForeignKeyInput, ReferentialAction } from './ir/foreign-key';\nimport type { ForeignKeyReferenceInput } from './ir/foreign-key-reference';\nimport type { PrimaryKeyInput } from './ir/primary-key';\nimport type { IndexInput } from './ir/sql-index';\nimport type { UniqueConstraintInput } from './ir/unique-constraint';\n\nexport type BackingIndexCandidates = {\n readonly indexes: readonly { readonly columns: readonly string[] }[];\n readonly uniques: readonly { readonly columns: readonly string[] }[];\n readonly primaryKey?: { readonly columns: readonly string[] } | undefined;\n};\n\n/**\n * The column-list keys (`\"colA,colB\"`, order preserved) a table's own\n * indexes, unique constraints, and primary key already back. A foreign key\n * whose source columns join to one of these keys needs no separately\n * derived backing index.\n *\n * Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`\n * (deriving the discrete backing-index entities persisted at `contract emit`)\n * and the postgres PSL inferrer (deciding whether an introspected relation\n * needs an explicit `index: false`).\n */\nexport function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[] {\n return [\n ...table.indexes.map((index) => index.columns.join(',')),\n ...table.uniques.map((unique) => unique.columns.join(',')),\n ...(table.primaryKey ? [table.primaryKey.columns.join(',')] : []),\n ];\n}\n\n/**\n * Whether `columns`, in order, matches one of `backingKeys` (see\n * {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not\n * satisfy a backing index declared as `(b, a)`.\n */\nexport function isBackedByColumnKeys(\n columns: readonly string[],\n backingKeys: readonly string[],\n): boolean {\n return backingKeys.includes(columns.join(','));\n}\n\n/**\n * A foreign key as authored, before FK1 materialization: the referential\n * coordinates plus the `constraint`/`index` intent booleans that drive\n * whether — and how — it survives into the persisted contract.\n */\nexport interface ForeignKeyAuthoringInput {\n readonly source: ForeignKeyReferenceInput;\n readonly target: ForeignKeyReferenceInput;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n readonly constraint: boolean;\n readonly index: boolean;\n}\n\nexport interface MaterializedTableConstraints {\n readonly foreignKeys: readonly ForeignKeyInput[];\n readonly indexes: readonly IndexInput[];\n}\n\n/**\n * Lowers a table's authored foreign keys into the discrete entities\n * `contract.json` persists: a `constraint: false` FK contributes no\n * `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already\n * backed by a declared index/unique/primary-key contributes a named\n * `indexes[]` entry (`defaultIndexName`). Declared indexes always survive\n * unchanged; a second FK sharing already-synthesized backing columns does not\n * mint a duplicate index.\n */\nexport function materializeForeignKeysAndIndexes(\n tableName: string,\n foreignKeys: readonly ForeignKeyAuthoringInput[],\n declaredIndexes: readonly IndexInput[],\n uniques: readonly UniqueConstraintInput[],\n primaryKey: PrimaryKeyInput | undefined,\n): MaterializedTableConstraints {\n const satisfiedIndexColumns = new Set(\n backingIndexColumnKeys({ indexes: declaredIndexes, uniques, primaryKey }),\n );\n const synthesizedIndexes: IndexInput[] = [];\n const materializedForeignKeys: ForeignKeyInput[] = [];\n\n for (const { constraint, index, ...reference } of foreignKeys) {\n if (constraint !== false) {\n materializedForeignKeys.push(reference);\n }\n if (index !== false) {\n const key = reference.source.columns.join(',');\n if (!satisfiedIndexColumns.has(key)) {\n synthesizedIndexes.push({\n columns: reference.source.columns,\n name: defaultIndexName(tableName, reference.source.columns),\n });\n satisfiedIndexColumns.add(key);\n }\n }\n }\n\n return {\n foreignKeys: materializedForeignKeys,\n indexes: [...declaredIndexes, ...synthesizedIndexes],\n };\n}\n"],"mappings":";;;;;;;;;;;;;AAwBA,SAAgB,uBAAuB,OAAkD;CACvF,OAAO;EACL,GAAG,MAAM,QAAQ,KAAK,UAAU,MAAM,QAAQ,KAAK,GAAG,CAAC;EACvD,GAAG,MAAM,QAAQ,KAAK,WAAW,OAAO,QAAQ,KAAK,GAAG,CAAC;EACzD,GAAI,MAAM,aAAa,CAAC,MAAM,WAAW,QAAQ,KAAK,GAAG,CAAC,IAAI,CAAC;CACjE;AACF;;;;;;AAOA,SAAgB,qBACd,SACA,aACS;CACT,OAAO,YAAY,SAAS,QAAQ,KAAK,GAAG,CAAC;AAC/C;;;;;;;;;;AA+BA,SAAgB,iCACd,WACA,aACA,iBACA,SACA,YAC8B;CAC9B,MAAM,wBAAwB,IAAI,IAChC,uBAAuB;EAAE,SAAS;EAAiB;EAAS;CAAW,CAAC,CAC1E;CACA,MAAM,qBAAmC,CAAC;CAC1C,MAAM,0BAA6C,CAAC;CAEpD,KAAK,MAAM,EAAE,YAAY,OAAO,GAAG,eAAe,aAAa;EAC7D,IAAI,eAAe,OACjB,wBAAwB,KAAK,SAAS;EAExC,IAAI,UAAU,OAAO;GACnB,MAAM,MAAM,UAAU,OAAO,QAAQ,KAAK,GAAG;GAC7C,IAAI,CAAC,sBAAsB,IAAI,GAAG,GAAG;IACnC,mBAAmB,KAAK;KACtB,SAAS,UAAU,OAAO;KAC1B,MAAM,iBAAiB,WAAW,UAAU,OAAO,OAAO;IAC5D,CAAC;IACD,sBAAsB,IAAI,GAAG;GAC/B;EACF;CACF;CAEA,OAAO;EACL,aAAa;EACb,SAAS,CAAC,GAAG,iBAAiB,GAAG,kBAAkB;CACrD;AACF"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage-table-CE-Ns6wa.d.mts","names":[],"sources":["../src/ir/check-constraint.ts","../src/ir/storage-column.ts","../src/ir/storage-table.ts"],"mappings":";;;;;;;;;;AASA;UAAiB,oBAAA;EAAA,SACN,IAAA;EAAA,SACA,MAAA;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ACvB,OAAA,EAAS,aAAA,CAAc,KAAA;EAAA,SACvB,WAAA,EAAa,aAAA,CAAc,UAAA;EAAA,SACnB,UAAA,GAAa,UAAA;EAAA,SACb,OAAA,GAAU,aAAA;EAAA,SACV,MAAA,GAAS,aAAA,CAAc,eAAA;cAE5B,KAAA,EAAO,iBAAA;ED3Bc;;;;;;;EAAA,OCgE1B,EAAA,CAAG,KAAA,EAAO,YAAA,eAA2B,KAAA,IAAS,YAAA;EAAA,OAK9C,MAAA,CACL,KAAA,EAAO,YAAA,cACP,UAAA,mBACS,KAAA,IAAS,YAAA;AAAA"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"storage-table-DBpYBmty.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 { freezeNode } from '@prisma-next/framework-components/ir';\nimport { SqlNode } from './sql-node';\n\nexport interface IndexInput {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n}\n\n/**\n * SQL Contract IR node for a table-level secondary index.\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 columns: readonly string[];\n declare readonly name?: string;\n declare readonly type?: string;\n declare readonly options?: Record<string, unknown>;\n\n constructor(input: IndexInput) {\n super();\n this.columns = input.columns;\n if (input.name !== undefined) this.name = input.name;\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 { 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 Error(`Expected a StorageTable at ${coordinate}`);\n }\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkCA,IAAsB,UAAtB,cAAsC,WAAW;CAC/C;CAEA,cAAc;EACZ,MAAM;EACN,OAAO,eAAe,MAAM,QAAQ;GAClC,OAAO;GACP,UAAU;GACV,YAAY;GAMZ,cAAc;EAChB,CAAC;CACH;AACF;;;;;;;;;;;;;;;;;ACtBA,IAAa,kBAAb,cAAqC,QAAQ;CAC3C;CACA;CACA;CAEA,YAAY,OAA6B;EACvC,MAAM;EACN,KAAK,OAAO,MAAM;EAClB,KAAK,SAAS,MAAM;EACpB,KAAK,WAAW,MAAM;EACtB,WAAW,IAAI;CACjB;AACF;;;;;;;;;;;;;;;;;;;ACHA,IAAa,sBAAb,cAAyC,QAAQ;CAC/C;CACA;CACA;CAGA,YAAY,OAAiC;EAC3C,MAAM;EACN,KAAK,cAAc,cAAc,MAAM,WAAW;EAClD,KAAK,YAAY,MAAM;EACvB,KAAK,UAAU,MAAM;EACrB,IAAI,MAAM,YAAY,KAAA,GAAW,KAAK,UAAU,MAAM;EACtD,WAAW,IAAI;CACjB;AACF;;;;;;;;;;;;;;;;;;;;;;;AClBA,IAAa,aAAb,cAAgC,QAAQ;CACtC;CACA;CAKA,YAAY,OAAwB;EAClC,MAAM;EACN,KAAK,SACH,MAAM,kBAAkB,sBACpB,MAAM,SACN,IAAI,oBAAoB,MAAM,MAAM;EAC1C,KAAK,SACH,M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,CAAA,CAAE,kBAAA,SAA2B,CAAA;AAAA,KAGjC,kBAAA,OAAyB,CAAA,oBACjC,MAAA,kBACA,CAAA;EAAA,SAAqB,gBAAA;AAAA,IACnB,CAAA,SAAU,sBAAA,GACR,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,iBAAA,OAAwB,CAAA,oBAChC,MAAA,kBACA,CAAA;EAAA,SAAqB,eAAA;AAAA,IACnB,CAAA,SAAU,sBAAA,GACR,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,oBAAA,OAA2B,CAAA,oBACnC,MAAA,kBACA,CAAA;EAAA,SAAqB,kBAAA;AAAA,IACnB,CAAA,SAAU,8BAAA,GACR,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,yBAAA,OAAgC,CAAA,oBACxC,MAAA,kBACA,CAAA;EAAA,SAAqB,uBAAA;AAAA,IACnB,CAAA,SAAU,8BAAA,GACR,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,iBAAA,MAAuB,YAAA,CAAa,2BAAA,CAA4B,CAAA;AAAA,KAChE,0BAAA,MAAgC,qBAAA,CAAsB,2BAAA,CAA4B,CAAA;AAAA,KAClF,uBAAA,MAA6B,kBAAA,CAAmB,2BAAA,CAA4B,CAAA;AAAA,KAC5E,sBAAA,MAA4B,iBAAA,CAAkB,2BAAA,CAA4B,CAAA;AAAA,KAC1E,yBAAA,MAA+B,oBAAA,CAAqB,2BAAA,CAA4B,CAAA;AAAA,KAChF,8BAAA,MAAoC,yBAAA,CAC9C,2BAAA,CAA4B,CAAA;AAAA,KAGlB,iBAAA,0BAA2C,SAAA,oBACnD,iBAAA,CAAkB,SAAA,IAClB,YAAA,CAAa,SAAA"}
@@ -1,55 +0,0 @@
1
- import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
2
-
3
- //#region src/ir/primary-key.d.ts
4
- interface PrimaryKeyInput {
5
- readonly columns: readonly string[];
6
- readonly name?: string;
7
- }
8
- /**
9
- * SQL Contract IR node for a table's primary-key constraint.
10
- */
11
- declare class PrimaryKey extends SqlNode {
12
- readonly columns: readonly string[];
13
- readonly name?: string;
14
- constructor(input: PrimaryKeyInput);
15
- }
16
- //#endregion
17
- //#region src/ir/sql-index.d.ts
18
- interface IndexInput {
19
- readonly columns: readonly string[];
20
- readonly name?: string;
21
- readonly type?: string;
22
- readonly options?: Record<string, unknown>;
23
- }
24
- /**
25
- * SQL Contract IR node for a table-level secondary index.
26
- *
27
- * Note that this class shadows the global TypeScript `Index` lib type
28
- * at the family-shared name; consumer files that need both should
29
- * alias one (e.g.
30
- * `import { Index as SqlIndexNode } from '@prisma-next/sql-contract/types'`).
31
- */
32
- declare class Index extends SqlNode {
33
- readonly columns: readonly string[];
34
- readonly name?: string;
35
- readonly type?: string;
36
- readonly options?: Record<string, unknown>;
37
- constructor(input: IndexInput);
38
- }
39
- //#endregion
40
- //#region src/ir/unique-constraint.d.ts
41
- interface UniqueConstraintInput {
42
- readonly columns: readonly string[];
43
- readonly name?: string;
44
- }
45
- /**
46
- * SQL Contract IR node for a table-level unique constraint.
47
- */
48
- declare class UniqueConstraint extends SqlNode {
49
- readonly columns: readonly string[];
50
- readonly name?: string;
51
- constructor(input: UniqueConstraintInput);
52
- }
53
- //#endregion
54
- export { PrimaryKey as a, IndexInput as i, UniqueConstraintInput as n, PrimaryKeyInput as o, Index as r, UniqueConstraint as t };
55
- //# sourceMappingURL=unique-constraint-C0De4sLU.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"unique-constraint-C0De4sLU.d.mts","names":[],"sources":["../src/ir/primary-key.ts","../src/ir/sql-index.ts","../src/ir/unique-constraint.ts"],"mappings":";;;UAGiB,eAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAI;AAAA;;;AAAA;cAMF,UAAA,SAAmB,OAAO;EAAA,SAC5B,OAAA;EAAA,SACQ,IAAA;cAEL,KAAA,EAAO,eAAA;AAAA;;;UCZJ,UAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAM;AAAA;ADFZ;AAMf;;;;;;;AANe,cCaF,KAAA,SAAc,OAAA;EAAA,SAChB,OAAA;EAAA,SACQ,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAA;cAEf,KAAA,EAAO,UAAA;AAAA;;;UCrBJ,qBAAA;EAAA,SACN,OAAA;EAAA,SACA,IAAI;AAAA;;;AFAA;cEMF,gBAAA,SAAyB,OAAO;EAAA,SAClC,OAAA;EAAA,SACQ,IAAA;cAEL,KAAA,EAAO,qBAAA;AAAA"}
@@ -1,8 +0,0 @@
1
- export {
2
- type BackingIndexCandidates,
3
- backingIndexColumnKeys,
4
- type ForeignKeyAuthoringInput,
5
- isBackedByColumnKeys,
6
- type MaterializedTableConstraints,
7
- materializeForeignKeysAndIndexes,
8
- } from '../foreign-key-materialization';
@@ -1,107 +0,0 @@
1
- import { defaultIndexName } from '@prisma-next/sql-schema-ir/naming';
2
- import type { ForeignKeyInput, ReferentialAction } from './ir/foreign-key';
3
- import type { ForeignKeyReferenceInput } from './ir/foreign-key-reference';
4
- import type { PrimaryKeyInput } from './ir/primary-key';
5
- import type { IndexInput } from './ir/sql-index';
6
- import type { UniqueConstraintInput } from './ir/unique-constraint';
7
-
8
- export type BackingIndexCandidates = {
9
- readonly indexes: readonly { readonly columns: readonly string[] }[];
10
- readonly uniques: readonly { readonly columns: readonly string[] }[];
11
- readonly primaryKey?: { readonly columns: readonly string[] } | undefined;
12
- };
13
-
14
- /**
15
- * The column-list keys (`"colA,colB"`, order preserved) a table's own
16
- * indexes, unique constraints, and primary key already back. A foreign key
17
- * whose source columns join to one of these keys needs no separately
18
- * derived backing index.
19
- *
20
- * Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
21
- * (deriving the discrete backing-index entities persisted at `contract emit`)
22
- * and the postgres PSL inferrer (deciding whether an introspected relation
23
- * needs an explicit `index: false`).
24
- */
25
- export function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[] {
26
- return [
27
- ...table.indexes.map((index) => index.columns.join(',')),
28
- ...table.uniques.map((unique) => unique.columns.join(',')),
29
- ...(table.primaryKey ? [table.primaryKey.columns.join(',')] : []),
30
- ];
31
- }
32
-
33
- /**
34
- * Whether `columns`, in order, matches one of `backingKeys` (see
35
- * {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
36
- * satisfy a backing index declared as `(b, a)`.
37
- */
38
- export function isBackedByColumnKeys(
39
- columns: readonly string[],
40
- backingKeys: readonly string[],
41
- ): boolean {
42
- return backingKeys.includes(columns.join(','));
43
- }
44
-
45
- /**
46
- * A foreign key as authored, before FK1 materialization: the referential
47
- * coordinates plus the `constraint`/`index` intent booleans that drive
48
- * whether — and how — it survives into the persisted contract.
49
- */
50
- export interface ForeignKeyAuthoringInput {
51
- readonly source: ForeignKeyReferenceInput;
52
- readonly target: ForeignKeyReferenceInput;
53
- readonly name?: string;
54
- readonly onDelete?: ReferentialAction;
55
- readonly onUpdate?: ReferentialAction;
56
- readonly constraint: boolean;
57
- readonly index: boolean;
58
- }
59
-
60
- export interface MaterializedTableConstraints {
61
- readonly foreignKeys: readonly ForeignKeyInput[];
62
- readonly indexes: readonly IndexInput[];
63
- }
64
-
65
- /**
66
- * Lowers a table's authored foreign keys into the discrete entities
67
- * `contract.json` persists: a `constraint: false` FK contributes no
68
- * `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
69
- * backed by a declared index/unique/primary-key contributes a named
70
- * `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
71
- * unchanged; a second FK sharing already-synthesized backing columns does not
72
- * mint a duplicate index.
73
- */
74
- export function materializeForeignKeysAndIndexes(
75
- tableName: string,
76
- foreignKeys: readonly ForeignKeyAuthoringInput[],
77
- declaredIndexes: readonly IndexInput[],
78
- uniques: readonly UniqueConstraintInput[],
79
- primaryKey: PrimaryKeyInput | undefined,
80
- ): MaterializedTableConstraints {
81
- const satisfiedIndexColumns = new Set(
82
- backingIndexColumnKeys({ indexes: declaredIndexes, uniques, primaryKey }),
83
- );
84
- const synthesizedIndexes: IndexInput[] = [];
85
- const materializedForeignKeys: ForeignKeyInput[] = [];
86
-
87
- for (const { constraint, index, ...reference } of foreignKeys) {
88
- if (constraint !== false) {
89
- materializedForeignKeys.push(reference);
90
- }
91
- if (index !== false) {
92
- const key = reference.source.columns.join(',');
93
- if (!satisfiedIndexColumns.has(key)) {
94
- synthesizedIndexes.push({
95
- columns: reference.source.columns,
96
- name: defaultIndexName(tableName, reference.source.columns),
97
- });
98
- satisfiedIndexColumns.add(key);
99
- }
100
- }
101
- }
102
-
103
- return {
104
- foreignKeys: materializedForeignKeys,
105
- indexes: [...declaredIndexes, ...synthesizedIndexes],
106
- };
107
- }