clear-router 2.6.6 → 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/README.md +2 -2
- 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 +2 -2
- package/dist/express/index.d.cts +2 -2
- package/dist/express/index.d.mts +2 -2
- package/dist/express/index.mjs +2 -2
- package/dist/fastify/index.cjs +2 -2
- package/dist/fastify/index.d.cts +2 -2
- package/dist/fastify/index.d.mts +2 -2
- package/dist/fastify/index.mjs +2 -2
- package/dist/h3/index.cjs +2 -2
- package/dist/h3/index.d.cts +2 -2
- package/dist/h3/index.d.mts +2 -2
- package/dist/h3/index.mjs +2 -2
- package/dist/hono/index.cjs +2 -2
- package/dist/hono/index.d.cts +2 -2
- package/dist/hono/index.d.mts +2 -2
- package/dist/hono/index.mjs +2 -2
- package/dist/index.cjs +28 -1
- package/dist/index.d.cts +77 -7
- package/dist/index.d.mts +77 -7
- package/dist/index.mjs +28 -1
- package/dist/koa/index.cjs +2 -2
- package/dist/koa/index.d.cts +2 -2
- package/dist/koa/index.d.mts +2 -2
- package/dist/koa/index.mjs +2 -2
- package/dist/{router-Cs8cC5zd.d.mts → router-1hB-k4No.d.mts} +77 -7
- package/dist/{router-CB7Duy0X.cjs → router-C6W-k6sS.cjs} +22 -1
- package/dist/{router-BITqScD_.d.cts → router-Cl6q9Od3.d.cts} +77 -7
- package/dist/{router-CTzjojnD.mjs → router-Dc9w86Wn.mjs} +22 -1
- package/package.json +3 -3
package/dist/index.d.mts
CHANGED
|
@@ -207,32 +207,94 @@ 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
|
/**
|
|
232
294
|
* @class clear-router CoreRouter
|
|
233
295
|
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
234
296
|
* @author 3m1n3nc3
|
|
235
|
-
* @repository https://github.com/
|
|
297
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
236
298
|
*/
|
|
237
299
|
declare abstract class CoreRouter {
|
|
238
300
|
protected static routerStateNamespace: string;
|
|
@@ -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
|
}
|
|
@@ -289,7 +295,7 @@ function isClass(value) {
|
|
|
289
295
|
* @class clear-router CoreRouter
|
|
290
296
|
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
291
297
|
* @author 3m1n3nc3
|
|
292
|
-
* @repository https://github.com/
|
|
298
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
293
299
|
*/
|
|
294
300
|
var CoreRouter = class {
|
|
295
301
|
static routerStateNamespace = "clear-router:core";
|
|
@@ -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
|
|
@@ -8,7 +8,7 @@ const require_responses = require('../responses-Bvnk0uvc.cjs');
|
|
|
8
8
|
* @class clear-router Koa Router
|
|
9
9
|
* @description Laravel-style routing system for Koa using @koa/router and shared clear-router core
|
|
10
10
|
* @author 3m1n3nc3
|
|
11
|
-
* @repository https://github.com/
|
|
11
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
12
12
|
*/
|
|
13
13
|
var Router = class Router extends require_router.CoreRouter {
|
|
14
14
|
static routerStateNamespace = "clear-router:koa";
|
package/dist/koa/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
/**
|
|
5
5
|
* @class clear-router Koa Router
|
|
6
6
|
* @description Laravel-style routing system for Koa using @koa/router and shared clear-router core
|
|
7
7
|
* @author 3m1n3nc3
|
|
8
|
-
* @repository https://github.com/
|
|
8
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
9
9
|
*/
|
|
10
10
|
declare class Router extends CoreRouter {
|
|
11
11
|
protected static routerStateNamespace: string;
|
package/dist/koa/index.d.mts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
|
/**
|
|
5
5
|
* @class clear-router Koa Router
|
|
6
6
|
* @description Laravel-style routing system for Koa using @koa/router and shared clear-router core
|
|
7
7
|
* @author 3m1n3nc3
|
|
8
|
-
* @repository https://github.com/
|
|
8
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
9
9
|
*/
|
|
10
10
|
declare class Router extends CoreRouter {
|
|
11
11
|
protected static routerStateNamespace: string;
|
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
|
|
@@ -7,7 +7,7 @@ import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-BvE
|
|
|
7
7
|
* @class clear-router Koa Router
|
|
8
8
|
* @description Laravel-style routing system for Koa using @koa/router and shared clear-router core
|
|
9
9
|
* @author 3m1n3nc3
|
|
10
|
-
* @repository https://github.com/
|
|
10
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
11
11
|
*/
|
|
12
12
|
var Router = class Router extends CoreRouter {
|
|
13
13
|
static routerStateNamespace = "clear-router:koa";
|
|
@@ -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> {
|
|
@@ -319,7 +381,7 @@ declare abstract class Controller<X = any> {
|
|
|
319
381
|
* @class clear-router CoreRouter
|
|
320
382
|
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
321
383
|
* @author 3m1n3nc3
|
|
322
|
-
* @repository https://github.com/
|
|
384
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
323
385
|
*/
|
|
324
386
|
declare abstract class CoreRouter {
|
|
325
387
|
protected static routerStateNamespace: string;
|
|
@@ -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
|
|
@@ -63,7 +63,7 @@ var Route = class {
|
|
|
63
63
|
* @class clear-router CoreRouter
|
|
64
64
|
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
65
65
|
* @author 3m1n3nc3
|
|
66
|
-
* @repository https://github.com/
|
|
66
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
67
67
|
*/
|
|
68
68
|
var CoreRouter = class {
|
|
69
69
|
static routerStateNamespace = "clear-router:core";
|
|
@@ -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> {
|
|
@@ -319,7 +381,7 @@ declare abstract class Controller<X = any> {
|
|
|
319
381
|
* @class clear-router CoreRouter
|
|
320
382
|
* @description Core routing logic for clear-router, shared between all supported adapters (Express.js, H3, etc.)
|
|
321
383
|
* @author 3m1n3nc3
|
|
322
|
-
* @repository https://github.com/
|
|
384
|
+
* @repository https://github.com/arkstack-tmp/clear-router
|
|
323
385
|
*/
|
|
324
386
|
declare abstract class CoreRouter {
|
|
325
387
|
protected static routerStateNamespace: string;
|
|
@@ -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
|