Skip to content

Commit

Permalink
merge dev to main (v2.9.0) (#1869)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Nov 18, 2024
2 parents d2554f2 + 768d94c commit 76c6579
Show file tree
Hide file tree
Showing 113 changed files with 8,852 additions and 758 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "zenstack-monorepo",
"version": "2.8.1",
"version": "2.9.0",
"description": "",
"scripts": {
"build": "pnpm -r build",
Expand Down
12 changes: 12 additions & 0 deletions packages/ide/jetbrains/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@

### Added

- Support for using `@@validate` attribute inside type declarations.

## 2.8.1

### Fixed

- Wrong validation errors when using strongly typed JSON fields in a multi-file schema setup.

## 2.8.0

### Added

- Type declaration support.

## 2.7.0
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ plugins {
}

group = "dev.zenstack"
version = "2.8.1"
version = "2.9.0"

repositories {
mavenCentral()
Expand Down
2 changes: 1 addition & 1 deletion packages/ide/jetbrains/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "jetbrains",
"version": "2.8.1",
"version": "2.9.0",
"displayName": "ZenStack JetBrains IDE Plugin",
"description": "ZenStack JetBrains IDE plugin",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 1 deletion packages/language/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/language",
"version": "2.8.1",
"version": "2.9.0",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
38 changes: 26 additions & 12 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ export function isLiteralExpr(item: unknown): item is LiteralExpr {
return reflection.isInstance(item, LiteralExpr);
}

export type ReferenceTarget = DataModelField | EnumField | FunctionParam;
export type MemberAccessTarget = DataModelField | TypeDefField;

export const MemberAccessTarget = 'MemberAccessTarget';

export function isMemberAccessTarget(item: unknown): item is MemberAccessTarget {
return reflection.isInstance(item, MemberAccessTarget);
}

export type ReferenceTarget = DataModelField | EnumField | FunctionParam | TypeDefField;

export const ReferenceTarget = 'ReferenceTarget';

Expand Down Expand Up @@ -285,7 +293,7 @@ export function isDataModel(item: unknown): item is DataModel {
}

export interface DataModelAttribute extends AstNode {
readonly $container: DataModel | Enum;
readonly $container: DataModel | Enum | TypeDef;
readonly $type: 'DataModelAttribute';
args: Array<AttributeArg>
decl: Reference<Attribute>
Expand All @@ -298,7 +306,7 @@ export function isDataModelAttribute(item: unknown): item is DataModelAttribute
}

export interface DataModelField extends AstNode {
readonly $container: DataModel | Enum | FunctionDecl;
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
readonly $type: 'DataModelField';
attributes: Array<DataModelFieldAttribute>
comments: Array<string>
Expand Down Expand Up @@ -370,7 +378,7 @@ export function isEnum(item: unknown): item is Enum {
}

export interface EnumField extends AstNode {
readonly $container: DataModel | Enum | FunctionDecl;
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
readonly $type: 'EnumField';
attributes: Array<DataModelFieldAttribute>
comments: Array<string>
Expand Down Expand Up @@ -413,7 +421,7 @@ export function isFunctionDecl(item: unknown): item is FunctionDecl {
}

export interface FunctionParam extends AstNode {
readonly $container: DataModel | Enum | FunctionDecl;
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
readonly $type: 'FunctionParam';
name: RegularID
optional: boolean
Expand Down Expand Up @@ -482,7 +490,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 | ReferenceArg | UnaryExpr | UnsupportedFieldType;
readonly $type: 'MemberAccessExpr';
member: Reference<DataModelField>
member: Reference<MemberAccessTarget>
operand: Expression
}

Expand Down Expand Up @@ -631,6 +639,7 @@ export function isThisExpr(item: unknown): item is ThisExpr {
export interface TypeDef extends AstNode {
readonly $container: Model;
readonly $type: 'TypeDef';
attributes: Array<DataModelAttribute>
comments: Array<string>
fields: Array<TypeDefField>
name: RegularID
Expand All @@ -643,7 +652,7 @@ export function isTypeDef(item: unknown): item is TypeDef {
}

export interface TypeDefField extends AstNode {
readonly $container: TypeDef;
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
readonly $type: 'TypeDefField';
attributes: Array<DataModelFieldAttribute>
comments: Array<string>
Expand Down Expand Up @@ -730,6 +739,7 @@ export type ZModelAstType = {
InvocationExpr: InvocationExpr
LiteralExpr: LiteralExpr
MemberAccessExpr: MemberAccessExpr
MemberAccessTarget: MemberAccessTarget
Model: Model
ModelImport: ModelImport
NullExpr: NullExpr
Expand All @@ -754,7 +764,7 @@ export type ZModelAstType = {
export class ZModelAstReflection extends AbstractAstReflection {

getAllTypes(): string[] {
return ['AbstractDeclaration', 'Argument', 'ArrayExpr', 'Attribute', 'AttributeArg', 'AttributeParam', 'AttributeParamType', 'BinaryExpr', 'BooleanLiteral', 'ConfigArrayExpr', 'ConfigExpr', 'ConfigField', 'ConfigInvocationArg', 'ConfigInvocationExpr', 'DataModel', 'DataModelAttribute', 'DataModelField', 'DataModelFieldAttribute', 'DataModelFieldType', 'DataSource', 'Enum', 'EnumField', 'Expression', 'FieldInitializer', 'FunctionDecl', 'FunctionParam', 'FunctionParamType', 'GeneratorDecl', 'InternalAttribute', 'InvocationExpr', 'LiteralExpr', 'MemberAccessExpr', 'Model', 'ModelImport', 'NullExpr', 'NumberLiteral', 'ObjectExpr', 'Plugin', 'PluginField', 'ReferenceArg', 'ReferenceExpr', 'ReferenceTarget', 'StringLiteral', 'ThisExpr', 'TypeDeclaration', 'TypeDef', 'TypeDefField', 'TypeDefFieldType', 'TypeDefFieldTypes', 'UnaryExpr', 'UnsupportedFieldType'];
return ['AbstractDeclaration', 'Argument', 'ArrayExpr', 'Attribute', 'AttributeArg', 'AttributeParam', 'AttributeParamType', 'BinaryExpr', 'BooleanLiteral', 'ConfigArrayExpr', 'ConfigExpr', 'ConfigField', 'ConfigInvocationArg', 'ConfigInvocationExpr', 'DataModel', 'DataModelAttribute', 'DataModelField', 'DataModelFieldAttribute', 'DataModelFieldType', 'DataSource', 'Enum', 'EnumField', 'Expression', 'FieldInitializer', 'FunctionDecl', 'FunctionParam', 'FunctionParamType', 'GeneratorDecl', 'InternalAttribute', 'InvocationExpr', 'LiteralExpr', 'MemberAccessExpr', 'MemberAccessTarget', 'Model', 'ModelImport', 'NullExpr', 'NumberLiteral', 'ObjectExpr', 'Plugin', 'PluginField', 'ReferenceArg', 'ReferenceExpr', 'ReferenceTarget', 'StringLiteral', 'ThisExpr', 'TypeDeclaration', 'TypeDef', 'TypeDefField', 'TypeDefFieldType', 'TypeDefFieldTypes', 'UnaryExpr', 'UnsupportedFieldType'];
}

protected override computeIsSubtype(subtype: string, supertype: string): boolean {
Expand Down Expand Up @@ -788,14 +798,17 @@ export class ZModelAstReflection extends AbstractAstReflection {
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
}
case DataModelField:
case EnumField:
case FunctionParam: {
return this.isSubtype(ReferenceTarget, supertype);
case TypeDefField: {
return this.isSubtype(MemberAccessTarget, supertype) || this.isSubtype(ReferenceTarget, supertype);
}
case Enum:
case TypeDef: {
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype) || this.isSubtype(TypeDefFieldTypes, supertype);
}
case EnumField:
case FunctionParam: {
return this.isSubtype(ReferenceTarget, supertype);
}
case InvocationExpr:
case LiteralExpr: {
return this.isSubtype(ConfigExpr, supertype) || this.isSubtype(Expression, supertype);
Expand Down Expand Up @@ -826,7 +839,7 @@ export class ZModelAstReflection extends AbstractAstReflection {
return FunctionDecl;
}
case 'MemberAccessExpr:member': {
return DataModelField;
return MemberAccessTarget;
}
case 'ReferenceExpr:target': {
return ReferenceTarget;
Expand Down Expand Up @@ -1055,6 +1068,7 @@ export class ZModelAstReflection extends AbstractAstReflection {
return {
name: 'TypeDef',
mandatory: [
{ name: 'attributes', type: 'array' },
{ name: 'comments', type: 'array' },
{ name: 'fields', type: 'array' }
]
Expand Down
72 changes: 58 additions & 14 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/rules@38"
"$ref": "#/types@1"
},
"deprecatedSyntax": false
}
Expand Down Expand Up @@ -2165,7 +2165,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/types@2"
"$ref": "#/types@3"
},
"terminal": {
"$type": "RuleCall",
Expand Down Expand Up @@ -2257,16 +2257,33 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"value": "{"
},
{
"$type": "Assignment",
"feature": "fields",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@41"
"$type": "Alternatives",
"elements": [
{
"$type": "Assignment",
"feature": "fields",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@41"
},
"arguments": []
}
},
"arguments": []
},
{
"$type": "Assignment",
"feature": "attributes",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@55"
},
"arguments": []
}
}
],
"cardinality": "*"
},
{
Expand Down Expand Up @@ -2375,7 +2392,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/types@1"
"$ref": "#/types@2"
},
"terminal": {
"$type": "RuleCall",
Expand Down Expand Up @@ -2827,7 +2844,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/types@2"
"$ref": "#/types@3"
},
"terminal": {
"$type": "RuleCall",
Expand Down Expand Up @@ -3255,7 +3272,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"terminal": {
"$type": "CrossReference",
"type": {
"$ref": "#/types@2"
"$ref": "#/types@3"
},
"terminal": {
"$type": "RuleCall",
Expand Down Expand Up @@ -3829,6 +3846,12 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"$ref": "#/rules@38"
}
},
{
"$type": "SimpleType",
"typeRef": {
"$ref": "#/rules@41"
}
},
{
"$type": "SimpleType",
"typeRef": {
Expand All @@ -3838,6 +3861,27 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
]
}
},
{
"$type": "Type",
"name": "MemberAccessTarget",
"type": {
"$type": "UnionType",
"types": [
{
"$type": "SimpleType",
"typeRef": {
"$ref": "#/rules@38"
}
},
{
"$type": "SimpleType",
"typeRef": {
"$ref": "#/rules@41"
}
}
]
}
},
{
"$type": "Type",
"name": "TypeDefFieldTypes",
Expand Down
15 changes: 10 additions & 5 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ ConfigArrayExpr:
ConfigExpr:
LiteralExpr | InvocationExpr | ConfigArrayExpr;

type ReferenceTarget = FunctionParam | DataModelField | EnumField;
type ReferenceTarget = FunctionParam | DataModelField | TypeDefField | EnumField;
ThisExpr:
value='this';

Expand Down Expand Up @@ -94,18 +94,20 @@ FieldInitializer:
InvocationExpr:
function=[FunctionDecl] '(' ArgumentList? ')';

// binary operator precedence follow Javascript's rules:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table
type MemberAccessTarget = DataModelField | TypeDefField;

MemberAccessExpr infers Expression:
PrimaryExpr (
{infer MemberAccessExpr.operand=current}
('.' member=[DataModelField])
('.' member=[MemberAccessTarget])
)*;

UnaryExpr:
operator=('!') operand=MemberAccessExpr;

// binary operator precedence follow Javascript's rules:
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table

CollectionPredicateExpr infers Expression:
MemberAccessExpr (
{infer BinaryExpr.left=current}
Expand Down Expand Up @@ -179,10 +181,12 @@ DataModelField:
DataModelFieldType:
(type=BuiltinType | unsupported=UnsupportedFieldType | reference=[TypeDeclaration:RegularID]) (array?='[' ']')? (optional?='?')?;

// TODO: unify TypeDef and abstract DataModel
TypeDef:
(comments+=TRIPLE_SLASH_COMMENT)*
'type' name=RegularID '{' (
fields+=TypeDefField
fields+=TypeDefField |
attributes+=DataModelAttribute
)*
'}';

Expand Down Expand Up @@ -245,6 +249,7 @@ type TypeDeclaration = DataModel | TypeDef | Enum;
DataModelFieldAttribute:
decl=[Attribute:FIELD_ATTRIBUTE_NAME] ('(' AttributeArgList? ')')?;

// TODO: need rename since it's for both DataModel and TypeDef
DataModelAttribute:
TRIPLE_SLASH_COMMENT* decl=[Attribute:MODEL_ATTRIBUTE_NAME] ('(' AttributeArgList? ')')?;

Expand Down
2 changes: 1 addition & 1 deletion packages/misc/redwood/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/redwood",
"displayName": "ZenStack RedwoodJS Integration",
"version": "2.8.1",
"version": "2.9.0",
"description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/openapi/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/openapi",
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
"version": "2.8.1",
"version": "2.9.0",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down
Loading

0 comments on commit 76c6579

Please sign in to comment.