Skip to content

Commit f2d7190

Browse files
authored
refactor: extract a runtime schema package (#350)
1 parent 7826da3 commit f2d7190

File tree

23 files changed

+115
-42
lines changed

23 files changed

+115
-42
lines changed

packages/orm/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
},
6464
"dependencies": {
6565
"@paralleldrive/cuid2": "^2.2.2",
66+
"@zenstackhq/schema": "workspace:*",
6667
"@zenstackhq/common-helpers": "workspace:*",
6768
"decimal.js": "catalog:",
6869
"json-stable-stringify": "^1.3.0",
@@ -92,8 +93,6 @@
9293
"@types/pg": "^8.0.0",
9394
"@types/toposort": "^2.0.7",
9495
"@zenstackhq/eslint-config": "workspace:*",
95-
"@zenstackhq/language": "workspace:*",
96-
"@zenstackhq/sdk": "workspace:*",
9796
"@zenstackhq/typescript-config": "workspace:*",
9897
"@zenstackhq/vitest-config": "workspace:*",
9998
"tsx": "^4.19.2",

packages/orm/src/client/client-impl.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@ import {
1111
type KyselyProps,
1212
} from 'kysely';
1313
import type { GetModels, ProcedureDef, SchemaDef } from '../schema';
14-
import type { AuthType } from '../schema/auth';
1514
import type { UnwrapTuplePromises } from '../utils/type-utils';
16-
import type { ClientConstructor, ClientContract, ModelOperations, TransactionIsolationLevel } from './contract';
15+
import type {
16+
AuthType,
17+
ClientConstructor,
18+
ClientContract,
19+
ModelOperations,
20+
TransactionIsolationLevel,
21+
} from './contract';
1722
import { AggregateOperationHandler } from './crud/operations/aggregate';
1823
import type { AllCrudOperation, CoreCrudOperation } from './crud/operations/base';
1924
import { BaseOperationHandler } from './crud/operations/base';

packages/orm/src/client/contract.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type Decimal from 'decimal.js';
22
import { type GetModels, type IsDelegateModel, type ProcedureDef, type SchemaDef } from '../schema';
3-
import type { AuthType } from '../schema/auth';
43
import type { OrUndefinedIf, Simplify, UnwrapTuplePromises } from '../utils/type-utils';
54
import type { TRANSACTION_UNSUPPORTED_METHODS } from './constants';
65
import type {
@@ -803,3 +802,14 @@ export type ModelOperations<Schema extends SchemaDef, Model extends GetModels<Sc
803802
>;
804803

805804
//#endregion
805+
806+
//#region Supporting types
807+
808+
export type AuthType<Schema extends SchemaDef> =
809+
string extends GetModels<Schema>
810+
? Record<string, unknown>
811+
: Schema['authType'] extends GetModels<Schema>
812+
? Partial<ModelResult<Schema, Schema['authType']>>
813+
: never;
814+
815+
//#endregion

packages/orm/src/client/crud/validator/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
FieldExpression,
88
MemberExpression,
99
UnaryExpression,
10-
} from '@zenstackhq/sdk/schema';
10+
} from '@zenstackhq/schema';
1111
import Decimal from 'decimal.js';
1212
import { match, P } from 'ts-pattern';
1313
import { z } from 'zod';

packages/orm/src/schema.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from '@zenstackhq/schema';
2+
export type { OperandExpression } from 'kysely';

packages/orm/src/schema/auth.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

packages/orm/src/schema/index.ts

Lines changed: 0 additions & 4 deletions
This file was deleted.

packages/orm/tsup.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { defineConfig } from 'tsup';
33
export default defineConfig({
44
entry: {
55
index: 'src/index.ts',
6-
schema: 'src/schema/index.ts',
6+
schema: 'src/schema.ts',
77
helpers: 'src/helpers.ts',
88
},
99
outDir: 'dist',

packages/schema/eslint.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import config from '@zenstackhq/eslint-config/base.js';
2+
3+
/** @type {import("eslint").Linter.Config} */
4+
export default config;

packages/schema/package.json

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
{
2+
"name": "@zenstackhq/schema",
3+
"version": "3.0.0-beta.14",
4+
"description": "ZenStack Runtime Schema",
5+
"type": "module",
6+
"scripts": {
7+
"build": "tsc --noEmit && tsup-node",
8+
"watch": "tsup-node --watch",
9+
"lint": "eslint src --ext ts",
10+
"pack": "pnpm pack"
11+
},
12+
"keywords": [],
13+
"author": "ZenStack Team",
14+
"license": "MIT",
15+
"files": [
16+
"dist"
17+
],
18+
"exports": {
19+
".": {
20+
"import": {
21+
"types": "./dist/index.d.ts",
22+
"default": "./dist/index.js"
23+
},
24+
"require": {
25+
"types": "./dist/index.d.cts",
26+
"default": "./dist/index.cjs"
27+
}
28+
}
29+
},
30+
"dependencies": {
31+
"decimal.js": "catalog:"
32+
},
33+
"devDependencies": {
34+
"@zenstackhq/eslint-config": "workspace:*",
35+
"@zenstackhq/typescript-config": "workspace:*"
36+
}
37+
}

0 commit comments

Comments
 (0)