@prisma-next/sql-contract 0.3.0-dev.6 → 0.3.0-dev.62
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.
- package/LICENSE +201 -0
- package/README.md +79 -10
- package/dist/factories.d.mts +48 -0
- package/dist/factories.d.mts.map +1 -0
- package/dist/factories.mjs +84 -0
- package/dist/factories.mjs.map +1 -0
- package/dist/pack-types.d.mts +13 -0
- package/dist/pack-types.d.mts.map +1 -0
- package/dist/pack-types.mjs +1 -0
- package/dist/types-T6o5-ZB3.d.mts +145 -0
- package/dist/types-T6o5-ZB3.d.mts.map +1 -0
- package/dist/types-kacOgEya.mjs +17 -0
- package/dist/types-kacOgEya.mjs.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/dist/validate.d.mts +11 -0
- package/dist/validate.d.mts.map +1 -0
- package/dist/validate.mjs +244 -0
- package/dist/validate.mjs.map +1 -0
- package/dist/validators-Dz93b38w.mjs +214 -0
- package/dist/validators-Dz93b38w.mjs.map +1 -0
- package/dist/validators.d.mts +65 -0
- package/dist/validators.d.mts.map +1 -0
- package/dist/validators.mjs +3 -0
- package/package.json +24 -28
- package/src/exports/types.ts +5 -0
- package/src/exports/validate.ts +6 -0
- package/src/exports/validators.ts +1 -1
- package/src/factories.ts +41 -8
- package/src/index.ts +1 -0
- package/src/types.ts +88 -2
- package/src/validate.ts +448 -0
- package/src/validators.ts +161 -10
- package/dist/exports/factories.d.ts +0 -2
- package/dist/exports/factories.d.ts.map +0 -1
- package/dist/exports/factories.js +0 -83
- package/dist/exports/factories.js.map +0 -1
- package/dist/exports/pack-types.d.ts +0 -2
- package/dist/exports/pack-types.d.ts.map +0 -1
- package/dist/exports/pack-types.js +0 -1
- package/dist/exports/pack-types.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
- package/dist/exports/validators.d.ts +0 -2
- package/dist/exports/validators.d.ts.map +0 -1
- package/dist/exports/validators.js +0 -96
- package/dist/exports/validators.js.map +0 -1
- package/dist/factories.d.ts +0 -38
- package/dist/factories.d.ts.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/pack-types.d.ts +0 -10
- package/dist/pack-types.d.ts.map +0 -1
- package/dist/types.d.ts +0 -68
- package/dist/types.d.ts.map +0 -1
- package/dist/validators.d.ts +0 -35
- package/dist/validators.d.ts.map +0 -1
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { a as ForeignKey, g as SqlStorage, l as ModelDefinition, m as SqlContract, p as ReferentialAction, s as ForeignKeyReferences } from "./types-T6o5-ZB3.mjs";
|
|
2
|
+
import * as arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
|
|
3
|
+
import * as arktype_internal_variants_string_ts0 from "arktype/internal/variants/string.ts";
|
|
4
|
+
|
|
5
|
+
//#region src/validators.d.ts
|
|
6
|
+
type ColumnDefaultLiteral = {
|
|
7
|
+
readonly kind: 'literal';
|
|
8
|
+
readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;
|
|
9
|
+
};
|
|
10
|
+
type ColumnDefaultFunction = {
|
|
11
|
+
readonly kind: 'function';
|
|
12
|
+
readonly expression: string;
|
|
13
|
+
};
|
|
14
|
+
declare const ColumnDefaultLiteralSchema: arktype_internal_variants_object_ts0.ObjectType<ColumnDefaultLiteral, {}>;
|
|
15
|
+
declare const ColumnDefaultFunctionSchema: arktype_internal_variants_object_ts0.ObjectType<ColumnDefaultFunction, {}>;
|
|
16
|
+
declare const ColumnDefaultSchema: arktype_internal_variants_object_ts0.ObjectType<ColumnDefaultLiteral | ColumnDefaultFunction, {}>;
|
|
17
|
+
declare const ForeignKeyReferencesSchema: arktype_internal_variants_object_ts0.ObjectType<ForeignKeyReferences, {}>;
|
|
18
|
+
declare const ReferentialActionSchema: arktype_internal_variants_string_ts0.StringType<ReferentialAction, {}>;
|
|
19
|
+
declare const ForeignKeySchema: arktype_internal_variants_object_ts0.ObjectType<ForeignKey, {}>;
|
|
20
|
+
/**
|
|
21
|
+
* Validates the structural shape of SqlStorage using Arktype.
|
|
22
|
+
*
|
|
23
|
+
* @param value - The storage value to validate
|
|
24
|
+
* @returns The validated storage if structure is valid
|
|
25
|
+
* @throws Error if the storage structure is invalid
|
|
26
|
+
*/
|
|
27
|
+
declare function validateStorage(value: unknown): SqlStorage;
|
|
28
|
+
/**
|
|
29
|
+
* Validates the structural shape of ModelDefinition using Arktype.
|
|
30
|
+
*
|
|
31
|
+
* @param value - The model value to validate
|
|
32
|
+
* @returns The validated model if structure is valid
|
|
33
|
+
* @throws Error if the model structure is invalid
|
|
34
|
+
*/
|
|
35
|
+
declare function validateModel(value: unknown): ModelDefinition;
|
|
36
|
+
/**
|
|
37
|
+
* Validates the structural shape of a SqlContract using Arktype.
|
|
38
|
+
*
|
|
39
|
+
* **Responsibility: Validation Only**
|
|
40
|
+
* This function validates that the contract has the correct structure and types.
|
|
41
|
+
* It does NOT normalize the contract - normalization must happen in the contract builder.
|
|
42
|
+
*
|
|
43
|
+
* The contract passed to this function must already be normalized (all required fields present).
|
|
44
|
+
* If normalization is needed, it should be done by the contract builder before calling this function.
|
|
45
|
+
*
|
|
46
|
+
* This ensures all required fields are present and have the correct types.
|
|
47
|
+
*
|
|
48
|
+
* @param value - The contract value to validate (typically from a JSON import)
|
|
49
|
+
* @returns The validated contract if structure is valid
|
|
50
|
+
* @throws Error if the contract structure is invalid
|
|
51
|
+
*/
|
|
52
|
+
declare function validateSqlContract<T extends SqlContract<SqlStorage>>(value: unknown): T;
|
|
53
|
+
/**
|
|
54
|
+
* Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.
|
|
55
|
+
*
|
|
56
|
+
* Returns an array of human-readable error strings. Empty array = valid.
|
|
57
|
+
*
|
|
58
|
+
* Currently checks:
|
|
59
|
+
* - `setNull` referential action on a non-nullable FK column (would fail at runtime)
|
|
60
|
+
* - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)
|
|
61
|
+
*/
|
|
62
|
+
declare function validateStorageSemantics(storage: SqlStorage): string[];
|
|
63
|
+
//#endregion
|
|
64
|
+
export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ForeignKeyReferencesSchema, ForeignKeySchema, ReferentialActionSchema, validateModel, validateSqlContract, validateStorage, validateStorageSemantics };
|
|
65
|
+
//# sourceMappingURL=validators.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"sourcesContent":[],"mappings":";;;;;KAgBK,oBAAA;;8CAEyC;;AAJ7B,KAMZ,qBAAA,GAJoB;EAIpB,SAAA,IAAA,EAAA,UAAqB;EAMb,SAAA,UAAA,EAAA,MAAA;AAKb,CAAA;AAKa,cAVA,0BAUgF,EAVtD,oCAAA,CAAA,UAUsD,CAVtD,oBAUsD,EAAA,CAAA,CAAA,CAAA;AAA7D,cALnB,2BAKmB,EALQ,oCAAA,CAAA,UAKR,CALQ,qBAKR,EAAA,CAAA,CAAA,CAAA;AAAA,cAAnB,mBAAmB,EAAA,oCAAA,CAAA,UAAA,CAAA,oBAAA,GAAA,qBAAA,EAAA,CAAA,CAAA,CAAA;AAAA,cAgEnB,0BAhEmB,EAgEO,oCAAA,CAAA,UAhEP,CAgEO,oBAhEP,EAAA,CAAA,CAAA,CAAA;AAAA,cAqEnB,uBArEmB,EAqEI,oCAAA,CAAA,UArEJ,CAqEI,iBArEJ,EAAA,CAAA,CAAA,CAAA;AAgEnB,cASA,gBANX,EAM2B,oCAAA,CAAA,UATU,CASV,UATU,EAAA,CAAA,CAAA,CAAA;AAKvC;AAIA;AAwFA;AAgBA;AAyBA;;;AAAwF,iBAzCxE,eAAA,CAyCwE,KAAA,EAAA,OAAA,CAAA,EAzCvC,UAyCuC;;AAiCxF;;;;;;iBA1DgB,aAAA,kBAA+B;;;;;;;;;;;;;;;;;iBAyB/B,8BAA8B,YAAY,8BAA8B;;;;;;;;;;iBAiCxE,wBAAA,UAAkC"}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { a as ForeignKeySchema, c as validateSqlContract, i as ForeignKeyReferencesSchema, l as validateStorage, n as ColumnDefaultLiteralSchema, o as ReferentialActionSchema, r as ColumnDefaultSchema, s as validateModel, t as ColumnDefaultFunctionSchema, u as validateStorageSemantics } from "./validators-Dz93b38w.mjs";
|
|
2
|
+
|
|
3
|
+
export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ForeignKeyReferencesSchema, ForeignKeySchema, ReferentialActionSchema, validateModel, validateSqlContract, validateStorage, validateStorageSemantics };
|
package/package.json
CHANGED
|
@@ -1,50 +1,46 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.62",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"sideEffects": false,
|
|
6
6
|
"description": "SQL contract types, validators, and IR factories for Prisma Next",
|
|
7
7
|
"dependencies": {
|
|
8
8
|
"arktype": "^2.1.25",
|
|
9
|
-
"@prisma-next/contract": "0.3.0-dev.
|
|
9
|
+
"@prisma-next/contract": "0.3.0-dev.62"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
|
-
"
|
|
13
|
-
"tsup": "8.5.1",
|
|
12
|
+
"tsdown": "0.18.4",
|
|
14
13
|
"typescript": "5.9.3",
|
|
15
|
-
"vitest": "4.0.
|
|
16
|
-
"@prisma-next/
|
|
14
|
+
"vitest": "4.0.17",
|
|
15
|
+
"@prisma-next/tsconfig": "0.0.0",
|
|
16
|
+
"@prisma-next/test-utils": "0.0.1",
|
|
17
|
+
"@prisma-next/tsdown": "0.0.0"
|
|
17
18
|
},
|
|
18
19
|
"files": [
|
|
19
20
|
"dist",
|
|
20
21
|
"src"
|
|
21
22
|
],
|
|
22
23
|
"exports": {
|
|
23
|
-
"./
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
"./validators":
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
"
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
"./pack-types": {
|
|
36
|
-
"types": "./dist/exports/pack-types.d.ts",
|
|
37
|
-
"import": "./dist/exports/pack-types.js"
|
|
38
|
-
}
|
|
24
|
+
"./factories": "./dist/factories.mjs",
|
|
25
|
+
"./pack-types": "./dist/pack-types.mjs",
|
|
26
|
+
"./types": "./dist/types.mjs",
|
|
27
|
+
"./validate": "./dist/validate.mjs",
|
|
28
|
+
"./validators": "./dist/validators.mjs",
|
|
29
|
+
"./package.json": "./package.json"
|
|
30
|
+
},
|
|
31
|
+
"repository": {
|
|
32
|
+
"type": "git",
|
|
33
|
+
"url": "https://github.com/prisma/prisma-next.git",
|
|
34
|
+
"directory": "packages/2-sql/1-core/contract"
|
|
39
35
|
},
|
|
40
36
|
"scripts": {
|
|
41
|
-
"build": "
|
|
37
|
+
"build": "tsdown",
|
|
42
38
|
"test": "vitest run",
|
|
43
39
|
"test:coverage": "vitest run --coverage",
|
|
44
|
-
"typecheck": "tsc --
|
|
45
|
-
"lint": "biome check . --
|
|
46
|
-
"lint:fix": "biome check --write .
|
|
47
|
-
"lint:fix:unsafe": "biome check --write --unsafe .
|
|
48
|
-
"clean": "
|
|
40
|
+
"typecheck": "tsc --noEmit",
|
|
41
|
+
"lint": "biome check . --error-on-warnings",
|
|
42
|
+
"lint:fix": "biome check --write .",
|
|
43
|
+
"lint:fix:unsafe": "biome check --write --unsafe .",
|
|
44
|
+
"clean": "rm -rf dist dist-tsc dist-tsc-prod coverage .tmp-output"
|
|
49
45
|
}
|
|
50
46
|
}
|
package/src/exports/types.ts
CHANGED
|
@@ -2,16 +2,21 @@ export type {
|
|
|
2
2
|
ExtractCodecTypes,
|
|
3
3
|
ExtractOperationTypes,
|
|
4
4
|
ForeignKey,
|
|
5
|
+
ForeignKeyOptions,
|
|
5
6
|
ForeignKeyReferences,
|
|
6
7
|
Index,
|
|
7
8
|
ModelDefinition,
|
|
8
9
|
ModelField,
|
|
9
10
|
ModelStorage,
|
|
10
11
|
PrimaryKey,
|
|
12
|
+
ReferentialAction,
|
|
11
13
|
SqlContract,
|
|
12
14
|
SqlMappings,
|
|
13
15
|
SqlStorage,
|
|
14
16
|
StorageColumn,
|
|
15
17
|
StorageTable,
|
|
18
|
+
StorageTypeInstance,
|
|
16
19
|
UniqueConstraint,
|
|
17
20
|
} from '../types';
|
|
21
|
+
|
|
22
|
+
export { applyFkDefaults, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX } from '../types';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from '../validators';
|
package/src/factories.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
ExecutionHashBase,
|
|
3
|
+
ProfileHashBase,
|
|
4
|
+
StorageHashBase,
|
|
5
|
+
} from '@prisma-next/contract/types';
|
|
1
6
|
import type {
|
|
2
7
|
ForeignKey,
|
|
8
|
+
ForeignKeyOptions,
|
|
3
9
|
ForeignKeyReferences,
|
|
4
10
|
Index,
|
|
5
11
|
ModelDefinition,
|
|
@@ -13,6 +19,7 @@ import type {
|
|
|
13
19
|
StorageTable,
|
|
14
20
|
UniqueConstraint,
|
|
15
21
|
} from './types';
|
|
22
|
+
import { applyFkDefaults } from './types';
|
|
16
23
|
|
|
17
24
|
/**
|
|
18
25
|
* Creates a StorageColumn with nativeType and codecId.
|
|
@@ -52,16 +59,20 @@ export function fk(
|
|
|
52
59
|
columns: readonly string[],
|
|
53
60
|
refTable: string,
|
|
54
61
|
refColumns: readonly string[],
|
|
55
|
-
|
|
62
|
+
opts?: ForeignKeyOptions & { constraint?: boolean; index?: boolean },
|
|
56
63
|
): ForeignKey {
|
|
57
64
|
const references: ForeignKeyReferences = {
|
|
58
65
|
table: refTable,
|
|
59
66
|
columns: refColumns,
|
|
60
67
|
};
|
|
68
|
+
|
|
61
69
|
return {
|
|
62
70
|
columns,
|
|
63
71
|
references,
|
|
64
|
-
...(name !== undefined && { name }),
|
|
72
|
+
...(opts?.name !== undefined && { name: opts.name }),
|
|
73
|
+
...(opts?.onDelete !== undefined && { onDelete: opts.onDelete }),
|
|
74
|
+
...(opts?.onUpdate !== undefined && { onUpdate: opts.onUpdate }),
|
|
75
|
+
...applyFkDefaults({ constraint: opts?.constraint, index: opts?.index }),
|
|
65
76
|
};
|
|
66
77
|
}
|
|
67
78
|
|
|
@@ -100,26 +111,40 @@ export function storage(tables: Record<string, StorageTable>): SqlStorage {
|
|
|
100
111
|
return { tables };
|
|
101
112
|
}
|
|
102
113
|
|
|
103
|
-
export function contract
|
|
114
|
+
export function contract<
|
|
115
|
+
TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
|
|
116
|
+
TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
|
|
117
|
+
TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
|
|
118
|
+
>(opts: {
|
|
104
119
|
target: string;
|
|
105
|
-
|
|
120
|
+
storageHash: TStorageHash;
|
|
121
|
+
executionHash?: TExecutionHash;
|
|
106
122
|
storage: SqlStorage;
|
|
107
123
|
models?: Record<string, ModelDefinition>;
|
|
108
124
|
relations?: Record<string, unknown>;
|
|
109
125
|
mappings?: Partial<SqlMappings>;
|
|
110
126
|
schemaVersion?: '1';
|
|
111
127
|
targetFamily?: 'sql';
|
|
112
|
-
profileHash?:
|
|
128
|
+
profileHash?: TProfileHash;
|
|
113
129
|
capabilities?: Record<string, Record<string, boolean>>;
|
|
114
130
|
extensionPacks?: Record<string, unknown>;
|
|
115
131
|
meta?: Record<string, unknown>;
|
|
116
132
|
sources?: Record<string, unknown>;
|
|
117
|
-
}): SqlContract
|
|
133
|
+
}): SqlContract<
|
|
134
|
+
SqlStorage,
|
|
135
|
+
Record<string, unknown>,
|
|
136
|
+
Record<string, unknown>,
|
|
137
|
+
SqlMappings,
|
|
138
|
+
TStorageHash,
|
|
139
|
+
TExecutionHash,
|
|
140
|
+
TProfileHash
|
|
141
|
+
> {
|
|
118
142
|
return {
|
|
119
143
|
schemaVersion: opts.schemaVersion ?? '1',
|
|
120
144
|
target: opts.target,
|
|
121
145
|
targetFamily: opts.targetFamily ?? 'sql',
|
|
122
|
-
|
|
146
|
+
storageHash: opts.storageHash,
|
|
147
|
+
...(opts.executionHash !== undefined && { executionHash: opts.executionHash }),
|
|
123
148
|
storage: opts.storage,
|
|
124
149
|
models: opts.models ?? {},
|
|
125
150
|
relations: opts.relations ?? {},
|
|
@@ -129,5 +154,13 @@ export function contract(opts: {
|
|
|
129
154
|
...(opts.extensionPacks !== undefined && { extensionPacks: opts.extensionPacks }),
|
|
130
155
|
...(opts.meta !== undefined && { meta: opts.meta }),
|
|
131
156
|
...(opts.sources !== undefined && { sources: opts.sources as Record<string, unknown> }),
|
|
132
|
-
} as SqlContract
|
|
157
|
+
} as SqlContract<
|
|
158
|
+
SqlStorage,
|
|
159
|
+
Record<string, unknown>,
|
|
160
|
+
Record<string, unknown>,
|
|
161
|
+
SqlMappings,
|
|
162
|
+
TStorageHash,
|
|
163
|
+
TExecutionHash,
|
|
164
|
+
TProfileHash
|
|
165
|
+
>;
|
|
133
166
|
}
|
package/src/index.ts
CHANGED
package/src/types.ts
CHANGED
|
@@ -1,9 +1,39 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
ColumnDefault,
|
|
3
|
+
ContractBase,
|
|
4
|
+
ExecutionHashBase,
|
|
5
|
+
ExecutionSection,
|
|
6
|
+
ProfileHashBase,
|
|
7
|
+
StorageHashBase,
|
|
8
|
+
} from '@prisma-next/contract/types';
|
|
2
9
|
|
|
10
|
+
/**
|
|
11
|
+
* A column definition in storage.
|
|
12
|
+
*
|
|
13
|
+
* `typeParams` is optional because most columns use non-parameterized types.
|
|
14
|
+
* Columns with parameterized types can either inline `typeParams` or reference
|
|
15
|
+
* a named {@link StorageTypeInstance} via `typeRef`.
|
|
16
|
+
*/
|
|
3
17
|
export type StorageColumn = {
|
|
4
18
|
readonly nativeType: string;
|
|
5
19
|
readonly codecId: string;
|
|
6
20
|
readonly nullable: boolean;
|
|
21
|
+
/**
|
|
22
|
+
* Opaque, codec-owned JS/type parameters.
|
|
23
|
+
* The codec that owns `codecId` defines the shape and semantics.
|
|
24
|
+
* Mutually exclusive with `typeRef`.
|
|
25
|
+
*/
|
|
26
|
+
readonly typeParams?: Record<string, unknown>;
|
|
27
|
+
/**
|
|
28
|
+
* Reference to a named type instance in `storage.types`.
|
|
29
|
+
* Mutually exclusive with `typeParams`.
|
|
30
|
+
*/
|
|
31
|
+
readonly typeRef?: string;
|
|
32
|
+
/**
|
|
33
|
+
* Default value for the column.
|
|
34
|
+
* Can be a literal value or database function.
|
|
35
|
+
*/
|
|
36
|
+
readonly default?: ColumnDefault;
|
|
7
37
|
};
|
|
8
38
|
|
|
9
39
|
export type PrimaryKey = {
|
|
@@ -26,10 +56,24 @@ export type ForeignKeyReferences = {
|
|
|
26
56
|
readonly columns: readonly string[];
|
|
27
57
|
};
|
|
28
58
|
|
|
59
|
+
export type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
60
|
+
|
|
61
|
+
export type ForeignKeyOptions = {
|
|
62
|
+
readonly name?: string;
|
|
63
|
+
readonly onDelete?: ReferentialAction;
|
|
64
|
+
readonly onUpdate?: ReferentialAction;
|
|
65
|
+
};
|
|
66
|
+
|
|
29
67
|
export type ForeignKey = {
|
|
30
68
|
readonly columns: readonly string[];
|
|
31
69
|
readonly references: ForeignKeyReferences;
|
|
32
70
|
readonly name?: string;
|
|
71
|
+
readonly onDelete?: ReferentialAction;
|
|
72
|
+
readonly onUpdate?: ReferentialAction;
|
|
73
|
+
/** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
74
|
+
readonly constraint: boolean;
|
|
75
|
+
/** Whether to emit a backing index for the FK columns. */
|
|
76
|
+
readonly index: boolean;
|
|
33
77
|
};
|
|
34
78
|
|
|
35
79
|
export type StorageTable = {
|
|
@@ -40,8 +84,29 @@ export type StorageTable = {
|
|
|
40
84
|
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
41
85
|
};
|
|
42
86
|
|
|
87
|
+
/**
|
|
88
|
+
* A named, parameterized type instance.
|
|
89
|
+
* These are registered in `storage.types` for reuse across columns
|
|
90
|
+
* and to enable ergonomic schema surfaces like `schema.types.MyType`.
|
|
91
|
+
*
|
|
92
|
+
* Unlike {@link StorageColumn}, `typeParams` is required here because
|
|
93
|
+
* `StorageTypeInstance` exists specifically to define reusable parameterized types.
|
|
94
|
+
* A type instance without parameters would be redundant—columns can reference
|
|
95
|
+
* the codec directly via `codecId`.
|
|
96
|
+
*/
|
|
97
|
+
export type StorageTypeInstance = {
|
|
98
|
+
readonly codecId: string;
|
|
99
|
+
readonly nativeType: string;
|
|
100
|
+
readonly typeParams: Record<string, unknown>;
|
|
101
|
+
};
|
|
102
|
+
|
|
43
103
|
export type SqlStorage = {
|
|
44
104
|
readonly tables: Record<string, StorageTable>;
|
|
105
|
+
/**
|
|
106
|
+
* Named type instances for parameterized/custom types.
|
|
107
|
+
* Columns can reference these via `typeRef`.
|
|
108
|
+
*/
|
|
109
|
+
readonly types?: Record<string, StorageTypeInstance>;
|
|
45
110
|
};
|
|
46
111
|
|
|
47
112
|
export type ModelField = {
|
|
@@ -67,17 +132,38 @@ export type SqlMappings = {
|
|
|
67
132
|
readonly operationTypes: Record<string, Record<string, unknown>>;
|
|
68
133
|
};
|
|
69
134
|
|
|
135
|
+
export const DEFAULT_FK_CONSTRAINT = true;
|
|
136
|
+
export const DEFAULT_FK_INDEX = true;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Resolves foreign key `constraint` and `index` fields to their effective boolean values,
|
|
140
|
+
* falling back through optional override defaults, then to the global defaults.
|
|
141
|
+
*/
|
|
142
|
+
export function applyFkDefaults(
|
|
143
|
+
fk: { constraint?: boolean | undefined; index?: boolean | undefined },
|
|
144
|
+
overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },
|
|
145
|
+
): { constraint: boolean; index: boolean } {
|
|
146
|
+
return {
|
|
147
|
+
constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,
|
|
148
|
+
index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
|
|
70
152
|
export type SqlContract<
|
|
71
153
|
S extends SqlStorage = SqlStorage,
|
|
72
154
|
M extends Record<string, unknown> = Record<string, unknown>,
|
|
73
155
|
R extends Record<string, unknown> = Record<string, unknown>,
|
|
74
156
|
Map extends SqlMappings = SqlMappings,
|
|
75
|
-
> =
|
|
157
|
+
TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,
|
|
158
|
+
TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,
|
|
159
|
+
TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,
|
|
160
|
+
> = ContractBase<TStorageHash, TExecutionHash, TProfileHash> & {
|
|
76
161
|
readonly targetFamily: string;
|
|
77
162
|
readonly storage: S;
|
|
78
163
|
readonly models: M;
|
|
79
164
|
readonly relations: R;
|
|
80
165
|
readonly mappings: Map;
|
|
166
|
+
readonly execution?: ExecutionSection;
|
|
81
167
|
};
|
|
82
168
|
|
|
83
169
|
export type ExtractCodecTypes<TContract extends SqlContract<SqlStorage>> =
|