@mojojs/core 1.26.18 → 2.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/README.md +1 -1
- package/lib/app.d.ts +31 -16
- package/lib/app.js +181 -126
- package/lib/body/params.js +0 -1
- package/lib/body.d.ts +13 -5
- package/lib/body.js +47 -17
- package/lib/cache.d.ts +1 -2
- package/lib/cache.js +12 -21
- package/lib/cgi.d.ts +3 -3
- package/lib/cgi.js +16 -8
- package/lib/cli/cgi.d.ts +1 -1
- package/lib/cli/cgi.js +1 -2
- package/lib/cli/create-full-app.d.ts +1 -1
- package/lib/cli/create-full-app.js +27 -27
- package/lib/cli/create-lite-app.d.ts +1 -1
- package/lib/cli/create-lite-app.js +2 -3
- package/lib/cli/create-plugin.d.ts +1 -1
- package/lib/cli/create-plugin.js +25 -23
- package/lib/cli/eval.d.ts +1 -1
- package/lib/cli/eval.js +12 -5
- package/lib/cli/get.d.ts +1 -1
- package/lib/cli/get.js +30 -26
- package/lib/cli/repl.d.ts +1 -1
- package/lib/cli/repl.js +0 -1
- package/lib/cli/routes.d.ts +1 -1
- package/lib/cli/routes.js +10 -7
- package/lib/cli/server.d.ts +1 -1
- package/lib/cli/server.js +41 -24
- package/lib/cli/version.js +1 -2
- package/lib/cli.d.ts +1 -1
- package/lib/cli.js +25 -19
- package/lib/context.d.ts +33 -10
- package/lib/context.js +137 -32
- package/lib/core.d.ts +14 -13
- package/lib/core.js +12 -12
- package/lib/headers.js +5 -4
- package/lib/hooks.d.ts +1 -1
- package/lib/hooks.js +1 -5
- package/lib/logger.d.ts +2 -2
- package/lib/logger.js +28 -16
- package/lib/mime.js +10 -13
- package/lib/plugins/default-conditions.d.ts +1 -1
- package/lib/plugins/default-conditions.js +0 -1
- package/lib/plugins/default-helpers.d.ts +1 -1
- package/lib/plugins/default-helpers.js +28 -11
- package/lib/plugins/json-config.d.ts +1 -1
- package/lib/plugins/json-config.js +0 -1
- package/lib/plugins/mount.d.ts +1 -1
- package/lib/plugins/mount.js +0 -1
- package/lib/plugins/tmpl-engine.d.ts +1 -1
- package/lib/plugins/tmpl-engine.js +2 -5
- package/lib/plugins/yaml-config.d.ts +1 -1
- package/lib/plugins/yaml-config.js +1 -2
- package/lib/renderer.d.ts +1 -1
- package/lib/renderer.js +27 -30
- package/lib/router/pattern.d.ts +1 -1
- package/lib/router/pattern.js +25 -14
- package/lib/router/plan.d.ts +1 -1
- package/lib/router/plan.js +12 -15
- package/lib/router/route.d.ts +10 -3
- package/lib/router/route.js +44 -38
- package/lib/router.d.ts +4 -4
- package/lib/router.js +25 -26
- package/lib/server/cookie.d.ts +1 -1
- package/lib/server/cookie.js +3 -2
- package/lib/server/request.d.ts +3 -3
- package/lib/server/request.js +44 -17
- package/lib/server/response.d.ts +3 -3
- package/lib/server/response.js +20 -20
- package/lib/server.d.ts +7 -2
- package/lib/server.js +70 -20
- package/lib/session.d.ts +8 -3
- package/lib/session.js +47 -29
- package/lib/sse.d.ts +10 -0
- package/lib/sse.js +62 -0
- package/lib/static.d.ts +1 -1
- package/lib/static.js +27 -22
- package/lib/types.d.ts +13 -5
- package/lib/types.js +0 -1
- package/lib/user-agent/cookie-jar.d.ts +2 -2
- package/lib/user-agent/cookie-jar.js +6 -9
- package/lib/user-agent/mock.d.ts +4 -4
- package/lib/user-agent/mock.js +6 -7
- package/lib/user-agent/response.d.ts +12 -1
- package/lib/user-agent/response.js +36 -2
- package/lib/user-agent/test.d.ts +75 -5
- package/lib/user-agent/test.js +147 -13
- package/lib/user-agent/transport/http.d.ts +2 -2
- package/lib/user-agent/transport/http.js +7 -10
- package/lib/user-agent/transport/https.d.ts +2 -2
- package/lib/user-agent/transport/https.js +2 -6
- package/lib/user-agent/transport/ws.d.ts +2 -2
- package/lib/user-agent/transport/ws.js +2 -3
- package/lib/user-agent.d.ts +21 -18
- package/lib/user-agent.js +70 -49
- package/lib/util.d.ts +13 -0
- package/lib/util.js +35 -11
- package/lib/validator/result.d.ts +1 -1
- package/lib/validator/result.js +8 -1
- package/lib/validator.d.ts +2 -2
- package/lib/validator.js +3 -6
- package/lib/websocket.d.ts +2 -2
- package/lib/websocket.js +9 -1
- package/package.json +22 -29
- package/lib/app.js.map +0 -1
- package/lib/body/params.js.map +0 -1
- package/lib/body.js.map +0 -1
- package/lib/cache.js.map +0 -1
- package/lib/cgi.js.map +0 -1
- package/lib/cli/cgi.js.map +0 -1
- package/lib/cli/create-full-app.js.map +0 -1
- package/lib/cli/create-lite-app.js.map +0 -1
- package/lib/cli/create-plugin.js.map +0 -1
- package/lib/cli/eval.js.map +0 -1
- package/lib/cli/get.js.map +0 -1
- package/lib/cli/repl.js.map +0 -1
- package/lib/cli/routes.js.map +0 -1
- package/lib/cli/server.js.map +0 -1
- package/lib/cli/version.js.map +0 -1
- package/lib/cli.js.map +0 -1
- package/lib/context.js.map +0 -1
- package/lib/core.js.map +0 -1
- package/lib/headers.js.map +0 -1
- package/lib/hooks.js.map +0 -1
- package/lib/logger.js.map +0 -1
- package/lib/mime.js.map +0 -1
- package/lib/plugins/default-conditions.js.map +0 -1
- package/lib/plugins/default-helpers.js.map +0 -1
- package/lib/plugins/json-config.js.map +0 -1
- package/lib/plugins/mount.js.map +0 -1
- package/lib/plugins/tmpl-engine.js.map +0 -1
- package/lib/plugins/yaml-config.js.map +0 -1
- package/lib/renderer.js.map +0 -1
- package/lib/router/pattern.js.map +0 -1
- package/lib/router/plan.js.map +0 -1
- package/lib/router/route.js.map +0 -1
- package/lib/router.js.map +0 -1
- package/lib/server/cookie.js.map +0 -1
- package/lib/server/request.js.map +0 -1
- package/lib/server/response.js.map +0 -1
- package/lib/server.js.map +0 -1
- package/lib/session.js.map +0 -1
- package/lib/static.js.map +0 -1
- package/lib/types.js.map +0 -1
- package/lib/user-agent/cookie-jar.js.map +0 -1
- package/lib/user-agent/mock.js.map +0 -1
- package/lib/user-agent/response.js.map +0 -1
- package/lib/user-agent/test.js.map +0 -1
- package/lib/user-agent/transport/http.js.map +0 -1
- package/lib/user-agent/transport/https.js.map +0 -1
- package/lib/user-agent/transport/ws.js.map +0 -1
- package/lib/user-agent.js.map +0 -1
- package/lib/util.js.map +0 -1
- package/lib/validator/result.js.map +0 -1
- package/lib/validator.js.map +0 -1
- package/lib/websocket.js.map +0 -1
package/lib/plugins/mount.d.ts
CHANGED
package/lib/plugins/mount.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
|
-
import { Cache } from
|
|
2
|
+
import { Cache } from "../cache.js";
|
|
3
3
|
import Path from '@mojojs/path';
|
|
4
4
|
import Template from '@mojojs/template';
|
|
5
5
|
/**
|
|
@@ -9,9 +9,7 @@ export default function tmplEnginePlugin(app) {
|
|
|
9
9
|
app.renderer.addEngine('tmpl', new TmplEngine());
|
|
10
10
|
}
|
|
11
11
|
class TmplEngine {
|
|
12
|
-
|
|
13
|
-
this.cache = new Cache();
|
|
14
|
-
}
|
|
12
|
+
cache = new Cache();
|
|
15
13
|
async render(ctx, options) {
|
|
16
14
|
let template;
|
|
17
15
|
if (options.inline !== undefined) {
|
|
@@ -35,4 +33,3 @@ class TmplEngine {
|
|
|
35
33
|
return Buffer.from(await template({ ...ctx.stash, stash: ctx.stash, ctx, view: options, tags: ctx.tags }));
|
|
36
34
|
}
|
|
37
35
|
}
|
|
38
|
-
//# sourceMappingURL=tmpl-engine.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { loadConfig } from
|
|
1
|
+
import { loadConfig } from "./json-config.js";
|
|
2
2
|
import * as yaml from 'js-yaml';
|
|
3
3
|
/**
|
|
4
4
|
* YAML config plugin.
|
|
@@ -8,4 +8,3 @@ export default function yamlConfigPlugin(app, options) {
|
|
|
8
8
|
options.ext = 'yml';
|
|
9
9
|
loadConfig(app, options, yaml.load);
|
|
10
10
|
}
|
|
11
|
-
//# sourceMappingURL=yaml-config.js.map
|
package/lib/renderer.d.ts
CHANGED
package/lib/renderer.js
CHANGED
|
@@ -7,35 +7,33 @@ const gzipPromise = promisify(gzip);
|
|
|
7
7
|
* Renderer class.
|
|
8
8
|
*/
|
|
9
9
|
export class Renderer {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this._viewIndex = undefined;
|
|
38
|
-
}
|
|
10
|
+
/**
|
|
11
|
+
* Try to negotiate compression for dynamically generated response content and gzip compress it automatically.
|
|
12
|
+
*/
|
|
13
|
+
autoCompress = true;
|
|
14
|
+
/**
|
|
15
|
+
* The default template engine to use for rendering in cases where auto-detection doesn't work, like for inline
|
|
16
|
+
* templates, defaults to `tmpl`.
|
|
17
|
+
*/
|
|
18
|
+
defaultEngine = 'tmpl';
|
|
19
|
+
/**
|
|
20
|
+
* The default format to render if format is not set, defaults to `html`. Note that changing the default away from
|
|
21
|
+
* `html` is not recommended, as it has the potential to break, for example, plugins with bundled templates.
|
|
22
|
+
*/
|
|
23
|
+
defaultFormat = 'html';
|
|
24
|
+
/**
|
|
25
|
+
* Template engines.
|
|
26
|
+
*/
|
|
27
|
+
engines = {};
|
|
28
|
+
/**
|
|
29
|
+
* Minimum output size in bytes required for compression to be used if enabled, defaults to `860`.
|
|
30
|
+
*/
|
|
31
|
+
minCompressSize = 860;
|
|
32
|
+
/**
|
|
33
|
+
* Directories to look for templates in, first one has the highest precedence.
|
|
34
|
+
*/
|
|
35
|
+
viewPaths = [Path.currentFile().sibling('..', 'vendor', 'views').toString()];
|
|
36
|
+
_viewIndex = undefined;
|
|
39
37
|
/**
|
|
40
38
|
* Register a template engine.
|
|
41
39
|
*/
|
|
@@ -194,4 +192,3 @@ export class Renderer {
|
|
|
194
192
|
return { output: await engine.render(ctx, options), format: view.format };
|
|
195
193
|
}
|
|
196
194
|
}
|
|
197
|
-
//# sourceMappingURL=renderer.js.map
|
package/lib/router/pattern.d.ts
CHANGED
package/lib/router/pattern.js
CHANGED
|
@@ -10,20 +10,32 @@ const OP = {
|
|
|
10
10
|
* Route pattern class.
|
|
11
11
|
*/
|
|
12
12
|
export class Pattern {
|
|
13
|
+
/**
|
|
14
|
+
* Pattern constraints.
|
|
15
|
+
*/
|
|
16
|
+
constraints;
|
|
17
|
+
/**
|
|
18
|
+
* Pattern default values.
|
|
19
|
+
*/
|
|
20
|
+
defaults;
|
|
21
|
+
/**
|
|
22
|
+
* Placeholder names.
|
|
23
|
+
*/
|
|
24
|
+
placeholders = [];
|
|
25
|
+
/**
|
|
26
|
+
* Pattern in compiled regular expression form.
|
|
27
|
+
*/
|
|
28
|
+
regex = undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Placeholder types.
|
|
31
|
+
*/
|
|
32
|
+
types;
|
|
33
|
+
/**
|
|
34
|
+
* Raw unparsed pattern.
|
|
35
|
+
*/
|
|
36
|
+
unparsed = '';
|
|
37
|
+
_ast = [];
|
|
13
38
|
constructor(path, options = {}) {
|
|
14
|
-
/**
|
|
15
|
-
* Placeholder names.
|
|
16
|
-
*/
|
|
17
|
-
this.placeholders = [];
|
|
18
|
-
/**
|
|
19
|
-
* Pattern in compiled regular expression form.
|
|
20
|
-
*/
|
|
21
|
-
this.regex = undefined;
|
|
22
|
-
/**
|
|
23
|
-
* Raw unparsed pattern.
|
|
24
|
-
*/
|
|
25
|
-
this.unparsed = '';
|
|
26
|
-
this._ast = [];
|
|
27
39
|
this.constraints = options.constraints ?? {};
|
|
28
40
|
this.defaults = options.defaults ?? {};
|
|
29
41
|
this.types = options.types ?? {};
|
|
@@ -202,4 +214,3 @@ export class Pattern {
|
|
|
202
214
|
ast.reverse();
|
|
203
215
|
}
|
|
204
216
|
}
|
|
205
|
-
//# sourceMappingURL=pattern.js.map
|
package/lib/router/plan.d.ts
CHANGED
package/lib/router/plan.js
CHANGED
|
@@ -2,20 +2,18 @@
|
|
|
2
2
|
* Router plan class.
|
|
3
3
|
*/
|
|
4
4
|
export class Plan {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
this.stops = [];
|
|
18
|
-
}
|
|
5
|
+
/**
|
|
6
|
+
* Route endpoint.
|
|
7
|
+
*/
|
|
8
|
+
endpoint = undefined;
|
|
9
|
+
/**
|
|
10
|
+
* Steps in route.
|
|
11
|
+
*/
|
|
12
|
+
steps = [];
|
|
13
|
+
/**
|
|
14
|
+
* Dispatch stops in route.
|
|
15
|
+
*/
|
|
16
|
+
stops = [];
|
|
19
17
|
/**
|
|
20
18
|
* Render route.
|
|
21
19
|
*/
|
|
@@ -27,4 +25,3 @@ export class Plan {
|
|
|
27
25
|
return { path: endpoint.render(merged), websocket: endpoint.hasWebSocket() };
|
|
28
26
|
}
|
|
29
27
|
}
|
|
30
|
-
//# sourceMappingURL=plan.js.map
|
package/lib/router/route.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { Router } from '../router.
|
|
2
|
-
import type { AnyArguments, MojoAction, RouteArguments } from '../types.
|
|
3
|
-
import { Pattern } from './pattern.
|
|
1
|
+
import type { Router } from '../router.ts';
|
|
2
|
+
import type { AnyArguments, MojoAction, RouteArguments } from '../types.ts';
|
|
3
|
+
import { Pattern } from './pattern.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Route class.
|
|
6
6
|
*/
|
|
@@ -122,6 +122,13 @@ export declare class Route {
|
|
|
122
122
|
* route.put('/user').to('User#replace');
|
|
123
123
|
*/
|
|
124
124
|
put(...args: RouteArguments): Route;
|
|
125
|
+
/**
|
|
126
|
+
* Generate route matching only `QUERY` requests.
|
|
127
|
+
* @example
|
|
128
|
+
* // Route with destination
|
|
129
|
+
* route.query('/search').to('Search#index');
|
|
130
|
+
*/
|
|
131
|
+
query(...args: RouteArguments): Route;
|
|
125
132
|
/**
|
|
126
133
|
* Remove route from parent.
|
|
127
134
|
*/
|
package/lib/router/route.js
CHANGED
|
@@ -1,44 +1,42 @@
|
|
|
1
|
-
import { Pattern } from
|
|
1
|
+
import { Pattern } from "./pattern.js";
|
|
2
2
|
/**
|
|
3
3
|
* Route class.
|
|
4
4
|
*/
|
|
5
5
|
export class Route {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this._root = undefined;
|
|
41
|
-
}
|
|
6
|
+
/**
|
|
7
|
+
* The children of this route, used for nesting routes.
|
|
8
|
+
*/
|
|
9
|
+
children = [];
|
|
10
|
+
/**
|
|
11
|
+
* Custom route name, if defined.
|
|
12
|
+
*/
|
|
13
|
+
customName = undefined;
|
|
14
|
+
/**
|
|
15
|
+
* Default route name.
|
|
16
|
+
*/
|
|
17
|
+
defaultName = undefined;
|
|
18
|
+
/**
|
|
19
|
+
* Allow `under` semantics for this route.
|
|
20
|
+
*/
|
|
21
|
+
underRoute = false;
|
|
22
|
+
/**
|
|
23
|
+
* Restrict HTTP methods this route is allowed to handle, defaults to no restrictions.
|
|
24
|
+
*/
|
|
25
|
+
methods = [];
|
|
26
|
+
/**
|
|
27
|
+
* Pattern for this route.
|
|
28
|
+
*/
|
|
29
|
+
pattern = new Pattern();
|
|
30
|
+
/**
|
|
31
|
+
* Activate conditions for this route.
|
|
32
|
+
*/
|
|
33
|
+
requirements = [];
|
|
34
|
+
/**
|
|
35
|
+
* Activate `websocket` semantics for this route.
|
|
36
|
+
*/
|
|
37
|
+
websocketRoute = false;
|
|
38
|
+
_parent = undefined;
|
|
39
|
+
_root = undefined;
|
|
42
40
|
/**
|
|
43
41
|
* Add a child to this route.
|
|
44
42
|
*/
|
|
@@ -172,6 +170,15 @@ export class Route {
|
|
|
172
170
|
put(...args) {
|
|
173
171
|
return this.any(['PUT'], ...args);
|
|
174
172
|
}
|
|
173
|
+
/**
|
|
174
|
+
* Generate route matching only `QUERY` requests.
|
|
175
|
+
* @example
|
|
176
|
+
* // Route with destination
|
|
177
|
+
* route.query('/search').to('Search#index');
|
|
178
|
+
*/
|
|
179
|
+
query(...args) {
|
|
180
|
+
return this.any(['QUERY'], ...args);
|
|
181
|
+
}
|
|
175
182
|
/**
|
|
176
183
|
* Remove route from parent.
|
|
177
184
|
*/
|
|
@@ -287,4 +294,3 @@ export class Route {
|
|
|
287
294
|
return branch;
|
|
288
295
|
}
|
|
289
296
|
}
|
|
290
|
-
//# sourceMappingURL=route.js.map
|
package/lib/router.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { MojoContext, PlaceholderType } from './types.
|
|
2
|
-
import { Cache } from './cache.
|
|
3
|
-
import { Plan } from './router/plan.
|
|
4
|
-
import { Route } from './router/route.
|
|
1
|
+
import type { MojoContext, PlaceholderType } from './types.ts';
|
|
2
|
+
import { Cache } from './cache.ts';
|
|
3
|
+
import { Plan } from './router/plan.ts';
|
|
4
|
+
import { Route } from './router/route.ts';
|
|
5
5
|
type RouteIndex = Record<string, Route>;
|
|
6
6
|
interface RouteSpec {
|
|
7
7
|
ctx?: MojoContext;
|
package/lib/router.js
CHANGED
|
@@ -1,35 +1,35 @@
|
|
|
1
|
-
import { Cache } from
|
|
2
|
-
import { Plan } from
|
|
3
|
-
import { Route } from
|
|
4
|
-
import * as util from
|
|
1
|
+
import { Cache } from "./cache.js";
|
|
2
|
+
import { Plan } from "./router/plan.js";
|
|
3
|
+
import { Route } from "./router/route.js";
|
|
4
|
+
import * as util from "./util.js";
|
|
5
5
|
const PLACEHOLDER = {};
|
|
6
6
|
/**
|
|
7
7
|
* Router class.
|
|
8
8
|
*/
|
|
9
9
|
export class Router extends Route {
|
|
10
|
+
/**
|
|
11
|
+
* Routing cache.
|
|
12
|
+
*/
|
|
13
|
+
cache = new Cache();
|
|
14
|
+
/**
|
|
15
|
+
* Contains all available conditions.
|
|
16
|
+
*/
|
|
17
|
+
conditions = {};
|
|
18
|
+
/**
|
|
19
|
+
* Directories to look for controllers in, first one has the highest precedence.
|
|
20
|
+
*/
|
|
21
|
+
controllerPaths = [];
|
|
22
|
+
/**
|
|
23
|
+
* Already loaded controllers.
|
|
24
|
+
*/
|
|
25
|
+
controllers = {};
|
|
26
|
+
/**
|
|
27
|
+
* Registered placeholder types, by default only `num` is already defined.
|
|
28
|
+
*/
|
|
29
|
+
types = { num: /[0-9]+/ };
|
|
30
|
+
_lookupIndex = undefined;
|
|
10
31
|
constructor() {
|
|
11
32
|
super();
|
|
12
|
-
/**
|
|
13
|
-
* Routing cache.
|
|
14
|
-
*/
|
|
15
|
-
this.cache = new Cache();
|
|
16
|
-
/**
|
|
17
|
-
* Contains all available conditions.
|
|
18
|
-
*/
|
|
19
|
-
this.conditions = {};
|
|
20
|
-
/**
|
|
21
|
-
* Directories to look for controllers in, first one has the highest precedence.
|
|
22
|
-
*/
|
|
23
|
-
this.controllerPaths = [];
|
|
24
|
-
/**
|
|
25
|
-
* Already loaded controllers.
|
|
26
|
-
*/
|
|
27
|
-
this.controllers = {};
|
|
28
|
-
/**
|
|
29
|
-
* Registered placeholder types, by default only `num` is already defined.
|
|
30
|
-
*/
|
|
31
|
-
this.types = { num: /[0-9]+/ };
|
|
32
|
-
this._lookupIndex = undefined;
|
|
33
33
|
this.root = this;
|
|
34
34
|
}
|
|
35
35
|
/**
|
|
@@ -218,4 +218,3 @@ export class Router extends Route {
|
|
|
218
218
|
return false;
|
|
219
219
|
}
|
|
220
220
|
}
|
|
221
|
-
//# sourceMappingURL=router.js.map
|
package/lib/server/cookie.d.ts
CHANGED
package/lib/server/cookie.js
CHANGED
|
@@ -3,7 +3,7 @@ import { decodeURIComponentSafe } from '@mojojs/util';
|
|
|
3
3
|
* Parse cookie.
|
|
4
4
|
*/
|
|
5
5
|
export function parseCookie(cookie) {
|
|
6
|
-
const values =
|
|
6
|
+
const values = Object.create(null);
|
|
7
7
|
for (const pair of cookie.split(/[,;]/)) {
|
|
8
8
|
const match = pair.match(/^\s*([^=\s]+)\s*=\s*(\S+)\s*$/);
|
|
9
9
|
if (match === null)
|
|
@@ -44,8 +44,9 @@ export function stringifyCookie(name, value, options = {}) {
|
|
|
44
44
|
cookie.push('SameSite=None');
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
|
+
if (options.partitioned === true)
|
|
48
|
+
cookie.push('Partitioned');
|
|
47
49
|
if (options?.secure === true)
|
|
48
50
|
cookie.push('Secure');
|
|
49
51
|
return cookie.join('; ');
|
|
50
52
|
}
|
|
51
|
-
//# sourceMappingURL=cookie.js.map
|
package/lib/server/request.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { ServerRequestOptions } from '../types.
|
|
2
|
-
import { Params } from '../body/params.
|
|
3
|
-
import { Body } from '../body.
|
|
1
|
+
import type { ServerRequestOptions } from '../types.ts';
|
|
2
|
+
import { Params } from '../body/params.ts';
|
|
3
|
+
import { Body } from '../body.ts';
|
|
4
4
|
/**
|
|
5
5
|
* Server request class.
|
|
6
6
|
*/
|
package/lib/server/request.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Params } from
|
|
2
|
-
import { Body } from
|
|
3
|
-
import { parseCookie } from
|
|
1
|
+
import { Params } from "../body/params.js";
|
|
2
|
+
import { Body } from "../body.js";
|
|
3
|
+
import { parseCookie } from "../server/cookie.js";
|
|
4
4
|
import { decodeURIComponentSafe } from '@mojojs/util';
|
|
5
5
|
// Official regex from RFC 3986
|
|
6
6
|
const URL_RE = /^(([^:/?#]+):)?(\/\/([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/;
|
|
@@ -9,21 +9,49 @@ let requestId = 0;
|
|
|
9
9
|
* Server request class.
|
|
10
10
|
*/
|
|
11
11
|
export class ServerRequest extends Body {
|
|
12
|
+
/**
|
|
13
|
+
* Request base path.
|
|
14
|
+
*/
|
|
15
|
+
basePath = '';
|
|
16
|
+
/**
|
|
17
|
+
* Check if underlying socket was encrypted with TLS.
|
|
18
|
+
*/
|
|
19
|
+
isSecure;
|
|
20
|
+
/**
|
|
21
|
+
* Request is a WebSocket handshake.
|
|
22
|
+
*/
|
|
23
|
+
isWebSocket;
|
|
24
|
+
/**
|
|
25
|
+
* Request method.
|
|
26
|
+
*/
|
|
27
|
+
method;
|
|
28
|
+
/**
|
|
29
|
+
* Request path.
|
|
30
|
+
*/
|
|
31
|
+
path = '/';
|
|
32
|
+
/**
|
|
33
|
+
* Peer address.
|
|
34
|
+
*/
|
|
35
|
+
remoteAddress;
|
|
36
|
+
/**
|
|
37
|
+
* Request ID.
|
|
38
|
+
*/
|
|
39
|
+
requestId;
|
|
40
|
+
/**
|
|
41
|
+
* Reverse proxy support is activated.
|
|
42
|
+
*/
|
|
43
|
+
reverseProxy;
|
|
44
|
+
/**
|
|
45
|
+
* Request URL.
|
|
46
|
+
*/
|
|
47
|
+
url;
|
|
48
|
+
_cookies = undefined;
|
|
49
|
+
_ip = undefined;
|
|
50
|
+
_protocol = undefined;
|
|
51
|
+
_query = undefined;
|
|
52
|
+
_userinfo = undefined;
|
|
12
53
|
constructor(options) {
|
|
13
54
|
super(options.headers, options.body);
|
|
14
|
-
/**
|
|
15
|
-
* Request base path.
|
|
16
|
-
*/
|
|
17
|
-
this.basePath = '';
|
|
18
|
-
/**
|
|
19
|
-
* Request path.
|
|
20
|
-
*/
|
|
21
|
-
this.path = '/';
|
|
22
|
-
this._cookies = undefined;
|
|
23
|
-
this._ip = undefined;
|
|
24
|
-
this._protocol = undefined;
|
|
25
|
-
this._query = undefined;
|
|
26
|
-
this._userinfo = undefined;
|
|
27
55
|
this.method = options.method ?? null;
|
|
28
56
|
const url = (this.url = options.url ?? null);
|
|
29
57
|
const pathMatch = (url ?? '').match(URL_RE);
|
|
@@ -114,4 +142,3 @@ export class ServerRequest extends Body {
|
|
|
114
142
|
return this._userinfo;
|
|
115
143
|
}
|
|
116
144
|
}
|
|
117
|
-
//# sourceMappingURL=request.js.map
|
package/lib/server/response.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { Context } from '../context.
|
|
2
|
-
import type { CookieOptions } from '../types.
|
|
1
|
+
import type { Context } from '../context.ts';
|
|
2
|
+
import type { CookieOptions } from '../types.ts';
|
|
3
3
|
import type { Stream } from 'node:stream';
|
|
4
|
-
import { Headers } from '../headers.
|
|
4
|
+
import { Headers } from '../headers.ts';
|
|
5
5
|
type SendResponse = (res: ServerResponse, body?: string | Buffer | Stream) => void;
|
|
6
6
|
/**
|
|
7
7
|
* Server response class.
|
package/lib/server/response.js
CHANGED
|
@@ -1,27 +1,28 @@
|
|
|
1
|
-
import { stringifyCookie } from
|
|
2
|
-
import { Headers } from
|
|
1
|
+
import { stringifyCookie } from "./cookie.js";
|
|
2
|
+
import { Headers } from "../headers.js";
|
|
3
3
|
/**
|
|
4
4
|
* Server response class.
|
|
5
5
|
*/
|
|
6
6
|
export class ServerResponse {
|
|
7
|
+
/**
|
|
8
|
+
* Response headers.
|
|
9
|
+
*/
|
|
10
|
+
headers = new Headers();
|
|
11
|
+
/**
|
|
12
|
+
* Response has already been sent.
|
|
13
|
+
*/
|
|
14
|
+
isSent = false;
|
|
15
|
+
/**
|
|
16
|
+
* Response status code.
|
|
17
|
+
*/
|
|
18
|
+
statusCode = 200;
|
|
19
|
+
/**
|
|
20
|
+
* Response status message.
|
|
21
|
+
*/
|
|
22
|
+
statusMessage = null;
|
|
23
|
+
_ctx = undefined;
|
|
24
|
+
_sendResponse;
|
|
7
25
|
constructor(sendResponse) {
|
|
8
|
-
/**
|
|
9
|
-
* Response headers.
|
|
10
|
-
*/
|
|
11
|
-
this.headers = new Headers();
|
|
12
|
-
/**
|
|
13
|
-
* Response has already been sent.
|
|
14
|
-
*/
|
|
15
|
-
this.isSent = false;
|
|
16
|
-
/**
|
|
17
|
-
* Response status code.
|
|
18
|
-
*/
|
|
19
|
-
this.statusCode = 200;
|
|
20
|
-
/**
|
|
21
|
-
* Response status message.
|
|
22
|
-
*/
|
|
23
|
-
this.statusMessage = null;
|
|
24
|
-
this._ctx = undefined;
|
|
25
26
|
this._sendResponse = sendResponse;
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
@@ -91,4 +92,3 @@ export class ServerResponse {
|
|
|
91
92
|
return this.set('Content-Type', type);
|
|
92
93
|
}
|
|
93
94
|
}
|
|
94
|
-
//# sourceMappingURL=response.js.map
|
package/lib/server.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type { MojoApp, ServerOptions } from './types.
|
|
1
|
+
import type { MojoApp, ServerOptions } from './types.ts';
|
|
2
2
|
import type { Socket } from 'node:net';
|
|
3
3
|
import http from 'node:http';
|
|
4
4
|
import https from 'node:https';
|
|
5
5
|
import { URL } from 'node:url';
|
|
6
|
-
import { ServerRequest } from './server/request.
|
|
6
|
+
import { ServerRequest } from './server/request.ts';
|
|
7
7
|
import { WebSocketServer } from 'ws';
|
|
8
8
|
type ListenArgs = any[];
|
|
9
9
|
/**
|
|
@@ -28,6 +28,11 @@ export declare class Server {
|
|
|
28
28
|
* Maximum number of requests socket can handle before closing keep alive connection, defaults to `0`.
|
|
29
29
|
*/
|
|
30
30
|
maxRequestsPerSocket: number | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Maximum WebSocket message size in bytes, defaults to `262144` (256 KiB). Connections exceeding the limit are closed
|
|
33
|
+
* with status `1009`.
|
|
34
|
+
*/
|
|
35
|
+
maxWebSocketSize: number;
|
|
31
36
|
/**
|
|
32
37
|
* Limit the amount of time for receiving the entire request from the client, defaults to `300000` (300 seconds).
|
|
33
38
|
*/
|