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