@webiny/handler 5.30.0 → 5.31.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/Context.d.ts +13 -0
- package/Context.js +29 -0
- package/Context.js.map +1 -0
- package/README.md +8 -2
- package/fastify.d.ts +8 -0
- package/fastify.js +312 -0
- package/fastify.js.map +1 -0
- package/index.d.ts +6 -5
- package/index.js +43 -36
- package/index.js.map +1 -1
- package/middleware.d.ts +1 -2
- package/middleware.js +3 -3
- package/middleware.js.map +1 -1
- package/package.json +18 -11
- package/plugins/BeforeHandlerPlugin.d.ts +1 -0
- package/plugins/BeforeHandlerPlugin.js +8 -2
- package/plugins/BeforeHandlerPlugin.js.map +1 -1
- package/plugins/EventPlugin.d.ts +25 -0
- package/plugins/EventPlugin.js +38 -0
- package/plugins/EventPlugin.js.map +1 -0
- package/plugins/HandlerErrorPlugin.d.ts +1 -0
- package/plugins/HandlerErrorPlugin.js +8 -2
- package/plugins/HandlerErrorPlugin.js.map +1 -1
- package/plugins/HandlerResultPlugin.d.ts +1 -0
- package/plugins/HandlerResultPlugin.js +8 -2
- package/plugins/HandlerResultPlugin.js.map +1 -1
- package/plugins/RoutePlugin.d.ts +23 -0
- package/plugins/RoutePlugin.js +30 -0
- package/plugins/RoutePlugin.js.map +1 -0
- package/types.d.ts +38 -71
- package/types.js +15 -1
- package/types.js.map +1 -1
- package/createHandler.d.ts +0 -3
- package/createHandler.js +0 -105
- package/createHandler.js.map +0 -1
- package/plugins/Context.d.ts +0 -20
- package/plugins/Context.js +0 -151
- package/plugins/Context.js.map +0 -1
- package/plugins/ContextPlugin.d.ts +0 -11
- package/plugins/ContextPlugin.js +0 -32
- package/plugins/ContextPlugin.js.map +0 -1
- package/plugins/HandlerPlugin.d.ts +0 -11
- package/plugins/HandlerPlugin.js +0 -28
- package/plugins/HandlerPlugin.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,28 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.31.0",
|
|
4
4
|
"main": "index.js",
|
|
5
|
-
"license": "MIT",
|
|
6
5
|
"repository": {
|
|
7
6
|
"type": "git",
|
|
8
7
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
9
8
|
},
|
|
10
|
-
"description": "
|
|
9
|
+
"description": "Our small wrapper around fastify to ease handling of http requests for the system.",
|
|
11
10
|
"contributors": [
|
|
12
|
-
"
|
|
13
|
-
"Sven Al Hamad <sven@webiny.com>",
|
|
14
|
-
"Adrian Smijulj <adrian@webiny.com>"
|
|
11
|
+
"Bruno Zorić <bruno@webiny.com>"
|
|
15
12
|
],
|
|
13
|
+
"license": "MIT",
|
|
16
14
|
"dependencies": {
|
|
17
|
-
"@babel/runtime": "7.18.
|
|
18
|
-
"@
|
|
15
|
+
"@babel/runtime": "7.18.9",
|
|
16
|
+
"@fastify/cookie": "7.3.1",
|
|
17
|
+
"@webiny/api": "5.31.0",
|
|
18
|
+
"@webiny/error": "5.31.0",
|
|
19
|
+
"@webiny/handler-client": "5.31.0",
|
|
20
|
+
"@webiny/plugins": "5.31.0",
|
|
21
|
+
"@webiny/utils": "5.31.0",
|
|
22
|
+
"fastify": "4.3.0"
|
|
19
23
|
},
|
|
20
24
|
"devDependencies": {
|
|
21
25
|
"@babel/cli": "^7.16.0",
|
|
22
26
|
"@babel/core": "^7.16.0",
|
|
23
27
|
"@babel/preset-env": "^7.16.4",
|
|
24
|
-
"@
|
|
25
|
-
"@webiny/
|
|
28
|
+
"@babel/preset-typescript": "^7.16.0",
|
|
29
|
+
"@webiny/cli": "^5.31.0",
|
|
30
|
+
"@webiny/project-utils": "^5.31.0",
|
|
31
|
+
"babel-plugin-lodash": "^3.3.4",
|
|
32
|
+
"merge": "^1.2.1",
|
|
26
33
|
"rimraf": "^3.0.2",
|
|
27
34
|
"ttypescript": "^1.5.13",
|
|
28
35
|
"typescript": "4.7.4"
|
|
@@ -35,5 +42,5 @@
|
|
|
35
42
|
"build": "yarn webiny run build",
|
|
36
43
|
"watch": "yarn webiny run watch"
|
|
37
44
|
},
|
|
38
|
-
"gitHead": "
|
|
45
|
+
"gitHead": "0b3fa2ace7f258628438aa993d782fb562a64358"
|
|
39
46
|
}
|
|
@@ -9,3 +9,4 @@ export declare class BeforeHandlerPlugin<T extends Context = Context> extends Pl
|
|
|
9
9
|
constructor(callable: BeforeHandlerCallable<T>);
|
|
10
10
|
apply(context: T): Promise<void>;
|
|
11
11
|
}
|
|
12
|
+
export declare const createBeforeHandlerPlugin: <T extends Context = Context>(callable: BeforeHandlerCallable<T>) => BeforeHandlerPlugin<T>;
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.BeforeHandlerPlugin = void 0;
|
|
8
|
+
exports.createBeforeHandlerPlugin = exports.BeforeHandlerPlugin = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
@@ -29,4 +29,10 @@ class BeforeHandlerPlugin extends _plugins.Plugin {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
exports.BeforeHandlerPlugin = BeforeHandlerPlugin;
|
|
32
|
-
(0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
|
|
32
|
+
(0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
|
|
33
|
+
|
|
34
|
+
const createBeforeHandlerPlugin = callable => {
|
|
35
|
+
return new BeforeHandlerPlugin(callable);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.createBeforeHandlerPlugin = createBeforeHandlerPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error"],"sources":["BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAIzEC,WAAW,CAACC,QAAD,EAAqC;IAC5C;IAD4C;IAE5C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEiB,MAALE,KAAK,CAACC,OAAD,EAA4B;IAC1C,IAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;MACtC,MAAMG,KAAK,CACN,6IADM,CAAX;IAGH;;IAED,OAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;EACH;;AAjBwE;;;8BAAhEN,mB,UACsC,gB"}
|
|
1
|
+
{"version":3,"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error","createBeforeHandlerPlugin"],"sources":["BeforeHandlerPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface BeforeHandlerCallable<T extends Context = Context> {\n (context: T): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"before-handler\";\n private readonly _callable: BeforeHandlerCallable<T>;\n\n constructor(callable: BeforeHandlerCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async apply(context: T): Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in BeforeHandlerPlugin! Either pass a callable to plugin constructor or extend the plugin and override the \"apply\" method.`\n );\n }\n\n return this._callable(context);\n }\n}\n\nexport const createBeforeHandlerPlugin = <T extends Context = Context>(\n callable: BeforeHandlerCallable<T>\n): BeforeHandlerPlugin<T> => {\n return new BeforeHandlerPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAIzEC,WAAW,CAACC,QAAD,EAAqC;IAC5C;IAD4C;IAE5C,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEiB,MAALE,KAAK,CAACC,OAAD,EAA4B;IAC1C,IAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;MACtC,MAAMG,KAAK,CACN,6IADM,CAAX;IAGH;;IAED,OAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;EACH;;AAjBwE;;;8BAAhEN,mB,UACsC,gB;;AAmB5C,MAAMQ,yBAAyB,GAClCL,QADqC,IAEZ;EACzB,OAAO,IAAIH,mBAAJ,CAA2BG,QAA3B,CAAP;AACH,CAJM"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EventPlugin must be handled in the package which implements fastify for certain cloud.
|
|
3
|
+
* There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
|
|
4
|
+
* to be sorted out in the implementation package.
|
|
5
|
+
*
|
|
6
|
+
* Note that only one EventPlugin can be defined per fastify initialisation.
|
|
7
|
+
* If more is needed, check ~/fastify.ts and implement that possibility.
|
|
8
|
+
*/
|
|
9
|
+
import { Plugin } from "@webiny/plugins/Plugin";
|
|
10
|
+
import { Request, Context as BaseContext, Reply } from "../types";
|
|
11
|
+
export interface EventPluginCallableParams<Payload, Context extends BaseContext> {
|
|
12
|
+
context: Context;
|
|
13
|
+
payload: Payload;
|
|
14
|
+
request: Request;
|
|
15
|
+
reply: Reply;
|
|
16
|
+
}
|
|
17
|
+
export interface EventPluginCallable<Payload, Context extends BaseContext, Response> {
|
|
18
|
+
(params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;
|
|
19
|
+
}
|
|
20
|
+
export declare class EventPlugin<Payload = any, Context extends BaseContext = BaseContext, Response = any> extends Plugin {
|
|
21
|
+
static type: string;
|
|
22
|
+
readonly cb: EventPluginCallable<Payload, Context, Response>;
|
|
23
|
+
constructor(cb: EventPluginCallable<Payload, Context, Response>);
|
|
24
|
+
}
|
|
25
|
+
export declare const createEvent: <Payload = any, Context extends BaseContext = BaseContext, Response_1 = any>(cb: EventPluginCallable<Payload, Context, Response_1>) => EventPlugin<Payload, Context, Response_1>;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createEvent = exports.EventPlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* EventPlugin must be handled in the package which implements fastify for certain cloud.
|
|
16
|
+
* There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that
|
|
17
|
+
* to be sorted out in the implementation package.
|
|
18
|
+
*
|
|
19
|
+
* Note that only one EventPlugin can be defined per fastify initialisation.
|
|
20
|
+
* If more is needed, check ~/fastify.ts and implement that possibility.
|
|
21
|
+
*/
|
|
22
|
+
class EventPlugin extends _Plugin.Plugin {
|
|
23
|
+
constructor(cb) {
|
|
24
|
+
super();
|
|
25
|
+
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
26
|
+
this.cb = cb;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
exports.EventPlugin = EventPlugin;
|
|
32
|
+
(0, _defineProperty2.default)(EventPlugin, "type", "handler.fastify.event");
|
|
33
|
+
|
|
34
|
+
const createEvent = cb => {
|
|
35
|
+
return new EventPlugin(cb);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
exports.createEvent = createEvent;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["EventPlugin","Plugin","constructor","cb","createEvent"],"sources":["EventPlugin.ts"],"sourcesContent":["/**\n * EventPlugin must be handled in the package which implements fastify for certain cloud.\n * There is no standard input for AWS Lambda, Google Cloud Functions and MS Azure Functions so we let that\n * to be sorted out in the implementation package.\n *\n * Note that only one EventPlugin can be defined per fastify initialisation.\n * If more is needed, check ~/fastify.ts and implement that possibility.\n */\nimport { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Request, Context as BaseContext, Reply } from \"~/types\";\n\nexport interface EventPluginCallableParams<Payload, Context extends BaseContext> {\n context: Context;\n payload: Payload;\n request: Request;\n reply: Reply;\n}\n\nexport interface EventPluginCallable<Payload, Context extends BaseContext, Response> {\n (params: EventPluginCallableParams<Payload, Context>): Promise<Response | Reply>;\n}\n\nexport class EventPlugin<\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n> extends Plugin {\n public static override type = \"handler.fastify.event\";\n\n public readonly cb: EventPluginCallable<Payload, Context, Response>;\n\n public constructor(cb: EventPluginCallable<Payload, Context, Response>) {\n super();\n this.cb = cb;\n }\n}\n\nexport const createEvent = <\n Payload = any,\n Context extends BaseContext = BaseContext,\n Response = any\n>(\n cb: EventPluginCallable<Payload, Context, Response>\n) => {\n return new EventPlugin<Payload, Context, Response>(cb);\n};\n"],"mappings":";;;;;;;;;;;AAQA;;AARA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAeO,MAAMA,WAAN,SAIGC,cAJH,CAIU;EAKNC,WAAW,CAACC,EAAD,EAAsD;IACpE;IADoE;IAEpE,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARY;;;8BAJJH,W,UAKqB,uB;;AAU3B,MAAMI,WAAW,GAKpBD,EALuB,IAMtB;EACD,OAAO,IAAIH,WAAJ,CAA4CG,EAA5C,CAAP;AACH,CARM"}
|
|
@@ -9,3 +9,4 @@ export declare class HandlerErrorPlugin<T extends Context = Context> extends Plu
|
|
|
9
9
|
constructor(callable: HandlerErrorCallable<T>);
|
|
10
10
|
handle(context: T, error: Error, next: Function): Promise<any>;
|
|
11
11
|
}
|
|
12
|
+
export declare const createHandlerErrorPlugin: <T extends Context = Context>(callable: HandlerErrorCallable<T>) => HandlerErrorPlugin<T>;
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.HandlerErrorPlugin = void 0;
|
|
8
|
+
exports.createHandlerErrorPlugin = exports.HandlerErrorPlugin = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
@@ -25,4 +25,10 @@ class HandlerErrorPlugin extends _plugins.Plugin {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
exports.HandlerErrorPlugin = HandlerErrorPlugin;
|
|
28
|
-
(0, _defineProperty2.default)(HandlerErrorPlugin, "type", "handler-error");
|
|
28
|
+
(0, _defineProperty2.default)(HandlerErrorPlugin, "type", "handler-error");
|
|
29
|
+
|
|
30
|
+
const createHandlerErrorPlugin = callable => {
|
|
31
|
+
return new HandlerErrorPlugin(callable);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.createHandlerErrorPlugin = createHandlerErrorPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next"],"sources":["HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: Function): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: Function): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,kBAAN,SAA8DC,eAA9D,CAAqE;EAKjEC,WAAW,CAACC,QAAD,EAAoC;IAClD;IADkD;IAElD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,KAAb,EAA2BC,IAA3B,EAAyD;IACxE,OAAO,KAAKJ,SAAL,CAAeE,OAAf,EAAwBC,KAAxB,EAA+BC,IAA/B,CAAP;EACH;;AAZuE;;;8BAA/DR,kB,UACsC,e"}
|
|
1
|
+
{"version":3,"names":["HandlerErrorPlugin","Plugin","constructor","callable","_callable","handle","context","error","next","createHandlerErrorPlugin"],"sources":["HandlerErrorPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\n\nexport interface HandlerErrorCallable<T extends Context = Context> {\n (context: T, error: Error, next: Function): Promise<any>;\n}\n\nexport class HandlerErrorPlugin<T extends Context = Context> extends Plugin {\n public static override readonly type: string = \"handler-error\";\n\n private readonly _callable: HandlerErrorCallable<T>;\n\n public constructor(callable: HandlerErrorCallable<T>) {\n super();\n this._callable = callable;\n }\n\n public async handle(context: T, error: Error, next: Function): Promise<any> {\n return this._callable(context, error, next);\n }\n}\n\nexport const createHandlerErrorPlugin = <T extends Context = Context>(\n callable: HandlerErrorCallable<T>\n): HandlerErrorPlugin<T> => {\n return new HandlerErrorPlugin<T>(callable);\n};\n"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,kBAAN,SAA8DC,eAA9D,CAAqE;EAKjEC,WAAW,CAACC,QAAD,EAAoC;IAClD;IADkD;IAElD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,KAAb,EAA2BC,IAA3B,EAAyD;IACxE,OAAO,KAAKJ,SAAL,CAAeE,OAAf,EAAwBC,KAAxB,EAA+BC,IAA/B,CAAP;EACH;;AAZuE;;;8BAA/DR,kB,UACsC,e;;AAc5C,MAAMS,wBAAwB,GACjCN,QADoC,IAEZ;EACxB,OAAO,IAAIH,kBAAJ,CAA0BG,QAA1B,CAAP;AACH,CAJM"}
|
|
@@ -9,3 +9,4 @@ export declare class HandlerResultPlugin<T extends Context = Context> extends Pl
|
|
|
9
9
|
constructor(callable: HandlerResultCallable<T>);
|
|
10
10
|
handle(context: T, result: any): Promise<any>;
|
|
11
11
|
}
|
|
12
|
+
export declare const createHandlerResultPlugin: <T extends Context = Context>(callable: HandlerResultCallable<T>) => HandlerResultPlugin<T>;
|
|
@@ -5,7 +5,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", {
|
|
6
6
|
value: true
|
|
7
7
|
});
|
|
8
|
-
exports.HandlerResultPlugin = void 0;
|
|
8
|
+
exports.createHandlerResultPlugin = exports.HandlerResultPlugin = void 0;
|
|
9
9
|
|
|
10
10
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
11
|
|
|
@@ -25,4 +25,10 @@ class HandlerResultPlugin extends _plugins.Plugin {
|
|
|
25
25
|
}
|
|
26
26
|
|
|
27
27
|
exports.HandlerResultPlugin = HandlerResultPlugin;
|
|
28
|
-
(0, _defineProperty2.default)(HandlerResultPlugin, "type", "handler-result");
|
|
28
|
+
(0, _defineProperty2.default)(HandlerResultPlugin, "type", "handler-result");
|
|
29
|
+
|
|
30
|
+
const createHandlerResultPlugin = callable => {
|
|
31
|
+
return new HandlerResultPlugin(callable);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
exports.createHandlerResultPlugin = createHandlerResultPlugin;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["HandlerResultPlugin","Plugin","constructor","callable","_callable","handle","context","result"],"sources":["HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\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"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAKlEC,WAAW,CAACC,QAAD,EAAqC;IACnD;IADmD;IAEnD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,MAAb,EAAwC;IACvD,OAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,MAAxB,CAAP;EACH;;AAZwE;;;8BAAhEP,mB,UACsC,gB"}
|
|
1
|
+
{"version":3,"names":["HandlerResultPlugin","Plugin","constructor","callable","_callable","handle","context","result","createHandlerResultPlugin"],"sources":["HandlerResultPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins\";\nimport { Context } from \"~/types\";\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"],"mappings":";;;;;;;;;;;AAAA;;AAOO,MAAMA,mBAAN,SAA+DC,eAA/D,CAAsE;EAKlEC,WAAW,CAACC,QAAD,EAAqC;IACnD;IADmD;IAEnD,KAAKC,SAAL,GAAiBD,QAAjB;EACH;;EAEkB,MAANE,MAAM,CAACC,OAAD,EAAaC,MAAb,EAAwC;IACvD,OAAO,KAAKH,SAAL,CAAeE,OAAf,EAAwBC,MAAxB,CAAP;EACH;;AAZwE;;;8BAAhEP,mB,UACsC,gB;;AAc5C,MAAMQ,yBAAyB,GAClCL,QADqC,IAEZ;EACzB,OAAO,IAAIH,mBAAJ,CAA2BG,QAA3B,CAAP;AACH,CAJM"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
+
import { Context, RouteMethod } from "../types";
|
|
3
|
+
interface RoutePluginCbParams<T extends Context> {
|
|
4
|
+
context: T;
|
|
5
|
+
onGet: RouteMethod;
|
|
6
|
+
onPost: RouteMethod;
|
|
7
|
+
onPut: RouteMethod;
|
|
8
|
+
onPatch: RouteMethod;
|
|
9
|
+
onDelete: RouteMethod;
|
|
10
|
+
onOptions: RouteMethod;
|
|
11
|
+
onAll: RouteMethod;
|
|
12
|
+
onHead: RouteMethod;
|
|
13
|
+
}
|
|
14
|
+
export interface RoutePluginCb<T extends Context> {
|
|
15
|
+
(params: RoutePluginCbParams<T>): void;
|
|
16
|
+
}
|
|
17
|
+
export declare class RoutePlugin<T extends Context = Context> extends Plugin {
|
|
18
|
+
static readonly type: string;
|
|
19
|
+
readonly cb: RoutePluginCb<T>;
|
|
20
|
+
constructor(cb: RoutePluginCb<T>);
|
|
21
|
+
}
|
|
22
|
+
export declare const createRoute: <T extends Context = Context>(cb: RoutePluginCb<T>) => RoutePlugin<T>;
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.createRoute = exports.RoutePlugin = void 0;
|
|
9
|
+
|
|
10
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
11
|
+
|
|
12
|
+
var _Plugin = require("@webiny/plugins/Plugin");
|
|
13
|
+
|
|
14
|
+
class RoutePlugin extends _Plugin.Plugin {
|
|
15
|
+
constructor(cb) {
|
|
16
|
+
super();
|
|
17
|
+
(0, _defineProperty2.default)(this, "cb", void 0);
|
|
18
|
+
this.cb = cb;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.RoutePlugin = RoutePlugin;
|
|
24
|
+
(0, _defineProperty2.default)(RoutePlugin, "type", "handler.fastify.route");
|
|
25
|
+
|
|
26
|
+
const createRoute = cb => {
|
|
27
|
+
return new RoutePlugin(cb);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
exports.createRoute = createRoute;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["RoutePlugin","Plugin","constructor","cb","createRoute"],"sources":["RoutePlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin\";\nimport { Context, RouteMethod } from \"~/types\";\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"],"mappings":";;;;;;;;;;;AAAA;;AAkBO,MAAMA,WAAN,SAAuDC,cAAvD,CAA8D;EAK1DC,WAAW,CAACC,EAAD,EAAuB;IACrC;IADqC;IAErC,KAAKA,EAAL,GAAUA,EAAV;EACH;;AARgE;;;8BAAxDH,W,UACsC,uB;;AAU5C,MAAMI,WAAW,GAAiCD,EAA9B,IAAuE;EAC9F,OAAO,IAAIH,WAAJ,CAAmBG,EAAnB,CAAP;AACH,CAFM"}
|
package/types.d.ts
CHANGED
|
@@ -1,79 +1,46 @@
|
|
|
1
|
-
import {
|
|
2
|
-
export
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
import { FastifyInstance, FastifyRequest, FastifyReply, HTTPMethods, RouteHandlerMethod } from "fastify";
|
|
2
|
+
export { FastifyInstance, HTTPMethods } from "fastify";
|
|
3
|
+
import { ClientContext } from "@webiny/handler-client/types";
|
|
4
|
+
export declare type RouteTypes = HTTPMethods;
|
|
5
|
+
export interface RouteMethodOptions {
|
|
6
|
+
override?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare type RouteMethodPath = `/${string}` | "*";
|
|
9
|
+
export interface RouteMethod {
|
|
10
|
+
(path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;
|
|
11
|
+
}
|
|
12
|
+
export declare type Request = FastifyRequest;
|
|
13
|
+
export declare type Reply = FastifyReply;
|
|
14
|
+
export declare type DefinedContextRoutes = Record<RouteTypes, string[]>;
|
|
15
|
+
export interface ContextRoutes {
|
|
16
|
+
defined: DefinedContextRoutes;
|
|
17
|
+
onGet: RouteMethod;
|
|
18
|
+
onPost: RouteMethod;
|
|
19
|
+
onPut: RouteMethod;
|
|
20
|
+
onPatch: RouteMethod;
|
|
21
|
+
onDelete: RouteMethod;
|
|
22
|
+
onOptions: RouteMethod;
|
|
23
|
+
onAll: RouteMethod;
|
|
24
|
+
onHead: RouteMethod;
|
|
25
|
+
}
|
|
26
|
+
export interface Context extends ClientContext {
|
|
16
27
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
28
|
+
* An instance of fastify server.
|
|
29
|
+
* Use at your own risk.
|
|
30
|
+
* @instance
|
|
19
31
|
*/
|
|
20
|
-
|
|
32
|
+
server: FastifyInstance;
|
|
21
33
|
/**
|
|
22
|
-
*
|
|
23
|
-
* @internal
|
|
24
|
-
*
|
|
25
|
-
* @private
|
|
34
|
+
* Current request. Must be set only once!
|
|
26
35
|
*/
|
|
27
|
-
|
|
36
|
+
request: FastifyRequest;
|
|
28
37
|
/**
|
|
29
|
-
* Not to be used outside of Webiny internal code.
|
|
30
38
|
* @internal
|
|
31
39
|
*/
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Wait for property to be defined on the object and then execute the callable.
|
|
40
|
-
* In case of multiple objects defined, wait for all of them.
|
|
41
|
-
*/
|
|
42
|
-
waitFor: <T extends Context = Context>(obj: string[] | string, cb: (context: T) => void) => void;
|
|
40
|
+
routes: ContextRoutes;
|
|
41
|
+
}
|
|
42
|
+
declare module "fastify" {
|
|
43
|
+
interface FastifyInstance {
|
|
44
|
+
webiny: Context;
|
|
45
|
+
}
|
|
43
46
|
}
|
|
44
|
-
/**
|
|
45
|
-
* Left for backwards-compatibility.
|
|
46
|
-
*
|
|
47
|
-
* @deprecated
|
|
48
|
-
*/
|
|
49
|
-
export declare type ContextPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
|
|
50
|
-
type: "context";
|
|
51
|
-
apply(context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9): Promise<void>;
|
|
52
|
-
};
|
|
53
|
-
/**
|
|
54
|
-
* Left for backwards-compatibility.
|
|
55
|
-
*
|
|
56
|
-
* @deprecated
|
|
57
|
-
*/
|
|
58
|
-
export declare type HandlerPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
|
|
59
|
-
type: "handler";
|
|
60
|
-
handle(context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9, next: () => Promise<void>): any;
|
|
61
|
-
};
|
|
62
|
-
/**
|
|
63
|
-
* Left for backwards-compatibility.
|
|
64
|
-
*
|
|
65
|
-
* @deprecated
|
|
66
|
-
*/
|
|
67
|
-
export declare type HandlerResultPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
|
|
68
|
-
type: "handler-result";
|
|
69
|
-
handle(context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9, result: any): any;
|
|
70
|
-
};
|
|
71
|
-
/**
|
|
72
|
-
* Left for backwards-compatibility.
|
|
73
|
-
*
|
|
74
|
-
* @deprecated
|
|
75
|
-
*/
|
|
76
|
-
export declare type HandlerErrorPlugin<C0 = Context, C1 = Context, C2 = Context, C3 = Context, C4 = Context, C5 = Context, C6 = Context, C7 = Context, C8 = Context, C9 = Context> = Plugin & {
|
|
77
|
-
type: "handler-error";
|
|
78
|
-
handle(context: C0 & C1 & C2 & C3 & C4 & C5 & C6 & C7 & C8 & C9, error: any, next: Function): Promise<any>;
|
|
79
|
-
};
|
package/types.js
CHANGED
|
@@ -2,4 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
|
-
});
|
|
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
|
+
|
|
19
|
+
var _fastify = require("fastify");
|
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import {\n FastifyInstance,\n FastifyRequest,\n FastifyReply,\n HTTPMethods,\n RouteHandlerMethod\n} from \"fastify\";\n\nexport { FastifyInstance, HTTPMethods } from \"fastify\";\nimport { ClientContext } from \"@webiny/handler-client/types\";\n\nexport type RouteTypes = HTTPMethods;\n\nexport interface RouteMethodOptions {\n override?: boolean;\n}\n\nexport type RouteMethodPath = `/${string}` | \"*\";\nexport interface RouteMethod {\n (path: RouteMethodPath, handler: RouteHandlerMethod, options?: RouteMethodOptions): void;\n}\n\nexport type Request = FastifyRequest;\nexport type Reply = FastifyReply;\n\nexport type DefinedContextRoutes = Record<RouteTypes, string[]>;\nexport interface ContextRoutes {\n defined: DefinedContextRoutes;\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}\n\nexport interface Context extends ClientContext {\n /**\n * An instance of fastify server.\n * Use at your own risk.\n * @instance\n */\n server: FastifyInstance;\n /**\n * Current request. Must be set only once!\n */\n request: FastifyRequest;\n /**\n * @internal\n */\n routes: ContextRoutes;\n}\n\ndeclare module \"fastify\" {\n interface FastifyInstance {\n webiny: Context;\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA"}
|
package/createHandler.d.ts
DELETED
package/createHandler.js
DELETED
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
|
|
10
|
-
var _middleware = _interopRequireDefault(require("./middleware"));
|
|
11
|
-
|
|
12
|
-
var _HandlerPlugin = require("./plugins/HandlerPlugin");
|
|
13
|
-
|
|
14
|
-
var _ContextPlugin = require("./plugins/ContextPlugin");
|
|
15
|
-
|
|
16
|
-
var _BeforeHandlerPlugin = require("./plugins/BeforeHandlerPlugin");
|
|
17
|
-
|
|
18
|
-
var _Context = require("./plugins/Context");
|
|
19
|
-
|
|
20
|
-
var _HandlerErrorPlugin = require("./plugins/HandlerErrorPlugin");
|
|
21
|
-
|
|
22
|
-
var _HandlerResultPlugin = require("./plugins/HandlerResultPlugin");
|
|
23
|
-
|
|
24
|
-
var _default = (...plugins) => async (...args) => {
|
|
25
|
-
const context = new _Context.Context({
|
|
26
|
-
plugins,
|
|
27
|
-
args,
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Inserted via webpack on build time.
|
|
31
|
-
*/
|
|
32
|
-
WEBINY_VERSION: process.env.WEBINY_VERSION
|
|
33
|
-
});
|
|
34
|
-
const result = await handle(context);
|
|
35
|
-
const handlerPlugins = context.plugins.byType(_HandlerResultPlugin.HandlerResultPlugin.type);
|
|
36
|
-
|
|
37
|
-
for (let i = 0; i < handlerPlugins.length; i++) {
|
|
38
|
-
if (!handlerPlugins[i].handle) {
|
|
39
|
-
continue;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
await handlerPlugins[i].handle(context, result);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return result;
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
exports.default = _default;
|
|
49
|
-
|
|
50
|
-
async function handle(context) {
|
|
51
|
-
try {
|
|
52
|
-
const contextPlugins = context.plugins.byType(_ContextPlugin.ContextPlugin.type);
|
|
53
|
-
|
|
54
|
-
for (let i = 0; i < contextPlugins.length; i++) {
|
|
55
|
-
if (!contextPlugins[i].apply) {
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
await contextPlugins[i].apply(context);
|
|
60
|
-
|
|
61
|
-
if (context.hasResult()) {
|
|
62
|
-
return context.getResult();
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
const beforeHandlerPlugins = context.plugins.byType(_BeforeHandlerPlugin.BeforeHandlerPlugin.type);
|
|
67
|
-
|
|
68
|
-
for (let i = 0; i < beforeHandlerPlugins.length; i++) {
|
|
69
|
-
if (!beforeHandlerPlugins[i].apply) {
|
|
70
|
-
continue;
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
await beforeHandlerPlugins[i].apply(context);
|
|
74
|
-
|
|
75
|
-
if (context.hasResult()) {
|
|
76
|
-
return context.getResult();
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const handlers = context.plugins.byType(_HandlerPlugin.HandlerPlugin.type);
|
|
81
|
-
const handler = (0, _middleware.default)(handlers.map(pl => {
|
|
82
|
-
return (context, next) => {
|
|
83
|
-
return pl.handle(context, next);
|
|
84
|
-
};
|
|
85
|
-
}));
|
|
86
|
-
const result = await handler(context);
|
|
87
|
-
|
|
88
|
-
if (!result) {
|
|
89
|
-
throw new Error(`No result was returned from registered handlers.`);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return result;
|
|
93
|
-
} catch (error) {
|
|
94
|
-
// Log error to cloud, as these can be extremely annoying to debug!
|
|
95
|
-
console.log("@webiny/handler");
|
|
96
|
-
console.log(error);
|
|
97
|
-
const handlers = context.plugins.byType(_HandlerErrorPlugin.HandlerErrorPlugin.type);
|
|
98
|
-
const handler = (0, _middleware.default)(handlers.map(pl => {
|
|
99
|
-
return (context, error, next) => {
|
|
100
|
-
return pl.handle(context, error, next);
|
|
101
|
-
};
|
|
102
|
-
}));
|
|
103
|
-
return handler(context, error);
|
|
104
|
-
}
|
|
105
|
-
}
|
package/createHandler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["plugins","args","context","Context","WEBINY_VERSION","process","env","result","handle","handlerPlugins","byType","HandlerResultPlugin","type","i","length","contextPlugins","ContextPlugin","apply","hasResult","getResult","beforeHandlerPlugins","BeforeHandlerPlugin","handlers","HandlerPlugin","handler","middleware","map","pl","next","Error","error","console","log","HandlerErrorPlugin"],"sources":["createHandler.ts"],"sourcesContent":["import middleware from \"./middleware\";\nimport { HandlerPlugin } from \"~/plugins/HandlerPlugin\";\nimport { ContextPlugin } from \"~/plugins/ContextPlugin\";\nimport { BeforeHandlerPlugin } from \"~/plugins/BeforeHandlerPlugin\";\nimport { Context } from \"~/plugins/Context\";\nimport { HandlerErrorPlugin } from \"~/plugins/HandlerErrorPlugin\";\nimport { HandlerResultPlugin } from \"~/plugins/HandlerResultPlugin\";\nimport { PluginCollection } from \"@webiny/plugins/types\";\n\nexport default (...plugins: PluginCollection) =>\n async (...args: string[]) => {\n const context = new Context({\n plugins,\n args,\n /**\n * Inserted via webpack on build time.\n */\n WEBINY_VERSION: process.env.WEBINY_VERSION as string\n });\n\n const result = await handle(context);\n\n const handlerPlugins = context.plugins.byType<HandlerResultPlugin>(\n HandlerResultPlugin.type\n );\n for (let i = 0; i < handlerPlugins.length; i++) {\n if (!handlerPlugins[i].handle) {\n continue;\n }\n await handlerPlugins[i].handle(context, result);\n }\n\n return result;\n };\n\nasync function handle(context: Context) {\n try {\n const contextPlugins = context.plugins.byType<ContextPlugin>(ContextPlugin.type);\n for (let i = 0; i < contextPlugins.length; i++) {\n if (!contextPlugins[i].apply) {\n continue;\n }\n await contextPlugins[i].apply(context);\n if (context.hasResult()) {\n return context.getResult();\n }\n }\n\n const beforeHandlerPlugins = context.plugins.byType<BeforeHandlerPlugin>(\n BeforeHandlerPlugin.type\n );\n for (let i = 0; i < beforeHandlerPlugins.length; i++) {\n if (!beforeHandlerPlugins[i].apply) {\n continue;\n }\n await beforeHandlerPlugins[i].apply(context);\n if (context.hasResult()) {\n return context.getResult();\n }\n }\n\n const handlers = context.plugins.byType<HandlerPlugin>(HandlerPlugin.type);\n const handler = middleware(\n handlers.map(pl => {\n return (context: Context, next: Function) => {\n return pl.handle(context, next);\n };\n })\n );\n const result = await handler(context);\n if (!result) {\n throw new Error(`No result was returned from registered handlers.`);\n }\n\n return result;\n } catch (error) {\n // Log error to cloud, as these can be extremely annoying to debug!\n console.log(\"@webiny/handler\");\n console.log(error);\n const handlers = context.plugins.byType<HandlerErrorPlugin>(HandlerErrorPlugin.type);\n const handler = middleware(\n handlers.map(pl => {\n return (context: Context, error: Error, next: Function) => {\n return pl.handle(context, error, next);\n };\n })\n );\n return handler(context, error);\n }\n}\n"],"mappings":"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"}
|
package/plugins/Context.d.ts
DELETED
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { Context as ContextInterface, HandlerArgs } from "../types";
|
|
2
|
-
import { PluginsContainer } from "@webiny/plugins";
|
|
3
|
-
import { PluginCollection } from "@webiny/plugins/types";
|
|
4
|
-
export interface ContextParams {
|
|
5
|
-
args?: HandlerArgs;
|
|
6
|
-
plugins?: PluginCollection;
|
|
7
|
-
WEBINY_VERSION: string;
|
|
8
|
-
}
|
|
9
|
-
export declare class Context implements ContextInterface {
|
|
10
|
-
_result: any;
|
|
11
|
-
readonly plugins: PluginsContainer;
|
|
12
|
-
readonly args: HandlerArgs;
|
|
13
|
-
readonly WEBINY_VERSION: string;
|
|
14
|
-
private readonly waiters;
|
|
15
|
-
constructor(params: ContextParams);
|
|
16
|
-
getResult(): any;
|
|
17
|
-
hasResult(): boolean;
|
|
18
|
-
setResult(value: any): void;
|
|
19
|
-
waitFor<T extends ContextInterface = ContextInterface>(obj: string | string[], cb: (context: T) => void): void;
|
|
20
|
-
}
|