@prisma-next/sql-contract 0.5.0-dev.6 → 0.5.0-dev.61

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.
@@ -1,4 +1,4 @@
1
- import { A as StorageTable, E as SqlModelStorage, P as UniqueConstraint, T as SqlModelFieldStorage, _ as PrimaryKey, f as ForeignKey, h as Index, k as StorageColumn, p as ForeignKeyOptions } from "./types-DdNz1nUf.mjs";
1
+ import { A as StorageColumn, D as SqlModelStorage, E as SqlModelFieldStorage, F as UniqueConstraint, _ as PrimaryKey, f as ForeignKey, h as Index, j as StorageTable, p as ForeignKeyOptions } from "./types-D1QODyT3.mjs";
2
2
  import { ScalarFieldType } from "@prisma-next/contract/types";
3
3
 
4
4
  //#region src/factories.d.ts
@@ -142,19 +142,42 @@ type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
142
142
  type OperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
143
143
  readonly operationTypes: infer O;
144
144
  } ? O extends Record<string, unknown> ? O : Record<string, never> : Record<string, never>;
145
- type QueryOperationArgSpec = {
146
- readonly codecId?: string;
147
- readonly traits?: readonly CodecTrait[];
148
- readonly nullable: boolean;
145
+ /**
146
+ * Dispatch hint identifying the first-argument target of an operation.
147
+ *
148
+ * Used by ORM column helpers to decide whether an operation is reachable on a
149
+ * field. Either names a concrete codec identity or a set of capability traits
150
+ * that the field's codec must carry.
151
+ */
152
+ type QueryOperationSelfSpec = {
153
+ readonly codecId: string;
154
+ readonly traits?: never;
155
+ } | {
156
+ readonly traits: readonly CodecTrait[];
157
+ readonly codecId?: never;
149
158
  };
150
- type QueryOperationTypeEntry = {
151
- readonly args: readonly QueryOperationArgSpec[];
152
- readonly returns: {
159
+ /**
160
+ * Structural shape an operation's impl must return: any value carrying a
161
+ * codec-exact `returnType` descriptor. `Expression<T>` (from
162
+ * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
163
+ * extends this. Trait-targeted returns are deliberately excluded — predicate
164
+ * detection and result decoding both depend on knowing the concrete return
165
+ * codec.
166
+ */
167
+ type QueryOperationReturn = {
168
+ readonly returnType: {
153
169
  readonly codecId: string;
154
170
  readonly nullable: boolean;
155
171
  };
156
172
  };
157
- type SqlQueryOperationTypes<T extends Record<string, QueryOperationTypeEntry>> = T;
173
+ type QueryOperationTypeEntry = {
174
+ readonly self?: QueryOperationSelfSpec;
175
+ readonly impl: (...args: never[]) => QueryOperationReturn;
176
+ };
177
+ type SqlQueryOperationTypes<_CT extends Record<string, {
178
+ readonly input: unknown;
179
+ readonly output: unknown;
180
+ }>, T extends Record<string, QueryOperationTypeEntry>> = T;
158
181
  type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
159
182
  type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
160
183
  readonly queryOperationTypes: infer Q;
@@ -175,5 +198,5 @@ type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T
175
198
  type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
176
199
  type ResolveOperationTypes<_TContract, TTypeMaps> = OperationTypesOf<TTypeMaps>;
177
200
  //#endregion
178
- export { StorageTable as A, ResolveCodecTypes as C, SqlQueryOperationTypes as D, SqlModelStorage as E, applyFkDefaults as F, TypeMaps as M, TypeMapsPhantomKey as N, SqlStorage as O, UniqueConstraint as P, ReferentialAction as S, SqlModelFieldStorage as T, PrimaryKey as _, ExtractCodecTypes as a, QueryOperationTypesBase as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKey as f, OperationTypesOf as g, Index as h, DEFAULT_FK_INDEX as i, StorageTypeInstance as j, StorageColumn as k, ExtractTypeMapsFromContract as l, ForeignKeyReferences as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, ForeignKeyOptions as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, QueryOperationArgSpec as v, ResolveOperationTypes as w, QueryOperationTypesOf as x, QueryOperationTypeEntry as y };
179
- //# sourceMappingURL=types-DdNz1nUf.d.mts.map
201
+ export { StorageColumn as A, ReferentialAction as C, SqlModelStorage as D, SqlModelFieldStorage as E, UniqueConstraint as F, applyFkDefaults as I, StorageTypeInstance as M, TypeMaps as N, SqlQueryOperationTypes as O, TypeMapsPhantomKey as P, QueryOperationTypesOf as S, ResolveOperationTypes as T, PrimaryKey as _, ExtractCodecTypes as a, QueryOperationTypeEntry as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKey as f, OperationTypesOf as g, Index as h, DEFAULT_FK_INDEX as i, StorageTable as j, SqlStorage as k, ExtractTypeMapsFromContract as l, ForeignKeyReferences as m, ContractWithTypeMaps as n, ExtractFieldInputTypes as o, ForeignKeyOptions as p, DEFAULT_FK_CONSTRAINT as r, ExtractFieldOutputTypes as s, CodecTypesOf as t, FieldInputTypesOf as u, QueryOperationReturn as v, ResolveCodecTypes as w, QueryOperationTypesBase as x, QueryOperationSelfSpec as y };
202
+ //# sourceMappingURL=types-D1QODyT3.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types-D1QODyT3.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;;AAUA;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;CAA8C;AAAZ,KA1E5C,UAAA,GA0E4C;EACtB,SAAA,OAAA,EAAA,SAAA,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ageBase } from '@prisma-next/contract/types';\nimport type { CodecTrait } from '@prisma-next/framework-components/codec';\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<THash extends string = string> = StorageBase<THash> & {\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 SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\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 TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly operationTypes: TOperationTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\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 QueryOperationArgSpec = {\n readonly codecId?: string;\n readonly traits?: readonly CodecTrait[];\n readonly nullable: boolean;\n};\n\nexport type QueryOperationTypeEntry = {\n readonly args: readonly QueryOperationArgSpec[];\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 ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n\nexport type ResolveOperationTypes<_TContract, TTypeMaps> = OperationTypesOf<TTypeMaps>;\n"],"mappings":";AA8HA,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"}
1
+ {"version":3,"file":"types-DRR5stkj.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type { ColumnDefault, StorageBase } from '@prisma-next/contract/types';\nimport type { CodecTrait } from '@prisma-next/framework-components/codec';\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<THash extends string = string> = StorageBase<THash> & {\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 SqlModelFieldStorage = {\n readonly column: string;\n readonly codecId?: string;\n readonly nullable?: boolean;\n};\n\nexport type SqlModelStorage = {\n readonly table: string;\n readonly fields: Record<string, SqlModelFieldStorage>;\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 TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly operationTypes: TOperationTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n readonly fieldOutputTypes: TFieldOutputTypes;\n readonly fieldInputTypes: TFieldInputTypes;\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\n/**\n * Dispatch hint identifying the first-argument target of an operation.\n *\n * Used by ORM column helpers to decide whether an operation is reachable on a\n * field. Either names a concrete codec identity or a set of capability traits\n * that the field's codec must carry.\n */\nexport type QueryOperationSelfSpec =\n | { readonly codecId: string; readonly traits?: never }\n | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };\n\n/**\n * Structural shape an operation's impl must return: any value carrying a\n * codec-exact `returnType` descriptor. `Expression<T>` (from\n * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)\n * extends this. Trait-targeted returns are deliberately excluded — predicate\n * detection and result decoding both depend on knowing the concrete return\n * codec.\n */\nexport type QueryOperationReturn = {\n readonly returnType: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type QueryOperationTypeEntry = {\n readonly self?: QueryOperationSelfSpec;\n readonly impl: (...args: never[]) => QueryOperationReturn;\n};\n\nexport type SqlQueryOperationTypes<\n _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,\n T extends Record<string, QueryOperationTypeEntry>,\n> = 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 ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type FieldOutputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldOutputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type FieldInputTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly fieldInputTypes: infer F }\n ? F extends Record<string, Record<string, unknown>>\n ? F\n : Record<string, never>\n : Record<string, never>;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n\nexport type ResolveOperationTypes<_TContract, TTypeMaps> = OperationTypesOf<TTypeMaps>;\n"],"mappings":";AA8HA,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 StorageTable, C as ResolveCodecTypes, D as SqlQueryOperationTypes, E as SqlModelStorage, F as applyFkDefaults, M as TypeMaps, N as TypeMapsPhantomKey, O as SqlStorage, P as UniqueConstraint, S as ReferentialAction, T as SqlModelFieldStorage, _ as PrimaryKey, a as ExtractCodecTypes, b as QueryOperationTypesBase, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKey, g as OperationTypesOf, h as Index, i as DEFAULT_FK_INDEX, j as StorageTypeInstance, k as StorageColumn, l as ExtractTypeMapsFromContract, m as ForeignKeyReferences, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as ForeignKeyOptions, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as QueryOperationArgSpec, w as ResolveOperationTypes, x as QueryOperationTypesOf, y as QueryOperationTypeEntry } from "./types-DdNz1nUf.mjs";
2
- export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type OperationTypesOf, type PrimaryKey, type QueryOperationArgSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlModelFieldStorage, type SqlModelStorage, type SqlQueryOperationTypes, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
1
+ import { A as StorageColumn, C as ReferentialAction, D as SqlModelStorage, E as SqlModelFieldStorage, F as UniqueConstraint, I as applyFkDefaults, M as StorageTypeInstance, N as TypeMaps, O as SqlQueryOperationTypes, P as TypeMapsPhantomKey, S as QueryOperationTypesOf, T as ResolveOperationTypes, _ as PrimaryKey, a as ExtractCodecTypes, b as QueryOperationTypeEntry, c as ExtractQueryOperationTypes, d as FieldOutputTypesOf, f as ForeignKey, g as OperationTypesOf, h as Index, i as DEFAULT_FK_INDEX, j as StorageTable, k as SqlStorage, l as ExtractTypeMapsFromContract, m as ForeignKeyReferences, n as ContractWithTypeMaps, o as ExtractFieldInputTypes, p as ForeignKeyOptions, r as DEFAULT_FK_CONSTRAINT, s as ExtractFieldOutputTypes, t as CodecTypesOf, u as FieldInputTypesOf, v as QueryOperationReturn, w as ResolveCodecTypes, x as QueryOperationTypesBase, y as QueryOperationSelfSpec } from "./types-D1QODyT3.mjs";
2
+ export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractFieldInputTypes, type ExtractFieldOutputTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type FieldInputTypesOf, type FieldOutputTypesOf, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type OperationTypesOf, type PrimaryKey, type QueryOperationReturn, type QueryOperationSelfSpec, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlModelFieldStorage, type SqlModelStorage, type SqlQueryOperationTypes, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
@@ -1,4 +1,4 @@
1
- import { O as SqlStorage } from "./types-DdNz1nUf.mjs";
1
+ import { k as SqlStorage } from "./types-D1QODyT3.mjs";
2
2
  import { Contract } from "@prisma-next/contract/types";
3
3
  import { CodecLookup } from "@prisma-next/framework-components/codec";
4
4
 
package/dist/validate.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-BjZ6lOS1.mjs";
1
+ import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-DWoHkCUr.mjs";
2
2
  import { ContractValidationError, validateContract as validateContract$1 } from "@prisma-next/contract/validate-contract";
3
3
 
4
4
  //#region src/validate.ts
@@ -103,6 +103,13 @@ const StorageSchema = type({
103
103
  function isPlainRecord(value) {
104
104
  return typeof value === "object" && value !== null && !Array.isArray(value);
105
105
  }
106
+ function findDuplicateValue(values) {
107
+ const seen = /* @__PURE__ */ new Set();
108
+ for (const value of values) {
109
+ if (seen.has(value)) return value;
110
+ seen.add(value);
111
+ }
112
+ }
106
113
  function isContractFieldType(value) {
107
114
  if (!isPlainRecord(value)) return false;
108
115
  const kind = value["kind"];
@@ -210,6 +217,8 @@ function validateSqlContract(value) {
210
217
  * Currently checks:
211
218
  * - duplicate named primary key / unique / index / foreign key objects within a table
212
219
  * - duplicate unique, index, or foreign key declarations within a table
220
+ * - duplicate columns within primary key / unique / index definitions
221
+ * - nullable columns in primary key definitions
213
222
  * - `setNull` referential action on a non-nullable FK column (would fail at runtime)
214
223
  * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)
215
224
  */
@@ -226,8 +235,15 @@ function validateStorageSemantics(storage) {
226
235
  for (const index of table.indexes) registerNamedObject("index", index.name);
227
236
  for (const fk of table.foreignKeys) registerNamedObject("foreign key", fk.name);
228
237
  for (const [name, kinds] of namedObjects) if (kinds.length > 1) errors.push(`Table "${tableName}": named object "${name}" is declared multiple times (${kinds.join(", ")})`);
238
+ if (table.primaryKey) {
239
+ const duplicateColumn = findDuplicateValue(table.primaryKey.columns);
240
+ if (duplicateColumn !== void 0) errors.push(`Table "${tableName}": primary key contains duplicate column "${duplicateColumn}"`);
241
+ for (const columnName of table.primaryKey.columns) if (table.columns[columnName]?.nullable === true) errors.push(`Table "${tableName}": primary key column "${columnName}" is nullable; primary key columns must be NOT NULL`);
242
+ }
229
243
  const seenUniqueDefinitions = /* @__PURE__ */ new Set();
230
244
  for (const unique of table.uniques) {
245
+ const duplicateColumn = findDuplicateValue(unique.columns);
246
+ if (duplicateColumn !== void 0) errors.push(`Table "${tableName}": unique constraint contains duplicate column "${duplicateColumn}"`);
231
247
  const signature = JSON.stringify({ columns: unique.columns });
232
248
  if (seenUniqueDefinitions.has(signature)) {
233
249
  errors.push(`Table "${tableName}": duplicate unique constraint definition on columns [${unique.columns.join(", ")}]`);
@@ -237,6 +253,8 @@ function validateStorageSemantics(storage) {
237
253
  }
238
254
  const seenIndexDefinitions = /* @__PURE__ */ new Set();
239
255
  for (const index of table.indexes) {
256
+ const duplicateColumn = findDuplicateValue(index.columns);
257
+ if (duplicateColumn !== void 0) errors.push(`Table "${tableName}": index contains duplicate column "${duplicateColumn}"`);
240
258
  const signature = JSON.stringify({
241
259
  columns: index.columns,
242
260
  using: index.using ?? null,
@@ -278,4 +296,4 @@ function validateStorageSemantics(storage) {
278
296
 
279
297
  //#endregion
280
298
  export { ForeignKeySchema as a, validateModel as c, validateStorageSemantics as d, ForeignKeyReferencesSchema as i, validateSqlContract as l, ColumnDefaultLiteralSchema as n, IndexSchema as o, ColumnDefaultSchema as r, ReferentialActionSchema as s, ColumnDefaultFunctionSchema as t, validateStorage as u };
281
- //# sourceMappingURL=validators-BjZ6lOS1.mjs.map
299
+ //# sourceMappingURL=validators-DWoHkCUr.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"validators-DWoHkCUr.mjs","names":["errors: string[]"],"sources":["../src/validators.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { ContractValidationError } from '@prisma-next/contract/validate-contract';\nimport { type } from 'arktype';\nimport type {\n ForeignKey,\n ForeignKeyReferences,\n PrimaryKey,\n ReferentialAction,\n SqlStorage,\n StorageTypeInstance,\n UniqueConstraint,\n} from './types';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst generatorKindSchema = type(\"'generator'\");\nconst generatorIdSchema = type('string').narrow((value, ctx) => {\n return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value) ? true : ctx.mustBe('a flat generator id');\n});\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst ExecutionMutationDefaultValueSchema = type({\n '+': 'reject',\n kind: generatorKindSchema,\n id: generatorIdSchema,\n 'params?': 'Record<string, unknown>',\n});\n\nconst ExecutionMutationDefaultSchema = type({\n '+': 'reject',\n ref: {\n '+': 'reject',\n table: 'string',\n column: 'string',\n },\n 'onCreate?': ExecutionMutationDefaultValueSchema,\n 'onUpdate?': ExecutionMutationDefaultValueSchema,\n});\n\nconst ExecutionSchema = type({\n '+': 'reject',\n executionHash: 'string',\n mutations: {\n '+': 'reject',\n defaults: ExecutionMutationDefaultSchema.array().readonly(),\n },\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\nconst StorageTypeInstanceSchema = type.declare<StorageTypeInstance>().type({\n codecId: 'string',\n nativeType: 'string',\n typeParams: 'Record<string, unknown>',\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKey>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraint>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'using?': 'string',\n 'config?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({\n table: 'string',\n columns: type.string.array().readonly(),\n});\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKey>().type({\n columns: type.string.array().readonly(),\n references: ForeignKeyReferencesSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nconst StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n});\n\nconst StorageSchema = type({\n '+': 'reject',\n storageHash: 'string',\n tables: type({ '[string]': StorageTableSchema }),\n 'types?': type({ '[string]': StorageTypeInstanceSchema }),\n});\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction findDuplicateValue(values: readonly string[]): string | undefined {\n const seen = new Set<string>();\n for (const value of values) {\n if (seen.has(value)) {\n return value;\n }\n seen.add(value);\n }\n return undefined;\n}\n\nfunction isContractFieldType(value: unknown): boolean {\n if (!isPlainRecord(value)) return false;\n const kind = value['kind'];\n if (kind === 'scalar') {\n if (typeof value['codecId'] !== 'string') return false;\n const typeParams = value['typeParams'];\n if (typeParams !== undefined && !isPlainRecord(typeParams)) return false;\n return true;\n }\n if (kind === 'valueObject') {\n return typeof value['name'] === 'string';\n }\n if (kind === 'union') {\n const members = value['members'];\n if (!Array.isArray(members)) return false;\n return members.every((m) => isContractFieldType(m));\n }\n return false;\n}\n\nconst ContractFieldTypeSchema = type('unknown').narrow((value, ctx) =>\n isContractFieldType(value) ? true : ctx.mustBe('scalar, valueObject, or union field type'),\n);\n\nconst ModelFieldSchema = type({\n '+': 'reject',\n nullable: 'boolean',\n type: ContractFieldTypeSchema,\n 'many?': 'true',\n 'dict?': 'true',\n});\n\nconst ModelStorageFieldSchema = type({\n column: 'string',\n 'codecId?': 'string',\n 'nullable?': 'boolean',\n});\n\nconst ModelStorageSchema = type({\n table: 'string',\n fields: type({ '[string]': ModelStorageFieldSchema }),\n});\n\nconst ModelSchema = type({\n storage: ModelStorageSchema,\n 'fields?': type({ '[string]': ModelFieldSchema }),\n 'relations?': type({ '[string]': 'unknown' }),\n 'discriminator?': 'unknown',\n 'variants?': 'unknown',\n 'base?': 'string',\n 'owner?': 'string',\n});\n\nconst ContractMetaSchema = type({\n '[string]': 'unknown',\n});\n\nconst SqlContractSchema = type({\n '+': 'reject',\n target: 'string',\n targetFamily: \"'sql'\",\n 'coreHash?': 'string',\n profileHash: 'string',\n 'capabilities?': 'Record<string, Record<string, boolean>>',\n 'extensionPacks?': 'Record<string, unknown>',\n 'meta?': ContractMetaSchema,\n 'roots?': 'Record<string, string>',\n models: type({ '[string]': ModelSchema }),\n 'valueObjects?': 'Record<string, unknown>',\n storage: StorageSchema,\n 'execution?': ExecutionSchema,\n});\n\n// NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()\n// instead of type.declare<T>().type() because the ColumnDefault union's value field\n// includes bigint | Date (runtime-only types after decoding) which cannot be expressed\n// in Arktype's JSON validation DSL. The `as SqlStorage` cast in validateStorage() bridges\n// the gap between the JSON-safe Arktype output and the runtime TypeScript type.\n// See decodeContractDefaults() in validate.ts for the decoding step.\n\n/**\n * Validates the structural shape of SqlStorage using Arktype.\n *\n * @param value - The storage value to validate\n * @returns The validated storage if structure is valid\n * @throws Error if the storage structure is invalid\n */\nexport function validateStorage(value: unknown): SqlStorage {\n const result = StorageSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Storage validation failed: ${messages}`);\n }\n return result as SqlStorage;\n}\n\nexport function validateModel(value: unknown): unknown {\n const result = ModelSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Model validation failed: ${messages}`);\n }\n return result;\n}\n\n/**\n * Validates the structural shape of an SQL contract using Arktype.\n *\n * Ensures all required fields are present and have the correct types,\n * including SQL-specific storage structure (tables, columns, constraints).\n *\n * @param value - The contract value to validate (typically from a JSON import)\n * @returns The validated contract if structure is valid\n * @throws ContractValidationError if the contract structure is invalid\n */\nexport function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T {\n if (typeof value !== 'object' || value === null) {\n throw new ContractValidationError(\n 'Contract structural validation failed: value must be an object',\n 'structural',\n );\n }\n\n const rawValue = value as { targetFamily?: string };\n if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {\n throw new ContractValidationError(\n `Unsupported target family: ${rawValue.targetFamily}`,\n 'structural',\n );\n }\n\n const contractResult = SqlContractSchema(value);\n\n if (contractResult instanceof type.errors) {\n const messages = contractResult.map((p: { message: string }) => p.message).join('; ');\n throw new ContractValidationError(\n `Contract structural validation failed: ${messages}`,\n 'structural',\n );\n }\n\n // Arktype's inferred output type differs from T due to exactOptionalPropertyTypes\n // and branded hash types — the runtime value is structurally compatible after validation\n return contractResult as unknown as T;\n}\n\n/**\n * Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.\n *\n * Returns an array of human-readable error strings. Empty array = valid.\n *\n * Currently checks:\n * - duplicate named primary key / unique / index / foreign key objects within a table\n * - duplicate unique, index, or foreign key declarations within a table\n * - duplicate columns within primary key / unique / index definitions\n * - nullable columns in primary key definitions\n * - `setNull` referential action on a non-nullable FK column (would fail at runtime)\n * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)\n */\nexport function validateStorageSemantics(storage: SqlStorage): string[] {\n const errors: string[] = [];\n\n for (const [tableName, table] of Object.entries(storage.tables)) {\n const namedObjects = new Map<string, string[]>();\n const registerNamedObject = (kind: string, name: string | undefined) => {\n if (!name) return;\n namedObjects.set(name, [...(namedObjects.get(name) ?? []), kind]);\n };\n\n registerNamedObject('primary key', table.primaryKey?.name);\n for (const unique of table.uniques) {\n registerNamedObject('unique constraint', unique.name);\n }\n for (const index of table.indexes) {\n registerNamedObject('index', index.name);\n }\n for (const fk of table.foreignKeys) {\n registerNamedObject('foreign key', fk.name);\n }\n\n for (const [name, kinds] of namedObjects) {\n if (kinds.length > 1) {\n errors.push(\n `Table \"${tableName}\": named object \"${name}\" is declared multiple times (${kinds.join(', ')})`,\n );\n }\n }\n\n if (table.primaryKey) {\n const duplicateColumn = findDuplicateValue(table.primaryKey.columns);\n if (duplicateColumn !== undefined) {\n errors.push(\n `Table \"${tableName}\": primary key contains duplicate column \"${duplicateColumn}\"`,\n );\n }\n\n for (const columnName of table.primaryKey.columns) {\n const column = table.columns[columnName];\n if (column?.nullable === true) {\n errors.push(\n `Table \"${tableName}\": primary key column \"${columnName}\" is nullable; primary key columns must be NOT NULL`,\n );\n }\n }\n }\n\n const seenUniqueDefinitions = new Set<string>();\n for (const unique of table.uniques) {\n const duplicateColumn = findDuplicateValue(unique.columns);\n if (duplicateColumn !== undefined) {\n errors.push(\n `Table \"${tableName}\": unique constraint contains duplicate column \"${duplicateColumn}\"`,\n );\n }\n\n const signature = JSON.stringify({ columns: unique.columns });\n if (seenUniqueDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate unique constraint definition on columns [${unique.columns.join(', ')}]`,\n );\n continue;\n }\n seenUniqueDefinitions.add(signature);\n }\n\n const seenIndexDefinitions = new Set<string>();\n for (const index of table.indexes) {\n const duplicateColumn = findDuplicateValue(index.columns);\n if (duplicateColumn !== undefined) {\n errors.push(`Table \"${tableName}\": index contains duplicate column \"${duplicateColumn}\"`);\n }\n\n const signature = JSON.stringify({\n columns: index.columns,\n using: index.using ?? null,\n config: index.config ?? null,\n });\n if (seenIndexDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate index definition on columns [${index.columns.join(', ')}]`,\n );\n continue;\n }\n seenIndexDefinitions.add(signature);\n }\n\n const seenForeignKeyDefinitions = new Set<string>();\n for (const fk of table.foreignKeys) {\n const signature = JSON.stringify({\n columns: fk.columns,\n references: fk.references,\n onDelete: fk.onDelete ?? null,\n onUpdate: fk.onUpdate ?? null,\n constraint: fk.constraint,\n index: fk.index,\n });\n if (seenForeignKeyDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate foreign key definition on columns [${fk.columns.join(', ')}]`,\n );\n continue;\n }\n seenForeignKeyDefinitions.add(signature);\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n const column = table.columns[colName];\n if (!column) continue;\n\n if (fk.onDelete === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onDelete setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onUpdate === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onUpdate setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onDelete === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onDelete setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n if (fk.onUpdate === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onUpdate setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n }\n }\n }\n\n return errors;\n}\n"],"mappings":";;;;AAkBA,MAAM,oBAAoB,KAAK,YAAY;AAC3C,MAAM,qBAAqB,KAAK,aAAa;AAC7C,MAAM,sBAAsB,KAAK,cAAc;AAC/C,MAAM,oBAAoB,KAAK,SAAS,CAAC,QAAQ,OAAO,QAAQ;AAC9D,QAAO,8BAA8B,KAAK,MAAM,GAAG,OAAO,IAAI,OAAO,sBAAsB;EAC3F;AAEF,MAAa,6BAA6B,KAAK,SAA+B,CAAC,KAAK;CAClF,MAAM;CACN,OAAO;CACR,CAAC;AAEF,MAAa,8BAA8B,KAAK,SAAgC,CAAC,KAAK;CACpF,MAAM;CACN,YAAY;CACb,CAAC;AAEF,MAAa,sBAAsB,2BAA2B,GAAG,4BAA4B;AAE7F,MAAM,sCAAsC,KAAK;CAC/C,KAAK;CACL,MAAM;CACN,IAAI;CACJ,WAAW;CACZ,CAAC;AAEF,MAAM,iCAAiC,KAAK;CAC1C,KAAK;CACL,KAAK;EACH,KAAK;EACL,OAAO;EACP,QAAQ;EACT;CACD,aAAa;CACb,aAAa;CACd,CAAC;AAEF,MAAM,kBAAkB,KAAK;CAC3B,KAAK;CACL,eAAe;CACf,WAAW;EACT,KAAK;EACL,UAAU,+BAA+B,OAAO,CAAC,UAAU;EAC5D;CACF,CAAC;AAEF,MAAM,sBAAsB,KAAK;CAC/B,KAAK;CACL,YAAY;CACZ,SAAS;CACT,UAAU;CACV,eAAe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,OAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,OACzE,QAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;AAEH,OAAI,GAAG,aAAa,gBAAgB,CAAC,OAAO,YAAY,OAAO,YAAY,OACzE,QAAO,KACL,UAAU,UAAU,gDAAgD,QAAQ,wCAC7E;;;AAMT,QAAO"}
@@ -1,4 +1,4 @@
1
- import { O as SqlStorage, S as ReferentialAction, f as ForeignKey, m as ForeignKeyReferences } from "./types-DdNz1nUf.mjs";
1
+ import { C as ReferentialAction, f as ForeignKey, k as SqlStorage, m as ForeignKeyReferences } from "./types-D1QODyT3.mjs";
2
2
  import { Contract } from "@prisma-next/contract/types";
3
3
  import * as arktype_internal_variants_object_ts0 from "arktype/internal/variants/object.ts";
4
4
  import * as arktype_internal_variants_string_ts0 from "arktype/internal/variants/string.ts";
@@ -52,6 +52,8 @@ declare function validateSqlContract<T extends Contract<SqlStorage>>(value: unkn
52
52
  * Currently checks:
53
53
  * - duplicate named primary key / unique / index / foreign key objects within a table
54
54
  * - duplicate unique, index, or foreign key declarations within a table
55
+ * - duplicate columns within primary key / unique / index definitions
56
+ * - nullable columns in primary key definitions
55
57
  * - `setNull` referential action on a non-nullable FK column (would fail at runtime)
56
58
  * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)
57
59
  */
@@ -1 +1 @@
1
- {"version":3,"file":"validators.d.mts","names":[],"sources":["../src/validators.ts"],"sourcesContent":[],"mappings":";;;;;;KAaK,oBAAA;;8CAEyC;;AAJ7B,KAMZ,qBAAA,GAJoB;EAIpB,SAAA,IAAA,EAAA,UAAqB;EAQb,SAAA,UAAA,EAAA,MAAA;AAKb,CAAA;AAKa,cAVA,0BAUgF,EAVtD,oCAAA,CAAA,UAUsD,CAVtD,oBAUsD,EAAA,CAAA,CAAA,CAAA;AAA7D,cALnB,2BAKmB,EALQ,oCAAA,CAAA,UAKR,CALQ,qBAKR,EAAA,CAAA,CA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CAAA,CAAA,CAAA;AAAA,cA4DnB,WA5DmB,EAiE9B,oCAAA,CALsB,UA5DQ,CAAA;EAAA,OAAA,EAAA,SAAA,MAAA,EAAA;EA4DnB,IAAA,CAAA,EAAA,MAAA;EAOA,KAAA,CAAA,EAAA,MAAA;EAKA,MAAA,CAAA,EAPX,MAOW,CAAA,MAAA,EAAA,OAE4D,CAAA;AAEzE,CAAA,EAAA,CAAa,CAAA,CAAA;AAgIG,cAzIH,0BAyI8C,EAzIpB,oCAAA,CAAA,UAyIoB,CAzIpB,oBAyIoB,EAAA,CAAA,CAAA,CAAA;AAS3C,cA7IH,uBA6IgB,EA7IO,oCAAA,CAAA,UA6IP,CA7IO,iBA6IP,EAAA,CAAA,CAAA,CAAA;AAmBb,cA5JH,gBA4JsB,EA5JN,oCAAA,CAAA,UA4JM,CA5JN,UA4JM,EAAA,CAAA,CAAA,CAAA;;;;;AA4CnC;;;iBAxEgB,eAAA,kBAAiC;iBASjC,aAAA;;;;;;;;;;;iBAmBA,8BAA8B,SAAS,8BAA8B;;;;;;;;;;;;;;iBA4CrE,wBAAA,UAAkC"}
@@ -1,3 +1,3 @@
1
- import { a as ForeignKeySchema, c as validateModel, d as validateStorageSemantics, i as ForeignKeyReferencesSchema, l as validateSqlContract, n as ColumnDefaultLiteralSchema, o as IndexSchema, r as ColumnDefaultSchema, s as ReferentialActionSchema, t as ColumnDefaultFunctionSchema, u as validateStorage } from "./validators-BjZ6lOS1.mjs";
1
+ import { a as ForeignKeySchema, c as validateModel, d as validateStorageSemantics, i as ForeignKeyReferencesSchema, l as validateSqlContract, n as ColumnDefaultLiteralSchema, o as IndexSchema, r as ColumnDefaultSchema, s as ReferentialActionSchema, t as ColumnDefaultFunctionSchema, u as validateStorage } from "./validators-DWoHkCUr.mjs";
2
2
 
3
3
  export { ColumnDefaultFunctionSchema, ColumnDefaultLiteralSchema, ColumnDefaultSchema, ForeignKeyReferencesSchema, ForeignKeySchema, IndexSchema, ReferentialActionSchema, validateModel, validateSqlContract, validateStorage, validateStorageSemantics };
package/package.json CHANGED
@@ -1,21 +1,22 @@
1
1
  {
2
2
  "name": "@prisma-next/sql-contract",
3
- "version": "0.5.0-dev.6",
3
+ "version": "0.5.0-dev.61",
4
+ "license": "Apache-2.0",
4
5
  "type": "module",
5
6
  "sideEffects": false,
6
7
  "description": "SQL contract types, validators, and IR factories for Prisma Next",
7
8
  "dependencies": {
8
9
  "arktype": "^2.1.25",
9
- "@prisma-next/contract": "0.5.0-dev.6",
10
- "@prisma-next/framework-components": "0.5.0-dev.6"
10
+ "@prisma-next/contract": "0.5.0-dev.61",
11
+ "@prisma-next/framework-components": "0.5.0-dev.61"
11
12
  },
12
13
  "devDependencies": {
13
14
  "tsdown": "0.18.4",
14
15
  "typescript": "5.9.3",
15
16
  "vitest": "4.0.17",
16
- "@prisma-next/test-utils": "0.0.1",
17
+ "@prisma-next/tsconfig": "0.0.0",
17
18
  "@prisma-next/tsdown": "0.0.0",
18
- "@prisma-next/tsconfig": "0.0.0"
19
+ "@prisma-next/test-utils": "0.0.1"
19
20
  },
20
21
  "files": [
21
22
  "dist",
@@ -14,7 +14,8 @@ export type {
14
14
  Index,
15
15
  OperationTypesOf,
16
16
  PrimaryKey,
17
- QueryOperationArgSpec,
17
+ QueryOperationReturn,
18
+ QueryOperationSelfSpec,
18
19
  QueryOperationTypeEntry,
19
20
  QueryOperationTypesBase,
20
21
  QueryOperationTypesOf,
package/src/types.ts CHANGED
@@ -167,18 +167,38 @@ export type OperationTypesOf<T> = [T] extends [never]
167
167
  : Record<string, never>
168
168
  : Record<string, never>;
169
169
 
170
- export type QueryOperationArgSpec = {
171
- readonly codecId?: string;
172
- readonly traits?: readonly CodecTrait[];
173
- readonly nullable: boolean;
170
+ /**
171
+ * Dispatch hint identifying the first-argument target of an operation.
172
+ *
173
+ * Used by ORM column helpers to decide whether an operation is reachable on a
174
+ * field. Either names a concrete codec identity or a set of capability traits
175
+ * that the field's codec must carry.
176
+ */
177
+ export type QueryOperationSelfSpec =
178
+ | { readonly codecId: string; readonly traits?: never }
179
+ | { readonly traits: readonly CodecTrait[]; readonly codecId?: never };
180
+
181
+ /**
182
+ * Structural shape an operation's impl must return: any value carrying a
183
+ * codec-exact `returnType` descriptor. `Expression<T>` (from
184
+ * `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
185
+ * extends this. Trait-targeted returns are deliberately excluded — predicate
186
+ * detection and result decoding both depend on knowing the concrete return
187
+ * codec.
188
+ */
189
+ export type QueryOperationReturn = {
190
+ readonly returnType: { readonly codecId: string; readonly nullable: boolean };
174
191
  };
175
192
 
176
193
  export type QueryOperationTypeEntry = {
177
- readonly args: readonly QueryOperationArgSpec[];
178
- readonly returns: { readonly codecId: string; readonly nullable: boolean };
194
+ readonly self?: QueryOperationSelfSpec;
195
+ readonly impl: (...args: never[]) => QueryOperationReturn;
179
196
  };
180
197
 
181
- export type SqlQueryOperationTypes<T extends Record<string, QueryOperationTypeEntry>> = T;
198
+ export type SqlQueryOperationTypes<
199
+ _CT extends Record<string, { readonly input: unknown; readonly output: unknown }>,
200
+ T extends Record<string, QueryOperationTypeEntry>,
201
+ > = T;
182
202
 
183
203
  export type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
184
204
 
package/src/validators.ts CHANGED
@@ -139,6 +139,17 @@ function isPlainRecord(value: unknown): value is Record<string, unknown> {
139
139
  return typeof value === 'object' && value !== null && !Array.isArray(value);
140
140
  }
141
141
 
142
+ function findDuplicateValue(values: readonly string[]): string | undefined {
143
+ const seen = new Set<string>();
144
+ for (const value of values) {
145
+ if (seen.has(value)) {
146
+ return value;
147
+ }
148
+ seen.add(value);
149
+ }
150
+ return undefined;
151
+ }
152
+
142
153
  function isContractFieldType(value: unknown): boolean {
143
154
  if (!isPlainRecord(value)) return false;
144
155
  const kind = value['kind'];
@@ -293,6 +304,8 @@ export function validateSqlContract<T extends Contract<SqlStorage>>(value: unkno
293
304
  * Currently checks:
294
305
  * - duplicate named primary key / unique / index / foreign key objects within a table
295
306
  * - duplicate unique, index, or foreign key declarations within a table
307
+ * - duplicate columns within primary key / unique / index definitions
308
+ * - nullable columns in primary key definitions
296
309
  * - `setNull` referential action on a non-nullable FK column (would fail at runtime)
297
310
  * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)
298
311
  */
@@ -325,8 +338,33 @@ export function validateStorageSemantics(storage: SqlStorage): string[] {
325
338
  }
326
339
  }
327
340
 
341
+ if (table.primaryKey) {
342
+ const duplicateColumn = findDuplicateValue(table.primaryKey.columns);
343
+ if (duplicateColumn !== undefined) {
344
+ errors.push(
345
+ `Table "${tableName}": primary key contains duplicate column "${duplicateColumn}"`,
346
+ );
347
+ }
348
+
349
+ for (const columnName of table.primaryKey.columns) {
350
+ const column = table.columns[columnName];
351
+ if (column?.nullable === true) {
352
+ errors.push(
353
+ `Table "${tableName}": primary key column "${columnName}" is nullable; primary key columns must be NOT NULL`,
354
+ );
355
+ }
356
+ }
357
+ }
358
+
328
359
  const seenUniqueDefinitions = new Set<string>();
329
360
  for (const unique of table.uniques) {
361
+ const duplicateColumn = findDuplicateValue(unique.columns);
362
+ if (duplicateColumn !== undefined) {
363
+ errors.push(
364
+ `Table "${tableName}": unique constraint contains duplicate column "${duplicateColumn}"`,
365
+ );
366
+ }
367
+
330
368
  const signature = JSON.stringify({ columns: unique.columns });
331
369
  if (seenUniqueDefinitions.has(signature)) {
332
370
  errors.push(
@@ -339,6 +377,11 @@ export function validateStorageSemantics(storage: SqlStorage): string[] {
339
377
 
340
378
  const seenIndexDefinitions = new Set<string>();
341
379
  for (const index of table.indexes) {
380
+ const duplicateColumn = findDuplicateValue(index.columns);
381
+ if (duplicateColumn !== undefined) {
382
+ errors.push(`Table "${tableName}": index contains duplicate column "${duplicateColumn}"`);
383
+ }
384
+
342
385
  const signature = JSON.stringify({
343
386
  columns: index.columns,
344
387
  using: index.using ?? null,
@@ -1 +0,0 @@
1
- {"version":3,"file":"types-DdNz1nUf.d.mts","names":[],"sources":["../src/types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ACxC,sBAAsB;KAG3B,iCAAiC,iCAAiC,IAC1E,YAAY,EAAE,2BAA2B;KAGjC,yBAAyB,qBACjC,wBACA;;cACY,eAAe,+BAEvB,wBACF;KAEM,wBAAwB,qBAChC,wBACA;;cACY,eAAe,+BAEvB,wBACF;KAEM,uBAAuB,aAAa,4BAA4B;KAChE,gCAAgC,sBAAsB,4BAA4B;KAClF,6BAA6B,mBAAmB,4BAA4B;KAC5E,4BAA4B,kBAAkB,4BAA4B;KAE1E,2CAA2C,6BACnD,kBAAkB,aAClB,aAAa;KAEL,+CAA+C,iBAAiB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"validators-BjZ6lOS1.mjs","names":["errors: string[]"],"sources":["../src/validators.ts"],"sourcesContent":["import type { Contract } from '@prisma-next/contract/types';\nimport { ContractValidationError } from '@prisma-next/contract/validate-contract';\nimport { type } from 'arktype';\nimport type {\n ForeignKey,\n ForeignKeyReferences,\n PrimaryKey,\n ReferentialAction,\n SqlStorage,\n StorageTypeInstance,\n UniqueConstraint,\n} from './types';\n\ntype ColumnDefaultLiteral = {\n readonly kind: 'literal';\n readonly value: string | number | boolean | Record<string, unknown> | unknown[] | null;\n};\ntype ColumnDefaultFunction = { readonly kind: 'function'; readonly expression: string };\nconst literalKindSchema = type(\"'literal'\");\nconst functionKindSchema = type(\"'function'\");\nconst generatorKindSchema = type(\"'generator'\");\nconst generatorIdSchema = type('string').narrow((value, ctx) => {\n return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value) ? true : ctx.mustBe('a flat generator id');\n});\n\nexport const ColumnDefaultLiteralSchema = type.declare<ColumnDefaultLiteral>().type({\n kind: literalKindSchema,\n value: 'string | number | boolean | null | unknown[] | Record<string, unknown>',\n});\n\nexport const ColumnDefaultFunctionSchema = type.declare<ColumnDefaultFunction>().type({\n kind: functionKindSchema,\n expression: 'string',\n});\n\nexport const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);\n\nconst ExecutionMutationDefaultValueSchema = type({\n '+': 'reject',\n kind: generatorKindSchema,\n id: generatorIdSchema,\n 'params?': 'Record<string, unknown>',\n});\n\nconst ExecutionMutationDefaultSchema = type({\n '+': 'reject',\n ref: {\n '+': 'reject',\n table: 'string',\n column: 'string',\n },\n 'onCreate?': ExecutionMutationDefaultValueSchema,\n 'onUpdate?': ExecutionMutationDefaultValueSchema,\n});\n\nconst ExecutionSchema = type({\n '+': 'reject',\n executionHash: 'string',\n mutations: {\n '+': 'reject',\n defaults: ExecutionMutationDefaultSchema.array().readonly(),\n },\n});\n\nconst StorageColumnSchema = type({\n '+': 'reject',\n nativeType: 'string',\n codecId: 'string',\n nullable: 'boolean',\n 'typeParams?': 'Record<string, unknown>',\n 'typeRef?': 'string',\n 'default?': ColumnDefaultSchema,\n}).narrow((col, ctx) => {\n if (col.typeParams !== undefined && col.typeRef !== undefined) {\n return ctx.mustBe('a column with either typeParams or typeRef, not both');\n }\n return true;\n});\n\nconst StorageTypeInstanceSchema = type.declare<StorageTypeInstance>().type({\n codecId: 'string',\n nativeType: 'string',\n typeParams: 'Record<string, unknown>',\n});\n\nconst PrimaryKeySchema = type.declare<PrimaryKey>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nconst UniqueConstraintSchema = type.declare<UniqueConstraint>().type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n});\n\nexport const IndexSchema = type({\n columns: type.string.array().readonly(),\n 'name?': 'string',\n 'using?': 'string',\n 'config?': 'Record<string, unknown>',\n});\n\nexport const ForeignKeyReferencesSchema = type.declare<ForeignKeyReferences>().type({\n table: 'string',\n columns: type.string.array().readonly(),\n});\n\nexport const ReferentialActionSchema = type\n .declare<ReferentialAction>()\n .type(\"'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'\");\n\nexport const ForeignKeySchema = type.declare<ForeignKey>().type({\n columns: type.string.array().readonly(),\n references: ForeignKeyReferencesSchema,\n 'name?': 'string',\n 'onDelete?': ReferentialActionSchema,\n 'onUpdate?': ReferentialActionSchema,\n constraint: 'boolean',\n index: 'boolean',\n});\n\nconst StorageTableSchema = type({\n '+': 'reject',\n columns: type({ '[string]': StorageColumnSchema }),\n 'primaryKey?': PrimaryKeySchema,\n uniques: UniqueConstraintSchema.array().readonly(),\n indexes: IndexSchema.array().readonly(),\n foreignKeys: ForeignKeySchema.array().readonly(),\n});\n\nconst StorageSchema = type({\n '+': 'reject',\n storageHash: 'string',\n tables: type({ '[string]': StorageTableSchema }),\n 'types?': type({ '[string]': StorageTypeInstanceSchema }),\n});\n\nfunction isPlainRecord(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value);\n}\n\nfunction isContractFieldType(value: unknown): boolean {\n if (!isPlainRecord(value)) return false;\n const kind = value['kind'];\n if (kind === 'scalar') {\n if (typeof value['codecId'] !== 'string') return false;\n const typeParams = value['typeParams'];\n if (typeParams !== undefined && !isPlainRecord(typeParams)) return false;\n return true;\n }\n if (kind === 'valueObject') {\n return typeof value['name'] === 'string';\n }\n if (kind === 'union') {\n const members = value['members'];\n if (!Array.isArray(members)) return false;\n return members.every((m) => isContractFieldType(m));\n }\n return false;\n}\n\nconst ContractFieldTypeSchema = type('unknown').narrow((value, ctx) =>\n isContractFieldType(value) ? true : ctx.mustBe('scalar, valueObject, or union field type'),\n);\n\nconst ModelFieldSchema = type({\n '+': 'reject',\n nullable: 'boolean',\n type: ContractFieldTypeSchema,\n 'many?': 'true',\n 'dict?': 'true',\n});\n\nconst ModelStorageFieldSchema = type({\n column: 'string',\n 'codecId?': 'string',\n 'nullable?': 'boolean',\n});\n\nconst ModelStorageSchema = type({\n table: 'string',\n fields: type({ '[string]': ModelStorageFieldSchema }),\n});\n\nconst ModelSchema = type({\n storage: ModelStorageSchema,\n 'fields?': type({ '[string]': ModelFieldSchema }),\n 'relations?': type({ '[string]': 'unknown' }),\n 'discriminator?': 'unknown',\n 'variants?': 'unknown',\n 'base?': 'string',\n 'owner?': 'string',\n});\n\nconst ContractMetaSchema = type({\n '[string]': 'unknown',\n});\n\nconst SqlContractSchema = type({\n '+': 'reject',\n target: 'string',\n targetFamily: \"'sql'\",\n 'coreHash?': 'string',\n profileHash: 'string',\n 'capabilities?': 'Record<string, Record<string, boolean>>',\n 'extensionPacks?': 'Record<string, unknown>',\n 'meta?': ContractMetaSchema,\n 'roots?': 'Record<string, string>',\n models: type({ '[string]': ModelSchema }),\n 'valueObjects?': 'Record<string, unknown>',\n storage: StorageSchema,\n 'execution?': ExecutionSchema,\n});\n\n// NOTE: StorageColumnSchema, StorageTableSchema, and StorageSchema use bare type()\n// instead of type.declare<T>().type() because the ColumnDefault union's value field\n// includes bigint | Date (runtime-only types after decoding) which cannot be expressed\n// in Arktype's JSON validation DSL. The `as SqlStorage` cast in validateStorage() bridges\n// the gap between the JSON-safe Arktype output and the runtime TypeScript type.\n// See decodeContractDefaults() in validate.ts for the decoding step.\n\n/**\n * Validates the structural shape of SqlStorage using Arktype.\n *\n * @param value - The storage value to validate\n * @returns The validated storage if structure is valid\n * @throws Error if the storage structure is invalid\n */\nexport function validateStorage(value: unknown): SqlStorage {\n const result = StorageSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Storage validation failed: ${messages}`);\n }\n return result as SqlStorage;\n}\n\nexport function validateModel(value: unknown): unknown {\n const result = ModelSchema(value);\n if (result instanceof type.errors) {\n const messages = result.map((p: { message: string }) => p.message).join('; ');\n throw new Error(`Model validation failed: ${messages}`);\n }\n return result;\n}\n\n/**\n * Validates the structural shape of an SQL contract using Arktype.\n *\n * Ensures all required fields are present and have the correct types,\n * including SQL-specific storage structure (tables, columns, constraints).\n *\n * @param value - The contract value to validate (typically from a JSON import)\n * @returns The validated contract if structure is valid\n * @throws ContractValidationError if the contract structure is invalid\n */\nexport function validateSqlContract<T extends Contract<SqlStorage>>(value: unknown): T {\n if (typeof value !== 'object' || value === null) {\n throw new ContractValidationError(\n 'Contract structural validation failed: value must be an object',\n 'structural',\n );\n }\n\n const rawValue = value as { targetFamily?: string };\n if (rawValue.targetFamily !== undefined && rawValue.targetFamily !== 'sql') {\n throw new ContractValidationError(\n `Unsupported target family: ${rawValue.targetFamily}`,\n 'structural',\n );\n }\n\n const contractResult = SqlContractSchema(value);\n\n if (contractResult instanceof type.errors) {\n const messages = contractResult.map((p: { message: string }) => p.message).join('; ');\n throw new ContractValidationError(\n `Contract structural validation failed: ${messages}`,\n 'structural',\n );\n }\n\n // Arktype's inferred output type differs from T due to exactOptionalPropertyTypes\n // and branded hash types — the runtime value is structurally compatible after validation\n return contractResult as unknown as T;\n}\n\n/**\n * Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.\n *\n * Returns an array of human-readable error strings. Empty array = valid.\n *\n * Currently checks:\n * - duplicate named primary key / unique / index / foreign key objects within a table\n * - duplicate unique, index, or foreign key declarations within a table\n * - `setNull` referential action on a non-nullable FK column (would fail at runtime)\n * - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)\n */\nexport function validateStorageSemantics(storage: SqlStorage): string[] {\n const errors: string[] = [];\n\n for (const [tableName, table] of Object.entries(storage.tables)) {\n const namedObjects = new Map<string, string[]>();\n const registerNamedObject = (kind: string, name: string | undefined) => {\n if (!name) return;\n namedObjects.set(name, [...(namedObjects.get(name) ?? []), kind]);\n };\n\n registerNamedObject('primary key', table.primaryKey?.name);\n for (const unique of table.uniques) {\n registerNamedObject('unique constraint', unique.name);\n }\n for (const index of table.indexes) {\n registerNamedObject('index', index.name);\n }\n for (const fk of table.foreignKeys) {\n registerNamedObject('foreign key', fk.name);\n }\n\n for (const [name, kinds] of namedObjects) {\n if (kinds.length > 1) {\n errors.push(\n `Table \"${tableName}\": named object \"${name}\" is declared multiple times (${kinds.join(', ')})`,\n );\n }\n }\n\n const seenUniqueDefinitions = new Set<string>();\n for (const unique of table.uniques) {\n const signature = JSON.stringify({ columns: unique.columns });\n if (seenUniqueDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate unique constraint definition on columns [${unique.columns.join(', ')}]`,\n );\n continue;\n }\n seenUniqueDefinitions.add(signature);\n }\n\n const seenIndexDefinitions = new Set<string>();\n for (const index of table.indexes) {\n const signature = JSON.stringify({\n columns: index.columns,\n using: index.using ?? null,\n config: index.config ?? null,\n });\n if (seenIndexDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate index definition on columns [${index.columns.join(', ')}]`,\n );\n continue;\n }\n seenIndexDefinitions.add(signature);\n }\n\n const seenForeignKeyDefinitions = new Set<string>();\n for (const fk of table.foreignKeys) {\n const signature = JSON.stringify({\n columns: fk.columns,\n references: fk.references,\n onDelete: fk.onDelete ?? null,\n onUpdate: fk.onUpdate ?? null,\n constraint: fk.constraint,\n index: fk.index,\n });\n if (seenForeignKeyDefinitions.has(signature)) {\n errors.push(\n `Table \"${tableName}\": duplicate foreign key definition on columns [${fk.columns.join(', ')}]`,\n );\n continue;\n }\n seenForeignKeyDefinitions.add(signature);\n }\n\n for (const fk of table.foreignKeys) {\n for (const colName of fk.columns) {\n const column = table.columns[colName];\n if (!column) continue;\n\n if (fk.onDelete === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onDelete setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onUpdate === 'setNull' && !column.nullable) {\n errors.push(\n `Table \"${tableName}\": onUpdate setNull on foreign key column \"${colName}\" which is NOT NULL`,\n );\n }\n if (fk.onDelete === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onDelete setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n if (fk.onUpdate === 'setDefault' && !column.nullable && column.default === undefined) {\n errors.push(\n `Table \"${tableName}\": onUpdate setDefault on foreign key column \"${colName}\" which is NOT NULL and has no DEFAULT`,\n );\n }\n }\n }\n }\n\n return errors;\n}\n"],"mappings":";;;;AAkBA,MAAM,oBAAoB,KAAK,YAAY;AAC3C,MA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