@prisma-next/sql-contract 0.8.0 → 0.9.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +13 -11
- package/dist/factories.d.mts +2 -2
- package/dist/factories.d.mts.map +1 -1
- package/dist/factories.mjs +16 -14
- package/dist/factories.mjs.map +1 -1
- package/dist/index-type-validation.d.mts +2 -2
- package/dist/index-type-validation.mjs +1 -1
- package/dist/index-type-validation.mjs.map +1 -1
- package/dist/{index-types-DqVqGHwg.d.mts → index-types-B1cf5N0F.d.mts} +1 -1
- package/dist/{index-types-DqVqGHwg.d.mts.map → index-types-B1cf5N0F.d.mts.map} +1 -1
- package/dist/index-types.d.mts +1 -1
- package/dist/types-B0lbr9cb.d.mts +498 -0
- package/dist/types-B0lbr9cb.d.mts.map +1 -0
- package/dist/types-iqFGDcJp.mjs +389 -0
- package/dist/types-iqFGDcJp.mjs.map +1 -0
- package/dist/types.d.mts +2 -2
- package/dist/types.mjs +2 -2
- package/dist/validators.d.mts +27 -15
- package/dist/validators.d.mts.map +1 -1
- package/dist/validators.mjs +409 -2
- package/dist/validators.mjs.map +1 -0
- package/package.json +6 -7
- package/src/exports/types.ts +30 -9
- package/src/factories.ts +19 -32
- package/src/index-type-validation.ts +1 -1
- package/src/index.ts +0 -1
- package/src/ir/foreign-key-references.ts +26 -0
- package/src/ir/foreign-key.ts +50 -0
- package/src/ir/postgres-enum-storage-entry.ts +55 -0
- package/src/ir/primary-key.ts +22 -0
- package/src/ir/sql-index.ts +33 -0
- package/src/ir/sql-node.ts +52 -0
- package/src/ir/sql-storage.ts +154 -0
- package/src/ir/sql-unspecified-namespace.ts +51 -0
- package/src/ir/storage-column.ts +55 -0
- package/src/ir/storage-table.ts +63 -0
- package/src/ir/storage-type-instance.ts +60 -0
- package/src/ir/unique-constraint.ts +22 -0
- package/src/types.ts +38 -99
- package/src/validators.ts +268 -28
- package/dist/types-hgzy8ME1.mjs +0 -13
- package/dist/types-hgzy8ME1.mjs.map +0 -1
- package/dist/types-njsiV-Ck.d.mts +0 -186
- package/dist/types-njsiV-Ck.d.mts.map +0 -1
- package/dist/validate.d.mts +0 -9
- package/dist/validate.d.mts.map +0 -1
- package/dist/validate.mjs +0 -106
- package/dist/validate.mjs.map +0 -1
- package/dist/validators-Dm5X-Hvg.mjs +0 -294
- package/dist/validators-Dm5X-Hvg.mjs.map +0 -1
- package/src/exports/validate.ts +0 -1
- package/src/validate.ts +0 -227
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-hgzy8ME1.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 readonly type?: string;\n readonly options?: 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 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 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\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"],"mappings":";AAsHA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;CACzC,OAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAA;EAC/C,OAAO,GAAG,SAAS,kBAAkB,SAAA;EACtC"}
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
import { ColumnDefault, StorageBase } from "@prisma-next/contract/types";
|
|
2
|
-
import { CodecTrait } from "@prisma-next/framework-components/codec";
|
|
3
|
-
|
|
4
|
-
//#region src/types.d.ts
|
|
5
|
-
/**
|
|
6
|
-
* A column definition in storage.
|
|
7
|
-
*
|
|
8
|
-
* `typeParams` is optional because most columns use non-parameterized types.
|
|
9
|
-
* Columns with parameterized types can either inline `typeParams` or reference
|
|
10
|
-
* a named {@link StorageTypeInstance} via `typeRef`.
|
|
11
|
-
*/
|
|
12
|
-
type StorageColumn = {
|
|
13
|
-
readonly nativeType: string;
|
|
14
|
-
readonly codecId: string;
|
|
15
|
-
readonly nullable: boolean;
|
|
16
|
-
/**
|
|
17
|
-
* Opaque, codec-owned JS/type parameters.
|
|
18
|
-
* The codec that owns `codecId` defines the shape and semantics.
|
|
19
|
-
* Mutually exclusive with `typeRef`.
|
|
20
|
-
*/
|
|
21
|
-
readonly typeParams?: Record<string, unknown>;
|
|
22
|
-
/**
|
|
23
|
-
* Reference to a named type instance in `storage.types`.
|
|
24
|
-
* Mutually exclusive with `typeParams`.
|
|
25
|
-
*/
|
|
26
|
-
readonly typeRef?: string;
|
|
27
|
-
/**
|
|
28
|
-
* Default value for the column.
|
|
29
|
-
* Can be a literal value or database function.
|
|
30
|
-
*/
|
|
31
|
-
readonly default?: ColumnDefault;
|
|
32
|
-
};
|
|
33
|
-
type PrimaryKey = {
|
|
34
|
-
readonly columns: readonly string[];
|
|
35
|
-
readonly name?: string;
|
|
36
|
-
};
|
|
37
|
-
type UniqueConstraint = {
|
|
38
|
-
readonly columns: readonly string[];
|
|
39
|
-
readonly name?: string;
|
|
40
|
-
};
|
|
41
|
-
type Index = {
|
|
42
|
-
readonly columns: readonly string[];
|
|
43
|
-
readonly name?: string;
|
|
44
|
-
readonly type?: string;
|
|
45
|
-
readonly options?: Record<string, unknown>;
|
|
46
|
-
};
|
|
47
|
-
type ForeignKeyReferences = {
|
|
48
|
-
readonly table: string;
|
|
49
|
-
readonly columns: readonly string[];
|
|
50
|
-
};
|
|
51
|
-
type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
52
|
-
type ForeignKeyOptions = {
|
|
53
|
-
readonly name?: string;
|
|
54
|
-
readonly onDelete?: ReferentialAction;
|
|
55
|
-
readonly onUpdate?: ReferentialAction;
|
|
56
|
-
};
|
|
57
|
-
type ForeignKey = {
|
|
58
|
-
readonly columns: readonly string[];
|
|
59
|
-
readonly references: ForeignKeyReferences;
|
|
60
|
-
readonly name?: string;
|
|
61
|
-
readonly onDelete?: ReferentialAction;
|
|
62
|
-
readonly onUpdate?: ReferentialAction; /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
63
|
-
readonly constraint: boolean; /** Whether to emit a backing index for the FK columns. */
|
|
64
|
-
readonly index: boolean;
|
|
65
|
-
};
|
|
66
|
-
type StorageTable = {
|
|
67
|
-
readonly columns: Record<string, StorageColumn>;
|
|
68
|
-
readonly primaryKey?: PrimaryKey;
|
|
69
|
-
readonly uniques: ReadonlyArray<UniqueConstraint>;
|
|
70
|
-
readonly indexes: ReadonlyArray<Index>;
|
|
71
|
-
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
72
|
-
};
|
|
73
|
-
/**
|
|
74
|
-
* A named, parameterized type instance.
|
|
75
|
-
* These are registered in `storage.types` for reuse across columns
|
|
76
|
-
* and to enable ergonomic schema surfaces like `schema.types.MyType`.
|
|
77
|
-
*
|
|
78
|
-
* Unlike {@link StorageColumn}, `typeParams` is required here because
|
|
79
|
-
* `StorageTypeInstance` exists specifically to define reusable parameterized types.
|
|
80
|
-
* A type instance without parameters would be redundant—columns can reference
|
|
81
|
-
* the codec directly via `codecId`.
|
|
82
|
-
*/
|
|
83
|
-
type StorageTypeInstance = {
|
|
84
|
-
readonly codecId: string;
|
|
85
|
-
readonly nativeType: string;
|
|
86
|
-
readonly typeParams: Record<string, unknown>;
|
|
87
|
-
};
|
|
88
|
-
type SqlStorage<THash extends string = string> = StorageBase<THash> & {
|
|
89
|
-
readonly tables: Record<string, StorageTable>;
|
|
90
|
-
/**
|
|
91
|
-
* Named type instances for parameterized/custom types.
|
|
92
|
-
* Columns can reference these via `typeRef`.
|
|
93
|
-
*/
|
|
94
|
-
readonly types?: Record<string, StorageTypeInstance>;
|
|
95
|
-
};
|
|
96
|
-
type SqlModelFieldStorage = {
|
|
97
|
-
readonly column: string;
|
|
98
|
-
readonly codecId?: string;
|
|
99
|
-
readonly nullable?: boolean;
|
|
100
|
-
};
|
|
101
|
-
type SqlModelStorage = {
|
|
102
|
-
readonly table: string;
|
|
103
|
-
readonly fields: Record<string, SqlModelFieldStorage>;
|
|
104
|
-
};
|
|
105
|
-
declare const DEFAULT_FK_CONSTRAINT = true;
|
|
106
|
-
declare const DEFAULT_FK_INDEX = true;
|
|
107
|
-
declare function applyFkDefaults(fk: {
|
|
108
|
-
constraint?: boolean | undefined;
|
|
109
|
-
index?: boolean | undefined;
|
|
110
|
-
}, overrideDefaults?: {
|
|
111
|
-
constraint?: boolean | undefined;
|
|
112
|
-
index?: boolean | undefined;
|
|
113
|
-
}): {
|
|
114
|
-
constraint: boolean;
|
|
115
|
-
index: boolean;
|
|
116
|
-
};
|
|
117
|
-
type TypeMaps<TCodecTypes extends Record<string, {
|
|
118
|
-
output: unknown;
|
|
119
|
-
}> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>, TFieldOutputTypes extends Record<string, Record<string, unknown>> = Record<string, never>, TFieldInputTypes extends Record<string, Record<string, unknown>> = Record<string, never>> = {
|
|
120
|
-
readonly codecTypes: TCodecTypes;
|
|
121
|
-
readonly queryOperationTypes: TQueryOperationTypes;
|
|
122
|
-
readonly fieldOutputTypes: TFieldOutputTypes;
|
|
123
|
-
readonly fieldInputTypes: TFieldInputTypes;
|
|
124
|
-
};
|
|
125
|
-
type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
126
|
-
readonly codecTypes: infer C;
|
|
127
|
-
} ? C extends Record<string, {
|
|
128
|
-
output: unknown;
|
|
129
|
-
}> ? C : Record<string, never> : Record<string, never>;
|
|
130
|
-
/**
|
|
131
|
-
* Dispatch hint identifying the first-argument target of an operation.
|
|
132
|
-
*
|
|
133
|
-
* Used by ORM column helpers to decide whether an operation is reachable on a
|
|
134
|
-
* field. Either names a concrete codec identity or a set of capability traits
|
|
135
|
-
* that the field's codec must carry.
|
|
136
|
-
*/
|
|
137
|
-
type QueryOperationSelfSpec = {
|
|
138
|
-
readonly codecId: string;
|
|
139
|
-
readonly traits?: never;
|
|
140
|
-
} | {
|
|
141
|
-
readonly traits: readonly CodecTrait[];
|
|
142
|
-
readonly codecId?: never;
|
|
143
|
-
};
|
|
144
|
-
/**
|
|
145
|
-
* Structural shape an operation's impl must return: any value carrying a
|
|
146
|
-
* codec-exact `returnType` descriptor. `Expression<T>` (from
|
|
147
|
-
* `@prisma-next/sql-relational-core/expression`, with `T extends ScopeField`)
|
|
148
|
-
* extends this. Trait-targeted returns are deliberately excluded — predicate
|
|
149
|
-
* detection and result decoding both depend on knowing the concrete return
|
|
150
|
-
* codec.
|
|
151
|
-
*/
|
|
152
|
-
type QueryOperationReturn = {
|
|
153
|
-
readonly returnType: {
|
|
154
|
-
readonly codecId: string;
|
|
155
|
-
readonly nullable: boolean;
|
|
156
|
-
};
|
|
157
|
-
};
|
|
158
|
-
type QueryOperationTypeEntry = {
|
|
159
|
-
readonly self?: QueryOperationSelfSpec;
|
|
160
|
-
readonly impl: (...args: never[]) => QueryOperationReturn;
|
|
161
|
-
};
|
|
162
|
-
type SqlQueryOperationTypes<_CT extends Record<string, {
|
|
163
|
-
readonly input: unknown;
|
|
164
|
-
readonly output: unknown;
|
|
165
|
-
}>, T extends Record<string, QueryOperationTypeEntry>> = T;
|
|
166
|
-
type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
|
|
167
|
-
type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
168
|
-
readonly queryOperationTypes: infer Q;
|
|
169
|
-
} ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
|
|
170
|
-
type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
|
|
171
|
-
type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
|
|
172
|
-
type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
|
|
173
|
-
type FieldOutputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
174
|
-
readonly fieldOutputTypes: infer F;
|
|
175
|
-
} ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
|
|
176
|
-
type FieldInputTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
177
|
-
readonly fieldInputTypes: infer F;
|
|
178
|
-
} ? F extends Record<string, Record<string, unknown>> ? F : Record<string, never> : Record<string, never>;
|
|
179
|
-
type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
180
|
-
type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
181
|
-
type ExtractFieldOutputTypes<T> = FieldOutputTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
182
|
-
type ExtractFieldInputTypes<T> = FieldInputTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
183
|
-
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
|
|
184
|
-
//#endregion
|
|
185
|
-
export { StorageTypeInstance as A, ResolveCodecTypes as C, SqlStorage as D, SqlQueryOperationTypes as E, TypeMapsPhantomKey as M, UniqueConstraint as N, StorageColumn as O, applyFkDefaults as P, ReferentialAction as S, SqlModelStorage as T, QueryOperationReturn as _, ExtractCodecTypes as a, QueryOperationTypesBase as b, ExtractQueryOperationTypes as c, FieldOutputTypesOf as d, ForeignKey as f, PrimaryKey as g, Index as h, DEFAULT_FK_INDEX as i, TypeMaps as j, StorageTable 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, QueryOperationSelfSpec as v, SqlModelFieldStorage as w, QueryOperationTypesOf as x, QueryOperationTypeEntry as y };
|
|
186
|
-
//# sourceMappingURL=types-njsiV-Ck.d.mts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types-njsiV-Ck.d.mts","names":[],"sources":["../src/types.ts"],"mappings":";;;;;;AAUA;;;;;KAAY,aAAA;EAAA,SACD,UAAA;EAAA,SACA,OAAA;EAAA,SACA,QAAA;EAWA;;;;;EAAA,SALA,UAAA,GAAa,MAAA;EAaF;;;;EAAA,SARX,OAAA;EAaiB;;;;EAAA,SARjB,OAAA,GAAU,aAAA;AAAA;AAAA,KAGT,UAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGC,gBAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;AAAA;AAAA,KAGC,KAAA;EAAA,SACD,OAAA;EAAA,SACA,IAAA;EAAA,SACA,IAAA;EAAA,SACA,OAAA,GAAU,MAAA;AAAA;AAAA,KAGT,oBAAA;EAAA,SACD,KAAA;EAAA,SACA,OAAA;AAAA;AAAA,KAGC,iBAAA;AAAA,KAEA,iBAAA;EAAA,SACD,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA;AAAA;AAAA,KAGV,UAAA;EAAA,SACD,OAAA;EAAA,SACA,UAAA,EAAY,oBAAA;EAAA,SACZ,IAAA;EAAA,SACA,QAAA,GAAW,iBAAA;EAAA,SACX,QAAA,GAAW,iBAAA,EALV;EAAA,SAOD,UAAA;WAEA,KAAA;AAAA;AAAA,KAGC,YAAA;EAAA,SACD,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AAA,CAA4B,CAAA;AAAA,KAClF,uBAAA,MAA6B,kBAAA,CAAmB,2BAAA,CAA4B,CAAA;AAAA,KAC5E,sBAAA,MAA4B,iBAAA,CAAkB,2BAAA,CAA4B,CAAA;AAAA,KAE1E,iBAAA,0BAA2C,SAAA,oBACnD,iBAAA,CAAkB,SAAA,IAClB,YAAA,CAAa,SAAA"}
|
package/dist/validate.d.mts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { D as SqlStorage } from "./types-njsiV-Ck.mjs";
|
|
2
|
-
import { Contract } from "@prisma-next/contract/types";
|
|
3
|
-
import { CodecLookup } from "@prisma-next/framework-components/codec";
|
|
4
|
-
|
|
5
|
-
//#region src/validate.d.ts
|
|
6
|
-
declare function validateContract<TContract extends Contract<SqlStorage>>(value: unknown, codecLookup: CodecLookup): TContract;
|
|
7
|
-
//#endregion
|
|
8
|
-
export { validateContract };
|
|
9
|
-
//# sourceMappingURL=validate.d.mts.map
|
package/dist/validate.d.mts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"mappings":";;;;;iBAoNgB,gBAAA,mBAAmC,QAAA,CAAS,UAAA,EAAA,CAC1D,KAAA,WACA,WAAA,EAAa,WAAA,GACZ,SAAA"}
|
package/dist/validate.mjs
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { d as validateStorageSemantics, l as validateSqlContract } from "./validators-Dm5X-Hvg.mjs";
|
|
2
|
-
import { ContractValidationError, validateContract as validateContract$1 } from "@prisma-next/contract/validate-contract";
|
|
3
|
-
//#region src/validate.ts
|
|
4
|
-
function validateModelStorageReferences(contract) {
|
|
5
|
-
for (const [modelName, model] of Object.entries(contract.models)) {
|
|
6
|
-
const storageTable = model.storage.table;
|
|
7
|
-
const table = contract.storage.tables[storageTable];
|
|
8
|
-
if (!table) throw new ContractValidationError(`Model "${modelName}" references non-existent table "${storageTable}"`, "storage");
|
|
9
|
-
const columnNames = new Set(Object.keys(table.columns));
|
|
10
|
-
for (const [fieldName, field] of Object.entries(model.storage.fields)) if (!columnNames.has(field.column)) throw new ContractValidationError(`Model "${modelName}" field "${fieldName}" references non-existent column "${field.column}" in table "${storageTable}"`, "storage");
|
|
11
|
-
const JSON_NATIVE_TYPES = new Set(["json", "jsonb"]);
|
|
12
|
-
for (const [fieldName, domainField] of Object.entries(model.fields)) {
|
|
13
|
-
if (domainField.type?.kind !== "valueObject") continue;
|
|
14
|
-
const storageField = model.storage.fields[fieldName];
|
|
15
|
-
if (!storageField) continue;
|
|
16
|
-
const column = table.columns[storageField.column];
|
|
17
|
-
if (!column) continue;
|
|
18
|
-
if (!JSON_NATIVE_TYPES.has(column.nativeType)) throw new ContractValidationError(`Model "${modelName}" field "${fieldName}" is a value object but storage column "${storageField.column}" has nativeType "${column.nativeType}" (expected json or jsonb)`, "storage");
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
function validateContractLogic(contract) {
|
|
23
|
-
const tableNames = new Set(Object.keys(contract.storage.tables));
|
|
24
|
-
for (const [tableName, table] of Object.entries(contract.storage.tables)) {
|
|
25
|
-
const columnNames = new Set(Object.keys(table.columns));
|
|
26
|
-
if (table.primaryKey) {
|
|
27
|
-
for (const colName of table.primaryKey.columns) if (!columnNames.has(colName)) throw new ContractValidationError(`Table "${tableName}" primaryKey references non-existent column "${colName}"`, "storage");
|
|
28
|
-
}
|
|
29
|
-
for (const unique of table.uniques) for (const colName of unique.columns) if (!columnNames.has(colName)) throw new ContractValidationError(`Table "${tableName}" unique constraint references non-existent column "${colName}"`, "storage");
|
|
30
|
-
for (const index of table.indexes) for (const colName of index.columns) if (!columnNames.has(colName)) throw new ContractValidationError(`Table "${tableName}" index references non-existent column "${colName}"`, "storage");
|
|
31
|
-
for (const [colName, column] of Object.entries(table.columns)) if (!column.nullable && column.default?.kind === "literal" && column.default.value === null) throw new ContractValidationError(`Table "${tableName}" column "${colName}" is NOT NULL but has a literal null default`, "storage");
|
|
32
|
-
for (const fk of table.foreignKeys) {
|
|
33
|
-
for (const colName of fk.columns) if (!columnNames.has(colName)) throw new ContractValidationError(`Table "${tableName}" foreignKey references non-existent column "${colName}"`, "storage");
|
|
34
|
-
if (!tableNames.has(fk.references.table)) throw new ContractValidationError(`Table "${tableName}" foreignKey references non-existent table "${fk.references.table}"`, "storage");
|
|
35
|
-
const referencedTable = contract.storage.tables[fk.references.table];
|
|
36
|
-
if (!referencedTable) continue;
|
|
37
|
-
const referencedColumnNames = new Set(Object.keys(referencedTable.columns));
|
|
38
|
-
for (const colName of fk.references.columns) if (!referencedColumnNames.has(colName)) throw new ContractValidationError(`Table "${tableName}" foreignKey references non-existent column "${colName}" in table "${fk.references.table}"`, "storage");
|
|
39
|
-
if (fk.columns.length !== fk.references.columns.length) throw new ContractValidationError(`Table "${tableName}" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`, "storage");
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
function validateSqlStorage(contract) {
|
|
44
|
-
const sqlContract = validateSqlContract(contract);
|
|
45
|
-
validateContractLogic(sqlContract);
|
|
46
|
-
validateModelStorageReferences(sqlContract);
|
|
47
|
-
const semanticErrors = validateStorageSemantics(sqlContract.storage);
|
|
48
|
-
if (semanticErrors.length > 0) throw new ContractValidationError(`Contract semantic validation failed: ${semanticErrors.join("; ")}`, "storage");
|
|
49
|
-
}
|
|
50
|
-
function decodeContractDefaults(contract, codecLookup) {
|
|
51
|
-
const tables = contract.storage.tables;
|
|
52
|
-
let tablesChanged = false;
|
|
53
|
-
const decodedTables = {};
|
|
54
|
-
for (const [tableName, table] of Object.entries(tables)) {
|
|
55
|
-
let columnsChanged = false;
|
|
56
|
-
const decodedColumns = {};
|
|
57
|
-
for (const [columnName, column] of Object.entries(table.columns)) {
|
|
58
|
-
if (column.default?.kind === "literal") {
|
|
59
|
-
const codec = codecLookup.get(column.codecId);
|
|
60
|
-
if (codec) {
|
|
61
|
-
const decodedValue = codec.decodeJson(column.default.value);
|
|
62
|
-
if (decodedValue !== column.default.value) {
|
|
63
|
-
columnsChanged = true;
|
|
64
|
-
decodedColumns[columnName] = {
|
|
65
|
-
...column,
|
|
66
|
-
default: {
|
|
67
|
-
kind: "literal",
|
|
68
|
-
value: decodedValue
|
|
69
|
-
}
|
|
70
|
-
};
|
|
71
|
-
continue;
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
decodedColumns[columnName] = column;
|
|
76
|
-
}
|
|
77
|
-
if (columnsChanged) {
|
|
78
|
-
tablesChanged = true;
|
|
79
|
-
decodedTables[tableName] = {
|
|
80
|
-
...table,
|
|
81
|
-
columns: decodedColumns
|
|
82
|
-
};
|
|
83
|
-
} else decodedTables[tableName] = table;
|
|
84
|
-
}
|
|
85
|
-
if (!tablesChanged) return contract;
|
|
86
|
-
return {
|
|
87
|
-
...contract,
|
|
88
|
-
storage: {
|
|
89
|
-
...contract.storage,
|
|
90
|
-
tables: decodedTables
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
function validateContract(value, codecLookup) {
|
|
95
|
-
const validated = validateContract$1(value, validateSqlStorage);
|
|
96
|
-
try {
|
|
97
|
-
return decodeContractDefaults(validated, codecLookup);
|
|
98
|
-
} catch (error) {
|
|
99
|
-
if (error instanceof ContractValidationError) throw error;
|
|
100
|
-
throw new ContractValidationError(error instanceof Error ? error.message : String(error), "storage");
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
//#endregion
|
|
104
|
-
export { validateContract };
|
|
105
|
-
|
|
106
|
-
//# sourceMappingURL=validate.mjs.map
|
package/dist/validate.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"validate.mjs","names":["f","frameworkValidateContract"],"sources":["../src/validate.ts"],"sourcesContent":["import type {\n ColumnDefaultLiteralInputValue,\n Contract,\n ContractField,\n ContractModel,\n JsonValue,\n} from '@prisma-next/contract/types';\nimport {\n ContractValidationError,\n validateContract as frameworkValidateContract,\n} from '@prisma-next/contract/validate-contract';\nimport type { CodecLookup } from '@prisma-next/framework-components/codec';\nimport type { SqlModelStorage, SqlStorage, StorageColumn, StorageTable } from './types';\nimport { validateSqlContract, validateStorageSemantics } from './validators';\n\ntype SqlValidationContract = Contract<SqlStorage, Record<string, ContractModel<SqlModelStorage>>>;\n\nfunction validateModelStorageReferences(contract: SqlValidationContract): void {\n for (const [modelName, model] of Object.entries(contract.models)) {\n const storageTable = model.storage.table;\n\n const table = contract.storage.tables[storageTable] as\n | (typeof contract.storage.tables)[string]\n | undefined;\n if (!table) {\n throw new ContractValidationError(\n `Model \"${modelName}\" references non-existent table \"${storageTable}\"`,\n 'storage',\n );\n }\n\n const columnNames = new Set(Object.keys(table.columns));\n for (const [fieldName, field] of Object.entries(model.storage.fields)) {\n if (!columnNames.has(field.column)) {\n throw new ContractValidationError(\n `Model \"${modelName}\" field \"${fieldName}\" references non-existent column \"${field.column}\" in table \"${storageTable}\"`,\n 'storage',\n );\n }\n }\n\n const JSON_NATIVE_TYPES = new Set(['json', 'jsonb']);\n for (const [fieldName, domainField] of Object.entries(model.fields)) {\n const f = domainField as ContractField;\n if (f.type?.kind !== 'valueObject') continue;\n const storageField = model.storage.fields[fieldName];\n if (!storageField) continue;\n const column = table.columns[storageField.column];\n if (!column) continue;\n if (!JSON_NATIVE_TYPES.has(column.nativeType)) {\n throw new ContractValidationError(\n `Model \"${modelName}\" field \"${fieldName}\" is a value object but storage column \"${storageField.column}\" has nativeType \"${column.nativeType}\" (expected json or jsonb)`,\n 'storage',\n );\n }\n }\n }\n}\n\nfunction validateContractLogic(contract: Contract<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 ContractValidationError(\n `Table \"${tableName}\" primaryKey references non-existent column \"${colName}\"`,\n 'storage',\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 ContractValidationError(\n `Table \"${tableName}\" unique constraint references non-existent column \"${colName}\"`,\n 'storage',\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 ContractValidationError(\n `Table \"${tableName}\" index references non-existent column \"${colName}\"`,\n 'storage',\n );\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 ContractValidationError(\n `Table \"${tableName}\" column \"${colName}\" is NOT NULL but has a literal null default`,\n 'storage',\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 ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\"`,\n 'storage',\n );\n }\n }\n\n if (!tableNames.has(fk.references.table)) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent table \"${fk.references.table}\"`,\n 'storage',\n );\n }\n\n const referencedTable = contract.storage.tables[fk.references.table];\n if (!referencedTable) continue;\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 ContractValidationError(\n `Table \"${tableName}\" foreignKey references non-existent column \"${colName}\" in table \"${fk.references.table}\"`,\n 'storage',\n );\n }\n }\n\n if (fk.columns.length !== fk.references.columns.length) {\n throw new ContractValidationError(\n `Table \"${tableName}\" foreignKey column count (${fk.columns.length}) does not match referenced column count (${fk.references.columns.length})`,\n 'storage',\n );\n }\n }\n }\n}\n\nfunction validateSqlStorage(contract: Contract): void {\n const sqlContract = validateSqlContract<SqlValidationContract>(contract);\n validateContractLogic(sqlContract);\n validateModelStorageReferences(sqlContract);\n const semanticErrors = validateStorageSemantics(sqlContract.storage);\n if (semanticErrors.length > 0) {\n throw new ContractValidationError(\n `Contract semantic validation failed: ${semanticErrors.join('; ')}`,\n 'storage',\n );\n }\n}\n\nfunction decodeContractDefaults<T extends Contract<SqlStorage>>(\n contract: T,\n codecLookup: CodecLookup,\n): 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 codec = codecLookup.get(column.codecId);\n if (codec) {\n const decodedValue = codec.decodeJson(\n column.default.value as JsonValue,\n ) as ColumnDefaultLiteralInputValue;\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 }\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 return {\n ...contract,\n storage: {\n ...contract.storage,\n tables: decodedTables,\n },\n } as T;\n}\n\nexport function validateContract<TContract extends Contract<SqlStorage>>(\n value: unknown,\n codecLookup: CodecLookup,\n): TContract {\n const validated = frameworkValidateContract<TContract>(value, validateSqlStorage);\n try {\n return decodeContractDefaults(validated, codecLookup);\n } catch (error) {\n if (error instanceof ContractValidationError) throw error;\n throw new ContractValidationError(\n error instanceof Error ? error.message : String(error),\n 'storage',\n );\n }\n}\n"],"mappings":";;;AAiBA,SAAS,+BAA+B,UAAuC;CAC7E,KAAK,MAAM,CAAC,WAAW,UAAU,OAAO,QAAQ,SAAS,OAAO,EAAE;EAChE,MAAM,eAAe,MAAM,QAAQ;EAEnC,MAAM,QAAQ,SAAS,QAAQ,OAAO;EAGtC,IAAI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,MAAM,EACtD,UACD"}
|
|
@@ -1,294 +0,0 @@
|
|
|
1
|
-
import { ContractValidationError } from "@prisma-next/contract/validate-contract";
|
|
2
|
-
import { type } from "arktype";
|
|
3
|
-
//#region src/validators.ts
|
|
4
|
-
const literalKindSchema = type("'literal'");
|
|
5
|
-
const functionKindSchema = type("'function'");
|
|
6
|
-
const generatorKindSchema = type("'generator'");
|
|
7
|
-
const generatorIdSchema = type("string").narrow((value, ctx) => {
|
|
8
|
-
return /^[A-Za-z0-9][A-Za-z0-9_-]*$/.test(value) ? true : ctx.mustBe("a flat generator id");
|
|
9
|
-
});
|
|
10
|
-
const ColumnDefaultLiteralSchema = type.declare().type({
|
|
11
|
-
kind: literalKindSchema,
|
|
12
|
-
value: "string | number | boolean | null | unknown[] | Record<string, unknown>"
|
|
13
|
-
});
|
|
14
|
-
const ColumnDefaultFunctionSchema = type.declare().type({
|
|
15
|
-
kind: functionKindSchema,
|
|
16
|
-
expression: "string"
|
|
17
|
-
});
|
|
18
|
-
const ColumnDefaultSchema = ColumnDefaultLiteralSchema.or(ColumnDefaultFunctionSchema);
|
|
19
|
-
const ExecutionMutationDefaultValueSchema = type({
|
|
20
|
-
"+": "reject",
|
|
21
|
-
kind: generatorKindSchema,
|
|
22
|
-
id: generatorIdSchema,
|
|
23
|
-
"params?": "Record<string, unknown>"
|
|
24
|
-
});
|
|
25
|
-
const ExecutionSchema = type({
|
|
26
|
-
"+": "reject",
|
|
27
|
-
executionHash: "string",
|
|
28
|
-
mutations: {
|
|
29
|
-
"+": "reject",
|
|
30
|
-
defaults: type({
|
|
31
|
-
"+": "reject",
|
|
32
|
-
ref: {
|
|
33
|
-
"+": "reject",
|
|
34
|
-
table: "string",
|
|
35
|
-
column: "string"
|
|
36
|
-
},
|
|
37
|
-
"onCreate?": ExecutionMutationDefaultValueSchema,
|
|
38
|
-
"onUpdate?": ExecutionMutationDefaultValueSchema
|
|
39
|
-
}).array().readonly()
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
const StorageColumnSchema = type({
|
|
43
|
-
"+": "reject",
|
|
44
|
-
nativeType: "string",
|
|
45
|
-
codecId: "string",
|
|
46
|
-
nullable: "boolean",
|
|
47
|
-
"typeParams?": "Record<string, unknown>",
|
|
48
|
-
"typeRef?": "string",
|
|
49
|
-
"default?": ColumnDefaultSchema
|
|
50
|
-
}).narrow((col, ctx) => {
|
|
51
|
-
if (col.typeParams !== void 0 && col.typeRef !== void 0) return ctx.mustBe("a column with either typeParams or typeRef, not both");
|
|
52
|
-
return true;
|
|
53
|
-
});
|
|
54
|
-
const StorageTypeInstanceSchema = type.declare().type({
|
|
55
|
-
codecId: "string",
|
|
56
|
-
nativeType: "string",
|
|
57
|
-
typeParams: "Record<string, unknown>"
|
|
58
|
-
});
|
|
59
|
-
const PrimaryKeySchema = type.declare().type({
|
|
60
|
-
columns: type.string.array().readonly(),
|
|
61
|
-
"name?": "string"
|
|
62
|
-
});
|
|
63
|
-
const UniqueConstraintSchema = type.declare().type({
|
|
64
|
-
columns: type.string.array().readonly(),
|
|
65
|
-
"name?": "string"
|
|
66
|
-
});
|
|
67
|
-
const IndexSchema = type({
|
|
68
|
-
columns: type.string.array().readonly(),
|
|
69
|
-
"name?": "string",
|
|
70
|
-
"type?": "string",
|
|
71
|
-
"options?": "Record<string, unknown>"
|
|
72
|
-
});
|
|
73
|
-
const ForeignKeyReferencesSchema = type.declare().type({
|
|
74
|
-
table: "string",
|
|
75
|
-
columns: type.string.array().readonly()
|
|
76
|
-
});
|
|
77
|
-
const ReferentialActionSchema = type.declare().type("'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault'");
|
|
78
|
-
const ForeignKeySchema = type.declare().type({
|
|
79
|
-
columns: type.string.array().readonly(),
|
|
80
|
-
references: ForeignKeyReferencesSchema,
|
|
81
|
-
"name?": "string",
|
|
82
|
-
"onDelete?": ReferentialActionSchema,
|
|
83
|
-
"onUpdate?": ReferentialActionSchema,
|
|
84
|
-
constraint: "boolean",
|
|
85
|
-
index: "boolean"
|
|
86
|
-
});
|
|
87
|
-
const StorageSchema = type({
|
|
88
|
-
"+": "reject",
|
|
89
|
-
storageHash: "string",
|
|
90
|
-
tables: type({ "[string]": type({
|
|
91
|
-
"+": "reject",
|
|
92
|
-
columns: type({ "[string]": StorageColumnSchema }),
|
|
93
|
-
"primaryKey?": PrimaryKeySchema,
|
|
94
|
-
uniques: UniqueConstraintSchema.array().readonly(),
|
|
95
|
-
indexes: IndexSchema.array().readonly(),
|
|
96
|
-
foreignKeys: ForeignKeySchema.array().readonly()
|
|
97
|
-
}) }),
|
|
98
|
-
"types?": type({ "[string]": StorageTypeInstanceSchema })
|
|
99
|
-
});
|
|
100
|
-
function isPlainRecord(value) {
|
|
101
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
102
|
-
}
|
|
103
|
-
function findDuplicateValue(values) {
|
|
104
|
-
const seen = /* @__PURE__ */ new Set();
|
|
105
|
-
for (const value of values) {
|
|
106
|
-
if (seen.has(value)) return value;
|
|
107
|
-
seen.add(value);
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
function isContractFieldType(value) {
|
|
111
|
-
if (!isPlainRecord(value)) return false;
|
|
112
|
-
const kind = value["kind"];
|
|
113
|
-
if (kind === "scalar") {
|
|
114
|
-
if (typeof value["codecId"] !== "string") return false;
|
|
115
|
-
const typeParams = value["typeParams"];
|
|
116
|
-
if (typeParams !== void 0 && !isPlainRecord(typeParams)) return false;
|
|
117
|
-
return true;
|
|
118
|
-
}
|
|
119
|
-
if (kind === "valueObject") return typeof value["name"] === "string";
|
|
120
|
-
if (kind === "union") {
|
|
121
|
-
const members = value["members"];
|
|
122
|
-
if (!Array.isArray(members)) return false;
|
|
123
|
-
return members.every((m) => isContractFieldType(m));
|
|
124
|
-
}
|
|
125
|
-
return false;
|
|
126
|
-
}
|
|
127
|
-
const ModelFieldSchema = type({
|
|
128
|
-
"+": "reject",
|
|
129
|
-
nullable: "boolean",
|
|
130
|
-
type: type("unknown").narrow((value, ctx) => isContractFieldType(value) ? true : ctx.mustBe("scalar, valueObject, or union field type")),
|
|
131
|
-
"many?": "true",
|
|
132
|
-
"dict?": "true"
|
|
133
|
-
});
|
|
134
|
-
const ModelSchema = type({
|
|
135
|
-
storage: type({
|
|
136
|
-
table: "string",
|
|
137
|
-
fields: type({ "[string]": type({
|
|
138
|
-
column: "string",
|
|
139
|
-
"codecId?": "string",
|
|
140
|
-
"nullable?": "boolean"
|
|
141
|
-
}) })
|
|
142
|
-
}),
|
|
143
|
-
"fields?": type({ "[string]": ModelFieldSchema }),
|
|
144
|
-
"relations?": type({ "[string]": "unknown" }),
|
|
145
|
-
"discriminator?": "unknown",
|
|
146
|
-
"variants?": "unknown",
|
|
147
|
-
"base?": "string",
|
|
148
|
-
"owner?": "string"
|
|
149
|
-
});
|
|
150
|
-
const SqlContractSchema = type({
|
|
151
|
-
"+": "reject",
|
|
152
|
-
target: "string",
|
|
153
|
-
targetFamily: "'sql'",
|
|
154
|
-
"coreHash?": "string",
|
|
155
|
-
profileHash: "string",
|
|
156
|
-
"capabilities?": "Record<string, Record<string, boolean>>",
|
|
157
|
-
"extensionPacks?": "Record<string, unknown>",
|
|
158
|
-
"meta?": type({ "[string]": "unknown" }),
|
|
159
|
-
"roots?": "Record<string, string>",
|
|
160
|
-
models: type({ "[string]": ModelSchema }),
|
|
161
|
-
"valueObjects?": "Record<string, unknown>",
|
|
162
|
-
storage: StorageSchema,
|
|
163
|
-
"execution?": ExecutionSchema
|
|
164
|
-
});
|
|
165
|
-
/**
|
|
166
|
-
* Validates the structural shape of SqlStorage using Arktype.
|
|
167
|
-
*
|
|
168
|
-
* @param value - The storage value to validate
|
|
169
|
-
* @returns The validated storage if structure is valid
|
|
170
|
-
* @throws Error if the storage structure is invalid
|
|
171
|
-
*/
|
|
172
|
-
function validateStorage(value) {
|
|
173
|
-
const result = StorageSchema(value);
|
|
174
|
-
if (result instanceof type.errors) {
|
|
175
|
-
const messages = result.map((p) => p.message).join("; ");
|
|
176
|
-
throw new Error(`Storage validation failed: ${messages}`);
|
|
177
|
-
}
|
|
178
|
-
return result;
|
|
179
|
-
}
|
|
180
|
-
function validateModel(value) {
|
|
181
|
-
const result = ModelSchema(value);
|
|
182
|
-
if (result instanceof type.errors) {
|
|
183
|
-
const messages = result.map((p) => p.message).join("; ");
|
|
184
|
-
throw new Error(`Model validation failed: ${messages}`);
|
|
185
|
-
}
|
|
186
|
-
return result;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Validates the structural shape of an SQL contract using Arktype.
|
|
190
|
-
*
|
|
191
|
-
* Ensures all required fields are present and have the correct types,
|
|
192
|
-
* including SQL-specific storage structure (tables, columns, constraints).
|
|
193
|
-
*
|
|
194
|
-
* @param value - The contract value to validate (typically from a JSON import)
|
|
195
|
-
* @returns The validated contract if structure is valid
|
|
196
|
-
* @throws ContractValidationError if the contract structure is invalid
|
|
197
|
-
*/
|
|
198
|
-
function validateSqlContract(value) {
|
|
199
|
-
if (typeof value !== "object" || value === null) throw new ContractValidationError("Contract structural validation failed: value must be an object", "structural");
|
|
200
|
-
const rawValue = value;
|
|
201
|
-
if (rawValue.targetFamily !== void 0 && rawValue.targetFamily !== "sql") throw new ContractValidationError(`Unsupported target family: ${rawValue.targetFamily}`, "structural");
|
|
202
|
-
const contractResult = SqlContractSchema(value);
|
|
203
|
-
if (contractResult instanceof type.errors) throw new ContractValidationError(`Contract structural validation failed: ${contractResult.map((p) => p.message).join("; ")}`, "structural");
|
|
204
|
-
return contractResult;
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Validates semantic constraints on SqlStorage that cannot be expressed in Arktype schemas.
|
|
208
|
-
*
|
|
209
|
-
* Returns an array of human-readable error strings. Empty array = valid.
|
|
210
|
-
*
|
|
211
|
-
* Currently checks:
|
|
212
|
-
* - duplicate named primary key / unique / index / foreign key objects within a table
|
|
213
|
-
* - duplicate unique, index, or foreign key declarations within a table
|
|
214
|
-
* - duplicate columns within primary key / unique / index definitions
|
|
215
|
-
* - nullable columns in primary key definitions
|
|
216
|
-
* - `setNull` referential action on a non-nullable FK column (would fail at runtime)
|
|
217
|
-
* - `setDefault` referential action on a non-nullable FK column without a DEFAULT (would fail at runtime)
|
|
218
|
-
*/
|
|
219
|
-
function validateStorageSemantics(storage) {
|
|
220
|
-
const errors = [];
|
|
221
|
-
for (const [tableName, table] of Object.entries(storage.tables)) {
|
|
222
|
-
const namedObjects = /* @__PURE__ */ new Map();
|
|
223
|
-
const registerNamedObject = (kind, name) => {
|
|
224
|
-
if (!name) return;
|
|
225
|
-
namedObjects.set(name, [...namedObjects.get(name) ?? [], kind]);
|
|
226
|
-
};
|
|
227
|
-
registerNamedObject("primary key", table.primaryKey?.name);
|
|
228
|
-
for (const unique of table.uniques) registerNamedObject("unique constraint", unique.name);
|
|
229
|
-
for (const index of table.indexes) registerNamedObject("index", index.name);
|
|
230
|
-
for (const fk of table.foreignKeys) registerNamedObject("foreign key", fk.name);
|
|
231
|
-
for (const [name, kinds] of namedObjects) if (kinds.length > 1) errors.push(`Table "${tableName}": named object "${name}" is declared multiple times (${kinds.join(", ")})`);
|
|
232
|
-
if (table.primaryKey) {
|
|
233
|
-
const duplicateColumn = findDuplicateValue(table.primaryKey.columns);
|
|
234
|
-
if (duplicateColumn !== void 0) errors.push(`Table "${tableName}": primary key contains duplicate column "${duplicateColumn}"`);
|
|
235
|
-
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`);
|
|
236
|
-
}
|
|
237
|
-
const seenUniqueDefinitions = /* @__PURE__ */ new Set();
|
|
238
|
-
for (const unique of table.uniques) {
|
|
239
|
-
const duplicateColumn = findDuplicateValue(unique.columns);
|
|
240
|
-
if (duplicateColumn !== void 0) errors.push(`Table "${tableName}": unique constraint contains duplicate column "${duplicateColumn}"`);
|
|
241
|
-
const signature = JSON.stringify({ columns: unique.columns });
|
|
242
|
-
if (seenUniqueDefinitions.has(signature)) {
|
|
243
|
-
errors.push(`Table "${tableName}": duplicate unique constraint definition on columns [${unique.columns.join(", ")}]`);
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
seenUniqueDefinitions.add(signature);
|
|
247
|
-
}
|
|
248
|
-
const sortOptions = (o) => o ? Object.fromEntries(Object.entries(o).sort(([a], [b]) => a.localeCompare(b))) : null;
|
|
249
|
-
const seenIndexDefinitions = /* @__PURE__ */ new Set();
|
|
250
|
-
for (const index of table.indexes) {
|
|
251
|
-
const duplicateColumn = findDuplicateValue(index.columns);
|
|
252
|
-
if (duplicateColumn !== void 0) errors.push(`Table "${tableName}": index contains duplicate column "${duplicateColumn}"`);
|
|
253
|
-
const signature = JSON.stringify({
|
|
254
|
-
columns: index.columns,
|
|
255
|
-
type: index.type ?? null,
|
|
256
|
-
options: sortOptions(index.options)
|
|
257
|
-
});
|
|
258
|
-
if (seenIndexDefinitions.has(signature)) {
|
|
259
|
-
errors.push(`Table "${tableName}": duplicate index definition on columns [${index.columns.join(", ")}]`);
|
|
260
|
-
continue;
|
|
261
|
-
}
|
|
262
|
-
seenIndexDefinitions.add(signature);
|
|
263
|
-
}
|
|
264
|
-
const seenForeignKeyDefinitions = /* @__PURE__ */ new Set();
|
|
265
|
-
for (const fk of table.foreignKeys) {
|
|
266
|
-
const signature = JSON.stringify({
|
|
267
|
-
columns: fk.columns,
|
|
268
|
-
references: fk.references,
|
|
269
|
-
onDelete: fk.onDelete ?? null,
|
|
270
|
-
onUpdate: fk.onUpdate ?? null,
|
|
271
|
-
constraint: fk.constraint,
|
|
272
|
-
index: fk.index
|
|
273
|
-
});
|
|
274
|
-
if (seenForeignKeyDefinitions.has(signature)) {
|
|
275
|
-
errors.push(`Table "${tableName}": duplicate foreign key definition on columns [${fk.columns.join(", ")}]`);
|
|
276
|
-
continue;
|
|
277
|
-
}
|
|
278
|
-
seenForeignKeyDefinitions.add(signature);
|
|
279
|
-
}
|
|
280
|
-
for (const fk of table.foreignKeys) for (const colName of fk.columns) {
|
|
281
|
-
const column = table.columns[colName];
|
|
282
|
-
if (!column) continue;
|
|
283
|
-
if (fk.onDelete === "setNull" && !column.nullable) errors.push(`Table "${tableName}": onDelete setNull on foreign key column "${colName}" which is NOT NULL`);
|
|
284
|
-
if (fk.onUpdate === "setNull" && !column.nullable) errors.push(`Table "${tableName}": onUpdate setNull on foreign key column "${colName}" which is NOT NULL`);
|
|
285
|
-
if (fk.onDelete === "setDefault" && !column.nullable && column.default === void 0) errors.push(`Table "${tableName}": onDelete setDefault on foreign key column "${colName}" which is NOT NULL and has no DEFAULT`);
|
|
286
|
-
if (fk.onUpdate === "setDefault" && !column.nullable && column.default === void 0) errors.push(`Table "${tableName}": onUpdate setDefault on foreign key column "${colName}" which is NOT NULL and has no DEFAULT`);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
return errors;
|
|
290
|
-
}
|
|
291
|
-
//#endregion
|
|
292
|
-
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 };
|
|
293
|
-
|
|
294
|
-
//# sourceMappingURL=validators-Dm5X-Hvg.mjs.map
|