@webiny/handler 0.0.0-unstable.b14eaecf38 → 0.0.0-unstable.b6d7105cee
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/Context.d.ts +4 -5
- package/Context.js +11 -38
- package/Context.js.map +1 -1
- package/PreHandler/IPreHandler.d.ts +9 -0
- package/PreHandler/IPreHandler.js +8 -0
- package/PreHandler/IPreHandler.js.map +1 -0
- package/PreHandler/IfNotOptionsRequest.d.ts +9 -0
- package/PreHandler/IfNotOptionsRequest.js +18 -0
- package/PreHandler/IfNotOptionsRequest.js.map +1 -0
- package/PreHandler/IfOptionsRequest.d.ts +9 -0
- package/PreHandler/IfOptionsRequest.js +18 -0
- package/PreHandler/IfOptionsRequest.js.map +1 -0
- package/PreHandler/PreHandler.d.ts +9 -0
- package/PreHandler/PreHandler.js +16 -0
- package/PreHandler/PreHandler.js.map +1 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.d.ts +10 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.js +25 -0
- package/PreHandler/ProcessBeforeHandlerPlugins.js.map +1 -0
- package/PreHandler/ProcessContextPlugins.d.ts +10 -0
- package/PreHandler/ProcessContextPlugins.js +25 -0
- package/PreHandler/ProcessContextPlugins.js.map +1 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.d.ts +10 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.js +25 -0
- package/PreHandler/ProcessHandlerOnRequestPlugins.js.map +1 -0
- package/PreHandler/RegisterExtensions.d.ts +10 -0
- package/PreHandler/RegisterExtensions.js +13 -0
- package/PreHandler/RegisterExtensions.js.map +1 -0
- package/PreHandler/SendEarlyOptionsResponse.d.ts +9 -0
- package/PreHandler/SendEarlyOptionsResponse.js +26 -0
- package/PreHandler/SendEarlyOptionsResponse.js.map +1 -0
- package/PreHandler/SetDefaultHeaders.d.ts +9 -0
- package/PreHandler/SetDefaultHeaders.js +46 -0
- package/PreHandler/SetDefaultHeaders.js.map +1 -0
- package/README.md +10 -14
- package/ResponseHeaders.d.ts +24 -0
- package/ResponseHeaders.js +36 -0
- package/ResponseHeaders.js.map +1 -0
- package/abstractions/Reply.d.ts +5 -0
- package/abstractions/Reply.js +5 -0
- package/abstractions/Reply.js.map +1 -0
- package/abstractions/Request.d.ts +5 -0
- package/abstractions/Request.js +5 -0
- package/abstractions/Request.js.map +1 -0
- package/abstractions/Route.d.ts +25 -0
- package/abstractions/Route.js +30 -0
- package/abstractions/Route.js.map +1 -0
- package/exports/api.d.ts +1 -0
- package/exports/api.js +1 -0
- package/fastify.d.ts +8 -5
- package/fastify.js +306 -412
- package/fastify.js.map +1 -1
- package/index.d.ts +19 -9
- package/index.js +19 -104
- package/package.json +23 -29
- package/plugins/BeforeHandlerPlugin.d.ts +1 -1
- package/plugins/BeforeHandlerPlugin.js +16 -26
- package/plugins/BeforeHandlerPlugin.js.map +1 -1
- package/plugins/EventPlugin.d.ts +3 -3
- package/plugins/EventPlugin.js +13 -30
- package/plugins/EventPlugin.js.map +1 -1
- package/plugins/HandlerErrorPlugin.d.ts +6 -3
- package/plugins/HandlerErrorPlugin.js +16 -24
- package/plugins/HandlerErrorPlugin.js.map +1 -1
- package/plugins/HandlerOnRequestPlugin.d.ts +9 -8
- package/plugins/HandlerOnRequestPlugin.js +16 -24
- package/plugins/HandlerOnRequestPlugin.js.map +1 -1
- package/plugins/HandlerResultPlugin.d.ts +1 -1
- package/plugins/HandlerResultPlugin.js +16 -24
- package/plugins/HandlerResultPlugin.js.map +1 -1
- package/plugins/ModifyFastifyPlugin.d.ts +2 -2
- package/plugins/ModifyFastifyPlugin.js +16 -24
- package/plugins/ModifyFastifyPlugin.js.map +1 -1
- package/plugins/ModifyResponseHeadersPlugin.d.ts +14 -0
- package/plugins/ModifyResponseHeadersPlugin.js +19 -0
- package/plugins/ModifyResponseHeadersPlugin.js.map +1 -0
- package/plugins/OnRequestResponseSendPlugin.d.ts +26 -0
- package/plugins/OnRequestResponseSendPlugin.js +17 -0
- package/plugins/OnRequestResponseSendPlugin.js.map +1 -0
- package/plugins/OnRequestTimeoutPlugin.d.ts +12 -0
- package/plugins/OnRequestTimeoutPlugin.js +17 -0
- package/plugins/OnRequestTimeoutPlugin.js.map +1 -0
- package/plugins/RegisterExtensionPlugin.d.ts +12 -0
- package/plugins/RegisterExtensionPlugin.js +16 -0
- package/plugins/RegisterExtensionPlugin.js.map +1 -0
- package/plugins/RoutePlugin.d.ts +2 -2
- package/plugins/RoutePlugin.js +13 -21
- package/plugins/RoutePlugin.js.map +1 -1
- package/stringifyError.d.ts +5 -0
- package/stringifyError.js +15 -0
- package/stringifyError.js.map +1 -0
- package/suppressPunycodeWarnings.d.ts +1 -0
- package/suppressPunycodeWarnings.js +7 -0
- package/suppressPunycodeWarnings.js.map +1 -0
- package/types.d.ts +11 -14
- package/types.js +1 -18
- package/index.js.map +0 -1
- package/middleware.d.ts +0 -4
- package/middleware.js +0 -45
- package/middleware.js.map +0 -1
- package/types.js.map +0 -1
|
@@ -1,20 +1,21 @@
|
|
|
1
|
+
import type { Context } from "../types.js";
|
|
1
2
|
import { Plugin } from "@webiny/plugins";
|
|
2
|
-
import { FastifyReply, FastifyRequest } from "fastify";
|
|
3
|
+
import type { FastifyReply, FastifyRequest } from "fastify";
|
|
3
4
|
/**
|
|
4
5
|
* If the execution of the callable returns false, no more plugins will be executed after the given one.
|
|
5
6
|
* Nor it will execute our default OPTIONS code.
|
|
6
7
|
*
|
|
7
8
|
* This way users can prevent stopping of the request on our built-in OPTIONS request.
|
|
8
9
|
*/
|
|
9
|
-
export
|
|
10
|
-
interface HandlerOnRequestPluginCallable {
|
|
11
|
-
(request: FastifyRequest, reply: FastifyReply): Promise<HandlerOnRequestPluginCallableResponse>;
|
|
10
|
+
export type HandlerOnRequestPluginCallableResponse = false | undefined | null | void;
|
|
11
|
+
interface HandlerOnRequestPluginCallable<C extends Context = Context> {
|
|
12
|
+
(request: FastifyRequest, reply: FastifyReply, context: C): Promise<HandlerOnRequestPluginCallableResponse>;
|
|
12
13
|
}
|
|
13
|
-
export declare class HandlerOnRequestPlugin extends Plugin {
|
|
14
|
+
export declare class HandlerOnRequestPlugin<C extends Context = Context> extends Plugin {
|
|
14
15
|
static type: string;
|
|
15
16
|
private readonly cb;
|
|
16
|
-
constructor(cb: HandlerOnRequestPluginCallable);
|
|
17
|
-
exec(request: FastifyRequest, reply: FastifyReply): Promise<HandlerOnRequestPluginCallableResponse>;
|
|
17
|
+
constructor(cb: HandlerOnRequestPluginCallable<C>);
|
|
18
|
+
exec(request: FastifyRequest, reply: FastifyReply, context: C): Promise<HandlerOnRequestPluginCallableResponse>;
|
|
18
19
|
}
|
|
19
|
-
export declare const createHandlerOnRequest: (cb: HandlerOnRequestPluginCallable) => HandlerOnRequestPlugin
|
|
20
|
+
export declare const createHandlerOnRequest: <C extends Context = Context>(cb: HandlerOnRequestPluginCallable<C>) => HandlerOnRequestPlugin<C>;
|
|
20
21
|
export {};
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
14
|
-
this.cb = cb;
|
|
15
|
-
}
|
|
16
|
-
async exec(request, reply) {
|
|
17
|
-
return this.cb(request, reply);
|
|
18
|
-
}
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class HandlerOnRequestPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.event.onRequest";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
async exec(request, reply, context) {
|
|
11
|
+
return this.cb(request, reply, context);
|
|
12
|
+
}
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
exports.createHandlerOnRequest = createHandlerOnRequest;
|
|
14
|
+
const createHandlerOnRequest = (cb)=>new HandlerOnRequestPlugin(cb);
|
|
15
|
+
export { HandlerOnRequestPlugin, createHandlerOnRequest };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=HandlerOnRequestPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/HandlerOnRequestPlugin.js","sources":["../../src/plugins/HandlerOnRequestPlugin.ts"],"sourcesContent":["import type { Context } from \"~/types.js\";\nimport { Plugin } from \"@webiny/plugins\";\nimport type { FastifyReply, FastifyRequest } from \"fastify\";\n\n/**\n * If the execution of the callable returns false, no more plugins will be executed after the given one.\n * Nor it will execute our default OPTIONS code.\n *\n * This way users can prevent stopping of the request on our built-in OPTIONS request.\n */\nexport type HandlerOnRequestPluginCallableResponse = false | undefined | null | void;\ninterface HandlerOnRequestPluginCallable<C extends Context = Context> {\n (\n request: FastifyRequest,\n reply: FastifyReply,\n context: C\n ): Promise<HandlerOnRequestPluginCallableResponse>;\n}\n\nexport class HandlerOnRequestPlugin<C extends Context = Context> extends Plugin {\n public static override type = \"handler.event.onRequest\";\n\n private readonly cb: HandlerOnRequestPluginCallable<C>;\n\n public constructor(cb: HandlerOnRequestPluginCallable<C>) {\n super();\n this.cb = cb;\n }\n\n public async exec(\n request: FastifyRequest,\n reply: FastifyReply,\n context: C\n ): Promise<HandlerOnRequestPluginCallableResponse> {\n return this.cb(request, reply, context);\n }\n}\n\nexport const createHandlerOnRequest = <C extends Context = Context>(\n cb: HandlerOnRequestPluginCallable<C>\n) => {\n return new HandlerOnRequestPlugin<C>(cb);\n};\n"],"names":["HandlerOnRequestPlugin","Plugin","cb","request","reply","context","createHandlerOnRequest"],"mappings":";AAmBO,MAAMA,+BAA4DC;;aAC9C,IAAI,GAAG;;IAI9B,YAAmBC,EAAqC,CAAE;QACtD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,MAAa,KACTC,OAAuB,EACvBC,KAAmB,EACnBC,OAAU,EACqC;QAC/C,OAAO,IAAI,CAAC,EAAE,CAACF,SAASC,OAAOC;IACnC;AACJ;AAEO,MAAMC,yBAAyB,CAClCJ,KAEO,IAAIF,uBAA0BE"}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(0, _defineProperty2.default)(this, "_callable", void 0);
|
|
14
|
-
this._callable = callable;
|
|
15
|
-
}
|
|
16
|
-
async handle(context, result) {
|
|
17
|
-
return this._callable(context, result);
|
|
18
|
-
}
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class HandlerResultPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler-result";
|
|
5
|
+
}
|
|
6
|
+
constructor(callable){
|
|
7
|
+
super();
|
|
8
|
+
this._callable = callable;
|
|
9
|
+
}
|
|
10
|
+
async handle(context, result) {
|
|
11
|
+
return this._callable(context, result);
|
|
12
|
+
}
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
exports.createHandlerResultPlugin = createHandlerResultPlugin;
|
|
14
|
+
const createHandlerResultPlugin = (callable)=>new HandlerResultPlugin(callable);
|
|
15
|
+
export { HandlerResultPlugin, createHandlerResultPlugin };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=HandlerResultPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/HandlerResultPlugin.js","sources":["../../src/plugins/HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types.js\";\n\nexport interface HandlerResultCallable<T extends Context = Context> {\n (context: T, result: any): Promise<any>;\n}\n\nexport class HandlerResultPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-result\";\n\n private readonly _callable: HandlerResultCallable<T>;\n\n public constructor(callable: HandlerResultCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, result: any): Promise<any> {\n return this._callable(context, result);\n }\n}\n\nexport const createHandlerResultPlugin = <T extends Context = Context>(\n callable: HandlerResultCallable<T>\n): HandlerResultPlugin<T> => {\n return new HandlerResultPlugin<T>(callable);\n};\n"],"names":["HandlerResultPlugin","Plugin","callable","context","result","createHandlerResultPlugin"],"mappings":";AAOO,MAAMA,4BAAyDC;;aAClC,IAAI,GAAW;;IAI/C,YAAmBC,QAAkC,CAAE;QACnD,KAAK;QACL,IAAI,CAAC,SAAS,GAAGA;IACrB;IAEA,MAAa,OAAOC,OAAU,EAAEC,MAAW,EAAgB;QACvD,OAAO,IAAI,CAAC,SAAS,CAACD,SAASC;IACnC;AACJ;AAEO,MAAMC,4BAA4B,CACrCH,WAEO,IAAIF,oBAAuBE"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import { FastifyInstance } from "fastify";
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
import type { FastifyInstance } from "fastify";
|
|
3
3
|
interface ModifyFastifyPluginCallable {
|
|
4
4
|
(app: FastifyInstance): void;
|
|
5
5
|
}
|
|
@@ -1,25 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
14
|
-
this.cb = cb;
|
|
15
|
-
}
|
|
16
|
-
modify(app) {
|
|
17
|
-
this.cb(app);
|
|
18
|
-
}
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
class ModifyFastifyPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.modify";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
modify(app) {
|
|
11
|
+
this.cb(app);
|
|
12
|
+
}
|
|
19
13
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
exports.createModifyFastifyPlugin = createModifyFastifyPlugin;
|
|
14
|
+
const createModifyFastifyPlugin = (cb)=>new ModifyFastifyPlugin(cb);
|
|
15
|
+
export { ModifyFastifyPlugin, createModifyFastifyPlugin };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=ModifyFastifyPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/ModifyFastifyPlugin.js","sources":["../../src/plugins/ModifyFastifyPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { FastifyInstance } from \"fastify\";\n\ninterface ModifyFastifyPluginCallable {\n (app: FastifyInstance): void;\n}\n\nexport class ModifyFastifyPlugin extends Plugin {\n public static override type = \"handler.fastify.modify\";\n\n private readonly cb: ModifyFastifyPluginCallable;\n\n public constructor(cb: ModifyFastifyPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public modify(app: FastifyInstance): void {\n this.cb(app);\n }\n}\n\nexport const createModifyFastifyPlugin = (cb: ModifyFastifyPluginCallable) => {\n return new ModifyFastifyPlugin(cb);\n};\n"],"names":["ModifyFastifyPlugin","Plugin","cb","app","createModifyFastifyPlugin"],"mappings":";AAOO,MAAMA,4BAA4BC;;aACd,IAAI,GAAG;;IAI9B,YAAmBC,EAA+B,CAAE;QAChD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEO,OAAOC,GAAoB,EAAQ;QACtC,IAAI,CAAC,EAAE,CAACA;IACZ;AACJ;AAEO,MAAMC,4BAA4B,CAACF,KAC/B,IAAIF,oBAAoBE"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
import type { ResponseHeaders } from "../ResponseHeaders.js";
|
|
3
|
+
import type { Request } from "../types.js";
|
|
4
|
+
interface ModifyResponseHeadersCallable {
|
|
5
|
+
(request: Request, headers: ResponseHeaders): void;
|
|
6
|
+
}
|
|
7
|
+
export declare class ModifyResponseHeadersPlugin extends Plugin {
|
|
8
|
+
static type: string;
|
|
9
|
+
private readonly cb;
|
|
10
|
+
constructor(cb: ModifyResponseHeadersCallable);
|
|
11
|
+
modify(request: Request, headers: ResponseHeaders): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function createModifyResponseHeaders(cb: ModifyResponseHeadersCallable): ModifyResponseHeadersPlugin;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
class ModifyResponseHeadersPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.response.modifyHeaders";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
modify(request, headers) {
|
|
11
|
+
this.cb(request, headers);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
function createModifyResponseHeaders(cb) {
|
|
15
|
+
return new ModifyResponseHeadersPlugin(cb);
|
|
16
|
+
}
|
|
17
|
+
export { ModifyResponseHeadersPlugin, createModifyResponseHeaders };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=ModifyResponseHeadersPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/ModifyResponseHeadersPlugin.js","sources":["../../src/plugins/ModifyResponseHeadersPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { ResponseHeaders } from \"~/ResponseHeaders.js\";\nimport type { Request } from \"~/types.js\";\n\ninterface ModifyResponseHeadersCallable {\n (request: Request, headers: ResponseHeaders): void;\n}\n\nexport class ModifyResponseHeadersPlugin extends Plugin {\n public static override type = \"handler.response.modifyHeaders\";\n private readonly cb: ModifyResponseHeadersCallable;\n\n constructor(cb: ModifyResponseHeadersCallable) {\n super();\n this.cb = cb;\n }\n\n modify(request: Request, headers: ResponseHeaders) {\n this.cb(request, headers);\n }\n}\n\nexport function createModifyResponseHeaders(cb: ModifyResponseHeadersCallable) {\n return new ModifyResponseHeadersPlugin(cb);\n}\n"],"names":["ModifyResponseHeadersPlugin","Plugin","cb","request","headers","createModifyResponseHeaders"],"mappings":";AAQO,MAAMA,oCAAoCC;;aACtB,IAAI,GAAG;;IAG9B,YAAYC,EAAiC,CAAE;QAC3C,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,OAAOC,OAAgB,EAAEC,OAAwB,EAAE;QAC/C,IAAI,CAAC,EAAE,CAACD,SAASC;IACrB;AACJ;AAEO,SAASC,4BAA4BH,EAAiC;IACzE,OAAO,IAAIF,4BAA4BE;AAC3C"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* !!!!!!!!!!!!!!
|
|
3
|
+
* !!! DANGER !!!
|
|
4
|
+
* !!!!!!!!!!!!!!
|
|
5
|
+
*
|
|
6
|
+
* Using this plugin can cause slowdowns in your application response times.
|
|
7
|
+
* Also, if you do not return payload from the plugin callback, there will be nothing to send in the response.
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from "@webiny/plugins";
|
|
10
|
+
import type { Reply as FastifyReply, Request as FastifyRequest } from "../types.js";
|
|
11
|
+
export interface IOnResponseSendPluginCallable {
|
|
12
|
+
<T = unknown>(request: FastifyRequest, reply: FastifyReply, payload: T): Promise<T>;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* @description Read info in the class file.
|
|
16
|
+
*/
|
|
17
|
+
export declare class OnRequestResponseSendPlugin extends Plugin {
|
|
18
|
+
static type: string;
|
|
19
|
+
private readonly cb;
|
|
20
|
+
constructor(cb: IOnResponseSendPluginCallable);
|
|
21
|
+
exec<T = unknown>(request: FastifyRequest, reply: FastifyReply, payload: T): Promise<unknown>;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* @description Read info in the class file.
|
|
25
|
+
*/
|
|
26
|
+
export declare const createOnRequestResponseSend: (cb: IOnResponseSendPluginCallable) => OnRequestResponseSendPlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class OnRequestResponseSendPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.onRequestResponseSend";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
async exec(request, reply, payload) {
|
|
11
|
+
return await this.cb(request, reply, payload);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const createOnRequestResponseSend = (cb)=>new OnRequestResponseSendPlugin(cb);
|
|
15
|
+
export { OnRequestResponseSendPlugin, createOnRequestResponseSend };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=OnRequestResponseSendPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/OnRequestResponseSendPlugin.js","sources":["../../src/plugins/OnRequestResponseSendPlugin.ts"],"sourcesContent":["/**\n * !!!!!!!!!!!!!!\n * !!! DANGER !!!\n * !!!!!!!!!!!!!!\n *\n * Using this plugin can cause slowdowns in your application response times.\n * Also, if you do not return payload from the plugin callback, there will be nothing to send in the response.\n */\nimport { Plugin } from \"@webiny/plugins\";\nimport type { Reply as FastifyReply, Request as FastifyRequest } from \"~/types.js\";\n\nexport interface IOnResponseSendPluginCallable {\n <T = unknown>(request: FastifyRequest, reply: FastifyReply, payload: T): Promise<T>;\n}\n\n/**\n * @description Read info in the class file.\n */\nexport class OnRequestResponseSendPlugin extends Plugin {\n public static override type: string = \"handler.onRequestResponseSend\";\n\n private readonly cb: IOnResponseSendPluginCallable;\n\n public constructor(cb: IOnResponseSendPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public async exec<T = unknown>(\n request: FastifyRequest,\n reply: FastifyReply,\n payload: T\n ): Promise<unknown> {\n return await this.cb<T>(request, reply, payload);\n }\n}\n\n/**\n * @description Read info in the class file.\n */\nexport const createOnRequestResponseSend = (cb: IOnResponseSendPluginCallable) => {\n return new OnRequestResponseSendPlugin(cb);\n};\n"],"names":["OnRequestResponseSendPlugin","Plugin","cb","request","reply","payload","createOnRequestResponseSend"],"mappings":";AAkBO,MAAMA,oCAAoCC;;aACtB,IAAI,GAAW;;IAItC,YAAmBC,EAAiC,CAAE;QAClD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,MAAa,KACTC,OAAuB,EACvBC,KAAmB,EACnBC,OAAU,EACM;QAChB,OAAO,MAAM,IAAI,CAAC,EAAE,CAAIF,SAASC,OAAOC;IAC5C;AACJ;AAKO,MAAMC,8BAA8B,CAACJ,KACjC,IAAIF,4BAA4BE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import type { Reply as FastifyReply, Request as FastifyRequest } from "../types.js";
|
|
3
|
+
export interface IOnRequestTimeoutPluginCallable {
|
|
4
|
+
(request: FastifyRequest, reply: FastifyReply): Promise<unknown>;
|
|
5
|
+
}
|
|
6
|
+
export declare class OnRequestTimeoutPlugin extends Plugin {
|
|
7
|
+
static type: string;
|
|
8
|
+
private readonly cb;
|
|
9
|
+
constructor(cb: IOnRequestTimeoutPluginCallable);
|
|
10
|
+
exec(request: FastifyRequest, reply: FastifyReply): Promise<unknown>;
|
|
11
|
+
}
|
|
12
|
+
export declare const createOnRequestTimeout: (cb: IOnRequestTimeoutPluginCallable) => OnRequestTimeoutPlugin;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class OnRequestTimeoutPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.onRequestTimeout";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
10
|
+
async exec(request, reply) {
|
|
11
|
+
return await this.cb(request, reply);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
const createOnRequestTimeout = (cb)=>new OnRequestTimeoutPlugin(cb);
|
|
15
|
+
export { OnRequestTimeoutPlugin, createOnRequestTimeout };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=OnRequestTimeoutPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/OnRequestTimeoutPlugin.js","sources":["../../src/plugins/OnRequestTimeoutPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Reply as FastifyReply, Request as FastifyRequest } from \"~/types.js\";\n\nexport interface IOnRequestTimeoutPluginCallable {\n (request: FastifyRequest, reply: FastifyReply): Promise<unknown>;\n}\n\nexport class OnRequestTimeoutPlugin extends Plugin {\n public static override type: string = \"handler.onRequestTimeout\";\n\n private readonly cb: IOnRequestTimeoutPluginCallable;\n\n public constructor(cb: IOnRequestTimeoutPluginCallable) {\n super();\n this.cb = cb;\n }\n\n public async exec(request: FastifyRequest, reply: FastifyReply): Promise<unknown> {\n return await this.cb(request, reply);\n }\n}\n\nexport const createOnRequestTimeout = (cb: IOnRequestTimeoutPluginCallable) => {\n return new OnRequestTimeoutPlugin(cb);\n};\n"],"names":["OnRequestTimeoutPlugin","Plugin","cb","request","reply","createOnRequestTimeout"],"mappings":";AAOO,MAAMA,+BAA+BC;;aACjB,IAAI,GAAW;;IAItC,YAAmBC,EAAmC,CAAE;QACpD,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;IAEA,MAAa,KAAKC,OAAuB,EAAEC,KAAmB,EAAoB;QAC9E,OAAO,MAAM,IAAI,CAAC,EAAE,CAACD,SAASC;IAClC;AACJ;AAEO,MAAMC,yBAAyB,CAACH,KAC5B,IAAIF,uBAAuBE"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
import type { Context } from "../types.js";
|
|
3
|
+
export interface IRegisterExtensionPluginCb<C extends Context = Context> {
|
|
4
|
+
(context: C): Promise<void> | void;
|
|
5
|
+
}
|
|
6
|
+
export declare class RegisterExtensionPlugin<C extends Context = Context> extends Plugin {
|
|
7
|
+
private readonly cb;
|
|
8
|
+
static readonly type: string;
|
|
9
|
+
constructor(cb: IRegisterExtensionPluginCb<C>);
|
|
10
|
+
apply(context: C): Promise<void> | void;
|
|
11
|
+
}
|
|
12
|
+
export declare const createRegisterExtensionPlugin: <C extends Context = Context>(cb: IRegisterExtensionPluginCb<C>) => RegisterExtensionPlugin<C>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins";
|
|
2
|
+
class RegisterExtensionPlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.register.extension";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super(), this.cb = cb;
|
|
8
|
+
}
|
|
9
|
+
apply(context) {
|
|
10
|
+
return this.cb(context);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
const createRegisterExtensionPlugin = (cb)=>new RegisterExtensionPlugin(cb);
|
|
14
|
+
export { RegisterExtensionPlugin, createRegisterExtensionPlugin };
|
|
15
|
+
|
|
16
|
+
//# sourceMappingURL=RegisterExtensionPlugin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"plugins/RegisterExtensionPlugin.js","sources":["../../src/plugins/RegisterExtensionPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport type { Context } from \"~/types.js\";\n\nexport interface IRegisterExtensionPluginCb<C extends Context = Context> {\n (context: C): Promise<void> | void;\n}\n\nexport class RegisterExtensionPlugin<C extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler.register.extension\";\n\n public constructor(private readonly cb: IRegisterExtensionPluginCb<C>) {\n super();\n }\n\n public apply(context: C): Promise<void> | void {\n return this.cb(context);\n }\n}\n\nexport const createRegisterExtensionPlugin = <C extends Context = Context>(\n cb: IRegisterExtensionPluginCb<C>\n) => {\n return new RegisterExtensionPlugin<C>(cb);\n};\n"],"names":["RegisterExtensionPlugin","Plugin","cb","context","createRegisterExtensionPlugin"],"mappings":";AAOO,MAAMA,gCAA6DC;;aACtC,IAAI,GAAW;;IAE/C,YAAoCC,EAAiC,CAAE;QACnE,KAAK,SAD2BA,EAAE,GAAFA;IAEpC;IAEO,MAAMC,OAAU,EAAwB;QAC3C,OAAO,IAAI,CAAC,EAAE,CAACA;IACnB;AACJ;AAEO,MAAMC,gCAAgC,CACzCF,KAEO,IAAIF,wBAA2BE"}
|
package/plugins/RoutePlugin.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import { Context, RouteMethod } from "../types";
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
import type { Context, RouteMethod } from "../types.js";
|
|
3
3
|
interface RoutePluginCbParams<T extends Context> {
|
|
4
4
|
context: T;
|
|
5
5
|
onGet: RouteMethod;
|
package/plugins/RoutePlugin.js
CHANGED
|
@@ -1,22 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
class RoutePlugin extends _Plugin.Plugin {
|
|
11
|
-
constructor(cb) {
|
|
12
|
-
super();
|
|
13
|
-
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
14
|
-
this.cb = cb;
|
|
15
|
-
}
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
class RoutePlugin extends Plugin {
|
|
3
|
+
static{
|
|
4
|
+
this.type = "handler.fastify.route";
|
|
5
|
+
}
|
|
6
|
+
constructor(cb){
|
|
7
|
+
super();
|
|
8
|
+
this.cb = cb;
|
|
9
|
+
}
|
|
16
10
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
};
|
|
22
|
-
exports.createRoute = createRoute;
|
|
11
|
+
const createRoute = (cb)=>new RoutePlugin(cb);
|
|
12
|
+
export { RoutePlugin, createRoute };
|
|
13
|
+
|
|
14
|
+
//# sourceMappingURL=RoutePlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"plugins/RoutePlugin.js","sources":["../../src/plugins/RoutePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { Context, RouteMethod } from \"~/types.js\";\n\ninterface RoutePluginCbParams<T extends Context> {\n context: T;\n onGet: RouteMethod;\n onPost: RouteMethod;\n onPut: RouteMethod;\n onPatch: RouteMethod;\n onDelete: RouteMethod;\n onOptions: RouteMethod;\n onAll: RouteMethod;\n onHead: RouteMethod;\n}\nexport interface RoutePluginCb<T extends Context> {\n (params: RoutePluginCbParams<T>): void;\n}\n\nexport class RoutePlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler.fastify.route\";\n\n public readonly cb: RoutePluginCb<T>;\n\n public constructor(cb: RoutePluginCb<T>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createRoute = <T extends Context = Context>(cb: RoutePluginCb<T>): RoutePlugin<T> => {\n return new RoutePlugin<T>(cb);\n};\n"],"names":["RoutePlugin","Plugin","cb","createRoute"],"mappings":";AAkBO,MAAMA,oBAAiDC;;aAC1B,IAAI,GAAW;;IAI/C,YAAmBC,EAAoB,CAAE;QACrC,KAAK;QACL,IAAI,CAAC,EAAE,GAAGA;IACd;AACJ;AAEO,MAAMC,cAAc,CAA8BD,KAC9C,IAAIF,YAAeE"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
const stringifyError = (error)=>{
|
|
2
|
+
const { name, message, code, stack, data } = error;
|
|
3
|
+
return JSON.stringify({
|
|
4
|
+
...error,
|
|
5
|
+
constructorName: error.constructor?.name || "UnknownError",
|
|
6
|
+
name: name || "No error name",
|
|
7
|
+
message: message || "No error message",
|
|
8
|
+
code: code || "NO_CODE",
|
|
9
|
+
data,
|
|
10
|
+
stack: "true" === process.env.DEBUG ? stack : "Turn on the debug flag to see the stack."
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
export { stringifyError };
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=stringifyError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stringifyError.js","sources":["../src/stringifyError.ts"],"sourcesContent":["export interface CustomError extends Error {\n code?: string;\n data?: Record<string, any>;\n}\n\nexport const stringifyError = (error: CustomError) => {\n const { name, message, code, stack, data } = error;\n return JSON.stringify({\n ...error,\n constructorName: error.constructor?.name || \"UnknownError\",\n name: name || \"No error name\",\n message: message || \"No error message\",\n code: code || \"NO_CODE\",\n data,\n stack: process.env.DEBUG === \"true\" ? stack : \"Turn on the debug flag to see the stack.\"\n });\n};\n"],"names":["stringifyError","error","name","message","code","stack","data","JSON","process"],"mappings":"AAKO,MAAMA,iBAAiB,CAACC;IAC3B,MAAM,EAAEC,IAAI,EAAEC,OAAO,EAAEC,IAAI,EAAEC,KAAK,EAAEC,IAAI,EAAE,GAAGL;IAC7C,OAAOM,KAAK,SAAS,CAAC;QAClB,GAAGN,KAAK;QACR,iBAAiBA,MAAM,WAAW,EAAE,QAAQ;QAC5C,MAAMC,QAAQ;QACd,SAASC,WAAW;QACpB,MAAMC,QAAQ;QACdE;QACA,OAAOE,AAAsB,WAAtBA,QAAQ,GAAG,CAAC,KAAK,GAAcH,QAAQ;IAClD;AACJ"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
const originalConsoleError = console.error;
|
|
2
|
+
console.error = (message, ...args)=>{
|
|
3
|
+
if ("string" == typeof message && message.includes("punycode")) return;
|
|
4
|
+
originalConsoleError.call(console, message, ...args);
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
//# sourceMappingURL=suppressPunycodeWarnings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"suppressPunycodeWarnings.js","sources":["../src/suppressPunycodeWarnings.ts"],"sourcesContent":["const originalConsoleError = console.error;\nconsole.error = (message, ...args) => {\n if (typeof message === \"string\" && message.includes(\"punycode\")) {\n return;\n }\n originalConsoleError.call(console, message, ...args);\n};\n\nexport {};\n"],"names":["originalConsoleError","console","message","args"],"mappings":"AAAA,MAAMA,uBAAuBC,QAAQ,KAAK;AAC1CA,QAAQ,KAAK,GAAG,CAACC,SAAS,GAAGC;IACzB,IAAI,AAAmB,YAAnB,OAAOD,WAAwBA,QAAQ,QAAQ,CAAC,aAChD;IAEJF,qBAAqB,IAAI,CAACC,SAASC,YAAYC;AACnD"}
|
package/types.d.ts
CHANGED
|
@@ -1,16 +1,18 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
import "@fastify/cookie";
|
|
2
|
+
import type { FastifyRequest, FastifyReply, HTTPMethods as BaseHttpMethods, RouteHandlerMethod } from "fastify";
|
|
3
|
+
export type { FastifyInstance } from "fastify";
|
|
4
|
+
import type { Context as BaseContext } from "@webiny/api/types.js";
|
|
4
5
|
export interface RouteMethodOptions {
|
|
5
6
|
override?: boolean;
|
|
6
7
|
}
|
|
7
|
-
export
|
|
8
|
+
export type RouteMethodPath = `/${string}` | "*";
|
|
8
9
|
export interface RouteMethod {
|
|
9
10
|
(path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;
|
|
10
11
|
}
|
|
11
|
-
export
|
|
12
|
-
export
|
|
13
|
-
export
|
|
12
|
+
export type Request = FastifyRequest;
|
|
13
|
+
export type Reply = FastifyReply;
|
|
14
|
+
export type HTTPMethods = Uppercase<BaseHttpMethods>;
|
|
15
|
+
export type DefinedContextRoutes = Record<HTTPMethods, string[]>;
|
|
14
16
|
export interface ContextRoutes {
|
|
15
17
|
defined: DefinedContextRoutes;
|
|
16
18
|
onGet: RouteMethod;
|
|
@@ -22,13 +24,7 @@ export interface ContextRoutes {
|
|
|
22
24
|
onAll: RouteMethod;
|
|
23
25
|
onHead: RouteMethod;
|
|
24
26
|
}
|
|
25
|
-
export interface Context extends
|
|
26
|
-
/**
|
|
27
|
-
* An instance of fastify server.
|
|
28
|
-
* Use at your own risk.
|
|
29
|
-
* @instance
|
|
30
|
-
*/
|
|
31
|
-
server: FastifyInstance;
|
|
27
|
+
export interface Context extends BaseContext {
|
|
32
28
|
/**
|
|
33
29
|
* Current request. Must be set only once!
|
|
34
30
|
*/
|
|
@@ -45,5 +41,6 @@ export interface Context extends ClientContext {
|
|
|
45
41
|
declare module "fastify" {
|
|
46
42
|
interface FastifyInstance {
|
|
47
43
|
webiny: Context;
|
|
44
|
+
__webiny_raw_result: any;
|
|
48
45
|
}
|
|
49
46
|
}
|
package/types.js
CHANGED
|
@@ -1,18 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "FastifyInstance", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _fastify.FastifyInstance;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "HTTPMethods", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _fastify.HTTPMethods;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
var _fastify = require("fastify");
|
|
1
|
+
import "@fastify/cookie";
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"~/fastify\";\nexport * from \"~/Context\";\nexport * from \"~/plugins/EventPlugin\";\nexport * from \"~/plugins/RoutePlugin\";\nexport * from \"~/plugins/BeforeHandlerPlugin\";\nexport * from \"~/plugins/HandlerErrorPlugin\";\nexport * from \"~/plugins/HandlerResultPlugin\";\nexport * from \"~/plugins/HandlerOnRequestPlugin\";\nexport * from \"~/plugins/ModifyFastifyPlugin\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/middleware.d.ts
DELETED
package/middleware.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.middleware = void 0;
|
|
7
|
-
/**
|
|
8
|
-
* Compose a single middleware from the array of middleware functions
|
|
9
|
-
*/
|
|
10
|
-
const middleware = (functions = []) => {
|
|
11
|
-
return (...args) => {
|
|
12
|
-
if (!functions.length) {
|
|
13
|
-
return Promise.resolve();
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Create a clone of function chain to prevent modifying the original array with `shift()`
|
|
17
|
-
const chain = [...functions];
|
|
18
|
-
return new Promise((parentResolve, parentReject) => {
|
|
19
|
-
const next = async () => {
|
|
20
|
-
const fn = chain.shift();
|
|
21
|
-
if (!fn) {
|
|
22
|
-
return Promise.resolve();
|
|
23
|
-
}
|
|
24
|
-
return new Promise(async (resolve, reject) => {
|
|
25
|
-
try {
|
|
26
|
-
const result = await fn(...args, resolve);
|
|
27
|
-
if (typeof result !== "undefined") {
|
|
28
|
-
return parentResolve(result);
|
|
29
|
-
}
|
|
30
|
-
} catch (e) {
|
|
31
|
-
reject(e);
|
|
32
|
-
}
|
|
33
|
-
}).then(() => {
|
|
34
|
-
return next();
|
|
35
|
-
}).then(() => {
|
|
36
|
-
parentResolve(...args);
|
|
37
|
-
}).catch(e => {
|
|
38
|
-
parentReject(e);
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
return next();
|
|
42
|
-
});
|
|
43
|
-
};
|
|
44
|
-
};
|
|
45
|
-
exports.middleware = middleware;
|
package/middleware.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["middleware","functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"sources":["middleware.ts"],"sourcesContent":["/**\n * Compose a single middleware from the array of middleware functions\n */\nexport const middleware = (functions: Function[] = []): Function => {\n return (...args: string[]): Promise<any> => {\n if (!functions.length) {\n return Promise.resolve();\n }\n\n // Create a clone of function chain to prevent modifying the original array with `shift()`\n const chain = [...functions];\n return new Promise((parentResolve: any, parentReject) => {\n const next = async (): Promise<any> => {\n const fn = chain.shift();\n if (!fn) {\n return Promise.resolve();\n }\n\n return new Promise(async (resolve, reject) => {\n try {\n const result = await fn(...args, resolve);\n if (typeof result !== \"undefined\") {\n return parentResolve(result);\n }\n } catch (e) {\n reject(e);\n }\n })\n .then(() => {\n return next();\n })\n .then(() => {\n parentResolve(...args);\n })\n .catch(e => {\n parentReject(e);\n });\n };\n\n return next();\n });\n };\n};\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACO,MAAMA,UAAU,GAAG,CAACC,SAAqB,GAAG,EAAE,KAAe;EAChE,OAAO,CAAC,GAAGC,IAAc,KAAmB;IACxC,IAAI,CAACD,SAAS,CAACE,MAAM,EAAE;MACnB,OAAOC,OAAO,CAACC,OAAO,EAAE;IAC5B;;IAEA;IACA,MAAMC,KAAK,GAAG,CAAC,GAAGL,SAAS,CAAC;IAC5B,OAAO,IAAIG,OAAO,CAAC,CAACG,aAAkB,EAAEC,YAAY,KAAK;MACrD,MAAMC,IAAI,GAAG,YAA0B;QACnC,MAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAK,EAAE;QACxB,IAAI,CAACD,EAAE,EAAE;UACL,OAAON,OAAO,CAACC,OAAO,EAAE;QAC5B;QAEA,OAAO,IAAID,OAAO,CAAC,OAAOC,OAAO,EAAEO,MAAM,KAAK;UAC1C,IAAI;YACA,MAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAI,EAAEG,OAAO,CAAC;YACzC,IAAI,OAAOQ,MAAM,KAAK,WAAW,EAAE;cAC/B,OAAON,aAAa,CAACM,MAAM,CAAC;YAChC;UACJ,CAAC,CAAC,OAAOC,CAAC,EAAE;YACRF,MAAM,CAACE,CAAC,CAAC;UACb;QACJ,CAAC,CAAC,CACGC,IAAI,CAAC,MAAM;UACR,OAAON,IAAI,EAAE;QACjB,CAAC,CAAC,CACDM,IAAI,CAAC,MAAM;UACRR,aAAa,CAAC,GAAGL,IAAI,CAAC;QAC1B,CAAC,CAAC,CACDc,KAAK,CAACF,CAAC,IAAI;UACRN,YAAY,CAACM,CAAC,CAAC;QACnB,CAAC,CAAC;MACV,CAAC;MAED,OAAOL,IAAI,EAAE;IACjB,CAAC,CAAC;EACN,CAAC;AACL,CAAC;AAAC"}
|