@sap/cds-compiler 2.15.4 → 3.0.0
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 +33 -1590
- package/bin/cdsc.js +36 -33
- package/doc/CHANGELOG_ARCHIVE.md +1592 -0
- package/doc/CHANGELOG_BETA.md +3 -4
- package/doc/CHANGELOG_DEPRECATED.md +35 -1
- package/doc/{DeprecatedOptions.md → DeprecatedOptions_v2.md} +3 -1
- package/doc/Versioning.md +20 -1
- package/lib/api/.eslintrc.json +2 -2
- package/lib/api/main.js +220 -103
- package/lib/api/options.js +15 -85
- package/lib/api/validate.js +6 -10
- package/lib/base/keywords.js +216 -109
- package/lib/base/message-registry.js +60 -20
- package/lib/base/messages.js +65 -24
- package/lib/base/model.js +44 -2
- package/lib/checks/actionsFunctions.js +7 -5
- package/lib/checks/annotationsOData.js +1 -1
- package/lib/checks/cdsPersistence.js +1 -0
- package/lib/checks/elements.js +6 -6
- package/lib/checks/invalidTarget.js +1 -1
- package/lib/checks/nonexpandableStructured.js +1 -1
- package/lib/checks/queryNoDbArtifacts.js +2 -1
- package/lib/checks/selectItems.js +5 -1
- package/lib/checks/types.js +4 -2
- package/lib/checks/utils.js +2 -2
- package/lib/checks/validator.js +2 -1
- package/lib/compiler/assert-consistency.js +15 -10
- package/lib/compiler/builtins.js +87 -9
- package/lib/compiler/define.js +2 -2
- package/lib/compiler/extend.js +59 -11
- package/lib/compiler/finalize-parse-cdl.js +20 -9
- package/lib/compiler/index.js +25 -11
- package/lib/compiler/moduleLayers.js +7 -0
- package/lib/compiler/populate.js +13 -13
- package/lib/compiler/propagator.js +3 -3
- package/lib/compiler/resolve.js +193 -218
- package/lib/compiler/shared.js +47 -76
- package/lib/compiler/tweak-assocs.js +9 -10
- package/lib/compiler/utils.js +5 -0
- package/lib/edm/csn2edm.js +18 -21
- package/lib/edm/edmPreprocessor.js +25 -30
- package/lib/edm/edmUtils.js +10 -24
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +8 -30
- package/lib/gen/language.tokens +105 -114
- package/lib/gen/languageLexer.interp +1 -34
- package/lib/gen/languageLexer.js +889 -1007
- package/lib/gen/languageLexer.tokens +95 -106
- package/lib/gen/languageParser.js +20632 -22313
- package/lib/json/from-csn.js +56 -49
- package/lib/json/to-csn.js +10 -8
- package/lib/language/antlrParser.js +2 -2
- package/lib/language/docCommentParser.js +61 -38
- package/lib/language/errorStrategy.js +52 -40
- package/lib/language/genericAntlrParser.js +303 -229
- package/lib/language/language.g4 +573 -629
- package/lib/language/multiLineStringParser.js +14 -42
- package/lib/language/textUtils.js +44 -0
- package/lib/main.d.ts +27 -42
- package/lib/main.js +104 -81
- package/lib/model/csnRefs.js +1 -1
- package/lib/model/csnUtils.js +170 -283
- package/lib/model/revealInternalProperties.js +28 -8
- package/lib/model/sortViews.js +32 -31
- package/lib/optionProcessor.js +12 -21
- package/lib/render/.eslintrc.json +1 -1
- package/lib/render/DuplicateChecker.js +4 -7
- package/lib/render/manageConstraints.js +70 -2
- package/lib/render/toCdl.js +334 -339
- package/lib/render/toHdbcds.js +19 -15
- package/lib/render/toRename.js +44 -22
- package/lib/render/toSql.js +53 -51
- package/lib/render/utils/common.js +15 -1
- package/lib/render/utils/sql.js +20 -19
- package/lib/sql-identifier.js +6 -0
- package/lib/transform/db/.eslintrc.json +3 -2
- package/lib/transform/db/cdsPersistence.js +5 -15
- package/lib/transform/db/constraints.js +1 -1
- package/lib/transform/db/expansion.js +7 -6
- package/lib/transform/db/flattening.js +18 -19
- package/lib/transform/db/views.js +3 -3
- package/lib/transform/draft/.eslintrc.json +2 -2
- package/lib/transform/draft/db.js +6 -6
- package/lib/transform/draft/odata.js +6 -7
- package/lib/transform/forHanaNew.js +19 -22
- package/lib/transform/forOdataNew.js +10 -12
- package/lib/transform/localized.js +22 -16
- package/lib/transform/odata/toFinalBaseType.js +10 -10
- package/lib/transform/odata/typesExposure.js +3 -3
- package/lib/transform/odata/utils.js +1 -38
- package/lib/transform/transformUtilsNew.js +63 -77
- package/lib/transform/translateAssocsToJoins.js +2 -2
- package/lib/transform/universalCsn/.eslintrc.json +2 -2
- package/lib/transform/universalCsn/coreComputed.js +11 -6
- package/lib/transform/universalCsn/universalCsnEnricher.js +33 -5
- package/lib/utils/file.js +3 -3
- package/lib/utils/timetrace.js +20 -21
- package/package.json +35 -4
- package/doc/ApiMigration.md +0 -237
- package/doc/CommandLineMigration.md +0 -58
- package/doc/ErrorMessages.md +0 -175
- package/doc/FioriAnnotations.md +0 -94
- package/doc/ODataTransformation.md +0 -273
- package/lib/backends.js +0 -529
- package/lib/fix_antlr4-8_warning.js +0 -56
package/lib/api/options.js
CHANGED
|
@@ -24,7 +24,7 @@ const publicOptionsNewAPI = [
|
|
|
24
24
|
'sqlChangeMode',
|
|
25
25
|
'allowCsnDowngrade',
|
|
26
26
|
'joinfk',
|
|
27
|
-
'magicVars', // deprecated
|
|
27
|
+
'magicVars', // deprecated, not removed in v3 as we have specific error messages for it
|
|
28
28
|
'variableReplacements',
|
|
29
29
|
// ODATA
|
|
30
30
|
'odataVersion',
|
|
@@ -107,47 +107,10 @@ function translateOptions(input = {}, defaults = {}, hardRequire = {},
|
|
|
107
107
|
// Overwrite with the hardRequire options - like src: sql in to.sql()
|
|
108
108
|
Object.assign(options, hardRequire);
|
|
109
109
|
|
|
110
|
-
for (const optionName in options) {
|
|
111
|
-
const optionValue = options[optionName];
|
|
112
|
-
mapToOldNames(optionName, optionValue);
|
|
113
|
-
}
|
|
114
|
-
|
|
115
110
|
// Convenience for $user -> $user.id replacement
|
|
116
111
|
if (options.variableReplacements && options.variableReplacements.$user && typeof options.variableReplacements.$user === 'string')
|
|
117
112
|
options.variableReplacements.$user = { id: options.variableReplacements.$user };
|
|
118
113
|
|
|
119
|
-
/**
|
|
120
|
-
* Map a new-style option to it's old format
|
|
121
|
-
*
|
|
122
|
-
* @param {string} optionName Name of the option to map
|
|
123
|
-
* @param {any} optionValue Value of the option to map
|
|
124
|
-
*/
|
|
125
|
-
function mapToOldNames(optionName, optionValue) {
|
|
126
|
-
// Keep all input options and add the "compatibility" options
|
|
127
|
-
switch (optionName) {
|
|
128
|
-
case 'beta':
|
|
129
|
-
options.betaMode = optionValue;
|
|
130
|
-
break;
|
|
131
|
-
case 'odataVersion':
|
|
132
|
-
options.version = optionValue;
|
|
133
|
-
break;
|
|
134
|
-
case 'sqlDialect':
|
|
135
|
-
options.dialect = optionValue;
|
|
136
|
-
break;
|
|
137
|
-
case 'sqlMapping':
|
|
138
|
-
options.names = optionValue;
|
|
139
|
-
break;
|
|
140
|
-
// No need to remap variableReplacements here - we use the new mechanism with that directly
|
|
141
|
-
case 'magicVars':
|
|
142
|
-
if (optionValue.user)
|
|
143
|
-
options.user = optionValue.user;
|
|
144
|
-
if (optionValue.locale)
|
|
145
|
-
options.locale = optionValue.locale;
|
|
146
|
-
break;
|
|
147
|
-
default: break;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
114
|
return options;
|
|
152
115
|
}
|
|
153
116
|
|
|
@@ -155,78 +118,45 @@ module.exports = {
|
|
|
155
118
|
to: {
|
|
156
119
|
cdl: options => translateOptions(options, undefined, undefined, undefined, undefined, 'to.cdl'),
|
|
157
120
|
sql: (options) => {
|
|
158
|
-
const hardOptions = { src: 'sql' };
|
|
121
|
+
const hardOptions = { src: 'sql', toSql: true, forHana: true };
|
|
159
122
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'plain' };
|
|
160
123
|
const processed = translateOptions(options, defaultOptions, hardOptions, undefined, [ 'sql-dialect-and-naming' ], 'to.sql');
|
|
161
124
|
|
|
162
|
-
|
|
163
|
-
result.toSql = Object.assign({}, processed);
|
|
164
|
-
|
|
165
|
-
return result;
|
|
125
|
+
return Object.assign({}, processed);
|
|
166
126
|
},
|
|
167
127
|
hdi: (options) => {
|
|
168
|
-
const hardOptions = { src: 'hdi' };
|
|
128
|
+
const hardOptions = { src: 'hdi', toSql: true, forHana: true };
|
|
169
129
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
const result = Object.assign({}, processed);
|
|
173
|
-
result.toSql = Object.assign({}, processed);
|
|
174
|
-
|
|
175
|
-
return result;
|
|
130
|
+
return translateOptions(options, defaultOptions, hardOptions, { sqlDialect: generateStringValidator([ 'hana' ]) }, undefined, 'to.hdi');
|
|
176
131
|
},
|
|
177
132
|
hdbcds: (options) => {
|
|
133
|
+
const hardOptions = { forHana: true };
|
|
178
134
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
const result = Object.assign({}, processed);
|
|
182
|
-
result.forHana = Object.assign({}, processed);
|
|
183
|
-
|
|
184
|
-
return result;
|
|
135
|
+
return translateOptions(options, defaultOptions, hardOptions, { sqlDialect: generateStringValidator([ 'hana' ]) }, undefined, 'to.hdbcds');
|
|
185
136
|
},
|
|
186
137
|
edm: (options) => {
|
|
187
|
-
const hardOptions = { json: true, combined: true };
|
|
138
|
+
const hardOptions = { json: true, combined: true, toOdata: true };
|
|
188
139
|
const defaultOptions = { odataVersion: 'v4', odataFormat: 'flat' };
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
const result = Object.assign({}, processed);
|
|
192
|
-
result.toOdata = Object.assign({}, processed);
|
|
193
|
-
|
|
194
|
-
return result;
|
|
140
|
+
return translateOptions(options, defaultOptions, hardOptions, { odataVersion: generateStringValidator([ 'v4' ]) }, [ 'valid-structured' ], 'to.edm');
|
|
195
141
|
},
|
|
196
142
|
edmx: (options) => {
|
|
197
|
-
const hardOptions = { xml: true, combined: true };
|
|
143
|
+
const hardOptions = { xml: true, combined: true, toOdata: true };
|
|
198
144
|
const defaultOptions = {
|
|
199
145
|
odataVersion: 'v4', odataFormat: 'flat',
|
|
200
146
|
};
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
const result = Object.assign({}, processed);
|
|
204
|
-
result.toOdata = Object.assign({}, processed);
|
|
205
|
-
|
|
206
|
-
return result;
|
|
147
|
+
return translateOptions(options, defaultOptions, hardOptions, undefined, [ 'valid-structured' ], 'to.edmx');
|
|
207
148
|
},
|
|
208
149
|
},
|
|
209
150
|
for: { // TODO: Rename version to oDataVersion
|
|
210
|
-
|
|
211
151
|
odata: (options) => {
|
|
152
|
+
const hardOptions = { toOdata: true };
|
|
212
153
|
const defaultOptions = { odataVersion: 'v4', odataFormat: 'flat' };
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
const result = Object.assign({}, processed);
|
|
216
|
-
result.toOdata = Object.assign({}, processed);
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
return result;
|
|
154
|
+
return translateOptions(options, defaultOptions, hardOptions, undefined, [ 'valid-structured' ], 'for.odata');
|
|
220
155
|
},
|
|
221
156
|
hana: (options) => {
|
|
157
|
+
const hardOptions = { forHana: true };
|
|
222
158
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const result = Object.assign({}, processed);
|
|
226
|
-
result.forHana = Object.assign({}, processed);
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
return result;
|
|
159
|
+
return translateOptions(options, defaultOptions, hardOptions, undefined, undefined, 'for.hana');
|
|
230
160
|
},
|
|
231
161
|
},
|
|
232
162
|
};
|
package/lib/api/validate.js
CHANGED
|
@@ -65,13 +65,6 @@ const validators = {
|
|
|
65
65
|
return val === null ? val : `type ${ typeof val }`;
|
|
66
66
|
},
|
|
67
67
|
},
|
|
68
|
-
magicVars: {
|
|
69
|
-
validate: val => val !== null && typeof val === 'object' && !Array.isArray(val),
|
|
70
|
-
expected: () => 'type object',
|
|
71
|
-
found: (val) => {
|
|
72
|
-
return val === null ? val : `type ${ typeof val }`;
|
|
73
|
-
},
|
|
74
|
-
},
|
|
75
68
|
// TODO: Maybe do a deep validation of the whole object with leafs?
|
|
76
69
|
variableReplacements: {
|
|
77
70
|
validate: val => val !== null && typeof val === 'object' && !Array.isArray(val),
|
|
@@ -85,7 +78,7 @@ const validators = {
|
|
|
85
78
|
expected: () => 'type array',
|
|
86
79
|
found: val => `type ${ typeof val }`,
|
|
87
80
|
},
|
|
88
|
-
sqlDialect: generateStringValidator([ 'sqlite', 'hana', 'plain' ]),
|
|
81
|
+
sqlDialect: generateStringValidator([ 'sqlite', 'hana', 'plain', 'postgres' ]),
|
|
89
82
|
sqlMapping: generateStringValidator([ 'plain', 'quoted', 'hdbcds' ]),
|
|
90
83
|
odataVersion: generateStringValidator([ 'v2', 'v4' ]),
|
|
91
84
|
odataFormat: generateStringValidator([ 'flat', 'structured' ]),
|
|
@@ -131,16 +124,19 @@ const allCombinationValidators = {
|
|
|
131
124
|
'valid-structured': {
|
|
132
125
|
validate: options => options.odataVersion === 'v2' && options.odataFormat === 'structured',
|
|
133
126
|
severity: 'error',
|
|
127
|
+
getParameters: () => {},
|
|
134
128
|
getMessage: () => 'Structured OData is only supported with OData version v4',
|
|
135
129
|
},
|
|
136
130
|
'sql-dialect-and-naming': {
|
|
137
131
|
validate: options => options.sqlDialect && options.sqlMapping && ![ 'hana' ].includes(options.sqlDialect) && [ 'quoted', 'hdbcds' ].includes(options.sqlMapping),
|
|
138
132
|
severity: 'error',
|
|
139
|
-
|
|
133
|
+
getParameters: options => ({ name: options.sqlDialect, prop: options.sqlMapping }),
|
|
134
|
+
getMessage: () => 'sqlDialect $(NAME) can\'t be combined with sqlMapping $(PROP)',
|
|
140
135
|
},
|
|
141
136
|
'beta-no-test': {
|
|
142
137
|
validate: options => options.beta && !options.testMode,
|
|
143
138
|
severity: 'warning',
|
|
139
|
+
getParameters: () => {},
|
|
144
140
|
getMessage: () => 'Option "beta" was used. This option should not be used in productive scenarios!',
|
|
145
141
|
},
|
|
146
142
|
};
|
|
@@ -176,7 +172,7 @@ function validate(options, moduleName, customValidators = {}, combinationValidat
|
|
|
176
172
|
for (const combinationValidatorName of combinationValidators.concat([ 'beta-no-test' ])) {
|
|
177
173
|
const combinationValidator = allCombinationValidators[combinationValidatorName];
|
|
178
174
|
if (combinationValidator.validate(options))
|
|
179
|
-
message[combinationValidator.severity]('invalid-option-combination', null,
|
|
175
|
+
message[combinationValidator.severity]('invalid-option-combination', null, combinationValidator.getParameters(options), combinationValidator.getMessage(options));
|
|
180
176
|
}
|
|
181
177
|
|
|
182
178
|
message.throwWithAnyError();
|