jimpex 8.0.0 → 9.0.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/CHANGELOG.md +13 -0
- package/README.md +2 -2
- package/dist/app/index.d.mts +14 -0
- package/dist/app/index.d.ts +5 -4
- package/dist/app/index.js +4 -0
- package/dist/app/jimpex.d.mts +14 -0
- package/dist/app/jimpex.d.ts +3 -2
- package/dist/app/jimpex.js +225 -0
- package/dist/app/jimpex.js.map +1 -1
- package/dist/controllers/common/config.d.mts +79 -0
- package/dist/controllers/common/config.d.ts +3 -2
- package/dist/controllers/common/config.js +18 -0
- package/dist/controllers/common/config.js.map +1 -1
- package/dist/controllers/common/health.d.mts +83 -0
- package/dist/controllers/common/health.d.ts +4 -3
- package/dist/controllers/common/health.js +18 -0
- package/dist/controllers/common/health.js.map +1 -1
- package/dist/controllers/common/index.d.mts +21 -0
- package/dist/controllers/common/index.d.ts +4 -4
- package/dist/controllers/common/index.js +6 -0
- package/dist/controllers/common/statics.d.mts +215 -0
- package/dist/controllers/common/statics.d.ts +4 -4
- package/dist/controllers/common/statics.js +51 -0
- package/dist/controllers/common/statics.js.map +1 -1
- package/dist/controllers/index.d.mts +24 -0
- package/dist/controllers/index.d.ts +4 -4
- package/dist/controllers/index.js +5 -0
- package/dist/controllers/utils/gateway.d.mts +725 -0
- package/dist/controllers/utils/gateway.d.ts +4 -3
- package/dist/controllers/utils/gateway.js +152 -0
- package/dist/controllers/utils/gateway.js.map +1 -1
- package/dist/controllers/utils/index.d.mts +17 -0
- package/dist/controllers/utils/index.d.ts +4 -3
- package/dist/controllers/utils/index.js +4 -0
- package/dist/esm/app/jimpex.js +222 -1
- package/dist/esm/app/jimpex.js.map +1 -1
- package/dist/esm/{chunk-T2T6Q22Z.js → chunk-2B2CG5KL.js} +1 -1
- package/dist/esm/controllers/common/config.js +19 -1
- package/dist/esm/controllers/common/config.js.map +1 -1
- package/dist/esm/controllers/common/health.js +19 -1
- package/dist/esm/controllers/common/health.js.map +1 -1
- package/dist/esm/controllers/common/statics.js +48 -1
- package/dist/esm/controllers/common/statics.js.map +1 -1
- package/dist/esm/controllers/utils/gateway.js +153 -1
- package/dist/esm/controllers/utils/gateway.js.map +1 -1
- package/dist/esm/middlewares/common/errorHandler.js +25 -1
- package/dist/esm/middlewares/common/errorHandler.js.map +1 -1
- package/dist/esm/middlewares/common/forceHTTPS.js +13 -1
- package/dist/esm/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/esm/middlewares/common/hsts.js +22 -1
- package/dist/esm/middlewares/common/hsts.js.map +1 -1
- package/dist/esm/middlewares/html/fastHTML.js +55 -1
- package/dist/esm/middlewares/html/fastHTML.js.map +1 -1
- package/dist/esm/middlewares/html/showHTML.js +33 -1
- package/dist/esm/middlewares/html/showHTML.js.map +1 -1
- package/dist/esm/middlewares/utils/versionValidator.js +35 -1
- package/dist/esm/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/esm/services/common/appError.js +48 -2
- package/dist/esm/services/common/appError.js.map +1 -1
- package/dist/esm/services/common/httpError.js +10 -1
- package/dist/esm/services/common/httpError.js.map +1 -1
- package/dist/esm/services/common/index.js +1 -1
- package/dist/esm/services/common/sendFile.js +1 -1
- package/dist/esm/services/frontend/frontendFs.js +29 -1
- package/dist/esm/services/frontend/frontendFs.js.map +1 -1
- package/dist/esm/services/frontend/index.js +1 -1
- package/dist/esm/services/html/htmlGenerator.js +51 -1
- package/dist/esm/services/html/htmlGenerator.js.map +1 -1
- package/dist/esm/services/html/index.js +1 -1
- package/dist/esm/services/http/apiClient.js +27 -1
- package/dist/esm/services/http/apiClient.js.map +1 -1
- package/dist/esm/services/http/http.js +50 -1
- package/dist/esm/services/http/http.js.map +1 -1
- package/dist/esm/services/http/index.js +1 -1
- package/dist/esm/services/http/responsesBuilder.js +49 -2
- package/dist/esm/services/http/responsesBuilder.js.map +1 -1
- package/dist/esm/services/utils/ensureBearerToken.js +17 -1
- package/dist/esm/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/esm/services/utils/index.js +1 -1
- package/dist/esm/utils/fns/others.js +1 -1
- package/dist/esm/utils/fns/routes.js +1 -1
- package/dist/esm/utils/fns/routes.js.map +1 -1
- package/dist/esm/utils/fns/statuses.js +1 -1
- package/dist/esm/utils/fns/text.js +1 -1
- package/dist/esm/utils/wrappers.js +1 -1
- package/dist/{jimpex-7eaee271.d.ts → index-b2a04c78.d.ts} +9 -5
- package/dist/index-efeb437e.d.ts +1282 -0
- package/dist/index.d.mts +46 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +9 -0
- package/dist/middlewares/common/errorHandler.d.mts +132 -0
- package/dist/middlewares/common/errorHandler.d.ts +4 -3
- package/dist/middlewares/common/errorHandler.js +24 -0
- package/dist/middlewares/common/errorHandler.js.map +1 -1
- package/dist/middlewares/common/forceHTTPS.d.mts +69 -0
- package/dist/middlewares/common/forceHTTPS.d.ts +5 -4
- package/dist/middlewares/common/forceHTTPS.js +12 -0
- package/dist/middlewares/common/forceHTTPS.js.map +1 -1
- package/dist/middlewares/common/hsts.d.mts +110 -0
- package/dist/middlewares/common/hsts.d.ts +5 -4
- package/dist/middlewares/common/hsts.js +21 -0
- package/dist/middlewares/common/hsts.js.map +1 -1
- package/dist/middlewares/common/index.d.mts +22 -0
- package/dist/middlewares/common/index.d.ts +4 -3
- package/dist/middlewares/common/index.js +6 -0
- package/dist/middlewares/html/fastHTML.d.mts +180 -0
- package/dist/middlewares/html/fastHTML.d.ts +4 -4
- package/dist/middlewares/html/fastHTML.js +54 -0
- package/dist/middlewares/html/fastHTML.js.map +1 -1
- package/dist/middlewares/html/index.d.mts +21 -0
- package/dist/middlewares/html/index.d.ts +4 -4
- package/dist/middlewares/html/index.js +5 -0
- package/dist/middlewares/html/showHTML.d.mts +127 -0
- package/dist/middlewares/html/showHTML.d.ts +4 -4
- package/dist/middlewares/html/showHTML.js +32 -0
- package/dist/middlewares/html/showHTML.js.map +1 -1
- package/dist/middlewares/index.d.mts +30 -0
- package/dist/middlewares/index.d.ts +4 -4
- package/dist/middlewares/index.js +6 -0
- package/dist/middlewares/utils/index.d.mts +20 -0
- package/dist/middlewares/utils/index.d.ts +4 -3
- package/dist/middlewares/utils/index.js +4 -0
- package/dist/middlewares/utils/versionValidator.d.mts +215 -0
- package/dist/middlewares/utils/versionValidator.d.ts +4 -3
- package/dist/middlewares/utils/versionValidator.js +34 -0
- package/dist/middlewares/utils/versionValidator.js.map +1 -1
- package/dist/services/common/appError.d.mts +139 -0
- package/dist/services/common/appError.d.ts +4 -3
- package/dist/services/common/appError.js +47 -1
- package/dist/services/common/appError.js.map +1 -1
- package/dist/services/common/httpError.d.mts +80 -0
- package/dist/services/common/httpError.d.ts +4 -3
- package/dist/services/common/httpError.js +9 -0
- package/dist/services/common/httpError.js.map +1 -1
- package/dist/services/common/index.d.mts +47 -0
- package/dist/services/common/index.d.ts +4 -4
- package/dist/services/common/index.js +4 -1
- package/dist/services/common/sendFile.d.mts +102 -0
- package/dist/services/common/sendFile.d.ts +3 -3
- package/dist/services/frontend/frontendFs.d.mts +96 -0
- package/dist/services/frontend/frontendFs.d.ts +3 -3
- package/dist/services/frontend/frontendFs.js +32 -0
- package/dist/services/frontend/frontendFs.js.map +1 -1
- package/dist/services/frontend/index.d.mts +40 -0
- package/dist/services/frontend/index.d.ts +4 -4
- package/dist/services/frontend/index.js +2 -1
- package/dist/services/html/htmlGenerator.d.mts +237 -0
- package/dist/services/html/htmlGenerator.d.ts +2 -2
- package/dist/services/html/htmlGenerator.js +50 -0
- package/dist/services/html/htmlGenerator.js.map +1 -1
- package/dist/services/html/index.d.mts +43 -0
- package/dist/services/html/index.d.ts +4 -4
- package/dist/services/html/index.js +2 -1
- package/dist/services/http/apiClient.d.mts +170 -0
- package/dist/services/http/apiClient.d.ts +4 -3
- package/dist/services/http/apiClient.js +26 -0
- package/dist/services/http/apiClient.js.map +1 -1
- package/dist/services/http/http.d.mts +176 -0
- package/dist/services/http/http.d.ts +4 -3
- package/dist/services/http/http.js +53 -0
- package/dist/services/http/http.js.map +1 -1
- package/dist/services/http/index.d.mts +51 -0
- package/dist/services/http/index.d.ts +4 -3
- package/dist/services/http/index.js +4 -1
- package/dist/services/http/responsesBuilder.d.mts +179 -0
- package/dist/services/http/responsesBuilder.d.ts +3 -2
- package/dist/services/http/responsesBuilder.js +48 -1
- package/dist/services/http/responsesBuilder.js.map +1 -1
- package/dist/services/index.d.mts +33 -0
- package/dist/services/index.d.ts +4 -4
- package/dist/services/index.js +8 -0
- package/dist/services/utils/ensureBearerToken.d.mts +158 -0
- package/dist/services/utils/ensureBearerToken.d.ts +5 -4
- package/dist/services/utils/ensureBearerToken.js +16 -0
- package/dist/services/utils/ensureBearerToken.js.map +1 -1
- package/dist/services/utils/index.d.mts +44 -0
- package/dist/services/utils/index.d.ts +4 -3
- package/dist/services/utils/index.js +2 -1
- package/dist/types/events.d.mts +14 -0
- package/dist/types/events.d.ts +5 -4
- package/dist/types/express.d.mts +10 -0
- package/dist/types/http.d.mts +79 -0
- package/dist/types/index.d.mts +14 -0
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.js +9 -0
- package/dist/types/options.d.mts +14 -0
- package/dist/types/options.d.ts +4 -3
- package/dist/types/utils.d.mts +48 -0
- package/dist/types/wootils.d.mts +4 -0
- package/dist/utils/fns/index.d.mts +5 -0
- package/dist/utils/fns/index.js +7 -0
- package/dist/utils/fns/others.d.mts +17 -0
- package/dist/utils/fns/routes.d.mts +39 -0
- package/dist/utils/fns/routes.js.map +1 -1
- package/dist/utils/fns/statuses.d.mts +45 -0
- package/dist/utils/fns/statuses.js +4 -0
- package/dist/utils/fns/statuses.js.map +1 -1
- package/dist/utils/fns/text.d.mts +9 -0
- package/dist/utils/index.d.mts +19 -0
- package/dist/utils/index.d.ts +5 -4
- package/dist/utils/index.js +5 -0
- package/dist/utils/wrappers.d.mts +14 -0
- package/dist/utils/wrappers.d.ts +4 -3
- package/package.json +43 -43
- /package/dist/esm/{chunk-T2T6Q22Z.js.map → chunk-2B2CG5KL.js.map} +0 -0
|
@@ -0,0 +1,1282 @@
|
|
|
1
|
+
import { ExpressMiddlewareLike } from './types/express.mjs';
|
|
2
|
+
import { JimpexServer, JimpexServerInstance, JimpexHTTPSCredentials } from './types/http.mjs';
|
|
3
|
+
import { NoStringIndex, DeepPartial, DeepReadonly } from './types/utils.mjs';
|
|
4
|
+
import '@homer0/path-utils';
|
|
5
|
+
import { SimpleLogger } from '@homer0/simple-logger';
|
|
6
|
+
import { SimpleConfig } from '@homer0/simple-config';
|
|
7
|
+
import { EventsHub } from '@homer0/events-hub';
|
|
8
|
+
import { Router, Express } from 'express';
|
|
9
|
+
import 'node-fetch';
|
|
10
|
+
import 'https';
|
|
11
|
+
import 'http';
|
|
12
|
+
import * as _homer0_jimple from '@homer0/jimple';
|
|
13
|
+
import { ProviderRegisterFn as ProviderRegisterFn$1, GenericCurriedFn, Jimple } from '@homer0/jimple';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* The base payload the events emitted by the application send.
|
|
17
|
+
*
|
|
18
|
+
* @template T Extra properties beside the reference to the application.
|
|
19
|
+
* @group Services/Events
|
|
20
|
+
*/
|
|
21
|
+
type EventPayload<T = Record<string, unknown>> = {
|
|
22
|
+
/**
|
|
23
|
+
* A reference to the application.
|
|
24
|
+
*/
|
|
25
|
+
app: Jimpex;
|
|
26
|
+
} & T;
|
|
27
|
+
/**
|
|
28
|
+
* A dictionary with the events emitted by the application and their payloads.
|
|
29
|
+
*
|
|
30
|
+
* @group Services/Events
|
|
31
|
+
*/
|
|
32
|
+
interface JimpexEvents {
|
|
33
|
+
/**
|
|
34
|
+
* Called right before creating the server and calling `listen` on it.
|
|
35
|
+
*/
|
|
36
|
+
beforeStart: EventPayload;
|
|
37
|
+
/**
|
|
38
|
+
* Called once the server confirmed that is listening.
|
|
39
|
+
*/
|
|
40
|
+
start: EventPayload;
|
|
41
|
+
/**
|
|
42
|
+
* Called after the controllers and middlewares have been mounted.
|
|
43
|
+
*/
|
|
44
|
+
afterStart: EventPayload;
|
|
45
|
+
/**
|
|
46
|
+
* Called after the `onStart` callback has been called.
|
|
47
|
+
*/
|
|
48
|
+
afterStartCallback: EventPayload;
|
|
49
|
+
/**
|
|
50
|
+
* Called before closing the server instance.
|
|
51
|
+
*/
|
|
52
|
+
beforeStop: EventPayload;
|
|
53
|
+
/**
|
|
54
|
+
* Called after the server instance has been closed.
|
|
55
|
+
*/
|
|
56
|
+
afterStop: EventPayload;
|
|
57
|
+
/**
|
|
58
|
+
* Called every time a new route is mounted in the application.
|
|
59
|
+
*/
|
|
60
|
+
routeAdded: EventPayload<{
|
|
61
|
+
route: string;
|
|
62
|
+
}>;
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The events emitted by the application.
|
|
66
|
+
*
|
|
67
|
+
* @group Services/Events
|
|
68
|
+
*/
|
|
69
|
+
type JimpexEventName = keyof JimpexEvents;
|
|
70
|
+
/**
|
|
71
|
+
* The type of the payload sent by a specific event.
|
|
72
|
+
*
|
|
73
|
+
* @template EventName The literal type of the event, to obtain the type of the
|
|
74
|
+
* payload.
|
|
75
|
+
* @group Services/Events
|
|
76
|
+
*/
|
|
77
|
+
type JimpexEventPayload<EventName extends JimpexEventName> = JimpexEvents[EventName];
|
|
78
|
+
/**
|
|
79
|
+
* A dictionary of the reducer events and their targets.
|
|
80
|
+
*
|
|
81
|
+
* @group Services/Events
|
|
82
|
+
*/
|
|
83
|
+
interface JimpexReducerEventTargets {
|
|
84
|
+
/**
|
|
85
|
+
* It gets called before mounting a router/middleware for a specific route.
|
|
86
|
+
*/
|
|
87
|
+
controllerWillBeMounted: Router | ExpressMiddlewareLike;
|
|
88
|
+
/**
|
|
89
|
+
* It gets called before using a middleware without route.
|
|
90
|
+
*/
|
|
91
|
+
middlewareWillBeUsed: ExpressMiddlewareLike;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* A dictionary of the payloads the reducer events the application uses.
|
|
95
|
+
*
|
|
96
|
+
* @group Services/Events
|
|
97
|
+
*/
|
|
98
|
+
interface JimpexReducerEventPayloads {
|
|
99
|
+
/**
|
|
100
|
+
* It gets called before mounting a router/middleware for a specific route.
|
|
101
|
+
*/
|
|
102
|
+
controllerWillBeMounted: EventPayload<{
|
|
103
|
+
/**
|
|
104
|
+
* The route in which the controller will be mounted.
|
|
105
|
+
*/
|
|
106
|
+
route: string;
|
|
107
|
+
/**
|
|
108
|
+
* A reference for the controller/middleware before being "connected".
|
|
109
|
+
*/
|
|
110
|
+
controller: Controller | Middleware;
|
|
111
|
+
}>;
|
|
112
|
+
/**
|
|
113
|
+
* It gets called before using a middleware without route.
|
|
114
|
+
*/
|
|
115
|
+
middlewareWillBeUsed: EventPayload;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* The reducer events used by the application.
|
|
119
|
+
*
|
|
120
|
+
* @group Services/Events
|
|
121
|
+
*/
|
|
122
|
+
type JimpexReducerEventName = keyof JimpexReducerEventTargets;
|
|
123
|
+
/**
|
|
124
|
+
* The type of the target of a specific reducer event.
|
|
125
|
+
*
|
|
126
|
+
* @template EventName The literal type of the event, to obtain the type of the
|
|
127
|
+
* target.
|
|
128
|
+
* @group Services/Events
|
|
129
|
+
*/
|
|
130
|
+
type JimpexReducerEventTarget<EventName extends JimpexReducerEventName> = JimpexReducerEventTargets[EventName];
|
|
131
|
+
/**
|
|
132
|
+
* The type of the payload of a specific reducer event.
|
|
133
|
+
*
|
|
134
|
+
* @template EventName The literal type of the event, to obtain the type of the
|
|
135
|
+
* payload.
|
|
136
|
+
* @group Services/Events
|
|
137
|
+
*/
|
|
138
|
+
type JimpexReducerEventPayload<EventName extends JimpexReducerEventName> = JimpexReducerEventPayloads[EventName];
|
|
139
|
+
/**
|
|
140
|
+
* The name of the events o reducer events emitted/used by the application.
|
|
141
|
+
* This generic type exists because the listener for both types are added using the same
|
|
142
|
+
* method.
|
|
143
|
+
*
|
|
144
|
+
* @group Services/Events
|
|
145
|
+
*/
|
|
146
|
+
type JimpexEventNameLike = JimpexEventName | JimpexReducerEventName;
|
|
147
|
+
/**
|
|
148
|
+
* The definition of a listener for an event or a reducer event.
|
|
149
|
+
*
|
|
150
|
+
* @template EventName The literal type of the event, to validate whether the
|
|
151
|
+
* parameters should be for a reducer event or an event.
|
|
152
|
+
* @group Services/Events
|
|
153
|
+
*/
|
|
154
|
+
type JimpexEventListener<EventName extends JimpexEventNameLike> = EventName extends JimpexEventName ? (payload: JimpexEventPayload<EventName>) => void : EventName extends JimpexReducerEventName ? (target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>) => JimpexReducerEventTarget<EventName> : never;
|
|
155
|
+
/**
|
|
156
|
+
* The `events` service Jimpex uses.
|
|
157
|
+
* This is an alternative declaration of the `EventsHub` class that uses the interfaces
|
|
158
|
+
* and types from this project.
|
|
159
|
+
*
|
|
160
|
+
* @group Services
|
|
161
|
+
* @group Services/Events
|
|
162
|
+
*/
|
|
163
|
+
type Events = {
|
|
164
|
+
/**
|
|
165
|
+
* Adds a new event listener.
|
|
166
|
+
*
|
|
167
|
+
* @param event The name of the event.
|
|
168
|
+
* @param listener The listener function.
|
|
169
|
+
* @returns An unsubscribe function to remove the listener.
|
|
170
|
+
* @template EventName The literal type of the event, to generate the type of the
|
|
171
|
+
* listener.
|
|
172
|
+
* @example
|
|
173
|
+
*
|
|
174
|
+
* const unsubscribe = events.on('afterStart', ({ app }) => {
|
|
175
|
+
* app.getLogger().info('Hello world!');
|
|
176
|
+
* unsubscribe();
|
|
177
|
+
* });
|
|
178
|
+
*
|
|
179
|
+
*/
|
|
180
|
+
on: <EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>) => () => boolean;
|
|
181
|
+
/**
|
|
182
|
+
* Adds an event listener that will only be executed once.
|
|
183
|
+
*
|
|
184
|
+
* @param event The name of the event.
|
|
185
|
+
* @param listener The listener function.
|
|
186
|
+
* @returns An unsubscribe function to remove the listener.
|
|
187
|
+
* @template EventName The literal type of the event, to generate the type of the
|
|
188
|
+
* listener.
|
|
189
|
+
* @example
|
|
190
|
+
*
|
|
191
|
+
* events.once('afterStart', ({ app }) => {
|
|
192
|
+
* app.getLogger().info('Hello world!');
|
|
193
|
+
* unsubscribe();
|
|
194
|
+
* });
|
|
195
|
+
*
|
|
196
|
+
*/
|
|
197
|
+
once: <EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>) => () => boolean;
|
|
198
|
+
/**
|
|
199
|
+
* Emits an event and call all its listeners.
|
|
200
|
+
*
|
|
201
|
+
* @param event The name of the events.
|
|
202
|
+
* @param payload Context information for the event.
|
|
203
|
+
* @template EventName The literal type of the event, to generate the type of the
|
|
204
|
+
* payload.
|
|
205
|
+
* @example
|
|
206
|
+
*
|
|
207
|
+
* // Extend the interface to type the payload.
|
|
208
|
+
* interface JimpexEvents {
|
|
209
|
+
* myEvent: { message: string };
|
|
210
|
+
* }
|
|
211
|
+
* // Add the listener.
|
|
212
|
+
* events.on('myEvent', ({ message }) => {
|
|
213
|
+
* console.log('Event received:', message);
|
|
214
|
+
* });
|
|
215
|
+
* // Trigger the event.
|
|
216
|
+
* events.emit('myEvent', { message: 'Hello' });
|
|
217
|
+
* // prints "Event received: Hello"
|
|
218
|
+
*
|
|
219
|
+
*/
|
|
220
|
+
emit: <EventName extends JimpexEventName>(event: JimpexEventName, payload: JimpexEventPayload<EventName>) => void;
|
|
221
|
+
/**
|
|
222
|
+
* Asynchronously reduces a target using an event. It's like emit, but the event
|
|
223
|
+
* listeners return a modified (or not) version of the `target`.
|
|
224
|
+
*
|
|
225
|
+
* @param event The name of the event.
|
|
226
|
+
* @param target The variable to reduce with the reducers/listeners.
|
|
227
|
+
* @param payload Context information for the event.
|
|
228
|
+
* @returns A version of the `target` processed by the listeners.
|
|
229
|
+
* @template EventName The literal type of the event, to generate the types of the
|
|
230
|
+
* target and the payload.
|
|
231
|
+
* @example
|
|
232
|
+
*
|
|
233
|
+
* // Extend the interface to type the target.
|
|
234
|
+
* interface JimpexReducerEventTargets {
|
|
235
|
+
* myReducer: unknown[];
|
|
236
|
+
* }
|
|
237
|
+
* // Extend the interface to type the payload.
|
|
238
|
+
* interface JimpexReducerEventPayloads {
|
|
239
|
+
* myReducer: {
|
|
240
|
+
* message: string;
|
|
241
|
+
* };
|
|
242
|
+
* }
|
|
243
|
+
* // Add the reducer.
|
|
244
|
+
* events.on('myReducer', async (target, { message }) => {
|
|
245
|
+
* const data = await fetch('https://api.example.com/' + message);
|
|
246
|
+
* target.push(data);
|
|
247
|
+
* return target;
|
|
248
|
+
* });
|
|
249
|
+
* // Trigger the event.
|
|
250
|
+
* const result = await events.reduce('myReducer', [], { message: 'Hello' });
|
|
251
|
+
* // result would be a list of data fetched from the API.
|
|
252
|
+
*
|
|
253
|
+
*/
|
|
254
|
+
reduce: <EventName extends JimpexReducerEventName>(event: JimpexReducerEventName, target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>) => Promise<JimpexReducerEventTarget<EventName>>;
|
|
255
|
+
/**
|
|
256
|
+
* Synchronously reduces a target using an event. It's like emit, but the events
|
|
257
|
+
* listener return a modified (or not) version of the `target`.
|
|
258
|
+
*
|
|
259
|
+
* @param event The name of the event.
|
|
260
|
+
* @param target The variable to reduce with the reducers/listeners.
|
|
261
|
+
* @param payload Context information for the event.
|
|
262
|
+
* @returns A version of the `target` processed by the listeners.
|
|
263
|
+
* @template EventName The literal type of the event, to generate the types of the
|
|
264
|
+
* target and the payload.
|
|
265
|
+
* @example
|
|
266
|
+
*
|
|
267
|
+
* // Extend the interface to type the target.
|
|
268
|
+
* interface JimpexReducerEventTargets {
|
|
269
|
+
* myReducer: string[];
|
|
270
|
+
* }
|
|
271
|
+
* // Extend the interface to type the payload.
|
|
272
|
+
* interface JimpexReducerEventPayloads {
|
|
273
|
+
* myReducer: {
|
|
274
|
+
* message: string;
|
|
275
|
+
* };
|
|
276
|
+
* }
|
|
277
|
+
* // Add the reducer.
|
|
278
|
+
* events.on('myReducer', (target, { message }) => {
|
|
279
|
+
* target.push(message);
|
|
280
|
+
* return target;
|
|
281
|
+
* });
|
|
282
|
+
* // Trigger the event.
|
|
283
|
+
* events.reduce('event', [], 'Hello');
|
|
284
|
+
* // returns ['Hello']
|
|
285
|
+
*
|
|
286
|
+
*/
|
|
287
|
+
reduceSync: <EventName extends JimpexReducerEventName>(event: JimpexReducerEventName, target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>) => JimpexReducerEventTarget<EventName>;
|
|
288
|
+
};
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* The options for the application's configuration service.
|
|
292
|
+
*
|
|
293
|
+
* @see {@link https://www.npmjs.com/package/@homer0/simple-config}
|
|
294
|
+
* @group Jimpex
|
|
295
|
+
*/
|
|
296
|
+
type JimpexConfigOptions = {
|
|
297
|
+
/**
|
|
298
|
+
* The default settings for the configuration. If no external configuration is used,
|
|
299
|
+
* this needs to include a `port` property.
|
|
300
|
+
*/
|
|
301
|
+
default: unknown;
|
|
302
|
+
/**
|
|
303
|
+
* The name of the application, used for external configuration files.
|
|
304
|
+
*
|
|
305
|
+
* @default 'app'
|
|
306
|
+
*/
|
|
307
|
+
name: string;
|
|
308
|
+
/**
|
|
309
|
+
* The path to where external configuration files are stored. Relative to the project
|
|
310
|
+
* root.
|
|
311
|
+
*
|
|
312
|
+
* @default 'config/'
|
|
313
|
+
*/
|
|
314
|
+
path: string;
|
|
315
|
+
/**
|
|
316
|
+
* Whether the configuration files are inside a sub directory or not. If `true`, a
|
|
317
|
+
* configuration path would be `config/[app-name]/[file]`.
|
|
318
|
+
*
|
|
319
|
+
* @default false
|
|
320
|
+
*/
|
|
321
|
+
hasFolder: boolean;
|
|
322
|
+
/**
|
|
323
|
+
* Whether or not to check for the environment variable and load a configuration file
|
|
324
|
+
* based on its value.
|
|
325
|
+
*
|
|
326
|
+
* @default true
|
|
327
|
+
*/
|
|
328
|
+
loadFromEnvironment: boolean;
|
|
329
|
+
/**
|
|
330
|
+
* The name of the environment variable that will be used to set the active
|
|
331
|
+
* configuration.
|
|
332
|
+
*
|
|
333
|
+
* @default 'CONFIG'
|
|
334
|
+
*/
|
|
335
|
+
environmentVariable: string;
|
|
336
|
+
/**
|
|
337
|
+
* The name of the default configuration file.
|
|
338
|
+
*
|
|
339
|
+
* @default '[app-name].config.js'
|
|
340
|
+
*/
|
|
341
|
+
defaultConfigFilename: string;
|
|
342
|
+
/**
|
|
343
|
+
* The name format of other external configuration files.
|
|
344
|
+
*
|
|
345
|
+
* @default '[app-name].[config-name].config.js'
|
|
346
|
+
*/
|
|
347
|
+
filenameFormat: string;
|
|
348
|
+
};
|
|
349
|
+
/**
|
|
350
|
+
* The options for the middleware that serves static files.
|
|
351
|
+
*
|
|
352
|
+
* @group Jimpex
|
|
353
|
+
*/
|
|
354
|
+
type JimpexStaticsOptions = {
|
|
355
|
+
/**
|
|
356
|
+
* Whether or not to enable the middleware.
|
|
357
|
+
*
|
|
358
|
+
* @default true
|
|
359
|
+
*/
|
|
360
|
+
enabled: boolean;
|
|
361
|
+
/**
|
|
362
|
+
* If `true`, the path to the statics folder will be relative to the project root
|
|
363
|
+
* directory, otherwise, it will be relative to the directory where the app executable
|
|
364
|
+
* file is located.
|
|
365
|
+
*
|
|
366
|
+
* @default false
|
|
367
|
+
*/
|
|
368
|
+
onHome: boolean;
|
|
369
|
+
/**
|
|
370
|
+
* The name of both the route and the folder, relative to whatever you defined with the
|
|
371
|
+
* `onHome` option.
|
|
372
|
+
*
|
|
373
|
+
* @default 'statics'
|
|
374
|
+
*/
|
|
375
|
+
route: string;
|
|
376
|
+
/**
|
|
377
|
+
* By default, the folder will be the same as the `route`,
|
|
378
|
+
* but you can use this option to define a relative path that won't affect the route.
|
|
379
|
+
*
|
|
380
|
+
* @default ''
|
|
381
|
+
*/
|
|
382
|
+
folder?: string;
|
|
383
|
+
};
|
|
384
|
+
/**
|
|
385
|
+
* The options for the Express application.
|
|
386
|
+
*
|
|
387
|
+
* @group Jimpex
|
|
388
|
+
*/
|
|
389
|
+
type JimpexExpressOptions = {
|
|
390
|
+
/**
|
|
391
|
+
* Whether or not to enable the `trust proxy` option.
|
|
392
|
+
*
|
|
393
|
+
* @default true
|
|
394
|
+
*/
|
|
395
|
+
trustProxy: boolean;
|
|
396
|
+
/**
|
|
397
|
+
* Whether or not to remove the `x-powered-by` header.
|
|
398
|
+
*
|
|
399
|
+
* @default true
|
|
400
|
+
*/
|
|
401
|
+
disableXPoweredBy: boolean;
|
|
402
|
+
/**
|
|
403
|
+
* Whether or not to add the `compression` middleware.
|
|
404
|
+
*
|
|
405
|
+
* @default true
|
|
406
|
+
*/
|
|
407
|
+
compression: boolean;
|
|
408
|
+
/**
|
|
409
|
+
* Whether or not to add the `body-parser` middleware.
|
|
410
|
+
*
|
|
411
|
+
* @default true
|
|
412
|
+
*/
|
|
413
|
+
bodyParser: boolean;
|
|
414
|
+
/**
|
|
415
|
+
* Whether or not to add the `multer` middleware.
|
|
416
|
+
*
|
|
417
|
+
* @see {@link https://www.npmjs.com/package/multer}
|
|
418
|
+
*/
|
|
419
|
+
multer: boolean;
|
|
420
|
+
};
|
|
421
|
+
/**
|
|
422
|
+
* The options to configure the application executable path.
|
|
423
|
+
*
|
|
424
|
+
* @group Jimpex
|
|
425
|
+
*/
|
|
426
|
+
type JimpexPathOptions = {
|
|
427
|
+
/**
|
|
428
|
+
* A "hardcoded" path to the application executable file.
|
|
429
|
+
*
|
|
430
|
+
* @default ''
|
|
431
|
+
*/
|
|
432
|
+
appPath?: string;
|
|
433
|
+
/**
|
|
434
|
+
* If `true`, it will try to figure out the parent file path, and use its directory as
|
|
435
|
+
* the path.
|
|
436
|
+
*
|
|
437
|
+
* @default true
|
|
438
|
+
*/
|
|
439
|
+
useParentPath: boolean;
|
|
440
|
+
};
|
|
441
|
+
/**
|
|
442
|
+
* The options to enable some of the default services Jimpex comes with.
|
|
443
|
+
*
|
|
444
|
+
* @group Jimpex
|
|
445
|
+
*/
|
|
446
|
+
type JimpexServicesOptions = {
|
|
447
|
+
/**
|
|
448
|
+
* Whether or not to register all the `common` services: `appError`, `httpError`, and
|
|
449
|
+
* `sendFile`.
|
|
450
|
+
*
|
|
451
|
+
* @default true
|
|
452
|
+
*/
|
|
453
|
+
common: boolean;
|
|
454
|
+
/**
|
|
455
|
+
* Whether or not to register the `http` services: `apiClient`, `http`, and
|
|
456
|
+
* `responsesBuilder`.
|
|
457
|
+
*
|
|
458
|
+
* @default true
|
|
459
|
+
*/
|
|
460
|
+
http: boolean;
|
|
461
|
+
/**
|
|
462
|
+
* Whether or not to register the `utils` services: `ensureBearerToken`.
|
|
463
|
+
*/
|
|
464
|
+
utils: boolean;
|
|
465
|
+
};
|
|
466
|
+
/**
|
|
467
|
+
* The format in which the application's health status can be returned.
|
|
468
|
+
* It's either a simple boolean, or a more detailed object.
|
|
469
|
+
*
|
|
470
|
+
* @group Jimpex
|
|
471
|
+
*/
|
|
472
|
+
type JimpexHealthStatus = boolean | {
|
|
473
|
+
isHealthy?: boolean;
|
|
474
|
+
services?: Record<string, boolean>;
|
|
475
|
+
};
|
|
476
|
+
/**
|
|
477
|
+
* Returns the application health status. This is normally used by the `healthController`.
|
|
478
|
+
*
|
|
479
|
+
* @group Jimpex
|
|
480
|
+
*/
|
|
481
|
+
type JimpexHealthCheckFn = (app: Jimpex) => Promise<JimpexHealthStatus>;
|
|
482
|
+
/**
|
|
483
|
+
* The options to create a new instance of Jimpex.
|
|
484
|
+
*
|
|
485
|
+
* @group Jimpex
|
|
486
|
+
*/
|
|
487
|
+
type JimpexOptions = {
|
|
488
|
+
/**
|
|
489
|
+
* The size limit for the requests payload.
|
|
490
|
+
*
|
|
491
|
+
* @default '15MB'
|
|
492
|
+
*/
|
|
493
|
+
filesizeLimit: string;
|
|
494
|
+
/**
|
|
495
|
+
* Whether or not to call the `boot` method after initialization. This is useful if you
|
|
496
|
+
* want to register/overwrite services only on certain contexts, like a dev environment.
|
|
497
|
+
*
|
|
498
|
+
* @default true
|
|
499
|
+
*/
|
|
500
|
+
boot: boolean;
|
|
501
|
+
/**
|
|
502
|
+
* The options to configure the application executable path.
|
|
503
|
+
*/
|
|
504
|
+
path: JimpexPathOptions;
|
|
505
|
+
/**
|
|
506
|
+
* Options for the configuration service.
|
|
507
|
+
*
|
|
508
|
+
* @see {@link https://www.npmjs.com/package/@homer0/simple-config}
|
|
509
|
+
*/
|
|
510
|
+
config: JimpexConfigOptions;
|
|
511
|
+
/**
|
|
512
|
+
* Options for the middleware that serves static files.
|
|
513
|
+
*/
|
|
514
|
+
statics: JimpexStaticsOptions;
|
|
515
|
+
/**
|
|
516
|
+
* Options for the Express application.
|
|
517
|
+
*/
|
|
518
|
+
express: JimpexExpressOptions;
|
|
519
|
+
/**
|
|
520
|
+
* Options to manage the default services.
|
|
521
|
+
*/
|
|
522
|
+
services: JimpexServicesOptions;
|
|
523
|
+
/**
|
|
524
|
+
* A function that will be used to check the application health status.
|
|
525
|
+
*/
|
|
526
|
+
healthCheck: JimpexHealthCheckFn;
|
|
527
|
+
};
|
|
528
|
+
/**
|
|
529
|
+
* The function called when the application starts listening for requests.
|
|
530
|
+
*
|
|
531
|
+
* @group Jimpex
|
|
532
|
+
*/
|
|
533
|
+
type JimpexStartCallback = (config: SimpleConfig) => void;
|
|
534
|
+
|
|
535
|
+
/**
|
|
536
|
+
* The function a provider uses to configure a resource in the container.
|
|
537
|
+
*
|
|
538
|
+
* @group Wrappers
|
|
539
|
+
*/
|
|
540
|
+
type ProviderRegisterFn = ProviderRegisterFn$1<Jimpex>;
|
|
541
|
+
/**
|
|
542
|
+
* Creates an object that can configure/extend the container by registering services and
|
|
543
|
+
* resources.
|
|
544
|
+
*
|
|
545
|
+
* @example
|
|
546
|
+
*
|
|
547
|
+
* class APIClient {}
|
|
548
|
+
* const apiClientProvider = provider((app) => {
|
|
549
|
+
* app.set('apiClient', () => new APIClient());
|
|
550
|
+
* });
|
|
551
|
+
*
|
|
552
|
+
* @group Wrappers
|
|
553
|
+
*/
|
|
554
|
+
declare const provider: (register: ProviderRegisterFn$1<Jimpex>) => _homer0_jimple.Resource<"provider", "register", ProviderRegisterFn$1<Jimpex>>;
|
|
555
|
+
/**
|
|
556
|
+
* Creates an object like a provider, but that it can also be used as a function, as it
|
|
557
|
+
* normally expose options for the resources it will configure.
|
|
558
|
+
*
|
|
559
|
+
* @example
|
|
560
|
+
*
|
|
561
|
+
* <caption>Registering as a common provider</caption>
|
|
562
|
+
*
|
|
563
|
+
* const apiClientProvider = providerCreator(
|
|
564
|
+
* ({ serviceName = 'apiClient' }) =>
|
|
565
|
+
* (app) => {
|
|
566
|
+
* app.set(serviceName, () => new APIClient());
|
|
567
|
+
* },
|
|
568
|
+
* );
|
|
569
|
+
*
|
|
570
|
+
* container.register(apiClientProvider);
|
|
571
|
+
*
|
|
572
|
+
* @example
|
|
573
|
+
*
|
|
574
|
+
* <caption>Registering a created provider</caption>
|
|
575
|
+
*
|
|
576
|
+
* container.register(
|
|
577
|
+
* apiClientProvider({
|
|
578
|
+
* serviceName: 'myApiClient',
|
|
579
|
+
* }),
|
|
580
|
+
* );
|
|
581
|
+
*
|
|
582
|
+
* @group Wrappers
|
|
583
|
+
*/
|
|
584
|
+
declare const providerCreator: <CreatorFn extends GenericCurriedFn<ProviderRegisterFn$1<Jimpex>>>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"provider", "register", CreatorFn, ProviderRegisterFn$1<Jimpex>>;
|
|
585
|
+
/**
|
|
586
|
+
* Creates a collection of providers that can be registered one by one, or all at once.
|
|
587
|
+
*
|
|
588
|
+
* @example
|
|
589
|
+
*
|
|
590
|
+
* <caption>Registering all the providers at once</caption>
|
|
591
|
+
*
|
|
592
|
+
* const collection = providers({
|
|
593
|
+
* apiClient: apiClientProvider,
|
|
594
|
+
* http: httpProvider,
|
|
595
|
+
* });
|
|
596
|
+
*
|
|
597
|
+
* container.register(collection);
|
|
598
|
+
*
|
|
599
|
+
* @example
|
|
600
|
+
*
|
|
601
|
+
* <caption>Registering one by one</caption>
|
|
602
|
+
*
|
|
603
|
+
* container.register(collection.http);
|
|
604
|
+
*
|
|
605
|
+
* @group Wrappers
|
|
606
|
+
*/
|
|
607
|
+
declare const providers: <ItemsParam>(items: ItemsParam & Record<string, _homer0_jimple.Resource<"provider", "register", ProviderRegisterFn$1<Jimpex>>>) => ItemsParam & Record<string, _homer0_jimple.Resource<"provider", "register", ProviderRegisterFn$1<Jimpex>>> & {
|
|
608
|
+
provider: true;
|
|
609
|
+
} & {
|
|
610
|
+
register: ProviderRegisterFn$1<Jimpex>;
|
|
611
|
+
} & Record<string, unknown>;
|
|
612
|
+
/**
|
|
613
|
+
* An object that can configure/extend the container by registering services and
|
|
614
|
+
* resources.
|
|
615
|
+
*
|
|
616
|
+
* @group Wrappers
|
|
617
|
+
*/
|
|
618
|
+
type Provider = ReturnType<typeof provider>;
|
|
619
|
+
/**
|
|
620
|
+
* A provider creator is like a provider, but it can also be used as a function, and it
|
|
621
|
+
* expose options for the resources it will configure.
|
|
622
|
+
*
|
|
623
|
+
* @group Wrappers
|
|
624
|
+
*/
|
|
625
|
+
type ProviderCreator = ReturnType<typeof providerCreator>;
|
|
626
|
+
/**
|
|
627
|
+
* A collection of providers that can be registered one by one, or all at once.
|
|
628
|
+
*
|
|
629
|
+
* @group Wrappers
|
|
630
|
+
*/
|
|
631
|
+
type Providers = ReturnType<typeof providers>;
|
|
632
|
+
/**
|
|
633
|
+
* A union of all types that can be registered in the provider with a `register` function.
|
|
634
|
+
*
|
|
635
|
+
* @group Wrappers
|
|
636
|
+
*/
|
|
637
|
+
type ProviderLike = Provider | ProviderCreator | Providers;
|
|
638
|
+
/**
|
|
639
|
+
* The function a controller uses to mount a controller/middleware in the container.
|
|
640
|
+
*
|
|
641
|
+
* @param container The reference to the Jimpex container.
|
|
642
|
+
* @param route The route on which the controller will be mounted on.
|
|
643
|
+
* @group Wrappers
|
|
644
|
+
*/
|
|
645
|
+
type ControllerConnectFn = <ContainerType extends Jimpex = Jimpex>(container: ContainerType, route: string) => Router | ExpressMiddlewareLike;
|
|
646
|
+
/**
|
|
647
|
+
* Generates a routes controller for the application container to mount.
|
|
648
|
+
*
|
|
649
|
+
* @param connect A function that will be called the moment the application mounts the
|
|
650
|
+
* controller, and that is in charge of registering routes and
|
|
651
|
+
* middlewares.
|
|
652
|
+
* @example
|
|
653
|
+
*
|
|
654
|
+
* const myController = controller((app) => {
|
|
655
|
+
* const router = app.getRouter();
|
|
656
|
+
* const ctrl = new MyController();
|
|
657
|
+
* return router.get('...', ctrl.doSomething()).post('...', ctrl.doSomethingElse());
|
|
658
|
+
* });
|
|
659
|
+
*
|
|
660
|
+
* // ...
|
|
661
|
+
* container.mount('/charo', myController);
|
|
662
|
+
*
|
|
663
|
+
* @group Wrappers
|
|
664
|
+
*/
|
|
665
|
+
declare const controller: (connect: ControllerConnectFn) => _homer0_jimple.Resource<"controller", "connect", ControllerConnectFn>;
|
|
666
|
+
/**
|
|
667
|
+
* A high order function that generates a controller. It's used on the definitions of a
|
|
668
|
+
* controller creator.
|
|
669
|
+
*
|
|
670
|
+
* @group Wrappers
|
|
671
|
+
*/
|
|
672
|
+
type ControllerCreatorFn = GenericCurriedFn<ControllerConnectFn>;
|
|
673
|
+
/**
|
|
674
|
+
* Generates a configurable routes controller for the application to mount. It's
|
|
675
|
+
* configurable because the `creator`, instead of just being sent to the container to
|
|
676
|
+
* mount, it can also be called as a function with custom parameters the controller can
|
|
677
|
+
* receive.
|
|
678
|
+
*
|
|
679
|
+
* @param creator A function that will generate a controller.
|
|
680
|
+
* @example
|
|
681
|
+
*
|
|
682
|
+
* <caption>Basic usage</caption>
|
|
683
|
+
*
|
|
684
|
+
* const myController = controllerCreator((options = {}) => (app) => {
|
|
685
|
+
* const router = app.getRouter();
|
|
686
|
+
* const ctrl = new MyController(options);
|
|
687
|
+
* return router.get('...', ctrl.doSomething()).post('...', ctrl.doSomethingElse());
|
|
688
|
+
* });
|
|
689
|
+
*
|
|
690
|
+
* // ...
|
|
691
|
+
* container.mount('/charo', myController);
|
|
692
|
+
*
|
|
693
|
+
* @example
|
|
694
|
+
*
|
|
695
|
+
* <caption>Custom parameters</caption>
|
|
696
|
+
*
|
|
697
|
+
* container.mount('/pili', myController({ foo: 'bar' }));
|
|
698
|
+
*
|
|
699
|
+
* @group Wrappers
|
|
700
|
+
*/
|
|
701
|
+
declare const controllerCreator: <CreatorFn extends ControllerCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"controller", "connect", CreatorFn, ControllerConnectFn>;
|
|
702
|
+
/**
|
|
703
|
+
* A resource that will define middlewares for specific routes.
|
|
704
|
+
*
|
|
705
|
+
* @group Wrappers
|
|
706
|
+
*/
|
|
707
|
+
type Controller = ReturnType<typeof controller>;
|
|
708
|
+
/**
|
|
709
|
+
* A controller creator is like a controller, but it can also be used as a function, and
|
|
710
|
+
* it can receive custom parameters to configure its behavior.
|
|
711
|
+
*
|
|
712
|
+
* @group Wrappers
|
|
713
|
+
*/
|
|
714
|
+
type ControllerCreator = ReturnType<typeof controllerCreator>;
|
|
715
|
+
/**
|
|
716
|
+
* The function a controller provider uses to configure/extend the container before
|
|
717
|
+
* returning an actual controller.
|
|
718
|
+
*
|
|
719
|
+
* @param container The reference to the Jimpex container.
|
|
720
|
+
* @param route The route on which the controller will be mounted on.
|
|
721
|
+
* @group Wrappers
|
|
722
|
+
*/
|
|
723
|
+
type ControllerProviderRegisterFn = <ContainerType extends Jimpex = Jimpex>(container: ContainerType, route: string) => Controller;
|
|
724
|
+
/**
|
|
725
|
+
* Creates a "controller provider", which is a controller that can configure/extend the
|
|
726
|
+
* container before the application mounts it.
|
|
727
|
+
*
|
|
728
|
+
* @param register A function that will be called the moment the application mounts
|
|
729
|
+
* the controller provider.
|
|
730
|
+
* @example
|
|
731
|
+
*
|
|
732
|
+
* class MyController {}
|
|
733
|
+
* const myControllerProvider = controllerProvider((app) => {
|
|
734
|
+
* app.set('myController', () => new MyController());
|
|
735
|
+
* return controller(() => {
|
|
736
|
+
* const ctrl = app.get<MyController>('myController');
|
|
737
|
+
* const router = app.getRouter();
|
|
738
|
+
* return router.get('/', ctrl.doSomething());
|
|
739
|
+
* });
|
|
740
|
+
* });
|
|
741
|
+
*
|
|
742
|
+
* @group Wrappers
|
|
743
|
+
*/
|
|
744
|
+
declare const controllerProvider: (register: ControllerProviderRegisterFn) => _homer0_jimple.Resource<"provider", "register", ControllerProviderRegisterFn>;
|
|
745
|
+
/**
|
|
746
|
+
* A high order function that generates a controller provider. It's used on the
|
|
747
|
+
* definitions of a controller provider creator.
|
|
748
|
+
*
|
|
749
|
+
* @group Wrappers
|
|
750
|
+
*/
|
|
751
|
+
type ControllerProviderCreatorFn = GenericCurriedFn<ControllerProviderRegisterFn>;
|
|
752
|
+
/**
|
|
753
|
+
* Generates a configurable controller provider for the application to mount. This is a
|
|
754
|
+
* mix of a controller creator and a controller provider: it gives you the flexibility of
|
|
755
|
+
* the creator, with the resources of the provider.
|
|
756
|
+
*
|
|
757
|
+
* @param creator A function that will generate a controller provider.
|
|
758
|
+
* @example
|
|
759
|
+
*
|
|
760
|
+
* <caption>Basic usage</caption>
|
|
761
|
+
*
|
|
762
|
+
* class MyController {}
|
|
763
|
+
* const myControllerProvider = controllerProviderCreator(
|
|
764
|
+
* ({ serviceName = 'myController' }) =>
|
|
765
|
+
* (app) => {
|
|
766
|
+
* app.set(serviceName, () => new MyController());
|
|
767
|
+
* return controller(() => {
|
|
768
|
+
* const ctrl = app.get<MyController>(serviceName);
|
|
769
|
+
* const router = app.getRouter();
|
|
770
|
+
* return router.get('/', ctrl.doSomething());
|
|
771
|
+
* });
|
|
772
|
+
* },
|
|
773
|
+
* );
|
|
774
|
+
*
|
|
775
|
+
* // ...
|
|
776
|
+
* container.mount('/charo', myControllerProvider);
|
|
777
|
+
*
|
|
778
|
+
* @example
|
|
779
|
+
*
|
|
780
|
+
* <caption>Custom parameters</caption>
|
|
781
|
+
*
|
|
782
|
+
* container.mount('/pili', myControllerProvider({ serviceName: 'something' }));
|
|
783
|
+
*
|
|
784
|
+
* @group Wrappers
|
|
785
|
+
*/
|
|
786
|
+
declare const controllerProviderCreator: <CreatorFn extends ControllerProviderCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"provider", "register", CreatorFn, ControllerProviderRegisterFn>;
|
|
787
|
+
/**
|
|
788
|
+
* A special kind of controller that can be used to configure/extend the container before
|
|
789
|
+
* returning an actual controller.
|
|
790
|
+
*
|
|
791
|
+
* @group Wrappers
|
|
792
|
+
*/
|
|
793
|
+
type ControllerProvider = ReturnType<typeof controllerProvider>;
|
|
794
|
+
/**
|
|
795
|
+
* A "creator version" of a controller provider: a controller that can be used to
|
|
796
|
+
* configure/extend the container before returning an actual controller, but that can also
|
|
797
|
+
* be called as a function, and it can receive custom parameters to configure its
|
|
798
|
+
* behavior.
|
|
799
|
+
*
|
|
800
|
+
* @group Wrappers
|
|
801
|
+
*/
|
|
802
|
+
type ControllerProviderCreator = ReturnType<typeof controllerProviderCreator>;
|
|
803
|
+
/**
|
|
804
|
+
* The function a middleware uses to mount itself in the container.
|
|
805
|
+
*
|
|
806
|
+
* @param container The reference to the Jimpex container.
|
|
807
|
+
* @param route This is optional because the implementation can use it as a
|
|
808
|
+
* "global widdleware", or for a specific route.
|
|
809
|
+
* @returns The resource can choose to be enabled or not by returning the function, or
|
|
810
|
+
* `undefined`.
|
|
811
|
+
* @group Wrappers
|
|
812
|
+
*/
|
|
813
|
+
type MiddlewareConnectFn = <ContainerType extends Jimpex = Jimpex>(app: ContainerType, route?: string) => Router | ExpressMiddlewareLike | undefined;
|
|
814
|
+
/**
|
|
815
|
+
* Generates a middleware for the application container to mount.
|
|
816
|
+
*
|
|
817
|
+
* @param connect A function that will be called the moment the application tries to
|
|
818
|
+
* mount the middleware.
|
|
819
|
+
* @example
|
|
820
|
+
*
|
|
821
|
+
* <caption>Basic usage</caption>
|
|
822
|
+
*
|
|
823
|
+
* const myMiddleware = controller((app) => {
|
|
824
|
+
* const responsesBuilder = app.get<ResponsesBuilder>('responsesBuilder');
|
|
825
|
+
* return (_, res) => {
|
|
826
|
+
* responsesBuilder.json({ res, data: { hello: 'world' } });
|
|
827
|
+
* };
|
|
828
|
+
* });
|
|
829
|
+
*
|
|
830
|
+
* // ...
|
|
831
|
+
* container.use(myMiddleware);
|
|
832
|
+
*
|
|
833
|
+
* @example
|
|
834
|
+
*
|
|
835
|
+
* <caption>On a specific route</caption>
|
|
836
|
+
*
|
|
837
|
+
* container.mount('/charo', myMiddleware);
|
|
838
|
+
*
|
|
839
|
+
* @group Wrappers
|
|
840
|
+
*/
|
|
841
|
+
declare const middleware: (connect: MiddlewareConnectFn) => _homer0_jimple.Resource<"middleware", "connect", MiddlewareConnectFn>;
|
|
842
|
+
/**
|
|
843
|
+
* A high order function that generates a middleware. It's used on the definitions of a
|
|
844
|
+
* middleware creator.
|
|
845
|
+
*
|
|
846
|
+
* @group Wrappers
|
|
847
|
+
*/
|
|
848
|
+
type MiddlewareCreatorFn = GenericCurriedFn<MiddlewareConnectFn>;
|
|
849
|
+
/**
|
|
850
|
+
* Generates a configurable middleware for the application to use. It's configurable
|
|
851
|
+
* because the `creator`, instead of just being sent to the container to mount, it can
|
|
852
|
+
* also be called as a function with custom parameters the middleware can receive.
|
|
853
|
+
*
|
|
854
|
+
* @param creator A function that will generate a middleware.
|
|
855
|
+
* @example
|
|
856
|
+
*
|
|
857
|
+
* <caption>Basic usage</caption>
|
|
858
|
+
*
|
|
859
|
+
* const myMiddleware = middlewareCreator((options = {}) => (app) => {
|
|
860
|
+
* const message = options.message || 'Hello Charo!';
|
|
861
|
+
* const responsesBuilder = app.get<ResponsesBuilder>('responsesBuilder');
|
|
862
|
+
* return (_, res) => {
|
|
863
|
+
* responsesBuilder.json({ res, data: { message } });
|
|
864
|
+
* };
|
|
865
|
+
* });
|
|
866
|
+
*
|
|
867
|
+
* // ...
|
|
868
|
+
* container.use(myMiddleware);
|
|
869
|
+
*
|
|
870
|
+
* @example
|
|
871
|
+
*
|
|
872
|
+
* <caption>Custom parameters</caption>
|
|
873
|
+
*
|
|
874
|
+
* container.use(myMiddleware({ message: 'Hello Pili!' }));
|
|
875
|
+
*
|
|
876
|
+
* @group Wrappers
|
|
877
|
+
*/
|
|
878
|
+
declare const middlewareCreator: <CreatorFn extends MiddlewareCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"middleware", "connect", CreatorFn, MiddlewareConnectFn>;
|
|
879
|
+
/**
|
|
880
|
+
* A resource that will define middlewares the application can use.
|
|
881
|
+
*
|
|
882
|
+
* @group Wrappers
|
|
883
|
+
*/
|
|
884
|
+
type Middleware = ReturnType<typeof middleware>;
|
|
885
|
+
/**
|
|
886
|
+
* A middleware creator is like a middleware, but i can also be used as a function, and it
|
|
887
|
+
* can receive custom parameters to configure its behavior.
|
|
888
|
+
*
|
|
889
|
+
* @group Wrappers
|
|
890
|
+
*/
|
|
891
|
+
type MiddlewareCreator = ReturnType<typeof middlewareCreator>;
|
|
892
|
+
/**
|
|
893
|
+
* The function a middelware provider uses to configure/extend the container before
|
|
894
|
+
* returning an actual middleware.
|
|
895
|
+
*
|
|
896
|
+
* @param container The reference to the Jimpex container.
|
|
897
|
+
* @param route This is available only in the case the middleware is mounted on a
|
|
898
|
+
* specific route.
|
|
899
|
+
* @group Wrappers
|
|
900
|
+
*/
|
|
901
|
+
type MiddlewareProviderRegisterFn = <ContainerType extends Jimpex = Jimpex>(container: ContainerType, route?: string) => Middleware;
|
|
902
|
+
/**
|
|
903
|
+
* Creates a "middleware provider", which is a middleware that can configure/extend the
|
|
904
|
+
* container before the application uses it.
|
|
905
|
+
*
|
|
906
|
+
* @param register A function that will be called the moment the application uses the
|
|
907
|
+
* middleware provider.
|
|
908
|
+
* @example
|
|
909
|
+
*
|
|
910
|
+
* class MyServiceWithMiddleware {
|
|
911
|
+
* constructor(private readonly responsesBuilder: ResponsesBuilder) {}
|
|
912
|
+
* getMiddleware() {
|
|
913
|
+
* return (_, res) => {
|
|
914
|
+
* this.responsesBuilder.json({ res, data: { message } });
|
|
915
|
+
* };
|
|
916
|
+
* }
|
|
917
|
+
* }
|
|
918
|
+
*
|
|
919
|
+
* const myMiddlewareProvider = middlewareProvider((app) => {
|
|
920
|
+
* app.set(
|
|
921
|
+
* 'myMiddleware',
|
|
922
|
+
* () => new MyServiceWithMiddleware(app.get('responsesBuilder')),
|
|
923
|
+
* );
|
|
924
|
+
* return middleware(() =>
|
|
925
|
+
* app.get<MyServiceWithMiddleware>('myMiddleware').getMiddleware(),
|
|
926
|
+
* );
|
|
927
|
+
* });
|
|
928
|
+
*
|
|
929
|
+
* @group Wrappers
|
|
930
|
+
*/
|
|
931
|
+
declare const middlewareProvider: (register: MiddlewareProviderRegisterFn) => _homer0_jimple.Resource<"provider", "register", MiddlewareProviderRegisterFn>;
|
|
932
|
+
/**
|
|
933
|
+
* A high order function that generates a middleware provider. It's used on the
|
|
934
|
+
* definitions of a middleware provider creator.
|
|
935
|
+
*
|
|
936
|
+
* @group Wrappers
|
|
937
|
+
*/
|
|
938
|
+
type MiddlewareProviderCreatorFn = GenericCurriedFn<MiddlewareProviderRegisterFn>;
|
|
939
|
+
/**
|
|
940
|
+
* Generates a configurable middleware provider for the application to use. This is a mix
|
|
941
|
+
* of a middleware creator and a middleware provider: it gives you the flexibility of the
|
|
942
|
+
* creator, with the resources of the provider.
|
|
943
|
+
*
|
|
944
|
+
* @param creator A function that will generate a middleware provider.
|
|
945
|
+
* @example
|
|
946
|
+
*
|
|
947
|
+
* <caption>Basic usage</caption>
|
|
948
|
+
*
|
|
949
|
+
* class MyServiceWithMiddleware {
|
|
950
|
+
* constructor(private readonly responsesBuilder: ResponsesBuilder) {}
|
|
951
|
+
* getMiddleware() {
|
|
952
|
+
* return (_, res) => {
|
|
953
|
+
* this.responsesBuilder.json({ res, data: { message } });
|
|
954
|
+
* };
|
|
955
|
+
* }
|
|
956
|
+
* }
|
|
957
|
+
* const myMiddlewareProvider = middlewareProviderCreator(
|
|
958
|
+
* ({ serviceName = 'myMiddleware' }) =>
|
|
959
|
+
* (app) => {
|
|
960
|
+
* app.set(
|
|
961
|
+
* serviceName,
|
|
962
|
+
* () => new MyServiceWithMiddleware(app.get('responsesBuilder')),
|
|
963
|
+
* );
|
|
964
|
+
* return middleware(() =>
|
|
965
|
+
* app.get<MyServiceWithMiddleware>(serviceName).getMiddleware(),
|
|
966
|
+
* );
|
|
967
|
+
* },
|
|
968
|
+
* );
|
|
969
|
+
*
|
|
970
|
+
* // ...
|
|
971
|
+
* container.use(myMiddlewareProvider);
|
|
972
|
+
*
|
|
973
|
+
* @example
|
|
974
|
+
*
|
|
975
|
+
* <caption>Custom parameters</caption>
|
|
976
|
+
*
|
|
977
|
+
* container.use(myMiddlewareProvider({ serviceName: 'something' }));
|
|
978
|
+
*
|
|
979
|
+
* @group Wrappers
|
|
980
|
+
*/
|
|
981
|
+
declare const middlewareProviderCreator: <CreatorFn extends MiddlewareProviderCreatorFn>(creator: CreatorFn) => _homer0_jimple.ResourceCreator<"provider", "register", CreatorFn, MiddlewareProviderRegisterFn>;
|
|
982
|
+
/**
|
|
983
|
+
* A special kind of middleware that can be used to configure/extend the container before
|
|
984
|
+
* returning an actual middleware.
|
|
985
|
+
*
|
|
986
|
+
* @group Wrappers
|
|
987
|
+
*/
|
|
988
|
+
type MiddlewareProvider = ReturnType<typeof middlewareProvider>;
|
|
989
|
+
/**
|
|
990
|
+
* A "creator version" of a middleware provider: a middleware that can be used to
|
|
991
|
+
* configure/extend the container before returning an actual middleware, but that can also
|
|
992
|
+
* be called as a function, and it can receive custom parameters to configure its
|
|
993
|
+
* behavior.
|
|
994
|
+
*
|
|
995
|
+
* @group Wrappers
|
|
996
|
+
*/
|
|
997
|
+
type MiddlewareProviderCreator = ReturnType<typeof middlewareProviderCreator>;
|
|
998
|
+
/**
|
|
999
|
+
* A union types of the different kinds of middlewares that can be used by the
|
|
1000
|
+
* application.
|
|
1001
|
+
*
|
|
1002
|
+
* @group Wrappers
|
|
1003
|
+
*/
|
|
1004
|
+
type MiddlewareLike = NoStringIndex<Middleware> | NoStringIndex<MiddlewareProvider> | ExpressMiddlewareLike;
|
|
1005
|
+
/**
|
|
1006
|
+
* A union types of the different kinds of controllers that can be mounted by the
|
|
1007
|
+
* application.
|
|
1008
|
+
*
|
|
1009
|
+
* @group Wrappers
|
|
1010
|
+
*/
|
|
1011
|
+
type ControllerLike = NoStringIndex<Controller> | NoStringIndex<ControllerProvider> | MiddlewareLike;
|
|
1012
|
+
|
|
1013
|
+
/**
|
|
1014
|
+
* Jimpex is a mix of Jimple, a Javascript port of Pimple dependency injection container,
|
|
1015
|
+
* and Express, one of the most popular web frameworks for Node.
|
|
1016
|
+
*
|
|
1017
|
+
* @group Jimpex
|
|
1018
|
+
* @todo Implement `helmet`.
|
|
1019
|
+
*/
|
|
1020
|
+
declare class Jimpex extends Jimple {
|
|
1021
|
+
/**
|
|
1022
|
+
* The customization settings for the application.
|
|
1023
|
+
*/
|
|
1024
|
+
protected _options: JimpexOptions;
|
|
1025
|
+
/**
|
|
1026
|
+
* The Express application Jimpex uses under the hood.
|
|
1027
|
+
*/
|
|
1028
|
+
protected _express: Express;
|
|
1029
|
+
/**
|
|
1030
|
+
* Since the configuration service has an async initialization, the class uses this flag
|
|
1031
|
+
* internally to validate if the configuration has been initialized or not.
|
|
1032
|
+
*/
|
|
1033
|
+
protected _configReady: boolean;
|
|
1034
|
+
/**
|
|
1035
|
+
* A reference to the actuall HTTP the application will use. This can vary depending on
|
|
1036
|
+
* whether HTTPS, or HTTP2 are enabled. If HTTPS is not enabled, it will be the same as
|
|
1037
|
+
* the `express` property; if HTTPS is enabled, it will be an `https` server; and if
|
|
1038
|
+
* HTTP2 is enabled, it will be an `spdy` server.
|
|
1039
|
+
*/
|
|
1040
|
+
protected _server?: JimpexServer;
|
|
1041
|
+
/**
|
|
1042
|
+
* The instance of the server that is listening for requests.
|
|
1043
|
+
*/
|
|
1044
|
+
protected _instance?: JimpexServerInstance;
|
|
1045
|
+
/**
|
|
1046
|
+
* A list of functions that implement controllers and middlewares. When the application
|
|
1047
|
+
* starts, the queue will be processed and those controllers and middlewares will be
|
|
1048
|
+
* added to the server instance. The reason they are not added directly like with a
|
|
1049
|
+
* regular Express implementation is that services on Jimple use lazy loading, and
|
|
1050
|
+
* adding middlewares and controllers as they come could cause errors if they depend on
|
|
1051
|
+
* services that are not yet registered.
|
|
1052
|
+
*/
|
|
1053
|
+
protected _mountQueue: Array<(server: Express) => void>;
|
|
1054
|
+
/**
|
|
1055
|
+
* A list with all the top routes controlled by the application. Every time a controller
|
|
1056
|
+
* is mounted, its route will be added here.
|
|
1057
|
+
*/
|
|
1058
|
+
protected _controlledRoutes: string[];
|
|
1059
|
+
/**
|
|
1060
|
+
* @param options Preferences to customize the application.
|
|
1061
|
+
* @param config The default settings for the configuration service. It's a
|
|
1062
|
+
* shortcuit for `options.config.default`
|
|
1063
|
+
*/
|
|
1064
|
+
constructor(options?: DeepPartial<JimpexOptions>, config?: unknown);
|
|
1065
|
+
/**
|
|
1066
|
+
* This is where the app would register all its specific services, middlewares and controllers.
|
|
1067
|
+
*/
|
|
1068
|
+
boot(): void;
|
|
1069
|
+
/**
|
|
1070
|
+
* Disables the server TLS validation. Meant to be used for development purposes.
|
|
1071
|
+
*/
|
|
1072
|
+
disableTLSValidation(): void;
|
|
1073
|
+
/**
|
|
1074
|
+
* Starts the app server.
|
|
1075
|
+
*
|
|
1076
|
+
* @param onStart A callback function to be called when the server actually starts.
|
|
1077
|
+
* @returns The server instance.
|
|
1078
|
+
*/
|
|
1079
|
+
start(onStart?: JimpexStartCallback): Promise<JimpexServerInstance>;
|
|
1080
|
+
/**
|
|
1081
|
+
* This is an alias of `start`. The idea is for it to be used on serverless platforms,
|
|
1082
|
+
* where you don't get to start your app, you just have export it.
|
|
1083
|
+
*
|
|
1084
|
+
* @param port In case the configuration doesn't already have it,
|
|
1085
|
+
* this is the port where the application will use to run. If this
|
|
1086
|
+
* parameter is used, the method will overwrite the `port`
|
|
1087
|
+
* setting on the configuration service.
|
|
1088
|
+
* @param onStart A callback function to be called when the server starts.
|
|
1089
|
+
* @returns The server instance.
|
|
1090
|
+
*/
|
|
1091
|
+
listen(port?: number, onStart?: JimpexStartCallback): Promise<JimpexServerInstance>;
|
|
1092
|
+
/**
|
|
1093
|
+
* Stops the server instance.
|
|
1094
|
+
*/
|
|
1095
|
+
stop(): void;
|
|
1096
|
+
/**
|
|
1097
|
+
* Mounts a route controller or a middleware into a server routes.
|
|
1098
|
+
*
|
|
1099
|
+
* @param route The route for the controller/middleware.
|
|
1100
|
+
* @param controller The controller/middleware resource to be mounted.
|
|
1101
|
+
*/
|
|
1102
|
+
mount(route: string, controller: ControllerLike): void;
|
|
1103
|
+
/**
|
|
1104
|
+
* Adds a global middleware to the application.
|
|
1105
|
+
*
|
|
1106
|
+
* @param middleware The middleware resource to be added.
|
|
1107
|
+
*/
|
|
1108
|
+
use(middleware: MiddlewareLike): void;
|
|
1109
|
+
getConfig(): SimpleConfig;
|
|
1110
|
+
getConfig<T = unknown>(setting: string | string[], asArray?: boolean): T;
|
|
1111
|
+
/**
|
|
1112
|
+
* Creates a new router instance.
|
|
1113
|
+
*/
|
|
1114
|
+
getRouter(): Router;
|
|
1115
|
+
/**
|
|
1116
|
+
* The logger service.
|
|
1117
|
+
*/
|
|
1118
|
+
get logger(): SimpleLogger;
|
|
1119
|
+
/**
|
|
1120
|
+
* The Express application Jimpex uses under the hood.
|
|
1121
|
+
*/
|
|
1122
|
+
get express(): Express;
|
|
1123
|
+
/**
|
|
1124
|
+
* The server instance that gets created when the app is started.
|
|
1125
|
+
*/
|
|
1126
|
+
get instance(): JimpexServerInstance | undefined;
|
|
1127
|
+
/**
|
|
1128
|
+
* The application customization options.
|
|
1129
|
+
*/
|
|
1130
|
+
get options(): DeepReadonly<JimpexOptions>;
|
|
1131
|
+
/**
|
|
1132
|
+
* Gets the events service.
|
|
1133
|
+
*/
|
|
1134
|
+
get eventsHub(): EventsHub;
|
|
1135
|
+
/**
|
|
1136
|
+
* A list of the routes that have controllers mounted on them.
|
|
1137
|
+
*/
|
|
1138
|
+
get routes(): string[];
|
|
1139
|
+
/**
|
|
1140
|
+
* Adds a listener for an application event.
|
|
1141
|
+
*
|
|
1142
|
+
* @param eventName The name of the event to listen for.
|
|
1143
|
+
* @param listener The listener function.
|
|
1144
|
+
* @returns A function to unsubscribe the listener.
|
|
1145
|
+
* @template EventName The name of the event, to match the type of the listener
|
|
1146
|
+
* function.
|
|
1147
|
+
*/
|
|
1148
|
+
on<EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>): () => boolean;
|
|
1149
|
+
/**
|
|
1150
|
+
* Adds a listener for an application event that will only be execuded once: the first
|
|
1151
|
+
* time the event is triggered.
|
|
1152
|
+
*
|
|
1153
|
+
* @param eventName The name of the event to listen for.
|
|
1154
|
+
* @param listener The listener function.
|
|
1155
|
+
* @returns A function to unsubscribe the listener.
|
|
1156
|
+
* @template EventName The name of the event, to match the type of the listener
|
|
1157
|
+
* function.
|
|
1158
|
+
*/
|
|
1159
|
+
once<EventName extends JimpexEventNameLike>(eventName: EventName, listener: JimpexEventListener<EventName>): () => boolean;
|
|
1160
|
+
/**
|
|
1161
|
+
* Based on the application options, it returns wheter the application is healthy or
|
|
1162
|
+
* not.
|
|
1163
|
+
*/
|
|
1164
|
+
isHealthy(): ReturnType<JimpexHealthCheckFn>;
|
|
1165
|
+
/**
|
|
1166
|
+
* This method is like a "lifecycle method", it gets executed on the constructor right
|
|
1167
|
+
* before the "boot step". The idea is for the method to be a helper when the
|
|
1168
|
+
* application is defined by subclassing {@link Jimpex}: the application could register
|
|
1169
|
+
* all important services here and the routes on boot, then, if the implementation needs
|
|
1170
|
+
* to access or overwrite a something, it can send `boot: false`, access/register what
|
|
1171
|
+
* it needs, and then call `boot()`. That would be impossible for an application without
|
|
1172
|
+
* overwriting the constructor and the boot functionality.
|
|
1173
|
+
*/
|
|
1174
|
+
protected _init(): void;
|
|
1175
|
+
/**
|
|
1176
|
+
* It generates overwrites for the application options when it gets created. This method
|
|
1177
|
+
* is a helper for when the application is defined by subclassing {@link Jimpex}: It's
|
|
1178
|
+
* highly probable that if the application needs to change the default options, it would
|
|
1179
|
+
* want to do it right from the class, instead of having to do it on every
|
|
1180
|
+
* implementation. A way to do it would be overwriting the constructor and calling
|
|
1181
|
+
* `super` with the custom overwrites, but this method exists so that won't be
|
|
1182
|
+
* necessary: when creating the `options`, the constructor will merge the result of this
|
|
1183
|
+
* method on top of the default ones.
|
|
1184
|
+
*/
|
|
1185
|
+
protected _initOptions(): DeepPartial<JimpexOptions>;
|
|
1186
|
+
/**
|
|
1187
|
+
* Registers the "core services" on the container: logger, events, utils, etc.
|
|
1188
|
+
*/
|
|
1189
|
+
protected _setupCoreServices(): void;
|
|
1190
|
+
/**
|
|
1191
|
+
* Configures the Express application based on the class options.
|
|
1192
|
+
*/
|
|
1193
|
+
protected _setupExpress(): void;
|
|
1194
|
+
/**
|
|
1195
|
+
* Adds a static folder to the application.
|
|
1196
|
+
*
|
|
1197
|
+
* @param route The route to add the folder to.
|
|
1198
|
+
* @param folder The path to the folder in the file system. If not defined, it will
|
|
1199
|
+
* be use the same value as `route`. The path could be relative to the
|
|
1200
|
+
* project root, or where the application executable is located,
|
|
1201
|
+
* depending on the value of the `onHome` parameter.
|
|
1202
|
+
* @param onHome If `true`, the path to the folder will be relative to the project
|
|
1203
|
+
* root. If `false`, it will be relative to where the application
|
|
1204
|
+
* executable is located.
|
|
1205
|
+
*/
|
|
1206
|
+
protected _addStaticsFolder(route: string, folder?: string, onHome?: boolean): void;
|
|
1207
|
+
/**
|
|
1208
|
+
* This helper method validates the `path` options in order to register the `app`
|
|
1209
|
+
* location in the `pathUtils` service. The `app` location should be the path to where
|
|
1210
|
+
* the application executable is located, but due to how ESM works, we can't infer it
|
|
1211
|
+
* from the `module` object, so we need either recieved as the `appPath` setting, or try
|
|
1212
|
+
* to get it from the parent module.
|
|
1213
|
+
*
|
|
1214
|
+
* @throws If the method should use the path from the parent module, but can't find
|
|
1215
|
+
* it.
|
|
1216
|
+
*/
|
|
1217
|
+
protected _configurePath(): void;
|
|
1218
|
+
/**
|
|
1219
|
+
* Setups the configuration service. The new configuration service requires async calls
|
|
1220
|
+
* in order to load the configuration files (as it uses `import` instead of `require`),
|
|
1221
|
+
* so it can't be instantiated as the other services.
|
|
1222
|
+
* This method is called just before starting the application.
|
|
1223
|
+
*/
|
|
1224
|
+
protected _setupConfig(): Promise<void>;
|
|
1225
|
+
/**
|
|
1226
|
+
* Processes the resources from the mount queue (added with {@link Jimpex.mount} and
|
|
1227
|
+
* {@link Jimpex.use}), and adds them to the Express application.
|
|
1228
|
+
*/
|
|
1229
|
+
protected _mountResources(): void;
|
|
1230
|
+
/**
|
|
1231
|
+
* Emits an event using the `events` service.
|
|
1232
|
+
*
|
|
1233
|
+
* @param name The name of the event to emit.
|
|
1234
|
+
* @param payload The event payload.
|
|
1235
|
+
* @template EventName The literal name of the event, to type the event payload.
|
|
1236
|
+
*/
|
|
1237
|
+
protected _emitEvent<EventName extends JimpexEventName>(name: EventName, payload: JimpexEventPayload<EventName>): void;
|
|
1238
|
+
/**
|
|
1239
|
+
* Sends a target object to a list of reducer events so they can modify or replace it.
|
|
1240
|
+
*
|
|
1241
|
+
* @param name The name of the event to use.
|
|
1242
|
+
* @param target The object to reduce with the event.
|
|
1243
|
+
* @param payload Extra context for the listeners.
|
|
1244
|
+
*/
|
|
1245
|
+
protected _reduceWithEvent<EventName extends JimpexReducerEventName>(name: EventName, target: JimpexReducerEventTarget<EventName>, payload: JimpexReducerEventPayload<EventName>): JimpexReducerEventTarget<EventName>;
|
|
1246
|
+
/**
|
|
1247
|
+
* Loads the contents of a dictionary of credentials files that need to be used to
|
|
1248
|
+
* configure HTTPS.
|
|
1249
|
+
*
|
|
1250
|
+
* @param credentialsInfo The dictionary where the keys are the type of credentials
|
|
1251
|
+
* (`ca`, `cert`, `key`) and the values are the paths to the
|
|
1252
|
+
* files.
|
|
1253
|
+
* @param onHome If this is `true`, the path of the files will be relative
|
|
1254
|
+
* to the project root. If it is `false`, it will be relative
|
|
1255
|
+
* to where the application executable is located.
|
|
1256
|
+
* @returns
|
|
1257
|
+
*/
|
|
1258
|
+
protected _loadCredentials(credentialsInfo: JimpexHTTPSCredentials, onHome?: boolean): Promise<JimpexHTTPSCredentials>;
|
|
1259
|
+
/**
|
|
1260
|
+
* Validates the configuration and chooses the server the application needs to use: If
|
|
1261
|
+
* HTTP2 is enabled, it will use Spdy; if HTTPS is enabled but HTTP is not, it will use
|
|
1262
|
+
* the native HTTPS server; otherwise, it will be just the Express instance.
|
|
1263
|
+
*
|
|
1264
|
+
* @returns {Server}
|
|
1265
|
+
* @throws {Error} If HTTP2 is enabled but HTTPS is not.
|
|
1266
|
+
* @throws {Error} If HTTPS is enabled but there's no `https.credentials` object.
|
|
1267
|
+
* @throws {Error} If HTTPS is enabled and no creadentials are found.
|
|
1268
|
+
* @access protected
|
|
1269
|
+
* @ignore
|
|
1270
|
+
*/
|
|
1271
|
+
protected _createServer(): Promise<JimpexServer>;
|
|
1272
|
+
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Shorthand for `new Jimpex()`.
|
|
1275
|
+
*
|
|
1276
|
+
* @param args The same parameters as the {@link Jimpex} constructor.
|
|
1277
|
+
* @returns A new instance of {@link Jimpex}.
|
|
1278
|
+
* @group Jimpex
|
|
1279
|
+
*/
|
|
1280
|
+
declare const jimpex: (options?: DeepPartial<JimpexOptions> | undefined, config?: unknown) => Jimpex;
|
|
1281
|
+
|
|
1282
|
+
export { MiddlewareProvider as $, Providers as A, ProviderLike as B, ControllerConnectFn as C, controller as D, EventPayload as E, ControllerCreatorFn as F, controllerCreator as G, Controller as H, ControllerCreator as I, Jimpex as J, ControllerProviderRegisterFn as K, controllerProvider as L, ControllerProviderCreatorFn as M, controllerProviderCreator as N, ControllerProvider as O, ProviderRegisterFn as P, ControllerProviderCreator as Q, MiddlewareConnectFn as R, middleware as S, MiddlewareCreatorFn as T, middlewareCreator as U, Middleware as V, MiddlewareCreator as W, MiddlewareProviderRegisterFn as X, middlewareProvider as Y, MiddlewareProviderCreatorFn as Z, middlewareProviderCreator as _, JimpexEvents as a, MiddlewareProviderCreator as a0, MiddlewareLike as a1, ControllerLike as a2, JimpexEventName as b, JimpexEventPayload as c, JimpexReducerEventTargets as d, JimpexReducerEventPayloads as e, JimpexReducerEventName as f, JimpexReducerEventTarget as g, JimpexReducerEventPayload as h, JimpexEventNameLike as i, jimpex as j, JimpexEventListener as k, Events as l, JimpexConfigOptions as m, JimpexStaticsOptions as n, JimpexExpressOptions as o, JimpexPathOptions as p, JimpexServicesOptions as q, JimpexHealthStatus as r, JimpexHealthCheckFn as s, JimpexOptions as t, JimpexStartCallback as u, provider as v, providerCreator as w, providers as x, Provider as y, ProviderCreator as z };
|