Skip to content

Commit cebd9d4

Browse files
authored
Merge pull request #359 from zenstackhq/dev
merge dev to main (v3.0.0-beta.16)
2 parents ead10f7 + 5dc0087 commit cebd9d4

File tree

89 files changed

+7803
-439
lines changed

Some content is hidden

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

89 files changed

+7803
-439
lines changed

.github/workflows/update-samples.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ jobs:
9595
npm install "$pkg@next"
9696
done
9797
98-
# Finally run zenstack generate
99-
npx zen generate
98+
# Finally run generate
99+
npm run generate
100100
101101
- name: Commit and push changes
102102
if: steps.check-package.outputs.exists == 'true'

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Even without using advanced features, ZenStack offers the following benefits as
5151
5252
# Quick start
5353

54-
> You can also check the [blog sample](./samples/blog) for a complete example.
54+
- [ORM](./samples/orm): A simple example demonstrating ZenStack ORM usage.
55+
- [Next.js + TanStack Query](./samples/next.js): A full-stack sample demonstrating using TanStack Query to consume ZenStack's automatic CRUD services in a Next.js app.
5556

5657
## Installation
5758

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-v3",
3-
"version": "3.0.0-beta.15",
3+
"version": "3.0.0-beta.16",
44
"description": "ZenStack",
55
"packageManager": "[email protected]",
66
"scripts": {
@@ -31,7 +31,8 @@
3131
"typescript": "catalog:",
3232
"typescript-eslint": "^8.34.1",
3333
"vitest": "^3.2.4",
34-
"yaml": "^2.8.0"
34+
"yaml": "^2.8.0",
35+
"prisma": "catalog:"
3536
},
3637
"pnpm": {
3738
"onlyBuiltDependencies": [

packages/cli/package.json

Lines changed: 2 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-beta.15",
6+
"version": "3.0.0-beta.16",
77
"type": "module",
88
"author": {
99
"name": "ZenStack Team"
@@ -45,7 +45,7 @@
4545
"prisma": "catalog:"
4646
},
4747
"devDependencies": {
48-
"@types/better-sqlite3": "^7.6.13",
48+
"@types/better-sqlite3": "catalog:",
4949
"@types/semver": "^7.7.0",
5050
"@types/tmp": "catalog:",
5151
"@zenstackhq/eslint-config": "workspace:*",

packages/cli/src/actions/generate.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ type Options = {
1313
schema?: string;
1414
output?: string;
1515
silent: boolean;
16+
lite: boolean;
17+
liteOnly: boolean;
1618
};
1719

1820
/**
@@ -88,10 +90,15 @@ async function runPlugins(schemaFile: string, model: Model, outputPath: string,
8890
}
8991
}
9092

91-
const defaultPlugins = [corePlugins['typescript']].reverse();
92-
defaultPlugins.forEach((d) => {
93-
if (!processedPlugins.some((p) => p.cliPlugin === d)) {
94-
processedPlugins.push({ cliPlugin: d, pluginOptions: {} });
93+
const defaultPlugins = [
94+
{
95+
plugin: corePlugins['typescript'],
96+
options: { lite: options.lite, liteOnly: options.liteOnly },
97+
},
98+
];
99+
defaultPlugins.forEach(({ plugin, options }) => {
100+
if (!processedPlugins.some((p) => p.cliPlugin === plugin)) {
101+
processedPlugins.push({ cliPlugin: plugin, pluginOptions: options });
95102
}
96103
});
97104

packages/cli/src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,8 @@ function createProgram() {
5959
.addOption(schemaOption)
6060
.addOption(noVersionCheckOption)
6161
.addOption(new Option('-o, --output <path>', 'default output directory for code generation'))
62+
.addOption(new Option('--lite', 'also generate a lite version of schema without attributes').default(false))
63+
.addOption(new Option('--lite-only', 'only generate lite version of schema without attributes').default(false))
6264
.addOption(new Option('--silent', 'suppress all output except errors').default(false))
6365
.action(generateAction);
6466

packages/cli/src/plugins/typescript.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,22 @@ const plugin: CliPlugin = {
77
name: 'TypeScript Schema Generator',
88
statusText: 'Generating TypeScript schema',
99
async generate({ model, defaultOutputPath, pluginOptions }) {
10+
// output path
1011
let outDir = defaultOutputPath;
1112
if (typeof pluginOptions['output'] === 'string') {
1213
outDir = path.resolve(defaultOutputPath, pluginOptions['output']);
1314
if (!fs.existsSync(outDir)) {
1415
fs.mkdirSync(outDir, { recursive: true });
1516
}
1617
}
17-
await new TsSchemaGenerator().generate(model, outDir);
18+
19+
// lite mode
20+
const lite = pluginOptions['lite'] === true;
21+
22+
// liteOnly mode
23+
const liteOnly = pluginOptions['liteOnly'] === true;
24+
25+
await new TsSchemaGenerator().generate(model, { outDir, lite, liteOnly });
1826
},
1927
};
2028

packages/cli/test/generate.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,18 @@ describe('CLI generate command test', () => {
4444
runCli('generate', workDir);
4545
expect(fs.existsSync(path.join(workDir, 'bar/schema.ts'))).toBe(true);
4646
});
47+
48+
it('should respect lite option', () => {
49+
const workDir = createProject(model);
50+
runCli('generate --lite', workDir);
51+
expect(fs.existsSync(path.join(workDir, 'zenstack/schema.ts'))).toBe(true);
52+
expect(fs.existsSync(path.join(workDir, 'zenstack/schema-lite.ts'))).toBe(true);
53+
});
54+
55+
it('should respect liteOnly option', () => {
56+
const workDir = createProject(model);
57+
runCli('generate --lite-only', workDir);
58+
expect(fs.existsSync(path.join(workDir, 'zenstack/schema.ts'))).toBe(false);
59+
expect(fs.existsSync(path.join(workDir, 'zenstack/schema-lite.ts'))).toBe(true);
60+
});
4761
});

packages/cli/test/ts-schema-gen.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,4 +420,26 @@ model User {
420420
},
421421
});
422422
});
423+
424+
it('supports lite schema generation', async () => {
425+
const { schemaLite } = await generateTsSchema(
426+
`
427+
model User {
428+
id String @id @default(uuid())
429+
name String
430+
email String @unique
431+
432+
@@map('users')
433+
}
434+
`,
435+
undefined,
436+
undefined,
437+
undefined,
438+
true,
439+
);
440+
441+
expect(schemaLite!.models.User.attributes).toBeUndefined();
442+
expect(schemaLite!.models.User.fields.id.attributes).toBeUndefined();
443+
expect(schemaLite!.models.User.fields.email.attributes).toBeUndefined();
444+
});
423445
});

0 commit comments

Comments
 (0)