@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/dist/types.d.ts CHANGED
@@ -1,13 +1,40 @@
1
- import type { QueryClientConfig, QueryKey } from '@tanstack/react-query';
1
+ import type { QueryClientConfig, QueryFilters, QueryKey } from '@tanstack/react-query';
2
2
  /**
3
3
  * What the integration stores for one query.
4
4
  *
5
5
  * `dataUpdatedAt` is TanStack's own timestamp, so a restored entry feeds its staleness
6
6
  * arithmetic exactly as if the fetch had happened in this session.
7
+ *
8
+ * `queryKey` is written by {@link syncBlazeQueryCache} and the imperative helpers so a
9
+ * mirror entry is self-describing: {@link dehydrateBlazeQueryClient} needs it to rebuild
10
+ * a TanStack query from the mirror alone. Optional because entries written by older
11
+ * versions of this package do not carry it — those still hydrate the hooks, they just
12
+ * cannot be dehydrated back into TanStack.
7
13
  */
8
14
  export interface BlazeQueryRecord<T = unknown> {
9
15
  data: T;
10
16
  dataUpdatedAt: number;
17
+ queryKey?: QueryKey;
18
+ /**
19
+ * `'infinite'` for infinite queries, absent for plain ones — the same `_type` TanStack
20
+ * stamps on the query itself, so {@link dehydrateBlazeQueryClient} can rebuild an infinite
21
+ * query as one. Written by the sync layer and the imperative helpers for records that
22
+ * carry `queryKey`; absent (meaning: plain) on older records.
23
+ */
24
+ queryType?: 'infinite';
25
+ }
26
+ /**
27
+ * One live mirror entry as {@link BlazeQueryCacheLike.entries} reports it.
28
+ *
29
+ * Structurally a subset of the concrete cache's `CacheEntry`, so `cache.entries()` is
30
+ * assignable without ceremony.
31
+ */
32
+ export interface BlazeMirrorEntry {
33
+ /** The query hash the record is filed under — a `DehydratedQuery.queryHash`. */
34
+ key: string;
35
+ value: BlazeQueryRecord;
36
+ /** Tags attached to this entry, for tag-filtered purges and dehydration. */
37
+ readonly tags: readonly string[];
11
38
  }
12
39
  /**
13
40
  * The slice of a cache the integration needs.
@@ -29,12 +56,54 @@ export interface BlazeQueryCacheLike {
29
56
  * discarded concurrent renders).
30
57
  */
31
58
  peek?(key: string): BlazeQueryRecord | undefined;
59
+ /**
60
+ * The tags currently attached to `key` (empty when the key is unknown).
61
+ *
62
+ * Optional, like {@link BlazeQueryCacheLike.peek}: the concrete `BlazeCache` has it as
63
+ * `tagsOf()`. When present, the sync layer reads the existing entry's tags before
64
+ * re-writing it (a refetch of a query whose helper set per-query tags) so the re-write
65
+ * preserves them instead of stamping the sync defaults over them. When absent, the
66
+ * re-write falls back to the sync defaults — the same behaviour as before this reader
67
+ * existed.
68
+ */
69
+ tagsOf?(key: string): readonly string[];
70
+ /**
71
+ * Milliseconds until `key` expires, or `undefined` when it has no TTL or is unknown.
72
+ *
73
+ * Optional for the same reason as {@link BlazeQueryCacheLike.tagsOf}: with it, a refetch
74
+ * re-write can keep the entry's *remaining* freshness window (a helper's short TTL is a
75
+ * deliberate choice) rather than resetting it to a fresh full TTL.
76
+ */
77
+ ttl?(key: string): number | undefined;
32
78
  set(key: string, value: BlazeQueryRecord, options?: {
33
79
  ttlMs?: number;
34
80
  tags?: readonly string[];
35
81
  }): void;
36
82
  delete(key: string): boolean;
37
83
  has(key: string): boolean;
84
+ /**
85
+ * Removes every entry carrying any of `tags`, returning the removed keys.
86
+ *
87
+ * Not called by this package: the purge helpers enumerate {@link BlazeQueryCacheLike.entries}
88
+ * instead (or throw when it is absent), so a purge on a cache shared with another
89
+ * integration stays on mirror records — `invalidateTags` reaches the whole tag namespace,
90
+ * all integrations included. It remains part of the cache contract for callers who want
91
+ * exactly that.
92
+ */
93
+ invalidateTags?(...tags: string[]): string[];
94
+ /**
95
+ * Every live entry — key, record and tags — without touching statistics.
96
+ *
97
+ * Optional, like {@link BlazeQueryCacheLike.peek} and
98
+ * {@link BlazeQueryCacheLike.invalidateTags}: enumerating the mirror is what lets the
99
+ * filter-aware helpers ({@link invalidateBlazeQueries}, {@link removeBlazeQueries},
100
+ * {@link dehydrateBlazeQueryClient}) match entries the current session's TanStack cache
101
+ * never touched — a prefix purge after a user switch, a full-mirror wipe, a dehydration
102
+ * of everything persisted. When a filter needs enumeration and it is absent, those
103
+ * helpers **throw** instead of silently purging only what TanStack happens to know right
104
+ * now. The concrete `BlazeCache` has it as `entries()`.
105
+ */
106
+ entries?(): BlazeMirrorEntry[];
38
107
  }
39
108
  /** Options for {@link syncBlazeQueryCache} and {@link createBlazeQueryClient}. */
40
109
  export interface BlazeQuerySyncOptions {
@@ -58,4 +127,28 @@ export interface BlazeQueryClientOptions extends BlazeQuerySyncOptions {
58
127
  /** Options handed to `new QueryClient(...)` — its own `queryCache` is respected. */
59
128
  client?: QueryClientConfig;
60
129
  }
130
+ /** How an imperative helper writes into the Blaze Cache alongside TanStack Query. */
131
+ export interface BlazeMirrorOptions {
132
+ /** TTL for the mirror entry. Defaults to the same 24 h the sync layer uses. */
133
+ ttlMs?: number;
134
+ /** Tags for the mirror entry. Defaults to `['react-query']`. */
135
+ tags?: readonly string[];
136
+ }
137
+ /**
138
+ * A `QueryFilters` with an extra Blaze tag selector.
139
+ *
140
+ * `tags` matches mirror entries through {@link BlazeQueryCacheLike}-style tag lookup on
141
+ * the concrete cache (`cache.invalidateTags` / `cache.keysWithTag`). When both a
142
+ * `queryKey`/`predicate` and `tags` are given, a query must match **both**.
143
+ */
144
+ export interface BlazeQueryFilters extends QueryFilters {
145
+ /** Invalidate/remove mirror entries carrying any of these tags. */
146
+ tags?: readonly string[];
147
+ /**
148
+ * Which queries to refetch when invalidating — forwarded to TanStack's
149
+ * `invalidateQueries`, ignored by `removeQueries` (removed queries refetch only when a
150
+ * hook asks for them again).
151
+ */
152
+ refetchType?: 'active' | 'inactive' | 'all' | 'none';
153
+ }
61
154
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,iBAAiB,EAAE,QAAQ,EAAE,MAAM,uBA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AE,GAAG,MAAM,EAAE,CAAC;IAC7C;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,IAAI,gBAAgB,EAAE,CAAC;CAChC;AAED,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,mBAAmB,CAAC;IAE3B;;;;;OAKG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IAEf,yFAAyF;IACzF,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IAEzB,qEAAqE;IACrE,IAAI,CAAC,EAAE,CAAC,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,KAAK,OAAO,CAAC;IAE1D,mEAAmE;IACnE,YAAY,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,iFAAiF;AACjF,MAAM,WAAW,uBAAwB,SAAQ,qBAAqB;IACpE,oFAAoF;IACpF,MAAM,CAAC,EAAE,iBAAiB,CAAC;CAC5B;AAED,qFAAqF;AACrF,MAAM,WAAW,kBAAkB;IACjC,+EAA+E;IAC/E,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,gEAAgE;IAChE,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,MAAM,WAAW,iBAAkB,SAAQ,YAAY;IACrD,mEAAmE;IACnE,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAC;IACzB;;;;OAIG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,UAAU,GAAG,KAAK,GAAG,MAAM,CAAC;CACtD"}
@@ -0,0 +1,46 @@
1
+ import type { DefaultError, InfiniteData, QueryClient, QueryKey, UseInfiniteQueryOptions, UseInfiniteQueryResult } from '@tanstack/react-query';
2
+ import type { BlazeQueryCacheLike } from './types.js';
3
+ /**
4
+ * The options {@link useBlazeInfiniteQuery} hands to `useInfiniteQuery`: the caller's
5
+ * options with the Blaze Cache mirror seeded in, or the caller's options returned
6
+ * untouched.
7
+ *
8
+ * Infinite queries are mirrored as a whole — TanStack stores `InfiniteData` (every page
9
+ * plus its page params) as one `query.state.data`, so the sync layer persists that one
10
+ * object and this function seeds it straight back as `initialData`. The first render
11
+ * after a reload therefore paints **all previously loaded pages at once**, while
12
+ * `dataUpdatedAt` carries the original timestamp so TanStack still refetches in the
13
+ * background.
14
+ *
15
+ * The rules are exactly {@link seedBlazeQueryOptions}'s, deliberately:
16
+ *
17
+ * * A caller-supplied `initialData` or `initialDataUpdatedAt` is authoritative — the
18
+ * mirror stays out of it entirely.
19
+ * * With neither supplied, the mirror seeds both fields together, so the data paints
20
+ * instantly *and* is treated as stale.
21
+ */
22
+ export declare function seedBlazeInfiniteQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(cache: BlazeQueryCacheLike, client: QueryClient, options: UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>;
23
+ /**
24
+ * `useInfiniteQuery` that starts from the Blaze Cache.
25
+ *
26
+ * A previously mirrored `InfiniteData` payload — every page and page param fetched in an
27
+ * earlier session — is injected as `initialData` **with its original `dataUpdatedAt`**,
28
+ * so the list paints fully populated on the first render after a reload while TanStack
29
+ * still considers it stale and refetches in the background. Caller-supplied
30
+ * `initialData`/`initialDataUpdatedAt` short-circuit the seeding entirely; see
31
+ * {@link seedBlazeInfiniteQueryOptions}.
32
+ *
33
+ * ```tsx
34
+ * const feed = useBlazeInfiniteQuery(cache, {
35
+ * queryKey: ['feed', userId],
36
+ * queryFn: ({ pageParam }) => fetchFeed(userId, pageParam),
37
+ * initialPageParam: 0,
38
+ * getNextPageParam: (lastPage) => lastPage.nextCursor,
39
+ * });
40
+ * // feed.data?.pages — the pages cached before the reload, immediately
41
+ * ```
42
+ *
43
+ * Requires a `QueryClientProvider` above it, exactly like `useInfiniteQuery`.
44
+ */
45
+ export declare function useBlazeInfiniteQuery<TQueryFnData = unknown, TError = DefaultError, TData = InfiniteData<TQueryFnData>, TQueryKey extends QueryKey = QueryKey, TPageParam = unknown>(cache: BlazeQueryCacheLike, options: UseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>): UseInfiniteQueryResult<TData, TError>;
46
+ //# sourceMappingURL=useBlazeInfiniteQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeInfiniteQuery.d.ts","sourceRoot":"","sources":["../src/useBlazeInfiniteQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,6BAA6B,CAC3C,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,CAAC,YAAY,CAAC,EAClC,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,UAAU,GAAG,OAAO,EAEpB,KAAK,EAAE,mBAAmB,EAC1B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,GACnF,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,CAiC7E;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,CAAC,YAAY,CAAC,EAClC,SAAS,SAAS,QAAQ,GAAG,QAAQ,EACrC,UAAU,GAAG,OAAO,EAEpB,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,uBAAuB,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,CAAC,GACnF,sBAAsB,CAAC,KAAK,EAAE,MAAM,CAAC,CAMvC"}
@@ -0,0 +1,80 @@
1
+ import { useInfiniteQuery, useQueryClient } from '@tanstack/react-query';
2
+ import { readBlazeRecord } from './useBlazeQuery.js';
3
+ /**
4
+ * The options {@link useBlazeInfiniteQuery} hands to `useInfiniteQuery`: the caller's
5
+ * options with the Blaze Cache mirror seeded in, or the caller's options returned
6
+ * untouched.
7
+ *
8
+ * Infinite queries are mirrored as a whole — TanStack stores `InfiniteData` (every page
9
+ * plus its page params) as one `query.state.data`, so the sync layer persists that one
10
+ * object and this function seeds it straight back as `initialData`. The first render
11
+ * after a reload therefore paints **all previously loaded pages at once**, while
12
+ * `dataUpdatedAt` carries the original timestamp so TanStack still refetches in the
13
+ * background.
14
+ *
15
+ * The rules are exactly {@link seedBlazeQueryOptions}'s, deliberately:
16
+ *
17
+ * * A caller-supplied `initialData` or `initialDataUpdatedAt` is authoritative — the
18
+ * mirror stays out of it entirely.
19
+ * * With neither supplied, the mirror seeds both fields together, so the data paints
20
+ * instantly *and* is treated as stale.
21
+ */
22
+ export function seedBlazeInfiniteQueryOptions(cache, client, options) {
23
+ // Same authority rule as the non-infinite seed: an explicit `initialData` (function
24
+ // form included) or its timestamp short-circuits the mirror entirely.
25
+ if (options.initialData !== undefined || options.initialDataUpdatedAt !== undefined) {
26
+ return options;
27
+ }
28
+ const record = readBlazeRecord(cache, client, options);
29
+ if (record === undefined)
30
+ return options;
31
+ // Shape gate before seeding: this key's mirror record may hold plain (non-paginated)
32
+ // data — a `setBlazeQueryData` write on the same key, a query that was once a plain
33
+ // query and later became infinite, or a foreign value at a colliding key on a shared
34
+ // cache. Handing TanStack a non-`InfiniteData` payload produces a "successful" query
35
+ // whose `data.pages` is `undefined` — the first `data.pages.map(...)` in app code
36
+ // crashes *after* rendering looked healthy. A non-matching record is simply not seeded:
37
+ // the query fetches normally, exactly as if the mirror were empty.
38
+ const data = record.data;
39
+ const isInfiniteShaped = typeof data === 'object' &&
40
+ data !== null &&
41
+ Array.isArray(data.pages) &&
42
+ Array.isArray(data.pageParams);
43
+ if (!isInfiniteShaped)
44
+ return options;
45
+ // The mirror's payload *is* an `InfiniteData` object — that is what TanStack put in
46
+ // the cache — so it slots into `initialData` without transformation. The cast exists
47
+ // because the record type is deliberately untyped (`unknown`).
48
+ return {
49
+ ...options,
50
+ initialData: record.data,
51
+ initialDataUpdatedAt: record.dataUpdatedAt,
52
+ };
53
+ }
54
+ /**
55
+ * `useInfiniteQuery` that starts from the Blaze Cache.
56
+ *
57
+ * A previously mirrored `InfiniteData` payload — every page and page param fetched in an
58
+ * earlier session — is injected as `initialData` **with its original `dataUpdatedAt`**,
59
+ * so the list paints fully populated on the first render after a reload while TanStack
60
+ * still considers it stale and refetches in the background. Caller-supplied
61
+ * `initialData`/`initialDataUpdatedAt` short-circuit the seeding entirely; see
62
+ * {@link seedBlazeInfiniteQueryOptions}.
63
+ *
64
+ * ```tsx
65
+ * const feed = useBlazeInfiniteQuery(cache, {
66
+ * queryKey: ['feed', userId],
67
+ * queryFn: ({ pageParam }) => fetchFeed(userId, pageParam),
68
+ * initialPageParam: 0,
69
+ * getNextPageParam: (lastPage) => lastPage.nextCursor,
70
+ * });
71
+ * // feed.data?.pages — the pages cached before the reload, immediately
72
+ * ```
73
+ *
74
+ * Requires a `QueryClientProvider` above it, exactly like `useInfiniteQuery`.
75
+ */
76
+ export function useBlazeInfiniteQuery(cache, options) {
77
+ const client = useQueryClient();
78
+ return useInfiniteQuery(seedBlazeInfiniteQueryOptions(cache, client, options));
79
+ }
80
+ //# sourceMappingURL=useBlazeInfiniteQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeInfiniteQuery.js","sourceRoot":"","sources":["../src/useBlazeInfiniteQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;A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;AACJ,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { DefaultError, UseMutationOptions, UseMutationResult } from '@tanstack/react-query';
2
+ import type { BlazeQueryCacheLike, BlazeQueryFilters } from './types.js';
3
+ /**
4
+ * The options {@link useBlazeMutation} accepts: TanStack's own `UseMutationOptions` —
5
+ * everything you can pass to `useMutation` — plus declarative, **two-sided** invalidation.
6
+ */
7
+ export interface BlazeMutationOptions<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown> extends UseMutationOptions<TData, TError, TVariables, TContext> {
8
+ /**
9
+ * Queries invalidated after a successful mutation, one filter or an array of them —
10
+ * each applied through {@link invalidateBlazeQueries}, so TanStack marks them stale
11
+ * (active ones refetch) **and** the matching persisted records are purged.
12
+ *
13
+ * Runs after your own `onSuccess`, awaited in order, so callback side effects (writes,
14
+ * navigation) land before anything is invalidated — and a throwing `onSuccess` skips
15
+ * the invalidation exactly like it skips TanStack's own refetch chain.
16
+ *
17
+ * ```ts
18
+ * const addTodo = useBlazeMutation(cache, {
19
+ * mutationFn: (text: string) => api.addTodo(text),
20
+ * invalidate: { queryKey: ['todos'] },
21
+ * });
22
+ * ```
23
+ *
24
+ * Omit it to keep invalidation entirely in your own `onSuccess`/`onSettled` — those are
25
+ * untouched when no `invalidate` is given.
26
+ */
27
+ invalidate?: BlazeQueryFilters | BlazeQueryFilters[];
28
+ }
29
+ /**
30
+ * `useMutation` whose success path keeps the Blaze Cache mirror in step.
31
+ *
32
+ * Apart from the optional {@link BlazeMutationOptions.invalidate} — TanStack-side
33
+ * invalidation plus mirror purge through {@link invalidateBlazeQueries} — this is
34
+ * `useMutation` verbatim: same generics, same result type, same per-call callbacks, and
35
+ * your hook-level callbacks run first when both are present.
36
+ *
37
+ * ```tsx
38
+ * function AddTodo({ userId }: { userId: string }) {
39
+ * const addTodo = useBlazeMutation(cache, {
40
+ * mutationFn: (text: string) => api.addTodo(userId, text),
41
+ * invalidate: [
42
+ * { queryKey: ['todos', userId] },
43
+ * { tags: ['todos', `user:${userId}`] },
44
+ * ],
45
+ * onSuccess: () => toast('Added'),
46
+ * });
47
+ * // addTodo.mutate('Buy milk') — 'Added' toasts, then both filters invalidate
48
+ * }
49
+ * ```
50
+ *
51
+ * Requires a `QueryClientProvider` above it, exactly like `useMutation`.
52
+ */
53
+ export declare function useBlazeMutation<TData = unknown, TError = DefaultError, TVariables = void, TContext = unknown>(cache: BlazeQueryCacheLike, options: BlazeMutationOptions<TData, TError, TVariables, TContext>): UseMutationResult<TData, TError, TVariables, TContext>;
54
+ //# sourceMappingURL=useBlazeMutation.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeMutation.d.ts","sourceRoot":"","sources":["../src/useBlazeMutation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAGjG,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAEzE;;;GAGG;AACH,MAAM,WAAW,oBAAoB,CACnC,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,YAAY,EACrB,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,CAClB,SAAQ,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC;IAC/D;;;;;;;;;;;;;;;;;;OAkBG;IACH,UAAU,CAAC,EAAE,iBAAiB,GAAG,iBAAiB,EAAE,CAAC;CACtD;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,gBAAgB,CAC9B,KAAK,GAAG,OAAO,EACf,MAAM,GAAG,YAAY,EACrB,UAAU,GAAG,IAAI,EACjB,QAAQ,GAAG,OAAO,EAElB,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,oBAAoB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,GACjE,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,UAAU,EAAE,QAAQ,CAAC,CA2BxD"}
@@ -0,0 +1,50 @@
1
+ import { useMutation, useQueryClient } from '@tanstack/react-query';
2
+ import { invalidateBlazeQueries } from './imperative.js';
3
+ /**
4
+ * `useMutation` whose success path keeps the Blaze Cache mirror in step.
5
+ *
6
+ * Apart from the optional {@link BlazeMutationOptions.invalidate} — TanStack-side
7
+ * invalidation plus mirror purge through {@link invalidateBlazeQueries} — this is
8
+ * `useMutation` verbatim: same generics, same result type, same per-call callbacks, and
9
+ * your hook-level callbacks run first when both are present.
10
+ *
11
+ * ```tsx
12
+ * function AddTodo({ userId }: { userId: string }) {
13
+ * const addTodo = useBlazeMutation(cache, {
14
+ * mutationFn: (text: string) => api.addTodo(userId, text),
15
+ * invalidate: [
16
+ * { queryKey: ['todos', userId] },
17
+ * { tags: ['todos', `user:${userId}`] },
18
+ * ],
19
+ * onSuccess: () => toast('Added'),
20
+ * });
21
+ * // addTodo.mutate('Buy milk') — 'Added' toasts, then both filters invalidate
22
+ * }
23
+ * ```
24
+ *
25
+ * Requires a `QueryClientProvider` above it, exactly like `useMutation`.
26
+ */
27
+ export function useBlazeMutation(cache, options) {
28
+ const client = useQueryClient();
29
+ // Without `invalidate` there is nothing to compose — pass the caller's options through
30
+ // untouched, so `onSuccess` semantics are byte-for-byte TanStack's.
31
+ if (options.invalidate === undefined) {
32
+ return useMutation(options, client);
33
+ }
34
+ const { invalidate, onSuccess, ...mutationOptions } = options;
35
+ return useMutation({
36
+ ...mutationOptions,
37
+ onSuccess: async (data, variables, onMutateResult, context) => {
38
+ // Caller first: their `onSuccess` writes/navigation happen before invalidation,
39
+ // and if it throws, no invalidation runs — mirroring how TanStack treats a
40
+ // throwing `onSuccess` by abandoning the rest of its success chain.
41
+ if (onSuccess)
42
+ await onSuccess(data, variables, onMutateResult, context);
43
+ const filters = Array.isArray(invalidate) ? invalidate : [invalidate];
44
+ for (const filter of filters) {
45
+ await invalidateBlazeQueries(cache, client, filter);
46
+ }
47
+ },
48
+ }, client);
49
+ }
50
+ //# sourceMappingURL=useBlazeMutation.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeMutation.js","sourceRoot":"","sources":["../src/useBlazeMutation.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAGpE,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AAmCzD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,UAAU,gBAAgB,CAM9B,KAA0B,EAC1B,OAAkE;IAElE,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAEhC,uFAAuF;IACvF,oEAAoE;IACpE,IAAI,OAAO,CAAC,UAAU,KAAK,SAAS,EAAE,CAAC;QACrC,OAAO,WAAW,CAAsC,OAAO,EAAE,MAAM,CAAC,CAAC;IAC3E,CAAC;IAED,MAAM,EAAE,UAAU,EAAE,SAAS,EAAE,GAAG,eAAe,EAAE,GAAG,OAAO,CAAC;IAE9D,OAAO,WAAW,CAChB;QACE,GAAG,eAAe;QAClB,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,EAAE,EAAE;YAC5D,gFAAgF;YAChF,2EAA2E;YAC3E,oEAAoE;YACpE,IAAI,SAAS;gBAAE,MAAM,SAAS,CAAC,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;YACzE,MAAM,OAAO,GAAG,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC;YACtE,KAAK,MAAM,MAAM,IAAI,OAAO,EAAE,CAAC;gBAC7B,MAAM,sBAAsB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;YACtD,CAAC;QACH,CAAC;KACF,EACD,MAAM,CACP,CAAC;AACJ,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { QueriesOptions, QueriesResults, QueryClient } from '@tanstack/react-query';
2
+ import type { BlazeQueryCacheLike } from './types.js';
3
+ /**
4
+ * The options {@link useBlazeQueries} accepts: TanStack's own `useQueries` shape — a
5
+ * `queries` array plus the optional `combine` — with each query seeded from the Blaze
6
+ * Cache first.
7
+ *
8
+ * The generics mirror `useQueries`' so per-query inference (each `queryFn`'s result,
9
+ * each `select`, and `combine`'s output) survives the round trip: a tuple of queries
10
+ * destructure into individually typed results, exactly as with `useQueries`.
11
+ */
12
+ export interface UseBlazeQueriesOptions<T extends Array<any>, TCombinedResult = QueriesResults<T>> {
13
+ /** Query option objects — the same shapes `useQueries` takes, seeded from the mirror. */
14
+ queries: readonly [...QueriesOptions<T>];
15
+ /** Combine the results into a single value, as `useQueries` does. */
16
+ combine?: (result: QueriesResults<T>) => TCombinedResult;
17
+ }
18
+ /**
19
+ * The render-time data path for {@link useBlazeQueries}: seed every query's options
20
+ * from the Blaze Cache, then hand the array to TanStack.
21
+ *
22
+ * Exposed as a plain function (like {@link seedBlazeQueryOptions}) so the per-query
23
+ * seeding can be exercised without a DOM renderer. Each entry goes through
24
+ * {@link seedBlazeQueryOptions} unchanged — the same authority rules, the same
25
+ * `peek`-first lookup, the same custom-hasher handling — so one cold entry in the
26
+ * mirror never blocks the others from seeding.
27
+ */
28
+ export declare function seedBlazeQueriesOptions<T extends Array<any>, TCombinedResult = QueriesResults<T>>(cache: BlazeQueryCacheLike, client: QueryClient, options: UseBlazeQueriesOptions<T, TCombinedResult>): UseBlazeQueriesOptions<T, TCombinedResult>;
29
+ /**
30
+ * `useQueries` where every query is seeded from the Blaze Cache.
31
+ *
32
+ * The parallel equivalent of {@link useBlazeQuery}: each query in the array gets the
33
+ * instant-first-paint treatment independently — a cached entry becomes `initialData`
34
+ * with its original `dataUpdatedAt`, an uncached one fetches cold. Results and typing
35
+ * match `useQueries` exactly, including `combine`.
36
+ *
37
+ * ```tsx
38
+ * const [profile, settings, notifications] = useBlazeQueries(cache, {
39
+ * queries: [
40
+ * { queryKey: ['profile', userId], queryFn: () => api.profile(userId) },
41
+ * { queryKey: ['settings'], queryFn: api.settings },
42
+ * { queryKey: ['notifications', userId], queryFn: () => api.notifications(userId) },
43
+ * ],
44
+ * });
45
+ * ```
46
+ *
47
+ * Requires a `QueryClientProvider` above it, exactly like `useQueries`.
48
+ */
49
+ export declare function useBlazeQueries<T extends Array<any>, TCombinedResult = QueriesResults<T>>(cache: BlazeQueryCacheLike, options: UseBlazeQueriesOptions<T, TCombinedResult>): TCombinedResult;
50
+ //# sourceMappingURL=useBlazeQueries.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeQueries.d.ts","sourceRoot":"","sources":["../src/useBlazeQueries.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,WAAW,EACZ,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;GAQG;AACH,MAAM,WAAW,sBAAsB,CACrC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EACpB,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC;IAEnC,yFAAyF;IACzF,OAAO,EAAE,SAAS,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,qEAAqE;IACrE,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC,CAAC,KAAK,eAAe,CAAC;CAC1D;AAED;;;;;;;;;GASG;AACH,wBAAgB,uBAAuB,CACrC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EACpB,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,EAEnC,KAAK,EAAE,mBAAmB,EAC1B,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,sBAAsB,CAAC,CAAC,EAAE,eAAe,CAAC,GAClD,sBAAsB,CAAC,CAAC,EAAE,eAAe,CAAC,CAU5C;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,CAAC,CAAC,SAAS,KAAK,CAAC,GAAG,CAAC,EAAE,eAAe,GAAG,cAAc,CAAC,CAAC,CAAC,EACvF,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,sBAAsB,CAAC,CAAC,EAAE,eAAe,CAAC,GAClD,eAAe,CAIjB"}
@@ -0,0 +1,46 @@
1
+ import { useQueries, useQueryClient } from '@tanstack/react-query';
2
+ import { seedBlazeQueryOptions } from './useBlazeQuery.js';
3
+ /**
4
+ * The render-time data path for {@link useBlazeQueries}: seed every query's options
5
+ * from the Blaze Cache, then hand the array to TanStack.
6
+ *
7
+ * Exposed as a plain function (like {@link seedBlazeQueryOptions}) so the per-query
8
+ * seeding can be exercised without a DOM renderer. Each entry goes through
9
+ * {@link seedBlazeQueryOptions} unchanged — the same authority rules, the same
10
+ * `peek`-first lookup, the same custom-hasher handling — so one cold entry in the
11
+ * mirror never blocks the others from seeding.
12
+ */
13
+ export function seedBlazeQueriesOptions(cache, client, options) {
14
+ return {
15
+ ...options,
16
+ // Per-entry seeding is type-preserving, but `T` is generic here so TS only sees the
17
+ // elements' constraint and refuses the direct cast to the conditional
18
+ // `QueriesOptions<T>` shape — the `unknown` bridge is the honest description.
19
+ queries: options.queries.map((query) => seedBlazeQueryOptions(cache, client, query)),
20
+ };
21
+ }
22
+ /**
23
+ * `useQueries` where every query is seeded from the Blaze Cache.
24
+ *
25
+ * The parallel equivalent of {@link useBlazeQuery}: each query in the array gets the
26
+ * instant-first-paint treatment independently — a cached entry becomes `initialData`
27
+ * with its original `dataUpdatedAt`, an uncached one fetches cold. Results and typing
28
+ * match `useQueries` exactly, including `combine`.
29
+ *
30
+ * ```tsx
31
+ * const [profile, settings, notifications] = useBlazeQueries(cache, {
32
+ * queries: [
33
+ * { queryKey: ['profile', userId], queryFn: () => api.profile(userId) },
34
+ * { queryKey: ['settings'], queryFn: api.settings },
35
+ * { queryKey: ['notifications', userId], queryFn: () => api.notifications(userId) },
36
+ * ],
37
+ * });
38
+ * ```
39
+ *
40
+ * Requires a `QueryClientProvider` above it, exactly like `useQueries`.
41
+ */
42
+ export function useBlazeQueries(cache, options) {
43
+ const client = useQueryClient();
44
+ return useQueries(seedBlazeQueriesOptions(cache, client, options), client);
45
+ }
46
+ //# sourceMappingURL=useBlazeQueries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeQueries.js","sourceRoot":"","sources":["../src/useBlazeQueries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AAOnE,OAAO,EAAE,qBAAqB,EAAE,MAAM,oBAAoB,CAAC;AAsB3D;;;;;;;;;GASG;AACH,MAAM,UAAU,uBAAuB,CAIrC,KAA0B,EAC1B,MAAmB,EACnB,OAAmD;IAEnD,OAAO;QACL,GAAG,OAAO;QACV,oFAAoF;QACpF,sEAAsE;QACtE,8EAA8E;QAC9E,OAAO,EAAE,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CACrC,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,CAAC,CACwB;KACtE,CAAC;AACJ,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,UAAU,eAAe,CAC7B,KAA0B,EAC1B,OAAmD;IAEnD,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAEhC,OAAO,UAAU,CAAqB,uBAAuB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;AACjG,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { DefaultError, QueryClient, QueryKey, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
2
- import type { BlazeQueryCacheLike } from './types.js';
2
+ import type { BlazeQueryCacheLike, BlazeQueryRecord } from './types.js';
3
3
  /**
4
4
  * The options {@link useBlazeQuery} hands to `useQuery`: the caller's options with the Blaze
5
5
  * Cache mirror seeded in, or the caller's options returned untouched.
@@ -18,6 +18,16 @@ import type { BlazeQueryCacheLike } from './types.js';
18
18
  * stale, so the background refetch happens exactly as it would without the cache.
19
19
  */
20
20
  export declare function seedBlazeQueryOptions<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(cache: BlazeQueryCacheLike, client: QueryClient, options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>): UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>;
21
+ /**
22
+ * The mirror lookup every seed function shares: resolve the query's hash the way TanStack
23
+ * will file it, then read the record back **without** touching cache statistics.
24
+ *
25
+ * Kept separate from the seeding rules so {@link seedBlazeQueryOptions},
26
+ * {@link seedBlazeInfiniteQueryOptions} and {@link seedBlazeQueriesOptions} cannot drift
27
+ * from each other — a custom `queryKeyHashFn` or a `peek`-less cache behaves identically
28
+ * in all three.
29
+ */
30
+ export declare function readBlazeRecord(cache: BlazeQueryCacheLike, client: QueryClient, options: Pick<UseQueryOptions<any, any, any, any>, 'queryKey' | 'queryHash' | 'queryKeyHashFn'>): BlazeQueryRecord | undefined;
21
31
  /**
22
32
  * `useQuery` that starts from the Blaze Cache.
23
33
  *
@@ -1 +1 @@
1
- {"version":3,"file":"useBlazeQuery.d.ts","sourceRoot":"","sources":["../src/useBlazeQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,QAAQ,EACR,eAAe,EACf,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;;;;;;GAgBG;AACH,wBAAgB,qBAAqB,CACnC,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,KAAK,EAAE,mBAAmB,EAC1B,MAAM,EAAE,W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AC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,EACnC,UAAU,GAAG,WAAW,GAAG,gBAAgB,CAC5C,GACA,gBAAgB,GAAG,SAAS,CAmB9B;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,aAAa,CAC3B,YAAY,GAAG,OAAO,EACtB,MAAM,GAAG,YAAY,EACrB,KAAK,GAAG,YAAY,EACpB,SAAS,SAAS,QAAQ,GAAG,QAAQ,EAErC,KAAK,EAAE,mBAAmB,EAC1B,OAAO,EAAE,eAAe,CAAC,YAAY,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,CAAC,GAC/D,cAAc,CAAC,KAAK,EAAE,MAAM,CAAC,CAM/B"}
@@ -1,5 +1,6 @@
1
1
  import { useQuery, useQueryClient } from '@tanstack/react-query';
2
2
  import { resolveQueryHash } from './hash.js';
3
+ import { isMirrorRecord } from './record.js';
3
4
  /**
4
5
  * The options {@link useBlazeQuery} hands to `useQuery`: the caller's options with the Blaze
5
6
  * Cache mirror seeded in, or the caller's options returned untouched.
@@ -23,15 +24,7 @@ export function seedBlazeQueryOptions(cache, client, options) {
23
24
  if (options.initialData !== undefined || options.initialDataUpdatedAt !== undefined) {
24
25
  return options;
25
26
  }
26
- // Sync writes under `query.queryHash`, which honors a configured `queryKeyHashFn`; resolve
27
- // the hash the same way TanStack does, or a custom hasher points the lookup at a key the
28
- // mirror never used.
29
- const hash = resolveQueryHash(client, options.queryKey, options);
30
- // `peek` first: `get` marks the entry used for SIEVE and counts a hit/miss, so a render
31
- // would mutate global cache state — StrictMode double-renders and discarded concurrent
32
- // renders included — and skew the stats panel. `get` stays the fallback for caches that
33
- // predate `peek` (it is optional on `BlazeQueryCacheLike` for their sake).
34
- const record = cache.peek ? cache.peek(hash) : cache.get(hash);
27
+ const record = readBlazeRecord(cache, client, options);
35
28
  if (record === undefined)
36
29
  return options;
37
30
  // `initialData` is declared against `TData` in one overload and `TQueryFnData` in another;
@@ -42,6 +35,37 @@ export function seedBlazeQueryOptions(cache, client, options) {
42
35
  initialDataUpdatedAt: record.dataUpdatedAt,
43
36
  };
44
37
  }
38
+ /**
39
+ * The mirror lookup every seed function shares: resolve the query's hash the way TanStack
40
+ * will file it, then read the record back **without** touching cache statistics.
41
+ *
42
+ * Kept separate from the seeding rules so {@link seedBlazeQueryOptions},
43
+ * {@link seedBlazeInfiniteQueryOptions} and {@link seedBlazeQueriesOptions} cannot drift
44
+ * from each other — a custom `queryKeyHashFn` or a `peek`-less cache behaves identically
45
+ * in all three.
46
+ */
47
+ export function readBlazeRecord(cache, client,
48
+ // Deliberately `any`-typed generics: callers pass options generic in `TQueryKey`, and a
49
+ // `readonly unknown[]`-constrained pick rejects `QueryKeyHashFunction<TQueryKey>` under
50
+ // contravariance even though every concrete instantiation fits.
51
+ options) {
52
+ // Sync writes under `query.queryHash`, which honors a configured `queryKeyHashFn`; resolve
53
+ // the hash the same way TanStack does, or a custom hasher points the lookup at a key the
54
+ // mirror never used.
55
+ const hash = resolveQueryHash(client, options.queryKey, options);
56
+ // `peek` first: `get` marks the entry used for SIEVE and counts a hit/miss, so a render
57
+ // would mutate global cache state — StrictMode double-renders and discarded concurrent
58
+ // renders included — and skew the stats panel. `get` stays the fallback for caches that
59
+ // predate `peek` (it is optional on `BlazeQueryCacheLike` for their sake).
60
+ const record = cache.peek ? cache.peek(hash) : cache.get(hash);
61
+ // Shape gate: on a cache shared with `@blaze-cache/axios`, `@blaze-cache/fetch` or
62
+ // `@blaze-cache/swr`, a forced key collision can park a foreign value under this query's
63
+ // hash. Seeding it would hand an HTTP body (or a raw fetcher result) to TanStack as
64
+ // `initialData` — with no `dataUpdatedAt` to date it, so a configured `staleTime` would
65
+ // be ignored too. Only a record this package could have written is mirror data; anything
66
+ // else reads as the miss it is. See {@link isMirrorRecord}.
67
+ return isMirrorRecord(record) ? record : undefined;
68
+ }
45
69
  /**
46
70
  * `useQuery` that starts from the Blaze Cache.
47
71
  *
@@ -1 +1 @@
1
- {"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CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAE/D,mFAAmF;IACnF,yFAAyF;IACzF,oFAAoF;IACpF,wFAAwF;IACxF,yFAAyF;IACzF,4DAA4D;IAC5D,OAAO,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC;AACrD,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,aAAa,CAM3B,KAA0B,EAC1B,OAAgE;IAEhE,MAAM,MAAM,GAAG,cAAc,EAAE,CAAC;IAEhC,OAAO,QAAQ,CACb,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,CAC9C,CAAC;AACJ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blaze-cache/react-query",
3
- "version": "0.2.3-beta",
3
+ "version": "0.3.0-beta.0",
4
4
  "description": "Persist TanStack Query v5 in WebAssembly — instant first paint after reload while stale-while-revalidate still works",
5
5
  "keywords": [
6
6
  "react-query",
@@ -38,7 +38,7 @@
38
38
  "dist"
39
39
  ],
40
40
  "dependencies": {
41
- "@blaze-cache/core": "0.2.3-beta"
41
+ "@blaze-cache/core": "0.3.0-beta.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "@tanstack/react-query": "^5.0.0"