diff --git a/README.md b/README.md index 949162d8..967c00ab 100644 --- a/README.md +++ b/README.md @@ -351,9 +351,9 @@ db.$use({ return { intercept: model === 'User', // load entities affected before the mutation (defaults to false) - loadBeforeMutationEntity: true, + loadBeforeMutationEntities: true, // load entities affected after the mutation (defaults to false) - loadAfterMutationEntity: true, + loadAfterMutationEntities: true, }; }, beforeEntityMutation({ model, action, entities }) { diff --git a/packages/runtime/src/client/executor/zenstack-query-executor.ts b/packages/runtime/src/client/executor/zenstack-query-executor.ts index 454c0a82..8aff9505 100644 --- a/packages/runtime/src/client/executor/zenstack-query-executor.ts +++ b/packages/runtime/src/client/executor/zenstack-query-executor.ts @@ -72,7 +72,7 @@ export class ZenStackQueryExecutor extends DefaultQuer const oldQueryNode = queryNode; if ( (InsertQueryNode.is(queryNode) || UpdateQueryNode.is(queryNode)) && - mutationInterceptionInfo?.loadAfterMutationEntity + mutationInterceptionInfo?.loadAfterMutationEntities ) { // need to make sure the query node has "returnAll" // for insert and update queries @@ -283,13 +283,13 @@ export class ZenStackQueryExecutor extends DefaultQuer queryNode, }); result.intercept ||= filterResult.intercept; - result.loadBeforeMutationEntity ||= filterResult.loadBeforeMutationEntity; - result.loadAfterMutationEntity ||= filterResult.loadAfterMutationEntity; + result.loadBeforeMutationEntities ||= filterResult.loadBeforeMutationEntities; + result.loadAfterMutationEntities ||= filterResult.loadAfterMutationEntities; } } let beforeMutationEntities: Record[] | undefined; - if (result.loadBeforeMutationEntity && (UpdateQueryNode.is(queryNode) || DeleteQueryNode.is(queryNode))) { + if (result.loadBeforeMutationEntities && (UpdateQueryNode.is(queryNode) || DeleteQueryNode.is(queryNode))) { beforeMutationEntities = await this.loadEntities(mutationModel, where); } @@ -354,7 +354,7 @@ export class ZenStackQueryExecutor extends DefaultQuer for (const hook of hooks) { let afterMutationEntities: Record[] | undefined = undefined; - if (mutationInterceptionInfo.loadAfterMutationEntity) { + if (mutationInterceptionInfo.loadAfterMutationEntities) { if (InsertQueryNode.is(queryNode) || UpdateQueryNode.is(queryNode)) { afterMutationEntities = queryResult.rows as Record[]; } diff --git a/packages/runtime/src/client/plugin.ts b/packages/runtime/src/client/plugin.ts index 3b006862..8ae24be6 100644 --- a/packages/runtime/src/client/plugin.ts +++ b/packages/runtime/src/client/plugin.ts @@ -39,12 +39,12 @@ export type MutationInterceptionFilterResult = { /** * Whether entities should be loaded before the mutation. */ - loadBeforeMutationEntity?: boolean; + loadBeforeMutationEntities?: boolean; /** * Whether entities should be loaded after the mutation. */ - loadAfterMutationEntity?: boolean; + loadAfterMutationEntities?: boolean; }; type MutationHooksArgs = { @@ -149,16 +149,16 @@ export interface RuntimePlugin { /** * Called before an entity is mutated. - * @param args.entity Only available if `loadBeforeMutationEntity` is set to true in the + * @param args.entity Only available if `loadBeforeMutationEntities` is set to true in the * return value of {@link RuntimePlugin.mutationInterceptionFilter}. */ beforeEntityMutation?: BeforeEntityMutationCallback; /** * Called after an entity is mutated. - * @param args.beforeMutationEntity Only available if `loadBeforeMutationEntity` is set to true in the + * @param args.beforeMutationEntity Only available if `loadBeforeMutationEntities` is set to true in the * return value of {@link RuntimePlugin.mutationInterceptionFilter}. - * @param args.afterMutationEntity Only available if `loadAfterMutationEntity` is set to true in the + * @param args.afterMutationEntity Only available if `loadAfterMutationEntities` is set to true in the * return value of {@link RuntimePlugin.mutationInterceptionFilter}. */ afterEntityMutation?: AfterEntityMutationCallback; diff --git a/packages/runtime/test/plugin/mutation-hooks.test.ts b/packages/runtime/test/plugin/mutation-hooks.test.ts index 3feb595a..c249e0a6 100644 --- a/packages/runtime/test/plugin/mutation-hooks.test.ts +++ b/packages/runtime/test/plugin/mutation-hooks.test.ts @@ -112,7 +112,7 @@ describe('Entity lifecycle tests', () => { mutationInterceptionFilter: () => { return { intercept: true, - loadBeforeMutationEntity: true, + loadBeforeMutationEntities: true, }; }, beforeEntityMutation(args) { @@ -159,7 +159,7 @@ describe('Entity lifecycle tests', () => { mutationInterceptionFilter: () => { return { intercept: true, - loadAfterMutationEntity: true, + loadAfterMutationEntities: true, }; }, afterEntityMutation(args) { @@ -205,7 +205,7 @@ describe('Entity lifecycle tests', () => { mutationInterceptionFilter: () => { return { intercept: true, - loadAfterMutationEntity: true, + loadAfterMutationEntities: true, }; }, afterEntityMutation(args) { @@ -263,7 +263,7 @@ describe('Entity lifecycle tests', () => { mutationInterceptionFilter: (args) => { return { intercept: args.action === 'create' || args.action === 'update', - loadAfterMutationEntity: true, + loadAfterMutationEntities: true, }; }, afterEntityMutation(args) { @@ -350,8 +350,8 @@ describe('Entity lifecycle tests', () => { mutationInterceptionFilter: () => { return { intercept: true, - loadBeforeMutationEntity: true, - loadAfterMutationEntity: true, + loadBeforeMutationEntities: true, + loadAfterMutationEntities: true, }; }, afterEntityMutation(args) {