Skip to content

Commit 30fc2fa

Browse files
authored
Merge pull request #119 from zenstackhq/dev
merge dev to main (v3.0.0-alpha.13)
2 parents ed6cfe6 + a0c79b0 commit 30fc2fa

File tree

145 files changed

+8746
-2470
lines changed

Some content is hidden

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

145 files changed

+8746
-2470
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
name: Claude Code Review
2+
3+
on:
4+
pull_request:
5+
types: [opened, synchronize]
6+
# Optional: Only run on specific file changes
7+
# paths:
8+
# - "src/**/*.ts"
9+
# - "src/**/*.tsx"
10+
# - "src/**/*.js"
11+
# - "src/**/*.jsx"
12+
13+
jobs:
14+
claude-review:
15+
# Optional: Filter by PR author
16+
# if: |
17+
# github.event.pull_request.user.login == 'external-contributor' ||
18+
# github.event.pull_request.user.login == 'new-developer' ||
19+
# github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR'
20+
21+
runs-on: ubuntu-latest
22+
permissions:
23+
contents: read
24+
pull-requests: write
25+
issues: read
26+
id-token: write
27+
28+
steps:
29+
- name: Checkout repository
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 1
33+
34+
- name: Run Claude Code Review
35+
id: claude-review
36+
uses: anthropics/claude-code-action@beta
37+
with:
38+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
39+
40+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
41+
# model: "claude-opus-4-20250514"
42+
43+
# Direct prompt for automated review (no @claude mention needed)
44+
direct_prompt: |
45+
Please review this pull request and provide feedback on:
46+
- Code quality and best practices
47+
- Potential bugs or issues
48+
- Performance considerations
49+
- Security concerns
50+
- Test coverage
51+
52+
Be constructive and helpful in your feedback.
53+
54+
# Optional: Use sticky comments to make Claude reuse the same comment on subsequent pushes to the same PR
55+
# use_sticky_comment: true
56+
57+
# Optional: Customize review based on file types
58+
# direct_prompt: |
59+
# Review this PR focusing on:
60+
# - For TypeScript files: Type safety and proper interface usage
61+
# - For API endpoints: Security, input validation, and error handling
62+
# - For React components: Performance, accessibility, and best practices
63+
# - For tests: Coverage, edge cases, and test quality
64+
65+
# Optional: Different prompts for different authors
66+
# direct_prompt: |
67+
# ${{ github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' &&
68+
# 'Welcome! Please review this PR from a first-time contributor. Be encouraging and provide detailed explanations for any suggestions.' ||
69+
# 'Please provide a thorough code review focusing on our coding standards and best practices.' }}
70+
71+
# Optional: Add specific tools for running tests or linting
72+
# allowed_tools: "Bash(npm run test),Bash(npm run lint),Bash(npm run typecheck)"
73+
74+
# Optional: Skip review for certain conditions
75+
# if: |
76+
# !contains(github.event.pull_request.title, '[skip-review]') &&
77+
# !contains(github.event.pull_request.title, '[WIP]')

.github/workflows/claude.yml

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
name: Claude Code
2+
3+
on:
4+
issue_comment:
5+
types: [created]
6+
pull_request_review_comment:
7+
types: [created]
8+
issues:
9+
types: [opened, assigned]
10+
pull_request_review:
11+
types: [submitted]
12+
13+
jobs:
14+
claude:
15+
if: |
16+
(github.event_name == 'issue_comment' && contains(github.event.comment.body, '@claude')) ||
17+
(github.event_name == 'pull_request_review_comment' && contains(github.event.comment.body, '@claude')) ||
18+
(github.event_name == 'pull_request_review' && contains(github.event.review.body, '@claude')) ||
19+
(github.event_name == 'issues' && (contains(github.event.issue.body, '@claude') || contains(github.event.issue.title, '@claude')))
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: read
23+
pull-requests: write
24+
issues: read
25+
id-token: write
26+
actions: read # Required for Claude to read CI results on PRs
27+
steps:
28+
- name: Checkout repository
29+
uses: actions/checkout@v4
30+
with:
31+
fetch-depth: 1
32+
33+
- name: Run Claude Code
34+
id: claude
35+
uses: anthropics/claude-code-action@beta
36+
with:
37+
claude_code_oauth_token: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
38+
39+
# This is an optional setting that allows Claude to read CI results on PRs
40+
additional_permissions: |
41+
actions: read
42+
43+
# Optional: Specify model (defaults to Claude Sonnet 4, uncomment for Claude Opus 4)
44+
# model: "claude-opus-4-20250514"
45+
46+
# Optional: Customize the trigger phrase (default: @claude)
47+
# trigger_phrase: "/claude"
48+
49+
# Optional: Trigger when specific user is assigned to an issue
50+
# assignee_trigger: "claude-bot"
51+
52+
# Optional: Allow Claude to run specific commands
53+
# allowed_tools: "Bash(npm install),Bash(npm run build),Bash(npm run test:*),Bash(npm run lint:*)"
54+
55+
# Optional: Add custom instructions for Claude to customize its behavior for your project
56+
# custom_instructions: |
57+
# Follow our coding standards
58+
# Ensure all new code has tests
59+
# Use TypeScript for new files
60+
61+
# Optional: Custom environment variables for Claude
62+
# claude_env: |
63+
# NODE_ENV: test

.prettierignore

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
packages/language/src/generated/**
2-
**/schema.ts
2+
**/test/**/schema.ts
3+
**/test/**/models.ts
4+
**/test/**/input.ts
5+
samples/**/schema.ts
6+
samples/**/models.ts
7+
samples/**/input.ts

.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": "turbo watch build",
21+
"command": "pnpm watch",
2222
"type": "shell",
2323
"group": {
2424
"kind": "build"
@@ -50,6 +50,16 @@
5050
"color": "terminal.ansiMagenta",
5151
"id": "server-process"
5252
}
53+
},
54+
{
55+
"label": "Submit PR",
56+
"command": "pnpm pr",
57+
"type": "shell",
58+
"icon": {
59+
"color": "terminal.ansiWhite",
60+
"id": "server-process"
61+
},
62+
"problemMatcher": []
5363
}
5464
]
5565
}

CLAUDE.md

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# CLAUDE.md
2+
3+
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
4+
5+
## Development Commands
6+
7+
### Build System
8+
9+
- `pnpm build` - Build all packages using Turbo
10+
- `pnpm watch` - Watch mode for all packages
11+
- `pnpm lint` - Run ESLint across all packages
12+
- `pnpm test` - Run tests for all packages
13+
14+
### Package Management
15+
16+
- Uses `pnpm` with workspaces
17+
- Package manager is pinned to `[email protected]`
18+
- Packages are located in `packages/`, `samples/`, and `tests/`
19+
20+
### Testing
21+
22+
- Runtime package tests: `pnpm test` (includes vitest, typing generation, and typecheck)
23+
- CLI tests: `pnpm test`
24+
- E2E tests are in `tests/e2e/` directory
25+
26+
### ZenStack CLI Commands
27+
28+
- `npx zenstack init` - Initialize ZenStack in a project
29+
- `npx zenstack generate` - Compile ZModel schema to TypeScript
30+
- `npx zenstack db push` - Sync schema to database (uses Prisma)
31+
- `npx zenstack migrate dev` - Create and apply migrations
32+
- `npx zenstack migrate deploy` - Deploy migrations to production
33+
34+
## Architecture Overview
35+
36+
### Core Components
37+
38+
- **@zenstackhq/runtime** - Main database client and ORM engine built on Kysely
39+
- **@zenstackhq/cli** - Command line interface and project management
40+
- **@zenstackhq/language** - ZModel language specification and parser (uses Langium)
41+
- **@zenstackhq/sdk** - Code generation utilities and schema processing
42+
43+
### Key Architecture Patterns
44+
45+
- **Monorepo Structure**: Uses pnpm workspaces with Turbo for build orchestration
46+
- **Language-First Design**: ZModel DSL compiles to TypeScript, not runtime code generation
47+
- **Kysely-Based ORM**: V3 uses Kysely as query builder instead of Prisma runtime dependency
48+
- **Plugin Architecture**: Runtime plugins for query interception and entity mutation hooks
49+
50+
### ZModel to TypeScript Flow
51+
52+
1. ZModel schema (`schema.zmodel`) defines database structure and policies
53+
2. `zenstack generate` compiles ZModel to TypeScript schema (`schema.ts`)
54+
3. Schema is used to instantiate `ZenStackClient` with type-safe CRUD operations
55+
4. Client provides both high-level ORM API and low-level Kysely query builder
56+
57+
### Package Dependencies
58+
59+
- **Runtime**: Depends on Kysely, Zod, and various utility libraries
60+
- **CLI**: Depends on language package, Commander.js, and Prisma (for migrations)
61+
- **Language**: Uses Langium for grammar parsing and AST generation
62+
- **Database Support**: SQLite (better-sqlite3) and PostgreSQL (pg) only
63+
64+
### Testing Strategy
65+
66+
- Runtime package has comprehensive client API tests and policy tests
67+
- CLI has action-specific tests for commands
68+
- E2E tests validate real-world schema compatibility (cal.com, formbricks, trigger.dev)
69+
- Type coverage tests ensure TypeScript inference works correctly
70+
71+
## Key Differences from Prisma
72+
73+
- No runtime dependency on @prisma/client
74+
- Pure TypeScript implementation without Rust/WASM
75+
- Built-in access control and validation (coming soon)
76+
- Kysely query builder as escape hatch instead of raw SQL
77+
- Schema-first approach with ZModel DSL extension of Prisma schema language
78+
79+
## Development Notes
80+
81+
- Always run `zenstack generate` after modifying ZModel schemas
82+
- Database migrations still use Prisma CLI under the hood
83+
- Plugin system allows interception at ORM, Kysely, and entity mutation levels
84+
- Computed fields are evaluated at database level for performance

TODO.md

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
- [x] migrate
88
- [x] info
99
- [x] init
10+
- [x] validate
11+
- [ ] format
12+
- [ ] db seed
13+
- [ ] ZModel
14+
- [ ] View support
1015
- [ ] ORM
1116
- [x] Create
1217
- [x] Input validation
@@ -44,7 +49,7 @@
4449
- [x] Nested to-one
4550
- [x] Incremental update for numeric fields
4651
- [x] Array update
47-
- [ ] Strict typing for checked/unchecked input
52+
- [x] Strict typing for checked/unchecked input
4853
- [x] Upsert
4954
- [ ] Implement with "on conflict"
5055
- [x] Delete
@@ -53,30 +58,36 @@
5358
- [x] Aggregate
5459
- [x] Group by
5560
- [x] Raw queries
56-
- [ ] Transactions
61+
- [x] Transactions
5762
- [x] Interactive transaction
5863
- [x] Sequential transaction
5964
- [ ] Extensions
6065
- [x] Query builder API
6166
- [x] Computed fields
6267
- [x] Prisma client extension
68+
- [ ] Custom procedures
6369
- [ ] Misc
6470
- [x] JSDoc for CRUD methods
6571
- [x] Cache validation schemas
6672
- [x] Compound ID
6773
- [ ] Cross field comparison
6874
- [x] Many-to-many relation
6975
- [ ] Empty AND/OR/NOT behavior
70-
- [?] Logging
71-
- [ ] Error system
76+
- [x] Logging
77+
- [x] Error system
7278
- [x] Custom table name
7379
- [x] Custom field name
7480
- [ ] Strict undefined checks
7581
- [ ] DbNull vs JsonNull
7682
- [ ] Benchmark
7783
- [ ] Plugin
7884
- [ ] Post-mutation hooks should be called after transaction is committed
79-
- [ ] Polymorphism
85+
- [x] TypeDef and mixin
86+
- [ ] Strongly typed JSON
87+
- [x] Polymorphism
88+
- [x] ZModel
89+
- [x] Runtime
90+
- [x] Typing
8091
- [ ] Validation
8192
- [ ] Access Policy
8293
- [ ] Short-circuit pre-create check for scalar-field only policies

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.12",
3+
"version": "3.0.0-alpha.13",
44
"description": "ZenStack",
55
"packageManager": "[email protected]",
66
"scripts": {

packages/cli/package.json

Lines changed: 1 addition & 1 deletion
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.12",
6+
"version": "3.0.0-alpha.13",
77
"type": "module",
88
"author": {
99
"name": "ZenStack Team"

packages/cli/src/actions/generate.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ type Options = {
1717
* CLI action for generating code from schema
1818
*/
1919
export async function run(options: Options) {
20+
const start = Date.now();
21+
2022
const schemaFile = getSchemaFile(options.schema);
2123

2224
const model = await loadSchemaDocument(schemaFile);
@@ -40,7 +42,7 @@ export async function run(options: Options) {
4042
}
4143

4244
if (!options.silent) {
43-
console.log(colors.green('Generation completed successfully.'));
45+
console.log(colors.green(`Generation completed successfully in ${Date.now() - start}ms.`));
4446
console.log(`You can now create a ZenStack client with it.
4547
4648
\`\`\`ts

packages/cli/src/actions/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { run as generate } from './generate';
33
import { run as info } from './info';
44
import { run as init } from './init';
55
import { run as migrate } from './migrate';
6+
import { run as validate } from './validate';
67

7-
export { db, generate, info, init, migrate };
8+
export { db, generate, info, init, migrate, validate };

0 commit comments

Comments
 (0)