@sap/cds 6.3.2 → 6.4.1

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