@novice1/app 0.2.0 → 0.3.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/lib/baseApp.d.ts CHANGED
@@ -1,81 +1,98 @@
1
- /// <reference types="node" />
2
- import http from 'http';
3
- import net from 'net';
4
- import express from 'express';
5
- import core from 'express-serve-static-core';
6
- import { IRouter, RequestHandler, RouteMeta } from '@novice1/routing';
7
- export interface FrameworkOptions {
8
- auth?: RequestHandler[];
9
- middlewares?: (core.RequestHandler | core.RequestHandlerParams)[];
10
- validators?: RequestHandler[];
11
- }
12
- export interface Options {
13
- framework?: FrameworkOptions;
14
- routers?: IRouter[];
15
- }
16
- export interface IApp {
17
- get meta(): RouteMeta[];
18
- get server(): http.Server | undefined;
19
- addRouters(routers: IRouter[] | IRouter): IApp;
20
- addOptions(options: Options): IApp;
21
- build(options?: http.ServerOptions): http.Server;
22
- disable(setting: string): IApp;
23
- enable(setting: string): IApp;
24
- disabled(setting: string): boolean;
25
- enabled(setting: string): boolean;
26
- on(event: string, callback: (parent: core.Application) => void): IApp;
27
- }
28
- /**
29
- * Abstract application
30
- */
31
- export declare abstract class BaseApp implements IApp {
32
- #private;
33
- protected __app: express.Application;
34
- protected __router: IRouter;
35
- /**
36
- * Express Application
37
- */
38
- get _app(): express.Application;
39
- /**
40
- * Main router
41
- */
42
- get _router(): IRouter;
43
- get building(): boolean;
44
- get built(): boolean;
45
- get meta(): RouteMeta[];
46
- get server(): http.Server | undefined;
47
- constructor(options?: Options);
48
- private _registerRouter;
49
- private _buildFramework;
50
- private _buildRoutes;
51
- /**
52
- *
53
- * @param options Options to concatenate with current options.
54
- * @returns
55
- */
56
- addOptions(options: Options): BaseApp;
57
- addFrameworkOptions(options: FrameworkOptions): BaseApp;
58
- addRouters(routers: IRouter[] | IRouter): BaseApp;
59
- build(options?: http.ServerOptions): http.Server;
60
- listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): http.Server;
61
- listen(port?: number, hostname?: string, listeningListener?: () => void): http.Server;
62
- listen(port?: number, backlog?: number, listeningListener?: () => void): http.Server;
63
- listen(port?: number, listeningListener?: () => void): http.Server;
64
- listen(path: string, backlog?: number, listeningListener?: () => void): http.Server;
65
- listen(path: string, listeningListener?: () => void): http.Server;
66
- listen(options: net.ListenOptions, listeningListener?: () => void): http.Server;
67
- listen(handle: unknown, backlog?: number, listeningListener?: () => void): http.Server;
68
- listen(handle: unknown, listeningListener?: () => void): http.Server;
69
- /**
70
- * Creates a router and adds it to the application.
71
- * @returns The created router
72
- */
73
- lazyrouter(options?: express.RouterOptions): IRouter;
74
- disable(setting: string): BaseApp;
75
- disabled(setting: string): boolean;
76
- enable(setting: string): BaseApp;
77
- enabled(setting: string): boolean;
78
- on(event: string, callback: (parent: core.Application) => void): BaseApp;
79
- set(setting: string, val?: unknown): BaseApp;
80
- get(setting: string): any;
81
- }
1
+ /// <reference types="node" />
2
+ /// <reference types="node" />
3
+ import http from 'http';
4
+ import net from 'net';
5
+ import express from 'express';
6
+ import core from 'express-serve-static-core';
7
+ import { IRouter, RequestHandler, RouteMeta } from '@novice1/routing';
8
+ export interface FrameworkOptions {
9
+ auth?: RequestHandler[];
10
+ middlewares?: (core.RequestHandler | core.RequestHandlerParams)[];
11
+ validators?: RequestHandler[];
12
+ }
13
+ export interface Options {
14
+ framework?: FrameworkOptions;
15
+ routers?: IRouter[];
16
+ }
17
+ export interface IApp {
18
+ get meta(): RouteMeta[];
19
+ get server(): http.Server | undefined;
20
+ addRouters(routers: IRouter[] | IRouter): IApp;
21
+ addOptions(options: Options): IApp;
22
+ build<T extends http.ServerOptions = http.ServerOptions>(options?: T | null, mod?: {
23
+ createServer(requestListener?: http.RequestListener): http.Server;
24
+ createServer(options: T, requestListener?: http.RequestListener | undefined): http.Server;
25
+ }): http.Server;
26
+ disable(setting: string): IApp;
27
+ enable(setting: string): IApp;
28
+ disabled(setting: string): boolean;
29
+ enabled(setting: string): boolean;
30
+ on(event: string, callback: (parent: core.Application) => void): IApp;
31
+ }
32
+ /**
33
+ * Abstract application
34
+ */
35
+ export declare abstract class BaseApp implements IApp {
36
+ #private;
37
+ protected __app: express.Application;
38
+ protected __router: IRouter;
39
+ /**
40
+ * Express Application
41
+ */
42
+ get _app(): express.Application;
43
+ /**
44
+ * Main router
45
+ */
46
+ get _router(): IRouter;
47
+ get building(): boolean;
48
+ get built(): boolean;
49
+ get meta(): RouteMeta[];
50
+ get server(): http.Server | undefined;
51
+ constructor(options?: Options);
52
+ private _registerRouter;
53
+ private _buildFramework;
54
+ private _buildRoutes;
55
+ /**
56
+ *
57
+ * @param options Options to concatenate with current options.
58
+ * @returns
59
+ */
60
+ addOptions(options: Options): BaseApp;
61
+ addFrameworkOptions(options: FrameworkOptions): BaseApp;
62
+ addRouters(routers: IRouter[] | IRouter): BaseApp;
63
+ /**
64
+ *
65
+ * @param options
66
+ * @param mod Module that will create the server (e.g.: require('https'))
67
+ * @example ```js
68
+ * const https = require('https');
69
+ * const server = app.build(HTTPS_SERVER_OPTIONS, https);
70
+ * server.listen(PORT);
71
+ * ```
72
+ */
73
+ build<T extends http.ServerOptions = http.ServerOptions>(options?: T | null, mod?: {
74
+ createServer(requestListener?: http.RequestListener): http.Server;
75
+ createServer(options: T, requestListener?: http.RequestListener | undefined): http.Server;
76
+ }): http.Server;
77
+ listen(port?: number, hostname?: string, backlog?: number, listeningListener?: () => void): http.Server;
78
+ listen(port?: number, hostname?: string, listeningListener?: () => void): http.Server;
79
+ listen(port?: number, backlog?: number, listeningListener?: () => void): http.Server;
80
+ listen(port?: number, listeningListener?: () => void): http.Server;
81
+ listen(path: string, backlog?: number, listeningListener?: () => void): http.Server;
82
+ listen(path: string, listeningListener?: () => void): http.Server;
83
+ listen(options: net.ListenOptions, listeningListener?: () => void): http.Server;
84
+ listen(handle: unknown, backlog?: number, listeningListener?: () => void): http.Server;
85
+ listen(handle: unknown, listeningListener?: () => void): http.Server;
86
+ /**
87
+ * Creates a router and adds it to the application.
88
+ * @returns The created router
89
+ */
90
+ lazyrouter(options?: express.RouterOptions): IRouter;
91
+ disable(setting: string): BaseApp;
92
+ disabled(setting: string): boolean;
93
+ enable(setting: string): BaseApp;
94
+ enabled(setting: string): boolean;
95
+ on(event: string, callback: (parent: core.Application) => void): BaseApp;
96
+ set(setting: string, val?: unknown): BaseApp;
97
+ get(setting: string): any;
98
+ }