@zenstackhq/orm 3.2.1 → 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.cts 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,478 +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>;
565
- /**
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> & {
355
+ contains?: string;
582
356
  /**
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
- } & ('_count' extends keyof I ? I['_count'] extends false | undefined ? {} : {
756
- _count: SelectCountResult<Schema, Model, I['_count']>;
757
- } : {}) : Args extends {
758
- omit: infer O;
759
- } & Record<string, unknown> ? DefaultModelResult<Schema, Model, O, Options, false, false> : DefaultModelResult<Schema, Model, undefined, Options, false, false>, Optional, Array>;
760
- 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>>;
761
- type SimplifiedPlainResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Simplify<ModelResult<Schema, Model, Args, Options, false, false>>;
762
- type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = PartialIf<Optional<{
763
- [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial>;
764
- }, Partial extends true ? never : keyof {
765
- [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true;
766
- }>, Partial> & Record<string, unknown>;
767
- type BatchResult = {
768
- count: number;
769
- };
770
- type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ScalarOnly extends boolean = false, WithAggregations extends boolean = false> = {
771
- [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>;
772
- } & {
773
- $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
774
- } & {
775
- AND?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
776
- OR?: WhereInput<Schema, Model, ScalarOnly>[];
777
- NOT?: OrArray<WhereInput<Schema, Model, ScalarOnly>>;
778
- };
779
- 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>;
780
440
  /**
781
- * Checks for equality with the specified enum value.
441
+ * Filters against the minimum value.
782
442
  */
783
- equals?: NullableIf<keyof GetEnum<Schema, T>, Nullable>;
443
+ _min?: BytesFilter<false, false>;
784
444
  /**
785
- * Checks if the enum value is in the specified list of values.
445
+ * Filters against the maximum value.
786
446
  */
787
- in?: (keyof GetEnum<Schema, T>)[];
447
+ _max?: BytesFilter<false, false>;
448
+ } : {}));
449
+ type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<boolean, Nullable> | ({
788
450
  /**
789
- * Checks if the enum value is not in the specified list of values.
451
+ * Checks for equality with the specified value.
790
452
  */
791
- notIn?: (keyof GetEnum<Schema, T>)[];
453
+ equals?: NullableIf<boolean, Nullable>;
792
454
  /**
793
455
  * Builds a negated filter.
794
456
  */
795
- not?: EnumFilter<Schema, T, Nullable, WithAggregations>;
457
+ not?: BooleanFilter<Nullable, WithAggregations>;
796
458
  } & (WithAggregations extends true ? {
797
459
  /**
798
460
  * Filters against the count of records.
@@ -801,204 +463,25 @@ type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable e
801
463
  /**
802
464
  * Filters against the minimum value.
803
465
  */
804
- _min?: EnumFilter<Schema, T, false, false>;
466
+ _min?: BooleanFilter<false, false>;
805
467
  /**
806
468
  * Filters against the maximum value.
807
469
  */
808
- _max?: EnumFilter<Schema, T, false, false>;
470
+ _max?: BooleanFilter<false, false>;
809
471
  } : {}));
810
- type ArrayFilter<Schema extends SchemaDef, Type extends string> = {
472
+ type JsonFilter = {
811
473
  /**
812
- * 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.
813
475
  */
814
- equals?: MapScalarType<Schema, Type>[] | null;
476
+ path?: string;
815
477
  /**
816
- * Checks if the array contains all elements of the specified array.
478
+ * Checks for equality with the specified value.
817
479
  */
818
- has?: MapScalarType<Schema, Type> | null;
480
+ equals?: JsonValue | JsonNullValues;
819
481
  /**
820
- * Checks if the array contains any of the elements of the specified array.
482
+ * Builds a negated filter.
821
483
  */
822
- hasEvery?: MapScalarType<Schema, Type>[];
823
- /**
824
- * Checks if the array contains some of the elements of the specified array.
825
- */
826
- hasSome?: MapScalarType<Schema, Type>[];
827
- /**
828
- * Checks if the array is empty.
829
- */
830
- isEmpty?: boolean;
831
- };
832
- type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
833
- 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;
834
- type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean> = {
835
- /**
836
- * Checks for equality with the specified value.
837
- */
838
- equals?: NullableIf<DataType, Nullable>;
839
- /**
840
- * Checks if the value is in the specified list of values.
841
- */
842
- in?: DataType[];
843
- /**
844
- * Checks if the value is not in the specified list of values.
845
- */
846
- notIn?: DataType[];
847
- /**
848
- * Checks if the value is less than the specified value.
849
- */
850
- lt?: DataType;
851
- /**
852
- * Checks if the value is less than or equal to the specified value.
853
- */
854
- lte?: DataType;
855
- /**
856
- * Checks if the value is greater than the specified value.
857
- */
858
- gt?: DataType;
859
- /**
860
- * Checks if the value is greater than or equal to the specified value.
861
- */
862
- gte?: DataType;
863
- /**
864
- * Builds a negated filter.
865
- */
866
- not?: PrimitiveFilter<T, Nullable, WithAggregations>;
867
- };
868
- type StringFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<string, Nullable> | (CommonPrimitiveFilter<string, 'String', Nullable, WithAggregations> & {
869
- /**
870
- * Checks if the string contains the specified substring.
871
- */
872
- contains?: string;
873
- /**
874
- * Checks if the string starts with the specified substring.
875
- */
876
- startsWith?: string;
877
- /**
878
- * Checks if the string ends with the specified substring.
879
- */
880
- endsWith?: string;
881
- /**
882
- * Specifies the string comparison mode. Not effective for "sqlite" provider
883
- */
884
- mode?: 'default' | 'insensitive';
885
- } & (WithAggregations extends true ? {
886
- /**
887
- * Filters against the count of records.
888
- */
889
- _count?: NumberFilter<'Int', false, false>;
890
- /**
891
- * Filters against the minimum value.
892
- */
893
- _min?: StringFilter<false, false>;
894
- /**
895
- * Filters against the maximum value.
896
- */
897
- _max?: StringFilter<false, false>;
898
- } : {}));
899
- 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 ? {
900
- /**
901
- * Filters against the count of records.
902
- */
903
- _count?: NumberFilter<'Int', false, false>;
904
- /**
905
- * Filters against the average value.
906
- */
907
- _avg?: NumberFilter<T, false, false>;
908
- /**
909
- * Filters against the sum value.
910
- */
911
- _sum?: NumberFilter<T, false, false>;
912
- /**
913
- * Filters against the minimum value.
914
- */
915
- _min?: NumberFilter<T, false, false>;
916
- /**
917
- * Filters against the maximum value.
918
- */
919
- _max?: NumberFilter<T, false, false>;
920
- } : {}));
921
- type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Date | string, Nullable> | (CommonPrimitiveFilter<Date | string, 'DateTime', Nullable, WithAggregations> & (WithAggregations extends true ? {
922
- /**
923
- * Filters against the count of records.
924
- */
925
- _count?: NumberFilter<'Int', false, false>;
926
- /**
927
- * Filters against the minimum value.
928
- */
929
- _min?: DateTimeFilter<false, false>;
930
- /**
931
- * Filters against the maximum value.
932
- */
933
- _max?: DateTimeFilter<false, false>;
934
- } : {}));
935
- type BytesFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Uint8Array | Buffer, Nullable> | ({
936
- /**
937
- * Checks for equality with the specified value.
938
- */
939
- equals?: NullableIf<Uint8Array, Nullable>;
940
- /**
941
- * Checks if the value is in the specified list of values.
942
- */
943
- in?: Uint8Array[];
944
- /**
945
- * Checks if the value is not in the specified list of values.
946
- */
947
- notIn?: Uint8Array[];
948
- /**
949
- * Builds a negated filter.
950
- */
951
- not?: BytesFilter<Nullable, WithAggregations>;
952
- } & (WithAggregations extends true ? {
953
- /**
954
- * Filters against the count of records.
955
- */
956
- _count?: NumberFilter<'Int', false, false>;
957
- /**
958
- * Filters against the minimum value.
959
- */
960
- _min?: BytesFilter<false, false>;
961
- /**
962
- * Filters against the maximum value.
963
- */
964
- _max?: BytesFilter<false, false>;
965
- } : {}));
966
- type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<boolean, Nullable> | ({
967
- /**
968
- * Checks for equality with the specified value.
969
- */
970
- equals?: NullableIf<boolean, Nullable>;
971
- /**
972
- * Builds a negated filter.
973
- */
974
- not?: BooleanFilter<Nullable, WithAggregations>;
975
- } & (WithAggregations extends true ? {
976
- /**
977
- * Filters against the count of records.
978
- */
979
- _count?: NumberFilter<'Int', false, false>;
980
- /**
981
- * Filters against the minimum value.
982
- */
983
- _min?: BooleanFilter<false, false>;
984
- /**
985
- * Filters against the maximum value.
986
- */
987
- _max?: BooleanFilter<false, false>;
988
- } : {}));
989
- type JsonFilter = {
990
- /**
991
- * JSON path to select the value to filter on. If omitted, the whole JSON value is used.
992
- */
993
- path?: string;
994
- /**
995
- * Checks for equality with the specified value.
996
- */
997
- equals?: JsonValue | JsonNullValues;
998
- /**
999
- * Builds a negated filter.
1000
- */
1001
- not?: JsonValue | JsonNullValues;
484
+ not?: JsonValue | JsonNullValues;
1002
485
  /**
1003
486
  * Checks if the value is a string and contains the specified substring.
1004
487
  */
@@ -1617,120 +1100,557 @@ type GroupByResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Ar
1617
1100
  _min: infer Min;
1618
1101
  } ? {
1619
1102
  /**
1620
- * 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`.
1621
1594
  */
1622
- _min: AggCommonOutput<Min>;
1623
- } : {}) & (Args extends {
1624
- _max: infer Max;
1625
- } ? {
1595
+ runAfterMutationWithinTransaction?: boolean;
1596
+ };
1597
+ type MutationHooksArgs<Schema extends SchemaDef> = {
1626
1598
  /**
1627
- * Maximum aggregation result
1599
+ * The model that is being mutated.
1628
1600
  */
1629
- _max: AggCommonOutput<Max>;
1630
- } : {})>;
1631
- 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>>;
1632
- 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>>;
1633
- 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>>;
1634
- type SetRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>>;
1635
- 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>;
1636
1602
  /**
1637
- * Unique filter to select the record to update.
1603
+ * The mutation action that is being performed.
1638
1604
  */
1639
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1605
+ action: 'create' | 'update' | 'delete';
1640
1606
  /**
1641
- * The data to update the record with.
1607
+ * The mutation data. Only available for create and update actions.
1642
1608
  */
1643
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1644
- }, true> : XOR<{
1609
+ queryNode: OperationNode;
1645
1610
  /**
1646
- * 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.
1647
1613
  */
1648
- 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> & {
1649
1619
  /**
1650
- * 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.
1651
1622
  */
1652
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1653
- }, UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>>;
1654
- type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<{
1623
+ loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
1655
1624
  /**
1656
- * 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.
1657
1630
  */
1658
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1631
+ client: ClientContract<Schema>;
1632
+ };
1633
+ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
1659
1634
  /**
1660
- * The data to create the record if it doesn't exist.
1635
+ * Loads the entities that have been mutated.
1661
1636
  */
1662
- create: CreateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1637
+ loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
1663
1638
  /**
1664
- * 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.
1665
1643
  */
1666
- update: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1667
- }, FieldIsArray<Schema, Model, Field>>;
1668
- 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>>>;
1669
- 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>>;
1670
- type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, true>>;
1671
- type GetProcedureNames<Schema extends SchemaDef> = Schema extends {
1672
- procedures: Record<string, ProcedureDef>;
1673
- } ? keyof Schema['procedures'] : never;
1674
- type GetProcedureParams<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1675
- procedures: Record<string, ProcedureDef>;
1676
- } ? Schema['procedures'][ProcName]['params'] : never;
1677
- type GetProcedure<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1678
- procedures: Record<string, ProcedureDef>;
1679
- } ? Schema['procedures'][ProcName] : never;
1680
- type _OptionalProcedureParamNames<Params> = keyof {
1681
- [K in keyof Params as Params[K] extends {
1682
- optional: true;
1683
- } ? K : never]: K;
1684
- };
1685
- type _RequiredProcedureParamNames<Params> = keyof {
1686
- [K in keyof Params as Params[K] extends {
1687
- optional: true;
1688
- } ? never : K]: K;
1689
- };
1690
- type _HasRequiredProcedureParams<Params> = _RequiredProcedureParamNames<Params> extends never ? false : true;
1691
- type MapProcedureArgsObject<Schema extends SchemaDef, Params> = Simplify<Optional<{
1692
- [K in keyof Params]: MapProcedureParam<Schema, Params[K]>;
1693
- }, _OptionalProcedureParamNames<Params>>>;
1694
- type ProcedureEnvelope<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>, Params = GetProcedureParams<Schema, ProcName>> = keyof Params extends never ? {
1695
- args?: Record<string, never>;
1696
- } : _HasRequiredProcedureParams<Params> extends true ? {
1697
- args: MapProcedureArgsObject<Schema, Params>;
1698
- } : {
1699
- args?: MapProcedureArgsObject<Schema, Params>;
1644
+ client: ClientContract<Schema>;
1700
1645
  };
1701
- type ProcedureHandlerCtx<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = {
1646
+ type OnKyselyQueryArgs<Schema extends SchemaDef> = {
1647
+ schema: SchemaDef;
1702
1648
  client: ClientContract<Schema>;
1703
- } & ProcedureEnvelope<Schema, ProcName>;
1704
- /**
1705
- * Shape of a procedure's runtime function.
1706
- */
1707
- 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>>>;
1708
- /**
1709
- * Signature for procedure handlers configured via client options.
1710
- */
1711
- type ProcedureHandlerFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (ctx: ProcedureHandlerCtx<Schema, ProcName>) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
1712
- type MapProcedureReturn<Schema extends SchemaDef, Proc> = Proc extends {
1713
- returnType: infer R;
1714
- } ? Proc extends {
1715
- returnArray: true;
1716
- } ? Array<MapType<Schema, R & string>> : MapType<Schema, R & string> : never;
1717
- type MapProcedureParam<Schema extends SchemaDef, P> = P extends {
1718
- type: infer U;
1719
- } ? OrUndefinedIf<P extends {
1720
- array: true;
1721
- } ? Array<MapType<Schema, U & string>> : MapType<Schema, U & string>, P extends {
1722
- optional: true;
1723
- } ? true : false> : never;
1724
- type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1725
- [Key in RelationFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends {
1726
- references: readonly unknown[];
1727
- } ? never : Key]: true;
1649
+ query: RootOperationNode;
1650
+ proceed: ProceedKyselyQueryFunction;
1728
1651
  };
1729
- type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1730
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
1731
- } extends never ? false : true;
1732
- type EnumValue<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = GetEnum<Schema, Enum>[keyof GetEnum<Schema, Enum>];
1733
- 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>>;
1734
1654
 
1735
1655
  /**
1736
1656
  * A promise that only executes when it's awaited or .then() is called.
@@ -1744,6 +1664,10 @@ type ZenStackPromise<Schema extends SchemaDef, T> = Promise<T> & {
1744
1664
  };
1745
1665
 
1746
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']> : {};
1747
1671
  /**
1748
1672
  * Transaction isolation levels.
1749
1673
  */
@@ -1757,7 +1681,7 @@ declare enum TransactionIsolationLevel {
1757
1681
  /**
1758
1682
  * ZenStack client interface.
1759
1683
  */
1760
- 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 = {}> = {
1761
1685
  /**
1762
1686
  * The schema definition.
1763
1687
  */
@@ -1807,7 +1731,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1807
1731
  /**
1808
1732
  * Sets the current user identity.
1809
1733
  */
1810
- $setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options>;
1734
+ $setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema, Options, ExtQueryArgs>;
1811
1735
  /**
1812
1736
  * Returns a new client with new options applied.
1813
1737
  * @example
@@ -1815,14 +1739,14 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1815
1739
  * const dbNoValidation = db.$setOptions({ ...db.$options, validateInput: false });
1816
1740
  * ```
1817
1741
  */
1818
- $setOptions<Options extends ClientOptions<Schema>>(options: Options): ClientContract<Schema, Options>;
1742
+ $setOptions<Options extends ClientOptions<Schema>>(options: Options): ClientContract<Schema, Options, ExtQueryArgs>;
1819
1743
  /**
1820
1744
  * Returns a new client enabling/disabling input validations expressed with attributes like
1821
1745
  * `@email`, `@regex`, `@@validate`, etc.
1822
1746
  *
1823
- * @deprecated Use `$setOptions` instead.
1747
+ * @deprecated Use {@link $setOptions} instead.
1824
1748
  */
1825
- $setInputValidation(enable: boolean): ClientContract<Schema, Options>;
1749
+ $setInputValidation(enable: boolean): ClientContract<Schema, Options, ExtQueryArgs>;
1826
1750
  /**
1827
1751
  * The Kysely query builder instance.
1828
1752
  */
@@ -1834,7 +1758,7 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1834
1758
  /**
1835
1759
  * Starts an interactive transaction.
1836
1760
  */
1837
- $transaction<T>(callback: (tx: Omit<ClientContract<Schema, Options>, TransactionUnsupportedMethods>) => Promise<T>, options?: {
1761
+ $transaction<T>(callback: (tx: TransactionClientContract<Schema, Options, ExtQueryArgs>) => Promise<T>, options?: {
1838
1762
  isolationLevel?: TransactionIsolationLevel;
1839
1763
  }): Promise<T>;
1840
1764
  /**
@@ -1846,11 +1770,11 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1846
1770
  /**
1847
1771
  * Returns a new client with the specified plugin installed.
1848
1772
  */
1849
- $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>;
1850
1774
  /**
1851
1775
  * Returns a new client with the specified plugin removed.
1852
1776
  */
1853
- $unuse(pluginId: string): ClientContract<Schema, Options>;
1777
+ $unuse(pluginId: string): ClientContract<Schema, Options, ExtQueryArgs>;
1854
1778
  /**
1855
1779
  * Returns a new client with all plugins removed.
1856
1780
  */
@@ -1869,12 +1793,12 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1869
1793
  */
1870
1794
  $pushSchema(): Promise<void>;
1871
1795
  } & {
1872
- [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>;
1873
1797
  } & ProcedureOperations<Schema>;
1874
1798
  /**
1875
1799
  * The contract for a client in a transaction.
1876
1800
  */
1877
- 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>;
1878
1802
  type ProcedureOperations<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
1879
1803
  /**
1880
1804
  * Custom procedures.
@@ -1905,7 +1829,7 @@ type CRUD_EXT = CRUD | 'post-update';
1905
1829
  * Extended CRUD operations including 'post-update'.
1906
1830
  */
1907
1831
  declare const CRUD_EXT: readonly ["create", "read", "update", "delete", "post-update"];
1908
- 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> = {
1909
1833
  /**
1910
1834
  * Returns a list of entities.
1911
1835
  * @param args - query args
@@ -1987,35 +1911,35 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
1987
1911
  * }); // result: `{ _count: { posts: number } }`
1988
1912
  * ```
1989
1913
  */
1990
- 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>[]>;
1991
1915
  /**
1992
1916
  * Returns a uniquely identified entity.
1993
1917
  * @param args - query args
1994
1918
  * @returns a single entity or null if not found
1995
1919
  * @see {@link findMany}
1996
1920
  */
1997
- 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>;
1998
1922
  /**
1999
1923
  * Returns a uniquely identified entity or throws `NotFoundError` if not found.
2000
1924
  * @param args - query args
2001
1925
  * @returns a single entity
2002
1926
  * @see {@link findMany}
2003
1927
  */
2004
- 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>>;
2005
1929
  /**
2006
1930
  * Returns the first entity.
2007
1931
  * @param args - query args
2008
1932
  * @returns a single entity or null if not found
2009
1933
  * @see {@link findMany}
2010
1934
  */
2011
- 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>;
2012
1936
  /**
2013
1937
  * Returns the first entity or throws `NotFoundError` if not found.
2014
1938
  * @param args - query args
2015
1939
  * @returns a single entity
2016
1940
  * @see {@link findMany}
2017
1941
  */
2018
- 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>>;
2019
1943
  /**
2020
1944
  * Creates a new entity.
2021
1945
  * @param args - create args
@@ -2068,7 +1992,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2068
1992
  * });
2069
1993
  * ```
2070
1994
  */
2071
- 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>>;
2072
1996
  /**
2073
1997
  * Creates multiple entities. Only scalar fields are allowed.
2074
1998
  * @param args - create args
@@ -2094,7 +2018,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2094
2018
  * });
2095
2019
  * ```
2096
2020
  */
2097
- 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>;
2098
2022
  /**
2099
2023
  * Creates multiple entities and returns them.
2100
2024
  * @param args - create args. See {@link createMany} for input. Use
@@ -2113,7 +2037,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2113
2037
  * });
2114
2038
  * ```
2115
2039
  */
2116
- 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>[]>;
2117
2041
  /**
2118
2042
  * Updates a uniquely identified entity.
2119
2043
  * @param args - update args. See {@link findMany} for how to control
@@ -2231,7 +2155,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2231
2155
  * });
2232
2156
  * ```
2233
2157
  */
2234
- 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>>;
2235
2159
  /**
2236
2160
  * Updates multiple entities.
2237
2161
  * @param args - update args. Only scalar fields are allowed for data.
@@ -2252,7 +2176,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2252
2176
  * limit: 10
2253
2177
  * });
2254
2178
  */
2255
- 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>;
2256
2180
  /**
2257
2181
  * Updates multiple entities and returns them.
2258
2182
  * @param args - update args. Only scalar fields are allowed for data.
@@ -2275,7 +2199,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2275
2199
  * });
2276
2200
  * ```
2277
2201
  */
2278
- 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>[]>;
2279
2203
  /**
2280
2204
  * Creates or updates an entity.
2281
2205
  * @param args - upsert args
@@ -2296,7 +2220,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2296
2220
  * });
2297
2221
  * ```
2298
2222
  */
2299
- 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>>;
2300
2224
  /**
2301
2225
  * Deletes a uniquely identifiable entity.
2302
2226
  * @param args - delete args
@@ -2316,7 +2240,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2316
2240
  * }); // result: `{ id: string; email: string }`
2317
2241
  * ```
2318
2242
  */
2319
- 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>>;
2320
2244
  /**
2321
2245
  * Deletes multiple entities.
2322
2246
  * @param args - delete args
@@ -2336,7 +2260,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2336
2260
  * });
2337
2261
  * ```
2338
2262
  */
2339
- 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>;
2340
2264
  /**
2341
2265
  * Counts rows or field values.
2342
2266
  * @param args - count args
@@ -2355,7 +2279,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2355
2279
  * select: { _all: true, email: true }
2356
2280
  * }); // result: `{ _all: number, email: number }`
2357
2281
  */
2358
- 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>>>;
2359
2283
  /**
2360
2284
  * Aggregates rows.
2361
2285
  * @param args - aggregation args
@@ -2373,7 +2297,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2373
2297
  * _max: { age: true }
2374
2298
  * }); // result: `{ _count: number, _avg: { age: number }, ... }`
2375
2299
  */
2376
- 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>>>;
2377
2301
  /**
2378
2302
  * Groups rows by columns.
2379
2303
  * @param args - groupBy args
@@ -2407,7 +2331,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2407
2331
  * having: { country: 'US', age: { _avg: { gte: 18 } } }
2408
2332
  * });
2409
2333
  */
2410
- 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>>>;
2411
2335
  /**
2412
2336
  * Checks if an entity exists.
2413
2337
  * @param args - exists args
@@ -2425,10 +2349,10 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
2425
2349
  * where: { posts: { some: { published: true } } },
2426
2350
  * }); // result: `boolean`
2427
2351
  */
2428
- 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>;
2429
2353
  };
2430
2354
  type OperationsIneligibleForDelegateModels = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert';
2431
- 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>;
2432
2356
  /**
2433
2357
  * Type for auth context that includes both scalar and relation fields.
2434
2358
  * Relations are recursively included to allow nested auth data like { user: { profile: { ... } } }
@@ -2438,6 +2362,117 @@ type AuthModelType<Schema extends SchemaDef, Model extends GetModels<Schema>> =
2438
2362
  };
2439
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>;
2440
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
+
2441
2476
  /**
2442
2477
  * ZenStack ORM client.
2443
2478
  */
@@ -2670,4 +2705,4 @@ declare namespace schemaUtils {
2670
2705
  export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
2671
2706
  }
2672
2707
 
2673
- 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 };