@cap-js/cds-types 0.0.1 → 0.2.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/README.md +13 -2
- package/apis/cds.d.ts +30 -26
- package/apis/core.d.ts +90 -83
- package/apis/cqn.d.ts +87 -65
- package/apis/csn.d.ts +25 -16
- package/apis/env.d.ts +21 -24
- package/apis/events.d.ts +82 -59
- package/apis/internal/inference.d.ts +39 -5
- package/apis/linked.d.ts +45 -38
- package/apis/log.d.ts +79 -71
- package/apis/models.d.ts +155 -162
- package/apis/ql.d.ts +256 -191
- package/apis/server.d.ts +72 -62
- package/apis/services.d.ts +164 -106
- package/apis/test.d.ts +80 -49
- package/apis/utils.d.ts +85 -90
- package/package.json +13 -3
package/apis/services.d.ts
CHANGED
|
@@ -1,118 +1,95 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/ban-types */
|
|
1
2
|
import { SELECT, INSERT, UPDATE, DELETE, Query, ConstructedQuery, UPSERT } from './ql'
|
|
2
3
|
import { Awaitable } from './ql'
|
|
3
4
|
import { ArrayConstructable, Constructable } from './internal/inference'
|
|
4
|
-
import { LinkedCSN, LinkedDefinition, Definitions, LinkedEntity } from './linked'
|
|
5
|
+
import { LinkedCSN, LinkedDefinition, Definitions as LinkedDefinitions, LinkedEntity } from './linked'
|
|
5
6
|
import { CSN } from './csn'
|
|
6
7
|
import { EventContext } from './events'
|
|
7
8
|
import { Request } from './events'
|
|
9
|
+
import { ReadableStream } from 'node:stream/web'
|
|
10
|
+
|
|
11
|
+
type Key = number | string | any
|
|
8
12
|
|
|
9
13
|
export class QueryAPI {
|
|
10
14
|
|
|
11
|
-
entities
|
|
15
|
+
entities: LinkedCSN['entities']
|
|
12
16
|
|
|
13
17
|
/**
|
|
14
18
|
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
15
19
|
*/
|
|
16
20
|
read: {
|
|
17
|
-
<T extends ArrayConstructable
|
|
18
|
-
<T>(entity: LinkedDefinition | string, key?:
|
|
21
|
+
<T extends ArrayConstructable>(entity: T, key?: Key): Awaitable<SELECT<T>, InstanceType<T>>,
|
|
22
|
+
<T>(entity: LinkedDefinition | string, key?: Key): SELECT<T>,
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
/**
|
|
22
26
|
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
23
27
|
*/
|
|
24
28
|
create: {
|
|
25
|
-
<T extends ArrayConstructable
|
|
26
|
-
<T>(entity: LinkedDefinition | string, key?:
|
|
29
|
+
<T extends ArrayConstructable>(entity: T, key?: Key): INSERT<T>,
|
|
30
|
+
<T>(entity: LinkedDefinition | string, key?: Key): INSERT<T>,
|
|
27
31
|
}
|
|
28
32
|
|
|
29
33
|
/**
|
|
30
34
|
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
31
35
|
*/
|
|
32
36
|
insert: {
|
|
33
|
-
<T extends ArrayConstructable
|
|
34
|
-
<T>(data: object | object[]): INSERT<T
|
|
37
|
+
<T extends ArrayConstructable>(data: T): INSERT<T>,
|
|
38
|
+
<T>(data: object | object[]): INSERT<T>,
|
|
35
39
|
}
|
|
36
40
|
|
|
37
41
|
/**
|
|
38
42
|
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
39
43
|
*/
|
|
40
44
|
upsert: {
|
|
41
|
-
<T extends ArrayConstructable
|
|
42
|
-
<T>(data: object | object[]): UPSERT<T
|
|
45
|
+
<T extends ArrayConstructable>(data: T): UPSERT<T>,
|
|
46
|
+
<T>(data: object | object[]): UPSERT<T>,
|
|
43
47
|
}
|
|
44
48
|
|
|
45
49
|
/**
|
|
46
50
|
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
47
51
|
*/
|
|
48
52
|
update: {
|
|
49
|
-
<T extends ArrayConstructable
|
|
50
|
-
<T>(entity: LinkedDefinition | string, key?:
|
|
53
|
+
<T extends ArrayConstructable>(entity: T, key?: Key): UPDATE<T>,
|
|
54
|
+
<T>(entity: LinkedDefinition | string, key?: Key): UPDATE<T>,
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
/**
|
|
54
58
|
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
55
59
|
*/
|
|
56
60
|
run: {
|
|
57
|
-
(query: ConstructedQuery | ConstructedQuery[]): Promise<ResultSet | any
|
|
58
|
-
(query: Query): Promise<ResultSet | any
|
|
59
|
-
(query: string, args?: any[] | object): Promise<ResultSet | any
|
|
61
|
+
(query: ConstructedQuery | ConstructedQuery[]): Promise<ResultSet | any>,
|
|
62
|
+
(query: Query): Promise<ResultSet | any>,
|
|
63
|
+
(query: string, args?: any[] | object): Promise<ResultSet | any>,
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
/**
|
|
63
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
64
|
-
*/
|
|
65
|
-
delete<T>(entity: LinkedDefinition | string, key?: any): DELETE<T>
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#srv-foreach-entity)
|
|
69
|
-
*/
|
|
70
|
-
foreach(query: Query, callback: (row: object) => void): this
|
|
71
|
-
|
|
72
66
|
/**
|
|
73
67
|
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#srv-stream-column)
|
|
74
68
|
*/
|
|
75
69
|
stream: {
|
|
76
70
|
(column: string): {
|
|
77
71
|
from(entity: LinkedDefinition | string): {
|
|
78
|
-
where(filter: any): ReadableStream
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
(query: Query): Promise<ReadableStream
|
|
72
|
+
where(filter: any): ReadableStream,
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
(query: Query): Promise<ReadableStream>,
|
|
82
76
|
}
|
|
83
77
|
|
|
84
78
|
/**
|
|
85
|
-
*
|
|
86
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx)
|
|
87
|
-
*/
|
|
88
|
-
|
|
89
|
-
tx: {
|
|
90
|
-
(fn: (tx: Transaction) => {}): Promise<unknown>
|
|
91
|
-
(context?: object): Transaction
|
|
92
|
-
(context: object, fn: (tx: Transaction) => {}): Promise<unknown>
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
transaction: {
|
|
96
|
-
(fn: (tx: Transaction) => {}): Promise<unknown>
|
|
97
|
-
(context?: object): Transaction
|
|
98
|
-
(context: object, fn: (tx: Transaction) => {}): Promise<unknown>
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/**
|
|
102
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx#cds-spawn)
|
|
79
|
+
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
103
80
|
*/
|
|
104
|
-
|
|
105
|
-
[key: string]: any
|
|
106
|
-
every?: number
|
|
107
|
-
after?: number
|
|
108
|
-
}, fn: (tx: Transaction) => {}): SpawnEventEmitter
|
|
81
|
+
delete<T>(entity: LinkedDefinition | string, key?: Key): DELETE<T>
|
|
109
82
|
|
|
110
83
|
/**
|
|
111
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/
|
|
84
|
+
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#srv-foreach-entity)
|
|
112
85
|
*/
|
|
113
|
-
|
|
86
|
+
foreach (query: Query, callback: (row: object) => void): this
|
|
87
|
+
transaction: {
|
|
88
|
+
(fn: (tx: Transaction) => object): Promise<any>,
|
|
89
|
+
(context?: object): Transaction,
|
|
90
|
+
(context: object, fn: (tx: Transaction) => object): Promise<any>,
|
|
91
|
+
}
|
|
114
92
|
|
|
115
|
-
db: DatabaseService
|
|
116
93
|
}
|
|
117
94
|
|
|
118
95
|
|
|
@@ -121,24 +98,25 @@ export class QueryAPI {
|
|
|
121
98
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
122
99
|
*/
|
|
123
100
|
export class Service extends QueryAPI {
|
|
124
|
-
|
|
101
|
+
|
|
102
|
+
constructor (
|
|
125
103
|
name?: string,
|
|
126
104
|
model?: CSN,
|
|
127
105
|
options?: {
|
|
128
|
-
kind: string
|
|
129
|
-
impl: string | ServiceImpl
|
|
106
|
+
kind: string,
|
|
107
|
+
impl: string | ServiceImpl,
|
|
130
108
|
}
|
|
131
109
|
)
|
|
132
110
|
|
|
133
111
|
/**
|
|
134
|
-
* The
|
|
112
|
+
* The kind of the service
|
|
135
113
|
*/
|
|
136
|
-
|
|
114
|
+
kind: string
|
|
137
115
|
|
|
138
116
|
/**
|
|
139
|
-
* The
|
|
117
|
+
* The name of the service
|
|
140
118
|
*/
|
|
141
|
-
|
|
119
|
+
name: string
|
|
142
120
|
|
|
143
121
|
/**
|
|
144
122
|
* The model from which the service's definition was loaded
|
|
@@ -150,40 +128,40 @@ export class Service extends QueryAPI {
|
|
|
150
128
|
* Provides access to the entities exposed by a service
|
|
151
129
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
152
130
|
*/
|
|
153
|
-
entities:
|
|
131
|
+
entities: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
154
132
|
|
|
155
133
|
/**
|
|
156
134
|
* Provides access to the events declared by a service
|
|
157
135
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
158
136
|
*/
|
|
159
|
-
events:
|
|
137
|
+
events: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
160
138
|
|
|
161
139
|
/**
|
|
162
140
|
* Provides access to the types exposed by a service
|
|
163
141
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
164
142
|
*/
|
|
165
|
-
types:
|
|
143
|
+
types: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
166
144
|
|
|
167
145
|
/**
|
|
168
146
|
* Provides access to the operations, i.e. actions and functions, exposed by a service
|
|
169
147
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
170
148
|
*/
|
|
171
|
-
operations:
|
|
149
|
+
operations: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
172
150
|
|
|
173
151
|
/**
|
|
174
152
|
* Acts like a parameter-less constructor. Ensure to call `await super.init()` to have the base class’s handlers added.
|
|
175
153
|
* You may register own handlers before the base class’s ones, to intercept requests before the default handlers snap in.
|
|
176
154
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#srv-init)
|
|
177
155
|
*/
|
|
178
|
-
init(): Promise<void>
|
|
156
|
+
init (): Promise<void>
|
|
179
157
|
|
|
180
158
|
/**
|
|
181
159
|
* Constructs and emits an asynchronous event.
|
|
182
160
|
* @see [capire docs](https://cap.cloud.sap/docs/core-services#srv-emit-event)
|
|
183
161
|
*/
|
|
184
162
|
emit: {
|
|
185
|
-
<T = any>(details: { event: types.event
|
|
186
|
-
<T = any>(event: types.event, data?: object, headers?: object): Promise<T
|
|
163
|
+
<T = any>(details: { event: types.event, data?: object, headers?: object }): Promise<T>,
|
|
164
|
+
<T = any>(event: types.event, data?: object, headers?: object): Promise<T>,
|
|
187
165
|
}
|
|
188
166
|
|
|
189
167
|
/**
|
|
@@ -191,12 +169,12 @@ export class Service extends QueryAPI {
|
|
|
191
169
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#srv-send-request)
|
|
192
170
|
*/
|
|
193
171
|
send: {
|
|
194
|
-
<T = any>(event: types.event, path: string, data?: object, headers?: object): Promise<T
|
|
195
|
-
<T = any>(event: types.event, data?: object, headers?: object): Promise<T
|
|
196
|
-
<T = any>(details: { event: types.event
|
|
197
|
-
<T = any>(details: { query: ConstructedQuery
|
|
198
|
-
<T = any>(details: { method: types.eventName
|
|
199
|
-
<T = any>(details: { event: types.eventName
|
|
172
|
+
<T = any>(event: types.event, path: string, data?: object, headers?: object): Promise<T>,
|
|
173
|
+
<T = any>(event: types.event, data?: object, headers?: object): Promise<T>,
|
|
174
|
+
<T = any>(details: { event: types.event, data?: object, headers?: object }): Promise<T>,
|
|
175
|
+
<T = any>(details: { query: ConstructedQuery, data?: object, headers?: object }): Promise<T>,
|
|
176
|
+
<T = any>(details: { method: types.eventName, path: string, data?: object, headers?: object }): Promise<T>,
|
|
177
|
+
<T = any>(details: { event: types.eventName, entity: LinkedDefinition | string, data?: object, params?: object, headers?: object }): Promise<T>,
|
|
200
178
|
}
|
|
201
179
|
|
|
202
180
|
/**
|
|
@@ -204,40 +182,54 @@ export class Service extends QueryAPI {
|
|
|
204
182
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
205
183
|
*/
|
|
206
184
|
get<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
185
|
+
|
|
207
186
|
/**
|
|
208
187
|
* Constructs and sends a POST request.
|
|
209
188
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
210
189
|
*/
|
|
211
190
|
post<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
191
|
+
|
|
212
192
|
/**
|
|
213
193
|
* Constructs and sends a PUT request.
|
|
214
194
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
215
195
|
*/
|
|
216
196
|
put<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
197
|
+
|
|
217
198
|
/**
|
|
218
199
|
* Constructs and sends a PATCH request.
|
|
219
200
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
220
201
|
*/
|
|
221
202
|
patch<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
203
|
+
|
|
222
204
|
/**
|
|
223
205
|
* Constructs and sends a DELETE request.
|
|
224
206
|
*/
|
|
225
207
|
delete: {
|
|
226
|
-
<T = any>(entityOrPath: types.target, data?: object): DELETE<T
|
|
227
|
-
<T extends ArrayConstructable
|
|
228
|
-
<T>(entity: LinkedDefinition | string, key?:
|
|
208
|
+
<T = any>(entityOrPath: types.target, data?: object): DELETE<T>,
|
|
209
|
+
<T extends ArrayConstructable>(entity: T, key?: Key): DELETE<T>,
|
|
210
|
+
<T>(entity: LinkedDefinition | string, key?: Key): DELETE<T>,
|
|
229
211
|
}
|
|
230
212
|
|
|
231
213
|
// The central method to dispatch events
|
|
232
|
-
dispatch(msg: types.event): Promise<any>
|
|
214
|
+
dispatch (msg: types.event): Promise<any>
|
|
215
|
+
|
|
216
|
+
// FIXME: not yet documented, will come in future version
|
|
217
|
+
// disconnect (tenant?: string): Promise<void>
|
|
233
218
|
|
|
234
219
|
// Provider API
|
|
235
|
-
prepend(fn: ServiceImpl): Promise<this>
|
|
220
|
+
prepend (fn: ServiceImpl): Promise<this>
|
|
221
|
+
|
|
236
222
|
on<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<InstanceType<T>, InstanceType<T> | void | Error>): this
|
|
223
|
+
|
|
237
224
|
on<F extends CdsFunction>(boundAction: F, service: string, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
|
|
225
|
+
|
|
238
226
|
on<F extends CdsFunction>(unboundAction: F, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
|
|
239
|
-
|
|
240
|
-
on(eve: types.event, handler: OnEventHandler): this
|
|
227
|
+
|
|
228
|
+
on (eve: types.event, entity: types.target, handler: OnEventHandler): this
|
|
229
|
+
|
|
230
|
+
on (eve: types.event, handler: OnEventHandler): this
|
|
231
|
+
|
|
232
|
+
on (eve: 'error', handler: OnErrorHandler): this
|
|
241
233
|
|
|
242
234
|
|
|
243
235
|
// onSucceeded (eve: types.Events, entity: types.Target, handler: types.EventHandler): this
|
|
@@ -245,26 +237,40 @@ export class Service extends QueryAPI {
|
|
|
245
237
|
// onFailed (eve: types.Events, entity: types.Target, handler: types.EventHandler): this
|
|
246
238
|
// onFailed (eve: types.Events, handler: types.EventHandler): this
|
|
247
239
|
before<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.Before<InstanceType<T>, InstanceType<T> | void | Error>): this
|
|
248
|
-
|
|
249
|
-
before(eve: types.event, handler: EventHandler): this
|
|
240
|
+
|
|
241
|
+
before (eve: types.event, entity: types.target, handler: EventHandler): this
|
|
242
|
+
|
|
243
|
+
before (eve: types.event, handler: EventHandler): this
|
|
244
|
+
|
|
250
245
|
after<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.After<InstanceType<T>, InstanceType<T> | void | Error>): this
|
|
251
|
-
|
|
252
|
-
after(eve: types.event, handler: ResultsHandler): this
|
|
253
|
-
|
|
246
|
+
|
|
247
|
+
after (eve: types.event, entity: types.target, handler: ResultsHandler): this
|
|
248
|
+
|
|
249
|
+
after (eve: types.event, handler: ResultsHandler): this
|
|
250
|
+
|
|
251
|
+
reject (eves: types.event, ...entity: types.target[]): this
|
|
252
|
+
|
|
254
253
|
}
|
|
255
254
|
|
|
256
255
|
export class ApplicationService extends Service {}
|
|
257
256
|
export class MessagingService extends Service {}
|
|
258
257
|
export class RemoteService extends Service {}
|
|
259
258
|
export class DatabaseService extends Service {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
259
|
+
|
|
260
|
+
deploy (model?: CSN | string): Promise<CSN>
|
|
261
|
+
|
|
262
|
+
begin (): Promise<void>
|
|
263
|
+
|
|
264
|
+
commit (): Promise<void>
|
|
265
|
+
|
|
266
|
+
rollback (): Promise<void>
|
|
267
|
+
|
|
264
268
|
}
|
|
265
269
|
|
|
266
270
|
|
|
267
271
|
export default class cds {
|
|
272
|
+
|
|
273
|
+
|
|
268
274
|
/**
|
|
269
275
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
270
276
|
*/
|
|
@@ -289,15 +295,16 @@ export default class cds {
|
|
|
289
295
|
* @see [capire docs](https://cap.cloud.sap/docs/node.js/databases)
|
|
290
296
|
*/
|
|
291
297
|
DatabaseService: typeof DatabaseService
|
|
298
|
+
|
|
292
299
|
}
|
|
293
300
|
|
|
294
301
|
|
|
295
|
-
interface Transaction extends Service {
|
|
302
|
+
export interface Transaction extends Service {
|
|
296
303
|
commit(): Promise<void>
|
|
297
304
|
rollback(): Promise<void>
|
|
298
305
|
}
|
|
299
306
|
|
|
300
|
-
interface ResultSet extends Array<
|
|
307
|
+
interface ResultSet extends Array<object> {}
|
|
301
308
|
|
|
302
309
|
interface ServiceImpl {
|
|
303
310
|
(this: Service, srv: Service): any
|
|
@@ -312,6 +319,10 @@ interface OnEventHandler {
|
|
|
312
319
|
(req: Request, next: Function): Promise<any> | any | void
|
|
313
320
|
}
|
|
314
321
|
|
|
322
|
+
interface OnErrorHandler {
|
|
323
|
+
(err: Error, req: Request): any | void
|
|
324
|
+
}
|
|
325
|
+
|
|
315
326
|
// `Partial` wraps any type and allows all properties to be undefined
|
|
316
327
|
// in addition to their actual type.
|
|
317
328
|
// This is important in the context of CRUD events, where
|
|
@@ -322,7 +333,7 @@ type Partial<T> = { [Key in keyof T]: undefined | T[Key] }
|
|
|
322
333
|
// Naming the first parameter in a handler `each` has special voodoo
|
|
323
334
|
// semantic which makes it impossible for us to infer the exact behaviour on a type level.
|
|
324
335
|
// So we always have to expect scalars as well as arrays in some callbacks.
|
|
325
|
-
type OneOrMany<T> = T | T[]
|
|
336
|
+
type OneOrMany<T> = T | T[]
|
|
326
337
|
|
|
327
338
|
// functions generated by cds-typer explicitly carry types for
|
|
328
339
|
// parameters and return type, as their names are not accessible from
|
|
@@ -331,23 +342,23 @@ type OneOrMany<T> = T | T[];
|
|
|
331
342
|
type CdsFunction = {
|
|
332
343
|
(...args: any[]): any,
|
|
333
344
|
__parameters: object,
|
|
334
|
-
__returns:
|
|
345
|
+
__returns: any,
|
|
335
346
|
}
|
|
336
347
|
|
|
337
348
|
type TypedRequest<T> = Omit<Request, 'data'> & { data: T }
|
|
338
349
|
|
|
339
350
|
// https://cap.cloud.sap/docs/node.js/core-services#srv-on-before-after
|
|
340
351
|
declare namespace CRUDEventHandler {
|
|
341
|
-
type Before<P,R> = (req: TypedRequest<P>) => Promise<R> | R
|
|
342
|
-
type On<P,R> = (req: TypedRequest<P>, next: (...args: any) => Promise<R> | R) => Promise<R> | R
|
|
343
|
-
type After<P,R> = (data: undefined | P, req: TypedRequest<P>) => Promise<R> | R
|
|
352
|
+
type Before<P, R> = (req: TypedRequest<P>) => Promise<R> | R
|
|
353
|
+
type On<P, R> = (req: TypedRequest<P>, next: (...args: any[]) => Promise<R> | R) => Promise<R> | R
|
|
354
|
+
type After<P, R> = (data: undefined | P, req: TypedRequest<P>) => Promise<R> | R
|
|
344
355
|
}
|
|
345
356
|
|
|
346
357
|
// Handlers for actions try to infer the passed .data property
|
|
347
358
|
// as strictly as possible and therefore have to remove
|
|
348
359
|
// { data: any } (inherited EventMessage} with a more restricted
|
|
349
360
|
// type, based on the parameters of the action.
|
|
350
|
-
interface ActionEventHandler<P,R> {
|
|
361
|
+
interface ActionEventHandler<P, R> {
|
|
351
362
|
(req: Omit<Request, 'data'> & { data: P }, next: Function): Promise<R> | R
|
|
352
363
|
}
|
|
353
364
|
|
|
@@ -364,28 +375,75 @@ interface ResultsHandler {
|
|
|
364
375
|
}
|
|
365
376
|
|
|
366
377
|
interface SpawnEvents {
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
378
|
+
succeeded: (res: any) => void
|
|
379
|
+
failed: (error: any) => void
|
|
380
|
+
done: () => void
|
|
370
381
|
}
|
|
371
382
|
|
|
372
383
|
declare class SpawnEventEmitter {
|
|
384
|
+
|
|
373
385
|
on<U extends keyof SpawnEvents>(
|
|
374
386
|
event: U, listener: SpawnEvents[U]
|
|
375
|
-
): this
|
|
387
|
+
): this
|
|
376
388
|
|
|
377
389
|
emit<U extends keyof SpawnEvents>(
|
|
378
390
|
event: U, ...args: Parameters<SpawnEvents[U]>
|
|
379
|
-
): boolean
|
|
391
|
+
): boolean
|
|
380
392
|
timer: any
|
|
393
|
+
|
|
381
394
|
}
|
|
382
395
|
|
|
383
396
|
declare namespace types {
|
|
384
397
|
type event = eventName | eventName[]
|
|
385
|
-
type eventName =
|
|
398
|
+
type eventName = string
|
|
386
399
|
| 'CREATE' | 'READ' | 'UPDATE' | 'DELETE'
|
|
387
400
|
| 'NEW' | 'EDIT' | 'PATCH' | 'SAVE'
|
|
388
401
|
| 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE'
|
|
389
402
|
| 'COMMIT' | 'ROLLBACK'
|
|
390
|
-
type target = string | LinkedDefinition | LinkedEntity | (string | LinkedDefinition | LinkedEntity)[] | ArrayConstructable
|
|
403
|
+
type target = string | LinkedDefinition | LinkedEntity | (string | LinkedDefinition | LinkedEntity)[] | ArrayConstructable
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
type SpawnOptions = {
|
|
407
|
+
[key: string]: any,
|
|
408
|
+
every?: number,
|
|
409
|
+
after?: number,
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
// FIXME: this was ?: EventContext before. Is context supposed to not be present sometimes?
|
|
413
|
+
// let, as apparently we can reassign?
|
|
414
|
+
/**
|
|
415
|
+
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx#event-contexts
|
|
416
|
+
*/
|
|
417
|
+
export let context: EventContext | undefined
|
|
418
|
+
|
|
419
|
+
/**
|
|
420
|
+
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx#cds-spawn)
|
|
421
|
+
*/
|
|
422
|
+
export function spawn (options: SpawnOptions, fn: (tx: Transaction) => object): SpawnEventEmitter
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
// facade proxies into cds.db, which is a Service
|
|
426
|
+
/**
|
|
427
|
+
* Starts or joins a transaction
|
|
428
|
+
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx)
|
|
429
|
+
*/
|
|
430
|
+
export const tx: {
|
|
431
|
+
(fn: (tx: Transaction) => object): Promise<any>,
|
|
432
|
+
(context?: object): Transaction,
|
|
433
|
+
(context: object, fn: (tx: Transaction) => object): Promise<any>,
|
|
391
434
|
}
|
|
435
|
+
export const entities: Service['entities']
|
|
436
|
+
export const run: Service['run']
|
|
437
|
+
export const foreach: Service['foreach']
|
|
438
|
+
export const stream: Service['stream']
|
|
439
|
+
export const read: Service['read']
|
|
440
|
+
export const create: Service['create']
|
|
441
|
+
export const insert: Service['insert']
|
|
442
|
+
export const update: Service['update']
|
|
443
|
+
// temporarily moved to cds.d.ts, as "delete" is a reserved keyword
|
|
444
|
+
// export const delete: Service['delete']
|
|
445
|
+
// FIXME: see Service.disconnect comment
|
|
446
|
+
// export const disconnect: Service['disconnect']
|
|
447
|
+
export const transaction: Service['transaction']
|
|
448
|
+
export const db: DatabaseService
|
|
449
|
+
// export const upsert: Service['upsert']
|
package/apis/test.d.ts
CHANGED
|
@@ -1,59 +1,91 @@
|
|
|
1
|
-
import { AxiosInstance } from 'axios'
|
|
2
|
-
import
|
|
3
|
-
import * as http from 'http'
|
|
4
|
-
import { Service } from './services'
|
|
1
|
+
import { AxiosInstance } from 'axios'
|
|
2
|
+
import chai from 'chai'
|
|
3
|
+
import * as http from 'http'
|
|
4
|
+
import { Service } from './services'
|
|
5
|
+
import * as cds from './cds'
|
|
6
|
+
|
|
7
|
+
type _cds = typeof cds
|
|
5
8
|
|
|
6
9
|
declare class Axios {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
get
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
get
|
|
10
|
+
|
|
11
|
+
get axios (): AxiosInstance
|
|
12
|
+
get: AxiosInstance['get'];
|
|
13
|
+
|
|
14
|
+
put: AxiosInstance['put']
|
|
15
|
+
|
|
16
|
+
post: AxiosInstance['post']
|
|
17
|
+
|
|
18
|
+
patch: AxiosInstance['patch']
|
|
19
|
+
|
|
20
|
+
delete: AxiosInstance['delete']
|
|
21
|
+
|
|
22
|
+
options: AxiosInstance['options']
|
|
23
|
+
|
|
24
|
+
get GET (): Axios['get']
|
|
25
|
+
|
|
26
|
+
get PUT (): Axios['put']
|
|
27
|
+
|
|
28
|
+
get POST (): Axios['post']
|
|
29
|
+
|
|
30
|
+
get PATCH (): Axios['patch']
|
|
31
|
+
|
|
32
|
+
get DELETE (): Axios['delete']
|
|
33
|
+
|
|
34
|
+
get OPTIONS (): Axios['options']
|
|
35
|
+
|
|
22
36
|
}
|
|
23
37
|
|
|
24
38
|
declare class DataUtil {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
39
|
+
|
|
40
|
+
delete (db?: Service): Promise<void>
|
|
41
|
+
|
|
42
|
+
reset (db?: Service): Promise<void>
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @deprecated if needed, call `reset()`, considering test performance
|
|
46
|
+
*/
|
|
47
|
+
autoReset (enabled: boolean): this
|
|
48
|
+
|
|
28
49
|
}
|
|
29
50
|
|
|
30
51
|
declare class Test extends Axios {
|
|
31
52
|
|
|
32
|
-
test
|
|
53
|
+
test: Test
|
|
54
|
+
|
|
55
|
+
run (cmd: string, ...args: string[]): this
|
|
56
|
+
|
|
57
|
+
in (...paths: string[]): this
|
|
58
|
+
|
|
59
|
+
silent (): this
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* @deprecated Server log is shown by default. Use `log()` to get control over it.
|
|
63
|
+
*/
|
|
64
|
+
verbose (v: boolean): this
|
|
33
65
|
|
|
34
|
-
|
|
35
|
-
in(...paths: string[]): this;
|
|
36
|
-
silent(): this;
|
|
37
|
-
/** @deprecated */ verbose(v: boolean): this;
|
|
66
|
+
get chai (): typeof chai
|
|
38
67
|
|
|
39
|
-
get
|
|
40
|
-
get expect(): typeof chai.expect;
|
|
41
|
-
get assert(): typeof chai.assert;
|
|
42
|
-
get data(): DataUtil;
|
|
43
|
-
get cds(): typeof import('./cds')
|
|
68
|
+
get expect (): typeof chai.expect
|
|
44
69
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
70
|
+
get assert (): typeof chai.assert
|
|
71
|
+
|
|
72
|
+
get data (): DataUtil
|
|
73
|
+
|
|
74
|
+
get cds (): _cds
|
|
75
|
+
|
|
76
|
+
log (): {
|
|
77
|
+
output: string,
|
|
78
|
+
clear(): void,
|
|
79
|
+
release(): void,
|
|
49
80
|
}
|
|
50
81
|
|
|
51
|
-
then(r: (args: { server: http.Server, url: string }) => void): void
|
|
82
|
+
then (r: (args: { server: http.Server, url: string }) => void): void
|
|
52
83
|
|
|
53
84
|
// get sleep(): (ms: number) => Promise<void>;
|
|
54
85
|
// get spy(): <T, K extends keyof T>(o: T, f: K) => T[K] extends (...args: infer TArgs) => infer TReturnValue
|
|
55
86
|
// ? Spy<TArgs, TReturnValue>
|
|
56
87
|
// : Spy;
|
|
88
|
+
|
|
57
89
|
}
|
|
58
90
|
|
|
59
91
|
// typings for spy inspired by @types/sinon
|
|
@@ -63,19 +95,18 @@ declare class Test extends Axios {
|
|
|
63
95
|
// restore(): (...args: TArgs) => TReturnValue;
|
|
64
96
|
// }
|
|
65
97
|
|
|
66
|
-
|
|
98
|
+
declare const test: {
|
|
99
|
+
Test: typeof Test,
|
|
67
100
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Test: typeof Test
|
|
71
|
-
/**
|
|
72
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/cds-test?q=cds.test#run)
|
|
101
|
+
/**
|
|
102
|
+
* @see [capire docs](https://cap.cloud.sap/docs/node.js/cds-test#class-cds-test-test)
|
|
73
103
|
*/
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
104
|
+
(dirname: string): Test,
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* @see [capire docs](https://cap.cloud.sap/docs/node.js/cds-test#class-cds-test-test)
|
|
77
108
|
*/
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
109
|
+
(command: string, ...args: string[]): Test,
|
|
110
|
+
|
|
111
|
+
in (dirname: string): Test,
|
|
81
112
|
}
|