@zenstackhq/orm 3.1.0 → 3.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +244 -48
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +238 -27
- package/dist/index.d.ts +238 -27
- package/dist/index.js +243 -48
- package/dist/index.js.map +1 -1
- package/package.json +7 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import Decimal from 'decimal.js';
|
|
2
1
|
import * as _zenstackhq_schema from '@zenstackhq/schema';
|
|
3
2
|
import { SchemaDef, BuiltinType, GetModels, FieldDef, ModelDef, DataSourceProviderType, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, GetModel, ProcedureDef, NonRelationFields, GetEnums, GetEnum, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetTypeDefFieldType, TypeDefFieldIsArray, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, IsDelegateModel, Expression as Expression$1, LiteralExpression, ArrayExpression, FieldExpression, MemberExpression, BinaryExpression, UnaryExpression, CallExpression, ThisExpression, NullExpression } from '@zenstackhq/schema';
|
|
4
3
|
import * as kysely from 'kysely';
|
|
5
4
|
import { OperationNodeVisitor, OperationNode, SelectQueryNode, SelectionNode, ColumnNode, AliasNode, TableNode, FromNode, ReferenceNode, AndNode, OrNode, ValueListNode, ParensNode, JoinNode, RawNode, WhereNode, InsertQueryNode, DeleteQueryNode, ReturningNode, CreateTableNode, AddColumnNode, ColumnDefinitionNode, DropTableNode, OrderByNode, OrderByItemNode, GroupByNode, GroupByItemNode, UpdateQueryNode, ColumnUpdateNode, LimitNode, OffsetNode, OnConflictNode, OnDuplicateKeyNode, CheckConstraintNode, DataTypeNode, SelectAllNode, IdentifierNode, SchemableIdentifierNode, ValueNode, PrimitiveValueListNode, OperatorNode, CreateIndexNode, DropIndexNode, ListNode, PrimaryKeyConstraintNode, UniqueConstraintNode, ReferencesNode, WithNode, CommonTableExpressionNode, CommonTableExpressionNameNode, HavingNode, CreateSchemaNode, DropSchemaNode, AlterTableNode, DropColumnNode, RenameColumnNode, AlterColumnNode, ModifyColumnNode, AddConstraintNode, DropConstraintNode, ForeignKeyConstraintNode, CreateViewNode, DropViewNode, GeneratedNode, DefaultValueNode, OnNode, ValuesNode, SelectModifierNode, CreateTypeNode, DropTypeNode, ExplainNode, DefaultInsertValueNode, AggregateFunctionNode, OverNode, PartitionByNode, PartitionByItemNode, SetOperationNode, BinaryOperationNode, UnaryOperationNode, UsingNode, FunctionNode, CaseNode, WhenNode, JSONReferenceNode, JSONPathNode, JSONPathLegNode, JSONOperatorChainNode, TupleNode, MergeQueryNode, MatchedNode, AddIndexNode, CastNode, FetchNode, TopNode, OutputNode, RenameConstraintNode, RefreshMaterializedViewNode, OrActionNode, CollateNode, Kysely, ExpressionBuilder, SelectQueryBuilder, Expression, SqlBool, ExpressionWrapper, Generated, QueryId, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig, OperandExpression } from 'kysely';
|
|
5
|
+
import Decimal from 'decimal.js';
|
|
6
|
+
import { z } from 'zod';
|
|
6
7
|
|
|
7
8
|
declare class DefaultOperationNodeVisitor extends OperationNodeVisitor {
|
|
8
9
|
protected defaultVisit(node: OperationNode): void;
|
|
@@ -154,6 +155,12 @@ type TypeMap = {
|
|
|
154
155
|
DateTime: Date;
|
|
155
156
|
Bytes: Uint8Array;
|
|
156
157
|
Json: JsonValue;
|
|
158
|
+
Null: null;
|
|
159
|
+
Object: Record<string, unknown>;
|
|
160
|
+
Any: unknown;
|
|
161
|
+
Unsupported: unknown;
|
|
162
|
+
Void: void;
|
|
163
|
+
Undefined: undefined;
|
|
157
164
|
};
|
|
158
165
|
type MapBaseType$1<T extends string> = T extends keyof TypeMap ? TypeMap[T] : unknown;
|
|
159
166
|
type OrArray<T, IF extends boolean = true> = IF extends true ? T | T[] : T;
|
|
@@ -196,7 +203,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
196
203
|
protected eb: ExpressionBuilder<any, any>;
|
|
197
204
|
constructor(schema: Schema, options: ClientOptions<Schema>);
|
|
198
205
|
transformPrimitive(value: unknown, _type: BuiltinType, _forArrayField: boolean): unknown;
|
|
199
|
-
transformOutput(value: unknown, _type: BuiltinType): unknown;
|
|
206
|
+
transformOutput(value: unknown, _type: BuiltinType, _array: boolean): unknown;
|
|
200
207
|
buildSelectModel(model: string, modelAlias: string): SelectQueryBuilder<any, any, {}>;
|
|
201
208
|
buildFilterSortTake(model: string, args: FindArgs<Schema, GetModels<Schema>, true>, query: SelectQueryBuilder<any, any, {}>, modelAlias: string): SelectQueryBuilder<any, any, {}>;
|
|
202
209
|
buildFilter(model: string, modelAlias: string, where: boolean | object | undefined): Expression<SqlBool>;
|
|
@@ -314,7 +321,122 @@ type WrapNull<T, Null> = Null extends true ? T | null : T;
|
|
|
314
321
|
type MapType$1<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = WrapNull<MapBaseType<GetModelFieldType<Schema, Model, Field>>, ModelFieldIsOptional<Schema, Model, Field>>;
|
|
315
322
|
type toKyselyFieldType<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends GetModelFields<Schema, Model>> = FieldHasDefault<Schema, Model, Field> extends true ? Generated<MapType$1<Schema, Model, Field>> : MapType$1<Schema, Model, Field>;
|
|
316
323
|
|
|
317
|
-
|
|
324
|
+
declare class InputValidator<Schema extends SchemaDef> {
|
|
325
|
+
private readonly client;
|
|
326
|
+
constructor(client: ClientContract<Schema>);
|
|
327
|
+
private get schema();
|
|
328
|
+
private get options();
|
|
329
|
+
private get extraValidationsEnabled();
|
|
330
|
+
validateProcedureInput(proc: string, input: unknown): unknown;
|
|
331
|
+
private makeProcedureParamSchema;
|
|
332
|
+
validateFindArgs(model: GetModels<Schema>, args: unknown, options: {
|
|
333
|
+
unique: boolean;
|
|
334
|
+
findOne: boolean;
|
|
335
|
+
}): FindArgs<Schema, GetModels<Schema>, true> | undefined;
|
|
336
|
+
validateExistsArgs(model: GetModels<Schema>, args: unknown): ExistsArgs<Schema, GetModels<Schema>> | undefined;
|
|
337
|
+
validateCreateArgs(model: GetModels<Schema>, args: unknown): CreateArgs<Schema, GetModels<Schema>>;
|
|
338
|
+
validateCreateManyArgs(model: GetModels<Schema>, args: unknown): CreateManyArgs<Schema, GetModels<Schema>>;
|
|
339
|
+
validateCreateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): CreateManyAndReturnArgs<Schema, GetModels<Schema>> | undefined;
|
|
340
|
+
validateUpdateArgs(model: GetModels<Schema>, args: unknown): UpdateArgs<Schema, GetModels<Schema>>;
|
|
341
|
+
validateUpdateManyArgs(model: GetModels<Schema>, args: unknown): UpdateManyArgs<Schema, GetModels<Schema>>;
|
|
342
|
+
validateUpdateManyAndReturnArgs(model: GetModels<Schema>, args: unknown): UpdateManyAndReturnArgs<Schema, GetModels<Schema>>;
|
|
343
|
+
validateUpsertArgs(model: GetModels<Schema>, args: unknown): UpsertArgs<Schema, GetModels<Schema>>;
|
|
344
|
+
validateDeleteArgs(model: GetModels<Schema>, args: unknown): DeleteArgs<Schema, GetModels<Schema>>;
|
|
345
|
+
validateDeleteManyArgs(model: GetModels<Schema>, args: unknown): DeleteManyArgs<Schema, GetModels<Schema>> | undefined;
|
|
346
|
+
validateCountArgs(model: GetModels<Schema>, args: unknown): CountArgs<Schema, GetModels<Schema>> | undefined;
|
|
347
|
+
validateAggregateArgs(model: GetModels<Schema>, args: unknown): AggregateArgs<Schema, GetModels<Schema>>;
|
|
348
|
+
validateGroupByArgs(model: GetModels<Schema>, args: unknown): GroupByArgs<Schema, GetModels<Schema>>;
|
|
349
|
+
private getSchemaCache;
|
|
350
|
+
private setSchemaCache;
|
|
351
|
+
private validate;
|
|
352
|
+
private makeFindSchema;
|
|
353
|
+
private makeExistsSchema;
|
|
354
|
+
private makeScalarSchema;
|
|
355
|
+
private makeEnumSchema;
|
|
356
|
+
private makeTypeDefSchema;
|
|
357
|
+
private makeWhereSchema;
|
|
358
|
+
private makeTypedJsonFilterSchema;
|
|
359
|
+
private isTypeDefType;
|
|
360
|
+
private makeEnumFilterSchema;
|
|
361
|
+
private makeArrayFilterSchema;
|
|
362
|
+
private internalMakeArrayFilterSchema;
|
|
363
|
+
private makePrimitiveFilterSchema;
|
|
364
|
+
private makeJsonValueSchema;
|
|
365
|
+
private makeJsonFilterSchema;
|
|
366
|
+
private makeDateTimeFilterSchema;
|
|
367
|
+
private makeBooleanFilterSchema;
|
|
368
|
+
private makeBytesFilterSchema;
|
|
369
|
+
private makeCommonPrimitiveFilterComponents;
|
|
370
|
+
private makeCommonPrimitiveFilterSchema;
|
|
371
|
+
private makeNumberFilterSchema;
|
|
372
|
+
private makeStringFilterSchema;
|
|
373
|
+
private makeStringModeSchema;
|
|
374
|
+
private makeSelectSchema;
|
|
375
|
+
private makeCountSelectionSchema;
|
|
376
|
+
private makeRelationSelectIncludeSchema;
|
|
377
|
+
private makeOmitSchema;
|
|
378
|
+
private makeIncludeSchema;
|
|
379
|
+
private makeOrderBySchema;
|
|
380
|
+
private makeDistinctSchema;
|
|
381
|
+
private makeCursorSchema;
|
|
382
|
+
private makeCreateSchema;
|
|
383
|
+
private makeCreateManySchema;
|
|
384
|
+
private makeCreateManyAndReturnSchema;
|
|
385
|
+
private makeCreateDataSchema;
|
|
386
|
+
private isDelegateDiscriminator;
|
|
387
|
+
private makeRelationManipulationSchema;
|
|
388
|
+
private makeSetDataSchema;
|
|
389
|
+
private makeConnectDataSchema;
|
|
390
|
+
private makeDisconnectDataSchema;
|
|
391
|
+
private makeDeleteRelationDataSchema;
|
|
392
|
+
private makeConnectOrCreateDataSchema;
|
|
393
|
+
private makeCreateManyDataSchema;
|
|
394
|
+
private makeUpdateSchema;
|
|
395
|
+
private makeUpdateManySchema;
|
|
396
|
+
private makeUpdateManyAndReturnSchema;
|
|
397
|
+
private makeUpsertSchema;
|
|
398
|
+
private makeUpdateDataSchema;
|
|
399
|
+
private makeDeleteSchema;
|
|
400
|
+
private makeDeleteManySchema;
|
|
401
|
+
makeCountSchema(model: GetModels<Schema>): z.ZodOptional<z.ZodObject<{
|
|
402
|
+
where: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
403
|
+
skip: z.ZodOptional<z.ZodNumber>;
|
|
404
|
+
take: z.ZodOptional<z.ZodNumber>;
|
|
405
|
+
orderBy: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>> | z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>, z.ZodArray<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>]>>;
|
|
406
|
+
select: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
|
|
407
|
+
_all: z.ZodOptional<z.ZodLiteral<true>>;
|
|
408
|
+
}, z.core.$strict>]>>;
|
|
409
|
+
}, z.core.$strip>>;
|
|
410
|
+
private makeCountAggregateInputSchema;
|
|
411
|
+
makeAggregateSchema(model: GetModels<Schema>): z.ZodOptional<z.ZodObject<{
|
|
412
|
+
where: z.ZodOptional<z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>;
|
|
413
|
+
skip: z.ZodOptional<z.ZodNumber>;
|
|
414
|
+
take: z.ZodOptional<z.ZodNumber>;
|
|
415
|
+
orderBy: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>> | z.ZodOptional<z.ZodUnion<readonly [z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>, z.ZodArray<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>]>>;
|
|
416
|
+
_count: z.ZodOptional<z.ZodUnion<readonly [z.ZodLiteral<true>, z.ZodObject<{
|
|
417
|
+
_all: z.ZodOptional<z.ZodLiteral<true>>;
|
|
418
|
+
}, z.core.$strict>]>>;
|
|
419
|
+
_avg: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
|
|
420
|
+
_sum: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
|
|
421
|
+
_min: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
|
|
422
|
+
_max: z.ZodOptional<z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>>;
|
|
423
|
+
}, z.core.$strip>>;
|
|
424
|
+
makeSumAvgInputSchema(model: GetModels<Schema>): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
|
|
425
|
+
makeMinMaxInputSchema(model: GetModels<Schema>): z.ZodObject<Record<string, z.ZodType<unknown, unknown, z.core.$ZodTypeInternals<unknown, unknown>>>, z.core.$strict>;
|
|
426
|
+
private makeGroupBySchema;
|
|
427
|
+
private onlyAggregationFields;
|
|
428
|
+
private makeHavingSchema;
|
|
429
|
+
private makeSkipSchema;
|
|
430
|
+
private makeTakeSchema;
|
|
431
|
+
private refineForSelectIncludeMutuallyExclusive;
|
|
432
|
+
private refineForSelectOmitMutuallyExclusive;
|
|
433
|
+
private nullableIf;
|
|
434
|
+
private orArray;
|
|
435
|
+
private isNumericField;
|
|
436
|
+
private get providerSupportsCaseSensitivity();
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
type CoreCrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy' | 'exists';
|
|
318
440
|
type AllCrudOperation = CoreCrudOperation | 'findUniqueOrThrow' | 'findFirstOrThrow';
|
|
319
441
|
|
|
320
442
|
/**
|
|
@@ -342,6 +464,10 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
|
|
|
342
464
|
* Intercepts an ORM query.
|
|
343
465
|
*/
|
|
344
466
|
onQuery?: OnQueryCallback<Schema>;
|
|
467
|
+
/**
|
|
468
|
+
* Intercepts a procedure invocation.
|
|
469
|
+
*/
|
|
470
|
+
onProcedure?: OnProcedureCallback<Schema>;
|
|
345
471
|
/**
|
|
346
472
|
* Intercepts an entity mutation.
|
|
347
473
|
*/
|
|
@@ -356,6 +482,32 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
|
|
|
356
482
|
*/
|
|
357
483
|
declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
|
|
358
484
|
|
|
485
|
+
type OnProcedureCallback<Schema extends SchemaDef> = (ctx: OnProcedureHookContext<Schema>) => Promise<unknown>;
|
|
486
|
+
type OnProcedureHookContext<Schema extends SchemaDef> = {
|
|
487
|
+
/**
|
|
488
|
+
* The procedure name.
|
|
489
|
+
*/
|
|
490
|
+
name: string;
|
|
491
|
+
/**
|
|
492
|
+
* Whether the procedure is a mutation.
|
|
493
|
+
*/
|
|
494
|
+
mutation: boolean;
|
|
495
|
+
/**
|
|
496
|
+
* Procedure invocation input (envelope).
|
|
497
|
+
*
|
|
498
|
+
* The canonical shape is `{ args?: Record<string, unknown> }`.
|
|
499
|
+
* When a procedure has required params, `args` is required.
|
|
500
|
+
*/
|
|
501
|
+
input: unknown;
|
|
502
|
+
/**
|
|
503
|
+
* Continues the invocation. The input passed here is forwarded to the next handler.
|
|
504
|
+
*/
|
|
505
|
+
proceed: (input: unknown) => Promise<unknown>;
|
|
506
|
+
/**
|
|
507
|
+
* The ZenStack client that is invoking the procedure.
|
|
508
|
+
*/
|
|
509
|
+
client: ClientContract<Schema>;
|
|
510
|
+
};
|
|
359
511
|
type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
|
|
360
512
|
type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
361
513
|
/**
|
|
@@ -560,7 +712,7 @@ type HasComputedFields<Schema extends SchemaDef> = string extends GetModels<Sche
|
|
|
560
712
|
type ProceduresOptions<Schema extends SchemaDef> = Schema extends {
|
|
561
713
|
procedures: Record<string, ProcedureDef>;
|
|
562
714
|
} ? {
|
|
563
|
-
[Key in
|
|
715
|
+
[Key in GetProcedureNames<Schema>]: ProcedureHandlerFunc<Schema, Key>;
|
|
564
716
|
} : {};
|
|
565
717
|
type HasProcedures<Schema extends SchemaDef> = Schema extends {
|
|
566
718
|
procedures: Record<string, ProcedureDef>;
|
|
@@ -1040,6 +1192,7 @@ type FindArgs<Schema extends SchemaDef, Model extends GetModels<Schema>, Collect
|
|
|
1040
1192
|
} : {}) & (AllowFilter extends true ? FilterArgs<Schema, Model> : {}) & SelectIncludeOmit<Schema, Model, Collection>;
|
|
1041
1193
|
type FindManyArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
|
|
1042
1194
|
type FindFirstArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FindArgs<Schema, Model, true>;
|
|
1195
|
+
type ExistsArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = FilterArgs<Schema, Model>;
|
|
1043
1196
|
type FindUniqueArgs<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
|
|
1044
1197
|
where: WhereUniqueInput<Schema, Model>;
|
|
1045
1198
|
} & SelectIncludeOmit<Schema, Model, true>;
|
|
@@ -1513,6 +1666,59 @@ type NestedUpsertInput<Schema extends SchemaDef, Model extends GetModels<Schema>
|
|
|
1513
1666
|
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>>>;
|
|
1514
1667
|
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>>;
|
|
1515
1668
|
type NestedDeleteManyInput<Schema extends SchemaDef, Model extends GetModels<Schema>, Field extends RelationFields<Schema, Model>> = OrArray<WhereInput<Schema, RelationFieldType<Schema, Model, Field>, true>>;
|
|
1669
|
+
type GetProcedureNames<Schema extends SchemaDef> = Schema extends {
|
|
1670
|
+
procedures: Record<string, ProcedureDef>;
|
|
1671
|
+
} ? keyof Schema['procedures'] : never;
|
|
1672
|
+
type GetProcedureParams<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
|
|
1673
|
+
procedures: Record<string, ProcedureDef>;
|
|
1674
|
+
} ? Schema['procedures'][ProcName]['params'] : never;
|
|
1675
|
+
type GetProcedure<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = Schema extends {
|
|
1676
|
+
procedures: Record<string, ProcedureDef>;
|
|
1677
|
+
} ? Schema['procedures'][ProcName] : never;
|
|
1678
|
+
type _OptionalProcedureParamNames<Params> = keyof {
|
|
1679
|
+
[K in keyof Params as Params[K] extends {
|
|
1680
|
+
optional: true;
|
|
1681
|
+
} ? K : never]: K;
|
|
1682
|
+
};
|
|
1683
|
+
type _RequiredProcedureParamNames<Params> = keyof {
|
|
1684
|
+
[K in keyof Params as Params[K] extends {
|
|
1685
|
+
optional: true;
|
|
1686
|
+
} ? never : K]: K;
|
|
1687
|
+
};
|
|
1688
|
+
type _HasRequiredProcedureParams<Params> = _RequiredProcedureParamNames<Params> extends never ? false : true;
|
|
1689
|
+
type MapProcedureArgsObject<Schema extends SchemaDef, Params> = Simplify<Optional<{
|
|
1690
|
+
[K in keyof Params]: MapProcedureParam<Schema, Params[K]>;
|
|
1691
|
+
}, _OptionalProcedureParamNames<Params>>>;
|
|
1692
|
+
type ProcedureEnvelope<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>, Params = GetProcedureParams<Schema, ProcName>> = keyof Params extends never ? {
|
|
1693
|
+
args?: Record<string, never>;
|
|
1694
|
+
} : _HasRequiredProcedureParams<Params> extends true ? {
|
|
1695
|
+
args: MapProcedureArgsObject<Schema, Params>;
|
|
1696
|
+
} : {
|
|
1697
|
+
args?: MapProcedureArgsObject<Schema, Params>;
|
|
1698
|
+
};
|
|
1699
|
+
type ProcedureHandlerCtx<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = {
|
|
1700
|
+
client: ClientContract<Schema>;
|
|
1701
|
+
} & ProcedureEnvelope<Schema, ProcName>;
|
|
1702
|
+
/**
|
|
1703
|
+
* Shape of a procedure's runtime function.
|
|
1704
|
+
*/
|
|
1705
|
+
type ProcedureFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (...args: _HasRequiredProcedureParams<GetProcedureParams<Schema, ProcName>> extends true ? [input: ProcedureEnvelope<Schema, ProcName>] : [input?: ProcedureEnvelope<Schema, ProcName>]) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
|
|
1706
|
+
/**
|
|
1707
|
+
* Signature for procedure handlers configured via client options.
|
|
1708
|
+
*/
|
|
1709
|
+
type ProcedureHandlerFunc<Schema extends SchemaDef, ProcName extends GetProcedureNames<Schema>> = (ctx: ProcedureHandlerCtx<Schema, ProcName>) => MaybePromise<MapProcedureReturn<Schema, GetProcedure<Schema, ProcName>>>;
|
|
1710
|
+
type MapProcedureReturn<Schema extends SchemaDef, Proc> = Proc extends {
|
|
1711
|
+
returnType: infer R;
|
|
1712
|
+
} ? Proc extends {
|
|
1713
|
+
returnArray: true;
|
|
1714
|
+
} ? Array<MapType<Schema, R & string>> : MapType<Schema, R & string> : never;
|
|
1715
|
+
type MapProcedureParam<Schema extends SchemaDef, P> = P extends {
|
|
1716
|
+
type: infer U;
|
|
1717
|
+
} ? OrUndefinedIf<P extends {
|
|
1718
|
+
array: true;
|
|
1719
|
+
} ? Array<MapType<Schema, U & string>> : MapType<Schema, U & string>, P extends {
|
|
1720
|
+
optional: true;
|
|
1721
|
+
} ? true : false> : never;
|
|
1516
1722
|
type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
1517
1723
|
[Key in RelationFields<Schema, Model> as GetModelField<Schema, Model, Key>['relation'] extends {
|
|
1518
1724
|
references: readonly unknown[];
|
|
@@ -1521,6 +1727,8 @@ type NonOwnedRelationFields<Schema extends SchemaDef, Model extends GetModels<Sc
|
|
|
1521
1727
|
type HasToManyRelations<Schema extends SchemaDef, Model extends GetModels<Schema>> = keyof {
|
|
1522
1728
|
[Key in RelationFields<Schema, Model> as FieldIsArray<Schema, Model, Key> extends true ? Key : never]: true;
|
|
1523
1729
|
} extends never ? false : true;
|
|
1730
|
+
type EnumValue<Schema extends SchemaDef, Enum extends GetEnums<Schema>> = GetEnum<Schema, Enum>[keyof GetEnum<Schema, Enum>];
|
|
1731
|
+
type MapType<Schema extends SchemaDef, T extends string> = T extends keyof TypeMap ? TypeMap[T] : T extends GetModels<Schema> ? ModelResult<Schema, T> : T extends GetTypeDefs<Schema> ? TypeDefResult<Schema, T> : T extends GetEnums<Schema> ? EnumValue<Schema, T> : unknown;
|
|
1524
1732
|
|
|
1525
1733
|
/**
|
|
1526
1734
|
* A promise that only executes when it's awaited or .then() is called.
|
|
@@ -1660,34 +1868,19 @@ type ClientContract<Schema extends SchemaDef, Options extends ClientOptions<Sche
|
|
|
1660
1868
|
$pushSchema(): Promise<void>;
|
|
1661
1869
|
} & {
|
|
1662
1870
|
[Key in GetModels<Schema> as Uncapitalize<Key>]: ModelOperations<Schema, Key, ToQueryOptions<Options>>;
|
|
1663
|
-
} &
|
|
1871
|
+
} & ProcedureOperations<Schema>;
|
|
1664
1872
|
/**
|
|
1665
1873
|
* The contract for a client in a transaction.
|
|
1666
1874
|
*/
|
|
1667
1875
|
type TransactionClientContract<Schema extends SchemaDef, Options extends ClientOptions<Schema>> = Omit<ClientContract<Schema, Options>, TransactionUnsupportedMethods>;
|
|
1668
|
-
type
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
Boolean: boolean;
|
|
1675
|
-
DateTime: Date;
|
|
1676
|
-
};
|
|
1677
|
-
type MapType<Schema extends SchemaDef, T extends string> = T extends keyof _TypeMap ? _TypeMap[T] : T extends GetModels<Schema> ? ModelResult<Schema, T> : unknown;
|
|
1678
|
-
type Procedures<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
|
|
1679
|
-
$procedures: {
|
|
1680
|
-
[Key in keyof Schema['procedures']]: ProcedureFunc<Schema, Schema['procedures'][Key]>;
|
|
1876
|
+
type ProcedureOperations<Schema extends SchemaDef> = Schema['procedures'] extends Record<string, ProcedureDef> ? {
|
|
1877
|
+
/**
|
|
1878
|
+
* Custom procedures.
|
|
1879
|
+
*/
|
|
1880
|
+
$procs: {
|
|
1881
|
+
[Key in GetProcedureNames<Schema>]: ProcedureFunc<Schema, Key>;
|
|
1681
1882
|
};
|
|
1682
1883
|
} : {};
|
|
1683
|
-
type ProcedureFunc<Schema extends SchemaDef, Proc extends ProcedureDef> = (...args: MapProcedureParams<Schema, Proc['params']>) => Promise<MapType<Schema, Proc['returnType']>>;
|
|
1684
|
-
type MapProcedureParams<Schema extends SchemaDef, Params> = {
|
|
1685
|
-
[P in keyof Params]: Params[P] extends {
|
|
1686
|
-
type: infer U;
|
|
1687
|
-
} ? OrUndefinedIf<MapType<Schema, U & string>, Params[P] extends {
|
|
1688
|
-
optional: true;
|
|
1689
|
-
} ? true : false> : never;
|
|
1690
|
-
};
|
|
1691
1884
|
/**
|
|
1692
1885
|
* Creates a new ZenStack client instance.
|
|
1693
1886
|
*/
|
|
@@ -2213,6 +2406,24 @@ type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema
|
|
|
2213
2406
|
* });
|
|
2214
2407
|
*/
|
|
2215
2408
|
groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
|
|
2409
|
+
/**
|
|
2410
|
+
* Checks if an entity exists.
|
|
2411
|
+
* @param args - exists args
|
|
2412
|
+
* @returns whether a matching entity was found
|
|
2413
|
+
*
|
|
2414
|
+
* @example
|
|
2415
|
+
* ```ts
|
|
2416
|
+
* // check if a user exists
|
|
2417
|
+
* await db.user.exists({
|
|
2418
|
+
* where: { id: 1 },
|
|
2419
|
+
* }); // result: `boolean`
|
|
2420
|
+
*
|
|
2421
|
+
* // check with a relation
|
|
2422
|
+
* await db.user.exists({
|
|
2423
|
+
* where: { posts: { some: { published: true } } },
|
|
2424
|
+
* }); // result: `boolean`
|
|
2425
|
+
*/
|
|
2426
|
+
exists<T extends ExistsArgs<Schema, Model>>(args?: Subset<T, ExistsArgs<Schema, Model>>): ZenStackPromise<Schema, boolean>;
|
|
2216
2427
|
};
|
|
2217
2428
|
type OperationsIneligibleForDelegateModels = 'create' | 'createMany' | 'createManyAndReturn' | 'upsert';
|
|
2218
2429
|
type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>, Options extends QueryOptions<Schema> = QueryOptions<Schema>> = Omit<AllModelOperations<Schema, Model, Options>, IsDelegateModel<Schema, Model> extends true ? OperationsIneligibleForDelegateModels : never>;
|
|
@@ -2457,4 +2668,4 @@ declare namespace schemaUtils {
|
|
|
2457
2668
|
export { schemaUtils_ExpressionVisitor as ExpressionVisitor, schemaUtils_MatchingExpressionVisitor as MatchingExpressionVisitor, type schemaUtils_VisitResult as VisitResult };
|
|
2458
2669
|
}
|
|
2459
2670
|
|
|
2460
|
-
export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, type AllModelOperations, AnyNull, AnyNullClass, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type CoreCrudOperation as CrudOperation, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitInput, type OmitOptions, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureFunc, type
|
|
2671
|
+
export { type AfterEntityMutationCallback, type AggregateArgs, type AggregateResult, type AllModelOperations, AnyNull, AnyNullClass, type AuthType, BaseCrudDialect, type BatchResult, type BeforeEntityMutationCallback, type BooleanFilter, type BytesFilter, CRUD, CRUD_EXT, type ClientConstructor, type ClientContract, type ClientOptions, type ComputedFieldsOptions, type CountArgs, type CountResult, type CreateArgs, type CreateInput, type CreateManyAndReturnArgs, type CreateManyArgs, type CreateManyInput, type CoreCrudOperation as CrudOperation, type DateTimeFilter, DbNull, DbNullClass, type DefaultModelResult, type DeleteArgs, type DeleteManyArgs, type EntityMutationHooksDef, type ExistsArgs, type FindArgs, type FindFirstArgs, type FindManyArgs, type FindUniqueArgs, type GetProcedure, type GetProcedureNames, type GetProcedureParams, type GroupByArgs, type GroupByResult, type HasComputedFields, type HasProcedures, type IncludeInput, InputValidator, type JsonArray, type JsonFilter, JsonNull, JsonNullClass, type JsonNullValues, type JsonObject, type JsonValue, kyselyUtils as KyselyUtils, type ModelOperations, type ModelResult, type NullsOrder, type NumberFilter, ORMError, ORMErrorReason, type OmitInput, type OmitOptions, type OnKyselyQueryArgs, type OnKyselyQueryCallback, type OnProcedureHookContext, type OperationsIneligibleForDelegateModels, type OrderBy, type PluginAfterEntityMutationArgs, type PluginBeforeEntityMutationArgs, type ProcedureEnvelope, type ProcedureFunc, type ProcedureHandlerFunc, type ProcedureOperations, type ProceduresOptions, type ProceedKyselyQueryFunction, type QueryOptions, queryUtils as QueryUtils, RejectedByPolicyReason, type RuntimePlugin, schemaUtils as SchemaUtils, type SelectIncludeOmit, type SelectInput, type SelectSubset, type SimplifiedPlainResult, type SimplifiedResult, type SortOrder, type StringFilter, type Subset, type ToKysely, type ToQueryOptions, type TransactionClientContract, TransactionIsolationLevel, type TypeDefResult, type TypedJsonFilter, type UpdateArgs, type UpdateInput, type UpdateManyAndReturnArgs, type UpdateManyArgs, type UpsertArgs, type WhereInput, type WhereUniqueInput, type ZModelFunction, type ZModelFunctionContext, ZenStackClient, type ZenStackPromise, definePlugin, getCrudDialect };
|