@webiny/handler-client 6.0.0-beta.0 → 6.0.0-rc.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/HandlerClient.d.ts +1 -1
- package/HandlerClient.js +6 -13
- package/HandlerClient.js.map +1 -1
- package/HandlerClientPlugin.d.ts +3 -3
- package/HandlerClientPlugin.js +2 -9
- package/HandlerClientPlugin.js.map +1 -1
- package/README.md +7 -15
- package/index.d.ts +2 -2
- package/index.js +4 -26
- package/index.js.map +1 -1
- package/package.json +9 -19
- package/types.d.ts +5 -5
- package/types.js +1 -5
- package/types.js.map +1 -1
package/HandlerClient.d.ts
CHANGED
package/HandlerClient.js
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
var _error = _interopRequireDefault(require("@webiny/error"));
|
|
9
|
-
var _HandlerClientPlugin = require("./HandlerClientPlugin");
|
|
1
|
+
import WebinyError from "@webiny/error";
|
|
2
|
+
import { HandlerClientPlugin } from "./HandlerClientPlugin.js";
|
|
10
3
|
const defaultPluginName = "handler-client";
|
|
11
4
|
const getPluginFetcher = context => {
|
|
12
|
-
const pl = new
|
|
5
|
+
const pl = new HandlerClientPlugin({
|
|
13
6
|
invoke: async params => {
|
|
14
7
|
const {
|
|
15
8
|
name,
|
|
@@ -18,7 +11,7 @@ const getPluginFetcher = context => {
|
|
|
18
11
|
} = params;
|
|
19
12
|
const plugin = context.plugins.byName(name);
|
|
20
13
|
if (!plugin) {
|
|
21
|
-
throw new
|
|
14
|
+
throw new WebinyError(`Could not find "${name}" handler plugin.`);
|
|
22
15
|
}
|
|
23
16
|
const promise = plugin.invoke(payload);
|
|
24
17
|
if (useAwait === false) {
|
|
@@ -70,10 +63,10 @@ class HandlerClient {
|
|
|
70
63
|
if (params.description) {
|
|
71
64
|
data.description = params.description;
|
|
72
65
|
}
|
|
73
|
-
throw new
|
|
66
|
+
throw new WebinyError(`An error occurred while trying to invoke another handler with the following params: ${JSON.stringify(params, null, 2)}`, "INVOKE_ERROR", data);
|
|
74
67
|
}
|
|
75
68
|
}
|
|
76
69
|
}
|
|
77
|
-
|
|
70
|
+
export default HandlerClient;
|
|
78
71
|
|
|
79
72
|
//# sourceMappingURL=HandlerClient.js.map
|
package/HandlerClient.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["WebinyError","HandlerClientPlugin","defaultPluginName","getPluginFetcher","context","pl","invoke","params","name","payload","await","useAwait","plugin","plugins","byName","promise","getHandlerClientPlugin","HandlerClient","constructor","default","canHandle","ex","data","error","message","code","description","JSON","stringify"],"sources":["HandlerClient.ts"],"sourcesContent":["import WebinyError from \"@webiny/error\";\nimport type { HandlerClientHandlerPlugin, InvokeArgs, ClientContext } from \"./types.js\";\nimport { HandlerClientPlugin } from \"~/HandlerClientPlugin.js\";\n\nconst defaultPluginName = \"handler-client\";\n\nconst getPluginFetcher = (context: ClientContext): HandlerClientPlugin => {\n const pl = new HandlerClientPlugin({\n invoke: async params => {\n const { name, payload, await: useAwait } = params;\n const plugin = context.plugins.byName<HandlerClientHandlerPlugin>(name);\n if (!plugin) {\n throw new WebinyError(`Could not find \"${name}\" handler plugin.`);\n }\n\n const promise = plugin.invoke(payload);\n if (useAwait === false) {\n return null;\n }\n\n return promise;\n }\n });\n pl.name = defaultPluginName;\n return pl;\n};\n\nconst getHandlerClientPlugin = (context: ClientContext): HandlerClientPlugin => {\n const plugin = context.plugins.byName<HandlerClientPlugin>(\"handler-client\");\n if (plugin) {\n return plugin;\n }\n // If not specified, use a fallback plugin that fetches different handlers via plugins.\n // This might also be useful for testing purposes.\n return getPluginFetcher(context);\n};\n\nclass HandlerClient {\n private readonly plugin: any;\n /**\n * We need the default plugin to later on fetch another plugin than initially selected.\n * If name of the required plugin is not the default one, fetch new one.\n */\n private readonly default: HandlerClientPlugin;\n\n constructor(context: ClientContext) {\n this.plugin = getHandlerClientPlugin(context);\n this.default = getPluginFetcher(context);\n }\n\n public async invoke<TInvokeArgsPayload = any, TResponse = any>(\n params: InvokeArgs<TInvokeArgsPayload>\n ): Promise<TResponse> {\n let plugin: HandlerClientPlugin = this.plugin;\n if (plugin.canHandle && plugin.canHandle(params) === false) {\n plugin = this.default;\n }\n try {\n return await plugin.invoke(params);\n } catch (ex) {\n /**\n * We collect error that was caught and the description of the invoke, if any.\n */\n const data: Record<string, any> = {\n error: {\n message: ex.message,\n data: ex.data,\n code: ex.code\n }\n };\n if (params.description) {\n data.description = params.description;\n }\n throw new WebinyError(\n `An error occurred while trying to invoke another handler with the following params: ${JSON.stringify(\n params,\n null,\n 2\n )}`,\n \"INVOKE_ERROR\",\n data\n );\n }\n }\n}\n\nexport default HandlerClient;\n"],"mappings":"AAAA,OAAOA,WAAW,MAAM,eAAe;AAEvC,SAASC,mBAAmB;AAE5B,MAAMC,iBAAiB,GAAG,gBAAgB;AAE1C,MAAMC,gBAAgB,GAAIC,OAAsB,IAA0B;EACtE,MAAMC,EAAE,GAAG,IAAIJ,mBAAmB,CAAC;IAC/BK,MAAM,EAAE,MAAMC,MAAM,IAAI;MACpB,MAAM;QAAEC,IAAI;QAAEC,OAAO;QAAEC,KAAK,EAAEC;MAAS,CAAC,GAAGJ,MAAM;MACjD,MAAMK,MAAM,GAAGR,OAAO,CAACS,OAAO,CAACC,MAAM,CAA6BN,IAAI,CAAC;MACvE,IAAI,CAACI,MAAM,EAAE;QACT,MAAM,IAAIZ,WAAW,CAAC,mBAAmBQ,IAAI,mBAAmB,CAAC;MACrE;MAEA,MAAMO,OAAO,GAAGH,MAAM,CAACN,MAAM,CAACG,OAAO,CAAC;MACtC,IAAIE,QAAQ,KAAK,KAAK,EAAE;QACpB,OAAO,I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SAAS,CACjGrB,MAAM,EACN,IAAI,EACJ,CACJ,CAAC,EAAE,EACH,cAAc,EACde,IACJ,CAAC;IACL;EACJ;AACJ;AAEA,eAAeL,aAAa","ignoreList":[]}
|
package/HandlerClientPlugin.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Plugin } from "@webiny/plugins/Plugin";
|
|
2
|
-
import { InvokeArgs } from "./types";
|
|
3
|
-
interface HandlerClientPluginCallable<Payload =
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
import type { InvokeArgs } from "./types.js";
|
|
3
|
+
interface HandlerClientPluginCallable<Payload = any, Response = any> {
|
|
4
4
|
(params: InvokeArgs<Payload>): Promise<Response>;
|
|
5
5
|
}
|
|
6
6
|
export interface HandlerClientPluginParams {
|
package/HandlerClientPlugin.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.HandlerClientPlugin = void 0;
|
|
7
|
-
var _Plugin = require("@webiny/plugins/Plugin");
|
|
8
|
-
class HandlerClientPlugin extends _Plugin.Plugin {
|
|
1
|
+
import { Plugin } from "@webiny/plugins/Plugin.js";
|
|
2
|
+
export class HandlerClientPlugin extends Plugin {
|
|
9
3
|
static type = "handler-client";
|
|
10
4
|
constructor({
|
|
11
5
|
invoke,
|
|
@@ -25,6 +19,5 @@ class HandlerClientPlugin extends _Plugin.Plugin {
|
|
|
25
19
|
return this._invoke(params);
|
|
26
20
|
}
|
|
27
21
|
}
|
|
28
|
-
exports.HandlerClientPlugin = HandlerClientPlugin;
|
|
29
22
|
|
|
30
23
|
//# sourceMappingURL=HandlerClientPlugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["Plugin","HandlerClientPlugin","type","constructor","invoke","canUse","_invoke","canHandle","params"],"sources":["HandlerClientPlugin.ts"],"sourcesContent":["import { Plugin } from \"@webiny/plugins/Plugin.js\";\nimport type { InvokeArgs } from \"~/types.js\";\n\ninterface HandlerClientPluginCallable<Payload = any, Response = any> {\n (params: InvokeArgs<Payload>): Promise<Response>;\n}\n\nexport interface HandlerClientPluginParams {\n invoke: HandlerClientPluginCallable;\n canUse?: (params: InvokeArgs) => boolean;\n}\n\nexport class HandlerClientPlugin extends Plugin {\n public static override type = \"handler-client\";\n\n private readonly _invoke: HandlerClientPluginCallable;\n private readonly canUse?: (params: InvokeArgs) => boolean;\n\n public constructor({ invoke, canUse }: HandlerClientPluginParams) {\n super();\n this._invoke = invoke;\n this.canUse = canUse;\n }\n\n public canHandle(params: InvokeArgs): boolean {\n if (!this.canUse) {\n return true;\n }\n return this.canUse(params);\n }\n\n public invoke<Payload = any, Response = any>(params: InvokeArgs<Payload>): Promise<Response> {\n return this._invoke(params);\n }\n}\n"],"mappings":"AAAA,SAASA,MAAM,QAAQ,2BAA2B;AAYlD,OAAO,MAAMC,mBAAmB,SAASD,MAAM,CAAC;EAC5C,OAAuBE,IAAI,GAAG,gBAAgB;EAKvCC,WAAWA,CAAC;IAAEC,MAAM;IAAEC;EAAkC,CAAC,EAAE;IAC9D,KAAK,CAAC,CAAC;IACP,IAAI,CAACC,OAAO,GAAGF,MAAM;IACrB,IAAI,CAACC,MAAM,GAAGA,MAAM;EACxB;EAEOE,SAASA,CAACC,MAAkB,EAAW;IAC1C,IAAI,CAAC,IAAI,CAACH,MAAM,EAAE;MACd,OAAO,IAAI;IACf;IACA,OAAO,IAAI,CAACA,MAAM,CAACG,MAAM,CAAC;EAC9B;EAEOJ,MAAMA,CAAgCI,MAA2B,EAAqB;IACzF,OAAO,IAAI,CAACF,OAAO,CAACE,MAAM,CAAC;EAC/B;AACJ","ignoreList":[]}
|
package/README.md
CHANGED
|
@@ -1,19 +1,11 @@
|
|
|
1
1
|
# @webiny/handler-client
|
|
2
|
-
[](https://www.npmjs.com/package/@webiny/handler-client)
|
|
3
|
-
[](https://www.npmjs.com/package/@webiny/handler-client)
|
|
4
|
-
[](https://github.com/prettier/prettier)
|
|
5
|
-
[](http://makeapullrequest.com)
|
|
6
2
|
|
|
7
|
-
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
## Install
|
|
12
|
-
```
|
|
13
|
-
npm install --save @webiny/handler-client
|
|
14
|
-
```
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
15
8
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
```
|
|
9
|
+
---
|
|
10
|
+
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,33 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
var _exportNames = {
|
|
8
|
-
createHandlerClient: true
|
|
9
|
-
};
|
|
10
|
-
exports.createHandlerClient = void 0;
|
|
11
|
-
var _HandlerClient = _interopRequireDefault(require("./HandlerClient"));
|
|
12
|
-
var _HandlerClientPlugin = require("./HandlerClientPlugin");
|
|
13
|
-
Object.keys(_HandlerClientPlugin).forEach(function (key) {
|
|
14
|
-
if (key === "default" || key === "__esModule") return;
|
|
15
|
-
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
16
|
-
if (key in exports && exports[key] === _HandlerClientPlugin[key]) return;
|
|
17
|
-
Object.defineProperty(exports, key, {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () {
|
|
20
|
-
return _HandlerClientPlugin[key];
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
});
|
|
24
|
-
const createHandlerClient = () => ({
|
|
1
|
+
import HandlerClient from "./HandlerClient.js";
|
|
2
|
+
export * from "./HandlerClientPlugin.js";
|
|
3
|
+
export const createHandlerClient = () => ({
|
|
25
4
|
type: "context",
|
|
26
5
|
name: "handler-client.context",
|
|
27
6
|
async apply(context) {
|
|
28
|
-
context.handlerClient = new
|
|
7
|
+
context.handlerClient = new HandlerClient(context);
|
|
29
8
|
}
|
|
30
9
|
});
|
|
31
|
-
exports.createHandlerClient = createHandlerClient;
|
|
32
10
|
|
|
33
11
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["
|
|
1
|
+
{"version":3,"names":["HandlerClient","createHandlerClient","type","name","apply","context","handlerClient"],"sources":["index.ts"],"sourcesContent":["import HandlerClient from \"./HandlerClient.js\";\nimport type { ClientContext } from \"~/types.js\";\n\nexport * from \"./HandlerClientPlugin.js\";\n\nexport const createHandlerClient = () => ({\n type: \"context\",\n name: \"handler-client.context\",\n async apply(context: ClientContext) {\n context.handlerClient = new HandlerClient(context);\n }\n});\n"],"mappings":"AAAA,OAAOA,aAAa;AAGpB;AAEA,OAAO,MAAMC,mBAAmB,GAAGA,CAAA,MAAO;EACtCC,IAAI,EAAE,SAAS;EACfC,IAAI,EAAE,wBAAwB;EAC9B,MAAMC,KAAKA,CAACC,OAAsB,EAAE;IAChCA,OAAO,CAACC,aAAa,GAAG,IAAIN,aAAa,CAACK,OAAO,CAAC;EACtD;AACJ,CAAC,CAAC","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/handler-client",
|
|
3
|
-
"version": "6.0.0-
|
|
3
|
+
"version": "6.0.0-rc.0",
|
|
4
|
+
"type": "module",
|
|
4
5
|
"main": "index.js",
|
|
5
6
|
"repository": {
|
|
6
7
|
"type": "git",
|
|
@@ -14,29 +15,18 @@
|
|
|
14
15
|
],
|
|
15
16
|
"license": "MIT",
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@
|
|
18
|
-
"@webiny/
|
|
19
|
-
"@webiny/
|
|
20
|
-
"@webiny/plugins": "6.0.0-beta.0"
|
|
18
|
+
"@webiny/api": "6.0.0-rc.0",
|
|
19
|
+
"@webiny/error": "6.0.0-rc.0",
|
|
20
|
+
"@webiny/plugins": "6.0.0-rc.0"
|
|
21
21
|
},
|
|
22
22
|
"devDependencies": {
|
|
23
|
-
"@
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"@babel/preset-typescript": "7.24.1",
|
|
27
|
-
"@webiny/cli": "6.0.0-beta.0",
|
|
28
|
-
"@webiny/project-utils": "6.0.0-beta.0",
|
|
29
|
-
"jest": "29.7.0",
|
|
30
|
-
"rimraf": "5.0.5",
|
|
31
|
-
"typescript": "4.7.4"
|
|
23
|
+
"@webiny/build-tools": "6.0.0-rc.0",
|
|
24
|
+
"rimraf": "6.1.3",
|
|
25
|
+
"typescript": "5.9.3"
|
|
32
26
|
},
|
|
33
27
|
"publishConfig": {
|
|
34
28
|
"access": "public",
|
|
35
29
|
"directory": "dist"
|
|
36
30
|
},
|
|
37
|
-
"
|
|
38
|
-
"build": "yarn webiny run build",
|
|
39
|
-
"watch": "yarn webiny run watch"
|
|
40
|
-
},
|
|
41
|
-
"gitHead": "aa8dbfbbd5ad13ec271adba6f2431e02991a300f"
|
|
31
|
+
"gitHead": "0f2aa699f4642e550ab62c96fcd050e8d02345c9"
|
|
42
32
|
}
|
package/types.d.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import HandlerClient from "./HandlerClient";
|
|
2
|
-
import { Plugin } from "@webiny/plugins/types";
|
|
3
|
-
import { Context } from "@webiny/api/types";
|
|
4
|
-
export
|
|
1
|
+
import type HandlerClient from "./HandlerClient.js";
|
|
2
|
+
import type { Plugin } from "@webiny/plugins/types.js";
|
|
3
|
+
import type { Context } from "@webiny/api/types.js";
|
|
4
|
+
export type InvokeArgs<TInvokeArgsPayload = any> = {
|
|
5
5
|
name: string;
|
|
6
6
|
payload?: TInvokeArgsPayload;
|
|
7
7
|
await?: boolean;
|
|
8
8
|
description?: string;
|
|
9
9
|
};
|
|
10
|
-
export
|
|
10
|
+
export type HandlerClientHandlerPlugin = Plugin & {
|
|
11
11
|
type: "handler-client-handler";
|
|
12
12
|
invoke: <TArgs = Record<string, any>, TResponse = Record<string, any>>(params: TArgs) => TResponse | Promise<TResponse>;
|
|
13
13
|
};
|
package/types.js
CHANGED
package/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import HandlerClient from \"./HandlerClient\";\nimport { Plugin } from \"@webiny/plugins/types\";\nimport { Context } from \"@webiny/api/types\";\n\nexport type InvokeArgs<TInvokeArgsPayload = any> = {\n name: string;\n payload?: TInvokeArgsPayload;\n await?: boolean;\n description?: string;\n};\n\nexport type HandlerClientHandlerPlugin = Plugin & {\n type: \"handler-client-handler\";\n invoke: <TArgs = Record<string, any>, TResponse = Record<string, any>>(\n params: TArgs\n ) => TResponse | Promise<TResponse>;\n};\n\nexport interface ClientContext extends Context {\n handlerClient: HandlerClient;\n}\n"],"mappings":"","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type HandlerClient from \"./HandlerClient.js\";\nimport type { Plugin } from \"@webiny/plugins/types.js\";\nimport type { Context } from \"@webiny/api/types.js\";\n\nexport type InvokeArgs<TInvokeArgsPayload = any> = {\n name: string;\n payload?: TInvokeArgsPayload;\n await?: boolean;\n description?: string;\n};\n\nexport type HandlerClientHandlerPlugin = Plugin & {\n type: \"handler-client-handler\";\n invoke: <TArgs = Record<string, any>, TResponse = Record<string, any>>(\n params: TArgs\n ) => TResponse | Promise<TResponse>;\n};\n\nexport interface ClientContext extends Context {\n handlerClient: HandlerClient;\n}\n"],"mappings":"","ignoreList":[]}
|