routup 0.11.0 → 0.12.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.
@@ -0,0 +1,21 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ _exportStar(require("./utils"), exports);
11
+ function _exportStar(from, to) {
12
+ Object.keys(from).forEach(function(k) {
13
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
14
+ enumerable: true,
15
+ get: function() {
16
+ return from[k];
17
+ }
18
+ });
19
+ });
20
+ return from;
21
+ }
@@ -0,0 +1,29 @@
1
+ /*
2
+ * Copyright (c) 2022-2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "processHandlerExecutionOutput", {
11
+ enumerable: true,
12
+ get: ()=>processHandlerExecutionOutput
13
+ });
14
+ const _core = require("@routup/core");
15
+ const _utils = require("../utils");
16
+ function processHandlerExecutionOutput(res, next, output) {
17
+ if ((0, _utils.isPromise)(output)) {
18
+ output.then((r)=>{
19
+ if (typeof r !== 'undefined') {
20
+ (0, _core.send)(res, r);
21
+ }
22
+ return r;
23
+ }).catch(next);
24
+ return;
25
+ }
26
+ if (typeof output !== 'undefined') {
27
+ (0, _core.send)(res, output);
28
+ }
29
+ }
package/dist/index.js ADDED
@@ -0,0 +1,28 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ _exportStar(require("./handler"), exports);
11
+ _exportStar(require("./layer"), exports);
12
+ _exportStar(require("./path"), exports);
13
+ _exportStar(require("./route"), exports);
14
+ _exportStar(require("./router"), exports);
15
+ _exportStar(require("./type"), exports);
16
+ _exportStar(require("./utils"), exports);
17
+ _exportStar(require("@routup/core"), exports);
18
+ function _exportStar(from, to) {
19
+ Object.keys(from).forEach(function(k) {
20
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
21
+ enumerable: true,
22
+ get: function() {
23
+ return from[k];
24
+ }
25
+ });
26
+ });
27
+ return from;
28
+ }
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ _exportStar(require("./module"), exports);
11
+ _exportStar(require("./type"), exports);
12
+ _exportStar(require("./utils"), exports);
13
+ function _exportStar(from, to) {
14
+ Object.keys(from).forEach(function(k) {
15
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
16
+ enumerable: true,
17
+ get: function() {
18
+ return from[k];
19
+ }
20
+ });
21
+ });
22
+ return from;
23
+ }
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "Layer", {
11
+ enumerable: true,
12
+ get: ()=>Layer
13
+ });
14
+ const _http = require("@ebec/http");
15
+ const _core = require("@routup/core");
16
+ const _handler = require("../handler");
17
+ const _path = require("../path");
18
+ class Layer {
19
+ // --------------------------------------------------
20
+ isError() {
21
+ return this.fn.length === 4;
22
+ }
23
+ dispatch(req, res, meta, next, err) {
24
+ (0, _core.setRequestParams)(req, meta.params || {});
25
+ (0, _core.setRequestMountPath)(req, meta.mountPath || '/');
26
+ if (typeof err !== 'undefined') {
27
+ if (this.fn.length === 4) {
28
+ try {
29
+ this.fn(err, req, res, next);
30
+ } catch (e) {
31
+ /* istanbul ignore next */ /* istanbul ignore next */ if (e instanceof Error) {
32
+ next(e);
33
+ } else {
34
+ next(new _http.BadRequestError({
35
+ message: 'The request could not be processed by the error handler.'
36
+ }));
37
+ }
38
+ }
39
+ return;
40
+ }
41
+ /* istanbul ignore next */ next(err);
42
+ /* istanbul ignore next */ return;
43
+ }
44
+ /* istanbul ignore next */ if (this.fn.length > 3) {
45
+ next();
46
+ return;
47
+ }
48
+ try {
49
+ const output = this.fn(req, res, next);
50
+ (0, _handler.processHandlerExecutionOutput)(res, next, output);
51
+ } catch (e) {
52
+ /* istanbul ignore next */ if (e instanceof Error) {
53
+ next(e);
54
+ } else {
55
+ next(new _http.BadRequestError({
56
+ message: 'The request could not be processed by the handler.'
57
+ }));
58
+ }
59
+ }
60
+ }
61
+ // --------------------------------------------------
62
+ matchPath(path) {
63
+ return this.pathMatcher.test(path);
64
+ }
65
+ exec(path) {
66
+ return this.pathMatcher.exec(path);
67
+ }
68
+ // --------------------------------------------------
69
+ constructor(options, fn){
70
+ this['@instanceof'] = Symbol.for('Layer');
71
+ this.pathMatcher = new _path.PathMatcher(options.path, options.pathMatcher);
72
+ this.fn = fn;
73
+ }
74
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "isLayerInstance", {
11
+ enumerable: true,
12
+ get: ()=>isLayerInstance
13
+ });
14
+ const _utils = require("../utils");
15
+ function isLayerInstance(input) {
16
+ return (0, _utils.isInstance)(input, 'Layer');
17
+ }
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ _exportStar(require("./matcher"), exports);
11
+ _exportStar(require("./type"), exports);
12
+ function _exportStar(from, to) {
13
+ Object.keys(from).forEach(function(k) {
14
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
15
+ enumerable: true,
16
+ get: function() {
17
+ return from[k];
18
+ }
19
+ });
20
+ });
21
+ return from;
22
+ }
@@ -0,0 +1,74 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "PathMatcher", {
11
+ enumerable: true,
12
+ get: ()=>PathMatcher
13
+ });
14
+ const _pathToRegexp = require("path-to-regexp");
15
+ function decodeParam(val) {
16
+ /* istanbul ignore next */ if (typeof val !== 'string' || val.length === 0) {
17
+ return val;
18
+ }
19
+ return decodeURIComponent(val);
20
+ }
21
+ class PathMatcher {
22
+ test(path) {
23
+ const fastSlash = this.path === '/' && this.regexpOptions.end === false;
24
+ if (fastSlash) {
25
+ return true;
26
+ }
27
+ return this.regexp.test(path);
28
+ }
29
+ exec(path) {
30
+ let match = null;
31
+ const fastSlash = this.path === '/' && this.regexpOptions.end === false;
32
+ if (fastSlash) {
33
+ return {
34
+ path: '/',
35
+ params: {}
36
+ };
37
+ }
38
+ match = this.regexp.exec(path);
39
+ if (!match) {
40
+ return undefined;
41
+ }
42
+ if (this.path instanceof RegExp) {
43
+ return {
44
+ path,
45
+ params: {
46
+ 0: decodeParam(match[0])
47
+ }
48
+ };
49
+ }
50
+ const output = {};
51
+ for(let i = 1; i < match.length; i++){
52
+ const key = this.regexpKeys[i - 1];
53
+ const prop = key.name;
54
+ const val = decodeParam(match[i]);
55
+ if (typeof val !== 'undefined') {
56
+ output[prop] = val;
57
+ }
58
+ }
59
+ return {
60
+ path: match[0],
61
+ params: output
62
+ };
63
+ }
64
+ constructor(path, options){
65
+ this.regexpKeys = [];
66
+ this.path = path;
67
+ this.regexpOptions = options || {};
68
+ if (path instanceof RegExp) {
69
+ this.regexp = path;
70
+ } else {
71
+ this.regexp = (0, _pathToRegexp.pathToRegexp)(path, this.regexpKeys, options);
72
+ }
73
+ }
74
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
@@ -0,0 +1,23 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ _exportStar(require("./module"), exports);
11
+ _exportStar(require("./type"), exports);
12
+ _exportStar(require("./utils"), exports);
13
+ function _exportStar(from, to) {
14
+ Object.keys(from).forEach(function(k) {
15
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
16
+ enumerable: true,
17
+ get: function() {
18
+ return from[k];
19
+ }
20
+ });
21
+ });
22
+ return from;
23
+ }
@@ -0,0 +1,135 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "Route", {
11
+ enumerable: true,
12
+ get: ()=>Route
13
+ });
14
+ const _smob = require("smob");
15
+ const _core = require("@routup/core");
16
+ const _layer = require("../layer");
17
+ const _path = require("../path");
18
+ function _extends() {
19
+ _extends = Object.assign || function(target) {
20
+ for(var i = 1; i < arguments.length; i++){
21
+ var source = arguments[i];
22
+ for(var key in source){
23
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
24
+ target[key] = source[key];
25
+ }
26
+ }
27
+ }
28
+ return target;
29
+ };
30
+ return _extends.apply(this, arguments);
31
+ }
32
+ class Route {
33
+ // --------------------------------------------------
34
+ matchPath(path) {
35
+ return this.pathMatcher.test(path);
36
+ }
37
+ matchMethod(method) {
38
+ let name = method.toLowerCase();
39
+ if (name === _core.Method.HEAD && !(0, _smob.hasOwnProperty)(this.layers, name)) {
40
+ name = _core.Method.GET;
41
+ }
42
+ return Object.prototype.hasOwnProperty.call(this.layers, name);
43
+ }
44
+ // --------------------------------------------------
45
+ getMethods() {
46
+ const keys = Object.keys(this.layers);
47
+ if ((0, _smob.hasOwnProperty)(this.layers, _core.Method.GET) && !(0, _smob.hasOwnProperty)(this.layers, _core.Method.HEAD)) {
48
+ keys.push(_core.Method.HEAD);
49
+ }
50
+ return keys;
51
+ }
52
+ // --------------------------------------------------
53
+ dispatch(req, res, meta, done) {
54
+ /* istanbul ignore next */ if (!req.method) {
55
+ done();
56
+ return;
57
+ }
58
+ let name = req.method.toLowerCase();
59
+ if (name === _core.Method.HEAD && !(0, _smob.hasOwnProperty)(this.layers, name)) {
60
+ name = _core.Method.GET;
61
+ }
62
+ const layers = this.layers[name];
63
+ /* istanbul ignore next */ if (typeof layers === 'undefined' || layers.length === 0 || typeof meta.path === 'undefined') {
64
+ done();
65
+ return;
66
+ }
67
+ const layerMeta = _extends({}, meta);
68
+ const output = this.pathMatcher.exec(meta.path);
69
+ if (output) {
70
+ layerMeta.params = (0, _smob.merge)({}, meta.params || {}, output.params);
71
+ }
72
+ let index = -1;
73
+ const next = (err)=>{
74
+ index++;
75
+ if (index >= layers.length) {
76
+ setImmediate(done, err);
77
+ return;
78
+ }
79
+ const layer = layers[index];
80
+ if (err && !layer.isError()) {
81
+ next(err);
82
+ return;
83
+ }
84
+ layer.dispatch(req, res, _extends({}, layerMeta), next);
85
+ };
86
+ next();
87
+ }
88
+ // --------------------------------------------------
89
+ register(method, ...handlers) {
90
+ this.layers[method] = [];
91
+ for(let i = 0; i < handlers.length; i++){
92
+ const layer = new _layer.Layer({
93
+ path: this.path,
94
+ pathMatcher: this.pathMatcherOptions
95
+ }, handlers[i]);
96
+ this.layers[method].push(layer);
97
+ }
98
+ }
99
+ get(...handlers) {
100
+ return this.register(_core.Method.GET, ...handlers);
101
+ }
102
+ post(...handlers) {
103
+ return this.register(_core.Method.POST, ...handlers);
104
+ }
105
+ put(...handlers) {
106
+ return this.register(_core.Method.PUT, ...handlers);
107
+ }
108
+ patch(...handlers) {
109
+ return this.register(_core.Method.PATCH, ...handlers);
110
+ }
111
+ delete(...handlers) {
112
+ return this.register(_core.Method.DELETE, ...handlers);
113
+ }
114
+ head(...handlers) {
115
+ return this.register(_core.Method.HEAD, ...handlers);
116
+ }
117
+ options(...handlers) {
118
+ return this.register(_core.Method.OPTIONS, ...handlers);
119
+ }
120
+ // --------------------------------------------------
121
+ isStrictPath() {
122
+ return typeof this.path !== 'string' || this.path !== '/' && this.path.length !== 0;
123
+ }
124
+ // --------------------------------------------------
125
+ constructor(options){
126
+ this['@instanceof'] = Symbol.for('Route');
127
+ this.layers = {};
128
+ this.path = options.path;
129
+ this.pathMatcherOptions = _extends({
130
+ end: true,
131
+ strict: this.isStrictPath()
132
+ }, options.pathMatcher);
133
+ this.pathMatcher = new _path.PathMatcher(this.path, this.pathMatcherOptions);
134
+ }
135
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
@@ -0,0 +1,17 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "isRouteInstance", {
11
+ enumerable: true,
12
+ get: ()=>isRouteInstance
13
+ });
14
+ const _utils = require("../utils");
15
+ function isRouteInstance(input) {
16
+ return (0, _utils.isInstance)(input, 'Route');
17
+ }
@@ -0,0 +1,22 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ _exportStar(require("./module"), exports);
11
+ _exportStar(require("./type"), exports);
12
+ function _exportStar(from, to) {
13
+ Object.keys(from).forEach(function(k) {
14
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
15
+ enumerable: true,
16
+ get: function() {
17
+ return from[k];
18
+ }
19
+ });
20
+ });
21
+ return from;
22
+ }
@@ -0,0 +1,294 @@
1
+ /*
2
+ * Copyright (c) 2022-2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ function _export(target, all) {
11
+ for(var name in all)Object.defineProperty(target, name, {
12
+ enumerable: true,
13
+ get: all[name]
14
+ });
15
+ }
16
+ _export(exports, {
17
+ isRouterInstance: ()=>isRouterInstance,
18
+ Router: ()=>Router
19
+ });
20
+ const _http = require("@ebec/http");
21
+ const _http1 = require("http");
22
+ const _smob = require("smob");
23
+ const _core = require("@routup/core");
24
+ const _path = require("../path");
25
+ const _utils = require("../utils");
26
+ const _layer = require("../layer");
27
+ const _route = require("../route");
28
+ function _extends() {
29
+ _extends = Object.assign || function(target) {
30
+ for(var i = 1; i < arguments.length; i++){
31
+ var source = arguments[i];
32
+ for(var key in source){
33
+ if (Object.prototype.hasOwnProperty.call(source, key)) {
34
+ target[key] = source[key];
35
+ }
36
+ }
37
+ }
38
+ return target;
39
+ };
40
+ return _extends.apply(this, arguments);
41
+ }
42
+ function isRouterInstance(input) {
43
+ return (0, _utils.isInstance)(input, 'Router');
44
+ }
45
+ class Router {
46
+ // --------------------------------------------------
47
+ setPathMatcherOptions(input) {
48
+ this.pathMatcherOptions = input;
49
+ if (this.pathMatcher) {
50
+ this.pathMatcher.regexpOptions = this.pathMatcherOptions;
51
+ }
52
+ }
53
+ setPath(value) {
54
+ if (value === '/' || !(0, _utils.isPath)(value)) {
55
+ this.path = '/';
56
+ return;
57
+ }
58
+ if (typeof value === 'string') {
59
+ this.path = (0, _core.withLeadingSlash)((0, _core.withoutTrailingSlash)(`${value}`));
60
+ } else {
61
+ this.path = value;
62
+ }
63
+ this.pathMatcher = new _path.PathMatcher(this.path, this.pathMatcherOptions);
64
+ }
65
+ // --------------------------------------------------
66
+ createListener() {
67
+ this.isRoot = true;
68
+ return (req, res)=>{
69
+ this.dispatch(req, res);
70
+ };
71
+ }
72
+ /* istanbul ignore next */ listen(port) {
73
+ const server = (0, _http1.createServer)(this.createListener());
74
+ return server.listen(port);
75
+ }
76
+ // --------------------------------------------------
77
+ matchPath(path) {
78
+ if (this.pathMatcher) {
79
+ return this.pathMatcher.test(path);
80
+ }
81
+ return true;
82
+ }
83
+ // --------------------------------------------------
84
+ dispatch(req, res, meta, done) {
85
+ let index = -1;
86
+ meta = meta || {};
87
+ let allowedMethods = [];
88
+ if (this.isRoot && typeof this.timeout === 'number') {
89
+ (0, _utils.createRequestTimeout)(res, this.timeout, done);
90
+ }
91
+ const fn = (err)=>{
92
+ /* istanbul ignore if */ if (!this.isRoot) {
93
+ if (typeof done !== 'undefined') {
94
+ setImmediate(()=>done(err));
95
+ }
96
+ return;
97
+ }
98
+ if (typeof err !== 'undefined') {
99
+ res.statusCode = _http.BadRequestErrorOptions.statusCode;
100
+ res.statusMessage = _http.BadRequestErrorOptions.message;
101
+ res.end();
102
+ return;
103
+ }
104
+ if (req.method && req.method.toLowerCase() === _core.Method.OPTIONS) {
105
+ const options = allowedMethods.map((key)=>key.toUpperCase()).join(',');
106
+ res.setHeader(_core.HeaderName.ALLOW, options);
107
+ (0, _core.send)(res, options);
108
+ return;
109
+ }
110
+ res.statusCode = _http.NotFoundErrorOptions.statusCode;
111
+ res.end();
112
+ };
113
+ let path = meta.path || (0, _core.useRequestPath)(req);
114
+ if (this.pathMatcher) {
115
+ const output = this.pathMatcher.exec(path);
116
+ if (typeof output !== 'undefined') {
117
+ meta.mountPath = (0, _core.cleanDoubleSlashes)(`${meta.mountPath || ''}/${output.path}`);
118
+ if (path === output.path) {
119
+ path = '/';
120
+ } else {
121
+ path = (0, _core.withLeadingSlash)(path.substring(output.path.length));
122
+ }
123
+ meta.params = (0, _smob.merge)(meta.params || {}, output.params);
124
+ }
125
+ }
126
+ meta.path = path;
127
+ if (!meta.mountPath) {
128
+ meta.mountPath = '/';
129
+ }
130
+ const next = (err)=>{
131
+ if (index >= this.stack.length) {
132
+ setImmediate(fn, err);
133
+ return;
134
+ }
135
+ let layer;
136
+ let match = false;
137
+ while(!match && index < this.stack.length){
138
+ index++;
139
+ layer = this.stack[index];
140
+ if ((0, _layer.isLayerInstance)(layer)) {
141
+ if (!layer.isError() && err) {
142
+ continue;
143
+ }
144
+ match = layer.matchPath(path);
145
+ }
146
+ if (isRouterInstance(layer)) {
147
+ match = layer.matchPath(path);
148
+ }
149
+ if ((0, _route.isRouteInstance)(layer)) {
150
+ match = layer.matchPath(path);
151
+ if (req.method && !layer.matchMethod(req.method)) {
152
+ match = false;
153
+ if (req.method.toLowerCase() === _core.Method.OPTIONS) {
154
+ allowedMethods = (0, _smob.mergeArrays)(allowedMethods, layer.getMethods(), true);
155
+ }
156
+ }
157
+ }
158
+ }
159
+ if (!match || !layer) {
160
+ setImmediate(fn, err);
161
+ return;
162
+ }
163
+ const layerMeta = _extends({}, meta);
164
+ if ((0, _layer.isLayerInstance)(layer)) {
165
+ const output = layer.exec(path);
166
+ if (output) {
167
+ layerMeta.params = (0, _smob.merge)(output.params, layerMeta.params || {});
168
+ layerMeta.mountPath = (0, _core.cleanDoubleSlashes)(`${layerMeta.mountPath || ''}/${output.path}`);
169
+ }
170
+ }
171
+ if (err) {
172
+ if ((0, _layer.isLayerInstance)(layer) && layer.isError()) {
173
+ layer.dispatch(req, res, layerMeta, next, err);
174
+ return;
175
+ }
176
+ /* istanbul ignore next */ setImmediate(next, err);
177
+ return;
178
+ }
179
+ layer.dispatch(req, res, layerMeta, next);
180
+ };
181
+ next();
182
+ }
183
+ /* istanbul ignore next */ dispatchAsync(req, res) {
184
+ return new Promise((resolve, reject)=>{
185
+ this.dispatch(req, res, {}, (err)=>{
186
+ if (err) {
187
+ reject(err);
188
+ return;
189
+ }
190
+ resolve();
191
+ });
192
+ });
193
+ }
194
+ // --------------------------------------------------
195
+ route(path) {
196
+ if (typeof path === 'string' && path.length > 0) {
197
+ path = (0, _core.withLeadingSlash)(path);
198
+ }
199
+ const index = this.stack.findIndex((item)=>(0, _route.isRouteInstance)(item) && item.path === path);
200
+ if (index !== -1) {
201
+ return this.stack[index];
202
+ }
203
+ const route = new _route.Route({
204
+ path,
205
+ pathMatcher: {
206
+ sensitive: this.pathMatcherOptions.sensitive
207
+ }
208
+ });
209
+ this.stack.push(route);
210
+ return route;
211
+ }
212
+ delete(path, ...handlers) {
213
+ const route = this.route(path);
214
+ route.delete(...handlers);
215
+ return this;
216
+ }
217
+ get(path, ...handlers) {
218
+ const route = this.route(path);
219
+ route.get(...handlers);
220
+ return this;
221
+ }
222
+ post(path, ...handlers) {
223
+ const route = this.route(path);
224
+ route.post(...handlers);
225
+ return this;
226
+ }
227
+ put(path, ...handlers) {
228
+ const route = this.route(path);
229
+ route.put(...handlers);
230
+ return this;
231
+ }
232
+ patch(path, ...handlers) {
233
+ const route = this.route(path);
234
+ route.patch(...handlers);
235
+ return this;
236
+ }
237
+ head(path, ...handlers) {
238
+ const route = this.route(path);
239
+ route.head(...handlers);
240
+ return this;
241
+ }
242
+ options(path, ...handlers) {
243
+ const route = this.route(path);
244
+ route.options(...handlers);
245
+ return this;
246
+ }
247
+ use(...input) {
248
+ /* istanbul ignore next */ if (input.length === 0) {
249
+ return this;
250
+ }
251
+ let path;
252
+ if ((0, _utils.isPath)(input[0])) {
253
+ path = input.shift();
254
+ }
255
+ for(let i = 0; i < input.length; i++){
256
+ const item = input[i];
257
+ if (isRouterInstance(item)) {
258
+ if (path) {
259
+ item.setPath(path);
260
+ }
261
+ item.setPathMatcherOptions(this.pathMatcherOptions);
262
+ this.stack.push(item);
263
+ continue;
264
+ }
265
+ if (typeof item === 'function') {
266
+ this.stack.push(new _layer.Layer({
267
+ path: path || '/',
268
+ pathMatcher: {
269
+ strict: false,
270
+ end: false,
271
+ sensitive: this.pathMatcherOptions.sensitive
272
+ }
273
+ }, item));
274
+ }
275
+ }
276
+ return this;
277
+ }
278
+ // --------------------------------------------------
279
+ constructor(ctx){
280
+ this['@instanceof'] = Symbol.for('Router');
281
+ /**
282
+ * Array of mounted layers, routes & routers.
283
+ *
284
+ * @protected
285
+ */ this.stack = [];
286
+ ctx = ctx || {};
287
+ this.pathMatcherOptions = _extends({
288
+ end: false,
289
+ sensitive: true
290
+ }, ctx.pathMatcher || {});
291
+ this.timeout = ctx.timeout;
292
+ this.setPath(ctx.path || '/');
293
+ }
294
+ }
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
package/dist/type.js ADDED
@@ -0,0 +1,9 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
@@ -0,0 +1,24 @@
1
+ /*
2
+ * Copyright (c) 2022-2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ _exportStar(require("./is-instance"), exports);
11
+ _exportStar(require("./path"), exports);
12
+ _exportStar(require("./promise"), exports);
13
+ _exportStar(require("./request"), exports);
14
+ function _exportStar(from, to) {
15
+ Object.keys(from).forEach(function(k) {
16
+ if (k !== "default" && !Object.prototype.hasOwnProperty.call(to, k)) Object.defineProperty(to, k, {
17
+ enumerable: true,
18
+ get: function() {
19
+ return from[k];
20
+ }
21
+ });
22
+ });
23
+ return from;
24
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2022-2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "isInstance", {
11
+ enumerable: true,
12
+ get: ()=>isInstance
13
+ });
14
+ function isInstance(input, name) {
15
+ return typeof input === 'object' && input !== null && input['@instanceof'] === Symbol.for(name);
16
+ }
@@ -0,0 +1,16 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "isPath", {
11
+ enumerable: true,
12
+ get: ()=>isPath
13
+ });
14
+ function isPath(input) {
15
+ return typeof input === 'string' || input instanceof RegExp;
16
+ }
@@ -0,0 +1,19 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "isPromise", {
11
+ enumerable: true,
12
+ get: ()=>isPromise
13
+ });
14
+ const _smob = require("smob");
15
+ function isPromise(p) {
16
+ return (0, _smob.isObject)(p) && (p instanceof Promise || // eslint-disable-next-line @typescript-eslint/ban-ts-comment
17
+ // @ts-ignore
18
+ typeof p.then === 'function');
19
+ }
@@ -0,0 +1,33 @@
1
+ /*
2
+ * Copyright (c) 2022.
3
+ * Author Peter Placzek (tada5hi)
4
+ * For the full copyright and license information,
5
+ * view the LICENSE file that was distributed with this source code.
6
+ */ "use strict";
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ Object.defineProperty(exports, "createRequestTimeout", {
11
+ enumerable: true,
12
+ get: ()=>createRequestTimeout
13
+ });
14
+ const _http = require("@ebec/http");
15
+ function createRequestTimeout(res, timeout, done) {
16
+ const instance = setTimeout(()=>{
17
+ res.statusCode = _http.GatewayTimeoutErrorOptions.statusCode;
18
+ res.statusMessage = _http.GatewayTimeoutErrorOptions.message;
19
+ res.end();
20
+ }, timeout);
21
+ res.once('close', ()=>{
22
+ clearTimeout(instance);
23
+ if (typeof done === 'function') {
24
+ done();
25
+ }
26
+ });
27
+ res.once('error', (e)=>{
28
+ clearTimeout(instance);
29
+ if (typeof done === 'function') {
30
+ done(e);
31
+ }
32
+ });
33
+ }
package/package.json CHANGED
@@ -1,23 +1,15 @@
1
1
  {
2
2
  "name": "routup",
3
- "version": "0.11.0",
3
+ "version": "0.12.0",
4
4
  "description": "Routup is a minimalistic http based routing framework.",
5
- "main": "dist/index.cjs",
6
- "module": "dist/index.mjs",
5
+ "main": "dist/index.js",
7
6
  "typings": "dist/index.d.ts",
8
- "exports": {
9
- "./package.json": "./package.json",
10
- ".": {
11
- "require": "./dist/index.cjs",
12
- "import": "./dist/index.mjs"
13
- }
14
- },
15
7
  "files": [
16
8
  "dist/"
17
9
  ],
18
10
  "scripts": {
19
11
  "build:types": "tsc --emitDeclarationOnly -p tsconfig.build.json",
20
- "build:js": "rollup -c",
12
+ "build:js": "npx swc ./src -d dist --config-file ../../.swcrc.json",
21
13
  "build": "rimraf ./dist && cross-env NODE_ENV=production npm run build:js && npm run build:types",
22
14
  "test": "cross-env NODE_ENV=test jest --config ./test/jest.config.js",
23
15
  "test:coverage": "cross-env NODE_ENV=test jest --config ./test/jest.config.js --coverage",
@@ -49,7 +41,7 @@
49
41
  },
50
42
  "homepage": "https://github.com/Tada5hi/routup#readme",
51
43
  "peerDependencies": {
52
- "@routup/core": ">=0.5.0 <1.0.0"
44
+ "@routup/core": ">=0.6.0 <1.0.0"
53
45
  },
54
46
  "dependencies": {
55
47
  "@ebec/http": "^0.1.0",
@@ -57,9 +49,9 @@
57
49
  "smob": "^0.0.7"
58
50
  },
59
51
  "devDependencies": {
60
- "@routup/core": "^0.5.0",
52
+ "@routup/core": "^0.6.0",
61
53
  "@types/supertest": "^2.0.12",
62
54
  "supertest": "^6.3.3"
63
55
  },
64
- "gitHead": "3aac0797ad68a1e748f819ffbf0423168a4906ae"
56
+ "gitHead": "9b1e92db85376e9d8bd24fe0b30531b1932a6a26"
65
57
  }
package/dist/index.cjs DELETED
@@ -1,2 +0,0 @@
1
- "use strict";var a=require("@routup/core"),f=require("smob"),l=require("@ebec/http"),k=require("path-to-regexp"),D=require("http");function g(r,t){return typeof r=="object"&&r!==null&&r["@instanceof"]===Symbol.for(t)}function b(r){return typeof r=="string"||r instanceof RegExp}function v(r){return f.isObject(r)&&(r instanceof Promise||typeof r.then=="function")}function T(r,t,e){const s=setTimeout(()=>{r.statusCode=l.GatewayTimeoutErrorOptions.statusCode,r.statusMessage=l.GatewayTimeoutErrorOptions.message,r.end()},t);r.once("close",()=>{clearTimeout(s),typeof e=="function"&&e()}),r.once("error",h=>{clearTimeout(s),typeof e=="function"&&e(h)})}function I(r,t,e){if(v(e)){e.then(s=>(typeof s<"u"&&a.send(r,s),s)).catch(t);return}typeof e<"u"&&a.send(r,e)}function S(r){return typeof r!="string"||r.length===0?r:decodeURIComponent(r)}class M{constructor(t,e){this.regexpKeys=[],this.path=t,this.regexpOptions=e||{},t instanceof RegExp?this.regexp=t:this.regexp=k.pathToRegexp(t,this.regexpKeys,e)}test(t){return this.path==="/"&&this.regexpOptions.end===!1?!0:this.regexp.test(t)}exec(t){let e=null;if(this.path==="/"&&this.regexpOptions.end===!1)return{path:"/",params:{}};if(e=this.regexp.exec(t),!e)return;if(this.path instanceof RegExp)return{path:t,params:{0:S(e[0])}};const s={};for(let h=1;h<e.length;h++){const p=this.regexpKeys[h-1].name,i=S(e[h]);typeof i<"u"&&(s[p]=i)}return{path:e[0],params:s}}}class E{constructor(t,e){this["@instanceof"]=Symbol.for("Layer"),this.pathMatcher=new M(t.path,t.pathMatcher),this.fn=e}isError(){return this.fn.length===4}dispatch(t,e,s,h,p){if(a.setRequestParams(t,s.params||{}),a.setRequestMountPath(t,s.mountPath||"/"),typeof p<"u"){if(this.fn.length===4){try{this.fn(p,t,e,h)}catch(i){i instanceof Error?h(i):h(new l.BadRequestError({message:"The request could not be processed by the error handler."}))}return}h(p);return}if(this.fn.length>3){h();return}try{const i=this.fn(t,e,h);I(e,h,i)}catch(i){i instanceof Error?h(i):h(new l.BadRequestError({message:"The request could not be processed by the handler."}))}}matchPath(t){return this.pathMatcher.test(t)}exec(t){return this.pathMatcher.exec(t)}}function O(r){return g(r,"Layer")}var $=Object.defineProperty,L=Object.getOwnPropertySymbols,G=Object.prototype.hasOwnProperty,N=Object.prototype.propertyIsEnumerable,q=(r,t,e)=>t in r?$(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,w=(r,t)=>{for(var e in t||(t={}))G.call(t,e)&&q(r,e,t[e]);if(L)for(var e of L(t))N.call(t,e)&&q(r,e,t[e]);return r};class j{constructor(t){this["@instanceof"]=Symbol.for("Route"),this.layers={},this.path=t.path,this.pathMatcherOptions=w({end:!0,strict:this.isStrictPath()},t.pathMatcher),this.pathMatcher=new M(this.path,this.pathMatcherOptions)}matchPath(t){return this.pathMatcher.test(t)}matchMethod(t){let e=t.toLowerCase();return e===a.Method.HEAD&&!f.hasOwnProperty(this.layers,e)&&(e=a.Method.GET),Object.prototype.hasOwnProperty.call(this.layers,e)}getMethods(){const t=Object.keys(this.layers);return f.hasOwnProperty(this.layers,a.Method.GET)&&!f.hasOwnProperty(this.layers,a.Method.HEAD)&&t.push(a.Method.HEAD),t}dispatch(t,e,s,h){if(!t.method){h();return}let p=t.method.toLowerCase();p===a.Method.HEAD&&!f.hasOwnProperty(this.layers,p)&&(p=a.Method.GET);const i=this.layers[p];if(typeof i>"u"||i.length===0||typeof s.path>"u"){h();return}const y=w({},s),c=this.pathMatcher.exec(s.path);c&&(y.params=f.merge({},s.params||{},c.params));let d=-1;const o=n=>{if(d++,d>=i.length){setImmediate(h,n);return}const u=i[d];if(n&&!u.isError()){o(n);return}u.dispatch(t,e,w({},y),o)};o()}register(t,...e){this.layers[t]=[];for(let s=0;s<e.length;s++){const h=new E({path:this.path,pathMatcher:this.pathMatcherOptions},e[s]);this.layers[t].push(h)}}get(...t){return this.register(a.Method.GET,...t)}post(...t){return this.register(a.Method.POST,...t)}put(...t){return this.register(a.Method.PUT,...t)}patch(...t){return this.register(a.Method.PATCH,...t)}delete(...t){return this.register(a.Method.DELETE,...t)}head(...t){return this.register(a.Method.HEAD,...t)}options(...t){return this.register(a.Method.OPTIONS,...t)}isStrictPath(){return typeof this.path!="string"||this.path!=="/"&&this.path.length!==0}}function R(r){return g(r,"Route")}var B=Object.defineProperty,C=Object.getOwnPropertySymbols,K=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable,H=(r,t,e)=>t in r?B(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,A=(r,t)=>{for(var e in t||(t={}))K.call(t,e)&&H(r,e,t[e]);if(C)for(var e of C(t))U.call(t,e)&&H(r,e,t[e]);return r};function x(r){return g(r,"Router")}class F{constructor(t){this["@instanceof"]=Symbol.for("Router"),this.stack=[],t=t||{},this.pathMatcherOptions=A({end:!1,sensitive:!0},t.pathMatcher||{}),this.timeout=t.timeout,this.setPath(t.path||"/")}setPathMatcherOptions(t){this.pathMatcherOptions=t,this.pathMatcher&&(this.pathMatcher.regexpOptions=this.pathMatcherOptions)}setPath(t){if(t==="/"||!b(t)){this.path="/";return}typeof t=="string"?this.path=a.withLeadingSlash(a.withoutTrailingSlash(`${t}`)):this.path=t,this.pathMatcher=new M(this.path,this.pathMatcherOptions)}createListener(){return this.isRoot=!0,(t,e)=>{this.dispatch(t,e)}}listen(t){return D.createServer(this.createListener()).listen(t)}matchPath(t){return this.pathMatcher?this.pathMatcher.test(t):!0}dispatch(t,e,s,h){let p=-1;s=s||{};let i=[];this.isRoot&&typeof this.timeout=="number"&&T(e,this.timeout,h);const y=o=>{if(!this.isRoot){typeof h<"u"&&setImmediate(()=>h(o));return}if(typeof o<"u"){e.statusCode=l.BadRequestErrorOptions.statusCode,e.statusMessage=l.BadRequestErrorOptions.message,e.end();return}if(t.method&&t.method.toLowerCase()===a.Method.OPTIONS){const n=i.map(u=>u.toUpperCase()).join(",");e.setHeader(a.HeaderName.ALLOW,n),a.send(e,n);return}e.statusCode=l.NotFoundErrorOptions.statusCode,e.end()};let c=s.path||a.useRequestPath(t);if(this.pathMatcher){const o=this.pathMatcher.exec(c);typeof o<"u"&&(s.mountPath=a.cleanDoubleSlashes(`${s.mountPath||""}/${o.path}`),c===o.path?c="/":c=a.withLeadingSlash(c.substring(o.path.length)),s.params=f.merge(s.params||{},o.params))}s.path=c,s.mountPath||(s.mountPath="/");const d=o=>{if(p>=this.stack.length){setImmediate(y,o);return}let n,u=!1;for(;!u&&p<this.stack.length;){if(p++,n=this.stack[p],O(n)){if(!n.isError()&&o)continue;u=n.matchPath(c)}x(n)&&(u=n.matchPath(c)),R(n)&&(u=n.matchPath(c),t.method&&!n.matchMethod(t.method)&&(u=!1,t.method.toLowerCase()===a.Method.OPTIONS&&(i=f.mergeArrays(i,n.getMethods(),!0))))}if(!u||!n){setImmediate(y,o);return}const m=A({},s);if(O(n)){const P=n.exec(c);P&&(m.params=f.merge(P.params,m.params||{}),m.mountPath=a.cleanDoubleSlashes(`${m.mountPath||""}/${P.path}`))}if(o){if(O(n)&&n.isError()){n.dispatch(t,e,m,d,o);return}setImmediate(d,o);return}n.dispatch(t,e,m,d)};d()}dispatchAsync(t,e){return new Promise((s,h)=>{this.dispatch(t,e,{},p=>{if(p){h(p);return}s()})})}route(t){typeof t=="string"&&t.length>0&&(t=a.withLeadingSlash(t));const e=this.stack.findIndex(h=>R(h)&&h.path===t);if(e!==-1)return this.stack[e];const s=new j({path:t,pathMatcher:{sensitive:this.pathMatcherOptions.sensitive}});return this.stack.push(s),s}delete(t,...e){return this.route(t).delete(...e),this}get(t,...e){return this.route(t).get(...e),this}post(t,...e){return this.route(t).post(...e),this}put(t,...e){return this.route(t).put(...e),this}patch(t,...e){return this.route(t).patch(...e),this}head(t,...e){return this.route(t).head(...e),this}options(t,...e){return this.route(t).options(...e),this}use(...t){if(t.length===0)return this;let e;b(t[0])&&(e=t.shift());for(let s=0;s<t.length;s++){const h=t[s];if(x(h)){e&&h.setPath(e),h.setPathMatcherOptions(this.pathMatcherOptions),this.stack.push(h);continue}typeof h=="function"&&this.stack.push(new E({path:e||"/",pathMatcher:{strict:!1,end:!1,sensitive:this.pathMatcherOptions.sensitive}},h))}return this}}exports.Layer=E,exports.PathMatcher=M,exports.Route=j,exports.Router=F,exports.createRequestTimeout=T,exports.isInstance=g,exports.isLayerInstance=O,exports.isPath=b,exports.isPromise=v,exports.isRouteInstance=R,exports.isRouterInstance=x,exports.processHandlerExecutionOutput=I,Object.keys(a).forEach(function(r){r!=="default"&&!exports.hasOwnProperty(r)&&Object.defineProperty(exports,r,{enumerable:!0,get:function(){return a[r]}})});
2
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sources":["../src/utils/is-instance.ts","../src/utils/path.ts","../src/utils/promise.ts","../src/utils/request.ts","../src/handler/utils.ts","../src/path/matcher.ts","../src/layer/module.ts","../src/layer/utils.ts","../src/route/module.ts","../src/route/utils.ts","../src/router/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isInstance(input: unknown, name: string) {\n return (\n typeof input === 'object' &&\n input !== null &&\n (input as { '@instanceof': symbol })['@instanceof'] === Symbol.for(name)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Path } from '../type';\n\nexport function isPath(input: unknown) : input is Path {\n return typeof input === 'string' || input instanceof RegExp;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from 'smob';\n\nexport function isPromise(p: unknown) : p is Promise<unknown> {\n return isObject(p) &&\n (\n p instanceof Promise ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n typeof p.then === 'function'\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { GatewayTimeoutErrorOptions } from '@ebec/http';\nimport { Next, Response } from '@routup/core';\n\n/* istanbul ignore next */\nexport function createRequestTimeout(res: Response, timeout: number, done?: Next) {\n const instance = setTimeout(() => {\n res.statusCode = GatewayTimeoutErrorOptions.statusCode;\n res.statusMessage = GatewayTimeoutErrorOptions.message;\n\n res.end();\n }, timeout);\n\n res.once('close', () => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done();\n }\n });\n\n res.once('error', (e) => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done(e);\n }\n });\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Next, Response, send } from '@routup/core';\nimport { isPromise } from '../utils';\n\nexport function processHandlerExecutionOutput(res: Response, next: Next, output?: unknown) {\n if (isPromise(output)) {\n output\n .then((r) => {\n if (typeof r !== 'undefined') {\n send(res, r);\n }\n\n return r;\n })\n .catch(next);\n return;\n }\n\n if (typeof output !== 'undefined') {\n send(res, output);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n Key, pathToRegexp,\n} from 'path-to-regexp';\nimport { Path } from '../type';\nimport { PathMatcherExecResult, PathMatcherOptions } from './type';\n\nfunction decodeParam(val: unknown) {\n /* istanbul ignore next */\n if (typeof val !== 'string' || val.length === 0) {\n return val;\n }\n\n return decodeURIComponent(val);\n}\n\nexport class PathMatcher {\n path: Path;\n\n regexp : RegExp;\n\n regexpKeys : Key[] = [];\n\n regexpOptions: PathMatcherOptions;\n\n constructor(path: Path, options?: PathMatcherOptions) {\n this.path = path;\n this.regexpOptions = options || {};\n\n if (path instanceof RegExp) {\n this.regexp = path;\n } else {\n this.regexp = pathToRegexp(path, this.regexpKeys, options);\n }\n }\n\n test(path: string) {\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return true;\n }\n\n return this.regexp.test(path);\n }\n\n exec(path: string) : PathMatcherExecResult | undefined {\n let match : RegExpExecArray | null = null;\n\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return {\n path: '/',\n params: {},\n };\n }\n\n match = this.regexp.exec(path);\n\n if (!match) {\n return undefined;\n }\n\n if (this.path instanceof RegExp) {\n return {\n path,\n params: {\n 0: decodeParam(match[0]),\n },\n };\n }\n\n const output : Record<string, unknown> = {};\n\n for (let i = 1; i < match.length; i++) {\n const key = this.regexpKeys[i - 1];\n const prop = key.name;\n const val = decodeParam(match[i]);\n\n if (typeof val !== 'undefined') {\n output[prop] = val;\n }\n }\n\n return {\n path: match[0],\n params: output,\n };\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BadRequestError } from '@ebec/http';\nimport {\n Next, Request, Response, setRequestMountPath, setRequestParams,\n} from '@routup/core';\nimport { processHandlerExecutionOutput } from '../handler';\nimport { PathMatcher } from '../path';\nimport {\n DispatcherMeta,\n} from '../type';\nimport { LayerOptions } from './type';\n\nexport class Layer {\n readonly '@instanceof' = Symbol.for('Layer');\n\n protected fn : CallableFunction;\n\n protected pathMatcher : PathMatcher;\n\n // --------------------------------------------------\n\n constructor(\n options: LayerOptions,\n fn: CallableFunction,\n ) {\n this.pathMatcher = new PathMatcher(options.path, options.pathMatcher);\n this.fn = fn;\n }\n\n // --------------------------------------------------\n\n isError() {\n return this.fn.length === 4;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction,\n err: Error,\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: Next,\n err?: Error,\n ) : void {\n setRequestParams(req, meta.params || {});\n setRequestMountPath(req, meta.mountPath || '/');\n\n if (typeof err !== 'undefined') {\n if (this.fn.length === 4) {\n try {\n this.fn(err, req, res, next);\n } catch (e) {\n /* istanbul ignore next */\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the error handler.',\n }));\n }\n }\n\n return;\n }\n\n /* istanbul ignore next */\n next(err);\n /* istanbul ignore next */\n return;\n }\n\n /* istanbul ignore next */\n if (this.fn.length > 3) {\n next();\n return;\n }\n\n try {\n const output = this.fn(req, res, next);\n\n processHandlerExecutionOutput(res, next, output);\n } catch (e) {\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the handler.',\n }));\n }\n }\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n exec(path: string) {\n return this.pathMatcher.exec(path);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Layer } from './module';\n\nexport function isLayerInstance(input: unknown) : input is Layer {\n return isInstance(input, 'Layer');\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty, merge } from 'smob';\nimport {\n Handler, Method, Next, Request, Response,\n} from '@routup/core';\nimport { Layer } from '../layer';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouteOptions } from './type';\n\nexport class Route {\n readonly '@instanceof' = Symbol.for('Route');\n\n public path : Path;\n\n protected pathMatcher : PathMatcher;\n\n protected pathMatcherOptions : PathMatcherOptions;\n\n protected layers : Record<string, Layer[]> = {};\n\n // --------------------------------------------------\n\n constructor(options: RouteOptions) {\n this.path = options.path;\n\n this.pathMatcherOptions = {\n end: true,\n strict: this.isStrictPath(),\n ...options.pathMatcher,\n };\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n matchMethod(method: string) : boolean {\n let name = method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n return Object.prototype.hasOwnProperty.call(this.layers, name);\n }\n\n // --------------------------------------------------\n\n getMethods() : string[] {\n const keys = Object.keys(this.layers);\n\n if (\n hasOwnProperty(this.layers, Method.GET) &&\n !hasOwnProperty(this.layers, Method.HEAD)\n ) {\n keys.push(Method.HEAD);\n }\n\n return keys;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n done: Next,\n ) : void {\n /* istanbul ignore next */\n if (!req.method) {\n done();\n return;\n }\n\n let name = req.method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n const layers = this.layers[name];\n\n /* istanbul ignore next */\n if (\n typeof layers === 'undefined' ||\n layers.length === 0 ||\n typeof meta.path === 'undefined'\n ) {\n done();\n\n return;\n }\n\n const layerMeta : DispatcherMeta = {\n ...meta,\n };\n\n const output = this.pathMatcher.exec(meta.path);\n if (output) {\n layerMeta.params = merge({}, (meta.params || {}), output.params);\n }\n\n let index = -1;\n\n const next = (err?: Error) : void => {\n index++;\n\n if (index >= layers.length) {\n setImmediate(done, err);\n return;\n }\n\n const layer = layers[index];\n if (\n err &&\n !layer.isError()\n ) {\n next(err);\n return;\n }\n\n layer.dispatch(req, res, { ...layerMeta }, next);\n };\n\n next();\n }\n\n // --------------------------------------------------\n\n register(method: `${Method}`, ...handlers: Handler[]) {\n this.layers[method] = [];\n\n for (let i = 0; i < handlers.length; i++) {\n const layer = new Layer(\n {\n path: this.path,\n pathMatcher: this.pathMatcherOptions,\n },\n handlers[i],\n );\n\n this.layers[method].push(layer);\n }\n }\n\n get(...handlers: Handler[]) {\n return this.register(Method.GET, ...handlers);\n }\n\n post(...handlers: Handler[]) {\n return this.register(Method.POST, ...handlers);\n }\n\n put(...handlers: Handler[]) {\n return this.register(Method.PUT, ...handlers);\n }\n\n patch(...handlers: Handler[]) {\n return this.register(Method.PATCH, ...handlers);\n }\n\n delete(...handlers: Handler[]) {\n return this.register(Method.DELETE, ...handlers);\n }\n\n head(...handlers: Handler[]) {\n return this.register(Method.HEAD, ...handlers);\n }\n\n options(...handlers: Handler[]) {\n return this.register(Method.OPTIONS, ...handlers);\n }\n\n // --------------------------------------------------\n\n private isStrictPath() {\n return typeof this.path !== 'string' ||\n (this.path !== '/' && this.path.length !== 0);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Route } from './module';\n\nexport function isRouteInstance(input: unknown) : input is Route {\n return isInstance(input, 'Route');\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n BadRequestErrorOptions,\n NotFoundErrorOptions,\n} from '@ebec/http';\nimport { RequestListener, createServer } from 'http';\nimport { merge, mergeArrays } from 'smob';\nimport {\n ErrorHandler,\n Handler,\n HeaderName,\n Method,\n Next,\n Request,\n Response,\n cleanDoubleSlashes,\n send,\n useRequestPath,\n withLeadingSlash,\n withoutTrailingSlash,\n} from '@routup/core';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n createRequestTimeout,\n isInstance,\n isPath,\n\n} from '../utils';\nimport { Layer, isLayerInstance } from '../layer';\nimport { Route, isRouteInstance } from '../route';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouterOptions } from './type';\n\nexport function isRouterInstance(input: unknown) : input is Router {\n return isInstance(input, 'Router');\n}\n\nexport class Router {\n readonly '@instanceof' = Symbol.for('Router');\n\n /**\n * Array of mounted layers, routes & routers.\n *\n * @protected\n */\n protected stack : (Router | Route | Layer)[] = [];\n\n /**\n * Mount path of instance\n *\n * @protected\n */\n protected path : Path | undefined;\n\n /**\n * Path matcher for the current mount path.\n *\n * @protected\n */\n protected pathMatcher : PathMatcher | undefined;\n\n /**\n * Path matcher options.\n *\n * @protected\n */\n protected pathMatcherOptions : PathMatcherOptions;\n\n /**\n * Is this the root instance?\n *\n * @protected\n */\n protected isRoot : boolean | undefined;\n\n /**\n * Timeout before the router decides to abort the request.\n *\n * @protected\n */\n protected timeout: number | undefined;\n\n // --------------------------------------------------\n\n constructor(ctx?: RouterOptions) {\n ctx = ctx || {};\n\n this.pathMatcherOptions = {\n end: false,\n sensitive: true,\n ...(ctx.pathMatcher || {}),\n };\n\n this.timeout = ctx.timeout;\n\n this.setPath(ctx.path || '/');\n }\n\n // --------------------------------------------------\n\n setPathMatcherOptions(input: PathMatcherOptions) {\n this.pathMatcherOptions = input;\n\n if (this.pathMatcher) {\n this.pathMatcher.regexpOptions = this.pathMatcherOptions;\n }\n }\n\n setPath(value: Path) {\n if (value === '/' || !isPath(value)) {\n this.path = '/';\n return;\n }\n\n if (typeof value === 'string') {\n this.path = withLeadingSlash(withoutTrailingSlash(`${value}`));\n } else {\n this.path = value;\n }\n\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n createListener() : RequestListener {\n this.isRoot = true;\n\n return (req, res) => {\n this.dispatch(req, res);\n };\n }\n\n /* istanbul ignore next */\n listen(port: number) {\n const server = createServer(this.createListener());\n return server.listen(port);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n if (this.pathMatcher) {\n return this.pathMatcher.test(path);\n }\n\n return true;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta?: DispatcherMeta,\n done?: Next,\n ) : void {\n let index = -1;\n\n meta = meta || {};\n\n let allowedMethods : string[] = [];\n\n if (\n this.isRoot &&\n typeof this.timeout === 'number'\n ) {\n createRequestTimeout(res, this.timeout, done);\n }\n\n const fn = (err?: Error) => {\n /* istanbul ignore if */\n if (!this.isRoot) {\n if (typeof done !== 'undefined') {\n setImmediate(() => done(err));\n }\n\n return;\n }\n\n if (typeof err !== 'undefined') {\n res.statusCode = BadRequestErrorOptions.statusCode;\n res.statusMessage = BadRequestErrorOptions.message;\n\n res.end();\n\n return;\n }\n\n if (\n req.method &&\n req.method.toLowerCase() === Method.OPTIONS\n ) {\n const options = allowedMethods\n .map((key) => key.toUpperCase())\n .join(',');\n\n res.setHeader(HeaderName.ALLOW, options);\n send(res, options);\n\n return;\n }\n\n res.statusCode = NotFoundErrorOptions.statusCode;\n res.end();\n };\n\n let path = meta.path || useRequestPath(req);\n\n if (this.pathMatcher) {\n const output = this.pathMatcher.exec(path);\n if (typeof output !== 'undefined') {\n meta.mountPath = cleanDoubleSlashes(`${meta.mountPath || ''}/${output.path}`);\n\n if (path === output.path) {\n path = '/';\n } else {\n path = withLeadingSlash(path.substring(output.path.length));\n }\n\n meta.params = merge(meta.params || {}, output.params);\n }\n }\n\n meta.path = path;\n\n if (!meta.mountPath) {\n meta.mountPath = '/';\n }\n\n const next = (err?: Error) : void => {\n if (index >= this.stack.length) {\n setImmediate(fn, err);\n return;\n }\n\n let layer : Route | Router | Layer | undefined;\n let match = false;\n\n while (!match && index < this.stack.length) {\n index++;\n\n layer = this.stack[index];\n\n if (isLayerInstance(layer)) {\n if (!layer.isError() && err) {\n continue;\n }\n\n match = layer.matchPath(path);\n }\n\n if (isRouterInstance(layer)) {\n match = layer.matchPath(path);\n }\n\n if (isRouteInstance(layer)) {\n match = layer.matchPath(path);\n\n if (\n req.method &&\n !layer.matchMethod(req.method)\n ) {\n match = false;\n\n if (req.method.toLowerCase() === Method.OPTIONS) {\n allowedMethods = mergeArrays(\n allowedMethods,\n layer.getMethods(),\n true,\n );\n }\n }\n }\n }\n\n if (!match || !layer) {\n setImmediate(fn, err);\n return;\n }\n\n const layerMeta : DispatcherMeta = { ...meta };\n\n if (isLayerInstance(layer)) {\n const output = layer.exec(path);\n\n if (output) {\n layerMeta.params = merge(output.params, layerMeta.params || {});\n layerMeta.mountPath = cleanDoubleSlashes(`${layerMeta.mountPath || ''}/${output.path}`);\n }\n }\n\n if (err) {\n if (\n isLayerInstance(layer) &&\n layer.isError()\n ) {\n layer.dispatch(req, res, layerMeta, next, err);\n return;\n }\n\n /* istanbul ignore next */\n setImmediate(next, err);\n return;\n }\n\n layer.dispatch(req, res, layerMeta, next);\n };\n\n next();\n }\n\n /* istanbul ignore next */\n dispatchAsync(\n req: Request,\n res: Response,\n ) : Promise<void> {\n return new Promise((resolve, reject) => {\n this.dispatch(req, res, {}, (err?: Error) => {\n if (err) {\n reject(err);\n return;\n }\n\n resolve();\n });\n });\n }\n\n // --------------------------------------------------\n\n route(\n path: Path,\n ) : Route {\n if (\n typeof path === 'string' &&\n path.length > 0\n ) {\n path = withLeadingSlash(path);\n }\n\n const index = this.stack.findIndex(\n (item) => isRouteInstance(item) && item.path === path,\n );\n\n if (index !== -1) {\n return this.stack[index] as Route;\n }\n\n const route = new Route({\n path,\n pathMatcher: {\n sensitive: this.pathMatcherOptions.sensitive,\n },\n });\n this.stack.push(route);\n\n return route;\n }\n\n delete(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.delete(...handlers);\n\n return this;\n }\n\n get(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.get(...handlers);\n\n return this;\n }\n\n post(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.post(...handlers);\n\n return this;\n }\n\n put(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.put(...handlers);\n\n return this;\n }\n\n patch(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.patch(...handlers);\n\n return this;\n }\n\n head(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.head(...handlers);\n\n return this;\n }\n\n options(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.options(...handlers);\n\n return this;\n }\n\n // --------------------------------------------------\n\n use(router: Router) : this;\n\n use(handler: Handler) : this;\n\n use(handler: ErrorHandler) : this;\n\n use(path: Path, router: Router) : this;\n\n use(path: Path, handler: Handler) : this;\n\n use(path: Path, handler: ErrorHandler) : this;\n\n use(...input: unknown[]) : this {\n /* istanbul ignore next */\n if (input.length === 0) {\n return this;\n }\n\n let path : Path | undefined;\n\n if (isPath(input[0])) {\n path = input.shift() as Path;\n }\n\n for (let i = 0; i < input.length; i++) {\n const item = input[i];\n if (isRouterInstance(item)) {\n if (path) {\n item.setPath(path);\n }\n item.setPathMatcherOptions(this.pathMatcherOptions);\n this.stack.push(item);\n continue;\n }\n\n if (typeof item === 'function') {\n this.stack.push(new Layer({\n path: path || '/',\n pathMatcher: {\n strict: false,\n end: false,\n sensitive: this.pathMatcherOptions.sensitive,\n },\n }, item));\n }\n }\n\n return this;\n }\n}\n"],"names":["isInstance","input","name","isPath","isPromise","p","isObject","createRequestTimeout","res","timeout","done","instance","GatewayTimeoutErrorOptions","e","processHandlerExecutionOutput","next","output","r","send","decodeParam","val","PathMatcher","path","options","pathToRegexp","match","i","prop","Layer","fn","req","meta","err","setRequestParams","setRequestMountPath","BadRequestError","isLayerInstance","Route","__spreadValues","method","Method","hasOwnProperty","keys","layers","layerMeta","merge","index","layer","handlers","isRouteInstance","isRouterInstance","Router","ctx","value","withLeadingSlash","withoutTrailingSlash","port","createServer","allowedMethods","BadRequestErrorOptions","key","HeaderName","NotFoundErrorOptions","useRequestPath","cleanDoubleSlashes","mergeArrays","resolve","reject","item","route"],"mappings":"mIAOO,SAASA,EAAWC,EAAgBC,EAAc,CACrD,OACI,OAAOD,GAAU,UACjBA,IAAU,MACTA,EAAoC,iBAAmB,OAAO,IAAIC,CAAI,CAE/E,CCJgB,SAA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AAI,EACvB,IAAI,GAAG0B,CAAQ,EAEd,IACX,CAEA,KAAK1B,KAAe0B,EAA4B,CAE5C,OADc,KAAK,MAAM1B,CAAI,EACvB,KAAK,GAAG0B,CAAQ,EAEf,IACX,CAEA,IAAI1B,KAAe0B,EAA4B,CAE3C,OADc,KAAK,MAAM1B,CAAI,EACvB,IAAI,GAAG0B,CAAQ,EAEd,IACX,CAEA,MAAM1B,KAAe0B,EAA4B,CAE7C,OADc,KAAK,MAAM1B,CAAI,EACvB,MAAM,GAAG0B,CAAQ,EAEhB,IACX,CAEA,KAAK1B,KAAe0B,EAA4B,CAE5C,OADc,KAAK,MAAM1B,CAAI,EACvB,KAAK,GAAG0B,CAAQ,EAEf,IACX,CAEA,QAAQ1B,KAAe0B,EAA4B,CAE/C,OADc,KAAK,MAAM1B,CAAI,EACvB,QAAQ,GAAG0B,CAAQ,EAElB,IACX,CAgBA,OAAO/C,EAAyB,CAE5B,GAAIA,EAAM,SAAW,EACjB,OAAO,KAGX,IAAIqB,EAEAnB,EAAOF,EAAM,EAAE,IACfqB,EAAOrB,EAAM,MAAM,GAGvB,QAASyB,EAAI,EAAGA,EAAIzB,EAAM,OAAQyB,IAAK,CACnC,MAAM0C,EAAOnE,EAAMyB,GACnB,GAAIwB,EAAiBkB,CAAI,EAAG,CACpB9C,GACA8C,EAAK,QAAQ9C,CAAI,EAErB8C,EAAK,sBAAsB,KAAK,kBAAkB,EAClD,KAAK,MAAM,KAAKA,CAAI,EACpB,QACJ,CAEI,OAAOA,GAAS,YAChB,KAAK,MAAM,KAAK,IAAIxC,EAAM,CACtB,KAAMN,GAAQ,IACd,YAAa,CACT,OAAQ,GACR,IAAK,GACL,UAAW,KAAK,mBAAmB,SACvC,CACJ,EAAG8C,CAAI,CAAC,CAEhB,CAEA,OAAO,IACX,CACJ"}
package/dist/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- import{send as P,setRequestParams as U,setRequestMountPath as B,Method as p,withLeadingSlash as b,withoutTrailingSlash as F,useRequestPath as W,cleanDoubleSlashes as I,HeaderName as z}from"@routup/core";export*from"@routup/core";import{isObject as J,hasOwnProperty as d,merge as E,mergeArrays as Q}from"smob";import{GatewayTimeoutErrorOptions as S,BadRequestError as L,BadRequestErrorOptions as j,NotFoundErrorOptions as V}from"@ebec/http";import{pathToRegexp as X}from"path-to-regexp";import{createServer as Y}from"http";function y(r,t){return typeof r=="object"&&r!==null&&r["@instanceof"]===Symbol.for(t)}function x(r){return typeof r=="string"||r instanceof RegExp}function C(r){return J(r)&&(r instanceof Promise||typeof r.then=="function")}function k(r,t,e){const s=setTimeout(()=>{r.statusCode=S.statusCode,r.statusMessage=S.message,r.end()},t);r.once("close",()=>{clearTimeout(s),typeof e=="function"&&e()}),r.once("error",h=>{clearTimeout(s),typeof e=="function"&&e(h)})}function H(r,t,e){if(C(e)){e.then(s=>(typeof s<"u"&&P(r,s),s)).catch(t);return}typeof e<"u"&&P(r,e)}function A(r){return typeof r!="string"||r.length===0?r:decodeURIComponent(r)}class g{constructor(t,e){this.regexpKeys=[],this.path=t,this.regexpOptions=e||{},t instanceof RegExp?this.regexp=t:this.regexp=X(t,this.regexpKeys,e)}test(t){return this.path==="/"&&this.regexpOptions.end===!1?!0:this.regexp.test(t)}exec(t){let e=null;if(this.path==="/"&&this.regexpOptions.end===!1)return{path:"/",params:{}};if(e=this.regexp.exec(t),!e)return;if(this.path instanceof RegExp)return{path:t,params:{0:A(e[0])}};const s={};for(let h=1;h<e.length;h++){const o=this.regexpKeys[h-1].name,i=A(e[h]);typeof i<"u"&&(s[o]=i)}return{path:e[0],params:s}}}class w{constructor(t,e){this["@instanceof"]=Symbol.for("Layer"),this.pathMatcher=new g(t.path,t.pathMatcher),this.fn=e}isError(){return this.fn.length===4}dispatch(t,e,s,h,o){if(U(t,s.params||{}),B(t,s.mountPath||"/"),typeof o<"u"){if(this.fn.length===4){try{this.fn(o,t,e,h)}catch(i){i instanceof Error?h(i):h(new L({message:"The request could not be processed by the error handler."}))}return}h(o);return}if(this.fn.length>3){h();return}try{const i=this.fn(t,e,h);H(e,h,i)}catch(i){i instanceof Error?h(i):h(new L({message:"The request could not be processed by the handler."}))}}matchPath(t){return this.pathMatcher.test(t)}exec(t){return this.pathMatcher.exec(t)}}function O(r){return y(r,"Layer")}var Z=Object.defineProperty,q=Object.getOwnPropertySymbols,_=Object.prototype.hasOwnProperty,tt=Object.prototype.propertyIsEnumerable,D=(r,t,e)=>t in r?Z(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,R=(r,t)=>{for(var e in t||(t={}))_.call(t,e)&&D(r,e,t[e]);if(q)for(var e of q(t))tt.call(t,e)&&D(r,e,t[e]);return r};class ${constructor(t){this["@instanceof"]=Symbol.for("Route"),this.layers={},this.path=t.path,this.pathMatcherOptions=R({end:!0,strict:this.isStrictPath()},t.pathMatcher),this.pathMatcher=new g(this.path,this.pathMatcherOptions)}matchPath(t){return this.pathMatcher.test(t)}matchMethod(t){let e=t.toLowerCase();return e===p.HEAD&&!d(this.layers,e)&&(e=p.GET),Object.prototype.hasOwnProperty.call(this.layers,e)}getMethods(){const t=Object.keys(this.layers);return d(this.layers,p.GET)&&!d(this.layers,p.HEAD)&&t.push(p.HEAD),t}dispatch(t,e,s,h){if(!t.method){h();return}let o=t.method.toLowerCase();o===p.HEAD&&!d(this.layers,o)&&(o=p.GET);const i=this.layers[o];if(typeof i>"u"||i.length===0||typeof s.path>"u"){h();return}const l=R({},s),c=this.pathMatcher.exec(s.path);c&&(l.params=E({},s.params||{},c.params));let f=-1;const n=a=>{if(f++,f>=i.length){setImmediate(h,a);return}const u=i[f];if(a&&!u.isError()){n(a);return}u.dispatch(t,e,R({},l),n)};n()}register(t,...e){this.layers[t]=[];for(let s=0;s<e.length;s++){const h=new w({path:this.path,pathMatcher:this.pathMatcherOptions},e[s]);this.layers[t].push(h)}}get(...t){return this.register(p.GET,...t)}post(...t){return this.register(p.POST,...t)}put(...t){return this.register(p.PUT,...t)}patch(...t){return this.register(p.PATCH,...t)}delete(...t){return this.register(p.DELETE,...t)}head(...t){return this.register(p.HEAD,...t)}options(...t){return this.register(p.OPTIONS,...t)}isStrictPath(){return typeof this.path!="string"||this.path!=="/"&&this.path.length!==0}}function v(r){return y(r,"Route")}var et=Object.defineProperty,G=Object.getOwnPropertySymbols,rt=Object.prototype.hasOwnProperty,st=Object.prototype.propertyIsEnumerable,N=(r,t,e)=>t in r?et(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,K=(r,t)=>{for(var e in t||(t={}))rt.call(t,e)&&N(r,e,t[e]);if(G)for(var e of G(t))st.call(t,e)&&N(r,e,t[e]);return r};function T(r){return y(r,"Router")}class ht{constructor(t){this["@instanceof"]=Symbol.for("Router"),this.stack=[],t=t||{},this.pathMatcherOptions=K({end:!1,sensitive:!0},t.pathMatcher||{}),this.timeout=t.timeout,this.setPath(t.path||"/")}setPathMatcherOptions(t){this.pathMatcherOptions=t,this.pathMatcher&&(this.pathMatcher.regexpOptions=this.pathMatcherOptions)}setPath(t){if(t==="/"||!x(t)){this.path="/";return}typeof t=="string"?this.path=b(F(`${t}`)):this.path=t,this.pathMatcher=new g(this.path,this.pathMatcherOptions)}createListener(){return this.isRoot=!0,(t,e)=>{this.dispatch(t,e)}}listen(t){return Y(this.createListener()).listen(t)}matchPath(t){return this.pathMatcher?this.pathMatcher.test(t):!0}dispatch(t,e,s,h){let o=-1;s=s||{};let i=[];this.isRoot&&typeof this.timeout=="number"&&k(e,this.timeout,h);const l=n=>{if(!this.isRoot){typeof h<"u"&&setImmediate(()=>h(n));return}if(typeof n<"u"){e.statusCode=j.statusCode,e.statusMessage=j.message,e.end();return}if(t.method&&t.method.toLowerCase()===p.OPTIONS){const a=i.map(u=>u.toUpperCase()).join(",");e.setHeader(z.ALLOW,a),P(e,a);return}e.statusCode=V.statusCode,e.end()};let c=s.path||W(t);if(this.pathMatcher){const n=this.pathMatcher.exec(c);typeof n<"u"&&(s.mountPath=I(`${s.mountPath||""}/${n.path}`),c===n.path?c="/":c=b(c.substring(n.path.length)),s.params=E(s.params||{},n.params))}s.path=c,s.mountPath||(s.mountPath="/");const f=n=>{if(o>=this.stack.length){setImmediate(l,n);return}let a,u=!1;for(;!u&&o<this.stack.length;){if(o++,a=this.stack[o],O(a)){if(!a.isError()&&n)continue;u=a.matchPath(c)}T(a)&&(u=a.matchPath(c)),v(a)&&(u=a.matchPath(c),t.method&&!a.matchMethod(t.method)&&(u=!1,t.method.toLowerCase()===p.OPTIONS&&(i=Q(i,a.getMethods(),!0))))}if(!u||!a){setImmediate(l,n);return}const m=K({},s);if(O(a)){const M=a.exec(c);M&&(m.params=E(M.params,m.params||{}),m.mountPath=I(`${m.mountPath||""}/${M.path}`))}if(n){if(O(a)&&a.isError()){a.dispatch(t,e,m,f,n);return}setImmediate(f,n);return}a.dispatch(t,e,m,f)};f()}dispatchAsync(t,e){return new Promise((s,h)=>{this.dispatch(t,e,{},o=>{if(o){h(o);return}s()})})}route(t){typeof t=="string"&&t.length>0&&(t=b(t));const e=this.stack.findIndex(h=>v(h)&&h.path===t);if(e!==-1)return this.stack[e];const s=new $({path:t,pathMatcher:{sensitive:this.pathMatcherOptions.sensitive}});return this.stack.push(s),s}delete(t,...e){return this.route(t).delete(...e),this}get(t,...e){return this.route(t).get(...e),this}post(t,...e){return this.route(t).post(...e),this}put(t,...e){return this.route(t).put(...e),this}patch(t,...e){return this.route(t).patch(...e),this}head(t,...e){return this.route(t).head(...e),this}options(t,...e){return this.route(t).options(...e),this}use(...t){if(t.length===0)return this;let e;x(t[0])&&(e=t.shift());for(let s=0;s<t.length;s++){const h=t[s];if(T(h)){e&&h.setPath(e),h.setPathMatcherOptions(this.pathMatcherOptions),this.stack.push(h);continue}typeof h=="function"&&this.stack.push(new w({path:e||"/",pathMatcher:{strict:!1,end:!1,sensitive:this.pathMatcherOptions.sensitive}},h))}return this}}export{w as Layer,g as PathMatcher,$ as Route,ht as Router,k as createRequestTimeout,y as isInstance,O as isLayerInstance,x as isPath,C as isPromise,v as isRouteInstance,T as isRouterInstance,H as processHandlerExecutionOutput};
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sources":["../src/utils/is-instance.ts","../src/utils/path.ts","../src/utils/promise.ts","../src/utils/request.ts","../src/handler/utils.ts","../src/path/matcher.ts","../src/layer/module.ts","../src/layer/utils.ts","../src/route/module.ts","../src/route/utils.ts","../src/router/module.ts"],"sourcesContent":["/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nexport function isInstance(input: unknown, name: string) {\n return (\n typeof input === 'object' &&\n input !== null &&\n (input as { '@instanceof': symbol })['@instanceof'] === Symbol.for(name)\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Path } from '../type';\n\nexport function isPath(input: unknown) : input is Path {\n return typeof input === 'string' || input instanceof RegExp;\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isObject } from 'smob';\n\nexport function isPromise(p: unknown) : p is Promise<unknown> {\n return isObject(p) &&\n (\n p instanceof Promise ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore\n typeof p.then === 'function'\n );\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { GatewayTimeoutErrorOptions } from '@ebec/http';\nimport { Next, Response } from '@routup/core';\n\n/* istanbul ignore next */\nexport function createRequestTimeout(res: Response, timeout: number, done?: Next) {\n const instance = setTimeout(() => {\n res.statusCode = GatewayTimeoutErrorOptions.statusCode;\n res.statusMessage = GatewayTimeoutErrorOptions.message;\n\n res.end();\n }, timeout);\n\n res.once('close', () => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done();\n }\n });\n\n res.once('error', (e) => {\n clearTimeout(instance);\n\n if (typeof done === 'function') {\n done(e);\n }\n });\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { Next, Response, send } from '@routup/core';\nimport { isPromise } from '../utils';\n\nexport function processHandlerExecutionOutput(res: Response, next: Next, output?: unknown) {\n if (isPromise(output)) {\n output\n .then((r) => {\n if (typeof r !== 'undefined') {\n send(res, r);\n }\n\n return r;\n })\n .catch(next);\n return;\n }\n\n if (typeof output !== 'undefined') {\n send(res, output);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n Key, pathToRegexp,\n} from 'path-to-regexp';\nimport { Path } from '../type';\nimport { PathMatcherExecResult, PathMatcherOptions } from './type';\n\nfunction decodeParam(val: unknown) {\n /* istanbul ignore next */\n if (typeof val !== 'string' || val.length === 0) {\n return val;\n }\n\n return decodeURIComponent(val);\n}\n\nexport class PathMatcher {\n path: Path;\n\n regexp : RegExp;\n\n regexpKeys : Key[] = [];\n\n regexpOptions: PathMatcherOptions;\n\n constructor(path: Path, options?: PathMatcherOptions) {\n this.path = path;\n this.regexpOptions = options || {};\n\n if (path instanceof RegExp) {\n this.regexp = path;\n } else {\n this.regexp = pathToRegexp(path, this.regexpKeys, options);\n }\n }\n\n test(path: string) {\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return true;\n }\n\n return this.regexp.test(path);\n }\n\n exec(path: string) : PathMatcherExecResult | undefined {\n let match : RegExpExecArray | null = null;\n\n const fastSlash = this.path === '/' && this.regexpOptions.end === false;\n if (fastSlash) {\n return {\n path: '/',\n params: {},\n };\n }\n\n match = this.regexp.exec(path);\n\n if (!match) {\n return undefined;\n }\n\n if (this.path instanceof RegExp) {\n return {\n path,\n params: {\n 0: decodeParam(match[0]),\n },\n };\n }\n\n const output : Record<string, unknown> = {};\n\n for (let i = 1; i < match.length; i++) {\n const key = this.regexpKeys[i - 1];\n const prop = key.name;\n const val = decodeParam(match[i]);\n\n if (typeof val !== 'undefined') {\n output[prop] = val;\n }\n }\n\n return {\n path: match[0],\n params: output,\n };\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { BadRequestError } from '@ebec/http';\nimport {\n Next, Request, Response, setRequestMountPath, setRequestParams,\n} from '@routup/core';\nimport { processHandlerExecutionOutput } from '../handler';\nimport { PathMatcher } from '../path';\nimport {\n DispatcherMeta,\n} from '../type';\nimport { LayerOptions } from './type';\n\nexport class Layer {\n readonly '@instanceof' = Symbol.for('Layer');\n\n protected fn : CallableFunction;\n\n protected pathMatcher : PathMatcher;\n\n // --------------------------------------------------\n\n constructor(\n options: LayerOptions,\n fn: CallableFunction,\n ) {\n this.pathMatcher = new PathMatcher(options.path, options.pathMatcher);\n this.fn = fn;\n }\n\n // --------------------------------------------------\n\n isError() {\n return this.fn.length === 4;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: CallableFunction,\n err: Error,\n ) : void;\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n next: Next,\n err?: Error,\n ) : void {\n setRequestParams(req, meta.params || {});\n setRequestMountPath(req, meta.mountPath || '/');\n\n if (typeof err !== 'undefined') {\n if (this.fn.length === 4) {\n try {\n this.fn(err, req, res, next);\n } catch (e) {\n /* istanbul ignore next */\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the error handler.',\n }));\n }\n }\n\n return;\n }\n\n /* istanbul ignore next */\n next(err);\n /* istanbul ignore next */\n return;\n }\n\n /* istanbul ignore next */\n if (this.fn.length > 3) {\n next();\n return;\n }\n\n try {\n const output = this.fn(req, res, next);\n\n processHandlerExecutionOutput(res, next, output);\n } catch (e) {\n /* istanbul ignore next */\n if (e instanceof Error) {\n next(e);\n } else {\n next(new BadRequestError({\n message: 'The request could not be processed by the handler.',\n }));\n }\n }\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n exec(path: string) {\n return this.pathMatcher.exec(path);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Layer } from './module';\n\nexport function isLayerInstance(input: unknown) : input is Layer {\n return isInstance(input, 'Layer');\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { hasOwnProperty, merge } from 'smob';\nimport {\n Handler, Method, Next, Request, Response,\n} from '@routup/core';\nimport { Layer } from '../layer';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouteOptions } from './type';\n\nexport class Route {\n readonly '@instanceof' = Symbol.for('Route');\n\n public path : Path;\n\n protected pathMatcher : PathMatcher;\n\n protected pathMatcherOptions : PathMatcherOptions;\n\n protected layers : Record<string, Layer[]> = {};\n\n // --------------------------------------------------\n\n constructor(options: RouteOptions) {\n this.path = options.path;\n\n this.pathMatcherOptions = {\n end: true,\n strict: this.isStrictPath(),\n ...options.pathMatcher,\n };\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n return this.pathMatcher.test(path);\n }\n\n matchMethod(method: string) : boolean {\n let name = method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n return Object.prototype.hasOwnProperty.call(this.layers, name);\n }\n\n // --------------------------------------------------\n\n getMethods() : string[] {\n const keys = Object.keys(this.layers);\n\n if (\n hasOwnProperty(this.layers, Method.GET) &&\n !hasOwnProperty(this.layers, Method.HEAD)\n ) {\n keys.push(Method.HEAD);\n }\n\n return keys;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta: DispatcherMeta,\n done: Next,\n ) : void {\n /* istanbul ignore next */\n if (!req.method) {\n done();\n return;\n }\n\n let name = req.method.toLowerCase();\n\n if (\n name === Method.HEAD &&\n !hasOwnProperty(this.layers, name)\n ) {\n name = Method.GET;\n }\n\n const layers = this.layers[name];\n\n /* istanbul ignore next */\n if (\n typeof layers === 'undefined' ||\n layers.length === 0 ||\n typeof meta.path === 'undefined'\n ) {\n done();\n\n return;\n }\n\n const layerMeta : DispatcherMeta = {\n ...meta,\n };\n\n const output = this.pathMatcher.exec(meta.path);\n if (output) {\n layerMeta.params = merge({}, (meta.params || {}), output.params);\n }\n\n let index = -1;\n\n const next = (err?: Error) : void => {\n index++;\n\n if (index >= layers.length) {\n setImmediate(done, err);\n return;\n }\n\n const layer = layers[index];\n if (\n err &&\n !layer.isError()\n ) {\n next(err);\n return;\n }\n\n layer.dispatch(req, res, { ...layerMeta }, next);\n };\n\n next();\n }\n\n // --------------------------------------------------\n\n register(method: `${Method}`, ...handlers: Handler[]) {\n this.layers[method] = [];\n\n for (let i = 0; i < handlers.length; i++) {\n const layer = new Layer(\n {\n path: this.path,\n pathMatcher: this.pathMatcherOptions,\n },\n handlers[i],\n );\n\n this.layers[method].push(layer);\n }\n }\n\n get(...handlers: Handler[]) {\n return this.register(Method.GET, ...handlers);\n }\n\n post(...handlers: Handler[]) {\n return this.register(Method.POST, ...handlers);\n }\n\n put(...handlers: Handler[]) {\n return this.register(Method.PUT, ...handlers);\n }\n\n patch(...handlers: Handler[]) {\n return this.register(Method.PATCH, ...handlers);\n }\n\n delete(...handlers: Handler[]) {\n return this.register(Method.DELETE, ...handlers);\n }\n\n head(...handlers: Handler[]) {\n return this.register(Method.HEAD, ...handlers);\n }\n\n options(...handlers: Handler[]) {\n return this.register(Method.OPTIONS, ...handlers);\n }\n\n // --------------------------------------------------\n\n private isStrictPath() {\n return typeof this.path !== 'string' ||\n (this.path !== '/' && this.path.length !== 0);\n }\n}\n","/*\n * Copyright (c) 2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport { isInstance } from '../utils';\nimport { Route } from './module';\n\nexport function isRouteInstance(input: unknown) : input is Route {\n return isInstance(input, 'Route');\n}\n","/*\n * Copyright (c) 2022-2022.\n * Author Peter Placzek (tada5hi)\n * For the full copyright and license information,\n * view the LICENSE file that was distributed with this source code.\n */\n\nimport {\n BadRequestErrorOptions,\n NotFoundErrorOptions,\n} from '@ebec/http';\nimport { RequestListener, createServer } from 'http';\nimport { merge, mergeArrays } from 'smob';\nimport {\n ErrorHandler,\n Handler,\n HeaderName,\n Method,\n Next,\n Request,\n Response,\n cleanDoubleSlashes,\n send,\n useRequestPath,\n withLeadingSlash,\n withoutTrailingSlash,\n} from '@routup/core';\nimport { PathMatcher, PathMatcherOptions } from '../path';\nimport {\n createRequestTimeout,\n isInstance,\n isPath,\n\n} from '../utils';\nimport { Layer, isLayerInstance } from '../layer';\nimport { Route, isRouteInstance } from '../route';\nimport {\n DispatcherMeta,\n Path,\n} from '../type';\nimport { RouterOptions } from './type';\n\nexport function isRouterInstance(input: unknown) : input is Router {\n return isInstance(input, 'Router');\n}\n\nexport class Router {\n readonly '@instanceof' = Symbol.for('Router');\n\n /**\n * Array of mounted layers, routes & routers.\n *\n * @protected\n */\n protected stack : (Router | Route | Layer)[] = [];\n\n /**\n * Mount path of instance\n *\n * @protected\n */\n protected path : Path | undefined;\n\n /**\n * Path matcher for the current mount path.\n *\n * @protected\n */\n protected pathMatcher : PathMatcher | undefined;\n\n /**\n * Path matcher options.\n *\n * @protected\n */\n protected pathMatcherOptions : PathMatcherOptions;\n\n /**\n * Is this the root instance?\n *\n * @protected\n */\n protected isRoot : boolean | undefined;\n\n /**\n * Timeout before the router decides to abort the request.\n *\n * @protected\n */\n protected timeout: number | undefined;\n\n // --------------------------------------------------\n\n constructor(ctx?: RouterOptions) {\n ctx = ctx || {};\n\n this.pathMatcherOptions = {\n end: false,\n sensitive: true,\n ...(ctx.pathMatcher || {}),\n };\n\n this.timeout = ctx.timeout;\n\n this.setPath(ctx.path || '/');\n }\n\n // --------------------------------------------------\n\n setPathMatcherOptions(input: PathMatcherOptions) {\n this.pathMatcherOptions = input;\n\n if (this.pathMatcher) {\n this.pathMatcher.regexpOptions = this.pathMatcherOptions;\n }\n }\n\n setPath(value: Path) {\n if (value === '/' || !isPath(value)) {\n this.path = '/';\n return;\n }\n\n if (typeof value === 'string') {\n this.path = withLeadingSlash(withoutTrailingSlash(`${value}`));\n } else {\n this.path = value;\n }\n\n this.pathMatcher = new PathMatcher(this.path, this.pathMatcherOptions);\n }\n\n // --------------------------------------------------\n\n createListener() : RequestListener {\n this.isRoot = true;\n\n return (req, res) => {\n this.dispatch(req, res);\n };\n }\n\n /* istanbul ignore next */\n listen(port: number) {\n const server = createServer(this.createListener());\n return server.listen(port);\n }\n\n // --------------------------------------------------\n\n matchPath(path: string) : boolean {\n if (this.pathMatcher) {\n return this.pathMatcher.test(path);\n }\n\n return true;\n }\n\n // --------------------------------------------------\n\n dispatch(\n req: Request,\n res: Response,\n meta?: DispatcherMeta,\n done?: Next,\n ) : void {\n let index = -1;\n\n meta = meta || {};\n\n let allowedMethods : string[] = [];\n\n if (\n this.isRoot &&\n typeof this.timeout === 'number'\n ) {\n createRequestTimeout(res, this.timeout, done);\n }\n\n const fn = (err?: Error) => {\n /* istanbul ignore if */\n if (!this.isRoot) {\n if (typeof done !== 'undefined') {\n setImmediate(() => done(err));\n }\n\n return;\n }\n\n if (typeof err !== 'undefined') {\n res.statusCode = BadRequestErrorOptions.statusCode;\n res.statusMessage = BadRequestErrorOptions.message;\n\n res.end();\n\n return;\n }\n\n if (\n req.method &&\n req.method.toLowerCase() === Method.OPTIONS\n ) {\n const options = allowedMethods\n .map((key) => key.toUpperCase())\n .join(',');\n\n res.setHeader(HeaderName.ALLOW, options);\n send(res, options);\n\n return;\n }\n\n res.statusCode = NotFoundErrorOptions.statusCode;\n res.end();\n };\n\n let path = meta.path || useRequestPath(req);\n\n if (this.pathMatcher) {\n const output = this.pathMatcher.exec(path);\n if (typeof output !== 'undefined') {\n meta.mountPath = cleanDoubleSlashes(`${meta.mountPath || ''}/${output.path}`);\n\n if (path === output.path) {\n path = '/';\n } else {\n path = withLeadingSlash(path.substring(output.path.length));\n }\n\n meta.params = merge(meta.params || {}, output.params);\n }\n }\n\n meta.path = path;\n\n if (!meta.mountPath) {\n meta.mountPath = '/';\n }\n\n const next = (err?: Error) : void => {\n if (index >= this.stack.length) {\n setImmediate(fn, err);\n return;\n }\n\n let layer : Route | Router | Layer | undefined;\n let match = false;\n\n while (!match && index < this.stack.length) {\n index++;\n\n layer = this.stack[index];\n\n if (isLayerInstance(layer)) {\n if (!layer.isError() && err) {\n continue;\n }\n\n match = layer.matchPath(path);\n }\n\n if (isRouterInstance(layer)) {\n match = layer.matchPath(path);\n }\n\n if (isRouteInstance(layer)) {\n match = layer.matchPath(path);\n\n if (\n req.method &&\n !layer.matchMethod(req.method)\n ) {\n match = false;\n\n if (req.method.toLowerCase() === Method.OPTIONS) {\n allowedMethods = mergeArrays(\n allowedMethods,\n layer.getMethods(),\n true,\n );\n }\n }\n }\n }\n\n if (!match || !layer) {\n setImmediate(fn, err);\n return;\n }\n\n const layerMeta : DispatcherMeta = { ...meta };\n\n if (isLayerInstance(layer)) {\n const output = layer.exec(path);\n\n if (output) {\n layerMeta.params = merge(output.params, layerMeta.params || {});\n layerMeta.mountPath = cleanDoubleSlashes(`${layerMeta.mountPath || ''}/${output.path}`);\n }\n }\n\n if (err) {\n if (\n isLayerInstance(layer) &&\n layer.isError()\n ) {\n layer.dispatch(req, res, layerMeta, next, err);\n return;\n }\n\n /* istanbul ignore next */\n setImmediate(next, err);\n return;\n }\n\n layer.dispatch(req, res, layerMeta, next);\n };\n\n next();\n }\n\n /* istanbul ignore next */\n dispatchAsync(\n req: Request,\n res: Response,\n ) : Promise<void> {\n return new Promise((resolve, reject) => {\n this.dispatch(req, res, {}, (err?: Error) => {\n if (err) {\n reject(err);\n return;\n }\n\n resolve();\n });\n });\n }\n\n // --------------------------------------------------\n\n route(\n path: Path,\n ) : Route {\n if (\n typeof path === 'string' &&\n path.length > 0\n ) {\n path = withLeadingSlash(path);\n }\n\n const index = this.stack.findIndex(\n (item) => isRouteInstance(item) && item.path === path,\n );\n\n if (index !== -1) {\n return this.stack[index] as Route;\n }\n\n const route = new Route({\n path,\n pathMatcher: {\n sensitive: this.pathMatcherOptions.sensitive,\n },\n });\n this.stack.push(route);\n\n return route;\n }\n\n delete(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.delete(...handlers);\n\n return this;\n }\n\n get(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.get(...handlers);\n\n return this;\n }\n\n post(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.post(...handlers);\n\n return this;\n }\n\n put(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.put(...handlers);\n\n return this;\n }\n\n patch(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.patch(...handlers);\n\n return this;\n }\n\n head(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.head(...handlers);\n\n return this;\n }\n\n options(path: Path, ...handlers: Handler[]) : this {\n const route = this.route(path);\n route.options(...handlers);\n\n return this;\n }\n\n // --------------------------------------------------\n\n use(router: Router) : this;\n\n use(handler: Handler) : this;\n\n use(handler: ErrorHandler) : this;\n\n use(path: Path, router: Router) : this;\n\n use(path: Path, handler: Handler) : this;\n\n use(path: Path, handler: ErrorHandler) : this;\n\n use(...input: unknown[]) : this {\n /* istanbul ignore next */\n if (input.length === 0) {\n return this;\n }\n\n let path : Path | undefined;\n\n if (isPath(input[0])) {\n path = input.shift() as Path;\n }\n\n for (let i = 0; i < input.length; i++) {\n const item = input[i];\n if (isRouterInstance(item)) {\n if (path) {\n item.setPath(path);\n }\n item.setPathMatcherOptions(this.pathMatcherOptions);\n this.stack.push(item);\n continue;\n }\n\n if (typeof item === 'function') {\n this.stack.push(new Layer({\n path: path || '/',\n pathMatcher: {\n strict: false,\n end: false,\n sensitive: this.pathMatcherOptions.sensitive,\n },\n }, item));\n }\n }\n\n return this;\n }\n}\n"],"names":["isInstance","input","name","isPath","isPromise","p","isObject","createRequestTimeout","res","timeout","done","instance","GatewayTimeoutErrorOptions","e","processHandlerExecutionOutput","next","output","r","send","decodeParam","val","PathMatcher","path","options","pathToRegexp","match","i","prop","Layer","fn","req","meta","err","setRequestParams","setRequestMountPath","BadRequestError","isLayerInstance","Route","__spreadValues","method","Method","hasOwnProperty","keys","layers","layerMeta","merge","index","layer","handlers","isRouteInstance","isRouterInstance","Router","ctx","value","withLeadingSlash","withoutTrailingSlash","port","createServer","allowedMethods","BadRequestErrorOptions","key","HeaderName","NotFoundErrorOptions","useRequestPath","cleanDoubleSlashes","mergeArrays","resolve","reject","item","route"],"mappings":"0gBAOO,SAASA,EAAWC,EAAgBC,EAAc,CACrD,OACI,OAAOD,GAAU,UACjBA,IAAU,MACTA,EAAoC,iBAAmB,OAAO,IAAIC,CAAI,CAE/E,CCJgB,SAAAC,EAAOF,EAAgC,CACnD,OAAO,OAAOA,GAAU,UAAYA,aAAiB,MACzD,CCFgB,SAAAG,EAAUC,EAAoC,CAC1D,OAAOC,EAASD,CAAC,IAETA,aAAa,SAGb,OAAOA,EAAE,MAAS,WAE9B,CCNgB,SAAAE,EAAqBC,EAAeC,EAAiBC,EAAa,CAC9E,MAAMC,EAAW,WAAW,IAAM,CAC9BH,EAAI,WAAaI,EA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