@zenstackhq/runtime 3.0.0-beta.1 → 3.0.0-beta.11
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-CusA0mQO.d.cts → auth-CzM6GLw6.d.cts} +17 -960
- package/dist/{contract-CusA0mQO.d.ts → auth-CzM6GLw6.d.ts} +17 -960
- package/dist/index.cjs +5299 -5479
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1290 -11
- package/dist/index.d.ts +1290 -11
- package/dist/index.js +5252 -5442
- package/dist/index.js.map +1 -1
- package/dist/schema.cjs +3 -0
- package/dist/schema.cjs.map +1 -1
- package/dist/schema.d.cts +3 -0
- package/dist/schema.d.ts +3 -0
- package/dist/schema.js +3 -0
- package/dist/schema.js.map +1 -1
- package/package.json +13 -16
- package/dist/plugins/policy/index.cjs +0 -2650
- package/dist/plugins/policy/index.cjs.map +0 -1
- package/dist/plugins/policy/index.d.cts +0 -22
- package/dist/plugins/policy/index.d.ts +0 -22
- package/dist/plugins/policy/index.js +0 -2624
- package/dist/plugins/policy/index.js.map +0 -1
- package/dist/plugins/policy/plugin.zmodel +0 -33
package/dist/index.d.ts
CHANGED
|
@@ -1,36 +1,1315 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import '
|
|
5
|
-
|
|
1
|
+
import Decimal from 'decimal.js';
|
|
2
|
+
import * as _zenstackhq_sdk_schema from '@zenstackhq/sdk/schema';
|
|
3
|
+
import { SchemaDef, BuiltinType, GetModels, FieldDef, ModelDef, DataSourceProviderType, GetModel, ProcedureDef, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, ThisExpression, NullExpression } from '@zenstackhq/sdk/schema';
|
|
4
|
+
import { F as FindArgs, O as OrArray, a as OrderBy, M as MaybePromise, T as ToKyselySchema, P as PrependParameter, A as AuthType, b as ToKysely, U as UnwrapTuplePromises, S as SelectSubset, c as Simplify, d as ModelResult, e as FindUniqueArgs, C as CreateArgs, f as CreateManyArgs, B as BatchResult, g as CreateManyAndReturnArgs, h as UpdateArgs, i as UpdateManyArgs, j as Subset, k as UpdateManyAndReturnArgs, l as UpsertArgs, D as DeleteArgs, m as DeleteManyArgs, n as CountArgs, o as CountResult, p as AggregateArgs, q as AggregateResult, G as GroupByArgs, r as GroupByResult, s as OrUndefinedIf } from './auth-CzM6GLw6.js';
|
|
5
|
+
export { E as BooleanFilter, z as BytesFilter, y as DateTimeFilter, Y as FindFirstArgs, X as FindManyArgs, V as IncludeInput, J as JsonArray, t as JsonObject, u as JsonValue, I as NullsOrder, N as NumberFilter, L as OmitInput, Q as SelectIncludeOmit, R as SelectInput, v as SimplifiedModelResult, H as SortOrder, x as StringFilter, w as TypeDefResult, W as WhereInput, K as WhereUniqueInput } from './auth-CzM6GLw6.js';
|
|
6
|
+
import * as kysely from 'kysely';
|
|
7
|
+
import { ExpressionBuilder, SelectQueryBuilder, Expression, SqlBool, ExpressionWrapper, OperationNode, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig, OperationNodeVisitor, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode } from 'kysely';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Client API methods that are not supported in transactions.
|
|
11
|
+
*/
|
|
12
|
+
declare const TRANSACTION_UNSUPPORTED_METHODS: readonly ["$transaction", "$connect", "$disconnect", "$use"];
|
|
13
|
+
/**
|
|
14
|
+
* Logical combinators used in filters.
|
|
15
|
+
*/
|
|
16
|
+
declare const LOGICAL_COMBINATORS: readonly ["AND", "OR", "NOT"];
|
|
17
|
+
/**
|
|
18
|
+
* Aggregation operators.
|
|
19
|
+
*/
|
|
20
|
+
declare const AGGREGATE_OPERATORS: readonly ["_count", "_sum", "_avg", "_min", "_max"];
|
|
21
|
+
type AGGREGATE_OPERATORS = (typeof AGGREGATE_OPERATORS)[number];
|
|
22
|
+
|
|
23
|
+
declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
24
|
+
protected readonly schema: Schema;
|
|
25
|
+
protected readonly options: ClientOptions<Schema>;
|
|
26
|
+
protected eb: ExpressionBuilder<any, any>;
|
|
27
|
+
constructor(schema: Schema, options: ClientOptions<Schema>);
|
|
28
|
+
transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
|
|
29
|
+
transformOutput(value: unknown, _type: BuiltinType): unknown;
|
|
30
|
+
buildSelectModel(model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
|
|
31
|
+
buildFilterSortTake(model: GetModels<Schema>, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
|
|
32
|
+
buildFilter(model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
|
|
33
|
+
private buildCursorFilter;
|
|
34
|
+
private isLogicalCombinator;
|
|
35
|
+
protected buildCompositeFilter(model: string, modelAlias: string, key: (typeof LOGICAL_COMBINATORS)[number], payload: any): Expression<SqlBool>;
|
|
36
|
+
private buildRelationFilter;
|
|
37
|
+
private buildToOneRelationFilter;
|
|
38
|
+
private buildToManyRelationFilter;
|
|
39
|
+
private buildArrayFilter;
|
|
40
|
+
buildPrimitiveFilter(fieldRef: Expression<any>, fieldDef: FieldDef, payload: any): Expression<SqlBool>;
|
|
41
|
+
private buildLiteralFilter;
|
|
42
|
+
private buildStandardFilter;
|
|
43
|
+
private buildStringFilter;
|
|
44
|
+
private prepStringCasing;
|
|
45
|
+
private buildNumberFilter;
|
|
46
|
+
private buildBooleanFilter;
|
|
47
|
+
private buildDateTimeFilter;
|
|
48
|
+
private buildBytesFilter;
|
|
49
|
+
private buildEnumFilter;
|
|
50
|
+
buildOrderBy(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, orderBy: OrArray<OrderBy<Schema, GetModels<Schema>, boolean, boolean>> | undefined, negated: boolean): SelectQueryBuilder<any, any, any>;
|
|
51
|
+
buildSelectAllFields(model: string, query: SelectQueryBuilder<any, any, any>, omit: Record<string, boolean | undefined> | undefined, modelAlias: string): SelectQueryBuilder<any, any, any>;
|
|
52
|
+
protected buildModelSelect(model: GetModels<Schema>, subQueryAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>, selectAllFields: boolean): SelectQueryBuilder<any, any, {}>;
|
|
53
|
+
buildSelectField(query: SelectQueryBuilder<any, any, any>, model: string, modelAlias: string, field: string): SelectQueryBuilder<any, any, any>;
|
|
54
|
+
buildDelegateJoin(thisModel: string, thisModelAlias: string, otherModelAlias: string, query: SelectQueryBuilder<any, any, any>): SelectQueryBuilder<any, any, any>;
|
|
55
|
+
buildCountJson(model: string, eb: ExpressionBuilder<any, any>, parentAlias: string, payload: any): ExpressionWrapper<any, any, unknown>;
|
|
56
|
+
private negateSort;
|
|
57
|
+
true(): Expression<SqlBool>;
|
|
58
|
+
false(): Expression<SqlBool>;
|
|
59
|
+
isTrue(expression: Expression<SqlBool>): boolean;
|
|
60
|
+
isFalse(expression: Expression<SqlBool>): boolean;
|
|
61
|
+
and(...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
62
|
+
or(...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
63
|
+
not(...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
64
|
+
fieldRef(model: string, field: string, modelAlias?: string, inlineComputedField?: boolean): any;
|
|
65
|
+
protected canJoinWithoutNestedSelect(modelDef: ModelDef, payload: boolean | FindArgs<Schema, GetModels<Schema>, true>): boolean;
|
|
66
|
+
abstract get provider(): DataSourceProviderType;
|
|
67
|
+
/**
|
|
68
|
+
* Builds selection for a relation field.
|
|
69
|
+
*/
|
|
70
|
+
abstract buildRelationSelection(query: SelectQueryBuilder<any, any, any>, model: string, relationField: string, parentAlias: string, payload: true | FindArgs<Schema, GetModels<Schema>, true>): SelectQueryBuilder<any, any, any>;
|
|
71
|
+
/**
|
|
72
|
+
* Builds skip and take clauses.
|
|
73
|
+
*/
|
|
74
|
+
abstract buildSkipTake(query: SelectQueryBuilder<any, any, any>, skip: number | undefined, take: number | undefined): SelectQueryBuilder<any, any, any>;
|
|
75
|
+
/**
|
|
76
|
+
* Builds an Kysely expression that returns a JSON object for the given key-value pairs.
|
|
77
|
+
*/
|
|
78
|
+
abstract buildJsonObject(value: Record<string, Expression<unknown>>): ExpressionWrapper<any, any, unknown>;
|
|
79
|
+
/**
|
|
80
|
+
* Builds an Kysely expression that returns the length of an array.
|
|
81
|
+
*/
|
|
82
|
+
abstract buildArrayLength(array: Expression<unknown>): ExpressionWrapper<any, any, number>;
|
|
83
|
+
/**
|
|
84
|
+
* Builds an array literal SQL string for the given values.
|
|
85
|
+
*/
|
|
86
|
+
abstract buildArrayLiteralSQL(values: unknown[]): string;
|
|
87
|
+
/**
|
|
88
|
+
* Whether the dialect supports updating with a limit on the number of updated rows.
|
|
89
|
+
*/
|
|
90
|
+
abstract get supportsUpdateWithLimit(): boolean;
|
|
91
|
+
/**
|
|
92
|
+
* Whether the dialect supports deleting with a limit on the number of deleted rows.
|
|
93
|
+
*/
|
|
94
|
+
abstract get supportsDeleteWithLimit(): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* Whether the dialect supports DISTINCT ON.
|
|
97
|
+
*/
|
|
98
|
+
abstract get supportsDistinctOn(): boolean;
|
|
99
|
+
/**
|
|
100
|
+
* Whether the dialect support inserting with `DEFAULT` as field value.
|
|
101
|
+
*/
|
|
102
|
+
abstract get supportInsertWithDefault(): boolean;
|
|
103
|
+
/**
|
|
104
|
+
* Gets the SQL column type for the given field definition.
|
|
105
|
+
*/
|
|
106
|
+
abstract getFieldSqlType(fieldDef: FieldDef): string;
|
|
107
|
+
abstract getStringCasingBehavior(): {
|
|
108
|
+
supportsILike: boolean;
|
|
109
|
+
likeCaseSensitive: boolean;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
type CoreCrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
|
|
114
|
+
type AllCrudOperation = CoreCrudOperation | 'findUniqueOrThrow' | 'findFirstOrThrow';
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* ZenStack runtime plugin.
|
|
118
|
+
*/
|
|
119
|
+
interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
|
|
120
|
+
/**
|
|
121
|
+
* Plugin ID.
|
|
122
|
+
*/
|
|
123
|
+
id: string;
|
|
124
|
+
/**
|
|
125
|
+
* Plugin display name.
|
|
126
|
+
*/
|
|
127
|
+
name?: string;
|
|
128
|
+
/**
|
|
129
|
+
* Plugin description.
|
|
130
|
+
*/
|
|
131
|
+
description?: string;
|
|
132
|
+
/**
|
|
133
|
+
* Custom function implementations.
|
|
134
|
+
*/
|
|
135
|
+
functions?: Record<string, ZModelFunction<Schema>>;
|
|
136
|
+
/**
|
|
137
|
+
* Intercepts an ORM query.
|
|
138
|
+
*/
|
|
139
|
+
onQuery?: OnQueryCallback<Schema>;
|
|
140
|
+
/**
|
|
141
|
+
* Intercepts an entity mutation.
|
|
142
|
+
*/
|
|
143
|
+
onEntityMutation?: EntityMutationHooksDef<Schema>;
|
|
144
|
+
/**
|
|
145
|
+
* Intercepts a Kysely query.
|
|
146
|
+
*/
|
|
147
|
+
onKyselyQuery?: OnKyselyQueryCallback<Schema>;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Defines a ZenStack runtime plugin.
|
|
151
|
+
*/
|
|
152
|
+
declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
|
|
153
|
+
|
|
154
|
+
type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
|
|
155
|
+
type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
156
|
+
/**
|
|
157
|
+
* The model that is being queried.
|
|
158
|
+
*/
|
|
159
|
+
model: GetModels<Schema>;
|
|
160
|
+
/**
|
|
161
|
+
* The operation that is being performed.
|
|
162
|
+
*/
|
|
163
|
+
operation: AllCrudOperation;
|
|
164
|
+
/**
|
|
165
|
+
* The query arguments.
|
|
166
|
+
*/
|
|
167
|
+
args: unknown;
|
|
168
|
+
/**
|
|
169
|
+
* The function to proceed with the original query.
|
|
170
|
+
* It takes the same arguments as the operation method.
|
|
171
|
+
*
|
|
172
|
+
* @param args The query arguments.
|
|
173
|
+
*/
|
|
174
|
+
proceed: (args: unknown) => Promise<unknown>;
|
|
175
|
+
/**
|
|
176
|
+
* The ZenStack client that is performing the operation.
|
|
177
|
+
*/
|
|
178
|
+
client: ClientContract<Schema>;
|
|
179
|
+
};
|
|
180
|
+
type EntityMutationHooksDef<Schema extends SchemaDef> = {
|
|
181
|
+
/**
|
|
182
|
+
* Called before entities are mutated.
|
|
183
|
+
*/
|
|
184
|
+
beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
|
|
185
|
+
/**
|
|
186
|
+
* Called after entities are mutated.
|
|
187
|
+
*/
|
|
188
|
+
afterEntityMutation?: AfterEntityMutationCallback<Schema>;
|
|
189
|
+
/**
|
|
190
|
+
* Whether to run after-mutation hooks within the transaction that performs the mutation.
|
|
191
|
+
*
|
|
192
|
+
* If set to `true`, if the mutation already runs inside a transaction, the callbacks are
|
|
193
|
+
* executed immediately after the mutation within the transaction boundary. If the mutation
|
|
194
|
+
* is not running inside a transaction, a new transaction is created to run both the mutation
|
|
195
|
+
* and the callbacks.
|
|
196
|
+
*
|
|
197
|
+
* If set to `false`, the callbacks are executed after the mutation transaction is committed.
|
|
198
|
+
*
|
|
199
|
+
* Defaults to `false`.
|
|
200
|
+
*/
|
|
201
|
+
runAfterMutationWithinTransaction?: boolean;
|
|
202
|
+
};
|
|
203
|
+
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
204
|
+
/**
|
|
205
|
+
* The model that is being mutated.
|
|
206
|
+
*/
|
|
207
|
+
model: GetModels<Schema>;
|
|
208
|
+
/**
|
|
209
|
+
* The mutation action that is being performed.
|
|
210
|
+
*/
|
|
211
|
+
action: 'create' | 'update' | 'delete';
|
|
212
|
+
/**
|
|
213
|
+
* The mutation data. Only available for create and update actions.
|
|
214
|
+
*/
|
|
215
|
+
queryNode: OperationNode;
|
|
216
|
+
/**
|
|
217
|
+
* A query ID that uniquely identifies the mutation operation. You can use it to correlate
|
|
218
|
+
* data between the before and after mutation hooks.
|
|
219
|
+
*/
|
|
220
|
+
queryId: string;
|
|
221
|
+
};
|
|
222
|
+
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
223
|
+
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
224
|
+
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
225
|
+
/**
|
|
226
|
+
* Loads the entities that are about to be mutated. The db operation that loads the entities is executed
|
|
227
|
+
* within the same transaction context as the mutation.
|
|
228
|
+
*/
|
|
229
|
+
loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
230
|
+
/**
|
|
231
|
+
* The ZenStack client you can use to perform additional operations. The database operations initiated
|
|
232
|
+
* from this client are executed within the same transaction as the mutation if the mutation is running
|
|
233
|
+
* inside a transaction.
|
|
234
|
+
*
|
|
235
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
236
|
+
*/
|
|
237
|
+
client: ClientContract<Schema>;
|
|
238
|
+
};
|
|
239
|
+
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
240
|
+
/**
|
|
241
|
+
* Loads the entities that have been mutated.
|
|
242
|
+
*/
|
|
243
|
+
loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
244
|
+
/**
|
|
245
|
+
* The ZenStack client you can use to perform additional operations.
|
|
246
|
+
* See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
|
|
247
|
+
*
|
|
248
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
249
|
+
*/
|
|
250
|
+
client: ClientContract<Schema>;
|
|
251
|
+
};
|
|
252
|
+
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
253
|
+
schema: SchemaDef;
|
|
254
|
+
client: ClientContract<Schema>;
|
|
255
|
+
query: RootOperationNode;
|
|
256
|
+
proceed: ProceedKyselyQueryFunction;
|
|
257
|
+
};
|
|
258
|
+
type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
|
|
259
|
+
type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
|
|
260
|
+
|
|
261
|
+
type ZModelFunctionContext<Schema extends SchemaDef> = {
|
|
262
|
+
/**
|
|
263
|
+
* ZenStack client instance
|
|
264
|
+
*/
|
|
265
|
+
client: ClientContract<Schema>;
|
|
266
|
+
/**
|
|
267
|
+
* Database dialect
|
|
268
|
+
*/
|
|
269
|
+
dialect: BaseCrudDialect<Schema>;
|
|
270
|
+
/**
|
|
271
|
+
* The containing model name
|
|
272
|
+
*/
|
|
273
|
+
model: GetModels<Schema>;
|
|
274
|
+
/**
|
|
275
|
+
* The alias name that can be used to refer to the containing model
|
|
276
|
+
*/
|
|
277
|
+
modelAlias: string;
|
|
278
|
+
/**
|
|
279
|
+
* The CRUD operation being performed
|
|
280
|
+
*/
|
|
281
|
+
operation: CRUD_EXT;
|
|
282
|
+
};
|
|
283
|
+
type ZModelFunction<Schema extends SchemaDef> = (eb: ExpressionBuilder<ToKyselySchema<Schema>, keyof ToKyselySchema<Schema>>, args: Expression<any>[], context: ZModelFunctionContext<Schema>) => Expression<unknown>;
|
|
284
|
+
/**
|
|
285
|
+
* ZenStack client options.
|
|
286
|
+
*/
|
|
287
|
+
type ClientOptions<Schema extends SchemaDef> = {
|
|
288
|
+
/**
|
|
289
|
+
* Kysely dialect.
|
|
290
|
+
*/
|
|
291
|
+
dialect: Dialect;
|
|
292
|
+
/**
|
|
293
|
+
* Custom function definitions.
|
|
294
|
+
*/
|
|
295
|
+
functions?: Record<string, ZModelFunction<Schema>>;
|
|
296
|
+
/**
|
|
297
|
+
* Plugins.
|
|
298
|
+
*/
|
|
299
|
+
plugins?: RuntimePlugin<Schema>[];
|
|
300
|
+
/**
|
|
301
|
+
* Logging configuration.
|
|
302
|
+
*/
|
|
303
|
+
log?: KyselyConfig['log'];
|
|
304
|
+
/**
|
|
305
|
+
* Whether to automatically fix timezone for `DateTime` fields returned by node-pg. Defaults
|
|
306
|
+
* to `true`.
|
|
307
|
+
*
|
|
308
|
+
* Node-pg has a terrible quirk that it interprets the date value as local timezone (as a
|
|
309
|
+
* `Date` object) although for `DateTime` field the data in DB is stored in UTC.
|
|
310
|
+
* @see https://github.com/brianc/node-postgres/issues/429
|
|
311
|
+
*/
|
|
312
|
+
fixPostgresTimezone?: boolean;
|
|
313
|
+
/**
|
|
314
|
+
* Whether to enable input validations expressed with attributes like `@email`, `@regex`,
|
|
315
|
+
* `@@validate`, etc. Defaults to `true`.
|
|
316
|
+
*/
|
|
317
|
+
validateInput?: boolean;
|
|
318
|
+
} & (HasComputedFields<Schema> extends true ? {
|
|
319
|
+
/**
|
|
320
|
+
* Computed field definitions.
|
|
321
|
+
*/
|
|
322
|
+
computedFields: ComputedFieldsOptions<Schema>;
|
|
323
|
+
} : {}) & (HasProcedures<Schema> extends true ? {
|
|
324
|
+
/**
|
|
325
|
+
* Custom procedure definitions.
|
|
326
|
+
*/
|
|
327
|
+
procedures: ProceduresOptions<Schema>;
|
|
328
|
+
} : {});
|
|
329
|
+
type ComputedFieldsOptions<Schema extends SchemaDef> = {
|
|
330
|
+
[Model in GetModels<Schema> as 'computedFields' extends keyof GetModel<Schema, Model> ? Model : never]: {
|
|
331
|
+
[Field in keyof Schema['models'][Model]['computedFields']]: PrependParameter<ExpressionBuilder<ToKyselySchema<Schema>, Model>, Schema['models'][Model]['computedFields'][Field]>;
|
|
332
|
+
};
|
|
333
|
+
};
|
|
334
|
+
type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Schema> ? false : keyof ComputedFieldsOptions<Schema> extends never ? false : true;
|
|
335
|
+
type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
|
|
336
|
+
procedures: Record<string, ProcedureDef>;
|
|
337
|
+
} ? {
|
|
338
|
+
[Key in keyof Schema['procedures']]: PrependParameter<ClientContract<Schema>, ProcedureFunc<Schema, Schema['procedures'][Key]>>;
|
|
339
|
+
} : {};
|
|
340
|
+
type HasProcedures<Schema extends SchemaDef> = Schema extends {
|
|
341
|
+
procedures: Record<string, ProcedureDef>;
|
|
342
|
+
} ? true : false;
|
|
343
|
+
|
|
344
|
+
/**
|
|
345
|
+
* A promise that only executes when it's awaited or .then() is called.
|
|
346
|
+
*/
|
|
347
|
+
type ZenStackPromise<Schema extends SchemaDef, T> = Promise<T> & {
|
|
348
|
+
/**
|
|
349
|
+
* @private
|
|
350
|
+
* Callable to get a plain promise.
|
|
351
|
+
*/
|
|
352
|
+
cb: (txClient?: ClientContract<Schema>) => Promise<T>;
|
|
353
|
+
};
|
|
354
|
+
|
|
355
|
+
type TransactionUnsupportedMethods = (typeof TRANSACTION_UNSUPPORTED_METHODS)[number];
|
|
356
|
+
/**
|
|
357
|
+
* Transaction isolation levels.
|
|
358
|
+
*/
|
|
359
|
+
declare enum TransactionIsolationLevel {
|
|
360
|
+
ReadUncommitted = "read uncommitted",
|
|
361
|
+
ReadCommitted = "read committed",
|
|
362
|
+
RepeatableRead = "repeatable read",
|
|
363
|
+
Serializable = "serializable",
|
|
364
|
+
Snapshot = "snapshot"
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* ZenStack client interface.
|
|
368
|
+
*/
|
|
369
|
+
type ClientContract<Schema extends SchemaDef> = {
|
|
370
|
+
readonly $schema: Schema;
|
|
371
|
+
/**
|
|
372
|
+
* The client options.
|
|
373
|
+
*/
|
|
374
|
+
readonly $options: ClientOptions<Schema>;
|
|
375
|
+
/**
|
|
376
|
+
* Executes a prepared raw query and returns the number of affected rows.
|
|
377
|
+
* @example
|
|
378
|
+
* ```
|
|
379
|
+
* const result = await db.$executeRaw`UPDATE User SET cool = ${true} WHERE email = ${'user@email.com'};`
|
|
380
|
+
* ```
|
|
381
|
+
*/
|
|
382
|
+
$executeRaw(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, number>;
|
|
383
|
+
/**
|
|
384
|
+
* Executes a raw query and returns the number of affected rows.
|
|
385
|
+
* This method is susceptible to SQL injections.
|
|
386
|
+
* @example
|
|
387
|
+
* ```
|
|
388
|
+
* const result = await db.$executeRawUnsafe('UPDATE User SET cool = $1 WHERE email = $2 ;', true, 'user@email.com')
|
|
389
|
+
* ```
|
|
390
|
+
*/
|
|
391
|
+
$executeRawUnsafe(query: string, ...values: any[]): ZenStackPromise<Schema, number>;
|
|
392
|
+
/**
|
|
393
|
+
* Performs a prepared raw query and returns the `SELECT` data.
|
|
394
|
+
* @example
|
|
395
|
+
* ```
|
|
396
|
+
* const result = await db.$queryRaw`SELECT * FROM User WHERE id = ${1} OR email = ${'user@email.com'};`
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
$queryRaw<T = unknown>(query: TemplateStringsArray, ...values: any[]): ZenStackPromise<Schema, T>;
|
|
400
|
+
/**
|
|
401
|
+
* Performs a raw query and returns the `SELECT` data.
|
|
402
|
+
* This method is susceptible to SQL injections.
|
|
403
|
+
* @example
|
|
404
|
+
* ```
|
|
405
|
+
* const result = await db.$queryRawUnsafe('SELECT * FROM User WHERE id = $1 OR email = $2;', 1, 'user@email.com')
|
|
406
|
+
* ```
|
|
407
|
+
*/
|
|
408
|
+
$queryRawUnsafe<T = unknown>(query: string, ...values: any[]): ZenStackPromise<Schema, T>;
|
|
409
|
+
/**
|
|
410
|
+
* The current user identity.
|
|
411
|
+
*/
|
|
412
|
+
get $auth(): AuthType<Schema> | undefined;
|
|
413
|
+
/**
|
|
414
|
+
* Sets the current user identity.
|
|
415
|
+
*/
|
|
416
|
+
$setAuth(auth: AuthType<Schema> | undefined): ClientContract<Schema>;
|
|
417
|
+
/**
|
|
418
|
+
* Returns a new client enabling/disabling input validations expressed with attributes like
|
|
419
|
+
* `@email`, `@regex`, `@@validate`, etc.
|
|
420
|
+
*/
|
|
421
|
+
$setInputValidation(enable: boolean): ClientContract<Schema>;
|
|
422
|
+
/**
|
|
423
|
+
* The Kysely query builder instance.
|
|
424
|
+
*/
|
|
425
|
+
readonly $qb: ToKysely<Schema>;
|
|
426
|
+
/**
|
|
427
|
+
* The raw Kysely query builder without any ZenStack enhancements.
|
|
428
|
+
*/
|
|
429
|
+
readonly $qbRaw: ToKysely<any>;
|
|
430
|
+
/**
|
|
431
|
+
* Starts an interactive transaction.
|
|
432
|
+
*/
|
|
433
|
+
$transaction<T>(callback: (tx: Omit<ClientContract<Schema>, TransactionUnsupportedMethods>) => Promise<T>, options?: {
|
|
434
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
435
|
+
}): Promise<T>;
|
|
436
|
+
/**
|
|
437
|
+
* Starts a sequential transaction.
|
|
438
|
+
*/
|
|
439
|
+
$transaction<P extends ZenStackPromise<Schema, any>[]>(arg: [...P], options?: {
|
|
440
|
+
isolationLevel?: TransactionIsolationLevel;
|
|
441
|
+
}): Promise<UnwrapTuplePromises<P>>;
|
|
442
|
+
/**
|
|
443
|
+
* Returns a new client with the specified plugin installed.
|
|
444
|
+
*/
|
|
445
|
+
$use(plugin: RuntimePlugin<Schema>): ClientContract<Schema>;
|
|
446
|
+
/**
|
|
447
|
+
* Returns a new client with the specified plugin removed.
|
|
448
|
+
*/
|
|
449
|
+
$unuse(pluginId: string): ClientContract<Schema>;
|
|
450
|
+
/**
|
|
451
|
+
* Returns a new client with all plugins removed.
|
|
452
|
+
*/
|
|
453
|
+
$unuseAll(): ClientContract<Schema>;
|
|
454
|
+
/**
|
|
455
|
+
* Eagerly connects to the database.
|
|
456
|
+
*/
|
|
457
|
+
$connect(): Promise<void>;
|
|
458
|
+
/**
|
|
459
|
+
* Explicitly disconnects from the database.
|
|
460
|
+
*/
|
|
461
|
+
$disconnect(): Promise<void>;
|
|
462
|
+
/**
|
|
463
|
+
* Pushes the schema to the database. For testing purposes only.
|
|
464
|
+
* @private
|
|
465
|
+
*/
|
|
466
|
+
$pushSchema(): Promise<void>;
|
|
467
|
+
} & {
|
|
468
|
+
[Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key>;
|
|
469
|
+
} & Procedures<Schema>;
|
|
470
|
+
/**
|
|
471
|
+
* The contract for a client in a transaction.
|
|
472
|
+
*/
|
|
473
|
+
type TransactionClientContract<Schema extends SchemaDef> = Omit<ClientContract<Schema>, TransactionUnsupportedMethods>;
|
|
474
|
+
type _TypeMap = {
|
|
475
|
+
String: string;
|
|
476
|
+
Int: number;
|
|
477
|
+
Float: number;
|
|
478
|
+
BigInt: bigint;
|
|
479
|
+
Decimal: Decimal;
|
|
480
|
+
Boolean: boolean;
|
|
481
|
+
DateTime: Date;
|
|
482
|
+
};
|
|
483
|
+
type MapType<Schema extends SchemaDef, T extends string> = T extends keyof _TypeMap ? _TypeMap[T] : T extends GetModels<Schema> ? ModelResult<Schema, T> : unknown;
|
|
484
|
+
type Procedures<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
|
|
485
|
+
$procedures: {
|
|
486
|
+
[Key in keyof Schema['procedures']]: ProcedureFunc<Schema, Schema['procedures'][Key]>;
|
|
487
|
+
};
|
|
488
|
+
} : {};
|
|
489
|
+
type ProcedureFunc<Schema extends SchemaDef, Proc extends ProcedureDef> = (...args: MapProcedureParams<Schema, Proc['params']>) => Promise<MapType<Schema, Proc['returnType']>>;
|
|
490
|
+
type MapProcedureParams<Schema extends SchemaDef, Params> = {
|
|
491
|
+
[P in keyof Params]: Params[P] extends {
|
|
492
|
+
type: infer U;
|
|
493
|
+
} ? OrUndefinedIf<MapType<Schema, U & string>, Params[P] extends {
|
|
494
|
+
optional: true;
|
|
495
|
+
} ? true : false> : never;
|
|
496
|
+
};
|
|
497
|
+
/**
|
|
498
|
+
* Creates a new ZenStack client instance.
|
|
499
|
+
*/
|
|
500
|
+
interface ClientConstructor {
|
|
501
|
+
new <Schema extends SchemaDef>(schema: Schema, options: ClientOptions<Schema>): ClientContract<Schema>;
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* CRUD operations.
|
|
505
|
+
*/
|
|
506
|
+
type CRUD = 'create' | 'read' | 'update' | 'delete';
|
|
507
|
+
/**
|
|
508
|
+
* CRUD operations.
|
|
509
|
+
*/
|
|
510
|
+
declare const CRUD: readonly ["create", "read", "update", "delete"];
|
|
511
|
+
/**
|
|
512
|
+
* Extended CRUD operations including 'post-update'.
|
|
513
|
+
*/
|
|
514
|
+
type CRUD_EXT = CRUD | 'post-update';
|
|
515
|
+
/**
|
|
516
|
+
* Extended CRUD operations including 'post-update'.
|
|
517
|
+
*/
|
|
518
|
+
declare const CRUD_EXT: readonly ["create", "read", "update", "delete", "post-update"];
|
|
519
|
+
type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
|
|
520
|
+
/**
|
|
521
|
+
* Returns a list of entities.
|
|
522
|
+
* @param args - query args
|
|
523
|
+
* @returns a list of entities
|
|
524
|
+
*
|
|
525
|
+
* @example
|
|
526
|
+
* ```ts
|
|
527
|
+
* // find all users and return all scalar fields
|
|
528
|
+
* await db.user.findMany();
|
|
529
|
+
*
|
|
530
|
+
* // find all users with name 'Alex'
|
|
531
|
+
* await db.user.findMany({
|
|
532
|
+
* where: {
|
|
533
|
+
* name: 'Alex'
|
|
534
|
+
* }
|
|
535
|
+
* });
|
|
536
|
+
*
|
|
537
|
+
* // select fields
|
|
538
|
+
* await db.user.findMany({
|
|
539
|
+
* select: {
|
|
540
|
+
* name: true,
|
|
541
|
+
* email: true,
|
|
542
|
+
* }
|
|
543
|
+
* }); // result: `Array<{ name: string, email: string }>`
|
|
544
|
+
*
|
|
545
|
+
* // omit fields
|
|
546
|
+
* await db.user.findMany({
|
|
547
|
+
* omit: {
|
|
548
|
+
* name: true,
|
|
549
|
+
* }
|
|
550
|
+
* }); // result: `Array<{ id: number; email: string; ... }>`
|
|
551
|
+
*
|
|
552
|
+
* // include relations (and all scalar fields)
|
|
553
|
+
* await db.user.findMany({
|
|
554
|
+
* include: {
|
|
555
|
+
* posts: true,
|
|
556
|
+
* }
|
|
557
|
+
* }); // result: `Array<{ ...; posts: Post[] }>`
|
|
558
|
+
*
|
|
559
|
+
* // include relations with filter
|
|
560
|
+
* await db.user.findMany({
|
|
561
|
+
* include: {
|
|
562
|
+
* posts: {
|
|
563
|
+
* where: {
|
|
564
|
+
* published: true
|
|
565
|
+
* }
|
|
566
|
+
* }
|
|
567
|
+
* }
|
|
568
|
+
* });
|
|
569
|
+
*
|
|
570
|
+
* // pagination and sorting
|
|
571
|
+
* await db.user.findMany({
|
|
572
|
+
* skip: 10,
|
|
573
|
+
* take: 10,
|
|
574
|
+
* orderBy: [{ name: 'asc' }, { email: 'desc' }],
|
|
575
|
+
* });
|
|
576
|
+
*
|
|
577
|
+
* // pagination with cursor (https://www.prisma.io/docs/orm/prisma-client/queries/pagination#cursor-based-pagination)
|
|
578
|
+
* await db.user.findMany({
|
|
579
|
+
* cursor: { id: 10 },
|
|
580
|
+
* skip: 1,
|
|
581
|
+
* take: 10,
|
|
582
|
+
* orderBy: { id: 'asc' },
|
|
583
|
+
* });
|
|
584
|
+
*
|
|
585
|
+
* // distinct
|
|
586
|
+
* await db.user.findMany({
|
|
587
|
+
* distinct: ['name']
|
|
588
|
+
* });
|
|
589
|
+
*
|
|
590
|
+
* // count all relations
|
|
591
|
+
* await db.user.findMany({
|
|
592
|
+
* _count: true,
|
|
593
|
+
* }); // result: `{ _count: { posts: number; ... } }`
|
|
594
|
+
*
|
|
595
|
+
* // count selected relations
|
|
596
|
+
* await db.user.findMany({
|
|
597
|
+
* _count: { select: { posts: true } },
|
|
598
|
+
* }); // result: `{ _count: { posts: number } }`
|
|
599
|
+
* ```
|
|
600
|
+
*/
|
|
601
|
+
findMany<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
|
|
602
|
+
/**
|
|
603
|
+
* Returns a uniquely identified entity.
|
|
604
|
+
* @param args - query args
|
|
605
|
+
* @returns a single entity or null if not found
|
|
606
|
+
* @see {@link findMany}
|
|
607
|
+
*/
|
|
608
|
+
findUnique<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
|
|
609
|
+
/**
|
|
610
|
+
* Returns a uniquely identified entity or throws `NotFoundError` if not found.
|
|
611
|
+
* @param args - query args
|
|
612
|
+
* @returns a single entity
|
|
613
|
+
* @see {@link findMany}
|
|
614
|
+
*/
|
|
615
|
+
findUniqueOrThrow<T extends FindUniqueArgs<Schema, Model>>(args: SelectSubset<T, FindUniqueArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
616
|
+
/**
|
|
617
|
+
* Returns the first entity.
|
|
618
|
+
* @param args - query args
|
|
619
|
+
* @returns a single entity or null if not found
|
|
620
|
+
* @see {@link findMany}
|
|
621
|
+
*/
|
|
622
|
+
findFirst<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>> | null>;
|
|
623
|
+
/**
|
|
624
|
+
* Returns the first entity or throws `NotFoundError` if not found.
|
|
625
|
+
* @param args - query args
|
|
626
|
+
* @returns a single entity
|
|
627
|
+
* @see {@link findMany}
|
|
628
|
+
*/
|
|
629
|
+
findFirstOrThrow<T extends FindArgs<Schema, Model, true>>(args?: SelectSubset<T, FindArgs<Schema, Model, true>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
630
|
+
/**
|
|
631
|
+
* Creates a new entity.
|
|
632
|
+
* @param args - create args
|
|
633
|
+
* @returns the created entity
|
|
634
|
+
*
|
|
635
|
+
* @example
|
|
636
|
+
* ```ts
|
|
637
|
+
* // simple create
|
|
638
|
+
* await db.user.create({
|
|
639
|
+
* data: { name: 'Alex', email: 'alex@zenstack.dev' }
|
|
640
|
+
* });
|
|
641
|
+
*
|
|
642
|
+
* // nested create with relation
|
|
643
|
+
* await db.user.create({
|
|
644
|
+
* data: {
|
|
645
|
+
* email: 'alex@zenstack.dev',
|
|
646
|
+
* posts: { create: { title: 'Hello World' } }
|
|
647
|
+
* }
|
|
648
|
+
* });
|
|
649
|
+
*
|
|
650
|
+
* // you can use `select`, `omit`, and `include` to control
|
|
651
|
+
* // the fields returned by the query, as with `findMany`
|
|
652
|
+
* await db.user.create({
|
|
653
|
+
* data: {
|
|
654
|
+
* email: 'alex@zenstack.dev',
|
|
655
|
+
* posts: { create: { title: 'Hello World' } }
|
|
656
|
+
* },
|
|
657
|
+
* include: { posts: true }
|
|
658
|
+
* }); // result: `{ id: number; posts: Post[] }`
|
|
659
|
+
*
|
|
660
|
+
* // connect relations
|
|
661
|
+
* await db.user.create({
|
|
662
|
+
* data: {
|
|
663
|
+
* email: 'alex@zenstack.dev',
|
|
664
|
+
* posts: { connect: { id: 1 } }
|
|
665
|
+
* }
|
|
666
|
+
* });
|
|
667
|
+
*
|
|
668
|
+
* // connect relations, and create if not found
|
|
669
|
+
* await db.user.create({
|
|
670
|
+
* data: {
|
|
671
|
+
* email: 'alex@zenstack.dev',
|
|
672
|
+
* posts: {
|
|
673
|
+
* connectOrCreate: {
|
|
674
|
+
* where: { id: 1 },
|
|
675
|
+
* create: { title: 'Hello World' }
|
|
676
|
+
* }
|
|
677
|
+
* }
|
|
678
|
+
* }
|
|
679
|
+
* });
|
|
680
|
+
* ```
|
|
681
|
+
*/
|
|
682
|
+
create<T extends CreateArgs<Schema, Model>>(args: SelectSubset<T, CreateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
683
|
+
/**
|
|
684
|
+
* Creates multiple entities. Only scalar fields are allowed.
|
|
685
|
+
* @param args - create args
|
|
686
|
+
* @returns count of created entities: `{ count: number }`
|
|
687
|
+
*
|
|
688
|
+
* @example
|
|
689
|
+
* ```ts
|
|
690
|
+
* // create multiple entities
|
|
691
|
+
* await db.user.createMany({
|
|
692
|
+
* data: [
|
|
693
|
+
* { name: 'Alex', email: 'alex@zenstack.dev' },
|
|
694
|
+
* { name: 'John', email: 'john@zenstack.dev' }
|
|
695
|
+
* ]
|
|
696
|
+
* });
|
|
697
|
+
*
|
|
698
|
+
* // skip items that cause unique constraint violation
|
|
699
|
+
* await db.user.createMany({
|
|
700
|
+
* data: [
|
|
701
|
+
* { name: 'Alex', email: 'alex@zenstack.dev' },
|
|
702
|
+
* { name: 'John', email: 'john@zenstack.dev' }
|
|
703
|
+
* ],
|
|
704
|
+
* skipDuplicates: true
|
|
705
|
+
* });
|
|
706
|
+
* ```
|
|
707
|
+
*/
|
|
708
|
+
createMany<T extends CreateManyArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
|
|
709
|
+
/**
|
|
710
|
+
* Creates multiple entities and returns them.
|
|
711
|
+
* @param args - create args. See {@link createMany} for input. Use
|
|
712
|
+
* `select` and `omit` to control the fields returned.
|
|
713
|
+
* @returns the created entities
|
|
714
|
+
*
|
|
715
|
+
* @example
|
|
716
|
+
* ```ts
|
|
717
|
+
* // create multiple entities and return selected fields
|
|
718
|
+
* await db.user.createManyAndReturn({
|
|
719
|
+
* data: [
|
|
720
|
+
* { name: 'Alex', email: 'alex@zenstack.dev' },
|
|
721
|
+
* { name: 'John', email: 'john@zenstack.dev' }
|
|
722
|
+
* ],
|
|
723
|
+
* select: { id: true, email: true }
|
|
724
|
+
* });
|
|
725
|
+
* ```
|
|
726
|
+
*/
|
|
727
|
+
createManyAndReturn<T extends CreateManyAndReturnArgs<Schema, Model>>(args?: SelectSubset<T, CreateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
|
|
728
|
+
/**
|
|
729
|
+
* Updates a uniquely identified entity.
|
|
730
|
+
* @param args - update args. See {@link findMany} for how to control
|
|
731
|
+
* fields and relations returned.
|
|
732
|
+
* @returns the updated entity. Throws `NotFoundError` if the entity is not found.
|
|
733
|
+
*
|
|
734
|
+
* @example
|
|
735
|
+
* ```ts
|
|
736
|
+
* // update fields
|
|
737
|
+
* await db.user.update({
|
|
738
|
+
* where: { id: 1 },
|
|
739
|
+
* data: { name: 'Alex' }
|
|
740
|
+
* });
|
|
741
|
+
*
|
|
742
|
+
* // connect a relation
|
|
743
|
+
* await db.user.update({
|
|
744
|
+
* where: { id: 1 },
|
|
745
|
+
* data: { posts: { connect: { id: 1 } } }
|
|
746
|
+
* });
|
|
747
|
+
*
|
|
748
|
+
* // connect relation, and create if not found
|
|
749
|
+
* await db.user.update({
|
|
750
|
+
* where: { id: 1 },
|
|
751
|
+
* data: {
|
|
752
|
+
* posts: {
|
|
753
|
+
* connectOrCreate: {
|
|
754
|
+
* where: { id: 1 },
|
|
755
|
+
* create: { title: 'Hello World' }
|
|
756
|
+
* }
|
|
757
|
+
* }
|
|
758
|
+
* }
|
|
759
|
+
* });
|
|
760
|
+
*
|
|
761
|
+
* // create many related entities (only available for one-to-many relations)
|
|
762
|
+
* await db.user.update({
|
|
763
|
+
* where: { id: 1 },
|
|
764
|
+
* data: {
|
|
765
|
+
* posts: {
|
|
766
|
+
* createMany: {
|
|
767
|
+
* data: [{ title: 'Hello World' }, { title: 'Hello World 2' }],
|
|
768
|
+
* }
|
|
769
|
+
* }
|
|
770
|
+
* }
|
|
771
|
+
* });
|
|
772
|
+
*
|
|
773
|
+
* // disconnect a one-to-many relation
|
|
774
|
+
* await db.user.update({
|
|
775
|
+
* where: { id: 1 },
|
|
776
|
+
* data: { posts: { disconnect: { id: 1 } } }
|
|
777
|
+
* });
|
|
778
|
+
*
|
|
779
|
+
* // disconnect a one-to-one relation
|
|
780
|
+
* await db.user.update({
|
|
781
|
+
* where: { id: 1 },
|
|
782
|
+
* data: { profile: { disconnect: true } }
|
|
783
|
+
* });
|
|
784
|
+
*
|
|
785
|
+
* // replace a relation (only available for one-to-many relations)
|
|
786
|
+
* await db.user.update({
|
|
787
|
+
* where: { id: 1 },
|
|
788
|
+
* data: {
|
|
789
|
+
* posts: {
|
|
790
|
+
* set: [{ id: 1 }, { id: 2 }]
|
|
791
|
+
* }
|
|
792
|
+
* }
|
|
793
|
+
* });
|
|
794
|
+
*
|
|
795
|
+
* // update a relation
|
|
796
|
+
* await db.user.update({
|
|
797
|
+
* where: { id: 1 },
|
|
798
|
+
* data: {
|
|
799
|
+
* posts: {
|
|
800
|
+
* update: { where: { id: 1 }, data: { title: 'Hello World' } }
|
|
801
|
+
* }
|
|
802
|
+
* }
|
|
803
|
+
* });
|
|
804
|
+
*
|
|
805
|
+
* // upsert a relation
|
|
806
|
+
* await db.user.update({
|
|
807
|
+
* where: { id: 1 },
|
|
808
|
+
* data: {
|
|
809
|
+
* posts: {
|
|
810
|
+
* upsert: {
|
|
811
|
+
* where: { id: 1 },
|
|
812
|
+
* create: { title: 'Hello World' },
|
|
813
|
+
* update: { title: 'Hello World' }
|
|
814
|
+
* }
|
|
815
|
+
* }
|
|
816
|
+
* }
|
|
817
|
+
* });
|
|
818
|
+
*
|
|
819
|
+
* // update many related entities (only available for one-to-many relations)
|
|
820
|
+
* await db.user.update({
|
|
821
|
+
* where: { id: 1 },
|
|
822
|
+
* data: {
|
|
823
|
+
* posts: {
|
|
824
|
+
* updateMany: {
|
|
825
|
+
* where: { published: true },
|
|
826
|
+
* data: { title: 'Hello World' }
|
|
827
|
+
* }
|
|
828
|
+
* }
|
|
829
|
+
* }
|
|
830
|
+
* });
|
|
831
|
+
*
|
|
832
|
+
* // delete a one-to-many relation
|
|
833
|
+
* await db.user.update({
|
|
834
|
+
* where: { id: 1 },
|
|
835
|
+
* data: { posts: { delete: { id: 1 } } }
|
|
836
|
+
* });
|
|
837
|
+
*
|
|
838
|
+
* // delete a one-to-one relation
|
|
839
|
+
* await db.user.update({
|
|
840
|
+
* where: { id: 1 },
|
|
841
|
+
* data: { profile: { delete: true } }
|
|
842
|
+
* });
|
|
843
|
+
* ```
|
|
844
|
+
*/
|
|
845
|
+
update<T extends UpdateArgs<Schema, Model>>(args: SelectSubset<T, UpdateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
846
|
+
/**
|
|
847
|
+
* Updates multiple entities.
|
|
848
|
+
* @param args - update args. Only scalar fields are allowed for data.
|
|
849
|
+
* @returns count of updated entities: `{ count: number }`
|
|
850
|
+
*
|
|
851
|
+
* @example
|
|
852
|
+
* ```ts
|
|
853
|
+
* // update many entities
|
|
854
|
+
* await db.user.updateMany({
|
|
855
|
+
* where: { email: { endsWith: '@zenstack.dev' } },
|
|
856
|
+
* data: { role: 'ADMIN' }
|
|
857
|
+
* });
|
|
858
|
+
*
|
|
859
|
+
* // limit the number of updated entities
|
|
860
|
+
* await db.user.updateMany({
|
|
861
|
+
* where: { email: { endsWith: '@zenstack.dev' } },
|
|
862
|
+
* data: { role: 'ADMIN' },
|
|
863
|
+
* limit: 10
|
|
864
|
+
* });
|
|
865
|
+
*/
|
|
866
|
+
updateMany<T extends UpdateManyArgs<Schema, Model>>(args: Subset<T, UpdateManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
|
|
867
|
+
/**
|
|
868
|
+
* Updates multiple entities and returns them.
|
|
869
|
+
* @param args - update args. Only scalar fields are allowed for data.
|
|
870
|
+
* @returns the updated entities
|
|
871
|
+
*
|
|
872
|
+
* @example
|
|
873
|
+
* ```ts
|
|
874
|
+
* // update many entities and return selected fields
|
|
875
|
+
* await db.user.updateManyAndReturn({
|
|
876
|
+
* where: { email: { endsWith: '@zenstack.dev' } },
|
|
877
|
+
* data: { role: 'ADMIN' },
|
|
878
|
+
* select: { id: true, email: true }
|
|
879
|
+
* }); // result: `Array<{ id: string; email: string }>`
|
|
880
|
+
*
|
|
881
|
+
* // limit the number of updated entities
|
|
882
|
+
* await db.user.updateManyAndReturn({
|
|
883
|
+
* where: { email: { endsWith: '@zenstack.dev' } },
|
|
884
|
+
* data: { role: 'ADMIN' },
|
|
885
|
+
* limit: 10
|
|
886
|
+
* });
|
|
887
|
+
* ```
|
|
888
|
+
*/
|
|
889
|
+
updateManyAndReturn<T extends UpdateManyAndReturnArgs<Schema, Model>>(args: Subset<T, UpdateManyAndReturnArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>[]>;
|
|
890
|
+
/**
|
|
891
|
+
* Creates or updates an entity.
|
|
892
|
+
* @param args - upsert args
|
|
893
|
+
* @returns the upserted entity
|
|
894
|
+
*
|
|
895
|
+
* @example
|
|
896
|
+
* ```ts
|
|
897
|
+
* // upsert an entity
|
|
898
|
+
* await db.user.upsert({
|
|
899
|
+
* // `where` clause is used to find the entity
|
|
900
|
+
* where: { id: 1 },
|
|
901
|
+
* // `create` clause is used if the entity is not found
|
|
902
|
+
* create: { email: 'alex@zenstack.dev', name: 'Alex' },
|
|
903
|
+
* // `update` clause is used if the entity is found
|
|
904
|
+
* update: { name: 'Alex-new' },
|
|
905
|
+
* // `select` and `omit` can be used to control the returned fields
|
|
906
|
+
* ...
|
|
907
|
+
* });
|
|
908
|
+
* ```
|
|
909
|
+
*/
|
|
910
|
+
upsert<T extends UpsertArgs<Schema, Model>>(args: SelectSubset<T, UpsertArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
911
|
+
/**
|
|
912
|
+
* Deletes a uniquely identifiable entity.
|
|
913
|
+
* @param args - delete args
|
|
914
|
+
* @returns the deleted entity. Throws `NotFoundError` if the entity is not found.
|
|
915
|
+
*
|
|
916
|
+
* @example
|
|
917
|
+
* ```ts
|
|
918
|
+
* // delete an entity
|
|
919
|
+
* await db.user.delete({
|
|
920
|
+
* where: { id: 1 }
|
|
921
|
+
* });
|
|
922
|
+
*
|
|
923
|
+
* // delete an entity and return selected fields
|
|
924
|
+
* await db.user.delete({
|
|
925
|
+
* where: { id: 1 },
|
|
926
|
+
* select: { id: true, email: true }
|
|
927
|
+
* }); // result: `{ id: string; email: string }`
|
|
928
|
+
* ```
|
|
929
|
+
*/
|
|
930
|
+
delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
931
|
+
/**
|
|
932
|
+
* Deletes multiple entities.
|
|
933
|
+
* @param args - delete args
|
|
934
|
+
* @returns count of deleted entities: `{ count: number }`
|
|
935
|
+
*
|
|
936
|
+
* @example
|
|
937
|
+
* ```ts
|
|
938
|
+
* // delete many entities
|
|
939
|
+
* await db.user.deleteMany({
|
|
940
|
+
* where: { email: { endsWith: '@zenstack.dev' } }
|
|
941
|
+
* });
|
|
942
|
+
*
|
|
943
|
+
* // limit the number of deleted entities
|
|
944
|
+
* await db.user.deleteMany({
|
|
945
|
+
* where: { email: { endsWith: '@zenstack.dev' } },
|
|
946
|
+
* limit: 10
|
|
947
|
+
* });
|
|
948
|
+
* ```
|
|
949
|
+
*/
|
|
950
|
+
deleteMany<T extends DeleteManyArgs<Schema, Model>>(args?: Subset<T, DeleteManyArgs<Schema, Model>>): ZenStackPromise<Schema, BatchResult>;
|
|
951
|
+
/**
|
|
952
|
+
* Counts rows or field values.
|
|
953
|
+
* @param args - count args
|
|
954
|
+
* @returns `number`, or an object containing count of selected relations
|
|
955
|
+
*
|
|
956
|
+
* @example
|
|
957
|
+
* ```ts
|
|
958
|
+
* // count all
|
|
959
|
+
* await db.user.count();
|
|
960
|
+
*
|
|
961
|
+
* // count with a filter
|
|
962
|
+
* await db.user.count({ where: { email: { endsWith: '@zenstack.dev' } } });
|
|
963
|
+
*
|
|
964
|
+
* // count rows and field values
|
|
965
|
+
* await db.user.count({
|
|
966
|
+
* select: { _all: true, email: true }
|
|
967
|
+
* }); // result: `{ _all: number, email: number }`
|
|
968
|
+
*/
|
|
969
|
+
count<T extends CountArgs<Schema, Model>>(args?: Subset<T, CountArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<CountResult<Schema, Model, T>>>;
|
|
970
|
+
/**
|
|
971
|
+
* Aggregates rows.
|
|
972
|
+
* @param args - aggregation args
|
|
973
|
+
* @returns an object containing aggregated values
|
|
974
|
+
*
|
|
975
|
+
* @example
|
|
976
|
+
* ```ts
|
|
977
|
+
* // aggregate rows
|
|
978
|
+
* await db.profile.aggregate({
|
|
979
|
+
* where: { email: { endsWith: '@zenstack.dev' } },
|
|
980
|
+
* _count: true,
|
|
981
|
+
* _avg: { age: true },
|
|
982
|
+
* _sum: { age: true },
|
|
983
|
+
* _min: { age: true },
|
|
984
|
+
* _max: { age: true }
|
|
985
|
+
* }); // result: `{ _count: number, _avg: { age: number }, ... }`
|
|
986
|
+
*/
|
|
987
|
+
aggregate<T extends AggregateArgs<Schema, Model>>(args: Subset<T, AggregateArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<AggregateResult<Schema, Model, T>>>;
|
|
988
|
+
/**
|
|
989
|
+
* Groups rows by columns.
|
|
990
|
+
* @param args - groupBy args
|
|
991
|
+
* @returns an object containing grouped values
|
|
992
|
+
*
|
|
993
|
+
* @example
|
|
994
|
+
* ```ts
|
|
995
|
+
* // group by a field
|
|
996
|
+
* await db.profile.groupBy({
|
|
997
|
+
* by: 'country',
|
|
998
|
+
* _count: true
|
|
999
|
+
* }); // result: `Array<{ country: string, _count: number }>`
|
|
1000
|
+
*
|
|
1001
|
+
* // group by multiple fields
|
|
1002
|
+
* await db.profile.groupBy({
|
|
1003
|
+
* by: ['country', 'city'],
|
|
1004
|
+
* _count: true
|
|
1005
|
+
* }); // result: `Array<{ country: string, city: string, _count: number }>`
|
|
1006
|
+
*
|
|
1007
|
+
* // group by with sorting, the `orderBy` fields must be either an aggregation
|
|
1008
|
+
* // or a field used in the `by` list
|
|
1009
|
+
* await db.profile.groupBy({
|
|
1010
|
+
* by: 'country',
|
|
1011
|
+
* orderBy: { country: 'desc' }
|
|
1012
|
+
* });
|
|
1013
|
+
*
|
|
1014
|
+
* // group by with having (post-aggregation filter), the fields used in `having` must
|
|
1015
|
+
* // be either an aggregation, or a field used in the `by` list
|
|
1016
|
+
* await db.profile.groupBy({
|
|
1017
|
+
* by: 'country',
|
|
1018
|
+
* having: { country: 'US', age: { _avg: { gte: 18 } } }
|
|
1019
|
+
* });
|
|
1020
|
+
*/
|
|
1021
|
+
groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
|
|
1022
|
+
};
|
|
1023
|
+
type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<AllModelOperations<Schema, Model>, IsDelegateModel<Schema, Model> extends true ? 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' : never>;
|
|
6
1024
|
|
|
7
1025
|
/**
|
|
8
1026
|
* ZenStack ORM client.
|
|
9
1027
|
*/
|
|
10
1028
|
declare const ZenStackClient: ClientConstructor;
|
|
11
1029
|
|
|
1030
|
+
declare function getCrudDialect<Schema extends SchemaDef>(schema: Schema, options: ClientOptions<Schema>): BaseCrudDialect<Schema>;
|
|
1031
|
+
|
|
1032
|
+
/**
|
|
1033
|
+
* Base for all ZenStack runtime errors.
|
|
1034
|
+
*/
|
|
1035
|
+
declare class ZenStackError extends Error {
|
|
1036
|
+
}
|
|
12
1037
|
/**
|
|
13
1038
|
* Error thrown when input validation fails.
|
|
14
1039
|
*/
|
|
15
|
-
declare class InputValidationError extends
|
|
1040
|
+
declare class InputValidationError extends ZenStackError {
|
|
16
1041
|
constructor(message: string, cause?: unknown);
|
|
17
1042
|
}
|
|
18
1043
|
/**
|
|
19
1044
|
* Error thrown when a query fails.
|
|
20
1045
|
*/
|
|
21
|
-
declare class QueryError extends
|
|
1046
|
+
declare class QueryError extends ZenStackError {
|
|
22
1047
|
constructor(message: string, cause?: unknown);
|
|
23
1048
|
}
|
|
24
1049
|
/**
|
|
25
1050
|
* Error thrown when an internal error occurs.
|
|
26
1051
|
*/
|
|
27
|
-
declare class InternalError extends
|
|
1052
|
+
declare class InternalError extends ZenStackError {
|
|
28
1053
|
}
|
|
29
1054
|
/**
|
|
30
1055
|
* Error thrown when an entity is not found.
|
|
31
1056
|
*/
|
|
32
|
-
declare class NotFoundError extends
|
|
33
|
-
constructor(model: string);
|
|
1057
|
+
declare class NotFoundError extends ZenStackError {
|
|
1058
|
+
constructor(model: string, details?: string);
|
|
1059
|
+
}
|
|
1060
|
+
/**
|
|
1061
|
+
* Reason code for policy rejection.
|
|
1062
|
+
*/
|
|
1063
|
+
declare enum RejectedByPolicyReason {
|
|
1064
|
+
/**
|
|
1065
|
+
* Rejected because the operation is not allowed by policy.
|
|
1066
|
+
*/
|
|
1067
|
+
NO_ACCESS = "no-access",
|
|
1068
|
+
/**
|
|
1069
|
+
* Rejected because the result cannot be read back after mutation due to policy.
|
|
1070
|
+
*/
|
|
1071
|
+
CANNOT_READ_BACK = "cannot-read-back",
|
|
1072
|
+
/**
|
|
1073
|
+
* Other reasons.
|
|
1074
|
+
*/
|
|
1075
|
+
OTHER = "other"
|
|
1076
|
+
}
|
|
1077
|
+
/**
|
|
1078
|
+
* Error thrown when an operation is rejected by access policy.
|
|
1079
|
+
*/
|
|
1080
|
+
declare class RejectedByPolicyError extends ZenStackError {
|
|
1081
|
+
readonly model: string | undefined;
|
|
1082
|
+
readonly reason: RejectedByPolicyReason;
|
|
1083
|
+
constructor(model: string | undefined, reason?: RejectedByPolicyReason, message?: string);
|
|
1084
|
+
}
|
|
1085
|
+
|
|
1086
|
+
declare function hasModel(schema: SchemaDef, model: string): boolean;
|
|
1087
|
+
declare function getModel(schema: SchemaDef, model: string): ModelDef | undefined;
|
|
1088
|
+
declare function getTypeDef(schema: SchemaDef, type: string): _zenstackhq_sdk_schema.TypeDefDef | undefined;
|
|
1089
|
+
declare function requireModel(schema: SchemaDef, model: string): ModelDef;
|
|
1090
|
+
declare function getField(schema: SchemaDef, model: string, field: string): FieldDef | undefined;
|
|
1091
|
+
declare function requireField(schema: SchemaDef, modelOrType: string, field: string): FieldDef;
|
|
1092
|
+
declare function getIdFields<Schema extends SchemaDef>(schema: SchemaDef, model: GetModels<Schema>): string[] | undefined;
|
|
1093
|
+
declare function requireIdFields(schema: SchemaDef, model: string): string[];
|
|
1094
|
+
declare function getRelationForeignKeyFieldPairs(schema: SchemaDef, model: string, relationField: string): {
|
|
1095
|
+
keyPairs: {
|
|
1096
|
+
fk: string;
|
|
1097
|
+
pk: string;
|
|
1098
|
+
}[];
|
|
1099
|
+
ownedByModel: boolean;
|
|
1100
|
+
};
|
|
1101
|
+
declare function isScalarField(schema: SchemaDef, model: string, field: string): boolean;
|
|
1102
|
+
declare function isForeignKeyField(schema: SchemaDef, model: string, field: string): boolean;
|
|
1103
|
+
declare function isRelationField(schema: SchemaDef, model: string, field: string): boolean;
|
|
1104
|
+
declare function isInheritedField(schema: SchemaDef, model: string, field: string): boolean;
|
|
1105
|
+
declare function getUniqueFields(schema: SchemaDef, model: string): ({
|
|
1106
|
+
name: string;
|
|
1107
|
+
def: FieldDef;
|
|
1108
|
+
} | {
|
|
1109
|
+
name: string;
|
|
1110
|
+
defs: Record<string, FieldDef>;
|
|
1111
|
+
})[];
|
|
1112
|
+
declare function getIdValues(schema: SchemaDef, model: string, data: any): Record<string, any>;
|
|
1113
|
+
declare function fieldHasDefaultValue(fieldDef: FieldDef): boolean | undefined;
|
|
1114
|
+
declare function isEnum(schema: SchemaDef, type: string): boolean;
|
|
1115
|
+
declare function getEnum(schema: SchemaDef, type: string): _zenstackhq_sdk_schema.EnumDef | undefined;
|
|
1116
|
+
declare function buildJoinPairs(schema: SchemaDef, model: string, modelAlias: string, relationField: string, relationModelAlias: string): [string, string][];
|
|
1117
|
+
declare function makeDefaultOrderBy<Schema extends SchemaDef>(schema: SchemaDef, model: string): OrderBy<Schema, Extract<keyof Schema["models"], string>, true, false>[];
|
|
1118
|
+
declare function getManyToManyRelation(schema: SchemaDef, model: string, field: string): {
|
|
1119
|
+
parentFkName: string;
|
|
1120
|
+
parentPKName: string;
|
|
1121
|
+
otherModel: string;
|
|
1122
|
+
otherField: string;
|
|
1123
|
+
otherFkName: string;
|
|
1124
|
+
otherPKName: string;
|
|
1125
|
+
joinTable: string;
|
|
1126
|
+
} | undefined;
|
|
1127
|
+
/**
|
|
1128
|
+
* Convert filter like `{ id1_id2: { id1: 1, id2: 1 } }` to `{ id1: 1, id2: 1 }`
|
|
1129
|
+
*/
|
|
1130
|
+
declare function flattenCompoundUniqueFilters(schema: SchemaDef, model: string, filter: unknown): any;
|
|
1131
|
+
declare function ensureArray<T>(value: T | T[]): T[];
|
|
1132
|
+
declare function safeJSONStringify(value: unknown): string;
|
|
1133
|
+
declare function extractIdFields(entity: any, schema: SchemaDef, model: string): {
|
|
1134
|
+
[k: string]: unknown;
|
|
1135
|
+
};
|
|
1136
|
+
declare function getDiscriminatorField(schema: SchemaDef, model: string): string | undefined;
|
|
1137
|
+
declare function getDelegateDescendantModels(schema: SchemaDef, model: string, collected?: Set<ModelDef>): ModelDef[];
|
|
1138
|
+
declare function aggregate(eb: ExpressionBuilder<any, any>, expr: Expression<any>, op: AGGREGATE_OPERATORS): kysely.AggregateFunctionBuilder<any, any, string | number | bigint>;
|
|
1139
|
+
/**
|
|
1140
|
+
* Strips alias from the node if it exists.
|
|
1141
|
+
*/
|
|
1142
|
+
declare function stripAlias(node: OperationNode): {
|
|
1143
|
+
alias: OperationNode;
|
|
1144
|
+
node: OperationNode;
|
|
1145
|
+
} | {
|
|
1146
|
+
alias: undefined;
|
|
1147
|
+
node: OperationNode;
|
|
1148
|
+
};
|
|
1149
|
+
/**
|
|
1150
|
+
* Extracts model name from an OperationNode.
|
|
1151
|
+
*/
|
|
1152
|
+
declare function extractModelName(node: OperationNode): string | undefined;
|
|
1153
|
+
/**
|
|
1154
|
+
* Extracts field name from an OperationNode.
|
|
1155
|
+
*/
|
|
1156
|
+
declare function extractFieldName(node: OperationNode): string | undefined;
|
|
1157
|
+
|
|
1158
|
+
declare const queryUtils_aggregate: typeof aggregate;
|
|
1159
|
+
declare const queryUtils_buildJoinPairs: typeof buildJoinPairs;
|
|
1160
|
+
declare const queryUtils_ensureArray: typeof ensureArray;
|
|
1161
|
+
declare const queryUtils_extractFieldName: typeof extractFieldName;
|
|
1162
|
+
declare const queryUtils_extractIdFields: typeof extractIdFields;
|
|
1163
|
+
declare const queryUtils_extractModelName: typeof extractModelName;
|
|
1164
|
+
declare const queryUtils_fieldHasDefaultValue: typeof fieldHasDefaultValue;
|
|
1165
|
+
declare const queryUtils_flattenCompoundUniqueFilters: typeof flattenCompoundUniqueFilters;
|
|
1166
|
+
declare const queryUtils_getDelegateDescendantModels: typeof getDelegateDescendantModels;
|
|
1167
|
+
declare const queryUtils_getDiscriminatorField: typeof getDiscriminatorField;
|
|
1168
|
+
declare const queryUtils_getEnum: typeof getEnum;
|
|
1169
|
+
declare const queryUtils_getField: typeof getField;
|
|
1170
|
+
declare const queryUtils_getIdFields: typeof getIdFields;
|
|
1171
|
+
declare const queryUtils_getIdValues: typeof getIdValues;
|
|
1172
|
+
declare const queryUtils_getManyToManyRelation: typeof getManyToManyRelation;
|
|
1173
|
+
declare const queryUtils_getModel: typeof getModel;
|
|
1174
|
+
declare const queryUtils_getRelationForeignKeyFieldPairs: typeof getRelationForeignKeyFieldPairs;
|
|
1175
|
+
declare const queryUtils_getTypeDef: typeof getTypeDef;
|
|
1176
|
+
declare const queryUtils_getUniqueFields: typeof getUniqueFields;
|
|
1177
|
+
declare const queryUtils_hasModel: typeof hasModel;
|
|
1178
|
+
declare const queryUtils_isEnum: typeof isEnum;
|
|
1179
|
+
declare const queryUtils_isForeignKeyField: typeof isForeignKeyField;
|
|
1180
|
+
declare const queryUtils_isInheritedField: typeof isInheritedField;
|
|
1181
|
+
declare const queryUtils_isRelationField: typeof isRelationField;
|
|
1182
|
+
declare const queryUtils_isScalarField: typeof isScalarField;
|
|
1183
|
+
declare const queryUtils_makeDefaultOrderBy: typeof makeDefaultOrderBy;
|
|
1184
|
+
declare const queryUtils_requireField: typeof requireField;
|
|
1185
|
+
declare const queryUtils_requireIdFields: typeof requireIdFields;
|
|
1186
|
+
declare const queryUtils_requireModel: typeof requireModel;
|
|
1187
|
+
declare const queryUtils_safeJSONStringify: typeof safeJSONStringify;
|
|
1188
|
+
declare const queryUtils_stripAlias: typeof stripAlias;
|
|
1189
|
+
declare namespace queryUtils {
|
|
1190
|
+
export { queryUtils_aggregate as aggregate, queryUtils_buildJoinPairs as buildJoinPairs, queryUtils_ensureArray as ensureArray, queryUtils_extractFieldName as extractFieldName, queryUtils_extractIdFields as extractIdFields, queryUtils_extractModelName as extractModelName, queryUtils_fieldHasDefaultValue as fieldHasDefaultValue, queryUtils_flattenCompoundUniqueFilters as flattenCompoundUniqueFilters, queryUtils_getDelegateDescendantModels as getDelegateDescendantModels, queryUtils_getDiscriminatorField as getDiscriminatorField, queryUtils_getEnum as getEnum, queryUtils_getField as getField, queryUtils_getIdFields as getIdFields, queryUtils_getIdValues as getIdValues, queryUtils_getManyToManyRelation as getManyToManyRelation, queryUtils_getModel as getModel, queryUtils_getRelationForeignKeyFieldPairs as getRelationForeignKeyFieldPairs, queryUtils_getTypeDef as getTypeDef, queryUtils_getUniqueFields as getUniqueFields, queryUtils_hasModel as hasModel, queryUtils_isEnum as isEnum, queryUtils_isForeignKeyField as isForeignKeyField, queryUtils_isInheritedField as isInheritedField, queryUtils_isRelationField as isRelationField, queryUtils_isScalarField as isScalarField, queryUtils_makeDefaultOrderBy as makeDefaultOrderBy, queryUtils_requireField as requireField, queryUtils_requireIdFields as requireIdFields, queryUtils_requireModel as requireModel, queryUtils_safeJSONStringify as safeJSONStringify, queryUtils_stripAlias as stripAlias };
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
declare class DefaultOperationNodeVisitor extends OperationNodeVisitor {
|
|
1194
|
+
protected defaultVisit(node: OperationNode): void;
|
|
1195
|
+
protected visitSelectQuery(node: SelectQueryNode): void;
|
|
1196
|
+
protected visitSelection(node: SelectionNode): void;
|
|
1197
|
+
protected visitColumn(node: ColumnNode): void;
|
|
1198
|
+
protected visitAlias(node: AliasNode): void;
|
|
1199
|
+
protected visitTable(node: TableNode): void;
|
|
1200
|
+
protected visitFrom(node: FromNode): void;
|
|
1201
|
+
protected visitReference(node: ReferenceNode): void;
|
|
1202
|
+
protected visitAnd(node: AndNode): void;
|
|
1203
|
+
protected visitOr(node: OrNode): void;
|
|
1204
|
+
protected visitValueList(node: ValueListNode): void;
|
|
1205
|
+
protected visitParens(node: ParensNode): void;
|
|
1206
|
+
protected visitJoin(node: JoinNode): void;
|
|
1207
|
+
protected visitRaw(node: RawNode): void;
|
|
1208
|
+
protected visitWhere(node: WhereNode): void;
|
|
1209
|
+
protected visitInsertQuery(node: InsertQueryNode): void;
|
|
1210
|
+
protected visitDeleteQuery(node: DeleteQueryNode): void;
|
|
1211
|
+
protected visitReturning(node: ReturningNode): void;
|
|
1212
|
+
protected visitCreateTable(node: CreateTableNode): void;
|
|
1213
|
+
protected visitAddColumn(node: AddColumnNode): void;
|
|
1214
|
+
protected visitColumnDefinition(node: ColumnDefinitionNode): void;
|
|
1215
|
+
protected visitDropTable(node: DropTableNode): void;
|
|
1216
|
+
protected visitOrderBy(node: OrderByNode): void;
|
|
1217
|
+
protected visitOrderByItem(node: OrderByItemNode): void;
|
|
1218
|
+
protected visitGroupBy(node: GroupByNode): void;
|
|
1219
|
+
protected visitGroupByItem(node: GroupByItemNode): void;
|
|
1220
|
+
protected visitUpdateQuery(node: UpdateQueryNode): void;
|
|
1221
|
+
protected visitColumnUpdate(node: ColumnUpdateNode): void;
|
|
1222
|
+
protected visitLimit(node: LimitNode): void;
|
|
1223
|
+
protected visitOffset(node: OffsetNode): void;
|
|
1224
|
+
protected visitOnConflict(node: OnConflictNode): void;
|
|
1225
|
+
protected visitOnDuplicateKey(node: OnDuplicateKeyNode): void;
|
|
1226
|
+
protected visitCheckConstraint(node: CheckConstraintNode): void;
|
|
1227
|
+
protected visitDataType(node: DataTypeNode): void;
|
|
1228
|
+
protected visitSelectAll(node: SelectAllNode): void;
|
|
1229
|
+
protected visitIdentifier(node: IdentifierNode): void;
|
|
1230
|
+
protected visitSchemableIdentifier(node: SchemableIdentifierNode): void;
|
|
1231
|
+
protected visitValue(node: ValueNode): void;
|
|
1232
|
+
protected visitPrimitiveValueList(node: PrimitiveValueListNode): void;
|
|
1233
|
+
protected visitOperator(node: OperatorNode): void;
|
|
1234
|
+
protected visitCreateIndex(node: CreateIndexNode): void;
|
|
1235
|
+
protected visitDropIndex(node: DropIndexNode): void;
|
|
1236
|
+
protected visitList(node: ListNode): void;
|
|
1237
|
+
protected visitPrimaryKeyConstraint(node: PrimaryKeyConstraintNode): void;
|
|
1238
|
+
protected visitUniqueConstraint(node: UniqueConstraintNode): void;
|
|
1239
|
+
protected visitReferences(node: ReferencesNode): void;
|
|
1240
|
+
protected visitWith(node: WithNode): void;
|
|
1241
|
+
protected visitCommonTableExpression(node: CommonTableExpressionNode): void;
|
|
1242
|
+
protected visitCommonTableExpressionName(node: CommonTableExpressionNameNode): void;
|
|
1243
|
+
protected visitHaving(node: HavingNode): void;
|
|
1244
|
+
protected visitCreateSchema(node: CreateSchemaNode): void;
|
|
1245
|
+
protected visitDropSchema(node: DropSchemaNode): void;
|
|
1246
|
+
protected visitAlterTable(node: AlterTableNode): void;
|
|
1247
|
+
protected visitDropColumn(node: DropColumnNode): void;
|
|
1248
|
+
protected visitRenameColumn(node: RenameColumnNode): void;
|
|
1249
|
+
protected visitAlterColumn(node: AlterColumnNode): void;
|
|
1250
|
+
protected visitModifyColumn(node: ModifyColumnNode): void;
|
|
1251
|
+
protected visitAddConstraint(node: AddConstraintNode): void;
|
|
1252
|
+
protected visitDropConstraint(node: DropConstraintNode): void;
|
|
1253
|
+
protected visitForeignKeyConstraint(node: ForeignKeyConstraintNode): void;
|
|
1254
|
+
protected visitCreateView(node: CreateViewNode): void;
|
|
1255
|
+
protected visitDropView(node: DropViewNode): void;
|
|
1256
|
+
protected visitGenerated(node: GeneratedNode): void;
|
|
1257
|
+
protected visitDefaultValue(node: DefaultValueNode): void;
|
|
1258
|
+
protected visitOn(node: OnNode): void;
|
|
1259
|
+
protected visitValues(node: ValuesNode): void;
|
|
1260
|
+
protected visitSelectModifier(node: SelectModifierNode): void;
|
|
1261
|
+
protected visitCreateType(node: CreateTypeNode): void;
|
|
1262
|
+
protected visitDropType(node: DropTypeNode): void;
|
|
1263
|
+
protected visitExplain(node: ExplainNode): void;
|
|
1264
|
+
protected visitDefaultInsertValue(node: DefaultInsertValueNode): void;
|
|
1265
|
+
protected visitAggregateFunction(node: AggregateFunctionNode): void;
|
|
1266
|
+
protected visitOver(node: OverNode): void;
|
|
1267
|
+
protected visitPartitionBy(node: PartitionByNode): void;
|
|
1268
|
+
protected visitPartitionByItem(node: PartitionByItemNode): void;
|
|
1269
|
+
protected visitSetOperation(node: SetOperationNode): void;
|
|
1270
|
+
protected visitBinaryOperation(node: BinaryOperationNode): void;
|
|
1271
|
+
protected visitUnaryOperation(node: UnaryOperationNode): void;
|
|
1272
|
+
protected visitUsing(node: UsingNode): void;
|
|
1273
|
+
protected visitFunction(node: FunctionNode): void;
|
|
1274
|
+
protected visitCase(node: CaseNode): void;
|
|
1275
|
+
protected visitWhen(node: WhenNode): void;
|
|
1276
|
+
protected visitJSONReference(node: JSONReferenceNode): void;
|
|
1277
|
+
protected visitJSONPath(node: JSONPathNode): void;
|
|
1278
|
+
protected visitJSONPathLeg(node: JSONPathLegNode): void;
|
|
1279
|
+
protected visitJSONOperatorChain(node: JSONOperatorChainNode): void;
|
|
1280
|
+
protected visitTuple(node: TupleNode): void;
|
|
1281
|
+
protected visitMergeQuery(node: MergeQueryNode): void;
|
|
1282
|
+
protected visitMatched(node: MatchedNode): void;
|
|
1283
|
+
protected visitAddIndex(node: AddIndexNode): void;
|
|
1284
|
+
protected visitCast(node: CastNode): void;
|
|
1285
|
+
protected visitFetch(node: FetchNode): void;
|
|
1286
|
+
protected visitTop(node: TopNode): void;
|
|
1287
|
+
protected visitOutput(node: OutputNode): void;
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
type kyselyUtils_DefaultOperationNodeVisitor = DefaultOperationNodeVisitor;
|
|
1291
|
+
declare const kyselyUtils_DefaultOperationNodeVisitor: typeof DefaultOperationNodeVisitor;
|
|
1292
|
+
declare namespace kyselyUtils {
|
|
1293
|
+
export { kyselyUtils_DefaultOperationNodeVisitor as DefaultOperationNodeVisitor };
|
|
1294
|
+
}
|
|
1295
|
+
|
|
1296
|
+
declare class ExpressionVisitor {
|
|
1297
|
+
visit(expr: Expression$1): void;
|
|
1298
|
+
protected visitLiteral(_e: LiteralExpression): void;
|
|
1299
|
+
protected visitArray(e: ArrayExpression): void;
|
|
1300
|
+
protected visitField(_e: FieldExpression): void;
|
|
1301
|
+
protected visitMember(e: MemberExpression): void;
|
|
1302
|
+
protected visitBinary(e: BinaryExpression): void;
|
|
1303
|
+
protected visitUnary(e: UnaryExpression): void;
|
|
1304
|
+
protected visitCall(e: CallExpression): void;
|
|
1305
|
+
protected visitThis(_e: ThisExpression): void;
|
|
1306
|
+
protected visitNull(_e: NullExpression): void;
|
|
1307
|
+
}
|
|
1308
|
+
|
|
1309
|
+
type schemaUtils_ExpressionVisitor = ExpressionVisitor;
|
|
1310
|
+
declare const schemaUtils_ExpressionVisitor: typeof ExpressionVisitor;
|
|
1311
|
+
declare namespace schemaUtils {
|
|
1312
|
+
export { schemaUtils_ExpressionVisitor as ExpressionVisitor };
|
|
34
1313
|
}
|
|
35
1314
|
|
|
36
|
-
export { ClientConstructor, InputValidationError, InternalError, NotFoundError, QueryError, ZenStackClient };
|
|
1315
|
+
export { type AfterEntityMutationCallback, AggregateArgs, AggregateResult, type AllModelOperations, BaseCrudDialect, BatchResult, type BeforeEntityMutationCallback, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, CountArgs, CountResult, CreateArgs, CreateManyAndReturnArgs, CreateManyArgs, type CoreCrudOperation as CrudOperation, DeleteArgs, DeleteManyArgs, type EntityMutationHooksDef, FindArgs, FindUniqueArgs, GroupByArgs, GroupByResult, type HasComputedFields, type HasProcedures, InputValidationError, InternalError, kyselyUtils as KyselyUtils, type ModelOperations, ModelResult, NotFoundError, type OnKyselyQueryArgs, type OnKyselyQueryCallback, OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureFunc, type Procedures, type ProceduresOptions, type ProceedKyselyQueryFunction, QueryError, queryUtils as QueryUtils, RejectedByPolicyError, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, SelectSubset, Subset, ToKysely, type TransactionClientContract, TransactionIsolationLevel, UpdateArgs, UpdateManyAndReturnArgs, UpdateManyArgs, UpsertArgs, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, ZenStackError, type ZenStackPromise, definePlugin, getCrudDialect };
|