clear-router 2.5.7 → 2.5.9
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/{bindings-CV1e5jho.d.mts → bindings-B5ttDy47.d.cts} +1 -0
- package/dist/{bindings-NV0CdqGl.d.cts → bindings-BWMHQe9i.d.mts} +1 -0
- package/dist/{bindings-DIanvIVd.mjs → bindings-CYpdvTjf.mjs} +4 -1
- package/dist/{bindings-DvV2DXWi.cjs → bindings-CoxxSopM.cjs} +9 -0
- package/dist/core/index.cjs +2 -2
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +2 -2
- package/dist/decorators/index.cjs +1 -1
- package/dist/decorators/index.d.cts +1 -1
- package/dist/decorators/index.d.mts +1 -1
- package/dist/decorators/index.mjs +1 -1
- package/dist/decorators/setup.cjs +2 -2
- package/dist/decorators/setup.d.cts +1 -1
- package/dist/decorators/setup.d.mts +2 -1
- package/dist/decorators/setup.mjs +2 -2
- package/dist/express/index.cjs +3 -3
- package/dist/express/index.d.cts +1 -1
- package/dist/express/index.d.mts +1 -1
- package/dist/express/index.mjs +3 -3
- package/dist/fastify/index.cjs +3 -3
- package/dist/fastify/index.d.cts +1 -1
- package/dist/fastify/index.d.mts +1 -1
- package/dist/fastify/index.mjs +3 -3
- package/dist/h3/index.cjs +3 -3
- package/dist/h3/index.d.cts +1 -1
- package/dist/h3/index.d.mts +1 -1
- package/dist/h3/index.mjs +3 -3
- package/dist/hono/index.cjs +3 -3
- package/dist/hono/index.d.cts +1 -1
- package/dist/hono/index.d.mts +1 -1
- package/dist/hono/index.mjs +3 -3
- package/dist/index.cjs +65 -24
- package/dist/index.d.cts +20 -2
- package/dist/index.d.mts +20 -2
- package/dist/index.mjs +65 -24
- package/dist/koa/index.cjs +3 -3
- package/dist/koa/index.d.cts +1 -1
- package/dist/koa/index.d.mts +1 -1
- package/dist/koa/index.mjs +3 -3
- package/dist/{responses-JzXstGU5.cjs → responses-B7G02ibg.cjs} +1 -1
- package/dist/{responses-_II3dOJ5.mjs → responses-DUFly0RZ.mjs} +1 -1
- package/dist/{router-DzbF-ZV0.mjs → router-B_ouWc5s.mjs} +63 -25
- package/dist/{router-BdMuUzGU.cjs → router-Cmua21-t.cjs} +63 -25
- package/dist/{router-D7R3G8w-.d.mts → router-DMFeflRM.d.mts} +20 -3
- package/dist/{router-WAxKAcWR.d.cts → router-SAdZ7fgy.d.cts} +20 -3
- package/package.json +5 -5
|
@@ -12,6 +12,7 @@ declare class Container {
|
|
|
12
12
|
static unbind<T>(token: BindToken<T>): void;
|
|
13
13
|
static clear(): void;
|
|
14
14
|
static has<T>(token: BindToken<T>): boolean;
|
|
15
|
+
static bindings<V = any>(): Record<string, BindValue<V>>;
|
|
15
16
|
static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
|
|
16
17
|
private static resolveBinding;
|
|
17
18
|
}
|
|
@@ -12,6 +12,7 @@ declare class Container {
|
|
|
12
12
|
static unbind<T>(token: BindToken<T>): void;
|
|
13
13
|
static clear(): void;
|
|
14
14
|
static has<T>(token: BindToken<T>): boolean;
|
|
15
|
+
static bindings<V = any>(): Record<string, BindValue<V>>;
|
|
15
16
|
static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
|
|
16
17
|
private static resolveBinding;
|
|
17
18
|
}
|
|
@@ -118,6 +118,9 @@ var Container = class {
|
|
|
118
118
|
static has(token) {
|
|
119
119
|
return this.registry.has(token);
|
|
120
120
|
}
|
|
121
|
+
static bindings() {
|
|
122
|
+
return Object.fromEntries(this.registry.entries());
|
|
123
|
+
}
|
|
121
124
|
static async resolve(token, ctx, autoDiscover = false) {
|
|
122
125
|
if (token === Request) return ctx.clearRequest;
|
|
123
126
|
if (token === Response) return ctx.clearResponse;
|
|
@@ -208,4 +211,4 @@ function isClass(value) {
|
|
|
208
211
|
}
|
|
209
212
|
|
|
210
213
|
//#endregion
|
|
211
|
-
export { getStandardMetadata as a, getDesignParamTypes as i, Container as n,
|
|
214
|
+
export { getStandardMetadata as a, Request as c, getDesignParamTypes as i, Container as n, isClass as o, getBindingMetadataFromTargets as r, Response as s, Bind as t };
|
|
@@ -119,6 +119,9 @@ var Container = class {
|
|
|
119
119
|
static has(token) {
|
|
120
120
|
return this.registry.has(token);
|
|
121
121
|
}
|
|
122
|
+
static bindings() {
|
|
123
|
+
return Object.fromEntries(this.registry.entries());
|
|
124
|
+
}
|
|
122
125
|
static async resolve(token, ctx, autoDiscover = false) {
|
|
123
126
|
if (token === Request) return ctx.clearRequest;
|
|
124
127
|
if (token === Response) return ctx.clearResponse;
|
|
@@ -250,4 +253,10 @@ Object.defineProperty(exports, 'getStandardMetadata', {
|
|
|
250
253
|
get: function () {
|
|
251
254
|
return getStandardMetadata;
|
|
252
255
|
}
|
|
256
|
+
});
|
|
257
|
+
Object.defineProperty(exports, 'isClass', {
|
|
258
|
+
enumerable: true,
|
|
259
|
+
get: function () {
|
|
260
|
+
return isClass;
|
|
261
|
+
}
|
|
253
262
|
});
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_bindings = require('../bindings-
|
|
3
|
-
const require_router = require('../router-
|
|
2
|
+
const require_bindings = require('../bindings-CoxxSopM.cjs');
|
|
3
|
+
const require_router = require('../router-Cmua21-t.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/core/plugins.ts
|
|
6
6
|
function definePlugin(plugin) {
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
|
|
1
|
+
import { a as ClearRouterPluginRequestContext, c as PluginBindValue, d as Request, i as ClearRouterPluginInput, l as PluginSetupResult, n as ClearRouterPlugin, o as PluginBind, r as ClearRouterPluginContext, s as PluginBindFactory, t as CoreRouter, u as definePlugin, w as Response } from "../router-SAdZ7fgy.cjs";
|
|
2
|
+
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as
|
|
2
|
-
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
|
|
1
|
+
import { a as ClearRouterPluginRequestContext, c as PluginBindValue, d as Request, i as ClearRouterPluginInput, l as PluginSetupResult, n as ClearRouterPlugin, o as PluginBind, r as ClearRouterPluginContext, s as PluginBindFactory, t as CoreRouter, u as definePlugin, w as Response } from "../router-DMFeflRM.mjs";
|
|
2
|
+
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
1
|
+
import { c as Request, s as Response } from "../bindings-CYpdvTjf.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/core/plugins.ts
|
|
5
5
|
function definePlugin(plugin) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_bindings = require('../bindings-
|
|
2
|
+
const require_bindings = require('../bindings-CoxxSopM.cjs');
|
|
3
3
|
|
|
4
4
|
exports.Bind = require_bindings.Bind;
|
|
5
5
|
exports.Container = require_bindings.Container;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-
|
|
1
|
+
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-B5ttDy47.cjs";
|
|
2
2
|
export { Bind, type BindDecorator, type BindFactory, type BindToken, type BindValue, Container };
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-
|
|
1
|
+
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-BWMHQe9i.mjs";
|
|
2
2
|
export { Bind, type BindDecorator, type BindFactory, type BindToken, type BindValue, Container };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const require_bindings = require('../bindings-
|
|
3
|
-
const require_router = require('../router-
|
|
2
|
+
const require_bindings = require('../bindings-CoxxSopM.cjs');
|
|
3
|
+
const require_router = require('../router-Cmua21-t.cjs');
|
|
4
4
|
require('./index.cjs');
|
|
5
5
|
require("reflect-metadata");
|
|
6
6
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-
|
|
1
|
+
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-B5ttDy47.cjs";
|
|
2
2
|
export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
-
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-
|
|
1
|
+
import { a as BindValue, i as BindToken, n as BindDecorator, o as Container, r as BindFactory, t as Bind } from "../bindings-BWMHQe9i.mjs";
|
|
2
|
+
import "reflect-metadata";
|
|
2
3
|
export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { n as Container, t as Bind } from "../bindings-
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
1
|
+
import { n as Container, t as Bind } from "../bindings-CYpdvTjf.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
|
|
3
3
|
import "./index.mjs";
|
|
4
4
|
import "reflect-metadata";
|
|
5
5
|
|
package/dist/express/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
require('../bindings-
|
|
3
|
-
const require_router = require('../router-
|
|
4
|
-
const require_responses = require('../responses-
|
|
2
|
+
require('../bindings-CoxxSopM.cjs');
|
|
3
|
+
const require_router = require('../router-Cmua21-t.cjs');
|
|
4
|
+
const require_responses = require('../responses-B7G02ibg.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/express/router.ts
|
|
7
7
|
/**
|
package/dist/express/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, _ as Handler, b as ApiResourceMiddleware, f as Route, t as CoreRouter, v as HttpContext, x as ControllerAction, y as Middleware } from "../router-SAdZ7fgy.cjs";
|
|
2
2
|
import { Router as Router$1 } from "express";
|
|
3
3
|
|
|
4
4
|
//#region src/express/router.d.ts
|
package/dist/express/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, _ as Handler, b as ApiResourceMiddleware, f as Route, t as CoreRouter, v as HttpContext, x as ControllerAction, y as Middleware } from "../router-DMFeflRM.mjs";
|
|
2
2
|
import { Router as Router$1 } from "express";
|
|
3
3
|
|
|
4
4
|
//#region src/express/router.d.ts
|
package/dist/express/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../bindings-
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
3
|
-
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-
|
|
1
|
+
import "../bindings-CYpdvTjf.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
|
|
3
|
+
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DUFly0RZ.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/express/router.ts
|
|
6
6
|
/**
|
package/dist/fastify/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
require('../bindings-
|
|
3
|
-
const require_router = require('../router-
|
|
4
|
-
const require_responses = require('../responses-
|
|
2
|
+
require('../bindings-CoxxSopM.cjs');
|
|
3
|
+
const require_router = require('../router-Cmua21-t.cjs');
|
|
4
|
+
const require_responses = require('../responses-B7G02ibg.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/fastify/router.ts
|
|
7
7
|
/**
|
package/dist/fastify/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-SAdZ7fgy.cjs";
|
|
2
2
|
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
3
3
|
|
|
4
4
|
//#region types/fastify.d.ts
|
package/dist/fastify/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-DMFeflRM.mjs";
|
|
2
2
|
import { FastifyInstance, FastifyReply, FastifyRequest } from "fastify";
|
|
3
3
|
|
|
4
4
|
//#region types/fastify.d.ts
|
package/dist/fastify/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../bindings-
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
3
|
-
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-
|
|
1
|
+
import "../bindings-CYpdvTjf.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
|
|
3
|
+
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DUFly0RZ.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/fastify/router.ts
|
|
6
6
|
/**
|
package/dist/h3/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
require('../bindings-
|
|
3
|
-
const require_router = require('../router-
|
|
4
|
-
const require_responses = require('../responses-
|
|
2
|
+
require('../bindings-CoxxSopM.cjs');
|
|
3
|
+
const require_router = require('../router-Cmua21-t.cjs');
|
|
4
|
+
const require_responses = require('../responses-B7G02ibg.cjs');
|
|
5
5
|
let h3 = require("h3");
|
|
6
6
|
|
|
7
7
|
//#region src/h3/router.ts
|
package/dist/h3/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, b as ApiResourceMiddleware, f as Route, g as Middleware, h as HttpContext, m as Handler, p as H3App, t as CoreRouter, x as ControllerAction } from "../router-SAdZ7fgy.cjs";
|
|
2
2
|
import { H3 } from "h3";
|
|
3
3
|
|
|
4
4
|
//#region src/h3/router.d.ts
|
package/dist/h3/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, b as ApiResourceMiddleware, f as Route, g as Middleware, h as HttpContext, m as Handler, p as H3App, t as CoreRouter, x as ControllerAction } from "../router-DMFeflRM.mjs";
|
|
2
2
|
import { H3 } from "h3";
|
|
3
3
|
|
|
4
4
|
//#region src/h3/router.d.ts
|
package/dist/h3/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../bindings-
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
3
|
-
import { n as resolveResponseMeta } from "../responses-
|
|
1
|
+
import "../bindings-CYpdvTjf.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
|
|
3
|
+
import { n as resolveResponseMeta } from "../responses-DUFly0RZ.mjs";
|
|
4
4
|
import { HTTPResponse, getQuery, getRouterParams, readBody } from "h3";
|
|
5
5
|
|
|
6
6
|
//#region src/h3/router.ts
|
package/dist/hono/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
require('../bindings-
|
|
3
|
-
const require_router = require('../router-
|
|
4
|
-
const require_responses = require('../responses-
|
|
2
|
+
require('../bindings-CoxxSopM.cjs');
|
|
3
|
+
const require_router = require('../router-Cmua21-t.cjs');
|
|
4
|
+
const require_responses = require('../responses-B7G02ibg.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/hono/router.ts
|
|
7
7
|
/**
|
package/dist/hono/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-SAdZ7fgy.cjs";
|
|
2
2
|
import { Context, HonoRequest, MiddlewareHandler } from "hono";
|
|
3
3
|
|
|
4
4
|
//#region types/hono.d.ts
|
package/dist/hono/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-DMFeflRM.mjs";
|
|
2
2
|
import { Context, HonoRequest, MiddlewareHandler } from "hono";
|
|
3
3
|
|
|
4
4
|
//#region types/hono.d.ts
|
package/dist/hono/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../bindings-
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
3
|
-
import { n as resolveResponseMeta } from "../responses-
|
|
1
|
+
import "../bindings-CYpdvTjf.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
|
|
3
|
+
import { n as resolveResponseMeta } from "../responses-DUFly0RZ.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/hono/router.ts
|
|
6
6
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -165,6 +165,9 @@ var Container = class {
|
|
|
165
165
|
static has(token) {
|
|
166
166
|
return this.registry.has(token);
|
|
167
167
|
}
|
|
168
|
+
static bindings() {
|
|
169
|
+
return Object.fromEntries(this.registry.entries());
|
|
170
|
+
}
|
|
168
171
|
static async resolve(token, ctx, autoDiscover = false) {
|
|
169
172
|
if (token === Request) return ctx.clearRequest;
|
|
170
173
|
if (token === Response) return ctx.clearResponse;
|
|
@@ -384,9 +387,18 @@ var CoreRouter = class {
|
|
|
384
387
|
const setup = async () => {
|
|
385
388
|
const ctx = {
|
|
386
389
|
container: Container,
|
|
387
|
-
bind:
|
|
390
|
+
bind: this.createPluginBind(),
|
|
391
|
+
bindings: Container.bindings(),
|
|
388
392
|
configure: this.configure.bind(this),
|
|
389
393
|
configureDefaults: this.configureDefaults.bind(this),
|
|
394
|
+
get request() {
|
|
395
|
+
return this.getRequest();
|
|
396
|
+
},
|
|
397
|
+
get response() {
|
|
398
|
+
return this.getResponse();
|
|
399
|
+
},
|
|
400
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
401
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
390
402
|
options
|
|
391
403
|
};
|
|
392
404
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -410,12 +422,39 @@ var CoreRouter = class {
|
|
|
410
422
|
await Promise.all(pending);
|
|
411
423
|
}
|
|
412
424
|
static groupContext = new node_async_hooks.AsyncLocalStorage();
|
|
425
|
+
static pluginRequestContext = new node_async_hooks.AsyncLocalStorage();
|
|
413
426
|
static routes = [];
|
|
414
427
|
static routesByPathMethod = {};
|
|
415
428
|
static routesByMethod = {};
|
|
416
429
|
static prefix = "";
|
|
417
430
|
static groupMiddlewares = [];
|
|
418
431
|
static globalMiddlewares = [];
|
|
432
|
+
static getCurrentPluginRequestContext() {
|
|
433
|
+
return this.pluginRequestContext.getStore();
|
|
434
|
+
}
|
|
435
|
+
static createPluginRequestContext(ctx) {
|
|
436
|
+
const request = ctx.clearRequest;
|
|
437
|
+
const response = ctx.clearResponse;
|
|
438
|
+
return {
|
|
439
|
+
...ctx,
|
|
440
|
+
ctx,
|
|
441
|
+
request,
|
|
442
|
+
response,
|
|
443
|
+
clearRequest: request,
|
|
444
|
+
clearResponse: response
|
|
445
|
+
};
|
|
446
|
+
}
|
|
447
|
+
static createPluginBind() {
|
|
448
|
+
const bind = (token, value) => {
|
|
449
|
+
if (typeof value === "function" && !isClass(value)) {
|
|
450
|
+
const factory = value;
|
|
451
|
+
Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
Container.bind(token, value);
|
|
455
|
+
};
|
|
456
|
+
return bind;
|
|
457
|
+
}
|
|
419
458
|
static ensureState() {
|
|
420
459
|
this.bindStateAccessors();
|
|
421
460
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -730,30 +769,32 @@ var CoreRouter = class {
|
|
|
730
769
|
};
|
|
731
770
|
}
|
|
732
771
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
772
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
773
|
+
await this.pluginsReady();
|
|
774
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
775
|
+
const metadata = getBindingMetadataFromTargets([
|
|
776
|
+
{
|
|
777
|
+
target: bindingTarget,
|
|
778
|
+
propertyKey: bindingMethod
|
|
779
|
+
},
|
|
780
|
+
{ target: bindingHandler },
|
|
781
|
+
{
|
|
782
|
+
target: bindingTarget,
|
|
783
|
+
propertyKey: "__class__"
|
|
784
|
+
}
|
|
785
|
+
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
786
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
787
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
788
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
789
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
790
|
+
const args = [];
|
|
791
|
+
for (const token of tokens) {
|
|
792
|
+
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
793
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
794
|
+
args.push(resolved);
|
|
744
795
|
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
748
|
-
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
749
|
-
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
750
|
-
const args = [];
|
|
751
|
-
for (const token of tokens) {
|
|
752
|
-
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
753
|
-
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
754
|
-
args.push(resolved);
|
|
755
|
-
}
|
|
756
|
-
return handlerFunction(...args);
|
|
796
|
+
return handlerFunction(...args);
|
|
797
|
+
});
|
|
757
798
|
}
|
|
758
799
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
759
800
|
const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
|
package/dist/index.d.cts
CHANGED
|
@@ -138,18 +138,32 @@ declare class Container {
|
|
|
138
138
|
static unbind<T>(token: BindToken<T>): void;
|
|
139
139
|
static clear(): void;
|
|
140
140
|
static has<T>(token: BindToken<T>): boolean;
|
|
141
|
+
static bindings<V = any>(): Record<string, BindValue<V>>;
|
|
141
142
|
static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
|
|
142
143
|
private static resolveBinding;
|
|
143
144
|
}
|
|
144
145
|
//#endregion
|
|
145
146
|
//#region src/core/plugins.d.ts
|
|
146
147
|
type PluginSetupResult = void | Promise<void>;
|
|
147
|
-
|
|
148
|
+
interface ClearRouterPluginRequestContext {
|
|
149
|
+
ctx: any;
|
|
150
|
+
request: Request;
|
|
151
|
+
response: Response$1;
|
|
152
|
+
[key: string]: any;
|
|
153
|
+
}
|
|
154
|
+
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
155
|
+
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
156
|
+
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
148
157
|
interface ClearRouterPluginContext<Options = any> {
|
|
149
158
|
container: typeof Container;
|
|
150
159
|
bind: PluginBind;
|
|
160
|
+
bindings: Record<string, BindValue>;
|
|
151
161
|
configure: (options: RouterConfig) => void;
|
|
152
162
|
configureDefaults: (options: RouterConfig) => void;
|
|
163
|
+
readonly request?: Request;
|
|
164
|
+
readonly response?: Response$1;
|
|
165
|
+
getRequest: () => Request | undefined;
|
|
166
|
+
getResponse: () => Response$1 | undefined;
|
|
153
167
|
options: Options;
|
|
154
168
|
}
|
|
155
169
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -211,12 +225,16 @@ declare abstract class CoreRouter {
|
|
|
211
225
|
prefix: string;
|
|
212
226
|
groupMiddlewares: any[];
|
|
213
227
|
}>;
|
|
228
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
214
229
|
static routes: Array<Route<any, any, any>>;
|
|
215
230
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
216
231
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
217
232
|
static prefix: string;
|
|
218
233
|
static groupMiddlewares: any[];
|
|
219
234
|
static globalMiddlewares: any[];
|
|
235
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
236
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
237
|
+
protected static createPluginBind(): PluginBind;
|
|
220
238
|
protected static ensureState(this: any): void;
|
|
221
239
|
/**
|
|
222
240
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -372,4 +390,4 @@ declare abstract class CoreRouter {
|
|
|
372
390
|
}): void;
|
|
373
391
|
}
|
|
374
392
|
//#endregion
|
|
375
|
-
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
|
393
|
+
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
package/dist/index.d.mts
CHANGED
|
@@ -138,18 +138,32 @@ declare class Container {
|
|
|
138
138
|
static unbind<T>(token: BindToken<T>): void;
|
|
139
139
|
static clear(): void;
|
|
140
140
|
static has<T>(token: BindToken<T>): boolean;
|
|
141
|
+
static bindings<V = any>(): Record<string, BindValue<V>>;
|
|
141
142
|
static resolve<T>(token: BindToken<T>, ctx: any, autoDiscover?: boolean): Promise<T | undefined>;
|
|
142
143
|
private static resolveBinding;
|
|
143
144
|
}
|
|
144
145
|
//#endregion
|
|
145
146
|
//#region src/core/plugins.d.ts
|
|
146
147
|
type PluginSetupResult = void | Promise<void>;
|
|
147
|
-
|
|
148
|
+
interface ClearRouterPluginRequestContext {
|
|
149
|
+
ctx: any;
|
|
150
|
+
request: Request;
|
|
151
|
+
response: Response$1;
|
|
152
|
+
[key: string]: any;
|
|
153
|
+
}
|
|
154
|
+
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
155
|
+
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
156
|
+
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
148
157
|
interface ClearRouterPluginContext<Options = any> {
|
|
149
158
|
container: typeof Container;
|
|
150
159
|
bind: PluginBind;
|
|
160
|
+
bindings: Record<string, BindValue>;
|
|
151
161
|
configure: (options: RouterConfig) => void;
|
|
152
162
|
configureDefaults: (options: RouterConfig) => void;
|
|
163
|
+
readonly request?: Request;
|
|
164
|
+
readonly response?: Response$1;
|
|
165
|
+
getRequest: () => Request | undefined;
|
|
166
|
+
getResponse: () => Response$1 | undefined;
|
|
153
167
|
options: Options;
|
|
154
168
|
}
|
|
155
169
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -211,12 +225,16 @@ declare abstract class CoreRouter {
|
|
|
211
225
|
prefix: string;
|
|
212
226
|
groupMiddlewares: any[];
|
|
213
227
|
}>;
|
|
228
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
214
229
|
static routes: Array<Route<any, any, any>>;
|
|
215
230
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
216
231
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
217
232
|
static prefix: string;
|
|
218
233
|
static groupMiddlewares: any[];
|
|
219
234
|
static globalMiddlewares: any[];
|
|
235
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
236
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
237
|
+
protected static createPluginBind(): PluginBind;
|
|
220
238
|
protected static ensureState(this: any): void;
|
|
221
239
|
/**
|
|
222
240
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -372,4 +390,4 @@ declare abstract class CoreRouter {
|
|
|
372
390
|
}): void;
|
|
373
391
|
}
|
|
374
392
|
//#endregion
|
|
375
|
-
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
|
393
|
+
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -164,6 +164,9 @@ var Container = class {
|
|
|
164
164
|
static has(token) {
|
|
165
165
|
return this.registry.has(token);
|
|
166
166
|
}
|
|
167
|
+
static bindings() {
|
|
168
|
+
return Object.fromEntries(this.registry.entries());
|
|
169
|
+
}
|
|
167
170
|
static async resolve(token, ctx, autoDiscover = false) {
|
|
168
171
|
if (token === Request) return ctx.clearRequest;
|
|
169
172
|
if (token === Response) return ctx.clearResponse;
|
|
@@ -383,9 +386,18 @@ var CoreRouter = class {
|
|
|
383
386
|
const setup = async () => {
|
|
384
387
|
const ctx = {
|
|
385
388
|
container: Container,
|
|
386
|
-
bind:
|
|
389
|
+
bind: this.createPluginBind(),
|
|
390
|
+
bindings: Container.bindings(),
|
|
387
391
|
configure: this.configure.bind(this),
|
|
388
392
|
configureDefaults: this.configureDefaults.bind(this),
|
|
393
|
+
get request() {
|
|
394
|
+
return this.getRequest();
|
|
395
|
+
},
|
|
396
|
+
get response() {
|
|
397
|
+
return this.getResponse();
|
|
398
|
+
},
|
|
399
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
400
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
389
401
|
options
|
|
390
402
|
};
|
|
391
403
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -409,12 +421,39 @@ var CoreRouter = class {
|
|
|
409
421
|
await Promise.all(pending);
|
|
410
422
|
}
|
|
411
423
|
static groupContext = new AsyncLocalStorage();
|
|
424
|
+
static pluginRequestContext = new AsyncLocalStorage();
|
|
412
425
|
static routes = [];
|
|
413
426
|
static routesByPathMethod = {};
|
|
414
427
|
static routesByMethod = {};
|
|
415
428
|
static prefix = "";
|
|
416
429
|
static groupMiddlewares = [];
|
|
417
430
|
static globalMiddlewares = [];
|
|
431
|
+
static getCurrentPluginRequestContext() {
|
|
432
|
+
return this.pluginRequestContext.getStore();
|
|
433
|
+
}
|
|
434
|
+
static createPluginRequestContext(ctx) {
|
|
435
|
+
const request = ctx.clearRequest;
|
|
436
|
+
const response = ctx.clearResponse;
|
|
437
|
+
return {
|
|
438
|
+
...ctx,
|
|
439
|
+
ctx,
|
|
440
|
+
request,
|
|
441
|
+
response,
|
|
442
|
+
clearRequest: request,
|
|
443
|
+
clearResponse: response
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
static createPluginBind() {
|
|
447
|
+
const bind = (token, value) => {
|
|
448
|
+
if (typeof value === "function" && !isClass(value)) {
|
|
449
|
+
const factory = value;
|
|
450
|
+
Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
451
|
+
return;
|
|
452
|
+
}
|
|
453
|
+
Container.bind(token, value);
|
|
454
|
+
};
|
|
455
|
+
return bind;
|
|
456
|
+
}
|
|
418
457
|
static ensureState() {
|
|
419
458
|
this.bindStateAccessors();
|
|
420
459
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -729,30 +768,32 @@ var CoreRouter = class {
|
|
|
729
768
|
};
|
|
730
769
|
}
|
|
731
770
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
771
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
772
|
+
await this.pluginsReady();
|
|
773
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
774
|
+
const metadata = getBindingMetadataFromTargets([
|
|
775
|
+
{
|
|
776
|
+
target: bindingTarget,
|
|
777
|
+
propertyKey: bindingMethod
|
|
778
|
+
},
|
|
779
|
+
{ target: bindingHandler },
|
|
780
|
+
{
|
|
781
|
+
target: bindingTarget,
|
|
782
|
+
propertyKey: "__class__"
|
|
783
|
+
}
|
|
784
|
+
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
785
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
786
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
787
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
788
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
789
|
+
const args = [];
|
|
790
|
+
for (const token of tokens) {
|
|
791
|
+
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
792
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
793
|
+
args.push(resolved);
|
|
743
794
|
}
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
747
|
-
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
748
|
-
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
749
|
-
const args = [];
|
|
750
|
-
for (const token of tokens) {
|
|
751
|
-
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
752
|
-
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
753
|
-
args.push(resolved);
|
|
754
|
-
}
|
|
755
|
-
return handlerFunction(...args);
|
|
795
|
+
return handlerFunction(...args);
|
|
796
|
+
});
|
|
756
797
|
}
|
|
757
798
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
758
799
|
const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
|
package/dist/koa/index.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
require('../bindings-
|
|
3
|
-
const require_router = require('../router-
|
|
4
|
-
const require_responses = require('../responses-
|
|
2
|
+
require('../bindings-CoxxSopM.cjs');
|
|
3
|
+
const require_router = require('../router-Cmua21-t.cjs');
|
|
4
|
+
const require_responses = require('../responses-B7G02ibg.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/koa/router.ts
|
|
7
7
|
/**
|
package/dist/koa/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-SAdZ7fgy.cjs";
|
|
2
2
|
import Koa from "koa";
|
|
3
3
|
import Router$1 from "@koa/router";
|
|
4
4
|
|
package/dist/koa/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { C as HttpMethod, S as ControllerHandler, b as ApiResourceMiddleware, d as Request, f as Route, t as CoreRouter, w as Response, x as ControllerAction } from "../router-DMFeflRM.mjs";
|
|
2
2
|
import Koa from "koa";
|
|
3
3
|
import Router$1 from "@koa/router";
|
|
4
4
|
|
package/dist/koa/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import "../bindings-
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
3
|
-
import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-
|
|
1
|
+
import "../bindings-CYpdvTjf.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-B_ouWc5s.mjs";
|
|
3
|
+
import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-DUFly0RZ.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/koa/router.ts
|
|
6
6
|
/**
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as getStandardMetadata, i as getDesignParamTypes, n as Container, o as
|
|
1
|
+
import { a as getStandardMetadata, c as Request, i as getDesignParamTypes, n as Container, o as isClass, r as getBindingMetadataFromTargets, s as Response } from "./bindings-CYpdvTjf.mjs";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
|
|
4
4
|
//#region src/Route.ts
|
|
@@ -207,9 +207,18 @@ var CoreRouter = class {
|
|
|
207
207
|
const setup = async () => {
|
|
208
208
|
const ctx = {
|
|
209
209
|
container: Container,
|
|
210
|
-
bind:
|
|
210
|
+
bind: this.createPluginBind(),
|
|
211
|
+
bindings: Container.bindings(),
|
|
211
212
|
configure: this.configure.bind(this),
|
|
212
213
|
configureDefaults: this.configureDefaults.bind(this),
|
|
214
|
+
get request() {
|
|
215
|
+
return this.getRequest();
|
|
216
|
+
},
|
|
217
|
+
get response() {
|
|
218
|
+
return this.getResponse();
|
|
219
|
+
},
|
|
220
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
221
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
213
222
|
options
|
|
214
223
|
};
|
|
215
224
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -233,12 +242,39 @@ var CoreRouter = class {
|
|
|
233
242
|
await Promise.all(pending);
|
|
234
243
|
}
|
|
235
244
|
static groupContext = new AsyncLocalStorage();
|
|
245
|
+
static pluginRequestContext = new AsyncLocalStorage();
|
|
236
246
|
static routes = [];
|
|
237
247
|
static routesByPathMethod = {};
|
|
238
248
|
static routesByMethod = {};
|
|
239
249
|
static prefix = "";
|
|
240
250
|
static groupMiddlewares = [];
|
|
241
251
|
static globalMiddlewares = [];
|
|
252
|
+
static getCurrentPluginRequestContext() {
|
|
253
|
+
return this.pluginRequestContext.getStore();
|
|
254
|
+
}
|
|
255
|
+
static createPluginRequestContext(ctx) {
|
|
256
|
+
const request = ctx.clearRequest;
|
|
257
|
+
const response = ctx.clearResponse;
|
|
258
|
+
return {
|
|
259
|
+
...ctx,
|
|
260
|
+
ctx,
|
|
261
|
+
request,
|
|
262
|
+
response,
|
|
263
|
+
clearRequest: request,
|
|
264
|
+
clearResponse: response
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
static createPluginBind() {
|
|
268
|
+
const bind = (token, value) => {
|
|
269
|
+
if (typeof value === "function" && !isClass(value)) {
|
|
270
|
+
const factory = value;
|
|
271
|
+
Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
Container.bind(token, value);
|
|
275
|
+
};
|
|
276
|
+
return bind;
|
|
277
|
+
}
|
|
242
278
|
static ensureState() {
|
|
243
279
|
this.bindStateAccessors();
|
|
244
280
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -553,30 +589,32 @@ var CoreRouter = class {
|
|
|
553
589
|
};
|
|
554
590
|
}
|
|
555
591
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
592
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
593
|
+
await this.pluginsReady();
|
|
594
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
595
|
+
const metadata = getBindingMetadataFromTargets([
|
|
596
|
+
{
|
|
597
|
+
target: bindingTarget,
|
|
598
|
+
propertyKey: bindingMethod
|
|
599
|
+
},
|
|
600
|
+
{ target: bindingHandler },
|
|
601
|
+
{
|
|
602
|
+
target: bindingTarget,
|
|
603
|
+
propertyKey: "__class__"
|
|
604
|
+
}
|
|
605
|
+
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
606
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
607
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
608
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
609
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
610
|
+
const args = [];
|
|
611
|
+
for (const token of tokens) {
|
|
612
|
+
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
613
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
614
|
+
args.push(resolved);
|
|
567
615
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
571
|
-
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
572
|
-
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
573
|
-
const args = [];
|
|
574
|
-
for (const token of tokens) {
|
|
575
|
-
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
576
|
-
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
577
|
-
args.push(resolved);
|
|
578
|
-
}
|
|
579
|
-
return handlerFunction(...args);
|
|
616
|
+
return handlerFunction(...args);
|
|
617
|
+
});
|
|
580
618
|
}
|
|
581
619
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
582
620
|
const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const require_bindings = require('./bindings-
|
|
1
|
+
const require_bindings = require('./bindings-CoxxSopM.cjs');
|
|
2
2
|
let node_async_hooks = require("node:async_hooks");
|
|
3
3
|
|
|
4
4
|
//#region src/Route.ts
|
|
@@ -207,9 +207,18 @@ var CoreRouter = class {
|
|
|
207
207
|
const setup = async () => {
|
|
208
208
|
const ctx = {
|
|
209
209
|
container: require_bindings.Container,
|
|
210
|
-
bind:
|
|
210
|
+
bind: this.createPluginBind(),
|
|
211
|
+
bindings: require_bindings.Container.bindings(),
|
|
211
212
|
configure: this.configure.bind(this),
|
|
212
213
|
configureDefaults: this.configureDefaults.bind(this),
|
|
214
|
+
get request() {
|
|
215
|
+
return this.getRequest();
|
|
216
|
+
},
|
|
217
|
+
get response() {
|
|
218
|
+
return this.getResponse();
|
|
219
|
+
},
|
|
220
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
221
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
213
222
|
options
|
|
214
223
|
};
|
|
215
224
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -233,12 +242,39 @@ var CoreRouter = class {
|
|
|
233
242
|
await Promise.all(pending);
|
|
234
243
|
}
|
|
235
244
|
static groupContext = new node_async_hooks.AsyncLocalStorage();
|
|
245
|
+
static pluginRequestContext = new node_async_hooks.AsyncLocalStorage();
|
|
236
246
|
static routes = [];
|
|
237
247
|
static routesByPathMethod = {};
|
|
238
248
|
static routesByMethod = {};
|
|
239
249
|
static prefix = "";
|
|
240
250
|
static groupMiddlewares = [];
|
|
241
251
|
static globalMiddlewares = [];
|
|
252
|
+
static getCurrentPluginRequestContext() {
|
|
253
|
+
return this.pluginRequestContext.getStore();
|
|
254
|
+
}
|
|
255
|
+
static createPluginRequestContext(ctx) {
|
|
256
|
+
const request = ctx.clearRequest;
|
|
257
|
+
const response = ctx.clearResponse;
|
|
258
|
+
return {
|
|
259
|
+
...ctx,
|
|
260
|
+
ctx,
|
|
261
|
+
request,
|
|
262
|
+
response,
|
|
263
|
+
clearRequest: request,
|
|
264
|
+
clearResponse: response
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
static createPluginBind() {
|
|
268
|
+
const bind = (token, value) => {
|
|
269
|
+
if (typeof value === "function" && !require_bindings.isClass(value)) {
|
|
270
|
+
const factory = value;
|
|
271
|
+
require_bindings.Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
require_bindings.Container.bind(token, value);
|
|
275
|
+
};
|
|
276
|
+
return bind;
|
|
277
|
+
}
|
|
242
278
|
static ensureState() {
|
|
243
279
|
this.bindStateAccessors();
|
|
244
280
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -553,30 +589,32 @@ var CoreRouter = class {
|
|
|
553
589
|
};
|
|
554
590
|
}
|
|
555
591
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
592
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
593
|
+
await this.pluginsReady();
|
|
594
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
595
|
+
const metadata = require_bindings.getBindingMetadataFromTargets([
|
|
596
|
+
{
|
|
597
|
+
target: bindingTarget,
|
|
598
|
+
propertyKey: bindingMethod
|
|
599
|
+
},
|
|
600
|
+
{ target: bindingHandler },
|
|
601
|
+
{
|
|
602
|
+
target: bindingTarget,
|
|
603
|
+
propertyKey: "__class__"
|
|
604
|
+
}
|
|
605
|
+
]) ?? require_bindings.getStandardMetadata(bindingMetadata, bindingMethod) ?? require_bindings.getStandardMetadata(bindingMetadata, "__class__");
|
|
606
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
607
|
+
const designTokens = [...bindingTarget ? require_bindings.getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? require_bindings.getDesignParamTypes(bindingHandler) : []];
|
|
608
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
609
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
610
|
+
const args = [];
|
|
611
|
+
for (const token of tokens) {
|
|
612
|
+
const resolved = await require_bindings.Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
613
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
614
|
+
args.push(resolved);
|
|
567
615
|
}
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
const designTokens = [...bindingTarget ? require_bindings.getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? require_bindings.getDesignParamTypes(bindingHandler) : []];
|
|
571
|
-
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
572
|
-
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
573
|
-
const args = [];
|
|
574
|
-
for (const token of tokens) {
|
|
575
|
-
const resolved = await require_bindings.Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
576
|
-
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
577
|
-
args.push(resolved);
|
|
578
|
-
}
|
|
579
|
-
return handlerFunction(...args);
|
|
616
|
+
return handlerFunction(...args);
|
|
617
|
+
});
|
|
580
618
|
}
|
|
581
619
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
582
620
|
const clearRequest = ctx.clearRequest instanceof require_bindings.Request ? ctx.clearRequest : new require_bindings.Request({
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as BindValue, i as BindToken, o as Container } from "./bindings-
|
|
1
|
+
import { a as BindValue, i as BindToken, o as Container } from "./bindings-BWMHQe9i.mjs";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
|
|
4
4
|
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
@@ -191,12 +191,25 @@ declare class Request$1<X = any, M = any> extends ClearRequest<X, M> {
|
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/core/plugins.d.ts
|
|
193
193
|
type PluginSetupResult = void | Promise<void>;
|
|
194
|
-
|
|
194
|
+
interface ClearRouterPluginRequestContext {
|
|
195
|
+
ctx: any;
|
|
196
|
+
request: Request$1;
|
|
197
|
+
response: Response$2;
|
|
198
|
+
[key: string]: any;
|
|
199
|
+
}
|
|
200
|
+
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
201
|
+
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
202
|
+
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
195
203
|
interface ClearRouterPluginContext<Options = any> {
|
|
196
204
|
container: typeof Container;
|
|
197
205
|
bind: PluginBind;
|
|
206
|
+
bindings: Record<string, BindValue>;
|
|
198
207
|
configure: (options: RouterConfig) => void;
|
|
199
208
|
configureDefaults: (options: RouterConfig) => void;
|
|
209
|
+
readonly request?: Request$1;
|
|
210
|
+
readonly response?: Response$2;
|
|
211
|
+
getRequest: () => Request$1 | undefined;
|
|
212
|
+
getResponse: () => Response$2 | undefined;
|
|
200
213
|
options: Options;
|
|
201
214
|
}
|
|
202
215
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -268,12 +281,16 @@ declare abstract class CoreRouter {
|
|
|
268
281
|
prefix: string;
|
|
269
282
|
groupMiddlewares: any[];
|
|
270
283
|
}>;
|
|
284
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
271
285
|
static routes: Array<Route<any, any, any>>;
|
|
272
286
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
273
287
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
274
288
|
static prefix: string;
|
|
275
289
|
static groupMiddlewares: any[];
|
|
276
290
|
static globalMiddlewares: any[];
|
|
291
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
292
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
293
|
+
protected static createPluginBind(): PluginBind;
|
|
277
294
|
protected static ensureState(this: any): void;
|
|
278
295
|
/**
|
|
279
296
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -429,4 +446,4 @@ declare abstract class CoreRouter {
|
|
|
429
446
|
}): void;
|
|
430
447
|
}
|
|
431
448
|
//#endregion
|
|
432
|
-
export {
|
|
449
|
+
export { HttpMethod as C, ControllerHandler as S, Handler$1 as _, ClearRouterPluginRequestContext as a, ApiResourceMiddleware as b, PluginBindValue as c, Request$1 as d, Route as f, Middleware as g, HttpContext as h, ClearRouterPluginInput as i, PluginSetupResult as l, Handler as m, ClearRouterPlugin as n, PluginBind as o, H3App as p, ClearRouterPluginContext as r, PluginBindFactory as s, CoreRouter as t, definePlugin as u, HttpContext$1 as v, Response$2 as w, ControllerAction as x, Middleware$1 as y };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as BindValue, i as BindToken, o as Container } from "./bindings-
|
|
1
|
+
import { a as BindValue, i as BindToken, o as Container } from "./bindings-B5ttDy47.cjs";
|
|
2
2
|
import { NextFunction, Request, Response as Response$1 } from "express";
|
|
3
3
|
import { EventHandlerRequest, H3, H3Event, Middleware, TypedServerRequest } from "h3";
|
|
4
4
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
@@ -191,12 +191,25 @@ declare class Request$1<X = any, M = any> extends ClearRequest<X, M> {
|
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/core/plugins.d.ts
|
|
193
193
|
type PluginSetupResult = void | Promise<void>;
|
|
194
|
-
|
|
194
|
+
interface ClearRouterPluginRequestContext {
|
|
195
|
+
ctx: any;
|
|
196
|
+
request: Request$1;
|
|
197
|
+
response: Response$2;
|
|
198
|
+
[key: string]: any;
|
|
199
|
+
}
|
|
200
|
+
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
201
|
+
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
202
|
+
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
195
203
|
interface ClearRouterPluginContext<Options = any> {
|
|
196
204
|
container: typeof Container;
|
|
197
205
|
bind: PluginBind;
|
|
206
|
+
bindings: Record<string, BindValue>;
|
|
198
207
|
configure: (options: RouterConfig) => void;
|
|
199
208
|
configureDefaults: (options: RouterConfig) => void;
|
|
209
|
+
readonly request?: Request$1;
|
|
210
|
+
readonly response?: Response$2;
|
|
211
|
+
getRequest: () => Request$1 | undefined;
|
|
212
|
+
getResponse: () => Response$2 | undefined;
|
|
200
213
|
options: Options;
|
|
201
214
|
}
|
|
202
215
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -268,12 +281,16 @@ declare abstract class CoreRouter {
|
|
|
268
281
|
prefix: string;
|
|
269
282
|
groupMiddlewares: any[];
|
|
270
283
|
}>;
|
|
284
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
271
285
|
static routes: Array<Route<any, any, any>>;
|
|
272
286
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
273
287
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
274
288
|
static prefix: string;
|
|
275
289
|
static groupMiddlewares: any[];
|
|
276
290
|
static globalMiddlewares: any[];
|
|
291
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
292
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
293
|
+
protected static createPluginBind(): PluginBind;
|
|
277
294
|
protected static ensureState(this: any): void;
|
|
278
295
|
/**
|
|
279
296
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -429,4 +446,4 @@ declare abstract class CoreRouter {
|
|
|
429
446
|
}): void;
|
|
430
447
|
}
|
|
431
448
|
//#endregion
|
|
432
|
-
export {
|
|
449
|
+
export { HttpMethod as C, ControllerHandler as S, Handler$1 as _, ClearRouterPluginRequestContext as a, ApiResourceMiddleware as b, PluginBindValue as c, Request$1 as d, Route as f, Middleware as g, HttpContext as h, ClearRouterPluginInput as i, PluginSetupResult as l, Handler as m, ClearRouterPlugin as n, PluginBind as o, H3App as p, ClearRouterPluginContext as r, PluginBindFactory as s, CoreRouter as t, definePlugin as u, HttpContext$1 as v, Response$2 as w, ControllerAction as x, Middleware$1 as y };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-router",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.9",
|
|
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",
|
|
@@ -121,7 +121,7 @@
|
|
|
121
121
|
"@types/koa": "^3.0.2",
|
|
122
122
|
"@types/koa__router": "^12.0.5",
|
|
123
123
|
"@types/node": "^20.10.6",
|
|
124
|
-
"@vitest/coverage-v8": "4.
|
|
124
|
+
"@vitest/coverage-v8": "4.1.5",
|
|
125
125
|
"eslint": "^10.0.2",
|
|
126
126
|
"fastify": "^5.8.2",
|
|
127
127
|
"hono": "^4.12.8",
|
|
@@ -133,9 +133,9 @@
|
|
|
133
133
|
"typescript": "^5.3.3",
|
|
134
134
|
"typescript-eslint": "^8.56.1",
|
|
135
135
|
"unrun": "0.2.27",
|
|
136
|
-
"vite
|
|
137
|
-
"vitepress": "^
|
|
138
|
-
"vitest": "^4.
|
|
136
|
+
"vite": "^8.0.11",
|
|
137
|
+
"vitepress": "^2.0.0-alpha.17",
|
|
138
|
+
"vitest": "^4.1.5"
|
|
139
139
|
},
|
|
140
140
|
"engines": {
|
|
141
141
|
"node": ">=20.0.0"
|