clear-router 2.6.7 → 2.7.0
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 +7 -1
- package/dist/core/index.d.cts +1 -1
- package/dist/core/index.d.mts +1 -1
- package/dist/core/index.mjs +7 -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 +27 -0
- package/dist/index.d.cts +76 -6
- package/dist/index.d.mts +76 -6
- package/dist/index.mjs +27 -0
- 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-BOKe0n0j.d.mts → router-1hB-k4No.d.mts} +76 -6
- package/dist/{router-CcG0NS8L.cjs → router-C6W-k6sS.cjs} +21 -0
- package/dist/{router-BHC0lGtp.d.cts → router-Cl6q9Od3.d.cts} +76 -6
- package/dist/{router-kOleKr2w.mjs → router-Dc9w86Wn.mjs} +21 -0
- package/package.json +1 -1
package/dist/core/index.cjs
CHANGED
|
@@ -1,8 +1,14 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_bindings = require('../bindings-CLsZjOEy.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-C6W-k6sS.cjs');
|
|
4
4
|
|
|
5
5
|
//#region src/core/plugins.ts
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new plugin
|
|
8
|
+
*
|
|
9
|
+
* @param plugin
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
6
12
|
function definePlugin(plugin) {
|
|
7
13
|
return plugin;
|
|
8
14
|
}
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { L 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-
|
|
1
|
+
import { L 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-Cl6q9Od3.cjs";
|
|
2
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 { L 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-
|
|
1
|
+
import { L 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-1hB-k4No.mjs";
|
|
2
2
|
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,7 +1,13 @@
|
|
|
1
1
|
import { c as Request, s as Response } from "../bindings-XLDXFpHZ.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-Dc9w86Wn.mjs";
|
|
3
3
|
|
|
4
4
|
//#region src/core/plugins.ts
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new plugin
|
|
7
|
+
*
|
|
8
|
+
* @param plugin
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
5
11
|
function definePlugin(plugin) {
|
|
6
12
|
return plugin;
|
|
7
13
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
const require_bindings = require('../bindings-CLsZjOEy.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-C6W-k6sS.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-CLsZjOEy.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-C6W-k6sS.cjs');
|
|
4
4
|
const require_responses = require('../responses-Bvnk0uvc.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/express/router.ts
|
package/dist/express/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as ControllerAction, I as HttpMethod, M as HttpContext, N as Middleware, P as ApiResourceMiddleware, j as Handler, m as Route, t as CoreRouter } from "../router-
|
|
1
|
+
import { F as ControllerAction, I as HttpMethod, M as HttpContext, N as Middleware, P as ApiResourceMiddleware, j as Handler, m as Route, t as CoreRouter } from "../router-Cl6q9Od3.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 { F as ControllerAction, I as HttpMethod, M as HttpContext, N as Middleware, P as ApiResourceMiddleware, j as Handler, m as Route, t as CoreRouter } from "../router-
|
|
1
|
+
import { F as ControllerAction, I as HttpMethod, M as HttpContext, N as Middleware, P as ApiResourceMiddleware, j as Handler, m as Route, t as CoreRouter } from "../router-1hB-k4No.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-XLDXFpHZ.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-Dc9w86Wn.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BvETUeDL.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-CLsZjOEy.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-C6W-k6sS.cjs');
|
|
4
4
|
const require_responses = require('../responses-Bvnk0uvc.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/fastify/router.ts
|
package/dist/fastify/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Middleware, D as FastifyApp, F as ControllerAction, I as HttpMethod, O as Handler, P as ApiResourceMiddleware, k as HttpContext, m as Route, t as CoreRouter } from "../router-
|
|
1
|
+
import { A as Middleware, D as FastifyApp, F as ControllerAction, I as HttpMethod, O as Handler, P as ApiResourceMiddleware, k as HttpContext, m as Route, t as CoreRouter } from "../router-Cl6q9Od3.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/fastify/router.d.ts
|
|
4
4
|
/**
|
package/dist/fastify/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { A as Middleware, D as FastifyApp, F as ControllerAction, I as HttpMethod, O as Handler, P as ApiResourceMiddleware, k as HttpContext, m as Route, t as CoreRouter } from "../router-
|
|
1
|
+
import { A as Middleware, D as FastifyApp, F as ControllerAction, I as HttpMethod, O as Handler, P as ApiResourceMiddleware, k as HttpContext, m as Route, t as CoreRouter } from "../router-1hB-k4No.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/fastify/router.d.ts
|
|
4
4
|
/**
|
package/dist/fastify/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../bindings-XLDXFpHZ.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-Dc9w86Wn.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-BvETUeDL.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-CLsZjOEy.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-C6W-k6sS.cjs');
|
|
4
4
|
const require_responses = require('../responses-Bvnk0uvc.cjs');
|
|
5
5
|
let h3 = require("h3");
|
|
6
6
|
|
package/dist/h3/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { C as H3App, E as Middleware, F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, T as HttpContext, m as Route, t as CoreRouter, w as Handler } from "../router-
|
|
1
|
+
import { C as H3App, E as Middleware, F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, T as HttpContext, m as Route, t as CoreRouter, w as Handler } from "../router-Cl6q9Od3.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 H3App, E as Middleware, F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, T as HttpContext, m as Route, t as CoreRouter, w as Handler } from "../router-
|
|
1
|
+
import { C as H3App, E as Middleware, F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, T as HttpContext, m as Route, t as CoreRouter, w as Handler } from "../router-1hB-k4No.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-XLDXFpHZ.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-Dc9w86Wn.mjs";
|
|
3
3
|
import { n as resolveResponseMeta } from "../responses-BvETUeDL.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-CLsZjOEy.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-C6W-k6sS.cjs');
|
|
4
4
|
const require_responses = require('../responses-Bvnk0uvc.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/hono/router.ts
|
package/dist/hono/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, S as Middleware, b as HonoApp, m as Route, t as CoreRouter, x as HttpContext, y as Handler } from "../router-
|
|
1
|
+
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, S as Middleware, b as HonoApp, m as Route, t as CoreRouter, x as HttpContext, y as Handler } from "../router-Cl6q9Od3.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/hono/router.d.ts
|
|
4
4
|
/**
|
package/dist/hono/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, S as Middleware, b as HonoApp, m as Route, t as CoreRouter, x as HttpContext, y as Handler } from "../router-
|
|
1
|
+
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, S as Middleware, b as HonoApp, m as Route, t as CoreRouter, x as HttpContext, y as Handler } from "../router-1hB-k4No.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/hono/router.d.ts
|
|
4
4
|
/**
|
package/dist/hono/index.mjs
CHANGED
package/dist/index.cjs
CHANGED
|
@@ -179,6 +179,12 @@ var Response = class {
|
|
|
179
179
|
|
|
180
180
|
//#endregion
|
|
181
181
|
//#region src/core/plugins.ts
|
|
182
|
+
/**
|
|
183
|
+
* Creates a new plugin
|
|
184
|
+
*
|
|
185
|
+
* @param plugin
|
|
186
|
+
* @returns
|
|
187
|
+
*/
|
|
182
188
|
function definePlugin(plugin) {
|
|
183
189
|
return plugin;
|
|
184
190
|
}
|
|
@@ -299,6 +305,7 @@ var CoreRouter = class {
|
|
|
299
305
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
300
306
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
301
307
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
308
|
+
static pluginHttpCtxResolversKey = Symbol.for("clear-router:plugin-http-ctx");
|
|
302
309
|
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
303
310
|
static requestProvider;
|
|
304
311
|
static responseProvider;
|
|
@@ -394,6 +401,11 @@ var CoreRouter = class {
|
|
|
394
401
|
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
395
402
|
return g[this.pluginArgumentResolversKey];
|
|
396
403
|
}
|
|
404
|
+
static getPluginHttpCtxResolvers() {
|
|
405
|
+
const g = globalThis;
|
|
406
|
+
if (!g[this.pluginHttpCtxResolversKey]) g[this.pluginHttpCtxResolversKey] = /* @__PURE__ */ new Set();
|
|
407
|
+
return g[this.pluginHttpCtxResolversKey];
|
|
408
|
+
}
|
|
397
409
|
static createDefaultState() {
|
|
398
410
|
return {
|
|
399
411
|
config: this.getDefaultConfig(),
|
|
@@ -475,6 +487,11 @@ var CoreRouter = class {
|
|
|
475
487
|
}
|
|
476
488
|
};
|
|
477
489
|
}
|
|
490
|
+
/**
|
|
491
|
+
* Default configuration used for everytime the router is reset
|
|
492
|
+
*
|
|
493
|
+
* @param options
|
|
494
|
+
*/
|
|
478
495
|
static configureDefaults(options) {
|
|
479
496
|
const g = globalThis;
|
|
480
497
|
const defaults = this.mergeConfig(g[this.defaultConfigKey] || this.createBaseConfig(), options);
|
|
@@ -502,6 +519,9 @@ var CoreRouter = class {
|
|
|
502
519
|
resolveArguments: (resolver) => {
|
|
503
520
|
this.getPluginArgumentResolvers().add(resolver);
|
|
504
521
|
},
|
|
522
|
+
useHttpContext: (resolver) => {
|
|
523
|
+
this.getPluginHttpCtxResolvers().add(resolver);
|
|
524
|
+
},
|
|
505
525
|
bindings: Container.bindings(),
|
|
506
526
|
configure: this.configure.bind(this),
|
|
507
527
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -572,6 +592,12 @@ var CoreRouter = class {
|
|
|
572
592
|
if (Array.isArray(args)) return args;
|
|
573
593
|
}
|
|
574
594
|
}
|
|
595
|
+
static async resolvePluginHttpCtx(ctx) {
|
|
596
|
+
const resolvers = Array.from(this.getPluginHttpCtxResolvers());
|
|
597
|
+
if (!resolvers.length) return void 0;
|
|
598
|
+
const pluginContext = this.createPluginRequestContext(ctx);
|
|
599
|
+
for (const resolver of resolvers) await resolver(pluginContext);
|
|
600
|
+
}
|
|
575
601
|
static ensureState() {
|
|
576
602
|
this.bindStateAccessors();
|
|
577
603
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -995,6 +1021,7 @@ var CoreRouter = class {
|
|
|
995
1021
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
996
1022
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
997
1023
|
await this.pluginsReady();
|
|
1024
|
+
await this.resolvePluginHttpCtx(ctx);
|
|
998
1025
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
999
1026
|
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
1000
1027
|
const metadata = getBindingMetadataFromTargets([
|
package/dist/index.d.cts
CHANGED
|
@@ -207,25 +207,87 @@ type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T |
|
|
|
207
207
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
208
208
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
209
209
|
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
210
|
-
interface ClearRouterPluginContext<Options = any> {
|
|
210
|
+
interface ClearRouterPluginContext<Options = any, _HttpContext = any> {
|
|
211
|
+
/**
|
|
212
|
+
* The service container
|
|
213
|
+
*/
|
|
211
214
|
container: typeof Container;
|
|
215
|
+
/**
|
|
216
|
+
* Register service container bindings
|
|
217
|
+
*/
|
|
212
218
|
bind: PluginBind;
|
|
219
|
+
/**
|
|
220
|
+
* Replace all controller method arguments
|
|
221
|
+
* @param resolver
|
|
222
|
+
* @returns
|
|
223
|
+
*/
|
|
213
224
|
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
225
|
+
/**
|
|
226
|
+
* Use the current http context
|
|
227
|
+
*/
|
|
228
|
+
useHttpContext: (resolver: PluginArgumentsResolver) => void;
|
|
229
|
+
/**
|
|
230
|
+
* All registered service container bindings
|
|
231
|
+
*/
|
|
214
232
|
bindings: Record<string, BindValue>;
|
|
233
|
+
/**
|
|
234
|
+
* Configures the router with the given options, such as method override settings
|
|
235
|
+
*
|
|
236
|
+
* @param options
|
|
237
|
+
* @returns
|
|
238
|
+
*/
|
|
215
239
|
configure: (options: RouterConfig) => void;
|
|
240
|
+
/**
|
|
241
|
+
* Default configuration used for everytime the router is reset
|
|
242
|
+
*
|
|
243
|
+
* @param options
|
|
244
|
+
*/
|
|
216
245
|
configureDefaults: (options: RouterConfig) => void;
|
|
246
|
+
/**
|
|
247
|
+
* The current Request instance
|
|
248
|
+
*/
|
|
217
249
|
readonly request?: Request;
|
|
250
|
+
/**
|
|
251
|
+
* The current Response instance
|
|
252
|
+
* @returns
|
|
253
|
+
*/
|
|
218
254
|
readonly response?: Response$1;
|
|
255
|
+
/**
|
|
256
|
+
* Get the current Request instance
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
219
259
|
getRequest: () => Request | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Get the current Response instance
|
|
262
|
+
* @returns
|
|
263
|
+
*/
|
|
220
264
|
getResponse: () => Response$1 | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Plugin configuration options
|
|
267
|
+
*/
|
|
221
268
|
options: Options;
|
|
222
269
|
}
|
|
223
|
-
interface ClearRouterPlugin<Options = any> {
|
|
270
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
271
|
+
/**
|
|
272
|
+
* The name of the plugin
|
|
273
|
+
*/
|
|
224
274
|
name?: string;
|
|
225
|
-
|
|
275
|
+
/**
|
|
276
|
+
* Plugin setup an implemnetation
|
|
277
|
+
*
|
|
278
|
+
* @param ctx
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
226
282
|
}
|
|
227
|
-
type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
|
|
228
|
-
|
|
283
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
284
|
+
/**
|
|
285
|
+
* Creates a new plugin
|
|
286
|
+
*
|
|
287
|
+
* @param plugin
|
|
288
|
+
* @returns
|
|
289
|
+
*/
|
|
290
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
229
291
|
//#endregion
|
|
230
292
|
//#region src/core/router.d.ts
|
|
231
293
|
/**
|
|
@@ -241,6 +303,7 @@ declare abstract class CoreRouter {
|
|
|
241
303
|
private static readonly defaultConfigKey;
|
|
242
304
|
private static readonly pluginStoreKey;
|
|
243
305
|
private static readonly pluginPendingKey;
|
|
306
|
+
private static readonly pluginHttpCtxResolversKey;
|
|
244
307
|
private static readonly pluginArgumentResolversKey;
|
|
245
308
|
private static requestProvider?;
|
|
246
309
|
private static responseProvider?;
|
|
@@ -269,6 +332,7 @@ declare abstract class CoreRouter {
|
|
|
269
332
|
protected static getPluginStore(): Set<string>;
|
|
270
333
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
271
334
|
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
335
|
+
protected static getPluginHttpCtxResolvers(): Set<PluginArgumentsResolver>;
|
|
272
336
|
protected static createDefaultState(): {
|
|
273
337
|
config: RouterConfig;
|
|
274
338
|
groupContext: AsyncLocalStorage<{
|
|
@@ -285,6 +349,11 @@ declare abstract class CoreRouter {
|
|
|
285
349
|
};
|
|
286
350
|
protected static bindStateAccessors(): void;
|
|
287
351
|
protected static createDefaultOptionsHandler(): any;
|
|
352
|
+
/**
|
|
353
|
+
* Default configuration used for everytime the router is reset
|
|
354
|
+
*
|
|
355
|
+
* @param options
|
|
356
|
+
*/
|
|
288
357
|
static configureDefaults(options?: RouterConfig): void;
|
|
289
358
|
/**
|
|
290
359
|
* Use a registered plugin
|
|
@@ -299,7 +368,8 @@ declare abstract class CoreRouter {
|
|
|
299
368
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
300
369
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
301
370
|
protected static createPluginBind(): PluginBind;
|
|
302
|
-
protected static resolvePluginArguments(
|
|
371
|
+
protected static resolvePluginArguments(ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
372
|
+
protected static resolvePluginHttpCtx(ctx: any): Promise<void>;
|
|
303
373
|
protected static ensureState(): void;
|
|
304
374
|
/**
|
|
305
375
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
package/dist/index.d.mts
CHANGED
|
@@ -207,25 +207,87 @@ type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T |
|
|
|
207
207
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
208
208
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
209
209
|
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
210
|
-
interface ClearRouterPluginContext<Options = any> {
|
|
210
|
+
interface ClearRouterPluginContext<Options = any, _HttpContext = any> {
|
|
211
|
+
/**
|
|
212
|
+
* The service container
|
|
213
|
+
*/
|
|
211
214
|
container: typeof Container;
|
|
215
|
+
/**
|
|
216
|
+
* Register service container bindings
|
|
217
|
+
*/
|
|
212
218
|
bind: PluginBind;
|
|
219
|
+
/**
|
|
220
|
+
* Replace all controller method arguments
|
|
221
|
+
* @param resolver
|
|
222
|
+
* @returns
|
|
223
|
+
*/
|
|
213
224
|
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
225
|
+
/**
|
|
226
|
+
* Use the current http context
|
|
227
|
+
*/
|
|
228
|
+
useHttpContext: (resolver: PluginArgumentsResolver) => void;
|
|
229
|
+
/**
|
|
230
|
+
* All registered service container bindings
|
|
231
|
+
*/
|
|
214
232
|
bindings: Record<string, BindValue>;
|
|
233
|
+
/**
|
|
234
|
+
* Configures the router with the given options, such as method override settings
|
|
235
|
+
*
|
|
236
|
+
* @param options
|
|
237
|
+
* @returns
|
|
238
|
+
*/
|
|
215
239
|
configure: (options: RouterConfig) => void;
|
|
240
|
+
/**
|
|
241
|
+
* Default configuration used for everytime the router is reset
|
|
242
|
+
*
|
|
243
|
+
* @param options
|
|
244
|
+
*/
|
|
216
245
|
configureDefaults: (options: RouterConfig) => void;
|
|
246
|
+
/**
|
|
247
|
+
* The current Request instance
|
|
248
|
+
*/
|
|
217
249
|
readonly request?: Request;
|
|
250
|
+
/**
|
|
251
|
+
* The current Response instance
|
|
252
|
+
* @returns
|
|
253
|
+
*/
|
|
218
254
|
readonly response?: Response$1;
|
|
255
|
+
/**
|
|
256
|
+
* Get the current Request instance
|
|
257
|
+
* @returns
|
|
258
|
+
*/
|
|
219
259
|
getRequest: () => Request | undefined;
|
|
260
|
+
/**
|
|
261
|
+
* Get the current Response instance
|
|
262
|
+
* @returns
|
|
263
|
+
*/
|
|
220
264
|
getResponse: () => Response$1 | undefined;
|
|
265
|
+
/**
|
|
266
|
+
* Plugin configuration options
|
|
267
|
+
*/
|
|
221
268
|
options: Options;
|
|
222
269
|
}
|
|
223
|
-
interface ClearRouterPlugin<Options = any> {
|
|
270
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
271
|
+
/**
|
|
272
|
+
* The name of the plugin
|
|
273
|
+
*/
|
|
224
274
|
name?: string;
|
|
225
|
-
|
|
275
|
+
/**
|
|
276
|
+
* Plugin setup an implemnetation
|
|
277
|
+
*
|
|
278
|
+
* @param ctx
|
|
279
|
+
* @returns
|
|
280
|
+
*/
|
|
281
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
226
282
|
}
|
|
227
|
-
type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
|
|
228
|
-
|
|
283
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
284
|
+
/**
|
|
285
|
+
* Creates a new plugin
|
|
286
|
+
*
|
|
287
|
+
* @param plugin
|
|
288
|
+
* @returns
|
|
289
|
+
*/
|
|
290
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
229
291
|
//#endregion
|
|
230
292
|
//#region src/core/router.d.ts
|
|
231
293
|
/**
|
|
@@ -241,6 +303,7 @@ declare abstract class CoreRouter {
|
|
|
241
303
|
private static readonly defaultConfigKey;
|
|
242
304
|
private static readonly pluginStoreKey;
|
|
243
305
|
private static readonly pluginPendingKey;
|
|
306
|
+
private static readonly pluginHttpCtxResolversKey;
|
|
244
307
|
private static readonly pluginArgumentResolversKey;
|
|
245
308
|
private static requestProvider?;
|
|
246
309
|
private static responseProvider?;
|
|
@@ -269,6 +332,7 @@ declare abstract class CoreRouter {
|
|
|
269
332
|
protected static getPluginStore(): Set<string>;
|
|
270
333
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
271
334
|
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
335
|
+
protected static getPluginHttpCtxResolvers(): Set<PluginArgumentsResolver>;
|
|
272
336
|
protected static createDefaultState(): {
|
|
273
337
|
config: RouterConfig;
|
|
274
338
|
groupContext: AsyncLocalStorage<{
|
|
@@ -285,6 +349,11 @@ declare abstract class CoreRouter {
|
|
|
285
349
|
};
|
|
286
350
|
protected static bindStateAccessors(): void;
|
|
287
351
|
protected static createDefaultOptionsHandler(): any;
|
|
352
|
+
/**
|
|
353
|
+
* Default configuration used for everytime the router is reset
|
|
354
|
+
*
|
|
355
|
+
* @param options
|
|
356
|
+
*/
|
|
288
357
|
static configureDefaults(options?: RouterConfig): void;
|
|
289
358
|
/**
|
|
290
359
|
* Use a registered plugin
|
|
@@ -299,7 +368,8 @@ declare abstract class CoreRouter {
|
|
|
299
368
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
300
369
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
301
370
|
protected static createPluginBind(): PluginBind;
|
|
302
|
-
protected static resolvePluginArguments(
|
|
371
|
+
protected static resolvePluginArguments(ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
372
|
+
protected static resolvePluginHttpCtx(ctx: any): Promise<void>;
|
|
303
373
|
protected static ensureState(): void;
|
|
304
374
|
/**
|
|
305
375
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
package/dist/index.mjs
CHANGED
|
@@ -178,6 +178,12 @@ var Response = class {
|
|
|
178
178
|
|
|
179
179
|
//#endregion
|
|
180
180
|
//#region src/core/plugins.ts
|
|
181
|
+
/**
|
|
182
|
+
* Creates a new plugin
|
|
183
|
+
*
|
|
184
|
+
* @param plugin
|
|
185
|
+
* @returns
|
|
186
|
+
*/
|
|
181
187
|
function definePlugin(plugin) {
|
|
182
188
|
return plugin;
|
|
183
189
|
}
|
|
@@ -298,6 +304,7 @@ var CoreRouter = class {
|
|
|
298
304
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
299
305
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
300
306
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
307
|
+
static pluginHttpCtxResolversKey = Symbol.for("clear-router:plugin-http-ctx");
|
|
301
308
|
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
302
309
|
static requestProvider;
|
|
303
310
|
static responseProvider;
|
|
@@ -393,6 +400,11 @@ var CoreRouter = class {
|
|
|
393
400
|
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
394
401
|
return g[this.pluginArgumentResolversKey];
|
|
395
402
|
}
|
|
403
|
+
static getPluginHttpCtxResolvers() {
|
|
404
|
+
const g = globalThis;
|
|
405
|
+
if (!g[this.pluginHttpCtxResolversKey]) g[this.pluginHttpCtxResolversKey] = /* @__PURE__ */ new Set();
|
|
406
|
+
return g[this.pluginHttpCtxResolversKey];
|
|
407
|
+
}
|
|
396
408
|
static createDefaultState() {
|
|
397
409
|
return {
|
|
398
410
|
config: this.getDefaultConfig(),
|
|
@@ -474,6 +486,11 @@ var CoreRouter = class {
|
|
|
474
486
|
}
|
|
475
487
|
};
|
|
476
488
|
}
|
|
489
|
+
/**
|
|
490
|
+
* Default configuration used for everytime the router is reset
|
|
491
|
+
*
|
|
492
|
+
* @param options
|
|
493
|
+
*/
|
|
477
494
|
static configureDefaults(options) {
|
|
478
495
|
const g = globalThis;
|
|
479
496
|
const defaults = this.mergeConfig(g[this.defaultConfigKey] || this.createBaseConfig(), options);
|
|
@@ -501,6 +518,9 @@ var CoreRouter = class {
|
|
|
501
518
|
resolveArguments: (resolver) => {
|
|
502
519
|
this.getPluginArgumentResolvers().add(resolver);
|
|
503
520
|
},
|
|
521
|
+
useHttpContext: (resolver) => {
|
|
522
|
+
this.getPluginHttpCtxResolvers().add(resolver);
|
|
523
|
+
},
|
|
504
524
|
bindings: Container.bindings(),
|
|
505
525
|
configure: this.configure.bind(this),
|
|
506
526
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -571,6 +591,12 @@ var CoreRouter = class {
|
|
|
571
591
|
if (Array.isArray(args)) return args;
|
|
572
592
|
}
|
|
573
593
|
}
|
|
594
|
+
static async resolvePluginHttpCtx(ctx) {
|
|
595
|
+
const resolvers = Array.from(this.getPluginHttpCtxResolvers());
|
|
596
|
+
if (!resolvers.length) return void 0;
|
|
597
|
+
const pluginContext = this.createPluginRequestContext(ctx);
|
|
598
|
+
for (const resolver of resolvers) await resolver(pluginContext);
|
|
599
|
+
}
|
|
574
600
|
static ensureState() {
|
|
575
601
|
this.bindStateAccessors();
|
|
576
602
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -994,6 +1020,7 @@ var CoreRouter = class {
|
|
|
994
1020
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
995
1021
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
996
1022
|
await this.pluginsReady();
|
|
1023
|
+
await this.resolvePluginHttpCtx(ctx);
|
|
997
1024
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
998
1025
|
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
999
1026
|
const metadata = getBindingMetadataFromTargets([
|
package/dist/koa/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('../bindings-CLsZjOEy.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-C6W-k6sS.cjs');
|
|
4
4
|
const require_responses = require('../responses-Bvnk0uvc.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/koa/router.ts
|
package/dist/koa/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, _ as KoaRouterApp, g as HttpContext, h as Handler, m as Route, t as CoreRouter, v as Middleware } from "../router-
|
|
1
|
+
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, _ as KoaRouterApp, g as HttpContext, h as Handler, m as Route, t as CoreRouter, v as Middleware } from "../router-Cl6q9Od3.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/koa/router.d.ts
|
|
4
4
|
/**
|
package/dist/koa/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, _ as KoaRouterApp, g as HttpContext, h as Handler, m as Route, t as CoreRouter, v as Middleware } from "../router-
|
|
1
|
+
import { F as ControllerAction, I as HttpMethod, P as ApiResourceMiddleware, _ as KoaRouterApp, g as HttpContext, h as Handler, m as Route, t as CoreRouter, v as Middleware } from "../router-1hB-k4No.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/koa/router.d.ts
|
|
4
4
|
/**
|
package/dist/koa/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import "../bindings-XLDXFpHZ.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-Dc9w86Wn.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-BvETUeDL.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/koa/router.ts
|
|
@@ -284,25 +284,87 @@ type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T |
|
|
|
284
284
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
285
285
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
286
286
|
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
287
|
-
interface ClearRouterPluginContext<Options = any> {
|
|
287
|
+
interface ClearRouterPluginContext<Options = any, _HttpContext = any> {
|
|
288
|
+
/**
|
|
289
|
+
* The service container
|
|
290
|
+
*/
|
|
288
291
|
container: typeof Container;
|
|
292
|
+
/**
|
|
293
|
+
* Register service container bindings
|
|
294
|
+
*/
|
|
289
295
|
bind: PluginBind;
|
|
296
|
+
/**
|
|
297
|
+
* Replace all controller method arguments
|
|
298
|
+
* @param resolver
|
|
299
|
+
* @returns
|
|
300
|
+
*/
|
|
290
301
|
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
302
|
+
/**
|
|
303
|
+
* Use the current http context
|
|
304
|
+
*/
|
|
305
|
+
useHttpContext: (resolver: PluginArgumentsResolver) => void;
|
|
306
|
+
/**
|
|
307
|
+
* All registered service container bindings
|
|
308
|
+
*/
|
|
291
309
|
bindings: Record<string, BindValue>;
|
|
310
|
+
/**
|
|
311
|
+
* Configures the router with the given options, such as method override settings
|
|
312
|
+
*
|
|
313
|
+
* @param options
|
|
314
|
+
* @returns
|
|
315
|
+
*/
|
|
292
316
|
configure: (options: RouterConfig) => void;
|
|
317
|
+
/**
|
|
318
|
+
* Default configuration used for everytime the router is reset
|
|
319
|
+
*
|
|
320
|
+
* @param options
|
|
321
|
+
*/
|
|
293
322
|
configureDefaults: (options: RouterConfig) => void;
|
|
323
|
+
/**
|
|
324
|
+
* The current Request instance
|
|
325
|
+
*/
|
|
294
326
|
readonly request?: Request$1;
|
|
327
|
+
/**
|
|
328
|
+
* The current Response instance
|
|
329
|
+
* @returns
|
|
330
|
+
*/
|
|
295
331
|
readonly response?: Response$2;
|
|
332
|
+
/**
|
|
333
|
+
* Get the current Request instance
|
|
334
|
+
* @returns
|
|
335
|
+
*/
|
|
296
336
|
getRequest: () => Request$1 | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* Get the current Response instance
|
|
339
|
+
* @returns
|
|
340
|
+
*/
|
|
297
341
|
getResponse: () => Response$2 | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Plugin configuration options
|
|
344
|
+
*/
|
|
298
345
|
options: Options;
|
|
299
346
|
}
|
|
300
|
-
interface ClearRouterPlugin<Options = any> {
|
|
347
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
348
|
+
/**
|
|
349
|
+
* The name of the plugin
|
|
350
|
+
*/
|
|
301
351
|
name?: string;
|
|
302
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Plugin setup an implemnetation
|
|
354
|
+
*
|
|
355
|
+
* @param ctx
|
|
356
|
+
* @returns
|
|
357
|
+
*/
|
|
358
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
303
359
|
}
|
|
304
|
-
type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
|
|
305
|
-
|
|
360
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
361
|
+
/**
|
|
362
|
+
* Creates a new plugin
|
|
363
|
+
*
|
|
364
|
+
* @param plugin
|
|
365
|
+
* @returns
|
|
366
|
+
*/
|
|
367
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
306
368
|
//#endregion
|
|
307
369
|
//#region src/Controller.d.ts
|
|
308
370
|
declare abstract class Controller<X = any> {
|
|
@@ -328,6 +390,7 @@ declare abstract class CoreRouter {
|
|
|
328
390
|
private static readonly defaultConfigKey;
|
|
329
391
|
private static readonly pluginStoreKey;
|
|
330
392
|
private static readonly pluginPendingKey;
|
|
393
|
+
private static readonly pluginHttpCtxResolversKey;
|
|
331
394
|
private static readonly pluginArgumentResolversKey;
|
|
332
395
|
private static requestProvider?;
|
|
333
396
|
private static responseProvider?;
|
|
@@ -356,6 +419,7 @@ declare abstract class CoreRouter {
|
|
|
356
419
|
protected static getPluginStore(): Set<string>;
|
|
357
420
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
358
421
|
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
422
|
+
protected static getPluginHttpCtxResolvers(): Set<PluginArgumentsResolver>;
|
|
359
423
|
protected static createDefaultState(): {
|
|
360
424
|
config: RouterConfig;
|
|
361
425
|
groupContext: AsyncLocalStorage<{
|
|
@@ -372,6 +436,11 @@ declare abstract class CoreRouter {
|
|
|
372
436
|
};
|
|
373
437
|
protected static bindStateAccessors(): void;
|
|
374
438
|
protected static createDefaultOptionsHandler(): any;
|
|
439
|
+
/**
|
|
440
|
+
* Default configuration used for everytime the router is reset
|
|
441
|
+
*
|
|
442
|
+
* @param options
|
|
443
|
+
*/
|
|
375
444
|
static configureDefaults(options?: RouterConfig): void;
|
|
376
445
|
/**
|
|
377
446
|
* Use a registered plugin
|
|
@@ -386,7 +455,8 @@ declare abstract class CoreRouter {
|
|
|
386
455
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
387
456
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
388
457
|
protected static createPluginBind(): PluginBind;
|
|
389
|
-
protected static resolvePluginArguments(
|
|
458
|
+
protected static resolvePluginArguments(ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
459
|
+
protected static resolvePluginHttpCtx(ctx: any): Promise<void>;
|
|
390
460
|
protected static ensureState(): void;
|
|
391
461
|
/**
|
|
392
462
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -72,6 +72,7 @@ var CoreRouter = class {
|
|
|
72
72
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
73
73
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
74
74
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
75
|
+
static pluginHttpCtxResolversKey = Symbol.for("clear-router:plugin-http-ctx");
|
|
75
76
|
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
76
77
|
static requestProvider;
|
|
77
78
|
static responseProvider;
|
|
@@ -167,6 +168,11 @@ var CoreRouter = class {
|
|
|
167
168
|
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
168
169
|
return g[this.pluginArgumentResolversKey];
|
|
169
170
|
}
|
|
171
|
+
static getPluginHttpCtxResolvers() {
|
|
172
|
+
const g = globalThis;
|
|
173
|
+
if (!g[this.pluginHttpCtxResolversKey]) g[this.pluginHttpCtxResolversKey] = /* @__PURE__ */ new Set();
|
|
174
|
+
return g[this.pluginHttpCtxResolversKey];
|
|
175
|
+
}
|
|
170
176
|
static createDefaultState() {
|
|
171
177
|
return {
|
|
172
178
|
config: this.getDefaultConfig(),
|
|
@@ -248,6 +254,11 @@ var CoreRouter = class {
|
|
|
248
254
|
}
|
|
249
255
|
};
|
|
250
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Default configuration used for everytime the router is reset
|
|
259
|
+
*
|
|
260
|
+
* @param options
|
|
261
|
+
*/
|
|
251
262
|
static configureDefaults(options) {
|
|
252
263
|
const g = globalThis;
|
|
253
264
|
const defaults = this.mergeConfig(g[this.defaultConfigKey] || this.createBaseConfig(), options);
|
|
@@ -275,6 +286,9 @@ var CoreRouter = class {
|
|
|
275
286
|
resolveArguments: (resolver) => {
|
|
276
287
|
this.getPluginArgumentResolvers().add(resolver);
|
|
277
288
|
},
|
|
289
|
+
useHttpContext: (resolver) => {
|
|
290
|
+
this.getPluginHttpCtxResolvers().add(resolver);
|
|
291
|
+
},
|
|
278
292
|
bindings: require_bindings.Container.bindings(),
|
|
279
293
|
configure: this.configure.bind(this),
|
|
280
294
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -345,6 +359,12 @@ var CoreRouter = class {
|
|
|
345
359
|
if (Array.isArray(args)) return args;
|
|
346
360
|
}
|
|
347
361
|
}
|
|
362
|
+
static async resolvePluginHttpCtx(ctx) {
|
|
363
|
+
const resolvers = Array.from(this.getPluginHttpCtxResolvers());
|
|
364
|
+
if (!resolvers.length) return void 0;
|
|
365
|
+
const pluginContext = this.createPluginRequestContext(ctx);
|
|
366
|
+
for (const resolver of resolvers) await resolver(pluginContext);
|
|
367
|
+
}
|
|
348
368
|
static ensureState() {
|
|
349
369
|
this.bindStateAccessors();
|
|
350
370
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -768,6 +788,7 @@ var CoreRouter = class {
|
|
|
768
788
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
769
789
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
770
790
|
await this.pluginsReady();
|
|
791
|
+
await this.resolvePluginHttpCtx(ctx);
|
|
771
792
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
772
793
|
const designTokens = [...bindingTarget ? require_bindings.getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? require_bindings.getDesignParamTypes(bindingHandler) : []];
|
|
773
794
|
const metadata = require_bindings.getBindingMetadataFromTargets([
|
|
@@ -284,25 +284,87 @@ type PluginBindFactory<T = any> = (ctx: ClearRouterPluginRequestContext) => T |
|
|
|
284
284
|
type PluginBindValue<T = any> = BindValue<T> | PluginBindFactory<T>;
|
|
285
285
|
type PluginBind = <T>(token: BindToken<T>, value: PluginBindValue<T>) => void;
|
|
286
286
|
type PluginArgumentsResolver = (ctx: ClearRouterPluginArgumentsContext) => any[] | undefined | Promise<any[] | undefined>;
|
|
287
|
-
interface ClearRouterPluginContext<Options = any> {
|
|
287
|
+
interface ClearRouterPluginContext<Options = any, _HttpContext = any> {
|
|
288
|
+
/**
|
|
289
|
+
* The service container
|
|
290
|
+
*/
|
|
288
291
|
container: typeof Container;
|
|
292
|
+
/**
|
|
293
|
+
* Register service container bindings
|
|
294
|
+
*/
|
|
289
295
|
bind: PluginBind;
|
|
296
|
+
/**
|
|
297
|
+
* Replace all controller method arguments
|
|
298
|
+
* @param resolver
|
|
299
|
+
* @returns
|
|
300
|
+
*/
|
|
290
301
|
resolveArguments: (resolver: PluginArgumentsResolver) => void;
|
|
302
|
+
/**
|
|
303
|
+
* Use the current http context
|
|
304
|
+
*/
|
|
305
|
+
useHttpContext: (resolver: PluginArgumentsResolver) => void;
|
|
306
|
+
/**
|
|
307
|
+
* All registered service container bindings
|
|
308
|
+
*/
|
|
291
309
|
bindings: Record<string, BindValue>;
|
|
310
|
+
/**
|
|
311
|
+
* Configures the router with the given options, such as method override settings
|
|
312
|
+
*
|
|
313
|
+
* @param options
|
|
314
|
+
* @returns
|
|
315
|
+
*/
|
|
292
316
|
configure: (options: RouterConfig) => void;
|
|
317
|
+
/**
|
|
318
|
+
* Default configuration used for everytime the router is reset
|
|
319
|
+
*
|
|
320
|
+
* @param options
|
|
321
|
+
*/
|
|
293
322
|
configureDefaults: (options: RouterConfig) => void;
|
|
323
|
+
/**
|
|
324
|
+
* The current Request instance
|
|
325
|
+
*/
|
|
294
326
|
readonly request?: Request$1;
|
|
327
|
+
/**
|
|
328
|
+
* The current Response instance
|
|
329
|
+
* @returns
|
|
330
|
+
*/
|
|
295
331
|
readonly response?: Response$2;
|
|
332
|
+
/**
|
|
333
|
+
* Get the current Request instance
|
|
334
|
+
* @returns
|
|
335
|
+
*/
|
|
296
336
|
getRequest: () => Request$1 | undefined;
|
|
337
|
+
/**
|
|
338
|
+
* Get the current Response instance
|
|
339
|
+
* @returns
|
|
340
|
+
*/
|
|
297
341
|
getResponse: () => Response$2 | undefined;
|
|
342
|
+
/**
|
|
343
|
+
* Plugin configuration options
|
|
344
|
+
*/
|
|
298
345
|
options: Options;
|
|
299
346
|
}
|
|
300
|
-
interface ClearRouterPlugin<Options = any> {
|
|
347
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
348
|
+
/**
|
|
349
|
+
* The name of the plugin
|
|
350
|
+
*/
|
|
301
351
|
name?: string;
|
|
302
|
-
|
|
352
|
+
/**
|
|
353
|
+
* Plugin setup an implemnetation
|
|
354
|
+
*
|
|
355
|
+
* @param ctx
|
|
356
|
+
* @returns
|
|
357
|
+
*/
|
|
358
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
303
359
|
}
|
|
304
|
-
type ClearRouterPluginInput<Options = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options>) => PluginSetupResult);
|
|
305
|
-
|
|
360
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
361
|
+
/**
|
|
362
|
+
* Creates a new plugin
|
|
363
|
+
*
|
|
364
|
+
* @param plugin
|
|
365
|
+
* @returns
|
|
366
|
+
*/
|
|
367
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
306
368
|
//#endregion
|
|
307
369
|
//#region src/Controller.d.ts
|
|
308
370
|
declare abstract class Controller<X = any> {
|
|
@@ -328,6 +390,7 @@ declare abstract class CoreRouter {
|
|
|
328
390
|
private static readonly defaultConfigKey;
|
|
329
391
|
private static readonly pluginStoreKey;
|
|
330
392
|
private static readonly pluginPendingKey;
|
|
393
|
+
private static readonly pluginHttpCtxResolversKey;
|
|
331
394
|
private static readonly pluginArgumentResolversKey;
|
|
332
395
|
private static requestProvider?;
|
|
333
396
|
private static responseProvider?;
|
|
@@ -356,6 +419,7 @@ declare abstract class CoreRouter {
|
|
|
356
419
|
protected static getPluginStore(): Set<string>;
|
|
357
420
|
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
358
421
|
protected static getPluginArgumentResolvers(): Set<PluginArgumentsResolver>;
|
|
422
|
+
protected static getPluginHttpCtxResolvers(): Set<PluginArgumentsResolver>;
|
|
359
423
|
protected static createDefaultState(): {
|
|
360
424
|
config: RouterConfig;
|
|
361
425
|
groupContext: AsyncLocalStorage<{
|
|
@@ -372,6 +436,11 @@ declare abstract class CoreRouter {
|
|
|
372
436
|
};
|
|
373
437
|
protected static bindStateAccessors(): void;
|
|
374
438
|
protected static createDefaultOptionsHandler(): any;
|
|
439
|
+
/**
|
|
440
|
+
* Default configuration used for everytime the router is reset
|
|
441
|
+
*
|
|
442
|
+
* @param options
|
|
443
|
+
*/
|
|
375
444
|
static configureDefaults(options?: RouterConfig): void;
|
|
376
445
|
/**
|
|
377
446
|
* Use a registered plugin
|
|
@@ -386,7 +455,8 @@ declare abstract class CoreRouter {
|
|
|
386
455
|
protected static getCurrentPluginRequestContext(): ClearRouterPluginRequestContext | undefined;
|
|
387
456
|
protected static createPluginRequestContext(ctx: any): ClearRouterPluginRequestContext;
|
|
388
457
|
protected static createPluginBind(): PluginBind;
|
|
389
|
-
protected static resolvePluginArguments(
|
|
458
|
+
protected static resolvePluginArguments(ctx: any, routeContext: Omit<ClearRouterPluginArgumentsContext, keyof ClearRouterPluginRequestContext>): Promise<any[] | undefined>;
|
|
459
|
+
protected static resolvePluginHttpCtx(ctx: any): Promise<void>;
|
|
390
460
|
protected static ensureState(): void;
|
|
391
461
|
/**
|
|
392
462
|
* Normalizes a path by ensuring it starts with a single slash and does not have trailing
|
|
@@ -72,6 +72,7 @@ var CoreRouter = class {
|
|
|
72
72
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
73
73
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
74
74
|
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
75
|
+
static pluginHttpCtxResolversKey = Symbol.for("clear-router:plugin-http-ctx");
|
|
75
76
|
static pluginArgumentResolversKey = Symbol.for("clear-router:plugin-argument-resolvers");
|
|
76
77
|
static requestProvider;
|
|
77
78
|
static responseProvider;
|
|
@@ -167,6 +168,11 @@ var CoreRouter = class {
|
|
|
167
168
|
if (!g[this.pluginArgumentResolversKey]) g[this.pluginArgumentResolversKey] = /* @__PURE__ */ new Set();
|
|
168
169
|
return g[this.pluginArgumentResolversKey];
|
|
169
170
|
}
|
|
171
|
+
static getPluginHttpCtxResolvers() {
|
|
172
|
+
const g = globalThis;
|
|
173
|
+
if (!g[this.pluginHttpCtxResolversKey]) g[this.pluginHttpCtxResolversKey] = /* @__PURE__ */ new Set();
|
|
174
|
+
return g[this.pluginHttpCtxResolversKey];
|
|
175
|
+
}
|
|
170
176
|
static createDefaultState() {
|
|
171
177
|
return {
|
|
172
178
|
config: this.getDefaultConfig(),
|
|
@@ -248,6 +254,11 @@ var CoreRouter = class {
|
|
|
248
254
|
}
|
|
249
255
|
};
|
|
250
256
|
}
|
|
257
|
+
/**
|
|
258
|
+
* Default configuration used for everytime the router is reset
|
|
259
|
+
*
|
|
260
|
+
* @param options
|
|
261
|
+
*/
|
|
251
262
|
static configureDefaults(options) {
|
|
252
263
|
const g = globalThis;
|
|
253
264
|
const defaults = this.mergeConfig(g[this.defaultConfigKey] || this.createBaseConfig(), options);
|
|
@@ -275,6 +286,9 @@ var CoreRouter = class {
|
|
|
275
286
|
resolveArguments: (resolver) => {
|
|
276
287
|
this.getPluginArgumentResolvers().add(resolver);
|
|
277
288
|
},
|
|
289
|
+
useHttpContext: (resolver) => {
|
|
290
|
+
this.getPluginHttpCtxResolvers().add(resolver);
|
|
291
|
+
},
|
|
278
292
|
bindings: Container.bindings(),
|
|
279
293
|
configure: this.configure.bind(this),
|
|
280
294
|
configureDefaults: this.configureDefaults.bind(this),
|
|
@@ -345,6 +359,12 @@ var CoreRouter = class {
|
|
|
345
359
|
if (Array.isArray(args)) return args;
|
|
346
360
|
}
|
|
347
361
|
}
|
|
362
|
+
static async resolvePluginHttpCtx(ctx) {
|
|
363
|
+
const resolvers = Array.from(this.getPluginHttpCtxResolvers());
|
|
364
|
+
if (!resolvers.length) return void 0;
|
|
365
|
+
const pluginContext = this.createPluginRequestContext(ctx);
|
|
366
|
+
for (const resolver of resolvers) await resolver(pluginContext);
|
|
367
|
+
}
|
|
348
368
|
static ensureState() {
|
|
349
369
|
this.bindStateAccessors();
|
|
350
370
|
if (!this.config) this.config = { methodOverride: {
|
|
@@ -768,6 +788,7 @@ var CoreRouter = class {
|
|
|
768
788
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
769
789
|
return this.pluginRequestContext.run(this.createPluginRequestContext(ctx), async () => {
|
|
770
790
|
await this.pluginsReady();
|
|
791
|
+
await this.resolvePluginHttpCtx(ctx);
|
|
771
792
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
772
793
|
const designTokens = [...bindingTarget ? getDesignParamTypes(bindingTarget, bindingMethod) : [], ...bindingHandler ? getDesignParamTypes(bindingHandler) : []];
|
|
773
794
|
const metadata = getBindingMetadataFromTargets([
|
package/package.json
CHANGED