@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/apis/server.d.ts CHANGED
@@ -1,135 +1,145 @@
1
- import { Service, ServiceImpl } from "./services"
2
- import { CSN } from "./csn"
3
- import * as http from "http"
4
- import { Application } from "express"
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'
5
7
 
6
- export default class cds {
8
+ type _cds = typeof cds
7
9
 
8
- connect: {
9
- /**
10
+ export const connect: {
11
+
12
+ /**
10
13
  * Connects to a specific datasource.
11
14
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
12
15
  */
13
- to(datasource: string, options?: cds_connect_options): Promise<Service>
16
+ to(datasource: string, options?: cds_connect_options): Promise<Service>,
14
17
 
15
- /**
18
+ /**
16
19
  * Connects to a specific datasource via options.
17
20
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect#cds-connect-to)
18
21
  */
19
- to(options: cds_connect_options): Promise<Service>
22
+ to(options: cds_connect_options): Promise<Service>,
20
23
 
21
- /**
24
+ /**
22
25
  * Connects the primary datasource.
23
26
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-connect)
24
27
  */
25
- (options?: string | cds_connect_options): Promise<typeof cds> //> cds.connect(<options>)
26
- }
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
+ }
27
31
 
28
- /**
32
+ /**
29
33
  * The default bootstrap function as loaded from server.js
30
34
  */
31
- server: Function
35
+ export const server: Function
32
36
 
33
- /**
37
+ /**
34
38
  * Constructs service providers from respective service definitions
35
39
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-serve)
36
40
  */
37
- serve (service : string, options?: {
38
- service?: string,
39
- from?: '*' | 'all' | string,
40
- [key: string]: unknown
41
- }) : Promise<cds_services> & cds_serve_fluent
42
-
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
43
53
 
44
- /**
54
+ /**
45
55
  * Emitted whenever a specific service is connected for the first time.
46
56
  */
47
- on(event: 'connect', listener: (srv: Service) => void): this
57
+ export function on (event: 'connect', listener: (srv: Service) => void): _cds
48
58
 
49
59
 
50
- /**
60
+ /**
51
61
  * Emitted at the very beginning of the bootsrapping process, when the
52
62
  * express application has been constructed but no middlewares or routes
53
63
  * added yet.
54
64
  */
55
- on (event : 'bootstrap', listener : (app : Application) => void) : this
56
- once (event : 'bootstrap', listener : (app : Application) => void) : this
65
+ export function on (event: 'bootstrap', listener: (app: Application) => void): _cds
66
+ export function once (event: 'bootstrap', listener: (app: Application) => void): _cds
57
67
 
58
- /**
68
+ /**
59
69
  * Emitted for each service served by cds.serve().
60
70
  */
61
- on (event : 'serving', listener : (srv : Service) => void) : this
71
+ export function on (event: 'serving', listener: (srv: Service) => void): _cds
62
72
 
63
- /**
73
+ /**
64
74
  * Emitted by the default, built-in `server.js` when all services are
65
75
  * constructed and mounted by cds.serve().
66
76
  */
67
- on (event : 'served', listener : (all : cds_services) => void) : this
68
- once (event : 'served', listener : (all : cds_services) => void) : this
77
+ export function on (event: 'served', listener: (all: cds_services) => void): _cds
78
+ export function once (event: 'served', listener: (all: cds_services) => void): _cds
69
79
 
70
- /**
80
+ /**
71
81
  * Emitted by the default, built-in `server.js` when the http server
72
82
  * is started and listening for incoming requests.
73
83
  */
74
- on (event : 'listening', listener : (args : { server: http.Server, url:string }) => void) : this
75
- once (event : 'listening', listener : (args : { server: http.Server, url:string }) => void) : this
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
76
86
 
77
- /**
87
+ /**
78
88
  * Emitted by the default, built-in `server.js` when the http server
79
89
  * is shutdown.
80
90
  */
81
- on (event : 'shutdown', listener : () => void) : this
82
- once (event : 'shutdown', listener : () => void) : this
91
+ export function on (event: 'shutdown', listener: () => void): _cds
92
+ export function once (event: 'shutdown', listener: () => void): _cds
83
93
 
84
- /**
94
+ /**
85
95
  * Dictionary of all services constructed and/or connected.
86
96
  */
87
- services : cds_services
97
+ export const services: cds_services
88
98
 
89
- /**
99
+ /**
90
100
  * Shortcut to base class for all service definitions from linked models.
91
101
  * Plus accessors to impl functions and constructed providers.
92
102
  */
93
- service : service
103
+ export const service: service
94
104
 
95
- /**
105
+ /**
96
106
  * Provides a graceful shutdown for running servers, by first emitting `cds.emit('shutdown')`.
97
107
  * @see [capire](https://cap.cloud.sap/docs/node.js/cds-facade#cds-exit)
98
108
  */
99
- exit(): void
109
+ export function exit (): void
100
110
 
101
- }
102
111
 
103
112
  export type service = {
104
- /**
113
+
114
+ /**
105
115
  * Dummy wrapper for service implementation functions.
106
116
  * Use that in modules to get IntelliSense.
107
117
  */
108
- impl (impl: ServiceImpl) : typeof impl
109
- // impl <T> (srv:T, impl: ( this: 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
110
120
 
111
- /**
121
+ /**
112
122
  * Array of all services constructed.
113
123
  */
114
- providers : Service[]
124
+ providers: Service[],
115
125
  }
116
126
 
117
127
 
118
- type cds_services = { [name:string]: Service }
128
+ type cds_services = { [name: string]: Service }
119
129
 
120
130
  interface cds_serve_fluent {
121
- from (model : string | CSN) : this
122
- to (protocol: string) : this
123
- at (path: string) : this
124
- in (app: Application) : this
125
- with (impl: ServiceImpl | string) : this
126
- // (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
127
137
  }
128
138
 
129
139
  interface cds_connect_options {
130
- impl?: string,
131
- service?: string,
132
- kind?: string,
133
- model?: string,
134
- credentials?: object
140
+ impl?: string
141
+ service?: string
142
+ kind?: string
143
+ model?: string
144
+ credentials?: object
135
145
  }