@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,96 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getTerm = exports.getFullyQualifiedType = exports.getPropertyType = exports.getImplicitPropertyType = void 0;
4
+ /**
5
+ * Gets the implicit property type based on the provided vocabulary service, context, and property name.
6
+ *
7
+ * @param vocabularyService - The vocabulary service.
8
+ * @param context - The context containing recordType, termType, etc.
9
+ * @param propertyName - The name of the property for which to get the type.
10
+ * @returns The implicit property type or undefined if not found.
11
+ */
12
+ function getImplicitPropertyType(vocabularyService, context, propertyName) {
13
+ var _a;
14
+ let baseType;
15
+ if (context.recordType) {
16
+ baseType = getFullyQualifiedType(vocabularyService, context.recordType);
17
+ }
18
+ if (!baseType && context.termType) {
19
+ baseType = (_a = vocabularyService.getTerm(context.termType)) === null || _a === void 0 ? void 0 : _a.type;
20
+ }
21
+ return getPropertyTypeFromBaseType(vocabularyService, baseType, propertyName);
22
+ }
23
+ exports.getImplicitPropertyType = getImplicitPropertyType;
24
+ /**
25
+ * Gets the property type from the provided vocabulary service based on the specified record type and property name.
26
+ *
27
+ * @param vocabularyService - The vocabulary service.
28
+ * @param recordType - The record type for which to retrieve the property type.
29
+ * @param propertyName - The name of the property for which to get the type.
30
+ * @returns The property type or undefined if not found.
31
+ */
32
+ function getPropertyType(vocabularyService, recordType, propertyName) {
33
+ if (!recordType) {
34
+ return undefined;
35
+ }
36
+ const baseType = getFullyQualifiedType(vocabularyService, recordType);
37
+ return getPropertyTypeFromBaseType(vocabularyService, baseType, propertyName);
38
+ }
39
+ exports.getPropertyType = getPropertyType;
40
+ /**
41
+ * Gets the property type from the base type using the provided vocabulary service, base type, and property name.
42
+ *
43
+ * @param vocabularyService - The vocabulary service.
44
+ * @param baseType - The base type from which to retrieve the property type.
45
+ * @param propertyName - The name of the property for which to get the type.
46
+ * @returns The property type or undefined if not found.
47
+ */
48
+ function getPropertyTypeFromBaseType(vocabularyService, baseType, propertyName) {
49
+ if (!baseType) {
50
+ return undefined;
51
+ }
52
+ const derivedTypeNames = [...vocabularyService.getDerivedTypeNames(baseType)];
53
+ for (const derivedTypeName of derivedTypeNames) {
54
+ const propertyType = vocabularyService.getComplexTypeProperty(derivedTypeName, propertyName);
55
+ if (propertyType) {
56
+ return propertyType;
57
+ }
58
+ }
59
+ return undefined;
60
+ }
61
+ /**
62
+ *
63
+ * @param service - The vocabulary service.
64
+ * @param type - The type string to be qualified.
65
+ * @returns The fully qualified type string or undefined if the namespace is not found.
66
+ */
67
+ function getFullyQualifiedType(service, type) {
68
+ const [simpleIdentifier] = type.split('.').slice(-1);
69
+ const namespace = service.getVocabularyNamespace(type);
70
+ if (namespace) {
71
+ return [namespace, simpleIdentifier].join('.');
72
+ }
73
+ return undefined;
74
+ }
75
+ exports.getFullyQualifiedType = getFullyQualifiedType;
76
+ /**
77
+ * Gets a term from the provided vocabulary service based on the specified vocabulary name or alias and term name.
78
+ *
79
+ * @param vocabularyService - The vocabulary service.
80
+ * @param vocabularyNameOrAlias - The name or alias of the vocabulary.
81
+ * @param termName - The name of the term to retrieve, if available.
82
+ * @returns The retrieved term or undefined if not found.
83
+ */
84
+ function getTerm(vocabularyService, vocabularyNameOrAlias, termName) {
85
+ const vocabulary = vocabularyService.getVocabulary(vocabularyNameOrAlias);
86
+ if (vocabulary && termName) {
87
+ const fullyQualifiedTermName = [vocabulary.namespace, termName].join('.');
88
+ const term = vocabularyService.getTerm(fullyQualifiedTermName);
89
+ if (term) {
90
+ return term;
91
+ }
92
+ }
93
+ return undefined;
94
+ }
95
+ exports.getTerm = getTerm;
96
+ //# sourceMappingURL=type-resolver.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"type-resolver.js","sourceRoot":"","sources":["../../../src/transforms/annotation/type-resolver.ts"],"names":[],"mappings":";;;AAIA;;;;;;;GAOG;AACH,SAAgB,uBAAuB,CACnC,iBAAoC,EACpC,OAAgB,EAChB,YAAoB;;IAEpB,IAAI,QAA4B,CAAC;IACjC,IAAI,OAAO,CAAC,UAAU,EAAE;QACpB,QAAQ,GAAG,qBAAqB,CAAC,iBAAiB,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;KAC3E;IACD,IAAI,CAAC,QAAQ,IAAI,OAAO,CAAC,QAAQ,EAAE;QAC/B,QAAQ,GAAG,MAAA,iBAAiB,CAAC,OAAO,CAAC,OAAO,CAAC,QAAQ,CAAC,0CAAE,IAAI,CAAC;KAChE;IACD,OAAO,2BAA2B,CAAC,iBAAiB,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAClF,CAAC;AAbD,0DAaC;AACD;;;;;;;GAOG;AACH,SAAgB,eAAe,CAC3B,iBAAoC,EACpC,UAA8B,EAC9B,YAAoB;IAEpB,IAAI,CAAC,UAAU,EAAE;QACb,OAAO,SAAS,CAAC;KACpB;IACD,MAAM,QAAQ,GAAG,qBAAqB,CAAC,iBAAiB,EAAE,UAAU,CAAC,CAAC;IAEtE,OAAO,2BAA2B,CAAC,iBAAiB,EAAE,QAAQ,EAAE,YAAY,CAAC,CAAC;AAClF,CAAC;AAXD,0CAWC;AAED;;;;;;;GAOG;AACH,SAAS,2BAA2B,CAChC,iBAAoC,EACpC,QAA4B,EAC5B,YAAoB;IAEpB,IAAI,CAAC,QAAQ,EAAE;QACX,OAAO,SAAS,CAAC;KACpB;IACD,MAAM,gBAAgB,GAAG,CAAC,GAAG,iBAAiB,CAAC,mBAAmB,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9E,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;QAC5C,MAAM,YAAY,GAAG,iBAAiB,CAAC,sBAAsB,CAAC,eAAe,EAAE,YAAY,CAAC,CAAC;QAC7F,IAAI,YAAY,EAAE;YACd,OAAO,YAAY,CAAC;SACvB;KACJ;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAED;;;;;GAKG;AACH,SAAgB,qBAAqB,CAAC,OAA0B,EAAE,IAAY;IAC1E,MAAM,CAAC,gBAAgB,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;IACrD,MAAM,SAAS,GAAG,OAAO,CAAC,sBAAsB,CAAC,IAAI,CAAC,CAAC;IACvD,IAAI,SAAS,EAAE;QACX,OAAO,CAAC,SAAS,EAAE,gBAAgB,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;KAClD;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAPD,sDAOC;AAED;;;;;;;GAOG;AACH,SAAgB,OAAO,CACnB,iBAAoC,EACpC,qBAA6B,EAC7B,QAA4B;IAE5B,MAAM,UAAU,GAAG,iBAAiB,CAAC,aAAa,CAAC,qBAAqB,CAAC,CAAC;IAC1E,IAAI,UAAU,IAAI,QAAQ,EAAE;QACxB,MAAM,sBAAsB,GAAG,CAAC,UAAU,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC1E,MAAM,IAAI,GAAG,iBAAiB,CAAC,OAAO,CAAC,sBAAsB,CAAC,CAAC;QAC/D,IAAI,IAAI,EAAE;YACN,OAAO,IAAI,CAAC;SACf;KACJ;IACD,OAAO,SAAS,CAAC;AACrB,CAAC;AAdD,0BAcC"}
@@ -0,0 +1,81 @@
1
+ import type { Diagnostic, Element, Position } from '@sap-ux/odata-annotation-core-types';
2
+ import type { VocabularyService } from '@sap-ux/odata-vocabularies';
3
+ export interface Context {
4
+ /**
5
+ * Record type that comes from text and is using alias.
6
+ */
7
+ recordType?: string;
8
+ termType?: string;
9
+ /**
10
+ * Alias used in annotation group.
11
+ */
12
+ groupName?: string;
13
+ valueType?: string;
14
+ isCollection?: boolean;
15
+ /**
16
+ * Name of property (during parsing of it's value)
17
+ */
18
+ propertyName?: string;
19
+ /**
20
+ * In this context only annotations and $value property is allowed, everything else is ignored.
21
+ */
22
+ inValueContainer?: boolean;
23
+ }
24
+ /**
25
+ * Contains current state of CDS annotation visitor
26
+ */
27
+ export declare class VisitorState {
28
+ vocabularyService: VocabularyService;
29
+ position?: Position | undefined;
30
+ elementStack: Element[];
31
+ /**
32
+ * @returns context
33
+ */
34
+ get context(): Context;
35
+ /**
36
+ * Gets the depth of the context stack.
37
+ *
38
+ * @type {number}
39
+ * @returns The depth of the context stack represents the number of items.
40
+ * currently present in the stack.
41
+ */
42
+ get contextDepth(): number;
43
+ /**
44
+ * @returns array of diagnostics array.
45
+ */
46
+ get diagnostics(): Diagnostic[];
47
+ /**
48
+ * Gets the set of paths stored in the instance.
49
+ *
50
+ * @type {Set<string>}
51
+ * @readonly
52
+ * @returns a set contains unique path strings.
53
+ */
54
+ get pathSet(): Set<string>;
55
+ private _contextStack;
56
+ private _diagnostics;
57
+ private _pathSet;
58
+ /**
59
+ *
60
+ * @param vocabularyService - The vocabulary service associated with the instance.
61
+ * @param [position] - The optional position associated with the instance.
62
+ */
63
+ constructor(vocabularyService: VocabularyService, position?: Position | undefined);
64
+ /**
65
+ *
66
+ * @param context context.
67
+ */
68
+ pushContext(context: Context): void;
69
+ popContext(): void;
70
+ /**
71
+ *
72
+ * @param diagnostic - The diagnostic to be added.
73
+ */
74
+ addDiagnostic(diagnostic: Diagnostic): void;
75
+ /**
76
+ *
77
+ * @param path - The path to be added.
78
+ */
79
+ addPath(path: string): void;
80
+ }
81
+ //# sourceMappingURL=visitor-state.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitor-state.d.ts","sourceRoot":"","sources":["../../../src/transforms/annotation/visitor-state.ts"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ule", { value: true });
3
+ exports.VisitorState = void 0;
4
+ /**
5
+ * Contains current state of CDS annotation visitor
6
+ */
7
+ class VisitorState {
8
+ /**
9
+ * @returns context
10
+ */
11
+ get context() {
12
+ const context = this._contextStack[this._contextStack.length - 1];
13
+ if (context) {
14
+ return context;
15
+ }
16
+ return {};
17
+ }
18
+ /**
19
+ * Gets the depth of the context stack.
20
+ *
21
+ * @type {number}
22
+ * @returns The depth of the context stack represents the number of items.
23
+ * currently present in the stack.
24
+ */
25
+ get contextDepth() {
26
+ return this._contextStack.length;
27
+ }
28
+ /**
29
+ * @returns array of diagnostics array.
30
+ */
31
+ get diagnostics() {
32
+ return this._diagnostics;
33
+ }
34
+ /**
35
+ * Gets the set of paths stored in the instance.
36
+ *
37
+ * @type {Set<string>}
38
+ * @readonly
39
+ * @returns a set contains unique path strings.
40
+ */
41
+ get pathSet() {
42
+ return this._pathSet;
43
+ }
44
+ /**
45
+ *
46
+ * @param vocabularyService - The vocabulary service associated with the instance.
47
+ * @param [position] - The optional position associated with the instance.
48
+ */
49
+ constructor(vocabularyService, position) {
50
+ this.vocabularyService = vocabularyService;
51
+ this.position = position;
52
+ this.elementStack = [];
53
+ this._contextStack = [];
54
+ this._diagnostics = [];
55
+ this._pathSet = new Set();
56
+ }
57
+ // context
58
+ /**
59
+ *
60
+ * @param context context.
61
+ */
62
+ pushContext(context) {
63
+ this._contextStack.push(Object.seal(Object.assign({}, context)));
64
+ }
65
+ popContext() {
66
+ this._contextStack.splice(-1);
67
+ }
68
+ // collectors
69
+ /**
70
+ *
71
+ * @param diagnostic - The diagnostic to be added.
72
+ */
73
+ addDiagnostic(diagnostic) {
74
+ this._diagnostics.push(diagnostic);
75
+ }
76
+ /**
77
+ *
78
+ * @param path - The path to be added.
79
+ */
80
+ addPath(path) {
81
+ this._pathSet.add(path);
82
+ }
83
+ }
84
+ exports.VisitorState = VisitorState;
85
+ //# sourceMappingURL=visitor-state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vis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,CAAC,IAAY;QAChB,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACJ;AAnFD,oCAmFC"}
@@ -0,0 +1,17 @@
1
+ import type { AnnotationNode } from '@sap-ux/cds-annotation-parser';
2
+ import type { Element } from '@sap-ux/odata-annotation-core-types';
3
+ import type { VisitorState } from './visitor-state';
4
+ /**
5
+ *
6
+ */
7
+ export declare class Visitor {
8
+ /**
9
+ *
10
+ * @param state - The visitor state.
11
+ * @param node - The annotation node to be visited.
12
+ * @returns The converted element or undefined if no conversion is performed.
13
+ */
14
+ visit(state: VisitorState, node: AnnotationNode): Element | undefined;
15
+ }
16
+ export declare const visitor: Visitor;
17
+ //# sourceMappingURL=visitor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitor.d.ts","sourceRoot":"","sources":["../../../src/transforms/annotation/visitor.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,+BAA+B,CAAC;AACpE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,qCAAqC,CAAC;AAMnE,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAEpD;;GAEG;AACH,qBAAa,OAAO;IAChB;;;;;OAKG;IACH,KAAK,CAAC,KAAK,EAAE,YAAY,EAAE,IAAI,EAAE,cAAc,GAAG,OAAO,GAAG,SAAS;CAuCxE;AAuBD,eAAO,MAAM,OAAO,SAAgB,CAAC"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.visitor = exports.Visitor = void 0;
4
+ const handlers_1 = require("./handlers");
5
+ const handler_1 = require("./handler");
6
+ /**
7
+ *
8
+ */
9
+ class Visitor {
10
+ /**
11
+ *
12
+ * @param state - The visitor state.
13
+ * @param node - The annotation node to be visited.
14
+ * @returns The converted element or undefined if no conversion is performed.
15
+ */
16
+ visit(state, node) {
17
+ const handler = handlers_1.nodeHandlerConfig[node.type];
18
+ if (!handler) {
19
+ return undefined;
20
+ }
21
+ const contextDepth = state.contextDepth;
22
+ const conversionResult = handler.convert(state, node);
23
+ const children = handler.getChildren ? handler.getChildren(state, node) : [];
24
+ if (!conversionResult && children.length === 0 && state.elementStack.length === 0) {
25
+ return undefined;
26
+ }
27
+ const [root, leaf] = processConversionResult(state.elementStack[state.elementStack.length - 1], conversionResult);
28
+ if (conversionResult) {
29
+ state.elementStack.push(leaf);
30
+ }
31
+ for (const child of children) {
32
+ const childElement = this.visit(state, child);
33
+ if (childElement) {
34
+ leaf.content.push(childElement);
35
+ }
36
+ }
37
+ if (conversionResult) {
38
+ state.elementStack.pop();
39
+ }
40
+ while (state.contextDepth > contextDepth) {
41
+ state.popContext();
42
+ }
43
+ return root;
44
+ }
45
+ }
46
+ exports.Visitor = Visitor;
47
+ /**
48
+ * Process the conversion result and return a tuple of elements.
49
+ *
50
+ * @param leaf - The leaf element.
51
+ * @param result - The conversion result.
52
+ * @returns A tuple containing the root and leaf elements.
53
+ * - If the result is undefined, returns [undefined, leaf].
54
+ * - If the result is a subtree, returns [result.root, result.leaf].
55
+ * - Otherwise, returns [result, result].
56
+ */
57
+ function processConversionResult(leaf, result) {
58
+ if (result === undefined) {
59
+ // Use element from previous call, when current node is not converted
60
+ return [undefined, leaf];
61
+ }
62
+ if ((0, handler_1.isSubtree)(result)) {
63
+ return [result.root, result.leaf];
64
+ }
65
+ return [result, result];
66
+ }
67
+ exports.visitor = new Visitor();
68
+ //# sourceMappingURL=visitor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"visitor.js","sourceRoot":"","sources":["../../../src/transforms/annotation/visitor.ts"],"names":[],"mappings":";;;AAEA,yCAA+C;AAG/C,uCAAsC;AAItC;;GAEG;AACH,MAAa,OAAO;IAChB;;;;;OAKG;IACH,KAAK,CAAC,KAAmB,EAAE,IAAoB;QAC3C,MAAM,OAAO,GAAG,4BAAiB,CAAC,IAAI,CAAC,IAAI,CAA2C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EAAE,MAAqB;IACjE,IAAI,MAAM,KAAK,SAAS,EAAE;QACtB,qEAAqE;QACrE,OAAO,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;KAC5B;IACD,IAAI,IAAA,mBAAS,EAAC,MAAM,CAAC,EAAE;QACnB,OAAO,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,CAAC;KACrC;IACD,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAC5B,CAAC;AAEY,QAAA,OAAO,GAAG,IAAI,OAAO,EAAE,CAAC"}
@@ -0,0 +1,31 @@
1
+ import { Position, Range } from 'vscode-languageserver-types';
2
+ import type { Assignment } from '@sap-ux/cds-annotation-parser';
3
+ import type { CdsVocabulary, VocabularyService } from '@sap-ux/odata-vocabularies';
4
+ import type { AnnotationAssignmentToken, FileIndex, IdentifierToken, MetadataCollector, CdsCompilerFacade, PropagatedTargetMap } from '@sap/ux-cds-compiler-facade';
5
+ import { TARGET_TYPE } from '@sap-ux/odata-annotation-core';
6
+ import type { Namespace, AnnotationFile, PositionPointer, Diagnostic, Reference } from '@sap-ux/odata-annotation-core';
7
+ export { TARGET_TYPE } from '@sap-ux/odata-annotation-core-types';
8
+ export declare const adjustCdsTermNames: (assignment: Assignment, cdsVocabulary: CdsVocabulary) => Assignment;
9
+ export declare const toAssignment: (annotation: AnnotationAssignmentToken, vocabularyService: VocabularyService) => Assignment;
10
+ export interface Target {
11
+ type: typeof TARGET_TYPE;
12
+ name: string;
13
+ kind: string;
14
+ nameRange?: Range;
15
+ range?: Range;
16
+ assignments: Assignment[];
17
+ }
18
+ export declare const toTarget: (carrier: IdentifierToken | undefined, carrierName: string, compilerFacade?: CdsCompilerFacade) => Target;
19
+ export interface CdsAnnotationFile {
20
+ namespace?: Namespace;
21
+ references: Reference[];
22
+ targetMap: Map<string, Target>;
23
+ }
24
+ export declare const toTargetMap: (fileIndex: FileIndex, uri: string, vocabularyService: VocabularyService, cdsCompilerFacade?: CdsCompilerFacade) => CdsAnnotationFile;
25
+ export declare const toAnnotationFile: (fileUri: string, vocabularyService: VocabularyService, cdsAnnotationFile: CdsAnnotationFile, metadataCollector: MetadataCollector, position?: Position, propagationMap?: PropagatedTargetMap) => {
26
+ file: AnnotationFile;
27
+ pointer?: string | undefined;
28
+ nodeRange?: Range | undefined;
29
+ diagnostics?: Diagnostic[] | undefined;
30
+ };
31
+ //# sourceMappingURL=annotation-file.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"annotation-file.d.ts","sourceRoot":"","sources":["../../src/transforms/annotation-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,6BAA6B,CAAC;AAG9D,OAAO,KAAK,EAA+B,UAAU,EAAc,MAAM,+BAA+B,CAAC;AACzG,OAAO,KAAK,EAAE,aAAa,EAAE,iBAAiB,EAAE,MAAM,4BAA4B,CAAC;AAEnF,OAAO,KAAK,EACR,yBAAyB,EACzB,SAAS,EACT,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACtB,MAAM,6BAA6B,CAAC;AAIrC,OAAO,EAIH,WAAW,EAOd,MAAM,+BAA+B,CAAC;AACvC,OAAO,KAAK,EACR,SAAS,EACT,cAAc,EACd,eAAe,EAEf,UAAU,EACV,SAAS,EACZ,MAAM,+BAA+B,CAAC;AAIvC,OAAO,EAAE,WAAW,EAAE,MAAM,qCAAqC,CAAC;AA2BlE,eAAO,MAAM,kBAAkB,eAAgB,UAAU,iBAAiB,aAAa,KAAG,UAkCzF,CAAC;AA+BF,eAAO,MAAM,YAAY,eACT,yBAAyB,qBAClB,iBAAiB,KACrC,UAiBF,CAAC;AAEF,MAAM,WAAW,MAAM;IACnB,IAAI,EAAE,OAAO,WAAW,CAAC;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,KAAK,CAAC;IAClB,KAAK,CAAC,EAAE,KAAK,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