@radatek/microserver 2.1.0 → 2.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/dist/microserver.d.ts +34 -22
- package/dist/microserver.js +254 -201
- package/microserver.ts +3803 -0
- package/package.json +9 -4
package/dist/microserver.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* MicroServer
|
|
3
|
-
* @version 2.
|
|
3
|
+
* @version 2.2.0
|
|
4
4
|
* @package @radatek/microserver
|
|
5
5
|
* @copyright Darius Kisonas 2022
|
|
6
6
|
* @license MIT
|
|
@@ -40,8 +40,9 @@ export type Routes = () => {
|
|
|
40
40
|
export declare abstract class Plugin {
|
|
41
41
|
name?: string;
|
|
42
42
|
priority?: number;
|
|
43
|
-
handler?(req: ServerRequest, res: ServerResponse, next: Function): void;
|
|
44
|
-
routes
|
|
43
|
+
handler?(req: ServerRequest, res: ServerResponse, next: Function): Promise<string | object | void> | string | object | void;
|
|
44
|
+
routes?(): Promise<Routes> | Routes;
|
|
45
|
+
initialise?(): Promise<void> | void;
|
|
45
46
|
constructor(router: Router, ...args: any);
|
|
46
47
|
}
|
|
47
48
|
interface PluginClass {
|
|
@@ -222,6 +223,14 @@ export interface Middleware {
|
|
|
222
223
|
priority?: number;
|
|
223
224
|
plugin?: Plugin;
|
|
224
225
|
}
|
|
226
|
+
declare class Waiter {
|
|
227
|
+
get busy(): boolean;
|
|
228
|
+
startJob(): void;
|
|
229
|
+
endJob(id?: string): void;
|
|
230
|
+
get nextId(): string;
|
|
231
|
+
wait(id: string): Promise<void>;
|
|
232
|
+
resolve(id: string): void;
|
|
233
|
+
}
|
|
225
234
|
/** Router */
|
|
226
235
|
export declare class Router extends EventEmitter {
|
|
227
236
|
server: MicroServer;
|
|
@@ -229,8 +238,11 @@ export declare class Router extends EventEmitter {
|
|
|
229
238
|
plugins: {
|
|
230
239
|
[key: string]: Plugin;
|
|
231
240
|
};
|
|
241
|
+
_waiter: Waiter;
|
|
232
242
|
/** @param {MicroServer} server */
|
|
233
243
|
constructor(server: MicroServer);
|
|
244
|
+
/** bind middleware or create one from string like: 'redirect:302,https://redirect.to', 'error:422', 'param:name=value', 'acl:users/get', 'model:User', 'group:Users', 'user:admin' */
|
|
245
|
+
bind(fn: string | Function | object): Function;
|
|
234
246
|
/** Handler */
|
|
235
247
|
handler(req: ServerRequest, res: ServerResponse, next: Function, method?: string): any;
|
|
236
248
|
/** Clear routes and middlewares */
|
|
@@ -241,54 +253,55 @@ export declare class Router extends EventEmitter {
|
|
|
241
253
|
*
|
|
242
254
|
* @signature add(plugin: Plugin)
|
|
243
255
|
* @param {Plugin} plugin plugin module instance
|
|
244
|
-
* @return {
|
|
256
|
+
* @return {Promise<>}
|
|
245
257
|
*
|
|
246
258
|
* @signature add(pluginid: string, ...args: any)
|
|
247
259
|
* @param {string} pluginid pluginid module
|
|
248
260
|
* @param {...any} args arguments passed to constructor
|
|
249
|
-
* @return {
|
|
261
|
+
* @return {Promise<>}
|
|
250
262
|
*
|
|
251
263
|
* @signature add(pluginClass: typeof Plugin, ...args: any)
|
|
252
264
|
* @param {typeof Plugin} pluginClass plugin class
|
|
253
265
|
* @param {...any} args arguments passed to constructor
|
|
254
|
-
* @return {
|
|
266
|
+
* @return {Promise<>}
|
|
255
267
|
*
|
|
256
268
|
* @signature add(middleware: Middleware)
|
|
257
269
|
* @param {Middleware} middleware
|
|
258
|
-
* @return {
|
|
270
|
+
* @return {Promise<>}
|
|
259
271
|
*
|
|
260
272
|
* @signature add(methodUrl: string, ...middlewares: any)
|
|
261
273
|
* @param {string} methodUrl 'METHOD /url' or '/url'
|
|
262
274
|
* @param {...any} middlewares
|
|
263
|
-
* @return {
|
|
275
|
+
* @return {Promise<>}
|
|
264
276
|
*
|
|
265
277
|
* @signature add(methodUrl: string, controllerClass: typeof Controller)
|
|
266
278
|
* @param {string} methodUrl 'METHOD /url' or '/url'
|
|
267
279
|
* @param {typeof Controller} controllerClass
|
|
268
|
-
* @return {
|
|
280
|
+
* @return {Promise<>}
|
|
269
281
|
*
|
|
270
282
|
* @signature add(methodUrl: string, routes: Array<Array<any>>)
|
|
271
283
|
* @param {string} methodUrl 'METHOD /url' or '/url'
|
|
272
284
|
* @param {Array<Array<any>>} routes list with subroutes: ['METHOD /suburl', ...middlewares]
|
|
273
|
-
* @return {
|
|
285
|
+
* @return {Promise<>}
|
|
274
286
|
*
|
|
275
287
|
* @signature add(methodUrl: string, routes: Array<Array<any>>)
|
|
276
288
|
* @param {string} methodUrl 'METHOD /url' or '/url'
|
|
277
289
|
* @param {Array<Array<any>>} routes list with subroutes: ['METHOD /suburl', ...middlewares]
|
|
278
|
-
* @return {
|
|
290
|
+
* @return {Promise<>}
|
|
279
291
|
*
|
|
280
292
|
* @signature add(routes: { [key: string]: Array<any> })
|
|
281
293
|
* @param { {[key: string]: Array<any>} } routes list with subroutes: 'METHOD /suburl': [...middlewares]
|
|
282
|
-
* @return {
|
|
294
|
+
* @return {Promise<>}
|
|
283
295
|
*
|
|
284
296
|
* @signature add(methodUrl: string, routes: { [key: string]: Array<any> })
|
|
285
297
|
* @param {string} methodUrl 'METHOD /url' or '/url'
|
|
286
298
|
* @param { {[key: string]: Array<any>} } routes list with subroutes: 'METHOD /suburl': [...middlewares]
|
|
287
|
-
* @return {
|
|
299
|
+
* @return {Promise<>}
|
|
288
300
|
*/
|
|
289
|
-
use(...args: any):
|
|
301
|
+
use(...args: any): Promise<void>;
|
|
302
|
+
waitPlugin(id: string): Promise<Plugin>;
|
|
290
303
|
/** Add hook */
|
|
291
|
-
hook(url: string, ...mid: Middleware[]):
|
|
304
|
+
hook(url: string, ...mid: Middleware[]): void;
|
|
292
305
|
/** Check if middleware allready added */
|
|
293
306
|
has(mid: Middleware): boolean;
|
|
294
307
|
}
|
|
@@ -364,23 +377,22 @@ export declare class MicroServer extends EventEmitter {
|
|
|
364
377
|
sockets: Set<net.Socket>;
|
|
365
378
|
/** server instances */
|
|
366
379
|
servers: Set<net.Server>;
|
|
380
|
+
_waiter: Waiter;
|
|
367
381
|
static plugins: {
|
|
368
382
|
[key: string]: PluginClass;
|
|
369
383
|
};
|
|
370
|
-
get plugins(): {
|
|
371
|
-
[key: string]: Plugin;
|
|
372
|
-
};
|
|
373
384
|
constructor(config: MicroServerConfig);
|
|
374
385
|
/** Add one time listener or call immediatelly for 'ready' */
|
|
375
386
|
once(name: string, cb: Function): this;
|
|
376
387
|
/** Add listener and call immediatelly for 'ready' */
|
|
377
388
|
on(name: string, cb: Function): this;
|
|
389
|
+
isReady(): boolean;
|
|
390
|
+
waitReady(): Promise<void>;
|
|
391
|
+
waitPlugin(id: string): Promise<void>;
|
|
378
392
|
/** Listen server, should be used only if config.listen is not set */
|
|
379
|
-
listen(config?: ListenConfig): Promise<
|
|
380
|
-
/** bind middleware or create one from string like: 'redirect:302,https://redirect.to', 'error:422', 'param:name=value', 'acl:users/get', 'model:User', 'group:Users', 'user:admin' */
|
|
381
|
-
bind(fn: string | Function | object): Function;
|
|
393
|
+
listen(config?: ListenConfig): Promise<void>;
|
|
382
394
|
/** Add middleware, routes, etc.. see {router.use} */
|
|
383
|
-
use(...args: any):
|
|
395
|
+
use(...args: any): Promise<void>;
|
|
384
396
|
/** Default server handler */
|
|
385
397
|
handler(req: ServerRequest, res: ServerResponse): void;
|
|
386
398
|
protected requestInit(req: ServerRequest, res?: ServerResponse): void;
|