@sap-ux/cds-odata-annotation-converter 0.2.0
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/LICENSE +201 -0
- package/README.md +55 -0
- package/dist/i18n/i18n.json +8 -0
- package/dist/i18n.d.ts +7 -0
- package/dist/i18n.d.ts.map +1 -0
- package/dist/i18n.js +37 -0
- package/dist/i18n.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/index.js.map +1 -0
- package/dist/printer/csdl-to-cds.d.ts +30 -0
- package/dist/printer/csdl-to-cds.d.ts.map +1 -0
- package/dist/printer/csdl-to-cds.js +391 -0
- package/dist/printer/csdl-to-cds.js.map +1 -0
- package/dist/printer/edm-json.d.ts +18 -0
- package/dist/printer/edm-json.d.ts.map +1 -0
- package/dist/printer/edm-json.js +140 -0
- package/dist/printer/edm-json.js.map +1 -0
- package/dist/printer/indent.d.ts +16 -0
- package/dist/printer/indent.d.ts.map +1 -0
- package/dist/printer/indent.js +72 -0
- package/dist/printer/indent.js.map +1 -0
- package/dist/printer/index.d.ts +3 -0
- package/dist/printer/index.d.ts.map +1 -0
- package/dist/printer/index.js +11 -0
- package/dist/printer/index.js.map +1 -0
- package/dist/printer/primitives.d.ts +16 -0
- package/dist/printer/primitives.d.ts.map +1 -0
- package/dist/printer/primitives.js +52 -0
- package/dist/printer/primitives.js.map +1 -0
- package/dist/transforms/annotation/convert.d.ts +25 -0
- package/dist/transforms/annotation/convert.d.ts.map +1 -0
- package/dist/transforms/annotation/convert.js +47 -0
- package/dist/transforms/annotation/convert.js.map +1 -0
- package/dist/transforms/annotation/creators.d.ts +5 -0
- package/dist/transforms/annotation/creators.d.ts.map +1 -0
- package/dist/transforms/annotation/creators.js +17 -0
- package/dist/transforms/annotation/creators.js.map +1 -0
- package/dist/transforms/annotation/find-node.d.ts +20 -0
- package/dist/transforms/annotation/find-node.d.ts.map +1 -0
- package/dist/transforms/annotation/find-node.js +461 -0
- package/dist/transforms/annotation/find-node.js.map +1 -0
- package/dist/transforms/annotation/flattened.d.ts +13 -0
- package/dist/transforms/annotation/flattened.d.ts.map +1 -0
- package/dist/transforms/annotation/flattened.js +151 -0
- package/dist/transforms/annotation/flattened.js.map +1 -0
- package/dist/transforms/annotation/handler.d.ts +32 -0
- package/dist/transforms/annotation/handler.d.ts.map +1 -0
- package/dist/transforms/annotation/handler.js +14 -0
- package/dist/transforms/annotation/handler.js.map +1 -0
- package/dist/transforms/annotation/handlers/annotation.d.ts +4 -0
- package/dist/transforms/annotation/handlers/annotation.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/annotation.js +160 -0
- package/dist/transforms/annotation/handlers/annotation.js.map +1 -0
- package/dist/transforms/annotation/handlers/boolean.d.ts +4 -0
- package/dist/transforms/annotation/handlers/boolean.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/boolean.js +25 -0
- package/dist/transforms/annotation/handlers/boolean.js.map +1 -0
- package/dist/transforms/annotation/handlers/collection.d.ts +4 -0
- package/dist/transforms/annotation/handlers/collection.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/collection.js +41 -0
- package/dist/transforms/annotation/handlers/collection.js.map +1 -0
- package/dist/transforms/annotation/handlers/edm-json.d.ts +51 -0
- package/dist/transforms/annotation/handlers/edm-json.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/edm-json.js +176 -0
- package/dist/transforms/annotation/handlers/edm-json.js.map +1 -0
- package/dist/transforms/annotation/handlers/enum.d.ts +24 -0
- package/dist/transforms/annotation/handlers/enum.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/enum.js +69 -0
- package/dist/transforms/annotation/handlers/enum.js.map +1 -0
- package/dist/transforms/annotation/handlers/expression.d.ts +6 -0
- package/dist/transforms/annotation/handlers/expression.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/expression.js +92 -0
- package/dist/transforms/annotation/handlers/expression.js.map +1 -0
- package/dist/transforms/annotation/handlers/index.d.ts +7 -0
- package/dist/transforms/annotation/handlers/index.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/index.js +33 -0
- package/dist/transforms/annotation/handlers/index.js.map +1 -0
- package/dist/transforms/annotation/handlers/number.d.ts +12 -0
- package/dist/transforms/annotation/handlers/number.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/number.js +48 -0
- package/dist/transforms/annotation/handlers/number.js.map +1 -0
- package/dist/transforms/annotation/handlers/path.d.ts +4 -0
- package/dist/transforms/annotation/handlers/path.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/path.js +193 -0
- package/dist/transforms/annotation/handlers/path.js.map +1 -0
- package/dist/transforms/annotation/handlers/quoted-literal.d.ts +4 -0
- package/dist/transforms/annotation/handlers/quoted-literal.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/quoted-literal.js +45 -0
- package/dist/transforms/annotation/handlers/quoted-literal.js.map +1 -0
- package/dist/transforms/annotation/handlers/record-property.d.ts +4 -0
- package/dist/transforms/annotation/handlers/record-property.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/record-property.js +57 -0
- package/dist/transforms/annotation/handlers/record-property.js.map +1 -0
- package/dist/transforms/annotation/handlers/record.d.ts +4 -0
- package/dist/transforms/annotation/handlers/record.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/record.js +243 -0
- package/dist/transforms/annotation/handlers/record.js.map +1 -0
- package/dist/transforms/annotation/handlers/string.d.ts +5 -0
- package/dist/transforms/annotation/handlers/string.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/string.js +56 -0
- package/dist/transforms/annotation/handlers/string.js.map +1 -0
- package/dist/transforms/annotation/handlers/token.d.ts +4 -0
- package/dist/transforms/annotation/handlers/token.d.ts.map +1 -0
- package/dist/transforms/annotation/handlers/token.js +19 -0
- package/dist/transforms/annotation/handlers/token.js.map +1 -0
- package/dist/transforms/annotation/index.d.ts +2 -0
- package/dist/transforms/annotation/index.d.ts.map +1 -0
- package/dist/transforms/annotation/index.js +6 -0
- package/dist/transforms/annotation/index.js.map +1 -0
- package/dist/transforms/annotation/path-utils.d.ts +13 -0
- package/dist/transforms/annotation/path-utils.d.ts.map +1 -0
- package/dist/transforms/annotation/path-utils.js +40 -0
- package/dist/transforms/annotation/path-utils.js.map +1 -0
- package/dist/transforms/annotation/range.d.ts +5 -0
- package/dist/transforms/annotation/range.d.ts.map +1 -0
- package/dist/transforms/annotation/range.js +11 -0
- package/dist/transforms/annotation/range.js.map +1 -0
- package/dist/transforms/annotation/type-resolver.d.ts +37 -0
- package/dist/transforms/annotation/type-resolver.d.ts.map +1 -0
- package/dist/transforms/annotation/type-resolver.js +96 -0
- package/dist/transforms/annotation/type-resolver.js.map +1 -0
- package/dist/transforms/annotation/visitor-state.d.ts +81 -0
- package/dist/transforms/annotation/visitor-state.d.ts.map +1 -0
- package/dist/transforms/annotation/visitor-state.js +85 -0
- package/dist/transforms/annotation/visitor-state.js.map +1 -0
- package/dist/transforms/annotation/visitor.d.ts +17 -0
- package/dist/transforms/annotation/visitor.d.ts.map +1 -0
- package/dist/transforms/annotation/visitor.js +68 -0
- package/dist/transforms/annotation/visitor.js.map +1 -0
- package/dist/transforms/annotation-file.d.ts +31 -0
- package/dist/transforms/annotation-file.d.ts.map +1 -0
- package/dist/transforms/annotation-file.js +514 -0
- package/dist/transforms/annotation-file.js.map +1 -0
- package/dist/transforms/index.d.ts +3 -0
- package/dist/transforms/index.d.ts.map +1 -0
- package/dist/transforms/index.js +10 -0
- package/dist/transforms/index.js.map +1 -0
- package/dist/transforms/misc.d.ts +2 -0
- package/dist/transforms/misc.d.ts.map +1 -0
- package/dist/transforms/misc.js +10 -0
- package/dist/transforms/misc.js.map +1 -0
- package/dist/transforms/types.d.ts +38 -0
- package/dist/transforms/types.d.ts.map +1 -0
- package/dist/transforms/types.js +3 -0
- package/dist/transforms/types.js.map +1 -0
- package/package.json +42 -0
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.findNode = void 0;
|
|
4
|
+
const cds_annotation_parser_1 = require("@sap-ux/cds-annotation-parser");
|
|
5
|
+
const odata_annotation_core_1 = require("@sap-ux/odata-annotation-core");
|
|
6
|
+
/**
|
|
7
|
+
* Visitor which traverses the tree and builds a path to the node,
|
|
8
|
+
* which has the most specific range matching to the given position.
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
class PositionVisitor {
|
|
12
|
+
/**
|
|
13
|
+
* Visits a TermNode or an array of TermNodes and returns a VisitorReturnValue.
|
|
14
|
+
*
|
|
15
|
+
* @param node - The TermNode or array of TermNodes to visit.
|
|
16
|
+
* @param options - The options for the position visitor.
|
|
17
|
+
* @param segments - The segments representing the path to the current node.
|
|
18
|
+
* @returns Returns the VisitorReturnValue or undefined if no match is found.
|
|
19
|
+
*/
|
|
20
|
+
visit(node, options, segments) {
|
|
21
|
+
if (Array.isArray(node)) {
|
|
22
|
+
for (let index = 0; index < node.length; index++) {
|
|
23
|
+
const child = node[index];
|
|
24
|
+
const children = this.visit(child, options, [index.toString()]);
|
|
25
|
+
if (children) {
|
|
26
|
+
return {
|
|
27
|
+
path: [...segments, ...children.path],
|
|
28
|
+
range: children.range
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
switch (node.type) {
|
|
35
|
+
case odata_annotation_core_1.TEXT_TYPE:
|
|
36
|
+
return this.visitText(node, options, segments);
|
|
37
|
+
case odata_annotation_core_1.ELEMENT_TYPE:
|
|
38
|
+
return this.visitElement(node, options, segments);
|
|
39
|
+
case odata_annotation_core_1.ATTRIBUTE_TYPE:
|
|
40
|
+
return this.visitAttribute(node, options, segments);
|
|
41
|
+
default:
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Visits a TextNode and returns information based on the specified options and segments.
|
|
47
|
+
*
|
|
48
|
+
* @param node - The TextNode to be visited.
|
|
49
|
+
* @param options - The options containing position information.
|
|
50
|
+
* @param segments - The array of segments representing the current path.
|
|
51
|
+
* @returns Returns information about the visited TextNode or undefined.
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
visitText(node, options, segments) {
|
|
55
|
+
var _a;
|
|
56
|
+
const { position } = options;
|
|
57
|
+
const nodeRange = (_a = node.range) !== null && _a !== void 0 ? _a : undefined;
|
|
58
|
+
if ((0, odata_annotation_core_1.positionContained)(nodeRange, position)) {
|
|
59
|
+
return {
|
|
60
|
+
path: [...segments, 'text'],
|
|
61
|
+
range: nodeRange
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
return undefined;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Visits an Attribute and returns information based on the specified options and segments.
|
|
68
|
+
*
|
|
69
|
+
* @param attribute - The Attribute to be visited.
|
|
70
|
+
* @param options - The options containing position information.
|
|
71
|
+
* @param segments - The array of segments representing the current path.
|
|
72
|
+
* @returns Returns information about the visited Attribute or undefined.
|
|
73
|
+
* @private
|
|
74
|
+
*/
|
|
75
|
+
visitAttribute(attribute, options, segments) {
|
|
76
|
+
var _a, _b;
|
|
77
|
+
const { position } = options;
|
|
78
|
+
const nameRange = (_a = attribute.nameRange) !== null && _a !== void 0 ? _a : undefined;
|
|
79
|
+
if ((0, odata_annotation_core_1.positionContained)(nameRange, position)) {
|
|
80
|
+
return {
|
|
81
|
+
path: [...segments, 'name'],
|
|
82
|
+
range: nameRange
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
const valueRange = (_b = attribute.valueRange) !== null && _b !== void 0 ? _b : undefined;
|
|
86
|
+
if ((0, odata_annotation_core_1.positionContained)(valueRange, position)) {
|
|
87
|
+
return {
|
|
88
|
+
path: [...segments, 'value'],
|
|
89
|
+
range: valueRange
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Visits an Element and returns information based on the specified options and segments.
|
|
96
|
+
*
|
|
97
|
+
* @param element - The Element to be visited.
|
|
98
|
+
* @param options - The options containing position information.
|
|
99
|
+
* @param segments - The array of segments representing the current path.
|
|
100
|
+
* @returns Returns information about the visited Element or undefined.
|
|
101
|
+
* @private
|
|
102
|
+
*/
|
|
103
|
+
visitElement(element, options, segments) {
|
|
104
|
+
const { position } = options;
|
|
105
|
+
const range = element.range;
|
|
106
|
+
if (range && (0, odata_annotation_core_1.positionContained)(range, position)) {
|
|
107
|
+
const attributeNames = Object.keys(element.attributes);
|
|
108
|
+
if ((0, odata_annotation_core_1.positionContained)(element.nameRange, position)) {
|
|
109
|
+
return {
|
|
110
|
+
path: [...segments, 'name'],
|
|
111
|
+
range: element.nameRange
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
for (const attributeName of attributeNames) {
|
|
115
|
+
const attribute = element.attributes[attributeName];
|
|
116
|
+
const children = this.visit(attribute, options, ['attributes', attributeName]);
|
|
117
|
+
if (children) {
|
|
118
|
+
return {
|
|
119
|
+
path: [...segments, ...children.path],
|
|
120
|
+
range: children.range
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if ((0, odata_annotation_core_1.positionContained)(element.contentRange, position)) {
|
|
125
|
+
return this.visitContent(element, options, segments);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
return undefined;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Visits the content of an Element and returns information based on the specified options and segments.
|
|
132
|
+
*
|
|
133
|
+
* @param element - The Element whose content is being visited.
|
|
134
|
+
* @param options - The options containing position information.
|
|
135
|
+
* @param segments - The array of segments representing the current path.
|
|
136
|
+
* @returns Returns information about the visited content or undefined.
|
|
137
|
+
* @private
|
|
138
|
+
*/
|
|
139
|
+
visitContent(element, options, segments) {
|
|
140
|
+
const { position } = options;
|
|
141
|
+
for (let index = 0; index < element.content.length; index++) {
|
|
142
|
+
const child = element.content[index];
|
|
143
|
+
const children = this.visit(child, options, ['content', index.toString()]);
|
|
144
|
+
if (children) {
|
|
145
|
+
return {
|
|
146
|
+
path: [...segments, ...children.path],
|
|
147
|
+
range: children.range
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
// position is not in any child node, find relative position to a child node
|
|
152
|
+
const index = element.content.findIndex((item) => item.range && (0, odata_annotation_core_1.isBefore)(position, item.range.start, true));
|
|
153
|
+
return {
|
|
154
|
+
path: [...segments, `$${index === -1 ? element.content.length : index}`],
|
|
155
|
+
range: element.contentRange
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
const visitor = new PositionVisitor();
|
|
160
|
+
/**
|
|
161
|
+
* Builds a pointer to a node in annotations,
|
|
162
|
+
* which has the most specific range matching to the given position.
|
|
163
|
+
*
|
|
164
|
+
* @param assignment CDS annotation AST assignment node.
|
|
165
|
+
* @param annotations Annotation elements.
|
|
166
|
+
* @param position Position used to match nodes.
|
|
167
|
+
* @returns matching node or undefined.
|
|
168
|
+
*/
|
|
169
|
+
function findNode(assignment, annotations, position) {
|
|
170
|
+
const result = visitor.visit(annotations, { position }, ['']);
|
|
171
|
+
if (result) {
|
|
172
|
+
const path = (0, cds_annotation_parser_1.findAnnotationNode)(assignment, { position, includeDelimiterCharacters: false });
|
|
173
|
+
const adjustedResult = adjustReturnValue(path, assignment, annotations, result, position);
|
|
174
|
+
return {
|
|
175
|
+
pointer: adjustedResult.path.join('/'),
|
|
176
|
+
range: adjustedResult.range
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return undefined;
|
|
180
|
+
}
|
|
181
|
+
exports.findNode = findNode;
|
|
182
|
+
/**
|
|
183
|
+
* Retrieves the specified nodes from the array of TermNodes based on the provided path.
|
|
184
|
+
*
|
|
185
|
+
* @param terms - The array of TermNodes to retrieve nodes from.
|
|
186
|
+
* @param path - The path specifying the sequence of indices or property names.
|
|
187
|
+
* @returns Returns the retrieved nodes based on the provided path.
|
|
188
|
+
*/
|
|
189
|
+
function getTermNodes(terms, path) {
|
|
190
|
+
// ignore the first empty segment
|
|
191
|
+
const [, indexString, ...segments] = path;
|
|
192
|
+
const index = parseInt(indexString, 10); // or use Number(indexString);
|
|
193
|
+
let node = terms[index];
|
|
194
|
+
const nodes = [];
|
|
195
|
+
for (const segment of segments) {
|
|
196
|
+
if (typeof node === 'object' && node !== null) {
|
|
197
|
+
node = node[segment]; // Use any to handle indexing with a string
|
|
198
|
+
}
|
|
199
|
+
nodes.push(node);
|
|
200
|
+
}
|
|
201
|
+
return nodes;
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Adjusts the VisitorReturnValue based on the provided AST path, assignment, terms, value, and position.
|
|
205
|
+
*
|
|
206
|
+
* @param astPath - The AST path specifying the sequence of indices or property names.
|
|
207
|
+
* @param assignment - The Assignment associated with the value.
|
|
208
|
+
* @param terms - The array of Element terms.
|
|
209
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
210
|
+
* @param position - The position information.
|
|
211
|
+
* @returns Returns the adjusted VisitorReturnValue.
|
|
212
|
+
*/
|
|
213
|
+
function adjustReturnValue(astPath, assignment, terms, value, position) {
|
|
214
|
+
const astNodes = (0, cds_annotation_parser_1.getAstNodes)(assignment, astPath);
|
|
215
|
+
const node = astNodes === null || astNodes === void 0 ? void 0 : astNodes[astNodes.length - 1];
|
|
216
|
+
if (!node) {
|
|
217
|
+
return value;
|
|
218
|
+
}
|
|
219
|
+
const nodes = getTermNodes(terms, value.path.filter((segment) => !segment.startsWith('$')));
|
|
220
|
+
value = edmJsonContent(astNodes, value, position);
|
|
221
|
+
value = enumCollection(astNodes, nodes, value, position);
|
|
222
|
+
if (Array.isArray(node)) {
|
|
223
|
+
return value;
|
|
224
|
+
}
|
|
225
|
+
switch (node.type) {
|
|
226
|
+
case cds_annotation_parser_1.RECORD_PROPERTY_TYPE:
|
|
227
|
+
case cds_annotation_parser_1.ANNOTATION_TYPE:
|
|
228
|
+
return beforeValue(node, value, position);
|
|
229
|
+
case cds_annotation_parser_1.NUMBER_LITERAL_TYPE:
|
|
230
|
+
case cds_annotation_parser_1.STRING_LITERAL_TYPE:
|
|
231
|
+
return stringValue(node, value, position);
|
|
232
|
+
case cds_annotation_parser_1.ENUM_TYPE:
|
|
233
|
+
return enumTextNode(value);
|
|
234
|
+
case cds_annotation_parser_1.EMPTY_VALUE_TYPE:
|
|
235
|
+
return emptyValue(node, value);
|
|
236
|
+
case cds_annotation_parser_1.PATH_TYPE:
|
|
237
|
+
return pathTextNode(node, value, position);
|
|
238
|
+
default:
|
|
239
|
+
return value;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Adjusts the VisitorReturnValue before processing the value based on the provided node, value, and position.
|
|
244
|
+
*
|
|
245
|
+
* @param node - The Annotation or RecordProperty node associated with the value.
|
|
246
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
247
|
+
* @param position - The position information.
|
|
248
|
+
* @returns Returns the adjusted VisitorReturnValue.
|
|
249
|
+
*/
|
|
250
|
+
function beforeValue(node, value, position) {
|
|
251
|
+
var _a, _b, _c, _d;
|
|
252
|
+
const lastPathSegment = value.path.slice(-1)[0];
|
|
253
|
+
if (node.type === cds_annotation_parser_1.RECORD_PROPERTY_TYPE && node.name.value === cds_annotation_parser_1.ReservedProperties.Value) {
|
|
254
|
+
// for $value pointer should not be adjusted
|
|
255
|
+
return value;
|
|
256
|
+
}
|
|
257
|
+
if ((lastPathSegment === null || lastPathSegment === void 0 ? void 0 : lastPathSegment.startsWith('$')) &&
|
|
258
|
+
((_b = (_a = node.colon) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.end) &&
|
|
259
|
+
!(0, odata_annotation_core_1.isBefore)(position, node.colon.range.end) &&
|
|
260
|
+
((_d = (_c = node.value) === null || _c === void 0 ? void 0 : _c.range) === null || _d === void 0 ? void 0 : _d.start) &&
|
|
261
|
+
(0, odata_annotation_core_1.isBefore)(position, node.value.range.start, true)) {
|
|
262
|
+
// $ segment shouldn't be included if the position is between colon and value
|
|
263
|
+
return {
|
|
264
|
+
path: value.path.slice(0, -1)
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
return value;
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Adjusts the VisitorReturnValue for StringLiteral or NumberLiteral nodes based on the provided node, value, and position.
|
|
271
|
+
*
|
|
272
|
+
* @param node - The StringLiteral or NumberLiteral node associated with the value.
|
|
273
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
274
|
+
* @param position - The position information.
|
|
275
|
+
* @returns Returns the adjusted VisitorReturnValue.
|
|
276
|
+
*/
|
|
277
|
+
function stringValue(node, value, position) {
|
|
278
|
+
const range = (0, cds_annotation_parser_1.nodeRange)(node, false);
|
|
279
|
+
const lastPathSegment = value.path.slice(-1)[0];
|
|
280
|
+
if (lastPathSegment !== 'text') {
|
|
281
|
+
// we need to only update position for text nodes
|
|
282
|
+
return value;
|
|
283
|
+
}
|
|
284
|
+
if (!range) {
|
|
285
|
+
return value;
|
|
286
|
+
}
|
|
287
|
+
const offset = position.character - range.start.character;
|
|
288
|
+
return {
|
|
289
|
+
path: [...value.path, `$${offset}`],
|
|
290
|
+
range: value.range
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
/**
|
|
294
|
+
* Adjusts the VisitorReturnValue for EmptyValue nodes based on the provided node and value.
|
|
295
|
+
*
|
|
296
|
+
* @param node - The EmptyValue node associated with the value.
|
|
297
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
298
|
+
* @returns Returns the adjusted VisitorReturnValue.
|
|
299
|
+
*/
|
|
300
|
+
function emptyValue(node, value) {
|
|
301
|
+
if (node.range) {
|
|
302
|
+
return {
|
|
303
|
+
path: value.path,
|
|
304
|
+
range: node.range
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Adjusts the VisitorReturnValue for enum collection based on the provided AST nodes, term nodes, value, and position.
|
|
311
|
+
*
|
|
312
|
+
* @param astNodes - The array of AST nodes associated with the annotation.
|
|
313
|
+
* @param nodes - The array of term nodes associated with the annotation.
|
|
314
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
315
|
+
* @param position - The position information for adjusting the value.
|
|
316
|
+
* @returns Returns the adjusted VisitorReturnValue.
|
|
317
|
+
*/
|
|
318
|
+
function enumCollection(astNodes, nodes, value, position) {
|
|
319
|
+
// The end of nodes array should look like this - [..., element, content, textNode, text ]
|
|
320
|
+
const [parent, , textNode] = nodes.slice(-4);
|
|
321
|
+
if ((parent === null || parent === void 0 ? void 0 : parent.type) !== odata_annotation_core_1.ELEMENT_TYPE || parent.name !== "EnumMember" /* Edm.EnumMember */) {
|
|
322
|
+
return value;
|
|
323
|
+
}
|
|
324
|
+
const collection = findLastNode(astNodes, cds_annotation_parser_1.COLLECTION_TYPE);
|
|
325
|
+
if (!collection) {
|
|
326
|
+
return value;
|
|
327
|
+
}
|
|
328
|
+
const enumNode = collection.items.find((child) => (0, odata_annotation_core_1.positionContained)(child.range, position));
|
|
329
|
+
if ((textNode === null || textNode === void 0 ? void 0 : textNode.type) !== odata_annotation_core_1.TEXT_TYPE || (enumNode === null || enumNode === void 0 ? void 0 : enumNode.type) !== cds_annotation_parser_1.ENUM_TYPE || enumNode.range === undefined) {
|
|
330
|
+
return value;
|
|
331
|
+
}
|
|
332
|
+
const startOffset = textNode.text.indexOf(enumNode.path.value);
|
|
333
|
+
// Make sure the in segment position is not negative if position is right before #
|
|
334
|
+
const charactersInSegment = Math.max(enumNode.range.start.character - position.character, 0);
|
|
335
|
+
const index = startOffset + charactersInSegment;
|
|
336
|
+
if (enumNode.path.range !== undefined) {
|
|
337
|
+
return {
|
|
338
|
+
path: [...value.path, `$${index}`],
|
|
339
|
+
range: enumNode.path.range
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
return value;
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Finds the last node of a specific type in an array of annotation nodes.
|
|
346
|
+
*
|
|
347
|
+
* @template T - The type of the node to find.
|
|
348
|
+
* @param nodes - The array of annotation nodes to search.
|
|
349
|
+
* @param type - The type of the node to find.
|
|
350
|
+
* @returns Returns the last node of the specified type, or undefined if not found.
|
|
351
|
+
*/
|
|
352
|
+
function findLastNode(nodes, type) {
|
|
353
|
+
for (let index = nodes.length - 1; index >= 0; index--) {
|
|
354
|
+
const element = nodes[index];
|
|
355
|
+
if (!Array.isArray(element) && element.type === type) {
|
|
356
|
+
// Type cast needed due to Typescript limitation https://github.com/microsoft/TypeScript/issues/50103
|
|
357
|
+
return element;
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
return undefined;
|
|
361
|
+
}
|
|
362
|
+
/**
|
|
363
|
+
* Adjusts the VisitorReturnValue for EDM JSON content based on the provided AST nodes, value, and position.
|
|
364
|
+
*
|
|
365
|
+
* @param astNodes - The array of AST nodes associated with the annotation.
|
|
366
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
367
|
+
* @param position - The position information for adjusting the value.
|
|
368
|
+
* @returns Returns the adjusted VisitorReturnValue for EDM JSON content.
|
|
369
|
+
*/
|
|
370
|
+
function edmJsonContent(astNodes, value, position) {
|
|
371
|
+
var _a, _b;
|
|
372
|
+
const edmJsonIndex = astNodes.findIndex((node) => !Array.isArray(node) && node.type === cds_annotation_parser_1.RECORD_PROPERTY_TYPE && node.name.value === cds_annotation_parser_1.ReservedProperties.EdmJson);
|
|
373
|
+
if (edmJsonIndex === -1) {
|
|
374
|
+
return value;
|
|
375
|
+
}
|
|
376
|
+
if (value.path[value.path.length - 1].startsWith('$')) {
|
|
377
|
+
// content pointer
|
|
378
|
+
const node = astNodes[astNodes.length - 1];
|
|
379
|
+
if (Array.isArray(node)) {
|
|
380
|
+
return value;
|
|
381
|
+
}
|
|
382
|
+
const range = (0, cds_annotation_parser_1.nodeRange)(node, false);
|
|
383
|
+
if (node.type !== cds_annotation_parser_1.RECORD_TYPE || !range) {
|
|
384
|
+
return value;
|
|
385
|
+
}
|
|
386
|
+
const property = node.properties[0];
|
|
387
|
+
if (property === undefined) {
|
|
388
|
+
return value;
|
|
389
|
+
}
|
|
390
|
+
// element name is already declared, so we can either only add annotations or attributes
|
|
391
|
+
if (((_a = property.range) === null || _a === void 0 ? void 0 : _a.start) && (0, odata_annotation_core_1.isBefore)(position, (_b = property.range) === null || _b === void 0 ? void 0 : _b.start)) {
|
|
392
|
+
// content/0 segments always get generated for positions elements in content range,
|
|
393
|
+
// but in this case we need to remove it
|
|
394
|
+
return {
|
|
395
|
+
path: [...value.path.slice(0, -3), `$0`],
|
|
396
|
+
range
|
|
397
|
+
};
|
|
398
|
+
}
|
|
399
|
+
else {
|
|
400
|
+
return {
|
|
401
|
+
path: [...value.path.slice(0, -1), 'attributes'],
|
|
402
|
+
range
|
|
403
|
+
};
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
return value;
|
|
407
|
+
}
|
|
408
|
+
/**
|
|
409
|
+
* Adjusts the VisitorReturnValue for an enum text node based on the provided value.
|
|
410
|
+
*
|
|
411
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
412
|
+
* @returns Returns the adjusted VisitorReturnValue for an enum text node.
|
|
413
|
+
*/
|
|
414
|
+
function enumTextNode(value) {
|
|
415
|
+
if (value.path[value.path.length - 1].startsWith('$')) {
|
|
416
|
+
return value;
|
|
417
|
+
}
|
|
418
|
+
const path = value.path.slice(0, -1);
|
|
419
|
+
return {
|
|
420
|
+
path,
|
|
421
|
+
range: value.range
|
|
422
|
+
};
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Adjusts the VisitorReturnValue for a path text node based on the provided value.
|
|
426
|
+
*
|
|
427
|
+
* @param node - The Path node being processed.
|
|
428
|
+
* @param value - The original VisitorReturnValue to be adjusted.
|
|
429
|
+
* @param position - The position within the document.
|
|
430
|
+
* @returns Returns the adjusted VisitorReturnValue for a path text node.
|
|
431
|
+
*/
|
|
432
|
+
function pathTextNode(node, value, position) {
|
|
433
|
+
const lastPathSegment = value.path.slice(-1)[0];
|
|
434
|
+
if (lastPathSegment !== 'text') {
|
|
435
|
+
// we need to only update position for text nodes
|
|
436
|
+
return value;
|
|
437
|
+
}
|
|
438
|
+
if (node.value === '') {
|
|
439
|
+
return {
|
|
440
|
+
path: [...value.path, '$0'],
|
|
441
|
+
range: value.range
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
for (let i = 0; i < node.segments.length; i++) {
|
|
445
|
+
const segment = node.segments[i];
|
|
446
|
+
if (segment.range && (0, odata_annotation_core_1.positionContained)(segment.range, position)) {
|
|
447
|
+
const prefix = node.segments
|
|
448
|
+
.filter((_, j) => j < i)
|
|
449
|
+
.map((s) => s.value)
|
|
450
|
+
.join('/');
|
|
451
|
+
const delimiterOffset = i === 0 ? 0 : 1; // If it is not the first item we need to add last delimiter
|
|
452
|
+
const localOffset = position.character - segment.range.start.character;
|
|
453
|
+
return {
|
|
454
|
+
path: [...value.path, `$${prefix.length + delimiterOffset + localOffset}`],
|
|
455
|
+
range: segment.range
|
|
456
|
+
};
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
return value;
|
|
460
|
+
}
|
|
461
|
+
//# sourceMappingURL=find-node.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-node.js","sourceRoot":"","sources":["../../../src/transforms/annotation/find-node.ts"],"names":[],"mappings":";;;AAWA,yEAcuC;AAGvC,yEAOuC;AAOvC;;;;GAIG;AACH,MAAM,eAAe;IACjB;;;;;;;OAOG;IACH,KAAK,CACD,IAA2B,EAC3B,OAA+B,EAC/B,QAAkB;QAElB,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACrB,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE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ux/cds-annotation-parser';
|
|
2
|
+
import type { Subtree } from './handler';
|
|
3
|
+
import type { VisitorState } from './visitor-state';
|
|
4
|
+
/**
|
|
5
|
+
* Builds a tree from a flattened annotation structure and updates context with the final value type.
|
|
6
|
+
*
|
|
7
|
+
* @param state VisitorSate for which context will be updated with the inferred value types.
|
|
8
|
+
* @param segments Array of identifiers representing flattened record structure.
|
|
9
|
+
* @param value annotation value.
|
|
10
|
+
* @returns subtree representing flattened structure
|
|
11
|
+
*/
|
|
12
|
+
export declare function convertFlattenedPath(state: VisitorState, segments: Identifier[], value: AnnotationValue | undefined): Subtree | undefined;
|
|
13
|
+
//# sourceMappingURL=flattened.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattened.d.ts","sourceRoot":"","sources":["../../../src/transforms/annotation/flattened.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAKjF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKzC,OAAO,KAAK,EAAW,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAI7D;;;;;;;GAOG;AACH,wBAAgB,oBAAoB,CAChC,KAAK,EAAE,YAAY,EACnB,QAAQ,EAAE,UAAU,EAAE,EACtB,KAAK,EAAE,eAAe,GAAG,SAAS,GACnC,OAAO,GAAG,SAAS,CA8DrB"}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.convertFlattenedPath = void 0;
|
|
4
|
+
const odata_annotation_core_1 = require("@sap-ux/odata-annotation-core");
|
|
5
|
+
const creators_1 = require("./creators");
|
|
6
|
+
const type_resolver_1 = require("./type-resolver");
|
|
7
|
+
const range_1 = require("./range");
|
|
8
|
+
/**
|
|
9
|
+
* Builds a tree from a flattened annotation structure and updates context with the final value type.
|
|
10
|
+
*
|
|
11
|
+
* @param state VisitorSate for which context will be updated with the inferred value types.
|
|
12
|
+
* @param segments Array of identifiers representing flattened record structure.
|
|
13
|
+
* @param value annotation value.
|
|
14
|
+
* @returns subtree representing flattened structure
|
|
15
|
+
*/
|
|
16
|
+
function convertFlattenedPath(state, segments, value) {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f;
|
|
18
|
+
// |________________Annotation____________________|
|
|
19
|
+
// | | |
|
|
20
|
+
// | |___________Record(root)_____________|
|
|
21
|
+
// | | |
|
|
22
|
+
// | |__________Property Value____________|
|
|
23
|
+
// | | |
|
|
24
|
+
// | | |________Record__________|
|
|
25
|
+
// | | | |
|
|
26
|
+
// | | |_____Property Value_____|
|
|
27
|
+
// | | | |
|
|
28
|
+
// | | | |
|
|
29
|
+
// UI.Chart.AxisScaling.ScaleBehavior : #AutoScale
|
|
30
|
+
// \______/|\_________/|\___________/ \________/
|
|
31
|
+
// | | | | | |
|
|
32
|
+
// | | | | | |
|
|
33
|
+
// | Record | Record | |
|
|
34
|
+
// | | | |
|
|
35
|
+
// Term | | |
|
|
36
|
+
// Property Property Enum Member
|
|
37
|
+
let root;
|
|
38
|
+
let parent;
|
|
39
|
+
const expandedStructures = convertToExpandedStructure(state, segments, value === null || value === void 0 ? void 0 : value.range);
|
|
40
|
+
for (const expandedStructure of expandedStructures) {
|
|
41
|
+
if (parent) {
|
|
42
|
+
const record = (0, odata_annotation_core_1.createElementNode)({
|
|
43
|
+
name: "Record" /* Edm.Record */,
|
|
44
|
+
range: (_a = expandedStructure.element.range) !== null && _a !== void 0 ? _a : undefined,
|
|
45
|
+
content: [expandedStructure.element],
|
|
46
|
+
contentRange: (_b = expandedStructure.element.range) !== null && _b !== void 0 ? _b : undefined
|
|
47
|
+
});
|
|
48
|
+
// property content range should include only child range
|
|
49
|
+
parent.contentRange = (_c = record.range) !== null && _c !== void 0 ? _c : undefined;
|
|
50
|
+
parent.content.push(record);
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
root = expandedStructure.element;
|
|
54
|
+
}
|
|
55
|
+
parent = expandedStructure.element;
|
|
56
|
+
}
|
|
57
|
+
const last = expandedStructures[expandedStructures.length - 1];
|
|
58
|
+
const newContext = {
|
|
59
|
+
valueType: (_d = last.vocabularyObject) === null || _d === void 0 ? void 0 : _d.type,
|
|
60
|
+
isCollection: (_e = last.vocabularyObject) === null || _e === void 0 ? void 0 : _e.isCollection
|
|
61
|
+
};
|
|
62
|
+
if (last.kind === 'annotation') {
|
|
63
|
+
newContext.termType = (_f = last.vocabularyObject) === null || _f === void 0 ? void 0 : _f.type;
|
|
64
|
+
}
|
|
65
|
+
else {
|
|
66
|
+
newContext.propertyName = last.element.attributes["Property" /* Edm.Property */].value;
|
|
67
|
+
}
|
|
68
|
+
state.pushContext(Object.assign(Object.assign({}, state.context), newContext));
|
|
69
|
+
if (!root || !parent) {
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
return {
|
|
73
|
+
root,
|
|
74
|
+
leaf: parent
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
exports.convertFlattenedPath = convertFlattenedPath;
|
|
78
|
+
/**
|
|
79
|
+
*
|
|
80
|
+
* @param state VisitorSate for which context will be updated with the inferred value types.
|
|
81
|
+
* @param segments Array of identifiers representing flattened record structure.
|
|
82
|
+
* @param valueRange element content/value range.
|
|
83
|
+
* @returns expanded structure either annotation or property kind.
|
|
84
|
+
*/
|
|
85
|
+
function convertToExpandedStructure(state, segments, valueRange) {
|
|
86
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
87
|
+
const expandedStructure = [];
|
|
88
|
+
const initialType = (_a = state.context.recordType) !== null && _a !== void 0 ? _a : state.context.termType;
|
|
89
|
+
const lastSegment = valueRange ? undefined : segments[segments.length - 1];
|
|
90
|
+
let i = 0;
|
|
91
|
+
while (i < segments.length) {
|
|
92
|
+
const segment = segments[i];
|
|
93
|
+
const propertyRange = (0, range_1.createRange)((_b = segment.range) === null || _b === void 0 ? void 0 : _b.start, (_c = valueRange === null || valueRange === void 0 ? void 0 : valueRange.end) !== null && _c !== void 0 ? _c : (_d = lastSegment === null || lastSegment === void 0 ? void 0 : lastSegment.range) === null || _d === void 0 ? void 0 : _d.end);
|
|
94
|
+
if (segment.value.startsWith('@')) {
|
|
95
|
+
// handle embedded annotation syntax (supported starting with cds-compiler v3)
|
|
96
|
+
// e.g. @Common.Text.@UI.TextArrangement : #TextFirst
|
|
97
|
+
const vocabularyNameOrAlias = segment.value.substring(1);
|
|
98
|
+
const termNameSegment = segments[i + 1];
|
|
99
|
+
const termQualifiedName = termNameSegment
|
|
100
|
+
? `${vocabularyNameOrAlias}.${termNameSegment.value}`
|
|
101
|
+
: vocabularyNameOrAlias;
|
|
102
|
+
const termValueRange = (0, range_1.createRange)((_e = segment.range) === null || _e === void 0 ? void 0 : _e.start, (_f = termNameSegment.range) === null || _f === void 0 ? void 0 : _f.end);
|
|
103
|
+
const embeddedAnnotation = (0, odata_annotation_core_1.createElementNode)({
|
|
104
|
+
name: "Annotation" /* Edm.Annotation */,
|
|
105
|
+
range: propertyRange,
|
|
106
|
+
attributes: {
|
|
107
|
+
["Term" /* Edm.Term */]: (0, creators_1.createTermAttribute)(termQualifiedName, termValueRange)
|
|
108
|
+
},
|
|
109
|
+
content: []
|
|
110
|
+
});
|
|
111
|
+
expandedStructure.push({
|
|
112
|
+
kind: 'annotation',
|
|
113
|
+
name: termQualifiedName,
|
|
114
|
+
vocabularyObject: (0, type_resolver_1.getTerm)(state.vocabularyService, vocabularyNameOrAlias, termNameSegment.value),
|
|
115
|
+
element: embeddedAnnotation
|
|
116
|
+
});
|
|
117
|
+
i += 2;
|
|
118
|
+
continue;
|
|
119
|
+
}
|
|
120
|
+
const flatProperty = (0, odata_annotation_core_1.createElementNode)({
|
|
121
|
+
name: "PropertyValue" /* Edm.PropertyValue */,
|
|
122
|
+
range: propertyRange,
|
|
123
|
+
contentRange: propertyRange,
|
|
124
|
+
attributes: {
|
|
125
|
+
["Property" /* Edm.Property */]: (0, creators_1.createPropertyAttribute)(segment.value, segment.range)
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
const parentType = (_j = (_h = (_g = expandedStructure[expandedStructure.length - 1]) === null || _g === void 0 ? void 0 : _g.vocabularyObject) === null || _h === void 0 ? void 0 : _h.type) !== null && _j !== void 0 ? _j : initialType;
|
|
129
|
+
expandedStructure.push({
|
|
130
|
+
kind: 'property',
|
|
131
|
+
name: segment.value,
|
|
132
|
+
vocabularyObject: (0, type_resolver_1.getPropertyType)(state.vocabularyService, parentType, segment.value),
|
|
133
|
+
element: flatProperty
|
|
134
|
+
});
|
|
135
|
+
i++;
|
|
136
|
+
}
|
|
137
|
+
// the leaf element should only include the values range in it's contentRange
|
|
138
|
+
const last = expandedStructure[expandedStructure.length - 1];
|
|
139
|
+
if (last) {
|
|
140
|
+
if (valueRange) {
|
|
141
|
+
last.element.contentRange = (0, range_1.copyRange)(valueRange);
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
// content range should not be added in case value does not exist
|
|
145
|
+
// e.g { AxisScaling. }
|
|
146
|
+
delete last.element.contentRange;
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
return expandedStructure;
|
|
150
|
+
}
|
|
151
|
+
//# sourceMappingURL=flattened.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattened.js","sourceRoot":"","sources":["../../../src/transforms/annotation/flattened.ts"],"names":[],"mappings":";;;AAGA,yEAAuE;AAIvE,yCAA0E;AAC1E,mDAA2D;AAG3D,mCAAiD;AAGjD;;;;;;;GAOG;AACH,SAAgB,oBAAoB,CAChC,KAAmB,EACnB,QAAsB,EACtB,KAAkC;;IAElC,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD,mDAAmD;IACnD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