Skip to content

Commit 979a6fd

Browse files
committed
chore: rename query function to proceed for onquery plugin
1 parent b57827a commit 979a6fd

File tree

5 files changed

+17
-17
lines changed

5 files changed

+17
-17
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ ORM query interception allows you to intercept the high-level ORM API calls. The
289289
```ts
290290
db.$use({
291291
id: 'cost-logger',
292-
onQuery: async ({ model, operation, args, query }) => {
292+
onQuery: async ({ model, operation, args, proceed }) => {
293293
const start = Date.now();
294-
const result = await query(args);
294+
const result = await proceed(args);
295295
console.log(`[cost] ${model} ${operation} took ${Date.now() - start}ms`);
296296
return result;
297297
},

packages/runtime/src/client/client-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function createModelCrudHandler<Schema extends SchemaDef, Model extends GetModel
379379
const onQuery = plugin.onQuery;
380380
if (onQuery) {
381381
const _proceed = proceed;
382-
proceed = () => onQuery({ client, model, operation, args, query: _proceed }) as Promise<unknown>;
382+
proceed = () => onQuery({ client, model, operation, args, proceed: _proceed }) as Promise<unknown>;
383383
}
384384
}
385385

packages/runtime/src/client/plugin.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,12 @@ type OnQueryHookContext<Schema extends SchemaDef> = {
6969
args: unknown;
7070

7171
/**
72-
* The query function to proceed with the original query.
72+
* The function to proceed with the original query.
7373
* It takes the same arguments as the operation method.
7474
*
7575
* @param args The query arguments.
7676
*/
77-
query: (args: unknown) => Promise<unknown>;
77+
proceed: (args: unknown) => Promise<unknown>;
7878

7979
/**
8080
* The ZenStack client that is performing the operation.

packages/runtime/test/plugin/on-query-hooks.test.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('On query hooks tests', () => {
3535
} else if (ctx.operation === 'update') {
3636
updateHookCalled = true;
3737
}
38-
return ctx.query(ctx.args);
38+
return ctx.proceed(ctx.args);
3939
},
4040
});
4141

@@ -61,7 +61,7 @@ describe('On query hooks tests', () => {
6161
hooksCalled = true;
6262
expect(ctx.model).toBe('User');
6363
}
64-
return ctx.query(ctx.args);
64+
return ctx.proceed(ctx.args);
6565
},
6666
});
6767
await expect(
@@ -84,7 +84,7 @@ describe('On query hooks tests', () => {
8484
hooksCalled = true;
8585
expect(ctx.model).toBe('User');
8686
expect(ctx.operation).toBe('findFirst');
87-
return ctx.query(ctx.args);
87+
return ctx.proceed(ctx.args);
8888
},
8989
});
9090
await expect(
@@ -106,9 +106,9 @@ describe('On query hooks tests', () => {
106106
onQuery: async (ctx) => {
107107
if (ctx.model === 'User' && ctx.operation === 'findFirst') {
108108
hooksCalled = true;
109-
return ctx.query({ where: { id: 'non-exist' } });
109+
return ctx.proceed({ where: { id: 'non-exist' } });
110110
} else {
111-
return ctx.query(ctx.args);
111+
return ctx.proceed(ctx.args);
112112
}
113113
},
114114
});
@@ -132,11 +132,11 @@ describe('On query hooks tests', () => {
132132
onQuery: async (ctx) => {
133133
if (ctx.model === 'User' && ctx.operation === 'findFirst') {
134134
hooksCalled = true;
135-
const result = await ctx.query(ctx.args);
135+
const result = await ctx.proceed(ctx.args);
136136
(result as any).happy = true;
137137
return result;
138138
} else {
139-
return ctx.query(ctx.args);
139+
return ctx.proceed(ctx.args);
140140
}
141141
},
142142
});
@@ -159,10 +159,10 @@ describe('On query hooks tests', () => {
159159
onQuery: async (ctx) => {
160160
if (ctx.model === 'User' && ctx.operation === 'create') {
161161
hooksCalled = true;
162-
await ctx.query(ctx.args);
162+
await ctx.proceed(ctx.args);
163163
throw new Error('trigger error');
164164
} else {
165-
return ctx.query(ctx.args);
165+
return ctx.proceed(ctx.args);
166166
}
167167
},
168168
});
@@ -194,7 +194,7 @@ describe('On query hooks tests', () => {
194194
id: 'test-plugin',
195195
onQuery: (ctx) => {
196196
findHookCalled = true;
197-
return ctx.query(ctx.args);
197+
return ctx.proceed(ctx.args);
198198
},
199199
});
200200

samples/blog/main.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ async function main() {
1717
},
1818
}).$use({
1919
id: 'cost-logger',
20-
onQuery: async ({ model, operation, args, query }) => {
20+
onQuery: async ({ model, operation, args, proceed }) => {
2121
const start = Date.now();
22-
const result = await query(args);
22+
const result = await proceed(args);
2323
console.log(`[cost] ${model} ${operation} took ${Date.now() - start}ms`);
2424
return result;
2525
},

0 commit comments

Comments
 (0)