@drakkar.software/starfish-client 3.0.0-alpha.26 → 3.0.0-alpha.28

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/index.js CHANGED
@@ -468,7 +468,20 @@ var StarfishClient = class {
468
468
  if (!res.ok) {
469
469
  throw new StarfishHttpError(res.status, await res.text());
470
470
  }
471
- return res.json();
471
+ const result = await res.json();
472
+ if (this.cache) {
473
+ const pullPath = sendPath.replace("/push/", "/pull/");
474
+ const cacheKey = pullCacheKey(pullPath);
475
+ const snapshot = {
476
+ data,
477
+ hash: result.hash,
478
+ timestamp: result.timestamp,
479
+ cachedAt: Date.now()
480
+ };
481
+ void this.cache.set(cacheKey, JSON.stringify(snapshot)).catch(() => {
482
+ });
483
+ }
484
+ return result;
472
485
  }
473
486
  /**
474
487
  * Append an element to an appendOnly (`by_timestamp`) collection.