Skip to content

Commit f9fd2e5

Browse files
authored
merge dev to main (v1.2.0) (#794)
2 parents 6fb649e + 600d13b commit f9fd2e5

Some content is hidden

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

77 files changed

+4495
-993
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -174,14 +174,27 @@ The following diagram gives a high-level architecture overview of ZenStack.
174174

175175
## Examples
176176

177+
### Todo SaaS App
178+
177179
Check out the [Collaborative Todo App](https://zenstack-todo.vercel.app/) for a running example. You can find different implementations below:
178180

179-
- [Next.js + SWR hooks](https://github.com/zenstackhq/sample-todo-nextjs)
180-
- [Next.js + TanStack Query](https://github.com/zenstackhq/sample-todo-nextjs-tanstack)
181-
- [Next.js + tRPC](https://github.com/zenstackhq/sample-todo-trpc)
182-
- [Nuxt + TanStack Query](https://github.com/zenstackhq/sample-todo-nuxt)
181+
- [Next.js 13 + NextAuth + SWR](https://github.com/zenstackhq/sample-todo-nextjs)
182+
- [Next.js 13 + NextAuth + TanStack Query](https://github.com/zenstackhq/sample-todo-nextjs-tanstack)
183+
- [Next.js 13 + NextAuth + tRPC](https://github.com/zenstackhq/sample-todo-trpc)
184+
- [Nuxt V3 + TanStack Query](https://github.com/zenstackhq/sample-todo-nuxt)
183185
- [SvelteKit + TanStack Query](https://github.com/zenstackhq/sample-todo-sveltekit)
184186

187+
### Blog App
188+
189+
- [Next.js 13 + Pages Route + SWR](https://github.com/zenstackhq/docs-tutorial-nextjs)
190+
- [Next.js 13 + App Route + SWR](https://github.com/zenstackhq/docs-tutorial-nextjs-app-dir)
191+
- [Next.js 13 + App Route + tRPC](https://github.com/zenstackhq/sample-blog-nextjs-app-trpc)
192+
- [Nuxt V3 + TanStack Query](https://github.com/zenstackhq/docs-tutorial-nuxt)
193+
- [SvelteKit](https://github.com/zenstackhq/docs-tutorial-sveltekit)
194+
- [Remix](https://github.com/zenstackhq/docs-tutorial-remix)
195+
- [Express Backend API](https://github.com/zenstackhq/docs-tutorial-express)
196+
- [Clerk Integration](https://github.com/zenstackhq/docs-tutorial-clerk)
197+
185198
## Community
186199

187200
Join our [discord server](https://discord.gg/Ykhr738dUe) for chat and updates!

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.1.1",
3+
"version": "1.2.0",
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.1.1",
3+
"version": "1.2.0",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",

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.1.1",
4+
"version": "1.2.0",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {

packages/plugins/openapi/src/rest-generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as path from 'path';
1919
import pluralize from 'pluralize';
2020
import invariant from 'tiny-invariant';
2121
import YAML from 'yaml';
22+
import { name } from '.';
2223
import { OpenAPIGeneratorBase } from './generator-base';
2324
import { getModelResourceMeta } from './meta';
2425

@@ -31,7 +32,7 @@ export class RESTfulOpenAPIGenerator extends OpenAPIGeneratorBase {
3132
private warnings: string[] = [];
3233

3334
generate() {
34-
let output = requireOption<string>(this.options, 'output');
35+
let output = requireOption<string>(this.options, 'output', name);
3536
output = resolvePath(output, this.options);
3637

3738
const components = this.generateComponents();

packages/plugins/openapi/src/rpc-generator.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import * as path from 'path';
1818
import invariant from 'tiny-invariant';
1919
import { upperCaseFirst } from 'upper-case-first';
2020
import YAML from 'yaml';
21+
import { name } from '.';
2122
import { OpenAPIGeneratorBase } from './generator-base';
2223
import { getModelResourceMeta } from './meta';
2324

@@ -32,7 +33,7 @@ export class RPCOpenAPIGenerator extends OpenAPIGeneratorBase {
3233
private warnings: string[] = [];
3334

3435
generate() {
35-
let output = requireOption<string>(this.options, 'output');
36+
let output = requireOption<string>(this.options, 'output', name);
3637
output = resolvePath(output, this.options);
3738

3839
// input types

packages/plugins/swr/package.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/swr",
33
"displayName": "ZenStack plugin for generating SWR hooks",
4-
"version": "1.1.1",
4+
"version": "1.2.0",
55
"description": "ZenStack plugin for generating SWR hooks",
66
"main": "index.js",
77
"repository": {
@@ -29,6 +29,7 @@
2929
"@zenstackhq/runtime": "workspace:*",
3030
"@zenstackhq/sdk": "workspace:*",
3131
"change-case": "^4.1.2",
32+
"cross-fetch": "^4.0.0",
3233
"decimal.js": "^10.4.2",
3334
"lower-case-first": "^2.0.2",
3435
"semver": "^7.3.8",
@@ -37,6 +38,7 @@
3738
},
3839
"devDependencies": {
3940
"@tanstack/react-query": "^4.28.0",
41+
"@testing-library/react": "^14.0.0",
4042
"@types/jest": "^29.5.0",
4143
"@types/node": "^18.0.0",
4244
"@types/react": "18.2.0",
@@ -45,6 +47,7 @@
4547
"@zenstackhq/testtools": "workspace:*",
4648
"copyfiles": "^2.4.1",
4749
"jest": "^29.5.0",
50+
"nock": "^13.3.6",
4851
"react": "18.2.0",
4952
"rimraf": "^3.0.2",
5053
"swr": "^2.0.3",

packages/plugins/swr/src/generator.ts

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { DMMF } from '@prisma/generator-helper';
22
import {
33
PluginOptions,
44
createProject,
5+
generateModelMeta,
56
getDataModels,
67
getPrismaClientImportSpec,
78
getPrismaVersion,
@@ -16,9 +17,10 @@ import path from 'path';
1617
import semver from 'semver';
1718
import { FunctionDeclaration, OptionalKind, ParameterDeclarationStructure, Project, SourceFile } from 'ts-morph';
1819
import { upperCaseFirst } from 'upper-case-first';
20+
import { name } from '.';
1921

2022
export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
21-
let outDir = requireOption<string>(options, 'output');
23+
let outDir = requireOption<string>(options, 'output', name);
2224
outDir = resolvePath(outDir, options);
2325

2426
const project = createProject();
@@ -32,6 +34,8 @@ export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.
3234

3335
const models = getDataModels(model);
3436

37+
await generateModelMeta(project, models, path.join(outDir, '__model_meta.ts'), false, true);
38+
3539
generateIndex(project, outDir, models);
3640

3741
models.forEach((dataModel) => {
@@ -60,24 +64,20 @@ function generateModelHooks(project: Project, outDir: string, model: DataModel,
6064
moduleSpecifier: prismaImport,
6165
});
6266
sf.addStatements([
63-
`import { useContext } from 'react';`,
64-
`import { RequestHandlerContext, type GetNextArgs, type RequestOptions, type InfiniteRequestOptions, type PickEnumerable, type CheckSelect } from '@zenstackhq/swr/runtime';`,
67+
`import { RequestHandlerContext, type GetNextArgs, type RequestOptions, type InfiniteRequestOptions, type PickEnumerable, type CheckSelect, useHooksContext } from '@zenstackhq/swr/runtime';`,
68+
`import metadata from './__model_meta';`,
6569
`import * as request from '@zenstackhq/swr/runtime';`,
6670
]);
6771

6872
const modelNameCap = upperCaseFirst(model.name);
6973
const prismaVersion = getPrismaVersion();
7074

71-
const prefixesToMutate = ['find', 'aggregate', 'count', 'groupBy'];
7275
const useMutation = sf.addFunction({
7376
name: `useMutate${model.name}`,
7477
isExported: true,
7578
statements: [
76-
'const { endpoint, fetch } = useContext(RequestHandlerContext);',
77-
`const prefixesToMutate = [${prefixesToMutate
78-
.map((prefix) => '`${endpoint}/' + lowerCaseFirst(model.name) + '/' + prefix + '`')
79-
.join(', ')}];`,
80-
'const mutate = request.getMutate(prefixesToMutate);',
79+
'const { endpoint, fetch, logging } = useHooksContext();',
80+
`const mutate = request.useMutate('${model.name}', metadata, logging);`,
8181
],
8282
});
8383
const mutationFuncs: string[] = [];
@@ -297,8 +297,6 @@ function generateQueryHook(
297297
typeParameters?: string[],
298298
infinite = false
299299
) {
300-
const modelRouteName = lowerCaseFirst(model.name);
301-
302300
const typeParams = typeParameters ? [...typeParameters] : [`T extends ${argsType}`];
303301
if (infinite) {
304302
typeParams.push(`R extends ${returnType}`);
@@ -329,10 +327,10 @@ function generateQueryHook(
329327
})
330328
.addBody()
331329
.addStatements([
332-
'const { endpoint, fetch } = useContext(RequestHandlerContext);',
330+
'const { endpoint, fetch } = useHooksContext();',
333331
!infinite
334-
? `return request.get<${returnType}>(\`\${endpoint}/${modelRouteName}/${operation}\`, args, options, fetch);`
335-
: `return request.infiniteGet<${inputType} | undefined, ${returnType}>(\`\${endpoint}/${modelRouteName}/${operation}\`, getNextArgs, options, fetch);`,
332+
? `return request.useGet<${returnType}>('${model.name}', '${operation}', endpoint, args, options, fetch);`
333+
: `return request.useInfiniteGet<${inputType} | undefined, ${returnType}>('${model.name}', '${operation}', endpoint, getNextArgs, options, fetch);`,
336334
]);
337335
}
338336

0 commit comments

Comments
 (0)