@thalesrc/hermes 5.3.3 → 6.0.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/broadcast/message-client.d.ts +3 -11
- package/broadcast/message-client.js +11 -18
- package/broadcast/message-host.d.ts +1 -8
- package/broadcast/message-host.js +11 -16
- package/broadcast/message-service.d.ts +1 -1
- package/chrome/message-client.js +3 -1
- package/chrome/message-host.js +3 -5
- package/iframe/iframe.type.d.ts +1 -1
- package/iframe/iframe.type.js +1 -0
- package/iframe/message-client.d.ts +1 -1
- package/iframe/message-client.js +8 -7
- package/iframe/message-host.js +31 -31
- package/iframe/message-service.d.ts +1 -1
- package/iframe/upcoming-message.js +1 -0
- package/jest.config.js +7 -3
- package/listener-storage.type.d.ts +1 -1
- package/listener-storage.type.js +1 -0
- package/message-host.js +24 -26
- package/message-response.type.d.ts +4 -4
- package/message-response.type.js +1 -0
- package/message.interface.js +1 -0
- package/mixin.d.ts +4 -4
- package/package.json +12 -11
- package/tsconfig.spec.json +1 -1
- package/worker/message-client.d.ts +1 -1
- package/worker/message-client.js +8 -8
- package/worker/message-host.js +5 -6
- package/worker/message-service.d.ts +1 -1
|
@@ -3,18 +3,10 @@ import { MessageClient } from "../message-client";
|
|
|
3
3
|
import { MessageResponse } from "../message-response.type";
|
|
4
4
|
import { Message } from "../message.interface";
|
|
5
5
|
import { GET_NEW_ID, RESPONSES$, SEND } from "../selectors";
|
|
6
|
-
interface MessageEvent<T> {
|
|
7
|
-
data: T;
|
|
8
|
-
}
|
|
9
|
-
declare const CHANNEL: unique symbol;
|
|
10
|
-
declare const HANDLER: unique symbol;
|
|
11
6
|
export declare class BroadcastMessageClient extends MessageClient {
|
|
12
|
-
private
|
|
13
|
-
[RESPONSES$]: Subject<MessageResponse
|
|
14
|
-
private [CHANNEL];
|
|
7
|
+
#private;
|
|
8
|
+
protected [RESPONSES$]: Subject<MessageResponse>;
|
|
15
9
|
constructor(channelName?: string);
|
|
16
|
-
[SEND]<T>(message: Message<T>): void;
|
|
17
|
-
protected [HANDLER]: (event: MessageEvent<MessageResponse>) => void;
|
|
10
|
+
protected [SEND]<T>(message: Message<T>): void;
|
|
18
11
|
protected [GET_NEW_ID](): string;
|
|
19
12
|
}
|
|
20
|
-
export {};
|
|
@@ -1,29 +1,22 @@
|
|
|
1
|
-
var _a, _b, _c;
|
|
2
1
|
import { Subject } from "rxjs";
|
|
3
2
|
import { MessageClient } from "../message-client";
|
|
4
3
|
import { GET_NEW_ID, RESPONSES$, SEND } from "../selectors";
|
|
5
4
|
import { DEFAULT_CHANNEL_NAME } from "./default-channel-name";
|
|
6
|
-
const CHANNEL = Symbol('Broadcast Channel');
|
|
7
|
-
const HANDLER = Symbol('Handler');
|
|
8
5
|
export class BroadcastMessageClient extends MessageClient {
|
|
6
|
+
[RESPONSES$] = new Subject();
|
|
7
|
+
#channel;
|
|
9
8
|
constructor(channelName = DEFAULT_CHANNEL_NAME) {
|
|
10
9
|
super();
|
|
11
|
-
this
|
|
12
|
-
this
|
|
13
|
-
this[_b] = new BroadcastChannel(this.channelName);
|
|
14
|
-
this[_c] = (event) => {
|
|
15
|
-
this[RESPONSES$].next(event.data);
|
|
16
|
-
};
|
|
17
|
-
this[CHANNEL].addEventListener('message', this[HANDLER]);
|
|
10
|
+
this.#channel = new BroadcastChannel(channelName);
|
|
11
|
+
this.#channel.addEventListener('message', this.#handler);
|
|
18
12
|
}
|
|
19
|
-
[
|
|
20
|
-
this
|
|
13
|
+
[SEND](message) {
|
|
14
|
+
this.#channel.postMessage(message);
|
|
21
15
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
return newId;
|
|
16
|
+
#handler = (event) => {
|
|
17
|
+
this[RESPONSES$].next(event.data);
|
|
18
|
+
};
|
|
19
|
+
[GET_NEW_ID]() {
|
|
20
|
+
return crypto.randomUUID();
|
|
28
21
|
}
|
|
29
22
|
}
|
|
@@ -1,15 +1,8 @@
|
|
|
1
1
|
import { MessageHost } from "../message-host";
|
|
2
2
|
import { MessageResponse } from "../message-response.type";
|
|
3
|
-
declare const REQUESTS$: unique symbol;
|
|
4
|
-
declare const HANDLER: unique symbol;
|
|
5
|
-
declare const CHANNEL: unique symbol;
|
|
6
3
|
export declare class BroadcastMessageHost extends MessageHost {
|
|
7
|
-
private
|
|
8
|
-
private [REQUESTS$];
|
|
9
|
-
private [CHANNEL];
|
|
4
|
+
#private;
|
|
10
5
|
constructor(channelName?: string);
|
|
11
6
|
protected response(message: MessageResponse): void;
|
|
12
7
|
terminate(): void;
|
|
13
|
-
private [HANDLER];
|
|
14
8
|
}
|
|
15
|
-
export {};
|
|
@@ -1,28 +1,23 @@
|
|
|
1
|
-
var _a, _b, _c;
|
|
2
1
|
import { Subject } from "rxjs";
|
|
3
2
|
import { MessageHost } from "../message-host";
|
|
4
3
|
import { DEFAULT_CHANNEL_NAME } from "./default-channel-name";
|
|
5
|
-
const REQUESTS$ = Symbol('Requests');
|
|
6
|
-
const HANDLER = Symbol('Handler');
|
|
7
|
-
const CHANNEL = Symbol('Broadcast Channel');
|
|
8
4
|
export class BroadcastMessageHost extends MessageHost {
|
|
5
|
+
#requests$ = new Subject();
|
|
6
|
+
#channel;
|
|
9
7
|
constructor(channelName = DEFAULT_CHANNEL_NAME) {
|
|
10
8
|
super();
|
|
11
|
-
this
|
|
12
|
-
this
|
|
13
|
-
this
|
|
14
|
-
this[_c] = (event) => {
|
|
15
|
-
this[REQUESTS$].next(event.data);
|
|
16
|
-
};
|
|
17
|
-
this[CHANNEL].addEventListener('message', this[HANDLER]);
|
|
18
|
-
this.listen(this[REQUESTS$]);
|
|
9
|
+
this.#channel = new BroadcastChannel(channelName);
|
|
10
|
+
this.#channel.addEventListener('message', this.#handler);
|
|
11
|
+
this.listen(this.#requests$);
|
|
19
12
|
}
|
|
20
13
|
response(message) {
|
|
21
|
-
this
|
|
14
|
+
this.#channel.postMessage(message);
|
|
22
15
|
}
|
|
23
16
|
terminate() {
|
|
24
|
-
this
|
|
25
|
-
this
|
|
17
|
+
this.#channel.removeEventListener('message', this.#handler);
|
|
18
|
+
this.#channel.close();
|
|
26
19
|
}
|
|
20
|
+
#handler = (event) => {
|
|
21
|
+
this.#requests$.next(event.data);
|
|
22
|
+
};
|
|
27
23
|
}
|
|
28
|
-
_a = REQUESTS$, _b = CHANNEL, _c = HANDLER;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { BroadcastMessageClient } from "./message-client";
|
|
2
|
-
declare const BroadcastMessageService_base: new (args_0: [string
|
|
2
|
+
declare const BroadcastMessageService_base: new (args_0: [channelName?: string], args_1: [channelName?: string]) => {
|
|
3
3
|
terminate: () => void;
|
|
4
4
|
} & BroadcastMessageClient;
|
|
5
5
|
export declare class BroadcastMessageService extends BroadcastMessageService_base {
|
package/chrome/message-client.js
CHANGED
|
@@ -7,6 +7,9 @@ const RANDOM_ID_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz012
|
|
|
7
7
|
const RANDOM_ID_CHARS_LENGTH = RANDOM_ID_CHARS.length;
|
|
8
8
|
const PORT = Symbol('Port');
|
|
9
9
|
export class ChromeMessageClient extends MessageClient {
|
|
10
|
+
static connections = {};
|
|
11
|
+
[RESPONSES$];
|
|
12
|
+
[PORT];
|
|
10
13
|
constructor(name = DEFAULT_CONNECTION_NAME) {
|
|
11
14
|
super();
|
|
12
15
|
if (!(name in ChromeMessageClient.connections)) {
|
|
@@ -32,4 +35,3 @@ export class ChromeMessageClient extends MessageClient {
|
|
|
32
35
|
return result;
|
|
33
36
|
}
|
|
34
37
|
}
|
|
35
|
-
ChromeMessageClient.connections = {};
|
package/chrome/message-host.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
var _a, _b;
|
|
2
1
|
import { Subject } from 'rxjs';
|
|
3
2
|
import { MessageHost } from '../message-host';
|
|
4
3
|
import { DEFAULT_CONNECTION_NAME } from './default-connection-name';
|
|
5
4
|
const PORTS = Symbol('Ports');
|
|
6
5
|
const REQUESTS$ = Symbol('Requests');
|
|
7
6
|
export class ChromeMessageHost extends MessageHost {
|
|
7
|
+
static PORT_IDENTIFIER = 'portIdentifier';
|
|
8
|
+
[PORTS] = {};
|
|
9
|
+
[REQUESTS$] = new Subject();
|
|
8
10
|
constructor(name = DEFAULT_CONNECTION_NAME) {
|
|
9
11
|
super();
|
|
10
|
-
this[_a] = {};
|
|
11
|
-
this[_b] = new Subject();
|
|
12
12
|
chrome.runtime.onConnect.addListener((port) => {
|
|
13
13
|
if (port.name !== name) {
|
|
14
14
|
return;
|
|
@@ -38,5 +38,3 @@ export class ChromeMessageHost extends MessageHost {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
}
|
|
41
|
-
_a = PORTS, _b = REQUESTS$;
|
|
42
|
-
ChromeMessageHost.PORT_IDENTIFIER = 'portIdentifier';
|
package/iframe/iframe.type.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export type IFrame = HTMLIFrameElement | (() => HTMLIFrameElement);
|
package/iframe/iframe.type.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -8,7 +8,7 @@ declare const TARGET_FRAME: unique symbol;
|
|
|
8
8
|
declare const _TARGET_FRAME: unique symbol;
|
|
9
9
|
export declare class IframeMessageClient extends MessageClient {
|
|
10
10
|
private channelName;
|
|
11
|
-
[RESPONSES$]: Subject<MessageResponse
|
|
11
|
+
[RESPONSES$]: Subject<MessageResponse>;
|
|
12
12
|
private [_TARGET_FRAME];
|
|
13
13
|
protected get [TARGET_FRAME](): null | HTMLIFrameElement;
|
|
14
14
|
constructor(channelName?: string, targetFrame?: IFrame);
|
package/iframe/message-client.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var _a;
|
|
2
1
|
import { uniqueId } from '@thalesrc/js-utils';
|
|
3
2
|
import { Subject } from 'rxjs';
|
|
4
3
|
import { MessageClient } from '../message-client';
|
|
@@ -8,10 +7,17 @@ import { DEFAULT_CHANNEL_NAME } from './default-channel-name';
|
|
|
8
7
|
const TARGET_FRAME = Symbol('Target Frame');
|
|
9
8
|
const _TARGET_FRAME = Symbol('_ Target Frame');
|
|
10
9
|
export class IframeMessageClient extends MessageClient {
|
|
10
|
+
channelName;
|
|
11
|
+
[RESPONSES$] = new Subject();
|
|
12
|
+
[_TARGET_FRAME];
|
|
13
|
+
get [TARGET_FRAME]() {
|
|
14
|
+
return typeof this[_TARGET_FRAME] === 'function'
|
|
15
|
+
? this[_TARGET_FRAME]() || null
|
|
16
|
+
: this[_TARGET_FRAME] || null;
|
|
17
|
+
}
|
|
11
18
|
constructor(channelName = DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
12
19
|
super();
|
|
13
20
|
this.channelName = channelName;
|
|
14
|
-
this[_a] = new Subject();
|
|
15
21
|
this[_TARGET_FRAME] = targetFrame;
|
|
16
22
|
window.addEventListener('message', ({ data, source }) => {
|
|
17
23
|
const target = this[TARGET_FRAME];
|
|
@@ -26,11 +32,6 @@ export class IframeMessageClient extends MessageClient {
|
|
|
26
32
|
this[RESPONSES$].next(data);
|
|
27
33
|
});
|
|
28
34
|
}
|
|
29
|
-
get [(_a = RESPONSES$, TARGET_FRAME)]() {
|
|
30
|
-
return typeof this[_TARGET_FRAME] === 'function'
|
|
31
|
-
? this[_TARGET_FRAME]() || null
|
|
32
|
-
: this[_TARGET_FRAME] || null;
|
|
33
|
-
}
|
|
34
35
|
[SEND](message) {
|
|
35
36
|
message = { ...message, path: `${this.channelName}${CHANNEL_PATH_SPLITTER}${message.path}` };
|
|
36
37
|
const target = this[TARGET_FRAME];
|
package/iframe/message-host.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var _a, _b, _c;
|
|
2
1
|
import { uniqueId } from '@thalesrc/js-utils';
|
|
3
2
|
import { Subject } from 'rxjs';
|
|
4
3
|
import { MessageHost } from '../message-host';
|
|
@@ -11,42 +10,22 @@ const HANDLER = Symbol('Handler');
|
|
|
11
10
|
const TARGET_FRAME = Symbol('Target Frame');
|
|
12
11
|
const _TARGET_FRAME = Symbol('_ Target Frame');
|
|
13
12
|
export class IframeMessageHost extends MessageHost {
|
|
13
|
+
channelName;
|
|
14
|
+
[REQUESTS$] = new Subject();
|
|
15
|
+
[SOURCES] = [];
|
|
16
|
+
[_TARGET_FRAME];
|
|
17
|
+
get [TARGET_FRAME]() {
|
|
18
|
+
return typeof this[_TARGET_FRAME] === 'function'
|
|
19
|
+
? this[_TARGET_FRAME]() || null
|
|
20
|
+
: this[_TARGET_FRAME] || null;
|
|
21
|
+
}
|
|
14
22
|
constructor(channelName = DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
15
23
|
super();
|
|
16
24
|
this.channelName = channelName;
|
|
17
|
-
this[_a] = new Subject();
|
|
18
|
-
this[_b] = [];
|
|
19
|
-
this[_c] = ({ data, source }) => {
|
|
20
|
-
if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
|
-
const targetFrame = this[TARGET_FRAME];
|
|
24
|
-
if (targetFrame && targetFrame.contentWindow !== source) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
const [channel, path] = data.path.split(CHANNEL_PATH_SPLITTER);
|
|
28
|
-
if (channel !== this.channelName) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
if (!this[SOURCES].some(([, s]) => s === source)) {
|
|
32
|
-
this[SOURCES].push([uniqueId('hermes-iframe-source'), source]);
|
|
33
|
-
}
|
|
34
|
-
const [sourceId] = this[SOURCES].find(([, s]) => s === source);
|
|
35
|
-
this[REQUESTS$].next({
|
|
36
|
-
body: targetFrame ? data.body : { data: data.body, sender: source },
|
|
37
|
-
id: `${sourceId}${SOURCE_ID_SPLITTER}${data.id}`,
|
|
38
|
-
path,
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
25
|
this[_TARGET_FRAME] = targetFrame;
|
|
42
26
|
window.addEventListener('message', this[HANDLER]);
|
|
43
27
|
this.listen(this[REQUESTS$]);
|
|
44
28
|
}
|
|
45
|
-
get [(_a = REQUESTS$, _b = SOURCES, TARGET_FRAME)]() {
|
|
46
|
-
return typeof this[_TARGET_FRAME] === 'function'
|
|
47
|
-
? this[_TARGET_FRAME]() || null
|
|
48
|
-
: this[_TARGET_FRAME] || null;
|
|
49
|
-
}
|
|
50
29
|
terminate() {
|
|
51
30
|
window.removeEventListener('message', this[HANDLER]);
|
|
52
31
|
}
|
|
@@ -59,5 +38,26 @@ export class IframeMessageHost extends MessageHost {
|
|
|
59
38
|
};
|
|
60
39
|
source.postMessage(message);
|
|
61
40
|
}
|
|
41
|
+
[HANDLER] = ({ data, source }) => {
|
|
42
|
+
if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const targetFrame = this[TARGET_FRAME];
|
|
46
|
+
if (targetFrame && targetFrame.contentWindow !== source) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const [channel, path] = data.path.split(CHANNEL_PATH_SPLITTER);
|
|
50
|
+
if (channel !== this.channelName) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
if (!this[SOURCES].some(([, s]) => s === source)) {
|
|
54
|
+
this[SOURCES].push([uniqueId('hermes-iframe-source'), source]);
|
|
55
|
+
}
|
|
56
|
+
const [sourceId] = this[SOURCES].find(([, s]) => s === source);
|
|
57
|
+
this[REQUESTS$].next({
|
|
58
|
+
body: targetFrame ? data.body : { data: data.body, sender: source },
|
|
59
|
+
id: `${sourceId}${SOURCE_ID_SPLITTER}${data.id}`,
|
|
60
|
+
path,
|
|
61
|
+
});
|
|
62
|
+
};
|
|
62
63
|
}
|
|
63
|
-
_c = HANDLER;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { IframeMessageClient } from "./message-client";
|
|
2
2
|
import { IFrame } from "./iframe.type";
|
|
3
|
-
declare const IframeMessageService_base: new (args_0: [string
|
|
3
|
+
declare const IframeMessageService_base: new (args_0: [channelName?: string, targetFrame?: IFrame], args_1: [channelName?: string, targetFrame?: IFrame]) => {
|
|
4
4
|
terminate: () => void;
|
|
5
5
|
} & IframeMessageClient;
|
|
6
6
|
export declare class IframeMessageService extends IframeMessageService_base {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/jest.config.js
CHANGED
|
@@ -6,13 +6,17 @@ module.exports = {
|
|
|
6
6
|
coverageReporters: ["html", "json"],
|
|
7
7
|
collectCoverageFrom: [
|
|
8
8
|
"src/**/*.ts",
|
|
9
|
-
"!**/*/index.ts"
|
|
9
|
+
"!**/*/index.ts",
|
|
10
|
+
"!src/broadcast/*", // Remove these lines later
|
|
11
|
+
"!src/chrome/*",
|
|
12
|
+
"!src/iframe/*",
|
|
13
|
+
"!src/worker/*",
|
|
10
14
|
],
|
|
11
15
|
testMatch: [
|
|
12
16
|
"**/__tests__/**/*.+(ts|tsx|js)",
|
|
13
17
|
"**/?(*.)+(spec|test).+(ts|tsx|js)"
|
|
14
18
|
],
|
|
15
19
|
transform: {
|
|
16
|
-
"^.+\\.(ts|tsx)$": "ts-jest"
|
|
17
|
-
}
|
|
20
|
+
"^.+\\.(ts|tsx)$": ["ts-jest", {tsconfig: './tsconfig.spec.json'}]
|
|
21
|
+
}
|
|
18
22
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { Observable } from 'rxjs';
|
|
2
|
-
export
|
|
2
|
+
export type ListenerStorage<T = any> = Map<string, ((message: any) => Observable<T>)[]>;
|
package/listener-storage.type.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/message-host.js
CHANGED
|
@@ -10,32 +10,30 @@ export const GET_LISTENERS = Symbol('Message Host Listeners');
|
|
|
10
10
|
* Message Host
|
|
11
11
|
*/
|
|
12
12
|
export class MessageHost {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
};
|
|
38
|
-
}
|
|
13
|
+
/**
|
|
14
|
+
* Message Terminator Subject
|
|
15
|
+
*
|
|
16
|
+
* Use `next(messageId)` method to terminate a message connection
|
|
17
|
+
*/
|
|
18
|
+
terminateMessage$ = new Subject();
|
|
19
|
+
/**
|
|
20
|
+
* Run this method to start listening the requests
|
|
21
|
+
*/
|
|
22
|
+
listen = (messages$) => {
|
|
23
|
+
for (const [path, listeners] of this[GET_LISTENERS]()) {
|
|
24
|
+
messages$
|
|
25
|
+
.pipe(filter(({ path: messagePath }) => path === messagePath))
|
|
26
|
+
.subscribe(({ body, id }) => {
|
|
27
|
+
for (const listener of listeners) {
|
|
28
|
+
listener.call(this, body).pipe(takeUntil(this.terminateMessage$.pipe(filter(terminatedMessageId => terminatedMessageId === id)))).subscribe(result => {
|
|
29
|
+
this.response({ completed: false, id, body: result });
|
|
30
|
+
}, noop, () => {
|
|
31
|
+
this.response({ completed: true, id });
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
};
|
|
39
37
|
/**
|
|
40
38
|
* All inherited listeners
|
|
41
39
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Message } from './message.interface';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
|
3
|
+
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
|
|
9
|
+
export type MessageResponse<T = any> = UncompletedMessageResponse<T> | CompletedMessageResponse;
|
|
10
10
|
export {};
|
package/message-response.type.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/message.interface.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/mixin.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
type Merge<T, U> = {
|
|
2
2
|
[P in keyof T]: P extends keyof U ? U[P] : T[P];
|
|
3
3
|
} & U;
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
type Constructor<T extends {}, U extends any[] = any[]> = new (...args: U) => T;
|
|
5
|
+
type ConstructorProps<T> = T extends {
|
|
6
6
|
new (...args: infer U): any;
|
|
7
7
|
} ? U : never;
|
|
8
|
-
|
|
8
|
+
type Instance<T> = T extends {
|
|
9
9
|
new (...args: any[]): infer U;
|
|
10
10
|
} ? U : never;
|
|
11
11
|
export declare function Mixin<T extends Constructor<any>, U extends Constructor<any>>(First: T, Second: U): Constructor<Merge<Instance<T>, Instance<U>>, [ConstructorProps<T>, ConstructorProps<U>]>;
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thalesrc/hermes",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "6.0.1",
|
|
4
4
|
"description": "Javascript messaging library",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"typings": "index.d.ts",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"build": "tsc -p ./tsconfig.lib.json",
|
|
8
9
|
"test": "jest",
|
|
9
10
|
"test:coverage": "jest --collectCoverage",
|
|
10
11
|
"lint": "tslint -p tsconfig.json && tslint -p tsconfig.spec.json",
|
|
@@ -34,19 +35,19 @@
|
|
|
34
35
|
},
|
|
35
36
|
"homepage": "https://github.com/thalesrc/hermes#readme",
|
|
36
37
|
"dependencies": {
|
|
37
|
-
"@thalesrc/js-utils": "^
|
|
38
|
-
"rxjs": "^
|
|
38
|
+
"@thalesrc/js-utils": "^2.12.0",
|
|
39
|
+
"rxjs": "^7.8.1"
|
|
39
40
|
},
|
|
40
41
|
"devDependencies": {
|
|
41
|
-
"@types/chrome": "^0.0.
|
|
42
|
-
"@types/jest": "^
|
|
43
|
-
"cpy-cli": "^
|
|
44
|
-
"jest": "^
|
|
45
|
-
"replace": "^1.
|
|
46
|
-
"rxjs-marbles": "^
|
|
47
|
-
"ts-jest": "^
|
|
42
|
+
"@types/chrome": "^0.0.253",
|
|
43
|
+
"@types/jest": "^29.5.10",
|
|
44
|
+
"cpy-cli": "^5.0.0",
|
|
45
|
+
"jest": "^29.7.0",
|
|
46
|
+
"replace": "^1.2.2",
|
|
47
|
+
"rxjs-marbles": "^7.0.1",
|
|
48
|
+
"ts-jest": "^29.1.1",
|
|
48
49
|
"tslint": "^5.20.1",
|
|
49
|
-
"typescript": "^3.2
|
|
50
|
+
"typescript": "^5.3.2"
|
|
50
51
|
},
|
|
51
52
|
"publishConfig": {
|
|
52
53
|
"access": "public"
|
package/tsconfig.spec.json
CHANGED
|
@@ -10,7 +10,7 @@ declare const WORKER: unique symbol;
|
|
|
10
10
|
declare const HANDLER: unique symbol;
|
|
11
11
|
declare const INSTANCE_ID: unique symbol;
|
|
12
12
|
export declare class WorkerMessageClient extends MessageClient {
|
|
13
|
-
[RESPONSES$]: Subject<MessageResponse
|
|
13
|
+
[RESPONSES$]: Subject<MessageResponse>;
|
|
14
14
|
protected [WORKER]: Worker;
|
|
15
15
|
private [INSTANCE_ID];
|
|
16
16
|
constructor(worker?: Worker);
|
package/worker/message-client.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
var _a, _b, _c;
|
|
2
1
|
import { uniqueId } from "@thalesrc/js-utils";
|
|
3
2
|
import { Subject } from "rxjs";
|
|
4
3
|
import { MessageClient } from "../message-client";
|
|
@@ -7,13 +6,11 @@ const WORKER = Symbol('Worker');
|
|
|
7
6
|
const HANDLER = Symbol('Handler');
|
|
8
7
|
const INSTANCE_ID = Symbol('Instance Id');
|
|
9
8
|
export class WorkerMessageClient extends MessageClient {
|
|
9
|
+
[RESPONSES$] = new Subject();
|
|
10
|
+
[WORKER];
|
|
11
|
+
[INSTANCE_ID] = Date.now();
|
|
10
12
|
constructor(worker) {
|
|
11
13
|
super();
|
|
12
|
-
this[_a] = new Subject();
|
|
13
|
-
this[_b] = Date.now();
|
|
14
|
-
this[_c] = (event) => {
|
|
15
|
-
this[RESPONSES$].next(event.data);
|
|
16
|
-
};
|
|
17
14
|
this[WORKER] = worker;
|
|
18
15
|
if (worker) {
|
|
19
16
|
worker.addEventListener('message', this[HANDLER]);
|
|
@@ -22,7 +19,7 @@ export class WorkerMessageClient extends MessageClient {
|
|
|
22
19
|
addEventListener('message', this[HANDLER]);
|
|
23
20
|
}
|
|
24
21
|
}
|
|
25
|
-
[
|
|
22
|
+
[SEND](message) {
|
|
26
23
|
if (this[WORKER]) {
|
|
27
24
|
this[WORKER].postMessage(message);
|
|
28
25
|
}
|
|
@@ -30,7 +27,10 @@ export class WorkerMessageClient extends MessageClient {
|
|
|
30
27
|
postMessage(message);
|
|
31
28
|
}
|
|
32
29
|
}
|
|
33
|
-
[
|
|
30
|
+
[HANDLER] = (event) => {
|
|
31
|
+
this[RESPONSES$].next(event.data);
|
|
32
|
+
};
|
|
33
|
+
[GET_NEW_ID]() {
|
|
34
34
|
return uniqueId('hermes-worker-message-' + this[INSTANCE_ID]);
|
|
35
35
|
}
|
|
36
36
|
}
|
package/worker/message-host.js
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
var _a, _b;
|
|
2
1
|
import { Subject } from "rxjs";
|
|
3
2
|
import { MessageHost } from "../message-host";
|
|
4
3
|
const REQUESTS$ = Symbol('Requests');
|
|
5
4
|
const HANDLER = Symbol('Handler');
|
|
6
5
|
const WORKER = Symbol('Worker');
|
|
7
6
|
export class WorkerMessageHost extends MessageHost {
|
|
7
|
+
[REQUESTS$] = new Subject();
|
|
8
|
+
[WORKER];
|
|
8
9
|
constructor(worker) {
|
|
9
10
|
super();
|
|
10
|
-
this[_a] = new Subject();
|
|
11
|
-
this[_b] = (event) => {
|
|
12
|
-
this[REQUESTS$].next(event.data);
|
|
13
|
-
};
|
|
14
11
|
if (worker) {
|
|
15
12
|
this[WORKER] = worker;
|
|
16
13
|
worker.addEventListener('message', this[HANDLER]);
|
|
@@ -36,5 +33,7 @@ export class WorkerMessageHost extends MessageHost {
|
|
|
36
33
|
removeEventListener('message', this[HANDLER]);
|
|
37
34
|
}
|
|
38
35
|
}
|
|
36
|
+
[HANDLER] = (event) => {
|
|
37
|
+
this[REQUESTS$].next(event.data);
|
|
38
|
+
};
|
|
39
39
|
}
|
|
40
|
-
_a = REQUESTS$, _b = HANDLER;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WorkerMessageClient } from "./message-client";
|
|
2
|
-
declare const WorkerMessageService_base: new (args_0: [Worker
|
|
2
|
+
declare const WorkerMessageService_base: new (args_0: [worker?: Worker], args_1: [worker?: Worker]) => {
|
|
3
3
|
terminate: () => void;
|
|
4
4
|
} & WorkerMessageClient;
|
|
5
5
|
export declare class WorkerMessageService extends WorkerMessageService_base {
|