@mmstack/resource 21.4.6 → 21.5.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 +6 -6
- package/fesm2022/mmstack-resource.mjs +438 -356
- package/fesm2022/mmstack-resource.mjs.map +1 -1
- package/package.json +1 -1
- package/types/mmstack-resource.d.ts +47 -6
package/README.md
CHANGED
|
@@ -311,7 +311,7 @@ After a successful mutation, related query caches usually need refreshing. Inste
|
|
|
311
311
|
|
|
312
312
|
```typescript
|
|
313
313
|
mutationResource((p: Post) => ({ url: '/api/posts', method: 'POST', body: p }), {
|
|
314
|
-
invalidates: ['/api/posts'], // every cached
|
|
314
|
+
invalidates: ['/api/posts'], // every cached entry under /api/posts (any method, params, subpaths, varyHeaders variants)
|
|
315
315
|
});
|
|
316
316
|
|
|
317
317
|
// or derived from the result:
|
|
@@ -320,7 +320,7 @@ mutationResource(request, {
|
|
|
320
320
|
});
|
|
321
321
|
```
|
|
322
322
|
|
|
323
|
-
Strings are URL prefixes matched against
|
|
323
|
+
Strings are URL prefixes matched against the request URL of every cached entry, regardless of HTTP method (so a POST-bodied search cached under the same URL is cleared too). Plain prefix matching also catches sibling paths sharing the prefix (`/api/posts-archive`) — pass `'/api/posts/'` or an exact URL to narrow. Keys a custom `hash` merely *prepends* a namespace to (e.g. a tenant/`sub`) are still matched; keys that abandon the auto shape entirely need an `invalidateMatcher: (urlPrefix) => (key) => boolean` (set per-mutation or globally via `provideMutationResourceOptions`), or manual `injectQueryCache().invalidateWhere`.
|
|
324
324
|
|
|
325
325
|
### Re-firing with an identical body (`triggerOnSameRequest`)
|
|
326
326
|
|
|
@@ -476,14 +476,14 @@ With `syncTabs: true`, cache invalidations and updates broadcast via `BroadcastC
|
|
|
476
476
|
|
|
477
477
|
```typescript
|
|
478
478
|
const cache = injectQueryCache<MyResponse>();
|
|
479
|
-
cache.
|
|
480
|
-
cache.invalidatePrefix('GET:/api/posts'); // drop every key under a URL prefix
|
|
479
|
+
cache.invalidateUrlPrefix('/api/posts'); // drop every entry under a URL prefix, any method
|
|
481
480
|
cache.invalidateWhere((key) => key.includes('userId=42')); // arbitrary predicates
|
|
481
|
+
cache.invalidatePrefix('raw-key-prefix'); // match the raw key string from its start
|
|
482
482
|
cache.clear(); // drop EVERYTHING — memory, persisted rows, other tabs
|
|
483
483
|
cache.store(key, value, staleTime, ttl); // imperative write
|
|
484
484
|
```
|
|
485
485
|
|
|
486
|
-
Auto-generated keys have the shape `${method}
|
|
486
|
+
Auto-generated keys have the shape `${method}${SEP}${url}${SEP}${responseType}[${SEP}params][${SEP}body][${SEP}vary]`, where `SEP` is a content-rare control-character delimiter (treat keys as opaque — don't hand-build them). `invalidateUrlPrefix(urlPrefix)` is the common move: it recovers the URL field structurally, so it matches **any** HTTP method and even keys a custom `cache.hash` prepends a namespace to. For a fully-custom key scheme it takes an optional `match` (`(urlPrefix) => (key) => boolean`). Call `clear()` on logout so no prior user's responses survive. For observability there's a read-only `cache.stats()` signal (`{ size, hits, misses }`) — handy for a debug panel; it deliberately exposes no mutation surface.
|
|
487
487
|
|
|
488
488
|
Prefer the declarative [`invalidates`](#declarative-invalidation-invalidates) option on `mutationResource` for the common "mutation succeeded → refresh related queries" case.
|
|
489
489
|
|
|
@@ -669,7 +669,7 @@ Declarative — the common case:
|
|
|
669
669
|
|
|
670
670
|
```typescript
|
|
671
671
|
mutationResource((p: Post) => ({ url: '/posts', method: 'POST', body: p }), {
|
|
672
|
-
invalidates: ['/posts'], // every cached
|
|
672
|
+
invalidates: ['/posts'], // every cached entry under /posts, any method + params + subpaths + vary variants
|
|
673
673
|
});
|
|
674
674
|
```
|
|
675
675
|
|