@blaze-cache/swr 0.2.5 → 0.3.0-beta.1
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 +23 -1
- package/dist/useBlazeSWR.d.ts.map +1 -1
- package/dist/useBlazeSWR.js +7 -2
- package/dist/useBlazeSWR.js.map +1 -1
- package/package.json +5 -4
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,24 @@ 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 # offline — stubbed fetcher, no network
|
|
149
|
+
pnpm --filter @blaze-cache/swr test:live # live — real public API, needs the network
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
The offline suite runs against the built package with Node's test runner, started with
|
|
153
|
+
`--experimental-test-module-mocks`: the hook test replaces the `swr` module with a
|
|
154
|
+
capture stub, so the exact config `useBlazeSWR` hands to SWR can be asserted without a
|
|
155
|
+
React renderer (the main suite needs none of that).
|
|
156
|
+
|
|
157
|
+
The live suite (4 tests) runs against `api.github.com`, proving the middleware round-trips
|
|
158
|
+
a real response body through the persisted envelope, that a fresh middleware run seeds
|
|
159
|
+
from the mirror with zero network, that a failing fetcher persists nothing, and that a
|
|
160
|
+
revalidation rewrites the same single entry in place. Every live test is skipped unless
|
|
161
|
+
`BLAZE_CACHE_LIVE=1` is set, so the default suite always runs offline.
|
|
162
|
+
|
|
142
163
|
## Documentation
|
|
143
164
|
|
|
144
165
|
Setup and the full integration reference live in the
|
|
@@ -149,6 +170,7 @@ Setup and the full integration reference live in the
|
|
|
149
170
|
* [`@blaze-cache/core`](https://www.npmjs.com/package/@blaze-cache/core) — the cache itself
|
|
150
171
|
* [`@blaze-cache/axios`](https://www.npmjs.com/package/@blaze-cache/axios) — HTTP adapter
|
|
151
172
|
* [`@blaze-cache/fetch`](https://www.npmjs.com/package/@blaze-cache/fetch) — drop-in `fetch()` replacement
|
|
173
|
+
* [`@blaze-cache/ky`](https://www.npmjs.com/package/@blaze-cache/ky) — ky hooks (v1 and v2)
|
|
152
174
|
* [`@blaze-cache/react-query`](https://www.npmjs.com/package/@blaze-cache/react-query) — TanStack Query v5 mirror + hook
|
|
153
175
|
|
|
154
176
|
## 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,
|
|
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"}
|
package/dist/useBlazeSWR.js
CHANGED
|
@@ -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 {
|
|
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
|
package/dist/useBlazeSWR.js.map
CHANGED
|
@@ -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,
|
|
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.
|
|
3
|
+
"version": "0.3.0-beta.1",
|
|
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.
|
|
38
|
+
"@blaze-cache/core": "0.3.0-beta.1"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
41
|
"swr": "^2.0.0"
|
|
@@ -46,7 +46,8 @@
|
|
|
46
46
|
},
|
|
47
47
|
"scripts": {
|
|
48
48
|
"build": "tsc -p tsconfig.json",
|
|
49
|
-
"test": "pnpm run build && node --test",
|
|
50
|
-
"typecheck": "tsc -p tsconfig.typecheck.json"
|
|
49
|
+
"test": "pnpm run build && node --experimental-test-module-mocks --test",
|
|
50
|
+
"typecheck": "tsc -p tsconfig.typecheck.json",
|
|
51
|
+
"test:live": "pnpm run build && BLAZE_CACHE_LIVE=1 node --test test/live.test.mjs"
|
|
51
52
|
}
|
|
52
53
|
}
|