roboto-js 1.4.35 → 1.4.37

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.
@@ -716,7 +716,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
716
716
  defaultOrderBy,
717
717
  defaultLimit,
718
718
  mergedParams,
719
- paramsKey,
719
+ currentTime,
720
+ cacheEntry,
720
721
  responsePromise,
721
722
  response,
722
723
  _args16 = arguments;
@@ -741,30 +742,34 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
741
742
  }
742
743
  }; // Merge defaults with provided params
743
744
  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;
745
+ currentTime = Date.now();
746
+ cacheEntry = this.requestCache[paramsKey];
747
+ if (!(cacheEntry && currentTime - cacheEntry.time < 10000)) {
748
+ _context16.next = 11;
747
749
  break;
748
750
  }
749
- console.log("Returning cached request for params:", paramsKey);
750
- return _context16.abrupt("return", this.requestCache[paramsKey]);
751
- case 10:
752
- //
753
- responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams])["finally"](function () {
754
- // Ensure that the cache is cleaned up after the promise settles
755
- delete _this.requestCache[paramsKey];
756
- }); // Store the promise in the cache
757
- this.requestCache[paramsKey] = responsePromise;
758
- _context16.next = 14;
751
+ // 10000 ms = 10 seconds
752
+ console.log("Using cached request for params:", paramsKey);
753
+ return _context16.abrupt("return", cacheEntry.val);
754
+ case 11:
755
+ // Create the response promise and store it in the cache
756
+ responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]); // Store the promise along with the current time in the cache
757
+ this.requestCache[paramsKey] = {
758
+ val: responsePromise,
759
+ time: currentTime
760
+ };
761
+
762
+ // Await the response from the API
763
+ _context16.next = 15;
759
764
  return responsePromise;
760
- case 14:
765
+ case 15:
761
766
  response = _context16.sent;
762
767
  if (!(response.data.ok === false)) {
763
- _context16.next = 17;
768
+ _context16.next = 18;
764
769
  break;
765
770
  }
766
771
  return _context16.abrupt("return", this._handleError(response));
767
- case 17:
772
+ case 18:
768
773
  // Process items into RbtObject instances
769
774
  if (Array.isArray(response.data.items)) {
770
775
  response.data.items = response.data.items.map(function (record) {
@@ -774,15 +779,16 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
774
779
  });
775
780
  }
776
781
  return _context16.abrupt("return", response.data.items);
777
- case 21:
778
- _context16.prev = 21;
782
+ case 22:
783
+ _context16.prev = 22;
779
784
  _context16.t0 = _context16["catch"](1);
785
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
780
786
  return _context16.abrupt("return", this._handleError(_context16.t0));
781
- case 24:
787
+ case 26:
782
788
  case "end":
783
789
  return _context16.stop();
784
790
  }
785
- }, _callee16, this, [[1, 21]]);
791
+ }, _callee16, this, [[1, 22]]);
786
792
  }));
787
793
  function query(_x11) {
788
794
  return _query.apply(this, arguments);
@@ -357,20 +357,24 @@ export default class RbtApi {
357
357
  };
358
358
 
359
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];
360
+ const currentTime = Date.now();
361
+ const cacheEntry = this.requestCache[paramsKey];
362
+ if (cacheEntry && currentTime - cacheEntry.time < 10000) {
363
+ // 10000 ms = 10 seconds
364
+ console.log("Using cached request for params:", paramsKey);
365
+ return cacheEntry.val;
364
366
  }
365
- //
366
367
 
367
- const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]).finally(() => {
368
- // Ensure that the cache is cleaned up after the promise settles
369
- delete this.requestCache[paramsKey];
370
- });
368
+ // Create the response promise and store it in the cache
369
+ const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
370
+
371
+ // Store the promise along with the current time in the cache
372
+ this.requestCache[paramsKey] = {
373
+ val: responsePromise,
374
+ time: currentTime
375
+ };
371
376
 
372
- // Store the promise in the cache
373
- this.requestCache[paramsKey] = responsePromise;
377
+ // Await the response from the API
374
378
  const response = await responsePromise;
375
379
  if (response.data.ok === false) {
376
380
  return this._handleError(response);
@@ -378,12 +382,15 @@ export default class RbtApi {
378
382
 
379
383
  // Process items into RbtObject instances
380
384
  if (Array.isArray(response.data.items)) {
381
- response.data.items = response.data.items.map(record => new RbtObject(record, this.axios, {
382
- isNew: true
383
- }));
385
+ response.data.items = response.data.items.map(record => {
386
+ return new RbtObject(record, this.axios, {
387
+ isNew: true
388
+ });
389
+ });
384
390
  }
385
391
  return response.data.items;
386
392
  } catch (e) {
393
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
387
394
  return this._handleError(e);
388
395
  }
389
396
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roboto-js",
3
- "version": "1.4.35",
3
+ "version": "1.4.37",
4
4
  "type": "module",
5
5
  "description": "",
6
6
  "main": "dist/cjs/index.cjs",
package/src/rbt_api.js CHANGED
@@ -406,7 +406,9 @@ export default class RbtApi {
406
406
  * Note: A default orderBy is applied if none is provided, ordering items by 'timeCreated' in descending order.
407
407
  */
408
408
  async query(type, params = {}) {
409
+
409
410
  try {
411
+
410
412
  params.type = type;
411
413
 
412
414
  // Default ordering and pagination
@@ -417,22 +419,20 @@ export default class RbtApi {
417
419
  const mergedParams = { ...defaultOrderBy, ...defaultLimit, ...params };
418
420
 
419
421
  // 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];
422
+ const currentTime = Date.now();
423
+ const cacheEntry = this.requestCache[paramsKey];
424
+ if (cacheEntry && (currentTime - cacheEntry.time) < 10000) { // 10000 ms = 10 seconds
425
+ console.log("Using cached request for params:", paramsKey);
426
+ return cacheEntry.val;
424
427
  }
425
- //
426
428
 
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
- });
429
+ // Create the response promise and store it in the cache
430
+ const responsePromise = this.axios.post('/object_service/queryObjects', [mergedParams]);
432
431
 
433
- // Store the promise in the cache
434
- this.requestCache[paramsKey] = responsePromise;
432
+ // Store the promise along with the current time in the cache
433
+ this.requestCache[paramsKey] = { val: responsePromise, time: currentTime };
435
434
 
435
+ // Await the response from the API
436
436
  const response = await responsePromise;
437
437
 
438
438
  if (response.data.ok === false) {
@@ -441,12 +441,20 @@ export default class RbtApi {
441
441
 
442
442
  // Process items into RbtObject instances
443
443
  if (Array.isArray(response.data.items)) {
444
- response.data.items = response.data.items.map(record => new RbtObject(record, this.axios, { isNew: true }));
444
+ response.data.items = response.data.items.map(record => {
445
+ return new RbtObject(record, this.axios, { isNew: true });
446
+ });
445
447
  }
448
+
446
449
  return response.data.items;
450
+
447
451
  } catch (e) {
452
+
453
+ delete this.requestCache[paramsKey]; // Ensure cache cleanup on error
448
454
  return this._handleError(e);
455
+
449
456
  }
457
+
450
458
  }
451
459
 
452
460
  /**