zenstack 0.1.45 → 0.1.47
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/out/cli/index.js +4 -1
- package/out/cli/index.js.map +1 -1
- package/out/generator/prisma/expression-writer.js +2 -2
- package/out/generator/prisma/expression-writer.js.map +1 -1
- package/out/generator/prisma/prisma-builder.js +2 -2
- package/out/generator/prisma/prisma-builder.js.map +1 -1
- package/out/generator/prisma/query-gard-generator.js +1 -1
- package/out/generator/prisma/query-gard-generator.js.map +1 -1
- package/out/generator/prisma/schema-generator.js +9 -17
- package/out/generator/prisma/schema-generator.js.map +1 -1
- package/out/generator/utils.js +1 -1
- package/out/generator/utils.js.map +1 -1
- package/out/langium-ext.js +3 -0
- package/out/langium-ext.js.map +1 -0
- package/out/language-server/constants.js +20 -0
- package/out/language-server/constants.js.map +1 -0
- package/out/language-server/generated/ast.js +7 -3
- package/out/language-server/generated/ast.js.map +1 -1
- package/out/language-server/generated/grammar.js +312 -113
- package/out/language-server/generated/grammar.js.map +1 -1
- package/out/language-server/generated/module.js +1 -1
- package/out/language-server/langium-ext.js +3 -0
- package/out/language-server/langium-ext.js.map +1 -0
- package/out/language-server/main.js +4 -3
- package/out/language-server/main.js.map +1 -1
- package/out/language-server/stdlib.zmodel +18 -17
- package/out/language-server/validator/attribute-validator copy.js +12 -0
- package/out/language-server/validator/attribute-validator copy.js.map +1 -0
- package/out/language-server/validator/attribute-validator.js +7 -0
- package/out/language-server/validator/attribute-validator.js.map +1 -0
- package/out/language-server/validator/datamodel-validator.js +199 -0
- package/out/language-server/validator/datamodel-validator.js.map +1 -0
- package/out/language-server/validator/datasource-validator copy.js +77 -0
- package/out/language-server/validator/datasource-validator copy.js.map +1 -0
- package/out/language-server/validator/datasource-validator.js +77 -0
- package/out/language-server/validator/datasource-validator.js.map +1 -0
- package/out/language-server/validator/enum-validator.js +10 -0
- package/out/language-server/validator/enum-validator.js.map +1 -0
- package/out/language-server/validator/model-validator.js +21 -0
- package/out/language-server/validator/model-validator.js.map +1 -0
- package/out/language-server/validator/schema-validator.js +21 -0
- package/out/language-server/validator/schema-validator.js.map +1 -0
- package/out/language-server/validator/utils.js +106 -0
- package/out/language-server/validator/utils.js.map +1 -0
- package/out/language-server/validator/zmodel-validator.js +52 -0
- package/out/language-server/validator/zmodel-validator.js.map +1 -0
- package/out/language-server/zmodel-index.js +0 -27
- package/out/language-server/zmodel-index.js.map +1 -1
- package/out/language-server/zmodel-linker.js +15 -7
- package/out/language-server/zmodel-linker.js.map +1 -1
- package/out/language-server/zmodel-module.js +1 -6
- package/out/language-server/zmodel-module.js.map +1 -1
- package/out/language-server/zmodel-scope.js +16 -5
- package/out/language-server/zmodel-scope.js.map +1 -1
- package/out/language-server/zmodel-validator.js +11 -1
- package/out/language-server/zmodel-validator.js.map +1 -1
- package/package.json +22 -19
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../../../src/language-server/generated/grammar.ts"],"names":[],"mappings":";AAAA;;;gFAGgF;;;AAEhF,
|
|
1
|
+
{"version":3,"file":"grammar.js","sourceRoot":"","sources":["../../../src/language-server/generated/grammar.ts"],"names":[],"mappings":";AAAA;;;gFAGgF;;;AAEhF,qCAAuD;AAEvD,IAAI,mBAAwC,CAAC;AACtC,MAAM,aAAa,GAAG,GAAY,EAAE,CAAC,mBAAmB,aAAnB,mBAAmB,cAAnB,mBAAmB,GAAI,CAAC,mBAAmB,GAAG,IAAA,6BAAmB,EAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA40E5G,CAAC,CAAC,CAAC;AA50EQ,QAAA,aAAa,iBA40ErB"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/******************************************************************************
|
|
3
|
-
* This file was generated by langium-cli 0.
|
|
3
|
+
* This file was generated by langium-cli 0.5.0.
|
|
4
4
|
* DO NOT EDIT MANUALLY!
|
|
5
5
|
******************************************************************************/
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"langium-ext.js","sourceRoot":"","sources":["../../src/language-server/langium-ext.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const langium_1 = require("langium");
|
|
4
|
-
const node_1 = require("
|
|
4
|
+
const node_1 = require("langium/node");
|
|
5
|
+
const node_2 = require("vscode-languageserver/node");
|
|
5
6
|
const zmodel_module_1 = require("./zmodel-module");
|
|
6
7
|
// Create a connection to the client
|
|
7
|
-
const connection = (0,
|
|
8
|
+
const connection = (0, node_2.createConnection)(node_2.ProposedFeatures.all);
|
|
8
9
|
// Inject the shared services and language-specific services
|
|
9
|
-
const { shared } = (0, zmodel_module_1.createZModelServices)({ connection });
|
|
10
|
+
const { shared } = (0, zmodel_module_1.createZModelServices)(Object.assign({ connection }, node_1.NodeFileSystem));
|
|
10
11
|
// Start the language server with the shared services
|
|
11
12
|
(0, langium_1.startLanguageServer)(shared);
|
|
12
13
|
//# sourceMappingURL=main.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/language-server/main.ts"],"names":[],"mappings":";;AAAA,qCAA8C;AAC9C,qDAAgF;AAChF,mDAAuD;AAEvD,oCAAoC;AACpC,MAAM,UAAU,GAAG,IAAA,uBAAgB,EAAC,uBAAgB,CAAC,GAAG,CAAC,CAAC;AAE1D,4DAA4D;AAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,oCAAoB,
|
|
1
|
+
{"version":3,"file":"main.js","sourceRoot":"","sources":["../../src/language-server/main.ts"],"names":[],"mappings":";;AAAA,qCAA8C;AAC9C,uCAA8C;AAC9C,qDAAgF;AAChF,mDAAuD;AAEvD,oCAAoC;AACpC,MAAM,UAAU,GAAG,IAAA,uBAAgB,EAAC,uBAAgB,CAAC,GAAG,CAAC,CAAC;AAE1D,4DAA4D;AAC5D,MAAM,EAAE,MAAM,EAAE,GAAG,IAAA,oCAAoB,kBAAG,UAAU,IAAK,qBAAc,EAAG,CAAC;AAE3E,qDAAqD;AACrD,IAAA,6BAAmB,EAAC,MAAM,CAAC,CAAC"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
enum
|
|
1
|
+
enum ReferentialAction {
|
|
2
2
|
Cascade
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
function env() String {}
|
|
6
|
-
function auth() User {}
|
|
7
|
-
function now() DateTime {}
|
|
8
|
-
function uuid() String {}
|
|
9
|
-
function cuid() String {}
|
|
5
|
+
function env(): String {}
|
|
6
|
+
function auth(): User {}
|
|
7
|
+
function now(): DateTime {}
|
|
8
|
+
function uuid(): String {}
|
|
9
|
+
function cuid(): String {}
|
|
10
10
|
function autoincrement() Int {}
|
|
11
11
|
|
|
12
|
-
attribute id()
|
|
13
|
-
attribute
|
|
14
|
-
attribute
|
|
15
|
-
attribute
|
|
16
|
-
attribute
|
|
17
|
-
attribute
|
|
18
|
-
attribute
|
|
19
|
-
attribute
|
|
20
|
-
attribute
|
|
21
|
-
|
|
22
|
-
attribute
|
|
12
|
+
attribute @id(map: String?)
|
|
13
|
+
attribute @default(_ value: ContextType)
|
|
14
|
+
attribute @unique(map: String?)
|
|
15
|
+
attribute @@unique(_ fields: FieldReference[], name: String?, map: String?)
|
|
16
|
+
attribute @@index(_ fields: FieldReference[], map: String?)
|
|
17
|
+
attribute @relation(_ name: String?, fields: FieldReference[]?, references: FieldReference[]?, onDelete: ReferentialAction?, onUpdate: ReferentialAction?, map: String?)
|
|
18
|
+
attribute @map(_ name: String)
|
|
19
|
+
attribute @@map(_ name: String)
|
|
20
|
+
attribute @updatedAt()
|
|
21
|
+
|
|
22
|
+
attribute @@allow(_ operation: String, _ condition: Boolean)
|
|
23
|
+
attribute @@deny(_ operation: String, _ condition: Boolean)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
class AttributeValidator {
|
|
4
|
+
validate(attr, accept) {
|
|
5
|
+
const defaultParams = attr.params.filter((p) => p.default);
|
|
6
|
+
if (defaultParams.length > 1) {
|
|
7
|
+
accept('error', 'Attribute can declare at most one default parameter', { node: defaultParams[1] });
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.default = AttributeValidator;
|
|
12
|
+
//# sourceMappingURL=attribute-validator%20copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-validator copy.js","sourceRoot":"","sources":["../../../src/language-server/validator/attribute-validator copy.ts"],"names":[],"mappings":";;AAIA,MAAqB,kBAAkB;IACnC,QAAQ,CAAC,IAAe,EAAE,MAA0B;QAChD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QAC3D,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE;YAC1B,MAAM,CACF,OAAO,EACP,qDAAqD,EACrD,EAAE,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,CAC7B,CAAC;SACL;IACL,CAAC;CACJ;AAXD,qCAWC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"attribute-validator.js","sourceRoot":"","sources":["../../../src/language-server/validator/attribute-validator.ts"],"names":[],"mappings":";;AAIA,MAAqB,kBAAkB;IACnC,QAAQ,CAAC,IAAe,EAAE,MAA0B,IAAG,CAAC;CAC3D;AAFD,qCAEC"}
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
const ast_1 = require("../generated/ast");
|
|
8
|
+
const utils_1 = require("./utils");
|
|
9
|
+
const pluralize_1 = __importDefault(require("pluralize"));
|
|
10
|
+
class DataModelValidator {
|
|
11
|
+
validate(dm, accept) {
|
|
12
|
+
(0, utils_1.validateDuplicatedDeclarations)(dm.fields, accept);
|
|
13
|
+
this.validateFields(dm, accept);
|
|
14
|
+
this.validateAttributes(dm, accept);
|
|
15
|
+
}
|
|
16
|
+
validateFields(dm, accept) {
|
|
17
|
+
const idFields = dm.fields.filter((f) => f.attributes.find((attr) => { var _a; return ((_a = attr.decl.ref) === null || _a === void 0 ? void 0 : _a.name) === '@id'; }));
|
|
18
|
+
if (idFields.length === 0) {
|
|
19
|
+
accept('error', 'Model must include a field with @id attribute', {
|
|
20
|
+
node: dm,
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
else if (idFields.length > 1) {
|
|
24
|
+
accept('error', 'Model can include at most one field with @id attribute', {
|
|
25
|
+
node: dm,
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
if (idFields[0].type.optional) {
|
|
30
|
+
accept('error', 'Field with @id attribute must not be optional', { node: idFields[0] });
|
|
31
|
+
}
|
|
32
|
+
if (idFields[0].type.array ||
|
|
33
|
+
!idFields[0].type.type ||
|
|
34
|
+
!constants_1.SCALAR_TYPES.includes(idFields[0].type.type)) {
|
|
35
|
+
accept('error', 'Field with @id attribute must be of scalar type', { node: idFields[0] });
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
dm.fields.forEach((field) => this.validateField(field, accept));
|
|
39
|
+
}
|
|
40
|
+
validateField(field, accept) {
|
|
41
|
+
var _a;
|
|
42
|
+
if (field.type.array && field.type.optional) {
|
|
43
|
+
accept('error', 'Optional lists are not supported. Use either `Type[]` or `Type?`', { node: field.type });
|
|
44
|
+
}
|
|
45
|
+
field.attributes.forEach((attr) => this.validateAttributeApplication(attr, accept));
|
|
46
|
+
if ((0, ast_1.isDataModel)((_a = field.type.reference) === null || _a === void 0 ? void 0 : _a.ref)) {
|
|
47
|
+
this.validateRelationField(field, accept);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
validateAttributes(dm, accept) {
|
|
51
|
+
dm.attributes.forEach((attr) => {
|
|
52
|
+
this.validateAttributeApplication(attr, accept);
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
validateAttributeApplication(attr, accept) {
|
|
56
|
+
const decl = attr.decl.ref;
|
|
57
|
+
if (!decl) {
|
|
58
|
+
throw new Error(`Reference unresolved: ${attr.decl.$refText}`);
|
|
59
|
+
}
|
|
60
|
+
const filledParams = new Set();
|
|
61
|
+
for (const arg of attr.args) {
|
|
62
|
+
let paramDecl;
|
|
63
|
+
if (!arg.name) {
|
|
64
|
+
paramDecl = decl.params.find((p) => p.default && !filledParams.has(p));
|
|
65
|
+
if (!paramDecl) {
|
|
66
|
+
accept('error', `Unexpected unnamed argument`, {
|
|
67
|
+
node: arg,
|
|
68
|
+
});
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
else {
|
|
73
|
+
paramDecl = decl.params.find((p) => p.name === arg.name);
|
|
74
|
+
if (!paramDecl) {
|
|
75
|
+
accept('error', `Attribute "${decl.name}" doesn't have a parameter named "${arg.name}"`, {
|
|
76
|
+
node: arg,
|
|
77
|
+
});
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!(0, utils_1.assignableToAttributeParam)(arg, paramDecl, attr)) {
|
|
82
|
+
accept('error', `Value is not assignable to parameter`, {
|
|
83
|
+
node: arg,
|
|
84
|
+
});
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
if (filledParams.has(paramDecl)) {
|
|
88
|
+
accept('error', `Parameter "${paramDecl.name}" is already provided`, { node: arg });
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
filledParams.add(paramDecl);
|
|
92
|
+
}
|
|
93
|
+
const missingParams = decl.params.filter((p) => !p.type.optional && !filledParams.has(p));
|
|
94
|
+
if (missingParams.length > 0) {
|
|
95
|
+
accept('error', `Required ${(0, pluralize_1.default)('parameter', missingParams.length)} not provided: ${missingParams
|
|
96
|
+
.map((p) => p.name)
|
|
97
|
+
.join(', ')}`, { node: attr });
|
|
98
|
+
return false;
|
|
99
|
+
}
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
parseRelation(field, accept) {
|
|
103
|
+
const relAttr = field.attributes.find((attr) => { var _a; return ((_a = attr.decl.ref) === null || _a === void 0 ? void 0 : _a.name) === '@relation'; });
|
|
104
|
+
let name;
|
|
105
|
+
let fields;
|
|
106
|
+
let references;
|
|
107
|
+
let valid = true;
|
|
108
|
+
if (!relAttr) {
|
|
109
|
+
return { attr: relAttr, name, fields, references, valid: true };
|
|
110
|
+
}
|
|
111
|
+
for (const arg of relAttr.args) {
|
|
112
|
+
if (!arg.name || arg.name === 'name') {
|
|
113
|
+
if ((0, ast_1.isLiteralExpr)(arg.value)) {
|
|
114
|
+
name = arg.value.value;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
else if (arg.name === 'fields') {
|
|
118
|
+
fields = arg.value.items;
|
|
119
|
+
if (fields.length === 0) {
|
|
120
|
+
if (accept) {
|
|
121
|
+
accept('error', `"fields" value cannot be emtpy`, {
|
|
122
|
+
node: arg,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
valid = false;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
else if (arg.name === 'references') {
|
|
129
|
+
references = arg.value.items;
|
|
130
|
+
if (references.length === 0) {
|
|
131
|
+
if (accept) {
|
|
132
|
+
accept('error', `"references" value cannot be emtpy`, {
|
|
133
|
+
node: arg,
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
valid = false;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return { attr: relAttr, name, fields, references, valid };
|
|
141
|
+
}
|
|
142
|
+
validateRelationField(field, accept) {
|
|
143
|
+
var _a, _b, _c, _d;
|
|
144
|
+
const thisRelation = this.parseRelation(field, accept);
|
|
145
|
+
if (!thisRelation.valid) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
const oppositeModel = field.type.reference.ref;
|
|
149
|
+
let oppositeFields = oppositeModel.fields.filter((f) => { var _a; return ((_a = f.type.reference) === null || _a === void 0 ? void 0 : _a.ref) === field.$container; });
|
|
150
|
+
oppositeFields = oppositeFields.filter((f) => {
|
|
151
|
+
const fieldRel = this.parseRelation(f);
|
|
152
|
+
return fieldRel.valid && fieldRel.name === thisRelation.name;
|
|
153
|
+
});
|
|
154
|
+
if (oppositeFields.length === 0) {
|
|
155
|
+
accept('error', `The relation field "${field.name}" on model "${field.$container.name}" is missing an opposite relation field on model "${oppositeModel.name}"`, { node: field });
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
else if (oppositeFields.length > 1) {
|
|
159
|
+
oppositeFields.forEach((f) => accept('error', `Fields ${oppositeFields
|
|
160
|
+
.map((f) => '"' + f.name + '"')
|
|
161
|
+
.join(', ')} on model ${oppositeModel.name} refer to the same relation to model "${field.$container.name}"`, { node: f }));
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const oppositeField = oppositeFields[0];
|
|
165
|
+
const oppositeRelation = this.parseRelation(oppositeField);
|
|
166
|
+
let relationOwner;
|
|
167
|
+
if (((_a = thisRelation === null || thisRelation === void 0 ? void 0 : thisRelation.references) === null || _a === void 0 ? void 0 : _a.length) && ((_b = thisRelation.fields) === null || _b === void 0 ? void 0 : _b.length)) {
|
|
168
|
+
if ((oppositeRelation === null || oppositeRelation === void 0 ? void 0 : oppositeRelation.references) || (oppositeRelation === null || oppositeRelation === void 0 ? void 0 : oppositeRelation.fields)) {
|
|
169
|
+
accept('error', '"fields" and "references" must be provided only on one side of relation field', { node: oppositeField });
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
relationOwner = oppositeField;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
else if (((_c = oppositeRelation === null || oppositeRelation === void 0 ? void 0 : oppositeRelation.references) === null || _c === void 0 ? void 0 : _c.length) &&
|
|
177
|
+
((_d = oppositeRelation.fields) === null || _d === void 0 ? void 0 : _d.length)) {
|
|
178
|
+
if ((thisRelation === null || thisRelation === void 0 ? void 0 : thisRelation.references) || (thisRelation === null || thisRelation === void 0 ? void 0 : thisRelation.fields)) {
|
|
179
|
+
accept('error', '"fields" and "references" must be provided only on one side of relation field', { node: field });
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
else {
|
|
183
|
+
relationOwner = field;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
[field, oppositeField].forEach((f) => accept('error', 'Field for one side of relation must carry @relation attribute with both "fields" and "references" fields', { node: f }));
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
if (!relationOwner.type.array && !relationOwner.type.optional) {
|
|
191
|
+
accept('error', 'Relation field needs to be list or optional', {
|
|
192
|
+
node: relationOwner,
|
|
193
|
+
});
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
exports.default = DataModelValidator;
|
|
199
|
+
//# sourceMappingURL=datamodel-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datamodel-validator.js","sourceRoot":"","sources":["../../../src/language-server/validator/datamodel-validator.ts"],"names":[],"mappings":";;;;;AAAA,+CAA+C;AAC/C,6CAU6B;AAG7B,mCAGiB;AACjB,0DAAkC;AAElC,MAAqB,kBAAkB;IACnC,QAAQ,CAAC,EAAa,EAAE,MAA0B;QAC9C,IAAA,sCAA8B,EAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,kBAAkB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IACxC,CAAC;IAEO,cAAc,CAAC,EAAa,EAAE,MAA0B;QAC5D,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACpC,CAAC,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,WAAC,OAAA,CAAA,MAAA,IAAI,CAAC,IAAI,CAAC,GAAG,0CAAE,IAAI,MAAK,KAAK,CAAA,EAAA,CAAC,CAC7D,CAAC;QACF,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE;YACvB,MAAM,CAAC,OAAO,EAAE,+CAA+C,EAAE;gBAC7D,IAAI,EAAE,EAAE;aACX,CAAC,CAAC;SACN;aAAM,IAAI,QAAQ,CAAC,MAAM,GAAG,CAAC,EAAE;YAC5B,MAAM,CACF,OAAO,EACP,wDAAwD,EACxD;gBACI,IAAI,EAAE,EAAE;aACX,CACJ,CAAC;SACL;aAAM;YACH,IAAI,QAAQ,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,EAAE;gBAC3B,MAAM,CACF,OAAO,EACP,+CAA+C,EAC/C,EAAE,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EAAE,CACxB,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CAAC,KAAK,IAAI,CAAC,aAAa,CAAC,IAAI,CAAC,QAAQ,EAAE;YAC3D,MAAM,CAAC,OAAO,EAAE,6CAA6C,EAAE;gBAC3D,IAAI,EAAE,aAAa;aACtB,CAAC,CAAC;YACH,OAAO;SACV;IACL,CAAC;CACJ;AA9RD,qCA8RC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ast_1 = require("../generated/ast");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const supportedFields = [
|
|
7
|
+
'provider',
|
|
8
|
+
'url',
|
|
9
|
+
'shadowDatabaseUrl',
|
|
10
|
+
'relationMode',
|
|
11
|
+
];
|
|
12
|
+
class DataSourceValidator {
|
|
13
|
+
validate(ds, accept) {
|
|
14
|
+
(0, utils_1.validateDuplicatedDeclarations)(ds.fields, accept);
|
|
15
|
+
this.validateFields(ds, accept);
|
|
16
|
+
this.validateProvider(ds, accept);
|
|
17
|
+
this.validateUrl(ds, accept);
|
|
18
|
+
this.validateRelationMode(ds, accept);
|
|
19
|
+
}
|
|
20
|
+
validateFields(ds, accept) {
|
|
21
|
+
ds.fields.forEach((f) => {
|
|
22
|
+
if (!supportedFields.includes(f.name)) {
|
|
23
|
+
accept('error', `Unexpected field "${f.name}"`, { node: f });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
validateProvider(ds, accept) {
|
|
28
|
+
const provider = ds.fields.find((f) => f.name === 'provider');
|
|
29
|
+
if (!provider) {
|
|
30
|
+
accept('error', 'datasource must include a "provider" field', {
|
|
31
|
+
node: ds,
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const value = (0, utils_1.getStringLiteral)(provider.value);
|
|
36
|
+
if (!value) {
|
|
37
|
+
accept('error', '"provider" must be set to a string literal', {
|
|
38
|
+
node: provider.value,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (!constants_1.SUPPORTED_PROVIDERS.includes(value)) {
|
|
42
|
+
accept('error', `Provider "${value}" is not supported. Choose from ${constants_1.SUPPORTED_PROVIDERS.map((p) => '"' + p + '"').join(' | ')}.`, { node: provider.value });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
validateUrl(ds, accept) {
|
|
46
|
+
var _a;
|
|
47
|
+
const url = ds.fields.find((f) => f.name === 'url');
|
|
48
|
+
if (!url) {
|
|
49
|
+
accept('error', 'datasource must include a "url" field', {
|
|
50
|
+
node: ds,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
for (const fieldName of ['url', 'shadowDatabaseUrl']) {
|
|
54
|
+
const field = ds.fields.find((f) => f.name === fieldName);
|
|
55
|
+
if (!field) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const value = (0, utils_1.getStringLiteral)(field.value);
|
|
59
|
+
if (!value &&
|
|
60
|
+
!((0, ast_1.isInvocationExpr)(field.value) &&
|
|
61
|
+
((_a = field.value.function.ref) === null || _a === void 0 ? void 0 : _a.name) === 'env')) {
|
|
62
|
+
accept('error', `"${fieldName}" must be set to a string literal or an invocation of "env" function`, { node: field.value });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
validateRelationMode(ds, accept) {
|
|
67
|
+
const field = ds.fields.find((f) => f.name === 'relationMode');
|
|
68
|
+
if (field) {
|
|
69
|
+
const val = (0, utils_1.getStringLiteral)(field.value);
|
|
70
|
+
if (!val || !['foreignKeys', 'prisma'].includes(val)) {
|
|
71
|
+
accept('error', '"relationMode" must be set to "foreignKeys" or "prisma"', { node: field.value });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.default = DataSourceValidator;
|
|
77
|
+
//# sourceMappingURL=datasource-validator%20copy.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource-validator copy.js","sourceRoot":"","sources":["../../../src/language-server/validator/datasource-validator copy.ts"],"names":[],"mappings":";;AAAA,6CAAmE;AAGnE,mCAA2E;AAC3E,4CAAmD;AAEnD,MAAM,eAAe,GAAG;IACpB,UAAU;IACV,KAAK;IACL,mBAAmB;IACnB,cAAc;CACjB,CAAC;AAEF,MAAqB,mBAAmB;IACpC,QAAQ,CAAC,EAAc,EAAE,MAA0B;QAC/C,IAAA,sCAA8B,EAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAEO,cAAc,CAAC,EAAc,EAAE,MAA0B;QAC7D,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;YACpB,IAAI,CAAC,eAAe,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE;gBACnC,MAAM,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC,CAAC;aAChE;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IAEO,gBAAgB,CAAC,EAAc,EAAE,MAA0B;QAC/D,MAAM,QAAQ,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC;QAC9D,IAAI,CAAC,QAAQ,EAAE;YACX,MAAM,CAAC,OAAO,EAAE,4CAA4C,EAAE;gBAC1D,IAAI,EAAE,EAAE;aACX,CAAC,CAAC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AAC,KAAK,CAAC;oBAC7B,CAAA,MAAA,KAAK,CAAC,KAAK,CAAC,QAAQ,CAAC,GAAG,0CAAE,IAAI,MAAK,KAAK,CAC3C,EACH;gBACE,MAAM,CACF,OAAO,EACP,IAAI,SAAS,sEAAsE,EACnF,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,CACxB,CAAC;aACL;SACJ;IACL,CAAC;IAEO,oBAAoB,CAAC,EAAc,EAAE,MAA0B;QACnE,MAAM,KAAK,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,CAAC;QAC/D,IAAI,KAAK,EAAE;YACP,MAAM,GAAG,GAAG,IAAA,wBAAgB,EAAC,KAAK,CAAC,KAAK,CAAC,CAAC;YAC1C,IAAI,CAAC,GAAG,IAAI,CAAC,CAAC,aAAa,EAAE,QAAQ,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE;gBAClD,MAAM,CACF,OAAO,EACP,yDAAyD,EACzD,EAAE,IAAI,EAAE,KAAK,CAAC,KAAK,EAAE,CACxB,CAAC;aACL;SACJ;IACL,CAAC;CACJ;AArFD,sCAqFC"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ast_1 = require("../generated/ast");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
const constants_1 = require("../constants");
|
|
6
|
+
const supportedFields = [
|
|
7
|
+
'provider',
|
|
8
|
+
'url',
|
|
9
|
+
'shadowDatabaseUrl',
|
|
10
|
+
'relationMode',
|
|
11
|
+
];
|
|
12
|
+
class DataSourceValidator {
|
|
13
|
+
validate(ds, accept) {
|
|
14
|
+
(0, utils_1.validateDuplicatedDeclarations)(ds.fields, accept);
|
|
15
|
+
this.validateFields(ds, accept);
|
|
16
|
+
this.validateProvider(ds, accept);
|
|
17
|
+
this.validateUrl(ds, accept);
|
|
18
|
+
this.validateRelationMode(ds, accept);
|
|
19
|
+
}
|
|
20
|
+
validateFields(ds, accept) {
|
|
21
|
+
ds.fields.forEach((f) => {
|
|
22
|
+
if (!supportedFields.includes(f.name)) {
|
|
23
|
+
accept('error', `Unexpected field "${f.name}"`, { node: f });
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
validateProvider(ds, accept) {
|
|
28
|
+
const provider = ds.fields.find((f) => f.name === 'provider');
|
|
29
|
+
if (!provider) {
|
|
30
|
+
accept('error', 'datasource must include a "provider" field', {
|
|
31
|
+
node: ds,
|
|
32
|
+
});
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const value = (0, utils_1.getStringLiteral)(provider.value);
|
|
36
|
+
if (!value) {
|
|
37
|
+
accept('error', '"provider" must be set to a string literal', {
|
|
38
|
+
node: provider.value,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
else if (!constants_1.SUPPORTED_PROVIDERS.includes(value)) {
|
|
42
|
+
accept('error', `Provider "${value}" is not supported. Choose from ${constants_1.SUPPORTED_PROVIDERS.map((p) => '"' + p + '"').join(' | ')}.`, { node: provider.value });
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
validateUrl(ds, accept) {
|
|
46
|
+
var _a;
|
|
47
|
+
const url = ds.fields.find((f) => f.name === 'url');
|
|
48
|
+
if (!url) {
|
|
49
|
+
accept('error', 'datasource must include a "url" field', {
|
|
50
|
+
node: ds,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
for (const fieldName of ['url', 'shadowDatabaseUrl']) {
|
|
54
|
+
const field = ds.fields.find((f) => f.name === fieldName);
|
|
55
|
+
if (!field) {
|
|
56
|
+
continue;
|
|
57
|
+
}
|
|
58
|
+
const value = (0, utils_1.getStringLiteral)(field.value);
|
|
59
|
+
if (!value &&
|
|
60
|
+
!((0, ast_1.isInvocationExpr)(field.value) &&
|
|
61
|
+
((_a = field.value.function.ref) === null || _a === void 0 ? void 0 : _a.name) === 'env')) {
|
|
62
|
+
accept('error', `"${fieldName}" must be set to a string literal or an invocation of "env" function`, { node: field.value });
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
validateRelationMode(ds, accept) {
|
|
67
|
+
const field = ds.fields.find((f) => f.name === 'relationMode');
|
|
68
|
+
if (field) {
|
|
69
|
+
const val = (0, utils_1.getStringLiteral)(field.value);
|
|
70
|
+
if (!val || !['foreignKeys', 'prisma'].includes(val)) {
|
|
71
|
+
accept('error', '"relationMode" must be set to "foreignKeys" or "prisma"', { node: field.value });
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
exports.default = DataSourceValidator;
|
|
77
|
+
//# sourceMappingURL=datasource-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"datasource-validator.js","sourceRoot":"","sources":["../../../src/language-server/validator/datasource-validator.ts"],"names":[],"mappings":";;AAAA,6CAAmE;AAGnE,mCAA2E;AAC3E,4CAAmD;AAEnD,MAAM,eAAe,GAAG;IACpB,UAAU;IACV,KAAK;IACL,mBAAmB;IACnB,cAAc;CACjB,CAAC;AAEF,MAAqB,mBAAmB;IACpC,QAAQ,CAAC,EAAc,EAAE,MAA0B;QAC/C,IAAA,sCAA8B,EAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,CAAC,cAAc,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,gBAAgB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAClC,IAAI,CAAC,WAAW,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;QAC7B,IAAI,CAAC,oBAAoB,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC1C,CAAC;IAEO,cAAc,CAAC,EAAc,EAAE,MAA0B;QAC7D,EAAE,CAAC,MAAM,CAAC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I,EAAE,KAAK,CAAC,KAAK,EAAE,CACxB,CAAC;aACL;SACJ;IACL,CAAC;CACJ;AArFD,sCAqFC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const utils_1 = require("./utils");
|
|
4
|
+
class EnumValidator {
|
|
5
|
+
validate(_enum, accept) {
|
|
6
|
+
(0, utils_1.validateDuplicatedDeclarations)(_enum.fields, accept);
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.default = EnumValidator;
|
|
10
|
+
//# sourceMappingURL=enum-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"enum-validator.js","sourceRoot":"","sources":["../../../src/language-server/validator/enum-validator.ts"],"names":[],"mappings":";;AAGA,mCAAyD;AAEzD,MAAqB,aAAa;IAC9B,QAAQ,CAAC,KAAW,EAAE,MAA0B;QAC5C,IAAA,sCAA8B,EAAC,KAAK,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACzD,CAAC;CACJ;AAJD,gCAIC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ast_1 = require("../generated/ast");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class ModelValidator {
|
|
6
|
+
validate(model, accept) {
|
|
7
|
+
(0, utils_1.validateDuplicatedDeclarations)(model.declarations, accept);
|
|
8
|
+
this.validateDataSources(model, accept);
|
|
9
|
+
}
|
|
10
|
+
validateDataSources(model, accept) {
|
|
11
|
+
const dataSources = model.declarations.filter((d) => (0, ast_1.isDataSource)(d));
|
|
12
|
+
if (dataSources.length === 0) {
|
|
13
|
+
accept('error', 'Model must define a datasource', { node: model });
|
|
14
|
+
}
|
|
15
|
+
else if (dataSources.length > 1) {
|
|
16
|
+
accept('error', 'Multiple datasource declarations are not allowed', { node: dataSources[1] });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = ModelValidator;
|
|
21
|
+
//# sourceMappingURL=model-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"model-validator.js","sourceRoot":"","sources":["../../../src/language-server/validator/model-validator.ts"],"names":[],"mappings":";;AAAA,6CAA0D;AAG1D,mCAAyD;AAEzD,MAAqB,cAAc;IAC/B,QAAQ,CAAC,KAAY,EAAE,MAA0B;QAC7C,IAAA,sCAA8B,EAAC,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC3D,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAEO,mBAAmB,CAAC,KAAY,EAAE,MAA0B;QAChE,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,kBAAY,EAAC,CAAC,CAAC,CAAC,CAAC;QACtE,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC1B,MAAM,CAAC,OAAO,EAAE,gCAAgC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;SACtE;aAAM,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/B,MAAM,CACF,OAAO,EACP,kDAAkD,EAClD,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAC3B,CAAC;SACL;IACL,CAAC;CACJ;AAlBD,iCAkBC"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ast_1 = require("../generated/ast");
|
|
4
|
+
const utils_1 = require("./utils");
|
|
5
|
+
class SchemaValidator {
|
|
6
|
+
validate(model, accept) {
|
|
7
|
+
(0, utils_1.validateDuplicatedDeclarations)(model.declarations, accept);
|
|
8
|
+
this.validateDataSources(model, accept);
|
|
9
|
+
}
|
|
10
|
+
validateDataSources(model, accept) {
|
|
11
|
+
const dataSources = model.declarations.filter((d) => (0, ast_1.isDataSource)(d));
|
|
12
|
+
if (dataSources.length === 0) {
|
|
13
|
+
accept('error', 'Model must define a datasource', { node: model });
|
|
14
|
+
}
|
|
15
|
+
else if (dataSources.length > 1) {
|
|
16
|
+
accept('error', 'Multiple datasource declarations are not allowed', { node: dataSources[1] });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.default = SchemaValidator;
|
|
21
|
+
//# sourceMappingURL=schema-validator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"schema-validator.js","sourceRoot":"","sources":["../../../src/language-server/validator/schema-validator.ts"],"names":[],"mappings":";;AAAA,6CAA0D;AAG1D,mCAAyD;AAEzD,MAAqB,eAAe;IAChC,QAAQ,CAAC,KAAY,EAAE,MAA0B;QAC7C,IAAA,sCAA8B,EAAC,KAAK,CAAC,YAAY,EAAE,MAAM,CAAC,CAAC;QAC3D,IAAI,CAAC,mBAAmB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;IAC5C,CAAC;IAEO,mBAAmB,CAAC,KAAY,EAAE,MAA0B;QAChE,MAAM,WAAW,GAAG,KAAK,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,IAAA,kBAAY,EAAC,CAAC,CAAC,CAAC,CAAC;QACtE,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC,EAAE;YAC1B,MAAM,CAAC,OAAO,EAAE,gCAAgC,EAAE,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;SACtE;aAAM,IAAI,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE;YAC/B,MAAM,CACF,OAAO,EACP,kDAAkD,EAClD,EAAE,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,EAAE,CAC3B,CAAC;SACL;IACL,CAAC;CACJ;AAlBD,kCAkBC"}
|