@zenstackhq/language 3.3.2 → 3.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/factory.cjs +2087 -0
- package/dist/factory.cjs.map +1 -0
- package/dist/factory.d.cts +284 -0
- package/dist/factory.d.ts +284 -0
- package/dist/factory.js +2020 -0
- package/dist/factory.js.map +1 -0
- package/dist/index.cjs +47 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +22 -18
- package/dist/index.d.ts +22 -18
- package/dist/index.js +47 -14
- package/dist/index.js.map +1 -1
- package/package.json +15 -5
- package/res/stdlib.zmodel +24 -3
package/dist/index.d.cts
CHANGED
|
@@ -2,24 +2,6 @@ import { Model, DataSource, GeneratorDecl, DataModel, TypeDef, Enum, Attribute,
|
|
|
2
2
|
import { ValidationAcceptor, Module, DeepPartial, AstNode } from 'langium';
|
|
3
3
|
import { LangiumServices, PartialLangiumServices, LangiumSharedServices, DefaultSharedModuleContext } from 'langium/lsp';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Loads ZModel document from the given file name. Include the additional document
|
|
7
|
-
* files if given.
|
|
8
|
-
*/
|
|
9
|
-
declare function loadDocument(fileName: string, additionalModelFiles?: string[]): Promise<{
|
|
10
|
-
success: true;
|
|
11
|
-
model: Model;
|
|
12
|
-
warnings: string[];
|
|
13
|
-
} | {
|
|
14
|
-
success: false;
|
|
15
|
-
errors: string[];
|
|
16
|
-
warnings: string[];
|
|
17
|
-
}>;
|
|
18
|
-
/**
|
|
19
|
-
* Formats the given ZModel content.
|
|
20
|
-
*/
|
|
21
|
-
declare function formatDocument(content: string): Promise<string>;
|
|
22
|
-
|
|
23
5
|
/******************************************************************************
|
|
24
6
|
* This file was generated by langium-cli 3.5.0.
|
|
25
7
|
* DO NOT EDIT MANUALLY!
|
|
@@ -96,6 +78,25 @@ declare function createZModelServices(logToConsole?: boolean): {
|
|
|
96
78
|
ZModelLanguage: ZModelServices;
|
|
97
79
|
};
|
|
98
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Loads ZModel document from the given file name. Include the additional document
|
|
83
|
+
* files if given.
|
|
84
|
+
*/
|
|
85
|
+
declare function loadDocument(fileName: string, additionalModelFiles?: string[], mergeImports?: boolean): Promise<{
|
|
86
|
+
success: true;
|
|
87
|
+
model: Model;
|
|
88
|
+
warnings: string[];
|
|
89
|
+
services: ZModelServices;
|
|
90
|
+
} | {
|
|
91
|
+
success: false;
|
|
92
|
+
errors: string[];
|
|
93
|
+
warnings: string[];
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Formats the given ZModel content.
|
|
97
|
+
*/
|
|
98
|
+
declare function formatDocument(content: string): Promise<string>;
|
|
99
|
+
|
|
99
100
|
/**
|
|
100
101
|
* Options for the generator.
|
|
101
102
|
*/
|
|
@@ -110,13 +111,16 @@ interface ZModelCodeOptions {
|
|
|
110
111
|
*/
|
|
111
112
|
declare class ZModelCodeGenerator {
|
|
112
113
|
private readonly options;
|
|
114
|
+
private readonly quote;
|
|
113
115
|
constructor(options?: Partial<ZModelCodeOptions>);
|
|
114
116
|
/**
|
|
115
117
|
* Generates ZModel source code from AST.
|
|
116
118
|
*/
|
|
117
119
|
generate(ast: AstNode): string;
|
|
120
|
+
private quotedStr;
|
|
118
121
|
private _generateModel;
|
|
119
122
|
private _generateDataSource;
|
|
123
|
+
private _generateModelImport;
|
|
120
124
|
private _generateEnum;
|
|
121
125
|
private _generateEnumField;
|
|
122
126
|
private _generateGenerator;
|
package/dist/index.d.ts
CHANGED
|
@@ -2,24 +2,6 @@ import { Model, DataSource, GeneratorDecl, DataModel, TypeDef, Enum, Attribute,
|
|
|
2
2
|
import { ValidationAcceptor, Module, DeepPartial, AstNode } from 'langium';
|
|
3
3
|
import { LangiumServices, PartialLangiumServices, LangiumSharedServices, DefaultSharedModuleContext } from 'langium/lsp';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* Loads ZModel document from the given file name. Include the additional document
|
|
7
|
-
* files if given.
|
|
8
|
-
*/
|
|
9
|
-
declare function loadDocument(fileName: string, additionalModelFiles?: string[]): Promise<{
|
|
10
|
-
success: true;
|
|
11
|
-
model: Model;
|
|
12
|
-
warnings: string[];
|
|
13
|
-
} | {
|
|
14
|
-
success: false;
|
|
15
|
-
errors: string[];
|
|
16
|
-
warnings: string[];
|
|
17
|
-
}>;
|
|
18
|
-
/**
|
|
19
|
-
* Formats the given ZModel content.
|
|
20
|
-
*/
|
|
21
|
-
declare function formatDocument(content: string): Promise<string>;
|
|
22
|
-
|
|
23
5
|
/******************************************************************************
|
|
24
6
|
* This file was generated by langium-cli 3.5.0.
|
|
25
7
|
* DO NOT EDIT MANUALLY!
|
|
@@ -96,6 +78,25 @@ declare function createZModelServices(logToConsole?: boolean): {
|
|
|
96
78
|
ZModelLanguage: ZModelServices;
|
|
97
79
|
};
|
|
98
80
|
|
|
81
|
+
/**
|
|
82
|
+
* Loads ZModel document from the given file name. Include the additional document
|
|
83
|
+
* files if given.
|
|
84
|
+
*/
|
|
85
|
+
declare function loadDocument(fileName: string, additionalModelFiles?: string[], mergeImports?: boolean): Promise<{
|
|
86
|
+
success: true;
|
|
87
|
+
model: Model;
|
|
88
|
+
warnings: string[];
|
|
89
|
+
services: ZModelServices;
|
|
90
|
+
} | {
|
|
91
|
+
success: false;
|
|
92
|
+
errors: string[];
|
|
93
|
+
warnings: string[];
|
|
94
|
+
}>;
|
|
95
|
+
/**
|
|
96
|
+
* Formats the given ZModel content.
|
|
97
|
+
*/
|
|
98
|
+
declare function formatDocument(content: string): Promise<string>;
|
|
99
|
+
|
|
99
100
|
/**
|
|
100
101
|
* Options for the generator.
|
|
101
102
|
*/
|
|
@@ -110,13 +111,16 @@ interface ZModelCodeOptions {
|
|
|
110
111
|
*/
|
|
111
112
|
declare class ZModelCodeGenerator {
|
|
112
113
|
private readonly options;
|
|
114
|
+
private readonly quote;
|
|
113
115
|
constructor(options?: Partial<ZModelCodeOptions>);
|
|
114
116
|
/**
|
|
115
117
|
* Generates ZModel source code from AST.
|
|
116
118
|
*/
|
|
117
119
|
generate(ast: AstNode): string;
|
|
120
|
+
private quotedStr;
|
|
118
121
|
private _generateModel;
|
|
119
122
|
private _generateDataSource;
|
|
123
|
+
private _generateModelImport;
|
|
120
124
|
private _generateEnum;
|
|
121
125
|
private _generateEnumField;
|
|
122
126
|
private _generateGenerator;
|
package/dist/index.js
CHANGED
|
@@ -6421,7 +6421,8 @@ var DataModelValidator = class {
|
|
|
6421
6421
|
const uniqueFields = allFields.filter((f) => f.attributes.find((attr) => attr.decl.ref?.name === "@unique"));
|
|
6422
6422
|
const modelLevelIds = getModelIdFields(dm);
|
|
6423
6423
|
const modelUniqueFields = getModelUniqueFields(dm);
|
|
6424
|
-
|
|
6424
|
+
const ignore = hasAttribute(dm, "@@ignore");
|
|
6425
|
+
if (!dm.isView && idFields.length === 0 && modelLevelIds.length === 0 && uniqueFields.length === 0 && modelUniqueFields.length === 0 && !ignore) {
|
|
6425
6426
|
accept("error", "Model must have at least one unique criteria. Either mark a single field with `@id`, `@unique` or add a multi field criterion with `@@id([])` or `@@unique([])` to the model.", {
|
|
6426
6427
|
node: dm
|
|
6427
6428
|
});
|
|
@@ -7711,6 +7712,7 @@ var ZModelCodeGenerator = class {
|
|
|
7711
7712
|
__name(this, "ZModelCodeGenerator");
|
|
7712
7713
|
}
|
|
7713
7714
|
options;
|
|
7715
|
+
quote;
|
|
7714
7716
|
constructor(options) {
|
|
7715
7717
|
this.options = {
|
|
7716
7718
|
binaryExprNumberOfSpaces: options?.binaryExprNumberOfSpaces ?? 1,
|
|
@@ -7718,6 +7720,7 @@ var ZModelCodeGenerator = class {
|
|
|
7718
7720
|
indent: options?.indent ?? 4,
|
|
7719
7721
|
quote: options?.quote ?? "single"
|
|
7720
7722
|
};
|
|
7723
|
+
this.quote = this.options.quote === "double" ? '"' : "'";
|
|
7721
7724
|
}
|
|
7722
7725
|
/**
|
|
7723
7726
|
* Generates ZModel source code from AST.
|
|
@@ -7729,17 +7732,28 @@ var ZModelCodeGenerator = class {
|
|
|
7729
7732
|
}
|
|
7730
7733
|
return handler.value.call(this, ast);
|
|
7731
7734
|
}
|
|
7735
|
+
quotedStr(val) {
|
|
7736
|
+
const trimmedVal = val.replace(new RegExp(`(?<!\\\\)${this.quote}`, "g"), `\\${this.quote}`);
|
|
7737
|
+
return `${this.quote}${trimmedVal}${this.quote}`;
|
|
7738
|
+
}
|
|
7732
7739
|
_generateModel(ast) {
|
|
7733
|
-
return ast.
|
|
7740
|
+
return `${ast.imports.map((d) => this.generate(d)).join("\n")}${ast.imports.length > 0 ? "\n\n" : ""}${ast.declarations.sort((a, b) => {
|
|
7741
|
+
if (a.$type === "Enum" && b.$type !== "Enum") return 1;
|
|
7742
|
+
if (a.$type !== "Enum" && b.$type === "Enum") return -1;
|
|
7743
|
+
return 0;
|
|
7744
|
+
}).map((d) => this.generate(d)).join("\n\n")}`;
|
|
7734
7745
|
}
|
|
7735
7746
|
_generateDataSource(ast) {
|
|
7736
7747
|
return `datasource ${ast.name} {
|
|
7737
7748
|
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7738
7749
|
}`;
|
|
7739
7750
|
}
|
|
7751
|
+
_generateModelImport(ast) {
|
|
7752
|
+
return `import ${this.quotedStr(ast.path)}`;
|
|
7753
|
+
}
|
|
7740
7754
|
_generateEnum(ast) {
|
|
7741
7755
|
return `enum ${ast.name} {
|
|
7742
|
-
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7756
|
+
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
7743
7757
|
}`;
|
|
7744
7758
|
}
|
|
7745
7759
|
_generateEnumField(ast) {
|
|
@@ -7772,12 +7786,20 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
|
7772
7786
|
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7773
7787
|
}
|
|
7774
7788
|
_generateDataModel(ast) {
|
|
7775
|
-
|
|
7789
|
+
const comments = `${ast.comments.join("\n")}
|
|
7790
|
+
`;
|
|
7791
|
+
return `${ast.comments.length > 0 ? comments : ""}${ast.isView ? "view" : "model"} ${ast.name}${ast.mixins.length > 0 ? " with " + ast.mixins.map((x) => x.$refText).join(", ") : ""} {
|
|
7776
7792
|
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attributes.length > 0 ? "\n\n" + ast.attributes.map((x) => this.indent + this.generate(x)).join("\n") : ""}
|
|
7777
7793
|
}`;
|
|
7778
7794
|
}
|
|
7779
7795
|
_generateDataField(ast) {
|
|
7780
|
-
|
|
7796
|
+
const fieldLine = `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7797
|
+
if (ast.comments.length === 0) {
|
|
7798
|
+
return fieldLine;
|
|
7799
|
+
}
|
|
7800
|
+
const commentLines = ast.comments.map((c, i) => i === 0 ? c : this.indent + c);
|
|
7801
|
+
return `${commentLines.join("\n")}
|
|
7802
|
+
${this.indent}${fieldLine}`;
|
|
7781
7803
|
}
|
|
7782
7804
|
fieldType(type) {
|
|
7783
7805
|
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
@@ -7810,7 +7832,7 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attribu
|
|
|
7810
7832
|
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
7811
7833
|
}
|
|
7812
7834
|
_generateLiteralExpr(ast) {
|
|
7813
|
-
return this.
|
|
7835
|
+
return this.quotedStr(ast.value);
|
|
7814
7836
|
}
|
|
7815
7837
|
_generateNumberLiteral(ast) {
|
|
7816
7838
|
return ast.value.toString();
|
|
@@ -7834,7 +7856,7 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attribu
|
|
|
7834
7856
|
return `${ast.target.$refText}${args}`;
|
|
7835
7857
|
}
|
|
7836
7858
|
_generateReferenceArg(ast) {
|
|
7837
|
-
return `${ast.name}
|
|
7859
|
+
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
7838
7860
|
}
|
|
7839
7861
|
_generateMemberExpr(ast) {
|
|
7840
7862
|
return `${this.generate(ast.operand)}.${ast.member.$refText}`;
|
|
@@ -7923,6 +7945,14 @@ _ts_decorate3([
|
|
|
7923
7945
|
]),
|
|
7924
7946
|
_ts_metadata3("design:returntype", void 0)
|
|
7925
7947
|
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
7948
|
+
_ts_decorate3([
|
|
7949
|
+
gen(ModelImport),
|
|
7950
|
+
_ts_metadata3("design:type", Function),
|
|
7951
|
+
_ts_metadata3("design:paramtypes", [
|
|
7952
|
+
typeof ModelImport === "undefined" ? Object : ModelImport
|
|
7953
|
+
]),
|
|
7954
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7955
|
+
], ZModelCodeGenerator.prototype, "_generateModelImport", null);
|
|
7926
7956
|
_ts_decorate3([
|
|
7927
7957
|
gen(Enum),
|
|
7928
7958
|
_ts_metadata3("design:type", Function),
|
|
@@ -9412,7 +9442,7 @@ function createZModelServices(logToConsole = false) {
|
|
|
9412
9442
|
__name(createZModelServices, "createZModelServices");
|
|
9413
9443
|
|
|
9414
9444
|
// src/document.ts
|
|
9415
|
-
async function loadDocument(fileName, additionalModelFiles = []) {
|
|
9445
|
+
async function loadDocument(fileName, additionalModelFiles = [], mergeImports = true) {
|
|
9416
9446
|
const { ZModelLanguage: services } = createZModelServices(false);
|
|
9417
9447
|
const extensions = services.LanguageMetaData.fileExtensions;
|
|
9418
9448
|
if (!extensions.includes(path4.extname(fileName))) {
|
|
@@ -9479,12 +9509,14 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
9479
9509
|
};
|
|
9480
9510
|
}
|
|
9481
9511
|
const model = document.parseResult.value;
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9512
|
+
if (mergeImports) {
|
|
9513
|
+
const imported = mergeImportsDeclarations(langiumDocuments, model);
|
|
9514
|
+
imported.forEach((model2) => {
|
|
9515
|
+
langiumDocuments.deleteDocument(model2.$document.uri);
|
|
9516
|
+
services.shared.workspace.IndexManager.remove(model2.$document.uri);
|
|
9517
|
+
});
|
|
9518
|
+
}
|
|
9519
|
+
const additionalErrors = mergeImports === true ? validationAfterImportMerge(model) : [];
|
|
9488
9520
|
if (additionalErrors.length > 0) {
|
|
9489
9521
|
return {
|
|
9490
9522
|
success: false,
|
|
@@ -9495,6 +9527,7 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
9495
9527
|
return {
|
|
9496
9528
|
success: true,
|
|
9497
9529
|
model: document.parseResult.value,
|
|
9530
|
+
services,
|
|
9498
9531
|
warnings
|
|
9499
9532
|
};
|
|
9500
9533
|
}
|