roboto-js 1.4.34 → 1.4.36

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.
@@ -743,26 +743,29 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
743
743
  mergedParams = _objectSpread(_objectSpread(_objectSpread({}, defaultOrderBy), defaultLimit), params); // Check cache for an existing request
744
744
  _paramsKey = JSON.stringify(mergedParams);
745
745
  if (!this.requestCache[_paramsKey]) {
746
- _context16.next = 10;
746
+ _context16.next = 9;
747
747
  break;
748
748
  }
749
- console.log("Returning cached request for params:", _paramsKey);
750
749
  return _context16.abrupt("return", this.requestCache[_paramsKey]);
751
- case 10:
752
- //
753
- responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Store the promise in the cache
750
+ case 9:
751
+ // Create the response promise and store it in the cache
752
+ responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams])["finally"](function () {
753
+ // Ensure that the cache is cleaned up after the promise settles
754
+ delete _this.requestCache[_paramsKey];
755
+ }); // Store the promise in the cache
754
756
  this.requestCache[_paramsKey] = responsePromise;
755
- _context16.next = 14;
757
+
758
+ // Await the response from the API
759
+ _context16.next = 13;
756
760
  return responsePromise;
757
- case 14:
761
+ case 13:
758
762
  response = _context16.sent;
759
- delete this.requestCache[_paramsKey];
760
763
  if (!(response.data.ok === false)) {
761
- _context16.next = 18;
764
+ _context16.next = 16;
762
765
  break;
763
766
  }
764
767
  return _context16.abrupt("return", this._handleError(response));
765
- case 18:
768
+ case 16:
766
769
  // Process items into RbtObject instances
767
770
  if (Array.isArray(response.data.items)) {
768
771
  response.data.items = response.data.items.map(function (record) {
@@ -772,16 +775,16 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
772
775
  });
773
776
  }
774
777
  return _context16.abrupt("return", response.data.items);
775
- case 22:
776
- _context16.prev = 22;
778
+ case 20:
779
+ _context16.prev = 20;
777
780
  _context16.t0 = _context16["catch"](1);
778
- delete this.requestCache[paramsKey];
781
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
779
782
  return _context16.abrupt("return", this._handleError(_context16.t0));
780
- case 26:
783
+ case 24:
781
784
  case "end":
782
785
  return _context16.stop();
783
786
  }
784
- }, _callee16, this, [[1, 22]]);
787
+ }, _callee16, this, [[1, 20]]);
785
788
  }));
786
789
  function query(_x11) {
787
790
  return _query.apply(this, arguments);
@@ -359,30 +359,35 @@ export default class RbtApi {
359
359
  // Check cache for an existing request
360
360
  const paramsKey = JSON.stringify(mergedParams);
361
361
  if (this.requestCache[paramsKey]) {
362
- console.log("Returning cached request for params:", paramsKey);
363
362
  return this.requestCache[paramsKey];
364
363
  }
365
- //
366
364
 
367
- const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
365
+ // Create the response promise and store it in the cache
366
+ const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]).finally(() => {
367
+ // Ensure that the cache is cleaned up after the promise settles
368
+ delete this.requestCache[paramsKey];
369
+ });
368
370
 
369
371
  // Store the promise in the cache
370
372
  this.requestCache[paramsKey] = responsePromise;
373
+
374
+ // Await the response from the API
371
375
  const response = await responsePromise;
372
- delete this.requestCache[paramsKey];
373
376
  if (response.data.ok === false) {
374
377
  return this._handleError(response);
375
378
  }
376
379
 
377
380
  // Process items into RbtObject instances
378
381
  if (Array.isArray(response.data.items)) {
379
- response.data.items = response.data.items.map(record => new RbtObject(record, this.axios, {
380
- isNew: true
381
- }));
382
+ response.data.items = response.data.items.map(record => {
383
+ return new RbtObject(record, this.axios, {
384
+ isNew: true
385
+ });
386
+ });
382
387
  }
383
388
  return response.data.items;
384
389
  } catch (e) {
385
- delete this.requestCache[paramsKey];
390
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
386
391
  return this._handleError(e);
387
392
  }
388
393
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.34",
3
+ "version": "1.4.36",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_api.js CHANGED
@@ -407,6 +407,7 @@ export default class RbtApi {
407
407
  */
408
408
  async query(type, params = {}) {
409
409
  try {
410
+
410
411
  params.type = type;
411
412
 
412
413
  // Default ordering and pagination
@@ -419,18 +420,21 @@ export default class RbtApi {
419
420
  // Check cache for an existing request
420
421
  const paramsKey = JSON.stringify(mergedParams);
421
422
  if (this.requestCache[paramsKey]) {
422
- console.log("Returning cached request for params:", paramsKey);
423
- return this.requestCache[paramsKey];
423
+ return this.requestCache[paramsKey];
424
424
  }
425
- //
426
425
 
427
- const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
426
+ // Create the response promise and store it in the cache
427
+ const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams])
428
+ .finally(() => {
429
+ // Ensure that the cache is cleaned up after the promise settles
430
+ delete this.requestCache[paramsKey];
431
+ });
428
432
 
429
433
  // Store the promise in the cache
430
434
  this.requestCache[paramsKey] = responsePromise;
431
435
 
436
+ // Await the response from the API
432
437
  const response = await responsePromise;
433
- delete this.requestCache[paramsKey];
434
438
 
435
439
  if (response.data.ok === false) {
436
440
  return this._handleError(response);
@@ -438,12 +442,18 @@ export default class RbtApi {
438
442
 
439
443
  // Process items into RbtObject instances
440
444
  if (Array.isArray(response.data.items)) {
441
- response.data.items = response.data.items.map(record => new RbtObject(record, this.axios, { isNew: true }));
445
+ response.data.items = response.data.items.map(record => {
446
+ return new RbtObject(record, this.axios, { isNew: true });
447
+ });
442
448
  }
449
+
443
450
  return response.data.items;
451
+
444
452
  } catch (e) {
445
- delete this.requestCache[paramsKey];
453
+
454
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
446
455
  return this._handleError(e);
456
+
447
457
  }
448
458
  }
449
459