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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"type": "module",
"author": {
"name": "ZenStack Team"
Expand Down
59 changes: 37 additions & 22 deletions packages/cli/src/actions/pull/provider/postgresql.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import type { ZModelServices } from '@zenstackhq/language';
import type { Attribute, BuiltinType, Enum, Expression } from '@zenstackhq/language/ast';
import { AstFactory, DataFieldAttributeFactory, ExpressionBuilder } from '@zenstackhq/language/factory';
import { Client } from 'pg';
import { CliError } from '../../../cli-error';
import { getAttributeRef, getDbName, getFunctionRef, normalizeDecimalDefault, normalizeFloatDefault } from '../utils';
import type { IntrospectedEnum, IntrospectedSchema, IntrospectedTable, IntrospectionProvider } from './provider';
import type { ZModelServices } from '@zenstackhq/language';
import { CliError } from '../../../cli-error';

/**
* Maps PostgreSQL internal type names to their standard SQL names for comparison.
Expand Down Expand Up @@ -110,8 +109,8 @@ const pgTypnameToZenStackNativeType: Record<string, string> = {

export const postgresql: IntrospectionProvider = {
isSupportedFeature(feature) {
const supportedFeatures = ['Schema', 'NativeEnum'];
return supportedFeatures.includes(feature);
const supportedFeatures = ['Schema', 'NativeEnum'];
return supportedFeatures.includes(feature);
},
getBuiltinType(type) {
const t = (type || '').toLowerCase();
Expand Down Expand Up @@ -176,7 +175,11 @@ export const postgresql: IntrospectionProvider = {
return { type: 'Unsupported' as const, isArray };
}
},
async introspect(connectionString: string, options: { schemas: string[]; modelCasing: 'pascal' | 'camel' | 'snake' | 'none' }): Promise<IntrospectedSchema> {
async introspect(
connectionString: string,
options: { schemas: string[]; modelCasing: 'pascal' | 'camel' | 'snake' | 'none' },
): Promise<IntrospectedSchema> {
const { Client } = await import('pg');
const client = new Client({ connectionString });
await client.connect();

Expand Down Expand Up @@ -233,7 +236,7 @@ export const postgresql: IntrospectionProvider = {
}
}
// Fall through to typeCastingConvert if datatype_name lookup fails
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}

switch (fieldType) {
Expand All @@ -243,7 +246,7 @@ export const postgresql: IntrospectionProvider = {
}

if (val.includes('::')) {
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}

// Fallback to string literal for other DateTime defaults
Expand All @@ -256,19 +259,19 @@ export const postgresql: IntrospectionProvider = {
}

if (val.includes('::')) {
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}
return (ab) => ab.NumberLiteral.setValue(val);

case 'Float':
if (val.includes('::')) {
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}
return normalizeFloatDefault(val);

case 'Decimal':
if (val.includes('::')) {
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}
return normalizeDecimalDefault(val);

Expand All @@ -277,7 +280,7 @@ export const postgresql: IntrospectionProvider = {

case 'String':
if (val.includes('::')) {
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}

if (val.startsWith("'") && val.endsWith("'")) {
Expand All @@ -286,12 +289,12 @@ export const postgresql: IntrospectionProvider = {
return (ab) => ab.StringLiteral.setValue(val);
case 'Json':
if (val.includes('::')) {
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}
return (ab) => ab.StringLiteral.setValue(val);
case 'Bytes':
if (val.includes('::')) {
return typeCastingConvert({defaultValue,enums,val,services});
return typeCastingConvert({ defaultValue, enums, val, services });
}
return (ab) => ab.StringLiteral.setValue(val);
}
Expand All @@ -303,15 +306,20 @@ export const postgresql: IntrospectionProvider = {
);
}

console.warn(`Unsupported default value type: "${defaultValue}" for field type "${fieldType}". Skipping default value.`);
console.warn(
`Unsupported default value type: "${defaultValue}" for field type "${fieldType}". Skipping default value.`,
);
return null;
},

getFieldAttributes({ fieldName, fieldType, datatype, length, precision, services }) {
const factories: DataFieldAttributeFactory[] = [];

// Add @updatedAt for DateTime fields named updatedAt or updated_at
if (fieldType === 'DateTime' && (fieldName.toLowerCase() === 'updatedat' || fieldName.toLowerCase() === 'updated_at')) {
if (
fieldType === 'DateTime' &&
(fieldName.toLowerCase() === 'updatedat' || fieldName.toLowerCase() === 'updated_at')
) {
factories.push(new DataFieldAttributeFactory().setDecl(getAttributeRef('@updatedAt', services)));
}

Expand All @@ -338,8 +346,7 @@ export const postgresql: IntrospectionProvider = {
dbAttr &&
defaultDatabaseType &&
(defaultDatabaseType.type !== normalizedDatatype ||
(defaultDatabaseType.precision &&
defaultDatabaseType.precision !== (length ?? precision)))
(defaultDatabaseType.precision && defaultDatabaseType.precision !== (length ?? precision)))
) {
const dbAttrFactory = new DataFieldAttributeFactory().setDecl(dbAttr);
// Only add length/precision if it's meaningful (not the standard bit width for the type)
Expand Down Expand Up @@ -628,7 +635,17 @@ WHERE
ORDER BY "ns"."nspname", "cls"."relname" ASC;
`;

function typeCastingConvert({defaultValue, enums, val, services}:{val: string, enums: Enum[], defaultValue:string, services:ZModelServices}): ((builder: ExpressionBuilder) => AstFactory<Expression>) | null {
function typeCastingConvert({
defaultValue,
enums,
val,
services,
}: {
val: string;
enums: Enum[];
defaultValue: string;
services: ZModelServices;
}): ((builder: ExpressionBuilder) => AstFactory<Expression>) | null {
const [value, type] = val
.replace(/'/g, '')
.split('::')
Expand All @@ -653,9 +670,7 @@ function typeCastingConvert({defaultValue, enums, val, services}:{val: string, e
}
const enumField = enumDef.fields.find((v) => getDbName(v) === value);
if (!enumField) {
throw new CliError(
`Enum value ${value} not found in enum ${type} for default value ${defaultValue}`,
);
throw new CliError(`Enum value ${value} not found in enum ${type} for default value ${defaultValue}`);
}
return (ab) => ab.ReferenceExpr.setTarget(enumField);
}
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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"license": "MIT",
"author": "ZenStack Team",
"files": [
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.4.0",
"version": "3.4.1",
"description": "ZenStack ORM",
"type": "module",
"scripts": {
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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"description": "ZenStack Zod integration",
"type": "module",
"scripts": {
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-orm",
"version": "3.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"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.4.0",
"version": "3.4.1",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tests/runtimes/bun/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "bun-e2e",
"version": "3.4.0",
"version": "3.4.1",
"private": true,
"type": "module",
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion tests/runtimes/edge-runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "edge-runtime-e2e",
"version": "3.4.0",
"version": "3.4.1",
"private": true,
"type": "module",
"scripts": {
Expand Down
Loading