UNPKG

@sap/cds-compiler

Version:

CDS (Core Data Services) compiler and backends

1,085 lines (796 loc) 80.5 kB
# ChangeLog for cds compiler and backends <!-- markdownlint-disable MD024 --> <!-- markdownlint-disable MD004 --> <!-- (no-duplicate-heading)--> Note: `beta` fixes, changes and features are usually not listed in this ChangeLog but in [doc/CHANGELOG_BETA.md](doc/CHANGELOG_BETA.md). The compiler behavior concerning `beta` features can change at any time without notice. ## Version 6.2.2 - 2025-07-28 ### Fixed - compiler: `@extension.code` was accidentally restricted to non-expression values. ## Version 6.2.0 - 2025-07-25 ### Added - parser: CDL-casts in queries now support all type expressions, e.g. `field : many String not null`. - compiler: Association paths in annotation expressions can now end with a filter, e.g. `@anno: (assoc[1=1])`. ### Changed - compiler: Annotation `@extension.code` is no longer propagated. - Update OData vocabularies: Common - The list of CDL keywords was updated for the latest CDL grammar. - to.cdl: Foreign keys of managed associations are only rendered explicitly if the compiler can't infer them when recompiled. - cdsc: The command `parseCdl` was renamed to `parse`, since it also supports CSN input. ### Fixed - compiler: + Calculated elements can now have a localized type. + Associations in sub-queries of an `order by` of a `UNION` are now redirected. ## Version 6.1.0 - 2025-06-27 ### Added - for.odata: + Introduce a new option `addAnnotationAddressViaNavigationPath` to annotate services containing draft-enabled entities with `@Common.AddressViaNavigationPath`. + Introduce a new option `draftMessages` that enhances the draft generation logic. ### Changed - Update OData vocabularies: Capabilities, Common ### Fixed - compiler: The ternary condition operator `…?…:…` is now right-associative as usual (in v5, chaining it like in `…?…:…?…:…` was not possible without parentheses). ## Version 6.0.14 - 2025-06-18 ### Fixed - to.sql: Fix error when calculated element refers to a localized element. - to.edm(x): Correctly handle `PropertyPath` in a collection when using expressions as annotation values ## Version 6.0.12 - 2025-06-06 ### Changed - Update OData vocabularies: 'Common', 'Hierarchy' ### Fixed - compiler: Fix artifact refs in annotated annotation expressions, i.e. the `Type` inside `annotate … with @SomeAnno: (cast( … as Type ))`. - to.sql: Checks around managed associations for mocked entities have been relaxed. - to.edm(x): Resolved a crash caused by references in annotation expressions that were not properly updated. ## Version 6.0.10 - 2025-05-28 ### Fixed - to.sql/to.hdi: + Fixed internal error for to-many associations without ON-condition in entities with `@cds.persistence.skip`. - for.odata/to.edm(x): + In annotation expressions: enum references that have already been resolved by the compiler are correctly rendered to EDMX. ## Version 6.0.8 - 2025-05-23 ### Changed - License changed to "SAP DEVELOPER LICENSE AGREEMENT Version 3.2 CAP" - Node 20 is now the minimum required version. - Namespace `cds.core` is no longer reserved by the cds-compiler. It is used by the CAP runtimes. - compiler: + Providing a filter for a function call now is a syntax error (was a warning before). Example: `count(*)[ uncheckedFilterRef > 0 ]`. + Providing a default value for an array-like action or function parameter is a syntax error now (was a warning before). Example: `action A( par: many Integer default 42 )`. + Providing an annotation for an array-like element in the middle of a type expression is no longer allowed (was a warning before), as this leads to unexpected results. Example: `bar: many String null @anno enum { symbol };`. Fix this by moving the annotation out of the type expression, e.g. before the element name. + A simple query inside parentheses (e.g. `entity V as (select from E)`) is no longer represented as `set` in CSN. Repeated `order by` or `limit` clauses are no longer allowed (e.g. `entity V as ( select from E order by id ) order by id;`). + Defining an element or parameter as `not null default now` now is an error. + A virtual element can be defined in a view without providing a value or reference. ```cds entity V as select from E { virtual a } //defines new virtual element 'a' ``` In this example, the compiler no longer tries to resolve the name of the virtual element as reference to an element of the view's data source. + If a select item selects an element of a virtual structure that itself is not explicitly marked as virtual, then the select item must be explicitly marked as virtual, too. + To-many associations without ON-condition no longer get a `keys` property, i.e. `Association to many Foo;` does not get any foreign keys. + Annotation `@cds.persistence.journal` is now propagated to generated entities, including `.texts` entities. + Doc comments are no longer propagated; use option `propagateDocComments: true` to propagate them again. + With CSN input, the compiler does not accept anymore type properties like `enum` in the `cast` property for the SQL function `cast` which were simply ignored by the SQL backend. Remark: inside a direct `cast` property for select columns (CDL-style `cast`), these type properties are still allowed. - to.sql/to.hdi: + Default for option `booleanEquality` is `true`, i.e. `!=` is rendered as `IS DISTINCT FROM` or a similar expression and therefore has boolean logic instead of three-valued logic. + To-many associations with neither an explicit foreign key list (i.e. without `keys`) nor an ON-condition are reported as errors. + For SAP HANA, CDS associations are by default no longer reflected in the respective database tables and views by native HANA Associations (HANA SQL clause `WITH ASSOCIATIONS`). They can be switched on via configuration `cds.sql.native_hana_associations: true`. + A set of OData and SAP HANA functions are translated to database-specific variants. See <https://cap.cloud.sap/docs/guides/databases#standard-database-functions>. + For SQL and HDI rendering, `$now` is no longer rendered as `CURRENT_TIMESTAMP`, but as a session variable `SESSION_CONTEXT('NOW')` for SAP HANA, `SESSION_CONTEXT('$now')` for SQLite, `@now` for H2, and `current_setting('cap.now')::timestamp` for Postgres. For `default` values, `CURRENT_TIMESTAMP` is kept, as `default` clauses only allow static expressions. To restore the old behavior, use option `dollarNowAsTimestamp: true`. + `count(*)` inside nested projections is rejected, as there is no proper representation in SQL - to.cdl: + Nested definition rendering is now the default, i.e. definitions inside services are rendered in `service { … }`, instead of being rendered top-level using their absolute name. + `to.cdl` no longer returns an entry `namespace`, only `model`. - for.odata/to.edm(x): + References to foreign keys in annotation expressions are now adjusted to directly reference the corresponding local foreign key element. + Annotating the generated `DraftAdministrativeData` artifacts and their elements is now supported. ### Added - for.odata/to.edm(x): + Annotating the generated `DraftAdministrativeData` artifacts and their elements is now supported. ### Removed - compiler: + The Antlr-based parser is removed. + v5 deprecated flags are removed, see [CHANGELOG_DEPRECATED.md](doc/CHANGELOG_DEPRECATED.md). + Option `compositionIncludes` is removed, as its default is `true`; instead, a deprecated flag was added. - to.hdbcds: The HDBCDS backend is deprecated and can no longer be invoked. ### Fixed - to.edm(x): Fixed crash for rare case if annotation expressions were used. ## Version 5.9.8 - 2025-07-14 ### Fixed - compiler: Calculated elements can now have a localized type ## Version 5.9.6 - 2025-06-18 ### Fixed - to.sql: Fix error when calculated element refers to a localized element. - to.edm(x): + Fix errors for service entities containing multiple path steps (e.g. `Service.Prefix.MyEntity`). + Support enum references in annotation expressions that were resolved by the compiler. ## Version 5.9.4 - 2025-05-22 ### Fixed - to.edm(x): Parameters are marked optional unless explicitly marked as `not null`. Annotation `Core.OptionalParameter` will be added to optional parameters. ## Version 5.9.2 - 2025-04-04 ### Fixed - to.edm(x): Revert addition of the attribute sap:filterable="false" to the NavigationProperty DraftAdministrativeData in OData V2 ## Version 5.9.0 - 2025-03-28 ### Added - compiler: + Generated entities for compositions of named aspects now have an `include` on the named aspect, inheriting actions from the aspect. This can be disabled via option `compositionIncludes: false`. + A warning is emitted for selected elements that are explicitly `virtual`, whose behavior will change in cds-compiler v6. + New warning for structures having a scalar default value. + New warning for localized structures, as they are not fully supported by the compiler. + The new parser (`newParser: true`) now supports operator `==`. - to.cdl: + Definitions can now be rendered nested in services. A common namespace can be extracted, too. To use it, enabled options `renderCdlDefinitionNesting` and `renderCdlCommonNamespace`. + Annotation array values are pretty-printed to reduce whitespace. - for.effective: Property `namespace` is no longer part of effective CSN. - for.sql/hdi: + The new operator `==` is rendered as `IS NOT DISTINCT FROM` or an equivalent expression. + Using option `booleanEquality`, operator `!=` is rendered as `IS DISTINCT FROM` or an equivalent expression. ### Changed - Update OData vocabularies: 'Common', 'Hierarchy' ### Fixed - to.odata: Annotation expressions using `LabeledElement` were not correctly rendered into EDMX. ## Version 5.8.2 - 2025-03-07 ### Fixed - for.odata: Generate foreign key elements for events again. ## Version 5.8.0 - 2025-02-27 ### Added - Type definitions can now be projections on other types, i.e. `type Proj : projection on OtherType { elem }`. Use it to create types based on other types, e.g. by selecting only certain elements. Only available with the new parser (`newParser: true`) - Analyze enum symbols like `#ENUM_SYMB` in all (sub) expressions and conditions. It can be validated if the compiler can deduce its `enum` type from its use context: + when the enum symbol is used as `default` value, `select` column expression, argument when navigating along an association to an entity with a parameter, or argument of a `cast` function call, or + when the enum symbol is compared to a reference or `cast` function call; we consider the operators `=`, `<>`, `!=`, `in`, `not in` and also analyze enum symbols as `when` operands if the `case` operand is a reference/`cast`. + We not only consider simple enum symbols, but also lists of enum symbols (on the right side of `in`/`not in`), and a `case … end` (sub) expression with enum symbols after the `then`s and/or the `else`. + An enum symbol can be validated if the deduced type is a direct or indirect `enum` type, or an managed association with one foreign key having an `enum` type. + For the effects in the compiler, IDE and backends, see the changelog entry for v5.7.0. Hint: the deprecated hdbcds backend does not support enum symbols. + Remark: the support for enum symbols used as annotation values is still limited. - to.sql.migration: Allow extending `precision` of `cds.Decimal` and allow extending `scale` if `precision` is increased by at least the same amount. - to.edm(x): `@assert.range` now supports "exclusive" values by writing values in parentheses such as `[ (1), (2) ]`, as well as "infinite" by using `[ _, _ ]`. - for.odata/to.edm(x)/for.seal: Propagate annotation expressions from managed associations to the foreign keys ### Changed - Top-level CSN property `csnInteropEffective` is ignored and no longer warned about. - Update OData vocabularies: 'Analytics', 'Common', 'Hierarchy', 'UI' ### Fixed - New CDL parser: parse all entity definitions using `projection on` without a terminating `;` if they had been accepted by the old parser, i.e. for compatibility, we gave up the idea of removing the existing special handling in this case. - Old and new parser: issue a warning for an ignored filter on the result of a function or method call. - CSN annotation expressions with value `true` for `=` were not checked. - Annotation `@Core.Computed` was not set for select items that are paths into structured parameters. - Annotation expression path rewriting has been improved. + Paths on foreign keys are rewritten. - for.seal: + References into structured parameters were incorrectly flattened. + Set `@cds.persistence.name` only on persistence-relevant things. ## Version 5.7.4 - 2025-02-05 ### Fixed - New CDL Parser (option `newParser: true`) + Improve code completion + Fix further edge cases in error recovery ## Version 5.7.2 - 2025-01-30 ### Fixed - Fix edge case in error recovery of the new CDL parser (option `newParser: true`) ## Version 5.7.0 - 2025-01-24 ### Added - Analyze enum symbols like `#ENUM_SYMB`; support starts at the following places: + used as sole `default` value or `select` column expression if the element/column has a specified enum type, or + used as sole value (in parentheses) of an annotation assignment if there is a definition for that annotation having an enum type; + effects in compiler: complain if enum symbol is undefined + effects in the IDE with an upcoming version of cds-lsp when compiler option `newParser` is set: offer code completion and hover information, + effects in backends like `to.sql` (and potentially runtimes): enum symbol is replaced by corresponding string/integer value when appropriate. - for.seal: Process foreign key annotations similar to to.edm(x) ### Changed - CDL parser: it is now recommended to set the option `newParser` to make the compiler use a CDL parser with a significantly smaller footprint (among other things). New features might only work if this option is set, see above. ### Fixed - CDL parser: doc comment parser was susceptible to ReDos - to.sql/hdi: Paths inside calculated elements that are simple functions were not properly rewritten. - for.odata: Re-add foreign keys in property `targetAspect` in the OData CSN. - to.edm(x): In annotation translation, by default map `SemanticObjectMappingAbstract` to `SemanticObjectMappingType` to avoid regressions. - to.cdl: Fix quoting of identifier `many` in `Composition of`/`Association to` - for.seal: Allow annotation paths to end in `many`-elements, not just scalar, like we allow in for.odata ## Version 5.6.0 - 2024-12-12 ### Added - Allow to refer to draft state element `HasActiveEntity` and `HasDraftEntity` via variable `$draft` in annotation path expressions. - for.odata|to.edm(x): Introduce annotating the generated foreign keys ### Changed - Update OData vocabularies: 'Common', 'EntityRelationship', 'UI' ## Version 5.5.2 - 2024-12-02 ### Fixed - to.hdi|sql|edm[x]: Correctly handle `cds.Map`, ensure that it does not have `.elements` yet. ## Version 5.5.0 - 2024-11-22 ### Added - CDL parser: when the new experimental option `newParser` is used, the compiler uses a CDL parser with a significantly smaller footprint (among other things). - to.sql|hdi.migration: For SAP HANA, render `ALTER` statements as one big statement to improve performance. - to.sql.migration: Give more helpful comments when using option `script`. ### Changed - Update OData vocabularies: 'Common', 'PersonalData', 'UI'. ## Version 5.4.4 - 2024-11-14 ### Fixed - Re-allow referring to mixins (and table aliases) in added columns - Re-add foreign keys of named aspects to the OData CSN. ## Version 5.4.2 - 2024-11-06 ### Fixed - to.sql: For SQLite, map `cds.Map` to `JSON_TEXT` to ensure text affinity. ## Version 5.4.0 - 2024-10-24 ### Added - to.edm(x): `cds.Map` as empty open complex type with name `cds_Map` or if the definition has been assigned `@open: false` as empty closed complex type `cds_Map_closed` in OData V4. ### Changed - Update OData vocabularies: 'Capabilities', 'Common', 'Core', 'PersonalData', 'PDF', 'UI'. - to.cdl: Identifiers using non-ASCII unicode characters, as introduced in v4.4.0, are no longer quoted. - For propagated expressions as annotation values, the `=` is changed as well, if it is a simple identifier. ### Fixed - compiler: Some invalid CDL snippets could crash the parser and compiler. - to.edm(x): OData V2: `Core.Links` watermark annotation has a `xmlns` attribute now. - for.seal: Remove unapplied extensions from CSN. - to.sql.migration: Handle `ALTER COLUMN` for columns with `NOT NULL` and a default value. ## Version 5.3.2 - 2024-10-08 ### Fixed - to.sql|hdi|hdbcds|effective: Handle subexpressions in conjunction with exists predicate. ## Version 5.3.0 - 2024-09-25 ### Added - compiler: + A warning is emitted if a string enum's values are longer than the specified length. + ON-condition rewriting has been improved and now supports secondary associations. - to.edm(x): Support optional action and function parameters in OData V4. The following rules apply: + A parameter declared `not null` without default value is mandatory. + A **function** parameter declared `null` without default value is mandatory. + An **action** parameter declared `null` without default value is optional as it is equivalent to `@Core.OptionalParameter { DefaultValue: null }`. + A parameter with a default value is optional and the default value is rendered as `@Core.OptionalParameter { DefaultValue: <value> }` regardless of its nullability. + `@Core.OptionalParameter: true` can be used to turn a mandatory parameter into an optional parameter (especially function parameters) and to signal an unspecified default value in the API if the parameter has no default clause. + `@Core.OptionalParameter: false` turns the creation of a `@Core.OptionalParameter: { Default: ... }` annotation off. + A default clause or `@Core.OptionalParameter: <bool>` have no effect on an explicit binding parameter. + Mandatory and optional **action** parameters may appear in any order. + Optional **function** parameters must not be followed by mandatory parameters. - to.edm: Forward `@OpenAPI {...}` into EDM Json with option `--odata-openapi-hints`. - cdsc: Option `--transitive-localized-views` was added. ### Fixed - CDL parser: Issue warning if annotation assignments have been written at an invalid position inside a type expressions. - CDL parser: Issue warning for arrayed parameter with default value. - to.cdl: Arrayed parameters with default values were not rendered correctly. ## Version 5.2.0 - 2024-08-27 ### Added - to.edm(x): Add `@Core.Links { rel: 'author', href: 'https://cap.cloud.sap' };` as watermark to lead schema. - to.sql.migration: Introduce option `script` to aid in generation of manual migration scripts by not aborting when encountering lossy changes. ### Changed - for.odata: No longer reject default values on action/function parameters. - to.edm(x): Raise warning for default values on action/function parameters that they are ignored. ### Fixed - compiler: Fix extensions with bound actions using an explicit binding parameter in `parseCdl` CSN. - for.odata, to.edm(x): Fix some issues with resolving annotation expressions in nested objects and reliably replace value of `=` attribute with `true` after processing. ## Version 5.1.2 - 2024-08-05 ### Fixed - compiler: In parseCdl mode, bound actions specifying the binding parameter with `$self` did not work. ## Version 5.1.0 - 2024-07-25 ### Added - cdsc: Option `--stdin` was added to support input via standard input, e.g. `cat file.cds | cdsc --stdin` - Allow to refer to draft state element `IsActiveEntity` via variable `$draft.IsActiveEntity` in annotation path expressions. + for.odata: During draft augmentation `$draft.IsActiveEntity` is rewritten to `$self.IsActiveEntity` for all draft enabled entities (root and sub nodes but not for named types or entity parameters). + to.edm(x): (V4 only) Allow to refer to an entity element in a bound action via `$self` and not only via explicit binding parameter in an annotation path expression. The API generator will prefix the path with the actual binding parameter name (explicit, annotation or default). ### Changed - Update OData vocabularies: 'Common', 'Core', 'HTML5', 'UI'. - to.cdl|hdbcds|hdi|sql: Remove `generated by` comment. ### Fixed - compiler: checks for associations now work for nested projections of the form `association.{ id }` - to.edm(x): No `Nullable` attribute for `$ReturnType` of `Collection(<entity type>)` [OData V4 CSDL, section 12.8 Return Type](https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_ReturnType) - to.sql|hdi|hdbcds: Detect and error on "cross-eyed" backlinks, where we cannot construct a valid on-condition. - to.sql|hdi.migration: Correctly detect that a view was dropped - this was previously just silently ignored. ## Version 5.0.6 - 2024-07-10 ### Fixed - for.seal: Don't generate DRAFT artifacts. ## Version 5.0.4 - 2024-06-26 ### Fixed - CDL parser: an `extend entity` and `extend aspect` with an extensions for the same element now correctly leads to an error, because it resulted in part of the extension being simply dropped. Remark: an `extend type` and the recommended plain `extend` led to an error in that situation already before. - to.sql: Conditions inside filters in combination with foreign key aliases were not properly translated in rare cases. - Update OData Vocabularies: 'PDF', 'UI'. ## Version 5.0.2 - 2024-06-14 ### Changed - API `CompilationError` will serialize the first compiler error in `e.message` - cdsc: `--without-hana-associations` is changed to `--with-hana-associations` ### Fixed - to.edm(x): + Respect `AppliesTo` specification in term definitions for actions and functions. + Make message `odata-spec-violation-namespace` a warning again. ## Version 5.0.0 - Pre-release version - 2024-05-29 This is a preview version for the major release and contains breaking changes. It should not be used for production. ### Changed - Node 18 is now the minimum required version. - API `CompilationError`s will no longer serialize all compiler messages into `e.message`. Use `e.messages[]` instead or `e.toString()` to serialize errors into a string. - CDL parser: Annotations that can't be applied are now rejected. - compiler: + `extend` statements on "namespaces" (paths that are not definitions) are now always errors. + non-structured events are rejected + `$self` references in JOINs are rejected if they could lead to issues in SQL rendering. + non-string enum definitions must have a value. + A top-level definition `$self` is rejected. `$self` is considered a reserved name. + `$at.from`/`$at.to` are deprecated; use `$valid.from`/`$valid.to` instead. - to.hdbcds: The HDBCDS backend is now considered deprecated. - to.edm(x): + Set default nullability to `true` for collection like properties (was `false` before). + Raise message ids `odata-spec-violation-namespace`, `odata-spec-violation-no-key` from warning to error. - to.sql: + `@cds.persistence.exists` is _not_ propagated to generated localization views (`localized.*`) + Option `fewerLocalizedViews` is now enabled by default. + Option `betterSqliteSessionVariables` is now enabled by default. ### Fixed - for.odata: Propagate all `@odata { Type, MaxLength, Precision, Scale, SRID }` to generated foreign keys. ### Removed - API: Deprecated functions `preparedCsnToEdmx` and `preparedCsnToEdm` were removed. Use `to.edm(x)` instead. ## Version 4.9.10 - 2025-04-29 ### Fixed - Added option `allowMixinInProjectionExtension` which allows referring to mixins in `extend projection`. This was forbidden in cds-compiler v4, but re-introduced in v5.5. Users wanting to migrate from cds-compiler v3 to v4 can use this option for easier migration. ## Version 4.9.8 - 2024-07-29 ### Fixed - compiler: Fix extensions with bound actions using an explicit binding parameter in `parseCdl` CSN. - to.edm(x): No `Nullable` attribute for `$ReturnType` of `Collection(<entity type>)` [OData V4 CSDL, section 12.8 Return Type](https://docs.oasis-open.org/odata/odata-csdl-xml/v4.01/odata-csdl-xml-v4.01.html#sec_ReturnType) ## Version 4.9.6 - 2024-07-15 ### Fixed - for.seal: Don't generate DRAFT artifacts. - for.odata: Propagate all `@odata { Type, MaxLength, Precision, Scale, SRID }` to generated foreign keys. - to.edm(x): Respect `AppliesTo` specification in term definitions for actions and functions. - to.sql: Conditions inside filters in combination with foreign key aliases were not properly translated in rare cases. ## Version 4.9.4 - 2024-05-21 ### Fixed - to.sql: + always include `tenant` column in foreign key references. + reject `tenantDiscriminator` option only if sql dialect is `hana` and if `withHanaAssociations` option is set. ## Version 4.9.2 - 2024-05-13 ### Fixed - compiler: Rewriting annotation expression paths in structures of projections has been improved. - to.edm(x): + Operator `/` represents `DivBy` operator, explicit `DivBy` is replaced with `Div` as integer division. - to.sql: consider all associations in tenant dependent entity for referential constraint generation ## Version 4.9.0 - 2024-04-25 ### Added - compiler: Annotations with expressions are now rewritten when propagated. - for.seal: Added API function that produces a CSN for SEAL. - for.odata/to.edm(x): Support annotation path expressions including path flattening. ### Changed - parser: A space between `.` and `*`/`{` (nested projections) is now a warning. Use `bin/cds_remove_invalid_whitespace.js` to automatically fix this warning. - compiler: + Published compositions with filters are changed to associations. + Expressions as annotation values are rejected for few known annotations that don't expect them. - Update OData vocabularies: 'Aggregation', 'Capabilities', 'Common', 'Hierarchy', 'PersonalData', 'Session', 'UI'. - to.edm(x): Exposed anonymous parameter types are now prefixed with `ap`, `bap` and `ep` for actions, bound actions and entities. ### Fixed - compiler: + Deprecated `$parameters` is no longer proposed in code completion. + Duplicate mixin definitions lead to failing name resolution. - to.cdl: Types were always rendered for associations with filters, even if it would lead to a compilation failure. - to.edm(x): + Fix a recursion bug in entity parameter handling. + Fix event exclusion in service preprocessing. ## Version 4.8.0 - 2024-03-21 ### Added - compiler: Type `cds.Vector` was added. It is mapped to `REAL_VECTOR` on SAP HANA. - Support associations to/from entities with parameters for SAP HANA SQL (hdi/direct). - to.sql/to.hdi: + SAP HANA keywords `ABSOLUTE`, `REAL_VECTOR`, and `ST_ASESRIJSON` are now included for smart quoting. + PostgreSQL keyword `SYSTEM_USER` is now included for smart quoting. - API: Added `to.sql.postgres.keywords` and `to.sql.h2.keywords`. They contain keywords for the respective SQL dialect. ### Changed - compiler: Overriding an included element must not change the type to an association if it wasn't an association before and vice versa. - Update OData vocabularies: 'Authorization', 'Common', 'UI'. ### Fixed - compiler: `cast()`s to structured types and associations are now rejected. They could lead to crashes before. - to.edm(x): + Reject action/function return types that are declared `many of many`. + Render user defined annotation type `cds.Integer` as `Edm.Int`. - to.sql|hdi|hdbcds: + Correctly handle `.list` during flattening. + Improve handling of `.items`. - to.sql|hdi.migration: + Turn types and aspects into dummies to reduce CSN size. + Correctly detect a removed `.default` and forcefully set the default to `null`. ## Version 4.7.6 - 2024-02-29 ### Fixed - OData: Restored compatibility with the Java runtime. Drafts generation was applied twice. ## Version 4.7.4 - 2024-02-27 ### Fixed - OData: Fixed infinite recursion in draft handling for nested recursive compositions. ## Version 4.7.2 - 2024-02-26 ### Fixed - Restored compatibility with `@sap/cds-dk` for Java runtime. ## Version 4.7.0 - 2024-02-23 ### Added - compiler: Virtual elements can now be referenced in expressions in annotation. ### Changed - Update OData vocabularies: 'Authorization', 'Common', 'Hierarchy', 'UI'. - to.edm(x): `@cds.odata.valuelist` renders all non-key elements of the value help list as `ValueListProperty`. ### Fixed - CDL parser: a `select` after two or more `(`s in an expression or condition could cause some constructs in that query, such as `virtual`, to be not properly parsed. - compiler: published associations with filters sometimes had the filter applied twice if used in inline aspect compositions - to.sql|hdi|hdbcds[.migration]: + With `withHanaAssociations`: `false`, remove the association elements from the final CSN in order to correctly detect them during migration scenarios and with generated `hdbcds`. + Skip expensive processing (for calculated elements and nested projections) if the model doesn't use it. + Don't greedily set alias on subqueries if not required. + Remove bound actions and turn all non-database relevant artifacts into dummies to simplify and shrink CSN. ## Version 4.6.2 - 2024-02-02 ### Fixed - compiler: Fix incorrect error about type properties if deprecated flag `ignoreSpecifiedQueryElements` is set. - Update OData vocabularies: 'Authorization', 'Common'. ## Version 4.6.0 - 2024-01-26 ### Added - compiler: Events can now be projections on other structured events and types. - to.cdl: `parseCdl` and `gensrc` style CSN (a.k.a. `inferred` and `xtended`) is now supported as input. ### Changed - Update OData vocabularies: 'Aggregation', 'Validation' - to.sql/hdi/hdbcds: Removed warnings for number and type of keys in draft-enabled entities. ### Fixed - compiler: + ON-conditions of associations with filters in calculated elements were incorrectly rewritten when included in other entities, and the filter was applied twice in some scenarios. + redirecting an association with filter did not rewrite paths relative to the redirection target. + Unknown type references with an explicit named type argument such as `Unknown(length: 10)` crashed. - to.edm(x): + `@Core.IsURL` is not rendered in combination with `@Core.MediaType` (V4 only). + No 'odata-navigation' warning for association targets annotated with `@cds.autoexpose: false`. + No empty annotation in API, when a non-existent base annotation is annotated (eg. `@Common.Label.@Core.Description` without `@Common.Label`). + Don't crash if value for `$Type` is not a string. + Generated foreign keys of type `cds.UUID` that are also primary key are not annotated with `@Core.ComputedDefaultValue`. This is a follow up correction to [4.5.0](#version-450---2023-12-08) ## Version 4.5.0 - 2023-12-08 ### Added - compiler/parser + Annotations can have any expressions as value, like `@Anno: ( ref + 1 )`. References are checked to be valid element references, inherited values might become invalid due to element renaming. This feature is still experimental, and might not be supported by all backends or runtimes at the moment. + A single `annotate` statement can now be used to annotate parameters, elements and bound actions in one statement. - to.edm(x): Key elements of type `cds.UUID` are annotated with `@Core.ComputedDefaultValue` if they are defined directly in the entity. Elements of type `cds.UUID` that are defined in a named structured type and used to define a key element are not annotated, instead a warning is raised if such elements are not annotated with `@Core.ComputedDefaultValue`. - to.sql|hdi: Add option `withHanaAssociations` which, for sqlDialect `hana`, allows suppressing the generation of the `WITH ASSOCIATIONS`. ### Changed - Update OData Vocabulary: 'Common'. - api: Reject CSN as input in backends, if it is a CSN in flavor `parsed` with a non-empty `requires` array. Reason being that the model is not considered a "full" CSN, as dependencies were not resolved. ### Fixed - compiler: + Fix false positives of cyclic dependencies for calculated elements. + Fix cardinality on source associations when publishing them with a filter (+ different cardinality) in a projection. The cardinality was incorrectly changed on the source as well. - CDL parser: + More numbers that would lose relevant digits due to precision loss are stored as strings in CSN (i.e. `{ "literal":"number", "val": "1.0000000000000001" }`). + Nested table expressions and queries in the FROM clause (with surrounding parentheses) could cause some constructs such as `virtual` to be not properly parsed. - to.hdi.migration: Don't drop-create the primary key when only a doc-comment has changed. - to.cdl: Fix edge case where `@A.![B#]` was not rendered correctly. ### Removed - to.edm(x): Remove option `--odata-open-type` introduced with [4.4.0](#version-440---2023-11-09). ## Version 4.4.4 - 2023-11-24 ### Fixed - to.hdi.migration: Changes in only `doc`-comments should not result in a drop-create of the primary key. ## Version 4.4.2 - 2023-11-17 ### Fixed - for.odata: Fix crash when using a projection with associations as action parameter type. - to.edm(x): `Edm.AnyPropertyPath` is hard to `Edm.PropertyPath`. As there is no dynamic path evaluation, `Edm.NavigationPropertyPath` must be enforced via `$edmJson`. `Edm.AnyPropertyPath` has been used in `@Aggregation.ApplySupported.GroupableProperties` for the first time after vocabulary update with [4.4.0](#version-440---2023-11-09). ## Version 4.4.0 - 2023-11-09 ### Added - compiler: International letters such as `ä` can now be used in CDS identifiers without quoting. Unicode letters similar to JavaScript are allowed. - to.edm(x): + Allow to render all complex types within a requested service as `OpenType=true` with option `--odata-open-type`. Explicit `@open: false` annotations are not overwritten. + Allow to annotate the generated draft artifacts but not generated foreign keys (as with any other managed association). - to.sql|hdi|hdbcds: Allow annotating the generated `.drafts` tables. ### Changed - CDL parser: improve error recovery inside structured annotation values - Update OData vocabularies: 'Aggregation', 'Common', 'Core', 'Hierarchy', 'ODM', 'UI'. ### Fixed - parser: + `/**/` was incorrectly parsed as an unterminated doc-comment, leading to parse errors. + Doc-comments consisting only of `*` were not correctly parsed. - compiler: do not propagate `default`s in a CSN of flavor `xtended`/`gensrc`. - to.hana: Fix various bugs in association to join translation. Support `$self` references in filter expressions. - to.edm(x): Omit `EntitySet` attribute on `Edm.FunctionImport` and `Edm.ActionImport` that return a singleton. - to.sql|hdi.migration: Improve handling of primary key changes - detect them and render corresponding drop-create. ## Version 4.3.2 - 2023-10-25 ### Fixed - compiler: Fix auto-exposure of composition target entities inside anonymous composition target aspects. - to.hana: Fix a bug in association to join translation, expect ON condition operand to be a function without arguments. ## Version 4.3.0 - 2023-09-29 ### Added - compiler: it is possible to publish associations with filters in views. Managed associations become unmanaged ones. For example: ```cds entity Proj as projection on Base { assoc[id = 1], }; ``` ### Changed - Update OData vocabularies: 'Aggregation', 'Capabilities', 'Common', 'PDF', 'PersonalData', 'UI'. ### Fixed - parser: Chained methods without arguments such as `b` in `a().b.c()` were lost. - compiler: + Type arguments in `cast()` functions, whose column also has an explicit type set, were not properly checked. Now the `cast()`s type and type arguments are checked. + SQL function `STDDEV(*)` was not parsable. + In views, published association's ON-conditions containing `$projection` are now rewritten to `$self` in the CSN `elements` property. This ensures recompilability of the CSN. ## Version 4.2.4 - 2023-09-14 ### Fixed - OData: For compatibility with the Java runtime, don't prepend table aliases to column aliases unless necessary. ## Version 4.2.2 - 2023-08-31 ### Fixed - to.sql|hdi.migration: Fix bug that caused a migration to be rendered for the HANA CDS types that were removed from the CSN ## Version 4.2.0 - 2023-08-29 ### Added - Compiler: + Option `moduleLookupDirectories: [ 'strings' ]` can be used to specify additional module lookup directories, similar to `node_modules/`. + LIMIT and OFFSET clauses can now contain expressions, including parameter references. - to.edm(x): + Detect spec violation `scale` > `precision`. - to.sql/for.odata: + With the new option `fewerLocalizedViews: true|false`, an entity/view will not get a localized convenience view, if it only has associations to localized entities/views. Only if there is actually a localized element (e.g. new localized element or reference to one), will it get a convenience view. - to.sql + In a localized scenario, create foreign key constraints for the generated `.texts` entities. + Casting `null` to a structure such as `null as field : StructT` is now supported. For each leaf element, an additional `null as field_name` column is added. ### Changed - Compiler: + Selecting fields of structures or associations (without filters) are now candidates for ON-condition rewrites: It is no longer necessary to select the struct/association directly. + Consistently handle the case when type elements are defined to be a `key`: the `key` property is not only preserved with `includes`, but also in other cases. Use option `deprecated.noKeyPropagationWithExpansions` to switch to the v3 behavior. + When including aspects or entities into structured type definitions, do not add actions to the type. + An `annotate` statement in the `extensions` section of a CSN now consistently uses the `elements` property even if the `annotate` is intended to be used for an enum symbol. Before v4.2, the compiler has used the `enum` property in a CSN of flavor `xtended` (`gensrc`) if it was certain that it was to be applied to an enum symbol. - to.cdl: If a definition has an `actions` property, an `actions {…}` block is now always rendered, and is not ignored if empty. - to.sql: + For SQL dialect "sqlite", `cds.DateTime` is now rendered as `DATETIME_TEXT` instead of `TIMESTAMP_TEXT`. + Casting a literal (except `null`) to a structure now yields a proper error. + `.texts` entities annotated with `@cds.persistence.skip` (without their original entity having that annotation) lead to deployment issues later. It is now an error. ### Fixed - Compiler: + Reject invalid reference in the `on` of `join`s already while compiling, not just when calling the (SQL) backend. + Correct the calculation of annotation assignments on the return structure of actions when both `annotate … with {…}` and `annotate … with returns {…}` had been used on the same structure element. Ensure that it works when non-applied, too. + Do not remove or invent `actions` properties with zero actions or functions in it. + Correct auto-redirection of direct cycle associations: if the source and target of a model association are the same entity, and the main artifact of the service association based on the model association is a suitable auto-redirection target, then use it as new target, independently from the value of `@cds.redirection.target`. - to.cdl: Indirectly structured types (`type T: Struct;`) with `includes` (`extend T with T2;`), are now properly rendered. - to.sql/hdi/hdbcds: + Views on views with parameters did not have localized convenience views based on other localized views (missing `localized.` prefix in FROM clause) + Run less checks on entities marked with `@cds.persistence.exists` + Correctly render SELECT items where the column name conflicts with a table alias - to.sql: Casting expressions to a structured type yields a proper error instead of strange compiler error. - to.edm(x): + Don't expand `@mandatory` if element has an annotation with prefix `@Common.FieldControl.`. + Fix a bug when referencing nested many structures, especially referring to a managed association via `$self` comparison. + Improve handling of non-collection annotation values for collection-like vocabulary types. + Don't render `Scale: variable` for `cds.Decimal(scale:0)`. - to.sql|hdi.migration: + Fixed a bug that caused rendering of `ALTER` statements to abort early and not render some statements. + CSN output now only contains real `cds` builtins, no early remapping to HANA CDS types or similar. - to.sql.migration: Don't drop-create views marked with `@cds.persistence.exists` ### Removed ## Version 4.1.2 - 2023-07-31 ### Fixed - to.hdi.migration: Changes in constraints are not rendered as part of the .hdbmigrationtable file, as they belong in other HDI artifacts ## Version 4.1.0 - 2023-07-28 ### Added - Calculated elements "on-read" can now reference localized elements. - Aliases for columns inside sub-queries are now optional, also for expressions. - for.odata/to.hdi/to.sql: Specified default value on a managed association is forwarded to a foreign key if association has exactly one foreign key. - CDL: Annotation-only aspects having no `elements` and `actions` can now be defined with the CDL syntax `@Anno… aspect Name;`. They cannot be extended with elements or actions in order to ensure that they can always be used to extend non-structures. To allow the former but not the latter, use `@Anno… aspect Name {…};`. - to.sql: Support session variables for h2 ### Changed - api: Function `isInReservedNamespace(name)` handles name `cds` as being in a reserved namespace as well. - `CompilationError.messages` are now sorted severity aware. Errors are listed first. - Compiler: + Improve the calculation of semantic code completion candidates. + Some checks, like those for valid `on` conditions of associations, are now already done with `compile` and not just the backends. + SQL `cast()`s must always have a `type` property + Type properties such as `precision` or `length` must be accompanied by a type (possibly inferred). - for.odata/to.hdi/to.sql: No longer reject unmanaged associations as foreign keys of a managed association. Instead, ignore such references during ON-condition rewriting and foreign key generation. Referring to unmanaged associations is incompatible with SAP HANA CDS naming mode 'hdbcds'. - to.sql: Rework session variables for postgres. - Update OData vocabularies: 'Common', 'HTML5', 'PersonalData', 'UI'. ### Fixed - Compiler: + ensure that annotations of elements in anonymous aspects of managed compositions are not lost. + issue error for definitions like `entity Self as projection on Base { $self.* };` instead of simply concluding that the projection has zero elements. + do not report a invalid cyclic dependency if associations between two entities are valid cycles. + Element type references can again follow associations (removed v4.0 incompatibility). - to.sql: + `$self` references inside a nested projection using `$self` was incorrectly resolved. + associations to entities marked with `@cds.persistence.skip` were not properly checked inside nested projections. + Select items casting `null` to an arrayed type work again, e.g. `null as ManyType`. - to.sql/hdi/hdbcds: Raise a nice error message for `@sql.append` on managed associations/compositions, as we do for structured error messages. - to.cdl: Annotations with multiple qualifiers (`#`) are now rendered correctly. - to.edm(x): Revert change introduced with [3.9.0](#version-390---2023-04-20) "Correct referential constraint calculation for `[0..1]` backlink associations". - for.odata: Process shortcut annotations sequence independent. - to.sql.migration: + Respect unique and referential constraints for delta calculation. + Added a configurable error for primary key additions, as those will lead to errors if the table contains data. This could lead to inconsistent states if some deployments succeed and others fail, so by default it is an error. ### Removed - Compiler: + forbid wildcards in projection extensions: `extend … with columns { * )`. + forbid column references such as `$user.*`, `$user.{id}` and `$user {id}`. ## Version 4.0.2 - 2023-06-22 ### Fixed - to.sql.migration: When drop-creating views, also drop-create (transitively) dependent views. - to.edm(x): + Forward `@odata.singleton { nullable }` annotation to parameter entity. + Annotations assigned to a parameterized entity are propagated to the parameter entity if the annotation is applicable to either an `edm.EntitySet` or `edm.Singleton`. This especially covers all `@Capabilities` and their shortcut forms like `@readonly` and `@insertonly`. The original annotation is not removed from the original entity. Annotations that should be rendered at the parameter `edm.EntityType` can be qualified with `$parameters`. Explicitly qualified annotations are removed from the original entity allowing individual assignments. ## Version 4.0.0 - 2023-06-06 ### Added - Calculated elements "on-write" are now supported, e.g. `elem = field + 1 stored;` will be rendered in SQL as `GENERATED ALWAYS AS`. - compiler: + `returns` of actions and functions can now be annotated, e.g. ```cds action A() returns @direct { … }; annotate A with returns { @anno val; } ``` + It is now possible to use `*/` inside doc comments by escaping it `*\/`. Only this exact string can be escaped. + Functions `parse.expr` and `parse.cql` now support `group by`, `having`, `order by`, `limit`, and `offset` in infix filters. + In expressions, you can now use function names after the `new` keyword which do not start with `st_`, if the name is followed by an open parenthesis. ### Changed - API: + `messageContext()` is now deprecated; use `messageStringMultiline()` instead with `config.sourceMap`. + `messageString(err, config)` has a new signature; the old one is still supported for backward compatibility. + Option `docComment: false` now removes doc comments during compilation even for CSN. If this option is not defined, doc comments are checked, but not put into CSN. - compiler: + CSN: Specified elements of queries are now resolved and checked (previously ignored except for annotations). Type properties (`length`, …) and some element properties are now taken from the specified elements instead of relying only on the elements inferred by the compiler. + CSN: Compiler accepts CSN input with CSN version `0.1.0` (produced by cds-compiler version 1.10.0 and older) only if the version attribute is properly set, i.e. `"version": {"csn": "0.1.0"}`. + CSN: Type properties (`length`, `precision`, `scale`, and `srid`) next to `elements` or `items` in CSN input is now an error. Previously ignored. + An extension of the form `extend Def with { name = 42 };` is now represented in parsed CSN as adding a calculated element. + `having` as the first word in an infix filter is now interpreted as keyword. Write `![having]` to have it parsed as identifier. + If a definition overrides elements of an included definition, it is sorted according to the included definition's element order. This is similar to how `*` works in projections. It is no longer possible to overwrite a scalar element with a structure and vice versa. + Two included definitions cannot have the same element. The including entity must override the element. + If a type with properties precision and scale is extended, the `extend` statement must extend both properties. + `annotate E:elem with actions {};` is now a parser error and no longer a compiler error. Only relevant if you use `parseCdl`-style CSN. + Annotations (and other properties) are now propagated to `returns` as well, if the returned artifact is a non-entity, e.g. a type. + `annotate E with returns {…}` is now only applied to actions/functions. Previous compiler versions autocorrected the `annotate` statements to apply them to an entity's elements. + Calculated elements can't refer to localized elements. + Table aliases can't be used in `extend Query with columns {…}` any longer. Use direct element references instead. + Table alias and mixin names can no longer start with `$`. Choose a different name. With this change we avoid unexpected name resolution effects in combination with built-in `$`-variables. + A semicolon is now required after a type definition like `type T : many {} null`. + Message ID `duplicate-autoexposed` was changed to `def-duplicate-autoexposed`. + Bare `$projection` are rejected. Use `$self` instead. - Update OData vocabularies 'Common', 'UI'. - to.sql: + Change default `length` for `cds.String` for all SQL dialects except `hana` to 255. + for the sql dialect `postgres`, the `ON DELETE RESTRICT` / `ON UPDATE RESTRICT` rules are omitted from the referential constraint definitions. - to.cdl: + If associations are used inside `items`, an error is emitted instead o