diff --git a/.github/workflows/update-samples.yml b/.github/workflows/update-samples.yml new file mode 100644 index 00000000..97b216ab --- /dev/null +++ b/.github/workflows/update-samples.yml @@ -0,0 +1,115 @@ +name: Update Sample Repos + +on: + release: + types: [published] + workflow_dispatch: + +permissions: + contents: read + +jobs: + update-samples: + runs-on: ubuntu-latest + outputs: + repos: ${{ steps.get-repos.outputs.repos }} + + steps: + - name: Get all public repos with v3-sample topic in @zenstackhq org + id: get-repos + env: + GH_TOKEN: ${{ secrets.PAT_TOKEN }} + run: | + # Get all public repos from the zenstackhq org with v3-sample topic + REPOS=$(gh repo list zenstackhq --json name,isPrivate,nameWithOwner,repositoryTopics --limit 100 | \ + jq -r '.[] | select(.isPrivate == false) | select((.repositoryTopics // []) | map(.name) | contains(["v3-sample"])) | .nameWithOwner') + + echo "Found repos with v3-sample topic:" + echo "$REPOS" + + # Convert to JSON array for matrix + REPOS_JSON=$(echo "$REPOS" | jq -R -s -c 'split("\n") | map(select(length > 0))') + echo "repos=$REPOS_JSON" >> $GITHUB_OUTPUT + + - name: Display repos to update + run: | + echo "Will update the following repos:" + echo '${{ steps.get-repos.outputs.repos }}' | jq -r '.[]' + + update-repo: + needs: update-samples + runs-on: ubuntu-latest + if: ${{ needs.update-samples.outputs.repos != '[]' }} + strategy: + matrix: + repo: ${{ fromJson(needs.update-samples.outputs.repos) }} + fail-fast: false + + steps: + - name: Checkout target repo + uses: actions/checkout@v4 + with: + repository: ${{ matrix.repo }} + token: ${{ secrets.PAT_TOKEN }} + + - name: Check if package.json exists + id: check-package + run: | + if [ -f "package.json" ]; then + echo "exists=true" >> $GITHUB_OUTPUT + else + echo "exists=false" >> $GITHUB_OUTPUT + fi + + - name: Use Node.js + if: steps.check-package.outputs.exists == 'true' + uses: actions/setup-node@v4 + with: + node-version: 20.x + cache: 'npm' + + - name: Update @zenstackhq packages to next + if: steps.check-package.outputs.exists == 'true' + run: | + # Get all @zenstackhq packages in the repo + PACKAGES=$(cat package.json | jq -r ' + [.dependencies, .devDependencies] | + add | + to_entries | + map(select(.key | startswith("@zenstackhq/"))) | + map(.key) | + .[] + ') + + if [ -z "$PACKAGES" ]; then + echo "No @zenstackhq packages found in ${{ matrix.repo }}" + exit 0 + fi + + echo "Updating packages in ${{ matrix.repo }}:" + echo "$PACKAGES" + + # Update each package to next tag + for pkg in $PACKAGES; do + echo "Updating $pkg to next" + npm install "$pkg@next" + done + + # Finally run zenstack generate + npx zen generate + + - name: Commit and push changes + if: steps.check-package.outputs.exists == 'true' + run: | + git config --global user.name "GitHub Actions Bot" + git config --global user.email "actions@github.com" + + # Check if there are changes to commit + if git diff --quiet && git diff --staged --quiet; then + echo "No changes to commit" + exit 0 + fi + + git add . + git commit -m "chore: update @zenstackhq packages to next release" + git push diff --git a/package.json b/package.json index 4867a361..bef5363a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zenstack-v3", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "ZenStack", "packageManager": "pnpm@10.20.0", "scripts": { diff --git a/packages/cli/package.json b/packages/cli/package.json index 77524cd8..39bf3b43 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.0.0-beta.14", + "version": "3.0.0-beta.15", "type": "module", "author": { "name": "ZenStack Team" diff --git a/packages/common-helpers/package.json b/packages/common-helpers/package.json index 17d2d09c..1beb9e15 100644 --- a/packages/common-helpers/package.json +++ b/packages/common-helpers/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/common-helpers", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "ZenStack Common Helpers", "type": "module", "scripts": { diff --git a/packages/config/eslint-config/package.json b/packages/config/eslint-config/package.json index a4ef9a4d..a0c56d72 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.0.0-beta.14", + "version": "3.0.0-beta.15", "type": "module", "private": true, "license": "MIT" diff --git a/packages/config/typescript-config/package.json b/packages/config/typescript-config/package.json index 05056894..0c9f0a9c 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.0.0-beta.14", + "version": "3.0.0-beta.15", "private": true, "license": "MIT" } diff --git a/packages/config/vitest-config/package.json b/packages/config/vitest-config/package.json index d46152d7..74257ed3 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.0.0-beta.14", + "version": "3.0.0-beta.15", "private": true, "license": "MIT", "exports": { diff --git a/packages/create-zenstack/package.json b/packages/create-zenstack/package.json index 0a3add29..77415588 100644 --- a/packages/create-zenstack/package.json +++ b/packages/create-zenstack/package.json @@ -1,6 +1,6 @@ { "name": "create-zenstack", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "Create a new ZenStack project", "type": "module", "scripts": { diff --git a/packages/dialects/sql.js/package.json b/packages/dialects/sql.js/package.json index 234f59b4..2fb82629 100644 --- a/packages/dialects/sql.js/package.json +++ b/packages/dialects/sql.js/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/kysely-sql-js", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "Kysely dialect for sql.js", "type": "module", "scripts": { diff --git a/packages/language/package.json b/packages/language/package.json index 198d7008..f123d173 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.0.0-beta.14", + "version": "3.0.0-beta.15", "license": "MIT", "author": "ZenStack Team", "files": [ diff --git a/packages/orm/package.json b/packages/orm/package.json index 2fb72d7c..50892908 100644 --- a/packages/orm/package.json +++ b/packages/orm/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/orm", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "ZenStack ORM", "type": "module", "scripts": { @@ -63,6 +63,7 @@ }, "dependencies": { "@paralleldrive/cuid2": "^2.2.2", + "@zenstackhq/schema": "workspace:*", "@zenstackhq/common-helpers": "workspace:*", "decimal.js": "catalog:", "json-stable-stringify": "^1.3.0", @@ -92,8 +93,6 @@ "@types/pg": "^8.0.0", "@types/toposort": "^2.0.7", "@zenstackhq/eslint-config": "workspace:*", - "@zenstackhq/language": "workspace:*", - "@zenstackhq/sdk": "workspace:*", "@zenstackhq/typescript-config": "workspace:*", "@zenstackhq/vitest-config": "workspace:*", "tsx": "^4.19.2", diff --git a/packages/orm/src/client/client-impl.ts b/packages/orm/src/client/client-impl.ts index 24b2d2be..150e00df 100644 --- a/packages/orm/src/client/client-impl.ts +++ b/packages/orm/src/client/client-impl.ts @@ -11,9 +11,14 @@ import { type KyselyProps, } from 'kysely'; import type { GetModels, ProcedureDef, SchemaDef } from '../schema'; -import type { AuthType } from '../schema/auth'; import type { UnwrapTuplePromises } from '../utils/type-utils'; -import type { ClientConstructor, ClientContract, ModelOperations, TransactionIsolationLevel } from './contract'; +import type { + AuthType, + ClientConstructor, + ClientContract, + ModelOperations, + TransactionIsolationLevel, +} from './contract'; import { AggregateOperationHandler } from './crud/operations/aggregate'; import type { AllCrudOperation, CoreCrudOperation } from './crud/operations/base'; import { BaseOperationHandler } from './crud/operations/base'; diff --git a/packages/orm/src/client/contract.ts b/packages/orm/src/client/contract.ts index 0d90bc88..81d7c016 100644 --- a/packages/orm/src/client/contract.ts +++ b/packages/orm/src/client/contract.ts @@ -1,6 +1,5 @@ import type Decimal from 'decimal.js'; import { type GetModels, type IsDelegateModel, type ProcedureDef, type SchemaDef } from '../schema'; -import type { AuthType } from '../schema/auth'; import type { OrUndefinedIf, Simplify, UnwrapTuplePromises } from '../utils/type-utils'; import type { TRANSACTION_UNSUPPORTED_METHODS } from './constants'; import type { @@ -803,3 +802,14 @@ export type ModelOperations; //#endregion + +//#region Supporting types + +export type AuthType = + string extends GetModels + ? Record + : Schema['authType'] extends GetModels + ? Partial> + : never; + +//#endregion diff --git a/packages/orm/src/client/crud/validator/utils.ts b/packages/orm/src/client/crud/validator/utils.ts index 6fd95a20..5024b07d 100644 --- a/packages/orm/src/client/crud/validator/utils.ts +++ b/packages/orm/src/client/crud/validator/utils.ts @@ -7,7 +7,7 @@ import type { FieldExpression, MemberExpression, UnaryExpression, -} from '@zenstackhq/sdk/schema'; +} from '@zenstackhq/schema'; import Decimal from 'decimal.js'; import { match, P } from 'ts-pattern'; import { z } from 'zod'; diff --git a/packages/orm/src/schema.ts b/packages/orm/src/schema.ts new file mode 100644 index 00000000..09f7d1de --- /dev/null +++ b/packages/orm/src/schema.ts @@ -0,0 +1,2 @@ +export * from '@zenstackhq/schema'; +export type { OperandExpression } from 'kysely'; diff --git a/packages/orm/src/schema/auth.ts b/packages/orm/src/schema/auth.ts deleted file mode 100644 index 868025ff..00000000 --- a/packages/orm/src/schema/auth.ts +++ /dev/null @@ -1,9 +0,0 @@ -import type { GetModels, SchemaDef } from '.'; -import type { ModelResult } from '../client/crud-types'; - -export type AuthType = - string extends GetModels - ? Record - : Schema['authType'] extends GetModels - ? Partial> - : never; diff --git a/packages/orm/src/schema/index.ts b/packages/orm/src/schema/index.ts deleted file mode 100644 index 10a69276..00000000 --- a/packages/orm/src/schema/index.ts +++ /dev/null @@ -1,4 +0,0 @@ -export type * from '@zenstackhq/sdk/schema'; -export type { OperandExpression } from 'kysely'; -export * from './auth'; -export * from './expression'; diff --git a/packages/orm/tsup.config.ts b/packages/orm/tsup.config.ts index b5acbfc2..f4168f61 100644 --- a/packages/orm/tsup.config.ts +++ b/packages/orm/tsup.config.ts @@ -3,7 +3,7 @@ import { defineConfig } from 'tsup'; export default defineConfig({ entry: { index: 'src/index.ts', - schema: 'src/schema/index.ts', + schema: 'src/schema.ts', helpers: 'src/helpers.ts', }, outDir: 'dist', diff --git a/packages/plugins/policy/package.json b/packages/plugins/policy/package.json index 9bb54099..efc13147 100644 --- a/packages/plugins/policy/package.json +++ b/packages/plugins/policy/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/plugin-policy", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "ZenStack Policy Plugin", "type": "module", "scripts": { diff --git a/packages/schema/eslint.config.js b/packages/schema/eslint.config.js new file mode 100644 index 00000000..5698b991 --- /dev/null +++ b/packages/schema/eslint.config.js @@ -0,0 +1,4 @@ +import config from '@zenstackhq/eslint-config/base.js'; + +/** @type {import("eslint").Linter.Config} */ +export default config; diff --git a/packages/schema/package.json b/packages/schema/package.json new file mode 100644 index 00000000..ffa93013 --- /dev/null +++ b/packages/schema/package.json @@ -0,0 +1,37 @@ +{ + "name": "@zenstackhq/schema", + "version": "3.0.0-beta.15", + "description": "ZenStack Runtime Schema", + "type": "module", + "scripts": { + "build": "tsc --noEmit && tsup-node", + "watch": "tsup-node --watch", + "lint": "eslint src --ext ts", + "pack": "pnpm pack" + }, + "keywords": [], + "author": "ZenStack Team", + "license": "MIT", + "files": [ + "dist" + ], + "exports": { + ".": { + "import": { + "types": "./dist/index.d.ts", + "default": "./dist/index.js" + }, + "require": { + "types": "./dist/index.d.cts", + "default": "./dist/index.cjs" + } + } + }, + "dependencies": { + "decimal.js": "catalog:" + }, + "devDependencies": { + "@zenstackhq/eslint-config": "workspace:*", + "@zenstackhq/typescript-config": "workspace:*" + } +} diff --git a/packages/orm/src/schema/expression.ts b/packages/schema/src/expression-utils.ts similarity index 97% rename from packages/orm/src/schema/expression.ts rename to packages/schema/src/expression-utils.ts index 2e2337fa..ee48aecc 100644 --- a/packages/orm/src/schema/expression.ts +++ b/packages/schema/src/expression-utils.ts @@ -11,8 +11,11 @@ import type { ThisExpression, UnaryExpression, UnaryOperator, -} from '.'; +} from './expression'; +/** + * Utility functions to create and work with Expression objects + */ export const ExpressionUtils = { literal: (value: string | number | boolean): LiteralExpression => { return { diff --git a/packages/sdk/src/schema/expression.ts b/packages/schema/src/expression.ts similarity index 100% rename from packages/sdk/src/schema/expression.ts rename to packages/schema/src/expression.ts diff --git a/packages/sdk/src/schema/index.ts b/packages/schema/src/index.ts similarity index 56% rename from packages/sdk/src/schema/index.ts rename to packages/schema/src/index.ts index 6863d7ba..6a171e59 100644 --- a/packages/sdk/src/schema/index.ts +++ b/packages/schema/src/index.ts @@ -1,4 +1,3 @@ export type * from './expression'; +export * from './expression-utils'; export type * from './schema'; - -export type { OperandExpression } from 'kysely'; diff --git a/packages/sdk/src/schema/schema.ts b/packages/schema/src/schema.ts similarity index 100% rename from packages/sdk/src/schema/schema.ts rename to packages/schema/src/schema.ts diff --git a/packages/schema/tsconfig.json b/packages/schema/tsconfig.json new file mode 100644 index 00000000..25cac129 --- /dev/null +++ b/packages/schema/tsconfig.json @@ -0,0 +1,7 @@ +{ + "extends": "@zenstackhq/typescript-config/base.json", + "compilerOptions": { + "noUnusedLocals": false + }, + "include": ["src/**/*.ts"] +} diff --git a/packages/schema/tsup.config.ts b/packages/schema/tsup.config.ts new file mode 100644 index 00000000..5a74a9dd --- /dev/null +++ b/packages/schema/tsup.config.ts @@ -0,0 +1,13 @@ +import { defineConfig } from 'tsup'; + +export default defineConfig({ + entry: { + index: 'src/index.ts', + }, + outDir: 'dist', + splitting: false, + sourcemap: true, + clean: true, + dts: true, + format: ['cjs', 'esm'], +}); diff --git a/packages/sdk/package.json b/packages/sdk/package.json index 81fa52a5..90c24571 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/sdk", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "ZenStack SDK", "type": "module", "scripts": { @@ -25,16 +25,6 @@ "types": "./dist/index.d.cts", "default": "./dist/index.cjs" } - }, - "./schema": { - "import": { - "types": "./dist/schema.d.ts", - "default": "./dist/schema.js" - }, - "require": { - "types": "./dist/schema.d.cts", - "default": "./dist/schema.cjs" - } } }, "dependencies": { diff --git a/packages/sdk/tsup.config.ts b/packages/sdk/tsup.config.ts index 4c9aca3e..5a74a9dd 100644 --- a/packages/sdk/tsup.config.ts +++ b/packages/sdk/tsup.config.ts @@ -3,7 +3,6 @@ import { defineConfig } from 'tsup'; export default defineConfig({ entry: { index: 'src/index.ts', - schema: 'src/schema/index.ts', }, outDir: 'dist', splitting: false, diff --git a/packages/server/package.json b/packages/server/package.json index ad7697bc..81b708d2 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/server", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "ZenStack automatic CRUD API handlers and server adapters", "type": "module", "scripts": { diff --git a/packages/tanstack-query/package.json b/packages/tanstack-query/package.json index e13e8d95..d87affb3 100644 --- a/packages/tanstack-query/package.json +++ b/packages/tanstack-query/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/tanstack-query", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "", "main": "index.js", "type": "module", diff --git a/packages/testtools/package.json b/packages/testtools/package.json index 6ac50f14..02f1f6b5 100644 --- a/packages/testtools/package.json +++ b/packages/testtools/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/testtools", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "ZenStack Test Tools", "type": "module", "scripts": { @@ -33,6 +33,7 @@ "dependencies": { "@zenstackhq/common-helpers": "workspace:*", "@zenstackhq/language": "workspace:*", + "@zenstackhq/schema": "workspace:*", "@zenstackhq/orm": "workspace:*", "@zenstackhq/sdk": "workspace:*", "@zenstackhq/plugin-policy": "workspace:*", diff --git a/packages/testtools/src/schema.ts b/packages/testtools/src/schema.ts index b78bcbc8..3506d11f 100644 --- a/packages/testtools/src/schema.ts +++ b/packages/testtools/src/schema.ts @@ -1,6 +1,6 @@ import { invariant } from '@zenstackhq/common-helpers'; import { TsSchemaGenerator } from '@zenstackhq/sdk'; -import type { SchemaDef } from '@zenstackhq/sdk/schema'; +import type { SchemaDef } from '@zenstackhq/schema'; import { execSync } from 'node:child_process'; import crypto from 'node:crypto'; import fs from 'node:fs'; diff --git a/packages/zod/package.json b/packages/zod/package.json index 27ff8d8f..95036aab 100644 --- a/packages/zod/package.json +++ b/packages/zod/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/zod", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "", "type": "module", "main": "index.js", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 39dda3fe..1267adc4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -285,6 +285,9 @@ importers: '@zenstackhq/common-helpers': specifier: workspace:* version: link:../common-helpers + '@zenstackhq/schema': + specifier: workspace:* + version: link:../schema better-sqlite3: specifier: 'catalog:' version: 12.2.0 @@ -331,12 +334,6 @@ importers: '@zenstackhq/eslint-config': specifier: workspace:* version: link:../config/eslint-config - '@zenstackhq/language': - specifier: workspace:* - version: link:../language - '@zenstackhq/sdk': - specifier: workspace:* - version: link:../sdk '@zenstackhq/typescript-config': specifier: workspace:* version: link:../config/typescript-config @@ -381,6 +378,19 @@ importers: specifier: workspace:* version: link:../../config/vitest-config + packages/schema: + dependencies: + decimal.js: + specifier: 'catalog:' + version: 10.4.3 + devDependencies: + '@zenstackhq/eslint-config': + specifier: workspace:* + version: link:../config/eslint-config + '@zenstackhq/typescript-config': + specifier: workspace:* + version: link:../config/typescript-config + packages/sdk: dependencies: '@zenstackhq/common-helpers': @@ -527,6 +537,9 @@ importers: '@zenstackhq/plugin-policy': specifier: workspace:* version: link:../plugins/policy + '@zenstackhq/schema': + specifier: workspace:* + version: link:../schema '@zenstackhq/sdk': specifier: workspace:* version: link:../sdk @@ -638,6 +651,9 @@ importers: '@zenstackhq/plugin-policy': specifier: workspace:* version: link:../../packages/plugins/policy + '@zenstackhq/schema': + specifier: workspace:* + version: link:../../packages/schema '@zenstackhq/sdk': specifier: workspace:* version: link:../../packages/sdk diff --git a/samples/blog/package.json b/samples/blog/package.json index 1f37fe60..aac2a675 100644 --- a/samples/blog/package.json +++ b/samples/blog/package.json @@ -1,6 +1,6 @@ { "name": "sample-blog", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "description": "", "main": "index.js", "scripts": { diff --git a/tests/e2e/orm/schemas/basic/helper.ts b/tests/e2e/orm/schemas/basic/helper.ts index 6eac1589..7057ecc6 100644 --- a/tests/e2e/orm/schemas/basic/helper.ts +++ b/tests/e2e/orm/schemas/basic/helper.ts @@ -1,4 +1,4 @@ -import type { DataSourceProviderType } from '@zenstackhq/sdk/schema'; +import type { DataSourceProviderType } from '@zenstackhq/schema'; import { schema } from './schema'; export function getSchema(type: ProviderType) { diff --git a/tests/e2e/package.json b/tests/e2e/package.json index 58d5a38a..9c44a027 100644 --- a/tests/e2e/package.json +++ b/tests/e2e/package.json @@ -1,6 +1,6 @@ { "name": "e2e", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "private": true, "type": "module", "scripts": { @@ -15,6 +15,7 @@ "@paralleldrive/cuid2": "^2.2.2", "@zenstackhq/cli": "workspace:*", "@zenstackhq/language": "workspace:*", + "@zenstackhq/schema": "workspace:*", "@zenstackhq/orm": "workspace:*", "@zenstackhq/plugin-policy": "workspace:*", "@zenstackhq/sdk": "workspace:*", diff --git a/tests/regression/package.json b/tests/regression/package.json index 9be1dac1..e8d4fc5f 100644 --- a/tests/regression/package.json +++ b/tests/regression/package.json @@ -1,6 +1,6 @@ { "name": "regression", - "version": "3.0.0-beta.14", + "version": "3.0.0-beta.15", "private": true, "type": "module", "scripts": {