@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.
Files changed (148) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +55 -0
  3. package/dist/i18n/i18n.json +8 -0
  4. package/dist/i18n.d.ts +7 -0
  5. package/dist/i18n.d.ts.map +1 -0
  6. package/dist/i18n.js +37 -0
  7. package/dist/i18n.js.map +1 -0
  8. package/dist/index.d.ts +8 -0
  9. package/dist/index.d.ts.map +1 -0
  10. package/dist/index.js +23 -0
  11. package/dist/index.js.map +1 -0
  12. package/dist/printer/csdl-to-cds.d.ts +30 -0
  13. package/dist/printer/csdl-to-cds.d.ts.map +1 -0
  14. package/dist/printer/csdl-to-cds.js +391 -0
  15. package/dist/printer/csdl-to-cds.js.map +1 -0
  16. package/dist/printer/edm-json.d.ts +18 -0
  17. package/dist/printer/edm-json.d.ts.map +1 -0
  18. package/dist/printer/edm-json.js +140 -0
  19. package/dist/printer/edm-json.js.map +1 -0
  20. package/dist/printer/indent.d.ts +16 -0
  21. package/dist/printer/indent.d.ts.map +1 -0
  22. package/dist/printer/indent.js +72 -0
  23. package/dist/printer/indent.js.map +1 -0
  24. package/dist/printer/index.d.ts +3 -0
  25. package/dist/printer/index.d.ts.map +1 -0
  26. package/dist/printer/index.js +11 -0
  27. package/dist/printer/index.js.map +1 -0
  28. package/dist/printer/primitives.d.ts +16 -0
  29. package/dist/printer/primitives.d.ts.map +1 -0
  30. package/dist/printer/primitives.js +52 -0
  31. package/dist/printer/primitives.js.map +1 -0
  32. package/dist/transforms/annotation/convert.d.ts +25 -0
  33. package/dist/transforms/annotation/convert.d.ts.map +1 -0
  34. package/dist/transforms/annotation/convert.js +47 -0
  35. package/dist/transforms/annotation/convert.js.map +1 -0
  36. package/dist/transforms/annotation/creators.d.ts +5 -0
  37. package/dist/transforms/annotation/creators.d.ts.map +1 -0
  38. package/dist/transforms/annotation/creators.js +17 -0
  39. package/dist/transforms/annotation/creators.js.map +1 -0
  40. package/dist/transforms/annotation/find-node.d.ts +20 -0
  41. package/dist/transforms/annotation/find-node.d.ts.map +1 -0
  42. package/dist/transforms/annotation/find-node.js +461 -0
  43. package/dist/transforms/annotation/find-node.js.map +1 -0
  44. package/dist/transforms/annotation/flattened.d.ts +13 -0
  45. package/dist/transforms/annotation/flattened.d.ts.map +1 -0
  46. package/dist/transforms/annotation/flattened.js +151 -0
  47. package/dist/transforms/annotation/flattened.js.map +1 -0
  48. package/dist/transforms/annotation/handler.d.ts +32 -0
  49. package/dist/transforms/annotation/handler.d.ts.map +1 -0
  50. package/dist/transforms/annotation/handler.js +14 -0
  51. package/dist/transforms/annotation/handler.js.map +1 -0
  52. package/dist/transforms/annotation/handlers/annotation.d.ts +4 -0
  53. package/dist/transforms/annotation/handlers/annotation.d.ts.map +1 -0
  54. package/dist/transforms/annotation/handlers/annotation.js +160 -0
  55. package/dist/transforms/annotation/handlers/annotation.js.map +1 -0
  56. package/dist/transforms/annotation/handlers/boolean.d.ts +4 -0
  57. package/dist/transforms/annotation/handlers/boolean.d.ts.map +1 -0
  58. package/dist/transforms/annotation/handlers/boolean.js +25 -0
  59. package/dist/transforms/annotation/handlers/boolean.js.map +1 -0
  60. package/dist/transforms/annotation/handlers/collection.d.ts +4 -0
  61. package/dist/transforms/annotation/handlers/collection.d.ts.map +1 -0
  62. package/dist/transforms/annotation/handlers/collection.js +41 -0
  63. package/dist/transforms/annotation/handlers/collection.js.map +1 -0
  64. package/dist/transforms/annotation/handlers/edm-json.d.ts +51 -0
  65. package/dist/transforms/annotation/handlers/edm-json.d.ts.map +1 -0
  66. package/dist/transforms/annotation/handlers/edm-json.js +176 -0
  67. package/dist/transforms/annotation/handlers/edm-json.js.map +1 -0
  68. package/dist/transforms/annotation/handlers/enum.d.ts +24 -0
  69. package/dist/transforms/annotation/handlers/enum.d.ts.map +1 -0
  70. package/dist/transforms/annotation/handlers/enum.js +69 -0
  71. package/dist/transforms/annotation/handlers/enum.js.map +1 -0
  72. package/dist/transforms/annotation/handlers/expression.d.ts +6 -0
  73. package/dist/transforms/annotation/handlers/expression.d.ts.map +1 -0
  74. package/dist/transforms/annotation/handlers/expression.js +92 -0
  75. package/dist/transforms/annotation/handlers/expression.js.map +1 -0
  76. package/dist/transforms/annotation/handlers/index.d.ts +7 -0
  77. package/dist/transforms/annotation/handlers/index.d.ts.map +1 -0
  78. package/dist/transforms/annotation/handlers/index.js +33 -0
  79. package/dist/transforms/annotation/handlers/index.js.map +1 -0
  80. package/dist/transforms/annotation/handlers/number.d.ts +12 -0
  81. package/dist/transforms/annotation/handlers/number.d.ts.map +1 -0
  82. package/dist/transforms/annotation/handlers/number.js +48 -0
  83. package/dist/transforms/annotation/handlers/number.js.map +1 -0
  84. package/dist/transforms/annotation/handlers/path.d.ts +4 -0
  85. package/dist/transforms/annotation/handlers/path.d.ts.map +1 -0
  86. package/dist/transforms/annotation/handlers/path.js +193 -0
  87. package/dist/transforms/annotation/handlers/path.js.map +1 -0
  88. package/dist/transforms/annotation/handlers/quoted-literal.d.ts +4 -0
  89. package/dist/transforms/annotation/handlers/quoted-literal.d.ts.map +1 -0
  90. package/dist/transforms/annotation/handlers/quoted-literal.js +45 -0
  91. package/dist/transforms/annotation/handlers/quoted-literal.js.map +1 -0
  92. package/dist/transforms/annotation/handlers/record-property.d.ts +4 -0
  93. package/dist/transforms/annotation/handlers/record-property.d.ts.map +1 -0
  94. package/dist/transforms/annotation/handlers/record-property.js +57 -0
  95. package/dist/transforms/annotation/handlers/record-property.js.map +1 -0
  96. package/dist/transforms/annotation/handlers/record.d.ts +4 -0
  97. package/dist/transforms/annotation/handlers/record.d.ts.map +1 -0
  98. package/dist/transforms/annotation/handlers/record.js +243 -0
  99. package/dist/transforms/annotation/handlers/record.js.map +1 -0
  100. package/dist/transforms/annotation/handlers/string.d.ts +5 -0
  101. package/dist/transforms/annotation/handlers/string.d.ts.map +1 -0
  102. package/dist/transforms/annotation/handlers/string.js +56 -0
  103. package/dist/transforms/annotation/handlers/string.js.map +1 -0
  104. package/dist/transforms/annotation/handlers/token.d.ts +4 -0
  105. package/dist/transforms/annotation/handlers/token.d.ts.map +1 -0
  106. package/dist/transforms/annotation/handlers/token.js +19 -0
  107. package/dist/transforms/annotation/handlers/token.js.map +1 -0
  108. package/dist/transforms/annotation/index.d.ts +2 -0
  109. package/dist/transforms/annotation/index.d.ts.map +1 -0
  110. package/dist/transforms/annotation/index.js +6 -0
  111. package/dist/transforms/annotation/index.js.map +1 -0
  112. package/dist/transforms/annotation/path-utils.d.ts +13 -0
  113. package/dist/transforms/annotation/path-utils.d.ts.map +1 -0
  114. package/dist/transforms/annotation/path-utils.js +40 -0
  115. package/dist/transforms/annotation/path-utils.js.map +1 -0
  116. package/dist/transforms/annotation/range.d.ts +5 -0
  117. package/dist/transforms/annotation/range.d.ts.map +1 -0
  118. package/dist/transforms/annotation/range.js +11 -0
  119. package/dist/transforms/annotation/range.js.map +1 -0
  120. package/dist/transforms/annotation/type-resolver.d.ts +37 -0
  121. package/dist/transforms/annotation/type-resolver.d.ts.map +1 -0
  122. package/dist/transforms/annotation/type-resolver.js +96 -0
  123. package/dist/transforms/annotation/type-resolver.js.map +1 -0
  124. package/dist/transforms/annotation/visitor-state.d.ts +81 -0
  125. package/dist/transforms/annotation/visitor-state.d.ts.map +1 -0
  126. package/dist/transforms/annotation/visitor-state.js +85 -0
  127. package/dist/transforms/annotation/visitor-state.js.map +1 -0
  128. package/dist/transforms/annotation/visitor.d.ts +17 -0
  129. package/dist/transforms/annotation/visitor.d.ts.map +1 -0
  130. package/dist/transforms/annotation/visitor.js +68 -0
  131. package/dist/transforms/annotation/visitor.js.map +1 -0
  132. package/dist/transforms/annotation-file.d.ts +31 -0
  133. package/dist/transforms/annotation-file.d.ts.map +1 -0
  134. package/dist/transforms/annotation-file.js +514 -0
  135. package/dist/transforms/annotation-file.js.map +1 -0
  136. package/dist/transforms/index.d.ts +3 -0
  137. package/dist/transforms/index.d.ts.map +1 -0
  138. package/dist/transforms/index.js +10 -0
  139. package/dist/transforms/index.js.map +1 -0
  140. package/dist/transforms/misc.d.ts +2 -0
  141. package/dist/transforms/misc.d.ts.map +1 -0
  142. package/dist/transforms/misc.js +10 -0
  143. package/dist/transforms/misc.js.map +1 -0
  144. package/dist/transforms/types.d.ts +38 -0
  145. package/dist/transforms/types.d.ts.map +1 -0
  146. package/dist/transforms/types.js +3 -0
  147. package/dist/transforms/types.js.map +1 -0
  148. package/package.json +42 -0
@@ -0,0 +1,32 @@
1
+ import type { AnnotationNode } from '@sap-ux/cds-annotation-parser';
2
+ import type { Element } from '@sap-ux/odata-annotation-core-types';
3
+ import type { Context, VisitorState } from './visitor-state';
4
+ export type ConvertResult = Element | Subtree | undefined;
5
+ export interface NodeHandler<N extends AnnotationNode> {
6
+ type: N['type'];
7
+ getChildren?: (state: VisitorState, node: N) => AnnotationNode[];
8
+ convert: (state: VisitorState, node: N) => ConvertResult;
9
+ updateContext?: (state: VisitorState, node: N, element: Element) => Context;
10
+ }
11
+ /**
12
+ * Used when node is converted in a tree structure with multiple levels
13
+ */
14
+ export interface Subtree {
15
+ /**
16
+ * Element that will be added as a content to the parent element
17
+ */
18
+ root: Element;
19
+ /**
20
+ * Element to which child elements will be added
21
+ */
22
+ leaf: Element;
23
+ }
24
+ /**
25
+ * Checks if the given value is a Subtree.
26
+ *
27
+ * @param value - The value to be checked.
28
+ * @returns Returns true if the value is a Subtree, otherwise false.
29
+ */
30
+ export declare function isSubtree(value: Subtree | Element): value is Subtree;
31
+ export type Visitor = (node: AnnotationNode) => void;
32
+ //# sourceMappingURL=handler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.d.ts","sourceRoot":"","sources":["../../../src/transforms/annotation/handler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AACnE,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAE7D,MAAM,MAAM,aAAa,GAAG,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAC1D,MAAM,WAAW,WAAW,CAAC,CAAC,SAAS,cAAc;IACjD,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC;IAChB,WAAW,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,KAAK,cAAc,EAAE,CAAC;IACjE,OAAO,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,KAAK,aAAa,CAAC;IACzD,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,OAAO,KAAK,OAAO,CAAC;CAC/E;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACpB;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC;IACd;;OAEG;IACH,IAAI,EAAE,OAAO,CAAC;CACjB;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,KAAK,IAAI,OAAO,CAEpE;AACD,MAAM,MAAM,OAAO,GAAG,CAAC,IAAI,EAAE,cAAc,KAAK,IAAI,CAAC"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isSubtree = void 0;
4
+ /**
5
+ * Checks if the given value is a Subtree.
6
+ *
7
+ * @param value - The value to be checked.
8
+ * @returns Returns true if the value is a Subtree, otherwise false.
9
+ */
10
+ function isSubtree(value) {
11
+ return value.type === undefined;
12
+ }
13
+ exports.isSubtree = isSubtree;
14
+ //# sourceMappingURL=handler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"handler.js","sourceRoot":"","sources":["../../../src/transforms/annotation/handler.ts"],"names":[],"mappings":";;;AA0BA;;;;;GAKG;AACH,SAAgB,SAAS,CAAC,KAAwB;IAC9C,OAAQ,KAA4B,CAAC,IAAI,KAAK,SAAS,CAAC;AAC5D,CAAC;AAFD,8BAEC"}
@@ -0,0 +1,4 @@
1
+ import type { Annotation } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const annotationHandler: NodeHandler<Annotation>;
4
+ //# sourceMappingURL=annotation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotation.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/annotation.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAA8B,MAAM,+BAA+B,CAAC;AAO5F,OAAO,KAAK,EAAiB,WAAW,EAAW,MAAM,YAAY,CAAC;AAKtE,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,UAAU,CAUrD,CAAC"}
@@ -0,0 +1,160 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.annotationHandler = void 0;
4
+ const cds_annotation_parser_1 = require("@sap-ux/cds-annotation-parser");
5
+ const odata_annotation_core_types_1 = require("@sap-ux/odata-annotation-core-types");
6
+ const flattened_1 = require("../flattened");
7
+ const type_resolver_1 = require("../type-resolver");
8
+ const creators_1 = require("../creators");
9
+ exports.annotationHandler = {
10
+ type: cds_annotation_parser_1.ANNOTATION_TYPE,
11
+ convert,
12
+ getChildren(state, annotation) {
13
+ if (annotation.value) {
14
+ return [annotation.value];
15
+ }
16
+ else {
17
+ return [];
18
+ }
19
+ }
20
+ };
21
+ /**
22
+ * Converts an Annotation node into an Element node and handles flattened structures.
23
+ *
24
+ * @param state - The visitor state.
25
+ * @param annotation - The Annotation node to convert.
26
+ * @returns Returns an Element or Subtree representing the converted structure.
27
+ */
28
+ function convert(state, annotation) {
29
+ var _a, _b;
30
+ const element = (0, odata_annotation_core_types_1.createElementNode)({
31
+ name: "Annotation" /* Edm.Annotation */,
32
+ range: (0, cds_annotation_parser_1.nodeRange)(annotation, false)
33
+ });
34
+ const isEmbeddedAnnotation = state.elementStack.length > 0;
35
+ const termSegments = getTermSegments(annotation, isEmbeddedAnnotation);
36
+ const termName = state.context.groupName && !isEmbeddedAnnotation
37
+ ? [state.context.groupName, ...termSegments.slice(0, 1)].join('.')
38
+ : termSegments.slice(0, 2).join('.');
39
+ element.attributes["Term" /* Edm.Term */] = (0, creators_1.createTermAttribute)(termName, getTermNameRange(state, annotation, isEmbeddedAnnotation));
40
+ const [namespaceOrAlias, termSimpleIdentifier] = termName.split('.');
41
+ const term = (0, type_resolver_1.getTerm)(state.vocabularyService, namespaceOrAlias, termSimpleIdentifier);
42
+ if (isEmbeddedAnnotation) {
43
+ state.pushContext({
44
+ valueType: term === null || term === void 0 ? void 0 : term.type,
45
+ termType: term === null || term === void 0 ? void 0 : term.type,
46
+ isCollection: term === null || term === void 0 ? void 0 : term.isCollection
47
+ });
48
+ }
49
+ else if (term) {
50
+ state.pushContext(Object.assign(Object.assign({}, state.context), { valueType: term === null || term === void 0 ? void 0 : term.type, termType: term.type, isCollection: term.isCollection }));
51
+ }
52
+ if (annotation.qualifier) {
53
+ element.attributes["Qualifier" /* Edm.Qualifier */] = (0, creators_1.createQualifierAttribute)(annotation.qualifier.value, (0, cds_annotation_parser_1.nodeRange)(annotation.qualifier, false));
54
+ }
55
+ if (annotation.value) {
56
+ element.contentRange = (0, cds_annotation_parser_1.nodeRange)(annotation.value, annotation.value.type !== cds_annotation_parser_1.EMPTY_VALUE_TYPE);
57
+ // take into account colon
58
+ if (annotation.colon && element.contentRange) {
59
+ const colonPosition = (_b = (_a = annotation === null || annotation === void 0 ? void 0 : annotation.colon) === null || _a === void 0 ? void 0 : _a.range) === null || _b === void 0 ? void 0 : _b.end;
60
+ // position right after colon should be counted as part of the elements content
61
+ element.contentRange.start = colonPosition
62
+ ? odata_annotation_core_types_1.Position.create(colonPosition.line, colonPosition.character)
63
+ : odata_annotation_core_types_1.Position.create(0, 0);
64
+ }
65
+ }
66
+ const flattenedSubtree = handleFlattenedStructure(state, annotation, element);
67
+ if (flattenedSubtree) {
68
+ return flattenedSubtree;
69
+ }
70
+ return element;
71
+ }
72
+ /**
73
+ * Get the term segments from an annotation.
74
+ *
75
+ * @param annotation - The annotation object.
76
+ * @param isEmbeddedAnnotation - A flag indicating whether the annotation is embedded.
77
+ * @returns An array of string segments extracted from the annotation's term property.
78
+ */
79
+ function getTermSegments(annotation, isEmbeddedAnnotation) {
80
+ return annotation.term.segments.map((identifier, index) => index === 0 && isEmbeddedAnnotation ? identifier.value.slice(1) : identifier.value);
81
+ }
82
+ /**
83
+ * Gets the range for the term name based on the given annotation node and context.
84
+ *
85
+ * @param state - The visitor state.
86
+ * @param node - The annotation node containing the term.
87
+ * @param isEmbeddedAnnotation - Indicates whether the annotation is embedded within another element.
88
+ * @returns Returns the range for the term name, or undefined if not applicable.
89
+ */
90
+ function getTermNameRange(state, node, isEmbeddedAnnotation) {
91
+ var _a, _b;
92
+ const segments = state.context.groupName && !isEmbeddedAnnotation
93
+ ? node.term.segments.slice(0, 1)
94
+ : node.term.segments.slice(0, 2);
95
+ if (segments.length === node.term.segments.length) {
96
+ // use full node if it is a complete match and no flattened syntax is used
97
+ return (0, cds_annotation_parser_1.nodeRange)(node.term, false);
98
+ }
99
+ const start = segments[0];
100
+ const end = segments.slice(-1)[0];
101
+ if (!start || !end) {
102
+ return undefined;
103
+ }
104
+ const startPosition = (_a = (0, cds_annotation_parser_1.nodeRange)(start, false)) === null || _a === void 0 ? void 0 : _a.start;
105
+ const endPosition = (_b = (0, cds_annotation_parser_1.nodeRange)(end, false)) === null || _b === void 0 ? void 0 : _b.end;
106
+ if (!startPosition || !endPosition) {
107
+ return undefined;
108
+ }
109
+ return odata_annotation_core_types_1.Range.create(startPosition, endPosition);
110
+ }
111
+ /**
112
+ * Gets the flattened segments from the term of the given annotation, considering the context and nesting.
113
+ *
114
+ * @param state - The visitor state.
115
+ * @param annotation - The annotation containing the term with segments.
116
+ * @returns Returns the flattened segments of the term.
117
+ */
118
+ function getFlattenedSegments(state, annotation) {
119
+ const isEmbeddedAnnotation = state.elementStack.length > 0;
120
+ const trailingTermSegmentStart = state.context.groupName && !isEmbeddedAnnotation ? 1 : 2;
121
+ return annotation.term.segments.slice(trailingTermSegmentStart);
122
+ }
123
+ /**
124
+ * Handles a flattened structure in the CDS syntax and builds nested structures.
125
+ *
126
+ * @param state - The visitor state.
127
+ * @param annotation - The annotation containing the flattened structure.
128
+ * @param element - The element to which the flattened structure will be added.
129
+ * @returns Returns a Subtree representing the nested structures, or undefined if not applicable.
130
+ */
131
+ function handleFlattenedStructure(state, annotation, element) {
132
+ // Build nested structures for CDS flattened syntax
133
+ // e.g UI.Chart.AxisScaling.ScaleBehavior : #AutoScale, @Common.Text.@UI.TextArrangement : #TextFirst
134
+ const flattenedSegments = getFlattenedSegments(state, annotation);
135
+ if (flattenedSegments.length) {
136
+ const subtree = (0, flattened_1.convertFlattenedPath)(state, flattenedSegments, annotation.value);
137
+ if (subtree) {
138
+ const range = subtree.root.range ? (0, cds_annotation_parser_1.copyRange)(subtree.root.range) : undefined;
139
+ if (subtree.root.name === "PropertyValue" /* Edm.PropertyValue */) {
140
+ const record = (0, odata_annotation_core_types_1.createElementNode)({
141
+ name: "Record" /* Edm.Record */,
142
+ range,
143
+ contentRange: range
144
+ });
145
+ record.content.push(subtree.root);
146
+ element.content.push(record);
147
+ }
148
+ else {
149
+ element.content.push(subtree.root);
150
+ }
151
+ element.contentRange = range ? (0, cds_annotation_parser_1.copyRange)(range) : undefined;
152
+ return {
153
+ root: element,
154
+ leaf: subtree.leaf
155
+ };
156
+ }
157
+ }
158
+ return undefined;
159
+ }
160
+ //# sourceMappingURL=annotation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotation.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/annotation.ts"],"names":[],"mappings":";;;AACA,yEAAwG;AAGxG,qFAA8F;AAC9F,4CAAoD;AAGpD,oDAA2C;AAE3C,0CA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,KAAK,CAAC,CAAC,CAAC,IAAA,iCAAS,EAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC7E,IAAI,OAAO,CAAC,IAAI,CAAC,IAAI,4CAAsB,EAAE;gBACzC,MAAM,MAAM,GAAG,IAAA,+CAAiB,EAAC;oBAC7B,IAAI,2BAAY;oBAChB,KAAK;oBACL,YAAY,EAAE,KAAK;iBACtB,CAAC,CAAC;gBACH,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;gBAClC,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;aAChC;iBAAM;gBACH,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;aACtC;YAED,OAAO,CAAC,YAAY,GAAG,KAAK,CAAC,CAAC,CAAC,IAAA,iCAAS,EAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAE5D,OAAO;gBACH,IAAI,EAAE,OAAO;gBACb,IAAI,EAAE,OAAO,CAAC,IAAI;aACrB,CAAC;SACL;KACJ;IACD,OAAO,SAAS,CAAC;AACrB,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { BooleanLiteral } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const booleanHandler: NodeHandler<BooleanLiteral>;
4
+ //# sourceMappingURL=boolean.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/boolean.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAKpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,eAAO,MAAM,cAAc,EAAE,WAAW,CAAC,cAAc,CAiBtD,CAAC"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.booleanHandler = void 0;
4
+ const cds_annotation_parser_1 = require("@sap-ux/cds-annotation-parser");
5
+ const odata_annotation_core_types_1 = require("@sap-ux/odata-annotation-core-types");
6
+ exports.booleanHandler = {
7
+ type: cds_annotation_parser_1.BOOLEAN_TYPE,
8
+ convert(state, node) {
9
+ let text = '';
10
+ if (node.value === true) {
11
+ text = 'true';
12
+ }
13
+ else if (node.value === false) {
14
+ text = 'false';
15
+ }
16
+ const element = (0, odata_annotation_core_types_1.createElementNode)({
17
+ name: "Bool" /* Edm.Bool */,
18
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
19
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, false),
20
+ content: [(0, odata_annotation_core_types_1.createTextNode)(text, (0, cds_annotation_parser_1.nodeRange)(node, false))]
21
+ });
22
+ return element;
23
+ }
24
+ };
25
+ //# sourceMappingURL=boolean.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"boolean.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/boolean.ts"],"names":[],"mappings":";;;AACA,yEAAwE;AAExE,qFAA6F;AAKhF,QAAA,cAAc,GAAgC;IACvD,IAAI,EAAE,oCAAY;IAClB,OAAO,CAAC,KAAmB,EAAE,IAAoB;QAC7C,IAAI,IAAI,GAAG,EAAE,CAAC;QACd,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,EAAE;YACrB,IAAI,GAAG,MAAM,CAAC;SACjB;aAAM,IAAI,IAAI,CAAC,KAAK,KAAK,KAAK,EAAE;YAC7B,IAAI,GAAG,OAAO,CAAC;SAClB;QACD,MAAM,OAAO,GAAY,IAAA,+CAAiB,EAAC;YACvC,IAAI,uBAAU;YACd,KAAK,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,IAAI,CAAC;YAC5B,YAAY,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,KAAK,CAAC;YACpC,OAAO,EAAE,CAAC,IAAA,4CAAc,EAAC,IAAI,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;SAC1D,CAAC,CAAC;QACH,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { Collection } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const collectionHandler: NodeHandler<Collection>;
4
+ //# sourceMappingURL=collection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/collection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAQhF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,eAAO,MAAM,iBAAiB,EAAE,WAAW,CAAC,UAAU,CAmBrD,CAAC"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.collectionHandler = void 0;
4
+ const cds_annotation_parser_1 = require("@sap-ux/cds-annotation-parser");
5
+ const odata_annotation_core_types_1 = require("@sap-ux/odata-annotation-core-types");
6
+ const odata_vocabularies_1 = require("@sap-ux/odata-vocabularies");
7
+ const enum_1 = require("./enum");
8
+ exports.collectionHandler = {
9
+ type: cds_annotation_parser_1.COLLECTION_TYPE,
10
+ getChildren,
11
+ convert(state, node) {
12
+ const valueType = state.context.valueType;
13
+ const vocabularyType = valueType ? state.vocabularyService.getType(valueType) : undefined;
14
+ state.pushContext(Object.assign(Object.assign({}, state.context), { isCollection: false }));
15
+ if (valueType && (vocabularyType === null || vocabularyType === void 0 ? void 0 : vocabularyType.kind) === odata_vocabularies_1.ENUM_TYPE_KIND) {
16
+ return (0, enum_1.convertFlags)(state, node, valueType);
17
+ }
18
+ const element = (0, odata_annotation_core_types_1.createElementNode)({
19
+ name: "Collection" /* Edm.Collection */,
20
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
21
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, false)
22
+ });
23
+ return element;
24
+ }
25
+ };
26
+ /**
27
+ * Gets the children of a collection node based on the provided visitor state and collection node.
28
+ *
29
+ * @param state - The visitor state.
30
+ * @param node - The collection node.
31
+ * @returns The array of children nodes.
32
+ */
33
+ function getChildren(state, node) {
34
+ const valueType = state.context.valueType;
35
+ const vocabularyType = valueType ? state.vocabularyService.getType(valueType) : undefined;
36
+ if ((vocabularyType === null || vocabularyType === void 0 ? void 0 : vocabularyType.kind) === odata_vocabularies_1.ENUM_TYPE_KIND) {
37
+ return [];
38
+ }
39
+ return node.items;
40
+ }
41
+ //# sourceMappingURL=collection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"collection.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/collection.ts"],"names":[],"mappings":";;;AACA,yEAA2E;AAG3E,qFAA6E;AAE7E,mEAA4D;AAI5D,iCAAsC;AAEzB,QAAA,iBAAiB,GAA4B;IACtD,IAAI,EAAE,uCAAe;IACrB,WAAW;IACX,OAAO,CAAC,KAAmB,EAAE,IAAgB;QACzC,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;QAC1C,MAAM,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;QAE1F,KAAK,CAAC,WAAW,iCAAM,KAAK,CAAC,OAAO,KAAE,YAAY,EAAE,KAAK,IAAG,CAAC;QAC7D,IAAI,SAAS,IAAI,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,MAAK,mCAAc,EAAE;YACtD,OAAO,IAAA,mBAAY,EAAC,KAAK,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC;SAC/C;QACD,MAAM,OAAO,GAAY,IAAA,+CAAiB,EAAC;YACvC,IAAI,mCAAgB;YACpB,KAAK,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,IAAI,CAAC;YAC5B,YAAY,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,KAAK,CAAC;SACvC,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ,CAAC;AAEF;;;;;;GAMG;AACH,SAAS,WAAW,CAAC,KAAmB,EAAE,IAAgB;IACtD,MAAM,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;IAC1C,MAAM,cAAc,GAAG,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,iBAAiB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1F,IAAI,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,MAAK,mCAAc,EAAE;QACzC,OAAO,EAAE,CAAC;KACb;IACD,OAAO,IAAI,CAAC,KAAK,CAAC;AACtB,CAAC"}
@@ -0,0 +1,51 @@
1
+ import type { Element } from '@sap-ux/odata-annotation-core';
2
+ import type { AnnotationNode, Record, StringLiteral, BooleanLiteral, NumberLiteral, AnnotationValue, RecordProperty } from '@sap-ux/cds-annotation-parser';
3
+ import { RECORD_TYPE, STRING_LITERAL_TYPE, COLLECTION_TYPE, EMPTY_VALUE_TYPE, BOOLEAN_TYPE, NUMBER_LITERAL_TYPE } from '@sap-ux/cds-annotation-parser';
4
+ import type { VisitorState } from '../visitor-state';
5
+ /**
6
+ *
7
+ */
8
+ export declare class EdmJsonVisitor {
9
+ private state;
10
+ isElementPathKind: (elementName: string) => boolean;
11
+ /**
12
+ *
13
+ * @param state - The visitor state.
14
+ */
15
+ constructor(state: VisitorState);
16
+ /**
17
+ * Visits the given AnnotationNode and invokes the corresponding visitor function based on the node type.
18
+ *
19
+ * @param node - The AnnotationNode to be visited.
20
+ * @returns Returns an Element or undefined based on the visitor function for the given node type.
21
+ */
22
+ visit(node: AnnotationNode): Element | undefined;
23
+ [RECORD_TYPE]: (record: Record) => Element | undefined;
24
+ /**
25
+ * Converts a RecordProperty representing an attribute into an Element and adds it to the provided Element.
26
+ *
27
+ * @param property - The RecordProperty representing the attribute.
28
+ * @param element - The Element to which the attribute will be added.
29
+ */
30
+ convertAttribute(property: RecordProperty, element: Element): void;
31
+ /**
32
+ * Converts an element name based on the provided RecordProperty and Element.
33
+ *
34
+ * @param property - The RecordProperty containing the element name.
35
+ * @param element - The Element to be converted.
36
+ */
37
+ convertElementName(property: RecordProperty, element: Element): void;
38
+ /**
39
+ * Converts a collection of AnnotationValue items into Elements and adds them to the provided Element.
40
+ *
41
+ * @param items - The collection of AnnotationValue items to be converted.
42
+ * @param element - The Element to which the converted items will be added.
43
+ */
44
+ convertCollection(items: AnnotationValue[], element: Element): void;
45
+ [COLLECTION_TYPE]: () => Element | undefined;
46
+ [EMPTY_VALUE_TYPE]: () => Element | undefined;
47
+ [STRING_LITERAL_TYPE]: (node: StringLiteral) => Element | undefined;
48
+ [BOOLEAN_TYPE]: (node: BooleanLiteral) => Element | undefined;
49
+ [NUMBER_LITERAL_TYPE]: (node: NumberLiteral) => Element | undefined;
50
+ }
51
+ //# sourceMappingURL=edm-json.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edm-json.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/edm-json.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAY,MAAM,+BAA+B,CAAC;AAIvE,OAAO,KAAK,EACR,cAAc,EACd,MAAM,EACN,aAAa,EACb,cAAc,EACd,aAAa,EACb,eAAe,EACf,cAAc,EACjB,MAAM,+BAA+B,CAAC;AACvC,OAAO,EACH,WAAW,EAEX,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,YAAY,EACZ,mBAAmB,EACtB,MAAM,+BAA+B,CAAC;AAEvC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAcrD;;GAEG;AACH,qBAAa,cAAc;IAcX,OAAO,CAAC,KAAK;IAbzB,iBAAiB,gBAAiB,MAAM,KAAG,OAAO,CAQhD;IACF;;;OAGG;gBACiB,KAAK,EAAE,YAAY;IAEvC;;;;;OAKG;IACH,KAAK,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,GAAG,SAAS;IAQhD,CAAC,WAAW,CAAC,WAAY,MAAM,KAAG,OAAO,GAAG,SAAS,CA8BnD;IAEF;;;;;OAKG;IACH,gBAAgB,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAgBlE;;;;;OAKG;IACH,kBAAkB,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IAoBpE;;;;;OAKG;IACH,iBAAiB,CAAC,KAAK,EAAE,eAAe,EAAE,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI;IASnE,CAAC,eAAe,CAAC,QAAO,OAAO,GAAG,SAAS,CAEzC;IACF,CAAC,gBAAgB,CAAC,QAAO,OAAO,GAAG,SAAS,CAE1C;IACF,CAAC,mBAAmB,CAAC,SAAU,aAAa,KAAG,OAAO,GAAG,SAAS,CAQhE;IACF,CAAC,YAAY,CAAC,SAAU,cAAc,KAAG,OAAO,GAAG,SAAS,CAc1D;IAEF,CAAC,mBAAmB,CAAC,SAAU,aAAa,KAAG,OAAO,GAAG,SAAS,CAMhE;CACL"}
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ var _a, _b, _c, _d, _e, _f;
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.EdmJsonVisitor = void 0;
5
+ const odata_annotation_core_1 = require("@sap-ux/odata-annotation-core");
6
+ const vscode_languageserver_types_1 = require("vscode-languageserver-types");
7
+ const cds_annotation_parser_1 = require("@sap-ux/cds-annotation-parser");
8
+ const i18n_1 = require("../../../i18n");
9
+ const number_1 = require("./number");
10
+ const handler_1 = require("../handler");
11
+ /**
12
+ *
13
+ */
14
+ class EdmJsonVisitor {
15
+ /**
16
+ *
17
+ * @param state - The visitor state.
18
+ */
19
+ constructor(state) {
20
+ this.state = state;
21
+ this.isElementPathKind = (elementName) => {
22
+ return [
23
+ "Path" /* Edm.Path */,
24
+ "PropertyPath" /* Edm.PropertyPath */,
25
+ "AnnotationPath" /* Edm.AnnotationPath */,
26
+ "ModelElementPath" /* Edm.ModelElementPath */,
27
+ "NavigationPropertyPath" /* Edm.NavigationPropertyPath */
28
+ ].includes(elementName);
29
+ };
30
+ this[_a] = (record) => {
31
+ var _g, _h, _j;
32
+ const element = (0, odata_annotation_core_1.createElementNode)({
33
+ name: '',
34
+ range: (0, cds_annotation_parser_1.nodeRange)(record, true),
35
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(record, false)
36
+ });
37
+ for (let i = 0; i < record.properties.length; i++) {
38
+ const property = record.properties[i];
39
+ if (property.name.value.startsWith('$')) {
40
+ if (i === 0) {
41
+ this.convertElementName(property, element);
42
+ }
43
+ else if (cds_annotation_parser_1.STRING_LITERAL_TYPE === ((_g = property.value) === null || _g === void 0 ? void 0 : _g.type) || cds_annotation_parser_1.EMPTY_VALUE_TYPE === ((_h = property.value) === null || _h === void 0 ? void 0 : _h.type)) {
44
+ this.convertAttribute(property, element);
45
+ }
46
+ else if ((_j = property.value) === null || _j === void 0 ? void 0 : _j.range) {
47
+ this.state.addDiagnostic({
48
+ range: property.value.range,
49
+ severity: vscode_languageserver_types_1.DiagnosticSeverity.Error,
50
+ message: i18n_1.i18n.t('The_attribute_value_must_be_a_string_literal')
51
+ });
52
+ }
53
+ }
54
+ }
55
+ if (element.name === '') {
56
+ // failed to determine element name -> we can't generate a correct element
57
+ return undefined;
58
+ }
59
+ return element;
60
+ };
61
+ this[_b] = () => {
62
+ return undefined;
63
+ };
64
+ this[_c] = () => {
65
+ return undefined;
66
+ };
67
+ this[_d] = (node) => {
68
+ const textNode = (0, odata_annotation_core_1.createTextNode)(node.value, (0, cds_annotation_parser_1.nodeRange)(node, false));
69
+ return (0, odata_annotation_core_1.createElementNode)({
70
+ name: "String" /* Edm.String */,
71
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
72
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, false),
73
+ content: [textNode]
74
+ });
75
+ };
76
+ this[_e] = (node) => {
77
+ let text = '';
78
+ if (node.value === true) {
79
+ text = 'true';
80
+ }
81
+ else if (node.value === false) {
82
+ text = 'false';
83
+ }
84
+ const element = (0, odata_annotation_core_1.createElementNode)({
85
+ name: "Bool" /* Edm.Bool */,
86
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
87
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, false),
88
+ content: [(0, odata_annotation_core_1.createTextNode)(text, (0, cds_annotation_parser_1.nodeRange)(node, false))]
89
+ });
90
+ return element;
91
+ };
92
+ this[_f] = (node) => {
93
+ const result = number_1.numberHandler.convert(this.state, node);
94
+ if (result === undefined || (0, handler_1.isSubtree)(result)) {
95
+ return undefined;
96
+ }
97
+ return result;
98
+ };
99
+ }
100
+ /**
101
+ * Visits the given AnnotationNode and invokes the corresponding visitor function based on the node type.
102
+ *
103
+ * @param node - The AnnotationNode to be visited.
104
+ * @returns Returns an Element or undefined based on the visitor function for the given node type.
105
+ */
106
+ visit(node) {
107
+ const visitor = this[node.type];
108
+ if (visitor) {
109
+ return visitor(node);
110
+ }
111
+ else {
112
+ return undefined;
113
+ }
114
+ }
115
+ /**
116
+ * Converts a RecordProperty representing an attribute into an Element and adds it to the provided Element.
117
+ *
118
+ * @param property - The RecordProperty representing the attribute.
119
+ * @param element - The Element to which the attribute will be added.
120
+ */
121
+ convertAttribute(property, element) {
122
+ var _g;
123
+ if (property.value) {
124
+ const name = property.name.value.substring(1);
125
+ element.attributes[name] = (0, odata_annotation_core_1.createAttributeNode)(name, ((_g = property.value) === null || _g === void 0 ? void 0 : _g.type) === cds_annotation_parser_1.STRING_LITERAL_TYPE ? property.value.value : '', (0, cds_annotation_parser_1.nodeRange)(property.name, false), property.value.range);
126
+ if (property.value.type === cds_annotation_parser_1.STRING_LITERAL_TYPE && this.isElementPathKind(name)) {
127
+ this.state.addPath(property.value.value);
128
+ }
129
+ }
130
+ }
131
+ /**
132
+ * Converts an element name based on the provided RecordProperty and Element.
133
+ *
134
+ * @param property - The RecordProperty containing the element name.
135
+ * @param element - The Element to be converted.
136
+ */
137
+ convertElementName(property, element) {
138
+ var _g, _h;
139
+ element.name = property.name.value.substring(1);
140
+ element.nameRange = property.name.range;
141
+ if (((_g = property.value) === null || _g === void 0 ? void 0 : _g.type) === cds_annotation_parser_1.STRING_LITERAL_TYPE) {
142
+ const textNode = (0, odata_annotation_core_1.createTextNode)(property.value.value, (0, cds_annotation_parser_1.nodeRange)(property.value, false));
143
+ element.content = [textNode];
144
+ if (this.isElementPathKind(element.name)) {
145
+ this.state.addPath(property.value.value);
146
+ }
147
+ }
148
+ else if (((_h = property.value) === null || _h === void 0 ? void 0 : _h.type) === cds_annotation_parser_1.COLLECTION_TYPE) {
149
+ // Record is used as a container for a single element here
150
+ this.convertCollection(property.value.items, element);
151
+ }
152
+ else if (property.value) {
153
+ const child = this.visit(property.value);
154
+ if (child) {
155
+ element.content.push(child);
156
+ }
157
+ }
158
+ }
159
+ /**
160
+ * Converts a collection of AnnotationValue items into Elements and adds them to the provided Element.
161
+ *
162
+ * @param items - The collection of AnnotationValue items to be converted.
163
+ * @param element - The Element to which the converted items will be added.
164
+ */
165
+ convertCollection(items, element) {
166
+ for (const item of items) {
167
+ const child = this.visit(item);
168
+ if (child) {
169
+ element.content.push(child);
170
+ }
171
+ }
172
+ }
173
+ }
174
+ exports.EdmJsonVisitor = EdmJsonVisitor;
175
+ _a = cds_annotation_parser_1.RECORD_TYPE, _b = cds_annotation_parser_1.COLLECTION_TYPE, _c = cds_annotation_parser_1.EMPTY_VALUE_TYPE, _d = cds_annotation_parser_1.STRING_LITERAL_TYPE, _e = cds_annotation_parser_1.BOOLEAN_TYPE, _f = cds_annotation_parser_1.NUMBER_LITERAL_TYPE;
176
+ //# sourceMappingURL=edm-json.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"edm-json.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/edm-json.ts"],"names":[],"mappings":";;;;AACA,yEAA4G;AAE5G,6EAAiE;AAUjE,yEAQuC;AACvC,wCAAqC;AAErC,qCAAyC;AACzC,wCAAuC;AAYvC;;GAEG;AACH,MAAa,cAAc;IAUvB;;;OAGG;IACH,YAAoB,KAAmB;QAAnB,UAAK,GAAL,KAAK,CAAc;QAbvC,sBAAiB,GAAG,CAAC,WAAmB,EAAW,EAAE;YACjD,OAAO;;;;;;aAMN,CAAC,QAAQ,CAAC,WAAkB,CAAC,CAAC;QACnC,CAAC,CAAC;QAqBF,QAAa,GAAG,CAAC,MAAc,EAAuB,EAAE;;YACpD,MAAM,OAAO,GAAY,IAAA,yCAAiB,EAAC;gBACvC,IAAI,EAAE,EAAE;gBACR,KAAK,EAAE,IAAA,iCAAS,EAAC,MAAM,EAAE,IAAI,CAAC;gBAC9B,YAAY,EAAE,IAAA,iCAAS,EAAC,MAAM,EAAE,KAAK,CAAC;aACzC,CAAC,CAAC;YAEH,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;gBAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;gBACtC,IAAI,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;oBACrC,IAAI,CAAC,KAAK,CAAC,EAAE;wBACT,IAAI,CAAC,kBAAkB,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;qBAC9C;yBAAM,IAAI,2CAAmB,MAAK,MAAA,QAAQ,CAAC,KAAK,0CAAE,IAAI,CAAA,IAAI,wCAAgB,MAAK,MAAA,QAAQ,CAAC,KAAK,0CAAE,IAAI,CAAA,EAAE;w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AE;YACjD,0DAA0D;YAC1D,IAAI,CAAC,iBAAiB,CAAC,QAAQ,CAAC,KAAK,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;SACzD;aAAM,IAAI,QAAQ,CAAC,KAAK,EAAE;YACvB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACzC,IAAI,KAAK,EAAE;gBACP,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC/B;SACJ;IACL,CAAC;IAED;;;;;OAKG;IACH,iBAAiB,CAAC,KAAwB,EAAE,OAAgB;QACxD,KAAK,MAAM,IAAI,IAAI,KAAK,EAAE;YACtB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAC/B,IAAI,KAAK,EAAE;gBACP,OAAO,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;aAC/B;SACJ;IACL,CAAC;CAwCJ;AAnKD,wCAmKC;KArII,mCAAW,OA+FX,uCAAe,OAGf,wCAAgB,OAGhB,2CAAmB,OASnB,oCAAY,OAgBZ,2CAAmB"}
@@ -0,0 +1,24 @@
1
+ import type { Collection, Enum } from '@sap-ux/cds-annotation-parser';
2
+ import type { Element } from '@sap-ux/odata-annotation-core-types';
3
+ import type { NodeHandler } from '../handler';
4
+ import type { VisitorState } from '../visitor-state';
5
+ /**
6
+ * Delimiter between two enum values, used for flags
7
+ */
8
+ export declare const ENUM_VALUE_DELIMITER = " ";
9
+ /**
10
+ * Delimiter between enum type and member name
11
+ */
12
+ export declare const ENUM_MEMBER_DELIMITER = "/";
13
+ export declare const toEnumValue: (type: string, memberName: string) => string;
14
+ export declare const enumHandler: NodeHandler<Enum>;
15
+ /**
16
+ * Converts collection items representing flags (enums) into an EnumMember element.
17
+ *
18
+ * @param state - The visitor state.
19
+ * @param node - The collection node containing enum items.
20
+ * @param valueType - The type of the enum values.
21
+ * @returns An EnumMember element representing the converted flags.
22
+ */
23
+ export declare function convertFlags(state: VisitorState, node: Collection, valueType: string): Element;
24
+ //# sourceMappingURL=enum.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/enum.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,+BAA+B,CAAC;AAGtE,OAAO,KAAK,EAAE,OAAO,EAAS,MAAM,qCAAqC,CAAC;AAG1E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAErD;;GAEG;AACH,eAAO,MAAM,oBAAoB,MAAM,CAAC;AACxC;;GAEG;AACH,eAAO,MAAM,qBAAqB,MAAM,CAAC;AAEzC,eAAO,MAAM,WAAW,SAAU,MAAM,cAAc,MAAM,KAAG,MAAwD,CAAC;AACxH,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,IAAI,CAqBzC,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAuB9F"}