From e9bab22f76000e814609b397caccb6dae885cb39 Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Mon, 12 Feb 2024 17:28:24 +0800 Subject: [PATCH 1/2] fix: supports for complex usage of "@@index" in zmodel --- package.json | 2 +- packages/ide/jetbrains/package.json | 2 +- packages/language/package.json | 2 +- packages/language/src/generated/ast.ts | 35 ++++--- packages/language/src/generated/grammar.ts | 72 ++++---------- packages/language/src/zmodel.langium | 6 +- packages/language/syntaxes/zmodel.tmLanguage | 2 +- .../language/syntaxes/zmodel.tmLanguage.json | 2 +- packages/misc/redwood/package.json | 2 +- packages/plugins/openapi/package.json | 2 +- packages/plugins/swr/package.json | 2 +- packages/plugins/tanstack-query/package.json | 2 +- packages/plugins/trpc/package.json | 2 +- packages/runtime/package.json | 2 +- packages/schema/package.json | 2 +- .../function-invocation-validator.ts | 1 + .../src/plugins/prisma/prisma-builder.ts | 6 +- .../src/plugins/prisma/schema-generator.ts | 8 +- packages/schema/src/res/stdlib.zmodel | 97 ++++++++++++++++++- packages/sdk/package.json | 2 +- packages/sdk/src/constants.ts | 1 + packages/sdk/src/zmodel-code-generator.ts | 6 +- packages/server/package.json | 2 +- packages/testtools/package.json | 2 +- 24 files changed, 161 insertions(+), 101 deletions(-) diff --git a/package.json b/package.json index 3c08bc9c3..2d2d2e264 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "zenstack-monorepo", - "version": "1.9.1", + "version": "1.9.0", "description": "", "scripts": { "build": "pnpm -r build", diff --git a/packages/ide/jetbrains/package.json b/packages/ide/jetbrains/package.json index b08392ade..7305853c2 100644 --- a/packages/ide/jetbrains/package.json +++ b/packages/ide/jetbrains/package.json @@ -1,6 +1,6 @@ { "name": "jetbrains", - "version": "1.9.1", + "version": "1.9.0", "displayName": "ZenStack JetBrains IDE Plugin", "description": "ZenStack JetBrains IDE plugin", "homepage": "https://zenstack.dev", diff --git a/packages/language/package.json b/packages/language/package.json index 1d06a04c7..d4260e6e6 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/language", - "version": "1.9.1", + "version": "1.9.0", "displayName": "ZenStack modeling language compiler", "description": "ZenStack modeling language compiler", "homepage": "https://zenstack.dev", diff --git a/packages/language/src/generated/ast.ts b/packages/language/src/generated/ast.ts index 7463fb9da..44e21b149 100644 --- a/packages/language/src/generated/ast.ts +++ b/packages/language/src/generated/ast.ts @@ -64,10 +64,10 @@ export function isReferenceTarget(item: unknown): item is ReferenceTarget { return reflection.isInstance(item, ReferenceTarget); } -export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'sort' | 'view' | string; +export type RegularID = 'abstract' | 'attribute' | 'datasource' | 'enum' | 'import' | 'in' | 'model' | 'plugin' | 'view' | string; export function isRegularID(item: unknown): item is RegularID { - return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'sort' || item === 'view' || item === 'import' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item))); + return item === 'model' || item === 'enum' || item === 'attribute' || item === 'datasource' || item === 'plugin' || item === 'abstract' || item === 'in' || item === 'view' || item === 'import' || (typeof item === 'string' && (/[_a-zA-Z][\w_]*/.test(item))); } export type TypeDeclaration = DataModel | Enum; @@ -81,7 +81,6 @@ export function isTypeDeclaration(item: unknown): item is TypeDeclaration { export interface Argument extends AstNode { readonly $container: InvocationExpr; readonly $type: 'Argument'; - name?: RegularID value: Expression } @@ -92,7 +91,7 @@ export function isArgument(item: unknown): item is Argument { } export interface ArrayExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'ArrayExpr'; items: Array } @@ -163,7 +162,7 @@ export function isAttributeParamType(item: unknown): item is AttributeParamType } export interface BinaryExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'BinaryExpr'; left: Expression operator: '!' | '!=' | '&&' | '<' | '<=' | '==' | '>' | '>=' | '?' | '^' | 'in' | '||' @@ -177,7 +176,7 @@ export function isBinaryExpr(item: unknown): item is BinaryExpr { } export interface BooleanLiteral extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'BooleanLiteral'; value: Boolean } @@ -189,7 +188,7 @@ export function isBooleanLiteral(item: unknown): item is BooleanLiteral { } export interface ConfigArrayExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'ConfigArrayExpr'; items: Array } @@ -440,7 +439,7 @@ export function isInternalAttribute(item: unknown): item is InternalAttribute { } export interface InvocationExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'InvocationExpr'; args: Array function: Reference @@ -453,7 +452,7 @@ export function isInvocationExpr(item: unknown): item is InvocationExpr { } export interface MemberAccessExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'MemberAccessExpr'; member: Reference operand: Expression @@ -490,7 +489,7 @@ export function isModelImport(item: unknown): item is ModelImport { } export interface NullExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'NullExpr'; value: 'null' } @@ -502,7 +501,7 @@ export function isNullExpr(item: unknown): item is NullExpr { } export interface NumberLiteral extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'NumberLiteral'; value: string } @@ -514,7 +513,7 @@ export function isNumberLiteral(item: unknown): item is NumberLiteral { } export interface ObjectExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'ObjectExpr'; fields: Array } @@ -554,8 +553,8 @@ export function isPluginField(item: unknown): item is PluginField { export interface ReferenceArg extends AstNode { readonly $container: ReferenceExpr; readonly $type: 'ReferenceArg'; - name: 'sort' - value: 'Asc' | 'Desc' + name: string + value: Expression } export const ReferenceArg = 'ReferenceArg'; @@ -565,7 +564,7 @@ export function isReferenceArg(item: unknown): item is ReferenceArg { } export interface ReferenceExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'ReferenceExpr'; args: Array target: Reference @@ -578,7 +577,7 @@ export function isReferenceExpr(item: unknown): item is ReferenceExpr { } export interface StringLiteral extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'StringLiteral'; value: string } @@ -590,7 +589,7 @@ export function isStringLiteral(item: unknown): item is StringLiteral { } export interface ThisExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'ThisExpr'; value: 'this' } @@ -602,7 +601,7 @@ export function isThisExpr(item: unknown): item is ThisExpr { } export interface UnaryExpr extends AstNode { - readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | UnaryExpr | UnsupportedFieldType; + readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType; readonly $type: 'UnaryExpr'; operand: Expression operator: '!' diff --git a/packages/language/src/generated/grammar.ts b/packages/language/src/generated/grammar.ts index 5dbe02014..2a5d532d3 100644 --- a/packages/language/src/generated/grammar.ts +++ b/packages/language/src/generated/grammar.ts @@ -1052,8 +1052,11 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "feature": "name", "operator": "=", "terminal": { - "$type": "Keyword", - "value": "sort" + "$type": "RuleCall", + "rule": { + "$ref": "#/rules@62" + }, + "arguments": [] } }, { @@ -1065,17 +1068,11 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "feature": "value", "operator": "=", "terminal": { - "$type": "Alternatives", - "elements": [ - { - "$type": "Keyword", - "value": "Asc" - }, - { - "$type": "Keyword", - "value": "Desc" - } - ] + "$type": "RuleCall", + "rule": { + "$ref": "#/rules@8" + }, + "arguments": [] } } ] @@ -1865,43 +1862,16 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "$type": "ParserRule", "name": "Argument", "definition": { - "$type": "Group", - "elements": [ - { - "$type": "Group", - "elements": [ - { - "$type": "Assignment", - "feature": "name", - "operator": "=", - "terminal": { - "$type": "RuleCall", - "rule": { - "$ref": "#/rules@46" - }, - "arguments": [] - } - }, - { - "$type": "Keyword", - "value": ":" - } - ], - "cardinality": "?" + "$type": "Assignment", + "feature": "value", + "operator": "=", + "terminal": { + "$type": "RuleCall", + "rule": { + "$ref": "#/rules@8" }, - { - "$type": "Assignment", - "feature": "value", - "operator": "=", - "terminal": { - "$type": "RuleCall", - "rule": { - "$ref": "#/rules@8" - }, - "arguments": [] - } - } - ] + "arguments": [] + } }, "definesHiddenTokens": false, "entry": false, @@ -2723,10 +2693,6 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "$type": "Keyword", "value": "in" }, - { - "$type": "Keyword", - "value": "sort" - }, { "$type": "Keyword", "value": "view" diff --git a/packages/language/src/zmodel.langium b/packages/language/src/zmodel.langium index da445c792..8fcc72c34 100644 --- a/packages/language/src/zmodel.langium +++ b/packages/language/src/zmodel.langium @@ -80,7 +80,7 @@ fragment ReferenceArgList: args+=ReferenceArg (',' args+=ReferenceArg)*; ReferenceArg: - name=('sort') ':' value=('Asc' | 'Desc'); + name=ID ':' value=Expression; ObjectExpr: @@ -172,7 +172,7 @@ fragment ArgumentList: args+=Argument (',' args+=Argument)*; Argument: - (name=RegularID ':')? value=Expression; + value=Expression; // model DataModel: @@ -224,7 +224,7 @@ FunctionParamType: // https://github.com/langium/langium/discussions/1012 RegularID returns string: // include keywords that we'd like to work as ID in most places - ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'sort' | 'view' | 'import'; + ID | 'model' | 'enum' | 'attribute' | 'datasource' | 'plugin' | 'abstract' | 'in' | 'view' | 'import'; // attribute Attribute: diff --git a/packages/language/syntaxes/zmodel.tmLanguage b/packages/language/syntaxes/zmodel.tmLanguage index cf70fb761..6102b919d 100644 --- a/packages/language/syntaxes/zmodel.tmLanguage +++ b/packages/language/syntaxes/zmodel.tmLanguage @@ -20,7 +20,7 @@ name keyword.control.zmodel match - \b(Any|Asc|BigInt|Boolean|Bytes|ContextType|DateTime|Decimal|Desc|FieldReference|Float|Int|Json|Null|Object|String|TransitiveFieldReference|Unsupported|abstract|attribute|datasource|enum|extends|false|function|generator|import|in|model|null|plugin|sort|this|true|view)\b + \b(Any|BigInt|Boolean|Bytes|ContextType|DateTime|Decimal|FieldReference|Float|Int|Json|Null|Object|String|TransitiveFieldReference|Unsupported|abstract|attribute|datasource|enum|extends|false|function|generator|import|in|model|null|plugin|this|true|view)\b name diff --git a/packages/language/syntaxes/zmodel.tmLanguage.json b/packages/language/syntaxes/zmodel.tmLanguage.json index 00c737c97..aad6a38c7 100644 --- a/packages/language/syntaxes/zmodel.tmLanguage.json +++ b/packages/language/syntaxes/zmodel.tmLanguage.json @@ -10,7 +10,7 @@ }, { "name": "keyword.control.zmodel", - "match": "\\b(Any|Asc|BigInt|Boolean|Bytes|ContextType|DateTime|Decimal|Desc|FieldReference|Float|Int|Json|Null|Object|String|TransitiveFieldReference|Unsupported|abstract|attribute|datasource|enum|extends|false|function|generator|import|in|model|null|plugin|sort|this|true|view)\\b" + "match": "\\b(Any|BigInt|Boolean|Bytes|ContextType|DateTime|Decimal|FieldReference|Float|Int|Json|Null|Object|String|TransitiveFieldReference|Unsupported|abstract|attribute|datasource|enum|extends|false|function|generator|import|in|model|null|plugin|this|true|view)\\b" }, { "name": "string.quoted.double.zmodel", diff --git a/packages/misc/redwood/package.json b/packages/misc/redwood/package.json index 011e0dd64..e477bc7b8 100644 --- a/packages/misc/redwood/package.json +++ b/packages/misc/redwood/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/redwood", "displayName": "ZenStack RedwoodJS Integration", - "version": "1.9.1", + "version": "1.9.0", "description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.", "repository": { "type": "git", diff --git a/packages/plugins/openapi/package.json b/packages/plugins/openapi/package.json index 6584ad022..96a336f58 100644 --- a/packages/plugins/openapi/package.json +++ b/packages/plugins/openapi/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/openapi", "displayName": "ZenStack Plugin and Runtime for OpenAPI", - "version": "1.9.1", + "version": "1.9.0", "description": "ZenStack plugin and runtime supporting OpenAPI", "main": "index.js", "repository": { diff --git a/packages/plugins/swr/package.json b/packages/plugins/swr/package.json index 351048b69..c64538378 100644 --- a/packages/plugins/swr/package.json +++ b/packages/plugins/swr/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/swr", "displayName": "ZenStack plugin for generating SWR hooks", - "version": "1.9.1", + "version": "1.9.0", "description": "ZenStack plugin for generating SWR hooks", "main": "index.js", "repository": { diff --git a/packages/plugins/tanstack-query/package.json b/packages/plugins/tanstack-query/package.json index ffbfd7bc0..0c16ca59d 100644 --- a/packages/plugins/tanstack-query/package.json +++ b/packages/plugins/tanstack-query/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/tanstack-query", "displayName": "ZenStack plugin for generating tanstack-query hooks", - "version": "1.9.1", + "version": "1.9.0", "description": "ZenStack plugin for generating tanstack-query hooks", "main": "index.js", "exports": { diff --git a/packages/plugins/trpc/package.json b/packages/plugins/trpc/package.json index 215039ba0..0b53d2aa2 100644 --- a/packages/plugins/trpc/package.json +++ b/packages/plugins/trpc/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/trpc", "displayName": "ZenStack plugin for tRPC", - "version": "1.9.1", + "version": "1.9.0", "description": "ZenStack plugin for tRPC", "main": "index.js", "repository": { diff --git a/packages/runtime/package.json b/packages/runtime/package.json index 494cf907f..3cb61dd38 100644 --- a/packages/runtime/package.json +++ b/packages/runtime/package.json @@ -1,7 +1,7 @@ { "name": "@zenstackhq/runtime", "displayName": "ZenStack Runtime Library", - "version": "1.9.1", + "version": "1.9.0", "description": "Runtime of ZenStack for both client-side and server-side environments.", "repository": { "type": "git", diff --git a/packages/schema/package.json b/packages/schema/package.json index 7fc652b14..af8672afb 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -3,7 +3,7 @@ "publisher": "zenstack", "displayName": "ZenStack Language Tools", "description": "Build scalable web apps with minimum code by defining authorization and validation rules inside the data schema that closer to the database", - "version": "1.9.1", + "version": "1.9.0", "author": { "name": "ZenStack Team" }, diff --git a/packages/schema/src/language-server/validator/function-invocation-validator.ts b/packages/schema/src/language-server/validator/function-invocation-validator.ts index 3bc364bd2..d8c3df900 100644 --- a/packages/schema/src/language-server/validator/function-invocation-validator.ts +++ b/packages/schema/src/language-server/validator/function-invocation-validator.ts @@ -52,6 +52,7 @@ export default class FunctionInvocationValidator implements AstValidator ExpressionContext.DefaultValue) .with(P.union('@@allow', '@@deny', '@allow', '@deny'), () => ExpressionContext.AccessPolicy) .with('@@validate', () => ExpressionContext.ValidationRule) + .with('@@index', () => ExpressionContext.Index) .otherwise(() => undefined); // get the context allowed for the function diff --git a/packages/schema/src/plugins/prisma/prisma-builder.ts b/packages/schema/src/plugins/prisma/prisma-builder.ts index 64777b62e..ea6317504 100644 --- a/packages/schema/src/plugins/prisma/prisma-builder.ts +++ b/packages/schema/src/plugins/prisma/prisma-builder.ts @@ -288,7 +288,7 @@ export class FieldReference { } export class FieldReferenceArg { - constructor(public name: 'sort', public value: 'Asc' | 'Desc') {} + constructor(public name: string, public value: string) {} toString(): string { return `${this.name}: ${this.value}`; @@ -304,10 +304,10 @@ export class FunctionCall { } export class FunctionCallArg { - constructor(public name: string | undefined, public value: string) {} + constructor(public value: string) {} toString(): string { - return this.name ? `${this.name}: ${this.value}` : this.value; + return this.value; } } diff --git a/packages/schema/src/plugins/prisma/schema-generator.ts b/packages/schema/src/plugins/prisma/schema-generator.ts index 98dfa717e..2aa426b57 100644 --- a/packages/schema/src/plugins/prisma/schema-generator.ts +++ b/packages/schema/src/plugins/prisma/schema-generator.ts @@ -217,6 +217,10 @@ export default class PrismaSchemaGenerator { return JSON.stringify(expr.value); } + private exprToText(expr: Expression) { + return new ZModelCodeGenerator({ quote: 'double' }).generate(expr); + } + private generateGenerator(prisma: PrismaModel, decl: GeneratorDecl) { const generator = prisma.addGenerator( decl.name, @@ -368,7 +372,7 @@ export default class PrismaSchemaGenerator { 'FieldReference', new PrismaFieldReference( resolved(node.target).name, - node.args.map((arg) => new PrismaFieldReferenceArg(arg.name, arg.value)) + node.args.map((arg) => new PrismaFieldReferenceArg(arg.name, this.exprToText(arg.value))) ) ); } else if (isInvocationExpr(node)) { @@ -391,7 +395,7 @@ export default class PrismaSchemaGenerator { throw new PluginError(name, 'Function call argument must be literal or null'); }); - return new PrismaFunctionCallArg(arg.name, val); + return new PrismaFunctionCallArg(val); }) ); } diff --git a/packages/schema/src/res/stdlib.zmodel b/packages/schema/src/res/stdlib.zmodel index be241fe2c..a3bee6b2e 100644 --- a/packages/schema/src/res/stdlib.zmodel +++ b/packages/schema/src/res/stdlib.zmodel @@ -61,6 +61,9 @@ enum ExpressionContext { // used in @@validate ValidationRule + + // used in @@index + Index } /** @@ -200,7 +203,7 @@ attribute @@@completionHint(_ values: String[]) * @param sort: Allows you to specify in what order the entries of the ID are stored in the database. The available options are Asc and Desc. * @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true. */ -attribute @id(map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma +attribute @id(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma /** * Defines a default value for a field. @@ -215,7 +218,7 @@ attribute @default(_ value: ContextType, map: String?) @@@prisma * @param sort: Allows you to specify in what order the entries of the constraint are stored in the database. The available options are Asc and Desc. * @param clustered: Boolean Defines whether the constraint is clustered or non-clustered. Defaults to false. */ -attribute @unique(map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma +attribute @unique(map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma /** * Defines a multi-field ID (composite ID) on the model. @@ -227,7 +230,7 @@ attribute @unique(map: String?, length: Int?, sort: String?, clustered: Boolean? * @param sort: Allows you to specify in what order the entries of the ID are stored in the database. The available options are Asc and Desc. * @param clustered: Defines whether the ID is clustered or non-clustered. Defaults to true. */ -attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma +attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma /** * Defines a compound unique constraint for the specified fields. @@ -238,7 +241,7 @@ attribute @@id(_ fields: FieldReference[], name: String?, map: String?, length: * @param sort: Allows you to specify in what order the entries of the constraint are stored in the database. The available options are Asc and Desc. * @param clustered: Boolean Defines whether the constraint is clustered or non-clustered. Defaults to false. */ -attribute @@unique(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: String?, clustered: Boolean?) @@@prisma +attribute @@unique(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?) @@@prisma /** * Index types @@ -252,6 +255,84 @@ enum IndexType { Brin } +/** + * Operator class for index + */ +enum IndexOperatorClass { + // GIN + ArrayOps + JsonbOps + JsonbPathOps + + // Gist + InetOps + + // SpGist + TextOps + + // BRIN + BitMinMaxOps + VarBitMinMaxOps + BpcharBloomOps + BpcharMinMaxOps + ByteaBloomOps + ByteaMinMaxOps + DateBloomOps + DateMinMaxOps + DateMinMaxMultiOps + Float4BloomOps + Float4MinMaxOps + Float4MinMaxMultiOps + Float8BloomOps + Float8MinMaxOps + Float8MinMaxMultiOps + InetInclusionOps + InetBloomOps + InetMinMaxOps + InetMinMaxMultiOps + Int2BloomOps + Int2MinMaxOps + Int2MinMaxMultiOps + Int4BloomOps + Int4MinMaxOps + Int4MinMaxMultiOps + Int8BloomOps + Int8MinMaxOps + Int8MinMaxMultiOps + NumericBloomOps + NumericMinMaxOps + NumericMinMaxMultiOps + OidBloomOps + OidMinMaxOps + OidMinMaxMultiOps + TextBloomOps + TextMinMaxOps + TextMinMaxMultiOps + TimestampBloomOps + TimestampMinMaxOps + TimestampMinMaxMultiOps + TimestampTzBloomOps + TimestampTzMinMaxOps + TimestampTzMinMaxMultiOps + TimeBloomOps + TimeMinMaxOps + TimeMinMaxMultiOps + TimeTzBloomOps + TimeTzMinMaxOps + TimeTzMinMaxMultiOps + UuidBloomOps + UuidMinMaxOps + UuidMinMaxMultiOps +} + +/** + * Index sort order + */ +enum SortOrder { + Asc + Desc +} + /** * Defines an index in the database. * @@ -263,7 +344,7 @@ enum IndexType { * @params clustered: Defines whether the index is clustered or non-clustered. Defaults to false. * @params type: Allows you to specify an index access method. Defaults to BTree. */ -attribute @@index(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: String?, clustered: Boolean?, type: IndexType?) @@@prisma +attribute @@index(_ fields: FieldReference[], name: String?, map: String?, length: Int?, sort: SortOrder?, clustered: Boolean?, type: IndexType?) @@@prisma /** * Defines meta information about the relation. @@ -598,3 +679,9 @@ attribute @prisma.passthrough(_ text: String) * A utility attribute to allow passthrough of arbitrary attribute text to the generated Prisma schema. */ attribute @@prisma.passthrough(_ text: String) + +/** + * Used for specifying operator classes for GIN index. + */ +function raw(value: String): Any { +} @@@expressionContext([Index]) diff --git a/packages/sdk/package.json b/packages/sdk/package.json index b4ccab542..99d7ba495 100644 --- a/packages/sdk/package.json +++ b/packages/sdk/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/sdk", - "version": "1.9.1", + "version": "1.9.0", "description": "ZenStack plugin development SDK", "main": "index.js", "scripts": { diff --git a/packages/sdk/src/constants.ts b/packages/sdk/src/constants.ts index e038c6958..1e0d22d67 100644 --- a/packages/sdk/src/constants.ts +++ b/packages/sdk/src/constants.ts @@ -12,6 +12,7 @@ export enum ExpressionContext { DefaultValue = 'DefaultValue', AccessPolicy = 'AccessPolicy', ValidationRule = 'ValidationRule', + Index = 'Index', } export const STD_LIB_MODULE_NAME = 'stdlib.zmodel'; diff --git a/packages/sdk/src/zmodel-code-generator.ts b/packages/sdk/src/zmodel-code-generator.ts index 1b1f001e1..facd7c76c 100644 --- a/packages/sdk/src/zmodel-code-generator.ts +++ b/packages/sdk/src/zmodel-code-generator.ts @@ -49,6 +49,7 @@ export interface ZModelCodeOptions { binaryExprNumberOfSpaces: number; unaryExprNumberOfSpaces: number; indent: number; + quote: 'single' | 'double'; } // a registry of generation handlers marked with @gen @@ -75,6 +76,7 @@ export class ZModelCodeGenerator { binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1, unaryExprNumberOfSpaces: options?.unaryExprNumberOfSpaces ?? 0, indent: options?.indent ?? 4, + quote: options?.quote ?? 'single', }; } @@ -224,7 +226,7 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join('\n')}${ @gen(StringLiteral) private _generateLiteralExpr(ast: LiteralExpr) { - return `'${ast.value}'`; + return this.options.quote === 'single' ? `'${ast.value}'` : `"${ast.value}"`; } @gen(NumberLiteral) @@ -321,7 +323,7 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join('\n')}${ } private argument(ast: Argument) { - return `${ast.name ? ast.name + ': ' : ''}${this.generate(ast.value)}`; + return this.generate(ast.value); } private get binaryExprSpace() { diff --git a/packages/server/package.json b/packages/server/package.json index af441d4f1..7ed1e3e29 100644 --- a/packages/server/package.json +++ b/packages/server/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/server", - "version": "1.9.1", + "version": "1.9.0", "displayName": "ZenStack Server-side Adapters", "description": "ZenStack server-side adapters", "homepage": "https://zenstack.dev", diff --git a/packages/testtools/package.json b/packages/testtools/package.json index 8acf19707..a9856e73e 100644 --- a/packages/testtools/package.json +++ b/packages/testtools/package.json @@ -1,6 +1,6 @@ { "name": "@zenstackhq/testtools", - "version": "1.9.1", + "version": "1.9.0", "description": "ZenStack Test Tools", "main": "index.js", "private": true, From a9732b2ee1d7617b510ff3774ec93d2de66a3ede Mon Sep 17 00:00:00 2001 From: ymc9 <104139426+ymc9@users.noreply.github.com> Date: Mon, 12 Feb 2024 18:15:06 +0800 Subject: [PATCH 2/2] fixes --- packages/language/package.json | 4 +- packages/language/src/generated/ast.ts | 18 ++++++++- packages/language/src/generated/grammar.ts | 25 ++++++------ packages/language/src/generated/module.ts | 8 ++-- packages/schema/package.json | 2 +- .../zmodel-completion-provider.ts | 10 ++--- .../src/language-server/zmodel-module.ts | 7 ++++ .../tests/generator/prisma-builder.test.ts | 2 +- .../schema/tests/schema/all-features.zmodel | 4 +- packages/schema/tests/schema/parser.test.ts | 2 - .../validation/attribute-validation.test.ts | 10 ++--- packages/sdk/src/zmodel-code-generator.ts | 2 +- packages/testtools/package.json | 2 +- pnpm-lock.yaml | 38 ++++++++++++------- 14 files changed, 84 insertions(+), 50 deletions(-) diff --git a/packages/language/package.json b/packages/language/package.json index d4260e6e6..a80768913 100644 --- a/packages/language/package.json +++ b/packages/language/package.json @@ -19,11 +19,11 @@ "author": "ZenStack Team", "license": "MIT", "devDependencies": { - "langium-cli": "1.2.0", + "langium-cli": "1.3.1", "plist2": "^1.1.3" }, "dependencies": { - "langium": "1.2.0" + "langium": "1.3.1" }, "contributes": { "languages": [ diff --git a/packages/language/src/generated/ast.ts b/packages/language/src/generated/ast.ts index 44e21b149..a95a748d9 100644 --- a/packages/language/src/generated/ast.ts +++ b/packages/language/src/generated/ast.ts @@ -1,10 +1,24 @@ /****************************************************************************** - * This file was generated by langium-cli 1.2.0. + * This file was generated by langium-cli 1.3.1. * DO NOT EDIT MANUALLY! ******************************************************************************/ /* eslint-disable */ -import { AstNode, AbstractAstReflection, Reference, ReferenceInfo, TypeMetaData } from 'langium'; +import type { AstNode, Reference, ReferenceInfo, TypeMetaData } from 'langium'; +import { AbstractAstReflection } from 'langium'; + +export const ZModelTerminals = { + WS: /\s+/, + INTERNAL_ATTRIBUTE_NAME: /@@@([_a-zA-Z][\w_]*\.)*[_a-zA-Z][\w_]*/, + MODEL_ATTRIBUTE_NAME: /@@([_a-zA-Z][\w_]*\.)*[_a-zA-Z][\w_]*/, + FIELD_ATTRIBUTE_NAME: /@([_a-zA-Z][\w_]*\.)*[_a-zA-Z][\w_]*/, + ID: /[_a-zA-Z][\w_]*/, + STRING: /"(\\.|[^"\\])*"|'(\\.|[^'\\])*'/, + NUMBER: /[+-]?[0-9]+(\.[0-9]+)?/, + TRIPLE_SLASH_COMMENT: /\/\/\/[^\n\r]*/, + ML_COMMENT: /\/\*[\s\S]*?\*\//, + SL_COMMENT: /\/\/[^\n\r]*/, +}; export type AbstractDeclaration = Attribute | DataModel | DataSource | Enum | FunctionDecl | GeneratorDecl | Plugin; diff --git a/packages/language/src/generated/grammar.ts b/packages/language/src/generated/grammar.ts index 2a5d532d3..45aa3ff97 100644 --- a/packages/language/src/generated/grammar.ts +++ b/packages/language/src/generated/grammar.ts @@ -1,9 +1,10 @@ /****************************************************************************** - * This file was generated by langium-cli 1.2.0. + * This file was generated by langium-cli 1.3.1. * DO NOT EDIT MANUALLY! ******************************************************************************/ -import { loadGrammarFromJson, Grammar } from 'langium'; +import type { Grammar } from 'langium'; +import { loadGrammarFromJson } from 'langium'; let loadedZModelGrammar: Grammar | undefined; export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModelGrammar = loadGrammarFromJson(`{ @@ -3418,7 +3419,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "WS", "definition": { "$type": "RegexToken", - "regex": "\\\\s+" + "regex": "/\\\\s+/" }, "fragment": false }, @@ -3427,7 +3428,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "INTERNAL_ATTRIBUTE_NAME", "definition": { "$type": "RegexToken", - "regex": "@@@([_a-zA-Z][\\\\w_]*\\\\.)*[_a-zA-Z][\\\\w_]*" + "regex": "/@@@([_a-zA-Z][\\\\w_]*\\\\.)*[_a-zA-Z][\\\\w_]*/" }, "fragment": false, "hidden": false @@ -3437,7 +3438,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "MODEL_ATTRIBUTE_NAME", "definition": { "$type": "RegexToken", - "regex": "@@([_a-zA-Z][\\\\w_]*\\\\.)*[_a-zA-Z][\\\\w_]*" + "regex": "/@@([_a-zA-Z][\\\\w_]*\\\\.)*[_a-zA-Z][\\\\w_]*/" }, "fragment": false, "hidden": false @@ -3447,7 +3448,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "FIELD_ATTRIBUTE_NAME", "definition": { "$type": "RegexToken", - "regex": "@([_a-zA-Z][\\\\w_]*\\\\.)*[_a-zA-Z][\\\\w_]*" + "regex": "/@([_a-zA-Z][\\\\w_]*\\\\.)*[_a-zA-Z][\\\\w_]*/" }, "fragment": false, "hidden": false @@ -3457,7 +3458,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "ID", "definition": { "$type": "RegexToken", - "regex": "[_a-zA-Z][\\\\w_]*" + "regex": "/[_a-zA-Z][\\\\w_]*/" }, "fragment": false, "hidden": false @@ -3467,7 +3468,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "STRING", "definition": { "$type": "RegexToken", - "regex": "\\"(\\\\\\\\.|[^\\"\\\\\\\\])*\\"|'(\\\\\\\\.|[^'\\\\\\\\])*'" + "regex": "/\\"(\\\\\\\\.|[^\\"\\\\\\\\])*\\"|'(\\\\\\\\.|[^'\\\\\\\\])*'/" }, "fragment": false, "hidden": false @@ -3477,7 +3478,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "NUMBER", "definition": { "$type": "RegexToken", - "regex": "[+-]?[0-9]+(\\\\.[0-9]+)?" + "regex": "/[+-]?[0-9]+(\\\\.[0-9]+)?/" }, "fragment": false, "hidden": false @@ -3487,7 +3488,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "TRIPLE_SLASH_COMMENT", "definition": { "$type": "RegexToken", - "regex": "\\\\/\\\\/\\\\/[^\\\\n\\\\r]*" + "regex": "/\\\\/\\\\/\\\\/[^\\\\n\\\\r]*/" }, "fragment": false, "hidden": false @@ -3498,7 +3499,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "ML_COMMENT", "definition": { "$type": "RegexToken", - "regex": "\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\/" + "regex": "/\\\\/\\\\*[\\\\s\\\\S]*?\\\\*\\\\//" }, "fragment": false }, @@ -3508,7 +3509,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel "name": "SL_COMMENT", "definition": { "$type": "RegexToken", - "regex": "\\\\/\\\\/[^\\\\n\\\\r]*" + "regex": "/\\\\/\\\\/[^\\\\n\\\\r]*/" }, "fragment": false } diff --git a/packages/language/src/generated/module.ts b/packages/language/src/generated/module.ts index ac0995108..b96dd1dee 100644 --- a/packages/language/src/generated/module.ts +++ b/packages/language/src/generated/module.ts @@ -1,17 +1,17 @@ /****************************************************************************** - * This file was generated by langium-cli 1.2.0. + * This file was generated by langium-cli 1.3.1. * DO NOT EDIT MANUALLY! ******************************************************************************/ -import { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices, LanguageMetaData, Module } from 'langium'; +import type { LangiumGeneratedServices, LangiumGeneratedSharedServices, LangiumSharedServices, LangiumServices, LanguageMetaData, Module } from 'langium'; import { ZModelAstReflection } from './ast'; import { ZModelGrammar } from './grammar'; -export const ZModelLanguageMetaData: LanguageMetaData = { +export const ZModelLanguageMetaData = { languageId: 'zmodel', fileExtensions: ['.zmodel'], caseInsensitive: false -}; +} as const satisfies LanguageMetaData; export const ZModelGeneratedSharedModule: Module = { AstReflection: () => new ZModelAstReflection() diff --git a/packages/schema/package.json b/packages/schema/package.json index af8672afb..2451a87c8 100644 --- a/packages/schema/package.json +++ b/packages/schema/package.json @@ -87,7 +87,7 @@ "colors": "1.4.0", "commander": "^8.3.0", "get-latest-version": "^5.0.1", - "langium": "1.2.0", + "langium": "1.3.1", "lower-case-first": "^2.0.2", "mixpanel": "^0.17.0", "ora": "^5.4.1", diff --git a/packages/schema/src/language-server/zmodel-completion-provider.ts b/packages/schema/src/language-server/zmodel-completion-provider.ts index 742f7087f..70400db64 100644 --- a/packages/schema/src/language-server/zmodel-completion-provider.ts +++ b/packages/schema/src/language-server/zmodel-completion-provider.ts @@ -61,7 +61,7 @@ export class ZModelCompletionProvider extends DefaultCompletionProvider { if (isDataModelAttribute(context.node) || isDataModelFieldAttribute(context.node)) { const completions = this.getCompletionFromHint(context.node); if (completions) { - completions.forEach(acceptor); + completions.forEach((c) => acceptor(context, c)); return; } } @@ -131,7 +131,7 @@ export class ZModelCompletionProvider extends DefaultCompletionProvider { return; } - const customAcceptor = (item: CompletionValueItem) => { + const customAcceptor = (context: CompletionContext, item: CompletionValueItem) => { // attributes starting with @@@ are for internal use only if (item.insertText?.startsWith('@@@') || item.label?.startsWith('@@@')) { return; @@ -156,7 +156,7 @@ export class ZModelCompletionProvider extends DefaultCompletionProvider { return; } } - acceptor(item); + acceptor(context, item); }; super.completionForCrossReference(context, crossRef, customAcceptor); @@ -168,11 +168,11 @@ export class ZModelCompletionProvider extends DefaultCompletionProvider { keyword: any, acceptor: CompletionAcceptor ): MaybePromise { - const customAcceptor = (item: CompletionValueItem) => { + const customAcceptor = (context: CompletionContext, item: CompletionValueItem) => { if (!this.filterKeywordForContext(context, keyword.value)) { return; } - acceptor(item); + acceptor(context, item); }; super.completionForKeyword(context, keyword, customAcceptor); } diff --git a/packages/schema/src/language-server/zmodel-module.ts b/packages/schema/src/language-server/zmodel-module.ts index 07dc223e0..c0c66ce43 100644 --- a/packages/schema/src/language-server/zmodel-module.ts +++ b/packages/schema/src/language-server/zmodel-module.ts @@ -2,12 +2,15 @@ import { ZModelGeneratedModule, ZModelGeneratedSharedModule } from '@zenstackhq/ import { DefaultConfigurationProvider, DefaultDocumentBuilder, + DefaultFuzzyMatcher, DefaultIndexManager, DefaultLangiumDocumentFactory, DefaultLangiumDocuments, DefaultLanguageServer, + DefaultNodeKindProvider, DefaultServiceRegistry, DefaultSharedModuleContext, + DefaultWorkspaceSymbolProvider, LangiumDefaultSharedServices, LangiumServices, LangiumSharedServices, @@ -77,6 +80,7 @@ export const ZModelModule: Module { @@ -85,6 +89,9 @@ export function createSharedModule( lsp: { Connection: () => context.connection, LanguageServer: (services) => new DefaultLanguageServer(services), + WorkspaceSymbolProvider: (services) => new DefaultWorkspaceSymbolProvider(services), + NodeKindProvider: () => new DefaultNodeKindProvider(), + FuzzyMatcher: () => new DefaultFuzzyMatcher(), }, workspace: { LangiumDocuments: (services) => new DefaultLangiumDocuments(services), diff --git a/packages/schema/tests/generator/prisma-builder.test.ts b/packages/schema/tests/generator/prisma-builder.test.ts index 48e465362..a3944401c 100644 --- a/packages/schema/tests/generator/prisma-builder.test.ts +++ b/packages/schema/tests/generator/prisma-builder.test.ts @@ -102,7 +102,7 @@ describe('Prisma Builder Tests', () => { undefined, new AttributeArgValue( 'FunctionCall', - new FunctionCall('dbgenerated', [new FunctionCallArg(undefined, '"timestamp_id()"')]) + new FunctionCall('dbgenerated', [new FunctionCallArg('"timestamp_id()"')]) ) ), ]), diff --git a/packages/schema/tests/schema/all-features.zmodel b/packages/schema/tests/schema/all-features.zmodel index c47a7cf79..b567093fe 100644 --- a/packages/schema/tests/schema/all-features.zmodel +++ b/packages/schema/tests/schema/all-features.zmodel @@ -40,7 +40,7 @@ model Space extends Base { createdAt DateTime @default(now()) updatedAt DateTime @updatedAt name String @length(4, 50) - slug String @unique @length(4, 16) + slug String @length(4, 16) owner User? @relation(fields: [ownerId], references: [id]) ownerId String? members SpaceUser[] @@ -58,6 +58,8 @@ model Space extends Base { // space admin can update and delete @@allow('update,delete', members?[user == auth() && role == ADMIN]) + + @@index([slug(ops: raw("gin_trgm_ops"))], type: Gin) } /* diff --git a/packages/schema/tests/schema/parser.test.ts b/packages/schema/tests/schema/parser.test.ts index 9b4150cd5..25ada5ceb 100644 --- a/packages/schema/tests/schema/parser.test.ts +++ b/packages/schema/tests/schema/parser.test.ts @@ -224,7 +224,6 @@ describe('Parsing Tests', () => { expect(((model.attributes[1].args[0].value as ArrayExpr).items[0] as ReferenceExpr).args[0]).toEqual( expect.objectContaining({ name: 'sort', - value: 'Asc', }) ); @@ -232,7 +231,6 @@ describe('Parsing Tests', () => { expect((model.attributes[2].args[0].value as ReferenceExpr).args[0]).toEqual( expect.objectContaining({ name: 'sort', - value: 'Desc', }) ); }); diff --git a/packages/schema/tests/schema/validation/attribute-validation.test.ts b/packages/schema/tests/schema/validation/attribute-validation.test.ts index 6d8d02b14..b86637b58 100644 --- a/packages/schema/tests/schema/validation/attribute-validation.test.ts +++ b/packages/schema/tests/schema/validation/attribute-validation.test.ts @@ -161,11 +161,11 @@ describe('Attribute tests', () => { model A { x Int y String - @@id([x, y], name: 'x_y', map: '_x_y', length: 10, sort: 'Asc', clustered: true) + @@id([x, y], name: 'x_y', map: '_x_y', length: 10, sort: Asc, clustered: true) } model B { - id String @id(map: '_id', length: 10, sort: 'Asc', clustered: true) + id String @id(map: '_id', length: 10, sort: Asc, clustered: true) } `); @@ -175,7 +175,7 @@ describe('Attribute tests', () => { id String @id x Int y String - @@unique([x, y], name: 'x_y', map: '_x_y', length: 10, sort: 'Asc', clustered: true) + @@unique([x, y], name: 'x_y', map: '_x_y', length: 10, sort: Asc, clustered: true) } `); @@ -193,7 +193,7 @@ describe('Attribute tests', () => { ${prelude} model A { id String @id - x Int @unique(map: '_x', length: 10, sort: 'Asc', clustered: true) + x Int @unique(map: '_x', length: 10, sort: Asc, clustered: true) } `); @@ -222,7 +222,7 @@ describe('Attribute tests', () => { id String @id x Int y String - @@index([x(sort: Asc), y(sort: Desc)], name: 'myindex', map: '_myindex', length: 10, sort: 'asc', clustered: true, type: BTree) + @@index([x(sort: Asc), y(sort: Desc)], name: 'myindex', map: '_myindex', length: 10, sort: Asc, clustered: true, type: BTree) } `); diff --git a/packages/sdk/src/zmodel-code-generator.ts b/packages/sdk/src/zmodel-code-generator.ts index facd7c76c..96aaa87d9 100644 --- a/packages/sdk/src/zmodel-code-generator.ts +++ b/packages/sdk/src/zmodel-code-generator.ts @@ -267,7 +267,7 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join('\n')}${ @gen(ReferenceArg) private _generateReferenceArg(ast: ReferenceArg) { - return `${ast.name}:${ast.value}`; + return `${ast.name}:${this.generate(ast.value)}`; } @gen(MemberAccessExpr) diff --git a/packages/testtools/package.json b/packages/testtools/package.json index a9856e73e..0aafe452e 100644 --- a/packages/testtools/package.json +++ b/packages/testtools/package.json @@ -24,7 +24,7 @@ "@zenstackhq/runtime": "workspace:*", "@zenstackhq/sdk": "workspace:*", "json5": "^2.2.3", - "langium": "1.2.0", + "langium": "1.3.1", "pg": "^8.11.1", "tmp": "^0.2.1", "vscode-uri": "^3.0.6", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d501a52ca..9dcef261b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -69,12 +69,12 @@ importers: packages/language: dependencies: langium: - specifier: 1.2.0 - version: 1.2.0 + specifier: 1.3.1 + version: 1.3.1 devDependencies: langium-cli: - specifier: 1.2.0 - version: 1.2.0 + specifier: 1.3.1 + version: 1.3.1 plist2: specifier: ^1.1.3 version: 1.1.3 @@ -484,8 +484,8 @@ importers: specifier: ^5.0.1 version: 5.0.1 langium: - specifier: 1.2.0 - version: 1.2.0 + specifier: 1.3.1 + version: 1.3.1 lower-case-first: specifier: ^2.0.2 version: 2.0.2 @@ -739,8 +739,8 @@ importers: specifier: ^2.2.3 version: 2.2.3 langium: - specifier: 1.2.0 - version: 1.2.0 + specifier: 1.3.1 + version: 1.3.1 pg: specifier: ^8.11.1 version: 8.11.1 @@ -10232,8 +10232,8 @@ packages: resolution: {integrity: sha512-dWl0Dbjm6Xm+kDxhPQJsCBTxrJzuGl0aP9rhr+TG8D3l+GL90N8O8lYUi7dTSAN2uuDqCtNgb6aEuQH5wsiV8Q==} dev: true - /langium-cli@1.2.0: - resolution: {integrity: sha512-DPyJUd4Hj8+OBNEcAQyJtW6e38+UPd758gTI7Ep0r/sDogrwJ/GJHx5nGA+r0ygpNcDPG+mS9Hw8Y05uCNNcoQ==} + /langium-cli@1.3.1: + resolution: {integrity: sha512-9faKpioKCjBD0Z4y165+wQlDFiDHOXYBlhPVgbV+neSnSB70belZLNfykAVa564360h7Br/5PogR5jW2n/tOKw==} engines: {node: '>=14.0.0'} hasBin: true dependencies: @@ -10241,12 +10241,20 @@ packages: commander: 10.0.1 fs-extra: 11.1.1 jsonschema: 1.4.1 - langium: 1.2.0 + langium: 1.3.1 + langium-railroad: 1.3.0 lodash: 4.17.21 dev: true - /langium@1.2.0: - resolution: {integrity: sha512-jFSptpFljYo9ZTHrq/GZflMUXiKo5KBNtsaIJtnIzDm9zC2FxsxejEFAtNL09262RVQt+zFeF/2iLAShFTGitw==} + /langium-railroad@1.3.0: + resolution: {integrity: sha512-I3gx79iF+Qpn2UjzfHLf2GENAD9mPdSZHL3juAZLBsxznw4se7MBrJX32oPr/35DTjU9q99wFCQoCXu7mcf+Bg==} + dependencies: + langium: 1.3.1 + railroad-diagrams: 1.0.0 + dev: true + + /langium@1.3.1: + resolution: {integrity: sha512-xC+DnAunl6cZIgYjRpgm3s1kYAB5/Wycsj24iYaXG9uai7SgvMaFZSrRvdA5rUK/lSta/CRvgF+ZFoEKEOFJ5w==} engines: {node: '>=14.0.0'} dependencies: chevrotain: 10.4.2 @@ -12619,6 +12627,10 @@ packages: resolution: {integrity: sha512-pNsHDxbGORSvuSScqNJ+3Km6QAVqk8CfsCBIEoDgpqLrkD2f3QM4I7d1ozJJ172OmIcoUcerZaNWqtLkRXTV3A==} dev: true + /railroad-diagrams@1.0.0: + resolution: {integrity: sha512-cz93DjNeLY0idrCNOH6PviZGRN9GJhsdm9hpn1YCS879fj4W+x5IFJhhkRZcwVgMmFF7R82UA/7Oh+R8lLZg6A==} + dev: true + /randombytes@2.1.0: resolution: {integrity: sha512-vYl3iOX+4CKUWuxGi9Ukhie6fsqXqS9FE2Zaic4tNFD2N2QQaXOMFbuKK4QmDHC0JO6B1Zp41J0LpT0oR68amQ==} dependencies: