@zenstackhq/orm 3.4.0-beta.1 → 3.4.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,79 +1,10 @@
1
1
  import * as _zenstackhq_schema 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, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, ProcedureDef, ModelDef, DataSourceProviderType, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, ThisExpression, NullExpression } 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, UpdatedAtInfo, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, BindingExpression, 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, Generated, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, AliasableExpression, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } 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, AliasableExpression, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig, OperandExpression } from 'kysely';
5
5
  import Decimal from 'decimal.js';
6
6
  import { z, ZodType } from 'zod';
7
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
- };
76
-
77
8
  declare class DefaultOperationNodeVisitor extends OperationNodeVisitor {
78
9
  protected defaultVisit(node: OperationNode): void;
79
10
  protected visitSelectQuery(node: SelectQueryNode): void;
@@ -183,6 +114,75 @@ declare namespace kyselyUtils {
183
114
  export { type kyselyUtils_AnyKysely as AnyKysely, kyselyUtils_DefaultOperationNodeVisitor as DefaultOperationNodeVisitor };
184
115
  }
185
116
 
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
  */
@@ -194,1554 +194,1883 @@ declare const LOGICAL_COMBINATORS: readonly ["AND", "OR", "NOT"];
194
194
  /**
195
195
  * Aggregation operators.
196
196
  */
197
- declare const AGGREGATE_OPERATORS: readonly ["_count", "_sum", "_avg", "_min", "_max"];
198
- type AGGREGATE_OPERATORS = (typeof AGGREGATE_OPERATORS)[number];
199
-
200
- type ToKyselySchema<Schema extends SchemaDef> = {
201
- [Model in GetModels<Schema>]: ToKyselyTable<Schema, Model>;
202
- };
203
- type ToKysely<Schema extends SchemaDef> = Kysely<ToKyselySchema<Schema>>;
204
- type ToKyselyTable<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
205
- [Field in ScalarFields<Schema, Model, false> | ForeignKeyFields<Schema, Model> as GetModelField<Schema, Model, Field>['originModel'] extends string ? never : Field]: toKyselyFieldType<Schema, Model, Field>;
197
+ declare const AggregateOperators: readonly ["_count", "_sum", "_avg", "_min", "_max"];
198
+ type AggregateOperators = (typeof AggregateOperators)[number];
199
+ /**
200
+ * Mapping of filter operators to their corresponding filter kind categories.
201
+ */
202
+ declare const FILTER_PROPERTY_TO_KIND: {
203
+ readonly equals: "Equality";
204
+ readonly not: "Equality";
205
+ readonly in: "Equality";
206
+ readonly notIn: "Equality";
207
+ readonly lt: "Range";
208
+ readonly lte: "Range";
209
+ readonly gt: "Range";
210
+ readonly gte: "Range";
211
+ readonly between: "Range";
212
+ readonly contains: "Like";
213
+ readonly startsWith: "Like";
214
+ readonly endsWith: "Like";
215
+ readonly mode: "Like";
216
+ readonly is: "Relation";
217
+ readonly isNot: "Relation";
218
+ readonly some: "Relation";
219
+ readonly every: "Relation";
220
+ readonly none: "Relation";
221
+ readonly path: "Json";
222
+ readonly string_contains: "Json";
223
+ readonly string_starts_with: "Json";
224
+ readonly string_ends_with: "Json";
225
+ readonly array_contains: "Json";
226
+ readonly array_starts_with: "Json";
227
+ readonly array_ends_with: "Json";
228
+ readonly has: "List";
229
+ readonly hasEvery: "List";
230
+ readonly hasSome: "List";
231
+ readonly isEmpty: "List";
206
232
  };
207
- type MapBaseType<T> = T extends 'String' ? string : T extends 'Boolean' ? boolean : T extends 'Int' | 'Float' ? number : T extends 'BigInt' ? bigint : T extends 'Decimal' ? Decimal : T extends 'DateTime' ? string : unknown;
208
- type WrapNull<T, Null> = Null extends true ? T | null : T;
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>>;
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>;
233
+ /**
234
+ * Mapping of filter operators to their corresponding filter kind categories.
235
+ */
236
+ type FilterPropertyToKind = typeof FILTER_PROPERTY_TO_KIND;
211
237
 
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> | ({
263
- /**
264
- * Checks for equality with the specified enum value.
265
- */
266
- equals?: NullableIf<keyof GetEnum<Schema, T>, Nullable>;
267
- /**
268
- * Checks if the enum value is in the specified list of values.
269
- */
270
- in?: (keyof GetEnum<Schema, T>)[];
271
- /**
272
- * Checks if the enum value is not in the specified list of values.
273
- */
274
- notIn?: (keyof GetEnum<Schema, T>)[];
275
- /**
276
- * Builds a negated filter.
277
- */
278
- not?: EnumFilter<Schema, T, Nullable, WithAggregations>;
279
- } & (WithAggregations extends true ? {
280
- /**
281
- * Filters against the count of records.
282
- */
283
- _count?: NumberFilter<'Int', false, false>;
238
+ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
239
+ protected readonly schema: Schema;
240
+ protected readonly options: ClientOptions<Schema>;
241
+ protected eb: ExpressionBuilder<any, any>;
242
+ constructor(schema: Schema, options: ClientOptions<Schema>);
284
243
  /**
285
- * Filters against the minimum value.
244
+ * Whether the dialect supports updating with a limit on the number of updated rows.
286
245
  */
287
- _min?: EnumFilter<Schema, T, false, false>;
246
+ abstract get supportsUpdateWithLimit(): boolean;
288
247
  /**
289
- * Filters against the maximum value.
248
+ * Whether the dialect supports deleting with a limit on the number of deleted rows.
290
249
  */
291
- _max?: EnumFilter<Schema, T, false, false>;
292
- } : {}));
293
- type ArrayFilter<Schema extends SchemaDef, Type extends string> = {
250
+ abstract get supportsDeleteWithLimit(): boolean;
294
251
  /**
295
- * Checks if the array equals the specified array.
252
+ * Whether the dialect supports DISTINCT ON.
296
253
  */
297
- equals?: MapScalarType<Schema, Type>[] | null;
254
+ abstract get supportsDistinctOn(): boolean;
298
255
  /**
299
- * Checks if the array contains all elements of the specified array.
256
+ * Whether the dialect support inserting with `DEFAULT` as field value.
300
257
  */
301
- has?: MapScalarType<Schema, Type> | null;
258
+ abstract get supportsDefaultAsFieldValue(): boolean;
302
259
  /**
303
- * Checks if the array contains any of the elements of the specified array.
260
+ * Whether the dialect supports the RETURNING clause in INSERT/UPDATE/DELETE statements.
304
261
  */
305
- hasEvery?: MapScalarType<Schema, Type>[];
262
+ abstract get supportsReturning(): boolean;
306
263
  /**
307
- * Checks if the array contains some of the elements of the specified array.
264
+ * Whether the dialect supports `INSERT INTO ... DEFAULT VALUES` syntax.
308
265
  */
309
- hasSome?: MapScalarType<Schema, Type>[];
266
+ abstract get supportsInsertDefaultValues(): boolean;
310
267
  /**
311
- * Checks if the array is empty.
268
+ * How to perform insert ignore operation.
312
269
  */
313
- isEmpty?: boolean;
314
- };
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> = {
270
+ abstract get insertIgnoreMethod(): 'onConflict' | 'ignore';
318
271
  /**
319
- * Checks for equality with the specified value.
272
+ * Transforms input value before sending to database.
320
273
  */
321
- equals?: NullableIf<DataType, Nullable>;
274
+ transformInput(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
322
275
  /**
323
- * Checks if the value is in the specified list of values.
276
+ * Transforms output value received from database.
324
277
  */
325
- in?: DataType[];
326
- /**
327
- * Checks if the value is not in the specified list of values.
328
- */
329
- notIn?: DataType[];
330
- /**
331
- * Checks if the value is less than the specified value.
332
- */
333
- lt?: DataType;
334
- /**
335
- * Checks if the value is less than or equal to the specified value.
336
- */
337
- lte?: DataType;
338
- /**
339
- * Checks if the value is greater than the specified value.
340
- */
341
- gt?: DataType;
342
- /**
343
- * Checks if the value is greater than or equal to the specified value.
344
- */
345
- gte?: DataType;
346
- /**
347
- * Checks if the value is between the specified values (inclusive).
348
- */
349
- between?: [start: DataType, end: DataType];
350
- /**
351
- * Builds a negated filter.
352
- */
353
- not?: PrimitiveFilter<T, Nullable, WithAggregations>;
354
- };
355
- type StringFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<string, Nullable> | (CommonPrimitiveFilter<string, 'String', Nullable, WithAggregations> & {
356
- /**
357
- * Checks if the string contains the specified substring.
358
- */
359
- contains?: string;
360
- /**
361
- * Checks if the string starts with the specified substring.
362
- */
363
- startsWith?: string;
364
- /**
365
- * Checks if the string ends with the specified substring.
366
- */
367
- endsWith?: string;
368
- /**
369
- * Specifies the string comparison mode. Not effective for "sqlite" provider
370
- */
371
- mode?: 'default' | 'insensitive';
372
- } & (WithAggregations extends true ? {
373
- /**
374
- * Filters against the count of records.
375
- */
376
- _count?: NumberFilter<'Int', false, false>;
278
+ transformOutput(value: unknown, _type: BuiltinType, _array: boolean): unknown;
279
+ buildSelectModel(model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
280
+ buildFilterSortTake(model: string, args: FindArgs<Schema, GetModels<Schema>, any, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
281
+ buildFilter(model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
282
+ private buildCursorFilter;
283
+ private isLogicalCombinator;
284
+ protected buildCompositeFilter(model: string, modelAlias: string, key: (typeof LOGICAL_COMBINATORS)[number], payload: any): Expression<SqlBool>;
285
+ private buildRelationFilter;
286
+ private buildToOneRelationFilter;
287
+ private buildToManyRelationFilter;
288
+ private buildArrayFilter;
289
+ buildPrimitiveFilter(fieldRef: Expression<any>, fieldDef: FieldDef, payload: any): any;
290
+ private buildJsonFilter;
291
+ private buildPlainJsonFilter;
292
+ private buildTypedJsonFilter;
293
+ private buildTypedJsonArrayFilter;
294
+ private buildTypeJsonNonArrayFilter;
295
+ private buildJsonValueFilterClause;
296
+ protected buildJsonEqualityFilter(lhs: Expression<any>, rhs: unknown): ExpressionWrapper<any, any, SqlBool>;
297
+ private buildLiteralFilter;
298
+ private buildStandardFilter;
299
+ private buildStringFilter;
300
+ private buildJsonStringFilter;
301
+ private escapeLikePattern;
302
+ private buildStringLike;
303
+ private prepStringCasing;
304
+ private buildNumberFilter;
305
+ private buildBooleanFilter;
306
+ private buildDateTimeFilter;
307
+ private buildBytesFilter;
308
+ private buildEnumFilter;
309
+ buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, negated: boolean, take: number | undefined): SelectQueryBuilder<any, any, any>;
310
+ buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined | null, modelAlias: string): SelectQueryBuilder<any, any, any>;
311
+ shouldOmitField(omit: unknown, model: string, field: string): any;
312
+ protected buildModelSelect(model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, any, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
313
+ buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
314
+ buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
315
+ buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): AliasableExpression<unknown>;
316
+ protected negateSort(sort: SortOrder, negated: boolean): SortOrder;
317
+ true(): Expression<SqlBool>;
318
+ false(): Expression<SqlBool>;
319
+ isTrue(expression: Expression<SqlBool>): boolean;
320
+ isFalse(expression: Expression<SqlBool>): boolean;
321
+ and(...args: Expression<SqlBool>[]): Expression<SqlBool>;
322
+ or(...args: Expression<SqlBool>[]): Expression<SqlBool>;
323
+ not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
324
+ fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean): any;
325
+ protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, any, true>): boolean;
326
+ abstract get provider(): DataSourceProviderType;
377
327
  /**
378
- * Filters against the minimum value.
328
+ * Builds selection for a relation field.
379
329
  */
380
- _min?: StringFilter<false, false>;
330
+ abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, any, true>): SelectQueryBuilder<any, any, any>;
381
331
  /**
382
- * Filters against the maximum value.
332
+ * Builds skip and take clauses.
383
333
  */
384
- _max?: StringFilter<false, false>;
385
- } : {}));
386
- 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 ? {
334
+ abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
387
335
  /**
388
- * Filters against the count of records.
336
+ * Builds an Kysely expression that returns a JSON object for the given key-value pairs.
389
337
  */
390
- _count?: NumberFilter<'Int', false, false>;
338
+ abstract buildJsonObject(value: Record<string, Expression<unknown>>): AliasableExpression<unknown>;
391
339
  /**
392
- * Filters against the average value.
340
+ * Builds an Kysely expression that returns the length of an array.
393
341
  */
394
- _avg?: NumberFilter<T, false, false>;
342
+ abstract buildArrayLength(array: Expression<unknown>): AliasableExpression<number>;
395
343
  /**
396
- * Filters against the sum value.
344
+ * Builds an array value expression.
397
345
  */
398
- _sum?: NumberFilter<T, false, false>;
346
+ abstract buildArrayValue(values: Expression<unknown>[], elemType: string): AliasableExpression<unknown>;
399
347
  /**
400
- * Filters against the minimum value.
348
+ * Builds an expression that checks if an array contains a single value.
401
349
  */
402
- _min?: NumberFilter<T, false, false>;
350
+ abstract buildArrayContains(field: Expression<unknown>, value: Expression<unknown>, elemType?: string): AliasableExpression<SqlBool>;
403
351
  /**
404
- * Filters against the maximum value.
352
+ * Builds an expression that checks if an array contains all values from another array.
405
353
  */
406
- _max?: NumberFilter<T, false, false>;
407
- } : {}));
408
- type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Date | string, Nullable> | (CommonPrimitiveFilter<Date | string, 'DateTime', Nullable, WithAggregations> & (WithAggregations extends true ? {
354
+ abstract buildArrayHasEvery(field: Expression<unknown>, values: Expression<unknown>): AliasableExpression<SqlBool>;
409
355
  /**
410
- * Filters against the count of records.
356
+ * Builds an expression that checks if an array overlaps with another array.
411
357
  */
412
- _count?: NumberFilter<'Int', false, false>;
358
+ abstract buildArrayHasSome(field: Expression<unknown>, values: Expression<unknown>): AliasableExpression<SqlBool>;
413
359
  /**
414
- * Filters against the minimum value.
360
+ * Casts the given expression to an integer type.
415
361
  */
416
- _min?: DateTimeFilter<false, false>;
362
+ abstract castInt<T extends Expression<any>>(expression: T): T;
417
363
  /**
418
- * Filters against the maximum value.
364
+ * Casts the given expression to a text type.
419
365
  */
420
- _max?: DateTimeFilter<false, false>;
421
- } : {}));
422
- type BytesFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<Uint8Array | Buffer, Nullable> | ({
366
+ abstract castText<T extends Expression<any>>(expression: T): T;
423
367
  /**
424
- * Checks for equality with the specified value.
368
+ * Trims double quotes from the start and end of a text expression.
425
369
  */
426
- equals?: NullableIf<Uint8Array, Nullable>;
370
+ abstract trimTextQuotes<T extends Expression<string>>(expression: T): T;
371
+ abstract getStringCasingBehavior(): {
372
+ supportsILike: boolean;
373
+ likeCaseSensitive: boolean;
374
+ };
427
375
  /**
428
- * Checks if the value is in the specified list of values.
376
+ * Builds a VALUES table and select all fields from it.
429
377
  */
430
- in?: Uint8Array[];
378
+ abstract buildValuesTableSelect(fields: FieldDef[], rows: unknown[][]): SelectQueryBuilder<any, any, any>;
431
379
  /**
432
- * Checks if the value is not in the specified list of values.
380
+ * Builds a JSON path selection expression.
433
381
  */
434
- notIn?: Uint8Array[];
382
+ protected abstract buildJsonPathSelection(receiver: Expression<any>, path: string | undefined): Expression<any>;
435
383
  /**
436
- * Builds a negated filter.
384
+ * Builds a JSON array filter expression.
437
385
  */
438
- not?: BytesFilter<Nullable, WithAggregations>;
439
- } & (WithAggregations extends true ? {
386
+ protected abstract buildJsonArrayFilter(receiver: Expression<any>, operation: 'array_contains' | 'array_starts_with' | 'array_ends_with', value: unknown): Expression<SqlBool>;
440
387
  /**
441
- * Filters against the count of records.
388
+ * Builds a JSON array exists predicate (returning if any element matches the filter).
442
389
  */
443
- _count?: NumberFilter<'Int', false, false>;
390
+ protected abstract buildJsonArrayExistsPredicate(receiver: Expression<any>, buildFilter: (elem: Expression<any>) => Expression<SqlBool>): Expression<SqlBool>;
444
391
  /**
445
- * Filters against the minimum value.
392
+ * Builds an ORDER BY clause for a field with NULLS FIRST/LAST support.
446
393
  */
447
- _min?: BytesFilter<false, false>;
394
+ protected abstract buildOrderByField(query: SelectQueryBuilder<any, any, any>, field: Expression<unknown>, sort: SortOrder, nulls: 'first' | 'last'): SelectQueryBuilder<any, any, any>;
395
+ }
396
+
397
+ type ToKyselySchema<Schema extends SchemaDef> = {
398
+ [Model in GetModels<Schema>]: ToKyselyTable<Schema, Model>;
399
+ };
400
+ type ToKysely<Schema extends SchemaDef> = Kysely<ToKyselySchema<Schema>>;
401
+ type ToKyselyTable<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
402
+ [Field in ScalarFields<Schema, Model, false> | ForeignKeyFields<Schema, Model> as GetModelField<Schema, Model, Field>['originModel'] extends string ? never : Field]: toKyselyFieldType<Schema, Model, Field>;
403
+ };
404
+ type MapBaseType<T> = T extends 'String' ? string : T extends 'Boolean' ? boolean : T extends 'Int' | 'Float' ? number : T extends 'BigInt' ? bigint : T extends 'Decimal' ? Decimal : T extends 'DateTime' ? string : unknown;
405
+ type WrapNull<T, Null> = Null extends true ? T | null : T;
406
+ 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>>;
407
+ 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>;
408
+
409
+ declare class InputValidator<Schema extends SchemaDef> {
410
+ private readonly client;
411
+ private readonly schemaCache;
412
+ private readonly allFilterKinds;
413
+ constructor(client: ClientContract<Schema>);
414
+ private get schema();
415
+ private get options();
416
+ private get extraValidationsEnabled();
417
+ validateFindArgs(model: GetModels<Schema>, args: unknown, operation: CoreCrudOperations): FindArgs<Schema, GetModels<Schema>, any, true> | undefined;
418
+ validateExistsArgs(model: GetModels<Schema>, args: unknown): ExistsArgs<Schema, GetModels<Schema>, any> | undefined;
419
+ validateCreateArgs(model: GetModels<Schema>, args: unknown): CreateArgs<Schema, GetModels<Schema>, any>;
420
+ validateCreateManyArgs(model: GetModels<Schema>, args: unknown): CreateManyArgs<Schema, GetModels<Schema>>;
421
+ validateCreateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): CreateManyAndReturnArgs<Schema, GetModels<Schema>, any> | undefined;
422
+ validateUpdateArgs(model: GetModels<Schema>, args: unknown): UpdateArgs<Schema, GetModels<Schema>, any>;
423
+ validateUpdateManyArgs(model: GetModels<Schema>, args: unknown): UpdateManyArgs<Schema, GetModels<Schema>, any>;
424
+ validateUpdateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): UpdateManyAndReturnArgs<Schema, GetModels<Schema>, any>;
425
+ validateUpsertArgs(model: GetModels<Schema>, args: unknown): UpsertArgs<Schema, GetModels<Schema>, any>;
426
+ validateDeleteArgs(model: GetModels<Schema>, args: unknown): DeleteArgs<Schema, GetModels<Schema>, any>;
427
+ validateDeleteManyArgs(model: GetModels<Schema>, args: unknown): DeleteManyArgs<Schema, GetModels<Schema>, any> | undefined;
428
+ validateCountArgs(model: GetModels<Schema>, args: unknown): CountArgs<Schema, GetModels<Schema>, any> | undefined;
429
+ validateAggregateArgs(model: GetModels<Schema>, args: unknown): AggregateArgs<Schema, GetModels<Schema>, any>;
430
+ validateGroupByArgs(model: GetModels<Schema>, args: unknown): GroupByArgs<Schema, GetModels<Schema>, any>;
431
+ validateProcedureInput(proc: string, input: unknown): unknown;
432
+ private validate;
433
+ private mergePluginArgsSchema;
434
+ private getPluginExtQueryArgsSchema;
435
+ private makeFindSchema;
436
+ private makeExistsSchema;
437
+ private makeScalarSchema;
438
+ private makeEnumSchema;
439
+ private makeTypeDefSchema;
440
+ private makeWhereSchema;
441
+ private makeTypedJsonFilterSchema;
442
+ private isTypeDefType;
443
+ private makeEnumFilterSchema;
444
+ private makeArrayFilterSchema;
445
+ private internalMakeArrayFilterSchema;
446
+ private makePrimitiveFilterSchema;
447
+ private makeJsonValueSchema;
448
+ private makeJsonFilterSchema;
449
+ private makeDateTimeFilterSchema;
450
+ private makeBooleanFilterSchema;
451
+ private makeBytesFilterSchema;
452
+ private makeCommonPrimitiveFilterComponents;
453
+ private makeCommonPrimitiveFilterSchema;
454
+ private makeNumberFilterSchema;
455
+ private makeStringFilterSchema;
456
+ private makeStringModeSchema;
457
+ private makeSelectSchema;
458
+ private makeCountSelectionSchema;
459
+ private makeRelationSelectIncludeSchema;
460
+ private makeOmitSchema;
461
+ private makeIncludeSchema;
462
+ private makeOrderBySchema;
463
+ private makeDistinctSchema;
464
+ private makeCursorSchema;
465
+ private makeCreateSchema;
466
+ private makeCreateManySchema;
467
+ private makeCreateManyAndReturnSchema;
468
+ private makeCreateDataSchema;
469
+ private isDelegateDiscriminator;
470
+ private makeRelationManipulationSchema;
471
+ private makeSetDataSchema;
472
+ private makeConnectDataSchema;
473
+ private makeDisconnectDataSchema;
474
+ private makeDeleteRelationDataSchema;
475
+ private makeConnectOrCreateDataSchema;
476
+ private makeCreateManyDataSchema;
477
+ private makeUpdateSchema;
478
+ private makeUpdateManySchema;
479
+ private makeUpdateManyAndReturnSchema;
480
+ private makeUpsertSchema;
481
+ private makeUpdateDataSchema;
482
+ private makeDeleteSchema;
483
+ private makeDeleteManySchema;
484
+ makeCountSchema(model: string): z.ZodOptional<z.ZodObject<z.core.$ZodLooseShape, z.core.$strict>>;
485
+ private makeCountAggregateInputSchema;
486
+ makeAggregateSchema(model: string): z.ZodOptional<z.ZodObject<z.core.$ZodLooseShape, z.core.$strict>>;
487
+ makeSumAvgInputSchema(model: string): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
488
+ makeMinMaxInputSchema(model: string): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
489
+ private makeGroupBySchema;
490
+ private onlyAggregationFields;
491
+ private makeHavingSchema;
492
+ private makeProcedureParamSchema;
493
+ getCache(cacheKey: string): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | undefined;
494
+ setCache(cacheKey: string, schema: ZodType): Map<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
495
+ private printCacheStats;
496
+ private makeSkipSchema;
497
+ private makeTakeSchema;
498
+ private refineForSelectIncludeMutuallyExclusive;
499
+ private refineForSelectOmitMutuallyExclusive;
500
+ private nullableIf;
501
+ private orArray;
502
+ private isNumericField;
503
+ private get providerSupportsCaseSensitivity();
448
504
  /**
449
- * Filters against the maximum value.
505
+ * Gets the effective set of allowed FilterKind values for a specific model and field.
506
+ * Respects the precedence: field-level > model-level $all > global $all.
450
507
  */
451
- _max?: BytesFilter<false, false>;
452
- } : {}));
453
- type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean> = NullableIf<boolean, Nullable> | ({
508
+ private getEffectiveFilterKinds;
454
509
  /**
455
- * Checks for equality with the specified value.
510
+ * Computes the effective set of filter kinds based on inclusion and exclusion lists.
456
511
  */
457
- equals?: NullableIf<boolean, Nullable>;
512
+ private computeFilterKinds;
458
513
  /**
459
- * Builds a negated filter.
514
+ * Filters operators based on allowed filter kinds.
460
515
  */
461
- not?: BooleanFilter<Nullable, WithAggregations>;
462
- } & (WithAggregations extends true ? {
516
+ private trimFilterOperators;
517
+ private createUnionFilterSchema;
463
518
  /**
464
- * Filters against the count of records.
519
+ * Checks if a model is included in the slicing configuration.
520
+ * Returns true if the model is allowed, false if it's excluded.
465
521
  */
466
- _count?: NumberFilter<'Int', false, false>;
467
- /**
468
- * Filters against the minimum value.
469
- */
470
- _min?: BooleanFilter<false, false>;
471
- /**
472
- * Filters against the maximum value.
473
- */
474
- _max?: BooleanFilter<false, false>;
475
- } : {}));
476
- type JsonFilter = {
522
+ private isModelAllowed;
523
+ }
524
+
525
+ /**
526
+ * List of core CRUD operations. It excludes the 'orThrow' variants.
527
+ */
528
+ declare const CoreCrudOperations: readonly ["findMany", "findUnique", "findFirst", "create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany", "count", "aggregate", "groupBy", "exists"];
529
+ /**
530
+ * List of core CRUD operations. It excludes the 'orThrow' variants.
531
+ */
532
+ type CoreCrudOperations = (typeof CoreCrudOperations)[number];
533
+ /**
534
+ * List of core read operations. It excludes the 'orThrow' variants.
535
+ */
536
+ declare const CoreReadOperations: readonly ["findMany", "findUnique", "findFirst", "count", "aggregate", "groupBy", "exists"];
537
+ /**
538
+ * List of core read operations. It excludes the 'orThrow' variants.
539
+ */
540
+ type CoreReadOperations = (typeof CoreReadOperations)[number];
541
+ /**
542
+ * List of core write operations.
543
+ */
544
+ declare const CoreWriteOperations: readonly ["create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany"];
545
+ /**
546
+ * List of core write operations.
547
+ */
548
+ type CoreWriteOperations = (typeof CoreWriteOperations)[number];
549
+ /**
550
+ * List of core create operations.
551
+ */
552
+ declare const CoreCreateOperations: readonly ["create", "createMany", "createManyAndReturn", "upsert"];
553
+ /**
554
+ * List of core create operations.
555
+ */
556
+ type CoreCreateOperations = (typeof CoreCreateOperations)[number];
557
+ /**
558
+ * List of core update operations.
559
+ */
560
+ declare const CoreUpdateOperations: readonly ["update", "updateMany", "updateManyAndReturn", "upsert"];
561
+ /**
562
+ * List of core update operations.
563
+ */
564
+ type CoreUpdateOperations = (typeof CoreUpdateOperations)[number];
565
+ /**
566
+ * List of core delete operations.
567
+ */
568
+ declare const CoreDeleteOperations: readonly ["delete", "deleteMany"];
569
+ /**
570
+ * List of core delete operations.
571
+ */
572
+ type CoreDeleteOperations = (typeof CoreDeleteOperations)[number];
573
+ /**
574
+ * List of all CRUD operations, including 'orThrow' variants.
575
+ */
576
+ declare const AllCrudOperations: readonly ["findMany", "findUnique", "findFirst", "create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany", "count", "aggregate", "groupBy", "exists", "findUniqueOrThrow", "findFirstOrThrow"];
577
+ /**
578
+ * List of all CRUD operations, including 'orThrow' variants.
579
+ */
580
+ type AllCrudOperations = (typeof AllCrudOperations)[number];
581
+ /**
582
+ * List of all read operations, including 'orThrow' variants.
583
+ */
584
+ declare const AllReadOperations: readonly ["findMany", "findUnique", "findFirst", "count", "aggregate", "groupBy", "exists", "findUniqueOrThrow", "findFirstOrThrow"];
585
+ /**
586
+ * List of all read operations, including 'orThrow' variants.
587
+ */
588
+ type AllReadOperations = (typeof AllReadOperations)[number];
589
+
590
+ type AllowedExtQueryArgKeys = CoreCrudOperations | '$create' | '$read' | '$update' | '$delete' | '$all';
591
+ /**
592
+ * Base shape of plugin-extended query args.
593
+ */
594
+ type ExtQueryArgsBase = {
595
+ [K in AllowedExtQueryArgKeys]?: object;
596
+ };
597
+ /**
598
+ * Base type for plugin-extended client members (methods and properties).
599
+ * Member names should start with '$' to avoid model name conflicts.
600
+ */
601
+ type ExtClientMembersBase = Record<string, unknown>;
602
+ /**
603
+ * ZenStack runtime plugin.
604
+ */
605
+ interface RuntimePlugin<Schema extends SchemaDef, ExtQueryArgs extends ExtQueryArgsBase, ExtClientMembers extends Record<string, unknown>> {
477
606
  /**
478
- * JSON path to select the value to filter on. If omitted, the whole JSON value is used.
607
+ * Plugin ID.
479
608
  */
480
- path?: string;
609
+ id: string;
481
610
  /**
482
- * Checks for equality with the specified value.
611
+ * Plugin display name.
483
612
  */
484
- equals?: JsonValue | JsonNullValues;
613
+ name?: string;
485
614
  /**
486
- * Builds a negated filter.
615
+ * Plugin description.
487
616
  */
488
- not?: JsonValue | JsonNullValues;
617
+ description?: string;
489
618
  /**
490
- * Checks if the value is a string and contains the specified substring.
619
+ * Custom function implementations.
620
+ * @private
491
621
  */
492
- string_contains?: string;
622
+ functions?: Record<string, ZModelFunction<Schema>>;
493
623
  /**
494
- * Checks if the value is a string and starts with the specified substring.
624
+ * Intercepts an ORM query.
495
625
  */
496
- string_starts_with?: string;
626
+ onQuery?: OnQueryCallback<Schema>;
497
627
  /**
498
- * Checks if the value is a string and ends with the specified substring.
628
+ * Intercepts a procedure invocation.
499
629
  */
500
- string_ends_with?: string;
630
+ onProcedure?: OnProcedureCallback<Schema>;
501
631
  /**
502
- * String comparison mode. Not effective for "sqlite" provider
632
+ * Intercepts an entity mutation.
503
633
  */
504
- mode?: 'default' | 'insensitive';
634
+ onEntityMutation?: EntityMutationHooksDef<Schema>;
505
635
  /**
506
- * Checks if the value is an array and contains the specified value.
636
+ * Intercepts a Kysely query.
507
637
  */
508
- array_contains?: JsonValue;
638
+ onKyselyQuery?: OnKyselyQueryCallback<Schema>;
509
639
  /**
510
- * Checks if the value is an array and starts with the specified value.
640
+ * Extended query args configuration.
511
641
  */
512
- array_starts_with?: JsonValue;
642
+ queryArgs?: {
643
+ [K in keyof ExtQueryArgs]: ZodType<ExtQueryArgs[K]>;
644
+ };
513
645
  /**
514
- * Checks if the value is an array and ends with the specified value.
646
+ * Extended client members (methods and properties).
515
647
  */
516
- array_ends_with?: JsonValue;
517
- };
518
- type TypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean> = XOR<JsonFilter, TypedJsonTypedFilter<Schema, TypeDefName, Array, Optional>>;
519
- type TypedJsonTypedFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean> = (Array extends true ? ArrayTypedJsonFilter<Schema, TypeDefName> : NonArrayTypedJsonFilter<Schema, TypeDefName>) | (Optional extends true ? null : never);
520
- type ArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>> = {
521
- some?: TypedJsonFieldsFilter<Schema, TypeDefName>;
522
- every?: TypedJsonFieldsFilter<Schema, TypeDefName>;
523
- none?: TypedJsonFieldsFilter<Schema, TypeDefName>;
524
- };
525
- type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>> = {
526
- is?: TypedJsonFieldsFilter<Schema, TypeDefName>;
527
- isNot?: TypedJsonFieldsFilter<Schema, TypeDefName>;
528
- } | TypedJsonFieldsFilter<Schema, TypeDefName>;
529
- type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>> = {
530
- [Key in GetTypeDefFields<Schema, TypeDefName>]?: GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsArray<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>> : TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>> : GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false> : PrimitiveFilter<GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false>;
531
- };
532
- type SortOrder = 'asc' | 'desc';
533
- type NullsOrder = 'first' | 'last';
534
- type OrderBy<Schema extends SchemaDef, Model extends GetModels<Schema>, WithRelation extends boolean, WithAggregation extends boolean> = {
535
- [Key in NonRelationFields<Schema, Model>]?: ModelFieldIsOptional<Schema, Model, Key> extends true ? SortOrder | {
536
- /**
537
- * Sort order
538
- */
539
- sort: SortOrder;
540
- /**
541
- * Treatment of null values
542
- */
543
- nulls?: NullsOrder;
544
- } : SortOrder;
545
- } & (WithRelation extends true ? {
546
- [Key in RelationFields<Schema, Model>]?: FieldIsArray<Schema, Model, Key> extends true ? {
547
- /**
548
- * Sorts by the count of related records.
549
- */
550
- _count?: SortOrder;
551
- } : OrderBy<Schema, RelationFieldType<Schema, Model, Key>, WithRelation, WithAggregation>;
552
- } : {}) & (WithAggregation extends true ? {
648
+ client?: ExtClientMembers;
649
+ }
650
+ type AnyPlugin = RuntimePlugin<any, any, any>;
651
+ /**
652
+ * Defines a ZenStack runtime plugin.
653
+ */
654
+ declare function definePlugin<Schema extends SchemaDef, const ExtQueryArgs extends ExtQueryArgsBase = {}, const ExtClientMembers extends Record<string, unknown> = {}>(plugin: RuntimePlugin<Schema, ExtQueryArgs, ExtClientMembers>): RuntimePlugin<any, ExtQueryArgs, ExtClientMembers>;
655
+ type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;
656
+ type OnProcedureHookContext<Schema extends SchemaDef> = {
553
657
  /**
554
- * Sorts by the count of records.
658
+ * The procedure name.
555
659
  */
556
- _count?: OrderBy<Schema, Model, false, false>;
660
+ name: string;
557
661
  /**
558
- * Sorts by the minimum value.
662
+ * Whether the procedure is a mutation.
559
663
  */
560
- _min?: MinMaxInput<Schema, Model, SortOrder>;
664
+ mutation: boolean;
561
665
  /**
562
- * Sorts by the maximum value.
666
+ * Procedure invocation input (envelope).
667
+ *
668
+ * The canonical shape is `{ args?: Record<string, unknown> }`.
669
+ * When a procedure has required params, `args` is required.
563
670
  */
564
- _max?: MinMaxInput<Schema, Model, SortOrder>;
565
- } & (NumericFields<Schema, Model> extends never ? {} : {
671
+ input: unknown;
566
672
  /**
567
- * Sorts by the average value.
673
+ * Continues the invocation. The input passed here is forwarded to the next handler.
568
674
  */
569
- _avg?: SumAvgInput<Schema, Model, SortOrder>;
675
+ proceed: (input: unknown) => Promise<unknown>;
570
676
  /**
571
- * Sorts by the sum value.
677
+ * The ZenStack client that is invoking the procedure.
572
678
  */
573
- _sum?: SumAvgInput<Schema, Model, SortOrder>;
574
- }) : {});
575
- type WhereUniqueInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = AtLeast<{
576
- [Key in keyof GetModel<Schema, Model>['uniqueFields']]?: GetModel<Schema, Model>['uniqueFields'][Key] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key]> : {
577
- [Key1 in keyof GetModel<Schema, Model>['uniqueFields'][Key]]: GetModel<Schema, Model>['uniqueFields'][Key][Key1] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key][Key1]> : never;
578
- };
579
- } & WhereInput<Schema, Model>, Extract<keyof GetModel<Schema, Model>['uniqueFields'], string>>;
580
- type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
581
- [Key in NonRelationFields<Schema, Model>]?: boolean;
679
+ client: ClientContract<Schema>;
582
680
  };
583
- type SelectIncludeOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean, AllowRelation extends boolean = true> = {
584
- /**
585
- * Explicitly select fields and relations to be returned by the query.
586
- */
587
- select?: SelectInput<Schema, Model, AllowCount, AllowRelation> | null;
681
+ type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
682
+ type OnQueryHookContext<Schema extends SchemaDef> = {
588
683
  /**
589
- * Specifies relations to be included in the query result. All scalar fields are included.
684
+ * The model that is being queried.
590
685
  */
591
- include?: IncludeInput<Schema, Model, AllowCount> | null;
686
+ model: GetModels<Schema>;
592
687
  /**
593
- * Explicitly omit fields from the query result.
688
+ * The operation that is being performed.
594
689
  */
595
- omit?: OmitInput<Schema, Model> | null;
596
- };
597
- type SelectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true, AllowRelation extends boolean = true> = {
598
- [Key in NonRelationFields<Schema, Model>]?: boolean;
599
- } & (AllowRelation extends true ? IncludeInput<Schema, Model, AllowCount> : {});
600
- type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>> = boolean | {
690
+ operation: AllCrudOperations;
601
691
  /**
602
- * Selects specific relations to count.
692
+ * The query arguments.
603
693
  */
604
- select: {
605
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]?: boolean | {
606
- where: WhereInput<Schema, RelationFieldType<Schema, Model, Key>, false>;
607
- };
608
- };
609
- };
610
- type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean = true> = {
611
- [Key in RelationFields<Schema, Model>]?: boolean | FindArgs<Schema, RelationFieldType<Schema, Model, Key>, FieldIsArray<Schema, Model, Key>, FieldIsArray<Schema, Model, Key> extends true ? true : ModelFieldIsOptional<Schema, Model, Key> extends true ? true : false>;
612
- } & (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
613
- _count?: SelectCount<Schema, Model>;
614
- } : {} : {});
615
- type Subset<T, U> = {
616
- [key in keyof T]: key extends keyof U ? T[key] : never;
617
- };
618
- type SelectSubset<T, U> = {
619
- [key in keyof T]: key extends keyof U ? T[key] : never;
620
- } & (T extends {
621
- select: any;
622
- include: any;
623
- } ? 'Please either choose `select` or `include`.' : T extends {
624
- select: any;
625
- omit: any;
626
- } ? 'Please either choose `select` or `omit`.' : {});
627
- type ToManyRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = {
628
- every?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
629
- some?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
630
- none?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
631
- };
632
- type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>> & {
694
+ args: Record<string, unknown> | undefined;
633
695
  /**
634
- * Checks if the related record matches the specified filter.
696
+ * The function to proceed with the original query.
697
+ * It takes the same arguments as the operation method.
698
+ *
699
+ * @param args The query arguments.
635
700
  */
636
- is?: NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>>;
701
+ proceed: (args: Record<string, unknown> | undefined) => Promise<unknown>;
637
702
  /**
638
- * Checks if the related record does not match the specified filter.
703
+ * The ZenStack client that is performing the operation.
639
704
  */
640
- isNot?: NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>>;
641
- }, ModelFieldIsOptional<Schema, Model, Field>>;
642
- type RelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationFilter<Schema, Model, Field> : ToOneRelationFilter<Schema, Model, Field>;
643
- type MapModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = MapFieldDefType<Schema, GetModelField<Schema, Model, Field>>;
644
- type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'>, Partial extends boolean = false> = WrapType<T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T['type'], Partial> & Record<string, unknown> : MapBaseType$1<T['type']>, T['optional'], T['array']>;
645
- type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
646
- [Key in GetModelFields<Schema, Model> as ModelFieldIsOptional<Schema, Model, Key> extends true ? Key : FieldHasDefault<Schema, Model, Key> extends true ? Key : FieldIsArray<Schema, Model, Key> extends true ? Key : GetModelField<Schema, Model, Key>['updatedAt'] extends (true | UpdatedAtInfo) ? Key : never]: GetModelField<Schema, Model, Key>;
705
+ client: ClientContract<Schema>;
647
706
  };
648
- type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'];
649
- type OppositeRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>> = FT extends GetModels<Schema> ? GetRelation<Schema, Model, Field> extends RelationInfo ? GetRelation<Schema, Model, Field>['opposite'] extends GetModelFields<Schema, FT> ? Schema['models'][FT]['fields'][GetRelation<Schema, Model, Field>['opposite']]['relation'] : never : never : never;
650
- type OppositeRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Opposite = OppositeRelation<Schema, Model, Field>> = Opposite extends RelationInfo ? (Opposite['fields'] extends readonly string[] ? Opposite['fields'] : []) : [];
651
- type OppositeRelationAndFK<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>, Relation = GetModelField<Schema, Model, Field>['relation'], Opposite = Relation extends RelationInfo ? Relation['opposite'] : never> = FT extends GetModels<Schema> ? Opposite extends GetModelFields<Schema, FT> ? Opposite | OppositeRelationFields<Schema, Model, Field>[number] : never : never;
652
- type FilterArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
707
+ type EntityMutationHooksDef<Schema extends SchemaDef> = {
653
708
  /**
654
- * Filter conditions
709
+ * Called before entities are mutated.
655
710
  */
656
- where?: WhereInput<Schema, Model>;
657
- };
658
- type SortAndTakeArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
711
+ beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
659
712
  /**
660
- * Number of records to skip
713
+ * Called after entities are mutated.
661
714
  */
662
- skip?: number;
663
- /**
664
- * Number of records to take
665
- */
666
- take?: number;
667
- /**
668
- * Order by clauses
669
- */
670
- orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
715
+ afterEntityMutation?: AfterEntityMutationCallback<Schema>;
671
716
  /**
672
- * Cursor for pagination
717
+ * Whether to run after-mutation hooks within the transaction that performs the mutation.
718
+ *
719
+ * If set to `true`, if the mutation already runs inside a transaction, the callbacks are
720
+ * executed immediately after the mutation within the transaction boundary. If the mutation
721
+ * is not running inside a transaction, a new transaction is created to run both the mutation
722
+ * and the callbacks.
723
+ *
724
+ * If set to `false`, the callbacks are executed after the mutation transaction is committed.
725
+ *
726
+ * Defaults to `false`.
673
727
  */
674
- cursor?: WhereUniqueInput<Schema, Model>;
728
+ runAfterMutationWithinTransaction?: boolean;
675
729
  };
676
- type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Collection extends boolean, AllowFilter extends boolean = true> = (Collection extends true ? SortAndTakeArgs<Schema, Model> & (ProviderSupportsDistinct<Schema> extends true ? {
677
- /**
678
- * Distinct fields. Only supported by providers that natively support SQL "DISTINCT ON".
679
- */
680
- distinct?: OrArray<NonRelationFields<Schema, Model>>;
681
- } : {}) : {}) & (AllowFilter extends true ? FilterArgs<Schema, Model> : {}) & SelectIncludeOmit<Schema, Model, Collection>;
682
- type FindManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
683
- type FindFirstArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
684
- type ExistsArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FilterArgs<Schema, Model>;
685
- type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
686
- where: WhereUniqueInput<Schema, Model>;
687
- } & SelectIncludeOmit<Schema, Model, true>;
688
- type CreateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
689
- data: CreateInput<Schema, Model>;
690
- } & SelectIncludeOmit<Schema, Model, true>;
691
- type CreateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyInput<Schema, Model>;
692
- type CreateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyInput<Schema, Model> & Omit<SelectIncludeOmit<Schema, Model, false, false>, 'include'>;
693
- type OptionalWrap<Schema extends SchemaDef, Model extends GetModels<Schema>, T extends object> = Optional<T, keyof T & OptionalFieldsForCreate<Schema, Model>>;
694
- type CreateScalarPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
695
- [Key in ScalarFields<Schema, Model, false> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? never : Key]: ScalarCreatePayload<Schema, Model, Key>;
696
- }>;
697
- type ScalarCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends ScalarFields<Schema, Model, false>> = ScalarFieldMutationPayload<Schema, Model, Field> | (FieldIsArray<Schema, Model, Field> extends true ? {
698
- set?: MapModelFieldType<Schema, Model, Field>;
699
- } : never);
700
- type ScalarFieldMutationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = IsJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? JsonValue | JsonNull | DbNull : JsonValue | JsonNull : MapModelFieldType<Schema, Model, Field>;
701
- type IsJsonField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends 'Json' ? true : false;
702
- type CreateFKPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
703
- [Key in ForeignKeyFields<Schema, Model>]: MapModelFieldType<Schema, Model, Key>;
704
- }>;
705
- type CreateRelationFieldPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = Omit<{
706
- /**
707
- * Connects or create a related record.
708
- */
709
- connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field>;
710
- /**
711
- * Creates a related record.
712
- */
713
- create?: NestedCreateInput<Schema, Model, Field>;
730
+ type MutationHooksArgs<Schema extends SchemaDef> = {
714
731
  /**
715
- * Creates a batch of related records.
732
+ * The model that is being mutated.
716
733
  */
717
- createMany?: NestedCreateManyInput<Schema, Model, Field>;
734
+ model: GetModels<Schema>;
718
735
  /**
719
- * Connects an existing record.
736
+ * The mutation action that is being performed.
720
737
  */
721
- connect?: ConnectInput<Schema, Model, Field>;
722
- }, (FieldIsArray<Schema, Model, Field> extends true ? never : 'createMany') | (FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'createMany' | 'connectOrCreate' : never)>;
723
- type CreateRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
724
- [Key in RelationFields<Schema, Model>]: CreateRelationFieldPayload<Schema, Model, Key>;
725
- }>;
726
- type CreateWithFKInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateScalarPayload<Schema, Model> & CreateFKPayload<Schema, Model> & CreateWithNonOwnedRelationPayload<Schema, Model>;
727
- type CreateWithRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateScalarPayload<Schema, Model> & CreateRelationPayload<Schema, Model>;
728
- type CreateWithNonOwnedRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
729
- [Key in NonOwnedRelationFields<Schema, Model>]: CreateRelationFieldPayload<Schema, Model, Key>;
730
- }>;
731
- type ConnectOrCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
738
+ action: 'create' | 'update' | 'delete';
732
739
  /**
733
- * The unique filter to find an existing record to connect.
740
+ * The mutation data. Only available for create and update actions.
734
741
  */
735
- where: WhereUniqueInput<Schema, Model>;
742
+ queryNode: OperationNode;
736
743
  /**
737
- * The data to create a new record if no existing record is found.
744
+ * A query ID that uniquely identifies the mutation operation. You can use it to correlate
745
+ * data between the before and after mutation hooks.
738
746
  */
739
- create: CreateInput<Schema, Model, Without>;
747
+ queryId: QueryId;
740
748
  };
741
- type CreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
749
+ type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
750
+ type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
751
+ type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
742
752
  /**
743
- * The data for the records to create.
753
+ * Loads the entities that are about to be mutated. The db operation that loads the entities is executed
754
+ * within the same transaction context as the mutation.
744
755
  */
745
- data: OrArray<Omit<CreateScalarPayload<Schema, Model>, Without> & Omit<CreateFKPayload<Schema, Model>, Without>>;
756
+ loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
746
757
  /**
747
- * Specifies whether to skip creating records that would violate unique constraints.
758
+ * The ZenStack client you can use to perform additional operations. The database operations initiated
759
+ * from this client are executed within the same transaction as the mutation if the mutation is running
760
+ * inside a transaction.
761
+ *
762
+ * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
748
763
  */
749
- skipDuplicates?: boolean;
764
+ client: ClientContract<Schema>;
750
765
  };
751
- type CreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = XOR<Omit<CreateWithFKInput<Schema, Model>, Without>, Omit<CreateWithRelationInput<Schema, Model>, Without>>;
752
- type NestedCreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<CreateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>, FieldIsArray<Schema, Model, Field>>;
753
- type NestedCreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = CreateManyInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
754
- type UpdateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
755
- /**
756
- * The data to update the record with.
757
- */
758
- data: UpdateInput<Schema, Model>;
759
- /**
760
- * The unique filter to find the record to update.
761
- */
762
- where: WhereUniqueInput<Schema, Model>;
763
- } & SelectIncludeOmit<Schema, Model, true>;
764
- type UpdateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = UpdateManyPayload<Schema, Model>;
765
- type UpdateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = UpdateManyPayload<Schema, Model> & Omit<SelectIncludeOmit<Schema, Model, false, false>, 'include'>;
766
- type UpdateManyPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
766
+ type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
767
767
  /**
768
- * The data to update the records with.
768
+ * Loads the entities that have been mutated.
769
769
  */
770
- data: OrArray<UpdateScalarInput<Schema, Model, Without>>;
770
+ loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
771
771
  /**
772
- * The filter to select records to update.
772
+ * The entities before mutation. Only available if `beforeEntityMutation` hook is provided and
773
+ * the `loadBeforeMutationEntities` function is called in that hook.
773
774
  */
774
- where?: WhereInput<Schema, Model>;
775
+ beforeMutationEntities?: Record<string, unknown>[];
775
776
  /**
776
- * Limit the number of records to update.
777
+ * The ZenStack client you can use to perform additional operations.
778
+ * See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
779
+ *
780
+ * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
777
781
  */
778
- limit?: number;
782
+ client: ClientContract<Schema>;
779
783
  };
780
- type UpsertArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
781
- /**
782
- * The data to create the record if it doesn't exist.
783
- */
784
- create: CreateInput<Schema, Model>;
785
- /**
786
- * The data to update the record with if it exists.
787
- */
788
- update: UpdateInput<Schema, Model>;
789
- /**
790
- * The unique filter to find the record to update.
791
- */
792
- where: WhereUniqueInput<Schema, Model>;
793
- } & SelectIncludeOmit<Schema, Model, true>;
794
- type UpdateScalarInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = Omit<{
795
- [Key in NonRelationFields<Schema, Model> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? never : Key]?: ScalarUpdatePayload<Schema, Model, Key>;
796
- }, Without>;
797
- type ScalarUpdatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends NonRelationFields<Schema, Model>> = ScalarFieldMutationPayload<Schema, Model, Field> | (Field extends NumericFields<Schema, Model> ? {
798
- /**
799
- * Sets the field to the specified value.
800
- */
801
- set?: NullableIf<number, ModelFieldIsOptional<Schema, Model, Field>>;
802
- /**
803
- * Increments the field by the specified value.
804
- */
805
- increment?: number;
784
+ type OnKyselyQueryArgs<Schema extends SchemaDef> = {
785
+ schema: SchemaDef;
786
+ client: ClientContract<Schema>;
787
+ query: RootOperationNode;
788
+ proceed: ProceedKyselyQueryFunction;
789
+ };
790
+ type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
791
+ type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
792
+
793
+ type ZModelFunctionContext<Schema extends SchemaDef> = {
806
794
  /**
807
- * Decrements the field by the specified value.
795
+ * ZenStack client instance
808
796
  */
809
- decrement?: number;
797
+ client: ClientContract<Schema>;
810
798
  /**
811
- * Multiplies the field by the specified value.
799
+ * Database dialect
812
800
  */
813
- multiply?: number;
801
+ dialect: BaseCrudDialect<Schema>;
814
802
  /**
815
- * Divides the field by the specified value.
803
+ * The containing model name
816
804
  */
817
- divide?: number;
818
- } : never) | (FieldIsArray<Schema, Model, Field> extends true ? {
805
+ model: GetModels<Schema>;
819
806
  /**
820
- * Sets the field to the specified array.
807
+ * The alias name that can be used to refer to the containing model
821
808
  */
822
- set?: MapModelFieldType<Schema, Model, Field>[];
809
+ modelAlias: string;
823
810
  /**
824
- * Appends the specified values to the array field.
811
+ * The CRUD operation being performed
825
812
  */
826
- push?: OrArray<MapModelFieldType<Schema, Model, Field>, true>;
827
- } : never);
828
- type UpdateRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = Omit<{
829
- [Key in RelationFields<Schema, Model>]?: UpdateRelationFieldPayload<Schema, Model, Key>;
830
- }, Without>;
831
- type UpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = UpdateScalarInput<Schema, Model, Without> & UpdateRelationInput<Schema, Model, Without>;
832
- type UpdateRelationFieldPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationUpdateInput<Schema, Model, Field> : ToOneRelationUpdateInput<Schema, Model, Field>;
833
- type ToManyRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = Omit<{
813
+ operation: CRUD_EXT;
814
+ };
815
+ type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
816
+ /**
817
+ * Options for slicing ORM client's capabilities by including/excluding certain models, operations,
818
+ * filters, etc.
819
+ */
820
+ type SlicingOptions<Schema extends SchemaDef> = {
834
821
  /**
835
- * Creates related records.
822
+ * Models to include in the client. If not specified, all models are included by default.
836
823
  */
837
- create?: NestedCreateInput<Schema, Model, Field>;
824
+ includedModels?: readonly GetModels<Schema>[];
838
825
  /**
839
- * Creates a batch of related records.
826
+ * Models to exclude from the client. Exclusion takes precedence over inclusion.
840
827
  */
841
- createMany?: NestedCreateManyInput<Schema, Model, Field>;
828
+ excludedModels?: readonly GetModels<Schema>[];
842
829
  /**
843
- * Connects existing records.
830
+ * Model slicing options.
844
831
  */
845
- connect?: ConnectInput<Schema, Model, Field>;
832
+ models?: {
833
+ [Model in GetModels<Schema>]?: ModelSlicingOptions<Schema, Model>;
834
+ } & {
835
+ /**
836
+ * Slicing options that apply to all models. Model-specific options will override these general
837
+ * options if both are specified.
838
+ */
839
+ $all?: ModelSlicingOptions<Schema, GetModels<Schema>>;
840
+ };
846
841
  /**
847
- * Connects or create related records.
842
+ * Procedures to include in the client. If not specified, all procedures are included by default.
848
843
  */
849
- connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field>;
844
+ includedProcedures?: readonly GetProcedureNames<Schema>[];
850
845
  /**
851
- * Disconnects related records.
846
+ * Procedures to exclude from the client. Exclusion takes precedence over inclusion.
852
847
  */
853
- disconnect?: DisconnectInput<Schema, Model, Field>;
848
+ excludedProcedures?: readonly GetProcedureNames<Schema>[];
849
+ };
850
+ /**
851
+ * Kinds of filter operations.
852
+ */
853
+ type FilterKind = FilterPropertyToKind[keyof FilterPropertyToKind];
854
+ /**
855
+ * Model slicing options.
856
+ */
857
+ type ModelSlicingOptions<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
854
858
  /**
855
- * Updates related records.
859
+ * ORM query operations to include for the model. If not specified, all operations are included
860
+ * by default.
856
861
  */
857
- update?: NestedUpdateInput<Schema, Model, Field>;
862
+ includedOperations?: readonly AllCrudOperations[];
858
863
  /**
859
- * Upserts related records.
864
+ * ORM query operations to exclude for the model. Exclusion takes precedence over inclusion.
860
865
  */
861
- upsert?: NestedUpsertInput<Schema, Model, Field>;
866
+ excludedOperations?: readonly AllCrudOperations[];
862
867
  /**
863
- * Updates a batch of related records.
868
+ * Field-level slicing options.
864
869
  */
865
- updateMany?: NestedUpdateManyInput<Schema, Model, Field>;
870
+ fields?: {
871
+ [Field in GetModelFields<Schema, Model>]?: FieldSlicingOptions;
872
+ } & {
873
+ /**
874
+ * Field slicing options that apply to all fields. Field-specific options will override these
875
+ * general options if both are specified.
876
+ */
877
+ $all?: FieldSlicingOptions;
878
+ };
879
+ };
880
+ /**
881
+ * Field slicing options.
882
+ */
883
+ type FieldSlicingOptions = {
866
884
  /**
867
- * Deletes related records.
885
+ * Filter kinds to include for the field. If not specified, all filter kinds are included by default.
868
886
  */
869
- delete?: NestedDeleteInput<Schema, Model, Field>;
887
+ includedFilterKinds?: readonly FilterKind[];
870
888
  /**
871
- * Deletes a batch of related records.
889
+ * Filter kinds to exclude for the field. Exclusion takes precedence over inclusion.
872
890
  */
873
- deleteMany?: NestedDeleteManyInput<Schema, Model, Field>;
891
+ excludedFilterKinds?: readonly FilterKind[];
892
+ };
893
+ /**
894
+ * Partial ORM client options that defines customizable behaviors.
895
+ */
896
+ type QueryOptions<Schema extends SchemaDef> = {
874
897
  /**
875
- * Sets the related records to the specified ones.
898
+ * Options for omitting fields in ORM query results.
876
899
  */
877
- set?: SetRelationInput<Schema, Model, Field>;
878
- }, FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'createMany' | 'connectOrCreate' | 'upsert' : never>;
879
- type ToOneRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = Omit<{
900
+ omit?: OmitConfig<Schema>;
880
901
  /**
881
- * Creates a related record.
902
+ * Whether to allow overriding omit settings at query time. Defaults to `true`. When set to `false`, a
903
+ * query-time `omit` clause that sets the field to `false` (not omitting) will trigger a validation error.
882
904
  */
883
- create?: NestedCreateInput<Schema, Model, Field>;
905
+ allowQueryTimeOmitOverride?: boolean;
884
906
  /**
885
- * Connects an existing record.
907
+ * Options for slicing ORM client's capabilities by including/excluding certain models, operations, filters, etc.
886
908
  */
887
- connect?: ConnectInput<Schema, Model, Field>;
909
+ slicing?: SlicingOptions<Schema>;
910
+ };
911
+ /**
912
+ * ZenStack client options.
913
+ */
914
+ type ClientOptions<Schema extends SchemaDef> = QueryOptions<Schema> & {
888
915
  /**
889
- * Connects or create a related record.
916
+ * Kysely dialect.
890
917
  */
891
- connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field>;
918
+ dialect: Dialect;
892
919
  /**
893
- * Updates the related record.
920
+ * Custom function definitions.
921
+ *
922
+ * @private
894
923
  */
895
- update?: NestedUpdateInput<Schema, Model, Field>;
924
+ functions?: Record<string, ZModelFunction<Schema>>;
896
925
  /**
897
- * Upserts the related record.
926
+ * Plugins.
898
927
  */
899
- upsert?: NestedUpsertInput<Schema, Model, Field>;
900
- } & (ModelFieldIsOptional<Schema, Model, Field> extends true ? {
928
+ plugins?: AnyPlugin[];
901
929
  /**
902
- * Disconnects the related record.
930
+ * Logging configuration.
903
931
  */
904
- disconnect?: DisconnectInput<Schema, Model, Field>;
932
+ log?: KyselyConfig['log'];
905
933
  /**
906
- * Deletes the related record.
934
+ * Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
935
+ * to `true`.
936
+ *
937
+ * Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
938
+ * `Date` object) although for `DateTime` field the data in DB is stored in UTC.
939
+ * @see https://github.com/brianc/node-postgres/issues/429
907
940
  */
908
- delete?: NestedDeleteInput<Schema, Model, Field>;
909
- } : {}), FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'connectOrCreate' | 'upsert' : never>;
910
- type DeleteArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
941
+ fixPostgresTimezone?: boolean;
911
942
  /**
912
- * The unique filter to find the record to delete.
943
+ * Whether to enable input validations expressed with attributes like `@email`, `@regex`,
944
+ * `@@validate`, etc. Defaults to `true`.
913
945
  */
914
- where: WhereUniqueInput<Schema, Model>;
915
- } & SelectIncludeOmit<Schema, Model, true>;
916
- type DeleteManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
946
+ validateInput?: boolean;
947
+ } & (HasComputedFields<Schema> extends true ? {
917
948
  /**
918
- * Filter to select records to delete.
949
+ * Computed field definitions.
919
950
  */
920
- where?: WhereInput<Schema, Model>;
951
+ computedFields: ComputedFieldsOptions<Schema>;
952
+ } : {}) & (HasProcedures<Schema> extends true ? {
921
953
  /**
922
- * Limits the number of records to delete.
954
+ * Custom procedure definitions.
923
955
  */
924
- limit?: number;
956
+ procedures: ProceduresOptions<Schema>;
957
+ } : {});
958
+ /**
959
+ * Config for omitting fields in ORM query results.
960
+ */
961
+ type OmitConfig<Schema extends SchemaDef> = {
962
+ [Model in GetModels<Schema>]?: {
963
+ [Field in GetModelFields<Schema, Model> as Field extends ScalarFields<Schema, Model> ? Field : never]?: boolean;
964
+ };
925
965
  };
926
- type CountArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<FindArgs<Schema, Model, true>, 'select' | 'include' | 'distinct' | 'omit'> & {
927
- /**
928
- * Selects fields to count
929
- */
930
- select?: CountAggregateInput<Schema, Model> | true;
966
+ type ComputedFieldsOptions<Schema extends SchemaDef> = {
967
+ [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
968
+ [Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
969
+ };
931
970
  };
932
- type CountAggregateInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
933
- [Key in NonRelationFields<Schema, Model>]?: true;
934
- } & {
935
- _all?: true;
971
+ type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
972
+ type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
973
+ procedures: Record<string, ProcedureDef>;
974
+ } ? {
975
+ [Key in GetProcedureNames<Schema>]: ProcedureHandlerFunc<Schema, Key>;
976
+ } : {};
977
+ type HasProcedures<Schema extends SchemaDef> = Schema extends {
978
+ procedures: Record<string, ProcedureDef>;
979
+ } ? true : false;
980
+ /**
981
+ * Extracts QueryOptions from an object with '$options' property.
982
+ */
983
+ type GetQueryOptions<T extends {
984
+ $options: any;
985
+ }> = T['$options'];
986
+
987
+ type IsNever<T> = [T] extends [never] ? true : false;
988
+ /**
989
+ * Filters models based on slicing configuration.
990
+ */
991
+ type GetSlicedModels<Schema extends SchemaDef, Options extends QueryOptions<Schema>> = Options['slicing'] extends infer S ? S extends SlicingOptions<Schema> ? S['includedModels'] extends readonly GetModels<Schema>[] ? Exclude<Extract<S['includedModels'][number], GetModels<Schema>>, S['excludedModels'] extends readonly GetModels<Schema>[] ? S['excludedModels'][number] : never> : Exclude<GetModels<Schema>, S['excludedModels'] extends readonly GetModels<Schema>[] ? S['excludedModels'][number] : never> : GetModels<Schema> : GetModels<Schema>;
992
+ /**
993
+ * Filters query operations based on slicing configuration for a specific model.
994
+ */
995
+ type GetSlicedOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = Options['slicing'] extends infer Slicing ? Slicing extends SlicingOptions<Schema> ? GetIncludedOperations<Slicing, Model> extends infer IO ? GetExcludedOperations<Slicing, Model> extends infer EO ? IO extends '_none_' ? never : IsNever<IO> extends false ? Exclude<IO, EO> : Exclude<AllCrudOperations, EO> : AllCrudOperations : AllCrudOperations : AllCrudOperations : AllCrudOperations;
996
+ type GetIncludedOperations<Slicing extends SlicingOptions<any>, Model extends string> = 'models' extends keyof Slicing ? Slicing extends {
997
+ models: infer Config;
998
+ } ? Model extends keyof Config ? 'includedOperations' extends keyof Config[Model] ? Config[Model] extends {
999
+ includedOperations: readonly [];
1000
+ } ? '_none_' : Config[Model] extends {
1001
+ includedOperations: readonly (infer IO)[];
1002
+ } ? IO : never : GetAllIncludedOperations<Slicing> : GetAllIncludedOperations<Slicing> : AllCrudOperations : AllCrudOperations;
1003
+ type GetAllIncludedOperations<Slicing extends SlicingOptions<any>> = 'models' extends keyof Slicing ? Slicing extends {
1004
+ models: infer Config;
1005
+ } ? '$all' extends keyof Config ? Config['$all'] extends {
1006
+ includedOperations: readonly [];
1007
+ } ? '_none_' : Config['$all'] extends {
1008
+ includedOperations: readonly (infer IO)[];
1009
+ } ? IO : AllCrudOperations : AllCrudOperations : AllCrudOperations : AllCrudOperations;
1010
+ type GetExcludedOperations<Slicing extends SlicingOptions<any>, Model extends string> = 'models' extends keyof Slicing ? Slicing extends {
1011
+ models: infer Config;
1012
+ } ? Model extends keyof Config ? Config[Model] extends {
1013
+ excludedOperations: readonly (infer EO)[];
1014
+ } ? EO : GetAllExcludedOperations<Slicing> : GetAllExcludedOperations<Slicing> : never : never;
1015
+ type GetAllExcludedOperations<Slicing extends SlicingOptions<any>> = 'models' extends keyof Slicing ? Slicing extends {
1016
+ models: infer M;
1017
+ } ? '$all' extends keyof M ? M['$all'] extends {
1018
+ excludedOperations: readonly (infer EO)[];
1019
+ } ? EO : never : never : never : never;
1020
+ /**
1021
+ * Filters procedures based on slicing configuration.
1022
+ */
1023
+ type GetSlicedProcedures<Schema extends SchemaDef, Options extends QueryOptions<Schema>> = Options['slicing'] extends infer S ? S extends SlicingOptions<Schema> ? S['includedProcedures'] extends readonly (infer IncludedProc)[] ? Exclude<Extract<IncludedProc, GetProcedureNames<Schema>>, S['excludedProcedures'] extends readonly (infer ExcludedProc)[] ? Extract<ExcludedProc, GetProcedureNames<Schema>> : never> : Exclude<GetProcedureNames<Schema>, S['excludedProcedures'] extends readonly (infer ExcludedProc)[] ? Extract<ExcludedProc, GetProcedureNames<Schema>> : never> : GetProcedureNames<Schema> : GetProcedureNames<Schema>;
1024
+ /**
1025
+ * Filters filter kinds for a specific field, considering field-level slicing configuration with $all fallback.
1026
+ */
1027
+ type GetSlicedFilterKindsForField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends string, Options extends QueryOptions<Schema>> = Options extends {
1028
+ slicing: infer S;
1029
+ } ? S extends SlicingOptions<Schema> ? GetFieldIncludedFilterKinds<S, Model, Field> extends infer IFK ? GetFieldExcludedFilterKinds<S, Model, Field> extends infer EFK ? '_none_' extends IFK ? never : IsNever<IFK> extends true ? IsNever<EFK> extends true ? FilterKind : Exclude<FilterKind, EFK> : Exclude<IFK, EFK> : FilterKind : FilterKind : FilterKind : FilterKind;
1030
+ type GetIncludedFilterKindsFromModelConfig<ModelConfig, Field extends string> = ModelConfig extends {
1031
+ includedFilterKinds: readonly [];
1032
+ } ? '_none_' : 'fields' extends keyof ModelConfig ? ModelConfig['fields'] extends infer FieldsConfig ? Field extends keyof FieldsConfig ? 'includedFilterKinds' extends keyof FieldsConfig[Field] ? FieldsConfig[Field] extends {
1033
+ includedFilterKinds: readonly [];
1034
+ } ? '_none_' : FieldsConfig[Field] extends {
1035
+ includedFilterKinds: readonly (infer IFK)[];
1036
+ } ? IFK : never : GetAllFieldsIncludedFilterKinds<FieldsConfig> : GetAllFieldsIncludedFilterKinds<FieldsConfig> : never : never;
1037
+ type GetFieldIncludedFilterKinds<S extends SlicingOptions<any>, Model extends string, Field extends string> = S extends {
1038
+ models?: infer Config;
1039
+ } ? Model extends keyof Config ? GetIncludedFilterKindsFromModelConfig<Config[Model], Field> : '$all' extends keyof Config ? GetIncludedFilterKindsFromModelConfig<Config['$all'], Field> : never : never;
1040
+ type GetAllFieldsIncludedFilterKinds<FieldsConfig> = '$all' extends keyof FieldsConfig ? FieldsConfig['$all'] extends {
1041
+ includedFilterKinds: readonly [];
1042
+ } ? '_none_' : FieldsConfig['$all'] extends {
1043
+ includedFilterKinds: readonly (infer IFK)[];
1044
+ } ? IFK : never : never;
1045
+ type GetExcludedFilterKindsFromModelConfig<ModelConfig, Field extends string> = 'fields' extends keyof ModelConfig ? ModelConfig['fields'] extends infer FieldsConfig ? Field extends keyof FieldsConfig ? FieldsConfig[Field] extends {
1046
+ excludedFilterKinds: readonly (infer EFK)[];
1047
+ } ? EFK : GetAllFieldsExcludedFilterKinds<FieldsConfig> : GetAllFieldsExcludedFilterKinds<FieldsConfig> : never : never;
1048
+ type GetFieldExcludedFilterKinds<S extends SlicingOptions<any>, Model extends string, Field extends string> = S extends {
1049
+ models?: infer Config;
1050
+ } ? Model extends keyof Config ? GetExcludedFilterKindsFromModelConfig<Config[Model], Field> : '$all' extends keyof Config ? GetExcludedFilterKindsFromModelConfig<Config['$all'], Field> : never : never;
1051
+ type GetAllFieldsExcludedFilterKinds<FieldsConfig> = '$all' extends keyof FieldsConfig ? FieldsConfig['$all'] extends {
1052
+ excludedFilterKinds: readonly (infer EFK)[];
1053
+ } ? EFK : never : never;
1054
+
1055
+ type DefaultModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Omit = undefined, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<{
1056
+ [Key in NonRelationFields<Schema, Model> as ShouldOmitField<Schema, Model, Options, Key, Omit> extends true ? never : Key]: MapModelFieldType<Schema, Model, Key>;
1057
+ }, Optional, Array>;
1058
+ 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>;
1059
+ 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;
1060
+ 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;
1061
+ type SchemaLevelOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['omit'] extends true ? true : false;
1062
+ type ModelSelectResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Select, Omit, Options extends QueryOptions<Schema>> = {
1063
+ [Key in keyof Select as Select[Key] extends false | undefined ? never : Key extends '_count' ? Select[Key] extends SelectCount<Schema, Model, Options> ? 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;
936
1064
  };
937
- type CountResult<Schema extends SchemaDef, _Model extends GetModels<Schema>, Args> = Args extends {
1065
+ type SelectCountResult<Schema extends SchemaDef, Model extends GetModels<Schema>, C> = C extends true ? {
1066
+ [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: number;
1067
+ } : C extends {
938
1068
  select: infer S;
939
- } ? S extends true ? number : {
1069
+ } ? {
940
1070
  [Key in keyof S]: number;
941
- } : number;
942
- type AggregateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1071
+ } : never;
1072
+ type ModelResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Optional = false, Array = false> = WrapType<Args extends {
1073
+ select: infer S extends object;
1074
+ omit?: infer O extends object;
1075
+ } & Record<string, unknown> ? ModelSelectResult<Schema, Model, S, O, Options> : Args extends {
1076
+ include: infer I extends object;
1077
+ omit?: infer O extends object;
1078
+ } & Record<string, unknown> ? // select all non-omitted scalar fields
1079
+ DefaultModelResult<Schema, Model, O, Options, false, false> & {
1080
+ [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>>;
1081
+ } & ('_count' extends keyof I ? I['_count'] extends false | undefined ? {} : {
1082
+ _count: SelectCountResult<Schema, Model, I['_count']>;
1083
+ } : {}) : Args extends {
1084
+ omit: infer O;
1085
+ } & Record<string, unknown> ? DefaultModelResult<Schema, Model, O, Options, false, false> : DefaultModelResult<Schema, Model, undefined, Options, false, false>, Optional, Array>;
1086
+ 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>>;
1087
+ type SimplifiedPlainResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args = {}, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Simplify<ModelResult<Schema, Model, Args, Options, false, false>>;
1088
+ type TypeDefResult<Schema extends SchemaDef, TypeDef extends GetTypeDefs<Schema>, Partial extends boolean = false> = PartialIf<Optional<{
1089
+ [Key in GetTypeDefFields<Schema, TypeDef>]: MapFieldDefType<Schema, GetTypeDefField<Schema, TypeDef, Key>, Partial>;
1090
+ }, Partial extends true ? never : keyof {
1091
+ [Key in GetTypeDefFields<Schema, TypeDef> as TypeDefFieldIsOptional<Schema, TypeDef, Key> extends true ? Key : never]: true;
1092
+ }>, Partial> & Record<string, unknown>;
1093
+ type BatchResult = {
1094
+ count: number;
1095
+ };
1096
+ type WhereInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>, ScalarOnly extends boolean = false, WithAggregations extends boolean = false> = {
1097
+ [Key in GetModelFields<Schema, Model> as ScalarOnly extends true ? Key extends RelationFields<Schema, Model> ? never : Key : Key]?: FieldFilter<Schema, Model, Key, Options, WithAggregations>;
1098
+ } & {
1099
+ $expr?: (eb: ExpressionBuilder<ToKyselySchema<Schema>, Model>) => OperandExpression<SqlBool>;
1100
+ } & {
1101
+ AND?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1102
+ OR?: WhereInput<Schema, Model, Options, ScalarOnly>[];
1103
+ NOT?: OrArray<WhereInput<Schema, Model, Options, ScalarOnly>>;
1104
+ };
1105
+ type FieldFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Options extends QueryOptions<Schema>, WithAggregations extends boolean, AllowedKinds extends FilterKind = GetSlicedFilterKindsForField<Schema, Model, Field, Options>> = Field extends RelationFields<Schema, Model> ? RelationFilter<Schema, Model, Field, Options, AllowedKinds> : FieldIsArray<Schema, Model, Field> extends true ? ArrayFilter<Schema, GetModelFieldType<Schema, Model, Field>, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetEnums<Schema> ? EnumFilter<Schema, GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds> : GetModelFieldType<Schema, Model, Field> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetModelFieldType<Schema, Model, Field>, FieldIsArray<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, AllowedKinds> : PrimitiveFilter<GetModelFieldType<Schema, Model, Field>, ModelFieldIsOptional<Schema, Model, Field>, WithAggregations, AllowedKinds>;
1106
+ type EnumFilter<Schema extends SchemaDef, T extends GetEnums<Schema>, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<keyof GetEnum<Schema, T>, Nullable> : never) | (('Equality' extends AllowedKinds ? {
943
1107
  /**
944
- * Filter conditions
1108
+ * Checks for equality with the specified enum value.
945
1109
  */
946
- where?: WhereInput<Schema, Model>;
1110
+ equals?: NullableIf<keyof GetEnum<Schema, T>, Nullable>;
947
1111
  /**
948
- * Number of records to skip for the aggregation
1112
+ * Checks if the enum value is in the specified list of values.
949
1113
  */
950
- skip?: number;
1114
+ in?: (keyof GetEnum<Schema, T>)[];
951
1115
  /**
952
- * Number of records to take for the aggregation
1116
+ * Checks if the enum value is not in the specified list of values.
953
1117
  */
954
- take?: number;
1118
+ notIn?: (keyof GetEnum<Schema, T>)[];
1119
+ } : {}) & {
955
1120
  /**
956
- * Order by clauses
1121
+ * Builds a negated filter.
957
1122
  */
958
- orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
959
- } & {
1123
+ not?: EnumFilter<Schema, T, Nullable, WithAggregations, AllowedKinds>;
1124
+ } & (WithAggregations extends true ? {
960
1125
  /**
961
- * Performs count aggregation.
1126
+ * Filters against the count of records.
962
1127
  */
963
- _count?: true | CountAggregateInput<Schema, Model>;
1128
+ _count?: NumberFilter<'Int', false, false, AllowedKinds>;
964
1129
  /**
965
- * Performs minimum value aggregation.
1130
+ * Filters against the minimum value.
966
1131
  */
967
- _min?: MinMaxInput<Schema, Model, true>;
1132
+ _min?: EnumFilter<Schema, T, false, false, AllowedKinds>;
968
1133
  /**
969
- * Performs maximum value aggregation.
1134
+ * Filters against the maximum value.
970
1135
  */
971
- _max?: MinMaxInput<Schema, Model, true>;
972
- } & (NumericFields<Schema, Model> extends never ? {} : {
1136
+ _max?: EnumFilter<Schema, T, false, false, AllowedKinds>;
1137
+ } : {}));
1138
+ type ArrayFilter<Schema extends SchemaDef, Type extends string, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
973
1139
  /**
974
- * Performs average value aggregation.
1140
+ * Checks if the array equals the specified array.
975
1141
  */
976
- _avg?: SumAvgInput<Schema, Model, true>;
1142
+ equals?: MapScalarType<Schema, Type>[] | null;
1143
+ } : {}) & ('List' extends AllowedKinds ? {
977
1144
  /**
978
- * Performs sum value aggregation.
1145
+ * Checks if the array contains all elements of the specified array.
979
1146
  */
980
- _sum?: SumAvgInput<Schema, Model, true>;
981
- });
982
- type NumericFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
983
- [Key in GetModelFields<Schema, Model> as GetModelFieldType<Schema, Model, Key> extends 'Int' | 'Float' | 'BigInt' | 'Decimal' ? FieldIsArray<Schema, Model, Key> extends true ? never : Key : never]: GetModelField<Schema, Model, Key>;
984
- };
985
- type SumAvgInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ValueType> = {
986
- [Key in NumericFields<Schema, Model>]?: ValueType;
987
- };
988
- type MinMaxInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ValueType> = {
989
- [Key in GetModelFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? never : FieldIsRelation<Schema, Model, Key> extends true ? never : Key]?: ValueType;
990
- };
991
- type AggregateResult<Schema extends SchemaDef, _Model extends GetModels<Schema>, Args> = (Args extends {
992
- _count: infer Count;
993
- } ? {
1147
+ has?: MapScalarType<Schema, Type> | null;
994
1148
  /**
995
- * Count aggregation result
1149
+ * Checks if the array contains any of the elements of the specified array.
996
1150
  */
997
- _count: AggCommonOutput<Count>;
998
- } : {}) & (Args extends {
999
- _sum: infer Sum;
1000
- } ? {
1151
+ hasEvery?: MapScalarType<Schema, Type>[];
1001
1152
  /**
1002
- * Sum aggregation result
1153
+ * Checks if the array contains some of the elements of the specified array.
1003
1154
  */
1004
- _sum: AggCommonOutput<Sum>;
1005
- } : {}) & (Args extends {
1006
- _avg: infer Avg;
1007
- } ? {
1155
+ hasSome?: MapScalarType<Schema, Type>[];
1008
1156
  /**
1009
- * Average aggregation result
1157
+ * Checks if the array is empty.
1010
1158
  */
1011
- _avg: AggCommonOutput<Avg>;
1012
- } : {}) & (Args extends {
1013
- _min: infer Min;
1014
- } ? {
1159
+ isEmpty?: boolean;
1160
+ } : {});
1161
+ type MapScalarType<Schema extends SchemaDef, Type extends string> = Type extends GetEnums<Schema> ? keyof GetEnum<Schema, Type> : MapBaseType$1<Type>;
1162
+ type PrimitiveFilter<T extends string, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = T extends 'String' ? StringFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Int' | 'Float' | 'Decimal' | 'BigInt' ? NumberFilter<T, Nullable, WithAggregations, AllowedKinds> : T extends 'Boolean' ? BooleanFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'DateTime' ? DateTimeFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Bytes' ? BytesFilter<Nullable, WithAggregations, AllowedKinds> : T extends 'Json' ? JsonFilter<AllowedKinds> : never;
1163
+ type CommonPrimitiveFilter<DataType, T extends BuiltinType, Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind> = ('Equality' extends AllowedKinds ? {
1015
1164
  /**
1016
- * Minimum aggregation result
1165
+ * Checks for equality with the specified value.
1017
1166
  */
1018
- _min: AggCommonOutput<Min>;
1019
- } : {}) & (Args extends {
1020
- _max: infer Max;
1021
- } ? {
1167
+ equals?: NullableIf<DataType, Nullable>;
1022
1168
  /**
1023
- * Maximum aggregation result
1169
+ * Checks if the value is in the specified list of values.
1024
1170
  */
1025
- _max: AggCommonOutput<Max>;
1026
- } : {});
1027
- type AggCommonOutput<Input> = Input extends true ? number : Input extends {} ? {
1028
- [Key in keyof Input]: number;
1029
- } : never;
1030
- type GroupByHaving<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<WhereInput<Schema, Model, true, true>, '$expr'>;
1031
- type GroupByArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1171
+ in?: DataType[];
1032
1172
  /**
1033
- * Filter conditions
1173
+ * Checks if the value is not in the specified list of values.
1034
1174
  */
1035
- where?: WhereInput<Schema, Model>;
1175
+ notIn?: DataType[];
1176
+ } : {}) & ('Range' extends AllowedKinds ? {
1036
1177
  /**
1037
- * Order by clauses
1178
+ * Checks if the value is less than the specified value.
1038
1179
  */
1039
- orderBy?: OrArray<OrderBy<Schema, Model, false, true>>;
1180
+ lt?: DataType;
1040
1181
  /**
1041
- * Fields to group by
1182
+ * Checks if the value is less than or equal to the specified value.
1042
1183
  */
1043
- by: NonRelationFields<Schema, Model> | NonEmptyArray<NonRelationFields<Schema, Model>>;
1184
+ lte?: DataType;
1044
1185
  /**
1045
- * Filter conditions for the grouped records
1186
+ * Checks if the value is greater than the specified value.
1046
1187
  */
1047
- having?: GroupByHaving<Schema, Model>;
1188
+ gt?: DataType;
1048
1189
  /**
1049
- * Number of records to take for grouping
1190
+ * Checks if the value is greater than or equal to the specified value.
1050
1191
  */
1051
- take?: number;
1192
+ gte?: DataType;
1052
1193
  /**
1053
- * Number of records to skip for grouping
1194
+ * Checks if the value is between the specified values (inclusive).
1054
1195
  */
1055
- skip?: number;
1196
+ between?: [start: DataType, end: DataType];
1197
+ } : {}) & {
1056
1198
  /**
1057
- * Performs count aggregation.
1199
+ * Builds a negated filter.
1058
1200
  */
1059
- _count?: true | CountAggregateInput<Schema, Model>;
1201
+ not?: PrimitiveFilter<T, Nullable, WithAggregations, AllowedKinds>;
1202
+ };
1203
+ type StringFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<string, Nullable> : never) | (CommonPrimitiveFilter<string, 'String', Nullable, WithAggregations, AllowedKinds> & ('Like' extends AllowedKinds ? {
1060
1204
  /**
1061
- * Performs minimum value aggregation.
1205
+ * Checks if the string contains the specified substring.
1062
1206
  */
1063
- _min?: MinMaxInput<Schema, Model, true>;
1207
+ contains?: string;
1064
1208
  /**
1065
- * Performs maximum value aggregation.
1209
+ * Checks if the string starts with the specified substring.
1066
1210
  */
1067
- _max?: MinMaxInput<Schema, Model, true>;
1068
- } & (NumericFields<Schema, Model> extends never ? {} : {
1211
+ startsWith?: string;
1069
1212
  /**
1070
- * Performs average value aggregation.
1213
+ * Checks if the string ends with the specified substring.
1071
1214
  */
1072
- _avg?: SumAvgInput<Schema, Model, true>;
1215
+ endsWith?: string;
1073
1216
  /**
1074
- * Performs sum value aggregation.
1217
+ * Specifies the string comparison mode. Not effective for "sqlite" provider
1075
1218
  */
1076
- _sum?: SumAvgInput<Schema, Model, true>;
1077
- });
1078
- type GroupByResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args extends {
1079
- by: unknown;
1080
- }> = Array<{
1081
- [Key in NonRelationFields<Schema, Model> as Key extends ValueOfPotentialTuple<Args['by']> ? Key : never]: MapModelFieldType<Schema, Model, Key>;
1082
- } & (Args extends {
1083
- _count: infer Count;
1084
- } ? {
1219
+ mode?: 'default' | 'insensitive';
1220
+ } : {}) & (WithAggregations extends true ? {
1085
1221
  /**
1086
- * Count aggregation result
1222
+ * Filters against the count of records.
1087
1223
  */
1088
- _count: AggCommonOutput<Count>;
1089
- } : {}) & (Args extends {
1090
- _avg: infer Avg;
1091
- } ? {
1224
+ _count?: NumberFilter<'Int', false, false, AllowedKinds>;
1092
1225
  /**
1093
- * Average aggregation result
1226
+ * Filters against the minimum value.
1094
1227
  */
1095
- _avg: AggCommonOutput<Avg>;
1096
- } : {}) & (Args extends {
1097
- _sum: infer Sum;
1098
- } ? {
1228
+ _min?: StringFilter<false, false, AllowedKinds>;
1099
1229
  /**
1100
- * Sum aggregation result
1230
+ * Filters against the maximum value.
1101
1231
  */
1102
- _sum: AggCommonOutput<Sum>;
1103
- } : {}) & (Args extends {
1104
- _min: infer Min;
1105
- } ? {
1232
+ _max?: StringFilter<false, false, AllowedKinds>;
1233
+ } : {}));
1234
+ type NumberFilter<T extends 'Int' | 'Float' | 'Decimal' | 'BigInt', Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<number | bigint, Nullable> : never) | (CommonPrimitiveFilter<number, T, Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1106
1235
  /**
1107
- * Minimum aggregation result
1236
+ * Filters against the count of records.
1108
1237
  */
1109
- _min: AggCommonOutput<Min>;
1110
- } : {}) & (Args extends {
1111
- _max: infer Max;
1112
- } ? {
1238
+ _count?: NumberFilter<'Int', false, false, AllowedKinds>;
1113
1239
  /**
1114
- * Maximum aggregation result
1240
+ * Filters against the average value.
1115
1241
  */
1116
- _max: AggCommonOutput<Max>;
1117
- } : {})>;
1118
- 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>>;
1119
- 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>>;
1120
- 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>>;
1121
- type SetRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>>;
1122
- type NestedUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<{
1242
+ _avg?: NumberFilter<T, false, false, AllowedKinds>;
1123
1243
  /**
1124
- * Unique filter to select the record to update.
1244
+ * Filters against the sum value.
1125
1245
  */
1126
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1246
+ _sum?: NumberFilter<T, false, false, AllowedKinds>;
1127
1247
  /**
1128
- * The data to update the record with.
1248
+ * Filters against the minimum value.
1129
1249
  */
1130
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1131
- }, true> : XOR<{
1250
+ _min?: NumberFilter<T, false, false, AllowedKinds>;
1132
1251
  /**
1133
- * Filter to select the record to update.
1252
+ * Filters against the maximum value.
1134
1253
  */
1135
- where?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>>;
1254
+ _max?: NumberFilter<T, false, false, AllowedKinds>;
1255
+ } : {}));
1256
+ type DateTimeFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<Date | string, Nullable> : never) | (CommonPrimitiveFilter<Date | string, 'DateTime', Nullable, WithAggregations, AllowedKinds> & (WithAggregations extends true ? {
1136
1257
  /**
1137
- * The data to update the record with.
1258
+ * Filters against the count of records.
1138
1259
  */
1139
- data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1140
- }, UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>>;
1141
- type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<{
1260
+ _count?: NumberFilter<'Int', false, false, AllowedKinds>;
1142
1261
  /**
1143
- * Unique filter to select the record to update.
1262
+ * Filters against the minimum value.
1144
1263
  */
1145
- where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>>;
1264
+ _min?: DateTimeFilter<false, false, AllowedKinds>;
1146
1265
  /**
1147
- * The data to create the record if it doesn't exist.
1266
+ * Filters against the maximum value.
1148
1267
  */
1149
- create: CreateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1268
+ _max?: DateTimeFilter<false, false, AllowedKinds>;
1269
+ } : {}));
1270
+ type BytesFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<Uint8Array | Buffer, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1150
1271
  /**
1151
- * The data to update the record with if it exists.
1272
+ * Checks for equality with the specified value.
1152
1273
  */
1153
- update: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1154
- }, FieldIsArray<Schema, Model, Field>>;
1155
- 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>>>;
1156
- 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>>;
1157
- type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, true>>;
1158
- type GetProcedureNames<Schema extends SchemaDef> = Schema extends {
1159
- procedures: Record<string, ProcedureDef>;
1160
- } ? keyof Schema['procedures'] : never;
1161
- type GetProcedureParams<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1162
- procedures: Record<string, ProcedureDef>;
1163
- } ? Schema['procedures'][ProcName]['params'] : never;
1164
- type GetProcedure<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
1165
- procedures: Record<string, ProcedureDef>;
1166
- } ? Schema['procedures'][ProcName] : never;
1167
- type _OptionalProcedureParamNames<Params> = keyof {
1168
- [K in keyof Params as Params[K] extends {
1169
- optional: true;
1170
- } ? K : never]: K;
1171
- };
1172
- type _RequiredProcedureParamNames<Params> = keyof {
1173
- [K in keyof Params as Params[K] extends {
1174
- optional: true;
1175
- } ? never : K]: K;
1176
- };
1177
- type _HasRequiredProcedureParams<Params> = _RequiredProcedureParamNames<Params> extends never ? false : true;
1178
- type MapProcedureArgsObject<Schema extends SchemaDef, Params> = Simplify<Optional<{
1179
- [K in keyof Params]: MapProcedureParam<Schema, Params[K]>;
1180
- }, _OptionalProcedureParamNames<Params>>>;
1181
- type ProcedureEnvelope<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>, Params = GetProcedureParams<Schema, ProcName>> = keyof Params extends never ? {
1182
- args?: Record<string, never>;
1183
- } : _HasRequiredProcedureParams<Params> extends true ? {
1184
- args: MapProcedureArgsObject<Schema, Params>;
1185
- } : {
1186
- args?: MapProcedureArgsObject<Schema, Params>;
1187
- };
1188
- type ProcedureHandlerCtx<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = {
1189
- client: ClientContract<Schema>;
1190
- } & ProcedureEnvelope<Schema, ProcName>;
1191
- /**
1192
- * Shape of a procedure's runtime function.
1193
- */
1194
- 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>>>;
1195
- /**
1196
- * Signature for procedure handlers configured via client options.
1197
- */
1198
- type ProcedureHandlerFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (ctx: ProcedureHandlerCtx<Schema, ProcName>) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
1199
- type MapProcedureReturn<Schema extends SchemaDef, Proc> = Proc extends {
1200
- returnType: infer R;
1201
- } ? Proc extends {
1202
- returnArray: true;
1203
- } ? Array<MapType<Schema, R & string>> : MapType<Schema, R & string> : never;
1204
- type MapProcedureParam<Schema extends SchemaDef, P> = P extends {
1205
- type: infer U;
1206
- } ? OrUndefinedIf<P extends {
1207
- array: true;
1208
- } ? Array<MapType<Schema, U & string>> : MapType<Schema, U & string>, P extends {
1209
- optional: true;
1210
- } ? true : false> : never;
1211
- type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1212
- [Key in RelationFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends {
1213
- references: readonly unknown[];
1214
- } ? never : Key]: true;
1215
- };
1216
- type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1217
- [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
1218
- } extends never ? false : true;
1219
- type EnumValue<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = GetEnum<Schema, Enum>[keyof GetEnum<Schema, Enum>];
1220
- 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;
1221
- type ProviderSupportsDistinct<Schema extends SchemaDef> = Schema['provider']['type'] extends 'postgresql' ? true : false;
1222
-
1223
- declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
1224
- protected readonly schema: Schema;
1225
- protected readonly options: ClientOptions<Schema>;
1226
- protected eb: ExpressionBuilder<any, any>;
1227
- constructor(schema: Schema, options: ClientOptions<Schema>);
1274
+ equals?: NullableIf<Uint8Array, Nullable>;
1228
1275
  /**
1229
- * Whether the dialect supports updating with a limit on the number of updated rows.
1276
+ * Checks if the value is in the specified list of values.
1230
1277
  */
1231
- abstract get supportsUpdateWithLimit(): boolean;
1278
+ in?: Uint8Array[];
1232
1279
  /**
1233
- * Whether the dialect supports deleting with a limit on the number of deleted rows.
1280
+ * Checks if the value is not in the specified list of values.
1234
1281
  */
1235
- abstract get supportsDeleteWithLimit(): boolean;
1282
+ notIn?: Uint8Array[];
1283
+ } : {}) & {
1236
1284
  /**
1237
- * Whether the dialect supports DISTINCT ON.
1285
+ * Builds a negated filter.
1238
1286
  */
1239
- abstract get supportsDistinctOn(): boolean;
1287
+ not?: BytesFilter<Nullable, WithAggregations, AllowedKinds>;
1288
+ } & (WithAggregations extends true ? {
1240
1289
  /**
1241
- * Whether the dialect support inserting with `DEFAULT` as field value.
1290
+ * Filters against the count of records.
1242
1291
  */
1243
- abstract get supportsDefaultAsFieldValue(): boolean;
1292
+ _count?: NumberFilter<'Int', false, false, AllowedKinds>;
1244
1293
  /**
1245
- * Whether the dialect supports the RETURNING clause in INSERT/UPDATE/DELETE statements.
1294
+ * Filters against the minimum value.
1246
1295
  */
1247
- abstract get supportsReturning(): boolean;
1296
+ _min?: BytesFilter<false, false, AllowedKinds>;
1248
1297
  /**
1249
- * Whether the dialect supports `INSERT INTO ... DEFAULT VALUES` syntax.
1298
+ * Filters against the maximum value.
1250
1299
  */
1251
- abstract get supportsInsertDefaultValues(): boolean;
1300
+ _max?: BytesFilter<false, false, AllowedKinds>;
1301
+ } : {}));
1302
+ type BooleanFilter<Nullable extends boolean, WithAggregations extends boolean, AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? NullableIf<boolean, Nullable> : never) | (('Equality' extends AllowedKinds ? {
1252
1303
  /**
1253
- * How to perform insert ignore operation.
1304
+ * Checks for equality with the specified value.
1254
1305
  */
1255
- abstract get insertIgnoreMethod(): 'onConflict' | 'ignore';
1306
+ equals?: NullableIf<boolean, Nullable>;
1307
+ } : {}) & {
1256
1308
  /**
1257
- * Transforms input value before sending to database.
1309
+ * Builds a negated filter.
1258
1310
  */
1259
- transformInput(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
1311
+ not?: BooleanFilter<Nullable, WithAggregations, AllowedKinds>;
1312
+ } & (WithAggregations extends true ? {
1260
1313
  /**
1261
- * Transforms output value received from database.
1314
+ * Filters against the count of records.
1262
1315
  */
1263
- transformOutput(value: unknown, _type: BuiltinType, _array: boolean): unknown;
1264
- buildSelectModel(model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
1265
- buildFilterSortTake(model: string, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
1266
- buildFilter(model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
1267
- private buildCursorFilter;
1268
- private isLogicalCombinator;
1269
- protected buildCompositeFilter(model: string, modelAlias: string, key: (typeof LOGICAL_COMBINATORS)[number], payload: any): Expression<SqlBool>;
1270
- private buildRelationFilter;
1271
- private buildToOneRelationFilter;
1272
- private buildToManyRelationFilter;
1273
- private buildArrayFilter;
1274
- buildPrimitiveFilter(fieldRef: Expression<any>, fieldDef: FieldDef, payload: any): any;
1275
- private buildJsonFilter;
1276
- private buildPlainJsonFilter;
1277
- private buildTypedJsonFilter;
1278
- private buildTypedJsonArrayFilter;
1279
- private buildTypeJsonNonArrayFilter;
1280
- private buildJsonValueFilterClause;
1281
- protected buildJsonEqualityFilter(lhs: Expression<any>, rhs: unknown): ExpressionWrapper<any, any, SqlBool>;
1282
- private buildLiteralFilter;
1283
- private buildStandardFilter;
1284
- private buildStringFilter;
1285
- private buildJsonStringFilter;
1286
- private escapeLikePattern;
1287
- private buildStringLike;
1288
- private prepStringCasing;
1289
- private buildNumberFilter;
1290
- private buildBooleanFilter;
1291
- private buildDateTimeFilter;
1292
- private buildBytesFilter;
1293
- private buildEnumFilter;
1294
- buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, negated: boolean, take: number | undefined): SelectQueryBuilder<any, any, any>;
1295
- buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined | null, modelAlias: string): SelectQueryBuilder<any, any, any>;
1296
- shouldOmitField(omit: unknown, model: string, field: string): any;
1297
- protected buildModelSelect(model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
1298
- buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
1299
- buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
1300
- buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): AliasableExpression<unknown>;
1301
- protected negateSort(sort: SortOrder, negated: boolean): SortOrder;
1302
- true(): Expression<SqlBool>;
1303
- false(): Expression<SqlBool>;
1304
- isTrue(expression: Expression<SqlBool>): boolean;
1305
- isFalse(expression: Expression<SqlBool>): boolean;
1306
- and(...args: Expression<SqlBool>[]): Expression<SqlBool>;
1307
- or(...args: Expression<SqlBool>[]): Expression<SqlBool>;
1308
- not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
1309
- fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean): any;
1310
- protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
1311
- abstract get provider(): DataSourceProviderType;
1316
+ _count?: NumberFilter<'Int', false, false, AllowedKinds>;
1312
1317
  /**
1313
- * Builds selection for a relation field.
1318
+ * Filters against the minimum value.
1314
1319
  */
1315
- abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>): SelectQueryBuilder<any, any, any>;
1320
+ _min?: BooleanFilter<false, false, AllowedKinds>;
1316
1321
  /**
1317
- * Builds skip and take clauses.
1322
+ * Filters against the maximum value.
1318
1323
  */
1319
- abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
1324
+ _max?: BooleanFilter<false, false, AllowedKinds>;
1325
+ } : {}));
1326
+ type JsonFilter<AllowedKinds extends FilterKind = FilterKind> = ('Equality' extends AllowedKinds ? {
1320
1327
  /**
1321
- * Builds an Kysely expression that returns a JSON object for the given key-value pairs.
1328
+ * Checks for equality with the specified value.
1322
1329
  */
1323
- abstract buildJsonObject(value: Record<string, Expression<unknown>>): AliasableExpression<unknown>;
1330
+ equals?: JsonValue | JsonNullValues;
1324
1331
  /**
1325
- * Builds an Kysely expression that returns the length of an array.
1332
+ * Builds a negated filter.
1326
1333
  */
1327
- abstract buildArrayLength(array: Expression<unknown>): AliasableExpression<number>;
1334
+ not?: JsonValue | JsonNullValues;
1335
+ } : {}) & ('Json' extends AllowedKinds ? {
1328
1336
  /**
1329
- * Builds an array value expression.
1337
+ * JSON path to select the value to filter on. If omitted, the whole JSON value is used.
1330
1338
  */
1331
- abstract buildArrayValue(values: Expression<unknown>[], elemType: string): AliasableExpression<unknown>;
1339
+ path?: string;
1332
1340
  /**
1333
- * Builds an expression that checks if an array contains a single value.
1341
+ * Checks if the value is a string and contains the specified substring.
1334
1342
  */
1335
- abstract buildArrayContains(field: Expression<unknown>, value: Expression<unknown>, elemType?: string): AliasableExpression<SqlBool>;
1343
+ string_contains?: string;
1336
1344
  /**
1337
- * Builds an expression that checks if an array contains all values from another array.
1345
+ * Checks if the value is a string and starts with the specified substring.
1338
1346
  */
1339
- abstract buildArrayHasEvery(field: Expression<unknown>, values: Expression<unknown>): AliasableExpression<SqlBool>;
1347
+ string_starts_with?: string;
1340
1348
  /**
1341
- * Builds an expression that checks if an array overlaps with another array.
1349
+ * Checks if the value is a string and ends with the specified substring.
1342
1350
  */
1343
- abstract buildArrayHasSome(field: Expression<unknown>, values: Expression<unknown>): AliasableExpression<SqlBool>;
1351
+ string_ends_with?: string;
1344
1352
  /**
1345
- * Casts the given expression to an integer type.
1353
+ * String comparison mode. Not effective for "sqlite" provider
1346
1354
  */
1347
- abstract castInt<T extends Expression<any>>(expression: T): T;
1355
+ mode?: 'default' | 'insensitive';
1348
1356
  /**
1349
- * Casts the given expression to a text type.
1357
+ * Checks if the value is an array and contains the specified value.
1350
1358
  */
1351
- abstract castText<T extends Expression<any>>(expression: T): T;
1359
+ array_contains?: JsonValue;
1352
1360
  /**
1353
- * Trims double quotes from the start and end of a text expression.
1361
+ * Checks if the value is an array and starts with the specified value.
1354
1362
  */
1355
- abstract trimTextQuotes<T extends Expression<string>>(expression: T): T;
1356
- abstract getStringCasingBehavior(): {
1357
- supportsILike: boolean;
1358
- likeCaseSensitive: boolean;
1359
- };
1363
+ array_starts_with?: JsonValue;
1360
1364
  /**
1361
- * Builds a VALUES table and select all fields from it.
1365
+ * Checks if the value is an array and ends with the specified value.
1362
1366
  */
1363
- abstract buildValuesTableSelect(fields: FieldDef[], rows: unknown[][]): SelectQueryBuilder<any, any, any>;
1367
+ array_ends_with?: JsonValue;
1368
+ } : {});
1369
+ type TypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = XOR<JsonFilter<AllowedKinds>, TypedJsonTypedFilter<Schema, TypeDefName, Array, Optional, AllowedKinds>>;
1370
+ type TypedJsonTypedFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, Array extends boolean, Optional extends boolean, AllowedKinds extends FilterKind> = 'Json' extends AllowedKinds ? (Array extends true ? ArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds> : NonArrayTypedJsonFilter<Schema, TypeDefName, AllowedKinds>) | (Optional extends true ? null : never) : {};
1371
+ type ArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = {
1372
+ some?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1373
+ every?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1374
+ none?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1375
+ };
1376
+ type NonArrayTypedJsonFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = {
1377
+ is?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1378
+ isNot?: TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1379
+ } | TypedJsonFieldsFilter<Schema, TypeDefName, AllowedKinds>;
1380
+ type TypedJsonFieldsFilter<Schema extends SchemaDef, TypeDefName extends GetTypeDefs<Schema>, AllowedKinds extends FilterKind> = {
1381
+ [Key in GetTypeDefFields<Schema, TypeDefName>]?: GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetTypeDefs<Schema> ? TypedJsonFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsArray<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, AllowedKinds> : TypeDefFieldIsArray<Schema, TypeDefName, Key> extends true ? ArrayFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, AllowedKinds> : GetTypeDefFieldType<Schema, TypeDefName, Key> extends GetEnums<Schema> ? EnumFilter<Schema, GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds> : PrimitiveFilter<GetTypeDefFieldType<Schema, TypeDefName, Key>, TypeDefFieldIsOptional<Schema, TypeDefName, Key>, false, AllowedKinds>;
1382
+ };
1383
+ type SortOrder = 'asc' | 'desc';
1384
+ type NullsOrder = 'first' | 'last';
1385
+ type OrderBy<Schema extends SchemaDef, Model extends GetModels<Schema>, WithRelation extends boolean, WithAggregation extends boolean> = {
1386
+ [Key in NonRelationFields<Schema, Model>]?: ModelFieldIsOptional<Schema, Model, Key> extends true ? SortOrder | {
1387
+ /**
1388
+ * Sort order
1389
+ */
1390
+ sort: SortOrder;
1391
+ /**
1392
+ * Treatment of null values
1393
+ */
1394
+ nulls?: NullsOrder;
1395
+ } : SortOrder;
1396
+ } & (WithRelation extends true ? {
1397
+ [Key in RelationFields<Schema, Model>]?: FieldIsArray<Schema, Model, Key> extends true ? {
1398
+ /**
1399
+ * Sorts by the count of related records.
1400
+ */
1401
+ _count?: SortOrder;
1402
+ } : OrderBy<Schema, RelationFieldType<Schema, Model, Key>, WithRelation, WithAggregation>;
1403
+ } : {}) & (WithAggregation extends true ? {
1364
1404
  /**
1365
- * Builds a JSON path selection expression.
1405
+ * Sorts by the count of records.
1366
1406
  */
1367
- protected abstract buildJsonPathSelection(receiver: Expression<any>, path: string | undefined): Expression<any>;
1407
+ _count?: OrderBy<Schema, Model, false, false>;
1368
1408
  /**
1369
- * Builds a JSON array filter expression.
1409
+ * Sorts by the minimum value.
1370
1410
  */
1371
- protected abstract buildJsonArrayFilter(receiver: Expression<any>, operation: 'array_contains' | 'array_starts_with' | 'array_ends_with', value: unknown): Expression<SqlBool>;
1411
+ _min?: MinMaxInput<Schema, Model, SortOrder>;
1372
1412
  /**
1373
- * Builds a JSON array exists predicate (returning if any element matches the filter).
1413
+ * Sorts by the maximum value.
1374
1414
  */
1375
- protected abstract buildJsonArrayExistsPredicate(receiver: Expression<any>, buildFilter: (elem: Expression<any>) => Expression<SqlBool>): Expression<SqlBool>;
1415
+ _max?: MinMaxInput<Schema, Model, SortOrder>;
1416
+ } & (NumericFields<Schema, Model> extends never ? {} : {
1376
1417
  /**
1377
- * Builds an ORDER BY clause for a field with NULLS FIRST/LAST support.
1418
+ * Sorts by the average value.
1378
1419
  */
1379
- protected abstract buildOrderByField(query: SelectQueryBuilder<any, any, any>, field: Expression<unknown>, sort: SortOrder, nulls: 'first' | 'last'): SelectQueryBuilder<any, any, any>;
1380
- }
1381
-
1382
- declare class InputValidator<Schema extends SchemaDef> {
1383
- private readonly client;
1384
- private readonly schemaCache;
1385
- constructor(client: ClientContract<Schema>);
1386
- private get schema();
1387
- private get options();
1388
- private get extraValidationsEnabled();
1389
- validateFindArgs(model: GetModels<Schema>, args: unknown, operation: CoreCrudOperations): FindArgs<Schema, GetModels<Schema>, true> | undefined;
1390
- validateExistsArgs(model: GetModels<Schema>, args: unknown): ExistsArgs<Schema, GetModels<Schema>> | undefined;
1391
- validateCreateArgs(model: GetModels<Schema>, args: unknown): CreateArgs<Schema, GetModels<Schema>>;
1392
- validateCreateManyArgs(model: GetModels<Schema>, args: unknown): CreateManyArgs<Schema, GetModels<Schema>>;
1393
- validateCreateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): CreateManyAndReturnArgs<Schema, GetModels<Schema>> | undefined;
1394
- validateUpdateArgs(model: GetModels<Schema>, args: unknown): UpdateArgs<Schema, GetModels<Schema>>;
1395
- validateUpdateManyArgs(model: GetModels<Schema>, args: unknown): UpdateManyArgs<Schema, GetModels<Schema>>;
1396
- validateUpdateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): UpdateManyAndReturnArgs<Schema, GetModels<Schema>>;
1397
- validateUpsertArgs(model: GetModels<Schema>, args: unknown): UpsertArgs<Schema, GetModels<Schema>>;
1398
- validateDeleteArgs(model: GetModels<Schema>, args: unknown): DeleteArgs<Schema, GetModels<Schema>>;
1399
- validateDeleteManyArgs(model: GetModels<Schema>, args: unknown): DeleteManyArgs<Schema, GetModels<Schema>> | undefined;
1400
- validateCountArgs(model: GetModels<Schema>, args: unknown): CountArgs<Schema, GetModels<Schema>> | undefined;
1401
- validateAggregateArgs(model: GetModels<Schema>, args: unknown): AggregateArgs<Schema, GetModels<Schema>>;
1402
- validateGroupByArgs(model: GetModels<Schema>, args: unknown): GroupByArgs<Schema, GetModels<Schema>>;
1403
- validateProcedureInput(proc: string, input: unknown): unknown;
1404
- private validate;
1405
- private mergePluginArgsSchema;
1406
- private getPluginExtQueryArgsSchema;
1407
- private makeFindSchema;
1408
- private makeExistsSchema;
1409
- private makeScalarSchema;
1410
- private makeEnumSchema;
1411
- private makeTypeDefSchema;
1412
- private makeWhereSchema;
1413
- private makeTypedJsonFilterSchema;
1414
- private isTypeDefType;
1415
- private makeEnumFilterSchema;
1416
- private makeArrayFilterSchema;
1417
- private internalMakeArrayFilterSchema;
1418
- private makePrimitiveFilterSchema;
1419
- private makeJsonValueSchema;
1420
- private makeJsonFilterSchema;
1421
- private makeDateTimeFilterSchema;
1422
- private makeBooleanFilterSchema;
1423
- private makeBytesFilterSchema;
1424
- private makeCommonPrimitiveFilterComponents;
1425
- private makeCommonPrimitiveFilterSchema;
1426
- private makeNumberFilterSchema;
1427
- private makeStringFilterSchema;
1428
- private makeStringModeSchema;
1429
- private makeSelectSchema;
1430
- private makeCountSelectionSchema;
1431
- private makeRelationSelectIncludeSchema;
1432
- private makeOmitSchema;
1433
- private makeIncludeSchema;
1434
- private makeOrderBySchema;
1435
- private makeDistinctSchema;
1436
- private makeCursorSchema;
1437
- private makeCreateSchema;
1438
- private makeCreateManySchema;
1439
- private makeCreateManyAndReturnSchema;
1440
- private makeCreateDataSchema;
1441
- private isDelegateDiscriminator;
1442
- private makeRelationManipulationSchema;
1443
- private makeSetDataSchema;
1444
- private makeConnectDataSchema;
1445
- private makeDisconnectDataSchema;
1446
- private makeDeleteRelationDataSchema;
1447
- private makeConnectOrCreateDataSchema;
1448
- private makeCreateManyDataSchema;
1449
- private makeUpdateSchema;
1450
- private makeUpdateManySchema;
1451
- private makeUpdateManyAndReturnSchema;
1452
- private makeUpsertSchema;
1453
- private makeUpdateDataSchema;
1454
- private makeDeleteSchema;
1455
- private makeDeleteManySchema;
1456
- makeCountSchema(model: string): z.ZodOptional<z.ZodObject<z.core.$ZodLooseShape, z.core.$strict>>;
1457
- private makeCountAggregateInputSchema;
1458
- makeAggregateSchema(model: string): z.ZodOptional<z.ZodObject<z.core.$ZodLooseShape, z.core.$strict>>;
1459
- makeSumAvgInputSchema(model: string): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
1460
- makeMinMaxInputSchema(model: string): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
1461
- private makeGroupBySchema;
1462
- private onlyAggregationFields;
1463
- private makeHavingSchema;
1464
- private makeProcedureParamSchema;
1465
- getCache(cacheKey: string): z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>> | undefined;
1466
- setCache(cacheKey: string, schema: ZodType): Map<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
1467
- private printCacheStats;
1468
- private makeSkipSchema;
1469
- private makeTakeSchema;
1470
- private refineForSelectIncludeMutuallyExclusive;
1471
- private refineForSelectOmitMutuallyExclusive;
1472
- private nullableIf;
1473
- private orArray;
1474
- private isNumericField;
1475
- private get providerSupportsCaseSensitivity();
1476
- }
1477
-
1478
- /**
1479
- * List of core CRUD operations. It excludes the 'orThrow' variants.
1480
- */
1481
- declare const CoreCrudOperations: readonly ["findMany", "findUnique", "findFirst", "create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany", "count", "aggregate", "groupBy", "exists"];
1482
- /**
1483
- * List of core CRUD operations. It excludes the 'orThrow' variants.
1484
- */
1485
- type CoreCrudOperations = (typeof CoreCrudOperations)[number];
1486
- /**
1487
- * List of core read operations. It excludes the 'orThrow' variants.
1488
- */
1489
- declare const CoreReadOperations: readonly ["findMany", "findUnique", "findFirst", "count", "aggregate", "groupBy", "exists"];
1490
- /**
1491
- * List of core read operations. It excludes the 'orThrow' variants.
1492
- */
1493
- type CoreReadOperations = (typeof CoreReadOperations)[number];
1494
- /**
1495
- * List of core write operations.
1496
- */
1497
- declare const CoreWriteOperations: readonly ["create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany"];
1498
- /**
1499
- * List of core write operations.
1500
- */
1501
- type CoreWriteOperations = (typeof CoreWriteOperations)[number];
1502
- /**
1503
- * List of core create operations.
1504
- */
1505
- declare const CoreCreateOperations: readonly ["create", "createMany", "createManyAndReturn", "upsert"];
1506
- /**
1507
- * List of core create operations.
1508
- */
1509
- type CoreCreateOperations = (typeof CoreCreateOperations)[number];
1510
- /**
1511
- * List of core update operations.
1512
- */
1513
- declare const CoreUpdateOperations: readonly ["update", "updateMany", "updateManyAndReturn", "upsert"];
1514
- /**
1515
- * List of core update operations.
1516
- */
1517
- type CoreUpdateOperations = (typeof CoreUpdateOperations)[number];
1518
- /**
1519
- * List of core delete operations.
1520
- */
1521
- declare const CoreDeleteOperations: readonly ["delete", "deleteMany"];
1522
- /**
1523
- * List of core delete operations.
1524
- */
1525
- type CoreDeleteOperations = (typeof CoreDeleteOperations)[number];
1526
- /**
1527
- * List of all CRUD operations, including 'orThrow' variants.
1528
- */
1529
- declare const AllCrudOperations: readonly ["findMany", "findUnique", "findFirst", "create", "createMany", "createManyAndReturn", "update", "updateMany", "updateManyAndReturn", "upsert", "delete", "deleteMany", "count", "aggregate", "groupBy", "exists", "findUniqueOrThrow", "findFirstOrThrow"];
1530
- /**
1531
- * List of all CRUD operations, including 'orThrow' variants.
1532
- */
1533
- type AllCrudOperations = (typeof AllCrudOperations)[number];
1534
- /**
1535
- * List of all read operations, including 'orThrow' variants.
1536
- */
1537
- declare const AllReadOperations: readonly ["findMany", "findUnique", "findFirst", "count", "aggregate", "groupBy", "exists", "findUniqueOrThrow", "findFirstOrThrow"];
1538
- /**
1539
- * List of all read operations, including 'orThrow' variants.
1540
- */
1541
- type AllReadOperations = (typeof AllReadOperations)[number];
1542
-
1543
- type AllowedExtQueryArgKeys = CoreCrudOperations | '$create' | '$read' | '$update' | '$delete' | '$all';
1544
- /**
1545
- * Base shape of plugin-extended query args.
1546
- */
1547
- type ExtQueryArgsBase = {
1548
- [K in AllowedExtQueryArgKeys]?: object;
1420
+ _avg?: SumAvgInput<Schema, Model, SortOrder>;
1421
+ /**
1422
+ * Sorts by the sum value.
1423
+ */
1424
+ _sum?: SumAvgInput<Schema, Model, SortOrder>;
1425
+ }) : {});
1426
+ type WhereUniqueInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = AtLeast<{
1427
+ [Key in keyof GetModel<Schema, Model>['uniqueFields']]?: GetModel<Schema, Model>['uniqueFields'][Key] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key]> : {
1428
+ [Key1 in keyof GetModel<Schema, Model>['uniqueFields'][Key]]: GetModel<Schema, Model>['uniqueFields'][Key][Key1] extends Pick<FieldDef, 'type'> ? MapFieldDefType<Schema, GetModel<Schema, Model>['uniqueFields'][Key][Key1]> : never;
1429
+ };
1430
+ } & WhereInput<Schema, Model, Options>, Extract<keyof GetModel<Schema, Model>['uniqueFields'], string>>;
1431
+ type OmitInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1432
+ [Key in NonRelationFields<Schema, Model>]?: boolean;
1549
1433
  };
1550
- /**
1551
- * Base type for plugin-extended client members (methods and properties).
1552
- * Member names should start with '$' to avoid model name conflicts.
1553
- */
1554
- type ExtClientMembersBase = Record<string, unknown>;
1555
- /**
1556
- * ZenStack runtime plugin.
1557
- */
1558
- interface RuntimePlugin<Schema extends SchemaDef, ExtQueryArgs extends ExtQueryArgsBase, ExtClientMembers extends Record<string, unknown>> {
1434
+ type SelectIncludeOmit<Schema extends SchemaDef, Model extends GetModels<Schema>, AllowCount extends boolean, Options extends QueryOptions<Schema> = QueryOptions<Schema>, AllowRelation extends boolean = true> = {
1435
+ /**
1436
+ * Explicitly select fields and relations to be returned by the query.
1437
+ */
1438
+ select?: SelectInput<Schema, Model, Options, AllowCount, AllowRelation> | null;
1439
+ /**
1440
+ * Explicitly omit fields from the query result.
1441
+ */
1442
+ omit?: OmitInput<Schema, Model> | null;
1443
+ } & (AllowRelation extends true ? {
1444
+ /**
1445
+ * Specifies relations to be included in the query result. All scalar fields are included.
1446
+ */
1447
+ include?: IncludeInput<Schema, Model, Options, AllowCount> | null;
1448
+ } : {});
1449
+ type SelectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>, AllowCount extends boolean = true, AllowRelation extends boolean = true> = {
1450
+ [Key in NonRelationFields<Schema, Model>]?: boolean;
1451
+ } & (AllowRelation extends true ? IncludeInput<Schema, Model, Options, AllowCount> : {});
1452
+ type SelectCount<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = boolean | {
1453
+ /**
1454
+ * Selects specific relations to count.
1455
+ */
1456
+ select: {
1457
+ [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]?: boolean | {
1458
+ where: WhereInput<Schema, RelationFieldType<Schema, Model, Key>, Options, false>;
1459
+ };
1460
+ };
1461
+ };
1462
+ type IncludeInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>, AllowCount extends boolean = true> = {
1463
+ [Key in RelationFields<Schema, Model> as RelationFieldType<Schema, Model, Key> extends GetSlicedModels<Schema, Options> ? Key : never]?: boolean | FindArgs<Schema, RelationFieldType<Schema, Model, Key>, Options, FieldIsArray<Schema, Model, Key>, FieldIsArray<Schema, Model, Key> extends true ? true : ModelFieldIsOptional<Schema, Model, Key> extends true ? true : false>;
1464
+ } & (AllowCount extends true ? HasToManyRelations<Schema, Model> extends true ? {
1465
+ _count?: SelectCount<Schema, Model, Options>;
1466
+ } : {} : {});
1467
+ type Subset<T, U> = {
1468
+ [key in keyof T]: key extends keyof U ? T[key] : never;
1469
+ };
1470
+ type SelectSubset<T, U> = {
1471
+ [key in keyof T]: key extends keyof U ? T[key] : never;
1472
+ } & (T extends {
1473
+ select: any;
1474
+ include: any;
1475
+ } ? 'Please either choose `select` or `include`.' : T extends {
1476
+ select: any;
1477
+ omit: any;
1478
+ } ? 'Please either choose `select` or `omit`.' : {});
1479
+ type ToManyRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = {
1480
+ every?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1481
+ some?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1482
+ none?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1483
+ };
1484
+ type ToOneRelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options> & {
1485
+ /**
1486
+ * Checks if the related record matches the specified filter.
1487
+ */
1488
+ is?: NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>, ModelFieldIsOptional<Schema, Model, Field>>;
1489
+ /**
1490
+ * Checks if the related record does not match the specified filter.
1491
+ */
1492
+ isNot?: NullableIf<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>, ModelFieldIsOptional<Schema, Model, Field>>;
1493
+ }, ModelFieldIsOptional<Schema, Model, Field>>;
1494
+ type RelationFilter<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>, AllowedKinds extends FilterKind> = 'Relation' extends AllowedKinds ? FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationFilter<Schema, Model, Field, Options> : ToOneRelationFilter<Schema, Model, Field, Options> : never;
1495
+ type MapModelFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = MapFieldDefType<Schema, GetModelField<Schema, Model, Field>>;
1496
+ type MapFieldDefType<Schema extends SchemaDef, T extends Pick<FieldDef, 'type' | 'optional' | 'array'>, Partial extends boolean = false> = WrapType<T['type'] extends GetEnums<Schema> ? keyof GetEnum<Schema, T['type']> : T['type'] extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T['type'], Partial> & Record<string, unknown> : MapBaseType$1<T['type']>, T['optional'], T['array']>;
1497
+ type OptionalFieldsForCreate<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1498
+ [Key in GetModelFields<Schema, Model> as ModelFieldIsOptional<Schema, Model, Key> extends true ? Key : FieldHasDefault<Schema, Model, Key> extends true ? Key : FieldIsArray<Schema, Model, Key> extends true ? Key : GetModelField<Schema, Model, Key>['updatedAt'] extends true | UpdatedAtInfo ? Key : never]: GetModelField<Schema, Model, Key>;
1499
+ };
1500
+ type GetRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelField<Schema, Model, Field>['relation'];
1501
+ type OppositeRelation<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>> = FT extends GetModels<Schema> ? GetRelation<Schema, Model, Field> extends RelationInfo ? GetRelation<Schema, Model, Field>['opposite'] extends GetModelFields<Schema, FT> ? Schema['models'][FT]['fields'][GetRelation<Schema, Model, Field>['opposite']]['relation'] : never : never : never;
1502
+ type OppositeRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, Opposite = OppositeRelation<Schema, Model, Field>> = Opposite extends RelationInfo ? (Opposite['fields'] extends readonly string[] ? Opposite['fields'] : []) : [];
1503
+ type OppositeRelationAndFK<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>, FT = FieldType<Schema, Model, Field>, Relation = GetModelField<Schema, Model, Field>['relation'], Opposite = Relation extends RelationInfo ? Relation['opposite'] : never> = FT extends GetModels<Schema> ? Opposite extends GetModelFields<Schema, FT> ? Opposite | OppositeRelationFields<Schema, Model, Field>[number] : never : never;
1504
+ type FilterArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = {
1505
+ /**
1506
+ * Filter conditions
1507
+ */
1508
+ where?: WhereInput<Schema, Model, Options>;
1509
+ };
1510
+ type SortAndTakeArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = {
1511
+ /**
1512
+ * Number of records to skip
1513
+ */
1514
+ skip?: number;
1515
+ /**
1516
+ * Number of records to take
1517
+ */
1518
+ take?: number;
1519
+ /**
1520
+ * Order by clauses
1521
+ */
1522
+ orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
1523
+ /**
1524
+ * Cursor for pagination
1525
+ */
1526
+ cursor?: WhereUniqueInput<Schema, Model, Options>;
1527
+ };
1528
+ type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Collection extends boolean, AllowFilter extends boolean = true> = (Collection extends true ? SortAndTakeArgs<Schema, Model, Options> & (ProviderSupportsDistinct<Schema> extends true ? {
1529
+ /**
1530
+ * Distinct fields. Only supported by providers that natively support SQL "DISTINCT ON".
1531
+ */
1532
+ distinct?: OrArray<NonRelationFields<Schema, Model>>;
1533
+ } : {}) : {}) & (AllowFilter extends true ? FilterArgs<Schema, Model, Options> : {}) & SelectIncludeOmit<Schema, Model, Collection, Options>;
1534
+ type FindManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = FindArgs<Schema, Model, Options, true>;
1535
+ type FindFirstArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = FindArgs<Schema, Model, Options, true>;
1536
+ type ExistsArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = FilterArgs<Schema, Model, Options>;
1537
+ type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1538
+ where: WhereUniqueInput<Schema, Model, Options>;
1539
+ } & SelectIncludeOmit<Schema, Model, true, Options>;
1540
+ type CreateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1541
+ data: CreateInput<Schema, Model, Options>;
1542
+ } & SelectIncludeOmit<Schema, Model, true, Options>;
1543
+ type CreateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = CreateManyInput<Schema, Model>;
1544
+ type CreateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = CreateManyInput<Schema, Model> & SelectIncludeOmit<Schema, Model, false, Options, false>;
1545
+ type OptionalWrap<Schema extends SchemaDef, Model extends GetModels<Schema>, T extends object> = Optional<T, keyof T & OptionalFieldsForCreate<Schema, Model>>;
1546
+ type CreateScalarPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
1547
+ [Key in ScalarFields<Schema, Model, false> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? never : Key]: ScalarCreatePayload<Schema, Model, Key>;
1548
+ }>;
1549
+ type ScalarCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends ScalarFields<Schema, Model, false>> = ScalarFieldMutationPayload<Schema, Model, Field> | (FieldIsArray<Schema, Model, Field> extends true ? {
1550
+ set?: MapModelFieldType<Schema, Model, Field>;
1551
+ } : never);
1552
+ type ScalarFieldMutationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = IsJsonField<Schema, Model, Field> extends true ? ModelFieldIsOptional<Schema, Model, Field> extends true ? JsonValue | JsonNull | DbNull : JsonValue | JsonNull : MapModelFieldType<Schema, Model, Field>;
1553
+ type IsJsonField<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = GetModelFieldType<Schema, Model, Field> extends 'Json' ? true : false;
1554
+ type CreateFKPayload<Schema extends SchemaDef, Model extends GetModels<Schema>> = OptionalWrap<Schema, Model, {
1555
+ [Key in ForeignKeyFields<Schema, Model>]: MapModelFieldType<Schema, Model, Key>;
1556
+ }>;
1557
+ type CreateRelationFieldPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = Omit<{
1558
+ /**
1559
+ * Connects or create a related record.
1560
+ */
1561
+ connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field, Options>;
1562
+ /**
1563
+ * Creates a related record.
1564
+ */
1565
+ create?: NestedCreateInput<Schema, Model, Field, Options>;
1566
+ /**
1567
+ * Creates a batch of related records.
1568
+ */
1569
+ createMany?: NestedCreateManyInput<Schema, Model, Field>;
1570
+ /**
1571
+ * Connects an existing record.
1572
+ */
1573
+ connect?: ConnectInput<Schema, Model, Field, Options>;
1574
+ }, (FieldIsArray<Schema, Model, Field> extends true ? never : 'createMany') | (FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'createMany' | 'connectOrCreate' : never)>;
1575
+ type CreateRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = OptionalWrap<Schema, Model, {
1576
+ [Key in RelationFields<Schema, Model> as RelationFieldType<Schema, Model, Key> extends GetSlicedModels<Schema, Options> ? Key : never]: CreateRelationFieldPayload<Schema, Model, Key, Options>;
1577
+ }>;
1578
+ type CreateWithFKInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = CreateScalarPayload<Schema, Model> & CreateFKPayload<Schema, Model> & CreateWithNonOwnedRelationPayload<Schema, Model, Options>;
1579
+ type CreateWithRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = CreateScalarPayload<Schema, Model> & CreateRelationPayload<Schema, Model, Options>;
1580
+ type CreateWithNonOwnedRelationPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>> = OptionalWrap<Schema, Model, {
1581
+ [Key in NonOwnedRelationFields<Schema, Model> as RelationFieldType<Schema, Model, Key> extends GetSlicedModels<Schema, Options> ? Key : never]: CreateRelationFieldPayload<Schema, Model, Key, Options>;
1582
+ }>;
1583
+ type ConnectOrCreatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Without extends string = never> = {
1584
+ /**
1585
+ * The unique filter to find an existing record to connect.
1586
+ */
1587
+ where: WhereUniqueInput<Schema, Model, Options>;
1588
+ /**
1589
+ * The data to create a new record if no existing record is found.
1590
+ */
1591
+ create: CreateInput<Schema, Model, Options, Without>;
1592
+ };
1593
+ type CreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = {
1594
+ /**
1595
+ * The data for the records to create.
1596
+ */
1597
+ data: OrArray<Omit<CreateScalarPayload<Schema, Model>, Without> & Omit<CreateFKPayload<Schema, Model>, Without>>;
1598
+ /**
1599
+ * Specifies whether to skip creating records that would violate unique constraints.
1600
+ */
1601
+ skipDuplicates?: boolean;
1602
+ };
1603
+ type CreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Without extends string = never> = XOR<Omit<CreateWithFKInput<Schema, Model, Options>, Without>, Omit<CreateWithRelationInput<Schema, Model, Options>, Without>>;
1604
+ type NestedCreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = OrArray<CreateInput<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>, FieldIsArray<Schema, Model, Field>>;
1605
+ type NestedCreateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = CreateManyInput<Schema, RelationFieldType<Schema, Model, Field>, OppositeRelationAndFK<Schema, Model, Field>>;
1606
+ type UpdateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1607
+ /**
1608
+ * The data to update the record with.
1609
+ */
1610
+ data: UpdateInput<Schema, Model, Options>;
1611
+ /**
1612
+ * The unique filter to find the record to update.
1613
+ */
1614
+ where: WhereUniqueInput<Schema, Model, Options>;
1615
+ } & SelectIncludeOmit<Schema, Model, true, Options>;
1616
+ type UpdateManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = UpdateManyPayload<Schema, Model, Options>;
1617
+ type UpdateManyAndReturnArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = UpdateManyPayload<Schema, Model, Options> & SelectIncludeOmit<Schema, Model, false, Options, false>;
1618
+ type UpdateManyPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>, Without extends string = never> = {
1619
+ /**
1620
+ * The data to update the records with.
1621
+ */
1622
+ data: OrArray<UpdateScalarInput<Schema, Model, Without>>;
1623
+ /**
1624
+ * The filter to select records to update.
1625
+ */
1626
+ where?: WhereInput<Schema, Model, Options>;
1627
+ /**
1628
+ * Limit the number of records to update.
1629
+ */
1630
+ limit?: number;
1631
+ };
1632
+ type UpsertArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1633
+ /**
1634
+ * The data to create the record if it doesn't exist.
1635
+ */
1636
+ create: CreateInput<Schema, Model, Options>;
1637
+ /**
1638
+ * The data to update the record with if it exists.
1639
+ */
1640
+ update: UpdateInput<Schema, Model, Options>;
1641
+ /**
1642
+ * The unique filter to find the record to update.
1643
+ */
1644
+ where: WhereUniqueInput<Schema, Model, Options>;
1645
+ } & SelectIncludeOmit<Schema, Model, true, Options>;
1646
+ type UpdateScalarInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Without extends string = never> = Omit<{
1647
+ [Key in NonRelationFields<Schema, Model> as FieldIsDelegateDiscriminator<Schema, Model, Key> extends true ? never : Key]?: ScalarUpdatePayload<Schema, Model, Key>;
1648
+ }, Without>;
1649
+ type ScalarUpdatePayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends NonRelationFields<Schema, Model>> = ScalarFieldMutationPayload<Schema, Model, Field> | (Field extends NumericFields<Schema, Model> ? {
1650
+ /**
1651
+ * Sets the field to the specified value.
1652
+ */
1653
+ set?: NullableIf<number, ModelFieldIsOptional<Schema, Model, Field>>;
1654
+ /**
1655
+ * Increments the field by the specified value.
1656
+ */
1657
+ increment?: number;
1658
+ /**
1659
+ * Decrements the field by the specified value.
1660
+ */
1661
+ decrement?: number;
1559
1662
  /**
1560
- * Plugin ID.
1663
+ * Multiplies the field by the specified value.
1561
1664
  */
1562
- id: string;
1665
+ multiply?: number;
1563
1666
  /**
1564
- * Plugin display name.
1667
+ * Divides the field by the specified value.
1565
1668
  */
1566
- name?: string;
1669
+ divide?: number;
1670
+ } : never) | (FieldIsArray<Schema, Model, Field> extends true ? {
1567
1671
  /**
1568
- * Plugin description.
1672
+ * Sets the field to the specified array.
1569
1673
  */
1570
- description?: string;
1674
+ set?: MapModelFieldType<Schema, Model, Field>[];
1571
1675
  /**
1572
- * Custom function implementations.
1573
- * @private
1676
+ * Appends the specified values to the array field.
1574
1677
  */
1575
- functions?: Record<string, ZModelFunction<Schema>>;
1678
+ push?: OrArray<MapModelFieldType<Schema, Model, Field>, true>;
1679
+ } : never);
1680
+ type UpdateRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Without extends string = never> = Omit<{
1681
+ [Key in RelationFields<Schema, Model> as RelationFieldType<Schema, Model, Key> extends GetSlicedModels<Schema, Options> ? Key : never]?: UpdateRelationFieldPayload<Schema, Model, Key, Options>;
1682
+ }, Without>;
1683
+ type UpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, Without extends string = never> = UpdateScalarInput<Schema, Model, Without> & UpdateRelationInput<Schema, Model, Options, Without>;
1684
+ type UpdateRelationFieldPayload<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = FieldIsArray<Schema, Model, Field> extends true ? ToManyRelationUpdateInput<Schema, Model, Field, Options> : ToOneRelationUpdateInput<Schema, Model, Field, Options>;
1685
+ type ToManyRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = Omit<{
1576
1686
  /**
1577
- * Intercepts an ORM query.
1687
+ * Creates related records.
1578
1688
  */
1579
- onQuery?: OnQueryCallback<Schema>;
1689
+ create?: NestedCreateInput<Schema, Model, Field, Options>;
1580
1690
  /**
1581
- * Intercepts a procedure invocation.
1691
+ * Creates a batch of related records.
1582
1692
  */
1583
- onProcedure?: OnProcedureCallback<Schema>;
1693
+ createMany?: NestedCreateManyInput<Schema, Model, Field>;
1584
1694
  /**
1585
- * Intercepts an entity mutation.
1695
+ * Connects existing records.
1586
1696
  */
1587
- onEntityMutation?: EntityMutationHooksDef<Schema>;
1697
+ connect?: ConnectInput<Schema, Model, Field, Options>;
1588
1698
  /**
1589
- * Intercepts a Kysely query.
1699
+ * Connects or create related records.
1590
1700
  */
1591
- onKyselyQuery?: OnKyselyQueryCallback<Schema>;
1701
+ connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field, Options>;
1592
1702
  /**
1593
- * Extended query args configuration.
1703
+ * Disconnects related records.
1594
1704
  */
1595
- queryArgs?: {
1596
- [K in keyof ExtQueryArgs]: ZodType<ExtQueryArgs[K]>;
1597
- };
1705
+ disconnect?: DisconnectInput<Schema, Model, Field, Options>;
1598
1706
  /**
1599
- * Extended client members (methods and properties).
1707
+ * Updates related records.
1600
1708
  */
1601
- client?: ExtClientMembers;
1602
- }
1603
- type AnyPlugin = RuntimePlugin<any, any, any>;
1604
- /**
1605
- * Defines a ZenStack runtime plugin.
1606
- */
1607
- declare function definePlugin<Schema extends SchemaDef, const ExtQueryArgs extends ExtQueryArgsBase = {}, const ExtClientMembers extends Record<string, unknown> = {}>(plugin: RuntimePlugin<Schema, ExtQueryArgs, ExtClientMembers>): RuntimePlugin<any, ExtQueryArgs, ExtClientMembers>;
1608
- type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;
1609
- type OnProcedureHookContext<Schema extends SchemaDef> = {
1709
+ update?: NestedUpdateInput<Schema, Model, Field, Options>;
1610
1710
  /**
1611
- * The procedure name.
1711
+ * Upserts related records.
1612
1712
  */
1613
- name: string;
1713
+ upsert?: NestedUpsertInput<Schema, Model, Field, Options>;
1614
1714
  /**
1615
- * Whether the procedure is a mutation.
1715
+ * Updates a batch of related records.
1616
1716
  */
1617
- mutation: boolean;
1717
+ updateMany?: NestedUpdateManyInput<Schema, Model, Field, Options>;
1618
1718
  /**
1619
- * Procedure invocation input (envelope).
1620
- *
1621
- * The canonical shape is `{ args?: Record<string, unknown> }`.
1622
- * When a procedure has required params, `args` is required.
1719
+ * Deletes related records.
1623
1720
  */
1624
- input: unknown;
1721
+ delete?: NestedDeleteInput<Schema, Model, Field, Options>;
1625
1722
  /**
1626
- * Continues the invocation. The input passed here is forwarded to the next handler.
1723
+ * Deletes a batch of related records.
1627
1724
  */
1628
- proceed: (input: unknown) => Promise<unknown>;
1725
+ deleteMany?: NestedDeleteManyInput<Schema, Model, Field, Options>;
1629
1726
  /**
1630
- * The ZenStack client that is invoking the procedure.
1727
+ * Sets the related records to the specified ones.
1631
1728
  */
1632
- client: ClientContract<Schema>;
1729
+ set?: SetRelationInput<Schema, Model, Field, Options>;
1730
+ }, FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'createMany' | 'connectOrCreate' | 'upsert' : never>;
1731
+ type ToOneRelationUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = Omit<{
1732
+ /**
1733
+ * Creates a related record.
1734
+ */
1735
+ create?: NestedCreateInput<Schema, Model, Field, Options>;
1736
+ /**
1737
+ * Connects an existing record.
1738
+ */
1739
+ connect?: ConnectInput<Schema, Model, Field, Options>;
1740
+ /**
1741
+ * Connects or create a related record.
1742
+ */
1743
+ connectOrCreate?: ConnectOrCreateInput<Schema, Model, Field, Options>;
1744
+ /**
1745
+ * Updates the related record.
1746
+ */
1747
+ update?: NestedUpdateInput<Schema, Model, Field, Options>;
1748
+ /**
1749
+ * Upserts the related record.
1750
+ */
1751
+ upsert?: NestedUpsertInput<Schema, Model, Field, Options>;
1752
+ } & (ModelFieldIsOptional<Schema, Model, Field> extends true ? {
1753
+ /**
1754
+ * Disconnects the related record.
1755
+ */
1756
+ disconnect?: DisconnectInput<Schema, Model, Field, Options>;
1757
+ /**
1758
+ * Deletes the related record.
1759
+ */
1760
+ delete?: NestedDeleteInput<Schema, Model, Field, Options>;
1761
+ } : {}), FieldIsDelegateRelation<Schema, Model, Field> extends true ? 'create' | 'connectOrCreate' | 'upsert' : never>;
1762
+ type DeleteArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1763
+ /**
1764
+ * The unique filter to find the record to delete.
1765
+ */
1766
+ where: WhereUniqueInput<Schema, Model, Options>;
1767
+ } & SelectIncludeOmit<Schema, Model, true, Options>;
1768
+ type DeleteManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1769
+ /**
1770
+ * Filter to select records to delete.
1771
+ */
1772
+ where?: WhereInput<Schema, Model, Options>;
1773
+ /**
1774
+ * Limits the number of records to delete.
1775
+ */
1776
+ limit?: number;
1633
1777
  };
1634
- type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
1635
- type OnQueryHookContext<Schema extends SchemaDef> = {
1778
+ type CountArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Omit<FindArgs<Schema, Model, Options, true>, 'select' | 'include' | 'distinct' | 'omit'> & {
1636
1779
  /**
1637
- * The model that is being queried.
1780
+ * Selects fields to count
1638
1781
  */
1639
- model: GetModels<Schema>;
1782
+ select?: CountAggregateInput<Schema, Model> | true;
1783
+ };
1784
+ type CountAggregateInput<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
1785
+ [Key in NonRelationFields<Schema, Model>]?: true;
1786
+ } & {
1787
+ _all?: true;
1788
+ };
1789
+ type CountResult<Schema extends SchemaDef, _Model extends GetModels<Schema>, Args> = Args extends {
1790
+ select: infer S;
1791
+ } ? S extends true ? number : {
1792
+ [Key in keyof S]: number;
1793
+ } : number;
1794
+ type AggregateArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1640
1795
  /**
1641
- * The operation that is being performed.
1796
+ * Filter conditions
1642
1797
  */
1643
- operation: AllCrudOperations;
1798
+ where?: WhereInput<Schema, Model, Options>;
1644
1799
  /**
1645
- * The query arguments.
1800
+ * Number of records to skip for the aggregation
1646
1801
  */
1647
- args: Record<string, unknown> | undefined;
1802
+ skip?: number;
1648
1803
  /**
1649
- * The function to proceed with the original query.
1650
- * It takes the same arguments as the operation method.
1651
- *
1652
- * @param args The query arguments.
1804
+ * Number of records to take for the aggregation
1653
1805
  */
1654
- proceed: (args: Record<string, unknown> | undefined) => Promise<unknown>;
1806
+ take?: number;
1655
1807
  /**
1656
- * The ZenStack client that is performing the operation.
1808
+ * Order by clauses
1657
1809
  */
1658
- client: ClientContract<Schema>;
1810
+ orderBy?: OrArray<OrderBy<Schema, Model, true, false>>;
1811
+ } & {
1812
+ /**
1813
+ * Performs count aggregation.
1814
+ */
1815
+ _count?: true | CountAggregateInput<Schema, Model>;
1816
+ /**
1817
+ * Performs minimum value aggregation.
1818
+ */
1819
+ _min?: MinMaxInput<Schema, Model, true>;
1820
+ /**
1821
+ * Performs maximum value aggregation.
1822
+ */
1823
+ _max?: MinMaxInput<Schema, Model, true>;
1824
+ } & (NumericFields<Schema, Model> extends never ? {} : {
1825
+ /**
1826
+ * Performs average value aggregation.
1827
+ */
1828
+ _avg?: SumAvgInput<Schema, Model, true>;
1829
+ /**
1830
+ * Performs sum value aggregation.
1831
+ */
1832
+ _sum?: SumAvgInput<Schema, Model, true>;
1833
+ });
1834
+ type NumericFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
1835
+ [Key in GetModelFields<Schema, Model> as GetModelFieldType<Schema, Model, Key> extends 'Int' | 'Float' | 'BigInt' | 'Decimal' ? FieldIsArray<Schema, Model, Key> extends true ? never : Key : never]: GetModelField<Schema, Model, Key>;
1659
1836
  };
1660
- type EntityMutationHooksDef<Schema extends SchemaDef> = {
1837
+ type SumAvgInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ValueType> = {
1838
+ [Key in NumericFields<Schema, Model>]?: ValueType;
1839
+ };
1840
+ type MinMaxInput<Schema extends SchemaDef, Model extends GetModels<Schema>, ValueType> = {
1841
+ [Key in GetModelFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? never : FieldIsRelation<Schema, Model, Key> extends true ? never : Key]?: ValueType;
1842
+ };
1843
+ type AggregateResult<Schema extends SchemaDef, _Model extends GetModels<Schema>, Args> = (Args extends {
1844
+ _count: infer Count;
1845
+ } ? {
1846
+ /**
1847
+ * Count aggregation result
1848
+ */
1849
+ _count: AggCommonOutput<Count>;
1850
+ } : {}) & (Args extends {
1851
+ _sum: infer Sum;
1852
+ } ? {
1853
+ /**
1854
+ * Sum aggregation result
1855
+ */
1856
+ _sum: AggCommonOutput<Sum>;
1857
+ } : {}) & (Args extends {
1858
+ _avg: infer Avg;
1859
+ } ? {
1860
+ /**
1861
+ * Average aggregation result
1862
+ */
1863
+ _avg: AggCommonOutput<Avg>;
1864
+ } : {}) & (Args extends {
1865
+ _min: infer Min;
1866
+ } ? {
1867
+ /**
1868
+ * Minimum aggregation result
1869
+ */
1870
+ _min: AggCommonOutput<Min>;
1871
+ } : {}) & (Args extends {
1872
+ _max: infer Max;
1873
+ } ? {
1874
+ /**
1875
+ * Maximum aggregation result
1876
+ */
1877
+ _max: AggCommonOutput<Max>;
1878
+ } : {});
1879
+ type AggCommonOutput<Input> = Input extends true ? number : Input extends {} ? {
1880
+ [Key in keyof Input]: number;
1881
+ } : never;
1882
+ type GroupByHaving<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Omit<WhereInput<Schema, Model, Options, true, true>, '$expr'>;
1883
+ type GroupByArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = {
1884
+ /**
1885
+ * Filter conditions
1886
+ */
1887
+ where?: WhereInput<Schema, Model, Options>;
1888
+ /**
1889
+ * Order by clauses
1890
+ */
1891
+ orderBy?: OrArray<OrderBy<Schema, Model, false, true>>;
1892
+ /**
1893
+ * Fields to group by
1894
+ */
1895
+ by: NonRelationFields<Schema, Model> | NonEmptyArray<NonRelationFields<Schema, Model>>;
1896
+ /**
1897
+ * Filter conditions for the grouped records
1898
+ */
1899
+ having?: GroupByHaving<Schema, Model, Options>;
1900
+ /**
1901
+ * Number of records to take for grouping
1902
+ */
1903
+ take?: number;
1904
+ /**
1905
+ * Number of records to skip for grouping
1906
+ */
1907
+ skip?: number;
1908
+ /**
1909
+ * Performs count aggregation.
1910
+ */
1911
+ _count?: true | CountAggregateInput<Schema, Model>;
1912
+ /**
1913
+ * Performs minimum value aggregation.
1914
+ */
1915
+ _min?: MinMaxInput<Schema, Model, true>;
1916
+ /**
1917
+ * Performs maximum value aggregation.
1918
+ */
1919
+ _max?: MinMaxInput<Schema, Model, true>;
1920
+ } & (NumericFields<Schema, Model> extends never ? {} : {
1921
+ /**
1922
+ * Performs average value aggregation.
1923
+ */
1924
+ _avg?: SumAvgInput<Schema, Model, true>;
1925
+ /**
1926
+ * Performs sum value aggregation.
1927
+ */
1928
+ _sum?: SumAvgInput<Schema, Model, true>;
1929
+ });
1930
+ type GroupByResult<Schema extends SchemaDef, Model extends GetModels<Schema>, Args extends {
1931
+ by: unknown;
1932
+ }> = Array<{
1933
+ [Key in NonRelationFields<Schema, Model> as Key extends ValueOfPotentialTuple<Args['by']> ? Key : never]: MapModelFieldType<Schema, Model, Key>;
1934
+ } & (Args extends {
1935
+ _count: infer Count;
1936
+ } ? {
1661
1937
  /**
1662
- * Called before entities are mutated.
1938
+ * Count aggregation result
1663
1939
  */
1664
- beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
1940
+ _count: AggCommonOutput<Count>;
1941
+ } : {}) & (Args extends {
1942
+ _avg: infer Avg;
1943
+ } ? {
1665
1944
  /**
1666
- * Called after entities are mutated.
1945
+ * Average aggregation result
1667
1946
  */
1668
- afterEntityMutation?: AfterEntityMutationCallback<Schema>;
1947
+ _avg: AggCommonOutput<Avg>;
1948
+ } : {}) & (Args extends {
1949
+ _sum: infer Sum;
1950
+ } ? {
1669
1951
  /**
1670
- * Whether to run after-mutation hooks within the transaction that performs the mutation.
1671
- *
1672
- * If set to `true`, if the mutation already runs inside a transaction, the callbacks are
1673
- * executed immediately after the mutation within the transaction boundary. If the mutation
1674
- * is not running inside a transaction, a new transaction is created to run both the mutation
1675
- * and the callbacks.
1676
- *
1677
- * If set to `false`, the callbacks are executed after the mutation transaction is committed.
1678
- *
1679
- * Defaults to `false`.
1952
+ * Sum aggregation result
1680
1953
  */
1681
- runAfterMutationWithinTransaction?: boolean;
1682
- };
1683
- type MutationHooksArgs<Schema extends SchemaDef> = {
1954
+ _sum: AggCommonOutput<Sum>;
1955
+ } : {}) & (Args extends {
1956
+ _min: infer Min;
1957
+ } ? {
1684
1958
  /**
1685
- * The model that is being mutated.
1959
+ * Minimum aggregation result
1686
1960
  */
1687
- model: GetModels<Schema>;
1961
+ _min: AggCommonOutput<Min>;
1962
+ } : {}) & (Args extends {
1963
+ _max: infer Max;
1964
+ } ? {
1688
1965
  /**
1689
- * The mutation action that is being performed.
1966
+ * Maximum aggregation result
1690
1967
  */
1691
- action: 'create' | 'update' | 'delete';
1968
+ _max: AggCommonOutput<Max>;
1969
+ } : {})>;
1970
+ type ConnectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>, Options>> : WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1971
+ type ConnectOrCreateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<ConnectOrCreatePayload<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>> : ConnectOrCreatePayload<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>;
1972
+ type DisconnectInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>, Options>, true> : boolean | WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1973
+ type SetRelationInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>, Options>>;
1974
+ type NestedUpdateInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<{
1692
1975
  /**
1693
- * The mutation data. Only available for create and update actions.
1976
+ * Unique filter to select the record to update.
1694
1977
  */
1695
- queryNode: OperationNode;
1978
+ where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1696
1979
  /**
1697
- * A query ID that uniquely identifies the mutation operation. You can use it to correlate
1698
- * data between the before and after mutation hooks.
1980
+ * The data to update the record with.
1699
1981
  */
1700
- queryId: QueryId;
1701
- };
1702
- type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
1703
- type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
1704
- type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
1982
+ data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>;
1983
+ }, true> : XOR<{
1705
1984
  /**
1706
- * Loads the entities that are about to be mutated. The db operation that loads the entities is executed
1707
- * within the same transaction context as the mutation.
1985
+ * Filter to select the record to update.
1708
1986
  */
1709
- loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
1987
+ where?: WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1710
1988
  /**
1711
- * The ZenStack client you can use to perform additional operations. The database operations initiated
1712
- * from this client are executed within the same transaction as the mutation if the mutation is running
1713
- * inside a transaction.
1714
- *
1715
- * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
1989
+ * The data to update the record with.
1716
1990
  */
1717
- client: ClientContract<Schema>;
1718
- };
1719
- type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
1991
+ data: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>;
1992
+ }, UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>>;
1993
+ type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = OrArray<{
1720
1994
  /**
1721
- * Loads the entities that have been mutated.
1995
+ * Unique filter to select the record to update.
1722
1996
  */
1723
- loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
1997
+ where: WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
1724
1998
  /**
1725
- * The entities before mutation. Only available if `beforeEntityMutation` hook is provided and
1726
- * the `loadBeforeMutationEntities` function is called in that hook.
1999
+ * The data to create the record if it doesn't exist.
1727
2000
  */
1728
- beforeMutationEntities?: Record<string, unknown>[];
2001
+ create: CreateInput<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>;
1729
2002
  /**
1730
- * The ZenStack client you can use to perform additional operations.
1731
- * See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
1732
- *
1733
- * Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
2003
+ * The data to update the record with if it exists.
1734
2004
  */
1735
- client: ClientContract<Schema>;
2005
+ update: UpdateInput<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>;
2006
+ }, FieldIsArray<Schema, Model, Field>>;
2007
+ type NestedUpdateManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = OrArray<UpdateManyPayload<Schema, RelationFieldType<Schema, Model, Field>, Options, OppositeRelationAndFK<Schema, Model, Field>>>;
2008
+ type NestedDeleteInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = FieldIsArray<Schema, Model, Field> extends true ? OrArray<WhereUniqueInput<Schema, RelationFieldType<Schema, Model, Field>, Options>, true> : boolean | WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options>;
2009
+ type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>, Options extends QueryOptions<Schema>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, Options, true>>;
2010
+ type GetProcedureNames<Schema extends SchemaDef> = Schema extends {
2011
+ procedures: Record<string, ProcedureDef>;
2012
+ } ? keyof Schema['procedures'] : never;
2013
+ type GetProcedureParams<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
2014
+ procedures: Record<string, ProcedureDef>;
2015
+ } ? Schema['procedures'][ProcName]['params'] : never;
2016
+ type GetProcedure<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
2017
+ procedures: Record<string, ProcedureDef>;
2018
+ } ? Schema['procedures'][ProcName] : never;
2019
+ type _OptionalProcedureParamNames<Params> = keyof {
2020
+ [K in keyof Params as Params[K] extends {
2021
+ optional: true;
2022
+ } ? K : never]: K;
1736
2023
  };
1737
- type OnKyselyQueryArgs<Schema extends SchemaDef> = {
1738
- schema: SchemaDef;
2024
+ type _RequiredProcedureParamNames<Params> = keyof {
2025
+ [K in keyof Params as Params[K] extends {
2026
+ optional: true;
2027
+ } ? never : K]: K;
2028
+ };
2029
+ type _HasRequiredProcedureParams<Params> = _RequiredProcedureParamNames<Params> extends never ? false : true;
2030
+ type MapProcedureArgsObject<Schema extends SchemaDef, Params> = Simplify<Optional<{
2031
+ [K in keyof Params]: MapProcedureParam<Schema, Params[K]>;
2032
+ }, _OptionalProcedureParamNames<Params>>>;
2033
+ type ProcedureEnvelope<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>, Params = GetProcedureParams<Schema, ProcName>> = keyof Params extends never ? {
2034
+ args?: Record<string, never>;
2035
+ } : _HasRequiredProcedureParams<Params> extends true ? {
2036
+ args: MapProcedureArgsObject<Schema, Params>;
2037
+ } : {
2038
+ args?: MapProcedureArgsObject<Schema, Params>;
2039
+ };
2040
+ type ProcedureHandlerCtx<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = {
1739
2041
  client: ClientContract<Schema>;
1740
- query: RootOperationNode;
1741
- proceed: ProceedKyselyQueryFunction;
2042
+ } & ProcedureEnvelope<Schema, ProcName>;
2043
+ /**
2044
+ * Shape of a procedure's runtime function.
2045
+ */
2046
+ 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>>>;
2047
+ /**
2048
+ * Signature for procedure handlers configured via client options.
2049
+ */
2050
+ type ProcedureHandlerFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (ctx: ProcedureHandlerCtx<Schema, ProcName>) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
2051
+ type MapProcedureReturn<Schema extends SchemaDef, Proc> = Proc extends {
2052
+ returnType: infer R;
2053
+ } ? Proc extends {
2054
+ returnArray: true;
2055
+ } ? Array<MapType<Schema, R & string>> : MapType<Schema, R & string> : never;
2056
+ type MapProcedureParam<Schema extends SchemaDef, P> = P extends {
2057
+ type: infer U;
2058
+ } ? OrUndefinedIf<P extends {
2059
+ array: true;
2060
+ } ? Array<MapType<Schema, U & string>> : MapType<Schema, U & string>, P extends {
2061
+ optional: true;
2062
+ } ? true : false> : never;
2063
+ type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
2064
+ [Key in RelationFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends {
2065
+ references: readonly unknown[];
2066
+ } ? never : Key]: true;
1742
2067
  };
1743
- type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
1744
- type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
2068
+ type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
2069
+ [Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
2070
+ } extends never ? false : true;
2071
+ type EnumValue<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = GetEnum<Schema, Enum>[keyof GetEnum<Schema, Enum>];
2072
+ 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;
2073
+ type ProviderSupportsDistinct<Schema extends SchemaDef> = Schema['provider']['type'] extends 'postgresql' ? true : false;
1745
2074
 
1746
2075
  /**
1747
2076
  * A promise that only executes when it's awaited or .then() is called.
@@ -1884,18 +2213,18 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
1884
2213
  */
1885
2214
  $pushSchema(): Promise<void>;
1886
2215
  } & {
1887
- [Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key, ToQueryOptions<Options>, ExtQueryArgs>;
1888
- } & ProcedureOperations<Schema> & ExtClientMembers;
2216
+ [Key in GetSlicedModels<Schema, Options> as Uncapitalize<Key>]: ModelOperations<Schema, Key, Options, ExtQueryArgs>;
2217
+ } & ProcedureOperations<Schema, Options> & ExtClientMembers;
1889
2218
  /**
1890
2219
  * The contract for a client in a transaction.
1891
2220
  */
1892
2221
  type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>, ExtQueryArgs extends ExtQueryArgsBase, ExtClientMembers extends ExtClientMembersBase> = Omit<ClientContract<Schema, Options, ExtQueryArgs, ExtClientMembers>, TransactionUnsupportedMethods>;
1893
- type ProcedureOperations<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
2222
+ type ProcedureOperations<Schema extends SchemaDef, Options extends ClientOptions<Schema> = ClientOptions<Schema>> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
1894
2223
  /**
1895
2224
  * Custom procedures.
1896
2225
  */
1897
2226
  $procs: {
1898
- [Key in GetProcedureNames<Schema>]: ProcedureFunc<Schema, Key>;
2227
+ [Key in GetSlicedProcedures<Schema, Options>]: ProcedureFunc<Schema, Key>;
1899
2228
  };
1900
2229
  } : {};
1901
2230
  /**
@@ -1920,6 +2249,9 @@ type CRUD_EXT = CRUD | 'post-update';
1920
2249
  * Extended CRUD operations including 'post-update'.
1921
2250
  */
1922
2251
  declare const CRUD_EXT: readonly ["create", "read", "update", "delete", "post-update"];
2252
+ type SliceOperations<T extends Record<string, unknown>, Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends ClientOptions<Schema>> = Omit<{
2253
+ [Key in keyof T as Key extends GetSlicedOperations<Schema, Model, Options> ? Key : never]: T[Key];
2254
+ }, IsDelegateModel<Schema, Model> extends true ? OperationsIneligibleForDelegateModels : never>;
1923
2255
  type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, ExtQueryArgs> = CommonModelOperations<Schema, Model, Options, ExtQueryArgs> & (Schema['provider']['type'] extends 'mysql' ? {} : {
1924
2256
  /**
1925
2257
  * Creates multiple entities and returns them.
@@ -1939,7 +2271,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
1939
2271
  * });
1940
2272
  * ```
1941
2273
  */
1942
- 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>[]>;
2274
+ createManyAndReturn<T extends CreateManyAndReturnArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'createManyAndReturn'>>(args?: SelectSubset<T, CreateManyAndReturnArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'createManyAndReturn'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
1943
2275
  /**
1944
2276
  * Updates multiple entities and returns them.
1945
2277
  * @param args - update args. Only scalar fields are allowed for data.
@@ -1962,7 +2294,7 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
1962
2294
  * });
1963
2295
  * ```
1964
2296
  */
1965
- 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>[]>;
2297
+ updateManyAndReturn<T extends UpdateManyAndReturnArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'updateManyAndReturn'>>(args: Subset<T, UpdateManyAndReturnArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'updateManyAndReturn'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
1966
2298
  });
1967
2299
  type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema>, ExtQueryArgs> = {
1968
2300
  /**
@@ -2046,35 +2378,35 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2046
2378
  * }); // result: `{ _count: { posts: number } }`
2047
2379
  * ```
2048
2380
  */
2049
- 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>[]>;
2381
+ findMany<T extends FindManyArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findMany'>>(args?: SelectSubset<T, FindManyArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findMany'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>[]>;
2050
2382
  /**
2051
2383
  * Returns a uniquely identified entity.
2052
2384
  * @param args - query args
2053
2385
  * @returns a single entity or null if not found
2054
2386
  * @see {@link findMany}
2055
2387
  */
2056
- 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>;
2388
+ findUnique<T extends FindUniqueArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options> | null>;
2057
2389
  /**
2058
2390
  * Returns a uniquely identified entity or throws `NotFoundError` if not found.
2059
2391
  * @param args - query args
2060
2392
  * @returns a single entity
2061
2393
  * @see {@link findMany}
2062
2394
  */
2063
- 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>>;
2395
+ findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findUnique'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2064
2396
  /**
2065
2397
  * Returns the first entity.
2066
2398
  * @param args - query args
2067
2399
  * @returns a single entity or null if not found
2068
2400
  * @see {@link findMany}
2069
2401
  */
2070
- 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>;
2402
+ findFirst<T extends FindFirstArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>(args?: SelectSubset<T, FindFirstArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options> | null>;
2071
2403
  /**
2072
2404
  * Returns the first entity or throws `NotFoundError` if not found.
2073
2405
  * @param args - query args
2074
2406
  * @returns a single entity
2075
2407
  * @see {@link findMany}
2076
2408
  */
2077
- 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>>;
2409
+ findFirstOrThrow<T extends FindFirstArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>(args?: SelectSubset<T, FindFirstArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'findFirst'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2078
2410
  /**
2079
2411
  * Creates a new entity.
2080
2412
  * @param args - create args
@@ -2127,7 +2459,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2127
2459
  * });
2128
2460
  * ```
2129
2461
  */
2130
- 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>>;
2462
+ create<T extends CreateArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'create'>>(args: SelectSubset<T, CreateArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'create'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2131
2463
  /**
2132
2464
  * Creates multiple entities. Only scalar fields are allowed.
2133
2465
  * @param args - create args
@@ -2271,7 +2603,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2271
2603
  * });
2272
2604
  * ```
2273
2605
  */
2274
- 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>>;
2606
+ update<T extends UpdateArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'update'>>(args: SelectSubset<T, UpdateArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'update'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2275
2607
  /**
2276
2608
  * Updates multiple entities.
2277
2609
  * @param args - update args. Only scalar fields are allowed for data.
@@ -2292,7 +2624,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2292
2624
  * limit: 10
2293
2625
  * });
2294
2626
  */
2295
- updateMany<T extends UpdateManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'updateMany'>>(args: Subset<T, UpdateManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'updateMany'>>): ZenStackPromise<Schema, BatchResult>;
2627
+ updateMany<T extends UpdateManyArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'updateMany'>>(args: Subset<T, UpdateManyArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'updateMany'>>): ZenStackPromise<Schema, BatchResult>;
2296
2628
  /**
2297
2629
  * Creates or updates an entity.
2298
2630
  * @param args - upsert args
@@ -2313,7 +2645,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2313
2645
  * });
2314
2646
  * ```
2315
2647
  */
2316
- 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>>;
2648
+ upsert<T extends UpsertArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'upsert'>>(args: SelectSubset<T, UpsertArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'upsert'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2317
2649
  /**
2318
2650
  * Deletes a uniquely identifiable entity.
2319
2651
  * @param args - delete args
@@ -2333,7 +2665,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2333
2665
  * }); // result: `{ id: string; email: string }`
2334
2666
  * ```
2335
2667
  */
2336
- 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>>;
2668
+ delete<T extends DeleteArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'delete'>>(args: SelectSubset<T, DeleteArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'delete'>>): ZenStackPromise<Schema, SimplifiedPlainResult<Schema, Model, T, Options>>;
2337
2669
  /**
2338
2670
  * Deletes multiple entities.
2339
2671
  * @param args - delete args
@@ -2353,7 +2685,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2353
2685
  * });
2354
2686
  * ```
2355
2687
  */
2356
- deleteMany<T extends DeleteManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'deleteMany'>>(args?: Subset<T, DeleteManyArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'deleteMany'>>): ZenStackPromise<Schema, BatchResult>;
2688
+ deleteMany<T extends DeleteManyArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'deleteMany'>>(args?: Subset<T, DeleteManyArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'deleteMany'>>): ZenStackPromise<Schema, BatchResult>;
2357
2689
  /**
2358
2690
  * Counts rows or field values.
2359
2691
  * @param args - count args
@@ -2372,7 +2704,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2372
2704
  * select: { _all: true, email: true }
2373
2705
  * }); // result: `{ _all: number, email: number }`
2374
2706
  */
2375
- 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>>>;
2707
+ count<T extends CountArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'count'>>(args?: Subset<T, CountArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'count'>>): ZenStackPromise<Schema, Simplify<CountResult<Schema, Model, T>>>;
2376
2708
  /**
2377
2709
  * Aggregates rows.
2378
2710
  * @param args - aggregation args
@@ -2390,7 +2722,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2390
2722
  * _max: { age: true }
2391
2723
  * }); // result: `{ _count: number, _avg: { age: number }, ... }`
2392
2724
  */
2393
- 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>>>;
2725
+ aggregate<T extends AggregateArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'aggregate'>>(args: Subset<T, AggregateArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'aggregate'>>): ZenStackPromise<Schema, Simplify<AggregateResult<Schema, Model, T>>>;
2394
2726
  /**
2395
2727
  * Groups rows by columns.
2396
2728
  * @param args - groupBy args
@@ -2424,7 +2756,7 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2424
2756
  * having: { country: 'US', age: { _avg: { gte: 18 } } }
2425
2757
  * });
2426
2758
  */
2427
- 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>>>;
2759
+ groupBy<T extends GroupByArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'groupBy'>>(args: Subset<T, GroupByArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'groupBy'>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
2428
2760
  /**
2429
2761
  * Checks if an entity exists.
2430
2762
  * @param args - exists args
@@ -2442,10 +2774,10 @@ type CommonModelOperations<Schema extends SchemaDef, Model extends GetModels<Sch
2442
2774
  * where: { posts: { some: { published: true } } },
2443
2775
  * }); // result: `boolean`
2444
2776
  */
2445
- exists<T extends ExistsArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'exists'>>(args?: Subset<T, ExistsArgs<Schema, Model> & ExtractExtQueryArgs<ExtQueryArgs, 'exists'>>): ZenStackPromise<Schema, boolean>;
2777
+ exists<T extends ExistsArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'exists'>>(args?: Subset<T, ExistsArgs<Schema, Model, Options> & ExtractExtQueryArgs<ExtQueryArgs, 'exists'>>): ZenStackPromise<Schema, boolean>;
2446
2778
  };
2447
2779
  type OperationsIneligibleForDelegateModels = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert';
2448
- 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>;
2780
+ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends ClientOptions<Schema> = ClientOptions<Schema>, ExtQueryArgs = {}> = SliceOperations<AllModelOperations<Schema, Model, Options, ExtQueryArgs>, Schema, Model, Options>;
2449
2781
  /**
2450
2782
  * Type for auth context that includes both scalar and relation fields.
2451
2783
  * Relations are recursively included to allow nested auth data like { user: { profile: { ... } } }
@@ -2455,117 +2787,6 @@ type AuthModelType<Schema extends SchemaDef, Model extends GetModels<Schema>> =
2455
2787
  };
2456
2788
  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>;
2457
2789
 
2458
- type ZModelFunctionContext<Schema extends SchemaDef> = {
2459
- /**
2460
- * ZenStack client instance
2461
- */
2462
- client: ClientContract<Schema>;
2463
- /**
2464
- * Database dialect
2465
- */
2466
- dialect: BaseCrudDialect<Schema>;
2467
- /**
2468
- * The containing model name
2469
- */
2470
- model: GetModels<Schema>;
2471
- /**
2472
- * The alias name that can be used to refer to the containing model
2473
- */
2474
- modelAlias: string;
2475
- /**
2476
- * The CRUD operation being performed
2477
- */
2478
- operation: CRUD_EXT;
2479
- };
2480
- type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
2481
- /**
2482
- * ZenStack client options.
2483
- */
2484
- type ClientOptions<Schema extends SchemaDef> = {
2485
- /**
2486
- * Kysely dialect.
2487
- */
2488
- dialect: Dialect;
2489
- /**
2490
- * Custom function definitions.
2491
- *
2492
- * @private
2493
- */
2494
- functions?: Record<string, ZModelFunction<Schema>>;
2495
- /**
2496
- * Plugins.
2497
- */
2498
- plugins?: AnyPlugin[];
2499
- /**
2500
- * Logging configuration.
2501
- */
2502
- log?: KyselyConfig['log'];
2503
- /**
2504
- * Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
2505
- * to `true`.
2506
- *
2507
- * Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
2508
- * `Date` object) although for `DateTime` field the data in DB is stored in UTC.
2509
- * @see https://github.com/brianc/node-postgres/issues/429
2510
- */
2511
- fixPostgresTimezone?: boolean;
2512
- /**
2513
- * Whether to enable input validations expressed with attributes like `@email`, `@regex`,
2514
- * `@@validate`, etc. Defaults to `true`.
2515
- */
2516
- validateInput?: boolean;
2517
- /**
2518
- * Options for omitting fields in ORM query results.
2519
- */
2520
- omit?: OmitConfig<Schema>;
2521
- /**
2522
- * Whether to allow overriding omit settings at query time. Defaults to `true`. When set to
2523
- * `false`, an `omit` clause that sets field to `false` (not omitting) will trigger a validation
2524
- * error.
2525
- */
2526
- allowQueryTimeOmitOverride?: boolean;
2527
- } & (HasComputedFields<Schema> extends true ? {
2528
- /**
2529
- * Computed field definitions.
2530
- */
2531
- computedFields: ComputedFieldsOptions<Schema>;
2532
- } : {}) & (HasProcedures<Schema> extends true ? {
2533
- /**
2534
- * Custom procedure definitions.
2535
- */
2536
- procedures: ProceduresOptions<Schema>;
2537
- } : {});
2538
- /**
2539
- * Config for omitting fields in ORM query results.
2540
- */
2541
- type OmitConfig<Schema extends SchemaDef> = {
2542
- [Model in GetModels<Schema>]?: {
2543
- [Field in GetModelFields<Schema, Model> as Field extends ScalarFields<Schema, Model> ? Field : never]?: boolean;
2544
- };
2545
- };
2546
- type ComputedFieldsOptions<Schema extends SchemaDef> = {
2547
- [Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
2548
- [Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
2549
- };
2550
- };
2551
- type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
2552
- type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
2553
- procedures: Record<string, ProcedureDef>;
2554
- } ? {
2555
- [Key in GetProcedureNames<Schema>]: ProcedureHandlerFunc<Schema, Key>;
2556
- } : {};
2557
- type HasProcedures<Schema extends SchemaDef> = Schema extends {
2558
- procedures: Record<string, ProcedureDef>;
2559
- } ? true : false;
2560
- /**
2561
- * Subset of client options relevant to query operations.
2562
- */
2563
- type QueryOptions<Schema extends SchemaDef> = Pick<ClientOptions<Schema>, 'omit'>;
2564
- /**
2565
- * Extract QueryOptions from ClientOptions
2566
- */
2567
- type ToQueryOptions<T extends ClientOptions<any>> = Pick<T, 'omit'>;
2568
-
2569
2790
  /**
2570
2791
  * ZenStack ORM client.
2571
2792
  */
@@ -2718,7 +2939,7 @@ declare function extractIdFields(entity: any, schema: SchemaDef, model: string):
2718
2939
  };
2719
2940
  declare function getDiscriminatorField(schema: SchemaDef, model: string): string | undefined;
2720
2941
  declare function getDelegateDescendantModels(schema: SchemaDef, model: string, collected?: Set<ModelDef>): ModelDef[];
2721
- declare function aggregate(eb: ExpressionBuilder<any, any>, expr: Expression<any>, op: AGGREGATE_OPERATORS): kysely.AggregateFunctionBuilder<any, any, string | number | bigint>;
2942
+ declare function aggregate(eb: ExpressionBuilder<any, any>, expr: Expression<any>, op: AggregateOperators): kysely.AggregateFunctionBuilder<any, any, string | number | bigint>;
2722
2943
  /**
2723
2944
  * Strips alias from the node if it exists.
2724
2945
  */
@@ -2810,4 +3031,4 @@ declare namespace schemaUtils {
2810
3031
  export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
2811
3032
  }
2812
3033
 
2813
- export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, 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 ExtClientMembersBase, 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 };
3034
+ export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, AllCrudOperations, type AllModelOperations, AllReadOperations, AnyNull, AnyNullClass, type AnyPlugin, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CoreCreateOperations, CoreCrudOperations, CoreDeleteOperations, CoreReadOperations, CoreUpdateOperations, 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 ExtClientMembersBase, type ExtQueryArgsBase, type FilterKind, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetAllIncludedOperations, type GetIncludedOperations, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GetQueryOptions, type GetSlicedFilterKindsForField, type GetSlicedModels, type GetSlicedOperations, type GetSlicedProcedures, 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 ModelSlicingOptions, 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 SlicingOptions, type SortOrder, type StringFilter, type Subset, type ToKysely, 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 };