@zenstackhq/runtime 3.0.0-beta.8 → 3.0.0-beta.9

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,1545 +0,0 @@
1
- import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
2
- import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetModel, FieldDef, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, BuiltinType, IsDelegateModel, GetModelDiscriminator, GetSubModels, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, ModelDef, DataSourceProviderType, ProcedureDef } from '@zenstackhq/sdk/schema';
3
- import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, OperationNode, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
4
-
5
- type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
6
- type NullableIf<T, Condition extends boolean> = Condition extends true ? T | null : T;
7
- type _Preserve = Date | Function | Decimal | Uint8Array | JsonObject | JsonValue;
8
- type _Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
9
- type Simplify<T, D extends number = 6> = D extends 0 ? T : T extends object ? T extends _Preserve ? T : {
10
- [K in keyof T]: Simplify<T[K], _Depth[D]>;
11
- } & {} : T;
12
- type WrapType<T, Optional = false, Array = false> = Array extends true ? Optional extends true ? T[] | null : T[] : Optional extends true ? T | null : T;
13
- type TypeMap = {
14
- String: string;
15
- Boolean: boolean;
16
- Int: number;
17
- Float: number;
18
- BigInt: bigint;
19
- Decimal: Decimal;
20
- DateTime: Date;
21
- Bytes: Uint8Array;
22
- Json: JsonValue;
23
- };
24
- type MapBaseType$1<T extends string> = T extends keyof TypeMap ? TypeMap[T] : unknown;
25
- type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
26
- type JsonObject = {
27
- [key: string]: JsonValue;
28
- };
29
- type JsonArray = Array<JsonValue>;
30
- type OrArray<T, IF extends boolean = true> = IF extends true ? T | T[] : T;
31
- type NonEmptyArray<T> = [T, ...T[]];
32
- type ValueOfPotentialTuple<T> = T extends unknown[] ? T[number] : T;
33
- type NoExpand<T> = T extends unknown ? T : never;
34
- type AtLeast<O extends object, K extends string> = NoExpand<O extends unknown ? (K extends keyof O ? {
35
- [P in K]: O[P];
36
- } & O : O) | ({
37
- [P in keyof O as P extends K ? K : never]-?: O[P];
38
- } & O) : never>;
39
- type Without<T, U> = {
40
- [P in Exclude<keyof T, keyof U>]?: never;
41
- };
42
- type XOR<T, U> = T extends object ? (U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U) : T;
43
- type MaybePromise<T> = T | Promise<T>;
44
- type PrependParameter<Param, Func> = Func extends (...args: any[]) => infer R ? (p: Param, ...args: Parameters<Func>) => R : never;
45
- type OrUndefinedIf<T, Condition extends boolean> = Condition extends true ? T | undefined : T;
46
- type UnwrapTuplePromises<T extends readonly unknown[]> = {
47
- [K in keyof T]: Awaited<T[K]>;
48
- };
49
-
50
- type ToKyselySchema<Schema extends SchemaDef> = {
51
- [Model in GetModels<Schema>]: ToKyselyTable<Schema, Model>;
52
- };
53
- type ToKysely<Schema extends SchemaDef> = Kysely<ToKyselySchema<Schema>>;
54
- type ToKyselyTable<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
55
- [Field in ScalarFields<Schema, Model, false> | ForeignKeyFields<Schema, Model> as GetModelField<Schema, Model, Field>['originModel'] extends string ? never : Field]: toKyselyFieldType<Schema, Model, Field>;
56
- };
57
- type MapBaseType<T> = T extends 'String' ? string : T extends 'Boolean' ? boolean : T extends 'Int' | 'Float' ? number : T extends 'BigInt' ? bigint : T extends 'Decimal' ? Decimal : T extends 'DateTime' ? string : unknown;
58
- type WrapNull<T, Null> = Null extends true ? T | null : T;
59
- type MapType$1<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = WrapNull<MapBaseType<GetModelFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>>;
60
- type toKyselyFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = FieldHasDefault<Schema, Model, Field> extends true ? Generated<MapType$1<Schema, Model, Field>> : MapType$1<Schema, Model, Field>;
61
-
62
- type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Optional = false, Array = false> = WrapType<IsDelegateModel<Schema, Model> extends true ? DelegateUnionResult<Schema, Model, GetSubModels<Schema, Model>, Omit> : {
63
- [Key in NonRelationFields<Schema, Model> as Key extends keyof Omit ? Omit[Key] extends true ? never : Key : Key]: MapModelFieldType<Schema, Model, Key>;
64
- }, Optional, Array>;
65
- type DelegateUnionResult<Schema extends SchemaDef, Model extends GetModels<Schema>, SubModel extends GetModels<Schema>, Omit = undefined> = SubModel extends string ? DefaultModelResult<Schema, SubModel, Omit> & {
66
- [K in GetModelDiscriminator<Schema, Model>]: SubModel;
67
- } : never;
68
- type ModelSelectResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Select, Omit> = {
69
- [Key in keyof Select as Select[Key] extends false | undefined ? never : Key extends keyof Omit ? Omit[Key] extends true ? never : Key : Key extends '_count' ? Select[Key] extends SelectCount<Schema, Model> ? Key : never : Key]: Key extends '_count' ? SelectCountResult<Schema, Model, Select[Key]> : Key extends NonRelationFields<Schema, Model> ? MapModelFieldType<Schema, Model, Key> : Key extends RelationFields<Schema, Model> ? Select[Key] extends FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> ? 'select' extends keyof Select[Key] ? ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Pick<Select[Key], 'select'>, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Pick<Select[Key], 'include' | 'omit'>, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : DefaultModelResult<Schema, RelationFieldType<Schema, Model, Key>, Omit, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : never;
70
- };
71
- type SelectCountResult<Schema extends SchemaDef, Model extends GetModels<Schema>, C> = C extends true ? {
72
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: number;
73
- } : C extends {
74
- select: infer S;
75
- } ? {
76
- [Key in keyof S]: number;
77
- } : never;
78
- type ModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args extends SelectIncludeOmit<Schema, Model, boolean> = {}, Optional = false, Array = false> = WrapType<Args extends {
79
- select: infer S;
80
- omit?: infer O;
81
- } ? ModelSelectResult<Schema, Model, S, O> : Args extends {
82
- include: infer I;
83
- omit?: infer O;
84
- } ? DefaultModelResult<Schema, Model, O> & {
85
- [Key in keyof I & RelationFields<Schema, Model> as I[Key] extends false | undefined ? never : Key]: I[Key] extends FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> ? ModelResult<Schema, RelationFieldType<Schema, Model, Key>, I[Key], ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : DefaultModelResult<Schema, RelationFieldType<Schema, Model, Key>, undefined, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>>;
86
- } : Args extends {
87
- omit: infer O;
88
- } ? DefaultModelResult<Schema, Model, O> : DefaultModelResult<Schema, Model>, Optional, Array>;
89
- type SimplifiedModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args extends SelectIncludeOmit<Schema, Model, boolean> = {}, Optional = false, Array = false> = Simplify<ModelResult<Schema, Model, Args, Optional, Array>>;
90
- type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>> = Optional<{
91
- [Key in GetTypeDefFields<Schema, TypeDef>]: MapTypeDefFieldType<Schema, TypeDef, Key>;
92
- }, keyof {
93
- [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true;
94
- }>;
95
- type BatchResult = {
96
- count: number;
97
- };
98
- type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ScalarOnly extends boolean = false, WithAggregations extends boolean = false> = {
99
- [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: Key extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Key> : FieldIsArray<Schema, Model, Key> extends true ? ArrayFilter<Schema, GetModelFieldType<Schema, Model, Key>> : GetModelFieldType<Schema, Model, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>, WithAggregations> : PrimitiveFilter<Schema, GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>, WithAggregations>;
100
- } & {
101
- $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
102
- } & {
103
- AND?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
104
- OR?: WhereInput<Schema, Model, ScalarOnly>[];
105
- NOT?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
106
- };
107
- type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable extends boolean, WithAggregations extends boolean> = NullableIf<keyof GetEnum<Schema, T>, Nullable> | ({
108
- equals?: NullableIf<keyof GetEnum<Schema, T>, Nullable>;
109
- in?: (keyof GetEnum<Schema, T>)[];
110
- notIn?: (keyof GetEnum<Schema, T>)[];
111
- not?: EnumFilter<Schema, T, Nullable, WithAggregations>;
112
- } & (WithAggregations extends true ? {
113
- _count?: NumberFilter<Schema, 'Int', false, false>;
114
- _min?: EnumFilter<Schema, T, false, false>;
115
- _max?: EnumFilter<Schema, T, false, false>;
116
- } : {}));
117
- type ArrayFilter<Schema extends SchemaDef, T extends string> = {
118
- equals?: MapScalarType<Schema, T>[] | null;
119
- has?: MapScalarType<Schema, T> | null;
120
- hasEvery?: MapScalarType<Schema, T>[];
121
- hasSome?: MapScalarType<Schema, T>[];
122
- isEmpty?: boolean;
123
- };
124
- type MapScalarType<Schema extends SchemaDef, T extends string> = T extends GetEnums<Schema> ? keyof GetEnum<Schema, T> : MapBaseType$1<T>;
125
- type PrimitiveFilter<Schema extends SchemaDef, T extends string, Nullable extends boolean, WithAggregations extends boolean> = T extends 'String' ? StringFilter<Schema, Nullable, WithAggregations> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<Schema, T, Nullable, WithAggregations> : T extends 'Boolean' ? BooleanFilter<Schema, Nullable, WithAggregations> : T extends 'DateTime' ? DateTimeFilter<Schema, Nullable, WithAggregations> : T extends 'Bytes' ? BytesFilter<Schema, Nullable, WithAggregations> : T extends 'Json' ? 'Not implemented yet' : never;
126
- type CommonPrimitiveFilter<Schema extends SchemaDef, DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean> = {
127
- equals?: NullableIf<DataType, Nullable>;
128
- in?: DataType[];
129
- notIn?: DataType[];
130
- lt?: DataType;
131
- lte?: DataType;
132
- gt?: DataType;
133
- gte?: DataType;
134
- not?: PrimitiveFilter<Schema, T, Nullable, WithAggregations>;
135
- };
136
- type StringFilter<Schema extends SchemaDef, Nullable extends boolean, WithAggregations extends boolean> = NullableIf<string, Nullable> | (CommonPrimitiveFilter<Schema, string, 'String', Nullable, WithAggregations> & {
137
- contains?: string;
138
- startsWith?: string;
139
- endsWith?: string;
140
- } & (WithAggregations extends true ? {
141
- _count?: NumberFilter<Schema, 'Int', false, false>;
142
- _min?: StringFilter<Schema, false, false>;
143
- _max?: StringFilter<Schema, false, false>;
144
- } : {}) & (ProviderSupportsCaseSensitivity<Schema> extends true ? {
145
- mode?: 'default' | 'insensitive';
146
- } : {}));
147
- type NumberFilter<Schema extends SchemaDef, T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean> = NullableIf<number | bigint, Nullable> | (CommonPrimitiveFilter<Schema, number, T, Nullable, WithAggregations> & (WithAggregations extends true ? {
148
- _count?: NumberFilter<Schema, 'Int', false, false>;
149
- _avg?: NumberFilter<Schema, T, false, false>;
150
- _sum?: NumberFilter<Schema, T, false, false>;
151
- _min?: NumberFilter<Schema, T, false, false>;
152
- _max?: NumberFilter<Schema, T, false, false>;
153
- } : {}));
154
- type DateTimeFilter<Schema extends SchemaDef, Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Date | string, Nullable> | (CommonPrimitiveFilter<Schema, Date | string, 'DateTime', Nullable, WithAggregations> & (WithAggregations extends true ? {
155
- _count?: NumberFilter<Schema, 'Int', false, false>;
156
- _min?: DateTimeFilter<Schema, false, false>;
157
- _max?: DateTimeFilter<Schema, false, false>;
158
- } : {}));
159
- type BytesFilter<Schema extends SchemaDef, Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Uint8Array | Buffer, Nullable> | ({
160
- equals?: NullableIf<Uint8Array, Nullable>;
161
- in?: Uint8Array[];
162
- notIn?: Uint8Array[];
163
- not?: BytesFilter<Schema, Nullable, WithAggregations>;
164
- } & (WithAggregations extends true ? {
165
- _count?: NumberFilter<Schema, 'Int', false, false>;
166
- _min?: BytesFilter<Schema, false, false>;
167
- _max?: BytesFilter<Schema, false, false>;
168
- } : {}));
169
- type BooleanFilter<Schema extends SchemaDef, Nullable extends boolean, WithAggregations extends boolean> = NullableIf<boolean, Nullable> | ({
170
- equals?: NullableIf<boolean, Nullable>;
171
- not?: BooleanFilter<Schema, Nullable, WithAggregations>;
172
- } & (WithAggregations extends true ? {
173
- _count?: NumberFilter<Schema, 'Int', false, false>;
174
- _min?: BooleanFilter<Schema, false, false>;
175
- _max?: BooleanFilter<Schema, false, false>;
176
- } : {}));
177
- type SortOrder = 'asc' | 'desc';
178
- type NullsOrder = 'first' | 'last';
179
- type OrderBy<Schema extends SchemaDef, Model extends GetModels<Schema>, WithRelation extends boolean, WithAggregation extends boolean> = {
180
- [Key in NonRelationFields<Schema, Model>]?: ModelFieldIsOptional<Schema, Model, Key> extends true ? SortOrder | {
181
- sort: SortOrder;
182
- nulls?: NullsOrder;
183
- } : SortOrder;
184
- } & (WithRelation extends true ? {
185
- [Key in RelationFields<Schema, Model>]?: FieldIsArray<Schema, Model, Key> extends true ? {
186
- _count?: SortOrder;
187
- } : OrderBy<Schema, RelationFieldType<Schema, Model, Key>, WithRelation, WithAggregation>;
188
- } : {}) & (WithAggregation extends true ? {
189
- _count?: OrderBy<Schema, Model, false, false>;
190
- _min?: MinMaxInput<Schema, Model, SortOrder>;
191
- _max?: MinMaxInput<Schema, Model, SortOrder>;
192
- } & (NumericFields<Schema, Model> extends never ? {} : {
193
- _avg?: SumAvgInput<Schema, Model, SortOrder>;
194
- _sum?: SumAvgInput<Schema, Model, SortOrder>;
195
- }) : {});
196
- type WhereUniqueInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = AtLeast<{
197
- [Key in keyof GetModel<Schema, Model>['uniqueFields']]?: GetModel<Schema, Model>['uniqueFields'][Key] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key]> : {
198
- [Key1 in keyof GetModel<Schema, Model>['uniqueFields'][Key]]: GetModel<Schema, Model>['uniqueFields'][Key][Key1] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key][Key1]> : never;
199
- };
200
- } & WhereInput<Schema, Model>, Extract<keyof GetModel<Schema, Model>['uniqueFields'], string>>;
201
- type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
202
- [Key in NonRelationFields<Schema, Model>]?: boolean;
203
- };
204
- type SelectIncludeOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean> = {
205
- select?: SelectInput<Schema, Model, AllowCount, boolean>;
206
- include?: IncludeInput<Schema, Model, AllowCount>;
207
- omit?: OmitInput<Schema, Model>;
208
- };
209
- type SelectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true, AllowRelation extends boolean = true> = {
210
- [Key in NonRelationFields<Schema, Model>]?: boolean;
211
- } & (AllowRelation extends true ? IncludeInput<Schema, Model, AllowCount> : {});
212
- type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = boolean | {
213
- select: {
214
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]?: boolean | {
215
- where: WhereInput<Schema, RelationFieldType<Schema, Model, Key>, false>;
216
- };
217
- };
218
- };
219
- type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true> = {
220
- [Key in RelationFields<Schema, Model>]?: boolean | FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, FieldIsArray<Schema, Model, Key> extends true ? true : ModelFieldIsOptional<Schema, Model, Key> extends true ? true : false>;
221
- } & (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
222
- _count?: SelectCount<Schema, Model>;
223
- } : {} : {});
224
- type Subset<T, U> = {
225
- [key in keyof T]: key extends keyof U ? T[key] : never;
226
- };
227
- type SelectSubset<T, U> = {
228
- [key in keyof T]: key extends keyof U ? T[key] : never;
229
- } & (T extends {
230
- select: any;
231
- include: any;
232
- } ? 'Please either choose `select` or `include`.' : T extends {
233
- select: any;
234
- omit: any;
235
- } ? 'Please either choose `select` or `omit`.' : {});
236
- type ToManyRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = {
237
- every?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
238
- some?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
239
- none?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
240
- };
241
- type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>> & {
242
- is?: NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>>;
243
- isNot?: NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>>;
244
- }, ModelFieldIsOptional<Schema, Model, Field>>;
245
- type RelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationFilter<Schema, Model, Field> : ToOneRelationFilter<Schema, Model, Field>;
246
- type MapModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = MapFieldDefType<Schema, GetModelField<Schema, Model, Field>>;
247
- type MapTypeDefFieldType<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Field extends GetTypeDefFields<Schema, TypeDef>> = MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Field>>;
248
- type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'>> = WrapType<T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T['type']> & Record<string, unknown> : MapBaseType$1<T['type']>, T['optional'], T['array']>;
249
- type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
250
- [Key in GetModelFields<Schema, Model> as ModelFieldIsOptional<Schema, Model, Key> extends true ? Key : FieldHasDefault<Schema, Model, Key> extends true ? Key : FieldIsArray<Schema, Model, Key> extends true ? Key : GetModelField<Schema, Model, Key>['updatedAt'] extends true ? Key : never]: GetModelField<Schema, Model, Key>;
251
- };
252
- type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'];
253
- type OppositeRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>> = FT extends GetModels<Schema> ? GetRelation<Schema, Model, Field> extends RelationInfo ? GetRelation<Schema, Model, Field>['opposite'] extends GetModelFields<Schema, FT> ? Schema['models'][FT]['fields'][GetRelation<Schema, Model, Field>['opposite']]['relation'] : never : never : never;
254
- type OppositeRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Opposite = OppositeRelation<Schema, Model, Field>> = Opposite extends RelationInfo ? (Opposite['fields'] extends string[] ? Opposite['fields'] : []) : [];
255
- type OppositeRelationAndFK<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>, Relation = GetModelField<Schema, Model, Field>['relation'], Opposite = Relation extends RelationInfo ? Relation['opposite'] : never> = FT extends GetModels<Schema> ? Opposite extends GetModelFields<Schema, FT> ? Opposite | OppositeRelationFields<Schema, Model, Field>[number] : never : never;
256
- type FilterArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
257
- where?: WhereInput<Schema, Model>;
258
- };
259
- type SortAndTakeArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
260
- skip?: number;
261
- take?: number;
262
- orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
263
- cursor?: WhereUniqueInput<Schema, Model>;
264
- };
265
- type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Collection extends boolean, AllowFilter extends boolean = true> = ProviderSupportsDistinct<Schema> extends true ? (Collection extends true ? SortAndTakeArgs<Schema, Model> & {
266
- distinct?: OrArray<NonRelationFields<Schema, Model>>;
267
- } : {}) & (AllowFilter extends true ? FilterArgs<Schema, Model> : {}) & SelectIncludeOmit<Schema, Model, Collection> : (Collection extends true ? SortAndTakeArgs<Schema, Model> : {}) & (AllowFilter extends true ? FilterArgs<Schema, Model> : {}) & SelectIncludeOmit<Schema, Model, Collection>;
268
- type FindManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
269
- type FindFirstArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, false>;
270
- type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
271
- where?: WhereUniqueInput<Schema, Model>;
272
- } & SelectIncludeOmit<Schema, Model, true>;
273
- type CreateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
274
- data: CreateInput<Schema, Model>;
275
- select?: SelectInput<Schema, Model>;
276
- include?: IncludeInput<Schema, Model>;
277
- omit?: OmitInput<Schema, Model>;
278
- };
279
- type CreateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyInput<Schema, Model>;
280
- type CreateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyInput<Schema, Model> & {
281
- select?: SelectInput<Schema, Model, false, false>;
282
- omit?: OmitInput<Schema, Model>;
283
- };
284
- type OptionalWrap<Schema extends SchemaDef, Model extends GetModels<Schema>, T extends object> = Optional<T, keyof T & OptionalFieldsForCreate<Schema, Model>>;
285
- type CreateScalarPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
286
- [Key in ScalarFields<Schema, Model, false> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? never : Key]: ScalarCreatePayload<Schema, Model, Key>;
287
- }>;
288
- type ScalarCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends ScalarFields<Schema, Model, false>> = MapModelFieldType<Schema, Model, Field> | (FieldIsArray<Schema, Model, Field> extends true ? {
289
- set?: MapModelFieldType<Schema, Model, Field>;
290
- } : never);
291
- type CreateFKPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
292
- [Key in ForeignKeyFields<Schema, Model>]: MapModelFieldType<Schema, Model, Key>;
293
- }>;
294
- type CreateRelationFieldPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = Omit<{
295
- connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field>;
296
- create?: NestedCreateInput<Schema, Model, Field>;
297
- createMany?: NestedCreateManyInput<Schema, Model, Field>;
298
- connect?: ConnectInput<Schema, Model, Field>;
299
- }, (FieldIsArray<Schema, Model, Field> extends true ? never : 'createMany') | (FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'createMany' | 'connectOrCreate' : never)>;
300
- type CreateRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
301
- [Key in RelationFields<Schema, Model>]: CreateRelationFieldPayload<Schema, Model, Key>;
302
- }>;
303
- type CreateWithFKInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateScalarPayload<Schema, Model> & CreateFKPayload<Schema, Model> & CreateWithNonOwnedRelationPayload<Schema, Model>;
304
- type CreateWithRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateScalarPayload<Schema, Model> & CreateRelationPayload<Schema, Model>;
305
- type CreateWithNonOwnedRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
306
- [Key in NonOwnedRelationFields<Schema, Model>]: CreateRelationFieldPayload<Schema, Model, Key>;
307
- }>;
308
- type ConnectOrCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
309
- where: WhereUniqueInput<Schema, Model>;
310
- create: CreateInput<Schema, Model, Without>;
311
- };
312
- type CreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
313
- data: OrArray<Omit<CreateScalarPayload<Schema, Model>, Without> & Omit<CreateFKPayload<Schema, Model>, Without>>;
314
- skipDuplicates?: boolean;
315
- };
316
- type CreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = XOR<Omit<CreateWithFKInput<Schema, Model>, Without>, Omit<CreateWithRelationInput<Schema, Model>, Without>>;
317
- type NestedCreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<CreateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>, FieldIsArray<Schema, Model, Field>>;
318
- type NestedCreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = CreateManyInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
319
- type UpdateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
320
- data: UpdateInput<Schema, Model>;
321
- where: WhereUniqueInput<Schema, Model>;
322
- select?: SelectInput<Schema, Model>;
323
- include?: IncludeInput<Schema, Model>;
324
- omit?: OmitInput<Schema, Model>;
325
- };
326
- type UpdateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = UpdateManyPayload<Schema, Model>;
327
- type UpdateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = UpdateManyPayload<Schema, Model> & {
328
- select?: SelectInput<Schema, Model, false, false>;
329
- omit?: OmitInput<Schema, Model>;
330
- };
331
- type UpdateManyPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
332
- data: OrArray<UpdateScalarInput<Schema, Model, Without>>;
333
- where?: WhereInput<Schema, Model>;
334
- limit?: number;
335
- };
336
- type UpsertArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
337
- create: CreateInput<Schema, Model>;
338
- update: UpdateInput<Schema, Model>;
339
- where: WhereUniqueInput<Schema, Model>;
340
- select?: SelectInput<Schema, Model>;
341
- include?: IncludeInput<Schema, Model>;
342
- omit?: OmitInput<Schema, Model>;
343
- };
344
- type UpdateScalarInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = Omit<{
345
- [Key in NonRelationFields<Schema, Model> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? never : Key]?: ScalarUpdatePayload<Schema, Model, Key>;
346
- }, Without>;
347
- type ScalarUpdatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends NonRelationFields<Schema, Model>> = MapModelFieldType<Schema, Model, Field> | (Field extends NumericFields<Schema, Model> ? {
348
- set?: NullableIf<number, ModelFieldIsOptional<Schema, Model, Field>>;
349
- increment?: number;
350
- decrement?: number;
351
- multiply?: number;
352
- divide?: number;
353
- } : never) | (FieldIsArray<Schema, Model, Field> extends true ? {
354
- set?: MapModelFieldType<Schema, Model, Field>[];
355
- push?: OrArray<MapModelFieldType<Schema, Model, Field>, true>;
356
- } : never);
357
- type UpdateRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = Omit<{
358
- [Key in RelationFields<Schema, Model>]?: UpdateRelationFieldPayload<Schema, Model, Key>;
359
- }, Without>;
360
- type UpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = UpdateScalarInput<Schema, Model, Without> & UpdateRelationInput<Schema, Model, Without>;
361
- type UpdateRelationFieldPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationUpdateInput<Schema, Model, Field> : ToOneRelationUpdateInput<Schema, Model, Field>;
362
- type ToManyRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = Omit<{
363
- create?: NestedCreateInput<Schema, Model, Field>;
364
- createMany?: NestedCreateManyInput<Schema, Model, Field>;
365
- connect?: ConnectInput<Schema, Model, Field>;
366
- connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field>;
367
- disconnect?: DisconnectInput<Schema, Model, Field>;
368
- update?: NestedUpdateInput<Schema, Model, Field>;
369
- upsert?: NestedUpsertInput<Schema, Model, Field>;
370
- updateMany?: NestedUpdateManyInput<Schema, Model, Field>;
371
- delete?: NestedDeleteInput<Schema, Model, Field>;
372
- deleteMany?: NestedDeleteManyInput<Schema, Model, Field>;
373
- set?: SetRelationInput<Schema, Model, Field>;
374
- }, FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'createMany' | 'connectOrCreate' | 'upsert' : never>;
375
- type ToOneRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = Omit<{
376
- create?: NestedCreateInput<Schema, Model, Field>;
377
- connect?: ConnectInput<Schema, Model, Field>;
378
- connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field>;
379
- update?: NestedUpdateInput<Schema, Model, Field>;
380
- upsert?: NestedUpsertInput<Schema, Model, Field>;
381
- } & (ModelFieldIsOptional<Schema, Model, Field> extends true ? {
382
- disconnect?: DisconnectInput<Schema, Model, Field>;
383
- delete?: NestedDeleteInput<Schema, Model, Field>;
384
- } : {}), FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'connectOrCreate' | 'upsert' : never>;
385
- type DeleteArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
386
- where: WhereUniqueInput<Schema, Model>;
387
- select?: SelectInput<Schema, Model>;
388
- include?: IncludeInput<Schema, Model>;
389
- omit?: OmitInput<Schema, Model>;
390
- };
391
- type DeleteManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
392
- where?: WhereInput<Schema, Model>;
393
- limit?: number;
394
- };
395
- type CountArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<FindArgs<Schema, Model, true>, 'select' | 'include' | 'distinct' | 'omit'> & {
396
- select?: CountAggregateInput<Schema, Model> | true;
397
- };
398
- type CountAggregateInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
399
- [Key in NonRelationFields<Schema, Model>]?: true;
400
- } & {
401
- _all?: true;
402
- };
403
- type CountResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args extends CountArgs<Schema, Model>> = Args extends {
404
- select: infer S;
405
- } ? S extends true ? number : {
406
- [Key in keyof S]: number;
407
- } : number;
408
- type AggregateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
409
- where?: WhereInput<Schema, Model>;
410
- skip?: number;
411
- take?: number;
412
- orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
413
- } & {
414
- _count?: true | CountAggregateInput<Schema, Model>;
415
- _min?: MinMaxInput<Schema, Model, true>;
416
- _max?: MinMaxInput<Schema, Model, true>;
417
- } & (NumericFields<Schema, Model> extends never ? {} : {
418
- _avg?: SumAvgInput<Schema, Model, true>;
419
- _sum?: SumAvgInput<Schema, Model, true>;
420
- });
421
- type NumericFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
422
- [Key in GetModelFields<Schema, Model> as GetModelFieldType<Schema, Model, Key> extends 'Int' | 'Float' | 'BigInt' | 'Decimal' ? FieldIsArray<Schema, Model, Key> extends true ? never : Key : never]: GetModelField<Schema, Model, Key>;
423
- };
424
- type SumAvgInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ValueType> = {
425
- [Key in NumericFields<Schema, Model>]?: ValueType;
426
- };
427
- type MinMaxInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ValueType> = {
428
- [Key in GetModelFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? never : FieldIsRelation<Schema, Model, Key> extends true ? never : Key]?: ValueType;
429
- };
430
- type AggregateResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args extends AggregateArgs<Schema, Model>> = (Args extends {
431
- _count: infer Count;
432
- } ? {
433
- _count: AggCommonOutput<Count>;
434
- } : {}) & (Args extends {
435
- _sum: infer Sum;
436
- } ? {
437
- _sum: AggCommonOutput<Sum>;
438
- } : {}) & (Args extends {
439
- _avg: infer Avg;
440
- } ? {
441
- _avg: AggCommonOutput<Avg>;
442
- } : {}) & (Args extends {
443
- _min: infer Min;
444
- } ? {
445
- _min: AggCommonOutput<Min>;
446
- } : {}) & (Args extends {
447
- _max: infer Max;
448
- } ? {
449
- _max: AggCommonOutput<Max>;
450
- } : {});
451
- type AggCommonOutput<Input> = Input extends true ? number : Input extends {} ? {
452
- [Key in keyof Input]: number;
453
- } : never;
454
- type GroupByHaving<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<WhereInput<Schema, Model, true, true>, '$expr'>;
455
- type GroupByArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
456
- where?: WhereInput<Schema, Model>;
457
- orderBy?: OrArray<OrderBy<Schema, Model, false, true>>;
458
- by: NonRelationFields<Schema, Model> | NonEmptyArray<NonRelationFields<Schema, Model>>;
459
- having?: GroupByHaving<Schema, Model>;
460
- take?: number;
461
- skip?: number;
462
- _count?: true | CountAggregateInput<Schema, Model>;
463
- _min?: MinMaxInput<Schema, Model, true>;
464
- _max?: MinMaxInput<Schema, Model, true>;
465
- } & (NumericFields<Schema, Model> extends never ? {} : {
466
- _avg?: SumAvgInput<Schema, Model, true>;
467
- _sum?: SumAvgInput<Schema, Model, true>;
468
- });
469
- type GroupByResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args extends GroupByArgs<Schema, Model>> = Array<{
470
- [Key in NonRelationFields<Schema, Model> as Key extends ValueOfPotentialTuple<Args['by']> ? Key : never]: MapModelFieldType<Schema, Model, Key>;
471
- } & (Args extends {
472
- _count: infer Count;
473
- } ? {
474
- _count: AggCommonOutput<Count>;
475
- } : {}) & (Args extends {
476
- _avg: infer Avg;
477
- } ? {
478
- _avg: AggCommonOutput<Avg>;
479
- } : {}) & (Args extends {
480
- _sum: infer Sum;
481
- } ? {
482
- _sum: AggCommonOutput<Sum>;
483
- } : {}) & (Args extends {
484
- _min: infer Min;
485
- } ? {
486
- _min: AggCommonOutput<Min>;
487
- } : {}) & (Args extends {
488
- _max: infer Max;
489
- } ? {
490
- _max: AggCommonOutput<Max>;
491
- } : {})>;
492
- type ConnectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>> : WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
493
- type ConnectOrCreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<ConnectOrCreatePayload<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>> : ConnectOrCreatePayload<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
494
- type DisconnectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>, true> : boolean | WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
495
- type SetRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>>;
496
- type NestedUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<{
497
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
498
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
499
- }, true> : XOR<{
500
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
501
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
502
- }, UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>>;
503
- type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<{
504
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
505
- create: CreateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
506
- update: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
507
- }, FieldIsArray<Schema, Model, Field>>;
508
- type NestedUpdateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<UpdateManyPayload<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>>;
509
- type NestedDeleteInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>, true> : boolean | WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
510
- type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, true>>;
511
- type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
512
- [Key in RelationFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends {
513
- references: unknown[];
514
- } ? never : Key]: true;
515
- };
516
- type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
517
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
518
- } extends never ? false : true;
519
- type ProviderSupportsCaseSensitivity<Schema extends SchemaDef> = Schema['provider']['type'] extends 'postgresql' ? true : false;
520
- type ProviderSupportsDistinct<Schema extends SchemaDef> = Schema['provider']['type'] extends 'postgresql' ? true : false;
521
-
522
- type AuthType<Schema extends SchemaDef> = string extends GetModels<Schema> ? Record<string, unknown> : Schema['authType'] extends GetModels<Schema> ? Partial<ModelResult<Schema, Schema['authType']>> : never;
523
-
524
- /**
525
- * Client API methods that are not supported in transactions.
526
- */
527
- declare const TRANSACTION_UNSUPPORTED_METHODS: readonly ["$transaction", "$disconnect", "$use"];
528
- /**
529
- * Logical combinators used in filters.
530
- */
531
- declare const LOGICAL_COMBINATORS: readonly ["AND", "OR", "NOT"];
532
-
533
- declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
534
- protected readonly schema: Schema;
535
- protected readonly options: ClientOptions<Schema>;
536
- constructor(schema: Schema, options: ClientOptions<Schema>);
537
- transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
538
- transformOutput(value: unknown, _type: BuiltinType): unknown;
539
- buildSelectModel(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
540
- buildFilterSortTake(model: GetModels<Schema>, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
541
- buildFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
542
- private buildCursorFilter;
543
- private isLogicalCombinator;
544
- protected buildCompositeFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, key: (typeof LOGICAL_COMBINATORS)[number], payload: any): Expression<SqlBool>;
545
- private buildRelationFilter;
546
- private buildToOneRelationFilter;
547
- private buildToManyRelationFilter;
548
- private buildArrayFilter;
549
- buildPrimitiveFilter(eb: ExpressionBuilder<any, any>, fieldRef: Expression<any>, fieldDef: FieldDef, payload: any): Expression<SqlBool>;
550
- private buildLiteralFilter;
551
- private buildStandardFilter;
552
- private buildStringFilter;
553
- private prepStringCasing;
554
- private buildNumberFilter;
555
- private buildBooleanFilter;
556
- private buildDateTimeFilter;
557
- private buildBytesFilter;
558
- private buildEnumFilter;
559
- buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, useDefaultIfEmpty: boolean, negated: boolean): SelectQueryBuilder<any, any, any>;
560
- buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined, modelAlias: string): SelectQueryBuilder<any, any, any>;
561
- protected buildModelSelect(eb: ExpressionBuilder<any, any>, model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
562
- buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
563
- buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
564
- buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): ExpressionWrapper<any, any, unknown>;
565
- private negateSort;
566
- true(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
567
- false(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
568
- isTrue(expression: Expression<SqlBool>): boolean;
569
- isFalse(expression: Expression<SqlBool>): boolean;
570
- and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
571
- or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
572
- not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
573
- fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string, inlineComputedField?: boolean): ExpressionWrapper<any, any, unknown>;
574
- protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
575
- abstract get provider(): DataSourceProviderType;
576
- /**
577
- * Builds selection for a relation field.
578
- */
579
- abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>): SelectQueryBuilder<any, any, any>;
580
- /**
581
- * Builds skip and take clauses.
582
- */
583
- abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
584
- /**
585
- * Builds an Kysely expression that returns a JSON object for the given key-value pairs.
586
- */
587
- abstract buildJsonObject(eb: ExpressionBuilder<any, any>, value: Record<string, Expression<unknown>>): ExpressionWrapper<any, any, unknown>;
588
- /**
589
- * Builds an Kysely expression that returns the length of an array.
590
- */
591
- abstract buildArrayLength(eb: ExpressionBuilder<any, any>, array: Expression<unknown>): ExpressionWrapper<any, any, number>;
592
- /**
593
- * Builds an array literal SQL string for the given values.
594
- */
595
- abstract buildArrayLiteralSQL(values: unknown[]): string;
596
- /**
597
- * Whether the dialect supports updating with a limit on the number of updated rows.
598
- */
599
- abstract get supportsUpdateWithLimit(): boolean;
600
- /**
601
- * Whether the dialect supports deleting with a limit on the number of deleted rows.
602
- */
603
- abstract get supportsDeleteWithLimit(): boolean;
604
- /**
605
- * Whether the dialect supports DISTINCT ON.
606
- */
607
- abstract get supportsDistinctOn(): boolean;
608
- /**
609
- * Whether the dialect support inserting with `DEFAULT` as field value.
610
- */
611
- abstract get supportInsertWithDefault(): boolean;
612
- /**
613
- * Gets the SQL column type for the given field definition.
614
- */
615
- abstract getFieldSqlType(fieldDef: FieldDef): string;
616
- abstract getStringCasingBehavior(): {
617
- supportsILike: boolean;
618
- likeCaseSensitive: boolean;
619
- };
620
- }
621
-
622
- type CoreCrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
623
- type AllCrudOperation = CoreCrudOperation | 'findUniqueOrThrow' | 'findFirstOrThrow';
624
-
625
- /**
626
- * ZenStack runtime plugin.
627
- */
628
- interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
629
- /**
630
- * Plugin ID.
631
- */
632
- id: string;
633
- /**
634
- * Plugin display name.
635
- */
636
- name?: string;
637
- /**
638
- * Plugin description.
639
- */
640
- description?: string;
641
- /**
642
- * Custom function implementations.
643
- */
644
- functions?: Record<string, ZModelFunction<Schema>>;
645
- /**
646
- * Intercepts an ORM query.
647
- */
648
- onQuery?: OnQueryCallback<Schema>;
649
- /**
650
- * Intercepts an entity mutation.
651
- */
652
- onEntityMutation?: EntityMutationHooksDef<Schema>;
653
- /**
654
- * Intercepts a Kysely query.
655
- */
656
- onKyselyQuery?: OnKyselyQueryCallback<Schema>;
657
- }
658
- /**
659
- * Defines a ZenStack runtime plugin.
660
- */
661
- declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
662
-
663
- type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
664
- type OnQueryHookContext<Schema extends SchemaDef> = {
665
- /**
666
- * The model that is being queried.
667
- */
668
- model: GetModels<Schema>;
669
- /**
670
- * The operation that is being performed.
671
- */
672
- operation: AllCrudOperation;
673
- /**
674
- * The query arguments.
675
- */
676
- args: unknown;
677
- /**
678
- * The function to proceed with the original query.
679
- * It takes the same arguments as the operation method.
680
- *
681
- * @param args The query arguments.
682
- */
683
- proceed: (args: unknown) => Promise<unknown>;
684
- /**
685
- * The ZenStack client that is performing the operation.
686
- */
687
- client: ClientContract<Schema>;
688
- };
689
- type EntityMutationHooksDef<Schema extends SchemaDef> = {
690
- /**
691
- * Called before entities are mutated.
692
- */
693
- beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
694
- /**
695
- * Called after entities are mutated.
696
- */
697
- afterEntityMutation?: AfterEntityMutationCallback<Schema>;
698
- /**
699
- * Whether to run after-mutation hooks within the transaction that performs the mutation.
700
- *
701
- * If set to `true`, if the mutation already runs inside a transaction, the callbacks are
702
- * executed immediately after the mutation within the transaction boundary. If the mutation
703
- * is not running inside a transaction, a new transaction is created to run both the mutation
704
- * and the callbacks.
705
- *
706
- * If set to `false`, the callbacks are executed after the mutation transaction is committed.
707
- *
708
- * Defaults to `false`.
709
- */
710
- runAfterMutationWithinTransaction?: boolean;
711
- };
712
- type MutationHooksArgs<Schema extends SchemaDef> = {
713
- /**
714
- * The model that is being mutated.
715
- */
716
- model: GetModels<Schema>;
717
- /**
718
- * The mutation action that is being performed.
719
- */
720
- action: 'create' | 'update' | 'delete';
721
- /**
722
- * The mutation data. Only available for create and update actions.
723
- */
724
- queryNode: OperationNode;
725
- /**
726
- * A query ID that uniquely identifies the mutation operation. You can use it to correlate
727
- * data between the before and after mutation hooks.
728
- */
729
- queryId: string;
730
- };
731
- type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
732
- type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
733
- type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
734
- /**
735
- * Loads the entities that are about to be mutated. The db operation that loads the entities is executed
736
- * within the same transaction context as the mutation.
737
- */
738
- loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
739
- /**
740
- * The ZenStack client you can use to perform additional operations. The database operations initiated
741
- * from this client are executed within the same transaction as the mutation if the mutation is running
742
- * inside a transaction.
743
- *
744
- * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
745
- */
746
- client: ClientContract<Schema>;
747
- };
748
- type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
749
- /**
750
- * Loads the entities that have been mutated.
751
- */
752
- loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
753
- /**
754
- * The ZenStack client you can use to perform additional operations.
755
- * See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
756
- *
757
- * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
758
- */
759
- client: ClientContract<Schema>;
760
- };
761
- type OnKyselyQueryArgs<Schema extends SchemaDef> = {
762
- schema: SchemaDef;
763
- client: ClientContract<Schema>;
764
- query: RootOperationNode;
765
- proceed: ProceedKyselyQueryFunction;
766
- };
767
- type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
768
- type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
769
-
770
- type ZModelFunctionContext<Schema extends SchemaDef> = {
771
- /**
772
- * ZenStack client instance
773
- */
774
- client: ClientContract<Schema>;
775
- /**
776
- * Database dialect
777
- */
778
- dialect: BaseCrudDialect<Schema>;
779
- /**
780
- * The containing model name
781
- */
782
- model: GetModels<Schema>;
783
- /**
784
- * The alias name that can be used to refer to the containing model
785
- */
786
- modelAlias: string;
787
- /**
788
- * The CRUD operation being performed
789
- */
790
- operation: CRUD_EXT;
791
- };
792
- type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
793
- /**
794
- * ZenStack client options.
795
- */
796
- type ClientOptions<Schema extends SchemaDef> = {
797
- /**
798
- * Kysely dialect.
799
- */
800
- dialect: Dialect;
801
- /**
802
- * Custom function definitions.
803
- */
804
- functions?: Record<string, ZModelFunction<Schema>>;
805
- /**
806
- * Plugins.
807
- */
808
- plugins?: RuntimePlugin<Schema>[];
809
- /**
810
- * Logging configuration.
811
- */
812
- log?: KyselyConfig['log'];
813
- /**
814
- * Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
815
- * to `true`.
816
- *
817
- * Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
818
- * `Date` object) although for `DateTime` field the data in DB is stored in UTC.
819
- * @see https://github.com/brianc/node-postgres/issues/429
820
- */
821
- fixPostgresTimezone?: boolean;
822
- } & (HasComputedFields<Schema> extends true ? {
823
- /**
824
- * Computed field definitions.
825
- */
826
- computedFields: ComputedFieldsOptions<Schema>;
827
- } : {}) & (HasProcedures<Schema> extends true ? {
828
- /**
829
- * Custom procedure definitions.
830
- */
831
- procedures: ProceduresOptions<Schema>;
832
- } : {});
833
- type ComputedFieldsOptions<Schema extends SchemaDef> = {
834
- [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
835
- [Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
836
- };
837
- };
838
- type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
839
- type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
840
- procedures: Record<string, ProcedureDef>;
841
- } ? {
842
- [Key in keyof Schema['procedures']]: PrependParameter<ClientContract<Schema>, ProcedureFunc<Schema, Schema['procedures'][Key]>>;
843
- } : {};
844
- type HasProcedures<Schema extends SchemaDef> = Schema extends {
845
- procedures: Record<string, ProcedureDef>;
846
- } ? true : false;
847
-
848
- /**
849
- * A promise that only executes when it's awaited or .then() is called.
850
- */
851
- type ZenStackPromise<Schema extends SchemaDef, T> = Promise<T> & {
852
- /**
853
- * @private
854
- * Callable to get a plain promise.
855
- */
856
- cb: (txClient?: ClientContract<Schema>) => Promise<T>;
857
- };
858
-
859
- type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[number];
860
- /**
861
- * Transaction isolation levels.
862
- */
863
- declare enum TransactionIsolationLevel {
864
- ReadUncommitted = "read uncommitted",
865
- ReadCommitted = "read committed",
866
- RepeatableRead = "repeatable read",
867
- Serializable = "serializable",
868
- Snapshot = "snapshot"
869
- }
870
- /**
871
- * ZenStack client interface.
872
- */
873
- type ClientContract<Schema extends SchemaDef> = {
874
- readonly $schema: Schema;
875
- /**
876
- * The client options.
877
- */
878
- readonly $options: ClientOptions<Schema>;
879
- /**
880
- * Executes a prepared raw query and returns the number of affected rows.
881
- * @example
882
- * ```
883
- * const result = await db.$executeRaw`UPDATE User SET cool = ${true} WHERE email = ${'user@email.com'};`
884
- * ```
885
- */
886
- $executeRaw(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, number>;
887
- /**
888
- * Executes a raw query and returns the number of affected rows.
889
- * This method is susceptible to SQL injections.
890
- * @example
891
- * ```
892
- * const result = await db.$executeRawUnsafe('UPDATE User SET cool = $1 WHERE email = $2 ;', true, 'user@email.com')
893
- * ```
894
- */
895
- $executeRawUnsafe(query: string, ...values: any[]): ZenStackPromise<Schema, number>;
896
- /**
897
- * Performs a prepared raw query and returns the `SELECT` data.
898
- * @example
899
- * ```
900
- * const result = await db.$queryRaw`SELECT * FROM User WHERE id = ${1} OR email = ${'user@email.com'};`
901
- * ```
902
- */
903
- $queryRaw<T = unknown>(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, T>;
904
- /**
905
- * Performs a raw query and returns the `SELECT` data.
906
- * This method is susceptible to SQL injections.
907
- * @example
908
- * ```
909
- * const result = await db.$queryRawUnsafe('SELECT * FROM User WHERE id = $1 OR email = $2;', 1, 'user@email.com')
910
- * ```
911
- */
912
- $queryRawUnsafe<T = unknown>(query: string, ...values: any[]): ZenStackPromise<Schema, T>;
913
- /**
914
- * The current user identity.
915
- */
916
- get $auth(): AuthType<Schema> | undefined;
917
- /**
918
- * Sets the current user identity.
919
- */
920
- $setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema>;
921
- /**
922
- * The Kysely query builder instance.
923
- */
924
- readonly $qb: ToKysely<Schema>;
925
- /**
926
- * The raw Kysely query builder without any ZenStack enhancements.
927
- */
928
- readonly $qbRaw: ToKysely<any>;
929
- /**
930
- * Starts an interactive transaction.
931
- */
932
- $transaction<T>(callback: (tx: Omit<ClientContract<Schema>, TransactionUnsupportedMethods>) => Promise<T>, options?: {
933
- isolationLevel?: TransactionIsolationLevel;
934
- }): Promise<T>;
935
- /**
936
- * Starts a sequential transaction.
937
- */
938
- $transaction<P extends ZenStackPromise<Schema, any>[]>(arg: [...P], options?: {
939
- isolationLevel?: TransactionIsolationLevel;
940
- }): Promise<UnwrapTuplePromises<P>>;
941
- /**
942
- * Returns a new client with the specified plugin installed.
943
- */
944
- $use(plugin: RuntimePlugin<Schema>): ClientContract<Schema>;
945
- /**
946
- * Returns a new client with the specified plugin removed.
947
- */
948
- $unuse(pluginId: string): ClientContract<Schema>;
949
- /**
950
- * Returns a new client with all plugins removed.
951
- */
952
- $unuseAll(): ClientContract<Schema>;
953
- /**
954
- * Disconnects the underlying Kysely instance from the database.
955
- */
956
- $disconnect(): Promise<void>;
957
- /**
958
- * Pushes the schema to the database. For testing purposes only.
959
- * @private
960
- */
961
- $pushSchema(): Promise<void>;
962
- } & {
963
- [Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key>;
964
- } & Procedures<Schema>;
965
- type _TypeMap = {
966
- String: string;
967
- Int: number;
968
- Float: number;
969
- BigInt: bigint;
970
- Decimal: Decimal$1;
971
- Boolean: boolean;
972
- DateTime: Date;
973
- };
974
- type MapType<Schema extends SchemaDef, T extends string> = T extends keyof _TypeMap ? _TypeMap[T] : T extends GetModels<Schema> ? ModelResult<Schema, T> : unknown;
975
- type Procedures<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
976
- $procedures: {
977
- [Key in keyof Schema['procedures']]: ProcedureFunc<Schema, Schema['procedures'][Key]>;
978
- };
979
- } : {};
980
- type ProcedureFunc<Schema extends SchemaDef, Proc extends ProcedureDef> = (...args: MapProcedureParams<Schema, Proc['params']>) => Promise<MapType<Schema, Proc['returnType']>>;
981
- type MapProcedureParams<Schema extends SchemaDef, Params> = {
982
- [P in keyof Params]: Params[P] extends {
983
- type: infer U;
984
- } ? OrUndefinedIf<MapType<Schema, U & string>, Params[P] extends {
985
- optional: true;
986
- } ? true : false> : never;
987
- };
988
- /**
989
- * Creates a new ZenStack client instance.
990
- */
991
- interface ClientConstructor {
992
- new <Schema extends SchemaDef>(schema: Schema, options: ClientOptions<Schema>): ClientContract<Schema>;
993
- }
994
- /**
995
- * CRUD operations.
996
- */
997
- type CRUD = 'create' | 'read' | 'update' | 'delete';
998
- /**
999
- * CRUD operations.
1000
- */
1001
- declare const CRUD: readonly ["create", "read", "update", "delete"];
1002
- /**
1003
- * Extended CRUD operations including 'post-update'.
1004
- */
1005
- type CRUD_EXT = CRUD | 'post-update';
1006
- /**
1007
- * Extended CRUD operations including 'post-update'.
1008
- */
1009
- declare const CRUD_EXT: readonly ["create", "read", "update", "delete", "post-update"];
1010
- type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1011
- /**
1012
- * Returns a list of entities.
1013
- * @param args - query args
1014
- * @returns a list of entities
1015
- *
1016
- * @example
1017
- * ```ts
1018
- * // find all users and return all scalar fields
1019
- * await db.user.findMany();
1020
- *
1021
- * // find all users with name 'Alex'
1022
- * await db.user.findMany({
1023
- * where: {
1024
- * name: 'Alex'
1025
- * }
1026
- * });
1027
- *
1028
- * // select fields
1029
- * await db.user.findMany({
1030
- * select: {
1031
- * name: true,
1032
- * email: true,
1033
- * }
1034
- * }); // result: `Array<{ name: string, email: string }>`
1035
- *
1036
- * // omit fields
1037
- * await db.user.findMany({
1038
- * omit: {
1039
- * name: true,
1040
- * }
1041
- * }); // result: `Array<{ id: number; email: string; ... }>`
1042
- *
1043
- * // include relations (and all scalar fields)
1044
- * await db.user.findMany({
1045
- * include: {
1046
- * posts: true,
1047
- * }
1048
- * }); // result: `Array<{ ...; posts: Post[] }>`
1049
- *
1050
- * // include relations with filter
1051
- * await db.user.findMany({
1052
- * include: {
1053
- * posts: {
1054
- * where: {
1055
- * published: true
1056
- * }
1057
- * }
1058
- * }
1059
- * });
1060
- *
1061
- * // pagination and sorting
1062
- * await db.user.findMany({
1063
- * skip: 10,
1064
- * take: 10,
1065
- * orderBy: [{ name: 'asc' }, { email: 'desc' }],
1066
- * });
1067
- *
1068
- * // pagination with cursor (https://www.prisma.io/docs/orm/prisma-client/queries/pagination#cursor-based-pagination)
1069
- * await db.user.findMany({
1070
- * cursor: { id: 10 },
1071
- * skip: 1,
1072
- * take: 10,
1073
- * orderBy: { id: 'asc' },
1074
- * });
1075
- *
1076
- * // distinct
1077
- * await db.user.findMany({
1078
- * distinct: ['name']
1079
- * });
1080
- *
1081
- * // count all relations
1082
- * await db.user.findMany({
1083
- * _count: true,
1084
- * }); // result: `{ _count: { posts: number; ... } }`
1085
- *
1086
- * // count selected relations
1087
- * await db.user.findMany({
1088
- * _count: { select: { posts: true } },
1089
- * }); // result: `{ _count: { posts: number } }`
1090
- * ```
1091
- */
1092
- findMany<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
1093
- /**
1094
- * Returns a uniquely identified entity.
1095
- * @param args - query args
1096
- * @returns a single entity or null if not found
1097
- * @see {@link findMany}
1098
- */
1099
- findUnique<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
1100
- /**
1101
- * Returns a uniquely identified entity or throws `NotFoundError` if not found.
1102
- * @param args - query args
1103
- * @returns a single entity
1104
- * @see {@link findMany}
1105
- */
1106
- findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1107
- /**
1108
- * Returns the first entity.
1109
- * @param args - query args
1110
- * @returns a single entity or null if not found
1111
- * @see {@link findMany}
1112
- */
1113
- findFirst<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
1114
- /**
1115
- * Returns the first entity or throws `NotFoundError` if not found.
1116
- * @param args - query args
1117
- * @returns a single entity
1118
- * @see {@link findMany}
1119
- */
1120
- findFirstOrThrow<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1121
- /**
1122
- * Creates a new entity.
1123
- * @param args - create args
1124
- * @returns the created entity
1125
- *
1126
- * @example
1127
- * ```ts
1128
- * // simple create
1129
- * await db.user.create({
1130
- * data: { name: 'Alex', email: 'alex@zenstack.dev' }
1131
- * });
1132
- *
1133
- * // nested create with relation
1134
- * await db.user.create({
1135
- * data: {
1136
- * email: 'alex@zenstack.dev',
1137
- * posts: { create: { title: 'Hello World' } }
1138
- * }
1139
- * });
1140
- *
1141
- * // you can use `select`, `omit`, and `include` to control
1142
- * // the fields returned by the query, as with `findMany`
1143
- * await db.user.create({
1144
- * data: {
1145
- * email: 'alex@zenstack.dev',
1146
- * posts: { create: { title: 'Hello World' } }
1147
- * },
1148
- * include: { posts: true }
1149
- * }); // result: `{ id: number; posts: Post[] }`
1150
- *
1151
- * // connect relations
1152
- * await db.user.create({
1153
- * data: {
1154
- * email: 'alex@zenstack.dev',
1155
- * posts: { connect: { id: 1 } }
1156
- * }
1157
- * });
1158
- *
1159
- * // connect relations, and create if not found
1160
- * await db.user.create({
1161
- * data: {
1162
- * email: 'alex@zenstack.dev',
1163
- * posts: {
1164
- * connectOrCreate: {
1165
- * where: { id: 1 },
1166
- * create: { title: 'Hello World' }
1167
- * }
1168
- * }
1169
- * }
1170
- * });
1171
- * ```
1172
- */
1173
- create<T extends CreateArgs<Schema, Model>>(args: SelectSubset<T, CreateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1174
- /**
1175
- * Creates multiple entities. Only scalar fields are allowed.
1176
- * @param args - create args
1177
- * @returns count of created entities: `{ count: number }`
1178
- *
1179
- * @example
1180
- * ```ts
1181
- * // create multiple entities
1182
- * await db.user.createMany({
1183
- * data: [
1184
- * { name: 'Alex', email: 'alex@zenstack.dev' },
1185
- * { name: 'John', email: 'john@zenstack.dev' }
1186
- * ]
1187
- * });
1188
- *
1189
- * // skip items that cause unique constraint violation
1190
- * await db.user.createMany({
1191
- * data: [
1192
- * { name: 'Alex', email: 'alex@zenstack.dev' },
1193
- * { name: 'John', email: 'john@zenstack.dev' }
1194
- * ],
1195
- * skipDuplicates: true
1196
- * });
1197
- * ```
1198
- */
1199
- createMany<T extends CreateManyArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
1200
- /**
1201
- * Creates multiple entities and returns them.
1202
- * @param args - create args. See {@link createMany} for input. Use
1203
- * `select` and `omit` to control the fields returned.
1204
- * @returns the created entities
1205
- *
1206
- * @example
1207
- * ```ts
1208
- * // create multiple entities and return selected fields
1209
- * await db.user.createManyAndReturn({
1210
- * data: [
1211
- * { name: 'Alex', email: 'alex@zenstack.dev' },
1212
- * { name: 'John', email: 'john@zenstack.dev' }
1213
- * ],
1214
- * select: { id: true, email: true }
1215
- * });
1216
- * ```
1217
- */
1218
- createManyAndReturn<T extends CreateManyAndReturnArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
1219
- /**
1220
- * Updates a uniquely identified entity.
1221
- * @param args - update args. See {@link findMany} for how to control
1222
- * fields and relations returned.
1223
- * @returns the updated entity. Throws `NotFoundError` if the entity is not found.
1224
- *
1225
- * @example
1226
- * ```ts
1227
- * // update fields
1228
- * await db.user.update({
1229
- * where: { id: 1 },
1230
- * data: { name: 'Alex' }
1231
- * });
1232
- *
1233
- * // connect a relation
1234
- * await db.user.update({
1235
- * where: { id: 1 },
1236
- * data: { posts: { connect: { id: 1 } } }
1237
- * });
1238
- *
1239
- * // connect relation, and create if not found
1240
- * await db.user.update({
1241
- * where: { id: 1 },
1242
- * data: {
1243
- * posts: {
1244
- * connectOrCreate: {
1245
- * where: { id: 1 },
1246
- * create: { title: 'Hello World' }
1247
- * }
1248
- * }
1249
- * }
1250
- * });
1251
- *
1252
- * // create many related entities (only available for one-to-many relations)
1253
- * await db.user.update({
1254
- * where: { id: 1 },
1255
- * data: {
1256
- * posts: {
1257
- * createMany: {
1258
- * data: [{ title: 'Hello World' }, { title: 'Hello World 2' }],
1259
- * }
1260
- * }
1261
- * }
1262
- * });
1263
- *
1264
- * // disconnect a one-to-many relation
1265
- * await db.user.update({
1266
- * where: { id: 1 },
1267
- * data: { posts: { disconnect: { id: 1 } } }
1268
- * });
1269
- *
1270
- * // disconnect a one-to-one relation
1271
- * await db.user.update({
1272
- * where: { id: 1 },
1273
- * data: { profile: { disconnect: true } }
1274
- * });
1275
- *
1276
- * // replace a relation (only available for one-to-many relations)
1277
- * await db.user.update({
1278
- * where: { id: 1 },
1279
- * data: {
1280
- * posts: {
1281
- * set: [{ id: 1 }, { id: 2 }]
1282
- * }
1283
- * }
1284
- * });
1285
- *
1286
- * // update a relation
1287
- * await db.user.update({
1288
- * where: { id: 1 },
1289
- * data: {
1290
- * posts: {
1291
- * update: { where: { id: 1 }, data: { title: 'Hello World' } }
1292
- * }
1293
- * }
1294
- * });
1295
- *
1296
- * // upsert a relation
1297
- * await db.user.update({
1298
- * where: { id: 1 },
1299
- * data: {
1300
- * posts: {
1301
- * upsert: {
1302
- * where: { id: 1 },
1303
- * create: { title: 'Hello World' },
1304
- * update: { title: 'Hello World' }
1305
- * }
1306
- * }
1307
- * }
1308
- * });
1309
- *
1310
- * // update many related entities (only available for one-to-many relations)
1311
- * await db.user.update({
1312
- * where: { id: 1 },
1313
- * data: {
1314
- * posts: {
1315
- * updateMany: {
1316
- * where: { published: true },
1317
- * data: { title: 'Hello World' }
1318
- * }
1319
- * }
1320
- * }
1321
- * });
1322
- *
1323
- * // delete a one-to-many relation
1324
- * await db.user.update({
1325
- * where: { id: 1 },
1326
- * data: { posts: { delete: { id: 1 } } }
1327
- * });
1328
- *
1329
- * // delete a one-to-one relation
1330
- * await db.user.update({
1331
- * where: { id: 1 },
1332
- * data: { profile: { delete: true } }
1333
- * });
1334
- * ```
1335
- */
1336
- update<T extends UpdateArgs<Schema, Model>>(args: SelectSubset<T, UpdateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1337
- /**
1338
- * Updates multiple entities.
1339
- * @param args - update args. Only scalar fields are allowed for data.
1340
- * @returns count of updated entities: `{ count: number }`
1341
- *
1342
- * @example
1343
- * ```ts
1344
- * // update many entities
1345
- * await db.user.updateMany({
1346
- * where: { email: { endsWith: '@zenstack.dev' } },
1347
- * data: { role: 'ADMIN' }
1348
- * });
1349
- *
1350
- * // limit the number of updated entities
1351
- * await db.user.updateMany({
1352
- * where: { email: { endsWith: '@zenstack.dev' } },
1353
- * data: { role: 'ADMIN' },
1354
- * limit: 10
1355
- * });
1356
- */
1357
- updateMany<T extends UpdateManyArgs<Schema, Model>>(args: Subset<T, UpdateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
1358
- /**
1359
- * Updates multiple entities and returns them.
1360
- * @param args - update args. Only scalar fields are allowed for data.
1361
- * @returns the updated entities
1362
- *
1363
- * @example
1364
- * ```ts
1365
- * // update many entities and return selected fields
1366
- * await db.user.updateManyAndReturn({
1367
- * where: { email: { endsWith: '@zenstack.dev' } },
1368
- * data: { role: 'ADMIN' },
1369
- * select: { id: true, email: true }
1370
- * }); // result: `Array<{ id: string; email: string }>`
1371
- *
1372
- * // limit the number of updated entities
1373
- * await db.user.updateManyAndReturn({
1374
- * where: { email: { endsWith: '@zenstack.dev' } },
1375
- * data: { role: 'ADMIN' },
1376
- * limit: 10
1377
- * });
1378
- * ```
1379
- */
1380
- updateManyAndReturn<T extends UpdateManyAndReturnArgs<Schema, Model>>(args: Subset<T, UpdateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
1381
- /**
1382
- * Creates or updates an entity.
1383
- * @param args - upsert args
1384
- * @returns the upserted entity
1385
- *
1386
- * @example
1387
- * ```ts
1388
- * // upsert an entity
1389
- * await db.user.upsert({
1390
- * // `where` clause is used to find the entity
1391
- * where: { id: 1 },
1392
- * // `create` clause is used if the entity is not found
1393
- * create: { email: 'alex@zenstack.dev', name: 'Alex' },
1394
- * // `update` clause is used if the entity is found
1395
- * update: { name: 'Alex-new' },
1396
- * // `select` and `omit` can be used to control the returned fields
1397
- * ...
1398
- * });
1399
- * ```
1400
- */
1401
- upsert<T extends UpsertArgs<Schema, Model>>(args: SelectSubset<T, UpsertArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1402
- /**
1403
- * Deletes a uniquely identifiable entity.
1404
- * @param args - delete args
1405
- * @returns the deleted entity. Throws `NotFoundError` if the entity is not found.
1406
- *
1407
- * @example
1408
- * ```ts
1409
- * // delete an entity
1410
- * await db.user.delete({
1411
- * where: { id: 1 }
1412
- * });
1413
- *
1414
- * // delete an entity and return selected fields
1415
- * await db.user.delete({
1416
- * where: { id: 1 },
1417
- * select: { id: true, email: true }
1418
- * }); // result: `{ id: string; email: string }`
1419
- * ```
1420
- */
1421
- delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1422
- /**
1423
- * Deletes multiple entities.
1424
- * @param args - delete args
1425
- * @returns count of deleted entities: `{ count: number }`
1426
- *
1427
- * @example
1428
- * ```ts
1429
- * // delete many entities
1430
- * await db.user.deleteMany({
1431
- * where: { email: { endsWith: '@zenstack.dev' } }
1432
- * });
1433
- *
1434
- * // limit the number of deleted entities
1435
- * await db.user.deleteMany({
1436
- * where: { email: { endsWith: '@zenstack.dev' } },
1437
- * limit: 10
1438
- * });
1439
- * ```
1440
- */
1441
- deleteMany<T extends DeleteManyArgs<Schema, Model>>(args?: Subset<T, DeleteManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
1442
- /**
1443
- * Counts rows or field values.
1444
- * @param args - count args
1445
- * @returns `number`, or an object containing count of selected relations
1446
- *
1447
- * @example
1448
- * ```ts
1449
- * // count all
1450
- * await db.user.count();
1451
- *
1452
- * // count with a filter
1453
- * await db.user.count({ where: { email: { endsWith: '@zenstack.dev' } } });
1454
- *
1455
- * // count rows and field values
1456
- * await db.user.count({
1457
- * select: { _all: true, email: true }
1458
- * }); // result: `{ _all: number, email: number }`
1459
- */
1460
- count<T extends CountArgs<Schema, Model>>(args?: Subset<T, CountArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<CountResult<Schema, Model, T>>>;
1461
- /**
1462
- * Aggregates rows.
1463
- * @param args - aggregation args
1464
- * @returns an object containing aggregated values
1465
- *
1466
- * @example
1467
- * ```ts
1468
- * // aggregate rows
1469
- * await db.profile.aggregate({
1470
- * where: { email: { endsWith: '@zenstack.dev' } },
1471
- * _count: true,
1472
- * _avg: { age: true },
1473
- * _sum: { age: true },
1474
- * _min: { age: true },
1475
- * _max: { age: true }
1476
- * }); // result: `{ _count: number, _avg: { age: number }, ... }`
1477
- */
1478
- aggregate<T extends AggregateArgs<Schema, Model>>(args: Subset<T, AggregateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<AggregateResult<Schema, Model, T>>>;
1479
- /**
1480
- * Groups rows by columns.
1481
- * @param args - groupBy args
1482
- * @returns an object containing grouped values
1483
- *
1484
- * @example
1485
- * ```ts
1486
- * // group by a field
1487
- * await db.profile.groupBy({
1488
- * by: 'country',
1489
- * _count: true
1490
- * }); // result: `Array<{ country: string, _count: number }>`
1491
- *
1492
- * // group by multiple fields
1493
- * await db.profile.groupBy({
1494
- * by: ['country', 'city'],
1495
- * _count: true
1496
- * }); // result: `Array<{ country: string, city: string, _count: number }>`
1497
- *
1498
- * // group by with sorting, the `orderBy` fields must be either an aggregation
1499
- * // or a field used in the `by` list
1500
- * await db.profile.groupBy({
1501
- * by: 'country',
1502
- * orderBy: { country: 'desc' }
1503
- * });
1504
- *
1505
- * // group by with having (post-aggregation filter), the fields used in `having` must
1506
- * // be either an aggregation, or a field used in the `by` list
1507
- * await db.profile.groupBy({
1508
- * by: 'country',
1509
- * having: { country: 'US', age: { _avg: { gte: 18 } } }
1510
- * });
1511
- */
1512
- groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
1513
- };
1514
- type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<AllModelOperations<Schema, Model>, IsDelegateModel<Schema, Model> extends true ? 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' : never>;
1515
-
1516
- /**
1517
- * Base for all ZenStack runtime errors.
1518
- */
1519
- declare class ZenStackError extends Error {
1520
- }
1521
- /**
1522
- * Error thrown when input validation fails.
1523
- */
1524
- declare class InputValidationError extends ZenStackError {
1525
- constructor(message: string, cause?: unknown);
1526
- }
1527
- /**
1528
- * Error thrown when a query fails.
1529
- */
1530
- declare class QueryError extends ZenStackError {
1531
- constructor(message: string, cause?: unknown);
1532
- }
1533
- /**
1534
- * Error thrown when an internal error occurs.
1535
- */
1536
- declare class InternalError extends ZenStackError {
1537
- }
1538
- /**
1539
- * Error thrown when an entity is not found.
1540
- */
1541
- declare class NotFoundError extends ZenStackError {
1542
- constructor(model: string, details?: string);
1543
- }
1544
-
1545
- export { type RuntimePlugin as $, type DeleteArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type DeleteManyArgs as E, type FindArgs as F, type CountArgs as G, type CountResult as H, type IncludeInput as I, type JsonArray as J, type AggregateArgs as K, type AggregateResult as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByArgs as P, type GroupByResult as Q, ZenStackError as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, InputValidationError as V, type WhereInput as W, QueryError as X, InternalError as Y, type ZenStackPromise as Z, NotFoundError as _, type JsonObject as a, type ZModelFunction as a0, type OnKyselyQueryArgs as a1, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type TypeDefResult as f, type StringFilter as g, type BytesFilter as h, type BooleanFilter as i, type SortOrder as j, type NullsOrder as k, type WhereUniqueInput as l, type OmitInput as m, type SelectIncludeOmit as n, type SelectInput as o, type Subset as p, type SelectSubset as q, type FindManyArgs as r, type FindFirstArgs as s, type FindUniqueArgs as t, type CreateArgs as u, type CreateManyArgs as v, type CreateManyAndReturnArgs as w, type UpdateManyArgs as x, type UpdateManyAndReturnArgs as y, type UpsertArgs as z };