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/index.d.mts
CHANGED
|
@@ -6,4 +6,5 @@ import { ClearRequest } from "./ClearRequest.mjs";
|
|
|
6
6
|
import { Controller } from "./Controller.mjs";
|
|
7
7
|
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./core/plugins.mjs";
|
|
8
8
|
import { CoreRouter } from "./core/router.mjs";
|
|
9
|
-
|
|
9
|
+
import { importFile, wrap } from "./core/helpers.mjs";
|
|
10
|
+
export { ClearHttpContext, ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, Route, RouteParameter, definePlugin, importFile, wrap };
|
package/dist/index.mjs
CHANGED
|
@@ -4,7 +4,8 @@ import { Route } from "./Route.mjs";
|
|
|
4
4
|
import { Request } from "./core/Request.mjs";
|
|
5
5
|
import { Response } from "./core/Response.mjs";
|
|
6
6
|
import { definePlugin } from "./core/plugins.mjs";
|
|
7
|
+
import { importFile, wrap } from "./core/helpers.mjs";
|
|
7
8
|
import { CoreRouter } from "./core/router.mjs";
|
|
8
9
|
import "./core/index.mjs";
|
|
9
10
|
|
|
10
|
-
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, definePlugin };
|
|
11
|
+
export { ClearRequest, Controller, CoreRouter, Request, Response, Route, definePlugin, importFile, wrap };
|
package/dist/koa/router.cjs
CHANGED
|
@@ -157,8 +157,8 @@ var Router = class Router extends require_router.CoreRouter {
|
|
|
157
157
|
* @param callback
|
|
158
158
|
* @param middlewares
|
|
159
159
|
*/
|
|
160
|
-
static async group(prefix,
|
|
161
|
-
await super.group(prefix,
|
|
160
|
+
static async group(prefix, source, middlewares) {
|
|
161
|
+
await super.group(prefix, source, middlewares);
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* Apply middlewares to a group of routes defined within the callback
|
package/dist/koa/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, HttpContext, KoaRouterApp, Middleware } from "../types/koa.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
|
/**
|
|
@@ -102,7 +102,7 @@ declare class Router extends CoreRouter {
|
|
|
102
102
|
* @param callback
|
|
103
103
|
* @param middlewares
|
|
104
104
|
*/
|
|
105
|
-
static group(prefix: string,
|
|
105
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
106
106
|
/**
|
|
107
107
|
* Apply middlewares to a group of routes defined within the callback
|
|
108
108
|
*
|
package/dist/koa/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, HttpContext, KoaRouterApp, Middleware } from "../types/koa.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
|
/**
|
|
@@ -102,7 +102,7 @@ declare class Router extends CoreRouter {
|
|
|
102
102
|
* @param callback
|
|
103
103
|
* @param middlewares
|
|
104
104
|
*/
|
|
105
|
-
static group(prefix: string,
|
|
105
|
+
static group(prefix: string, source: RouteGroupSource, middlewares?: Middleware[]): Promise<void>;
|
|
106
106
|
/**
|
|
107
107
|
* Apply middlewares to a group of routes defined within the callback
|
|
108
108
|
*
|
package/dist/koa/router.mjs
CHANGED
|
@@ -157,8 +157,8 @@ var Router = class Router extends CoreRouter {
|
|
|
157
157
|
* @param callback
|
|
158
158
|
* @param middlewares
|
|
159
159
|
*/
|
|
160
|
-
static async group(prefix,
|
|
161
|
-
await super.group(prefix,
|
|
160
|
+
static async group(prefix, source, middlewares) {
|
|
161
|
+
await super.group(prefix, source, middlewares);
|
|
162
162
|
}
|
|
163
163
|
/**
|
|
164
164
|
* Apply middlewares to a group of routes defined within the callback
|
package/dist/types/basic.d.cts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { JitiOptions, JitiResolveOptions } from "jiti";
|
|
2
|
+
|
|
1
3
|
//#region src/types/basic.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Controller method reference
|
|
4
6
|
*/
|
|
5
7
|
type ControllerHandler = [any, string];
|
|
6
8
|
type MaybePromise<T = any> = T | Promise<T>;
|
|
7
|
-
type
|
|
9
|
+
type RouteGroupCallback = () => MaybePromise<void>;
|
|
10
|
+
type RouteGroupSource = RouteGroupCallback | string;
|
|
8
11
|
type MiddlewareHandle<Args extends any[] = any[], Return = any> = (...args: Args) => MaybePromise<Return>;
|
|
9
12
|
type MiddlewareClass<M extends MiddlewareHandle = MiddlewareHandle> = new () => {
|
|
10
13
|
handle: M;
|
|
@@ -18,14 +21,14 @@ type ClassMiddleware<M extends MiddlewareHandle = MiddlewareHandle> = Middleware
|
|
|
18
21
|
*/
|
|
19
22
|
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
20
23
|
/**
|
|
21
|
-
* Common
|
|
24
|
+
* Common resource action names
|
|
22
25
|
*/
|
|
23
|
-
type
|
|
26
|
+
type ResourceAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
24
27
|
/**
|
|
25
28
|
* Generic Object type for request data
|
|
26
29
|
*/
|
|
27
30
|
type RequestData = Record<string, any>;
|
|
28
|
-
type ApiResourceMiddleware<M = any> = M | M[] | { [K in
|
|
31
|
+
type ApiResourceMiddleware<M = any> = M | M[] | { [K in ResourceAction]?: M | M[] };
|
|
29
32
|
interface RouterConfig {
|
|
30
33
|
/**
|
|
31
34
|
* When enabled, API param name will be infered from the route path.
|
|
@@ -49,5 +52,12 @@ interface RouterConfig {
|
|
|
49
52
|
autoDiscover?: boolean;
|
|
50
53
|
};
|
|
51
54
|
}
|
|
55
|
+
interface FileImporter {
|
|
56
|
+
<T = unknown>(filePath: string): Promise<T>;
|
|
57
|
+
<T = unknown>(filePath: string, userOptions?: JitiOptions | undefined): Promise<T>;
|
|
58
|
+
<T = unknown>(filePath: string, userOptions?: JitiOptions | undefined, resolveOptions?: (JitiResolveOptions & {
|
|
59
|
+
default?: true;
|
|
60
|
+
})): Promise<T>;
|
|
61
|
+
}
|
|
52
62
|
//#endregion
|
|
53
|
-
export { ApiResourceMiddleware, ClassMiddleware,
|
|
63
|
+
export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MiddlewareHandle, RequestData, ResourceAction, RouteGroupSource, RouterConfig };
|
package/dist/types/basic.d.mts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
import { JitiOptions, JitiResolveOptions } from "jiti";
|
|
2
|
+
|
|
1
3
|
//#region src/types/basic.d.ts
|
|
2
4
|
/**
|
|
3
5
|
* Controller method reference
|
|
4
6
|
*/
|
|
5
7
|
type ControllerHandler = [any, string];
|
|
6
8
|
type MaybePromise<T = any> = T | Promise<T>;
|
|
7
|
-
type
|
|
9
|
+
type RouteGroupCallback = () => MaybePromise<void>;
|
|
10
|
+
type RouteGroupSource = RouteGroupCallback | string;
|
|
8
11
|
type MiddlewareHandle<Args extends any[] = any[], Return = any> = (...args: Args) => MaybePromise<Return>;
|
|
9
12
|
type MiddlewareClass<M extends MiddlewareHandle = MiddlewareHandle> = new () => {
|
|
10
13
|
handle: M;
|
|
@@ -18,14 +21,14 @@ type ClassMiddleware<M extends MiddlewareHandle = MiddlewareHandle> = Middleware
|
|
|
18
21
|
*/
|
|
19
22
|
type HttpMethod = 'get' | 'post' | 'put' | 'delete' | 'patch' | 'options' | 'head';
|
|
20
23
|
/**
|
|
21
|
-
* Common
|
|
24
|
+
* Common resource action names
|
|
22
25
|
*/
|
|
23
|
-
type
|
|
26
|
+
type ResourceAction = 'index' | 'show' | 'create' | 'update' | 'destroy';
|
|
24
27
|
/**
|
|
25
28
|
* Generic Object type for request data
|
|
26
29
|
*/
|
|
27
30
|
type RequestData = Record<string, any>;
|
|
28
|
-
type ApiResourceMiddleware<M = any> = M | M[] | { [K in
|
|
31
|
+
type ApiResourceMiddleware<M = any> = M | M[] | { [K in ResourceAction]?: M | M[] };
|
|
29
32
|
interface RouterConfig {
|
|
30
33
|
/**
|
|
31
34
|
* When enabled, API param name will be infered from the route path.
|
|
@@ -49,5 +52,12 @@ interface RouterConfig {
|
|
|
49
52
|
autoDiscover?: boolean;
|
|
50
53
|
};
|
|
51
54
|
}
|
|
55
|
+
interface FileImporter {
|
|
56
|
+
<T = unknown>(filePath: string): Promise<T>;
|
|
57
|
+
<T = unknown>(filePath: string, userOptions?: JitiOptions | undefined): Promise<T>;
|
|
58
|
+
<T = unknown>(filePath: string, userOptions?: JitiOptions | undefined, resolveOptions?: (JitiResolveOptions & {
|
|
59
|
+
default?: true;
|
|
60
|
+
})): Promise<T>;
|
|
61
|
+
}
|
|
52
62
|
//#endregion
|
|
53
|
-
export { ApiResourceMiddleware, ClassMiddleware,
|
|
63
|
+
export { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MaybePromise, MiddlewareClass, MiddlewareHandle, MiddlewareInstance, RequestData, ResourceAction, RouteGroupCallback, RouteGroupSource, RouterConfig };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { ApiResourceMiddleware, ClassMiddleware, ControllerHandler, FileImporter, HttpMethod, MaybePromise, MiddlewareClass, MiddlewareHandle, MiddlewareInstance, RequestData, ResourceAction, RouteGroupCallback, RouteGroupSource, RouterConfig } from "./basic.mjs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-router",
|
|
3
|
-
"version": "2.8.
|
|
3
|
+
"version": "2.8.2",
|
|
4
4
|
"description": "Laravel-style routing for Node.js with support for Express, H3, Fastify, Hono, and Koa, including CommonJS, ESM, and TypeScript support.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"h3",
|
|
@@ -82,13 +82,13 @@
|
|
|
82
82
|
"LICENSE"
|
|
83
83
|
],
|
|
84
84
|
"peerDependencies": {
|
|
85
|
+
"@h3ravel/support": "^0.15.11",
|
|
85
86
|
"@koa/router": "^15.0.0",
|
|
86
87
|
"express": "^5.1.0",
|
|
87
88
|
"fastify": "^5.0.0",
|
|
88
89
|
"h3": "^2.0.1-rc.16",
|
|
89
90
|
"hono": "^4.0.0",
|
|
90
91
|
"koa": "^3.0.0",
|
|
91
|
-
"@h3ravel/support": "^0.15.11",
|
|
92
92
|
"reflect-metadata": "^0.2.2"
|
|
93
93
|
},
|
|
94
94
|
"peerDependenciesMeta": {
|
|
@@ -144,6 +144,9 @@
|
|
|
144
144
|
"engines": {
|
|
145
145
|
"node": ">=20.0.0"
|
|
146
146
|
},
|
|
147
|
+
"dependencies": {
|
|
148
|
+
"jiti": "^2.7.0"
|
|
149
|
+
},
|
|
147
150
|
"scripts": {
|
|
148
151
|
"test": "vitest run",
|
|
149
152
|
"test:watch": "vitest --watch",
|