clear-router 2.5.7 → 2.5.8
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-DIanvIVd.mjs → bindings-DJDdQv1q.mjs} +1 -1
- package/dist/{bindings-DvV2DXWi.cjs → bindings-T0FKpWyi.cjs} +6 -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.mjs +1 -1
- package/dist/decorators/setup.cjs +2 -2
- 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 +61 -24
- package/dist/index.d.cts +18 -2
- package/dist/index.d.mts +18 -2
- package/dist/index.mjs +61 -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-_II3dOJ5.mjs → responses-B184V5nj.mjs} +1 -1
- package/dist/{responses-JzXstGU5.cjs → responses-CfCmLLo9.cjs} +1 -1
- package/dist/{router-D7R3G8w-.d.mts → router-B8l8jerS.d.mts} +18 -2
- package/dist/{router-WAxKAcWR.d.cts → router-CiGcLUZD.d.cts} +18 -2
- package/dist/{router-BdMuUzGU.cjs → router-DbPFGTYG.cjs} +62 -25
- package/dist/{router-DzbF-ZV0.mjs → router-we2Hw9nA.mjs} +62 -25
- package/package.json +5 -5
|
@@ -208,4 +208,4 @@ function isClass(value) {
|
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
//#endregion
|
|
211
|
-
export { getStandardMetadata as a, getDesignParamTypes as i, Container as n,
|
|
211
|
+
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 };
|
|
@@ -250,4 +250,10 @@ Object.defineProperty(exports, 'getStandardMetadata', {
|
|
|
250
250
|
get: function () {
|
|
251
251
|
return getStandardMetadata;
|
|
252
252
|
}
|
|
253
|
+
});
|
|
254
|
+
Object.defineProperty(exports, 'isClass', {
|
|
255
|
+
enumerable: true,
|
|
256
|
+
get: function () {
|
|
257
|
+
return isClass;
|
|
258
|
+
}
|
|
253
259
|
});
|
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-T0FKpWyi.cjs');
|
|
3
|
+
const require_router = require('../router-DbPFGTYG.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-CiGcLUZD.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-B8l8jerS.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-DJDdQv1q.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-we2Hw9nA.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-T0FKpWyi.cjs');
|
|
3
3
|
|
|
4
4
|
exports.Bind = require_bindings.Bind;
|
|
5
5
|
exports.Container = require_bindings.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-T0FKpWyi.cjs');
|
|
3
|
+
const require_router = require('../router-DbPFGTYG.cjs');
|
|
4
4
|
require('./index.cjs');
|
|
5
5
|
require("reflect-metadata");
|
|
6
6
|
|
|
@@ -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-DJDdQv1q.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-we2Hw9nA.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-T0FKpWyi.cjs');
|
|
3
|
+
const require_router = require('../router-DbPFGTYG.cjs');
|
|
4
|
+
const require_responses = require('../responses-CfCmLLo9.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-CiGcLUZD.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-B8l8jerS.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-DJDdQv1q.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
|
|
3
|
+
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-B184V5nj.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-T0FKpWyi.cjs');
|
|
3
|
+
const require_router = require('../router-DbPFGTYG.cjs');
|
|
4
|
+
const require_responses = require('../responses-CfCmLLo9.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-CiGcLUZD.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-B8l8jerS.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-DJDdQv1q.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
|
|
3
|
+
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-B184V5nj.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-T0FKpWyi.cjs');
|
|
3
|
+
const require_router = require('../router-DbPFGTYG.cjs');
|
|
4
|
+
const require_responses = require('../responses-CfCmLLo9.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-CiGcLUZD.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-B8l8jerS.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-DJDdQv1q.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
|
|
3
|
+
import { n as resolveResponseMeta } from "../responses-B184V5nj.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-T0FKpWyi.cjs');
|
|
3
|
+
const require_router = require('../router-DbPFGTYG.cjs');
|
|
4
|
+
const require_responses = require('../responses-CfCmLLo9.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-CiGcLUZD.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-B8l8jerS.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-DJDdQv1q.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
|
|
3
|
+
import { n as resolveResponseMeta } from "../responses-B184V5nj.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/hono/router.ts
|
|
6
6
|
/**
|
package/dist/index.cjs
CHANGED
|
@@ -384,9 +384,17 @@ var CoreRouter = class {
|
|
|
384
384
|
const setup = async () => {
|
|
385
385
|
const ctx = {
|
|
386
386
|
container: Container,
|
|
387
|
-
bind:
|
|
387
|
+
bind: this.createPluginBind(),
|
|
388
388
|
configure: this.configure.bind(this),
|
|
389
389
|
configureDefaults: this.configureDefaults.bind(this),
|
|
390
|
+
get request() {
|
|
391
|
+
return this.getRequest();
|
|
392
|
+
},
|
|
393
|
+
get response() {
|
|
394
|
+
return this.getResponse();
|
|
395
|
+
},
|
|
396
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
397
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
390
398
|
options
|
|
391
399
|
};
|
|
392
400
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -410,12 +418,39 @@ var CoreRouter = class {
|
|
|
410
418
|
await Promise.all(pending);
|
|
411
419
|
}
|
|
412
420
|
static groupContext = new node_async_hooks.AsyncLocalStorage();
|
|
421
|
+
static pluginRequestContext = new node_async_hooks.AsyncLocalStorage();
|
|
413
422
|
static routes = [];
|
|
414
423
|
static routesByPathMethod = {};
|
|
415
424
|
static routesByMethod = {};
|
|
416
425
|
static prefix = "";
|
|
417
426
|
static groupMiddlewares = [];
|
|
418
427
|
static globalMiddlewares = [];
|
|
428
|
+
static getCurrentPluginRequestContext() {
|
|
429
|
+
return this.pluginRequestContext.getStore();
|
|
430
|
+
}
|
|
431
|
+
static createPluginRequestContext(ctx) {
|
|
432
|
+
const request = ctx.clearRequest;
|
|
433
|
+
const response = ctx.clearResponse;
|
|
434
|
+
return {
|
|
435
|
+
...ctx,
|
|
436
|
+
ctx,
|
|
437
|
+
request,
|
|
438
|
+
response,
|
|
439
|
+
clearRequest: request,
|
|
440
|
+
clearResponse: response
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
static createPluginBind() {
|
|
444
|
+
const bind = (token, value) => {
|
|
445
|
+
if (typeof value === "function" && !isClass(value)) {
|
|
446
|
+
const factory = value;
|
|
447
|
+
Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
Container.bind(token, value);
|
|
451
|
+
};
|
|
452
|
+
return bind;
|
|
453
|
+
}
|
|
419
454
|
static ensureState() {
|
|
420
455
|
this.bindStateAccessors();
|
|
421
456
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -730,30 +765,32 @@ var CoreRouter = class {
|
|
|
730
765
|
};
|
|
731
766
|
}
|
|
732
767
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
768
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
769
|
+
await this.pluginsReady();
|
|
770
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
771
|
+
const metadata = getBindingMetadataFromTargets([
|
|
772
|
+
{
|
|
773
|
+
target: bindingTarget,
|
|
774
|
+
propertyKey: bindingMethod
|
|
775
|
+
},
|
|
776
|
+
{ target: bindingHandler },
|
|
777
|
+
{
|
|
778
|
+
target: bindingTarget,
|
|
779
|
+
propertyKey: "__class__"
|
|
780
|
+
}
|
|
781
|
+
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
782
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
783
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
784
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
785
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
786
|
+
const args = [];
|
|
787
|
+
for (const token of tokens) {
|
|
788
|
+
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
789
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
790
|
+
args.push(resolved);
|
|
744
791
|
}
|
|
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);
|
|
792
|
+
return handlerFunction(...args);
|
|
793
|
+
});
|
|
757
794
|
}
|
|
758
795
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
759
796
|
const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
|
package/dist/index.d.cts
CHANGED
|
@@ -144,12 +144,24 @@ declare class Container {
|
|
|
144
144
|
//#endregion
|
|
145
145
|
//#region src/core/plugins.d.ts
|
|
146
146
|
type PluginSetupResult = void | Promise<void>;
|
|
147
|
-
|
|
147
|
+
interface ClearRouterPluginRequestContext {
|
|
148
|
+
ctx: any;
|
|
149
|
+
request: Request;
|
|
150
|
+
response: Response$1;
|
|
151
|
+
[key: string]: any;
|
|
152
|
+
}
|
|
153
|
+
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
154
|
+
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
155
|
+
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
148
156
|
interface ClearRouterPluginContext<Options = any> {
|
|
149
157
|
container: typeof Container;
|
|
150
158
|
bind: PluginBind;
|
|
151
159
|
configure: (options: RouterConfig) => void;
|
|
152
160
|
configureDefaults: (options: RouterConfig) => void;
|
|
161
|
+
readonly request?: Request;
|
|
162
|
+
readonly response?: Response$1;
|
|
163
|
+
getRequest: () => Request | undefined;
|
|
164
|
+
getResponse: () => Response$1 | undefined;
|
|
153
165
|
options: Options;
|
|
154
166
|
}
|
|
155
167
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -211,12 +223,16 @@ declare abstract class CoreRouter {
|
|
|
211
223
|
prefix: string;
|
|
212
224
|
groupMiddlewares: any[];
|
|
213
225
|
}>;
|
|
226
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
214
227
|
static routes: Array<Route<any, any, any>>;
|
|
215
228
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
216
229
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
217
230
|
static prefix: string;
|
|
218
231
|
static groupMiddlewares: any[];
|
|
219
232
|
static globalMiddlewares: any[];
|
|
233
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
234
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
235
|
+
protected static createPluginBind(): PluginBind;
|
|
220
236
|
protected static ensureState(this: any): void;
|
|
221
237
|
/**
|
|
222
238
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -372,4 +388,4 @@ declare abstract class CoreRouter {
|
|
|
372
388
|
}): void;
|
|
373
389
|
}
|
|
374
390
|
//#endregion
|
|
375
|
-
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
|
391
|
+
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
|
@@ -144,12 +144,24 @@ declare class Container {
|
|
|
144
144
|
//#endregion
|
|
145
145
|
//#region src/core/plugins.d.ts
|
|
146
146
|
type PluginSetupResult = void | Promise<void>;
|
|
147
|
-
|
|
147
|
+
interface ClearRouterPluginRequestContext {
|
|
148
|
+
ctx: any;
|
|
149
|
+
request: Request;
|
|
150
|
+
response: Response$1;
|
|
151
|
+
[key: string]: any;
|
|
152
|
+
}
|
|
153
|
+
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
154
|
+
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
155
|
+
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
148
156
|
interface ClearRouterPluginContext<Options = any> {
|
|
149
157
|
container: typeof Container;
|
|
150
158
|
bind: PluginBind;
|
|
151
159
|
configure: (options: RouterConfig) => void;
|
|
152
160
|
configureDefaults: (options: RouterConfig) => void;
|
|
161
|
+
readonly request?: Request;
|
|
162
|
+
readonly response?: Response$1;
|
|
163
|
+
getRequest: () => Request | undefined;
|
|
164
|
+
getResponse: () => Response$1 | undefined;
|
|
153
165
|
options: Options;
|
|
154
166
|
}
|
|
155
167
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -211,12 +223,16 @@ declare abstract class CoreRouter {
|
|
|
211
223
|
prefix: string;
|
|
212
224
|
groupMiddlewares: any[];
|
|
213
225
|
}>;
|
|
226
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
214
227
|
static routes: Array<Route<any, any, any>>;
|
|
215
228
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
216
229
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
217
230
|
static prefix: string;
|
|
218
231
|
static groupMiddlewares: any[];
|
|
219
232
|
static globalMiddlewares: any[];
|
|
233
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
234
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
235
|
+
protected static createPluginBind(): PluginBind;
|
|
220
236
|
protected static ensureState(this: any): void;
|
|
221
237
|
/**
|
|
222
238
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -372,4 +388,4 @@ declare abstract class CoreRouter {
|
|
|
372
388
|
}): void;
|
|
373
389
|
}
|
|
374
390
|
//#endregion
|
|
375
|
-
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, Controller, CoreRouter, PluginBind, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
|
391
|
+
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -383,9 +383,17 @@ var CoreRouter = class {
|
|
|
383
383
|
const setup = async () => {
|
|
384
384
|
const ctx = {
|
|
385
385
|
container: Container,
|
|
386
|
-
bind:
|
|
386
|
+
bind: this.createPluginBind(),
|
|
387
387
|
configure: this.configure.bind(this),
|
|
388
388
|
configureDefaults: this.configureDefaults.bind(this),
|
|
389
|
+
get request() {
|
|
390
|
+
return this.getRequest();
|
|
391
|
+
},
|
|
392
|
+
get response() {
|
|
393
|
+
return this.getResponse();
|
|
394
|
+
},
|
|
395
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
396
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
389
397
|
options
|
|
390
398
|
};
|
|
391
399
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -409,12 +417,39 @@ var CoreRouter = class {
|
|
|
409
417
|
await Promise.all(pending);
|
|
410
418
|
}
|
|
411
419
|
static groupContext = new AsyncLocalStorage();
|
|
420
|
+
static pluginRequestContext = new AsyncLocalStorage();
|
|
412
421
|
static routes = [];
|
|
413
422
|
static routesByPathMethod = {};
|
|
414
423
|
static routesByMethod = {};
|
|
415
424
|
static prefix = "";
|
|
416
425
|
static groupMiddlewares = [];
|
|
417
426
|
static globalMiddlewares = [];
|
|
427
|
+
static getCurrentPluginRequestContext() {
|
|
428
|
+
return this.pluginRequestContext.getStore();
|
|
429
|
+
}
|
|
430
|
+
static createPluginRequestContext(ctx) {
|
|
431
|
+
const request = ctx.clearRequest;
|
|
432
|
+
const response = ctx.clearResponse;
|
|
433
|
+
return {
|
|
434
|
+
...ctx,
|
|
435
|
+
ctx,
|
|
436
|
+
request,
|
|
437
|
+
response,
|
|
438
|
+
clearRequest: request,
|
|
439
|
+
clearResponse: response
|
|
440
|
+
};
|
|
441
|
+
}
|
|
442
|
+
static createPluginBind() {
|
|
443
|
+
const bind = (token, value) => {
|
|
444
|
+
if (typeof value === "function" && !isClass(value)) {
|
|
445
|
+
const factory = value;
|
|
446
|
+
Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
Container.bind(token, value);
|
|
450
|
+
};
|
|
451
|
+
return bind;
|
|
452
|
+
}
|
|
418
453
|
static ensureState() {
|
|
419
454
|
this.bindStateAccessors();
|
|
420
455
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -729,30 +764,32 @@ var CoreRouter = class {
|
|
|
729
764
|
};
|
|
730
765
|
}
|
|
731
766
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
767
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
768
|
+
await this.pluginsReady();
|
|
769
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
770
|
+
const metadata = getBindingMetadataFromTargets([
|
|
771
|
+
{
|
|
772
|
+
target: bindingTarget,
|
|
773
|
+
propertyKey: bindingMethod
|
|
774
|
+
},
|
|
775
|
+
{ target: bindingHandler },
|
|
776
|
+
{
|
|
777
|
+
target: bindingTarget,
|
|
778
|
+
propertyKey: "__class__"
|
|
779
|
+
}
|
|
780
|
+
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
781
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
782
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
783
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
784
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
785
|
+
const args = [];
|
|
786
|
+
for (const token of tokens) {
|
|
787
|
+
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
788
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
789
|
+
args.push(resolved);
|
|
743
790
|
}
|
|
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);
|
|
791
|
+
return handlerFunction(...args);
|
|
792
|
+
});
|
|
756
793
|
}
|
|
757
794
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
758
795
|
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-T0FKpWyi.cjs');
|
|
3
|
+
const require_router = require('../router-DbPFGTYG.cjs');
|
|
4
|
+
const require_responses = require('../responses-CfCmLLo9.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-CiGcLUZD.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-B8l8jerS.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-DJDdQv1q.mjs";
|
|
2
|
+
import { t as CoreRouter } from "../router-we2Hw9nA.mjs";
|
|
3
|
+
import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-B184V5nj.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/koa/router.ts
|
|
6
6
|
/**
|
|
@@ -191,12 +191,24 @@ 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;
|
|
198
206
|
configure: (options: RouterConfig) => void;
|
|
199
207
|
configureDefaults: (options: RouterConfig) => void;
|
|
208
|
+
readonly request?: Request$1;
|
|
209
|
+
readonly response?: Response$2;
|
|
210
|
+
getRequest: () => Request$1 | undefined;
|
|
211
|
+
getResponse: () => Response$2 | undefined;
|
|
200
212
|
options: Options;
|
|
201
213
|
}
|
|
202
214
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -268,12 +280,16 @@ declare abstract class CoreRouter {
|
|
|
268
280
|
prefix: string;
|
|
269
281
|
groupMiddlewares: any[];
|
|
270
282
|
}>;
|
|
283
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
271
284
|
static routes: Array<Route<any, any, any>>;
|
|
272
285
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
273
286
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
274
287
|
static prefix: string;
|
|
275
288
|
static groupMiddlewares: any[];
|
|
276
289
|
static globalMiddlewares: any[];
|
|
290
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
291
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
292
|
+
protected static createPluginBind(): PluginBind;
|
|
277
293
|
protected static ensureState(this: any): void;
|
|
278
294
|
/**
|
|
279
295
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -429,4 +445,4 @@ declare abstract class CoreRouter {
|
|
|
429
445
|
}): void;
|
|
430
446
|
}
|
|
431
447
|
//#endregion
|
|
432
|
-
export {
|
|
448
|
+
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 };
|
|
@@ -191,12 +191,24 @@ 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;
|
|
198
206
|
configure: (options: RouterConfig) => void;
|
|
199
207
|
configureDefaults: (options: RouterConfig) => void;
|
|
208
|
+
readonly request?: Request$1;
|
|
209
|
+
readonly response?: Response$2;
|
|
210
|
+
getRequest: () => Request$1 | undefined;
|
|
211
|
+
getResponse: () => Response$2 | undefined;
|
|
200
212
|
options: Options;
|
|
201
213
|
}
|
|
202
214
|
interface ClearRouterPlugin<Options = any> {
|
|
@@ -268,12 +280,16 @@ declare abstract class CoreRouter {
|
|
|
268
280
|
prefix: string;
|
|
269
281
|
groupMiddlewares: any[];
|
|
270
282
|
}>;
|
|
283
|
+
protected static pluginRequestContext: AsyncLocalStorage<ClearRouterPluginRequestContext>;
|
|
271
284
|
static routes: Array<Route<any, any, any>>;
|
|
272
285
|
static routesByPathMethod: Record<string, Route<any, any, any>>;
|
|
273
286
|
static routesByMethod: { [method in Uppercase<HttpMethod>]?: Array<Route<any, any, any>> };
|
|
274
287
|
static prefix: string;
|
|
275
288
|
static groupMiddlewares: any[];
|
|
276
289
|
static globalMiddlewares: any[];
|
|
290
|
+
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
291
|
+
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
292
|
+
protected static createPluginBind(): PluginBind;
|
|
277
293
|
protected static ensureState(this: any): void;
|
|
278
294
|
/**
|
|
279
295
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -429,4 +445,4 @@ declare abstract class CoreRouter {
|
|
|
429
445
|
}): void;
|
|
430
446
|
}
|
|
431
447
|
//#endregion
|
|
432
|
-
export {
|
|
448
|
+
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
|
-
const require_bindings = require('./bindings-
|
|
1
|
+
const require_bindings = require('./bindings-T0FKpWyi.cjs');
|
|
2
2
|
let node_async_hooks = require("node:async_hooks");
|
|
3
3
|
|
|
4
4
|
//#region src/Route.ts
|
|
@@ -207,9 +207,17 @@ 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
211
|
configure: this.configure.bind(this),
|
|
212
212
|
configureDefaults: this.configureDefaults.bind(this),
|
|
213
|
+
get request() {
|
|
214
|
+
return this.getRequest();
|
|
215
|
+
},
|
|
216
|
+
get response() {
|
|
217
|
+
return this.getResponse();
|
|
218
|
+
},
|
|
219
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
220
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
213
221
|
options
|
|
214
222
|
};
|
|
215
223
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -233,12 +241,39 @@ var CoreRouter = class {
|
|
|
233
241
|
await Promise.all(pending);
|
|
234
242
|
}
|
|
235
243
|
static groupContext = new node_async_hooks.AsyncLocalStorage();
|
|
244
|
+
static pluginRequestContext = new node_async_hooks.AsyncLocalStorage();
|
|
236
245
|
static routes = [];
|
|
237
246
|
static routesByPathMethod = {};
|
|
238
247
|
static routesByMethod = {};
|
|
239
248
|
static prefix = "";
|
|
240
249
|
static groupMiddlewares = [];
|
|
241
250
|
static globalMiddlewares = [];
|
|
251
|
+
static getCurrentPluginRequestContext() {
|
|
252
|
+
return this.pluginRequestContext.getStore();
|
|
253
|
+
}
|
|
254
|
+
static createPluginRequestContext(ctx) {
|
|
255
|
+
const request = ctx.clearRequest;
|
|
256
|
+
const response = ctx.clearResponse;
|
|
257
|
+
return {
|
|
258
|
+
...ctx,
|
|
259
|
+
ctx,
|
|
260
|
+
request,
|
|
261
|
+
response,
|
|
262
|
+
clearRequest: request,
|
|
263
|
+
clearResponse: response
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
static createPluginBind() {
|
|
267
|
+
const bind = (token, value) => {
|
|
268
|
+
if (typeof value === "function" && !require_bindings.isClass(value)) {
|
|
269
|
+
const factory = value;
|
|
270
|
+
require_bindings.Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
require_bindings.Container.bind(token, value);
|
|
274
|
+
};
|
|
275
|
+
return bind;
|
|
276
|
+
}
|
|
242
277
|
static ensureState() {
|
|
243
278
|
this.bindStateAccessors();
|
|
244
279
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -553,30 +588,32 @@ var CoreRouter = class {
|
|
|
553
588
|
};
|
|
554
589
|
}
|
|
555
590
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
591
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
592
|
+
await this.pluginsReady();
|
|
593
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
594
|
+
const metadata = require_bindings.getBindingMetadataFromTargets([
|
|
595
|
+
{
|
|
596
|
+
target: bindingTarget,
|
|
597
|
+
propertyKey: bindingMethod
|
|
598
|
+
},
|
|
599
|
+
{ target: bindingHandler },
|
|
600
|
+
{
|
|
601
|
+
target: bindingTarget,
|
|
602
|
+
propertyKey: "__class__"
|
|
603
|
+
}
|
|
604
|
+
]) ?? require_bindings.getStandardMetadata(bindingMetadata, bindingMethod) ?? require_bindings.getStandardMetadata(bindingMetadata, "__class__");
|
|
605
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
606
|
+
const designTokens = [...bindingTarget ? require_bindings.getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? require_bindings.getDesignParamTypes(bindingHandler) : []];
|
|
607
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
608
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
609
|
+
const args = [];
|
|
610
|
+
for (const token of tokens) {
|
|
611
|
+
const resolved = await require_bindings.Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
612
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
613
|
+
args.push(resolved);
|
|
567
614
|
}
|
|
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);
|
|
615
|
+
return handlerFunction(...args);
|
|
616
|
+
});
|
|
580
617
|
}
|
|
581
618
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
582
619
|
const clearRequest = ctx.clearRequest instanceof require_bindings.Request ? ctx.clearRequest : new require_bindings.Request({
|
|
@@ -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-DJDdQv1q.mjs";
|
|
2
2
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
3
3
|
|
|
4
4
|
//#region src/Route.ts
|
|
@@ -207,9 +207,17 @@ var CoreRouter = class {
|
|
|
207
207
|
const setup = async () => {
|
|
208
208
|
const ctx = {
|
|
209
209
|
container: Container,
|
|
210
|
-
bind:
|
|
210
|
+
bind: this.createPluginBind(),
|
|
211
211
|
configure: this.configure.bind(this),
|
|
212
212
|
configureDefaults: this.configureDefaults.bind(this),
|
|
213
|
+
get request() {
|
|
214
|
+
return this.getRequest();
|
|
215
|
+
},
|
|
216
|
+
get response() {
|
|
217
|
+
return this.getResponse();
|
|
218
|
+
},
|
|
219
|
+
getRequest: () => this.getCurrentPluginRequestContext()?.request,
|
|
220
|
+
getResponse: () => this.getCurrentPluginRequestContext()?.response,
|
|
213
221
|
options
|
|
214
222
|
};
|
|
215
223
|
if (typeof plugin === "function") await plugin(ctx);
|
|
@@ -233,12 +241,39 @@ var CoreRouter = class {
|
|
|
233
241
|
await Promise.all(pending);
|
|
234
242
|
}
|
|
235
243
|
static groupContext = new AsyncLocalStorage();
|
|
244
|
+
static pluginRequestContext = new AsyncLocalStorage();
|
|
236
245
|
static routes = [];
|
|
237
246
|
static routesByPathMethod = {};
|
|
238
247
|
static routesByMethod = {};
|
|
239
248
|
static prefix = "";
|
|
240
249
|
static groupMiddlewares = [];
|
|
241
250
|
static globalMiddlewares = [];
|
|
251
|
+
static getCurrentPluginRequestContext() {
|
|
252
|
+
return this.pluginRequestContext.getStore();
|
|
253
|
+
}
|
|
254
|
+
static createPluginRequestContext(ctx) {
|
|
255
|
+
const request = ctx.clearRequest;
|
|
256
|
+
const response = ctx.clearResponse;
|
|
257
|
+
return {
|
|
258
|
+
...ctx,
|
|
259
|
+
ctx,
|
|
260
|
+
request,
|
|
261
|
+
response,
|
|
262
|
+
clearRequest: request,
|
|
263
|
+
clearResponse: response
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
static createPluginBind() {
|
|
267
|
+
const bind = (token, value) => {
|
|
268
|
+
if (typeof value === "function" && !isClass(value)) {
|
|
269
|
+
const factory = value;
|
|
270
|
+
Container.bind(token, (ctx) => factory(this.createPluginRequestContext(ctx)));
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
Container.bind(token, value);
|
|
274
|
+
};
|
|
275
|
+
return bind;
|
|
276
|
+
}
|
|
242
277
|
static ensureState() {
|
|
243
278
|
this.bindStateAccessors();
|
|
244
279
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -553,30 +588,32 @@ var CoreRouter = class {
|
|
|
553
588
|
};
|
|
554
589
|
}
|
|
555
590
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
591
|
+
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
592
|
+
await this.pluginsReady();
|
|
593
|
+
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
594
|
+
const metadata = getBindingMetadataFromTargets([
|
|
595
|
+
{
|
|
596
|
+
target: bindingTarget,
|
|
597
|
+
propertyKey: bindingMethod
|
|
598
|
+
},
|
|
599
|
+
{ target: bindingHandler },
|
|
600
|
+
{
|
|
601
|
+
target: bindingTarget,
|
|
602
|
+
propertyKey: "__class__"
|
|
603
|
+
}
|
|
604
|
+
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
605
|
+
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
606
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
607
|
+
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
608
|
+
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
609
|
+
const args = [];
|
|
610
|
+
for (const token of tokens) {
|
|
611
|
+
const resolved = await Container.resolve(token, ctx, Boolean(this.config.container?.autoDiscover));
|
|
612
|
+
if (typeof resolved === "undefined") return handlerFunction(ctx, ctx.clearRequest);
|
|
613
|
+
args.push(resolved);
|
|
567
614
|
}
|
|
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);
|
|
615
|
+
return handlerFunction(...args);
|
|
616
|
+
});
|
|
580
617
|
}
|
|
581
618
|
static bindRequestToInstance(ctx, instance, route, payload) {
|
|
582
619
|
const clearRequest = ctx.clearRequest instanceof Request ? ctx.clearRequest : new Request({
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "clear-router",
|
|
3
|
-
"version": "2.5.
|
|
3
|
+
"version": "2.5.8",
|
|
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"
|