@blaze-cache/react-query 0.2.3-beta → 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 +139 -1
- package/dist/hydration.d.ts +74 -0
- package/dist/hydration.d.ts.map +1 -0
- package/dist/hydration.js +107 -0
- package/dist/hydration.js.map +1 -0
- package/dist/imperative.d.ts +101 -0
- package/dist/imperative.d.ts.map +1 -0
- package/dist/imperative.js +261 -0
- package/dist/imperative.js.map +1 -0
- package/dist/index.d.ts +21 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +16 -4
- package/dist/index.js.map +1 -1
- package/dist/record.d.ts +16 -0
- package/dist/record.d.ts.map +1 -0
- package/dist/record.js +19 -0
- package/dist/record.js.map +1 -0
- package/dist/sync.d.ts +4 -0
- package/dist/sync.d.ts.map +1 -1
- package/dist/sync.js +53 -5
- package/dist/sync.js.map +1 -1
- package/dist/types.d.ts +94 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/useBlazeInfiniteQuery.d.ts +46 -0
- package/dist/useBlazeInfiniteQuery.d.ts.map +1 -0
- package/dist/useBlazeInfiniteQuery.js +80 -0
- package/dist/useBlazeInfiniteQuery.js.map +1 -0
- package/dist/useBlazeMutation.d.ts +54 -0
- package/dist/useBlazeMutation.d.ts.map +1 -0
- package/dist/useBlazeMutation.js +50 -0
- package/dist/useBlazeMutation.js.map +1 -0
- package/dist/useBlazeQueries.d.ts +50 -0
- package/dist/useBlazeQueries.d.ts.map +1 -0
- package/dist/useBlazeQueries.js +46 -0
- package/dist/useBlazeQueries.js.map +1 -0
- package/dist/useBlazeQuery.d.ts +11 -1
- package/dist/useBlazeQuery.d.ts.map +1 -1
- package/dist/useBlazeQuery.js +33 -9
- package/dist/useBlazeQuery.js.map +1 -1
- package/package.json +2 -2
|
@@ -0,0 +1,261 @@
|
|
|
1
|
+
import { matchQuery, partialMatchKey } from '@tanstack/react-query';
|
|
2
|
+
import { isMirrorRecord } from './record.js';
|
|
3
|
+
import { resolveQueryHash } from './hash.js';
|
|
4
|
+
import { DEFAULT_TAGS, DEFAULT_TTL_MS } from './sync.js';
|
|
5
|
+
import { seedBlazeQueryOptions } from './useBlazeQuery.js';
|
|
6
|
+
/** The `cache.set` options a helper writes with: the caller's, or the sync layer's defaults. */
|
|
7
|
+
function mirrorWriteOptions(options) {
|
|
8
|
+
return {
|
|
9
|
+
ttlMs: options?.ttlMs ?? DEFAULT_TTL_MS,
|
|
10
|
+
tags: options?.tags ?? DEFAULT_TAGS,
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** Every live mirror entry, or a thrown error — never a silently partial operation. */
|
|
14
|
+
function entriesOf(cache) {
|
|
15
|
+
if (!cache.entries) {
|
|
16
|
+
throw new Error('[blaze-cache/react-query] This filter must be matched against every persisted ' +
|
|
17
|
+
'entry, but the cache does not implement `entries()`. Refusing to run a ' +
|
|
18
|
+
'deliberately partial purge — use the concrete `BlazeCache`, or narrow the ' +
|
|
19
|
+
'filter to `exact` query keys, which need no enumeration.');
|
|
20
|
+
}
|
|
21
|
+
return cache.entries();
|
|
22
|
+
}
|
|
23
|
+
/** True when `entry` carries any of `tags`. */
|
|
24
|
+
function hasAnyTag(entry, tags) {
|
|
25
|
+
return entry.tags.some((tag) => tags.includes(tag));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Purges every **mirror record** carrying any of `tags`, returning the removed keys.
|
|
29
|
+
*
|
|
30
|
+
* Deliberately *not* `cache.invalidateTags`: the core's tag index is one global namespace
|
|
31
|
+
* with no per-integration scoping, so on a cache shared with `@blaze-cache/axios`,
|
|
32
|
+
* `@blaze-cache/fetch` or `@blaze-cache/swr` that call would silently purge other
|
|
33
|
+
* integrations' entries too. Enumerating `entries()` lets the selection be narrowed to
|
|
34
|
+
* this package's own records (see {@link isMirrorRecord}) plus tag membership — a
|
|
35
|
+
* `tags` purge here removes what *this* integration tagged and nothing else.
|
|
36
|
+
*
|
|
37
|
+
* Throws when the cache cannot enumerate: a `tags` selector that quietly matched nothing
|
|
38
|
+
* is exactly the bug this package refuses to ship.
|
|
39
|
+
*/
|
|
40
|
+
function purgeMirrorByTags(cache, tags) {
|
|
41
|
+
return entriesOf(cache)
|
|
42
|
+
.filter((entry) => isMirrorRecord(entry.value) && hasAnyTag(entry, tags))
|
|
43
|
+
.map((entry) => entry.key);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolves one {@link BlazeQueryFilters} against **both** caches: purges the matching
|
|
47
|
+
* mirror entries immediately and returns the filters TanStack's side of the operation
|
|
48
|
+
* should run with.
|
|
49
|
+
*
|
|
50
|
+
* The two sides see different data, so the selection rules are explicit:
|
|
51
|
+
*
|
|
52
|
+
* * **`tags`** live only in the Blaze Cache. A tags-only filter purges by tag (above) and
|
|
53
|
+
* narrows TanStack to the queries whose mirror entries were removed. Combined with a
|
|
54
|
+
* key or a state filter, `entries()` is required so the selection can be intersected
|
|
55
|
+
* rather than unioned.
|
|
56
|
+
* * **`queryKey`/`exact`** match each mirror entry's stored `queryKey`, so a prefix purge
|
|
57
|
+
* also reaches entries from earlier sessions that this TanStack cache never loaded.
|
|
58
|
+
* `exact` keys are a single computable hash and need no enumeration. Entries written
|
|
59
|
+
* before records carried a `queryKey` can only be reached through their live TanStack
|
|
60
|
+
* query, which the union below covers.
|
|
61
|
+
* * **`predicate`/`stale`/`type`/`fetchStatus`** read query state, which mirror entries do
|
|
62
|
+
* not carry — those select TanStack queries, and the mirror follows their hashes. A
|
|
63
|
+
* `tags` filter intersected with them therefore needs `entries()` too.
|
|
64
|
+
* * **No filters** purge the whole mirror (and remove/invalidate every TanStack query).
|
|
65
|
+
*/
|
|
66
|
+
function purgeMirrorAndBuildFilters(cache, client, filters) {
|
|
67
|
+
const { tags, ...queryFilters } = filters;
|
|
68
|
+
const { queryKey, exact, predicate, stale, type = 'all', fetchStatus } = queryFilters;
|
|
69
|
+
const stateful = predicate !== undefined || stale !== undefined || type !== 'all' || fetchStatus !== undefined;
|
|
70
|
+
// Hashes of the queries TanStack currently knows and that match the query-side filters —
|
|
71
|
+
// the only mirror entries reachable when the selection leans on live query state.
|
|
72
|
+
const knownHashes = () => new Set(client.getQueryCache().findAll(queryFilters).map((query) => query.queryHash));
|
|
73
|
+
let removed;
|
|
74
|
+
if (stateful) {
|
|
75
|
+
const hashes = knownHashes();
|
|
76
|
+
if (tags) {
|
|
77
|
+
// Intersect: the entry must carry the tag *and* belong to a query TanStack matched.
|
|
78
|
+
// Shape-gated like every other mirror-side selection — a hash TanStack knows may
|
|
79
|
+
// point at another integration's entry on a shared cache, which this purge must not
|
|
80
|
+
// delete (see `purgeMirrorByTags`).
|
|
81
|
+
removed = entriesOf(cache)
|
|
82
|
+
.filter((entry) => isMirrorRecord(entry.value) && hasAnyTag(entry, tags) && hashes.has(entry.key))
|
|
83
|
+
.map((entry) => entry.key);
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// TanStack's hashes alone cannot vouch for what sits under them in the mirror —
|
|
87
|
+
// enumerate and keep only mirror records, so a foreign entry at a colliding key
|
|
88
|
+
// survives the purge.
|
|
89
|
+
removed = entriesOf(cache)
|
|
90
|
+
.filter((entry) => isMirrorRecord(entry.value) && hashes.has(entry.key))
|
|
91
|
+
.map((entry) => entry.key);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
else if (queryKey) {
|
|
95
|
+
const exactHash = exact ? resolveQueryHash(client, queryKey) : undefined;
|
|
96
|
+
removed = entriesOf(cache)
|
|
97
|
+
.filter((entry) => {
|
|
98
|
+
// One gate for every key-based branch: this package purges *mirror records* only.
|
|
99
|
+
// `exactHash` is computable, but the value under it is not — a shared cache may
|
|
100
|
+
// hold an axios/fetch/SWR entry (or an app value) under the same key string.
|
|
101
|
+
if (!isMirrorRecord(entry.value))
|
|
102
|
+
return false;
|
|
103
|
+
if (tags && !hasAnyTag(entry, tags))
|
|
104
|
+
return false;
|
|
105
|
+
if (exactHash !== undefined) {
|
|
106
|
+
// An exact key is a single candidate hash — no enumeration needed for the
|
|
107
|
+
// key match itself, and the tag test above already narrowed it.
|
|
108
|
+
return entry.key === exactHash;
|
|
109
|
+
}
|
|
110
|
+
const entryKey = entry.value.queryKey;
|
|
111
|
+
// Legacy records (no `queryKey`) predate the self-describing format; they are only
|
|
112
|
+
// reachable through a live TanStack query, which the invalidate/remove side covers.
|
|
113
|
+
if (entryKey === undefined)
|
|
114
|
+
return false;
|
|
115
|
+
return partialMatchKey(entryKey, queryKey);
|
|
116
|
+
})
|
|
117
|
+
.map((entry) => entry.key);
|
|
118
|
+
}
|
|
119
|
+
else if (tags) {
|
|
120
|
+
removed = purgeMirrorByTags(cache, tags);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
// No filters at all: every *mirror record* goes — and nothing else. On a shared
|
|
124
|
+
// cache the store holds other integrations' entries too (see `isMirrorRecord`), so
|
|
125
|
+
// "everything persisted for queries" must not read as "everything in the cache".
|
|
126
|
+
removed = entriesOf(cache)
|
|
127
|
+
.filter((entry) => isMirrorRecord(entry.value))
|
|
128
|
+
.map((entry) => entry.key);
|
|
129
|
+
}
|
|
130
|
+
for (const key of removed)
|
|
131
|
+
cache.delete(key);
|
|
132
|
+
// TanStack's side. With `tags` in play, tag membership is what the mirror knew and
|
|
133
|
+
// TanStack cannot see, so it becomes a predicate composed with the original filters —
|
|
134
|
+
// every other selector still applies through `matchQuery`.
|
|
135
|
+
if (tags) {
|
|
136
|
+
const removedSet = new Set(removed);
|
|
137
|
+
return {
|
|
138
|
+
...queryFilters,
|
|
139
|
+
predicate: (query) => removedSet.has(query.queryHash) && matchQuery(queryFilters, query),
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
return queryFilters;
|
|
143
|
+
}
|
|
144
|
+
/**
|
|
145
|
+
* `prefetchQuery` that starts from the Blaze Cache.
|
|
146
|
+
*
|
|
147
|
+
* Mirrors {@link useBlazeQuery} imperatively: the persisted record is seeded as
|
|
148
|
+
* `initialData` with its original `dataUpdatedAt` before prefetching, so a `staleTime`
|
|
149
|
+
* window can be satisfied from disk without touching the network at all. When a fetch
|
|
150
|
+
* does run, its result is written back to the mirror under the same record (tags, TTL and
|
|
151
|
+
* self-describing `queryKey` included) — even on a client with no sync layer attached.
|
|
152
|
+
*
|
|
153
|
+
* Errors are swallowed exactly like TanStack's `prefetchQuery`.
|
|
154
|
+
*
|
|
155
|
+
* ```ts
|
|
156
|
+
* await prefetchBlazeQuery(cache, client, {
|
|
157
|
+
* queryKey: ['todos', userId],
|
|
158
|
+
* queryFn: () => fetchTodos(userId),
|
|
159
|
+
* staleTime: 5 * 60_000,
|
|
160
|
+
* tags: ['todos', `user:${userId}`],
|
|
161
|
+
* });
|
|
162
|
+
* ```
|
|
163
|
+
*/
|
|
164
|
+
export async function prefetchBlazeQuery(cache, client, options) {
|
|
165
|
+
// Seed first, so freshness is judged against the persisted record — a mirror hit inside
|
|
166
|
+
// `staleTime` completes without a network round trip.
|
|
167
|
+
const seeded = seedBlazeQueryOptions(cache, client, options);
|
|
168
|
+
await client.prefetchQuery(seeded);
|
|
169
|
+
const hash = resolveQueryHash(client, options.queryKey, options);
|
|
170
|
+
const query = client.getQueryCache().get(hash);
|
|
171
|
+
const data = query?.state.data;
|
|
172
|
+
if (!query || data === undefined)
|
|
173
|
+
return; // failed fetch — nothing to persist
|
|
174
|
+
cache.set(hash, { data, dataUpdatedAt: query.state.dataUpdatedAt, queryKey: options.queryKey }, mirrorWriteOptions(options));
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* `setQueryData` that also writes the Blaze Cache mirror.
|
|
178
|
+
*
|
|
179
|
+
* The TanStack write goes through first (so its exact `dataUpdatedAt` — and structural
|
|
180
|
+
* sharing, which may keep the previous object — is what both caches record), then the
|
|
181
|
+
* mirror is written synchronously under the resolved query hash, tagged per `options`.
|
|
182
|
+
* With a sync layer attached, its batched write sees this identical record and leaves the
|
|
183
|
+
* helper's `ttlMs`/`tags` in place.
|
|
184
|
+
*
|
|
185
|
+
* `data` is a plain value, not an updater — pass a function to TanStack's own
|
|
186
|
+
* `client.setQueryData` when you need to read the previous value first. `undefined` is
|
|
187
|
+
* ignored on both sides, exactly as TanStack ignores it.
|
|
188
|
+
*
|
|
189
|
+
* ```ts
|
|
190
|
+
* setBlazeQueryData(cache, client, ['settings', userId], settings, {
|
|
191
|
+
* tags: ['settings', `user:${userId}`],
|
|
192
|
+
* });
|
|
193
|
+
* ```
|
|
194
|
+
*
|
|
195
|
+
* @returns The stored data, or `undefined` when `data` was `undefined`.
|
|
196
|
+
*/
|
|
197
|
+
export function setBlazeQueryData(cache, client, queryKey, data, options) {
|
|
198
|
+
// Explicit `QueryKey` (rather than the caller's `TQueryKey`) for the key type argument:
|
|
199
|
+
// a generic key keeps `InferDataFromTag` a deferred conditional the data would not
|
|
200
|
+
// assign to, while the widened key resolves it to `TData` — and tag inference does not
|
|
201
|
+
// matter here, since this function *supplies* the data instead of reading it.
|
|
202
|
+
const stored = client.setQueryData(queryKey, data);
|
|
203
|
+
if (stored === undefined)
|
|
204
|
+
return undefined;
|
|
205
|
+
const hash = resolveQueryHash(client, queryKey);
|
|
206
|
+
const dataUpdatedAt = client.getQueryCache().get(hash)?.state.dataUpdatedAt ?? Date.now() /* always set */;
|
|
207
|
+
cache.set(hash, { data: stored, dataUpdatedAt, queryKey }, mirrorWriteOptions(options));
|
|
208
|
+
return stored;
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* `invalidateQueries` for both caches at once: TanStack marks the matching queries stale
|
|
212
|
+
* (active ones refetch, as usual), and the matching **persisted** records are purged so a
|
|
213
|
+
* reload cannot paint pre-invalidation data.
|
|
214
|
+
*
|
|
215
|
+
* Keeping the mirror entry instead would defeat the call — `dataUpdatedAt` is TanStack's
|
|
216
|
+
* staleness clock, and a persisted record would come back as `initialData` on the next
|
|
217
|
+
* session regardless of when it was invalidated. In-session behaviour is untouched:
|
|
218
|
+
* the refetched results re-mirror themselves through the sync layer, stale-while-revalidate
|
|
219
|
+
* included. This mirrors the sync layer's own contract that *explicit* purges remove
|
|
220
|
+
* mirror entries (see {@link syncBlazeQueryCache}).
|
|
221
|
+
*
|
|
222
|
+
* Filters work on both sides; see {@link BlazeQueryFilters} for how `tags`, keys and
|
|
223
|
+
* query-state selectors combine. Purging by tag or by non-exact key needs
|
|
224
|
+
* `cache.entries` — both **throw** when it is absent rather than under-delivering.
|
|
225
|
+
* (Tag purges deliberately enumerate rather than call `cache.invalidateTags`: the core's
|
|
226
|
+
* tag index is one global namespace, so that call would reach other integrations' entries
|
|
227
|
+
* on a shared cache. Enumeration keeps the purge on mirror records — see
|
|
228
|
+
* {@link isMirrorRecord}.)
|
|
229
|
+
*
|
|
230
|
+
* ```ts
|
|
231
|
+
* await invalidateBlazeQueries(cache, client, { queryKey: ['todos', userId] });
|
|
232
|
+
* await invalidateBlazeQueries(cache, client, { tags: [`user:${userId}`] });
|
|
233
|
+
* ```
|
|
234
|
+
*
|
|
235
|
+
* @returns Resolves like TanStack's `invalidateQueries` — once the triggered refetches settle.
|
|
236
|
+
*/
|
|
237
|
+
export function invalidateBlazeQueries(cache, client, filters = {}) {
|
|
238
|
+
const tanstackFilters = purgeMirrorAndBuildFilters(cache, client, filters);
|
|
239
|
+
return client.invalidateQueries(tanstackFilters);
|
|
240
|
+
}
|
|
241
|
+
/**
|
|
242
|
+
* `removeQueries` for both caches at once: TanStack drops the matching queries outright,
|
|
243
|
+
* and the matching persisted records are purged — the explicit-purge half of the sync
|
|
244
|
+
* layer's contract (see {@link syncBlazeQueryCache}).
|
|
245
|
+
*
|
|
246
|
+
* The same mirror-side rules and rejections as {@link invalidateBlazeQueries} apply; the
|
|
247
|
+
* difference between the two helpers is what happens on TanStack's side (dropped vs.
|
|
248
|
+
* marked stale), not what happens in the mirror.
|
|
249
|
+
*
|
|
250
|
+
* ```ts
|
|
251
|
+
* // After a logout — including queries from earlier sessions TanStack never loaded:
|
|
252
|
+
* removeBlazeQueries(cache, client, { tags: [`user:${userId}`] });
|
|
253
|
+
* // Every mirror record — and only those, so foreign entries on a shared cache stay:
|
|
254
|
+
* removeBlazeQueries(cache, client);
|
|
255
|
+
* ```
|
|
256
|
+
*/
|
|
257
|
+
export function removeBlazeQueries(cache, client, filters = {}) {
|
|
258
|
+
const tanstackFilters = purgeMirrorAndBuildFilters(cache, client, filters);
|
|
259
|
+
client.removeQueries(tanstackFilters);
|
|
260
|
+
}
|
|
261
|
+
//# sourceMappingURL=imperative.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"imperative.js","sourceRoot":"","sources":["../src/imperative.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAUpE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AACzD,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAwB3D,gGAAgG;AAChG,SAAS,kBAAkB,CAAC,OAA4B;IAItD,OAAO;QACL,KAAK,EAAE,OAAO,EAAE,KAAK,IAAI,cAAc;QACvC,IAAI,EAAE,OAAO,EAAE,IAAI,IAAI,YAAY;KACpC,CAAC;AACJ,CAAC;AAED,uFAAuF;AACvF,SAAS,SAAS,CAAC,KAA0B;IAC3C,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,gFAAgF;YAC9E,yEAAyE;YACzE,4EAA4E;YAC5E,0DAA0D,CAC7D,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC,OAAO,EAAE,CAAC;AACzB,CAAC;AAED,+CAA+C;AAC/C,SAAS,SAAS,CAAC,KAAuB,EAAE,IAAuB;IACjE,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,GAAG,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AAI,CAAC,GAAG,EAAE,CAAC,gBAAgB,CAAC;IACvF,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE,aAAa,EAAE,QAAQ,EAAE,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC,CAAC;IACxF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,UAAU,sBAAsB,CACpC,KAA0B,EAC1B,MAAmB,EACnB,UAA6B,EAAE;IAE/B,MAAM,eAAe,GAAG,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC,iBAAiB,CAAC,eAAe,CAAC,CAAC;AACnD,CAAC;AAED;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,kBAAkB,CAChC,KAA0B,EAC1B,MAAmB,EACnB,UAA6B,EAAE;IAE/B,MAAM,eAAe,GAAG,0BAA0B,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAAC;IAC3E,MAAM,CAAC,aAAa,CAAC,eAAe,CAAC,CAAC;AACxC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TanStack Query (v5) integration backed by Blaze Cache.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Three independent pieces:
|
|
5
5
|
*
|
|
6
6
|
* * {@link syncBlazeQueryCache} / {@link createBlazeQueryClient} — mirror successful queries
|
|
7
7
|
* so they survive a reload.
|
|
8
|
-
* *
|
|
9
|
-
*
|
|
8
|
+
* * Hooks that seed from that mirror: {@link useBlazeQuery}, {@link useBlazeInfiniteQuery}
|
|
9
|
+
* and {@link useBlazeQueries} paint instantly from persisted data while TanStack still
|
|
10
|
+
* refetches in the background; {@link useBlazeMutation} invalidates both caches after a
|
|
11
|
+
* successful mutation.
|
|
12
|
+
* * Imperative helpers that keep both caches in step without a hook:
|
|
13
|
+
* {@link prefetchBlazeQuery}, {@link setBlazeQueryData}, {@link invalidateBlazeQueries},
|
|
14
|
+
* {@link removeBlazeQueries}, and the persistence round trip
|
|
15
|
+
* {@link dehydrateBlazeQueryClient} / {@link hydrateBlazeQueryClient}.
|
|
10
16
|
*
|
|
11
17
|
* ```tsx
|
|
12
18
|
* const cache = await createCache();
|
|
@@ -24,7 +30,17 @@
|
|
|
24
30
|
* @packageDocumentation
|
|
25
31
|
*/
|
|
26
32
|
export { createBlazeQueryClient, syncBlazeQueryCache } from './sync.js';
|
|
33
|
+
export { isMirrorRecord } from './record.js';
|
|
27
34
|
export { hashQueryKey, resolveQueryHash } from './hash.js';
|
|
28
|
-
export { seedBlazeQueryOptions, useBlazeQuery } from './useBlazeQuery.js';
|
|
29
|
-
export
|
|
35
|
+
export { readBlazeRecord, seedBlazeQueryOptions, useBlazeQuery } from './useBlazeQuery.js';
|
|
36
|
+
export { seedBlazeInfiniteQueryOptions, useBlazeInfiniteQuery, } from './useBlazeInfiniteQuery.js';
|
|
37
|
+
export { seedBlazeQueriesOptions, useBlazeQueries } from './useBlazeQueries.js';
|
|
38
|
+
export type { UseBlazeQueriesOptions } from './useBlazeQueries.js';
|
|
39
|
+
export { invalidateBlazeQueries, prefetchBlazeQuery, removeBlazeQueries, setBlazeQueryData, } from './imperative.js';
|
|
40
|
+
export type { BlazeFetchQueryOptions } from './imperative.js';
|
|
41
|
+
export { useBlazeMutation } from './useBlazeMutation.js';
|
|
42
|
+
export type { BlazeMutationOptions } from './useBlazeMutation.js';
|
|
43
|
+
export { dehydrateBlazeQueryClient, hydrateBlazeQueryClient } from './hydration.js';
|
|
44
|
+
export type { DehydrateBlazeOptions, HydrateBlazeOptions } from './hydration.js';
|
|
45
|
+
export type { BlazeMirrorEntry, BlazeMirrorOptions, BlazeQueryCacheLike, BlazeQueryClientOptions, BlazeQueryFilters, BlazeQueryRecord, BlazeQuerySyncOptions, } from './types.js';
|
|
30
46
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAChF,YAAY,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AACnE,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AACzB,YAAY,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,YAAY,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAClE,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC;AACpF,YAAY,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AAEjF,YAAY,EACV,gBAAgB,EAChB,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,YAAY,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* TanStack Query (v5) integration backed by Blaze Cache.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
4
|
+
* Three independent pieces:
|
|
5
5
|
*
|
|
6
6
|
* * {@link syncBlazeQueryCache} / {@link createBlazeQueryClient} — mirror successful queries
|
|
7
7
|
* so they survive a reload.
|
|
8
|
-
* *
|
|
9
|
-
*
|
|
8
|
+
* * Hooks that seed from that mirror: {@link useBlazeQuery}, {@link useBlazeInfiniteQuery}
|
|
9
|
+
* and {@link useBlazeQueries} paint instantly from persisted data while TanStack still
|
|
10
|
+
* refetches in the background; {@link useBlazeMutation} invalidates both caches after a
|
|
11
|
+
* successful mutation.
|
|
12
|
+
* * Imperative helpers that keep both caches in step without a hook:
|
|
13
|
+
* {@link prefetchBlazeQuery}, {@link setBlazeQueryData}, {@link invalidateBlazeQueries},
|
|
14
|
+
* {@link removeBlazeQueries}, and the persistence round trip
|
|
15
|
+
* {@link dehydrateBlazeQueryClient} / {@link hydrateBlazeQueryClient}.
|
|
10
16
|
*
|
|
11
17
|
* ```tsx
|
|
12
18
|
* const cache = await createCache();
|
|
@@ -24,6 +30,12 @@
|
|
|
24
30
|
* @packageDocumentation
|
|
25
31
|
*/
|
|
26
32
|
export { createBlazeQueryClient, syncBlazeQueryCache } from './sync.js';
|
|
33
|
+
export { isMirrorRecord } from './record.js';
|
|
27
34
|
export { hashQueryKey, resolveQueryHash } from './hash.js';
|
|
28
|
-
export { seedBlazeQueryOptions, useBlazeQuery } from './useBlazeQuery.js';
|
|
35
|
+
export { readBlazeRecord, seedBlazeQueryOptions, useBlazeQuery } from './useBlazeQuery.js';
|
|
36
|
+
export { seedBlazeInfiniteQueryOptions, useBlazeInfiniteQuery, } from './useBlazeInfiniteQuery.js';
|
|
37
|
+
export { seedBlazeQueriesOptions, useBlazeQueries } from './useBlazeQueries.js';
|
|
38
|
+
export { invalidateBlazeQueries, prefetchBlazeQuery, removeBlazeQueries, setBlazeQueryData, } from './imperative.js';
|
|
39
|
+
export { useBlazeMutation } from './useBlazeMutation.js';
|
|
40
|
+
export { dehydrateBlazeQueryClient, hydrateBlazeQueryClient } from './hydration.js';
|
|
29
41
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AAEH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,qBAAqB,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC3F,OAAO,EACL,6BAA6B,EAC7B,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAEhF,OAAO,EACL,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAEzD,OAAO,EAAE,yBAAyB,EAAE,uBAAuB,EAAE,MAAM,gBAAgB,CAAC"}
|
package/dist/record.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { BlazeQueryRecord } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Shape check: is this value a record **this package** could have written?
|
|
4
|
+
*
|
|
5
|
+
* Every record the sync layer and the imperative helpers write carries `dataUpdatedAt`,
|
|
6
|
+
* TanStack's own timestamp — and nothing the *other* integrations store on a shared cache
|
|
7
|
+
* does. Axios and fetch records are stamped `storedAt`/`freshUntil`, SWR persists raw
|
|
8
|
+
* fetcher results, and manual entries are whatever the app put there.
|
|
9
|
+
*
|
|
10
|
+
* The check exists for the shared-cache reality a single-package type cannot see: it
|
|
11
|
+
* keeps a mirror read from handing a foreign value to TanStack as query data, and the
|
|
12
|
+
* unfiltered purge from reading foreign entries as its own. The one unavoidable false
|
|
13
|
+
* positive is an app value that happens to carry a numeric `dataUpdatedAt`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function isMirrorRecord(value: unknown): value is BlazeQueryRecord;
|
|
16
|
+
//# sourceMappingURL=record.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.d.ts","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,gBAAgB,CAMxE"}
|
package/dist/record.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shape check: is this value a record **this package** could have written?
|
|
3
|
+
*
|
|
4
|
+
* Every record the sync layer and the imperative helpers write carries `dataUpdatedAt`,
|
|
5
|
+
* TanStack's own timestamp — and nothing the *other* integrations store on a shared cache
|
|
6
|
+
* does. Axios and fetch records are stamped `storedAt`/`freshUntil`, SWR persists raw
|
|
7
|
+
* fetcher results, and manual entries are whatever the app put there.
|
|
8
|
+
*
|
|
9
|
+
* The check exists for the shared-cache reality a single-package type cannot see: it
|
|
10
|
+
* keeps a mirror read from handing a foreign value to TanStack as query data, and the
|
|
11
|
+
* unfiltered purge from reading foreign entries as its own. The one unavoidable false
|
|
12
|
+
* positive is an app value that happens to carry a numeric `dataUpdatedAt`.
|
|
13
|
+
*/
|
|
14
|
+
export function isMirrorRecord(value) {
|
|
15
|
+
return (typeof value === 'object' &&
|
|
16
|
+
value !== null &&
|
|
17
|
+
typeof value.dataUpdatedAt === 'number');
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=record.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"record.js","sourceRoot":"","sources":["../src/record.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,cAAc,CAAC,KAAc;IAC3C,OAAO,CACL,OAAO,KAAK,KAAK,QAAQ;QACzB,KAAK,KAAK,IAAI;QACd,OAAQ,KAAqC,CAAC,aAAa,KAAK,QAAQ,CACzE,CAAC;AACJ,CAAC"}
|
package/dist/sync.d.ts
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { QueryClient } from '@tanstack/react-query';
|
|
2
2
|
import type { BlazeQueryClientOptions, BlazeQuerySyncOptions } from './types.js';
|
|
3
|
+
/** Mirrored data survives this long in the Blaze Cache (TanStack owns in-session freshness). */
|
|
4
|
+
export declare const DEFAULT_TTL_MS = 86400000;
|
|
5
|
+
/** Default tag, so `cache.invalidateTags('react-query')` purges the whole mirror. */
|
|
6
|
+
export declare const DEFAULT_TAGS: readonly string[];
|
|
3
7
|
/**
|
|
4
8
|
* Mirrors TanStack Query's cache into a Blaze Cache.
|
|
5
9
|
*
|
package/dist/sync.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAIpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAEjF,gGAAgG;AAChG,eAAO,MAAM,cAAc,WAAa,CAAC;AACzC,qFAAqF;AACrF,eAAO,MAAM,YAAY,EAAE,SAAS,MAAM,EAAoB,CAAC;AAE/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,qBAAqB,GAC7B,MAAM,IAAI,CA6IZ;AAED;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,WAAW,CAKpF"}
|
package/dist/sync.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { QueryClient } from '@tanstack/react-query';
|
|
2
|
+
import { isMirrorRecord } from './record.js';
|
|
2
3
|
/** Mirrored data survives this long in the Blaze Cache (TanStack owns in-session freshness). */
|
|
3
|
-
const DEFAULT_TTL_MS = 86_400_000;
|
|
4
|
+
export const DEFAULT_TTL_MS = 86_400_000;
|
|
4
5
|
/** Default tag, so `cache.invalidateTags('react-query')` purges the whole mirror. */
|
|
5
|
-
const DEFAULT_TAGS = ['react-query'];
|
|
6
|
+
export const DEFAULT_TAGS = ['react-query'];
|
|
6
7
|
/**
|
|
7
8
|
* Mirrors TanStack Query's cache into a Blaze Cache.
|
|
8
9
|
*
|
|
@@ -99,8 +100,17 @@ export function syncBlazeQueryCache(client, options) {
|
|
|
99
100
|
// GC and explicit purges are indistinguishable in the event — the wrapper flag above
|
|
100
101
|
// is the only difference. Keep the mirror through GC: the persisted copy exists for
|
|
101
102
|
// the next session's first paint, not for this one's housekeeping.
|
|
102
|
-
|
|
103
|
-
|
|
103
|
+
//
|
|
104
|
+
// Shape-gated: a key TanStack removes may hold another integration's entry on a
|
|
105
|
+
// shared cache (the axios/fetch/swr wrappers key by URL, and a hash can collide with
|
|
106
|
+
// one). Deleting on the strength of the TanStack event alone would destroy an entry
|
|
107
|
+
// this layer never wrote — when the cache cannot tell mirror records from foreign
|
|
108
|
+
// values (`peek` absent, or a non-mirror value), an unknown value is left alone.
|
|
109
|
+
if (explicitRemoval && !options.skip?.(query.queryKey, hash)) {
|
|
110
|
+
const record = cache.peek ? cache.peek(hash) : undefined;
|
|
111
|
+
if (record === undefined || isMirrorRecord(record))
|
|
112
|
+
cache.delete(hash);
|
|
113
|
+
}
|
|
104
114
|
return;
|
|
105
115
|
}
|
|
106
116
|
if (event.type !== 'updated')
|
|
@@ -113,7 +123,45 @@ export function syncBlazeQueryCache(client, options) {
|
|
|
113
123
|
return;
|
|
114
124
|
if (options.skip?.(query.queryKey, hash))
|
|
115
125
|
return;
|
|
116
|
-
|
|
126
|
+
// An identical record is already in the mirror — the imperative helpers
|
|
127
|
+
// (`setBlazeQueryData`, `prefetchBlazeQuery`, `hydrateBlazeQueryClient`) write theirs
|
|
128
|
+
// synchronously, ahead of this batched flush. Skip so *their* `ttlMs`/`tags` survive:
|
|
129
|
+
// re-writing here would re-stamp the entry with the sync's defaults and silently strip
|
|
130
|
+
// a per-query tag. Same data reference and same timestamp means nothing actually
|
|
131
|
+
// changed, so skipping loses nothing but the redundant write.
|
|
132
|
+
const existing = cache.peek ? cache.peek(hash) : undefined;
|
|
133
|
+
if (existing &&
|
|
134
|
+
existing.data === data &&
|
|
135
|
+
existing.dataUpdatedAt === query.state.dataUpdatedAt) {
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
// When the entry already exists (a *refetch*: new data, or a helper's write that this
|
|
139
|
+
// flush is now updating), the previous stamp wins over the sync defaults. A helper that
|
|
140
|
+
// wrote `tags: ['todos', 'user:42']` under a short TTL meant exactly that — re-stamping
|
|
141
|
+
// with the defaults would strip the per-query tags (so `cache.invalidateTags('todos')`
|
|
142
|
+
// silently stopped reaching the entry) and reset the deliberate short freshness window.
|
|
143
|
+
// `peek` and the readers below are synchronous, so nothing can change between them.
|
|
144
|
+
const preserve = existing !== undefined && isMirrorRecord(existing);
|
|
145
|
+
// `undefined` from either reader means "no reader on this cache" — fall back to the
|
|
146
|
+
// defaults, exactly as before. An *empty* tag list is a value, not an absence: an
|
|
147
|
+
// explicit `tags: []` write must survive a refetch too, so `??` (not `||`) selects it.
|
|
148
|
+
const previousTags = preserve && cache.tagsOf ? cache.tagsOf(hash) : undefined;
|
|
149
|
+
const previousTtlMs = preserve && cache.ttl ? (cache.ttl(hash) ?? 0) : undefined;
|
|
150
|
+
// `queryKey` (and `queryType` for infinite queries) make the record self-describing:
|
|
151
|
+
// dehydrate needs them to rebuild a TanStack query from the mirror alone.
|
|
152
|
+
cache.set(hash, {
|
|
153
|
+
data,
|
|
154
|
+
dataUpdatedAt: query.state.dataUpdatedAt,
|
|
155
|
+
queryKey: query.queryKey,
|
|
156
|
+
...(query.queryType === 'infinite' ? { queryType: 'infinite' } : null),
|
|
157
|
+
}, {
|
|
158
|
+
// `ttl() === undefined` for a live entry means it has *no* deadline; `0` is how
|
|
159
|
+
// the core spells "never expires", so that round-trips instead of being replaced
|
|
160
|
+
// by a fresh 24 h default. A finite value is the *remaining* window — the helper's
|
|
161
|
+
// original deadline stands; the refetch does not extend the lease it chose.
|
|
162
|
+
ttlMs: previousTtlMs ?? ttlMs,
|
|
163
|
+
tags: previousTags ?? tags,
|
|
164
|
+
});
|
|
117
165
|
});
|
|
118
166
|
return () => {
|
|
119
167
|
unsubscribe();
|
package/dist/sync.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAG7C,gGAAgG;AAChG,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,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