roboto-js 1.4.32 → 1.4.33

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.
@@ -62,6 +62,7 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
62
62
  this.localDb = null;
63
63
  this.iac_session = null;
64
64
  this.appServiceHost = null;
65
+ this.requestCache = {};
65
66
 
66
67
  // Use the storageAdaptor to get the authToken, if available
67
68
  this.initAuthToken(authtoken);
@@ -715,6 +716,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
715
716
  defaultOrderBy,
716
717
  defaultLimit,
717
718
  mergedParams,
719
+ _paramsKey,
720
+ responsePromise,
718
721
  response,
719
722
  _args16 = arguments;
720
723
  return _regeneratorRuntime().wrap(function _callee16$(_context16) {
@@ -737,17 +740,32 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
737
740
  results: 50
738
741
  }
739
742
  }; // Merge defaults with provided params
740
- mergedParams = _objectSpread(_objectSpread(_objectSpread({}, defaultOrderBy), defaultLimit), params);
741
- _context16.next = 8;
743
+ mergedParams = _objectSpread(_objectSpread(_objectSpread({}, defaultOrderBy), defaultLimit), params); // Check cache for an existing request
744
+ _paramsKey = JSON.stringify(mergedParams);
745
+ if (!this.requestCache[_paramsKey]) {
746
+ _context16.next = 10;
747
+ break;
748
+ }
749
+ console.log("Returning cached request for params:", _paramsKey);
750
+ return _context16.abrupt("return", this.requestCache[_paramsKey]);
751
+ case 10:
752
+ _context16.next = 12;
742
753
  return this.axios.post('/object_service/queryObjects', [mergedParams]);
743
- case 8:
754
+ case 12:
755
+ responsePromise = _context16.sent;
756
+ // Store the promise in the cache
757
+ this.requestCache[_paramsKey] = responsePromise;
758
+ _context16.next = 16;
759
+ return responsePromise;
760
+ case 16:
744
761
  response = _context16.sent;
762
+ delete this.requestCache[_paramsKey];
745
763
  if (!(response.data.ok === false)) {
746
- _context16.next = 11;
764
+ _context16.next = 20;
747
765
  break;
748
766
  }
749
767
  return _context16.abrupt("return", this._handleError(response));
750
- case 11:
768
+ case 20:
751
769
  // Process items into RbtObject instances
752
770
  if (Array.isArray(response.data.items)) {
753
771
  response.data.items = response.data.items.map(function (record) {
@@ -757,15 +775,16 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
757
775
  });
758
776
  }
759
777
  return _context16.abrupt("return", response.data.items);
760
- case 15:
761
- _context16.prev = 15;
778
+ case 24:
779
+ _context16.prev = 24;
762
780
  _context16.t0 = _context16["catch"](1);
781
+ delete this.requestCache[paramsKey];
763
782
  return _context16.abrupt("return", this._handleError(_context16.t0));
764
- case 18:
783
+ case 28:
765
784
  case "end":
766
785
  return _context16.stop();
767
786
  }
768
- }, _callee16, this, [[1, 15]]);
787
+ }, _callee16, this, [[1, 24]]);
769
788
  }));
770
789
  function query(_x11) {
771
790
  return _query.apply(this, arguments);
@@ -34,6 +34,7 @@ export default class RbtApi {
34
34
  this.localDb = null;
35
35
  this.iac_session = null;
36
36
  this.appServiceHost = null;
37
+ this.requestCache = {};
37
38
 
38
39
  // Use the storageAdaptor to get the authToken, if available
39
40
  this.initAuthToken(authtoken);
@@ -354,7 +355,21 @@ export default class RbtApi {
354
355
  ...defaultLimit,
355
356
  ...params
356
357
  };
357
- const response = await this.axios.post('/object_service/queryObjects', [mergedParams]);
358
+
359
+ // Check cache for an existing request
360
+ const paramsKey = JSON.stringify(mergedParams);
361
+ if (this.requestCache[paramsKey]) {
362
+ console.log("Returning cached request for params:", paramsKey);
363
+ return this.requestCache[paramsKey];
364
+ }
365
+ //
366
+
367
+ const responsePromise = await this.axios.post('/object_service/queryObjects', [mergedParams]);
368
+
369
+ // Store the promise in the cache
370
+ this.requestCache[paramsKey] = responsePromise;
371
+ const response = await responsePromise;
372
+ delete this.requestCache[paramsKey];
358
373
  if (response.data.ok === false) {
359
374
  return this._handleError(response);
360
375
  }
@@ -367,6 +382,7 @@ export default class RbtApi {
367
382
  }
368
383
  return response.data.items;
369
384
  } catch (e) {
385
+ delete this.requestCache[paramsKey];
370
386
  return this._handleError(e);
371
387
  }
372
388
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.32",
3
+ "version": "1.4.33",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_api.js CHANGED
@@ -33,6 +33,7 @@ export default class RbtApi {
33
33
  this.localDb = null;
34
34
  this.iac_session = null;
35
35
  this.appServiceHost = null;
36
+ this.requestCache = {};
36
37
 
37
38
  // Use the storageAdaptor to get the authToken, if available
38
39
  this.initAuthToken(authtoken);
@@ -415,7 +416,22 @@ export default class RbtApi {
415
416
  // Merge defaults with provided params
416
417
  const mergedParams = { ...defaultOrderBy, ...defaultLimit, ...params };
417
418
 
418
- const response = await this.axios.post('/object_service/queryObjects', [mergedParams]);
419
+ // Check cache for an existing request
420
+ const paramsKey = JSON.stringify(mergedParams);
421
+ if (this.requestCache[paramsKey]) {
422
+ console.log("Returning cached request for params:", paramsKey);
423
+ return this.requestCache[paramsKey];
424
+ }
425
+ //
426
+
427
+ const responsePromise = await this.axios.post('/object_service/queryObjects', [mergedParams]);
428
+
429
+ // Store the promise in the cache
430
+ this.requestCache[paramsKey] = responsePromise;
431
+
432
+ const response = await responsePromise;
433
+ delete this.requestCache[paramsKey];
434
+
419
435
  if (response.data.ok === false) {
420
436
  return this._handleError(response);
421
437
  }
@@ -426,6 +442,7 @@ export default class RbtApi {
426
442
  }
427
443
  return response.data.items;
428
444
  } catch (e) {
445
+ delete this.requestCache[paramsKey];
429
446
  return this._handleError(e);
430
447
  }
431
448
  }