@sap/cds 6.4.1 → 6.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/CHANGELOG.md +79 -6
  2. package/README.md +5 -0
  3. package/apis/cqn.d.ts +14 -3
  4. package/apis/ql.d.ts +8 -8
  5. package/apis/services.d.ts +37 -65
  6. package/apis/test.d.ts +7 -0
  7. package/bin/build/buildTaskEngine.js +9 -14
  8. package/bin/build/buildTaskFactory.js +1 -1
  9. package/bin/build/buildTaskHandler.js +3 -14
  10. package/bin/build/index.js +8 -2
  11. package/bin/build/provider/buildTaskProviderInternal.js +18 -13
  12. package/bin/build/provider/fiori/index.js +5 -10
  13. package/bin/build/provider/hana/2migration.js +11 -2
  14. package/bin/build/provider/hana/index.js +17 -14
  15. package/bin/build/provider/hana/template/.hdiconfig-hanacloud +137 -0
  16. package/bin/build/provider/hana/template/package.json +3 -0
  17. package/bin/build/provider/mtx/resourcesTarBuilder.js +12 -3
  18. package/bin/build/provider/mtx-extension/index.js +57 -37
  19. package/bin/build/provider/mtx-sidecar/index.js +1 -1
  20. package/bin/build/util.js +18 -1
  21. package/bin/cds.js +1 -5
  22. package/bin/deploy/to-hana/hana.js +10 -3
  23. package/bin/serve.js +36 -20
  24. package/common.cds +7 -0
  25. package/lib/auth/jwt-auth.js +8 -7
  26. package/lib/compile/for/lean_drafts.js +55 -6
  27. package/lib/compile/minify.js +3 -3
  28. package/lib/dbs/cds-deploy.js +18 -17
  29. package/lib/env/cds-requires.js +1 -1
  30. package/lib/env/defaults.js +5 -1
  31. package/lib/env/schemas/cds-rc.json +74 -3
  32. package/lib/index.js +4 -2
  33. package/lib/lazy.js +6 -8
  34. package/lib/log/cds-error.js +2 -2
  35. package/lib/ql/Whereable.js +22 -11
  36. package/lib/ql/cds-ql.js +1 -1
  37. package/lib/req/cds-context.js +3 -3
  38. package/lib/req/response.js +8 -3
  39. package/lib/req/user.js +12 -2
  40. package/lib/srv/bindings.js +1 -2
  41. package/lib/srv/cds-serve.js +2 -1
  42. package/lib/srv/middlewares/trace.js +31 -15
  43. package/lib/srv/protocols/odata-v2-proxy.js +8 -8
  44. package/lib/srv/srv-handlers.js +26 -7
  45. package/lib/srv/srv-methods.js +2 -2
  46. package/lib/srv/srv-models.js +8 -3
  47. package/lib/utils/cds-test.js +7 -5
  48. package/lib/utils/cds-utils.js +3 -1
  49. package/lib/utils/tar.js +6 -3
  50. package/libx/_runtime/auth/strategies/JWT.js +1 -0
  51. package/libx/_runtime/auth/strategies/ias-auth.js +3 -2
  52. package/libx/_runtime/auth/strategies/mock.js +12 -1
  53. package/libx/_runtime/auth/strategies/xssecUtils.js +7 -8
  54. package/libx/_runtime/auth/strategies/xsuaa.js +1 -0
  55. package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +6 -2
  56. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +1 -2
  57. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +26 -1
  58. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +8 -0
  59. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/ExpressionToCQN.js +1 -1
  60. package/libx/_runtime/cds-services/adapter/odata-v4/odata-to-cqn/readToCQN.js +11 -2
  61. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/PrimitiveValueDecoder.js +8 -8
  62. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/ValueConverter.js +1 -1
  63. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/validator/ValueValidator.js +14 -14
  64. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/deserializer/DeserializerFactory.js +1 -0
  65. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/serializer/ResourceJsonSerializer.js +3 -0
  66. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/utils/UriHelper.js +2 -1
  67. package/libx/_runtime/cds-services/adapter/odata-v4/utils/metaInfo.js +3 -2
  68. package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +7 -0
  69. package/libx/_runtime/cds-services/adapter/odata-v4/utils/stream.js +0 -3
  70. package/libx/_runtime/cds-services/services/Service.js +11 -19
  71. package/libx/_runtime/cds-services/services/utils/columns.js +42 -40
  72. package/libx/_runtime/cds-services/util/assert.js +7 -1
  73. package/libx/_runtime/common/code-ext/WorkerReq.js +81 -0
  74. package/libx/_runtime/common/code-ext/config.js +13 -0
  75. package/libx/_runtime/common/code-ext/execute.js +113 -0
  76. package/libx/_runtime/common/code-ext/handlers.js +49 -0
  77. package/libx/_runtime/common/code-ext/worker.js +40 -0
  78. package/libx/_runtime/common/code-ext/workerQuery.js +45 -0
  79. package/libx/_runtime/common/code-ext/workerQueryExecutor.js +36 -0
  80. package/libx/_runtime/common/composition/data.js +5 -2
  81. package/libx/_runtime/common/composition/tree.js +2 -0
  82. package/libx/_runtime/common/generic/auth/restrict.js +1 -1
  83. package/libx/_runtime/common/generic/crud.js +4 -0
  84. package/libx/_runtime/common/generic/etag.js +3 -1
  85. package/libx/_runtime/common/generic/input.js +12 -14
  86. package/libx/_runtime/common/i18n/index.js +1 -1
  87. package/libx/_runtime/common/utils/cqn2cqn4sql.js +47 -22
  88. package/libx/_runtime/common/utils/path.js +5 -26
  89. package/libx/_runtime/common/utils/search2cqn4sql.js +16 -9
  90. package/libx/_runtime/common/utils/templateProcessorPathSerializer.js +19 -13
  91. package/libx/_runtime/db/data-conversion/post-processing.js +1 -1
  92. package/libx/_runtime/db/expand/expandCQNToJoin.js +7 -4
  93. package/libx/_runtime/db/expand/rawToExpanded.js +3 -2
  94. package/libx/_runtime/db/generic/input.js +2 -2
  95. package/libx/_runtime/db/generic/integrity.js +1 -0
  96. package/libx/_runtime/db/generic/virtual.js +1 -0
  97. package/libx/_runtime/db/query/read.js +3 -2
  98. package/libx/_runtime/db/utils/localized.js +1 -1
  99. package/libx/_runtime/fiori/generic/activate.js +7 -1
  100. package/libx/_runtime/fiori/generic/before.js +9 -1
  101. package/libx/_runtime/fiori/generic/edit.js +8 -1
  102. package/libx/_runtime/fiori/generic/new.js +2 -0
  103. package/libx/_runtime/fiori/generic/patch.js +2 -0
  104. package/libx/_runtime/fiori/generic/prepare.js +2 -0
  105. package/libx/_runtime/fiori/generic/read.js +16 -5
  106. package/libx/_runtime/fiori/generic/readOverDraft.js +2 -0
  107. package/libx/_runtime/fiori/lean-draft.js +505 -241
  108. package/libx/_runtime/fiori/utils/delete.js +2 -0
  109. package/libx/_runtime/hana/customBuilder/CustomSelectBuilder.js +5 -5
  110. package/libx/_runtime/hana/pool.js +1 -1
  111. package/libx/_runtime/hana/search2cqn4sql.js +51 -51
  112. package/libx/_runtime/messaging/Outbox.js +1 -1
  113. package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +1 -0
  114. package/libx/_runtime/messaging/enterprise-messaging.js +2 -6
  115. package/libx/_runtime/messaging/file-based.js +1 -2
  116. package/libx/_runtime/messaging/outbox/OutboxRunner.js +1 -1
  117. package/libx/_runtime/messaging/outbox/utils.js +1 -1
  118. package/libx/_runtime/messaging/service.js +0 -1
  119. package/libx/_runtime/remote/Service.js +1 -0
  120. package/libx/_runtime/sqlite/convertDraftAdminPathExpression.js +19 -3
  121. package/libx/_runtime/sqlite/customBuilder/CustomExpressionBuilder.js +0 -18
  122. package/libx/_runtime/sqlite/customBuilder/CustomFunctionBuilder.js +0 -18
  123. package/libx/_runtime/sqlite/customBuilder/CustomSelectBuilder.js +0 -24
  124. package/libx/_runtime/sqlite/customBuilder/CustomUpsertBuilder.js +2 -1
  125. package/libx/_runtime/sqlite/customBuilder/index.js +47 -32
  126. package/libx/odata/afterburner.js +23 -8
  127. package/libx/odata/cqn2odata.js +1 -1
  128. package/libx/odata/grammar.pegjs +3 -4
  129. package/libx/odata/index.js +5 -1
  130. package/libx/odata/parseToCqn.js +3 -3
  131. package/libx/odata/parser.js +1 -1
  132. package/libx/odata/utils.js +58 -1
  133. package/libx/rest/middleware/parse.js +26 -4
  134. package/package.json +1 -1
  135. package/server.js +1 -1
  136. package/libx/_runtime/sqlite/customBuilder/CustomDeleteBuilder.js +0 -17
  137. package/libx/_runtime/sqlite/customBuilder/CustomReferenceBuilder.js +0 -11
  138. package/libx/_runtime/sqlite/customBuilder/CustomUpdateBuilder.js +0 -17
  139. /package/bin/build/provider/hana/template/{.hdiconfig → .hdiconfig-haas} +0 -0
package/CHANGELOG.md CHANGED
@@ -4,24 +4,95 @@
4
4
  - The format is based on [Keep a Changelog](http://keepachangelog.com/).
5
5
  - This project adheres to [Semantic Versioning](http://semver.org/).
6
6
 
7
+ ## Version 6.6.0 - 2023-02-27
8
+
9
+ ### Added
10
+
11
+ - Improved error handling for `cds build` if the SaaS base model is missing in an extension project.
12
+ - Support for reliable paging using `$skiptoken`. Can be activated via `cds.query.limit.reliablePaging = true`
13
+
14
+ ### Changed
15
+
16
+ - `cds.serve(ServiceName)` (and `cds serve -s ServiceName`) now exactly serve services with the given names. Previously, all services that ended with the given name were served as well, e.g. `MyServiceName` and `ServiceName`, which might be problematic for applications that bootstrap services one by one.
17
+ - Optimize `@cds.persistence.journal` filtering for `last-dev` CSN file.
18
+ - `process.exit()` is no longer called during server shutdown, so that other/custom exit handlers get a chance to execute.
19
+
20
+ ### Fixed
21
+
22
+ - `cds deploy --to hana` no longer calls `cds bind` when `VCAP_SERVICES` is provided, e.g via `default-env.json`.
23
+ - `$search` on an entity without String elements
24
+ - Only elements from type `cds.String` are searchable when combining `$apply` and `$search`
25
+ - Error message for missing database connection in draft case
26
+ - Extensibility with in-memory Sqlite
27
+ - OData adapter error messages
28
+ - Columns in navigation path are now added to the SELECT.columns in new parser
29
+ - Application service calls on draft enabled entities using aliases
30
+ - Custom mtxs build tasks now use the correct default `src` folder value.
31
+ - `cds build` adds a `.hdiconfig` file when creating HANA migration tables if none is existing.
32
+ - UPSERTs using reserved keywords
33
+ - Fix outbound-streaming error handling
34
+ - Rollback transaction if inbound streaming fails
35
+ - Custom database initialization in `db/init.js` now skips the `t0` tenant for multitenant apps.
36
+ - Concurrent etag calculation for UPDATE and DELETE
37
+ - Typings for `cds.delete()`
38
+ - CQN for `not` operator with OData functions
39
+ - Expand on composition of aspect for draft enabled entities
40
+ - Better error messages are provided for errors with HTTP status code `400`, `500` and `501`
41
+
42
+ ## Version 6.5.0 - 2023-01-27
43
+
44
+ ### Added
45
+
46
+ - New aspect `sap.common.TextsAspect` in common.cds
47
+ - New syntax for collection bound entities
48
+
49
+ ### Changed
50
+
51
+ - Successive calls to `SELECT.where()` wraps existing clause in brackets if it contains `or`. E.g.
52
+ ```js
53
+ SELECT.from `X` .where `x` .or `y` .where `z`
54
+ //> SELECT from X where (x or y) and z`
55
+ ```
56
+ - `cds build` for HANA now adds an `engines.node` version to the generated `db/package.json`. This will help in the future when runtime environments change their default to some version higher than the one supported by `@sap/hdi-deploy`.
57
+ - `cds build` checks the consistency of built-in models for java projects. An error is logged if some model files could not successfully be resolved indicating that a required npm module might be missing.
58
+ - Status code of draft actions are set in respective handler instead of protocol adapter
59
+ - `cds deploy --dry` no longer loads the `sqlite3` module by mistake. This fixes a regression when building Java projects. As a side effect a file with the name `undefined` was created in the project root folder.
60
+ - Internal representation of pseudo roles `internal-user` and `system-user`
61
+
62
+ ### Fixed
63
+
64
+ - Resolve i18n folders from the root directory
65
+ - Types for `cds.test`
66
+ - Types for `srv.send`
67
+ - Optimized Search: Search queries for localized entities will now use default values, if no localized data is found in the corresponding localized tables on SAP HANA. Correct aliasing by search queries with navigation.
68
+ - Resolution of `type of` references during minify in bootstrap
69
+ - Generation of odata-v2 URL in case of select=* in `urlify()`
70
+ - Build resets changed `cds.env` and `cds.root` when finished
71
+ - Expand error when using infix filters
72
+ - CDS configuration schema validation for `@sap/cds-mtxs`
73
+ - Typings for QL API
74
+ - Return types of asynchronous service API
75
+
7
76
  ## Version 6.4.1 - 2022-01-16
8
77
 
9
78
  ### Fixed
10
79
 
11
80
  - `cds build` correctly creates a `resources.tgz` file for MTXS projects on Windows
12
- - `cds.deploy` for HANA now doesn't try to search for a globally installed `@sap/hdi-deploy` if there's no `npm` installed, e.g. on a Node.js server without `npm`.
81
+ - `cds.deploy` for HANA now doesn't try to search for a globally installed `@sap/hdi-deploy` if there's no `npm` installed, e.g. on a Node.js server without `npm`
13
82
  - Signature for `cds.ql.UPSERT`
14
83
  - Signature for `<srv>.delete().where()`
15
84
  - Signature for `SELECT.alias`
16
85
  - `UPSERT` requests for SQLite if only keys are provided
17
- - `cds.test` doesn't log database resets with `autoReset` enabled any more.
18
- - The `cds.deploy` output for HANA is now correctly formatted in Kibana.
86
+ - `cds.test` doesn't log database resets with `autoReset` enabled any more
87
+ - The `cds.deploy` output for HANA is now correctly formatted in Kibana
19
88
  - SAP HANA stored procedures containing implicit selects
20
89
  - Shorthand configuration for `graphql` in `cds.env.protocols`
21
90
  - If `cds.env.protocols` is set, `cds.requires.middlewares` is automatically turned on
22
91
  - `cds.context` middleware is split to initial handling of request correlation and user propagation
23
92
  - fix view resolving and managed data for UPSERT
24
93
  - `cds.linked` supports polymorphic self links like in: `action foo( self: [many] $self, ...)`
94
+ - Error with `@odata.draft.enabled` and `@restrict`
95
+ - Skip mandatory check on navigation properties for write requests
25
96
 
26
97
  ## Version 6.4.0 - 2022-12-15
27
98
 
@@ -33,11 +104,12 @@
33
104
  - `persistent-outbox`: Support for parallel processing with option `parallel: true` as well as pluggable processor functions through `service.outbox.process` (beta)
34
105
  - `cds version` now also lists packages with `@cap-js/` prefix from dependencies
35
106
  - `cds.context.http` is now available for webhook-based requests
36
- - `cds build` for HANA migration tables now only saves model entities annotated with `@cds.persistence.journal` as `last-dev` version.
107
+ - `cds build` for SAP HANA migration tables now only saves model entities annotated with `@cds.persistence.journal` as `last-dev` version.
37
108
  - `cds deploy` now uses the `VCAP_SERVICES` environment variable (if set), and skips `cf` operations in this case
38
109
 
39
110
  ### Changed
40
111
 
112
+ - Added several missing signatures in CQN types that are now in accordance with the current documentation.
41
113
  - `.columns(…)` of both `cql.SELECT` and `cql.INSERT` give improved code completion when paired when appropriate type definitions are present
42
114
  - Status code of error messages caused by empty `not null` fields is changed from `400` to `500` on database layer. Note, that as result the error message `Value is required` in production will be replaced by `Internal server error` in the HTTP response.
43
115
  - Underscores in environment variables can now be escaped by two `__` to set keys in `cds.env`. For example, use `CDS_FEATURES_WITH__MOCKS=...` to set `features.with_mocks`. Note that previously, this ended up as `features: { with_: { mocks:... }}`, so in rare cases, it might yield unexpected results.
@@ -68,6 +140,7 @@
68
140
  - Quoting of keys typed as `cds.String` in error targets. Error targets are a relative resource path to correlate error
69
141
  messages with the corresponding text input filed in the UI in an OData HTTP error response body for errors, warnings,
70
142
  and info messages. For example:
143
+ - Error with `GET` on `actions`
71
144
 
72
145
  ```diff
73
146
  HTTP/1.1 400 Bad Request
@@ -88,8 +161,8 @@ Content-Length: 145
88
161
  ```
89
162
 
90
163
  - Application crash if batched Uri uses invalid percent encoding
91
- - `cds build` for HANA no longer produces `hdbtabledata` for csv files that refer to non-existing entities. This can be the case for imported content packages that bring csv files for entities that are not used in the application model.
92
- - `cds build` for HANA now gives precedence for csv files from application layer. This is important for imported content packages that bring csv files that shall be overwritten in the application layer.
164
+ - `cds build` for SAP HANA no longer produces `hdbtabledata` for csv files that refer to non-existing entities. This can be the case for imported content packages that bring csv files for entities that are not used in the application model.
165
+ - `cds build` for SAP HANA now gives precedence for csv files from application layer. This is important for imported content packages that bring csv files that shall be overwritten in the application layer.
93
166
  - `cds build` for Java no longer adds the service `cds.xt.MTXServices` to the application model.
94
167
  - `cds build` no longer fails when creating large resource TAR archives for MTXS projects.
95
168
 
package/README.md CHANGED
@@ -4,5 +4,10 @@ The API package for the [SAP Cloud Application Programming Model (CAP)](https://
4
4
 
5
5
  See the [API documentation](https://cap.cloud.sap/docs/node.js/api) for more details.
6
6
 
7
+ ## How to Obtain Support**
8
+
9
+ In case you find a bug, please report an [incident](https://cap.cloud.sap/docs/resources/#reporting-incidents) on SAP Support Portal.
10
+
7
11
  ## License
12
+
8
13
  This package is provided under the terms of the [SAP Developer License Agreement](https://tools.hana.ondemand.com/developer-license-3.1.txt).
package/apis/cqn.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { entity } from "./csn"
2
+
1
3
  export type Query = SELECT | INSERT | UPDATE | DELETE | CREATE | DROP | UPSERT
2
4
  export type ParsedExpr = expr & { _:string }
3
5
 
@@ -5,6 +7,7 @@ export type SELECT = {SELECT:{
5
7
  distinct?: true
6
8
  one? : boolean
7
9
  from : source
10
+ mixin?: {[key:string]: expr}
8
11
  columns? : column_expr[]
9
12
  excluding? : string[]
10
13
  where? : predicate
@@ -12,18 +15,23 @@ export type SELECT = {SELECT:{
12
15
  groupBy? : expr[]
13
16
  orderBy? : ordering_term[]
14
17
  limit?: { rows:val, offset:val }
18
+ forUpdate?: { wait: number }
19
+ forShareLock?: { wait: number }
20
+ search?: _xpr
21
+ count?: boolean
15
22
  }}
16
23
 
17
24
  export type INSERT = {INSERT:{
18
- into : name
25
+ into : name | ref
19
26
  entries : any[]
20
27
  columns : string[]
21
28
  values : any[]
22
29
  rows : any[]
30
+ as : SELECT
23
31
  }}
24
32
 
25
33
  export type UPSERT = {UPSERT:{
26
- into : name
34
+ into : name | ref
27
35
  entries : any[]
28
36
  columns : string[]
29
37
  values : any[]
@@ -42,11 +50,14 @@ export type DELETE = {DELETE:{
42
50
  }}
43
51
 
44
52
  export type CREATE = {CREATE:{
45
- entity : name
53
+ entity : entity | name
54
+ as: SELECT
46
55
  }}
47
56
 
48
57
  export type DROP = {DROP:{
49
58
  entity : name
59
+ table: ref
60
+ view: ref
50
61
  }}
51
62
 
52
63
  type name = string
package/apis/ql.d.ts CHANGED
@@ -152,7 +152,7 @@ export class SELECT<T> extends ConstructedQuery {
152
152
  // & ((...expr : string[]) => this)
153
153
  // & ((predicate:object) => this)
154
154
 
155
- SELECT : CQN.SELECT
155
+ SELECT : CQN.SELECT["SELECT"]
156
156
  }
157
157
 
158
158
 
@@ -209,7 +209,7 @@ export class INSERT<T> extends ConstructedQuery {
209
209
  columns (...col: string[]) : this
210
210
  values (... val: any[]) : this
211
211
  rows (... row: any[]) : this
212
- INSERT : CQN.INSERT
212
+ INSERT : CQN.INSERT["INSERT"]
213
213
  }
214
214
 
215
215
 
@@ -229,7 +229,7 @@ export class UPSERT<T> extends ConstructedQuery {
229
229
  columns (...col: string[]) : this
230
230
  values (... val: any[]) : this
231
231
  rows (... row: any[]) : this
232
- UPSERT : CQN.UPSERT
232
+ UPSERT : CQN.UPSERT["UPSERT"]
233
233
  }
234
234
 
235
235
 
@@ -243,7 +243,7 @@ export class DELETE<T> extends ConstructedQuery {
243
243
  where (...expr : any[]) : this
244
244
  and (predicate:object) : this
245
245
  and (...expr : any[]) : this
246
- DELETE : CQN.DELETE
246
+ DELETE : CQN.DELETE["DELETE"]
247
247
  }
248
248
 
249
249
  export class UPDATE<T> extends ConstructedQuery {
@@ -264,15 +264,15 @@ export class UPDATE<T> extends ConstructedQuery {
264
264
  where (...expr : any[]) : this
265
265
  and (predicate:object) : this
266
266
  and (...expr : any[]) : this
267
- UPDATE : CQN.UPDATE
267
+ UPDATE : CQN.UPDATE["UPDATE"]
268
268
  }
269
269
 
270
270
  export class CREATE<T> extends ConstructedQuery {
271
271
  static entity (entity : Definition | string) : CREATE<any>
272
- CREATE : CQN.CREATE
272
+ CREATE : CQN.CREATE["CREATE"]
273
273
  }
274
274
 
275
275
  export class DROP<T> extends ConstructedQuery {
276
276
  static entity (entity : Definition | string) : DROP<any>
277
- DROP : CQN.DROP
278
- }
277
+ DROP : CQN.DROP["DROP"]
278
+ }
@@ -1,4 +1,4 @@
1
- import { SELECT, INSERT, UPDATE, DELETE, Query, ConstructedQuery } from './ql'
1
+ import { SELECT, INSERT, UPDATE, DELETE, Query, ConstructedQuery, UPSERT } from './ql'
2
2
  import { Projection, Proxy, Awaitable } from './ql'
3
3
  import { ArrayConstructable } from './internal/inference'
4
4
  import { LinkedModel, Definition, Definitions } from './reflect'
@@ -31,8 +31,8 @@ export class QueryAPI {
31
31
  }
32
32
 
33
33
  /**
34
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
35
- */
34
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
35
+ */
36
36
  upsert: {
37
37
  <T extends ArrayConstructable<any>>(data: T): UPSERT<T>
38
38
  <T>(data: object | object[]): UPSERT<T>
@@ -49,25 +49,16 @@ export class QueryAPI {
49
49
  /**
50
50
  * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
51
51
  */
52
- // as delete is the only one of the CRUD methods from QueryAPI
53
- // that is extended in Service, we have to add the second signature down there
54
- // (TS error 2425)
55
- delete<T>(entity: Definition | string, key?: any): DELETE<T>
56
-
57
- /**
58
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
59
- */
60
- run(query: ConstructedQuery | ConstructedQuery[]): Promise<ResultSet | any>
61
-
62
- /**
63
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
64
- */
65
- run(query: Query): Promise<ResultSet | any>
66
-
52
+ run: {
53
+ (query: ConstructedQuery | ConstructedQuery[]): Promise<ResultSet | any>
54
+ (query: Query): Promise<ResultSet | any>
55
+ (query: string, args?: any[] | object): Promise<ResultSet | any>
56
+ }
57
+
67
58
  /**
68
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run-sql)
59
+ * @see [docs](https://cap.cloud.sap/docs/node.js/cds-facade?q=cds.delete)
69
60
  */
70
- run(query: string, args?: any[] | object): Promise<ResultSet | any>
61
+ delete<T>(entity: Definition | string, key?: any): DELETE<T>
71
62
 
72
63
  /**
73
64
  * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
@@ -77,17 +68,15 @@ export class QueryAPI {
77
68
  /**
78
69
  * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-stream)
79
70
  */
80
- stream(column: string): {
81
- from(entity: Definition | string): {
82
- where(filter: any): ReadableStream
71
+ stream: {
72
+ (column: string): {
73
+ from(entity: Definition | string): {
74
+ where(filter: any): ReadableStream
75
+ }
83
76
  }
77
+ (query: Query): Promise<ReadableStream>
84
78
  }
85
79
 
86
- /**
87
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-stream)
88
- */
89
- stream(query: Query): Promise<ReadableStream>
90
-
91
80
  /**
92
81
  * Starts or joins a transaction
93
82
  * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-tx)
@@ -156,68 +145,51 @@ export class Service extends QueryAPI {
156
145
  * Constructs and emits an asynchronous event.
157
146
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-emit)
158
147
  */
159
- emit(details: { event: Events; data?: object; headers?: object }): Promise<this>
160
-
161
- /**
162
- * Constructs and emits an asynchronous event.
163
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-emit)
164
- */
165
- emit(event: Events, data?: object, headers?: object): Promise<this>
148
+ emit: {
149
+ <T = any>(details: { event: Events; data?: object; headers?: object }): Promise<T>
150
+ <T = any>(event: Events, data?: object, headers?: object): Promise<T>
151
+ }
166
152
 
167
153
  /**
168
154
  * Constructs and sends a synchronous request.
169
155
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend--method-path-data-headers--results-)
170
156
  */
171
- send(event: Events, path: string, data?: object, headers?: object): Promise<this>
172
-
173
- /**
174
- * Constructs and sends a synchronous request.
175
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend---method-path--query--event-data-headers---results-)
176
- */
177
- send(details: { event: Events; data?: object; headers?: object }): Promise<this>
178
-
179
- /**
180
- * Constructs and sends a synchronous request.
181
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend---method-path--query--event-data-headers---results-)
182
- */
183
- send(details: { query: ConstructedQuery; data?: object; headers?: object }): Promise<this>
184
-
185
- /**
186
- * Constructs and sends a synchronous request.
187
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend---method-path--query--event-data-headers---results-)
188
- */
189
- send(details: { method: Event; path: string; data?: object; headers?: object }): Promise<this>
157
+ send: {
158
+ <T = any>(event: Events, path: string, data?: object, headers?: object): Promise<T>
159
+ <T = any>(event: Events, data?: object, headers?: object): Promise<T>
160
+ <T = any>(details: { event: Events; data?: object; headers?: object }): Promise<T>
161
+ <T = any>(details: { query: ConstructedQuery; data?: object; headers?: object }): Promise<T>
162
+ <T = any>(details: { method: Event; path: string; data?: object; headers?: object }): Promise<T>
163
+ }
190
164
 
191
165
  /**
192
166
  * Constructs and sends a GET request.
193
167
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
194
168
  */
195
- get(entityOrPath: Target, data?: object): Promise<this>
169
+ get<T = any>(entityOrPath: Target, data?: object): Promise<T>
196
170
  /**
197
171
  * Constructs and sends a POST request.
198
172
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
199
173
  */
200
- post(entityOrPath: Target, data?: object): Promise<this>
174
+ post<T = any>(entityOrPath: Target, data?: object): Promise<T>
201
175
  /**
202
176
  * Constructs and sends a PUT request.
203
177
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
204
178
  */
205
- put(entityOrPath: Target, data?: object): Promise<this>
179
+ put<T = any>(entityOrPath: Target, data?: object): Promise<T>
206
180
  /**
207
181
  * Constructs and sends a PATCH request.
208
182
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
209
183
  */
210
- patch(entityOrPath: Target, data?: object): Promise<this>
184
+ patch<T = any>(entityOrPath: Target, data?: object): Promise<T>
211
185
  /**
212
186
  * Constructs and sends a DELETE request.
213
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
214
187
  */
215
- delete(entityOrPath: Target, data?: object): DELETE<T>
216
- /**
217
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
218
- */
219
- delete<T extends ArrayConstructable<any>>(entity: T, key?: any): DELETE<T>
220
- delete<T>(entity: Definition | string, key?: any): DELETE<T>
188
+ delete: {
189
+ (entityOrPath: Target, data?: object): DELETE<T>
190
+ <T extends ArrayConstructable<any>>(entity: T, key?: any): DELETE<T>
191
+ <T>(entity: Definition | string, key?: any): DELETE<T>
192
+ }
221
193
 
222
194
  // The central method to dispatch events
223
195
  dispatch(msg: EventMessage): Promise<any>
package/apis/test.d.ts CHANGED
@@ -57,5 +57,12 @@ declare class Test extends Axios {
57
57
  export = cds
58
58
 
59
59
  declare class cds {
60
+ /**
61
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/cds-test?q=cds.test#run)
62
+ */
60
63
  test(projectDir: string): Test;
64
+ /**
65
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/cds-test?q=cds.test#run-2)
66
+ */
67
+ test(command: string, ...args: string[]): Test;
61
68
  }
@@ -2,7 +2,7 @@ const fs = require('fs')
2
2
  const path = require('path')
3
3
  const cds = require('./cds'), { log } = cds.exec
4
4
  const { sortMessagesSeverityAware, deduplicateMessages, CompilationError } = require('@sap/cds-compiler')
5
- const { relativePaths, BuildError, BuildMessage, resolveRequiredSapModels, hasJavaNature } = require('./util')
5
+ const { relativePaths, BuildError, BuildMessage, resolveRequiredSapModels } = require('./util')
6
6
  const { OUTPUT_MODE_DEFAULT, SEVERITIES, LOG_LEVELS, LOG_MODULE_NAMES, CDS_MODEL_EXCLUDE_LIST } = require('./constants')
7
7
  const BuildTaskProviderFactory = require('./buildTaskProviderFactory')
8
8
  const BuildTaskHandlerInternal = require('./provider/buildTaskHandlerInternal')
@@ -41,16 +41,13 @@ class BuildTaskEngine {
41
41
  buildOptions.target = path.resolve(buildOptions.root, cds.env.build.target)
42
42
  }
43
43
 
44
- // Java projects don't have node modules installed on project root level
45
- if (!hasJavaNature([buildOptions.root])) {
46
- // validate required @sap namespace models - log only
47
- const { unresolved, missing } = BuildTaskEngine._resolveRequiredSapServices(tasks)
48
- if (unresolved.length > 0) {
49
- messages.push(new BuildMessage(`Required CDS service models [${unresolved.join(', ')}] cannot be resolved. Make sure to install the missing npm modules.`))
50
- }
51
- if (missing.length > 0) {
52
- messages.push(new BuildMessage(`Required CDS service models [${missing.join(', ')}] are missing in custom build tasks. Make sure to add the missing models.`))
53
- }
44
+ // validate required @sap namespace models - log only
45
+ const { unresolved, missing } = BuildTaskEngine._resolveRequiredSapServices(tasks)
46
+ if (unresolved.length > 0) {
47
+ messages.push(new BuildMessage(`Required CDS service models [${unresolved.join(', ')}] cannot be resolved. Make sure to install the missing npm modules.`))
48
+ }
49
+ if (missing.length > 0) {
50
+ messages.push(new BuildMessage(`Required CDS service models [${missing.join(', ')}] are missing in custom build tasks. Make sure to add the missing models.`))
54
51
  }
55
52
 
56
53
  // create build task handlers
@@ -260,8 +257,6 @@ class BuildTaskEngine {
260
257
  const files = BuildTaskEngine._getBuildOutput(handlers, buildOptions)
261
258
  if (files.length > 0) {
262
259
  this.logger.log(`done > wrote output to:\n ${files.join("\n ")}\n`)
263
- } else {
264
- this.logger.log('done >')
265
260
  }
266
261
  }
267
262
 
@@ -337,7 +332,7 @@ class BuildTaskEngine {
337
332
  }
338
333
 
339
334
  /**
340
- * Returns a sorted and flatend list of all messages extracted from the given errors.
335
+ * Returns a sorted and flattened list of all messages extracted from the given errors.
341
336
  * @param {Array<Error>} errors
342
337
  */
343
338
  static _getErrorMessages(errors) {
@@ -56,7 +56,7 @@ class BuildTaskFactory {
56
56
 
57
57
  async _createTasks(providerFactory) {
58
58
  const buildOptions = providerFactory.buildOptions
59
- this.logger.log(`determining build tasks for project [${buildOptions.root}].`)
59
+ this.logger.debug(`determining build tasks for project [${buildOptions.root}].`)
60
60
 
61
61
  // clearing model cache (details https://github.tools.sap/cap/cds/pull/181) is no longer required
62
62
  // because of changes https://github.tools.sap/cap/cds/pull/1121
@@ -3,7 +3,7 @@ const fs = require('fs').promises
3
3
  const cds = require('./cds')
4
4
 
5
5
  const { BUILD_OPTION_OUTPUT_MODE, OUTPUT_MODE_DEFAULT, OUTPUT_MODE_RESULT_ONLY, SEVERITY_INFO, SEVERITY_WARNING, SEVERITY_ERROR, OVERRIDE_METHOD_MSG } = require('./constants')
6
- const { hasOptionValue, getProperty, relativePaths, BuildMessage } = require('./util')
6
+ const { hasOptionValue, getProperty, relativePaths, copy, BuildMessage } = require('./util')
7
7
 
8
8
  /**
9
9
  * The build task handler creates the build output for a dedicated build task. It is uniquely identified
@@ -157,7 +157,7 @@ class BuildTaskHandler {
157
157
  if (fs.cp) { // Node.js >= 16.7
158
158
  return fs.cp(src, dest, { recursive: true })
159
159
  }
160
- return this._copy(src, dest)
160
+ return copy(src, dest)
161
161
  }
162
162
  return dest
163
163
  }
@@ -184,7 +184,7 @@ class BuildTaskHandler {
184
184
  async model() {
185
185
  const files = this._resolveModel()
186
186
  if (!files || files.length === 0) {
187
- this._logger.log("no model found, skip build")
187
+ this._logger.log(`no CDS model found for [${this.task.for}] build task [${this.task.src}] - nothing to be done`)
188
188
  return null
189
189
  }
190
190
  this._logger._debug && this._logger.debug(`model: ${relativePaths(this._buildOptions.root, files).join(", ")}`)
@@ -237,16 +237,5 @@ class BuildTaskHandler {
237
237
  }
238
238
  return getProperty(this._buildOptions, qualifiedName)
239
239
  }
240
-
241
- // Asynchronously copies the entire content from src to dest.
242
- async _copy(src, dest) {
243
- if ((await fs.stat(src)).isDirectory()) {
244
- const entries = await fs.readdir(src)
245
- return Promise.all(entries.map(async each => this._copy(path.join(src, each), path.join(dest, each))))
246
- } else {
247
- await fs.mkdir(path.dirname(dest), { recursive: true })
248
- return fs.copyFile(src, dest)
249
- }
250
- }
251
240
  }
252
241
  module.exports = BuildTaskHandler
@@ -13,7 +13,7 @@ module.exports = Object.assign(build,
13
13
  /**
14
14
  * New modular build.
15
15
  *
16
- * @param {object} options - commmand options as defined by build command.
16
+ * @param {object} options - command options as defined by build command.
17
17
  */
18
18
  async function build(options = {}) {
19
19
  const projectPath = path.resolve(options.project || '.')
@@ -22,6 +22,7 @@ async function build(options = {}) {
22
22
  }
23
23
 
24
24
  const cds = require('./cds')
25
+ const cdsEnv = cds.env, cdsRoot = cds.root
25
26
  if (projectPath !== process.cwd()) {
26
27
  const env = cds.env.for('cds', projectPath);
27
28
  cds.env = env // REVISIT: not good / fragile
@@ -31,17 +32,22 @@ async function build(options = {}) {
31
32
  const buildOptions = _mergeCliOptions({ root: projectPath }, options)
32
33
  const buildTaskFactory = new BuildTaskFactory(logger)
33
34
  const buildTaskEngine = new BuildTaskEngine(logger)
35
+ let buildResult
34
36
 
35
37
  try {
36
38
  const tasks = await buildTaskFactory.getTasks(buildOptions)
37
- return buildTaskEngine.processTasks(tasks, buildOptions)
39
+ buildResult = await buildTaskEngine.processTasks(tasks, buildOptions)
38
40
  } catch (e) {
39
41
  // cds CLI layer logs if invoked from CLI
40
42
  if (!buildOptions.cli) {
41
43
  buildTaskEngine._logMessages(buildOptions, [e])
42
44
  }
43
45
  throw e
46
+ } finally {
47
+ cds.root = cdsRoot
48
+ cds.env = cdsEnv
44
49
  }
50
+ return buildResult
45
51
  }
46
52
 
47
53
  function _mergeCliOptions(buildOptions, options) {
@@ -63,7 +63,11 @@ class BuildTaskProviderInternal extends BuildTaskProvider {
63
63
  break
64
64
  case BUILD_TASK_MTX_EXTENSION:
65
65
  case BUILD_TASK_MTX:
66
- task.src = task.src || "."
66
+ if (isStreamlinedMtx()) {
67
+ task.src = task.src || BuildTaskProviderInternal._normalizePath(cds.env.folders.srv)
68
+ } else {
69
+ task.src = task.src || "."
70
+ }
67
71
  break
68
72
  default:
69
73
  throw new Error(`Unknown build task '${task.use || task.for}'`)
@@ -84,13 +88,13 @@ class BuildTaskProviderInternal extends BuildTaskProvider {
84
88
  if (Array.isArray(db) && db.length > 0) {
85
89
  db = BuildTaskProviderInternal._getModuleFolder(projectPath, db) || null
86
90
  if (!db && !addRequiredTasks) { // log once
87
- this.logger.log("No database module found")
91
+ this.logger.debug("No database module found")
88
92
  }
89
93
  }
90
94
  if (Array.isArray(srv) && srv.length > 0) {
91
95
  srv = BuildTaskProviderInternal._getModuleFolder(projectPath, srv) || null
92
96
  if (!srv && !addRequiredTasks) { // log once
93
- this.logger.log("No service module found")
97
+ this.logger.debug("No service module found")
94
98
  }
95
99
  }
96
100
  // create required build tasks
@@ -191,13 +195,21 @@ class BuildTaskProviderInternal extends BuildTaskProvider {
191
195
  }
192
196
  this.logger.debug("determining mtx version of nodejs project")
193
197
 
198
+ // preserve order of creation
199
+ if (BuildTaskProviderInternal._isMtxExtension()) {
200
+ this.logger.debug("Streamlined MTX extension app")
201
+ return {
202
+ for: BUILD_TASK_MTX_EXTENSION
203
+ }
204
+ }
205
+
194
206
  if (isStreamlinedMtx()) {
195
207
  if (cds.env.requires["cds.xt.ModelProviderService"]?.kind === "rest") { // "cds.xt.ModelProviderService": "from-sidecar"
196
208
  this.logger.debug("Nodejs Streamlined MTX app with sidecar")
197
209
 
198
210
  const sidecarPath = path.join(projectPath, MTX_SIDECAR_FOLDER)
199
211
  if (!fs.existsSync(sidecarPath)) {
200
- throw new BuildError("CDS build failed", `MTX sidecar directory '${sidecarPath}' not existing. Custom build task configuration necessary if the folder is named differently.`)
212
+ throw new BuildError(`MTX sidecar directory '${sidecarPath}' not existing. Custom build task configuration necessary if the folder is named differently.`)
201
213
  }
202
214
  const sidecarEnv = cds.env.for("cds", sidecarPath)
203
215
  if (sidecarEnv.requires["cds.xt.ModelProviderService"]?.kind === "in-sidecar") {
@@ -205,12 +217,12 @@ class BuildTaskProviderInternal extends BuildTaskProvider {
205
217
  for: BUILD_TASK_MTX_SIDECAR
206
218
  }
207
219
  }
208
- throw new BuildError("CDS build failed", 'Invalid MTX sidecar configuration. Make sure to add required service "cds.xt.ModelProviderService": "in-sidecar".')
220
+ throw new BuildError("Invalid MTX sidecar configuration - \"cds.xt.ModelProviderService\": \"in-sidecar\" missing.")
209
221
  }
210
222
 
211
223
  if (cds.env.requires["cds.xt.ModelProviderService"]?.kind === "in-sidecar") {
212
224
  // cds build is executed in sidecar folder
213
- throw new BuildError("CDS build failed", "Invalid working directory. Make sure to execute 'cds build' in CAP project root directory.")
225
+ throw new BuildError("Invalid working directory. Make sure to execute 'cds build' in CAP project root directory.")
214
226
  }
215
227
 
216
228
  this.logger.debug("Nodejs Streamlined MTX app without sidecar")
@@ -220,13 +232,6 @@ class BuildTaskProviderInternal extends BuildTaskProvider {
220
232
  }
221
233
  }
222
234
 
223
- if (BuildTaskProviderInternal._isMtxExtension()) {
224
- this.logger.debug("Streamlined MTX extension app")
225
- return {
226
- for: BUILD_TASK_MTX_EXTENSION
227
- }
228
- }
229
-
230
235
  if (cds.env.requires.multitenancy) {
231
236
  this.logger.debug("Nodejs Classic MTX app without sidecar")
232
237
  return {