From b86ffb92a75838b1111895a7af0ae56aecc7997c Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Wed, 13 Aug 2025 20:51:36 +0800 Subject: [PATCH 1/2] fix: improve plugin config typing --- README.md | 4 ++-- .../src/client/executor/zenstack-query-executor.ts | 10 +++++----- packages/runtime/src/client/plugin.ts | 10 +++++----- packages/runtime/test/plugin/mutation-hooks.test.ts | 4 ++-- 4 files changed, 14 insertions(+), 14 deletions(-) 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..a401d4a1 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) { @@ -350,7 +350,7 @@ describe('Entity lifecycle tests', () => { mutationInterceptionFilter: () => { return { intercept: true, - loadBeforeMutationEntity: true, + loadBeforeMutationEntities: true, loadAfterMutationEntity: true, }; }, From 15462e2f7ea612daf85966e89fb4610f895ed834 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Wed, 13 Aug 2025 20:55:32 +0800 Subject: [PATCH 2/2] update --- packages/runtime/test/plugin/mutation-hooks.test.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/runtime/test/plugin/mutation-hooks.test.ts b/packages/runtime/test/plugin/mutation-hooks.test.ts index a401d4a1..c249e0a6 100644 --- a/packages/runtime/test/plugin/mutation-hooks.test.ts +++ b/packages/runtime/test/plugin/mutation-hooks.test.ts @@ -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) { @@ -351,7 +351,7 @@ describe('Entity lifecycle tests', () => { return { intercept: true, loadBeforeMutationEntities: true, - loadAfterMutationEntity: true, + loadAfterMutationEntities: true, }; }, afterEntityMutation(args) {