@ic-reactor/react 3.13.0 → 4.0.0-beta.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 +237 -787
- package/dist/index.d.ts +260 -16
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +471 -23
- package/dist/index.js.map +1 -1
- package/llms.txt +82 -278
- package/package.json +11 -39
- package/src/index.tsx +612 -0
- package/dist/auth/auth-client-compat.d.ts +0 -122
- package/dist/auth/auth-client-compat.d.ts.map +0 -1
- package/dist/auth/auth-client-compat.js +0 -162
- package/dist/auth/auth-client-compat.js.map +0 -1
- package/dist/auth/authentication-manager.d.ts +0 -405
- package/dist/auth/authentication-manager.d.ts.map +0 -1
- package/dist/auth/authentication-manager.js +0 -1537
- package/dist/auth/authentication-manager.js.map +0 -1
- package/dist/auth/constants.d.ts +0 -24
- package/dist/auth/constants.d.ts.map +0 -1
- package/dist/auth/constants.js +0 -24
- package/dist/auth/constants.js.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.d.ts +0 -14
- package/dist/auth/createIdentityAttributeHooks.d.ts.map +0 -1
- package/dist/auth/createIdentityAttributeHooks.js +0 -122
- package/dist/auth/createIdentityAttributeHooks.js.map +0 -1
- package/dist/auth/identity-attributes-manager.d.ts +0 -27
- package/dist/auth/identity-attributes-manager.d.ts.map +0 -1
- package/dist/auth/identity-attributes-manager.js +0 -191
- package/dist/auth/identity-attributes-manager.js.map +0 -1
- package/dist/auth/identity-attributes.d.ts +0 -19
- package/dist/auth/identity-attributes.d.ts.map +0 -1
- package/dist/auth/identity-attributes.js +0 -227
- package/dist/auth/identity-attributes.js.map +0 -1
- package/dist/auth/index.d.ts +0 -8
- package/dist/auth/index.d.ts.map +0 -1
- package/dist/auth/index.js +0 -8
- package/dist/auth/index.js.map +0 -1
- package/dist/auth/local-ii-probe.d.ts +0 -57
- package/dist/auth/local-ii-probe.d.ts.map +0 -1
- package/dist/auth/local-ii-probe.js +0 -121
- package/dist/auth/local-ii-probe.js.map +0 -1
- package/dist/auth/types.d.ts +0 -222
- package/dist/auth/types.d.ts.map +0 -1
- package/dist/auth/types.js +0 -2
- package/dist/auth/types.js.map +0 -1
- package/dist/createActorHooks.d.ts +0 -41
- package/dist/createActorHooks.d.ts.map +0 -1
- package/dist/createActorHooks.js +0 -17
- package/dist/createActorHooks.js.map +0 -1
- package/dist/createInfiniteQuery.d.ts +0 -185
- package/dist/createInfiniteQuery.d.ts.map +0 -1
- package/dist/createInfiniteQuery.js +0 -198
- package/dist/createInfiniteQuery.js.map +0 -1
- package/dist/createMutation.d.ts +0 -33
- package/dist/createMutation.d.ts.map +0 -1
- package/dist/createMutation.js +0 -199
- package/dist/createMutation.js.map +0 -1
- package/dist/createQuery.d.ts +0 -63
- package/dist/createQuery.d.ts.map +0 -1
- package/dist/createQuery.js +0 -204
- package/dist/createQuery.js.map +0 -1
- package/dist/createReactorProvider.d.ts +0 -158
- package/dist/createReactorProvider.d.ts.map +0 -1
- package/dist/createReactorProvider.js +0 -256
- package/dist/createReactorProvider.js.map +0 -1
- package/dist/createSuspenseInfiniteQuery.d.ts +0 -154
- package/dist/createSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/createSuspenseInfiniteQuery.js +0 -209
- package/dist/createSuspenseInfiniteQuery.js.map +0 -1
- package/dist/createSuspenseQuery.d.ts +0 -46
- package/dist/createSuspenseQuery.d.ts.map +0 -1
- package/dist/createSuspenseQuery.js +0 -158
- package/dist/createSuspenseQuery.js.map +0 -1
- package/dist/defineDisplayReactor.d.ts +0 -43
- package/dist/defineDisplayReactor.d.ts.map +0 -1
- package/dist/defineDisplayReactor.js +0 -42
- package/dist/defineDisplayReactor.js.map +0 -1
- package/dist/defineReactor.d.ts +0 -99
- package/dist/defineReactor.d.ts.map +0 -1
- package/dist/defineReactor.js +0 -15
- package/dist/defineReactor.js.map +0 -1
- package/dist/defineReactorShared.d.ts +0 -84
- package/dist/defineReactorShared.d.ts.map +0 -1
- package/dist/defineReactorShared.js +0 -139
- package/dist/defineReactorShared.js.map +0 -1
- package/dist/hooks/createAuthHooks.d.ts +0 -50
- package/dist/hooks/createAuthHooks.d.ts.map +0 -1
- package/dist/hooks/createAuthHooks.js +0 -291
- package/dist/hooks/createAuthHooks.js.map +0 -1
- package/dist/hooks/index.d.ts +0 -21
- package/dist/hooks/index.d.ts.map +0 -1
- package/dist/hooks/index.js +0 -24
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.d.ts +0 -67
- package/dist/hooks/useActorInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorInfiniteQuery.js +0 -89
- package/dist/hooks/useActorInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorMethod.d.ts +0 -148
- package/dist/hooks/useActorMethod.d.ts.map +0 -1
- package/dist/hooks/useActorMethod.js +0 -394
- package/dist/hooks/useActorMethod.js.map +0 -1
- package/dist/hooks/useActorMutation.d.ts +0 -51
- package/dist/hooks/useActorMutation.d.ts.map +0 -1
- package/dist/hooks/useActorMutation.js +0 -70
- package/dist/hooks/useActorMutation.js.map +0 -1
- package/dist/hooks/useActorQuery.d.ts +0 -45
- package/dist/hooks/useActorQuery.d.ts.map +0 -1
- package/dist/hooks/useActorQuery.js +0 -67
- package/dist/hooks/useActorQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts +0 -51
- package/dist/hooks/useActorSuspenseInfiniteQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseInfiniteQuery.js +0 -76
- package/dist/hooks/useActorSuspenseInfiniteQuery.js.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.d.ts +0 -32
- package/dist/hooks/useActorSuspenseQuery.d.ts.map +0 -1
- package/dist/hooks/useActorSuspenseQuery.js +0 -58
- package/dist/hooks/useActorSuspenseQuery.js.map +0 -1
- package/dist/ownedAuthentication.d.ts +0 -52
- package/dist/ownedAuthentication.d.ts.map +0 -1
- package/dist/ownedAuthentication.js +0 -49
- package/dist/ownedAuthentication.js.map +0 -1
- package/dist/server.d.ts +0 -21
- package/dist/server.d.ts.map +0 -1
- package/dist/server.js +0 -23
- package/dist/server.js.map +0 -1
- package/dist/testing.d.ts +0 -19
- package/dist/testing.d.ts.map +0 -1
- package/dist/testing.js +0 -19
- package/dist/testing.js.map +0 -1
- package/dist/types.d.ts +0 -671
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/dist/utils.d.ts +0 -207
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -405
- package/dist/utils.js.map +0 -1
- package/dist/validation.d.ts +0 -136
- package/dist/validation.d.ts.map +0 -1
- package/dist/validation.js +0 -144
- package/dist/validation.js.map +0 -1
- package/src/auth/auth-client-compat.ts +0 -273
- package/src/auth/authentication-manager.ts +0 -1682
- package/src/auth/constants.ts +0 -32
- package/src/auth/createIdentityAttributeHooks.ts +0 -169
- package/src/auth/identity-attributes-manager.ts +0 -226
- package/src/auth/identity-attributes.ts +0 -345
- package/src/auth/index.ts +0 -7
- package/src/auth/local-ii-probe.ts +0 -173
- package/src/auth/types.ts +0 -243
- package/src/createActorHooks.ts +0 -208
- package/src/createInfiniteQuery.ts +0 -670
- package/src/createMutation.ts +0 -324
- package/src/createQuery.ts +0 -369
- package/src/createReactorProvider.ts +0 -365
- package/src/createSuspenseInfiniteQuery.ts +0 -651
- package/src/createSuspenseQuery.ts +0 -304
- package/src/defineDisplayReactor.ts +0 -62
- package/src/defineReactor.ts +0 -142
- package/src/defineReactorShared.ts +0 -268
- package/src/hooks/createAuthHooks.ts +0 -371
- package/src/hooks/index.ts +0 -103
- package/src/hooks/useActorInfiniteQuery.ts +0 -278
- package/src/hooks/useActorMethod.ts +0 -710
- package/src/hooks/useActorMutation.ts +0 -205
- package/src/hooks/useActorQuery.ts +0 -157
- package/src/hooks/useActorSuspenseInfiniteQuery.ts +0 -248
- package/src/hooks/useActorSuspenseQuery.ts +0 -147
- package/src/index.ts +0 -31
- package/src/ownedAuthentication.ts +0 -81
- package/src/server.ts +0 -23
- package/src/testing.ts +0 -18
- package/src/types.ts +0 -948
- package/src/utils.ts +0 -505
- package/src/validation.ts +0 -226
package/src/hooks/index.ts
DELETED
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
// ============================================================================
|
|
2
|
-
// Hooks
|
|
3
|
-
//
|
|
4
|
-
// These are the RAW hooks: they take the reactor as a property. They are
|
|
5
|
-
// therefore exported as `useReactor*` only — the `useActor*` names belong to
|
|
6
|
-
// the bound hooks `createActorHooks` returns, which take no reactor. Aliasing
|
|
7
|
-
// the raw implementations under the bound names would hand a caller following
|
|
8
|
-
// the documented `useActorQuery({ functionName })` shape an undefined reactor.
|
|
9
|
-
// ============================================================================
|
|
10
|
-
|
|
11
|
-
// useActorQuery / useReactorQuery
|
|
12
|
-
export { useActorQuery as useReactorQuery } from "./useActorQuery.js"
|
|
13
|
-
|
|
14
|
-
// useActorMutation / useReactorMutation
|
|
15
|
-
export { useActorMutation as useReactorMutation } from "./useActorMutation.js"
|
|
16
|
-
|
|
17
|
-
// useActorSuspenseQuery / useReactorSuspenseQuery
|
|
18
|
-
export { useActorSuspenseQuery as useReactorSuspenseQuery } from "./useActorSuspenseQuery.js"
|
|
19
|
-
|
|
20
|
-
// useActorInfiniteQuery / useReactorInfiniteQuery
|
|
21
|
-
export { useActorInfiniteQuery as useReactorInfiniteQuery } from "./useActorInfiniteQuery.js"
|
|
22
|
-
|
|
23
|
-
// useActorSuspenseInfiniteQuery / useReactorSuspenseInfiniteQuery
|
|
24
|
-
export { useActorSuspenseInfiniteQuery as useReactorSuspenseInfiniteQuery } from "./useActorSuspenseInfiniteQuery.js"
|
|
25
|
-
|
|
26
|
-
// useActorMethod / useReactorMethod
|
|
27
|
-
export {
|
|
28
|
-
useActorMethod,
|
|
29
|
-
useActorMethod as useReactorMethod,
|
|
30
|
-
createActorMethodHooks,
|
|
31
|
-
} from "./useActorMethod.js"
|
|
32
|
-
|
|
33
|
-
// createAuthHooks
|
|
34
|
-
export { createAuthHooks } from "./createAuthHooks.js"
|
|
35
|
-
export type { CreateAuthHooksReturn, UseAuthReturn } from "./createAuthHooks.js"
|
|
36
|
-
|
|
37
|
-
// ============================================================================
|
|
38
|
-
// Types - UseReactor* (with reactor parameter)
|
|
39
|
-
// ============================================================================
|
|
40
|
-
|
|
41
|
-
export type {
|
|
42
|
-
UseActorQueryParameters as UseReactorQueryParameters,
|
|
43
|
-
UseActorQueryResult as UseReactorQueryResult,
|
|
44
|
-
} from "./useActorQuery.js"
|
|
45
|
-
|
|
46
|
-
export type {
|
|
47
|
-
UseActorMutationParameters as UseReactorMutationParameters,
|
|
48
|
-
UseActorMutationResult as UseReactorMutationResult,
|
|
49
|
-
} from "./useActorMutation.js"
|
|
50
|
-
|
|
51
|
-
export type {
|
|
52
|
-
UseActorSuspenseQueryParameters as UseReactorSuspenseQueryParameters,
|
|
53
|
-
UseActorSuspenseQueryResult as UseReactorSuspenseQueryResult,
|
|
54
|
-
} from "./useActorSuspenseQuery.js"
|
|
55
|
-
|
|
56
|
-
export type {
|
|
57
|
-
UseActorInfiniteQueryParameters as UseReactorInfiniteQueryParameters,
|
|
58
|
-
UseActorInfiniteQueryResult as UseReactorInfiniteQueryResult,
|
|
59
|
-
} from "./useActorInfiniteQuery.js"
|
|
60
|
-
|
|
61
|
-
export type {
|
|
62
|
-
UseActorSuspenseInfiniteQueryParameters as UseReactorSuspenseInfiniteQueryParameters,
|
|
63
|
-
UseActorSuspenseInfiniteQueryResult as UseReactorSuspenseInfiniteQueryResult,
|
|
64
|
-
} from "./useActorSuspenseInfiniteQuery.js"
|
|
65
|
-
|
|
66
|
-
export type {
|
|
67
|
-
UseActorMethodParameters as UseReactorMethodParameters,
|
|
68
|
-
UseActorMethodResult as UseReactorMethodResult,
|
|
69
|
-
} from "./useActorMethod.js"
|
|
70
|
-
|
|
71
|
-
// ============================================================================
|
|
72
|
-
// Types - UseActor* (without reactor parameter, for use with createActorHooks)
|
|
73
|
-
// ============================================================================
|
|
74
|
-
|
|
75
|
-
export type {
|
|
76
|
-
UseActorQueryConfig as UseActorQueryParameters,
|
|
77
|
-
UseActorQueryResult,
|
|
78
|
-
} from "./useActorQuery.js"
|
|
79
|
-
|
|
80
|
-
export type {
|
|
81
|
-
UseActorMutationConfig as UseActorMutationParameters,
|
|
82
|
-
UseActorMutationResult,
|
|
83
|
-
} from "./useActorMutation.js"
|
|
84
|
-
|
|
85
|
-
export type {
|
|
86
|
-
UseActorSuspenseQueryConfig as UseActorSuspenseQueryParameters,
|
|
87
|
-
UseActorSuspenseQueryResult,
|
|
88
|
-
} from "./useActorSuspenseQuery.js"
|
|
89
|
-
|
|
90
|
-
export type {
|
|
91
|
-
UseActorInfiniteQueryConfig as UseActorInfiniteQueryParameters,
|
|
92
|
-
UseActorInfiniteQueryResult,
|
|
93
|
-
} from "./useActorInfiniteQuery.js"
|
|
94
|
-
|
|
95
|
-
export type {
|
|
96
|
-
UseActorSuspenseInfiniteQueryConfig as UseActorSuspenseInfiniteQueryParameters,
|
|
97
|
-
UseActorSuspenseInfiniteQueryResult,
|
|
98
|
-
} from "./useActorSuspenseInfiniteQuery.js"
|
|
99
|
-
|
|
100
|
-
export type {
|
|
101
|
-
UseActorMethodConfig as UseActorMethodParameters,
|
|
102
|
-
UseActorMethodResult,
|
|
103
|
-
} from "./useActorMethod.js"
|
|
@@ -1,278 +0,0 @@
|
|
|
1
|
-
import { useMemo } from "react"
|
|
2
|
-
import {
|
|
3
|
-
QueryKey,
|
|
4
|
-
useInfiniteQuery,
|
|
5
|
-
skipToken,
|
|
6
|
-
UseInfiniteQueryResult,
|
|
7
|
-
UseInfiniteQueryOptions,
|
|
8
|
-
InfiniteData,
|
|
9
|
-
type SkipToken,
|
|
10
|
-
} from "@tanstack/react-query"
|
|
11
|
-
import {
|
|
12
|
-
FunctionName,
|
|
13
|
-
Reactor,
|
|
14
|
-
TransformKey,
|
|
15
|
-
ReactorArgs,
|
|
16
|
-
ReactorReturnOk,
|
|
17
|
-
ReactorQueryData,
|
|
18
|
-
ReactorReturnErr,
|
|
19
|
-
} from "@ic-reactor/core"
|
|
20
|
-
import { CallConfig } from "@icp-sdk/core/agent"
|
|
21
|
-
import {
|
|
22
|
-
callConfigForKey,
|
|
23
|
-
mergeFactoryQueryKey,
|
|
24
|
-
normalizeQueryData,
|
|
25
|
-
retryOption,
|
|
26
|
-
skippedQueryKey,
|
|
27
|
-
useMountQueryClient,
|
|
28
|
-
} from "../utils.js"
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Parameters for useActorInfiniteQuery hook.
|
|
32
|
-
* Extends react-query's UseInfiniteQueryOptions with custom reactor params.
|
|
33
|
-
*/
|
|
34
|
-
export interface UseActorInfiniteQueryParameters<
|
|
35
|
-
Service,
|
|
36
|
-
Method extends FunctionName<Service>,
|
|
37
|
-
Transform extends TransformKey = "candid",
|
|
38
|
-
TPageParam = unknown,
|
|
39
|
-
Selected = InfiniteData<
|
|
40
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
41
|
-
TPageParam
|
|
42
|
-
>,
|
|
43
|
-
> extends Omit<
|
|
44
|
-
UseInfiniteQueryOptions<
|
|
45
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
46
|
-
ReactorReturnErr<Service, Method, Transform>,
|
|
47
|
-
Selected,
|
|
48
|
-
QueryKey,
|
|
49
|
-
TPageParam
|
|
50
|
-
>,
|
|
51
|
-
"queryKey" | "queryFn" | "getNextPageParam" | "initialPageParam"
|
|
52
|
-
> {
|
|
53
|
-
/** The reactor instance to use for method calls */
|
|
54
|
-
reactor: Reactor<Service, Transform>
|
|
55
|
-
/** The method name to call on the canister */
|
|
56
|
-
functionName: Method
|
|
57
|
-
/**
|
|
58
|
-
* Function to get args from page parameter, or TanStack Query's `skipToken`
|
|
59
|
-
* while the args are not known: the query then waits without fetching, in
|
|
60
|
-
* an entry of its own under its method and `queryKey`, which no call's key
|
|
61
|
-
* shares, so it shows no data until the args arrive.
|
|
62
|
-
*/
|
|
63
|
-
getArgs:
|
|
64
|
-
| ((pageParam: TPageParam) => ReactorArgs<Service, Method, Transform>)
|
|
65
|
-
| SkipToken
|
|
66
|
-
/**
|
|
67
|
-
* Narrows what the cache key derives from the call arguments.
|
|
68
|
-
*
|
|
69
|
-
* By default the key is scoped by `getArgs(initialPageParam)`, so two
|
|
70
|
-
* infinite queries on the same method with different arguments stay in
|
|
71
|
-
* separate cache entries. Supply this when those args embed the cursor and
|
|
72
|
-
* only part of them identifies the query — return the stable, serializable
|
|
73
|
-
* portion (typically everything except the pagination field). It is required
|
|
74
|
-
* when `initialPageParam` changes between renders, as `Date.now()` does:
|
|
75
|
-
* without it every render keys a new query.
|
|
76
|
-
*/
|
|
77
|
-
getKeyArgs?: (args: ReactorArgs<Service, Method, Transform>) => unknown
|
|
78
|
-
/** Agent call configuration (effectiveCanisterId, etc.) */
|
|
79
|
-
callConfig?: CallConfig
|
|
80
|
-
/** Custom query key (auto-generated if not provided) */
|
|
81
|
-
queryKey?: QueryKey
|
|
82
|
-
/** Initial page parameter */
|
|
83
|
-
initialPageParam: TPageParam
|
|
84
|
-
/** Function to determine next page parameter */
|
|
85
|
-
getNextPageParam: (
|
|
86
|
-
lastPage: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
87
|
-
allPages: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>[],
|
|
88
|
-
lastPageParam: TPageParam,
|
|
89
|
-
allPageParams: TPageParam[]
|
|
90
|
-
) => TPageParam | undefined | null
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export type UseActorInfiniteQueryConfig<
|
|
94
|
-
Service,
|
|
95
|
-
Method extends FunctionName<Service>,
|
|
96
|
-
Transform extends TransformKey = "candid",
|
|
97
|
-
TPageParam = unknown,
|
|
98
|
-
Selected = InfiniteData<
|
|
99
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
100
|
-
TPageParam
|
|
101
|
-
>,
|
|
102
|
-
> = Omit<
|
|
103
|
-
UseActorInfiniteQueryParameters<
|
|
104
|
-
Service,
|
|
105
|
-
Method,
|
|
106
|
-
Transform,
|
|
107
|
-
TPageParam,
|
|
108
|
-
Selected
|
|
109
|
-
>,
|
|
110
|
-
"reactor"
|
|
111
|
-
>
|
|
112
|
-
|
|
113
|
-
export type UseActorInfiniteQueryResult<
|
|
114
|
-
Service,
|
|
115
|
-
Method extends FunctionName<Service>,
|
|
116
|
-
Transform extends TransformKey = "candid",
|
|
117
|
-
TPageParam = unknown,
|
|
118
|
-
Selected = InfiniteData<
|
|
119
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
120
|
-
TPageParam
|
|
121
|
-
>,
|
|
122
|
-
> = UseInfiniteQueryResult<
|
|
123
|
-
Selected,
|
|
124
|
-
ReactorReturnErr<Service, Method, Transform>
|
|
125
|
-
>
|
|
126
|
-
|
|
127
|
-
/**
|
|
128
|
-
* Hook for executing infinite/paginated query calls on a canister.
|
|
129
|
-
*
|
|
130
|
-
* @example
|
|
131
|
-
* const { data, fetchNextPage, hasNextPage } = useReactorInfiniteQuery({
|
|
132
|
-
* reactor,
|
|
133
|
-
* functionName: "getItems",
|
|
134
|
-
* getArgs: (pageParam) => [{ offset: pageParam, limit: 10 }] as const,
|
|
135
|
-
* initialPageParam: 0,
|
|
136
|
-
* getNextPageParam: (lastPage) => lastPage.nextOffset,
|
|
137
|
-
* })
|
|
138
|
-
*
|
|
139
|
-
* // Wait for the args: no fetch until userId is known
|
|
140
|
-
* const { data } = useReactorInfiniteQuery({
|
|
141
|
-
* reactor,
|
|
142
|
-
* functionName: "getUserItems",
|
|
143
|
-
* getArgs: userId
|
|
144
|
-
* ? (pageParam) => [{ userId, offset: pageParam, limit: 10 }] as const
|
|
145
|
-
* : skipToken,
|
|
146
|
-
* initialPageParam: 0,
|
|
147
|
-
* getNextPageParam: (lastPage) => lastPage.nextOffset,
|
|
148
|
-
* })
|
|
149
|
-
*/
|
|
150
|
-
export const useActorInfiniteQuery = <
|
|
151
|
-
Service,
|
|
152
|
-
Method extends FunctionName<Service>,
|
|
153
|
-
Transform extends TransformKey = "candid",
|
|
154
|
-
TPageParam = unknown,
|
|
155
|
-
Selected = InfiniteData<
|
|
156
|
-
ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>,
|
|
157
|
-
TPageParam
|
|
158
|
-
>,
|
|
159
|
-
>({
|
|
160
|
-
reactor,
|
|
161
|
-
functionName,
|
|
162
|
-
getArgs,
|
|
163
|
-
getKeyArgs,
|
|
164
|
-
callConfig,
|
|
165
|
-
queryKey,
|
|
166
|
-
...options
|
|
167
|
-
}: UseActorInfiniteQueryParameters<
|
|
168
|
-
Service,
|
|
169
|
-
Method,
|
|
170
|
-
Transform,
|
|
171
|
-
TPageParam,
|
|
172
|
-
Selected
|
|
173
|
-
>): UseActorInfiniteQueryResult<
|
|
174
|
-
Service,
|
|
175
|
-
Method,
|
|
176
|
-
Transform,
|
|
177
|
-
TPageParam,
|
|
178
|
-
Selected
|
|
179
|
-
> => {
|
|
180
|
-
useMountQueryClient(reactor.queryClient)
|
|
181
|
-
|
|
182
|
-
// Always pass queryKey through generateQueryKey so it is merged with the
|
|
183
|
-
// reactor/function identity. Using the custom key verbatim would cause cache
|
|
184
|
-
// collisions if two different actors or methods share the same key string.
|
|
185
|
-
const baseQueryKey = useMemo(() => {
|
|
186
|
-
// Waiting for its args: an entry of its own under the method and the
|
|
187
|
-
// custom key, which every key the args will give extends; see
|
|
188
|
-
// skippedQueryKey.
|
|
189
|
-
if (getArgs === skipToken) {
|
|
190
|
-
return skippedQueryKey(
|
|
191
|
-
reactor.generateQueryKey(
|
|
192
|
-
{ functionName, queryKey: mergeFactoryQueryKey(queryKey) },
|
|
193
|
-
callConfig
|
|
194
|
-
),
|
|
195
|
-
"infinite"
|
|
196
|
-
)
|
|
197
|
-
}
|
|
198
|
-
// Fold the call arguments into the key. They live in the `getArgs`
|
|
199
|
-
// closure rather than in the config, so without this two hooks on the
|
|
200
|
-
// same method with different arguments share one cache entry and serve
|
|
201
|
-
// each other's pages. `getKeyArgs` narrows them exactly as it does for the
|
|
202
|
-
// factories, which the bound hook's config type always accepted: it used
|
|
203
|
-
// to be ignored here, so the cursor stayed in the key, and an
|
|
204
|
-
// `initialPageParam` that changes every render (`Date.now()`) keyed a new
|
|
205
|
-
// query on every render — an endless loop of first-page fetches.
|
|
206
|
-
const initialArgs = getArgs(options.initialPageParam)
|
|
207
|
-
const keyArgs = getKeyArgs?.(initialArgs) ?? initialArgs
|
|
208
|
-
|
|
209
|
-
return reactor.generateQueryKey(
|
|
210
|
-
{
|
|
211
|
-
functionName,
|
|
212
|
-
queryKey: mergeFactoryQueryKey(queryKey, undefined, keyArgs),
|
|
213
|
-
},
|
|
214
|
-
callConfig
|
|
215
|
-
)
|
|
216
|
-
}, [
|
|
217
|
-
queryKey,
|
|
218
|
-
reactor,
|
|
219
|
-
// `canisterId` is mutable reactor state that `setCanisterId` can change,
|
|
220
|
-
// while `reactor` itself stays the same object — so it has to be a
|
|
221
|
-
// dependency in its own right or the key stays pinned to the old canister
|
|
222
|
-
// while the queryFn already calls the new one.
|
|
223
|
-
reactor.canisterId?.toString(),
|
|
224
|
-
functionName,
|
|
225
|
-
callConfig,
|
|
226
|
-
getArgs,
|
|
227
|
-
getKeyArgs,
|
|
228
|
-
options.initialPageParam,
|
|
229
|
-
])
|
|
230
|
-
|
|
231
|
-
// Memoize queryFn to prevent recreation on every render
|
|
232
|
-
const queryFn = useMemo(
|
|
233
|
-
() =>
|
|
234
|
-
getArgs === skipToken
|
|
235
|
-
? skipToken
|
|
236
|
-
: async ({
|
|
237
|
-
pageParam,
|
|
238
|
-
queryKey: fetchedKey,
|
|
239
|
-
}: {
|
|
240
|
-
pageParam: TPageParam
|
|
241
|
-
queryKey: QueryKey
|
|
242
|
-
}) => {
|
|
243
|
-
const args = getArgs(pageParam)
|
|
244
|
-
const result = await reactor.callMethod({
|
|
245
|
-
functionName,
|
|
246
|
-
args,
|
|
247
|
-
callConfig: callConfigForKey(fetchedKey, callConfig),
|
|
248
|
-
})
|
|
249
|
-
return normalizeQueryData<
|
|
250
|
-
ReactorReturnOk<Service, Method, Transform>
|
|
251
|
-
>(result as ReactorReturnOk<Service, Method, Transform>)
|
|
252
|
-
},
|
|
253
|
-
[reactor, functionName, getArgs, callConfig]
|
|
254
|
-
)
|
|
255
|
-
|
|
256
|
-
// The method's default `retry`: for an update method, only failures that
|
|
257
|
-
// prove the canister never ran the call; see `Reactor.getQueryRetry`.
|
|
258
|
-
const defaultRetry = useMemo(
|
|
259
|
-
() => reactor.getQueryRetry(functionName, baseQueryKey),
|
|
260
|
-
[reactor, functionName, baseQueryKey]
|
|
261
|
-
)
|
|
262
|
-
|
|
263
|
-
return useInfiniteQuery(
|
|
264
|
-
{
|
|
265
|
-
queryKey: baseQueryKey,
|
|
266
|
-
queryFn,
|
|
267
|
-
...options,
|
|
268
|
-
...retryOption(options.retry, defaultRetry),
|
|
269
|
-
} as any,
|
|
270
|
-
reactor.queryClient
|
|
271
|
-
) as UseActorInfiniteQueryResult<
|
|
272
|
-
Service,
|
|
273
|
-
Method,
|
|
274
|
-
Transform,
|
|
275
|
-
TPageParam,
|
|
276
|
-
Selected
|
|
277
|
-
>
|
|
278
|
-
}
|