@prisma-next/sql-contract 0.3.0-dev.13 → 0.3.0-dev.130
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README.md +84 -10
- package/dist/factories.d.mts +48 -0
- package/dist/factories.d.mts.map +1 -0
- package/dist/factories.mjs +84 -0
- package/dist/factories.mjs.map +1 -0
- package/dist/pack-types.d.mts +13 -0
- package/dist/pack-types.d.mts.map +1 -0
- package/dist/pack-types.mjs +1 -0
- package/dist/types-CB821Pqa.d.mts +197 -0
- package/dist/types-CB821Pqa.d.mts.map +1 -0
- package/dist/types-DRR5stkj.mjs +13 -0
- package/dist/types-DRR5stkj.mjs.map +1 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/dist/validate.d.mts +11 -0
- package/dist/validate.d.mts.map +1 -0
- package/dist/validate.mjs +437 -0
- package/dist/validate.mjs.map +1 -0
- package/dist/validators-CNxeypbZ.mjs +234 -0
- package/dist/validators-CNxeypbZ.mjs.map +1 -0
- package/dist/validators.d.mts +71 -0
- package/dist/validators.d.mts.map +1 -0
- package/dist/validators.mjs +3 -0
- package/package.json +21 -25
- package/src/construct.ts +181 -0
- package/src/exports/types.ts +21 -0
- package/src/exports/validate.ts +6 -0
- package/src/exports/validators.ts +1 -1
- package/src/factories.ts +41 -8
- package/src/index.ts +1 -0
- package/src/types.ts +176 -9
- package/src/validate.ts +560 -0
- package/src/validators.ts +184 -18
- package/dist/exports/factories.d.ts +0 -2
- package/dist/exports/factories.d.ts.map +0 -1
- package/dist/exports/factories.js +0 -83
- package/dist/exports/factories.js.map +0 -1
- package/dist/exports/pack-types.d.ts +0 -2
- package/dist/exports/pack-types.d.ts.map +0 -1
- package/dist/exports/pack-types.js +0 -1
- package/dist/exports/pack-types.js.map +0 -1
- package/dist/exports/types.d.ts +0 -2
- package/dist/exports/types.d.ts.map +0 -1
- package/dist/exports/types.js +0 -1
- package/dist/exports/types.js.map +0 -1
- package/dist/exports/validators.d.ts +0 -2
- package/dist/exports/validators.d.ts.map +0 -1
- package/dist/exports/validators.js +0 -96
- package/dist/exports/validators.js.map +0 -1
- package/dist/factories.d.ts +0 -38
- package/dist/factories.d.ts.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/pack-types.d.ts +0 -10
- package/dist/pack-types.d.ts.map +0 -1
- package/dist/types.d.ts +0 -68
- package/dist/types.d.ts.map +0 -1
- package/dist/validators.d.ts +0 -35
- package/dist/validators.d.ts.map +0 -1
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { ColumnDefault, ContractBase, DomainRelationOn, ExecutionHashBase, ExecutionSection, ProfileHashBase, StorageHashBase } from "@prisma-next/contract/types";
|
|
2
|
+
|
|
3
|
+
//#region src/types.d.ts
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A column definition in storage.
|
|
7
|
+
*
|
|
8
|
+
* `typeParams` is optional because most columns use non-parameterized types.
|
|
9
|
+
* Columns with parameterized types can either inline `typeParams` or reference
|
|
10
|
+
* a named {@link StorageTypeInstance} via `typeRef`.
|
|
11
|
+
*/
|
|
12
|
+
type StorageColumn = {
|
|
13
|
+
readonly nativeType: string;
|
|
14
|
+
readonly codecId: string;
|
|
15
|
+
readonly nullable: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Opaque, codec-owned JS/type parameters.
|
|
18
|
+
* The codec that owns `codecId` defines the shape and semantics.
|
|
19
|
+
* Mutually exclusive with `typeRef`.
|
|
20
|
+
*/
|
|
21
|
+
readonly typeParams?: Record<string, unknown>;
|
|
22
|
+
/**
|
|
23
|
+
* Reference to a named type instance in `storage.types`.
|
|
24
|
+
* Mutually exclusive with `typeParams`.
|
|
25
|
+
*/
|
|
26
|
+
readonly typeRef?: string;
|
|
27
|
+
/**
|
|
28
|
+
* Default value for the column.
|
|
29
|
+
* Can be a literal value or database function.
|
|
30
|
+
*/
|
|
31
|
+
readonly default?: ColumnDefault;
|
|
32
|
+
};
|
|
33
|
+
type PrimaryKey = {
|
|
34
|
+
readonly columns: readonly string[];
|
|
35
|
+
readonly name?: string;
|
|
36
|
+
};
|
|
37
|
+
type UniqueConstraint = {
|
|
38
|
+
readonly columns: readonly string[];
|
|
39
|
+
readonly name?: string;
|
|
40
|
+
};
|
|
41
|
+
type Index = {
|
|
42
|
+
readonly columns: readonly string[];
|
|
43
|
+
readonly name?: string;
|
|
44
|
+
/**
|
|
45
|
+
* Optional access method identifier.
|
|
46
|
+
* Extension-specific methods are represented as strings and interpreted
|
|
47
|
+
* by the owning extension package.
|
|
48
|
+
*/
|
|
49
|
+
readonly using?: string;
|
|
50
|
+
/**
|
|
51
|
+
* Optional extension-owned index configuration payload.
|
|
52
|
+
*/
|
|
53
|
+
readonly config?: Record<string, unknown>;
|
|
54
|
+
};
|
|
55
|
+
type ForeignKeyReferences = {
|
|
56
|
+
readonly table: string;
|
|
57
|
+
readonly columns: readonly string[];
|
|
58
|
+
};
|
|
59
|
+
type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';
|
|
60
|
+
type ForeignKeyOptions = {
|
|
61
|
+
readonly name?: string;
|
|
62
|
+
readonly onDelete?: ReferentialAction;
|
|
63
|
+
readonly onUpdate?: ReferentialAction;
|
|
64
|
+
};
|
|
65
|
+
type ForeignKey = {
|
|
66
|
+
readonly columns: readonly string[];
|
|
67
|
+
readonly references: ForeignKeyReferences;
|
|
68
|
+
readonly name?: string;
|
|
69
|
+
readonly onDelete?: ReferentialAction;
|
|
70
|
+
readonly onUpdate?: ReferentialAction;
|
|
71
|
+
/** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */
|
|
72
|
+
readonly constraint: boolean;
|
|
73
|
+
/** Whether to emit a backing index for the FK columns. */
|
|
74
|
+
readonly index: boolean;
|
|
75
|
+
};
|
|
76
|
+
type StorageTable = {
|
|
77
|
+
readonly columns: Record<string, StorageColumn>;
|
|
78
|
+
readonly primaryKey?: PrimaryKey;
|
|
79
|
+
readonly uniques: ReadonlyArray<UniqueConstraint>;
|
|
80
|
+
readonly indexes: ReadonlyArray<Index>;
|
|
81
|
+
readonly foreignKeys: ReadonlyArray<ForeignKey>;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* A named, parameterized type instance.
|
|
85
|
+
* These are registered in `storage.types` for reuse across columns
|
|
86
|
+
* and to enable ergonomic schema surfaces like `schema.types.MyType`.
|
|
87
|
+
*
|
|
88
|
+
* Unlike {@link StorageColumn}, `typeParams` is required here because
|
|
89
|
+
* `StorageTypeInstance` exists specifically to define reusable parameterized types.
|
|
90
|
+
* A type instance without parameters would be redundant—columns can reference
|
|
91
|
+
* the codec directly via `codecId`.
|
|
92
|
+
*/
|
|
93
|
+
type StorageTypeInstance = {
|
|
94
|
+
readonly codecId: string;
|
|
95
|
+
readonly nativeType: string;
|
|
96
|
+
readonly typeParams: Record<string, unknown>;
|
|
97
|
+
};
|
|
98
|
+
type SqlStorage = {
|
|
99
|
+
readonly tables: Record<string, StorageTable>;
|
|
100
|
+
/**
|
|
101
|
+
* Named type instances for parameterized/custom types.
|
|
102
|
+
* Columns can reference these via `typeRef`.
|
|
103
|
+
*/
|
|
104
|
+
readonly types?: Record<string, StorageTypeInstance>;
|
|
105
|
+
};
|
|
106
|
+
type ModelField = {
|
|
107
|
+
readonly column: string;
|
|
108
|
+
};
|
|
109
|
+
type ModelStorage = {
|
|
110
|
+
readonly table: string;
|
|
111
|
+
};
|
|
112
|
+
type ModelDefinition = {
|
|
113
|
+
readonly storage: ModelStorage;
|
|
114
|
+
readonly fields: Record<string, ModelField>;
|
|
115
|
+
readonly relations: Record<string, unknown>;
|
|
116
|
+
readonly owner?: string;
|
|
117
|
+
};
|
|
118
|
+
type SqlModelFieldStorage = {
|
|
119
|
+
readonly column: string;
|
|
120
|
+
readonly codecId?: string;
|
|
121
|
+
readonly nullable?: boolean;
|
|
122
|
+
};
|
|
123
|
+
type SqlModelStorage = {
|
|
124
|
+
readonly table: string;
|
|
125
|
+
readonly fields: Record<string, SqlModelFieldStorage>;
|
|
126
|
+
};
|
|
127
|
+
type SqlRelation = {
|
|
128
|
+
readonly to: string;
|
|
129
|
+
readonly cardinality: '1:1' | '1:N' | 'N:1';
|
|
130
|
+
readonly on: DomainRelationOn;
|
|
131
|
+
};
|
|
132
|
+
type SqlMappings = {
|
|
133
|
+
readonly modelToTable?: Record<string, string>;
|
|
134
|
+
readonly tableToModel?: Record<string, string>;
|
|
135
|
+
readonly fieldToColumn?: Record<string, Record<string, string>>;
|
|
136
|
+
readonly columnToField?: Record<string, Record<string, string>>;
|
|
137
|
+
};
|
|
138
|
+
declare const DEFAULT_FK_CONSTRAINT = true;
|
|
139
|
+
declare const DEFAULT_FK_INDEX = true;
|
|
140
|
+
declare function applyFkDefaults(fk: {
|
|
141
|
+
constraint?: boolean | undefined;
|
|
142
|
+
index?: boolean | undefined;
|
|
143
|
+
}, overrideDefaults?: {
|
|
144
|
+
constraint?: boolean | undefined;
|
|
145
|
+
index?: boolean | undefined;
|
|
146
|
+
}): {
|
|
147
|
+
constraint: boolean;
|
|
148
|
+
index: boolean;
|
|
149
|
+
};
|
|
150
|
+
type TypeMaps<TCodecTypes extends Record<string, {
|
|
151
|
+
output: unknown;
|
|
152
|
+
}> = Record<string, never>, TOperationTypes extends Record<string, unknown> = Record<string, never>, TQueryOperationTypes extends Record<string, unknown> = Record<string, never>> = {
|
|
153
|
+
readonly codecTypes: TCodecTypes;
|
|
154
|
+
readonly operationTypes: TOperationTypes;
|
|
155
|
+
readonly queryOperationTypes: TQueryOperationTypes;
|
|
156
|
+
};
|
|
157
|
+
type CodecTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
158
|
+
readonly codecTypes: infer C;
|
|
159
|
+
} ? C extends Record<string, {
|
|
160
|
+
output: unknown;
|
|
161
|
+
}> ? C : Record<string, never> : Record<string, never>;
|
|
162
|
+
type OperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
163
|
+
readonly operationTypes: infer O;
|
|
164
|
+
} ? O extends Record<string, unknown> ? O : Record<string, never> : Record<string, never>;
|
|
165
|
+
type QueryOperationTypeEntry = {
|
|
166
|
+
readonly args: readonly {
|
|
167
|
+
readonly codecId: string;
|
|
168
|
+
readonly nullable: boolean;
|
|
169
|
+
}[];
|
|
170
|
+
readonly returns: {
|
|
171
|
+
readonly codecId: string;
|
|
172
|
+
readonly nullable: boolean;
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
type SqlQueryOperationTypes<T extends Record<string, QueryOperationTypeEntry>> = T;
|
|
176
|
+
type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;
|
|
177
|
+
type QueryOperationTypesOf<T> = [T] extends [never] ? Record<string, never> : T extends {
|
|
178
|
+
readonly queryOperationTypes: infer Q;
|
|
179
|
+
} ? Q extends Record<string, unknown> ? Q : Record<string, never> : Record<string, never>;
|
|
180
|
+
type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';
|
|
181
|
+
type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & { readonly [K in TypeMapsPhantomKey]?: TTypeMaps };
|
|
182
|
+
type SqlContract<S extends SqlStorage = SqlStorage, M extends Record<string, unknown> = Record<string, unknown>, R extends Record<string, unknown> = Record<string, unknown>, Map extends SqlMappings = SqlMappings, TStorageHash extends StorageHashBase<string> = StorageHashBase<string>, TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>, TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>> = ContractBase<TStorageHash, TExecutionHash, TProfileHash, M> & {
|
|
183
|
+
readonly targetFamily: string;
|
|
184
|
+
readonly storage: S;
|
|
185
|
+
readonly relations: R;
|
|
186
|
+
readonly mappings: Map;
|
|
187
|
+
readonly execution?: ExecutionSection;
|
|
188
|
+
};
|
|
189
|
+
type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T ? NonNullable<T[TypeMapsPhantomKey & keyof T]> : never;
|
|
190
|
+
type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
191
|
+
type ExtractOperationTypes<T> = OperationTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
192
|
+
type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;
|
|
193
|
+
type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractCodecTypes<TContract> : CodecTypesOf<TTypeMaps>;
|
|
194
|
+
type ResolveOperationTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never] ? ExtractOperationTypes<TContract> : OperationTypesOf<TTypeMaps>;
|
|
195
|
+
//#endregion
|
|
196
|
+
export { SqlStorage as A, ResolveOperationTypes as C, SqlModelStorage as D, SqlModelFieldStorage as E, TypeMapsPhantomKey as F, UniqueConstraint as I, applyFkDefaults as L, StorageTable as M, StorageTypeInstance as N, SqlQueryOperationTypes as O, TypeMaps as P, ResolveCodecTypes as S, SqlMappings as T, PrimaryKey as _, ExtractCodecTypes as a, QueryOperationTypesOf as b, ExtractTypeMapsFromContract as c, ForeignKeyReferences as d, Index as f, OperationTypesOf as g, ModelStorage as h, DEFAULT_FK_INDEX as i, StorageColumn as j, SqlRelation as k, ForeignKey as l, ModelField as m, ContractWithTypeMaps as n, ExtractOperationTypes as o, ModelDefinition as p, DEFAULT_FK_CONSTRAINT as r, ExtractQueryOperationTypes as s, CodecTypesOf as t, ForeignKeyOptions as u, QueryOperationTypeEntry as v, SqlContract as w, ReferentialAction as x, QueryOperationTypesBase as y };
|
|
197
|
+
//# sourceMappingURL=types-CB821Pqa.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-CB821Pqa.d.mts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAiBA;AAsBA;AAKA;AAKA;AAeA;AAKY,KApDA,aAAA,GAoDiB;EAEjB,SAAA,UAAA,EAAiB,M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AgB,SAAA,QAAA,EAAA,OAAA;;;;;;;KAhDR,iCAAiC,eAAe,4BAA4B;KAE5E,uBAAA,GAA0B,eAAe;KAEzC,4BAA4B,qBACpC,wBACA;;cACY,8BAER,wBACF;KAEM,kBAAA;KAEA,6CAA6C,6BACxC,sBAAsB;KAG3B,sBACA,aAAa,sBACb,0BAA0B,mCAC1B,0BAA0B,qCACxB,cAAc,kCACL,0BAA0B,gDACxB,4BAA4B,gDAC9B,0BAA0B,2BAC7C,aAAa,cAAc,gBAAgB,cAAc;;oBAEzC;sBACE;qBACD;uBACE;;KAGX,iCAAiC,iCAAiC,IAC1E,YAAY,EAAE,2BAA2B;KAGjC,uBAAuB,aAAa,4BAA4B;KAChE,2BAA2B,iBAAiB,4BAA4B;KACxE,gCAAgC,sBAAsB,4BAA4B;KAElF,2CAA2C,6BACnD,kBAAkB,aAClB,aAAa;KAEL,+CAA+C,6BACvD,sBAAsB,aACtB,iBAAiB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
//#region src/types.ts
|
|
2
|
+
const DEFAULT_FK_CONSTRAINT = true;
|
|
3
|
+
const DEFAULT_FK_INDEX = true;
|
|
4
|
+
function applyFkDefaults(fk, overrideDefaults) {
|
|
5
|
+
return {
|
|
6
|
+
constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,
|
|
7
|
+
index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//#endregion
|
|
12
|
+
export { DEFAULT_FK_INDEX as n, applyFkDefaults as r, DEFAULT_FK_CONSTRAINT as t };
|
|
13
|
+
//# sourceMappingURL=types-DRR5stkj.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types-DRR5stkj.mjs","names":[],"sources":["../src/types.ts"],"sourcesContent":["import type {\n ColumnDefault,\n ContractBase,\n DomainRelationOn,\n ExecutionHashBase,\n ExecutionSection,\n ProfileHashBase,\n StorageHashBase,\n} from '@prisma-next/contract/types';\n\n/**\n * A column definition in storage.\n *\n * `typeParams` is optional because most columns use non-parameterized types.\n * Columns with parameterized types can either inline `typeParams` or reference\n * a named {@link StorageTypeInstance} via `typeRef`.\n */\nexport type StorageColumn = {\n readonly nativeType: string;\n readonly codecId: string;\n readonly nullable: boolean;\n /**\n * Opaque, codec-owned JS/type parameters.\n * The codec that owns `codecId` defines the shape and semantics.\n * Mutually exclusive with `typeRef`.\n */\n readonly typeParams?: Record<string, unknown>;\n /**\n * Reference to a named type instance in `storage.types`.\n * Mutually exclusive with `typeParams`.\n */\n readonly typeRef?: string;\n /**\n * Default value for the column.\n * Can be a literal value or database function.\n */\n readonly default?: ColumnDefault;\n};\n\nexport type PrimaryKey = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type UniqueConstraint = {\n readonly columns: readonly string[];\n readonly name?: string;\n};\n\nexport type Index = {\n readonly columns: readonly string[];\n readonly name?: string;\n /**\n * Optional access method identifier.\n * Extension-specific methods are represented as strings and interpreted\n * by the owning extension package.\n */\n readonly using?: string;\n /**\n * Optional extension-owned index configuration payload.\n */\n readonly config?: Record<string, unknown>;\n};\n\nexport type ForeignKeyReferences = {\n readonly table: string;\n readonly columns: readonly string[];\n};\n\nexport type ReferentialAction = 'noAction' | 'restrict' | 'cascade' | 'setNull' | 'setDefault';\n\nexport type ForeignKeyOptions = {\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n};\n\nexport type ForeignKey = {\n readonly columns: readonly string[];\n readonly references: ForeignKeyReferences;\n readonly name?: string;\n readonly onDelete?: ReferentialAction;\n readonly onUpdate?: ReferentialAction;\n /** Whether to emit FK constraint DDL (ALTER TABLE … ADD CONSTRAINT … FOREIGN KEY). */\n readonly constraint: boolean;\n /** Whether to emit a backing index for the FK columns. */\n readonly index: boolean;\n};\n\nexport type StorageTable = {\n readonly columns: Record<string, StorageColumn>;\n readonly primaryKey?: PrimaryKey;\n readonly uniques: ReadonlyArray<UniqueConstraint>;\n readonly indexes: ReadonlyArray<Index>;\n readonly foreignKeys: ReadonlyArray<ForeignKey>;\n};\n\n/**\n * A named, parameterized type instance.\n * These are registered in `storage.types` for reuse across columns\n * and to enable ergonomic schema surfaces like `schema.types.MyType`.\n *\n * Unlike {@link StorageColumn}, `typeParams` is required here because\n * `StorageTypeInstance` exists specifically to define reusable parameterized types.\n * A type instance without parameters would be redundant—columns can reference\n * the codec directly via `codecId`.\n */\nexport type StorageTypeInstance = {\n readonly codecId: string;\n readonly nativeType: string;\n readonly typeParams: Record<string, unknown>;\n};\n\nexport type SqlStorage = {\n readonly tables: Record<string, StorageTable>;\n /**\n * Named type instances for parameterized/custom types.\n * Columns can reference these via `typeRef`.\n */\n readonly types?: Record<string, StorageTypeInstance>;\n};\n\nexport type ModelField = {\n readonly column: string;\n};\n\nexport type ModelStorage = {\n readonly table: string;\n};\n\nexport type ModelDefinition = {\n readonly storage: ModelStorage;\n readonly fields: Record<string, ModelField>;\n readonly relations: Record<string, unknown>;\n readonly owner?: string;\n};\n\nexport type SqlModelFieldStorage = {\n readonly column: string;\n 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 type SqlRelation = {\n readonly to: string;\n readonly cardinality: '1:1' | '1:N' | 'N:1';\n readonly on: DomainRelationOn;\n};\n\nexport type SqlMappings = {\n readonly modelToTable?: Record<string, string>;\n readonly tableToModel?: Record<string, string>;\n readonly fieldToColumn?: Record<string, Record<string, string>>;\n readonly columnToField?: Record<string, Record<string, string>>;\n};\n\nexport const DEFAULT_FK_CONSTRAINT = true;\nexport const DEFAULT_FK_INDEX = true;\n\nexport function applyFkDefaults(\n fk: { constraint?: boolean | undefined; index?: boolean | undefined },\n overrideDefaults?: { constraint?: boolean | undefined; index?: boolean | undefined },\n): { constraint: boolean; index: boolean } {\n return {\n constraint: fk.constraint ?? overrideDefaults?.constraint ?? DEFAULT_FK_CONSTRAINT,\n index: fk.index ?? overrideDefaults?.index ?? DEFAULT_FK_INDEX,\n };\n}\n\nexport type TypeMaps<\n TCodecTypes extends Record<string, { output: unknown }> = Record<string, never>,\n TOperationTypes extends Record<string, unknown> = Record<string, never>,\n TQueryOperationTypes extends Record<string, unknown> = Record<string, never>,\n> = {\n readonly codecTypes: TCodecTypes;\n readonly operationTypes: TOperationTypes;\n readonly queryOperationTypes: TQueryOperationTypes;\n};\n\nexport type CodecTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly codecTypes: infer C }\n ? C extends Record<string, { output: unknown }>\n ? C\n : Record<string, never>\n : Record<string, never>;\n\nexport type OperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly operationTypes: infer O }\n ? O extends Record<string, unknown>\n ? O\n : Record<string, never>\n : Record<string, never>;\n\nexport type QueryOperationTypeEntry = {\n readonly args: readonly { readonly codecId: string; readonly nullable: boolean }[];\n readonly returns: { readonly codecId: string; readonly nullable: boolean };\n};\n\nexport type SqlQueryOperationTypes<T extends Record<string, QueryOperationTypeEntry>> = T;\n\nexport type QueryOperationTypesBase = Record<string, QueryOperationTypeEntry>;\n\nexport type QueryOperationTypesOf<T> = [T] extends [never]\n ? Record<string, never>\n : T extends { readonly queryOperationTypes: infer Q }\n ? Q extends Record<string, unknown>\n ? Q\n : Record<string, never>\n : Record<string, never>;\n\nexport type TypeMapsPhantomKey = '__@prisma-next/sql-contract/typeMaps@__';\n\nexport type ContractWithTypeMaps<TContract, TTypeMaps> = TContract & {\n readonly [K in TypeMapsPhantomKey]?: TTypeMaps;\n};\n\nexport type SqlContract<\n S extends SqlStorage = SqlStorage,\n M extends Record<string, unknown> = Record<string, unknown>,\n R extends Record<string, unknown> = Record<string, unknown>,\n Map extends SqlMappings = SqlMappings,\n TStorageHash extends StorageHashBase<string> = StorageHashBase<string>,\n TExecutionHash extends ExecutionHashBase<string> = ExecutionHashBase<string>,\n TProfileHash extends ProfileHashBase<string> = ProfileHashBase<string>,\n> = ContractBase<TStorageHash, TExecutionHash, TProfileHash, M> & {\n readonly targetFamily: string;\n readonly storage: S;\n readonly relations: R;\n readonly mappings: Map;\n readonly execution?: ExecutionSection;\n};\n\nexport type ExtractTypeMapsFromContract<T> = TypeMapsPhantomKey extends keyof T\n ? NonNullable<T[TypeMapsPhantomKey & keyof T]>\n : never;\n\nexport type ExtractCodecTypes<T> = CodecTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractOperationTypes<T> = OperationTypesOf<ExtractTypeMapsFromContract<T>>;\nexport type ExtractQueryOperationTypes<T> = QueryOperationTypesOf<ExtractTypeMapsFromContract<T>>;\n\nexport type ResolveCodecTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractCodecTypes<TContract>\n : CodecTypesOf<TTypeMaps>;\n\nexport type ResolveOperationTypes<TContract, TTypeMaps> = [TTypeMaps] extends [never]\n ? ExtractOperationTypes<TContract>\n : OperationTypesOf<TTypeMaps>;\n"],"mappings":";AAiKA,MAAa,wBAAwB;AACrC,MAAa,mBAAmB;AAEhC,SAAgB,gBACd,IACA,kBACyC;AACzC,QAAO;EACL,YAAY,GAAG,cAAc,kBAAkB,cAAc;EAC7D,OAAO,GAAG,SAAS,kBAAkB,SAAS;EAC/C"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import { A as SqlStorage, C as ResolveOperationTypes, D as SqlModelStorage, E as SqlModelFieldStorage, F as TypeMapsPhantomKey, I as UniqueConstraint, L as applyFkDefaults, M as StorageTable, N as StorageTypeInstance, O as SqlQueryOperationTypes, P as TypeMaps, S as ResolveCodecTypes, T as SqlMappings, _ as PrimaryKey, a as ExtractCodecTypes, b as QueryOperationTypesOf, c as ExtractTypeMapsFromContract, d as ForeignKeyReferences, f as Index, g as OperationTypesOf, h as ModelStorage, i as DEFAULT_FK_INDEX, j as StorageColumn, k as SqlRelation, l as ForeignKey, m as ModelField, n as ContractWithTypeMaps, o as ExtractOperationTypes, p as ModelDefinition, r as DEFAULT_FK_CONSTRAINT, s as ExtractQueryOperationTypes, t as CodecTypesOf, u as ForeignKeyOptions, v as QueryOperationTypeEntry, w as SqlContract, x as ReferentialAction, y as QueryOperationTypesBase } from "./types-CB821Pqa.mjs";
|
|
2
|
+
export { type CodecTypesOf, type ContractWithTypeMaps, DEFAULT_FK_CONSTRAINT, DEFAULT_FK_INDEX, type ExtractCodecTypes, type ExtractOperationTypes, type ExtractQueryOperationTypes, type ExtractTypeMapsFromContract, type ForeignKey, type ForeignKeyOptions, type ForeignKeyReferences, type Index, type ModelDefinition, type ModelField, type ModelStorage, type OperationTypesOf, type PrimaryKey, type QueryOperationTypeEntry, type QueryOperationTypesBase, type QueryOperationTypesOf, type ReferentialAction, type ResolveCodecTypes, type ResolveOperationTypes, type SqlContract, type SqlMappings, type SqlModelFieldStorage, type SqlModelStorage, type SqlQueryOperationTypes, type SqlRelation, type SqlStorage, type StorageColumn, type StorageTable, type StorageTypeInstance, type TypeMaps, type TypeMapsPhantomKey, type UniqueConstraint, applyFkDefaults };
|
package/dist/types.mjs
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { A as SqlStorage, j as StorageColumn, w as SqlContract } from "./types-CB821Pqa.mjs";
|
|
2
|
+
import "@prisma-next/contract/types";
|
|
3
|
+
|
|
4
|
+
//#region src/validate.d.ts
|
|
5
|
+
declare function isBigIntColumn(column: StorageColumn): boolean;
|
|
6
|
+
declare function decodeContractDefaults<T extends SqlContract<SqlStorage>>(contract: T): T;
|
|
7
|
+
declare function normalizeContract(contract: unknown): SqlContract<SqlStorage>;
|
|
8
|
+
declare function validateContract<TContract extends SqlContract<SqlStorage>>(value: unknown): TContract;
|
|
9
|
+
//#endregion
|
|
10
|
+
export { decodeContractDefaults, isBigIntColumn, normalizeContract, validateContract };
|
|
11
|
+
//# sourceMappingURL=validate.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate.d.mts","names":[],"sources":["../src/validate.ts"],"sourcesContent":[],"mappings":";;;;iBAgGgB,cAAA,SAAuB;AAAvB,iBAkCA,sBAlCuB,CAAa,UAkCH,WAlCG,CAkCS,UAlCT,CAAA,CAAA,CAAA,QAAA,EAkCgC,CAlChC,CAAA,EAkCoC,CAlCpC;AAkCpC,iBAmVA,iBAAA,CAnVsB,QAAA,EAAA,OAAA,CAAA,EAmVgB,WAnVhB,CAmV4B,UAnV5B,CAAA;AAAuB,iBA2Z7C,gBA3Z6C,CAAA,kBA2ZV,WA3ZU,CA2ZE,UA3ZF,CAAA,CAAA,CAAA,KAAA,EAAA,OAAA,CAAA,EA6Z1D,SA7Z0D"}
|