@zenstackhq/runtime 3.0.0-alpha.23 → 3.0.0-alpha.25
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-Y3qWOegb.d.cts → contract-BOWN0dwS.d.cts} +90 -85
- package/dist/{contract-Y3qWOegb.d.ts → contract-BOWN0dwS.d.ts} +90 -85
- package/dist/index.cjs +38 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +39 -40
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.cjs +10 -7
- package/dist/plugins/policy/index.cjs.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +1 -1
- package/dist/plugins/policy/index.js +10 -7
- package/dist/plugins/policy/index.js.map +1 -1
- package/package.json +9 -9
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
|
|
2
2
|
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, BuiltinType, GetModel, FieldDef, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, IsDelegateModel, GetModelDiscriminator, GetSubModels, FieldIsRelationArray, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, DataSourceProviderType, ProcedureDef } from '@zenstackhq/sdk/schema';
|
|
3
|
-
import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, RootOperationNode, QueryResult, UnknownRow,
|
|
3
|
+
import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, OperationNode, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
|
|
4
4
|
|
|
5
5
|
type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
6
6
|
type NullableIf<T, Condition extends boolean> = Condition extends true ? T | null : T;
|
|
@@ -562,7 +562,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
562
562
|
protected and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
563
563
|
protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
564
564
|
protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
565
|
-
fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string): ExpressionWrapper<any, any, unknown>;
|
|
565
|
+
fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string, inlineComputedField?: boolean): ExpressionWrapper<any, any, unknown>;
|
|
566
566
|
abstract get provider(): DataSourceProviderType;
|
|
567
567
|
/**
|
|
568
568
|
* Builds selection for a relation field.
|
|
@@ -605,79 +605,66 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
605
605
|
type CrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
|
|
606
606
|
|
|
607
607
|
/**
|
|
608
|
-
*
|
|
608
|
+
* ZenStack runtime plugin.
|
|
609
609
|
*/
|
|
610
|
-
|
|
610
|
+
interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
|
|
611
611
|
/**
|
|
612
|
-
*
|
|
612
|
+
* Plugin ID.
|
|
613
613
|
*/
|
|
614
|
-
|
|
614
|
+
id: string;
|
|
615
615
|
/**
|
|
616
|
-
*
|
|
616
|
+
* Plugin display name.
|
|
617
617
|
*/
|
|
618
|
-
|
|
618
|
+
name?: string;
|
|
619
619
|
/**
|
|
620
|
-
*
|
|
620
|
+
* Plugin description.
|
|
621
621
|
*/
|
|
622
|
-
|
|
623
|
-
};
|
|
624
|
-
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
622
|
+
description?: string;
|
|
625
623
|
/**
|
|
626
|
-
*
|
|
624
|
+
* Intercepts an ORM query.
|
|
627
625
|
*/
|
|
628
|
-
|
|
626
|
+
onQuery?: OnQueryCallback<Schema>;
|
|
629
627
|
/**
|
|
630
|
-
*
|
|
628
|
+
* Intercepts an entity mutation.
|
|
631
629
|
*/
|
|
632
|
-
|
|
630
|
+
onEntityMutation?: EntityMutationHooksDef<Schema>;
|
|
633
631
|
/**
|
|
634
|
-
*
|
|
632
|
+
* Intercepts a Kysely query.
|
|
635
633
|
*/
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
639
|
-
entities?: Record<string, unknown>[];
|
|
640
|
-
};
|
|
641
|
-
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
642
|
-
beforeMutationEntities?: Record<string, unknown>[];
|
|
643
|
-
afterMutationEntities?: Record<string, unknown>[];
|
|
644
|
-
};
|
|
645
|
-
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
646
|
-
kysely: ToKysely<Schema>;
|
|
647
|
-
schema: SchemaDef;
|
|
648
|
-
client: ClientContract<Schema>;
|
|
649
|
-
query: RootOperationNode;
|
|
650
|
-
proceed: ProceedKyselyQueryFunction;
|
|
651
|
-
};
|
|
652
|
-
type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
|
|
653
|
-
type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
|
|
654
|
-
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
655
|
-
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
656
|
-
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
634
|
+
onKyselyQuery?: OnKyselyQueryCallback<Schema>;
|
|
635
|
+
}
|
|
657
636
|
/**
|
|
658
|
-
* ZenStack runtime plugin.
|
|
637
|
+
* Defines a ZenStack runtime plugin.
|
|
659
638
|
*/
|
|
660
|
-
|
|
639
|
+
declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
|
|
640
|
+
|
|
641
|
+
type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
|
|
642
|
+
type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
661
643
|
/**
|
|
662
|
-
*
|
|
644
|
+
* The model that is being queried.
|
|
663
645
|
*/
|
|
664
|
-
|
|
646
|
+
model: GetModels<Schema>;
|
|
665
647
|
/**
|
|
666
|
-
*
|
|
648
|
+
* The operation that is being performed.
|
|
667
649
|
*/
|
|
668
|
-
|
|
650
|
+
operation: CrudOperation;
|
|
669
651
|
/**
|
|
670
|
-
*
|
|
652
|
+
* The query arguments.
|
|
671
653
|
*/
|
|
672
|
-
|
|
654
|
+
args: unknown;
|
|
673
655
|
/**
|
|
674
|
-
*
|
|
656
|
+
* The function to proceed with the original query.
|
|
657
|
+
* It takes the same arguments as the operation method.
|
|
658
|
+
*
|
|
659
|
+
* @param args The query arguments.
|
|
675
660
|
*/
|
|
676
|
-
|
|
661
|
+
proceed: (args: unknown) => Promise<unknown>;
|
|
677
662
|
/**
|
|
678
|
-
*
|
|
663
|
+
* The ZenStack client that is performing the operation.
|
|
679
664
|
*/
|
|
680
|
-
|
|
665
|
+
client: ClientContract<Schema>;
|
|
666
|
+
};
|
|
667
|
+
type EntityMutationHooksDef<Schema extends SchemaDef> = {
|
|
681
668
|
/**
|
|
682
669
|
* This callback determines whether a mutation should be intercepted, and if so,
|
|
683
670
|
* what data should be loaded before and after the mutation.
|
|
@@ -697,52 +684,69 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
|
|
|
697
684
|
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
698
685
|
*/
|
|
699
686
|
afterEntityMutation?: AfterEntityMutationCallback<Schema>;
|
|
700
|
-
}
|
|
701
|
-
type OnQueryHooks<Schema extends SchemaDef = SchemaDef> = {
|
|
702
|
-
[Model in GetModels<Schema> as Uncapitalize<Model>]?: OnQueryOperationHooks<Schema, Model>;
|
|
703
|
-
} & {
|
|
704
|
-
$allModels?: OnQueryOperationHooks<Schema, GetModels<Schema>>;
|
|
705
687
|
};
|
|
706
|
-
type
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
688
|
+
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
689
|
+
/**
|
|
690
|
+
* The model that is being mutated.
|
|
691
|
+
*/
|
|
692
|
+
model: GetModels<Schema>;
|
|
693
|
+
/**
|
|
694
|
+
* The mutation action that is being performed.
|
|
695
|
+
*/
|
|
696
|
+
action: 'create' | 'update' | 'delete';
|
|
697
|
+
/**
|
|
698
|
+
* The mutation data. Only available for create and update actions.
|
|
699
|
+
*/
|
|
700
|
+
queryNode: OperationNode;
|
|
716
701
|
};
|
|
717
|
-
type
|
|
702
|
+
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
703
|
+
/**
|
|
704
|
+
* The result of the hooks interception filter.
|
|
705
|
+
*/
|
|
706
|
+
type MutationInterceptionFilterResult = {
|
|
718
707
|
/**
|
|
719
|
-
*
|
|
708
|
+
* Whether to intercept the mutation or not.
|
|
709
|
+
*/
|
|
710
|
+
intercept: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Whether entities should be loaded before the mutation.
|
|
720
713
|
*/
|
|
721
|
-
|
|
714
|
+
loadBeforeMutationEntities?: boolean;
|
|
722
715
|
/**
|
|
723
|
-
*
|
|
716
|
+
* Whether entities should be loaded after the mutation.
|
|
724
717
|
*/
|
|
725
|
-
|
|
718
|
+
loadAfterMutationEntities?: boolean;
|
|
719
|
+
};
|
|
720
|
+
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
721
|
+
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
722
|
+
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
726
723
|
/**
|
|
727
|
-
*
|
|
724
|
+
* Entities that are about to be mutated. Only available if `loadBeforeMutationEntities` is set to
|
|
725
|
+
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
728
726
|
*/
|
|
729
|
-
|
|
727
|
+
entities?: unknown[];
|
|
728
|
+
};
|
|
729
|
+
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
730
730
|
/**
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
* @param args The query arguments.
|
|
731
|
+
* Entities that are about to be mutated. Only available if `loadBeforeMutationEntities` is set to
|
|
732
|
+
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
735
733
|
*/
|
|
736
|
-
|
|
734
|
+
beforeMutationEntities?: unknown[];
|
|
737
735
|
/**
|
|
738
|
-
*
|
|
736
|
+
* Entities mutated. Only available if `loadAfterMutationEntities` is set to true in the return
|
|
737
|
+
* value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
739
738
|
*/
|
|
739
|
+
afterMutationEntities?: unknown[];
|
|
740
|
+
};
|
|
741
|
+
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
742
|
+
kysely: ToKysely<Schema>;
|
|
743
|
+
schema: SchemaDef;
|
|
740
744
|
client: ClientContract<Schema>;
|
|
745
|
+
query: RootOperationNode;
|
|
746
|
+
proceed: ProceedKyselyQueryFunction;
|
|
741
747
|
};
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
*/
|
|
745
|
-
declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
|
|
748
|
+
type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
|
|
749
|
+
type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
|
|
746
750
|
|
|
747
751
|
type ZModelFunctionContext<Schema extends SchemaDef> = {
|
|
748
752
|
dialect: BaseCrudDialect<Schema>;
|
|
@@ -950,7 +954,7 @@ interface ClientConstructor {
|
|
|
950
954
|
* CRUD operations.
|
|
951
955
|
*/
|
|
952
956
|
type CRUD = 'create' | 'read' | 'update' | 'delete';
|
|
953
|
-
type
|
|
957
|
+
type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
|
|
954
958
|
/**
|
|
955
959
|
* Returns a list of entities.
|
|
956
960
|
* @param args - query args
|
|
@@ -1361,7 +1365,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
|
|
|
1361
1365
|
* }); // result: `{ id: string; email: string }`
|
|
1362
1366
|
* ```
|
|
1363
1367
|
*/
|
|
1364
|
-
delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model>>>;
|
|
1368
|
+
delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
1365
1369
|
/**
|
|
1366
1370
|
* Deletes multiple entities.
|
|
1367
1371
|
* @param args - delete args
|
|
@@ -1453,6 +1457,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
|
|
|
1453
1457
|
* });
|
|
1454
1458
|
*/
|
|
1455
1459
|
groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
|
|
1456
|
-
}
|
|
1460
|
+
};
|
|
1461
|
+
type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<AllModelOperations<Schema, Model>, IsDelegateModel<Schema, Model> extends true ? 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' : never>;
|
|
1457
1462
|
|
|
1458
1463
|
export { type DeleteArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type DeleteManyArgs as E, type FindArgs as F, type CountArgs as G, type CountResult as H, type IncludeInput as I, type JsonArray as J, type AggregateArgs as K, type AggregateResult as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByArgs as P, type GroupByResult as Q, type RuntimePlugin as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, type OnKyselyQueryArgs as V, type WhereInput as W, type JsonObject as a, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type TypeDefResult as f, type StringFilter as g, type BytesFilter as h, type BooleanFilter as i, type SortOrder as j, type NullsOrder as k, type WhereUniqueInput as l, type OmitInput as m, type SelectIncludeOmit as n, type SelectInput as o, type Subset as p, type SelectSubset as q, type FindManyArgs as r, type FindFirstArgs as s, type FindUniqueArgs as t, type CreateArgs as u, type CreateManyArgs as v, type CreateManyAndReturnArgs as w, type UpdateManyArgs as x, type UpdateManyAndReturnArgs as y, type UpsertArgs as z };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Decimal, { Decimal as Decimal$1 } from 'decimal.js';
|
|
2
2
|
import { SchemaDef, GetModels, ScalarFields, ForeignKeyFields, GetModelFields, FieldHasDefault, GetModelFieldType, ModelFieldIsOptional, GetModelField, NonRelationFields, RelationFields, FieldIsArray, RelationFieldType, FieldIsRelation, GetEnums, GetEnum, BuiltinType, GetModel, FieldDef, GetTypeDefs, GetTypeDefFields, GetTypeDefField, TypeDefFieldIsOptional, IsDelegateModel, GetModelDiscriminator, GetSubModels, FieldIsRelationArray, FieldIsDelegateDiscriminator, FieldType, RelationInfo, FieldIsDelegateRelation, DataSourceProviderType, ProcedureDef } from '@zenstackhq/sdk/schema';
|
|
3
|
-
import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, RootOperationNode, QueryResult, UnknownRow,
|
|
3
|
+
import { Generated, Kysely, ExpressionBuilder, OperandExpression, SqlBool, SelectQueryBuilder, Expression, ExpressionWrapper, OperationNode, RootOperationNode, QueryResult, UnknownRow, Dialect, KyselyConfig } from 'kysely';
|
|
4
4
|
|
|
5
5
|
type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
|
|
6
6
|
type NullableIf<T, Condition extends boolean> = Condition extends true ? T | null : T;
|
|
@@ -562,7 +562,7 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
562
562
|
protected and(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
563
563
|
protected or(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): Expression<SqlBool>;
|
|
564
564
|
protected not(eb: ExpressionBuilder<any, any>, ...args: Expression<SqlBool>[]): ExpressionWrapper<any, any, SqlBool>;
|
|
565
|
-
fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string): ExpressionWrapper<any, any, unknown>;
|
|
565
|
+
fieldRef(model: string, field: string, eb: ExpressionBuilder<any, any>, modelAlias?: string, inlineComputedField?: boolean): ExpressionWrapper<any, any, unknown>;
|
|
566
566
|
abstract get provider(): DataSourceProviderType;
|
|
567
567
|
/**
|
|
568
568
|
* Builds selection for a relation field.
|
|
@@ -605,79 +605,66 @@ declare abstract class BaseCrudDialect<Schema extends SchemaDef> {
|
|
|
605
605
|
type CrudOperation = 'findMany' | 'findUnique' | 'findFirst' | 'create' | 'createMany' | 'createManyAndReturn' | 'update' | 'updateMany' | 'updateManyAndReturn' | 'upsert' | 'delete' | 'deleteMany' | 'count' | 'aggregate' | 'groupBy';
|
|
606
606
|
|
|
607
607
|
/**
|
|
608
|
-
*
|
|
608
|
+
* ZenStack runtime plugin.
|
|
609
609
|
*/
|
|
610
|
-
|
|
610
|
+
interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
|
|
611
611
|
/**
|
|
612
|
-
*
|
|
612
|
+
* Plugin ID.
|
|
613
613
|
*/
|
|
614
|
-
|
|
614
|
+
id: string;
|
|
615
615
|
/**
|
|
616
|
-
*
|
|
616
|
+
* Plugin display name.
|
|
617
617
|
*/
|
|
618
|
-
|
|
618
|
+
name?: string;
|
|
619
619
|
/**
|
|
620
|
-
*
|
|
620
|
+
* Plugin description.
|
|
621
621
|
*/
|
|
622
|
-
|
|
623
|
-
};
|
|
624
|
-
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
622
|
+
description?: string;
|
|
625
623
|
/**
|
|
626
|
-
*
|
|
624
|
+
* Intercepts an ORM query.
|
|
627
625
|
*/
|
|
628
|
-
|
|
626
|
+
onQuery?: OnQueryCallback<Schema>;
|
|
629
627
|
/**
|
|
630
|
-
*
|
|
628
|
+
* Intercepts an entity mutation.
|
|
631
629
|
*/
|
|
632
|
-
|
|
630
|
+
onEntityMutation?: EntityMutationHooksDef<Schema>;
|
|
633
631
|
/**
|
|
634
|
-
*
|
|
632
|
+
* Intercepts a Kysely query.
|
|
635
633
|
*/
|
|
636
|
-
|
|
637
|
-
}
|
|
638
|
-
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
639
|
-
entities?: Record<string, unknown>[];
|
|
640
|
-
};
|
|
641
|
-
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
642
|
-
beforeMutationEntities?: Record<string, unknown>[];
|
|
643
|
-
afterMutationEntities?: Record<string, unknown>[];
|
|
644
|
-
};
|
|
645
|
-
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
646
|
-
kysely: ToKysely<Schema>;
|
|
647
|
-
schema: SchemaDef;
|
|
648
|
-
client: ClientContract<Schema>;
|
|
649
|
-
query: RootOperationNode;
|
|
650
|
-
proceed: ProceedKyselyQueryFunction;
|
|
651
|
-
};
|
|
652
|
-
type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
|
|
653
|
-
type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
|
|
654
|
-
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
655
|
-
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
656
|
-
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
634
|
+
onKyselyQuery?: OnKyselyQueryCallback<Schema>;
|
|
635
|
+
}
|
|
657
636
|
/**
|
|
658
|
-
* ZenStack runtime plugin.
|
|
637
|
+
* Defines a ZenStack runtime plugin.
|
|
659
638
|
*/
|
|
660
|
-
|
|
639
|
+
declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
|
|
640
|
+
|
|
641
|
+
type OnQueryCallback<Schema extends SchemaDef> = (ctx: OnQueryHookContext<Schema>) => Promise<unknown>;
|
|
642
|
+
type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
661
643
|
/**
|
|
662
|
-
*
|
|
644
|
+
* The model that is being queried.
|
|
663
645
|
*/
|
|
664
|
-
|
|
646
|
+
model: GetModels<Schema>;
|
|
665
647
|
/**
|
|
666
|
-
*
|
|
648
|
+
* The operation that is being performed.
|
|
667
649
|
*/
|
|
668
|
-
|
|
650
|
+
operation: CrudOperation;
|
|
669
651
|
/**
|
|
670
|
-
*
|
|
652
|
+
* The query arguments.
|
|
671
653
|
*/
|
|
672
|
-
|
|
654
|
+
args: unknown;
|
|
673
655
|
/**
|
|
674
|
-
*
|
|
656
|
+
* The function to proceed with the original query.
|
|
657
|
+
* It takes the same arguments as the operation method.
|
|
658
|
+
*
|
|
659
|
+
* @param args The query arguments.
|
|
675
660
|
*/
|
|
676
|
-
|
|
661
|
+
proceed: (args: unknown) => Promise<unknown>;
|
|
677
662
|
/**
|
|
678
|
-
*
|
|
663
|
+
* The ZenStack client that is performing the operation.
|
|
679
664
|
*/
|
|
680
|
-
|
|
665
|
+
client: ClientContract<Schema>;
|
|
666
|
+
};
|
|
667
|
+
type EntityMutationHooksDef<Schema extends SchemaDef> = {
|
|
681
668
|
/**
|
|
682
669
|
* This callback determines whether a mutation should be intercepted, and if so,
|
|
683
670
|
* what data should be loaded before and after the mutation.
|
|
@@ -697,52 +684,69 @@ interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
|
|
|
697
684
|
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
698
685
|
*/
|
|
699
686
|
afterEntityMutation?: AfterEntityMutationCallback<Schema>;
|
|
700
|
-
}
|
|
701
|
-
type OnQueryHooks<Schema extends SchemaDef = SchemaDef> = {
|
|
702
|
-
[Model in GetModels<Schema> as Uncapitalize<Model>]?: OnQueryOperationHooks<Schema, Model>;
|
|
703
|
-
} & {
|
|
704
|
-
$allModels?: OnQueryOperationHooks<Schema, GetModels<Schema>>;
|
|
705
687
|
};
|
|
706
|
-
type
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
688
|
+
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
689
|
+
/**
|
|
690
|
+
* The model that is being mutated.
|
|
691
|
+
*/
|
|
692
|
+
model: GetModels<Schema>;
|
|
693
|
+
/**
|
|
694
|
+
* The mutation action that is being performed.
|
|
695
|
+
*/
|
|
696
|
+
action: 'create' | 'update' | 'delete';
|
|
697
|
+
/**
|
|
698
|
+
* The mutation data. Only available for create and update actions.
|
|
699
|
+
*/
|
|
700
|
+
queryNode: OperationNode;
|
|
716
701
|
};
|
|
717
|
-
type
|
|
702
|
+
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
703
|
+
/**
|
|
704
|
+
* The result of the hooks interception filter.
|
|
705
|
+
*/
|
|
706
|
+
type MutationInterceptionFilterResult = {
|
|
718
707
|
/**
|
|
719
|
-
*
|
|
708
|
+
* Whether to intercept the mutation or not.
|
|
709
|
+
*/
|
|
710
|
+
intercept: boolean;
|
|
711
|
+
/**
|
|
712
|
+
* Whether entities should be loaded before the mutation.
|
|
720
713
|
*/
|
|
721
|
-
|
|
714
|
+
loadBeforeMutationEntities?: boolean;
|
|
722
715
|
/**
|
|
723
|
-
*
|
|
716
|
+
* Whether entities should be loaded after the mutation.
|
|
724
717
|
*/
|
|
725
|
-
|
|
718
|
+
loadAfterMutationEntities?: boolean;
|
|
719
|
+
};
|
|
720
|
+
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
721
|
+
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
722
|
+
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
726
723
|
/**
|
|
727
|
-
*
|
|
724
|
+
* Entities that are about to be mutated. Only available if `loadBeforeMutationEntities` is set to
|
|
725
|
+
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
728
726
|
*/
|
|
729
|
-
|
|
727
|
+
entities?: unknown[];
|
|
728
|
+
};
|
|
729
|
+
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
730
730
|
/**
|
|
731
|
-
*
|
|
732
|
-
*
|
|
733
|
-
*
|
|
734
|
-
* @param args The query arguments.
|
|
731
|
+
* Entities that are about to be mutated. Only available if `loadBeforeMutationEntities` is set to
|
|
732
|
+
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
735
733
|
*/
|
|
736
|
-
|
|
734
|
+
beforeMutationEntities?: unknown[];
|
|
737
735
|
/**
|
|
738
|
-
*
|
|
736
|
+
* Entities mutated. Only available if `loadAfterMutationEntities` is set to true in the return
|
|
737
|
+
* value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
739
738
|
*/
|
|
739
|
+
afterMutationEntities?: unknown[];
|
|
740
|
+
};
|
|
741
|
+
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
742
|
+
kysely: ToKysely<Schema>;
|
|
743
|
+
schema: SchemaDef;
|
|
740
744
|
client: ClientContract<Schema>;
|
|
745
|
+
query: RootOperationNode;
|
|
746
|
+
proceed: ProceedKyselyQueryFunction;
|
|
741
747
|
};
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
*/
|
|
745
|
-
declare function definePlugin<Schema extends SchemaDef>(plugin: RuntimePlugin<Schema>): RuntimePlugin<Schema>;
|
|
748
|
+
type ProceedKyselyQueryFunction = (query: RootOperationNode) => Promise<QueryResult<any>>;
|
|
749
|
+
type OnKyselyQueryCallback<Schema extends SchemaDef> = (args: OnKyselyQueryArgs<Schema>) => Promise<QueryResult<UnknownRow>>;
|
|
746
750
|
|
|
747
751
|
type ZModelFunctionContext<Schema extends SchemaDef> = {
|
|
748
752
|
dialect: BaseCrudDialect<Schema>;
|
|
@@ -950,7 +954,7 @@ interface ClientConstructor {
|
|
|
950
954
|
* CRUD operations.
|
|
951
955
|
*/
|
|
952
956
|
type CRUD = 'create' | 'read' | 'update' | 'delete';
|
|
953
|
-
type
|
|
957
|
+
type AllModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = {
|
|
954
958
|
/**
|
|
955
959
|
* Returns a list of entities.
|
|
956
960
|
* @param args - query args
|
|
@@ -1361,7 +1365,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
|
|
|
1361
1365
|
* }); // result: `{ id: string; email: string }`
|
|
1362
1366
|
* ```
|
|
1363
1367
|
*/
|
|
1364
|
-
delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model>>>;
|
|
1368
|
+
delete<T extends DeleteArgs<Schema, Model>>(args: SelectSubset<T, DeleteArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<ModelResult<Schema, Model, T>>>;
|
|
1365
1369
|
/**
|
|
1366
1370
|
* Deletes multiple entities.
|
|
1367
1371
|
* @param args - delete args
|
|
@@ -1453,6 +1457,7 @@ type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>>
|
|
|
1453
1457
|
* });
|
|
1454
1458
|
*/
|
|
1455
1459
|
groupBy<T extends GroupByArgs<Schema, Model>>(args: Subset<T, GroupByArgs<Schema, Model>>): ZenStackPromise<Schema, Simplify<GroupByResult<Schema, Model, T>>>;
|
|
1456
|
-
}
|
|
1460
|
+
};
|
|
1461
|
+
type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Schema>> = Omit<AllModelOperations<Schema, Model>, IsDelegateModel<Schema, Model> extends true ? 'create' | 'createMany' | 'createManyAndReturn' | 'upsert' : never>;
|
|
1457
1462
|
|
|
1458
1463
|
export { type DeleteArgs as A, type BatchResult as B, type ClientConstructor as C, type DateTimeFilter as D, type DeleteManyArgs as E, type FindArgs as F, type CountArgs as G, type CountResult as H, type IncludeInput as I, type JsonArray as J, type AggregateArgs as K, type AggregateResult as L, type ModelResult as M, type NumberFilter as N, type OrderBy as O, type GroupByArgs as P, type GroupByResult as Q, type RuntimePlugin as R, type SimplifiedModelResult as S, type ToKysely as T, type UpdateArgs as U, type OnKyselyQueryArgs as V, type WhereInput as W, type JsonObject as a, type JsonValue as b, type ClientContract as c, type ClientOptions as d, definePlugin as e, type TypeDefResult as f, type StringFilter as g, type BytesFilter as h, type BooleanFilter as i, type SortOrder as j, type NullsOrder as k, type WhereUniqueInput as l, type OmitInput as m, type SelectIncludeOmit as n, type SelectInput as o, type Subset as p, type SelectSubset as q, type FindManyArgs as r, type FindFirstArgs as s, type FindUniqueArgs as t, type CreateArgs as u, type CreateManyArgs as v, type CreateManyAndReturnArgs as w, type UpdateManyArgs as x, type UpdateManyAndReturnArgs as y, type UpsertArgs as z };
|