@sap/cds-compiler 4.4.4 → 4.6.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 +88 -0
- package/bin/cdsc.js +18 -11
- package/bin/cdsv2m.js +7 -5
- package/doc/CHANGELOG_BETA.md +22 -0
- package/lib/api/main.js +306 -144
- package/lib/api/options.js +18 -6
- package/lib/api/validate.js +1 -1
- package/lib/base/message-registry.js +45 -10
- package/lib/base/messages.js +33 -16
- package/lib/base/model.js +4 -0
- package/lib/base/optionProcessorHelper.js +45 -176
- package/lib/checks/annotationsOData.js +49 -0
- package/lib/checks/elements.js +32 -34
- package/lib/checks/enricher.js +39 -3
- package/lib/checks/validator.js +8 -7
- package/lib/compiler/assert-consistency.js +40 -17
- package/lib/compiler/builtins.js +30 -53
- package/lib/compiler/checks.js +46 -14
- package/lib/compiler/cycle-detector.js +1 -4
- package/lib/compiler/define.js +35 -10
- package/lib/compiler/extend.js +21 -7
- package/lib/compiler/generate.js +3 -0
- package/lib/compiler/populate.js +5 -1
- package/lib/compiler/propagator.js +46 -9
- package/lib/compiler/resolve.js +94 -35
- package/lib/compiler/shared.js +60 -33
- package/lib/compiler/tweak-assocs.js +188 -92
- package/lib/compiler/utils.js +11 -1
- package/lib/edm/annotations/edmJson.js +41 -66
- package/lib/edm/annotations/genericTranslation.js +27 -9
- package/lib/edm/annotations/preprocessAnnotations.js +2 -3
- package/lib/edm/csn2edm.js +28 -11
- package/lib/edm/edmInboundChecks.js +58 -15
- package/lib/edm/edmPreprocessor.js +12 -16
- package/lib/edm/edmUtils.js +5 -2
- package/lib/gen/Dictionary.json +10 -0
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +15 -2
- package/lib/gen/language.tokens +1 -0
- package/lib/gen/languageParser.js +6557 -5618
- package/lib/json/from-csn.js +4 -5
- package/lib/json/to-csn.js +29 -4
- package/lib/language/antlrParser.js +19 -1
- package/lib/language/errorStrategy.js +28 -7
- package/lib/language/genericAntlrParser.js +118 -24
- package/lib/language/textUtils.js +16 -0
- package/lib/main.d.ts +28 -3
- package/lib/main.js +3 -0
- package/lib/model/csnRefs.js +4 -1
- package/lib/model/csnUtils.js +20 -14
- package/lib/model/revealInternalProperties.js +5 -2
- package/lib/optionProcessor.js +23 -22
- package/lib/render/manageConstraints.js +13 -29
- package/lib/render/toCdl.js +47 -26
- package/lib/render/toHdbcds.js +63 -42
- package/lib/render/toRename.js +6 -10
- package/lib/render/toSql.js +71 -117
- package/lib/render/utils/common.js +41 -6
- package/lib/transform/.eslintrc.json +9 -1
- package/lib/transform/addTenantFields.js +228 -0
- package/lib/transform/db/applyTransformations.js +57 -4
- package/lib/transform/db/assertUnique.js +4 -4
- package/lib/transform/db/backlinks.js +13 -1
- package/lib/transform/db/cdsPersistence.js +1 -1
- package/lib/transform/db/expansion.js +24 -3
- package/lib/transform/db/flattening.js +70 -71
- package/lib/transform/db/killAnnotations.js +37 -0
- package/lib/transform/db/rewriteCalculatedElements.js +46 -6
- package/lib/transform/db/temporal.js +1 -1
- package/lib/transform/draft/db.js +2 -16
- package/lib/transform/draft/odata.js +3 -3
- package/lib/transform/effective/associations.js +3 -5
- package/lib/transform/effective/main.js +6 -9
- package/lib/transform/forOdata.js +26 -55
- package/lib/transform/forRelationalDB.js +38 -18
- package/lib/transform/odata/toFinalBaseType.js +3 -3
- package/lib/transform/odata/typesExposure.js +14 -5
- package/lib/transform/transformUtils.js +47 -34
- package/lib/transform/translateAssocsToJoins.js +45 -11
- package/lib/transform/universalCsn/coreComputed.js +1 -1
- package/lib/transform/universalCsn/universalCsnEnricher.js +4 -4
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,79 @@
|
|
|
7
7
|
Note: `beta` fixes, changes and features are usually not listed in this ChangeLog but [here](doc/CHANGELOG_BETA.md).
|
|
8
8
|
The compiler behavior concerning `beta` features can change at any time without notice.
|
|
9
9
|
|
|
10
|
+
|
|
11
|
+
## Version 4.6.0 - 2024-01-26
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
|
|
15
|
+
- compiler: Events can now be projections on other structured events and types.
|
|
16
|
+
- to.cdl: `parseCdl` and `gensrc` style CSN (a.k.a. `inferred` and `xtended`) is now supported as input.
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Update OData vocabularies: 'Aggregation', 'Validation'
|
|
21
|
+
- to.sql/hdi/hdbcds: Removed warnings for number and type of keys in draft-enabled entities.
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
|
|
25
|
+
- compiler:
|
|
26
|
+
+ ON-conditions of associations with filters in calculated elements were incorrectly rewritten when included
|
|
27
|
+
in other entities, and the filter was applied twice in some scenarios.
|
|
28
|
+
+ redirecting an association with filter did not rewrite paths relative to the redirection target.
|
|
29
|
+
+ Unknown type references with an explicit named type argument such as `Unknown(length: 10)` crashed.
|
|
30
|
+
- to.edm(x):
|
|
31
|
+
+ `@Core.IsURL` is not rendered in combination with `@Core.MediaType` (V4 only).
|
|
32
|
+
+ No 'odata-navigation' warning for association targets annotated with `@cds.autoexpose: false`.
|
|
33
|
+
+ No empty annotation in API, when a non-existent base annotation is annotated
|
|
34
|
+
(eg. `@Common.Label.@Core.Description` without `@Common.Label`).
|
|
35
|
+
+ Don't crash if value for `$Type` is not a string.
|
|
36
|
+
+ Generated foreign keys of type `cds.UUID` that are also primary key are not annotated with
|
|
37
|
+
`@Core.ComputedDefaultValue`. This is a follow up correction to [4.5.0](#version-450---2023-12-08)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Version 4.5.0 - 2023-12-08
|
|
41
|
+
|
|
42
|
+
### Added
|
|
43
|
+
|
|
44
|
+
- compiler/parser
|
|
45
|
+
+ Annotations can have any expressions as value, like `@Anno: ( ref + 1 )`.
|
|
46
|
+
References are checked to be valid element references,
|
|
47
|
+
inherited values might become invalid due to element renaming.
|
|
48
|
+
This feature is still experimental, and
|
|
49
|
+
might not be supported by all backends or runtimes at the moment.
|
|
50
|
+
+ A single `annotate` statement can now be used to annotate parameters, elements and
|
|
51
|
+
bound actions in one statement.
|
|
52
|
+
- to.edm(x): Key elements of type `cds.UUID` are annotated with `@Core.ComputedDefaultValue` if they are
|
|
53
|
+
defined directly in the entity. Elements of type `cds.UUID` that are defined in a named structured type
|
|
54
|
+
and used to define a key element are not annotated, instead a warning is raised if such elements are
|
|
55
|
+
not annotated with `@Core.ComputedDefaultValue`.
|
|
56
|
+
- to.sql|hdi: Add option `withHanaAssociations` which, for sqlDialect `hana`, allows suppressing
|
|
57
|
+
the generation of the `WITH ASSOCIATIONS`.
|
|
58
|
+
|
|
59
|
+
### Changed
|
|
60
|
+
|
|
61
|
+
- Update OData Vocabulary: 'Common'.
|
|
62
|
+
- api: Reject CSN as input in backends, if it is a CSN in flavor `parsed` with a non-empty `requires` array.
|
|
63
|
+
Reason being that the model is not considered a "full" CSN, as dependencies were not resolved.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- compiler:
|
|
68
|
+
+ Fix false positives of cyclic dependencies for calculated elements.
|
|
69
|
+
+ Fix cardinality on source associations when publishing them with a filter (+ different cardinality)
|
|
70
|
+
in a projection. The cardinality was incorrectly changed on the source as well.
|
|
71
|
+
- CDL parser:
|
|
72
|
+
+ More numbers that would lose relevant digits due to precision loss are
|
|
73
|
+
stored as strings in CSN (i.e. `{ "literal":"number", "val": "1.0000000000000001" }`).
|
|
74
|
+
+ Nested table expressions and queries in the FROM clause (with surrounding parentheses)
|
|
75
|
+
could cause some constructs such as `virtual` to be not properly parsed.
|
|
76
|
+
- to.hdi.migration: Don't drop-create the primary key when only a doc-comment has changed.
|
|
77
|
+
- to.cdl: Fix edge case where `@A.![B#]` was not rendered correctly.
|
|
78
|
+
|
|
79
|
+
### Removed
|
|
80
|
+
|
|
81
|
+
- to.edm(x): Remove option `--odata-open-type` introduced with [4.4.0](#version-440---2023-11-09).
|
|
82
|
+
|
|
10
83
|
## Version 4.4.4 - 2023-11-24
|
|
11
84
|
|
|
12
85
|
### Fixed
|
|
@@ -311,6 +384,7 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
311
384
|
we avoid unexpected name resolution effects in combination with built-in `$`-variables.
|
|
312
385
|
+ A semicolon is now required after a type definition like `type T : many {} null`.
|
|
313
386
|
+ Message ID `duplicate-autoexposed` was changed to `def-duplicate-autoexposed`.
|
|
387
|
+
+ Bare `$projection` are rejected. Use `$self` instead.
|
|
314
388
|
- Update OData vocabularies 'Common', 'UI'.
|
|
315
389
|
- to.sql:
|
|
316
390
|
+ Change default `length` for `cds.String` for all SQL dialects except `hana` to 255.
|
|
@@ -361,6 +435,20 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
361
435
|
are removed, because since - `Entity.myElement` could also be a definition,
|
|
362
436
|
creating ambiguities. This did not work always, anyway.
|
|
363
437
|
|
|
438
|
+
## Version 3.9.12 - 2023-12-06
|
|
439
|
+
|
|
440
|
+
### Fixed
|
|
441
|
+
|
|
442
|
+
- compiler:
|
|
443
|
+
+ SQL function `STDDEV(*)` was not parsable.
|
|
444
|
+
+ Numbers in scientific notation `-1e1` were sometimes not recognized via CSN input.
|
|
445
|
+
- for.odata: Fix crash when using a projection with associations as action parameter type.
|
|
446
|
+
- for.hana: Fix a bug in association to join translation, expect ON condition operand to be a function without arguments.
|
|
447
|
+
- to.edm(x):
|
|
448
|
+
+ Omit `EntitySet` attribute on `Edm.FunctionImport` and `Edm.ActionImport` that return a singleton.
|
|
449
|
+
+ Don't render `Scale: variable` for `cds.Decimal(scale:0)`.
|
|
450
|
+
- to.sql/hdi/hdbcds: consider `having` predicate for `exists` expansion
|
|
451
|
+
|
|
364
452
|
## Version 3.9.10 - 2023-08-25
|
|
365
453
|
|
|
366
454
|
### Fixed
|
package/bin/cdsc.js
CHANGED
|
@@ -27,10 +27,12 @@ const { reveal } = require('../lib/model/revealInternalProperties');
|
|
|
27
27
|
const enrichCsn = require('../lib/model/enrichCsn');
|
|
28
28
|
const { optionProcessor } = require('../lib/optionProcessor');
|
|
29
29
|
const {
|
|
30
|
-
explainMessage, hasMessageExplanation, sortMessages,
|
|
30
|
+
explainMessage, hasMessageExplanation, sortMessages,
|
|
31
|
+
messageIdsWithExplanation, makeMessageFunction,
|
|
31
32
|
} = require('../lib/base/messages');
|
|
32
33
|
const { term } = require('../lib/utils/term');
|
|
33
34
|
const { addLocalizationViews } = require('../lib/transform/localized');
|
|
35
|
+
const { addTenantFields } = require('../lib/transform/addTenantFields');
|
|
34
36
|
const { availableBetaFlags } = require('../lib/base/model');
|
|
35
37
|
const { alterConstraintsWithCsn } = require('../lib/render/manageConstraints');
|
|
36
38
|
|
|
@@ -63,17 +65,13 @@ function remapCmdOptions( options, command ) {
|
|
|
63
65
|
for (const [ key, value ] of Object.entries(options[command])) {
|
|
64
66
|
switch (key) {
|
|
65
67
|
case 'user':
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (!options.variableReplacements.$user)
|
|
69
|
-
options.variableReplacements.$user = {};
|
|
68
|
+
options.variableReplacements ??= {};
|
|
69
|
+
options.variableReplacements.$user ??= {};
|
|
70
70
|
options.variableReplacements.$user.id = value;
|
|
71
71
|
break;
|
|
72
72
|
case 'locale':
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
if (!options.variableReplacements.$user)
|
|
76
|
-
options.variableReplacements.$user = {};
|
|
73
|
+
options.variableReplacements ??= {};
|
|
74
|
+
options.variableReplacements.$user ??= {};
|
|
77
75
|
options.variableReplacements.$user.locale = value;
|
|
78
76
|
break;
|
|
79
77
|
case 'serviceNames':
|
|
@@ -391,7 +389,8 @@ function executeCommandLine( command, options, args ) {
|
|
|
391
389
|
// / DO NOT DELETE THIS TORENAME FUNCTIONALITY!!
|
|
392
390
|
function toRename( model ) {
|
|
393
391
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
394
|
-
const
|
|
392
|
+
const messageFunctions = makeMessageFunction(csn, options, 'to.rename');
|
|
393
|
+
const renameResult = _toRename(csn, options, messageFunctions);
|
|
395
394
|
let storedProcedure = `PROCEDURE RENAME_${renameResult.options.sqlMapping.toUpperCase()}_TO_PLAIN LANGUAGE SQLSCRIPT AS BEGIN\n`;
|
|
396
395
|
for (const name in renameResult.rename) {
|
|
397
396
|
storedProcedure += ` --\n -- ${name}\n --\n`;
|
|
@@ -406,7 +405,8 @@ function executeCommandLine( command, options, args ) {
|
|
|
406
405
|
function manageConstraints( model ) {
|
|
407
406
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
408
407
|
const { src } = options || {};
|
|
409
|
-
const
|
|
408
|
+
const messageFunctions = makeMessageFunction(csn, options, 'alterConstraints');
|
|
409
|
+
const alterConstraintsResult = alterConstraintsWithCsn(csn, options, messageFunctions);
|
|
410
410
|
Object.keys(alterConstraintsResult).forEach((id) => {
|
|
411
411
|
const renderedConstraintStatement = alterConstraintsResult[id];
|
|
412
412
|
if (src === 'hdi')
|
|
@@ -419,6 +419,11 @@ function executeCommandLine( command, options, args ) {
|
|
|
419
419
|
// Execute the command line option '--to-sql' and display the results.
|
|
420
420
|
// Return the original model (for chaining)
|
|
421
421
|
function toSql( model ) {
|
|
422
|
+
if (options.withoutHanaAssociations) {
|
|
423
|
+
options.withHanaAssociations = false;
|
|
424
|
+
delete options.withoutHanaAssociations;
|
|
425
|
+
}
|
|
426
|
+
|
|
422
427
|
const csn = options.directBackend ? model : compactModel(model, options);
|
|
423
428
|
if (options.src === 'hdi') {
|
|
424
429
|
if (options.csn) {
|
|
@@ -554,6 +559,8 @@ function executeCommandLine( command, options, args ) {
|
|
|
554
559
|
}
|
|
555
560
|
else if (!options.parseOnly) { // no output if parseOnly but not rawOutput
|
|
556
561
|
const csn = compactModel(xsn, options);
|
|
562
|
+
if (command === 'toCsn' && options.tenantAsColumn)
|
|
563
|
+
addTenantFields(csn, options);
|
|
557
564
|
if (command === 'toCsn' && options.withLocalized)
|
|
558
565
|
addLocalizationViews(csn, options);
|
|
559
566
|
if (options.enrichCsn)
|
package/bin/cdsv2m.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
// Very simple command-line interface to support model migration
|
|
6
|
-
// v1 to v2.
|
|
7
|
-
// as after #2629, we could have a cdsc commend "migrate...)
|
|
5
|
+
// Very simple command-line interface to support model migration
|
|
6
|
+
// from compiler v1 to v2.
|
|
8
7
|
|
|
9
8
|
const commands = {
|
|
10
9
|
ria,
|
|
11
10
|
};
|
|
12
11
|
const compiler = require('../lib/compiler');
|
|
12
|
+
const { smartId } = require('../lib/render/toCdl');
|
|
13
13
|
|
|
14
14
|
const { argv } = process;
|
|
15
15
|
const cmd = commands[argv[2]];
|
|
@@ -42,6 +42,8 @@ function ria() {
|
|
|
42
42
|
annotates[name.slice( 1, -1 )] = true;
|
|
43
43
|
} );
|
|
44
44
|
}
|
|
45
|
-
for (const name in annotates)
|
|
46
|
-
|
|
45
|
+
for (const name in annotates) {
|
|
46
|
+
const escaped = name.split('.').map(part => smartId(part)).join('.');
|
|
47
|
+
console.log(`annotate ${escaped} with @cds.redirection.target: false;`);
|
|
48
|
+
}
|
|
47
49
|
}
|
package/doc/CHANGELOG_BETA.md
CHANGED
|
@@ -8,6 +8,28 @@ Note: `beta` fixes, changes and features are listed in this ChangeLog just for i
|
|
|
8
8
|
The compiler behavior concerning `beta` features can change at any time without notice.
|
|
9
9
|
**Don't use `beta` fixes, changes and features in productive mode.**
|
|
10
10
|
|
|
11
|
+
## Version 4.6.0 - 2024-01-26
|
|
12
|
+
|
|
13
|
+
### Added `vectorType`
|
|
14
|
+
|
|
15
|
+
Using this beta flag, the new type `cds.Vector` is available for modeling.
|
|
16
|
+
|
|
17
|
+
## Version 4.5.0 - 2023-12-08
|
|
18
|
+
|
|
19
|
+
### Added `odataAnnotationExpressions`
|
|
20
|
+
|
|
21
|
+
This flag allows to use expressions as annotation values, e.g.
|
|
22
|
+
`@anno: (1+2)` and to enable OData specific transformations on those expressions.
|
|
23
|
+
|
|
24
|
+
### Added `tenantVariable`
|
|
25
|
+
|
|
26
|
+
If this beta flag is enabled, variable `$tenant` can be used without explicit replacement value.
|
|
27
|
+
|
|
28
|
+
### Added feature "associations as direct calculated element values"
|
|
29
|
+
|
|
30
|
+
This beta feature does not require a flag. It is now possible to use associations with
|
|
31
|
+
filters as direct values of calculated elements (on-read), e.g. `calc = assoc[ID = 1]`.
|
|
32
|
+
|
|
11
33
|
## Version 4.3.0 - 2023-09-29
|
|
12
34
|
|
|
13
35
|
### Removed `associationDefault`
|