routup 0.0.1
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/LICENSE +21 -0
- package/README.md +74 -0
- package/dist/constants.d.ts +20 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +31 -0
- package/dist/constants.js.map +1 -0
- package/dist/helpers/index.d.ts +3 -0
- package/dist/helpers/index.d.ts.map +1 -0
- package/dist/helpers/index.js +25 -0
- package/dist/helpers/index.js.map +1 -0
- package/dist/helpers/request/body.d.ts +5 -0
- package/dist/helpers/request/body.d.ts.map +1 -0
- package/dist/helpers/request/body.js +19 -0
- package/dist/helpers/request/body.js.map +1 -0
- package/dist/helpers/request/cache.d.ts +3 -0
- package/dist/helpers/request/cache.d.ts.map +1 -0
- package/dist/helpers/request/cache.js +21 -0
- package/dist/helpers/request/cache.js.map +1 -0
- package/dist/helpers/request/env.d.ts +4 -0
- package/dist/helpers/request/env.d.ts.map +1 -0
- package/dist/helpers/request/env.js +27 -0
- package/dist/helpers/request/env.js.map +1 -0
- package/dist/helpers/request/header-accept-charset.d.ts +7 -0
- package/dist/helpers/request/header-accept-charset.d.ts.map +1 -0
- package/dist/helpers/request/header-accept-charset.js +21 -0
- package/dist/helpers/request/header-accept-charset.js.map +1 -0
- package/dist/helpers/request/header-accept-encoding.d.ts +7 -0
- package/dist/helpers/request/header-accept-encoding.d.ts.map +1 -0
- package/dist/helpers/request/header-accept-encoding.js +21 -0
- package/dist/helpers/request/header-accept-encoding.js.map +1 -0
- package/dist/helpers/request/header-accept-language.d.ts +7 -0
- package/dist/helpers/request/header-accept-language.d.ts.map +1 -0
- package/dist/helpers/request/header-accept-language.js +21 -0
- package/dist/helpers/request/header-accept-language.js.map +1 -0
- package/dist/helpers/request/header-accept.d.ts +7 -0
- package/dist/helpers/request/header-accept.d.ts.map +1 -0
- package/dist/helpers/request/header-accept.js +45 -0
- package/dist/helpers/request/header-accept.js.map +1 -0
- package/dist/helpers/request/header-content-type.d.ts +4 -0
- package/dist/helpers/request/header-content-type.d.ts.map +1 -0
- package/dist/helpers/request/header-content-type.js +28 -0
- package/dist/helpers/request/header-content-type.js.map +1 -0
- package/dist/helpers/request/header.d.ts +5 -0
- package/dist/helpers/request/header.d.ts.map +1 -0
- package/dist/helpers/request/header.js +18 -0
- package/dist/helpers/request/header.js.map +1 -0
- package/dist/helpers/request/index.d.ts +13 -0
- package/dist/helpers/request/index.d.ts.map +1 -0
- package/dist/helpers/request/index.js +35 -0
- package/dist/helpers/request/index.js.map +1 -0
- package/dist/helpers/request/mount-path.d.ts +6 -0
- package/dist/helpers/request/mount-path.d.ts.map +1 -0
- package/dist/helpers/request/mount-path.js +22 -0
- package/dist/helpers/request/mount-path.js.map +1 -0
- package/dist/helpers/request/negotiator.d.ts +5 -0
- package/dist/helpers/request/negotiator.d.ts.map +1 -0
- package/dist/helpers/request/negotiator.js +22 -0
- package/dist/helpers/request/negotiator.js.map +1 -0
- package/dist/helpers/request/params.d.ts +5 -0
- package/dist/helpers/request/params.d.ts.map +1 -0
- package/dist/helpers/request/params.js +25 -0
- package/dist/helpers/request/params.js.map +1 -0
- package/dist/helpers/request/path.d.ts +4 -0
- package/dist/helpers/request/path.d.ts.map +1 -0
- package/dist/helpers/request/path.js +21 -0
- package/dist/helpers/request/path.js.map +1 -0
- package/dist/helpers/response/body.d.ts +7 -0
- package/dist/helpers/response/body.d.ts.map +1 -0
- package/dist/helpers/response/body.js +48 -0
- package/dist/helpers/response/body.js.map +1 -0
- package/dist/helpers/response/cache.d.ts +8 -0
- package/dist/helpers/response/cache.d.ts.map +1 -0
- package/dist/helpers/response/cache.js +25 -0
- package/dist/helpers/response/cache.js.map +1 -0
- package/dist/helpers/response/header-attachment.d.ts +4 -0
- package/dist/helpers/response/header-attachment.d.ts.map +1 -0
- package/dist/helpers/response/header-attachment.js +29 -0
- package/dist/helpers/response/header-attachment.js.map +1 -0
- package/dist/helpers/response/header-content-type.d.ts +4 -0
- package/dist/helpers/response/header-content-type.d.ts.map +1 -0
- package/dist/helpers/response/header-content-type.js +25 -0
- package/dist/helpers/response/header-content-type.js.map +1 -0
- package/dist/helpers/response/header.d.ts +4 -0
- package/dist/helpers/response/header.d.ts.map +1 -0
- package/dist/helpers/response/header.js +39 -0
- package/dist/helpers/response/header.js.map +1 -0
- package/dist/helpers/response/index.d.ts +10 -0
- package/dist/helpers/response/index.d.ts.map +1 -0
- package/dist/helpers/response/index.js +32 -0
- package/dist/helpers/response/index.js.map +1 -0
- package/dist/helpers/response/send-file.d.ts +5 -0
- package/dist/helpers/response/send-file.d.ts.map +1 -0
- package/dist/helpers/response/send-file.js +27 -0
- package/dist/helpers/response/send-file.js.map +1 -0
- package/dist/helpers/response/send-format.d.ts +5 -0
- package/dist/helpers/response/send-format.d.ts.map +1 -0
- package/dist/helpers/response/send-format.js +13 -0
- package/dist/helpers/response/send-format.js.map +1 -0
- package/dist/helpers/response/send-redirect.d.ts +3 -0
- package/dist/helpers/response/send-redirect.d.ts.map +1 -0
- package/dist/helpers/response/send-redirect.js +19 -0
- package/dist/helpers/response/send-redirect.js.map +1 -0
- package/dist/helpers/response/send-stream.d.ts +7 -0
- package/dist/helpers/response/send-stream.d.ts.map +1 -0
- package/dist/helpers/response/send-stream.js +33 -0
- package/dist/helpers/response/send-stream.js.map +1 -0
- package/dist/helpers/response/send.d.ts +3 -0
- package/dist/helpers/response/send.d.ts.map +1 -0
- package/dist/helpers/response/send.js +100 -0
- package/dist/helpers/response/send.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +29 -0
- package/dist/index.js.map +1 -0
- package/dist/layer/index.d.ts +3 -0
- package/dist/layer/index.d.ts.map +1 -0
- package/dist/layer/index.js +25 -0
- package/dist/layer/index.js.map +1 -0
- package/dist/layer/module.d.ts +15 -0
- package/dist/layer/module.d.ts.map +1 -0
- package/dist/layer/module.js +72 -0
- package/dist/layer/module.js.map +1 -0
- package/dist/layer/utils.d.ts +3 -0
- package/dist/layer/utils.d.ts.map +1 -0
- package/dist/layer/utils.js +15 -0
- package/dist/layer/utils.js.map +1 -0
- package/dist/path/index.d.ts +3 -0
- package/dist/path/index.d.ts.map +1 -0
- package/dist/path/index.js +25 -0
- package/dist/path/index.js.map +1 -0
- package/dist/path/matcher.d.ts +13 -0
- package/dist/path/matcher.d.ts.map +1 -0
- package/dist/path/matcher.js +73 -0
- package/dist/path/matcher.js.map +1 -0
- package/dist/path/type.d.ts +5 -0
- package/dist/path/type.d.ts.map +1 -0
- package/dist/path/type.js +9 -0
- package/dist/path/type.js.map +1 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.js +25 -0
- package/dist/route/index.js.map +1 -0
- package/dist/route/module.d.ts +21 -0
- package/dist/route/module.d.ts.map +1 -0
- package/dist/route/module.js +87 -0
- package/dist/route/module.js.map +1 -0
- package/dist/route/utils.d.ts +3 -0
- package/dist/route/utils.d.ts.map +1 -0
- package/dist/route/utils.js +15 -0
- package/dist/route/utils.js.map +1 -0
- package/dist/router/index.d.ts +3 -0
- package/dist/router/index.d.ts.map +1 -0
- package/dist/router/index.js +25 -0
- package/dist/router/index.js.map +1 -0
- package/dist/router/module.d.ts +40 -0
- package/dist/router/module.d.ts.map +1 -0
- package/dist/router/module.js +229 -0
- package/dist/router/module.js.map +1 -0
- package/dist/router/type.d.ts +18 -0
- package/dist/router/type.d.ts.map +1 -0
- package/dist/router/type.js +9 -0
- package/dist/router/type.js.map +1 -0
- package/dist/type.d.ts +25 -0
- package/dist/type.d.ts.map +1 -0
- package/dist/type.js +9 -0
- package/dist/type.js.map +1 -0
- package/dist/utils/index.d.ts +6 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +28 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/is-instance.d.ts +2 -0
- package/dist/utils/is-instance.d.ts.map +1 -0
- package/dist/utils/is-instance.js +16 -0
- package/dist/utils/is-instance.js.map +1 -0
- package/dist/utils/mime.d.ts +2 -0
- package/dist/utils/mime.d.ts.map +1 -0
- package/dist/utils/mime.js +21 -0
- package/dist/utils/mime.js.map +1 -0
- package/dist/utils/path.d.ts +3 -0
- package/dist/utils/path.d.ts.map +1 -0
- package/dist/utils/path.js +14 -0
- package/dist/utils/path.js.map +1 -0
- package/dist/utils/response.d.ts +3 -0
- package/dist/utils/response.d.ts.map +1 -0
- package/dist/utils/response.js +31 -0
- package/dist/utils/response.js.map +1 -0
- package/dist/utils/url.d.ts +8 -0
- package/dist/utils/url.d.ts.map +1 -0
- package/dist/utils/url.js +58 -0
- package/dist/utils/url.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send.d.ts","sourceRoot":"","sources":["../../../src/helpers/response/send.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAItC,wBAAgB,IAAI,CAAC,GAAG,EAAE,QAAQ,EAAE,KAAK,CAAC,EAAE,GAAG,QA+F9C"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.send = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright (c) 2022.
|
|
9
|
+
* Author Peter Placzek (tada5hi)
|
|
10
|
+
* For the full copyright and license information,
|
|
11
|
+
* view the LICENSE file that was distributed with this source code.
|
|
12
|
+
*/
|
|
13
|
+
const etag_1 = __importDefault(require("etag"));
|
|
14
|
+
const constants_1 = require("../../constants");
|
|
15
|
+
const header_1 = require("./header");
|
|
16
|
+
const header_content_type_1 = require("./header-content-type");
|
|
17
|
+
function send(res, chunk) {
|
|
18
|
+
switch (typeof chunk) {
|
|
19
|
+
case 'string': {
|
|
20
|
+
(0, header_content_type_1.setResponseHeaderContentType)(res, 'html', true);
|
|
21
|
+
break;
|
|
22
|
+
}
|
|
23
|
+
case 'boolean':
|
|
24
|
+
case 'number':
|
|
25
|
+
case 'object': {
|
|
26
|
+
if (chunk === null) {
|
|
27
|
+
chunk = '';
|
|
28
|
+
}
|
|
29
|
+
else if (Buffer.isBuffer(chunk)) {
|
|
30
|
+
(0, header_content_type_1.setResponseHeaderContentType)(res, 'bin', true);
|
|
31
|
+
}
|
|
32
|
+
else {
|
|
33
|
+
chunk = JSON.stringify(chunk);
|
|
34
|
+
(0, header_content_type_1.setResponseHeaderContentType)(res, 'application/json', true);
|
|
35
|
+
}
|
|
36
|
+
break;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
let encoding;
|
|
40
|
+
if (typeof chunk === 'string') {
|
|
41
|
+
res.setHeader(constants_1.HeaderName.CONTENT_ENCODING, 'utf-8');
|
|
42
|
+
(0, header_1.appendResponseHeaderDirective)(res, constants_1.HeaderName.CONTENT_TYPE, 'charset=utf-8');
|
|
43
|
+
encoding = 'utf-8';
|
|
44
|
+
}
|
|
45
|
+
// populate Content-Length
|
|
46
|
+
let len;
|
|
47
|
+
if (chunk !== undefined) {
|
|
48
|
+
if (Buffer.isBuffer(chunk)) {
|
|
49
|
+
// get length of Buffer
|
|
50
|
+
len = chunk.length;
|
|
51
|
+
}
|
|
52
|
+
else if (chunk.length < 1000) {
|
|
53
|
+
// just calculate length when no ETag + small chunk
|
|
54
|
+
len = Buffer.byteLength(chunk, encoding);
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
// convert chunk to Buffer and calculate
|
|
58
|
+
chunk = Buffer.from(chunk, encoding);
|
|
59
|
+
encoding = undefined;
|
|
60
|
+
len = chunk.length;
|
|
61
|
+
}
|
|
62
|
+
res.setHeader(constants_1.HeaderName.CONTENT_LENGTH, len);
|
|
63
|
+
}
|
|
64
|
+
// set etag for buffers > 10kb
|
|
65
|
+
if (typeof len !== 'undefined' &&
|
|
66
|
+
len > 10000) {
|
|
67
|
+
const chunkHash = (0, etag_1.default)(chunk, {
|
|
68
|
+
weak: true,
|
|
69
|
+
});
|
|
70
|
+
res.setHeader('ETag', chunkHash);
|
|
71
|
+
if (res.req.headers['if-none-match'] === chunkHash) {
|
|
72
|
+
res.statusCode = 304;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
// strip irrelevant headers
|
|
76
|
+
if (res.statusCode === 204 || res.statusCode === 304) {
|
|
77
|
+
res.removeHeader('Content-Type');
|
|
78
|
+
res.removeHeader('Content-Length');
|
|
79
|
+
res.removeHeader('Transfer-Encoding');
|
|
80
|
+
chunk = '';
|
|
81
|
+
}
|
|
82
|
+
// alter headers for 205
|
|
83
|
+
if (res.statusCode === 205) {
|
|
84
|
+
res.setHeader('Content-Length', 0);
|
|
85
|
+
res.removeHeader('Transfer-Encoding');
|
|
86
|
+
chunk = '';
|
|
87
|
+
}
|
|
88
|
+
if (res.req.method === 'HEAD') {
|
|
89
|
+
// skip body for HEAD
|
|
90
|
+
res.end();
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (typeof encoding !== 'undefined') {
|
|
94
|
+
res.end(chunk, encoding);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
res.end(chunk);
|
|
98
|
+
}
|
|
99
|
+
exports.send = send;
|
|
100
|
+
//# sourceMappingURL=send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"send.js","sourceRoot":"","sources":["../../../src/helpers/response/send.ts"],"names":[],"mappings":";;;;;;AAAA;;;;;GAKG;AACH,gDAAwB;AACxB,+CAA6C;AAE7C,qCAAyD;AACzD,+DAAqE;AAErE,SAAgB,IAAI,CAAC,GAAa,EAAE,KAAW;IAC3C,QAAQ,OAAO,KAAK,EAAE;QAClB,KAAK,QAAQ,CAAC,CAAC;YACX,IAAA,kDAA4B,EAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;Y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AAC,CAAC;AACnB,CAAC;AA/FD,oBA+FC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,cAAc,aAAa,CAAC;AAC5B,cAAc,WAAW,CAAC;AAC1B,cAAc,SAAS,CAAC;AACxB,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./constants"), exports);
|
|
24
|
+
__exportStar(require("./helpers"), exports);
|
|
25
|
+
__exportStar(require("./layer"), exports);
|
|
26
|
+
__exportStar(require("./router"), exports);
|
|
27
|
+
__exportStar(require("./route"), exports);
|
|
28
|
+
__exportStar(require("./type"), exports);
|
|
29
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,8CAA4B;AAC5B,4CAA0B;AAC1B,0CAAwB;AACxB,2CAAyB;AACzB,0CAAwB;AACxB,yCAAuB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/layer/index.ts"],"names":[],"mappings":"AAOA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./module"), exports);
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/layer/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { ParseOptions, TokensToRegexpOptions } from 'path-to-regexp';
|
|
2
|
+
import { PathMatcher } from '../path';
|
|
3
|
+
import { DispatcherMeta, Path, Request, Response } from '../type';
|
|
4
|
+
export declare class Layer {
|
|
5
|
+
readonly '@instanceof': symbol;
|
|
6
|
+
protected fn: CallableFunction;
|
|
7
|
+
protected pathMatcher: PathMatcher;
|
|
8
|
+
constructor(path: Path, options: TokensToRegexpOptions & ParseOptions, fn: CallableFunction);
|
|
9
|
+
isError(): boolean;
|
|
10
|
+
dispatch(req: Request, res: Response, meta: DispatcherMeta, next: CallableFunction): void;
|
|
11
|
+
dispatch(req: Request, res: Response, meta: DispatcherMeta, next: CallableFunction, err: Error): void;
|
|
12
|
+
matchPath(path: string): boolean;
|
|
13
|
+
exec(path: string): import("../path").PathMatcherExecResult | undefined;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/layer/module.ts"],"names":[],"mappings":"AAQA,OAAO,EACH,YAAY,EAAE,qBAAqB,EACtC,MAAM,gBAAgB,CAAC;AAExB,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EACH,cAAc,EAAQ,IAAI,EAAE,OAAO,EAAE,QAAQ,EAChD,MAAM,SAAS,CAAC;AAEjB,qBAAa,KAAK;IACd,QAAQ,CAAC,aAAa,SAAuB;IAE7C,SAAS,CAAC,EAAE,EAAG,gBAAgB,CAAC;IAEhC,SAAS,CAAC,WAAW,EAAG,WAAW,CAAC;gBAKhC,IAAI,EAAE,IAAI,EACV,OAAO,EAAE,qBAAqB,GAAG,YAAY,EAC7C,EAAE,EAAE,gBAAgB;IAQxB,OAAO;IAMP,QAAQ,CACJ,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,gBAAgB,GACtB,IAAI;IAER,QAAQ,CACJ,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,gBAAgB,EACtB,GAAG,EAAE,KAAK,GACV,IAAI;IAoDR,SAAS,CAAC,IAAI,EAAE,MAAM,GAAI,OAAO;IAIjC,IAAI,CAAC,IAAI,EAAE,MAAM;CAGpB"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Layer = void 0;
|
|
10
|
+
const http_1 = require("@ebec/http");
|
|
11
|
+
const helpers_1 = require("../helpers");
|
|
12
|
+
const path_1 = require("../path");
|
|
13
|
+
class Layer {
|
|
14
|
+
// --------------------------------------------------
|
|
15
|
+
constructor(path, options, fn) {
|
|
16
|
+
this['@instanceof'] = Symbol.for('Layer');
|
|
17
|
+
this.pathMatcher = new path_1.PathMatcher(path, options);
|
|
18
|
+
this.fn = fn;
|
|
19
|
+
}
|
|
20
|
+
// --------------------------------------------------
|
|
21
|
+
isError() {
|
|
22
|
+
return this.fn.length === 4;
|
|
23
|
+
}
|
|
24
|
+
dispatch(req, res, meta, next, err) {
|
|
25
|
+
(0, helpers_1.setRequestParams)(req, meta.params || {});
|
|
26
|
+
if (typeof err !== 'undefined') {
|
|
27
|
+
if (this.fn.length === 4) {
|
|
28
|
+
try {
|
|
29
|
+
this.fn(err, req, res, next);
|
|
30
|
+
}
|
|
31
|
+
catch (e) {
|
|
32
|
+
/* istanbul ignore next */
|
|
33
|
+
next(err);
|
|
34
|
+
}
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
/* istanbul ignore next */
|
|
38
|
+
next(err);
|
|
39
|
+
/* istanbul ignore next */
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
/* istanbul ignore next */
|
|
43
|
+
if (this.fn.length > 3) {
|
|
44
|
+
next();
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
const output = this.fn(req, res, next);
|
|
49
|
+
if (output instanceof Promise) {
|
|
50
|
+
output.catch((e) => next(e));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
catch (e) {
|
|
54
|
+
/* istanbul ignore next */
|
|
55
|
+
if (e instanceof Error) {
|
|
56
|
+
next(e);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
next(new http_1.InternalServerError());
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
// --------------------------------------------------
|
|
64
|
+
matchPath(path) {
|
|
65
|
+
return this.pathMatcher.test(path);
|
|
66
|
+
}
|
|
67
|
+
exec(path) {
|
|
68
|
+
return this.pathMatcher.exec(path);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
exports.Layer = Layer;
|
|
72
|
+
//# sourceMappingURL=module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/layer/module.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,qCAAiD;AAIjD,wCAA8C;AAC9C,kCAAsC;AAKtC,MAAa,KAAK;IAOd,qDAAqD;IAErD,YACI,IAAU,EACV,OAA6C,EAC7C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ACR,0BAA0B;YAC1B,IAAI,CAAC,YAAY,KAAK,EAAE;gBACpB,IAAI,CAAC,CAAC,CAAC,CAAC;aACX;iBAAM;gBACH,IAAI,CAAC,IAAI,0BAAmB,EAAE,CAAC,CAAC;aACnC;SACJ;IACL,CAAC;IAED,qDAAqD;IAErD,SAAS,CAAC,IAAY;QAClB,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;IAED,IAAI,CAAC,IAAY;QACb,OAAO,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvC,CAAC;CACJ;AAlGD,sBAkGC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/layer/utils.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAEjC,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAI,KAAK,IAAI,KAAK,CAE/D"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.isLayerInstance = void 0;
|
|
10
|
+
const utils_1 = require("../utils");
|
|
11
|
+
function isLayerInstance(input) {
|
|
12
|
+
return (0, utils_1.isInstance)(input, 'Layer');
|
|
13
|
+
}
|
|
14
|
+
exports.isLayerInstance = isLayerInstance;
|
|
15
|
+
//# sourceMappingURL=utils.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/layer/utils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,oCAAsC;AAGtC,SAAgB,eAAe,CAAC,KAAc;IAC1C,OAAO,IAAA,kBAAU,EAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACtC,CAAC;AAFD,0CAEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/path/index.ts"],"names":[],"mappings":"AAOA,cAAc,WAAW,CAAC;AAC1B,cAAc,QAAQ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./matcher"), exports);
|
|
24
|
+
__exportStar(require("./type"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/path/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,4CAA0B;AAC1B,yCAAuB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Key, ParseOptions, TokensToRegexpOptions } from 'path-to-regexp';
|
|
2
|
+
import { Path } from '../type';
|
|
3
|
+
import { PathMatcherExecResult } from './type';
|
|
4
|
+
export declare class PathMatcher {
|
|
5
|
+
path: Path;
|
|
6
|
+
regexp: RegExp;
|
|
7
|
+
regexpKeys: Key[];
|
|
8
|
+
regexpOptions: TokensToRegexpOptions & ParseOptions;
|
|
9
|
+
constructor(path: Path, options?: TokensToRegexpOptions & ParseOptions);
|
|
10
|
+
test(path: string): boolean;
|
|
11
|
+
exec(path: string): PathMatcherExecResult | undefined;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=matcher.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matcher.d.ts","sourceRoot":"","sources":["../../src/path/matcher.ts"],"names":[],"mappings":"AAOA,OAAO,EACH,GAAG,EAAE,YAAY,EAAE,qBAAqB,EAC3C,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,IAAI,EAAE,MAAM,SAAS,CAAC;AAC/B,OAAO,EAAE,qBAAqB,EAAE,MAAM,QAAQ,CAAC;AAU/C,qBAAa,WAAW;IACpB,IAAI,EAAE,IAAI,CAAC;IAEX,MAAM,EAAG,MAAM,CAAC;IAEhB,UAAU,EAAG,GAAG,EAAE,CAAM;IAExB,aAAa,EAAE,qBAAqB,GAAG,YAAY,CAAC;gBAExC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,qBAAqB,GAAG,YAAY;IAWtE,IAAI,CAAC,IAAI,EAAE,MAAM;IASjB,IAAI,CAAC,IAAI,EAAE,MAAM,GAAI,qBAAqB,GAAG,SAAS;CA2CzD"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.PathMatcher = void 0;
|
|
10
|
+
const path_to_regexp_1 = require("path-to-regexp");
|
|
11
|
+
function decodeParam(val) {
|
|
12
|
+
if (typeof val !== 'string' || val.length === 0) {
|
|
13
|
+
return val;
|
|
14
|
+
}
|
|
15
|
+
return decodeURIComponent(val);
|
|
16
|
+
}
|
|
17
|
+
class PathMatcher {
|
|
18
|
+
constructor(path, options) {
|
|
19
|
+
this.regexpKeys = [];
|
|
20
|
+
this.path = path;
|
|
21
|
+
this.regexpOptions = options || {};
|
|
22
|
+
if (path instanceof RegExp) {
|
|
23
|
+
this.regexp = path;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
this.regexp = (0, path_to_regexp_1.pathToRegexp)(path, this.regexpKeys, options);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
test(path) {
|
|
30
|
+
const fastSlash = this.path === '/' && this.regexpOptions.end === false;
|
|
31
|
+
if (fastSlash) {
|
|
32
|
+
return true;
|
|
33
|
+
}
|
|
34
|
+
return this.regexp.test(path);
|
|
35
|
+
}
|
|
36
|
+
exec(path) {
|
|
37
|
+
let match = null;
|
|
38
|
+
const fastSlash = this.path === '/' && this.regexpOptions.end === false;
|
|
39
|
+
if (fastSlash) {
|
|
40
|
+
return {
|
|
41
|
+
path: '/',
|
|
42
|
+
params: {},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
match = this.regexp.exec(path);
|
|
46
|
+
if (!match) {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
if (this.path instanceof RegExp) {
|
|
50
|
+
return {
|
|
51
|
+
path,
|
|
52
|
+
params: {
|
|
53
|
+
0: decodeParam(match[0]),
|
|
54
|
+
},
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
const output = {};
|
|
58
|
+
for (let i = 1; i < match.length; i++) {
|
|
59
|
+
const key = this.regexpKeys[i - 1];
|
|
60
|
+
const prop = key.name;
|
|
61
|
+
const val = decodeParam(match[i]);
|
|
62
|
+
if (typeof val !== 'undefined') {
|
|
63
|
+
output[prop] = val;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
path: match[0],
|
|
68
|
+
params: output,
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
exports.PathMatcher = PathMatcher;
|
|
73
|
+
//# sourceMappingURL=matcher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"matcher.js","sourceRoot":"","sources":["../../src/path/matcher.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,mDAEwB;AAIxB,SAAS,WAAW,CAAC,GAAY;IAC7B,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,KAAK,CAAC,EAAE;QAC7C,OAAO,GAAG,CAAC;KACd;IAED,OAAO,kBAAkB,CAAC,GAAG,CAAC,CAAC;AACnC,CAAC;AAED,MAAa,WAAW;IASpB,YAAY,IAAU,EAAE,OAA8C;QAJtE,eAAU,GAAW,EAAE,CAAC;QAKpB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;QACjB,IAAI,CAAC,aAAa,GAAG,OAAO,IAAI,EAAE,CAAC;QAEnC,IAAI,IAAI,YAAY,MAAM,EAAE;YACxB,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;SACtB;aAAM;YACH,IAAI,CAAC,MAAM,GAAG,IAAA,6BAAY,EAAC,IAAI,EAAE,IAAI,CAAC,UAAU,EAAE,OAAO,CAAC,CAAC;SAC9D;IACL,CAAC;IAED,IAAI,CAAC,IAAY;QACb,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,KAAK,GAAG,IAAI,IAAI,CAAC,aAAa,C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,EAAE,MAAM;SACjB,CAAC;IACN,CAAC;CACJ;AAxED,kCAwEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.d.ts","sourceRoot":"","sources":["../../src/path/type.ts"],"names":[],"mappings":"AAOA,oBAAY,qBAAqB,GAAG;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC9B,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
//# sourceMappingURL=type.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type.js","sourceRoot":"","sources":["../../src/path/type.ts"],"names":[],"mappings":";AAAA;;;;;GAKG"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":"AAOA,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./module"), exports);
|
|
24
|
+
__exportStar(require("./utils"), exports);
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/route/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;;;;;;;;;;;AAEH,2CAAyB;AACzB,0CAAwB"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Method } from '../constants';
|
|
2
|
+
import { Layer } from '../layer';
|
|
3
|
+
import { PathMatcher } from '../path';
|
|
4
|
+
import { DispatcherMeta, Handler, Next, Path, Request, Response } from '../type';
|
|
5
|
+
export declare class Route {
|
|
6
|
+
readonly '@instanceof': symbol;
|
|
7
|
+
path: Path;
|
|
8
|
+
protected pathMatcher: PathMatcher;
|
|
9
|
+
protected layers: Record<string, Layer[]>;
|
|
10
|
+
constructor(path: Path);
|
|
11
|
+
matchPath(path: string): boolean;
|
|
12
|
+
matchMethod(method: string): boolean;
|
|
13
|
+
dispatch(req: Request, res: Response, meta: DispatcherMeta, done: Next): void;
|
|
14
|
+
register(method: `${Method}`, ...handlers: Handler[]): void;
|
|
15
|
+
get(...handlers: Handler[]): void;
|
|
16
|
+
post(...handlers: Handler[]): void;
|
|
17
|
+
put(...handlers: Handler[]): void;
|
|
18
|
+
patch(...handlers: Handler[]): void;
|
|
19
|
+
delete(...handlers: Handler[]): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/route/module.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AACtC,OAAO,EACH,cAAc,EACd,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EACzC,MAAM,SAAS,CAAC;AAEjB,qBAAa,KAAK;IACd,QAAQ,CAAC,aAAa,SAAuB;IAEtC,IAAI,EAAG,IAAI,CAAC;IAEnB,SAAS,CAAC,WAAW,EAAG,WAAW,CAAC;IAEpC,SAAS,CAAC,MAAM,EAAG,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,CAAC,CAAM;gBAIpC,IAAI,EAAE,IAAI;IAQtB,SAAS,CAAC,IAAI,EAAE,MAAM,GAAI,OAAO;IAIjC,WAAW,CAAC,MAAM,EAAE,MAAM,GAAI,OAAO;IAMrC,QAAQ,CACJ,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,QAAQ,EACb,IAAI,EAAE,cAAc,EACpB,IAAI,EAAE,IAAI,GACV,IAAI;IA+CR,QAAQ,CAAC,MAAM,EAAE,GAAG,MAAM,EAAE,EAAE,GAAG,QAAQ,EAAE,OAAO,EAAE;IAgBpD,GAAG,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI1B,IAAI,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI3B,GAAG,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI1B,KAAK,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;IAI5B,MAAM,CAAC,GAAG,QAAQ,EAAE,OAAO,EAAE;CAGhC"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2022.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.Route = void 0;
|
|
10
|
+
const smob_1 = require("smob");
|
|
11
|
+
const constants_1 = require("../constants");
|
|
12
|
+
const layer_1 = require("../layer");
|
|
13
|
+
const path_1 = require("../path");
|
|
14
|
+
class Route {
|
|
15
|
+
// --------------------------------------------------
|
|
16
|
+
constructor(path) {
|
|
17
|
+
this['@instanceof'] = Symbol.for('Route');
|
|
18
|
+
this.layers = {};
|
|
19
|
+
this.path = path;
|
|
20
|
+
this.pathMatcher = new path_1.PathMatcher(path);
|
|
21
|
+
}
|
|
22
|
+
// --------------------------------------------------
|
|
23
|
+
matchPath(path) {
|
|
24
|
+
return this.pathMatcher.test(path);
|
|
25
|
+
}
|
|
26
|
+
matchMethod(method) {
|
|
27
|
+
return Object.prototype.hasOwnProperty.call(this.layers, method.toLowerCase());
|
|
28
|
+
}
|
|
29
|
+
// --------------------------------------------------
|
|
30
|
+
dispatch(req, res, meta, done) {
|
|
31
|
+
if (!req.method) {
|
|
32
|
+
done();
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const name = req.method.toLowerCase();
|
|
36
|
+
const layers = this.layers[name];
|
|
37
|
+
if (typeof layers === 'undefined' ||
|
|
38
|
+
layers.length === 0 ||
|
|
39
|
+
typeof meta.path === 'undefined') {
|
|
40
|
+
done();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
const layerMeta = Object.assign({}, meta);
|
|
44
|
+
const output = this.pathMatcher.exec(meta.path);
|
|
45
|
+
if (output) {
|
|
46
|
+
layerMeta.params = (0, smob_1.merge)({}, (meta.params || {}), output.params);
|
|
47
|
+
}
|
|
48
|
+
let index = -1;
|
|
49
|
+
const next = (err) => {
|
|
50
|
+
index++;
|
|
51
|
+
if (index >= layers.length) {
|
|
52
|
+
setImmediate(() => done(err));
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const layer = layers[index];
|
|
56
|
+
layer.dispatch(req, res, Object.assign({}, layerMeta), next);
|
|
57
|
+
};
|
|
58
|
+
next();
|
|
59
|
+
}
|
|
60
|
+
// --------------------------------------------------
|
|
61
|
+
register(method, ...handlers) {
|
|
62
|
+
this.layers[method] = [];
|
|
63
|
+
for (let i = 0; i < handlers.length; i++) {
|
|
64
|
+
const layer = new layer_1.Layer(this.path, {
|
|
65
|
+
end: true,
|
|
66
|
+
}, handlers[i]);
|
|
67
|
+
this.layers[method].push(layer);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
get(...handlers) {
|
|
71
|
+
return this.register(constants_1.Method.GET, ...handlers);
|
|
72
|
+
}
|
|
73
|
+
post(...handlers) {
|
|
74
|
+
return this.register(constants_1.Method.POST, ...handlers);
|
|
75
|
+
}
|
|
76
|
+
put(...handlers) {
|
|
77
|
+
return this.register(constants_1.Method.PUT, ...handlers);
|
|
78
|
+
}
|
|
79
|
+
patch(...handlers) {
|
|
80
|
+
return this.register(constants_1.Method.PATCH, ...handlers);
|
|
81
|
+
}
|
|
82
|
+
delete(...handlers) {
|
|
83
|
+
return this.register(constants_1.Method.DELETE, ...handlers);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
exports.Route = Route;
|
|
87
|
+
//# sourceMappingURL=module.js.map
|