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.
Files changed (47) hide show
  1. package/dist/handler/index.js +21 -24
  2. package/dist/handler/utils.js +29 -29
  3. package/dist/index.js +28 -31
  4. package/dist/layer/index.js +23 -26
  5. package/dist/layer/module.js +74 -82
  6. package/dist/layer/type.js +9 -9
  7. package/dist/layer/utils.js +17 -15
  8. package/dist/path/index.js +22 -25
  9. package/dist/path/matcher.js +74 -74
  10. package/dist/path/type.js +9 -9
  11. package/dist/route/index.js +23 -26
  12. package/dist/route/module.js +135 -125
  13. package/dist/route/type.js +9 -9
  14. package/dist/route/utils.js +17 -15
  15. package/dist/router/index.js +22 -25
  16. package/dist/router/module.js +294 -285
  17. package/dist/router/type.js +9 -3
  18. package/dist/type.js +9 -9
  19. package/dist/utils/index.js +24 -27
  20. package/dist/utils/is-instance.js +16 -16
  21. package/dist/utils/path.js +16 -14
  22. package/dist/utils/promise.js +19 -19
  23. package/dist/utils/request.js +33 -32
  24. package/package.json +11 -6
  25. package/dist/handler/index.js.map +0 -1
  26. package/dist/handler/utils.js.map +0 -1
  27. package/dist/index.js.map +0 -1
  28. package/dist/layer/index.js.map +0 -1
  29. package/dist/layer/module.js.map +0 -1
  30. package/dist/layer/type.js.map +0 -1
  31. package/dist/layer/utils.js.map +0 -1
  32. package/dist/path/index.js.map +0 -1
  33. package/dist/path/matcher.js.map +0 -1
  34. package/dist/path/type.js.map +0 -1
  35. package/dist/route/index.js.map +0 -1
  36. package/dist/route/module.js.map +0 -1
  37. package/dist/route/type.js.map +0 -1
  38. package/dist/route/utils.js.map +0 -1
  39. package/dist/router/index.js.map +0 -1
  40. package/dist/router/module.js.map +0 -1
  41. package/dist/router/type.js.map +0 -1
  42. package/dist/type.js.map +0 -1
  43. package/dist/utils/index.js.map +0 -1
  44. package/dist/utils/is-instance.js.map +0 -1
  45. package/dist/utils/path.js.map +0 -1
  46. package/dist/utils/promise.js.map +0 -1
  47. package/dist/utils/request.js.map +0 -1
package/dist/path/type.js CHANGED
@@ -1,9 +1,9 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- //# sourceMappingURL=type.js.map
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
+ });
@@ -1,26 +1,23 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./module"), exports);
24
- __exportStar(require("./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
+ }
@@ -1,125 +1,135 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.Route = void 0;
10
- const smob_1 = require("smob");
11
- const core_1 = require("@routup/core");
12
- const layer_1 = require("../layer");
13
- const path_1 = require("../path");
14
- class Route {
15
- // --------------------------------------------------
16
- constructor(options) {
17
- this['@instanceof'] = Symbol.for('Route');
18
- this.layers = {};
19
- this.path = options.path;
20
- this.pathMatcherOptions = Object.assign({ end: true, strict: this.isStrictPath() }, options.pathMatcher);
21
- this.pathMatcher = new path_1.PathMatcher(this.path, this.pathMatcherOptions);
22
- }
23
- // --------------------------------------------------
24
- matchPath(path) {
25
- return this.pathMatcher.test(path);
26
- }
27
- matchMethod(method) {
28
- let name = method.toLowerCase();
29
- if (name === core_1.Method.HEAD &&
30
- !(0, smob_1.hasOwnProperty)(this.layers, name)) {
31
- name = core_1.Method.GET;
32
- }
33
- return Object.prototype.hasOwnProperty.call(this.layers, name);
34
- }
35
- // --------------------------------------------------
36
- getMethods() {
37
- const keys = Object.keys(this.layers);
38
- if ((0, smob_1.hasOwnProperty)(this.layers, core_1.Method.GET) &&
39
- !(0, smob_1.hasOwnProperty)(this.layers, core_1.Method.HEAD)) {
40
- keys.push(core_1.Method.HEAD);
41
- }
42
- return keys;
43
- }
44
- // --------------------------------------------------
45
- dispatch(req, res, meta, done) {
46
- /* istanbul ignore next */
47
- if (!req.method) {
48
- done();
49
- return;
50
- }
51
- let name = req.method.toLowerCase();
52
- if (name === core_1.Method.HEAD &&
53
- !(0, smob_1.hasOwnProperty)(this.layers, name)) {
54
- name = core_1.Method.GET;
55
- }
56
- const layers = this.layers[name];
57
- /* istanbul ignore next */
58
- if (typeof layers === 'undefined' ||
59
- layers.length === 0 ||
60
- typeof meta.path === 'undefined') {
61
- done();
62
- return;
63
- }
64
- const layerMeta = Object.assign({}, meta);
65
- const output = this.pathMatcher.exec(meta.path);
66
- if (output) {
67
- layerMeta.params = (0, smob_1.merge)({}, (meta.params || {}), output.params);
68
- }
69
- let index = -1;
70
- const next = (err) => {
71
- index++;
72
- if (index >= layers.length) {
73
- setImmediate(done, err);
74
- return;
75
- }
76
- const layer = layers[index];
77
- if (err &&
78
- !layer.isError()) {
79
- next(err);
80
- return;
81
- }
82
- layer.dispatch(req, res, Object.assign({}, layerMeta), next);
83
- };
84
- next();
85
- }
86
- // --------------------------------------------------
87
- register(method, ...handlers) {
88
- this.layers[method] = [];
89
- for (let i = 0; i < handlers.length; i++) {
90
- const layer = new layer_1.Layer({
91
- path: this.path,
92
- pathMatcher: this.pathMatcherOptions,
93
- }, handlers[i]);
94
- this.layers[method].push(layer);
95
- }
96
- }
97
- get(...handlers) {
98
- return this.register(core_1.Method.GET, ...handlers);
99
- }
100
- post(...handlers) {
101
- return this.register(core_1.Method.POST, ...handlers);
102
- }
103
- put(...handlers) {
104
- return this.register(core_1.Method.PUT, ...handlers);
105
- }
106
- patch(...handlers) {
107
- return this.register(core_1.Method.PATCH, ...handlers);
108
- }
109
- delete(...handlers) {
110
- return this.register(core_1.Method.DELETE, ...handlers);
111
- }
112
- head(...handlers) {
113
- return this.register(core_1.Method.HEAD, ...handlers);
114
- }
115
- options(...handlers) {
116
- return this.register(core_1.Method.OPTIONS, ...handlers);
117
- }
118
- // --------------------------------------------------
119
- isStrictPath() {
120
- return typeof this.path !== 'string' ||
121
- (this.path !== '/' && this.path.length !== 0);
122
- }
123
- }
124
- exports.Route = Route;
125
- //# sourceMappingURL=module.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
+ 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
+ }
@@ -1,9 +1,9 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- //# sourceMappingURL=type.js.map
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
+ });
@@ -1,15 +1,17 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.isRouteInstance = void 0;
10
- const utils_1 = require("../utils");
11
- function isRouteInstance(input) {
12
- return (0, utils_1.isInstance)(input, 'Route');
13
- }
14
- exports.isRouteInstance = isRouteInstance;
15
- //# sourceMappingURL=utils.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
+ 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
+ }
@@ -1,25 +1,22 @@
1
- "use strict";
2
- /*
3
- * Copyright (c) 2022.
4
- * Author Peter Placzek (tada5hi)
5
- * For the full copyright and license information,
6
- * view the LICENSE file that was distributed with this source code.
7
- */
8
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
- if (k2 === undefined) k2 = k;
10
- var desc = Object.getOwnPropertyDescriptor(m, k);
11
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
- desc = { enumerable: true, get: function() { return m[k]; } };
13
- }
14
- Object.defineProperty(o, k2, desc);
15
- }) : (function(o, m, k, k2) {
16
- if (k2 === undefined) k2 = k;
17
- o[k2] = m[k];
18
- }));
19
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
20
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
21
- };
22
- Object.defineProperty(exports, "__esModule", { value: true });
23
- __exportStar(require("./module"), exports);
24
- __exportStar(require("./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
+ }