@prisma-next/sql-contract 0.8.0 → 0.9.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 (52) hide show
  1. package/README.md +13 -11
  2. package/dist/factories.d.mts +2 -2
  3. package/dist/factories.d.mts.map +1 -1
  4. package/dist/factories.mjs +16 -14
  5. package/dist/factories.mjs.map +1 -1
  6. package/dist/index-type-validation.d.mts +2 -2
  7. package/dist/index-type-validation.mjs +1 -1
  8. package/dist/index-type-validation.mjs.map +1 -1
  9. package/dist/{index-types-DqVqGHwg.d.mts → index-types-B1cf5N0F.d.mts} +1 -1
  10. package/dist/{index-types-DqVqGHwg.d.mts.map → index-types-B1cf5N0F.d.mts.map} +1 -1
  11. package/dist/index-types.d.mts +1 -1
  12. package/dist/types-B0lbr9cb.d.mts +498 -0
  13. package/dist/types-B0lbr9cb.d.mts.map +1 -0
  14. package/dist/types-iqFGDcJp.mjs +389 -0
  15. package/dist/types-iqFGDcJp.mjs.map +1 -0
  16. package/dist/types.d.mts +2 -2
  17. package/dist/types.mjs +2 -2
  18. package/dist/validators.d.mts +27 -15
  19. package/dist/validators.d.mts.map +1 -1
  20. package/dist/validators.mjs +409 -2
  21. package/dist/validators.mjs.map +1 -0
  22. package/package.json +6 -7
  23. package/src/exports/types.ts +30 -9
  24. package/src/factories.ts +19 -32
  25. package/src/index-type-validation.ts +1 -1
  26. package/src/index.ts +0 -1
  27. package/src/ir/foreign-key-references.ts +26 -0
  28. package/src/ir/foreign-key.ts +50 -0
  29. package/src/ir/postgres-enum-storage-entry.ts +55 -0
  30. package/src/ir/primary-key.ts +22 -0
  31. package/src/ir/sql-index.ts +33 -0
  32. package/src/ir/sql-node.ts +52 -0
  33. package/src/ir/sql-storage.ts +154 -0
  34. package/src/ir/sql-unspecified-namespace.ts +51 -0
  35. package/src/ir/storage-column.ts +55 -0
  36. package/src/ir/storage-table.ts +63 -0
  37. package/src/ir/storage-type-instance.ts +60 -0
  38. package/src/ir/unique-constraint.ts +22 -0
  39. package/src/types.ts +38 -99
  40. package/src/validators.ts +268 -28
  41. package/dist/types-hgzy8ME1.mjs +0 -13
  42. package/dist/types-hgzy8ME1.mjs.map +0 -1
  43. package/dist/types-njsiV-Ck.d.mts +0 -186
  44. package/dist/types-njsiV-Ck.d.mts.map +0 -1
  45. package/dist/validate.d.mts +0 -9
  46. package/dist/validate.d.mts.map +0 -1
  47. package/dist/validate.mjs +0 -106
  48. package/dist/validate.mjs.map +0 -1
  49. package/dist/validators-Dm5X-Hvg.mjs +0 -294
  50. package/dist/validators-Dm5X-Hvg.mjs.map +0 -1
  51. package/src/exports/validate.ts +0 -1
  52. package/src/validate.ts +0 -227
package/README.md CHANGED
@@ -9,7 +9,7 @@ This package provides TypeScript type definitions, Arktype validators, and facto
9
9
  ## Responsibilities
10
10
 
11
11
  - **SQL Contract Types**: Defines SQL-specific contract types (`SqlContract`, `SqlStorage`, `StorageTable`, `SqlModelStorage`, `SqlModelFieldStorage`, `ForeignKeysConfig`) that extend framework-level contract types
12
- - **Contract Validation**: Provides Arktype-based structural validators and the shared `validateContract` entrypoint for runtime-safe contract validation
12
+ - **Contract Validation**: Provides Arktype-based structural validators that the per-target `contractSerializer` SPI consumes for runtime-safe contract validation
13
13
  - **IR Factories**: Provides pure factory functions for constructing contract IR structures in tests and authoring
14
14
  - **Shared Plane Access**: Enables both migration-plane and runtime-plane packages to import SQL contract types without violating plane boundaries
15
15
 
@@ -102,10 +102,10 @@ const named = fk(['userId'], 'user', ['id'], {
102
102
  Validate contract structures using Arktype validators:
103
103
 
104
104
  ```typescript
105
- import { validateSqlContract, validateStorage, validateModel } from '@prisma-next/sql-contract/validators';
105
+ import { validateSqlContractFully, validateStorage, validateModel } from '@prisma-next/sql-contract/validators';
106
106
 
107
107
  // Validate a complete contract
108
- const contract = validateSqlContract<Contract>(contractJson);
108
+ const contract = validateSqlContractFully<Contract>(contractJson);
109
109
 
110
110
  // Validate storage structure
111
111
  const storage = validateStorage(storageJson);
@@ -114,18 +114,21 @@ const storage = validateStorage(storageJson);
114
114
  const model = validateModel(modelJson);
115
115
  ```
116
116
 
117
- Validate JSON-emitted contracts with mapping + logic checks:
117
+ Validate JSON-emitted contracts with mapping + logic checks via the
118
+ target descriptor's `contractSerializer` SPI:
118
119
 
119
120
  ```typescript
120
- import { validateContract } from '@prisma-next/sql-contract/validate';
121
+ import postgresTarget from '@prisma-next/target-postgres/control';
121
122
 
122
- const contract = validateContract<Contract>(contractJson);
123
+ const contract = postgresTarget.contractSerializer.deserializeContract(contractJson);
123
124
  ```
124
125
 
125
- `validateContract` returns a constructed contract that:
126
- - Strips `_generated` if present on input (emitter metadata is excluded from the returned value)
127
- - Validates model-to-storage cross-references (table existence, column existence)
128
- - Does not require execution stack or runtime descriptors
126
+ `deserializeContract` parses the on-disk envelope, hydrates the SQL
127
+ Contract IR class hierarchy (`SqlStorage` `StorageTable` `StorageColumn`
128
+ / `PrimaryKey` / …), and validates model-to-storage cross-references in
129
+ one pass. End-user app code typically calls the canonical façade instead
130
+ (e.g. `postgres<Contract>({ contractJson, … })`), which threads the same
131
+ SPI internally.
129
132
 
130
133
  ### Factories
131
134
 
@@ -172,7 +175,6 @@ const c = contract({
172
175
 
173
176
  - `./types`: TypeScript type definitions
174
177
  - `./validators`: Arktype validators for structural validation
175
- - `./validate`: Shared `validateContract` helper for JSON imports
176
178
  - `./factories`: Factory functions for constructing contract IR
177
179
  - `./pack-types`: Shared extension/pack typing helpers
178
180
 
@@ -1,4 +1,4 @@
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";
1
+ import { B as Index, H as PrimaryKey, I as UniqueConstraint, P as StorageTable, R as StorageColumn, b as SqlModelStorage, f as ForeignKeyOptions, q as ForeignKey, y as SqlModelFieldStorage, z as StorageColumnInput } from "./types-B0lbr9cb.mjs";
2
2
  import { ScalarFieldType } from "@prisma-next/contract/types";
3
3
 
4
4
  //#region src/factories.d.ts
@@ -10,7 +10,7 @@ declare function fk(columns: readonly string[], refTable: string, refColumns: re
10
10
  constraint?: boolean;
11
11
  index?: boolean;
12
12
  }): ForeignKey;
13
- declare function table(columns: Record<string, StorageColumn>, opts?: {
13
+ declare function table(columns: Record<string, StorageColumn | StorageColumnInput>, opts?: {
14
14
  pk?: PrimaryKey;
15
15
  uniques?: readonly UniqueConstraint[];
16
16
  indexes?: readonly Index[];
@@ -1 +1 @@
1
- {"version":3,"file":"factories.d.mts","names":[],"sources":["../src/factories.ts"],"mappings":";;;;iBAegB,GAAA,CAAI,UAAA,UAAoB,OAAA,UAAiB,QAAA,aAAmB,aAAA;AAAA,iBAQ5D,EAAA,CAAA,GAAM,OAAA,sBAA6B,UAAA;AAAA,iBAMnC,MAAA,CAAA,GAAU,OAAA,sBAA6B,gBAAA;AAAA,iBAMvC,KAAA,CAAA,GAAS,OAAA,sBAA6B,KAAA;AAAA,iBAMtC,EAAA,CACd,OAAA,qBACA,QAAA,UACA,UAAA,qBACA,IAAA,GAAO,iBAAA;EAAsB,UAAA;EAAsB,KAAA;AAAA,IAClD,UAAA;AAAA,iBAgBa,KAAA,CACd,OAAA,EAAS,MAAA,SAAe,aAAA,GACxB,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;EAEX,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,GAAA,CAAI,UAAA,UAAoB,OAAA,UAAiB,QAAA,aAAmB,aAAA;AAAA,iBAI5D,EAAA,CAAA,GAAM,OAAA,sBAA6B,UAAA;AAAA,iBAInC,MAAA,CAAA,GAAU,OAAA,sBAA6B,gBAAA;AAAA,iBAIvC,KAAA,CAAA,GAAS,OAAA,sBAA6B,KAAA;AAAA,iBAItC,EAAA,CACd,OAAA,qBACA,QAAA,UACA,UAAA,qBACA,IAAA,GAAO,iBAAA;EAAsB,UAAA;EAAsB,KAAA;AAAA,IAClD,UAAA;AAAA,iBAaa,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;EAEX,OAAA,EAAS,eAAA;EACT,MAAA,EAAQ,MAAA;IAAA,SAA0B,QAAA;IAAA,SAA4B,IAAA,EAAM,eAAA;EAAA;EACpE,SAAA,EAAW,MAAA;AAAA"}
@@ -1,23 +1,27 @@
1
- import { r as applyFkDefaults } from "./types-hgzy8ME1.mjs";
1
+ import { c as StorageTable, f as Index, g as ForeignKey, l as UniqueConstraint, p as PrimaryKey, r as applyFkDefaults, u as StorageColumn } from "./types-iqFGDcJp.mjs";
2
2
  //#region src/factories.ts
3
3
  function col(nativeType, codecId, nullable = false) {
4
- return {
4
+ return new StorageColumn({
5
5
  nativeType,
6
6
  codecId,
7
7
  nullable
8
- };
8
+ });
9
9
  }
10
10
  function pk(...columns) {
11
- return { columns };
11
+ return new PrimaryKey({ columns });
12
12
  }
13
13
  function unique(...columns) {
14
- return { columns };
14
+ return new UniqueConstraint({ columns });
15
15
  }
16
16
  function index(...columns) {
17
- return { columns };
17
+ return new Index({ columns });
18
18
  }
19
19
  function fk(columns, refTable, refColumns, opts) {
20
- return {
20
+ const defaults = applyFkDefaults({
21
+ constraint: opts?.constraint,
22
+ index: opts?.index
23
+ });
24
+ return new ForeignKey({
21
25
  columns,
22
26
  references: {
23
27
  table: refTable,
@@ -26,20 +30,18 @@ function fk(columns, refTable, refColumns, opts) {
26
30
  ...opts?.name !== void 0 && { name: opts.name },
27
31
  ...opts?.onDelete !== void 0 && { onDelete: opts.onDelete },
28
32
  ...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate },
29
- ...applyFkDefaults({
30
- constraint: opts?.constraint,
31
- index: opts?.index
32
- })
33
- };
33
+ constraint: defaults.constraint,
34
+ index: defaults.index
35
+ });
34
36
  }
35
37
  function table(columns, opts) {
36
- return {
38
+ return new StorageTable({
37
39
  columns,
38
40
  ...opts?.pk !== void 0 && { primaryKey: opts.pk },
39
41
  uniques: opts?.uniques ?? [],
40
42
  indexes: opts?.indexes ?? [],
41
43
  foreignKeys: opts?.fks ?? []
42
- };
44
+ });
43
45
  }
44
46
  function model(tableName, fields, relations = {}) {
45
47
  return {
@@ -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;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"}
1
+ {"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import type { ScalarFieldType } from '@prisma-next/contract/types';\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(nativeType: string, codecId: string, nullable = false): StorageColumn {\n return new StorageColumn({ nativeType, codecId, nullable });\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 columns: readonly string[],\n refTable: string,\n refColumns: readonly string[],\n opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean },\n): ForeignKey {\n const defaults = applyFkDefaults({ constraint: opts?.constraint, index: opts?.index });\n return new ForeignKey({\n columns,\n references: { table: refTable, columns: refColumns },\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): {\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,IAAI,cAAc;EAAE;EAAY;EAAS;EAAU,CAAC;;AAG7D,SAAgB,GAAG,GAAG,SAAwC;CAC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-DqVqGHwg.mjs";
1
+ import { E as SqlStorage } from "./types-B0lbr9cb.mjs";
2
+ import { a as IndexTypeRegistry } from "./index-types-B1cf5N0F.mjs";
3
3
  import { Contract } from "@prisma-next/contract/types";
4
4
 
5
5
  //#region src/index-type-validation.d.ts
@@ -1,4 +1,4 @@
1
- import { ContractValidationError } from "@prisma-next/contract/validate-contract";
1
+ import { ContractValidationError } from "@prisma-next/contract/contract-validation-error";
2
2
  import { type } from "arktype";
3
3
  //#region src/index-type-validation.ts
4
4
  function validateIndexTypes(contract, indexTypeRegistry) {
@@ -1 +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"}
1
+ {"version":3,"file":"index-type-validation.mjs","names":[],"sources":["../src/index-type-validation.ts"],"sourcesContent":["import { ContractValidationError } from '@prisma-next/contract/contract-validation-error';\nimport type { Contract } from '@prisma-next/contract/types';\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"}
@@ -28,4 +28,4 @@ interface IndexTypeRegistry {
28
28
  declare function createIndexTypeRegistry(): IndexTypeRegistry;
29
29
  //#endregion
30
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
31
+ //# sourceMappingURL=index-types-B1cf5N0F.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index-types-DqVqGHwg.d.mts","names":[],"sources":["../src/index-types.ts"],"mappings":";;;UAEi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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"}
@@ -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-DqVqGHwg.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-B1cf5N0F.mjs";
2
2
  export { type IndexTypeBuilder, type IndexTypeEntry, type IndexTypeMap, type IndexTypeRegistration, type IndexTypeRegistry, createIndexTypeRegistry, defineIndexTypes };