Skip to content

Commit

Permalink
feat: react-hooks generator and runtime targeting @tanstack/react-que…
Browse files Browse the repository at this point in the history
…ry (zenstackhq#309)

Co-authored-by: Jonathan Gerbaud <jonathan.gerbaud@abewy.com>
  • Loading branch information
ymc9 and jonathangerbaud authored Mar 30, 2023
1 parent 955e657 commit 21ccddb
Show file tree
Hide file tree
Showing 24 changed files with 2,784 additions and 2,063 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "1.0.0-alpha.87",
"version": "1.0.0-alpha.94",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/language",
"version": "1.0.0-alpha.87",
"version": "1.0.0-alpha.94",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
9 changes: 4 additions & 5 deletions packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/next",
"version": "1.0.0-alpha.87",
"version": "1.0.0-alpha.94",
"displayName": "ZenStack Next.js integration",
"description": "ZenStack Next.js integration",
"homepage": "https://zenstack.dev",
Expand All @@ -21,12 +21,10 @@
"author": "",
"license": "MIT",
"peerDependencies": {
"next": "^12.3.1 || ^13",
"react": "^17.0.2 || ^18"
"next": "^12.3.1 || ^13"
},
"dependencies": {
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/testtools": "workspace:*",
"tmp": "^0.2.1"
},
"devDependencies": {
Expand All @@ -40,6 +38,7 @@
"superjson": "^1.11.0",
"supertest": "^6.3.3",
"ts-jest": "^29.0.5",
"typescript": "^4.9.4"
"typescript": "^4.9.4",
"@zenstackhq/testtools": "workspace:*"
}
}
2 changes: 1 addition & 1 deletion packages/plugins/openapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/openapi",
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
"version": "1.0.0-alpha.87",
"version": "1.0.0-alpha.94",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down
15 changes: 10 additions & 5 deletions packages/plugins/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/react",
"displayName": "ZenStack plugin and runtime for ReactJS",
"version": "1.0.0-alpha.87",
"version": "1.0.0-alpha.94",
"description": "ZenStack plugin and runtime for ReactJS",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -29,22 +29,27 @@
"change-case": "^4.1.2",
"decimal.js": "^10.4.2",
"superjson": "^1.11.0",
"swr": "^2.0.3",
"ts-morph": "^16.0.0"
},
"peerDependencies": {
"react": "^17.0.2 || ^18",
"react-dom": "^17.0.2 || ^18"
"react-dom": "^17.0.2 || ^18",
"swr": "2.x",
"@tanstack/react-query": "4.x"
},
"devDependencies": {
"@tanstack/react-query": "^4.28.0",
"@types/jest": "^29.5.0",
"@types/react": "^18.0.26",
"@types/tmp": "^0.2.3",
"@zenstackhq/testtools": "workspace:*",
"copyfiles": "^2.4.1",
"jest": "^29.5.0",
"rimraf": "^3.0.2",
"react": "^17.0.2 || ^18",
"react-dom": "^17.0.2 || ^18",
"swr": "^2.0.3",
"ts-jest": "^29.0.5",
"typescript": "^4.9.4",
"@zenstackhq/testtools": "workspace:*"
"typescript": "^4.9.4"
}
}
17 changes: 17 additions & 0 deletions packages/plugins/react/src/generator/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import type { DMMF } from '@prisma/generator-helper';
import { PluginError, type PluginOptions } from '@zenstackhq/sdk';
import type { Model } from '@zenstackhq/sdk/ast';
import { generate as reactQueryGenerate } from './react-query';
import { generate as swrGenerate } from './swr';

export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
const fetcher = (options.fetcher as string) ?? 'swr';
switch (fetcher) {
case 'swr':
return swrGenerate(model, options, dmmf);
case 'react-query':
return reactQueryGenerate(model, options, dmmf);
default:
throw new PluginError(`Unknown "fetcher" option: ${fetcher}, use "swr" or "react-query"`);
}
}
Loading

0 comments on commit 21ccddb

Please sign in to comment.