@zenstackhq/orm 3.2.0 → 3.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,9 +1,78 @@
1
1
  import * as _zenstackhq_schema from '@zenstackhq/schema';
2
- import { SchemaDef, BuiltinType, GetModels, FieldDef, ModelDef, DataSourceProviderType, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, GetModel, ProcedureDef, NonRelationFields, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetTypeDefFieldType, TypeDefFieldIsArray, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
2
+ import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, FieldDef, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetModel, BuiltinType, GetTypeDefFieldType, TypeDefFieldIsArray, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, ProcedureDef, ModelDef, DataSourceProviderType, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
3
3
  import * as kysely from 'kysely';
4
- import { OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Kysely, ExpressionBuilder, SelectQueryBuilder, Expression, SqlBool, ExpressionWrapper, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig, OperandExpression } from 'kysely';
4
+ import { OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Kysely, Generated, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
5
5
  import Decimal from 'decimal.js';
6
- import { z } from 'zod';
6
+ import { z, ZodObject } from 'zod';
7
+
8
+ type JsonValue = string | number | boolean | JsonObject | JsonArray;
9
+ type JsonObject = {
10
+ [key: string]: JsonValue | null;
11
+ };
12
+ type JsonArray = ReadonlyArray<JsonValue | null>;
13
+ type JsonNullValues = DbNull | JsonNull | AnyNull;
14
+ declare class DbNullClass {
15
+ private __brand;
16
+ }
17
+ declare const DbNull: DbNullClass;
18
+ type DbNull = typeof DbNull;
19
+ declare class JsonNullClass {
20
+ private __brand;
21
+ }
22
+ declare const JsonNull: JsonNullClass;
23
+ type JsonNull = typeof JsonNull;
24
+ declare class AnyNullClass {
25
+ private __brand;
26
+ }
27
+ declare const AnyNull: AnyNullClass;
28
+ type AnyNull = typeof AnyNull;
29
+
30
+ type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
31
+ type PartialIf<T, Condition extends boolean> = Condition extends true ? Partial<T> : T;
32
+ type NullableIf<T, Condition extends boolean> = Condition extends true ? T | null : T;
33
+ type _Preserve = Date | Function | Decimal | Uint8Array | JsonObject | JsonValue;
34
+ type _Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
35
+ type Simplify<T, D extends number = 6> = D extends 0 ? T : T extends object ? T extends _Preserve ? T : {
36
+ [K in keyof T]: Simplify<T[K], _Depth[D]>;
37
+ } & {} : T;
38
+ type WrapType<T, Optional = false, Array = false> = Array extends true ? Optional extends true ? T[] | null : T[] : Optional extends true ? T | null : T;
39
+ type TypeMap = {
40
+ String: string;
41
+ Boolean: boolean;
42
+ Int: number;
43
+ Float: number;
44
+ BigInt: bigint;
45
+ Decimal: Decimal;
46
+ DateTime: Date;
47
+ Bytes: Uint8Array;
48
+ Json: JsonValue;
49
+ Null: null;
50
+ Object: Record<string, unknown>;
51
+ Any: unknown;
52
+ Unsupported: unknown;
53
+ Void: void;
54
+ Undefined: undefined;
55
+ };
56
+ type MapBaseType$1<T extends string> = T extends keyof TypeMap ? TypeMap[T] : unknown;
57
+ type OrArray<T, IF extends boolean = true> = IF extends true ? T | T[] : T;
58
+ type NonEmptyArray<T> = [T, ...T[]];
59
+ type ValueOfPotentialTuple<T> = T extends unknown[] ? T[number] : T;
60
+ type NoExpand<T> = T extends unknown ? T : never;
61
+ type AtLeast<O extends object, K extends string> = NoExpand<O extends unknown ? (K extends keyof O ? {
62
+ [P in K]: O[P];
63
+ } & O : O) | ({
64
+ [P in keyof O as P extends K ? K : never]-?: O[P];
65
+ } & O) : never>;
66
+ type Without<T, U> = {
67
+ [P in Exclude<keyof T, keyof U>]?: never;
68
+ };
69
+ type XOR<T, U> = T extends object ? (U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U) : T;
70
+ type MaybePromise<T> = T | Promise<T>;
71
+ type PrependParameter<Param, Func> = Func extends (...args: any[]) => infer R ? (p: Param, ...args: Parameters<Func>) => R : never;
72
+ type OrUndefinedIf<T, Condition extends boolean> = Condition extends true ? T | undefined : T;
73
+ type UnwrapTuplePromises<T extends readonly unknown[]> = {
74
+ [K in keyof T]: Awaited<T[K]>;
75
+ };
7
76
 
8
77
  declare class DefaultOperationNodeVisitor extends OperationNodeVisitor {
9
78
  protected defaultVisit(node: OperationNode): void;
@@ -114,75 +183,6 @@ declare namespace kyselyUtils {
114
183
  export { type kyselyUtils_AnyKysely as AnyKysely, kyselyUtils_DefaultOperationNodeVisitor as DefaultOperationNodeVisitor };
115
184
  }
116
185
 
117
- type JsonValue = string | number | boolean | JsonObject | JsonArray;
118
- type JsonObject = {
119
- [key: string]: JsonValue | null;
120
- };
121
- type JsonArray = ReadonlyArray<JsonValue | null>;
122
- type JsonNullValues = DbNull | JsonNull | AnyNull;
123
- declare class DbNullClass {
124
- private __brand;
125
- }
126
- declare const DbNull: DbNullClass;
127
- type DbNull = typeof DbNull;
128
- declare class JsonNullClass {
129
- private __brand;
130
- }
131
- declare const JsonNull: JsonNullClass;
132
- type JsonNull = typeof JsonNull;
133
- declare class AnyNullClass {
134
- private __brand;
135
- }
136
- declare const AnyNull: AnyNullClass;
137
- type AnyNull = typeof AnyNull;
138
-
139
- type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
140
- type PartialIf<T, Condition extends boolean> = Condition extends true ? Partial<T> : T;
141
- type NullableIf<T, Condition extends boolean> = Condition extends true ? T | null : T;
142
- type _Preserve = Date | Function | Decimal | Uint8Array | JsonObject | JsonValue;
143
- type _Depth = [never, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
144
- type Simplify<T, D extends number = 6> = D extends 0 ? T : T extends object ? T extends _Preserve ? T : {
145
- [K in keyof T]: Simplify<T[K], _Depth[D]>;
146
- } & {} : T;
147
- type WrapType<T, Optional = false, Array = false> = Array extends true ? Optional extends true ? T[] | null : T[] : Optional extends true ? T | null : T;
148
- type TypeMap = {
149
- String: string;
150
- Boolean: boolean;
151
- Int: number;
152
- Float: number;
153
- BigInt: bigint;
154
- Decimal: Decimal;
155
- DateTime: Date;
156
- Bytes: Uint8Array;
157
- Json: JsonValue;
158
- Null: null;
159
- Object: Record<string, unknown>;
160
- Any: unknown;
161
- Unsupported: unknown;
162
- Void: void;
163
- Undefined: undefined;
164
- };
165
- type MapBaseType$1<T extends string> = T extends keyof TypeMap ? TypeMap[T] : unknown;
166
- type OrArray<T, IF extends boolean = true> = IF extends true ? T | T[] : T;
167
- type NonEmptyArray<T> = [T, ...T[]];
168
- type ValueOfPotentialTuple<T> = T extends unknown[] ? T[number] : T;
169
- type NoExpand<T> = T extends unknown ? T : never;
170
- type AtLeast<O extends object, K extends string> = NoExpand<O extends unknown ? (K extends keyof O ? {
171
- [P in K]: O[P];
172
- } & O : O) | ({
173
- [P in keyof O as P extends K ? K : never]-?: O[P];
174
- } & O) : never>;
175
- type Without<T, U> = {
176
- [P in Exclude<keyof T, keyof U>]?: never;
177
- };
178
- type XOR<T, U> = T extends object ? (U extends object ? (Without<T, U> & U) | (Without<U, T> & T) : U) : T;
179
- type MaybePromise<T> = T | Promise<T>;
180
- type PrependParameter<Param, Func> = Func extends (...args: any[]) => infer R ? (p: Param, ...args: Parameters<Func>) => R : never;
181
- type OrUndefinedIf<T, Condition extends boolean> = Condition extends true ? T | undefined : T;
182
- type UnwrapTuplePromises<T extends readonly unknown[]> = {
183
- [K in keyof T]: Awaited<T[K]>;
184
- };
185
-
186
186
  /**
187
187
  * Client API methods that are not supported in transactions.
188
188
  */
@@ -197,118 +197,6 @@ declare const LOGICAL_COMBINATORS: readonly ["AND", "OR", "NOT"];
197
197
  declare const AGGREGATE_OPERATORS: readonly ["_count", "_sum", "_avg", "_min", "_max"];
198
198
  type AGGREGATE_OPERATORS = (typeof AGGREGATE_OPERATORS)[number];
199
199
 
200
- declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
201
- protected readonly schema: Schema;
202
- protected readonly options: ClientOptions<Schema>;
203
- protected eb: ExpressionBuilder<any, any>;
204
- constructor(schema: Schema, options: ClientOptions<Schema>);
205
- transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
206
- transformOutput(value: unknown, _type: BuiltinType, _array: boolean): unknown;
207
- buildSelectModel(model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
208
- buildFilterSortTake(model: string, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
209
- buildFilter(model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
210
- private buildCursorFilter;
211
- private isLogicalCombinator;
212
- protected buildCompositeFilter(model: string, modelAlias: string, key: (typeof LOGICAL_COMBINATORS)[number], payload: any): Expression<SqlBool>;
213
- private buildRelationFilter;
214
- private buildToOneRelationFilter;
215
- private buildToManyRelationFilter;
216
- private buildArrayFilter;
217
- buildPrimitiveFilter(fieldRef: Expression<any>, fieldDef: FieldDef, payload: any): any;
218
- private buildJsonFilter;
219
- private buildPlainJsonFilter;
220
- private buildTypedJsonFilter;
221
- private buildTypedJsonArrayFilter;
222
- private buildTypeJsonNonArrayFilter;
223
- private buildJsonValueFilterClause;
224
- private buildLiteralFilter;
225
- private buildStandardFilter;
226
- private buildStringFilter;
227
- private buildJsonStringFilter;
228
- private escapeLikePattern;
229
- private buildStringLike;
230
- private prepStringCasing;
231
- private buildNumberFilter;
232
- private buildBooleanFilter;
233
- private buildDateTimeFilter;
234
- private buildBytesFilter;
235
- private buildEnumFilter;
236
- buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, negated: boolean): SelectQueryBuilder<any, any, any>;
237
- buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined | null, modelAlias: string): SelectQueryBuilder<any, any, any>;
238
- shouldOmitField(omit: unknown, model: string, field: string): any;
239
- protected buildModelSelect(model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
240
- buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
241
- buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
242
- buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): ExpressionWrapper<any, any, unknown>;
243
- private negateSort;
244
- true(): Expression<SqlBool>;
245
- false(): Expression<SqlBool>;
246
- isTrue(expression: Expression<SqlBool>): boolean;
247
- isFalse(expression: Expression<SqlBool>): boolean;
248
- and(...args: Expression<SqlBool>[]): Expression<SqlBool>;
249
- or(...args: Expression<SqlBool>[]): Expression<SqlBool>;
250
- not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
251
- fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean): any;
252
- protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
253
- abstract get provider(): DataSourceProviderType;
254
- /**
255
- * Builds selection for a relation field.
256
- */
257
- abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>): SelectQueryBuilder<any, any, any>;
258
- /**
259
- * Builds skip and take clauses.
260
- */
261
- abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
262
- /**
263
- * Builds an Kysely expression that returns a JSON object for the given key-value pairs.
264
- */
265
- abstract buildJsonObject(value: Record<string, Expression<unknown>>): ExpressionWrapper<any, any, unknown>;
266
- /**
267
- * Builds an Kysely expression that returns the length of an array.
268
- */
269
- abstract buildArrayLength(array: Expression<unknown>): ExpressionWrapper<any, any, number>;
270
- /**
271
- * Builds an array literal SQL string for the given values.
272
- */
273
- abstract buildArrayLiteralSQL(values: unknown[]): string;
274
- /**
275
- * Whether the dialect supports updating with a limit on the number of updated rows.
276
- */
277
- abstract get supportsUpdateWithLimit(): boolean;
278
- /**
279
- * Whether the dialect supports deleting with a limit on the number of deleted rows.
280
- */
281
- abstract get supportsDeleteWithLimit(): boolean;
282
- /**
283
- * Whether the dialect supports DISTINCT ON.
284
- */
285
- abstract get supportsDistinctOn(): boolean;
286
- /**
287
- * Whether the dialect support inserting with `DEFAULT` as field value.
288
- */
289
- abstract get supportInsertWithDefault(): boolean;
290
- /**
291
- * Gets the SQL column type for the given field definition.
292
- */
293
- abstract getFieldSqlType(fieldDef: FieldDef): string;
294
- abstract getStringCasingBehavior(): {
295
- supportsILike: boolean;
296
- likeCaseSensitive: boolean;
297
- };
298
- /**
299
- * Builds a JSON path selection expression.
300
- */
301
- protected abstract buildJsonPathSelection(receiver: Expression<any>, path: string | undefined): Expression<any>;
302
- /**
303
- * Builds a JSON array filter expression.
304
- */
305
- protected abstract buildJsonArrayFilter(receiver: Expression<any>, operation: 'array_contains' | 'array_starts_with' | 'array_ends_with', value: unknown): Expression<SqlBool>;
306
- /**
307
- * Builds a JSON array exists predicate (returning if any element matches the filter).
308
- */
309
- protected abstract buildJsonArrayExistsPredicate(receiver: Expression<any>, buildFilter: (elem: Expression<any>) => Expression<SqlBool>): Expression<SqlBool>;
310
- }
311
-
312
200
  type ToKyselySchema<Schema extends SchemaDef> = {
313
201
  [Model in GetModels<Schema>]: ToKyselyTable<Schema, Model>;
314
202
  };
@@ -321,476 +209,252 @@ type WrapNull<T, Null> = Null extends true ? T | null : T;
321
209
  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>>;
322
210
  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>;
323
211
 
324
- declare class InputValidator<Schema extends SchemaDef> {
325
- private readonly client;
326
- constructor(client: ClientContract<Schema>);
327
- private get schema();
328
- private get options();
329
- private get extraValidationsEnabled();
330
- validateProcedureInput(proc: string, input: unknown): unknown;
331
- private makeProcedureParamSchema;
332
- validateFindArgs(model: GetModels<Schema>, args: unknown, options: {
333
- unique: boolean;
334
- findOne: boolean;
335
- }): FindArgs<Schema, GetModels<Schema>, true> | undefined;
336
- validateExistsArgs(model: GetModels<Schema>, args: unknown): ExistsArgs<Schema, GetModels<Schema>> | undefined;
337
- validateCreateArgs(model: GetModels<Schema>, args: unknown): CreateArgs<Schema, GetModels<Schema>>;
338
- validateCreateManyArgs(model: GetModels<Schema>, args: unknown): CreateManyArgs<Schema, GetModels<Schema>>;
339
- validateCreateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): CreateManyAndReturnArgs<Schema, GetModels<Schema>> | undefined;
340
- validateUpdateArgs(model: GetModels<Schema>, args: unknown): UpdateArgs<Schema, GetModels<Schema>>;
341
- validateUpdateManyArgs(model: GetModels<Schema>, args: unknown): UpdateManyArgs<Schema, GetModels<Schema>>;
342
- validateUpdateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): UpdateManyAndReturnArgs<Schema, GetModels<Schema>>;
343
- validateUpsertArgs(model: GetModels<Schema>, args: unknown): UpsertArgs<Schema, GetModels<Schema>>;
344
- validateDeleteArgs(model: GetModels<Schema>, args: unknown): DeleteArgs<Schema, GetModels<Schema>>;
345
- validateDeleteManyArgs(model: GetModels<Schema>, args: unknown): DeleteManyArgs<Schema, GetModels<Schema>> | undefined;
346
- validateCountArgs(model: GetModels<Schema>, args: unknown): CountArgs<Schema, GetModels<Schema>> | undefined;
347
- validateAggregateArgs(model: GetModels<Schema>, args: unknown): AggregateArgs<Schema, GetModels<Schema>>;
348
- validateGroupByArgs(model: GetModels<Schema>, args: unknown): GroupByArgs<Schema, GetModels<Schema>>;
349
- private getSchemaCache;
350
- private setSchemaCache;
351
- private validate;
352
- private makeFindSchema;
353
- private makeExistsSchema;
354
- private makeScalarSchema;
355
- private makeEnumSchema;
356
- private makeTypeDefSchema;
357
- private makeWhereSchema;
358
- private makeTypedJsonFilterSchema;
359
- private isTypeDefType;
360
- private makeEnumFilterSchema;
361
- private makeArrayFilterSchema;
362
- private internalMakeArrayFilterSchema;
363
- private makePrimitiveFilterSchema;
364
- private makeJsonValueSchema;
365
- private makeJsonFilterSchema;
366
- private makeDateTimeFilterSchema;
367
- private makeBooleanFilterSchema;
368
- private makeBytesFilterSchema;
369
- private makeCommonPrimitiveFilterComponents;
370
- private makeCommonPrimitiveFilterSchema;
371
- private makeNumberFilterSchema;
372
- private makeStringFilterSchema;
373
- private makeStringModeSchema;
374
- private makeSelectSchema;
375
- private makeCountSelectionSchema;
376
- private makeRelationSelectIncludeSchema;
377
- private makeOmitSchema;
378
- private makeIncludeSchema;
379
- private makeOrderBySchema;
380
- private makeDistinctSchema;
381
- private makeCursorSchema;
382
- private makeCreateSchema;
383
- private makeCreateManySchema;
384
- private makeCreateManyAndReturnSchema;
385
- private makeCreateDataSchema;
386
- private isDelegateDiscriminator;
387
- private makeRelationManipulationSchema;
388
- private makeSetDataSchema;
389
- private makeConnectDataSchema;
390
- private makeDisconnectDataSchema;
391
- private makeDeleteRelationDataSchema;
392
- private makeConnectOrCreateDataSchema;
393
- private makeCreateManyDataSchema;
394
- private makeUpdateSchema;
395
- private makeUpdateManySchema;
396
- private makeUpdateManyAndReturnSchema;
397
- private makeUpsertSchema;
398
- private makeUpdateDataSchema;
399
- private makeDeleteSchema;
400
- private makeDeleteManySchema;
401
- makeCountSchema(model: GetModels<Schema>): z.ZodOptional<z.ZodObject<{
402
- where: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
403
- skip: z.ZodOptional<z.ZodNumber>;
404
- take: z.ZodOptional<z.ZodNumber>;
405
- orderBy: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>> | z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>, z.ZodArray<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>]>>;
406
- select: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
407
- _all: z.ZodOptional<z.ZodLiteral<true>>;
408
- }, z.core.$strict>]>>;
409
- }, z.core.$strip>>;
410
- private makeCountAggregateInputSchema;
411
- makeAggregateSchema(model: GetModels<Schema>): z.ZodOptional<z.ZodObject<{
412
- where: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
413
- skip: z.ZodOptional<z.ZodNumber>;
414
- take: z.ZodOptional<z.ZodNumber>;
415
- orderBy: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>> | z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>, z.ZodArray<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>]>>;
416
- _count: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
417
- _all: z.ZodOptional<z.ZodLiteral<true>>;
418
- }, z.core.$strict>]>>;
419
- _avg: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
420
- _sum: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
421
- _min: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
422
- _max: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
423
- }, z.core.$strip>>;
424
- makeSumAvgInputSchema(model: GetModels<Schema>): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
425
- makeMinMaxInputSchema(model: GetModels<Schema>): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
426
- private makeGroupBySchema;
427
- private onlyAggregationFields;
428
- private makeHavingSchema;
429
- private makeSkipSchema;
430
- private makeTakeSchema;
431
- private refineForSelectIncludeMutuallyExclusive;
432
- private refineForSelectOmitMutuallyExclusive;
433
- private nullableIf;
434
- private orArray;
435
- private isNumericField;
436
- private get providerSupportsCaseSensitivity();
437
- }
438
-
439
- type CoreCrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy' | 'exists';
440
- type AllCrudOperation = CoreCrudOperation | 'findUniqueOrThrow' | 'findFirstOrThrow';
441
-
442
- /**
443
- * ZenStack runtime plugin.
444
- */
445
- interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
446
- /**
447
- * Plugin ID.
448
- */
449
- id: string;
212
+ type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<{
213
+ [Key in NonRelationFields<Schema, Model> as ShouldOmitField<Schema, Model, Options, Key, Omit> extends true ? never : Key]: MapModelFieldType<Schema, Model, Key>;
214
+ }, Optional, Array>;
215
+ type ShouldOmitField<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = QueryLevelOmit<Schema, Model, Field, Omit> extends boolean ? QueryLevelOmit<Schema, Model, Field, Omit> : OptionsLevelOmit<Schema, Model, Field, Options> extends boolean ? OptionsLevelOmit<Schema, Model, Field, Options> : SchemaLevelOmit<Schema, Model, Field>;
216
+ type QueryLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = Field extends keyof Omit ? (Omit[Field] extends boolean ? Omit[Field] : undefined) : undefined;
217
+ type OptionsLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>> = Model extends keyof Options['omit'] ? Field extends keyof Options['omit'][Model] ? Options['omit'][Model][Field] extends boolean ? Options['omit'][Model][Field] : undefined : undefined : undefined;
218
+ type SchemaLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['omit'] extends true ? true : false;
219
+ type ModelSelectResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Select, Omit, Options extends QueryOptions<Schema>> = {
220
+ [Key in keyof Select as Select[Key] extends false | undefined ? never : Key extends '_count' ? Select[Key] extends SelectCount<Schema, Model> ? Key : never : Key extends keyof Omit ? Omit[Key] extends true ? never : Key : Key]: Key extends '_count' ? SelectCountResult<Schema, Model, Select[Key]> : Key extends NonRelationFields<Schema, Model> ? MapModelFieldType<Schema, Model, Key> : Key extends RelationFields<Schema, Model> ? ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Select[Key], Options, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : never;
221
+ };
222
+ type SelectCountResult<Schema extends SchemaDef, Model extends GetModels<Schema>, C> = C extends true ? {
223
+ [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: number;
224
+ } : C extends {
225
+ select: infer S;
226
+ } ? {
227
+ [Key in keyof S]: number;
228
+ } : never;
229
+ type ModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<Args extends {
230
+ select: infer S extends object;
231
+ omit?: infer O extends object;
232
+ } & Record<string, unknown> ? ModelSelectResult<Schema, Model, S, O, Options> : Args extends {
233
+ include: infer I extends object;
234
+ omit?: infer O extends object;
235
+ } & Record<string, unknown> ? // select all non-omitted scalar fields
236
+ DefaultModelResult<Schema, Model, O, Options, false, false> & {
237
+ [Key in keyof I & RelationFields<Schema, Model> as I[Key] extends false | undefined ? never : Key]: ModelResult<Schema, RelationFieldType<Schema, Model, Key>, I[Key], Options, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>>;
238
+ } & ('_count' extends keyof I ? I['_count'] extends false | undefined ? {} : {
239
+ _count: SelectCountResult<Schema, Model, I['_count']>;
240
+ } : {}) : Args extends {
241
+ omit: infer O;
242
+ } & Record<string, unknown> ? DefaultModelResult<Schema, Model, O, Options, false, false> : DefaultModelResult<Schema, Model, undefined, Options, false, false>, Optional, Array>;
243
+ type SimplifiedResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = Simplify<ModelResult<Schema, Model, Args, Options, Optional, Array>>;
244
+ type SimplifiedPlainResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Simplify<ModelResult<Schema, Model, Args, Options, false, false>>;
245
+ type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = PartialIf<Optional<{
246
+ [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial>;
247
+ }, Partial extends true ? never : keyof {
248
+ [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true;
249
+ }>, Partial> & Record<string, unknown>;
250
+ type BatchResult = {
251
+ count: number;
252
+ };
253
+ type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ScalarOnly extends boolean = false, WithAggregations extends boolean = false> = {
254
+ [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> : GetModelFieldType<Schema, Model, Key> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetModelFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>> : PrimitiveFilter<GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>, WithAggregations>;
255
+ } & {
256
+ $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
257
+ } & {
258
+ AND?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
259
+ OR?: WhereInput<Schema, Model, ScalarOnly>[];
260
+ NOT?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
261
+ };
262
+ type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable extends boolean, WithAggregations extends boolean> = NullableIf<keyof GetEnum<Schema, T>, Nullable> | ({
450
263
  /**
451
- * Plugin display name.
264
+ * Checks for equality with the specified enum value.
452
265
  */
453
- name?: string;
266
+ equals?: NullableIf<keyof GetEnum<Schema, T>, Nullable>;
454
267
  /**
455
- * Plugin description.
268
+ * Checks if the enum value is in the specified list of values.
456
269
  */
457
- description?: string;
270
+ in?: (keyof GetEnum<Schema, T>)[];
458
271
  /**
459
- * Custom function implementations.
460
- * @private
272
+ * Checks if the enum value is not in the specified list of values.
461
273
  */
462
- functions?: Record<string, ZModelFunction<Schema>>;
274
+ notIn?: (keyof GetEnum<Schema, T>)[];
463
275
  /**
464
- * Intercepts an ORM query.
276
+ * Builds a negated filter.
465
277
  */
466
- onQuery?: OnQueryCallback<Schema>;
278
+ not?: EnumFilter<Schema, T, Nullable, WithAggregations>;
279
+ } & (WithAggregations extends true ? {
467
280
  /**
468
- * Intercepts a procedure invocation.
281
+ * Filters against the count of records.
469
282
  */
470
- onProcedure?: OnProcedureCallback<Schema>;
283
+ _count?: NumberFilter<'Int', false, false>;
471
284
  /**
472
- * Intercepts an entity mutation.
285
+ * Filters against the minimum value.
473
286
  */
474
- onEntityMutation?: EntityMutationHooksDef<Schema>;
287
+ _min?: EnumFilter<Schema, T, false, false>;
475
288
  /**
476
- * Intercepts a Kysely query.
289
+ * Filters against the maximum value.
477
290
  */
478
- onKyselyQuery?: OnKyselyQueryCallback<Schema>;
479
- }
480
- /**
481
- * Defines a ZenStack runtime plugin.
482
- */
483
- declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
484
-
485
- type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;
486
- type OnProcedureHookContext<Schema extends SchemaDef> = {
291
+ _max?: EnumFilter<Schema, T, false, false>;
292
+ } : {}));
293
+ type ArrayFilter<Schema extends SchemaDef, Type extends string> = {
487
294
  /**
488
- * The procedure name.
295
+ * Checks if the array equals the specified array.
489
296
  */
490
- name: string;
297
+ equals?: MapScalarType<Schema, Type>[] | null;
491
298
  /**
492
- * Whether the procedure is a mutation.
299
+ * Checks if the array contains all elements of the specified array.
493
300
  */
494
- mutation: boolean;
301
+ has?: MapScalarType<Schema, Type> | null;
495
302
  /**
496
- * Procedure invocation input (envelope).
497
- *
498
- * The canonical shape is `{ args?: Record<string, unknown> }`.
499
- * When a procedure has required params, `args` is required.
303
+ * Checks if the array contains any of the elements of the specified array.
500
304
  */
501
- input: unknown;
305
+ hasEvery?: MapScalarType<Schema, Type>[];
502
306
  /**
503
- * Continues the invocation. The input passed here is forwarded to the next handler.
307
+ * Checks if the array contains some of the elements of the specified array.
504
308
  */
505
- proceed: (input: unknown) => Promise<unknown>;
309
+ hasSome?: MapScalarType<Schema, Type>[];
506
310
  /**
507
- * The ZenStack client that is invoking the procedure.
311
+ * Checks if the array is empty.
508
312
  */
509
- client: ClientContract<Schema>;
313
+ isEmpty?: boolean;
510
314
  };
511
- type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
512
- type OnQueryHookContext<Schema extends SchemaDef> = {
315
+ type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
316
+ type PrimitiveFilter<T extends string, Nullable extends boolean, WithAggregations extends boolean> = T extends 'String' ? StringFilter<Nullable, WithAggregations> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable, WithAggregations> : T extends 'Boolean' ? BooleanFilter<Nullable, WithAggregations> : T extends 'DateTime' ? DateTimeFilter<Nullable, WithAggregations> : T extends 'Bytes' ? BytesFilter<Nullable, WithAggregations> : T extends 'Json' ? JsonFilter : never;
317
+ type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean> = {
513
318
  /**
514
- * The model that is being queried.
319
+ * Checks for equality with the specified value.
515
320
  */
516
- model: GetModels<Schema>;
321
+ equals?: NullableIf<DataType, Nullable>;
517
322
  /**
518
- * The operation that is being performed.
323
+ * Checks if the value is in the specified list of values.
519
324
  */
520
- operation: AllCrudOperation;
325
+ in?: DataType[];
521
326
  /**
522
- * The query arguments.
327
+ * Checks if the value is not in the specified list of values.
523
328
  */
524
- args: unknown;
329
+ notIn?: DataType[];
525
330
  /**
526
- * The function to proceed with the original query.
527
- * It takes the same arguments as the operation method.
528
- *
529
- * @param args The query arguments.
331
+ * Checks if the value is less than the specified value.
530
332
  */
531
- proceed: (args: unknown) => Promise<unknown>;
333
+ lt?: DataType;
532
334
  /**
533
- * The ZenStack client that is performing the operation.
335
+ * Checks if the value is less than or equal to the specified value.
534
336
  */
535
- client: ClientContract<Schema>;
536
- };
537
- type EntityMutationHooksDef<Schema extends SchemaDef> = {
337
+ lte?: DataType;
538
338
  /**
539
- * Called before entities are mutated.
339
+ * Checks if the value is greater than the specified value.
540
340
  */
541
- beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
341
+ gt?: DataType;
542
342
  /**
543
- * Called after entities are mutated.
343
+ * Checks if the value is greater than or equal to the specified value.
544
344
  */
545
- afterEntityMutation?: AfterEntityMutationCallback<Schema>;
345
+ gte?: DataType;
546
346
  /**
547
- * Whether to run after-mutation hooks within the transaction that performs the mutation.
548
- *
549
- * If set to `true`, if the mutation already runs inside a transaction, the callbacks are
550
- * executed immediately after the mutation within the transaction boundary. If the mutation
551
- * is not running inside a transaction, a new transaction is created to run both the mutation
552
- * and the callbacks.
553
- *
554
- * If set to `false`, the callbacks are executed after the mutation transaction is committed.
555
- *
556
- * Defaults to `false`.
347
+ * Builds a negated filter.
557
348
  */
558
- runAfterMutationWithinTransaction?: boolean;
349
+ not?: PrimitiveFilter<T, Nullable, WithAggregations>;
559
350
  };
560
- type MutationHooksArgs<Schema extends SchemaDef> = {
351
+ type StringFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<string, Nullable> | (CommonPrimitiveFilter<string, 'String', Nullable, WithAggregations> & {
561
352
  /**
562
- * The model that is being mutated.
353
+ * Checks if the string contains the specified substring.
563
354
  */
564
- model: GetModels<Schema>;
355
+ contains?: string;
565
356
  /**
566
- * The mutation action that is being performed.
567
- */
568
- action: 'create' | 'update' | 'delete';
569
- /**
570
- * The mutation data. Only available for create and update actions.
571
- */
572
- queryNode: OperationNode;
573
- /**
574
- * A query ID that uniquely identifies the mutation operation. You can use it to correlate
575
- * data between the before and after mutation hooks.
576
- */
577
- queryId: QueryId;
578
- };
579
- type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
580
- type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
581
- type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
582
- /**
583
- * Loads the entities that are about to be mutated. The db operation that loads the entities is executed
584
- * within the same transaction context as the mutation.
357
+ * Checks if the string starts with the specified substring.
585
358
  */
586
- loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
359
+ startsWith?: string;
587
360
  /**
588
- * The ZenStack client you can use to perform additional operations. The database operations initiated
589
- * from this client are executed within the same transaction as the mutation if the mutation is running
590
- * inside a transaction.
591
- *
592
- * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
361
+ * Checks if the string ends with the specified substring.
593
362
  */
594
- client: ClientContract<Schema>;
595
- };
596
- type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
363
+ endsWith?: string;
597
364
  /**
598
- * Loads the entities that have been mutated.
365
+ * Specifies the string comparison mode. Not effective for "sqlite" provider
599
366
  */
600
- loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
367
+ mode?: 'default' | 'insensitive';
368
+ } & (WithAggregations extends true ? {
601
369
  /**
602
- * The ZenStack client you can use to perform additional operations.
603
- * See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
604
- *
605
- * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
370
+ * Filters against the count of records.
606
371
  */
607
- client: ClientContract<Schema>;
608
- };
609
- type OnKyselyQueryArgs<Schema extends SchemaDef> = {
610
- schema: SchemaDef;
611
- client: ClientContract<Schema>;
612
- query: RootOperationNode;
613
- proceed: ProceedKyselyQueryFunction;
614
- };
615
- type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
616
- type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
617
-
618
- type ZModelFunctionContext<Schema extends SchemaDef> = {
372
+ _count?: NumberFilter<'Int', false, false>;
619
373
  /**
620
- * ZenStack client instance
374
+ * Filters against the minimum value.
621
375
  */
622
- client: ClientContract<Schema>;
376
+ _min?: StringFilter<false, false>;
623
377
  /**
624
- * Database dialect
378
+ * Filters against the maximum value.
625
379
  */
626
- dialect: BaseCrudDialect<Schema>;
380
+ _max?: StringFilter<false, false>;
381
+ } : {}));
382
+ type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean> = NullableIf<number | bigint, Nullable> | (CommonPrimitiveFilter<number, T, Nullable, WithAggregations> & (WithAggregations extends true ? {
627
383
  /**
628
- * The containing model name
384
+ * Filters against the count of records.
629
385
  */
630
- model: GetModels<Schema>;
386
+ _count?: NumberFilter<'Int', false, false>;
631
387
  /**
632
- * The alias name that can be used to refer to the containing model
388
+ * Filters against the average value.
633
389
  */
634
- modelAlias: string;
390
+ _avg?: NumberFilter<T, false, false>;
635
391
  /**
636
- * The CRUD operation being performed
392
+ * Filters against the sum value.
637
393
  */
638
- operation: CRUD_EXT;
639
- };
640
- type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
641
- /**
642
- * ZenStack client options.
643
- */
644
- type ClientOptions<Schema extends SchemaDef> = {
394
+ _sum?: NumberFilter<T, false, false>;
645
395
  /**
646
- * Kysely dialect.
396
+ * Filters against the minimum value.
647
397
  */
648
- dialect: Dialect;
398
+ _min?: NumberFilter<T, false, false>;
649
399
  /**
650
- * Custom function definitions.
651
- *
652
- * @private
400
+ * Filters against the maximum value.
653
401
  */
654
- functions?: Record<string, ZModelFunction<Schema>>;
402
+ _max?: NumberFilter<T, false, false>;
403
+ } : {}));
404
+ type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Date | string, Nullable> | (CommonPrimitiveFilter<Date | string, 'DateTime', Nullable, WithAggregations> & (WithAggregations extends true ? {
655
405
  /**
656
- * Plugins.
406
+ * Filters against the count of records.
657
407
  */
658
- plugins?: RuntimePlugin<Schema>[];
408
+ _count?: NumberFilter<'Int', false, false>;
659
409
  /**
660
- * Logging configuration.
410
+ * Filters against the minimum value.
661
411
  */
662
- log?: KyselyConfig['log'];
412
+ _min?: DateTimeFilter<false, false>;
663
413
  /**
664
- * Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
665
- * to `true`.
666
- *
667
- * Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
668
- * `Date` object) although for `DateTime` field the data in DB is stored in UTC.
669
- * @see https://github.com/brianc/node-postgres/issues/429
414
+ * Filters against the maximum value.
670
415
  */
671
- fixPostgresTimezone?: boolean;
416
+ _max?: DateTimeFilter<false, false>;
417
+ } : {}));
418
+ type BytesFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Uint8Array | Buffer, Nullable> | ({
672
419
  /**
673
- * Whether to enable input validations expressed with attributes like `@email`, `@regex`,
674
- * `@@validate`, etc. Defaults to `true`.
420
+ * Checks for equality with the specified value.
675
421
  */
676
- validateInput?: boolean;
422
+ equals?: NullableIf<Uint8Array, Nullable>;
677
423
  /**
678
- * Options for omitting fields in ORM query results.
424
+ * Checks if the value is in the specified list of values.
679
425
  */
680
- omit?: OmitOptions<Schema>;
426
+ in?: Uint8Array[];
681
427
  /**
682
- * Whether to allow overriding omit settings at query time. Defaults to `true`. When set to
683
- * `false`, an `omit` clause that sets field to `false` (not omitting) will trigger a validation
684
- * error.
428
+ * Checks if the value is not in the specified list of values.
685
429
  */
686
- allowQueryTimeOmitOverride?: boolean;
687
- } & (HasComputedFields<Schema> extends true ? {
430
+ notIn?: Uint8Array[];
688
431
  /**
689
- * Computed field definitions.
432
+ * Builds a negated filter.
690
433
  */
691
- computedFields: ComputedFieldsOptions<Schema>;
692
- } : {}) & (HasProcedures<Schema> extends true ? {
434
+ not?: BytesFilter<Nullable, WithAggregations>;
435
+ } & (WithAggregations extends true ? {
693
436
  /**
694
- * Custom procedure definitions.
437
+ * Filters against the count of records.
695
438
  */
696
- procedures: ProceduresOptions<Schema>;
697
- } : {});
698
- /**
699
- * Options for omitting fields in ORM query results.
700
- */
701
- type OmitOptions<Schema extends SchemaDef> = {
702
- [Model in GetModels<Schema>]?: {
703
- [Field in GetModelFields<Schema, Model> as Field extends ScalarFields<Schema, Model> ? Field : never]?: boolean;
704
- };
705
- };
706
- type ComputedFieldsOptions<Schema extends SchemaDef> = {
707
- [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
708
- [Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
709
- };
710
- };
711
- type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
712
- type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
713
- procedures: Record<string, ProcedureDef>;
714
- } ? {
715
- [Key in GetProcedureNames<Schema>]: ProcedureHandlerFunc<Schema, Key>;
716
- } : {};
717
- type HasProcedures<Schema extends SchemaDef> = Schema extends {
718
- procedures: Record<string, ProcedureDef>;
719
- } ? true : false;
720
- /**
721
- * Subset of client options relevant to query operations.
722
- */
723
- type QueryOptions<Schema extends SchemaDef> = Pick<ClientOptions<Schema>, 'omit'>;
724
- /**
725
- * Extract QueryOptions from ClientOptions
726
- */
727
- type ToQueryOptions<T extends ClientOptions<any>> = Pick<T, 'omit'>;
728
-
729
- type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<{
730
- [Key in NonRelationFields<Schema, Model> as ShouldOmitField<Schema, Model, Options, Key, Omit> extends true ? never : Key]: MapModelFieldType<Schema, Model, Key>;
731
- }, Optional, Array>;
732
- type ShouldOmitField<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = QueryLevelOmit<Schema, Model, Field, Omit> extends boolean ? QueryLevelOmit<Schema, Model, Field, Omit> : OptionsLevelOmit<Schema, Model, Field, Options> extends boolean ? OptionsLevelOmit<Schema, Model, Field, Options> : SchemaLevelOmit<Schema, Model, Field>;
733
- type QueryLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Omit> = Field extends keyof Omit ? (Omit[Field] extends boolean ? Omit[Field] : undefined) : undefined;
734
- type OptionsLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>> = Model extends keyof Options['omit'] ? Field extends keyof Options['omit'][Model] ? Options['omit'][Model][Field] extends boolean ? Options['omit'][Model][Field] : undefined : undefined : undefined;
735
- type SchemaLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['omit'] extends true ? true : false;
736
- type ModelSelectResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Select, Omit, Options extends QueryOptions<Schema>> = {
737
- [Key in keyof Select as Select[Key] extends false | undefined ? never : Key extends '_count' ? Select[Key] extends SelectCount<Schema, Model> ? Key : never : Key extends keyof Omit ? Omit[Key] extends true ? never : Key : Key]: Key extends '_count' ? SelectCountResult<Schema, Model, Select[Key]> : Key extends NonRelationFields<Schema, Model> ? MapModelFieldType<Schema, Model, Key> : Key extends RelationFields<Schema, Model> ? ModelResult<Schema, RelationFieldType<Schema, Model, Key>, Select[Key], Options, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>> : never;
738
- };
739
- type SelectCountResult<Schema extends SchemaDef, Model extends GetModels<Schema>, C> = C extends true ? {
740
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: number;
741
- } : C extends {
742
- select: infer S;
743
- } ? {
744
- [Key in keyof S]: number;
745
- } : never;
746
- type ModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<Args extends {
747
- select: infer S extends object;
748
- omit?: infer O extends object;
749
- } & Record<string, unknown> ? ModelSelectResult<Schema, Model, S, O, Options> : Args extends {
750
- include: infer I extends object;
751
- omit?: infer O extends object;
752
- } & Record<string, unknown> ? // select all non-omitted scalar fields
753
- DefaultModelResult<Schema, Model, O, Options, false, false> & {
754
- [Key in keyof I & RelationFields<Schema, Model> as I[Key] extends false | undefined ? never : Key]: ModelResult<Schema, RelationFieldType<Schema, Model, Key>, I[Key], Options, ModelFieldIsOptional<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>>;
755
- } : Args extends {
756
- omit: infer O;
757
- } & Record<string, unknown> ? DefaultModelResult<Schema, Model, O, Options, false, false> : DefaultModelResult<Schema, Model, undefined, Options, false, false>, Optional, Array>;
758
- type SimplifiedResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = Simplify<ModelResult<Schema, Model, Args, Options, Optional, Array>>;
759
- type SimplifiedPlainResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Simplify<ModelResult<Schema, Model, Args, Options, false, false>>;
760
- type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = PartialIf<Optional<{
761
- [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial>;
762
- }, Partial extends true ? never : keyof {
763
- [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true;
764
- }>, Partial> & Record<string, unknown>;
765
- type BatchResult = {
766
- count: number;
767
- };
768
- type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ScalarOnly extends boolean = false, WithAggregations extends boolean = false> = {
769
- [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> : GetModelFieldType<Schema, Model, Key> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetModelFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>> : PrimitiveFilter<GetModelFieldType<Schema, Model, Key>, ModelFieldIsOptional<Schema, Model, Key>, WithAggregations>;
770
- } & {
771
- $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
772
- } & {
773
- AND?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
774
- OR?: WhereInput<Schema, Model, ScalarOnly>[];
775
- NOT?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
776
- };
777
- type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable extends boolean, WithAggregations extends boolean> = NullableIf<keyof GetEnum<Schema, T>, Nullable> | ({
439
+ _count?: NumberFilter<'Int', false, false>;
778
440
  /**
779
- * Checks for equality with the specified enum value.
441
+ * Filters against the minimum value.
780
442
  */
781
- equals?: NullableIf<keyof GetEnum<Schema, T>, Nullable>;
443
+ _min?: BytesFilter<false, false>;
782
444
  /**
783
- * Checks if the enum value is in the specified list of values.
445
+ * Filters against the maximum value.
784
446
  */
785
- in?: (keyof GetEnum<Schema, T>)[];
447
+ _max?: BytesFilter<false, false>;
448
+ } : {}));
449
+ type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<boolean, Nullable> | ({
786
450
  /**
787
- * Checks if the enum value is not in the specified list of values.
451
+ * Checks for equality with the specified value.
788
452
  */
789
- notIn?: (keyof GetEnum<Schema, T>)[];
453
+ equals?: NullableIf<boolean, Nullable>;
790
454
  /**
791
455
  * Builds a negated filter.
792
456
  */
793
- not?: EnumFilter<Schema, T, Nullable, WithAggregations>;
457
+ not?: BooleanFilter<Nullable, WithAggregations>;
794
458
  } & (WithAggregations extends true ? {
795
459
  /**
796
460
  * Filters against the count of records.
@@ -799,210 +463,31 @@ type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable e
799
463
  /**
800
464
  * Filters against the minimum value.
801
465
  */
802
- _min?: EnumFilter<Schema, T, false, false>;
466
+ _min?: BooleanFilter<false, false>;
803
467
  /**
804
468
  * Filters against the maximum value.
805
469
  */
806
- _max?: EnumFilter<Schema, T, false, false>;
470
+ _max?: BooleanFilter<false, false>;
807
471
  } : {}));
808
- type ArrayFilter<Schema extends SchemaDef, Type extends string> = {
472
+ type JsonFilter = {
809
473
  /**
810
- * Checks if the array equals the specified array.
474
+ * JSON path to select the value to filter on. If omitted, the whole JSON value is used.
811
475
  */
812
- equals?: MapScalarType<Schema, Type>[] | null;
476
+ path?: string;
813
477
  /**
814
- * Checks if the array contains all elements of the specified array.
478
+ * Checks for equality with the specified value.
815
479
  */
816
- has?: MapScalarType<Schema, Type> | null;
480
+ equals?: JsonValue | JsonNullValues;
817
481
  /**
818
- * Checks if the array contains any of the elements of the specified array.
482
+ * Builds a negated filter.
819
483
  */
820
- hasEvery?: MapScalarType<Schema, Type>[];
484
+ not?: JsonValue | JsonNullValues;
821
485
  /**
822
- * Checks if the array contains some of the elements of the specified array.
486
+ * Checks if the value is a string and contains the specified substring.
823
487
  */
824
- hasSome?: MapScalarType<Schema, Type>[];
488
+ string_contains?: string;
825
489
  /**
826
- * Checks if the array is empty.
827
- */
828
- isEmpty?: boolean;
829
- };
830
- type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
831
- type PrimitiveFilter<T extends string, Nullable extends boolean, WithAggregations extends boolean> = T extends 'String' ? StringFilter<Nullable, WithAggregations> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable, WithAggregations> : T extends 'Boolean' ? BooleanFilter<Nullable, WithAggregations> : T extends 'DateTime' ? DateTimeFilter<Nullable, WithAggregations> : T extends 'Bytes' ? BytesFilter<Nullable, WithAggregations> : T extends 'Json' ? JsonFilter : never;
832
- type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean> = {
833
- /**
834
- * Checks for equality with the specified value.
835
- */
836
- equals?: NullableIf<DataType, Nullable>;
837
- /**
838
- * Checks if the value is in the specified list of values.
839
- */
840
- in?: DataType[];
841
- /**
842
- * Checks if the value is not in the specified list of values.
843
- */
844
- notIn?: DataType[];
845
- /**
846
- * Checks if the value is less than the specified value.
847
- */
848
- lt?: DataType;
849
- /**
850
- * Checks if the value is less than or equal to the specified value.
851
- */
852
- lte?: DataType;
853
- /**
854
- * Checks if the value is greater than the specified value.
855
- */
856
- gt?: DataType;
857
- /**
858
- * Checks if the value is greater than or equal to the specified value.
859
- */
860
- gte?: DataType;
861
- /**
862
- * Builds a negated filter.
863
- */
864
- not?: PrimitiveFilter<T, Nullable, WithAggregations>;
865
- };
866
- type StringFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<string, Nullable> | (CommonPrimitiveFilter<string, 'String', Nullable, WithAggregations> & {
867
- /**
868
- * Checks if the string contains the specified substring.
869
- */
870
- contains?: string;
871
- /**
872
- * Checks if the string starts with the specified substring.
873
- */
874
- startsWith?: string;
875
- /**
876
- * Checks if the string ends with the specified substring.
877
- */
878
- endsWith?: string;
879
- /**
880
- * Specifies the string comparison mode. Not effective for "sqlite" provider
881
- */
882
- mode?: 'default' | 'insensitive';
883
- } & (WithAggregations extends true ? {
884
- /**
885
- * Filters against the count of records.
886
- */
887
- _count?: NumberFilter<'Int', false, false>;
888
- /**
889
- * Filters against the minimum value.
890
- */
891
- _min?: StringFilter<false, false>;
892
- /**
893
- * Filters against the maximum value.
894
- */
895
- _max?: StringFilter<false, false>;
896
- } : {}));
897
- type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean> = NullableIf<number | bigint, Nullable> | (CommonPrimitiveFilter<number, T, Nullable, WithAggregations> & (WithAggregations extends true ? {
898
- /**
899
- * Filters against the count of records.
900
- */
901
- _count?: NumberFilter<'Int', false, false>;
902
- /**
903
- * Filters against the average value.
904
- */
905
- _avg?: NumberFilter<T, false, false>;
906
- /**
907
- * Filters against the sum value.
908
- */
909
- _sum?: NumberFilter<T, false, false>;
910
- /**
911
- * Filters against the minimum value.
912
- */
913
- _min?: NumberFilter<T, false, false>;
914
- /**
915
- * Filters against the maximum value.
916
- */
917
- _max?: NumberFilter<T, false, false>;
918
- } : {}));
919
- type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Date | string, Nullable> | (CommonPrimitiveFilter<Date | string, 'DateTime', Nullable, WithAggregations> & (WithAggregations extends true ? {
920
- /**
921
- * Filters against the count of records.
922
- */
923
- _count?: NumberFilter<'Int', false, false>;
924
- /**
925
- * Filters against the minimum value.
926
- */
927
- _min?: DateTimeFilter<false, false>;
928
- /**
929
- * Filters against the maximum value.
930
- */
931
- _max?: DateTimeFilter<false, false>;
932
- } : {}));
933
- type BytesFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Uint8Array | Buffer, Nullable> | ({
934
- /**
935
- * Checks for equality with the specified value.
936
- */
937
- equals?: NullableIf<Uint8Array, Nullable>;
938
- /**
939
- * Checks if the value is in the specified list of values.
940
- */
941
- in?: Uint8Array[];
942
- /**
943
- * Checks if the value is not in the specified list of values.
944
- */
945
- notIn?: Uint8Array[];
946
- /**
947
- * Builds a negated filter.
948
- */
949
- not?: BytesFilter<Nullable, WithAggregations>;
950
- } & (WithAggregations extends true ? {
951
- /**
952
- * Filters against the count of records.
953
- */
954
- _count?: NumberFilter<'Int', false, false>;
955
- /**
956
- * Filters against the minimum value.
957
- */
958
- _min?: BytesFilter<false, false>;
959
- /**
960
- * Filters against the maximum value.
961
- */
962
- _max?: BytesFilter<false, false>;
963
- } : {}));
964
- type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<boolean, Nullable> | ({
965
- /**
966
- * Checks for equality with the specified value.
967
- */
968
- equals?: NullableIf<boolean, Nullable>;
969
- /**
970
- * Builds a negated filter.
971
- */
972
- not?: BooleanFilter<Nullable, WithAggregations>;
973
- } & (WithAggregations extends true ? {
974
- /**
975
- * Filters against the count of records.
976
- */
977
- _count?: NumberFilter<'Int', false, false>;
978
- /**
979
- * Filters against the minimum value.
980
- */
981
- _min?: BooleanFilter<false, false>;
982
- /**
983
- * Filters against the maximum value.
984
- */
985
- _max?: BooleanFilter<false, false>;
986
- } : {}));
987
- type JsonFilter = {
988
- /**
989
- * JSON path to select the value to filter on. If omitted, the whole JSON value is used.
990
- */
991
- path?: string;
992
- /**
993
- * Checks for equality with the specified value.
994
- */
995
- equals?: JsonValue | JsonNullValues;
996
- /**
997
- * Builds a negated filter.
998
- */
999
- not?: JsonValue | JsonNullValues;
1000
- /**
1001
- * Checks if the value is a string and contains the specified substring.
1002
- */
1003
- string_contains?: string;
1004
- /**
1005
- * Checks if the value is a string and starts with the specified substring.
490
+ * Checks if the value is a string and starts with the specified substring.
1006
491
  */
1007
492
  string_starts_with?: string;
1008
493
  /**
@@ -1615,120 +1100,557 @@ type GroupByResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Ar
1615
1100
  _min: infer Min;
1616
1101
  } ? {
1617
1102
  /**
1618
- * Minimum aggregation result
1103
+ * Minimum aggregation result
1104
+ */
1105
+ _min: AggCommonOutput<Min>;
1106
+ } : {}) & (Args extends {
1107
+ _max: infer Max;
1108
+ } ? {
1109
+ /**
1110
+ * Maximum aggregation result
1111
+ */
1112
+ _max: AggCommonOutput<Max>;
1113
+ } : {})>;
1114
+ 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>>;
1115
+ 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>>;
1116
+ 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>>;
1117
+ type SetRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>>;
1118
+ type NestedUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<{
1119
+ /**
1120
+ * Unique filter to select the record to update.
1121
+ */
1122
+ where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1123
+ /**
1124
+ * The data to update the record with.
1125
+ */
1126
+ data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1127
+ }, true> : XOR<{
1128
+ /**
1129
+ * Filter to select the record to update.
1130
+ */
1131
+ where?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
1132
+ /**
1133
+ * The data to update the record with.
1134
+ */
1135
+ data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1136
+ }, UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>>;
1137
+ type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<{
1138
+ /**
1139
+ * Unique filter to select the record to update.
1140
+ */
1141
+ where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1142
+ /**
1143
+ * The data to create the record if it doesn't exist.
1144
+ */
1145
+ create: CreateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1146
+ /**
1147
+ * The data to update the record with if it exists.
1148
+ */
1149
+ update: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1150
+ }, FieldIsArray<Schema, Model, Field>>;
1151
+ 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>>>;
1152
+ 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>>;
1153
+ type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, true>>;
1154
+ type GetProcedureNames<Schema extends SchemaDef> = Schema extends {
1155
+ procedures: Record<string, ProcedureDef>;
1156
+ } ? keyof Schema['procedures'] : never;
1157
+ type GetProcedureParams<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1158
+ procedures: Record<string, ProcedureDef>;
1159
+ } ? Schema['procedures'][ProcName]['params'] : never;
1160
+ type GetProcedure<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1161
+ procedures: Record<string, ProcedureDef>;
1162
+ } ? Schema['procedures'][ProcName] : never;
1163
+ type _OptionalProcedureParamNames<Params> = keyof {
1164
+ [K in keyof Params as Params[K] extends {
1165
+ optional: true;
1166
+ } ? K : never]: K;
1167
+ };
1168
+ type _RequiredProcedureParamNames<Params> = keyof {
1169
+ [K in keyof Params as Params[K] extends {
1170
+ optional: true;
1171
+ } ? never : K]: K;
1172
+ };
1173
+ type _HasRequiredProcedureParams<Params> = _RequiredProcedureParamNames<Params> extends never ? false : true;
1174
+ type MapProcedureArgsObject<Schema extends SchemaDef, Params> = Simplify<Optional<{
1175
+ [K in keyof Params]: MapProcedureParam<Schema, Params[K]>;
1176
+ }, _OptionalProcedureParamNames<Params>>>;
1177
+ type ProcedureEnvelope<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>, Params = GetProcedureParams<Schema, ProcName>> = keyof Params extends never ? {
1178
+ args?: Record<string, never>;
1179
+ } : _HasRequiredProcedureParams<Params> extends true ? {
1180
+ args: MapProcedureArgsObject<Schema, Params>;
1181
+ } : {
1182
+ args?: MapProcedureArgsObject<Schema, Params>;
1183
+ };
1184
+ type ProcedureHandlerCtx<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = {
1185
+ client: ClientContract<Schema>;
1186
+ } & ProcedureEnvelope<Schema, ProcName>;
1187
+ /**
1188
+ * Shape of a procedure's runtime function.
1189
+ */
1190
+ type ProcedureFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (...args: _HasRequiredProcedureParams<GetProcedureParams<Schema, ProcName>> extends true ? [input: ProcedureEnvelope<Schema, ProcName>] : [input?: ProcedureEnvelope<Schema, ProcName>]) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
1191
+ /**
1192
+ * Signature for procedure handlers configured via client options.
1193
+ */
1194
+ type ProcedureHandlerFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (ctx: ProcedureHandlerCtx<Schema, ProcName>) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
1195
+ type MapProcedureReturn<Schema extends SchemaDef, Proc> = Proc extends {
1196
+ returnType: infer R;
1197
+ } ? Proc extends {
1198
+ returnArray: true;
1199
+ } ? Array<MapType<Schema, R & string>> : MapType<Schema, R & string> : never;
1200
+ type MapProcedureParam<Schema extends SchemaDef, P> = P extends {
1201
+ type: infer U;
1202
+ } ? OrUndefinedIf<P extends {
1203
+ array: true;
1204
+ } ? Array<MapType<Schema, U & string>> : MapType<Schema, U & string>, P extends {
1205
+ optional: true;
1206
+ } ? true : false> : never;
1207
+ type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1208
+ [Key in RelationFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends {
1209
+ references: readonly unknown[];
1210
+ } ? never : Key]: true;
1211
+ };
1212
+ type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1213
+ [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
1214
+ } extends never ? false : true;
1215
+ type EnumValue<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = GetEnum<Schema, Enum>[keyof GetEnum<Schema, Enum>];
1216
+ type MapType<Schema extends SchemaDef, T extends string> = T extends keyof TypeMap ? TypeMap[T] : T extends GetModels<Schema> ? ModelResult<Schema, T> : T extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T> : T extends GetEnums<Schema> ? EnumValue<Schema, T> : unknown;
1217
+
1218
+ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
1219
+ protected readonly schema: Schema;
1220
+ protected readonly options: ClientOptions<Schema>;
1221
+ protected eb: ExpressionBuilder<any, any>;
1222
+ constructor(schema: Schema, options: ClientOptions<Schema>);
1223
+ transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
1224
+ transformOutput(value: unknown, _type: BuiltinType, _array: boolean): unknown;
1225
+ buildSelectModel(model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
1226
+ buildFilterSortTake(model: string, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
1227
+ buildFilter(model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
1228
+ private buildCursorFilter;
1229
+ private isLogicalCombinator;
1230
+ protected buildCompositeFilter(model: string, modelAlias: string, key: (typeof LOGICAL_COMBINATORS)[number], payload: any): Expression<SqlBool>;
1231
+ private buildRelationFilter;
1232
+ private buildToOneRelationFilter;
1233
+ private buildToManyRelationFilter;
1234
+ private buildArrayFilter;
1235
+ buildPrimitiveFilter(fieldRef: Expression<any>, fieldDef: FieldDef, payload: any): any;
1236
+ private buildJsonFilter;
1237
+ private buildPlainJsonFilter;
1238
+ private buildTypedJsonFilter;
1239
+ private buildTypedJsonArrayFilter;
1240
+ private buildTypeJsonNonArrayFilter;
1241
+ private buildJsonValueFilterClause;
1242
+ private buildLiteralFilter;
1243
+ private buildStandardFilter;
1244
+ private buildStringFilter;
1245
+ private buildJsonStringFilter;
1246
+ private escapeLikePattern;
1247
+ private buildStringLike;
1248
+ private prepStringCasing;
1249
+ private buildNumberFilter;
1250
+ private buildBooleanFilter;
1251
+ private buildDateTimeFilter;
1252
+ private buildBytesFilter;
1253
+ private buildEnumFilter;
1254
+ buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, negated: boolean): SelectQueryBuilder<any, any, any>;
1255
+ buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined | null, modelAlias: string): SelectQueryBuilder<any, any, any>;
1256
+ shouldOmitField(omit: unknown, model: string, field: string): any;
1257
+ protected buildModelSelect(model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
1258
+ buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
1259
+ buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
1260
+ buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): ExpressionWrapper<any, any, unknown>;
1261
+ private negateSort;
1262
+ true(): Expression<SqlBool>;
1263
+ false(): Expression<SqlBool>;
1264
+ isTrue(expression: Expression<SqlBool>): boolean;
1265
+ isFalse(expression: Expression<SqlBool>): boolean;
1266
+ and(...args: Expression<SqlBool>[]): Expression<SqlBool>;
1267
+ or(...args: Expression<SqlBool>[]): Expression<SqlBool>;
1268
+ not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
1269
+ fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean): any;
1270
+ protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
1271
+ abstract get provider(): DataSourceProviderType;
1272
+ /**
1273
+ * Builds selection for a relation field.
1274
+ */
1275
+ abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>): SelectQueryBuilder<any, any, any>;
1276
+ /**
1277
+ * Builds skip and take clauses.
1278
+ */
1279
+ abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
1280
+ /**
1281
+ * Builds an Kysely expression that returns a JSON object for the given key-value pairs.
1282
+ */
1283
+ abstract buildJsonObject(value: Record<string, Expression<unknown>>): ExpressionWrapper<any, any, unknown>;
1284
+ /**
1285
+ * Builds an Kysely expression that returns the length of an array.
1286
+ */
1287
+ abstract buildArrayLength(array: Expression<unknown>): ExpressionWrapper<any, any, number>;
1288
+ /**
1289
+ * Builds an array literal SQL string for the given values.
1290
+ */
1291
+ abstract buildArrayLiteralSQL(values: unknown[]): string;
1292
+ /**
1293
+ * Whether the dialect supports updating with a limit on the number of updated rows.
1294
+ */
1295
+ abstract get supportsUpdateWithLimit(): boolean;
1296
+ /**
1297
+ * Whether the dialect supports deleting with a limit on the number of deleted rows.
1298
+ */
1299
+ abstract get supportsDeleteWithLimit(): boolean;
1300
+ /**
1301
+ * Whether the dialect supports DISTINCT ON.
1302
+ */
1303
+ abstract get supportsDistinctOn(): boolean;
1304
+ /**
1305
+ * Whether the dialect support inserting with `DEFAULT` as field value.
1306
+ */
1307
+ abstract get supportInsertWithDefault(): boolean;
1308
+ /**
1309
+ * Gets the SQL column type for the given field definition.
1310
+ */
1311
+ abstract getFieldSqlType(fieldDef: FieldDef): string;
1312
+ abstract getStringCasingBehavior(): {
1313
+ supportsILike: boolean;
1314
+ likeCaseSensitive: boolean;
1315
+ };
1316
+ /**
1317
+ * Builds a JSON path selection expression.
1318
+ */
1319
+ protected abstract buildJsonPathSelection(receiver: Expression<any>, path: string | undefined): Expression<any>;
1320
+ /**
1321
+ * Builds a JSON array filter expression.
1322
+ */
1323
+ protected abstract buildJsonArrayFilter(receiver: Expression<any>, operation: 'array_contains' | 'array_starts_with' | 'array_ends_with', value: unknown): Expression<SqlBool>;
1324
+ /**
1325
+ * Builds a JSON array exists predicate (returning if any element matches the filter).
1326
+ */
1327
+ protected abstract buildJsonArrayExistsPredicate(receiver: Expression<any>, buildFilter: (elem: Expression<any>) => Expression<SqlBool>): Expression<SqlBool>;
1328
+ }
1329
+
1330
+ declare class InputValidator<Schema extends SchemaDef> {
1331
+ private readonly client;
1332
+ private readonly schemaCache;
1333
+ constructor(client: ClientContract<Schema>);
1334
+ private get schema();
1335
+ private get options();
1336
+ private get extraValidationsEnabled();
1337
+ validateProcedureInput(proc: string, input: unknown): unknown;
1338
+ private makeProcedureParamSchema;
1339
+ validateFindArgs(model: GetModels<Schema>, args: unknown, operation: CoreCrudOperations): FindArgs<Schema, GetModels<Schema>, true> | undefined;
1340
+ validateExistsArgs(model: GetModels<Schema>, args: unknown): ExistsArgs<Schema, GetModels<Schema>> | undefined;
1341
+ validateCreateArgs(model: GetModels<Schema>, args: unknown): CreateArgs<Schema, GetModels<Schema>>;
1342
+ validateCreateManyArgs(model: GetModels<Schema>, args: unknown): CreateManyArgs<Schema, GetModels<Schema>>;
1343
+ validateCreateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): CreateManyAndReturnArgs<Schema, GetModels<Schema>> | undefined;
1344
+ validateUpdateArgs(model: GetModels<Schema>, args: unknown): UpdateArgs<Schema, GetModels<Schema>>;
1345
+ validateUpdateManyArgs(model: GetModels<Schema>, args: unknown): UpdateManyArgs<Schema, GetModels<Schema>>;
1346
+ validateUpdateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): UpdateManyAndReturnArgs<Schema, GetModels<Schema>>;
1347
+ validateUpsertArgs(model: GetModels<Schema>, args: unknown): UpsertArgs<Schema, GetModels<Schema>>;
1348
+ validateDeleteArgs(model: GetModels<Schema>, args: unknown): DeleteArgs<Schema, GetModels<Schema>>;
1349
+ validateDeleteManyArgs(model: GetModels<Schema>, args: unknown): DeleteManyArgs<Schema, GetModels<Schema>> | undefined;
1350
+ validateCountArgs(model: GetModels<Schema>, args: unknown): CountArgs<Schema, GetModels<Schema>> | undefined;
1351
+ validateAggregateArgs(model: GetModels<Schema>, args: unknown): AggregateArgs<Schema, GetModels<Schema>>;
1352
+ validateGroupByArgs(model: GetModels<Schema>, args: unknown): GroupByArgs<Schema, GetModels<Schema>>;
1353
+ private getSchemaCache;
1354
+ private setSchemaCache;
1355
+ private validate;
1356
+ private mergePluginArgsSchema;
1357
+ private makeFindSchema;
1358
+ private makeExistsSchema;
1359
+ private makeScalarSchema;
1360
+ private makeEnumSchema;
1361
+ private makeTypeDefSchema;
1362
+ private makeWhereSchema;
1363
+ private makeTypedJsonFilterSchema;
1364
+ private isTypeDefType;
1365
+ private makeEnumFilterSchema;
1366
+ private makeArrayFilterSchema;
1367
+ private internalMakeArrayFilterSchema;
1368
+ private makePrimitiveFilterSchema;
1369
+ private makeJsonValueSchema;
1370
+ private makeJsonFilterSchema;
1371
+ private makeDateTimeFilterSchema;
1372
+ private makeBooleanFilterSchema;
1373
+ private makeBytesFilterSchema;
1374
+ private makeCommonPrimitiveFilterComponents;
1375
+ private makeCommonPrimitiveFilterSchema;
1376
+ private makeNumberFilterSchema;
1377
+ private makeStringFilterSchema;
1378
+ private makeStringModeSchema;
1379
+ private makeSelectSchema;
1380
+ private makeCountSelectionSchema;
1381
+ private makeRelationSelectIncludeSchema;
1382
+ private makeOmitSchema;
1383
+ private makeIncludeSchema;
1384
+ private makeOrderBySchema;
1385
+ private makeDistinctSchema;
1386
+ private makeCursorSchema;
1387
+ private makeCreateSchema;
1388
+ private makeCreateManySchema;
1389
+ private makeCreateManyAndReturnSchema;
1390
+ private makeCreateDataSchema;
1391
+ private isDelegateDiscriminator;
1392
+ private makeRelationManipulationSchema;
1393
+ private makeSetDataSchema;
1394
+ private makeConnectDataSchema;
1395
+ private makeDisconnectDataSchema;
1396
+ private makeDeleteRelationDataSchema;
1397
+ private makeConnectOrCreateDataSchema;
1398
+ private makeCreateManyDataSchema;
1399
+ private makeUpdateSchema;
1400
+ private makeUpdateManySchema;
1401
+ private makeUpdateManyAndReturnSchema;
1402
+ private makeUpsertSchema;
1403
+ private makeUpdateDataSchema;
1404
+ private makeDeleteSchema;
1405
+ private makeDeleteManySchema;
1406
+ makeCountSchema(model: GetModels<Schema>): z.ZodOptional<z.ZodObject<z.core.$ZodLooseShape, z.core.$strict>>;
1407
+ private makeCountAggregateInputSchema;
1408
+ makeAggregateSchema(model: GetModels<Schema>): z.ZodOptional<z.ZodObject<z.core.$ZodLooseShape, z.core.$strict>>;
1409
+ makeSumAvgInputSchema(model: GetModels<Schema>): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
1410
+ makeMinMaxInputSchema(model: GetModels<Schema>): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
1411
+ private makeGroupBySchema;
1412
+ private onlyAggregationFields;
1413
+ private makeHavingSchema;
1414
+ private makeSkipSchema;
1415
+ private makeTakeSchema;
1416
+ private refineForSelectIncludeMutuallyExclusive;
1417
+ private refineForSelectOmitMutuallyExclusive;
1418
+ private nullableIf;
1419
+ private orArray;
1420
+ private isNumericField;
1421
+ private get providerSupportsCaseSensitivity();
1422
+ }
1423
+
1424
+ /**
1425
+ * List of core CRUD operations. It excludes the 'orThrow' variants.
1426
+ */
1427
+ declare const CoreCrudOperations: readonly ["findMany", "findUnique", "findFirst", "create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany", "count", "aggregate", "groupBy", "exists"];
1428
+ /**
1429
+ * List of core CRUD operations. It excludes the 'orThrow' variants.
1430
+ */
1431
+ type CoreCrudOperations = (typeof CoreCrudOperations)[number];
1432
+ /**
1433
+ * List of core read operations. It excludes the 'orThrow' variants.
1434
+ */
1435
+ declare const CoreReadOperations: readonly ["findMany", "findUnique", "findFirst", "count", "aggregate", "groupBy", "exists"];
1436
+ /**
1437
+ * List of core read operations. It excludes the 'orThrow' variants.
1438
+ */
1439
+ type CoreReadOperations = (typeof CoreReadOperations)[number];
1440
+ /**
1441
+ * List of core write operations.
1442
+ */
1443
+ declare const CoreWriteOperations: readonly ["create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany"];
1444
+ /**
1445
+ * List of core write operations.
1446
+ */
1447
+ type CoreWriteOperations = (typeof CoreWriteOperations)[number];
1448
+ /**
1449
+ * List of all CRUD operations, including 'orThrow' variants.
1450
+ */
1451
+ declare const AllCrudOperations: readonly ["findMany", "findUnique", "findFirst", "create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany", "count", "aggregate", "groupBy", "exists", "findUniqueOrThrow", "findFirstOrThrow"];
1452
+ /**
1453
+ * List of all CRUD operations, including 'orThrow' variants.
1454
+ */
1455
+ type AllCrudOperations = (typeof AllCrudOperations)[number];
1456
+ /**
1457
+ * List of all read operations, including 'orThrow' variants.
1458
+ */
1459
+ declare const AllReadOperations: readonly ["findMany", "findUnique", "findFirst", "count", "aggregate", "groupBy", "exists", "findUniqueOrThrow", "findFirstOrThrow"];
1460
+ /**
1461
+ * List of all read operations, including 'orThrow' variants.
1462
+ */
1463
+ type AllReadOperations = (typeof AllReadOperations)[number];
1464
+
1465
+ /**
1466
+ * Base shape of plugin-extended query args.
1467
+ */
1468
+ type ExtQueryArgsBase = {
1469
+ [K in CoreCrudOperations | 'all']?: object;
1470
+ };
1471
+ /**
1472
+ * ZenStack runtime plugin.
1473
+ */
1474
+ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef, _ExtQueryArgs extends ExtQueryArgsBase = {}> {
1475
+ /**
1476
+ * Plugin ID.
1477
+ */
1478
+ id: string;
1479
+ /**
1480
+ * Plugin display name.
1481
+ */
1482
+ name?: string;
1483
+ /**
1484
+ * Plugin description.
1485
+ */
1486
+ description?: string;
1487
+ /**
1488
+ * Custom function implementations.
1489
+ * @private
1490
+ */
1491
+ functions?: Record<string, ZModelFunction<Schema>>;
1492
+ /**
1493
+ * Intercepts an ORM query.
1494
+ */
1495
+ onQuery?: OnQueryCallback<Schema>;
1496
+ /**
1497
+ * Intercepts a procedure invocation.
1498
+ */
1499
+ onProcedure?: OnProcedureCallback<Schema>;
1500
+ /**
1501
+ * Intercepts an entity mutation.
1502
+ */
1503
+ onEntityMutation?: EntityMutationHooksDef<Schema>;
1504
+ /**
1505
+ * Intercepts a Kysely query.
1506
+ */
1507
+ onKyselyQuery?: OnKyselyQueryCallback<Schema>;
1508
+ /**
1509
+ * Extended query args configuration.
1510
+ */
1511
+ extQueryArgs?: {
1512
+ /**
1513
+ * Callback for getting a Zod schema to validate the extended query args for the given operation.
1514
+ */
1515
+ getValidationSchema: (operation: CoreCrudOperations) => ZodObject | undefined;
1516
+ };
1517
+ }
1518
+ /**
1519
+ * Defines a ZenStack runtime plugin.
1520
+ */
1521
+ declare function definePlugin<Schema extends SchemaDef = SchemaDef, ExtQueryArgs extends ExtQueryArgsBase = {}>(plugin: RuntimePlugin<Schema, ExtQueryArgs>): RuntimePlugin<Schema, ExtQueryArgs>;
1522
+ type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;
1523
+ type OnProcedureHookContext<Schema extends SchemaDef> = {
1524
+ /**
1525
+ * The procedure name.
1526
+ */
1527
+ name: string;
1528
+ /**
1529
+ * Whether the procedure is a mutation.
1530
+ */
1531
+ mutation: boolean;
1532
+ /**
1533
+ * Procedure invocation input (envelope).
1534
+ *
1535
+ * The canonical shape is `{ args?: Record<string, unknown> }`.
1536
+ * When a procedure has required params, `args` is required.
1537
+ */
1538
+ input: unknown;
1539
+ /**
1540
+ * Continues the invocation. The input passed here is forwarded to the next handler.
1541
+ */
1542
+ proceed: (input: unknown) => Promise<unknown>;
1543
+ /**
1544
+ * The ZenStack client that is invoking the procedure.
1545
+ */
1546
+ client: ClientContract<Schema>;
1547
+ };
1548
+ type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
1549
+ type OnQueryHookContext<Schema extends SchemaDef> = {
1550
+ /**
1551
+ * The model that is being queried.
1552
+ */
1553
+ model: GetModels<Schema>;
1554
+ /**
1555
+ * The operation that is being performed.
1556
+ */
1557
+ operation: AllCrudOperations;
1558
+ /**
1559
+ * The query arguments.
1560
+ */
1561
+ args: Record<string, unknown> | undefined;
1562
+ /**
1563
+ * The function to proceed with the original query.
1564
+ * It takes the same arguments as the operation method.
1565
+ *
1566
+ * @param args The query arguments.
1567
+ */
1568
+ proceed: (args: Record<string, unknown> | undefined) => Promise<unknown>;
1569
+ /**
1570
+ * The ZenStack client that is performing the operation.
1571
+ */
1572
+ client: ClientContract<Schema>;
1573
+ };
1574
+ type EntityMutationHooksDef<Schema extends SchemaDef> = {
1575
+ /**
1576
+ * Called before entities are mutated.
1577
+ */
1578
+ beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
1579
+ /**
1580
+ * Called after entities are mutated.
1581
+ */
1582
+ afterEntityMutation?: AfterEntityMutationCallback<Schema>;
1583
+ /**
1584
+ * Whether to run after-mutation hooks within the transaction that performs the mutation.
1585
+ *
1586
+ * If set to `true`, if the mutation already runs inside a transaction, the callbacks are
1587
+ * executed immediately after the mutation within the transaction boundary. If the mutation
1588
+ * is not running inside a transaction, a new transaction is created to run both the mutation
1589
+ * and the callbacks.
1590
+ *
1591
+ * If set to `false`, the callbacks are executed after the mutation transaction is committed.
1592
+ *
1593
+ * Defaults to `false`.
1619
1594
  */
1620
- _min: AggCommonOutput<Min>;
1621
- } : {}) & (Args extends {
1622
- _max: infer Max;
1623
- } ? {
1595
+ runAfterMutationWithinTransaction?: boolean;
1596
+ };
1597
+ type MutationHooksArgs<Schema extends SchemaDef> = {
1624
1598
  /**
1625
- * Maximum aggregation result
1599
+ * The model that is being mutated.
1626
1600
  */
1627
- _max: AggCommonOutput<Max>;
1628
- } : {})>;
1629
- 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>>;
1630
- 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>>;
1631
- 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>>;
1632
- type SetRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>>;
1633
- type NestedUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<{
1601
+ model: GetModels<Schema>;
1634
1602
  /**
1635
- * Unique filter to select the record to update.
1603
+ * The mutation action that is being performed.
1636
1604
  */
1637
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1605
+ action: 'create' | 'update' | 'delete';
1638
1606
  /**
1639
- * The data to update the record with.
1607
+ * The mutation data. Only available for create and update actions.
1640
1608
  */
1641
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1642
- }, true> : XOR<{
1609
+ queryNode: OperationNode;
1643
1610
  /**
1644
- * Filter to select the record to update.
1611
+ * A query ID that uniquely identifies the mutation operation. You can use it to correlate
1612
+ * data between the before and after mutation hooks.
1645
1613
  */
1646
- where?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
1614
+ queryId: QueryId;
1615
+ };
1616
+ type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
1617
+ type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
1618
+ type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
1647
1619
  /**
1648
- * The data to update the record with.
1620
+ * Loads the entities that are about to be mutated. The db operation that loads the entities is executed
1621
+ * within the same transaction context as the mutation.
1649
1622
  */
1650
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1651
- }, UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>>;
1652
- type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<{
1623
+ loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
1653
1624
  /**
1654
- * Unique filter to select the record to update.
1625
+ * The ZenStack client you can use to perform additional operations. The database operations initiated
1626
+ * from this client are executed within the same transaction as the mutation if the mutation is running
1627
+ * inside a transaction.
1628
+ *
1629
+ * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
1655
1630
  */
1656
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1631
+ client: ClientContract<Schema>;
1632
+ };
1633
+ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
1657
1634
  /**
1658
- * The data to create the record if it doesn't exist.
1635
+ * Loads the entities that have been mutated.
1659
1636
  */
1660
- create: CreateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1637
+ loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
1661
1638
  /**
1662
- * The data to update the record with if it exists.
1639
+ * The ZenStack client you can use to perform additional operations.
1640
+ * See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
1641
+ *
1642
+ * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
1663
1643
  */
1664
- update: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1665
- }, FieldIsArray<Schema, Model, Field>>;
1666
- 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>>>;
1667
- 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>>;
1668
- type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, true>>;
1669
- type GetProcedureNames<Schema extends SchemaDef> = Schema extends {
1670
- procedures: Record<string, ProcedureDef>;
1671
- } ? keyof Schema['procedures'] : never;
1672
- type GetProcedureParams<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1673
- procedures: Record<string, ProcedureDef>;
1674
- } ? Schema['procedures'][ProcName]['params'] : never;
1675
- type GetProcedure<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1676
- procedures: Record<string, ProcedureDef>;
1677
- } ? Schema['procedures'][ProcName] : never;
1678
- type _OptionalProcedureParamNames<Params> = keyof {
1679
- [K in keyof Params as Params[K] extends {
1680
- optional: true;
1681
- } ? K : never]: K;
1682
- };
1683
- type _RequiredProcedureParamNames<Params> = keyof {
1684
- [K in keyof Params as Params[K] extends {
1685
- optional: true;
1686
- } ? never : K]: K;
1687
- };
1688
- type _HasRequiredProcedureParams<Params> = _RequiredProcedureParamNames<Params> extends never ? false : true;
1689
- type MapProcedureArgsObject<Schema extends SchemaDef, Params> = Simplify<Optional<{
1690
- [K in keyof Params]: MapProcedureParam<Schema, Params[K]>;
1691
- }, _OptionalProcedureParamNames<Params>>>;
1692
- type ProcedureEnvelope<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>, Params = GetProcedureParams<Schema, ProcName>> = keyof Params extends never ? {
1693
- args?: Record<string, never>;
1694
- } : _HasRequiredProcedureParams<Params> extends true ? {
1695
- args: MapProcedureArgsObject<Schema, Params>;
1696
- } : {
1697
- args?: MapProcedureArgsObject<Schema, Params>;
1644
+ client: ClientContract<Schema>;
1698
1645
  };
1699
- type ProcedureHandlerCtx<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = {
1646
+ type OnKyselyQueryArgs<Schema extends SchemaDef> = {
1647
+ schema: SchemaDef;
1700
1648
  client: ClientContract<Schema>;
1701
- } & ProcedureEnvelope<Schema, ProcName>;
1702
- /**
1703
- * Shape of a procedure's runtime function.
1704
- */
1705
- type ProcedureFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (...args: _HasRequiredProcedureParams<GetProcedureParams<Schema, ProcName>> extends true ? [input: ProcedureEnvelope<Schema, ProcName>] : [input?: ProcedureEnvelope<Schema, ProcName>]) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
1706
- /**
1707
- * Signature for procedure handlers configured via client options.
1708
- */
1709
- type ProcedureHandlerFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (ctx: ProcedureHandlerCtx<Schema, ProcName>) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
1710
- type MapProcedureReturn<Schema extends SchemaDef, Proc> = Proc extends {
1711
- returnType: infer R;
1712
- } ? Proc extends {
1713
- returnArray: true;
1714
- } ? Array<MapType<Schema, R & string>> : MapType<Schema, R & string> : never;
1715
- type MapProcedureParam<Schema extends SchemaDef, P> = P extends {
1716
- type: infer U;
1717
- } ? OrUndefinedIf<P extends {
1718
- array: true;
1719
- } ? Array<MapType<Schema, U & string>> : MapType<Schema, U & string>, P extends {
1720
- optional: true;
1721
- } ? true : false> : never;
1722
- type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1723
- [Key in RelationFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends {
1724
- references: readonly unknown[];
1725
- } ? never : Key]: true;
1649
+ query: RootOperationNode;
1650
+ proceed: ProceedKyselyQueryFunction;
1726
1651
  };
1727
- type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1728
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
1729
- } extends never ? false : true;
1730
- type EnumValue<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = GetEnum<Schema, Enum>[keyof GetEnum<Schema, Enum>];
1731
- type MapType<Schema extends SchemaDef, T extends string> = T extends keyof TypeMap ? TypeMap[T] : T extends GetModels<Schema> ? ModelResult<Schema, T> : T extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T> : T extends GetEnums<Schema> ? EnumValue<Schema, T> : unknown;
1652
+ type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
1653
+ type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
1732
1654
 
1733
1655
  /**
1734
1656
  * A promise that only executes when it's awaited or .then() is called.
@@ -1742,6 +1664,10 @@ type ZenStackPromise<Schema extends SchemaDef, T> = Promise<T> & {
1742
1664
  };
1743
1665
 
1744
1666
  type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[number];
1667
+ /**
1668
+ * Extracts extended query args for a specific operation.
1669
+ */
1670
+ type ExtractExtQueryArgs<ExtQueryArgs, Operation extends CoreCrudOperations> = Operation extends keyof ExtQueryArgs ? NonNullable<ExtQueryArgs[Operation]> : 'all' extends keyof ExtQueryArgs ? NonNullable<ExtQueryArgs['all']> : {};
1745
1671
  /**
1746
1672
  * Transaction isolation levels.
1747
1673
  */
@@ -1755,7 +1681,7 @@ declare enum TransactionIsolationLevel {
1755
1681
  /**
1756
1682
  * ZenStack client interface.
1757
1683
  */
1758
- type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema> = ClientOptions<Schema>> = {
1684
+ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase = {}> = {
1759
1685
  /**
1760
1686
  * The schema definition.
1761
1687
  */
@@ -1805,7 +1731,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1805
1731
  /**
1806
1732
  * Sets the current user identity.
1807
1733
  */
1808
- $setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options>;
1734
+ $setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options, ExtQueryArgs>;
1809
1735
  /**
1810
1736
  * Returns a new client with new options applied.
1811
1737
  * @example
@@ -1813,14 +1739,14 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1813
1739
  * const dbNoValidation = db.$setOptions({ ...db.$options, validateInput: false });
1814
1740
  * ```
1815
1741
  */
1816
- $setOptions<Options extends ClientOptions<Schema>>(options: Options): ClientContract<Schema, Options>;
1742
+ $setOptions<Options extends ClientOptions<Schema>>(options: Options): ClientContract<Schema, Options, ExtQueryArgs>;
1817
1743
  /**
1818
1744
  * Returns a new client enabling/disabling input validations expressed with attributes like
1819
1745
  * `@email`, `@regex`, `@@validate`, etc.
1820
1746
  *
1821
- * @deprecated Use `$setOptions` instead.
1747
+ * @deprecated Use {@link $setOptions} instead.
1822
1748
  */
1823
- $setInputValidation(enable: boolean): ClientContract<Schema, Options>;
1749
+ $setInputValidation(enable: boolean): ClientContract<Schema, Options, ExtQueryArgs>;
1824
1750
  /**
1825
1751
  * The Kysely query builder instance.
1826
1752
  */
@@ -1832,7 +1758,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1832
1758
  /**
1833
1759
  * Starts an interactive transaction.
1834
1760
  */
1835
- $transaction<T>(callback: (tx: Omit<ClientContract<Schema, Options>, TransactionUnsupportedMethods>) => Promise<T>, options?: {
1761
+ $transaction<T>(callback: (tx: TransactionClientContract<Schema, Options, ExtQueryArgs>) => Promise<T>, options?: {
1836
1762
  isolationLevel?: TransactionIsolationLevel;
1837
1763
  }): Promise<T>;
1838
1764
  /**
@@ -1844,11 +1770,11 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1844
1770
  /**
1845
1771
  * Returns a new client with the specified plugin installed.
1846
1772
  */
1847
- $use(plugin: RuntimePlugin<Schema>): ClientContract<Schema, Options>;
1773
+ $use<PluginSchema extends SchemaDef = Schema, PluginExtQueryArgs extends ExtQueryArgsBase = {}>(plugin: RuntimePlugin<PluginSchema, PluginExtQueryArgs>): ClientContract<Schema, Options, ExtQueryArgs & PluginExtQueryArgs>;
1848
1774
  /**
1849
1775
  * Returns a new client with the specified plugin removed.
1850
1776
  */
1851
- $unuse(pluginId: string): ClientContract<Schema, Options>;
1777
+ $unuse(pluginId: string): ClientContract<Schema, Options, ExtQueryArgs>;
1852
1778
  /**
1853
1779
  * Returns a new client with all plugins removed.
1854
1780
  */
@@ -1867,12 +1793,12 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1867
1793
  */
1868
1794
  $pushSchema(): Promise<void>;
1869
1795
  } & {
1870
- [Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key, ToQueryOptions<Options>>;
1796
+ [Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key, ToQueryOptions<Options>, ExtQueryArgs>;
1871
1797
  } & ProcedureOperations<Schema>;
1872
1798
  /**
1873
1799
  * The contract for a client in a transaction.
1874
1800
  */
1875
- type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>> = Omit<ClientContract<Schema, Options>, TransactionUnsupportedMethods>;
1801
+ type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase> = Omit<ClientContract<Schema, Options, ExtQueryArgs>, TransactionUnsupportedMethods>;
1876
1802
  type ProcedureOperations<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
1877
1803
  /**
1878
1804
  * Custom procedures.
@@ -1903,7 +1829,7 @@ type CRUD_EXT = CRUD | 'post-update';
1903
1829
  * Extended CRUD operations including 'post-update'.
1904
1830
  */
1905
1831
  declare const CRUD_EXT: readonly ["create", "read", "update", "delete", "post-update"];
1906
- type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = {
1832
+ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, ExtQueryArgs> = {
1907
1833
  /**
1908
1834
  * Returns a list of entities.
1909
1835
  * @param args - query args
@@ -1985,35 +1911,35 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
1985
1911
  * }); // result: `{ _count: { posts: number } }`
1986
1912
  * ```
1987
1913
  */
1988
- findMany<T extends FindManyArgs<Schema, Model>>(args?: SelectSubset<T, FindManyArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
1914
+ findMany<T extends FindManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findMany'>>(args?: SelectSubset<T, FindManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findMany'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
1989
1915
  /**
1990
1916
  * Returns a uniquely identified entity.
1991
1917
  * @param args - query args
1992
1918
  * @returns a single entity or null if not found
1993
1919
  * @see {@link findMany}
1994
1920
  */
1995
- findUnique<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options> | null>;
1921
+ findUnique<T extends FindUniqueArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options> | null>;
1996
1922
  /**
1997
1923
  * Returns a uniquely identified entity or throws `NotFoundError` if not found.
1998
1924
  * @param args - query args
1999
1925
  * @returns a single entity
2000
1926
  * @see {@link findMany}
2001
1927
  */
2002
- findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
1928
+ findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2003
1929
  /**
2004
1930
  * Returns the first entity.
2005
1931
  * @param args - query args
2006
1932
  * @returns a single entity or null if not found
2007
1933
  * @see {@link findMany}
2008
1934
  */
2009
- findFirst<T extends FindFirstArgs<Schema, Model>>(args?: SelectSubset<T, FindFirstArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options> | null>;
1935
+ findFirst<T extends FindFirstArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>(args?: SelectSubset<T, FindFirstArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options> | null>;
2010
1936
  /**
2011
1937
  * Returns the first entity or throws `NotFoundError` if not found.
2012
1938
  * @param args - query args
2013
1939
  * @returns a single entity
2014
1940
  * @see {@link findMany}
2015
1941
  */
2016
- findFirstOrThrow<T extends FindFirstArgs<Schema, Model>>(args?: SelectSubset<T, FindFirstArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
1942
+ findFirstOrThrow<T extends FindFirstArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>(args?: SelectSubset<T, FindFirstArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2017
1943
  /**
2018
1944
  * Creates a new entity.
2019
1945
  * @param args - create args
@@ -2066,7 +1992,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2066
1992
  * });
2067
1993
  * ```
2068
1994
  */
2069
- create<T extends CreateArgs<Schema, Model>>(args: SelectSubset<T, CreateArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
1995
+ create<T extends CreateArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'create'>>(args: SelectSubset<T, CreateArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'create'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2070
1996
  /**
2071
1997
  * Creates multiple entities. Only scalar fields are allowed.
2072
1998
  * @param args - create args
@@ -2092,7 +2018,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2092
2018
  * });
2093
2019
  * ```
2094
2020
  */
2095
- createMany<T extends CreateManyArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
2021
+ createMany<T extends CreateManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'createMany'>>(args?: SelectSubset<T, CreateManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'createMany'>>): ZenStackPromise<Schema, BatchResult>;
2096
2022
  /**
2097
2023
  * Creates multiple entities and returns them.
2098
2024
  * @param args - create args. See {@link createMany} for input. Use
@@ -2111,7 +2037,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2111
2037
  * });
2112
2038
  * ```
2113
2039
  */
2114
- createManyAndReturn<T extends CreateManyAndReturnArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
2040
+ createManyAndReturn<T extends CreateManyAndReturnArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'createManyAndReturn'>>(args?: SelectSubset<T, CreateManyAndReturnArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'createManyAndReturn'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
2115
2041
  /**
2116
2042
  * Updates a uniquely identified entity.
2117
2043
  * @param args - update args. See {@link findMany} for how to control
@@ -2229,7 +2155,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2229
2155
  * });
2230
2156
  * ```
2231
2157
  */
2232
- update<T extends UpdateArgs<Schema, Model>>(args: SelectSubset<T, UpdateArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2158
+ update<T extends UpdateArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'update'>>(args: SelectSubset<T, UpdateArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'update'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2233
2159
  /**
2234
2160
  * Updates multiple entities.
2235
2161
  * @param args - update args. Only scalar fields are allowed for data.
@@ -2250,7 +2176,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2250
2176
  * limit: 10
2251
2177
  * });
2252
2178
  */
2253
- updateMany<T extends UpdateManyArgs<Schema, Model>>(args: Subset<T, UpdateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
2179
+ updateMany<T extends UpdateManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'updateMany'>>(args: Subset<T, UpdateManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'updateMany'>>): ZenStackPromise<Schema, BatchResult>;
2254
2180
  /**
2255
2181
  * Updates multiple entities and returns them.
2256
2182
  * @param args - update args. Only scalar fields are allowed for data.
@@ -2273,7 +2199,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2273
2199
  * });
2274
2200
  * ```
2275
2201
  */
2276
- updateManyAndReturn<T extends UpdateManyAndReturnArgs<Schema, Model>>(args: Subset<T, UpdateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
2202
+ updateManyAndReturn<T extends UpdateManyAndReturnArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'updateManyAndReturn'>>(args: Subset<T, UpdateManyAndReturnArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'updateManyAndReturn'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
2277
2203
  /**
2278
2204
  * Creates or updates an entity.
2279
2205
  * @param args - upsert args
@@ -2294,7 +2220,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2294
2220
  * });
2295
2221
  * ```
2296
2222
  */
2297
- upsert<T extends UpsertArgs<Schema, Model>>(args: SelectSubset<T, UpsertArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2223
+ upsert<T extends UpsertArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'upsert'>>(args: SelectSubset<T, UpsertArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'upsert'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2298
2224
  /**
2299
2225
  * Deletes a uniquely identifiable entity.
2300
2226
  * @param args - delete args
@@ -2314,7 +2240,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2314
2240
  * }); // result: `{ id: string; email: string }`
2315
2241
  * ```
2316
2242
  */
2317
- delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2243
+ delete<T extends DeleteArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'delete'>>(args: SelectSubset<T, DeleteArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'delete'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2318
2244
  /**
2319
2245
  * Deletes multiple entities.
2320
2246
  * @param args - delete args
@@ -2334,7 +2260,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2334
2260
  * });
2335
2261
  * ```
2336
2262
  */
2337
- deleteMany<T extends DeleteManyArgs<Schema, Model>>(args?: Subset<T, DeleteManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
2263
+ deleteMany<T extends DeleteManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'deleteMany'>>(args?: Subset<T, DeleteManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'deleteMany'>>): ZenStackPromise<Schema, BatchResult>;
2338
2264
  /**
2339
2265
  * Counts rows or field values.
2340
2266
  * @param args - count args
@@ -2353,7 +2279,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2353
2279
  * select: { _all: true, email: true }
2354
2280
  * }); // result: `{ _all: number, email: number }`
2355
2281
  */
2356
- count<T extends CountArgs<Schema, Model>>(args?: Subset<T, CountArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<CountResult<Schema, Model, T>>>;
2282
+ count<T extends CountArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'count'>>(args?: Subset<T, CountArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'count'>>): ZenStackPromise<Schema, Simplify<CountResult<Schema, Model, T>>>;
2357
2283
  /**
2358
2284
  * Aggregates rows.
2359
2285
  * @param args - aggregation args
@@ -2371,7 +2297,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2371
2297
  * _max: { age: true }
2372
2298
  * }); // result: `{ _count: number, _avg: { age: number }, ... }`
2373
2299
  */
2374
- aggregate<T extends AggregateArgs<Schema, Model>>(args: Subset<T, AggregateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<AggregateResult<Schema, Model, T>>>;
2300
+ aggregate<T extends AggregateArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'aggregate'>>(args: Subset<T, AggregateArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'aggregate'>>): ZenStackPromise<Schema, Simplify<AggregateResult<Schema, Model, T>>>;
2375
2301
  /**
2376
2302
  * Groups rows by columns.
2377
2303
  * @param args - groupBy args
@@ -2405,7 +2331,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2405
2331
  * having: { country: 'US', age: { _avg: { gte: 18 } } }
2406
2332
  * });
2407
2333
  */
2408
- groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
2334
+ groupBy<T extends GroupByArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'groupBy'>>(args: Subset<T, GroupByArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'groupBy'>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
2409
2335
  /**
2410
2336
  * Checks if an entity exists.
2411
2337
  * @param args - exists args
@@ -2423,10 +2349,10 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2423
2349
  * where: { posts: { some: { published: true } } },
2424
2350
  * }); // result: `boolean`
2425
2351
  */
2426
- exists<T extends ExistsArgs<Schema, Model>>(args?: Subset<T, ExistsArgs<Schema, Model>>): ZenStackPromise<Schema, boolean>;
2352
+ exists<T extends ExistsArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'exists'>>(args?: Subset<T, ExistsArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'exists'>>): ZenStackPromise<Schema, boolean>;
2427
2353
  };
2428
2354
  type OperationsIneligibleForDelegateModels = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert';
2429
- type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Omit<AllModelOperations<Schema, Model, Options>, IsDelegateModel<Schema, Model> extends true ? OperationsIneligibleForDelegateModels : never>;
2355
+ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>, ExtQueryArgs = {}> = Omit<AllModelOperations<Schema, Model, Options, ExtQueryArgs>, IsDelegateModel<Schema, Model> extends true ? OperationsIneligibleForDelegateModels : never>;
2430
2356
  /**
2431
2357
  * Type for auth context that includes both scalar and relation fields.
2432
2358
  * Relations are recursively included to allow nested auth data like { user: { profile: { ... } } }
@@ -2436,6 +2362,117 @@ type AuthModelType<Schema extends SchemaDef, Model extends GetModels<Schema>> =
2436
2362
  };
2437
2363
  type AuthType<Schema extends SchemaDef> = Schema['authType'] extends GetModels<Schema> ? AuthModelType<Schema, Schema['authType']> : Schema['authType'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, Schema['authType'], true> : Record<string, unknown>;
2438
2364
 
2365
+ type ZModelFunctionContext<Schema extends SchemaDef> = {
2366
+ /**
2367
+ * ZenStack client instance
2368
+ */
2369
+ client: ClientContract<Schema>;
2370
+ /**
2371
+ * Database dialect
2372
+ */
2373
+ dialect: BaseCrudDialect<Schema>;
2374
+ /**
2375
+ * The containing model name
2376
+ */
2377
+ model: GetModels<Schema>;
2378
+ /**
2379
+ * The alias name that can be used to refer to the containing model
2380
+ */
2381
+ modelAlias: string;
2382
+ /**
2383
+ * The CRUD operation being performed
2384
+ */
2385
+ operation: CRUD_EXT;
2386
+ };
2387
+ type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
2388
+ /**
2389
+ * ZenStack client options.
2390
+ */
2391
+ type ClientOptions<Schema extends SchemaDef> = {
2392
+ /**
2393
+ * Kysely dialect.
2394
+ */
2395
+ dialect: Dialect;
2396
+ /**
2397
+ * Custom function definitions.
2398
+ *
2399
+ * @private
2400
+ */
2401
+ functions?: Record<string, ZModelFunction<Schema>>;
2402
+ /**
2403
+ * Plugins.
2404
+ */
2405
+ plugins?: RuntimePlugin<any, any>[];
2406
+ /**
2407
+ * Logging configuration.
2408
+ */
2409
+ log?: KyselyConfig['log'];
2410
+ /**
2411
+ * Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
2412
+ * to `true`.
2413
+ *
2414
+ * Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
2415
+ * `Date` object) although for `DateTime` field the data in DB is stored in UTC.
2416
+ * @see https://github.com/brianc/node-postgres/issues/429
2417
+ */
2418
+ fixPostgresTimezone?: boolean;
2419
+ /**
2420
+ * Whether to enable input validations expressed with attributes like `@email`, `@regex`,
2421
+ * `@@validate`, etc. Defaults to `true`.
2422
+ */
2423
+ validateInput?: boolean;
2424
+ /**
2425
+ * Options for omitting fields in ORM query results.
2426
+ */
2427
+ omit?: OmitConfig<Schema>;
2428
+ /**
2429
+ * Whether to allow overriding omit settings at query time. Defaults to `true`. When set to
2430
+ * `false`, an `omit` clause that sets field to `false` (not omitting) will trigger a validation
2431
+ * error.
2432
+ */
2433
+ allowQueryTimeOmitOverride?: boolean;
2434
+ } & (HasComputedFields<Schema> extends true ? {
2435
+ /**
2436
+ * Computed field definitions.
2437
+ */
2438
+ computedFields: ComputedFieldsOptions<Schema>;
2439
+ } : {}) & (HasProcedures<Schema> extends true ? {
2440
+ /**
2441
+ * Custom procedure definitions.
2442
+ */
2443
+ procedures: ProceduresOptions<Schema>;
2444
+ } : {});
2445
+ /**
2446
+ * Config for omitting fields in ORM query results.
2447
+ */
2448
+ type OmitConfig<Schema extends SchemaDef> = {
2449
+ [Model in GetModels<Schema>]?: {
2450
+ [Field in GetModelFields<Schema, Model> as Field extends ScalarFields<Schema, Model> ? Field : never]?: boolean;
2451
+ };
2452
+ };
2453
+ type ComputedFieldsOptions<Schema extends SchemaDef> = {
2454
+ [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
2455
+ [Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
2456
+ };
2457
+ };
2458
+ type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
2459
+ type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
2460
+ procedures: Record<string, ProcedureDef>;
2461
+ } ? {
2462
+ [Key in GetProcedureNames<Schema>]: ProcedureHandlerFunc<Schema, Key>;
2463
+ } : {};
2464
+ type HasProcedures<Schema extends SchemaDef> = Schema extends {
2465
+ procedures: Record<string, ProcedureDef>;
2466
+ } ? true : false;
2467
+ /**
2468
+ * Subset of client options relevant to query operations.
2469
+ */
2470
+ type QueryOptions<Schema extends SchemaDef> = Pick<ClientOptions<Schema>, 'omit'>;
2471
+ /**
2472
+ * Extract QueryOptions from ClientOptions
2473
+ */
2474
+ type ToQueryOptions<T extends ClientOptions<any>> = Pick<T, 'omit'>;
2475
+
2439
2476
  /**
2440
2477
  * ZenStack ORM client.
2441
2478
  */
@@ -2668,4 +2705,4 @@ declare namespace schemaUtils {
2668
2705
  export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
2669
2706
  }
2670
2707
 
2671
- export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, type AllModelOperations, AnyNull, AnyNullClass, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type CoreCrudOperation as CrudOperation, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitInput, type OmitOptions, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SortOrder, type StringFilter, type Subset, type ToKysely, type ToQueryOptions, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, definePlugin, getCrudDialect };
2708
+ export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCrudOperations, CoreReadOperations, CoreWriteOperations, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type ExtQueryArgsBase, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitConfig, type OmitInput, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SortOrder, type StringFilter, type Subset, type ToKysely, type ToQueryOptions, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, definePlugin, getCrudDialect };