clear-router 2.7.6 → 2.8.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/ClearRequest.cjs +23 -0
- package/dist/ClearRequest.d.cts +28 -0
- package/dist/ClearRequest.d.mts +28 -0
- package/dist/ClearRequest.mjs +22 -0
- package/dist/Contracts.d.cts +12 -0
- package/dist/Contracts.d.mts +12 -0
- package/dist/Controller.cjs +12 -0
- package/dist/Controller.d.cts +14 -0
- package/dist/Controller.d.mts +14 -0
- package/dist/Controller.mjs +11 -0
- package/dist/{Request-DKXwa_W0.d.mts → Request-Ci0UQ-Vl.d.mts} +32 -5
- package/dist/ResourceRouteSelection.cjs +26 -0
- package/dist/ResourceRouteSelection.d.cts +20 -0
- package/dist/ResourceRouteSelection.d.mts +20 -0
- package/dist/ResourceRouteSelection.mjs +25 -0
- package/dist/ResourceRoutes.cjs +60 -0
- package/dist/ResourceRoutes.d.cts +37 -0
- package/dist/ResourceRoutes.d.mts +37 -0
- package/dist/ResourceRoutes.mjs +60 -0
- package/dist/Route.cjs +90 -0
- package/dist/Route.d.cts +62 -0
- package/dist/Route.d.mts +62 -0
- package/dist/Route.mjs +89 -0
- package/dist/core/Request.cjs +35 -0
- package/dist/core/Request.d.cts +25 -0
- package/dist/core/Request.d.mts +25 -0
- package/dist/core/Request.mjs +35 -0
- package/dist/core/Response.cjs +59 -0
- package/dist/core/Response.d.cts +24 -0
- package/dist/core/Response.d.mts +24 -0
- package/dist/core/Response.mjs +58 -0
- package/dist/{bindings-CLsZjOEy.cjs → core/bindings.cjs} +10 -160
- package/dist/{bindings-CNL7bpz5.d.mts → core/bindings.d.cts} +1 -1
- package/dist/{bindings-CxvtC8XS.d.cts → core/bindings.d.mts} +1 -1
- package/dist/{bindings-XLDXFpHZ.mjs → core/bindings.mjs} +3 -110
- package/dist/core/index.cjs +7 -17
- package/dist/core/index.d.cts +4 -1
- package/dist/core/index.d.mts +4 -1
- package/dist/core/index.mjs +4 -14
- package/dist/core/plugins.cjs +14 -0
- package/dist/core/plugins.d.cts +109 -0
- package/dist/core/plugins.d.mts +109 -0
- package/dist/core/plugins.mjs +13 -0
- package/dist/{responses-Bvnk0uvc.cjs → core/responses.cjs} +5 -20
- package/dist/{responses-BvETUeDL.mjs → core/responses.mjs} +2 -2
- package/dist/{router-C6W-k6sS.cjs → core/router.cjs} +67 -72
- package/dist/core/router.d.cts +286 -0
- package/dist/core/router.d.mts +286 -0
- package/dist/{router-Dc9w86Wn.mjs → core/router.mjs} +62 -62
- package/dist/decorators/index.cjs +1 -1
- package/dist/decorators/index.d.cts +1 -1
- package/dist/decorators/index.d.mts +1 -1
- package/dist/decorators/index.mjs +1 -1
- package/dist/decorators/setup.cjs +2 -2
- package/dist/decorators/setup.d.cts +1 -1
- package/dist/decorators/setup.d.mts +1 -2
- package/dist/decorators/setup.mjs +2 -2
- package/dist/express/index.cjs +2 -265
- package/dist/express/index.d.cts +1 -127
- package/dist/express/index.d.mts +1 -127
- package/dist/express/index.mjs +1 -264
- package/dist/express/router.cjs +265 -0
- package/dist/express/router.d.cts +132 -0
- package/dist/express/router.d.mts +132 -0
- package/dist/express/router.mjs +265 -0
- package/dist/fastify/index.cjs +2 -254
- package/dist/fastify/index.d.cts +1 -125
- package/dist/fastify/index.d.mts +1 -125
- package/dist/fastify/index.mjs +1 -253
- package/dist/fastify/router.cjs +254 -0
- package/dist/fastify/router.d.cts +130 -0
- package/dist/fastify/router.d.mts +130 -0
- package/dist/fastify/router.mjs +254 -0
- package/dist/h3/index.cjs +2 -260
- package/dist/h3/index.d.cts +1 -128
- package/dist/h3/index.d.mts +1 -128
- package/dist/h3/index.mjs +1 -259
- package/dist/h3/router.cjs +260 -0
- package/dist/h3/router.d.cts +133 -0
- package/dist/h3/router.d.mts +133 -0
- package/dist/h3/router.mjs +260 -0
- package/dist/hono/index.cjs +2 -251
- package/dist/hono/index.d.cts +1 -130
- package/dist/hono/index.d.mts +1 -130
- package/dist/hono/index.mjs +1 -250
- package/dist/hono/router.cjs +251 -0
- package/dist/hono/router.d.cts +135 -0
- package/dist/hono/router.d.mts +135 -0
- package/dist/hono/router.mjs +251 -0
- package/dist/index.cjs +16 -1097
- package/dist/index.d.cts +9 -563
- package/dist/index.d.mts +9 -563
- package/dist/index.mjs +8 -1089
- package/dist/koa/index.cjs +2 -261
- package/dist/koa/index.d.cts +1 -131
- package/dist/koa/index.d.mts +1 -131
- package/dist/koa/index.mjs +1 -260
- package/dist/koa/router.cjs +261 -0
- package/dist/koa/router.d.cts +136 -0
- package/dist/koa/router.d.mts +136 -0
- package/dist/koa/router.mjs +261 -0
- package/dist/types/basic.d.cts +53 -0
- package/dist/types/basic.d.mts +11 -1
- package/dist/types/express.d.cts +48 -0
- package/dist/types/express.d.mts +10 -4
- package/dist/types/fastify.d.cts +24 -0
- package/dist/types/fastify.d.mts +7 -4
- package/dist/types/h3.d.cts +46 -0
- package/dist/types/h3.d.mts +10 -5
- package/dist/types/hono.d.cts +22 -0
- package/dist/types/hono.d.mts +8 -6
- package/dist/types/koa.d.cts +26 -0
- package/dist/types/koa.d.mts +7 -5
- package/package.json +1 -1
- package/dist/router-BEgAxp5A.d.cts +0 -649
- package/dist/router-DKKYx23P.d.mts +0 -649
|
@@ -22,4 +22,4 @@ declare class Container {
|
|
|
22
22
|
}
|
|
23
23
|
declare function Bind(...tokens: BindToken[]): BindDecorator;
|
|
24
24
|
//#endregion
|
|
25
|
-
export {
|
|
25
|
+
export { Bind, BindDecorator, BindFactory, BindToken, BindValue, Container };
|
|
@@ -1,113 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @param body - Parsed request body
|
|
5
|
-
*/
|
|
6
|
-
body;
|
|
7
|
-
/**
|
|
8
|
-
* @param query - Parsed query parameters
|
|
9
|
-
*/
|
|
10
|
-
query;
|
|
11
|
-
/**
|
|
12
|
-
* @param params - Parsed route parameters
|
|
13
|
-
*/
|
|
14
|
-
params;
|
|
15
|
-
route;
|
|
16
|
-
constructor(init) {
|
|
17
|
-
Object.assign(this, init);
|
|
18
|
-
}
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
//#endregion
|
|
22
|
-
//#region src/core/Request.ts
|
|
23
|
-
var Request = class extends ClearRequest {
|
|
24
|
-
original;
|
|
25
|
-
method = "GET";
|
|
26
|
-
path = "/";
|
|
27
|
-
url = "/";
|
|
28
|
-
headers = {};
|
|
29
|
-
constructor(init) {
|
|
30
|
-
super(init);
|
|
31
|
-
Object.assign(this, init);
|
|
32
|
-
}
|
|
33
|
-
getBody() {
|
|
34
|
-
return this.body ?? {};
|
|
35
|
-
}
|
|
36
|
-
header(name) {
|
|
37
|
-
if (typeof this.headers.get === "function") return this.headers.get(name) || "";
|
|
38
|
-
const headers = this.headers;
|
|
39
|
-
const value = headers[name] ?? headers[name.toLowerCase()];
|
|
40
|
-
return Array.isArray(value) ? String(value[0] ?? "") : String(value ?? "");
|
|
41
|
-
}
|
|
42
|
-
param(name) {
|
|
43
|
-
return this.params?.[name];
|
|
44
|
-
}
|
|
45
|
-
input(name) {
|
|
46
|
-
return this.body?.[name] ?? this.query?.[name] ?? this.params?.[name];
|
|
47
|
-
}
|
|
48
|
-
is(method) {
|
|
49
|
-
return this.method.toLowerCase() === String(method).toLowerCase();
|
|
50
|
-
}
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
//#endregion
|
|
54
|
-
//#region src/core/Response.ts
|
|
55
|
-
var Response = class {
|
|
56
|
-
body;
|
|
57
|
-
headers = new Headers();
|
|
58
|
-
sent = false;
|
|
59
|
-
statusCode = 200;
|
|
60
|
-
statusText = "OK";
|
|
61
|
-
constructor(init) {
|
|
62
|
-
const { status: _, ...rest } = init ?? {};
|
|
63
|
-
Object.assign(this, rest);
|
|
64
|
-
if (init?.headers && !(init.headers instanceof Headers)) this.headers = new Headers(init.headers);
|
|
65
|
-
if (init?.status && typeof init.status === "number") this.statusCode = init?.status;
|
|
66
|
-
}
|
|
67
|
-
status(code) {
|
|
68
|
-
this.statusCode = code;
|
|
69
|
-
return this;
|
|
70
|
-
}
|
|
71
|
-
setStatusText(text) {
|
|
72
|
-
this.statusText = text;
|
|
73
|
-
return this;
|
|
74
|
-
}
|
|
75
|
-
code(code) {
|
|
76
|
-
return this.status(code);
|
|
77
|
-
}
|
|
78
|
-
setHeader(name, value) {
|
|
79
|
-
this.headers.set(name, value);
|
|
80
|
-
return this;
|
|
81
|
-
}
|
|
82
|
-
header(name, value) {
|
|
83
|
-
return this.setHeader(name, value);
|
|
84
|
-
}
|
|
85
|
-
set(name, value) {
|
|
86
|
-
return this.setHeader(name, value);
|
|
87
|
-
}
|
|
88
|
-
type(contentType) {
|
|
89
|
-
return this.setHeader("Content-Type", contentType);
|
|
90
|
-
}
|
|
91
|
-
send(body) {
|
|
92
|
-
this.body = body;
|
|
93
|
-
this.sent = true;
|
|
94
|
-
return this;
|
|
95
|
-
}
|
|
96
|
-
json(body) {
|
|
97
|
-
return this.type("application/json; charset=utf-8").send(body);
|
|
98
|
-
}
|
|
99
|
-
html(body) {
|
|
100
|
-
return this.type("text/html; charset=utf-8").send(body);
|
|
101
|
-
}
|
|
102
|
-
text(body) {
|
|
103
|
-
return this.type("text/plain; charset=utf-8").send(body);
|
|
104
|
-
}
|
|
105
|
-
noContent() {
|
|
106
|
-
return this.status(204).send(null);
|
|
107
|
-
}
|
|
108
|
-
};
|
|
1
|
+
import { Request } from "./Request.mjs";
|
|
2
|
+
import { Response } from "./Response.mjs";
|
|
109
3
|
|
|
110
|
-
//#endregion
|
|
111
4
|
//#region src/core/bindings.ts
|
|
112
5
|
const metadataKey = Symbol.for("clear-router:binding-metadata");
|
|
113
6
|
const bindings = /* @__PURE__ */ new WeakMap();
|
|
@@ -258,4 +151,4 @@ function isClass(value) {
|
|
|
258
151
|
}
|
|
259
152
|
|
|
260
153
|
//#endregion
|
|
261
|
-
export {
|
|
154
|
+
export { Bind, Container, getBindingMetadataFromTargets, getDesignParamTypes, getStandardMetadata, isClass };
|
package/dist/core/index.cjs
CHANGED
|
@@ -1,20 +1,10 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
const
|
|
3
|
-
const
|
|
2
|
+
const require_Request = require('./Request.cjs');
|
|
3
|
+
const require_Response = require('./Response.cjs');
|
|
4
|
+
const require_plugins = require('./plugins.cjs');
|
|
5
|
+
const require_router = require('./router.cjs');
|
|
4
6
|
|
|
5
|
-
//#region src/core/plugins.ts
|
|
6
|
-
/**
|
|
7
|
-
* Creates a new plugin
|
|
8
|
-
*
|
|
9
|
-
* @param plugin
|
|
10
|
-
* @returns
|
|
11
|
-
*/
|
|
12
|
-
function definePlugin(plugin) {
|
|
13
|
-
return plugin;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
//#endregion
|
|
17
7
|
exports.CoreRouter = require_router.CoreRouter;
|
|
18
|
-
exports.Request =
|
|
19
|
-
exports.Response =
|
|
20
|
-
exports.definePlugin = definePlugin;
|
|
8
|
+
exports.Request = require_Request.Request;
|
|
9
|
+
exports.Response = require_Response.Response;
|
|
10
|
+
exports.definePlugin = require_plugins.definePlugin;
|
package/dist/core/index.d.cts
CHANGED
|
@@ -1,2 +1,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response } from "./Response.cjs";
|
|
2
|
+
import { Request } from "./Request.cjs";
|
|
3
|
+
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./plugins.cjs";
|
|
4
|
+
import { CoreRouter } from "./router.cjs";
|
|
2
5
|
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,5 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response } from "./Response.mjs";
|
|
2
|
+
import { Request } from "./Request.mjs";
|
|
3
|
+
import { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin } from "./plugins.mjs";
|
|
4
|
+
import { CoreRouter } from "./router.mjs";
|
|
2
5
|
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, CoreRouter, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, Request, Response, definePlugin };
|
package/dist/core/index.mjs
CHANGED
|
@@ -1,16 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Request } from "./Request.mjs";
|
|
2
|
+
import { Response } from "./Response.mjs";
|
|
3
|
+
import { definePlugin } from "./plugins.mjs";
|
|
4
|
+
import { CoreRouter } from "./router.mjs";
|
|
3
5
|
|
|
4
|
-
//#region src/core/plugins.ts
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new plugin
|
|
7
|
-
*
|
|
8
|
-
* @param plugin
|
|
9
|
-
* @returns
|
|
10
|
-
*/
|
|
11
|
-
function definePlugin(plugin) {
|
|
12
|
-
return plugin;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
//#endregion
|
|
16
6
|
export { CoreRouter, Request, Response, definePlugin };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RouterConfig } from "../types/basic.cjs";
|
|
2
|
+
import { Response } from "./Response.cjs";
|
|
3
|
+
import { Request } from "./Request.cjs";
|
|
4
|
+
import { BindToken, BindValue, Container } from "./bindings.cjs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/plugins.d.ts
|
|
7
|
+
type PluginSetupResult = void | Promise<void>;
|
|
8
|
+
interface ClearRouterPluginRequestContext<HttpContext = any> {
|
|
9
|
+
ctx: HttpContext;
|
|
10
|
+
request: Request;
|
|
11
|
+
response: Response;
|
|
12
|
+
getBindings: () => Record<string, BindValue>;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
interface ClearRouterPluginArgumentsContext<X = any> extends ClearRouterPluginRequestContext<X> {
|
|
16
|
+
target?: object;
|
|
17
|
+
method?: PropertyKey;
|
|
18
|
+
handler?: object;
|
|
19
|
+
metadata?: object;
|
|
20
|
+
tokens: BindToken[];
|
|
21
|
+
designTokens: BindToken[];
|
|
22
|
+
}
|
|
23
|
+
type PluginBindFactory<T = any, X = any> = (ctx: ClearRouterPluginRequestContext<X>) => T | Promise<T>;
|
|
24
|
+
type PluginBindValue<T = any, X = any> = BindValue<T> | PluginBindFactory<T, X>;
|
|
25
|
+
type PluginBind<X = any> = <T>(token: BindToken<T>, value: PluginBindValue<T, X>) => void;
|
|
26
|
+
type PluginArgumentsResolver<HttpContext = any> = (ctx: ClearRouterPluginArgumentsContext<HttpContext>) => any[] | undefined | Promise<any[] | undefined>;
|
|
27
|
+
interface ClearRouterPluginContext<Options = any, HttpContext = any> {
|
|
28
|
+
/**
|
|
29
|
+
* The service container
|
|
30
|
+
*/
|
|
31
|
+
container: typeof Container;
|
|
32
|
+
/**
|
|
33
|
+
* Register service container bindings
|
|
34
|
+
*/
|
|
35
|
+
bind: PluginBind<HttpContext>;
|
|
36
|
+
/**
|
|
37
|
+
* Replace all controller method arguments
|
|
38
|
+
* @param resolver
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
resolveArguments: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Use the current http context
|
|
44
|
+
*/
|
|
45
|
+
useHttpContext: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* All registered service container bindings
|
|
48
|
+
*/
|
|
49
|
+
bindings: Record<string, BindValue>;
|
|
50
|
+
/**
|
|
51
|
+
* Configures the router with the given options, such as method override settings
|
|
52
|
+
*
|
|
53
|
+
* @param options
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
configure: (options: RouterConfig) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Default configuration used for everytime the router is reset
|
|
59
|
+
*
|
|
60
|
+
* @param options
|
|
61
|
+
*/
|
|
62
|
+
configureDefaults: (options: RouterConfig) => void;
|
|
63
|
+
/**
|
|
64
|
+
* The current Request instance
|
|
65
|
+
*/
|
|
66
|
+
readonly request?: Request;
|
|
67
|
+
/**
|
|
68
|
+
* The current Response instance
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
readonly response?: Response;
|
|
72
|
+
/**
|
|
73
|
+
* Get the current Request instance
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
getRequest: () => Request | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get the current Response instance
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
getResponse: () => Response | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Plugin configuration options
|
|
84
|
+
*/
|
|
85
|
+
options: Options;
|
|
86
|
+
}
|
|
87
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
88
|
+
/**
|
|
89
|
+
* The name of the plugin
|
|
90
|
+
*/
|
|
91
|
+
name?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Plugin setup an implemnetation
|
|
94
|
+
*
|
|
95
|
+
* @param ctx
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
99
|
+
}
|
|
100
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new plugin
|
|
103
|
+
*
|
|
104
|
+
* @param plugin
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin };
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { RouterConfig } from "../types/basic.mjs";
|
|
2
|
+
import { Response } from "./Response.mjs";
|
|
3
|
+
import { Request } from "./Request.mjs";
|
|
4
|
+
import { BindToken, BindValue, Container } from "./bindings.mjs";
|
|
5
|
+
|
|
6
|
+
//#region src/core/plugins.d.ts
|
|
7
|
+
type PluginSetupResult = void | Promise<void>;
|
|
8
|
+
interface ClearRouterPluginRequestContext<HttpContext = any> {
|
|
9
|
+
ctx: HttpContext;
|
|
10
|
+
request: Request;
|
|
11
|
+
response: Response;
|
|
12
|
+
getBindings: () => Record<string, BindValue>;
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
}
|
|
15
|
+
interface ClearRouterPluginArgumentsContext<X = any> extends ClearRouterPluginRequestContext<X> {
|
|
16
|
+
target?: object;
|
|
17
|
+
method?: PropertyKey;
|
|
18
|
+
handler?: object;
|
|
19
|
+
metadata?: object;
|
|
20
|
+
tokens: BindToken[];
|
|
21
|
+
designTokens: BindToken[];
|
|
22
|
+
}
|
|
23
|
+
type PluginBindFactory<T = any, X = any> = (ctx: ClearRouterPluginRequestContext<X>) => T | Promise<T>;
|
|
24
|
+
type PluginBindValue<T = any, X = any> = BindValue<T> | PluginBindFactory<T, X>;
|
|
25
|
+
type PluginBind<X = any> = <T>(token: BindToken<T>, value: PluginBindValue<T, X>) => void;
|
|
26
|
+
type PluginArgumentsResolver<HttpContext = any> = (ctx: ClearRouterPluginArgumentsContext<HttpContext>) => any[] | undefined | Promise<any[] | undefined>;
|
|
27
|
+
interface ClearRouterPluginContext<Options = any, HttpContext = any> {
|
|
28
|
+
/**
|
|
29
|
+
* The service container
|
|
30
|
+
*/
|
|
31
|
+
container: typeof Container;
|
|
32
|
+
/**
|
|
33
|
+
* Register service container bindings
|
|
34
|
+
*/
|
|
35
|
+
bind: PluginBind<HttpContext>;
|
|
36
|
+
/**
|
|
37
|
+
* Replace all controller method arguments
|
|
38
|
+
* @param resolver
|
|
39
|
+
* @returns
|
|
40
|
+
*/
|
|
41
|
+
resolveArguments: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
42
|
+
/**
|
|
43
|
+
* Use the current http context
|
|
44
|
+
*/
|
|
45
|
+
useHttpContext: (resolver: PluginArgumentsResolver<HttpContext>) => void;
|
|
46
|
+
/**
|
|
47
|
+
* All registered service container bindings
|
|
48
|
+
*/
|
|
49
|
+
bindings: Record<string, BindValue>;
|
|
50
|
+
/**
|
|
51
|
+
* Configures the router with the given options, such as method override settings
|
|
52
|
+
*
|
|
53
|
+
* @param options
|
|
54
|
+
* @returns
|
|
55
|
+
*/
|
|
56
|
+
configure: (options: RouterConfig) => void;
|
|
57
|
+
/**
|
|
58
|
+
* Default configuration used for everytime the router is reset
|
|
59
|
+
*
|
|
60
|
+
* @param options
|
|
61
|
+
*/
|
|
62
|
+
configureDefaults: (options: RouterConfig) => void;
|
|
63
|
+
/**
|
|
64
|
+
* The current Request instance
|
|
65
|
+
*/
|
|
66
|
+
readonly request?: Request;
|
|
67
|
+
/**
|
|
68
|
+
* The current Response instance
|
|
69
|
+
* @returns
|
|
70
|
+
*/
|
|
71
|
+
readonly response?: Response;
|
|
72
|
+
/**
|
|
73
|
+
* Get the current Request instance
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
getRequest: () => Request | undefined;
|
|
77
|
+
/**
|
|
78
|
+
* Get the current Response instance
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
getResponse: () => Response | undefined;
|
|
82
|
+
/**
|
|
83
|
+
* Plugin configuration options
|
|
84
|
+
*/
|
|
85
|
+
options: Options;
|
|
86
|
+
}
|
|
87
|
+
interface ClearRouterPlugin<Options = any, HttpContext = any> {
|
|
88
|
+
/**
|
|
89
|
+
* The name of the plugin
|
|
90
|
+
*/
|
|
91
|
+
name?: string;
|
|
92
|
+
/**
|
|
93
|
+
* Plugin setup an implemnetation
|
|
94
|
+
*
|
|
95
|
+
* @param ctx
|
|
96
|
+
* @returns
|
|
97
|
+
*/
|
|
98
|
+
setup: (ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult;
|
|
99
|
+
}
|
|
100
|
+
type ClearRouterPluginInput<Options = any, HttpContext = any> = ClearRouterPlugin<Options> | ((ctx: ClearRouterPluginContext<Options, HttpContext>) => PluginSetupResult);
|
|
101
|
+
/**
|
|
102
|
+
* Creates a new plugin
|
|
103
|
+
*
|
|
104
|
+
* @param plugin
|
|
105
|
+
* @returns
|
|
106
|
+
*/
|
|
107
|
+
declare function definePlugin<Options = any, HttpContext = any>(plugin: ClearRouterPlugin<Options, HttpContext>): ClearRouterPlugin<Options, HttpContext>;
|
|
108
|
+
//#endregion
|
|
109
|
+
export { ClearRouterPlugin, ClearRouterPluginArgumentsContext, ClearRouterPluginContext, ClearRouterPluginInput, ClearRouterPluginRequestContext, PluginArgumentsResolver, PluginBind, PluginBindFactory, PluginBindValue, PluginSetupResult, definePlugin };
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_Response = require('./Response.cjs');
|
|
2
2
|
|
|
3
3
|
//#region src/core/responses.ts
|
|
4
4
|
function isFetchResponse(value) {
|
|
5
5
|
return typeof globalThis.Response !== "undefined" && value instanceof globalThis.Response;
|
|
6
6
|
}
|
|
7
7
|
function isCoreResponse(value) {
|
|
8
|
-
return value instanceof
|
|
8
|
+
return value instanceof require_Response.Response;
|
|
9
9
|
}
|
|
10
10
|
function isH3Response(value) {
|
|
11
11
|
return Boolean(value && typeof value === "object" && value.constructor?.name === "HTTPResponse");
|
|
@@ -88,21 +88,6 @@ function inferStringContentType(value, apiRequest) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
return isFetchResponse;
|
|
95
|
-
}
|
|
96
|
-
});
|
|
97
|
-
Object.defineProperty(exports, 'resolveResponseMeta', {
|
|
98
|
-
enumerable: true,
|
|
99
|
-
get: function () {
|
|
100
|
-
return resolveResponseMeta;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
Object.defineProperty(exports, 'responseWasSent', {
|
|
104
|
-
enumerable: true,
|
|
105
|
-
get: function () {
|
|
106
|
-
return responseWasSent;
|
|
107
|
-
}
|
|
108
|
-
});
|
|
91
|
+
exports.isFetchResponse = isFetchResponse;
|
|
92
|
+
exports.resolveResponseMeta = resolveResponseMeta;
|
|
93
|
+
exports.responseWasSent = responseWasSent;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { Response } from "./Response.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/core/responses.ts
|
|
4
4
|
function isFetchResponse(value) {
|
|
@@ -88,4 +88,4 @@ function inferStringContentType(value, apiRequest) {
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
//#endregion
|
|
91
|
-
export { resolveResponseMeta
|
|
91
|
+
export { isFetchResponse, resolveResponseMeta, responseWasSent };
|