@thalesrc/hermes 0.0.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/LICENSE +21 -0
- package/README.md +538 -0
- package/broadcast/default-channel-name.cjs +4 -0
- package/broadcast/default-channel-name.d.ts +1 -0
- package/broadcast/default-channel-name.js +3 -0
- package/broadcast/default-channel-name.js.map +1 -0
- package/broadcast/index.cjs +13 -0
- package/broadcast/index.d.ts +5 -0
- package/broadcast/index.js +7 -0
- package/broadcast/index.js.map +1 -0
- package/broadcast/message-client.cjs +26 -0
- package/broadcast/message-client.d.ts +12 -0
- package/broadcast/message-client.js +24 -0
- package/broadcast/message-client.js.map +1 -0
- package/broadcast/message-host.cjs +28 -0
- package/broadcast/message-host.d.ts +9 -0
- package/broadcast/message-host.js +26 -0
- package/broadcast/message-host.js.map +1 -0
- package/broadcast/message-service.cjs +13 -0
- package/broadcast/message-service.d.ts +8 -0
- package/broadcast/message-service.js +11 -0
- package/broadcast/message-service.js.map +1 -0
- package/chrome/default-connection-name.cjs +4 -0
- package/chrome/default-connection-name.d.ts +1 -0
- package/chrome/default-connection-name.js +3 -0
- package/chrome/default-connection-name.js.map +1 -0
- package/chrome/index.cjs +11 -0
- package/chrome/index.d.ts +4 -0
- package/chrome/index.js +6 -0
- package/chrome/index.js.map +1 -0
- package/chrome/message-client.cjs +41 -0
- package/chrome/message-client.d.ts +15 -0
- package/chrome/message-client.js +39 -0
- package/chrome/message-client.js.map +1 -0
- package/chrome/message-host.cjs +43 -0
- package/chrome/message-host.d.ts +9 -0
- package/chrome/message-host.js +41 -0
- package/chrome/message-host.js.map +1 -0
- package/iframe/channel-path-splitter.cjs +4 -0
- package/iframe/channel-path-splitter.d.ts +1 -0
- package/iframe/channel-path-splitter.js +3 -0
- package/iframe/channel-path-splitter.js.map +1 -0
- package/iframe/default-channel-name.cjs +4 -0
- package/iframe/default-channel-name.d.ts +1 -0
- package/iframe/default-channel-name.js +3 -0
- package/iframe/default-channel-name.js.map +1 -0
- package/iframe/iframe.type.cjs +2 -0
- package/iframe/iframe.type.d.ts +1 -0
- package/iframe/iframe.type.js +3 -0
- package/iframe/iframe.type.js.map +1 -0
- package/iframe/index.cjs +13 -0
- package/iframe/index.d.ts +6 -0
- package/iframe/index.js +7 -0
- package/iframe/index.js.map +1 -0
- package/iframe/message-client.cjs +50 -0
- package/iframe/message-client.d.ts +14 -0
- package/iframe/message-client.js +48 -0
- package/iframe/message-client.js.map +1 -0
- package/iframe/message-host.cjs +63 -0
- package/iframe/message-host.d.ts +11 -0
- package/iframe/message-host.js +61 -0
- package/iframe/message-host.js.map +1 -0
- package/iframe/message-service.cjs +13 -0
- package/iframe/message-service.d.ts +9 -0
- package/iframe/message-service.js +11 -0
- package/iframe/message-service.js.map +1 -0
- package/iframe/source-id-splitter.cjs +4 -0
- package/iframe/source-id-splitter.d.ts +1 -0
- package/iframe/source-id-splitter.js +3 -0
- package/iframe/source-id-splitter.js.map +1 -0
- package/iframe/upcoming-message.cjs +2 -0
- package/iframe/upcoming-message.d.ts +4 -0
- package/iframe/upcoming-message.js +3 -0
- package/iframe/upcoming-message.js.map +1 -0
- package/index.cjs +13 -0
- package/index.d.ts +7 -0
- package/index.js +7 -0
- package/index.js.map +1 -0
- package/listen.decorator.cjs +20 -0
- package/listen.decorator.d.ts +6 -0
- package/listen.decorator.js +19 -0
- package/listen.decorator.js.map +1 -0
- package/listener-storage.type.cjs +2 -0
- package/listener-storage.type.d.ts +2 -0
- package/listener-storage.type.js +3 -0
- package/listener-storage.type.js.map +1 -0
- package/message-client.cjs +10 -0
- package/message-client.d.ts +23 -0
- package/message-client.js +8 -0
- package/message-client.js.map +1 -0
- package/message-host.cjs +58 -0
- package/message-host.d.ts +26 -0
- package/message-host.js +56 -0
- package/message-host.js.map +1 -0
- package/message-response.type.cjs +2 -0
- package/message-response.type.d.ts +14 -0
- package/message-response.type.js +3 -0
- package/message-response.type.js.map +1 -0
- package/message.interface.cjs +2 -0
- package/message.interface.d.ts +6 -0
- package/message.interface.js +3 -0
- package/message.interface.js.map +1 -0
- package/package.json +158 -0
- package/request.decorator.cjs +20 -0
- package/request.decorator.d.ts +1 -0
- package/request.decorator.js +19 -0
- package/request.decorator.js.map +1 -0
- package/selectors.cjs +10 -0
- package/selectors.d.ts +7 -0
- package/selectors.js +9 -0
- package/selectors.js.map +1 -0
- package/worker/index.cjs +13 -0
- package/worker/index.d.ts +5 -0
- package/worker/index.js +7 -0
- package/worker/index.js.map +1 -0
- package/worker/message-client.cjs +174 -0
- package/worker/message-client.d.ts +117 -0
- package/worker/message-client.js +172 -0
- package/worker/message-client.js.map +1 -0
- package/worker/message-host.cjs +41 -0
- package/worker/message-host.d.ts +9 -0
- package/worker/message-host.js +39 -0
- package/worker/message-host.js.map +1 -0
- package/worker/message-service.cjs +12 -0
- package/worker/message-service.d.ts +8 -0
- package/worker/message-service.js +10 -0
- package/worker/message-service.js.map +1 -0
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IframeMessageHost = void 0;
|
|
4
|
+
const js_utils_1 = require("@thalesrc/js-utils");
|
|
5
|
+
const rxjs_1 = require("rxjs");
|
|
6
|
+
const message_host_1 = require("../message-host");
|
|
7
|
+
const channel_path_splitter_1 = require("./channel-path-splitter");
|
|
8
|
+
const default_channel_name_1 = require("./default-channel-name");
|
|
9
|
+
const source_id_splitter_1 = require("./source-id-splitter");
|
|
10
|
+
const selectors_1 = require("../selectors");
|
|
11
|
+
class IframeMessageHost extends message_host_1.MessageHost {
|
|
12
|
+
channelName;
|
|
13
|
+
#requests = new rxjs_1.Subject();
|
|
14
|
+
#sources = [];
|
|
15
|
+
#_targetFrame;
|
|
16
|
+
get #targetFrame() {
|
|
17
|
+
return typeof this.#_targetFrame === 'function'
|
|
18
|
+
? this.#_targetFrame() || null
|
|
19
|
+
: this.#_targetFrame || null;
|
|
20
|
+
}
|
|
21
|
+
constructor(channelName = default_channel_name_1.DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
22
|
+
super();
|
|
23
|
+
this.channelName = channelName;
|
|
24
|
+
this.#_targetFrame = targetFrame;
|
|
25
|
+
window.addEventListener('message', this.#handler);
|
|
26
|
+
this[selectors_1.LISTEN](this.#requests);
|
|
27
|
+
}
|
|
28
|
+
terminate() {
|
|
29
|
+
window.removeEventListener('message', this.#handler);
|
|
30
|
+
}
|
|
31
|
+
[selectors_1.RESPONSE](message) {
|
|
32
|
+
const [sourceId, messageId] = message.id.split(source_id_splitter_1.SOURCE_ID_SPLITTER);
|
|
33
|
+
const [, source] = this.#sources.find(([sId]) => sId === sourceId);
|
|
34
|
+
message = {
|
|
35
|
+
...message,
|
|
36
|
+
id: messageId,
|
|
37
|
+
};
|
|
38
|
+
source.postMessage(message);
|
|
39
|
+
}
|
|
40
|
+
#handler = ({ data, source }) => {
|
|
41
|
+
if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const targetFrame = this.#targetFrame;
|
|
45
|
+
if (targetFrame && targetFrame.contentWindow !== source) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const [channel, path] = data.path.split(channel_path_splitter_1.CHANNEL_PATH_SPLITTER);
|
|
49
|
+
if (channel !== this.channelName) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
if (!this.#sources.some(([, s]) => s === source)) {
|
|
53
|
+
this.#sources.push([(0, js_utils_1.uniqueId)('hermes-iframe-source'), source]);
|
|
54
|
+
}
|
|
55
|
+
const [sourceId] = this.#sources.find(([, s]) => s === source);
|
|
56
|
+
this.#requests.next({
|
|
57
|
+
body: targetFrame ? data.body : { data: data.body, sender: source },
|
|
58
|
+
id: `${sourceId}${source_id_splitter_1.SOURCE_ID_SPLITTER}${data.id}`,
|
|
59
|
+
path,
|
|
60
|
+
});
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
exports.IframeMessageHost = IframeMessageHost;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { MessageHost } from '../message-host';
|
|
2
|
+
import { SuccessfulMessageResponse } from '../message-response.type';
|
|
3
|
+
import { IFrame } from './iframe.type';
|
|
4
|
+
import { RESPONSE } from '../selectors';
|
|
5
|
+
export declare class IframeMessageHost extends MessageHost {
|
|
6
|
+
#private;
|
|
7
|
+
private channelName;
|
|
8
|
+
constructor(channelName?: string, targetFrame?: IFrame);
|
|
9
|
+
terminate(): void;
|
|
10
|
+
protected [RESPONSE](message: SuccessfulMessageResponse): void;
|
|
11
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { uniqueId } from '@thalesrc/js-utils';
|
|
2
|
+
import { Subject } from 'rxjs';
|
|
3
|
+
import { MessageHost } from '../message-host';
|
|
4
|
+
import { CHANNEL_PATH_SPLITTER } from './channel-path-splitter';
|
|
5
|
+
import { DEFAULT_CHANNEL_NAME } from './default-channel-name';
|
|
6
|
+
import { SOURCE_ID_SPLITTER } from './source-id-splitter';
|
|
7
|
+
import { LISTEN, RESPONSE } from '../selectors';
|
|
8
|
+
export class IframeMessageHost extends MessageHost {
|
|
9
|
+
channelName;
|
|
10
|
+
#requests = new Subject();
|
|
11
|
+
#sources = [];
|
|
12
|
+
#_targetFrame;
|
|
13
|
+
get #targetFrame() {
|
|
14
|
+
return typeof this.#_targetFrame === 'function'
|
|
15
|
+
? this.#_targetFrame() || null
|
|
16
|
+
: this.#_targetFrame || null;
|
|
17
|
+
}
|
|
18
|
+
constructor(channelName = DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
19
|
+
super();
|
|
20
|
+
this.channelName = channelName;
|
|
21
|
+
this.#_targetFrame = targetFrame;
|
|
22
|
+
window.addEventListener('message', this.#handler);
|
|
23
|
+
this[LISTEN](this.#requests);
|
|
24
|
+
}
|
|
25
|
+
terminate() {
|
|
26
|
+
window.removeEventListener('message', this.#handler);
|
|
27
|
+
}
|
|
28
|
+
[RESPONSE](message) {
|
|
29
|
+
const [sourceId, messageId] = message.id.split(SOURCE_ID_SPLITTER);
|
|
30
|
+
const [, source] = this.#sources.find(([sId]) => sId === sourceId);
|
|
31
|
+
message = {
|
|
32
|
+
...message,
|
|
33
|
+
id: messageId,
|
|
34
|
+
};
|
|
35
|
+
source.postMessage(message);
|
|
36
|
+
}
|
|
37
|
+
#handler = ({ data, source }) => {
|
|
38
|
+
if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const targetFrame = this.#targetFrame;
|
|
42
|
+
if (targetFrame && targetFrame.contentWindow !== source) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const [channel, path] = data.path.split(CHANNEL_PATH_SPLITTER);
|
|
46
|
+
if (channel !== this.channelName) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (!this.#sources.some(([, s]) => s === source)) {
|
|
50
|
+
this.#sources.push([uniqueId('hermes-iframe-source'), source]);
|
|
51
|
+
}
|
|
52
|
+
const [sourceId] = this.#sources.find(([, s]) => s === source);
|
|
53
|
+
this.#requests.next({
|
|
54
|
+
body: targetFrame ? data.body : { data: data.body, sender: source },
|
|
55
|
+
id: `${sourceId}${SOURCE_ID_SPLITTER}${data.id}`,
|
|
56
|
+
path,
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
//# sourceMappingURL=message-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/iframe/message-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC;AAC/B,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,C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,EAAC;YACjE,EAAE,EAAE,GAAG,QAAQ,GAAG,kBAAkB,GAAG,IAAI,CAAC,EAAE,EAAE;YAChD,IAAI;SACL,CAAC,CAAC;IACL,CAAC,CAAA;CACF","file":"message-host.js","sourcesContent":["import { uniqueId } from '@thalesrc/js-utils';\nimport { Subject } from 'rxjs';\nimport { MessageHost } from '../message-host';\nimport { SuccessfulMessageResponse } from '../message-response.type';\nimport { Message } from '../message.interface';\nimport { CHANNEL_PATH_SPLITTER } from './channel-path-splitter';\nimport { DEFAULT_CHANNEL_NAME } from './default-channel-name';\nimport { SOURCE_ID_SPLITTER } from './source-id-splitter';\nimport { IFrame } from './iframe.type';\nimport { LISTEN, RESPONSE } from '../selectors';\n\nexport class IframeMessageHost extends MessageHost {\n #requests = new Subject<Message>();\n #sources: Array<[string, MessageEventSource]> = [];\n #_targetFrame: IFrame | undefined;\n\n get #targetFrame(): null | HTMLIFrameElement {\n return typeof this.#_targetFrame === 'function'\n ? (this.#_targetFrame as () => HTMLIFrameElement)() || null\n : this.#_targetFrame as HTMLIFrameElement || null;\n }\n\n constructor(\n private channelName = DEFAULT_CHANNEL_NAME,\n targetFrame?: IFrame\n ) {\n super();\n\n this.#_targetFrame = targetFrame;\n\n window.addEventListener('message', this.#handler);\n\n this[LISTEN](this.#requests);\n }\n\n public terminate(): void {\n window.removeEventListener('message', this.#handler);\n }\n\n protected [RESPONSE](message: SuccessfulMessageResponse): void {\n const [sourceId, messageId] = message.id.split(SOURCE_ID_SPLITTER);\n const [, source] = this.#sources.find(([sId]) => sId === sourceId)!;\n\n message = {\n ...message,\n id: messageId,\n };\n\n (source as any).postMessage(message);\n }\n\n #handler = ({data, source}: MessageEvent<Message>) => {\n if (!data || typeof data !== 'object' || !data.path || typeof data.id === 'undefined') {\n return;\n }\n\n const targetFrame = this.#targetFrame;\n\n if (targetFrame && targetFrame.contentWindow !== source) {\n return;\n }\n\n const [channel, path] = data.path.split(CHANNEL_PATH_SPLITTER);\n\n if (channel !== this.channelName) {\n return;\n }\n\n if (!this.#sources.some(([, s]) => s === source)) {\n this.#sources.push([uniqueId('hermes-iframe-source') as string, source!]);\n }\n\n const [sourceId] = this.#sources.find(([, s]) => s === source)!;\n this.#requests.next({\n body: targetFrame ? data.body : {data: data.body, sender: source},\n id: `${sourceId}${SOURCE_ID_SPLITTER}${data.id}`,\n path,\n });\n }\n}\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.IframeMessageService = void 0;
|
|
4
|
+
const mixin_1 = require("@thalesrc/js-utils/class/mixin");
|
|
5
|
+
const message_client_1 = require("./message-client");
|
|
6
|
+
const message_host_1 = require("./message-host");
|
|
7
|
+
const default_channel_name_1 = require("./default-channel-name");
|
|
8
|
+
class IframeMessageService extends (0, mixin_1.mixin)(message_host_1.IframeMessageHost, message_client_1.IframeMessageClient) {
|
|
9
|
+
constructor(channelName = default_channel_name_1.DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
10
|
+
super([channelName, targetFrame], [channelName, targetFrame]);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.IframeMessageService = IframeMessageService;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { IframeMessageClient } from "./message-client";
|
|
2
|
+
import { IFrame } from "./iframe.type";
|
|
3
|
+
declare const IframeMessageService_base: new (args_0: [channelName?: string | undefined, targetFrame?: IFrame | undefined], args_1: [channelName?: string | undefined, targetFrame?: IFrame | undefined]) => {
|
|
4
|
+
terminate: () => void;
|
|
5
|
+
} & IframeMessageClient;
|
|
6
|
+
export declare class IframeMessageService extends IframeMessageService_base {
|
|
7
|
+
constructor(channelName?: string, targetFrame?: IFrame);
|
|
8
|
+
}
|
|
9
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { mixin } from "@thalesrc/js-utils/class/mixin";
|
|
2
|
+
import { IframeMessageClient } from "./message-client";
|
|
3
|
+
import { IframeMessageHost } from "./message-host";
|
|
4
|
+
import { DEFAULT_CHANNEL_NAME } from "./default-channel-name";
|
|
5
|
+
export class IframeMessageService extends mixin(IframeMessageHost, IframeMessageClient) {
|
|
6
|
+
constructor(channelName = DEFAULT_CHANNEL_NAME, targetFrame) {
|
|
7
|
+
super([channelName, targetFrame], [channelName, targetFrame]);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=message-service.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/iframe/message-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,gCAAgC,CAAC;AACvD,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAG9D,MAAM,OAAO,oBAAqB,SAAQ,KAAK,CAAC,iBAAiB,EAAE,mBAAmB,CAAC;IACrF,YACE,WAAW,GAAG,oBAAoB,EAClC,WAAoB;QAEpB,KAAK,CAAC,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC,WAAW,EAAE,WAAW,CAAC,CAAC,CAAC;IAChE,CAAC;CACF","file":"message-service.js","sourcesContent":["import { mixin } from \"@thalesrc/js-utils/class/mixin\";\nimport { IframeMessageClient } from \"./message-client\";\nimport { IframeMessageHost } from \"./message-host\";\nimport { DEFAULT_CHANNEL_NAME } from \"./default-channel-name\";\nimport { IFrame } from \"./iframe.type\";\n\nexport class IframeMessageService extends mixin(IframeMessageHost, IframeMessageClient) {\n constructor(\n channelName = DEFAULT_CHANNEL_NAME,\n targetFrame?: IFrame\n ) {\n super([channelName, targetFrame], [channelName, targetFrame]);\n }\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const SOURCE_ID_SPLITTER = "__hermes_source_id_splitter__";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/iframe/source-id-splitter.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,kBAAkB,GAAG,+BAA+B,CAAC","file":"source-id-splitter.js","sourcesContent":["export const SOURCE_ID_SPLITTER = '__hermes_source_id_splitter__';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/iframe/upcoming-message.ts"],"names":[],"mappings":"","file":"upcoming-message.js","sourcesContent":["export interface UpcomingMessage<T = any> {\n data: T;\n sender: Window;\n}\n"]}
|
package/index.cjs
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageHost = exports.MessageClient = exports.Listen = exports.Request = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
var request_decorator_1 = require("./request.decorator");
|
|
6
|
+
Object.defineProperty(exports, "Request", { enumerable: true, get: function () { return request_decorator_1.Request; } });
|
|
7
|
+
var listen_decorator_1 = require("./listen.decorator");
|
|
8
|
+
Object.defineProperty(exports, "Listen", { enumerable: true, get: function () { return listen_decorator_1.Listen; } });
|
|
9
|
+
var message_client_1 = require("./message-client");
|
|
10
|
+
Object.defineProperty(exports, "MessageClient", { enumerable: true, get: function () { return message_client_1.MessageClient; } });
|
|
11
|
+
var message_host_1 = require("./message-host");
|
|
12
|
+
Object.defineProperty(exports, "MessageHost", { enumerable: true, get: function () { return message_host_1.MessageHost; } });
|
|
13
|
+
tslib_1.__exportStar(require("./selectors"), exports);
|
package/index.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { Request } from './request.decorator';
|
|
2
|
+
export { Listen } from './listen.decorator';
|
|
3
|
+
export { Message } from './message.interface';
|
|
4
|
+
export { MessageResponse } from './message-response.type';
|
|
5
|
+
export { MessageClient } from './message-client';
|
|
6
|
+
export { MessageHost } from './message-host';
|
|
7
|
+
export * from './selectors';
|
package/index.js
ADDED
package/index.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAG5C,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAC7C,cAAc,aAAa,CAAC","file":"index.js","sourcesContent":["export { Request } from './request.decorator';\nexport { Listen } from './listen.decorator';\nexport { Message } from './message.interface';\nexport { MessageResponse } from './message-response.type';\nexport { MessageClient } from './message-client';\nexport { MessageHost } from './message-host';\nexport * from './selectors';\n"]}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Listen = Listen;
|
|
4
|
+
const selectors_1 = require("./selectors");
|
|
5
|
+
/**
|
|
6
|
+
* Decorate a generator method to listen messages of a domain and reply them by using `yield`
|
|
7
|
+
*
|
|
8
|
+
* @param path Acts like an api endpoint path of an XHR for extensions messaging
|
|
9
|
+
*/
|
|
10
|
+
function Listen(path) {
|
|
11
|
+
return function (target, key, descriptor) {
|
|
12
|
+
if (!target.constructor[selectors_1.MESSAGE_LISTENERS]) {
|
|
13
|
+
target.constructor[selectors_1.MESSAGE_LISTENERS] = new Map();
|
|
14
|
+
}
|
|
15
|
+
target.constructor[selectors_1.MESSAGE_LISTENERS].set(path ?? key, [
|
|
16
|
+
...(target.constructor[selectors_1.MESSAGE_LISTENERS].get(path ?? key) || []),
|
|
17
|
+
descriptor.value
|
|
18
|
+
]);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { MESSAGE_LISTENERS } from './selectors';
|
|
2
|
+
/**
|
|
3
|
+
* Decorate a generator method to listen messages of a domain and reply them by using `yield`
|
|
4
|
+
*
|
|
5
|
+
* @param path Acts like an api endpoint path of an XHR for extensions messaging
|
|
6
|
+
*/
|
|
7
|
+
export function Listen(path) {
|
|
8
|
+
return function (target, key, descriptor) {
|
|
9
|
+
if (!target.constructor[MESSAGE_LISTENERS]) {
|
|
10
|
+
target.constructor[MESSAGE_LISTENERS] = new Map();
|
|
11
|
+
}
|
|
12
|
+
target.constructor[MESSAGE_LISTENERS].set(path ?? key, [
|
|
13
|
+
...(target.constructor[MESSAGE_LISTENERS].get(path ?? key) || []),
|
|
14
|
+
descriptor.value
|
|
15
|
+
]);
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=listen.decorator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/listen.decorator.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AAEhD;;;;GAIG;AACH,MAAM,UAAU,MAAM,CAAC,IAAa;IAClC,OAAO,UAAS,MAAM,EAAE,GAAG,EAAE,UAAU;QACrC,IAAI,CAAE,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAC,EAAE,CAAC;YACnD,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAC,GAAG,IAAI,GAAG,EAAE,CAAC;QAC7D,CAAC;QAEC,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAqB,CAAC,GAAG,CAAC,IAAK,IAAI,GAAG,EAAE;YACpF,GAAG,CAAE,MAAM,CAAC,WAAmB,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;YAC1E,UAAU,CAAC,KAAK;SACV,CAAC,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC","file":"listen.decorator.js","sourcesContent":["import { ListenerStorage } from './listener-storage.type';\nimport { MESSAGE_LISTENERS } from './selectors';\n\n/**\n * Decorate a generator method to listen messages of a domain and reply them by using `yield`\n *\n * @param path Acts like an api endpoint path of an XHR for extensions messaging\n */\nexport function Listen(path?: string): MethodDecorator {\n return function(target, key, descriptor) {\n if (!(target.constructor as any)[MESSAGE_LISTENERS]) {\n (target.constructor as any)[MESSAGE_LISTENERS] = new Map();\n }\n\n ((target.constructor as any)[MESSAGE_LISTENERS] as ListenerStorage).set(path! ?? key, [\n ...((target.constructor as any)[MESSAGE_LISTENERS].get(path ?? key) || []),\n descriptor.value\n ] as any);\n };\n}\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/listener-storage.type.ts"],"names":[],"mappings":"","file":"listener-storage.type.js","sourcesContent":["import { Observable } from 'rxjs';\n\nexport type ListenerStorage<T = any> = Map<string, ((message: any) => Observable<T>)[]>;\n"]}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Observable } from 'rxjs';
|
|
2
|
+
import { MessageResponse } from './message-response.type';
|
|
3
|
+
import { Message } from './message.interface';
|
|
4
|
+
import { GET_NEW_ID, RESPONSES$, SEND } from './selectors';
|
|
5
|
+
/**
|
|
6
|
+
* Message Client
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class MessageClient {
|
|
9
|
+
/**
|
|
10
|
+
* Emits all messages got from hosts
|
|
11
|
+
*/
|
|
12
|
+
protected abstract readonly [RESPONSES$]: Observable<MessageResponse>;
|
|
13
|
+
/**
|
|
14
|
+
* Request decorators use this method to send messages
|
|
15
|
+
*
|
|
16
|
+
* @param message Message payload to send
|
|
17
|
+
*/
|
|
18
|
+
protected abstract [SEND](message: Message): void;
|
|
19
|
+
/**
|
|
20
|
+
* Request decorators use this method to get unique message id all accross the platform
|
|
21
|
+
*/
|
|
22
|
+
protected abstract [GET_NEW_ID](): string;
|
|
23
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/message-client.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAE3D;;GAEG;AACH,MAAM,OAAgB,aAAa;CAiBlC","file":"message-client.js","sourcesContent":["import { Observable } from 'rxjs';\n\nimport { MessageResponse } from './message-response.type';\nimport { Message } from './message.interface';\nimport { GET_NEW_ID, RESPONSES$, SEND } from './selectors';\n\n/**\n * Message Client\n */\nexport abstract class MessageClient {\n /**\n * Emits all messages got from hosts\n */\n protected abstract readonly [RESPONSES$]: Observable<MessageResponse>;\n\n /**\n * Request decorators use this method to send messages\n *\n * @param message Message payload to send\n */\n protected abstract [SEND](message: Message): void;\n\n /**\n * Request decorators use this method to get unique message id all accross the platform\n */\n protected abstract [GET_NEW_ID](): string;\n}\n"]}
|
package/message-host.cjs
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.MessageHost = void 0;
|
|
4
|
+
const rxjs_1 = require("rxjs");
|
|
5
|
+
const operators_1 = require("rxjs/operators");
|
|
6
|
+
const selectors_1 = require("./selectors");
|
|
7
|
+
/**
|
|
8
|
+
* Message Host
|
|
9
|
+
*/
|
|
10
|
+
class MessageHost {
|
|
11
|
+
/**
|
|
12
|
+
* Message Terminator Subject
|
|
13
|
+
*
|
|
14
|
+
* Use `next(messageId)` method to terminate a message connection
|
|
15
|
+
*/
|
|
16
|
+
[selectors_1.TERMINATE_MESSAGE$] = new rxjs_1.Subject();
|
|
17
|
+
/**
|
|
18
|
+
* Run this method to start listening the requests
|
|
19
|
+
*/
|
|
20
|
+
[selectors_1.LISTEN] = (messages$) => {
|
|
21
|
+
for (const [path, listeners] of this.#getListeners()) {
|
|
22
|
+
messages$
|
|
23
|
+
.pipe((0, operators_1.filter)(({ path: messagePath }) => path === messagePath))
|
|
24
|
+
.subscribe(({ body, id }) => {
|
|
25
|
+
for (const listener of listeners) {
|
|
26
|
+
listener.call(this, body).pipe((0, operators_1.takeUntil)(this[selectors_1.TERMINATE_MESSAGE$].pipe((0, operators_1.filter)(terminatedMessageId => terminatedMessageId === id)))).subscribe({
|
|
27
|
+
next: result => {
|
|
28
|
+
this[selectors_1.RESPONSE]({ completed: false, id, body: result });
|
|
29
|
+
},
|
|
30
|
+
error: error => {
|
|
31
|
+
this[selectors_1.RESPONSE]({ completed: true, id, error });
|
|
32
|
+
},
|
|
33
|
+
complete: () => {
|
|
34
|
+
this[selectors_1.RESPONSE]({ completed: true, id });
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* All inherited listeners
|
|
43
|
+
*/
|
|
44
|
+
#getListeners() {
|
|
45
|
+
const map = new Map();
|
|
46
|
+
let currentProto = this['__proto__' + ''];
|
|
47
|
+
while (currentProto.constructor !== Object) {
|
|
48
|
+
if (Reflect.ownKeys(currentProto.constructor).includes(selectors_1.MESSAGE_LISTENERS)) {
|
|
49
|
+
for (const [key, handlers] of currentProto.constructor[selectors_1.MESSAGE_LISTENERS]) {
|
|
50
|
+
map.set(key, [...(map.get(key) || []), ...handlers]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
currentProto = currentProto.__proto__;
|
|
54
|
+
}
|
|
55
|
+
return map;
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
exports.MessageHost = MessageHost;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Observable, Subject } from 'rxjs';
|
|
2
|
+
import { SuccessfulMessageResponse } from './message-response.type';
|
|
3
|
+
import { Message } from './message.interface';
|
|
4
|
+
import { LISTEN, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';
|
|
5
|
+
/**
|
|
6
|
+
* Message Host
|
|
7
|
+
*/
|
|
8
|
+
export declare abstract class MessageHost {
|
|
9
|
+
#private;
|
|
10
|
+
/**
|
|
11
|
+
* Message Terminator Subject
|
|
12
|
+
*
|
|
13
|
+
* Use `next(messageId)` method to terminate a message connection
|
|
14
|
+
*/
|
|
15
|
+
protected readonly [TERMINATE_MESSAGE$]: Subject<string>;
|
|
16
|
+
/**
|
|
17
|
+
* Run this method to start listening the requests
|
|
18
|
+
*/
|
|
19
|
+
protected readonly [LISTEN]: (messages$: Observable<Message>) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Build a reponse method to send the responses to the requests by using the communication methods of the platform
|
|
22
|
+
*
|
|
23
|
+
* @param message Incoming response message
|
|
24
|
+
*/
|
|
25
|
+
protected abstract [RESPONSE]<T = any>(message: SuccessfulMessageResponse<T>): void;
|
|
26
|
+
}
|
package/message-host.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Subject } from 'rxjs';
|
|
2
|
+
import { filter, takeUntil } from 'rxjs/operators';
|
|
3
|
+
import { LISTEN, MESSAGE_LISTENERS, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';
|
|
4
|
+
/**
|
|
5
|
+
* Message Host
|
|
6
|
+
*/
|
|
7
|
+
export class MessageHost {
|
|
8
|
+
/**
|
|
9
|
+
* Message Terminator Subject
|
|
10
|
+
*
|
|
11
|
+
* Use `next(messageId)` method to terminate a message connection
|
|
12
|
+
*/
|
|
13
|
+
[TERMINATE_MESSAGE$] = new Subject();
|
|
14
|
+
/**
|
|
15
|
+
* Run this method to start listening the requests
|
|
16
|
+
*/
|
|
17
|
+
[LISTEN] = (messages$) => {
|
|
18
|
+
for (const [path, listeners] of this.#getListeners()) {
|
|
19
|
+
messages$
|
|
20
|
+
.pipe(filter(({ path: messagePath }) => path === messagePath))
|
|
21
|
+
.subscribe(({ body, id }) => {
|
|
22
|
+
for (const listener of listeners) {
|
|
23
|
+
listener.call(this, body).pipe(takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id)))).subscribe({
|
|
24
|
+
next: result => {
|
|
25
|
+
this[RESPONSE]({ completed: false, id, body: result });
|
|
26
|
+
},
|
|
27
|
+
error: error => {
|
|
28
|
+
this[RESPONSE]({ completed: true, id, error });
|
|
29
|
+
},
|
|
30
|
+
complete: () => {
|
|
31
|
+
this[RESPONSE]({ completed: true, id });
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* All inherited listeners
|
|
40
|
+
*/
|
|
41
|
+
#getListeners() {
|
|
42
|
+
const map = new Map();
|
|
43
|
+
let currentProto = this['__proto__' + ''];
|
|
44
|
+
while (currentProto.constructor !== Object) {
|
|
45
|
+
if (Reflect.ownKeys(currentProto.constructor).includes(MESSAGE_LISTENERS)) {
|
|
46
|
+
for (const [key, handlers] of currentProto.constructor[MESSAGE_LISTENERS]) {
|
|
47
|
+
map.set(key, [...(map.get(key) || []), ...handlers]);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
currentProto = currentProto.__proto__;
|
|
51
|
+
}
|
|
52
|
+
return map;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
//# sourceMappingURL=message-host.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/message-host.ts"],"names":[],"mappings":"AAAA,OAAO,EAAc,OAAO,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKnD,OAAO,EAAE,MAAM,EAAE,iBAAiB,EAAE,QAAQ,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAC;AAEtF;;GAEG;AACH,MAAM,OAAgB,WAAW;IAC/B;;;;OAIG;IACgB,CAAC,kBAAkB,CAAC,GAAG,IAAI,OAAO,EAAU,CAAC;IAEhE;;OAEG;IACgB,CAAC,MAAM,CA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AAI,IAAY,CAAC,WAAW,GAAG,EAAE,CAAC,CAAC;QAEnD,OAAO,YAAY,CAAC,WAAW,KAAK,MAAM,EAAE,CAAC;YAC3C,IAAI,OAAO,CAAC,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC,CAAC,QAAQ,CAAC,iBAAiB,CAAC,EAAE,CAAC;gBAC1E,KAAK,MAAM,CAAC,GAAG,EAAE,QAAQ,CAAC,IAAI,YAAY,CAAC,WAAW,CAAC,iBAAiB,CAAoB,EAAE,CAAC;oBAC7F,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,QAAQ,CAAC,CAAC,CAAC;gBACvD,CAAC;YACH,CAAC;YAED,YAAY,GAAG,YAAY,CAAC,SAAS,CAAC;QACxC,CAAC;QAED,OAAO,GAAG,CAAC;IACb,CAAC;CACF","file":"message-host.js","sourcesContent":["import { Observable, Subject } from 'rxjs';\nimport { filter, takeUntil } from 'rxjs/operators';\n\nimport { ListenerStorage } from './listener-storage.type';\nimport { SuccessfulMessageResponse } from './message-response.type';\nimport { Message } from './message.interface';\nimport { LISTEN, MESSAGE_LISTENERS, RESPONSE, TERMINATE_MESSAGE$ } from './selectors';\n\n/**\n * Message Host\n */\nexport abstract class MessageHost {\n /**\n * Message Terminator Subject\n *\n * Use `next(messageId)` method to terminate a message connection\n */\n protected readonly [TERMINATE_MESSAGE$] = new Subject<string>();\n\n /**\n * Run this method to start listening the requests\n */\n protected readonly [LISTEN] = (messages$: Observable<Message>): void => {\n for (const [path, listeners] of this.#getListeners()) {\n messages$\n .pipe(filter(({path: messagePath}) => path === messagePath))\n .subscribe(({body, id}) => {\n for (const listener of listeners) {\n (listener.call(this, body) as Observable<any>).pipe(\n takeUntil(this[TERMINATE_MESSAGE$].pipe(filter(terminatedMessageId => terminatedMessageId === id))),\n ).subscribe({\n next: result => {\n this[RESPONSE]({completed: false, id, body: result});\n },\n error: error => {\n this[RESPONSE]({completed: true, id, error});\n },\n complete: () => {\n this[RESPONSE]({completed: true, id });\n }\n });\n }\n });\n }\n }\n\n /**\n * Build a reponse method to send the responses to the requests by using the communication methods of the platform\n *\n * @param message Incoming response message\n */\n protected abstract [RESPONSE]<T = any>(message: SuccessfulMessageResponse<T>): void;\n\n /**\n * All inherited listeners\n */\n #getListeners(): ListenerStorage {\n const map: ListenerStorage = new Map();\n\n let currentProto = (this as any)['__proto__' + ''];\n\n while (currentProto.constructor !== Object) {\n if (Reflect.ownKeys(currentProto.constructor).includes(MESSAGE_LISTENERS)) {\n for (const [key, handlers] of currentProto.constructor[MESSAGE_LISTENERS] as ListenerStorage) {\n map.set(key, [...(map.get(key) || []), ...handlers]);\n }\n }\n\n currentProto = currentProto.__proto__;\n }\n\n return map;\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { Message } from './message.interface';
|
|
2
|
+
type Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;
|
|
3
|
+
export type UncompletedMessageResponse<T = any> = Omit<Message<T>, 'path'> & {
|
|
4
|
+
completed: false;
|
|
5
|
+
};
|
|
6
|
+
type CompletedMessageResponse = Omit<Message, 'body' | 'path'> & {
|
|
7
|
+
completed: true;
|
|
8
|
+
};
|
|
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;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/message-response.type.ts"],"names":[],"mappings":"","file":"message-response.type.js","sourcesContent":["import { Message } from './message.interface';\n\ntype Omit<ObjectType, KeysType extends keyof ObjectType> = Pick<ObjectType, Exclude<keyof ObjectType, KeysType>>;\n\nexport type UncompletedMessageResponse<T = any> = Omit<Message<T>, 'path'> & { completed: false; };\ntype CompletedMessageResponse = Omit<Message, 'body' | 'path'> & { completed: true; };\n\nexport type ErrorMessageResponse = {error: any};\nexport type SuccessfulMessageResponse<T = any> = UncompletedMessageResponse<T> | CompletedMessageResponse;\n\nexport type MessageResponse<T = any> = SuccessfulMessageResponse<T> | ErrorMessageResponse;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../../../libs/hermes/src/message.interface.ts"],"names":[],"mappings":"","file":"message.interface.js","sourcesContent":["export interface Message<T = any> {\n path: string;\n body: T;\n id: string;\n error?: any;\n}\n"]}
|