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.
- package/dist/cjs/rbt_api.cjs +27 -21
- package/dist/esm/rbt_api.js +21 -14
- package/package.json +1 -1
- package/src/rbt_api.js +21 -13
package/dist/cjs/rbt_api.cjs
CHANGED
|
@@ -716,7 +716,8 @@ var RbtApi = exports["default"] = /*#__PURE__*/function () {
|
|
|
716
716
|
defaultOrderBy,
|
|
717
717
|
defaultLimit,
|
|
718
718
|
mergedParams,
|
|
719
|
-
|
|
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
|
-
|
|
745
|
-
|
|
746
|
-
|
|
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
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
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
|
|
765
|
+
case 15:
|
|
761
766
|
response = _context16.sent;
|
|
762
767
|
if (!(response.data.ok === false)) {
|
|
763
|
-
_context16.next =
|
|
768
|
+
_context16.next = 18;
|
|
764
769
|
break;
|
|
765
770
|
}
|
|
766
771
|
return _context16.abrupt("return", this._handleError(response));
|
|
767
|
-
case
|
|
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
|
|
778
|
-
_context16.prev =
|
|
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
|
|
787
|
+
case 26:
|
|
782
788
|
case "end":
|
|
783
789
|
return _context16.stop();
|
|
784
790
|
}
|
|
785
|
-
}, _callee16, this, [[1,
|
|
791
|
+
}, _callee16, this, [[1, 22]]);
|
|
786
792
|
}));
|
|
787
793
|
function query(_x11) {
|
|
788
794
|
return _query.apply(this, arguments);
|
package/dist/esm/rbt_api.js
CHANGED
|
@@ -357,20 +357,24 @@ export default class RbtApi {
|
|
|
357
357
|
};
|
|
358
358
|
|
|
359
359
|
// Check cache for an existing request
|
|
360
|
-
const
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
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
|
-
//
|
|
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 =>
|
|
382
|
-
|
|
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
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
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
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
|
-
|
|
428
|
-
|
|
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 =>
|
|
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
|
/**
|