@mmstack/resource 20.0.3 → 20.0.4
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/fesm2022/mmstack-resource.mjs +13 -16
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/index.d.ts +1 -520
- package/lib/mutation-resource.d.ts +92 -0
- package/lib/public_api.d.ts +3 -0
- package/lib/query-resource.d.ts +97 -0
- package/lib/util/cache/cache.d.ts +177 -0
- package/lib/util/cache/cache.interceptor.d.ts +39 -0
- package/lib/util/cache/index.d.ts +2 -0
- package/lib/util/cache/public_api.d.ts +2 -0
- package/lib/util/catch-value-error.d.ts +2 -0
- package/lib/util/circuit-breaker.d.ts +74 -0
- package/lib/util/dedupe.interceptor.d.ts +50 -0
- package/lib/util/equality.d.ts +3 -0
- package/lib/util/has-slow-connection.d.ts +1 -0
- package/lib/util/index.d.ts +11 -0
- package/lib/util/persist.d.ts +3 -0
- package/lib/util/public_api.d.ts +3 -0
- package/lib/util/refresh.d.ts +3 -0
- package/lib/util/retry-on-error.d.ts +6 -0
- package/lib/util/to-resource-object.d.ts +2 -0
- package/lib/util/url-with-params.d.ts +2 -0
- package/package.json +1 -1
|
@@ -322,30 +322,25 @@ function parseCacheControlHeader(req) {
|
|
|
322
322
|
};
|
|
323
323
|
return directives;
|
|
324
324
|
}
|
|
325
|
-
function resolveTimings(cacheControl,
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
ttl,
|
|
329
|
-
};
|
|
325
|
+
function resolveTimings(cacheControl, optStaleTime, optTTL) {
|
|
326
|
+
let staleTime = optStaleTime;
|
|
327
|
+
let ttl = optTTL;
|
|
330
328
|
if (cacheControl.immutable)
|
|
331
329
|
return {
|
|
332
330
|
staleTime: Infinity,
|
|
333
331
|
ttl: Infinity,
|
|
334
332
|
};
|
|
333
|
+
if (cacheControl.maxAge !== null)
|
|
334
|
+
ttl = cacheControl.maxAge * 1000;
|
|
335
|
+
if (cacheControl.staleWhileRevalidate !== null)
|
|
336
|
+
staleTime = cacheControl.staleWhileRevalidate * 1000;
|
|
335
337
|
// if no-cache is set, we must always revalidate
|
|
336
338
|
if (cacheControl.noCache || cacheControl.mustRevalidate)
|
|
337
|
-
|
|
338
|
-
if (
|
|
339
|
-
|
|
340
|
-
if (cacheControl.maxAge !== null)
|
|
341
|
-
timings.ttl = cacheControl.maxAge * 1000;
|
|
342
|
-
// if stale-while-revalidate is set, we must revalidate after that time at the latest, but we can still serve the stale data
|
|
343
|
-
if (cacheControl.staleWhileRevalidate !== null) {
|
|
344
|
-
const ms = cacheControl.staleWhileRevalidate * 1000;
|
|
345
|
-
if (timings.staleTime === undefined || timings.staleTime > ms)
|
|
346
|
-
timings.staleTime = ms;
|
|
339
|
+
staleTime = 0;
|
|
340
|
+
if (ttl !== undefined && staleTime !== undefined && ttl < staleTime) {
|
|
341
|
+
staleTime = ttl;
|
|
347
342
|
}
|
|
348
|
-
return
|
|
343
|
+
return { staleTime, ttl };
|
|
349
344
|
}
|
|
350
345
|
/**
|
|
351
346
|
* Creates an `HttpInterceptorFn` that implements caching for HTTP requests. This interceptor
|
|
@@ -403,6 +398,8 @@ function createCacheInterceptor(allowedMethods = ['GET', 'HEAD', 'OPTIONS']) {
|
|
|
403
398
|
if (cacheControl.noStore)
|
|
404
399
|
return;
|
|
405
400
|
const { staleTime, ttl } = resolveTimings(cacheControl, opt.staleTime, opt.ttl);
|
|
401
|
+
if (opt.ttl === 0)
|
|
402
|
+
return; // no point
|
|
406
403
|
cache.store(key, event, staleTime, ttl);
|
|
407
404
|
}
|
|
408
405
|
}), map((event) => {
|