@sap/cds-compiler 2.5.0 → 2.10.4

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 (92) hide show
  1. package/CHANGELOG.md +191 -9
  2. package/bin/cdsc.js +2 -2
  3. package/doc/CHANGELOG_BETA.md +33 -3
  4. package/lib/api/main.js +29 -101
  5. package/lib/api/options.js +15 -11
  6. package/lib/api/validate.js +12 -8
  7. package/lib/backends.js +0 -81
  8. package/lib/base/keywords.js +32 -2
  9. package/lib/base/message-registry.js +63 -9
  10. package/lib/base/messages.js +63 -21
  11. package/lib/base/model.js +2 -3
  12. package/lib/checks/defaultValues.js +27 -2
  13. package/lib/checks/elements.js +1 -6
  14. package/lib/checks/foreignKeys.js +0 -6
  15. package/lib/checks/managedWithoutKeys.js +17 -0
  16. package/lib/checks/nonexpandableStructured.js +38 -0
  17. package/lib/checks/onConditions.js +9 -45
  18. package/lib/checks/queryNoDbArtifacts.js +25 -7
  19. package/lib/checks/selectItems.js +25 -2
  20. package/lib/checks/types.js +26 -2
  21. package/lib/checks/unknownMagic.js +38 -0
  22. package/lib/checks/utils.js +61 -0
  23. package/lib/checks/validator.js +60 -7
  24. package/lib/compiler/assert-consistency.js +16 -7
  25. package/lib/compiler/builtins.js +2 -0
  26. package/lib/compiler/checks.js +6 -4
  27. package/lib/compiler/definer.js +99 -42
  28. package/lib/compiler/index.js +73 -27
  29. package/lib/compiler/resolver.js +288 -157
  30. package/lib/compiler/shared.js +31 -11
  31. package/lib/edm/annotations/genericTranslation.js +182 -186
  32. package/lib/edm/csn2edm.js +103 -108
  33. package/lib/edm/edm.js +18 -21
  34. package/lib/edm/edmPreprocessor.js +361 -114
  35. package/lib/edm/edmUtils.js +103 -33
  36. package/lib/gen/Dictionary.json +22 -0
  37. package/lib/gen/language.checksum +1 -1
  38. package/lib/gen/language.interp +12 -1
  39. package/lib/gen/language.tokens +57 -53
  40. package/lib/gen/languageLexer.interp +10 -1
  41. package/lib/gen/languageLexer.js +770 -744
  42. package/lib/gen/languageLexer.tokens +49 -46
  43. package/lib/gen/languageParser.js +4713 -4279
  44. package/lib/json/from-csn.js +103 -45
  45. package/lib/json/to-csn.js +296 -117
  46. package/lib/language/antlrParser.js +4 -3
  47. package/lib/language/errorStrategy.js +1 -0
  48. package/lib/language/genericAntlrParser.js +21 -12
  49. package/lib/language/language.g4 +99 -31
  50. package/lib/main.d.ts +81 -3
  51. package/lib/main.js +30 -7
  52. package/lib/model/api.js +78 -0
  53. package/lib/model/csnRefs.js +329 -142
  54. package/lib/model/csnUtils.js +235 -58
  55. package/lib/model/enrichCsn.js +18 -1
  56. package/lib/model/revealInternalProperties.js +2 -1
  57. package/lib/modelCompare/compare.js +37 -20
  58. package/lib/optionProcessor.js +9 -3
  59. package/lib/render/.eslintrc.json +4 -1
  60. package/lib/render/DuplicateChecker.js +8 -5
  61. package/lib/render/toCdl.js +112 -33
  62. package/lib/render/toHdbcds.js +134 -64
  63. package/lib/render/toSql.js +91 -38
  64. package/lib/render/utils/common.js +8 -13
  65. package/lib/render/utils/sql.js +3 -3
  66. package/lib/sql-identifier.js +6 -1
  67. package/lib/transform/db/assertUnique.js +5 -6
  68. package/lib/transform/db/constraints.js +29 -13
  69. package/lib/transform/db/draft.js +8 -6
  70. package/lib/transform/db/expansion.js +582 -0
  71. package/lib/transform/db/flattening.js +325 -0
  72. package/lib/transform/db/groupByOrderBy.js +2 -2
  73. package/lib/transform/db/transformExists.js +284 -63
  74. package/lib/transform/forHanaNew.js +98 -381
  75. package/lib/transform/forOdataNew.js +21 -22
  76. package/lib/transform/localized.js +37 -10
  77. package/lib/transform/odata/attachPath.js +19 -4
  78. package/lib/transform/odata/generateForeignKeyElements.js +11 -10
  79. package/lib/transform/odata/referenceFlattener.js +60 -39
  80. package/lib/transform/odata/sortByAssociationDependency.js +2 -2
  81. package/lib/transform/odata/structuralPath.js +72 -0
  82. package/lib/transform/odata/structureFlattener.js +19 -18
  83. package/lib/transform/odata/typesExposure.js +22 -12
  84. package/lib/transform/transformUtilsNew.js +134 -78
  85. package/lib/transform/translateAssocsToJoins.js +17 -14
  86. package/lib/transform/universalCsnEnricher.js +67 -0
  87. package/lib/utils/file.js +0 -11
  88. package/lib/utils/moduleResolve.js +6 -8
  89. package/package.json +1 -1
  90. package/lib/json/walker.js +0 -26
  91. package/lib/transform/sqlite +0 -0
  92. package/lib/utils/string.js +0 -17
@@ -0,0 +1,78 @@
1
+ // Miscellaneous CSN functions we put into our compiler API
2
+
3
+ // Do not change at will - they are in the compiler API!
4
+
5
+ /**
6
+ * Dictionary of default traversal functions for function `traverseCsn`.
7
+ * It maps CSN property names to functions which are used by default
8
+ * to traverse the CSN node which is the value of the corresponding property.
9
+ * Users specify their own traversal function via argument `userFunctions`.
10
+ *
11
+ * Each function in `userFunctions` and `defaultFunctions` is called with:
12
+ * - `userFunctions`
13
+ * - the current CSN node, i.e. ‹parent node›.‹property name›
14
+ * - the the ‹parent node›
15
+ * - the ‹property name› (might be useful if the same function is used for several props)
16
+ */
17
+ const defaultFunctions = {
18
+ '@': () => {}, // do not traverse annotation assignments
19
+ args: dictionary,
20
+ elements: dictionary,
21
+ enum: dictionary,
22
+ params: dictionary,
23
+ actions: dictionary,
24
+ mixin: dictionary,
25
+ definitions: dictionary,
26
+ '$': () => {}, // do not traverse properties starting with '$'
27
+ }
28
+
29
+ /**
30
+ * Traverse the CSN node `csn`.
31
+ * If `csn` is an array, call it recursively on each array item.
32
+ * If `csn` is an(other) object, call a function on each property:
33
+ * - The property name is a used as key in argument `userFunctions` and the
34
+ * constant `defaultFunctions` above to get the function which is called on
35
+ * the property value, see `defaultFunctions` for details.
36
+ * - If no function is found with the property name, try to find one with the first char.
37
+ * - If still not found, call `traverseCsn` recursively.
38
+ *
39
+ * The functions in `userFunctions` are usually transformer functions, which
40
+ * change the input CSN destructively.
41
+ */
42
+ function traverseCsn( userFunctions, csn ) {
43
+ if (!csn || typeof csn !== 'object')
44
+ return;
45
+ if (Array.isArray( csn )) {
46
+ csn.forEach( node => traverseCsn( userFunctions, node ) );
47
+ }
48
+ else {
49
+ for (const prop of Object.keys( csn )) {
50
+ const func = userFunctions[prop] || defaultFunctions[prop] ||
51
+ userFunctions[prop.charAt(0)] || defaultFunctions[prop.charAt(0)] ||
52
+ traverseCsn;
53
+ func( userFunctions, csn[prop], csn, prop );
54
+ }
55
+ }
56
+ }
57
+ // people might want to have their own traversal function for `elements`, etc:
58
+ traverseCsn.dictionary = dictionary;
59
+
60
+ /**
61
+ * Traverse the CSN dictionary node `csn`.
62
+ * Call `traverseCsn` on each property value in `csn`, passing down `userFunctions`.
63
+ */
64
+ function dictionary( userFunctions, csn ) {
65
+ if (!csn || typeof csn !== 'object')
66
+ return;
67
+ if (Array.isArray( csn )) { // args can be both array and dictionary
68
+ csn.forEach( node => traverseCsn( userFunctions, node ) );
69
+ }
70
+ else {
71
+ for (const name of Object.keys( csn ))
72
+ traverseCsn( userFunctions, csn[name] );
73
+ }
74
+ }
75
+
76
+ module.exports = {
77
+ traverseCsn,
78
+ };