Skip to content

Commit b5929d8

Browse files
authored
merge dev to main (v1.3.1) (#838)
2 parents e07b5dd + 9a0895b commit b5929d8

File tree

24 files changed

+698
-357
lines changed

24 files changed

+698
-357
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": "1.3.0",
3+
"version": "1.3.1",
44
"description": "",
55
"scripts": {
66
"build": "pnpm -r build",

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.3.0",
3+
"version": "1.3.1",
44
"displayName": "ZenStack modeling language compiler",
55
"description": "ZenStack modeling language compiler",
66
"homepage": "https://zenstack.dev",

packages/language/src/generated/grammar.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,8 @@ export const ZModelGrammar = (): Grammar => loadedZModelGrammar ?? (loadedZModel
665665
"rule": {
666666
"$ref": "#/rules@15"
667667
},
668-
"arguments": []
668+
"arguments": [],
669+
"cardinality": "?"
669670
},
670671
{
671672
"$type": "Keyword",

packages/language/src/zmodel.langium

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ ArrayExpr:
5151
'[' (items+=Expression (',' items+=Expression)*)? ']';
5252

5353
ConfigInvocationExpr:
54-
name=ID ('(' ConfigInvocationArgList ')')?;
54+
name=ID ('(' ConfigInvocationArgList? ')')?;
5555

5656
fragment ConfigInvocationArgList:
5757
args+=ConfigInvocationArg (',' args+=ConfigInvocationArg)*;
@@ -67,7 +67,6 @@ ConfigExpr:
6767
LiteralExpr | InvocationExpr | ConfigArrayExpr;
6868

6969
type ReferenceTarget = FunctionParam | DataModelField | EnumField;
70-
7170
ThisExpr:
7271
value=THIS;
7372

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

261260
type TypeDeclaration = DataModel | Enum;
262-
263261
DataModelFieldAttribute:
264262
decl=[Attribute:DataModelFieldAttributeName] ('(' AttributeArgList? ')')?;
265263

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": "1.3.0",
4+
"version": "1.3.1",
55
"description": "ZenStack plugin and runtime supporting OpenAPI",
66
"main": "index.js",
77
"repository": {

packages/plugins/swr/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/swr",
33
"displayName": "ZenStack plugin for generating SWR hooks",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"description": "ZenStack plugin for generating SWR hooks",
66
"main": "index.js",
77
"repository": {

packages/plugins/tanstack-query/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/tanstack-query",
33
"displayName": "ZenStack plugin for generating tanstack-query hooks",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"description": "ZenStack plugin for generating tanstack-query hooks",
66
"main": "index.js",
77
"exports": {

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.3.0",
4+
"version": "1.3.1",
55
"description": "ZenStack plugin for tRPC",
66
"main": "index.js",
77
"repository": {

packages/runtime/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@zenstackhq/runtime",
33
"displayName": "ZenStack Runtime Library",
4-
"version": "1.3.0",
4+
"version": "1.3.1",
55
"description": "Runtime of ZenStack for both client-side and server-side environments.",
66
"repository": {
77
"type": "git",

packages/schema/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"publisher": "zenstack",
44
"displayName": "ZenStack Language Tools",
55
"description": "Build scalable web apps with minimum code by defining authorization and validation rules inside the data schema that closer to the database",
6-
"version": "1.3.0",
6+
"version": "1.3.1",
77
"author": {
88
"name": "ZenStack Team"
99
},

packages/schema/src/cli/cli-util.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,13 @@ export async function getPluginDocuments(services: ZModelServices, fileName: str
161161
if (isPlugin(decl)) {
162162
const providerField = decl.fields.find((f) => f.name === 'provider');
163163
if (providerField) {
164-
const provider = getLiteral<string>(providerField.value);
164+
let provider = getLiteral<string>(providerField.value);
165165
if (provider) {
166166
try {
167+
if (provider.startsWith('.')) {
168+
// resolve relative path against the schema file
169+
provider = path.resolve(path.dirname(fileName), provider);
170+
}
167171
const pluginEntrance = require.resolve(`${provider}`);
168172
const pluginModelFile = path.join(path.dirname(pluginEntrance), PLUGIN_MODULE_NAME);
169173
if (fs.existsSync(pluginModelFile)) {

packages/schema/src/cli/plugin-runner.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,15 @@ export class PluginRunner {
5454
const plugins: PluginInfo[] = [];
5555
const pluginDecls = options.schema.declarations.filter((d): d is Plugin => isPlugin(d));
5656

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

5959
for (const pluginDecl of pluginDecls) {
6060
const pluginProvider = this.getPluginProvider(pluginDecl);
6161
if (!pluginProvider) {
6262
console.error(`Plugin ${pluginDecl.name} has invalid provider option`);
6363
throw new PluginError('', `Plugin ${pluginDecl.name} has invalid provider option`);
6464
}
65-
const pluginModulePath = this.getPluginModulePath(pluginProvider);
65+
const pluginModulePath = this.getPluginModulePath(pluginProvider, options);
6666
// eslint-disable-next-line @typescript-eslint/no-explicit-any
6767
let pluginModule: any;
6868
try {
@@ -117,7 +117,7 @@ export class PluginRunner {
117117
plugins.unshift(existing);
118118
} else {
119119
// synthesize a plugin and insert front
120-
const pluginModule = require(this.getPluginModulePath(corePlugin.provider));
120+
const pluginModule = require(this.getPluginModulePath(corePlugin.provider, options));
121121
const pluginName = this.getPluginName(pluginModule, corePlugin.provider);
122122
plugins.unshift({
123123
name: pluginName,
@@ -300,7 +300,10 @@ export class PluginRunner {
300300
}
301301
}
302302

303-
private getPluginModulePath(provider: string) {
303+
private getPluginModulePath(provider: string, options: Pick<PluginOptions, 'schemaPath'>) {
304+
if (path.isAbsolute(provider) || provider.startsWith('.')) {
305+
return resolvePath(provider, options);
306+
}
304307
let pluginModulePath = provider;
305308
if (pluginModulePath.startsWith('@core/')) {
306309
pluginModulePath = pluginModulePath.replace(/^@core/, path.join(__dirname, '../plugins'));

packages/schema/src/plugins/prisma/schema-generator.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ import {
6262
PassThroughAttribute as PrismaPassThroughAttribute,
6363
SimpleField,
6464
} from './prisma-builder';
65-
import ZModelCodeGenerator from './zmodel-code-generator';
65+
import { ZModelCodeGenerator } from '@zenstackhq/sdk';
6666

6767
const MODEL_PASSTHROUGH_ATTR = '@@prisma.passthrough';
6868
const FIELD_PASSTHROUGH_ATTR = '@prisma.passthrough';
@@ -266,7 +266,7 @@ export default class PrismaSchemaGenerator {
266266

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

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

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

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

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

@@ -413,7 +413,7 @@ export default class PrismaSchemaGenerator {
413413

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

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

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

429-
const documentations = nonPrismaAttributes.map((attr) => '/// ' + this.zModelGenerator.generateAttribute(attr));
429+
const documentations = nonPrismaAttributes.map((attr) => '/// ' + this.zModelGenerator.generate(attr));
430430
_enum.addField(field.name, attributes, documentations);
431431
}
432432
}

packages/schema/src/plugins/prisma/zmodel-code-generator.ts

Lines changed: 0 additions & 177 deletions
This file was deleted.

0 commit comments

Comments
 (0)