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