clear-router 2.8.0 → 2.8.2
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/dist/ResourceRoutes.cjs +97 -7
- package/dist/ResourceRoutes.d.cts +65 -6
- package/dist/ResourceRoutes.d.mts +65 -6
- package/dist/ResourceRoutes.mjs +97 -7
- package/dist/core/helpers.cjs +32 -0
- package/dist/core/helpers.d.cts +18 -0
- package/dist/core/helpers.d.mts +17 -0
- package/dist/core/helpers.mjs +31 -0
- package/dist/core/index.cjs +1 -6
- package/dist/core/index.d.cts +2 -1
- package/dist/core/index.d.mts +2 -1
- package/dist/core/index.mjs +2 -1
- package/dist/core/router.cjs +43 -38
- package/dist/core/router.d.cts +7 -4
- package/dist/core/router.d.mts +7 -4
- package/dist/core/router.mjs +43 -38
- package/dist/express/router.cjs +2 -2
- package/dist/express/router.d.cts +4 -4
- package/dist/express/router.d.mts +4 -4
- package/dist/express/router.mjs +2 -2
- package/dist/fastify/router.cjs +2 -2
- package/dist/fastify/router.d.cts +4 -4
- package/dist/fastify/router.d.mts +4 -4
- package/dist/fastify/router.mjs +2 -2
- package/dist/h3/router.cjs +2 -2
- package/dist/h3/router.d.cts +4 -4
- package/dist/h3/router.d.mts +4 -4
- package/dist/h3/router.mjs +2 -2
- package/dist/hono/router.cjs +2 -2
- package/dist/hono/router.d.cts +4 -4
- package/dist/hono/router.d.mts +4 -4
- package/dist/hono/router.mjs +2 -2
- package/dist/index.cjs +4 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.mjs +2 -1
- package/dist/koa/router.cjs +2 -2
- package/dist/koa/router.d.cts +4 -4
- package/dist/koa/router.d.mts +4 -4
- package/dist/koa/router.mjs +2 -2
- package/dist/types/basic.d.cts +15 -5
- package/dist/types/basic.d.mts +15 -5
- package/dist/types/index.d.mts +1 -0
- package/package.json +5 -2
package/dist/core/router.cjs
CHANGED
|
@@ -3,6 +3,9 @@ const require_Response = require('./Response.cjs');
|
|
|
3
3
|
const require_bindings = require('./bindings.cjs');
|
|
4
4
|
const require_ResourceRoutes = require('../ResourceRoutes.cjs');
|
|
5
5
|
const require_Route = require('../Route.cjs');
|
|
6
|
+
const require_helpers = require('./helpers.cjs');
|
|
7
|
+
let node_path = require("node:path");
|
|
8
|
+
let node_fs_promises = require("node:fs/promises");
|
|
6
9
|
let node_async_hooks = require("node:async_hooks");
|
|
7
10
|
let node_module = require("node:module");
|
|
8
11
|
|
|
@@ -90,6 +93,15 @@ var CoreRouter = class {
|
|
|
90
93
|
if (route.routeName && this.routesByName.get(route.routeName) === route) this.routesByName.delete(route.routeName);
|
|
91
94
|
}
|
|
92
95
|
}
|
|
96
|
+
static removeRoute(route) {
|
|
97
|
+
this.routes.delete(route);
|
|
98
|
+
if (route.routeName && this.routesByName.get(route.routeName) === route) this.routesByName.delete(route.routeName);
|
|
99
|
+
for (const method of route.methods) {
|
|
100
|
+
const methodKey = method.toUpperCase();
|
|
101
|
+
this.routesByPathMethod.delete(`${methodKey} ${route.path}`);
|
|
102
|
+
this.routesByMethod.set(methodKey, (this.routesByMethod.get(methodKey) ?? []).filter((existingRoute) => existingRoute !== route));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
93
105
|
/**
|
|
94
106
|
* Resets the router to it's default state
|
|
95
107
|
*/
|
|
@@ -537,47 +549,14 @@ var CoreRouter = class {
|
|
|
537
549
|
* @param options
|
|
538
550
|
*/
|
|
539
551
|
static apiResource(basePath, controller, options) {
|
|
540
|
-
const resourceRoutes = {};
|
|
541
552
|
let paramName = "id";
|
|
542
553
|
if (!!this.config.inferParamName && this.hasPackageInstalled("@h3ravel/support")) {
|
|
543
554
|
const { str } = (0, node_module.createRequire)(require("url").pathToFileURL(__filename).href)("@h3ravel/support");
|
|
544
555
|
paramName = str(basePath).singular().afterLast("/").toString();
|
|
545
556
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
path: "/"
|
|
550
|
-
},
|
|
551
|
-
show: {
|
|
552
|
-
method: "get",
|
|
553
|
-
path: `/:${paramName}`
|
|
554
|
-
},
|
|
555
|
-
create: {
|
|
556
|
-
method: "post",
|
|
557
|
-
path: "/"
|
|
558
|
-
},
|
|
559
|
-
update: {
|
|
560
|
-
method: "put",
|
|
561
|
-
path: `/:${paramName}`
|
|
562
|
-
},
|
|
563
|
-
destroy: {
|
|
564
|
-
method: "delete",
|
|
565
|
-
path: `/:${paramName}`
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
const only = options?.only || Object.keys(actions);
|
|
569
|
-
const except = options?.except || [];
|
|
570
|
-
const preController = typeof controller === "function" ? new controller() : controller;
|
|
571
|
-
for (const action of only) {
|
|
572
|
-
if (except.includes(action)) continue;
|
|
573
|
-
if (typeof preController[action] === "function") {
|
|
574
|
-
const { method, path } = actions[action];
|
|
575
|
-
const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
|
|
576
|
-
const name = `${basePath}${path}`.replace(/\/:[^/]+|\/\{[^}]+\}/g, "").replace(/\{(\w+):[^}]+\}/g, "$1").replace(/\/|:|[{}]/g, ".").replace(/\.{2,}/g, ".").replace(/^\.|\.$/g, "");
|
|
577
|
-
resourceRoutes[action] = this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0).name(name + "." + action.toLowerCase());
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return new require_ResourceRoutes.ResourceRoutes(resourceRoutes);
|
|
557
|
+
return new require_ResourceRoutes.ResourceRoutes(basePath, controller, paramName, options, ({ method, path, handler, middlewares, name }) => {
|
|
558
|
+
return this.add(method, path, handler, middlewares).name(name);
|
|
559
|
+
}, (route) => this.removeRoute(route)).register();
|
|
581
560
|
}
|
|
582
561
|
/**
|
|
583
562
|
* Adds a new GET route to the router.
|
|
@@ -664,7 +643,7 @@ var CoreRouter = class {
|
|
|
664
643
|
* @param callback
|
|
665
644
|
* @param middlewares
|
|
666
645
|
*/
|
|
667
|
-
static async group(prefix,
|
|
646
|
+
static async group(prefix, source, middlewares) {
|
|
668
647
|
this.ensureState();
|
|
669
648
|
const context = this.groupContext.getStore();
|
|
670
649
|
const previousPrefix = context?.prefix ?? this.prefix;
|
|
@@ -675,9 +654,35 @@ var CoreRouter = class {
|
|
|
675
654
|
groupMiddlewares: [...previousMiddlewares, ...middlewares || []]
|
|
676
655
|
};
|
|
677
656
|
await this.groupContext.run(nextContext, async () => {
|
|
678
|
-
|
|
657
|
+
if (typeof source === "function") {
|
|
658
|
+
await Promise.resolve(source());
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
for (const file of await this.resolveGroupFiles(source)) await require_helpers.importFile(file);
|
|
679
662
|
});
|
|
680
663
|
}
|
|
664
|
+
static async resolveGroupFiles(source) {
|
|
665
|
+
const resolved = (0, node_path.isAbsolute)(source) ? source : (0, node_path.resolve)(process.cwd(), source);
|
|
666
|
+
let sourceStat;
|
|
667
|
+
try {
|
|
668
|
+
sourceStat = await (0, node_fs_promises.stat)(resolved);
|
|
669
|
+
} catch {
|
|
670
|
+
throw new Error(`Route group source not found: ${source}`);
|
|
671
|
+
}
|
|
672
|
+
if (sourceStat.isFile()) return [resolved];
|
|
673
|
+
if (!sourceStat.isDirectory()) throw new Error(`Route group source must be a file or directory: ${source}`);
|
|
674
|
+
return this.readGroupDirectory(resolved);
|
|
675
|
+
}
|
|
676
|
+
static async readGroupDirectory(directory) {
|
|
677
|
+
const entries = await (0, node_fs_promises.readdir)(directory, { withFileTypes: true });
|
|
678
|
+
const files = [];
|
|
679
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
680
|
+
const path = (0, node_path.join)(directory, entry.name);
|
|
681
|
+
if (entry.isDirectory()) files.push(...await this.readGroupDirectory(path));
|
|
682
|
+
else if (entry.isFile() && /\.(?:[cm]?ts)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) files.push(path);
|
|
683
|
+
}
|
|
684
|
+
return files;
|
|
685
|
+
}
|
|
681
686
|
/**
|
|
682
687
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
683
688
|
*
|
package/dist/core/router.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource, RouterConfig } from "../types/basic.cjs";
|
|
2
2
|
import { Response } from "./Response.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
4
|
import { Request } from "./Request.cjs";
|
|
@@ -49,6 +49,7 @@ declare abstract class CoreRouter {
|
|
|
49
49
|
protected static routeSpecificity(route: Route<any, any, any>): [number, number, number];
|
|
50
50
|
protected static orderedRoutes(): Array<Route<any, any, any>>;
|
|
51
51
|
protected static removeRouteMethod(route: Route<any, any, any>, method: HttpMethod, path: string): void;
|
|
52
|
+
protected static removeRoute(route: Route<any, any, any>): void;
|
|
52
53
|
/**
|
|
53
54
|
* Resets the router to it's default state
|
|
54
55
|
*/
|
|
@@ -143,8 +144,8 @@ declare abstract class CoreRouter {
|
|
|
143
144
|
* @param options
|
|
144
145
|
*/
|
|
145
146
|
static apiResource(basePath: string, controller: any, options?: {
|
|
146
|
-
only?:
|
|
147
|
-
except?:
|
|
147
|
+
only?: ResourceAction[];
|
|
148
|
+
except?: ResourceAction[];
|
|
148
149
|
middlewares?: ApiResourceMiddleware<any>;
|
|
149
150
|
}): ResourceRoutes<any, any, any>;
|
|
150
151
|
/**
|
|
@@ -218,7 +219,9 @@ declare abstract class CoreRouter {
|
|
|
218
219
|
* @param callback
|
|
219
220
|
* @param middlewares
|
|
220
221
|
*/
|
|
221
|
-
static group(prefix: string,
|
|
222
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: any[]): Promise<void>;
|
|
223
|
+
protected static resolveGroupFiles(source: string): Promise<string[]>;
|
|
224
|
+
protected static readGroupDirectory(directory: string): Promise<string[]>;
|
|
222
225
|
/**
|
|
223
226
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
224
227
|
*
|
package/dist/core/router.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource, RouterConfig } from "../types/basic.mjs";
|
|
2
2
|
import { Response } from "./Response.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
4
|
import { Request } from "./Request.mjs";
|
|
@@ -49,6 +49,7 @@ declare abstract class CoreRouter {
|
|
|
49
49
|
protected static routeSpecificity(route: Route<any, any, any>): [number, number, number];
|
|
50
50
|
protected static orderedRoutes(): Array<Route<any, any, any>>;
|
|
51
51
|
protected static removeRouteMethod(route: Route<any, any, any>, method: HttpMethod, path: string): void;
|
|
52
|
+
protected static removeRoute(route: Route<any, any, any>): void;
|
|
52
53
|
/**
|
|
53
54
|
* Resets the router to it's default state
|
|
54
55
|
*/
|
|
@@ -143,8 +144,8 @@ declare abstract class CoreRouter {
|
|
|
143
144
|
* @param options
|
|
144
145
|
*/
|
|
145
146
|
static apiResource(basePath: string, controller: any, options?: {
|
|
146
|
-
only?:
|
|
147
|
-
except?:
|
|
147
|
+
only?: ResourceAction[];
|
|
148
|
+
except?: ResourceAction[];
|
|
148
149
|
middlewares?: ApiResourceMiddleware<any>;
|
|
149
150
|
}): ResourceRoutes<any, any, any>;
|
|
150
151
|
/**
|
|
@@ -218,7 +219,9 @@ declare abstract class CoreRouter {
|
|
|
218
219
|
* @param callback
|
|
219
220
|
* @param middlewares
|
|
220
221
|
*/
|
|
221
|
-
static group(prefix: string,
|
|
222
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: any[]): Promise<void>;
|
|
223
|
+
protected static resolveGroupFiles(source: string): Promise<string[]>;
|
|
224
|
+
protected static readGroupDirectory(directory: string): Promise<string[]>;
|
|
222
225
|
/**
|
|
223
226
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
224
227
|
*
|
package/dist/core/router.mjs
CHANGED
|
@@ -3,7 +3,10 @@ import { Response } from "./Response.mjs";
|
|
|
3
3
|
import { Container, getBindingMetadataFromTargets, getDesignParamTypes, getStandardMetadata, isClass } from "./bindings.mjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
5
5
|
import { Route } from "../Route.mjs";
|
|
6
|
+
import { importFile } from "./helpers.mjs";
|
|
6
7
|
import { createRequire } from "node:module";
|
|
8
|
+
import { isAbsolute, join, resolve } from "node:path";
|
|
9
|
+
import { readdir, stat } from "node:fs/promises";
|
|
7
10
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
8
11
|
|
|
9
12
|
//#region src/core/router.ts
|
|
@@ -90,6 +93,15 @@ var CoreRouter = class {
|
|
|
90
93
|
if (route.routeName && this.routesByName.get(route.routeName) === route) this.routesByName.delete(route.routeName);
|
|
91
94
|
}
|
|
92
95
|
}
|
|
96
|
+
static removeRoute(route) {
|
|
97
|
+
this.routes.delete(route);
|
|
98
|
+
if (route.routeName && this.routesByName.get(route.routeName) === route) this.routesByName.delete(route.routeName);
|
|
99
|
+
for (const method of route.methods) {
|
|
100
|
+
const methodKey = method.toUpperCase();
|
|
101
|
+
this.routesByPathMethod.delete(`${methodKey} ${route.path}`);
|
|
102
|
+
this.routesByMethod.set(methodKey, (this.routesByMethod.get(methodKey) ?? []).filter((existingRoute) => existingRoute !== route));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
93
105
|
/**
|
|
94
106
|
* Resets the router to it's default state
|
|
95
107
|
*/
|
|
@@ -537,47 +549,14 @@ var CoreRouter = class {
|
|
|
537
549
|
* @param options
|
|
538
550
|
*/
|
|
539
551
|
static apiResource(basePath, controller, options) {
|
|
540
|
-
const resourceRoutes = {};
|
|
541
552
|
let paramName = "id";
|
|
542
553
|
if (!!this.config.inferParamName && this.hasPackageInstalled("@h3ravel/support")) {
|
|
543
554
|
const { str } = createRequire(import.meta.url)("@h3ravel/support");
|
|
544
555
|
paramName = str(basePath).singular().afterLast("/").toString();
|
|
545
556
|
}
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
path: "/"
|
|
550
|
-
},
|
|
551
|
-
show: {
|
|
552
|
-
method: "get",
|
|
553
|
-
path: `/:${paramName}`
|
|
554
|
-
},
|
|
555
|
-
create: {
|
|
556
|
-
method: "post",
|
|
557
|
-
path: "/"
|
|
558
|
-
},
|
|
559
|
-
update: {
|
|
560
|
-
method: "put",
|
|
561
|
-
path: `/:${paramName}`
|
|
562
|
-
},
|
|
563
|
-
destroy: {
|
|
564
|
-
method: "delete",
|
|
565
|
-
path: `/:${paramName}`
|
|
566
|
-
}
|
|
567
|
-
};
|
|
568
|
-
const only = options?.only || Object.keys(actions);
|
|
569
|
-
const except = options?.except || [];
|
|
570
|
-
const preController = typeof controller === "function" ? new controller() : controller;
|
|
571
|
-
for (const action of only) {
|
|
572
|
-
if (except.includes(action)) continue;
|
|
573
|
-
if (typeof preController[action] === "function") {
|
|
574
|
-
const { method, path } = actions[action];
|
|
575
|
-
const actionMiddlewares = typeof options?.middlewares === "object" && !Array.isArray(options.middlewares) ? options.middlewares[action] : options?.middlewares;
|
|
576
|
-
const name = `${basePath}${path}`.replace(/\/:[^/]+|\/\{[^}]+\}/g, "").replace(/\{(\w+):[^}]+\}/g, "$1").replace(/\/|:|[{}]/g, ".").replace(/\.{2,}/g, ".").replace(/^\.|\.$/g, "");
|
|
577
|
-
resourceRoutes[action] = this.add(method, `${basePath}${path}`, [controller, action], Array.isArray(actionMiddlewares) ? actionMiddlewares : actionMiddlewares ? [actionMiddlewares] : void 0).name(name + "." + action.toLowerCase());
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return new ResourceRoutes(resourceRoutes);
|
|
557
|
+
return new ResourceRoutes(basePath, controller, paramName, options, ({ method, path, handler, middlewares, name }) => {
|
|
558
|
+
return this.add(method, path, handler, middlewares).name(name);
|
|
559
|
+
}, (route) => this.removeRoute(route)).register();
|
|
581
560
|
}
|
|
582
561
|
/**
|
|
583
562
|
* Adds a new GET route to the router.
|
|
@@ -664,7 +643,7 @@ var CoreRouter = class {
|
|
|
664
643
|
* @param callback
|
|
665
644
|
* @param middlewares
|
|
666
645
|
*/
|
|
667
|
-
static async group(prefix,
|
|
646
|
+
static async group(prefix, source, middlewares) {
|
|
668
647
|
this.ensureState();
|
|
669
648
|
const context = this.groupContext.getStore();
|
|
670
649
|
const previousPrefix = context?.prefix ?? this.prefix;
|
|
@@ -675,9 +654,35 @@ var CoreRouter = class {
|
|
|
675
654
|
groupMiddlewares: [...previousMiddlewares, ...middlewares || []]
|
|
676
655
|
};
|
|
677
656
|
await this.groupContext.run(nextContext, async () => {
|
|
678
|
-
|
|
657
|
+
if (typeof source === "function") {
|
|
658
|
+
await Promise.resolve(source());
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
for (const file of await this.resolveGroupFiles(source)) await importFile(file);
|
|
679
662
|
});
|
|
680
663
|
}
|
|
664
|
+
static async resolveGroupFiles(source) {
|
|
665
|
+
const resolved = isAbsolute(source) ? source : resolve(process.cwd(), source);
|
|
666
|
+
let sourceStat;
|
|
667
|
+
try {
|
|
668
|
+
sourceStat = await stat(resolved);
|
|
669
|
+
} catch {
|
|
670
|
+
throw new Error(`Route group source not found: ${source}`);
|
|
671
|
+
}
|
|
672
|
+
if (sourceStat.isFile()) return [resolved];
|
|
673
|
+
if (!sourceStat.isDirectory()) throw new Error(`Route group source must be a file or directory: ${source}`);
|
|
674
|
+
return this.readGroupDirectory(resolved);
|
|
675
|
+
}
|
|
676
|
+
static async readGroupDirectory(directory) {
|
|
677
|
+
const entries = await readdir(directory, { withFileTypes: true });
|
|
678
|
+
const files = [];
|
|
679
|
+
for (const entry of entries.sort((left, right) => left.name.localeCompare(right.name))) {
|
|
680
|
+
const path = join(directory, entry.name);
|
|
681
|
+
if (entry.isDirectory()) files.push(...await this.readGroupDirectory(path));
|
|
682
|
+
else if (entry.isFile() && /\.(?:[cm]?ts)$/.test(entry.name) && !entry.name.endsWith(".d.ts")) files.push(path);
|
|
683
|
+
}
|
|
684
|
+
return files;
|
|
685
|
+
}
|
|
681
686
|
/**
|
|
682
687
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
683
688
|
*
|
package/dist/express/router.cjs
CHANGED
|
@@ -141,8 +141,8 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
141
141
|
* @param callback
|
|
142
142
|
* @param middlewares
|
|
143
143
|
*/
|
|
144
|
-
static async group(prefix,
|
|
145
|
-
await super.group(prefix,
|
|
144
|
+
static async group(prefix, source, middlewares) {
|
|
145
|
+
await super.group(prefix, source, middlewares);
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.cjs";
|
|
2
2
|
import { Handler, HttpContext, Middleware } from "../types/express.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
@@ -34,8 +34,8 @@ declare class Router$1 extends CoreRouter {
|
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
37
|
-
only?:
|
|
38
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
40
40
|
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
41
41
|
/**
|
|
@@ -101,7 +101,7 @@ declare class Router$1 extends CoreRouter {
|
|
|
101
101
|
* @param callback
|
|
102
102
|
* @param middlewares
|
|
103
103
|
*/
|
|
104
|
-
static group(prefix: string,
|
|
104
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
105
105
|
/**
|
|
106
106
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
107
107
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
|
|
2
2
|
import { Handler, HttpContext, Middleware } from "../types/express.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
@@ -34,8 +34,8 @@ declare class Router$1 extends CoreRouter {
|
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
37
|
-
only?:
|
|
38
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
40
40
|
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
41
41
|
/**
|
|
@@ -101,7 +101,7 @@ declare class Router$1 extends CoreRouter {
|
|
|
101
101
|
* @param callback
|
|
102
102
|
* @param middlewares
|
|
103
103
|
*/
|
|
104
|
-
static group(prefix: string,
|
|
104
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
105
105
|
/**
|
|
106
106
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
107
107
|
*
|
package/dist/express/router.mjs
CHANGED
|
@@ -141,8 +141,8 @@ var Router = class Router extends CoreRouter {
|
|
|
141
141
|
* @param callback
|
|
142
142
|
* @param middlewares
|
|
143
143
|
*/
|
|
144
|
-
static async group(prefix,
|
|
145
|
-
await super.group(prefix,
|
|
144
|
+
static async group(prefix, source, middlewares) {
|
|
145
|
+
await super.group(prefix, source, middlewares);
|
|
146
146
|
}
|
|
147
147
|
/**
|
|
148
148
|
* Adds global middlewares to the router, which will be applied to all routes.
|
package/dist/fastify/router.cjs
CHANGED
|
@@ -134,8 +134,8 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
134
134
|
* @param callback
|
|
135
135
|
* @param middlewares
|
|
136
136
|
*/
|
|
137
|
-
static async group(prefix,
|
|
138
|
-
await super.group(prefix,
|
|
137
|
+
static async group(prefix, source, middlewares) {
|
|
138
|
+
await super.group(prefix, source, middlewares);
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* Apply middlewares to a group of routes defined within the callback
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.cjs";
|
|
2
2
|
import { FastifyApp, Handler, HttpContext, Middleware } from "../types/fastify.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
@@ -32,8 +32,8 @@ declare class Router extends CoreRouter {
|
|
|
32
32
|
* @param options Optional configuration for the resource
|
|
33
33
|
*/
|
|
34
34
|
static apiResource(basePath: string, controller: any, options?: {
|
|
35
|
-
only?:
|
|
36
|
-
except?:
|
|
35
|
+
only?: ResourceAction[];
|
|
36
|
+
except?: ResourceAction[];
|
|
37
37
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
38
38
|
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
39
39
|
/**
|
|
@@ -99,7 +99,7 @@ declare class Router extends CoreRouter {
|
|
|
99
99
|
* @param callback
|
|
100
100
|
* @param middlewares
|
|
101
101
|
*/
|
|
102
|
-
static group(prefix: string,
|
|
102
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
103
103
|
/**
|
|
104
104
|
* Apply middlewares to a group of routes defined within the callback
|
|
105
105
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
|
|
2
2
|
import { FastifyApp, Handler, HttpContext, Middleware } from "../types/fastify.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
@@ -32,8 +32,8 @@ declare class Router extends CoreRouter {
|
|
|
32
32
|
* @param options Optional configuration for the resource
|
|
33
33
|
*/
|
|
34
34
|
static apiResource(basePath: string, controller: any, options?: {
|
|
35
|
-
only?:
|
|
36
|
-
except?:
|
|
35
|
+
only?: ResourceAction[];
|
|
36
|
+
except?: ResourceAction[];
|
|
37
37
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
38
38
|
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
39
39
|
/**
|
|
@@ -99,7 +99,7 @@ declare class Router extends CoreRouter {
|
|
|
99
99
|
* @param callback
|
|
100
100
|
* @param middlewares
|
|
101
101
|
*/
|
|
102
|
-
static group(prefix: string,
|
|
102
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
103
103
|
/**
|
|
104
104
|
* Apply middlewares to a group of routes defined within the callback
|
|
105
105
|
*
|
package/dist/fastify/router.mjs
CHANGED
|
@@ -134,8 +134,8 @@ var Router = class Router extends CoreRouter {
|
|
|
134
134
|
* @param callback
|
|
135
135
|
* @param middlewares
|
|
136
136
|
*/
|
|
137
|
-
static async group(prefix,
|
|
138
|
-
await super.group(prefix,
|
|
137
|
+
static async group(prefix, source, middlewares) {
|
|
138
|
+
await super.group(prefix, source, middlewares);
|
|
139
139
|
}
|
|
140
140
|
/**
|
|
141
141
|
* Apply middlewares to a group of routes defined within the callback
|
package/dist/h3/router.cjs
CHANGED
|
@@ -143,8 +143,8 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
143
143
|
* @param callback
|
|
144
144
|
* @param middlewares
|
|
145
145
|
*/
|
|
146
|
-
static async group(prefix,
|
|
147
|
-
await super.group(prefix,
|
|
146
|
+
static async group(prefix, source, middlewares) {
|
|
147
|
+
await super.group(prefix, source, middlewares);
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Adds global middlewares to the router, which will be applied to all routes.
|
package/dist/h3/router.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.cjs";
|
|
2
2
|
import { H3App, Handler, HttpContext, Middleware as Middleware$1 } from "../types/h3.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
@@ -34,8 +34,8 @@ declare class Router extends CoreRouter {
|
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
37
|
-
only?:
|
|
38
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
39
|
middlewares?: ApiResourceMiddleware<Middleware$1>;
|
|
40
40
|
}): ResourceRoutes<HttpContext, Middleware$1, Handler>;
|
|
41
41
|
/**
|
|
@@ -101,7 +101,7 @@ declare class Router extends CoreRouter {
|
|
|
101
101
|
* @param callback
|
|
102
102
|
* @param middlewares
|
|
103
103
|
*/
|
|
104
|
-
static group(prefix: string,
|
|
104
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware$1[]): Promise<void>;
|
|
105
105
|
/**
|
|
106
106
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
107
107
|
*
|
package/dist/h3/router.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
|
|
2
2
|
import { H3App, Handler, HttpContext, Middleware as Middleware$1 } from "../types/h3.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
@@ -34,8 +34,8 @@ declare class Router extends CoreRouter {
|
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
37
|
-
only?:
|
|
38
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
39
|
middlewares?: ApiResourceMiddleware<Middleware$1>;
|
|
40
40
|
}): ResourceRoutes<HttpContext, Middleware$1, Handler>;
|
|
41
41
|
/**
|
|
@@ -101,7 +101,7 @@ declare class Router extends CoreRouter {
|
|
|
101
101
|
* @param callback
|
|
102
102
|
* @param middlewares
|
|
103
103
|
*/
|
|
104
|
-
static group(prefix: string,
|
|
104
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware$1[]): Promise<void>;
|
|
105
105
|
/**
|
|
106
106
|
* Adds global middlewares to the router, which will be applied to all routes.
|
|
107
107
|
*
|
package/dist/h3/router.mjs
CHANGED
|
@@ -143,8 +143,8 @@ var Router = class Router extends CoreRouter {
|
|
|
143
143
|
* @param callback
|
|
144
144
|
* @param middlewares
|
|
145
145
|
*/
|
|
146
|
-
static async group(prefix,
|
|
147
|
-
await super.group(prefix,
|
|
146
|
+
static async group(prefix, source, middlewares) {
|
|
147
|
+
await super.group(prefix, source, middlewares);
|
|
148
148
|
}
|
|
149
149
|
/**
|
|
150
150
|
* Adds global middlewares to the router, which will be applied to all routes.
|
package/dist/hono/router.cjs
CHANGED
|
@@ -147,8 +147,8 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
147
147
|
* @param callback
|
|
148
148
|
* @param middlewares
|
|
149
149
|
*/
|
|
150
|
-
static async group(prefix,
|
|
151
|
-
await super.group(prefix,
|
|
150
|
+
static async group(prefix, source, middlewares) {
|
|
151
|
+
await super.group(prefix, source, middlewares);
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Apply middlewares to a group of routes defined within the callback
|
package/dist/hono/router.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.cjs";
|
|
2
2
|
import { Handler, HonoApp, HttpContext, Middleware } from "../types/hono.cjs";
|
|
3
3
|
import { Route } from "../Route.cjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.cjs";
|
|
@@ -34,8 +34,8 @@ declare class Router extends CoreRouter {
|
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
37
|
-
only?:
|
|
38
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
40
40
|
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
41
41
|
/**
|
|
@@ -101,7 +101,7 @@ declare class Router extends CoreRouter {
|
|
|
101
101
|
* @param callback
|
|
102
102
|
* @param middlewares
|
|
103
103
|
*/
|
|
104
|
-
static group(prefix: string,
|
|
104
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
105
105
|
/**
|
|
106
106
|
* Apply middlewares to a group of routes defined within the callback
|
|
107
107
|
*
|
package/dist/hono/router.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { ApiResourceMiddleware,
|
|
1
|
+
import { ApiResourceMiddleware, HttpMethod, ResourceAction, RouteGroupSource } from "../types/basic.mjs";
|
|
2
2
|
import { Handler, HonoApp, HttpContext, Middleware } from "../types/hono.mjs";
|
|
3
3
|
import { Route } from "../Route.mjs";
|
|
4
4
|
import { ResourceRoutes } from "../ResourceRoutes.mjs";
|
|
@@ -34,8 +34,8 @@ declare class Router extends CoreRouter {
|
|
|
34
34
|
* @param options
|
|
35
35
|
*/
|
|
36
36
|
static apiResource(basePath: string, controller: any, options?: {
|
|
37
|
-
only?:
|
|
38
|
-
except?:
|
|
37
|
+
only?: ResourceAction[];
|
|
38
|
+
except?: ResourceAction[];
|
|
39
39
|
middlewares?: ApiResourceMiddleware<Middleware>;
|
|
40
40
|
}): ResourceRoutes<HttpContext, Middleware, Handler>;
|
|
41
41
|
/**
|
|
@@ -101,7 +101,7 @@ declare class Router extends CoreRouter {
|
|
|
101
101
|
* @param callback
|
|
102
102
|
* @param middlewares
|
|
103
103
|
*/
|
|
104
|
-
static group(prefix: string,
|
|
104
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
105
105
|
/**
|
|
106
106
|
* Apply middlewares to a group of routes defined within the callback
|
|
107
107
|
*
|
package/dist/hono/router.mjs
CHANGED
|
@@ -147,8 +147,8 @@ var Router = class Router extends CoreRouter {
|
|
|
147
147
|
* @param callback
|
|
148
148
|
* @param middlewares
|
|
149
149
|
*/
|
|
150
|
-
static async group(prefix,
|
|
151
|
-
await super.group(prefix,
|
|
150
|
+
static async group(prefix, source, middlewares) {
|
|
151
|
+
await super.group(prefix, source, middlewares);
|
|
152
152
|
}
|
|
153
153
|
/**
|
|
154
154
|
* Apply middlewares to a group of routes defined within the callback
|
package/dist/index.cjs
CHANGED
|
@@ -5,6 +5,7 @@ const require_Route = require('./Route.cjs');
|
|
|
5
5
|
const require_Request = require('./core/Request.cjs');
|
|
6
6
|
const require_Response = require('./core/Response.cjs');
|
|
7
7
|
const require_plugins = require('./core/plugins.cjs');
|
|
8
|
+
const require_helpers = require('./core/helpers.cjs');
|
|
8
9
|
const require_router = require('./core/router.cjs');
|
|
9
10
|
require('./core/index.cjs');
|
|
10
11
|
|
|
@@ -14,4 +15,6 @@ exports.CoreRouter = require_router.CoreRouter;
|
|
|
14
15
|
exports.Request = require_Request.Request;
|
|
15
16
|
exports.Response = require_Response.Response;
|
|
16
17
|
exports.Route = require_Route.Route;
|
|
17
|
-
exports.definePlugin = require_plugins.definePlugin;
|
|
18
|
+
exports.definePlugin = require_plugins.definePlugin;
|
|
19
|
+
exports.importFile = require_helpers.importFile;
|
|
20
|
+
exports.wrap = require_helpers.wrap;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,4 +6,5 @@ import { ClearRequest } from "./ClearRequest.cjs";
|
|
|
6
6
|
import { Controller } from "./Controller.cjs";
|
|
7
7
|
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.cjs";
|
|
8
8
|
import { CoreRouter } from "./core/router.cjs";
|
|
9
|
-
|
|
9
|
+
import { importFile, wrap } from "./core/helpers.cjs";
|
|
10
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteParameter, definePlugin, importFile, wrap };
|