@webiny/handler 5.17.4-beta.1 → 5.18.0-beta.2
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/createHandler.js +2 -3
- package/index.js +1 -2
- package/middleware.js +1 -2
- package/package.json +5 -5
- package/plugins/BeforeHandlerPlugin.js +1 -2
- package/plugins/ContextPlugin.js +1 -2
- package/types.js +1 -2
- package/createHandler.js.map +0 -1
- package/index.js.map +0 -1
- package/middleware.js.map +0 -1
- package/plugins/BeforeHandlerPlugin.js.map +0 -1
- package/plugins/ContextPlugin.js.map +0 -1
- package/types.js.map +0 -1
package/createHandler.js
CHANGED
|
@@ -33,7 +33,7 @@ var _default = (...plugins) => async (...args) => {
|
|
|
33
33
|
|
|
34
34
|
exports.default = _default;
|
|
35
35
|
|
|
36
|
-
async function handle(
|
|
36
|
+
async function handle(_, context) {
|
|
37
37
|
try {
|
|
38
38
|
const contextPlugins = context.plugins.byType("context");
|
|
39
39
|
|
|
@@ -67,5 +67,4 @@ async function handle(args, context) {
|
|
|
67
67
|
const handler = (0, _middleware.default)(handlers.map(pl => pl.handle));
|
|
68
68
|
return handler(context, error);
|
|
69
69
|
}
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=createHandler.js.map
|
|
70
|
+
}
|
package/index.js
CHANGED
package/middleware.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.18.0-beta.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -15,14 +15,14 @@
|
|
|
15
15
|
],
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"@babel/runtime": "7.16.3",
|
|
18
|
-
"@webiny/plugins": "5.
|
|
18
|
+
"@webiny/plugins": "5.18.0-beta.2"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@babel/cli": "^7.5.5",
|
|
22
22
|
"@babel/core": "^7.5.5",
|
|
23
23
|
"@babel/preset-env": "^7.5.5",
|
|
24
|
-
"@webiny/cli": "^5.
|
|
25
|
-
"@webiny/project-utils": "^5.
|
|
24
|
+
"@webiny/cli": "^5.18.0-beta.2",
|
|
25
|
+
"@webiny/project-utils": "^5.18.0-beta.2",
|
|
26
26
|
"rimraf": "^3.0.2",
|
|
27
27
|
"typescript": "^4.1.3"
|
|
28
28
|
},
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"build": "yarn webiny run build",
|
|
35
35
|
"watch": "yarn webiny run watch"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "02bb6242be1f61cbc204aea458fbc9e7c6000fc8"
|
|
38
38
|
}
|
|
@@ -29,5 +29,4 @@ class BeforeHandlerPlugin extends _plugins.Plugin {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
exports.BeforeHandlerPlugin = BeforeHandlerPlugin;
|
|
32
|
-
(0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
|
|
33
|
-
//# sourceMappingURL=BeforeHandlerPlugin.js.map
|
|
32
|
+
(0, _defineProperty2.default)(BeforeHandlerPlugin, "type", "before-handler");
|
package/plugins/ContextPlugin.js
CHANGED
|
@@ -29,5 +29,4 @@ class ContextPlugin extends _plugins.Plugin {
|
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
exports.ContextPlugin = ContextPlugin;
|
|
32
|
-
(0, _defineProperty2.default)(ContextPlugin, "type", "context");
|
|
33
|
-
//# sourceMappingURL=ContextPlugin.js.map
|
|
32
|
+
(0, _defineProperty2.default)(ContextPlugin, "type", "context");
|
package/types.js
CHANGED
package/createHandler.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createHandler.ts"],"names":["plugins","args","context","PluginsContainer","WEBINY_VERSION","process","env","result","handle","handlerPlugins","byType","i","length","apply","contextPlugins","beforeHandlerPlugins","handlers","handler","map","pl","Error","error","console","log"],"mappings":";;;;;;;;;AAAA;;AASA;;eAEe,CAAC,GAAGA,OAAJ,KACX,OAAO,GAAGC,IAAV,KAAmB;AACf,QAAMC,OAAgB,GAAG;AACrBF,IAAAA,OAAO,EAAE,IAAIG,yBAAJ,CAAqBH,OAArB,CADY;AAErBC,IAAAA,IAFqB;AAGrB;AACA;AACAG,IAAAA,cAAc,EAAEC,OAAO,CAACC,GAAR,CAAYF;AALP,GAAzB;AAQA,QAAMG,MAAM,GAAG,MAAMC,MAAM,CAACP,IAAD,EAAOC,OAAP,CAA3B;AAEA,QAAMO,cAAc,GAAGP,OAAO,CAACF,OAAR,CAAgBU,MAAhB,CAA4C,gBAA5C,CAAvB;;AACA,OAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGF,cAAc,CAACG,MAAnC,EAA2CD,CAAC,EAA5C,EAAgD;AAC5C,QAAIF,cAAc,CAACE,CAAD,CAAd,CAAkBE,KAAtB,EAA6B;AACzB,YAAMJ,cAAc,CAACE,CAAD,CAAd,CAAkBE,KAAlB,CAAwBN,MAAxB,EAAgCL,OAAhC,CAAN;AACH;AACJ;;AAED,SAAOK,MAAP;AACH,C;;;;AAEL,eAAeC,MAAf,CAAsBP,IAAtB,EAA4BC,OAA5B,EAA8C;AAC1C,MAAI;AACA,UAAMY,cAAc,GAAGZ,OAAO,CAACF,OAAR,CAAgBU,MAAhB,CAAsC,SAAtC,CAAvB;;AACA,SAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGG,cAAc,CAACF,MAAnC,EAA2CD,CAAC,EAA5C,EAAgD;AAC5C,UAAIG,cAAc,CAACH,CAAD,CAAd,CAAkBE,KAAtB,EAA6B;AACzB,cAAMC,cAAc,CAACH,CAAD,CAAd,CAAkBE,KAAlB,CAAwBX,OAAxB,CAAN;AACH;AACJ;;AAED,UAAMa,oBAAoB,GAAGb,OAAO,CAACF,OAAR,CAAgBU,MAAhB,CAA4C,gBAA5C,CAA7B;;AACA,SAAK,IAAIC,CAAC,GAAG,CAAb,EAAgBA,CAAC,GAAGI,oBAAoB,CAACH,MAAzC,EAAiDD,CAAC,EAAlD,EAAsD;AAClD,UAAII,oBAAoB,CAACJ,CAAD,CAApB,CAAwBE,KAA5B,EAAmC;AAC/B,cAAME,oBAAoB,CAACJ,CAAD,CAApB,CAAwBE,KAAxB,CAA8BX,OAA9B,CAAN;AACH;AACJ;;AAED,UAAMc,QAAQ,GAAGd,OAAO,CAACF,OAAR,CAAgBU,MAAhB,CAAsC,SAAtC,CAAjB;AACA,UAAMO,OAAO,GAAG,yBAAWD,QAAQ,CAACE,GAAT,CAAaC,EAAE,IAAIA,EAAE,CAACX,MAAtB,CAAX,CAAhB;AACA,UAAMD,MAAM,GAAG,MAAMU,OAAO,CAACf,OAAD,CAA5B;;AACA,QAAI,CAACK,MAAL,EAAa;AACT,YAAMa,KAAK,CAAE,kDAAF,CAAX;AACH;;AAED,WAAOb,MAAP;AACH,GAvBD,CAuBE,OAAOc,KAAP,EAAc;AACZ;AACAC,IAAAA,OAAO,CAACC,GAAR,CAAYF,KAAZ;AACA,UAAML,QAAQ,GAAGd,OAAO,CAACF,OAAR,CAAgBU,MAAhB,CAA2C,eAA3C,CAAjB;AACA,UAAMO,OAAO,GAAG,yBAAWD,QAAQ,CAACE,GAAT,CAAaC,EAAE,IAAIA,EAAE,CAACX,MAAtB,CAAX,CAAhB;AACA,WAAOS,OAAO,CAACf,OAAD,EAAUmB,KAAV,CAAd;AACH;AACJ","sourcesContent":["import { PluginsContainer } from \"@webiny/plugins\";\nimport {\n Context,\n HandlerResultPlugin,\n ContextPlugin,\n HandlerPlugin,\n HandlerErrorPlugin,\n BeforeHandlerPlugin\n} from \"./types\";\nimport middleware from \"./middleware\";\n\nexport default (...plugins) =>\n async (...args) => {\n const context: Context = {\n plugins: new PluginsContainer(plugins),\n args,\n // @ts-ignore\n // this is injected using webpack.DefinePlugin at build time\n WEBINY_VERSION: process.env.WEBINY_VERSION\n };\n\n const result = await handle(args, context);\n\n const handlerPlugins = context.plugins.byType<HandlerResultPlugin>(\"handler-result\");\n for (let i = 0; i < handlerPlugins.length; i++) {\n if (handlerPlugins[i].apply) {\n await handlerPlugins[i].apply(result, context);\n }\n }\n\n return result;\n };\n\nasync function handle(args, context: Context) {\n try {\n const contextPlugins = context.plugins.byType<ContextPlugin>(\"context\");\n for (let i = 0; i < contextPlugins.length; i++) {\n if (contextPlugins[i].apply) {\n await contextPlugins[i].apply(context);\n }\n }\n\n const beforeHandlerPlugins = context.plugins.byType<BeforeHandlerPlugin>(\"before-handler\");\n for (let i = 0; i < beforeHandlerPlugins.length; i++) {\n if (beforeHandlerPlugins[i].apply) {\n await beforeHandlerPlugins[i].apply(context);\n }\n }\n\n const handlers = context.plugins.byType<HandlerPlugin>(\"handler\");\n const handler = middleware(handlers.map(pl => pl.handle));\n const result = await handler(context);\n if (!result) {\n throw 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(error);\n const handlers = context.plugins.byType<HandlerErrorPlugin>(\"handler-error\");\n const handler = middleware(handlers.map(pl => pl.handle));\n return handler(context, error);\n }\n}\n"],"file":"createHandler.js"}
|
package/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA","sourcesContent":["export { default as createHandler } from \"./createHandler\";\n"],"file":"index.js"}
|
package/middleware.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/middleware.ts"],"names":["functions","args","length","Promise","resolve","chain","parentResolve","parentReject","next","fn","shift","reject","result","e","then","catch"],"mappings":";;;;;;;AAAA;AACA;AACA;eACe,CAACA,SAA0B,GAAG,EAA9B,KAA+C;AAC1D,SAAO,CAAC,GAAGC,IAAJ,KAA2B;AAC9B,QAAI,CAACD,SAAS,CAACE,MAAf,EAAuB;AACnB,aAAOC,OAAO,CAACC,OAAR,EAAP;AACH,KAH6B,CAK9B;;;AACA,UAAMC,KAAK,GAAG,CAAC,GAAGL,SAAJ,CAAd;AACA,WAAO,IAAIG,OAAJ,CAAY,CAACG,aAAD,EAAqBC,YAArB,KAAsC;AACrD,YAAMC,IAAI,GAAG,YAAY;AACrB,cAAMC,EAAE,GAAGJ,KAAK,CAACK,KAAN,EAAX;;AACA,YAAI,CAACD,EAAL,EAAS;AACL,iBAAON,OAAO,CAACC,OAAR,EAAP;AACH;;AAED,eAAO,IAAID,OAAJ,CAAY,OAAOC,OAAP,EAAgBO,MAAhB,KAA2B;AAC1C,cAAI;AACA,kBAAMC,MAAM,GAAG,MAAMH,EAAE,CAAC,GAAGR,IAAJ,EAAUG,OAAV,CAAvB;;AACA,gBAAI,OAAOQ,MAAP,KAAkB,WAAtB,EAAmC;AAC/B,qBAAON,aAAa,CAACM,MAAD,CAApB;AACH;AACJ,WALD,CAKE,OAAOC,CAAP,EAAU;AACRF,YAAAA,MAAM,CAACE,CAAD,CAAN;AACH;AACJ,SATM,EAUFC,IAVE,CAUG,MAAM;AACR,iBAAON,IAAI,EAAX;AACH,SAZE,EAaFM,IAbE,CAaG,MAAM;AACRR,UAAAA,aAAa,CAAC,GAAGL,IAAJ,CAAb;AACH,SAfE,EAgBFc,KAhBE,CAgBIF,CAAC,IAAI;AACRN,UAAAA,YAAY,CAACM,CAAD,CAAZ;AACH,SAlBE,CAAP;AAmBH,OAzBD;;AA2BA,aAAOL,IAAI,EAAX;AACH,KA7BM,CAAP;AA8BH,GArCD;AAsCH,C","sourcesContent":["/**\n * Compose a single middleware from the array of middleware functions\n */\nexport default (functions: Array<Function> = []): Function => {\n return (...args): 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 () => {\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"],"file":"middleware.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/BeforeHandlerPlugin.ts"],"names":["BeforeHandlerPlugin","Plugin","constructor","callable","_callable","apply","context","Error"],"mappings":";;;;;;;;;;;AAAA;;AAMO,MAAMA,mBAAN,SAA4CC,eAA5C,CAAmD;AAItDC,EAAAA,WAAW,CAACC,QAAD,EAAgC;AACvC;AADuC;AAEvC,SAAKC,SAAL,GAAiBD,QAAjB;AACH;;AAEDE,EAAAA,KAAK,CAACC,OAAD,EAA0C;AAC3C,QAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;AACtC,YAAMG,KAAK,CACN,6IADM,CAAX;AAGH;;AAED,WAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;AACH;;AAjBqD;;;8BAA7CN,mB,UACqB,gB","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\n\ninterface Callable<TContext> {\n (context: TContext): void | Promise<void>;\n}\n\nexport class BeforeHandlerPlugin<TContext> extends Plugin {\n public static readonly type = \"before-handler\";\n private readonly _callable: Callable<TContext>;\n\n constructor(callable?: Callable<TContext>) {\n super();\n this._callable = callable;\n }\n\n apply(context: TContext): void | 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"],"file":"BeforeHandlerPlugin.js"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/plugins/ContextPlugin.ts"],"names":["ContextPlugin","Plugin","constructor","callable","_callable","apply","context","Error"],"mappings":";;;;;;;;;;;AAAA;;AAMO,MAAMA,aAAN,SAAsCC,eAAtC,CAA6C;AAIhDC,EAAAA,WAAW,CAACC,QAAD,EAAgC;AACvC;AADuC;AAEvC,SAAKC,SAAL,GAAiBD,QAAjB;AACH;;AAEDE,EAAAA,KAAK,CAACC,OAAD,EAA0C;AAC3C,QAAI,OAAO,KAAKF,SAAZ,KAA0B,UAA9B,EAA0C;AACtC,YAAMG,KAAK,CACN,uIADM,CAAX;AAGH;;AAED,WAAO,KAAKH,SAAL,CAAeE,OAAf,CAAP;AACH;;AAjB+C;;;8BAAvCN,a,UACqB,S","sourcesContent":["import { Plugin } from \"@webiny/plugins\";\n\ninterface Callable<TContext> {\n (context: TContext): void | Promise<void>;\n}\n\nexport class ContextPlugin<TContext> extends Plugin {\n public static readonly type = \"context\";\n private readonly _callable: Callable<TContext>;\n\n constructor(callable?: Callable<TContext>) {\n super();\n this._callable = callable;\n }\n\n apply(context: TContext): void | Promise<void> {\n if (typeof this._callable !== \"function\") {\n throw Error(\n `Missing callable in ContextPlugin! 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"],"file":"ContextPlugin.js"}
|
package/types.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":"","sourcesContent":[],"file":"types.js"}
|