@cap-js/cds-types 0.1.0 → 0.3.0-beta.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/README.md +11 -0
- package/dist/cds-types.d.ts +2778 -0
- package/package.json +23 -8
- package/apis/cds.d.ts +0 -44
- package/apis/core.d.ts +0 -95
- package/apis/cqn.d.ts +0 -87
- package/apis/csn.d.ts +0 -117
- package/apis/env.d.ts +0 -22
- package/apis/events.d.ts +0 -105
- package/apis/internal/inference.d.ts +0 -32
- package/apis/linked.d.ts +0 -105
- package/apis/log.d.ts +0 -164
- package/apis/models.d.ts +0 -171
- package/apis/ql.d.ts +0 -327
- package/apis/server.d.ts +0 -143
- package/apis/services.d.ts +0 -414
- package/apis/test.d.ts +0 -87
- package/apis/utils.d.ts +0 -89
package/apis/server.d.ts
DELETED
|
@@ -1,143 +0,0 @@
|
|
|
1
|
-
import { Service, ServiceImpl } from "./services"
|
|
2
|
-
import { CSN } from "./csn"
|
|
3
|
-
import * as http from "http"
|
|
4
|
-
import * as cds from './cds'
|
|
5
|
-
import { Application } from "express"
|
|
6
|
-
|
|
7
|
-
type _cds = typeof cds
|
|
8
|
-
|
|
9
|
-
export const connect: {
|
|
10
|
-
/**
|
|
11
|
-
* Connects to a specific datasource.
|
|
12
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
|
|
13
|
-
*/
|
|
14
|
-
to(datasource: string, options?: cds_connect_options): Promise<Service>
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Connects to a specific datasource via options.
|
|
18
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
|
|
19
|
-
*/
|
|
20
|
-
to(options: cds_connect_options): Promise<Service>
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Connects the primary datasource.
|
|
24
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect)
|
|
25
|
-
*/
|
|
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
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* The default bootstrap function as loaded from server.js
|
|
32
|
-
*/
|
|
33
|
-
export const server: Function
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Constructs service providers from respective service definitions
|
|
37
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-serve)
|
|
38
|
-
*/
|
|
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
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Emitted whenever a model is loaded using cds.load().
|
|
47
|
-
*/
|
|
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
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Emitted whenever a specific service is connected for the first time.
|
|
54
|
-
*/
|
|
55
|
-
export function on(event: 'connect', listener: (srv: Service) => void): _cds
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Emitted at the very beginning of the bootsrapping process, when the
|
|
60
|
-
* express application has been constructed but no middlewares or routes
|
|
61
|
-
* added yet.
|
|
62
|
-
*/
|
|
63
|
-
export function on (event : 'bootstrap', listener : (app : Application) => void) : _cds
|
|
64
|
-
export function once (event : 'bootstrap', listener : (app : Application) => void) : _cds
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
* Emitted for each service served by cds.serve().
|
|
68
|
-
*/
|
|
69
|
-
export function on (event : 'serving', listener : (srv : Service) => void) : _cds
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Emitted by the default, built-in `server.js` when all services are
|
|
73
|
-
* constructed and mounted by cds.serve().
|
|
74
|
-
*/
|
|
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
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Emitted by the default, built-in `server.js` when the http server
|
|
80
|
-
* is started and listening for incoming requests.
|
|
81
|
-
*/
|
|
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
|
-
|
|
85
|
-
/**
|
|
86
|
-
* Emitted by the default, built-in `server.js` when the http server
|
|
87
|
-
* is shutdown.
|
|
88
|
-
*/
|
|
89
|
-
export function on (event : 'shutdown', listener : () => void) : _cds
|
|
90
|
-
export function once (event : 'shutdown', listener : () => void) : _cds
|
|
91
|
-
|
|
92
|
-
/**
|
|
93
|
-
* Dictionary of all services constructed and/or connected.
|
|
94
|
-
*/
|
|
95
|
-
export const services : cds_services
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Shortcut to base class for all service definitions from linked models.
|
|
99
|
-
* Plus accessors to impl functions and constructed providers.
|
|
100
|
-
*/
|
|
101
|
-
export const service : service
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Provides a graceful shutdown for running servers, by first emitting `cds.emit('shutdown')`.
|
|
105
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-facade#cds-exit)
|
|
106
|
-
*/
|
|
107
|
-
export function exit(): void
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
export type service = {
|
|
112
|
-
/**
|
|
113
|
-
* Dummy wrapper for service implementation functions.
|
|
114
|
-
* Use that in modules to get IntelliSense.
|
|
115
|
-
*/
|
|
116
|
-
impl (impl: ServiceImpl) : typeof impl
|
|
117
|
-
// impl <T> (srv:T, impl: ( _cds: T, srv: (T) ) => any) : typeof impl
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* Array of all services constructed.
|
|
121
|
-
*/
|
|
122
|
-
providers : Service[]
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
type cds_services = { [name:string]: Service }
|
|
127
|
-
|
|
128
|
-
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
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
interface cds_connect_options {
|
|
138
|
-
impl?: string,
|
|
139
|
-
service?: string,
|
|
140
|
-
kind?: string,
|
|
141
|
-
model?: string,
|
|
142
|
-
credentials?: object
|
|
143
|
-
}
|
package/apis/services.d.ts
DELETED
|
@@ -1,414 +0,0 @@
|
|
|
1
|
-
import { SELECT, INSERT, UPDATE, DELETE, Query, ConstructedQuery, UPSERT } from './ql'
|
|
2
|
-
import { Awaitable } from './ql'
|
|
3
|
-
import { ArrayConstructable, Constructable } from './internal/inference'
|
|
4
|
-
import { LinkedCSN, LinkedDefinition, Definitions as LinkedDefinitions, LinkedEntity } from './linked'
|
|
5
|
-
import { CSN } from './csn'
|
|
6
|
-
import { EventContext } from './events'
|
|
7
|
-
import { Request } from './events'
|
|
8
|
-
import { ReadableStream } from 'node:stream/web'
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
export class QueryAPI {
|
|
12
|
-
|
|
13
|
-
entities : LinkedCSN['entities']
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
17
|
-
*/
|
|
18
|
-
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
|
-
}
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
25
|
-
*/
|
|
26
|
-
create: {
|
|
27
|
-
<T extends ArrayConstructable<any>>(entity: T, key?: any): INSERT<T>
|
|
28
|
-
<T>(entity: LinkedDefinition | string, key?: any): INSERT<T>
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
33
|
-
*/
|
|
34
|
-
insert: {
|
|
35
|
-
<T extends ArrayConstructable<any>>(data: T): INSERT<T>
|
|
36
|
-
<T>(data: object | object[]): INSERT<T>
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
41
|
-
*/
|
|
42
|
-
upsert: {
|
|
43
|
-
<T extends ArrayConstructable<any>>(data: T): UPSERT<T>
|
|
44
|
-
<T>(data: object | object[]): UPSERT<T>
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
49
|
-
*/
|
|
50
|
-
update: {
|
|
51
|
-
<T extends ArrayConstructable<any>>(entity: T, key?: any): UPDATE<T>
|
|
52
|
-
<T>(entity: LinkedDefinition | string, key?: any): UPDATE<T>
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
57
|
-
*/
|
|
58
|
-
run: {
|
|
59
|
-
(query: ConstructedQuery | ConstructedQuery[]): Promise<ResultSet | any>
|
|
60
|
-
(query: Query): Promise<ResultSet | any>
|
|
61
|
-
(query: string, args?: any[] | object): Promise<ResultSet | any>
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
/**
|
|
65
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#srv-stream-column)
|
|
66
|
-
*/
|
|
67
|
-
stream: {
|
|
68
|
-
(column: string): {
|
|
69
|
-
from(entity: LinkedDefinition | string): {
|
|
70
|
-
where(filter: any): ReadableStream
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
(query: Query): Promise<ReadableStream>
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#crud-style-api)
|
|
78
|
-
*/
|
|
79
|
-
delete<T>(entity: LinkedDefinition | string, key?: any): DELETE<T>
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/core-services#srv-foreach-entity)
|
|
83
|
-
*/
|
|
84
|
-
foreach(query: Query, callback: (row: object) => void): this
|
|
85
|
-
|
|
86
|
-
transaction: {
|
|
87
|
-
(fn: (tx: Transaction) => {}): Promise<unknown>
|
|
88
|
-
(context?: object): Transaction
|
|
89
|
-
(context: object, fn: (tx: Transaction) => {}): Promise<unknown>
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Class cds.Service
|
|
96
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
97
|
-
*/
|
|
98
|
-
export class Service extends QueryAPI {
|
|
99
|
-
constructor(
|
|
100
|
-
name?: string,
|
|
101
|
-
model?: CSN,
|
|
102
|
-
options?: {
|
|
103
|
-
kind: string
|
|
104
|
-
impl: string | ServiceImpl
|
|
105
|
-
}
|
|
106
|
-
)
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* The kind of the service
|
|
110
|
-
*/
|
|
111
|
-
kind: string
|
|
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/core-services)
|
|
121
|
-
*/
|
|
122
|
-
model: LinkedCSN
|
|
123
|
-
|
|
124
|
-
/**
|
|
125
|
-
* Provides access to the entities exposed by a service
|
|
126
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
127
|
-
*/
|
|
128
|
-
entities: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Provides access to the events declared by a service
|
|
132
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
133
|
-
*/
|
|
134
|
-
events: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Provides access to the types exposed by a service
|
|
138
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
139
|
-
*/
|
|
140
|
-
types: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
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/core-services)
|
|
145
|
-
*/
|
|
146
|
-
operations: LinkedDefinitions & ((namespace: string) => LinkedDefinitions)
|
|
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/core-services#srv-init)
|
|
152
|
-
*/
|
|
153
|
-
init(): Promise<void>
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Constructs and emits an asynchronous event.
|
|
157
|
-
* @see [capire docs](https://cap.cloud.sap/docs/core-services#srv-emit-event)
|
|
158
|
-
*/
|
|
159
|
-
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>
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
/**
|
|
165
|
-
* Constructs and sends a synchronous request.
|
|
166
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#srv-send-request)
|
|
167
|
-
*/
|
|
168
|
-
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>
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
/**
|
|
178
|
-
* Constructs and sends a GET request.
|
|
179
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
180
|
-
*/
|
|
181
|
-
get<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
182
|
-
/**
|
|
183
|
-
* Constructs and sends a POST request.
|
|
184
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
185
|
-
*/
|
|
186
|
-
post<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
187
|
-
/**
|
|
188
|
-
* Constructs and sends a PUT request.
|
|
189
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
190
|
-
*/
|
|
191
|
-
put<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
192
|
-
/**
|
|
193
|
-
* Constructs and sends a PATCH request.
|
|
194
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services#rest-style-api)
|
|
195
|
-
*/
|
|
196
|
-
patch<T = any>(entityOrPath: types.target, data?: object): Promise<T>
|
|
197
|
-
/**
|
|
198
|
-
* Constructs and sends a DELETE request.
|
|
199
|
-
*/
|
|
200
|
-
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>
|
|
204
|
-
}
|
|
205
|
-
|
|
206
|
-
// The central method to dispatch events
|
|
207
|
-
dispatch(msg: types.event): Promise<any>
|
|
208
|
-
|
|
209
|
-
// FIXME: not yet documented, will come in future version
|
|
210
|
-
//disconnect (tenant?: string): Promise<void>
|
|
211
|
-
|
|
212
|
-
// Provider API
|
|
213
|
-
prepend(fn: ServiceImpl): Promise<this>
|
|
214
|
-
on<T extends Constructable>(eve: types.event, entity: T, handler: CRUDEventHandler.On<InstanceType<T>, InstanceType<T> | void | Error>): this
|
|
215
|
-
on<F extends CdsFunction>(boundAction: F, service: string, handler: ActionEventHandler<F['__parameters'], void | Error | F['__returns']>): this
|
|
216
|
-
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
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
// onSucceeded (eve: types.Events, entity: types.Target, handler: types.EventHandler): this
|
|
222
|
-
// onSucceeded (eve: types.Events, handler: types.EventHandler): this
|
|
223
|
-
// onFailed (eve: types.Events, entity: types.Target, handler: types.EventHandler): this
|
|
224
|
-
// onFailed (eve: types.Events, handler: types.EventHandler): this
|
|
225
|
-
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
|
|
228
|
-
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
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
export class ApplicationService extends Service {}
|
|
235
|
-
export class MessagingService extends Service {}
|
|
236
|
-
export class RemoteService extends Service {}
|
|
237
|
-
export class DatabaseService extends Service {
|
|
238
|
-
deploy(model?: CSN | string): Promise<CSN>
|
|
239
|
-
begin(): Promise<void>
|
|
240
|
-
commit(): Promise<void>
|
|
241
|
-
rollback(): Promise<void>
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
export default class cds {
|
|
246
|
-
/**
|
|
247
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/core-services)
|
|
248
|
-
*/
|
|
249
|
-
Service: typeof Service
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/app-services)
|
|
253
|
-
*/
|
|
254
|
-
ApplicationService: typeof ApplicationService
|
|
255
|
-
|
|
256
|
-
/**
|
|
257
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/remote-services)
|
|
258
|
-
*/
|
|
259
|
-
RemoteService: typeof RemoteService
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/messaging)
|
|
263
|
-
*/
|
|
264
|
-
MessagingService: typeof MessagingService
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/databases)
|
|
268
|
-
*/
|
|
269
|
-
DatabaseService: typeof DatabaseService
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
export interface Transaction extends Service {
|
|
274
|
-
commit(): Promise<void>
|
|
275
|
-
rollback(): Promise<void>
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
interface ResultSet extends Array<{}> {}
|
|
279
|
-
|
|
280
|
-
interface ServiceImpl {
|
|
281
|
-
(this: Service, srv: Service): any
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
interface EventHandler {
|
|
285
|
-
// (msg : types.EventMessage) : Promise<any> | any | void
|
|
286
|
-
(req: Request): Promise<any> | any | void
|
|
287
|
-
}
|
|
288
|
-
|
|
289
|
-
interface OnEventHandler {
|
|
290
|
-
(req: Request, next: Function): Promise<any> | any | void
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
// `Partial` wraps any type and allows all properties to be undefined
|
|
294
|
-
// in addition to their actual type.
|
|
295
|
-
// This is important in the context of CRUD events, where
|
|
296
|
-
// entities could be lacking any properties, like a non-existing ID
|
|
297
|
-
// or when DB fields are corrupted, etc.
|
|
298
|
-
type Partial<T> = { [Key in keyof T]: undefined | T[Key] }
|
|
299
|
-
|
|
300
|
-
// Naming the first parameter in a handler `each` has special voodoo
|
|
301
|
-
// semantic which makes it impossible for us to infer the exact behaviour on a type level.
|
|
302
|
-
// So we always have to expect scalars as well as arrays in some callbacks.
|
|
303
|
-
type OneOrMany<T> = T | T[];
|
|
304
|
-
|
|
305
|
-
// functions generated by cds-typer explicitly carry types for
|
|
306
|
-
// parameters and return type, as their names are not accessible from
|
|
307
|
-
// function signatures to the type system.
|
|
308
|
-
// This meta information is required in .on action handlers.
|
|
309
|
-
type CdsFunction = {
|
|
310
|
-
(...args: any[]): any,
|
|
311
|
-
__parameters: object,
|
|
312
|
-
__returns: unknown
|
|
313
|
-
}
|
|
314
|
-
|
|
315
|
-
type TypedRequest<T> = Omit<Request, 'data'> & { data: T }
|
|
316
|
-
|
|
317
|
-
// https://cap.cloud.sap/docs/node.js/core-services#srv-on-before-after
|
|
318
|
-
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
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
// Handlers for actions try to infer the passed .data property
|
|
325
|
-
// as strictly as possible and therefore have to remove
|
|
326
|
-
// { data: any } (inherited EventMessage} with a more restricted
|
|
327
|
-
// type, based on the parameters of the action.
|
|
328
|
-
interface ActionEventHandler<P,R> {
|
|
329
|
-
(req: Omit<Request, 'data'> & { data: P }, next: Function): Promise<R> | R
|
|
330
|
-
}
|
|
331
|
-
|
|
332
|
-
// Note: the behaviour of ResultsHandler changes based on the name of the parameter.
|
|
333
|
-
// If the parameter in the hook is called "each", it is called once for each row in the result,
|
|
334
|
-
// otherwise it gets called exactly one time with the entire result.
|
|
335
|
-
// This runtime behaviour can not be described on type level
|
|
336
|
-
// (in a way that would benefit the user).
|
|
337
|
-
// The user will therefore receive "any" as their result/ each. If we could some day differentiate,
|
|
338
|
-
// we may want to add a generic to ResultsHandler which is passed from the EventHandlers down below.
|
|
339
|
-
interface ResultsHandler {
|
|
340
|
-
(results: any[], req: Request): void
|
|
341
|
-
(each: any, req: Request): void
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
interface SpawnEvents {
|
|
345
|
-
'succeeded': (res: any) => void
|
|
346
|
-
'failed': (error: any) => void
|
|
347
|
-
'done': () => void
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
declare class SpawnEventEmitter {
|
|
351
|
-
on<U extends keyof SpawnEvents>(
|
|
352
|
-
event: U, listener: SpawnEvents[U]
|
|
353
|
-
): this;
|
|
354
|
-
|
|
355
|
-
emit<U extends keyof SpawnEvents>(
|
|
356
|
-
event: U, ...args: Parameters<SpawnEvents[U]>
|
|
357
|
-
): boolean;
|
|
358
|
-
timer: any
|
|
359
|
-
}
|
|
360
|
-
|
|
361
|
-
declare namespace types {
|
|
362
|
-
type event = eventName | eventName[]
|
|
363
|
-
type eventName = (string & {})
|
|
364
|
-
| 'CREATE' | 'READ' | 'UPDATE' | 'DELETE'
|
|
365
|
-
| 'NEW' | 'EDIT' | 'PATCH' | 'SAVE'
|
|
366
|
-
| 'GET' | 'PUT' | 'POST' | 'PATCH' | 'DELETE'
|
|
367
|
-
| 'COMMIT' | 'ROLLBACK'
|
|
368
|
-
type target = string | LinkedDefinition | LinkedEntity | (string | LinkedDefinition | LinkedEntity)[] | ArrayConstructable<any>
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
type SpawnOptions = {
|
|
372
|
-
[key: string]: any
|
|
373
|
-
every?: number
|
|
374
|
-
after?: number
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
// FIXME: this was ?: EventContext before. Is context supposed to not be present sometimes?
|
|
378
|
-
// let, as apparently we can reassign?
|
|
379
|
-
/**
|
|
380
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx#event-contexts
|
|
381
|
-
*/
|
|
382
|
-
export let context: EventContext | undefined
|
|
383
|
-
|
|
384
|
-
/**
|
|
385
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx#cds-spawn)
|
|
386
|
-
*/
|
|
387
|
-
export function spawn(options: SpawnOptions, fn: (tx: Transaction) => {}): SpawnEventEmitter
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
// facade proxies into cds.db, which is a Service
|
|
391
|
-
/**
|
|
392
|
-
* Starts or joins a transaction
|
|
393
|
-
* @see [docs](https://cap.cloud.sap/docs/node.js/cds-tx)
|
|
394
|
-
*/
|
|
395
|
-
export const tx: {
|
|
396
|
-
(fn: (tx: Transaction) => {}): Promise<unknown>
|
|
397
|
-
(context?: object): Transaction
|
|
398
|
-
(context: object, fn: (tx: Transaction) => {}): Promise<unknown>
|
|
399
|
-
}
|
|
400
|
-
export const entities: Service['entities']
|
|
401
|
-
export const run: Service['run']
|
|
402
|
-
export const foreach: Service['foreach']
|
|
403
|
-
export const stream: Service['stream']
|
|
404
|
-
export const read: Service['read']
|
|
405
|
-
export const create: Service['create']
|
|
406
|
-
export const insert: Service['insert']
|
|
407
|
-
export const update: Service['update']
|
|
408
|
-
// temporarily moved to cds.d.ts, as "delete" is a reserved keyword
|
|
409
|
-
// export const delete: Service['delete']
|
|
410
|
-
// FIXME: see Service.disconnect comment
|
|
411
|
-
//export const disconnect: Service['disconnect']
|
|
412
|
-
export const transaction: Service['transaction']
|
|
413
|
-
export const db: DatabaseService
|
|
414
|
-
//export const upsert: Service['upsert']
|
package/apis/test.d.ts
DELETED
|
@@ -1,87 +0,0 @@
|
|
|
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
|
|
8
|
-
|
|
9
|
-
declare class Axios {
|
|
10
|
-
get axios(): AxiosInstance;
|
|
11
|
-
|
|
12
|
-
get : AxiosInstance['get'];
|
|
13
|
-
put : AxiosInstance['put'];
|
|
14
|
-
post : AxiosInstance['post'];
|
|
15
|
-
patch : AxiosInstance['patch'];
|
|
16
|
-
delete : AxiosInstance['delete'];
|
|
17
|
-
options : AxiosInstance['options'];
|
|
18
|
-
|
|
19
|
-
get GET() : Axios['get'];
|
|
20
|
-
get PUT() : Axios['put'];
|
|
21
|
-
get POST() : Axios['post'];
|
|
22
|
-
get PATCH() : Axios['patch'];
|
|
23
|
-
get DELETE() : Axios['delete'];
|
|
24
|
-
get OPTIONS() : Axios['options'];
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
declare class DataUtil {
|
|
28
|
-
delete(db?: Service): Promise<void>;
|
|
29
|
-
reset(db?: Service): Promise<void>;
|
|
30
|
-
/**
|
|
31
|
-
* @deprecated if needed, call `reset()`, considering test performance
|
|
32
|
-
*/
|
|
33
|
-
autoReset(enabled: boolean): this;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
declare class Test extends Axios {
|
|
37
|
-
|
|
38
|
-
test : Test
|
|
39
|
-
|
|
40
|
-
run(cmd: string, ...args: string[]): this;
|
|
41
|
-
in(...paths: string[]): this;
|
|
42
|
-
silent(): this;
|
|
43
|
-
/**
|
|
44
|
-
* @deprecated Server log is shown by default. Use `log()` to get control over it.
|
|
45
|
-
*/
|
|
46
|
-
verbose(v: boolean): this;
|
|
47
|
-
|
|
48
|
-
get chai(): typeof chai;
|
|
49
|
-
get expect(): typeof chai.expect;
|
|
50
|
-
get assert(): typeof chai.assert;
|
|
51
|
-
get data(): DataUtil;
|
|
52
|
-
get cds(): _cds
|
|
53
|
-
|
|
54
|
-
log() : {
|
|
55
|
-
output: string
|
|
56
|
-
clear(): void
|
|
57
|
-
release(): void
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
then(r: (args: { server: http.Server, url: string }) => void): void;
|
|
61
|
-
|
|
62
|
-
// get sleep(): (ms: number) => Promise<void>;
|
|
63
|
-
// get spy(): <T, K extends keyof T>(o: T, f: K) => T[K] extends (...args: infer TArgs) => infer TReturnValue
|
|
64
|
-
// ? Spy<TArgs, TReturnValue>
|
|
65
|
-
// : Spy;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// typings for spy inspired by @types/sinon
|
|
69
|
-
// interface Spy<TArgs extends any[] = any[], TReturnValue = any> {
|
|
70
|
-
// (...args: TArgs): TReturnValue;
|
|
71
|
-
// called: number;
|
|
72
|
-
// restore(): (...args: TArgs) => TReturnValue;
|
|
73
|
-
// }
|
|
74
|
-
|
|
75
|
-
declare const test: {
|
|
76
|
-
Test: typeof Test
|
|
77
|
-
/**
|
|
78
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/cds-test#class-cds-test-test)
|
|
79
|
-
*/
|
|
80
|
-
(dirname: string): Test;
|
|
81
|
-
/**
|
|
82
|
-
* @see [capire docs](https://cap.cloud.sap/docs/node.js/cds-test#class-cds-test-test)
|
|
83
|
-
*/
|
|
84
|
-
(command: string, ...args: string[]): Test;
|
|
85
|
-
|
|
86
|
-
in (dirname: string) : Test
|
|
87
|
-
}
|