Skip to content

Commit

Permalink
merge dev to main (#226)
Browse files Browse the repository at this point in the history
  • Loading branch information
ymc9 authored Mar 3, 2023
2 parents fb1ec3d + 4f1b9fc commit 8675170
Show file tree
Hide file tree
Showing 34 changed files with 540 additions and 331 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{
"name": "zenstack-monorepo",
"version": "1.0.0-alpha.48",
"version": "1.0.0-alpha.53",
"description": "",
"scripts": {
"build": "pnpm -r build",
"test": "pnpm -r run test --silent",
"lint": "pnpm -r lint",
"publish-all": "pnpm --filter \"./packages/**\" -r publish",
"publish-dev": "pnpm --filter \"./packages/**\" -r publish --tag dev",
"publish-canary": "pnpm --filter \"./packages/**\" -r publish --tag canary"
"publish-all": "pnpm --filter \"./packages/**\" -r publish --access public",
"publish-dev": "pnpm --filter \"./packages/**\" -r publish --access public --tag dev",
"publish-canary": "pnpm --filter \"./packages/**\" -r publish --access public --tag canary"
},
"keywords": [],
"author": "",
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": "1.0.0-alpha.48",
"version": "1.0.0-alpha.53",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
19 changes: 17 additions & 2 deletions packages/language/src/generated/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export function isDataModel(item: unknown): item is DataModel {
}

export interface DataModelAttribute extends AstNode {
readonly $container: DataModel;
readonly $container: DataModel | Enum;
readonly $type: 'DataModelAttribute';
args: Array<AttributeArg>
decl: Reference<Attribute>
Expand Down Expand Up @@ -204,7 +204,7 @@ export function isDataModelField(item: unknown): item is DataModelField {
}

export interface DataModelFieldAttribute extends AstNode {
readonly $container: DataModelField;
readonly $container: DataModelField | EnumField;
readonly $type: 'DataModelFieldAttribute';
args: Array<AttributeArg>
decl: Reference<Attribute>
Expand Down Expand Up @@ -260,6 +260,8 @@ export function isDataSourceField(item: unknown): item is DataSourceField {
export interface Enum extends AstNode {
readonly $container: Model;
readonly $type: 'Enum';
attributes: Array<DataModelAttribute>
comments: Array<string>
fields: Array<EnumField>
name: string
}
Expand All @@ -273,6 +275,8 @@ export function isEnum(item: unknown): item is Enum {
export interface EnumField extends AstNode {
readonly $container: DataModel | Enum | FunctionDecl;
readonly $type: 'EnumField';
attributes: Array<DataModelFieldAttribute>
comments: Array<string>
name: string
}

Expand Down Expand Up @@ -697,10 +701,21 @@ export class ZModelAstReflection extends AbstractAstReflection {
return {
name: 'Enum',
mandatory: [
{ name: 'attributes', type: 'array' },
{ name: 'comments', type: 'array' },
{ name: 'fields', type: 'array' }
]
};
}
case 'EnumField': {
return {
name: 'EnumField',
mandatory: [
{ name: 'attributes', type: 'array' },
{ name: 'comments', type: 'array' }
]
};
}
case 'FunctionDecl': {
return {
name: 'FunctionDecl',
Expand Down
143 changes: 105 additions & 38 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1603,13 +1603,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
]
},
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "[]"
},
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "["
}
},
{
"$type": "Keyword",
"value": "]"
}
],
"cardinality": "?"
},
{
Expand Down Expand Up @@ -1638,11 +1647,16 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
"$type": "Assignment",
"feature": "comments",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": []
},
"arguments": [],
"cardinality": "*"
},
{
Expand All @@ -1666,16 +1680,33 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"value": "{"
},
{
"$type": "Assignment",
"feature": "fields",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@30"
"$type": "Alternatives",
"elements": [
{
"$type": "Assignment",
"feature": "fields",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@30"
},
"arguments": []
}
},
"arguments": []
},
{
"$type": "Assignment",
"feature": "attributes",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@43"
},
"arguments": []
}
}
],
"cardinality": "+"
},
{
Expand All @@ -1698,11 +1729,16 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
"$type": "Assignment",
"feature": "comments",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": []
},
"arguments": [],
"cardinality": "*"
},
{
Expand All @@ -1716,6 +1752,19 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
},
"arguments": []
}
},
{
"$type": "Assignment",
"feature": "attributes",
"operator": "+=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@42"
},
"arguments": []
},
"cardinality": "*"
}
]
},
Expand Down Expand Up @@ -1937,13 +1986,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
]
},
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "[]"
},
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "["
}
},
{
"$type": "Keyword",
"value": "]"
}
],
"cardinality": "?"
}
]
Expand Down Expand Up @@ -2334,13 +2392,22 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
]
},
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "[]"
},
"$type": "Group",
"elements": [
{
"$type": "Assignment",
"feature": "array",
"operator": "?=",
"terminal": {
"$type": "Keyword",
"value": "["
}
},
{
"$type": "Keyword",
"value": "]"
}
],
"cardinality": "?"
},
{
Expand Down
18 changes: 12 additions & 6 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ fragment ReferenceArgList:
args+=ReferenceArg (',' args+=ReferenceArg)*;

ReferenceArg:
name=('sort') ':' value=('Asc'| 'Desc');
name=('sort') ':' value=('Asc' | 'Desc');

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

DataModelFieldType:
(type=BuiltinType | reference=[TypeDeclaration:ID]) (array?='[]')? (optional?='?')?;
(type=BuiltinType | reference=[TypeDeclaration:ID]) (array?='[' ']')? (optional?='?')?;

// enum
Enum:
TRIPLE_SLASH_COMMENT* 'enum' name=ID '{' (fields+=EnumField)+ '}';
(comments+=TRIPLE_SLASH_COMMENT)*
'enum' name=ID '{' (
fields+=EnumField
| attributes+=DataModelAttribute
)+
'}';

EnumField:
TRIPLE_SLASH_COMMENT* name=ID;
(comments+=TRIPLE_SLASH_COMMENT)*
name=ID (attributes+=DataModelFieldAttribute)*;

// function
FunctionDecl:
Expand All @@ -162,7 +168,7 @@ FunctionParam:
TRIPLE_SLASH_COMMENT* name=ID ':' type=FunctionParamType;

FunctionParamType:
(type=ExpressionType | reference=[TypeDeclaration]) (array?='[]')?;
(type=ExpressionType | reference=[TypeDeclaration]) (array?='[' ']')?;

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

type TypeDeclaration = DataModel | Enum;

Expand Down
2 changes: 1 addition & 1 deletion packages/next/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@zenstackhq/next",
"version": "1.0.0-alpha.48",
"version": "1.0.0-alpha.53",
"displayName": "ZenStack Next.js integration",
"description": "ZenStack Next.js integration",
"homepage": "https://zenstack.dev",
Expand Down
6 changes: 5 additions & 1 deletion packages/plugins/react/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/react",
"displayName": "ZenStack plugin and runtime for ReactJS",
"version": "1.0.0-alpha.48",
"version": "1.0.0-alpha.53",
"description": "ZenStack plugin and runtime for ReactJS",
"main": "index.js",
"repository": {
Expand Down Expand Up @@ -32,6 +32,10 @@
"swr": "^2.0.3",
"ts-morph": "^16.0.0"
},
"peerDependencies": {
"react": "^17.0.2 || ^18",
"react-dom": "^17.0.2 || ^18"
},
"devDependencies": {
"@types/react": "^18.0.26",
"copyfiles": "^2.4.1",
Expand Down
4 changes: 2 additions & 2 deletions packages/plugins/react/src/react-hooks-generator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DMMF } from '@prisma/generator-helper';
import { PluginError, PluginOptions } from '@zenstackhq/sdk';
import { CrudFailureReason, PluginError, PluginOptions } from '@zenstackhq/sdk';
import { DataModel, isDataModel, Model } from '@zenstackhq/sdk/ast';
import { camelCase, paramCase } from 'change-case';
import * as path from 'path';
Expand Down Expand Up @@ -35,7 +35,7 @@ function wrapReadbackErrorCheck(code: string) {
return `try {
${code}
} catch (err: any) {
if (err.info?.prisma && err.info?.code === 'P2004' && err.info?.reason === 'RESULT_NOT_READABLE') {
if (err.info?.prisma && err.info?.code === 'P2004' && err.info?.reason === '${CrudFailureReason.RESULT_NOT_READABLE}') {
// unable to readback data
return undefined;
} else {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/trpc/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/trpc",
"displayName": "ZenStack plugin for tRPC",
"version": "1.0.0-alpha.48",
"version": "1.0.0-alpha.53",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
Loading

0 comments on commit 8675170

Please sign in to comment.