routup 0.10.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.
- package/dist/handler/index.js +21 -24
- package/dist/handler/utils.js +29 -29
- package/dist/index.js +28 -31
- package/dist/layer/index.js +23 -26
- package/dist/layer/module.js +74 -82
- package/dist/layer/type.js +9 -9
- package/dist/layer/utils.js +17 -15
- package/dist/path/index.js +22 -25
- package/dist/path/matcher.js +74 -74
- package/dist/path/type.js +9 -9
- package/dist/route/index.js +23 -26
- package/dist/route/module.js +135 -125
- package/dist/route/type.js +9 -9
- package/dist/route/utils.js +17 -15
- package/dist/router/index.js +22 -25
- package/dist/router/module.js +294 -285
- package/dist/router/type.js +9 -3
- package/dist/type.js +9 -9
- package/dist/utils/index.js +24 -27
- package/dist/utils/is-instance.js +16 -16
- package/dist/utils/path.js +16 -14
- package/dist/utils/promise.js +19 -19
- package/dist/utils/request.js +33 -32
- package/package.json +11 -6
- package/dist/handler/index.js.map +0 -1
- package/dist/handler/utils.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/layer/index.js.map +0 -1
- package/dist/layer/module.js.map +0 -1
- package/dist/layer/type.js.map +0 -1
- package/dist/layer/utils.js.map +0 -1
- package/dist/path/index.js.map +0 -1
- package/dist/path/matcher.js.map +0 -1
- package/dist/path/type.js.map +0 -1
- package/dist/route/index.js.map +0 -1
- package/dist/route/module.js.map +0 -1
- package/dist/route/type.js.map +0 -1
- package/dist/route/utils.js.map +0 -1
- package/dist/router/index.js.map +0 -1
- package/dist/router/module.js.map +0 -1
- package/dist/router/type.js.map +0 -1
- package/dist/type.js.map +0 -1
- package/dist/utils/index.js.map +0 -1
- package/dist/utils/is-instance.js.map +0 -1
- package/dist/utils/path.js.map +0 -1
- package/dist/utils/promise.js.map +0 -1
- package/dist/utils/request.js.map +0 -1
package/dist/path/type.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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/route/index.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
Object.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
__exportStar(require("./type"), exports);
|
|
25
|
-
__exportStar(require("./utils"), exports);
|
|
26
|
-
//# sourceMappingURL=index.js.map
|
|
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
|
+
}
|
package/dist/route/module.js
CHANGED
|
@@ -1,125 +1,135 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
42
|
-
return
|
|
43
|
-
}
|
|
44
|
-
// --------------------------------------------------
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (!
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
|
|
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
|
+
}
|
package/dist/route/type.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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/route/utils.js
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
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
|
+
}
|
package/dist/router/index.js
CHANGED
|
@@ -1,25 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
__exportStar(require("./module"), exports);
|
|
24
|
-
__exportStar(require("./type"), exports);
|
|
25
|
-
//# sourceMappingURL=index.js.map
|
|
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
|
+
}
|