@zenstackhq/runtime 3.0.0-alpha.1 → 3.0.0-alpha.11

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.
Files changed (40) hide show
  1. package/dist/{contract-DguafRNB.d.cts → contract-BQGRBbOU.d.cts} +846 -734
  2. package/dist/{contract-DguafRNB.d.ts → contract-BQGRBbOU.d.ts} +846 -734
  3. package/dist/{utils/pg-utils.cjs → helpers.cjs} +8 -16
  4. package/dist/helpers.cjs.map +1 -0
  5. package/dist/helpers.d.cts +1 -0
  6. package/dist/helpers.d.ts +1 -0
  7. package/dist/helpers.js +6 -0
  8. package/dist/helpers.js.map +1 -0
  9. package/dist/index.cjs +535 -343
  10. package/dist/index.cjs.map +1 -1
  11. package/dist/index.d.cts +28 -6
  12. package/dist/index.d.ts +28 -6
  13. package/dist/index.js +484 -297
  14. package/dist/index.js.map +1 -1
  15. package/dist/plugins/policy.cjs +115 -104
  16. package/dist/plugins/policy.cjs.map +1 -1
  17. package/dist/plugins/policy.d.cts +2 -4
  18. package/dist/plugins/policy.d.ts +2 -4
  19. package/dist/plugins/policy.js +87 -66
  20. package/dist/plugins/policy.js.map +1 -1
  21. package/dist/schema.cjs.map +1 -1
  22. package/dist/schema.js.map +1 -1
  23. package/package.json +23 -46
  24. package/dist/client.cjs +0 -6094
  25. package/dist/client.cjs.map +0 -1
  26. package/dist/client.d.cts +0 -19
  27. package/dist/client.d.ts +0 -19
  28. package/dist/client.js +0 -6060
  29. package/dist/client.js.map +0 -1
  30. package/dist/utils/pg-utils.cjs.map +0 -1
  31. package/dist/utils/pg-utils.d.cts +0 -8
  32. package/dist/utils/pg-utils.d.ts +0 -8
  33. package/dist/utils/pg-utils.js +0 -16
  34. package/dist/utils/pg-utils.js.map +0 -1
  35. package/dist/utils/sqlite-utils.cjs +0 -55
  36. package/dist/utils/sqlite-utils.cjs.map +0 -1
  37. package/dist/utils/sqlite-utils.d.cts +0 -8
  38. package/dist/utils/sqlite-utils.d.ts +0 -8
  39. package/dist/utils/sqlite-utils.js +0 -22
  40. package/dist/utils/sqlite-utils.js.map +0 -1
@@ -1,12 +1,16 @@
1
- import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetFields, FieldHasDefault, GetFieldType, FieldIsOptional, RelationFields, RelationFieldType, FieldIsArray, GetEnums, GetEnum, BuiltinType, NonRelationFields, GetModel, FieldDef, GetField, FieldIsRelationArray, RelationInfo, FieldType, FieldIsRelation, DataSourceProviderType, ProcedureDef, DataSourceProvider } from '@zenstackhq/sdk/schema';
2
1
  import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
3
- import { Kysely, Generated, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, RootOperationNode, QueryResult, UnknownRow, OperationNode, KyselyConfig, SqliteDialectConfig, PostgresDialectConfig } from 'kysely';
4
- import { Optional } from 'utility-types';
5
- import { Model } from '@zenstackhq/language/ast';
2
+ import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetFields, FieldHasDefault, GetFieldType, FieldIsOptional, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, GetField, FieldIsRelation, GetEnums, GetEnum, BuiltinType, GetModel, FieldDef, FieldIsRelationArray, FieldType, RelationInfo, DataSourceProviderType, DataSourceProvider, ProcedureDef } from '@zenstackhq/sdk/schema';
3
+ import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, RootOperationNode, QueryResult, UnknownRow, OperationNode, SqliteDialectConfig, PostgresDialectConfig, KyselyConfig } from 'kysely';
6
4
 
5
+ type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
7
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;
8
12
  type WrapType<T, Optional = false, Array = false> = Optional extends true ? T | null : Array extends true ? T[] : T;
9
- type MapBaseType$1<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' ? Date : T extends 'Json' ? JsonValue : unknown;
13
+ type MapBaseType$1<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' ? Date : T extends 'Bytes' ? Uint8Array : T extends 'Json' ? JsonValue : unknown;
10
14
  type JsonValue = string | number | boolean | null | JsonObject | JsonArray;
11
15
  type JsonObject = {
12
16
  [key: string]: JsonValue;
@@ -24,10 +28,13 @@ type AtLeast<O extends object, K extends string> = NoExpand<O extends unknown ?
24
28
  type Without<T, U> = {
25
29
  [P in Exclude<keyof T, keyof U>]?: never;
26
30
  };
27
- type XOR<T, U> = T extends object ? U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U : T;
31
+ type XOR<T, U> = T extends object ? (U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U) : T;
28
32
  type MaybePromise<T> = T | Promise<T>;
29
33
  type PrependParameter<Param, Func> = Func extends (...args: any[]) => infer R ? (p: Param, ...args: Parameters<Func>) => R : never;
30
34
  type OrUndefinedIf<T, Condition extends boolean> = Condition extends true ? T | undefined : T;
35
+ type UnwrapTuplePromises<T extends readonly unknown[]> = {
36
+ [K in keyof T]: Awaited<T[K]>;
37
+ };
31
38
 
32
39
  type ToKyselySchema<Schema extends SchemaDef> = {
33
40
  [Model in GetModels<Schema>]: ToKyselyTable<Schema, Model>;
@@ -45,7 +52,7 @@ type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema
45
52
  [Key in NonRelationFields<Schema, Model> as Key extends keyof Omit ? Omit[Key] extends true ? never : Key : Key]: MapFieldType<Schema, Model, Key>;
46
53
  }, Optional, Array>;
47
54
  type ModelSelectResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Select, Omit> = {
48
- [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> ? MapFieldType<Schema, Model, Key> : Key extends RelationFields<Schema, Model> ? Select[Key] extends FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> ? ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Select[Key], FieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : DefaultModelResult<Schema, RelationFieldType<Schema, Model, Key>, Omit, FieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : never;
55
+ [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> ? MapFieldType<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'>, FieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Pick<Select[Key], 'include' | 'omit'>, FieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : DefaultModelResult<Schema, RelationFieldType<Schema, Model, Key>, Omit, FieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : never;
49
56
  };
50
57
  type SelectCountResult<Schema extends SchemaDef, Model extends GetModels<Schema>, C> = C extends true ? {
51
58
  [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: number;
@@ -65,6 +72,7 @@ type ModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args
65
72
  } : Args extends {
66
73
  omit: infer O;
67
74
  } ? DefaultModelResult<Schema, Model, O> : DefaultModelResult<Schema, Model>, Optional, Array>;
75
+ 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>>;
68
76
  type BatchResult = {
69
77
  count: number;
70
78
  };
@@ -90,7 +98,7 @@ type ArrayFilter<T extends string> = {
90
98
  hasSome?: MapBaseType$1<T>[];
91
99
  isEmpty?: boolean;
92
100
  };
93
- type PrimitiveFilter<T extends string, Nullable extends boolean> = T extends 'String' ? StringFilter<Nullable> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable> : T extends 'Boolean' ? BooleanFilter<Nullable> : T extends 'DateTime' ? DateTimeFilter<Nullable> : T extends 'Json' ? 'Not implemented yet' : never;
101
+ type PrimitiveFilter<T extends string, Nullable extends boolean> = T extends 'String' ? StringFilter<Nullable> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable> : T extends 'Boolean' ? BooleanFilter<Nullable> : T extends 'DateTime' ? DateTimeFilter<Nullable> : T extends 'Bytes' ? BytesFilter<Nullable> : T extends 'Json' ? 'Not implemented yet' : never;
94
102
  type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean> = {
95
103
  equals?: NullableIf<DataType, Nullable>;
96
104
  in?: DataType[];
@@ -143,13 +151,13 @@ type WhereUniqueInput<Schema extends SchemaDef, Model extends GetModels<Schema>>
143
151
  [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;
144
152
  };
145
153
  } & WhereInput<Schema, Model>, Extract<keyof GetModel<Schema, Model>['uniqueFields'], string>>;
146
- type OmitFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
154
+ type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
147
155
  [Key in NonRelationFields<Schema, Model>]?: true;
148
156
  };
149
157
  type SelectIncludeOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean> = {
150
- select?: Select<Schema, Model, AllowCount, boolean>;
151
- include?: Include<Schema, Model>;
152
- omit?: OmitFields<Schema, Model>;
158
+ select?: SelectInput<Schema, Model, AllowCount, boolean>;
159
+ include?: IncludeInput<Schema, Model>;
160
+ omit?: OmitInput<Schema, Model>;
153
161
  };
154
162
  type Distinct<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
155
163
  distinct?: OrArray<NonRelationFields<Schema, Model>>;
@@ -157,9 +165,9 @@ type Distinct<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
157
165
  type Cursor<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
158
166
  cursor?: WhereUniqueInput<Schema, Model>;
159
167
  };
160
- type Select<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends Boolean, AllowRelation extends boolean = true> = {
168
+ type SelectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true, AllowRelation extends boolean = true> = {
161
169
  [Key in NonRelationFields<Schema, Model>]?: true;
162
- } & (AllowRelation extends true ? Include<Schema, Model> : {}) & // relation fields
170
+ } & (AllowRelation extends true ? IncludeInput<Schema, Model> : {}) & // relation fields
163
171
  (AllowCount extends true ? {
164
172
  _count?: SelectCount<Schema, Model>;
165
173
  } : {});
@@ -170,7 +178,7 @@ type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = tr
170
178
  };
171
179
  };
172
180
  };
173
- type Include<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
181
+ type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
174
182
  [Key in RelationFields<Schema, Model>]?: boolean | FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, FieldIsArray<Schema, Model, Key> extends true ? true : FieldIsOptional<Schema, Model, Key> extends true ? true : false>;
175
183
  };
176
184
  type Subset<T, U> = {
@@ -202,7 +210,7 @@ type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<S
202
210
  };
203
211
  type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>> = GetField<Schema, Model, Field>['relation'];
204
212
  type OppositeRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>, FT = FieldType<Schema, Model, Field>> = FT extends GetModels<Schema> ? GetRelation<Schema, Model, Field> extends RelationInfo ? GetRelation<Schema, Model, Field>['opposite'] extends GetFields<Schema, FT> ? Schema['models'][FT]['fields'][GetRelation<Schema, Model, Field>['opposite']]['relation'] : never : never : never;
205
- type OppositeRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>, Opposite = OppositeRelation<Schema, Model, Field>> = Opposite extends RelationInfo ? Opposite['fields'] extends string[] ? Opposite['fields'] : [] : [];
213
+ type OppositeRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>, Opposite = OppositeRelation<Schema, Model, Field>> = Opposite extends RelationInfo ? (Opposite['fields'] extends string[] ? Opposite['fields'] : []) : [];
206
214
  type OppositeRelationAndFK<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetFields<Schema, Model>, FT = FieldType<Schema, Model, Field>, Relation = GetField<Schema, Model, Field>['relation'], Opposite = Relation extends RelationInfo ? Relation['opposite'] : never> = FT extends GetModels<Schema> ? Opposite extends GetFields<Schema, FT> ? Opposite | OppositeRelationFields<Schema, Model, Field>[number] : never : never;
207
215
  type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Collection extends boolean, AllowFilter extends boolean = true> = (Collection extends true ? {
208
216
  skip?: number;
@@ -211,19 +219,21 @@ type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Collect
211
219
  } : {}) & (AllowFilter extends true ? {
212
220
  where?: WhereInput<Schema, Model>;
213
221
  } : {}) & SelectIncludeOmit<Schema, Model, Collection> & Distinct<Schema, Model> & Cursor<Schema, Model>;
222
+ type FindManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
223
+ type FindFirstArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, false>;
214
224
  type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
215
225
  where?: WhereUniqueInput<Schema, Model>;
216
226
  } & SelectIncludeOmit<Schema, Model, true>;
217
227
  type CreateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
218
228
  data: CreateInput<Schema, Model>;
219
- select?: Select<Schema, Model, true>;
220
- include?: Include<Schema, Model>;
221
- omit?: OmitFields<Schema, Model>;
229
+ select?: SelectInput<Schema, Model, true>;
230
+ include?: IncludeInput<Schema, Model>;
231
+ omit?: OmitInput<Schema, Model>;
222
232
  };
223
- type CreateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyPayload<Schema, Model>;
224
- type CreateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyPayload<Schema, Model> & {
225
- select?: Select<Schema, Model, false, false>;
226
- omit?: OmitFields<Schema, Model>;
233
+ type CreateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyInput<Schema, Model>;
234
+ type CreateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyInput<Schema, Model> & {
235
+ select?: SelectInput<Schema, Model, false, false>;
236
+ omit?: OmitInput<Schema, Model>;
227
237
  };
228
238
  type OptionalWrap<Schema extends SchemaDef, Model extends GetModels<Schema>, T extends object> = Optional<T, keyof T & OptionalFieldsForCreate<Schema, Model>>;
229
239
  type CreateScalarPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
@@ -244,30 +254,33 @@ type CreateRelationFieldPayload<Schema extends SchemaDef, Model extends GetModel
244
254
  type CreateRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
245
255
  [Key in RelationFields<Schema, Model>]: CreateRelationFieldPayload<Schema, Model, Key>;
246
256
  }>;
247
- type CreateWithFKInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateScalarPayload<Schema, Model> & CreateFKPayload<Schema, Model>;
257
+ type CreateWithFKInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateScalarPayload<Schema, Model> & CreateFKPayload<Schema, Model> & CreateWithNonOwnedRelationPayload<Schema, Model>;
248
258
  type CreateWithRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateScalarPayload<Schema, Model> & CreateRelationPayload<Schema, Model>;
259
+ type CreateWithNonOwnedRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
260
+ [Key in NonOwnedRelationFields<Schema, Model>]: CreateRelationFieldPayload<Schema, Model, Key>;
261
+ }>;
249
262
  type ConnectOrCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
250
263
  where: WhereUniqueInput<Schema, Model>;
251
264
  create: CreateInput<Schema, Model, Without>;
252
265
  };
253
- type CreateManyPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
266
+ type CreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
254
267
  data: OrArray<Omit<CreateScalarPayload<Schema, Model>, Without> & Omit<CreateFKPayload<Schema, Model>, Without>>;
255
268
  skipDuplicates?: boolean;
256
269
  };
257
270
  type CreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = XOR<Omit<CreateWithFKInput<Schema, Model>, Without>, Omit<CreateWithRelationInput<Schema, Model>, Without>>;
258
271
  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>>;
259
- type NestedCreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = CreateManyPayload<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
272
+ type NestedCreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = CreateManyInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
260
273
  type UpdateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
261
274
  data: UpdateInput<Schema, Model>;
262
275
  where: WhereUniqueInput<Schema, Model>;
263
- select?: Select<Schema, Model, true>;
264
- include?: Include<Schema, Model>;
265
- omit?: OmitFields<Schema, Model>;
276
+ select?: SelectInput<Schema, Model, true>;
277
+ include?: IncludeInput<Schema, Model>;
278
+ omit?: OmitInput<Schema, Model>;
266
279
  };
267
280
  type UpdateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = UpdateManyPayload<Schema, Model>;
268
281
  type UpdateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = UpdateManyPayload<Schema, Model> & {
269
- select?: Select<Schema, Model, false, false>;
270
- omit?: OmitFields<Schema, Model>;
282
+ select?: SelectInput<Schema, Model, false, false>;
283
+ omit?: OmitInput<Schema, Model>;
271
284
  };
272
285
  type UpdateManyPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
273
286
  data: OrArray<UpdateScalarInput<Schema, Model, Without>>;
@@ -278,9 +291,9 @@ type UpsertArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
278
291
  create: CreateInput<Schema, Model>;
279
292
  update: UpdateInput<Schema, Model>;
280
293
  where: WhereUniqueInput<Schema, Model>;
281
- select?: Select<Schema, Model, true>;
282
- include?: Include<Schema, Model>;
283
- omit?: OmitFields<Schema, Model>;
294
+ select?: SelectInput<Schema, Model, true>;
295
+ include?: IncludeInput<Schema, Model>;
296
+ omit?: OmitInput<Schema, Model>;
284
297
  };
285
298
  type UpdateScalarInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = Omit<{
286
299
  [Key in NonRelationFields<Schema, Model>]?: ScalarUpdatePayload<Schema, Model, Key>;
@@ -325,9 +338,9 @@ type ToOneRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<
325
338
  } : {});
326
339
  type DeleteArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
327
340
  where: WhereUniqueInput<Schema, Model>;
328
- select?: Select<Schema, Model, true>;
329
- include?: Include<Schema, Model>;
330
- omit?: OmitFields<Schema, Model>;
341
+ select?: SelectInput<Schema, Model, true>;
342
+ include?: IncludeInput<Schema, Model>;
343
+ omit?: OmitInput<Schema, Model>;
331
344
  };
332
345
  type DeleteManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
333
346
  where?: WhereInput<Schema, Model>;
@@ -448,607 +461,92 @@ type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>
448
461
  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>>>;
449
462
  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>>;
450
463
  type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, true>>;
451
- interface ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> {
464
+ type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
465
+ [Key in RelationFields<Schema, Model> as GetField<Schema, Model, Key>['relation'] extends {
466
+ references: unknown[];
467
+ } ? never : Key]: Key;
468
+ };
469
+
470
+ type AuthType<Schema extends SchemaDef> = string extends GetModels<Schema> ? Record<string, unknown> : Schema['authType'] extends GetModels<Schema> ? Partial<ModelResult<Schema, Schema['authType']>> : never;
471
+
472
+ /**
473
+ * Client API methods that are not supported in transactions.
474
+ */
475
+ declare const TRANSACTION_UNSUPPORTED_METHODS: readonly ["$transaction", "$disconnect", "$use"];
476
+
477
+ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
478
+ protected readonly schema: Schema;
479
+ protected readonly options: ClientOptions<Schema>;
480
+ constructor(schema: Schema, options: ClientOptions<Schema>);
481
+ abstract get provider(): DataSourceProviderType;
482
+ transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
483
+ abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>): SelectQueryBuilder<any, any, any>;
484
+ abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
485
+ buildFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
486
+ protected buildCompositeFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, key: 'AND' | 'OR' | 'NOT', payload: any): Expression<SqlBool>;
487
+ private buildRelationFilter;
488
+ private buildToOneRelationFilter;
489
+ private buildToManyRelationFilter;
490
+ private buildArrayFilter;
491
+ buildPrimitiveFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, field: string, fieldDef: FieldDef, payload: any): Expression<SqlBool>;
492
+ private buildLiteralFilter;
493
+ private buildStandardFilter;
494
+ private buildStringFilter;
495
+ private prepStringCasing;
496
+ private buildNumberFilter;
497
+ private buildBooleanFilter;
498
+ private buildDateTimeFilter;
499
+ private buildBytesFilter;
500
+ private buildEnumFilter;
501
+ 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>;
502
+ private negateSort;
503
+ true(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
504
+ false(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
505
+ isTrue(expression: Expression<SqlBool>): boolean;
506
+ isFalse(expression: Expression<SqlBool>): boolean;
507
+ protected and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
508
+ protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
509
+ protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
452
510
  /**
453
- * Returns a list of entities.
454
- * @param args - query args
455
- * @returns a list of entities
456
- *
457
- * @example
458
- * ```ts
459
- * // find all users and return all scalar fields
460
- * await client.user.findMany();
461
- *
462
- * // find all users with name 'Alex'
463
- * await client.user.findMany({
464
- * where: {
465
- * name: 'Alex'
466
- * }
467
- * });
468
- *
469
- * // select fields
470
- * await client.user.findMany({
471
- * select: {
472
- * name: true,
473
- * email: true,
474
- * }
475
- * }); // result: `Array<{ name: string, email: string }>`
476
- *
477
- * // omit fields
478
- * await client.user.findMany({
479
- * omit: {
480
- * name: true,
481
- * }
482
- * }); // result: `Array<{ id: number; email: string; ... }>`
483
- *
484
- * // include relations (and all scalar fields)
485
- * await client.user.findMany({
486
- * include: {
487
- * posts: true,
488
- * }
489
- * }); // result: `Array<{ ...; posts: Post[] }>`
490
- *
491
- * // include relations with filter
492
- * await client.user.findMany({
493
- * include: {
494
- * posts: {
495
- * where: {
496
- * published: true
497
- * }
498
- * }
499
- * }
500
- * });
501
- *
502
- * // pagination and sorting
503
- * await client.user.findMany({
504
- * skip: 10,
505
- * take: 10,
506
- * orderBy: [{ name: 'asc' }, { email: 'desc' }],
507
- * });
508
- *
509
- * // pagination with cursor (https://www.prisma.io/docs/orm/prisma-client/queries/pagination#cursor-based-pagination)
510
- * await client.user.findMany({
511
- * cursor: { id: 10 },
512
- * skip: 1,
513
- * take: 10,
514
- * orderBy: { id: 'asc' },
515
- * });
516
- *
517
- * // distinct
518
- * await client.user.findMany({
519
- * distinct: ['name']
520
- * });
521
- *
522
- * // count all relations
523
- * await client.user.findMany({
524
- * _count: true,
525
- * }); // result: `{ _count: { posts: number; ... } }`
526
- *
527
- * // count selected relations
528
- * await client.user.findMany({
529
- * _count: { select: { posts: true } },
530
- * }); // result: `{ _count: { posts: number } }`
531
- * ```
511
+ * Builds an Kysely expression that returns a JSON object for the given key-value pairs.
532
512
  */
533
- findMany<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): Promise<ModelResult<Schema, Model, T>[]>;
513
+ abstract buildJsonObject(eb: ExpressionBuilder<any, any>, value: Record<string, Expression<unknown>>): ExpressionWrapper<any, any, unknown>;
534
514
  /**
535
- * Returns a uniquely identified entity.
536
- * @param args - query args
537
- * @returns a single entity or null if not found
538
- * @see {@link findMany}
515
+ * Builds an Kysely expression that returns the length of an array.
539
516
  */
540
- findUnique<T extends FindUniqueArgs<Schema, Model>>(args?: SelectSubset<T, FindUniqueArgs<Schema, Model>>): Promise<ModelResult<Schema, Model, T> | null>;
517
+ abstract buildArrayLength(eb: ExpressionBuilder<any, any>, array: Expression<unknown>): ExpressionWrapper<any, any, number>;
541
518
  /**
542
- * Returns a uniquely identified entity or throws `NotFoundError` if not found.
543
- * @param args - query args
544
- * @returns a single entity
545
- * @see {@link findMany}
519
+ * Builds an array literal SQL string for the given values.
546
520
  */
547
- findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model>>(args?: SelectSubset<T, FindUniqueArgs<Schema, Model>>): Promise<ModelResult<Schema, Model, T>>;
521
+ abstract buildArrayLiteralSQL(values: unknown[]): string;
548
522
  /**
549
- * Returns the first entity.
550
- * @param args - query args
551
- * @returns a single entity or null if not found
552
- * @see {@link findMany}
523
+ * Whether the dialect supports updating with a limit on the number of updated rows.
553
524
  */
554
- findFirst<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): Promise<ModelResult<Schema, Model, T> | null>;
525
+ abstract get supportsUpdateWithLimit(): boolean;
555
526
  /**
556
- * Returns the first entity or throws `NotFoundError` if not found.
557
- * @param args - query args
558
- * @returns a single entity
559
- * @see {@link findMany}
527
+ * Whether the dialect supports deleting with a limit on the number of deleted rows.
560
528
  */
561
- findFirstOrThrow<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): Promise<ModelResult<Schema, Model, T>>;
529
+ abstract get supportsDeleteWithLimit(): boolean;
562
530
  /**
563
- * Creates a new entity.
564
- * @param args - create args
565
- * @returns the created entity
566
- *
567
- * @example
568
- * ```ts
569
- * // simple create
570
- * await client.user.create({
571
- * data: { name: 'Alex', email: 'alex@zenstack.dev' }
572
- * });
573
- *
574
- * // nested create with relation
575
- * await client.user.create({
576
- * data: {
577
- * email: 'alex@zenstack.dev',
578
- * posts: { create: { title: 'Hello World' } }
579
- * }
580
- * });
581
- *
582
- * // you can use `select`, `omit`, and `include` to control
583
- * // the fields returned by the query, as with `findMany`
584
- * await client.user.create({
585
- * data: {
586
- * email: 'alex@zenstack.dev',
587
- * posts: { create: { title: 'Hello World' } }
588
- * },
589
- * include: { posts: true }
590
- * }); // result: `{ id: number; posts: Post[] }`
591
- *
592
- * // connect relations
593
- * await client.user.create({
594
- * data: {
595
- * email: 'alex@zenstack.dev',
596
- * posts: { connect: { id: 1 } }
597
- * }
598
- * });
599
- *
600
- * // connect relations, and create if not found
601
- * await client.user.create({
602
- * data: {
603
- * email: 'alex@zenstack.dev',
604
- * posts: {
605
- * connectOrCreate: {
606
- * where: { id: 1 },
607
- * create: { title: 'Hello World' }
608
- * }
609
- * }
610
- * }
611
- * });
612
- * ```
531
+ * Whether the dialect supports DISTINCT ON.
613
532
  */
614
- create<T extends CreateArgs<Schema, Model>>(args: SelectSubset<T, CreateArgs<Schema, Model>>): Promise<ModelResult<Schema, Model, T>>;
533
+ abstract get supportsDistinctOn(): boolean;
534
+ }
535
+
536
+ type CrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
537
+
538
+ /**
539
+ * The result of the hooks interception filter.
540
+ */
541
+ type MutationInterceptionFilterResult = {
615
542
  /**
616
- * Creates multiple entities. Only scalar fields are allowed.
617
- * @param args - create args
618
- * @returns count of created entities: `{ count: number }`
619
- *
620
- * @example
621
- * ```ts
622
- * // create multiple entities
623
- * await client.user.createMany({
624
- * data: [
625
- * { name: 'Alex', email: 'alex@zenstack.dev' },
626
- * { name: 'John', email: 'john@zenstack.dev' }
627
- * ]
628
- * });
629
- *
630
- * // skip items that cause unique constraint violation
631
- * await client.user.createMany({
632
- * data: [
633
- * { name: 'Alex', email: 'alex@zenstack.dev' },
634
- * { name: 'John', email: 'john@zenstack.dev' }
635
- * ],
636
- * skipDuplicates: true
637
- * });
638
- * ```
543
+ * Whether to intercept the mutation or not.
639
544
  */
640
- createMany(args?: CreateManyPayload<Schema, Model>): Promise<BatchResult>;
545
+ intercept: boolean;
641
546
  /**
642
- * Creates multiple entities and returns them.
643
- * @param args - create args. See {@link createMany} for input. Use
644
- * `select` and `omit` to control the fields returned.
645
- * @returns the created entities
646
- *
647
- * @example
648
- * ```ts
649
- * // create multiple entities and return selected fields
650
- * await client.user.createManyAndReturn({
651
- * data: [
652
- * { name: 'Alex', email: 'alex@zenstack.dev' },
653
- * { name: 'John', email: 'john@zenstack.dev' }
654
- * ],
655
- * select: { id: true, email: true }
656
- * });
657
- * ```
547
+ * Whether entities should be loaded before the mutation.
658
548
  */
659
- createManyAndReturn<T extends CreateManyAndReturnArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyAndReturnArgs<Schema, Model>>): Promise<ModelResult<Schema, Model, T>[]>;
660
- /**
661
- * Updates a uniquely identified entity.
662
- * @param args - update args. See {@link findMany} for how to control
663
- * fields and relations returned.
664
- * @returns the updated entity. Throws `NotFoundError` if the entity is not found.
665
- *
666
- * @example
667
- * ```ts
668
- * // update fields
669
- * await client.user.update({
670
- * where: { id: 1 },
671
- * data: { name: 'Alex' }
672
- * });
673
- *
674
- * // connect a relation
675
- * await client.user.update({
676
- * where: { id: 1 },
677
- * data: { posts: { connect: { id: 1 } } }
678
- * });
679
- *
680
- * // connect relation, and create if not found
681
- * await client.user.update({
682
- * where: { id: 1 },
683
- * data: {
684
- * posts: {
685
- * connectOrCreate: {
686
- * where: { id: 1 },
687
- * create: { title: 'Hello World' }
688
- * }
689
- * }
690
- * }
691
- * });
692
- *
693
- * // create many related entities (only available for one-to-many relations)
694
- * await client.user.update({
695
- * where: { id: 1 },
696
- * data: {
697
- * posts: {
698
- * createMany: {
699
- * data: [{ title: 'Hello World' }, { title: 'Hello World 2' }],
700
- * }
701
- * }
702
- * }
703
- * });
704
- *
705
- * // disconnect a one-to-many relation
706
- * await client.user.update({
707
- * where: { id: 1 },
708
- * data: { posts: { disconnect: { id: 1 } } }
709
- * });
710
- *
711
- * // disconnect a one-to-one relation
712
- * await client.user.update({
713
- * where: { id: 1 },
714
- * data: { profile: { disconnect: true } }
715
- * });
716
- *
717
- * // replace a relation (only available for one-to-many relations)
718
- * await client.user.update({
719
- * where: { id: 1 },
720
- * data: {
721
- * posts: {
722
- * set: [{ id: 1 }, { id: 2 }]
723
- * }
724
- * }
725
- * });
726
- *
727
- * // update a relation
728
- * await client.user.update({
729
- * where: { id: 1 },
730
- * data: {
731
- * posts: {
732
- * update: { where: { id: 1 }, data: { title: 'Hello World' } }
733
- * }
734
- * }
735
- * });
736
- *
737
- * // upsert a relation
738
- * await client.user.update({
739
- * where: { id: 1 },
740
- * data: {
741
- * posts: {
742
- * upsert: {
743
- * where: { id: 1 },
744
- * create: { title: 'Hello World' },
745
- * update: { title: 'Hello World' }
746
- * }
747
- * }
748
- * }
749
- * });
750
- *
751
- * // update many related entities (only available for one-to-many relations)
752
- * await client.user.update({
753
- * where: { id: 1 },
754
- * data: {
755
- * posts: {
756
- * updateMany: {
757
- * where: { published: true },
758
- * data: { title: 'Hello World' }
759
- * }
760
- * }
761
- * }
762
- * });
763
- *
764
- * // delete a one-to-many relation
765
- * await client.user.update({
766
- * where: { id: 1 },
767
- * data: { posts: { delete: { id: 1 } } }
768
- * });
769
- *
770
- * // delete a one-to-one relation
771
- * await client.user.update({
772
- * where: { id: 1 },
773
- * data: { profile: { delete: true } }
774
- * });
775
- * ```
776
- */
777
- update<T extends UpdateArgs<Schema, Model>>(args: SelectSubset<T, UpdateArgs<Schema, Model>>): Promise<ModelResult<Schema, Model, T>>;
778
- /**
779
- * Updates multiple entities.
780
- * @param args - update args. Only scalar fields are allowed for data.
781
- * @returns count of updated entities: `{ count: number }`
782
- *
783
- * @example
784
- * ```ts
785
- * // update many entities
786
- * await client.user.updateMany({
787
- * where: { email: { endsWith: '@zenstack.dev' } },
788
- * data: { role: 'ADMIN' }
789
- * });
790
- *
791
- * // limit the number of updated entities
792
- * await client.user.updateMany({
793
- * where: { email: { endsWith: '@zenstack.dev' } },
794
- * data: { role: 'ADMIN' },
795
- * limit: 10
796
- * });
797
- */
798
- updateMany<T extends UpdateManyArgs<Schema, Model>>(args: Subset<T, UpdateManyArgs<Schema, Model>>): Promise<BatchResult>;
799
- /**
800
- * Updates multiple entities and returns them.
801
- * @param args - update args. Only scalar fields are allowed for data.
802
- * @returns the updated entities
803
- *
804
- * @example
805
- * ```ts
806
- * // update many entities and return selected fields
807
- * await client.user.updateManyAndReturn({
808
- * where: { email: { endsWith: '@zenstack.dev' } },
809
- * data: { role: 'ADMIN' },
810
- * select: { id: true, email: true }
811
- * }); // result: `Array<{ id: string; email: string }>`
812
- *
813
- * // limit the number of updated entities
814
- * await client.user.updateManyAndReturn({
815
- * where: { email: { endsWith: '@zenstack.dev' } },
816
- * data: { role: 'ADMIN' },
817
- * limit: 10
818
- * });
819
- * ```
820
- */
821
- updateManyAndReturn<T extends UpdateManyAndReturnArgs<Schema, Model>>(args: Subset<T, UpdateManyAndReturnArgs<Schema, Model>>): Promise<ModelResult<Schema, Model, T>[]>;
822
- /**
823
- * Creates or updates an entity.
824
- * @param args - upsert args
825
- * @returns the upserted entity
826
- *
827
- * @example
828
- * ```ts
829
- * // upsert an entity
830
- * await client.user.upsert({
831
- * // `where` clause is used to find the entity
832
- * where: { id: 1 },
833
- * // `create` clause is used if the entity is not found
834
- * create: { email: 'alex@zenstack.dev', name: 'Alex' },
835
- * // `update` clause is used if the entity is found
836
- * update: { name: 'Alex-new' },
837
- * // `select` and `omit` can be used to control the returned fields
838
- * ...
839
- * });
840
- * ```
841
- */
842
- upsert<T extends UpsertArgs<Schema, Model>>(args: SelectSubset<T, UpsertArgs<Schema, Model>>): Promise<ModelResult<Schema, Model, T>>;
843
- /**
844
- * Deletes a uniquely identifiable entity.
845
- * @param args - delete args
846
- * @returns the deleted entity. Throws `NotFoundError` if the entity is not found.
847
- *
848
- * @example
849
- * ```ts
850
- * // delete an entity
851
- * await client.user.delete({
852
- * where: { id: 1 }
853
- * });
854
- *
855
- * // delete an entity and return selected fields
856
- * await client.user.delete({
857
- * where: { id: 1 },
858
- * select: { id: true, email: true }
859
- * }); // result: `{ id: string; email: string }`
860
- * ```
861
- */
862
- delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): Promise<ModelResult<Schema, Model>>;
863
- /**
864
- * Deletes multiple entities.
865
- * @param args - delete args
866
- * @returns count of deleted entities: `{ count: number }`
867
- *
868
- * @example
869
- * ```ts
870
- * // delete many entities
871
- * await client.user.deleteMany({
872
- * where: { email: { endsWith: '@zenstack.dev' } }
873
- * });
874
- *
875
- * // limit the number of deleted entities
876
- * await client.user.deleteMany({
877
- * where: { email: { endsWith: '@zenstack.dev' } },
878
- * limit: 10
879
- * });
880
- * ```
881
- */
882
- deleteMany<T extends DeleteManyArgs<Schema, Model>>(args?: Subset<T, DeleteManyArgs<Schema, Model>>): Promise<BatchResult>;
883
- /**
884
- * Counts rows or field values.
885
- * @param args - count args
886
- * @returns `number`, or an object containing count of selected relations
887
- *
888
- * @example
889
- * ```ts
890
- * // count all
891
- * await client.user.count();
892
- *
893
- * // count with a filter
894
- * await client.user.count({ where: { email: { endsWith: '@zenstack.dev' } } });
895
- *
896
- * // count rows and field values
897
- * await client.user.count({
898
- * select: { _all: true, email: true }
899
- * }); // result: `{ _all: number, email: number }`
900
- */
901
- count<T extends CountArgs<Schema, Model>>(args?: Subset<T, CountArgs<Schema, Model>>): Promise<CountResult<Schema, Model, T>>;
902
- /**
903
- * Aggregates rows.
904
- * @param args - aggregation args
905
- * @returns an object containing aggregated values
906
- *
907
- * @example
908
- * ```ts
909
- * // aggregate rows
910
- * await client.profile.aggregate({
911
- * where: { email: { endsWith: '@zenstack.dev' } },
912
- * _count: true,
913
- * _avg: { age: true },
914
- * _sum: { age: true },
915
- * _min: { age: true },
916
- * _max: { age: true }
917
- * }); // result: `{ _count: number, _avg: { age: number }, ... }`
918
- */
919
- aggregate<T extends AggregateArgs<Schema, Model>>(args: Subset<T, AggregateArgs<Schema, Model>>): Promise<AggregateResult<Schema, Model, T>>;
920
- /**
921
- * Groups rows by columns.
922
- * @param args - groupBy args
923
- * @returns an object containing grouped values
924
- *
925
- * @example
926
- * ```ts
927
- * // group by a field
928
- * await client.profile.groupBy({
929
- * by: 'country',
930
- * _count: true
931
- * }); // result: `Array<{ country: string, _count: number }>`
932
- *
933
- * // group by multiple fields
934
- * await client.profile.groupBy({
935
- * by: ['country', 'city'],
936
- * _count: true
937
- * }); // result: `Array<{ country: string, city: string, _count: number }>`
938
- *
939
- * // group by with sorting, the `orderBy` fields must be in the `by` list
940
- * await client.profile.groupBy({
941
- * by: 'country',
942
- * orderBy: { country: 'desc' }
943
- * });
944
- *
945
- * // group by with having (post-aggregation filter), the `having` fields must
946
- * // be in the `by` list
947
- * await client.profile.groupBy({
948
- * by: 'country',
949
- * having: { country: 'US' }
950
- * });
951
- */
952
- groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): Promise<GroupByResult<Schema, Model, T>>;
953
- }
954
-
955
- type AuthType<Schema extends SchemaDef> = string extends GetModels<Schema> ? Record<string, unknown> : Schema['authType'] extends GetModels<Schema> ? Partial<ModelResult<Schema, Schema['authType']>> : never;
956
-
957
- declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
958
- protected readonly schema: Schema;
959
- protected readonly options: ClientOptions<Schema>;
960
- constructor(schema: Schema, options: ClientOptions<Schema>);
961
- abstract get provider(): DataSourceProviderType;
962
- transformPrimitive(value: unknown, _type: BuiltinType): unknown;
963
- abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>): SelectQueryBuilder<any, any, any>;
964
- abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
965
- buildFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
966
- protected buildCompositeFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, key: 'AND' | 'OR' | 'NOT', payload: any): Expression<SqlBool>;
967
- private buildRelationFilter;
968
- private buildToOneRelationFilter;
969
- private buildToManyRelationFilter;
970
- private buildArrayFilter;
971
- buildPrimitiveFilter(eb: ExpressionBuilder<any, any>, model: string, modelAlias: string, field: string, fieldDef: FieldDef, payload: any): Expression<SqlBool>;
972
- private buildLiteralFilter;
973
- private buildStandardFilter;
974
- private buildStringFilter;
975
- private prepStringCasing;
976
- private buildNumberFilter;
977
- private buildBooleanFilter;
978
- private buildDateTimeFilter;
979
- private buildBytesFilter;
980
- private buildEnumFilter;
981
- 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>;
982
- private negateSort;
983
- true(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
984
- false(eb: ExpressionBuilder<any, any>): Expression<SqlBool>;
985
- isTrue(expression: Expression<SqlBool>): boolean;
986
- isFalse(expression: Expression<SqlBool>): boolean;
987
- protected and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
988
- protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
989
- protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
990
- /**
991
- * Builds an Kysely expression that returns a JSON object for the given key-value pairs.
992
- */
993
- abstract buildJsonObject(eb: ExpressionBuilder<any, any>, value: Record<string, Expression<unknown>>): ExpressionWrapper<any, any, unknown>;
994
- /**
995
- * Builds an Kysely expression that returns the length of an array.
996
- */
997
- abstract buildArrayLength(eb: ExpressionBuilder<any, any>, array: Expression<unknown>): ExpressionWrapper<any, any, number>;
998
- /**
999
- * Builds an array literal SQL string for the given values.
1000
- */
1001
- abstract buildArrayLiteralSQL(values: unknown[]): string;
1002
- /**
1003
- * Whether the dialect supports updating with a limit on the number of updated rows.
1004
- */
1005
- abstract get supportsUpdateWithLimit(): boolean;
1006
- /**
1007
- * Whether the dialect supports deleting with a limit on the number of deleted rows.
1008
- */
1009
- abstract get supportsDeleteWithLimit(): boolean;
1010
- /**
1011
- * Whether the dialect supports DISTINCT ON.
1012
- */
1013
- abstract get supportsDistinctOn(): boolean;
1014
- }
1015
-
1016
- type CrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
1017
-
1018
- type QueryContext<Schema extends SchemaDef> = {
1019
- /**
1020
- * The ZenStack client that's invoking the plugin.
1021
- */
1022
- client: ClientContract<Schema>;
1023
- /**
1024
- * The model that is being queried.
1025
- */
1026
- model: GetModels<Schema>;
1027
- /**
1028
- * The query operation that is being performed.
1029
- */
1030
- operation: CrudOperation;
1031
- /**
1032
- * The query arguments.
1033
- */
1034
- queryArgs: unknown;
1035
- };
1036
- /**
1037
- * The result of the hooks interception filter.
1038
- */
1039
- type MutationInterceptionFilterResult = {
1040
- /**
1041
- * Whether to intercept the mutation or not.
1042
- */
1043
- intercept: boolean;
1044
- /**
1045
- * Whether to use a transaction for the mutation.
1046
- */
1047
- useTransactionForMutation?: boolean;
1048
- /**
1049
- * Whether entities should be loaded before the mutation.
1050
- */
1051
- loadBeforeMutationEntity?: boolean;
549
+ loadBeforeMutationEntity?: boolean;
1052
550
  /**
1053
551
  * Whether entities should be loaded after the mutation.
1054
552
  */
@@ -1068,9 +566,6 @@ type MutationHooksArgs<Schema extends SchemaDef> = {
1068
566
  */
1069
567
  queryNode: OperationNode;
1070
568
  };
1071
- type OnQueryArgs<Schema extends SchemaDef> = QueryContext<Schema> & {
1072
- proceed: ProceedQueryFunction<Schema>;
1073
- };
1074
569
  type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
1075
570
  entities?: Record<string, unknown>[];
1076
571
  };
@@ -1078,16 +573,12 @@ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs
1078
573
  beforeMutationEntities?: Record<string, unknown>[];
1079
574
  afterMutationEntities?: Record<string, unknown>[];
1080
575
  };
1081
- type ProceedQueryFunction<Schema extends SchemaDef> = (queryArgs: unknown, tx?: ClientContract<Schema>) => Promise<unknown>;
1082
- type OnKyselyQueryTransactionCallback = (proceed: ProceedKyselyQueryFunction) => Promise<QueryResult<any>>;
1083
- type OnKyselyQueryTransaction = (callback: OnKyselyQueryTransactionCallback) => Promise<QueryResult<any>>;
1084
576
  type OnKyselyQueryArgs<Schema extends SchemaDef> = {
1085
577
  kysely: ToKysely<Schema>;
1086
578
  schema: SchemaDef;
1087
579
  client: ClientContract<Schema>;
1088
580
  query: RootOperationNode;
1089
581
  proceed: ProceedKyselyQueryFunction;
1090
- transaction: OnKyselyQueryTransaction;
1091
582
  };
1092
583
  type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
1093
584
  /**
@@ -1109,7 +600,7 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
1109
600
  /**
1110
601
  * Intercepts an ORM query.
1111
602
  */
1112
- onQuery?: (args: OnQueryArgs<Schema>) => Promise<unknown>;
603
+ onQuery?: OnQueryHooks<Schema>;
1113
604
  /**
1114
605
  * Intercepts a Kysely query.
1115
606
  */
@@ -1132,141 +623,762 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
1132
623
  * @param args.afterMutationEntity Only available if `loadAfterMutationEntity` is set to true in the
1133
624
  * return value of {@link RuntimePlugin.mutationInterceptionFilter}.
1134
625
  */
1135
- afterEntityMutation?: (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
1136
- }
1137
- type CliGeneratorContext = {
1138
- model: Model;
1139
- outputPath: string;
1140
- tsSchemaFile: string;
1141
- };
1142
- type CliGenerator = (context: CliGeneratorContext) => MaybePromise<void>;
1143
-
1144
- type DialectConfig<Provider extends DataSourceProvider> = Provider['type'] extends 'sqlite' ? Optional<SqliteDialectConfig, 'database'> : Provider extends 'postgresql' ? Optional<PostgresDialectConfig, 'pool'> : never;
1145
- type ZModelFunctionContext<Schema extends SchemaDef> = {
1146
- dialect: BaseCrudDialect<Schema>;
1147
- model: GetModels<Schema>;
1148
- operation: CRUD;
1149
- };
1150
- type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
1151
- /**
1152
- * ZenStack client options.
1153
- */
1154
- type ClientOptions<Schema extends SchemaDef> = {
626
+ afterEntityMutation?: (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
627
+ }
628
+ type OnQueryHooks<Schema extends SchemaDef = SchemaDef> = {
629
+ [Model in GetModels<Schema> as Uncapitalize<Model>]?: OnQueryOperationHooks<Schema, Model>;
630
+ } & {
631
+ $allModels?: OnQueryOperationHooks<Schema, GetModels<Schema>>;
632
+ };
633
+ type OnQueryOperationHooks<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
634
+ [Operation in keyof ModelOperations<Schema, Model>]?: (ctx: OnQueryHookContext<Schema, Model, Operation>) => Promise<Awaited<ReturnType<ModelOperations<Schema, Model>[Operation]>>>;
635
+ } & {
636
+ $allOperations?: (ctx: {
637
+ model: Model;
638
+ operation: CrudOperation;
639
+ args: unknown;
640
+ query: (args: unknown) => Promise<unknown>;
641
+ }) => MaybePromise<unknown>;
642
+ };
643
+ type OnQueryHookContext<Schema extends SchemaDef, Model extends GetModels<Schema>, Operation extends keyof ModelOperations<Schema, Model>> = {
644
+ /**
645
+ * The model that is being queried.
646
+ */
647
+ model: Model;
648
+ /**
649
+ * The operation that is being performed.
650
+ */
651
+ operation: Operation;
652
+ /**
653
+ * The query arguments.
654
+ */
655
+ args: Parameters<ModelOperations<Schema, Model>[Operation]>[0];
656
+ /**
657
+ * The query function to proceed with the original query.
658
+ * It takes the same arguments as the operation method.
659
+ *
660
+ * @param args The query arguments.
661
+ */
662
+ query: (args: Parameters<ModelOperations<Schema, Model>[Operation]>[0]) => ReturnType<ModelOperations<Schema, Model>[Operation]>;
663
+ /**
664
+ * The ZenStack client that is performing the operation.
665
+ */
666
+ client: ClientContract<Schema>;
667
+ };
668
+ /**
669
+ * Defines a ZenStack runtime plugin.
670
+ */
671
+ declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
672
+
673
+ type DialectConfig<Provider extends DataSourceProvider> = Provider['type'] extends 'sqlite' ? Optional<SqliteDialectConfig, 'database'> : Provider['type'] extends 'postgresql' ? Optional<PostgresDialectConfig, 'pool'> : never;
674
+ type ZModelFunctionContext<Schema extends SchemaDef> = {
675
+ dialect: BaseCrudDialect<Schema>;
676
+ model: GetModels<Schema>;
677
+ operation: CRUD;
678
+ };
679
+ type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
680
+ /**
681
+ * ZenStack client options.
682
+ */
683
+ type ClientOptions<Schema extends SchemaDef> = {
684
+ /**
685
+ * Database dialect configuration.
686
+ */
687
+ dialectConfig: DialectConfig<Schema['provider']>;
688
+ /**
689
+ * Custom function definitions.
690
+ */
691
+ functions?: Record<string, ZModelFunction<Schema>>;
692
+ /**
693
+ * Plugins.
694
+ */
695
+ plugins?: RuntimePlugin<Schema>[];
696
+ /**
697
+ * Logging configuration.
698
+ */
699
+ log?: KyselyConfig['log'];
700
+ /**
701
+ * Debug mode.
702
+ */
703
+ debug?: boolean;
704
+ } & (HasComputedFields<Schema> extends true ? {
705
+ /**
706
+ * Computed field definitions.
707
+ */
708
+ computedFields: ComputedFieldsOptions<Schema>;
709
+ } : {}) & (HasProcedures<Schema> extends true ? {
710
+ /**
711
+ * Custom procedure definitions.
712
+ */
713
+ procedures: ProceduresOptions<Schema>;
714
+ } : {});
715
+ type ComputedFieldsOptions<Schema extends SchemaDef> = {
716
+ [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
717
+ [Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
718
+ };
719
+ };
720
+ type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
721
+ type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
722
+ procedures: Record<string, ProcedureDef>;
723
+ } ? {
724
+ [Key in keyof Schema['procedures']]: PrependParameter<ClientContract<Schema>, ProcedureFunc<Schema, Schema['procedures'][Key]>>;
725
+ } : {};
726
+ type HasProcedures<Schema extends SchemaDef> = Schema extends {
727
+ procedures: Record<string, ProcedureDef>;
728
+ } ? true : false;
729
+
730
+ /**
731
+ * A promise that only executes when it's awaited or .then() is called.
732
+ */
733
+ type ZenStackPromise<Schema extends SchemaDef, T> = Promise<T> & {
734
+ /**
735
+ * @private
736
+ * Callable to get a plain promise.
737
+ */
738
+ cb: (txClient?: ClientContract<Schema>) => Promise<T>;
739
+ };
740
+
741
+ type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[number];
742
+ /**
743
+ * Transaction isolation levels.
744
+ */
745
+ declare enum TransactionIsolationLevel {
746
+ ReadUncommitted = "read uncommitted",
747
+ ReadCommitted = "read committed",
748
+ RepeatableRead = "repeatable read",
749
+ Serializable = "serializable",
750
+ Snapshot = "snapshot"
751
+ }
752
+ /**
753
+ * ZenStack client interface.
754
+ */
755
+ type ClientContract<Schema extends SchemaDef> = {
756
+ readonly $schema: Schema;
757
+ /**
758
+ * The client options.
759
+ */
760
+ readonly $options: ClientOptions<Schema>;
761
+ /**
762
+ * Executes a prepared raw query and returns the number of affected rows.
763
+ * @example
764
+ * ```
765
+ * const result = await client.$executeRaw`UPDATE User SET cool = ${true} WHERE email = ${'user@email.com'};`
766
+ * ```
767
+ */
768
+ $executeRaw(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, number>;
769
+ /**
770
+ * Executes a raw query and returns the number of affected rows.
771
+ * This method is susceptible to SQL injections.
772
+ * @example
773
+ * ```
774
+ * const result = await client.$executeRawUnsafe('UPDATE User SET cool = $1 WHERE email = $2 ;', true, 'user@email.com')
775
+ * ```
776
+ */
777
+ $executeRawUnsafe(query: string, ...values: any[]): ZenStackPromise<Schema, number>;
778
+ /**
779
+ * Performs a prepared raw query and returns the `SELECT` data.
780
+ * @example
781
+ * ```
782
+ * const result = await client.$queryRaw`SELECT * FROM User WHERE id = ${1} OR email = ${'user@email.com'};`
783
+ * ```
784
+ */
785
+ $queryRaw<T = unknown>(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, T>;
786
+ /**
787
+ * Performs a raw query and returns the `SELECT` data.
788
+ * This method is susceptible to SQL injections.
789
+ * @example
790
+ * ```
791
+ * const result = await client.$queryRawUnsafe('SELECT * FROM User WHERE id = $1 OR email = $2;', 1, 'user@email.com')
792
+ * ```
793
+ */
794
+ $queryRawUnsafe<T = unknown>(query: string, ...values: any[]): ZenStackPromise<Schema, T>;
795
+ /**
796
+ * The current user identity.
797
+ */
798
+ get $auth(): AuthType<Schema> | undefined;
799
+ /**
800
+ * Sets the current user identity.
801
+ */
802
+ $setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema>;
803
+ /**
804
+ * The Kysely query builder instance.
805
+ */
806
+ readonly $qb: ToKysely<Schema>;
807
+ /**
808
+ * The raw Kysely query builder without any ZenStack enhancements.
809
+ */
810
+ readonly $qbRaw: ToKysely<any>;
811
+ /**
812
+ * Starts an interactive transaction.
813
+ */
814
+ $transaction<T>(callback: (tx: Omit<ClientContract<Schema>, TransactionUnsupportedMethods>) => Promise<T>, options?: {
815
+ isolationLevel?: TransactionIsolationLevel;
816
+ }): Promise<T>;
817
+ /**
818
+ * Starts a sequential transaction.
819
+ */
820
+ $transaction<P extends ZenStackPromise<Schema, any>[]>(arg: [...P], options?: {
821
+ isolationLevel?: TransactionIsolationLevel;
822
+ }): Promise<UnwrapTuplePromises<P>>;
823
+ /**
824
+ * Returns a new client with the specified plugin installed.
825
+ */
826
+ $use(plugin: RuntimePlugin<Schema>): ClientContract<Schema>;
827
+ /**
828
+ * Returns a new client with the specified plugin removed.
829
+ */
830
+ $unuse(pluginId: string): ClientContract<Schema>;
831
+ /**
832
+ * Returns a new client with all plugins removed.
833
+ */
834
+ $unuseAll(): ClientContract<Schema>;
835
+ /**
836
+ * Disconnects the underlying Kysely instance from the database.
837
+ */
838
+ $disconnect(): Promise<void>;
839
+ /**
840
+ * Pushes the schema to the database. For testing purposes only.
841
+ * @private
842
+ */
843
+ $pushSchema(): Promise<void>;
844
+ } & {
845
+ [Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key>;
846
+ } & Procedures<Schema>;
847
+ type _TypeMap = {
848
+ String: string;
849
+ Int: number;
850
+ Float: number;
851
+ BigInt: bigint;
852
+ Decimal: Decimal$1;
853
+ Boolean: boolean;
854
+ DateTime: Date;
855
+ };
856
+ type MapType<Schema extends SchemaDef, T extends string> = T extends keyof _TypeMap ? _TypeMap[T] : T extends GetModels<Schema> ? ModelResult<Schema, T> : unknown;
857
+ type Procedures<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
858
+ $procedures: {
859
+ [Key in keyof Schema['procedures']]: ProcedureFunc<Schema, Schema['procedures'][Key]>;
860
+ };
861
+ } : {};
862
+ type ProcedureFunc<Schema extends SchemaDef, Proc extends ProcedureDef> = (...args: MapProcedureParams<Schema, Proc['params']>) => Promise<MapType<Schema, Proc['returnType']>>;
863
+ type MapProcedureParams<Schema extends SchemaDef, Params> = {
864
+ [P in keyof Params]: Params[P] extends {
865
+ type: infer U;
866
+ } ? OrUndefinedIf<MapType<Schema, U & string>, Params[P] extends {
867
+ optional: true;
868
+ } ? true : false> : never;
869
+ };
870
+ /**
871
+ * Creates a new ZenStack client instance.
872
+ */
873
+ interface ClientConstructor {
874
+ new <Schema extends SchemaDef>(schema: Schema, options: ClientOptions<Schema>): ClientContract<Schema>;
875
+ }
876
+ /**
877
+ * CRUD operations.
878
+ */
879
+ type CRUD = 'create' | 'read' | 'update' | 'delete';
880
+ interface ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> {
881
+ /**
882
+ * Returns a list of entities.
883
+ * @param args - query args
884
+ * @returns a list of entities
885
+ *
886
+ * @example
887
+ * ```ts
888
+ * // find all users and return all scalar fields
889
+ * await client.user.findMany();
890
+ *
891
+ * // find all users with name 'Alex'
892
+ * await client.user.findMany({
893
+ * where: {
894
+ * name: 'Alex'
895
+ * }
896
+ * });
897
+ *
898
+ * // select fields
899
+ * await client.user.findMany({
900
+ * select: {
901
+ * name: true,
902
+ * email: true,
903
+ * }
904
+ * }); // result: `Array<{ name: string, email: string }>`
905
+ *
906
+ * // omit fields
907
+ * await client.user.findMany({
908
+ * omit: {
909
+ * name: true,
910
+ * }
911
+ * }); // result: `Array<{ id: number; email: string; ... }>`
912
+ *
913
+ * // include relations (and all scalar fields)
914
+ * await client.user.findMany({
915
+ * include: {
916
+ * posts: true,
917
+ * }
918
+ * }); // result: `Array<{ ...; posts: Post[] }>`
919
+ *
920
+ * // include relations with filter
921
+ * await client.user.findMany({
922
+ * include: {
923
+ * posts: {
924
+ * where: {
925
+ * published: true
926
+ * }
927
+ * }
928
+ * }
929
+ * });
930
+ *
931
+ * // pagination and sorting
932
+ * await client.user.findMany({
933
+ * skip: 10,
934
+ * take: 10,
935
+ * orderBy: [{ name: 'asc' }, { email: 'desc' }],
936
+ * });
937
+ *
938
+ * // pagination with cursor (https://www.prisma.io/docs/orm/prisma-client/queries/pagination#cursor-based-pagination)
939
+ * await client.user.findMany({
940
+ * cursor: { id: 10 },
941
+ * skip: 1,
942
+ * take: 10,
943
+ * orderBy: { id: 'asc' },
944
+ * });
945
+ *
946
+ * // distinct
947
+ * await client.user.findMany({
948
+ * distinct: ['name']
949
+ * });
950
+ *
951
+ * // count all relations
952
+ * await client.user.findMany({
953
+ * _count: true,
954
+ * }); // result: `{ _count: { posts: number; ... } }`
955
+ *
956
+ * // count selected relations
957
+ * await client.user.findMany({
958
+ * _count: { select: { posts: true } },
959
+ * }); // result: `{ _count: { posts: number } }`
960
+ * ```
961
+ */
962
+ findMany<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
1155
963
  /**
1156
- * Database dialect configuration.
964
+ * Returns a uniquely identified entity.
965
+ * @param args - query args
966
+ * @returns a single entity or null if not found
967
+ * @see {@link findMany}
1157
968
  */
1158
- dialectConfig?: DialectConfig<Schema['provider']>;
969
+ findUnique<T extends FindUniqueArgs<Schema, Model>>(args?: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
1159
970
  /**
1160
- * Custom function definitions.
971
+ * Returns a uniquely identified entity or throws `NotFoundError` if not found.
972
+ * @param args - query args
973
+ * @returns a single entity
974
+ * @see {@link findMany}
1161
975
  */
1162
- functions?: Record<string, ZModelFunction<Schema>>;
976
+ findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model>>(args?: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1163
977
  /**
1164
- * Plugins.
978
+ * Returns the first entity.
979
+ * @param args - query args
980
+ * @returns a single entity or null if not found
981
+ * @see {@link findMany}
1165
982
  */
1166
- plugins?: RuntimePlugin<Schema>[];
983
+ findFirst<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
1167
984
  /**
1168
- * Logging configuration.
985
+ * Returns the first entity or throws `NotFoundError` if not found.
986
+ * @param args - query args
987
+ * @returns a single entity
988
+ * @see {@link findMany}
1169
989
  */
1170
- log?: KyselyConfig['log'];
1171
- } & (HasComputedFields<Schema> extends true ? {
990
+ findFirstOrThrow<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1172
991
  /**
1173
- * Computed field definitions.
992
+ * Creates a new entity.
993
+ * @param args - create args
994
+ * @returns the created entity
995
+ *
996
+ * @example
997
+ * ```ts
998
+ * // simple create
999
+ * await client.user.create({
1000
+ * data: { name: 'Alex', email: 'alex@zenstack.dev' }
1001
+ * });
1002
+ *
1003
+ * // nested create with relation
1004
+ * await client.user.create({
1005
+ * data: {
1006
+ * email: 'alex@zenstack.dev',
1007
+ * posts: { create: { title: 'Hello World' } }
1008
+ * }
1009
+ * });
1010
+ *
1011
+ * // you can use `select`, `omit`, and `include` to control
1012
+ * // the fields returned by the query, as with `findMany`
1013
+ * await client.user.create({
1014
+ * data: {
1015
+ * email: 'alex@zenstack.dev',
1016
+ * posts: { create: { title: 'Hello World' } }
1017
+ * },
1018
+ * include: { posts: true }
1019
+ * }); // result: `{ id: number; posts: Post[] }`
1020
+ *
1021
+ * // connect relations
1022
+ * await client.user.create({
1023
+ * data: {
1024
+ * email: 'alex@zenstack.dev',
1025
+ * posts: { connect: { id: 1 } }
1026
+ * }
1027
+ * });
1028
+ *
1029
+ * // connect relations, and create if not found
1030
+ * await client.user.create({
1031
+ * data: {
1032
+ * email: 'alex@zenstack.dev',
1033
+ * posts: {
1034
+ * connectOrCreate: {
1035
+ * where: { id: 1 },
1036
+ * create: { title: 'Hello World' }
1037
+ * }
1038
+ * }
1039
+ * }
1040
+ * });
1041
+ * ```
1174
1042
  */
1175
- computedFields: ComputedFieldsOptions<Schema>;
1176
- } : {}) & (HasProcedures<Schema> extends true ? {
1043
+ create<T extends CreateArgs<Schema, Model>>(args: SelectSubset<T, CreateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1177
1044
  /**
1178
- * Custom procedure definitions.
1045
+ * Creates multiple entities. Only scalar fields are allowed.
1046
+ * @param args - create args
1047
+ * @returns count of created entities: `{ count: number }`
1048
+ *
1049
+ * @example
1050
+ * ```ts
1051
+ * // create multiple entities
1052
+ * await client.user.createMany({
1053
+ * data: [
1054
+ * { name: 'Alex', email: 'alex@zenstack.dev' },
1055
+ * { name: 'John', email: 'john@zenstack.dev' }
1056
+ * ]
1057
+ * });
1058
+ *
1059
+ * // skip items that cause unique constraint violation
1060
+ * await client.user.createMany({
1061
+ * data: [
1062
+ * { name: 'Alex', email: 'alex@zenstack.dev' },
1063
+ * { name: 'John', email: 'john@zenstack.dev' }
1064
+ * ],
1065
+ * skipDuplicates: true
1066
+ * });
1067
+ * ```
1179
1068
  */
1180
- procedures: ProceduresOptions<Schema>;
1181
- } : {});
1182
- type ComputedFieldsOptions<Schema extends SchemaDef> = {
1183
- [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
1184
- [Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
1185
- };
1186
- };
1187
- type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
1188
- type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
1189
- procedures: Record<string, ProcedureDef>;
1190
- } ? {
1191
- [Key in keyof Schema['procedures']]: PrependParameter<ClientContract<Schema>, ProcedureFunc<Schema, Schema['procedures'][Key]>>;
1192
- } : {};
1193
- type HasProcedures<Schema extends SchemaDef> = Schema extends {
1194
- procedures: Record<string, ProcedureDef>;
1195
- } ? true : false;
1196
-
1197
- /**
1198
- * ZenStack client interface.
1199
- */
1200
- type ClientContract<Schema extends SchemaDef> = {
1201
- readonly $schema: Schema;
1069
+ createMany<T extends CreateManyArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
1202
1070
  /**
1203
- * The client options.
1071
+ * Creates multiple entities and returns them.
1072
+ * @param args - create args. See {@link createMany} for input. Use
1073
+ * `select` and `omit` to control the fields returned.
1074
+ * @returns the created entities
1075
+ *
1076
+ * @example
1077
+ * ```ts
1078
+ * // create multiple entities and return selected fields
1079
+ * await client.user.createManyAndReturn({
1080
+ * data: [
1081
+ * { name: 'Alex', email: 'alex@zenstack.dev' },
1082
+ * { name: 'John', email: 'john@zenstack.dev' }
1083
+ * ],
1084
+ * select: { id: true, email: true }
1085
+ * });
1086
+ * ```
1204
1087
  */
1205
- readonly $options: ClientOptions<Schema>;
1088
+ createManyAndReturn<T extends CreateManyAndReturnArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
1206
1089
  /**
1207
- * The current user identity.
1090
+ * Updates a uniquely identified entity.
1091
+ * @param args - update args. See {@link findMany} for how to control
1092
+ * fields and relations returned.
1093
+ * @returns the updated entity. Throws `NotFoundError` if the entity is not found.
1094
+ *
1095
+ * @example
1096
+ * ```ts
1097
+ * // update fields
1098
+ * await client.user.update({
1099
+ * where: { id: 1 },
1100
+ * data: { name: 'Alex' }
1101
+ * });
1102
+ *
1103
+ * // connect a relation
1104
+ * await client.user.update({
1105
+ * where: { id: 1 },
1106
+ * data: { posts: { connect: { id: 1 } } }
1107
+ * });
1108
+ *
1109
+ * // connect relation, and create if not found
1110
+ * await client.user.update({
1111
+ * where: { id: 1 },
1112
+ * data: {
1113
+ * posts: {
1114
+ * connectOrCreate: {
1115
+ * where: { id: 1 },
1116
+ * create: { title: 'Hello World' }
1117
+ * }
1118
+ * }
1119
+ * }
1120
+ * });
1121
+ *
1122
+ * // create many related entities (only available for one-to-many relations)
1123
+ * await client.user.update({
1124
+ * where: { id: 1 },
1125
+ * data: {
1126
+ * posts: {
1127
+ * createMany: {
1128
+ * data: [{ title: 'Hello World' }, { title: 'Hello World 2' }],
1129
+ * }
1130
+ * }
1131
+ * }
1132
+ * });
1133
+ *
1134
+ * // disconnect a one-to-many relation
1135
+ * await client.user.update({
1136
+ * where: { id: 1 },
1137
+ * data: { posts: { disconnect: { id: 1 } } }
1138
+ * });
1139
+ *
1140
+ * // disconnect a one-to-one relation
1141
+ * await client.user.update({
1142
+ * where: { id: 1 },
1143
+ * data: { profile: { disconnect: true } }
1144
+ * });
1145
+ *
1146
+ * // replace a relation (only available for one-to-many relations)
1147
+ * await client.user.update({
1148
+ * where: { id: 1 },
1149
+ * data: {
1150
+ * posts: {
1151
+ * set: [{ id: 1 }, { id: 2 }]
1152
+ * }
1153
+ * }
1154
+ * });
1155
+ *
1156
+ * // update a relation
1157
+ * await client.user.update({
1158
+ * where: { id: 1 },
1159
+ * data: {
1160
+ * posts: {
1161
+ * update: { where: { id: 1 }, data: { title: 'Hello World' } }
1162
+ * }
1163
+ * }
1164
+ * });
1165
+ *
1166
+ * // upsert a relation
1167
+ * await client.user.update({
1168
+ * where: { id: 1 },
1169
+ * data: {
1170
+ * posts: {
1171
+ * upsert: {
1172
+ * where: { id: 1 },
1173
+ * create: { title: 'Hello World' },
1174
+ * update: { title: 'Hello World' }
1175
+ * }
1176
+ * }
1177
+ * }
1178
+ * });
1179
+ *
1180
+ * // update many related entities (only available for one-to-many relations)
1181
+ * await client.user.update({
1182
+ * where: { id: 1 },
1183
+ * data: {
1184
+ * posts: {
1185
+ * updateMany: {
1186
+ * where: { published: true },
1187
+ * data: { title: 'Hello World' }
1188
+ * }
1189
+ * }
1190
+ * }
1191
+ * });
1192
+ *
1193
+ * // delete a one-to-many relation
1194
+ * await client.user.update({
1195
+ * where: { id: 1 },
1196
+ * data: { posts: { delete: { id: 1 } } }
1197
+ * });
1198
+ *
1199
+ * // delete a one-to-one relation
1200
+ * await client.user.update({
1201
+ * where: { id: 1 },
1202
+ * data: { profile: { delete: true } }
1203
+ * });
1204
+ * ```
1208
1205
  */
1209
- get $auth(): AuthType<Schema> | undefined;
1206
+ update<T extends UpdateArgs<Schema, Model>>(args: SelectSubset<T, UpdateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1210
1207
  /**
1211
- * Sets the current user identity.
1208
+ * Updates multiple entities.
1209
+ * @param args - update args. Only scalar fields are allowed for data.
1210
+ * @returns count of updated entities: `{ count: number }`
1211
+ *
1212
+ * @example
1213
+ * ```ts
1214
+ * // update many entities
1215
+ * await client.user.updateMany({
1216
+ * where: { email: { endsWith: '@zenstack.dev' } },
1217
+ * data: { role: 'ADMIN' }
1218
+ * });
1219
+ *
1220
+ * // limit the number of updated entities
1221
+ * await client.user.updateMany({
1222
+ * where: { email: { endsWith: '@zenstack.dev' } },
1223
+ * data: { role: 'ADMIN' },
1224
+ * limit: 10
1225
+ * });
1212
1226
  */
1213
- $setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema>;
1227
+ updateMany<T extends UpdateManyArgs<Schema, Model>>(args: Subset<T, UpdateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
1214
1228
  /**
1215
- * The Kysely query builder instance.
1229
+ * Updates multiple entities and returns them.
1230
+ * @param args - update args. Only scalar fields are allowed for data.
1231
+ * @returns the updated entities
1232
+ *
1233
+ * @example
1234
+ * ```ts
1235
+ * // update many entities and return selected fields
1236
+ * await client.user.updateManyAndReturn({
1237
+ * where: { email: { endsWith: '@zenstack.dev' } },
1238
+ * data: { role: 'ADMIN' },
1239
+ * select: { id: true, email: true }
1240
+ * }); // result: `Array<{ id: string; email: string }>`
1241
+ *
1242
+ * // limit the number of updated entities
1243
+ * await client.user.updateManyAndReturn({
1244
+ * where: { email: { endsWith: '@zenstack.dev' } },
1245
+ * data: { role: 'ADMIN' },
1246
+ * limit: 10
1247
+ * });
1248
+ * ```
1216
1249
  */
1217
- readonly $qb: ToKysely<Schema>;
1250
+ updateManyAndReturn<T extends UpdateManyAndReturnArgs<Schema, Model>>(args: Subset<T, UpdateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
1218
1251
  /**
1219
- * The raw Kysely query builder without any ZenStack enhancements.
1252
+ * Creates or updates an entity.
1253
+ * @param args - upsert args
1254
+ * @returns the upserted entity
1255
+ *
1256
+ * @example
1257
+ * ```ts
1258
+ * // upsert an entity
1259
+ * await client.user.upsert({
1260
+ * // `where` clause is used to find the entity
1261
+ * where: { id: 1 },
1262
+ * // `create` clause is used if the entity is not found
1263
+ * create: { email: 'alex@zenstack.dev', name: 'Alex' },
1264
+ * // `update` clause is used if the entity is found
1265
+ * update: { name: 'Alex-new' },
1266
+ * // `select` and `omit` can be used to control the returned fields
1267
+ * ...
1268
+ * });
1269
+ * ```
1220
1270
  */
1221
- readonly $qbRaw: ToKysely<any>;
1271
+ upsert<T extends UpsertArgs<Schema, Model>>(args: SelectSubset<T, UpsertArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
1222
1272
  /**
1223
- * Starts a transaction.
1273
+ * Deletes a uniquely identifiable entity.
1274
+ * @param args - delete args
1275
+ * @returns the deleted entity. Throws `NotFoundError` if the entity is not found.
1276
+ *
1277
+ * @example
1278
+ * ```ts
1279
+ * // delete an entity
1280
+ * await client.user.delete({
1281
+ * where: { id: 1 }
1282
+ * });
1283
+ *
1284
+ * // delete an entity and return selected fields
1285
+ * await client.user.delete({
1286
+ * where: { id: 1 },
1287
+ * select: { id: true, email: true }
1288
+ * }); // result: `{ id: string; email: string }`
1289
+ * ```
1224
1290
  */
1225
- $transaction<T>(callback: (tx: ClientContract<Schema>) => Promise<T>): Promise<T>;
1291
+ delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model>>>;
1226
1292
  /**
1227
- * Returns a new client with the specified plugin installed.
1293
+ * Deletes multiple entities.
1294
+ * @param args - delete args
1295
+ * @returns count of deleted entities: `{ count: number }`
1296
+ *
1297
+ * @example
1298
+ * ```ts
1299
+ * // delete many entities
1300
+ * await client.user.deleteMany({
1301
+ * where: { email: { endsWith: '@zenstack.dev' } }
1302
+ * });
1303
+ *
1304
+ * // limit the number of deleted entities
1305
+ * await client.user.deleteMany({
1306
+ * where: { email: { endsWith: '@zenstack.dev' } },
1307
+ * limit: 10
1308
+ * });
1309
+ * ```
1228
1310
  */
1229
- $use(plugin: RuntimePlugin<Schema>): ClientContract<Schema>;
1311
+ deleteMany<T extends DeleteManyArgs<Schema, Model>>(args?: Subset<T, DeleteManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
1230
1312
  /**
1231
- * Returns a new client with all plugins removed.
1313
+ * Counts rows or field values.
1314
+ * @param args - count args
1315
+ * @returns `number`, or an object containing count of selected relations
1316
+ *
1317
+ * @example
1318
+ * ```ts
1319
+ * // count all
1320
+ * await client.user.count();
1321
+ *
1322
+ * // count with a filter
1323
+ * await client.user.count({ where: { email: { endsWith: '@zenstack.dev' } } });
1324
+ *
1325
+ * // count rows and field values
1326
+ * await client.user.count({
1327
+ * select: { _all: true, email: true }
1328
+ * }); // result: `{ _all: number, email: number }`
1232
1329
  */
1233
- $unuseAll(): ClientContract<Schema>;
1330
+ count<T extends CountArgs<Schema, Model>>(args?: Subset<T, CountArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<CountResult<Schema, Model, T>>>;
1234
1331
  /**
1235
- * Disconnects the underlying Kysely instance from the database.
1332
+ * Aggregates rows.
1333
+ * @param args - aggregation args
1334
+ * @returns an object containing aggregated values
1335
+ *
1336
+ * @example
1337
+ * ```ts
1338
+ * // aggregate rows
1339
+ * await client.profile.aggregate({
1340
+ * where: { email: { endsWith: '@zenstack.dev' } },
1341
+ * _count: true,
1342
+ * _avg: { age: true },
1343
+ * _sum: { age: true },
1344
+ * _min: { age: true },
1345
+ * _max: { age: true }
1346
+ * }); // result: `{ _count: number, _avg: { age: number }, ... }`
1236
1347
  */
1237
- $disconnect(): Promise<void>;
1348
+ aggregate<T extends AggregateArgs<Schema, Model>>(args: Subset<T, AggregateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<AggregateResult<Schema, Model, T>>>;
1238
1349
  /**
1239
- * Pushes the schema to the database. For testing purposes only.
1240
- * @private
1350
+ * Groups rows by columns.
1351
+ * @param args - groupBy args
1352
+ * @returns an object containing grouped values
1353
+ *
1354
+ * @example
1355
+ * ```ts
1356
+ * // group by a field
1357
+ * await client.profile.groupBy({
1358
+ * by: 'country',
1359
+ * _count: true
1360
+ * }); // result: `Array<{ country: string, _count: number }>`
1361
+ *
1362
+ * // group by multiple fields
1363
+ * await client.profile.groupBy({
1364
+ * by: ['country', 'city'],
1365
+ * _count: true
1366
+ * }); // result: `Array<{ country: string, city: string, _count: number }>`
1367
+ *
1368
+ * // group by with sorting, the `orderBy` fields must be in the `by` list
1369
+ * await client.profile.groupBy({
1370
+ * by: 'country',
1371
+ * orderBy: { country: 'desc' }
1372
+ * });
1373
+ *
1374
+ * // group by with having (post-aggregation filter), the `having` fields must
1375
+ * // be in the `by` list
1376
+ * await client.profile.groupBy({
1377
+ * by: 'country',
1378
+ * having: { country: 'US' }
1379
+ * });
1241
1380
  */
1242
- $pushSchema(): Promise<void>;
1243
- } & {
1244
- [Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key>;
1245
- } & Procedures<Schema>;
1246
- type MapType<Schema extends SchemaDef, T extends string> = T extends 'String' ? string : T extends 'Int' ? number : T extends 'Float' ? number : T extends 'BigInt' ? bigint : T extends 'Decimal' ? Decimal$1 : T extends 'Boolean' ? boolean : T extends 'DateTime' ? Date : T extends GetModels<Schema> ? ModelResult<Schema, T> : unknown;
1247
- type Procedures<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
1248
- $procedures: {
1249
- [Key in keyof Schema['procedures']]: ProcedureFunc<Schema, Schema['procedures'][Key]>;
1250
- };
1251
- } : {};
1252
- type ProcedureFunc<Schema extends SchemaDef, Proc extends ProcedureDef> = (...args: MapProcedureParams<Schema, Proc['params']>) => Promise<MapType<Schema, Proc['returnType']>>;
1253
- type MapProcedureParams<Schema extends SchemaDef, Params> = {
1254
- [P in keyof Params]: Params[P] extends {
1255
- type: infer U;
1256
- } ? OrUndefinedIf<MapType<Schema, U & string>, Params[P] extends {
1257
- optional: true;
1258
- } ? true : false> : never;
1259
- };
1260
- /**
1261
- * Creates a new ZenStack client instance.
1262
- */
1263
- interface ClientConstructor {
1264
- new <Schema extends SchemaDef>(schema: HasComputedFields<Schema> extends false ? Schema : never): ClientContract<Schema>;
1265
- new <Schema extends SchemaDef>(schema: Schema, options: ClientOptions<Schema>): ClientContract<Schema>;
1381
+ groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
1266
1382
  }
1267
- /**
1268
- * CRUD operations.
1269
- */
1270
- type CRUD = 'create' | 'read' | 'update' | 'delete';
1271
1383
 
1272
- export type { UpdateInput as A, BatchResult as B, ClientConstructor as C, DateTimeFilter as D, DeleteArgs as E, FindArgs as F, DeleteManyArgs as G, CountArgs as H, CountAggregateInput as I, CountResult as J, AggregateArgs as K, AggregateResult as L, ModelResult as M, NumberFilter as N, OrderBy as O, GroupByArgs as P, GroupByResult as Q, ModelOperations as R, StringFilter as S, ToKysely as T, UpdateArgs as U, RuntimePlugin as V, WhereInput as W, OnKyselyQueryArgs as X, ClientContract as a, ClientOptions as b, CliGenerator as c, CommonPrimitiveFilter as d, BytesFilter as e, BooleanFilter as f, SortOrder as g, NullsOrder as h, WhereUniqueInput as i, SelectIncludeOmit as j, Subset as k, SelectSubset as l, MapFieldType as m, OptionalFieldsForCreate as n, OppositeRelationFields as o, OppositeRelationAndFK as p, FindUniqueArgs as q, CreateArgs as r, CreateManyArgs as s, CreateManyAndReturnArgs as t, CreateInput as u, UpdateManyArgs as v, UpdateManyAndReturnArgs as w, UpsertArgs as x, UpdateScalarInput as y, UpdateRelationInput as z };
1384
+ export { type DeleteManyArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type CountArgs as E, type FindArgs as F, type CountResult as G, type AggregateArgs as H, type IncludeInput as I, type JsonArray as J, type AggregateResult as K, type GroupByArgs as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByResult as P, type OnKyselyQueryArgs as Q, type RuntimePlugin as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, type WhereInput as W, type JsonObject as a, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type StringFilter as f, type BytesFilter as g, type BooleanFilter as h, type SortOrder as i, type NullsOrder as j, type WhereUniqueInput as k, type OmitInput as l, type SelectIncludeOmit as m, type SelectInput as n, type Subset as o, type SelectSubset as p, type FindManyArgs as q, type FindFirstArgs as r, type FindUniqueArgs as s, type CreateArgs as t, type CreateManyArgs as u, type CreateManyAndReturnArgs as v, type UpdateManyArgs as w, type UpdateManyAndReturnArgs as x, type UpsertArgs as y, type DeleteArgs as z };