@blaze-cache/swr 0.2.5 → 0.3.0-beta.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/README.md CHANGED
@@ -80,7 +80,10 @@ arguments, then normal SWR options plus the Blaze-side stamp (`ttlMs`/`tags`).
80
80
  | `BlazeSWROptions` / `BlazeSWRMiddlewareOptions` / `BlazeSWRCacheLike` / `BlazeSWRRecord` | The option, cache and record types. |
81
81
 
82
82
  Precedence for the write stamp: the current `useSWR`/`useBlazeSWR` options, then the
83
- middleware's own options, then the defaults.
83
+ middleware's own options, then the defaults. `useBlazeSWR` keeps `ttlMs`/`tags` in the
84
+ SWR config it hands to `useSWR` rather than stripping them out, so a hook-level stamp
85
+ also wins an `SWRConfig` provider's merged values — a provider default can never shadow
86
+ a per-call one.
84
87
 
85
88
  ## Example usage
86
89
 
@@ -139,6 +142,17 @@ cache.invalidateTags('todos');
139
142
  mutate('/api/todos'); // SWR's own revalidation for the mounted hook
140
143
  ```
141
144
 
145
+ ## Testing
146
+
147
+ ```sh
148
+ pnpm --filter @blaze-cache/swr test
149
+ ```
150
+
151
+ The suite runs against the built package with Node's test runner, started with
152
+ `--experimental-test-module-mocks`: the hook test replaces the `swr` module with a
153
+ capture stub, so the exact config `useBlazeSWR` hands to SWR can be asserted without a
154
+ React renderer (the main suite needs none of that).
155
+
142
156
  ## Documentation
143
157
 
144
158
  Setup and the full integration reference live in the
@@ -149,6 +163,7 @@ Setup and the full integration reference live in the
149
163
  * [`@blaze-cache/core`](https://www.npmjs.com/package/@blaze-cache/core) — the cache itself
150
164
  * [`@blaze-cache/axios`](https://www.npmjs.com/package/@blaze-cache/axios) — HTTP adapter
151
165
  * [`@blaze-cache/fetch`](https://www.npmjs.com/package/@blaze-cache/fetch) — drop-in `fetch()` replacement
166
+ * [`@blaze-cache/ky`](https://www.npmjs.com/package/@blaze-cache/ky) — ky hooks (v1 and v2)
152
167
  * [`@blaze-cache/react-query`](https://www.npmjs.com/package/@blaze-cache/react-query) — TanStack Query v5 mirror + hook
153
168
 
154
169
  ## License
@@ -1 +1 @@
1
- {"version":3,"file":"useBlazeSWR.d.ts","sourceRoot":"","sources":["../src/useBlazeSWR.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,WAAW,CACzB,IAAI,GAAG,GAAG,EACV,KAAK,GAAG,GAAG,EACX,MAAM,SAAS,GAAG,GAAG,GAAG,EAExB,KAAK,EAAE,iBAAiB,EACxB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,IAAW,EAC5C,OAAO,GAAE,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAM,GAChE,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAO1B"}
1
+ {"version":3,"file":"useBlazeSWR.d.ts","sourceRoot":"","sources":["../src/useBlazeSWR.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,KAAK,CAAC;AAGrD,OAAO,KAAK,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAErE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,WAAW,CACzB,IAAI,GAAG,GAAG,EACV,KAAK,GAAG,GAAG,EACX,MAAM,SAAS,GAAG,GAAG,GAAG,EAExB,KAAK,EAAE,iBAAiB,EACxB,GAAG,EAAE,MAAM,EACX,OAAO,GAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,GAAG,IAAW,EAC5C,OAAO,GAAE,eAAe,CAAC,IAAI,EAAE,KAAK,EAAE,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,CAAM,GAChE,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAY1B"}
@@ -42,10 +42,15 @@ import { blazeSWRMiddleware } from './middleware.js';
42
42
  * @param options Normal SWR options plus `ttlMs`/`tags`.
43
43
  */
44
44
  export function useBlazeSWR(cache, key, fetcher = null, options = {}) {
45
- const { ttlMs, tags, use, ...swrOptions } = options;
45
+ const { use, ...swrOptions } = options;
46
46
  return useSWR(key, fetcher, {
47
+ // `ttlMs`/`tags` deliberately stay *in* the config: SWR merges an `SWRConfig`
48
+ // provider's values into it too, and hook-level options win that merge — so a
49
+ // per-call stamp reaches the middleware's `config.ttlMs ?? options.ttlMs ?? default`
50
+ // read as the highest precedence. Stripping them into the middleware's own options
51
+ // would invert that: the provider's config value would then shadow the per-call one.
47
52
  ...swrOptions,
48
- use: [blazeSWRMiddleware(cache, { ttlMs, tags }), ...(use ?? [])],
53
+ use: [blazeSWRMiddleware(cache, { ttlMs: options.ttlMs, tags: options.tags }), ...(use ?? [])],
49
54
  });
50
55
  }
51
56
  //# sourceMappingURL=useBlazeSWR.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"useBlazeSWR.js","sourceRoot":"","sources":["../src/useBlazeSWR.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,KAAK,CAAC;AAGzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,WAAW,CAKzB,KAAwB,EACxB,GAAW,EACX,UAAwC,IAAI,EAC5C,UAA+D,EAAE;IAEjE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAEpD,OAAO,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;QAC1B,GAAG,UAAU;QACb,GAAG,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;KAClE,CAA6B,CAAC;AACjC,CAAC"}
1
+ {"version":3,"file":"useBlazeSWR.js","sourceRoot":"","sources":["../src/useBlazeSWR.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,KAAK,CAAC;AAGzB,OAAO,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAC;AAGrD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,UAAU,WAAW,CAKzB,KAAwB,EACxB,GAAW,EACX,UAAwC,IAAI,EAC5C,UAA+D,EAAE;IAEjE,MAAM,EAAE,GAAG,EAAE,GAAG,UAAU,EAAE,GAAG,OAAO,CAAC;IAEvC,OAAO,MAAM,CAAC,GAAG,EAAE,OAAO,EAAE;QAC1B,8EAA8E;QAC9E,8EAA8E;QAC9E,qFAAqF;QACrF,mFAAmF;QACnF,qFAAqF;QACrF,GAAG,UAAU;QACb,GAAG,EAAE,CAAC,kBAAkB,CAAC,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,EAAE,GAAG,CAAC,GAAG,IAAI,EAAE,CAAC,CAAC;KAC/F,CAA6B,CAAC;AACjC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaze-cache/swr",
3
- "version": "0.2.5",
3
+ "version": "0.3.0-beta.0",
4
4
  "description": "Persist SWR in WebAssembly — instant first paint after reload while stale-while-revalidate still works",
5
5
  "keywords": [
6
6
  "swr",
@@ -35,7 +35,7 @@
35
35
  "dist"
36
36
  ],
37
37
  "dependencies": {
38
- "@blaze-cache/core": "0.2.5"
38
+ "@blaze-cache/core": "0.3.0-beta.0"
39
39
  },
40
40
  "peerDependencies": {
41
41
  "swr": "^2.0.0"
@@ -46,7 +46,7 @@
46
46
  },
47
47
  "scripts": {
48
48
  "build": "tsc -p tsconfig.json",
49
- "test": "pnpm run build && node --test",
49
+ "test": "pnpm run build && node --experimental-test-module-mocks --test",
50
50
  "typecheck": "tsc -p tsconfig.typecheck.json"
51
51
  }
52
52
  }