@prisma-next/sql-contract 0.3.0-dev.5 → 0.3.0-dev.50

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 (58) hide show
  1. package/README.md +79 -10
  2. package/dist/factories.d.mts +48 -0
  3. package/dist/factories.d.mts.map +1 -0
  4. package/dist/factories.mjs +84 -0
  5. package/dist/factories.mjs.map +1 -0
  6. package/dist/pack-types.d.mts +13 -0
  7. package/dist/pack-types.d.mts.map +1 -0
  8. package/dist/pack-types.mjs +1 -0
  9. package/dist/types-T6o5-ZB3.d.mts +145 -0
  10. package/dist/types-T6o5-ZB3.d.mts.map +1 -0
  11. package/dist/types-kacOgEya.mjs +17 -0
  12. package/dist/types-kacOgEya.mjs.map +1 -0
  13. package/dist/types.d.mts +2 -0
  14. package/dist/types.mjs +3 -0
  15. package/dist/validate.d.mts +11 -0
  16. package/dist/validate.d.mts.map +1 -0
  17. package/dist/validate.mjs +244 -0
  18. package/dist/validate.mjs.map +1 -0
  19. package/dist/validators-Dz93b38w.mjs +214 -0
  20. package/dist/validators-Dz93b38w.mjs.map +1 -0
  21. package/dist/validators.d.mts +65 -0
  22. package/dist/validators.d.mts.map +1 -0
  23. package/dist/validators.mjs +3 -0
  24. package/package.json +23 -27
  25. package/src/exports/types.ts +5 -0
  26. package/src/exports/validate.ts +6 -0
  27. package/src/exports/validators.ts +1 -1
  28. package/src/factories.ts +41 -8
  29. package/src/index.ts +1 -0
  30. package/src/types.ts +88 -2
  31. package/src/validate.ts +448 -0
  32. package/src/validators.ts +161 -10
  33. package/dist/exports/factories.d.ts +0 -2
  34. package/dist/exports/factories.d.ts.map +0 -1
  35. package/dist/exports/factories.js +0 -83
  36. package/dist/exports/factories.js.map +0 -1
  37. package/dist/exports/pack-types.d.ts +0 -2
  38. package/dist/exports/pack-types.d.ts.map +0 -1
  39. package/dist/exports/pack-types.js +0 -1
  40. package/dist/exports/pack-types.js.map +0 -1
  41. package/dist/exports/types.d.ts +0 -2
  42. package/dist/exports/types.d.ts.map +0 -1
  43. package/dist/exports/types.js +0 -1
  44. package/dist/exports/types.js.map +0 -1
  45. package/dist/exports/validators.d.ts +0 -2
  46. package/dist/exports/validators.d.ts.map +0 -1
  47. package/dist/exports/validators.js +0 -96
  48. package/dist/exports/validators.js.map +0 -1
  49. package/dist/factories.d.ts +0 -38
  50. package/dist/factories.d.ts.map +0 -1
  51. package/dist/index.d.ts +0 -4
  52. package/dist/index.d.ts.map +0 -1
  53. package/dist/pack-types.d.ts +0 -10
  54. package/dist/pack-types.d.ts.map +0 -1
  55. package/dist/types.d.ts +0 -68
  56. package/dist/types.d.ts.map +0 -1
  57. package/dist/validators.d.ts +0 -35
  58. package/dist/validators.d.ts.map +0 -1
package/README.md CHANGED
@@ -8,8 +8,8 @@ This package provides TypeScript type definitions, Arktype validators, and facto
8
8
 
9
9
  ## Responsibilities
10
10
 
11
- - **SQL Contract Types**: Defines SQL-specific contract types (`SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, `SqlMappings`) that extend framework-level contract types
12
- - **Contract Validation**: Provides Arktype-based validators for structural validation of SQL contracts, storage, and models
11
+ - **SQL Contract Types**: Defines SQL-specific contract types (`SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, `SqlMappings`, `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
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
 
@@ -19,12 +19,13 @@ Each `StorageColumn` in SQL contracts includes both:
19
19
  - **`nativeType`** (required): Native database type identifier (e.g., `'int4'`, `'text'`, `'vector'`) - used for database structure verification and migration planning
20
20
  - **`codecId`** (required): Codec identifier (e.g., `'pg/int4@1'`, `'pg/text@1'`, `'pg/vector@1'`) - used for query builders and runtime codecs
21
21
  - **`nullable`** (required): Whether the column is nullable
22
+ - **`default`** (optional): Uses the shared `ColumnDefault` type from `@prisma-next/contract` for db-agnostic defaults (literal or function). Client-generated defaults live in `execution.mutations.defaults`.
22
23
 
23
24
  Both `nativeType` and `codecId` are required to ensure contracts are consumable by both the application (via codec IDs) and the database (via native types). See `docs/briefs/Sql-Contract-Native-and-Codec-Types.md` for details.
24
25
 
25
26
  ## Package Contents
26
27
 
27
- - **TypeScript Types**: Type definitions for `SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, and related types
28
+ - **TypeScript Types**: Type definitions for `SqlContract`, `SqlStorage`, `StorageTable`, `ModelDefinition`, `ForeignKeysConfig`, and related types
28
29
  - **Validators**: Arktype-based validators for structural validation of contracts, storage, and models
29
30
  - **Factories**: Pure factory functions for constructing contract IR structures in tests and authoring
30
31
 
@@ -40,15 +41,68 @@ import type {
40
41
  SqlStorage,
41
42
  StorageTable,
42
43
  ModelDefinition,
43
- } from '@prisma-next/sql-contract/exports/types';
44
+ ForeignKeysConfig,
45
+ } from '@prisma-next/sql-contract/types';
44
46
  ```
45
47
 
48
+ ### Foreign Keys Configuration
49
+
50
+ `SqlContract` includes an optional `foreignKeys` field of type `ForeignKeysConfig` that controls whether the planner emits foreign key constraints and their backing indexes:
51
+
52
+ ```typescript
53
+ type ForeignKeysConfig = {
54
+ readonly constraints: boolean; // Emit FOREIGN KEY constraints
55
+ readonly indexes: boolean; // Emit FK-backing indexes
56
+ };
57
+ ```
58
+
59
+ When omitted, defaults to `{ constraints: true, indexes: true }`. See [ADR 161](../../../docs/architecture%20docs/adrs/ADR%20161%20-%20Explicit%20foreign%20key%20constraint%20and%20index%20configuration.md) for design rationale.
60
+
61
+ ### Referential Actions
62
+
63
+ `ForeignKey` supports optional `onDelete` and `onUpdate` fields of type `ReferentialAction`:
64
+
65
+ ```typescript
66
+ type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
67
+
68
+ type ForeignKey = {
69
+ readonly columns: readonly string[];
70
+ readonly references: ForeignKeyReferences;
71
+ readonly name?: string;
72
+ readonly onDelete?: ReferentialAction;
73
+ readonly onUpdate?: ReferentialAction;
74
+ };
75
+ ```
76
+
77
+ When omitted, the database applies its default behavior (Postgres: `NO ACTION`). See [ADR 166](../../../docs/architecture%20docs/adrs/ADR%20166%20-%20Referential%20actions%20for%20foreign%20keys.md) for design rationale.
78
+
79
+ The `fk()` factory accepts referential actions via an options object:
80
+
81
+ ```typescript
82
+ import { fk } from '@prisma-next/sql-contract/factories';
83
+
84
+ // Simple FK (no referential actions)
85
+ const simple = fk(['userId'], 'user', ['id']);
86
+
87
+ // FK with onDelete cascade
88
+ const cascading = fk(['userId'], 'user', ['id'], { onDelete: 'cascade' });
89
+
90
+ // FK with name and both actions
91
+ const named = fk(['userId'], 'user', ['id'], {
92
+ name: 'post_userId_fkey',
93
+ onDelete: 'cascade',
94
+ onUpdate: 'noAction',
95
+ });
96
+ ```
97
+
98
+ **Semantic validation:** `validateStorageSemantics()` rejects `setNull` when the FK column is `NOT NULL` (the database would fail at runtime).
99
+
46
100
  ### Validators
47
101
 
48
102
  Validate contract structures using Arktype validators:
49
103
 
50
104
  ```typescript
51
- import { validateSqlContract, validateStorage, validateModel } from '@prisma-next/sql-contract/exports/validators';
105
+ import { validateSqlContract, validateStorage, validateModel } from '@prisma-next/sql-contract/validators';
52
106
 
53
107
  // Validate a complete contract
54
108
  const contract = validateSqlContract<Contract>(contractJson);
@@ -60,12 +114,25 @@ const storage = validateStorage(storageJson);
60
114
  const model = validateModel(modelJson);
61
115
  ```
62
116
 
117
+ Validate JSON-emitted contracts with mapping + logic checks:
118
+
119
+ ```typescript
120
+ import { validateContract } from '@prisma-next/sql-contract/validate';
121
+
122
+ const contract = validateContract<Contract>(contractJson);
123
+ ```
124
+
125
+ Mapping overrides in `contract.mappings` follow strict pair semantics:
126
+ - `modelToTable` and `tableToModel` must either both be omitted (auto-computed) or both be provided as inverse maps.
127
+ - `fieldToColumn` and `columnToField` must either both be omitted (auto-computed) or both be provided as inverse maps.
128
+ - `codecTypes` and `operationTypes` are merged additively on top of defaults.
129
+
63
130
  ### Factories
64
131
 
65
132
  Use factory functions to construct contract IR structures in tests:
66
133
 
67
134
  ```typescript
68
- import { col, table, storage, model, contract, pk, unique, index, fk } from '@prisma-next/sql-contract/exports/factories';
135
+ import { col, table, storage, model, contract, pk, unique, index, fk } from '@prisma-next/sql-contract/factories';
69
136
 
70
137
  // Create a column (nativeType, codecId, nullable)
71
138
  const idColumn = col('int4', 'pg/int4@1', false);
@@ -95,7 +162,7 @@ const userModel = model('user', {
95
162
  // Create a complete contract
96
163
  const c = contract({
97
164
  target: 'postgres',
98
- coreHash: 'sha256:abc123',
165
+ storageHash: 'sha256:abc123',
99
166
  storage: s,
100
167
  models: { User: userModel },
101
168
  });
@@ -103,9 +170,11 @@ const c = contract({
103
170
 
104
171
  ## Exports
105
172
 
106
- - `./exports/types`: TypeScript type definitions
107
- - `./exports/validators`: Arktype validators for structural validation
108
- - `./exports/factories`: Factory functions for constructing contract IR
173
+ - `./types`: TypeScript type definitions
174
+ - `./validators`: Arktype validators for structural validation
175
+ - `./validate`: Shared `validateContract` helper for JSON imports
176
+ - `./factories`: Factory functions for constructing contract IR
177
+ - `./pack-types`: Shared extension/pack typing helpers
109
178
 
110
179
  ## Architecture
111
180
 
@@ -0,0 +1,48 @@
1
+ import { _ as StorageColumn, a as ForeignKey, b as UniqueConstraint, c as Index, f as PrimaryKey, g as SqlStorage, h as SqlMappings, l as ModelDefinition, m as SqlContract, o as ForeignKeyOptions, u as ModelField, v as StorageTable } from "./types-T6o5-ZB3.mjs";
2
+ import { ExecutionHashBase, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
3
+
4
+ //#region src/factories.d.ts
5
+
6
+ /**
7
+ * Creates a StorageColumn with nativeType and codecId.
8
+ *
9
+ * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')
10
+ * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')
11
+ * @param nullable - Whether the column is nullable (default: false)
12
+ * @returns StorageColumn with nativeType and codecId
13
+ */
14
+ declare function col(nativeType: string, codecId: string, nullable?: boolean): StorageColumn;
15
+ declare function pk(...columns: readonly string[]): PrimaryKey;
16
+ declare function unique(...columns: readonly string[]): UniqueConstraint;
17
+ declare function index(...columns: readonly string[]): Index;
18
+ declare function fk(columns: readonly string[], refTable: string, refColumns: readonly string[], opts?: ForeignKeyOptions & {
19
+ constraint?: boolean;
20
+ index?: boolean;
21
+ }): ForeignKey;
22
+ declare function table(columns: Record<string, StorageColumn>, opts?: {
23
+ pk?: PrimaryKey;
24
+ uniques?: readonly UniqueConstraint[];
25
+ indexes?: readonly Index[];
26
+ fks?: readonly ForeignKey[];
27
+ }): StorageTable;
28
+ declare function model(table: string, fields: Record<string, ModelField>, relations?: Record<string, unknown>): ModelDefinition;
29
+ declare function storage(tables: Record<string, StorageTable>): SqlStorage;
30
+ declare function contract<TStorageHash extends StorageHashBase<string> = StorageHashBase<string>, TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>, TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>>(opts: {
31
+ target: string;
32
+ storageHash: TStorageHash;
33
+ executionHash?: TExecutionHash;
34
+ storage: SqlStorage;
35
+ models?: Record<string, ModelDefinition>;
36
+ relations?: Record<string, unknown>;
37
+ mappings?: Partial<SqlMappings>;
38
+ schemaVersion?: '1';
39
+ targetFamily?: 'sql';
40
+ profileHash?: TProfileHash;
41
+ capabilities?: Record<string, Record<string, boolean>>;
42
+ extensionPacks?: Record<string, unknown>;
43
+ meta?: Record<string, unknown>;
44
+ sources?: Record<string, unknown>;
45
+ }): SqlContract<SqlStorage, Record<string, unknown>, Record<string, unknown>, SqlMappings, TStorageHash, TExecutionHash, TProfileHash>;
46
+ //#endregion
47
+ export { col, contract, fk, index, model, pk, storage, table, unique };
48
+ //# sourceMappingURL=factories.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":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
5
+ * Creates a StorageColumn with nativeType and codecId.
6
+ *
7
+ * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')
8
+ * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')
9
+ * @param nullable - Whether the column is nullable (default: false)
10
+ * @returns StorageColumn with nativeType and codecId
11
+ */
12
+ function col(nativeType, codecId, nullable = false) {
13
+ return {
14
+ nativeType,
15
+ codecId,
16
+ nullable
17
+ };
18
+ }
19
+ function pk(...columns) {
20
+ return { columns };
21
+ }
22
+ function unique(...columns) {
23
+ return { columns };
24
+ }
25
+ function index(...columns) {
26
+ return { columns };
27
+ }
28
+ function fk(columns, refTable, refColumns, opts) {
29
+ return {
30
+ columns,
31
+ references: {
32
+ table: refTable,
33
+ columns: refColumns
34
+ },
35
+ ...opts?.name !== void 0 && { name: opts.name },
36
+ ...opts?.onDelete !== void 0 && { onDelete: opts.onDelete },
37
+ ...opts?.onUpdate !== void 0 && { onUpdate: opts.onUpdate },
38
+ ...applyFkDefaults({
39
+ constraint: opts?.constraint,
40
+ index: opts?.index
41
+ })
42
+ };
43
+ }
44
+ function table(columns, opts) {
45
+ return {
46
+ columns,
47
+ ...opts?.pk !== void 0 && { primaryKey: opts.pk },
48
+ uniques: opts?.uniques ?? [],
49
+ indexes: opts?.indexes ?? [],
50
+ foreignKeys: opts?.fks ?? []
51
+ };
52
+ }
53
+ function model(table$1, fields, relations = {}) {
54
+ return {
55
+ storage: { table: table$1 },
56
+ fields,
57
+ relations
58
+ };
59
+ }
60
+ function storage(tables) {
61
+ return { tables };
62
+ }
63
+ function contract(opts) {
64
+ return {
65
+ schemaVersion: opts.schemaVersion ?? "1",
66
+ target: opts.target,
67
+ targetFamily: opts.targetFamily ?? "sql",
68
+ storageHash: opts.storageHash,
69
+ ...opts.executionHash !== void 0 && { executionHash: opts.executionHash },
70
+ storage: opts.storage,
71
+ models: opts.models ?? {},
72
+ relations: opts.relations ?? {},
73
+ mappings: opts.mappings ?? {},
74
+ ...opts.profileHash !== void 0 && { profileHash: opts.profileHash },
75
+ ...opts.capabilities !== void 0 && { capabilities: opts.capabilities },
76
+ ...opts.extensionPacks !== void 0 && { extensionPacks: opts.extensionPacks },
77
+ ...opts.meta !== void 0 && { meta: opts.meta },
78
+ ...opts.sources !== void 0 && { sources: opts.sources }
79
+ };
80
+ }
81
+
82
+ //#endregion
83
+ export { col, contract, fk, index, model, pk, storage, table, unique };
84
+ //# sourceMappingURL=factories.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"factories.mjs","names":[],"sources":["../src/factories.ts"],"sourcesContent":["import type {\n ExecutionHashBase,\n ProfileHashBase,\n StorageHashBase,\n} from '@prisma-next/contract/types';\nimport type {\n ForeignKey,\n ForeignKeyOptions,\n ForeignKeyReferences,\n Index,\n ModelDefinition,\n ModelField,\n ModelStorage,\n PrimaryKey,\n SqlContract,\n SqlMappings,\n SqlStorage,\n StorageColumn,\n StorageTable,\n UniqueConstraint,\n} from './types';\nimport { applyFkDefaults } from './types';\n\n/**\n * Creates a StorageColumn with nativeType and codecId.\n *\n * @param nativeType - Native database type identifier (e.g., 'int4', 'text', 'vector')\n * @param codecId - Codec identifier (e.g., 'pg/int4@1', 'pg/text@1')\n * @param nullable - Whether the column is nullable (default: false)\n * @returns StorageColumn with nativeType and codecId\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 table: string,\n fields: Record<string, ModelField>,\n relations: Record<string, unknown> = {},\n): ModelDefinition {\n const storage: ModelStorage = { table };\n return {\n storage,\n fields,\n relations,\n };\n}\n\nexport function storage(tables: Record<string, StorageTable>): SqlStorage {\n return { tables };\n}\n\nexport function contract<\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n>(opts: {\n target: string;\n storageHash: TStorageHash;\n executionHash?: TExecutionHash;\n storage: SqlStorage;\n models?: Record<string, ModelDefinition>;\n relations?: Record<string, unknown>;\n mappings?: Partial<SqlMappings>;\n schemaVersion?: '1';\n targetFamily?: 'sql';\n profileHash?: TProfileHash;\n capabilities?: Record<string, Record<string, boolean>>;\n extensionPacks?: Record<string, unknown>;\n meta?: Record<string, unknown>;\n sources?: Record<string, unknown>;\n}): SqlContract<\n SqlStorage,\n Record<string, unknown>,\n Record<string, unknown>,\n SqlMappings,\n TStorageHash,\n TExecutionHash,\n TProfileHash\n> {\n return {\n schemaVersion: opts.schemaVersion ?? '1',\n target: opts.target,\n targetFamily: opts.targetFamily ?? 'sql',\n storageHash: opts.storageHash,\n ...(opts.executionHash !== undefined && { executionHash: opts.executionHash }),\n storage: opts.storage,\n models: opts.models ?? {},\n relations: opts.relations ?? {},\n mappings: (opts.mappings ?? {}) as SqlMappings,\n ...(opts.profileHash !== undefined && { profileHash: opts.profileHash }),\n ...(opts.capabilities !== undefined && { capabilities: opts.capabilities }),\n ...(opts.extensionPacks !== undefined && { extensionPacks: opts.extensionPacks }),\n ...(opts.meta !== undefined && { meta: opts.meta }),\n ...(opts.sources !== undefined && { sources: opts.sources as Record<string, unknown> }),\n } as SqlContract<\n SqlStorage,\n Record<string, unknown>,\n Record<string, unknown>,\n SqlMappings,\n TStorageHash,\n TExecutionHash,\n TProfileHash\n >;\n}\n"],"mappings":";;;;;;;;;;;AA+BA,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,SACA,QACA,YAAqC,EAAE,EACtB;AAEjB,QAAO;EACL,SAF4B,EAAE,gBAAO;EAGrC;EACA;EACD;;AAGH,SAAgB,QAAQ,QAAkD;AACxE,QAAO,EAAE,QAAQ;;AAGnB,SAAgB,SAId,MAuBA;AACA,QAAO;EACL,eAAe,KAAK,iBAAiB;EACrC,QAAQ,KAAK;EACb,cAAc,KAAK,gBAAgB;EACnC,aAAa,KAAK;EAClB,GAAI,KAAK,kBAAkB,UAAa,EAAE,eAAe,KAAK,eAAe;EAC7E,SAAS,KAAK;EACd,QAAQ,KAAK,UAAU,EAAE;EACzB,WAAW,KAAK,aAAa,EAAE;EAC/B,UAAW,KAAK,YAAY,EAAE;EAC9B,GAAI,KAAK,gBAAgB,UAAa,EAAE,aAAa,KAAK,aAAa;EACvE,GAAI,KAAK,iBAAiB,UAAa,EAAE,cAAc,KAAK,cAAc;EAC1E,GAAI,KAAK,mBAAmB,UAAa,EAAE,gBAAgB,KAAK,gBAAgB;EAChF,GAAI,KAAK,SAAS,UAAa,EAAE,MAAM,KAAK,MAAM;EAClD,GAAI,KAAK,YAAY,UAAa,EAAE,SAAS,KAAK,SAAoC;EACvF"}
@@ -0,0 +1,13 @@
1
+ //#region src/pack-types.d.ts
2
+ /**
3
+ * Storage type metadata for pack refs.
4
+ */
5
+ interface StorageTypeMetadata {
6
+ readonly typeId: string;
7
+ readonly familyId: string;
8
+ readonly targetId: string;
9
+ readonly nativeType?: string;
10
+ }
11
+ //#endregion
12
+ export { type StorageTypeMetadata };
13
+ //# sourceMappingURL=pack-types.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pack-types.d.mts","names":[],"sources":["../src/pack-types.ts"],"sourcesContent":[],"mappings":";;AAGA;;UAAiB,mBAAA"}
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,145 @@
1
+ import { ColumnDefault, ContractBase, ExecutionHashBase, ExecutionSection, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
2
+
3
+ //#region src/types.d.ts
4
+
5
+ /**
6
+ * A column definition in storage.
7
+ *
8
+ * `typeParams` is optional because most columns use non-parameterized types.
9
+ * Columns with parameterized types can either inline `typeParams` or reference
10
+ * a named {@link StorageTypeInstance} via `typeRef`.
11
+ */
12
+ type StorageColumn = {
13
+ readonly nativeType: string;
14
+ readonly codecId: string;
15
+ readonly nullable: boolean;
16
+ /**
17
+ * Opaque, codec-owned JS/type parameters.
18
+ * The codec that owns `codecId` defines the shape and semantics.
19
+ * Mutually exclusive with `typeRef`.
20
+ */
21
+ readonly typeParams?: Record<string, unknown>;
22
+ /**
23
+ * Reference to a named type instance in `storage.types`.
24
+ * Mutually exclusive with `typeParams`.
25
+ */
26
+ readonly typeRef?: string;
27
+ /**
28
+ * Default value for the column.
29
+ * Can be a literal value or database function.
30
+ */
31
+ readonly default?: ColumnDefault;
32
+ };
33
+ type PrimaryKey = {
34
+ readonly columns: readonly string[];
35
+ readonly name?: string;
36
+ };
37
+ type UniqueConstraint = {
38
+ readonly columns: readonly string[];
39
+ readonly name?: string;
40
+ };
41
+ type Index = {
42
+ readonly columns: readonly string[];
43
+ readonly name?: string;
44
+ };
45
+ type ForeignKeyReferences = {
46
+ readonly table: string;
47
+ readonly columns: readonly string[];
48
+ };
49
+ type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
50
+ type ForeignKeyOptions = {
51
+ readonly name?: string;
52
+ readonly onDelete?: ReferentialAction;
53
+ readonly onUpdate?: ReferentialAction;
54
+ };
55
+ type ForeignKey = {
56
+ readonly columns: readonly string[];
57
+ readonly references: ForeignKeyReferences;
58
+ readonly name?: string;
59
+ readonly onDelete?: ReferentialAction;
60
+ readonly onUpdate?: ReferentialAction;
61
+ /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
62
+ readonly constraint: boolean;
63
+ /** Whether to emit a backing index for the FK columns. */
64
+ readonly index: boolean;
65
+ };
66
+ type StorageTable = {
67
+ readonly columns: Record<string, StorageColumn>;
68
+ readonly primaryKey?: PrimaryKey;
69
+ readonly uniques: ReadonlyArray<UniqueConstraint>;
70
+ readonly indexes: ReadonlyArray<Index>;
71
+ readonly foreignKeys: ReadonlyArray<ForeignKey>;
72
+ };
73
+ /**
74
+ * A named, parameterized type instance.
75
+ * These are registered in `storage.types` for reuse across columns
76
+ * and to enable ergonomic schema surfaces like `schema.types.MyType`.
77
+ *
78
+ * Unlike {@link StorageColumn}, `typeParams` is required here because
79
+ * `StorageTypeInstance` exists specifically to define reusable parameterized types.
80
+ * A type instance without parameters would be redundant—columns can reference
81
+ * the codec directly via `codecId`.
82
+ */
83
+ type StorageTypeInstance = {
84
+ readonly codecId: string;
85
+ readonly nativeType: string;
86
+ readonly typeParams: Record<string, unknown>;
87
+ };
88
+ type SqlStorage = {
89
+ readonly tables: Record<string, StorageTable>;
90
+ /**
91
+ * Named type instances for parameterized/custom types.
92
+ * Columns can reference these via `typeRef`.
93
+ */
94
+ readonly types?: Record<string, StorageTypeInstance>;
95
+ };
96
+ type ModelField = {
97
+ readonly column: string;
98
+ };
99
+ type ModelStorage = {
100
+ readonly table: string;
101
+ };
102
+ type ModelDefinition = {
103
+ readonly storage: ModelStorage;
104
+ readonly fields: Record<string, ModelField>;
105
+ readonly relations: Record<string, unknown>;
106
+ };
107
+ type SqlMappings = {
108
+ readonly modelToTable?: Record<string, string>;
109
+ readonly tableToModel?: Record<string, string>;
110
+ readonly fieldToColumn?: Record<string, Record<string, string>>;
111
+ readonly columnToField?: Record<string, Record<string, string>>;
112
+ readonly codecTypes: Record<string, {
113
+ readonly output: unknown;
114
+ }>;
115
+ readonly operationTypes: Record<string, Record<string, unknown>>;
116
+ };
117
+ declare const DEFAULT_FK_CONSTRAINT = true;
118
+ declare const DEFAULT_FK_INDEX = true;
119
+ /**
120
+ * Resolves foreign key `constraint` and `index` fields to their effective boolean values,
121
+ * falling back through optional override defaults, then to the global defaults.
122
+ */
123
+ declare function applyFkDefaults(fk: {
124
+ constraint?: boolean | undefined;
125
+ index?: boolean | undefined;
126
+ }, overrideDefaults?: {
127
+ constraint?: boolean | undefined;
128
+ index?: boolean | undefined;
129
+ }): {
130
+ constraint: boolean;
131
+ index: boolean;
132
+ };
133
+ type SqlContract<S extends SqlStorage = SqlStorage, M extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>, Map extends SqlMappings = SqlMappings, TStorageHash extends StorageHashBase<string> = StorageHashBase<string>, TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>, TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>> = ContractBase<TStorageHash, TExecutionHash, TProfileHash> & {
134
+ readonly targetFamily: string;
135
+ readonly storage: S;
136
+ readonly models: M;
137
+ readonly relations: R;
138
+ readonly mappings: Map;
139
+ readonly execution?: ExecutionSection;
140
+ };
141
+ type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['codecTypes'];
142
+ type ExtractOperationTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['operationTypes'];
143
+ //#endregion
144
+ export { StorageColumn as _, ForeignKey as a, UniqueConstraint as b, Index as c, ModelStorage as d, PrimaryKey as f, SqlStorage as g, SqlMappings as h, ExtractOperationTypes as i, ModelDefinition as l, SqlContract as m, DEFAULT_FK_INDEX as n, ForeignKeyOptions as o, ReferentialAction as p, ExtractCodecTypes as r, ForeignKeyReferences as s, DEFAULT_FK_CONSTRAINT as t, ModelField as u, StorageTable as v, applyFkDefaults as x, StorageTypeInstance as y };
145
+ //# sourceMappingURL=types-T6o5-ZB3.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-T6o5-ZB3.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAgBA;AAsBA;AAKA;AAKA;AAKA;AAKY,KA1CA,aAAA,GA0CiB;EAEjB,SAAA,UAAA,EAAiB,MAAA;EAMjB,SAAA,OAAU,EAAA,MAAA;EAEC,SAAA,QAAA,EAAA,OAAA;EAED;;;AAQtB;;EACoB,SAAA,UAAA,CAAA,E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EA5EC,UA4ED;EAA0B,SAAA,OAAA,EA3E7B,aA2E6B,CA3Ef,gBA2Ee,CAAA;EACxB,SAAA,OAAA,EA3EL,aA2EK,CA3ES,KA2ET,CAAA;EAA4B,SAAA,WAAA,EA1E7B,aA0E6B,CA1Ef,UA0Ee,CAAA;CAC9B;;;;;;;;;;;AAOgB,KArE3B,mBAAA,GAqE2B;EAG3B,SAAA,OAAA,EAAA,MAAiB;EAA+B,SAAA,UAAA,EAAA,MAAA;EAAZ,SAAA,UAAA,EArEzB,MAqEyB,CAAA,MAAA,EAAA,OAAA,CAAA;CAC9C;AAAS,KAnEC,UAAA,GAmED;EAEC,SAAA,MAAA,EApEO,MAoEP,CAAqB,MAAA,EApEC,YAoED,CAAA;EAA+B;;;;mBA/D7C,eAAe;;KAGtB,UAAA;;;KAIA,YAAA;;;KAIA,eAAA;oBACQ;mBACD,eAAe;sBACZ;;KAGV,WAAA;0BACc;0BACA;2BACC,eAAe;2BACf,eAAe;uBACnB;;;2BACI,eAAe;;cAG7B,qBAAA;cACA,gBAAA;;;;;iBAMG,eAAA;;;;;;;;;;KAUJ,sBACA,aAAa,sBACb,0BAA0B,mCAC1B,0BAA0B,qCACxB,cAAc,kCACL,0BAA0B,gDACxB,4BAA4B,gDAC9B,0BAA0B,2BAC7C,aAAa,cAAc,gBAAgB;;oBAE3B;mBACD;sBACG;qBACD;uBACE;;KAGX,oCAAoC,YAAY,eAC1D;KAEU,wCAAwC,YAAY,eAC9D"}
@@ -0,0 +1,17 @@
1
+ //#region src/types.ts
2
+ const DEFAULT_FK_CONSTRAINT = true;
3
+ const DEFAULT_FK_INDEX = true;
4
+ /**
5
+ * Resolves foreign key `constraint` and `index` fields to their effective boolean values,
6
+ * falling back through optional override defaults, then to the global defaults.
7
+ */
8
+ function applyFkDefaults(fk, overrideDefaults) {
9
+ return {
10
+ constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,
11
+ index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX
12
+ };
13
+ }
14
+
15
+ //#endregion
16
+ export { DEFAULT_FK_INDEX as n, applyFkDefaults as r, DEFAULT_FK_CONSTRAINT as t };
17
+ //# sourceMappingURL=types-kacOgEya.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-kacOgEya.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n ColumnDefault,\n ContractBase,\n ExecutionHashBase,\n ExecutionSection,\n ProfileHashBase,\n StorageHashBase,\n} from '@prisma-next/contract/types';\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};\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 = {\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 ModelField = {\n readonly column: string;\n};\n\nexport type ModelStorage = {\n readonly table: string;\n};\n\nexport type ModelDefinition = {\n readonly storage: ModelStorage;\n readonly fields: Record<string, ModelField>;\n readonly relations: Record<string, unknown>;\n};\n\nexport type SqlMappings = {\n readonly modelToTable?: Record<string, string>;\n readonly tableToModel?: Record<string, string>;\n readonly fieldToColumn?: Record<string, Record<string, string>>;\n readonly columnToField?: Record<string, Record<string, string>>;\n readonly codecTypes: Record<string, { readonly output: unknown }>;\n readonly operationTypes: Record<string, Record<string, unknown>>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\n/**\n * Resolves foreign key `constraint` and `index` fields to their effective boolean values,\n * falling back through optional override defaults, then to the global defaults.\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 SqlContract<\n S extends SqlStorage = SqlStorage,\n M extends Record<string, unknown> = Record<string, unknown>,\n R extends Record<string, unknown> = Record<string, unknown>,\n Map extends SqlMappings = SqlMappings,\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n> = ContractBase<TStorageHash, TExecutionHash, TProfileHash> & {\n readonly targetFamily: string;\n readonly storage: S;\n readonly models: M;\n readonly relations: R;\n readonly mappings: Map;\n readonly execution?: ExecutionSection;\n};\n\nexport type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> =\n TContract['mappings']['codecTypes'];\n\nexport type ExtractOperationTypes<TContract extends SqlContract<SqlStorage>> =\n TContract['mappings']['operationTypes'];\n"],"mappings":";AAsIA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;;;;;AAMhC,SAAgB,gBACd,IACA,kBACyC;AACzC,QAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAc;EAC7D,OAAO,GAAG,SAAS,kBAAkB,SAAS;EAC/C"}
@@ -0,0 +1,2 @@
1
+ import { _ as StorageColumn, a as ForeignKey, b as UniqueConstraint, c as Index, d as ModelStorage, f as PrimaryKey, g as SqlStorage, h as SqlMappings, i as ExtractOperationTypes, l as ModelDefinition, m as SqlContract, n as DEFAULT_FK_INDEX, o as ForeignKeyOptions, p as ReferentialAction, r as ExtractCodecTypes, s as ForeignKeyReferences, t as DEFAULT_FK_CONSTRAINT, u as ModelField, v as StorageTable, x as applyFkDefaults, y as StorageTypeInstance } from "./types-T6o5-ZB3.mjs";
2
+ export { DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractOperationTypes, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type ModelDefinition, type ModelField, type ModelStorage, type PrimaryKey, type ReferentialAction, type SqlContract, type SqlMappings, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type UniqueConstraint, applyFkDefaults };
package/dist/types.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { n as DEFAULT_FK_INDEX, r as applyFkDefaults, t as DEFAULT_FK_CONSTRAINT } from "./types-kacOgEya.mjs";
2
+
3
+ export { DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, applyFkDefaults };
@@ -0,0 +1,11 @@
1
+ import { _ as StorageColumn, g as SqlStorage, m as SqlContract } from "./types-T6o5-ZB3.mjs";
2
+ import "@prisma-next/contract/types";
3
+
4
+ //#region src/validate.d.ts
5
+ declare function isBigIntColumn(column: StorageColumn): boolean;
6
+ declare function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contract: T): T;
7
+ declare function normalizeContract(contract: unknown): SqlContract<SqlStorage>;
8
+ declare function validateContract<TContract extends SqlContract<SqlStorage>>(value: unknown): TContract;
9
+ //#endregion
10
+ export { decodeContractDefaults, isBigIntColumn, normalizeContract, validateContract };
11
+ //# sourceMappingURL=validate.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"sourcesContent":[],"mappings":";;;;iBA6PgB,cAAA,SAAuB;AAAvB,iBAkCA,sBAlCuB,CAAa,UAkCH,WAlCG,CAkCS,UAlCT,CAAA,CAAA,CAAA,QAAA,EAkCgC,CAlChC,CAAA,EAkCoC,CAlCpC;AAkCpC,iBAqDA,iBAAA,CArDsB,QAAA,EAAA,OAAA,CAAA,EAqDgB,WArDhB,CAqD4B,UArD5B,CAAA;AAAuB,iBAwI7C,gBAxI6C,CAAA,kBAwIV,WAxIU,CAwIE,UAxIF,CAAA,CAAA,CAAA,KAAA,EAAA,OAAA,CAAA,EA0I1D,SA1I0D"}