polfan-server-js-client 0.2.102 → 0.2.103

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.
@@ -5,7 +5,8 @@
5
5
  </component>
6
6
  <component name="ChangeListManager">
7
7
  <list default="true" id="831dae43-0da1-47fd-a5f7-33dd5eec2992" name="Changes" comment="Topic unfollowing">
8
- <change beforePath="$PROJECT_DIR$/src/state-tracker/FollowedTopicsManager.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/state-tracker/FollowedTopicsManager.ts" afterDir="false" />
8
+ <change beforePath="$PROJECT_DIR$/package.json" beforeDir="false" afterPath="$PROJECT_DIR$/package.json" afterDir="false" />
9
+ <change beforePath="$PROJECT_DIR$/src/WebApiChatClient.ts" beforeDir="false" afterPath="$PROJECT_DIR$/src/WebApiChatClient.ts" afterDir="false" />
9
10
  </list>
10
11
  <option name="SHOW_DIALOG" value="false" />
11
12
  <option name="HIGHLIGHT_CONFLICTS" value="true" />
@@ -208,15 +209,7 @@
208
209
  <workItem from="1782664203095" duration="5539000" />
209
210
  <workItem from="1782909199211" duration="2404000" />
210
211
  <workItem from="1783939298935" duration="21428000" />
211
- <workItem from="1784102649250" duration="7240000" />
212
- </task>
213
- <task id="LOCAL-00053" summary="New member count field in RoomSummary">
214
- <option name="closed" value="true" />
215
- <created>1754319172537</created>
216
- <option name="number" value="00053" />
217
- <option name="presentableId" value="LOCAL-00053" />
218
- <option name="project" value="LOCAL" />
219
- <updated>1754319172537</updated>
212
+ <workItem from="1784102649250" duration="10048000" />
220
213
  </task>
221
214
  <task id="LOCAL-00054" summary="Version bump">
222
215
  <option name="closed" value="true" />
@@ -602,7 +595,15 @@
602
595
  <option name="project" value="LOCAL" />
603
596
  <updated>1784229730189</updated>
604
597
  </task>
605
- <option name="localTasksCounter" value="102" />
598
+ <task id="LOCAL-00102" summary="Topic unfollowing">
599
+ <option name="closed" value="true" />
600
+ <created>1784236719408</created>
601
+ <option name="number" value="00102" />
602
+ <option name="presentableId" value="LOCAL-00102" />
603
+ <option name="project" value="LOCAL" />
604
+ <updated>1784236719408</updated>
605
+ </task>
606
+ <option name="localTasksCounter" value="103" />
606
607
  <servers />
607
608
  </component>
608
609
  <component name="TypeScriptGeneratedFilesManager">
@@ -5228,7 +5228,7 @@ var WebApiChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5228
5228
  WebApiChatClient_classCallCheck(this, WebApiChatClient);
5229
5229
  _this = WebApiChatClient_callSuper(this, WebApiChatClient);
5230
5230
  WebApiChatClient_defineProperty(_this, "Event", WebApiChatClientEvent);
5231
- WebApiChatClient_defineProperty(_this, "sendStack", void 0);
5231
+ WebApiChatClient_defineProperty(_this, "sendStack", []);
5232
5232
  _this.options = options;
5233
5233
  return _this;
5234
5234
  }
@@ -5237,17 +5237,18 @@ var WebApiChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5237
5237
  key: "send",
5238
5238
  value: function () {
5239
5239
  var _send = WebApiChatClient_asyncToGenerator(/*#__PURE__*/WebApiChatClient_regenerator().m(function _callee(commandType, commandData) {
5240
- var envelope;
5240
+ var envelope, item;
5241
5241
  return WebApiChatClient_regenerator().w(function (_context) {
5242
5242
  while (1) switch (_context.n) {
5243
5243
  case 0:
5244
5244
  envelope = this.createEnvelope(commandType, commandData);
5245
- this.sendStack.push({
5245
+ item = {
5246
5246
  data: envelope,
5247
5247
  attempts: 0,
5248
5248
  lastTimeoutId: null
5249
- });
5250
- this.makeApiCall(this.sendStack.length - 1);
5249
+ };
5250
+ this.sendStack.push(item);
5251
+ this.makeApiCall(item);
5251
5252
  return _context.a(2, this.createPromiseFromCommandEnvelope(envelope));
5252
5253
  }
5253
5254
  }, _callee, this);
@@ -5261,36 +5262,53 @@ var WebApiChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5261
5262
  key: "destroy",
5262
5263
  value: function destroy() {
5263
5264
  var _this2 = this;
5264
- // Cancel all awaiting requests
5265
- this.sendStack.forEach(function (item) {
5265
+ // Cancel all awaiting requests, rejecting their promises so no caller
5266
+ // is left awaiting forever
5267
+ var pending = this.sendStack;
5268
+ this.sendStack = [];
5269
+ pending.forEach(function (item) {
5266
5270
  if (item.lastTimeoutId) {
5267
5271
  clearTimeout(item.lastTimeoutId);
5268
5272
  }
5269
- _this2.awaitingResponse["delete"](item.data.ref);
5273
+ _this2.handleEnvelopeSendError(item.data, new Error('Client destroyed'));
5270
5274
  });
5271
- this.sendStack = [];
5272
5275
  this.emit(this.Event.destroy, false);
5273
5276
  }
5274
5277
  }, {
5275
5278
  key: "onMessage",
5276
5279
  value: function () {
5277
- var _onMessage = WebApiChatClient_asyncToGenerator(/*#__PURE__*/WebApiChatClient_regenerator().m(function _callee2(reqId, response) {
5278
- var envelope;
5280
+ var _onMessage = WebApiChatClient_asyncToGenerator(/*#__PURE__*/WebApiChatClient_regenerator().m(function _callee2(item, response) {
5281
+ var envelope, _t;
5279
5282
  return WebApiChatClient_regenerator().w(function (_context2) {
5280
- while (1) switch (_context2.n) {
5283
+ while (1) switch (_context2.p = _context2.n) {
5281
5284
  case 0:
5282
- this.sendStack.splice(reqId, 1);
5285
+ _context2.p = 0;
5283
5286
  _context2.n = 1;
5284
5287
  return response.json();
5285
5288
  case 1:
5286
5289
  envelope = _context2.v;
5290
+ _context2.n = 3;
5291
+ break;
5292
+ case 2:
5293
+ _context2.p = 2;
5294
+ _t = _context2.v;
5295
+ // Non-envelope response (e.g. a proxy error page) - failed attempt
5296
+ this.onError(item, "envelope ".concat(item.data.ref, " (HTTP ").concat(response.status, ", unparsable body)"));
5297
+ return _context2.a(2);
5298
+ case 3:
5299
+ if (this.removeFromStack(item)) {
5300
+ _context2.n = 4;
5301
+ break;
5302
+ }
5303
+ return _context2.a(2);
5304
+ case 4:
5287
5305
  this.handleIncomingEnvelope(envelope);
5288
5306
  this.emit(envelope.type, envelope.data);
5289
5307
  this.emit(this.Event.message, envelope);
5290
- case 2:
5308
+ case 5:
5291
5309
  return _context2.a(2);
5292
5310
  }
5293
- }, _callee2, this);
5311
+ }, _callee2, this, [[0, 2]]);
5294
5312
  }));
5295
5313
  function onMessage(_x3, _x4) {
5296
5314
  return _onMessage.apply(this, arguments);
@@ -5299,43 +5317,60 @@ var WebApiChatClient = /*#__PURE__*/function (_AbstractChatClient) {
5299
5317
  }()
5300
5318
  }, {
5301
5319
  key: "onError",
5302
- value: function onError(reqId, body) {
5320
+ value: function onError(item, body) {
5303
5321
  var _this$options$attempt,
5304
5322
  _this3 = this,
5305
5323
  _this$options$attempt2;
5306
- if (this.sendStack[reqId].attempts >= ((_this$options$attempt = this.options.attemptsToSend) !== null && _this$options$attempt !== void 0 ? _this$options$attempt : 10)) {
5307
- this.sendStack.splice(reqId, 1);
5308
- this.handleEnvelopeSendError(this.sendStack[reqId].data, new Error("Cannot send ".concat(body, "; aborting after reaching the maximum connection errors")));
5324
+ if (!this.sendStack.includes(item)) {
5325
+ return; // Destroyed in the meantime
5326
+ }
5327
+ if (item.attempts >= ((_this$options$attempt = this.options.attemptsToSend) !== null && _this$options$attempt !== void 0 ? _this$options$attempt : 10)) {
5328
+ this.removeFromStack(item);
5329
+ this.handleEnvelopeSendError(item.data, new Error("Cannot send ".concat(body, "; aborting after reaching the maximum connection errors")));
5309
5330
  return;
5310
5331
  }
5311
- this.sendStack[reqId].lastTimeoutId = setTimeout(function () {
5312
- return _this3.makeApiCall(reqId);
5332
+ item.lastTimeoutId = setTimeout(function () {
5333
+ return _this3.makeApiCall(item);
5313
5334
  }, (_this$options$attempt2 = this.options.attemptDelayMs) !== null && _this$options$attempt2 !== void 0 ? _this$options$attempt2 : 3000);
5314
5335
  }
5315
5336
  }, {
5316
5337
  key: "makeApiCall",
5317
- value: function makeApiCall(reqId) {
5338
+ value: function makeApiCall(item) {
5318
5339
  var _this$options$queryPa,
5319
5340
  _this4 = this;
5320
- this.sendStack[reqId].attempts++;
5321
- var bodyJson = JSON.stringify(this.sendStack[reqId].data);
5341
+ if (!this.sendStack.includes(item)) {
5342
+ return; // Destroyed before this (re)try fired
5343
+ }
5344
+ item.attempts++;
5345
+ item.lastTimeoutId = null;
5346
+ var bodyJson = JSON.stringify(item.data);
5322
5347
  var headers = {
5323
5348
  'Content-Type': 'application/json',
5324
5349
  Accept: 'application/json'
5325
5350
  };
5326
5351
  headers.Authorization = "Bearer ".concat(this.options.token);
5327
- var params = new URLSearchParams((_this$options$queryPa = this.options.queryParams) !== null && _this$options$queryPa !== void 0 ? _this$options$queryPa : {});
5328
- var url = "".concat(this.options.url).concat(params ? '?' + params : '');
5352
+ var query = new URLSearchParams((_this$options$queryPa = this.options.queryParams) !== null && _this$options$queryPa !== void 0 ? _this$options$queryPa : {}).toString();
5353
+ var url = query ? "".concat(this.options.url, "?").concat(query) : this.options.url;
5329
5354
  fetch(url, {
5330
5355
  headers: headers,
5331
5356
  body: bodyJson,
5332
5357
  method: 'POST'
5333
5358
  }).then(function (response) {
5334
- return _this4.onMessage(reqId, response);
5359
+ return _this4.onMessage(item, response);
5335
5360
  })["catch"](function () {
5336
- return _this4.onError(reqId, bodyJson);
5361
+ return _this4.onError(item, bodyJson);
5337
5362
  });
5338
5363
  }
5364
+ }, {
5365
+ key: "removeFromStack",
5366
+ value: function removeFromStack(item) {
5367
+ var index = this.sendStack.indexOf(item);
5368
+ if (index === -1) {
5369
+ return false;
5370
+ }
5371
+ this.sendStack.splice(index, 1);
5372
+ return true;
5373
+ }
5339
5374
  }]);
5340
5375
  }(AbstractChatClient);
5341
5376
  ;// ./src/AbstractRestClient.ts