shelving 1.197.0 → 1.198.0

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/api/index.d.ts CHANGED
@@ -3,6 +3,7 @@ export * from "./cache/EndpointCache.js";
3
3
  export * from "./endpoint/Endpoint.js";
4
4
  export * from "./endpoint/util.js";
5
5
  export * from "./provider/APIProvider.js";
6
+ export * from "./provider/CachedAPIProvider.js";
6
7
  export * from "./provider/ClientAPIProvider.js";
7
8
  export * from "./provider/DebugAPIProvider.js";
8
9
  export * from "./provider/JSONAPIProvider.js";
package/api/index.js CHANGED
@@ -3,6 +3,7 @@ export * from "./cache/EndpointCache.js";
3
3
  export * from "./endpoint/Endpoint.js";
4
4
  export * from "./endpoint/util.js";
5
5
  export * from "./provider/APIProvider.js";
6
+ export * from "./provider/CachedAPIProvider.js";
6
7
  export * from "./provider/ClientAPIProvider.js";
7
8
  export * from "./provider/DebugAPIProvider.js";
8
9
  export * from "./provider/JSONAPIProvider.js";
@@ -0,0 +1,20 @@
1
+ import type { AnyCaller } from "../../util/function.js";
2
+ import type { Endpoint } from "../endpoint/Endpoint.js";
3
+ import type { APIProvider } from "./APIProvider.js";
4
+ import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
5
+ /**
6
+ * API provider wrapper that serves requests through an `APICache`.
7
+ * - Constructor accepts a `source` provider and an optional default `maxAge`.
8
+ * - On `call(...)`, triggers `cache.refresh(maxAge)` for the endpoint+payload before awaiting `cache.call(...)`.
9
+ * - `invalidate`, `invalidateAll`, `refresh`, and `refreshAll` pass through to the underlying cache and use `this.maxAge` as the default refresh timing.
10
+ */
11
+ export declare class CachedAPIProvider<P, R> extends ThroughAPIProvider<P, R> {
12
+ readonly maxAge: number | undefined;
13
+ private readonly _cache;
14
+ constructor(source: APIProvider<P, R>, maxAge?: number);
15
+ call<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP, maxAge?: number | undefined, caller?: AnyCaller): Promise<RR>;
16
+ invalidate<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP): void;
17
+ invalidateAll<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>): void;
18
+ refresh<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>, payload: PP): void;
19
+ refreshAll<PP extends P, RR extends R>(endpoint: Endpoint<PP, RR>): void;
20
+ }
@@ -0,0 +1,34 @@
1
+ import { APICache } from "../cache/APICache.js";
2
+ import { ThroughAPIProvider } from "./ThroughAPIProvider.js";
3
+ /**
4
+ * API provider wrapper that serves requests through an `APICache`.
5
+ * - Constructor accepts a `source` provider and an optional default `maxAge`.
6
+ * - On `call(...)`, triggers `cache.refresh(maxAge)` for the endpoint+payload before awaiting `cache.call(...)`.
7
+ * - `invalidate`, `invalidateAll`, `refresh`, and `refreshAll` pass through to the underlying cache and use `this.maxAge` as the default refresh timing.
8
+ */
9
+ export class CachedAPIProvider extends ThroughAPIProvider {
10
+ maxAge;
11
+ _cache;
12
+ constructor(source, maxAge) {
13
+ super(source);
14
+ this.maxAge = maxAge;
15
+ this._cache = new APICache(source);
16
+ }
17
+ // @ts-expect-error TS2416: intentionally diverges from `APIProvider.call` — `RequestOptions` are not used by the cache, so the third arg is repurposed as `maxAge`.
18
+ call(endpoint, payload, maxAge = this.maxAge, caller = this.call) {
19
+ this._cache.refresh(endpoint, payload, maxAge);
20
+ return this._cache.call(endpoint, payload, maxAge, caller);
21
+ }
22
+ invalidate(endpoint, payload) {
23
+ this._cache.invalidate(endpoint, payload);
24
+ }
25
+ invalidateAll(endpoint) {
26
+ this._cache.invalidateAll(endpoint);
27
+ }
28
+ refresh(endpoint, payload) {
29
+ this._cache.refresh(endpoint, payload, this.maxAge);
30
+ }
31
+ refreshAll(endpoint) {
32
+ this._cache.refreshAll(endpoint, this.maxAge);
33
+ }
34
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shelving",
3
- "version": "1.197.0",
3
+ "version": "1.198.0",
4
4
  "author": "Dave Houlbrooke <dave@shax.com>",
5
5
  "repository": {
6
6
  "type": "git",