@prisma-next/sql-contract 0.5.0-dev.9 → 0.6.0-dev.1

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 (42) hide show
  1. package/dist/factories.d.mts +1 -1
  2. package/dist/factories.d.mts.map +1 -1
  3. package/dist/factories.mjs +2 -3
  4. package/dist/factories.mjs.map +1 -1
  5. package/dist/index-type-validation.d.mts +9 -0
  6. package/dist/index-type-validation.d.mts.map +1 -0
  7. package/dist/index-type-validation.mjs +18 -0
  8. package/dist/index-type-validation.mjs.map +1 -0
  9. package/dist/index-types-DqVqGHwg.d.mts +31 -0
  10. package/dist/index-types-DqVqGHwg.d.mts.map +1 -0
  11. package/dist/index-types.d.mts +2 -0
  12. package/dist/index-types.mjs +39 -0
  13. package/dist/index-types.mjs.map +1 -0
  14. package/dist/pack-types.d.mts.map +1 -1
  15. package/dist/pack-types.mjs +1 -1
  16. package/dist/{types-DRR5stkj.mjs → types-hgzy8ME1.mjs} +4 -4
  17. package/dist/types-hgzy8ME1.mjs.map +1 -0
  18. package/dist/{types-DdNz1nUf.d.mts → types-njsiV-Ck.d.mts} +38 -31
  19. package/dist/types-njsiV-Ck.d.mts.map +1 -0
  20. package/dist/types.d.mts +2 -2
  21. package/dist/types.mjs +2 -3
  22. package/dist/validate.d.mts +1 -1
  23. package/dist/validate.d.mts.map +1 -1
  24. package/dist/validate.mjs +2 -3
  25. package/dist/validate.mjs.map +1 -1
  26. package/dist/{validators-BjZ6lOS1.mjs → validators-Dm5X-Hvg.mjs} +50 -37
  27. package/dist/validators-Dm5X-Hvg.mjs.map +1 -0
  28. package/dist/validators.d.mts +14 -12
  29. package/dist/validators.d.mts.map +1 -1
  30. package/dist/validators.mjs +2 -3
  31. package/package.json +10 -7
  32. package/src/exports/index-type-validation.ts +1 -0
  33. package/src/exports/index-types.ts +9 -0
  34. package/src/exports/types.ts +2 -3
  35. package/src/index-type-validation.ts +37 -0
  36. package/src/index-types.ts +77 -0
  37. package/src/index.ts +2 -0
  38. package/src/types.ts +28 -28
  39. package/src/validators.ts +50 -4
  40. package/dist/types-DRR5stkj.mjs.map +0 -1
  41. package/dist/types-DdNz1nUf.d.mts.map +0 -1
  42. package/dist/validators-BjZ6lOS1.mjs.map +0 -1
@@ -1,4 +1,4 @@
1
- import { A as StorageTable, E as SqlModelStorage, P as UniqueConstraint, T as SqlModelFieldStorage, _ as PrimaryKey, f as ForeignKey, h as Index, k as StorageColumn, p as ForeignKeyOptions } from "./types-DdNz1nUf.mjs";
1
+ import { N as UniqueConstraint, O as StorageColumn, T as SqlModelStorage, f as ForeignKey, g as PrimaryKey, h as Index, k as StorageTable, p as ForeignKeyOptions, w as SqlModelFieldStorage } from "./types-njsiV-Ck.mjs";
2
2
  import { ScalarFieldType } from "@prisma-next/contract/types";
3
3
 
4
4
  //#region src/factories.d.ts
@@ -1 +1 @@
1
- {"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"sourcesContent":[],"mappings":";;;;iBAegB,GAAA,2DAA4D;iBAQ5D,EAAA,iCAAmC;AARnC,iBAcA,MAAA,CAd4D,GAAA,OAAa,EAAA,SAAA,MAAA,EAAA,CAAA,EAclC,gBAdkC;AAQzE,iBAYA,KAAA,CAZmC,GAAU,OAAA,EAAA,SAAA,MAAA,EAAA,CAAA,EAYP,KAZO;AAM7C,iBAYA,EAAA,CAZuC,OAAA,EAAA,SAAgB,MAAA,EAAA,EAAA,QAAA,EAAA,MAAA,EAAA,UAAA,EAAA,SAAA,MAAA,EAAA,EAAA,IAiCvE,CAjCuE,EAgB9D,iBAhB8D,GAAA;EAMvD,UAAK,CAAA,EAAA,OAAiC;EAMtC,KAAE,CAAA,EAAA,OAAA;AAqBlB,CAAA,CAAA,EAhBG,UAgBkB;AACK,iBADV,KAAA,CACU,OAAA,EAAf,MAAe,CAAA,MAAA,EAAA,aAAA,CAAA,EAAA,IAKP,CALO,EAAA;EAAf,EAAA,CAAA,EAEF,UAFE;EAEF,O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;EACT,MAAA,EAAQ,MAAA;IAAA,SAA0B,QAAA;IAAA,SAA4B,IAAA,EAAM,eAAA;EAAA;EACpE,SAAA,EAAW,MAAA;AAAA"}
@@ -1,5 +1,4 @@
1
- import { r as applyFkDefaults } from "./types-DRR5stkj.mjs";
2
-
1
+ import { r as applyFkDefaults } from "./types-hgzy8ME1.mjs";
3
2
  //#region src/factories.ts
4
3
  function col(nativeType, codecId, nullable = false) {
5
4
  return {
@@ -58,7 +57,7 @@ function model(tableName, fields, relations = {}) {
58
57
  relations
59
58
  };
60
59
  }
61
-
62
60
  //#endregion
63
61
  export { col, fk, index, model, pk, table, unique };
62
+
64
63
  //# sourceMappingURL=factories.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import type { ScalarFieldType } from '@prisma-next/contract/types';\nimport type {\n ForeignKey,\n ForeignKeyOptions,\n ForeignKeyReferences,\n Index,\n PrimaryKey,\n SqlModelFieldStorage,\n SqlModelStorage,\n StorageColumn,\n StorageTable,\n UniqueConstraint,\n} from './types';\nimport { applyFkDefaults } from './types';\n\nexport function col(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return {\n nativeType,\n codecId,\n nullable,\n };\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return {\n columns,\n };\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return {\n columns,\n };\n}\n\nexport function index(...columns: readonly string[]): Index {\n return {\n columns,\n };\n}\n\nexport function fk(\n columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean },\n): ForeignKey {\n const references: ForeignKeyReferences = {\n table: refTable,\n columns: refColumns,\n };\n\n return {\n columns,\n references,\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n ...applyFkDefaults({ constraint: opts?.constraint, index: opts?.index }),\n };\n}\n\nexport function table(\n columns: Record<string, StorageColumn>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return {\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): {\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, 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,IAAI,YAAoB,SAAiB,WAAW,OAAsB;AACxF,QAAO;EACL;EACA;EACA;EACD;;AAGH,SAAgB,GAAG,GAAG,SAAwC;AAC5D,QAAO,EACL,SACD;;AAGH,SAAgB,OAAO,GAAG,SAA8C;AACtE,QAAO,EACL,SACD;;AAGH,SAAgB,MAAM,GAAG,SAAmC;AAC1D,QAAO,EACL,SACD;;AAGH,SAAgB,GACd,SACA,UACA,YACA,MACY;AAMZ,QAAO;EACL;EACA,YAPuC;GACvC,OAAO;GACP,SAAS;GACV;EAKC,GAAI,MAAM,SAAS,UAAa,EAAE,MAAM,KAAK,MAAM;EACnD,GAAI,MAAM,aAAa,UAAa,EAAE,UAAU,KAAK,UAAU;EAC/D,GAAI,MAAM,aAAa,UAAa,EAAE,UAAU,KAAK,UAAU;EAC/D,GAAG,gBAAgB;GAAE,YAAY,MAAM;GAAY,OAAO,MAAM;GAAO,CAAC;EACzE;;AAGH,SAAgB,MACd,SACA,MAMc;AACd,QAAO;EACL;EACA,GAAI,MAAM,OAAO,UAAa,EAAE,YAAY,KAAK,IAAI;EACrD,SAAS,MAAM,WAAW,EAAE;EAC5B,SAAS,MAAM,WAAW,EAAE;EAC5B,aAAa,MAAM,OAAO,EAAE;EAC7B;;AAGH,SAAgB,MACd,WACA,QACA,YAAqC,EAAE,EAKvC;AAWA,QAAO;EACL,SAX+B;GAAE,OAAO;GAAW;GAAQ;EAY3D,QAXmB,OAAO,YAC1B,OAAO,QAAQ,OAAO,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA;GACE,UAAU,MAAM,YAAY;GAC5B,MAAM;IAAE,MAAM;IAAmB,SAAS,MAAM,WAAW;IAAkB;GAC9E,CACF,CAAC,CACH;EAIC;EACD"}
1
+ {"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import type { ScalarFieldType } from '@prisma-next/contract/types';\nimport type {\n ForeignKey,\n ForeignKeyOptions,\n ForeignKeyReferences,\n Index,\n PrimaryKey,\n SqlModelFieldStorage,\n SqlModelStorage,\n StorageColumn,\n StorageTable,\n UniqueConstraint,\n} from './types';\nimport { applyFkDefaults } from './types';\n\nexport function col(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return {\n nativeType,\n codecId,\n nullable,\n };\n}\n\nexport function pk(...columns: readonly string[]): PrimaryKey {\n return {\n columns,\n };\n}\n\nexport function unique(...columns: readonly string[]): UniqueConstraint {\n return {\n columns,\n };\n}\n\nexport function index(...columns: readonly string[]): Index {\n return {\n columns,\n };\n}\n\nexport function fk(\n columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean },\n): ForeignKey {\n const references: ForeignKeyReferences = {\n table: refTable,\n columns: refColumns,\n };\n\n return {\n columns,\n references,\n ...(opts?.name !== undefined && { name: opts.name }),\n ...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),\n ...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),\n ...applyFkDefaults({ constraint: opts?.constraint, index: opts?.index }),\n };\n}\n\nexport function table(\n columns: Record<string, StorageColumn>,\n opts?: {\n pk?: PrimaryKey;\n uniques?: readonly UniqueConstraint[];\n indexes?: readonly Index[];\n fks?: readonly ForeignKey[];\n },\n): StorageTable {\n return {\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): {\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, 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,IAAI,YAAoB,SAAiB,WAAW,OAAsB;CACxF,OAAO;EACL;EACA;EACA;EACD;;AAGH,SAAgB,GAAG,GAAG,SAAwC;CAC5D,OAAO,EACL,SACD;;AAGH,SAAgB,OAAO,GAAG,SAA8C;CACtE,OAAO,EACL,SACD;;AAGH,SAAgB,MAAM,GAAG,SAAmC;CAC1D,OAAO,EACL,SACD;;AAGH,SAAgB,GACd,SACA,UACA,YACA,MACY;CAMZ,OAAO;EACL;EACA,YAAA;GANA,OAAO;GACP,SAAS;GAKC;EACV,GAAI,MAAM,SAAS,KAAA,KAAa,EAAE,MAAM,KAAK,MAAM;EACnD,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,UAAU;EAC/D,GAAI,MAAM,aAAa,KAAA,KAAa,EAAE,UAAU,KAAK,UAAU;EAC/D,GAAG,gBAAgB;GAAE,YAAY,MAAM;GAAY,OAAO,MAAM;GAAO,CAAC;EACzE;;AAGH,SAAgB,MACd,SACA,MAMc;CACd,OAAO;EACL;EACA,GAAI,MAAM,OAAO,KAAA,KAAa,EAAE,YAAY,KAAK,IAAI;EACrD,SAAS,MAAM,WAAW,EAAE;EAC5B,SAAS,MAAM,WAAW,EAAE;EAC5B,aAAa,MAAM,OAAO,EAAE;EAC7B;;AAGH,SAAgB,MACd,WACA,QACA,YAAqC,EAAE,EAKvC;CAWA,OAAO;EACL,SAAA;GAXiC,OAAO;GAAW;GAW5C;EACP,QAXmB,OAAO,YAC1B,OAAO,QAAQ,OAAO,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA;GACE,UAAU,MAAM,YAAY;GAC5B,MAAM;IAAE,MAAM;IAAmB,SAAS,MAAM,WAAW;IAAkB;GAC9E,CACF,CAAC,CAIkB;EACpB;EACD"}
@@ -0,0 +1,9 @@
1
+ import { D as SqlStorage } from "./types-njsiV-Ck.mjs";
2
+ import { a as IndexTypeRegistry } from "./index-types-DqVqGHwg.mjs";
3
+ import { Contract } from "@prisma-next/contract/types";
4
+
5
+ //#region src/index-type-validation.d.ts
6
+ declare function validateIndexTypes(contract: Contract<SqlStorage>, indexTypeRegistry: IndexTypeRegistry): void;
7
+ //#endregion
8
+ export { validateIndexTypes };
9
+ //# sourceMappingURL=index-type-validation.d.mts.map
@@ -0,0 +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"}
@@ -0,0 +1,18 @@
1
+ import { ContractValidationError } from "@prisma-next/contract/validate-contract";
2
+ import { type } from "arktype";
3
+ //#region src/index-type-validation.ts
4
+ function validateIndexTypes(contract, indexTypeRegistry) {
5
+ for (const [tableName, table] of Object.entries(contract.storage.tables)) for (const index of table.indexes) {
6
+ if (index.type === void 0 && index.options !== void 0) throw new ContractValidationError(`Table "${tableName}" index on columns [${index.columns.join(", ")}] has options without a type`, "storage");
7
+ if (index.type === void 0) continue;
8
+ const entry = indexTypeRegistry.get(index.type);
9
+ if (entry === void 0) throw new ContractValidationError(`Table "${tableName}" index on columns [${index.columns.join(", ")}] uses unregistered index type "${index.type}"`, "storage");
10
+ const optionsValue = index.options ?? {};
11
+ const result = entry.options(optionsValue);
12
+ if (result instanceof type.errors) throw new ContractValidationError(`Table "${tableName}" index on columns [${index.columns.join(", ")}] has invalid options for type "${index.type}": ${result.summary}`, "storage");
13
+ }
14
+ }
15
+ //#endregion
16
+ export { validateIndexTypes };
17
+
18
+ //# sourceMappingURL=index-type-validation.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { ContractValidationError } from '@prisma-next/contract/validate-contract';\nimport { type } from 'arktype';\nimport type { IndexTypeRegistry } from './index-types';\nimport type { SqlStorage } from './types';\n\nexport function validateIndexTypes(\n contract: Contract<SqlStorage>,\n indexTypeRegistry: IndexTypeRegistry,\n): void {\n for (const [tableName, table] of Object.entries(contract.storage.tables)) {\n for (const index of table.indexes) {\n if (index.type === undefined && index.options !== undefined) {\n throw new ContractValidationError(\n `Table \"${tableName}\" index on columns [${index.columns.join(', ')}] has options without a type`,\n 'storage',\n );\n }\n if (index.type === undefined) continue;\n const entry = indexTypeRegistry.get(index.type);\n if (entry === undefined) {\n throw new ContractValidationError(\n `Table \"${tableName}\" index on columns [${index.columns.join(', ')}] uses unregistered index type \"${index.type}\"`,\n 'storage',\n );\n }\n const optionsValue = index.options ?? {};\n const result = entry.options(optionsValue);\n if (result instanceof type.errors) {\n throw new ContractValidationError(\n `Table \"${tableName}\" index on columns [${index.columns.join(', ')}] has invalid options for type \"${index.type}\": ${result.summary}`,\n 'storage',\n );\n }\n }\n }\n}\n"],"mappings":";;;AAMA,SAAgB,mBACd,UACA,mBACM;CACN,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,SAAS,QAAQ,OAAO,EACtE,KAAK,MAAM,SAAS,MAAM,SAAS;EACjC,IAAI,MAAM,SAAS,KAAA,KAAa,MAAM,YAAY,KAAA,GAChD,MAAM,IAAI,wBACR,UAAU,UAAU,sBAAsB,MAAM,QAAQ,KAAK,KAAK,CAAC,+BACnE,UACD;EAEH,IAAI,MAAM,SAAS,KAAA,GAAW;EAC9B,MAAM,QAAQ,kBAAkB,IAAI,MAAM,KAAK;EAC/C,IAAI,UAAU,KAAA,GACZ,MAAM,IAAI,wBACR,UAAU,UAAU,sBAAsB,MAAM,QAAQ,KAAK,KAAK,CAAC,kCAAkC,MAAM,KAAK,IAChH,UACD;EAEH,MAAM,eAAe,MAAM,WAAW,EAAE;EACxC,MAAM,SAAS,MAAM,QAAQ,aAAa;EAC1C,IAAI,kBAAkB,KAAK,QACzB,MAAM,IAAI,wBACR,UAAU,UAAU,sBAAsB,MAAM,QAAQ,KAAK,KAAK,CAAC,kCAAkC,MAAM,KAAK,KAAK,OAAO,WAC5H,UACD"}
@@ -0,0 +1,31 @@
1
+ import { Type } from "arktype";
2
+
3
+ //#region src/index-types.d.ts
4
+ interface IndexTypeEntry<TOptions = unknown> {
5
+ readonly type: string;
6
+ readonly options: Type<TOptions>;
7
+ }
8
+ type IndexTypeMap = { readonly [K in string]: {
9
+ readonly options: unknown;
10
+ } };
11
+ interface IndexTypeRegistration<TMap extends IndexTypeMap = Record<never, never>> {
12
+ readonly IndexTypes: TMap;
13
+ readonly entries: ReadonlyArray<IndexTypeEntry>;
14
+ }
15
+ interface IndexTypeBuilder<TMap extends IndexTypeMap = Record<never, never>> extends IndexTypeRegistration<TMap> {
16
+ add<TLit extends string, TOpts>(typeLiteral: TLit, entry: {
17
+ readonly options: Type<TOpts>;
18
+ }): IndexTypeBuilder<TMap & Record<TLit, {
19
+ readonly options: TOpts;
20
+ }>>;
21
+ }
22
+ declare function defineIndexTypes(): IndexTypeBuilder<Record<never, never>>;
23
+ interface IndexTypeRegistry {
24
+ register(entry: IndexTypeEntry): void;
25
+ get(typeLiteral: string): IndexTypeEntry | undefined;
26
+ has(typeLiteral: string): boolean;
27
+ }
28
+ declare function createIndexTypeRegistry(): IndexTypeRegistry;
29
+ //#endregion
30
+ 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-DqVqGHwg.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-types-DqVqGHwg.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;;UAEiB,cAAA;EAAA,SACN,IAAA;EAAA,SACA,OAAA,EAAS,IAAA,CAAK,QAAA;AAAA;AAAA,KAGb,YAAA;EAAA,SAAoD,OAAA;AAAA;AAAA,UAE/C,qBAAA,cAAmC,YAAA,GAAe,MAAA;EAAA,SACxD,UAAA,EAAY,IAAA;EAAA,SACZ,OAAA,EAAS,aAAA,CAAc,cAAA;AAAA;AAAA,UAGjB,gBAAA,cAA8B,YAAA,GAAe,MAAA,wBACpD,qBAAA,CAAsB,IAAA;EAC9B,GAAA,6BACE,WAAA,EAAa,IAAA,EACb,KAAA;IAAA,SAAkB,OAAA,EAAS,IAAA,CAAK,KAAA;EAAA,IAC/B,gBAAA,CAAiB,IAAA,GAAO,MAAA,CAAO,IAAA;IAAA,SAAiB,OAAA,EAAS,KAAA;EAAA;AAAA;AAAA,iBA0B9C,gBAAA,CAAA,GAAoB,gBAAA,CAAiB,MAAA;AAAA,UAIpC,iBAAA;EACf,QAAA,CAAS,KAAA,EAAO,cAAA;EAChB,GAAA,CAAI,WAAA,WAAsB,cAAA;EAC1B,GAAA,CAAI,WAAA;AAAA;AAAA,iBAsBU,uBAAA,CAAA,GAA2B,iBAAA"}
@@ -0,0 +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-DqVqGHwg.mjs";
2
+ export { type IndexTypeBuilder, type IndexTypeEntry, type IndexTypeMap, type IndexTypeRegistration, type IndexTypeRegistry, createIndexTypeRegistry, defineIndexTypes };
@@ -0,0 +1,39 @@
1
+ //#region src/index-types.ts
2
+ var IndexTypeBuilderImpl = class IndexTypeBuilderImpl {
3
+ entries;
4
+ IndexTypes;
5
+ constructor(entries) {
6
+ this.entries = entries;
7
+ this.IndexTypes = {};
8
+ }
9
+ 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
+ return new IndexTypeBuilderImpl([...this.entries, {
12
+ type: typeLiteral,
13
+ options: entry.options
14
+ }]);
15
+ }
16
+ };
17
+ function defineIndexTypes() {
18
+ return new IndexTypeBuilderImpl([]);
19
+ }
20
+ var IndexTypeRegistryImpl = class {
21
+ entries = /* @__PURE__ */ new Map();
22
+ register(entry) {
23
+ if (this.entries.has(entry.type)) throw new Error(`Index type "${entry.type}" is already registered`);
24
+ this.entries.set(entry.type, entry);
25
+ }
26
+ get(typeLiteral) {
27
+ return this.entries.get(typeLiteral);
28
+ }
29
+ has(typeLiteral) {
30
+ return this.entries.has(typeLiteral);
31
+ }
32
+ };
33
+ function createIndexTypeRegistry() {
34
+ return new IndexTypeRegistryImpl();
35
+ }
36
+ //#endregion
37
+ export { createIndexTypeRegistry, defineIndexTypes };
38
+
39
+ //# sourceMappingURL=index-types.mjs.map
@@ -0,0 +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,EAAE;;CAGtB,IACE,aACA,OACoE;EACpE,IAAI,KAAK,QAAQ,MAAM,MAAM,EAAE,SAAS,YAAY,EAClD,MAAM,IAAI,MAAM,eAAe,YAAY,uCAAuC;EAEpF,OAAO,IAAI,qBAAuE,CAChF,GAAG,KAAK,SACR;GAAE,MAAM;GAAa,SAAS,MAAM;GAA0B,CAC/D,CAAC;;;AAIN,SAAgB,mBAA2D;CACzE,OAAO,IAAI,qBAAqB,EAAE,CAAC;;AASrC,IAAM,wBAAN,MAAyD;CACvD,0BAA2B,IAAI,KAA6B;CAE5D,SAAS,OAA6B;EACpC,IAAI,KAAK,QAAQ,IAAI,MAAM,KAAK,EAC9B,MAAM,IAAI,MAAM,eAAe,MAAM,KAAK,yBAAyB;EAErE,KAAK,QAAQ,IAAI,MAAM,MAAM,MAAM;;CAGrC,IAAI,aAAiD;EACnD,OAAO,KAAK,QAAQ,IAAI,YAAY;;CAGtC,IAAI,aAA8B;EAChC,OAAO,KAAK,QAAQ,IAAI,YAAY;;;AAIxC,SAAgB,0BAA6C;CAC3D,OAAO,IAAI,uBAAuB"}
@@ -1 +1 @@
1
- {"version":3,"file":"pack-types.d.mts","names":[],"sources":["../src/pack-types.ts"],"sourcesContent":[],"mappings":";;AAGA;;UAAiB,mBAAA"}
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 +1 @@
1
- export { };
1
+ export {};
@@ -3,11 +3,11 @@ const DEFAULT_FK_CONSTRAINT = true;
3
3
  const DEFAULT_FK_INDEX = true;
4
4
  function applyFkDefaults(fk, overrideDefaults) {
5
5
  return {
6
- constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,
7
- index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX
6
+ constraint: fk.constraint ?? overrideDefaults?.constraint ?? true,
7
+ index: fk.index ?? overrideDefaults?.index ?? true
8
8
  };
9
9
  }
10
-
11
10
  //#endregion
12
11
  export { DEFAULT_FK_INDEX as n, applyFkDefaults as r, DEFAULT_FK_CONSTRAINT as t };
13
- //# sourceMappingURL=types-DRR5stkj.mjs.map
12
+
13
+ //# sourceMappingURL=types-hgzy8ME1.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-hgzy8ME1.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { ColumnDefault, StorageBase } from '@prisma-next/contract/types';\nimport type { CodecTrait } from '@prisma-next/framework-components/codec';\n\n/**\n * A column definition in storage.\n *\n * `typeParams` is optional because most columns use non-parameterized types.\n * Columns with parameterized types can either inline `typeParams` or reference\n * a named {@link StorageTypeInstance} via `typeRef`.\n */\nexport type StorageColumn = {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n /**\n * Opaque, codec-owned JS/type parameters.\n * The codec that owns `codecId` defines the shape and semantics.\n * Mutually exclusive with `typeRef`.\n */\n readonly typeParams?: Record<string, unknown>;\n /**\n * Reference to a named type instance in `storage.types`.\n * Mutually exclusive with `typeParams`.\n */\n readonly typeRef?: string;\n /**\n * Default value for the column.\n * Can be a literal value or database function.\n */\n readonly default?: ColumnDefault;\n};\n\nexport type PrimaryKey = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type UniqueConstraint = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type Index = {\n readonly columns: readonly string[];\n readonly name?: string;\n readonly type?: string;\n readonly options?: Record<string, unknown>;\n};\n\nexport type ForeignKeyReferences = {\n readonly table: string;\n readonly columns: readonly string[];\n};\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type ForeignKey = {\n readonly columns: readonly string[];\n readonly references: ForeignKeyReferences;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n};\n\nexport type StorageTable = {\n readonly columns: Record<string, StorageColumn>;\n readonly primaryKey?: PrimaryKey;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n};\n\n/**\n * A named, parameterized type instance.\n * These are registered in `storage.types` for reuse across columns\n * and to enable ergonomic schema surfaces like `schema.types.MyType`.\n *\n * Unlike {@link StorageColumn}, `typeParams` is required here because\n * `StorageTypeInstance` exists specifically to define reusable parameterized types.\n * A type instance without parameters would be redundant—columns can reference\n * the codec directly via `codecId`.\n */\nexport type StorageTypeInstance = {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n};\n\nexport type SqlStorage<THash extends string = string> = StorageBase<THash> & {\n readonly tables: Record<string, StorageTable>;\n /**\n * Named type instances for parameterized/custom types.\n * Columns can reference these via `typeRef`.\n */\n readonly types?: Record<string, StorageTypeInstance>;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n"],"mappings":";AAsHA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;CACzC,OAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAA;EAC/C,OAAO,GAAG,SAAS,kBAAkB,SAAA;EACtC"}
@@ -2,7 +2,6 @@ import { ColumnDefault, StorageBase } from "@prisma-next/contract/types";
2
2
  import { CodecTrait } from "@prisma-next/framework-components/codec";
3
3
 
4
4
  //#region src/types.d.ts
5
-
6
5
  /**
7
6
  * A column definition in storage.
8
7
  *
@@ -42,16 +41,8 @@ type UniqueConstraint = {
42
41
  type Index = {
43
42
  readonly columns: readonly string[];
44
43
  readonly name?: string;
45
- /**
46
- * Optional access method identifier.
47
- * Extension-specific methods are represented as strings and interpreted
48
- * by the owning extension package.
49
- */
50
- readonly using?: string;
51
- /**
52
- * Optional extension-owned index configuration payload.
53
- */
54
- readonly config?: Record<string, unknown>;
44
+ readonly type?: string;
45
+ readonly options?: Record<string, unknown>;
55
46
  };
56
47
  type ForeignKeyReferences = {
57
48
  readonly table: string;
@@ -68,10 +59,8 @@ type ForeignKey = {
68
59
  readonly references: ForeignKeyReferences;
69
60
  readonly name?: string;
70
61
  readonly onDelete?: ReferentialAction;
71
- readonly onUpdate?: ReferentialAction;
72
- /** Whether to emit FK constraint DDL (ALTER TABLE ADD CONSTRAINT … FOREIGN KEY). */
73
- readonly constraint: boolean;
74
- /** Whether to emit a backing index for the FK columns. */
62
+ readonly onUpdate?: ReferentialAction; /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
63
+ readonly constraint: boolean; /** Whether to emit a backing index for the FK columns. */
75
64
  readonly index: boolean;
76
65
  };
77
66
  type StorageTable = {
@@ -127,9 +116,8 @@ declare function applyFkDefaults(fk: {
127
116
  };
128
117
  type TypeMaps<TCodecTypes extends Record<string, {
129
118
  output: unknown;
130
- }> = Record<string, never>, TOperationTypes extends Record<string, unknown> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>, TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>> = {
119
+ }> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>, TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>> = {
131
120
  readonly codecTypes: TCodecTypes;
132
- readonly operationTypes: TOperationTypes;
133
121
  readonly queryOperationTypes: TQueryOperationTypes;
134
122
  readonly fieldOutputTypes: TFieldOutputTypes;
135
123
  readonly fieldInputTypes: TFieldInputTypes;
@@ -139,22 +127,42 @@ type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
139
127
  } ? C extends Record<string, {
140
128
  output: unknown;
141
129
  }> ? C : Record<string, never> : Record<string, never>;
142
- type OperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
143
- readonly operationTypes: infer O;
144
- } ? O extends Record<string, unknown> ? O : Record<string, never> : Record<string, never>;
145
- type QueryOperationArgSpec = {
146
- readonly codecId?: string;
147
- readonly traits?: readonly CodecTrait[];
148
- readonly nullable: boolean;
130
+ /**
131
+ * Dispatch hint identifying the first-argument target of an operation.
132
+ *
133
+ * Used by ORM column helpers to decide whether an operation is reachable on a
134
+ * field. Either names a concrete codec identity or a set of capability traits
135
+ * that the field's codec must carry.
136
+ */
137
+ type QueryOperationSelfSpec = {
138
+ readonly codecId: string;
139
+ readonly traits?: never;
140
+ } | {
141
+ readonly traits: readonly CodecTrait[];
142
+ readonly codecId?: never;
149
143
  };
150
- type QueryOperationTypeEntry = {
151
- readonly args: readonly QueryOperationArgSpec[];
152
- readonly returns: {
144
+ /**
145
+ * Structural shape an operation's impl must return: any value carrying a
146
+ * codec-exact `returnType` descriptor. `Expression<T>` (from
147
+ * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
148
+ * extends this. Trait-targeted returns are deliberately excluded — predicate
149
+ * detection and result decoding both depend on knowing the concrete return
150
+ * codec.
151
+ */
152
+ type QueryOperationReturn = {
153
+ readonly returnType: {
153
154
  readonly codecId: string;
154
155
  readonly nullable: boolean;
155
156
  };
156
157
  };
157
- type SqlQueryOperationTypes<T extends Record<string, QueryOperationTypeEntry>> = T;
158
+ type QueryOperationTypeEntry = {
159
+ readonly self?: QueryOperationSelfSpec;
160
+ readonly impl: (...args: never[]) => QueryOperationReturn;
161
+ };
162
+ type SqlQueryOperationTypes<_CT extends Record<string, {
163
+ readonly input: unknown;
164
+ readonly output: unknown;
165
+ }>, T extends Record<string, QueryOperationTypeEntry>> = T;
158
166
  type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
159
167
  type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
160
168
  readonly queryOperationTypes: infer Q;
@@ -173,7 +181,6 @@ type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromCo
173
181
  type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
174
182
  type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
175
183
  type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
176
- type ResolveOperationTypes<_TContract, TTypeMaps> = OperationTypesOf<TTypeMaps>;
177
184
  //#endregion
178
- export { StorageTable as A, ResolveCodecTypes as C, SqlQueryOperationTypes as D, SqlModelStorage as E, applyFkDefaults as F, TypeMaps as M, TypeMapsPhantomKey as N, SqlStorage as O, UniqueConstraint as P, ReferentialAction as S, SqlModelFieldStorage as T, PrimaryKey as _, ExtractCodecTypes as a, QueryOperationTypesBase as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKey as f, OperationTypesOf as g, Index as h, DEFAULT_FK_INDEX as i, StorageTypeInstance as j, StorageColumn as k, ExtractTypeMapsFromContract as l, ForeignKeyReferences as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, ForeignKeyOptions as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, QueryOperationArgSpec as v, ResolveOperationTypes as w, QueryOperationTypesOf as x, QueryOperationTypeEntry as y };
179
- //# sourceMappingURL=types-DdNz1nUf.d.mts.map
185
+ export { StorageTypeInstance as A, ResolveCodecTypes as C, SqlStorage as D, SqlQueryOperationTypes as E, TypeMapsPhantomKey as M, UniqueConstraint as N, StorageColumn as O, applyFkDefaults as P, ReferentialAction as S, SqlModelStorage as T, QueryOperationReturn as _, ExtractCodecTypes as a, QueryOperationTypesBase as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKey as f, PrimaryKey as g, Index as h, DEFAULT_FK_INDEX as i, TypeMaps as j, StorageTable as k, ExtractTypeMapsFromContract as l, ForeignKeyReferences as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, ForeignKeyOptions as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, QueryOperationSelfSpec as v, SqlModelFieldStorage as w, QueryOperationTypesOf as x, QueryOperationTypeEntry as y };
186
+ //# sourceMappingURL=types-njsiV-Ck.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-njsiV-Ck.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;AAUA;;;;;KAAY,aAAA;EAAA,SACD,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAWA;;;;;EAAA,SALA,UAAA,GAAa,MAAA;EAaF;;;;EAAA,SARX,OAAA;EAaiB;;;;EAAA,SARjB,OAAA,GAAU,aAAA;AAAA;AAAA,KAGT,UAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGC,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGC,KAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAA;AAAA;AAAA,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CAAA,oBACjC,MAAA,kBACA,CAAA;EAAA,SAAqB,gBAAA;AAAA,IACnB,CAAA,SAAU,MAAA,SAAe,MAAA,qBACvB,CAAA,GACA,MAAA,kBACF,MAAA;AAAA,KAEM,iBAAA,OAAwB,CAAA,oBAChC,MAAA,kBACA,CAAA;EAAA,SAAqB,eAAA;AAAA,IACnB,CAAA,SAAU,MAAA,SAAe,MAAA,qBACvB,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,KAE1E,iBAAA,0BAA2C,SAAA,oBACnD,iBAAA,CAAkB,SAAA,IAClB,YAAA,CAAa,SAAA"}
package/dist/types.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { A as StorageTable, C as ResolveCodecTypes, D as SqlQueryOperationTypes, E as SqlModelStorage, F as applyFkDefaults, M as TypeMaps, N as TypeMapsPhantomKey, O as SqlStorage, P as UniqueConstraint, S as ReferentialAction, T as SqlModelFieldStorage, _ as PrimaryKey, a as ExtractCodecTypes, b as QueryOperationTypesBase, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKey, g as OperationTypesOf, h as Index, i as DEFAULT_FK_INDEX, j as StorageTypeInstance, k as StorageColumn, l as ExtractTypeMapsFromContract, m as ForeignKeyReferences, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as ForeignKeyOptions, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as QueryOperationArgSpec, w as ResolveOperationTypes, x as QueryOperationTypesOf, y as QueryOperationTypeEntry } from "./types-DdNz1nUf.mjs";
2
- export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type OperationTypesOf, type PrimaryKey, type QueryOperationArgSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlModelFieldStorage, type SqlModelStorage, type SqlQueryOperationTypes, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
1
+ import { A as StorageTypeInstance, C as ResolveCodecTypes, D as SqlStorage, E as SqlQueryOperationTypes, M as TypeMapsPhantomKey, N as UniqueConstraint, O as StorageColumn, P as applyFkDefaults, S as ReferentialAction, T as SqlModelStorage, _ as QueryOperationReturn, a as ExtractCodecTypes, b as QueryOperationTypesBase, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKey, g as PrimaryKey, h as Index, i as DEFAULT_FK_INDEX, j as TypeMaps, k as StorageTable, l as ExtractTypeMapsFromContract, m as ForeignKeyReferences, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as ForeignKeyOptions, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as QueryOperationSelfSpec, w as SqlModelFieldStorage, x as QueryOperationTypesOf, y as QueryOperationTypeEntry } from "./types-njsiV-Ck.mjs";
2
+ export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type PrimaryKey, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type SqlModelFieldStorage, type SqlModelStorage, type SqlQueryOperationTypes, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
package/dist/types.mjs CHANGED
@@ -1,3 +1,2 @@
1
- import { n as DEFAULT_FK_INDEX, r as applyFkDefaults, t as DEFAULT_FK_CONSTRAINT } from "./types-DRR5stkj.mjs";
2
-
3
- export { DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, applyFkDefaults };
1
+ import { n as DEFAULT_FK_INDEX, r as applyFkDefaults, t as DEFAULT_FK_CONSTRAINT } from "./types-hgzy8ME1.mjs";
2
+ export { DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, applyFkDefaults };
@@ -1,4 +1,4 @@
1
- import { O as SqlStorage } from "./types-DdNz1nUf.mjs";
1
+ import { D as SqlStorage } from "./types-njsiV-Ck.mjs";
2
2
  import { Contract } from "@prisma-next/contract/types";
3
3
  import { CodecLookup } from "@prisma-next/framework-components/codec";
4
4
 
@@ -1 +1 @@
1
- {"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"sourcesContent":[],"mappings":";;;;;iBAoNgB,mCAAmC,SAAS,0CAE7C,cACZ"}
1
+ {"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"mappings":";;;;;iBAoNgB,gBAAA,mBAAmC,QAAA,CAAS,UAAA,EAAA,CAC1D,KAAA,WACA,WAAA,EAAa,WAAA,GACZ,SAAA"}
package/dist/validate.mjs CHANGED
@@ -1,6 +1,5 @@
1
- import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-BjZ6lOS1.mjs";
1
+ import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-Dm5X-Hvg.mjs";
2
2
  import { ContractValidationError, validateContract as validateContract$1 } from "@prisma-next/contract/validate-contract";
3
-
4
3
  //#region src/validate.ts
5
4
  function validateModelStorageReferences(contract) {
6
5
  for (const [modelName, model] of Object.entries(contract.models)) {
@@ -101,7 +100,7 @@ function validateContract(value, codecLookup) {
101
100
  throw new ContractValidationError(error instanceof Error ? error.message : String(error), "storage");
102
101
  }
103
102
  }
104
-
105
103
  //#endregion
106
104
  export { validateContract };
105
+
107
106
  //# sourceMappingURL=validate.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"validate.mjs","names":["decodedTables: Record<string, StorageTable>","decodedColumns: Record<string, StorageColumn>","frameworkValidateContract"],"sources":["../src/validate.ts"],"sourcesContent":["import type {\n ColumnDefaultLiteralInputValue,\n Contract,\n ContractField,\n ContractModel,\n JsonValue,\n} from '@prisma-next/contract/types';\nimport {\n ContractValidationError,\n validateContract as frameworkValidateContract,\n} from '@prisma-next/contract/validate-contract';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport type { SqlModelStorage, SqlStorage, StorageColumn, StorageTable } from './types';\nimport { validateSqlContract, validateStorageSemantics } from './validators';\n\ntype SqlValidationContract = Contract<SqlStorage, Record<string, ContractModel<SqlModelStorage>>>;\n\nfunction validateModelStorageReferences(contract: SqlValidationContract): void {\n for (const [modelName, model] of Object.entries(contract.models)) {\n const storageTable = model.storage.table;\n\n const table = contract.storage.tables[storageTable] as\n | (typeof contract.storage.tables)[string]\n | undefined;\n if (!table) {\n throw new ContractValidationError(\n `Model \"${modelName}\" references non-existent table \"${storageTable}\"`,\n 'storage',\n );\n }\n\n const columnNames = new Set(Object.keys(table.columns));\n for (const [fieldName, field] of Object.entries(model.storage.fields)) {\n if (!columnNames.has(field.column)) {\n throw new ContractValidationError(\n `Model \"${modelName}\" field \"${fieldName}\" references non-existent column \"${field.column}\" in table \"${storageTable}\"`,\n 'storage',\n );\n }\n }\n\n const JSON_NATIVE_TYPES = new Set(['json', 'jsonb']);\n for (const [fieldName, domainField] of Object.entries(model.fields)) {\n const f = domainField as ContractField;\n if (f.type?.kind !== 'valueObject') continue;\n const storageField = model.storage.fields[fieldName];\n if (!storageField) continue;\n const column = table.columns[storageField.column];\n if (!column) continue;\n if (!JSON_NATIVE_TYPES.has(column.nativeType)) {\n throw new ContractValidationError(\n `Model \"${modelName}\" field \"${fieldName}\" is a value object but storage column \"${storageField.column}\" has nativeType \"${column.nativeType}\" (expected json or jsonb)`,\n 'storage',\n );\n }\n }\n }\n}\n\nfunction validateContractLogic(contract: Contract<SqlStorage>): void {\n const tableNames = new Set(Object.keys(contract.storage.tables));\n\n for (const [tableName, table] of Object.entries(contract.storage.tables)) {\n const columnNames = new Set(Object.keys(table.columns));\n\n if (table.primaryKey) {\n for (const colName of table.primaryKey.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n }\n\n for (const unique of table.uniques) {\n for (const colName of unique.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n }\n\n for (const index of table.indexes) {\n for (const colName of index.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" index references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n }\n\n for (const [colName, column] of Object.entries(table.columns)) {\n if (!column.nullable && column.default?.kind === 'literal' && column.default.value === null) {\n throw new ContractValidationError(\n `Table \"${tableName}\" column \"${colName}\" is NOT NULL but has a literal null default`,\n 'storage',\n );\n }\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n\n if (!tableNames.has(fk.references.table)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n 'storage',\n );\n }\n\n const referencedTable = contract.storage.tables[fk.references.table];\n if (!referencedTable) continue;\n const referencedColumnNames = new Set(Object.keys(referencedTable.columns));\n for (const colName of fk.references.columns) {\n if (!referencedColumnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.references.table}\"`,\n 'storage',\n );\n }\n }\n\n if (fk.columns.length !== fk.references.columns.length) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,\n 'storage',\n );\n }\n }\n }\n}\n\nfunction validateSqlStorage(contract: Contract): void {\n const sqlContract = validateSqlContract<SqlValidationContract>(contract);\n validateContractLogic(sqlContract);\n validateModelStorageReferences(sqlContract);\n const semanticErrors = validateStorageSemantics(sqlContract.storage);\n if (semanticErrors.length > 0) {\n throw new ContractValidationError(\n `Contract semantic validation failed: ${semanticErrors.join('; ')}`,\n 'storage',\n );\n }\n}\n\nfunction decodeContractDefaults<T extends Contract<SqlStorage>>(\n contract: T,\n codecLookup: CodecLookup,\n): T {\n const tables = contract.storage.tables;\n let tablesChanged = false;\n const decodedTables: Record<string, StorageTable> = {};\n\n for (const [tableName, table] of Object.entries(tables)) {\n let columnsChanged = false;\n const decodedColumns: Record<string, StorageColumn> = {};\n\n for (const [columnName, column] of Object.entries(table.columns)) {\n if (column.default?.kind === 'literal') {\n const codec = codecLookup.get(column.codecId);\n if (codec) {\n const decodedValue = codec.decodeJson(\n column.default.value as JsonValue,\n ) as ColumnDefaultLiteralInputValue;\n if (decodedValue !== column.default.value) {\n columnsChanged = true;\n decodedColumns[columnName] = {\n ...column,\n default: { kind: 'literal', value: decodedValue },\n };\n continue;\n }\n }\n }\n decodedColumns[columnName] = column;\n }\n\n if (columnsChanged) {\n tablesChanged = true;\n decodedTables[tableName] = { ...table, columns: decodedColumns };\n } else {\n decodedTables[tableName] = table;\n }\n }\n\n if (!tablesChanged) {\n return contract;\n }\n\n return {\n ...contract,\n storage: {\n ...contract.storage,\n tables: decodedTables,\n },\n } as T;\n}\n\nexport function validateContract<TContract extends Contract<SqlStorage>>(\n value: unknown,\n codecLookup: CodecLookup,\n): TContract {\n const validated = frameworkValidateContract<TContract>(value, validateSqlStorage);\n try {\n return decodeContractDefaults(validated, codecLookup);\n } catch (error) {\n if (error instanceof ContractValidationError) throw error;\n throw new ContractValidationError(\n error instanceof Error ? error.message : String(error),\n 'storage',\n );\n }\n}\n"],"mappings":";;;;AAiBA,SAAS,+BAA+B,UAAuC;AAC7E,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,SAAS,OAAO,EAAE;EAChE,MAAM,eAAe,MAAM,QAAQ;EAEnC,MAAM,QAAQ,SAAS,QAAQ,OAAO;AAGtC,MAAI,CAAC,MACH,OAAM,IAAI,wBACR,UAAU,UAAU,mCAAmC,aAAa,IACpE,UACD;EAGH,MAAM,cAAc,IAAI,IAAI,OAAO,KAAK,MAAM,QAAQ,CAAC;AACvD,OAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,MAAM,QAAQ,OAAO,CACnE,KAAI,CAAC,YAAY,IAAI,MAAM,OAAO,CAChC,OAAM,IAAI,wBACR,UAAU,UAAU,WAAW,UAAU,oCAAoC,MAAM,OAAO,cAAc,aAAa,IACrH,UACD;EAIL,MAAM,oBAAoB,IAAI,IAAI,CAAC,QAAQ,QAAQ,CAAC;AACpD,OAAK,MAAM,CAAC,WAAW,gBAAgB,OAAO,QAAQ,MAAM,OAAO,EAAE;AAEnE,OADU,YACJ,MAAM,SAAS,cAAe;GACpC,MAAM,eAAe,MAAM,QAAQ,OAAO;AAC1C,OAAI,CAAC,aAAc;GACnB,MAAM,SAAS,MAAM,QAAQ,aAAa;AAC1C,OAAI,CAAC,OAAQ;AACb,OAAI,CAAC,kBAAkB,IAAI,OAAO,WAAW,CAC3C,OAAM,IAAI,wBACR,UAAU,UAAU,WA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AACjB,qBAAe,cAAc;OAC3B,GAAG;OACH,SAAS;QAAE,MAAM;QAAW,OAAO;QAAc;OAClD;AACD;;;;AAIN,kBAAe,cAAc;;AAG/B,MAAI,gBAAgB;AAClB,mBAAgB;AAChB,iBAAc,aAAa;IAAE,GAAG;IAAO,SAAS;IAAgB;QAEhE,eAAc,aAAa;;AAI/B,KAAI,CAAC,cACH,QAAO;AAGT,QAAO;EACL,GAAG;EACH,SAAS;GACP,GAAG,SAAS;GACZ,QAAQ;GACT;EACF;;AAGH,SAAgB,iBACd,OACA,aACW;CACX,MAAM,YAAYC,mBAAqC,OAAO,mBAAmB;AACjF,KAAI;AACF,SAAO,uBAAuB,WAAW,YAAY;UAC9C,OAAO;AACd,MAAI,iBAAiB,wBAAyB,OAAM;AACpD,QAAM,IAAI,wBACR,iBAAiB,QAAQ,MAAM,UAAU,OAAO,MAAM,EACtD,UACD"}
1
+ {"version":3,"file":"validate.mjs","names":["f","frameworkValidateContract"],"sources":["../src/validate.ts"],"sourcesContent":["import type {\n ColumnDefaultLiteralInputValue,\n Contract,\n ContractField,\n ContractModel,\n JsonValue,\n} from '@prisma-next/contract/types';\nimport {\n ContractValidationError,\n validateContract as frameworkValidateContract,\n} from '@prisma-next/contract/validate-contract';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport type { SqlModelStorage, SqlStorage, StorageColumn, StorageTable } from './types';\nimport { validateSqlContract, validateStorageSemantics } from './validators';\n\ntype SqlValidationContract = Contract<SqlStorage, Record<string, ContractModel<SqlModelStorage>>>;\n\nfunction validateModelStorageReferences(contract: SqlValidationContract): void {\n for (const [modelName, model] of Object.entries(contract.models)) {\n const storageTable = model.storage.table;\n\n const table = contract.storage.tables[storageTable] as\n | (typeof contract.storage.tables)[string]\n | undefined;\n if (!table) {\n throw new ContractValidationError(\n `Model \"${modelName}\" references non-existent table \"${storageTable}\"`,\n 'storage',\n );\n }\n\n const columnNames = new Set(Object.keys(table.columns));\n for (const [fieldName, field] of Object.entries(model.storage.fields)) {\n if (!columnNames.has(field.column)) {\n throw new ContractValidationError(\n `Model \"${modelName}\" field \"${fieldName}\" references non-existent column \"${field.column}\" in table \"${storageTable}\"`,\n 'storage',\n );\n }\n }\n\n const JSON_NATIVE_TYPES = new Set(['json', 'jsonb']);\n for (const [fieldName, domainField] of Object.entries(model.fields)) {\n const f = domainField as ContractField;\n if (f.type?.kind !== 'valueObject') continue;\n const storageField = model.storage.fields[fieldName];\n if (!storageField) continue;\n const column = table.columns[storageField.column];\n if (!column) continue;\n if (!JSON_NATIVE_TYPES.has(column.nativeType)) {\n throw new ContractValidationError(\n `Model \"${modelName}\" field \"${fieldName}\" is a value object but storage column \"${storageField.column}\" has nativeType \"${column.nativeType}\" (expected json or jsonb)`,\n 'storage',\n );\n }\n }\n }\n}\n\nfunction validateContractLogic(contract: Contract<SqlStorage>): void {\n const tableNames = new Set(Object.keys(contract.storage.tables));\n\n for (const [tableName, table] of Object.entries(contract.storage.tables)) {\n const columnNames = new Set(Object.keys(table.columns));\n\n if (table.primaryKey) {\n for (const colName of table.primaryKey.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n }\n\n for (const unique of table.uniques) {\n for (const colName of unique.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n }\n\n for (const index of table.indexes) {\n for (const colName of index.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" index references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n }\n\n for (const [colName, column] of Object.entries(table.columns)) {\n if (!column.nullable && column.default?.kind === 'literal' && column.default.value === null) {\n throw new ContractValidationError(\n `Table \"${tableName}\" column \"${colName}\" is NOT NULL but has a literal null default`,\n 'storage',\n );\n }\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n if (!columnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n\n if (!tableNames.has(fk.references.table)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n 'storage',\n );\n }\n\n const referencedTable = contract.storage.tables[fk.references.table];\n if (!referencedTable) continue;\n const referencedColumnNames = new Set(Object.keys(referencedTable.columns));\n for (const colName of fk.references.columns) {\n if (!referencedColumnNames.has(colName)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.references.table}\"`,\n 'storage',\n );\n }\n }\n\n if (fk.columns.length !== fk.references.columns.length) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,\n 'storage',\n );\n }\n }\n }\n}\n\nfunction validateSqlStorage(contract: Contract): void {\n const sqlContract = validateSqlContract<SqlValidationContract>(contract);\n validateContractLogic(sqlContract);\n validateModelStorageReferences(sqlContract);\n const semanticErrors = validateStorageSemantics(sqlContract.storage);\n if (semanticErrors.length > 0) {\n throw new ContractValidationError(\n `Contract semantic validation failed: ${semanticErrors.join('; ')}`,\n 'storage',\n );\n }\n}\n\nfunction decodeContractDefaults<T extends Contract<SqlStorage>>(\n contract: T,\n codecLookup: CodecLookup,\n): T {\n const tables = contract.storage.tables;\n let tablesChanged = false;\n const decodedTables: Record<string, StorageTable> = {};\n\n for (const [tableName, table] of Object.entries(tables)) {\n let columnsChanged = false;\n const decodedColumns: Record<string, StorageColumn> = {};\n\n for (const [columnName, column] of Object.entries(table.columns)) {\n if (column.default?.kind === 'literal') {\n const codec = codecLookup.get(column.codecId);\n if (codec) {\n const decodedValue = codec.decodeJson(\n column.default.value as JsonValue,\n ) as ColumnDefaultLiteralInputValue;\n if (decodedValue !== column.default.value) {\n columnsChanged = true;\n decodedColumns[columnName] = {\n ...column,\n default: { kind: 'literal', value: decodedValue },\n };\n continue;\n }\n }\n }\n decodedColumns[columnName] = column;\n }\n\n if (columnsChanged) {\n tablesChanged = true;\n decodedTables[tableName] = { ...table, columns: decodedColumns };\n } else {\n decodedTables[tableName] = table;\n }\n }\n\n if (!tablesChanged) {\n return contract;\n }\n\n return {\n ...contract,\n storage: {\n ...contract.storage,\n tables: decodedTables,\n },\n } as T;\n}\n\nexport function validateContract<TContract extends Contract<SqlStorage>>(\n value: unknown,\n codecLookup: CodecLookup,\n): TContract {\n const validated = frameworkValidateContract<TContract>(value, validateSqlStorage);\n try {\n return decodeContractDefaults(validated, codecLookup);\n } catch (error) {\n if (error instanceof ContractValidationError) throw error;\n throw new ContractValidationError(\n error instanceof Error ? error.message : String(error),\n 'storage',\n );\n }\n}\n"],"mappings":";;;AAiBA,SAAS,+BAA+B,UAAuC;CAC7E,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,SAAS,OAAO,EAAE;EAChE,MAAM,eAAe,MAAM,QAAQ;EAEnC,MAAM,QAAQ,SAAS,QAAQ,OAAO;EAGtC,IAAI,CAAC,OACH,MAAM,IAAI,wBACR,UAAU,UAAU,mCAAmC,aAAa,IACpE,UACD;EAGH,MAAM,cAAc,IAAI,IAAI,OAAO,KAAK,MAAM,QAAQ,CAAC;EACvD,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,MAAM,QAAQ,OAAO,EACnE,IAAI,CAAC,YAAY,IAAI,MAAM,OAAO,EAChC,MAAM,IAAI,wBACR,UAAU,UAAU,WAAW,UAAU,oCAAoC,MAAM,OAAO,cAAc,aAAa,IACrH,UACD;EAIL,MAAM,oBAAoB,IAAI,IAAI,CAAC,QAAQ,QAAQ,CAAC;EACpD,KAAK,MAAM,CAAC,WAAW,gBAAgB,OAAO,QAAQ,MAAM,OAAO,EAAE;GAEnE,IAAIA,YAAE,MAAM,SAAS,eAAe;GACpC,MAAM,eAAe,MAAM,QAAQ,OAAO;GAC1C,I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