@esportsplus/routing 0.0.39 → 0.0.41
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/build/browser.d.ts +1 -1
- package/build/browser.js +20 -14
- package/build/constants.js +6 -1
- package/build/index.js +27 -5
- package/build/router/index.js +12 -8
- package/build/router/node.js +12 -9
- package/build/router/route.js +9 -3
- package/build/slugify.js +3 -1
- package/build/types.js +6 -2
- package/package.json +4 -4
- package/src/browser.ts +8 -8
package/build/browser.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ declare const _default: <T>(instance?: Router<T> | undefined) => {
|
|
|
8
8
|
middleware: {
|
|
9
9
|
(...middleware: Middleware<T>[]): () => T;
|
|
10
10
|
dispatch(request: Request<T>): T;
|
|
11
|
-
match(fallback: Route<T>, scheduler: Scheduler, subdomain?: string | undefined): (request: Request<T>, next: Next<T>) => import("@esportsplus/template/build/types").
|
|
11
|
+
match(fallback: Route<T>, scheduler: Scheduler, subdomain?: string | undefined): (request: Request<T>, next: Next<T>) => import("@esportsplus/template/build/types").Renderable;
|
|
12
12
|
};
|
|
13
13
|
redirect: (path: string, values?: unknown[]) => void;
|
|
14
14
|
router: Router<T>;
|
package/build/browser.js
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const reactivity_1 = require("@esportsplus/reactivity");
|
|
7
|
+
const template_1 = require("@esportsplus/template");
|
|
8
|
+
const pipeline_1 = __importDefault(require("@esportsplus/pipeline"));
|
|
9
|
+
const router_1 = __importDefault(require("./router"));
|
|
5
10
|
let cache = [];
|
|
6
11
|
function back() {
|
|
7
12
|
window.history.back();
|
|
@@ -11,7 +16,6 @@ function forward() {
|
|
|
11
16
|
}
|
|
12
17
|
function href() {
|
|
13
18
|
let data = new URL(window.location?.href || ''), path = data.hash ? data.hash.slice(1).split('?') : ['/', ''], request = {
|
|
14
|
-
data: {},
|
|
15
19
|
href: data.href,
|
|
16
20
|
hostname: data.hostname,
|
|
17
21
|
method: 'GET',
|
|
@@ -42,7 +46,7 @@ function match(request, router, subdomain) {
|
|
|
42
46
|
}
|
|
43
47
|
function middleware(request, router) {
|
|
44
48
|
function host(...middleware) {
|
|
45
|
-
let instance =
|
|
49
|
+
let instance = (0, pipeline_1.default)(...middleware);
|
|
46
50
|
return () => instance(request);
|
|
47
51
|
}
|
|
48
52
|
;
|
|
@@ -54,7 +58,7 @@ function middleware(request, router) {
|
|
|
54
58
|
return route.dispatch(request);
|
|
55
59
|
};
|
|
56
60
|
host.match = (fallback, scheduler, subdomain) => {
|
|
57
|
-
let state = reactive({
|
|
61
|
+
let state = (0, reactivity_1.reactive)({
|
|
58
62
|
parameters: undefined,
|
|
59
63
|
root: undefined,
|
|
60
64
|
route: undefined
|
|
@@ -62,22 +66,24 @@ function middleware(request, router) {
|
|
|
62
66
|
if (fallback === undefined) {
|
|
63
67
|
throw new Error('Middleware: fallback route does not exist');
|
|
64
68
|
}
|
|
65
|
-
effect(() => {
|
|
69
|
+
(0, reactivity_1.effect)(() => {
|
|
66
70
|
let { parameters, route } = match(request, router, subdomain);
|
|
67
71
|
state.parameters = parameters;
|
|
68
72
|
state.route = route || fallback;
|
|
69
73
|
});
|
|
70
74
|
return (request, next) => {
|
|
71
|
-
return html `${() => {
|
|
75
|
+
return (0, template_1.html) `${() => {
|
|
72
76
|
if (state.route === undefined) {
|
|
73
77
|
throw new Error('Routing: route is undefined');
|
|
74
78
|
}
|
|
75
79
|
if (state.root !== undefined) {
|
|
76
80
|
state.root.dispose();
|
|
77
81
|
}
|
|
78
|
-
return root((root) => {
|
|
79
|
-
request.data
|
|
80
|
-
|
|
82
|
+
return (0, reactivity_1.root)((root) => {
|
|
83
|
+
request.data = {
|
|
84
|
+
parameters: state.parameters,
|
|
85
|
+
route: state.route
|
|
86
|
+
};
|
|
81
87
|
state.root = root;
|
|
82
88
|
return next(request);
|
|
83
89
|
}, scheduler);
|
|
@@ -101,8 +107,8 @@ function onpopstate() {
|
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
}
|
|
104
|
-
|
|
105
|
-
let request = reactive(href()), router = instance ||
|
|
110
|
+
exports.default = (instance) => {
|
|
111
|
+
let request = (0, reactivity_1.reactive)(href()), router = instance || (0, router_1.default)();
|
|
106
112
|
if (cache.push(request) === 1) {
|
|
107
113
|
window.addEventListener('hashchange', onpopstate);
|
|
108
114
|
}
|
package/build/constants.js
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.WILDCARD = exports.STATIC = exports.PLACEHOLDER = void 0;
|
|
1
4
|
const PLACEHOLDER = 0;
|
|
5
|
+
exports.PLACEHOLDER = PLACEHOLDER;
|
|
2
6
|
const STATIC = 1;
|
|
7
|
+
exports.STATIC = STATIC;
|
|
3
8
|
const WILDCARD = 2;
|
|
4
|
-
|
|
9
|
+
exports.WILDCARD = WILDCARD;
|
package/build/index.js
CHANGED
|
@@ -1,5 +1,27 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
17
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.slugify = exports.router = exports.browser = void 0;
|
|
21
|
+
const browser_1 = __importDefault(require("./browser"));
|
|
22
|
+
exports.browser = browser_1.default;
|
|
23
|
+
const router_1 = __importDefault(require("./router"));
|
|
24
|
+
exports.router = router_1.default;
|
|
25
|
+
const slugify_1 = __importDefault(require("./slugify"));
|
|
26
|
+
exports.slugify = slugify_1.default;
|
|
27
|
+
__exportStar(require("./types"), exports);
|
package/build/router/index.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Route = exports.Router = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
5
|
+
const node_1 = require("./node");
|
|
6
|
+
const route_1 = require("./route");
|
|
7
|
+
Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return route_1.Route; } });
|
|
4
8
|
let { isArray } = Array;
|
|
5
9
|
function normalize(path) {
|
|
6
10
|
if (path[0] !== '/') {
|
|
@@ -39,10 +43,10 @@ class Router {
|
|
|
39
43
|
static = {};
|
|
40
44
|
subdomains = null;
|
|
41
45
|
constructor() {
|
|
42
|
-
this.root = new Node();
|
|
46
|
+
this.root = new node_1.Node();
|
|
43
47
|
}
|
|
44
48
|
add(radixkey, route) {
|
|
45
|
-
if (radixkey.indexOf(':') === -1 || this.root.add(radixkey, route).type === STATIC) {
|
|
49
|
+
if (radixkey.indexOf(':') === -1 || this.root.add(radixkey, route).type === constants_1.STATIC) {
|
|
46
50
|
if (this.static[radixkey]) {
|
|
47
51
|
throw new Error(`Routing: static path '${radixkey}' is already in use`);
|
|
48
52
|
}
|
|
@@ -51,7 +55,7 @@ class Router {
|
|
|
51
55
|
return this;
|
|
52
56
|
}
|
|
53
57
|
route({ middleware, name, path, responder, subdomain }) {
|
|
54
|
-
let route = new Route(responder);
|
|
58
|
+
let route = new route_1.Route(responder);
|
|
55
59
|
for (let i = 0, n = this.groups.length; i < n; i++) {
|
|
56
60
|
let { middleware, name, path, subdomain } = this.groups[i];
|
|
57
61
|
set(route, 'name', name);
|
|
@@ -161,5 +165,5 @@ class Router {
|
|
|
161
165
|
return resolved.join('/');
|
|
162
166
|
}
|
|
163
167
|
}
|
|
164
|
-
|
|
165
|
-
|
|
168
|
+
exports.Router = Router;
|
|
169
|
+
exports.default = () => new Router();
|
package/build/router/node.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Node = void 0;
|
|
4
|
+
const constants_1 = require("../constants");
|
|
2
5
|
class Node {
|
|
3
6
|
children = null;
|
|
4
7
|
parent = null;
|
|
@@ -10,7 +13,7 @@ class Node {
|
|
|
10
13
|
this.parent = parent;
|
|
11
14
|
}
|
|
12
15
|
add(path, route) {
|
|
13
|
-
let node = this, segments = path.split('/'), type = STATIC, unnamed = 0;
|
|
16
|
+
let node = this, segments = path.split('/'), type = constants_1.STATIC, unnamed = 0;
|
|
14
17
|
for (let i = 0, n = segments.length; i < n; i++) {
|
|
15
18
|
let child = node.children?.get(segments[i]);
|
|
16
19
|
if (!child) {
|
|
@@ -21,12 +24,12 @@ class Node {
|
|
|
21
24
|
node.children.set(segment, (child = new Node(node)));
|
|
22
25
|
if (symbol === ':') {
|
|
23
26
|
child.property = (segment.slice(1) || unnamed++).toString();
|
|
24
|
-
node.children.set(PLACEHOLDER, child);
|
|
27
|
+
node.children.set(constants_1.PLACEHOLDER, child);
|
|
25
28
|
type = null;
|
|
26
29
|
}
|
|
27
30
|
else if (symbol === '*') {
|
|
28
31
|
child.property = (segment.slice(2) || unnamed++).toString();
|
|
29
|
-
node.children.set(WILDCARD, child);
|
|
32
|
+
node.children.set(constants_1.WILDCARD, child);
|
|
30
33
|
type = null;
|
|
31
34
|
}
|
|
32
35
|
}
|
|
@@ -40,7 +43,7 @@ class Node {
|
|
|
40
43
|
find(path) {
|
|
41
44
|
let node = this, parameters = {}, segments = path.split('/'), wildcard = null;
|
|
42
45
|
for (let i = 0, n = segments.length; i < n; i++) {
|
|
43
|
-
let segment = segments[i], wc = node.children?.get(WILDCARD);
|
|
46
|
+
let segment = segments[i], wc = node.children?.get(constants_1.WILDCARD);
|
|
44
47
|
if (wc) {
|
|
45
48
|
wildcard = {
|
|
46
49
|
node: wc,
|
|
@@ -52,7 +55,7 @@ class Node {
|
|
|
52
55
|
node = next;
|
|
53
56
|
}
|
|
54
57
|
else {
|
|
55
|
-
node = node.children?.get(PLACEHOLDER);
|
|
58
|
+
node = node.children?.get(constants_1.PLACEHOLDER);
|
|
56
59
|
if (!node) {
|
|
57
60
|
break;
|
|
58
61
|
}
|
|
@@ -85,9 +88,9 @@ class Node {
|
|
|
85
88
|
let parent = node.parent;
|
|
86
89
|
if (parent && parent.children) {
|
|
87
90
|
parent.children.delete(segments[segments.length - 1]);
|
|
88
|
-
parent.children.delete(WILDCARD);
|
|
89
|
-
parent.children.delete(PLACEHOLDER);
|
|
91
|
+
parent.children.delete(constants_1.WILDCARD);
|
|
92
|
+
parent.children.delete(constants_1.PLACEHOLDER);
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
|
-
|
|
96
|
+
exports.Node = Node;
|
package/build/router/route.js
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.Route = void 0;
|
|
7
|
+
const pipeline_1 = __importDefault(require("@esportsplus/pipeline"));
|
|
2
8
|
class Route {
|
|
3
9
|
middleware = null;
|
|
4
10
|
name = null;
|
|
@@ -12,7 +18,7 @@ class Route {
|
|
|
12
18
|
if (this.middleware === null) {
|
|
13
19
|
return this.responder(request);
|
|
14
20
|
}
|
|
15
|
-
return
|
|
21
|
+
return (0, pipeline_1.default)(...this.middleware, (request) => this.responder(request))(request);
|
|
16
22
|
}
|
|
17
23
|
}
|
|
18
|
-
|
|
24
|
+
exports.Route = Route;
|
package/build/slugify.js
CHANGED
package/build/types.js
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Router = exports.Route = void 0;
|
|
4
|
+
const router_1 = require("./router");
|
|
5
|
+
Object.defineProperty(exports, "Route", { enumerable: true, get: function () { return router_1.Route; } });
|
|
6
|
+
Object.defineProperty(exports, "Router", { enumerable: true, get: function () { return router_1.Router; } });
|
package/package.json
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"author": "ICJR",
|
|
3
3
|
"dependencies": {
|
|
4
4
|
"@esportsplus/pipeline": "^0.0.5",
|
|
5
|
-
"@esportsplus/reactivity": "^0.1.
|
|
6
|
-
"@esportsplus/template": "^0.1.
|
|
5
|
+
"@esportsplus/reactivity": "^0.1.18",
|
|
6
|
+
"@esportsplus/template": "^0.1.29"
|
|
7
7
|
},
|
|
8
8
|
"devDependencies": {
|
|
9
|
-
"@esportsplus/typescript": "^0.0.
|
|
9
|
+
"@esportsplus/typescript": "^0.0.18"
|
|
10
10
|
},
|
|
11
11
|
"main": "./build/index.js",
|
|
12
12
|
"name": "@esportsplus/routing",
|
|
@@ -18,5 +18,5 @@
|
|
|
18
18
|
"prepublishOnly": "npm run build"
|
|
19
19
|
},
|
|
20
20
|
"types": "./build/index.d.ts",
|
|
21
|
-
"version": "0.0.
|
|
21
|
+
"version": "0.0.41"
|
|
22
22
|
}
|
package/src/browser.ts
CHANGED
|
@@ -16,11 +16,10 @@ function forward() {
|
|
|
16
16
|
window.history.forward();
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
function href<T>()
|
|
19
|
+
function href<T>() {
|
|
20
20
|
let data = new URL( window.location?.href || '' ),
|
|
21
21
|
path = data.hash ? data.hash.slice(1).split('?') : ['/', ''],
|
|
22
|
-
request
|
|
23
|
-
data: {},
|
|
22
|
+
request = {
|
|
24
23
|
href: data.href,
|
|
25
24
|
hostname: data.hostname,
|
|
26
25
|
method: 'GET',
|
|
@@ -28,7 +27,7 @@ function href<T>(): Request<T> {
|
|
|
28
27
|
path: path[0],
|
|
29
28
|
port: data.port,
|
|
30
29
|
protocol: data.protocol,
|
|
31
|
-
query: {}
|
|
30
|
+
query: {} as Record<PropertyKey, unknown>
|
|
32
31
|
};
|
|
33
32
|
|
|
34
33
|
if (path[1]) {
|
|
@@ -37,7 +36,7 @@ function href<T>(): Request<T> {
|
|
|
37
36
|
}
|
|
38
37
|
}
|
|
39
38
|
|
|
40
|
-
return request
|
|
39
|
+
return request as Request<T>;
|
|
41
40
|
}
|
|
42
41
|
|
|
43
42
|
function match<T>(request: Request<T>, router: Router<T>, subdomain?: string) {
|
|
@@ -101,9 +100,10 @@ function middleware<T>(request: Request<T>, router: Router<T>) {
|
|
|
101
100
|
}
|
|
102
101
|
|
|
103
102
|
return root((root) => {
|
|
104
|
-
request.data
|
|
105
|
-
|
|
106
|
-
|
|
103
|
+
request.data = {
|
|
104
|
+
parameters: state.parameters,
|
|
105
|
+
route: state.route
|
|
106
|
+
};
|
|
107
107
|
state.root = root;
|
|
108
108
|
|
|
109
109
|
return next(request);
|