@prisma-next/sql-contract 0.3.0-dev.4 → 0.3.0-dev.40

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 (46) hide show
  1. package/README.md +40 -10
  2. package/dist/factories.d.mts +49 -0
  3. package/dist/factories.d.mts.map +1 -0
  4. package/dist/factories.mjs +82 -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-DTFobApb.d.mts +137 -0
  10. package/dist/types-DTFobApb.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 +8 -0
  16. package/dist/validate.d.mts.map +1 -0
  17. package/dist/validate.mjs +179 -0
  18. package/dist/validate.mjs.map +1 -0
  19. package/dist/validators-Dfw5_HSi.mjs +162 -0
  20. package/dist/validators-Dfw5_HSi.mjs.map +1 -0
  21. package/dist/{exports/validators.d.ts → validators.d.mts} +17 -4
  22. package/dist/validators.d.mts.map +1 -0
  23. package/dist/validators.mjs +3 -0
  24. package/package.json +26 -28
  25. package/src/exports/factories.ts +11 -0
  26. package/src/exports/pack-types.ts +1 -0
  27. package/src/exports/types.ts +20 -0
  28. package/src/exports/validate.ts +1 -0
  29. package/src/exports/validators.ts +1 -0
  30. package/src/factories.ts +162 -0
  31. package/src/index.ts +4 -0
  32. package/src/pack-types.ts +9 -0
  33. package/src/types.ts +163 -0
  34. package/src/validate.ts +335 -0
  35. package/src/validators.ts +218 -0
  36. package/dist/exports/factories.d.ts +0 -41
  37. package/dist/exports/factories.js +0 -83
  38. package/dist/exports/factories.js.map +0 -1
  39. package/dist/exports/pack-types.d.ts +0 -11
  40. package/dist/exports/pack-types.js +0 -1
  41. package/dist/exports/pack-types.js.map +0 -1
  42. package/dist/exports/types.d.ts +0 -70
  43. package/dist/exports/types.js +0 -1
  44. package/dist/exports/types.js.map +0 -1
  45. package/dist/exports/validators.js +0 -96
  46. package/dist/exports/validators.js.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,29 @@ 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
+
46
61
  ### Validators
47
62
 
48
63
  Validate contract structures using Arktype validators:
49
64
 
50
65
  ```typescript
51
- import { validateSqlContract, validateStorage, validateModel } from '@prisma-next/sql-contract/exports/validators';
66
+ import { validateSqlContract, validateStorage, validateModel } from '@prisma-next/sql-contract/validators';
52
67
 
53
68
  // Validate a complete contract
54
69
  const contract = validateSqlContract<Contract>(contractJson);
@@ -60,12 +75,25 @@ const storage = validateStorage(storageJson);
60
75
  const model = validateModel(modelJson);
61
76
  ```
62
77
 
78
+ Validate JSON-emitted contracts with mapping + logic checks:
79
+
80
+ ```typescript
81
+ import { validateContract } from '@prisma-next/sql-contract/validate';
82
+
83
+ const contract = validateContract<Contract>(contractJson);
84
+ ```
85
+
86
+ Mapping overrides in `contract.mappings` follow strict pair semantics:
87
+ - `modelToTable` and `tableToModel` must either both be omitted (auto-computed) or both be provided as inverse maps.
88
+ - `fieldToColumn` and `columnToField` must either both be omitted (auto-computed) or both be provided as inverse maps.
89
+ - `codecTypes` and `operationTypes` are merged additively on top of defaults.
90
+
63
91
  ### Factories
64
92
 
65
93
  Use factory functions to construct contract IR structures in tests:
66
94
 
67
95
  ```typescript
68
- import { col, table, storage, model, contract, pk, unique, index, fk } from '@prisma-next/sql-contract/exports/factories';
96
+ import { col, table, storage, model, contract, pk, unique, index, fk } from '@prisma-next/sql-contract/factories';
69
97
 
70
98
  // Create a column (nativeType, codecId, nullable)
71
99
  const idColumn = col('int4', 'pg/int4@1', false);
@@ -95,7 +123,7 @@ const userModel = model('user', {
95
123
  // Create a complete contract
96
124
  const c = contract({
97
125
  target: 'postgres',
98
- coreHash: 'sha256:abc123',
126
+ storageHash: 'sha256:abc123',
99
127
  storage: s,
100
128
  models: { User: userModel },
101
129
  });
@@ -103,9 +131,11 @@ const c = contract({
103
131
 
104
132
  ## Exports
105
133
 
106
- - `./exports/types`: TypeScript type definitions
107
- - `./exports/validators`: Arktype validators for structural validation
108
- - `./exports/factories`: Factory functions for constructing contract IR
134
+ - `./types`: TypeScript type definitions
135
+ - `./validators`: Arktype validators for structural validation
136
+ - `./validate`: Shared `validateContract` helper for JSON imports
137
+ - `./factories`: Factory functions for constructing contract IR
138
+ - `./pack-types`: Shared extension/pack typing helpers
109
139
 
110
140
  ## Architecture
111
141
 
@@ -0,0 +1,49 @@
1
+ import { a as ForeignKey, c as ModelDefinition, d as PrimaryKey, f as SqlContract, g as StorageTable, h as StorageColumn, l as ModelField, m as SqlStorage, p as SqlMappings, s as Index, v as UniqueConstraint } from "./types-DTFobApb.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?: {
19
+ name?: string;
20
+ constraint?: boolean;
21
+ index?: boolean;
22
+ }): ForeignKey;
23
+ declare function table(columns: Record<string, StorageColumn>, opts?: {
24
+ pk?: PrimaryKey;
25
+ uniques?: readonly UniqueConstraint[];
26
+ indexes?: readonly Index[];
27
+ fks?: readonly ForeignKey[];
28
+ }): StorageTable;
29
+ declare function model(table: string, fields: Record<string, ModelField>, relations?: Record<string, unknown>): ModelDefinition;
30
+ declare function storage(tables: Record<string, StorageTable>): SqlStorage;
31
+ declare function contract<TStorageHash extends StorageHashBase<string> = StorageHashBase<string>, TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>, TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>>(opts: {
32
+ target: string;
33
+ storageHash: TStorageHash;
34
+ executionHash?: TExecutionHash;
35
+ storage: SqlStorage;
36
+ models?: Record<string, ModelDefinition>;
37
+ relations?: Record<string, unknown>;
38
+ mappings?: Partial<SqlMappings>;
39
+ schemaVersion?: '1';
40
+ targetFamily?: 'sql';
41
+ profileHash?: TProfileHash;
42
+ capabilities?: Record<string, Record<string, boolean>>;
43
+ extensionPacks?: Record<string, unknown>;
44
+ meta?: Record<string, unknown>;
45
+ sources?: Record<string, unknown>;
46
+ }): SqlContract<SqlStorage, Record<string, unknown>, Record<string, unknown>, SqlMappings, TStorageHash, TExecutionHash, TProfileHash>;
47
+ //#endregion
48
+ export { col, contract, fk, index, model, pk, storage, table, unique };
49
+ //# sourceMappingURL=factories.d.mts.map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@@
1
+ import { r as applyFkDefaults } from "./types-kacOgEya.mjs";
2
+
3
+ //#region src/factories.ts
4
+ /**
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
+ ...applyFkDefaults({
36
+ constraint: opts?.constraint,
37
+ index: opts?.index
38
+ }),
39
+ ...opts?.name !== void 0 && { name: opts.name }
40
+ };
41
+ }
42
+ function table(columns, opts) {
43
+ return {
44
+ columns,
45
+ ...opts?.pk !== void 0 && { primaryKey: opts.pk },
46
+ uniques: opts?.uniques ?? [],
47
+ indexes: opts?.indexes ?? [],
48
+ foreignKeys: opts?.fks ?? []
49
+ };
50
+ }
51
+ function model(table$1, fields, relations = {}) {
52
+ return {
53
+ storage: { table: table$1 },
54
+ fields,
55
+ relations
56
+ };
57
+ }
58
+ function storage(tables) {
59
+ return { tables };
60
+ }
61
+ function contract(opts) {
62
+ return {
63
+ schemaVersion: opts.schemaVersion ?? "1",
64
+ target: opts.target,
65
+ targetFamily: opts.targetFamily ?? "sql",
66
+ storageHash: opts.storageHash,
67
+ ...opts.executionHash !== void 0 && { executionHash: opts.executionHash },
68
+ storage: opts.storage,
69
+ models: opts.models ?? {},
70
+ relations: opts.relations ?? {},
71
+ mappings: opts.mappings ?? {},
72
+ ...opts.profileHash !== void 0 && { profileHash: opts.profileHash },
73
+ ...opts.capabilities !== void 0 && { capabilities: opts.capabilities },
74
+ ...opts.extensionPacks !== void 0 && { extensionPacks: opts.extensionPacks },
75
+ ...opts.meta !== void 0 && { meta: opts.meta },
76
+ ...opts.sources !== void 0 && { sources: opts.sources }
77
+ };
78
+ }
79
+
80
+ //#endregion
81
+ export { col, contract, fk, index, model, pk, storage, table, unique };
82
+ //# 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 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?: { name?: string; constraint?: boolean; index?: boolean },\n): ForeignKey {\n const references: ForeignKeyReferences = {\n table: refTable,\n columns: refColumns,\n };\n return {\n columns,\n references,\n ...applyFkDefaults({ constraint: opts?.constraint, index: opts?.index }),\n ...(opts?.name !== undefined && { name: opts.name }),\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":";;;;;;;;;;;AA8BA,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;AAKZ,QAAO;EACL;EACA,YANuC;GACvC,OAAO;GACP,SAAS;GACV;EAIC,GAAG,gBAAgB;GAAE,YAAY,MAAM;GAAY,OAAO,MAAM;GAAO,CAAC;EACxE,GAAI,MAAM,SAAS,UAAa,EAAE,MAAM,KAAK,MAAM;EACpD;;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,137 @@
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 ForeignKey = {
50
+ readonly columns: readonly string[];
51
+ readonly references: ForeignKeyReferences;
52
+ readonly name?: string;
53
+ /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
54
+ readonly constraint: boolean;
55
+ /** Whether to emit a backing index for the FK columns. */
56
+ readonly index: boolean;
57
+ };
58
+ type StorageTable = {
59
+ readonly columns: Record<string, StorageColumn>;
60
+ readonly primaryKey?: PrimaryKey;
61
+ readonly uniques: ReadonlyArray<UniqueConstraint>;
62
+ readonly indexes: ReadonlyArray<Index>;
63
+ readonly foreignKeys: ReadonlyArray<ForeignKey>;
64
+ };
65
+ /**
66
+ * A named, parameterized type instance.
67
+ * These are registered in `storage.types` for reuse across columns
68
+ * and to enable ergonomic schema surfaces like `schema.types.MyType`.
69
+ *
70
+ * Unlike {@link StorageColumn}, `typeParams` is required here because
71
+ * `StorageTypeInstance` exists specifically to define reusable parameterized types.
72
+ * A type instance without parameters would be redundant—columns can reference
73
+ * the codec directly via `codecId`.
74
+ */
75
+ type StorageTypeInstance = {
76
+ readonly codecId: string;
77
+ readonly nativeType: string;
78
+ readonly typeParams: Record<string, unknown>;
79
+ };
80
+ type SqlStorage = {
81
+ readonly tables: Record<string, StorageTable>;
82
+ /**
83
+ * Named type instances for parameterized/custom types.
84
+ * Columns can reference these via `typeRef`.
85
+ */
86
+ readonly types?: Record<string, StorageTypeInstance>;
87
+ };
88
+ type ModelField = {
89
+ readonly column: string;
90
+ };
91
+ type ModelStorage = {
92
+ readonly table: string;
93
+ };
94
+ type ModelDefinition = {
95
+ readonly storage: ModelStorage;
96
+ readonly fields: Record<string, ModelField>;
97
+ readonly relations: Record<string, unknown>;
98
+ };
99
+ type SqlMappings = {
100
+ readonly modelToTable?: Record<string, string>;
101
+ readonly tableToModel?: Record<string, string>;
102
+ readonly fieldToColumn?: Record<string, Record<string, string>>;
103
+ readonly columnToField?: Record<string, Record<string, string>>;
104
+ readonly codecTypes: Record<string, {
105
+ readonly output: unknown;
106
+ }>;
107
+ readonly operationTypes: Record<string, Record<string, unknown>>;
108
+ };
109
+ declare const DEFAULT_FK_CONSTRAINT = true;
110
+ declare const DEFAULT_FK_INDEX = true;
111
+ /**
112
+ * Resolves foreign key `constraint` and `index` fields to their effective boolean values,
113
+ * falling back through optional override defaults, then to the global defaults.
114
+ */
115
+ declare function applyFkDefaults(fk: {
116
+ constraint?: boolean | undefined;
117
+ index?: boolean | undefined;
118
+ }, overrideDefaults?: {
119
+ constraint?: boolean | undefined;
120
+ index?: boolean | undefined;
121
+ }): {
122
+ constraint: boolean;
123
+ index: boolean;
124
+ };
125
+ 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> & {
126
+ readonly targetFamily: string;
127
+ readonly storage: S;
128
+ readonly models: M;
129
+ readonly relations: R;
130
+ readonly mappings: Map;
131
+ readonly execution?: ExecutionSection;
132
+ };
133
+ type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['codecTypes'];
134
+ type ExtractOperationTypes<TContract extends SqlContract<SqlStorage>> = TContract['mappings']['operationTypes'];
135
+ //#endregion
136
+ export { StorageTypeInstance as _, ForeignKey as a, ModelDefinition as c, PrimaryKey as d, SqlContract as f, StorageTable as g, StorageColumn as h, ExtractOperationTypes as i, ModelField as l, SqlStorage as m, DEFAULT_FK_INDEX as n, ForeignKeyReferences as o, SqlMappings as p, ExtractCodecTypes as r, Index as s, DEFAULT_FK_CONSTRAINT as t, ModelStorage as u, UniqueConstraint as v, applyFkDefaults as y };
137
+ //# sourceMappingURL=types-DTFobApb.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-DTFobApb.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAgBA;AAsBA;AAKA;AAKA;AAKA;AAKY,KA1CA,aAAA,GA4CW;EAQX,SAAA,UAAY,EAAA,MAAA;EACW,SAAA,OAAA,EAAA,MAAA;EAAf,SAAA,QAAA,EAAA,OAAA;EACI;;;;;EAGc,SAAA,UAAA,CAAA,EAhDd,MAgDc,CAAA,MAAA,EAAA,OAAA,CAAA;EAAd;;AAaxB;AAMA;EACkC,SAAA,OAAA,CAAA,EAAA,MAAA;EAAf;;;;EAQP,SAAA,OAAU,CAAA,EAlED,aAkEC;AAItB,CAAA;AAIY,KAvEA,UAAA,GAuEe;EACP,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EACc,SAAA,IAAA,CAAA,EAAA,MAAA;CAAf;AACG,KArEV,gBAAA,GAqEU;EAAM,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EAGhB,SAAA,IAAA,CAAW,EAAA,MAAA;CACG;AACA,KArEd,KAAA,GAqEc;EACgB,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EAAf,SAAA,IAAA,CAAA,EAAA,MAAA;CACe;AAAf,KAlEf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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 ForeignKey = {\n readonly columns: readonly string[];\n readonly references: ForeignKeyReferences;\n readonly name?: string;\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":";AA4HA,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 StorageTypeInstance, a as ForeignKey, c as ModelDefinition, d as PrimaryKey, f as SqlContract, g as StorageTable, h as StorageColumn, i as ExtractOperationTypes, l as ModelField, m as SqlStorage, n as DEFAULT_FK_INDEX, o as ForeignKeyReferences, p as SqlMappings, r as ExtractCodecTypes, s as Index, t as DEFAULT_FK_CONSTRAINT, u as ModelStorage, v as UniqueConstraint, y as applyFkDefaults } from "./types-DTFobApb.mjs";
2
+ export { DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractOperationTypes, type ForeignKey, type ForeignKeyReferences, type Index, type ModelDefinition, type ModelField, type ModelStorage, type PrimaryKey, 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,8 @@
1
+ import { f as SqlContract, m as SqlStorage } from "./types-DTFobApb.mjs";
2
+
3
+ //#region src/validate.d.ts
4
+ declare function normalizeContract(contract: unknown): SqlContract<SqlStorage>;
5
+ declare function validateContract<TContract extends SqlContract<SqlStorage>>(value: unknown): TContract;
6
+ //#endregion
7
+ export { normalizeContract, validateContract };
8
+ //# sourceMappingURL=validate.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"sourcesContent":[],"mappings":";;;iBA0OgB,iBAAA,qBAAsC,YAAY;iBAmFlD,mCAAmC,YAAY,8BAE5D"}