valyrian.js 7.2.12 → 8.0.1
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/README.md +6 -6
- package/dist/flux-store/index.d.ts +32 -0
- package/dist/flux-store/index.d.ts.map +1 -0
- package/dist/flux-store/index.js +267 -0
- package/dist/flux-store/index.js.map +7 -0
- package/dist/flux-store/index.min.js +1 -0
- package/dist/flux-store/index.min.js.map +1 -0
- package/dist/flux-store/index.mjs +246 -0
- package/dist/flux-store/index.mjs.map +7 -0
- package/dist/hooks/index.d.ts.map +1 -1
- package/dist/hooks/index.js +35 -51
- package/dist/hooks/index.js.map +3 -3
- package/dist/hooks/index.min.js +1 -0
- package/dist/hooks/index.min.js.map +1 -0
- package/dist/hooks/index.mjs +36 -52
- package/dist/hooks/index.mjs.map +3 -3
- package/dist/index.d.ts +18 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +107 -88
- package/dist/index.js.map +3 -3
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/index.mjs +107 -88
- package/dist/index.mjs.map +3 -3
- package/dist/native-store/index.d.ts +14 -0
- package/dist/native-store/index.d.ts.map +1 -0
- package/dist/native-store/index.js +103 -0
- package/dist/native-store/index.js.map +7 -0
- package/dist/native-store/index.min.js +1 -0
- package/dist/native-store/index.min.js.map +1 -0
- package/dist/native-store/index.mjs +82 -0
- package/dist/native-store/index.mjs.map +7 -0
- package/dist/node/index.d.ts +1 -1
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +125 -10
- package/dist/node/index.js.map +4 -4
- package/dist/node/index.mjs +125 -10
- package/dist/node/index.mjs.map +4 -4
- package/dist/node/node.sw.js +152 -0
- package/dist/node/utils/icons.d.ts +4 -5
- package/dist/node/utils/icons.d.ts.map +1 -1
- package/dist/node/utils/inline.d.ts +1 -1
- package/dist/node/utils/inline.d.ts.map +1 -1
- package/dist/node/utils/node.sw.js +152 -0
- package/dist/node/utils/session-storage.d.ts +22 -0
- package/dist/node/utils/session-storage.d.ts.map +1 -0
- package/dist/node/utils/sw.d.ts.map +1 -1
- package/dist/node/utils/tree-adapter.d.ts +5 -1
- package/dist/node/utils/tree-adapter.d.ts.map +1 -1
- package/dist/pulse-store/index.d.ts +16 -0
- package/dist/pulse-store/index.d.ts.map +1 -0
- package/dist/pulse-store/index.js +143 -0
- package/dist/pulse-store/index.js.map +7 -0
- package/dist/pulse-store/index.min.js +1 -0
- package/dist/pulse-store/index.min.js.map +1 -0
- package/dist/pulse-store/index.mjs +122 -0
- package/dist/pulse-store/index.mjs.map +7 -0
- package/dist/request/index.d.ts +11 -11
- package/dist/request/index.d.ts.map +1 -1
- package/dist/request/index.js +63 -84
- package/dist/request/index.js.map +2 -2
- package/dist/request/index.min.js +1 -0
- package/dist/request/index.min.js.map +1 -0
- package/dist/request/index.mjs +63 -84
- package/dist/request/index.mjs.map +2 -2
- package/dist/router/index.d.ts +36 -33
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js +247 -96
- package/dist/router/index.js.map +3 -3
- package/dist/router/index.min.js +1 -0
- package/dist/router/index.min.js.map +1 -0
- package/dist/router/index.mjs +247 -96
- package/dist/router/index.mjs.map +3 -3
- package/dist/signals/index.d.ts +6 -0
- package/dist/signals/index.d.ts.map +1 -0
- package/dist/signals/index.js +92 -0
- package/dist/signals/index.js.map +7 -0
- package/dist/signals/index.min.js +1 -0
- package/dist/signals/index.min.js.map +1 -0
- package/dist/signals/index.mjs +71 -0
- package/dist/signals/index.mjs.map +7 -0
- package/dist/suspense/index.d.ts +6 -0
- package/dist/suspense/index.d.ts.map +1 -0
- package/dist/suspense/index.js +67 -0
- package/dist/suspense/index.js.map +7 -0
- package/dist/suspense/index.min.js +1 -0
- package/dist/suspense/index.min.js.map +1 -0
- package/dist/suspense/index.mjs +46 -0
- package/dist/suspense/index.mjs.map +7 -0
- package/dist/sw/index.min.js +1 -0
- package/dist/sw/index.min.js.map +1 -0
- package/dist/translate/index.d.ts +19 -0
- package/dist/translate/index.d.ts.map +1 -0
- package/dist/translate/index.js +150 -0
- package/dist/translate/index.js.map +7 -0
- package/dist/translate/index.min.js +1 -0
- package/dist/translate/index.min.js.map +1 -0
- package/dist/translate/index.mjs +129 -0
- package/dist/translate/index.mjs.map +7 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/deep-freeze.d.ts +3 -0
- package/dist/utils/deep-freeze.d.ts.map +1 -0
- package/dist/utils/getter-setter.d.ts +3 -0
- package/dist/utils/getter-setter.d.ts.map +1 -0
- package/dist/utils/has-changed.d.ts +2 -0
- package/dist/utils/has-changed.d.ts.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +138 -0
- package/dist/utils/index.js.map +7 -0
- package/dist/utils/index.min.js +1 -0
- package/dist/utils/index.min.js.map +1 -0
- package/dist/utils/index.mjs +115 -0
- package/dist/utils/index.mjs.map +7 -0
- package/lib/flux-store/index.ts +312 -0
- package/lib/hooks/index.ts +39 -57
- package/lib/index.ts +135 -118
- package/lib/native-store/index.ts +106 -0
- package/lib/node/index.ts +3 -1
- package/lib/node/utils/icons.ts +4 -4
- package/lib/node/utils/inline.ts +2 -0
- package/lib/node/utils/node.sw.js +152 -0
- package/lib/node/utils/session-storage.ts +117 -0
- package/lib/node/utils/sw.ts +34 -10
- package/lib/node/utils/tree-adapter.ts +19 -1
- package/lib/pulse-store/index.ts +188 -0
- package/lib/request/index.ts +92 -122
- package/lib/router/index.ts +353 -164
- package/lib/signals/index.ts +98 -0
- package/lib/suspense/index.ts +57 -0
- package/lib/translate/index.ts +156 -0
- package/lib/utils/deep-freeze.ts +54 -0
- package/lib/utils/getter-setter.ts +40 -0
- package/lib/utils/has-changed.ts +43 -0
- package/lib/utils/index.ts +3 -0
- package/package.json +40 -57
- package/tsconfig.json +5 -4
- package/dist/dataset/index.d.ts +0 -24
- package/dist/dataset/index.d.ts.map +0 -1
- package/dist/dataset/index.js +0 -178
- package/dist/dataset/index.js.map +0 -7
- package/dist/dataset/index.mjs +0 -157
- package/dist/dataset/index.mjs.map +0 -7
- package/dist/node/node.sw.tpl +0 -133
- package/dist/node/utils/node.sw.tpl +0 -133
- package/dist/proxy-signal/index.d.ts +0 -23
- package/dist/proxy-signal/index.d.ts.map +0 -1
- package/dist/proxy-signal/index.js +0 -138
- package/dist/proxy-signal/index.js.map +0 -7
- package/dist/proxy-signal/index.mjs +0 -117
- package/dist/proxy-signal/index.mjs.map +0 -7
- package/dist/signal/index.d.ts +0 -9
- package/dist/signal/index.d.ts.map +0 -1
- package/dist/signal/index.js +0 -76
- package/dist/signal/index.js.map +0 -7
- package/dist/signal/index.mjs +0 -55
- package/dist/signal/index.mjs.map +0 -7
- package/dist/store/index.d.ts +0 -16
- package/dist/store/index.d.ts.map +0 -1
- package/dist/store/index.js +0 -93
- package/dist/store/index.js.map +0 -7
- package/dist/store/index.mjs +0 -72
- package/dist/store/index.mjs.map +0 -7
- package/lib/dataset/index.ts +0 -193
- package/lib/node/utils/node.sw.tpl +0 -133
- package/lib/proxy-signal/index.ts +0 -187
- package/lib/signal/index.ts +0 -86
- package/lib/store/index.ts +0 -101
package/dist/router/index.mjs
CHANGED
|
@@ -21,83 +21,85 @@ function getPathWithoutLastSlash(path) {
|
|
|
21
21
|
}
|
|
22
22
|
return pathWithoutLastSlash;
|
|
23
23
|
}
|
|
24
|
-
var addPath = ({
|
|
25
|
-
router,
|
|
26
|
-
method,
|
|
27
|
-
path,
|
|
28
|
-
middlewares
|
|
29
|
-
}) => {
|
|
30
|
-
if (!method || !path || !Array.isArray(middlewares) || middlewares.length === 0) {
|
|
31
|
-
throw new Error(`Invalid route input: ${method} ${path} ${middlewares}`);
|
|
32
|
-
}
|
|
33
|
-
const realpath = path.replace(/(\S)(\/+)$/, "$1");
|
|
34
|
-
const params = (realpath.match(/:(\w+)?/gi) || []).map((param) => param.slice(1));
|
|
35
|
-
const regexpPath = "^" + realpath.replace(/:(\w+)/gi, "([^\\/\\s]+)") + "$";
|
|
36
|
-
router.paths.push({
|
|
37
|
-
method,
|
|
38
|
-
path: realpath,
|
|
39
|
-
middlewares: flat(middlewares),
|
|
40
|
-
params,
|
|
41
|
-
regexp: new RegExp(regexpPath, "i")
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
24
|
function parseQuery(queryParts) {
|
|
45
25
|
const parts = queryParts ? queryParts.split("&") : [];
|
|
46
26
|
const query = {};
|
|
47
27
|
for (const nameValue of parts) {
|
|
48
28
|
const [name, value] = nameValue.split("=", 2);
|
|
49
|
-
query[name] = value
|
|
29
|
+
query[name] = isNaN(Number(value)) === false ? Number(value) : value === "true" ? true : value === "false" ? false : value;
|
|
50
30
|
}
|
|
51
31
|
return query;
|
|
52
32
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
break;
|
|
33
|
+
var RouteTree = class {
|
|
34
|
+
root = { segment: "", children: /* @__PURE__ */ new Map(), isDynamic: false };
|
|
35
|
+
addRoute(path, middlewares) {
|
|
36
|
+
const segments = path === "/" ? [path] : path.split("/").filter(Boolean);
|
|
37
|
+
let currentNode = this.root;
|
|
38
|
+
for (const segment of segments) {
|
|
39
|
+
const isDynamic = segment.startsWith(":");
|
|
40
|
+
const key = isDynamic ? ":" : segment;
|
|
41
|
+
if (!currentNode.children.has(key)) {
|
|
42
|
+
currentNode.children.set(key, {
|
|
43
|
+
segment,
|
|
44
|
+
children: /* @__PURE__ */ new Map(),
|
|
45
|
+
isDynamic,
|
|
46
|
+
paramKey: isDynamic ? segment.slice(1) : void 0
|
|
47
|
+
});
|
|
69
48
|
}
|
|
49
|
+
currentNode = currentNode.children.get(key);
|
|
70
50
|
}
|
|
51
|
+
currentNode.middlewares = middlewares;
|
|
71
52
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
params
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
53
|
+
// Search for a route in the tree
|
|
54
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
55
|
+
findRoute(path) {
|
|
56
|
+
const pathWithoutLastSlash = getPathWithoutLastSlash(path);
|
|
57
|
+
const segments = pathWithoutLastSlash === "/" ? [pathWithoutLastSlash] : pathWithoutLastSlash.split("/").filter(Boolean);
|
|
58
|
+
let currentNode = this.root;
|
|
59
|
+
const params = {};
|
|
60
|
+
const wildcardMiddlewares = [];
|
|
61
|
+
const segmentsLength = segments.length;
|
|
62
|
+
for (let i = 0; i < segmentsLength; i++) {
|
|
63
|
+
if (!currentNode) {
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
const segment = segments[i];
|
|
67
|
+
let found = false;
|
|
68
|
+
for (const [key, child] of currentNode.children) {
|
|
69
|
+
if (key === segment) {
|
|
70
|
+
currentNode = child;
|
|
71
|
+
found = true;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
if (segment !== ".*" && key === ":") {
|
|
75
|
+
currentNode = child;
|
|
76
|
+
params[child.paramKey] = segment;
|
|
77
|
+
found = true;
|
|
78
|
+
break;
|
|
79
|
+
}
|
|
80
|
+
if (key === ".*" && !found) {
|
|
81
|
+
wildcardMiddlewares.push(...child.middlewares || []);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (!found) {
|
|
85
|
+
if (currentNode.children.has(".*")) {
|
|
86
|
+
return { middlewares: wildcardMiddlewares, params };
|
|
87
|
+
}
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
96
90
|
}
|
|
91
|
+
const allMiddlewares = [...wildcardMiddlewares, ...currentNode.middlewares || []];
|
|
92
|
+
if (allMiddlewares.length === 0) {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
return { middlewares: allMiddlewares, params };
|
|
97
96
|
}
|
|
98
|
-
}
|
|
97
|
+
};
|
|
98
|
+
var RouterError = class RouterError2 extends Error {
|
|
99
|
+
status = 500;
|
|
100
|
+
};
|
|
99
101
|
var Router = class _Router {
|
|
100
|
-
|
|
102
|
+
routeTree = new RouteTree();
|
|
101
103
|
container = null;
|
|
102
104
|
query = {};
|
|
103
105
|
options = {};
|
|
@@ -106,55 +108,93 @@ var Router = class _Router {
|
|
|
106
108
|
params = {};
|
|
107
109
|
matches = [];
|
|
108
110
|
pathPrefix = "";
|
|
111
|
+
errorHandlers = /* @__PURE__ */ new Map();
|
|
109
112
|
constructor(pathPrefix = "") {
|
|
110
113
|
this.pathPrefix = pathPrefix;
|
|
111
114
|
}
|
|
112
|
-
add(
|
|
113
|
-
const
|
|
114
|
-
addPath({ router: this, method: "add", path: pathWithoutLastSlash, middlewares });
|
|
115
|
-
return this;
|
|
116
|
-
}
|
|
117
|
-
use(...middlewares) {
|
|
115
|
+
add(...args) {
|
|
116
|
+
const flatArgs = flat(args);
|
|
118
117
|
const path = getPathWithoutLastSlash(
|
|
119
|
-
`${this.pathPrefix}${typeof
|
|
118
|
+
`${this.pathPrefix}${typeof flatArgs[0] === "string" ? flatArgs.shift() : "/.*"}`
|
|
120
119
|
);
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
continue;
|
|
120
|
+
if (flatArgs.length === 1 && flatArgs[0] instanceof _Router) {
|
|
121
|
+
const subrouter = flatArgs[0];
|
|
122
|
+
for (const subroute of subrouter.routes()) {
|
|
123
|
+
const subroutePath = `${path}${subroute}`;
|
|
124
|
+
this.routeTree.addRoute(subroutePath, subrouter.routeTree.findRoute(subroute).middlewares || []);
|
|
125
|
+
}
|
|
126
|
+
} else {
|
|
127
|
+
if (flatArgs.some((item) => item instanceof _Router)) {
|
|
128
|
+
throw new RouterError("You cannot add middlewares when adding a subrouter.");
|
|
133
129
|
}
|
|
134
|
-
if (typeof item
|
|
135
|
-
|
|
130
|
+
if (flatArgs.some((item) => typeof item !== "function")) {
|
|
131
|
+
throw new RouterError("All middlewares must be functions.");
|
|
136
132
|
}
|
|
133
|
+
this.routeTree.addRoute(path, flatArgs);
|
|
137
134
|
}
|
|
138
135
|
return this;
|
|
139
136
|
}
|
|
137
|
+
catch(...args) {
|
|
138
|
+
const condition = typeof args[0] === "number" || typeof args[0] === "string" || args[0].name.includes("Error") ? args.shift() : "generic";
|
|
139
|
+
if (typeof condition !== "number" && typeof condition !== "string" && !condition.name.includes("Error")) {
|
|
140
|
+
throw new RouterError("The condition must be a number, string or an instance of Error.");
|
|
141
|
+
}
|
|
142
|
+
if (args.some((item) => typeof item !== "function")) {
|
|
143
|
+
throw new RouterError("All middlewares must be functions.");
|
|
144
|
+
}
|
|
145
|
+
let handlers = this.errorHandlers.get(condition);
|
|
146
|
+
if (!handlers) {
|
|
147
|
+
handlers = [];
|
|
148
|
+
this.errorHandlers.set(condition, handlers);
|
|
149
|
+
}
|
|
150
|
+
handlers.push(...args);
|
|
151
|
+
return this;
|
|
152
|
+
}
|
|
140
153
|
routes() {
|
|
141
|
-
return this.
|
|
154
|
+
return this.getAllRoutes(this.routeTree.root, "");
|
|
142
155
|
}
|
|
143
|
-
|
|
156
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
157
|
+
async go(path, parentComponent) {
|
|
144
158
|
if (!path) {
|
|
145
|
-
|
|
159
|
+
return this.handleError(new RouterError("The URL is empty."), parentComponent);
|
|
160
|
+
}
|
|
161
|
+
if (/%[^0-9A-Fa-f]{2}/.test(path)) {
|
|
162
|
+
return this.handleError(new RouterError(`The URL ${path} is malformed.`));
|
|
146
163
|
}
|
|
147
164
|
const constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);
|
|
148
165
|
const parts = constructedPath.split("?", 2);
|
|
149
166
|
this.url = constructedPath;
|
|
150
167
|
this.query = parseQuery(parts[1]);
|
|
151
|
-
const
|
|
152
|
-
|
|
168
|
+
const finalPath = parts[0].replace(/(.+)\/$/, "$1").split("#")[0];
|
|
169
|
+
this.path = path;
|
|
170
|
+
let route = this.routeTree.findRoute(finalPath);
|
|
171
|
+
if (!route || !route.middlewares) {
|
|
172
|
+
const finalPathParts = finalPath.split("/");
|
|
173
|
+
while (finalPathParts.length > 0) {
|
|
174
|
+
finalPathParts.pop();
|
|
175
|
+
const wildcardRoute = this.routeTree.findRoute(finalPathParts.join("/") + "/.*");
|
|
176
|
+
if (wildcardRoute) {
|
|
177
|
+
route = wildcardRoute;
|
|
178
|
+
break;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
if (!route || !route.middlewares) {
|
|
182
|
+
const error = new RouterError(`The URL ${constructedPath} was not found in the router's registered paths.`);
|
|
183
|
+
error.status = 404;
|
|
184
|
+
return this.handleError(error, parentComponent);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
const { middlewares, params } = route;
|
|
188
|
+
this.params = params;
|
|
189
|
+
let component = await this.searchComponent(middlewares, parentComponent);
|
|
153
190
|
if (component === false) {
|
|
154
191
|
return;
|
|
155
192
|
}
|
|
156
193
|
if (!component) {
|
|
157
|
-
|
|
194
|
+
return this.handleError(
|
|
195
|
+
new RouterError(`The URL ${constructedPath} did not return a valid component.`),
|
|
196
|
+
parentComponent
|
|
197
|
+
);
|
|
158
198
|
}
|
|
159
199
|
if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {
|
|
160
200
|
const childComponent = isVnodeComponent(component) ? component : v(component, {});
|
|
@@ -165,7 +205,7 @@ var Router = class _Router {
|
|
|
165
205
|
component = v(parentComponent, {}, childComponent);
|
|
166
206
|
}
|
|
167
207
|
}
|
|
168
|
-
if (!isNodeJs &&
|
|
208
|
+
if (!isNodeJs && window.location.pathname + window.location.search !== constructedPath) {
|
|
169
209
|
window.history.pushState(null, "", constructedPath);
|
|
170
210
|
}
|
|
171
211
|
if (this.container) {
|
|
@@ -174,17 +214,128 @@ var Router = class _Router {
|
|
|
174
214
|
}
|
|
175
215
|
getOnClickHandler(url) {
|
|
176
216
|
return (e) => {
|
|
217
|
+
if (e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.defaultPrevented) {
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
177
220
|
if (typeof url === "string" && url.length > 0) {
|
|
178
221
|
this.go(url);
|
|
179
222
|
}
|
|
180
223
|
e.preventDefault();
|
|
181
224
|
};
|
|
182
225
|
}
|
|
226
|
+
getAllRoutes(node, prefix) {
|
|
227
|
+
const routes = [];
|
|
228
|
+
for (const [key, child] of node.children) {
|
|
229
|
+
const newPrefix = `${prefix}/${child.isDynamic ? `:${child.paramKey}` : key}`.replace(/\/$/, "");
|
|
230
|
+
if (child.middlewares) {
|
|
231
|
+
routes.push(newPrefix);
|
|
232
|
+
}
|
|
233
|
+
routes.push(...this.getAllRoutes(child, newPrefix));
|
|
234
|
+
}
|
|
235
|
+
return routes;
|
|
236
|
+
}
|
|
237
|
+
createRequest() {
|
|
238
|
+
return {
|
|
239
|
+
params: this.params,
|
|
240
|
+
query: this.query,
|
|
241
|
+
url: this.url,
|
|
242
|
+
path: this.path,
|
|
243
|
+
matches: this.matches,
|
|
244
|
+
redirect: (path) => this.go(path)
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
getErrorConditionMiddlewares(error) {
|
|
248
|
+
for (const [condition, middlewares] of this.errorHandlers) {
|
|
249
|
+
if (typeof condition !== "number" && typeof condition !== "string" && error instanceof condition && error.name === condition.name) {
|
|
250
|
+
return middlewares;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const [condition, middlewares] of this.errorHandlers) {
|
|
254
|
+
if (typeof condition === "number" && (error.status === condition || error.code === condition)) {
|
|
255
|
+
return middlewares;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
for (const [condition, middlewares] of this.errorHandlers) {
|
|
259
|
+
if (typeof condition === "string" && (error.name === condition || error.message.includes(condition))) {
|
|
260
|
+
return middlewares;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
return this.errorHandlers.get("generic") || false;
|
|
264
|
+
}
|
|
265
|
+
// eslint-disable-next-line sonarjs/cognitive-complexity
|
|
266
|
+
async handleError(error, parentComponent) {
|
|
267
|
+
const request = this.createRequest();
|
|
268
|
+
let component = null;
|
|
269
|
+
const middlewares = this.getErrorConditionMiddlewares(error);
|
|
270
|
+
if (middlewares === false) {
|
|
271
|
+
throw error;
|
|
272
|
+
}
|
|
273
|
+
let response;
|
|
274
|
+
try {
|
|
275
|
+
for (const middleware of middlewares) {
|
|
276
|
+
response = await middleware(request, error);
|
|
277
|
+
if (response !== void 0 && (isComponent(response) || isVnodeComponent(response))) {
|
|
278
|
+
component = response;
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
if (response === false) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
} catch (err) {
|
|
286
|
+
err.cause = error;
|
|
287
|
+
let errorCauseCount = 0;
|
|
288
|
+
while (err.cause) {
|
|
289
|
+
errorCauseCount++;
|
|
290
|
+
}
|
|
291
|
+
if (errorCauseCount > 20) {
|
|
292
|
+
throw new RouterError("Too many error causes. Possible circular error handling.");
|
|
293
|
+
}
|
|
294
|
+
return this.handleError(err, parentComponent);
|
|
295
|
+
}
|
|
296
|
+
if (component) {
|
|
297
|
+
if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {
|
|
298
|
+
const childComponent = isVnodeComponent(component) ? component : v(component, {});
|
|
299
|
+
if (isVnodeComponent(parentComponent)) {
|
|
300
|
+
parentComponent.children.push(childComponent);
|
|
301
|
+
component = parentComponent;
|
|
302
|
+
} else {
|
|
303
|
+
component = v(parentComponent, {}, childComponent);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
if (!isNodeJs && window.location.pathname + window.location.search !== this.url) {
|
|
307
|
+
window.history.pushState(null, "", this.url);
|
|
308
|
+
}
|
|
309
|
+
if (this.container) {
|
|
310
|
+
return mount(this.container, component);
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
throw error;
|
|
314
|
+
}
|
|
315
|
+
async searchComponent(middlewares, parentComponent) {
|
|
316
|
+
const request = this.createRequest();
|
|
317
|
+
let response;
|
|
318
|
+
for (const middleware of middlewares) {
|
|
319
|
+
try {
|
|
320
|
+
response = await middleware(request);
|
|
321
|
+
} catch (error) {
|
|
322
|
+
return this.handleError(error, parentComponent);
|
|
323
|
+
}
|
|
324
|
+
if (response !== void 0 && (isComponent(response) || isVnodeComponent(response))) {
|
|
325
|
+
return response;
|
|
326
|
+
}
|
|
327
|
+
if (response === false) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
}
|
|
331
|
+
return response;
|
|
332
|
+
}
|
|
183
333
|
};
|
|
184
334
|
var localRedirect;
|
|
185
|
-
function redirect(url, parentComponent, preventPushState = false) {
|
|
335
|
+
async function redirect(url, parentComponent, preventPushState = false) {
|
|
186
336
|
if (!localRedirect) {
|
|
187
|
-
|
|
337
|
+
console.warn("Redirect function is not initialized. Please mount the router first.");
|
|
338
|
+
return;
|
|
188
339
|
}
|
|
189
340
|
return localRedirect(url, parentComponent, preventPushState);
|
|
190
341
|
}
|
|
@@ -194,20 +345,20 @@ function mountRouter(elementContainer, router) {
|
|
|
194
345
|
if (!isNodeJs) {
|
|
195
346
|
let onPopStateGoToRoute2 = function() {
|
|
196
347
|
const pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);
|
|
197
|
-
router.go(pathWithoutPrefix
|
|
348
|
+
router.go(pathWithoutPrefix);
|
|
198
349
|
};
|
|
199
350
|
var onPopStateGoToRoute = onPopStateGoToRoute2;
|
|
200
351
|
window.addEventListener("popstate", onPopStateGoToRoute2, false);
|
|
201
352
|
onPopStateGoToRoute2();
|
|
202
353
|
}
|
|
203
|
-
directive("route", (vnode) => {
|
|
204
|
-
const url = vnode.props["v-route"];
|
|
354
|
+
directive("route", (url, vnode) => {
|
|
205
355
|
setAttribute("href", url, vnode);
|
|
206
356
|
setAttribute("onclick", router.getOnClickHandler(url), vnode);
|
|
207
357
|
});
|
|
208
358
|
}
|
|
209
359
|
export {
|
|
210
360
|
Router,
|
|
361
|
+
RouterError,
|
|
211
362
|
mountRouter,
|
|
212
363
|
redirect
|
|
213
364
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../lib/router/index.ts"],
|
|
4
|
-
"sourcesContent": ["/* eslint-disable no-use-before-define */\nimport {\n Component,\n POJOComponent,\n VnodeComponentInterface,\n VnodeWithDom,\n directive,\n isComponent,\n isNodeJs,\n isVnodeComponent,\n mount,\n setAttribute,\n v\n} from \"valyrian.js\";\n\ninterface Request {\n params: Record<string, any>;\n query: Record<string, any>;\n url: string;\n path: string;\n matches: string[];\n // eslint-disable-next-line no-unused-vars\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => false;\n}\n\ninterface Middleware {\n // eslint-disable-next-line no-unused-vars\n (req: Request, res?: any):\n | Promise<any | Component | POJOComponent | VnodeComponentInterface>\n | any\n | Component\n | POJOComponent\n | VnodeComponentInterface;\n}\n\ninterface Middlewares extends Array<Middleware> {}\n\ninterface Path {\n method: string;\n path: string;\n middlewares: Middlewares;\n params: string[];\n regexp: RegExp;\n}\n\ninterface RouterInterface {\n paths: Path[];\n container: Element | string | null;\n query: Record<string, string | number>;\n options: Record<string, any>;\n url: string;\n path: string;\n params: Record<string, string | number | any>;\n matches: string[];\n pathPrefix: string;\n // eslint-disable-next-line no-unused-vars\n add(method: string, ...args: Middlewares): Router;\n // eslint-disable-next-line no-unused-vars\n use(...args: (string | Middleware | Router)[]): Router;\n\n routes(): string[];\n // eslint-disable-next-line no-unused-vars\n go(path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface): Promise<string | void>;\n}\n\ninterface RedirectFunction {\n // eslint-disable-next-line no-unused-vars\n (\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState?: boolean\n ): Promise<string | void>;\n}\n\nfunction flat(array: any) {\n return Array.isArray(array) ? array.flat(Infinity) : [array];\n}\n\nfunction getPathWithoutPrefix(path: string, prefix: string) {\n return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), \"\"));\n}\n\nfunction getPathWithoutLastSlash(path: string) {\n let pathWithoutLastSlash = path.replace(/\\/$/, \"\");\n if (pathWithoutLastSlash === \"\") {\n pathWithoutLastSlash = \"/\";\n }\n return pathWithoutLastSlash;\n}\n\nconst addPath = ({\n router,\n method,\n path,\n middlewares\n}: {\n router: Router;\n method: string;\n path: string;\n middlewares: Middleware[];\n}): void => {\n if (!method || !path || !Array.isArray(middlewares) || middlewares.length === 0) {\n throw new Error(`Invalid route input: ${method} ${path} ${middlewares}`);\n }\n\n // Trim trailing slashes from the path\n const realpath = path.replace(/(\\S)(\\/+)$/, \"$1\");\n\n // Find the express-like params in the path\n const params = (realpath.match(/:(\\w+)?/gi) || [])\n // Set the names of the params found\n .map((param) => param.slice(1));\n\n // Generate a regular expression to match the path\n const regexpPath = \"^\" + realpath.replace(/:(\\w+)/gi, \"([^\\\\/\\\\s]+)\") + \"$\";\n\n router.paths.push({\n method,\n path: realpath,\n middlewares: flat(middlewares),\n params,\n regexp: new RegExp(regexpPath, \"i\")\n });\n};\n\n// Parse a query string into an object\nfunction parseQuery(queryParts?: string): Record<string, string> {\n // Split the query string into an array of name-value pairs\n const parts = queryParts ? queryParts.split(\"&\") : [];\n const query: Record<string, string> = {};\n\n // Iterate over the name-value pairs and add them to the query object\n for (const nameValue of parts) {\n const [name, value] = nameValue.split(\"=\", 2);\n query[name] = value || \"\";\n }\n\n return query;\n}\n\n// Search for middlewares that match a given path\nfunction searchMiddlewares(router: RouterInterface, path: string): Middlewares {\n const middlewares: Middlewares = [];\n const params: Record<string, any> = {};\n const matches = [];\n\n // Search for middlewares\n for (const item of router.paths) {\n const match = item.regexp.exec(path);\n\n // If we found middlewares\n if (Array.isArray(match)) {\n middlewares.push(...item.middlewares);\n match.shift();\n\n // Parse params\n for (const [index, key] of item.params.entries()) {\n params[key] = match[index];\n }\n\n // Add remaining matches to the array\n matches.push(...match);\n\n if (item.method === \"add\") {\n router.path = getPathWithoutPrefix(item.path, router.pathPrefix);\n break;\n }\n }\n }\n\n router.params = params;\n router.matches = matches;\n\n return middlewares;\n}\n\nasync function searchComponent(\n router: RouterInterface,\n middlewares: Middlewares\n): Promise<Component | VnodeComponentInterface | false | void> {\n // Define request object with default values\n const request: Request = {\n params: router.params,\n query: router.query,\n url: router.url,\n path: router.path,\n matches: router.matches,\n redirect: (path: string, parentComponent?: Component | POJOComponent | VnodeComponentInterface) => {\n router.go(path, parentComponent);\n // Return false to stop the middleware chain\n return false;\n }\n };\n\n // Initialize response variable\n let response;\n\n // Iterate through middlewares\n for (const middleware of middlewares) {\n // Invoke middleware and update response\n response = await middleware(request, response);\n\n // Return response if it's a valid component\n if (response !== undefined && (isComponent(response) || isVnodeComponent(response))) {\n return response;\n }\n\n // Return false if response is explicitly false to stop the middleware chain\n if (response === false) {\n return false;\n }\n }\n}\n\nexport class Router implements RouterInterface {\n paths: Path[] = [];\n container: Element | string | null = null;\n query: Record<string, string | number> = {};\n options: Record<string, any> = {};\n url: string = \"\";\n path: string = \"\";\n params: Record<string, string | number | any> = {};\n matches: string[] = [];\n pathPrefix: string = \"\";\n\n constructor(pathPrefix: string = \"\") {\n this.pathPrefix = pathPrefix;\n }\n\n add(path: string, ...middlewares: Middlewares): Router {\n const pathWithoutLastSlash = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n addPath({ router: this, method: \"add\", path: pathWithoutLastSlash, middlewares });\n return this;\n }\n\n use(...middlewares: Middlewares | Router[] | string[]): Router {\n const path = getPathWithoutLastSlash(\n `${this.pathPrefix}${typeof middlewares[0] === \"string\" ? middlewares.shift() : \"/\"}`\n );\n\n for (const item of middlewares) {\n if (item instanceof Router) {\n const subrouter = item as Router;\n for (const subpath of subrouter.paths) {\n addPath({\n router: this,\n method: subpath.method,\n path: `${path}${subpath.path}`.replace(/^\\/\\//, \"/\"),\n middlewares: subpath.middlewares\n });\n }\n continue;\n }\n\n if (typeof item === \"function\") {\n addPath({ router: this, method: \"use\", path: `${path}.*`, middlewares: [item as Middleware] });\n }\n }\n\n return this;\n }\n\n routes(): string[] {\n return this.paths.filter((path) => path.method === \"add\").map((path) => path.path);\n }\n\n async go(\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n ): Promise<string | void> {\n if (!path) {\n throw new Error(\"router.url.required\");\n }\n\n const constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n const parts = constructedPath.split(\"?\", 2);\n this.url = constructedPath;\n this.query = parseQuery(parts[1]);\n\n const middlewares = searchMiddlewares(this as RouterInterface, parts[0].replace(/(.+)\\/$/, \"$1\").split(\"#\")[0]);\n let component = await searchComponent(this as RouterInterface, middlewares);\n\n if (component === false) {\n return;\n }\n\n if (!component) {\n throw new Error(`The url ${constructedPath} requested wasn't found`);\n }\n\n if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {\n const childComponent = isVnodeComponent(component) ? component : v(component as Component, {});\n if (isVnodeComponent(parentComponent)) {\n parentComponent.children.push(childComponent);\n component = parentComponent;\n } else {\n component = v(parentComponent, {}, childComponent) as VnodeComponentInterface;\n }\n }\n\n if (!isNodeJs && !preventPushState) {\n window.history.pushState(null, \"\", constructedPath);\n }\n\n if (this.container) {\n return mount(this.container, component);\n }\n }\n\n getOnClickHandler(url: string) {\n return (e: MouseEvent) => {\n if (typeof url === \"string\" && url.length > 0) {\n this.go(url);\n }\n e.preventDefault();\n };\n }\n}\n\nlet localRedirect: RedirectFunction;\n\nexport function redirect(\n url: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n): Promise<string | void> {\n if (!localRedirect) {\n throw new Error(\"router.redirect.not.found\");\n }\n return localRedirect(url, parentComponent, preventPushState);\n}\n\nexport function mountRouter(elementContainer: string | any, router: Router): void {\n router.container = elementContainer;\n localRedirect = router.go.bind(router);\n\n if (!isNodeJs) {\n function onPopStateGoToRoute(): void {\n const pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);\n (router as unknown as Router).go(pathWithoutPrefix, undefined, true);\n }\n window.addEventListener(\"popstate\", onPopStateGoToRoute, false);\n onPopStateGoToRoute();\n }\n\n directive(\"route\", (vnode: VnodeWithDom): void => {\n const url = vnode.props[\"v-route\"];\n setAttribute(\"href\", url, vnode);\n setAttribute(\"onclick\", router.getOnClickHandler(url), vnode);\n });\n}\n"],
|
|
5
|
-
"mappings": ";
|
|
6
|
-
"names": ["onPopStateGoToRoute"]
|
|
4
|
+
"sourcesContent": ["/* eslint-disable no-console */\n/* eslint-disable no-use-before-define */\nimport {\n Component,\n POJOComponent,\n VnodeComponentInterface,\n VnodeWithDom,\n directive,\n isComponent,\n isNodeJs,\n isVnodeComponent,\n mount,\n setAttribute,\n v\n} from \"valyrian.js\";\n\nexport interface Request {\n params: Record<string, any>;\n query: Record<string, any>;\n url: string;\n path: string;\n matches: string[];\n // eslint-disable-next-line no-unused-vars\n redirect: (path: string) => Promise<string | void>;\n}\n\nexport interface Middleware {\n // eslint-disable-next-line no-unused-vars\n (req: Request, err?: any):\n | Promise<any | Component | POJOComponent | VnodeComponentInterface>\n | any\n | Component\n | POJOComponent\n | VnodeComponentInterface;\n}\n\ninterface Middlewares extends Array<Middleware> {}\n\ninterface RedirectFunction {\n (\n // eslint-disable-next-line no-unused-vars\n path: string,\n // eslint-disable-next-line no-unused-vars\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n // eslint-disable-next-line no-unused-vars\n preventPushState?: boolean\n ): Promise<string | void>;\n}\n\nfunction flat(array: any) {\n return Array.isArray(array) ? array.flat(Infinity) : [array];\n}\n\nfunction getPathWithoutPrefix(path: string, prefix: string) {\n return getPathWithoutLastSlash(path.replace(new RegExp(`^${prefix}`), \"\"));\n}\n\nfunction getPathWithoutLastSlash(path: string) {\n let pathWithoutLastSlash = path.replace(/\\/$/, \"\");\n if (pathWithoutLastSlash === \"\") {\n pathWithoutLastSlash = \"/\";\n }\n return pathWithoutLastSlash;\n}\n\n// Parse a query string into an object\nfunction parseQuery(queryParts?: string): Record<string, any> {\n const parts = queryParts ? queryParts.split(\"&\") : [];\n const query: Record<string, any> = {};\n\n for (const nameValue of parts) {\n const [name, value] = nameValue.split(\"=\", 2);\n query[name] =\n isNaN(Number(value)) === false ? Number(value) : value === \"true\" ? true : value === \"false\" ? false : value;\n }\n\n return query;\n}\n\ninterface RouteNode {\n segment: string;\n children: Map<string, RouteNode>;\n middlewares?: Middlewares;\n paramKey?: string;\n isDynamic: boolean;\n}\n\nclass RouteTree {\n root: RouteNode = { segment: \"\", children: new Map(), isDynamic: false };\n\n addRoute(path: string, middlewares: Middlewares) {\n const segments = path === \"/\" ? [path] : path.split(\"/\").filter(Boolean); // Divide the path into segments\n let currentNode = this.root;\n\n for (const segment of segments) {\n const isDynamic = segment.startsWith(\":\");\n const key = isDynamic ? \":\" : segment; // If the segment is dynamic, use \":\" as key\n\n if (!currentNode.children.has(key)) {\n currentNode.children.set(key, {\n segment: segment,\n children: new Map(),\n isDynamic: isDynamic,\n paramKey: isDynamic ? segment.slice(1) : undefined\n });\n }\n\n currentNode = currentNode.children.get(key)!;\n }\n\n currentNode.middlewares = middlewares; // Assign the middlewares to the last node\n }\n\n // Search for a route in the tree\n // eslint-disable-next-line sonarjs/cognitive-complexity\n findRoute(path: string): { middlewares?: Middlewares; params: Record<string, string> } | null {\n const pathWithoutLastSlash = getPathWithoutLastSlash(path);\n const segments =\n pathWithoutLastSlash === \"/\" ? [pathWithoutLastSlash] : pathWithoutLastSlash.split(\"/\").filter(Boolean);\n let currentNode: RouteNode | null = this.root;\n const params: Record<string, string> = {};\n\n const wildcardMiddlewares: Middlewares = []; // Middlewares for wildcard routes\n const segmentsLength = segments.length;\n\n for (let i = 0; i < segmentsLength; i++) {\n if (!currentNode) {\n break;\n }\n\n const segment = segments[i];\n\n let found = false;\n\n for (const [key, child] of currentNode.children) {\n if (key === segment) {\n currentNode = child;\n found = true;\n break;\n }\n\n if (segment !== \".*\" && key === \":\") {\n currentNode = child;\n params[child.paramKey!] = segment;\n found = true;\n break;\n }\n\n if (key === \".*\" && !found) {\n wildcardMiddlewares.push(...(child.middlewares || []));\n }\n }\n\n if (!found) {\n if (currentNode.children.has(\".*\")) {\n return { middlewares: wildcardMiddlewares, params };\n }\n return null;\n }\n }\n\n // Add the wildcard middlewares to the current node middlewares\n const allMiddlewares = [...wildcardMiddlewares, ...(currentNode.middlewares || [])];\n\n // If there are no middlewares, return null\n if (allMiddlewares.length === 0) {\n return null;\n }\n\n // If there are middlewares, return them\n return { middlewares: allMiddlewares, params };\n }\n}\n\nexport const RouterError = class RouterError extends Error {\n status: number | undefined = 500;\n};\n\ntype RouteParams = string | Middleware | Router | (string | Middleware | Router | RouteParams)[];\n\nexport class Router {\n private routeTree = new RouteTree();\n container: Element | string | null = null;\n query: Record<string, string | number> = {};\n options: Record<string, any> = {};\n url: string = \"\";\n path: string = \"\";\n params: Record<string, string | number | any> = {};\n matches: string[] = [];\n pathPrefix: string = \"\";\n\n private errorHandlers: Map<number | string | Error | \"generic\", Middlewares> = new Map();\n\n constructor(pathPrefix: string = \"\") {\n this.pathPrefix = pathPrefix;\n }\n\n add(...args: RouteParams[]): Router {\n const flatArgs = flat(args);\n const path = getPathWithoutLastSlash(\n `${this.pathPrefix}${typeof flatArgs[0] === \"string\" ? flatArgs.shift() : \"/.*\"}`\n );\n\n // If the first argument is a Router, add all its routes\n if (flatArgs.length === 1 && flatArgs[0] instanceof Router) {\n const subrouter = flatArgs[0] as Router;\n for (const subroute of subrouter.routes()) {\n const subroutePath = `${path}${subroute}`;\n this.routeTree.addRoute(subroutePath, subrouter.routeTree.findRoute(subroute)!.middlewares || []);\n }\n } else {\n // Verify that no middlewares are added when a subrouter is added\n if (flatArgs.some((item) => item instanceof Router)) {\n throw new RouterError(\"You cannot add middlewares when adding a subrouter.\");\n }\n\n // Verify that all middlewares are functions\n if (flatArgs.some((item) => typeof item !== \"function\")) {\n throw new RouterError(\"All middlewares must be functions.\");\n }\n\n this.routeTree.addRoute(path, flatArgs as Middlewares);\n }\n\n return this;\n }\n\n catch(...args: (number | string | Error | typeof Error | Middleware)[]): Router {\n const condition =\n typeof args[0] === \"number\" || typeof args[0] === \"string\" || args[0].name.includes(\"Error\")\n ? (args.shift() as number | string | Error)\n : \"generic\";\n\n if (typeof condition !== \"number\" && typeof condition !== \"string\" && !condition.name.includes(\"Error\")) {\n throw new RouterError(\"The condition must be a number, string or an instance of Error.\");\n }\n\n // Verify that all middlewares are functions\n if (args.some((item) => typeof item !== \"function\")) {\n throw new RouterError(\"All middlewares must be functions.\");\n }\n\n let handlers = this.errorHandlers.get(condition);\n if (!handlers) {\n handlers = [];\n this.errorHandlers.set(condition, handlers);\n }\n\n handlers.push(...(args as Middlewares));\n return this;\n }\n\n routes(): string[] {\n return this.getAllRoutes(this.routeTree.root, \"\");\n }\n\n // eslint-disable-next-line sonarjs/cognitive-complexity\n async go(\n path: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface\n ): Promise<string | void> {\n if (!path) {\n return this.handleError(new RouterError(\"The URL is empty.\"), parentComponent);\n }\n\n if (/%[^0-9A-Fa-f]{2}/.test(path)) {\n return this.handleError(new RouterError(`The URL ${path} is malformed.`));\n }\n\n const constructedPath = getPathWithoutLastSlash(`${this.pathPrefix}${path}`);\n const parts = constructedPath.split(\"?\", 2);\n this.url = constructedPath;\n this.query = parseQuery(parts[1]);\n\n const finalPath = parts[0].replace(/(.+)\\/$/, \"$1\").split(\"#\")[0];\n this.path = path;\n\n let route = this.routeTree.findRoute(finalPath);\n\n if (!route || !route.middlewares) {\n // If the route is not found, search for a wildcard route\n const finalPathParts = finalPath.split(\"/\"); // Divide the path into segments\n\n while (finalPathParts.length > 0) {\n finalPathParts.pop(); // Remove the last segment\n const wildcardRoute = this.routeTree.findRoute(finalPathParts.join(\"/\") + \"/.*\"); // Search for a wildcard route\n if (wildcardRoute) {\n route = wildcardRoute;\n break;\n }\n }\n\n // If no route is found, return a 404 error\n if (!route || !route.middlewares) {\n const error = new RouterError(`The URL ${constructedPath} was not found in the router's registered paths.`);\n (error as any).status = 404;\n return this.handleError(error, parentComponent);\n }\n }\n\n const { middlewares, params } = route;\n this.params = params;\n\n let component = await this.searchComponent(middlewares, parentComponent);\n\n if (component === false) {\n return;\n }\n\n if (!component) {\n return this.handleError(\n new RouterError(`The URL ${constructedPath} did not return a valid component.`),\n parentComponent\n );\n }\n\n if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {\n const childComponent = isVnodeComponent(component) ? component : v(component as Component, {});\n if (isVnodeComponent(parentComponent)) {\n parentComponent.children.push(childComponent);\n component = parentComponent;\n } else {\n component = v(parentComponent, {}, childComponent) as VnodeComponentInterface;\n }\n }\n\n if (!isNodeJs && window.location.pathname + window.location.search !== constructedPath) {\n window.history.pushState(null, \"\", constructedPath);\n }\n\n if (this.container) {\n return mount(this.container, component);\n }\n }\n\n getOnClickHandler(url: string) {\n return (e: MouseEvent) => {\n if (e.button !== 0 || e.ctrlKey || e.metaKey || e.shiftKey || e.altKey || e.defaultPrevented) {\n return;\n }\n\n if (typeof url === \"string\" && url.length > 0) {\n this.go(url);\n }\n e.preventDefault();\n };\n }\n\n private getAllRoutes(node: RouteNode, prefix: string): string[] {\n const routes: string[] = [];\n\n for (const [key, child] of node.children) {\n // eslint-disable-next-line sonarjs/no-nested-template-literals\n const newPrefix = `${prefix}/${child.isDynamic ? `:${child.paramKey}` : key}`.replace(/\\/$/, \"\");\n if (child.middlewares) {\n routes.push(newPrefix);\n }\n routes.push(...this.getAllRoutes(child, newPrefix));\n }\n\n return routes;\n }\n\n private createRequest(): Request {\n return {\n params: this.params,\n query: this.query,\n url: this.url,\n path: this.path,\n matches: this.matches,\n redirect: (path: string) => this.go(path)\n };\n }\n\n private getErrorConditionMiddlewares(error: any): Middlewares | false {\n // Search first for class and name errors\n for (const [condition, middlewares] of this.errorHandlers) {\n if (\n typeof condition !== \"number\" &&\n typeof condition !== \"string\" &&\n error instanceof (condition as any) &&\n error.name === condition.name\n ) {\n return middlewares;\n }\n }\n\n // then for code errors\n for (const [condition, middlewares] of this.errorHandlers) {\n if (typeof condition === \"number\" && (error.status === condition || error.code === condition)) {\n return middlewares;\n }\n }\n\n // and then for message errors\n for (const [condition, middlewares] of this.errorHandlers) {\n if (typeof condition === \"string\" && (error.name === condition || error.message.includes(condition))) {\n return middlewares;\n }\n }\n\n // If no specific error handler is found, return the generic one\n return this.errorHandlers.get(\"generic\") || false;\n }\n\n // eslint-disable-next-line sonarjs/cognitive-complexity\n private async handleError(\n error: Error,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface\n ): Promise<void | string> {\n const request: Request = this.createRequest();\n let component = null;\n const middlewares = this.getErrorConditionMiddlewares(error);\n\n // If no error handler is found, throw the error\n if (middlewares === false) {\n throw error;\n }\n\n let response;\n try {\n for (const middleware of middlewares) {\n response = await middleware(request, error);\n\n // If the response is a component or vnode, return it for rendering\n if (response !== undefined && (isComponent(response) || isVnodeComponent(response))) {\n component = response;\n break;\n }\n\n // If the response is false, stop the middleware chain\n if (response === false) {\n return;\n }\n }\n } catch (err) {\n // If an error occurs during the error handling, we handle it recursively\n (err as Error).cause = error;\n\n let errorCauseCount = 0;\n while ((err as Error).cause) {\n errorCauseCount++;\n }\n\n if (errorCauseCount > 20) {\n throw new RouterError(\"Too many error causes. Possible circular error handling.\");\n }\n\n return this.handleError(err as Error, parentComponent);\n }\n\n if (component) {\n // If there is an error middleware that returns a component, we return it\n if (isComponent(parentComponent) || isVnodeComponent(parentComponent)) {\n const childComponent = isVnodeComponent(component) ? component : v(component as Component, {});\n if (isVnodeComponent(parentComponent)) {\n parentComponent.children.push(childComponent);\n component = parentComponent;\n } else {\n component = v(parentComponent, {}, childComponent) as VnodeComponentInterface;\n }\n }\n\n // If we are in the browser, we update the URL\n if (!isNodeJs && window.location.pathname + window.location.search !== this.url) {\n window.history.pushState(null, \"\", this.url);\n }\n\n // If there is a container, we mount the component\n if (this.container) {\n return mount(this.container, component);\n }\n }\n\n // If there is no component to render, we throw the error\n throw error;\n }\n\n private async searchComponent(\n middlewares: Middlewares,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface\n ) {\n const request: Request = this.createRequest();\n\n let response;\n\n for (const middleware of middlewares) {\n try {\n response = await middleware(request);\n } catch (error) {\n return this.handleError(error as Error, parentComponent);\n }\n\n // If the response is a component or vnode, return it for rendering\n if (response !== undefined && (isComponent(response) || isVnodeComponent(response))) {\n return response;\n }\n\n // If the response is false, stop the middleware chain\n if (response === false) {\n return false;\n }\n }\n\n return response;\n }\n}\n\nlet localRedirect: RedirectFunction;\n\nexport async function redirect(\n url: string,\n parentComponent?: Component | POJOComponent | VnodeComponentInterface,\n preventPushState = false\n): Promise<string | void> {\n if (!localRedirect) {\n // eslint-disable-next-line no-console\n console.warn(\"Redirect function is not initialized. Please mount the router first.\");\n return;\n }\n return localRedirect(url, parentComponent, preventPushState);\n}\n\nexport function mountRouter(elementContainer: string | any, router: Router): void {\n router.container = elementContainer;\n localRedirect = router.go.bind(router);\n\n if (!isNodeJs) {\n function onPopStateGoToRoute(): void {\n const pathWithoutPrefix = getPathWithoutPrefix(document.location.pathname, router.pathPrefix);\n (router as unknown as Router).go(pathWithoutPrefix);\n }\n window.addEventListener(\"popstate\", onPopStateGoToRoute, false);\n onPopStateGoToRoute();\n }\n\n directive(\"route\", (url: string, vnode: VnodeWithDom): void => {\n setAttribute(\"href\", url, vnode);\n setAttribute(\"onclick\", router.getOnClickHandler(url), vnode);\n });\n}\n"],
|
|
5
|
+
"mappings": ";AAEA;AAAA,EAKE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAmCP,SAAS,KAAK,OAAY;AACxB,SAAO,MAAM,QAAQ,KAAK,IAAI,MAAM,KAAK,QAAQ,IAAI,CAAC,KAAK;AAC7D;AAEA,SAAS,qBAAqB,MAAc,QAAgB;AAC1D,SAAO,wBAAwB,KAAK,QAAQ,IAAI,OAAO,IAAI,MAAM,EAAE,GAAG,EAAE,CAAC;AAC3E;AAEA,SAAS,wBAAwB,MAAc;AAC7C,MAAI,uBAAuB,KAAK,QAAQ,OAAO,EAAE;AACjD,MAAI,yBAAyB,IAAI;AAC/B,2BAAuB;AAAA,EACzB;AACA,SAAO;AACT;AAGA,SAAS,WAAW,YAA0C;AAC5D,QAAM,QAAQ,aAAa,WAAW,MAAM,GAAG,IAAI,CAAC;AACpD,QAAM,QAA6B,CAAC;AAEpC,aAAW,aAAa,OAAO;AAC7B,UAAM,CAAC,MAAM,KAAK,IAAI,UAAU,MAAM,KAAK,CAAC;AAC5C,UAAM,IAAI,IACR,MAAM,OAAO,KAAK,CAAC,MAAM,QAAQ,OAAO,KAAK,IAAI,UAAU,SAAS,OAAO,UAAU,UAAU,QAAQ;AAAA,EAC3G;AAEA,SAAO;AACT;AAUA,IAAM,YAAN,MAAgB;AAAA,EACd,OAAkB,EAAE,SAAS,IAAI,UAAU,oBAAI,IAAI,GAAG,WAAW,MAAM;AAAA,EAEvE,SAAS,MAAc,aAA0B;AAC/C,UAAM,WAAW,SAAS,MAAM,CAAC,IAAI,IAAI,KAAK,MAAM,GAAG,EAAE,OAAO,OAAO;AACvE,QAAI,cAAc,KAAK;AAEvB,eAAW,WAAW,UAAU;AAC9B,YAAM,YAAY,QAAQ,WAAW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AkB,GAAG,GAAG,KAAK;AAAA,EAC9D,CAAC;AACH;",
|
|
6
|
+
"names": ["RouterError", "onPopStateGoToRoute"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export type Signal<T> = [() => T, (newValue: T | ((current: T) => T)) => void, () => void];
|
|
2
|
+
export declare function createSignal<T>(initialValue: T): Signal<T>;
|
|
3
|
+
export declare function createEffect(effect: Function): void;
|
|
4
|
+
export type SignalStore<T> = [() => T, (path: string, newValue: T | ((current: T) => T) | any) => void];
|
|
5
|
+
export declare function createSignalStore<T>(initialState: T): SignalStore<T>;
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../lib/signals/index.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,MAAM,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,KAAK,IAAI,EAAE,MAAM,IAAI,CAAC,CAAC;AAE3F,wBAAgB,YAAY,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CAkD1D;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,QAAQ,QAW5C;AAMD,MAAM,MAAM,WAAW,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAC,GAAG,GAAG,KAAK,IAAI,CAAC,CAAC;AAExG,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,CAkBpE"}
|