@sap/cds-compiler 3.4.4 → 3.5.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 (129) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/README.md +1 -0
  3. package/bin/cds_update_identifiers.js +5 -5
  4. package/bin/cdsc.js +12 -12
  5. package/doc/CHANGELOG_ARCHIVE.md +1 -1
  6. package/doc/CHANGELOG_BETA.md +9 -1
  7. package/doc/CHANGELOG_DEPRECATED.md +2 -0
  8. package/lib/api/main.js +58 -59
  9. package/lib/api/options.js +4 -2
  10. package/lib/api/validate.js +2 -2
  11. package/lib/base/cleanSymbols.js +2 -3
  12. package/lib/base/dictionaries.js +6 -6
  13. package/lib/base/error.js +2 -2
  14. package/lib/base/keywords.js +6 -6
  15. package/lib/base/location.js +11 -12
  16. package/lib/base/message-registry.js +124 -28
  17. package/lib/base/messages.js +247 -179
  18. package/lib/base/model.js +14 -11
  19. package/lib/base/node-helpers.js +9 -10
  20. package/lib/base/optionProcessorHelper.js +138 -129
  21. package/lib/checks/actionsFunctions.js +5 -5
  22. package/lib/checks/annotationsOData.js +4 -4
  23. package/lib/checks/arrayOfs.js +1 -1
  24. package/lib/checks/cdsPersistence.js +1 -1
  25. package/lib/checks/checkForTypes.js +3 -3
  26. package/lib/checks/defaultValues.js +3 -3
  27. package/lib/checks/elements.js +7 -7
  28. package/lib/checks/emptyOrOnlyVirtual.js +2 -2
  29. package/lib/checks/foreignKeys.js +1 -1
  30. package/lib/checks/invalidTarget.js +4 -4
  31. package/lib/checks/managedInType.js +1 -1
  32. package/lib/checks/managedWithoutKeys.js +1 -1
  33. package/lib/checks/nonexpandableStructured.js +5 -3
  34. package/lib/checks/nullableKeys.js +1 -1
  35. package/lib/checks/onConditions.js +5 -6
  36. package/lib/checks/parameters.js +1 -1
  37. package/lib/checks/queryNoDbArtifacts.js +2 -2
  38. package/lib/checks/selectItems.js +4 -4
  39. package/lib/checks/sql-snippets.js +4 -4
  40. package/lib/checks/types.js +7 -7
  41. package/lib/checks/utils.js +4 -4
  42. package/lib/checks/validator.js +16 -13
  43. package/lib/compiler/.eslintrc.json +1 -1
  44. package/lib/compiler/assert-consistency.js +0 -1
  45. package/lib/compiler/builtins.js +1 -1
  46. package/lib/compiler/checks.js +73 -15
  47. package/lib/compiler/define.js +3 -7
  48. package/lib/compiler/extend.js +212 -32
  49. package/lib/compiler/finalize-parse-cdl.js +7 -2
  50. package/lib/compiler/index.js +17 -14
  51. package/lib/compiler/populate.js +2 -5
  52. package/lib/compiler/propagator.js +2 -0
  53. package/lib/compiler/shared.js +23 -12
  54. package/lib/compiler/tweak-assocs.js +5 -6
  55. package/lib/compiler/utils.js +6 -0
  56. package/lib/edm/annotations/genericTranslation.js +553 -319
  57. package/lib/edm/annotations/preprocessAnnotations.js +39 -35
  58. package/lib/edm/csn2edm.js +88 -75
  59. package/lib/edm/edm.js +17 -3
  60. package/lib/edm/edmAnnoPreprocessor.js +5 -5
  61. package/lib/edm/edmPreprocessor.js +106 -76
  62. package/lib/edm/edmUtils.js +41 -2
  63. package/lib/gen/Dictionary.json +34 -0
  64. package/lib/gen/language.checksum +1 -1
  65. package/lib/gen/language.interp +66 -63
  66. package/lib/gen/language.tokens +81 -81
  67. package/lib/gen/languageLexer.interp +4 -10
  68. package/lib/gen/languageLexer.js +854 -869
  69. package/lib/gen/languageLexer.tokens +79 -81
  70. package/lib/gen/languageParser.js +14360 -14146
  71. package/lib/inspect/inspectModelStatistics.js +2 -2
  72. package/lib/inspect/inspectPropagation.js +6 -6
  73. package/lib/inspect/inspectUtils.js +2 -2
  74. package/lib/json/from-csn.js +82 -40
  75. package/lib/json/to-csn.js +82 -157
  76. package/lib/language/.eslintrc.json +1 -4
  77. package/lib/language/genericAntlrParser.js +59 -38
  78. package/lib/language/language.g4 +1508 -1490
  79. package/lib/language/multiLineStringParser.js +1 -1
  80. package/lib/main.js +3 -3
  81. package/lib/model/csnUtils.js +130 -122
  82. package/lib/model/revealInternalProperties.js +1 -1
  83. package/lib/model/sortViews.js +4 -6
  84. package/lib/modelCompare/utils/filter.js +4 -3
  85. package/lib/optionProcessor.js +5 -0
  86. package/lib/render/DuplicateChecker.js +1 -1
  87. package/lib/render/manageConstraints.js +12 -12
  88. package/lib/render/toCdl.js +225 -159
  89. package/lib/render/toHdbcds.js +63 -63
  90. package/lib/render/toRename.js +5 -5
  91. package/lib/render/toSql.js +55 -65
  92. package/lib/render/utils/common.js +20 -37
  93. package/lib/render/utils/delta.js +3 -3
  94. package/lib/render/utils/sql.js +22 -6
  95. package/lib/render/utils/stringEscapes.js +3 -3
  96. package/lib/transform/db/applyTransformations.js +3 -3
  97. package/lib/transform/db/assertUnique.js +13 -12
  98. package/lib/transform/db/associations.js +5 -5
  99. package/lib/transform/db/cdsPersistence.js +10 -8
  100. package/lib/transform/db/constraints.js +14 -14
  101. package/lib/transform/db/expansion.js +20 -22
  102. package/lib/transform/db/flattening.js +24 -42
  103. package/lib/transform/db/groupByOrderBy.js +3 -3
  104. package/lib/transform/db/temporal.js +6 -6
  105. package/lib/transform/db/transformExists.js +23 -23
  106. package/lib/transform/db/views.js +16 -16
  107. package/lib/transform/draft/db.js +10 -10
  108. package/lib/transform/draft/odata.js +2 -2
  109. package/lib/transform/forOdataNew.js +12 -40
  110. package/lib/transform/forRelationalDB.js +17 -7
  111. package/lib/transform/localized.js +2 -2
  112. package/lib/transform/odata/toFinalBaseType.js +41 -27
  113. package/lib/transform/odata/typesExposure.js +106 -62
  114. package/lib/transform/parseExpr.js +209 -106
  115. package/lib/transform/transformUtilsNew.js +2 -2
  116. package/lib/transform/translateAssocsToJoins.js +24 -19
  117. package/lib/transform/universalCsn/coreComputed.js +10 -10
  118. package/lib/transform/universalCsn/universalCsnEnricher.js +26 -26
  119. package/lib/transform/universalCsn/utils.js +3 -3
  120. package/lib/utils/file.js +5 -5
  121. package/lib/utils/moduleResolve.js +13 -13
  122. package/lib/utils/objectUtils.js +6 -6
  123. package/lib/utils/term.js +5 -2
  124. package/lib/utils/timetrace.js +51 -24
  125. package/package.json +5 -7
  126. package/share/messages/check-proper-type-of.md +1 -1
  127. package/share/messages/message-explanations.json +1 -1
  128. package/share/messages/redirected-to-complex.md +4 -4
  129. package/share/messages/{syntax-expecting-integer.md → syntax-expecting-unsigned-int.md} +7 -4
@@ -32,7 +32,7 @@ const $SELF = '$self';
32
32
  * @param {CSN.Artifact} obj
33
33
  * @returns {string}
34
34
  */
35
- function getEscapedHanaComment(obj) {
35
+ function getEscapedHanaComment( obj ) {
36
36
  return getHanaComment(obj).replace(/\n/g, '\\n').replace(/'/g, "''");
37
37
  }
38
38
 
@@ -42,7 +42,7 @@ function getEscapedHanaComment(obj) {
42
42
  * @param {string} str
43
43
  * @returns {string}
44
44
  */
45
- function renderStringForHdbcds(str) {
45
+ function renderStringForHdbcds( str ) {
46
46
  return `'${str.replace(/'/g, '\'\'')}'`;
47
47
  }
48
48
 
@@ -60,7 +60,7 @@ function renderStringForHdbcds(str) {
60
60
  * @param {CSN.Options} [options] Transformation options
61
61
  * @returns {object} Dictionary of filename: content
62
62
  */
63
- function toHdbcdsSource(csn, options) {
63
+ function toHdbcdsSource( csn, options ) {
64
64
  timetrace.start('HDBCDS rendering');
65
65
  const plainNames = options.sqlMapping === 'plain';
66
66
  const quotedNames = options.sqlMapping === 'quoted';
@@ -101,7 +101,7 @@ function toHdbcdsSource(csn, options) {
101
101
  },
102
102
  });
103
103
 
104
- function renderExpr(x, env) {
104
+ function renderExpr( x, env ) {
105
105
  return exprRenderer.renderExpr(x, env);
106
106
  }
107
107
 
@@ -164,7 +164,7 @@ function toHdbcdsSource(csn, options) {
164
164
  killList.forEach(fn => fn());
165
165
 
166
166
  throwWithAnyError();
167
- timetrace.stop();
167
+ timetrace.stop('HDBCDS rendering');
168
168
  return options.testMode ? sort(hdbcdsResult) : hdbcdsResult;
169
169
 
170
170
  /**
@@ -173,7 +173,7 @@ function toHdbcdsSource(csn, options) {
173
173
  * @param {Object} obj Object to sort
174
174
  * @returns {Object} With keys sorted
175
175
  */
176
- function sort(obj) {
176
+ function sort( obj ) {
177
177
  const keys = Object.keys(obj).sort((a, b) => a.localeCompare(b));
178
178
  const sortedResult = Object.create(null);
179
179
  for (let i = 0; i < keys.length; i++)
@@ -190,7 +190,7 @@ function toHdbcdsSource(csn, options) {
190
190
  * @param {CdlRenderEnvironment} env Environment
191
191
  * @returns {string} The rendered artifact
192
192
  */
193
- function renderArtifact(artifactName, art, env) {
193
+ function renderArtifact( artifactName, art, env ) {
194
194
  // FIXME: Correctly build the paths during runtime to give better locations
195
195
  env.path = [ 'definitions', artifactName ];
196
196
  // Ignore whole artifacts if toHana says so
@@ -233,7 +233,7 @@ function toHdbcdsSource(csn, options) {
233
233
  * @param {string} artifactName Find all children of this artifact
234
234
  * @returns {object} Dictionary with direct sub-artifacts
235
235
  */
236
- function getSubArtifacts(artifactName) {
236
+ function getSubArtifacts( artifactName ) {
237
237
  const prefix = `${artifactName}.`;
238
238
  const result = Object.create(null);
239
239
  for (const name in csn.definitions) {
@@ -265,7 +265,7 @@ function toHdbcdsSource(csn, options) {
265
265
  * @param {string} contextName Name of the (grand?)parent context
266
266
  * @returns {boolean} True if there is another context in between
267
267
  */
268
- function isContainedInOtherContext(containee, contextName) {
268
+ function isContainedInOtherContext( containee, contextName ) {
269
269
  const parts = containee.split('.');
270
270
  const prefixLength = contextName.split('.').length;
271
271
 
@@ -333,7 +333,7 @@ function toHdbcdsSource(csn, options) {
333
333
  * @param {CdlRenderEnvironment} env Environment
334
334
  * @returns {string} The rendered context/service
335
335
  */
336
- function renderContext(artifactName, art, env, isShadowed) {
336
+ function renderContext( artifactName, art, env, isShadowed ) {
337
337
  let result = '';
338
338
  if (!isShadowed)
339
339
  isShadowed = contextIsShadowed(artifactName);
@@ -365,7 +365,7 @@ function toHdbcdsSource(csn, options) {
365
365
  * @param {string} artifactName
366
366
  * @returns {boolean}
367
367
  */
368
- function contextIsShadowed(artifactName) {
368
+ function contextIsShadowed( artifactName ) {
369
369
  if (artifactName.indexOf('.') === -1)
370
370
  return false;
371
371
 
@@ -387,7 +387,7 @@ function toHdbcdsSource(csn, options) {
387
387
  * @param {string} name Possibly dotted artifact name
388
388
  * @returns {CdlRenderEnvironment} Updated env or original instance
389
389
  */
390
- function updatePrefixForDottedName(env, name) {
390
+ function updatePrefixForDottedName( env, name ) {
391
391
  if (plainNames) {
392
392
  let innerEnv = env;
393
393
  if (name.indexOf('.') !== -1) {
@@ -409,7 +409,7 @@ function toHdbcdsSource(csn, options) {
409
409
  * @param {CdlRenderEnvironment} env Environment
410
410
  * @returns {string} The rendered children of the namespace
411
411
  */
412
- function renderNamespace(artifactName, art, env) {
412
+ function renderNamespace( artifactName, art, env ) {
413
413
  // We currently do not render anything for a namespace, we just append its id to
414
414
  // the environment's current name prefix and descend into its children
415
415
  let result = '';
@@ -429,7 +429,7 @@ function toHdbcdsSource(csn, options) {
429
429
  * @param {CdlRenderEnvironment} env Environment
430
430
  * @returns {string} The rendered entity
431
431
  */
432
- function renderEntity(artifactName, art, env) {
432
+ function renderEntity( artifactName, art, env ) {
433
433
  let result = '';
434
434
  const childEnv = increaseIndent(env);
435
435
  const normalizedArtifactName = renderArtifactName(artifactName, env);
@@ -478,7 +478,7 @@ function toHdbcdsSource(csn, options) {
478
478
  * @param {CSN.Artifact} art
479
479
  * @param {CdlRenderEnvironment} env
480
480
  */
481
- function createTopLevelAliasesForArtifact(artName, art, env) {
481
+ function createTopLevelAliasesForArtifact( artName, art, env ) {
482
482
  forEachMember(art, (element) => {
483
483
  if (!element.target)
484
484
  return;
@@ -503,7 +503,7 @@ function toHdbcdsSource(csn, options) {
503
503
  * @param {CdlRenderEnvironment} env Environment
504
504
  * @returns {string} Return the resulting source string.
505
505
  */
506
- function renderTechnicalConfiguration(tc, env) {
506
+ function renderTechnicalConfiguration( tc, env ) {
507
507
  let result = '';
508
508
  const childEnv = increaseIndent(env);
509
509
 
@@ -577,7 +577,7 @@ function toHdbcdsSource(csn, options) {
577
577
  * @param {string} columnName Name of the SQL column
578
578
  * @returns {Array} Modified expression array
579
579
  */
580
- function fixFuzzyIndex(fuzzyIndex, columnName) {
580
+ function fixFuzzyIndex( fuzzyIndex, columnName ) {
581
581
  return fuzzyIndex.map(token => (token === 'on' ? { xpr: [ 'on', '(', { ref: columnName.split('.') }, ')' ] } : token));
582
582
  }
583
583
  }
@@ -593,7 +593,7 @@ function toHdbcdsSource(csn, options) {
593
593
  * @param {boolean} [isSubElement] Whether the given element is a subelement or not - subelements cannot be key!
594
594
  * @returns {string} The rendered element
595
595
  */
596
- function renderElement(elementName, elm, env, duplicateChecker, isSubElement) {
596
+ function renderElement( elementName, elm, env, duplicateChecker, isSubElement ) {
597
597
  // Ignore if toHana says so
598
598
  if (elm.virtual)
599
599
  return '';
@@ -634,7 +634,7 @@ function toHdbcdsSource(csn, options) {
634
634
  * @param {CdlRenderEnvironment} env Environment
635
635
  * @returns {string} Rendered view source
636
636
  */
637
- function renderViewSource(source, env) {
637
+ function renderViewSource( source, env ) {
638
638
  // Sub-SELECT
639
639
  if (source.SELECT || source.SET) {
640
640
  let result = `(${renderQuery(source, false, increaseIndent(env))})`;
@@ -671,7 +671,7 @@ function toHdbcdsSource(csn, options) {
671
671
  * @param {CdlRenderEnvironment} env Environment
672
672
  * @returns {string} Rendered path
673
673
  */
674
- function renderAbsolutePath(path, env) {
674
+ function renderAbsolutePath( path, env ) {
675
675
  // Sanity checks
676
676
  if (!path.ref)
677
677
  throw new ModelError(`Expecting ref in path: ${JSON.stringify(path)}`);
@@ -712,7 +712,7 @@ function toHdbcdsSource(csn, options) {
712
712
  * @param {CdlRenderEnvironment} env Environment
713
713
  * @returns {string} Rendered path including alias
714
714
  */
715
- function renderAbsolutePathWithAlias(path, env) {
715
+ function renderAbsolutePathWithAlias( path, env ) {
716
716
  let result = renderAbsolutePath(path, env);
717
717
  // Take care of aliases - for artifact references, use the resulting name (multi-dot joined with _)
718
718
  const implicitAlias = path.ref.length === 0 ? getLastPartOf(getResultingName(csn, options.sqlMapping, path.ref[0])) : getLastPartOfRef(path.ref);
@@ -737,7 +737,7 @@ function toHdbcdsSource(csn, options) {
737
737
  * @param {CdlRenderEnvironment} env Environment
738
738
  * @returns {string} Rendered column
739
739
  */
740
- function renderViewColumn(col, elements, env ) {
740
+ function renderViewColumn( col, elements, env ) {
741
741
  // Annotations and column
742
742
  let result = '';
743
743
 
@@ -800,7 +800,7 @@ function toHdbcdsSource(csn, options) {
800
800
  * @param {CdlRenderEnvironment} env Environment
801
801
  * @returns {string} The rendered view
802
802
  */
803
- function renderView(artifactName, art, env) {
803
+ function renderView( artifactName, art, env ) {
804
804
  let result = '';
805
805
  const artifactPath = [ 'definitions', artifactName ];
806
806
  globalDuplicateChecker.addArtifact(art['@cds.persistence.name'], artifactPath, artifactName);
@@ -844,7 +844,7 @@ function toHdbcdsSource(csn, options) {
844
844
  * @param {object} [elements] For leading query, the elements of the artifact
845
845
  * @returns {string} The rendered query
846
846
  */
847
- function renderQuery(query, isLeadingQuery, env, path = [], elements = null) {
847
+ function renderQuery( query, isLeadingQuery, env, path = [], elements = null ) {
848
848
  let result = '';
849
849
  env.skipKeys = !isLeadingQuery;
850
850
  // Set operator, like UNION, INTERSECT, ...
@@ -912,7 +912,7 @@ function toHdbcdsSource(csn, options) {
912
912
  * @param {CdlRenderEnvironment} env Environment
913
913
  * @returns {string} The query with WHERE etc. added
914
914
  */
915
- function renderSelectProperties(select, alreadyRendered, env) {
915
+ function renderSelectProperties( select, alreadyRendered, env ) {
916
916
  if (select.where)
917
917
  alreadyRendered += `${continueIndent(alreadyRendered, env)}where ${renderExpr(select.where, env)}`;
918
918
 
@@ -938,7 +938,7 @@ function toHdbcdsSource(csn, options) {
938
938
  * @param {CdlRenderEnvironment} env Environment
939
939
  * @returns {string} String to join with
940
940
  */
941
- function continueIndent(result, env) {
941
+ function continueIndent( result, env ) {
942
942
  if (result.endsWith('}') || result.endsWith('})')) {
943
943
  // The preceding clause ended with '}', just append after that
944
944
  return ' ';
@@ -954,7 +954,7 @@ function toHdbcdsSource(csn, options) {
954
954
  * @param {CdlRenderEnvironment} env Environment
955
955
  * @returns {string} Rendered limit clause
956
956
  */
957
- function renderLimit(limit, env) {
957
+ function renderLimit( limit, env ) {
958
958
  let result = '';
959
959
  if (limit.rows !== undefined)
960
960
  result += `limit ${renderExpr(limit.rows, env)}`;
@@ -973,7 +973,7 @@ function toHdbcdsSource(csn, options) {
973
973
  * @param {CdlRenderEnvironment} env Environment
974
974
  * @returns {string} Rendered order by
975
975
  */
976
- function renderOrderByEntry(entry, env) {
976
+ function renderOrderByEntry( entry, env ) {
977
977
  let result = renderExpr(entry, env);
978
978
  if (entry.sort)
979
979
  result += ` ${entry.sort}`;
@@ -992,7 +992,7 @@ function toHdbcdsSource(csn, options) {
992
992
  * @param {CdlRenderEnvironment} env Environment
993
993
  * @returns {string} The resulting parameter as source string (no trailing LF).
994
994
  */
995
- function renderParameter(parName, par, env) {
995
+ function renderParameter( parName, par, env ) {
996
996
  if (par.notNull === true || par.notNull === false)
997
997
  info('query-ignoring-param-nullability', env.path.concat([ 'params', parName ]), { '#': 'std' });
998
998
  return `${env.indent + formatParamIdentifier(parName, env.path.concat([ 'params', parName ]))} : ${renderTypeReference(par, env)}`;
@@ -1007,7 +1007,7 @@ function toHdbcdsSource(csn, options) {
1007
1007
  * @param {CdlRenderEnvironment} env Environment
1008
1008
  * @returns {string} Rendered type/annotation
1009
1009
  */
1010
- function renderType(artifactName, art, env) {
1010
+ function renderType( artifactName, art, env ) {
1011
1011
  if (art.kind === 'aspect' || art.kind === 'type' && !hdbcdsNames || art.kind === 'type' && hdbcdsNames && !art.elements)
1012
1012
  return '';
1013
1013
  let result = '';
@@ -1040,7 +1040,7 @@ function toHdbcdsSource(csn, options) {
1040
1040
  * @param {CdlRenderEnvironment} env Environment
1041
1041
  * @returns {string} Rendered type reference
1042
1042
  */
1043
- function renderTypeReference(elm, env) {
1043
+ function renderTypeReference( elm, env ) {
1044
1044
  let result = '';
1045
1045
 
1046
1046
  // Array type: Render items instead
@@ -1099,7 +1099,7 @@ function toHdbcdsSource(csn, options) {
1099
1099
  * @param {CdlRenderEnvironment} env
1100
1100
  * @returns {string}
1101
1101
  */
1102
- function renderAssociationType(elm, env) {
1102
+ function renderAssociationType( elm, env ) {
1103
1103
  // Type, cardinality and target
1104
1104
  let result = 'association';
1105
1105
 
@@ -1148,7 +1148,7 @@ function toHdbcdsSource(csn, options) {
1148
1148
  * @param {CSN.Element} elm Element with the type
1149
1149
  * @returns {string} The rendered type
1150
1150
  */
1151
- function renderBuiltinType(elm) {
1151
+ function renderBuiltinType( elm ) {
1152
1152
  if (elm.type === 'cds.Decimal' && elm.scale === undefined && elm.precision === undefined)
1153
1153
  return 'DecimalFloat';
1154
1154
 
@@ -1163,7 +1163,7 @@ function toHdbcdsSource(csn, options) {
1163
1163
  * @param {number} idx Path position
1164
1164
  * @returns {string} Rendered path step
1165
1165
  */
1166
- function renderPathStep(s, idx, ref, env) {
1166
+ function renderPathStep( s, idx, ref, env ) {
1167
1167
  // Simple id or absolute name
1168
1168
  if (typeof s === 'string') {
1169
1169
  // HANA-specific extra magic (should actually be in forRelationalDB)
@@ -1226,7 +1226,7 @@ function toHdbcdsSource(csn, options) {
1226
1226
  * @param {object} x Expression with a val and/or literal property
1227
1227
  * @returns {string} Rendered expression
1228
1228
  */
1229
- function renderExpressionLiteral(x) {
1229
+ function renderExpressionLiteral( x ) {
1230
1230
  // Literal value, possibly with explicit 'literal' property
1231
1231
  switch (x.literal || typeof x.val) {
1232
1232
  case 'number':
@@ -1256,7 +1256,7 @@ function toHdbcdsSource(csn, options) {
1256
1256
  * @param {object} x
1257
1257
  * @returns {string}
1258
1258
  */
1259
- function renderExpressionFunc(x) {
1259
+ function renderExpressionFunc( x ) {
1260
1260
  const regex = RegExp(/^[a-zA-Z][\w#$]*$/, 'g');
1261
1261
  const funcName = regex.test(x.func) ? x.func : quoteId(x.func);
1262
1262
  // we can't quote functions with parens, issue warning if it is a reserved keyword
@@ -1270,7 +1270,7 @@ function toHdbcdsSource(csn, options) {
1270
1270
  * @returns {string} Rendered expression
1271
1271
  * @todo no extra magic with x.param or x.global
1272
1272
  */
1273
- function renderExpressionRef(x) {
1273
+ function renderExpressionRef( x ) {
1274
1274
  if (!x.param && !x.global) {
1275
1275
  const magicReplacement = getVariableReplacement(x.ref, options);
1276
1276
  if (x.ref[0] === '$user') {
@@ -1309,7 +1309,7 @@ function toHdbcdsSource(csn, options) {
1309
1309
  * @param {CdlRenderEnvironment} env Environment
1310
1310
  * @returns {string} Rendered arguments
1311
1311
  */
1312
- function renderArgs(node, sep, env) {
1312
+ function renderArgs( node, sep, env ) {
1313
1313
  const args = node.args ? node.args : {};
1314
1314
  // Positional arguments
1315
1315
  if (Array.isArray(args))
@@ -1330,7 +1330,7 @@ function toHdbcdsSource(csn, options) {
1330
1330
  * @param {CSN.Cardinality} card Cardinality
1331
1331
  * @returns {string} Rendered cardinality
1332
1332
  */
1333
- function renderCardinality(card) {
1333
+ function renderCardinality( card ) {
1334
1334
  if (!card)
1335
1335
  return '';
1336
1336
 
@@ -1353,7 +1353,7 @@ function toHdbcdsSource(csn, options) {
1353
1353
  * @param {object} obj Thing to render for
1354
1354
  * @returns {string} null/not null
1355
1355
  */
1356
- function renderNullability(obj /* , env */) {
1356
+ function renderNullability( obj /* , env */) {
1357
1357
  if (obj.notNull === undefined) {
1358
1358
  // Attribute not set at all
1359
1359
  return '';
@@ -1370,7 +1370,7 @@ function toHdbcdsSource(csn, options) {
1370
1370
  * @param {CdlRenderEnvironment} env Environment
1371
1371
  * @returns {string} Rendered foreign key
1372
1372
  */
1373
- function renderForeignKey(fKey, env) {
1373
+ function renderForeignKey( fKey, env ) {
1374
1374
  return `${renderExpr(fKey, env)}${fKey.as ? (` as ${fKey.as}`) : ''}`;
1375
1375
  }
1376
1376
 
@@ -1381,7 +1381,7 @@ function toHdbcdsSource(csn, options) {
1381
1381
  * @param {CSN.Element} elm Element to render type parameters for
1382
1382
  * @returns {string} Rendered type parameters
1383
1383
  */
1384
- function renderTypeParameters(elm /* , env */) {
1384
+ function renderTypeParameters( elm /* , env */) {
1385
1385
  const params = [];
1386
1386
  // Length, precision and scale (even if incomplete)
1387
1387
  if (elm.length !== undefined)
@@ -1408,7 +1408,7 @@ function toHdbcdsSource(csn, options) {
1408
1408
  * @param {CdlRenderEnvironment} env Environment
1409
1409
  * @returns {string} Uppercased and underscored absName
1410
1410
  */
1411
- function renderAbsoluteNamePlain(absName, env) {
1411
+ function renderAbsoluteNamePlain( absName, env ) {
1412
1412
  // Add using declaration
1413
1413
  env.topLevelAliases[absName] = {
1414
1414
  quotedName: formatIdentifier(uppercaseAndUnderscore(absName)),
@@ -1426,7 +1426,7 @@ function toHdbcdsSource(csn, options) {
1426
1426
  * @param {CdlRenderEnvironment} env Environment
1427
1427
  * @returns {string} absName, with correct quotes
1428
1428
  */
1429
- function renderAbsoluteNameWithQuotes(absName, env) {
1429
+ function renderAbsoluteNameWithQuotes( absName, env ) {
1430
1430
  // Special case: If the top-level artifact name is not a valid artifact name, it came from an unchecked annotation
1431
1431
  // and must be left as it is (just quoted)
1432
1432
  let topLevelName = getRootArtifactName(absName, csn);
@@ -1484,7 +1484,7 @@ function toHdbcdsSource(csn, options) {
1484
1484
  * @param {string} topLevelName Name of a top-level artifact
1485
1485
  * @returns {string} Appropriate __alias
1486
1486
  */
1487
- function createTopLevelAliasName(topLevelName) {
1487
+ function createTopLevelAliasName( topLevelName ) {
1488
1488
  // FIXME: We should rather check for conflicts than just using something obscure like this ...
1489
1489
  return `__${topLevelName.replace(/::/g, '__').replace(/\./g, '_')}`;
1490
1490
  }
@@ -1496,7 +1496,7 @@ function toHdbcdsSource(csn, options) {
1496
1496
  * @param {CdlRenderEnvironment} env Environment
1497
1497
  * @returns {string} Usings for the given artifact
1498
1498
  */
1499
- function renderUsings(artifactName, env) {
1499
+ function renderUsings( artifactName, env ) {
1500
1500
  const distinct = {};
1501
1501
  Object.keys(env.topLevelAliases)
1502
1502
  .filter(name => env.topLevelAliases[name].quotedAlias !== formatIdentifier(uppercaseAndUnderscore(artifactName))) // avoid "using FOO as FOO" in FOO.cds
@@ -1513,7 +1513,7 @@ function toHdbcdsSource(csn, options) {
1513
1513
  * see cap/cds-compiler#8269 for details
1514
1514
  * @param {string} name of the native db object
1515
1515
  */
1516
- function checkForNameClashesWithNativeObject(name) {
1516
+ function checkForNameClashesWithNativeObject( name ) {
1517
1517
  const possibleShadowName = getNamePrefix(env.topLevelAliases[name].quotedName);
1518
1518
  const mightBeShadowedBy = csn.definitions[possibleShadowName];
1519
1519
  if (mightBeShadowedBy) {
@@ -1524,7 +1524,7 @@ function toHdbcdsSource(csn, options) {
1524
1524
  }
1525
1525
  }
1526
1526
 
1527
- function isArtifactRendered(art, artName) {
1527
+ function isArtifactRendered( art, artName ) {
1528
1528
  const isHanaCdsContext = art.kind === 'service' || art.kind === 'context';
1529
1529
  if (isHanaCdsContext)
1530
1530
  return isContextRendered(artName);
@@ -1541,7 +1541,7 @@ function toHdbcdsSource(csn, options) {
1541
1541
  * @param {string} contextName
1542
1542
  * @returns {boolean} true if a context/service will be rendered as a SAP HANA CDS context.
1543
1543
  */
1544
- function isContextRendered(contextName) {
1544
+ function isContextRendered( contextName ) {
1545
1545
  const subArtifacts = getSubArtifacts(contextName);
1546
1546
  return Object.entries(subArtifacts).some(([ artName, art ]) => {
1547
1547
  if (art.kind === 'context')
@@ -1557,7 +1557,7 @@ function toHdbcdsSource(csn, options) {
1557
1557
  * "com.sap.foo.native.object" --> com
1558
1558
  * "com.sap.foo::native.object" --> com.sap.foo.native
1559
1559
  */
1560
- function getNamePrefix(usingName) {
1560
+ function getNamePrefix( usingName ) {
1561
1561
  usingName = usingName.replace(/"/g, '');
1562
1562
  if (usingName.indexOf('::') !== -1) {
1563
1563
  const parts = usingName.split('::');
@@ -1579,7 +1579,7 @@ function toHdbcdsSource(csn, options) {
1579
1579
  * @param {CdlRenderEnvironment} env Environment
1580
1580
  * @returns {string} Rendered namespace declaration
1581
1581
  */
1582
- function renderNamespaceDeclaration(topLevelName, env) {
1582
+ function renderNamespaceDeclaration( topLevelName, env ) {
1583
1583
  if (plainNames) {
1584
1584
  // No namespaces in plain mode
1585
1585
  return '';
@@ -1643,7 +1643,7 @@ function toHdbcdsSource(csn, options) {
1643
1643
  * @param {string} id Name prefix to add
1644
1644
  * @returns {CdlRenderEnvironment} New environment with added prefix
1645
1645
  */
1646
- function addNamePrefix(env, id) {
1646
+ function addNamePrefix( env, id ) {
1647
1647
  return Object.assign({}, env, { namePrefix: `${env.namePrefix + quoteId(id)}.` });
1648
1648
  }
1649
1649
 
@@ -1653,7 +1653,7 @@ function toHdbcdsSource(csn, options) {
1653
1653
  * @param {CdlRenderEnvironment} env Current environment
1654
1654
  * @returns {CdlRenderEnvironment} New environment with increased indent
1655
1655
  */
1656
- function increaseIndent(env) {
1656
+ function increaseIndent( env ) {
1657
1657
  return Object.assign({}, env, { namePrefix: '', indent: `${env.indent} ` });
1658
1658
  }
1659
1659
 
@@ -1663,7 +1663,7 @@ function toHdbcdsSource(csn, options) {
1663
1663
  * @param {string} path Path to quote
1664
1664
  * @returns {string} Quoted path
1665
1665
  */
1666
- function quotePathString(path) {
1666
+ function quotePathString( path ) {
1667
1667
  // "foo"."bar"."wiz"."blub"
1668
1668
  return path.split('.').map(quoteId).join('.');
1669
1669
  }
@@ -1675,7 +1675,7 @@ function toHdbcdsSource(csn, options) {
1675
1675
  * @param {string} absPath Absolute path to quote
1676
1676
  * @returns {string} Quoted path
1677
1677
  */
1678
- function quoteAbsolutePathString(absPath) {
1678
+ function quoteAbsolutePathString( absPath ) {
1679
1679
  const namespace = getNamespace(csn, absPath);
1680
1680
  const resultingName = getResultingName(csn, options.sqlMapping, absPath);
1681
1681
 
@@ -1691,7 +1691,7 @@ function toHdbcdsSource(csn, options) {
1691
1691
  * @param {string} id Identifier to quote
1692
1692
  * @returns {string} Properly quoted identifier
1693
1693
  */
1694
- function quoteId(id) {
1694
+ function quoteId( id ) {
1695
1695
  // Should only ever be called for real IDs (i.e. no dots inside)
1696
1696
  if (id.indexOf('.') !== -1)
1697
1697
  throw new ModelError(`HDBCDS: Tried to quote id with dot: ${id}`);
@@ -1715,7 +1715,7 @@ function toHdbcdsSource(csn, options) {
1715
1715
  * @param {string} absName Absolute name
1716
1716
  * @returns {string} Correctly quoted absName
1717
1717
  */
1718
- function quoteAbsoluteNameAsId(absName) {
1718
+ function quoteAbsoluteNameAsId( absName ) {
1719
1719
  const resultingName = getResultingName(csn, options.sqlMapping, absName);
1720
1720
 
1721
1721
  if (hdbcdsNames) {
@@ -1732,7 +1732,7 @@ function toHdbcdsSource(csn, options) {
1732
1732
  * @param {string} id Identifier
1733
1733
  * @returns {string} Quoted/uppercased id
1734
1734
  */
1735
- function formatIdentifier(id) {
1735
+ function formatIdentifier( id ) {
1736
1736
  id = plainNames ? id.toUpperCase() : id;
1737
1737
  return quoteId(id);
1738
1738
  }
@@ -1746,7 +1746,7 @@ function toHdbcdsSource(csn, options) {
1746
1746
  * @param {CSN.Path} [location] Optional location for the warning.
1747
1747
  * @returns {string} Quoted/uppercased id
1748
1748
  */
1749
- function formatParamIdentifier(id, location) {
1749
+ function formatParamIdentifier( id, location ) {
1750
1750
  // Warn if colliding with HANA keyword, but do not quote for plain
1751
1751
  // --> quoted reserved words as param lead to a weird deployment error
1752
1752
  if (keywords.hdbcds.includes(uppercaseAndUnderscore(id)))
@@ -1775,7 +1775,7 @@ function toHdbcdsSource(csn, options) {
1775
1775
  * @param {boolean} [fallthrough=false] For certain artifacts, plain-rendering is supposed to look like quoted/hdbcds
1776
1776
  * @returns {string} Artifact name ready for rendering
1777
1777
  */
1778
- function renderArtifactName(artifactName, env, fallthrough = false) {
1778
+ function renderArtifactName( artifactName, env, fallthrough = false ) {
1779
1779
  if (plainNames && !fallthrough)
1780
1780
  return formatIdentifier(uppercaseAndUnderscore(artifactName));
1781
1781
  // hdbcds with quoted or hdbcds naming
@@ -1792,7 +1792,7 @@ function toHdbcdsSource(csn, options) {
1792
1792
  * @param {string} name Name to transform
1793
1793
  * @returns {string} Uppercased and underscored name
1794
1794
  */
1795
- function uppercaseAndUnderscore(name) {
1795
+ function uppercaseAndUnderscore( name ) {
1796
1796
  // Always replace '.' by '_' and uppercase
1797
1797
  return name.replace(/\./g, '_').toUpperCase();
1798
1798
  }
@@ -1807,9 +1807,9 @@ function toHdbcdsSource(csn, options) {
1807
1807
  * @property {{[name: string]: {
1808
1808
  quotedName: string,
1809
1809
  quotedAlias: string
1810
- }}} topLevelAliases Dictionary of aliases for used artifact names
1810
+ }}} [topLevelAliases] Dictionary of aliases for used artifact names
1811
1811
  *
1812
- * @property {string} namePrefix Current name prefix (including trailing dot if not empty)
1812
+ * @property {string} [namePrefix] Current name prefix (including trailing dot if not empty)
1813
1813
  * @property {boolean} [skipKeys] Skip rendering keys in subqueries
1814
1814
  * @property {CSN.Artifact} [_artifact] The original view artifact, used when rendering queries
1815
1815
  */
@@ -30,7 +30,7 @@ const { transformForRelationalDBWithCsn } = require('../transform/forRelationalD
30
30
  * @param {CSN.Options} options Transformation options
31
31
  * @returns {object} A dictionary of name: rename statement
32
32
  */
33
- function toRename(inputCsn, options) {
33
+ function toRename( inputCsn, options ) {
34
34
  const { error, warning, throwWithError } = makeMessageFunction(inputCsn, options, 'to.rename');
35
35
 
36
36
  // Merge options with defaults.
@@ -80,7 +80,7 @@ function toRename(inputCsn, options) {
80
80
  * @param {CSN.Artifact} art CSN artifact
81
81
  * @returns {string} RENAME statements
82
82
  */
83
- function renameTableAndColumns(artifactName, art) {
83
+ function renameTableAndColumns( artifactName, art ) {
84
84
  let resultStr = '';
85
85
  if (art.kind === 'entity' && !art.query) {
86
86
  const beforeTableName = quoteSqlId(absoluteCdsName(artifactName));
@@ -118,7 +118,7 @@ function toRename(inputCsn, options) {
118
118
  * @param {string} name Name to absolutify
119
119
  * @returns {string} Absolute name
120
120
  */
121
- function absoluteCdsName(name) {
121
+ function absoluteCdsName( name ) {
122
122
  if (options.sqlMapping !== 'hdbcds')
123
123
  return name;
124
124
 
@@ -136,7 +136,7 @@ function toRename(inputCsn, options) {
136
136
  * @param {string} name Name to quote
137
137
  * @returns {string} Quoted string
138
138
  */
139
- function quoteSqlId(name) {
139
+ function quoteSqlId( name ) {
140
140
  if (options.sqlMapping === 'quoted')
141
141
  name = name.replace(/::/g, '.');
142
142
 
@@ -150,7 +150,7 @@ function toRename(inputCsn, options) {
150
150
  * @param {string} name Name to turn into a plain identifier
151
151
  * @returns {string} A plain SQL identifier
152
152
  */
153
- function plainSqlId(name) {
153
+ function plainSqlId( name ) {
154
154
  return `"${name.toUpperCase().replace(/(::|\.)/g, '_').replace(/"/g, '""')}"`;
155
155
  }
156
156
  }