@sap/cds-compiler 2.12.0 → 2.13.6
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 +110 -15
- package/bin/cdsc.js +13 -13
- package/bin/cdsse.js +2 -2
- package/doc/CHANGELOG_BETA.md +13 -6
- package/doc/CHANGELOG_DEPRECATED.md +22 -6
- package/doc/NameResolution.md +21 -16
- package/lib/api/main.js +28 -63
- package/lib/api/options.js +3 -3
- package/lib/api/validate.js +0 -5
- package/lib/backends.js +15 -23
- package/lib/base/dictionaries.js +0 -8
- package/lib/base/error.js +26 -0
- package/lib/base/keywords.js +7 -17
- package/lib/base/location.js +9 -4
- package/lib/base/message-registry.js +25 -4
- package/lib/base/messages.js +16 -26
- package/lib/base/model.js +2 -63
- package/lib/base/optionProcessorHelper.js +158 -123
- package/lib/checks/annotationsOData.js +1 -1
- package/lib/checks/cdsPersistence.js +2 -1
- package/lib/checks/enricher.js +17 -1
- package/lib/checks/invalidTarget.js +3 -1
- package/lib/checks/managedWithoutKeys.js +3 -1
- package/lib/checks/selectItems.js +4 -4
- package/lib/checks/sql-snippets.js +27 -26
- package/lib/checks/types.js +1 -1
- package/lib/checks/validator.js +4 -7
- package/lib/compiler/assert-consistency.js +5 -3
- package/lib/compiler/builtins.js +8 -6
- package/lib/compiler/checks.js +14 -3
- package/lib/compiler/cycle-detector.js +1 -1
- package/lib/compiler/define.js +1103 -0
- package/lib/compiler/extend.js +983 -0
- package/lib/compiler/finalize-parse-cdl.js +231 -0
- package/lib/compiler/index.js +32 -13
- package/lib/compiler/kick-start.js +190 -0
- package/lib/compiler/moduleLayers.js +4 -4
- package/lib/compiler/populate.js +1226 -0
- package/lib/compiler/propagator.js +111 -46
- package/lib/compiler/resolve.js +1433 -0
- package/lib/compiler/shared.js +64 -37
- package/lib/compiler/tweak-assocs.js +529 -0
- package/lib/compiler/utils.js +197 -33
- package/lib/edm/.eslintrc.json +5 -0
- package/lib/edm/annotations/genericTranslation.js +5 -9
- package/lib/edm/annotations/preprocessAnnotations.js +2 -2
- package/lib/edm/csn2edm.js +9 -8
- package/lib/edm/edm.js +11 -12
- package/lib/edm/edmPreprocessor.js +137 -73
- package/lib/edm/edmUtils.js +116 -22
- package/lib/gen/Dictionary.json +10 -3
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +9 -1
- package/lib/gen/language.tokens +86 -83
- package/lib/gen/languageLexer.interp +10 -1
- package/lib/gen/languageLexer.js +860 -833
- package/lib/gen/languageLexer.tokens +78 -75
- package/lib/gen/languageParser.js +5282 -4265
- package/lib/json/from-csn.js +12 -1
- package/lib/json/to-csn.js +126 -66
- package/lib/language/docCommentParser.js +2 -2
- package/lib/language/genericAntlrParser.js +76 -3
- package/lib/language/language.g4 +297 -130
- package/lib/language/multiLineStringParser.js +5 -5
- package/lib/main.d.ts +468 -59
- package/lib/main.js +35 -9
- package/lib/model/api.js +3 -1
- package/lib/model/csnRefs.js +225 -156
- package/lib/model/csnUtils.js +192 -223
- package/lib/model/enrichCsn.js +70 -29
- package/lib/model/revealInternalProperties.js +27 -6
- package/lib/model/sortViews.js +2 -1
- package/lib/modelCompare/compare.js +17 -12
- package/lib/optionProcessor.js +5 -4
- package/lib/render/manageConstraints.js +35 -32
- package/lib/render/toCdl.js +73 -288
- package/lib/render/toHdbcds.js +25 -23
- package/lib/render/toSql.js +98 -41
- package/lib/render/utils/common.js +5 -10
- package/lib/render/utils/sql.js +4 -3
- package/lib/render/utils/stringEscapes.js +111 -0
- package/lib/sql-identifier.js +1 -1
- package/lib/transform/.eslintrc.json +5 -0
- package/lib/transform/db/.eslintrc.json +2 -0
- package/lib/transform/db/applyTransformations.js +35 -12
- package/lib/transform/db/assertUnique.js +1 -1
- package/lib/transform/db/associations.js +103 -305
- package/lib/transform/db/cdsPersistence.js +2 -2
- package/lib/transform/db/constraints.js +55 -52
- package/lib/transform/db/expansion.js +46 -24
- package/lib/transform/db/flattening.js +553 -102
- package/lib/transform/db/groupByOrderBy.js +3 -1
- package/lib/transform/db/transformExists.js +59 -6
- package/lib/transform/db/views.js +5 -4
- package/lib/transform/draft/.eslintrc.json +38 -0
- package/lib/transform/{db/draft.js → draft/db.js} +6 -5
- package/lib/transform/draft/odata.js +227 -0
- package/lib/transform/forHanaNew.js +67 -183
- package/lib/transform/forOdataNew.js +17 -171
- package/lib/transform/localized.js +34 -19
- package/lib/transform/odata/generateForeignKeyElements.js +1 -1
- package/lib/transform/odata/referenceFlattener.js +95 -89
- package/lib/transform/odata/structureFlattener.js +1 -1
- package/lib/transform/odata/toFinalBaseType.js +86 -12
- package/lib/transform/odata/typesExposure.js +5 -5
- package/lib/transform/odata/utils.js +2 -2
- package/lib/transform/transformUtilsNew.js +36 -22
- package/lib/transform/translateAssocsToJoins.js +2 -19
- package/lib/transform/universalCsn/.eslintrc.json +36 -0
- package/lib/transform/universalCsn/coreComputed.js +170 -0
- package/lib/transform/universalCsn/universalCsnEnricher.js +715 -0
- package/lib/transform/universalCsn/utils.js +63 -0
- package/lib/utils/objectUtils.js +30 -0
- package/package.json +1 -1
- package/share/messages/README.md +26 -0
- package/lib/compiler/definer.js +0 -2361
- package/lib/compiler/resolver.js +0 -3079
- package/lib/transform/universalCsnEnricher.js +0 -237
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,101 @@
|
|
|
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
|
+
## Version 2.13.6 - 2022-25-03
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- to.hdbcds/hdi/sql: Correctly handle `localized` in conjunction with `@cds.persistence.exists`
|
|
15
|
+
|
|
16
|
+
## Version 2.13.4 - 2022-22-03
|
|
17
|
+
|
|
18
|
+
No changes compared to Version 2.13.0; fixes latest NPM tag
|
|
19
|
+
|
|
20
|
+
## Version 2.13.2 - 2022-22-03
|
|
21
|
+
|
|
22
|
+
No changes compared to Version 2.13.0; fixes latest NPM tag
|
|
23
|
+
|
|
24
|
+
## Version 2.13.0 - 2022-22-03
|
|
25
|
+
|
|
26
|
+
### Added
|
|
27
|
+
|
|
28
|
+
- CDL syntax:
|
|
29
|
+
+ Allow to `extend E:elem` and `annotate E:elem` instead of having to write deeply nested statements.
|
|
30
|
+
+ Enable `default` values as part of scalar type definitions.
|
|
31
|
+
+ The following `extend` syntax variants are now possible:
|
|
32
|
+
```cds
|
|
33
|
+
extend … with elements { … }
|
|
34
|
+
extend … with definitions { … }
|
|
35
|
+
extend … with columns { … }
|
|
36
|
+
extend … with enum { … }
|
|
37
|
+
extend … with actions { … }
|
|
38
|
+
```
|
|
39
|
+
This syntax expresses _how_ an artifact is extended instead of _what_ is extended.
|
|
40
|
+
+ Using `ORDER BY` in generic functions such as SAP HANA's `first_value` is now possible.
|
|
41
|
+
- Make API function `compileSources` accept CSN objects as file content
|
|
42
|
+
- to.edm(x): Annotate view parameters with `@sap.parameter: mandatory` (V2) and `@Common.FieldControl: #Mandatory` (V4).
|
|
43
|
+
- to.sql/hdi/hdbcds: Introduce the annotations `@sql.prepend` and `@sql.append` that allow inserting user-written SQL
|
|
44
|
+
snippets into the compiler generated content. Changes in annotations `@sql.prepend` and `@sql.append` are now reflected
|
|
45
|
+
in the output of `to.hdi.migration`. This enables CDS Build to produce `.hdbmigrationtable` files translating such model
|
|
46
|
+
changes into schema changes.
|
|
47
|
+
- API: Lists of keywords for various backends are available as `to.<backend>[.<config>].keywords`, e.g. `to.sql.sqlite.keywords`.
|
|
48
|
+
- for.odata/to.edm(x): The draft composition hull is now also taking into account compositions in subelements.
|
|
49
|
+
|
|
50
|
+
### Changed
|
|
51
|
+
|
|
52
|
+
- In query entities inside services, only auto-redirect associations and compositions
|
|
53
|
+
in the main query of the entity.
|
|
54
|
+
- An element now inherits the property `notNull` from its query source (as
|
|
55
|
+
before) or its type (like it does for most other properties);
|
|
56
|
+
`notNull` is then not further propagated to its sub elements anymore.
|
|
57
|
+
- A structure element inherits the property `virtual` from its query source (as
|
|
58
|
+
before), but does not further propagate `virtual` to its sub elements
|
|
59
|
+
(semantically of course, but the CSN is not cluttered with it);
|
|
60
|
+
there is a new warning if a previously `virtual` query entity
|
|
61
|
+
element is now considered to be non-virtual.
|
|
62
|
+
- Do not propagate annotation value `null`.
|
|
63
|
+
The value `null` of an annotation (and `doc`) is used to stop the inheritance
|
|
64
|
+
of an annotation value. This means than other than that, a value `null` should
|
|
65
|
+
not be handled differently to not having set that annotation.
|
|
66
|
+
- In the effective CSN, the structure type is only expanded if something has changed
|
|
67
|
+
for associations: the `target` (`keys` does not change if the `target` does not change)
|
|
68
|
+
unmanaged associations as sub elements are not supported anyway.
|
|
69
|
+
- In the effective CSN, “simple” type properties like `length`, `precision`,
|
|
70
|
+
`scale` and `srid` are propagated even for a propagation via type.
|
|
71
|
+
- Update OData Vocabularies: 'Capabilities', 'Common', 'Core', 'UI'.
|
|
72
|
+
- to.sql:
|
|
73
|
+
+ For SQL dialect `hana` referential constraints are now appended
|
|
74
|
+
as `ALTER TABLE ADD CONSTRAINT` clause to the end of `schema.sql`.
|
|
75
|
+
With option `constraintsInCreateTable` constraints are rendered into the
|
|
76
|
+
`CREATE TABLE` statement.
|
|
77
|
+
+ Referential constraint names are now prefixed with `c__`.
|
|
78
|
+
|
|
79
|
+
### Fixed
|
|
80
|
+
|
|
81
|
+
- Properly resolve references inside anonymous aspects:
|
|
82
|
+
+ references starting with `$self.` made the compiler dump.
|
|
83
|
+
+ a simple `$self` did not always work as expected (it represents the entity created via the anonymous aspect).
|
|
84
|
+
+ other references inside deeply nested anonymous aspects induced a compilation error.
|
|
85
|
+
- compiler: `()` inside `ORDER BY` clause was not correctly set.
|
|
86
|
+
- parse.cdl: References in `ORDER BY` and filters are now correctly resolved.
|
|
87
|
+
- Issue error when trying to introduce managed compositions of aspects in `mixin`s
|
|
88
|
+
- Issue error in all cases for type references to unmanaged associations.
|
|
89
|
+
- Avoid dump when extending an illegal definition with a name starting with `cds.`.
|
|
90
|
+
- to.sql/to.cdl/to.hdbcds/to.hdi: Render `cast()` inside `ORDER BY`, `GROUP BY` and `HAVING` properly.
|
|
91
|
+
- to.sql/hdi/hdbcds:
|
|
92
|
+
+ `$self` was incorrectly treated as a structured path step.
|
|
93
|
+
+ Correctly handle table alias in on-condition of mixin in `exists` expansion.
|
|
94
|
+
+ Correctly handle table `$self` references to aliased fields in on-condition of mixin association
|
|
95
|
+
during `exists` expansion.
|
|
96
|
+
- to.edm: Don't escape `&` as `&`.
|
|
97
|
+
- to.edmx: Escaping compliant to XML specification:
|
|
98
|
+
+ `&` and `<` are always escaped.
|
|
99
|
+
+ `>` is not escaped, unless it appears in text values as `]]>`.
|
|
100
|
+
+ `"` is escaped in attribute values only.
|
|
101
|
+
+ Control characters are always escaped.
|
|
102
|
+
- Ellipsis (`...`) in annotations in different layers but without base annotation now produces an error.
|
|
103
|
+
The old but incorrect behavior can be re-enabled with option `anno-unexpected-ellipsis-layers`.
|
|
104
|
+
|
|
10
105
|
## Version 2.12.0 - 2022-01-25
|
|
11
106
|
|
|
12
107
|
### Added
|
|
@@ -18,16 +113,16 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
18
113
|
for syntax highlighting, similar to markdown. In difference to the former, text blocks require the
|
|
19
114
|
opening and closing backticks to be on separate lines.
|
|
20
115
|
Example:
|
|
116
|
+
````
|
|
117
|
+
@annotation: `Multi
|
|
118
|
+
line\u{0020}strings`
|
|
21
119
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
</summary>
|
|
29
|
-
```
|
|
30
|
-
...
|
|
120
|
+
@textblock: ```xml
|
|
121
|
+
<summary>
|
|
122
|
+
<detail>The root tag has no indentation in this example</detail>
|
|
123
|
+
</summary>
|
|
124
|
+
```
|
|
125
|
+
````
|
|
31
126
|
|
|
32
127
|
- Enhance the ellipsis operator `...` for array annotations by an `up to ‹val›`:
|
|
33
128
|
only values in the array of the base annotation up to (including) the first match
|
|
@@ -38,12 +133,12 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
38
133
|
values in `‹val›` are equal to the corresponding property value in the array value;
|
|
39
134
|
it is not necessary to specify all properties of the array value items in `‹val›`.
|
|
40
135
|
Example
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
136
|
+
```
|
|
137
|
+
@Anno: [{name: one, val: 1}, {name: two, val: 2}, {name: four, val: 4}]
|
|
138
|
+
type T: Integer;
|
|
139
|
+
@Anno: [{name: zero, val: 0}, ... up to {name: two}, {name: three, val: 3}, ...]
|
|
140
|
+
annotate T;
|
|
141
|
+
```
|
|
47
142
|
- for.odata: Support `@cds.on {update|insert}` as replacement for deprecated `@odata.on { update|insert }` to
|
|
48
143
|
set `@Core.Computed`.
|
|
49
144
|
|
package/bin/cdsc.js
CHANGED
|
@@ -163,14 +163,6 @@ try {
|
|
|
163
163
|
)
|
|
164
164
|
cmdLine.options.assertIntegrity = cmdLine.options.assertIntegrity === 'true';
|
|
165
165
|
|
|
166
|
-
// remap string values for `constraintsAsAlter` option to boolean
|
|
167
|
-
if (cmdLine.options.constraintsAsAlter &&
|
|
168
|
-
cmdLine.options.constraintsAsAlter === 'true' ||
|
|
169
|
-
cmdLine.options.constraintsAsAlter === 'false'
|
|
170
|
-
)
|
|
171
|
-
cmdLine.options.constraintsAsAlter = cmdLine.options.constraintsAsAlter === 'true';
|
|
172
|
-
|
|
173
|
-
|
|
174
166
|
// Enable all beta-flags if betaMode is set to true
|
|
175
167
|
if (cmdLine.options.betaMode)
|
|
176
168
|
cmdLine.options.beta = availableBetaFlags;
|
|
@@ -452,7 +444,7 @@ function executeCommandLine(command, options, args) {
|
|
|
452
444
|
* Print the model's messages to stderr in a human readable way.
|
|
453
445
|
*
|
|
454
446
|
* @param {CSN.Model | XSN.Model} model
|
|
455
|
-
* @param {
|
|
447
|
+
* @param {CompileMessage[]} messages
|
|
456
448
|
*/
|
|
457
449
|
function displayMessages( model, messages = options.messages ) {
|
|
458
450
|
if (!Array.isArray(messages))
|
|
@@ -483,7 +475,6 @@ function executeCommandLine(command, options, args) {
|
|
|
483
475
|
hasAtLeastOneExplanation = hasAtLeastOneExplanation || main.hasMessageExplanation(msg.messageId);
|
|
484
476
|
const name = msg.location && msg.location.file;
|
|
485
477
|
const fullFilePath = name ? path.resolve('', name) : undefined;
|
|
486
|
-
const context = fullFilePath ? sourceLines(fullFilePath) : [];
|
|
487
478
|
log(main.messageStringMultiline(msg, {
|
|
488
479
|
normalizeFilename,
|
|
489
480
|
noMessageId: !options.showMessageId,
|
|
@@ -491,8 +482,12 @@ function executeCommandLine(command, options, args) {
|
|
|
491
482
|
hintExplanation: true,
|
|
492
483
|
color: options.color,
|
|
493
484
|
}));
|
|
494
|
-
if (
|
|
485
|
+
if (fullFilePath && msg.location.col) {
|
|
486
|
+
// A message context only makes sense, if we have at least a medium precision,
|
|
487
|
+
// i.e. line and column for start position.
|
|
488
|
+
const context = sourceLines(fullFilePath);
|
|
495
489
|
log(main.messageContext(context, msg, { color: options.color }));
|
|
490
|
+
}
|
|
496
491
|
log(); // newline
|
|
497
492
|
});
|
|
498
493
|
if (options.showMessageId && hasAtLeastOneExplanation)
|
|
@@ -557,8 +552,13 @@ function executeCommandLine(command, options, args) {
|
|
|
557
552
|
content = JSON.stringify(content, null, 2);
|
|
558
553
|
|
|
559
554
|
if (dir === '-') {
|
|
560
|
-
if (!omitHeadline)
|
|
561
|
-
|
|
555
|
+
if (!omitHeadline) {
|
|
556
|
+
const sqlTypes = {
|
|
557
|
+
sql: true, hdbconstraint: true, hdbtable: true, hdbview: true,
|
|
558
|
+
};
|
|
559
|
+
const commentStarter = fileName.split('.').pop() in sqlTypes ? '--$' : '//';
|
|
560
|
+
process.stdout.write(`${commentStarter} ------------------- ${fileName} -------------------\n`);
|
|
561
|
+
}
|
|
562
562
|
|
|
563
563
|
process.stdout.write(`${content}\n`);
|
|
564
564
|
if (!omitHeadline)
|
package/bin/cdsse.js
CHANGED
|
@@ -144,8 +144,8 @@ function lint( err, buf ) {
|
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
146
|
|
|
147
|
-
function tokensAt( buf,
|
|
148
|
-
const src = `${buf.substring( 0,
|
|
147
|
+
function tokensAt( buf, _offset, col, symbol ) {
|
|
148
|
+
const src = `${buf.substring( 0, _offset )}≠${buf.substring( _offset )}`;
|
|
149
149
|
const et = messageAt( compiler.parseX( src, frel, { messages: [] } ), 'expectedTokens', col ) || [];
|
|
150
150
|
for (const n of et) {
|
|
151
151
|
if (typeof symbol === 'string') {
|
package/doc/CHANGELOG_BETA.md
CHANGED
|
@@ -8,23 +8,30 @@ 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 2.XX.YY
|
|
12
|
+
|
|
13
|
+
### Removed `assocsWithParams`
|
|
14
|
+
|
|
15
|
+
Instead, of using the beta flag `assocsWithParams`, you can change the severity of the messages
|
|
16
|
+
`def-unexpected-paramview-assoc` and `def-unexpected-calcview-assoc`.
|
|
17
|
+
|
|
11
18
|
## Version 2.12.0 - 2022-01-25
|
|
12
19
|
|
|
13
20
|
### Added `sqlSnippets`
|
|
14
21
|
|
|
15
22
|
- to.sql/hdi/hdbcds: Introduce the annotations `@sql.prepend` and `@sql.append` that allow inserting user-written SQL snippets into the compiler generated content.
|
|
16
23
|
|
|
17
|
-
## Version 2.11.0
|
|
24
|
+
## Version 2.11.0 - 2021-12-02
|
|
18
25
|
|
|
19
26
|
### Removed `foreignKeyConstraints`
|
|
20
27
|
|
|
21
|
-
## Version 2.10.4
|
|
28
|
+
## Version 2.10.4 - 2021-11-05
|
|
22
29
|
|
|
23
30
|
### Fixed `nestedProjections`
|
|
24
31
|
|
|
25
32
|
- to.sql/hdi/hdbcds: Correctly handle a `*` at the not-first place in the query
|
|
26
33
|
|
|
27
|
-
## Version 2.6.0
|
|
34
|
+
## Version 2.6.0 - 2021-08-23
|
|
28
35
|
|
|
29
36
|
### Removed `pretransformedCSN`
|
|
30
37
|
|
|
@@ -48,7 +55,7 @@ This is now the default - see CHANGELOG entry for 2.6.0
|
|
|
48
55
|
- Composition of one w/o backlink will result in a constraint in
|
|
49
56
|
the entity where the composition is defined
|
|
50
57
|
|
|
51
|
-
## Version 2.4.4
|
|
58
|
+
## Version 2.4.4 - 2021-07-02
|
|
52
59
|
|
|
53
60
|
### Added `nestedProjections`
|
|
54
61
|
|
|
@@ -59,7 +66,7 @@ This is now the default - see CHANGELOG entry for 2.6.0
|
|
|
59
66
|
- _Some checks are missing and will be added! Minor changes might occur._
|
|
60
67
|
- **The SQL backends might not work properly yet if nested projections are used!**
|
|
61
68
|
|
|
62
|
-
## Version 2.4.2
|
|
69
|
+
## Version 2.4.2 - 2021-07-01
|
|
63
70
|
|
|
64
71
|
### Added `keylessManagedAssoc`
|
|
65
72
|
|
|
@@ -71,7 +78,7 @@ This is now the default - see CHANGELOG entry for 2.6.0
|
|
|
71
78
|
Consequently, these associations are not added to the `WITH ASSOCIATIONS` clause or forwarded to HANA CDS.
|
|
72
79
|
Managed Associations without foreign keys must be enabled with `--beta: keylessManagedAssoc`
|
|
73
80
|
|
|
74
|
-
## Version 2.4.0
|
|
81
|
+
## Version 2.4.0 - 2021-06-28
|
|
75
82
|
|
|
76
83
|
### Changed `foreignKeyConstraints`
|
|
77
84
|
|
|
@@ -11,9 +11,25 @@ Note: `deprecated` features are listed in this ChangeLog just for information.
|
|
|
11
11
|
**When the `deprecated` option is set, the `beta` option is ignored,
|
|
12
12
|
and several new features are not available.**
|
|
13
13
|
|
|
14
|
+
## Version 2.XX.YY - 2022-MM-DD
|
|
15
|
+
|
|
16
|
+
### Added `redirectInSubQueries`
|
|
17
|
+
|
|
18
|
+
When this option is set, we auto-redirect associations and composition also in
|
|
19
|
+
non-main queries, sometimes without rewriting the `keys`/`on` (there will be no
|
|
20
|
+
fix for this).
|
|
21
|
+
|
|
22
|
+
### Added `oldVirtualNotNullPropagation`
|
|
23
|
+
|
|
24
|
+
When this option is set, we do not propagate `notNull` along types.
|
|
25
|
+
Additionally, we propagate `notNull` and `virtual` from a query source element
|
|
26
|
+
to the sub elements of a query entity element, even if the property is not
|
|
27
|
+
propagated to the query entity element itself (like with type references).
|
|
28
|
+
|
|
29
|
+
|
|
14
30
|
## Version 2.2.0
|
|
15
31
|
|
|
16
|
-
|
|
32
|
+
### Added `noScopedRedirections`
|
|
17
33
|
|
|
18
34
|
When this option is set, the definition scope is not taken into account when
|
|
19
35
|
trying to find an implicit redirection target. Setting the following
|
|
@@ -21,18 +37,18 @@ deprecated options also switches off scoped redirections (additionally to their
|
|
|
21
37
|
other effect): `noElementsExpansion`, `generatedEntityNameWithUnderscore`,
|
|
22
38
|
`shortAutoexposed`, `longAutoexposed`, `noInheritedAutoexposeViaComposition`.
|
|
23
39
|
|
|
24
|
-
|
|
40
|
+
### Added `noInheritedAutoexposeViaComposition`
|
|
25
41
|
|
|
26
42
|
When this option is set, only entities directly specified after `Composition of` are
|
|
27
43
|
auto-exposed, not entities used as target via explicit or implicit `redirected to`.
|
|
28
44
|
|
|
29
45
|
## Version 2.0.16
|
|
30
46
|
|
|
31
|
-
|
|
47
|
+
### Added `downgradableErrors`
|
|
32
48
|
|
|
33
49
|
Allow to change the severity of some errors which should stay to be an error.
|
|
34
50
|
|
|
35
|
-
|
|
51
|
+
### Added `shortAutoexposed`
|
|
36
52
|
|
|
37
53
|
When this option is set (and `generatedEntityNameWithUnderscore`), the names of
|
|
38
54
|
autoexposed entities are calculated according to the default compiler v1
|
|
@@ -40,13 +56,13 @@ behavior (without v1 options `dependentAutoexposed` and `longAutoexposed`).
|
|
|
40
56
|
|
|
41
57
|
## Version 2.0.10
|
|
42
58
|
|
|
43
|
-
|
|
59
|
+
### Added `longAutoexposed`
|
|
44
60
|
|
|
45
61
|
When this option is set (and `generatedEntityNameWithUnderscore`),
|
|
46
62
|
the names of autoexposed entities are calculated according to the
|
|
47
63
|
compiler v1 option `longAutoexposed`.
|
|
48
64
|
|
|
49
|
-
|
|
65
|
+
### Added `generatedEntityNameWithUnderscore`
|
|
50
66
|
|
|
51
67
|
Keep using `_` is separator for generated autoexposed entities and for entities
|
|
52
68
|
created for managed compositions. It also disables a definition `A.B.C` if `A`
|
package/doc/NameResolution.md
CHANGED
|
@@ -22,22 +22,27 @@ others might want to [skip the introduction](#design-principles).
|
|
|
22
22
|
|
|
23
23
|
## Table of Contents
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
<!-- toc: start -->
|
|
26
|
+
|
|
27
|
+
1. [Table of Contents](#table-of-contents)
|
|
28
|
+
2. [Introduction](#introduction)
|
|
29
|
+
1. [Background: SQL](#background-sql)
|
|
30
|
+
2. [Background: modern programming languages](#background-modern-programming-languages)
|
|
31
|
+
3. [Design Principles](#design-principles)
|
|
32
|
+
4. [Name Resolution - the Basics](#name-resolution---the-basics)
|
|
33
|
+
1. [Common rules](#common-rules)
|
|
34
|
+
2. [Resolving paths](#resolving-paths)
|
|
35
|
+
3. [Navigation environment](#navigation-environment)
|
|
36
|
+
5. [References to main artifacts](#references-to-main-artifacts)
|
|
37
|
+
6. [Values and references to elements](#values-and-references-to-elements)
|
|
38
|
+
1. [References in queries](#references-in-queries)
|
|
39
|
+
2. [References to sibling elements](#references-to-sibling-elements)
|
|
40
|
+
3. [Other element references](#other-element-references)
|
|
41
|
+
7. [Paths as annotation values](#paths-as-annotation-values)
|
|
42
|
+
8. [Differences to HANA-CDS](#differences-to-hana-cds)
|
|
43
|
+
9. [Summary](#summary)
|
|
44
|
+
|
|
45
|
+
<!-- toc: end -->
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
## Introduction
|
package/lib/api/main.js
CHANGED
|
@@ -35,6 +35,7 @@ const propertyToCheck = {
|
|
|
35
35
|
|
|
36
36
|
const { cloneCsn } = require('../model/csnUtils');
|
|
37
37
|
const { toHdbcdsSource } = require('../render/toHdbcds');
|
|
38
|
+
const { ModelError } = require('../base/error');
|
|
38
39
|
|
|
39
40
|
const relevantGeneralOptions = [ /* for future generic options */ ];
|
|
40
41
|
const relevantOdataOptions = [ 'sqlMapping', 'odataFormat' ];
|
|
@@ -115,7 +116,7 @@ function checkPreTransformedCsn(csn, options, relevantOptionNames, warnAboutMism
|
|
|
115
116
|
* @returns {boolean} Return true if it is pre-transformed
|
|
116
117
|
*/
|
|
117
118
|
function isPreTransformed(csn, transformation) {
|
|
118
|
-
return csn.meta && csn.meta.transformation === transformation;
|
|
119
|
+
return csn && csn.meta && csn.meta.transformation === transformation;
|
|
119
120
|
}
|
|
120
121
|
|
|
121
122
|
/**
|
|
@@ -173,7 +174,7 @@ function forSql(csn, options = {}) {
|
|
|
173
174
|
* Transform a CSN like to.hdi
|
|
174
175
|
*
|
|
175
176
|
* @param {CSN.Model} csn Plain input CSN
|
|
176
|
-
* @param {
|
|
177
|
+
* @param {HdiOptions} [options={}] Options
|
|
177
178
|
* @returns {CSN.Model} CSN transformed like to.hdi
|
|
178
179
|
* @private
|
|
179
180
|
*/
|
|
@@ -186,7 +187,7 @@ function forHdi(csn, options = {}) {
|
|
|
186
187
|
* Transform a CSN like to.hdbcds
|
|
187
188
|
*
|
|
188
189
|
* @param {CSN.Model} csn Plain input CSN
|
|
189
|
-
* @param {
|
|
190
|
+
* @param {HdbcdsOptions} [options={}] Options
|
|
190
191
|
* @returns {CSN.Model} CSN transformed like to.hdbcds
|
|
191
192
|
* @private
|
|
192
193
|
*/
|
|
@@ -224,7 +225,7 @@ function sql(csn, options = {}) {
|
|
|
224
225
|
* Process the given CSN into HDI artifacts.
|
|
225
226
|
*
|
|
226
227
|
* @param {CSN.Model} csn A clean input CSN
|
|
227
|
-
* @param {
|
|
228
|
+
* @param {HdiOptions} [options={}] Options
|
|
228
229
|
* @returns {HDIArtifacts} { <filename>:<content>, ...}
|
|
229
230
|
*/
|
|
230
231
|
function hdi(csn, options = {}) {
|
|
@@ -247,19 +248,19 @@ function hdi(csn, options = {}) {
|
|
|
247
248
|
const flat = flattenResultStructure(intermediateResult);
|
|
248
249
|
|
|
249
250
|
const nameMapping = Object.create(null);
|
|
250
|
-
const
|
|
251
|
-
const
|
|
251
|
+
const sqlArtifactsWithCSNNamesToSort = Object.create(null);
|
|
252
|
+
const sqlArtifactsNotToSort = Object.create(null);
|
|
252
253
|
|
|
253
254
|
Object.keys(flat).forEach((key) => {
|
|
254
255
|
const artifactNameLikeInCsn = key.replace(/\.[^/.]+$/, '');
|
|
255
256
|
nameMapping[artifactNameLikeInCsn] = key;
|
|
256
257
|
if (key.endsWith('.hdbtable') || key.endsWith('.hdbview'))
|
|
257
|
-
|
|
258
|
+
sqlArtifactsWithCSNNamesToSort[artifactNameLikeInCsn] = flat[key];
|
|
258
259
|
else
|
|
259
|
-
|
|
260
|
+
sqlArtifactsNotToSort[key] = flat[key];
|
|
260
261
|
});
|
|
261
262
|
|
|
262
|
-
const sorted = sortViews({ sql:
|
|
263
|
+
const sorted = sortViews({ sql: sqlArtifactsWithCSNNamesToSort, csn: sqlCSN })
|
|
263
264
|
.filter(obj => obj.sql)
|
|
264
265
|
.reduce((previous, current) => {
|
|
265
266
|
const hdiArtifactName = remapName(nameMapping[current.name], sqlCSN, k => !k.endsWith('.hdbindex'));
|
|
@@ -267,9 +268,9 @@ function hdi(csn, options = {}) {
|
|
|
267
268
|
return previous;
|
|
268
269
|
}, Object.create(null));
|
|
269
270
|
|
|
270
|
-
// now add the not-sorted stuff, like
|
|
271
|
-
Object.keys(
|
|
272
|
-
sorted[remapName(key, sqlCSN, k => !k.endsWith('.hdbindex'))] =
|
|
271
|
+
// now add the not-sorted stuff, like indices
|
|
272
|
+
Object.keys(sqlArtifactsNotToSort).forEach((key) => {
|
|
273
|
+
sorted[remapName(key, sqlCSN, k => !k.endsWith('.hdbindex'))] = sqlArtifactsNotToSort[key];
|
|
273
274
|
});
|
|
274
275
|
|
|
275
276
|
return sorted;
|
|
@@ -325,7 +326,7 @@ function remapName(key, csn, filter = () => true) {
|
|
|
325
326
|
* Note: Only supports changes in entities (not views etc.) compiled/rendered as HANA-CSN/SQL.
|
|
326
327
|
*
|
|
327
328
|
* @param {CSN.Model} csn A clean input CSN representing the desired "after-image"
|
|
328
|
-
* @param {
|
|
329
|
+
* @param {HdiOptions} options Options
|
|
329
330
|
* @param {CSN.Model} beforeImage A HANA-transformed CSN representing the "before-image", or null in case no such image
|
|
330
331
|
* is known, i.e. for the very first migration step
|
|
331
332
|
* @returns {object} - afterImage: The desired after-image in HANA-CSN format
|
|
@@ -346,8 +347,8 @@ function hdiMigration(csn, options, beforeImage) {
|
|
|
346
347
|
* This is for backward compatibility with @sap/cds@4.5.(2…3).
|
|
347
348
|
*
|
|
348
349
|
* @todo Remove in cds-compiler@2.x
|
|
349
|
-
* @param {
|
|
350
|
-
* @param {CSN.Model
|
|
350
|
+
* @param {HdiOptions|CSN.Model} inputOptions Options or CSN image
|
|
351
|
+
* @param {HdiOptions|CSN.Model} inputBeforeImage CSN image or options
|
|
351
352
|
* @returns {Array} Array where the real options come first
|
|
352
353
|
*/
|
|
353
354
|
function backwardCompatible(inputOptions, inputBeforeImage) {
|
|
@@ -438,7 +439,7 @@ hdi.migration = hdiMigration;
|
|
|
438
439
|
* Process the given CSN into HDBCDS artifacts.
|
|
439
440
|
*
|
|
440
441
|
* @param {any} csn A clean input CSN
|
|
441
|
-
* @param {
|
|
442
|
+
* @param {HdbcdsOptions} [options={}] Options
|
|
442
443
|
* @returns {HDBCDS} { <filename>:<content>, ...}
|
|
443
444
|
*/
|
|
444
445
|
function hdbcds(csn, options = {}) {
|
|
@@ -643,12 +644,18 @@ function publishCsnProcessor( processor, _name ) {
|
|
|
643
644
|
return processor( csn, options, ...args );
|
|
644
645
|
}
|
|
645
646
|
catch (err) {
|
|
646
|
-
if (err instanceof CompilationError || options.noRecompile)
|
|
647
|
-
|
|
647
|
+
if (err instanceof CompilationError || options.noRecompile || isPreTransformed(csn, 'odata')) // we cannot recompile a pre-transformed CSN
|
|
648
|
+
throw err;
|
|
649
|
+
|
|
650
|
+
if (options.testMode && !(err instanceof TypeError) &&
|
|
651
|
+
!(err instanceof ModelError))
|
|
648
652
|
throw err;
|
|
649
653
|
|
|
650
654
|
const { info } = makeMessageFunction( csn, options, 'compile' );
|
|
651
|
-
info( 'api-recompiled-csn', emptyLocation('csn.json'), {}, 'CSN input had to be recompiled' );
|
|
655
|
+
const msg = info( 'api-recompiled-csn', emptyLocation('csn.json'), {}, 'CSN input had to be recompiled' );
|
|
656
|
+
if (options.internalMsg)
|
|
657
|
+
msg.error = err; // Attach original error
|
|
658
|
+
|
|
652
659
|
// next line to be replaced by CSN parser call which reads the CSN object
|
|
653
660
|
const xsn = recompileX(csn, options);
|
|
654
661
|
const recompiledCsn = compactModel(xsn);
|
|
@@ -682,12 +689,6 @@ function publishCsnProcessor( processor, _name ) {
|
|
|
682
689
|
* @typedef {'plain' | 'quoted' | 'hdbcds' } NamingMode
|
|
683
690
|
*/
|
|
684
691
|
|
|
685
|
-
/**
|
|
686
|
-
* Available SQL change modes
|
|
687
|
-
*
|
|
688
|
-
* @typedef {'alter' | 'drop' } SqlChangeMode
|
|
689
|
-
*/
|
|
690
|
-
|
|
691
692
|
/**
|
|
692
693
|
* Available oData versions
|
|
693
694
|
*
|
|
@@ -700,42 +701,6 @@ function publishCsnProcessor( processor, _name ) {
|
|
|
700
701
|
* @typedef { 'structured' | 'flat' } oDataFormat
|
|
701
702
|
*/
|
|
702
703
|
|
|
703
|
-
/**
|
|
704
|
-
* Generally available options
|
|
705
|
-
*
|
|
706
|
-
* @typedef {object} Options
|
|
707
|
-
* @property {object} [beta] Enable experimental features - not for productive use!
|
|
708
|
-
* @property {boolean} [dependentAutoexposed=false] For dependent autoexposed entities (managed compositions, texts entity), follow name of base entity
|
|
709
|
-
* @property {boolean} [longAutoexposed=false] Deprecated: Produce long names (with underscores) for autoexposed entities
|
|
710
|
-
* @property {Map<string, number>} [severities={}] Map of message-id and severity that allows setting the severity for the given message
|
|
711
|
-
* @property {Array} [messages] Allows collecting all messages in the options instead of printing them to stderr.
|
|
712
|
-
*/
|
|
713
|
-
|
|
714
|
-
/**
|
|
715
|
-
* Options available for to.hdi
|
|
716
|
-
*
|
|
717
|
-
* @typedef {object} hdiOptions
|
|
718
|
-
* @property {NamingMode} [sqlMapping='plain'] Naming mode to use
|
|
719
|
-
* @property {SqlChangeMode} [sqlChangeMode='alter'] SQL change mode to use (for changed columns)
|
|
720
|
-
* @property {boolean} [allowCsnDowngrade=false] Allow downgrades of CSN major version (for modelCompare)
|
|
721
|
-
* @property {object} [beta] Enable experimental features - not for productive use!
|
|
722
|
-
* @property {boolean} [longAutoexposed=false] Deprecated: Produce long names (with underscores) for autoexposed entities
|
|
723
|
-
* @property {Map<string, number>} [severities={}] Map of message-id and severity that allows setting the severity for the given message
|
|
724
|
-
* @property {Array} [messages] Allows collecting all messages in the options instead of printing them to stderr.
|
|
725
|
-
*/
|
|
726
|
-
|
|
727
|
-
/**
|
|
728
|
-
* Options available for to.hdbcds
|
|
729
|
-
*
|
|
730
|
-
* @typedef {object} hdbcdsOptions
|
|
731
|
-
* @property {NamingMode} [sqlMapping='plain'] Naming mode to use
|
|
732
|
-
* @property {object} [beta] Enable experimental features - not for productive use!
|
|
733
|
-
* @property {boolean} [longAutoexposed=false] Deprecated: Produce long names (with underscores) for autoexposed entities
|
|
734
|
-
* @property {Map<string, number>} [severities={}] Map of message-id and severity that allows setting the severity for the given message
|
|
735
|
-
* @property {Array} [messages] Allows collecting all messages in the options instead of printing them to stderr.
|
|
736
|
-
*/
|
|
737
|
-
|
|
738
|
-
|
|
739
704
|
/**
|
|
740
705
|
* A fresh (just compiled, not transformed) CSN
|
|
741
706
|
*
|
|
@@ -755,13 +720,13 @@ function publishCsnProcessor( processor, _name ) {
|
|
|
755
720
|
*/
|
|
756
721
|
|
|
757
722
|
/**
|
|
758
|
-
* A map of { <file.hdbcds>:<content> }.
|
|
723
|
+
* A map of { <file.hdbcds|hdbconstraint>:<content> }.
|
|
759
724
|
*
|
|
760
725
|
* @typedef {object} HDBCDS
|
|
761
726
|
*/
|
|
762
727
|
|
|
763
728
|
/**
|
|
764
|
-
* A map of { <file.hdbtable
|
|
729
|
+
* A map of { <file.hdbtable|hdbview|hdbconstraint...>:<content> }.
|
|
765
730
|
*
|
|
766
731
|
* @typedef {object} HDIArtifacts
|
|
767
732
|
*/
|
package/lib/api/options.js
CHANGED
|
@@ -49,7 +49,7 @@ const privateOptions = [
|
|
|
49
49
|
'traceParserAmb',
|
|
50
50
|
'testMode',
|
|
51
51
|
'testSortCsn',
|
|
52
|
-
'
|
|
52
|
+
'constraintsInCreateTable',
|
|
53
53
|
'integrityNotEnforced',
|
|
54
54
|
'integrityNotValidated',
|
|
55
55
|
'assertIntegrity',
|
|
@@ -158,7 +158,7 @@ module.exports = {
|
|
|
158
158
|
sql: (options) => {
|
|
159
159
|
const hardOptions = { src: 'sql' };
|
|
160
160
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'plain' };
|
|
161
|
-
const processed = translateOptions(options, defaultOptions, hardOptions, undefined, [ 'sql-dialect-and-naming'
|
|
161
|
+
const processed = translateOptions(options, defaultOptions, hardOptions, undefined, [ 'sql-dialect-and-naming' ], 'to.sql');
|
|
162
162
|
|
|
163
163
|
const result = Object.assign({}, processed);
|
|
164
164
|
result.toSql = Object.assign({}, processed);
|
|
@@ -166,7 +166,7 @@ module.exports = {
|
|
|
166
166
|
return result;
|
|
167
167
|
},
|
|
168
168
|
hdi: (options) => {
|
|
169
|
-
const hardOptions = { src: 'hdi'
|
|
169
|
+
const hardOptions = { src: 'hdi' };
|
|
170
170
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
171
171
|
const processed = translateOptions(options, defaultOptions, hardOptions, { sqlDialect: generateStringValidator([ 'hana' ]) }, undefined, 'to.hdi');
|
|
172
172
|
|
package/lib/api/validate.js
CHANGED
|
@@ -142,11 +142,6 @@ const allCombinationValidators = {
|
|
|
142
142
|
severity: 'warning',
|
|
143
143
|
getMessage: () => 'Option "beta" was used. This option should not be used in productive scenarios!',
|
|
144
144
|
},
|
|
145
|
-
'constraints-as-alter-sqlite': {
|
|
146
|
-
validate: options => options.constraintsAsAlter && options.sqlDialect && options.sqlDialect === 'sqlite',
|
|
147
|
-
severity: 'warning',
|
|
148
|
-
getMessage: options => `Option 'constraintsAsAlter' is ignored for sqlDialect '${ options.sqlDialect }'`,
|
|
149
|
-
},
|
|
150
145
|
};
|
|
151
146
|
/* eslint-disable jsdoc/no-undefined-types */
|
|
152
147
|
/**
|