Skip to content
This repository was archived by the owner on Apr 23, 2025. It is now read-only.

Commit 21ccddb

Browse files
feat: react-hooks generator and runtime targeting @tanstack/react-query (zenstackhq#309)
Co-authored-by: Jonathan Gerbaud <jonathan.gerbaud@abewy.com>
1 parent 955e657 commit 21ccddb

File tree

24 files changed

+2784
-2063
lines changed

24 files changed

+2784
-2063
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "1.0.0-alpha.87",
3+
"version": "1.0.0-alpha.94",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/language",
3-
"version": "1.0.0-alpha.87",
3+
"version": "1.0.0-alpha.94",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",

packages/next/package.json

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/next",
3-
"version": "1.0.0-alpha.87",
3+
"version": "1.0.0-alpha.94",
44
"displayName": "ZenStack Next.js integration",
55
"description": "ZenStack Next.js integration",
66
"homepage": "https://zenstack.dev",
@@ -21,12 +21,10 @@
2121
"author": "",
2222
"license": "MIT",
2323
"peerDependencies": {
24-
"next": "^12.3.1 || ^13",
25-
"react": "^17.0.2 || ^18"
24+
"next": "^12.3.1 || ^13"
2625
},
2726
"dependencies": {
2827
"@zenstackhq/runtime": "workspace:*",
29-
"@zenstackhq/testtools": "workspace:*",
3028
"tmp": "^0.2.1"
3129
},
3230
"devDependencies": {
@@ -40,6 +38,7 @@
4038
"superjson": "^1.11.0",
4139
"supertest": "^6.3.3",
4240
"ts-jest": "^29.0.5",
43-
"typescript": "^4.9.4"
41+
"typescript": "^4.9.4",
42+
"@zenstackhq/testtools": "workspace:*"
4443
}
4544
}

packages/plugins/openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/openapi",
33
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
4-
"version": "1.0.0-alpha.87",
4+
"version": "1.0.0-alpha.94",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {

packages/plugins/react/package.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/react",
33
"displayName": "ZenStack plugin and runtime for ReactJS",
4-
"version": "1.0.0-alpha.87",
4+
"version": "1.0.0-alpha.94",
55
"description": "ZenStack plugin and runtime for ReactJS",
66
"main": "index.js",
77
"repository": {
@@ -29,22 +29,27 @@
2929
"change-case": "^4.1.2",
3030
"decimal.js": "^10.4.2",
3131
"superjson": "^1.11.0",
32-
"swr": "^2.0.3",
3332
"ts-morph": "^16.0.0"
3433
},
3534
"peerDependencies": {
3635
"react": "^17.0.2 || ^18",
37-
"react-dom": "^17.0.2 || ^18"
36+
"react-dom": "^17.0.2 || ^18",
37+
"swr": "2.x",
38+
"@tanstack/react-query": "4.x"
3839
},
3940
"devDependencies": {
41+
"@tanstack/react-query": "^4.28.0",
4042
"@types/jest": "^29.5.0",
4143
"@types/react": "^18.0.26",
4244
"@types/tmp": "^0.2.3",
45+
"@zenstackhq/testtools": "workspace:*",
4346
"copyfiles": "^2.4.1",
4447
"jest": "^29.5.0",
4548
"rimraf": "^3.0.2",
49+
"react": "^17.0.2 || ^18",
50+
"react-dom": "^17.0.2 || ^18",
51+
"swr": "^2.0.3",
4652
"ts-jest": "^29.0.5",
47-
"typescript": "^4.9.4",
48-
"@zenstackhq/testtools": "workspace:*"
53+
"typescript": "^4.9.4"
4954
}
5055
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import type { DMMF } from '@prisma/generator-helper';
2+
import { PluginError, type PluginOptions } from '@zenstackhq/sdk';
3+
import type { Model } from '@zenstackhq/sdk/ast';
4+
import { generate as reactQueryGenerate } from './react-query';
5+
import { generate as swrGenerate } from './swr';
6+
7+
export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
8+
const fetcher = (options.fetcher as string) ?? 'swr';
9+
switch (fetcher) {
10+
case 'swr':
11+
return swrGenerate(model, options, dmmf);
12+
case 'react-query':
13+
return reactQueryGenerate(model, options, dmmf);
14+
default:
15+
throw new PluginError(`Unknown "fetcher" option: ${fetcher}, use "swr" or "react-query"`);
16+
}
17+
}

0 commit comments

Comments
 (0)