Skip to content

Commit 8675170

Browse files
authored
merge dev to main (#226)
2 parents fb1ec3d + 4f1b9fc commit 8675170

34 files changed

+540
-331
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name": "zenstack-monorepo",
3-
"version": "1.0.0-alpha.48",
3+
"version": "1.0.0-alpha.53",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",
77
"test": "pnpm -r run test --silent",
88
"lint": "pnpm -r lint",
9-
"publish-all": "pnpm --filter \"./packages/**\" -r publish",
10-
"publish-dev": "pnpm --filter \"./packages/**\" -r publish --tag dev",
11-
"publish-canary": "pnpm --filter \"./packages/**\" -r publish --tag canary"
9+
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public",
10+
"publish-dev": "pnpm --filter \"./packages/**\" -r publish --access public --tag dev",
11+
"publish-canary": "pnpm --filter \"./packages/**\" -r publish --access public --tag canary"
1212
},
1313
"keywords": [],
1414
"author": "",

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": "1.0.0-alpha.48",
3+
"version": "1.0.0-alpha.53",
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: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ export function isDataModel(item: unknown): item is DataModel {
176176
}
177177

178178
export interface DataModelAttribute extends AstNode {
179-
readonly $container: DataModel;
179+
readonly $container: DataModel | Enum;
180180
readonly $type: 'DataModelAttribute';
181181
args: Array<AttributeArg>
182182
decl: Reference<Attribute>
@@ -204,7 +204,7 @@ export function isDataModelField(item: unknown): item is DataModelField {
204204
}
205205

206206
export interface DataModelFieldAttribute extends AstNode {
207-
readonly $container: DataModelField;
207+
readonly $container: DataModelField | EnumField;
208208
readonly $type: 'DataModelFieldAttribute';
209209
args: Array<AttributeArg>
210210
decl: Reference<Attribute>
@@ -260,6 +260,8 @@ export function isDataSourceField(item: unknown): item is DataSourceField {
260260
export interface Enum extends AstNode {
261261
readonly $container: Model;
262262
readonly $type: 'Enum';
263+
attributes: Array<DataModelAttribute>
264+
comments: Array<string>
263265
fields: Array<EnumField>
264266
name: string
265267
}
@@ -273,6 +275,8 @@ export function isEnum(item: unknown): item is Enum {
273275
export interface EnumField extends AstNode {
274276
readonly $container: DataModel | Enum | FunctionDecl;
275277
readonly $type: 'EnumField';
278+
attributes: Array<DataModelFieldAttribute>
279+
comments: Array<string>
276280
name: string
277281
}
278282

@@ -697,10 +701,21 @@ export class ZModelAstReflection extends AbstractAstReflection {
697701
return {
698702
name: 'Enum',
699703
mandatory: [
704+
{ name: 'attributes', type: 'array' },
705+
{ name: 'comments', type: 'array' },
700706
{ name: 'fields', type: 'array' }
701707
]
702708
};
703709
}
710+
case 'EnumField': {
711+
return {
712+
name: 'EnumField',
713+
mandatory: [
714+
{ name: 'attributes', type: 'array' },
715+
{ name: 'comments', type: 'array' }
716+
]
717+
};
718+
}
704719
case 'FunctionDecl': {
705720
return {
706721
name: 'FunctionDecl',

packages/language/src/generated/grammar.ts

Lines changed: 105 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1603,13 +1603,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
16031603
]
16041604
},
16051605
{
1606-
"$type": "Assignment",
1607-
"feature": "array",
1608-
"operator": "?=",
1609-
"terminal": {
1610-
"$type": "Keyword",
1611-
"value": "[]"
1612-
},
1606+
"$type": "Group",
1607+
"elements": [
1608+
{
1609+
"$type": "Assignment",
1610+
"feature": "array",
1611+
"operator": "?=",
1612+
"terminal": {
1613+
"$type": "Keyword",
1614+
"value": "["
1615+
}
1616+
},
1617+
{
1618+
"$type": "Keyword",
1619+
"value": "]"
1620+
}
1621+
],
16131622
"cardinality": "?"
16141623
},
16151624
{
@@ -1638,11 +1647,16 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
16381647
"$type": "Group",
16391648
"elements": [
16401649
{
1641-
"$type": "RuleCall",
1642-
"rule": {
1643-
"$ref": "#/rules@56"
1650+
"$type": "Assignment",
1651+
"feature": "comments",
1652+
"operator": "+=",
1653+
"terminal": {
1654+
"$type": "RuleCall",
1655+
"rule": {
1656+
"$ref": "#/rules@56"
1657+
},
1658+
"arguments": []
16441659
},
1645-
"arguments": [],
16461660
"cardinality": "*"
16471661
},
16481662
{
@@ -1666,16 +1680,33 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
16661680
"value": "{"
16671681
},
16681682
{
1669-
"$type": "Assignment",
1670-
"feature": "fields",
1671-
"operator": "+=",
1672-
"terminal": {
1673-
"$type": "RuleCall",
1674-
"rule": {
1675-
"$ref": "#/rules@30"
1683+
"$type": "Alternatives",
1684+
"elements": [
1685+
{
1686+
"$type": "Assignment",
1687+
"feature": "fields",
1688+
"operator": "+=",
1689+
"terminal": {
1690+
"$type": "RuleCall",
1691+
"rule": {
1692+
"$ref": "#/rules@30"
1693+
},
1694+
"arguments": []
1695+
}
16761696
},
1677-
"arguments": []
1678-
},
1697+
{
1698+
"$type": "Assignment",
1699+
"feature": "attributes",
1700+
"operator": "+=",
1701+
"terminal": {
1702+
"$type": "RuleCall",
1703+
"rule": {
1704+
"$ref": "#/rules@43"
1705+
},
1706+
"arguments": []
1707+
}
1708+
}
1709+
],
16791710
"cardinality": "+"
16801711
},
16811712
{
@@ -1698,11 +1729,16 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
16981729
"$type": "Group",
16991730
"elements": [
17001731
{
1701-
"$type": "RuleCall",
1702-
"rule": {
1703-
"$ref": "#/rules@56"
1732+
"$type": "Assignment",
1733+
"feature": "comments",
1734+
"operator": "+=",
1735+
"terminal": {
1736+
"$type": "RuleCall",
1737+
"rule": {
1738+
"$ref": "#/rules@56"
1739+
},
1740+
"arguments": []
17041741
},
1705-
"arguments": [],
17061742
"cardinality": "*"
17071743
},
17081744
{
@@ -1716,6 +1752,19 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
17161752
},
17171753
"arguments": []
17181754
}
1755+
},
1756+
{
1757+
"$type": "Assignment",
1758+
"feature": "attributes",
1759+
"operator": "+=",
1760+
"terminal": {
1761+
"$type": "RuleCall",
1762+
"rule": {
1763+
"$ref": "#/rules@42"
1764+
},
1765+
"arguments": []
1766+
},
1767+
"cardinality": "*"
17191768
}
17201769
]
17211770
},
@@ -1937,13 +1986,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
19371986
]
19381987
},
19391988
{
1940-
"$type": "Assignment",
1941-
"feature": "array",
1942-
"operator": "?=",
1943-
"terminal": {
1944-
"$type": "Keyword",
1945-
"value": "[]"
1946-
},
1989+
"$type": "Group",
1990+
"elements": [
1991+
{
1992+
"$type": "Assignment",
1993+
"feature": "array",
1994+
"operator": "?=",
1995+
"terminal": {
1996+
"$type": "Keyword",
1997+
"value": "["
1998+
}
1999+
},
2000+
{
2001+
"$type": "Keyword",
2002+
"value": "]"
2003+
}
2004+
],
19472005
"cardinality": "?"
19482006
}
19492007
]
@@ -2334,13 +2392,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
23342392
]
23352393
},
23362394
{
2337-
"$type": "Assignment",
2338-
"feature": "array",
2339-
"operator": "?=",
2340-
"terminal": {
2341-
"$type": "Keyword",
2342-
"value": "[]"
2343-
},
2395+
"$type": "Group",
2396+
"elements": [
2397+
{
2398+
"$type": "Assignment",
2399+
"feature": "array",
2400+
"operator": "?=",
2401+
"terminal": {
2402+
"$type": "Keyword",
2403+
"value": "["
2404+
}
2405+
},
2406+
{
2407+
"$type": "Keyword",
2408+
"value": "]"
2409+
}
2410+
],
23442411
"cardinality": "?"
23452412
},
23462413
{

packages/language/src/zmodel.langium

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fragment ReferenceArgList:
5454
args+=ReferenceArg (',' args+=ReferenceArg)*;
5555

5656
ReferenceArg:
57-
name=('sort') ':' value=('Asc'| 'Desc');
57+
name=('sort') ':' value=('Asc' | 'Desc');
5858

5959
InvocationExpr:
6060
function=[FunctionDecl] '(' ArgumentList? ')';
@@ -145,14 +145,20 @@ DataModelField:
145145
name=ID type=DataModelFieldType (attributes+=DataModelFieldAttribute)*;
146146

147147
DataModelFieldType:
148-
(type=BuiltinType | reference=[TypeDeclaration:ID]) (array?='[]')? (optional?='?')?;
148+
(type=BuiltinType | reference=[TypeDeclaration:ID]) (array?='[' ']')? (optional?='?')?;
149149

150150
// enum
151151
Enum:
152-
TRIPLE_SLASH_COMMENT* 'enum' name=ID '{' (fields+=EnumField)+ '}';
152+
(comments+=TRIPLE_SLASH_COMMENT)*
153+
'enum' name=ID '{' (
154+
fields+=EnumField
155+
| attributes+=DataModelAttribute
156+
)+
157+
'}';
153158

154159
EnumField:
155-
TRIPLE_SLASH_COMMENT* name=ID;
160+
(comments+=TRIPLE_SLASH_COMMENT)*
161+
name=ID (attributes+=DataModelFieldAttribute)*;
156162

157163
// function
158164
FunctionDecl:
@@ -162,7 +168,7 @@ FunctionParam:
162168
TRIPLE_SLASH_COMMENT* name=ID ':' type=FunctionParamType;
163169

164170
FunctionParamType:
165-
(type=ExpressionType | reference=[TypeDeclaration]) (array?='[]')?;
171+
(type=ExpressionType | reference=[TypeDeclaration]) (array?='[' ']')?;
166172

167173
QualifiedName returns string:
168174
ID ('.' ID)*;
@@ -192,7 +198,7 @@ AttributeParam:
192198
// FieldReference refers to fields declared in the current model
193199
// TransitiveFieldReference refers to fields declared in the model type of the current field
194200
AttributeParamType:
195-
(type=(ExpressionType | 'FieldReference' | 'TransitiveFieldReference' | 'ContextType') | reference=[TypeDeclaration:ID]) (array?='[]')? (optional?='?')?;
201+
(type=(ExpressionType | 'FieldReference' | 'TransitiveFieldReference' | 'ContextType') | reference=[TypeDeclaration:ID]) (array?='[' ']')? (optional?='?')?;
196202

197203
type TypeDeclaration = DataModel | Enum;
198204

packages/next/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@zenstackhq/next",
3-
"version": "1.0.0-alpha.48",
3+
"version": "1.0.0-alpha.53",
44
"displayName": "ZenStack Next.js integration",
55
"description": "ZenStack Next.js integration",
66
"homepage": "https://zenstack.dev",

packages/plugins/react/package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/react",
33
"displayName": "ZenStack plugin and runtime for ReactJS",
4-
"version": "1.0.0-alpha.48",
4+
"version": "1.0.0-alpha.53",
55
"description": "ZenStack plugin and runtime for ReactJS",
66
"main": "index.js",
77
"repository": {
@@ -32,6 +32,10 @@
3232
"swr": "^2.0.3",
3333
"ts-morph": "^16.0.0"
3434
},
35+
"peerDependencies": {
36+
"react": "^17.0.2 || ^18",
37+
"react-dom": "^17.0.2 || ^18"
38+
},
3539
"devDependencies": {
3640
"@types/react": "^18.0.26",
3741
"copyfiles": "^2.4.1",

packages/plugins/react/src/react-hooks-generator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { DMMF } from '@prisma/generator-helper';
2-
import { PluginError, PluginOptions } from '@zenstackhq/sdk';
2+
import { CrudFailureReason, PluginError, PluginOptions } from '@zenstackhq/sdk';
33
import { DataModel, isDataModel, Model } from '@zenstackhq/sdk/ast';
44
import { camelCase, paramCase } from 'change-case';
55
import * as path from 'path';
@@ -35,7 +35,7 @@ function wrapReadbackErrorCheck(code: string) {
3535
return `try {
3636
${code}
3737
} catch (err: any) {
38-
if (err.info?.prisma && err.info?.code === 'P2004' && err.info?.reason === 'RESULT_NOT_READABLE') {
38+
if (err.info?.prisma && err.info?.code === 'P2004' && err.info?.reason === '${CrudFailureReason.RESULT_NOT_READABLE}') {
3939
// unable to readback data
4040
return undefined;
4141
} else {

packages/plugins/trpc/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/trpc",
33
"displayName": "ZenStack plugin for tRPC",
4-
"version": "1.0.0-alpha.48",
4+
"version": "1.0.0-alpha.53",
55
"description": "ZenStack plugin for tRPC",
66
"main": "index.js",
77
"repository": {

0 commit comments

Comments
 (0)