diff --git a/packages/orm/package.json b/packages/orm/package.json index 2fb72d7c..bb3a09f0 100644 --- a/packages/orm/package.json +++ b/packages/orm/package.json @@ -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/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..dc7312e6 --- /dev/null +++ b/packages/schema/package.json @@ -0,0 +1,37 @@ +{ + "name": "@zenstackhq/schema", + "version": "3.0.0-beta.14", + "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..73e48b52 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -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/testtools/package.json b/packages/testtools/package.json index 6ac50f14..4792116f 100644 --- a/packages/testtools/package.json +++ b/packages/testtools/package.json @@ -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/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/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..d660e9d9 100644 --- a/tests/e2e/package.json +++ b/tests/e2e/package.json @@ -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:*",