Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

### Testing

- Runtime package tests: `pnpm test` (includes vitest, typing generation, and typecheck)
- CLI tests: `pnpm test`
- E2E tests are in `tests/e2e/` directory

### ZenStack CLI Commands
Expand All @@ -35,7 +33,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

### Core Components

- **@zenstackhq/runtime** - Main database client and ORM engine built on Kysely
- **@zenstackhq/orm** - ORM engine built above Kysely
- **@zenstackhq/cli** - Command line interface and project management
- **@zenstackhq/language** - ZModel language specification and parser (uses Langium)
- **@zenstackhq/sdk** - Code generation utilities and schema processing
Expand All @@ -56,14 +54,14 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co

### Package Dependencies

- **Runtime**: Depends on Kysely, Zod, and various utility libraries
- **ORM**: Depends on Kysely, Zod, and various utility libraries
- **CLI**: Depends on language package, Commander.js, and Prisma (for migrations)
- **Language**: Uses Langium for grammar parsing and AST generation
- **Database Support**: SQLite (better-sqlite3) and PostgreSQL (pg) only

### Testing Strategy

- Runtime package has comprehensive client API tests and policy tests
- ORM package has comprehensive client API tests and policy tests
- CLI has action-specific tests for commands
- E2E tests validate real-world schema compatibility (cal.com, formbricks, trigger.dev)
- Type coverage tests ensure TypeScript inference works correctly
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ Even without using advanced features, ZenStack offers the following benefits as
2. More TypeScript type inference, less code generation.
3. Fully-typed query-builder API as a better escape hatch compared to Prisma's [raw queries](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/raw-queries) or [typed SQL](https://www.prisma.io/docs/orm/prisma-client/using-raw-sql/typedsql).

> Although ZenStack v3's runtime doesn't depend on Prisma anymore (specifically, `@prisma/client`), it still relies on Prisma to handle database migration. See [database migration](https://zenstack.dev/docs/3.x/orm/migration) for more details.
> Although ZenStack v3's ORM runtime doesn't depend on Prisma anymore (specifically, `@prisma/client`), it still relies on Prisma to handle database migration. See [database migration](https://zenstack.dev/docs/3.x/orm/migration) for more details.

# Quick start

Expand Down Expand Up @@ -77,7 +77,7 @@ Alternatively, you can set it up manually:

```bash
npm install -D @zenstackhq/cli@next
npm install @zenstackhq/runtime@next
npm install @zenstackhq/orm@next
```

Then create a `zenstack` folder and a `schema.zmodel` file in it.
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
"@types/semver": "^7.7.0",
"@types/tmp": "catalog:",
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/orm": "workspace:*",
"@zenstackhq/testtools": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/vitest-config": "workspace:*",
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/actions/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export async function run(options: Options) {
console.log(`You can now create a ZenStack client with it.

\`\`\`ts
import { ZenStackClient } from '@zenstackhq/runtime';
import { ZenStackClient } from '@zenstackhq/orm';
import { schema } from '${outputPath}/schema';

const client = new ZenStackClient(schema, {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/actions/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { STARTER_ZMODEL } from './templates';
export async function run(projectPath: string) {
const packages = [
{ name: '@zenstackhq/cli@next', dev: true },
{ name: '@zenstackhq/runtime@next', dev: false },
{ name: '@zenstackhq/orm@next', dev: false },
];
let pm = await detect();
if (!pm) {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/src/actions/templates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ model Post {
}
`;

export const STARTER_MAIN_TS = `import { ZenStackClient } from '@zenstackhq/runtime';
export const STARTER_MAIN_TS = `import { ZenStackClient } from '@zenstackhq/orm';
import SQLite from 'better-sqlite3';
import { SqliteDialect } from 'kysely';
import { schema } from './zenstack/schema';
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/test/ts-schema-gen.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ExpressionUtils } from '@zenstackhq/runtime/schema';
import { ExpressionUtils } from '@zenstackhq/orm/schema';
import { createTestProject, generateTsSchema, generateTsSchemaInPlace } from '@zenstackhq/testtools';
import fs from 'node:fs';
import path from 'node:path';
Expand Down
2 changes: 1 addition & 1 deletion packages/create-zenstack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ function initProject(name: string) {
// install packages
const packages = [
{ name: '@zenstackhq/cli@next', dev: true },
{ name: '@zenstackhq/runtime@next', dev: false },
{ name: '@zenstackhq/orm@next', dev: false },
{ name: 'better-sqlite3', dev: false },
{ name: '@types/better-sqlite3', dev: true },
{ name: 'typescript', dev: true },
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions packages/runtime/package.json → packages/orm/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/runtime",
"name": "@zenstackhq/orm",
"version": "3.0.0-beta.13",
"description": "ZenStack Runtime",
"description": "ZenStack ORM",
"type": "module",
"scripts": {
"build": "tsc --noEmit && tsup-node",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion packages/plugins/policy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
},
"dependencies": {
"@zenstackhq/common-helpers": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/orm": "workspace:*",
"ts-pattern": "catalog:"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/policy/src/column-collector.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { KyselyUtils } from '@zenstackhq/runtime';
import { KyselyUtils } from '@zenstackhq/orm';
import type { ColumnNode, OperationNode } from 'kysely';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/policy/src/expression-evaluator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
type LiteralExpression,
type MemberExpression,
type UnaryExpression,
} from '@zenstackhq/runtime/schema';
} from '@zenstackhq/orm/schema';

type ExpressionEvaluatorContext = {
auth?: any;
Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/policy/src/expression-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
type BaseCrudDialect,
type ClientContract,
type CRUD_EXT,
} from '@zenstackhq/runtime';
} from '@zenstackhq/orm';
import type {
BinaryExpression,
BinaryOperator,
Expand All @@ -17,15 +17,15 @@ import type {
LiteralExpression,
MemberExpression,
UnaryExpression,
} from '@zenstackhq/runtime/schema';
} from '@zenstackhq/orm/schema';
import {
ExpressionUtils,
type ArrayExpression,
type CallExpression,
type Expression,
type FieldExpression,
type SchemaDef,
} from '@zenstackhq/runtime/schema';
} from '@zenstackhq/orm/schema';
import {
AliasNode,
BinaryOperationNode,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/policy/src/functions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { invariant } from '@zenstackhq/common-helpers';
import type { ZModelFunction, ZModelFunctionContext } from '@zenstackhq/runtime';
import { CRUD, QueryUtils } from '@zenstackhq/runtime';
import type { ZModelFunction, ZModelFunctionContext } from '@zenstackhq/orm';
import { CRUD, QueryUtils } from '@zenstackhq/orm';
import { ExpressionWrapper, ValueNode, type Expression, type ExpressionBuilder } from 'kysely';
import { PolicyHandler } from './policy-handler';

Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/policy/src/plugin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type OnKyselyQueryArgs, type RuntimePlugin } from '@zenstackhq/runtime';
import type { SchemaDef } from '@zenstackhq/runtime/schema';
import { type OnKyselyQueryArgs, type RuntimePlugin } from '@zenstackhq/orm';
import type { SchemaDef } from '@zenstackhq/orm/schema';
import { check } from './functions';
import { PolicyHandler } from './policy-handler';

Expand Down
6 changes: 3 additions & 3 deletions packages/plugins/policy/src/policy-handler.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { invariant } from '@zenstackhq/common-helpers';
import type { BaseCrudDialect, ClientContract, ProceedKyselyQueryFunction } from '@zenstackhq/runtime';
import type { BaseCrudDialect, ClientContract, ProceedKyselyQueryFunction } from '@zenstackhq/orm';
import {
getCrudDialect,
InternalError,
Expand All @@ -9,15 +9,15 @@ import {
RejectedByPolicyReason,
SchemaUtils,
type CRUD_EXT,
} from '@zenstackhq/runtime';
} from '@zenstackhq/orm';
import {
ExpressionUtils,
type BuiltinType,
type Expression,
type GetModels,
type MemberExpression,
type SchemaDef,
} from '@zenstackhq/runtime/schema';
} from '@zenstackhq/orm/schema';
import {
AliasNode,
BinaryOperationNode,
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/policy/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { CRUD_EXT } from '@zenstackhq/runtime';
import type { Expression } from '@zenstackhq/runtime/schema';
import type { CRUD_EXT } from '@zenstackhq/orm';
import type { Expression } from '@zenstackhq/orm/schema';

/**
* Access policy kind.
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/policy/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { BaseCrudDialect } from '@zenstackhq/runtime';
import { ExpressionUtils, type Expression, type SchemaDef } from '@zenstackhq/runtime/schema';
import type { BaseCrudDialect } from '@zenstackhq/orm';
import { ExpressionUtils, type Expression, type SchemaDef } from '@zenstackhq/orm/schema';
import type { OperationNode } from 'kysely';
import {
AliasNode,
Expand Down
16 changes: 8 additions & 8 deletions packages/sdk/src/ts-schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export class TsSchemaGenerator {
: []),
]),
),
ts.factory.createStringLiteral('@zenstackhq/runtime/schema'),
ts.factory.createStringLiteral('@zenstackhq/orm/schema'),
);
statements.push(runtimeImportDecl);

Expand Down Expand Up @@ -1116,7 +1116,7 @@ export class TsSchemaGenerator {
// generate: import { schema as $schema, type SchemaType as $Schema } from './schema';
statements.push(this.generateSchemaImport(model, true, true));

// generate: import type { ModelResult as $ModelResult } from '@zenstackhq/runtime';
// generate: import type { ModelResult as $ModelResult } from '@zenstackhq/orm';
statements.push(
ts.factory.createImportDeclaration(
undefined,
Expand All @@ -1140,7 +1140,7 @@ export class TsSchemaGenerator {
: []),
]),
),
ts.factory.createStringLiteral('@zenstackhq/runtime'),
ts.factory.createStringLiteral('@zenstackhq/orm'),
),
);

Expand Down Expand Up @@ -1289,7 +1289,7 @@ export class TsSchemaGenerator {
// generate: import { SchemaType as $Schema } from './schema';
statements.push(this.generateSchemaImport(model, false, true));

// generate: import { CreateArgs as $CreateArgs, ... } from '@zenstackhq/runtime';
// generate: import { CreateArgs as $CreateArgs, ... } from '@zenstackhq/orm';
const inputTypes = [
'FindManyArgs',
'FindUniqueArgs',
Expand Down Expand Up @@ -1318,7 +1318,7 @@ export class TsSchemaGenerator {
OmitInput: 'Omit',
};

// generate: import { CreateArgs as $CreateArgs, ... } from '@zenstackhq/runtime';
// generate: import { CreateArgs as $CreateArgs, ... } from '@zenstackhq/orm';
statements.push(
ts.factory.createImportDeclaration(
undefined,
Expand All @@ -1335,11 +1335,11 @@ export class TsSchemaGenerator {
),
),
),
ts.factory.createStringLiteral('@zenstackhq/runtime'),
ts.factory.createStringLiteral('@zenstackhq/orm'),
),
);

// generate: import { type SelectIncludeOmit as $SelectIncludeOmit, type SimplifiedModelResult as $SimplifiedModelResult } from '@zenstackhq/runtime';
// generate: import { type SelectIncludeOmit as $SelectIncludeOmit, type SimplifiedModelResult as $SimplifiedModelResult } from '@zenstackhq/orm';
statements.push(
ts.factory.createImportDeclaration(
undefined,
Expand All @@ -1359,7 +1359,7 @@ export class TsSchemaGenerator {
),
]),
),
ts.factory.createStringLiteral('@zenstackhq/runtime'),
ts.factory.createStringLiteral('@zenstackhq/orm'),
),
);

Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
},
"dependencies": {
"@zenstackhq/common-helpers": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/orm": "workspace:*",
"decimal.js": "catalog:",
"superjson": "^2.2.3",
"ts-pattern": "catalog:"
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/api/rpc/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import {
RejectedByPolicyError,
ZenStackError,
type ClientContract,
} from '@zenstackhq/runtime';
import type { SchemaDef } from '@zenstackhq/runtime/schema';
} from '@zenstackhq/orm';
import type { SchemaDef } from '@zenstackhq/orm/schema';
import SuperJSON from 'superjson';
import type { ApiHandler, LogConfig, RequestContext, Response } from '../../types';
import { log, registerCustomSerializers } from '../utils';
Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/express/middleware.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ClientContract } from '@zenstackhq/runtime';
import type { SchemaDef } from '@zenstackhq/runtime/schema';
import type { ClientContract } from '@zenstackhq/orm';
import type { SchemaDef } from '@zenstackhq/orm/schema';
import type { Handler, Request, Response } from 'express';
import type { ApiHandler } from '../types';

Expand Down
4 changes: 2 additions & 2 deletions packages/server/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { ClientContract } from '@zenstackhq/runtime';
import type { SchemaDef } from '@zenstackhq/runtime/schema';
import type { ClientContract } from '@zenstackhq/orm';
import type { SchemaDef } from '@zenstackhq/orm/schema';

/**
* Log levels
Expand Down
4 changes: 2 additions & 2 deletions packages/server/test/api/rpc.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ClientContract } from '@zenstackhq/runtime';
import { SchemaDef } from '@zenstackhq/runtime/schema';
import { ClientContract } from '@zenstackhq/orm';
import { SchemaDef } from '@zenstackhq/orm/schema';
import { createPolicyTestClient, createTestClient } from '@zenstackhq/testtools';
import Decimal from 'decimal.js';
import SuperJSON from 'superjson';
Expand Down
2 changes: 1 addition & 1 deletion packages/tanstack-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
},
"dependencies": {
"@zenstackhq/runtime": "workspace:*"
"@zenstackhq/orm": "workspace:*"
},
"devDependencies": {
"@zenstackhq/eslint-config": "workspace:*",
Expand Down
4 changes: 2 additions & 2 deletions packages/tanstack-query/src/react.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import type {
UseQueryOptions,
UseQueryResult,
} from '@tanstack/react-query';
import type { CreateArgs, FindArgs, ModelResult, SelectSubset } from '@zenstackhq/runtime';
import type { GetModels, SchemaDef } from '@zenstackhq/runtime/schema';
import type { CreateArgs, FindArgs, ModelResult, SelectSubset } from '@zenstackhq/orm';
import type { GetModels, SchemaDef } from '@zenstackhq/orm/schema';

export type toHooks<Schema extends SchemaDef> = {
[Model in GetModels<Schema> as Uncapitalize<Model>]: ToModelHooks<Schema, Model>;
Expand Down
2 changes: 1 addition & 1 deletion packages/testtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"dependencies": {
"@zenstackhq/common-helpers": "workspace:*",
"@zenstackhq/language": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/orm": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
"@zenstackhq/plugin-policy": "workspace:*",
"glob": "^11.0.2",
Expand Down
4 changes: 2 additions & 2 deletions packages/testtools/src/client.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { invariant } from '@zenstackhq/common-helpers';
import type { Model } from '@zenstackhq/language/ast';
import { PolicyPlugin } from '@zenstackhq/plugin-policy';
import { ZenStackClient, type ClientContract, type ClientOptions } from '@zenstackhq/runtime';
import type { SchemaDef } from '@zenstackhq/runtime/schema';
import { ZenStackClient, type ClientContract, type ClientOptions } from '@zenstackhq/orm';
import type { SchemaDef } from '@zenstackhq/orm/schema';
import { PrismaSchemaGenerator } from '@zenstackhq/sdk';
import SQLite from 'better-sqlite3';
import { PostgresDialect, SqliteDialect, type LogEvent } from 'kysely';
Expand Down
2 changes: 1 addition & 1 deletion packages/testtools/src/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function createTestProject(zmodelContent?: string) {
}

// in addition, symlink zenstack packages
const zenstackPackages = ['language', 'sdk', 'runtime', 'cli'];
const zenstackPackages = ['language', 'sdk', 'orm', 'cli'];
fs.mkdirSync(path.join(workDir, 'node_modules/@zenstackhq'));
for (const pkg of zenstackPackages) {
fs.symlinkSync(
Expand Down
2 changes: 1 addition & 1 deletion packages/testtools/src/vitest-ext.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { InputValidationError, NotFoundError, RejectedByPolicyError } from '@zenstackhq/runtime';
import { InputValidationError, NotFoundError, RejectedByPolicyError } from '@zenstackhq/orm';
import { expect } from 'vitest';

function isPromise(value: any) {
Expand Down
2 changes: 1 addition & 1 deletion packages/zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}
},
"dependencies": {
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/orm": "workspace:*",
"ts-pattern": "catalog:"
},
"devDependencies": {
Expand Down
Loading