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