Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

merge dev to main (v1.3.1) #838

Merged
merged 3 commits into from
Nov 17, 2023
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.3.0",
"version": "1.3.1",
"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.3.0",
"version": "1.3.1",
"displayName": "ZenStack modeling language compiler",
"description": "ZenStack modeling language compiler",
"homepage": "https://zenstack.dev",
Expand Down
3 changes: 2 additions & 1 deletion packages/language/src/generated/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
"rule": {
"$ref": "#/rules@15"
},
"arguments": []
"arguments": [],
"cardinality": "?"
},
{
"$type": "Keyword",
Expand Down
4 changes: 1 addition & 3 deletions packages/language/src/zmodel.langium
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ ArrayExpr:
'[' (items+=Expression (',' items+=Expression)*)? ']';

ConfigInvocationExpr:
name=ID ('(' ConfigInvocationArgList ')')?;
name=ID ('(' ConfigInvocationArgList? ')')?;

fragment ConfigInvocationArgList:
args+=ConfigInvocationArg (',' args+=ConfigInvocationArg)*;
Expand All @@ -67,7 +67,6 @@ ConfigExpr:
LiteralExpr | InvocationExpr | ConfigArrayExpr;

type ReferenceTarget = FunctionParam | DataModelField | EnumField;

ThisExpr:
value=THIS;

Expand Down Expand Up @@ -259,7 +258,6 @@ AttributeParamType:
(type=(ExpressionType | 'FieldReference' | 'TransitiveFieldReference' | 'ContextType') | reference=[TypeDeclaration:RegularID]) (array?='[' ']')? (optional?='?')?;

type TypeDeclaration = DataModel | Enum;

DataModelFieldAttribute:
decl=[Attribute:DataModelFieldAttributeName] ('(' AttributeArgList? ')')?;

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": "1.3.0",
"version": "1.3.1",
"description": "ZenStack plugin and runtime supporting OpenAPI",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/swr/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/swr",
"displayName": "ZenStack plugin for generating SWR hooks",
"version": "1.3.0",
"version": "1.3.1",
"description": "ZenStack plugin for generating SWR hooks",
"main": "index.js",
"repository": {
Expand Down
2 changes: 1 addition & 1 deletion packages/plugins/tanstack-query/package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@zenstackhq/tanstack-query",
"displayName": "ZenStack plugin for generating tanstack-query hooks",
"version": "1.3.0",
"version": "1.3.1",
"description": "ZenStack plugin for generating tanstack-query hooks",
"main": "index.js",
"exports": {
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.3.0",
"version": "1.3.1",
"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.3.0",
"version": "1.3.1",
"description": "Runtime of ZenStack for both client-side and server-side environments.",
"repository": {
"type": "git",
Expand Down
2 changes: 1 addition & 1 deletion packages/schema/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"publisher": "zenstack",
"displayName": "ZenStack Language Tools",
"description": "Build scalable web apps with minimum code by defining authorization and validation rules inside the data schema that closer to the database",
"version": "1.3.0",
"version": "1.3.1",
"author": {
"name": "ZenStack Team"
},
Expand Down
6 changes: 5 additions & 1 deletion packages/schema/src/cli/cli-util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,13 @@ export async function getPluginDocuments(services: ZModelServices, fileName: str
if (isPlugin(decl)) {
const providerField = decl.fields.find((f) => f.name === 'provider');
if (providerField) {
const provider = getLiteral<string>(providerField.value);
let provider = getLiteral<string>(providerField.value);
if (provider) {
try {
if (provider.startsWith('.')) {
// resolve relative path against the schema file
provider = path.resolve(path.dirname(fileName), provider);
}
const pluginEntrance = require.resolve(`${provider}`);
const pluginModelFile = path.join(path.dirname(pluginEntrance), PLUGIN_MODULE_NAME);
if (fs.existsSync(pluginModelFile)) {
Expand Down
11 changes: 7 additions & 4 deletions packages/schema/src/cli/plugin-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ export class PluginRunner {
const plugins: PluginInfo[] = [];
const pluginDecls = options.schema.declarations.filter((d): d is Plugin => isPlugin(d));

let prismaOutput = resolvePath('./prisma/schema.prisma', { schemaPath: options.schemaPath, name: '' });
let prismaOutput = resolvePath('./prisma/schema.prisma', { schemaPath: options.schemaPath });

for (const pluginDecl of pluginDecls) {
const pluginProvider = this.getPluginProvider(pluginDecl);
if (!pluginProvider) {
console.error(`Plugin ${pluginDecl.name} has invalid provider option`);
throw new PluginError('', `Plugin ${pluginDecl.name} has invalid provider option`);
}
const pluginModulePath = this.getPluginModulePath(pluginProvider);
const pluginModulePath = this.getPluginModulePath(pluginProvider, options);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
let pluginModule: any;
try {
Expand Down Expand Up @@ -117,7 +117,7 @@ export class PluginRunner {
plugins.unshift(existing);
} else {
// synthesize a plugin and insert front
const pluginModule = require(this.getPluginModulePath(corePlugin.provider));
const pluginModule = require(this.getPluginModulePath(corePlugin.provider, options));
const pluginName = this.getPluginName(pluginModule, corePlugin.provider);
plugins.unshift({
name: pluginName,
Expand Down Expand Up @@ -300,7 +300,10 @@ export class PluginRunner {
}
}

private getPluginModulePath(provider: string) {
private getPluginModulePath(provider: string, options: Pick<PluginOptions, 'schemaPath'>) {
if (path.isAbsolute(provider) || provider.startsWith('.')) {
return resolvePath(provider, options);
}
let pluginModulePath = provider;
if (pluginModulePath.startsWith('@core/')) {
pluginModulePath = pluginModulePath.replace(/^@core/, path.join(__dirname, '../plugins'));
Expand Down
10 changes: 5 additions & 5 deletions packages/schema/src/plugins/prisma/schema-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ import {
PassThroughAttribute as PrismaPassThroughAttribute,
SimpleField,
} from './prisma-builder';
import ZModelCodeGenerator from './zmodel-code-generator';
import { ZModelCodeGenerator } from '@zenstackhq/sdk';

const MODEL_PASSTHROUGH_ATTR = '@@prisma.passthrough';
const FIELD_PASSTHROUGH_ATTR = '@prisma.passthrough';
Expand Down Expand Up @@ -266,7 +266,7 @@ export default class PrismaSchemaGenerator {

decl.attributes
.filter((attr) => attr.decl.ref && !this.isPrismaAttribute(attr))
.forEach((attr) => model.addComment('/// ' + this.zModelGenerator.generateAttribute(attr)));
.forEach((attr) => model.addComment('/// ' + this.zModelGenerator.generate(attr)));

// user defined comments pass-through
decl.comments.forEach((c) => model.addComment(c));
Expand Down Expand Up @@ -313,7 +313,7 @@ export default class PrismaSchemaGenerator {

const nonPrismaAttributes = field.attributes.filter((attr) => attr.decl.ref && !this.isPrismaAttribute(attr));

const documentations = nonPrismaAttributes.map((attr) => '/// ' + this.zModelGenerator.generateAttribute(attr));
const documentations = nonPrismaAttributes.map((attr) => '/// ' + this.zModelGenerator.generate(attr));

const result = model.addField(field.name, type, attributes, documentations);

Expand Down Expand Up @@ -413,7 +413,7 @@ export default class PrismaSchemaGenerator {

decl.attributes
.filter((attr) => attr.decl.ref && !this.isPrismaAttribute(attr))
.forEach((attr) => _enum.addComment('/// ' + this.zModelGenerator.generateAttribute(attr)));
.forEach((attr) => _enum.addComment('/// ' + this.zModelGenerator.generate(attr)));

// user defined comments pass-through
decl.comments.forEach((c) => _enum.addComment(c));
Expand All @@ -426,7 +426,7 @@ export default class PrismaSchemaGenerator {

const nonPrismaAttributes = field.attributes.filter((attr) => attr.decl.ref && !this.isPrismaAttribute(attr));

const documentations = nonPrismaAttributes.map((attr) => '/// ' + this.zModelGenerator.generateAttribute(attr));
const documentations = nonPrismaAttributes.map((attr) => '/// ' + this.zModelGenerator.generate(attr));
_enum.addField(field.name, attributes, documentations);
}
}
177 changes: 0 additions & 177 deletions packages/schema/src/plugins/prisma/zmodel-code-generator.ts

This file was deleted.

Loading