@sap/cds 6.0.4 → 6.1.2

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 +180 -18
  2. package/apis/cds.d.ts +11 -7
  3. package/apis/log.d.ts +124 -0
  4. package/apis/ql.d.ts +72 -15
  5. package/apis/services.d.ts +13 -2
  6. package/bin/build/buildTaskHandler.js +5 -2
  7. package/bin/build/constants.js +4 -1
  8. package/bin/build/provider/buildTaskHandlerEdmx.js +11 -39
  9. package/bin/build/provider/buildTaskHandlerFeatureToggles.js +14 -34
  10. package/bin/build/provider/buildTaskHandlerInternal.js +56 -4
  11. package/bin/build/provider/buildTaskProviderInternal.js +22 -14
  12. package/bin/build/provider/hana/index.js +12 -9
  13. package/bin/build/provider/java/index.js +18 -8
  14. package/bin/build/provider/mtx/index.js +7 -4
  15. package/bin/build/provider/mtx/resourcesTarBuilder.js +60 -35
  16. package/bin/build/provider/mtx-extension/index.js +57 -0
  17. package/bin/build/provider/mtx-sidecar/index.js +46 -18
  18. package/bin/build/provider/nodejs/index.js +34 -13
  19. package/bin/deploy/to-hana/cfUtil.js +7 -2
  20. package/bin/deploy/to-hana/hana.js +20 -25
  21. package/bin/deploy/to-hana/hdiDeployUtil.js +13 -2
  22. package/bin/serve.js +7 -4
  23. package/lib/compile/{index.js → cds-compile.js} +0 -0
  24. package/lib/compile/extend.js +15 -5
  25. package/lib/compile/minify.js +1 -15
  26. package/lib/compile/parse.js +1 -1
  27. package/lib/compile/resolve.js +2 -2
  28. package/lib/compile/to/srvinfo.js +6 -4
  29. package/lib/{deploy.js → dbs/cds-deploy.js} +9 -8
  30. package/lib/env/{index.js → cds-env.js} +1 -17
  31. package/lib/env/{requires.js → cds-requires.js} +24 -3
  32. package/lib/env/defaults.js +7 -1
  33. package/lib/env/schemas/cds-package.json +11 -0
  34. package/lib/env/schemas/cds-rc.json +614 -0
  35. package/lib/index.js +19 -16
  36. package/lib/log/{errors.js → cds-error.js} +1 -1
  37. package/lib/log/{index.js → cds-log.js} +0 -0
  38. package/lib/log/format/kibana.js +19 -1
  39. package/lib/ql/Query.js +9 -3
  40. package/lib/ql/SELECT.js +2 -2
  41. package/lib/ql/UPDATE.js +2 -2
  42. package/lib/ql/{index.js → cds-ql.js} +4 -10
  43. package/lib/req/context.js +49 -17
  44. package/lib/req/locale.js +5 -1
  45. package/lib/{serve → srv}/adapters.js +23 -19
  46. package/lib/{connect → srv}/bindings.js +0 -0
  47. package/lib/{connect/index.js → srv/cds-connect.js} +1 -1
  48. package/lib/{serve/index.js → srv/cds-serve.js} +0 -0
  49. package/lib/{serve → srv}/factory.js +1 -1
  50. package/lib/{serve/Service-api.js → srv/srv-api.js} +22 -6
  51. package/lib/{serve/Service-dispatch.js → srv/srv-dispatch.js} +13 -8
  52. package/lib/{serve/Service-handlers.js → srv/srv-handlers.js} +10 -0
  53. package/lib/{serve/Service-methods.js → srv/srv-methods.js} +10 -8
  54. package/lib/srv/srv-models.js +207 -0
  55. package/lib/{serve/Transaction.js → srv/srv-tx.js} +57 -40
  56. package/lib/utils/{tests.js → cds-test.js} +2 -2
  57. package/lib/utils/cds-utils.js +146 -0
  58. package/lib/utils/index.js +2 -145
  59. package/lib/utils/jest.js +43 -0
  60. package/lib/utils/resources/index.js +15 -25
  61. package/lib/utils/resources/tar.js +18 -41
  62. package/libx/_runtime/auth/index.js +14 -11
  63. package/libx/_runtime/cds-services/adapter/odata-v4/OData.js +7 -19
  64. package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +1 -4
  65. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +1 -4
  66. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +1 -4
  67. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/delete.js +1 -4
  68. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/error.js +2 -2
  69. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +6 -19
  70. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +3 -5
  71. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/request.js +1 -1
  72. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +1 -4
  73. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/utils/PrimitiveValueDecoder.js +0 -2
  74. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/deserializer/DeserializerFactory.js +3 -1
  75. package/libx/_runtime/cds-services/adapter/odata-v4/to.js +38 -4
  76. package/libx/_runtime/cds-services/adapter/odata-v4/utils/readAfterWrite.js +1 -3
  77. package/libx/_runtime/cds-services/services/utils/differ.js +4 -0
  78. package/libx/_runtime/cds-services/util/errors.js +1 -29
  79. package/libx/_runtime/common/i18n/messages.properties +2 -1
  80. package/libx/_runtime/common/perf/index.js +10 -15
  81. package/libx/_runtime/common/utils/binary.js +3 -4
  82. package/libx/_runtime/common/utils/cqn2cqn4sql.js +0 -1
  83. package/libx/_runtime/common/utils/entityFromCqn.js +8 -5
  84. package/libx/_runtime/common/utils/keys.js +14 -6
  85. package/libx/_runtime/common/utils/resolveView.js +1 -1
  86. package/libx/_runtime/common/utils/template.js +1 -1
  87. package/libx/_runtime/db/Service.js +2 -14
  88. package/libx/_runtime/db/expand/expandCQNToJoin.js +28 -25
  89. package/libx/_runtime/db/expand/rawToExpanded.js +7 -6
  90. package/libx/_runtime/db/generic/input.js +8 -1
  91. package/libx/_runtime/db/sql-builder/InsertBuilder.js +1 -1
  92. package/libx/_runtime/db/sql-builder/SelectBuilder.js +37 -18
  93. package/libx/_runtime/extensibility/activate.js +47 -47
  94. package/libx/_runtime/extensibility/add.js +22 -13
  95. package/libx/_runtime/extensibility/addExtension.js +17 -13
  96. package/libx/_runtime/extensibility/defaults.js +25 -30
  97. package/libx/_runtime/extensibility/handler/transformREAD.js +20 -18
  98. package/libx/_runtime/extensibility/linter/allowlist_checker.js +373 -0
  99. package/libx/_runtime/extensibility/linter/annotations_checker.js +113 -0
  100. package/libx/_runtime/extensibility/linter/checker_base.js +20 -0
  101. package/libx/_runtime/extensibility/linter/namespace_checker.js +180 -0
  102. package/libx/_runtime/extensibility/linter.js +32 -0
  103. package/libx/_runtime/extensibility/push.js +77 -20
  104. package/libx/_runtime/extensibility/service.js +29 -12
  105. package/libx/_runtime/extensibility/token.js +57 -0
  106. package/libx/_runtime/extensibility/utils.js +8 -6
  107. package/libx/_runtime/extensibility/validation.js +6 -9
  108. package/libx/_runtime/fiori/generic/new.js +0 -11
  109. package/libx/_runtime/fiori/utils/where.js +1 -1
  110. package/libx/_runtime/hana/Service.js +0 -1
  111. package/libx/_runtime/hana/conversion.js +12 -1
  112. package/libx/_runtime/hana/customBuilder/CustomFunctionBuilder.js +4 -3
  113. package/libx/_runtime/hana/customBuilder/CustomSelectBuilder.js +5 -0
  114. package/libx/_runtime/hana/pool.js +6 -10
  115. package/libx/_runtime/hana/search2Contains.js +0 -5
  116. package/libx/_runtime/hana/search2cqn4sql.js +1 -0
  117. package/libx/_runtime/messaging/common-utils/authorizedRequest.js +1 -1
  118. package/libx/_runtime/messaging/enterprise-messaging-utils/EMManagement.js +1 -2
  119. package/libx/_runtime/messaging/outbox/utils.js +1 -1
  120. package/libx/_runtime/messaging/service.js +11 -6
  121. package/libx/_runtime/remote/utils/data.js +5 -0
  122. package/libx/_runtime/sqlite/Service.js +7 -6
  123. package/libx/_runtime/sqlite/execute.js +41 -28
  124. package/libx/odata/afterburner.js +79 -2
  125. package/libx/odata/cqn2odata.js +15 -9
  126. package/libx/odata/grammar.pegjs +157 -76
  127. package/libx/odata/index.js +9 -3
  128. package/libx/odata/parser.js +1 -1
  129. package/libx/odata/utils.js +39 -5
  130. package/libx/rest/RestAdapter.js +3 -7
  131. package/libx/rest/middleware/delete.js +4 -5
  132. package/libx/rest/middleware/parse.js +3 -2
  133. package/package.json +3 -3
  134. package/server.js +1 -1
  135. package/srv/extensibility-service.cds +6 -3
  136. package/srv/model-provider.cds +3 -1
  137. package/srv/model-provider.js +86 -106
  138. package/srv/mtx.js +7 -1
  139. package/libx/_runtime/cds-services/adapter/odata-v4/Dispatcher.js +0 -240
package/CHANGELOG.md CHANGED
@@ -4,6 +4,167 @@
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.1.2 - 2022-09-05
8
+
9
+ ### Fixed
10
+
11
+ - Missing key insertion from where clauses in references for deep update statements
12
+ - Prevent duplicate entries for some `INSERT` statements
13
+ - Log details were not properly displayed in Kibana
14
+ - getCsn in model-provider if `cds.requires.toggles` is false
15
+ - HTTP calls in messaging have the correct content length
16
+ - Performance issue for OData <entity>/$count requests
17
+ - Typescript definition for SQL-native variant of `srv.run`, like `srv.run('SELECT * from Authors where name like ?',['%Poe%'])`
18
+ - Typescript definitions for `srv.run( [query] )` and `srv.send( {query, headers} )`
19
+ - Typescript definitions for `cds.log` are improved, level indicators like `cds.log()._debug` added
20
+ - Typescript definitions for `tx` now carry additional service methods
21
+ - `cds login` now returns errors with a better root cause messages
22
+ - `$expand` requests for to-one associations that do not select the foreign key
23
+ - `UPDATE` statement accepts empty objects: `UPDATE('Foo').with({ bar: {} })`
24
+ - URI encoding of parameters in remote service calls
25
+
26
+ ### Removed
27
+
28
+ ## Version 6.1.1 - 2022-08-24
29
+
30
+ ### Added
31
+
32
+ - The configuration schema now includes `cds.extends` and `new-fields` (in `cds.xt.ExtensibilityService`)
33
+ - `srv.run(fn)` now accepts a function as first argument, which will be run in an active outer transaction, if any, or in a newly created one. This is in contrast to `srv.tx(fn)` which always creates a new tx.
34
+ ```js
35
+ cds.run (tx => { // nested operations are guaranteed to run in a tx
36
+ await INSERT.into (Foo, ...)
37
+ await INSERT.into (Bar, ...)
38
+ })
39
+ ```
40
+
41
+ ### Fixed
42
+
43
+ - Erroneous checks for `join` in `SELECT.from(SELECT.from('xxx'))`
44
+ - Virtual fields with default values in draft context
45
+ - View resolving without model information doesn't crash
46
+ - Unable to upload large attachments. Uploading a large attachment (base64 encoded) caused a runtime exception.
47
+ - `cds.Query.then()` is using `AsyncResource.runInAsyncScope` from now on. &rarr; this avoids callstacks being cut off, e.g. in debuggers.
48
+ - `cds.tx()` and `cds.context` have been fixed to avoid accidential fallbacks to auto-commit mode.
49
+ - HDI configuration data (e.g. `./cfg`, `.hdiignore`) is now included in the `resources.tgz` file which is required for Streamlined MTX.
50
+ - `cds deploy` accepts in addition to `VCAP_SERVICES` also `TARGET_CONTAINER` and `SERVICE_REPLACEMENTS` from vcap file when using `--vcap-file` parameter.
51
+ - `cds build` doesn't duplicate CSV files that are contained in `db/src/**`.
52
+ - Typescript issues in `apis/log.d.ts`
53
+ - `cds build` adds OS agnostic base model path to generated feature CSN.
54
+ - Unhandled promise rejection in `expand` handling
55
+ - `cds.context.model` middleware is not mounted for not extensible services
56
+ - `cds.context` continuation was sometimes not reset in REST adapter
57
+ - Requests don't fail with `RangeError: Unable to get service from service map due to error: Invalid time value` anymore
58
+
59
+ ## Version 6.1.0 - 2022-08-10
60
+
61
+ ### Added
62
+
63
+ - Detailed information about pool state: `borrowed`, `pending`, `size`, `available`, `max` to the timeout error
64
+ - Odata v2 payloads for `cds.Time` are converted from hh:mm:ss to PThhHmmMssS e.g. 12:34:56 to PT12H34M56S if provided in hh:mm:ss format
65
+ - Odata v2 payloads for `cds.Integer` are converted to String if not provided as String
66
+ - New OData parser supports aliased parameters e.g. `...function(ID=@p)?@p=5`
67
+ - Support for locale "en_US_x_saprigi"
68
+ - Parameter `rows` in ql API function `limit` can be omitted for remote services, e.g. `SELECT.limit(undefined, 5)`
69
+ - New OData parser supports $filter with "in" operator, e.g. `$filter=ID in (1,2,3)`
70
+ - `cds build` copies `package.json` and `.cdsrc.json` into _main folder of MTX sidecar app.
71
+ - New OData parser supports null parameter in function/action, e.g `/findBooks(author=1,title=null)`
72
+ - New enviroment variable `schemas` contains locations for json schemas validating `package.json`, `.cdsrc.json` and `.cdsrc-private.json` in VS Code
73
+ - `cds.test` can now listen on a fixed port by way of additional arguments '--port', '<PORT_NUMBER>
74
+ - `cds.requires.db.kind = 'sql-mt'` is introduced as a shorthand for
75
+ ```js
76
+ "db": {
77
+ "kind": "sqlite",
78
+ "[production]": {
79
+ "kind": "hana-mt"
80
+ }
81
+ }
82
+ ```
83
+ - `cds build` support for Streamlined MTX extension projects based on build task `mtx-extension`
84
+ - TS definitions for `SELECT.forSharedLock` and `SELECT.forUpdate`
85
+ - TS definitions for `log`
86
+ - Support for new cds build task option `deploy-format`. Java apps may use this option instead of the corresponding global CDS config option.
87
+ - The `ExtensibilityService` serves an endpoint to retrieve a subdomain-specific JWT, which is used by `cds login`
88
+ - The endpoint `/-/cds/extensibility/push` now checks restrictions for new extensions. The configuration is added to the `cds.xt.ExtensibilityService`
89
+ ```js
90
+ "requires": {
91
+ "cds.xt.ExtensibilityService": {
92
+ "element-prefix": ["Z_", "ZZ_"],
93
+ "namespace-blocklist": ["com.sap.", "sap."],
94
+ "extension-allowlist": [
95
+ {
96
+ "for": ["my.bookshop"],
97
+ "kind": "entity",
98
+ "new-fields": 2
99
+ },
100
+ {
101
+ "for": ["CatalogService"],
102
+ "new-entities": 2
103
+ }
104
+ ]
105
+ }
106
+ }
107
+ ```
108
+ - `cds build` validates required service models `@sap/**` for MTX sidecar app and logs an ERROR if some couldn't be resolved.
109
+ - Configuration schema for many properties of the `cds` configuration block in `package.json` or `.cdsrc.json`, especially for `cds.requires...`
110
+
111
+ ### Changed
112
+
113
+ - Streamlined calculation of the difference for `DELETE` queries using `req.diff()`
114
+ - Improved error messages for rest / new odata parser
115
+ - Adjust types for `SELECT.from` and `SELECT.one` to accept array classes as well
116
+ - No `"` added around search values in OData v2 e.g. Foo?search=name is passed through as is
117
+ - If an entity can not be read after write (e.g. insert only entity) no error is shown in the log
118
+ - Throw not supported error for pagination in `$expand`
119
+
120
+ ### Fixed
121
+
122
+ - Wrong context in `tx.run(query)` when `query` is an array
123
+ - We now detect and ignore erroneous attempts to re-register framework-generated stubs as handlers for custom actions/functions.
124
+ - Emits with `persistent-outbox` also work with manual transactions
125
+ - You can now use `cds.ql` fluent API to query tables not in the model, but in database.
126
+ For example, within `cap/samples/bookshop` this works now:
127
+ ```sql
128
+ await SELECT.from('sqlite_master')
129
+ await cds.read('sqlite_master')
130
+ ```
131
+ Caveat: the following undocumented usage of unqualified names happened to work in the past.
132
+ But this was very fragile and caused lots of issues, and therefore was removed:
133
+ ```sql
134
+ await SELECT.from('Books')
135
+ await cds.read('Books')
136
+ ```
137
+ Always use qualified names, or reflected definitions instead:
138
+ ```sql
139
+ const Books = 'sap.capire.bookshop.Books'
140
+ await SELECT.from(Books)
141
+ await cds.read(Books)
142
+ ```
143
+ ```sql
144
+ const {Books} = cds.entities ('sap.capire.bookshop')
145
+ await SELECT.from(Books)
146
+ await cds.read(Books)
147
+ ```
148
+ - Wrong results for expand to many without `orderBy`
149
+ - `cds deploy` api endpoint regex for cli now ignores trailing version info in url
150
+ - Default values no longer overwrite payload values on fields of new drafts
151
+ - Unmanaged to-one navigation caused malformed SQL statement in draft
152
+ - `cds.compile.to.serviceinfo` fix failure to detect Java services if `odataV4.endpoint.path` or `odataV2.endpoint.path` missing in `cds` configuration in `application.yaml`
153
+ - Data type conversion did not work in some expand cases
154
+ - Failed connection to SAP HANA with no or malformed credentials was leading to credentials being written to the log
155
+ - `cds build` no longer fails with an error `no such file` if one of the following files has been defined in some `srv` subfolder - `package.json, package-lock.json, .cdsrc.json, .npmrc`
156
+ - Tar issue on Windows: 'The command line is too long'.
157
+ - `$search`: Lifecycle issue that causes an empty search result when the `$search` and `$expand` query options were combined
158
+ - Operator `IN` with Tagged Template String Literals e.g.:
159
+ ```sql
160
+ SELECT.from(Object).where`userId IN ${aUserIDs}`
161
+ ```
162
+ - `cds build` now uses a closed version range in the node engines version of the deployed application's `package.json`
163
+ - `cds build` no longer generates EDMX files for services that aren't odata protocol enabled
164
+ - `cds deploy` handles orgs and spaces containing commas correctly
165
+ - Incorrect decoding of special characters when reading data of type `cds.LargeString` from SAP HANA using `hdb@^0.19.5` driver
166
+ - The payload is added to the delete request in rest adapter as req.data
167
+
7
168
  ## Version 6.0.4 - 2022-07-20
8
169
 
9
170
  ### Fixed
@@ -38,17 +199,18 @@
38
199
  ## Version 6.0.1 - 2022-07-05
39
200
 
40
201
  ### Added
202
+
41
203
  - Config option `cds.env.server.port` allows to configure the port to use (in addition to `process.env.PORT` and CLI option `--port`)
42
204
 
205
+ ### Changed
206
+
207
+ - Plugins cannot be loaded as ES modules, but need to remain CommonJS modules
208
+
43
209
  ### Fixed
44
210
 
45
211
  - Removed debug log about shutdown from `cds serve`
46
212
  - Hiding timeout error in production mode
47
213
 
48
- ### Changed
49
-
50
- - Plugins cannot be loaded as ES modules, but need to remain CommonJS modules
51
-
52
214
  ## Version 6.0.0 - 2022-06-30
53
215
 
54
216
  ### Added
@@ -95,7 +257,7 @@
95
257
  - Support for `FOR SHARE LOCK` on SAP HANA to acquire shared locks on the queried records so that the locked records
96
258
  stay intact until the transaction is committed or rolled back.
97
259
  - Consistent error information for remote batch requests
98
- - `cds.env` now supports expanding scalar `cds.requires` entries from `cds.requires.kinds`as follows:
260
+ - `cds.env` now supports expanding scalar `cds.requires` entries from `cds.requires.kinds` as follows:
99
261
  ```jsonc
100
262
  { "cds": {
101
263
  "requires": {
@@ -114,23 +276,23 @@ stay intact until the transaction is committed or rolled back.
114
276
  - Ordering by aggregated value for draft-enabled active entity
115
277
  - `cds build` support for model provider service-based resource deployment.
116
278
  - Remote service:
117
- - Conversion of OData V2 (`"kind": "odata-v2"`) function and action results to OData V4 format
118
- - Conversion of binary data in CQN queries to `base64url` in URL and payload
119
- - Key predicate is omitted for single-key entities in resulting URL (e.g. `GET /Foo(1)` instead of `GET /Foo(ID=1)`)
120
- - Support of views with parameters
279
+ + Conversion of OData V2 (`"kind": "odata-v2"`) function and action results to OData V4 format
280
+ + Conversion of binary data in CQN queries to `base64url` in URL and payload
281
+ + Key predicate is omitted for single-key entities in resulting URL (e.g. `GET /Foo(1)` instead of `GET /Foo(ID=1)`)
282
+ + Support of views with parameters
121
283
  - Add `@odata.mediaContentType` if selecting stream property
122
284
  - Kubernetes service bindings: Support for servicebinding.io and SAP BTP Service Operator based bindings
123
285
  - `cds build` copies an existing `.npmrc` file located in the root or srv folder of your project into the deployment folder (usually `gen/srv`). This allows for dedicated npm configuration in cloud environments. Can be switched off by cds build option `contentNpmrc`.
124
286
  - `cds build` copies an existing `.cdsrc.json` file located in the root or srv folder of your project into the deployment folder (usually `gen/srv`). The effective CDS configuration is created from the `.cdsrc.json` and CDS configuration defined in the `package.json` file. Can be switched off by cds build option `contentCdsrcJson`.
125
287
  - Beta OData URL to CQN parser (`cds.env.features.odata_new_parser = true`):
126
- - `@odata.context` is derived without using okra, not yet supported:
127
- - `$expand=*` query option
128
- - Support for actions and functions
129
- - Further `$apply` transformations supported
130
- - (nested) `concat` transformations
131
- - `orderBy` transformation
132
- - `top` & `skip` transformation
133
- - `identity` transformation
288
+ + `@odata.context` is derived without using okra, not yet supported:
289
+ + `$expand=*` query option
290
+ + Support for actions and functions
291
+ + Further `$apply` transformations supported
292
+ + (nested) `concat` transformations
293
+ + `orderBy` transformation
294
+ + `top` & `skip` transformation
295
+ + `identity` transformation
134
296
  - Log `BEGIN`/`COMMIT`/`ROLLBACK` commands when using SAP HANA as the underlying database
135
297
  - Binary data in payload is validated to be RFC-4648 and OData ABNF conformed
136
298
  - Support multiple media (streaming) properties in one entity
@@ -140,7 +302,6 @@ stay intact until the transaction is committed or rolled back.
140
302
  - $filter in $expand for remote services
141
303
  - Mapping of aliases in $expand for remote services
142
304
 
143
-
144
305
  ### Changed
145
306
 
146
307
  - `@sap/cds` can now be loaded from different install locations like any other module, i.e. `@require('@sap/cds')` will no longer return the same singleton instance.
@@ -194,6 +355,7 @@ Note that this is a breaking change for appliations that rely on error sanitizat
194
355
 
195
356
  ### Fixed
196
357
 
358
+ - We don't rely on `global.cds` anymore -> allows to load and correctly work with multiple versions of `cds`
197
359
  - Improved shutdown for AMQP connections and file listeners
198
360
  - Using `CQL` with a tagged template string `SELECT from Foo { null as boo }` throwed an exception.
199
361
  - In case of `MULTIPLE_ERRORS` throw an `Error` instead of an object
package/apis/cds.d.ts CHANGED
@@ -1,11 +1,15 @@
1
+
2
+ type cds_facade = import('./core')
3
+ & import('./models')
4
+ & import('./connect')
5
+ & import('./serve')
6
+ & import('./ql').cds_ql
7
+ & import('./services').cds
8
+ & import('./services').QueryAPI
9
+ & import('./log')
10
+
1
11
  declare global {
2
- const cds : import ('./core')
3
- & import ('./models')
4
- & import ('./connect')
5
- & import ('./serve')
6
- & import ('./ql').cds_ql
7
- & import ('./services').cds
8
- & import ('./services').QueryAPI
12
+ const cds : cds_facade
9
13
  class SELECT<T> extends cds.ql.SELECT<T>{}
10
14
  class INSERT<T> extends cds.ql.INSERT<T>{}
11
15
  class UPDATE<T> extends cds.ql.UPDATE<T>{}
package/apis/log.d.ts ADDED
@@ -0,0 +1,124 @@
1
+ export = cds
2
+ declare class cds {
3
+ /**
4
+ * Create a new logger, or install a custom log formatter
5
+ */
6
+ log: LogFactory
7
+
8
+ /**
9
+ * Shortcut to `cds.log(...).debug`, returning `undefined` if `cds.log(...)._debug` is `false`.
10
+ * Use like this:
11
+ * ```
12
+ * const dbg = cds.debug('foo')
13
+ * ...
14
+ * dbg && dbg('message')
15
+ * ```
16
+ *
17
+ * @param name logger name
18
+ */
19
+ debug(name: string): undefined | Log
20
+ }
21
+
22
+ declare type LogFactory = {
23
+ /**
24
+ * Returns a trace logger for the given module if trace is switched on for it,
25
+ * otherwise returns null. All cds runtime packages use this method for their
26
+ * trace and debug output.
27
+ *
28
+ * By default this logger would prefix all output with `[sql] - `
29
+ * You can change this by specifying another prefix in the options:
30
+ * ```
31
+ * const LOG = cds.log('sql|db',{ prefix:'cds.ql' })
32
+ * ```
33
+ * Call `cds.log()` for a given module again to dynamically change the log level
34
+ * of all formerly created loggers, for example:
35
+ * ```
36
+ * const LOG = cds.log('sql')
37
+ * LOG.info ('this will show, as default level is info')
38
+ * cds.log('sql','warn')
39
+ * LOG.info ('this will be suppressed now')
40
+ * ```
41
+ * @param name logger name
42
+ * @param options level and prefix
43
+ * @returns the logger
44
+ *
45
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-log)
46
+ */
47
+ (name: string, options?: string | number | { level?: number, prefix?: string }): Logger
48
+
49
+ /**
50
+ * Set a custom formatter function like that:
51
+ * ```
52
+ * cds.log.format = (module, level, ...args) => [ '[', module, ']', ...args ]
53
+ * ```
54
+ *
55
+ * The formatter shall return an array of arguments, which are passed to the logger (for example, `console.log()`)
56
+ *
57
+ * @param module logger name
58
+ * @param level log level
59
+ * @param args additional arguments
60
+ */
61
+ format(module: string, level: number, args: any[]): any[]
62
+ }
63
+
64
+ declare class Logger {
65
+ /**
66
+ * Logs with 'trace' level
67
+ */
68
+ trace: Log
69
+ /**
70
+ * Logs with 'debug' level
71
+ */
72
+ debug: Log
73
+ /**
74
+ * Logs with 'info' level
75
+ */
76
+ info: Log
77
+ /**
78
+ * Logs with 'warn' level
79
+ */
80
+ warn: Log
81
+ /**
82
+ * Logs with 'error' level
83
+ */
84
+ error: Log
85
+ /**
86
+ * Logs with default level
87
+ */
88
+ log: Log
89
+
90
+ /**
91
+ * @returns whether 'trace' level is active
92
+ */
93
+ _trace: boolean
94
+ /**
95
+ * @returns whether 'debug' level is active
96
+ */
97
+ _debug: boolean
98
+ /**
99
+ * @returns whether 'info' level is active
100
+ */
101
+ _info: boolean
102
+ /**
103
+ * @returns whether 'warn' level is active
104
+ */
105
+ _warn: boolean
106
+ /**
107
+ * @returns whether 'error' level is active
108
+ */
109
+ _error: boolean
110
+ }
111
+
112
+ declare type Log = {
113
+ /**
114
+ * Logs a message
115
+ *
116
+ * @param message text to log
117
+ * @param optionalParams additional parameters, same as in `console.log(text, param1, ...)`
118
+ */
119
+ (message?: any, ...optionalParams: any[]): void
120
+ }
121
+
122
+ declare enum levels {
123
+ SILENT = 0, ERROR = 1, WARN = 2, INFO = 3, DEBUG = 4, TRACE = 5, SILLY = 5, VERBOSE = 5
124
+ }
package/apis/ql.d.ts CHANGED
@@ -15,6 +15,31 @@ export class cds_ql {
15
15
  ql:QL & ((context:object) => QL)
16
16
  }
17
17
 
18
+ export type PK = number | string | object
19
+
20
+ // to support path expressions: https://pages.github.tools.sap/cap/docs/java/query-api#path-expressions
21
+ // `Book.title` == `Proxy<Book>.title()`
22
+ type Proxy<T> = {
23
+ [Key in keyof T]: () => Proxy<T[Key]>
24
+ } & {
25
+ /**
26
+ * Accesses any nested attribute based on a path:
27
+ * `X.get('a.b.c.d')`. Note that you will not receive
28
+ * proper typing after this call.
29
+ * To still have access to typed results, use
30
+ * `X.a().b().c().d()` instead.
31
+ */
32
+ get: (path: string) => Proxy<unknown>
33
+ }
34
+
35
+ // any class (not value) of array to represent plural types used in cds-typer.
36
+ // Mainly used as pattern match for SingularType
37
+ type ArrayClass = {new():Array<unknown>}
38
+
39
+ // concrete singular type.
40
+ // `SingularType<typeof Books>` == `Book`.
41
+ type SingularType<T extends ArrayClass> = InstanceType<T>[number]
42
+
18
43
  declare class QL {
19
44
  SELECT : typeof SELECT & ((...columns:string[]) => SELECT<any>) & ((columns:string[]) => SELECT<any>)
20
45
  INSERT : typeof INSERT & ((...entries:object[]) => INSERT<any>) & ((entries:object[]) => INSERT<any>)
@@ -26,12 +51,14 @@ declare class QL {
26
51
 
27
52
  // (new QL).SELECT.from('Foo').byKey(11).a
28
53
 
54
+
55
+
29
56
  export class SELECT<T> extends ConstructedQuery {
30
57
  static one : SELECT_one & { from: SELECT_one }
31
58
  static distinct : typeof SELECT
32
59
  static from : SELECT_from
33
- from (entity: Definition | string, primaryKey? : number | string | object, projection? : (e:any)=>void) : this
34
- byKey (primaryKey? : number | string | object) : this
60
+ from (entity: Definition | string, primaryKey? : PK, projection? : (e:any)=>void) : this
61
+ byKey (primaryKey? : PK) : this
35
62
  columns (projection:(e:T)=>void) : this
36
63
  columns (...col:string[]) : this
37
64
  where (predicate:object) : this
@@ -43,23 +70,53 @@ export class SELECT<T> extends ConstructedQuery {
43
70
  groupBy (...expr : string[]) : this
44
71
  orderBy (...expr : string[]) : this
45
72
  limit (rows : number, offset? : number) : this
73
+ forSharedLock () : this
74
+ forUpdate () : this
46
75
  SELECT : CQN.SELECT
47
76
  }
48
77
 
49
78
  type SELECT_one =
50
- ((entity: Definition | string, primaryKey? : number | string | object, projection? : (e:any)=>void) => SELECT<any>)
79
+ ((entity: Definition | string, primaryKey? : PK, projection? : (e:any)=>void) => SELECT<any>)
80
+
81
+ // calling with class
82
+ & (<T extends ArrayClass>
83
+ (entityType: T)
84
+ => SELECT<SingularType<T>> & Promise<SingularType<T>>)
85
+ &
86
+ (<T extends ArrayClass>
87
+ (entityType: T, projection: (e: Proxy<SingularType<T>>) => void)
88
+ => SELECT<SingularType<T>> & Promise<SingularType<T>>)
89
+ &
90
+ (<T extends ArrayClass>
91
+ (entityType: T, primaryKey : PK, projection: (e: Proxy<SingularType<T>>) => void)
92
+ => SELECT<SingularType<T>> & Promise<SingularType<T>>)
93
+
94
+
51
95
  & (<T> (entity: T[], projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
52
- & (<T> (entity: T[], primaryKey : number | string | object, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
96
+ & (<T> (entity: T[], primaryKey : PK, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
53
97
  & (<T> (entity: {new():T}, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
54
- & (<T> (entity: {new():T}, primaryKey : number | string | object, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
98
+ & (<T> (entity: {new():T}, primaryKey : PK, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
99
+
55
100
 
56
101
 
57
102
  type SELECT_from =
58
- ((entity: Definition | string, primaryKey? : number | string | object, projection? : (e:any)=>void) => SELECT<any>)
103
+ // calling with class
104
+ (<T extends ArrayClass>
105
+ (entityType: T)
106
+ => SELECT<SingularType<T>> & Promise<SingularType<T>>)
107
+ &
108
+ (<T extends ArrayClass>
109
+ (entityType: T, projection: (e: Proxy<SingularType<T>>) => void)
110
+ => SELECT<SingularType<T>> & Promise<SingularType<T>>)
111
+ &
112
+ (<T extends ArrayClass>
113
+ (entityType: T, primaryKey : PK, projection: (e: Proxy<SingularType<T>>) => void)
114
+ => SELECT<SingularType<T>> & Promise<SingularType<T>>)
115
+ // calling with definition
116
+ & ((entity: Definition | string, primaryKey? : PK, projection? : (e:any)=>void) => SELECT<any>)
117
+ // calling with concrete list
59
118
  & (<T> (entity: T[], projection? : (e:T)=>void) => SELECT<T> & Promise<T[]>)
60
- & (<T> (entity: T[], primaryKey : number | string | object, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
61
- & (<T> (entity: {new():T}, projection? : (e:T)=>void) => SELECT<T> & Promise<T[]>)
62
- & (<T> (entity: {new():T}, primaryKey : number | string | object, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
119
+ & (<T> (entity: T[], primaryKey : PK, projection? : (e:T)=>void) => SELECT<T> & Promise<T>)
63
120
 
64
121
 
65
122
  export class INSERT<T> extends ConstructedQuery {
@@ -76,8 +133,8 @@ export class INSERT<T> extends ConstructedQuery {
76
133
  }
77
134
 
78
135
  export class DELETE<T> extends ConstructedQuery {
79
- static from (entity : Definition | string, primaryKey? : number | string | object) : DELETE<any>
80
- byKey (primaryKey? : number | string | object) : this
136
+ static from (entity : Definition | string, primaryKey? : PK) : DELETE<any>
137
+ byKey (primaryKey? : PK) : this
81
138
  where (predicate:object) : this
82
139
  where (...expr : any[]) : this
83
140
  and (predicate:object) : this
@@ -86,10 +143,10 @@ export class DELETE<T> extends ConstructedQuery {
86
143
  }
87
144
 
88
145
  export class UPDATE<T> extends ConstructedQuery {
89
- static entity (entity : Definition | string, primaryKey? : number | string | object) : UPDATE<any>
90
- static entity <T> (entity:Constructable<T>, primaryKey? : number | string | object) : UPDATE<T>
91
- static entity <T> (entity:T, primaryKey? : number | string | object) : UPDATE<T>
92
- byKey (primaryKey? : number | string | object) : this
146
+ static entity (entity : Definition | string, primaryKey? : PK) : UPDATE<any>
147
+ static entity <T> (entity:Constructable<T>, primaryKey? : PK) : UPDATE<T>
148
+ static entity <T> (entity:T, primaryKey? : PK) : UPDATE<T>
149
+ byKey (primaryKey? : PK) : this
93
150
  // with (block: (e:T)=>void) : this
94
151
  // set (block: (e:T)=>void) : this
95
152
  set (data:object) : this
@@ -34,7 +34,7 @@ export class QueryAPI {
34
34
  /**
35
35
  * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
36
36
  */
37
- run (query : ConstructedQuery) : Promise<ResultSet | any>
37
+ run (query : ConstructedQuery|ConstructedQuery[]) : Promise<ResultSet | any>
38
38
 
39
39
  /**
40
40
  * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
@@ -42,6 +42,11 @@ export class QueryAPI {
42
42
  run (query : Query) : Promise<ResultSet | any>
43
43
 
44
44
  /**
45
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run-sql)
46
+ */
47
+ run (query : string, args? : any[]|object) : Promise<ResultSet | any>
48
+
49
+ /**
45
50
  * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
46
51
  */
47
52
  foreach (query : Query, callback: (row:object) => void) : this
@@ -141,6 +146,12 @@ export class Service extends QueryAPI {
141
146
  send (details: { event: Events, data?: object, headers?: object }) : Promise<this>
142
147
 
143
148
  /**
149
+ * Constructs and sends a synchronous request.
150
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
151
+ */
152
+ send (details: { query: ConstructedQuery, headers?: object }) : Promise<this>
153
+
154
+ /**
144
155
  * Constructs and sends a GET request.
145
156
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
146
157
  */
@@ -190,7 +201,7 @@ export class Service extends QueryAPI {
190
201
 
191
202
  }
192
203
 
193
- export interface Transaction extends QueryAPI {
204
+ export interface Transaction extends Service {
194
205
  commit() : Promise<void>
195
206
  rollback() : Promise<void>
196
207
  }
@@ -187,9 +187,8 @@ class BuildTaskHandler {
187
187
  return null
188
188
  }
189
189
  this._logger._debug && this._logger.debug(`model: ${relativePaths(this._buildOptions.root, files).join(", ")}`)
190
- const options = { messages: this._messages }
191
190
  // $location paths are relative to current working dir by default - make sure a given project root folder is taken
192
- options.cwd = this._buildOptions.root
191
+ const options = { ...this.options(), cwd: this._buildOptions.root }
193
192
 
194
193
  const model = await this._cds.load(files, options)
195
194
  if (!model) {
@@ -198,6 +197,10 @@ class BuildTaskHandler {
198
197
  return model
199
198
  }
200
199
 
200
+ options() {
201
+ return { messages: this._messages }
202
+ }
203
+
201
204
  /**
202
205
  * Adds the given fully qualified file path to the list of files that are written by this build task.
203
206
  * @param {string} filePath
@@ -14,7 +14,8 @@ exports.BUILD_TASK_HANA = "hana"
14
14
  exports.BUILD_TASK_FIORI = "fiori"
15
15
  exports.BUILD_TASK_MTX = "mtx"
16
16
  exports.BUILD_TASK_MTX_SIDECAR = "mtx-sidecar"
17
- exports.BUILD_TASKS = [this.BUILD_TASK_JAVA, this.BUILD_TASK_JAVA_CF, this.BUILD_TASK_NODEJS, this.BUILD_TASK_NODE_CF, this.BUILD_TASK_HANA, this.BUILD_TASK_FIORI, this.BUILD_TASK_MTX, this.BUILD_TASK_MTX_SIDECAR]
17
+ exports.BUILD_TASK_MTX_EXTENSION = "mtx-extension"
18
+ exports.BUILD_TASKS = [this.BUILD_TASK_JAVA, this.BUILD_TASK_JAVA_CF, this.BUILD_TASK_NODEJS, this.BUILD_TASK_NODE_CF, this.BUILD_TASK_HANA, this.BUILD_TASK_FIORI, this.BUILD_TASK_MTX, this.BUILD_TASK_MTX_SIDECAR, this.BUILD_TASK_MTX_EXTENSION]
18
19
 
19
20
  exports.ODATA_VERSION = "odata.version"
20
21
  exports.ODATA_VERSION_V2 = "v2"
@@ -44,6 +45,7 @@ exports.CSV_FILE_DETECTION = "csvFileDetection" // detect CSV files
44
45
  exports.FOLDER_GEN = "gen"
45
46
  exports.FILE_EXT_CDS = ".cds"
46
47
  exports.MTX_SIDECAR_FOLDER = "mtx/sidecar" // default name of the mtx sidecar folder
48
+ exports.DEFAULT_CSN_FILE_NAME = "csn.json"
47
49
 
48
50
  exports.CDS_CONFIG_PATH_SEP = "/"
49
51
  exports.SKIP_ASSERT_COMPILER_V2 = "skip-assert-compiler-v2"
@@ -59,3 +61,4 @@ exports.LOG_LEVEL_DEBUG = "debug"
59
61
  exports.LOG_LEVELS = [exports.LOG_LEVEL_ERROR, exports.LOG_LEVEL_WARN, exports.LOG_LEVEL_INFO, exports.LOG_LEVEL_DEBUG]
60
62
  exports.LOG_MODULE_NAMES = "cds|build"
61
63
  exports.OVERRIDE_METHOD_MSG = "Must override method"
64
+ exports.SEMVER_REGEX = /^(\D*)(\d+\.)?(\d+\.)?(\*|\d+)/