Aktueller Stand
This commit is contained in:
5
backend/node_modules/hono/dist/router/smart-router/index.js
generated
vendored
Normal file
5
backend/node_modules/hono/dist/router/smart-router/index.js
generated
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
// src/router/smart-router/index.ts
|
||||
import { SmartRouter } from "./router.js";
|
||||
export {
|
||||
SmartRouter
|
||||
};
|
||||
58
backend/node_modules/hono/dist/router/smart-router/router.js
generated
vendored
Normal file
58
backend/node_modules/hono/dist/router/smart-router/router.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
// src/router/smart-router/router.ts
|
||||
import { MESSAGE_MATCHER_IS_ALREADY_BUILT, UnsupportedPathError } from "../../router.js";
|
||||
var SmartRouter = class {
|
||||
name = "SmartRouter";
|
||||
#routers = [];
|
||||
#routes = [];
|
||||
constructor(init) {
|
||||
this.#routers = init.routers;
|
||||
}
|
||||
add(method, path, handler) {
|
||||
if (!this.#routes) {
|
||||
throw new Error(MESSAGE_MATCHER_IS_ALREADY_BUILT);
|
||||
}
|
||||
this.#routes.push([method, path, handler]);
|
||||
}
|
||||
match(method, path) {
|
||||
if (!this.#routes) {
|
||||
throw new Error("Fatal error");
|
||||
}
|
||||
const routers = this.#routers;
|
||||
const routes = this.#routes;
|
||||
const len = routers.length;
|
||||
let i = 0;
|
||||
let res;
|
||||
for (; i < len; i++) {
|
||||
const router = routers[i];
|
||||
try {
|
||||
for (let i2 = 0, len2 = routes.length; i2 < len2; i2++) {
|
||||
router.add(...routes[i2]);
|
||||
}
|
||||
res = router.match(method, path);
|
||||
} catch (e) {
|
||||
if (e instanceof UnsupportedPathError) {
|
||||
continue;
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
this.match = router.match.bind(router);
|
||||
this.#routers = [router];
|
||||
this.#routes = void 0;
|
||||
break;
|
||||
}
|
||||
if (i === len) {
|
||||
throw new Error("Fatal error");
|
||||
}
|
||||
this.name = `SmartRouter + ${this.activeRouter.name}`;
|
||||
return res;
|
||||
}
|
||||
get activeRouter() {
|
||||
if (this.#routes || this.#routers.length !== 1) {
|
||||
throw new Error("No active router has been determined yet.");
|
||||
}
|
||||
return this.#routers[0];
|
||||
}
|
||||
};
|
||||
export {
|
||||
SmartRouter
|
||||
};
|
||||
Reference in New Issue
Block a user