@blaze-cache/react-query 0.0.0-stage → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Blaze Cache
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/dist/hash.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { QueryKey } from '@tanstack/react-query';
2
+ /**
3
+ * Canonical hash for a query key — the very hash TanStack Query stores in
4
+ * `query.queryHash`.
5
+ *
6
+ * Delegating to TanStack's own `hashKey` rather than re-implementing it means the pre-fetch
7
+ * lookup in {@link useBlazeQuery} can never drift from the key the sync layer writes, even
8
+ * across library upgrades.
9
+ *
10
+ * ```ts
11
+ * hashQueryKey(['todos', { page: 1, done: true }]);
12
+ * // '["todos",{"done":true,"page":1}]' — object keys are sorted, so order never matters
13
+ * ```
14
+ */
15
+ export declare function hashQueryKey(queryKey: QueryKey): string;
16
+ //# sourceMappingURL=hash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.d.ts","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEtD;;;;;;;;;;;;GAYG;AACH,wBAAgB,YAAY,CAAC,QAAQ,EAAE,QAAQ,GAAG,MAAM,CAEvD"}
package/dist/hash.js ADDED
@@ -0,0 +1,18 @@
1
+ import { hashKey } from '@tanstack/react-query';
2
+ /**
3
+ * Canonical hash for a query key — the very hash TanStack Query stores in
4
+ * `query.queryHash`.
5
+ *
6
+ * Delegating to TanStack's own `hashKey` rather than re-implementing it means the pre-fetch
7
+ * lookup in {@link useBlazeQuery} can never drift from the key the sync layer writes, even
8
+ * across library upgrades.
9
+ *
10
+ * ```ts
11
+ * hashQueryKey(['todos', { page: 1, done: true }]);
12
+ * // '["todos",{"done":true,"page":1}]' — object keys are sorted, so order never matters
13
+ * ```
14
+ */
15
+ export function hashQueryKey(queryKey) {
16
+ return hashKey(queryKey);
17
+ }
18
+ //# sourceMappingURL=hash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hash.js","sourceRoot":"","sources":["../src/hash.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAGhD;;;;;;;;;;;;GAYG;AACH,MAAM,UAAU,YAAY,CAAC,QAAkB;IAC7C,OAAO,OAAO,CAAC,QAAQ,CAAC,CAAC;AAC3B,CAAC"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * TanStack Query (v5) integration backed by Blaze Cache.
3
+ *
4
+ * Two independent pieces:
5
+ *
6
+ * * {@link syncBlazeQueryCache} / {@link createBlazeQueryClient} — mirror successful queries
7
+ * so they survive a reload.
8
+ * * {@link useBlazeQuery} — a `useQuery` that seeds `initialData` from that mirror, giving
9
+ * an instant first paint while TanStack still refetches in the background.
10
+ *
11
+ * ```tsx
12
+ * const cache = await createCache();
13
+ * const queryClient = createBlazeQueryClient({ cache });
14
+ *
15
+ * function Todos({ userId }: { userId: string }) {
16
+ * const todos = useBlazeQuery(cache, {
17
+ * queryKey: ['todos', userId],
18
+ * queryFn: () => fetchTodos(userId),
19
+ * });
20
+ * // …
21
+ * }
22
+ * ```
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ export { createBlazeQueryClient, syncBlazeQueryCache } from './sync.js';
27
+ export { hashQueryKey } from './hash.js';
28
+ export { useBlazeQuery } from './useBlazeQuery.js';
29
+ export type { BlazeQueryCacheLike, BlazeQueryClientOptions, BlazeQueryRecord, BlazeQuerySyncOptions, } from './types.js';
30
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD,YAAY,EACV,mBAAmB,EACnB,uBAAuB,EACvB,gBAAgB,EAChB,qBAAqB,GACtB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,29 @@
1
+ /**
2
+ * TanStack Query (v5) integration backed by Blaze Cache.
3
+ *
4
+ * Two independent pieces:
5
+ *
6
+ * * {@link syncBlazeQueryCache} / {@link createBlazeQueryClient} — mirror successful queries
7
+ * so they survive a reload.
8
+ * * {@link useBlazeQuery} — a `useQuery` that seeds `initialData` from that mirror, giving
9
+ * an instant first paint while TanStack still refetches in the background.
10
+ *
11
+ * ```tsx
12
+ * const cache = await createCache();
13
+ * const queryClient = createBlazeQueryClient({ cache });
14
+ *
15
+ * function Todos({ userId }: { userId: string }) {
16
+ * const todos = useBlazeQuery(cache, {
17
+ * queryKey: ['todos', userId],
18
+ * queryFn: () => fetchTodos(userId),
19
+ * });
20
+ * // …
21
+ * }
22
+ * ```
23
+ *
24
+ * @packageDocumentation
25
+ */
26
+ export { createBlazeQueryClient, syncBlazeQueryCache } from './sync.js';
27
+ export { hashQueryKey } from './hash.js';
28
+ export { useBlazeQuery } from './useBlazeQuery.js';
29
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/sync.d.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { QueryClient } from '@tanstack/react-query';
2
+ import type { BlazeQueryClientOptions, BlazeQuerySyncOptions } from './types.js';
3
+ /**
4
+ * Mirrors TanStack Query's cache into a Blaze Cache.
5
+ *
6
+ * The two layers have different jobs, and the seam is deliberate:
7
+ *
8
+ * | Event | Behaviour |
9
+ * | --- | --- |
10
+ * | `updated` + `success`/`setState` | mirrored — a completed fetch or `setQueryData` |
11
+ * | `updated` + `invalidate` | **kept** — stale data stays so `staleTime: 0` can still paint instantly |
12
+ * | `updated` + `error` | ignored — TanStack owns error state in-session |
13
+ * | `removed` | deleted, so `removeQueries` really removes it |
14
+ *
15
+ * Returns the unsubscribe function; {@link createBlazeQueryClient} wires it into
16
+ * `client.destroy()`.
17
+ */
18
+ export declare function syncBlazeQueryCache(client: QueryClient, options: BlazeQuerySyncOptions): () => void;
19
+ /**
20
+ * A `QueryClient` that mirrors every successful query into a Blaze Cache.
21
+ *
22
+ * ```ts
23
+ * const cache = await createCache({ persistence: { namespace: 'queries' } });
24
+ * const queryClient = createBlazeQueryClient({ cache });
25
+ *
26
+ * <QueryClientProvider client={queryClient}> … </QueryClientProvider>
27
+ * ```
28
+ *
29
+ * The subscription lives exactly as long as the client: the `QueryCache` holds the listener,
30
+ * and the client holds the cache, so they are collected together once you drop the client.
31
+ * Need an explicit handle? Use {@link syncBlazeQueryCache} instead.
32
+ */
33
+ export declare function createBlazeQueryClient(options: BlazeQueryClientOptions): QueryClient;
34
+ //# sourceMappingURL=sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.d.ts","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAOjF;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,mBAAmB,CACjC,MAAM,EAAE,WAAW,EACnB,OAAO,EAAE,qBAAqB,GAC7B,MAAM,IAAI,CAwBZ;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,WAAW,CAKpF"}
package/dist/sync.js ADDED
@@ -0,0 +1,66 @@
1
+ import { QueryClient } from '@tanstack/react-query';
2
+ /** Mirrored data survives this long in the Blaze Cache (TanStack owns in-session freshness). */
3
+ const DEFAULT_TTL_MS = 86_400_000;
4
+ /** Default tag, so `cache.invalidateTags('react-query')` purges the whole mirror. */
5
+ const DEFAULT_TAGS = ['react-query'];
6
+ /**
7
+ * Mirrors TanStack Query's cache into a Blaze Cache.
8
+ *
9
+ * The two layers have different jobs, and the seam is deliberate:
10
+ *
11
+ * | Event | Behaviour |
12
+ * | --- | --- |
13
+ * | `updated` + `success`/`setState` | mirrored — a completed fetch or `setQueryData` |
14
+ * | `updated` + `invalidate` | **kept** — stale data stays so `staleTime: 0` can still paint instantly |
15
+ * | `updated` + `error` | ignored — TanStack owns error state in-session |
16
+ * | `removed` | deleted, so `removeQueries` really removes it |
17
+ *
18
+ * Returns the unsubscribe function; {@link createBlazeQueryClient} wires it into
19
+ * `client.destroy()`.
20
+ */
21
+ export function syncBlazeQueryCache(client, options) {
22
+ const { cache } = options;
23
+ const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
24
+ const tags = options.tags ?? DEFAULT_TAGS;
25
+ return client.getQueryCache().subscribe((event) => {
26
+ const { query } = event;
27
+ const hash = query.queryHash;
28
+ if (event.type === 'removed') {
29
+ if (!options.skip?.(query.queryKey, hash))
30
+ cache.delete(hash);
31
+ return;
32
+ }
33
+ if (event.type !== 'updated')
34
+ return;
35
+ // `success` covers fetches and `setQueryData`; `setState` covers `hydrate()`/manual writes.
36
+ if (event.action.type !== 'success' && event.action.type !== 'setState')
37
+ return;
38
+ const data = query.state.data;
39
+ if (data === undefined && !options.includeEmpty)
40
+ return;
41
+ if (options.skip?.(query.queryKey, hash))
42
+ return;
43
+ cache.set(hash, { data, dataUpdatedAt: query.state.dataUpdatedAt }, { ttlMs, tags });
44
+ });
45
+ }
46
+ /**
47
+ * A `QueryClient` that mirrors every successful query into a Blaze Cache.
48
+ *
49
+ * ```ts
50
+ * const cache = await createCache({ persistence: { namespace: 'queries' } });
51
+ * const queryClient = createBlazeQueryClient({ cache });
52
+ *
53
+ * <QueryClientProvider client={queryClient}> … </QueryClientProvider>
54
+ * ```
55
+ *
56
+ * The subscription lives exactly as long as the client: the `QueryCache` holds the listener,
57
+ * and the client holds the cache, so they are collected together once you drop the client.
58
+ * Need an explicit handle? Use {@link syncBlazeQueryCache} instead.
59
+ */
60
+ export function createBlazeQueryClient(options) {
61
+ const { client: clientOptions, ...syncOptions } = options;
62
+ const client = new QueryClient(clientOptions);
63
+ syncBlazeQueryCache(client, syncOptions);
64
+ return client;
65
+ }
66
+ //# sourceMappingURL=sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sync.js","sourceRoot":"","sources":["../src/sync.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAKpD,gGAAgG;AAChG,MAAM,cAAc,GAAG,UAAU,CAAC;AAClC,qFAAqF;AACrF,MAAM,YAAY,GAAsB,CAAC,aAAa,CAAC,CAAC;AAExD;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAmB,EACnB,OAA8B;IAE9B,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1B,MAAM,KAAK,GAAG,OAAO,CAAC,KAAK,IAAI,cAAc,CAAC;IAC9C,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,IAAI,YAAY,CAAC;IAE1C,OAAO,MAAM,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC,KAA4B,EAAE,EAAE;QACvE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,CAAC;QACxB,MAAM,IAAI,GAAG,KAAK,CAAC,SAAS,CAAC;QAE7B,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,IAAI,CAAC,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC;gBAAE,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAC9D,OAAO;QACT,CAAC;QAED,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS;YAAE,OAAO;QACrC,4FAA4F;QAC5F,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,SAAS,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU;YAAE,OAAO;QAEhF,MAAM,IAAI,GAAG,KAAK,CAAC,KAAK,CAAC,IAAI,CAAC;QAC9B,IAAI,IAAI,KAAK,SAAS,IAAI,CAAC,OAAO,CAAC,YAAY;YAAE,OAAO;QACxD,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,QAAQ,EAAE,IAAI,CAAC;YAAE,OAAO;QAEjD,KAAK,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,aAAa,EAAE,KAAK,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;IACvF,CAAC,CAAC,CAAC;AACL,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,sBAAsB,CAAC,OAAgC;IACrE,MAAM,EAAE,MAAM,EAAE,aAAa,EAAE,GAAG,WAAW,EAAE,GAAG,OAAO,CAAC;IAC1D,MAAM,MAAM,GAAG,IAAI,WAAW,CAAC,aAAa,CAAC,CAAC;IAC9C,mBAAmB,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IACzC,OAAO,MAAM,CAAC;AAChB,CAAC"}
@@ -0,0 +1,50 @@
1
+ import type { QueryClientConfig, QueryKey } from '@tanstack/react-query';
2
+ /**
3
+ * What the integration stores for one query.
4
+ *
5
+ * `dataUpdatedAt` is TanStack's own timestamp, so a restored entry feeds its staleness
6
+ * arithmetic exactly as if the fetch had happened in this session.
7
+ */
8
+ export interface BlazeQueryRecord<T = unknown> {
9
+ data: T;
10
+ dataUpdatedAt: number;
11
+ }
12
+ /**
13
+ * The slice of a cache the integration needs.
14
+ *
15
+ * The value type is `any` so that a plain `createCache()` (which stores heterogeneous values)
16
+ * is assignable without ceremony. Pass `createCache<BlazeQueryRecord>()` if you would rather
17
+ * have the compiler check both directions.
18
+ */
19
+ export interface BlazeQueryCacheLike {
20
+ get(key: string): BlazeQueryRecord | undefined;
21
+ set(key: string, value: BlazeQueryRecord, options?: {
22
+ ttlMs?: number;
23
+ tags?: readonly string[];
24
+ }): void;
25
+ delete(key: string): boolean;
26
+ has(key: string): boolean;
27
+ }
28
+ /** Options for {@link syncBlazeQueryCache} and {@link createBlazeQueryClient}. */
29
+ export interface BlazeQuerySyncOptions {
30
+ cache: BlazeQueryCacheLike;
31
+ /**
32
+ * How long mirrored data survives in the Blaze Cache.
33
+ *
34
+ * Default `86_400_000` (24 h) — TanStack owns freshness in-session, Blaze Cache owns it
35
+ * across sessions.
36
+ */
37
+ ttlMs?: number;
38
+ /** Tags attached to mirrored entries, enabling `cache.invalidateTags('react-query')`. */
39
+ tags?: readonly string[];
40
+ /** Return `true` to keep a query out of the Blaze Cache entirely. */
41
+ skip?: (queryKey: QueryKey, queryHash: string) => boolean;
42
+ /** Mirror queries whose `data` is `undefined`. Default `false`. */
43
+ includeEmpty?: boolean;
44
+ }
45
+ /** {@link BlazeQuerySyncOptions} plus options forwarded to the `QueryClient`. */
46
+ export interface BlazeQueryClientOptions extends BlazeQuerySyncOptions {
47
+ /** Options handed to `new QueryClient(...)` — its own `queryCache` is respected. */
48
+ client?: QueryClientConfig;
49
+ }
50
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAyB,iBAAiB,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAEhG;;;;;GAKG;AACH,MAAM,WAAW,gBAAgB,CAAC,CAAC,GAAG,OAAO;IAC3C,IAAI,EAAE,CAAC,CAAC;IACR,aAAa,EAAE,MAAM,CAAC;CACvB;AAED;;;;;;GAMG;AACH,MAAM,WAAW,mBAAmB;IAClC,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,gBAAgB,GAAG,SAAS,CAAC;IAC/C,GAAG,CACD,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,gBAAgB,EACvB,OAAO,CAAC,EAAE;QAAE,KAAK,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;KAAE,GACrD,IAAI,CAAC;IACR,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;IAC7B,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC3B;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"}
package/dist/types.js ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,21 @@
1
+ import type { DefaultError, QueryKey, UseQueryOptions, UseQueryResult } from '@tanstack/react-query';
2
+ import type { BlazeQueryCacheLike } from './types.js';
3
+ /**
4
+ * `useQuery` that starts from the Blaze Cache.
5
+ *
6
+ * A previously mirrored result is injected as `initialData` **with its original
7
+ * `dataUpdatedAt`**, so the first render after a reload paints real data immediately and
8
+ * TanStack still considers it stale — the background refetch happens exactly as it would
9
+ * without the cache.
10
+ *
11
+ * ```tsx
12
+ * const todos = useBlazeQuery(cache, {
13
+ * queryKey: ['todos', userId],
14
+ * queryFn: () => api.get('/todos').then((r) => r.data),
15
+ * });
16
+ * ```
17
+ *
18
+ * This requires a `QueryClientProvider` above it, exactly like `useQuery`.
19
+ */
20
+ export declare function useBlazeQuery<TQueryFnData = unknown, TError = DefaultError, TData = TQueryFnData, TQueryKey extends QueryKey = QueryKey>(cache: BlazeQueryCacheLike, options: UseQueryOptions<TQueryFnData, TError, TData, TQueryKey>): UseQueryResult<TData, TError>;
21
+ //# sourceMappingURL=useBlazeQuery.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeQuery.d.ts","sourceRoot":"","sources":["../src/useBlazeQuery.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,QAAQ,EACR,eAAe,EACf,cAAc,EACf,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AAEtD;;;;;;;;;;;;;;;;GAgBG;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,CAa/B"}
@@ -0,0 +1,32 @@
1
+ import { useQuery } from '@tanstack/react-query';
2
+ import { hashQueryKey } from './hash.js';
3
+ /**
4
+ * `useQuery` that starts from the Blaze Cache.
5
+ *
6
+ * A previously mirrored result is injected as `initialData` **with its original
7
+ * `dataUpdatedAt`**, so the first render after a reload paints real data immediately and
8
+ * TanStack still considers it stale — the background refetch happens exactly as it would
9
+ * without the cache.
10
+ *
11
+ * ```tsx
12
+ * const todos = useBlazeQuery(cache, {
13
+ * queryKey: ['todos', userId],
14
+ * queryFn: () => api.get('/todos').then((r) => r.data),
15
+ * });
16
+ * ```
17
+ *
18
+ * This requires a `QueryClientProvider` above it, exactly like `useQuery`.
19
+ */
20
+ export function useBlazeQuery(cache, options) {
21
+ // `??` keeps an explicit `initialData` (including its function form) authoritative.
22
+ const record = cache.get(hashQueryKey(options.queryKey));
23
+ // `initialData` is declared against `TData` in one overload and `TQueryFnData` in another;
24
+ // the spread makes the union unreadable to the overloads, so it is asserted once here.
25
+ const seeded = {
26
+ ...options,
27
+ initialData: options.initialData ?? record?.data,
28
+ initialDataUpdatedAt: options.initialDataUpdatedAt ?? record?.dataUpdatedAt,
29
+ };
30
+ return useQuery(seeded);
31
+ }
32
+ //# sourceMappingURL=useBlazeQuery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useBlazeQuery.js","sourceRoot":"","sources":["../src/useBlazeQuery.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAQjD,OAAO,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAGzC;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,UAAU,aAAa,CAM3B,KAA0B,EAC1B,OAAgE;IAEhE,oFAAoF;IACpF,MAAM,MAAM,GAAG,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzD,2FAA2F;IAC3F,uFAAuF;IACvF,MAAM,MAAM,GAAG;QACb,GAAG,OAAO;QACV,WAAW,EAAE,OAAO,CAAC,WAAW,IAAK,MAAM,EAAE,IAAiC;QAC9E,oBAAoB,EAAE,OAAO,CAAC,oBAAoB,IAAI,MAAM,EAAE,aAAa;KACjB,CAAC;IAE7D,OAAO,QAAQ,CAAyC,MAAM,CAAC,CAAC;AAClE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,53 @@
1
1
  {
2
2
  "name": "@blaze-cache/react-query",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.1.0",
4
+ "description": "Persist TanStack Query v5 in WebAssembly — instant first paint after reload while stale-while-revalidate still works",
5
+ "keywords": [
6
+ "react-query",
7
+ "tanstack-query",
8
+ "tanstack",
9
+ "react",
10
+ "cache",
11
+ "persistence",
12
+ "hydration",
13
+ "stale-while-revalidate",
14
+ "webassembly",
15
+ "wasm"
16
+ ],
17
+ "license": "MIT",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/blaze-cache/blaze-cache.git",
21
+ "directory": "packages/react-query"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "sideEffects": false,
27
+ "type": "module",
28
+ "main": "dist/index.js",
29
+ "types": "dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "types": "./dist/index.d.ts",
33
+ "import": "./dist/index.js"
34
+ }
35
+ },
36
+ "files": [
37
+ "dist"
38
+ ],
39
+ "dependencies": {
40
+ "@blaze-cache/core": "0.1.0"
41
+ },
42
+ "peerDependencies": {
43
+ "@tanstack/react-query": "^5.0.0"
44
+ },
45
+ "devDependencies": {
46
+ "@tanstack/react-query": "^5.90.0",
47
+ "typescript": "^5.9.3"
48
+ },
49
+ "scripts": {
50
+ "build": "tsc -p tsconfig.json",
51
+ "typecheck": "tsc -p tsconfig.typecheck.json"
52
+ }
6
53
  }
package/README.md DELETED
@@ -1,3 +0,0 @@
1
- # Temporary Holding Version
2
-
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.