@thalesrc/hermes 6.0.1 → 6.1.1

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.
@@ -1,5 +1,5 @@
1
1
  import { MessageHost } from '../message-host';
2
- import { MessageResponse } from '../message-response.type';
2
+ import { SuccessfulMessageResponse } from '../message-response.type';
3
3
  declare const PORTS: unique symbol;
4
4
  declare const REQUESTS$: unique symbol;
5
5
  export declare class ChromeMessageHost extends MessageHost {
@@ -7,6 +7,6 @@ export declare class ChromeMessageHost extends MessageHost {
7
7
  private [PORTS];
8
8
  private [REQUESTS$];
9
9
  constructor(name?: string);
10
- protected response(message: MessageResponse): void;
10
+ protected response(message: SuccessfulMessageResponse): void;
11
11
  }
12
12
  export {};
@@ -1,5 +1,5 @@
1
1
  import { MessageHost } from '../message-host';
2
- import { MessageResponse } from '../message-response.type';
2
+ import { SuccessfulMessageResponse } from '../message-response.type';
3
3
  import { IFrame } from './iframe.type';
4
4
  declare const REQUESTS$: unique symbol;
5
5
  declare const SOURCES: unique symbol;
@@ -14,7 +14,7 @@ export declare class IframeMessageHost extends MessageHost {
14
14
  protected get [TARGET_FRAME](): null | HTMLIFrameElement;
15
15
  constructor(channelName?: string, targetFrame?: IFrame);
16
16
  terminate(): void;
17
- protected response(message: MessageResponse): void;
17
+ protected response(message: SuccessfulMessageResponse): void;
18
18
  private [HANDLER];
19
19
  }
20
20
  export {};
package/index.d.ts CHANGED
@@ -4,3 +4,4 @@ export { Message } from './message.interface';
4
4
  export { MessageResponse } from './message-response.type';
5
5
  export { MessageClient } from './message-client';
6
6
  export { MessageHost } from './message-host';
7
+ export * from './selectors';
package/index.js CHANGED
@@ -2,3 +2,4 @@ export { Request } from './request.decorator';
2
2
  export { Listen } from './listen.decorator';
3
3
  export { MessageClient } from './message-client';
4
4
  export { MessageHost } from './message-host';
5
+ export * from './selectors';
package/message-host.d.ts CHANGED
@@ -1,14 +1,11 @@
1
1
  import { Observable, Subject } from 'rxjs';
2
- import { MessageResponse } from './message-response.type';
2
+ import { SuccessfulMessageResponse } from './message-response.type';
3
3
  import { Message } from './message.interface';
4
- /**
5
- * Listeners property symbol
6
- */
7
- export declare const GET_LISTENERS: unique symbol;
8
4
  /**
9
5
  * Message Host
10
6
  */
11
7
  export declare abstract class MessageHost {
8
+ #private;
12
9
  /**
13
10
  * Message Terminator Subject
14
11
  *
@@ -24,9 +21,5 @@ export declare abstract class MessageHost {
24
21
  *
25
22
  * @param message Incoming response message
26
23
  */
27
- protected abstract response(message: MessageResponse): void;
28
- /**
29
- * All inherited listeners
30
- */
31
- private [GET_LISTENERS];
24
+ protected abstract response<T = any>(message: SuccessfulMessageResponse<T>): void;
32
25
  }
package/message-host.js CHANGED
@@ -2,10 +2,6 @@ import { noop } from '@thalesrc/js-utils';
2
2
  import { Subject } from 'rxjs';
3
3
  import { filter, takeUntil } from 'rxjs/operators';
4
4
  import { MESSAGE_LISTENERS } from './selectors';
5
- /**
6
- * Listeners property symbol
7
- */
8
- export const GET_LISTENERS = Symbol('Message Host Listeners');
9
5
  /**
10
6
  * Message Host
11
7
  */
@@ -20,7 +16,7 @@ export class MessageHost {
20
16
  * Run this method to start listening the requests
21
17
  */
22
18
  listen = (messages$) => {
23
- for (const [path, listeners] of this[GET_LISTENERS]()) {
19
+ for (const [path, listeners] of this.#getListeners()) {
24
20
  messages$
25
21
  .pipe(filter(({ path: messagePath }) => path === messagePath))
26
22
  .subscribe(({ body, id }) => {
@@ -37,7 +33,7 @@ export class MessageHost {
37
33
  /**
38
34
  * All inherited listeners
39
35
  */
40
- [GET_LISTENERS]() {
36
+ #getListeners() {
41
37
  const map = new Map();
42
38
  let currentProto = this['__proto__' + ''];
43
39
  while (currentProto.constructor !== Object) {
@@ -1,10 +1,14 @@
1
1
  import { Message } from './message.interface';
2
2
  type Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
3
- type UncompletedMessageResponse<T = any> = Omit<Message<T>, 'path'> & {
3
+ export type UncompletedMessageResponse<T = any> = Omit<Message<T>, 'path'> & {
4
4
  completed: false;
5
5
  };
6
6
  type CompletedMessageResponse = Omit<Message, 'body' | 'path'> & {
7
7
  completed: true;
8
8
  };
9
- export type MessageResponse<T = any> = UncompletedMessageResponse<T> | CompletedMessageResponse;
9
+ export type ErrorMessageResponse = {
10
+ error: any;
11
+ };
12
+ export type SuccessfulMessageResponse<T = any> = UncompletedMessageResponse<T> | CompletedMessageResponse;
13
+ export type MessageResponse<T = any> = SuccessfulMessageResponse<T> | ErrorMessageResponse;
10
14
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@thalesrc/hermes",
3
- "version": "6.0.1",
3
+ "version": "6.1.1",
4
4
  "description": "Javascript messaging library",
5
5
  "main": "index.js",
6
6
  "typings": "index.d.ts",
@@ -1,11 +1,16 @@
1
- import { filter, pluck, takeWhile } from 'rxjs/operators';
1
+ import { filter, map, takeWhile } from 'rxjs/operators';
2
2
  import { GET_NEW_ID, RESPONSES$, SEND } from './selectors';
3
3
  export function Request(path) {
4
4
  return function (target, key, descriptor) {
5
5
  descriptor.value = function (message) {
6
6
  const messageId = this[GET_NEW_ID]();
7
7
  this[SEND]({ body: message, id: messageId, path });
8
- return this[RESPONSES$].pipe(filter(({ id }) => id === messageId), takeWhile(({ completed }) => !completed), pluck('body'));
8
+ return this[RESPONSES$].pipe(map((data) => {
9
+ const { error } = data;
10
+ if (error)
11
+ throw error;
12
+ return data;
13
+ }), filter(({ id }) => id === messageId), takeWhile(({ completed }) => !completed), map(({ body }) => body));
9
14
  };
10
15
  return descriptor;
11
16
  };
package/tsconfig.lib.json CHANGED
@@ -1,5 +1,10 @@
1
1
  {
2
2
  "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": [
5
+ "@types/chrome"
6
+ ]
7
+ },
3
8
  "exclude": [
4
9
  "node_modules",
5
10
  "**/*.spec.ts"