@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/bin/cdsc.js
CHANGED
|
@@ -19,7 +19,7 @@ const compiler = require('../lib/compiler');
|
|
|
19
19
|
const main = require('../lib/main');
|
|
20
20
|
const { for_sql, for_hdi, for_hdbcds } = require('../lib/api/main');
|
|
21
21
|
const { compactModel } = require('../lib/json/to-csn');
|
|
22
|
-
const {
|
|
22
|
+
const { toRename: _toRename } = require('../lib/render/toRename');
|
|
23
23
|
const util = require('util');
|
|
24
24
|
const fs = require('fs');
|
|
25
25
|
const path = require('path');
|
|
@@ -33,6 +33,7 @@ const { term } = require('../lib/utils/term');
|
|
|
33
33
|
const { splitLines } = require('../lib/utils/file');
|
|
34
34
|
const { addLocalizationViews } = require('../lib/transform/localized');
|
|
35
35
|
const { availableBetaFlags } = require('../lib/base/model');
|
|
36
|
+
const { alterConstraintsWithCsn } = require('../lib/render/manageConstraints');
|
|
36
37
|
|
|
37
38
|
// Note: Instead of throwing ProcessExitError, we would rather just call process.exit(exitCode),
|
|
38
39
|
// but that might truncate the output of stdout and stderr, both of which are async (or rather,
|
|
@@ -56,11 +57,11 @@ catch (err) {
|
|
|
56
57
|
throw err;
|
|
57
58
|
}
|
|
58
59
|
|
|
59
|
-
function remapCmdOptions(options,
|
|
60
|
-
if (!
|
|
61
|
-
return
|
|
60
|
+
function remapCmdOptions(options, command) {
|
|
61
|
+
if (!command || !options[command])
|
|
62
|
+
return;
|
|
62
63
|
|
|
63
|
-
for (const [ key, value ] of Object.entries(
|
|
64
|
+
for (const [ key, value ] of Object.entries(options[command])) {
|
|
64
65
|
switch (key) {
|
|
65
66
|
case 'names':
|
|
66
67
|
options.sqlMapping = value;
|
|
@@ -88,11 +89,14 @@ function remapCmdOptions(options, cmdOptions) {
|
|
|
88
89
|
case 'serviceNames':
|
|
89
90
|
options.serviceNames = value.split(',');
|
|
90
91
|
break;
|
|
92
|
+
case 'flavor':
|
|
93
|
+
options.csnFlavor = value;
|
|
94
|
+
break;
|
|
91
95
|
default:
|
|
92
96
|
options[key] = value;
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
|
-
|
|
99
|
+
delete options[command];
|
|
96
100
|
}
|
|
97
101
|
|
|
98
102
|
function cdsc_main() {
|
|
@@ -273,6 +277,7 @@ function executeCommandLine(command, options, args) {
|
|
|
273
277
|
if (!commands[command] && !commandsWithoutCompilation[command])
|
|
274
278
|
throw new Error(`Missing implementation for command ${command}`);
|
|
275
279
|
|
|
280
|
+
remapCmdOptions( options, command );
|
|
276
281
|
|
|
277
282
|
if (commandsWithoutCompilation[command]) {
|
|
278
283
|
commandsWithoutCompilation[command]();
|
|
@@ -296,7 +301,7 @@ function executeCommandLine(command, options, args) {
|
|
|
296
301
|
// Return the original model (for chaining)
|
|
297
302
|
function toCdl( model ) {
|
|
298
303
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
299
|
-
const cdlResult = main.to.cdl(csn,
|
|
304
|
+
const cdlResult = main.to.cdl(csn, options);
|
|
300
305
|
for (const name in cdlResult)
|
|
301
306
|
writeToFileOrDisplay(options.out, `${name}.cds`, cdlResult[name]);
|
|
302
307
|
|
|
@@ -321,11 +326,11 @@ function executeCommandLine(command, options, args) {
|
|
|
321
326
|
function toHana( model ) {
|
|
322
327
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
323
328
|
|
|
324
|
-
if (options.
|
|
325
|
-
displayNamedCsn(for_hdbcds(csn,
|
|
329
|
+
if (options.csn) {
|
|
330
|
+
displayNamedCsn(for_hdbcds(csn, options), 'hana_csn');
|
|
326
331
|
}
|
|
327
332
|
else {
|
|
328
|
-
const hanaResult = main.to.hdbcds(csn,
|
|
333
|
+
const hanaResult = main.to.hdbcds(csn, options);
|
|
329
334
|
for (const name in hanaResult)
|
|
330
335
|
writeToFileOrDisplay(options.out, name, hanaResult[name]);
|
|
331
336
|
}
|
|
@@ -336,25 +341,23 @@ function executeCommandLine(command, options, args) {
|
|
|
336
341
|
// Execute the command line option '--to-odata' and display the results.
|
|
337
342
|
// Return the original model (for chaining)
|
|
338
343
|
function toOdata( model ) {
|
|
339
|
-
if (options.
|
|
340
|
-
options.
|
|
341
|
-
options.
|
|
342
|
-
options.
|
|
343
|
-
options.toOdata.odataContainment = true;
|
|
344
|
+
if (options.odataVersion === 'v4x') {
|
|
345
|
+
options.odataVersion = 'v4';
|
|
346
|
+
options.odataFormat = 'structured';
|
|
347
|
+
options.odataContainment = true;
|
|
344
348
|
}
|
|
345
349
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
const odataCsn = main.for.odata(csn, odataOptions);
|
|
350
|
+
if (options.csn) {
|
|
351
|
+
const odataCsn = main.for.odata(csn, options);
|
|
349
352
|
displayNamedCsn(odataCsn, 'odata_csn');
|
|
350
353
|
}
|
|
351
|
-
else if (options.
|
|
352
|
-
const result = main.to.edm.all(csn,
|
|
354
|
+
else if (options.json) {
|
|
355
|
+
const result = main.to.edm.all(csn, options);
|
|
353
356
|
for (const serviceName in result)
|
|
354
357
|
writeToFileOrDisplay(options.out, `${serviceName}.json`, result[serviceName]);
|
|
355
358
|
}
|
|
356
359
|
else {
|
|
357
|
-
const result = main.to.edmx.all(csn,
|
|
360
|
+
const result = main.to.edmx.all(csn, options);
|
|
358
361
|
for (const serviceName in result)
|
|
359
362
|
writeToFileOrDisplay(options.out, `${serviceName}.xml`, result[serviceName]);
|
|
360
363
|
}
|
|
@@ -368,14 +371,14 @@ function executeCommandLine(command, options, args) {
|
|
|
368
371
|
// / DO NOT DELETE THIS TORENAME FUNCTIONALITY!!
|
|
369
372
|
function toRename( model ) {
|
|
370
373
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
371
|
-
const renameResult =
|
|
372
|
-
let storedProcedure = `PROCEDURE RENAME_${renameResult.options.
|
|
374
|
+
const renameResult = _toRename(csn, options);
|
|
375
|
+
let storedProcedure = `PROCEDURE RENAME_${renameResult.options.sqlMapping.toUpperCase()}_TO_PLAIN LANGUAGE SQLSCRIPT AS BEGIN\n`;
|
|
373
376
|
for (const name in renameResult.rename) {
|
|
374
377
|
storedProcedure += ` --\n -- ${name}\n --\n`;
|
|
375
378
|
storedProcedure += renameResult.rename[name];
|
|
376
379
|
}
|
|
377
380
|
storedProcedure += 'END;\n';
|
|
378
|
-
writeToFileOrDisplay(options.out, `storedProcedure_${renameResult.options.
|
|
381
|
+
writeToFileOrDisplay(options.out, `storedProcedure_${renameResult.options.sqlMapping}_to_plain.sql`, storedProcedure, true);
|
|
379
382
|
return model;
|
|
380
383
|
}
|
|
381
384
|
|
|
@@ -397,21 +400,21 @@ function executeCommandLine(command, options, args) {
|
|
|
397
400
|
// Return the original model (for chaining)
|
|
398
401
|
function toSql( model ) {
|
|
399
402
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
400
|
-
if (options.
|
|
401
|
-
if (options.
|
|
402
|
-
displayNamedCsn(for_hdi(csn,
|
|
403
|
+
if (options.src === 'hdi') {
|
|
404
|
+
if (options.csn) {
|
|
405
|
+
displayNamedCsn(for_hdi(csn, options), 'hdi_csn');
|
|
403
406
|
}
|
|
404
407
|
else {
|
|
405
|
-
const hdiResult = main.to.hdi(csn,
|
|
408
|
+
const hdiResult = main.to.hdi(csn, options);
|
|
406
409
|
for (const name in hdiResult)
|
|
407
410
|
writeToFileOrDisplay(options.out, name, hdiResult[name]);
|
|
408
411
|
}
|
|
409
412
|
}
|
|
410
|
-
else if (options.
|
|
411
|
-
displayNamedCsn(for_sql(csn,
|
|
413
|
+
else if (options.csn) {
|
|
414
|
+
displayNamedCsn(for_sql(csn, options), 'sql_csn');
|
|
412
415
|
}
|
|
413
416
|
else {
|
|
414
|
-
const sqlResult = main.to.sql(csn,
|
|
417
|
+
const sqlResult = main.to.sql(csn, options);
|
|
415
418
|
writeToFileOrDisplay(options.out, 'model.sql', sqlResult.join('\n'), true);
|
|
416
419
|
}
|
|
417
420
|
return model;
|
|
@@ -524,7 +527,7 @@ function executeCommandLine(command, options, args) {
|
|
|
524
527
|
}
|
|
525
528
|
else if (!options.lintMode) {
|
|
526
529
|
const csn = compactModel(xsn, options);
|
|
527
|
-
if (command === 'toCsn' && options.
|
|
530
|
+
if (command === 'toCsn' && options.withLocalized)
|
|
528
531
|
addLocalizationViews(csn, options);
|
|
529
532
|
if (options.enrichCsn)
|
|
530
533
|
enrichCsn( csn, options );
|
|
@@ -543,7 +546,7 @@ function executeCommandLine(command, options, args) {
|
|
|
543
546
|
writeToFileOrDisplay(options.out, `${name}_raw.txt`, options.messages, true);
|
|
544
547
|
}
|
|
545
548
|
else if (!options.lintMode && !options.internalMsg) {
|
|
546
|
-
if (command === 'toCsn' && options.
|
|
549
|
+
if (command === 'toCsn' && options.withLocalized)
|
|
547
550
|
addLocalizationViews(csn, options);
|
|
548
551
|
writeToFileOrDisplay(options.out, `${name}.json`, csn, true);
|
|
549
552
|
}
|