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
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:

strategy:
matrix:
node-version: [24.x]
node-version: [22.x, 24.x]
provider: [sqlite, postgresql, mysql]

steps:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "zenstack-v3",
"displayName": "ZenStack",
"description": "ZenStack",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/auth-adapters/better-auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/better-auth",
"displayName": "ZenStack Better Auth Adapter",
"description": "ZenStack Better Auth Adapter. This adapter is modified from better-auth's Prisma adapter.",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
4 changes: 2 additions & 2 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/cli",
"displayName": "ZenStack CLI",
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down Expand Up @@ -110,7 +110,7 @@
}
},
"engines": {
"node": ">=20"
"node": ">=22"
Comment thread
ymc9 marked this conversation as resolved.
Resolved
},
"funding": "https://github.com/sponsors/zenstackhq"
}
2 changes: 1 addition & 1 deletion packages/clients/client-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/client-helpers",
"displayName": "ZenStack Client Helpers",
"description": "Helpers for implementing clients that consume ZenStack's CRUD service",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/fetch-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/fetch-client",
"displayName": "ZenStack Fetch Client",
"description": "Simple fetch-based client for consuming ZenStack's RPC-style CRUD API",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/tanstack-query/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/tanstack-query",
"displayName": "ZenStack TanStack Query Integration",
"description": "TanStack Query Client for consuming ZenStack v3's CRUD service",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/common-helpers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/common-helpers",
"displayName": "ZenStack Common Helpers",
"description": "ZenStack Common Helpers",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/eslint-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/eslint-config",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"private": true,
"license": "MIT"
Expand Down
2 changes: 1 addition & 1 deletion packages/config/tsdown-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/tsdown-config",
"version": "3.10.1",
"version": "3.10.2",
"private": true,
"type": "module",
"license": "MIT",
Expand Down
2 changes: 1 addition & 1 deletion packages/config/typescript-config/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/typescript-config",
"version": "3.10.1",
"version": "3.10.2",
"private": true,
"license": "MIT"
}
2 changes: 1 addition & 1 deletion packages/config/vitest-config/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/vitest-config",
"type": "module",
"version": "3.10.1",
"version": "3.10.2",
"private": true,
"license": "MIT",
"exports": {
Expand Down
2 changes: 1 addition & 1 deletion packages/create-zenstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "create-zenstack",
"displayName": "Create ZenStack",
"description": "Create a new ZenStack project",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/vscode/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "zenstack-v3",
"publisher": "zenstack",
"version": "3.10.1",
"version": "3.10.2",
"displayName": "ZenStack V3 Language Tools",
"description": "VSCode extension for ZenStack (v3) ZModel language",
"private": true,
Expand Down
5 changes: 4 additions & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/language",
"displayName": "ZenStack Language Tooling",
"description": "ZenStack ZModel language specification",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down Expand Up @@ -92,5 +92,8 @@
"langium-cli": "catalog:",
"tmp": "catalog:"
},
"engines": {
"node": ">=22"
},
"funding": "https://github.com/sponsors/zenstackhq"
}
5 changes: 4 additions & 1 deletion packages/orm/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/orm",
"displayName": "ZenStack ORM",
"description": "ZenStack ORM",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down Expand Up @@ -171,5 +171,8 @@
"tsx": "catalog:",
"zod": "^4.1.0"
},
"engines": {
"node": ">=22"
},
"funding": "https://github.com/sponsors/zenstackhq"
}
2 changes: 1 addition & 1 deletion packages/plugins/policy/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/plugin-policy",
"displayName": "ZenStack Access Policy Plugin",
"description": "ZenStack plugin that enforces access control policies defined in the schema",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
77 changes: 75 additions & 2 deletions packages/plugins/policy/src/expression-transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,12 @@ export class ExpressionTransformer<Schema extends SchemaDef> {
const rightFieldDef = this.getFieldDefFromFieldRef(normalizedRight, context);
// Map ZModel operator to SQL operator string
const sqlOp = op === '==' ? '=' : op;
// `before()` enums are text in the VALUES table and pg can't compare text to a native enum
// enums read from a VALUES table (`before()` rows, create input) are text, and pg can't
// compare text to a native enum
const asText =
this.isBeforeEnumField(normalizedLeft, context) || this.isBeforeEnumField(normalizedRight, context);
this.isBeforeEnumField(normalizedLeft, context) ||
this.isBeforeEnumField(normalizedRight, context) ||
this.isCreateInputEnumComparison(normalizedLeft, normalizedRight, context);
Comment thread
ymc9 marked this conversation as resolved.
Resolved
const operand = (node: OperationNode) =>
asText ? this.dialect.castText(new ExpressionWrapper(node)) : new ExpressionWrapper(node);
return this.dialect
Expand Down Expand Up @@ -1233,6 +1236,76 @@ export class ExpressionTransformer<Schema extends SchemaDef> {
return !!fieldDef && QueryUtils.isEnum(this.schema, fieldDef.type);
}

/**
* Whether a comparison in a create rule needs both operands compared as text.
*
* Create rules are evaluated before the insert, against a `VALUES` table built from the input
* (see `enforcePreCreatePolicyForOne`). That table carries enum fields as `text`, while stored
* columns have the native enum type, and PostgreSQL has no `text = "Enum"` operator (42883).
*
* Returns true only when one operand is an enum field of the entity being created and the
* other is a stored field of the same enum, e.g. for `model Grant { permission Permission }`:
* - `permission == anchor.defaultPermission` (bare top-level field vs. related row)
* - `anchor.approvals?[permission == this.permission]` (stored row vs. `this`)
*
* Not for literals (`permission == EDIT`): the name mapper still translates `@map`-ed literals.
* Not for enums with `@map`-ed values: the input holds names (`ACTIVE`) but stored columns
* hold mapped values (`active`), so a text comparison would be wrong (#2867).
*/
private isCreateInputEnumComparison(left: Expression, right: Expression, context: ExpressionTransformerContext) {
// only create rules read from the input `VALUES` table
if (context.operation !== 'create') {
return false;
}
const leftInput = this.getCreateInputEnumField(left, context);
const rightInput = this.getCreateInputEnumField(right, context);
// exactly one operand must be create input: if both are, both are text; if neither is,
// both are stored native enums. Either way the types already match.
if (!leftInput === !rightInput) {
return false;
}
const inputDef = (leftInput ?? rightInput)!;
// the other operand must be a stored field of the same enum (a literal resolves to no field)
const storedDef = this.getFieldDefFromFieldRef(leftInput ? right : left, context);
return storedDef?.type === inputDef.type && !this.hasMappedEnumValues(inputDef.type);
}

/**
* If the expression reads an enum field of the entity being created (i.e. a column of the input
* `VALUES` table), returns that field's definition; otherwise `undefined`.
*
* - `this.field` always refers to the entity the rule belongs to. A longer path such as
* `this.anchor.defaultPermission` goes through a relation and reads a stored row.
* - a bare `field` refers to the entity being created only at the top level of the rule. Inside
* a collection predicate (`relation?[field == ...]`) it refers to the related stored row.
*/
private getCreateInputEnumField(expr: Expression, context: ExpressionTransformerContext) {
let field: string | undefined;
if (ExpressionUtils.isMember(expr) && ExpressionUtils.isThis(expr.receiver) && expr.members.length === 1) {
// `this.field`
field = expr.members[0];
} else if (
ExpressionUtils.isField(expr) &&
// still on the model the rule belongs to ...
context.modelOrType === context.thisType &&
// ... and not inside a collection predicate: there (incl. self-relations, where the
// model is the same) a bare field is a stored row, aliased differently
context.alias === context.thisAlias
) {
// bare top-level `field`
field = expr.field;
}
// `this` and top-level bare fields both resolve against the model being created
const fieldDef = field ? QueryUtils.getField(this.schema, context.thisType, field) : undefined;
return fieldDef && QueryUtils.isEnum(this.schema, fieldDef.type) ? fieldDef : undefined;
}

// whether any member of the enum carries `@map`, i.e. its stored values differ from its names
private hasMappedEnumValues(enumType: string) {
const enumDef = QueryUtils.getEnum(this.schema, enumType);
return Object.values(enumDef?.fields ?? {}).some((f) => f.attributes?.some((attr) => attr.name === '@map'));
}

private getFieldDefFromFieldRef(expr: Expression, context: ExpressionTransformerContext): FieldDef | undefined {
return this.resolveFieldRef(expr, context)?.fieldDef;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/soft-delete/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/plugin-soft-delete",
"displayName": "ZenStack Soft Delete Plugin",
"description": "ZenStack plugin that implements soft-delete by intercepting Kysely queries",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/schema",
"displayName": "ZenStack Schema Object Model",
"description": "TypeScript representation of ZModel schema",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/sdk",
"displayName": "ZenStack SDK",
"description": "Utilities for building ZenStack plugins",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/server",
"displayName": "ZenStack Automatic CRUD Server",
"description": "ZenStack automatic CRUD API handlers and server adapters for popular frameworks",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
8 changes: 5 additions & 3 deletions packages/testtools/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/testtools",
"displayName": "ZenStack Test Tools",
"description": "ZenStack Test Tools",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down Expand Up @@ -55,7 +55,8 @@
},
"peerDependencies": {
"better-sqlite3": "catalog:",
"pg": "catalog:"
"pg": "catalog:",
"vitest": "^4.0.14"
},
"devDependencies": {
"@types/better-sqlite3": "catalog:",
Expand All @@ -65,7 +66,8 @@
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/tsdown-config": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*",
"typescript": "catalog:"
"typescript": "catalog:",
"vitest": "^4.0.14"
},
"funding": "https://github.com/sponsors/zenstackhq"
}
2 changes: 1 addition & 1 deletion packages/zod/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "@zenstackhq/zod",
"displayName": "ZenStack Zod Integration",
"description": "Automatically deriving Zod schemas from ZModel schemas",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"author": {
"name": "ZenStack Team",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion samples/orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sample-orm",
"version": "3.10.1",
"version": "3.10.2",
"description": "",
"main": "index.js",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion samples/taskforge/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "taskforge",
"version": "3.10.1",
"version": "3.10.2",
"type": "module",
"private": true,
"description": "A CLI for a team collaboration / project-tracking platform, built on ZenStack v3 (ORM) and better-auth.",
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "e2e",
"version": "3.10.1",
"version": "3.10.2",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tests/regression/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "regression",
"version": "3.10.1",
"version": "3.10.2",
"private": true,
"type": "module",
"scripts": {
Expand Down
Loading
Loading