@zenstackhq/language 3.3.3 → 3.4.0-beta.2
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 +53 -16
- 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 +53 -16
- package/dist/index.js.map +1 -1
- package/package.json +15 -5
- package/res/stdlib.zmodel +3 -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,21 +7732,36 @@ 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.declarations.map((d) => this.generate(d)).join("\n\n")
|
|
7740
|
+
return `${ast.imports.map((d) => this.generate(d)).join("\n")}${ast.imports.length > 0 ? "\n\n" : ""}${ast.declarations.map((d) => this.generate(d)).join("\n\n")}`;
|
|
7734
7741
|
}
|
|
7735
7742
|
_generateDataSource(ast) {
|
|
7736
7743
|
return `datasource ${ast.name} {
|
|
7737
7744
|
${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
7738
7745
|
}`;
|
|
7739
7746
|
}
|
|
7747
|
+
_generateModelImport(ast) {
|
|
7748
|
+
return `import ${this.quotedStr(ast.path)}`;
|
|
7749
|
+
}
|
|
7740
7750
|
_generateEnum(ast) {
|
|
7741
|
-
|
|
7742
|
-
|
|
7751
|
+
const comments = `${ast.comments.join("\n")}
|
|
7752
|
+
`;
|
|
7753
|
+
return `${ast.comments.length > 0 ? comments : ""}enum ${ast.name} {
|
|
7754
|
+
${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
7755
|
}`;
|
|
7744
7756
|
}
|
|
7745
7757
|
_generateEnumField(ast) {
|
|
7746
|
-
|
|
7758
|
+
const fieldLine = `${ast.name}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7759
|
+
if (ast.comments.length === 0) {
|
|
7760
|
+
return fieldLine;
|
|
7761
|
+
}
|
|
7762
|
+
const commentLines = ast.comments.map((c, i) => i === 0 ? c : this.indent + c);
|
|
7763
|
+
return `${commentLines.join("\n")}
|
|
7764
|
+
${this.indent}${fieldLine}`;
|
|
7747
7765
|
}
|
|
7748
7766
|
_generateGenerator(ast) {
|
|
7749
7767
|
return `generator ${ast.name} {
|
|
@@ -7772,12 +7790,20 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}
|
|
|
7772
7790
|
return `${ast.name} = ${this.generate(ast.value)}`;
|
|
7773
7791
|
}
|
|
7774
7792
|
_generateDataModel(ast) {
|
|
7775
|
-
|
|
7793
|
+
const comments = `${ast.comments.join("\n")}
|
|
7794
|
+
`;
|
|
7795
|
+
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
7796
|
${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
7797
|
}`;
|
|
7778
7798
|
}
|
|
7779
7799
|
_generateDataField(ast) {
|
|
7780
|
-
|
|
7800
|
+
const fieldLine = `${ast.name} ${this.fieldType(ast.type)}${ast.attributes.length > 0 ? " " + ast.attributes.map((x) => this.generate(x)).join(" ") : ""}`;
|
|
7801
|
+
if (ast.comments.length === 0) {
|
|
7802
|
+
return fieldLine;
|
|
7803
|
+
}
|
|
7804
|
+
const commentLines = ast.comments.map((c, i) => i === 0 ? c : this.indent + c);
|
|
7805
|
+
return `${commentLines.join("\n")}
|
|
7806
|
+
${this.indent}${fieldLine}`;
|
|
7781
7807
|
}
|
|
7782
7808
|
fieldType(type) {
|
|
7783
7809
|
const baseType = type.type ? type.type : type.$type == "DataFieldType" && type.unsupported ? "Unsupported(" + this.generate(type.unsupported.value) + ")" : type.reference?.$refText;
|
|
@@ -7810,7 +7836,7 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attribu
|
|
|
7810
7836
|
return `[${ast.items.map((item) => this.generate(item)).join(", ")}]`;
|
|
7811
7837
|
}
|
|
7812
7838
|
_generateLiteralExpr(ast) {
|
|
7813
|
-
return this.
|
|
7839
|
+
return this.quotedStr(ast.value);
|
|
7814
7840
|
}
|
|
7815
7841
|
_generateNumberLiteral(ast) {
|
|
7816
7842
|
return ast.value.toString();
|
|
@@ -7834,7 +7860,7 @@ ${ast.fields.map((x) => this.indent + this.generate(x)).join("\n")}${ast.attribu
|
|
|
7834
7860
|
return `${ast.target.$refText}${args}`;
|
|
7835
7861
|
}
|
|
7836
7862
|
_generateReferenceArg(ast) {
|
|
7837
|
-
return `${ast.name}
|
|
7863
|
+
return `${ast.name}: ${this.generate(ast.value)}`;
|
|
7838
7864
|
}
|
|
7839
7865
|
_generateMemberExpr(ast) {
|
|
7840
7866
|
return `${this.generate(ast.operand)}.${ast.member.$refText}`;
|
|
@@ -7923,6 +7949,14 @@ _ts_decorate3([
|
|
|
7923
7949
|
]),
|
|
7924
7950
|
_ts_metadata3("design:returntype", void 0)
|
|
7925
7951
|
], ZModelCodeGenerator.prototype, "_generateDataSource", null);
|
|
7952
|
+
_ts_decorate3([
|
|
7953
|
+
gen(ModelImport),
|
|
7954
|
+
_ts_metadata3("design:type", Function),
|
|
7955
|
+
_ts_metadata3("design:paramtypes", [
|
|
7956
|
+
typeof ModelImport === "undefined" ? Object : ModelImport
|
|
7957
|
+
]),
|
|
7958
|
+
_ts_metadata3("design:returntype", void 0)
|
|
7959
|
+
], ZModelCodeGenerator.prototype, "_generateModelImport", null);
|
|
7926
7960
|
_ts_decorate3([
|
|
7927
7961
|
gen(Enum),
|
|
7928
7962
|
_ts_metadata3("design:type", Function),
|
|
@@ -9412,7 +9446,7 @@ function createZModelServices(logToConsole = false) {
|
|
|
9412
9446
|
__name(createZModelServices, "createZModelServices");
|
|
9413
9447
|
|
|
9414
9448
|
// src/document.ts
|
|
9415
|
-
async function loadDocument(fileName, additionalModelFiles = []) {
|
|
9449
|
+
async function loadDocument(fileName, additionalModelFiles = [], mergeImports = true) {
|
|
9416
9450
|
const { ZModelLanguage: services } = createZModelServices(false);
|
|
9417
9451
|
const extensions = services.LanguageMetaData.fileExtensions;
|
|
9418
9452
|
if (!extensions.includes(path4.extname(fileName))) {
|
|
@@ -9479,12 +9513,14 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
9479
9513
|
};
|
|
9480
9514
|
}
|
|
9481
9515
|
const model = document.parseResult.value;
|
|
9482
|
-
|
|
9483
|
-
|
|
9484
|
-
|
|
9485
|
-
|
|
9486
|
-
|
|
9487
|
-
|
|
9516
|
+
if (mergeImports) {
|
|
9517
|
+
const imported = mergeImportsDeclarations(langiumDocuments, model);
|
|
9518
|
+
imported.forEach((model2) => {
|
|
9519
|
+
langiumDocuments.deleteDocument(model2.$document.uri);
|
|
9520
|
+
services.shared.workspace.IndexManager.remove(model2.$document.uri);
|
|
9521
|
+
});
|
|
9522
|
+
}
|
|
9523
|
+
const additionalErrors = mergeImports === true ? validationAfterImportMerge(model) : [];
|
|
9488
9524
|
if (additionalErrors.length > 0) {
|
|
9489
9525
|
return {
|
|
9490
9526
|
success: false,
|
|
@@ -9495,6 +9531,7 @@ async function loadDocument(fileName, additionalModelFiles = []) {
|
|
|
9495
9531
|
return {
|
|
9496
9532
|
success: true,
|
|
9497
9533
|
model: document.parseResult.value,
|
|
9534
|
+
services,
|
|
9498
9535
|
warnings
|
|
9499
9536
|
};
|
|
9500
9537
|
}
|