Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
10 changes: 2 additions & 8 deletions packages/cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,22 @@
"dependencies": {
"@zenstackhq/language": "workspace:*",
"@zenstackhq/sdk": "workspace:*",
"async-exit-hook": "^2.0.1",
"colors": "1.4.0",
"commander": "^8.3.0",
"langium": "catalog:",
"ora": "^5.4.1",
"package-manager-detector": "^1.3.0",
"tiny-invariant": "^1.3.3",
"ts-pattern": "catalog:"
},
"peerDependencies": {
"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"
}
}
4 changes: 2 additions & 2 deletions packages/cli/src/actions/generate.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { isPlugin, LiteralExpr, type Model } from '@zenstackhq/language/ast';
import type { CliGenerator } from '@zenstackhq/runtime/client';
import { PrismaSchemaGenerator, TsSchemaGenerator } from '@zenstackhq/sdk';
import { invariant } from '@zenstackhq/sdk/local-helpers';
import colors from 'colors';
import fs from 'node:fs';
import path from 'node:path';
import invariant from 'tiny-invariant';
import { getSchemaFile, loadSchemaDocument } from './action-utils';

type Options = {
Expand Down Expand Up @@ -41,7 +41,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
7 changes: 1 addition & 6 deletions packages/runtime/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,11 @@
"dependencies": {
"@paralleldrive/cuid2": "^2.2.2",
"decimal.js": "^10.4.3",
"is-plain-object": "^5.0.0",
"json-stable-stringify": "^1.3.0",
"kysely": "catalog:",
"nanoid": "^5.0.9",
"tiny-invariant": "^1.3.3",
"ts-pattern": "catalog:",
"ulid": "^3.0.0",
"utility-types": "^3.11.0",
"uuid": "^11.0.5"
},
"peerDependencies": {
Expand All @@ -92,13 +89,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
4 changes: 1 addition & 3 deletions packages/runtime/src/client/crud/dialects/base.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { invariant, isPlainObject } from '@zenstackhq/sdk/local-helpers';
import type { Expression, ExpressionBuilder, ExpressionWrapper, SqlBool, ValueNode } from 'kysely';
import { sql, type SelectQueryBuilder } from 'kysely';
import invariant from 'tiny-invariant';
import { match, P } from 'ts-pattern';
import type { BuiltinType, DataSourceProviderType, FieldDef, GetModels, SchemaDef } from '../../../schema';
import { enumerate } from '../../../utils/enumerate';
// @ts-expect-error
import { isPlainObject } from 'is-plain-object';
import type { OrArray } from '../../../utils/type-utils';
import type {
BooleanFilter,
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/client/crud/dialects/postgresql.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { invariant } from '@zenstackhq/sdk/local-helpers';
import {
sql,
type Expression,
Expand All @@ -6,7 +7,6 @@ import {
type RawBuilder,
type SelectQueryBuilder,
} from 'kysely';
import invariant from 'tiny-invariant';
import { match } from 'ts-pattern';
import type { BuiltinType, FieldDef, GetModels, SchemaDef } from '../../../schema';
import type { FindArgs } from '../../crud-types';
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/client/crud/dialects/sqlite.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { invariant } from '@zenstackhq/sdk/local-helpers';
import type Decimal from 'decimal.js';
import {
ExpressionWrapper,
Expand All @@ -7,7 +8,6 @@ import {
type RawBuilder,
type SelectQueryBuilder,
} from 'kysely';
import invariant from 'tiny-invariant';
import { match } from 'ts-pattern';
import type { BuiltinType, GetModels, SchemaDef } from '../../../schema';
import type { FindArgs } from '../../crud-types';
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/src/client/crud/operations/base.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { createId } from '@paralleldrive/cuid2';
import { invariant } from '@zenstackhq/sdk/local-helpers';
import {
DeleteResult,
expressionBuilder,
Expand All @@ -10,7 +11,6 @@ import {
type SelectQueryBuilder,
} from 'kysely';
import { nanoid } from 'nanoid';
import invariant from 'tiny-invariant';
import { match } from 'ts-pattern';
import { ulid } from 'ulid';
import * as uuid from 'uuid';
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
6 changes: 3 additions & 3 deletions packages/runtime/src/client/functions.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { invariant, capitalize, uncapitalize } from '@zenstackhq/sdk/local-helpers';
import { sql, ValueNode, type Expression, type ExpressionBuilder } from 'kysely';
import invariant from 'tiny-invariant';
import { match } from 'ts-pattern';
import type { ZModelFunction, ZModelFunctionContext } from './options';

Expand Down Expand Up @@ -132,8 +132,8 @@ 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', () => 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
2 changes: 1 addition & 1 deletion packages/runtime/src/client/helpers/schema-db-pusher.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { invariant } from '@zenstackhq/sdk/local-helpers';
import { CreateTableBuilder, sql, type ColumnDataType, type OnModifyForeignAction } from 'kysely';
import invariant from 'tiny-invariant';
import { match } from 'ts-pattern';
import {
ExpressionUtils,
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
2 changes: 1 addition & 1 deletion packages/runtime/src/client/result-processor.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { invariant } from '@zenstackhq/sdk/local-helpers';
import Decimal from 'decimal.js';
import invariant from 'tiny-invariant';
import { match } from 'ts-pattern';
import type { BuiltinType, FieldDef, GetModels, SchemaDef } from '../schema';
import { ensureArray, getField } from './query-utils';
Expand Down
Loading