@prisma-next/sql-contract 0.15.0 → 0.16.0-dev.10

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 (89) hide show
  1. package/dist/canonicalization-hooks.d.mts +0 -1
  2. package/dist/canonicalization-hooks.d.mts.map +1 -1
  3. package/dist/canonicalization-hooks.mjs +0 -10
  4. package/dist/canonicalization-hooks.mjs.map +1 -1
  5. package/dist/contract-errors-CPZcBw8G.mjs +9 -0
  6. package/dist/contract-errors-CPZcBw8G.mjs.map +1 -0
  7. package/dist/contract-view.d.mts +1 -2
  8. package/dist/contract-view.d.mts.map +1 -1
  9. package/dist/entity-handle-lowering-hook.d.mts.map +1 -1
  10. package/dist/{entity-kinds-BEPZdFBN.mjs → entity-kinds-La8Jg-jW.mjs} +6 -7
  11. package/dist/entity-kinds-La8Jg-jW.mjs.map +1 -0
  12. package/dist/entity-kinds.d.mts +2 -3
  13. package/dist/entity-kinds.d.mts.map +1 -1
  14. package/dist/entity-kinds.mjs +1 -1
  15. package/dist/factories.d.mts +4 -6
  16. package/dist/factories.d.mts.map +1 -1
  17. package/dist/factories.mjs +2 -9
  18. package/dist/factories.mjs.map +1 -1
  19. package/dist/{foreign-key-DM1UTydh.d.mts → foreign-key-CWCEM2IT.d.mts} +11 -10
  20. package/dist/foreign-key-CWCEM2IT.d.mts.map +1 -0
  21. package/dist/foreign-key-materialization.d.mts +63 -0
  22. package/dist/foreign-key-materialization.d.mts.map +1 -0
  23. package/dist/foreign-key-materialization.mjs +67 -0
  24. package/dist/foreign-key-materialization.mjs.map +1 -0
  25. package/dist/index-type-validation.d.mts +3 -3
  26. package/dist/index-type-validation.d.mts.map +1 -1
  27. package/dist/{index-types-Czsyu7Iw.d.mts → index-types-DPVhsW0v.d.mts} +2 -3
  28. package/dist/index-types-DPVhsW0v.d.mts.map +1 -0
  29. package/dist/index-types.d.mts +1 -1
  30. package/dist/index-types.mjs +3 -2
  31. package/dist/index-types.mjs.map +1 -1
  32. package/dist/pack-types.d.mts.map +1 -1
  33. package/dist/referential-action-sql.d.mts +1 -2
  34. package/dist/referential-action-sql.d.mts.map +1 -1
  35. package/dist/resolve-storage-table.d.mts +2 -3
  36. package/dist/resolve-storage-table.d.mts.map +1 -1
  37. package/dist/resolve-storage-table.mjs +5 -4
  38. package/dist/resolve-storage-table.mjs.map +1 -1
  39. package/dist/{sql-node-V214WXQD.d.mts → sql-node-QXu33IeX.d.mts} +1 -2
  40. package/dist/sql-node-QXu33IeX.d.mts.map +1 -0
  41. package/dist/{sql-storage-Dt5ipcRl.d.mts → sql-storage-BIErcfFA.d.mts} +4 -5
  42. package/dist/sql-storage-BIErcfFA.d.mts.map +1 -0
  43. package/dist/{storage-table-y6R6pxyI.mjs → storage-table-9O0ZNiMs.mjs} +12 -7
  44. package/dist/storage-table-9O0ZNiMs.mjs.map +1 -0
  45. package/dist/{storage-table-Bj1ZN1P7.d.mts → storage-table-mNGckl3_.d.mts} +5 -56
  46. package/dist/storage-table-mNGckl3_.d.mts.map +1 -0
  47. package/dist/{storage-value-set-D-jww77l.d.mts → storage-value-set-DPHvvSdB.d.mts} +2 -3
  48. package/dist/storage-value-set-DPHvvSdB.d.mts.map +1 -0
  49. package/dist/{storage-value-set-Tx3CFoS_.mjs → storage-value-set-DiGJT-LT.mjs} +2 -2
  50. package/dist/{storage-value-set-Tx3CFoS_.mjs.map → storage-value-set-DiGJT-LT.mjs.map} +1 -1
  51. package/dist/{types-zBvpNCmg.d.mts → types-lpzJtKpv.d.mts} +8 -4
  52. package/dist/types-lpzJtKpv.d.mts.map +1 -0
  53. package/dist/types.d.mts +8 -8
  54. package/dist/types.d.mts.map +1 -1
  55. package/dist/types.mjs +14 -4
  56. package/dist/types.mjs.map +1 -1
  57. package/dist/unique-constraint-WHfanEUq.d.mts +54 -0
  58. package/dist/unique-constraint-WHfanEUq.d.mts.map +1 -0
  59. package/dist/validators.d.mts +4 -4
  60. package/dist/validators.d.mts.map +1 -1
  61. package/dist/validators.mjs +7 -8
  62. package/dist/validators.mjs.map +1 -1
  63. package/dist/value-set-derivation-hook.d.mts +1 -2
  64. package/dist/value-set-derivation-hook.d.mts.map +1 -1
  65. package/package.json +10 -8
  66. package/src/canonicalization-hooks.ts +1 -2
  67. package/src/contract-errors.ts +14 -0
  68. package/src/entity-kinds.ts +4 -1
  69. package/src/exports/foreign-key-materialization.ts +8 -0
  70. package/src/factories.ts +1 -5
  71. package/src/foreign-key-materialization.ts +107 -0
  72. package/src/index-types.ts +11 -2
  73. package/src/ir/foreign-key.ts +9 -9
  74. package/src/ir/sql-storage.ts +2 -1
  75. package/src/ir/storage-entry-schemas.ts +0 -2
  76. package/src/ir/storage-table.ts +2 -1
  77. package/src/resolve-storage-table.ts +4 -1
  78. package/src/validators.ts +17 -6
  79. package/dist/entity-kinds-BEPZdFBN.mjs.map +0 -1
  80. package/dist/foreign-key-DM1UTydh.d.mts.map +0 -1
  81. package/dist/index-types-Czsyu7Iw.d.mts.map +0 -1
  82. package/dist/sql-node-V214WXQD.d.mts.map +0 -1
  83. package/dist/sql-storage-Dt5ipcRl.d.mts.map +0 -1
  84. package/dist/storage-table-Bj1ZN1P7.d.mts.map +0 -1
  85. package/dist/storage-table-y6R6pxyI.mjs.map +0 -1
  86. package/dist/storage-value-set-D-jww77l.d.mts.map +0 -1
  87. package/dist/types-Hkxybhdj.mjs +0 -13
  88. package/dist/types-Hkxybhdj.mjs.map +0 -1
  89. package/dist/types-zBvpNCmg.d.mts.map +0 -1
@@ -1,5 +1,4 @@
1
1
  import { PreserveEmptyPredicate, StorageSort } from "@prisma-next/contract/hashing";
2
-
3
2
  //#region src/canonicalization-hooks.d.ts
4
3
  declare const sqlContractCanonicalizationHooks: {
5
4
  readonly shouldPreserveEmpty: PreserveEmptyPredicate;
@@ -1 +1 @@
1
- {"version":3,"file":"canonicalization-hooks.d.mts","names":[],"sources":["../src/canonicalization-hooks.ts"],"mappings":";;;cAqDa,gCAAA;EAAA,SACF,mBAAA,EAAqB,sBAAA;EAAA,SACrB,WAAA,EAAa,WAAW;AAAA"}
1
+ {"version":3,"file":"canonicalization-hooks.d.mts","names":[],"sources":["../src/canonicalization-hooks.ts"],"mappings":";;cAoDa;WACF,qBAAqB;WACrB,aAAa"}
@@ -29,16 +29,6 @@ const preserveEmptyPatterns = [
29
29
  "foreignKeys"
30
30
  ]
31
31
  ],
32
- [
33
- "storage",
34
- "namespaces",
35
- "*",
36
- "entries",
37
- "table",
38
- "*",
39
- "foreignKeys",
40
- ["constraint", "index"]
41
- ],
42
32
  [
43
33
  "storage",
44
34
  "namespaces",
@@ -1 +1 @@
1
- {"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n matchesPathPattern,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'foreignKeys', ['constraint', 'index']],\n // A column default's literal payload is data, not shape — `{ kind:\n // 'literal', value: false }` (or `value: []`) must survive the\n // default-omission walk or the emitted contract fails its own\n // validation on the next read (PN-CLI-4003 on `Boolean @default(false)`).\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'columns', '*', 'default', 'value'],\n] as const satisfies readonly PathPattern[];\n\n// A literal column default's value is user data, not omittable structure:\n// `@default(false)` (and empty objects/arrays at any depth inside the value)\n// must survive canonicalization, or the emitted contract fails the runtime's\n// structural validation with `default.value … (was missing)`.\nconst columnDefaultValuePrefix = [\n 'storage',\n 'namespaces',\n '*',\n 'entries',\n 'table',\n '*',\n 'columns',\n '*',\n 'default',\n 'value',\n] as const satisfies PathPattern;\n\nconst isColumnDefaultValuePath = (path: readonly string[]): boolean =>\n path.length >= columnDefaultValuePrefix.length &&\n matchesPathPattern(path.slice(0, columnDefaultValuePrefix.length), columnDefaultValuePrefix);\n\nconst sortTargets = [\n { path: ['namespaces', '*', 'entries', 'table', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst matchesPreserveEmptyPattern = createPreserveEmptyPredicate(preserveEmptyPatterns);\n\nconst shouldPreserveEmpty: PreserveEmptyPredicate = (path) =>\n isColumnDefaultValuePath(path) || matchesPreserveEmptyPattern(path);\n\nconst sortStorage: StorageSort = createStorageSort(sortTargets);\n\nexport const sqlContractCanonicalizationHooks: {\n readonly shouldPreserveEmpty: PreserveEmptyPredicate;\n readonly sortStorage: StorageSort;\n} = {\n shouldPreserveEmpty,\n sortStorage,\n};\n"],"mappings":";;AASA,MAAM,wBAAwB;CAC5B;EAAC;EAAW;EAAc;EAAK;EAAW;CAAO;CACjD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;CAAG;CACtD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;GAAC;GAAW;GAAW;EAAa;CAAC;CAC7F;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;EAAe,CAAC,cAAc,OAAO;CAAC;CAK9F;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;EAAW;EAAK;EAAW;CAAO;AAC5F;AAMA,MAAM,2BAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,4BAA4B,SAChC,KAAK,UAAU,yBAAyB,UACxC,mBAAmB,KAAK,MAAM,GAAG,yBAAyB,MAAM,GAAG,wBAAwB;AAE7F,MAAM,cAAc,CAClB;CAAE,MAAM;EAAC;EAAc;EAAK;EAAW;EAAS;CAAG;CAAG,WAAW,CAAC,WAAW,SAAS;AAAE,CAC1F;AAEA,MAAM,8BAA8B,6BAA6B,qBAAqB;AAEtF,MAAM,uBAA+C,SACnD,yBAAyB,IAAI,KAAK,4BAA4B,IAAI;AAIpE,MAAa,mCAGT;CACF;CACA,aAP+B,kBAAkB,WAOjD;AACF"}
1
+ {"version":3,"file":"canonicalization-hooks.mjs","names":[],"sources":["../src/canonicalization-hooks.ts"],"sourcesContent":["import type { PreserveEmptyPredicate, StorageSort } from '@prisma-next/contract/hashing';\nimport {\n createPreserveEmptyPredicate,\n createStorageSort,\n matchesPathPattern,\n type NamedArraySortTarget,\n type PathPattern,\n} from '@prisma-next/contract/hashing-utils';\n\nconst preserveEmptyPatterns = [\n ['storage', 'namespaces', '*', 'entries', 'table'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*'],\n ['storage', 'namespaces', '*', 'entries', 'table', '*', ['uniques', 'indexes', 'foreignKeys']],\n // A column default's literal payload is data, not shape — `{ kind:\n // 'literal', value: false }` (or `value: []`) must survive the\n // default-omission walk or the emitted contract fails its own\n // validation on the next read (CONTRACT.VALIDATION_FAILED on `Boolean @default(false)`).\n ['storage', 'namespaces', '*', 'entries', 'table', '*', 'columns', '*', 'default', 'value'],\n] as const satisfies readonly PathPattern[];\n\n// A literal column default's value is user data, not omittable structure:\n// `@default(false)` (and empty objects/arrays at any depth inside the value)\n// must survive canonicalization, or the emitted contract fails the runtime's\n// structural validation with `default.value … (was missing)`.\nconst columnDefaultValuePrefix = [\n 'storage',\n 'namespaces',\n '*',\n 'entries',\n 'table',\n '*',\n 'columns',\n '*',\n 'default',\n 'value',\n] as const satisfies PathPattern;\n\nconst isColumnDefaultValuePath = (path: readonly string[]): boolean =>\n path.length >= columnDefaultValuePrefix.length &&\n matchesPathPattern(path.slice(0, columnDefaultValuePrefix.length), columnDefaultValuePrefix);\n\nconst sortTargets = [\n { path: ['namespaces', '*', 'entries', 'table', '*'], arrayKeys: ['indexes', 'uniques'] },\n] as const satisfies readonly NamedArraySortTarget[];\n\nconst matchesPreserveEmptyPattern = createPreserveEmptyPredicate(preserveEmptyPatterns);\n\nconst shouldPreserveEmpty: PreserveEmptyPredicate = (path) =>\n isColumnDefaultValuePath(path) || matchesPreserveEmptyPattern(path);\n\nconst sortStorage: StorageSort = createStorageSort(sortTargets);\n\nexport const sqlContractCanonicalizationHooks: {\n readonly shouldPreserveEmpty: PreserveEmptyPredicate;\n readonly sortStorage: StorageSort;\n} = {\n shouldPreserveEmpty,\n sortStorage,\n};\n"],"mappings":";;AASA,MAAM,wBAAwB;CAC5B;EAAC;EAAW;EAAc;EAAK;EAAW;CAAO;CACjD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;CAAG;CACtD;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;GAAC;GAAW;GAAW;EAAa;CAAC;CAK7F;EAAC;EAAW;EAAc;EAAK;EAAW;EAAS;EAAK;EAAW;EAAK;EAAW;CAAO;AAC5F;AAMA,MAAM,2BAA2B;CAC/B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;AAEA,MAAM,4BAA4B,SAChC,KAAK,UAAU,yBAAyB,UACxC,mBAAmB,KAAK,MAAM,GAAG,yBAAyB,MAAM,GAAG,wBAAwB;AAE7F,MAAM,cAAc,CAClB;CAAE,MAAM;EAAC;EAAc;EAAK;EAAW;EAAS;CAAG;CAAG,WAAW,CAAC,WAAW,SAAS;AAAE,CAC1F;AAEA,MAAM,8BAA8B,6BAA6B,qBAAqB;AAEtF,MAAM,uBAA+C,SACnD,yBAAyB,IAAI,KAAK,4BAA4B,IAAI;AAIpE,MAAa,mCAGT;CACF;CACA,aAP+B,kBAAkB,WAOjD;AACF"}
@@ -0,0 +1,9 @@
1
+ import { structuredError } from "@prisma-next/utils/structured-error";
2
+ //#region src/contract-errors.ts
3
+ function contractError(code, message, options) {
4
+ return structuredError(code, message, options);
5
+ }
6
+ //#endregion
7
+ export { contractError as t };
8
+
9
+ //# sourceMappingURL=contract-errors-CPZcBw8G.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract-errors-CPZcBw8G.mjs","names":[],"sources":["../src/contract-errors.ts"],"sourcesContent":["import type { StructuredError, StructuredErrorOptions } from '@prisma-next/utils/structured-error';\nimport { structuredError } from '@prisma-next/utils/structured-error';\n\ntype ContractCode = `CONTRACT.${ContractSubcode}`;\n\ntype ContractSubcode = 'PACK_CONTRIBUTION_INVALID' | 'TABLE_AMBIGUOUS' | 'VALIDATION_FAILED';\n\nexport function contractError(\n code: ContractCode,\n message: string,\n options?: StructuredErrorOptions,\n): StructuredError {\n return structuredError(code, message, options);\n}\n"],"mappings":";;AAOA,SAAgB,cACd,MACA,SACA,SACiB;CACjB,OAAO,gBAAgB,MAAM,SAAS,OAAO;AAC/C"}
@@ -1,7 +1,6 @@
1
- import { s as SqlStorage } from "./sql-storage-Dt5ipcRl.mjs";
1
+ import { s as SqlStorage } from "./sql-storage-BIErcfFA.mjs";
2
2
  import { DefaultNamespaceEntries, NamespacedEntities, SingleNamespaceView } from "@prisma-next/framework-components/ir";
3
3
  import { Contract } from "@prisma-next/contract/types";
4
-
5
4
  //#region src/contract-view.d.ts
6
5
  /**
7
6
  * The SQL family's statically-named built-in entity kinds. `table` and
@@ -1 +1 @@
1
- {"version":3,"file":"contract-view.d.mts","names":[],"sources":["../src/contract-view.ts"],"mappings":";;;;;;;AAeA;;;cAAa,iBAAA;AAAA,KACD,cAAA,WAAyB,iBAAiB;AAAA,KAEjD,UAAA,mBAA6B,QAAA,CAAS,UAAA,KAAe,uBAAA,CACxD,SAAA;;;;AAHoD;AAAU;;KAYpD,2BAAA,mBAA8C,QAAA,CAAS,UAAA,KACjE,mBAAA,CAAoB,UAAA,CAAW,SAAA,GAAY,cAAA;;;;;;;;;;KAWjC,sBAAA,mBAAyC,QAAA,CAAS,UAAA,KAAe,SAAA,GAC3E,2BAAA,CAA4B,SAAA;EAAA,SACjB,SAAA,EAAW,kBAAA,CAAmB,SAAA,aAAsB,cAAA;AAAA;AAvBtD;AASX;;;;;;AATW,iBAiCK,2BAAA,mBAA8C,QAAA,CAAS,UAAA,GACrE,QAAA,EAAU,SAAA,GACT,sBAAA,CAAuB,SAAA;;;;;;;;;;;KAyBd,sBAAA,mBAAyC,QAAA,CAAS,UAAA,KAAe,SAAA;EAAA,SAClE,SAAA,EAAW,kBAAA,CAAmB,SAAA,aAAsB,cAAA;AAAA;AAxC/D;;;;AAAA,iBA+CgB,2BAAA,mBAA8C,QAAA,CAAS,UAAA,GACrE,QAAA,EAAU,SAAA,GACT,sBAAA,CAAuB,SAAA"}
1
+ {"version":3,"file":"contract-view.d.mts","names":[],"sources":["../src/contract-view.ts"],"mappings":";;;;;;;;;cAea;KACD,yBAAyB;KAEhC,WAAW,kBAAkB,SAAS,eAAe,wBACxD;;;;;;;KASU,4BAA4B,kBAAkB,SAAS,eACjE,oBAAoB,WAAW,YAAY;;;;;;;;;;KAWjC,uBAAuB,kBAAkB,SAAS,eAAe,YAC3E,4BAA4B;WACjB,WAAW,mBAAmB,sBAAsB;;;;;;;;;iBAUjD,4BAA4B,kBAAkB,SAAS,aACrE,UAAU,YACT,uBAAuB;;;;;;;;;;;KAyBd,uBAAuB,kBAAkB,SAAS,eAAe;WAClE,WAAW,mBAAmB,sBAAsB;;;;;;iBAO/C,4BAA4B,kBAAkB,SAAS,aACrE,UAAU,YACT,uBAAuB"}
@@ -1 +1 @@
1
- {"version":3,"file":"entity-handle-lowering-hook.d.mts","names":[],"sources":["../src/entity-handle-lowering-hook.ts"],"mappings":";;AAwBA;;;;;;;;;AAEiC;AAUjC;;;;;;;;;;;;UAZiB,gBAAA;EAAA,SACN,UAAA;EAAA,SACA,IAAA,GAAO,QAAQ,CAAC,MAAA;AAAA;AA0BH;AAIxB;;;;;;AAJwB,KAhBZ,uBAAA;EAAA,SAEG,IAAA;EAAA,SACA,WAAA;EAAA,SACA,SAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,OAAA;EAAA,SACA,WAAA;EAAA,SACA,SAAA;EAAA,SACA,SAAA;AAAA;EAAA,SAGA,IAAA;EAAA,SACA,SAAA;AAAA;;UAIE,wBAAA;EAAA,SACN,MAAA,EAAQ,gBAAA;EAAA,SACR,IAAA,EAAM,QAAA,CAAS,MAAA,SAAe,uBAAA;AAAA;AAAA,UAGxB,yBAAA;EAOiB;EAAA,SALvB,OAAA,WAAkB,wBAAwB;EAAA,SAC1C,kBAAA;AAAA;;UAIM,iBAAA;EAAA,SACN,WAAA;EAAA,SACA,UAAA;EAAA,SACA,GAAA;EAAA,SACA,MAAA;AAAA;AAAA,UAGM,mCAAA;EAMiE;;;;;EAAhF,kBAAA,CAAmB,KAAA,EAAO,yBAAA,YAAqC,iBAAiB;AAAA;AAIlF;AAAA,iBAAgB,4BAAA,CACd,SAAA,YACC,SAAA,IAAa,mCAAmC;;;;;;;AAAA;AAgBnD;KAAY,oBAAA,GAAuB,QAAQ,CAAC,MAAA;EAAA,SAA0B,SAAA;AAAA"}
1
+ {"version":3,"file":"entity-handle-lowering-hook.d.mts","names":[],"sources":["../src/entity-handle-lowering-hook.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;UAwBiB;WACN;WACA,OAAO,SAAS;;;;;;;;;KAUf;WAEG;WACA;WACA;WACA;;WAGA;WACA;WACA;WACA;WACA;;WAGA;WACA;;;UAIE;WACN,QAAQ;WACR,MAAM,SAAS,eAAe;;UAGxB;;WAEN,kBAAkB;WAClB;;;UAIM;WACN;WACA;WACA;WACA;;UAGM;;;;;;EAMf,mBAAmB,OAAO,qCAAqC;;;iBAIjD,6BACd,qBACC,aAAa;;;;;;;;;KAgBJ,uBAAuB,SAAS;WAA0B"}
@@ -1,5 +1,6 @@
1
- import { t as StorageTable } from "./storage-table-y6R6pxyI.mjs";
2
- import { t as StorageValueSet } from "./storage-value-set-Tx3CFoS_.mjs";
1
+ import { t as contractError } from "./contract-errors-CPZcBw8G.mjs";
2
+ import { t as StorageTable } from "./storage-table-9O0ZNiMs.mjs";
3
+ import { t as StorageValueSet } from "./storage-value-set-DiGJT-LT.mjs";
3
4
  import { type } from "arktype";
4
5
  //#region src/ir/storage-entry-schemas.ts
5
6
  const literalKindSchema = type("'literal'");
@@ -78,9 +79,7 @@ const ForeignKeySchema = type.declare().type({
78
79
  target: ForeignKeyReferenceSchema,
79
80
  "name?": "string",
80
81
  "onDelete?": ReferentialActionSchema,
81
- "onUpdate?": ReferentialActionSchema,
82
- constraint: "boolean",
83
- index: "boolean"
82
+ "onUpdate?": ReferentialActionSchema
84
83
  });
85
84
  const CheckConstraintSchema = type({
86
85
  "+": "reject",
@@ -121,7 +120,7 @@ const valueSetEntityKind = {
121
120
  function composeSqlEntityKinds(packKinds = []) {
122
121
  const kinds = /* @__PURE__ */ new Map([["table", tableEntityKind], ["valueSet", valueSetEntityKind]]);
123
122
  for (const descriptor of packKinds) {
124
- if (kinds.has(descriptor.kind)) throw new Error(`composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`);
123
+ if (kinds.has(descriptor.kind)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `composeSqlEntityKinds: duplicate entity kind "${descriptor.kind}" — each kind may be registered only once`, { meta: { entityKind: descriptor.kind } });
125
124
  kinds.set(descriptor.kind, descriptor);
126
125
  }
127
126
  return kinds;
@@ -129,4 +128,4 @@ function composeSqlEntityKinds(packKinds = []) {
129
128
  //#endregion
130
129
  export { ColumnDefaultFunctionSchema as a, ForeignKeyReferenceSchema as c, IndexSchema as d, ReferentialActionSchema as f, CheckConstraintSchema as i, ForeignKeySchema as l, StorageValueSetSchema as m, tableEntityKind as n, ColumnDefaultLiteralSchema as o, StorageTableSchema as p, valueSetEntityKind as r, ColumnDefaultSchema as s, composeSqlEntityKinds as t, ForeignKeySourceSchema as u };
131
130
 
132
- //# sourceMappingURL=entity-kinds-BEPZdFBN.mjs.map
131
+ //# sourceMappingURL=entity-kinds-La8Jg-jW.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entity-kinds-La8Jg-jW.mjs","names":[],"sources":["../src/ir/storage-entry-schemas.ts","../src/entity-kinds.ts"],"sourcesContent":["import { type Type, type } from 'arktype';\nimport type { ForeignKeyInput, ReferentialAction } from './foreign-key';\nimport type { ForeignKeyReferenceInput } from './foreign-key-reference';\nimport type { PrimaryKeyInput } from './primary-key';\nimport type { UniqueConstraintInput } from './unique-constraint';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\n\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst ControlPolicySchema = type(\"'managed' | 'tolerated' | 'external' | 'observed'\");\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst StorageValueSetRefSchema = type({\n plane: \"'storage'\",\n namespaceId: 'string',\n entityKind: \"'valueSet'\",\n entityName: 'string',\n 'spaceId?': 'string',\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'many?': 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n 'control?': ControlPolicySchema,\n 'valueSet?': StorageValueSetRefSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\n/**\n * Storage value-set entry under `storage.namespaces[id].entries.valueSet[name]`.\n * Carries a `kind: 'valueSet'` discriminator (enumerable, survives JSON) and an\n * ordered `values` array of codec-encoded permitted values.\n */\nexport const StorageValueSetSchema = type({\n kind: \"'valueSet'\",\n values: type('string | number | boolean | null | unknown[] | Record<string, unknown>')\n .array()\n .readonly(),\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKeyInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraintInput>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'type?': 'string',\n 'options?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferenceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n 'spaceId?': 'string',\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ForeignKeySourceSchema = type({\n '+': 'reject',\n namespaceId: 'string',\n tableName: 'string',\n columns: type.string.array().readonly(),\n}) satisfies Type<ForeignKeyReferenceInput>;\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKeyInput>().type({\n source: ForeignKeySourceSchema,\n target: ForeignKeyReferenceSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n});\n\nexport const CheckConstraintSchema = type({\n '+': 'reject',\n name: 'string',\n column: 'string',\n valueSet: StorageValueSetRefSchema,\n});\n\nexport const StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n 'control?': ControlPolicySchema,\n 'checks?': CheckConstraintSchema.array().readonly(),\n});\n","import type {\n AnyEntityKindDescriptor,\n EntityKindDescriptor,\n} from '@prisma-next/framework-components/ir';\nimport { contractError } from './contract-errors';\nimport { StorageTableSchema, StorageValueSetSchema } from './ir/storage-entry-schemas';\nimport { StorageTable, type StorageTableInput } from './ir/storage-table';\nimport { StorageValueSet, type StorageValueSetInput } from './ir/storage-value-set';\n\nexport const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable> = {\n kind: 'table',\n schema: StorageTableSchema,\n construct: (input) => new StorageTable(input),\n};\n\nexport const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet> = {\n kind: 'valueSet',\n schema: StorageValueSetSchema,\n construct: (input) => new StorageValueSet(input),\n};\n\n/**\n * Assembles the `kind → descriptor` registry for SQL namespaces: the built-in\n * `table` and `valueSet` kinds plus any target `packKinds`. This builds the\n * lookup table — it does not touch contract data. `hydrateNamespaceEntities`\n * later consumes this registry to turn a namespace's raw entries into IR\n * instances, and `createSqlContractSchema` derives validation from the same\n * registry. Throws on a duplicate kind.\n */\nexport function composeSqlEntityKinds(\n packKinds: readonly AnyEntityKindDescriptor[] = [],\n): ReadonlyMap<string, AnyEntityKindDescriptor> {\n const kinds = new Map<string, AnyEntityKindDescriptor>([\n ['table', tableEntityKind],\n ['valueSet', valueSetEntityKind],\n ]);\n for (const descriptor of packKinds) {\n if (kinds.has(descriptor.kind)) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `composeSqlEntityKinds: duplicate entity kind \"${descriptor.kind}\" — each kind may be registered only once`,\n { meta: { entityKind: descriptor.kind } },\n );\n }\n kinds.set(descriptor.kind, descriptor);\n }\n return kinds;\n}\n"],"mappings":";;;;;AAYA,MAAM,oBAAoB,KAAK,WAAW;AAC1C,MAAM,qBAAqB,KAAK,YAAY;AAC5C,MAAM,sBAAsB,KAAK,mDAAmD;AAEpF,MAAa,6BAA6B,KAAK,QAA8B,CAAC,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;AACT,CAAC;AAED,MAAa,8BAA8B,KAAK,QAA+B,CAAC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;AACd,CAAC;AAED,MAAa,sBAAsB,2BAA2B,GAAG,2BAA2B;AAE5F,MAAM,2BAA2B,KAAK;CACpC,OAAO;CACP,aAAa;CACb,YAAY;CACZ,YAAY;CACZ,YAAY;AACd,CAAC;AAED,MAAM,sBAAsB,KAAK;CAC/B,KAAK;CACL,YAAY;CACZ,SAAS;CACT,UAAU;CACV,SAAS;CACT,eAAe;CACf,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,aAAa;AACf,CAAC,CAAC,CAAC,QAAQ,KAAK,QAAQ;CACtB,IAAI,IAAI,eAAe,KAAA,KAAa,IAAI,YAAY,KAAA,GAClD,OAAO,IAAI,OAAO,sDAAsD;CAE1E,OAAO;AACT,CAAC;;;;;;AAOD,MAAa,wBAAwB,KAAK;CACxC,MAAM;CACN,QAAQ,KAAK,wEAAwE,CAAC,CACnF,MAAM,CAAC,CACP,SAAS;AACd,CAAC;AAED,MAAM,mBAAmB,KAAK,QAAyB,CAAC,CAAC,KAAK;CAC5D,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;AACX,CAAC;AAED,MAAM,yBAAyB,KAAK,QAA+B,CAAC,CAAC,KAAK;CACxE,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;AACX,CAAC;AAED,MAAa,cAAc,KAAK;CAC9B,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,SAAS;CACT,SAAS;CACT,YAAY;AACd,CAAC;AAED,MAAa,4BAA4B,KAAK;CAC5C,KAAK;CACL,aAAa;CACb,WAAW;CACX,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;CACtC,YAAY;AACd,CAAC;AAED,MAAa,yBAAyB,KAAK;CACzC,KAAK;CACL,aAAa;CACb,WAAW;CACX,SAAS,KAAK,OAAO,MAAM,CAAC,CAAC,SAAS;AACxC,CAAC;AAED,MAAa,0BAA0B,KACpC,QAA2B,CAAC,CAC5B,KAAK,gEAAgE;AAExE,MAAa,mBAAmB,KAAK,QAAyB,CAAC,CAAC,KAAK;CACnE,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,aAAa;CACb,aAAa;AACf,CAAC;AAED,MAAa,wBAAwB,KAAK;CACxC,KAAK;CACL,MAAM;CACN,QAAQ;CACR,UAAU;AACZ,CAAC;AAED,MAAa,qBAAqB,KAAK;CACrC,KAAK;CACL,SAAS,KAAK,EAAE,YAAY,oBAAoB,CAAC;CACjD,eAAe;CACf,SAAS,uBAAuB,MAAM,CAAC,CAAC,SAAS;CACjD,SAAS,YAAY,MAAM,CAAC,CAAC,SAAS;CACtC,aAAa,iBAAiB,MAAM,CAAC,CAAC,SAAS;CAC/C,YAAY;CACZ,WAAW,sBAAsB,MAAM,CAAC,CAAC,SAAS;AACpD,CAAC;;;ACrHD,MAAa,kBAAyE;CACpF,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,aAAa,KAAK;AAC9C;AAEA,MAAa,qBAAkF;CAC7F,MAAM;CACN,QAAQ;CACR,YAAY,UAAU,IAAI,gBAAgB,KAAK;AACjD;;;;;;;;;AAUA,SAAgB,sBACd,YAAgD,CAAC,GACH;CAC9C,MAAM,wBAAQ,IAAI,IAAqC,CACrD,CAAC,SAAS,eAAe,GACzB,CAAC,YAAY,kBAAkB,CACjC,CAAC;CACD,KAAK,MAAM,cAAc,WAAW;EAClC,IAAI,MAAM,IAAI,WAAW,IAAI,GAC3B,MAAM,cACJ,sCACA,iDAAiD,WAAW,KAAK,4CACjE,EAAE,MAAM,EAAE,YAAY,WAAW,KAAK,EAAE,CAC1C;EAEF,MAAM,IAAI,WAAW,MAAM,UAAU;CACvC;CACA,OAAO;AACT"}
@@ -1,7 +1,6 @@
1
- import { n as StorageTableInput, t as StorageTable } from "./storage-table-Bj1ZN1P7.mjs";
2
- import { n as StorageValueSetInput, t as StorageValueSet } from "./storage-value-set-D-jww77l.mjs";
1
+ import { n as StorageTableInput, t as StorageTable } from "./storage-table-mNGckl3_.mjs";
2
+ import { n as StorageValueSetInput, t as StorageValueSet } from "./storage-value-set-DPHvvSdB.mjs";
3
3
  import { AnyEntityKindDescriptor, EntityKindDescriptor } from "@prisma-next/framework-components/ir";
4
-
5
4
  //#region src/entity-kinds.d.ts
6
5
  declare const tableEntityKind: EntityKindDescriptor<StorageTableInput, StorageTable>;
7
6
  declare const valueSetEntityKind: EntityKindDescriptor<StorageValueSetInput, StorageValueSet>;
@@ -1 +1 @@
1
- {"version":3,"file":"entity-kinds.d.mts","names":[],"sources":["../src/entity-kinds.ts"],"mappings":";;;;;cAQa,eAAA,EAAiB,oBAAA,CAAqB,iBAAA,EAAmB,YAAA;AAAA,cAMzD,kBAAA,EAAoB,oBAAA,CAAqB,oBAAA,EAAsB,eAAA;AAN5E;;;;;;;;AAAA,iBAoBgB,qBAAA,CACd,SAAA,YAAoB,uBAAA,KACnB,WAAA,SAAoB,uBAAA"}
1
+ {"version":3,"file":"entity-kinds.d.mts","names":[],"sources":["../src/entity-kinds.ts"],"mappings":";;;;cASa,iBAAiB,qBAAqB,mBAAmB;cAMzD,oBAAoB,qBAAqB,sBAAsB;;;;;;;;;iBAc5D,sBACd,qBAAoB,4BACnB,oBAAoB"}
@@ -1,2 +1,2 @@
1
- import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-BEPZdFBN.mjs";
1
+ import { n as tableEntityKind, r as valueSetEntityKind, t as composeSqlEntityKinds } from "./entity-kinds-La8Jg-jW.mjs";
2
2
  export { composeSqlEntityKinds, tableEntityKind, valueSetEntityKind };
@@ -1,8 +1,8 @@
1
- import { a as StorageColumn, l as PrimaryKey, o as StorageColumnInput, r as UniqueConstraint, s as Index, t as StorageTable } from "./storage-table-Bj1ZN1P7.mjs";
2
- import { t as ForeignKey } from "./foreign-key-DM1UTydh.mjs";
3
- import { T as SqlModelStorage, m as ForeignKeyOptions, w as SqlModelFieldStorage } from "./types-zBvpNCmg.mjs";
1
+ import { i as StorageColumnInput, r as StorageColumn, t as StorageTable } from "./storage-table-mNGckl3_.mjs";
2
+ import { t as ForeignKey } from "./foreign-key-CWCEM2IT.mjs";
3
+ import { a as PrimaryKey, r as Index, t as UniqueConstraint } from "./unique-constraint-WHfanEUq.mjs";
4
+ import { T as SqlModelStorage, m as ForeignKeyOptions, w as SqlModelFieldStorage } from "./types-lpzJtKpv.mjs";
4
5
  import { ScalarFieldType } from "@prisma-next/contract/types";
5
-
6
6
  //#region src/factories.d.ts
7
7
  declare function col(nativeType: string, codecId: string, nullable?: boolean, opts?: {
8
8
  readonly many?: boolean;
@@ -11,8 +11,6 @@ declare function pk(...columns: readonly string[]): PrimaryKey;
11
11
  declare function unique(...columns: readonly string[]): UniqueConstraint;
12
12
  declare function index(...columns: readonly string[]): Index;
13
13
  declare function fk(srcTableName: string, srcColumns: readonly string[], targetTableName: string, targetColumns: readonly string[], opts?: ForeignKeyOptions & {
14
- constraint?: boolean;
15
- index?: boolean;
16
14
  namespaceId?: string;
17
15
  }): ForeignKey;
18
16
  declare function table(columns: Record<string, StorageColumn | StorageColumnInput>, opts?: {
@@ -1 +1 @@
1
- {"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;;;iBAgBgB,GAAA,CACd,UAAA,UACA,OAAA,UACA,QAAA,YACA,IAAA;EAAA,SAAkB,IAAA;AAAA,IACjB,aAAa;AAAA,iBASA,EAAA,IAAM,OAAA,sBAA6B,UAAU;AAAA,iBAI7C,MAAA,IAAU,OAAA,sBAA6B,gBAAgB;AAAA,iBAIvD,KAAA,IAAS,OAAA,sBAA6B,KAAK;AAAA,iBAI3C,EAAA,CACd,YAAA,UACA,UAAA,qBACA,eAAA,UACA,aAAA,qBACA,IAAA,GAAO,iBAAA;EAAsB,UAAA;EAAsB,KAAA;EAAiB,WAAA;AAAA,IACnE,UAAU;AAAA,iBAcG,KAAA,CACd,OAAA,EAAS,MAAA,SAAe,aAAA,GAAgB,kBAAA,GACxC,IAAA;EACE,EAAA,GAAK,UAAA;EACL,OAAA,YAAmB,gBAAA;EACnB,OAAA,YAAmB,KAAA;EACnB,GAAA,YAAe,UAAA;AAAA,IAEhB,YAAA;AAAA,iBAUa,KAAA,CACd,SAAA,UACA,MAAA,EAAQ,MAAA,SAAe,oBAAA,GACvB,SAAA,GAAW,MAAA,mBACX,WAAA;EAEA,OAAA,EAAS,eAAA;EACT,MAAA,EAAQ,MAAA;IAAA,SAA0B,QAAA;IAAA,SAA4B,IAAA,EAAM,eAAA;EAAA;EACpE,SAAA,EAAW,MAAA;AAAA"}
1
+ {"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;;;iBAegB,IACd,oBACA,iBACA,oBACA;WAAkB;IACjB;iBASa,MAAM,6BAA6B;iBAInC,UAAU,6BAA6B;iBAIvC,SAAS,6BAA6B;iBAItC,GACd,sBACA,+BACA,yBACA,kCACA,OAAO;EAAsB;IAC5B;iBAWa,MACd,SAAS,eAAe,gBAAgB,qBACxC;EACE,KAAK;EACL,mBAAmB;EACnB,mBAAmB;EACnB,eAAe;IAEhB;iBAUa,MACd,mBACA,QAAQ,eAAe,uBACvB,YAAW,yBACX;EAEA,SAAS;EACT,QAAQ;aAA0B;aAA4B,MAAM;;EACpE,WAAW"}
@@ -1,5 +1,4 @@
1
- import { a as PrimaryKey, i as Index, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, t as StorageTable } from "./storage-table-y6R6pxyI.mjs";
2
- import { r as applyFkDefaults } from "./types-Hkxybhdj.mjs";
1
+ import { a as PrimaryKey, i as Index, n as UniqueConstraint, o as ForeignKey, r as StorageColumn, t as StorageTable } from "./storage-table-9O0ZNiMs.mjs";
3
2
  import { UNBOUND_NAMESPACE_ID } from "@prisma-next/framework-components/ir";
4
3
  import { asNamespaceId } from "@prisma-next/contract/types";
5
4
  //#region src/factories.ts
@@ -21,10 +20,6 @@ function index(...columns) {
21
20
  return new Index({ columns });
22
21
  }
23
22
  function fk(srcTableName, srcColumns, targetTableName, targetColumns, opts) {
24
- const defaults = applyFkDefaults({
25
- constraint: opts?.constraint,
26
- index: opts?.index
27
- });
28
23
  const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);
29
24
  return new ForeignKey({
30
25
  source: {
@@ -39,9 +34,7 @@ function fk(srcTableName, srcColumns, targetTableName, targetColumns, opts) {
39
34
  },
40
35
  ...opts?.name !== void 0 && { name: opts.name },
41
36
  ...opts?.onDelete !== void 0 && { onDelete: opts.onDelete },
42
- ...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate },
43
- constraint: defaults.constraint,
44
- index: defaults.index
37
+ ...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate }
45
38
  });
46
39
  }
47
40
  function table(columns, opts) {
@@ -1 +1 @@
1
- {"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import { asNamespaceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n applyFkDefaults,\n ForeignKey,\n type ForeignKeyOptions,\n Index,\n PrimaryKey,\n type SqlModelFieldStorage,\n type SqlModelStorage,\n StorageColumn,\n type StorageColumnInput,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nexport function col(\n nativeType: string,\n codecId: string,\n nullable = false,\n opts?: { readonly many?: boolean },\n): StorageColumn {\n return new StorageColumn({\n nativeType,\n codecId,\n nullable,\n ...(opts?.many !== undefined && { many: opts.many }),\n });\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return new PrimaryKey({ columns });\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return new UniqueConstraint({ columns });\n}\n\nexport function index(...columns: readonly string[]): Index {\n return new Index({ columns });\n}\n\nexport function fk(\n srcTableName: string,\n srcColumns: readonly string[],\n targetTableName: string,\n targetColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean; namespaceId?: string },\n): ForeignKey {\n const defaults = applyFkDefaults({ constraint: opts?.constraint, index: opts?.index });\n const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);\n return new ForeignKey({\n source: { namespaceId, tableName: srcTableName, columns: srcColumns },\n target: { namespaceId, tableName: targetTableName, columns: targetColumns },\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n constraint: defaults.constraint,\n index: defaults.index,\n });\n}\n\nexport function table(\n columns: Record<string, StorageColumn | StorageColumnInput>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return new StorageTable({\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n });\n}\n\nexport function model(\n tableName: string,\n fields: Record<string, SqlModelFieldStorage>,\n relations: Record<string, unknown> = {},\n namespaceId: string = UNBOUND_NAMESPACE_ID,\n): {\n storage: SqlModelStorage;\n fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;\n relations: Record<string, unknown>;\n} {\n const storage: SqlModelStorage = { table: tableName, namespaceId, fields };\n const domainFields = Object.fromEntries(\n Object.entries(fields).map(([name, field]) => [\n name,\n {\n nullable: field.nullable ?? false,\n type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },\n },\n ]),\n ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;\n return {\n storage,\n fields: domainFields,\n relations,\n };\n}\n"],"mappings":";;;;;AAgBA,SAAgB,IACd,YACA,SACA,WAAW,OACX,MACe;CACf,OAAO,IAAI,cAAc;EACvB;EACA;EACA;EACA,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;CACpD,CAAC;AACH;AAEA,SAAgB,GAAG,GAAG,SAAwC;CAC5D,OAAO,IAAI,WAAW,EAAE,QAAQ,CAAC;AACnC;AAEA,SAAgB,OAAO,GAAG,SAA8C;CACtE,OAAO,IAAI,iBAAiB,EAAE,QAAQ,CAAC;AACzC;AAEA,SAAgB,MAAM,GAAG,SAAmC;CAC1D,OAAO,IAAI,MAAM,EAAE,QAAQ,CAAC;AAC9B;AAEA,SAAgB,GACd,cACA,YACA,iBACA,eACA,MACY;CACZ,MAAM,WAAW,gBAAgB;EAAE,YAAY,MAAM;EAAY,OAAO,MAAM;CAAM,CAAC;CACrF,MAAM,cAAc,cAAc,MAAM,eAAe,oBAAoB;CAC3E,OAAO,IAAI,WAAW;EACpB,QAAQ;GAAE;GAAa,WAAW;GAAc,SAAS;EAAW;EACpE,QAAQ;GAAE;GAAa,WAAW;GAAiB,SAAS;EAAc;EAC1E,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;EAClD,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,YAAY,SAAS;EACrB,OAAO,SAAS;CAClB,CAAC;AACH;AAEA,SAAgB,MACd,SACA,MAMc;CACd,OAAO,IAAI,aAAa;EACtB;EACA,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,YAAY,KAAK,GAAG;EACpD,SAAS,MAAM,WAAW,CAAC;EAC3B,SAAS,MAAM,WAAW,CAAC;EAC3B,aAAa,MAAM,OAAO,CAAC;CAC7B,CAAC;AACH;AAEA,SAAgB,MACd,WACA,QACA,YAAqC,CAAC,GACtC,cAAsB,sBAKtB;CAWA,OAAO;EACL,SAAA;GAXiC,OAAO;GAAW;GAAa;EAW1D;EACN,QAXmB,OAAO,YAC1B,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA;GACE,UAAU,MAAM,YAAY;GAC5B,MAAM;IAAE,MAAM;IAAmB,SAAS,MAAM,WAAW;GAAiB;EAC9E,CACF,CAAC,CAIkB;EACnB;CACF;AACF"}
1
+ {"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import { asNamespaceId, type ScalarFieldType } from '@prisma-next/contract/types';\nimport { UNBOUND_NAMESPACE_ID } from '@prisma-next/framework-components/ir';\nimport {\n ForeignKey,\n type ForeignKeyOptions,\n Index,\n PrimaryKey,\n type SqlModelFieldStorage,\n type SqlModelStorage,\n StorageColumn,\n type StorageColumnInput,\n StorageTable,\n UniqueConstraint,\n} from './types';\n\nexport function col(\n nativeType: string,\n codecId: string,\n nullable = false,\n opts?: { readonly many?: boolean },\n): StorageColumn {\n return new StorageColumn({\n nativeType,\n codecId,\n nullable,\n ...(opts?.many !== undefined && { many: opts.many }),\n });\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return new PrimaryKey({ columns });\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return new UniqueConstraint({ columns });\n}\n\nexport function index(...columns: readonly string[]): Index {\n return new Index({ columns });\n}\n\nexport function fk(\n srcTableName: string,\n srcColumns: readonly string[],\n targetTableName: string,\n targetColumns: readonly string[],\n opts?: ForeignKeyOptions & { namespaceId?: string },\n): ForeignKey {\n const namespaceId = asNamespaceId(opts?.namespaceId ?? UNBOUND_NAMESPACE_ID);\n return new ForeignKey({\n source: { namespaceId, tableName: srcTableName, columns: srcColumns },\n target: { namespaceId, tableName: targetTableName, columns: targetColumns },\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n });\n}\n\nexport function table(\n columns: Record<string, StorageColumn | StorageColumnInput>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return new StorageTable({\n columns,\n ...(opts?.pk !== undefined && { primaryKey: opts.pk }),\n uniques: opts?.uniques ?? [],\n indexes: opts?.indexes ?? [],\n foreignKeys: opts?.fks ?? [],\n });\n}\n\nexport function model(\n tableName: string,\n fields: Record<string, SqlModelFieldStorage>,\n relations: Record<string, unknown> = {},\n namespaceId: string = UNBOUND_NAMESPACE_ID,\n): {\n storage: SqlModelStorage;\n fields: Record<string, { readonly nullable: boolean; readonly type: ScalarFieldType }>;\n relations: Record<string, unknown>;\n} {\n const storage: SqlModelStorage = { table: tableName, namespaceId, fields };\n const domainFields = Object.fromEntries(\n Object.entries(fields).map(([name, field]) => [\n name,\n {\n nullable: field.nullable ?? false,\n type: { kind: 'scalar' as const, codecId: field.codecId ?? 'core/unknown@1' },\n },\n ]),\n ) as Record<string, { nullable: boolean; type: ScalarFieldType }>;\n return {\n storage,\n fields: domainFields,\n relations,\n };\n}\n"],"mappings":";;;;AAeA,SAAgB,IACd,YACA,SACA,WAAW,OACX,MACe;CACf,OAAO,IAAI,cAAc;EACvB;EACA;EACA;EACA,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;CACpD,CAAC;AACH;AAEA,SAAgB,GAAG,GAAG,SAAwC;CAC5D,OAAO,IAAI,WAAW,EAAE,QAAQ,CAAC;AACnC;AAEA,SAAgB,OAAO,GAAG,SAA8C;CACtE,OAAO,IAAI,iBAAiB,EAAE,QAAQ,CAAC;AACzC;AAEA,SAAgB,MAAM,GAAG,SAAmC;CAC1D,OAAO,IAAI,MAAM,EAAE,QAAQ,CAAC;AAC9B;AAEA,SAAgB,GACd,cACA,YACA,iBACA,eACA,MACY;CACZ,MAAM,cAAc,cAAc,MAAM,eAAe,oBAAoB;CAC3E,OAAO,IAAI,WAAW;EACpB,QAAQ;GAAE;GAAa,WAAW;GAAc,SAAS;EAAW;EACpE,QAAQ;GAAE;GAAa,WAAW;GAAiB,SAAS;EAAc;EAC1E,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,KAAK;EAClD,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;EAC9D,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,SAAS;CAChE,CAAC;AACH;AAEA,SAAgB,MACd,SACA,MAMc;CACd,OAAO,IAAI,aAAa;EACtB;EACA,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,YAAY,KAAK,GAAG;EACpD,SAAS,MAAM,WAAW,CAAC;EAC3B,SAAS,MAAM,WAAW,CAAC;EAC3B,aAAa,MAAM,OAAO,CAAC;CAC7B,CAAC;AACH;AAEA,SAAgB,MACd,WACA,QACA,YAAqC,CAAC,GACtC,cAAsB,sBAKtB;CAWA,OAAO;EACL,SAAA;GAXiC,OAAO;GAAW;GAAa;EAW1D;EACN,QAXmB,OAAO,YAC1B,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA;GACE,UAAU,MAAM,YAAY;GAC5B,MAAM;IAAE,MAAM;IAAmB,SAAS,MAAM,WAAW;GAAiB;EAC9E,CACF,CAAC,CAIkB;EACnB;CACF;AACF"}
@@ -1,6 +1,5 @@
1
- import { t as SqlNode } from "./sql-node-V214WXQD.mjs";
1
+ import { t as SqlNode } from "./sql-node-QXu33IeX.mjs";
2
2
  import { NamespaceId } from "@prisma-next/contract/types";
3
-
4
3
  //#region src/ir/foreign-key-reference.d.ts
5
4
  /**
6
5
  * Input for a foreign-key reference (one side of a foreign-key declaration).
@@ -51,13 +50,17 @@ interface ForeignKeyInput {
51
50
  readonly name?: string;
52
51
  readonly onDelete?: ReferentialAction;
53
52
  readonly onUpdate?: ReferentialAction;
54
- /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
55
- readonly constraint: boolean;
56
- /** Whether to emit a backing index for the FK columns. */
57
- readonly index: boolean;
58
53
  }
59
54
  /**
60
- * SQL Contract IR node for a table-level foreign-key declaration.
55
+ * SQL Contract IR node for a table-level foreign-key declaration — the
56
+ * referential constraint only (source, target, `onDelete`/`onUpdate`).
57
+ *
58
+ * A persisted `foreignKeys[]` entry always denotes a real constraint: whether
59
+ * to emit the constraint at all, and whether to back it with an index, are
60
+ * authoring-time decisions (PSL `@relation(index:)`, TS `fk({ constraint,
61
+ * index })`) resolved once at `contract emit` — a `constraint: false` FK
62
+ * simply has no entry here, and a backing index (if any) is its own discrete,
63
+ * named entry in the table's `indexes[]`.
61
64
  *
62
65
  * Each FK carries explicit `source` and `target` {@link ForeignKeyReference}
63
66
  * coordinates (namespace, table, columns). For single-namespace contracts the
@@ -71,8 +74,6 @@ interface ForeignKeyInput {
71
74
  declare class ForeignKey extends SqlNode {
72
75
  readonly source: ForeignKeyReference;
73
76
  readonly target: ForeignKeyReference;
74
- readonly constraint: boolean;
75
- readonly index: boolean;
76
77
  readonly name?: string;
77
78
  readonly onDelete?: ReferentialAction;
78
79
  readonly onUpdate?: ReferentialAction;
@@ -80,4 +81,4 @@ declare class ForeignKey extends SqlNode {
80
81
  }
81
82
  //#endregion
82
83
  export { ForeignKeyReferenceInput as a, ForeignKeyReference as i, ForeignKeyInput as n, ReferentialAction as r, ForeignKey as t };
83
- //# sourceMappingURL=foreign-key-DM1UTydh.d.mts.map
84
+ //# sourceMappingURL=foreign-key-CWCEM2IT.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"foreign-key-CWCEM2IT.d.mts","names":[],"sources":["../src/ir/foreign-key-reference.ts","../src/ir/foreign-key.ts"],"mappings":";;;;;;;;;;;;;;UAeiB;WACN;WACA;WACA;WACA;;;;;;;;;;;;;;;;;;cAmBE,4BAA4B;WAC9B,aAAa;WACb;WACA;WACQ;cAEL,OAAO;;;;KCxCT;UAEK;WACN,QAAQ,sBAAsB;WAC9B,QAAQ,sBAAsB;WAC9B;WACA,WAAW;WACX,WAAW;;;;;;;;;;;;;;;;;;;;;;cAuBT,mBAAmB;WACrB,QAAQ;WACR,QAAQ;WACA;WACA,WAAW;WACX,WAAW;cAEhB,OAAO"}
@@ -0,0 +1,63 @@
1
+ import { a as ForeignKeyReferenceInput, n as ForeignKeyInput, r as ReferentialAction } from "./foreign-key-CWCEM2IT.mjs";
2
+ import { i as IndexInput, n as UniqueConstraintInput, o as PrimaryKeyInput } from "./unique-constraint-WHfanEUq.mjs";
3
+ //#region src/foreign-key-materialization.d.ts
4
+ type BackingIndexCandidates = {
5
+ readonly indexes: readonly {
6
+ readonly columns: readonly string[];
7
+ }[];
8
+ readonly uniques: readonly {
9
+ readonly columns: readonly string[];
10
+ }[];
11
+ readonly primaryKey?: {
12
+ readonly columns: readonly string[];
13
+ } | undefined;
14
+ };
15
+ /**
16
+ * The column-list keys (`"colA,colB"`, order preserved) a table's own
17
+ * indexes, unique constraints, and primary key already back. A foreign key
18
+ * whose source columns join to one of these keys needs no separately
19
+ * derived backing index.
20
+ *
21
+ * Shared by {@link isBackedByColumnKeys}'s callers: `materializeForeignKeysAndIndexes`
22
+ * (deriving the discrete backing-index entities persisted at `contract emit`)
23
+ * and the postgres PSL inferrer (deciding whether an introspected relation
24
+ * needs an explicit `index: false`).
25
+ */
26
+ declare function backingIndexColumnKeys(table: BackingIndexCandidates): readonly string[];
27
+ /**
28
+ * Whether `columns`, in order, matches one of `backingKeys` (see
29
+ * {@link backingIndexColumnKeys}). Order-sensitive: `(a, b)` does not
30
+ * satisfy a backing index declared as `(b, a)`.
31
+ */
32
+ declare function isBackedByColumnKeys(columns: readonly string[], backingKeys: readonly string[]): boolean;
33
+ /**
34
+ * A foreign key as authored, before FK1 materialization: the referential
35
+ * coordinates plus the `constraint`/`index` intent booleans that drive
36
+ * whether — and how — it survives into the persisted contract.
37
+ */
38
+ interface ForeignKeyAuthoringInput {
39
+ readonly source: ForeignKeyReferenceInput;
40
+ readonly target: ForeignKeyReferenceInput;
41
+ readonly name?: string;
42
+ readonly onDelete?: ReferentialAction;
43
+ readonly onUpdate?: ReferentialAction;
44
+ readonly constraint: boolean;
45
+ readonly index: boolean;
46
+ }
47
+ interface MaterializedTableConstraints {
48
+ readonly foreignKeys: readonly ForeignKeyInput[];
49
+ readonly indexes: readonly IndexInput[];
50
+ }
51
+ /**
52
+ * Lowers a table's authored foreign keys into the discrete entities
53
+ * `contract.json` persists: a `constraint: false` FK contributes no
54
+ * `foreignKeys[]` entry, and an `index: true` FK whose columns aren't already
55
+ * backed by a declared index/unique/primary-key contributes a named
56
+ * `indexes[]` entry (`defaultIndexName`). Declared indexes always survive
57
+ * unchanged; a second FK sharing already-synthesized backing columns does not
58
+ * mint a duplicate index.
59
+ */
60
+ declare function materializeForeignKeysAndIndexes(tableName: string, foreignKeys: readonly ForeignKeyAuthoringInput[], declaredIndexes: readonly IndexInput[], uniques: readonly UniqueConstraintInput[], primaryKey: PrimaryKeyInput | undefined): MaterializedTableConstraints;
61
+ //#endregion
62
+ export { type BackingIndexCandidates, type ForeignKeyAuthoringInput, type MaterializedTableConstraints, backingIndexColumnKeys, isBackedByColumnKeys, materializeForeignKeysAndIndexes };
63
+ //# sourceMappingURL=foreign-key-materialization.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"foreign-key-materialization.d.mts","names":[],"sources":["../src/foreign-key-materialization.ts"],"mappings":";;;KAOY;WACD;aAA6B;;WAC7B;aAA6B;;WAC7B;aAAwB;;;;;;;;;;;;;;iBAcnB,uBAAuB,OAAO;;;;;;iBAa9B,qBACd,4BACA;;;;;;UAUe;WACN,QAAQ;WACR,QAAQ;WACR;WACA,WAAW;WACX,WAAW;WACX;WACA;;UAGM;WACN,sBAAsB;WACtB,kBAAkB;;;;;;;;;;;iBAYb,iCACd,mBACA,sBAAsB,4BACtB,0BAA0B,cAC1B,kBAAkB,yBAClB,YAAY,8BACX"}
@@ -0,0 +1,67 @@
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
@@ -0,0 +1 @@
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,7 +1,7 @@
1
- import { s as SqlStorage } from "./sql-storage-Dt5ipcRl.mjs";
2
- import { a as IndexTypeRegistry } from "./index-types-Czsyu7Iw.mjs";
1
+ import { s as SqlStorage } from "./sql-storage-BIErcfFA.mjs";
2
+ import "./types-lpzJtKpv.mjs";
3
+ import { a as IndexTypeRegistry } from "./index-types-DPVhsW0v.mjs";
3
4
  import { Contract } from "@prisma-next/contract/types";
4
-
5
5
  //#region src/index-type-validation.d.ts
6
6
  declare function validateIndexTypes(contract: Contract<SqlStorage>, indexTypeRegistry: IndexTypeRegistry): void;
7
7
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"index-type-validation.d.mts","names":[],"sources":["../src/index-type-validation.ts"],"mappings":";;;;;iBAMgB,kBAAA,CACd,QAAA,EAAU,QAAA,CAAS,UAAA,GACnB,iBAAA,EAAmB,iBAAA"}
1
+ {"version":3,"file":"index-type-validation.d.mts","names":[],"sources":["../src/index-type-validation.ts"],"mappings":";;;;;iBAMgB,mBACd,UAAU,SAAS,aACnB,mBAAmB"}
@@ -1,5 +1,4 @@
1
1
  import { Type } from "arktype";
2
-
3
2
  //#region src/index-types.d.ts
4
3
  interface IndexTypeEntry<TOptions = unknown> {
5
4
  readonly type: string;
@@ -7,7 +6,7 @@ interface IndexTypeEntry<TOptions = unknown> {
7
6
  }
8
7
  type IndexTypeMap = { readonly [K in string]: {
9
8
  readonly options: unknown;
10
- } };
9
+ }; };
11
10
  interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {
12
11
  readonly IndexTypes: TMap;
13
12
  readonly entries: ReadonlyArray<IndexTypeEntry>;
@@ -28,4 +27,4 @@ interface IndexTypeRegistry {
28
27
  declare function createIndexTypeRegistry(): IndexTypeRegistry;
29
28
  //#endregion
30
29
  export { IndexTypeRegistry as a, IndexTypeRegistration as i, IndexTypeEntry as n, createIndexTypeRegistry as o, IndexTypeMap as r, defineIndexTypes as s, IndexTypeBuilder as t };
31
- //# sourceMappingURL=index-types-Czsyu7Iw.d.mts.map
30
+ //# sourceMappingURL=index-types-DPVhsW0v.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-types-DPVhsW0v.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;UAGiB,eAAe;WACrB;WACA,SAAS,KAAK;;KAGb,2BAA2B;WAAyB;;UAE/C,sBAAsB,aAAa,eAAe;WACxD,YAAY;WACZ,SAAS,cAAc;;UAGjB,iBAAiB,aAAa,eAAe,8BACpD,sBAAsB;EAC9B,IAAI,qBAAqB,OACvB,aAAa,MACb;aAAkB,SAAS,KAAK;MAC/B,iBAAiB,OAAO,OAAO;aAAiB,SAAS;;;iBA8B9C,oBAAoB,iBAAiB;UAIpC;EACf,SAAS,OAAO;EAChB,IAAI,sBAAsB;EAC1B,IAAI;;iBA0BU,2BAA2B"}
@@ -1,2 +1,2 @@
1
- import { a as IndexTypeRegistry, i as IndexTypeRegistration, n as IndexTypeEntry, o as createIndexTypeRegistry, r as IndexTypeMap, s as defineIndexTypes, t as IndexTypeBuilder } from "./index-types-Czsyu7Iw.mjs";
1
+ import { a as IndexTypeRegistry, i as IndexTypeRegistration, n as IndexTypeEntry, o as createIndexTypeRegistry, r as IndexTypeMap, s as defineIndexTypes, t as IndexTypeBuilder } from "./index-types-DPVhsW0v.mjs";
2
2
  export { type IndexTypeBuilder, type IndexTypeEntry, type IndexTypeMap, type IndexTypeRegistration, type IndexTypeRegistry, createIndexTypeRegistry, defineIndexTypes };
@@ -1,3 +1,4 @@
1
+ import { t as contractError } from "./contract-errors-CPZcBw8G.mjs";
1
2
  //#region src/index-types.ts
2
3
  var IndexTypeBuilderImpl = class IndexTypeBuilderImpl {
3
4
  entries;
@@ -7,7 +8,7 @@ var IndexTypeBuilderImpl = class IndexTypeBuilderImpl {
7
8
  this.IndexTypes = {};
8
9
  }
9
10
  add(typeLiteral, entry) {
10
- if (this.entries.some((e) => e.type === typeLiteral)) throw new Error(`Index type "${typeLiteral}" is already declared in this builder`);
11
+ if (this.entries.some((e) => e.type === typeLiteral)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Index type "${typeLiteral}" is already declared in this builder`, { meta: { indexType: typeLiteral } });
11
12
  return new IndexTypeBuilderImpl([...this.entries, {
12
13
  type: typeLiteral,
13
14
  options: entry.options
@@ -20,7 +21,7 @@ function defineIndexTypes() {
20
21
  var IndexTypeRegistryImpl = class {
21
22
  entries = /* @__PURE__ */ new Map();
22
23
  register(entry) {
23
- if (this.entries.has(entry.type)) throw new Error(`Index type "${entry.type}" is already registered`);
24
+ if (this.entries.has(entry.type)) throw contractError("CONTRACT.PACK_CONTRIBUTION_INVALID", `Index type "${entry.type}" is already registered`, { meta: { indexType: entry.type } });
24
25
  this.entries.set(entry.type, entry);
25
26
  }
26
27
  get(typeLiteral) {
@@ -1 +1 @@
1
- {"version":3,"file":"index-types.mjs","names":[],"sources":["../src/index-types.ts"],"sourcesContent":["import type { Type } from 'arktype';\n\nexport interface IndexTypeEntry<TOptions = unknown> {\n readonly type: string;\n readonly options: Type<TOptions>;\n}\n\nexport type IndexTypeMap = { readonly [K in string]: { readonly options: unknown } };\n\nexport interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {\n readonly IndexTypes: TMap;\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n}\n\nexport interface IndexTypeBuilder<TMap extends IndexTypeMap = Record<never, never>>\n extends IndexTypeRegistration<TMap> {\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>>;\n}\n\nclass IndexTypeBuilderImpl<TMap extends IndexTypeMap> implements IndexTypeBuilder<TMap> {\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n readonly IndexTypes: TMap;\n\n constructor(entries: ReadonlyArray<IndexTypeEntry>) {\n this.entries = entries;\n this.IndexTypes = {} as TMap;\n }\n\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>> {\n if (this.entries.some((e) => e.type === typeLiteral)) {\n throw new Error(`Index type \"${typeLiteral}\" is already declared in this builder`);\n }\n return new IndexTypeBuilderImpl<TMap & Record<TLit, { readonly options: TOpts }>>([\n ...this.entries,\n { type: typeLiteral, options: entry.options as Type<unknown> },\n ]);\n }\n}\n\nexport function defineIndexTypes(): IndexTypeBuilder<Record<never, never>> {\n return new IndexTypeBuilderImpl([]);\n}\n\nexport interface IndexTypeRegistry {\n register(entry: IndexTypeEntry): void;\n get(typeLiteral: string): IndexTypeEntry | undefined;\n has(typeLiteral: string): boolean;\n}\n\nclass IndexTypeRegistryImpl implements IndexTypeRegistry {\n private readonly entries = new Map<string, IndexTypeEntry>();\n\n register(entry: IndexTypeEntry): void {\n if (this.entries.has(entry.type)) {\n throw new Error(`Index type \"${entry.type}\" is already registered`);\n }\n this.entries.set(entry.type, entry);\n }\n\n get(typeLiteral: string): IndexTypeEntry | undefined {\n return this.entries.get(typeLiteral);\n }\n\n has(typeLiteral: string): boolean {\n return this.entries.has(typeLiteral);\n }\n}\n\nexport function createIndexTypeRegistry(): IndexTypeRegistry {\n return new IndexTypeRegistryImpl();\n}\n"],"mappings":";AAsBA,IAAM,uBAAN,MAAM,qBAAkF;CACtF;CACA;CAEA,YAAY,SAAwC;EAClD,KAAK,UAAU;EACf,KAAK,aAAa,CAAC;CACrB;CAEA,IACE,aACA,OACoE;EACpE,IAAI,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,WAAW,GACjD,MAAM,IAAI,MAAM,eAAe,YAAY,sCAAsC;EAEnF,OAAO,IAAI,qBAAuE,CAChF,GAAG,KAAK,SACR;GAAE,MAAM;GAAa,SAAS,MAAM;EAAyB,CAC/D,CAAC;CACH;AACF;AAEA,SAAgB,mBAA2D;CACzE,OAAO,IAAI,qBAAqB,CAAC,CAAC;AACpC;AAQA,IAAM,wBAAN,MAAyD;CACvD,0BAA2B,IAAI,IAA4B;CAE3D,SAAS,OAA6B;EACpC,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,GAC7B,MAAM,IAAI,MAAM,eAAe,MAAM,KAAK,wBAAwB;EAEpE,KAAK,QAAQ,IAAI,MAAM,MAAM,KAAK;CACpC;CAEA,IAAI,aAAiD;EACnD,OAAO,KAAK,QAAQ,IAAI,WAAW;CACrC;CAEA,IAAI,aAA8B;EAChC,OAAO,KAAK,QAAQ,IAAI,WAAW;CACrC;AACF;AAEA,SAAgB,0BAA6C;CAC3D,OAAO,IAAI,sBAAsB;AACnC"}
1
+ {"version":3,"file":"index-types.mjs","names":[],"sources":["../src/index-types.ts"],"sourcesContent":["import type { Type } from 'arktype';\nimport { contractError } from './contract-errors';\n\nexport interface IndexTypeEntry<TOptions = unknown> {\n readonly type: string;\n readonly options: Type<TOptions>;\n}\n\nexport type IndexTypeMap = { readonly [K in string]: { readonly options: unknown } };\n\nexport interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {\n readonly IndexTypes: TMap;\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n}\n\nexport interface IndexTypeBuilder<TMap extends IndexTypeMap = Record<never, never>>\n extends IndexTypeRegistration<TMap> {\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>>;\n}\n\nclass IndexTypeBuilderImpl<TMap extends IndexTypeMap> implements IndexTypeBuilder<TMap> {\n readonly entries: ReadonlyArray<IndexTypeEntry>;\n readonly IndexTypes: TMap;\n\n constructor(entries: ReadonlyArray<IndexTypeEntry>) {\n this.entries = entries;\n this.IndexTypes = {} as TMap;\n }\n\n add<TLit extends string, TOpts>(\n typeLiteral: TLit,\n entry: { readonly options: Type<TOpts> },\n ): IndexTypeBuilder<TMap & Record<TLit, { readonly options: TOpts }>> {\n if (this.entries.some((e) => e.type === typeLiteral)) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `Index type \"${typeLiteral}\" is already declared in this builder`,\n { meta: { indexType: typeLiteral } },\n );\n }\n return new IndexTypeBuilderImpl<TMap & Record<TLit, { readonly options: TOpts }>>([\n ...this.entries,\n { type: typeLiteral, options: entry.options as Type<unknown> },\n ]);\n }\n}\n\nexport function defineIndexTypes(): IndexTypeBuilder<Record<never, never>> {\n return new IndexTypeBuilderImpl([]);\n}\n\nexport interface IndexTypeRegistry {\n register(entry: IndexTypeEntry): void;\n get(typeLiteral: string): IndexTypeEntry | undefined;\n has(typeLiteral: string): boolean;\n}\n\nclass IndexTypeRegistryImpl implements IndexTypeRegistry {\n private readonly entries = new Map<string, IndexTypeEntry>();\n\n register(entry: IndexTypeEntry): void {\n if (this.entries.has(entry.type)) {\n throw contractError(\n 'CONTRACT.PACK_CONTRIBUTION_INVALID',\n `Index type \"${entry.type}\" is already registered`,\n { meta: { indexType: entry.type } },\n );\n }\n this.entries.set(entry.type, entry);\n }\n\n get(typeLiteral: string): IndexTypeEntry | undefined {\n return this.entries.get(typeLiteral);\n }\n\n has(typeLiteral: string): boolean {\n return this.entries.has(typeLiteral);\n }\n}\n\nexport function createIndexTypeRegistry(): IndexTypeRegistry {\n return new IndexTypeRegistryImpl();\n}\n"],"mappings":";;AAuBA,IAAM,uBAAN,MAAM,qBAAkF;CACtF;CACA;CAEA,YAAY,SAAwC;EAClD,KAAK,UAAU;EACf,KAAK,aAAa,CAAC;CACrB;CAEA,IACE,aACA,OACoE;EACpE,IAAI,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,WAAW,GACjD,MAAM,cACJ,sCACA,eAAe,YAAY,wCAC3B,EAAE,MAAM,EAAE,WAAW,YAAY,EAAE,CACrC;EAEF,OAAO,IAAI,qBAAuE,CAChF,GAAG,KAAK,SACR;GAAE,MAAM;GAAa,SAAS,MAAM;EAAyB,CAC/D,CAAC;CACH;AACF;AAEA,SAAgB,mBAA2D;CACzE,OAAO,IAAI,qBAAqB,CAAC,CAAC;AACpC;AAQA,IAAM,wBAAN,MAAyD;CACvD,0BAA2B,IAAI,IAA4B;CAE3D,SAAS,OAA6B;EACpC,IAAI,KAAK,QAAQ,IAAI,MAAM,IAAI,GAC7B,MAAM,cACJ,sCACA,eAAe,MAAM,KAAK,0BAC1B,EAAE,MAAM,EAAE,WAAW,MAAM,KAAK,EAAE,CACpC;EAEF,KAAK,QAAQ,IAAI,MAAM,MAAM,KAAK;CACpC;CAEA,IAAI,aAAiD;EACnD,OAAO,KAAK,QAAQ,IAAI,WAAW;CACrC;CAEA,IAAI,aAA8B;EAChC,OAAO,KAAK,QAAQ,IAAI,WAAW;CACrC;AACF;AAEA,SAAgB,0BAA6C;CAC3D,OAAO,IAAI,sBAAsB;AACnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"pack-types.d.mts","names":[],"sources":["../src/pack-types.ts"],"mappings":";;AAGA;;UAAiB,mBAAA;EAAA,SACN,MAAA;EAAA,SACA,QAAA;EAAA,SACA,QAAA;EAAA,SACA,UAAA;AAAA"}
1
+ {"version":3,"file":"pack-types.d.mts","names":[],"sources":["../src/pack-types.ts"],"mappings":";;;;UAGiB;WACN;WACA;WACA;WACA"}
@@ -1,5 +1,4 @@
1
- import { r as ReferentialAction } from "./foreign-key-DM1UTydh.mjs";
2
-
1
+ import { r as ReferentialAction } from "./foreign-key-CWCEM2IT.mjs";
3
2
  //#region src/referential-action-sql.d.ts
4
3
  /**
5
4
  * Maps each `ReferentialAction` value to the SQL keyword used in ON DELETE /
@@ -1 +1 @@
1
- {"version":3,"file":"referential-action-sql.d.mts","names":[],"sources":["../src/referential-action-sql.ts"],"mappings":";;;;;AAOA;;;cAAa,sBAAA,EAAwB,MAAM,CAAC,iBAAA"}
1
+ {"version":3,"file":"referential-action-sql.d.mts","names":[],"sources":["../src/referential-action-sql.ts"],"mappings":";;;;;;;cAOa,wBAAwB,OAAO"}
@@ -1,6 +1,5 @@
1
- import { t as StorageTable } from "./storage-table-Bj1ZN1P7.mjs";
2
- import { s as SqlStorage } from "./sql-storage-Dt5ipcRl.mjs";
3
-
1
+ import { t as StorageTable } from "./storage-table-mNGckl3_.mjs";
2
+ import { s as SqlStorage } from "./sql-storage-BIErcfFA.mjs";
4
3
  //#region src/resolve-storage-table.d.ts
5
4
  interface ResolvedStorageTable {
6
5
  readonly namespaceId: string;
@@ -1 +1 @@
1
- {"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":";;;;UAIiB,oBAAA;EAAA,SACN,WAAA;EAAA,SACA,KAAA,EAAO,YAAY;AAAA;;;;;;;AAAA;AAY9B;;iBAAgB,mBAAA,CACd,OAAA,EAAS,UAAA,EACT,SAAA,UACA,WAAA,YACC,oBAAoB"}
1
+ {"version":3,"file":"resolve-storage-table.d.mts","names":[],"sources":["../src/resolve-storage-table.ts"],"mappings":";;;UAKiB;WACN;WACA,OAAO;;;;;;;;;;;iBAYF,oBACd,SAAS,YACT,mBACA,uBACC"}
@@ -1,3 +1,4 @@
1
+ import { t as contractError } from "./contract-errors-CPZcBw8G.mjs";
1
2
  import { entityAt } from "@prisma-next/framework-components/ir";
2
3
  //#region src/resolve-storage-table.ts
3
4
  /**
@@ -33,10 +34,10 @@ function resolveStorageTable(storage, tableName, namespaceId) {
33
34
  table
34
35
  });
35
36
  }
36
- if (matches.length > 1) {
37
- const candidates = matches.map((match) => match.namespaceId).sort().join(", ");
38
- throw new Error(`Storage table "${tableName}" is ambiguous across namespaces [${candidates}]; qualify it with a namespace coordinate.`);
39
- }
37
+ if (matches.length > 1) throw contractError("CONTRACT.TABLE_AMBIGUOUS", `Storage table "${tableName}" is ambiguous across namespaces [${matches.map((match) => match.namespaceId).sort().join(", ")}]; qualify it with a namespace coordinate.`, { meta: {
38
+ tableName,
39
+ candidates: matches.map((match) => match.namespaceId).sort()
40
+ } });
40
41
  return matches[0];
41
42
  }
42
43
  //#endregion