@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,69 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertFlags = exports.enumHandler = exports.toEnumValue = exports.ENUM_MEMBER_DELIMITER = exports.ENUM_VALUE_DELIMITER = 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
+ /**
7
+ * Delimiter between two enum values, used for flags
8
+ */
9
+ exports.ENUM_VALUE_DELIMITER = ' ';
10
+ /**
11
+ * Delimiter between enum type and member name
12
+ */
13
+ exports.ENUM_MEMBER_DELIMITER = '/';
14
+ const toEnumValue = (type, memberName) => [type, memberName].join(exports.ENUM_MEMBER_DELIMITER);
15
+ exports.toEnumValue = toEnumValue;
16
+ exports.enumHandler = {
17
+ type: cds_annotation_parser_1.ENUM_TYPE,
18
+ convert(state, node) {
19
+ if (!state.context.valueType) {
20
+ return;
21
+ }
22
+ const enumValue = (0, exports.toEnumValue)(state.context.valueType, node.path.value);
23
+ const textNode = (0, odata_annotation_core_types_1.createTextNode)(enumValue, (0, cds_annotation_parser_1.nodeRange)(node, false));
24
+ const enumFragmentRange = (0, cds_annotation_parser_1.nodeRange)(node, true);
25
+ if (enumFragmentRange) {
26
+ textNode.fragmentRanges = [enumFragmentRange];
27
+ }
28
+ return (0, odata_annotation_core_types_1.createElementNode)({
29
+ name: "EnumMember" /* Edm.EnumMember */,
30
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
31
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, false),
32
+ content: [textNode]
33
+ });
34
+ }
35
+ };
36
+ /**
37
+ * Converts collection items representing flags (enums) into an EnumMember element.
38
+ *
39
+ * @param state - The visitor state.
40
+ * @param node - The collection node containing enum items.
41
+ * @param valueType - The type of the enum values.
42
+ * @returns An EnumMember element representing the converted flags.
43
+ */
44
+ function convertFlags(state, node, valueType) {
45
+ // Alternative is to provide conversion diagnostics
46
+ const enums = node.items.filter((item) => item.type === cds_annotation_parser_1.ENUM_TYPE);
47
+ const segments = [];
48
+ const fragmentRanges = [];
49
+ let invalidRanges = false;
50
+ for (const enumNode of enums) {
51
+ const enumValue = (0, exports.toEnumValue)(valueType, enumNode.path.value);
52
+ segments.push(enumValue);
53
+ if (enumNode.range) {
54
+ fragmentRanges.push((0, cds_annotation_parser_1.copyRange)(enumNode.range));
55
+ }
56
+ else {
57
+ invalidRanges = true;
58
+ }
59
+ }
60
+ const value = segments.join(exports.ENUM_VALUE_DELIMITER);
61
+ return (0, odata_annotation_core_types_1.createElementNode)({
62
+ name: "EnumMember" /* Edm.EnumMember */,
63
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
64
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, false),
65
+ content: [(0, odata_annotation_core_types_1.createTextNode)(value, (0, cds_annotation_parser_1.nodeRange)(node, false), invalidRanges ? undefined : fragmentRanges)]
66
+ });
67
+ }
68
+ exports.convertFlags = convertFlags;
69
+ //# sourceMappingURL=enum.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"enum.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/enum.ts"],"names":[],"mappings":";;;AACA,yEAAgF;AAGhF,qFAA6F;AAK7F;;GAEG;AACU,QAAA,oBAAoB,GAAG,GAAG,CAAC;AACxC;;GAEG;AACU,QAAA,qBAAqB,GAAG,GAAG,CAAC;AAElC,MAAM,WAAW,GAAG,CAAC,IAAY,EAAE,U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;IACnC,IAAI,aAAa,GAAG,KAAK,CAAC;IAC1B,KAAK,MAAM,QAAQ,IAAI,KAAK,EAAE;QAC1B,MAAM,SAAS,GAAG,IAAA,mBAAW,EAAC,SAAS,EAAE,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QAC9D,QAAQ,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACzB,IAAI,QAAQ,CAAC,KAAK,EAAE;YAChB,cAAc,CAAC,IAAI,CAAC,IAAA,iCAAS,EAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,CAAC;SAClD;aAAM;YACH,aAAa,GAAG,IAAI,CAAC;SACxB;KACJ;IAED,MAAM,KAAK,GAAG,QAAQ,CAAC,IAAI,CAAC,4BAAoB,CAAC,CAAC;IAClD,OAAO,IAAA,+CAAiB,EAAC;QACrB,IAAI,mCAAgB;QACpB,KAAK,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,IAAI,CAAC;QAC5B,YAAY,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,KAAK,CAAC;QACpC,OAAO,EAAE,CAAC,IAAA,4CAAc,EAAC,KAAK,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,KAAK,CAAC,EAAE,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,cAAc,CAAC,CAAC;KACvG,CAAC,CAAC;AACP,CAAC;AAvBD,oCAuBC"}
@@ -0,0 +1,6 @@
1
+ import type { IncorrectExpression, CorrectExpression, UnsupportedOperatorExpression } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const correctExpressionHandler: NodeHandler<CorrectExpression>;
4
+ export declare const incorrectExpressionHandler: NodeHandler<IncorrectExpression>;
5
+ export declare const unknownOperatorExpressionHandler: NodeHandler<UnsupportedOperatorExpression>;
6
+ //# sourceMappingURL=expression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/expression.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAER,mBAAmB,EACnB,iBAAiB,EACjB,6BAA6B,EAChC,MAAM,+BAA+B,CAAC;AAavC,OAAO,KAAK,EAAiB,WAAW,EAAW,MAAM,YAAY,CAAC;AAGtE,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAAC,iBAAiB,CAqBnE,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,WAAW,CAAC,mBAAmB,CAKvE,CAAC;AAGF,eAAO,MAAM,gCAAgC,EAAE,WAAW,CAAC,6BAA6B,CAcvF,CAAC"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.unknownOperatorExpressionHandler = exports.incorrectExpressionHandler = exports.correctExpressionHandler = 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.correctExpressionHandler = {
7
+ type: cds_annotation_parser_1.CORRECT_EXPRESSION_TYPE,
8
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
9
+ getChildren(state, expression) {
10
+ if ((0, cds_annotation_parser_1.containsIncorrectExpressions)(expression)) {
11
+ return [];
12
+ }
13
+ return expression.operands;
14
+ },
15
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
16
+ convert(state, expression) {
17
+ var _a;
18
+ if ((0, cds_annotation_parser_1.containsIncorrectExpressions)(expression)) {
19
+ return;
20
+ }
21
+ const noContentRange = { line: 0, character: 0 };
22
+ const startRange = (0, cds_annotation_parser_1.nodeRange)(expression.operands[0], true);
23
+ const contentRangeStart = startRange === null || startRange === void 0 ? void 0 : startRange.start;
24
+ const contentRangeEnd = (_a = (0, cds_annotation_parser_1.nodeRange)(expression.operands[expression.operands.length - 1], true)) === null || _a === void 0 ? void 0 : _a.end;
25
+ const contentRange = { start: contentRangeStart !== null && contentRangeStart !== void 0 ? contentRangeStart : noContentRange, end: contentRangeEnd !== null && contentRangeEnd !== void 0 ? contentRangeEnd : noContentRange };
26
+ return buildElementForOperator(expression, contentRange);
27
+ }
28
+ };
29
+ // incorrect expressions appear as empty values in generic annotation file
30
+ exports.incorrectExpressionHandler = {
31
+ type: cds_annotation_parser_1.INCORRECT_EXPRESSION_TYPE,
32
+ convert() {
33
+ return;
34
+ }
35
+ };
36
+ // expressions with unknown operators appear as nodes with name of unknown operator only (no other operators, no operands as sub nodes)
37
+ exports.unknownOperatorExpressionHandler = {
38
+ type: cds_annotation_parser_1.UNSUPPORTED_OPERATOR_EXPRESSION_TYPE,
39
+ getChildren() {
40
+ return [];
41
+ },
42
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
43
+ convert(state, expression) {
44
+ const element = (0, odata_annotation_core_types_1.createElementNode)({
45
+ name: expression.unsupportedOperator.value,
46
+ nameRange: expression.unsupportedOperator.range,
47
+ range: expression.unsupportedOperator.range
48
+ });
49
+ return element;
50
+ }
51
+ };
52
+ /**
53
+ *
54
+ * @param expression correct expression.
55
+ * @param contentRange element content range.
56
+ * @returns element or subtree containing all the info of range, name. content range..
57
+ */
58
+ function buildElementForOperator(expression, contentRange) {
59
+ var _a;
60
+ const operatorDefinition = cds_annotation_parser_1.operatorMap[expression.operatorName];
61
+ const edmName = (_a = operatorDefinition.edmName) !== null && _a !== void 0 ? _a : '';
62
+ const elementName = edmName.startsWith('odata.') ? "Apply" /* Edm.Apply */ : edmName;
63
+ const element = (0, odata_annotation_core_types_1.createElementNode)({
64
+ name: elementName,
65
+ contentRange,
66
+ range: (0, cds_annotation_parser_1.nodeRange)(expression, true)
67
+ });
68
+ const operatorRange = expression.operators[0].range;
69
+ if (elementName === "Apply" /* Edm.Apply */) {
70
+ element.attributes = {
71
+ ["Function" /* Edm.Function */]: (0, odata_annotation_core_types_1.createAttributeNode)("Function" /* Edm.Function */, edmName, undefined, operatorRange)
72
+ };
73
+ }
74
+ else {
75
+ element.nameRange = operatorRange;
76
+ }
77
+ if (operatorDefinition.edmName && operatorDefinition.edmNot) {
78
+ // wrap valid edm node into 'Not' expression
79
+ const notElement = (0, odata_annotation_core_types_1.createElementNode)({
80
+ name: "Not" /* Edm.Not */,
81
+ nameRange: operatorRange,
82
+ contentRange,
83
+ content: [element]
84
+ });
85
+ return { root: notElement, leaf: element };
86
+ }
87
+ else {
88
+ element.contentRange = contentRange;
89
+ return element;
90
+ }
91
+ }
92
+ //# sourceMappingURL=expression.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expression.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/expression.ts"],"names":[],"mappings":";;;AAMA,yEAOuC;AAGvC,qFAAkG;AAKrF,QAAA,wBAAwB,GAAmC;IACpE,IAAI,EAAE,+CAAuB;IAC7B,6DAA6D;IAC7D,WAAW,CAAC,KAAmB,EAAE,UAA6B;QAC1D,IAAI,IAAA,oDAA4B,EAAC,UAAU,CAAC,EAAE;YAC1C,OAAO,EAAE,CAAC;SACb;QACD,OAAO,UAAU,CAAC,QAAQ,CAAC;IAC/B,CAAC;IACD,6DAA6D;IAC7D,OAAO,CAAC,KAAmB,EAAE,UAA6B;;QACtD,IAAI,IAAA,oDAA4B,EAAC,UAAU,CAAC,EAAE;YAC1C,OAAO;SACV;QACD,MAAM,cAAc,GAAG,EAAE,IAAI,EAAE,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,CAAC;QACjD,MAAM,UAAU,GAAG,IAAA,iCAAS,EAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QAC3D,MAAM,iBAAiB,GAAG,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,KAAK,CAAC;QAC5C,MAAM,eAAe,GAAG,MAAA,IAAA,iCAAS,EAAC,UAAU,CAAC,QAAQ,CAAC,UAAU,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,0CAAE,GAAG,CAAC;QAClG,MAAM,YAAY,GAA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C,CAAC,CAAC;IACH,MAAM,aAAa,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;IACpD,IAAI,WAAW,4BAAc,EAAE;QAC3B,OAAO,CAAC,UAAU,GAAG;YACjB,+BAAc,EAAE,IAAA,iDAAmB,iCAAe,OAAO,EAAE,SAAS,EAAE,aAAa,CAAC;SACvF,CAAC;KACL;SAAM;QACH,OAAO,CAAC,SAAS,GAAG,aAAa,CAAC;KACrC;IACD,IAAI,kBAAkB,CAAC,OAAO,IAAI,kBAAkB,CAAC,MAAM,EAAE;QACzD,4CAA4C;QAC5C,MAAM,UAAU,GAAY,IAAA,+CAAiB,EAAC;YAC1C,IAAI,qBAAS;YACb,SAAS,EAAE,aAAa;YACxB,YAAY;YACZ,OAAO,EAAE,CAAC,OAAO,CAAC;SACrB,CAAC,CAAC;QACH,OAAO,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAa,CAAC;KACzD;SAAM;QACH,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;QACpC,OAAO,OAAO,CAAC;KAClB;AACL,CAAC"}
@@ -0,0 +1,7 @@
1
+ import type { AnnotationNode } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export type NodeHandlerConfig = {
4
+ [Node in AnnotationNode as Node['type']]?: NodeHandler<Node>;
5
+ };
6
+ export declare const nodeHandlerConfig: NodeHandlerConfig;
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAEpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAc9C,MAAM,MAAM,iBAAiB,GAAG;KAC3B,IAAI,IAAI,cAAc,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,WAAW,CAAC,IAAI,CAAC;CAC/D,CAAC;AAEF,eAAO,MAAM,iBAAiB,EAAE,iBAgB/B,CAAC"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nodeHandlerConfig = void 0;
4
+ const annotation_1 = require("./annotation");
5
+ const collection_1 = require("./collection");
6
+ const record_1 = require("./record");
7
+ const record_property_1 = require("./record-property");
8
+ const boolean_1 = require("./boolean");
9
+ const enum_1 = require("./enum");
10
+ const expression_1 = require("./expression");
11
+ const number_1 = require("./number");
12
+ const string_1 = require("./string");
13
+ const quoted_literal_1 = require("./quoted-literal");
14
+ const path_1 = require("./path");
15
+ const token_1 = require("./token");
16
+ exports.nodeHandlerConfig = {
17
+ [annotation_1.annotationHandler.type]: annotation_1.annotationHandler,
18
+ [record_1.recordHandler.type]: record_1.recordHandler,
19
+ [record_property_1.recordPropertyHandler.type]: record_property_1.recordPropertyHandler,
20
+ [collection_1.collectionHandler.type]: collection_1.collectionHandler,
21
+ [boolean_1.booleanHandler.type]: boolean_1.booleanHandler,
22
+ [string_1.stringHandler.type]: string_1.stringHandler,
23
+ [string_1.multiLineStringHandler.type]: string_1.multiLineStringHandler,
24
+ [enum_1.enumHandler.type]: enum_1.enumHandler,
25
+ [expression_1.correctExpressionHandler.type]: expression_1.correctExpressionHandler,
26
+ [expression_1.unknownOperatorExpressionHandler.type]: expression_1.unknownOperatorExpressionHandler,
27
+ [expression_1.incorrectExpressionHandler.type]: expression_1.incorrectExpressionHandler,
28
+ [number_1.numberHandler.type]: number_1.numberHandler,
29
+ [quoted_literal_1.quotedLiteralHandler.type]: quoted_literal_1.quotedLiteralHandler,
30
+ [path_1.pathHandler.type]: path_1.pathHandler,
31
+ [token_1.tokenHandler.type]: token_1.tokenHandler
32
+ };
33
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/index.ts"],"names":[],"mappings":";;;AAGA,6CAAiD;AACjD,6CAAiD;AACjD,qCAAyC;AACzC,uDAA0D;AAC1D,uCAA2C;AAC3C,iCAAqC;AACrC,6CAAsH;AACtH,qCAAyC;AACzC,qCAAiE;AACjE,qDAAwD;AACxD,iCAAqC;AACrC,mCAAuC;AAM1B,QAAA,iBAAiB,GAAsB;IAChD,CAAC,8BAAiB,CAAC,IAAI,CAAC,EAAE,8BAAiB;IAC3C,CAAC,sBAAa,CAAC,IAAI,CAAC,EAAE,sBAAa;IACnC,CAAC,uCAAqB,CAAC,IAAI,CAAC,EAAE,uCAAqB;IACnD,CAAC,8BAAiB,CAAC,IAAI,CAAC,EAAE,8BAAiB;IAC3C,CAAC,wBAAc,CAAC,IAAI,CAAC,EAAE,wBAAc;IACrC,CAAC,sBAAa,CAAC,IAAI,CAAC,EAAE,sBAAa;IACnC,CAAC,+BAAsB,CAAC,IAAI,CAAC,EAAE,+BAAsB;IACrD,CAAC,kBAAW,CAAC,IAAI,CAAC,EAAE,kBAAW;IAC/B,CAAC,qCAAwB,CAAC,IAAI,CAAC,EAAE,qCAAwB;IACzD,CAAC,6CAAgC,CAAC,IAAI,CAAC,EAAE,6CAAgC;IACzE,CAAC,uCAA0B,CAAC,IAAI,CAAC,EAAE,uCAA0B;IAC7D,CAAC,sBAAa,CAAC,IAAI,CAAC,EAAE,sBAAa;IACnC,CAAC,qCAAoB,CAAC,IAAI,CAAC,EAAE,qCAAoB;IACjD,CAAC,kBAAW,CAAC,IAAI,CAAC,EAAE,kBAAW;IAC/B,CAAC,oBAAY,CAAC,IAAI,CAAC,EAAE,oBAAY;CACpC,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { NumberLiteral } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const numberHandler: NodeHandler<NumberLiteral>;
4
+ /**
5
+ * Determines the corresponding Edm type for the given type name and value.
6
+ *
7
+ * @param typeName - The type name to be considered.
8
+ * @param value - The value for which the Edm type is determined.
9
+ * @returns The corresponding Edm type.
10
+ */
11
+ export declare function getNumberType(typeName: string | undefined, value: number | string): string;
12
+ //# sourceMappingURL=number.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAKnE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,eAAO,MAAM,aAAa,EAAE,WAAW,CAAC,aAAa,CAWpD,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,SAAS,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAqB1F"}
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getNumberType = exports.numberHandler = 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.numberHandler = {
7
+ type: cds_annotation_parser_1.NUMBER_LITERAL_TYPE,
8
+ convert(state, node) {
9
+ const elementName = getNumberType(state.context.valueType, node.value);
10
+ return (0, odata_annotation_core_types_1.createElementNode)({
11
+ name: elementName,
12
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
13
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, true),
14
+ content: [(0, odata_annotation_core_types_1.createTextNode)(node.value.toString(), (0, cds_annotation_parser_1.nodeRange)(node, false))]
15
+ });
16
+ }
17
+ };
18
+ /**
19
+ * Determines the corresponding Edm type for the given type name and value.
20
+ *
21
+ * @param typeName - The type name to be considered.
22
+ * @param value - The value for which the Edm type is determined.
23
+ * @returns The corresponding Edm type.
24
+ */
25
+ function getNumberType(typeName, value) {
26
+ if (typeName === 'Edm.Decimal') {
27
+ return "Decimal" /* Edm.Decimal */;
28
+ }
29
+ if (typeName === 'Edm.Double' || typeName === 'Edm.Single') {
30
+ return "Float" /* Edm.Float */;
31
+ }
32
+ if (typeName === 'Edm.Int64') {
33
+ return "Int" /* Edm.Int */;
34
+ }
35
+ if (typeof value === 'number') {
36
+ if (typeName === 'Edm.String') {
37
+ return "String" /* Edm.String */;
38
+ }
39
+ if (Number.isInteger(value)) {
40
+ return "Int" /* Edm.Int */;
41
+ }
42
+ // cds has no number literals which can only be represented as float value, see url://pages.github.tools.sap/cap/docs/cds/types
43
+ return "Decimal" /* Edm.Decimal */;
44
+ }
45
+ return "String" /* Edm.String */;
46
+ }
47
+ exports.getNumberType = getNumberType;
48
+ //# sourceMappingURL=number.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"number.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/number.ts"],"names":[],"mappings":";;;AACA,yEAA+E;AAE/E,qFAA6F;AAKhF,QAAA,aAAa,GAA+B;IACrD,IAAI,EAAE,2CAAmB;IACzB,OAAO,CAAC,KAAmB,EAAE,IAAmB;QAC5C,MAAM,WAAW,GAAG,aAAa,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QACvE,OAAO,IAAA,+CAAiB,EAAC;YACrB,IAAI,EAAE,WAAW;YACjB,KAAK,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,IAAI,CAAC;YAC5B,YAAY,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,IAAI,CAAC;YACnC,OAAO,EAAE,CAAC,IAAA,4CAAc,EAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,EAAE,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,KAAK,CAAC,CAAC,CAAC;SAC3E,CAAC,CAAC;IACP,CAAC;CACJ,CAAC;AAEF;;;;;;GAMG;AACH,SAAgB,aAAa,CAAC,QAA4B,EAAE,KAAsB;IAC9E,IAAI,QAAQ,KAAK,aAAa,EAAE;QAC5B,mCAAmB;KACtB;IACD,IAAI,QAAQ,KAAK,YAAY,IAAI,QAAQ,KAAK,YAAY,EAAE;QACxD,+BAAiB;KACpB;IACD,IAAI,QAAQ,KAAK,WAAW,EAAE;QAC1B,2BAAe;KAClB;IACD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;QAC3B,IAAI,QAAQ,KAAK,YAAY,EAAE;YAC3B,iCAAkB;SACrB;QACD,IAAI,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE;YACzB,2BAAe;SAClB;QACD,+HAA+H;QAC/H,mCAAmB;KACtB;IACD,iCAAkB;AACtB,CAAC;AArBD,sCAqBC"}
@@ -0,0 +1,4 @@
1
+ import type { Path } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const pathHandler: NodeHandler<Path>;
4
+ //# sourceMappingURL=path.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,IAAI,EAAyB,MAAM,+BAA+B,CAAC;AAuBjF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAK9C,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,IAAI,CAuBzC,CAAC"}
@@ -0,0 +1,193 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.pathHandler = 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 i18n_1 = require("../../../i18n");
7
+ const path_utils_1 = require("../path-utils");
8
+ exports.pathHandler = {
9
+ type: cds_annotation_parser_1.PATH_TYPE,
10
+ convert(state, node) {
11
+ var _a;
12
+ const elementName = (_a = (state.context.valueType ? (0, path_utils_1.pathLikeTypeElementName)(state.context.valueType) : undefined)) !== null && _a !== void 0 ? _a : "Path" /* Edm.Path */;
13
+ const pathText = node.value
14
+ .split('@')
15
+ .map((segment, i) => (i === 0 ? segment.replace(/\./g, '/') : segment))
16
+ .join('@');
17
+ const fragmentRanges = calculateFragmentRanges(state, node);
18
+ state.addPath(pathText);
19
+ const element = (0, odata_annotation_core_types_1.createElementNode)({
20
+ name: elementName,
21
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true),
22
+ contentRange: (0, cds_annotation_parser_1.nodeRange)(node, false),
23
+ content: [(0, odata_annotation_core_types_1.createTextNode)(pathText, (0, cds_annotation_parser_1.nodeRange)(node, false), fragmentRanges)]
24
+ });
25
+ return element;
26
+ }
27
+ };
28
+ /**
29
+ * Fragment ranges are calculated as following.
30
+ * before first @ all '.' chars have been replaced by '/', hence every segment considered as fragment.
31
+ * after first @ fragments are parts separated by '/', i.e. dots are not separators of fragments in that region.
32
+ *
33
+ * @param state - The visitor state.
34
+ * @param node - The path node containing segments and separators.
35
+ * @returns An array of fragment ranges derived from the positions of segments and separators.
36
+ */
37
+ function calculateFragmentRanges(state, node) {
38
+ const tokens = [...node.segments, ...node.separators].sort((a, b) => {
39
+ var _a, _b, _c, _d, _e, _f, _g, _h;
40
+ const startA = (_b = (_a = a.range) === null || _a === void 0 ? void 0 : _a.start) === null || _b === void 0 ? void 0 : _b.character;
41
+ const startB = (_d = (_c = b.range) === null || _c === void 0 ? void 0 : _c.start) === null || _d === void 0 ? void 0 : _d.character;
42
+ if (startA && startB && startA !== startB) {
43
+ return startA - startB;
44
+ }
45
+ const endA = (_f = (_e = a.range) === null || _e === void 0 ? void 0 : _e.end) === null || _f === void 0 ? void 0 : _f.character;
46
+ const endB = (_h = (_g = b.range) === null || _g === void 0 ? void 0 : _g.end) === null || _h === void 0 ? void 0 : _h.character;
47
+ if (endA && endB) {
48
+ return endA - endB;
49
+ }
50
+ return 0;
51
+ });
52
+ const fragments = convertToFragments(state, node, tokens);
53
+ return fragments.map((fragment) => fragment.range);
54
+ }
55
+ /**
56
+ * Converts the segments of a Path node into Fragments, handling both data model segments and annotation references.
57
+ *
58
+ * @param state - The VisitorState object managing the state during the visit.
59
+ * @param node - The Path node representing the path.
60
+ * @param tokens - The array of Identifier or Separator tokens representing the path segments.
61
+ * @returns An array of Fragments representing the converted segments of the path.
62
+ */
63
+ function convertToFragments(state, node, tokens) {
64
+ // If any of the token range is not defined,
65
+ // then we can't generate fragment ranges correctly => no ranges are returned
66
+ const fragments = [];
67
+ let i = 0;
68
+ // Process data model segments (until first annotation reference starting with @)
69
+ for (; i < tokens.length; i++) {
70
+ const token = tokens[i];
71
+ if (token.type === cds_annotation_parser_1.IDENTIFIER_TYPE) {
72
+ if (token.value.includes('@')) {
73
+ // segment referencing annotation is found
74
+ break;
75
+ }
76
+ if (!token.range) {
77
+ return [];
78
+ }
79
+ const fragment = {
80
+ image: token.value,
81
+ range: (0, cds_annotation_parser_1.copyRange)(token.range)
82
+ };
83
+ fragments.push(fragment);
84
+ }
85
+ else if (token.value === '/' && !token.escaped) {
86
+ pushWrongPathSeparatorDiagnostic(state, token);
87
+ }
88
+ }
89
+ const annotationFragments = processAnnotationSegments(state, node, tokens, i);
90
+ // TODO: check if we should actually include fragments with 0 length
91
+ // filtering fragments with no content to preserve existing behavior
92
+ return [...fragments, ...annotationFragments].filter((fragment) => fragment.image.length);
93
+ }
94
+ /**
95
+ * Processes the segments of an annotation path, extracting fragments and checking for missing path escaping.
96
+ *
97
+ * @param state - The VisitorState object managing the state during the visit.
98
+ * @param node - The Path node representing the path.
99
+ * @param tokens - The array of Identifier or Separator tokens representing the path segments.
100
+ * @param startIndex - The index indicating the start of the range in the tokens array.
101
+ * @returns An array of Fragments representing the processed segments of the annotation path.
102
+ */
103
+ function processAnnotationSegments(state, node, tokens, startIndex) {
104
+ const fragments = [];
105
+ let requiresEscaping = false;
106
+ let i = startIndex;
107
+ while (i < tokens.length) {
108
+ let token = tokens[i];
109
+ if (!token.range) {
110
+ return [];
111
+ }
112
+ const fragment = {
113
+ image: '',
114
+ range: odata_annotation_core_types_1.Range.create((0, cds_annotation_parser_1.copyPosition)(token.range.start), (0, cds_annotation_parser_1.copyPosition)(token.range.start))
115
+ };
116
+ while ((token === null || token === void 0 ? void 0 : token.type) === cds_annotation_parser_1.IDENTIFIER_TYPE || (token === null || token === void 0 ? void 0 : token.value) === '.') {
117
+ fragment.image += token.value;
118
+ if (fragment.range && token.range) {
119
+ fragment.range.end = (0, cds_annotation_parser_1.copyPosition)(token.range.end);
120
+ }
121
+ i++;
122
+ token = tokens[i];
123
+ if ((token === null || token === void 0 ? void 0 : token.type) === cds_annotation_parser_1.SEPARATOR_TYPE && token.value === '/' && !token.escaped) {
124
+ requiresEscaping = true;
125
+ }
126
+ }
127
+ fragments.push(fragment);
128
+ i++;
129
+ }
130
+ if (requiresEscaping) {
131
+ pushMissingPathEscapingDiagnostic(state, node, tokens, startIndex);
132
+ }
133
+ return fragments;
134
+ }
135
+ /**
136
+ * Pushes a diagnostic for missing path escaping brackets in the specified range of tokens.
137
+ *
138
+ * @param state - The VisitorState object managing the state during the visit.
139
+ * @param node - The Path node representing the path.
140
+ * @param tokens - The array of Identifier or Separator tokens representing the path segments.
141
+ * @param startIndex - The index indicating the start of the range in the tokens array.
142
+ */
143
+ function pushMissingPathEscapingDiagnostic(state, node, tokens, startIndex) {
144
+ const start = tokens[startIndex];
145
+ const end = tokens.slice(-1)[0];
146
+ if (!(start === null || start === void 0 ? void 0 : start.range) || !(end === null || end === void 0 ? void 0 : end.range)) {
147
+ return;
148
+ }
149
+ const pathSeparatorDiagnostic = {
150
+ rule: odata_annotation_core_types_1.ODATA_PATH_SEPARATOR_RULE,
151
+ message: i18n_1.i18n.t('Path_escaping_brackets_should_be_used'),
152
+ range: odata_annotation_core_types_1.Range.create((0, cds_annotation_parser_1.copyPosition)(start.range.start), (0, cds_annotation_parser_1.copyPosition)(end.range.end)),
153
+ severity: odata_annotation_core_types_1.DiagnosticSeverity.Warning
154
+ };
155
+ const valueToBeEscaped = '@' + node.value.split('@').slice(1).join('@');
156
+ const prefix = start.type === cds_annotation_parser_1.IDENTIFIER_TYPE && start.quoted ? '' : '![';
157
+ const suffix = ']';
158
+ // If there are existing escape sequences, we need to remove them
159
+ const body = valueToBeEscaped.replace(/[![\]]/g, '');
160
+ pathSeparatorDiagnostic.data = {
161
+ value: valueToBeEscaped,
162
+ proposedValue: prefix + body + suffix
163
+ };
164
+ state.addDiagnostic(pathSeparatorDiagnostic);
165
+ }
166
+ /**
167
+ * Pushes a diagnostic for a wrong path separator in the given token range.
168
+ *
169
+ * @param state - The VisitorState object managing the state during the visit.
170
+ * @param token - The Separator token representing the path separator.
171
+ */
172
+ function pushWrongPathSeparatorDiagnostic(state, token) {
173
+ if (!token.range) {
174
+ return;
175
+ }
176
+ // code action to correct wrong separator
177
+ const message = i18n_1.i18n.t('Wrong_path_separator_0_Did_you_mean_1', {
178
+ currentValue: '/',
179
+ proposedValue: '.',
180
+ interpolation: { escapeValue: false }
181
+ });
182
+ const diagnostic = odata_annotation_core_types_1.Diagnostic.create(token.range, message, odata_annotation_core_types_1.DiagnosticSeverity.Warning);
183
+ diagnostic.data = {
184
+ caseCheck: {
185
+ value: '/',
186
+ proposedValue: '.',
187
+ lookupPath: [],
188
+ isNamespacedValue: false
189
+ }
190
+ };
191
+ state.addDiagnostic(diagnostic);
192
+ }
193
+ //# sourceMappingURL=path.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"path.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/path.ts"],"names":[],"mappings":";;;AACA,yEAOuC;AAGvC,qFAQ6C;AAE7C,wCAAqC;AAKrC,8CAAwD;AAE3C,QAAA,WAAW,GAAsB;IAC1C,IAAI,EAAE,iCAAS;IACf,OAAO,CAAC,KAAmB,EAAE,IAAU;;QACnC,MAAM,WAAW,GACb,MAAA,CAAC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC,CAAC,IAAA,oCAAuB,EAAC,K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AAC,KAAK,CAAC,KAAK,EAAE,OAAO,EAAE,gDAAkB,CAAC,OAAO,CAAC,CAAC;IACvF,UAAU,CAAC,IAAI,GAAG;QACd,SAAS,EAAE;YACP,KAAK,EAAE,GAAG;YACV,aAAa,EAAE,GAAG;YAClB,UAAU,EAAE,EAAE;YACd,iBAAiB,EAAE,KAAK;SAC3B;KACJ,CAAC;IACF,KAAK,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC;AACpC,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { QuotedLiteral } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const quotedLiteralHandler: NodeHandler<QuotedLiteral>;
4
+ //# sourceMappingURL=quoted-literal.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quoted-literal.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/quoted-literal.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAqB,MAAM,+BAA+B,CAAC;AAKtF,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAG9C,eAAO,MAAM,oBAAoB,EAAE,WAAW,CAAC,aAAa,CAW3D,CAAC"}
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.quotedLiteralHandler = 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.quotedLiteralHandler = {
7
+ type: cds_annotation_parser_1.QUOTED_LITERAL_TYPE,
8
+ convert(state, node) {
9
+ const element = (0, odata_annotation_core_types_1.createElementNode)({
10
+ name: getElementNameForQuotedLiteral(node.kind),
11
+ nameRange: (0, cds_annotation_parser_1.nodeRange)(node, false),
12
+ range: (0, cds_annotation_parser_1.nodeRange)(node, true)
13
+ });
14
+ return element;
15
+ }
16
+ };
17
+ /**
18
+ *
19
+ * @param kind quoted string.
20
+ * @returns check case and return Edm (Time of Day, date, dateOffset or binary).
21
+ */
22
+ function getElementNameForQuotedLiteral(kind) {
23
+ switch (kind) {
24
+ case 'time':
25
+ return "TimeOfDay" /* Edm.TimeOfDay */;
26
+ case 'date':
27
+ return "Date" /* Edm.Date */;
28
+ case 'timestamp':
29
+ return "DateTimeOffset" /* Edm.DateTimeOffset */;
30
+ case 'binary':
31
+ return "Binary" /* Edm.Binary */;
32
+ default:
33
+ // Use 'assertNever' to handle exhaustiveness check
34
+ return assertNever(kind);
35
+ }
36
+ }
37
+ /**
38
+ * Throws an error indicating that a value should never be reached.
39
+ *
40
+ * @param value - The value that should never be reached.
41
+ */
42
+ function assertNever(value) {
43
+ throw new Error(`Unexpected value: ${value}`);
44
+ }
45
+ //# sourceMappingURL=quoted-literal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"quoted-literal.js","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/quoted-literal.ts"],"names":[],"mappings":";;;AACA,yEAA+E;AAE/E,qFAA6E;AAKhE,QAAA,oBAAoB,GAA+B;IAC5D,IAAI,EAAE,2CAAmB;IACzB,OAAO,CAAC,KAAmB,EAAE,IAAmB;QAC5C,MAAM,OAAO,GAAY,IAAA,+CAAiB,EAAC;YACvC,IAAI,EAAE,8BAA8B,CAAC,IAAI,CAAC,IAAI,CAAC;YAC/C,SAAS,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,KAAK,CAAC;YACjC,KAAK,EAAE,IAAA,iCAAS,EAAC,IAAI,EAAE,IAAI,CAAC;SAC/B,CAAC,CAAC;QAEH,OAAO,OAAO,CAAC;IACnB,CAAC;CACJ,CAAC;AAEF;;;;GAIG;AACH,SAAS,8BAA8B,CAAC,IAAuB;IAC3D,QAAQ,IAAI,EAAE;QACV,KAAK,MAAM;YACP,uCAAqB;QACzB,KAAK,MAAM;YACP,6BAAgB;QACpB,KAAK,WAAW;YACZ,iDAA0B;QAC9B,KAAK,QAAQ;YACT,iCAAkB;QACtB;YACI,mDAAmD;YACnD,OAAO,WAAW,CAAC,IAAI,CAAC,CAAC;KAChC;AACL,CAAC;AAED;;;;GAIG;AACH,SAAS,WAAW,CAAC,KAAY;IAC7B,MAAM,IAAI,KAAK,CAAC,qBAAqB,KAAK,EAAE,CAAC,CAAC;AAClD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import type { RecordProperty } from '@sap-ux/cds-annotation-parser';
2
+ import type { NodeHandler } from '../handler';
3
+ export declare const recordPropertyHandler: NodeHandler<RecordProperty>;
4
+ //# sourceMappingURL=record-property.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"record-property.d.ts","sourceRoot":"","sources":["../../../../src/transforms/annotation/handlers/record-property.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAkB,cAAc,EAAE,MAAM,+BAA+B,CAAC;AAOpF,OAAO,KAAK,EAAE,WAAW,EAAW,MAAM,YAAY,CAAC;AAKvD,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAAC,cAAc,CAsD7D,CAAC"}