@cap-js/cds-types 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cds-types.d.ts +2778 -0
- package/package.json +22 -15
- package/apis/cds.d.ts +0 -44
- package/apis/core.d.ts +0 -108
- package/apis/cqn.d.ts +0 -98
- package/apis/csn.d.ts +0 -126
- package/apis/env.d.ts +0 -22
- package/apis/events.d.ts +0 -149
- package/apis/internal/inference.d.ts +0 -66
- package/apis/linked.d.ts +0 -104
- package/apis/log.d.ts +0 -173
- package/apis/models.d.ts +0 -173
- package/apis/ql.d.ts +0 -395
- package/apis/server.d.ts +0 -145
- package/apis/services.d.ts +0 -449
- package/apis/test.d.ts +0 -112
- package/apis/utils.d.ts +0 -90
package/apis/ql.d.ts
DELETED
|
@@ -1,395 +0,0 @@
|
|
|
1
|
-
import { Definition, EntityElements } from './csn'
|
|
2
|
-
import * as CQN from './cqn'
|
|
3
|
-
import { Constructable, ArrayConstructable, SingularType } from './internal/inference'
|
|
4
|
-
import { LinkedEntity } from './linked'
|
|
5
|
-
import { ref, column_expr } from './cqn'
|
|
6
|
-
|
|
7
|
-
export type Query = CQN.Query
|
|
8
|
-
|
|
9
|
-
export class ConstructedQuery {
|
|
10
|
-
|
|
11
|
-
then (_resolved: (x: any) => any, _rejected: (e: Error) => any): any
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export type PK = number | string | object
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
type Primitive = string | number | boolean | Date
|
|
20
|
-
|
|
21
|
-
// don't wrap QLExtensions in more QLExtensions (indirection to work around recursive definition)
|
|
22
|
-
type QLExtensions<T> = T extends QLExtensions_<any> ? T : QLExtensions_<T>
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* QLExtensions are properties that are attached to entities in CQL contexts.
|
|
26
|
-
* They are passed down to all properties recursively.
|
|
27
|
-
*/
|
|
28
|
-
type QLExtensions_<T> = {
|
|
29
|
-
[Key in keyof T]: QLExtensions<T[Key]>
|
|
30
|
-
} & {
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* Alias for this attribute.
|
|
34
|
-
*/
|
|
35
|
-
as: (alias: string) => void,
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Accesses any nested attribute based on a [path](https://cap.cloud.sap/cap/docs/java/query-api#path-expressions):
|
|
39
|
-
* `X.get('a.b.c.d')`. Note that you will not receive
|
|
40
|
-
* proper typing after this call.
|
|
41
|
-
* To still have access to typed results, use
|
|
42
|
-
* `X.a().b().c().d()` instead.
|
|
43
|
-
*/
|
|
44
|
-
get: (path: string) => any,
|
|
45
|
-
|
|
46
|
-
// have to exclude undefined from the type, or we'd end up with a distribution of Subqueryable
|
|
47
|
-
// over T and undefined, which gives us zero code completion within the callable.
|
|
48
|
-
} & Subqueryable<Exclude<T, undefined>>
|
|
49
|
-
|
|
50
|
-
/**
|
|
51
|
-
* Adds the ability for subqueries to structured properties.
|
|
52
|
-
* The final result of each subquery will be the property itself:
|
|
53
|
-
* `Book.title` == `Subqueryable<Book>.title()`
|
|
54
|
-
*/
|
|
55
|
-
type Subqueryable<T> = T extends Primitive ? unknown
|
|
56
|
-
// composition of many/ association to many
|
|
57
|
-
: T extends readonly unknown[] ? {
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* @example
|
|
61
|
-
* ```js
|
|
62
|
-
* SELECT.from(Books, b => b.author)
|
|
63
|
-
* ```
|
|
64
|
-
* means: "select all books and project each book's author"
|
|
65
|
-
*
|
|
66
|
-
* whereas
|
|
67
|
-
* ```js
|
|
68
|
-
* SELECT.from(Books, b => b.author(a => a.ID))
|
|
69
|
-
* ```
|
|
70
|
-
* means: "select all books, subselect each book's author's ID
|
|
71
|
-
*
|
|
72
|
-
* Note that you do not need to return anything from these subqueries.
|
|
73
|
-
*/
|
|
74
|
-
(fn: ((a: QLExtensions<T[number]>) => any) | '*'): T[number],
|
|
75
|
-
}
|
|
76
|
-
// composition of one/ association to one
|
|
77
|
-
: {
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* @example
|
|
81
|
-
* ```js
|
|
82
|
-
* SELECT.from(Books, b => b.author)
|
|
83
|
-
* ```
|
|
84
|
-
* means: "select all books and project each book's author"
|
|
85
|
-
*
|
|
86
|
-
* whereas
|
|
87
|
-
* ```js
|
|
88
|
-
* SELECT.from(Books, b => b.author(a => a.ID))
|
|
89
|
-
* ```
|
|
90
|
-
* means: "select all books, subselect each book's author's ID
|
|
91
|
-
*
|
|
92
|
-
* Note that you do not need to return anything from these subqueries.
|
|
93
|
-
*/
|
|
94
|
-
(fn: ((a: QLExtensions<T>) => any) | '*'): T,
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
// Alias for projections
|
|
99
|
-
// https://cap.cloud.sap/docs/node.js/cds-ql?q=projection#projection-functions
|
|
100
|
-
// export type Projection<T> = (e:T)=>void
|
|
101
|
-
export type Projection<T> = (e: QLExtensions<T extends ArrayConstructable ? SingularType<T> : T>) => void
|
|
102
|
-
// Type for query pieces that can either be chained to build more complex queries or
|
|
103
|
-
// awaited to materialise the result:
|
|
104
|
-
// `Awaitable<SELECT<Book>, Book> = SELECT<Book> & Promise<Book>`
|
|
105
|
-
//
|
|
106
|
-
// While the benefit is probably not immediately obvious as we don't exactly
|
|
107
|
-
// save a lot of typing over explicitly writing `SELECT<Book> & Promise<Book>`,
|
|
108
|
-
// it makes the semantics more explicit. Also sets us up for when TypeScript ever
|
|
109
|
-
// improves their generics to support:
|
|
110
|
-
//
|
|
111
|
-
// `Awaitable<T> = T extends unknown<infer I> ? (T & Promise<I>) : never`
|
|
112
|
-
// (at the time of writing, infering the first generic parameter of ANY type
|
|
113
|
-
// does not seem to be possible.)
|
|
114
|
-
export type Awaitable<T, I> = T & Promise<I>
|
|
115
|
-
|
|
116
|
-
// all the functionality of an instance of SELECT, but directly callable:
|
|
117
|
-
// new SELECT(...).(...) == SELECT(...)
|
|
118
|
-
export type StaticSELECT<T> = typeof SELECT
|
|
119
|
-
& ((...columns: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) => SELECT<T>)
|
|
120
|
-
& ((...columns: string[]) => SELECT<T>)
|
|
121
|
-
& ((columns: string[]) => SELECT<T>)
|
|
122
|
-
& (TaggedTemplateQueryPart<SELECT<T>>)
|
|
123
|
-
& SELECT_one // as it is not directly quantified, ...
|
|
124
|
-
& SELECT_from // ...we should expect both a scalar and a list
|
|
125
|
-
|
|
126
|
-
declare class QL<T> {
|
|
127
|
-
|
|
128
|
-
SELECT: StaticSELECT<T>
|
|
129
|
-
|
|
130
|
-
INSERT: typeof INSERT
|
|
131
|
-
& ((...entries: object[]) => INSERT<any>) & ((entries: object[]) => INSERT<any>)
|
|
132
|
-
|
|
133
|
-
UPSERT: typeof UPSERT
|
|
134
|
-
& ((...entries: object[]) => UPSERT<any>) & ((entries: object[]) => UPSERT<any>)
|
|
135
|
-
|
|
136
|
-
UPDATE: typeof UPDATE
|
|
137
|
-
& typeof UPDATE.entity
|
|
138
|
-
|
|
139
|
-
DELETE: typeof DELETE
|
|
140
|
-
& ((...entries: object[]) => DELETE<any>) & ((entries: object[]) => DELETE<any>)
|
|
141
|
-
|
|
142
|
-
CREATE: typeof CREATE
|
|
143
|
-
|
|
144
|
-
DROP: typeof DROP
|
|
145
|
-
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
// used as a catch-all type for using tagged template strings: SELECT `foo`. from `bar` etc.
|
|
149
|
-
// the resulting signatures are actually not very strongly typed, but they at least accept template strings
|
|
150
|
-
// when run in strict mode.
|
|
151
|
-
// This signature has to be added to a method as intersection type.
|
|
152
|
-
// Defining overloads with it will override preceding signatures and the other way around.
|
|
153
|
-
type TaggedTemplateQueryPart<T> = (strings: TemplateStringsArray, ...params: unknown[]) => T
|
|
154
|
-
|
|
155
|
-
export class SELECT<T> extends ConstructedQuery {
|
|
156
|
-
|
|
157
|
-
static one: SELECT_one & { from: SELECT_one }
|
|
158
|
-
|
|
159
|
-
static distinct: typeof SELECT
|
|
160
|
-
|
|
161
|
-
static from: SELECT_from
|
|
162
|
-
|
|
163
|
-
from: SELECT_from & TaggedTemplateQueryPart<this>
|
|
164
|
-
& ((entity: Definition | string, primaryKey?: PK, projection?: Projection<unknown>) => this)
|
|
165
|
-
|
|
166
|
-
byKey (primaryKey?: PK): this
|
|
167
|
-
columns: TaggedTemplateQueryPart<this>
|
|
168
|
-
& ((projection: Projection<T>) => this)
|
|
169
|
-
& ((...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]) => this)
|
|
170
|
-
& ((...col: (string | column_expr)[]) => this)
|
|
171
|
-
& ((col: (string | column_expr)[]) => this)
|
|
172
|
-
|
|
173
|
-
where: TaggedTemplateQueryPart<this>
|
|
174
|
-
& ((predicate: object) => this)
|
|
175
|
-
& ((...expr: any[]) => this)
|
|
176
|
-
|
|
177
|
-
and: TaggedTemplateQueryPart<this>
|
|
178
|
-
& ((predicate: object) => this)
|
|
179
|
-
& ((...expr: any[]) => this)
|
|
180
|
-
|
|
181
|
-
having: TaggedTemplateQueryPart<this>
|
|
182
|
-
& ((...expr: string[]) => this)
|
|
183
|
-
& ((predicate: object) => this)
|
|
184
|
-
|
|
185
|
-
groupBy: TaggedTemplateQueryPart<this>
|
|
186
|
-
& ((...expr: string[]) => this)
|
|
187
|
-
|
|
188
|
-
orderBy: TaggedTemplateQueryPart<this>
|
|
189
|
-
& ((...expr: string[]) => this)
|
|
190
|
-
|
|
191
|
-
limit: TaggedTemplateQueryPart<this>
|
|
192
|
-
& ((rows: number, offset?: number) => this)
|
|
193
|
-
|
|
194
|
-
forShareLock (): this
|
|
195
|
-
|
|
196
|
-
forUpdate ({ wait }?: { wait?: number }): this
|
|
197
|
-
|
|
198
|
-
alias (as: string): this
|
|
199
|
-
elements: EntityElements
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
// Not yet public
|
|
203
|
-
// fullJoin (other: string, as: string) : this
|
|
204
|
-
// leftJoin (other: string, as: string) : this
|
|
205
|
-
// rightJoin (other: string, as: string) : this
|
|
206
|
-
// innerJoin (other: string, as: string) : this
|
|
207
|
-
// join (other: string, as: string, kind?: string) : this
|
|
208
|
-
// on : TaggedTemplateQueryPart<this>
|
|
209
|
-
// & ((...expr : string[]) => this)
|
|
210
|
-
// & ((predicate:object) => this)
|
|
211
|
-
|
|
212
|
-
SELECT: CQN.SELECT['SELECT'] & {
|
|
213
|
-
forUpdate?: { wait: number },
|
|
214
|
-
forShareLock?: { wait: number },
|
|
215
|
-
search?: CQN.predicate,
|
|
216
|
-
count?: boolean,
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
type SELECT_one =
|
|
223
|
-
TaggedTemplateQueryPart<Awaitable<SELECT<unknown>, InstanceType<any>>>
|
|
224
|
-
&
|
|
225
|
-
// calling with class
|
|
226
|
-
(<T extends ArrayConstructable<any>>
|
|
227
|
-
(entityType: T, projection?: Projection<QLExtensions<SingularType<T>>>)
|
|
228
|
-
=> Awaitable<SELECT<SingularType<T>>, SingularType<T>>)
|
|
229
|
-
&
|
|
230
|
-
(<T extends ArrayConstructable<any>>
|
|
231
|
-
(entityType: T, primaryKey: PK, projection?: Projection<QLExtensions<SingularType<T>>>)
|
|
232
|
-
=> Awaitable<SELECT<SingularType<T>>, SingularType<T>>)
|
|
233
|
-
|
|
234
|
-
& ((entity: Definition | string, primaryKey?: PK, projection?: Projection<unknown>) => SELECT<any>)
|
|
235
|
-
& ((entity: LinkedEntity | string, primaryKey?: PK, projection?: Projection<unknown>) => SELECT<any>)
|
|
236
|
-
& (<T> (entity: T[], projection?: Projection<T>) => Awaitable<SELECT<T>, T>)
|
|
237
|
-
& (<T> (entity: T[], primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT<T>, T>)
|
|
238
|
-
& (<T> (entity: { new(): T }, projection?: Projection<T>) => Awaitable<SELECT<T>, T>)
|
|
239
|
-
& (<T> (entity: { new(): T }, primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT<T>, T>)
|
|
240
|
-
& ((subject: ref) => SELECT<any>)
|
|
241
|
-
|
|
242
|
-
type SELECT_from =
|
|
243
|
-
// tagged template
|
|
244
|
-
TaggedTemplateQueryPart<Awaitable<SELECT<unknown>, InstanceType<any>>>
|
|
245
|
-
&
|
|
246
|
-
// calling with class
|
|
247
|
-
(<T extends ArrayConstructable<any>>
|
|
248
|
-
(entityType: T, projection?: Projection<QLExtensions<SingularType<T>>>)
|
|
249
|
-
=> Awaitable<SELECT<T>, InstanceType<T>>)
|
|
250
|
-
&
|
|
251
|
-
(<T extends ArrayConstructable<any>>
|
|
252
|
-
(entityType: T, primaryKey: PK, projection?: Projection<SingularType<T>>)
|
|
253
|
-
=> Awaitable<SELECT<SingularType<T>>, InstanceType<SingularType<T>>>) // when specifying a key, we expect a single element as result
|
|
254
|
-
// calling with definition
|
|
255
|
-
& ((entity: Definition | string, primaryKey?: PK, projection?: Projection<unknown>) => SELECT<any>)
|
|
256
|
-
& ((entity: LinkedEntity | string, primaryKey?: PK, projection?: Projection<unknown>) => SELECT<any>)
|
|
257
|
-
// calling with concrete list
|
|
258
|
-
& (<T> (entity: T[], projection?: Projection<T>) => SELECT<T> & Promise<T[]>)
|
|
259
|
-
& (<T> (entity: T[], primaryKey: PK, projection?: Projection<T>) => Awaitable<SELECT<T>, T>)
|
|
260
|
-
& ((subject: ref) => SELECT<any>)
|
|
261
|
-
|
|
262
|
-
export class INSERT<T> extends ConstructedQuery {
|
|
263
|
-
|
|
264
|
-
static into: (<T extends ArrayConstructable<any>> (entity: T, entries?: object | object[]) => INSERT<SingularType<T>>)
|
|
265
|
-
& (TaggedTemplateQueryPart<INSERT<unknown>>)
|
|
266
|
-
& ((entity: Definition | string, entries?: object | object[]) => INSERT<any>)
|
|
267
|
-
& ((entity: LinkedEntity | string, entries?: object | object[]) => INSERT<any>)
|
|
268
|
-
& (<T> (entity: Constructable<T>, entries?: object | object[]) => INSERT<T>)
|
|
269
|
-
& (<T> (entity: T, entries?: T | object | object[]) => INSERT<T>)
|
|
270
|
-
|
|
271
|
-
into: (<T extends ArrayConstructable> (entity: T) => this)
|
|
272
|
-
& TaggedTemplateQueryPart<this>
|
|
273
|
-
& ((entity: Definition | string) => this)
|
|
274
|
-
|
|
275
|
-
data (block: (e: T) => void): this
|
|
276
|
-
|
|
277
|
-
entries (...entries: object[]): this
|
|
278
|
-
|
|
279
|
-
columns (...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]): this
|
|
280
|
-
|
|
281
|
-
columns (...col: string[]): this
|
|
282
|
-
|
|
283
|
-
values (...val: any[]): this
|
|
284
|
-
|
|
285
|
-
rows (...row: any[]): this
|
|
286
|
-
|
|
287
|
-
as (select: SELECT<T>): this
|
|
288
|
-
INSERT: CQN.INSERT['INSERT']
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
export class UPSERT<T> extends ConstructedQuery {
|
|
294
|
-
|
|
295
|
-
static into: (<T extends ArrayConstructable<any>> (entity: T, entries?: object | object[]) => UPSERT<SingularType<T>>)
|
|
296
|
-
& (TaggedTemplateQueryPart<UPSERT<unknown>>)
|
|
297
|
-
& ((entity: Definition | string, entries?: object | object[]) => UPSERT<any>)
|
|
298
|
-
& ((entity: LinkedEntity | string, entries?: object | object[]) => UPSERT<any>)
|
|
299
|
-
& (<T> (entity: Constructable<T>, entries?: object | object[]) => UPSERT<T>)
|
|
300
|
-
& (<T> (entity: T, entries?: T | object | object[]) => UPSERT<T>)
|
|
301
|
-
|
|
302
|
-
into: (<T extends ArrayConstructable> (entity: T) => this)
|
|
303
|
-
& TaggedTemplateQueryPart<this>
|
|
304
|
-
& ((entity: Definition | string) => this)
|
|
305
|
-
|
|
306
|
-
data (block: (e: T) => void): this
|
|
307
|
-
|
|
308
|
-
entries (...entries: object[]): this
|
|
309
|
-
|
|
310
|
-
columns (...col: (T extends ArrayConstructable<any> ? keyof SingularType<T> : keyof T)[]): this
|
|
311
|
-
|
|
312
|
-
columns (...col: string[]): this
|
|
313
|
-
|
|
314
|
-
values (...val: any[]): this
|
|
315
|
-
|
|
316
|
-
rows (...row: any[]): this
|
|
317
|
-
UPSERT: CQN.UPSERT['UPSERT']
|
|
318
|
-
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
322
|
-
export class DELETE<T> extends ConstructedQuery {
|
|
323
|
-
|
|
324
|
-
static from:
|
|
325
|
-
TaggedTemplateQueryPart<Awaitable<SELECT<unknown>, InstanceType<any>>>
|
|
326
|
-
& ((entity: Definition | string | ArrayConstructable, primaryKey?: PK) => DELETE<any>)
|
|
327
|
-
& ((entity: LinkedEntity | string | ArrayConstructable, primaryKey?: PK) => DELETE<any>)
|
|
328
|
-
& ((subject: ref) => DELETE<any>)
|
|
329
|
-
|
|
330
|
-
byKey (primaryKey?: PK): this
|
|
331
|
-
|
|
332
|
-
where (predicate: object): this
|
|
333
|
-
|
|
334
|
-
where (...expr: any[]): this
|
|
335
|
-
|
|
336
|
-
and (predicate: object): this
|
|
337
|
-
|
|
338
|
-
and (...expr: any[]): this
|
|
339
|
-
DELETE: CQN.DELETE['DELETE']
|
|
340
|
-
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
344
|
-
export class UPDATE<T> extends ConstructedQuery {
|
|
345
|
-
|
|
346
|
-
// cds-typer plural
|
|
347
|
-
static entity<T extends ArrayConstructable<any>> (entity: T, primaryKey?: PK): UPDATE<SingularType<T>>
|
|
348
|
-
|
|
349
|
-
static entity (entity: Definition | string, primaryKey?: PK): UPDATE<any>
|
|
350
|
-
|
|
351
|
-
static entity (entity: LinkedEntity | string, primaryKey?: PK): UPDATE<any>
|
|
352
|
-
|
|
353
|
-
static entity<T> (entity: Constructable<T>, primaryKey?: PK): UPDATE<T>
|
|
354
|
-
|
|
355
|
-
static entity<T> (entity: T, primaryKey?: PK): UPDATE<T>
|
|
356
|
-
|
|
357
|
-
byKey (primaryKey?: PK): this
|
|
358
|
-
// with (block: (e:T)=>void) : this
|
|
359
|
-
// set (block: (e:T)=>void) : this
|
|
360
|
-
set: TaggedTemplateQueryPart<this>
|
|
361
|
-
& ((data: object) => this);
|
|
362
|
-
|
|
363
|
-
with: TaggedTemplateQueryPart<this>
|
|
364
|
-
& ((data: object) => this)
|
|
365
|
-
|
|
366
|
-
where (predicate: object): this
|
|
367
|
-
|
|
368
|
-
where (...expr: any[]): this
|
|
369
|
-
|
|
370
|
-
and (predicate: object): this
|
|
371
|
-
|
|
372
|
-
and (...expr: any[]): this
|
|
373
|
-
UPDATE: CQN.UPDATE['UPDATE']
|
|
374
|
-
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
378
|
-
export class CREATE<T> extends ConstructedQuery {
|
|
379
|
-
|
|
380
|
-
static entity (entity: Definition | string): CREATE<any>
|
|
381
|
-
|
|
382
|
-
static entity (entity: LinkedEntity | string): CREATE<any>
|
|
383
|
-
CREATE: CQN.CREATE['CREATE']
|
|
384
|
-
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
/* eslint-disable-next-line @typescript-eslint/no-unused-vars */
|
|
388
|
-
export class DROP<T> extends ConstructedQuery {
|
|
389
|
-
|
|
390
|
-
static entity (entity: Definition | string): DROP<any>
|
|
391
|
-
|
|
392
|
-
static entity (entity: LinkedEntity | string): DROP<any>
|
|
393
|
-
DROP: CQN.DROP['DROP']
|
|
394
|
-
|
|
395
|
-
}
|
package/apis/server.d.ts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/ban-types */
|
|
2
|
-
import { Service, ServiceImpl } from './services'
|
|
3
|
-
import { CSN } from './csn'
|
|
4
|
-
import * as http from 'http'
|
|
5
|
-
import * as cds from './cds'
|
|
6
|
-
import { Application } from 'express'
|
|
7
|
-
|
|
8
|
-
type _cds = typeof cds
|
|
9
|
-
|
|
10
|
-
export const connect: {
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Connects to a specific datasource.
|
|
14
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
|
|
15
|
-
*/
|
|
16
|
-
to(datasource: string, options?: cds_connect_options): Promise<Service>,
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Connects to a specific datasource via options.
|
|
20
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
|
|
21
|
-
*/
|
|
22
|
-
to(options: cds_connect_options): Promise<Service>,
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Connects the primary datasource.
|
|
26
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect)
|
|
27
|
-
*/
|
|
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
|
-
}
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* The default bootstrap function as loaded from server.js
|
|
34
|
-
*/
|
|
35
|
-
export const server: Function
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Constructs service providers from respective service definitions
|
|
39
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-serve)
|
|
40
|
-
*/
|
|
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
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Emitted whenever a model is loaded using cds.load().
|
|
49
|
-
*/
|
|
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
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* Emitted whenever a specific service is connected for the first time.
|
|
56
|
-
*/
|
|
57
|
-
export function on (event: 'connect', listener: (srv: Service) => void): _cds
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Emitted at the very beginning of the bootsrapping process, when the
|
|
62
|
-
* express application has been constructed but no middlewares or routes
|
|
63
|
-
* added yet.
|
|
64
|
-
*/
|
|
65
|
-
export function on (event: 'bootstrap', listener: (app: Application) => void): _cds
|
|
66
|
-
export function once (event: 'bootstrap', listener: (app: Application) => void): _cds
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* Emitted for each service served by cds.serve().
|
|
70
|
-
*/
|
|
71
|
-
export function on (event: 'serving', listener: (srv: Service) => void): _cds
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* Emitted by the default, built-in `server.js` when all services are
|
|
75
|
-
* constructed and mounted by cds.serve().
|
|
76
|
-
*/
|
|
77
|
-
export function on (event: 'served', listener: (all: cds_services) => void): _cds
|
|
78
|
-
export function once (event: 'served', listener: (all: cds_services) => void): _cds
|
|
79
|
-
|
|
80
|
-
/**
|
|
81
|
-
* Emitted by the default, built-in `server.js` when the http server
|
|
82
|
-
* is started and listening for incoming requests.
|
|
83
|
-
*/
|
|
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
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* Emitted by the default, built-in `server.js` when the http server
|
|
89
|
-
* is shutdown.
|
|
90
|
-
*/
|
|
91
|
-
export function on (event: 'shutdown', listener: () => void): _cds
|
|
92
|
-
export function once (event: 'shutdown', listener: () => void): _cds
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* Dictionary of all services constructed and/or connected.
|
|
96
|
-
*/
|
|
97
|
-
export const services: cds_services
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* Shortcut to base class for all service definitions from linked models.
|
|
101
|
-
* Plus accessors to impl functions and constructed providers.
|
|
102
|
-
*/
|
|
103
|
-
export const service: service
|
|
104
|
-
|
|
105
|
-
/**
|
|
106
|
-
* Provides a graceful shutdown for running servers, by first emitting `cds.emit('shutdown')`.
|
|
107
|
-
* @see [capire](https://cap.cloud.sap/docs/node.js/cds-facade#cds-exit)
|
|
108
|
-
*/
|
|
109
|
-
export function exit (): void
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
export type service = {
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Dummy wrapper for service implementation functions.
|
|
116
|
-
* Use that in modules to get IntelliSense.
|
|
117
|
-
*/
|
|
118
|
-
impl (impl: ServiceImpl): typeof impl,
|
|
119
|
-
// impl <T> (srv:T, impl: ( _cds: T, srv: (T) ) => any) : typeof impl
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Array of all services constructed.
|
|
123
|
-
*/
|
|
124
|
-
providers: Service[],
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
type cds_services = { [name: string]: Service }
|
|
129
|
-
|
|
130
|
-
interface cds_serve_fluent {
|
|
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
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
interface cds_connect_options {
|
|
140
|
-
impl?: string
|
|
141
|
-
service?: string
|
|
142
|
-
kind?: string
|
|
143
|
-
model?: string
|
|
144
|
-
credentials?: object
|
|
145
|
-
}
|