@prisma-next/sql-contract 0.3.0-dev.123 → 0.3.0-dev.125
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/dist/factories.d.mts +1 -1
- package/dist/{types-mnqqP_Au.d.mts → types-C7hjlEOo.d.mts} +17 -5
- package/dist/types-C7hjlEOo.d.mts.map +1 -0
- package/dist/types-DRR5stkj.mjs.map +1 -1
- package/dist/types.d.mts +2 -2
- package/dist/validate.d.mts +1 -1
- package/dist/validate.d.mts.map +1 -1
- package/dist/validate.mjs +246 -53
- package/dist/validate.mjs.map +1 -1
- package/dist/{validators-DuHeCiKZ.mjs → validators-B1ZW3frd.mjs} +18 -6
- package/dist/validators-B1ZW3frd.mjs.map +1 -0
- package/dist/validators.d.mts +1 -1
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +1 -1
- package/package.json +4 -4
- package/src/construct.ts +4 -1
- package/src/exports/types.ts +3 -0
- package/src/types.ts +18 -2
- package/src/validate.ts +345 -57
- package/src/validators.ts +16 -6
- package/dist/types-mnqqP_Au.d.mts.map +0 -1
- package/dist/validators-DuHeCiKZ.mjs.map +0 -1
package/dist/factories.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as SqlStorage, I as UniqueConstraint, M as StorageTable, T as SqlMappings, _ as PrimaryKey, f as Index, j as StorageColumn, l as ForeignKey, m as ModelField, p as ModelDefinition, u as ForeignKeyOptions, w as SqlContract } from "./types-C7hjlEOo.mjs";
|
|
2
2
|
import { ExecutionHashBase, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
3
3
|
|
|
4
4
|
//#region src/factories.d.ts
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ColumnDefault, ContractBase, ExecutionHashBase, ExecutionSection, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
1
|
+
import { ColumnDefault, ContractBase, DomainRelationOn, ExecutionHashBase, ExecutionSection, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
2
|
|
|
3
3
|
//#region src/types.d.ts
|
|
4
4
|
|
|
@@ -113,6 +113,19 @@ type ModelDefinition = {
|
|
|
113
113
|
readonly storage: ModelStorage;
|
|
114
114
|
readonly fields: Record<string, ModelField>;
|
|
115
115
|
readonly relations: Record<string, unknown>;
|
|
116
|
+
readonly owner?: string;
|
|
117
|
+
};
|
|
118
|
+
type SqlModelFieldStorage = {
|
|
119
|
+
readonly column: string;
|
|
120
|
+
};
|
|
121
|
+
type SqlModelStorage = {
|
|
122
|
+
readonly table: string;
|
|
123
|
+
readonly fields: Record<string, SqlModelFieldStorage>;
|
|
124
|
+
};
|
|
125
|
+
type SqlRelation = {
|
|
126
|
+
readonly to: string;
|
|
127
|
+
readonly cardinality: '1:1' | '1:N' | 'N:1';
|
|
128
|
+
readonly on: DomainRelationOn;
|
|
116
129
|
};
|
|
117
130
|
type SqlMappings = {
|
|
118
131
|
readonly modelToTable?: Record<string, string>;
|
|
@@ -164,10 +177,9 @@ type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T
|
|
|
164
177
|
} ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
|
|
165
178
|
type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
|
|
166
179
|
type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
|
|
167
|
-
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> & {
|
|
180
|
+
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, M> & {
|
|
168
181
|
readonly targetFamily: string;
|
|
169
182
|
readonly storage: S;
|
|
170
|
-
readonly models: M;
|
|
171
183
|
readonly relations: R;
|
|
172
184
|
readonly mappings: Map;
|
|
173
185
|
readonly execution?: ExecutionSection;
|
|
@@ -179,5 +191,5 @@ type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromCo
|
|
|
179
191
|
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
|
|
180
192
|
type ResolveOperationTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractOperationTypes<TContract> : OperationTypesOf<TTypeMaps>;
|
|
181
193
|
//#endregion
|
|
182
|
-
export {
|
|
183
|
-
//# sourceMappingURL=types-
|
|
194
|
+
export { SqlStorage as A, ResolveOperationTypes as C, SqlModelStorage as D, SqlModelFieldStorage as E, TypeMapsPhantomKey as F, UniqueConstraint as I, applyFkDefaults as L, StorageTable as M, StorageTypeInstance as N, SqlQueryOperationTypes as O, TypeMaps as P, ResolveCodecTypes as S, SqlMappings as T, PrimaryKey as _, ExtractCodecTypes as a, QueryOperationTypesOf as b, ExtractTypeMapsFromContract as c, ForeignKeyReferences as d, Index as f, OperationTypesOf as g, ModelStorage as h, DEFAULT_FK_INDEX as i, StorageColumn as j, SqlRelation as k, ForeignKey as l, ModelField as m, ContractWithTypeMaps as n, ExtractOperationTypes as o, ModelDefinition as p, DEFAULT_FK_CONSTRAINT as r, ExtractQueryOperationTypes as s, CodecTypesOf as t, ForeignKeyOptions as u, QueryOperationTypeEntry as v, SqlContract as w, ReferentialAction as x, QueryOperationTypesBase as y };
|
|
195
|
+
//# sourceMappingURL=types-C7hjlEOo.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-C7hjlEOo.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAiBA;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;AAI5B;AAIA;AAKA;AAMA;EAC0B,SAAA,KAAA,CAAA,EAAA,MAAA;EACA;;;EAEgB,SAAA,MAAA,CAAA,EA/FtB,MA+FsB,CAAA,MAAA,EAAA,OAAA,CAAA;CAAf;AAAM,KA5FrB,oBAAA,GA4FqB;EAGpB,SAAA,KAAA,EAAA,MAAA;EACA,SAAA,OAAA,EAAA,SAAgB,MAAA,EAAA;AAE7B,CAAA;AAUY,KAvGA,iBAAA,GAuGQ,UAAA,GAAA,UAAA,GAAA,SAAA,GAAA,SAAA,GAAA,YAAA;AACE,K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GAAY,CAAA,SAxDI,MAwDJ,CAAA,MAAA,EAAqB,OAAA,CAAA,GAAA,CAAA,GAtDzB,MAsDyB,CAAA,MAAA,EAAA,KAAA,CAAA,GArD3B,MAqD2B,CAAA,MAAA,EAAA,KAAA,CAAA;AAA0B,KAnD/C,uBAAA,GAmD+C;EACjC,SAAA,IAAA,EAAA,SAAA;IAAtB,SAAA,OAAA,EAAA,MAAA;IACiB,SAAA,QAAA,EAAA,OAAA;EAAjB,CAAA,EAAA;EAAgB,SAAA,OAAA,EAAA;;;;;KAhDR,iCAAiC,eAAe,4BAA4B;KAE5E,uBAAA,GAA0B,eAAe;KAEzC,4BAA4B,qBACpC,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,cAAc;;oBAEzC;sBACE;qBACD;uBACE;;KAGX,iCAAiC,iCAAiC,IAC1E,YAAY,EAAE,2BAA2B;KAGjC,uBAAuB,aAAa,4BAA4B;KAChE,2BAA2B,iBAAiB,4BAA4B;KACxE,gCAAgC,sBAAsB,4BAA4B;KAElF,2CAA2C,6BACnD,kBAAkB,aAClB,aAAa;KAEL,+CAA+C,6BACvD,sBAAsB,aACtB,iBAAiB"}
|
|
@@ -1 +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 TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly operationTypes: TOperationTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\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 QueryOperationTypeEntry = {\n readonly args: readonly { readonly codecId: string; readonly nullable: boolean }[];\n readonly returns: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type SqlQueryOperationTypes<T extends Record<string, QueryOperationTypeEntry>> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\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
|
|
1
|
+
{"version":3,"file":"types-DRR5stkj.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n ColumnDefault,\n ContractBase,\n DomainRelationOn,\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 readonly owner?: string;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\n};\n\nexport type SqlRelation = {\n readonly to: string;\n readonly cardinality: '1:1' | '1:N' | 'N:1';\n readonly on: DomainRelationOn;\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 TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly operationTypes: TOperationTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\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 QueryOperationTypeEntry = {\n readonly args: readonly { readonly codecId: string; readonly nullable: boolean }[];\n readonly returns: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type SqlQueryOperationTypes<T extends Record<string, QueryOperationTypeEntry>> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\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, M> & {\n readonly targetFamily: string;\n readonly storage: S;\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>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<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":";AA+JA,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 { A as
|
|
2
|
-
export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractOperationTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type ModelDefinition, type ModelField, type ModelStorage, type OperationTypesOf, type PrimaryKey, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlContract, type SqlMappings, type SqlQueryOperationTypes, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
|
|
1
|
+
import { A as SqlStorage, C as ResolveOperationTypes, D as SqlModelStorage, E as SqlModelFieldStorage, F as TypeMapsPhantomKey, I as UniqueConstraint, L as applyFkDefaults, M as StorageTable, N as StorageTypeInstance, O as SqlQueryOperationTypes, P as TypeMaps, S as ResolveCodecTypes, T as SqlMappings, _ as PrimaryKey, a as ExtractCodecTypes, b as QueryOperationTypesOf, c as ExtractTypeMapsFromContract, d as ForeignKeyReferences, f as Index, g as OperationTypesOf, h as ModelStorage, i as DEFAULT_FK_INDEX, j as StorageColumn, k as SqlRelation, l as ForeignKey, m as ModelField, n as ContractWithTypeMaps, o as ExtractOperationTypes, p as ModelDefinition, r as DEFAULT_FK_CONSTRAINT, s as ExtractQueryOperationTypes, t as CodecTypesOf, u as ForeignKeyOptions, v as QueryOperationTypeEntry, w as SqlContract, x as ReferentialAction, y as QueryOperationTypesBase } from "./types-C7hjlEOo.mjs";
|
|
2
|
+
export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractOperationTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type ModelDefinition, type ModelField, type ModelStorage, type OperationTypesOf, type PrimaryKey, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlContract, type SqlMappings, type SqlModelFieldStorage, type SqlModelStorage, type SqlQueryOperationTypes, type SqlRelation, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, 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":";;;;iBAgGgB,cAAA,SAAuB;AAAvB,iBAkCA,sBAlCuB,CAAa,UAkCH,WAlCG,CAkCS,UAlCT,CAAA,CAAA,CAAA,QAAA,EAkCgC,CAlChC,CAAA,EAkCoC,CAlCpC;AAkCpC,iBAmVA,iBAAA,CAnVsB,QAAA,EAAA,OAAA,CAAA,EAmVgB,WAnVhB,CAmV4B,UAnV5B,CAAA;AAAuB,iBA2Z7C,gBA3Z6C,CAAA,kBA2ZV,WA3ZU,CA2ZE,UA3ZF,CAAA,CAAA,CAAA,KAAA,EAAA,OAAA,CAAA,EA6Z1D,SA7Z0D"}
|
package/dist/validate.mjs
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { r as applyFkDefaults } from "./types-DRR5stkj.mjs";
|
|
2
|
-
import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-
|
|
2
|
+
import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-B1ZW3frd.mjs";
|
|
3
3
|
import { isTaggedBigInt, isTaggedRaw } from "@prisma-next/contract/types";
|
|
4
|
+
import { validateContractDomain } from "@prisma-next/contract/validate-domain";
|
|
4
5
|
|
|
5
6
|
//#region src/construct.ts
|
|
6
7
|
function computeDefaultMappings(models) {
|
|
@@ -75,14 +76,22 @@ function stripGenerated(obj) {
|
|
|
75
76
|
function constructContract(input) {
|
|
76
77
|
const existingMappings = input.mappings;
|
|
77
78
|
const mappings = mergeMappings(computeDefaultMappings(input.models), existingMappings);
|
|
79
|
+
const stripped = stripGenerated(input);
|
|
78
80
|
return {
|
|
79
|
-
...
|
|
80
|
-
mappings
|
|
81
|
+
...stripped,
|
|
82
|
+
mappings,
|
|
83
|
+
roots: stripped.roots
|
|
81
84
|
};
|
|
82
85
|
}
|
|
83
86
|
|
|
84
87
|
//#endregion
|
|
85
88
|
//#region src/validate.ts
|
|
89
|
+
function extractDomainShape(contract) {
|
|
90
|
+
return {
|
|
91
|
+
roots: contract.roots,
|
|
92
|
+
models: contract.models
|
|
93
|
+
};
|
|
94
|
+
}
|
|
86
95
|
function validateContractLogic(contract) {
|
|
87
96
|
const tableNames = new Set(Object.keys(contract.storage.tables));
|
|
88
97
|
for (const [tableName, table] of Object.entries(contract.storage.tables)) {
|
|
@@ -164,65 +173,216 @@ function decodeContractDefaults(contract) {
|
|
|
164
173
|
}
|
|
165
174
|
};
|
|
166
175
|
}
|
|
167
|
-
function
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
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;
|
|
176
|
+
function normalizeStorage(contractObj) {
|
|
177
|
+
const normalizedStorage = contractObj["storage"];
|
|
178
|
+
if (!normalizedStorage || typeof normalizedStorage !== "object") return normalizedStorage;
|
|
179
|
+
const storage = normalizedStorage;
|
|
180
|
+
const tables = storage["tables"];
|
|
181
|
+
if (!tables) return storage;
|
|
182
|
+
const normalizedTables = {};
|
|
183
|
+
for (const [tableName, table] of Object.entries(tables)) {
|
|
184
|
+
const tableObj = table;
|
|
185
|
+
const columns = tableObj["columns"];
|
|
186
|
+
if (columns) {
|
|
187
|
+
const normalizedColumns = {};
|
|
188
|
+
for (const [columnName, column] of Object.entries(columns)) {
|
|
189
|
+
const columnObj = column;
|
|
190
|
+
normalizedColumns[columnName] = {
|
|
191
|
+
...columnObj,
|
|
192
|
+
nullable: columnObj["nullable"] ?? false
|
|
193
|
+
};
|
|
203
194
|
}
|
|
204
|
-
|
|
205
|
-
...
|
|
206
|
-
|
|
195
|
+
const normalizedForeignKeys = (tableObj["foreignKeys"] ?? []).map((fk) => ({
|
|
196
|
+
...fk,
|
|
197
|
+
...applyFkDefaults({
|
|
198
|
+
constraint: typeof fk["constraint"] === "boolean" ? fk["constraint"] : void 0,
|
|
199
|
+
index: typeof fk["index"] === "boolean" ? fk["index"] : void 0
|
|
200
|
+
})
|
|
201
|
+
}));
|
|
202
|
+
normalizedTables[tableName] = {
|
|
203
|
+
...tableObj,
|
|
204
|
+
columns: normalizedColumns,
|
|
205
|
+
uniques: tableObj["uniques"] ?? [],
|
|
206
|
+
indexes: tableObj["indexes"] ?? [],
|
|
207
|
+
foreignKeys: normalizedForeignKeys
|
|
207
208
|
};
|
|
209
|
+
} else normalizedTables[tableName] = tableObj;
|
|
210
|
+
}
|
|
211
|
+
return {
|
|
212
|
+
...storage,
|
|
213
|
+
tables: normalizedTables
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
function detectFormat(models) {
|
|
217
|
+
for (const model of Object.values(models)) {
|
|
218
|
+
const fields = model["fields"];
|
|
219
|
+
if (!fields) continue;
|
|
220
|
+
for (const field of Object.values(fields)) {
|
|
221
|
+
if ("column" in field) return "old";
|
|
222
|
+
if ("codecId" in field) return "new";
|
|
208
223
|
}
|
|
209
224
|
}
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
225
|
+
return "old";
|
|
226
|
+
}
|
|
227
|
+
function buildColumnToFieldMap(fields, modelName) {
|
|
228
|
+
const map = {};
|
|
229
|
+
for (const [fieldName, field] of Object.entries(fields)) {
|
|
230
|
+
const col = field["column"];
|
|
231
|
+
if (!col) continue;
|
|
232
|
+
if (Object.hasOwn(map, col)) throw new Error(`Model "${modelName}" has duplicate column mapping: fields "${map[col]}" and "${fieldName}" both map to column "${col}"`);
|
|
233
|
+
map[col] = fieldName;
|
|
234
|
+
}
|
|
235
|
+
return map;
|
|
236
|
+
}
|
|
237
|
+
function enrichOldFormatModels(models, storageObj, topRelations) {
|
|
238
|
+
const roots = {};
|
|
239
|
+
const tableToModel = {};
|
|
240
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
241
|
+
const tableName = model["storage"]?.["table"];
|
|
242
|
+
if (tableName) {
|
|
243
|
+
if (!model["owner"]) roots[modelName] = modelName;
|
|
244
|
+
tableToModel[tableName] = modelName;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
const enrichedModels = {};
|
|
248
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
249
|
+
const fields = model["fields"] ?? {};
|
|
250
|
+
const modelStorage = model["storage"];
|
|
251
|
+
const tableName = modelStorage?.["table"];
|
|
252
|
+
const storageColumns = (tableName ? storageObj.tables[tableName] : void 0)?.["columns"] ?? {};
|
|
253
|
+
const enrichedFields = {};
|
|
254
|
+
const modelStorageFields = {};
|
|
255
|
+
const hasStorageColumns = Object.keys(storageColumns).length > 0;
|
|
256
|
+
for (const [fieldName, field] of Object.entries(fields)) {
|
|
257
|
+
const colName = field["column"];
|
|
258
|
+
const storageCol = storageColumns[colName];
|
|
259
|
+
if (!storageCol && hasStorageColumns && colName) throw new Error(`Model "${modelName}" field "${fieldName}" references non-existent column "${colName}" in table "${tableName}"`);
|
|
260
|
+
enrichedFields[fieldName] = {
|
|
261
|
+
...field,
|
|
262
|
+
nullable: storageCol?.["nullable"] ?? false,
|
|
263
|
+
codecId: storageCol?.["codecId"] ?? ""
|
|
219
264
|
};
|
|
265
|
+
modelStorageFields[fieldName] = { column: colName };
|
|
220
266
|
}
|
|
221
|
-
|
|
267
|
+
const enrichedStorage = {
|
|
268
|
+
...modelStorage ?? {},
|
|
269
|
+
fields: modelStorageFields
|
|
270
|
+
};
|
|
271
|
+
enrichedModels[modelName] = {
|
|
272
|
+
...model,
|
|
273
|
+
fields: enrichedFields,
|
|
274
|
+
storage: enrichedStorage,
|
|
275
|
+
relations: model["relations"] ?? {}
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
for (const [tableName, tableRels] of Object.entries(topRelations)) {
|
|
279
|
+
const modelName = tableToModel[tableName];
|
|
280
|
+
if (!modelName) continue;
|
|
281
|
+
const existingModel = enrichedModels[modelName];
|
|
282
|
+
if (!existingModel) continue;
|
|
283
|
+
const existingRels = existingModel["relations"] ?? {};
|
|
284
|
+
const targetColumnToField = {};
|
|
285
|
+
const modelRelations = { ...existingRels };
|
|
286
|
+
for (const [relName, rel] of Object.entries(tableRels)) {
|
|
287
|
+
const on = rel["on"];
|
|
288
|
+
const parentCols = on?.["parentCols"] ?? [];
|
|
289
|
+
const childCols = on?.["childCols"] ?? [];
|
|
290
|
+
const toModel = rel["to"];
|
|
291
|
+
const sourceColToField = buildColumnToFieldMap(existingModel["fields"] ?? {}, modelName);
|
|
292
|
+
if (!targetColumnToField[toModel]) {
|
|
293
|
+
const targetModelObj = enrichedModels[toModel];
|
|
294
|
+
if (targetModelObj) targetColumnToField[toModel] = buildColumnToFieldMap(targetModelObj["fields"] ?? {}, toModel);
|
|
295
|
+
else targetColumnToField[toModel] = {};
|
|
296
|
+
}
|
|
297
|
+
const targetColToField = targetColumnToField[toModel] ?? {};
|
|
298
|
+
const localFields = parentCols.map((c) => sourceColToField[c] ?? c);
|
|
299
|
+
const targetFields = childCols.map((c) => targetColToField[c] ?? c);
|
|
300
|
+
modelRelations[relName] = {
|
|
301
|
+
to: toModel,
|
|
302
|
+
cardinality: rel["cardinality"],
|
|
303
|
+
on: {
|
|
304
|
+
localFields,
|
|
305
|
+
targetFields
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
enrichedModels[modelName] = {
|
|
310
|
+
...existingModel,
|
|
311
|
+
relations: modelRelations
|
|
312
|
+
};
|
|
222
313
|
}
|
|
223
314
|
return {
|
|
315
|
+
enrichedModels,
|
|
316
|
+
roots
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
function enrichNewFormatModels(models) {
|
|
320
|
+
const enrichedModels = {};
|
|
321
|
+
const topRelations = {};
|
|
322
|
+
const modelToTable = {};
|
|
323
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
324
|
+
const tableName = model["storage"]?.["table"];
|
|
325
|
+
if (tableName) modelToTable[modelName] = tableName;
|
|
326
|
+
}
|
|
327
|
+
for (const [modelName, model] of Object.entries(models)) {
|
|
328
|
+
const fields = model["fields"] ?? {};
|
|
329
|
+
const storageFields = model["storage"]?.["fields"] ?? {};
|
|
330
|
+
const enrichedFields = {};
|
|
331
|
+
for (const [fieldName, field] of Object.entries(fields)) {
|
|
332
|
+
const column = storageFields[fieldName]?.["column"];
|
|
333
|
+
enrichedFields[fieldName] = column ? {
|
|
334
|
+
...field,
|
|
335
|
+
column
|
|
336
|
+
} : { ...field };
|
|
337
|
+
}
|
|
338
|
+
enrichedModels[modelName] = {
|
|
339
|
+
...model,
|
|
340
|
+
fields: enrichedFields,
|
|
341
|
+
relations: model["relations"] ?? {}
|
|
342
|
+
};
|
|
343
|
+
const modelRels = model["relations"] ?? {};
|
|
344
|
+
const tableName = modelToTable[modelName];
|
|
345
|
+
if (!tableName) continue;
|
|
346
|
+
for (const [relName, rel] of Object.entries(modelRels)) {
|
|
347
|
+
const on = rel["on"];
|
|
348
|
+
if (!on) continue;
|
|
349
|
+
const toModel = rel["to"];
|
|
350
|
+
if (!modelToTable[toModel]) continue;
|
|
351
|
+
const sourceFields = enrichedFields;
|
|
352
|
+
const targetModelObj = models[toModel];
|
|
353
|
+
const targetFields = targetModelObj?.["fields"] ?? {};
|
|
354
|
+
const targetStorageFields = (targetModelObj?.["storage"])?.["fields"] ?? {};
|
|
355
|
+
const parentCols = (on.localFields ?? []).map((f) => {
|
|
356
|
+
return storageFields[f]?.["column"] ?? sourceFields[f]?.["column"] ?? f;
|
|
357
|
+
});
|
|
358
|
+
const childCols = (on.targetFields ?? []).map((f) => {
|
|
359
|
+
return targetStorageFields[f]?.["column"] ?? targetFields[f]?.["column"] ?? f;
|
|
360
|
+
});
|
|
361
|
+
if (!topRelations[tableName]) topRelations[tableName] = {};
|
|
362
|
+
topRelations[tableName][relName] = {
|
|
363
|
+
to: toModel,
|
|
364
|
+
cardinality: rel["cardinality"],
|
|
365
|
+
on: {
|
|
366
|
+
parentCols,
|
|
367
|
+
childCols
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
return {
|
|
373
|
+
enrichedModels,
|
|
374
|
+
topRelations
|
|
375
|
+
};
|
|
376
|
+
}
|
|
377
|
+
function normalizeContract(contract) {
|
|
378
|
+
if (typeof contract !== "object" || contract === null) return contract;
|
|
379
|
+
const contractObj = contract;
|
|
380
|
+
const normalizedStorage = normalizeStorage(contractObj);
|
|
381
|
+
const rawModels = contractObj["models"];
|
|
382
|
+
if (!rawModels || typeof rawModels !== "object" || rawModels === null) return {
|
|
224
383
|
...contractObj,
|
|
225
|
-
|
|
384
|
+
roots: contractObj["roots"] ?? {},
|
|
385
|
+
models: rawModels ?? {},
|
|
226
386
|
relations: contractObj["relations"] ?? {},
|
|
227
387
|
storage: normalizedStorage,
|
|
228
388
|
extensionPacks: contractObj["extensionPacks"] ?? {},
|
|
@@ -230,9 +390,42 @@ function normalizeContract(contract) {
|
|
|
230
390
|
meta: contractObj["meta"] ?? {},
|
|
231
391
|
sources: contractObj["sources"] ?? {}
|
|
232
392
|
};
|
|
393
|
+
const modelsObj = rawModels;
|
|
394
|
+
const format = detectFormat(modelsObj);
|
|
395
|
+
let normalizedModels;
|
|
396
|
+
let roots;
|
|
397
|
+
let topRelations;
|
|
398
|
+
if (format === "new") {
|
|
399
|
+
const result = enrichNewFormatModels(modelsObj);
|
|
400
|
+
normalizedModels = result.enrichedModels;
|
|
401
|
+
topRelations = {
|
|
402
|
+
...contractObj["relations"] ?? {},
|
|
403
|
+
...result.topRelations
|
|
404
|
+
};
|
|
405
|
+
roots = contractObj["roots"] ?? {};
|
|
406
|
+
} else {
|
|
407
|
+
const storageObj = { tables: (normalizedStorage && typeof normalizedStorage === "object" ? normalizedStorage : {})["tables"] ?? {} };
|
|
408
|
+
const existingRelations = contractObj["relations"] ?? {};
|
|
409
|
+
const result = enrichOldFormatModels(modelsObj, storageObj, existingRelations);
|
|
410
|
+
normalizedModels = result.enrichedModels;
|
|
411
|
+
roots = result.roots;
|
|
412
|
+
topRelations = existingRelations;
|
|
413
|
+
}
|
|
414
|
+
return {
|
|
415
|
+
...contractObj,
|
|
416
|
+
roots,
|
|
417
|
+
models: normalizedModels,
|
|
418
|
+
relations: topRelations,
|
|
419
|
+
storage: normalizedStorage,
|
|
420
|
+
extensionPacks: contractObj["extensionPacks"] ?? {},
|
|
421
|
+
capabilities: contractObj["capabilities"] ?? {},
|
|
422
|
+
meta: contractObj["meta"] ?? {},
|
|
423
|
+
sources: contractObj["sources"] ?? {}
|
|
424
|
+
};
|
|
233
425
|
}
|
|
234
426
|
function validateContract(value) {
|
|
235
427
|
const structurallyValid = validateSqlContract(normalizeContract(value));
|
|
428
|
+
validateContractDomain(extractDomainShape(structurallyValid));
|
|
236
429
|
validateContractLogic(structurallyValid);
|
|
237
430
|
const semanticErrors = validateStorageSemantics(structurallyValid.storage);
|
|
238
431
|
if (semanticErrors.length > 0) throw new Error(`Contract semantic validation failed: ${semanticErrors.join("; ")}`);
|
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/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,WAAW,cAAc;;AAGzC,gBAAc,aAAa;;AAG7B,QAAO;EACL;EACA;EACA;EACA;EACD;;AAGH,SAAS,2BACP,cACA,cACM;AACN,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,QAAQ,aAAa,CACvD,KAAI,aAAa,WAAW,MAC1B,OAAM,IAAI,MACR,4CAA4C,MAAM,IAAI,MAAM,mCAC7D;;AAKP,SAAS,2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;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"}
|
|
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>","map: Record<string, string>","roots: Record<string, string>","tableToModel: Record<string, string>","enrichedModels: Record<string, RawModel>","enrichedFields: Record<string, RawField>","modelStorageFields: Record<string, { column: string }>","targetColumnToField: Record<string, Record<string, string>>","modelRelations: Record<string, unknown>","topRelations: Record<string, Record<string, unknown>>","modelToTable: Record<string, string>","normalizedModels: Record<string, RawModel>"],"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 stripped = stripGenerated(input);\n\n const contractWithMappings = {\n ...stripped,\n mappings,\n roots: stripped.roots,\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 type { DomainContractShape, DomainModelShape } from '@prisma-next/contract/validate-domain';\nimport { validateContractDomain } from '@prisma-next/contract/validate-domain';\nimport { constructContract } from './construct';\nimport type { SqlContract, SqlStorage, StorageColumn, StorageTable } from './types';\nimport { applyFkDefaults } from './types';\nimport { validateSqlContract, validateStorageSemantics } from './validators';\n\nfunction extractDomainShape(contract: SqlContract<SqlStorage>): DomainContractShape {\n return {\n roots: contract.roots,\n models: contract.models as Record<string, DomainModelShape>,\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\nfunction normalizeStorage(contractObj: Record<string, unknown>): Record<string, unknown> {\n const normalizedStorage = contractObj['storage'];\n if (!normalizedStorage || typeof normalizedStorage !== 'object')\n return normalizedStorage as Record<string, unknown>;\n\n const storage = normalizedStorage as Record<string, unknown>;\n const tables = storage['tables'] as Record<string, unknown> | undefined;\n if (!tables) return storage;\n\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 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 return { ...storage, tables: normalizedTables };\n}\n\ntype RawModel = Record<string, unknown>;\ntype RawField = Record<string, unknown>;\ntype RawRelation = Record<string, unknown>;\ntype RawStorageObj = { tables: Record<string, Record<string, unknown>> };\n\nfunction detectFormat(models: Record<string, RawModel>): 'old' | 'new' {\n for (const model of Object.values(models)) {\n const fields = model['fields'] as Record<string, RawField> | undefined;\n if (!fields) continue;\n for (const field of Object.values(fields)) {\n if ('column' in field) return 'old';\n if ('codecId' in field) return 'new';\n }\n }\n return 'old';\n}\n\nfunction buildColumnToFieldMap(\n fields: Record<string, RawField>,\n modelName: string,\n): Record<string, string> {\n const map: Record<string, string> = {};\n for (const [fieldName, field] of Object.entries(fields)) {\n const col = field['column'] as string | undefined;\n if (!col) continue;\n if (Object.hasOwn(map, col)) {\n throw new Error(\n `Model \"${modelName}\" has duplicate column mapping: fields \"${map[col]}\" and \"${fieldName}\" both map to column \"${col}\"`,\n );\n }\n map[col] = fieldName;\n }\n return map;\n}\n\nfunction enrichOldFormatModels(\n models: Record<string, RawModel>,\n storageObj: RawStorageObj,\n topRelations: Record<string, Record<string, RawRelation>>,\n): { enrichedModels: Record<string, RawModel>; roots: Record<string, string> } {\n const roots: Record<string, string> = {};\n const tableToModel: Record<string, string> = {};\n\n for (const [modelName, model] of Object.entries(models)) {\n const modelStorage = model['storage'] as Record<string, unknown> | undefined;\n const tableName = modelStorage?.['table'] as string | undefined;\n if (tableName) {\n if (!model['owner']) {\n roots[modelName] = modelName;\n }\n tableToModel[tableName] = modelName;\n }\n }\n\n const enrichedModels: Record<string, RawModel> = {};\n\n for (const [modelName, model] of Object.entries(models)) {\n const fields = (model['fields'] ?? {}) as Record<string, RawField>;\n const modelStorage = model['storage'] as Record<string, unknown> | undefined;\n const tableName = modelStorage?.['table'] as string | undefined;\n const storageTable = tableName\n ? (storageObj.tables[tableName] as Record<string, unknown> | undefined)\n : undefined;\n const storageColumns = (storageTable?.['columns'] ?? {}) as Record<\n string,\n Record<string, unknown>\n >;\n\n const enrichedFields: Record<string, RawField> = {};\n const modelStorageFields: Record<string, { column: string }> = {};\n\n const hasStorageColumns = Object.keys(storageColumns).length > 0;\n for (const [fieldName, field] of Object.entries(fields)) {\n const colName = field['column'] as string;\n const storageCol = storageColumns[colName];\n if (!storageCol && hasStorageColumns && colName) {\n throw new Error(\n `Model \"${modelName}\" field \"${fieldName}\" references non-existent column \"${colName}\" in table \"${tableName}\"`,\n );\n }\n enrichedFields[fieldName] = {\n ...field,\n nullable: storageCol?.['nullable'] ?? false,\n codecId: storageCol?.['codecId'] ?? '',\n };\n modelStorageFields[fieldName] = { column: colName };\n }\n\n const enrichedStorage = {\n ...(modelStorage ?? {}),\n fields: modelStorageFields,\n };\n\n enrichedModels[modelName] = {\n ...model,\n fields: enrichedFields,\n storage: enrichedStorage,\n relations: model['relations'] ?? {},\n };\n }\n\n for (const [tableName, tableRels] of Object.entries(topRelations)) {\n const modelName = tableToModel[tableName];\n if (!modelName) continue;\n const existingModel = enrichedModels[modelName];\n if (!existingModel) continue;\n\n const existingRels = (existingModel['relations'] ?? {}) as Record<string, unknown>;\n const targetColumnToField: Record<string, Record<string, string>> = {};\n\n const modelRelations: Record<string, unknown> = { ...existingRels };\n for (const [relName, rel] of Object.entries(tableRels)) {\n const on = rel['on'] as { childCols?: string[]; parentCols?: string[] } | undefined;\n const parentCols = on?.['parentCols'] ?? [];\n const childCols = on?.['childCols'] ?? [];\n\n const toModel = rel['to'] as string;\n const sourceFields = (existingModel['fields'] ?? {}) as Record<string, RawField>;\n const sourceColToField = buildColumnToFieldMap(sourceFields, modelName);\n\n if (!targetColumnToField[toModel]) {\n const targetModelObj = enrichedModels[toModel];\n if (targetModelObj) {\n targetColumnToField[toModel] = buildColumnToFieldMap(\n (targetModelObj['fields'] ?? {}) as Record<string, RawField>,\n toModel,\n );\n } else {\n targetColumnToField[toModel] = {};\n }\n }\n const targetColToField = targetColumnToField[toModel] ?? {};\n\n // Old format: parentCols = columns on FK-holding table (local), childCols = columns on referenced table (target)\n const localFields = parentCols.map((c: string) => sourceColToField[c] ?? c);\n const targetFields = childCols.map((c: string) => targetColToField[c] ?? c);\n\n modelRelations[relName] = {\n to: toModel,\n cardinality: rel['cardinality'],\n on: { localFields, targetFields },\n };\n }\n\n enrichedModels[modelName] = {\n ...existingModel,\n relations: modelRelations,\n };\n }\n\n return { enrichedModels, roots };\n}\n\nfunction enrichNewFormatModels(models: Record<string, RawModel>): {\n enrichedModels: Record<string, RawModel>;\n topRelations: Record<string, Record<string, unknown>>;\n} {\n const enrichedModels: Record<string, RawModel> = {};\n const topRelations: Record<string, Record<string, unknown>> = {};\n const modelToTable: Record<string, string> = {};\n\n for (const [modelName, model] of Object.entries(models)) {\n const modelStorage = model['storage'] as Record<string, unknown> | undefined;\n const tableName = modelStorage?.['table'] as string | undefined;\n if (tableName) modelToTable[modelName] = tableName;\n }\n\n for (const [modelName, model] of Object.entries(models)) {\n const fields = (model['fields'] ?? {}) as Record<string, RawField>;\n const modelStorage = model['storage'] as Record<string, unknown> | undefined;\n const storageFields = (modelStorage?.['fields'] ?? {}) as Record<\n string,\n Record<string, unknown>\n >;\n\n const enrichedFields: Record<string, RawField> = {};\n for (const [fieldName, field] of Object.entries(fields)) {\n const sfEntry = storageFields[fieldName];\n const column = sfEntry?.['column'] as string | undefined;\n enrichedFields[fieldName] = column ? { ...field, column } : { ...field };\n }\n\n enrichedModels[modelName] = {\n ...model,\n fields: enrichedFields,\n relations: model['relations'] ?? {},\n };\n\n const modelRels = (model['relations'] ?? {}) as Record<string, RawRelation>;\n const tableName = modelToTable[modelName];\n if (!tableName) continue;\n\n for (const [relName, rel] of Object.entries(modelRels)) {\n const on = rel['on'] as { localFields?: string[]; targetFields?: string[] } | undefined;\n if (!on) continue;\n const toModel = rel['to'] as string;\n const toTable = modelToTable[toModel];\n if (!toTable) continue;\n\n const sourceFields = enrichedFields;\n const targetModelObj = models[toModel];\n const targetFields = (targetModelObj?.['fields'] ?? {}) as Record<string, RawField>;\n const targetStorageObj = targetModelObj?.['storage'] as Record<string, unknown> | undefined;\n const targetStorageFields = (targetStorageObj?.['fields'] ?? {}) as Record<\n string,\n Record<string, unknown>\n >;\n\n const parentCols = (on.localFields ?? []).map((f: string) => {\n const sf = storageFields[f];\n return (\n (sf?.['column'] as string | undefined) ??\n (sourceFields[f]?.['column'] as string | undefined) ??\n f\n );\n });\n\n const childCols = (on.targetFields ?? []).map((f: string) => {\n const tsf = targetStorageFields[f];\n return (\n (tsf?.['column'] as string | undefined) ??\n (targetFields[f]?.['column'] as string | undefined) ??\n f\n );\n });\n\n if (!topRelations[tableName]) topRelations[tableName] = {};\n topRelations[tableName][relName] = {\n to: toModel,\n cardinality: rel['cardinality'],\n on: { parentCols, childCols },\n };\n }\n }\n\n return { enrichedModels, topRelations };\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 const normalizedStorage = normalizeStorage(contractObj);\n\n const rawModels = contractObj['models'];\n if (!rawModels || typeof rawModels !== 'object' || rawModels === null) {\n return {\n ...contractObj,\n roots: contractObj['roots'] ?? {},\n models: rawModels ?? {},\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\n const modelsObj = rawModels as Record<string, RawModel>;\n const format = detectFormat(modelsObj);\n\n let normalizedModels: Record<string, RawModel>;\n let roots: Record<string, string>;\n let topRelations: Record<string, Record<string, unknown>>;\n\n if (format === 'new') {\n const result = enrichNewFormatModels(modelsObj);\n normalizedModels = result.enrichedModels;\n topRelations = {\n ...((contractObj['relations'] ?? {}) as Record<string, Record<string, unknown>>),\n ...result.topRelations,\n };\n roots = (contractObj['roots'] as Record<string, string>) ?? {};\n } else {\n const rawStorageObj =\n normalizedStorage && typeof normalizedStorage === 'object'\n ? (normalizedStorage as Record<string, unknown>)\n : {};\n const storageObj = {\n tables: ((rawStorageObj as Record<string, unknown>)['tables'] ?? {}) as Record<\n string,\n Record<string, unknown>\n >,\n };\n const existingRelations = (contractObj['relations'] ?? {}) as Record<\n string,\n Record<string, RawRelation>\n >;\n const result = enrichOldFormatModels(modelsObj, storageObj, existingRelations);\n normalizedModels = result.enrichedModels;\n roots = result.roots;\n topRelations = existingRelations;\n }\n\n return {\n ...contractObj,\n roots,\n models: normalizedModels,\n relations: topRelations,\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\n const structurallyValid = validateSqlContract<SqlContract<SqlStorage>>(normalized);\n\n validateContractDomain(extractDomainShape(structurallyValid));\n\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,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