Skip to content

Commit 76c6579

Browse files
authored
merge dev to main (v2.9.0) (#1869)
2 parents d2554f2 + 768d94c commit 76c6579

File tree

113 files changed

+8852
-758
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

113 files changed

+8852
-758
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "2.8.1",
3+
"version": "2.9.0",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

packages/ide/jetbrains/CHANGELOG.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,18 @@
44

55
### Added
66

7+
- Support for using `@@validate` attribute inside type declarations.
8+
9+
## 2.8.1
10+
11+
### Fixed
12+
13+
- Wrong validation errors when using strongly typed JSON fields in a multi-file schema setup.
14+
15+
## 2.8.0
16+
17+
### Added
18+
719
- Type declaration support.
820

921
## 2.7.0

packages/ide/jetbrains/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ plugins {
99
}
1010

1111
group = "dev.zenstack"
12-
version = "2.8.1"
12+
version = "2.9.0"
1313

1414
repositories {
1515
mavenCentral()

packages/ide/jetbrains/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "jetbrains",
3-
"version": "2.8.1",
3+
"version": "2.9.0",
44
"displayName": "ZenStack JetBrains IDE Plugin",
55
"description": "ZenStack JetBrains IDE plugin",
66
"homepage": "https://zenstack.dev",

packages/language/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/language",
3-
"version": "2.8.1",
3+
"version": "2.9.0",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",

packages/language/src/generated/ast.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ export function isLiteralExpr(item: unknown): item is LiteralExpr {
7070
return reflection.isInstance(item, LiteralExpr);
7171
}
7272

73-
export type ReferenceTarget = DataModelField | EnumField | FunctionParam;
73+
export type MemberAccessTarget = DataModelField | TypeDefField;
74+
75+
export const MemberAccessTarget = 'MemberAccessTarget';
76+
77+
export function isMemberAccessTarget(item: unknown): item is MemberAccessTarget {
78+
return reflection.isInstance(item, MemberAccessTarget);
79+
}
80+
81+
export type ReferenceTarget = DataModelField | EnumField | FunctionParam | TypeDefField;
7482

7583
export const ReferenceTarget = 'ReferenceTarget';
7684

@@ -285,7 +293,7 @@ export function isDataModel(item: unknown): item is DataModel {
285293
}
286294

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

300308
export interface DataModelField extends AstNode {
301-
readonly $container: DataModel | Enum | FunctionDecl;
309+
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
302310
readonly $type: 'DataModelField';
303311
attributes: Array<DataModelFieldAttribute>
304312
comments: Array<string>
@@ -370,7 +378,7 @@ export function isEnum(item: unknown): item is Enum {
370378
}
371379

372380
export interface EnumField extends AstNode {
373-
readonly $container: DataModel | Enum | FunctionDecl;
381+
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
374382
readonly $type: 'EnumField';
375383
attributes: Array<DataModelFieldAttribute>
376384
comments: Array<string>
@@ -413,7 +421,7 @@ export function isFunctionDecl(item: unknown): item is FunctionDecl {
413421
}
414422

415423
export interface FunctionParam extends AstNode {
416-
readonly $container: DataModel | Enum | FunctionDecl;
424+
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
417425
readonly $type: 'FunctionParam';
418426
name: RegularID
419427
optional: boolean
@@ -482,7 +490,7 @@ export function isInvocationExpr(item: unknown): item is InvocationExpr {
482490
export interface MemberAccessExpr extends AstNode {
483491
readonly $container: Argument | ArrayExpr | AttributeArg | BinaryExpr | ConfigArrayExpr | ConfigField | ConfigInvocationArg | FieldInitializer | FunctionDecl | MemberAccessExpr | PluginField | ReferenceArg | UnaryExpr | UnsupportedFieldType;
484492
readonly $type: 'MemberAccessExpr';
485-
member: Reference<DataModelField>
493+
member: Reference<MemberAccessTarget>
486494
operand: Expression
487495
}
488496

@@ -631,6 +639,7 @@ export function isThisExpr(item: unknown): item is ThisExpr {
631639
export interface TypeDef extends AstNode {
632640
readonly $container: Model;
633641
readonly $type: 'TypeDef';
642+
attributes: Array<DataModelAttribute>
634643
comments: Array<string>
635644
fields: Array<TypeDefField>
636645
name: RegularID
@@ -643,7 +652,7 @@ export function isTypeDef(item: unknown): item is TypeDef {
643652
}
644653

645654
export interface TypeDefField extends AstNode {
646-
readonly $container: TypeDef;
655+
readonly $container: DataModel | Enum | FunctionDecl | TypeDef;
647656
readonly $type: 'TypeDefField';
648657
attributes: Array<DataModelFieldAttribute>
649658
comments: Array<string>
@@ -730,6 +739,7 @@ export type ZModelAstType = {
730739
InvocationExpr: InvocationExpr
731740
LiteralExpr: LiteralExpr
732741
MemberAccessExpr: MemberAccessExpr
742+
MemberAccessTarget: MemberAccessTarget
733743
Model: Model
734744
ModelImport: ModelImport
735745
NullExpr: NullExpr
@@ -754,7 +764,7 @@ export type ZModelAstType = {
754764
export class ZModelAstReflection extends AbstractAstReflection {
755765

756766
getAllTypes(): string[] {
757-
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'];
767+
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'];
758768
}
759769

760770
protected override computeIsSubtype(subtype: string, supertype: string): boolean {
@@ -788,14 +798,17 @@ export class ZModelAstReflection extends AbstractAstReflection {
788798
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype);
789799
}
790800
case DataModelField:
791-
case EnumField:
792-
case FunctionParam: {
793-
return this.isSubtype(ReferenceTarget, supertype);
801+
case TypeDefField: {
802+
return this.isSubtype(MemberAccessTarget, supertype) || this.isSubtype(ReferenceTarget, supertype);
794803
}
795804
case Enum:
796805
case TypeDef: {
797806
return this.isSubtype(AbstractDeclaration, supertype) || this.isSubtype(TypeDeclaration, supertype) || this.isSubtype(TypeDefFieldTypes, supertype);
798807
}
808+
case EnumField:
809+
case FunctionParam: {
810+
return this.isSubtype(ReferenceTarget, supertype);
811+
}
799812
case InvocationExpr:
800813
case LiteralExpr: {
801814
return this.isSubtype(ConfigExpr, supertype) || this.isSubtype(Expression, supertype);
@@ -826,7 +839,7 @@ export class ZModelAstReflection extends AbstractAstReflection {
826839
return FunctionDecl;
827840
}
828841
case 'MemberAccessExpr:member': {
829-
return DataModelField;
842+
return MemberAccessTarget;
830843
}
831844
case 'ReferenceExpr:target': {
832845
return ReferenceTarget;
@@ -1055,6 +1068,7 @@ export class ZModelAstReflection extends AbstractAstReflection {
10551068
return {
10561069
name: 'TypeDef',
10571070
mandatory: [
1071+
{ name: 'attributes', type: 'array' },
10581072
{ name: 'comments', type: 'array' },
10591073
{ name: 'fields', type: 'array' }
10601074
]

packages/language/src/generated/grammar.ts

Lines changed: 58 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1301,7 +1301,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
13011301
"terminal": {
13021302
"$type": "CrossReference",
13031303
"type": {
1304-
"$ref": "#/rules@38"
1304+
"$ref": "#/types@1"
13051305
},
13061306
"deprecatedSyntax": false
13071307
}
@@ -2165,7 +2165,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
21652165
"terminal": {
21662166
"$type": "CrossReference",
21672167
"type": {
2168-
"$ref": "#/types@2"
2168+
"$ref": "#/types@3"
21692169
},
21702170
"terminal": {
21712171
"$type": "RuleCall",
@@ -2257,16 +2257,33 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
22572257
"value": "{"
22582258
},
22592259
{
2260-
"$type": "Assignment",
2261-
"feature": "fields",
2262-
"operator": "+=",
2263-
"terminal": {
2264-
"$type": "RuleCall",
2265-
"rule": {
2266-
"$ref": "#/rules@41"
2260+
"$type": "Alternatives",
2261+
"elements": [
2262+
{
2263+
"$type": "Assignment",
2264+
"feature": "fields",
2265+
"operator": "+=",
2266+
"terminal": {
2267+
"$type": "RuleCall",
2268+
"rule": {
2269+
"$ref": "#/rules@41"
2270+
},
2271+
"arguments": []
2272+
}
22672273
},
2268-
"arguments": []
2269-
},
2274+
{
2275+
"$type": "Assignment",
2276+
"feature": "attributes",
2277+
"operator": "+=",
2278+
"terminal": {
2279+
"$type": "RuleCall",
2280+
"rule": {
2281+
"$ref": "#/rules@55"
2282+
},
2283+
"arguments": []
2284+
}
2285+
}
2286+
],
22702287
"cardinality": "*"
22712288
},
22722289
{
@@ -2375,7 +2392,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
23752392
"terminal": {
23762393
"$type": "CrossReference",
23772394
"type": {
2378-
"$ref": "#/types@1"
2395+
"$ref": "#/types@2"
23792396
},
23802397
"terminal": {
23812398
"$type": "RuleCall",
@@ -2827,7 +2844,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
28272844
"terminal": {
28282845
"$type": "CrossReference",
28292846
"type": {
2830-
"$ref": "#/types@2"
2847+
"$ref": "#/types@3"
28312848
},
28322849
"terminal": {
28332850
"$type": "RuleCall",
@@ -3255,7 +3272,7 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
32553272
"terminal": {
32563273
"$type": "CrossReference",
32573274
"type": {
3258-
"$ref": "#/types@2"
3275+
"$ref": "#/types@3"
32593276
},
32603277
"terminal": {
32613278
"$type": "RuleCall",
@@ -3829,6 +3846,12 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
38293846
"$ref": "#/rules@38"
38303847
}
38313848
},
3849+
{
3850+
"$type": "SimpleType",
3851+
"typeRef": {
3852+
"$ref": "#/rules@41"
3853+
}
3854+
},
38323855
{
38333856
"$type": "SimpleType",
38343857
"typeRef": {
@@ -3838,6 +3861,27 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
38383861
]
38393862
}
38403863
},
3864+
{
3865+
"$type": "Type",
3866+
"name": "MemberAccessTarget",
3867+
"type": {
3868+
"$type": "UnionType",
3869+
"types": [
3870+
{
3871+
"$type": "SimpleType",
3872+
"typeRef": {
3873+
"$ref": "#/rules@38"
3874+
}
3875+
},
3876+
{
3877+
"$type": "SimpleType",
3878+
"typeRef": {
3879+
"$ref": "#/rules@41"
3880+
}
3881+
}
3882+
]
3883+
}
3884+
},
38413885
{
38423886
"$type": "Type",
38433887
"name": "TypeDefFieldTypes",

packages/language/src/zmodel.langium

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ ConfigArrayExpr:
6666
ConfigExpr:
6767
LiteralExpr | InvocationExpr | ConfigArrayExpr;
6868

69-
type ReferenceTarget = FunctionParam | DataModelField | EnumField;
69+
type ReferenceTarget = FunctionParam | DataModelField | TypeDefField | EnumField;
7070
ThisExpr:
7171
value='this';
7272

@@ -94,18 +94,20 @@ FieldInitializer:
9494
InvocationExpr:
9595
function=[FunctionDecl] '(' ArgumentList? ')';
9696

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

10099
MemberAccessExpr infers Expression:
101100
PrimaryExpr (
102101
{infer MemberAccessExpr.operand=current}
103-
('.' member=[DataModelField])
102+
('.' member=[MemberAccessTarget])
104103
)*;
105104

106105
UnaryExpr:
107106
operator=('!') operand=MemberAccessExpr;
108107

108+
// binary operator precedence follow Javascript's rules:
109+
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#table
110+
109111
CollectionPredicateExpr infers Expression:
110112
MemberAccessExpr (
111113
{infer BinaryExpr.left=current}
@@ -179,10 +181,12 @@ DataModelField:
179181
DataModelFieldType:
180182
(type=BuiltinType | unsupported=UnsupportedFieldType | reference=[TypeDeclaration:RegularID]) (array?='[' ']')? (optional?='?')?;
181183

184+
// TODO: unify TypeDef and abstract DataModel
182185
TypeDef:
183186
(comments+=TRIPLE_SLASH_COMMENT)*
184187
'type' name=RegularID '{' (
185-
fields+=TypeDefField
188+
fields+=TypeDefField |
189+
attributes+=DataModelAttribute
186190
)*
187191
'}';
188192

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

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

packages/misc/redwood/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/redwood",
33
"displayName": "ZenStack RedwoodJS Integration",
4-
"version": "2.8.1",
4+
"version": "2.9.0",
55
"description": "CLI and runtime for integrating ZenStack with RedwoodJS projects.",
66
"repository": {
77
"type": "git",

packages/plugins/openapi/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/openapi",
33
"displayName": "ZenStack Plugin and Runtime for OpenAPI",
4-
"version": "2.8.1",
4+
"version": "2.9.0",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {

0 commit comments

Comments
 (0)