@sap/cds-compiler 2.5.0 → 2.10.4
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 +191 -9
- package/bin/cdsc.js +2 -2
- package/doc/CHANGELOG_BETA.md +33 -3
- package/lib/api/main.js +29 -101
- package/lib/api/options.js +15 -11
- package/lib/api/validate.js +12 -8
- package/lib/backends.js +0 -81
- package/lib/base/keywords.js +32 -2
- package/lib/base/message-registry.js +63 -9
- package/lib/base/messages.js +63 -21
- package/lib/base/model.js +2 -3
- package/lib/checks/defaultValues.js +27 -2
- package/lib/checks/elements.js +1 -6
- package/lib/checks/foreignKeys.js +0 -6
- package/lib/checks/managedWithoutKeys.js +17 -0
- package/lib/checks/nonexpandableStructured.js +38 -0
- package/lib/checks/onConditions.js +9 -45
- package/lib/checks/queryNoDbArtifacts.js +25 -7
- package/lib/checks/selectItems.js +25 -2
- package/lib/checks/types.js +26 -2
- package/lib/checks/unknownMagic.js +38 -0
- package/lib/checks/utils.js +61 -0
- package/lib/checks/validator.js +60 -7
- package/lib/compiler/assert-consistency.js +16 -7
- package/lib/compiler/builtins.js +2 -0
- package/lib/compiler/checks.js +6 -4
- package/lib/compiler/definer.js +99 -42
- package/lib/compiler/index.js +73 -27
- package/lib/compiler/resolver.js +288 -157
- package/lib/compiler/shared.js +31 -11
- package/lib/edm/annotations/genericTranslation.js +182 -186
- package/lib/edm/csn2edm.js +103 -108
- package/lib/edm/edm.js +18 -21
- package/lib/edm/edmPreprocessor.js +361 -114
- package/lib/edm/edmUtils.js +103 -33
- package/lib/gen/Dictionary.json +22 -0
- package/lib/gen/language.checksum +1 -1
- package/lib/gen/language.interp +12 -1
- package/lib/gen/language.tokens +57 -53
- package/lib/gen/languageLexer.interp +10 -1
- package/lib/gen/languageLexer.js +770 -744
- package/lib/gen/languageLexer.tokens +49 -46
- package/lib/gen/languageParser.js +4713 -4279
- package/lib/json/from-csn.js +103 -45
- package/lib/json/to-csn.js +296 -117
- package/lib/language/antlrParser.js +4 -3
- package/lib/language/errorStrategy.js +1 -0
- package/lib/language/genericAntlrParser.js +21 -12
- package/lib/language/language.g4 +99 -31
- package/lib/main.d.ts +81 -3
- package/lib/main.js +30 -7
- package/lib/model/api.js +78 -0
- package/lib/model/csnRefs.js +329 -142
- package/lib/model/csnUtils.js +235 -58
- package/lib/model/enrichCsn.js +18 -1
- package/lib/model/revealInternalProperties.js +2 -1
- package/lib/modelCompare/compare.js +37 -20
- package/lib/optionProcessor.js +9 -3
- package/lib/render/.eslintrc.json +4 -1
- package/lib/render/DuplicateChecker.js +8 -5
- package/lib/render/toCdl.js +112 -33
- package/lib/render/toHdbcds.js +134 -64
- package/lib/render/toSql.js +91 -38
- package/lib/render/utils/common.js +8 -13
- package/lib/render/utils/sql.js +3 -3
- package/lib/sql-identifier.js +6 -1
- package/lib/transform/db/assertUnique.js +5 -6
- package/lib/transform/db/constraints.js +29 -13
- package/lib/transform/db/draft.js +8 -6
- package/lib/transform/db/expansion.js +582 -0
- package/lib/transform/db/flattening.js +325 -0
- package/lib/transform/db/groupByOrderBy.js +2 -2
- package/lib/transform/db/transformExists.js +284 -63
- package/lib/transform/forHanaNew.js +98 -381
- package/lib/transform/forOdataNew.js +21 -22
- package/lib/transform/localized.js +37 -10
- package/lib/transform/odata/attachPath.js +19 -4
- package/lib/transform/odata/generateForeignKeyElements.js +11 -10
- package/lib/transform/odata/referenceFlattener.js +60 -39
- package/lib/transform/odata/sortByAssociationDependency.js +2 -2
- package/lib/transform/odata/structuralPath.js +72 -0
- package/lib/transform/odata/structureFlattener.js +19 -18
- package/lib/transform/odata/typesExposure.js +22 -12
- package/lib/transform/transformUtilsNew.js +134 -78
- package/lib/transform/translateAssocsToJoins.js +17 -14
- package/lib/transform/universalCsnEnricher.js +67 -0
- package/lib/utils/file.js +0 -11
- package/lib/utils/moduleResolve.js +6 -8
- package/package.json +1 -1
- package/lib/json/walker.js +0 -26
- package/lib/transform/sqlite +0 -0
- package/lib/utils/string.js +0 -17
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,182 @@
|
|
|
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.10.4 - 2021-11-05
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- to.sql/hdi/hdbcds:
|
|
15
|
+
+ Correctly complain about `exists` in conjunction with non-associations/compositions
|
|
16
|
+
+ Don't resolve types in action returns, as this causes issues with $self-resolution
|
|
17
|
+
|
|
18
|
+
- to.edm(x): Be robust against transitively untyped keys in stacked view hierarchies
|
|
19
|
+
|
|
20
|
+
## Version 2.10.2 - 2021-10-29
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- to.sql/hdi/hdbcds: Correctly handle `exists` in conjunction with mixin-associations
|
|
25
|
+
|
|
26
|
+
## Version 2.10.0 - 2021-10-28
|
|
27
|
+
|
|
28
|
+
### Added
|
|
29
|
+
|
|
30
|
+
- Support arbitrary paths after `$user` - similar to `$session`.
|
|
31
|
+
- Support scale `floating` and `variable` for `cds.Decimal` in CDL and CSN. Backend specific handling is descibed in their sections.
|
|
32
|
+
- Allow select item wildcard (`*`) in a `select`/`projection` at any position, not just the first.
|
|
33
|
+
|
|
34
|
+
- to.edm(x):
|
|
35
|
+
+ In Odata V4 generate transitive navigation property binding paths along containment hierarchies and terminate on the
|
|
36
|
+
first non-containment association. The association target is either an explicit Edm.EntitySet in the same EntityContainer
|
|
37
|
+
or in a referred EntityContainer (cross service references) or an implicit EntitySet identified by the containment path
|
|
38
|
+
originating from an explicit EntitySet. This enhancement has an observable effect only in structured format with containment
|
|
39
|
+
turned on.
|
|
40
|
+
+ Support for scales `variable` and `floating`:
|
|
41
|
+
+ V4: `variable` and `floating` are rendered as `Scale="variable"`. Since V4 does not support `floating`, it is aproximated as `variable`.
|
|
42
|
+
+ V2: `variable` and `floating` are announced via property annotation `sap:variable-scale="true"`
|
|
43
|
+
|
|
44
|
+
- to.sql/hdi/hdbcds:
|
|
45
|
+
+ Reject scale `floating` and `variable`.
|
|
46
|
+
+ Reject arbitrary `$user` or `$session` paths that cannot be translated to valid SQL.
|
|
47
|
+
+ Following a valid `exists`, further `exists` can be used inside of the filter-expression: `exists assoc[exists another[1=1]]`
|
|
48
|
+
+ `exists` can now be followed by more than one association step.
|
|
49
|
+
`exists assoc.anotherassoc.moreassoc` is semantically equivalent to `exists assoc[exists anotherassoc[exists moreassoc]]`
|
|
50
|
+
|
|
51
|
+
### Changed
|
|
52
|
+
|
|
53
|
+
- to.odata: Inform when overwriting draft action annotations like `@Common.DraftRoot.ActivationAction`.
|
|
54
|
+
|
|
55
|
+
## Version 2.9.0 - 2021-10-15
|
|
56
|
+
|
|
57
|
+
### Changed
|
|
58
|
+
|
|
59
|
+
- to.edm(x): Raise `odata-spec-violation-type` to a downgradable error.
|
|
60
|
+
|
|
61
|
+
### Fixed
|
|
62
|
+
|
|
63
|
+
- to.edm(x):
|
|
64
|
+
+ Fix a bug in annotation propagation to foreign keys.
|
|
65
|
+
+ Don't render annotations for not rendered stream element in V2.
|
|
66
|
+
- to.hdi:
|
|
67
|
+
+ for naming mode "hdbcds" and "quoted" parameter definitions are not quoted anymore.
|
|
68
|
+
- to.hdi/sql/hdbcds:
|
|
69
|
+
+ Correctly handle explicit and implicit alias during flattening.
|
|
70
|
+
+ Raise an error for `@odata.draft.enabled` artifacts with elements without types - instead of crashing with internal assertions.
|
|
71
|
+
|
|
72
|
+
## Version 2.8.0 - 2021-10-07
|
|
73
|
+
|
|
74
|
+
### Added
|
|
75
|
+
|
|
76
|
+
- Allow defining unmanaged associations in anonymous aspects of compositions.
|
|
77
|
+
- Enable extensions of anonymous aspects for managed compositions of aspects.
|
|
78
|
+
- When the option `addTextsLanguageAssoc` is set to true and
|
|
79
|
+
the model contains an entity `sap.common.Languages` with an element `code`,
|
|
80
|
+
all generated texts entities additionally contain an element `language`
|
|
81
|
+
which is an association to `sap.common.Languages` using element `local`.
|
|
82
|
+
- for.odata:
|
|
83
|
+
+ In `--odata-format=flat`, structured view parameters are flattened like elements.
|
|
84
|
+
- to.hdbcds
|
|
85
|
+
+ Use "smart quotes" for naming mode "plain" - automatically quote identifier which are reserved keywords or non-regular.
|
|
86
|
+
|
|
87
|
+
### Changed
|
|
88
|
+
|
|
89
|
+
- for.odata:
|
|
90
|
+
+ In `--data-format=structured`, anonymous sub elements of primary keys and parameters are set to `notNull:true`,
|
|
91
|
+
an existing `notNull` attribute is _not_ overwritten. Referred named types are _not_ modified.
|
|
92
|
+
- to.edm(x):
|
|
93
|
+
+ Improve specification violation checks of (nested) keys:
|
|
94
|
+
+ All (sub-)elements must be `Nullable: false` (error).
|
|
95
|
+
+ Must represent a single value (error).
|
|
96
|
+
+ In V4 must be a specification compliant Edm.PrimitiveType (warning).
|
|
97
|
+
- to.hdi/hdbcds/sql: $user.\<xy\> now has \<xy\> added as alias - "$user.\<xy\> as \<xy\>"
|
|
98
|
+
|
|
99
|
+
### Fixed
|
|
100
|
+
|
|
101
|
+
- Properly generate auto-exposed entities for associations in parameters.
|
|
102
|
+
- Correctly apply extensions to anonymous array item types.
|
|
103
|
+
- Correctly apply/render annotations to anonymous action return types.
|
|
104
|
+
- With CSN flavor `plain` (`gensrc`), correctly render annotations on elements
|
|
105
|
+
of referred structure types as `annotate` statements in the CSN's `extensions` property.
|
|
106
|
+
- to.cdl:
|
|
107
|
+
+ Correctly render extensions on array item types
|
|
108
|
+
+ Correctly render annotations on action return types
|
|
109
|
+
- to/for: Correctly handle CSN input where the prototype of objects is not the "default"
|
|
110
|
+
- to.hdi:
|
|
111
|
+
+ for naming mode "hdbcds" and "quoted" parameter definitions are now quoted.
|
|
112
|
+
+ for naming mode "plain", smart quotation is applied to parameter definitions if they are reserved words.
|
|
113
|
+
- to.hdi/hdbcds/sql:
|
|
114
|
+
+ Ensure that cdl-style casts to localized types do not lose their localized property
|
|
115
|
+
+ Fix a small memory leak during rendering of SQL/HDBCDS.
|
|
116
|
+
- to.edm(x): Remove ambiguous `Partner` attribute from `NavigationProperty`. A forward association referred
|
|
117
|
+
to by multiple backlinks (`$self` comparisons) is no longer partner to an arbitrary backlink.
|
|
118
|
+
|
|
119
|
+
## Version 2.7.0 - 2021-09-22
|
|
120
|
+
|
|
121
|
+
### Added
|
|
122
|
+
|
|
123
|
+
- to.hdi.migration:
|
|
124
|
+
+ Support changes to HANA comments.
|
|
125
|
+
|
|
126
|
+
### Changed
|
|
127
|
+
|
|
128
|
+
- Updated OData vocabularies 'Common', 'Core'
|
|
129
|
+
|
|
130
|
+
### Fixed
|
|
131
|
+
|
|
132
|
+
- Fix memory issue: do not keep reference to last-compiled model.
|
|
133
|
+
- Fix dump which occured when trying to report that the user has defined an element to be both `key` and `localized` if
|
|
134
|
+
`localized` was inherited via the provided type, or in the generated entity for a managed composition of aspect.
|
|
135
|
+
- Properly auto-expose targets of associations in parameters and `many`.
|
|
136
|
+
- for.Odata:
|
|
137
|
+
+ Fix handling of annotation `@cds.odata.valuelist` in conjunction with associations in structures using flat-mode and sqlMapping set to plain.
|
|
138
|
+
+ Set correctly the $localized property in the OData backend resulting CSN for artifacts that have localized convenience views.
|
|
139
|
+
- to.edm(x):
|
|
140
|
+
+ Fix rendering of structured referential constraints and nested partnerships in combination with `$self` comparisons.
|
|
141
|
+
+ Fix merging of `@Capabilities` annotations while transforming them into `NavigationCapabilities` from the containee into the container.
|
|
142
|
+
- to.sql/hdi/hdbcds:
|
|
143
|
+
+ Fix a bug in Association to Join translation in multi-level association redirection in combination with `$self`.
|
|
144
|
+
+ Correctly flatten paths with filters or parameters.
|
|
145
|
+
+ Improve error message in case of invalid `exists`.
|
|
146
|
+
|
|
147
|
+
## Version 2.6.2 - 2021-08-26
|
|
148
|
+
|
|
149
|
+
### Fixed
|
|
150
|
+
|
|
151
|
+
- to.sql/hdi/hdbcds/edm(x)/for.odata: Correctly handle tuple expansion in subqueries of Unions.
|
|
152
|
+
|
|
153
|
+
## Version 2.6.0 - 2021-08-23
|
|
154
|
+
|
|
155
|
+
### Added
|
|
156
|
+
|
|
157
|
+
- Support managed associations without foreign keys. Associations targeting a definition without primary keys or with an
|
|
158
|
+
explicit empty foreign key tuple or with empty structured elements as foreign keys and their corresponding `$self`
|
|
159
|
+
comparisons do not describe the relationship between the source and the target entity.
|
|
160
|
+
These associations can be used to establish API navigations but cannot be used to access elements in the target
|
|
161
|
+
entity as they cannot be transformed into a valid JOIN expression.
|
|
162
|
+
Consequently, these associations are not added to the `WITH ASSOCIATIONS` clause or forwarded to HANA CDS.
|
|
163
|
+
- to.sql/hdi/hdbcds/edm(x)/for.odata: Structure/managed association comparisons (tuple comparisons) are now
|
|
164
|
+
also expanded in infix filters, all expressions and all on-conditions.
|
|
165
|
+
- to.hdbcds: Better locations for messages - mostly concerning keywords and duplicates
|
|
166
|
+
|
|
167
|
+
### Changed
|
|
168
|
+
|
|
169
|
+
- to.sql/hdi/hdbcds: Invalid (i.e. not expandable) usage of structures is now checked - an error is raised
|
|
170
|
+
|
|
171
|
+
### Removed
|
|
172
|
+
|
|
173
|
+
- The internal non-enumerable CSN property `$env` has been removed from the compiled CSN.
|
|
174
|
+
|
|
175
|
+
### Fixed
|
|
176
|
+
|
|
177
|
+
- Make `;` optional before `}` in all circumstances (was not the case with `many`).
|
|
178
|
+
- to.sql/hdi/hdbcds/edm(x): More graceful handling of CSN input where associations do not have `keys` or an `on`-condition
|
|
179
|
+
|
|
180
|
+
## Version 2.5.2 - 2021-08-10
|
|
181
|
+
|
|
182
|
+
### Fixed
|
|
183
|
+
|
|
184
|
+
- to.hdbcds: Fixed a bug introduced with 2.5.0 that caused virtual elements to be rendered in views.
|
|
185
|
+
|
|
10
186
|
## Version 2.5.0 - 2021-07-28
|
|
11
187
|
|
|
12
188
|
### Added
|
|
@@ -47,19 +223,19 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
47
223
|
and 'Ignoring draft node for composition target ... because it is not part of a service'
|
|
48
224
|
- Doc comments are no longer ignored after enum values and on view columns in parseCdl mode.
|
|
49
225
|
- to.cdl:
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
226
|
+
+ Doc comments for enum values are correctly rendered.
|
|
227
|
+
+ Enum value and doc comments are now correctly rendered if the enum is called `doc`.
|
|
228
|
+
+ Doc comments at type references are correctly rendered.
|
|
229
|
+
+ Empty doc comments are correctly rendered and not left out.
|
|
230
|
+
+ Doc comments on view columns are correctly rendered.
|
|
55
231
|
- to.edm(x):
|
|
56
|
-
|
|
57
|
-
|
|
232
|
+
+ OData V2: Ignore `@odata.singleton`.
|
|
233
|
+
+ OData V4: Do not render an `edm:NavigationPropertyBinding` to a singleton if the association has
|
|
58
234
|
cardinality 'to-many'.
|
|
59
235
|
- forOData:
|
|
60
|
-
|
|
236
|
+
+ Fix automatic renaming of shortcut annotation (eg. `@label`) with value `null`.
|
|
61
237
|
- CSN parser:
|
|
62
|
-
|
|
238
|
+
+ Empty doc comments are correctly parsed and not complained about.
|
|
63
239
|
|
|
64
240
|
## Version 2.4.4 - 2021-07-02
|
|
65
241
|
|
|
@@ -477,6 +653,12 @@ synchronously.
|
|
|
477
653
|
- to.hdi.migration: Don't generate `ALTER` for type change from association to composition or vice versa (if the rest stays the same),
|
|
478
654
|
as the resulting SQL is identical.
|
|
479
655
|
|
|
656
|
+
## Version 1.50.10 - 2021-07-30
|
|
657
|
+
|
|
658
|
+
### Fixed
|
|
659
|
+
|
|
660
|
+
- to.hdi.migration: Check for incompatible CSN versions to avoid wrongly generated ALTER|DROP|ADD statements.
|
|
661
|
+
|
|
480
662
|
## Version 1.50.8 - 2021-07-01
|
|
481
663
|
|
|
482
664
|
### Fixed
|
package/bin/cdsc.js
CHANGED
|
@@ -411,7 +411,7 @@ function executeCommandLine(command, options, args) {
|
|
|
411
411
|
if (options.rawOutput)
|
|
412
412
|
console.error( util.inspect( reveal( err.model, options.rawOutput ), false, null ));
|
|
413
413
|
else
|
|
414
|
-
displayMessages( err.model, err.
|
|
414
|
+
displayMessages( err.model, err.messages );
|
|
415
415
|
process.exitCode = 1;
|
|
416
416
|
}
|
|
417
417
|
else if (err instanceof compiler.InvocationError) {
|
|
@@ -528,7 +528,7 @@ function executeCommandLine(command, options, args) {
|
|
|
528
528
|
fileName = fileName.replace(/[:/\\]/g, '_');
|
|
529
529
|
|
|
530
530
|
// replace all dots with underscore to get deployable .hdbcds sources (except the one before the file extension)
|
|
531
|
-
if (options.
|
|
531
|
+
if (options.transformation === 'hdbcds')
|
|
532
532
|
fileName = fileName.replace(/\.(?=.*?\.)/g, '_');
|
|
533
533
|
|
|
534
534
|
if (!(content instanceof String || typeof content === 'string'))
|
package/doc/CHANGELOG_BETA.md
CHANGED
|
@@ -1,12 +1,43 @@
|
|
|
1
1
|
# ChangeLog of Beta Features for cdx compiler and backends
|
|
2
2
|
|
|
3
3
|
<!-- markdownlint-disable MD024 -->
|
|
4
|
+
<!-- markdownlint-disable MD004 -->
|
|
4
5
|
<!-- (no-duplicate-heading)-->
|
|
5
6
|
|
|
6
7
|
Note: `beta` fixes, changes and features are listed in this ChangeLog just for information.
|
|
7
8
|
The compiler behavior concerning `beta` features can change at any time without notice.
|
|
8
9
|
**Don't use `beta` fixes, changes and features in productive mode.**
|
|
9
10
|
|
|
11
|
+
## Version 2.10.4
|
|
12
|
+
|
|
13
|
+
### Fixed `nestedProjections`
|
|
14
|
+
|
|
15
|
+
- to.sql/hdi/hdbcds: Correctly handle a `*` at the not-first place in the query
|
|
16
|
+
|
|
17
|
+
## Version 2.6.0
|
|
18
|
+
|
|
19
|
+
### Removed `pretransformedCSN`
|
|
20
|
+
|
|
21
|
+
### Removed `renderSql`
|
|
22
|
+
|
|
23
|
+
### Removed `keylessManagedAssoc`
|
|
24
|
+
|
|
25
|
+
This is now the default - see CHANGELOG entry for 2.6.0
|
|
26
|
+
|
|
27
|
+
### Fixed `nestedProjections`
|
|
28
|
+
|
|
29
|
+
- to.sql/hdi/hdbcds: now work correctly when nested projections are used
|
|
30
|
+
|
|
31
|
+
### Fixed `foreignKeyConstraints`
|
|
32
|
+
|
|
33
|
+
- Always use the name of the association / backlink compared to
|
|
34
|
+
`$self` as name suffix for a constraint
|
|
35
|
+
- Composition of one always result in:
|
|
36
|
+
+ ON DELETE RESTRICT
|
|
37
|
+
+ ON UPDATE RESTRICT
|
|
38
|
+
- Composition of one w/o backlink will result in a constraint in
|
|
39
|
+
the entity where the composition is defined
|
|
40
|
+
|
|
10
41
|
## Version 2.4.4
|
|
11
42
|
|
|
12
43
|
### Added `nestedProjections`
|
|
@@ -15,8 +46,8 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
15
46
|
`longer.ref as name { *, … } excluding { … }`, `{ col_expression1 as sub1, … } as name`, etc.
|
|
16
47
|
- Support `inline`: columns can look like `assoc_or_struct_or_tabalias.{ col_expression1, … }`,
|
|
17
48
|
`longer.ref[filter = condition].{ *, … } excluding { … }`, `assoc_or_struct_or_tabalias.*`, etc.
|
|
18
|
-
- _Some checks are missing and will be added!
|
|
19
|
-
-
|
|
49
|
+
- _Some checks are missing and will be added! Minor changes might occur._
|
|
50
|
+
- **The SQL backends might not work properly yet if nested projections are used!**
|
|
20
51
|
|
|
21
52
|
## Version 2.4.2
|
|
22
53
|
|
|
@@ -30,7 +61,6 @@ The compiler behavior concerning `beta` features can change at any time without
|
|
|
30
61
|
Consequently, these associations are not added to the `WITH ASSOCIATIONS` clause or forwarded to HANA CDS.
|
|
31
62
|
Managed Associations without foreign keys must be enabled with `--beta: keylessManagedAssoc`
|
|
32
63
|
|
|
33
|
-
|
|
34
64
|
## Version 2.4.0
|
|
35
65
|
|
|
36
66
|
### Changed `foreignKeyConstraints`
|
package/lib/api/main.js
CHANGED
|
@@ -4,15 +4,18 @@
|
|
|
4
4
|
|
|
5
5
|
const prepareOptions = require('./options');
|
|
6
6
|
const backends = require('../backends');
|
|
7
|
-
const { setProp
|
|
7
|
+
const { setProp } = require('../base/model');
|
|
8
8
|
const { emptyLocation } = require('../base/location');
|
|
9
|
-
const { CompilationError, makeMessageFunction
|
|
10
|
-
const {
|
|
9
|
+
const { CompilationError, makeMessageFunction } = require('../base/messages');
|
|
10
|
+
const { recompileX } = require('../compiler/index');
|
|
11
|
+
const { compactModel, sortCsn } = require('../json/to-csn');
|
|
11
12
|
const { transform4odataWithCsn } = require('../transform/forOdataNew.js');
|
|
12
13
|
const { toSqlDdl } = require('../render/toSql');
|
|
13
14
|
const { compareModels } = require('../modelCompare/compare');
|
|
14
15
|
const sortViews = require('../model/sortViews');
|
|
15
16
|
const { getResultingName } = require('../model/csnUtils');
|
|
17
|
+
const timetrace = require('../utils/timetrace');
|
|
18
|
+
const { transformForHanaWithCsn } = require('../transform/forHanaNew');
|
|
16
19
|
|
|
17
20
|
/**
|
|
18
21
|
* Return the artifact name for use for the hdbresult object
|
|
@@ -31,10 +34,10 @@ const propertyToCheck = {
|
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
const { cloneCsn } = require('../model/csnUtils');
|
|
37
|
+
const { toHdbcdsSource } = require('../render/toHdbcds');
|
|
34
38
|
|
|
35
39
|
const relevantGeneralOptions = [ /* for future generic options */ ];
|
|
36
40
|
const relevantOdataOptions = [ 'sqlMapping', 'odataFormat' ];
|
|
37
|
-
const relevantSqlOptions = [ 'sqlMapping', 'sqlDialect' ];
|
|
38
41
|
const warnAboutMismatchOdata = [ 'odataVersion' ];
|
|
39
42
|
|
|
40
43
|
/**
|
|
@@ -188,8 +191,11 @@ function forHdi(csn, options = {}) {
|
|
|
188
191
|
*/
|
|
189
192
|
function forHdbcds(csn, options = {}) {
|
|
190
193
|
const internalOptions = prepareOptions.to.hdbcds(options);
|
|
191
|
-
internalOptions.
|
|
192
|
-
|
|
194
|
+
internalOptions.transformation = 'hdbcds';
|
|
195
|
+
|
|
196
|
+
const hanaCsn = transformForHanaWithCsn(csn, internalOptions, 'to.hdbcds');
|
|
197
|
+
|
|
198
|
+
return internalOptions.testMode ? sortCsn(hanaCsn, internalOptions) : hanaCsn;
|
|
193
199
|
}
|
|
194
200
|
|
|
195
201
|
/**
|
|
@@ -205,18 +211,7 @@ function sql(csn, options = {}) {
|
|
|
205
211
|
// we need the CSN for view sorting
|
|
206
212
|
internalOptions.toSql.csn = true;
|
|
207
213
|
|
|
208
|
-
|
|
209
|
-
if (isBetaEnabled(internalOptions, 'pretransformedCSN') && isPreTransformed(csn, 'sql')) {
|
|
210
|
-
internalOptions.noRecompile = true; // pre-transformed cannot be recompiled!
|
|
211
|
-
checkPreTransformedCsn(csn, internalOptions, relevantSqlOptions, warnAboutMismatchOdata, 'to.sql');
|
|
212
|
-
|
|
213
|
-
intermediateResult = backends.renderSqlWithCsn(csn, internalOptions);
|
|
214
|
-
// attach CSN for view sorting
|
|
215
|
-
intermediateResult.csn = cloneCsn(csn, internalOptions);
|
|
216
|
-
}
|
|
217
|
-
else {
|
|
218
|
-
intermediateResult = backends.toSqlWithCsn(csn, internalOptions);
|
|
219
|
-
}
|
|
214
|
+
const intermediateResult = backends.toSqlWithCsn(csn, internalOptions);
|
|
220
215
|
|
|
221
216
|
const result = sortViews(intermediateResult);
|
|
222
217
|
|
|
@@ -445,10 +440,15 @@ hdi.migration = hdiMigration;
|
|
|
445
440
|
* @returns {HDBCDS} { <filename>:<content>, ...}
|
|
446
441
|
*/
|
|
447
442
|
function hdbcds(csn, options = {}) {
|
|
443
|
+
timetrace.start('to.hdbcds');
|
|
448
444
|
const internalOptions = prepareOptions.to.hdbcds(options);
|
|
449
|
-
|
|
445
|
+
internalOptions.transformation = 'hdbcds';
|
|
446
|
+
|
|
447
|
+
const hanaCsn = forHdbcds(csn, internalOptions);
|
|
450
448
|
|
|
451
|
-
|
|
449
|
+
const result = flattenResultStructure(toHdbcdsSource(hanaCsn, internalOptions));
|
|
450
|
+
timetrace.stop();
|
|
451
|
+
return result;
|
|
452
452
|
}
|
|
453
453
|
/**
|
|
454
454
|
* Generate a edm document for the given service
|
|
@@ -494,19 +494,17 @@ function edmall(csn, options = {}) {
|
|
|
494
494
|
if (internalOptions.version === 'v2')
|
|
495
495
|
error(null, null, 'OData JSON output is not available for OData V2');
|
|
496
496
|
|
|
497
|
-
let servicesAll;
|
|
498
|
-
|
|
499
497
|
const result = {};
|
|
498
|
+
let oDataCsn = csn;
|
|
500
499
|
|
|
501
|
-
if (isPreTransformed(csn, 'odata'))
|
|
500
|
+
if (isPreTransformed(csn, 'odata'))
|
|
502
501
|
checkPreTransformedCsn(csn, internalOptions, relevantOdataOptions, warnAboutMismatchOdata, 'for.odata');
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
const services = servicesAll.edmj;
|
|
502
|
+
|
|
503
|
+
else
|
|
504
|
+
oDataCsn = odataInternal(csn, internalOptions);
|
|
505
|
+
|
|
506
|
+
const servicesJson = backends.preparedCsnToEdmAll(oDataCsn, internalOptions);
|
|
507
|
+
const services = servicesJson.edmj;
|
|
510
508
|
for (const serviceName in services) {
|
|
511
509
|
const lEdm = services[serviceName];
|
|
512
510
|
// FIXME: Why only metadata_json - isn't this rather a 'combined_json' ? If so, rename it!
|
|
@@ -595,41 +593,6 @@ function flattenResultStructure(toProcess) {
|
|
|
595
593
|
return result;
|
|
596
594
|
}
|
|
597
595
|
|
|
598
|
-
/**
|
|
599
|
-
* Compute the .hdbcds files that would have been generated by the csn for an undeploy.json.
|
|
600
|
-
* This is needed for the handover between hdbcds and hdbtable - the existing hdbcds artifacts need to be undeployed.
|
|
601
|
-
*
|
|
602
|
-
* @param {any} csn A clean input CSN
|
|
603
|
-
* @param {hdbcdsOptions} [options={}] Options
|
|
604
|
-
* @returns {string[]} Array of .hdbcds filenames
|
|
605
|
-
*/
|
|
606
|
-
function undeploy(csn, options) {
|
|
607
|
-
const hdbcdsResult = hdbcds(csn, options);
|
|
608
|
-
|
|
609
|
-
return Object.keys(hdbcdsResult);
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
/**
|
|
613
|
-
* This function simply renders the given CSN to SQL - no integrity checks, no transformations, no guarantees for correctness.
|
|
614
|
-
* Strictly for internal evaluation!
|
|
615
|
-
*
|
|
616
|
-
* @param {CSN.Model} csn A CSN - for things to work correctly, this is expected to be a DB transformed CSN. Plain CSN might work - or might not.
|
|
617
|
-
* @param {sqlOptions} [options={}] Options
|
|
618
|
-
* @returns {SQL[]} Array of SQL statements, tables first, views second - the resulting statements might not be a consistent, deployable state!
|
|
619
|
-
*/
|
|
620
|
-
function renderSQL(csn, options) {
|
|
621
|
-
const internalOptions = prepareOptions.to.sql(options);
|
|
622
|
-
if (!isBetaEnabled(internalOptions, 'renderSQL'))
|
|
623
|
-
throw new Error('renderSQL is only available with beta-flag "renderSQL".');
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
// Add flag so it thinks we ran through forHanaNew
|
|
627
|
-
internalOptions.forHana = true;
|
|
628
|
-
|
|
629
|
-
const sqlResult = toSqlDdl(csn, internalOptions);
|
|
630
|
-
return Object.values(flattenResultStructure(sqlResult));
|
|
631
|
-
}
|
|
632
|
-
|
|
633
596
|
module.exports = {
|
|
634
597
|
odata: publishCsnProcessor(odata, 'for.odata'),
|
|
635
598
|
cdl: publishCsnProcessor(cdl, 'to.cdl'),
|
|
@@ -642,45 +605,10 @@ module.exports = {
|
|
|
642
605
|
for_sql: publishCsnProcessor(forSql, 'for.sql'),
|
|
643
606
|
for_hdi: publishCsnProcessor(forHdi, 'for.hdi'),
|
|
644
607
|
for_hdbcds: publishCsnProcessor(forHdbcds, 'for.hdbcds'),
|
|
645
|
-
renderSQL,
|
|
646
|
-
undeploy,
|
|
647
608
|
/** */
|
|
648
609
|
};
|
|
649
610
|
|
|
650
611
|
|
|
651
|
-
/**
|
|
652
|
-
* Recompile the given CSN
|
|
653
|
-
*
|
|
654
|
-
* @param {object} csn Input CSN to recompile to XSN
|
|
655
|
-
* @param {object} options Options
|
|
656
|
-
* @returns {object} XSN
|
|
657
|
-
*
|
|
658
|
-
* TODO: move to lib/compiler/, consider new $recompile option, probaby issue
|
|
659
|
-
* message api-recompiled-csn there.
|
|
660
|
-
*/
|
|
661
|
-
function recompile(csn, options) {
|
|
662
|
-
// TODO: is it really a good idea to set options in the input parameter?
|
|
663
|
-
// (as long as we have the messages meddling of the option processor...)
|
|
664
|
-
// OK, I try a copy
|
|
665
|
-
options = { ...options };
|
|
666
|
-
// Explicitly set parseCdl to false because backends cannot handle
|
|
667
|
-
// the option and is only intended for CDL sources.
|
|
668
|
-
options.parseCdl = false; // TODO: delete this option
|
|
669
|
-
// Explicitly delete all toCsn options
|
|
670
|
-
delete options.toCsn;
|
|
671
|
-
/* eslint-disable global-require */
|
|
672
|
-
const { augment } = require('../json/from-csn');
|
|
673
|
-
const { compileSourcesX } = require('../compiler');
|
|
674
|
-
/* eslint-enable global-require */
|
|
675
|
-
const file = csn.$location && csn.$location.file &&
|
|
676
|
-
csn.$location.file.replace(/[.]cds$/, '.cds.csn') || '<recompile>.csn';
|
|
677
|
-
const xsn = augment(csn, file, options); // in-place
|
|
678
|
-
const compiled = compileSourcesX( { [file]: xsn }, { ...options, $recompile: true } );
|
|
679
|
-
if (options.messages)
|
|
680
|
-
deduplicateMessages(options.messages);
|
|
681
|
-
return compiled;
|
|
682
|
-
}
|
|
683
|
-
|
|
684
612
|
/**
|
|
685
613
|
* @param {any} processor CSN processor
|
|
686
614
|
* @param {string} _name Name of the processor
|
|
@@ -720,7 +648,7 @@ function publishCsnProcessor( processor, _name ) {
|
|
|
720
648
|
const { info } = makeMessageFunction( csn, options, 'compile' );
|
|
721
649
|
info( 'api-recompiled-csn', emptyLocation('csn.json'), {}, 'CSN input had to be recompiled' );
|
|
722
650
|
// next line to be replaced by CSN parser call which reads the CSN object
|
|
723
|
-
const xsn =
|
|
651
|
+
const xsn = recompileX(csn, options);
|
|
724
652
|
const recompiledCsn = compactModel(xsn);
|
|
725
653
|
return processor( recompiledCsn, options, ...args );
|
|
726
654
|
}
|
package/lib/api/options.js
CHANGED
|
@@ -10,11 +10,13 @@ const publicOptionsNewAPI = [
|
|
|
10
10
|
// GENERAL
|
|
11
11
|
'beta',
|
|
12
12
|
'deprecated',
|
|
13
|
+
'addTextsLanguageAssoc',
|
|
13
14
|
'localizedLanguageFallback', // why can't I define the option type here?
|
|
14
15
|
'severities',
|
|
15
16
|
'messages',
|
|
16
17
|
'withLocations',
|
|
17
18
|
'defaultStringLength',
|
|
19
|
+
'csnFlavor',
|
|
18
20
|
// DB
|
|
19
21
|
'sqlDialect',
|
|
20
22
|
'sqlMapping',
|
|
@@ -68,10 +70,11 @@ const overallOptions = publicOptionsNewAPI.concat(privateOptions);
|
|
|
68
70
|
* @param {FlatOptions} [hardRequire={}] Hard requirements to enforce
|
|
69
71
|
* @param {object} [customValidators] Custom validations to run instead of defaults
|
|
70
72
|
* @param {string[]} [combinationValidators] Option combinations to validate
|
|
73
|
+
* @param {string} moduleName The called module, e.g. 'for.odata', 'to.hdi'. Needed to initialize the message functions
|
|
71
74
|
* @returns {TranslatedOptions} General cds options
|
|
72
75
|
*/
|
|
73
76
|
function translateOptions(input = {}, defaults = {}, hardRequire = {},
|
|
74
|
-
customValidators = {}, combinationValidators = []) {
|
|
77
|
+
customValidators = {}, combinationValidators = [], moduleName = '') {
|
|
75
78
|
const options = Object.assign({}, defaults);
|
|
76
79
|
const inputOptionNames = Object.keys(input);
|
|
77
80
|
for (const name of overallOptions) {
|
|
@@ -90,6 +93,7 @@ function translateOptions(input = {}, defaults = {}, hardRequire = {},
|
|
|
90
93
|
// Validate the filtered input options
|
|
91
94
|
// only "new-style" options are here
|
|
92
95
|
validate(options,
|
|
96
|
+
moduleName,
|
|
93
97
|
// TODO: is there a better place to specify the type of option values?
|
|
94
98
|
Object.assign( {
|
|
95
99
|
localizedLanguageFallback: generateStringValidator([ 'none', 'coalesce' ]),
|
|
@@ -141,11 +145,11 @@ function translateOptions(input = {}, defaults = {}, hardRequire = {},
|
|
|
141
145
|
|
|
142
146
|
module.exports = {
|
|
143
147
|
to: {
|
|
144
|
-
cdl: options => translateOptions(options),
|
|
148
|
+
cdl: options => translateOptions(options, undefined, undefined, undefined, undefined, 'to.cdl'),
|
|
145
149
|
sql: (options) => {
|
|
146
150
|
const hardOptions = { src: 'sql' };
|
|
147
151
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'plain' };
|
|
148
|
-
const processed = translateOptions(options, defaultOptions, hardOptions, undefined, [ 'sql-dialect-and-naming' ]);
|
|
152
|
+
const processed = translateOptions(options, defaultOptions, hardOptions, undefined, [ 'sql-dialect-and-naming' ], 'to.sql');
|
|
149
153
|
|
|
150
154
|
const result = Object.assign({}, processed);
|
|
151
155
|
result.toSql = Object.assign({}, processed);
|
|
@@ -155,7 +159,7 @@ module.exports = {
|
|
|
155
159
|
hdi: (options) => {
|
|
156
160
|
const hardOptions = { src: 'hdi' };
|
|
157
161
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
158
|
-
const processed = translateOptions(options, defaultOptions, hardOptions, { sqlDialect: generateStringValidator([ 'hana' ]) });
|
|
162
|
+
const processed = translateOptions(options, defaultOptions, hardOptions, { sqlDialect: generateStringValidator([ 'hana' ]) }, undefined, 'to.hdi');
|
|
159
163
|
|
|
160
164
|
const result = Object.assign({}, processed);
|
|
161
165
|
result.toSql = Object.assign({}, processed);
|
|
@@ -164,17 +168,17 @@ module.exports = {
|
|
|
164
168
|
},
|
|
165
169
|
hdbcds: (options) => {
|
|
166
170
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
167
|
-
const processed = translateOptions(options, defaultOptions, {}, { sqlDialect: generateStringValidator([ 'hana' ]) });
|
|
171
|
+
const processed = translateOptions(options, defaultOptions, {}, { sqlDialect: generateStringValidator([ 'hana' ]) }, undefined, 'to.hdbcds');
|
|
168
172
|
|
|
169
173
|
const result = Object.assign({}, processed);
|
|
170
|
-
result.
|
|
174
|
+
result.forHana = Object.assign({}, processed);
|
|
171
175
|
|
|
172
176
|
return result;
|
|
173
177
|
},
|
|
174
178
|
edm: (options) => {
|
|
175
179
|
const hardOptions = { json: true, combined: true };
|
|
176
180
|
const defaultOptions = { odataVersion: 'v4', odataFormat: 'flat' };
|
|
177
|
-
const processed = translateOptions(options, defaultOptions, hardOptions, { odataVersion: generateStringValidator([ 'v4' ]) }, [ 'valid-structured' ]);
|
|
181
|
+
const processed = translateOptions(options, defaultOptions, hardOptions, { odataVersion: generateStringValidator([ 'v4' ]) }, [ 'valid-structured' ], 'to.edm');
|
|
178
182
|
|
|
179
183
|
const result = Object.assign({}, processed);
|
|
180
184
|
result.toOdata = Object.assign({}, processed);
|
|
@@ -186,7 +190,7 @@ module.exports = {
|
|
|
186
190
|
const defaultOptions = {
|
|
187
191
|
odataVersion: 'v4', odataFormat: 'flat',
|
|
188
192
|
};
|
|
189
|
-
const processed = translateOptions(options, defaultOptions, hardOptions, undefined, [ 'valid-structured' ]);
|
|
193
|
+
const processed = translateOptions(options, defaultOptions, hardOptions, undefined, [ 'valid-structured' ], 'to.edmx');
|
|
190
194
|
|
|
191
195
|
const result = Object.assign({}, processed);
|
|
192
196
|
result.toOdata = Object.assign({}, processed);
|
|
@@ -198,7 +202,7 @@ module.exports = {
|
|
|
198
202
|
|
|
199
203
|
odata: (options) => {
|
|
200
204
|
const defaultOptions = { odataVersion: 'v4', odataFormat: 'flat' };
|
|
201
|
-
const processed = translateOptions(options, defaultOptions, undefined, undefined, [ 'valid-structured' ]);
|
|
205
|
+
const processed = translateOptions(options, defaultOptions, undefined, undefined, [ 'valid-structured' ], 'for.odata');
|
|
202
206
|
|
|
203
207
|
const result = Object.assign({}, processed);
|
|
204
208
|
result.toOdata = Object.assign({}, processed);
|
|
@@ -208,10 +212,10 @@ module.exports = {
|
|
|
208
212
|
},
|
|
209
213
|
hana: (options) => {
|
|
210
214
|
const defaultOptions = { sqlMapping: 'plain', sqlDialect: 'hana' };
|
|
211
|
-
const processed = translateOptions(options, defaultOptions);
|
|
215
|
+
const processed = translateOptions(options, defaultOptions, undefined, undefined, undefined, 'for.hana');
|
|
212
216
|
|
|
213
217
|
const result = Object.assign({}, processed);
|
|
214
|
-
result.
|
|
218
|
+
result.forHana = Object.assign({}, processed);
|
|
215
219
|
|
|
216
220
|
|
|
217
221
|
return result;
|