diff --git a/package.json b/package.json index 483728798..39cc8cd21 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zenstack-v3", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack", "packageManager": "pnpm@10.23.0", "type": "module", diff --git a/packages/auth-adapters/better-auth/package.json b/packages/auth-adapters/better-auth/package.json index 9e870515a..e8a6a1e7d 100644 --- a/packages/auth-adapters/better-auth/package.json +++ b/packages/auth-adapters/better-auth/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/better-auth", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack Better Auth Adapter. This adapter is modified from better-auth's Prisma adapter.", "type": "module", "scripts": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 2196fa74d..417b06e36 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -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.0", + "version": "3.3.1", "type": "module", "author": { "name": "ZenStack Team" diff --git a/packages/cli/src/actions/proxy.ts b/packages/cli/src/actions/proxy.ts index 4da3ca431..a38386995 100644 --- a/packages/cli/src/actions/proxy.ts +++ b/packages/cli/src/actions/proxy.ts @@ -1,5 +1,11 @@ -import { ZModelCodeGenerator } from '@zenstackhq/language'; -import { isDataSource } from '@zenstackhq/language/ast'; +import { + ConfigExpr, + InvocationExpr, + isDataSource, + isInvocationExpr, + isLiteralExpr, + LiteralExpr, +} from '@zenstackhq/language/ast'; import { getStringLiteral } from '@zenstackhq/language/utils'; import { ZenStackClient, type ClientContract } from '@zenstackhq/orm'; import { MysqlDialect } from '@zenstackhq/orm/dialects/mysql'; @@ -28,6 +34,10 @@ type Options = { }; export async function run(options: Options) { + const allowedLogLevels = ['error', 'query'] as const; + const log = options.logLevel?.filter((level): level is (typeof allowedLogLevels)[number] => + allowedLogLevels.includes(level as any), + ); const schemaFile = getSchemaFile(options.schema); console.log(colors.gray(`Loading ZModel schema from: ${schemaFile}`)); @@ -46,16 +56,12 @@ export async function run(options: Options) { if (!databaseUrl) { const schemaUrl = dataSource?.fields.find((f) => f.name === 'url')?.value; - if (!schemaUrl) { throw new CliError( `The schema's "datasource" does not have a "url" field, please provide it with -d option.`, ); } - const zModelGenerator = new ZModelCodeGenerator(); - const url = zModelGenerator.generate(schemaUrl); - - databaseUrl = evaluateUrl(url); + databaseUrl = evaluateUrl(schemaUrl); } const provider = getStringLiteral(dataSource?.fields.find((f) => f.name === 'provider')?.value)!; @@ -66,11 +72,6 @@ export async function run(options: Options) { const schemaModule = (await jiti.import(path.join(outputPath, 'schema'))) as any; - const allowedLogLevels = ['error', 'query'] as const; - const log = options.logLevel?.filter((level): level is (typeof allowedLogLevels)[number] => - allowedLogLevels.includes(level as any), - ); - const db = new ZenStackClient(schemaModule.schema, { dialect: dialect, log: log && log.length > 0 ? log : undefined, @@ -86,18 +87,20 @@ export async function run(options: Options) { startServer(db, schemaModule.schema, options); } -function evaluateUrl(value: string): string { - // Check if it's an env() function call - const envMatch = value.trim().match(/^env\s*\(\s*['"]([^'"]+)['"]\s*\)$/); - if (envMatch) { - const varName = envMatch[1]; - const envValue = process.env[varName!]; +function evaluateUrl(schemaUrl: ConfigExpr) { + if (isLiteralExpr(schemaUrl)) { + // Handle string literal + return getStringLiteral(schemaUrl); + } else if (isInvocationExpr(schemaUrl)) { + const envFunction = schemaUrl as InvocationExpr; + const envName = getStringLiteral(envFunction.args[0]?.value as LiteralExpr)!; + const envValue = process.env[envName]; if (!envValue) { - throw new CliError(`Environment variable ${varName} is not set`); + throw new CliError(`Environment variable ${envName} is not set`); } return envValue; } else { - return value; + throw new CliError(`Unable to resolve the "url" field value.`); } } diff --git a/packages/clients/client-helpers/package.json b/packages/clients/client-helpers/package.json index d98a534cd..08f5f9069 100644 --- a/packages/clients/client-helpers/package.json +++ b/packages/clients/client-helpers/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/client-helpers", - "version": "3.3.0", + "version": "3.3.1", "description": "Helpers for implementing clients that consume ZenStack's CRUD service", "type": "module", "scripts": { diff --git a/packages/clients/tanstack-query/package.json b/packages/clients/tanstack-query/package.json index f7038c56a..871c3f0f3 100644 --- a/packages/clients/tanstack-query/package.json +++ b/packages/clients/tanstack-query/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/tanstack-query", - "version": "3.3.0", + "version": "3.3.1", "description": "TanStack Query Client for consuming ZenStack v3's CRUD service", "type": "module", "scripts": { diff --git a/packages/clients/tanstack-query/src/common/client.ts b/packages/clients/tanstack-query/src/common/client.ts index c9609d510..9914ea736 100644 --- a/packages/clients/tanstack-query/src/common/client.ts +++ b/packages/clients/tanstack-query/src/common/client.ts @@ -1,6 +1,6 @@ import type { QueryClient } from '@tanstack/query-core'; import type { InvalidationPredicate, QueryInfo } from '@zenstackhq/client-helpers'; -import { parseQueryKey } from './query-key'; +import { parseQueryKey } from './query-key.js'; export function invalidateQueriesMatchingPredicate(queryClient: QueryClient, predicate: InvalidationPredicate) { return queryClient.invalidateQueries({ diff --git a/packages/clients/tanstack-query/src/react.ts b/packages/clients/tanstack-query/src/react.ts index 75045f5cd..1f718fd37 100644 --- a/packages/clients/tanstack-query/src/react.ts +++ b/packages/clients/tanstack-query/src/react.ts @@ -54,9 +54,9 @@ import type { } from '@zenstackhq/orm'; import type { GetModels, SchemaDef } from '@zenstackhq/schema'; import { createContext, useContext } from 'react'; -import { getAllQueries, invalidateQueriesMatchingPredicate } from './common/client'; -import { CUSTOM_PROC_ROUTE_NAME } from './common/constants'; -import { getQueryKey } from './common/query-key'; +import { getAllQueries, invalidateQueriesMatchingPredicate } from './common/client.js'; +import { CUSTOM_PROC_ROUTE_NAME } from './common/constants.js'; +import { getQueryKey } from './common/query-key.js'; import type { ExtraMutationOptions, ExtraQueryOptions, @@ -64,7 +64,7 @@ import type { QueryContext, TrimDelegateModelOperations, WithOptimistic, -} from './common/types'; +} from './common/types.js'; export type { FetchFn } from '@zenstackhq/client-helpers/fetch'; type ProcedureHookFn< diff --git a/packages/clients/tanstack-query/src/svelte/index.svelte.ts b/packages/clients/tanstack-query/src/svelte/index.svelte.ts index 0c976b715..b608e478d 100644 --- a/packages/clients/tanstack-query/src/svelte/index.svelte.ts +++ b/packages/clients/tanstack-query/src/svelte/index.svelte.ts @@ -55,9 +55,9 @@ import type { } from '@zenstackhq/orm'; import type { GetModels, SchemaDef } from '@zenstackhq/schema'; import { getContext, setContext } from 'svelte'; -import { getAllQueries, invalidateQueriesMatchingPredicate } from '../common/client'; -import { CUSTOM_PROC_ROUTE_NAME } from '../common/constants'; -import { getQueryKey } from '../common/query-key'; +import { getAllQueries, invalidateQueriesMatchingPredicate } from '../common/client.js'; +import { CUSTOM_PROC_ROUTE_NAME } from '../common/constants.js'; +import { getQueryKey } from '../common/query-key.js'; import type { ExtraMutationOptions, ExtraQueryOptions, @@ -65,7 +65,7 @@ import type { QueryContext, TrimDelegateModelOperations, WithOptimistic, -} from '../common/types'; +} from '../common/types.js'; export type { FetchFn } from '@zenstackhq/client-helpers/fetch'; type ProcedureHookFn< diff --git a/packages/clients/tanstack-query/src/vue.ts b/packages/clients/tanstack-query/src/vue.ts index bc0bf39f3..d63aa7e05 100644 --- a/packages/clients/tanstack-query/src/vue.ts +++ b/packages/clients/tanstack-query/src/vue.ts @@ -53,9 +53,9 @@ import type { } from '@zenstackhq/orm'; import type { GetModels, SchemaDef } from '@zenstackhq/schema'; import { computed, inject, provide, toValue, unref, type MaybeRefOrGetter, type Ref, type UnwrapRef } from 'vue'; -import { getAllQueries, invalidateQueriesMatchingPredicate } from './common/client'; -import { CUSTOM_PROC_ROUTE_NAME } from './common/constants'; -import { getQueryKey } from './common/query-key'; +import { getAllQueries, invalidateQueriesMatchingPredicate } from './common/client.js'; +import { CUSTOM_PROC_ROUTE_NAME } from './common/constants.js'; +import { getQueryKey } from './common/query-key.js'; import type { ExtraMutationOptions, ExtraQueryOptions, @@ -63,7 +63,7 @@ import type { QueryContext, TrimDelegateModelOperations, WithOptimistic, -} from './common/types'; +} from './common/types.js'; export type { FetchFn } from '@zenstackhq/client-helpers/fetch'; export const VueQueryContextKey = 'zenstack-vue-query-context'; diff --git a/packages/common-helpers/package.json b/packages/common-helpers/package.json index 7bd2d2836..98012a3b2 100644 --- a/packages/common-helpers/package.json +++ b/packages/common-helpers/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/common-helpers", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack Common Helpers", "type": "module", "scripts": { diff --git a/packages/config/eslint-config/package.json b/packages/config/eslint-config/package.json index 0a165bb09..2393786a6 100644 --- a/packages/config/eslint-config/package.json +++ b/packages/config/eslint-config/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/eslint-config", - "version": "3.3.0", + "version": "3.3.1", "type": "module", "private": true, "license": "MIT" diff --git a/packages/config/typescript-config/package.json b/packages/config/typescript-config/package.json index 5f2123433..b471a9e0e 100644 --- a/packages/config/typescript-config/package.json +++ b/packages/config/typescript-config/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/typescript-config", - "version": "3.3.0", + "version": "3.3.1", "private": true, "license": "MIT" } diff --git a/packages/config/vitest-config/package.json b/packages/config/vitest-config/package.json index d15f57401..ac62bbe1c 100644 --- a/packages/config/vitest-config/package.json +++ b/packages/config/vitest-config/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/vitest-config", "type": "module", - "version": "3.3.0", + "version": "3.3.1", "private": true, "license": "MIT", "exports": { diff --git a/packages/create-zenstack/package.json b/packages/create-zenstack/package.json index c62e80c52..52acfc886 100644 --- a/packages/create-zenstack/package.json +++ b/packages/create-zenstack/package.json @@ -1,6 +1,6 @@ { "name": "create-zenstack", - "version": "3.3.0", + "version": "3.3.1", "description": "Create a new ZenStack project", "type": "module", "scripts": { diff --git a/packages/ide/vscode/package.json b/packages/ide/vscode/package.json index e5b8933b4..7c6a41f30 100644 --- a/packages/ide/vscode/package.json +++ b/packages/ide/vscode/package.json @@ -1,7 +1,7 @@ { "name": "zenstack-v3", "publisher": "zenstack", - "version": "3.3.0", + "version": "3.3.1", "displayName": "ZenStack V3 Language Tools", "description": "VSCode extension for ZenStack (v3) ZModel language", "private": true, diff --git a/packages/language/package.json b/packages/language/package.json index c5f60b107..b88523d10 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/language", "description": "ZenStack ZModel language specification", - "version": "3.3.0", + "version": "3.3.1", "license": "MIT", "author": "ZenStack Team", "files": [ diff --git a/packages/orm/package.json b/packages/orm/package.json index 67d7da753..82eb8f3c9 100644 --- a/packages/orm/package.json +++ b/packages/orm/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/orm", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack ORM", "type": "module", "scripts": { diff --git a/packages/plugins/policy/package.json b/packages/plugins/policy/package.json index eb5b49705..ab7f8739a 100644 --- a/packages/plugins/policy/package.json +++ b/packages/plugins/policy/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/plugin-policy", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack Policy Plugin", "type": "module", "scripts": { diff --git a/packages/schema/package.json b/packages/schema/package.json index a1d1dd76a..6081827e8 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/schema", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack Runtime Schema", "type": "module", "scripts": { diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 79cc9883e..ad0ad9ac3 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/sdk", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack SDK", "type": "module", "scripts": { diff --git a/packages/server/package.json b/packages/server/package.json index 499ac858c..63255ecc9 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/server", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack automatic CRUD API handlers and server adapters", "type": "module", "scripts": { diff --git a/packages/testtools/package.json b/packages/testtools/package.json index 648e63ff4..6ca029d29 100644 --- a/packages/testtools/package.json +++ b/packages/testtools/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/testtools", - "version": "3.3.0", + "version": "3.3.1", "description": "ZenStack Test Tools", "type": "module", "scripts": { diff --git a/packages/zod/package.json b/packages/zod/package.json index 4b282a25f..cb501d8e3 100644 --- a/packages/zod/package.json +++ b/packages/zod/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/zod", - "version": "3.3.0", + "version": "3.3.1", "description": "", "type": "module", "main": "index.js", diff --git a/samples/orm/package.json b/samples/orm/package.json index 3b9ba4acc..001b1920a 100644 --- a/samples/orm/package.json +++ b/samples/orm/package.json @@ -1,6 +1,6 @@ { "name": "sample-blog", - "version": "3.3.0", + "version": "3.3.1", "description": "", "main": "index.js", "private": true, diff --git a/tests/e2e/package.json b/tests/e2e/package.json index d7b3f4b55..9949ab634 100644 --- a/tests/e2e/package.json +++ b/tests/e2e/package.json @@ -1,6 +1,6 @@ { "name": "e2e", - "version": "3.3.0", + "version": "3.3.1", "private": true, "type": "module", "scripts": { diff --git a/tests/regression/package.json b/tests/regression/package.json index 2f9fd6330..d9d9bdc3f 100644 --- a/tests/regression/package.json +++ b/tests/regression/package.json @@ -1,6 +1,6 @@ { "name": "regression", - "version": "3.3.0", + "version": "3.3.1", "private": true, "type": "module", "scripts": { diff --git a/tests/runtimes/bun/package.json b/tests/runtimes/bun/package.json index 8ed96ebc2..1f42ba1e8 100644 --- a/tests/runtimes/bun/package.json +++ b/tests/runtimes/bun/package.json @@ -1,6 +1,6 @@ { "name": "bun-e2e", - "version": "3.3.0", + "version": "3.3.1", "private": true, "type": "module", "scripts": { diff --git a/tests/runtimes/edge-runtime/package.json b/tests/runtimes/edge-runtime/package.json index 0999f28c5..5ccb97501 100644 --- a/tests/runtimes/edge-runtime/package.json +++ b/tests/runtimes/edge-runtime/package.json @@ -1,6 +1,6 @@ { "name": "edge-runtime-e2e", - "version": "3.3.0", + "version": "3.3.1", "private": true, "type": "module", "scripts": {