Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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": "1.0.0-alpha.28",
"version": "1.0.0-alpha.31",
"description": "",
"scripts": {
"build": "pnpm -r build",
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.28",
"version": "1.0.0-alpha.31",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
127 changes: 118 additions & 9 deletions packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Keyword",
"value": "datasource"
Expand Down Expand Up @@ -156,6 +164,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "name",
Expand Down Expand Up @@ -211,6 +227,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Keyword",
"value": "generator"
Expand Down Expand Up @@ -263,6 +287,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "name",
Expand Down Expand Up @@ -318,6 +350,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Keyword",
"value": "plugin"
Expand Down Expand Up @@ -370,6 +410,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "name",
Expand Down Expand Up @@ -1589,6 +1637,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Keyword",
"value": "enum"
Expand Down Expand Up @@ -1639,16 +1695,29 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"$type": "ParserRule",
"name": "EnumField",
"definition": {
"$type": "Assignment",
"feature": "name",
"operator": "=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@53"
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
"arguments": []
}
{
"$type": "Assignment",
"feature": "name",
"operator": "=",
"terminal": {
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@53"
},
"arguments": []
}
}
]
},
"definesHiddenTokens": false,
"entry": false,
Expand All @@ -1663,6 +1732,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Keyword",
"value": "function"
Expand Down Expand Up @@ -1779,6 +1856,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "name",
Expand Down Expand Up @@ -2034,6 +2119,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Keyword",
"value": "attribute"
Expand Down Expand Up @@ -2126,6 +2219,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "default",
Expand Down Expand Up @@ -2323,6 +2424,14 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"definition": {
"$type": "Group",
"elements": [
{
"$type": "RuleCall",
"rule": {
"$ref": "#/rules@56"
},
"arguments": [],
"cardinality": "*"
},
{
"$type": "Assignment",
"feature": "decl",
Expand Down
26 changes: 13 additions & 13 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,24 @@ AbstractDeclaration:

// datasource
DataSource:
'datasource' name=ID '{' (fields+=DataSourceField)* '}';
TRIPLE_SLASH_COMMENT* 'datasource' name=ID '{' (fields+=DataSourceField)* '}';

DataSourceField:
name=ID '=' value=(LiteralExpr|InvocationExpr);
TRIPLE_SLASH_COMMENT* name=ID '=' value=(LiteralExpr|InvocationExpr);

// generator
GeneratorDecl:
'generator' name=ID '{' (fields+=GeneratorField)* '}';
TRIPLE_SLASH_COMMENT* 'generator' name=ID '{' (fields+=GeneratorField)* '}';

GeneratorField:
name=ID '=' value=(LiteralExpr | ArrayExpr);
TRIPLE_SLASH_COMMENT* name=ID '=' value=(LiteralExpr | ArrayExpr);

// plugin
Plugin:
'plugin' name=ID '{' (fields+=PluginField)* '}';
TRIPLE_SLASH_COMMENT* 'plugin' name=ID '{' (fields+=PluginField)* '}';

PluginField:
name=ID '=' value=(LiteralExpr | ArrayExpr);
TRIPLE_SLASH_COMMENT* name=ID '=' value=(LiteralExpr | ArrayExpr);

// expression
Expression:
Expand Down Expand Up @@ -149,17 +149,17 @@ DataModelFieldType:

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

EnumField:
name=ID;
TRIPLE_SLASH_COMMENT* name=ID;

// function
FunctionDecl:
'function' name=ID '(' (params+=FunctionParam (',' params+=FunctionParam)*)? ')' ':' returnType=FunctionParamType '{' (expression=Expression)? '}';
TRIPLE_SLASH_COMMENT* 'function' name=ID '(' (params+=FunctionParam (',' params+=FunctionParam)*)? ')' ':' returnType=FunctionParamType '{' (expression=Expression)? '}';

FunctionParam:
name=ID ':' type=FunctionParamType;
TRIPLE_SLASH_COMMENT* name=ID ':' type=FunctionParamType;

FunctionParamType:
(type=ExpressionType | reference=[TypeDeclaration]) (array?='[]')?;
Expand All @@ -184,10 +184,10 @@ AttributeName returns string:

// attribute
Attribute:
'attribute' name=AttributeName '(' (params+=AttributeParam (',' params+=AttributeParam)*)? ')' (attributes+=AttributeAttribute)*;
TRIPLE_SLASH_COMMENT* 'attribute' name=AttributeName '(' (params+=AttributeParam (',' params+=AttributeParam)*)? ')' (attributes+=AttributeAttribute)*;

AttributeParam:
(default?='_')? name=ID ':' type=AttributeParamType;
TRIPLE_SLASH_COMMENT* (default?='_')? name=ID ':' type=AttributeParamType;

// FieldReference refers to fields declared in the current model
// TransitiveFieldReference refers to fields declared in the model type of the current field
Expand All @@ -200,7 +200,7 @@ DataModelFieldAttribute:
decl=[Attribute:DataModelFieldAttributeName] ('(' AttributeArgList? ')')?;

DataModelAttribute:
decl=[Attribute:DataModelAttributeName] ('(' AttributeArgList? ')')?;
TRIPLE_SLASH_COMMENT* decl=[Attribute:DataModelAttributeName] ('(' AttributeArgList? ')')?;

AttributeAttribute:
decl=[Attribute:AttributeAttributeName] ('(' AttributeArgList? ')')?;
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.28",
"version": "1.0.0-alpha.31",
"displayName": "ZenStack Next.js integration",
"description": "ZenStack Next.js integration",
"homepage": "https://zenstack.dev",
Expand Down
2 changes: 1 addition & 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.28",
"version": "1.0.0-alpha.31",
"description": "ZenStack plugin and runtime for ReactJS",
"main": "index.js",
"repository": {
Expand Down
17 changes: 5 additions & 12 deletions packages/plugins/react/src/react-hooks-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,6 @@ import * as path from 'path';
import { Project } from 'ts-morph';

export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.Document) {
const project = new Project();
const models: DataModel[] = [];
const warnings: string[] = [];

for (const dm of model.declarations.filter((d): d is DataModel => isDataModel(d))) {
const hasAllowRule = dm.attributes.find((attr) => attr.decl.ref?.name === '@@allow');
if (hasAllowRule) {
models.push(dm);
}
}

let outDir = options.output as string;
if (!outDir) {
throw new PluginError('"output" option is required');
Expand All @@ -27,6 +16,10 @@ export async function generate(model: Model, options: PluginOptions, dmmf: DMMF.
outDir = path.join(path.dirname(options.schemaPath), outDir);
}

const project = new Project();
const warnings: string[] = [];
const models = model.declarations.filter((d): d is DataModel => isDataModel(d));

generateIndex(project, outDir, models);

models.forEach((model) => {
Expand All @@ -42,7 +35,7 @@ function wrapReadbackErrorCheck(code: string) {
return `try {
${code}
} catch (err: any) {
if (err.prisma && err.code === 'P2004') {
if (err.info?.prisma && err.info?.code === 'P2004') {
// 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.28",
"version": "1.0.0-alpha.31",
"description": "ZenStack plugin for tRPC",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/runtime/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/runtime",
"displayName": "ZenStack Runtime Library",
"version": "1.0.0-alpha.28",
"version": "1.0.0-alpha.31",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand Down
Loading