@prisma-next/sql-contract 0.3.0-dev.73 → 0.3.0-dev.75
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/README.md +6 -1
- package/dist/factories.d.mts +1 -1
- package/dist/factories.mjs +1 -1
- package/dist/{types-BaAbD2Bc.d.mts → types-CcCSXOlR.d.mts} +23 -12
- package/dist/types-CcCSXOlR.d.mts.map +1 -0
- package/dist/{types-kacOgEya.mjs → types-DRR5stkj.mjs} +1 -5
- package/dist/{types-kacOgEya.mjs.map → types-DRR5stkj.mjs.map} +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +1 -1
- package/dist/validate.d.mts +1 -1
- package/dist/validate.d.mts.map +1 -1
- package/dist/validate.mjs +20 -20
- package/dist/validate.mjs.map +1 -1
- package/dist/validators.d.mts +1 -1
- package/package.json +2 -2
- package/src/construct.ts +178 -0
- package/src/exports/types.ts +8 -0
- package/src/types.ts +43 -10
- package/src/validate.ts +4 -180
- package/dist/types-BaAbD2Bc.d.mts.map +0 -1
package/README.md
CHANGED
|
@@ -122,10 +122,15 @@ import { validateContract } from '@prisma-next/sql-contract/validate';
|
|
|
122
122
|
const contract = validateContract<Contract>(contractJson);
|
|
123
123
|
```
|
|
124
124
|
|
|
125
|
+
`validateContract` returns a constructed contract that:
|
|
126
|
+
- Computes runtime-real `mappings` (modelToTable, tableToModel, fieldToColumn, columnToField) from models/storage
|
|
127
|
+
- Strips `_generated` if present on input (emitter metadata is excluded from the returned value)
|
|
128
|
+
- Does not require execution stack or runtime descriptors
|
|
129
|
+
|
|
125
130
|
Mapping overrides in `contract.mappings` follow strict pair semantics:
|
|
126
131
|
- `modelToTable` and `tableToModel` must either both be omitted (auto-computed) or both be provided as inverse maps.
|
|
127
132
|
- `fieldToColumn` and `columnToField` must either both be omitted (auto-computed) or both be provided as inverse maps.
|
|
128
|
-
-
|
|
133
|
+
- Codec and operation type maps are type-only (phantom channel) and are not present at runtime.
|
|
129
134
|
|
|
130
135
|
### Factories
|
|
131
136
|
|
package/dist/factories.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as StorageColumn, O as UniqueConstraint, S as SqlStorage, b as SqlContract, c as ForeignKey, d as Index, f as ModelDefinition, g as PrimaryKey, l as ForeignKeyOptions, p as ModelField, w as StorageTable, x as SqlMappings } from "./types-CcCSXOlR.mjs";
|
|
2
2
|
import { ExecutionHashBase, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
3
3
|
|
|
4
4
|
//#region src/factories.d.ts
|
package/dist/factories.mjs
CHANGED
|
@@ -119,17 +119,9 @@ type SqlMappings = {
|
|
|
119
119
|
readonly tableToModel?: Record<string, string>;
|
|
120
120
|
readonly fieldToColumn?: Record<string, Record<string, string>>;
|
|
121
121
|
readonly columnToField?: Record<string, Record<string, string>>;
|
|
122
|
-
readonly codecTypes: Record<string, {
|
|
123
|
-
readonly output: unknown;
|
|
124
|
-
}>;
|
|
125
|
-
readonly operationTypes: Record<string, Record<string, unknown>>;
|
|
126
122
|
};
|
|
127
123
|
declare const DEFAULT_FK_CONSTRAINT = true;
|
|
128
124
|
declare const DEFAULT_FK_INDEX = true;
|
|
129
|
-
/**
|
|
130
|
-
* Resolves foreign key `constraint` and `index` fields to their effective boolean values,
|
|
131
|
-
* falling back through optional override defaults, then to the global defaults.
|
|
132
|
-
*/
|
|
133
125
|
declare function applyFkDefaults(fk: {
|
|
134
126
|
constraint?: boolean | undefined;
|
|
135
127
|
index?: boolean | undefined;
|
|
@@ -140,6 +132,22 @@ declare function applyFkDefaults(fk: {
|
|
|
140
132
|
constraint: boolean;
|
|
141
133
|
index: boolean;
|
|
142
134
|
};
|
|
135
|
+
type TypeMaps<TCodecTypes extends Record<string, {
|
|
136
|
+
output: unknown;
|
|
137
|
+
}> = Record<string, never>, TOperationTypes extends Record<string, unknown> = Record<string, never>> = {
|
|
138
|
+
readonly codecTypes: TCodecTypes;
|
|
139
|
+
readonly operationTypes: TOperationTypes;
|
|
140
|
+
};
|
|
141
|
+
type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
142
|
+
readonly codecTypes: infer C;
|
|
143
|
+
} ? C extends Record<string, {
|
|
144
|
+
output: unknown;
|
|
145
|
+
}> ? C : Record<string, never> : Record<string, never>;
|
|
146
|
+
type OperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
147
|
+
readonly operationTypes: infer O;
|
|
148
|
+
} ? O extends Record<string, unknown> ? O : Record<string, never> : Record<string, never>;
|
|
149
|
+
type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
|
|
150
|
+
type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
|
|
143
151
|
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> & {
|
|
144
152
|
readonly targetFamily: string;
|
|
145
153
|
readonly storage: S;
|
|
@@ -148,8 +156,11 @@ type SqlContract<S extends SqlStorage = SqlStorage, M extends Record<string, unk
|
|
|
148
156
|
readonly mappings: Map;
|
|
149
157
|
readonly execution?: ExecutionSection;
|
|
150
158
|
};
|
|
151
|
-
type
|
|
152
|
-
type
|
|
159
|
+
type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
|
|
160
|
+
type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
161
|
+
type ExtractOperationTypes<T> = OperationTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
162
|
+
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
|
|
163
|
+
type ResolveOperationTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractOperationTypes<TContract> : OperationTypesOf<TTypeMaps>;
|
|
153
164
|
//#endregion
|
|
154
|
-
export { StorageColumn as _,
|
|
155
|
-
//# sourceMappingURL=types-
|
|
165
|
+
export { StorageColumn as C, TypeMapsPhantomKey as D, TypeMaps as E, UniqueConstraint as O, SqlStorage as S, StorageTypeInstance as T, ReferentialAction as _, ExtractCodecTypes as a, SqlContract as b, ForeignKey as c, Index as d, ModelDefinition as f, PrimaryKey as g, OperationTypesOf as h, DEFAULT_FK_INDEX as i, applyFkDefaults as k, ForeignKeyOptions as l, ModelStorage as m, ContractWithTypeMaps as n, ExtractOperationTypes as o, ModelField as p, DEFAULT_FK_CONSTRAINT as r, ExtractTypeMapsFromContract as s, CodecTypesOf as t, ForeignKeyReferences as u, ResolveCodecTypes as v, StorageTable as w, SqlMappings as x, ResolveOperationTypes as y };
|
|
166
|
+
//# sourceMappingURL=types-CcCSXOlR.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CcCSXOlR.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAgBA;AAsBA;AAKA;AAKA;AAeA;AAKY,KApDA,aAAA,GAoDiB;EAEjB,SAAA,UAAA,EAAiB,MAAA;EAMjB,SAAA,OAAU,EAAA,MAAA;EAEC,SAAA,QAAA,EAAA,OAAA;EAED;;;AAQtB;;EACoB,SAAA,UAAA,CAAA,EAhEI,MAgEJ,CAAA,MAAA,EAAA,OAAA,CAAA;EACI;;;;EAEJ,SAAA,OAAA,CAAA,EAAA,MAAA;EACkB;;;AAatC;EAMY,SAAA,OAAU,CAAA,EA7ED,aA6EC;CACY;AAAf,KA3EP,UAAA,GA2EO;EAKe,SAAA,OAAA,EA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IAC1E,YAAY,EAAE,2BAA2B;KAGjC,uBAAuB,aAAa,4BAA4B;KAChE,2BAA2B,iBAAiB,4BAA4B;KAExE,2CAA2C,6BACnD,kBAAkB,aAClB,aAAa;KAEL,+CAA+C,6BACvD,sBAAsB,aACtB,iBAAiB"}
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
//#region src/types.ts
|
|
2
2
|
const DEFAULT_FK_CONSTRAINT = true;
|
|
3
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
4
|
function applyFkDefaults(fk, overrideDefaults) {
|
|
9
5
|
return {
|
|
10
6
|
constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,
|
|
@@ -14,4 +10,4 @@ function applyFkDefaults(fk, overrideDefaults) {
|
|
|
14
10
|
|
|
15
11
|
//#endregion
|
|
16
12
|
export { DEFAULT_FK_INDEX as n, applyFkDefaults as r, DEFAULT_FK_CONSTRAINT as t };
|
|
17
|
-
//# sourceMappingURL=types-
|
|
13
|
+
//# sourceMappingURL=types-DRR5stkj.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types-
|
|
1
|
+
{"version":3,"file":"types-DRR5stkj.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 * Optional access method identifier.\n * Extension-specific methods are represented as strings and interpreted\n * by the owning extension package.\n */\n readonly using?: string;\n /**\n * Optional extension-owned index configuration payload.\n */\n readonly config?: Record<string, unknown>;\n};\n\nexport type ForeignKeyReferences = {\n readonly table: string;\n readonly columns: readonly string[];\n};\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type ForeignKey = {\n readonly columns: readonly string[];\n readonly references: ForeignKeyReferences;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n};\n\nexport type StorageTable = {\n readonly columns: Record<string, StorageColumn>;\n readonly primaryKey?: PrimaryKey;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n};\n\n/**\n * A named, parameterized type instance.\n * These are registered in `storage.types` for reuse across columns\n * and to enable ergonomic schema surfaces like `schema.types.MyType`.\n *\n * Unlike {@link StorageColumn}, `typeParams` is required here because\n * `StorageTypeInstance` exists specifically to define reusable parameterized types.\n * A type instance without parameters would be redundant—columns can reference\n * the codec directly via `codecId`.\n */\nexport type StorageTypeInstance = {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n};\n\nexport type SqlStorage = {\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};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TOperationTypes extends Record<string, unknown> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly operationTypes: TOperationTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\nexport type OperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly operationTypes: infer O }\n ? O extends Record<string, unknown>\n ? O\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type 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 ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractOperationTypes<T> = OperationTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n\nexport type ResolveOperationTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractOperationTypes<TContract>\n : OperationTypesOf<TTypeMaps>;\n"],"mappings":";AA8IA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;AACzC,QAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAc;EAC7D,OAAO,GAAG,SAAS,kBAAkB,SAAS;EAC/C"}
|
package/dist/types.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
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 };
|
|
1
|
+
import { C as StorageColumn, D as TypeMapsPhantomKey, E as TypeMaps, O as UniqueConstraint, S as SqlStorage, T as StorageTypeInstance, _ as ReferentialAction, a as ExtractCodecTypes, b as SqlContract, c as ForeignKey, d as Index, f as ModelDefinition, g as PrimaryKey, h as OperationTypesOf, i as DEFAULT_FK_INDEX, k as applyFkDefaults, l as ForeignKeyOptions, m as ModelStorage, n as ContractWithTypeMaps, o as ExtractOperationTypes, p as ModelField, r as DEFAULT_FK_CONSTRAINT, s as ExtractTypeMapsFromContract, t as CodecTypesOf, u as ForeignKeyReferences, v as ResolveCodecTypes, w as StorageTable, x as SqlMappings, y as ResolveOperationTypes } from "./types-CcCSXOlR.mjs";
|
|
2
|
+
export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractOperationTypes, type ExtractTypeMapsFromContract, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type ModelDefinition, type ModelField, type ModelStorage, type OperationTypesOf, type PrimaryKey, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlContract, type SqlMappings, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
|
package/dist/types.mjs
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { n as DEFAULT_FK_INDEX, r as applyFkDefaults, t as DEFAULT_FK_CONSTRAINT } from "./types-
|
|
1
|
+
import { n as DEFAULT_FK_INDEX, r as applyFkDefaults, t as DEFAULT_FK_CONSTRAINT } from "./types-DRR5stkj.mjs";
|
|
2
2
|
|
|
3
3
|
export { DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, applyFkDefaults };
|
package/dist/validate.d.mts
CHANGED
package/dist/validate.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"sourcesContent":[],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"sourcesContent":[],"mappings":";;;;iBAuFgB,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"}
|
package/dist/validate.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { r as applyFkDefaults } from "./types-
|
|
1
|
+
import { r as applyFkDefaults } from "./types-DRR5stkj.mjs";
|
|
2
2
|
import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-CQXvLZa7.mjs";
|
|
3
3
|
import { isTaggedBigInt, isTaggedRaw } from "@prisma-next/contract/types";
|
|
4
4
|
|
|
5
|
-
//#region src/
|
|
5
|
+
//#region src/construct.ts
|
|
6
6
|
function computeDefaultMappings(models) {
|
|
7
7
|
const modelToTable = {};
|
|
8
8
|
const tableToModel = {};
|
|
@@ -25,9 +25,7 @@ function computeDefaultMappings(models) {
|
|
|
25
25
|
modelToTable,
|
|
26
26
|
tableToModel,
|
|
27
27
|
fieldToColumn,
|
|
28
|
-
columnToField
|
|
29
|
-
codecTypes: {},
|
|
30
|
-
operationTypes: {}
|
|
28
|
+
columnToField
|
|
31
29
|
};
|
|
32
30
|
}
|
|
33
31
|
function assertInverseModelMappings(modelToTable, tableToModel) {
|
|
@@ -67,17 +65,24 @@ function mergeMappings(defaults, existingMappings) {
|
|
|
67
65
|
modelToTable,
|
|
68
66
|
tableToModel,
|
|
69
67
|
fieldToColumn,
|
|
70
|
-
columnToField
|
|
71
|
-
codecTypes: {
|
|
72
|
-
...defaults.codecTypes,
|
|
73
|
-
...existingMappings?.codecTypes ?? {}
|
|
74
|
-
},
|
|
75
|
-
operationTypes: {
|
|
76
|
-
...defaults.operationTypes,
|
|
77
|
-
...existingMappings?.operationTypes ?? {}
|
|
78
|
-
}
|
|
68
|
+
columnToField
|
|
79
69
|
};
|
|
80
70
|
}
|
|
71
|
+
function stripGenerated(obj) {
|
|
72
|
+
const { _generated: _, ...rest } = obj;
|
|
73
|
+
return rest;
|
|
74
|
+
}
|
|
75
|
+
function constructContract(input) {
|
|
76
|
+
const existingMappings = input.mappings;
|
|
77
|
+
const mappings = mergeMappings(computeDefaultMappings(input.models), existingMappings);
|
|
78
|
+
return {
|
|
79
|
+
...stripGenerated(input),
|
|
80
|
+
mappings
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region src/validate.ts
|
|
81
86
|
function validateContractLogic(contract) {
|
|
82
87
|
const tableNames = new Set(Object.keys(contract.storage.tables));
|
|
83
88
|
for (const [tableName, table] of Object.entries(contract.storage.tables)) {
|
|
@@ -231,12 +236,7 @@ function validateContract(value) {
|
|
|
231
236
|
validateContractLogic(structurallyValid);
|
|
232
237
|
const semanticErrors = validateStorageSemantics(structurallyValid.storage);
|
|
233
238
|
if (semanticErrors.length > 0) throw new Error(`Contract semantic validation failed: ${semanticErrors.join("; ")}`);
|
|
234
|
-
|
|
235
|
-
const mappings = mergeMappings(computeDefaultMappings(structurallyValid.models), existingMappings);
|
|
236
|
-
return decodeContractDefaults({
|
|
237
|
-
...structurallyValid,
|
|
238
|
-
mappings
|
|
239
|
-
});
|
|
239
|
+
return decodeContractDefaults(constructContract(structurallyValid));
|
|
240
240
|
}
|
|
241
241
|
|
|
242
242
|
//#endregion
|
package/dist/validate.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"validate.mjs","names":["modelToTable: Record<string, string>","tableToModel: Record<string, string>","fieldToColumn: Record<string, Record<string, string>>","columnToField: Record<string, Record<string, string>>","modelFieldToColumn: Record<string, string>","decodedTables: Record<string, StorageTable>","decodedColumns: Record<string, StorageColumn>","normalizedTables: Record<string, unknown>","normalizedColumns: Record<string, unknown>","normalizedModelsObj: Record<string, unknown>"],"sources":["../src/validate.ts"],"sourcesContent":["import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport { isTaggedBigInt, isTaggedRaw } from '@prisma-next/contract/types';\nimport type {\n ModelDefinition,\n SqlContract,\n SqlMappings,\n SqlStorage,\n StorageColumn,\n StorageTable,\n} from './types';\nimport { applyFkDefaults } from './types';\nimport { validateSqlContract, validateStorageSemantics } from './validators';\n\ntype ResolvedMappings = {\n modelToTable: Record<string, string>;\n tableToModel: Record<string, string>;\n fieldToColumn: Record<string, Record<string, string>>;\n columnToField: Record<string, Record<string, string>>;\n codecTypes: Record<string, { readonly output: unknown }>;\n operationTypes: Record<string, Record<string, unknown>>;\n};\n\nfunction computeDefaultMappings(models: Record<string, ModelDefinition>): ResolvedMappings {\n const modelToTable: Record<string, string> = {};\n const tableToModel: Record<string, string> = {};\n const fieldToColumn: Record<string, Record<string, string>> = {};\n const columnToField: Record<string, Record<string, string>> = {};\n\n for (const [modelName, model] of Object.entries(models)) {\n const tableName = model.storage.table;\n modelToTable[modelName] = tableName;\n tableToModel[tableName] = modelName;\n\n const modelFieldToColumn: Record<string, string> = {};\n for (const [fieldName, field] of Object.entries(model.fields)) {\n const columnName = field.column;\n modelFieldToColumn[fieldName] = columnName;\n if (!columnToField[tableName]) {\n columnToField[tableName] = {};\n }\n columnToField[tableName][columnName] = fieldName;\n }\n\n fieldToColumn[modelName] = modelFieldToColumn;\n }\n\n return {\n modelToTable,\n tableToModel,\n fieldToColumn,\n columnToField,\n codecTypes: {},\n operationTypes: {},\n };\n}\n\nfunction assertInverseModelMappings(\n modelToTable: Record<string, string>,\n tableToModel: Record<string, string>,\n) {\n for (const [model, table] of Object.entries(modelToTable)) {\n if (tableToModel[table] !== model) {\n throw new Error(\n `Mappings override mismatch: modelToTable.${model}=\"${table}\" is not mirrored in tableToModel`,\n );\n }\n }\n for (const [table, model] of Object.entries(tableToModel)) {\n if (modelToTable[model] !== table) {\n throw new Error(\n `Mappings override mismatch: tableToModel.${table}=\"${model}\" is not mirrored in modelToTable`,\n );\n }\n }\n}\n\nfunction assertInverseFieldMappings(\n fieldToColumn: Record<string, Record<string, string>>,\n columnToField: Record<string, Record<string, string>>,\n modelToTable: Record<string, string>,\n tableToModel: Record<string, string>,\n) {\n for (const [model, fields] of Object.entries(fieldToColumn)) {\n const table = modelToTable[model];\n if (!table) {\n throw new Error(\n `Mappings override mismatch: fieldToColumn references unknown model \"${model}\"`,\n );\n }\n const reverseFields = columnToField[table];\n if (!reverseFields) {\n throw new Error(\n `Mappings override mismatch: columnToField is missing table \"${table}\" for model \"${model}\"`,\n );\n }\n for (const [field, column] of Object.entries(fields)) {\n if (reverseFields[column] !== field) {\n throw new Error(\n `Mappings override mismatch: fieldToColumn.${model}.${field}=\"${column}\" is not mirrored in columnToField.${table}`,\n );\n }\n }\n }\n\n for (const [table, columns] of Object.entries(columnToField)) {\n const model = tableToModel[table];\n if (!model) {\n throw new Error(\n `Mappings override mismatch: columnToField references unknown table \"${table}\"`,\n );\n }\n const forwardFields = fieldToColumn[model];\n if (!forwardFields) {\n throw new Error(\n `Mappings override mismatch: fieldToColumn is missing model \"${model}\" for table \"${table}\"`,\n );\n }\n for (const [column, field] of Object.entries(columns)) {\n if (forwardFields[field] !== column) {\n throw new Error(\n `Mappings override mismatch: columnToField.${table}.${column}=\"${field}\" is not mirrored in fieldToColumn.${model}`,\n );\n }\n }\n }\n}\n\nfunction mergeMappings(\n defaults: ResolvedMappings,\n existingMappings?: Partial<SqlMappings>,\n): ResolvedMappings {\n const hasModelToTable = existingMappings?.modelToTable !== undefined;\n const hasTableToModel = existingMappings?.tableToModel !== undefined;\n if (hasModelToTable !== hasTableToModel) {\n throw new Error(\n 'Mappings override mismatch: modelToTable and tableToModel must be provided together',\n );\n }\n\n const hasFieldToColumn = existingMappings?.fieldToColumn !== undefined;\n const hasColumnToField = existingMappings?.columnToField !== undefined;\n if (hasFieldToColumn !== hasColumnToField) {\n throw new Error(\n 'Mappings override mismatch: fieldToColumn and columnToField must be provided together',\n );\n }\n\n const modelToTable: Record<string, string> = hasModelToTable\n ? (existingMappings?.modelToTable ?? {})\n : defaults.modelToTable;\n const tableToModel: Record<string, string> = hasTableToModel\n ? (existingMappings?.tableToModel ?? {})\n : defaults.tableToModel;\n assertInverseModelMappings(modelToTable, tableToModel);\n\n const fieldToColumn: Record<string, Record<string, string>> = hasFieldToColumn\n ? (existingMappings?.fieldToColumn ?? {})\n : defaults.fieldToColumn;\n const columnToField: Record<string, Record<string, string>> = hasColumnToField\n ? (existingMappings?.columnToField ?? {})\n : defaults.columnToField;\n assertInverseFieldMappings(fieldToColumn, columnToField, modelToTable, tableToModel);\n\n return {\n modelToTable,\n tableToModel,\n fieldToColumn,\n columnToField,\n codecTypes: { ...defaults.codecTypes, ...(existingMappings?.codecTypes ?? {}) },\n operationTypes: { ...defaults.operationTypes, ...(existingMappings?.operationTypes ?? {}) },\n };\n}\n\nfunction validateContractLogic(contract: SqlContract<SqlStorage>): void {\n const tableNames = new Set(Object.keys(contract.storage.tables));\n\n for (const [tableName, table] of Object.entries(contract.storage.tables)) {\n const columnNames = new Set(Object.keys(table.columns));\n\n if (table.primaryKey) {\n for (const colName of table.primaryKey.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const unique of table.uniques) {\n for (const colName of unique.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const index of table.indexes) {\n for (const colName of index.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(`Table \"${tableName}\" index references non-existent column \"${colName}\"`);\n }\n }\n }\n\n for (const [colName, column] of Object.entries(table.columns)) {\n if (!column.nullable && column.default?.kind === 'literal' && column.default.value === null) {\n throw new Error(\n `Table \"${tableName}\" column \"${colName}\" is NOT NULL but has a literal null default`,\n );\n }\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`,\n );\n }\n }\n\n if (!tableNames.has(fk.references.table)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n );\n }\n\n const referencedTable = contract.storage.tables[\n fk.references.table\n ] as (typeof contract.storage.tables)[string];\n const referencedColumnNames = new Set(Object.keys(referencedTable.columns));\n for (const colName of fk.references.columns) {\n if (!referencedColumnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.references.table}\"`,\n );\n }\n }\n\n if (fk.columns.length !== fk.references.columns.length) {\n throw new Error(\n `Table \"${tableName}\" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,\n );\n }\n }\n }\n}\n\nconst BIGINT_NATIVE_TYPES = new Set(['bigint', 'int8']);\n\nexport function isBigIntColumn(column: StorageColumn): boolean {\n const nativeType = column.nativeType?.toLowerCase() ?? '';\n if (BIGINT_NATIVE_TYPES.has(nativeType)) return true;\n const codecId = column.codecId?.toLowerCase() ?? '';\n return codecId.includes('int8') || codecId.includes('bigint');\n}\n\nexport function decodeDefaultLiteralValue(\n value: ColumnDefaultLiteralInputValue,\n column: StorageColumn,\n tableName: string,\n columnName: string,\n): ColumnDefaultLiteralInputValue {\n if (value instanceof Date) {\n return value;\n }\n if (isTaggedRaw(value)) {\n return value.value;\n }\n if (isTaggedBigInt(value)) {\n if (!isBigIntColumn(column)) {\n return value;\n }\n try {\n return BigInt(value.value);\n } catch {\n throw new Error(\n `Invalid tagged bigint for default value on \"${tableName}.${columnName}\": \"${value.value}\" is not a valid integer`,\n );\n }\n }\n return value;\n}\n\nexport function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contract: T): T {\n const tables = contract.storage.tables;\n let tablesChanged = false;\n const decodedTables: Record<string, StorageTable> = {};\n\n for (const [tableName, table] of Object.entries(tables)) {\n let columnsChanged = false;\n const decodedColumns: Record<string, StorageColumn> = {};\n\n for (const [columnName, column] of Object.entries(table.columns)) {\n if (column.default?.kind === 'literal') {\n const decodedValue = decodeDefaultLiteralValue(\n column.default.value,\n column,\n tableName,\n columnName,\n );\n if (decodedValue !== column.default.value) {\n columnsChanged = true;\n decodedColumns[columnName] = {\n ...column,\n default: { kind: 'literal', value: decodedValue },\n };\n continue;\n }\n }\n decodedColumns[columnName] = column;\n }\n\n if (columnsChanged) {\n tablesChanged = true;\n decodedTables[tableName] = { ...table, columns: decodedColumns };\n } else {\n decodedTables[tableName] = table;\n }\n }\n\n if (!tablesChanged) {\n return contract;\n }\n\n // The spread widens to SqlContract<SqlStorage>, but this transformation only\n // decodes tagged bigint defaults for bigint-like columns and preserves all\n // other properties of T.\n return {\n ...contract,\n storage: {\n ...contract.storage,\n tables: decodedTables,\n },\n } as T;\n}\n\nexport function normalizeContract(contract: unknown): SqlContract<SqlStorage> {\n if (typeof contract !== 'object' || contract === null) {\n return contract as SqlContract<SqlStorage>;\n }\n\n const contractObj = contract as Record<string, unknown>;\n\n let normalizedStorage = contractObj['storage'];\n if (normalizedStorage && typeof normalizedStorage === 'object' && normalizedStorage !== null) {\n const storage = normalizedStorage as Record<string, unknown>;\n const tables = storage['tables'] as Record<string, unknown> | undefined;\n\n if (tables) {\n const normalizedTables: Record<string, unknown> = {};\n for (const [tableName, table] of Object.entries(tables)) {\n const tableObj = table as Record<string, unknown>;\n const columns = tableObj['columns'] as Record<string, unknown> | undefined;\n\n if (columns) {\n const normalizedColumns: Record<string, unknown> = {};\n for (const [columnName, column] of Object.entries(columns)) {\n const columnObj = column as Record<string, unknown>;\n normalizedColumns[columnName] = {\n ...columnObj,\n nullable: columnObj['nullable'] ?? false,\n };\n }\n\n // Normalize foreign keys: add constraint/index defaults if missing\n const rawForeignKeys = (tableObj['foreignKeys'] ?? []) as Array<Record<string, unknown>>;\n const normalizedForeignKeys = rawForeignKeys.map((fk) => ({\n ...fk,\n ...applyFkDefaults({\n constraint: typeof fk['constraint'] === 'boolean' ? fk['constraint'] : undefined,\n index: typeof fk['index'] === 'boolean' ? fk['index'] : undefined,\n }),\n }));\n\n normalizedTables[tableName] = {\n ...tableObj,\n columns: normalizedColumns,\n uniques: tableObj['uniques'] ?? [],\n indexes: tableObj['indexes'] ?? [],\n foreignKeys: normalizedForeignKeys,\n };\n } else {\n normalizedTables[tableName] = tableObj;\n }\n }\n\n normalizedStorage = {\n ...storage,\n tables: normalizedTables,\n };\n }\n }\n\n let normalizedModels = contractObj['models'];\n if (normalizedModels && typeof normalizedModels === 'object' && normalizedModels !== null) {\n const models = normalizedModels as Record<string, unknown>;\n const normalizedModelsObj: Record<string, unknown> = {};\n for (const [modelName, model] of Object.entries(models)) {\n const modelObj = model as Record<string, unknown>;\n normalizedModelsObj[modelName] = {\n ...modelObj,\n relations: modelObj['relations'] ?? {},\n };\n }\n normalizedModels = normalizedModelsObj;\n }\n\n return {\n ...contractObj,\n models: normalizedModels,\n relations: contractObj['relations'] ?? {},\n storage: normalizedStorage,\n extensionPacks: contractObj['extensionPacks'] ?? {},\n capabilities: contractObj['capabilities'] ?? {},\n meta: contractObj['meta'] ?? {},\n sources: contractObj['sources'] ?? {},\n } as SqlContract<SqlStorage>;\n}\n\nexport function validateContract<TContract extends SqlContract<SqlStorage>>(\n value: unknown,\n): TContract {\n const normalized = normalizeContract(value);\n const structurallyValid = validateSqlContract<SqlContract<SqlStorage>>(normalized);\n validateContractLogic(structurallyValid);\n\n const semanticErrors = validateStorageSemantics(structurallyValid.storage);\n if (semanticErrors.length > 0) {\n throw new Error(`Contract semantic validation failed: ${semanticErrors.join('; ')}`);\n }\n\n const existingMappings = (structurallyValid as { mappings?: Partial<SqlMappings> }).mappings;\n const defaultMappings = computeDefaultMappings(\n structurallyValid.models as Record<string, ModelDefinition>,\n );\n const mappings = mergeMappings(defaultMappings, existingMappings);\n\n const contractWithMappings = {\n ...structurallyValid,\n mappings,\n };\n\n return decodeContractDefaults(contractWithMappings) as TContract;\n}\n"],"mappings":";;;;;AAsBA,SAAS,uBAAuB,QAA2D;CACzF,MAAMA,eAAuC,EAAE;CAC/C,MAAMC,eAAuC,EAAE;CAC/C,MAAMC,gBAAwD,EAAE;CAChE,MAAMC,gBAAwD,EAAE;AAEhE,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,EAAE;EACvD,MAAM,YAAY,MAAM,QAAQ;AAChC,eAAa,aAAa;AAC1B,eAAa,aAAa;EAE1B,MAAMC,qBAA6C,EAAE;AACrD,OAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,MAAM,OAAO,EAAE;GAC7D,MAAM,aAAa,MAAM;AACzB,sBAAmB,aAAa;AAChC,OAAI,CAAC,cAAc,WACjB,eAAc,aAAa,EAAE;AAE/B,iBAAc,WAAW,cAAc;;AAGzC,gBAAc,aAAa;;AAG7B,QAAO;EACL;EACA;EACA;EACA;EACA,YAAY,EAAE;EACd,gBAAgB,EAAE;EACnB;;AAGH,SAAS,2BACP,cACA,cACA;AACA,MAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,aAAa,CACvD,KAAI,aAAa,WAAW,MAC1B,OAAM,IAAI,MACR,4CAA4C,MAAM,IAAI,MAAM,mCAC7D;AAGL,MAAK,MAAM,CAAC,OAAO,UAAU,OAAO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E;EACtC;;AAGH,SAAgB,iBACd,OACW;CAEX,MAAM,oBAAoB,oBADP,kBAAkB,MAAM,CACuC;AAClF,uBAAsB,kBAAkB;CAExC,MAAM,iBAAiB,yBAAyB,kBAAkB,QAAQ;AAC1E,KAAI,eAAe,SAAS,EAC1B,OAAM,IAAI,MAAM,wCAAwC,eAAe,KAAK,KAAK,GAAG;CAGtF,MAAM,mBAAoB,kBAA0D;CAIpF,MAAM,WAAW,cAHO,uBACtB,kBAAkB,OACnB,EAC+C,iBAAiB;AAOjE,QAAO,uBALsB;EAC3B,GAAG;EACH;EACD,CAEkD"}
|
|
1
|
+
{"version":3,"file":"validate.mjs","names":["modelToTable: Record<string, string>","tableToModel: Record<string, string>","fieldToColumn: Record<string, Record<string, string>>","columnToField: Record<string, Record<string, string>>","modelFieldToColumn: Record<string, string>","decodedTables: Record<string, StorageTable>","decodedColumns: Record<string, StorageColumn>","normalizedTables: Record<string, unknown>","normalizedColumns: Record<string, unknown>","normalizedModelsObj: Record<string, unknown>"],"sources":["../src/construct.ts","../src/validate.ts"],"sourcesContent":["import type { ModelDefinition, SqlContract, SqlMappings, SqlStorage } from './types';\n\ntype ResolvedMappings = {\n modelToTable: Record<string, string>;\n tableToModel: Record<string, string>;\n fieldToColumn: Record<string, Record<string, string>>;\n columnToField: Record<string, Record<string, string>>;\n};\n\nfunction computeDefaultMappings(models: Record<string, ModelDefinition>): ResolvedMappings {\n const modelToTable: Record<string, string> = {};\n const tableToModel: Record<string, string> = {};\n const fieldToColumn: Record<string, Record<string, string>> = {};\n const columnToField: Record<string, Record<string, string>> = {};\n\n for (const [modelName, model] of Object.entries(models)) {\n const tableName = model.storage.table;\n modelToTable[modelName] = tableName;\n tableToModel[tableName] = modelName;\n\n const modelFieldToColumn: Record<string, string> = {};\n for (const [fieldName, field] of Object.entries(model.fields)) {\n const columnName = field.column;\n modelFieldToColumn[fieldName] = columnName;\n if (!columnToField[tableName]) {\n columnToField[tableName] = {};\n }\n columnToField[tableName][columnName] = fieldName;\n }\n\n fieldToColumn[modelName] = modelFieldToColumn;\n }\n\n return {\n modelToTable,\n tableToModel,\n fieldToColumn,\n columnToField,\n };\n}\n\nfunction assertInverseModelMappings(\n modelToTable: Record<string, string>,\n tableToModel: Record<string, string>,\n): void {\n for (const [model, table] of Object.entries(modelToTable)) {\n if (tableToModel[table] !== model) {\n throw new Error(\n `Mappings override mismatch: modelToTable.${model}=\"${table}\" is not mirrored in tableToModel`,\n );\n }\n }\n for (const [table, model] of Object.entries(tableToModel)) {\n if (modelToTable[model] !== table) {\n throw new Error(\n `Mappings override mismatch: tableToModel.${table}=\"${model}\" is not mirrored in modelToTable`,\n );\n }\n }\n}\n\nfunction assertInverseFieldMappings(\n fieldToColumn: Record<string, Record<string, string>>,\n columnToField: Record<string, Record<string, string>>,\n modelToTable: Record<string, string>,\n tableToModel: Record<string, string>,\n): void {\n for (const [model, fields] of Object.entries(fieldToColumn)) {\n const table = modelToTable[model];\n if (!table) {\n throw new Error(\n `Mappings override mismatch: fieldToColumn references unknown model \"${model}\"`,\n );\n }\n const reverseFields = columnToField[table];\n if (!reverseFields) {\n throw new Error(\n `Mappings override mismatch: columnToField is missing table \"${table}\" for model \"${model}\"`,\n );\n }\n for (const [field, column] of Object.entries(fields)) {\n if (reverseFields[column] !== field) {\n throw new Error(\n `Mappings override mismatch: fieldToColumn.${model}.${field}=\"${column}\" is not mirrored in columnToField.${table}`,\n );\n }\n }\n }\n\n for (const [table, columns] of Object.entries(columnToField)) {\n const model = tableToModel[table];\n if (!model) {\n throw new Error(\n `Mappings override mismatch: columnToField references unknown table \"${table}\"`,\n );\n }\n const forwardFields = fieldToColumn[model];\n if (!forwardFields) {\n throw new Error(\n `Mappings override mismatch: fieldToColumn is missing model \"${model}\" for table \"${table}\"`,\n );\n }\n for (const [column, field] of Object.entries(columns)) {\n if (forwardFields[field] !== column) {\n throw new Error(\n `Mappings override mismatch: columnToField.${table}.${column}=\"${field}\" is not mirrored in fieldToColumn.${model}`,\n );\n }\n }\n }\n}\n\nfunction mergeMappings(\n defaults: ResolvedMappings,\n existingMappings?: Partial<SqlMappings>,\n): ResolvedMappings {\n const hasModelToTable = existingMappings?.modelToTable !== undefined;\n const hasTableToModel = existingMappings?.tableToModel !== undefined;\n if (hasModelToTable !== hasTableToModel) {\n throw new Error(\n 'Mappings override mismatch: modelToTable and tableToModel must be provided together',\n );\n }\n\n const hasFieldToColumn = existingMappings?.fieldToColumn !== undefined;\n const hasColumnToField = existingMappings?.columnToField !== undefined;\n if (hasFieldToColumn !== hasColumnToField) {\n throw new Error(\n 'Mappings override mismatch: fieldToColumn and columnToField must be provided together',\n );\n }\n\n const modelToTable: Record<string, string> = hasModelToTable\n ? (existingMappings?.modelToTable ?? {})\n : defaults.modelToTable;\n const tableToModel: Record<string, string> = hasTableToModel\n ? (existingMappings?.tableToModel ?? {})\n : defaults.tableToModel;\n assertInverseModelMappings(modelToTable, tableToModel);\n\n const fieldToColumn: Record<string, Record<string, string>> = hasFieldToColumn\n ? (existingMappings?.fieldToColumn ?? {})\n : defaults.fieldToColumn;\n const columnToField: Record<string, Record<string, string>> = hasColumnToField\n ? (existingMappings?.columnToField ?? {})\n : defaults.columnToField;\n assertInverseFieldMappings(fieldToColumn, columnToField, modelToTable, tableToModel);\n\n return {\n modelToTable,\n tableToModel,\n fieldToColumn,\n columnToField,\n };\n}\n\ntype ValidatedContractInput = SqlContract<SqlStorage> & { _generated?: unknown };\n\nfunction stripGenerated(obj: ValidatedContractInput): Omit<ValidatedContractInput, '_generated'> {\n const input = obj as unknown as Record<string, unknown>;\n const { _generated: _, ...rest } = input;\n return rest as Omit<ValidatedContractInput, '_generated'>;\n}\n\nexport function constructContract<TContract extends SqlContract<SqlStorage>>(\n input: ValidatedContractInput,\n): TContract {\n const existingMappings = (input as { mappings?: Partial<SqlMappings> }).mappings;\n const defaultMappings = computeDefaultMappings(input.models as Record<string, ModelDefinition>);\n const mappings = mergeMappings(defaultMappings, existingMappings);\n\n const contractWithMappings = {\n ...stripGenerated(input),\n mappings,\n };\n\n return contractWithMappings as TContract;\n}\n","import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';\nimport { isTaggedBigInt, isTaggedRaw } from '@prisma-next/contract/types';\nimport { constructContract } from './construct';\nimport type { SqlContract, SqlStorage, StorageColumn, StorageTable } from './types';\nimport { applyFkDefaults } from './types';\nimport { validateSqlContract, validateStorageSemantics } from './validators';\n\nfunction validateContractLogic(contract: SqlContract<SqlStorage>): void {\n const tableNames = new Set(Object.keys(contract.storage.tables));\n\n for (const [tableName, table] of Object.entries(contract.storage.tables)) {\n const columnNames = new Set(Object.keys(table.columns));\n\n if (table.primaryKey) {\n for (const colName of table.primaryKey.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const unique of table.uniques) {\n for (const colName of unique.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`,\n );\n }\n }\n }\n\n for (const index of table.indexes) {\n for (const colName of index.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(`Table \"${tableName}\" index references non-existent column \"${colName}\"`);\n }\n }\n }\n\n for (const [colName, column] of Object.entries(table.columns)) {\n if (!column.nullable && column.default?.kind === 'literal' && column.default.value === null) {\n throw new Error(\n `Table \"${tableName}\" column \"${colName}\" is NOT NULL but has a literal null default`,\n );\n }\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n if (!columnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`,\n );\n }\n }\n\n if (!tableNames.has(fk.references.table)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n );\n }\n\n const referencedTable = contract.storage.tables[\n fk.references.table\n ] as (typeof contract.storage.tables)[string];\n const referencedColumnNames = new Set(Object.keys(referencedTable.columns));\n for (const colName of fk.references.columns) {\n if (!referencedColumnNames.has(colName)) {\n throw new Error(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.references.table}\"`,\n );\n }\n }\n\n if (fk.columns.length !== fk.references.columns.length) {\n throw new Error(\n `Table \"${tableName}\" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,\n );\n }\n }\n }\n}\n\nconst BIGINT_NATIVE_TYPES = new Set(['bigint', 'int8']);\n\nexport function isBigIntColumn(column: StorageColumn): boolean {\n const nativeType = column.nativeType?.toLowerCase() ?? '';\n if (BIGINT_NATIVE_TYPES.has(nativeType)) return true;\n const codecId = column.codecId?.toLowerCase() ?? '';\n return codecId.includes('int8') || codecId.includes('bigint');\n}\n\nexport function decodeDefaultLiteralValue(\n value: ColumnDefaultLiteralInputValue,\n column: StorageColumn,\n tableName: string,\n columnName: string,\n): ColumnDefaultLiteralInputValue {\n if (value instanceof Date) {\n return value;\n }\n if (isTaggedRaw(value)) {\n return value.value;\n }\n if (isTaggedBigInt(value)) {\n if (!isBigIntColumn(column)) {\n return value;\n }\n try {\n return BigInt(value.value);\n } catch {\n throw new Error(\n `Invalid tagged bigint for default value on \"${tableName}.${columnName}\": \"${value.value}\" is not a valid integer`,\n );\n }\n }\n return value;\n}\n\nexport function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contract: T): T {\n const tables = contract.storage.tables;\n let tablesChanged = false;\n const decodedTables: Record<string, StorageTable> = {};\n\n for (const [tableName, table] of Object.entries(tables)) {\n let columnsChanged = false;\n const decodedColumns: Record<string, StorageColumn> = {};\n\n for (const [columnName, column] of Object.entries(table.columns)) {\n if (column.default?.kind === 'literal') {\n const decodedValue = decodeDefaultLiteralValue(\n column.default.value,\n column,\n tableName,\n columnName,\n );\n if (decodedValue !== column.default.value) {\n columnsChanged = true;\n decodedColumns[columnName] = {\n ...column,\n default: { kind: 'literal', value: decodedValue },\n };\n continue;\n }\n }\n decodedColumns[columnName] = column;\n }\n\n if (columnsChanged) {\n tablesChanged = true;\n decodedTables[tableName] = { ...table, columns: decodedColumns };\n } else {\n decodedTables[tableName] = table;\n }\n }\n\n if (!tablesChanged) {\n return contract;\n }\n\n // The spread widens to SqlContract<SqlStorage>, but this transformation only\n // decodes tagged bigint defaults for bigint-like columns and preserves all\n // other properties of T.\n return {\n ...contract,\n storage: {\n ...contract.storage,\n tables: decodedTables,\n },\n } as T;\n}\n\nexport function normalizeContract(contract: unknown): SqlContract<SqlStorage> {\n if (typeof contract !== 'object' || contract === null) {\n return contract as SqlContract<SqlStorage>;\n }\n\n const contractObj = contract as Record<string, unknown>;\n\n let normalizedStorage = contractObj['storage'];\n if (normalizedStorage && typeof normalizedStorage === 'object' && normalizedStorage !== null) {\n const storage = normalizedStorage as Record<string, unknown>;\n const tables = storage['tables'] as Record<string, unknown> | undefined;\n\n if (tables) {\n const normalizedTables: Record<string, unknown> = {};\n for (const [tableName, table] of Object.entries(tables)) {\n const tableObj = table as Record<string, unknown>;\n const columns = tableObj['columns'] as Record<string, unknown> | undefined;\n\n if (columns) {\n const normalizedColumns: Record<string, unknown> = {};\n for (const [columnName, column] of Object.entries(columns)) {\n const columnObj = column as Record<string, unknown>;\n normalizedColumns[columnName] = {\n ...columnObj,\n nullable: columnObj['nullable'] ?? false,\n };\n }\n\n // Normalize foreign keys: add constraint/index defaults if missing\n const rawForeignKeys = (tableObj['foreignKeys'] ?? []) as Array<Record<string, unknown>>;\n const normalizedForeignKeys = rawForeignKeys.map((fk) => ({\n ...fk,\n ...applyFkDefaults({\n constraint: typeof fk['constraint'] === 'boolean' ? fk['constraint'] : undefined,\n index: typeof fk['index'] === 'boolean' ? fk['index'] : undefined,\n }),\n }));\n\n normalizedTables[tableName] = {\n ...tableObj,\n columns: normalizedColumns,\n uniques: tableObj['uniques'] ?? [],\n indexes: tableObj['indexes'] ?? [],\n foreignKeys: normalizedForeignKeys,\n };\n } else {\n normalizedTables[tableName] = tableObj;\n }\n }\n\n normalizedStorage = {\n ...storage,\n tables: normalizedTables,\n };\n }\n }\n\n let normalizedModels = contractObj['models'];\n if (normalizedModels && typeof normalizedModels === 'object' && normalizedModels !== null) {\n const models = normalizedModels as Record<string, unknown>;\n const normalizedModelsObj: Record<string, unknown> = {};\n for (const [modelName, model] of Object.entries(models)) {\n const modelObj = model as Record<string, unknown>;\n normalizedModelsObj[modelName] = {\n ...modelObj,\n relations: modelObj['relations'] ?? {},\n };\n }\n normalizedModels = normalizedModelsObj;\n }\n\n return {\n ...contractObj,\n models: normalizedModels,\n relations: contractObj['relations'] ?? {},\n storage: normalizedStorage,\n extensionPacks: contractObj['extensionPacks'] ?? {},\n capabilities: contractObj['capabilities'] ?? {},\n meta: contractObj['meta'] ?? {},\n sources: contractObj['sources'] ?? {},\n } as SqlContract<SqlStorage>;\n}\n\nexport function validateContract<TContract extends SqlContract<SqlStorage>>(\n value: unknown,\n): TContract {\n const normalized = normalizeContract(value);\n const structurallyValid = validateSqlContract<SqlContract<SqlStorage>>(normalized);\n validateContractLogic(structurallyValid);\n\n const semanticErrors = validateStorageSemantics(structurallyValid.storage);\n if (semanticErrors.length > 0) {\n throw new Error(`Contract semantic validation failed: ${semanticErrors.join('; ')}`);\n }\n\n const constructed = constructContract<TContract>(structurallyValid);\n return decodeContractDefaults(constructed) as TContract;\n}\n"],"mappings":";;;;;AASA,SAAS,uBAAuB,QAA2D;CACzF,MAAMA,eAAuC,EAAE;CAC/C,MAAMC,eAAuC,EAAE;CAC/C,MAAMC,gBAAwD,EAAE;CAChE,MAAMC,gBAAwD,EAAE;AAEhE,MAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,EAAE;EACvD,MAAM,YAAY,MAAM,QAAQ;AAChC,eAAa,aAAa;AAC1B,eAAa,aAAa;EAE1B,MAAMC,qBAA6C,EAAE;AACrD,OAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,MAAM,OAAO,EAAE;GAC7D,MAAM,aAAa,MAAM;AACzB,sBAAmB,aAAa;AAChC,OAAI,CAAC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AqB,MAAM;EACzF,MAAM,SAAS;EACf,MAAMC,sBAA+C,EAAE;AACvD,OAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,OAAO,EAAE;GACvD,MAAM,WAAW;AACjB,uBAAoB,aAAa;IAC/B,GAAG;IACH,WAAW,SAAS,gBAAgB,EAAE;IACvC;;AAEH,qBAAmB;;AAGrB,QAAO;EACL,GAAG;EACH,QAAQ;EACR,WAAW,YAAY,gBAAgB,EAAE;EACzC,SAAS;EACT,gBAAgB,YAAY,qBAAqB,EAAE;EACnD,cAAc,YAAY,mBAAmB,EAAE;EAC/C,MAAM,YAAY,WAAW,EAAE;EAC/B,SAAS,YAAY,cAAc,EAAE;EACtC;;AAGH,SAAgB,iBACd,OACW;CAEX,MAAM,oBAAoB,oBADP,kBAAkB,MAAM,CACuC;AAClF,uBAAsB,kBAAkB;CAExC,MAAM,iBAAiB,yBAAyB,kBAAkB,QAAQ;AAC1E,KAAI,eAAe,SAAS,EAC1B,OAAM,IAAI,MAAM,wCAAwC,eAAe,KAAK,KAAK,GAAG;AAItF,QAAO,uBADa,kBAA6B,kBAAkB,CACzB"}
|
package/dist/validators.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { S as SqlStorage, _ as ReferentialAction, b as SqlContract, c as ForeignKey, f as ModelDefinition, u as ForeignKeyReferences } from "./types-CcCSXOlR.mjs";
|
|
2
2
|
import * as arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
|
|
3
3
|
import * as arktype_internal_variants_string_ts0 from "arktype/internal/variants/string.ts";
|
|
4
4
|
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@prisma-next/sql-contract",
|
|
3
|
-
"version": "0.3.0-dev.
|
|
3
|
+
"version": "0.3.0-dev.75",
|
|
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.75"
|
|
10
10
|
},
|
|
11
11
|
"devDependencies": {
|
|
12
12
|
"tsdown": "0.18.4",
|
package/src/construct.ts
ADDED
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import type { ModelDefinition, SqlContract, SqlMappings, SqlStorage } from './types';
|
|
2
|
+
|
|
3
|
+
type ResolvedMappings = {
|
|
4
|
+
modelToTable: Record<string, string>;
|
|
5
|
+
tableToModel: Record<string, string>;
|
|
6
|
+
fieldToColumn: Record<string, Record<string, string>>;
|
|
7
|
+
columnToField: Record<string, Record<string, string>>;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
function computeDefaultMappings(models: Record<string, ModelDefinition>): ResolvedMappings {
|
|
11
|
+
const modelToTable: Record<string, string> = {};
|
|
12
|
+
const tableToModel: Record<string, string> = {};
|
|
13
|
+
const fieldToColumn: Record<string, Record<string, string>> = {};
|
|
14
|
+
const columnToField: Record<string, Record<string, string>> = {};
|
|
15
|
+
|
|
16
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
17
|
+
const tableName = model.storage.table;
|
|
18
|
+
modelToTable[modelName] = tableName;
|
|
19
|
+
tableToModel[tableName] = modelName;
|
|
20
|
+
|
|
21
|
+
const modelFieldToColumn: Record<string, string> = {};
|
|
22
|
+
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
23
|
+
const columnName = field.column;
|
|
24
|
+
modelFieldToColumn[fieldName] = columnName;
|
|
25
|
+
if (!columnToField[tableName]) {
|
|
26
|
+
columnToField[tableName] = {};
|
|
27
|
+
}
|
|
28
|
+
columnToField[tableName][columnName] = fieldName;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fieldToColumn[modelName] = modelFieldToColumn;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
modelToTable,
|
|
36
|
+
tableToModel,
|
|
37
|
+
fieldToColumn,
|
|
38
|
+
columnToField,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function assertInverseModelMappings(
|
|
43
|
+
modelToTable: Record<string, string>,
|
|
44
|
+
tableToModel: Record<string, string>,
|
|
45
|
+
): void {
|
|
46
|
+
for (const [model, table] of Object.entries(modelToTable)) {
|
|
47
|
+
if (tableToModel[table] !== model) {
|
|
48
|
+
throw new Error(
|
|
49
|
+
`Mappings override mismatch: modelToTable.${model}="${table}" is not mirrored in tableToModel`,
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
for (const [table, model] of Object.entries(tableToModel)) {
|
|
54
|
+
if (modelToTable[model] !== table) {
|
|
55
|
+
throw new Error(
|
|
56
|
+
`Mappings override mismatch: tableToModel.${table}="${model}" is not mirrored in modelToTable`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function assertInverseFieldMappings(
|
|
63
|
+
fieldToColumn: Record<string, Record<string, string>>,
|
|
64
|
+
columnToField: Record<string, Record<string, string>>,
|
|
65
|
+
modelToTable: Record<string, string>,
|
|
66
|
+
tableToModel: Record<string, string>,
|
|
67
|
+
): void {
|
|
68
|
+
for (const [model, fields] of Object.entries(fieldToColumn)) {
|
|
69
|
+
const table = modelToTable[model];
|
|
70
|
+
if (!table) {
|
|
71
|
+
throw new Error(
|
|
72
|
+
`Mappings override mismatch: fieldToColumn references unknown model "${model}"`,
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
const reverseFields = columnToField[table];
|
|
76
|
+
if (!reverseFields) {
|
|
77
|
+
throw new Error(
|
|
78
|
+
`Mappings override mismatch: columnToField is missing table "${table}" for model "${model}"`,
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
for (const [field, column] of Object.entries(fields)) {
|
|
82
|
+
if (reverseFields[column] !== field) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Mappings override mismatch: fieldToColumn.${model}.${field}="${column}" is not mirrored in columnToField.${table}`,
|
|
85
|
+
);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
for (const [table, columns] of Object.entries(columnToField)) {
|
|
91
|
+
const model = tableToModel[table];
|
|
92
|
+
if (!model) {
|
|
93
|
+
throw new Error(
|
|
94
|
+
`Mappings override mismatch: columnToField references unknown table "${table}"`,
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
const forwardFields = fieldToColumn[model];
|
|
98
|
+
if (!forwardFields) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`Mappings override mismatch: fieldToColumn is missing model "${model}" for table "${table}"`,
|
|
101
|
+
);
|
|
102
|
+
}
|
|
103
|
+
for (const [column, field] of Object.entries(columns)) {
|
|
104
|
+
if (forwardFields[field] !== column) {
|
|
105
|
+
throw new Error(
|
|
106
|
+
`Mappings override mismatch: columnToField.${table}.${column}="${field}" is not mirrored in fieldToColumn.${model}`,
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function mergeMappings(
|
|
114
|
+
defaults: ResolvedMappings,
|
|
115
|
+
existingMappings?: Partial<SqlMappings>,
|
|
116
|
+
): ResolvedMappings {
|
|
117
|
+
const hasModelToTable = existingMappings?.modelToTable !== undefined;
|
|
118
|
+
const hasTableToModel = existingMappings?.tableToModel !== undefined;
|
|
119
|
+
if (hasModelToTable !== hasTableToModel) {
|
|
120
|
+
throw new Error(
|
|
121
|
+
'Mappings override mismatch: modelToTable and tableToModel must be provided together',
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const hasFieldToColumn = existingMappings?.fieldToColumn !== undefined;
|
|
126
|
+
const hasColumnToField = existingMappings?.columnToField !== undefined;
|
|
127
|
+
if (hasFieldToColumn !== hasColumnToField) {
|
|
128
|
+
throw new Error(
|
|
129
|
+
'Mappings override mismatch: fieldToColumn and columnToField must be provided together',
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const modelToTable: Record<string, string> = hasModelToTable
|
|
134
|
+
? (existingMappings?.modelToTable ?? {})
|
|
135
|
+
: defaults.modelToTable;
|
|
136
|
+
const tableToModel: Record<string, string> = hasTableToModel
|
|
137
|
+
? (existingMappings?.tableToModel ?? {})
|
|
138
|
+
: defaults.tableToModel;
|
|
139
|
+
assertInverseModelMappings(modelToTable, tableToModel);
|
|
140
|
+
|
|
141
|
+
const fieldToColumn: Record<string, Record<string, string>> = hasFieldToColumn
|
|
142
|
+
? (existingMappings?.fieldToColumn ?? {})
|
|
143
|
+
: defaults.fieldToColumn;
|
|
144
|
+
const columnToField: Record<string, Record<string, string>> = hasColumnToField
|
|
145
|
+
? (existingMappings?.columnToField ?? {})
|
|
146
|
+
: defaults.columnToField;
|
|
147
|
+
assertInverseFieldMappings(fieldToColumn, columnToField, modelToTable, tableToModel);
|
|
148
|
+
|
|
149
|
+
return {
|
|
150
|
+
modelToTable,
|
|
151
|
+
tableToModel,
|
|
152
|
+
fieldToColumn,
|
|
153
|
+
columnToField,
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
type ValidatedContractInput = SqlContract<SqlStorage> & { _generated?: unknown };
|
|
158
|
+
|
|
159
|
+
function stripGenerated(obj: ValidatedContractInput): Omit<ValidatedContractInput, '_generated'> {
|
|
160
|
+
const input = obj as unknown as Record<string, unknown>;
|
|
161
|
+
const { _generated: _, ...rest } = input;
|
|
162
|
+
return rest as Omit<ValidatedContractInput, '_generated'>;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
export function constructContract<TContract extends SqlContract<SqlStorage>>(
|
|
166
|
+
input: ValidatedContractInput,
|
|
167
|
+
): TContract {
|
|
168
|
+
const existingMappings = (input as { mappings?: Partial<SqlMappings> }).mappings;
|
|
169
|
+
const defaultMappings = computeDefaultMappings(input.models as Record<string, ModelDefinition>);
|
|
170
|
+
const mappings = mergeMappings(defaultMappings, existingMappings);
|
|
171
|
+
|
|
172
|
+
const contractWithMappings = {
|
|
173
|
+
...stripGenerated(input),
|
|
174
|
+
mappings,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
return contractWithMappings as TContract;
|
|
178
|
+
}
|
package/src/exports/types.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
export type {
|
|
2
|
+
CodecTypesOf,
|
|
3
|
+
ContractWithTypeMaps,
|
|
2
4
|
ExtractCodecTypes,
|
|
3
5
|
ExtractOperationTypes,
|
|
6
|
+
ExtractTypeMapsFromContract,
|
|
4
7
|
ForeignKey,
|
|
5
8
|
ForeignKeyOptions,
|
|
6
9
|
ForeignKeyReferences,
|
|
@@ -8,14 +11,19 @@ export type {
|
|
|
8
11
|
ModelDefinition,
|
|
9
12
|
ModelField,
|
|
10
13
|
ModelStorage,
|
|
14
|
+
OperationTypesOf,
|
|
11
15
|
PrimaryKey,
|
|
12
16
|
ReferentialAction,
|
|
17
|
+
ResolveCodecTypes,
|
|
18
|
+
ResolveOperationTypes,
|
|
13
19
|
SqlContract,
|
|
14
20
|
SqlMappings,
|
|
15
21
|
SqlStorage,
|
|
16
22
|
StorageColumn,
|
|
17
23
|
StorageTable,
|
|
18
24
|
StorageTypeInstance,
|
|
25
|
+
TypeMaps,
|
|
26
|
+
TypeMapsPhantomKey,
|
|
19
27
|
UniqueConstraint,
|
|
20
28
|
} from '../types';
|
|
21
29
|
|
package/src/types.ts
CHANGED
|
@@ -138,17 +138,11 @@ export type SqlMappings = {
|
|
|
138
138
|
readonly tableToModel?: Record<string, string>;
|
|
139
139
|
readonly fieldToColumn?: Record<string, Record<string, string>>;
|
|
140
140
|
readonly columnToField?: Record<string, Record<string, string>>;
|
|
141
|
-
readonly codecTypes: Record<string, { readonly output: unknown }>;
|
|
142
|
-
readonly operationTypes: Record<string, Record<string, unknown>>;
|
|
143
141
|
};
|
|
144
142
|
|
|
145
143
|
export const DEFAULT_FK_CONSTRAINT = true;
|
|
146
144
|
export const DEFAULT_FK_INDEX = true;
|
|
147
145
|
|
|
148
|
-
/**
|
|
149
|
-
* Resolves foreign key `constraint` and `index` fields to their effective boolean values,
|
|
150
|
-
* falling back through optional override defaults, then to the global defaults.
|
|
151
|
-
*/
|
|
152
146
|
export function applyFkDefaults(
|
|
153
147
|
fk: { constraint?: boolean | undefined; index?: boolean | undefined },
|
|
154
148
|
overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },
|
|
@@ -159,6 +153,36 @@ export function applyFkDefaults(
|
|
|
159
153
|
};
|
|
160
154
|
}
|
|
161
155
|
|
|
156
|
+
export type TypeMaps<
|
|
157
|
+
TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,
|
|
158
|
+
TOperationTypes extends Record<string, unknown> = Record<string, never>,
|
|
159
|
+
> = {
|
|
160
|
+
readonly codecTypes: TCodecTypes;
|
|
161
|
+
readonly operationTypes: TOperationTypes;
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
export type CodecTypesOf<T> = [T] extends [never]
|
|
165
|
+
? Record<string, never>
|
|
166
|
+
: T extends { readonly codecTypes: infer C }
|
|
167
|
+
? C extends Record<string, { output: unknown }>
|
|
168
|
+
? C
|
|
169
|
+
: Record<string, never>
|
|
170
|
+
: Record<string, never>;
|
|
171
|
+
|
|
172
|
+
export type OperationTypesOf<T> = [T] extends [never]
|
|
173
|
+
? Record<string, never>
|
|
174
|
+
: T extends { readonly operationTypes: infer O }
|
|
175
|
+
? O extends Record<string, unknown>
|
|
176
|
+
? O
|
|
177
|
+
: Record<string, never>
|
|
178
|
+
: Record<string, never>;
|
|
179
|
+
|
|
180
|
+
export type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
|
|
181
|
+
|
|
182
|
+
export type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {
|
|
183
|
+
readonly [K in TypeMapsPhantomKey]?: TTypeMaps;
|
|
184
|
+
};
|
|
185
|
+
|
|
162
186
|
export type SqlContract<
|
|
163
187
|
S extends SqlStorage = SqlStorage,
|
|
164
188
|
M extends Record<string, unknown> = Record<string, unknown>,
|
|
@@ -176,8 +200,17 @@ export type SqlContract<
|
|
|
176
200
|
readonly execution?: ExecutionSection;
|
|
177
201
|
};
|
|
178
202
|
|
|
179
|
-
export type
|
|
180
|
-
|
|
203
|
+
export type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T
|
|
204
|
+
? NonNullable<T[TypeMapsPhantomKey & keyof T]>
|
|
205
|
+
: never;
|
|
206
|
+
|
|
207
|
+
export type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
208
|
+
export type ExtractOperationTypes<T> = OperationTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
209
|
+
|
|
210
|
+
export type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]
|
|
211
|
+
? ExtractCodecTypes<TContract>
|
|
212
|
+
: CodecTypesOf<TTypeMaps>;
|
|
181
213
|
|
|
182
|
-
export type
|
|
183
|
-
TContract
|
|
214
|
+
export type ResolveOperationTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]
|
|
215
|
+
? ExtractOperationTypes<TContract>
|
|
216
|
+
: OperationTypesOf<TTypeMaps>;
|
package/src/validate.ts
CHANGED
|
@@ -1,176 +1,10 @@
|
|
|
1
1
|
import type { ColumnDefaultLiteralInputValue } from '@prisma-next/contract/types';
|
|
2
2
|
import { isTaggedBigInt, isTaggedRaw } from '@prisma-next/contract/types';
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
SqlContract,
|
|
6
|
-
SqlMappings,
|
|
7
|
-
SqlStorage,
|
|
8
|
-
StorageColumn,
|
|
9
|
-
StorageTable,
|
|
10
|
-
} from './types';
|
|
3
|
+
import { constructContract } from './construct';
|
|
4
|
+
import type { SqlContract, SqlStorage, StorageColumn, StorageTable } from './types';
|
|
11
5
|
import { applyFkDefaults } from './types';
|
|
12
6
|
import { validateSqlContract, validateStorageSemantics } from './validators';
|
|
13
7
|
|
|
14
|
-
type ResolvedMappings = {
|
|
15
|
-
modelToTable: Record<string, string>;
|
|
16
|
-
tableToModel: Record<string, string>;
|
|
17
|
-
fieldToColumn: Record<string, Record<string, string>>;
|
|
18
|
-
columnToField: Record<string, Record<string, string>>;
|
|
19
|
-
codecTypes: Record<string, { readonly output: unknown }>;
|
|
20
|
-
operationTypes: Record<string, Record<string, unknown>>;
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
function computeDefaultMappings(models: Record<string, ModelDefinition>): ResolvedMappings {
|
|
24
|
-
const modelToTable: Record<string, string> = {};
|
|
25
|
-
const tableToModel: Record<string, string> = {};
|
|
26
|
-
const fieldToColumn: Record<string, Record<string, string>> = {};
|
|
27
|
-
const columnToField: Record<string, Record<string, string>> = {};
|
|
28
|
-
|
|
29
|
-
for (const [modelName, model] of Object.entries(models)) {
|
|
30
|
-
const tableName = model.storage.table;
|
|
31
|
-
modelToTable[modelName] = tableName;
|
|
32
|
-
tableToModel[tableName] = modelName;
|
|
33
|
-
|
|
34
|
-
const modelFieldToColumn: Record<string, string> = {};
|
|
35
|
-
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
36
|
-
const columnName = field.column;
|
|
37
|
-
modelFieldToColumn[fieldName] = columnName;
|
|
38
|
-
if (!columnToField[tableName]) {
|
|
39
|
-
columnToField[tableName] = {};
|
|
40
|
-
}
|
|
41
|
-
columnToField[tableName][columnName] = fieldName;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
fieldToColumn[modelName] = modelFieldToColumn;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return {
|
|
48
|
-
modelToTable,
|
|
49
|
-
tableToModel,
|
|
50
|
-
fieldToColumn,
|
|
51
|
-
columnToField,
|
|
52
|
-
codecTypes: {},
|
|
53
|
-
operationTypes: {},
|
|
54
|
-
};
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function assertInverseModelMappings(
|
|
58
|
-
modelToTable: Record<string, string>,
|
|
59
|
-
tableToModel: Record<string, string>,
|
|
60
|
-
) {
|
|
61
|
-
for (const [model, table] of Object.entries(modelToTable)) {
|
|
62
|
-
if (tableToModel[table] !== model) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`Mappings override mismatch: modelToTable.${model}="${table}" is not mirrored in tableToModel`,
|
|
65
|
-
);
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
for (const [table, model] of Object.entries(tableToModel)) {
|
|
69
|
-
if (modelToTable[model] !== table) {
|
|
70
|
-
throw new Error(
|
|
71
|
-
`Mappings override mismatch: tableToModel.${table}="${model}" is not mirrored in modelToTable`,
|
|
72
|
-
);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
function assertInverseFieldMappings(
|
|
78
|
-
fieldToColumn: Record<string, Record<string, string>>,
|
|
79
|
-
columnToField: Record<string, Record<string, string>>,
|
|
80
|
-
modelToTable: Record<string, string>,
|
|
81
|
-
tableToModel: Record<string, string>,
|
|
82
|
-
) {
|
|
83
|
-
for (const [model, fields] of Object.entries(fieldToColumn)) {
|
|
84
|
-
const table = modelToTable[model];
|
|
85
|
-
if (!table) {
|
|
86
|
-
throw new Error(
|
|
87
|
-
`Mappings override mismatch: fieldToColumn references unknown model "${model}"`,
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
const reverseFields = columnToField[table];
|
|
91
|
-
if (!reverseFields) {
|
|
92
|
-
throw new Error(
|
|
93
|
-
`Mappings override mismatch: columnToField is missing table "${table}" for model "${model}"`,
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
for (const [field, column] of Object.entries(fields)) {
|
|
97
|
-
if (reverseFields[column] !== field) {
|
|
98
|
-
throw new Error(
|
|
99
|
-
`Mappings override mismatch: fieldToColumn.${model}.${field}="${column}" is not mirrored in columnToField.${table}`,
|
|
100
|
-
);
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
for (const [table, columns] of Object.entries(columnToField)) {
|
|
106
|
-
const model = tableToModel[table];
|
|
107
|
-
if (!model) {
|
|
108
|
-
throw new Error(
|
|
109
|
-
`Mappings override mismatch: columnToField references unknown table "${table}"`,
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
const forwardFields = fieldToColumn[model];
|
|
113
|
-
if (!forwardFields) {
|
|
114
|
-
throw new Error(
|
|
115
|
-
`Mappings override mismatch: fieldToColumn is missing model "${model}" for table "${table}"`,
|
|
116
|
-
);
|
|
117
|
-
}
|
|
118
|
-
for (const [column, field] of Object.entries(columns)) {
|
|
119
|
-
if (forwardFields[field] !== column) {
|
|
120
|
-
throw new Error(
|
|
121
|
-
`Mappings override mismatch: columnToField.${table}.${column}="${field}" is not mirrored in fieldToColumn.${model}`,
|
|
122
|
-
);
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function mergeMappings(
|
|
129
|
-
defaults: ResolvedMappings,
|
|
130
|
-
existingMappings?: Partial<SqlMappings>,
|
|
131
|
-
): ResolvedMappings {
|
|
132
|
-
const hasModelToTable = existingMappings?.modelToTable !== undefined;
|
|
133
|
-
const hasTableToModel = existingMappings?.tableToModel !== undefined;
|
|
134
|
-
if (hasModelToTable !== hasTableToModel) {
|
|
135
|
-
throw new Error(
|
|
136
|
-
'Mappings override mismatch: modelToTable and tableToModel must be provided together',
|
|
137
|
-
);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
const hasFieldToColumn = existingMappings?.fieldToColumn !== undefined;
|
|
141
|
-
const hasColumnToField = existingMappings?.columnToField !== undefined;
|
|
142
|
-
if (hasFieldToColumn !== hasColumnToField) {
|
|
143
|
-
throw new Error(
|
|
144
|
-
'Mappings override mismatch: fieldToColumn and columnToField must be provided together',
|
|
145
|
-
);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
const modelToTable: Record<string, string> = hasModelToTable
|
|
149
|
-
? (existingMappings?.modelToTable ?? {})
|
|
150
|
-
: defaults.modelToTable;
|
|
151
|
-
const tableToModel: Record<string, string> = hasTableToModel
|
|
152
|
-
? (existingMappings?.tableToModel ?? {})
|
|
153
|
-
: defaults.tableToModel;
|
|
154
|
-
assertInverseModelMappings(modelToTable, tableToModel);
|
|
155
|
-
|
|
156
|
-
const fieldToColumn: Record<string, Record<string, string>> = hasFieldToColumn
|
|
157
|
-
? (existingMappings?.fieldToColumn ?? {})
|
|
158
|
-
: defaults.fieldToColumn;
|
|
159
|
-
const columnToField: Record<string, Record<string, string>> = hasColumnToField
|
|
160
|
-
? (existingMappings?.columnToField ?? {})
|
|
161
|
-
: defaults.columnToField;
|
|
162
|
-
assertInverseFieldMappings(fieldToColumn, columnToField, modelToTable, tableToModel);
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
modelToTable,
|
|
166
|
-
tableToModel,
|
|
167
|
-
fieldToColumn,
|
|
168
|
-
columnToField,
|
|
169
|
-
codecTypes: { ...defaults.codecTypes, ...(existingMappings?.codecTypes ?? {}) },
|
|
170
|
-
operationTypes: { ...defaults.operationTypes, ...(existingMappings?.operationTypes ?? {}) },
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
|
|
174
8
|
function validateContractLogic(contract: SqlContract<SqlStorage>): void {
|
|
175
9
|
const tableNames = new Set(Object.keys(contract.storage.tables));
|
|
176
10
|
|
|
@@ -433,16 +267,6 @@ export function validateContract<TContract extends SqlContract<SqlStorage>>(
|
|
|
433
267
|
throw new Error(`Contract semantic validation failed: ${semanticErrors.join('; ')}`);
|
|
434
268
|
}
|
|
435
269
|
|
|
436
|
-
const
|
|
437
|
-
|
|
438
|
-
structurallyValid.models as Record<string, ModelDefinition>,
|
|
439
|
-
);
|
|
440
|
-
const mappings = mergeMappings(defaultMappings, existingMappings);
|
|
441
|
-
|
|
442
|
-
const contractWithMappings = {
|
|
443
|
-
...structurallyValid,
|
|
444
|
-
mappings,
|
|
445
|
-
};
|
|
446
|
-
|
|
447
|
-
return decodeContractDefaults(contractWithMappings) as TContract;
|
|
270
|
+
const constructed = constructContract<TContract>(structurallyValid);
|
|
271
|
+
return decodeContractDefaults(constructed) as TContract;
|
|
448
272
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-BaAbD2Bc.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAgBA;AAsBA;AAKA;AAKA;AAeA;AAKY,KApDA,aAAA,GAoDiB;EAEjB,SAAA,UAAA,EAAiB,MAAA;EAMjB,SAAA,OAAU,EAAA,MAAA;EAEC,SAAA,QAAA,EAAA,OAAA;EAED;;;AAQtB;;EACoB,SAAA,UAAA,CAAA,EAhEI,MAgEJ,CAAA,MAAA,EAAA,OAAA,CAAA;EACI;;;;EAEJ,SAAA,OAAA,CAAA,EAAA,MAAA;EACkB;;;AAatC;EAMY,SAAA,OAAU,CAAA,EA7ED,aA6EC;CACY;AAAf,KA3EP,UAAA,GA2EO;EAKe,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EAAf,SAAA,IAAA,CAAA,EAAA,MAAA;CAAM;AAGb,KA9EA,gBAAA,GA8EU;EAIV,SAAA,OAAY,EAAA,SAAA,MAAA,EAAA;EAIZ,SAAA,IAAA,CAAA,EAAA,MAAe;CACP;AACc,KAnFtB,KAAA,GAmFsB;EAAf,SAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EACG,SAAA,IAAA,CAAA,EAAA,MAAA;EAAM;AAG5B;;;;EAG2B,SAAA,KAAA,CAAA,EAAA,MAAA;EACe;;;EAEA,SAAA,MAAA,CAAA,EAjFtB,MAiFsB,CAAA,MAAA,EAAA,OAAA,CAAA;CAAf;AAAM,KA9ErB,oBAAA,GA8EqB;EAGpB,SAAA,KAAA,EAAA,MAAA;EACA,SAAA,OAAA,EA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