@sap/cds-compiler 2.12.0 → 2.15.2

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 (128) hide show
  1. package/CHANGELOG.md +221 -15
  2. package/bin/cdsc.js +125 -50
  3. package/bin/cdsse.js +2 -2
  4. package/doc/CHANGELOG_BETA.md +13 -6
  5. package/doc/CHANGELOG_DEPRECATED.md +22 -6
  6. package/doc/NameResolution.md +21 -16
  7. package/lib/api/main.js +47 -84
  8. package/lib/api/options.js +5 -6
  9. package/lib/api/validate.js +6 -11
  10. package/lib/backends.js +15 -23
  11. package/lib/base/dictionaries.js +0 -8
  12. package/lib/base/error.js +26 -0
  13. package/lib/base/keywords.js +7 -17
  14. package/lib/base/location.js +9 -4
  15. package/lib/base/message-registry.js +114 -18
  16. package/lib/base/messages.js +101 -90
  17. package/lib/base/model.js +2 -63
  18. package/lib/base/optionProcessorHelper.js +177 -123
  19. package/lib/checks/annotationsOData.js +12 -33
  20. package/lib/checks/arrayOfs.js +1 -34
  21. package/lib/checks/cdsPersistence.js +2 -1
  22. package/lib/checks/enricher.js +17 -1
  23. package/lib/checks/invalidTarget.js +3 -1
  24. package/lib/checks/managedWithoutKeys.js +3 -1
  25. package/lib/checks/selectItems.js +4 -4
  26. package/lib/checks/sql-snippets.js +27 -26
  27. package/lib/checks/types.js +1 -1
  28. package/lib/checks/validator.js +6 -11
  29. package/lib/compiler/assert-consistency.js +6 -3
  30. package/lib/compiler/base.js +1 -0
  31. package/lib/compiler/builtins.js +19 -6
  32. package/lib/compiler/checks.js +23 -60
  33. package/lib/compiler/cycle-detector.js +1 -1
  34. package/lib/compiler/define.js +1151 -0
  35. package/lib/compiler/extend.js +1000 -0
  36. package/lib/compiler/finalize-parse-cdl.js +237 -0
  37. package/lib/compiler/index.js +107 -39
  38. package/lib/compiler/kick-start.js +190 -0
  39. package/lib/compiler/moduleLayers.js +4 -4
  40. package/lib/compiler/populate.js +1227 -0
  41. package/lib/compiler/propagator.js +114 -46
  42. package/lib/compiler/resolve.js +1521 -0
  43. package/lib/compiler/shared.js +126 -65
  44. package/lib/compiler/tweak-assocs.js +535 -0
  45. package/lib/compiler/utils.js +197 -33
  46. package/lib/edm/.eslintrc.json +5 -0
  47. package/lib/edm/annotations/genericTranslation.js +38 -24
  48. package/lib/edm/annotations/preprocessAnnotations.js +2 -2
  49. package/lib/edm/csn2edm.js +219 -100
  50. package/lib/edm/edm.js +302 -230
  51. package/lib/edm/edmPreprocessor.js +554 -419
  52. package/lib/edm/edmUtils.js +138 -44
  53. package/lib/gen/Dictionary.json +100 -19
  54. package/lib/gen/language.checksum +1 -1
  55. package/lib/gen/language.interp +11 -1
  56. package/lib/gen/language.tokens +86 -83
  57. package/lib/gen/languageLexer.interp +10 -1
  58. package/lib/gen/languageLexer.js +860 -833
  59. package/lib/gen/languageLexer.tokens +78 -75
  60. package/lib/gen/languageParser.js +5765 -4480
  61. package/lib/json/csnVersion.js +10 -11
  62. package/lib/json/from-csn.js +15 -3
  63. package/lib/json/to-csn.js +126 -68
  64. package/lib/language/docCommentParser.js +4 -4
  65. package/lib/language/genericAntlrParser.js +123 -5
  66. package/lib/language/language.g4 +355 -156
  67. package/lib/language/multiLineStringParser.js +5 -5
  68. package/lib/main.d.ts +486 -59
  69. package/lib/main.js +41 -9
  70. package/lib/model/api.js +3 -1
  71. package/lib/model/csnRefs.js +252 -156
  72. package/lib/model/csnUtils.js +384 -297
  73. package/lib/model/enrichCsn.js +71 -29
  74. package/lib/model/revealInternalProperties.js +29 -8
  75. package/lib/model/sortViews.js +2 -1
  76. package/lib/modelCompare/compare.js +23 -18
  77. package/lib/optionProcessor.js +63 -26
  78. package/lib/render/manageConstraints.js +35 -32
  79. package/lib/render/toCdl.js +897 -947
  80. package/lib/render/toHdbcds.js +205 -257
  81. package/lib/render/toSql.js +264 -225
  82. package/lib/render/utils/common.js +136 -25
  83. package/lib/render/utils/sql.js +4 -3
  84. package/lib/render/utils/stringEscapes.js +111 -0
  85. package/lib/sql-identifier.js +1 -1
  86. package/lib/transform/.eslintrc.json +5 -0
  87. package/lib/transform/db/.eslintrc.json +3 -1
  88. package/lib/transform/db/applyTransformations.js +35 -12
  89. package/lib/transform/db/assertUnique.js +1 -1
  90. package/lib/transform/db/associations.js +104 -306
  91. package/lib/transform/db/cdsPersistence.js +2 -2
  92. package/lib/transform/db/constraints.js +58 -53
  93. package/lib/transform/db/expansion.js +60 -33
  94. package/lib/transform/db/flattening.js +582 -104
  95. package/lib/transform/db/groupByOrderBy.js +3 -1
  96. package/lib/transform/db/transformExists.js +66 -13
  97. package/lib/transform/db/views.js +11 -7
  98. package/lib/transform/draft/.eslintrc.json +38 -0
  99. package/lib/transform/{db/draft.js → draft/db.js} +6 -5
  100. package/lib/transform/draft/odata.js +227 -0
  101. package/lib/transform/forHanaNew.js +109 -208
  102. package/lib/transform/forOdataNew.js +59 -212
  103. package/lib/transform/localized.js +46 -26
  104. package/lib/transform/odata/toFinalBaseType.js +85 -11
  105. package/lib/transform/odata/typesExposure.js +147 -199
  106. package/lib/transform/odata/utils.js +2 -2
  107. package/lib/transform/transformUtilsNew.js +44 -33
  108. package/lib/transform/translateAssocsToJoins.js +3 -20
  109. package/lib/transform/universalCsn/.eslintrc.json +36 -0
  110. package/lib/transform/universalCsn/coreComputed.js +172 -0
  111. package/lib/transform/universalCsn/universalCsnEnricher.js +737 -0
  112. package/lib/transform/universalCsn/utils.js +63 -0
  113. package/lib/utils/moduleResolve.js +13 -6
  114. package/lib/utils/objectUtils.js +30 -0
  115. package/package.json +1 -1
  116. package/share/messages/README.md +26 -0
  117. package/share/messages/message-explanations.json +2 -1
  118. package/share/messages/syntax-expected-integer.md +37 -0
  119. package/lib/compiler/definer.js +0 -2361
  120. package/lib/compiler/resolver.js +0 -3079
  121. package/lib/transform/odata/attachPath.js +0 -96
  122. package/lib/transform/odata/expandStructKeysInAssociations.js +0 -59
  123. package/lib/transform/odata/generateForeignKeyElements.js +0 -261
  124. package/lib/transform/odata/referenceFlattener.js +0 -290
  125. package/lib/transform/odata/sortByAssociationDependency.js +0 -105
  126. package/lib/transform/odata/structuralPath.js +0 -72
  127. package/lib/transform/odata/structureFlattener.js +0 -171
  128. package/lib/transform/universalCsnEnricher.js +0 -237
package/lib/main.js CHANGED
@@ -18,11 +18,15 @@ const { odata, cdl, sql, hdi, hdbcds, edm, edmx } = require('./api/main');
18
18
  const { getArtifactDatabaseNameOf, getElementDatabaseNameOf } = require('./model/csnUtils');
19
19
  const { traverseCsn } = require('./model/api');
20
20
  const { createMessageFunctions, sortMessages, sortMessagesSeverityAware, deduplicateMessages } = require('./base/messages');
21
+ const { smartId, smartFuncId, delimitedId } = require('./sql-identifier');
22
+ const keywords = require( './base/keywords' );
21
23
 
22
24
  const parseLanguage = require('./language/antlrParser');
23
25
  const { parseX, compileX, compileSyncX, compileSourcesX, InvocationError } = require('./compiler');
24
26
  const { fns } = require('./compiler/shared');
25
- const { define } = require('./compiler/definer');
27
+ const define = require('./compiler/define');
28
+ const { isInReservedNamespace } = require("./compiler/builtins");
29
+ const finalizeParseCdl = require('./compiler/finalize-parse-cdl');
26
30
 
27
31
  // The compiler version (taken from package.json)
28
32
  function version() {
@@ -41,7 +45,7 @@ const {
41
45
 
42
46
  const { compactModel, compactQuery, compactExpr } = require('./json/to-csn')
43
47
 
44
- function parseCdl( cdl, filename, options = {} ) {
48
+ function parseCdl( cdlSource, filename, options = {} ) {
45
49
  options = Object.assign( {}, options, { parseCdl: true } );
46
50
  const sources = Object.create(null);
47
51
  /** @type {XSN.Model} */
@@ -49,26 +53,27 @@ function parseCdl( cdl, filename, options = {} ) {
49
53
  const messageFunctions = createMessageFunctions( options, 'parse', model );
50
54
  model.$messageFunctions = messageFunctions;
51
55
 
52
- const xsn = parseLanguage( cdl, filename, Object.assign( { parseOnly: true }, options ),
56
+ const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
53
57
  messageFunctions );
54
58
  sources[filename] = xsn;
55
59
  fns( model );
56
60
  define( model );
61
+ finalizeParseCdl( model );
57
62
  messageFunctions.throwWithError();
58
63
  return compactModel( model );
59
64
  }
60
65
 
61
- function parseCql( cdl, filename = '<query>.cds', options = {} ) {
66
+ function parseCql( cdlSource, filename = '<query>.cds', options = {} ) {
62
67
  const messageFunctions = createMessageFunctions( options, 'parse' );
63
- const xsn = parseLanguage( cdl, filename, Object.assign( { parseOnly: true }, options ),
68
+ const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
64
69
  messageFunctions, 'query' );
65
70
  messageFunctions.throwWithError();
66
71
  return compactQuery( xsn );
67
72
  }
68
73
 
69
- function parseExpr( cdl, filename = '<expr>.cds', options = {} ) {
74
+ function parseExpr( cdlSource, filename = '<expr>.cds', options = {} ) {
70
75
  const messageFunctions = createMessageFunctions( options, 'parse' );
71
- const xsn = parseLanguage( cdl, filename, Object.assign( { parseOnly: true }, options ),
76
+ const xsn = parseLanguage( cdlSource, filename, Object.assign( { parseOnly: true }, options ),
72
77
  messageFunctions, 'expr' );
73
78
  messageFunctions.throwWithError();
74
79
  return compactExpr( xsn );
@@ -107,10 +112,32 @@ module.exports = {
107
112
  * @deprecated Use parse.cql instead
108
113
  */
109
114
  parseToCqn: parseCql,
115
+ /**
116
+ * @deprecated Use parse.expr instead
117
+ */
110
118
  parseToExpr: parseExpr, // deprecated name
111
119
  // SNAPI
112
120
  for: { odata },
113
- to: { cdl, sql, hdi, hdbcds, edm, edmx },
121
+ to: {
122
+ cdl: Object.assign(cdl, {
123
+ keywords: Object.freeze([ ...keywords.cdl ]),
124
+ functions: Object.freeze([ ...keywords.cdl_functions ]),
125
+ }),
126
+ sql: Object.assign(sql, {
127
+ sqlite: { keywords: Object.freeze([ ...keywords.sqlite ] )},
128
+ smartId,
129
+ smartFunctionId: smartFuncId,
130
+ delimitedId,
131
+ }),
132
+ hdi: Object.assign(hdi, {
133
+ keywords: Object.freeze([ ...keywords.hana ]),
134
+ }),
135
+ hdbcds: Object.assign(hdbcds, {
136
+ keywords: Object.freeze([ ...keywords.hdbcds ]),
137
+ }),
138
+ edm,
139
+ edmx
140
+ },
114
141
  // Convenience for hdbtabledata calculation in @sap/cds
115
142
  getArtifactCdsPersistenceName: getArtifactDatabaseNameOf,
116
143
  getElementCdsPersistenceName: getElementDatabaseNameOf,
@@ -121,5 +148,10 @@ module.exports = {
121
148
  // INTERNAL functions for the cds-lsp package and friends - before you use
122
149
  // it, you MUST talk with us - there can be potential incompatibilities with
123
150
  // new releases (even having the same major version):
124
- $lsp: { parse: parseX, compile: compileX },
151
+ $lsp: { parse: parseX, compile: compileX, getArtifactName: a => a.name },
152
+
153
+ // CSN Model related functionality
154
+ model: {
155
+ isInReservedNamespace,
156
+ },
125
157
  };
package/lib/model/api.js CHANGED
@@ -28,12 +28,14 @@ const defaultFunctions = {
28
28
 
29
29
  /**
30
30
  * Traverse the CSN node `csn`.
31
+ *
31
32
  * If `csn` is an array, call it recursively on each array item.
32
33
  * If `csn` is an(other) object, call a function on each property:
33
34
  * - The property name is a used as key in argument `userFunctions` and the
34
35
  * constant `defaultFunctions` above to get the function which is called on
35
36
  * 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 no function is found with the property name, try to find one with the
38
+ * first char, which is useful for annotations.
37
39
  * - If still not found, call `traverseCsn` recursively.
38
40
  *
39
41
  * The functions in `userFunctions` are usually transformer functions, which