Skip to content

Commit 605af83

Browse files
committed
format
1 parent 3a05507 commit 605af83

17 files changed

+118
-29
lines changed

.prettierignore

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

CLAUDE.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
55
## Development Commands
66

77
### Build System
8+
89
- `pnpm build` - Build all packages using Turbo
910
- `pnpm watch` - Watch mode for all packages
1011
- `pnpm lint` - Run ESLint across all packages
1112
- `pnpm test` - Run tests for all packages
1213

1314
### Package Management
15+
1416
- Uses `pnpm` with workspaces
1517
- Package manager is pinned to `[email protected]`
1618
- Packages are located in `packages/`, `samples/`, and `tests/`
1719

1820
### Testing
21+
1922
- Runtime package tests: `pnpm test` (includes vitest, typing generation, and typecheck)
20-
- CLI tests: `pnpm test`
23+
- CLI tests: `pnpm test`
2124
- E2E tests are in `tests/e2e/` directory
2225

2326
### ZenStack CLI Commands
27+
2428
- `npx zenstack init` - Initialize ZenStack in a project
2529
- `npx zenstack generate` - Compile ZModel schema to TypeScript
2630
- `npx zenstack db push` - Sync schema to database (uses Prisma)
@@ -30,44 +34,51 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co
3034
## Architecture Overview
3135

3236
### Core Components
37+
3338
- **@zenstackhq/runtime** - Main database client and ORM engine built on Kysely
3439
- **@zenstackhq/cli** - Command line interface and project management
3540
- **@zenstackhq/language** - ZModel language specification and parser (uses Langium)
3641
- **@zenstackhq/sdk** - Code generation utilities and schema processing
3742

3843
### Key Architecture Patterns
44+
3945
- **Monorepo Structure**: Uses pnpm workspaces with Turbo for build orchestration
4046
- **Language-First Design**: ZModel DSL compiles to TypeScript, not runtime code generation
4147
- **Kysely-Based ORM**: V3 uses Kysely as query builder instead of Prisma runtime dependency
4248
- **Plugin Architecture**: Runtime plugins for query interception and entity mutation hooks
4349

4450
### ZModel to TypeScript Flow
51+
4552
1. ZModel schema (`schema.zmodel`) defines database structure and policies
4653
2. `zenstack generate` compiles ZModel to TypeScript schema (`schema.ts`)
4754
3. Schema is used to instantiate `ZenStackClient` with type-safe CRUD operations
4855
4. Client provides both high-level ORM API and low-level Kysely query builder
4956

5057
### Package Dependencies
58+
5159
- **Runtime**: Depends on Kysely, Zod, and various utility libraries
5260
- **CLI**: Depends on language package, Commander.js, and Prisma (for migrations)
5361
- **Language**: Uses Langium for grammar parsing and AST generation
5462
- **Database Support**: SQLite (better-sqlite3) and PostgreSQL (pg) only
5563

5664
### Testing Strategy
65+
5766
- Runtime package has comprehensive client API tests and policy tests
5867
- CLI has action-specific tests for commands
5968
- E2E tests validate real-world schema compatibility (cal.com, formbricks, trigger.dev)
6069
- Type coverage tests ensure TypeScript inference works correctly
6170

6271
## Key Differences from Prisma
72+
6373
- No runtime dependency on @prisma/client
6474
- Pure TypeScript implementation without Rust/WASM
6575
- Built-in access control and validation (coming soon)
6676
- Kysely query builder as escape hatch instead of raw SQL
6777
- Schema-first approach with ZModel DSL extension of Prisma schema language
6878

6979
## Development Notes
80+
7081
- Always run `zenstack generate` after modifying ZModel schemas
7182
- Database migrations still use Prisma CLI under the hood
7283
- Plugin system allows interception at ORM, Kysely, and entity mutation levels
73-
- Computed fields are evaluated at database level for performance
84+
- Computed fields are evaluated at database level for performance

packages/cli/src/actions/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,4 @@ export async function run(options: Options) {
1919
// Re-throw to maintain CLI exit code behavior
2020
throw error;
2121
}
22-
}
22+
}

packages/sdk/src/ts-schema-generator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ import path from 'node:path';
4242
import { match } from 'ts-pattern';
4343
import * as ts from 'typescript';
4444
import { ModelUtils } from '.';
45-
import { getAttribute, getAuthDecl, hasAttribute, isIdField, isUniqueField } from './model-utils';
45+
import { getAttribute, getAuthDecl, hasAttribute, isUniqueField } from './model-utils';
4646

4747
export class TsSchemaGenerator {
4848
public async generate(schemaFile: string, pluginModelFiles: string[], outputDir: string) {

tests/e2e/prisma-consistency/attributes.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2-
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
2+
import {
3+
ZenStackValidationTester,
4+
createTestDir,
5+
expectValidationSuccess,
6+
expectValidationFailure,
7+
baseSchema,
8+
} from './test-utils';
39

410
describe('Attributes Validation', () => {
511
let tester: ZenStackValidationTester;
@@ -57,4 +63,4 @@ model User {
5763

5864
expectValidationSuccess(result);
5965
});
60-
});
66+
});

tests/e2e/prisma-consistency/basic-models.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2-
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
2+
import {
3+
ZenStackValidationTester,
4+
createTestDir,
5+
expectValidationSuccess,
6+
expectValidationFailure,
7+
baseSchema,
8+
} from './test-utils';
39

410
describe('Basic Models Validation', () => {
511
let tester: ZenStackValidationTester;
@@ -96,4 +102,4 @@ model User {
96102

97103
expectValidationFailure(result);
98104
});
99-
});
105+
});

tests/e2e/prisma-consistency/compound-ids.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2-
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
2+
import {
3+
ZenStackValidationTester,
4+
createTestDir,
5+
expectValidationSuccess,
6+
expectValidationFailure,
7+
baseSchema,
8+
} from './test-utils';
39

410
describe('Compound IDs Validation', () => {
511
let tester: ZenStackValidationTester;
@@ -44,4 +50,4 @@ model User {
4450

4551
expectValidationFailure(result);
4652
});
47-
});
53+
});

tests/e2e/prisma-consistency/datasource.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2-
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
2+
import {
3+
ZenStackValidationTester,
4+
createTestDir,
5+
expectValidationSuccess,
6+
expectValidationFailure,
7+
baseSchema,
8+
} from './test-utils';
39

410
describe('Datasource Validation', () => {
511
let tester: ZenStackValidationTester;
@@ -61,4 +67,4 @@ model User {
6167

6268
expectValidationFailure(result);
6369
});
64-
});
70+
});

tests/e2e/prisma-consistency/enums.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2-
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema } from './test-utils';
2+
import {
3+
ZenStackValidationTester,
4+
createTestDir,
5+
expectValidationSuccess,
6+
expectValidationFailure,
7+
baseSchema,
8+
} from './test-utils';
39

410
describe('Enums Validation', () => {
511
let tester: ZenStackValidationTester;
@@ -50,4 +56,4 @@ model User {
5056

5157
expectValidationFailure(result);
5258
});
53-
});
59+
});

tests/e2e/prisma-consistency/field-types.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
2-
import { ZenStackValidationTester, createTestDir, expectValidationSuccess, expectValidationFailure, baseSchema, sqliteSchema } from './test-utils';
2+
import {
3+
ZenStackValidationTester,
4+
createTestDir,
5+
expectValidationSuccess,
6+
expectValidationFailure,
7+
baseSchema,
8+
sqliteSchema,
9+
} from './test-utils';
310

411
describe('Field Types Validation', () => {
512
let tester: ZenStackValidationTester;
@@ -52,4 +59,4 @@ model User {
5259

5360
expectValidationSuccess(result);
5461
});
55-
});
62+
});

0 commit comments

Comments
 (0)