@esportsplus/routing 0.0.42 → 0.0.43
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/.editorconfig +9 -9
- package/.gitattributes +2 -2
- package/.github/dependabot.yml +23 -0
- package/.github/workflows/bump.yml +7 -0
- package/.github/workflows/publish.yml +14 -0
- package/build/browser.d.ts +2 -2
- package/build/browser.js +11 -16
- package/build/constants.js +1 -6
- package/build/index.js +5 -27
- package/build/router/index.js +8 -12
- package/build/router/node.js +9 -12
- package/build/router/route.js +3 -9
- package/build/slugify.js +1 -3
- package/build/types.js +2 -6
- package/package.json +22 -22
- package/src/browser.ts +163 -163
- package/src/constants.ts +7 -7
- package/src/index.ts +7 -7
- package/src/router/index.ts +218 -218
- package/src/router/node.ts +140 -140
- package/src/router/route.ts +27 -27
- package/src/slugify.ts +3 -3
- package/src/types.ts +30 -30
- package/tsconfig.json +10 -9
package/.editorconfig
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
root = true
|
|
2
|
-
|
|
3
|
-
[*]
|
|
4
|
-
indent_style = space
|
|
5
|
-
indent_size = 4
|
|
6
|
-
charset = utf-8
|
|
7
|
-
trim_trailing_whitespace = true
|
|
8
|
-
insert_final_newline = true
|
|
9
|
-
end_of_line = lf
|
|
1
|
+
root = true
|
|
2
|
+
|
|
3
|
+
[*]
|
|
4
|
+
indent_style = space
|
|
5
|
+
indent_size = 4
|
|
6
|
+
charset = utf-8
|
|
7
|
+
trim_trailing_whitespace = true
|
|
8
|
+
insert_final_newline = true
|
|
9
|
+
end_of_line = lf
|
package/.gitattributes
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
# Auto detect text files and perform LF normalization
|
|
2
|
-
* text=auto
|
|
1
|
+
# Auto detect text files and perform LF normalization
|
|
2
|
+
* text=auto
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# To get started with Dependabot version updates, you'll need to specify which
|
|
2
|
+
# package ecosystems to update and where the package manifests are located.
|
|
3
|
+
# Please see the documentation for all configuration options:
|
|
4
|
+
# https://docs.github.com/code-security/dependabot/dependabot-version-updates/configuration-options-for-the-dependabot.yml-file
|
|
5
|
+
|
|
6
|
+
version: 2
|
|
7
|
+
registries:
|
|
8
|
+
npm-npmjs:
|
|
9
|
+
token: ${{secrets.NPM_TOKEN}}
|
|
10
|
+
type: npm-registry
|
|
11
|
+
url: https://registry.npmjs.org
|
|
12
|
+
updates:
|
|
13
|
+
- package-ecosystem: "npm"
|
|
14
|
+
directory: "/"
|
|
15
|
+
groups:
|
|
16
|
+
production-dependencies:
|
|
17
|
+
dependency-type: "production"
|
|
18
|
+
development-dependencies:
|
|
19
|
+
dependency-type: "development"
|
|
20
|
+
registries:
|
|
21
|
+
- npm-npmjs
|
|
22
|
+
schedule:
|
|
23
|
+
interval: "daily"
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
name: publish to npm
|
|
2
|
+
on:
|
|
3
|
+
release:
|
|
4
|
+
types: [published]
|
|
5
|
+
workflow_dispatch:
|
|
6
|
+
workflow_run:
|
|
7
|
+
workflows: [bump]
|
|
8
|
+
types:
|
|
9
|
+
- completed
|
|
10
|
+
jobs:
|
|
11
|
+
publish:
|
|
12
|
+
secrets:
|
|
13
|
+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_PUBLISHING }}
|
|
14
|
+
uses: esportsplus/workflows/.github/workflows/publish.yml@main
|
package/build/browser.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ import { Scheduler } from '@esportsplus/reactivity';
|
|
|
2
2
|
import { Middleware, Next, Request, Route, Router } from './types';
|
|
3
3
|
declare function back(): void;
|
|
4
4
|
declare function forward(): void;
|
|
5
|
-
declare const _default: <T>(instance?: Router<T>
|
|
5
|
+
declare const _default: <T>(instance?: Router<T>) => {
|
|
6
6
|
back: typeof back;
|
|
7
7
|
forward: typeof forward;
|
|
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
|
|
11
|
+
match(fallback: Route<T>, scheduler: Scheduler, subdomain?: string | undefined): (request: Request<T>, next: Next<T>) => import("@esportsplus/template").Renderable;
|
|
12
12
|
};
|
|
13
13
|
redirect: (path: string, values?: unknown[]) => void;
|
|
14
14
|
router: Router<T>;
|
package/build/browser.js
CHANGED
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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"));
|
|
1
|
+
import { effect, reactive, root } from '@esportsplus/reactivity';
|
|
2
|
+
import { html } from '@esportsplus/template';
|
|
3
|
+
import pipeline from '@esportsplus/pipeline';
|
|
4
|
+
import factory from './router';
|
|
10
5
|
let cache = [];
|
|
11
6
|
function back() {
|
|
12
7
|
window.history.back();
|
|
@@ -46,7 +41,7 @@ function match(request, router, subdomain) {
|
|
|
46
41
|
}
|
|
47
42
|
function middleware(request, router) {
|
|
48
43
|
function host(...middleware) {
|
|
49
|
-
let instance = (
|
|
44
|
+
let instance = pipeline(...middleware);
|
|
50
45
|
return () => instance(request);
|
|
51
46
|
}
|
|
52
47
|
;
|
|
@@ -58,7 +53,7 @@ function middleware(request, router) {
|
|
|
58
53
|
return route.dispatch(request);
|
|
59
54
|
};
|
|
60
55
|
host.match = (fallback, scheduler, subdomain) => {
|
|
61
|
-
let state =
|
|
56
|
+
let state = reactive({
|
|
62
57
|
parameters: undefined,
|
|
63
58
|
root: undefined,
|
|
64
59
|
route: undefined
|
|
@@ -66,20 +61,20 @@ function middleware(request, router) {
|
|
|
66
61
|
if (fallback === undefined) {
|
|
67
62
|
throw new Error('Middleware: fallback route does not exist');
|
|
68
63
|
}
|
|
69
|
-
|
|
64
|
+
effect(() => {
|
|
70
65
|
let { parameters, route } = match(request, router, subdomain);
|
|
71
66
|
state.parameters = parameters;
|
|
72
67
|
state.route = route || fallback;
|
|
73
68
|
});
|
|
74
69
|
return (request, next) => {
|
|
75
|
-
return
|
|
70
|
+
return html `${() => {
|
|
76
71
|
if (state.route === undefined) {
|
|
77
72
|
throw new Error('Routing: route is undefined');
|
|
78
73
|
}
|
|
79
74
|
if (state.root !== undefined) {
|
|
80
75
|
state.root.dispose();
|
|
81
76
|
}
|
|
82
|
-
return
|
|
77
|
+
return root((root) => {
|
|
83
78
|
request.data = {
|
|
84
79
|
parameters: state.parameters,
|
|
85
80
|
route: state.route
|
|
@@ -107,8 +102,8 @@ function onpopstate() {
|
|
|
107
102
|
}
|
|
108
103
|
}
|
|
109
104
|
}
|
|
110
|
-
|
|
111
|
-
let request =
|
|
105
|
+
export default (instance) => {
|
|
106
|
+
let request = reactive(Object.assign(href(), { data: {} })), router = instance || factory();
|
|
112
107
|
if (cache.push(request) === 1) {
|
|
113
108
|
window.addEventListener('hashchange', onpopstate);
|
|
114
109
|
}
|
package/build/constants.js
CHANGED
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.WILDCARD = exports.STATIC = exports.PLACEHOLDER = void 0;
|
|
4
1
|
const PLACEHOLDER = 0;
|
|
5
|
-
exports.PLACEHOLDER = PLACEHOLDER;
|
|
6
2
|
const STATIC = 1;
|
|
7
|
-
exports.STATIC = STATIC;
|
|
8
3
|
const WILDCARD = 2;
|
|
9
|
-
|
|
4
|
+
export { PLACEHOLDER, STATIC, WILDCARD };
|
package/build/index.js
CHANGED
|
@@ -1,27 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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);
|
|
1
|
+
import browser from './browser';
|
|
2
|
+
import router from './router';
|
|
3
|
+
import slugify from './slugify';
|
|
4
|
+
export { browser, router, slugify };
|
|
5
|
+
export * from './types';
|
package/build/router/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
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; } });
|
|
1
|
+
import { STATIC } from '../constants';
|
|
2
|
+
import { Node } from './node';
|
|
3
|
+
import { Route } from './route';
|
|
8
4
|
let { isArray } = Array;
|
|
9
5
|
function normalize(path) {
|
|
10
6
|
if (path[0] !== '/') {
|
|
@@ -43,10 +39,10 @@ class Router {
|
|
|
43
39
|
static = {};
|
|
44
40
|
subdomains = null;
|
|
45
41
|
constructor() {
|
|
46
|
-
this.root = new
|
|
42
|
+
this.root = new Node();
|
|
47
43
|
}
|
|
48
44
|
add(radixkey, route) {
|
|
49
|
-
if (radixkey.indexOf(':') === -1 || this.root.add(radixkey, route).type ===
|
|
45
|
+
if (radixkey.indexOf(':') === -1 || this.root.add(radixkey, route).type === STATIC) {
|
|
50
46
|
if (this.static[radixkey]) {
|
|
51
47
|
throw new Error(`Routing: static path '${radixkey}' is already in use`);
|
|
52
48
|
}
|
|
@@ -55,7 +51,7 @@ class Router {
|
|
|
55
51
|
return this;
|
|
56
52
|
}
|
|
57
53
|
route({ middleware, name, path, responder, subdomain }) {
|
|
58
|
-
let route = new
|
|
54
|
+
let route = new Route(responder);
|
|
59
55
|
for (let i = 0, n = this.groups.length; i < n; i++) {
|
|
60
56
|
let { middleware, name, path, subdomain } = this.groups[i];
|
|
61
57
|
set(route, 'name', name);
|
|
@@ -165,5 +161,5 @@ class Router {
|
|
|
165
161
|
return resolved.join('/');
|
|
166
162
|
}
|
|
167
163
|
}
|
|
168
|
-
|
|
169
|
-
|
|
164
|
+
export default () => new Router();
|
|
165
|
+
export { Router, Route };
|
package/build/router/node.js
CHANGED
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.Node = void 0;
|
|
4
|
-
const constants_1 = require("../constants");
|
|
1
|
+
import { PLACEHOLDER, STATIC, WILDCARD } from '../constants';
|
|
5
2
|
class Node {
|
|
6
3
|
children = null;
|
|
7
4
|
parent = null;
|
|
@@ -13,7 +10,7 @@ class Node {
|
|
|
13
10
|
this.parent = parent;
|
|
14
11
|
}
|
|
15
12
|
add(path, route) {
|
|
16
|
-
let node = this, segments = path.split('/'), type =
|
|
13
|
+
let node = this, segments = path.split('/'), type = STATIC, unnamed = 0;
|
|
17
14
|
for (let i = 0, n = segments.length; i < n; i++) {
|
|
18
15
|
let child = node.children?.get(segments[i]);
|
|
19
16
|
if (!child) {
|
|
@@ -24,12 +21,12 @@ class Node {
|
|
|
24
21
|
node.children.set(segment, (child = new Node(node)));
|
|
25
22
|
if (symbol === ':') {
|
|
26
23
|
child.property = (segment.slice(1) || unnamed++).toString();
|
|
27
|
-
node.children.set(
|
|
24
|
+
node.children.set(PLACEHOLDER, child);
|
|
28
25
|
type = null;
|
|
29
26
|
}
|
|
30
27
|
else if (symbol === '*') {
|
|
31
28
|
child.property = (segment.slice(2) || unnamed++).toString();
|
|
32
|
-
node.children.set(
|
|
29
|
+
node.children.set(WILDCARD, child);
|
|
33
30
|
type = null;
|
|
34
31
|
}
|
|
35
32
|
}
|
|
@@ -43,7 +40,7 @@ class Node {
|
|
|
43
40
|
find(path) {
|
|
44
41
|
let node = this, parameters = {}, segments = path.split('/'), wildcard = null;
|
|
45
42
|
for (let i = 0, n = segments.length; i < n; i++) {
|
|
46
|
-
let segment = segments[i], wc = node.children?.get(
|
|
43
|
+
let segment = segments[i], wc = node.children?.get(WILDCARD);
|
|
47
44
|
if (wc) {
|
|
48
45
|
wildcard = {
|
|
49
46
|
node: wc,
|
|
@@ -55,7 +52,7 @@ class Node {
|
|
|
55
52
|
node = next;
|
|
56
53
|
}
|
|
57
54
|
else {
|
|
58
|
-
node = node.children?.get(
|
|
55
|
+
node = node.children?.get(PLACEHOLDER);
|
|
59
56
|
if (!node) {
|
|
60
57
|
break;
|
|
61
58
|
}
|
|
@@ -88,9 +85,9 @@ class Node {
|
|
|
88
85
|
let parent = node.parent;
|
|
89
86
|
if (parent && parent.children) {
|
|
90
87
|
parent.children.delete(segments[segments.length - 1]);
|
|
91
|
-
parent.children.delete(
|
|
92
|
-
parent.children.delete(
|
|
88
|
+
parent.children.delete(WILDCARD);
|
|
89
|
+
parent.children.delete(PLACEHOLDER);
|
|
93
90
|
}
|
|
94
91
|
}
|
|
95
92
|
}
|
|
96
|
-
|
|
93
|
+
export { Node };
|
package/build/router/route.js
CHANGED
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
|
|
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"));
|
|
1
|
+
import pipeline from '@esportsplus/pipeline';
|
|
8
2
|
class Route {
|
|
9
3
|
middleware = null;
|
|
10
4
|
name = null;
|
|
@@ -18,7 +12,7 @@ class Route {
|
|
|
18
12
|
if (this.middleware === null) {
|
|
19
13
|
return this.responder(request);
|
|
20
14
|
}
|
|
21
|
-
return (
|
|
15
|
+
return pipeline(...this.middleware, (request) => this.responder(request))(request);
|
|
22
16
|
}
|
|
23
17
|
}
|
|
24
|
-
|
|
18
|
+
export { Route };
|
package/build/slugify.js
CHANGED
package/build/types.js
CHANGED
|
@@ -1,6 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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; } });
|
|
1
|
+
import { Route, Router } from './router';
|
|
2
|
+
export { Route, Router };
|
package/package.json
CHANGED
|
@@ -1,22 +1,22 @@
|
|
|
1
|
-
{
|
|
2
|
-
"author": "ICJR",
|
|
3
|
-
"dependencies": {
|
|
4
|
-
"@esportsplus/pipeline": "^0.0.5",
|
|
5
|
-
"@esportsplus/reactivity": "^0.1.
|
|
6
|
-
"@esportsplus/template": "^0.1.
|
|
7
|
-
},
|
|
8
|
-
"devDependencies": {
|
|
9
|
-
"@esportsplus/typescript": "^0.0.
|
|
10
|
-
},
|
|
11
|
-
"main": "./build/index.js",
|
|
12
|
-
"name": "@esportsplus/routing",
|
|
13
|
-
"private": false,
|
|
14
|
-
"scripts": {
|
|
15
|
-
"build": "tsc && tsc-alias",
|
|
16
|
-
"-": "-",
|
|
17
|
-
"prepare": "npm run build",
|
|
18
|
-
"prepublishOnly": "npm run build"
|
|
19
|
-
},
|
|
20
|
-
"types": "./build/index.d.ts",
|
|
21
|
-
"version": "0.0.
|
|
22
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"author": "ICJR",
|
|
3
|
+
"dependencies": {
|
|
4
|
+
"@esportsplus/pipeline": "^0.0.5",
|
|
5
|
+
"@esportsplus/reactivity": "^0.1.19",
|
|
6
|
+
"@esportsplus/template": "^0.1.32"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"@esportsplus/typescript": "^0.0.21"
|
|
10
|
+
},
|
|
11
|
+
"main": "./build/index.js",
|
|
12
|
+
"name": "@esportsplus/routing",
|
|
13
|
+
"private": false,
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc && tsc-alias",
|
|
16
|
+
"-": "-",
|
|
17
|
+
"prepare": "npm run build",
|
|
18
|
+
"prepublishOnly": "npm run build"
|
|
19
|
+
},
|
|
20
|
+
"types": "./build/index.d.ts",
|
|
21
|
+
"version": "0.0.43"
|
|
22
|
+
}
|