@prisma-next/sql-contract 0.3.0-dev.8 → 0.3.0-dev.81
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 +84 -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-CcCSXOlR.d.mts +166 -0
- package/dist/types-CcCSXOlR.d.mts.map +1 -0
- package/dist/types-DRR5stkj.mjs +13 -0
- package/dist/types-DRR5stkj.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-CQXvLZa7.mjs +216 -0
- package/dist/validators-CQXvLZa7.mjs.map +1 -0
- package/dist/validators.d.mts +71 -0
- package/dist/validators.d.mts.map +1 -0
- package/dist/validators.mjs +3 -0
- package/package.json +24 -28
- package/src/construct.ts +178 -0
- package/src/exports/types.ts +13 -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 +137 -8
- package/src/validate.ts +272 -0
- package/src/validators.ts +164 -12
- 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,166 @@
|
|
|
1
|
+
import { ColumnDefault, ContractBase, ExecutionHashBase, ExecutionSection, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A column definition in storage.
|
|
7
|
+
*
|
|
8
|
+
* `typeParams` is optional because most columns use non-parameterized types.
|
|
9
|
+
* Columns with parameterized types can either inline `typeParams` or reference
|
|
10
|
+
* a named {@link StorageTypeInstance} via `typeRef`.
|
|
11
|
+
*/
|
|
12
|
+
type StorageColumn = {
|
|
13
|
+
readonly nativeType: string;
|
|
14
|
+
readonly codecId: string;
|
|
15
|
+
readonly nullable: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Opaque, codec-owned JS/type parameters.
|
|
18
|
+
* The codec that owns `codecId` defines the shape and semantics.
|
|
19
|
+
* Mutually exclusive with `typeRef`.
|
|
20
|
+
*/
|
|
21
|
+
readonly typeParams?: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Reference to a named type instance in `storage.types`.
|
|
24
|
+
* Mutually exclusive with `typeParams`.
|
|
25
|
+
*/
|
|
26
|
+
readonly typeRef?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Default value for the column.
|
|
29
|
+
* Can be a literal value or database function.
|
|
30
|
+
*/
|
|
31
|
+
readonly default?: ColumnDefault;
|
|
32
|
+
};
|
|
33
|
+
type PrimaryKey = {
|
|
34
|
+
readonly columns: readonly string[];
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
};
|
|
37
|
+
type UniqueConstraint = {
|
|
38
|
+
readonly columns: readonly string[];
|
|
39
|
+
readonly name?: string;
|
|
40
|
+
};
|
|
41
|
+
type Index = {
|
|
42
|
+
readonly columns: readonly string[];
|
|
43
|
+
readonly name?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Optional access method identifier.
|
|
46
|
+
* Extension-specific methods are represented as strings and interpreted
|
|
47
|
+
* by the owning extension package.
|
|
48
|
+
*/
|
|
49
|
+
readonly using?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional extension-owned index configuration payload.
|
|
52
|
+
*/
|
|
53
|
+
readonly config?: Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
type ForeignKeyReferences = {
|
|
56
|
+
readonly table: string;
|
|
57
|
+
readonly columns: readonly string[];
|
|
58
|
+
};
|
|
59
|
+
type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
60
|
+
type ForeignKeyOptions = {
|
|
61
|
+
readonly name?: string;
|
|
62
|
+
readonly onDelete?: ReferentialAction;
|
|
63
|
+
readonly onUpdate?: ReferentialAction;
|
|
64
|
+
};
|
|
65
|
+
type ForeignKey = {
|
|
66
|
+
readonly columns: readonly string[];
|
|
67
|
+
readonly references: ForeignKeyReferences;
|
|
68
|
+
readonly name?: string;
|
|
69
|
+
readonly onDelete?: ReferentialAction;
|
|
70
|
+
readonly onUpdate?: ReferentialAction;
|
|
71
|
+
/** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
72
|
+
readonly constraint: boolean;
|
|
73
|
+
/** Whether to emit a backing index for the FK columns. */
|
|
74
|
+
readonly index: boolean;
|
|
75
|
+
};
|
|
76
|
+
type StorageTable = {
|
|
77
|
+
readonly columns: Record<string, StorageColumn>;
|
|
78
|
+
readonly primaryKey?: PrimaryKey;
|
|
79
|
+
readonly uniques: ReadonlyArray<UniqueConstraint>;
|
|
80
|
+
readonly indexes: ReadonlyArray<Index>;
|
|
81
|
+
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A named, parameterized type instance.
|
|
85
|
+
* These are registered in `storage.types` for reuse across columns
|
|
86
|
+
* and to enable ergonomic schema surfaces like `schema.types.MyType`.
|
|
87
|
+
*
|
|
88
|
+
* Unlike {@link StorageColumn}, `typeParams` is required here because
|
|
89
|
+
* `StorageTypeInstance` exists specifically to define reusable parameterized types.
|
|
90
|
+
* A type instance without parameters would be redundant—columns can reference
|
|
91
|
+
* the codec directly via `codecId`.
|
|
92
|
+
*/
|
|
93
|
+
type StorageTypeInstance = {
|
|
94
|
+
readonly codecId: string;
|
|
95
|
+
readonly nativeType: string;
|
|
96
|
+
readonly typeParams: Record<string, unknown>;
|
|
97
|
+
};
|
|
98
|
+
type SqlStorage = {
|
|
99
|
+
readonly tables: Record<string, StorageTable>;
|
|
100
|
+
/**
|
|
101
|
+
* Named type instances for parameterized/custom types.
|
|
102
|
+
* Columns can reference these via `typeRef`.
|
|
103
|
+
*/
|
|
104
|
+
readonly types?: Record<string, StorageTypeInstance>;
|
|
105
|
+
};
|
|
106
|
+
type ModelField = {
|
|
107
|
+
readonly column: string;
|
|
108
|
+
};
|
|
109
|
+
type ModelStorage = {
|
|
110
|
+
readonly table: string;
|
|
111
|
+
};
|
|
112
|
+
type ModelDefinition = {
|
|
113
|
+
readonly storage: ModelStorage;
|
|
114
|
+
readonly fields: Record<string, ModelField>;
|
|
115
|
+
readonly relations: Record<string, unknown>;
|
|
116
|
+
};
|
|
117
|
+
type SqlMappings = {
|
|
118
|
+
readonly modelToTable?: Record<string, string>;
|
|
119
|
+
readonly tableToModel?: Record<string, string>;
|
|
120
|
+
readonly fieldToColumn?: Record<string, Record<string, string>>;
|
|
121
|
+
readonly columnToField?: Record<string, Record<string, string>>;
|
|
122
|
+
};
|
|
123
|
+
declare const DEFAULT_FK_CONSTRAINT = true;
|
|
124
|
+
declare const DEFAULT_FK_INDEX = true;
|
|
125
|
+
declare function applyFkDefaults(fk: {
|
|
126
|
+
constraint?: boolean | undefined;
|
|
127
|
+
index?: boolean | undefined;
|
|
128
|
+
}, overrideDefaults?: {
|
|
129
|
+
constraint?: boolean | undefined;
|
|
130
|
+
index?: boolean | undefined;
|
|
131
|
+
}): {
|
|
132
|
+
constraint: boolean;
|
|
133
|
+
index: boolean;
|
|
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 };
|
|
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> & {
|
|
152
|
+
readonly targetFamily: string;
|
|
153
|
+
readonly storage: S;
|
|
154
|
+
readonly models: M;
|
|
155
|
+
readonly relations: R;
|
|
156
|
+
readonly mappings: Map;
|
|
157
|
+
readonly execution?: ExecutionSection;
|
|
158
|
+
};
|
|
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>;
|
|
164
|
+
//#endregion
|
|
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":[],"m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DA,CAAA,MAAA,EAAA,KAAA,CAAA,GAlDA,CAkDA,SAAA;EAAgB,SAAA,UAAA,EAAA,KAAA,EAAA;cAjDJ;;SAER,wBACF;KAEM,uBAAuB,qBAC/B,wBACA;;cACY,8BAER,wBACF;KAEM,kBAAA;KAEA,6CAA6C,6BACxC,sBAAsB;KAG3B,sBACA,aAAa,sBACb,0BAA0B,mCAC1B,0BAA0B,qCACxB,cAAc,kCACL,0BAA0B,gDACxB,4BAA4B,gDAC9B,0BAA0B,2BAC7C,aAAa,cAAc,gBAAgB;;oBAE3B;mBACD;sBACG;qBACD;uBACE;;KAGX,iCAAiC,iCAAiC,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
const DEFAULT_FK_CONSTRAINT = true;
|
|
3
|
+
const DEFAULT_FK_INDEX = true;
|
|
4
|
+
function applyFkDefaults(fk, overrideDefaults) {
|
|
5
|
+
return {
|
|
6
|
+
constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,
|
|
7
|
+
index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DEFAULT_FK_INDEX as n, applyFkDefaults as r, DEFAULT_FK_CONSTRAINT as t };
|
|
13
|
+
//# sourceMappingURL=types-DRR5stkj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
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
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { C as StorageColumn, S as SqlStorage, b as SqlContract } from "./types-CcCSXOlR.mjs";
|
|
2
|
+
import "@prisma-next/contract/types";
|
|
3
|
+
|
|
4
|
+
//#region src/validate.d.ts
|
|
5
|
+
declare function isBigIntColumn(column: StorageColumn): boolean;
|
|
6
|
+
declare function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contract: T): T;
|
|
7
|
+
declare function normalizeContract(contract: unknown): SqlContract<SqlStorage>;
|
|
8
|
+
declare function validateContract<TContract extends SqlContract<SqlStorage>>(value: unknown): TContract;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { decodeContractDefaults, isBigIntColumn, normalizeContract, validateContract };
|
|
11
|
+
//# sourceMappingURL=validate.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"sourcesContent":[],"mappings":";;;;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"}
|
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
import { r as applyFkDefaults } from "./types-DRR5stkj.mjs";
|
|
2
|
+
import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-CQXvLZa7.mjs";
|
|
3
|
+
import { isTaggedBigInt, isTaggedRaw } from "@prisma-next/contract/types";
|
|
4
|
+
|
|
5
|
+
//#region src/construct.ts
|
|
6
|
+
function computeDefaultMappings(models) {
|
|
7
|
+
const modelToTable = {};
|
|
8
|
+
const tableToModel = {};
|
|
9
|
+
const fieldToColumn = {};
|
|
10
|
+
const columnToField = {};
|
|
11
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
12
|
+
const tableName = model.storage.table;
|
|
13
|
+
modelToTable[modelName] = tableName;
|
|
14
|
+
tableToModel[tableName] = modelName;
|
|
15
|
+
const modelFieldToColumn = {};
|
|
16
|
+
for (const [fieldName, field] of Object.entries(model.fields)) {
|
|
17
|
+
const columnName = field.column;
|
|
18
|
+
modelFieldToColumn[fieldName] = columnName;
|
|
19
|
+
if (!columnToField[tableName]) columnToField[tableName] = {};
|
|
20
|
+
columnToField[tableName][columnName] = fieldName;
|
|
21
|
+
}
|
|
22
|
+
fieldToColumn[modelName] = modelFieldToColumn;
|
|
23
|
+
}
|
|
24
|
+
return {
|
|
25
|
+
modelToTable,
|
|
26
|
+
tableToModel,
|
|
27
|
+
fieldToColumn,
|
|
28
|
+
columnToField
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function assertInverseModelMappings(modelToTable, tableToModel) {
|
|
32
|
+
for (const [model, table] of Object.entries(modelToTable)) if (tableToModel[table] !== model) throw new Error(`Mappings override mismatch: modelToTable.${model}="${table}" is not mirrored in tableToModel`);
|
|
33
|
+
for (const [table, model] of Object.entries(tableToModel)) if (modelToTable[model] !== table) throw new Error(`Mappings override mismatch: tableToModel.${table}="${model}" is not mirrored in modelToTable`);
|
|
34
|
+
}
|
|
35
|
+
function assertInverseFieldMappings(fieldToColumn, columnToField, modelToTable, tableToModel) {
|
|
36
|
+
for (const [model, fields] of Object.entries(fieldToColumn)) {
|
|
37
|
+
const table = modelToTable[model];
|
|
38
|
+
if (!table) throw new Error(`Mappings override mismatch: fieldToColumn references unknown model "${model}"`);
|
|
39
|
+
const reverseFields = columnToField[table];
|
|
40
|
+
if (!reverseFields) throw new Error(`Mappings override mismatch: columnToField is missing table "${table}" for model "${model}"`);
|
|
41
|
+
for (const [field, column] of Object.entries(fields)) if (reverseFields[column] !== field) throw new Error(`Mappings override mismatch: fieldToColumn.${model}.${field}="${column}" is not mirrored in columnToField.${table}`);
|
|
42
|
+
}
|
|
43
|
+
for (const [table, columns] of Object.entries(columnToField)) {
|
|
44
|
+
const model = tableToModel[table];
|
|
45
|
+
if (!model) throw new Error(`Mappings override mismatch: columnToField references unknown table "${table}"`);
|
|
46
|
+
const forwardFields = fieldToColumn[model];
|
|
47
|
+
if (!forwardFields) throw new Error(`Mappings override mismatch: fieldToColumn is missing model "${model}" for table "${table}"`);
|
|
48
|
+
for (const [column, field] of Object.entries(columns)) if (forwardFields[field] !== column) throw new Error(`Mappings override mismatch: columnToField.${table}.${column}="${field}" is not mirrored in fieldToColumn.${model}`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
function mergeMappings(defaults, existingMappings) {
|
|
52
|
+
const hasModelToTable = existingMappings?.modelToTable !== void 0;
|
|
53
|
+
const hasTableToModel = existingMappings?.tableToModel !== void 0;
|
|
54
|
+
if (hasModelToTable !== hasTableToModel) throw new Error("Mappings override mismatch: modelToTable and tableToModel must be provided together");
|
|
55
|
+
const hasFieldToColumn = existingMappings?.fieldToColumn !== void 0;
|
|
56
|
+
const hasColumnToField = existingMappings?.columnToField !== void 0;
|
|
57
|
+
if (hasFieldToColumn !== hasColumnToField) throw new Error("Mappings override mismatch: fieldToColumn and columnToField must be provided together");
|
|
58
|
+
const modelToTable = hasModelToTable ? existingMappings?.modelToTable ?? {} : defaults.modelToTable;
|
|
59
|
+
const tableToModel = hasTableToModel ? existingMappings?.tableToModel ?? {} : defaults.tableToModel;
|
|
60
|
+
assertInverseModelMappings(modelToTable, tableToModel);
|
|
61
|
+
const fieldToColumn = hasFieldToColumn ? existingMappings?.fieldToColumn ?? {} : defaults.fieldToColumn;
|
|
62
|
+
const columnToField = hasColumnToField ? existingMappings?.columnToField ?? {} : defaults.columnToField;
|
|
63
|
+
assertInverseFieldMappings(fieldToColumn, columnToField, modelToTable, tableToModel);
|
|
64
|
+
return {
|
|
65
|
+
modelToTable,
|
|
66
|
+
tableToModel,
|
|
67
|
+
fieldToColumn,
|
|
68
|
+
columnToField
|
|
69
|
+
};
|
|
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
|
|
86
|
+
function validateContractLogic(contract) {
|
|
87
|
+
const tableNames = new Set(Object.keys(contract.storage.tables));
|
|
88
|
+
for (const [tableName, table] of Object.entries(contract.storage.tables)) {
|
|
89
|
+
const columnNames = new Set(Object.keys(table.columns));
|
|
90
|
+
if (table.primaryKey) {
|
|
91
|
+
for (const colName of table.primaryKey.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" primaryKey references non-existent column "${colName}"`);
|
|
92
|
+
}
|
|
93
|
+
for (const unique of table.uniques) for (const colName of unique.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" unique constraint references non-existent column "${colName}"`);
|
|
94
|
+
for (const index of table.indexes) for (const colName of index.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" index references non-existent column "${colName}"`);
|
|
95
|
+
for (const [colName, column] of Object.entries(table.columns)) if (!column.nullable && column.default?.kind === "literal" && column.default.value === null) throw new Error(`Table "${tableName}" column "${colName}" is NOT NULL but has a literal null default`);
|
|
96
|
+
for (const fk of table.foreignKeys) {
|
|
97
|
+
for (const colName of fk.columns) if (!columnNames.has(colName)) throw new Error(`Table "${tableName}" foreignKey references non-existent column "${colName}"`);
|
|
98
|
+
if (!tableNames.has(fk.references.table)) throw new Error(`Table "${tableName}" foreignKey references non-existent table "${fk.references.table}"`);
|
|
99
|
+
const referencedTable = contract.storage.tables[fk.references.table];
|
|
100
|
+
const referencedColumnNames = new Set(Object.keys(referencedTable.columns));
|
|
101
|
+
for (const colName of fk.references.columns) if (!referencedColumnNames.has(colName)) throw new Error(`Table "${tableName}" foreignKey references non-existent column "${colName}" in table "${fk.references.table}"`);
|
|
102
|
+
if (fk.columns.length !== fk.references.columns.length) throw new Error(`Table "${tableName}" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`);
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
const BIGINT_NATIVE_TYPES = new Set(["bigint", "int8"]);
|
|
107
|
+
function isBigIntColumn(column) {
|
|
108
|
+
const nativeType = column.nativeType?.toLowerCase() ?? "";
|
|
109
|
+
if (BIGINT_NATIVE_TYPES.has(nativeType)) return true;
|
|
110
|
+
const codecId = column.codecId?.toLowerCase() ?? "";
|
|
111
|
+
return codecId.includes("int8") || codecId.includes("bigint");
|
|
112
|
+
}
|
|
113
|
+
function decodeDefaultLiteralValue(value, column, tableName, columnName) {
|
|
114
|
+
if (value instanceof Date) return value;
|
|
115
|
+
if (isTaggedRaw(value)) return value.value;
|
|
116
|
+
if (isTaggedBigInt(value)) {
|
|
117
|
+
if (!isBigIntColumn(column)) return value;
|
|
118
|
+
try {
|
|
119
|
+
return BigInt(value.value);
|
|
120
|
+
} catch {
|
|
121
|
+
throw new Error(`Invalid tagged bigint for default value on "${tableName}.${columnName}": "${value.value}" is not a valid integer`);
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
function decodeContractDefaults(contract) {
|
|
127
|
+
const tables = contract.storage.tables;
|
|
128
|
+
let tablesChanged = false;
|
|
129
|
+
const decodedTables = {};
|
|
130
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
131
|
+
let columnsChanged = false;
|
|
132
|
+
const decodedColumns = {};
|
|
133
|
+
for (const [columnName, column] of Object.entries(table.columns)) {
|
|
134
|
+
if (column.default?.kind === "literal") {
|
|
135
|
+
const decodedValue = decodeDefaultLiteralValue(column.default.value, column, tableName, columnName);
|
|
136
|
+
if (decodedValue !== column.default.value) {
|
|
137
|
+
columnsChanged = true;
|
|
138
|
+
decodedColumns[columnName] = {
|
|
139
|
+
...column,
|
|
140
|
+
default: {
|
|
141
|
+
kind: "literal",
|
|
142
|
+
value: decodedValue
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
continue;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
decodedColumns[columnName] = column;
|
|
149
|
+
}
|
|
150
|
+
if (columnsChanged) {
|
|
151
|
+
tablesChanged = true;
|
|
152
|
+
decodedTables[tableName] = {
|
|
153
|
+
...table,
|
|
154
|
+
columns: decodedColumns
|
|
155
|
+
};
|
|
156
|
+
} else decodedTables[tableName] = table;
|
|
157
|
+
}
|
|
158
|
+
if (!tablesChanged) return contract;
|
|
159
|
+
return {
|
|
160
|
+
...contract,
|
|
161
|
+
storage: {
|
|
162
|
+
...contract.storage,
|
|
163
|
+
tables: decodedTables
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function normalizeContract(contract) {
|
|
168
|
+
if (typeof contract !== "object" || contract === null) return contract;
|
|
169
|
+
const contractObj = contract;
|
|
170
|
+
let normalizedStorage = contractObj["storage"];
|
|
171
|
+
if (normalizedStorage && typeof normalizedStorage === "object" && normalizedStorage !== null) {
|
|
172
|
+
const storage = normalizedStorage;
|
|
173
|
+
const tables = storage["tables"];
|
|
174
|
+
if (tables) {
|
|
175
|
+
const normalizedTables = {};
|
|
176
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
177
|
+
const tableObj = table;
|
|
178
|
+
const columns = tableObj["columns"];
|
|
179
|
+
if (columns) {
|
|
180
|
+
const normalizedColumns = {};
|
|
181
|
+
for (const [columnName, column] of Object.entries(columns)) {
|
|
182
|
+
const columnObj = column;
|
|
183
|
+
normalizedColumns[columnName] = {
|
|
184
|
+
...columnObj,
|
|
185
|
+
nullable: columnObj["nullable"] ?? false
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
const normalizedForeignKeys = (tableObj["foreignKeys"] ?? []).map((fk) => ({
|
|
189
|
+
...fk,
|
|
190
|
+
...applyFkDefaults({
|
|
191
|
+
constraint: typeof fk["constraint"] === "boolean" ? fk["constraint"] : void 0,
|
|
192
|
+
index: typeof fk["index"] === "boolean" ? fk["index"] : void 0
|
|
193
|
+
})
|
|
194
|
+
}));
|
|
195
|
+
normalizedTables[tableName] = {
|
|
196
|
+
...tableObj,
|
|
197
|
+
columns: normalizedColumns,
|
|
198
|
+
uniques: tableObj["uniques"] ?? [],
|
|
199
|
+
indexes: tableObj["indexes"] ?? [],
|
|
200
|
+
foreignKeys: normalizedForeignKeys
|
|
201
|
+
};
|
|
202
|
+
} else normalizedTables[tableName] = tableObj;
|
|
203
|
+
}
|
|
204
|
+
normalizedStorage = {
|
|
205
|
+
...storage,
|
|
206
|
+
tables: normalizedTables
|
|
207
|
+
};
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
let normalizedModels = contractObj["models"];
|
|
211
|
+
if (normalizedModels && typeof normalizedModels === "object" && normalizedModels !== null) {
|
|
212
|
+
const models = normalizedModels;
|
|
213
|
+
const normalizedModelsObj = {};
|
|
214
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
215
|
+
const modelObj = model;
|
|
216
|
+
normalizedModelsObj[modelName] = {
|
|
217
|
+
...modelObj,
|
|
218
|
+
relations: modelObj["relations"] ?? {}
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
normalizedModels = normalizedModelsObj;
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
...contractObj,
|
|
225
|
+
models: normalizedModels,
|
|
226
|
+
relations: contractObj["relations"] ?? {},
|
|
227
|
+
storage: normalizedStorage,
|
|
228
|
+
extensionPacks: contractObj["extensionPacks"] ?? {},
|
|
229
|
+
capabilities: contractObj["capabilities"] ?? {},
|
|
230
|
+
meta: contractObj["meta"] ?? {},
|
|
231
|
+
sources: contractObj["sources"] ?? {}
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
function validateContract(value) {
|
|
235
|
+
const structurallyValid = validateSqlContract(normalizeContract(value));
|
|
236
|
+
validateContractLogic(structurallyValid);
|
|
237
|
+
const semanticErrors = validateStorageSemantics(structurallyValid.storage);
|
|
238
|
+
if (semanticErrors.length > 0) throw new Error(`Contract semantic validation failed: ${semanticErrors.join("; ")}`);
|
|
239
|
+
return decodeContractDefaults(constructContract(structurallyValid));
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
//#endregion
|
|
243
|
+
export { decodeContractDefaults, isBigIntColumn, normalizeContract, validateContract };
|
|
244
|
+
//# sourceMappingURL=validate.mjs.map
|
|
@@ -0,0 +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/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,cAAc,WACjB,eAAc,aAAa,EAAE;AAE/B,iBAAc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