@mojojs/core 0.18.0 → 0.19.3
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/app.d.ts +117 -4
- package/lib/app.js +105 -8
- package/lib/app.js.map +1 -1
- package/lib/body/params.d.ts +6 -0
- package/lib/body/params.js +6 -0
- package/lib/body/params.js.map +1 -1
- package/lib/body.d.ts +48 -0
- package/lib/body.js +45 -0
- package/lib/body.js.map +1 -1
- package/lib/cli/create-full-app.d.ts +3 -0
- package/lib/cli/create-full-app.js +3 -0
- package/lib/cli/create-full-app.js.map +1 -1
- package/lib/cli/create-lite-app.d.ts +3 -0
- package/lib/cli/create-lite-app.js +3 -0
- package/lib/cli/create-lite-app.js.map +1 -1
- package/lib/cli/eval.d.ts +3 -0
- package/lib/cli/eval.js +3 -0
- package/lib/cli/eval.js.map +1 -1
- package/lib/cli/get.d.ts +3 -0
- package/lib/cli/get.js +3 -0
- package/lib/cli/get.js.map +1 -1
- package/lib/cli/repl.d.ts +3 -0
- package/lib/cli/repl.js +3 -0
- package/lib/cli/repl.js.map +1 -1
- package/lib/cli/routes.d.ts +3 -0
- package/lib/cli/routes.js +3 -0
- package/lib/cli/routes.js.map +1 -1
- package/lib/cli/server.d.ts +3 -0
- package/lib/cli/server.js +3 -0
- package/lib/cli/server.js.map +1 -1
- package/lib/cli/version.d.ts +3 -0
- package/lib/cli/version.js +3 -0
- package/lib/cli/version.js.map +1 -1
- package/lib/cli.d.ts +15 -0
- package/lib/cli.js +15 -0
- package/lib/cli.js.map +1 -1
- package/lib/context.d.ts +99 -0
- package/lib/context.js +84 -0
- package/lib/context.js.map +1 -1
- package/lib/core.d.ts +3 -0
- package/lib/core.js +3 -0
- package/lib/core.js.map +1 -1
- package/lib/hooks.d.ts +9 -0
- package/lib/hooks.js +9 -0
- package/lib/hooks.js.map +1 -1
- package/lib/logger.d.ts +69 -0
- package/lib/logger.js +63 -0
- package/lib/logger.js.map +1 -1
- package/lib/mime.d.ts +14 -0
- package/lib/mime.js +39 -9
- package/lib/mime.js.map +1 -1
- package/lib/mock/request.d.ts +3 -0
- package/lib/mock/request.js +3 -0
- package/lib/mock/request.js.map +1 -1
- package/lib/mock/response.d.ts +3 -0
- package/lib/mock/response.js +3 -0
- package/lib/mock/response.js.map +1 -1
- package/lib/plugins/default-helpers.d.ts +5 -0
- package/lib/plugins/default-helpers.js +18 -0
- package/lib/plugins/default-helpers.js.map +1 -0
- package/lib/plugins/exception-helpers.d.ts +3 -0
- package/lib/plugins/exception-helpers.js +3 -0
- package/lib/plugins/exception-helpers.js.map +1 -1
- package/lib/plugins/header-conditions.d.ts +3 -0
- package/lib/plugins/header-conditions.js +3 -0
- package/lib/plugins/header-conditions.js.map +1 -1
- package/lib/plugins/json-config.d.ts +3 -0
- package/lib/plugins/json-config.js +3 -0
- package/lib/plugins/json-config.js.map +1 -1
- package/lib/plugins/mt-engine.d.ts +3 -0
- package/lib/plugins/mt-engine.js +4 -1
- package/lib/plugins/mt-engine.js.map +1 -1
- package/lib/plugins/view-helpers.d.ts +3 -0
- package/lib/plugins/view-helpers.js +3 -12
- package/lib/plugins/view-helpers.js.map +1 -1
- package/lib/plugins/yaml-config.d.ts +3 -0
- package/lib/plugins/yaml-config.js +3 -0
- package/lib/plugins/yaml-config.js.map +1 -1
- package/lib/renderer.d.ts +38 -0
- package/lib/renderer.js +38 -0
- package/lib/renderer.js.map +1 -1
- package/lib/router/pattern.d.ts +33 -0
- package/lib/router/pattern.js +24 -0
- package/lib/router/pattern.js.map +1 -1
- package/lib/router/plan.d.ts +15 -0
- package/lib/router/plan.js +15 -0
- package/lib/router/plan.js.map +1 -1
- package/lib/router/route.d.ts +83 -0
- package/lib/router/route.js +83 -0
- package/lib/router/route.js.map +1 -1
- package/lib/router.d.ts +39 -3
- package/lib/router.js +47 -10
- package/lib/router.js.map +1 -1
- package/lib/server/cookie.d.ts +6 -0
- package/lib/server/cookie.js +6 -0
- package/lib/server/cookie.js.map +1 -1
- package/lib/server.d.ts +21 -0
- package/lib/server.js +15 -1
- package/lib/server.js.map +1 -1
- package/lib/session.d.ts +35 -0
- package/lib/session.js +35 -0
- package/lib/session.js.map +1 -1
- package/lib/static.d.ts +22 -0
- package/lib/static.js +22 -0
- package/lib/static.js.map +1 -1
- package/lib/user-agent/cookie-jar.d.ts +12 -0
- package/lib/user-agent/cookie-jar.js +12 -0
- package/lib/user-agent/cookie-jar.js.map +1 -1
- package/lib/user-agent/mock.d.ts +15 -0
- package/lib/user-agent/mock.js +15 -0
- package/lib/user-agent/mock.js.map +1 -1
- package/lib/user-agent/response.d.ts +27 -0
- package/lib/user-agent/response.js +27 -0
- package/lib/user-agent/response.js.map +1 -1
- package/lib/user-agent/test.d.ts +115 -2
- package/lib/user-agent/test.js +123 -10
- package/lib/user-agent/test.js.map +1 -1
- package/lib/user-agent/transport/http.d.ts +12 -0
- package/lib/user-agent/transport/http.js +12 -0
- package/lib/user-agent/transport/http.js.map +1 -1
- package/lib/user-agent/transport/https.d.ts +3 -0
- package/lib/user-agent/transport/https.js +3 -0
- package/lib/user-agent/transport/https.js.map +1 -1
- package/lib/user-agent/transport/ws.d.ts +6 -0
- package/lib/user-agent/transport/ws.js +6 -0
- package/lib/user-agent/transport/ws.js.map +1 -1
- package/lib/util.d.ts +31 -1
- package/lib/util.js +30 -0
- package/lib/util.js.map +1 -1
- package/lib/validator/result.d.ts +9 -0
- package/lib/validator/result.js +3 -0
- package/lib/validator/result.js.map +1 -1
- package/lib/validator.d.ts +9 -0
- package/lib/validator.js +9 -0
- package/lib/validator.js.map +1 -1
- package/lib/websocket.d.ts +18 -0
- package/lib/websocket.js +12 -0
- package/lib/websocket.js.map +1 -1
- package/package.json +3 -3
package/lib/app.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { Route } from './router/route.js';
|
|
3
|
-
import type { Server } from './server.js';
|
|
4
3
|
import type { AnyArguments, AppOptions, UserAgentOptions, MockRequestOptions, MojoAction, MojoContext, RouteArguments, ServerRequestOptions, TestUserAgentOptions } from './types.js';
|
|
5
4
|
import type { IncomingMessage, ServerResponse } from 'http';
|
|
6
5
|
import { CLI } from './cli.js';
|
|
@@ -23,50 +22,164 @@ export declare type Decoration = ((...args: any[]) => any) | {
|
|
|
23
22
|
set?: (value: any) => any;
|
|
24
23
|
};
|
|
25
24
|
export declare type Plugin = (app: App, options: Record<string, any>) => any;
|
|
25
|
+
/**
|
|
26
|
+
* Application class.
|
|
27
|
+
*/
|
|
26
28
|
export declare class App {
|
|
29
|
+
/**
|
|
30
|
+
* Command line interface.
|
|
31
|
+
*/
|
|
27
32
|
cli: CLI;
|
|
33
|
+
/**
|
|
34
|
+
* Application config.
|
|
35
|
+
*/
|
|
28
36
|
config: Record<string, any>;
|
|
37
|
+
/**
|
|
38
|
+
* Detect if the application has been imported and disable the command line interface if it has.
|
|
39
|
+
*/
|
|
29
40
|
detectImport: boolean;
|
|
41
|
+
/**
|
|
42
|
+
* Format for HTTP exceptions.
|
|
43
|
+
*/
|
|
30
44
|
exceptionFormat: string;
|
|
45
|
+
/**
|
|
46
|
+
* Application hooks.
|
|
47
|
+
*/
|
|
31
48
|
hooks: Hooks;
|
|
49
|
+
/**
|
|
50
|
+
* Application home directory.
|
|
51
|
+
*/
|
|
32
52
|
home: Path;
|
|
53
|
+
/**
|
|
54
|
+
* Application logger.
|
|
55
|
+
*/
|
|
33
56
|
log: Logger;
|
|
57
|
+
/**
|
|
58
|
+
* MIME types.
|
|
59
|
+
*/
|
|
34
60
|
mime: Mime;
|
|
61
|
+
/**
|
|
62
|
+
* Storage for user defined models.
|
|
63
|
+
*/
|
|
35
64
|
models: Record<string, any>;
|
|
65
|
+
/**
|
|
66
|
+
* Application renderer.
|
|
67
|
+
*/
|
|
36
68
|
renderer: Renderer;
|
|
69
|
+
/**
|
|
70
|
+
* Application router.
|
|
71
|
+
*/
|
|
37
72
|
router: Router;
|
|
73
|
+
/**
|
|
74
|
+
* Secret passphrases used for signed cookies and the like.
|
|
75
|
+
*/
|
|
38
76
|
secrets: string[];
|
|
77
|
+
/**
|
|
78
|
+
* Encrypted cookie based session manager.
|
|
79
|
+
*/
|
|
39
80
|
session: Session;
|
|
81
|
+
/**
|
|
82
|
+
* Static file server.
|
|
83
|
+
*/
|
|
40
84
|
static: Static;
|
|
85
|
+
/**
|
|
86
|
+
* HTTP/WebSocket user agent.
|
|
87
|
+
*/
|
|
41
88
|
ua: UserAgent;
|
|
89
|
+
/**
|
|
90
|
+
* JSON schema validator.
|
|
91
|
+
*/
|
|
42
92
|
validator: Validator;
|
|
43
93
|
_contextClass: any;
|
|
44
94
|
_mode: string;
|
|
45
|
-
_server: WeakRef<Server> | null;
|
|
46
95
|
constructor(options?: AppOptions);
|
|
96
|
+
/**
|
|
97
|
+
* Add an application hook.
|
|
98
|
+
*/
|
|
47
99
|
addAppHook(name: string, fn: AppHook): this;
|
|
100
|
+
/**
|
|
101
|
+
* Add a context hook.
|
|
102
|
+
*/
|
|
48
103
|
addContextHook(name: string, fn: ContextHook): this;
|
|
104
|
+
/**
|
|
105
|
+
* Add a helper.
|
|
106
|
+
*/
|
|
49
107
|
addHelper(name: string, fn: MojoAction): this;
|
|
108
|
+
/**
|
|
109
|
+
* Generate route matching any of the listed HTTP request methods or all.
|
|
110
|
+
*/
|
|
50
111
|
any(...args: AnyArguments): Route;
|
|
112
|
+
/**
|
|
113
|
+
* Decorate context class with a method or getter/setter.
|
|
114
|
+
*/
|
|
51
115
|
decorateContext(name: string, fn: Decoration): this;
|
|
116
|
+
/**
|
|
117
|
+
* Generate route matching only `DELETE` requests.
|
|
118
|
+
*/
|
|
52
119
|
delete(...args: RouteArguments): Route;
|
|
120
|
+
/**
|
|
121
|
+
* Generate route matching only `GET` requests.
|
|
122
|
+
*/
|
|
53
123
|
get(...args: RouteArguments): Route;
|
|
124
|
+
/**
|
|
125
|
+
* Handle a new incoming request, used by servers.
|
|
126
|
+
*/
|
|
54
127
|
handleRequest(ctx: MojoContext): Promise<void>;
|
|
128
|
+
/**
|
|
129
|
+
* Operating mode for application. Defaults to the value of the `NODE_ENV` environment variable.
|
|
130
|
+
*/
|
|
55
131
|
get mode(): string;
|
|
132
|
+
/**
|
|
133
|
+
* Create a context for application.
|
|
134
|
+
*/
|
|
56
135
|
newContext(req: IncomingMessage, res: ServerResponse, options: ServerRequestOptions): MojoContext;
|
|
136
|
+
/**
|
|
137
|
+
* Create a mock context for application. Very useful for testing helpers.
|
|
138
|
+
*/
|
|
57
139
|
newMockContext(options?: MockRequestOptions): MojoContext;
|
|
140
|
+
/**
|
|
141
|
+
* Create a new mock user agent for application.
|
|
142
|
+
*/
|
|
58
143
|
newMockUserAgent(options?: UserAgentOptions): Promise<MockUserAgent>;
|
|
144
|
+
/**
|
|
145
|
+
* Create a new test user agent for application.
|
|
146
|
+
*/
|
|
59
147
|
newTestUserAgent(options?: TestUserAgentOptions): Promise<TestUserAgent>;
|
|
148
|
+
/**
|
|
149
|
+
* Generate route matching only `OPTIONS` requests.
|
|
150
|
+
*/
|
|
60
151
|
options(...args: RouteArguments): Route;
|
|
152
|
+
/**
|
|
153
|
+
* Generate route matching only `PATCH` requests.
|
|
154
|
+
*/
|
|
61
155
|
patch(...args: RouteArguments): Route;
|
|
156
|
+
/**
|
|
157
|
+
* Register plugin.
|
|
158
|
+
*/
|
|
62
159
|
plugin(plugin: Plugin, options?: Record<string, any>): any;
|
|
160
|
+
/**
|
|
161
|
+
* Generate route matching only `POST` requests.
|
|
162
|
+
*/
|
|
63
163
|
post(...args: RouteArguments): Route;
|
|
164
|
+
/**
|
|
165
|
+
* Generate route matching only `PUT` requests.
|
|
166
|
+
*/
|
|
64
167
|
put(...args: RouteArguments): Route;
|
|
65
|
-
|
|
66
|
-
|
|
168
|
+
/**
|
|
169
|
+
* Start the command line interface.
|
|
170
|
+
*/
|
|
67
171
|
start(command?: string, ...args: string[]): void;
|
|
172
|
+
/**
|
|
173
|
+
* Generate route for a nested route with its own intermediate destination.
|
|
174
|
+
*/
|
|
68
175
|
under(...args: AnyArguments): Route;
|
|
176
|
+
/**
|
|
177
|
+
* Warmup the cache, usually called automatically.
|
|
178
|
+
*/
|
|
69
179
|
warmup(): Promise<void>;
|
|
180
|
+
/**
|
|
181
|
+
* Generate route matching only WebSocket handshake requests.
|
|
182
|
+
*/
|
|
70
183
|
websocket(...args: RouteArguments): Route;
|
|
71
184
|
}
|
|
72
185
|
export {};
|
package/lib/app.js
CHANGED
|
@@ -5,6 +5,7 @@ import { Logger } from './logger.js';
|
|
|
5
5
|
import { Mime } from './mime.js';
|
|
6
6
|
import { MockRequest } from './mock/request.js';
|
|
7
7
|
import { MockResponse } from './mock/response.js';
|
|
8
|
+
import defaultHelpersPlugin from './plugins/default-helpers.js';
|
|
8
9
|
import exceptionHelpersPlugin from './plugins/exception-helpers.js';
|
|
9
10
|
import headerConditionsPlugin from './plugins/header-conditions.js';
|
|
10
11
|
import mtEnginePlugin from './plugins/mt-engine.js';
|
|
@@ -20,22 +21,57 @@ import { Validator } from './validator.js';
|
|
|
20
21
|
import Path from '@mojojs/path';
|
|
21
22
|
const ContextWrapper = class extends Context {
|
|
22
23
|
};
|
|
24
|
+
/**
|
|
25
|
+
* Application class.
|
|
26
|
+
*/
|
|
23
27
|
export class App {
|
|
24
28
|
constructor(options = {}) {
|
|
29
|
+
/**
|
|
30
|
+
* Command line interface.
|
|
31
|
+
*/
|
|
25
32
|
this.cli = new CLI(this);
|
|
33
|
+
/**
|
|
34
|
+
* Application hooks.
|
|
35
|
+
*/
|
|
26
36
|
this.hooks = new Hooks();
|
|
37
|
+
/**
|
|
38
|
+
* Application home directory.
|
|
39
|
+
*/
|
|
27
40
|
this.home = new Path();
|
|
41
|
+
/**
|
|
42
|
+
* MIME types.
|
|
43
|
+
*/
|
|
28
44
|
this.mime = new Mime();
|
|
45
|
+
/**
|
|
46
|
+
* Storage for user defined models.
|
|
47
|
+
*/
|
|
29
48
|
this.models = {};
|
|
49
|
+
/**
|
|
50
|
+
* Application renderer.
|
|
51
|
+
*/
|
|
30
52
|
this.renderer = new Renderer();
|
|
53
|
+
/**
|
|
54
|
+
* Application router.
|
|
55
|
+
*/
|
|
31
56
|
this.router = new Router();
|
|
57
|
+
/**
|
|
58
|
+
* Encrypted cookie based session manager.
|
|
59
|
+
*/
|
|
32
60
|
this.session = new Session(this);
|
|
61
|
+
/**
|
|
62
|
+
* Static file server.
|
|
63
|
+
*/
|
|
33
64
|
this.static = new Static();
|
|
65
|
+
/**
|
|
66
|
+
* HTTP/WebSocket user agent.
|
|
67
|
+
*/
|
|
34
68
|
this.ua = new UserAgent();
|
|
69
|
+
/**
|
|
70
|
+
* JSON schema validator.
|
|
71
|
+
*/
|
|
35
72
|
this.validator = new Validator();
|
|
36
73
|
this._contextClass = class extends ContextWrapper {
|
|
37
74
|
};
|
|
38
|
-
this._server = null;
|
|
39
75
|
this.config = options.config ?? {};
|
|
40
76
|
this.detectImport = options.detectImport ?? true;
|
|
41
77
|
this.exceptionFormat = options.exceptionFormat ?? 'html';
|
|
@@ -43,27 +79,43 @@ export class App {
|
|
|
43
79
|
this._mode = options.mode ?? process.env.NODE_ENV ?? 'development';
|
|
44
80
|
const isDev = this._mode === 'development';
|
|
45
81
|
this.log = new Logger({ historySize: isDev ? 10 : 0, level: isDev ? 'trace' : 'info' });
|
|
46
|
-
this.plugin(
|
|
82
|
+
this.plugin(defaultHelpersPlugin);
|
|
47
83
|
this.plugin(exceptionHelpersPlugin);
|
|
48
84
|
this.plugin(headerConditionsPlugin);
|
|
85
|
+
this.plugin(mtEnginePlugin);
|
|
49
86
|
this.plugin(viewHelpersPlugin);
|
|
50
87
|
}
|
|
88
|
+
/**
|
|
89
|
+
* Add an application hook.
|
|
90
|
+
*/
|
|
51
91
|
addAppHook(name, fn) {
|
|
52
92
|
this.hooks.addHook(name, fn);
|
|
53
93
|
return this;
|
|
54
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Add a context hook.
|
|
97
|
+
*/
|
|
55
98
|
addContextHook(name, fn) {
|
|
56
99
|
this.hooks.addHook(name, fn);
|
|
57
100
|
return this;
|
|
58
101
|
}
|
|
102
|
+
/**
|
|
103
|
+
* Add a helper.
|
|
104
|
+
*/
|
|
59
105
|
addHelper(name, fn) {
|
|
60
106
|
return this.decorateContext(name, function (...args) {
|
|
61
107
|
return fn(this, ...args);
|
|
62
108
|
});
|
|
63
109
|
}
|
|
110
|
+
/**
|
|
111
|
+
* Generate route matching any of the listed HTTP request methods or all.
|
|
112
|
+
*/
|
|
64
113
|
any(...args) {
|
|
65
114
|
return this.router.any(...args);
|
|
66
115
|
}
|
|
116
|
+
/**
|
|
117
|
+
* Decorate context class with a method or getter/setter.
|
|
118
|
+
*/
|
|
67
119
|
decorateContext(name, fn) {
|
|
68
120
|
const proto = Context.prototype;
|
|
69
121
|
if (Object.getOwnPropertyDescriptor(proto, name) != null) {
|
|
@@ -77,12 +129,21 @@ export class App {
|
|
|
77
129
|
}
|
|
78
130
|
return this;
|
|
79
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* Generate route matching only `DELETE` requests.
|
|
134
|
+
*/
|
|
80
135
|
delete(...args) {
|
|
81
136
|
return this.router.delete(...args);
|
|
82
137
|
}
|
|
138
|
+
/**
|
|
139
|
+
* Generate route matching only `GET` requests.
|
|
140
|
+
*/
|
|
83
141
|
get(...args) {
|
|
84
142
|
return this.router.get(...args);
|
|
85
143
|
}
|
|
144
|
+
/**
|
|
145
|
+
* Handle a new incoming request, used by servers.
|
|
146
|
+
*/
|
|
86
147
|
async handleRequest(ctx) {
|
|
87
148
|
if ((await this.hooks.runHook('dispatch:before', ctx)) === true)
|
|
88
149
|
return;
|
|
@@ -95,55 +156,91 @@ export class App {
|
|
|
95
156
|
if (ctx.isWebSocket !== true)
|
|
96
157
|
await ctx.notFound();
|
|
97
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Operating mode for application. Defaults to the value of the `NODE_ENV` environment variable.
|
|
161
|
+
*/
|
|
98
162
|
get mode() {
|
|
99
163
|
return this._mode;
|
|
100
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Create a context for application.
|
|
167
|
+
*/
|
|
101
168
|
newContext(req, res, options) {
|
|
102
169
|
return new this._contextClass(this, req, res, options);
|
|
103
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a mock context for application. Very useful for testing helpers.
|
|
173
|
+
*/
|
|
104
174
|
newMockContext(options) {
|
|
105
175
|
const req = new MockRequest(options);
|
|
106
176
|
return new this._contextClass(this, req, new MockResponse(req), { isReverseProxy: false, isWebSocket: false });
|
|
107
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Create a new mock user agent for application.
|
|
180
|
+
*/
|
|
108
181
|
async newMockUserAgent(options) {
|
|
109
182
|
return await MockUserAgent.newMockUserAgent(this, options);
|
|
110
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Create a new test user agent for application.
|
|
186
|
+
*/
|
|
111
187
|
async newTestUserAgent(options) {
|
|
112
188
|
return await TestUserAgent.newTestUserAgent(this, options);
|
|
113
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Generate route matching only `OPTIONS` requests.
|
|
192
|
+
*/
|
|
114
193
|
options(...args) {
|
|
115
194
|
return this.router.options(...args);
|
|
116
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Generate route matching only `PATCH` requests.
|
|
198
|
+
*/
|
|
117
199
|
patch(...args) {
|
|
118
200
|
return this.router.patch(...args);
|
|
119
201
|
}
|
|
202
|
+
/**
|
|
203
|
+
* Register plugin.
|
|
204
|
+
*/
|
|
120
205
|
plugin(plugin, options = {}) {
|
|
121
206
|
return plugin(this, options);
|
|
122
207
|
}
|
|
208
|
+
/**
|
|
209
|
+
* Generate route matching only `POST` requests.
|
|
210
|
+
*/
|
|
123
211
|
post(...args) {
|
|
124
212
|
return this.router.post(...args);
|
|
125
213
|
}
|
|
214
|
+
/**
|
|
215
|
+
* Generate route matching only `PUT` requests.
|
|
216
|
+
*/
|
|
126
217
|
put(...args) {
|
|
127
218
|
return this.router.put(...args);
|
|
128
219
|
}
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
set server(server) {
|
|
133
|
-
this._server = server === null ? null : new WeakRef(server);
|
|
134
|
-
}
|
|
220
|
+
/**
|
|
221
|
+
* Start the command line interface.
|
|
222
|
+
*/
|
|
135
223
|
start(command, ...args) {
|
|
136
224
|
if (this.detectImport && process.argv[1] !== Path.callerFile().toString())
|
|
137
225
|
return;
|
|
138
226
|
this.cli.start(command, ...args).catch(error => this.log.error(error.message));
|
|
139
227
|
}
|
|
228
|
+
/**
|
|
229
|
+
* Generate route for a nested route with its own intermediate destination.
|
|
230
|
+
*/
|
|
140
231
|
under(...args) {
|
|
141
232
|
return this.router.under(...args);
|
|
142
233
|
}
|
|
234
|
+
/**
|
|
235
|
+
* Warmup the cache, usually called automatically.
|
|
236
|
+
*/
|
|
143
237
|
async warmup() {
|
|
144
238
|
await this.renderer.warmup();
|
|
145
239
|
await this.router.warmup();
|
|
146
240
|
}
|
|
241
|
+
/**
|
|
242
|
+
* Generate route matching only WebSocket handshake requests.
|
|
243
|
+
*/
|
|
147
244
|
websocket(...args) {
|
|
148
245
|
return this.router.websocket(...args);
|
|
149
246
|
}
|
package/lib/app.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"app.js","sourceRoot":"","sources":["../src/app.ts"],"names":[],"mappings":"AAaA,OAAO,EAAC,GAAG,EAAC,MAAM,UAAU,CAAC;AAC7B,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,KAAK,EAAC,MAAM,YAAY,CAAC;AACjC,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAC;AAC/B,OAAO,EAAC,WAAW,EAAC,MAAM,m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AAK,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;IACjF,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,GAAG,IAAkB;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,CAAC;IACpC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACV,MAAM,IAAI,CAAC,QAAQ,CAAC,MAAM,EAAE,CAAC;QAC7B,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,SAAS,CAAC,GAAG,IAAoB;QAC/B,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC,CAAC;IACxC,CAAC;CACF"}
|
package/lib/body/params.d.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { URLSearchParams } from 'url';
|
|
3
|
+
/**
|
|
4
|
+
* GET/POST parameter class.
|
|
5
|
+
*/
|
|
3
6
|
export declare class Params extends URLSearchParams {
|
|
7
|
+
/**
|
|
8
|
+
* Convert parameters into a plain object, useful for validation.
|
|
9
|
+
*/
|
|
4
10
|
toObject(): Record<string, string>;
|
|
5
11
|
}
|
package/lib/body/params.js
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { URLSearchParams } from 'url';
|
|
2
|
+
/**
|
|
3
|
+
* GET/POST parameter class.
|
|
4
|
+
*/
|
|
2
5
|
export class Params extends URLSearchParams {
|
|
6
|
+
/**
|
|
7
|
+
* Convert parameters into a plain object, useful for validation.
|
|
8
|
+
*/
|
|
3
9
|
toObject() {
|
|
4
10
|
return Object.fromEntries(this);
|
|
5
11
|
}
|
package/lib/body/params.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/body/params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,KAAK,CAAC;AAEpC,MAAM,OAAO,MAAO,SAAQ,eAAe;IACzC,QAAQ;QACN,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF"}
|
|
1
|
+
{"version":3,"file":"params.js","sourceRoot":"","sources":["../../src/body/params.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,eAAe,EAAC,MAAM,KAAK,CAAC;AAEpC;;GAEG;AACH,MAAM,OAAO,MAAO,SAAQ,eAAe;IACzC;;OAEG;IACH,QAAQ;QACN,OAAO,MAAM,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;IAClC,CAAC;CACF"}
|
package/lib/body.d.ts
CHANGED
|
@@ -22,24 +22,72 @@ interface FileUpload {
|
|
|
22
22
|
encoding: string;
|
|
23
23
|
mimetype: string;
|
|
24
24
|
}
|
|
25
|
+
/**
|
|
26
|
+
* HTTP message body base class.
|
|
27
|
+
*/
|
|
25
28
|
export declare class Body {
|
|
29
|
+
/**
|
|
30
|
+
* Automatically decompress message body if necessary.
|
|
31
|
+
*/
|
|
26
32
|
autoDecompress: boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Low-level HTTP message.
|
|
35
|
+
*/
|
|
27
36
|
raw: IncomingMessage;
|
|
28
37
|
_form: Params | undefined;
|
|
29
38
|
constructor(stream: IncomingMessage);
|
|
30
39
|
[Symbol.asyncIterator](): AsyncIterable<Buffer>;
|
|
40
|
+
/**
|
|
41
|
+
* Get message body as `Buffer` object.
|
|
42
|
+
*/
|
|
31
43
|
buffer(): Promise<Buffer>;
|
|
44
|
+
/**
|
|
45
|
+
* Get message body as a readable stream.
|
|
46
|
+
*/
|
|
32
47
|
createReadStream(): Readable;
|
|
48
|
+
/**
|
|
49
|
+
* Get async iterator for uploaded files from message body.
|
|
50
|
+
*/
|
|
33
51
|
files(options?: UploadOptions): AsyncIterableIterator<FileUpload>;
|
|
52
|
+
/**
|
|
53
|
+
* Get form parameters from message body.
|
|
54
|
+
*/
|
|
34
55
|
form(options?: UploadOptions): Promise<Params>;
|
|
56
|
+
/**
|
|
57
|
+
* Get HTTP header from message.
|
|
58
|
+
*/
|
|
35
59
|
get(name: string): string | undefined;
|
|
60
|
+
/**
|
|
61
|
+
* Get HTTP headers from message.
|
|
62
|
+
*/
|
|
36
63
|
get headers(): IncomingHttpHeaders;
|
|
64
|
+
/**
|
|
65
|
+
* Get HTML message body as `@mojojs/dom` object.
|
|
66
|
+
*/
|
|
37
67
|
html(): Promise<DOM>;
|
|
68
|
+
/**
|
|
69
|
+
* Check if underlying socket was encrypted with TLS.
|
|
70
|
+
*/
|
|
38
71
|
get isSecure(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Get JSON message body as parsed data structure.
|
|
74
|
+
*/
|
|
39
75
|
json(): Promise<JSONValue>;
|
|
76
|
+
/**
|
|
77
|
+
* Pipe message body to writable stream.
|
|
78
|
+
*/
|
|
40
79
|
pipe(writer: Writable): Promise<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Get message body as string.
|
|
82
|
+
*/
|
|
41
83
|
text(charset?: BufferEncoding): Promise<string>;
|
|
84
|
+
/**
|
|
85
|
+
* Get XML message body as `@mojojs/dom` object.
|
|
86
|
+
*/
|
|
42
87
|
xml(): Promise<DOM>;
|
|
88
|
+
/**
|
|
89
|
+
* Get YAML message body as parsed data structure.
|
|
90
|
+
*/
|
|
43
91
|
yaml(): Promise<unknown>;
|
|
44
92
|
_consumeBody(): Promise<Uint8Array[]>;
|
|
45
93
|
_formIterator(options?: UploadOptions): AsyncIterableIterator<[string, Readable, string, string, string]>;
|
package/lib/body.js
CHANGED
|
@@ -4,8 +4,14 @@ import { Params } from './body/params.js';
|
|
|
4
4
|
import DOM from '@mojojs/dom';
|
|
5
5
|
import busboy from 'busboy';
|
|
6
6
|
import yaml from 'js-yaml';
|
|
7
|
+
/**
|
|
8
|
+
* HTTP message body base class.
|
|
9
|
+
*/
|
|
7
10
|
export class Body {
|
|
8
11
|
constructor(stream) {
|
|
12
|
+
/**
|
|
13
|
+
* Automatically decompress message body if necessary.
|
|
14
|
+
*/
|
|
9
15
|
this.autoDecompress = true;
|
|
10
16
|
this._form = undefined;
|
|
11
17
|
this.raw = stream;
|
|
@@ -13,9 +19,15 @@ export class Body {
|
|
|
13
19
|
async *[Symbol.asyncIterator]() {
|
|
14
20
|
yield* this.createReadStream();
|
|
15
21
|
}
|
|
22
|
+
/**
|
|
23
|
+
* Get message body as `Buffer` object.
|
|
24
|
+
*/
|
|
16
25
|
async buffer() {
|
|
17
26
|
return Buffer.concat(await this._consumeBody());
|
|
18
27
|
}
|
|
28
|
+
/**
|
|
29
|
+
* Get message body as a readable stream.
|
|
30
|
+
*/
|
|
19
31
|
createReadStream() {
|
|
20
32
|
if (this.autoDecompress !== true || this.get('content-encoding') !== 'gzip')
|
|
21
33
|
return this.raw;
|
|
@@ -23,6 +35,9 @@ export class Body {
|
|
|
23
35
|
this.raw.pipe(gunzip);
|
|
24
36
|
return gunzip;
|
|
25
37
|
}
|
|
38
|
+
/**
|
|
39
|
+
* Get async iterator for uploaded files from message body.
|
|
40
|
+
*/
|
|
26
41
|
async *files(options) {
|
|
27
42
|
if (this._isForm() === false)
|
|
28
43
|
return;
|
|
@@ -37,6 +52,9 @@ export class Body {
|
|
|
37
52
|
throw error;
|
|
38
53
|
}
|
|
39
54
|
}
|
|
55
|
+
/**
|
|
56
|
+
* Get form parameters from message body.
|
|
57
|
+
*/
|
|
40
58
|
async form(options) {
|
|
41
59
|
if (this._form === undefined) {
|
|
42
60
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
@@ -46,34 +64,61 @@ export class Body {
|
|
|
46
64
|
}
|
|
47
65
|
return this._params;
|
|
48
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Get HTTP header from message.
|
|
69
|
+
*/
|
|
49
70
|
get(name) {
|
|
50
71
|
const header = this.raw.headers[name.toLowerCase()];
|
|
51
72
|
return Array.isArray(header) ? header.join(',') : header;
|
|
52
73
|
}
|
|
74
|
+
/**
|
|
75
|
+
* Get HTTP headers from message.
|
|
76
|
+
*/
|
|
53
77
|
get headers() {
|
|
54
78
|
return this.raw.headers;
|
|
55
79
|
}
|
|
80
|
+
/**
|
|
81
|
+
* Get HTML message body as `@mojojs/dom` object.
|
|
82
|
+
*/
|
|
56
83
|
async html() {
|
|
57
84
|
return new DOM(await this.text());
|
|
58
85
|
}
|
|
86
|
+
/**
|
|
87
|
+
* Check if underlying socket was encrypted with TLS.
|
|
88
|
+
*/
|
|
59
89
|
get isSecure() {
|
|
60
90
|
const socket = this.raw.socket;
|
|
61
91
|
return socket.encrypted ?? false;
|
|
62
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* Get JSON message body as parsed data structure.
|
|
95
|
+
*/
|
|
63
96
|
async json() {
|
|
64
97
|
return JSON.parse((await this.buffer()).toString());
|
|
65
98
|
}
|
|
99
|
+
/**
|
|
100
|
+
* Pipe message body to writable stream.
|
|
101
|
+
*/
|
|
66
102
|
async pipe(writer) {
|
|
67
103
|
return await new Promise((resolve, reject) => {
|
|
68
104
|
this.createReadStream().on('error', reject).pipe(writer).on('unpipe', resolve);
|
|
69
105
|
});
|
|
70
106
|
}
|
|
107
|
+
/**
|
|
108
|
+
* Get message body as string.
|
|
109
|
+
*/
|
|
71
110
|
async text(charset = 'utf8') {
|
|
72
111
|
return (await this.buffer()).toString(charset);
|
|
73
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* Get XML message body as `@mojojs/dom` object.
|
|
115
|
+
*/
|
|
74
116
|
async xml() {
|
|
75
117
|
return new DOM(await this.text(), { xml: true });
|
|
76
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* Get YAML message body as parsed data structure.
|
|
121
|
+
*/
|
|
77
122
|
async yaml() {
|
|
78
123
|
return yaml.load((await this.buffer()).toString());
|
|
79
124
|
}
|
package/lib/body.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"body.js","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,EAAE,EAAC,MAAM,QAAQ,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,SAAS,CAAC;AAwB3B,MAAM,OAAO,IAAI;
|
|
1
|
+
{"version":3,"file":"body.js","sourceRoot":"","sources":["../src/body.ts"],"names":[],"mappings":"AAIA,OAAO,EAAC,EAAE,EAAC,MAAM,QAAQ,CAAC;AAC1B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,GAAG,MAAM,aAAa,CAAC;AAC9B,OAAO,MAAM,MAAM,QAAQ,CAAC;AAC5B,OAAO,IAAI,MAAM,SAAS,CAAC;AAwB3B;;GAEG;AACH,MAAM,OAAO,IAAI;IAYf,YAAY,MAAuB;QAXnC;;WAEG;QACH,mBAAc,GAAG,IAAI,CAAC;QAMtB,UAAK,GAAuB,SAAS,CAAC;QAGpC,IAAI,CAAC,GAAG,GAAG,MAAM,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,aAAa,CAAC;QAC3B,KAAK,CAAC,CAAC,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACjC,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,MAAM;QACV,OAAO,MAAM,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,YAAY,EAAE,CAAC,CAAC;IAClD,CAAC;IAED;;OAEG;IACH,gBAAgB;QACd,IAAI,IAAI,CAAC,cAAc,KAAK,IAAI,IAAI,IAAI,CAAC,GAAG,CAAC,kBAAkB,CAAC,KAAK,MAAM;YAAE,OAAO,IAAI,C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