@sap/cds 6.3.2 → 6.4.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 (112) hide show
  1. package/CHANGELOG.md +76 -0
  2. package/apis/cds.d.ts +1 -1
  3. package/apis/core.d.ts +118 -90
  4. package/apis/cqn.d.ts +11 -2
  5. package/apis/internal/inference.d.ts +7 -2
  6. package/apis/ql.d.ts +45 -11
  7. package/apis/serve.d.ts +8 -1
  8. package/apis/services.d.ts +303 -305
  9. package/bin/build/buildTaskEngine.js +28 -36
  10. package/bin/build/buildTaskFactory.js +32 -81
  11. package/bin/build/buildTaskHandler.js +3 -2
  12. package/bin/build/buildTaskProvider.js +2 -2
  13. package/bin/build/buildTaskProviderFactory.js +5 -14
  14. package/bin/build/constants.js +0 -1
  15. package/bin/build/provider/buildTaskHandlerEdmx.js +7 -6
  16. package/bin/build/provider/buildTaskHandlerFeatureToggles.js +6 -5
  17. package/bin/build/provider/buildTaskHandlerInternal.js +9 -30
  18. package/bin/build/provider/buildTaskProviderInternal.js +70 -58
  19. package/bin/build/provider/fiori/index.js +6 -5
  20. package/bin/build/provider/hana/2migration.js +20 -3
  21. package/bin/build/provider/hana/2tabledata.js +1 -0
  22. package/bin/build/provider/hana/index.js +40 -17
  23. package/bin/build/provider/java/index.js +10 -10
  24. package/bin/build/provider/mtx/index.js +25 -16
  25. package/bin/build/provider/mtx/resourcesTarBuilder.js +22 -27
  26. package/bin/build/provider/mtx-extension/index.js +3 -2
  27. package/bin/build/provider/mtx-sidecar/index.js +16 -15
  28. package/bin/build/provider/nodejs/index.js +14 -56
  29. package/bin/build/util.js +56 -16
  30. package/bin/deploy/to-hana/cfUtil.js +2 -0
  31. package/bin/deploy/to-hana/gitUtil.js +1 -1
  32. package/bin/deploy/to-hana/hana.js +45 -38
  33. package/bin/deploy/to-hana/hdiDeployUtil.js +8 -9
  34. package/bin/deploy/to-hana/mtaUtil.js +13 -14
  35. package/bin/mtx/in-cds.js +3 -1
  36. package/bin/serve.js +1 -1
  37. package/bin/version.js +2 -1
  38. package/lib/compile/cds-compile.js +1 -0
  39. package/lib/compile/cdsc.js +1 -0
  40. package/lib/compile/etc/_localized.js +2 -2
  41. package/lib/compile/for/lean_drafts.js +83 -0
  42. package/lib/compile/for/nodejs.js +1 -0
  43. package/lib/compile/minify.js +2 -1
  44. package/lib/compile/to/gql.js +1 -1
  45. package/lib/compile/to/sql.js +11 -1
  46. package/lib/core/entities.js +1 -1
  47. package/lib/core/index.js +8 -9
  48. package/lib/core/infer.js +1 -0
  49. package/lib/dbs/cds-deploy.js +97 -41
  50. package/lib/env/cds-env.js +9 -10
  51. package/lib/env/cds-requires.js +8 -2
  52. package/lib/env/defaults.js +0 -4
  53. package/lib/env/schemas/cds-rc.json +38 -0
  54. package/lib/ql/SELECT.js +10 -4
  55. package/lib/srv/bindings.js +1 -1
  56. package/lib/srv/factory.js +1 -1
  57. package/lib/srv/srv-methods.js +1 -1
  58. package/lib/utils/cds-utils.js +11 -0
  59. package/lib/utils/inflect.js +13 -12
  60. package/lib/utils/tar.js +12 -4
  61. package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +2 -2
  62. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +1 -1
  63. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +1 -1
  64. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/delete.js +1 -1
  65. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +1 -15
  66. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +1 -1
  67. package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +1 -1
  68. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/errors/UriSyntaxError.js +1 -1
  69. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriParser.js +6 -1
  70. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/utils/BufferedWriter.js +1 -1
  71. package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/validator/ConditionalRequestValidator.js +0 -12
  72. package/libx/_runtime/cds-services/adapter/odata-v4/utils/oDataConfiguration.js +1 -7
  73. package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +4 -0
  74. package/libx/_runtime/cds-services/services/Service.js +23 -1
  75. package/libx/_runtime/cds-services/util/assert.js +0 -41
  76. package/libx/_runtime/common/composition/data.js +5 -1
  77. package/libx/_runtime/common/generic/auth/utils.js +3 -3
  78. package/libx/_runtime/common/generic/input.js +4 -24
  79. package/libx/_runtime/common/generic/paging.js +3 -3
  80. package/libx/_runtime/common/utils/csn.js +21 -15
  81. package/libx/_runtime/common/utils/draft.js +2 -1
  82. package/libx/_runtime/common/utils/resolveView.js +25 -4
  83. package/libx/_runtime/common/utils/rewriteAsterisks.js +3 -1
  84. package/libx/_runtime/common/utils/rowUUIDGenerator.js +21 -0
  85. package/libx/_runtime/common/utils/templateProcessor.js +12 -15
  86. package/libx/_runtime/common/utils/templateProcessorPathSerializer.js +23 -0
  87. package/libx/_runtime/db/expand/expandCQNToJoin.js +29 -12
  88. package/libx/_runtime/db/generic/input.js +7 -13
  89. package/libx/_runtime/db/sql-builder/UpsertBuilder.js +47 -0
  90. package/libx/_runtime/db/sql-builder/index.js +2 -0
  91. package/libx/_runtime/db/sql-builder/sqlFactory.js +9 -0
  92. package/libx/_runtime/db/utils/columns.js +4 -2
  93. package/libx/_runtime/fiori/generic/read.js +1 -12
  94. package/libx/_runtime/fiori/lean-draft.js +657 -0
  95. package/libx/_runtime/fiori/utils/handler.js +1 -1
  96. package/libx/_runtime/hana/pool.js +16 -1
  97. package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +2 -1
  98. package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +1 -1
  99. package/libx/_runtime/messaging/enterprise-messaging.js +2 -3
  100. package/libx/_runtime/messaging/outbox/utils.js +109 -70
  101. package/libx/_runtime/messaging/service.js +16 -7
  102. package/libx/_runtime/remote/Service.js +15 -2
  103. package/libx/_runtime/remote/utils/client.js +41 -11
  104. package/libx/_runtime/sqlite/Service.js +3 -0
  105. package/libx/_runtime/sqlite/convertDraftAdminPathExpression.js +56 -0
  106. package/libx/_runtime/sqlite/customBuilder/CustomUpsertBuilder.js +59 -0
  107. package/libx/_runtime/sqlite/customBuilder/index.js +5 -0
  108. package/libx/_runtime/sqlite/execute.js +1 -1
  109. package/libx/_runtime/types/api.js +2 -2
  110. package/libx/rest/RestAdapter.js +15 -13
  111. package/package.json +1 -1
  112. package/server.js +1 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,81 @@
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.4.0 - 2022-12-15
8
+
9
+ ### Added
10
+
11
+ - Signatures for `ql.UPSERT`
12
+ - Runtime support for flat database UPSERTs
13
+ - `enterprise-messaging`: Support for `@sap/cds-mtxs`
14
+ - `persistent-outbox`: Support for parallel processing with option `parallel: true` as well as pluggable processor functions through `service.outbox.process` (beta)
15
+ - `cds version` now also lists packages with `@cap-js/` prefix from dependencies
16
+ - `cds.context.http` is now available for webhook-based requests
17
+ - `cds build` for HANA migration tables now only saves model entities annotated with `@cds.persistence.journal` as `last-dev` version.
18
+ - `cds deploy` now uses the `VCAP_SERVICES` environment variable (if set), and skips `cf` operations in this case
19
+
20
+ ### Changed
21
+
22
+ - `.columns(…)` of both `cql.SELECT` and `cql.INSERT` give improved code completion when paired when appropriate type definitions are present
23
+ - 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.
24
+ - 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.
25
+ - `persistent-outbox`: Only programming errors lead to `process.exit()`, unrecoverable ones are only logged and their `attempts` are updated to `options.maxAttempts`
26
+ - Global configuration of CSRF-token handling for remote services `cds.env.features.fetch_csrf` is deprecated. Instead, please use `csrf: true/false` and `csrfInBatch: true/false` in the configuration of your remote services. These options will allow to configure CSRF-token handling for each remote service separately.
27
+ - `cds build` no longer creates `engines` entry in package.json in case none has been defined. The Node.js version matched the minimal supported version of the CDS runtime and might therefore already be outdated.
28
+ - For streamlined MTX, `@sap/cds` now uses the custom SAP Service Manager client built into `@sap/cds-mtxs`
29
+ - Require new package `@cap-js/graphql` for `cds compile -2 graphql`
30
+
31
+ ### Fixed
32
+
33
+ - Type `expr` of CQN can now describe function calls
34
+ - Added missing optional `options` parameter in signature of `cds.serve`
35
+ - `cds deploy` handles empty result from `cf` call correctly
36
+ - When using CQL projections with array types, the type of the projection variable will now be correctly inferred as a single element of that array
37
+ - `cds deploy` logs without label
38
+ - Localized draft requests with nested expand in the case of `to many` now return localized data
39
+ - Protected service root for REST adapter
40
+ - `cds build` logs tar error message
41
+ - Resolve view only with renamed fields in orderBy case
42
+ - In case of `$apply` no default values for `top` or `skip` are set in subselects
43
+ - Environment variables like `cds.requires.<service>.kind...` now consistently override services set in e.g. `package.json`
44
+ - Expand of composition backlink now accesses draft instance instead of active
45
+ - Performance of server bootstrap for services with lots of entities
46
+ - Error with virtual properties in expand combined with draft
47
+ - req.tenant is properly propagated by custom authentication in odata and rest
48
+ - Error with `SiblingEntity` in draft
49
+ - Quoting of keys typed as `cds.String` in error targets. Error targets are a relative resource path to correlate error
50
+ messages with the corresponding text input filed in the UI in an OData HTTP error response body for errors, warnings,
51
+ and info messages. For example:
52
+
53
+ ```diff
54
+ HTTP/1.1 400 Bad Request
55
+ OData-Version: 4.0
56
+ content-type: application/json;odata.metadata=minimal
57
+ Connection: close
58
+ Content-Length: 145
59
+
60
+ {
61
+ "error": {
62
+ "code": "400",
63
+ "message": "Value is required",
64
+ - "target": "items(ID=string-key-1)/text",
65
+ + "target": "items(ID='string-key-1')/text",
66
+ "@Common.numericSeverity": 4
67
+ }
68
+ }
69
+ ```
70
+
71
+ - Application crash if batched Uri uses invalid percent encoding
72
+ - `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.
73
+ - `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.
74
+ - `cds build` for Java no longer adds the service `cds.xt.MTXServices` to the application model.
75
+ - `cds build` no longer fails when creating large resource TAR archives for MTXS projects.
76
+
77
+ ### Removed
78
+
79
+ - Removed `PreconditionFailedError` when sending a request with an `if-match` header on an entity without an etag
80
+ - Check for forbidden deep operations for associations on database layer. All non key fields for associations provided by request are ignored. Please check https://cap.cloud.sap/docs/guides/providing-services#associations-vs-compositions for more information. Note that this is a breaking change for applications that rely on checks for forbidden deep operations by runtime.
81
+
7
82
  ## Version 6.3.2 - 2022-11-21
8
83
 
9
84
  ### Fixed
@@ -57,6 +132,7 @@
57
132
  ### Changed
58
133
 
59
134
  - In `enterprise-messaging`, emitting CloudEvents messages sets the HTTP header `Content-Type: application/cloudevents+json`
135
+ - Added type definition for `cds.User`
60
136
 
61
137
  ### Fixed
62
138
 
package/apis/cds.d.ts CHANGED
@@ -22,7 +22,7 @@ declare global {
22
22
  const DROP: typeof cds.ql.DROP
23
23
 
24
24
  // and these allow us to use them as type too, i.e. `const q: SELECT<Book> = ...`
25
- type SELECT<T> = ql.SELECT<T>
25
+ type SELECT<T> = ql.SELECT<T>
26
26
  type INSERT<T> = ql.INSERT<T>
27
27
  type UPDATE<T> = ql.UPDATE<T>
28
28
  type DELETE<T> = ql.DELETE<T>
package/apis/core.d.ts CHANGED
@@ -1,108 +1,136 @@
1
1
  // import types from '../lib/core'
2
2
  import { ReflectedModel, LinkedModel, LinkedDefinition } from './reflect'
3
- import { CSN as csn, Definition } from "./csn"
3
+ import { CSN as csn, Definition } from './csn'
4
4
 
5
- export = cds
6
- declare class cds {
5
+ type UserInput = string | { id: string; attr: Record<string, string>; roles: Record<string, string> } | User
7
6
 
8
- /**
9
- * Turns the given plain CSN model into a linked model
10
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
11
- */
12
- linked (model : csn) : LinkedModel
13
-
14
- /**
15
- * Turns the given plain CSN model into a reflected model
16
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
17
- */
18
- reflect (model : csn) : ReflectedModel
7
+ declare class User {
8
+ constructor(obj?: UserInput)
9
+ id: string
10
+ /**
11
+ * @deprecated Use https://cap.cloud.sap/docs/node.js/events#locale instead
12
+ */
13
+ locale: string
14
+ /**
15
+ * @deprecated Use https://cap.cloud.sap/docs/node.js/events#tenant instead
16
+ */
17
+ tenant: string | undefined
18
+ attr: Record<string, string>
19
+ roles: Record<string, string>
20
+ static Privileged: typeof Privileged
21
+ is(role: string): boolean
22
+ }
23
+ /**
24
+ * Subclass for executing code with superuser privileges.
25
+ */
26
+ declare class Privileged extends User {
27
+ constructor()
28
+ is(): boolean
29
+ }
19
30
 
31
+ export = cds
32
+ declare class cds {
33
+ /**
34
+ * Turns the given plain CSN model into a linked model
35
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
36
+ */
37
+ linked(model: csn): LinkedModel
20
38
 
21
- // infer (query : cqn, model : csn) : LinkedDefinition
39
+ /**
40
+ * Turns the given plain CSN model into a reflected model
41
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect)
42
+ */
43
+ reflect(model: csn): ReflectedModel
22
44
 
23
- builtin: {
24
- /**
25
- * Base classes of linked definitions from reflected models.
26
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-builtin-classes)
27
- */
28
- classes: {
29
- Association : Definition
30
- Composition : Definition
31
- context : Definition
32
- service : Definition
33
- type : Definition
34
- array : Definition
35
- struct : Definition
36
- entity : Definition
37
- event : Definition
38
- },
39
- types: {},
40
- }
45
+ /**
46
+ * Represents the user in a given context.
47
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/authentication#cds-user)
48
+ */
49
+ User: typeof User
41
50
 
42
- /**
43
- * Base class for linked Associations from reflected models.
44
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-Association)
45
- */
46
- Association : Definition
51
+ // infer (query : cqn, model : csn) : LinkedDefinition
47
52
 
48
- /**
49
- * Base class for linked Compositions from reflected models.
50
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-Association)
51
- */
52
- Composition : Definition
53
+ builtin: {
54
+ /**
55
+ * Base classes of linked definitions from reflected models.
56
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-builtin-classes)
57
+ */
58
+ classes: {
59
+ Association: Definition
60
+ Composition: Definition
61
+ context: Definition
62
+ service: Definition
63
+ type: Definition
64
+ array: Definition
65
+ struct: Definition
66
+ entity: Definition
67
+ event: Definition
68
+ }
69
+ types: {}
70
+ }
53
71
 
72
+ /**
73
+ * Base class for linked Associations from reflected models.
74
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-Association)
75
+ */
76
+ Association: Definition
54
77
 
55
- /**
56
- * Base class for linked entities from reflected models.
57
- * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-entity)
58
- */
59
- entity : Definition
78
+ /**
79
+ * Base class for linked Compositions from reflected models.
80
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-Association)
81
+ */
82
+ Composition: Definition
60
83
 
61
- struct : Definition
62
- array : Definition
63
- context : Definition
64
- service : Definition
84
+ /**
85
+ * Base class for linked entities from reflected models.
86
+ * @see [capire](https://cap.cloud.sap/docs/node.js/cds-reflect#cds-entity)
87
+ */
88
+ entity: Definition
65
89
 
66
- /**
67
- * Add aspects to a given object, for example:
68
- *
69
- * extend (Object.prototype) .with (class {
70
- * get foo() { return ... }
71
- * bar() {...}
72
- * }.prototype)
73
- */
74
- extend <T> (target:T) : ({
75
- with <X,Y,Z> (x:X, y:Y, z:Z): ( T & X & Y & Z )
76
- with <X,Y> (x:X, y:Y): ( T & X & Y )
77
- with <X> (x:X): ( T & X )
78
- })
90
+ struct: Definition
91
+ array: Definition
92
+ context: Definition
93
+ service: Definition
79
94
 
80
- /**
81
- * Equip a given facade object with getters for lazy-loading modules instead
82
- * of static requires. Example:
83
- *
84
- * const facade = lazify ({
85
- * sub: lazy => require ('./sub-module')
86
- * })
87
- *
88
- * The first usage of `facade.sub` will load the sub module
89
- * using standard Node.js's `module.require` functions.
90
- */
91
- lazify : <T>(target:T) => T
95
+ /**
96
+ * Add aspects to a given object, for example:
97
+ *
98
+ * extend (Object.prototype) .with (class {
99
+ * get foo() { return ... }
100
+ * bar() {...}
101
+ * }.prototype)
102
+ */
103
+ extend<T>(target: T): {
104
+ with<X, Y, Z>(x: X, y: Y, z: Z): T & X & Y & Z
105
+ with<X, Y>(x: X, y: Y): T & X & Y
106
+ with<X>(x: X): T & X
107
+ }
92
108
 
93
- /**
94
- * Prepare a node module for lazy-loading submodules instead
95
- * of static requires. Example:
96
- *
97
- * require = lazify (module) //> turns require into a lazy one
98
- * const facade = module.exports = {
99
- * sub: require ('./sub-module')
100
- * })
101
- *
102
- * The first usage of `facade.sub` will load the sub module
103
- * using standard Node.js's `module.require` functions.
104
- */
105
- lazified : <T>(target:T) => T
109
+ /**
110
+ * Equip a given facade object with getters for lazy-loading modules instead
111
+ * of static requires. Example:
112
+ *
113
+ * const facade = lazify ({
114
+ * sub: lazy => require ('./sub-module')
115
+ * })
116
+ *
117
+ * The first usage of `facade.sub` will load the sub module
118
+ * using standard Node.js's `module.require` functions.
119
+ */
120
+ lazify: <T>(target: T) => T
106
121
 
122
+ /**
123
+ * Prepare a node module for lazy-loading submodules instead
124
+ * of static requires. Example:
125
+ *
126
+ * require = lazify (module) //> turns require into a lazy one
127
+ * const facade = module.exports = {
128
+ * sub: require ('./sub-module')
129
+ * })
130
+ *
131
+ * The first usage of `facade.sub` will load the sub module
132
+ * using standard Node.js's `module.require` functions.
133
+ */
134
+ lazified: <T>(target: T) => T
107
135
  }
108
136
  // & typeof import ('../lib/index')
package/apis/cqn.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export type Query = SELECT | INSERT | UPDATE | DELETE | CREATE | DROP
1
+ export type Query = SELECT | INSERT | UPDATE | DELETE | CREATE | DROP | UPSERT
2
2
  export type ParsedExpr = expr & { _:string }
3
3
 
4
4
  export type SELECT = {SELECT:{
@@ -22,6 +22,14 @@ export type INSERT = {INSERT:{
22
22
  rows : any[]
23
23
  }}
24
24
 
25
+ export type UPSERT = {UPSERT:{
26
+ into : name
27
+ entries : any[]
28
+ columns : string[]
29
+ values : any[]
30
+ rows : any[]
31
+ }}
32
+
25
33
  export type UPDATE = {UPDATE:{
26
34
  entity : name
27
35
  data : { [key:string] : expr }
@@ -47,12 +55,13 @@ export type column_expr = expr & { as?: name, cast?:any, expand?: column_expr[],
47
55
  export type predicate = _xpr
48
56
  type ordering_term = expr & { sort?: "asc"|"desc", nulls?: "first"|"last" }
49
57
 
50
- export type expr = ref | val | xpr | SELECT
58
+ export type expr = ref | val | xpr | function_call | SELECT
51
59
  type ref = {ref:( name & { id?:string, where?:expr, args?:expr[] } )[]}
52
60
  type val = {val:any}
53
61
  type xpr = {xpr:_xpr}
54
62
  type _xpr = ( expr | operator ) []
55
63
  type operator = string
64
+ type function_call = {func: string, args: {[key: string]: unknown}[]}
56
65
 
57
66
  export type enum_literal = {"#": string}
58
67
  export type expr_literal = {"=": string}
@@ -2,13 +2,18 @@
2
2
  // They are merely meant as definitions that are used
3
3
  // in several places within the API.
4
4
 
5
+
6
+ export interface Constructable<T> {
7
+ new(...args: any[]): T
8
+ }
9
+
5
10
  // any class (not value) of array to represent plural types used in cds-typer.
6
11
  // Mainly used as pattern match for SingularType
7
12
  //type ArrayConstructable = Constructable<Array<unknown>>
8
- export interface ArrayConstructable<T = any[]> {
13
+ export interface ArrayConstructable<T = any> {
9
14
  new(...args: any[]): T[]
10
15
  }
11
16
 
12
17
  // concrete singular type.
13
- // `SingularType<Books>` == `Book`.
18
+ // `SingularType<typeof Books>` == `Book`.
14
19
  export type SingularType<T extends ArrayConstructable<T>> = InstanceType<T>[number]
package/apis/ql.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import {Definition} from "./csn"
2
2
  import * as CQN from "./cqn"
3
- import { ArrayConstructable, SingularType } from "./internal/inference"
3
+ import { Constructable, ArrayConstructable, SingularType } from "./internal/inference"
4
4
 
5
5
  export type Query = CQN.Query
6
6
 
@@ -8,10 +8,6 @@ export class ConstructedQuery {
8
8
  then(_resolved:(x:any)=>any, _rejected:(e:Error)=>any) : any
9
9
  }
10
10
 
11
- interface Constructable<T> {
12
- new(...args: any[]): T
13
- }
14
-
15
11
  export class cds_ql {
16
12
  ql:QL<any> & ((context:object) => QL<any>)
17
13
  }
@@ -36,7 +32,12 @@ interface QLExtensions {
36
32
  */
37
33
  type Subqueryable <T> = ((fn:((a:T)=>any)|"*") => T)
38
34
 
39
- type Proxy_<T> = {
35
+
36
+ /**
37
+ * Wrap every attribute into a proxy that supports operations
38
+ * in addition to its regular capabilities.
39
+ */
40
+ type ProxiedAttributes<T> = {
40
41
  [Key in keyof T]: Proxy<T[Key]> //& QLExtensions
41
42
  } & {
42
43
  /**
@@ -49,15 +50,23 @@ type Proxy_<T> = {
49
50
  get: (path: string) => any // Proxy<unknown>
50
51
  } & QLExtensions
51
52
 
52
- export type Proxy<T> = (T extends Subqueryable<infer U>
53
- ? (Omit<T, ""> & Subqueryable<Proxy<U>>) // drop ((x: T) => T) in favour of (x: Proxy<T>) => Proxy<T>)
54
- : (Proxy_<T>))
53
+ /**
54
+ * Entrance type for Proxies. The conditional makes sure that we don't
55
+ * wrap properties into multiple layers of proxy.
56
+ * Proxy_ was required as we can't circularily reference a type during its definition.
57
+ * So `Proxy<T> = T extends Proxy<any> ...` was not possible.
58
+ */
59
+ export type Proxy<T> = T extends Proxy_<any> ? T : Proxy_<T>
60
+
61
+ export type Proxy_<T> = (T extends Subqueryable<infer U>
62
+ ? (Omit<T, ""> & Subqueryable<Proxy_<U>>) // drop ((x: T) => T) in favour of (x: Proxy<T>) => Proxy<T>)
63
+ : (ProxiedAttributes<T>))
55
64
  & QLExtensions
56
65
 
57
66
  // Alias for projections
58
67
  // https://cap.cloud.sap/docs/node.js/cds-ql?q=projection#projection-functions
59
- export type Projection<T> = (e:T)=>void
60
-
68
+ //export type Projection<T> = (e:T)=>void
69
+ export type Projection<T> = (e:Proxy<T extends ArrayConstructable ? SingularType<T> : T>)=>void
61
70
  // Type for query pieces that can either be chained to build more complex queries or
62
71
  // awaited to materialise the result:
63
72
  // `Awaitable<SELECT<Book>, Book> = SELECT<Book> & Promise<Book>`
@@ -75,6 +84,7 @@ export type Awaitable<T, I> = T & Promise<I>
75
84
  // all the functionality of an instance of SELECT, but directly callable:
76
85
  // new SELECT(...).(...) == SELECT(...)
77
86
  export type StaticSELECT<T> = typeof SELECT
87
+ & ((...columns: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) => SELECT<T>)
78
88
  & ((...columns:string[]) => SELECT<T>)
79
89
  & ((columns:string[]) => SELECT<T>)
80
90
  & (TaggedTemplateQueryPart<SELECT<T>>)
@@ -108,6 +118,7 @@ export class SELECT<T> extends ConstructedQuery {
108
118
  byKey (primaryKey? : PK) : this
109
119
  columns: TaggedTemplateQueryPart<this>
110
120
  & ((projection: Projection<T>) => this)
121
+ & ((...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) => this)
111
122
  & ((...col:string[]) => this)
112
123
  where: TaggedTemplateQueryPart<this>
113
124
  & ((predicate:object) => this)
@@ -190,12 +201,35 @@ export class INSERT<T> extends ConstructedQuery {
190
201
  & ((entity : Definition | string) => this)
191
202
  data (block : (e:T)=>void) : this
192
203
  entries (...entries : object[]) : this
204
+ columns (...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) : this
193
205
  columns (...col: string[]) : this
194
206
  values (... val: any[]) : this
195
207
  rows (... row: any[]) : this
196
208
  INSERT : CQN.INSERT
197
209
  }
198
210
 
211
+
212
+ export class UPSERT<T> extends ConstructedQuery {
213
+ static into : (<T extends ArrayConstructable<any>> (entity:T, entries? : object | object[]) => UPSERT<SingularType<T>>)
214
+ & (TaggedTemplateQueryPart<UPSERT<unknown>>)
215
+ & ((entity : Definition | string, entries? : object | object[]) => UPSERT<any>)
216
+ & (<T> (entity:Constructable<T>, entries? : object | object[]) => UPSERT<T>)
217
+ & (<T> (entity:T, entries? : T | object | object[]) => UPSERT<T>)
218
+
219
+ into: (<T extends ArrayConstructable> (entity:T) => this)
220
+ & TaggedTemplateQueryPart<this>
221
+ & ((entity : Definition | string) => this)
222
+ data (block : (e:T)=>void) : this
223
+ entries (...entries : object[]) : this
224
+ columns (...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) : this
225
+ columns (...col: string[]) : this
226
+ values (... val: any[]) : this
227
+ rows (... row: any[]) : this
228
+ UPSERT : CQN.UPSERT
229
+ }
230
+
231
+
232
+
199
233
  export class DELETE<T> extends ConstructedQuery {
200
234
  static from:
201
235
  TaggedTemplateQueryPart<Awaitable<SELECT<unknown>, InstanceType<any>>>
package/apis/serve.d.ts CHANGED
@@ -19,6 +19,13 @@ interface _fluent {
19
19
  // (req,res) : void
20
20
  }
21
21
 
22
+ // these are temporary types until the API has been properly typed.
23
+ interface service_options {
24
+ service?: string | unknown,
25
+ from?: '*' | 'all' | string | unknown,
26
+ [key: string]: unknown
27
+ }
28
+
22
29
  export = cds_serve
23
30
  declare class cds_serve {
24
31
 
@@ -26,7 +33,7 @@ declare class cds_serve {
26
33
  * Constructs service providers from respective service definitions
27
34
  * @see [capire](https://cap.cloud.sap/docs/node.js/api#cds-serve)
28
35
  */
29
- serve (service : string) : _fluent & Promise<cds_services>
36
+ serve (service : string, options?: service_options) : _fluent & Promise<cds_services>
30
37
 
31
38
  /**
32
39
  * The default bootstrap function as loaded from server.js