clear-router 2.5.6 → 2.5.7
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 +1 -1
- package/dist/core/index.d.mts +1 -1
- 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 +35 -10
- package/dist/index.d.cts +5 -2
- package/dist/index.d.mts +5 -2
- package/dist/index.mjs +35 -10
- 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-CU4V1kX0.cjs → router-BdMuUzGU.cjs} +35 -10
- package/dist/{router-DCMtQ_Xi.d.mts → router-D7R3G8w-.d.mts} +5 -2
- package/dist/{router-B3QjblRX.mjs → router-DzbF-ZV0.mjs} +35 -10
- package/dist/{router-BYZmNzrZ.d.cts → router-WAxKAcWR.d.cts} +5 -2
- 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-DvV2DXWi.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-BdMuUzGU.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 PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-
|
|
1
|
+
import { a as PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-WAxKAcWR.cjs";
|
|
2
2
|
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-
|
|
1
|
+
import { a as PluginBind, c as Request, i as ClearRouterPluginInput, n as ClearRouterPlugin, o as PluginSetupResult, r as ClearRouterPluginContext, s as definePlugin, t as CoreRouter, x as Response } from "../router-D7R3G8w-.mjs";
|
|
2
2
|
export { ClearRouterPlugin, ClearRouterPluginContext, ClearRouterPluginInput, CoreRouter, PluginBind, 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-DvV2DXWi.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-BdMuUzGU.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-DvV2DXWi.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-BdMuUzGU.cjs');
|
|
4
4
|
const require_responses = require('../responses-JzXstGU5.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/express/router.ts
|
package/dist/express/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ApiResourceMiddleware, b as HttpMethod, g as Middleware, h as HttpContext, l as Route, m as Handler, t as CoreRouter, v as ControllerAction } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, g as Middleware, h as HttpContext, l as Route, m as Handler, t as CoreRouter, v as ControllerAction } from "../router-WAxKAcWR.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 { _ as ApiResourceMiddleware, b as HttpMethod, g as Middleware, h as HttpContext, l as Route, m as Handler, t as CoreRouter, v as ControllerAction } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, g as Middleware, h as HttpContext, l as Route, m as Handler, t as CoreRouter, v as ControllerAction } from "../router-D7R3G8w-.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-DIanvIVd.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-_II3dOJ5.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-DvV2DXWi.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-BdMuUzGU.cjs');
|
|
4
4
|
const require_responses = require('../responses-JzXstGU5.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/fastify/router.ts
|
package/dist/fastify/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-WAxKAcWR.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 { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-D7R3G8w-.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-DIanvIVd.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, r as responseWasSent, t as isFetchResponse } from "../responses-_II3dOJ5.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-DvV2DXWi.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-BdMuUzGU.cjs');
|
|
4
4
|
const require_responses = require('../responses-JzXstGU5.cjs');
|
|
5
5
|
let h3 = require("h3");
|
|
6
6
|
|
package/dist/h3/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ApiResourceMiddleware, b as HttpMethod, d as Handler, f as HttpContext, l as Route, p as Middleware, t as CoreRouter, u as H3App, v as ControllerAction } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, d as Handler, f as HttpContext, l as Route, p as Middleware, t as CoreRouter, u as H3App, v as ControllerAction } from "../router-WAxKAcWR.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 { _ as ApiResourceMiddleware, b as HttpMethod, d as Handler, f as HttpContext, l as Route, p as Middleware, t as CoreRouter, u as H3App, v as ControllerAction } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, d as Handler, f as HttpContext, l as Route, p as Middleware, t as CoreRouter, u as H3App, v as ControllerAction } from "../router-D7R3G8w-.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-DIanvIVd.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
|
|
3
3
|
import { n as resolveResponseMeta } from "../responses-_II3dOJ5.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-DvV2DXWi.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-BdMuUzGU.cjs');
|
|
4
4
|
const require_responses = require('../responses-JzXstGU5.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/hono/router.ts
|
package/dist/hono/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-WAxKAcWR.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 { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-D7R3G8w-.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
|
@@ -219,6 +219,7 @@ var CoreRouter = class {
|
|
|
219
219
|
static stateBoundKey = Symbol.for("clear-router:router-state-bound");
|
|
220
220
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
221
221
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
222
|
+
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
222
223
|
static createBaseConfig() {
|
|
223
224
|
return {
|
|
224
225
|
methodOverride: {
|
|
@@ -265,6 +266,11 @@ var CoreRouter = class {
|
|
|
265
266
|
if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
|
|
266
267
|
return g[this.pluginStoreKey];
|
|
267
268
|
}
|
|
269
|
+
static getPluginPendingStore() {
|
|
270
|
+
const g = globalThis;
|
|
271
|
+
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
272
|
+
return g[this.pluginPendingKey];
|
|
273
|
+
}
|
|
268
274
|
static createDefaultState() {
|
|
269
275
|
return {
|
|
270
276
|
config: this.getDefaultConfig(),
|
|
@@ -370,20 +376,38 @@ var CoreRouter = class {
|
|
|
370
376
|
* @param options
|
|
371
377
|
* @returns
|
|
372
378
|
*/
|
|
373
|
-
static use(plugin, options) {
|
|
379
|
+
static async use(plugin, options) {
|
|
374
380
|
const name = typeof plugin === "function" ? plugin.name : plugin.name;
|
|
375
381
|
const store = this.getPluginStore();
|
|
376
382
|
if (name && store.has(name)) return;
|
|
377
|
-
const ctx = {
|
|
378
|
-
container: Container,
|
|
379
|
-
bind: Container.bind.bind(Container),
|
|
380
|
-
configure: this.configure.bind(this),
|
|
381
|
-
configureDefaults: this.configureDefaults.bind(this),
|
|
382
|
-
options
|
|
383
|
-
};
|
|
384
|
-
if (typeof plugin === "function") plugin(ctx);
|
|
385
|
-
else plugin.setup(ctx);
|
|
386
383
|
if (name) store.add(name);
|
|
384
|
+
const setup = async () => {
|
|
385
|
+
const ctx = {
|
|
386
|
+
container: Container,
|
|
387
|
+
bind: Container.bind.bind(Container),
|
|
388
|
+
configure: this.configure.bind(this),
|
|
389
|
+
configureDefaults: this.configureDefaults.bind(this),
|
|
390
|
+
options
|
|
391
|
+
};
|
|
392
|
+
if (typeof plugin === "function") await plugin(ctx);
|
|
393
|
+
else await plugin.setup(ctx);
|
|
394
|
+
};
|
|
395
|
+
const pending = this.getPluginPendingStore();
|
|
396
|
+
const promise = setup();
|
|
397
|
+
pending.add(promise);
|
|
398
|
+
try {
|
|
399
|
+
await promise;
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (name) store.delete(name);
|
|
402
|
+
throw error;
|
|
403
|
+
} finally {
|
|
404
|
+
pending.delete(promise);
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
static async pluginsReady() {
|
|
408
|
+
const pending = Array.from(this.getPluginPendingStore());
|
|
409
|
+
if (!pending.length) return;
|
|
410
|
+
await Promise.all(pending);
|
|
387
411
|
}
|
|
388
412
|
static groupContext = new node_async_hooks.AsyncLocalStorage();
|
|
389
413
|
static routes = [];
|
|
@@ -706,6 +730,7 @@ var CoreRouter = class {
|
|
|
706
730
|
};
|
|
707
731
|
}
|
|
708
732
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
733
|
+
await this.pluginsReady();
|
|
709
734
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
710
735
|
const metadata = getBindingMetadataFromTargets([
|
|
711
736
|
{
|
package/dist/index.d.cts
CHANGED
|
@@ -143,7 +143,7 @@ declare class Container {
|
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
145
|
//#region src/core/plugins.d.ts
|
|
146
|
-
type PluginSetupResult = void
|
|
146
|
+
type PluginSetupResult = void | Promise<void>;
|
|
147
147
|
type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
|
|
148
148
|
interface ClearRouterPluginContext<Options = any> {
|
|
149
149
|
container: typeof Container;
|
|
@@ -172,12 +172,14 @@ declare abstract class CoreRouter {
|
|
|
172
172
|
private static readonly stateBoundKey;
|
|
173
173
|
private static readonly defaultConfigKey;
|
|
174
174
|
private static readonly pluginStoreKey;
|
|
175
|
+
private static readonly pluginPendingKey;
|
|
175
176
|
protected static createBaseConfig(): RouterConfig;
|
|
176
177
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
177
178
|
protected static getDefaultConfig(): RouterConfig;
|
|
178
179
|
protected static resolveStateNamespace(this: any): string;
|
|
179
180
|
protected static getStateStore(): Record<string, any>;
|
|
180
181
|
protected static getPluginStore(): Set<string>;
|
|
182
|
+
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
181
183
|
protected static createDefaultState(): {
|
|
182
184
|
config: RouterConfig;
|
|
183
185
|
groupContext: AsyncLocalStorage<{
|
|
@@ -203,7 +205,8 @@ declare abstract class CoreRouter {
|
|
|
203
205
|
* @param options
|
|
204
206
|
* @returns
|
|
205
207
|
*/
|
|
206
|
-
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): void
|
|
208
|
+
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
|
|
209
|
+
protected static pluginsReady(this: any): Promise<void>;
|
|
207
210
|
protected static groupContext: AsyncLocalStorage<{
|
|
208
211
|
prefix: string;
|
|
209
212
|
groupMiddlewares: any[];
|
package/dist/index.d.mts
CHANGED
|
@@ -143,7 +143,7 @@ declare class Container {
|
|
|
143
143
|
}
|
|
144
144
|
//#endregion
|
|
145
145
|
//#region src/core/plugins.d.ts
|
|
146
|
-
type PluginSetupResult = void
|
|
146
|
+
type PluginSetupResult = void | Promise<void>;
|
|
147
147
|
type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
|
|
148
148
|
interface ClearRouterPluginContext<Options = any> {
|
|
149
149
|
container: typeof Container;
|
|
@@ -172,12 +172,14 @@ declare abstract class CoreRouter {
|
|
|
172
172
|
private static readonly stateBoundKey;
|
|
173
173
|
private static readonly defaultConfigKey;
|
|
174
174
|
private static readonly pluginStoreKey;
|
|
175
|
+
private static readonly pluginPendingKey;
|
|
175
176
|
protected static createBaseConfig(): RouterConfig;
|
|
176
177
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
177
178
|
protected static getDefaultConfig(): RouterConfig;
|
|
178
179
|
protected static resolveStateNamespace(this: any): string;
|
|
179
180
|
protected static getStateStore(): Record<string, any>;
|
|
180
181
|
protected static getPluginStore(): Set<string>;
|
|
182
|
+
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
181
183
|
protected static createDefaultState(): {
|
|
182
184
|
config: RouterConfig;
|
|
183
185
|
groupContext: AsyncLocalStorage<{
|
|
@@ -203,7 +205,8 @@ declare abstract class CoreRouter {
|
|
|
203
205
|
* @param options
|
|
204
206
|
* @returns
|
|
205
207
|
*/
|
|
206
|
-
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): void
|
|
208
|
+
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
|
|
209
|
+
protected static pluginsReady(this: any): Promise<void>;
|
|
207
210
|
protected static groupContext: AsyncLocalStorage<{
|
|
208
211
|
prefix: string;
|
|
209
212
|
groupMiddlewares: any[];
|
package/dist/index.mjs
CHANGED
|
@@ -218,6 +218,7 @@ var CoreRouter = class {
|
|
|
218
218
|
static stateBoundKey = Symbol.for("clear-router:router-state-bound");
|
|
219
219
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
220
220
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
221
|
+
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
221
222
|
static createBaseConfig() {
|
|
222
223
|
return {
|
|
223
224
|
methodOverride: {
|
|
@@ -264,6 +265,11 @@ var CoreRouter = class {
|
|
|
264
265
|
if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
|
|
265
266
|
return g[this.pluginStoreKey];
|
|
266
267
|
}
|
|
268
|
+
static getPluginPendingStore() {
|
|
269
|
+
const g = globalThis;
|
|
270
|
+
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
271
|
+
return g[this.pluginPendingKey];
|
|
272
|
+
}
|
|
267
273
|
static createDefaultState() {
|
|
268
274
|
return {
|
|
269
275
|
config: this.getDefaultConfig(),
|
|
@@ -369,20 +375,38 @@ var CoreRouter = class {
|
|
|
369
375
|
* @param options
|
|
370
376
|
* @returns
|
|
371
377
|
*/
|
|
372
|
-
static use(plugin, options) {
|
|
378
|
+
static async use(plugin, options) {
|
|
373
379
|
const name = typeof plugin === "function" ? plugin.name : plugin.name;
|
|
374
380
|
const store = this.getPluginStore();
|
|
375
381
|
if (name && store.has(name)) return;
|
|
376
|
-
const ctx = {
|
|
377
|
-
container: Container,
|
|
378
|
-
bind: Container.bind.bind(Container),
|
|
379
|
-
configure: this.configure.bind(this),
|
|
380
|
-
configureDefaults: this.configureDefaults.bind(this),
|
|
381
|
-
options
|
|
382
|
-
};
|
|
383
|
-
if (typeof plugin === "function") plugin(ctx);
|
|
384
|
-
else plugin.setup(ctx);
|
|
385
382
|
if (name) store.add(name);
|
|
383
|
+
const setup = async () => {
|
|
384
|
+
const ctx = {
|
|
385
|
+
container: Container,
|
|
386
|
+
bind: Container.bind.bind(Container),
|
|
387
|
+
configure: this.configure.bind(this),
|
|
388
|
+
configureDefaults: this.configureDefaults.bind(this),
|
|
389
|
+
options
|
|
390
|
+
};
|
|
391
|
+
if (typeof plugin === "function") await plugin(ctx);
|
|
392
|
+
else await plugin.setup(ctx);
|
|
393
|
+
};
|
|
394
|
+
const pending = this.getPluginPendingStore();
|
|
395
|
+
const promise = setup();
|
|
396
|
+
pending.add(promise);
|
|
397
|
+
try {
|
|
398
|
+
await promise;
|
|
399
|
+
} catch (error) {
|
|
400
|
+
if (name) store.delete(name);
|
|
401
|
+
throw error;
|
|
402
|
+
} finally {
|
|
403
|
+
pending.delete(promise);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
static async pluginsReady() {
|
|
407
|
+
const pending = Array.from(this.getPluginPendingStore());
|
|
408
|
+
if (!pending.length) return;
|
|
409
|
+
await Promise.all(pending);
|
|
386
410
|
}
|
|
387
411
|
static groupContext = new AsyncLocalStorage();
|
|
388
412
|
static routes = [];
|
|
@@ -705,6 +729,7 @@ var CoreRouter = class {
|
|
|
705
729
|
};
|
|
706
730
|
}
|
|
707
731
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
732
|
+
await this.pluginsReady();
|
|
708
733
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
709
734
|
const metadata = getBindingMetadataFromTargets([
|
|
710
735
|
{
|
package/dist/koa/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
2
|
require('../bindings-DvV2DXWi.cjs');
|
|
3
|
-
const require_router = require('../router-
|
|
3
|
+
const require_router = require('../router-BdMuUzGU.cjs');
|
|
4
4
|
const require_responses = require('../responses-JzXstGU5.cjs');
|
|
5
5
|
|
|
6
6
|
//#region src/koa/router.ts
|
package/dist/koa/index.d.cts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-WAxKAcWR.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 { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-
|
|
1
|
+
import { _ as ApiResourceMiddleware, b as HttpMethod, c as Request, l as Route, t as CoreRouter, v as ControllerAction, x as Response, y as ControllerHandler } from "../router-D7R3G8w-.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-DIanvIVd.mjs";
|
|
2
|
-
import { t as CoreRouter } from "../router-
|
|
2
|
+
import { t as CoreRouter } from "../router-DzbF-ZV0.mjs";
|
|
3
3
|
import { n as resolveResponseMeta, t as isFetchResponse } from "../responses-_II3dOJ5.mjs";
|
|
4
4
|
|
|
5
5
|
//#region src/koa/router.ts
|
|
@@ -42,6 +42,7 @@ var CoreRouter = class {
|
|
|
42
42
|
static stateBoundKey = Symbol.for("clear-router:router-state-bound");
|
|
43
43
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
44
44
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
45
|
+
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
45
46
|
static createBaseConfig() {
|
|
46
47
|
return {
|
|
47
48
|
methodOverride: {
|
|
@@ -88,6 +89,11 @@ var CoreRouter = class {
|
|
|
88
89
|
if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
|
|
89
90
|
return g[this.pluginStoreKey];
|
|
90
91
|
}
|
|
92
|
+
static getPluginPendingStore() {
|
|
93
|
+
const g = globalThis;
|
|
94
|
+
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
95
|
+
return g[this.pluginPendingKey];
|
|
96
|
+
}
|
|
91
97
|
static createDefaultState() {
|
|
92
98
|
return {
|
|
93
99
|
config: this.getDefaultConfig(),
|
|
@@ -193,20 +199,38 @@ var CoreRouter = class {
|
|
|
193
199
|
* @param options
|
|
194
200
|
* @returns
|
|
195
201
|
*/
|
|
196
|
-
static use(plugin, options) {
|
|
202
|
+
static async use(plugin, options) {
|
|
197
203
|
const name = typeof plugin === "function" ? plugin.name : plugin.name;
|
|
198
204
|
const store = this.getPluginStore();
|
|
199
205
|
if (name && store.has(name)) return;
|
|
200
|
-
const ctx = {
|
|
201
|
-
container: require_bindings.Container,
|
|
202
|
-
bind: require_bindings.Container.bind.bind(require_bindings.Container),
|
|
203
|
-
configure: this.configure.bind(this),
|
|
204
|
-
configureDefaults: this.configureDefaults.bind(this),
|
|
205
|
-
options
|
|
206
|
-
};
|
|
207
|
-
if (typeof plugin === "function") plugin(ctx);
|
|
208
|
-
else plugin.setup(ctx);
|
|
209
206
|
if (name) store.add(name);
|
|
207
|
+
const setup = async () => {
|
|
208
|
+
const ctx = {
|
|
209
|
+
container: require_bindings.Container,
|
|
210
|
+
bind: require_bindings.Container.bind.bind(require_bindings.Container),
|
|
211
|
+
configure: this.configure.bind(this),
|
|
212
|
+
configureDefaults: this.configureDefaults.bind(this),
|
|
213
|
+
options
|
|
214
|
+
};
|
|
215
|
+
if (typeof plugin === "function") await plugin(ctx);
|
|
216
|
+
else await plugin.setup(ctx);
|
|
217
|
+
};
|
|
218
|
+
const pending = this.getPluginPendingStore();
|
|
219
|
+
const promise = setup();
|
|
220
|
+
pending.add(promise);
|
|
221
|
+
try {
|
|
222
|
+
await promise;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (name) store.delete(name);
|
|
225
|
+
throw error;
|
|
226
|
+
} finally {
|
|
227
|
+
pending.delete(promise);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
static async pluginsReady() {
|
|
231
|
+
const pending = Array.from(this.getPluginPendingStore());
|
|
232
|
+
if (!pending.length) return;
|
|
233
|
+
await Promise.all(pending);
|
|
210
234
|
}
|
|
211
235
|
static groupContext = new node_async_hooks.AsyncLocalStorage();
|
|
212
236
|
static routes = [];
|
|
@@ -529,6 +553,7 @@ var CoreRouter = class {
|
|
|
529
553
|
};
|
|
530
554
|
}
|
|
531
555
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
556
|
+
await this.pluginsReady();
|
|
532
557
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
533
558
|
const metadata = require_bindings.getBindingMetadataFromTargets([
|
|
534
559
|
{
|
|
@@ -190,7 +190,7 @@ declare class Request$1<X = any, M = any> extends ClearRequest<X, M> {
|
|
|
190
190
|
}
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/core/plugins.d.ts
|
|
193
|
-
type PluginSetupResult = void
|
|
193
|
+
type PluginSetupResult = void | Promise<void>;
|
|
194
194
|
type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
|
|
195
195
|
interface ClearRouterPluginContext<Options = any> {
|
|
196
196
|
container: typeof Container;
|
|
@@ -229,12 +229,14 @@ declare abstract class CoreRouter {
|
|
|
229
229
|
private static readonly stateBoundKey;
|
|
230
230
|
private static readonly defaultConfigKey;
|
|
231
231
|
private static readonly pluginStoreKey;
|
|
232
|
+
private static readonly pluginPendingKey;
|
|
232
233
|
protected static createBaseConfig(): RouterConfig;
|
|
233
234
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
234
235
|
protected static getDefaultConfig(): RouterConfig;
|
|
235
236
|
protected static resolveStateNamespace(this: any): string;
|
|
236
237
|
protected static getStateStore(): Record<string, any>;
|
|
237
238
|
protected static getPluginStore(): Set<string>;
|
|
239
|
+
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
238
240
|
protected static createDefaultState(): {
|
|
239
241
|
config: RouterConfig;
|
|
240
242
|
groupContext: AsyncLocalStorage<{
|
|
@@ -260,7 +262,8 @@ declare abstract class CoreRouter {
|
|
|
260
262
|
* @param options
|
|
261
263
|
* @returns
|
|
262
264
|
*/
|
|
263
|
-
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): void
|
|
265
|
+
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
|
|
266
|
+
protected static pluginsReady(this: any): Promise<void>;
|
|
264
267
|
protected static groupContext: AsyncLocalStorage<{
|
|
265
268
|
prefix: string;
|
|
266
269
|
groupMiddlewares: any[];
|
|
@@ -42,6 +42,7 @@ var CoreRouter = class {
|
|
|
42
42
|
static stateBoundKey = Symbol.for("clear-router:router-state-bound");
|
|
43
43
|
static defaultConfigKey = Symbol.for("clear-router:default-config");
|
|
44
44
|
static pluginStoreKey = Symbol.for("clear-router:plugins");
|
|
45
|
+
static pluginPendingKey = Symbol.for("clear-router:plugin-promises");
|
|
45
46
|
static createBaseConfig() {
|
|
46
47
|
return {
|
|
47
48
|
methodOverride: {
|
|
@@ -88,6 +89,11 @@ var CoreRouter = class {
|
|
|
88
89
|
if (!g[this.pluginStoreKey]) g[this.pluginStoreKey] = /* @__PURE__ */ new Set();
|
|
89
90
|
return g[this.pluginStoreKey];
|
|
90
91
|
}
|
|
92
|
+
static getPluginPendingStore() {
|
|
93
|
+
const g = globalThis;
|
|
94
|
+
if (!g[this.pluginPendingKey]) g[this.pluginPendingKey] = /* @__PURE__ */ new Set();
|
|
95
|
+
return g[this.pluginPendingKey];
|
|
96
|
+
}
|
|
91
97
|
static createDefaultState() {
|
|
92
98
|
return {
|
|
93
99
|
config: this.getDefaultConfig(),
|
|
@@ -193,20 +199,38 @@ var CoreRouter = class {
|
|
|
193
199
|
* @param options
|
|
194
200
|
* @returns
|
|
195
201
|
*/
|
|
196
|
-
static use(plugin, options) {
|
|
202
|
+
static async use(plugin, options) {
|
|
197
203
|
const name = typeof plugin === "function" ? plugin.name : plugin.name;
|
|
198
204
|
const store = this.getPluginStore();
|
|
199
205
|
if (name && store.has(name)) return;
|
|
200
|
-
const ctx = {
|
|
201
|
-
container: Container,
|
|
202
|
-
bind: Container.bind.bind(Container),
|
|
203
|
-
configure: this.configure.bind(this),
|
|
204
|
-
configureDefaults: this.configureDefaults.bind(this),
|
|
205
|
-
options
|
|
206
|
-
};
|
|
207
|
-
if (typeof plugin === "function") plugin(ctx);
|
|
208
|
-
else plugin.setup(ctx);
|
|
209
206
|
if (name) store.add(name);
|
|
207
|
+
const setup = async () => {
|
|
208
|
+
const ctx = {
|
|
209
|
+
container: Container,
|
|
210
|
+
bind: Container.bind.bind(Container),
|
|
211
|
+
configure: this.configure.bind(this),
|
|
212
|
+
configureDefaults: this.configureDefaults.bind(this),
|
|
213
|
+
options
|
|
214
|
+
};
|
|
215
|
+
if (typeof plugin === "function") await plugin(ctx);
|
|
216
|
+
else await plugin.setup(ctx);
|
|
217
|
+
};
|
|
218
|
+
const pending = this.getPluginPendingStore();
|
|
219
|
+
const promise = setup();
|
|
220
|
+
pending.add(promise);
|
|
221
|
+
try {
|
|
222
|
+
await promise;
|
|
223
|
+
} catch (error) {
|
|
224
|
+
if (name) store.delete(name);
|
|
225
|
+
throw error;
|
|
226
|
+
} finally {
|
|
227
|
+
pending.delete(promise);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
static async pluginsReady() {
|
|
231
|
+
const pending = Array.from(this.getPluginPendingStore());
|
|
232
|
+
if (!pending.length) return;
|
|
233
|
+
await Promise.all(pending);
|
|
210
234
|
}
|
|
211
235
|
static groupContext = new AsyncLocalStorage();
|
|
212
236
|
static routes = [];
|
|
@@ -529,6 +553,7 @@ var CoreRouter = class {
|
|
|
529
553
|
};
|
|
530
554
|
}
|
|
531
555
|
static async callHandler(handlerFunction, ctx, bindingTarget, bindingMethod, bindingHandler, bindingMetadata) {
|
|
556
|
+
await this.pluginsReady();
|
|
532
557
|
if (!this.config.container?.enabled) return handlerFunction(ctx, ctx.clearRequest);
|
|
533
558
|
const metadata = getBindingMetadataFromTargets([
|
|
534
559
|
{
|
|
@@ -190,7 +190,7 @@ declare class Request$1<X = any, M = any> extends ClearRequest<X, M> {
|
|
|
190
190
|
}
|
|
191
191
|
//#endregion
|
|
192
192
|
//#region src/core/plugins.d.ts
|
|
193
|
-
type PluginSetupResult = void
|
|
193
|
+
type PluginSetupResult = void | Promise<void>;
|
|
194
194
|
type PluginBind = <T>(token: BindToken<T>, value: BindValue<T>) => void;
|
|
195
195
|
interface ClearRouterPluginContext<Options = any> {
|
|
196
196
|
container: typeof Container;
|
|
@@ -229,12 +229,14 @@ declare abstract class CoreRouter {
|
|
|
229
229
|
private static readonly stateBoundKey;
|
|
230
230
|
private static readonly defaultConfigKey;
|
|
231
231
|
private static readonly pluginStoreKey;
|
|
232
|
+
private static readonly pluginPendingKey;
|
|
232
233
|
protected static createBaseConfig(): RouterConfig;
|
|
233
234
|
protected static mergeConfig(target: RouterConfig, source?: RouterConfig): RouterConfig;
|
|
234
235
|
protected static getDefaultConfig(): RouterConfig;
|
|
235
236
|
protected static resolveStateNamespace(this: any): string;
|
|
236
237
|
protected static getStateStore(): Record<string, any>;
|
|
237
238
|
protected static getPluginStore(): Set<string>;
|
|
239
|
+
protected static getPluginPendingStore(): Set<Promise<void>>;
|
|
238
240
|
protected static createDefaultState(): {
|
|
239
241
|
config: RouterConfig;
|
|
240
242
|
groupContext: AsyncLocalStorage<{
|
|
@@ -260,7 +262,8 @@ declare abstract class CoreRouter {
|
|
|
260
262
|
* @param options
|
|
261
263
|
* @returns
|
|
262
264
|
*/
|
|
263
|
-
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): void
|
|
265
|
+
static use<Options = any>(this: any, plugin: ClearRouterPluginInput<Options>, options?: Options): Promise<void>;
|
|
266
|
+
protected static pluginsReady(this: any): Promise<void>;
|
|
264
267
|
protected static groupContext: AsyncLocalStorage<{
|
|
265
268
|
prefix: string;
|
|
266
269
|
groupMiddlewares: any[];
|
package/package.json
CHANGED