Skip to content

Commit 7bb9639

Browse files
DoctorFTBymc9
andauthored
chore: remove some libraries, move local-helpers from v2 (#37)
* chore: remove unused spaces * chore(sdk): move libraries from v2 * chore: remove some libraries, use local-helpers from sdk --------- Co-authored-by: Yiming Cao <[email protected]>
1 parent df9f318 commit 7bb9639

38 files changed

+157
-102
lines changed

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,8 @@
1818
"license": "MIT",
1919
"devDependencies": {
2020
"@eslint/js": "^9.29.0",
21-
"@swc/core": "^1.12.5",
2221
"@types/node": "^20.17.24",
2322
"eslint": "~9.29.0",
24-
"npm-run-all": "^4.1.5",
2523
"prettier": "^3.5.3",
2624
"tsup": "^8.5.0",
2725
"tsx": "^4.20.3",

packages/cli/package.json

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
"@zenstackhq/language": "workspace:*",
3232
"@zenstackhq/sdk": "workspace:*",
3333
"@zenstackhq/common-helpers": "workspace:*",
34-
"async-exit-hook": "^2.0.1",
3534
"colors": "1.4.0",
3635
"commander": "^8.3.0",
3736
"langium": "catalog:",
@@ -43,15 +42,11 @@
4342
"prisma": "catalog:"
4443
},
4544
"devDependencies": {
46-
"@types/async-exit-hook": "^2.0.0",
4745
"@types/better-sqlite3": "^7.6.13",
48-
"@types/semver": "^7.3.13",
49-
"@types/tmp": "^0.2.6",
46+
"@zenstackhq/eslint-config": "workspace:*",
5047
"@zenstackhq/runtime": "workspace:*",
5148
"@zenstackhq/testtools": "workspace:*",
5249
"@zenstackhq/typescript-config": "workspace:*",
53-
"@zenstackhq/eslint-config": "workspace:*",
54-
"better-sqlite3": "^11.8.1",
55-
"tmp": "^0.2.3"
50+
"better-sqlite3": "^11.8.1"
5651
}
5752
}

packages/cli/src/actions/generate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import { ZenStackClient } from '@zenstackhq/runtime';
4040
import { schema } from '${outputPath}/schema';
4141
4242
const client = new ZenStackClient(schema, {
43-
dialectConfig: { ... }
43+
dialectConfig: { ... }
4444
});
4545
\`\`\`
4646
`);

packages/create-zenstack/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"ora": "^5.4.1"
3636
},
3737
"devDependencies": {
38-
"@zenstackhq/typescript-config": "workspace:*",
39-
"@zenstackhq/eslint-config": "workspace:*"
38+
"@zenstackhq/eslint-config": "workspace:*",
39+
"@zenstackhq/typescript-config": "workspace:*"
4040
}
4141
}

packages/ide/vscode/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@
3030
"license": "MIT",
3131
"packageManager": "[email protected]",
3232
"dependencies": {
33+
"@zenstackhq/language": "workspace:*",
3334
"langium": "catalog:",
3435
"vscode-languageclient": "^9.0.1",
35-
"vscode-languageserver": "^9.0.1",
36-
"@zenstackhq/language": "workspace:*"
36+
"vscode-languageserver": "^9.0.1"
3737
},
3838
"devDependencies": {
3939
"@types/vscode": "^1.63.0",
40-
"@zenstackhq/typescript-config": "workspace:*",
41-
"@zenstackhq/eslint-config": "workspace:*"
40+
"@zenstackhq/eslint-config": "workspace:*",
41+
"@zenstackhq/typescript-config": "workspace:*"
4242
},
4343
"files": [
4444
"dist",

packages/language/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
},
5050
"devDependencies": {
5151
"@types/pluralize": "^0.0.33",
52-
"langium-cli": "~3.3.0",
52+
"@zenstackhq/eslint-config": "workspace:*",
5353
"@zenstackhq/typescript-config": "workspace:*",
54-
"@zenstackhq/eslint-config": "workspace:*"
54+
"langium-cli": "~3.3.0"
5555
},
5656
"volta": {
5757
"node": "18.19.1",

packages/language/res/stdlib.zmodel

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ enum ReferentialAction {
2525
* Used with "onUpdate": when updating the identifier of a referenced object, the scalar fields of the referencing objects will be set to NULL.
2626
*/
2727
SetNull
28-
28+
2929
/**
3030
* Used with "onDelete": the scalar field of the referencing object will be set to the fields default value.
3131
* Used with "onUpdate": the scalar field of the referencing object will be set to the fields default value.
@@ -104,7 +104,7 @@ function ulid(): String {
104104
} @@@expressionContext([DefaultValue])
105105

106106
/**
107-
* Creates a sequence of integers in the underlying database and assign the incremented
107+
* Creates a sequence of integers in the underlying database and assign the incremented
108108
* values to the ID values of the created records based on the sequence.
109109
*/
110110
function autoincrement(): Int {
@@ -174,9 +174,9 @@ function isEmpty(field: Any[]): Boolean {
174174
/**
175175
* The name of the model for which the policy rule is defined. If the rule is
176176
* inherited to a sub model, this function returns the name of the sub model.
177-
*
177+
*
178178
* @param optional parameter to control the casing of the returned value. Valid
179-
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
179+
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
180180
* to "original".
181181
*/
182182
function currentModel(casing: String?): String {
@@ -186,7 +186,7 @@ function currentModel(casing: String?): String {
186186
* The operation for which the policy rule is defined for. Note that a rule with
187187
* "all" operation is expanded to "create", "read", "update", and "delete" rules,
188188
* and the function returns corresponding value for each expanded version.
189-
*
189+
*
190190
* @param optional parameter to control the casing of the returned value. Valid
191191
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
192192
* to "original".
@@ -523,13 +523,13 @@ attribute @@schema(_ name: String) @@@prisma
523523

524524
/**
525525
* Indicates that the field is a password field and needs to be hashed before persistence.
526-
*
526+
*
527527
* ZenStack uses `bcryptjs` library to hash password. You can use the `saltLength` parameter
528528
* to configure the cost of hashing, or use `salt` parameter to provide an explicit salt.
529529
* By default, salt length of 12 is used.
530530
*
531531
* @see https://www.npmjs.com/package/bcryptjs for details
532-
*
532+
*
533533
* @param saltLength: length of salt to use (cost factor for the hash function)
534534
* @param salt: salt to use (a pregenerated valid salt)
535535
*/
@@ -538,8 +538,8 @@ attribute @password(saltLength: Int?, salt: String?) @@@targetField([StringField
538538

539539
/**
540540
* Indicates that the field is encrypted when storing in the DB and should be decrypted when read
541-
*
542-
* ZenStack uses the Web Crypto API to encrypt and decrypt the field.
541+
*
542+
* ZenStack uses the Web Crypto API to encrypt and decrypt the field.
543543
*/
544544
attribute @encrypted() @@@targetField([StringField])
545545

@@ -665,9 +665,9 @@ function url(field: String): Boolean {
665665

666666
/**
667667
* Checks if the current user can perform the given operation on the given field.
668-
*
668+
*
669669
* @param field: The field to check access for
670-
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
670+
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
671671
* it defaults the operation of the containing policy rule.
672672
*/
673673
function check(field: Any, operation: String?): Boolean {

packages/language/src/utils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,6 @@ export function getObjectLiteral<T>(expr: Expression | ConfigExpr | undefined):
332332
}
333333

334334
export function getLiteralArray<
335-
336335
T extends string | number | boolean | any = any,
337336
>(expr: Expression | ConfigExpr | undefined): T[] | undefined {
338337
const arr = getArray(expr);

packages/language/src/validators/datamodel-validator.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,6 @@ export default class DataModelValidator implements AstValidator<DataModel> {
259259
return;
260260
}
261261

262-
263262
const oppositeModel = field.type.reference!.ref! as DataModel;
264263

265264
// Use name because the current document might be updated

packages/language/src/zmodel.langium

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ Argument:
164164
DataModel:
165165
(comments+=TRIPLE_SLASH_COMMENT)*
166166
(
167-
((isAbstract?='abstract')? 'model' name=RegularID
167+
((isAbstract?='abstract')? 'model' name=RegularID
168168
('extends' superTypes+=[DataModel] (',' superTypes+=[DataModel])*)?) |
169169
((isView?='view') name=RegularID)
170170
)
@@ -193,7 +193,7 @@ TypeDef:
193193
type TypeDefFieldTypes = TypeDef | Enum;
194194

195195
TypeDefField:
196-
(comments+=TRIPLE_SLASH_COMMENT)*
196+
(comments+=TRIPLE_SLASH_COMMENT)*
197197
name=RegularIDWithTypeNames type=TypeDefFieldType (attributes+=DataModelFieldAttribute)*;
198198

199199
TypeDefFieldType:
@@ -208,7 +208,7 @@ Enum:
208208
'enum' name=RegularID '{' (
209209
fields+=EnumField
210210
| attributes+=DataModelAttribute
211-
)+
211+
)+
212212
'}';
213213

214214
EnumField:

packages/runtime/package.json

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@
7373
"nanoid": "^5.0.9",
7474
"ts-pattern": "catalog:",
7575
"ulid": "^3.0.0",
76-
"utility-types": "^3.11.0",
7776
"uuid": "^11.0.5"
7877
},
7978
"peerDependencies": {
@@ -92,13 +91,11 @@
9291
"devDependencies": {
9392
"@types/better-sqlite3": "^7.0.0",
9493
"@types/pg": "^8.0.0",
95-
"@types/tmp": "^0.2.6",
94+
"@zenstackhq/eslint-config": "workspace:*",
9695
"@zenstackhq/language": "workspace:*",
9796
"@zenstackhq/sdk": "workspace:*",
9897
"@zenstackhq/testtools": "workspace:*",
9998
"@zenstackhq/typescript-config": "workspace:*",
100-
"@zenstackhq/eslint-config": "workspace:*",
101-
"tmp": "^0.2.3",
10299
"tsx": "^4.19.2"
103100
}
104101
}

packages/runtime/src/client/crud-types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type { ExpressionBuilder, OperandExpression, SqlBool } from 'kysely';
2-
import type { Optional } from 'utility-types';
32
import type {
43
BuiltinType,
54
FieldDef,
@@ -29,6 +28,7 @@ import type {
2928
MapBaseType,
3029
NonEmptyArray,
3130
NullableIf,
31+
Optional,
3232
OrArray,
3333
ValueOfPotentialTuple,
3434
WrapType,

packages/runtime/src/client/executor/zenstack-query-executor.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
} from 'kysely';
2323
import { nanoid } from 'nanoid';
2424
import { match } from 'ts-pattern';
25-
import type { PromiseType } from 'utility-types';
2625
import type { GetModels, SchemaDef } from '../../schema';
2726
import type { ClientImpl } from '../client-impl';
2827
import type { ClientContract } from '../contract';
@@ -58,7 +57,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
5857

5958
override async executeQuery(compiledQuery: CompiledQuery, queryId: QueryId) {
6059
let queryNode = compiledQuery.query;
61-
let mutationInterceptionInfo: PromiseType<ReturnType<typeof this.callMutationInterceptionFilters>>;
60+
let mutationInterceptionInfo: Awaited<ReturnType<typeof this.callMutationInterceptionFilters>>;
6261
if (this.isMutationNode(queryNode) && this.hasMutationHooks) {
6362
mutationInterceptionInfo = await this.callMutationInterceptionFilters(queryNode);
6463
}
@@ -291,7 +290,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
291290

292291
private callBeforeMutationHooks(
293292
queryNode: OperationNode,
294-
mutationInterceptionInfo: PromiseType<ReturnType<typeof this.callMutationInterceptionFilters>>,
293+
mutationInterceptionInfo: Awaited<ReturnType<typeof this.callMutationInterceptionFilters>>,
295294
) {
296295
if (!mutationInterceptionInfo?.intercept) {
297296
return;
@@ -315,7 +314,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
315314
private async callAfterQueryInterceptionFilters(
316315
queryResult: QueryResult<unknown>,
317316
queryNode: OperationNode,
318-
mutationInterceptionInfo: PromiseType<ReturnType<typeof this.callMutationInterceptionFilters>>,
317+
mutationInterceptionInfo: Awaited<ReturnType<typeof this.callMutationInterceptionFilters>>,
319318
) {
320319
if (!mutationInterceptionInfo?.intercept) {
321320
return;

packages/runtime/src/client/functions.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { invariant } from '@zenstackhq/common-helpers';
1+
import { invariant, capitalize, uncapitalize } from '@zenstackhq/common-helpers';
22
import { sql, ValueNode, type Expression, type ExpressionBuilder } from 'kysely';
33
import { match } from 'ts-pattern';
44
import type { ZModelFunction, ZModelFunctionContext } from './options';
@@ -132,8 +132,10 @@ function processCasing(casing: Expression<any>, result: string, model: string) {
132132
.with('original', () => model)
133133
.with('upper', () => result.toUpperCase())
134134
.with('lower', () => result.toLowerCase())
135-
.with('capitalize', () => `${result.charAt(0).toUpperCase() + result.slice(1)}`)
136-
.with('uncapitalize', () => `${result.charAt(0).toLowerCase() + result.slice(1)}`)
135+
.with('
136+
137+
', () => capitalize(result))
138+
.with('uncapitalize', () => uncapitalize(result))
137139
.otherwise(() => {
138140
throw new Error(
139141
`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`,

packages/runtime/src/client/options.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { Expression, ExpressionBuilder, KyselyConfig, PostgresDialectConfig, SqliteDialectConfig } from 'kysely';
2-
import type { Optional } from 'utility-types';
32
import type { DataSourceProvider, GetModel, GetModels, ProcedureDef, SchemaDef } from '../schema';
4-
import type { PrependParameter } from '../utils/type-utils';
3+
import type { Optional, PrependParameter } from '../utils/type-utils';
54
import type { ClientContract, CRUD, ProcedureFunc } from './contract';
65
import type { BaseCrudDialect } from './crud/dialects/base';
76
import type { RuntimePlugin } from './plugin';

packages/runtime/src/plugins/policy/expression-transformer.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
ValueNode,
1818
WhereNode,
1919
type ExpressionBuilder,
20+
type OperandExpression,
2021
type OperationNode,
2122
} from 'kysely';
2223
import { match } from 'ts-pattern';

packages/runtime/src/plugins/policy/plugin.zmodel

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/**
22
* Defines an access policy that allows a set of operations when the given condition is true.
3-
*
3+
*
44
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
55
* @param condition: a boolean expression that controls if the operation should be allowed.
66
*/
77
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)
88

99
/**
1010
* Defines an access policy that allows the annotated field to be read or updated.
11-
* You can pass a third argument as `true` to make it override the model-level policies.
12-
*
11+
* You can pass a third argument as `true` to make it override the model-level policies.
12+
*
1313
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
1414
* @param condition: a boolean expression that controls if the operation should be allowed.
1515
* @param override: a boolean value that controls if the field-level policy should override the model-level policy.
@@ -18,7 +18,7 @@ attribute @allow(_ operation: String @@@completionHint(["'create'", "'read'", "'
1818

1919
/**
2020
* Defines an access policy that denies a set of operations when the given condition is true.
21-
*
21+
*
2222
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
2323
* @param condition: a boolean expression that controls if the operation should be denied.
2424
*/

packages/runtime/src/utils/type-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import type Decimal from 'decimal.js';
22

3+
export type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;
4+
35
export type NullableIf<T, Condition extends boolean> = Condition extends true ? T | null : T;
46

57
export type PartialRecord<K extends string | number | symbol, T> = Partial<Record<K, T>>;

packages/runtime/test/client-api/type-coverage.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ describe('zmodel type coverage tests', () => {
88
`
99
model Foo {
1010
id String @id @default(cuid())
11-
11+
1212
String String
1313
Int Int
1414
BigInt BigInt
@@ -17,7 +17,7 @@ describe('zmodel type coverage tests', () => {
1717
Decimal Decimal
1818
Boolean Boolean
1919
Bytes Bytes
20-
20+
2121
@@allow('all', true)
2222
}
2323
`,

0 commit comments

Comments
 (0)