@matreshka/bff 0.11.0 → 0.11.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.
@@ -17,7 +17,9 @@ export type ServerActionProperties<ComponentType extends Componentable, PayloadT
17
17
  * Используется для выполнения произвольного кода на сервере, например, при клике по кнопке.
18
18
  * @param properties Свойства действия.
19
19
  */
20
- export type ServerActionHandler<ComponentType extends Componentable, PayloadType = undefined> = (properties: ServerActionProperties<ComponentType, PayloadType>) => void;
20
+ type SyncServerActionHandler<ComponentType extends Componentable, PayloadType = undefined> = (properties: ServerActionProperties<ComponentType, PayloadType>) => void;
21
+ type AsyncServerActionHandler<ComponentType extends Componentable, PayloadType = undefined> = (properties: ServerActionProperties<ComponentType, PayloadType>) => Promise<void>;
22
+ export type ServerActionHandler<ComponentType extends Componentable, PayloadType = undefined> = SyncServerActionHandler<ComponentType, PayloadType> | AsyncServerActionHandler<ComponentType, PayloadType>;
21
23
  /**
22
24
  * Серверное действие, выполняемое BFF при взаимодействии клиента с компонентом.
23
25
  */
@@ -28,3 +30,4 @@ export declare class ServerAction<ComponentType extends Componentable, PayloadTy
28
30
  payload(): object;
29
31
  execute(properties: ServerActionProperties<ComponentType, PayloadType>): void;
30
32
  }
33
+ export {};
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ServerAction = void 0;
4
4
  const action_1 = require("../../core/actions/action");
5
+ const client_context_1 = require("../../core/client-context");
5
6
  /**
6
7
  * Серверное действие, выполняемое BFF при взаимодействии клиента с компонентом.
7
8
  */
@@ -17,7 +18,27 @@ class ServerAction extends action_1.Action {
17
18
  return {};
18
19
  }
19
20
  execute(properties) {
20
- this.handler(properties);
21
+ let result;
22
+ try {
23
+ result = this.handler(properties);
24
+ }
25
+ catch (error) {
26
+ reportServerActionError(error, properties.instance);
27
+ return;
28
+ }
29
+ if (isPromise(result)) {
30
+ void result.catch((error) => reportServerActionError(error, properties.instance));
31
+ }
21
32
  }
22
33
  }
23
34
  exports.ServerAction = ServerAction;
35
+ function isPromise(value) {
36
+ return (value !== null &&
37
+ typeof value === "object" &&
38
+ "then" in value &&
39
+ typeof value.then === "function");
40
+ }
41
+ function reportServerActionError(error, instance) {
42
+ const client = instance.client ?? (0, client_context_1.currentClient)();
43
+ client?.error$.next(error);
44
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@matreshka/bff",
3
- "version": "0.11.0",
3
+ "version": "0.11.2",
4
4
  "description": "Matreshka BFF: server-driven UI runtime — routing, pages, context, component DSL, and platform APIs",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",