@sap/cds-compiler 5.9.2 → 6.0.10

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 (111) hide show
  1. package/CHANGELOG.md +109 -319
  2. package/README.md +1 -1
  3. package/bin/cds_update_identifiers.js +3 -5
  4. package/bin/cdsc.js +22 -8
  5. package/bin/cdshi.js +1 -1
  6. package/bin/cdsse.js +4 -4
  7. package/doc/CHANGELOG_BETA.md +11 -0
  8. package/doc/CHANGELOG_DEPRECATED.md +29 -0
  9. package/lib/api/main.js +8 -5
  10. package/lib/api/options.js +12 -10
  11. package/lib/base/builtins.js +1 -0
  12. package/lib/base/message-registry.js +190 -96
  13. package/lib/base/messages.js +29 -20
  14. package/lib/base/model.js +14 -24
  15. package/lib/checks/actionsFunctions.js +10 -20
  16. package/lib/checks/annotationsOData.js +1 -1
  17. package/lib/checks/elements.js +30 -10
  18. package/lib/checks/enums.js +31 -0
  19. package/lib/checks/foreignKeys.js +2 -2
  20. package/lib/checks/hasPersistedElements.js +5 -0
  21. package/lib/checks/invalidTarget.js +1 -1
  22. package/lib/checks/managedWithoutKeys.js +5 -4
  23. package/lib/checks/queryNoDbArtifacts.js +10 -8
  24. package/lib/checks/types.js +5 -5
  25. package/lib/checks/validator.js +6 -4
  26. package/lib/compiler/assert-consistency.js +12 -9
  27. package/lib/compiler/checks.js +18 -50
  28. package/lib/compiler/define.js +6 -6
  29. package/lib/compiler/extend.js +2 -1
  30. package/lib/compiler/generate.js +14 -17
  31. package/lib/compiler/populate.js +8 -31
  32. package/lib/compiler/propagator.js +21 -35
  33. package/lib/compiler/resolve.js +35 -22
  34. package/lib/compiler/shared.js +7 -1
  35. package/lib/compiler/tweak-assocs.js +1 -1
  36. package/lib/compiler/utils.js +1 -1
  37. package/lib/edm/annotations/edmJson.js +20 -15
  38. package/lib/edm/annotations/genericTranslation.js +7 -8
  39. package/lib/edm/csn2edm.js +46 -50
  40. package/lib/edm/edm.js +8 -7
  41. package/lib/edm/edmPreprocessor.js +37 -85
  42. package/lib/edm/edmUtils.js +2 -2
  43. package/lib/gen/BaseParser.js +55 -44
  44. package/lib/gen/CdlGrammar.checksum +1 -1
  45. package/lib/gen/CdlParser.js +1133 -1150
  46. package/lib/json/from-csn.js +70 -43
  47. package/lib/json/to-csn.js +6 -8
  48. package/lib/language/multiLineStringParser.js +3 -2
  49. package/lib/main.d.ts +58 -24
  50. package/lib/model/csnUtils.js +28 -39
  51. package/lib/model/xprAsTree.js +23 -9
  52. package/lib/modelCompare/compare.js +5 -4
  53. package/lib/optionProcessor.js +21 -17
  54. package/lib/parsers/AstBuildingParser.js +63 -11
  55. package/lib/parsers/XprTree.js +57 -3
  56. package/lib/parsers/identifiers.js +1 -1
  57. package/lib/parsers/index.js +0 -3
  58. package/lib/render/manageConstraints.js +25 -25
  59. package/lib/render/toCdl.js +173 -170
  60. package/lib/render/toHdbcds.js +126 -128
  61. package/lib/render/toRename.js +7 -7
  62. package/lib/render/toSql.js +128 -125
  63. package/lib/render/utils/common.js +47 -22
  64. package/lib/render/utils/delta.js +25 -25
  65. package/lib/render/utils/operators.js +2 -2
  66. package/lib/render/utils/pretty.js +5 -5
  67. package/lib/render/utils/sql.js +13 -13
  68. package/lib/render/utils/standardDatabaseFunctions.js +115 -103
  69. package/lib/render/utils/unique.js +4 -4
  70. package/lib/transform/db/applyTransformations.js +1 -1
  71. package/lib/transform/db/assertUnique.js +2 -2
  72. package/lib/transform/db/associations.js +6 -7
  73. package/lib/transform/db/assocsToQueries/utils.js +4 -5
  74. package/lib/transform/db/backlinks.js +12 -9
  75. package/lib/transform/db/cdsPersistence.js +8 -7
  76. package/lib/transform/db/constraints.js +13 -10
  77. package/lib/transform/db/expansion.js +7 -3
  78. package/lib/transform/db/flattening.js +4 -14
  79. package/lib/transform/db/processSqlServices.js +2 -1
  80. package/lib/transform/db/temporal.js +5 -7
  81. package/lib/transform/db/views.js +2 -4
  82. package/lib/transform/draft/db.js +8 -8
  83. package/lib/transform/draft/odata.js +10 -7
  84. package/lib/transform/forOdata.js +10 -5
  85. package/lib/transform/forRelationalDB.js +5 -75
  86. package/lib/transform/localized.js +1 -1
  87. package/lib/transform/odata/createForeignKeys.js +11 -10
  88. package/lib/transform/odata/flattening.js +8 -4
  89. package/lib/transform/odata/foreignKeyRefsInXprAnnos.js +96 -0
  90. package/lib/transform/odata/typesExposure.js +3 -3
  91. package/lib/transform/transformUtils.js +4 -8
  92. package/lib/transform/translateAssocsToJoins.js +14 -7
  93. package/lib/transform/universalCsn/universalCsnEnricher.js +10 -4
  94. package/lib/utils/objectUtils.js +0 -17
  95. package/package.json +10 -13
  96. package/share/messages/def-upcoming-virtual-change.md +1 -1
  97. package/LICENSE +0 -37
  98. package/bin/cds_remove_invalid_whitespace.js +0 -138
  99. package/doc/CHANGELOG_ARCHIVE.md +0 -3604
  100. package/lib/gen/genericAntlrParser.js +0 -3
  101. package/lib/gen/language.checksum +0 -1
  102. package/lib/gen/language.interp +0 -456
  103. package/lib/gen/language.tokens +0 -180
  104. package/lib/gen/languageLexer.interp +0 -439
  105. package/lib/gen/languageLexer.js +0 -1483
  106. package/lib/gen/languageLexer.tokens +0 -167
  107. package/lib/gen/languageParser.js +0 -24941
  108. package/lib/language/antlrParser.js +0 -205
  109. package/lib/language/errorStrategy.js +0 -646
  110. package/lib/language/genericAntlrParser.js +0 -1572
  111. package/lib/parsers/CdlGrammar.g4 +0 -2070
@@ -1,138 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // Remove whitespace where the compiler does not expect it and will
4
- // emit an error in the next major version. (Remark: not necessarily)
5
- //
6
- // This script removes whitespace where necessary.
7
- // It does not remove comments, even though they count as whitespace.
8
- //
9
- // Example CDS:
10
- // entity P as projection on E { s. * };
11
- // will become:
12
- // entity P as projection on E { s.* };
13
- //
14
- // Usage:
15
- // ./cds_remove_invalid_whitespace.js my_file.cds
16
- //
17
- // If you want to update all files in a directory, you can use
18
- // this shell script:
19
- // find . -type f -iname '*.cds' -exec ./cds_remove_invalid_whitespace.js {} \;
20
- //
21
- // Note that you need to update the path to this script in the commands above.
22
- //
23
-
24
- /* eslint no-process-exit: 0, no-console: 0 */
25
-
26
- 'use strict';
27
-
28
- const parsers = require('../lib/parsers');
29
- const { createMessageFunctions } = require('../lib/base/messages');
30
-
31
- const fs = require('fs');
32
- const path = require('path');
33
-
34
- const cliArgs = process.argv.slice(2);
35
- const filepath = cliArgs[0];
36
-
37
- if (filepath === '--help' || filepath === '-h')
38
- exitError();
39
-
40
- if (cliArgs.length !== 1)
41
- exitError(`Expected exactly one argument, ${ cliArgs.length } given`);
42
-
43
- if (!filepath)
44
- exitError('Expected non-empty filepath as argument!');
45
-
46
- // Do not use allow-list approach.
47
- // There may be CDS files with other extensions than `.cds`.
48
- if (filepath.endsWith('.csn') || filepath.endsWith('.json'))
49
- exitError('Only CDS files can be passed! Found CSN file!');
50
-
51
- const sourceStr = fs.readFileSync(filepath, 'utf-8');
52
- const newSourceStr = modernizeWhitespace(sourceStr, filepath);
53
- if (newSourceStr !== sourceStr)
54
- fs.writeFileSync(filepath, newSourceStr);
55
- process.exit(0); // success
56
-
57
- // --------------------------------------------------------
58
-
59
- function modernizeWhitespace( source, filename ) {
60
- const options = { messages: [], attachTokens: true };
61
- const messageFunctions = createMessageFunctions( options, 'parse', null );
62
-
63
- // parseCdl does not throw on CompilationError, so
64
- // we do not need a try...catch block.
65
- const ast = parsers.parseCdl(source, filename, options, messageFunctions);
66
-
67
- // To avoid spam, only report errors.
68
- // Users should use the compiler to get all messages.
69
- const errors = options.messages
70
- .filter(msg => (msg.severity === 'Error' && msg.messageId !== 'syntax-invalid-space'));
71
- if (errors.length > 0) {
72
- errors.forEach((msg) => {
73
- console.error(msg.toString());
74
- });
75
- console.error(`Found ${ errors.length } errors! \n`);
76
- exitError('The CDS parser emitted errors. Fix them first and try again.');
77
- }
78
-
79
- if (!ast.artifacts)
80
- return source;
81
-
82
- let currentOffset = 0;
83
-
84
- const { tokens } = ast.tokenStream;
85
- for (let i = 0; i < tokens.length; ++i) {
86
- const token = tokens[i];
87
- const next = tokens[i + 1];
88
- if (next && token.type === ast.tokenStream.DOTbeforeBRACE &&
89
- (next.type === ast.tokenStream.ASTERISK || next.type === ast.tokenStream.BRACE))
90
- updateWhitespace(token, next);
91
- }
92
-
93
- return source;
94
-
95
- // -----------------------------------------------
96
-
97
- function updateWhitespace( dot, braceOrAsterisk ) {
98
- if (dot.stop === braceOrAsterisk.start)
99
- return;
100
-
101
- const from = dot.stop + currentOffset + 1; // end points at the position *before* the character
102
- const to = braceOrAsterisk.start + currentOffset;
103
-
104
- source = replaceSliceInSource(source, from, to, '');
105
-
106
- currentOffset -= to - from;
107
- }
108
- }
109
-
110
- /**
111
- * Replaces a given span with @p replaceWith
112
- *
113
- * @param {string} source
114
- * @param {number} startIndex
115
- * @param {number} endIndex
116
- * @param {string} replaceWith
117
- * @return {string}
118
- */
119
- function replaceSliceInSource( source, startIndex, endIndex, replaceWith ) {
120
- return source.substring(0, startIndex) +
121
- replaceWith +
122
- source.substring(endIndex);
123
- }
124
-
125
- /**
126
- * @param {string} [msg]
127
- */
128
- function exitError( msg ) {
129
- if (msg)
130
- console.error(msg);
131
- usage();
132
- process.exit(1);
133
- }
134
-
135
- function usage() {
136
- console.error('');
137
- console.error(`usage: ${ path.basename(process.argv[1]) } <filename>`);
138
- }