@aws-amplify/pubsub 6.0.1-api-v6-models.9351bcf.0 → 6.0.1-api-v6-models.891fe0d.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.
@@ -1,6 +1,5 @@
1
1
  // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
2
2
  // SPDX-License-Identifier: Apache-2.0
3
- import { __assign, __awaiter, __extends, __generator, __rest } from "tslib";
4
3
  // @ts-ignore
5
4
  import * as Paho from '../vendor/paho-mqtt';
6
5
  import { Observable } from 'rxjs';
@@ -11,14 +10,14 @@ import { amplifyUuid } from '@aws-amplify/core/internals/utils';
11
10
  import { ConnectionStateMonitor, CONNECTION_CHANGE, } from '../utils/ConnectionStateMonitor';
12
11
  import { ReconnectEvent, ReconnectionMonitor, } from '../utils/ReconnectionMonitor';
13
12
  import { AMPLIFY_SYMBOL, CONNECTION_STATE_CHANGE } from './constants';
14
- var logger = new Logger('MqttOverWS');
13
+ const logger = new Logger('MqttOverWS');
15
14
  export function mqttTopicMatch(filter, topic) {
16
- var filterArray = filter.split('/');
17
- var length = filterArray.length;
18
- var topicArray = topic.split('/');
19
- for (var i = 0; i < length; ++i) {
20
- var left = filterArray[i];
21
- var right = topicArray[i];
15
+ const filterArray = filter.split('/');
16
+ const length = filterArray.length;
17
+ const topicArray = topic.split('/');
18
+ for (let i = 0; i < length; ++i) {
19
+ const left = filterArray[i];
20
+ const right = topicArray[i];
22
21
  if (left === '#')
23
22
  return topicArray.length >= length;
24
23
  if (left !== '+' && left !== right)
@@ -26,369 +25,244 @@ export function mqttTopicMatch(filter, topic) {
26
25
  }
27
26
  return length === topicArray.length;
28
27
  }
29
- var ClientsQueue = /** @class */ (function () {
30
- function ClientsQueue() {
28
+ class ClientsQueue {
29
+ constructor() {
31
30
  this.promises = new Map();
32
31
  }
33
- ClientsQueue.prototype.get = function (clientId, clientFactory) {
34
- return __awaiter(this, void 0, void 0, function () {
35
- var cachedPromise, newPromise;
36
- var _this = this;
37
- return __generator(this, function (_a) {
38
- cachedPromise = this.promises.get(clientId);
39
- if (cachedPromise)
40
- return [2 /*return*/, cachedPromise];
41
- if (clientFactory) {
42
- newPromise = clientFactory(clientId);
43
- this.promises.set(clientId, newPromise);
44
- newPromise.catch(function () { return _this.promises.delete(clientId); });
45
- return [2 /*return*/, newPromise];
46
- }
47
- return [2 /*return*/, undefined];
48
- });
49
- });
50
- };
51
- Object.defineProperty(ClientsQueue.prototype, "allClients", {
52
- get: function () {
53
- return Array.from(this.promises.keys());
54
- },
55
- enumerable: false,
56
- configurable: true
57
- });
58
- ClientsQueue.prototype.remove = function (clientId) {
32
+ async get(clientId, clientFactory) {
33
+ const cachedPromise = this.promises.get(clientId);
34
+ if (cachedPromise)
35
+ return cachedPromise;
36
+ if (clientFactory) {
37
+ const newPromise = clientFactory(clientId);
38
+ this.promises.set(clientId, newPromise);
39
+ newPromise.catch(() => this.promises.delete(clientId));
40
+ return newPromise;
41
+ }
42
+ return undefined;
43
+ }
44
+ get allClients() {
45
+ return Array.from(this.promises.keys());
46
+ }
47
+ remove(clientId) {
59
48
  this.promises.delete(clientId);
60
- };
61
- return ClientsQueue;
62
- }());
63
- var dispatchPubSubEvent = function (payload) {
49
+ }
50
+ }
51
+ const dispatchPubSubEvent = (payload) => {
64
52
  Hub.dispatch('pubsub', payload, 'PubSub', AMPLIFY_SYMBOL);
65
53
  };
66
- var topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
67
- var MqttOverWS = /** @class */ (function (_super) {
68
- __extends(MqttOverWS, _super);
69
- function MqttOverWS(options) {
70
- if (options === void 0) { options = {}; }
71
- var _this = _super.call(this, __assign(__assign({}, options), { clientId: options.clientId || amplifyUuid() })) || this;
72
- _this._clientsQueue = new ClientsQueue();
73
- _this.connectionStateMonitor = new ConnectionStateMonitor();
74
- _this.reconnectionMonitor = new ReconnectionMonitor();
75
- _this._topicObservers = new Map();
76
- _this._clientIdObservers = new Map();
54
+ const topicSymbol = typeof Symbol !== 'undefined' ? Symbol('topic') : '@@topic';
55
+ export class MqttOverWS extends AbstractPubSub {
56
+ constructor(options = {}) {
57
+ super({ ...options, clientId: options.clientId || amplifyUuid() });
58
+ this._clientsQueue = new ClientsQueue();
59
+ this.connectionStateMonitor = new ConnectionStateMonitor();
60
+ this.reconnectionMonitor = new ReconnectionMonitor();
61
+ this._topicObservers = new Map();
62
+ this._clientIdObservers = new Map();
77
63
  // Monitor the connection health state and pass changes along to Hub
78
- _this.connectionStateMonitor.connectionStateObservable.subscribe(function (connectionStateChange) {
64
+ this.connectionStateMonitor.connectionStateObservable.subscribe(connectionStateChange => {
79
65
  dispatchPubSubEvent({
80
66
  event: CONNECTION_STATE_CHANGE,
81
67
  data: {
82
- provider: _this,
68
+ provider: this,
83
69
  connectionState: connectionStateChange,
84
70
  },
85
- message: "Connection state is ".concat(connectionStateChange),
71
+ message: `Connection state is ${connectionStateChange}`,
86
72
  });
87
- _this.connectionState = connectionStateChange;
73
+ this.connectionState = connectionStateChange;
88
74
  // Trigger reconnection when the connection is disrupted
89
75
  if (connectionStateChange === ConnectionState.ConnectionDisrupted) {
90
- _this.reconnectionMonitor.record(ReconnectEvent.START_RECONNECT);
76
+ this.reconnectionMonitor.record(ReconnectEvent.START_RECONNECT);
91
77
  }
92
78
  else if (connectionStateChange !== ConnectionState.Connecting) {
93
79
  // Trigger connected to halt reconnection attempts
94
- _this.reconnectionMonitor.record(ReconnectEvent.HALT_RECONNECT);
80
+ this.reconnectionMonitor.record(ReconnectEvent.HALT_RECONNECT);
95
81
  }
96
82
  });
97
- return _this;
98
83
  }
99
- Object.defineProperty(MqttOverWS.prototype, "clientId", {
100
- get: function () {
101
- return this.options.clientId;
102
- },
103
- enumerable: false,
104
- configurable: true
105
- });
106
- Object.defineProperty(MqttOverWS.prototype, "endpoint", {
107
- get: function () {
108
- return Promise.resolve(this.options.endpoint);
109
- },
110
- enumerable: false,
111
- configurable: true
112
- });
113
- Object.defineProperty(MqttOverWS.prototype, "clientsQueue", {
114
- get: function () {
115
- return this._clientsQueue;
116
- },
117
- enumerable: false,
118
- configurable: true
119
- });
120
- Object.defineProperty(MqttOverWS.prototype, "isSSLEnabled", {
121
- get: function () {
122
- return !this.options['aws_appsync_dangerously_connect_to_http_endpoint_for_testing'];
123
- },
124
- enumerable: false,
125
- configurable: true
126
- });
127
- MqttOverWS.prototype.onDisconnect = function (_a) {
128
- var clientId = _a.clientId, errorCode = _a.errorCode, args = __rest(_a, ["clientId", "errorCode"]);
84
+ get clientId() {
85
+ return this.options.clientId;
86
+ }
87
+ get endpoint() {
88
+ return Promise.resolve(this.options.endpoint);
89
+ }
90
+ get clientsQueue() {
91
+ return this._clientsQueue;
92
+ }
93
+ get isSSLEnabled() {
94
+ return !this.options['aws_appsync_dangerously_connect_to_http_endpoint_for_testing'];
95
+ }
96
+ onDisconnect({ clientId, errorCode, ...args }) {
129
97
  if (errorCode !== 0) {
130
- logger.warn(clientId, JSON.stringify(__assign({ errorCode: errorCode }, args), null, 2));
98
+ logger.warn(clientId, JSON.stringify({ errorCode, ...args }, null, 2));
131
99
  if (!clientId) {
132
100
  return;
133
101
  }
134
- var clientIdObservers = this._clientIdObservers.get(clientId);
102
+ const clientIdObservers = this._clientIdObservers.get(clientId);
135
103
  if (!clientIdObservers) {
136
104
  return;
137
105
  }
138
106
  this.disconnect(clientId);
139
107
  }
140
- };
141
- MqttOverWS.prototype.newClient = function (_a) {
142
- var url = _a.url, clientId = _a.clientId;
143
- return __awaiter(this, void 0, void 0, function () {
144
- var client, connected;
145
- var _this = this;
146
- return __generator(this, function (_b) {
147
- switch (_b.label) {
148
- case 0:
149
- logger.debug('Creating new MQTT client', clientId);
150
- this.connectionStateMonitor.record(CONNECTION_CHANGE.OPENING_CONNECTION);
151
- client = new Paho.Client(url, clientId);
152
- client.onMessageArrived = function (_a) {
153
- var topic = _a.destinationName, msg = _a.payloadString;
154
- _this._onMessage(topic, msg);
155
- };
156
- client.onConnectionLost = function (_a) {
157
- var errorCode = _a.errorCode, args = __rest(_a, ["errorCode"]);
158
- _this.onDisconnect(__assign({ clientId: clientId, errorCode: errorCode }, args));
159
- _this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
160
- };
161
- return [4 /*yield*/, new Promise(function (resolve, reject) {
162
- client.connect({
163
- useSSL: _this.isSSLEnabled,
164
- mqttVersion: 3,
165
- onSuccess: function () { return resolve(true); },
166
- onFailure: function () {
167
- if (clientId)
168
- _this._clientsQueue.remove(clientId);
169
- _this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
170
- resolve(false);
171
- },
172
- });
173
- })];
174
- case 1:
175
- connected = _b.sent();
176
- if (connected) {
177
- this.connectionStateMonitor.record(CONNECTION_CHANGE.CONNECTION_ESTABLISHED);
178
- }
179
- return [2 /*return*/, client];
180
- }
181
- });
182
- });
183
- };
184
- MqttOverWS.prototype.connect = function (clientId, options) {
185
- if (options === void 0) { options = {}; }
186
- return __awaiter(this, void 0, void 0, function () {
187
- var _this = this;
188
- return __generator(this, function (_a) {
189
- switch (_a.label) {
190
- case 0: return [4 /*yield*/, this.clientsQueue.get(clientId, function (clientId) { return __awaiter(_this, void 0, void 0, function () {
191
- var client;
192
- return __generator(this, function (_a) {
193
- switch (_a.label) {
194
- case 0: return [4 /*yield*/, this.newClient(__assign(__assign({}, options), { clientId: clientId }))];
195
- case 1:
196
- client = _a.sent();
197
- if (client) {
198
- // Once connected, subscribe to all topics registered observers
199
- this._topicObservers.forEach(function (_value, key) {
200
- client.subscribe(key);
201
- });
202
- }
203
- return [2 /*return*/, client];
204
- }
205
- });
206
- }); })];
207
- case 1: return [2 /*return*/, _a.sent()];
208
- }
209
- });
210
- });
211
- };
212
- MqttOverWS.prototype.disconnect = function (clientId) {
213
- return __awaiter(this, void 0, void 0, function () {
214
- var client;
215
- return __generator(this, function (_a) {
216
- switch (_a.label) {
217
- case 0: return [4 /*yield*/, this.clientsQueue.get(clientId)];
218
- case 1:
219
- client = _a.sent();
220
- if (client && client.isConnected()) {
221
- client.disconnect();
222
- }
223
- this.clientsQueue.remove(clientId);
224
- this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
225
- return [2 /*return*/];
226
- }
108
+ }
109
+ async newClient({ url, clientId }) {
110
+ logger.debug('Creating new MQTT client', clientId);
111
+ this.connectionStateMonitor.record(CONNECTION_CHANGE.OPENING_CONNECTION);
112
+ // @ts-ignore
113
+ const client = new Paho.Client(url, clientId);
114
+ client.onMessageArrived = ({ destinationName: topic, payloadString: msg, }) => {
115
+ this._onMessage(topic, msg);
116
+ };
117
+ client.onConnectionLost = ({ errorCode, ...args }) => {
118
+ this.onDisconnect({ clientId, errorCode, ...args });
119
+ this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
120
+ };
121
+ const connected = await new Promise((resolve, reject) => {
122
+ client.connect({
123
+ useSSL: this.isSSLEnabled,
124
+ mqttVersion: 3,
125
+ onSuccess: () => resolve(true),
126
+ onFailure: () => {
127
+ if (clientId)
128
+ this._clientsQueue.remove(clientId);
129
+ this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
130
+ resolve(false);
131
+ },
227
132
  });
228
133
  });
229
- };
230
- MqttOverWS.prototype.publish = function (topics, msg) {
231
- return __awaiter(this, void 0, void 0, function () {
232
- var targetTopics, message, client;
233
- return __generator(this, function (_a) {
234
- switch (_a.label) {
235
- case 0:
236
- targetTopics = [].concat(topics);
237
- message = JSON.stringify(msg);
238
- return [4 /*yield*/, this.clientsQueue.get(this.clientId)];
239
- case 1:
240
- client = _a.sent();
241
- if (client) {
242
- logger.debug('Publishing to topic(s)', targetTopics.join(','), message);
243
- targetTopics.forEach(function (topic) { return client.send(topic, message); });
244
- }
245
- else {
246
- logger.debug('Publishing to topic(s) failed', targetTopics.join(','), message);
247
- }
248
- return [2 /*return*/];
249
- }
250
- });
134
+ if (connected) {
135
+ this.connectionStateMonitor.record(CONNECTION_CHANGE.CONNECTION_ESTABLISHED);
136
+ }
137
+ return client;
138
+ }
139
+ async connect(clientId, options = {}) {
140
+ return await this.clientsQueue.get(clientId, async (clientId) => {
141
+ const client = await this.newClient({ ...options, clientId });
142
+ if (client) {
143
+ // Once connected, subscribe to all topics registered observers
144
+ this._topicObservers.forEach((_value, key) => {
145
+ client.subscribe(key);
146
+ });
147
+ }
148
+ return client;
251
149
  });
252
- };
253
- MqttOverWS.prototype._onMessage = function (topic, msg) {
150
+ }
151
+ async disconnect(clientId) {
152
+ const client = await this.clientsQueue.get(clientId);
153
+ if (client && client.isConnected()) {
154
+ client.disconnect();
155
+ }
156
+ this.clientsQueue.remove(clientId);
157
+ this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSED);
158
+ }
159
+ async publish({ topics, message }) {
160
+ const targetTopics = [].concat(topics);
161
+ const msg = JSON.stringify(message);
162
+ const client = await this.clientsQueue.get(this.clientId);
163
+ if (client) {
164
+ logger.debug('Publishing to topic(s)', targetTopics.join(','), message);
165
+ targetTopics.forEach(topic => client.send(topic, msg));
166
+ }
167
+ else {
168
+ logger.debug('Publishing to topic(s) failed', targetTopics.join(','), message);
169
+ }
170
+ }
171
+ _onMessage(topic, msg) {
254
172
  try {
255
- var matchedTopicObservers_1 = [];
256
- this._topicObservers.forEach(function (observerForTopic, observerTopic) {
173
+ const matchedTopicObservers = [];
174
+ this._topicObservers.forEach((observerForTopic, observerTopic) => {
257
175
  if (mqttTopicMatch(observerTopic, topic)) {
258
- matchedTopicObservers_1.push(observerForTopic);
176
+ matchedTopicObservers.push(observerForTopic);
259
177
  }
260
178
  });
261
- var parsedMessage_1 = JSON.parse(msg);
262
- if (typeof parsedMessage_1 === 'object') {
179
+ const parsedMessage = JSON.parse(msg);
180
+ if (typeof parsedMessage === 'object') {
263
181
  // @ts-ignore
264
- parsedMessage_1[topicSymbol] = topic;
182
+ parsedMessage[topicSymbol] = topic;
265
183
  }
266
- matchedTopicObservers_1.forEach(function (observersForTopic) {
267
- observersForTopic.forEach(function (observer) { return observer.next(parsedMessage_1); });
184
+ matchedTopicObservers.forEach(observersForTopic => {
185
+ observersForTopic.forEach(observer => observer.next(parsedMessage));
268
186
  });
269
187
  }
270
188
  catch (error) {
271
189
  logger.warn('Error handling message', error, msg);
272
190
  }
273
- };
274
- MqttOverWS.prototype.subscribe = function (topics, options) {
275
- var _this = this;
276
- if (options === void 0) { options = {}; }
277
- var targetTopics = [].concat(topics);
191
+ }
192
+ subscribe({ topics, options = {}, }) {
193
+ const targetTopics = [].concat(topics);
278
194
  logger.debug('Subscribing to topic(s)', targetTopics.join(','));
279
- var reconnectSubscription;
280
- return new Observable(function (observer) {
281
- targetTopics.forEach(function (topic) {
195
+ let reconnectSubscription;
196
+ return new Observable(observer => {
197
+ targetTopics.forEach(topic => {
282
198
  // this._topicObservers is used to notify the observers according to the topic received on the message
283
- var observersForTopic = _this._topicObservers.get(topic);
199
+ let observersForTopic = this._topicObservers.get(topic);
284
200
  if (!observersForTopic) {
285
201
  observersForTopic = new Set();
286
- _this._topicObservers.set(topic, observersForTopic);
202
+ this._topicObservers.set(topic, observersForTopic);
287
203
  }
288
204
  observersForTopic.add(observer);
289
205
  });
290
- var _a = options.clientId, clientId = _a === void 0 ? _this.clientId : _a;
206
+ const { clientId = this.clientId } = options;
291
207
  // this._clientIdObservers is used to close observers when client gets disconnected
292
- var observersForClientId = _this._clientIdObservers.get(clientId);
208
+ let observersForClientId = this._clientIdObservers.get(clientId);
293
209
  if (!observersForClientId) {
294
210
  observersForClientId = new Set();
295
211
  }
296
212
  if (observersForClientId) {
297
213
  observersForClientId.add(observer);
298
- _this._clientIdObservers.set(clientId, observersForClientId);
214
+ this._clientIdObservers.set(clientId, observersForClientId);
299
215
  }
300
- (function () { return __awaiter(_this, void 0, void 0, function () {
301
- var getClient;
302
- var _this = this;
303
- return __generator(this, function (_a) {
304
- switch (_a.label) {
305
- case 0:
306
- getClient = function () { return __awaiter(_this, void 0, void 0, function () {
307
- var _a, url, _b, client_1, e_1;
308
- return __generator(this, function (_c) {
309
- switch (_c.label) {
310
- case 0:
311
- _c.trys.push([0, 5, , 6]);
312
- _a = options.url;
313
- if (!(_a === void 0)) return [3 /*break*/, 2];
314
- return [4 /*yield*/, this.endpoint];
315
- case 1:
316
- _b = _c.sent();
317
- return [3 /*break*/, 3];
318
- case 2:
319
- _b = _a;
320
- _c.label = 3;
321
- case 3:
322
- url = _b;
323
- return [4 /*yield*/, this.connect(clientId, { url: url })];
324
- case 4:
325
- client_1 = _c.sent();
326
- if (client_1 !== undefined) {
327
- targetTopics.forEach(function (topic) {
328
- client_1.subscribe(topic);
329
- });
330
- }
331
- return [3 /*break*/, 6];
332
- case 5:
333
- e_1 = _c.sent();
334
- logger.debug('Error forming connection', e_1);
335
- return [3 /*break*/, 6];
336
- case 6: return [2 /*return*/];
337
- }
338
- });
339
- }); };
340
- // Establish the initial connection
341
- return [4 /*yield*/, getClient()];
342
- case 1:
343
- // Establish the initial connection
344
- _a.sent();
345
- // Add an observable to the reconnection list to manage reconnection for this subscription
346
- reconnectSubscription = new Observable(function (observer) {
347
- _this.reconnectionMonitor.addObserver(observer);
348
- }).subscribe(function () {
349
- getClient();
216
+ (async () => {
217
+ const getClient = async () => {
218
+ try {
219
+ const { url = await this.endpoint } = options;
220
+ const client = await this.connect(clientId, { url });
221
+ if (client !== undefined) {
222
+ targetTopics.forEach(topic => {
223
+ client.subscribe(topic);
350
224
  });
351
- return [2 /*return*/];
225
+ }
352
226
  }
353
- });
354
- }); })();
355
- return function () { return __awaiter(_this, void 0, void 0, function () {
356
- var client;
357
- var _this = this;
358
- var _a, _b;
359
- return __generator(this, function (_c) {
360
- switch (_c.label) {
361
- case 0: return [4 /*yield*/, this.clientsQueue.get(clientId)];
362
- case 1:
363
- client = _c.sent();
364
- reconnectSubscription === null || reconnectSubscription === void 0 ? void 0 : reconnectSubscription.unsubscribe();
365
- if (client) {
366
- (_a = this._clientIdObservers.get(clientId)) === null || _a === void 0 ? void 0 : _a.delete(observer);
367
- // No more observers per client => client not needed anymore
368
- if (((_b = this._clientIdObservers.get(clientId)) === null || _b === void 0 ? void 0 : _b.size) === 0) {
369
- this.disconnect(clientId);
370
- this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSING_CONNECTION);
371
- this._clientIdObservers.delete(clientId);
372
- }
373
- targetTopics.forEach(function (topic) {
374
- var observersForTopic = _this._topicObservers.get(topic) ||
375
- new Set();
376
- observersForTopic.delete(observer);
377
- // if no observers exists for the topic, topic should be removed
378
- if (observersForTopic.size === 0) {
379
- _this._topicObservers.delete(topic);
380
- if (client.isConnected()) {
381
- client.unsubscribe(topic);
382
- }
383
- }
384
- });
385
- }
386
- return [2 /*return*/, null];
227
+ catch (e) {
228
+ logger.debug('Error forming connection', e);
387
229
  }
230
+ };
231
+ // Establish the initial connection
232
+ await getClient();
233
+ // Add an observable to the reconnection list to manage reconnection for this subscription
234
+ reconnectSubscription = new Observable(observer => {
235
+ this.reconnectionMonitor.addObserver(observer);
236
+ }).subscribe(() => {
237
+ getClient();
388
238
  });
389
- }); };
239
+ })();
240
+ return async () => {
241
+ const client = await this.clientsQueue.get(clientId);
242
+ reconnectSubscription?.unsubscribe();
243
+ if (client) {
244
+ this._clientIdObservers.get(clientId)?.delete(observer);
245
+ // No more observers per client => client not needed anymore
246
+ if (this._clientIdObservers.get(clientId)?.size === 0) {
247
+ this.disconnect(clientId);
248
+ this.connectionStateMonitor.record(CONNECTION_CHANGE.CLOSING_CONNECTION);
249
+ this._clientIdObservers.delete(clientId);
250
+ }
251
+ targetTopics.forEach(topic => {
252
+ const observersForTopic = this._topicObservers.get(topic) ||
253
+ new Set();
254
+ observersForTopic.delete(observer);
255
+ // if no observers exists for the topic, topic should be removed
256
+ if (observersForTopic.size === 0) {
257
+ this._topicObservers.delete(topic);
258
+ if (client.isConnected()) {
259
+ client.unsubscribe(topic);
260
+ }
261
+ }
262
+ });
263
+ }
264
+ return null;
265
+ };
390
266
  });
391
- };
392
- return MqttOverWS;
393
- }(AbstractPubSub));
394
- export { MqttOverWS };
267
+ }
268
+ }
@@ -1,12 +1,11 @@
1
1
  import { Observable } from 'rxjs';
2
- import { PubSubBase, PubSubOptions, PubSubContent } from '../types/PubSub';
3
- import { CustomUserAgentDetails } from '@aws-amplify/core/internals/utils';
2
+ import { PubSubBase, PubSubOptions, PubSubContent, PublishInput, SubscribeInput } from '../types/PubSub';
4
3
  export declare abstract class AbstractPubSub<T extends PubSubOptions> implements PubSubBase {
5
4
  private _config;
6
5
  constructor(options: T);
7
6
  configure(config: T): T;
8
7
  protected get options(): T;
9
8
  abstract newClient(clientOptions: T): Promise<any>;
10
- abstract publish(topics: string[] | string, msg: PubSubContent, options?: T): void;
11
- abstract subscribe(topics: string[] | string, options?: T, customUserAgentDetails?: CustomUserAgentDetails): Observable<PubSubContent>;
9
+ abstract publish(input: PublishInput): void;
10
+ abstract subscribe(input: SubscribeInput): Observable<PubSubContent>;
12
11
  }
@@ -1,22 +1,15 @@
1
- import { __assign } from "tslib";
2
1
  import { ConsoleLogger as Logger } from '@aws-amplify/core';
3
- var logger = new Logger('AbstractPubSubProvider');
4
- var AbstractPubSub = /** @class */ (function () {
5
- function AbstractPubSub(options) {
2
+ const logger = new Logger('AbstractPubSubProvider');
3
+ export class AbstractPubSub {
4
+ constructor(options) {
6
5
  this._config = options;
7
6
  }
8
- AbstractPubSub.prototype.configure = function (config) {
9
- this._config = __assign(__assign({}, config), this._config);
10
- logger.debug("configure", this._config);
7
+ configure(config) {
8
+ this._config = { ...config, ...this._config };
9
+ logger.debug(`configure`, this._config);
11
10
  return this.options;
12
- };
13
- Object.defineProperty(AbstractPubSub.prototype, "options", {
14
- get: function () {
15
- return __assign({}, this._config);
16
- },
17
- enumerable: false,
18
- configurable: true
19
- });
20
- return AbstractPubSub;
21
- }());
22
- export { AbstractPubSub };
11
+ }
12
+ get options() {
13
+ return { ...this._config };
14
+ }
15
+ }