@veams/status-quo-query 0.7.0 → 0.7.2
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 +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/provider.d.ts +2 -1
- package/dist/provider.js +3 -1
- package/dist/provider.js.map +1 -1
- package/package.json +1 -1
- package/src/__tests__/provider.spec.ts +14 -0
- package/src/index.ts +1 -1
- package/src/provider.ts +5 -1
package/README.md
CHANGED
|
@@ -453,6 +453,7 @@ Returns `QueryManager` with:
|
|
|
453
453
|
- `createUntrackedQuery(queryKey, queryFn, options?)`
|
|
454
454
|
- `createUntrackedMutation(mutationFn, options?)`
|
|
455
455
|
- `cancelQueries(...)`
|
|
456
|
+
- `fetchQuery(...)`
|
|
456
457
|
- `getQueryData(...)`
|
|
457
458
|
- `invalidateQueries(...)`
|
|
458
459
|
- `refetchQueries(...)`
|
|
@@ -461,7 +462,7 @@ Returns `QueryManager` with:
|
|
|
461
462
|
- `setQueryData(...)`
|
|
462
463
|
- `unsafe_getClient()`
|
|
463
464
|
|
|
464
|
-
All manager methods forward directly to the corresponding `QueryClient` methods. `
|
|
465
|
+
All manager methods forward directly to the corresponding `QueryClient` methods. `fetchQuery(...)` covers the common one-off read path without dropping to the raw client, while `unsafe_getClient()` remains the explicit escape hatch for unsupported TanStack APIs.
|
|
465
466
|
|
|
466
467
|
### Tracked Queries and Mutations
|
|
467
468
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
export * from './mutation.js';
|
|
2
2
|
export * from './query.js';
|
|
3
3
|
export * from './provider.js';
|
|
4
|
-
export type { TrackedDependencyRecord, TrackedDependencyValue, TrackedInvalidateOn, TrackedMatchMode, TrackedQueryKey, TrackedQueryKeySegment, } from './tracking';
|
|
4
|
+
export type { TrackedDependencyRecord, TrackedDependencyValue, TrackedInvalidateOn, TrackedMatchMode, TrackedQueryKey, TrackedQueryKeySegment, } from './tracking.js';
|
package/dist/provider.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type QueryClient, type MutationFunction } from '@tanstack/query-core';
|
|
2
2
|
import { type CreateMutation, type CreateUntrackedMutation, type MutationService, type TrackedMutationServiceOptions } from './mutation.js';
|
|
3
|
-
import { type CreateQuery, type CreateUntrackedQuery } from './query';
|
|
3
|
+
import { type CreateQuery, type CreateUntrackedQuery } from './query.js';
|
|
4
4
|
import { type TrackedDependencyValue } from './tracking.js';
|
|
5
5
|
/**
|
|
6
6
|
* Mutation factory returned by the paired tracked helper.
|
|
@@ -27,6 +27,7 @@ export interface QueryManager {
|
|
|
27
27
|
createUntrackedMutation: CreateUntrackedMutation;
|
|
28
28
|
createQueryAndMutation: CreateQueryAndMutation;
|
|
29
29
|
cancelQueries: QueryClient['cancelQueries'];
|
|
30
|
+
fetchQuery: QueryClient['fetchQuery'];
|
|
30
31
|
getQueryData: QueryClient['getQueryData'];
|
|
31
32
|
invalidateQueries: QueryClient['invalidateQueries'];
|
|
32
33
|
refetchQueries: QueryClient['refetchQueries'];
|
package/dist/provider.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// Import mutation and query setup functions and their factory types.
|
|
2
2
|
import { setupMutation, setupTrackedMutation, } from './mutation.js';
|
|
3
|
-
import { setupQuery, setupTrackedQuery } from './query';
|
|
3
|
+
import { setupQuery, setupTrackedQuery } from './query.js';
|
|
4
4
|
import { createTrackingRegistry, } from './tracking.js';
|
|
5
5
|
/**
|
|
6
6
|
* Prepares the query manager facade by binding all actions to a specific QueryClient instance.
|
|
@@ -44,6 +44,8 @@ export function setupQueryManager(queryClient) {
|
|
|
44
44
|
},
|
|
45
45
|
// Proxy for canceling queries with this client context.
|
|
46
46
|
cancelQueries: queryClient.cancelQueries.bind(queryClient),
|
|
47
|
+
// Proxy for fetching one query with this client context.
|
|
48
|
+
fetchQuery: queryClient.fetchQuery.bind(queryClient),
|
|
47
49
|
// Proxy for retrieving query data with this client context.
|
|
48
50
|
getQueryData: queryClient.getQueryData.bind(queryClient),
|
|
49
51
|
// Proxy for invalidating queries with this client context.
|
package/dist/provider.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,qEAAqE;AACrE,OAAO,EAKL,aAAa,EACb,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAA+C,UAAU,EAAE,iBAAiB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"provider.js","sourceRoot":"","sources":["../src/provider.ts"],"names":[],"mappings":"AAMA,qEAAqE;AACrE,OAAO,EAKL,aAAa,EACb,oBAAoB,GACrB,MAAM,eAAe,CAAC;AACvB,OAAO,EAA+C,UAAU,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AACxG,OAAO,EACL,sBAAsB,GAEvB,MAAM,eAAe,CAAC;AAmEvB;;GAEG;AACH,MAAM,UAAU,iBAAiB,CAAC,WAAwB;IACxD,sFAAsF;IACtF,sFAAsF;IACtF,MAAM,gBAAgB,GAAG,sBAAsB,EAAE,CAAC;IAClD,MAAM,YAAY,GAAG,iBAAiB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;IACtE,MAAM,eAAe,GAAG,oBAAoB,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;IAC5E,MAAM,qBAAqB,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACtD,MAAM,wBAAwB,GAAG,aAAa,CAAC,WAAW,CAAC,CAAC;IAE5D,WAAW,CAAC,aAAa,EAAE,CAAC,SAAS,CAAC,CAAC,KAAK,EAAE,EAAE;QAC9C,IAAI,KAAK,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;YAC7B,6FAA6F;YAC7F,4FAA4F;YAC5F,gFAAgF;YAChF,gBAAgB,CAAC,UAAU,CAAC,KAAK,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACrD,CAAC;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AAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -10,12 +10,21 @@ describe('Query Manager API', () => {
|
|
|
10
10
|
const cancelQueriesSpy = jest.spyOn(queryClient, 'cancelQueries');
|
|
11
11
|
const resetQueriesSpy = jest.spyOn(queryClient, 'resetQueries');
|
|
12
12
|
const removeQueriesSpy = jest.spyOn(queryClient, 'removeQueries');
|
|
13
|
+
const fetchUser = jest.fn().mockResolvedValue({ id: 7 });
|
|
14
|
+
const fetchQuerySpy = jest.spyOn(queryClient, 'fetchQuery');
|
|
13
15
|
const manager = setupQueryManager(queryClient);
|
|
14
16
|
|
|
15
17
|
manager.setQueryData<{ id: number }>(['user', 42], { id: 42 });
|
|
16
18
|
|
|
17
19
|
expect(manager.getQueryData<{ id: number }>(['user', 42])).toEqual({ id: 42 });
|
|
18
20
|
expect(manager.unsafe_getClient()).toBe(queryClient);
|
|
21
|
+
await expect(
|
|
22
|
+
manager.fetchQuery({
|
|
23
|
+
queryKey: ['user', 7],
|
|
24
|
+
queryFn: fetchUser,
|
|
25
|
+
staleTime: 60_000,
|
|
26
|
+
})
|
|
27
|
+
).resolves.toEqual({ id: 7 });
|
|
19
28
|
|
|
20
29
|
await manager.invalidateQueries({ queryKey: ['user'] });
|
|
21
30
|
await manager.refetchQueries({ queryKey: ['user'] });
|
|
@@ -23,6 +32,11 @@ describe('Query Manager API', () => {
|
|
|
23
32
|
await manager.resetQueries({ queryKey: ['user'] });
|
|
24
33
|
manager.removeQueries({ queryKey: ['user'] });
|
|
25
34
|
|
|
35
|
+
expect(fetchQuerySpy).toHaveBeenCalledWith({
|
|
36
|
+
queryKey: ['user', 7],
|
|
37
|
+
queryFn: fetchUser,
|
|
38
|
+
staleTime: 60_000,
|
|
39
|
+
});
|
|
26
40
|
expect(invalidateQueriesSpy).toHaveBeenCalledWith({ queryKey: ['user'] });
|
|
27
41
|
expect(refetchQueriesSpy).toHaveBeenCalledWith({ queryKey: ['user'] });
|
|
28
42
|
expect(cancelQueriesSpy).toHaveBeenCalledWith({ queryKey: ['user'] });
|
package/src/index.ts
CHANGED
package/src/provider.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
setupMutation,
|
|
14
14
|
setupTrackedMutation,
|
|
15
15
|
} from './mutation.js';
|
|
16
|
-
import { type CreateQuery, type CreateUntrackedQuery, setupQuery, setupTrackedQuery } from './query';
|
|
16
|
+
import { type CreateQuery, type CreateUntrackedQuery, setupQuery, setupTrackedQuery } from './query.js';
|
|
17
17
|
import {
|
|
18
18
|
createTrackingRegistry,
|
|
19
19
|
type TrackedDependencyValue,
|
|
@@ -66,6 +66,8 @@ export interface QueryManager {
|
|
|
66
66
|
createQueryAndMutation: CreateQueryAndMutation;
|
|
67
67
|
// Cancels active queries for the specified filters.
|
|
68
68
|
cancelQueries: QueryClient['cancelQueries'];
|
|
69
|
+
// Fetches one query through the shared QueryClient and returns the resolved data.
|
|
70
|
+
fetchQuery: QueryClient['fetchQuery'];
|
|
69
71
|
// Synchronously retrieves a snapshot of the current query data.
|
|
70
72
|
getQueryData: QueryClient['getQueryData'];
|
|
71
73
|
// Marks queries as invalid to trigger a refetch if they are active.
|
|
@@ -149,6 +151,8 @@ export function setupQueryManager(queryClient: QueryClient): QueryManager {
|
|
|
149
151
|
},
|
|
150
152
|
// Proxy for canceling queries with this client context.
|
|
151
153
|
cancelQueries: queryClient.cancelQueries.bind(queryClient),
|
|
154
|
+
// Proxy for fetching one query with this client context.
|
|
155
|
+
fetchQuery: queryClient.fetchQuery.bind(queryClient),
|
|
152
156
|
// Proxy for retrieving query data with this client context.
|
|
153
157
|
getQueryData: queryClient.getQueryData.bind(queryClient),
|
|
154
158
|
// Proxy for invalidating queries with this client context.
|