@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.
- package/chrome/message-host.d.ts +2 -2
- package/iframe/message-host.d.ts +2 -2
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/message-host.d.ts +3 -10
- package/message-host.js +2 -6
- package/message-response.type.d.ts +6 -2
- package/package.json +1 -1
- package/request.decorator.js +7 -2
- package/tsconfig.lib.json +5 -0
package/chrome/message-host.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MessageHost } from '../message-host';
|
|
2
|
-
import {
|
|
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:
|
|
10
|
+
protected response(message: SuccessfulMessageResponse): void;
|
|
11
11
|
}
|
|
12
12
|
export {};
|
package/iframe/message-host.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { MessageHost } from '../message-host';
|
|
2
|
-
import {
|
|
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:
|
|
17
|
+
protected response(message: SuccessfulMessageResponse): void;
|
|
18
18
|
private [HANDLER];
|
|
19
19
|
}
|
|
20
20
|
export {};
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
package/message-host.d.ts
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
import { Observable, Subject } from 'rxjs';
|
|
2
|
-
import {
|
|
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:
|
|
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
|
|
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
|
-
|
|
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
|
|
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
package/request.decorator.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
|
-
import { filter,
|
|
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(
|
|
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
|
};
|