@sap/cds-compiler 5.9.4 → 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.
- package/CHANGELOG.md +104 -319
- package/README.md +1 -1
- package/bin/cds_update_identifiers.js +3 -5
- package/bin/cdsc.js +22 -8
- package/bin/cdshi.js +1 -1
- package/bin/cdsse.js +4 -4
- package/doc/CHANGELOG_BETA.md +11 -0
- package/doc/CHANGELOG_DEPRECATED.md +29 -0
- package/lib/api/main.js +8 -5
- package/lib/api/options.js +12 -10
- package/lib/base/builtins.js +1 -0
- package/lib/base/message-registry.js +190 -96
- package/lib/base/messages.js +29 -20
- package/lib/base/model.js +14 -24
- package/lib/checks/actionsFunctions.js +10 -20
- package/lib/checks/annotationsOData.js +1 -1
- package/lib/checks/elements.js +30 -10
- package/lib/checks/enums.js +31 -0
- package/lib/checks/foreignKeys.js +2 -2
- package/lib/checks/hasPersistedElements.js +5 -0
- package/lib/checks/invalidTarget.js +1 -1
- package/lib/checks/managedWithoutKeys.js +5 -4
- package/lib/checks/queryNoDbArtifacts.js +10 -8
- package/lib/checks/types.js +5 -5
- package/lib/checks/validator.js +6 -4
- package/lib/compiler/assert-consistency.js +12 -9
- package/lib/compiler/checks.js +18 -50
- package/lib/compiler/define.js +6 -6
- package/lib/compiler/extend.js +2 -1
- package/lib/compiler/generate.js +14 -17
- package/lib/compiler/populate.js +8 -31
- package/lib/compiler/propagator.js +21 -35
- package/lib/compiler/resolve.js +35 -22
- package/lib/compiler/shared.js +7 -1
- package/lib/compiler/tweak-assocs.js +1 -1
- package/lib/compiler/utils.js +1 -1
- package/lib/edm/annotations/edmJson.js +20 -15
- package/lib/edm/annotations/genericTranslation.js +7 -8
- package/lib/edm/csn2edm.js +46 -50
- package/lib/edm/edm.js +8 -7
- package/lib/edm/edmPreprocessor.js +33 -83
- package/lib/edm/edmUtils.js +2 -2
- package/lib/gen/BaseParser.js +55 -44
- package/lib/gen/CdlGrammar.checksum +1 -1
- package/lib/gen/CdlParser.js +1133 -1150
- package/lib/json/from-csn.js +70 -43
- package/lib/json/to-csn.js +6 -8
- package/lib/language/multiLineStringParser.js +3 -2
- package/lib/main.d.ts +58 -24
- package/lib/model/csnUtils.js +28 -39
- package/lib/model/xprAsTree.js +23 -9
- package/lib/modelCompare/compare.js +5 -4
- package/lib/optionProcessor.js +21 -17
- package/lib/parsers/AstBuildingParser.js +63 -11
- package/lib/parsers/XprTree.js +57 -3
- package/lib/parsers/identifiers.js +1 -1
- package/lib/parsers/index.js +0 -3
- package/lib/render/manageConstraints.js +25 -25
- package/lib/render/toCdl.js +173 -170
- package/lib/render/toHdbcds.js +126 -128
- package/lib/render/toRename.js +7 -7
- package/lib/render/toSql.js +128 -125
- package/lib/render/utils/common.js +47 -22
- package/lib/render/utils/delta.js +25 -25
- package/lib/render/utils/operators.js +2 -2
- package/lib/render/utils/pretty.js +5 -5
- package/lib/render/utils/sql.js +13 -13
- package/lib/render/utils/standardDatabaseFunctions.js +115 -103
- package/lib/render/utils/unique.js +4 -4
- package/lib/transform/db/applyTransformations.js +1 -1
- package/lib/transform/db/assertUnique.js +2 -2
- package/lib/transform/db/associations.js +6 -7
- package/lib/transform/db/assocsToQueries/utils.js +4 -5
- package/lib/transform/db/backlinks.js +12 -9
- package/lib/transform/db/cdsPersistence.js +8 -7
- package/lib/transform/db/constraints.js +13 -10
- package/lib/transform/db/expansion.js +7 -3
- package/lib/transform/db/flattening.js +4 -14
- package/lib/transform/db/processSqlServices.js +2 -1
- package/lib/transform/db/temporal.js +5 -7
- package/lib/transform/db/views.js +2 -4
- package/lib/transform/draft/db.js +8 -8
- package/lib/transform/draft/odata.js +10 -7
- package/lib/transform/forOdata.js +10 -5
- package/lib/transform/forRelationalDB.js +5 -75
- package/lib/transform/localized.js +1 -1
- package/lib/transform/odata/createForeignKeys.js +11 -10
- package/lib/transform/odata/flattening.js +8 -4
- package/lib/transform/odata/foreignKeyRefsInXprAnnos.js +96 -0
- package/lib/transform/odata/typesExposure.js +3 -3
- package/lib/transform/transformUtils.js +4 -8
- package/lib/transform/translateAssocsToJoins.js +14 -7
- package/lib/transform/universalCsn/universalCsnEnricher.js +10 -4
- package/lib/utils/objectUtils.js +0 -17
- package/package.json +10 -13
- package/share/messages/def-upcoming-virtual-change.md +1 -1
- package/LICENSE +0 -37
- package/bin/cds_remove_invalid_whitespace.js +0 -138
- package/doc/CHANGELOG_ARCHIVE.md +0 -3604
- package/lib/gen/genericAntlrParser.js +0 -3
- package/lib/gen/language.checksum +0 -1
- package/lib/gen/language.interp +0 -456
- package/lib/gen/language.tokens +0 -180
- package/lib/gen/languageLexer.interp +0 -439
- package/lib/gen/languageLexer.js +0 -1483
- package/lib/gen/languageLexer.tokens +0 -167
- package/lib/gen/languageParser.js +0 -24941
- package/lib/language/antlrParser.js +0 -205
- package/lib/language/errorStrategy.js +0 -646
- package/lib/language/genericAntlrParser.js +0 -1572
- 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
|
-
}
|