@mojojs/core 0.17.3 → 0.19.2
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/README.md +1 -1
- package/lib/app.d.ts +114 -4
- package/lib/app.js +107 -16
- 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 +20 -4
- package/lib/cli.js.map +1 -1
- package/lib/context.d.ts +99 -0
- package/lib/context.js +88 -3
- 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 +3 -0
- 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/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.d.ts +3 -3
- package/lib/router.js +11 -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/request.d.ts +3 -5
- package/lib/server/request.js +10 -14
- package/lib/server/request.js.map +1 -1
- package/lib/server/response.js +1 -1
- package/lib/server/response.js.map +1 -1
- package/lib/server.d.ts +21 -0
- package/lib/server.js +17 -3
- 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 +19 -0
- package/lib/static.js +20 -1
- package/lib/static.js.map +1 -1
- package/lib/types.d.ts +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 +18 -2
- 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/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/user-agent.d.ts +1 -1
- package/lib/user-agent.js +10 -2
- package/lib/user-agent.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 +2 -2
- package/vendor/views/mojo/debug.html.mt +1 -1
- package/vendor/views/mojo/not-found.html.mt +1 -1
package/README.md
CHANGED
|
@@ -32,7 +32,7 @@ If you want to stay up to date on the latest developments join us on [IRC](https
|
|
|
32
32
|
dependency hell and allow for "Perl-grade" long term support.
|
|
33
33
|
|
|
34
34
|
* Fresh code based upon decades of experience developing [Mojolicious](https://mojolicious.org) and
|
|
35
|
-
[Catalyst](
|
|
35
|
+
[Catalyst](http://catalyst.perl.org), free and open source.
|
|
36
36
|
|
|
37
37
|
## Installation
|
|
38
38
|
|
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,161 @@ 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;
|
|
62
156
|
plugin(plugin: Plugin, options?: Record<string, any>): any;
|
|
157
|
+
/**
|
|
158
|
+
* Generate route matching only `POST` requests.
|
|
159
|
+
*/
|
|
63
160
|
post(...args: RouteArguments): Route;
|
|
161
|
+
/**
|
|
162
|
+
* Generate route matching only `PUT` requests.
|
|
163
|
+
*/
|
|
64
164
|
put(...args: RouteArguments): Route;
|
|
65
|
-
|
|
66
|
-
|
|
165
|
+
/**
|
|
166
|
+
* Start the command line interface.
|
|
167
|
+
*/
|
|
67
168
|
start(command?: string, ...args: string[]): void;
|
|
169
|
+
/**
|
|
170
|
+
* Generate route for a nested route with its own intermediate destination.
|
|
171
|
+
*/
|
|
68
172
|
under(...args: AnyArguments): Route;
|
|
173
|
+
/**
|
|
174
|
+
* Warmup the cache, usually called automatically.
|
|
175
|
+
*/
|
|
69
176
|
warmup(): Promise<void>;
|
|
177
|
+
/**
|
|
178
|
+
* Generate route matching only WebSocket handshake requests.
|
|
179
|
+
*/
|
|
70
180
|
websocket(...args: RouteArguments): Route;
|
|
71
181
|
}
|
|
72
182
|
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,76 +129,115 @@ 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
|
-
if (
|
|
88
|
-
if ((await this.hooks.runHook('websocket', ctx)) === true)
|
|
89
|
-
return;
|
|
90
|
-
await this.router.dispatch(ctx);
|
|
148
|
+
if ((await this.hooks.runHook('dispatch:before', ctx)) === true)
|
|
91
149
|
return;
|
|
92
|
-
|
|
93
|
-
if ((await this.hooks.runHook('request', ctx)) === true)
|
|
150
|
+
if (ctx.isWebSocket !== true && (await this.static.dispatch(ctx)) === true)
|
|
94
151
|
return;
|
|
95
|
-
if ((await this.
|
|
152
|
+
if ((await this.hooks.runHook('router:before', ctx)) === true)
|
|
96
153
|
return;
|
|
97
154
|
if ((await this.router.dispatch(ctx)) === true)
|
|
98
155
|
return;
|
|
99
|
-
|
|
156
|
+
if (ctx.isWebSocket !== true)
|
|
157
|
+
await ctx.notFound();
|
|
100
158
|
}
|
|
159
|
+
/**
|
|
160
|
+
* Operating mode for application. Defaults to the value of the `NODE_ENV` environment variable.
|
|
161
|
+
*/
|
|
101
162
|
get mode() {
|
|
102
163
|
return this._mode;
|
|
103
164
|
}
|
|
165
|
+
/**
|
|
166
|
+
* Create a context for application.
|
|
167
|
+
*/
|
|
104
168
|
newContext(req, res, options) {
|
|
105
169
|
return new this._contextClass(this, req, res, options);
|
|
106
170
|
}
|
|
171
|
+
/**
|
|
172
|
+
* Create a mock context for application. Very useful for testing helpers.
|
|
173
|
+
*/
|
|
107
174
|
newMockContext(options) {
|
|
108
175
|
const req = new MockRequest(options);
|
|
109
176
|
return new this._contextClass(this, req, new MockResponse(req), { isReverseProxy: false, isWebSocket: false });
|
|
110
177
|
}
|
|
178
|
+
/**
|
|
179
|
+
* Create a new mock user agent for application.
|
|
180
|
+
*/
|
|
111
181
|
async newMockUserAgent(options) {
|
|
112
182
|
return await MockUserAgent.newMockUserAgent(this, options);
|
|
113
183
|
}
|
|
184
|
+
/**
|
|
185
|
+
* Create a new test user agent for application.
|
|
186
|
+
*/
|
|
114
187
|
async newTestUserAgent(options) {
|
|
115
188
|
return await TestUserAgent.newTestUserAgent(this, options);
|
|
116
189
|
}
|
|
190
|
+
/**
|
|
191
|
+
* Generate route matching only `OPTIONS` requests.
|
|
192
|
+
*/
|
|
117
193
|
options(...args) {
|
|
118
194
|
return this.router.options(...args);
|
|
119
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Generate route matching only `PATCH` requests.
|
|
198
|
+
*/
|
|
120
199
|
patch(...args) {
|
|
121
200
|
return this.router.patch(...args);
|
|
122
201
|
}
|
|
123
202
|
plugin(plugin, options = {}) {
|
|
124
203
|
return plugin(this, options);
|
|
125
204
|
}
|
|
205
|
+
/**
|
|
206
|
+
* Generate route matching only `POST` requests.
|
|
207
|
+
*/
|
|
126
208
|
post(...args) {
|
|
127
209
|
return this.router.post(...args);
|
|
128
210
|
}
|
|
211
|
+
/**
|
|
212
|
+
* Generate route matching only `PUT` requests.
|
|
213
|
+
*/
|
|
129
214
|
put(...args) {
|
|
130
215
|
return this.router.put(...args);
|
|
131
216
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
set server(server) {
|
|
136
|
-
this._server = server === null ? null : new WeakRef(server);
|
|
137
|
-
}
|
|
217
|
+
/**
|
|
218
|
+
* Start the command line interface.
|
|
219
|
+
*/
|
|
138
220
|
start(command, ...args) {
|
|
139
221
|
if (this.detectImport && process.argv[1] !== Path.callerFile().toString())
|
|
140
222
|
return;
|
|
141
223
|
this.cli.start(command, ...args).catch(error => this.log.error(error.message));
|
|
142
224
|
}
|
|
225
|
+
/**
|
|
226
|
+
* Generate route for a nested route with its own intermediate destination.
|
|
227
|
+
*/
|
|
143
228
|
under(...args) {
|
|
144
229
|
return this.router.under(...args);
|
|
145
230
|
}
|
|
231
|
+
/**
|
|
232
|
+
* Warmup the cache, usually called automatically.
|
|
233
|
+
*/
|
|
146
234
|
async warmup() {
|
|
147
235
|
await this.renderer.warmup();
|
|
148
236
|
await this.router.warmup();
|
|
149
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* Generate route matching only WebSocket handshake requests.
|
|
240
|
+
*/
|
|
150
241
|
websocket(...args) {
|
|
151
242
|
return this.router.websocket(...args);
|
|
152
243
|
}
|
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,mBAAmB,CAAC;AAC9C,OAAO,EAAC,YAAY,EAAC,MAAM,oBAAoB,CAAC;AAChD,OAAO,oBAAoB,MAAM,8BAA8B,CAAC;AAChE,OAAO,sBAAsB,MAAM,gCAAgC,CAAC;AACpE,OAAO,sBAAsB,MAAM,gCAAgC,CAAC;AACpE,OAAO,cAAc,MAAM,wBAAwB,CAAC;AACpD,OAAO,iBAAiB,MAAM,2BAA2B,CAAC;AAC1D,OAAO,EAAC,QAAQ,EAAC,MAAM,eAAe,CAAC;AACvC,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,EAAC,OAAO,EAAC,MAAM,cAAc,CAAC;AACrC,OAAO,EAAC,MAAM,EAAC,MAAM,aAAa,CAAC;AACnC,OAAO,EAAC,SAAS,EAAC,MAAM,iBAAiB,CAAC;AAC1C,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,aAAa,EAAC,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAC,SAAS,EA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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
|
}
|