@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.
- package/CHANGELOG.md +95 -0
- package/apis/cds.d.ts +3 -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 +49 -11
- package/apis/serve.d.ts +8 -1
- package/apis/services.d.ts +311 -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 +2 -0
- 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 +17 -12
- 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/auth/index.js +17 -15
- 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/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 +9 -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/middlewares/cds-context.js +0 -2
- package/lib/srv/middlewares/ctx-auth.js +11 -0
- package/lib/srv/middlewares/ctx-model.js +22 -20
- package/lib/srv/middlewares/index.js +7 -9
- package/lib/srv/protocols/_legacy.js +4 -0
- package/lib/srv/protocols/graphql.js +2 -2
- package/lib/srv/protocols/index.js +7 -3
- package/lib/srv/srv-api.js +1 -0
- package/lib/srv/srv-methods.js +1 -1
- package/lib/utils/cds-utils.js +11 -0
- package/lib/utils/data.js +2 -2
- package/lib/utils/inflect.js +13 -12
- package/lib/utils/tar.js +43 -13
- 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/crud.js +1 -1
- package/libx/_runtime/common/generic/input.js +4 -24
- package/libx/_runtime/common/generic/paging.js +10 -9
- package/libx/_runtime/common/utils/cqn2cqn4sql.js +31 -0
- 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 +27 -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/InsertBuilder.js +5 -1
- package/libx/_runtime/db/sql-builder/UpsertBuilder.js +24 -0
- package/libx/_runtime/db/sql-builder/annotations.js +6 -3
- 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/Service.js +1 -1
- package/libx/_runtime/hana/execute.js +5 -5
- 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 +4 -1
- package/libx/_runtime/sqlite/convertDraftAdminPathExpression.js +56 -0
- package/libx/_runtime/sqlite/customBuilder/CustomUpsertBuilder.js +41 -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 +2 -19
package/apis/services.d.ts
CHANGED
|
@@ -1,92 +1,99 @@
|
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
228
|
-
|
|
241
|
+
commit(): Promise<void>
|
|
242
|
+
rollback(): Promise<void>
|
|
229
243
|
}
|
|
230
244
|
|
|
231
245
|
export class DatabaseService extends Service {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
282
|
+
(this: Service, srv: Service): any
|
|
271
283
|
}
|
|
272
284
|
|
|
273
285
|
export interface EventHandler {
|
|
274
|
-
|
|
275
|
-
|
|
286
|
+
// (msg : EventMessage) : Promise<any> | any | void
|
|
287
|
+
(req: Request): Promise<any> | any | void
|
|
276
288
|
}
|
|
277
289
|
|
|
278
290
|
export interface OnEventHandler {
|
|
279
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
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
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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 = (
|
|
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>
|