@sap/cds-compiler 6.3.6 → 6.4.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 (55) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/LICENSE +32 -0
  3. package/README.md +14 -2
  4. package/bin/cdsse.js +0 -3
  5. package/doc/CHANGELOG_BETA.md +1 -1
  6. package/doc/CHANGELOG_DEPRECATED.md +1 -1
  7. package/lib/base/message-registry.js +7 -0
  8. package/lib/base/messages.js +1 -1
  9. package/lib/base/model.js +2 -0
  10. package/lib/compiler/assert-consistency.js +1 -0
  11. package/lib/compiler/checks.js +37 -26
  12. package/lib/compiler/define.js +1 -1
  13. package/lib/compiler/extend.js +39 -50
  14. package/lib/compiler/finalize-parse-cdl.js +1 -1
  15. package/lib/compiler/lsp-api.js +1 -1
  16. package/lib/compiler/populate.js +2 -2
  17. package/lib/compiler/propagator.js +29 -6
  18. package/lib/compiler/resolve.js +13 -3
  19. package/lib/compiler/shared.js +31 -25
  20. package/lib/compiler/tweak-assocs.js +86 -28
  21. package/lib/compiler/xpr-rewrite.js +70 -38
  22. package/lib/edm/annotations/edmJson.js +206 -37
  23. package/lib/edm/csn2edm.js +13 -0
  24. package/lib/edm/edmUtils.js +2 -2
  25. package/lib/gen/BaseParser.js +106 -72
  26. package/lib/gen/CdlGrammar.checksum +1 -1
  27. package/lib/gen/CdlParser.js +1500 -1509
  28. package/lib/json/to-csn.js +8 -5
  29. package/lib/language/genericAntlrParser.js +0 -0
  30. package/lib/main.js +19 -16
  31. package/lib/model/csnRefs.js +589 -521
  32. package/lib/model/csnUtils.js +8 -5
  33. package/lib/model/enrichCsn.js +1 -0
  34. package/lib/parsers/AstBuildingParser.js +72 -27
  35. package/lib/render/toCdl.js +2 -1
  36. package/lib/render/toHdbcds.js +6 -3
  37. package/lib/render/toSql.js +5 -0
  38. package/lib/transform/db/applyTransformations.js +1 -1
  39. package/lib/transform/db/assertUnique.js +4 -1
  40. package/lib/transform/db/cdsPersistence.js +17 -18
  41. package/lib/transform/db/expansion.js +179 -3
  42. package/lib/transform/db/flattening.js +16 -5
  43. package/lib/transform/db/rewriteCalculatedElements.js +79 -283
  44. package/lib/transform/effective/main.js +8 -1
  45. package/lib/transform/forOdata.js +1 -1
  46. package/lib/transform/forRelationalDB.js +21 -80
  47. package/lib/transform/localized.js +65 -110
  48. package/lib/transform/odata/foreignKeyRefsInXprAnnos.js +89 -63
  49. package/lib/transform/transformUtils.js +23 -21
  50. package/lib/transform/translateAssocsToJoins.js +7 -5
  51. package/lib/transform/tupleExpansion.js +16 -3
  52. package/package.json +1 -1
  53. package/doc/DeprecatedOptions_v2.md +0 -150
  54. package/doc/NameResolution.md +0 -837
  55. package/lib/transform/parseExpr.js +0 -415
@@ -31,7 +31,6 @@ const normalizedKind = {
31
31
  let gensrcFlavor = true; // good enough here...
32
32
  let universalCsn = false;
33
33
  let strictMode = false; // whether to dump with unknown properties (in standard)
34
- /** @type {boolean|string} */
35
34
  let withLocations = false;
36
35
  let withDocComments = false;
37
36
  let structXpr = false;
@@ -121,6 +120,7 @@ const transformers = {
121
120
  default: expression,
122
121
  targetElement, // special display of foreign key
123
122
  value: enumValueOrCalc, // do not list for select items as elements
123
+ $calc: enumValueOrCalc,
124
124
  query,
125
125
  elements,
126
126
  actions: sortedDict, // TODO: just normal dictionary
@@ -253,7 +253,7 @@ function compactModel( model, options = model.options || {} ) {
253
253
  const loc = srcDict[first].location;
254
254
  if (loc && loc.file) {
255
255
  Object.defineProperty( csn, '$location', {
256
- value: { file: loc.file }, configurable: true, writable: true, enumerable: !!withLocations,
256
+ value: { file: loc.file }, configurable: true, writable: true, enumerable: withLocations,
257
257
  } );
258
258
  }
259
259
  set( '$extra', csn, srcDict[first] );
@@ -612,7 +612,7 @@ function addLocation( loc, csn ) {
612
612
  val.endCol = loc.endCol;
613
613
  }
614
614
  Object.defineProperty( csn, '$location', {
615
- value: val, configurable: true, writable: true, enumerable: !!withLocations,
615
+ value: val, configurable: true, writable: true, enumerable: withLocations,
616
616
  } );
617
617
  }
618
618
  return csn;
@@ -1165,19 +1165,22 @@ function targetElement( val, csn, node ) {
1165
1165
  Object.assign(csn, key);
1166
1166
  }
1167
1167
 
1168
- function enumValueOrCalc( v, csn, node ) {
1168
+ function enumValueOrCalc( v, csn, node, prop ) {
1169
1169
  if (v.$inferred && (universalCsn || gensrcFlavor))
1170
1170
  return undefined;
1171
1171
  // Enum values in CSN are without outer `value: { … }`:
1172
1172
  if (node.kind === 'enum') {
1173
1173
  Object.assign( csn, expression( v ) );
1174
1174
  }
1175
+ else if (v === true && prop === '$calc') {
1176
+ return true; // calculation has used non-projected elements
1177
+ }
1175
1178
  // In XSN, there are combined elem/column objects: do not represent column
1176
1179
  // expression when presented as element in CSN
1177
1180
 
1178
1181
  // node.$syntax set in define.el(!), but not inside an `extend`, a _parent might
1179
1182
  // not be set always for parse-only, especially with CSN input
1180
- else if (node.$syntax === 'calc' ||
1183
+ else if (node.$syntax === 'calc' || prop === '$calc' ||
1181
1184
  !node._parent || node._parent.kind === 'extend') {
1182
1185
  const stored = v.stored ? { stored: value(v.stored) } : {};
1183
1186
  return Object.assign( stored, expression( v ) );
File without changes
package/lib/main.js CHANGED
@@ -20,7 +20,7 @@ const { traceApi } = require('./api/trace');
20
20
 
21
21
  const snapi = lazyload('./api/main');
22
22
  const csnUtils = lazyload('./model/csnUtils');
23
- const model_api = lazyload('./model/api');
23
+ const modelApi = lazyload('./model/api');
24
24
  const messages = lazyload('./base/messages');
25
25
  const sqlIdentifier = lazyload('./sql-identifier');
26
26
  const keywords = lazyload( './base/keywords' );
@@ -37,13 +37,15 @@ const lsp = lazyload('./compiler/lsp-api');
37
37
  const meta = lazyload('./base/meta');
38
38
 
39
39
 
40
- const toCsn = lazyload('./json/to-csn')
40
+ const toCsn = lazyload('./json/to-csn');
41
41
 
42
42
  function parseCdl( cdlSource, filename, options = {} ) {
43
43
  options = Object.assign( {}, options, { parseCdl: true } );
44
44
  const sources = Object.create(null);
45
45
  /** @type {XSN.Model} */
46
- const model = { sources, options, $functions: {}, $volatileFunctions: {} };
46
+ const model = {
47
+ sources, options, $functions: {}, $volatileFunctions: {},
48
+ };
47
49
  const messageFunctions = messages.createMessageFunctions( options, 'parse', model );
48
50
  model.$messageFunctions = messageFunctions;
49
51
 
@@ -73,7 +75,8 @@ function parseExpr( cdlSource, filename = '<expr>.cds', options = {} ) {
73
75
  return toCsn.compactExpr( xsn );
74
76
  }
75
77
 
76
- // FIXME: The implementation of those functions that delegate to 'backends' should probably move here
78
+ // FIXME: The implementation of those functions that delegate to 'backends'
79
+ // should probably move here
77
80
  // ATTENTION: Keep in sync with main.d.ts!
78
81
  module.exports = {
79
82
  // Compiler
@@ -96,7 +99,7 @@ module.exports = {
96
99
  value: messages.CompilationError,
97
100
  writable: false,
98
101
  configurable: false,
99
- enumerable: true
102
+ enumerable: true,
100
103
  });
101
104
  return messages.CompilationError;
102
105
  },
@@ -113,7 +116,7 @@ module.exports = {
113
116
  value: compiler.InvocationError,
114
117
  writable: false,
115
118
  configurable: false,
116
- enumerable: false
119
+ enumerable: false,
117
120
  });
118
121
  return compiler.InvocationError;
119
122
  },
@@ -123,7 +126,7 @@ module.exports = {
123
126
  parse: {
124
127
  cdl: (...args) => parseCdl(...args),
125
128
  cql: (...args) => parseCql(...args),
126
- expr: (...args) => parseExpr(...args)
129
+ expr: (...args) => parseExpr(...args),
127
130
  },
128
131
  // SNAPI
129
132
  for: {
@@ -143,13 +146,13 @@ module.exports = {
143
146
  sql: Object.assign((...args) => snapi.sql(...args), {
144
147
  migration: (...args) => snapi.sql.migration(...args),
145
148
  sqlite: {
146
- keywords: Object.freeze([ ...keywords.sqlite ] )
149
+ keywords: Object.freeze([ ...keywords.sqlite ] ),
147
150
  },
148
151
  postgres: {
149
- keywords: Object.freeze([ ...keywords.postgres ] )
152
+ keywords: Object.freeze([ ...keywords.postgres ] ),
150
153
  },
151
154
  h2: {
152
- keywords: Object.freeze([ ...keywords.h2 ] )
155
+ keywords: Object.freeze([ ...keywords.h2 ] ),
153
156
  },
154
157
  smartId: (...args) => sqlIdentifier.smartId(...args),
155
158
  smartFunctionId: (...args) => sqlIdentifier.smartFuncId(...args),
@@ -163,13 +166,13 @@ module.exports = {
163
166
  keywords: Object.freeze([ ...keywords.hdbcds ] ),
164
167
  }),
165
168
  edm: Object.assign((...args) => snapi.edm(...args), {
166
- all: (...args) => snapi.edm.all(...args)
169
+ all: (...args) => snapi.edm.all(...args),
167
170
  }),
168
171
  edmx: Object.assign((...args) => snapi.edmx(...args), {
169
- all: (...args) => snapi.edmx.all(...args)
172
+ all: (...args) => snapi.edmx.all(...args),
170
173
  }),
171
174
  odata: Object.assign((...args) => snapi.odata2(...args), {
172
- all: (...args) => snapi.odata2.all(...args)
175
+ all: (...args) => snapi.odata2.all(...args),
173
176
  }),
174
177
  },
175
178
  // Convenience for hdbtabledata calculation in @sap/cds
@@ -177,7 +180,7 @@ module.exports = {
177
180
  getElementCdsPersistenceName: (...args) => csnUtils.getElementDatabaseNameOf(...args),
178
181
 
179
182
  // Other API functions:
180
- traverseCsn: (...args) => model_api.traverseCsn(...args),
183
+ traverseCsn: (...args) => modelApi.traverseCsn(...args),
181
184
 
182
185
  // INTERNAL functions for the cds-lsp package and friends - before you use
183
186
  // it, you MUST talk with us - there can be potential incompatibilities with
@@ -185,9 +188,9 @@ module.exports = {
185
188
  $lsp: {
186
189
  parse: (...args) => compiler.parseX(...args),
187
190
  compile: (...args) => compiler.compileX(...args),
188
- getArtifactName: (art) => base.getArtifactName(art),
191
+ getArtifactName: art => base.getArtifactName(art),
189
192
  traverseSemanticTokens: (xsn, options) => lsp.traverseSemanticTokens(xsn, options),
190
- getSemanticTokenOrigin: (obj) => lsp.getSemanticTokenOrigin(obj),
193
+ getSemanticTokenOrigin: obj => lsp.getSemanticTokenOrigin(obj),
191
194
  },
192
195
 
193
196
  // CSN Model related functionality