Skip to content

Commit 3d88a55

Browse files
authored
fix: improve plugin config typing (#161)
* fix: improve plugin config typing * update
1 parent 8a99a4a commit 3d88a55

File tree

4 files changed

+18
-18
lines changed

4 files changed

+18
-18
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,9 @@ db.$use({
351351
return {
352352
intercept: model === 'User',
353353
// load entities affected before the mutation (defaults to false)
354-
loadBeforeMutationEntity: true,
354+
loadBeforeMutationEntities: true,
355355
// load entities affected after the mutation (defaults to false)
356-
loadAfterMutationEntity: true,
356+
loadAfterMutationEntities: true,
357357
};
358358
},
359359
beforeEntityMutation({ model, action, entities }) {

packages/runtime/src/client/executor/zenstack-query-executor.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
7272
const oldQueryNode = queryNode;
7373
if (
7474
(InsertQueryNode.is(queryNode) || UpdateQueryNode.is(queryNode)) &&
75-
mutationInterceptionInfo?.loadAfterMutationEntity
75+
mutationInterceptionInfo?.loadAfterMutationEntities
7676
) {
7777
// need to make sure the query node has "returnAll"
7878
// for insert and update queries
@@ -283,13 +283,13 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
283283
queryNode,
284284
});
285285
result.intercept ||= filterResult.intercept;
286-
result.loadBeforeMutationEntity ||= filterResult.loadBeforeMutationEntity;
287-
result.loadAfterMutationEntity ||= filterResult.loadAfterMutationEntity;
286+
result.loadBeforeMutationEntities ||= filterResult.loadBeforeMutationEntities;
287+
result.loadAfterMutationEntities ||= filterResult.loadAfterMutationEntities;
288288
}
289289
}
290290

291291
let beforeMutationEntities: Record<string, unknown>[] | undefined;
292-
if (result.loadBeforeMutationEntity && (UpdateQueryNode.is(queryNode) || DeleteQueryNode.is(queryNode))) {
292+
if (result.loadBeforeMutationEntities && (UpdateQueryNode.is(queryNode) || DeleteQueryNode.is(queryNode))) {
293293
beforeMutationEntities = await this.loadEntities(mutationModel, where);
294294
}
295295

@@ -354,7 +354,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
354354

355355
for (const hook of hooks) {
356356
let afterMutationEntities: Record<string, unknown>[] | undefined = undefined;
357-
if (mutationInterceptionInfo.loadAfterMutationEntity) {
357+
if (mutationInterceptionInfo.loadAfterMutationEntities) {
358358
if (InsertQueryNode.is(queryNode) || UpdateQueryNode.is(queryNode)) {
359359
afterMutationEntities = queryResult.rows as Record<string, unknown>[];
360360
}

packages/runtime/src/client/plugin.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ export type MutationInterceptionFilterResult = {
3939
/**
4040
* Whether entities should be loaded before the mutation.
4141
*/
42-
loadBeforeMutationEntity?: boolean;
42+
loadBeforeMutationEntities?: boolean;
4343

4444
/**
4545
* Whether entities should be loaded after the mutation.
4646
*/
47-
loadAfterMutationEntity?: boolean;
47+
loadAfterMutationEntities?: boolean;
4848
};
4949

5050
type MutationHooksArgs<Schema extends SchemaDef> = {
@@ -149,16 +149,16 @@ export interface RuntimePlugin<Schema extends SchemaDef = SchemaDef> {
149149

150150
/**
151151
* Called before an entity is mutated.
152-
* @param args.entity Only available if `loadBeforeMutationEntity` is set to true in the
152+
* @param args.entity Only available if `loadBeforeMutationEntities` is set to true in the
153153
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
154154
*/
155155
beforeEntityMutation?: BeforeEntityMutationCallback<Schema>;
156156

157157
/**
158158
* Called after an entity is mutated.
159-
* @param args.beforeMutationEntity Only available if `loadBeforeMutationEntity` is set to true in the
159+
* @param args.beforeMutationEntity Only available if `loadBeforeMutationEntities` is set to true in the
160160
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
161-
* @param args.afterMutationEntity Only available if `loadAfterMutationEntity` is set to true in the
161+
* @param args.afterMutationEntity Only available if `loadAfterMutationEntities` is set to true in the
162162
* return value of {@link RuntimePlugin.mutationInterceptionFilter}.
163163
*/
164164
afterEntityMutation?: AfterEntityMutationCallback<Schema>;

packages/runtime/test/plugin/mutation-hooks.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ describe('Entity lifecycle tests', () => {
112112
mutationInterceptionFilter: () => {
113113
return {
114114
intercept: true,
115-
loadBeforeMutationEntity: true,
115+
loadBeforeMutationEntities: true,
116116
};
117117
},
118118
beforeEntityMutation(args) {
@@ -159,7 +159,7 @@ describe('Entity lifecycle tests', () => {
159159
mutationInterceptionFilter: () => {
160160
return {
161161
intercept: true,
162-
loadAfterMutationEntity: true,
162+
loadAfterMutationEntities: true,
163163
};
164164
},
165165
afterEntityMutation(args) {
@@ -205,7 +205,7 @@ describe('Entity lifecycle tests', () => {
205205
mutationInterceptionFilter: () => {
206206
return {
207207
intercept: true,
208-
loadAfterMutationEntity: true,
208+
loadAfterMutationEntities: true,
209209
};
210210
},
211211
afterEntityMutation(args) {
@@ -263,7 +263,7 @@ describe('Entity lifecycle tests', () => {
263263
mutationInterceptionFilter: (args) => {
264264
return {
265265
intercept: args.action === 'create' || args.action === 'update',
266-
loadAfterMutationEntity: true,
266+
loadAfterMutationEntities: true,
267267
};
268268
},
269269
afterEntityMutation(args) {
@@ -350,8 +350,8 @@ describe('Entity lifecycle tests', () => {
350350
mutationInterceptionFilter: () => {
351351
return {
352352
intercept: true,
353-
loadBeforeMutationEntity: true,
354-
loadAfterMutationEntity: true,
353+
loadBeforeMutationEntities: true,
354+
loadAfterMutationEntities: true,
355355
};
356356
},
357357
afterEntityMutation(args) {

0 commit comments

Comments
 (0)