clear-router 2.5.11 → 2.5.12
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/core/index.cjs +1 -1
- package/dist/core/index.d.cts +2 -2
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.mjs +1 -1
- package/dist/decorators/setup.cjs +1 -1
- package/dist/decorators/setup.mjs +1 -1
- package/dist/express/index.cjs +1 -1
- package/dist/express/index.d.cts +1 -1
- package/dist/express/index.d.mts +1 -1
- package/dist/express/index.mjs +1 -1
- package/dist/fastify/index.cjs +1 -1
- package/dist/fastify/index.d.cts +1 -1
- package/dist/fastify/index.d.mts +1 -1
- package/dist/fastify/index.mjs +1 -1
- package/dist/h3/index.cjs +1 -1
- package/dist/h3/index.d.cts +1 -1
- package/dist/h3/index.d.mts +1 -1
- package/dist/h3/index.mjs +1 -1
- package/dist/hono/index.cjs +1 -1
- package/dist/hono/index.d.cts +1 -1
- package/dist/hono/index.d.mts +1 -1
- package/dist/hono/index.mjs +1 -1
- package/dist/index.cjs +33 -4
- package/dist/index.d.cts +15 -1
- package/dist/index.d.mts +15 -1
- package/dist/index.mjs +33 -4
- package/dist/koa/index.cjs +1 -1
- package/dist/koa/index.d.cts +1 -1
- package/dist/koa/index.d.mts +1 -1
- package/dist/koa/index.mjs +1 -1
- package/dist/{router-DCGZNRNj.d.cts → router-35iBbCaF.d.cts} +15 -1
- package/dist/{router-BkYtqjYr.d.mts → router-91xVPlV0.d.mts} +15 -1
- package/dist/{router-CArh9OHb.mjs → router-BkJMl4xv.mjs} +33 -4
- package/dist/{router-DtqXUlJq.cjs → router-DPJfzvy5.cjs} +33 -4
- package/package.json +1 -1
package/dist/core/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_bindings = require('../bindings-CDGLuAq4.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-DPJfzvy5.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, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
|
1
|
+
import { E as Response, a as ClearRouterPluginInput, c as PluginBind, d as PluginSetupResult, f as definePlugin, i as ClearRouterPluginContext, l as PluginBindFactory, n as ClearRouterPlugin, o as ClearRouterPluginRequestContext, p as Request, r as ClearRouterPluginArgumentsContext, s as PluginArgumentsResolver, t as CoreRouter, u as PluginBindValue } from "../router-35iBbCaF.cjs";
|
|
2
|
+
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, 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, ClearRouterPluginRequestContext, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
|
1
|
+
import { E as Response, a as ClearRouterPluginInput, c as PluginBind, d as PluginSetupResult, f as definePlugin, i as ClearRouterPluginContext, l as PluginBindFactory, n as ClearRouterPlugin, o as ClearRouterPluginRequestContext, p as Request, r as ClearRouterPluginArgumentsContext, s as PluginArgumentsResolver, t as CoreRouter, u as PluginBindValue } from "../router-91xVPlV0.mjs";
|
|
2
|
+
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_bindings = require('../bindings-CDGLuAq4.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-DPJfzvy5.cjs');
|
|
4
4
|
require('./index.cjs');
|
|
5
5
|
require("reflect-metadata");
|
|
6
6
|
|
package/dist/express/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('../bindings-CDGLuAq4.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-DPJfzvy5.cjs');
|
|
4
4
|
const require_responses = require('../responses-CBP3RYjJ.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/express/router.ts
|
package/dist/express/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, b as HttpContext, m as Route, t as CoreRouter, x as Middleware, y as Handler } from "../router-35iBbCaF.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 { C as
|
|
1
|
+
import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, b as HttpContext, m as Route, t as CoreRouter, x as Middleware, y as Handler } from "../router-91xVPlV0.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,5 +1,5 @@
|
|
|
1
1
|
import "../bindings-B6x2HfzP.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/express/router.ts
|
package/dist/fastify/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('../bindings-CDGLuAq4.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-DPJfzvy5.cjs');
|
|
4
4
|
const require_responses = require('../responses-CBP3RYjJ.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/fastify/router.ts
|
package/dist/fastify/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-35iBbCaF.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 { C as
|
|
1
|
+
import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-91xVPlV0.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,5 +1,5 @@
|
|
|
1
1
|
import "../bindings-B6x2HfzP.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/fastify/router.ts
|
package/dist/h3/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('../bindings-CDGLuAq4.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-DPJfzvy5.cjs');
|
|
4
4
|
const require_responses = require('../responses-CBP3RYjJ.cjs');
|
|
5
5
|
let h3 = require("h3");
|
|
6
6
|
|
package/dist/h3/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, _ as HttpContext, g as Handler, h as H3App, m as Route, t as CoreRouter, v as Middleware } from "../router-35iBbCaF.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 { C as
|
|
1
|
+
import { C as ControllerAction, S as ApiResourceMiddleware, T as HttpMethod, _ as HttpContext, g as Handler, h as H3App, m as Route, t as CoreRouter, v as Middleware } from "../router-91xVPlV0.mjs";
|
|
2
2
|
import { H3 } from "h3";
|
|
3
3
|
|
|
4
4
|
//#region src/h3/router.d.ts
|
package/dist/h3/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../bindings-B6x2HfzP.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
|
|
3
3
|
import { n as resolveResponseMeta } from "../responses-DuZeRyGE.mjs";
|
|
4
4
|
import { HTTPResponse, getQuery, getRouterParams, readBody } from "h3";
|
|
5
5
|
|
package/dist/hono/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('../bindings-CDGLuAq4.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-DPJfzvy5.cjs');
|
|
4
4
|
const require_responses = require('../responses-CBP3RYjJ.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/hono/router.ts
|
package/dist/hono/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-35iBbCaF.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 { C as
|
|
1
|
+
import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-91xVPlV0.mjs";
|
|
2
2
|
import { Context, HonoRequest, MiddlewareHandler } from "hono";
|
|
3
3
|
|
|
4
4
|
//#region types/hono.d.ts
|
package/dist/hono/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -263,6 +263,7 @@ var CoreRouter = class {
|
|
|
263
263
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
264
264
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
265
265
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
266
|
+
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
266
267
|
static createBaseConfig() {
|
|
267
268
|
return {
|
|
268
269
|
methodOverride: {
|
|
@@ -314,6 +315,11 @@ var CoreRouter = class {
|
|
|
314
315
|
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
315
316
|
return g[this.pluginPendingKey];
|
|
316
317
|
}
|
|
318
|
+
static getPluginArgumentResolvers() {
|
|
319
|
+
const g = globalThis;
|
|
320
|
+
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
321
|
+
return g[this.pluginArgumentResolversKey];
|
|
322
|
+
}
|
|
317
323
|
static createDefaultState() {
|
|
318
324
|
return {
|
|
319
325
|
config: this.getDefaultConfig(),
|
|
@@ -428,6 +434,9 @@ var CoreRouter = class {
|
|
|
428
434
|
const ctx = {
|
|
429
435
|
container: Container,
|
|
430
436
|
bind: this.createPluginBind(),
|
|
437
|
+
resolveArguments: (resolver) => {
|
|
438
|
+
this.getPluginArgumentResolvers().add(resolver);
|
|
439
|
+
},
|
|
431
440
|
bindings: Container.bindings(),
|
|
432
441
|
configure: this.configure.bind(this),
|
|
433
442
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -480,8 +489,7 @@ var CoreRouter = class {
|
|
|
480
489
|
ctx,
|
|
481
490
|
request,
|
|
482
491
|
response,
|
|
483
|
-
|
|
484
|
-
clearResponse: response
|
|
492
|
+
getBindings: () => Container.bindings()
|
|
485
493
|
};
|
|
486
494
|
}
|
|
487
495
|
static createPluginBind() {
|
|
@@ -495,6 +503,18 @@ var CoreRouter = class {
|
|
|
495
503
|
};
|
|
496
504
|
return bind;
|
|
497
505
|
}
|
|
506
|
+
static async resolvePluginArguments(ctx, routeContext) {
|
|
507
|
+
const resolvers = Array.from(this.getPluginArgumentResolvers());
|
|
508
|
+
if (!resolvers.length) return void 0;
|
|
509
|
+
const pluginContext = {
|
|
510
|
+
...this.createPluginRequestContext(ctx),
|
|
511
|
+
...routeContext
|
|
512
|
+
};
|
|
513
|
+
for (const resolver of resolvers) {
|
|
514
|
+
const args = await resolver(pluginContext);
|
|
515
|
+
if (Array.isArray(args)) return args;
|
|
516
|
+
}
|
|
517
|
+
}
|
|
498
518
|
static ensureState() {
|
|
499
519
|
this.bindStateAccessors();
|
|
500
520
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -812,6 +832,7 @@ var CoreRouter = class {
|
|
|
812
832
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
813
833
|
await this.pluginsReady();
|
|
814
834
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
835
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
815
836
|
const metadata = getBindingMetadataFromTargets([
|
|
816
837
|
{
|
|
817
838
|
target: bindingTarget,
|
|
@@ -823,9 +844,17 @@ var CoreRouter = class {
|
|
|
823
844
|
propertyKey: "__class__"
|
|
824
845
|
}
|
|
825
846
|
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
847
|
+
const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
|
|
848
|
+
const pluginArgs = await this.resolvePluginArguments(ctx, {
|
|
849
|
+
target: bindingTarget,
|
|
850
|
+
method: bindingMethod,
|
|
851
|
+
handler: bindingHandler,
|
|
852
|
+
metadata: bindingMetadata,
|
|
853
|
+
tokens,
|
|
854
|
+
designTokens
|
|
855
|
+
});
|
|
856
|
+
if (pluginArgs) return handlerFunction(...pluginArgs);
|
|
826
857
|
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
827
|
-
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
828
|
-
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
829
858
|
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
830
859
|
const args = [];
|
|
831
860
|
for (const token of tokens) {
|
package/dist/index.d.cts
CHANGED
|
@@ -153,14 +153,25 @@ interface ClearRouterPluginRequestContext {
|
|
|
153
153
|
ctx: any;
|
|
154
154
|
request: Request;
|
|
155
155
|
response: Response$1;
|
|
156
|
+
getBindings: () => Record<string, BindValue>;
|
|
156
157
|
[key: string]: any;
|
|
157
158
|
}
|
|
159
|
+
interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
|
|
160
|
+
target?: object;
|
|
161
|
+
method?: PropertyKey;
|
|
162
|
+
handler?: object;
|
|
163
|
+
metadata?: object;
|
|
164
|
+
tokens: BindToken[];
|
|
165
|
+
designTokens: BindToken[];
|
|
166
|
+
}
|
|
158
167
|
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
159
168
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
160
169
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
170
|
+
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
161
171
|
interface ClearRouterPluginContext<Options = any> {
|
|
162
172
|
container: typeof Container;
|
|
163
173
|
bind: PluginBind;
|
|
174
|
+
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
164
175
|
bindings: Record<string, BindValue>;
|
|
165
176
|
configure: (options: RouterConfig) => void;
|
|
166
177
|
configureDefaults: (options: RouterConfig) => void;
|
|
@@ -191,6 +202,7 @@ declare abstract class CoreRouter {
|
|
|
191
202
|
private static readonly defaultConfigKey;
|
|
192
203
|
private static readonly pluginStoreKey;
|
|
193
204
|
private static readonly pluginPendingKey;
|
|
205
|
+
private static readonly pluginArgumentResolversKey;
|
|
194
206
|
protected static createBaseConfig(): RouterConfig;
|
|
195
207
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
196
208
|
protected static getDefaultConfig(): RouterConfig;
|
|
@@ -198,6 +210,7 @@ declare abstract class CoreRouter {
|
|
|
198
210
|
protected static getStateStore(): Record<string, any>;
|
|
199
211
|
protected static getPluginStore(): Set<string>;
|
|
200
212
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
213
|
+
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
201
214
|
protected static createDefaultState(): {
|
|
202
215
|
config: RouterConfig;
|
|
203
216
|
groupContext: AsyncLocalStorage<{
|
|
@@ -239,6 +252,7 @@ declare abstract class CoreRouter {
|
|
|
239
252
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
240
253
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
241
254
|
protected static createPluginBind(): PluginBind;
|
|
255
|
+
protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
242
256
|
protected static ensureState(this: any): void;
|
|
243
257
|
/**
|
|
244
258
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -394,4 +408,4 @@ declare abstract class CoreRouter {
|
|
|
394
408
|
}): void;
|
|
395
409
|
}
|
|
396
410
|
//#endregion
|
|
397
|
-
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
|
411
|
+
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
package/dist/index.d.mts
CHANGED
|
@@ -153,14 +153,25 @@ interface ClearRouterPluginRequestContext {
|
|
|
153
153
|
ctx: any;
|
|
154
154
|
request: Request;
|
|
155
155
|
response: Response$1;
|
|
156
|
+
getBindings: () => Record<string, BindValue>;
|
|
156
157
|
[key: string]: any;
|
|
157
158
|
}
|
|
159
|
+
interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
|
|
160
|
+
target?: object;
|
|
161
|
+
method?: PropertyKey;
|
|
162
|
+
handler?: object;
|
|
163
|
+
metadata?: object;
|
|
164
|
+
tokens: BindToken[];
|
|
165
|
+
designTokens: BindToken[];
|
|
166
|
+
}
|
|
158
167
|
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
159
168
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
160
169
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
170
|
+
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
161
171
|
interface ClearRouterPluginContext<Options = any> {
|
|
162
172
|
container: typeof Container;
|
|
163
173
|
bind: PluginBind;
|
|
174
|
+
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
164
175
|
bindings: Record<string, BindValue>;
|
|
165
176
|
configure: (options: RouterConfig) => void;
|
|
166
177
|
configureDefaults: (options: RouterConfig) => void;
|
|
@@ -191,6 +202,7 @@ declare abstract class CoreRouter {
|
|
|
191
202
|
private static readonly defaultConfigKey;
|
|
192
203
|
private static readonly pluginStoreKey;
|
|
193
204
|
private static readonly pluginPendingKey;
|
|
205
|
+
private static readonly pluginArgumentResolversKey;
|
|
194
206
|
protected static createBaseConfig(): RouterConfig;
|
|
195
207
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
196
208
|
protected static getDefaultConfig(): RouterConfig;
|
|
@@ -198,6 +210,7 @@ declare abstract class CoreRouter {
|
|
|
198
210
|
protected static getStateStore(): Record<string, any>;
|
|
199
211
|
protected static getPluginStore(): Set<string>;
|
|
200
212
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
213
|
+
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
201
214
|
protected static createDefaultState(): {
|
|
202
215
|
config: RouterConfig;
|
|
203
216
|
groupContext: AsyncLocalStorage<{
|
|
@@ -239,6 +252,7 @@ declare abstract class CoreRouter {
|
|
|
239
252
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
240
253
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
241
254
|
protected static createPluginBind(): PluginBind;
|
|
255
|
+
protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
242
256
|
protected static ensureState(this: any): void;
|
|
243
257
|
/**
|
|
244
258
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -394,4 +408,4 @@ declare abstract class CoreRouter {
|
|
|
394
408
|
}): void;
|
|
395
409
|
}
|
|
396
410
|
//#endregion
|
|
397
|
-
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
|
411
|
+
export { ClearRequest, ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, Controller, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response$1 as Response, Route, definePlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -262,6 +262,7 @@ var CoreRouter = class {
|
|
|
262
262
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
263
263
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
264
264
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
265
|
+
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
265
266
|
static createBaseConfig() {
|
|
266
267
|
return {
|
|
267
268
|
methodOverride: {
|
|
@@ -313,6 +314,11 @@ var CoreRouter = class {
|
|
|
313
314
|
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
314
315
|
return g[this.pluginPendingKey];
|
|
315
316
|
}
|
|
317
|
+
static getPluginArgumentResolvers() {
|
|
318
|
+
const g = globalThis;
|
|
319
|
+
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
320
|
+
return g[this.pluginArgumentResolversKey];
|
|
321
|
+
}
|
|
316
322
|
static createDefaultState() {
|
|
317
323
|
return {
|
|
318
324
|
config: this.getDefaultConfig(),
|
|
@@ -427,6 +433,9 @@ var CoreRouter = class {
|
|
|
427
433
|
const ctx = {
|
|
428
434
|
container: Container,
|
|
429
435
|
bind: this.createPluginBind(),
|
|
436
|
+
resolveArguments: (resolver) => {
|
|
437
|
+
this.getPluginArgumentResolvers().add(resolver);
|
|
438
|
+
},
|
|
430
439
|
bindings: Container.bindings(),
|
|
431
440
|
configure: this.configure.bind(this),
|
|
432
441
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -479,8 +488,7 @@ var CoreRouter = class {
|
|
|
479
488
|
ctx,
|
|
480
489
|
request,
|
|
481
490
|
response,
|
|
482
|
-
|
|
483
|
-
clearResponse: response
|
|
491
|
+
getBindings: () => Container.bindings()
|
|
484
492
|
};
|
|
485
493
|
}
|
|
486
494
|
static createPluginBind() {
|
|
@@ -494,6 +502,18 @@ var CoreRouter = class {
|
|
|
494
502
|
};
|
|
495
503
|
return bind;
|
|
496
504
|
}
|
|
505
|
+
static async resolvePluginArguments(ctx, routeContext) {
|
|
506
|
+
const resolvers = Array.from(this.getPluginArgumentResolvers());
|
|
507
|
+
if (!resolvers.length) return void 0;
|
|
508
|
+
const pluginContext = {
|
|
509
|
+
...this.createPluginRequestContext(ctx),
|
|
510
|
+
...routeContext
|
|
511
|
+
};
|
|
512
|
+
for (const resolver of resolvers) {
|
|
513
|
+
const args = await resolver(pluginContext);
|
|
514
|
+
if (Array.isArray(args)) return args;
|
|
515
|
+
}
|
|
516
|
+
}
|
|
497
517
|
static ensureState() {
|
|
498
518
|
this.bindStateAccessors();
|
|
499
519
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -811,6 +831,7 @@ var CoreRouter = class {
|
|
|
811
831
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
812
832
|
await this.pluginsReady();
|
|
813
833
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
834
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
814
835
|
const metadata = getBindingMetadataFromTargets([
|
|
815
836
|
{
|
|
816
837
|
target: bindingTarget,
|
|
@@ -822,9 +843,17 @@ var CoreRouter = class {
|
|
|
822
843
|
propertyKey: "__class__"
|
|
823
844
|
}
|
|
824
845
|
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
846
|
+
const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
|
|
847
|
+
const pluginArgs = await this.resolvePluginArguments(ctx, {
|
|
848
|
+
target: bindingTarget,
|
|
849
|
+
method: bindingMethod,
|
|
850
|
+
handler: bindingHandler,
|
|
851
|
+
metadata: bindingMetadata,
|
|
852
|
+
tokens,
|
|
853
|
+
designTokens
|
|
854
|
+
});
|
|
855
|
+
if (pluginArgs) return handlerFunction(...pluginArgs);
|
|
825
856
|
if (!metadata) return handlerFunction(ctx, ctx.clearRequest);
|
|
826
|
-
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
827
|
-
const tokens = metadata.tokens?.length ? metadata.tokens : designTokens;
|
|
828
857
|
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
829
858
|
const args = [];
|
|
830
859
|
for (const token of tokens) {
|
package/dist/koa/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('../bindings-CDGLuAq4.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-DPJfzvy5.cjs');
|
|
4
4
|
const require_responses = require('../responses-CBP3RYjJ.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/koa/router.ts
|
package/dist/koa/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as
|
|
1
|
+
import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-35iBbCaF.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 { C as
|
|
1
|
+
import { C as ControllerAction, E as Response, S as ApiResourceMiddleware, T as HttpMethod, m as Route, p as Request, t as CoreRouter, w as ControllerHandler } from "../router-91xVPlV0.mjs";
|
|
2
2
|
import Koa from "koa";
|
|
3
3
|
import Router$1 from "@koa/router";
|
|
4
4
|
|
package/dist/koa/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../bindings-B6x2HfzP.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-BkJMl4xv.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-DuZeRyGE.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/koa/router.ts
|
|
@@ -195,14 +195,25 @@ interface ClearRouterPluginRequestContext {
|
|
|
195
195
|
ctx: any;
|
|
196
196
|
request: Request$1;
|
|
197
197
|
response: Response$2;
|
|
198
|
+
getBindings: () => Record<string, BindValue>;
|
|
198
199
|
[key: string]: any;
|
|
199
200
|
}
|
|
201
|
+
interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
|
|
202
|
+
target?: object;
|
|
203
|
+
method?: PropertyKey;
|
|
204
|
+
handler?: object;
|
|
205
|
+
metadata?: object;
|
|
206
|
+
tokens: BindToken[];
|
|
207
|
+
designTokens: BindToken[];
|
|
208
|
+
}
|
|
200
209
|
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
201
210
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
202
211
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
212
|
+
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
203
213
|
interface ClearRouterPluginContext<Options = any> {
|
|
204
214
|
container: typeof Container;
|
|
205
215
|
bind: PluginBind;
|
|
216
|
+
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
206
217
|
bindings: Record<string, BindValue>;
|
|
207
218
|
configure: (options: RouterConfig) => void;
|
|
208
219
|
configureDefaults: (options: RouterConfig) => void;
|
|
@@ -243,6 +254,7 @@ declare abstract class CoreRouter {
|
|
|
243
254
|
private static readonly defaultConfigKey;
|
|
244
255
|
private static readonly pluginStoreKey;
|
|
245
256
|
private static readonly pluginPendingKey;
|
|
257
|
+
private static readonly pluginArgumentResolversKey;
|
|
246
258
|
protected static createBaseConfig(): RouterConfig;
|
|
247
259
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
248
260
|
protected static getDefaultConfig(): RouterConfig;
|
|
@@ -250,6 +262,7 @@ declare abstract class CoreRouter {
|
|
|
250
262
|
protected static getStateStore(): Record<string, any>;
|
|
251
263
|
protected static getPluginStore(): Set<string>;
|
|
252
264
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
265
|
+
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
253
266
|
protected static createDefaultState(): {
|
|
254
267
|
config: RouterConfig;
|
|
255
268
|
groupContext: AsyncLocalStorage<{
|
|
@@ -291,6 +304,7 @@ declare abstract class CoreRouter {
|
|
|
291
304
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
292
305
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
293
306
|
protected static createPluginBind(): PluginBind;
|
|
307
|
+
protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
294
308
|
protected static ensureState(this: any): void;
|
|
295
309
|
/**
|
|
296
310
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -446,4 +460,4 @@ declare abstract class CoreRouter {
|
|
|
446
460
|
}): void;
|
|
447
461
|
}
|
|
448
462
|
//#endregion
|
|
449
|
-
export {
|
|
463
|
+
export { ControllerAction as C, Response$2 as E, ApiResourceMiddleware as S, HttpMethod as T, HttpContext as _, ClearRouterPluginInput as a, HttpContext$1 as b, PluginBind as c, PluginSetupResult as d, definePlugin as f, Handler as g, H3App as h, ClearRouterPluginContext as i, PluginBindFactory as l, Route as m, ClearRouterPlugin as n, ClearRouterPluginRequestContext as o, Request$1 as p, ClearRouterPluginArgumentsContext as r, PluginArgumentsResolver as s, CoreRouter as t, PluginBindValue as u, Middleware as v, ControllerHandler as w, Middleware$1 as x, Handler$1 as y };
|
|
@@ -195,14 +195,25 @@ interface ClearRouterPluginRequestContext {
|
|
|
195
195
|
ctx: any;
|
|
196
196
|
request: Request$1;
|
|
197
197
|
response: Response$2;
|
|
198
|
+
getBindings: () => Record<string, BindValue>;
|
|
198
199
|
[key: string]: any;
|
|
199
200
|
}
|
|
201
|
+
interface ClearRouterPluginArgumentsContext extends ClearRouterPluginRequestContext {
|
|
202
|
+
target?: object;
|
|
203
|
+
method?: PropertyKey;
|
|
204
|
+
handler?: object;
|
|
205
|
+
metadata?: object;
|
|
206
|
+
tokens: BindToken[];
|
|
207
|
+
designTokens: BindToken[];
|
|
208
|
+
}
|
|
200
209
|
type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T | Promise<T>;
|
|
201
210
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
202
211
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
212
|
+
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
203
213
|
interface ClearRouterPluginContext<Options = any> {
|
|
204
214
|
container: typeof Container;
|
|
205
215
|
bind: PluginBind;
|
|
216
|
+
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
206
217
|
bindings: Record<string, BindValue>;
|
|
207
218
|
configure: (options: RouterConfig) => void;
|
|
208
219
|
configureDefaults: (options: RouterConfig) => void;
|
|
@@ -243,6 +254,7 @@ declare abstract class CoreRouter {
|
|
|
243
254
|
private static readonly defaultConfigKey;
|
|
244
255
|
private static readonly pluginStoreKey;
|
|
245
256
|
private static readonly pluginPendingKey;
|
|
257
|
+
private static readonly pluginArgumentResolversKey;
|
|
246
258
|
protected static createBaseConfig(): RouterConfig;
|
|
247
259
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
248
260
|
protected static getDefaultConfig(): RouterConfig;
|
|
@@ -250,6 +262,7 @@ declare abstract class CoreRouter {
|
|
|
250
262
|
protected static getStateStore(): Record<string, any>;
|
|
251
263
|
protected static getPluginStore(): Set<string>;
|
|
252
264
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
265
|
+
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
253
266
|
protected static createDefaultState(): {
|
|
254
267
|
config: RouterConfig;
|
|
255
268
|
groupContext: AsyncLocalStorage<{
|
|
@@ -291,6 +304,7 @@ declare abstract class CoreRouter {
|
|
|
291
304
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
292
305
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
293
306
|
protected static createPluginBind(): PluginBind;
|
|
307
|
+
protected static resolvePluginArguments(this: any, ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
294
308
|
protected static ensureState(this: any): void;
|
|
295
309
|
/**
|
|
296
310
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -446,4 +460,4 @@ declare abstract class CoreRouter {
|
|
|
446
460
|
}): void;
|
|
447
461
|
}
|
|
448
462
|
//#endregion
|
|
449
|
-
export {
|
|
463
|
+
export { ControllerAction as C, Response$2 as E, ApiResourceMiddleware as S, HttpMethod as T, HttpContext as _, ClearRouterPluginInput as a, HttpContext$1 as b, PluginBind as c, PluginSetupResult as d, definePlugin as f, Handler as g, H3App as h, ClearRouterPluginContext as i, PluginBindFactory as l, Route as m, ClearRouterPlugin as n, ClearRouterPluginRequestContext as o, Request$1 as p, ClearRouterPluginArgumentsContext as r, PluginArgumentsResolver as s, CoreRouter as t, PluginBindValue as u, Middleware as v, ControllerHandler as w, Middleware$1 as x, Handler$1 as y };
|
|
@@ -43,6 +43,7 @@ var CoreRouter = class {
|
|
|
43
43
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
44
44
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
45
45
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
46
|
+
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
46
47
|
static createBaseConfig() {
|
|
47
48
|
return {
|
|
48
49
|
methodOverride: {
|
|
@@ -94,6 +95,11 @@ var CoreRouter = class {
|
|
|
94
95
|
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
95
96
|
return g[this.pluginPendingKey];
|
|
96
97
|
}
|
|
98
|
+
static getPluginArgumentResolvers() {
|
|
99
|
+
const g = globalThis;
|
|
100
|
+
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
101
|
+
return g[this.pluginArgumentResolversKey];
|
|
102
|
+
}
|
|
97
103
|
static createDefaultState() {
|
|
98
104
|
return {
|
|
99
105
|
config: this.getDefaultConfig(),
|
|
@@ -208,6 +214,9 @@ var CoreRouter = class {
|
|
|
208
214
|
const ctx = {
|
|
209
215
|
container: Container,
|
|
210
216
|
bind: this.createPluginBind(),
|
|
217
|
+
resolveArguments: (resolver) => {
|
|
218
|
+
this.getPluginArgumentResolvers().add(resolver);
|
|
219
|
+
},
|
|
211
220
|
bindings: Container.bindings(),
|
|
212
221
|
configure: this.configure.bind(this),
|
|
213
222
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -260,8 +269,7 @@ var CoreRouter = class {
|
|
|
260
269
|
ctx,
|
|
261
270
|
request,
|
|
262
271
|
response,
|
|
263
|
-
|
|
264
|
-
clearResponse: response
|
|
272
|
+
getBindings: () => Container.bindings()
|
|
265
273
|
};
|
|
266
274
|
}
|
|
267
275
|
static createPluginBind() {
|
|
@@ -275,6 +283,18 @@ var CoreRouter = class {
|
|
|
275
283
|
};
|
|
276
284
|
return bind;
|
|
277
285
|
}
|
|
286
|
+
static async resolvePluginArguments(ctx, routeContext) {
|
|
287
|
+
const resolvers = Array.from(this.getPluginArgumentResolvers());
|
|
288
|
+
if (!resolvers.length) return void 0;
|
|
289
|
+
const pluginContext = {
|
|
290
|
+
...this.createPluginRequestContext(ctx),
|
|
291
|
+
...routeContext
|
|
292
|
+
};
|
|
293
|
+
for (const resolver of resolvers) {
|
|
294
|
+
const args = await resolver(pluginContext);
|
|
295
|
+
if (Array.isArray(args)) return args;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
278
298
|
static ensureState() {
|
|
279
299
|
this.bindStateAccessors();
|
|
280
300
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -592,6 +612,7 @@ var CoreRouter = class {
|
|
|
592
612
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
593
613
|
await this.pluginsReady();
|
|
594
614
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
615
|
+
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
595
616
|
const metadata = getBindingMetadataFromTargets([
|
|
596
617
|
{
|
|
597
618
|
target: bindingTarget,
|
|
@@ -603,9 +624,17 @@ var CoreRouter = class {
|
|
|
603
624
|
propertyKey: "__class__"
|
|
604
625
|
}
|
|
605
626
|
]) ?? getStandardMetadata(bindingMetadata, bindingMethod) ?? getStandardMetadata(bindingMetadata, "__class__");
|
|
627
|
+
const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
|
|
628
|
+
const pluginArgs = await this.resolvePluginArguments(ctx, {
|
|
629
|
+
target: bindingTarget,
|
|
630
|
+
method: bindingMethod,
|
|
631
|
+
handler: bindingHandler,
|
|
632
|
+
metadata: bindingMetadata,
|
|
633
|
+
tokens,
|
|
634
|
+
designTokens
|
|
635
|
+
});
|
|
636
|
+
if (pluginArgs) return handlerFunction(...pluginArgs);
|
|
606
637
|
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
638
|
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
610
639
|
const args = [];
|
|
611
640
|
for (const token of tokens) {
|
|
@@ -43,6 +43,7 @@ var CoreRouter = class {
|
|
|
43
43
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
44
44
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
45
45
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
46
|
+
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
46
47
|
static createBaseConfig() {
|
|
47
48
|
return {
|
|
48
49
|
methodOverride: {
|
|
@@ -94,6 +95,11 @@ var CoreRouter = class {
|
|
|
94
95
|
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
95
96
|
return g[this.pluginPendingKey];
|
|
96
97
|
}
|
|
98
|
+
static getPluginArgumentResolvers() {
|
|
99
|
+
const g = globalThis;
|
|
100
|
+
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
101
|
+
return g[this.pluginArgumentResolversKey];
|
|
102
|
+
}
|
|
97
103
|
static createDefaultState() {
|
|
98
104
|
return {
|
|
99
105
|
config: this.getDefaultConfig(),
|
|
@@ -208,6 +214,9 @@ var CoreRouter = class {
|
|
|
208
214
|
const ctx = {
|
|
209
215
|
container: require_bindings.Container,
|
|
210
216
|
bind: this.createPluginBind(),
|
|
217
|
+
resolveArguments: (resolver) => {
|
|
218
|
+
this.getPluginArgumentResolvers().add(resolver);
|
|
219
|
+
},
|
|
211
220
|
bindings: require_bindings.Container.bindings(),
|
|
212
221
|
configure: this.configure.bind(this),
|
|
213
222
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -260,8 +269,7 @@ var CoreRouter = class {
|
|
|
260
269
|
ctx,
|
|
261
270
|
request,
|
|
262
271
|
response,
|
|
263
|
-
|
|
264
|
-
clearResponse: response
|
|
272
|
+
getBindings: () => require_bindings.Container.bindings()
|
|
265
273
|
};
|
|
266
274
|
}
|
|
267
275
|
static createPluginBind() {
|
|
@@ -275,6 +283,18 @@ var CoreRouter = class {
|
|
|
275
283
|
};
|
|
276
284
|
return bind;
|
|
277
285
|
}
|
|
286
|
+
static async resolvePluginArguments(ctx, routeContext) {
|
|
287
|
+
const resolvers = Array.from(this.getPluginArgumentResolvers());
|
|
288
|
+
if (!resolvers.length) return void 0;
|
|
289
|
+
const pluginContext = {
|
|
290
|
+
...this.createPluginRequestContext(ctx),
|
|
291
|
+
...routeContext
|
|
292
|
+
};
|
|
293
|
+
for (const resolver of resolvers) {
|
|
294
|
+
const args = await resolver(pluginContext);
|
|
295
|
+
if (Array.isArray(args)) return args;
|
|
296
|
+
}
|
|
297
|
+
}
|
|
278
298
|
static ensureState() {
|
|
279
299
|
this.bindStateAccessors();
|
|
280
300
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -592,6 +612,7 @@ var CoreRouter = class {
|
|
|
592
612
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
593
613
|
await this.pluginsReady();
|
|
594
614
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
615
|
+
const designTokens = [...bindingTarget ? require_bindings.getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? require_bindings.getDesignParamTypes(bindingHandler) : []];
|
|
595
616
|
const metadata = require_bindings.getBindingMetadataFromTargets([
|
|
596
617
|
{
|
|
597
618
|
target: bindingTarget,
|
|
@@ -603,9 +624,17 @@ var CoreRouter = class {
|
|
|
603
624
|
propertyKey: "__class__"
|
|
604
625
|
}
|
|
605
626
|
]) ?? require_bindings.getStandardMetadata(bindingMetadata, bindingMethod) ?? require_bindings.getStandardMetadata(bindingMetadata, "__class__");
|
|
627
|
+
const tokens = metadata?.tokens?.length ? metadata.tokens : designTokens;
|
|
628
|
+
const pluginArgs = await this.resolvePluginArguments(ctx, {
|
|
629
|
+
target: bindingTarget,
|
|
630
|
+
method: bindingMethod,
|
|
631
|
+
handler: bindingHandler,
|
|
632
|
+
metadata: bindingMetadata,
|
|
633
|
+
tokens,
|
|
634
|
+
designTokens
|
|
635
|
+
});
|
|
636
|
+
if (pluginArgs) return handlerFunction(...pluginArgs);
|
|
606
637
|
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
638
|
if (!tokens.length) return handlerFunction(ctx, ctx.clearRequest);
|
|
610
639
|
const args = [];
|
|
611
640
|
for (const token of tokens) {
|
package/package.json
CHANGED