rx-postmessenger 2.0.1 → 4.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.
Files changed (110) hide show
  1. package/LICENSE +2 -2
  2. package/README.md +83 -63
  3. package/{esm → dist}/MessageFactory.d.ts +1 -3
  4. package/dist/MessageFactory.js +34 -0
  5. package/{cjs → dist}/MessageIDGenerator.d.ts +1 -1
  6. package/dist/MessageIDGenerator.js +19 -0
  7. package/{cjs → dist}/MessageValidator.d.ts +3 -4
  8. package/{esm → dist}/MessageValidator.js +19 -20
  9. package/dist/Messenger.d.ts +52 -0
  10. package/dist/Messenger.js +79 -0
  11. package/{cjs → dist}/PostmessageAdapter.d.ts +1 -2
  12. package/dist/PostmessageAdapter.js +11 -0
  13. package/dist/RxPostmessengerRequest.d.ts +11 -0
  14. package/dist/RxPostmessengerRequest.js +23 -0
  15. package/dist/functions/GUIDGenerator.d.ts +1 -0
  16. package/dist/functions/GUIDGenerator.js +10 -0
  17. package/dist/index.d.ts +4 -0
  18. package/dist/index.js +14 -0
  19. package/dist/public-api.d.ts +55 -0
  20. package/dist/public-api.js +1 -0
  21. package/dist/types.d.ts +58 -0
  22. package/dist/types.js +1 -0
  23. package/package.json +39 -47
  24. package/CHANGELOG.md +0 -159
  25. package/cjs/MessageFactory.d.ts +0 -11
  26. package/cjs/MessageFactory.js +0 -38
  27. package/cjs/MessageFactory.js.map +0 -1
  28. package/cjs/MessageIDGenerator.js +0 -24
  29. package/cjs/MessageIDGenerator.js.map +0 -1
  30. package/cjs/MessageValidator.js +0 -44
  31. package/cjs/MessageValidator.js.map +0 -1
  32. package/cjs/Messenger.d.ts +0 -99
  33. package/cjs/Messenger.js +0 -116
  34. package/cjs/Messenger.js.map +0 -1
  35. package/cjs/PostmessageAdapter.js +0 -14
  36. package/cjs/PostmessageAdapter.js.map +0 -1
  37. package/cjs/RxPostmessengerRequest.d.ts +0 -10
  38. package/cjs/RxPostmessengerRequest.js +0 -23
  39. package/cjs/RxPostmessengerRequest.js.map +0 -1
  40. package/cjs/functions/GUIDGenerator.d.ts +0 -1
  41. package/cjs/functions/GUIDGenerator.js +0 -59
  42. package/cjs/functions/GUIDGenerator.js.map +0 -1
  43. package/cjs/index.d.ts +0 -4
  44. package/cjs/index.js +0 -20
  45. package/cjs/index.js.map +0 -1
  46. package/cjs/interface/id-generator.d.ts +0 -11
  47. package/cjs/interface/id-generator.js +0 -3
  48. package/cjs/interface/id-generator.js.map +0 -1
  49. package/cjs/interface/message-factory.d.ts +0 -7
  50. package/cjs/interface/message-factory.js +0 -3
  51. package/cjs/interface/message-factory.js.map +0 -1
  52. package/cjs/interface/message-objects.d.ts +0 -30
  53. package/cjs/interface/message-objects.js +0 -3
  54. package/cjs/interface/message-objects.js.map +0 -1
  55. package/cjs/interface/message-validator.d.ts +0 -7
  56. package/cjs/interface/message-validator.js +0 -3
  57. package/cjs/interface/message-validator.js.map +0 -1
  58. package/cjs/interface/postmessage-adapter.d.ts +0 -6
  59. package/cjs/interface/postmessage-adapter.js +0 -3
  60. package/cjs/interface/postmessage-adapter.js.map +0 -1
  61. package/cjs/interface/public-interface.d.ts +0 -4
  62. package/cjs/interface/public-interface.js +0 -3
  63. package/cjs/interface/public-interface.js.map +0 -1
  64. package/esm/MessageFactory.js +0 -36
  65. package/esm/MessageFactory.js.map +0 -1
  66. package/esm/MessageIDGenerator.d.ts +0 -8
  67. package/esm/MessageIDGenerator.js +0 -22
  68. package/esm/MessageIDGenerator.js.map +0 -1
  69. package/esm/MessageValidator.d.ts +0 -30
  70. package/esm/MessageValidator.js.map +0 -1
  71. package/esm/Messenger.d.ts +0 -99
  72. package/esm/Messenger.js +0 -114
  73. package/esm/Messenger.js.map +0 -1
  74. package/esm/PostmessageAdapter.d.ts +0 -8
  75. package/esm/PostmessageAdapter.js +0 -12
  76. package/esm/PostmessageAdapter.js.map +0 -1
  77. package/esm/RxPostmessengerRequest.d.ts +0 -10
  78. package/esm/RxPostmessengerRequest.js +0 -21
  79. package/esm/RxPostmessengerRequest.js.map +0 -1
  80. package/esm/functions/GUIDGenerator.d.ts +0 -1
  81. package/esm/functions/GUIDGenerator.js +0 -56
  82. package/esm/functions/GUIDGenerator.js.map +0 -1
  83. package/esm/index.d.ts +0 -4
  84. package/esm/index.js +0 -17
  85. package/esm/index.js.map +0 -1
  86. package/esm/interface/id-generator.d.ts +0 -11
  87. package/esm/interface/id-generator.js +0 -1
  88. package/esm/interface/id-generator.js.map +0 -1
  89. package/esm/interface/message-factory.d.ts +0 -7
  90. package/esm/interface/message-factory.js +0 -1
  91. package/esm/interface/message-factory.js.map +0 -1
  92. package/esm/interface/message-objects.d.ts +0 -30
  93. package/esm/interface/message-objects.js +0 -1
  94. package/esm/interface/message-objects.js.map +0 -1
  95. package/esm/interface/message-validator.d.ts +0 -7
  96. package/esm/interface/message-validator.js +0 -1
  97. package/esm/interface/message-validator.js.map +0 -1
  98. package/esm/interface/postmessage-adapter.d.ts +0 -6
  99. package/esm/interface/postmessage-adapter.js +0 -1
  100. package/esm/interface/postmessage-adapter.js.map +0 -1
  101. package/esm/interface/public-interface.d.ts +0 -4
  102. package/esm/interface/public-interface.js +0 -1
  103. package/esm/interface/public-interface.js.map +0 -1
  104. package/karma.conf.js +0 -99
  105. package/rx-postmessenger.d.ts +0 -74
  106. package/umd/rx-postmessenger.js +0 -10827
  107. package/umd/rx-postmessenger.js.map +0 -1
  108. package/umd/rx-postmessenger.min.js +0 -17
  109. package/umd/rx-postmessenger.min.js.map +0 -1
  110. package/yarn-error.log +0 -4522
package/esm/Messenger.js DELETED
@@ -1,114 +0,0 @@
1
- // -----------------------------------------------------------------------------
2
- // Concrete imports
3
- // -----------------------------------------------------------------------------
4
- import { fromEvent } from 'rxjs';
5
- import { filter, map, pluck, take } from 'rxjs/operators';
6
- import { RxPostmessengerRequest } from './RxPostmessengerRequest';
7
- var Messenger = /** @class */ (function () {
8
- /**
9
- * @param {IMessageFactory} messageFactory - Factory instance for scalar message objects.
10
- * @param {IMessageValidator} messageValidator - Validator instance for incoming messages.
11
- * @param {IPostmessageAdapter} adapter - Adapter for interacting with the postMessage API
12
- */
13
- function Messenger(messageFactory, messageValidator, adapter) {
14
- var _this = this;
15
- this.messageFactory = messageFactory;
16
- this.messageValidator = messageValidator;
17
- this.adapter = adapter;
18
- this.inboundMessages$ = fromEvent(window, 'message').pipe(filter(function (message) { return _this.messageValidator.validate(message); }), pluck('data'));
19
- this.requests$ = this.messagesOfType('request');
20
- this.responses$ = this.messagesOfType('response');
21
- this.notifications$ = this.messagesOfType('notification');
22
- this.inboundMessages$.subscribe(function (_a) {
23
- var id = _a.id;
24
- return _this.messageFactory.invalidateID(id);
25
- });
26
- }
27
- /**
28
- *
29
- * Send a request over given channel with given payload. Returns an observable that will
30
- * emit the response and then complete.
31
- *
32
- * @param {string} channel The channel name of the request.
33
- * @param {*} [payload] The payload to send along with the request.
34
- */
35
- Messenger.prototype.request = function (channel, payload) {
36
- var request = this.messageFactory.makeRequest(channel, payload);
37
- var responseObservable = this.createResponseObservable(request.id);
38
- this.adapter.postMessage(request);
39
- return responseObservable;
40
- };
41
- /**
42
- * Send a notification over given channel with given payload.
43
- *
44
- * @param {string} channel - The channel name of the notification.
45
- * @param {*} [payload] - The payload to send along with the notification.
46
- */
47
- Messenger.prototype.notify = function (channel, payload) {
48
- this.adapter.postMessage(this.messageFactory.makeNotification(channel, payload));
49
- };
50
- /**
51
- * Returns an Observable that emits the subset of inbound notification messages where their
52
- * channel equals given channel name.
53
- *
54
- * @param {string} channel - The request channel name to listen to.
55
- * @return {Observable<object>}
56
- * @public
57
- */
58
- Messenger.prototype.requests = function (channel) {
59
- var _this = this;
60
- return this.requests$.pipe(filter(function (request) { return request.channel === channel; }), map(function (request) { return new RxPostmessengerRequest(request.id, request.channel, request.payload, function (payload) { return _this.respond(request.id, channel, payload); }); }));
61
- };
62
- /**
63
- * Returns an Observable that emits the subset of inbound notification messages where their
64
- * channel equals given channel name.
65
- *
66
- * @param {string} channel - The notification channel name to listen to.
67
- * @return {Observable<*>}
68
- * @public
69
- */
70
- Messenger.prototype.notifications = function (channel) {
71
- return this.notifications$.pipe(filter(function (notification) { return notification.channel === channel; }), pluck('payload'));
72
- };
73
- /**
74
- * Sends a response through given channel to the remote window, carrying given payload.
75
- *
76
- * @param {string} requestId - The request ID of the original request
77
- * @param {string} channel - The request-channel name to send the response over
78
- * @param {*} payload - The response payload
79
- * @return {Messenger}
80
- * @protected
81
- */
82
- Messenger.prototype.respond = function (requestId, channel, payload) {
83
- this.adapter.postMessage(this.messageFactory.makeResponse(requestId, channel, payload));
84
- return this;
85
- };
86
- /**
87
- * Creates an Observable that completes after a single emission of the MessageEvent response for request of given
88
- * requestId. If no matching response is ever received, the Observable never completes.
89
- *
90
- * @param {string} requestId
91
- * @return {Observable<object>}
92
- * @protected
93
- */
94
- Messenger.prototype.createResponseObservable = function (requestId) {
95
- return this.responses$.pipe(filter(function (response) { return response.requestId === requestId; }), pluck('payload'), take(1));
96
- };
97
- /**
98
- * Returns an Observable emitting all inbound messages` of given type.
99
- *
100
- * Returns an Observable emitting a subset of MessageEvent objects emitted
101
- * by this.inboundMessages$, passing through all MessageEvent objects whose
102
- * data.type property matches given type.
103
- *
104
- * @param {string} type
105
- * @return {Observable<object>}
106
- * @protected
107
- */
108
- Messenger.prototype.messagesOfType = function (type) {
109
- return this.inboundMessages$.pipe(filter(function (message) { return message.type === type; }));
110
- };
111
- return Messenger;
112
- }());
113
- export { Messenger };
114
- //# sourceMappingURL=Messenger.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"Messenger.js","sourceRoot":"","sources":["../src/Messenger.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF,OAAO,EAAE,SAAS,EAAc,MAAM,MAAM,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC1D,OAAO,EAAE,sBAAsB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C,QAAQ,IAAqC,OAAA,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAhC,CAAgC,CAAC,EACtF,KAAK,CAAwB,SAAS,CAAC,EACvC,IAAI,CAAC,CAAC,CAAC,CACV,CAAC;IACN,CAAC;IAED;;;;;;;;;;OAUG;IACO,kCAAc,GAAxB,UAAgD,IAAO;QACnD,OAAO,IAAI,CAAC,gBAAgB,CAAC,IAAI,CAC7B,MAAM,CAAC,UAAC,OAAO,IAAkC,OAAA,OAAO,CAAC,IAAI,KAAK,IAAI,EAArB,CAAqB,CAAC,CAC1E,CAAC;IACN,CAAC;IACL,gBAAC;AAAD,CAAC,AAnKD,IAmKC"}
@@ -1,8 +0,0 @@
1
- import { AnyMessage } from './interface/message-objects';
2
- import { IPostmessageAdapter } from './interface/postmessage-adapter';
3
- export declare class PostmessageAdapter implements IPostmessageAdapter {
4
- readonly targetWindow: Window;
5
- readonly targetOrigin: string;
6
- constructor(targetWindow: Window, targetOrigin: string);
7
- postMessage<T extends AnyMessage>(data: T): void;
8
- }
@@ -1,12 +0,0 @@
1
- var PostmessageAdapter = /** @class */ (function () {
2
- function PostmessageAdapter(targetWindow, targetOrigin) {
3
- this.targetWindow = targetWindow;
4
- this.targetOrigin = targetOrigin;
5
- }
6
- PostmessageAdapter.prototype.postMessage = function (data) {
7
- this.targetWindow.postMessage(data, this.targetOrigin);
8
- };
9
- return PostmessageAdapter;
10
- }());
11
- export { PostmessageAdapter };
12
- //# sourceMappingURL=PostmessageAdapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"PostmessageAdapter.js","sourceRoot":"","sources":["../src/PostmessageAdapter.ts"],"names":[],"mappings":"AAGA;IAEI,4BACoB,YAAoB,EACpB,YAAoB;QADpB,iBAAY,GAAZ,YAAY,CAAQ;QACpB,iBAAY,GAAZ,YAAY,CAAQ;IACrC,CAAC;IAEG,wCAAW,GAAlB,UAAyC,IAAO;QAE5C,IAAI,CAAC,YAAY,CAAC,WAAW,CAAC,IAAI,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC;IAC3D,CAAC;IACL,yBAAC;AAAD,CAAC,AAXD,IAWC"}
@@ -1,10 +0,0 @@
1
- import { IRequest } from './interface/public-interface';
2
- export declare class RxPostmessengerRequest<T, U> implements IRequest<T, U> {
3
- readonly channel: string;
4
- readonly payload: T;
5
- readonly isHandled: boolean;
6
- readonly id: string;
7
- private readonly _injectResponse;
8
- constructor(id: string, channel: string, payload: T, responseInjector: (data: U) => void);
9
- respond(data: U): void;
10
- }
@@ -1,21 +0,0 @@
1
- var RxPostmessengerRequest = /** @class */ (function () {
2
- function RxPostmessengerRequest(id, channel, payload, responseInjector) {
3
- this.isHandled = false;
4
- Object.defineProperties(this, {
5
- _injectResponse: { value: responseInjector },
6
- channel: { value: channel },
7
- id: { value: id },
8
- payload: { value: payload },
9
- });
10
- }
11
- RxPostmessengerRequest.prototype.respond = function (data) {
12
- if (this.isHandled) {
13
- return;
14
- }
15
- this._injectResponse(data);
16
- Object.defineProperty(this, 'isHandled', { value: true });
17
- };
18
- return RxPostmessengerRequest;
19
- }());
20
- export { RxPostmessengerRequest };
21
- //# sourceMappingURL=RxPostmessengerRequest.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RxPostmessengerRequest.js","sourceRoot":"","sources":["../src/RxPostmessengerRequest.ts"],"names":[],"mappings":"AAEA;IASI,gCACI,EAAU,EACV,OAAe,EACf,OAAU,EACV,gBAAmC;QATvB,cAAS,GAAY,KAAK,CAAC;QAWvC,MAAM,CAAC,gBAAgB,CAAC,IAAI,EAAE;YAC1B,eAAe,EAAE,EAAE,KAAK,EAAE,gBAAgB,EAAE;YAC5C,OAAO,EAAU,EAAE,KAAK,EAAE,OAAO,EAAE;YACnC,EAAE,EAAe,EAAE,KAAK,EAAE,EAAE,EAAE;YAC9B,OAAO,EAAU,EAAE,KAAK,EAAE,OAAO,EAAE;SACtC,CAAC,CAAC;IACP,CAAC;IAEM,wCAAO,GAAd,UAAe,IAAO;QAClB,IAAI,IAAI,CAAC,SAAS,EAAE;YAChB,OAAO;SACV;QAED,IAAI,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;QAC3B,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,WAAW,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IAC9D,CAAC;IACL,6BAAC;AAAD,CAAC,AA/BD,IA+BC"}
@@ -1 +0,0 @@
1
- export declare function GUIDGenerator(): IterableIterator<string>;
@@ -1,56 +0,0 @@
1
- var __generator = (this && this.__generator) || function (thisArg, body) {
2
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
3
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
4
- function verb(n) { return function (v) { return step([n, v]); }; }
5
- function step(op) {
6
- if (f) throw new TypeError("Generator is already executing.");
7
- while (_) try {
8
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
9
- if (y = 0, t) op = [op[0] & 2, t.value];
10
- switch (op[0]) {
11
- case 0: case 1: t = op; break;
12
- case 4: _.label++; return { value: op[1], done: false };
13
- case 5: _.label++; y = op[1]; op = [0]; continue;
14
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
15
- default:
16
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
17
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
18
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
19
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
20
- if (t[2]) _.ops.pop();
21
- _.trys.pop(); continue;
22
- }
23
- op = body.call(thisArg, _);
24
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
25
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
26
- }
27
- };
28
- export function GUIDGenerator() {
29
- var s4, IDSegment, guid;
30
- return __generator(this, function (_a) {
31
- switch (_a.label) {
32
- case 0:
33
- s4 = function () { return Math.floor((1 + Math.random()) * 0x10000).toString(16).substring(1); };
34
- IDSegment = function (size) {
35
- if (size === void 0) { size = 1; }
36
- return Array(size).fill(null).map(s4).join('');
37
- };
38
- guid = function () { return [
39
- IDSegment(2),
40
- IDSegment(),
41
- IDSegment(),
42
- IDSegment(),
43
- IDSegment(3),
44
- ].join('-'); };
45
- _a.label = 1;
46
- case 1:
47
- if (!true) return [3 /*break*/, 3];
48
- return [4 /*yield*/, guid()];
49
- case 2:
50
- _a.sent();
51
- return [3 /*break*/, 1];
52
- case 3: return [2 /*return*/];
53
- }
54
- });
55
- }
56
- //# sourceMappingURL=GUIDGenerator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"GUIDGenerator.js","sourceRoot":"","sources":["../../src/functions/GUIDGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,MAAM,UAAW,aAAa;;;;;gBACpB,EAAE,GAAG,cAAc,OAAA,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAnE,CAAmE,CAAC;gBACvF,SAAS,GAAG,UAAC,IAAgB;oBAAhB,qBAAA,EAAA,QAAgB;oBAAK,OAAA,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;gBAAvC,CAAuC,CAAC;gBAC1E,IAAI,GAAiB,cAAM,OAAA;oBAC7B,SAAS,CAAC,CAAC,CAAC;oBACZ,SAAS,EAAE;oBACX,SAAS,EAAE;oBACX,SAAS,EAAE;oBACX,SAAS,CAAC,CAAC,CAAC;iBACf,CAAC,IAAI,CAAC,GAAG,CAAC,EANsB,CAMtB,CAAC;;;qBAEL,IAAI;gBACP,qBAAM,IAAI,EAAE,EAAA;;gBAAZ,SAAY,CAAC;;;;;CAEpB"}
package/esm/index.d.ts DELETED
@@ -1,4 +0,0 @@
1
- import { IMessenger, IStatic } from './interface/public-interface';
2
- export declare function connect(remoteWindow: Window, remoteOrigin: string): IMessenger;
3
- declare const defaultNamespace: IStatic;
4
- export default defaultNamespace;
package/esm/index.js DELETED
@@ -1,17 +0,0 @@
1
- import { MessageFactory } from './MessageFactory';
2
- import { MessageIDGenerator } from './MessageIDGenerator';
3
- import { MessageValidator } from './MessageValidator';
4
- import { Messenger } from './Messenger';
5
- import { PostmessageAdapter } from './PostmessageAdapter';
6
- export function connect(remoteWindow, remoteOrigin) {
7
- if (window === remoteWindow) {
8
- throw new Error('Remote window can not be the same as the local window environment');
9
- }
10
- return new Messenger(new MessageFactory(new MessageIDGenerator()), new MessageValidator(remoteWindow, remoteOrigin), new PostmessageAdapter(remoteWindow, remoteOrigin));
11
- }
12
- // ---------------------------------------------------------------------------------------
13
- // API Exports
14
- // ---------------------------------------------------------------------------------------
15
- var defaultNamespace = { connect: connect };
16
- export default defaultNamespace;
17
- //# sourceMappingURL=index.js.map
package/esm/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAE1D,MAAM,UAAU,OAAO,CAAC,YAAoB,EAAE,YAAoB;IAE9D,IAAI,MAAM,KAAK,YAAY,EAAE;QACzB,MAAM,IAAI,KAAK,CAAC,mEAAmE,CAAC,CAAC;KACxF;IAED,OAAO,IAAI,SAAS,CAChB,IAAI,cAAc,CACd,IAAI,kBAAkB,EAAE,CAC3B,EACD,IAAI,gBAAgB,CAAC,YAAY,EAAE,YAAY,CAAC,EAChD,IAAI,kBAAkB,CAAC,YAAY,EAAE,YAAY,CAAC,CACrD,CAAC;AACN,CAAC;AAED,0FAA0F;AAC1F,cAAc;AACd,0FAA0F;AAE1F,IAAM,gBAAgB,GAAY,EAAE,OAAO,SAAA,EAAE,CAAC;AAC9C,eAAe,gBAAgB,CAAC"}
@@ -1,11 +0,0 @@
1
- export interface IMessageIDGenerator {
2
- /**
3
- * Get a new unique ID value for message objects.
4
- */
5
- generateID(): string;
6
- /**
7
- * Invalidates an ID value - marks it a used. This is a required
8
- * feature for syncing the used ID values
9
- */
10
- invalidateID(id: string): void;
11
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=id-generator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"id-generator.js","sourceRoot":"","sources":["../../src/interface/id-generator.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- import { INotificationObject, IRequestObject, IResponseObject } from './message-objects';
2
- export interface IMessageFactory {
3
- invalidateID(id: string): void;
4
- makeRequest<T>(channel: string, payload: T): IRequestObject<T>;
5
- makeResponse<T>(requestId: string, channel: string, payload: T): IResponseObject<T>;
6
- makeNotification<T>(channel: string, payload: T): INotificationObject<T>;
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=message-factory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-factory.js","sourceRoot":"","sources":["../../src/interface/message-factory.ts"],"names":[],"mappings":""}
@@ -1,30 +0,0 @@
1
- /**
2
- * The IMessageObject interface defines the format for data property values of MessageEvent objects.
3
- * This interface describes the actual format of data sent with postMessage that is required for
4
- * another RxPostmessenger on the other end of the line to be able to correctly interpret the
5
- * message.
6
- */
7
- export interface IMessageObject<T = any> {
8
- readonly id: string;
9
- readonly type: MessageType;
10
- readonly channel: string;
11
- readonly payload: T;
12
- }
13
- export interface IRequestObject<T = any> extends IMessageObject<T> {
14
- readonly type: 'request';
15
- }
16
- export interface IResponseObject<T = any> extends IMessageObject<T> {
17
- readonly requestId: string;
18
- readonly type: 'response';
19
- }
20
- export interface INotificationObject<T = any> extends IMessageObject<T> {
21
- readonly type: 'notification';
22
- }
23
- export declare type AnyMessage = IRequestObject | IResponseObject | INotificationObject;
24
- export interface IMessageTypeMap<T = any> {
25
- request: IRequestObject;
26
- response: IResponseObject;
27
- notification: INotificationObject;
28
- }
29
- export declare type MessageType = keyof IMessageTypeMap;
30
- export declare type MappedMessage<T extends MessageType> = IMessageTypeMap[T];
@@ -1 +0,0 @@
1
- //# sourceMappingURL=message-objects.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-objects.js","sourceRoot":"","sources":["../../src/interface/message-objects.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- import { AnyMessage } from './message-objects';
2
- export interface IOwnMessageEvent<T> extends MessageEvent {
3
- readonly data: T;
4
- }
5
- export interface IMessageValidator {
6
- validate(message: MessageEvent): message is IOwnMessageEvent<AnyMessage>;
7
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=message-validator.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"message-validator.js","sourceRoot":"","sources":["../../src/interface/message-validator.ts"],"names":[],"mappings":""}
@@ -1,6 +0,0 @@
1
- import { AnyMessage } from './message-objects';
2
- export interface IPostmessageAdapter {
3
- readonly targetWindow: Window;
4
- readonly targetOrigin: string;
5
- postMessage<T extends AnyMessage>(data: T): void;
6
- }
@@ -1 +0,0 @@
1
- //# sourceMappingURL=postmessage-adapter.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"postmessage-adapter.js","sourceRoot":"","sources":["../../src/interface/postmessage-adapter.ts"],"names":[],"mappings":""}
@@ -1,4 +0,0 @@
1
- import PublicInterface from '../../rx-postmessenger';
2
- export import IStatic = PublicInterface.Static;
3
- export import IMessenger = PublicInterface.Messenger;
4
- export import IRequest = PublicInterface.Request;
@@ -1 +0,0 @@
1
- //# sourceMappingURL=public-interface.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"public-interface.js","sourceRoot":"","sources":["../../src/interface/public-interface.ts"],"names":[],"mappings":""}
package/karma.conf.js DELETED
@@ -1,99 +0,0 @@
1
- module.exports = function(config) {
2
-
3
- const karmaPlugins = [
4
- require('karma-chai'),
5
- require('karma-chrome-launcher'),
6
- require('karma-coverage'),
7
- require('karma-coveralls'),
8
- require('karma-mocha'),
9
- require('karma-mocha-reporter'),
10
- require('karma-remap-coverage'),
11
- require('karma-sinon'),
12
- require('karma-sourcemap-loader'),
13
- require('karma-webpack'),
14
- ];
15
-
16
- const options = {
17
- frameworks: ["mocha", "chai", "sinon"],
18
- files: [
19
- __dirname + '/test/karma-test-shim.spec.ts'
20
- ],
21
- mime: {
22
- 'text/x-typescript': ['ts', 'tsx']
23
- },
24
- client: {
25
- clearContext: false // leave Spec Runner output visible in browser
26
- },
27
- autoWatch: true,
28
- singleRun: false,
29
- plugins: karmaPlugins,
30
-
31
- preprocessors: {
32
- [__dirname + '/test/karma-test-shim.spec.ts']: ['webpack', 'sourcemap'],
33
- [__dirname + '/src/**/*.ts']: ['coverage'],
34
- },
35
-
36
- webpack: {
37
- mode: 'development',
38
- devtool: "inline-source-map",
39
- resolve: {
40
- extensions: [".ts", ".js"]
41
- },
42
- module: {
43
- rules: [
44
- {
45
- test: /\.ts$/,
46
- loader: "ts-loader",
47
- exclude: /node_modules/,
48
- options: {
49
- compilerOptions: {
50
- outDir: __dirname,
51
- declaration: false,
52
- }
53
- }
54
- },
55
- // instrument only testing sources with Istanbul
56
- {
57
- enforce: 'post',
58
- test: /\.ts$/,
59
- loader: 'istanbul-instrumenter-loader?embedSource=true&noAutoWrap=true',
60
- exclude: /(\.(e2e|spec|mock|spec-helper)\.ts|node_modules)$/,
61
- }
62
- ],
63
- }
64
- },
65
-
66
- reporters: [
67
- 'remap-coverage',
68
- 'coverage',
69
- 'mocha',
70
- ],
71
-
72
- browsers: ['ChromeHeadless'],
73
-
74
- mochaReporter: {
75
- showDiff: true,
76
- },
77
-
78
- coverageReporter: {
79
- type: 'in-memory',
80
- },
81
-
82
- remapCoverageReporter: {
83
- 'text-summary': null,
84
- lcovonly: './coverage/lcov.info',
85
- html: './coverage/html',
86
- cobertura: './coverage/cobertura.xml',
87
- json: './coverage/coverage.json'
88
- },
89
- };
90
-
91
- if (process.env.TRAVIS) {
92
- options.autoWatch = false;
93
- options.singleRun = true;
94
- options.concurrency = 1;
95
- options.reporters.push('coveralls');
96
- }
97
-
98
- config.set(options);
99
- };
@@ -1,74 +0,0 @@
1
- import { Observable } from 'rxjs';
2
-
3
- declare const RxPostmessenger: RxPostmessenger.Static;
4
- export default RxPostmessenger;
5
- export as namespace RxPostmessenger;
6
-
7
- // tslint:disable:interface-name
8
-
9
- declare namespace RxPostmessenger {
10
-
11
- interface Static {
12
- /**
13
- * Create a new messenger for given window object. The remoteOrigin URL is used both to give to window.postMessage
14
- * calls on remoteWindow, and to filter inbound-message-events on the local window object.
15
- */
16
- connect(remoteWindow: Window, remoteOrigin: string): RxPostmessenger.Messenger;
17
- }
18
-
19
- interface Messenger {
20
-
21
- /**
22
- * Returns an Observable that emits all incoming notifications for given notification-channel.
23
- */
24
- notifications<T = any>(channel: string): Observable<T>;
25
-
26
- /**
27
- * Send a notification over given channel with given payload.
28
- */
29
- notify<T>(channel: string, payload?: T): void;
30
-
31
- /**
32
- * Send a request over given channel with given payload. Returns an observable that will emit the response
33
- * and then complete.
34
- */
35
- request<T = any, U = any>(channel: string, payload?: T): Observable<U>;
36
-
37
- /**
38
- * Returns an Observable that emits all incoming requests for given request-channel.
39
- */
40
- requests<T = any, U = any>(channel: string): Observable<Request<T, U>>;
41
- }
42
-
43
- /**
44
- *
45
- */
46
- interface Request<T, U> {
47
-
48
- /**
49
- * The name of the channel the request was sent through. The
50
- * channel literal is immutable. Attempts to override the
51
- * channel property
52
- */
53
- readonly channel: string;
54
-
55
- /**
56
- * The payload data for the request. The payload is immutable.
57
- * Attempts to set / override payload values will silently fail.
58
- * Attempts to mutate members of object-type payloads will
59
- * silently fail as well.
60
- */
61
- readonly payload: T;
62
-
63
- /**
64
- * Boolean indicating whether respond() has been called on the request
65
- * previously.
66
- */
67
- readonly isHandled: boolean;
68
-
69
- /**
70
- * Respond to the request with given data.
71
- */
72
- respond(data: U): void;
73
- }
74
- }