Skip to content

chore: remove some libraries, move local-helpers from v2 #37

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
"license": "MIT",
"devDependencies": {
"@eslint/js": "^9.29.0",
"@swc/core": "^1.12.5",
"@types/node": "^20.17.24",
"eslint": "~9.29.0",
"npm-run-all": "^4.1.5",
"prettier": "^3.5.3",
"tsup": "^8.5.0",
"tsx": "^4.20.3",
Expand Down
9 changes: 2 additions & 7 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
"@zenstackhq/language": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
"@zenstackhq/common-helpers": "workspace:*",
"async-exit-hook": "^2.0.1",
"colors": "1.4.0",
"commander": "^8.3.0",
"langium": "catalog:",
Expand All @@ -43,15 +42,11 @@
"prisma": "catalog:"
},
"devDependencies": {
"@types/async-exit-hook": "^2.0.0",
"@types/better-sqlite3": "^7.6.13",
"@types/semver": "^7.3.13",
"@types/tmp": "^0.2.6",
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/runtime": "workspace:*",
"@zenstackhq/testtools": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/eslint-config": "workspace:*",
"better-sqlite3": "^11.8.1",
"tmp": "^0.2.3"
"better-sqlite3": "^11.8.1"
}
}
2 changes: 1 addition & 1 deletion packages/cli/src/actions/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { ZenStackClient } from '@zenstackhq/runtime';
import { schema } from '${outputPath}/schema';

const client = new ZenStackClient(schema, {
dialectConfig: { ... }
dialectConfig: { ... }
});
\`\`\`
`);
Expand Down
4 changes: 2 additions & 2 deletions packages/create-zenstack/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"ora": "^5.4.1"
},
"devDependencies": {
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/eslint-config": "workspace:*"
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*"
}
}
8 changes: 4 additions & 4 deletions packages/ide/vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
"license": "MIT",
"packageManager": "[email protected]",
"dependencies": {
"@zenstackhq/language": "workspace:*",
"langium": "catalog:",
"vscode-languageclient": "^9.0.1",
"vscode-languageserver": "^9.0.1",
"@zenstackhq/language": "workspace:*"
"vscode-languageserver": "^9.0.1"
},
"devDependencies": {
"@types/vscode": "^1.63.0",
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/eslint-config": "workspace:*"
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*"
},
"files": [
"dist",
Expand Down
4 changes: 2 additions & 2 deletions packages/language/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
},
"devDependencies": {
"@types/pluralize": "^0.0.33",
"langium-cli": "~3.3.0",
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/eslint-config": "workspace:*"
"langium-cli": "~3.3.0"
},
"volta": {
"node": "18.19.1",
Expand Down
22 changes: 11 additions & 11 deletions packages/language/res/stdlib.zmodel
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ enum ReferentialAction {
* Used with "onUpdate": when updating the identifier of a referenced object, the scalar fields of the referencing objects will be set to NULL.
*/
SetNull

/**
* Used with "onDelete": the scalar field of the referencing object will be set to the fields default value.
* Used with "onUpdate": the scalar field of the referencing object will be set to the fields default value.
Expand Down Expand Up @@ -104,7 +104,7 @@ function ulid(): String {
} @@@expressionContext([DefaultValue])

/**
* Creates a sequence of integers in the underlying database and assign the incremented
* Creates a sequence of integers in the underlying database and assign the incremented
* values to the ID values of the created records based on the sequence.
*/
function autoincrement(): Int {
Expand Down Expand Up @@ -174,9 +174,9 @@ function isEmpty(field: Any[]): Boolean {
/**
* The name of the model for which the policy rule is defined. If the rule is
* inherited to a sub model, this function returns the name of the sub model.
*
*
* @param optional parameter to control the casing of the returned value. Valid
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
* to "original".
*/
function currentModel(casing: String?): String {
Expand All @@ -186,7 +186,7 @@ function currentModel(casing: String?): String {
* The operation for which the policy rule is defined for. Note that a rule with
* "all" operation is expanded to "create", "read", "update", and "delete" rules,
* and the function returns corresponding value for each expanded version.
*
*
* @param optional parameter to control the casing of the returned value. Valid
* values are "original", "upper", "lower", "capitalize", "uncapitalize". Defaults
* to "original".
Expand Down Expand Up @@ -523,13 +523,13 @@ attribute @@schema(_ name: String) @@@prisma

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

/**
* Indicates that the field is encrypted when storing in the DB and should be decrypted when read
*
* ZenStack uses the Web Crypto API to encrypt and decrypt the field.
*
* ZenStack uses the Web Crypto API to encrypt and decrypt the field.
*/
attribute @encrypted() @@@targetField([StringField])

Expand Down Expand Up @@ -665,9 +665,9 @@ function url(field: String): Boolean {

/**
* Checks if the current user can perform the given operation on the given field.
*
*
* @param field: The field to check access for
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
* @param operation: The operation to check access for. Can be "read", "create", "update", or "delete". If the operation is not provided,
* it defaults the operation of the containing policy rule.
*/
function check(field: Any, operation: String?): Boolean {
Expand Down
1 change: 0 additions & 1 deletion packages/language/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,6 @@ export function getObjectLiteral<T>(expr: Expression | ConfigExpr | undefined):
}

export function getLiteralArray<

T extends string | number | boolean | any = any,
>(expr: Expression | ConfigExpr | undefined): T[] | undefined {
const arr = getArray(expr);
Expand Down
1 change: 0 additions & 1 deletion packages/language/src/validators/datamodel-validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,6 @@ export default class DataModelValidator implements AstValidator<DataModel> {
return;
}


const oppositeModel = field.type.reference!.ref! as DataModel;

// Use name because the current document might be updated
Expand Down
6 changes: 3 additions & 3 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Argument:
DataModel:
(comments+=TRIPLE_SLASH_COMMENT)*
(
((isAbstract?='abstract')? 'model' name=RegularID
((isAbstract?='abstract')? 'model' name=RegularID
('extends' superTypes+=[DataModel] (',' superTypes+=[DataModel])*)?) |
((isView?='view') name=RegularID)
)
Expand Down Expand Up @@ -193,7 +193,7 @@ TypeDef:
type TypeDefFieldTypes = TypeDef | Enum;

TypeDefField:
(comments+=TRIPLE_SLASH_COMMENT)*
(comments+=TRIPLE_SLASH_COMMENT)*
name=RegularIDWithTypeNames type=TypeDefFieldType (attributes+=DataModelFieldAttribute)*;

TypeDefFieldType:
Expand All @@ -208,7 +208,7 @@ Enum:
'enum' name=RegularID '{' (
fields+=EnumField
| attributes+=DataModelAttribute
)+
)+
'}';

EnumField:
Expand Down
5 changes: 1 addition & 4 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@
"nanoid": "^5.0.9",
"ts-pattern": "catalog:",
"ulid": "^3.0.0",
"utility-types": "^3.11.0",
"uuid": "^11.0.5"
},
"peerDependencies": {
Expand All @@ -92,13 +91,11 @@
"devDependencies": {
"@types/better-sqlite3": "^7.0.0",
"@types/pg": "^8.0.0",
"@types/tmp": "^0.2.6",
"@zenstackhq/eslint-config": "workspace:*",
"@zenstackhq/language": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
"@zenstackhq/testtools": "workspace:*",
"@zenstackhq/typescript-config": "workspace:*",
"@zenstackhq/eslint-config": "workspace:*",
"tmp": "^0.2.3",
"tsx": "^4.19.2"
}
}
2 changes: 1 addition & 1 deletion packages/runtime/src/client/crud-types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type { ExpressionBuilder, OperandExpression, SqlBool } from 'kysely';
import type { Optional } from 'utility-types';
import type {
BuiltinType,
FieldDef,
Expand Down Expand Up @@ -29,6 +28,7 @@ import type {
MapBaseType,
NonEmptyArray,
NullableIf,
Optional,
OrArray,
ValueOfPotentialTuple,
WrapType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import {
} from 'kysely';
import { nanoid } from 'nanoid';
import { match } from 'ts-pattern';
import type { PromiseType } from 'utility-types';
import type { GetModels, SchemaDef } from '../../schema';
import type { ClientImpl } from '../client-impl';
import type { ClientContract } from '../contract';
Expand Down Expand Up @@ -58,7 +57,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer

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

private callBeforeMutationHooks(
queryNode: OperationNode,
mutationInterceptionInfo: PromiseType<ReturnType<typeof this.callMutationInterceptionFilters>>,
mutationInterceptionInfo: Awaited<ReturnType<typeof this.callMutationInterceptionFilters>>,
) {
if (!mutationInterceptionInfo?.intercept) {
return;
Expand All @@ -315,7 +314,7 @@ export class ZenStackQueryExecutor<Schema extends SchemaDef> extends DefaultQuer
private async callAfterQueryInterceptionFilters(
queryResult: QueryResult<unknown>,
queryNode: OperationNode,
mutationInterceptionInfo: PromiseType<ReturnType<typeof this.callMutationInterceptionFilters>>,
mutationInterceptionInfo: Awaited<ReturnType<typeof this.callMutationInterceptionFilters>>,
) {
if (!mutationInterceptionInfo?.intercept) {
return;
Expand Down
8 changes: 5 additions & 3 deletions packages/runtime/src/client/functions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { invariant } from '@zenstackhq/common-helpers';
import { invariant, capitalize, uncapitalize } from '@zenstackhq/common-helpers';
import { sql, ValueNode, type Expression, type ExpressionBuilder } from 'kysely';
import { match } from 'ts-pattern';
import type { ZModelFunction, ZModelFunctionContext } from './options';
Expand Down Expand Up @@ -132,8 +132,10 @@ function processCasing(casing: Expression<any>, result: string, model: string) {
.with('original', () => model)
.with('upper', () => result.toUpperCase())
.with('lower', () => result.toLowerCase())
.with('capitalize', () => `${result.charAt(0).toUpperCase() + result.slice(1)}`)
.with('uncapitalize', () => `${result.charAt(0).toLowerCase() + result.slice(1)}`)
.with('

', () => capitalize(result))
.with('uncapitalize', () => uncapitalize(result))
.otherwise(() => {
throw new Error(
`Invalid casing value: ${opNode.value}. Must be "original", "upper", "lower", "capitalize", or "uncapitalize".`,
Expand Down
3 changes: 1 addition & 2 deletions packages/runtime/src/client/options.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import type { Expression, ExpressionBuilder, KyselyConfig, PostgresDialectConfig, SqliteDialectConfig } from 'kysely';
import type { Optional } from 'utility-types';
import type { DataSourceProvider, GetModel, GetModels, ProcedureDef, SchemaDef } from '../schema';
import type { PrependParameter } from '../utils/type-utils';
import type { Optional, PrependParameter } from '../utils/type-utils';
import type { ClientContract, CRUD, ProcedureFunc } from './contract';
import type { BaseCrudDialect } from './crud/dialects/base';
import type { RuntimePlugin } from './plugin';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
ValueNode,
WhereNode,
type ExpressionBuilder,
type OperandExpression,
type OperationNode,
} from 'kysely';
import { match } from 'ts-pattern';
Expand Down
8 changes: 4 additions & 4 deletions packages/runtime/src/plugins/policy/plugin.zmodel
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
/**
* Defines an access policy that allows a set of operations when the given condition is true.
*
*
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
* @param condition: a boolean expression that controls if the operation should be allowed.
*/
attribute @@allow(_ operation: String @@@completionHint(["'create'", "'read'", "'update'", "'delete'", "'all'"]), _ condition: Boolean)

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

/**
* Defines an access policy that denies a set of operations when the given condition is true.
*
*
* @param operation: comma-separated list of "create", "read", "update", "delete". Use "all" to denote all operations.
* @param condition: a boolean expression that controls if the operation should be denied.
*/
Expand Down
2 changes: 2 additions & 0 deletions packages/runtime/src/utils/type-utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import type Decimal from 'decimal.js';

export type Optional<T extends object, K extends keyof T = keyof T> = Omit<T, K> & Partial<Pick<T, K>>;

export type NullableIf<T, Condition extends boolean> = Condition extends true ? T | null : T;

export type PartialRecord<K extends string | number | symbol, T> = Partial<Record<K, T>>;
Expand Down
4 changes: 2 additions & 2 deletions packages/runtime/test/client-api/type-coverage.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ describe('zmodel type coverage tests', () => {
`
model Foo {
id String @id @default(cuid())

String String
Int Int
BigInt BigInt
Expand All @@ -17,7 +17,7 @@ describe('zmodel type coverage tests', () => {
Decimal Decimal
Boolean Boolean
Bytes Bytes

@@allow('all', true)
}
`,
Expand Down
Loading
Loading