@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
@@ -1,92 +1,91 @@
1
1
  import { SELECT, INSERT, UPDATE, DELETE, Query, ConstructedQuery } from './ql'
2
- import { Projection, Proxy, Awaitable } from './ql'
3
- import { SingularType, ArrayConstructable } from './internal/inference'
2
+ import { Projection, Proxy, Awaitable } from './ql'
3
+ import { ArrayConstructable } from './internal/inference'
4
4
  import { LinkedModel, Definition, Definitions } from './reflect'
5
- import { csn, type } from "./csn"
5
+ import { csn, type } from './csn'
6
6
  // import { Service } from './cds'
7
7
 
8
8
  export class QueryAPI {
9
-
10
- /**
11
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
12
- */
13
- read: {
14
- <T extends ArrayConstructable<any>>(entity : T, key?: any) : Awaitable<SELECT<T>, InstanceType<T>>
15
- <T>(entity : Definition | string, key?: any) : SELECT<T>
16
- }
17
-
18
- /**
19
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
20
- */
21
- create: {
22
- <T extends ArrayConstructable<any>>(entity : T, key?: any) : INSERT<T>
23
- <T>(entity : Definition | string, key?: any) : INSERT<T>
24
- }
25
-
26
- /**
27
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
28
- */
29
- insert: {
30
- <T extends ArrayConstructable<any>>(data : T) : INSERT<T>
31
- <T>(data : object | object[]) : INSERT<T>
32
- }
33
-
34
- /**
35
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
36
- */
37
- update: {
38
- <T extends ArrayConstructable<any>>(entity : T, key?: any) : UPDATE<T>
39
- <T>(entity : Definition | string, key?: any) : UPDATE<T>
40
- }
41
-
42
- /**
43
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
44
- */
45
- // as delete is the only one of the CRUD methods from QueryAPI
46
- // that is extended in Service, we have to add the second signature down there
47
- // (TS error 2425)
48
- delete <T>(entity : Definition | string, key?: any) : DELETE<T>
49
-
50
- /**
51
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
52
- */
53
- run (query : ConstructedQuery|ConstructedQuery[]) : Promise<ResultSet | any>
54
-
55
- /**
56
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
57
- */
58
- run (query : Query) : Promise<ResultSet | any>
59
-
60
- /**
61
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run-sql)
62
- */
63
- run (query : string, args? : any[]|object) : Promise<ResultSet | any>
64
-
65
- /**
66
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
67
- */
68
- foreach (query : Query, callback: (row:object) => void) : this
69
-
70
- /**
71
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-stream)
72
- */
73
- stream (column:string) : {
74
- from (entity : Definition | string) : {
75
- where (filter : any) : ReadableStream
76
- }
77
- }
78
-
79
- /**
80
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-stream)
81
- */
82
- stream (query:Query) : Promise<ReadableStream>
83
-
84
- /**
85
- * Starts or joins a transaction
86
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-tx)
87
- */
88
- tx (context? : object) : Transaction
89
- transaction (context? : object) : Transaction
9
+ /**
10
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
11
+ */
12
+ read: {
13
+ <T extends ArrayConstructable<any>>(entity: T, key?: any): Awaitable<SELECT<T>, InstanceType<T>>
14
+ <T>(entity: Definition | string, key?: any): SELECT<T>
15
+ }
16
+
17
+ /**
18
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
19
+ */
20
+ create: {
21
+ <T extends ArrayConstructable<any>>(entity: T, key?: any): INSERT<T>
22
+ <T>(entity: Definition | string, key?: any): INSERT<T>
23
+ }
24
+
25
+ /**
26
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
27
+ */
28
+ insert: {
29
+ <T extends ArrayConstructable<any>>(data: T): INSERT<T>
30
+ <T>(data: object | object[]): INSERT<T>
31
+ }
32
+
33
+ /**
34
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
35
+ */
36
+ update: {
37
+ <T extends ArrayConstructable<any>>(entity: T, key?: any): UPDATE<T>
38
+ <T>(entity: Definition | string, key?: any): UPDATE<T>
39
+ }
40
+
41
+ /**
42
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
43
+ */
44
+ // as delete is the only one of the CRUD methods from QueryAPI
45
+ // that is extended in Service, we have to add the second signature down there
46
+ // (TS error 2425)
47
+ delete<T>(entity: Definition | string, key?: any): DELETE<T>
48
+
49
+ /**
50
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
51
+ */
52
+ run(query: ConstructedQuery | ConstructedQuery[]): Promise<ResultSet | any>
53
+
54
+ /**
55
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
56
+ */
57
+ run(query: Query): Promise<ResultSet | any>
58
+
59
+ /**
60
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run-sql)
61
+ */
62
+ run(query: string, args?: any[] | object): Promise<ResultSet | any>
63
+
64
+ /**
65
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
66
+ */
67
+ foreach(query: Query, callback: (row: object) => void): this
68
+
69
+ /**
70
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-stream)
71
+ */
72
+ stream(column: string): {
73
+ from(entity: Definition | string): {
74
+ where(filter: any): ReadableStream
75
+ }
76
+ }
77
+
78
+ /**
79
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-stream)
80
+ */
81
+ stream(query: Query): Promise<ReadableStream>
82
+
83
+ /**
84
+ * Starts or joins a transaction
85
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-tx)
86
+ */
87
+ tx(context?: object): Transaction
88
+ transaction(context?: object): Transaction
90
89
  }
91
90
 
92
91
  /**
@@ -94,207 +93,206 @@ export class QueryAPI {
94
93
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/services)
95
94
  */
96
95
  export class Service extends QueryAPI {
97
-
98
- constructor (name:String, model: csn, options: {
99
- kind: String
100
- impl: String | ServiceImpl
101
- })
102
-
103
- /**
104
- * The name of the service
105
- */
106
- name: string
107
-
108
- /**
109
- * The model from which the service's definition was loaded
110
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
111
- */
112
- model: LinkedModel
113
-
114
- /**
115
- * Provides access to the entities exposed by a service
116
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
117
- */
118
- entities: Definitions & ((namespace: string) => Definitions)
119
-
120
- /**
121
- * Provides access to the events declared by a service
122
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
123
- */
124
- events: Definitions & ((namespace: string) => Definitions)
125
-
126
- /**
127
- * Provides access to the types exposed by a service
128
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
129
- */
130
- types: Definitions & ((namespace: string) => Definitions)
131
-
132
- /**
133
- * Provides access to the operations, i.e. actions and functions, exposed by a service
134
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
135
- */
136
- operations: Definitions & ((namespace: string) => Definitions)
137
-
138
- /**
139
- * Acts like a parameter-less constructor. Ensure to call `await super.init()` to have the base class’s handlers added.
140
- * You may register own handlers before the base class’s ones, to intercept requests before the default handlers snap in.
141
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#cds-service-subclasses)
142
- */
143
- init() : Promise<void>
144
-
145
- /**
146
- * Constructs and emits an asynchronous event.
147
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-emit)
148
- */
149
- emit (details: { event: Events, data?: object, headers?: object }) : Promise<this>
150
-
151
- /**
152
- * Constructs and emits an asynchronous event.
153
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-emit)
154
- */
155
- emit (event: Events, data?: object, headers?: object) : Promise<this>
156
-
157
- /**
158
- * Constructs and sends a synchronous request.
159
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
160
- */
161
- send (event: Events, data?: object, headers?: object) : Promise<this>
162
-
163
- /**
164
- * Constructs and sends a synchronous request.
165
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
166
- */
167
- send (details: { event: Events, data?: object, headers?: object }) : Promise<this>
168
-
169
- /**
170
- * Constructs and sends a synchronous request.
171
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
172
- */
173
- send (details: { query: ConstructedQuery, headers?: object }) : Promise<this>
174
-
175
- /**
176
- * Constructs and sends a GET request.
177
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
178
- */
179
- get (entityOrPath: Target, data?: object) : Promise<this>
180
- /**
181
- * Constructs and sends a POST request.
182
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
183
- */
184
- post (entityOrPath: Target, data?: object) : Promise<this>
185
- /**
186
- * Constructs and sends a PUT request.
187
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
188
- */
189
- put (entityOrPath: Target, data?: object) : Promise<this>
190
- /**
191
- * Constructs and sends a PATCH request.
192
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
193
- */
194
- patch (entityOrPath: Target, data?: object) : Promise<this>
195
- /**
196
- * Constructs and sends a DELETE request.
197
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
198
- */
199
- delete (entityOrPath: Target, data?: object) : Promise<this>
200
- /**
201
- * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
202
- */
203
- delete <T extends ArrayConstructable<any>>(entity : T, key?: any): DELETE<T>
204
- delete <T>(entity : Definition | string, key?: any) : DELETE<T>
205
-
206
- // The central method to dispatch events
207
- dispatch (msg: EventMessage): Promise<any>
208
-
209
-
210
- // Provider API
211
- prepend (fn: ServiceImpl): Promise<this>
212
- on (eve: Events, entity: Target, handler: OnEventHandler): this
213
- on (eve: Events, handler: OnEventHandler): this
214
- // onSucceeded (eve: Events, entity: Target, handler: EventHandler): this
215
- // onSucceeded (eve: Events, handler: EventHandler): this
216
- // onFailed (eve: Events, entity: Target, handler: EventHandler): this
217
- // onFailed (eve: Events, handler: EventHandler): this
218
- before (eve: Events, entity: Target, handler: EventHandler): this
219
- before (eve: Events, handler: EventHandler): this
220
- after (eve: Events, entity: Target, handler: ResultsHandler): this
221
- after (eve: Events, handler: ResultsHandler): this
222
- reject (eves: Events, ...entity: Target[]): this
223
-
96
+ constructor(
97
+ name: String,
98
+ model: csn,
99
+ options: {
100
+ kind: String
101
+ impl: String | ServiceImpl
102
+ }
103
+ )
104
+
105
+ /**
106
+ * The name of the service
107
+ */
108
+ name: string
109
+
110
+ /**
111
+ * The model from which the service's definition was loaded
112
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
113
+ */
114
+ model: LinkedModel
115
+
116
+ /**
117
+ * Provides access to the entities exposed by a service
118
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
119
+ */
120
+ entities: Definitions & ((namespace: string) => Definitions)
121
+
122
+ /**
123
+ * Provides access to the events declared by a service
124
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
125
+ */
126
+ events: Definitions & ((namespace: string) => Definitions)
127
+
128
+ /**
129
+ * Provides access to the types exposed by a service
130
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
131
+ */
132
+ types: Definitions & ((namespace: string) => Definitions)
133
+
134
+ /**
135
+ * Provides access to the operations, i.e. actions and functions, exposed by a service
136
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-reflect)
137
+ */
138
+ operations: Definitions & ((namespace: string) => Definitions)
139
+
140
+ /**
141
+ * Acts like a parameter-less constructor. Ensure to call `await super.init()` to have the base class’s handlers added.
142
+ * You may register own handlers before the base class’s ones, to intercept requests before the default handlers snap in.
143
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#cds-service-subclasses)
144
+ */
145
+ init(): Promise<void>
146
+
147
+ /**
148
+ * Constructs and emits an asynchronous event.
149
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-emit)
150
+ */
151
+ emit(details: { event: Events; data?: object; headers?: object }): Promise<this>
152
+
153
+ /**
154
+ * Constructs and emits an asynchronous event.
155
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-emit)
156
+ */
157
+ emit(event: Events, data?: object, headers?: object): Promise<this>
158
+
159
+ /**
160
+ * Constructs and sends a synchronous request.
161
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend--method-path-data-headers--results-)
162
+ */
163
+ send(event: Events, path: string, data?: object, headers?: object): Promise<this>
164
+
165
+ /**
166
+ * Constructs and sends a synchronous request.
167
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend---method-path--query--event-data-headers---results-)
168
+ */
169
+ send(details: { event: Events; data?: object; headers?: object }): Promise<this>
170
+
171
+ /**
172
+ * Constructs and sends a synchronous request.
173
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend---method-path--query--event-data-headers---results-)
174
+ */
175
+ send(details: { query: ConstructedQuery; data?: object; headers?: object }): Promise<this>
176
+
177
+ /**
178
+ * Constructs and sends a synchronous request.
179
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srvsend---method-path--query--event-data-headers---results-)
180
+ */
181
+ send(details: { method: Event; path: string; data?: object; headers?: object }): Promise<this>
182
+
183
+ /**
184
+ * Constructs and sends a GET request.
185
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
186
+ */
187
+ get(entityOrPath: Target, data?: object): Promise<this>
188
+ /**
189
+ * Constructs and sends a POST request.
190
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
191
+ */
192
+ post(entityOrPath: Target, data?: object): Promise<this>
193
+ /**
194
+ * Constructs and sends a PUT request.
195
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
196
+ */
197
+ put(entityOrPath: Target, data?: object): Promise<this>
198
+ /**
199
+ * Constructs and sends a PATCH request.
200
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
201
+ */
202
+ patch(entityOrPath: Target, data?: object): Promise<this>
203
+ /**
204
+ * Constructs and sends a DELETE request.
205
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services#srv-send)
206
+ */
207
+ delete(entityOrPath: Target, data?: object): Promise<this>
208
+ /**
209
+ * @see [docs](https://cap.cloud.sap/docs/node.js/services#srv-run)
210
+ */
211
+ delete<T extends ArrayConstructable<any>>(entity: T, key?: any): DELETE<T>
212
+ delete<T>(entity: Definition | string, key?: any): DELETE<T>
213
+
214
+ // The central method to dispatch events
215
+ dispatch(msg: EventMessage): Promise<any>
216
+
217
+ // Provider API
218
+ prepend(fn: ServiceImpl): Promise<this>
219
+ on(eve: Events, entity: Target, handler: OnEventHandler): this
220
+ on(eve: Events, handler: OnEventHandler): this
221
+ // onSucceeded (eve: Events, entity: Target, handler: EventHandler): this
222
+ // onSucceeded (eve: Events, handler: EventHandler): this
223
+ // onFailed (eve: Events, entity: Target, handler: EventHandler): this
224
+ // onFailed (eve: Events, handler: EventHandler): this
225
+ before(eve: Events, entity: Target, handler: EventHandler): this
226
+ before(eve: Events, handler: EventHandler): this
227
+ after(eve: Events, entity: Target, handler: ResultsHandler): this
228
+ after(eve: Events, handler: ResultsHandler): this
229
+ reject(eves: Events, ...entity: Target[]): this
224
230
  }
225
231
 
226
232
  export interface Transaction extends Service {
227
- commit() : Promise<void>
228
- rollback() : Promise<void>
233
+ commit(): Promise<void>
234
+ rollback(): Promise<void>
229
235
  }
230
236
 
231
237
  export class DatabaseService extends Service {
232
- deploy (model?: csn | string) : Promise<csn>
233
- begin() : Promise<void>
234
- commit() : Promise<void>
235
- rollback() : Promise<void>
238
+ deploy(model?: csn | string): Promise<csn>
239
+ begin(): Promise<void>
240
+ commit(): Promise<void>
241
+ rollback(): Promise<void>
236
242
  }
237
243
 
238
244
  export interface ResultSet extends Array<{}> {}
239
245
 
240
246
  export class cds {
241
-
242
- /**
243
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/services)
244
- */
245
- Service : typeof Service
246
-
247
- /**
248
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/app-services)
249
- */
250
- ApplicationService : typeof Service
251
-
252
- /**
253
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/remote-services)
254
- */
255
- RemoteService : typeof Service
256
-
257
- /**
258
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/messaging)
259
- */
260
- MessagingService : typeof Service
261
-
262
- /**
263
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/databases)
264
- */
265
- DatabaseService : typeof DatabaseService
247
+ /**
248
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/services)
249
+ */
250
+ Service: typeof Service
251
+
252
+ /**
253
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/app-services)
254
+ */
255
+ ApplicationService: typeof Service
256
+
257
+ /**
258
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/remote-services)
259
+ */
260
+ RemoteService: typeof Service
261
+
262
+ /**
263
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/messaging)
264
+ */
265
+ MessagingService: typeof Service
266
+
267
+ /**
268
+ * @see [capire docs](https://cap.cloud.sap/docs/node.js/databases)
269
+ */
270
+ DatabaseService: typeof DatabaseService
266
271
  }
267
272
 
268
-
269
273
  export interface ServiceImpl {
270
- ( this: Service, srv: Service ) : any
274
+ (this: Service, srv: Service): any
271
275
  }
272
276
 
273
277
  export interface EventHandler {
274
- // (msg : EventMessage) : Promise<any> | any | void
275
- (req : Request) : Promise<any> | any | void
278
+ // (msg : EventMessage) : Promise<any> | any | void
279
+ (req: Request): Promise<any> | any | void
276
280
  }
277
281
 
278
282
  export interface OnEventHandler {
279
- (req : Request, next: Function) : Promise<any> | any | void
283
+ (req: Request, next: Function): Promise<any> | any | void
280
284
  }
281
285
 
286
+ // Note: the behaviour of ResultsHandler changes based on the name of the parameter.
287
+ // If the parameter in the hook is called "each", it is called once for each row in the result,
288
+ // otherwise it gets called exactly one time with the entire result.
289
+ // This runtime behaviour can not be described on type level
290
+ // (in a way that would benefit the user).
291
+ // The user will therefore receive "any" as their result/ each. If we could some day differentiate,
292
+ // we may want to add a generic to ResultsHandler which is passed from the EventHandlers down below.
282
293
  interface ResultsHandler {
283
- (results : any[], req : Request) : void
284
- (each : any, req : Request) : void
285
- }
286
-
287
- /**
288
- * Represents the user in a given context.
289
- * @see [capire docs](https://cap.cloud.sap/docs/node.js/authentication#cds-user)
290
- */
291
- interface User {
292
- id: string,
293
- locale: string,
294
- tenant: string | undefined,
295
- attr: Record<string, string>,
296
-
297
- is: (role : string) => boolean
294
+ (results: any[], req: Request): void
295
+ (each: any, req: Request): void
298
296
  }
299
297
 
300
298
  /**
@@ -302,64 +300,64 @@ interface User {
302
300
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/requests)
303
301
  */
304
302
  interface EventContext {
305
- timestamp : Date
306
- locale : string
307
- id : string
308
- user : User
309
- tenant : string
303
+ timestamp: Date
304
+ locale: string
305
+ id: string
306
+ user: User
307
+ tenant: string
310
308
  }
311
309
 
312
310
  /**
313
311
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/requests)
314
312
  */
315
- interface EventMessage extends EventContext{
316
- event : string
317
- data : any
318
- headers : {}
313
+ interface EventMessage extends EventContext {
314
+ event: string
315
+ data: any
316
+ headers: {}
319
317
  }
320
318
 
321
319
  /**
322
320
  * @see [capire docs](https://cap.cloud.sap/docs/node.js/requests)
323
321
  */
324
- interface Request extends EventMessage {
325
- params : (string|{})[]
326
- method : string
327
- path : string
328
- target : Definition
329
- /**
330
- * Shortcut to {@link target.name}
331
- *
332
- * @see https://cap.cloud.sap/docs/node.js/events#req-entity
333
- */
334
- entity: string
335
- query : Query
336
-
337
- reply (results) : void
338
-
339
- notify (code:number, msg:string, target?:string, args?:{}) : Error
340
- info (code:number, msg:string, target?:string, args?:{}) : Error
341
- warn (code:number, msg:string, target?:string, args?:{}) : Error
342
- error (code:number, msg:string, target?:string, args?:{}) : Error
343
- reject (code:number, msg:string, target?:string, args?:{}) : Error
344
-
345
- notify (msg:string, target?:string, args?:{}) : Error
346
- info (msg:string, target?:string, args?:{}) : Error
347
- warn (msg:string, target?:string, args?:{}) : Error
348
- error (msg:string, target?:string, args?:{}) : Error
349
- reject (msg:string, target?:string, args?:{}) : Error
350
-
351
- notify (msg:{ code?:number|string, msg:string, target?:string, args?:{} }) : Error
352
- info (msg:{ code?:number|string, msg:string, target?:string, args?:{} }) : Error
353
- warn (msg:{ code?:number|string, msg:string, target?:string, args?:{} }) : Error
354
- error (msg:{ code?:number|string, msg:string, target?:string, args?:{} }) : Error
355
- reject (msg:{ code?:number|string, msg:string, target?:string, args?:{} }) : Error
322
+ interface Request extends EventMessage {
323
+ params: (string | {})[]
324
+ method: string
325
+ path: string
326
+ target: Definition
327
+ /**
328
+ * Shortcut to {@link target.name}
329
+ *
330
+ * @see https://cap.cloud.sap/docs/node.js/events#req-entity
331
+ */
332
+ entity: string
333
+ query: Query
334
+
335
+ reply(results: any): void
336
+
337
+ notify(code: number, msg: string, target?: string, args?: {}): Error
338
+ info(code: number, msg: string, target?: string, args?: {}): Error
339
+ warn(code: number, msg: string, target?: string, args?: {}): Error
340
+ error(code: number, msg: string, target?: string, args?: {}): Error
341
+ reject(code: number, msg: string, target?: string, args?: {}): Error
342
+
343
+ notify(msg: string, target?: string, args?: {}): Error
344
+ info(msg: string, target?: string, args?: {}): Error
345
+ warn(msg: string, target?: string, args?: {}): Error
346
+ error(msg: string, target?: string, args?: {}): Error
347
+ reject(msg: string, target?: string, args?: {}): Error
348
+
349
+ notify(msg: { code?: number | string; msg: string; target?: string; args?: {} }): Error
350
+ info(msg: { code?: number | string; msg: string; target?: string; args?: {} }): Error
351
+ warn(msg: { code?: number | string; msg: string; target?: string; args?: {} }): Error
352
+ error(msg: { code?: number | string; msg: string; target?: string; args?: {} }): Error
353
+ reject(msg: { code?: number | string; msg: string; target?: string; args?: {} }): Error
356
354
  }
357
355
 
358
356
  type Events = Event | Event[]
359
- type Event = ( CRUD | TX | HTTP | DRAFT ) | (CustomOp & {})
357
+ type Event = (CRUD | TX | HTTP | DRAFT) | (CustomOp & {})
360
358
  type CRUD = 'CREATE' | 'READ' | 'UPDATE' | 'DELETE'
361
359
  type DRAFT = 'NEW' | 'EDIT' | 'PATCH' | 'SAVE'
362
360
  type HTTP = 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE'
363
361
  type TX = 'COMMIT' | 'ROLLBACK'
364
362
  type CustomOp = string
365
- type Target = string | Definition
363
+ type Target = string | Definition | ArrayConstructable<any>