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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-v3",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack",
"packageManager": "pnpm@10.23.0",
"type": "module",
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
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/better-auth",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack Better Auth Adapter. This adapter is modified from better-auth's Prisma adapter.",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack CLI",
"description": "FullStack database toolkit with built-in access control and automatic API generation.",
"version": "3.3.2",
"version": "3.3.3",
"type": "module",
"author": {
"name": "ZenStack Team"
Expand Down
19 changes: 18 additions & 1 deletion packages/cli/src/actions/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { Pool as PgPool } from 'pg';
import { CliError } from '../cli-error';
import { getVersion } from '../utils/version-utils';
import { getOutputPath, getSchemaFile, loadSchemaDocument } from './action-utils';
import type { SchemaDef } from '@zenstackhq/orm/schema';

type Options = {
output?: string;
Expand Down Expand Up @@ -72,9 +73,25 @@ export async function run(options: Options) {

const schemaModule = (await jiti.import(path.join(outputPath, 'schema'))) as any;

const db = new ZenStackClient(schemaModule.schema, {
// Build omit configuration for computed fields
const schema = schemaModule.schema as SchemaDef;
const omit: Record<string, Record<string, boolean>> = {};
for (const [modelName, modelDef] of Object.entries(schema.models)) {
const computedFields: Record<string, boolean> = {};
for (const [fieldName, fieldDef] of Object.entries(modelDef.fields)) {
if (fieldDef.computed === true) {
computedFields[fieldName] = true;
}
}
if (Object.keys(computedFields).length > 0) {
omit[modelName] = computedFields;
}
}

const db = new ZenStackClient(schema, {
dialect: dialect,
log: log && log.length > 0 ? log : undefined,
omit: Object.keys(omit).length > 0 ? omit : undefined,
});

// check whether the database is reachable
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/client-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/client-helpers",
"version": "3.3.2",
"version": "3.3.3",
"description": "Helpers for implementing clients that consume ZenStack's CRUD service",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/clients/tanstack-query/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/tanstack-query",
"version": "3.3.2",
"version": "3.3.3",
"description": "TanStack Query Client for consuming ZenStack v3's CRUD service",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/common-helpers/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/common-helpers",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack Common Helpers",
"type": "module",
"scripts": {
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.3.2",
"version": "3.3.3",
"type": "module",
"private": true,
"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.3.2",
"version": "3.3.3",
"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.3.2",
"version": "3.3.3",
"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
@@ -1,6 +1,6 @@
{
"name": "create-zenstack",
"version": "3.3.2",
"version": "3.3.3",
"description": "Create a new ZenStack project",
"type": "module",
"scripts": {
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.3.2",
"version": "3.3.3",
"displayName": "ZenStack V3 Language Tools",
"description": "VSCode extension for ZenStack (v3) ZModel language",
"private": true,
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/language",
"description": "ZenStack ZModel language specification",
"version": "3.3.2",
"version": "3.3.3",
"license": "MIT",
"author": "ZenStack Team",
"files": [
Expand Down
21 changes: 21 additions & 0 deletions packages/language/res/stdlib.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,9 @@ attribute @db.Uuid() @@@targetField([StringField]) @@@prisma
attribute @db.Xml() @@@targetField([StringField]) @@@prisma
attribute @db.Inet() @@@targetField([StringField]) @@@prisma
attribute @db.Citext() @@@targetField([StringField]) @@@prisma
attribute @db.TinyText() @@@targetField([StringField]) @@@prisma
attribute @db.MediumText() @@@targetField([StringField]) @@@prisma
attribute @db.LongText() @@@targetField([StringField]) @@@prisma

// Boolean type modifiers

Expand All @@ -437,16 +440,26 @@ attribute @db.Int() @@@targetField([IntField]) @@@prisma
attribute @db.Integer() @@@targetField([IntField]) @@@prisma
attribute @db.SmallInt() @@@targetField([IntField]) @@@prisma
attribute @db.Oid() @@@targetField([IntField]) @@@prisma
attribute @db.UnsignedInt() @@@targetField([IntField]) @@@prisma
attribute @db.UnsignedSmallInt() @@@targetField([IntField]) @@@prisma
attribute @db.MediumInt() @@@targetField([IntField]) @@@prisma
attribute @db.UnsignedMediumInt() @@@targetField([IntField]) @@@prisma
attribute @db.TinyInt(_ length: Int?) @@@targetField([IntField]) @@@prisma
attribute @db.UnsignedTinyInt(_ length: Int?) @@@targetField([IntField]) @@@prisma
attribute @db.Year() @@@targetField([IntField]) @@@prisma

// BigInt type modifiers

attribute @db.BigInt() @@@targetField([BigIntField]) @@@prisma
attribute @db.UnsignedBigInt() @@@targetField([BigIntField]) @@@prisma

// Float/Decimal type modifiers
attribute @db.DoublePrecision() @@@targetField([FloatField, DecimalField]) @@@prisma
attribute @db.Real() @@@targetField([FloatField, DecimalField]) @@@prisma
attribute @db.Decimal(_ p: Int?, _ s: Int?) @@@targetField([FloatField, DecimalField]) @@@prisma
attribute @db.Money() @@@targetField([FloatField, DecimalField]) @@@prisma
attribute @db.Float() @@@targetField([FloatField]) @@@prisma
attribute @db.Double() @@@targetField([FloatField]) @@@prisma

// DateTime type modifiers

Expand All @@ -455,6 +468,8 @@ attribute @db.Timestamptz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
attribute @db.Date() @@@targetField([DateTimeField]) @@@prisma
attribute @db.Time(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
attribute @db.Timetz(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma
attribute @db.DateTime(_ x: Int?) @@@targetField([DateTimeField]) @@@prisma


// Json type modifiers

Expand All @@ -464,6 +479,12 @@ attribute @db.JsonB() @@@targetField([JsonField]) @@@prisma
// Bytes type modifiers

attribute @db.ByteA() @@@targetField([BytesField]) @@@prisma
attribute @db.LongBlob() @@@targetField([BytesField]) @@@prisma
attribute @db.Binary(_ n: Int?) @@@targetField([BytesField]) @@@prisma
attribute @db.VarBinary(_ n: Int?) @@@targetField([BytesField]) @@@prisma
attribute @db.TinyBlob() @@@targetField([BytesField]) @@@prisma
attribute @db.Blob() @@@targetField([BytesField]) @@@prisma
attribute @db.MediumBlob() @@@targetField([BytesField]) @@@prisma

/**
* Specifies the schema to use in a multi-schema PostgreSQL database.
Expand Down
2 changes: 1 addition & 1 deletion packages/orm/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/orm",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack ORM",
"type": "module",
"scripts": {
Expand Down
8 changes: 6 additions & 2 deletions packages/orm/src/client/crud/dialects/base-dialect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
}

case 'has': {
clauses.push(this.buildArrayContains(receiver, this.eb.val(value)));
clauses.push(this.buildArrayContains(receiver, this.eb.val(value), fieldType));
break;
}

Expand Down Expand Up @@ -1442,7 +1442,11 @@ export abstract class BaseCrudDialect<Schema extends SchemaDef> {
/**
* Builds an expression that checks if an array contains a single value.
*/
abstract buildArrayContains(field: Expression<unknown>, value: Expression<unknown>): AliasableExpression<SqlBool>;
abstract buildArrayContains(
field: Expression<unknown>,
value: Expression<unknown>,
elemType?: string,
): AliasableExpression<SqlBool>;

/**
* Builds an expression that checks if an array contains all values from another array.
Expand Down
1 change: 1 addition & 0 deletions packages/orm/src/client/crud/dialects/mysql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ export class MySqlCrudDialect<Schema extends SchemaDef> extends LateralJoinDiale
override buildArrayContains(
_field: Expression<unknown>,
_value: Expression<unknown>,
_elemType?: string,
): AliasableExpression<SqlBool> {
throw createNotSupportedError('MySQL does not support native array operations');
}
Expand Down
17 changes: 14 additions & 3 deletions packages/orm/src/client/crud/dialects/postgresql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,9 +284,20 @@ export class PostgresCrudDialect<Schema extends SchemaDef> extends LateralJoinDi
return this.eb.cast(arr, sql`${sql.raw(mappedType)}[]`);
}

override buildArrayContains(field: Expression<unknown>, value: Expression<unknown>): AliasableExpression<SqlBool> {
// PostgreSQL @> operator expects array on both sides, so wrap single value in array
return this.eb(field, '@>', sql`ARRAY[${value}]`);
override buildArrayContains(
field: Expression<unknown>,
value: Expression<unknown>,
elemType?: string,
): AliasableExpression<SqlBool> {
// PostgreSQL @> operator expects array on both sides, so wrap single value in a typed array
const arrayExpr = sql`ARRAY[${value}]`;
if (elemType) {
const mappedType = this.getSqlType(elemType);
const typedArray = this.eb.cast(arrayExpr, sql`${sql.raw(mappedType)}[]`);
return this.eb(field, '@>', typedArray);
} else {
return this.eb(field, '@>', arrayExpr);
}
}

override buildArrayHasEvery(field: Expression<unknown>, values: Expression<unknown>): AliasableExpression<SqlBool> {
Expand Down
1 change: 1 addition & 0 deletions packages/orm/src/client/crud/dialects/sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,7 @@ export class SqliteCrudDialect<Schema extends SchemaDef> extends BaseCrudDialect
override buildArrayContains(
_field: Expression<unknown>,
_value: Expression<unknown>,
_elemType?: string,
): AliasableExpression<SqlBool> {
throw createNotSupportedError('SQLite does not support native array operations');
}
Expand Down
1 change: 1 addition & 0 deletions packages/orm/src/client/helpers/schema-db-pusher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,7 @@ export class SchemaDbPusher<Schema extends SchemaDef> {

private get floatType() {
return match<string, ColumnDataType | RawBuilder<unknown>>(this.schema.provider.type)
.with('postgresql', () => 'double precision')
.with('mysql', () => sql.raw('double'))
.otherwise(() => 'real');
}
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/policy/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/plugin-policy",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack Policy Plugin",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/schema",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack Runtime Schema",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/sdk/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/sdk",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack SDK",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/server",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack automatic CRUD API handlers and server adapters",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/testtools/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/testtools",
"version": "3.3.2",
"version": "3.3.3",
"description": "ZenStack Test Tools",
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion packages/zod/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/zod",
"version": "3.3.2",
"version": "3.3.3",
"description": "",
"type": "module",
"main": "index.js",
Expand Down
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-blog",
"version": "3.3.2",
"version": "3.3.3",
"description": "",
"main": "index.js",
"private": true,
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.3.2",
"version": "3.3.3",
"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.3.2",
"version": "3.3.3",
"private": true,
"type": "module",
"scripts": {
Expand Down
Loading
Loading