diff --git a/.github/release/.release-manifest.json b/.github/release/.release-manifest.json index 1857a084d..388e76056 100644 --- a/.github/release/.release-manifest.json +++ b/.github/release/.release-manifest.json @@ -1,14 +1,14 @@ { - ".": "2.0.0-alpha.1", - "packages/ide/jetbrains": "2.0.0-alpha.2", - "packages/language": "2.0.0-alpha.2", - "packages/misc/redwood": "2.0.0-alpha.2", - "packages/plugins/openapi": "2.0.0-alpha.2", - "packages/plugins/swr": "2.0.0-alpha.2", - "packages/plugins/tanstack-query": "2.0.0-alpha.2", - "packages/plugins/trpc": "2.0.0-alpha.2", - "packages/runtime": "2.0.0-alpha.2", - "packages/sdk": "2.0.0-alpha.2", - "packages/server": "2.0.0-alpha.2", - "packages/testtools": "2.0.0-alpha.2" + ".": "2.0.0-alpha.2", + "packages/ide/jetbrains": "2.0.0-alpha.3", + "packages/language": "2.0.0-alpha.3", + "packages/misc/redwood": "2.0.0-alpha.3", + "packages/plugins/openapi": "2.0.0-alpha.3", + "packages/plugins/swr": "2.0.0-alpha.3", + "packages/plugins/tanstack-query": "2.0.0-alpha.3", + "packages/plugins/trpc": "2.0.0-alpha.3", + "packages/runtime": "2.0.0-alpha.3", + "packages/sdk": "2.0.0-alpha.3", + "packages/server": "2.0.0-alpha.3", + "packages/testtools": "2.0.0-alpha.3" } \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 14a85cdea..a7d1431df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,24 @@ -# 0.5.0 (2022-12-15) +# Changelog + +## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* default auth without user context ([#1015](https://github.com/zenstackhq/zenstack/issues/1015)) ([e5b5a0f](https://github.com/zenstackhq/zenstack/commit/e5b5a0fee34e46bee5557229f6f5894629c6ad96)) +* foreign key constraint ambiguity in generated delegate prisma schema ([#1060](https://github.com/zenstackhq/zenstack/issues/1060)) ([ca2a314](https://github.com/zenstackhq/zenstack/commit/ca2a314a927053703e4dbc76542499159b8bf6a8)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* **polymorphism:** support `orderBy` with base fields ([#1086](https://github.com/zenstackhq/zenstack/issues/1086)) ([2e81a08](https://github.com/zenstackhq/zenstack/commit/2e81a089a1b57ebf61d25fc49300fa22f0cda06b)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) +* several issues with using `auth()` in `[@default](https://github.com/default)` ([#1088](https://github.com/zenstackhq/zenstack/issues/1088)) ([36e515e](https://github.com/zenstackhq/zenstack/commit/36e515e485c580657b9edbfc52014f3542abfb96)) + + +### Performance Improvements + +* improve polymorphism code generation speed ([#1073](https://github.com/zenstackhq/zenstack/issues/1073)) ([5b103ba](https://github.com/zenstackhq/zenstack/commit/5b103badea7876b7dfc1da91c26eca3213ddd413)) + +## 0.5.0 (2022-12-15) ### Features @@ -12,7 +32,7 @@ - Next-auth adapter and helper are moved to a separate package `@zenstackhq/next-auth`. -# 0.4.0 (2022-12-01) +## 0.4.0 (2022-12-01) ### Features @@ -50,7 +70,7 @@ Use @zenstackhq/runtime/types for type definitions shared between client and server, @zenstackhq/runtime/client for client-specific libaries (like React hooks), and @zenstackhq/runtime/server for server-specific libraries. -# 0.3.0 (2022-11-08) +## 0.3.0 (2022-11-08) ### Features @@ -70,7 +90,7 @@ - Better overall documentation -# 0.2.0 (2022-10-29) +## 0.2.0 (2022-10-29) ### Features diff --git a/package.json b/package.json index 54769b34b..febc93264 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zenstack-monorepo", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.2", "description": "", "scripts": { "build": "pnpm -r build", diff --git a/packages/ide/jetbrains/CHANGELOG.md b/packages/ide/jetbrains/CHANGELOG.md index 6f0f0e7ff..f8379c4bf 100644 --- a/packages/ide/jetbrains/CHANGELOG.md +++ b/packages/ide/jetbrains/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/ide/jetbrains/build.gradle.kts b/packages/ide/jetbrains/build.gradle.kts index 23c8d0b7b..d74358e5f 100644 --- a/packages/ide/jetbrains/build.gradle.kts +++ b/packages/ide/jetbrains/build.gradle.kts @@ -9,7 +9,7 @@ plugins { } group = "dev.zenstack" -version = "2.0.0-alpha.4" +version = "2.0.0-alpha.5" repositories { mavenCentral() diff --git a/packages/ide/jetbrains/package.json b/packages/ide/jetbrains/package.json index db2daea8d..45658df7a 100644 --- a/packages/ide/jetbrains/package.json +++ b/packages/ide/jetbrains/package.json @@ -1,6 +1,6 @@ { "name": "jetbrains", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "displayName": "ZenStack JetBrains IDE Plugin", "description": "ZenStack JetBrains IDE plugin", "homepage": "https://zenstack.dev", diff --git a/packages/language/CHANGELOG.md b/packages/language/CHANGELOG.md index cc2a59fdc..c91071f7a 100644 --- a/packages/language/CHANGELOG.md +++ b/packages/language/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/language/package.json b/packages/language/package.json index 315e65049..d1928eb0a 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/language", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "displayName": "ZenStack modeling language compiler", "description": "ZenStack modeling language compiler", "homepage": "https://zenstack.dev", @@ -23,7 +23,7 @@ "plist2": "^1.1.3" }, "dependencies": { - "langium": "1.3.1" + "langium": "1.3.1" }, "contributes": { "languages": [ diff --git a/packages/misc/redwood/CHANGELOG.md b/packages/misc/redwood/CHANGELOG.md index cc2a59fdc..c91071f7a 100644 --- a/packages/misc/redwood/CHANGELOG.md +++ b/packages/misc/redwood/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/misc/redwood/package.json b/packages/misc/redwood/package.json index 9886151b4..10e4b55fb 100644 --- a/packages/misc/redwood/package.json +++ b/packages/misc/redwood/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/redwood", "displayName": "ZenStack RedwoodJS Integration", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.", "repository": { "type": "git", diff --git a/packages/plugins/openapi/CHANGELOG.md b/packages/plugins/openapi/CHANGELOG.md index cc2a59fdc..9d0877c75 100644 --- a/packages/plugins/openapi/CHANGELOG.md +++ b/packages/plugins/openapi/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/plugins/openapi/package.json b/packages/plugins/openapi/package.json index 5d191e2ff..b4a539941 100644 --- a/packages/plugins/openapi/package.json +++ b/packages/plugins/openapi/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/openapi", "displayName": "ZenStack Plugin and Runtime for OpenAPI", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "ZenStack plugin and runtime supporting OpenAPI", "main": "index.js", "repository": { diff --git a/packages/plugins/swr/CHANGELOG.md b/packages/plugins/swr/CHANGELOG.md index cc2a59fdc..9d0877c75 100644 --- a/packages/plugins/swr/CHANGELOG.md +++ b/packages/plugins/swr/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/plugins/swr/package.json b/packages/plugins/swr/package.json index 12652665d..327a8dcfc 100644 --- a/packages/plugins/swr/package.json +++ b/packages/plugins/swr/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/swr", "displayName": "ZenStack plugin for generating SWR hooks", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "ZenStack plugin for generating SWR hooks", "main": "index.js", "repository": { diff --git a/packages/plugins/tanstack-query/CHANGELOG.md b/packages/plugins/tanstack-query/CHANGELOG.md index cc2a59fdc..9d0877c75 100644 --- a/packages/plugins/tanstack-query/CHANGELOG.md +++ b/packages/plugins/tanstack-query/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/plugins/tanstack-query/package.json b/packages/plugins/tanstack-query/package.json index 3da2d8bf8..8dd0d15d3 100644 --- a/packages/plugins/tanstack-query/package.json +++ b/packages/plugins/tanstack-query/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/tanstack-query", "displayName": "ZenStack plugin for generating tanstack-query hooks", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "ZenStack plugin for generating tanstack-query hooks", "main": "index.js", "exports": { diff --git a/packages/plugins/trpc/CHANGELOG.md b/packages/plugins/trpc/CHANGELOG.md index cc2a59fdc..9d0877c75 100644 --- a/packages/plugins/trpc/CHANGELOG.md +++ b/packages/plugins/trpc/CHANGELOG.md @@ -1,5 +1,14 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/plugins/trpc/package.json b/packages/plugins/trpc/package.json index c21bccd72..e4f8e4a05 100644 --- a/packages/plugins/trpc/package.json +++ b/packages/plugins/trpc/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/trpc", "displayName": "ZenStack plugin for tRPC", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "ZenStack plugin for tRPC", "main": "index.js", "repository": { diff --git a/packages/runtime/CHANGELOG.md b/packages/runtime/CHANGELOG.md index cc2a59fdc..edfc82a55 100644 --- a/packages/runtime/CHANGELOG.md +++ b/packages/runtime/CHANGELOG.md @@ -1,5 +1,17 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* default auth without user context ([#1015](https://github.com/zenstackhq/zenstack/issues/1015)) ([e5b5a0f](https://github.com/zenstackhq/zenstack/commit/e5b5a0fee34e46bee5557229f6f5894629c6ad96)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* **polymorphism:** support `orderBy` with base fields ([#1086](https://github.com/zenstackhq/zenstack/issues/1086)) ([2e81a08](https://github.com/zenstackhq/zenstack/commit/2e81a089a1b57ebf61d25fc49300fa22f0cda06b)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) +* several issues with using `auth()` in `[@default](https://github.com/default)` ([#1088](https://github.com/zenstackhq/zenstack/issues/1088)) ([36e515e](https://github.com/zenstackhq/zenstack/commit/36e515e485c580657b9edbfc52014f3542abfb96)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 4dcb94daa..c80bbca5f 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/runtime", "displayName": "ZenStack Runtime Library", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "Runtime of ZenStack for both client-side and server-side environments.", "repository": { "type": "git", diff --git a/packages/schema/package.json b/packages/schema/package.json index d2113958a..4fe78d2dd 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -3,7 +3,7 @@ "publisher": "zenstack", "displayName": "ZenStack Language Tools", "description": "Build scalable web apps with minimum code by defining authorization and validation rules inside the data schema that closer to the database", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.5", "author": { "name": "ZenStack Team" }, diff --git a/packages/schema/src/plugins/plugin-utils.ts b/packages/schema/src/plugins/plugin-utils.ts index d6cc12403..f405604d0 100644 --- a/packages/schema/src/plugins/plugin-utils.ts +++ b/packages/schema/src/plugins/plugin-utils.ts @@ -3,6 +3,7 @@ import { PluginGlobalOptions } from '@zenstackhq/sdk'; import fs from 'fs'; import path from 'path'; import { PluginRunnerOptions } from '../cli/plugin-runner'; +import { getPackageManager } from '../utils/pkg-utils'; export const ALL_OPERATION_KINDS: PolicyOperationKind[] = ['create', 'update', 'postUpdate', 'read', 'delete']; @@ -76,23 +77,32 @@ export function getDefaultOutputFolder(globalOptions?: PluginGlobalOptions) { return path.resolve(globalOptions.output); } - // Find the real runtime module path, it might be a symlink in pnpm - let runtimeModulePath = require.resolve('@zenstackhq/runtime'); - + // for testing, use the local node_modules if (process.env.ZENSTACK_TEST === '1') { - // handle the case when running as tests, resolve relative to CWD - runtimeModulePath = path.resolve(path.join(process.cwd(), 'node_modules', '@zenstackhq', 'runtime')); + return path.join(process.cwd(), 'node_modules', DEFAULT_RUNTIME_LOAD_PATH); } - if (runtimeModulePath) { - // start with the parent folder of @zenstackhq, supposed to be a node_modules folder - while (!runtimeModulePath.endsWith('@zenstackhq') && runtimeModulePath !== '/') { + const { projectRoot } = getPackageManager(__dirname); + if (fs.existsSync(path.join(projectRoot, 'node_modules'))) { + // use the located node_modules folder + return path.join(projectRoot, 'node_modules', DEFAULT_RUNTIME_LOAD_PATH); + } else { + // unable to locate a node_modules folder, fallback to where the runtime + // package resides + + // find the real runtime module path, it might be a symlink in pnpm + let runtimeModulePath = require.resolve('@zenstackhq/runtime'); + + if (runtimeModulePath) { + // start with the parent folder of @zenstackhq, supposed to be a node_modules folder + while (!runtimeModulePath.endsWith('@zenstackhq') && runtimeModulePath !== '/') { + runtimeModulePath = path.join(runtimeModulePath, '..'); + } runtimeModulePath = path.join(runtimeModulePath, '..'); } - runtimeModulePath = path.join(runtimeModulePath, '..'); + const modulesFolder = getNodeModulesFolder(runtimeModulePath); + return modulesFolder ? path.join(modulesFolder, DEFAULT_RUNTIME_LOAD_PATH) : undefined; } - const modulesFolder = getNodeModulesFolder(runtimeModulePath); - return modulesFolder ? path.join(modulesFolder, DEFAULT_RUNTIME_LOAD_PATH) : undefined; } /** diff --git a/packages/schema/src/utils/pkg-utils.ts b/packages/schema/src/utils/pkg-utils.ts index ce41dac34..69c42e1ae 100644 --- a/packages/schema/src/utils/pkg-utils.ts +++ b/packages/schema/src/utils/pkg-utils.ts @@ -1,22 +1,23 @@ import fs from 'node:fs'; import path from 'node:path'; import { execSync } from './exec-utils'; +import { match } from 'ts-pattern'; export type PackageManagers = 'npm' | 'yarn' | 'pnpm'; /** - * A type named FindUp that takes a type parameter e which extends boolean. - * If e extends true, it returns a union type of string[] or undefined. + * A type named FindUp that takes a type parameter e which extends boolean. + * If e extends true, it returns a union type of string[] or undefined. * If e does not extend true, it returns a union type of string or undefined. * * @export * @template e A type parameter that extends boolean */ -export type FindUp = e extends true ? string[] | undefined : string | undefined +export type FindUp = e extends true ? string[] | undefined : string | undefined; /** - * Find and return file paths by searching parent directories based on the given names list and current working directory (cwd) path. - * Optionally return a single path or multiple paths. - * If multiple allowed, return all paths found. + * Find and return file paths by searching parent directories based on the given names list and current working directory (cwd) path. + * Optionally return a single path or multiple paths. + * If multiple allowed, return all paths found. * If no paths are found, return undefined. * * @export @@ -27,7 +28,12 @@ export type FindUp = e extends true ? string[] | undefined : * @param [result=[]] An array of strings representing the accumulated results used in multiple results * @returns Path(s) to a specific file or folder within the directory or parent directories */ -export function findUp(names: string[], cwd: string = process.cwd(), multiple: e = false as e, result: string[] = []): FindUp { +export function findUp( + names: string[], + cwd: string = process.cwd(), + multiple: e = false as e, + result: string[] = [] +): FindUp { if (!names.some((name) => !!name)) return undefined; const target = names.find((name) => fs.existsSync(path.join(cwd, name))); if (multiple == false && target) return path.join(cwd, target) as FindUp; @@ -37,23 +43,22 @@ export function findUp(names: string[], cwd: string = return findUp(names, up, multiple, result); } -function getPackageManager(projectPath = '.'): PackageManagers { - const lockFile = findUp(['yarn.lock', 'pnpm-lock.yaml', 'package-lock.json'], projectPath); +export function getPackageManager(searchStartPath = '.') { + const lockFile = findUp(['yarn.lock', 'pnpm-lock.yaml', 'package-lock.json'], searchStartPath); if (!lockFile) { // default use npm - return 'npm'; + return { packageManager: 'npm', lockFile: undefined, projectRoot: searchStartPath }; } - switch (path.basename(lockFile)) { - case 'yarn.lock': - return 'yarn'; - case 'pnpm-lock.yaml': - return 'pnpm'; - default: - return 'npm'; - } + const packageManager = match(path.basename(lockFile)) + .with('yarn.lock', () => 'yarn') + .with('pnpm-lock.yaml', () => 'pnpm') + .otherwise(() => 'npm'); + + return { packageManager, lockFile, projectRoot: path.dirname(lockFile) }; } + export function installPackage( pkg: string, dev: boolean, @@ -106,7 +111,7 @@ export function ensurePackage( } /** - * A function that searches for the nearest package.json file starting from the provided search path or the current working directory if no search path is provided. + * A function that searches for the nearest package.json file starting from the provided search path or the current working directory if no search path is provided. * It iterates through the directory structure going one level up at a time until it finds a package.json file. If no package.json file is found, it returns undefined. * @deprecated Use findUp instead @see findUp */ diff --git a/packages/sdk/CHANGELOG.md b/packages/sdk/CHANGELOG.md index cc2a59fdc..bebfa058c 100644 --- a/packages/sdk/CHANGELOG.md +++ b/packages/sdk/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) +* several issues with using `auth()` in `[@default](https://github.com/default)` ([#1088](https://github.com/zenstackhq/zenstack/issues/1088)) ([36e515e](https://github.com/zenstackhq/zenstack/commit/36e515e485c580657b9edbfc52014f3542abfb96)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/sdk/package.json b/packages/sdk/package.json index d29ecefe1..5bdf1dc2b 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/sdk", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "ZenStack plugin development SDK", "main": "index.js", "scripts": { diff --git a/packages/server/CHANGELOG.md b/packages/server/CHANGELOG.md index cc2a59fdc..c91071f7a 100644 --- a/packages/server/CHANGELOG.md +++ b/packages/server/CHANGELOG.md @@ -1,5 +1,13 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/server/package.json b/packages/server/package.json index 40b660ef5..59c01026a 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/server", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "displayName": "ZenStack Server-side Adapters", "description": "ZenStack server-side adapters", "homepage": "https://zenstack.dev", diff --git a/packages/server/src/shared.ts b/packages/server/src/shared.ts index 1a9c62119..7538411c5 100644 --- a/packages/server/src/shared.ts +++ b/packages/server/src/shared.ts @@ -1,5 +1,5 @@ /* eslint-disable @typescript-eslint/no-var-requires */ -import type { ModelMeta, PolicyDef, ZodSchemas } from '@zenstackhq/runtime'; +import { DEFAULT_RUNTIME_LOAD_PATH, type ModelMeta, type PolicyDef, type ZodSchemas } from '@zenstackhq/runtime'; import path from 'path'; import { AdapterBaseOptions } from './types'; @@ -39,7 +39,8 @@ export function getDefaultModelMeta(loadPath: string | undefined): ModelMeta { if (process.env.ZENSTACK_TEST === '1' && !loadPath) { try { // special handling for running as tests, try resolving relative to CWD - return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'model-meta')).default; + return require(path.join(process.cwd(), 'node_modules', DEFAULT_RUNTIME_LOAD_PATH, 'model-meta')) + .default; } catch { throw new Error('Model meta cannot be loaded. Please make sure "zenstack generate" has been run.'); } @@ -66,7 +67,7 @@ export function getDefaultPolicy(loadPath: string | undefined): PolicyDef { if (process.env.ZENSTACK_TEST === '1' && !loadPath) { try { // special handling for running as tests, try resolving relative to CWD - return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'policy')).default; + return require(path.join(process.cwd(), 'node_modules', DEFAULT_RUNTIME_LOAD_PATH, 'policy')).default; } catch { throw new Error( 'Policy definition cannot be loaded from default location. Please make sure "zenstack generate" has been run.' @@ -97,7 +98,7 @@ export function getDefaultZodSchemas(loadPath: string | undefined): ZodSchemas | if (process.env.ZENSTACK_TEST === '1' && !loadPath) { try { // special handling for running as tests, try resolving relative to CWD - return require(path.join(process.cwd(), 'node_modules', '.zenstack', 'zod')); + return require(path.join(process.cwd(), 'node_modules', DEFAULT_RUNTIME_LOAD_PATH, 'zod')); } catch { return undefined; } diff --git a/packages/testtools/CHANGELOG.md b/packages/testtools/CHANGELOG.md index cc2a59fdc..bebfa058c 100644 --- a/packages/testtools/CHANGELOG.md +++ b/packages/testtools/CHANGELOG.md @@ -1,5 +1,15 @@ # Changelog +## [2.0.0-alpha.3](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.2...v2.0.0-alpha.3) (2024-03-07) + + +### Bug Fixes + +* clean up generation of logical prisma client ([#1082](https://github.com/zenstackhq/zenstack/issues/1082)) ([6e7993a](https://github.com/zenstackhq/zenstack/commit/6e7993afa8dde03ae12c44f198bcca04724dbc92)) +* more robust calculation of default location for code generation ([63f5cbc](https://github.com/zenstackhq/zenstack/commit/63f5cbc87ef7e9883ab4daedc01abc1d1a1926dc)) +* prisma.d.ts is not properly saved ([#1090](https://github.com/zenstackhq/zenstack/issues/1090)) ([d3629be](https://github.com/zenstackhq/zenstack/commit/d3629bef459afc11c16461fb18621d2f77ac35cc)) +* several issues with using `auth()` in `[@default](https://github.com/default)` ([#1088](https://github.com/zenstackhq/zenstack/issues/1088)) ([36e515e](https://github.com/zenstackhq/zenstack/commit/36e515e485c580657b9edbfc52014f3542abfb96)) + ## [2.0.0-alpha.2](https://github.com/zenstackhq/zenstack/compare/v2.0.0-alpha.1...v2.0.0-alpha.2) (2024-02-21) diff --git a/packages/testtools/package.json b/packages/testtools/package.json index 35b5078cc..b4741bb63 100644 --- a/packages/testtools/package.json +++ b/packages/testtools/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/testtools", - "version": "2.0.0-alpha.4", + "version": "2.0.0-alpha.3", "description": "ZenStack Test Tools", "main": "index.js", "private": true, diff --git a/packages/testtools/src/schema.ts b/packages/testtools/src/schema.ts index 392b4af4f..ecdad8336 100644 --- a/packages/testtools/src/schema.ts +++ b/packages/testtools/src/schema.ts @@ -2,7 +2,13 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import type { DMMF } from '@prisma/generator-helper'; import type { Model } from '@zenstackhq/language/ast'; -import type { AuthUser, CrudContract, EnhancementKind, EnhancementOptions } from '@zenstackhq/runtime'; +import { + DEFAULT_RUNTIME_LOAD_PATH, + type AuthUser, + type CrudContract, + type EnhancementKind, + type EnhancementOptions, +} from '@zenstackhq/runtime'; import { getDMMF } from '@zenstackhq/sdk'; import { execSync } from 'child_process'; import * as fs from 'fs'; @@ -284,7 +290,7 @@ export async function loadSchema(schema: string, options?: SchemaLoadOptions) { ? path.isAbsolute(opt.output) ? opt.output : path.join(projectRoot, opt.output) - : path.join(projectRoot, 'node_modules', '.zenstack'); + : path.join(projectRoot, 'node_modules', DEFAULT_RUNTIME_LOAD_PATH); const policy = require(path.join(outputPath, 'policy')).default; const modelMeta = require(path.join(outputPath, 'model-meta')).default;