@zenstackhq/runtime 3.0.0-alpha.31 → 3.0.0-alpha.32
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-5Wcmlo5v.d.cts → contract-CToGslMD.d.cts} +36 -38
- package/dist/{contract-5Wcmlo5v.d.ts → contract-CToGslMD.d.ts} +36 -38
- package/dist/index.cjs +297 -261
- 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 +245 -209
- package/dist/index.js.map +1 -1
- package/dist/plugins/policy/index.d.cts +1 -1
- package/dist/plugins/policy/index.d.ts +1 -1
- package/package.json +8 -8
|
@@ -674,24 +674,26 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
|
674
674
|
};
|
|
675
675
|
type EntityMutationHooksDef<Schema extends SchemaDef> = {
|
|
676
676
|
/**
|
|
677
|
-
*
|
|
678
|
-
* what data should be loaded before and after the mutation.
|
|
679
|
-
*/
|
|
680
|
-
mutationInterceptionFilter?: MutationInterceptionFilter<Schema>;
|
|
681
|
-
/**
|
|
682
|
-
* Called before an entity is mutated.
|
|
683
|
-
* @param args.entity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
684
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
677
|
+
* Called before entities are mutated.
|
|
685
678
|
*/
|
|
686
679
|
beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
|
|
687
680
|
/**
|
|
688
|
-
* Called after
|
|
689
|
-
* @param args.beforeMutationEntity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
690
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
691
|
-
* @param args.afterMutationEntity Only available if `loadAfterMutationEntities` is set to true in the
|
|
692
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
681
|
+
* Called after entities are mutated.
|
|
693
682
|
*/
|
|
694
683
|
afterEntityMutation?: AfterEntityMutationCallback<Schema>;
|
|
684
|
+
/**
|
|
685
|
+
* Whether to run after-mutation hooks within the transaction that performs the mutation.
|
|
686
|
+
*
|
|
687
|
+
* If set to `true`, if the mutation already runs inside a transaction, the callbacks are
|
|
688
|
+
* executed immediately after the mutation within the transaction boundary. If the mutation
|
|
689
|
+
* is not running inside a transaction, a new transaction is created to run both the mutation
|
|
690
|
+
* and the callbacks.
|
|
691
|
+
*
|
|
692
|
+
* If set to `false`, the callbacks are executed after the mutation transaction is committed.
|
|
693
|
+
*
|
|
694
|
+
* Defaults to `false`.
|
|
695
|
+
*/
|
|
696
|
+
runAfterMutationWithinTransaction?: boolean;
|
|
695
697
|
};
|
|
696
698
|
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
697
699
|
/**
|
|
@@ -706,45 +708,41 @@ type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
|
706
708
|
* The mutation data. Only available for create and update actions.
|
|
707
709
|
*/
|
|
708
710
|
queryNode: OperationNode;
|
|
709
|
-
};
|
|
710
|
-
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
711
|
-
/**
|
|
712
|
-
* The result of the hooks interception filter.
|
|
713
|
-
*/
|
|
714
|
-
type MutationInterceptionFilterResult = {
|
|
715
711
|
/**
|
|
716
|
-
*
|
|
712
|
+
* A query ID that uniquely identifies the mutation operation. You can use it to correlate
|
|
713
|
+
* data between the before and after mutation hooks.
|
|
717
714
|
*/
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Whether entities should be loaded before the mutation.
|
|
721
|
-
*/
|
|
722
|
-
loadBeforeMutationEntities?: boolean;
|
|
723
|
-
/**
|
|
724
|
-
* Whether entities should be loaded after the mutation.
|
|
725
|
-
*/
|
|
726
|
-
loadAfterMutationEntities?: boolean;
|
|
715
|
+
queryId: string;
|
|
727
716
|
};
|
|
728
717
|
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
729
718
|
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
730
719
|
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
731
720
|
/**
|
|
732
|
-
*
|
|
733
|
-
*
|
|
721
|
+
* Loads the entities that are about to be mutated. The db operation that loads the entities is executed
|
|
722
|
+
* within the same transaction context as the mutation.
|
|
723
|
+
*/
|
|
724
|
+
loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
725
|
+
/**
|
|
726
|
+
* The ZenStack client you can use to perform additional operations. The database operations initiated
|
|
727
|
+
* from this client are executed within the same transaction as the mutation if the mutation is running
|
|
728
|
+
* inside a transaction.
|
|
729
|
+
*
|
|
730
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
734
731
|
*/
|
|
735
|
-
|
|
732
|
+
client: ClientContract<Schema>;
|
|
736
733
|
};
|
|
737
734
|
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
738
735
|
/**
|
|
739
|
-
*
|
|
740
|
-
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
736
|
+
* Loads the entities that have been mutated.
|
|
741
737
|
*/
|
|
742
|
-
|
|
738
|
+
loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
743
739
|
/**
|
|
744
|
-
*
|
|
745
|
-
*
|
|
740
|
+
* The ZenStack client you can use to perform additional operations.
|
|
741
|
+
* See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
|
|
742
|
+
*
|
|
743
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
746
744
|
*/
|
|
747
|
-
|
|
745
|
+
client: ClientContract<Schema>;
|
|
748
746
|
};
|
|
749
747
|
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
750
748
|
kysely: ToKysely<Schema>;
|
|
@@ -674,24 +674,26 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
|
|
|
674
674
|
};
|
|
675
675
|
type EntityMutationHooksDef<Schema extends SchemaDef> = {
|
|
676
676
|
/**
|
|
677
|
-
*
|
|
678
|
-
* what data should be loaded before and after the mutation.
|
|
679
|
-
*/
|
|
680
|
-
mutationInterceptionFilter?: MutationInterceptionFilter<Schema>;
|
|
681
|
-
/**
|
|
682
|
-
* Called before an entity is mutated.
|
|
683
|
-
* @param args.entity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
684
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
677
|
+
* Called before entities are mutated.
|
|
685
678
|
*/
|
|
686
679
|
beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
|
|
687
680
|
/**
|
|
688
|
-
* Called after
|
|
689
|
-
* @param args.beforeMutationEntity Only available if `loadBeforeMutationEntities` is set to true in the
|
|
690
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
691
|
-
* @param args.afterMutationEntity Only available if `loadAfterMutationEntities` is set to true in the
|
|
692
|
-
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
681
|
+
* Called after entities are mutated.
|
|
693
682
|
*/
|
|
694
683
|
afterEntityMutation?: AfterEntityMutationCallback<Schema>;
|
|
684
|
+
/**
|
|
685
|
+
* Whether to run after-mutation hooks within the transaction that performs the mutation.
|
|
686
|
+
*
|
|
687
|
+
* If set to `true`, if the mutation already runs inside a transaction, the callbacks are
|
|
688
|
+
* executed immediately after the mutation within the transaction boundary. If the mutation
|
|
689
|
+
* is not running inside a transaction, a new transaction is created to run both the mutation
|
|
690
|
+
* and the callbacks.
|
|
691
|
+
*
|
|
692
|
+
* If set to `false`, the callbacks are executed after the mutation transaction is committed.
|
|
693
|
+
*
|
|
694
|
+
* Defaults to `false`.
|
|
695
|
+
*/
|
|
696
|
+
runAfterMutationWithinTransaction?: boolean;
|
|
695
697
|
};
|
|
696
698
|
type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
697
699
|
/**
|
|
@@ -706,45 +708,41 @@ type MutationHooksArgs<Schema extends SchemaDef> = {
|
|
|
706
708
|
* The mutation data. Only available for create and update actions.
|
|
707
709
|
*/
|
|
708
710
|
queryNode: OperationNode;
|
|
709
|
-
};
|
|
710
|
-
type MutationInterceptionFilter<Schema extends SchemaDef> = (args: MutationHooksArgs<Schema>) => MaybePromise<MutationInterceptionFilterResult>;
|
|
711
|
-
/**
|
|
712
|
-
* The result of the hooks interception filter.
|
|
713
|
-
*/
|
|
714
|
-
type MutationInterceptionFilterResult = {
|
|
715
711
|
/**
|
|
716
|
-
*
|
|
712
|
+
* A query ID that uniquely identifies the mutation operation. You can use it to correlate
|
|
713
|
+
* data between the before and after mutation hooks.
|
|
717
714
|
*/
|
|
718
|
-
|
|
719
|
-
/**
|
|
720
|
-
* Whether entities should be loaded before the mutation.
|
|
721
|
-
*/
|
|
722
|
-
loadBeforeMutationEntities?: boolean;
|
|
723
|
-
/**
|
|
724
|
-
* Whether entities should be loaded after the mutation.
|
|
725
|
-
*/
|
|
726
|
-
loadAfterMutationEntities?: boolean;
|
|
715
|
+
queryId: string;
|
|
727
716
|
};
|
|
728
717
|
type BeforeEntityMutationCallback<Schema extends SchemaDef> = (args: PluginBeforeEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
729
718
|
type AfterEntityMutationCallback<Schema extends SchemaDef> = (args: PluginAfterEntityMutationArgs<Schema>) => MaybePromise<void>;
|
|
730
719
|
type PluginBeforeEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
731
720
|
/**
|
|
732
|
-
*
|
|
733
|
-
*
|
|
721
|
+
* Loads the entities that are about to be mutated. The db operation that loads the entities is executed
|
|
722
|
+
* within the same transaction context as the mutation.
|
|
723
|
+
*/
|
|
724
|
+
loadBeforeMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
725
|
+
/**
|
|
726
|
+
* The ZenStack client you can use to perform additional operations. The database operations initiated
|
|
727
|
+
* from this client are executed within the same transaction as the mutation if the mutation is running
|
|
728
|
+
* inside a transaction.
|
|
729
|
+
*
|
|
730
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
734
731
|
*/
|
|
735
|
-
|
|
732
|
+
client: ClientContract<Schema>;
|
|
736
733
|
};
|
|
737
734
|
type PluginAfterEntityMutationArgs<Schema extends SchemaDef> = MutationHooksArgs<Schema> & {
|
|
738
735
|
/**
|
|
739
|
-
*
|
|
740
|
-
* true in the return value of {@link RuntimePlugin.mutationInterceptionFilter}.
|
|
736
|
+
* Loads the entities that have been mutated.
|
|
741
737
|
*/
|
|
742
|
-
|
|
738
|
+
loadAfterMutationEntities(): Promise<Record<string, unknown>[] | undefined>;
|
|
743
739
|
/**
|
|
744
|
-
*
|
|
745
|
-
*
|
|
740
|
+
* The ZenStack client you can use to perform additional operations.
|
|
741
|
+
* See {@link EntityMutationHooksDef.runAfterMutationWithinTransaction} for detailed transaction behavior.
|
|
742
|
+
*
|
|
743
|
+
* Mutations initiated from this client will NOT trigger entity mutation hooks to avoid infinite loops.
|
|
746
744
|
*/
|
|
747
|
-
|
|
745
|
+
client: ClientContract<Schema>;
|
|
748
746
|
};
|
|
749
747
|
type OnKyselyQueryArgs<Schema extends SchemaDef> = {
|
|
750
748
|
kysely: ToKysely<Schema>;
|