@sap/cds 6.3.1 → 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.
- package/CHANGELOG.md +87 -0
- package/apis/cds.d.ts +1 -1
- package/apis/core.d.ts +118 -90
- package/apis/cqn.d.ts +11 -2
- package/apis/internal/inference.d.ts +7 -2
- package/apis/ql.d.ts +45 -11
- package/apis/serve.d.ts +8 -1
- package/apis/services.d.ts +303 -305
- package/bin/build/buildTaskEngine.js +28 -36
- package/bin/build/buildTaskFactory.js +32 -81
- package/bin/build/buildTaskHandler.js +3 -2
- package/bin/build/buildTaskProvider.js +2 -2
- package/bin/build/buildTaskProviderFactory.js +5 -14
- package/bin/build/constants.js +0 -1
- package/bin/build/provider/buildTaskHandlerEdmx.js +7 -6
- package/bin/build/provider/buildTaskHandlerFeatureToggles.js +6 -5
- package/bin/build/provider/buildTaskHandlerInternal.js +9 -30
- package/bin/build/provider/buildTaskProviderInternal.js +70 -58
- package/bin/build/provider/fiori/index.js +6 -5
- package/bin/build/provider/hana/2migration.js +20 -3
- package/bin/build/provider/hana/2tabledata.js +1 -0
- package/bin/build/provider/hana/index.js +40 -17
- package/bin/build/provider/java/index.js +10 -10
- package/bin/build/provider/mtx/index.js +25 -16
- package/bin/build/provider/mtx/resourcesTarBuilder.js +22 -27
- package/bin/build/provider/mtx-extension/index.js +3 -2
- package/bin/build/provider/mtx-sidecar/index.js +16 -15
- package/bin/build/provider/nodejs/index.js +14 -56
- package/bin/build/util.js +56 -16
- package/bin/deploy/to-hana/cfUtil.js +4 -1
- package/bin/deploy/to-hana/gitUtil.js +1 -1
- package/bin/deploy/to-hana/hana.js +45 -38
- package/bin/deploy/to-hana/hdiDeployUtil.js +8 -9
- package/bin/deploy/to-hana/mtaUtil.js +13 -14
- package/bin/mtx/in-cds.js +3 -1
- package/bin/serve.js +1 -1
- package/bin/version.js +2 -1
- package/lib/compile/cds-compile.js +1 -0
- package/lib/compile/cdsc.js +1 -0
- package/lib/compile/etc/_localized.js +2 -2
- package/lib/compile/for/lean_drafts.js +83 -0
- package/lib/compile/for/nodejs.js +1 -0
- package/lib/compile/minify.js +2 -1
- package/lib/compile/parse.js +2 -1
- package/lib/compile/to/gql.js +1 -1
- package/lib/compile/to/sql.js +11 -1
- package/lib/core/entities.js +1 -1
- package/lib/core/index.js +8 -9
- package/lib/core/infer.js +1 -0
- package/lib/dbs/cds-deploy.js +97 -41
- package/lib/env/cds-env.js +9 -10
- package/lib/env/cds-requires.js +8 -2
- package/lib/env/defaults.js +0 -4
- package/lib/env/schemas/cds-rc.json +38 -0
- package/lib/ql/SELECT.js +10 -4
- package/lib/srv/bindings.js +1 -1
- package/lib/srv/factory.js +1 -1
- package/lib/srv/protocols/index.js +3 -1
- package/lib/srv/srv-methods.js +1 -1
- package/lib/utils/cds-utils.js +11 -0
- package/lib/utils/inflect.js +13 -12
- package/lib/utils/tar.js +53 -10
- package/libx/_runtime/cds-services/adapter/odata-v4/ODataRequest.js +2 -2
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/action.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/create.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/delete.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/metadata.js +1 -15
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/read.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/handlers/update.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/errors/UriSyntaxError.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-commons/uri/UriParser.js +6 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/utils/BufferedWriter.js +1 -1
- package/libx/_runtime/cds-services/adapter/odata-v4/okra/odata-server/validator/ConditionalRequestValidator.js +0 -12
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/oDataConfiguration.js +1 -7
- package/libx/_runtime/cds-services/adapter/odata-v4/utils/result.js +4 -0
- package/libx/_runtime/cds-services/services/Service.js +23 -1
- package/libx/_runtime/cds-services/util/assert.js +0 -41
- package/libx/_runtime/common/composition/data.js +5 -1
- package/libx/_runtime/common/generic/auth/utils.js +3 -3
- package/libx/_runtime/common/generic/input.js +4 -24
- package/libx/_runtime/common/generic/paging.js +3 -3
- package/libx/_runtime/common/utils/csn.js +21 -15
- package/libx/_runtime/common/utils/draft.js +2 -1
- package/libx/_runtime/common/utils/resolveView.js +25 -4
- package/libx/_runtime/common/utils/rewriteAsterisks.js +3 -1
- package/libx/_runtime/common/utils/rowUUIDGenerator.js +21 -0
- package/libx/_runtime/common/utils/templateProcessor.js +12 -15
- package/libx/_runtime/common/utils/templateProcessorPathSerializer.js +23 -0
- package/libx/_runtime/db/expand/expandCQNToJoin.js +29 -12
- package/libx/_runtime/db/generic/input.js +7 -13
- package/libx/_runtime/db/sql-builder/UpsertBuilder.js +47 -0
- package/libx/_runtime/db/sql-builder/index.js +2 -0
- package/libx/_runtime/db/sql-builder/sqlFactory.js +9 -0
- package/libx/_runtime/db/utils/columns.js +4 -2
- package/libx/_runtime/fiori/generic/read.js +1 -12
- package/libx/_runtime/fiori/lean-draft.js +657 -0
- package/libx/_runtime/fiori/utils/handler.js +1 -1
- package/libx/_runtime/hana/pool.js +16 -1
- package/libx/_runtime/messaging/enterprise-messaging-utils/getTenantInfo.js +2 -1
- package/libx/_runtime/messaging/enterprise-messaging-utils/registerEndpoints.js +1 -1
- package/libx/_runtime/messaging/enterprise-messaging.js +2 -3
- package/libx/_runtime/messaging/outbox/utils.js +109 -70
- package/libx/_runtime/messaging/service.js +16 -7
- package/libx/_runtime/remote/Service.js +15 -2
- package/libx/_runtime/remote/utils/client.js +41 -11
- package/libx/_runtime/sqlite/Service.js +3 -0
- package/libx/_runtime/sqlite/convertDraftAdminPathExpression.js +56 -0
- package/libx/_runtime/sqlite/customBuilder/CustomUpsertBuilder.js +59 -0
- package/libx/_runtime/sqlite/customBuilder/index.js +5 -0
- package/libx/_runtime/sqlite/execute.js +1 -1
- package/libx/_runtime/types/api.js +2 -2
- package/libx/rest/RestAdapter.js +15 -13
- package/package.json +1 -1
- package/server.js +1 -0
package/apis/services.d.ts
CHANGED
|
@@ -1,92 +1,91 @@
|
|
|
1
1
|
import { SELECT, INSERT, UPDATE, DELETE, Query, ConstructedQuery } from './ql'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
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
|
|
5
|
+
import { csn, type } from './csn'
|
|
6
6
|
// import { Service } from './cds'
|
|
7
7
|
|
|
8
8
|
export class QueryAPI {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
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
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
|
|
228
|
-
|
|
233
|
+
commit(): Promise<void>
|
|
234
|
+
rollback(): Promise<void>
|
|
229
235
|
}
|
|
230
236
|
|
|
231
237
|
export class DatabaseService extends Service {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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
|
-
|
|
274
|
+
(this: Service, srv: Service): any
|
|
271
275
|
}
|
|
272
276
|
|
|
273
277
|
export interface EventHandler {
|
|
274
|
-
|
|
275
|
-
|
|
278
|
+
// (msg : EventMessage) : Promise<any> | any | void
|
|
279
|
+
(req: Request): Promise<any> | any | void
|
|
276
280
|
}
|
|
277
281
|
|
|
278
282
|
export interface OnEventHandler {
|
|
279
|
-
|
|
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
|
-
|
|
284
|
-
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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 = (
|
|
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>
|