Skip to content

Commit e81b8bf

Browse files
authored
feat: make plugins compatible with prisma client extensions (#39)
* feat: make plugins compatible with prisma client extensions * chore: bump version, fix lint * update
1 parent 088c41a commit e81b8bf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+1107
-737
lines changed

.vscode/tasks.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
},
1919
{
2020
"label": "Build all - watch",
21-
"command": "pnpm watch",
21+
"command": "turbo watch build",
2222
"type": "shell",
2323
"group": {
2424
"kind": "build"
@@ -28,6 +28,16 @@
2828
"id": "server-process"
2929
}
3030
},
31+
{
32+
"label": "Lint all",
33+
"command": "pnpm lint",
34+
"type": "shell",
35+
"icon": {
36+
"color": "terminal.ansiYellow",
37+
"id": "server-process"
38+
},
39+
"problemMatcher": []
40+
},
3141
{
3242
"label": "Test all",
3343
"command": "pnpm test",

NEW-FEATURES.md

Lines changed: 0 additions & 2 deletions
This file was deleted.

README.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -280,16 +280,20 @@ You can use a plugin to achieve the following goals:
280280
281281
#### 1. ORM query interception
282282
283-
ORM query interception allows you to intercept the high-level ORM API calls.
283+
ORM query interception allows you to intercept the high-level ORM API calls. The interceptor's configuration is compatible with Prisma's [query client extension](https://www.prisma.io/docs/orm/prisma-client/client-extensions/query).
284284
285285
```ts
286286
client.$use({
287287
id: 'cost-logger',
288-
async onQuery({ model, operation, proceed, queryArgs }) {
289-
const start = Date.now();
290-
const result = await proceed(queryArgs);
291-
console.log(`[cost] ${model} ${operation} took ${Date.now() - start}ms`);
292-
return result;
288+
onQuery: {
289+
$allModels: {
290+
$allOperations: async ({ model, operation, args, query }) => {
291+
const start = Date.now();
292+
const result = await query(args);
293+
console.log(`[cost] ${model} ${operation} took ${Date.now() - start}ms`);
294+
return result;
295+
},
296+
},
293297
},
294298
});
295299
```

TODO.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,11 @@
5151
- [x] Count
5252
- [x] Aggregate
5353
- [x] Group by
54+
- [ ] Raw queries
5455
- [ ] Extensions
5556
- [x] Query builder API
5657
- [x] Computed fields
57-
- [ ] Prisma client extension
58+
- [x] Prisma client extension
5859
- [ ] Misc
5960
- [x] JSDoc for CRUD methods
6061
- [x] Cache validation schemas
@@ -66,7 +67,8 @@
6667
- [ ] Error system
6768
- [x] Custom table name
6869
- [x] Custom field name
69-
- [ ] Implement changesets
70+
- [ ] Strict undefined checks
71+
- [ ] Benchmark
7072
- [ ] Polymorphism
7173
- [ ] Validation
7274
- [ ] Access Policy

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-v3",
3-
"version": "3.0.0-alpha.4",
3+
"version": "3.0.0-alpha.5",
44
"description": "ZenStack",
55
"packageManager": "[email protected]",
66
"scripts": {

packages/cli/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "zenstack",
44
"displayName": "ZenStack CLI",
55
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
6-
"version": "3.0.0-alpha.4",
6+
"version": "3.0.0-alpha.5",
77
"type": "module",
88
"author": {
99
"name": "ZenStack Team"
@@ -22,20 +22,21 @@
2222
},
2323
"scripts": {
2424
"build": "tsup-node",
25+
"watch": "tsup-node --watch",
2526
"lint": "eslint src --ext ts",
2627
"test": "vitest run",
2728
"pack": "pnpm pack"
2829
},
2930
"dependencies": {
3031
"@zenstackhq/language": "workspace:*",
3132
"@zenstackhq/sdk": "workspace:*",
33+
"@zenstackhq/common-helpers": "workspace:*",
3234
"async-exit-hook": "^2.0.1",
3335
"colors": "1.4.0",
3436
"commander": "^8.3.0",
3537
"langium": "catalog:",
3638
"ora": "^5.4.1",
3739
"package-manager-detector": "^1.3.0",
38-
"tiny-invariant": "^1.3.3",
3940
"ts-pattern": "catalog:"
4041
},
4142
"peerDependencies": {

packages/cli/src/actions/generate.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1+
import { invariant } from '@zenstackhq/common-helpers';
12
import { isPlugin, LiteralExpr, type Model } from '@zenstackhq/language/ast';
2-
import type { CliGenerator } from '@zenstackhq/runtime/client';
3-
import { PrismaSchemaGenerator, TsSchemaGenerator } from '@zenstackhq/sdk';
3+
import { PrismaSchemaGenerator, TsSchemaGenerator, type CliGenerator } from '@zenstackhq/sdk';
44
import colors from 'colors';
55
import fs from 'node:fs';
66
import path from 'node:path';
7-
import invariant from 'tiny-invariant';
87
import { getSchemaFile, loadSchemaDocument } from './action-utils';
98

109
type Options = {
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import config from '@zenstackhq/eslint-config/base.js';
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default config;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"name": "@zenstackhq/common-helpers",
3+
"version": "3.0.0-alpha.5",
4+
"description": "ZenStack Common Helpers",
5+
"type": "module",
6+
"scripts": {
7+
"build": "tsup-node",
8+
"watch": "tsup-node --watch",
9+
"lint": "eslint src --ext ts",
10+
"pack": "pnpm pack"
11+
},
12+
"keywords": [],
13+
"author": "ZenStack Team",
14+
"license": "MIT",
15+
"files": [
16+
"dist"
17+
],
18+
"exports": {
19+
".": {
20+
"import": {
21+
"types": "./dist/index.d.ts",
22+
"default": "./dist/index.js"
23+
},
24+
"require": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
28+
}
29+
},
30+
"devDependencies": {
31+
"@zenstackhq/typescript-config": "workspace:*",
32+
"@zenstackhq/eslint-config": "workspace:*"
33+
}
34+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export * from './is-plain-object';
2+
export * from './lower-case-first';
3+
export * from './param-case';
4+
export * from './sleep';
5+
export * from './tiny-invariant';
6+
export * from './upper-case-first';

0 commit comments

Comments
 (0)