@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
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
import { type UseQueryResult, type UseMutationResult, type QueryKey, type QueryObserverOptions } from "@tanstack/react-query";
|
|
2
|
-
import { Reactor, BaseActor, FunctionName, TransformKey, ReactorArgs, ReactorReturnOk, ReactorQueryData, ReactorReturnErr, FunctionType } from "@ic-reactor/core";
|
|
3
|
-
import { CallConfig } from "@icp-sdk/core/agent";
|
|
4
|
-
import type { InvalidationTarget } from "../types.js";
|
|
5
|
-
/**
|
|
6
|
-
* Configuration for useActorMethod hook.
|
|
7
|
-
* Extends react-query's QueryObserverOptions with custom reactor params.
|
|
8
|
-
*
|
|
9
|
-
* This is a unified hook that handles both query and mutation methods.
|
|
10
|
-
* Query-specific options (like refetchInterval) only apply to query methods.
|
|
11
|
-
* Mutation-specific options (like invalidateQueries) only apply to mutation methods.
|
|
12
|
-
*
|
|
13
|
-
* `retry`, `retryDelay`, `networkMode` and `meta` decide how a call runs, so
|
|
14
|
-
* they apply to both. An update method's call is a mutation: without a `retry`
|
|
15
|
-
* here it follows the QueryClient's mutation defaults, which retry nothing
|
|
16
|
-
* unless the app set `mutations.retry`, because each attempt runs the update
|
|
17
|
-
* on the canister again. Its query defaults, such as `reactorRetry`, do not
|
|
18
|
-
* apply to it.
|
|
19
|
-
*/
|
|
20
|
-
export interface UseActorMethodParameters<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> extends Omit<QueryObserverOptions<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorReturnErr<Service, Method, Transform>, ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, QueryKey>, "queryKey" | "queryFn"> {
|
|
21
|
-
/** The reactor instance to use for method calls */
|
|
22
|
-
reactor: Reactor<Service, Transform>;
|
|
23
|
-
/** The method name to call on the canister */
|
|
24
|
-
functionName: Method;
|
|
25
|
-
/** Arguments to pass to the method (optional for parameterless methods) */
|
|
26
|
-
args?: ReactorArgs<Service, Method, Transform>;
|
|
27
|
-
/** Agent call configuration (effectiveCanisterId, etc.) */
|
|
28
|
-
callConfig?: CallConfig;
|
|
29
|
-
/** Custom query key (auto-generated if not provided) */
|
|
30
|
-
queryKey?: QueryKey;
|
|
31
|
-
/**
|
|
32
|
-
* Callback when the method call succeeds.
|
|
33
|
-
* Works for both query and mutation methods.
|
|
34
|
-
*
|
|
35
|
-
* A method's `undefined` result arrives as `null`, as in `useActorQuery`,
|
|
36
|
-
* for query and update methods alike.
|
|
37
|
-
*/
|
|
38
|
-
onSuccess?: (data: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>) => void;
|
|
39
|
-
/**
|
|
40
|
-
* Callback when the method call fails.
|
|
41
|
-
* Works for both query and mutation methods.
|
|
42
|
-
*/
|
|
43
|
-
onError?: (error: ReactorReturnErr<Service, Method, Transform>) => void;
|
|
44
|
-
/**
|
|
45
|
-
* Queries to invalidate after a successful mutation.
|
|
46
|
-
* Only applies to mutation methods (updates).
|
|
47
|
-
*
|
|
48
|
-
* Each entry is a query key, a query object or query factory, or a
|
|
49
|
-
* `{ functionName, args? }` method of `reactor`; see
|
|
50
|
-
* {@link InvalidationTarget}. `undefined` entries are skipped.
|
|
51
|
-
*
|
|
52
|
-
* The invalidation is awaited before `onSuccess` runs, as in
|
|
53
|
-
* `useActorMutation` and `createMutation`, so `onSuccess` sees the
|
|
54
|
-
* refetched data, and `call()` resolves once the invalidated queries in use
|
|
55
|
-
* have refetched.
|
|
56
|
-
*/
|
|
57
|
-
invalidateQueries?: InvalidationTarget<Service, Transform>[];
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Configuration type for bound useActorMethod hook (reactor omitted).
|
|
61
|
-
* For use with createActorHooks.
|
|
62
|
-
*/
|
|
63
|
-
export type UseActorMethodConfig<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> = Omit<UseActorMethodParameters<Service, Method, Transform>, "reactor">;
|
|
64
|
-
/**
|
|
65
|
-
* Result type for useActorMethod hook.
|
|
66
|
-
* Provides a unified interface for both query and mutation methods.
|
|
67
|
-
*/
|
|
68
|
-
export interface UseActorMethodResult<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid"> {
|
|
69
|
-
/**
|
|
70
|
-
* The returned data from the method call. A method's `undefined` result is
|
|
71
|
-
* `null` here, as in `useActorQuery`, so `undefined` means that no call has
|
|
72
|
-
* settled yet, that the last call failed, or that an update call is
|
|
73
|
-
* running. A query keeps its earlier data when a refetch fails.
|
|
74
|
-
*/
|
|
75
|
-
data: ReactorQueryData<ReactorReturnOk<Service, Method, Transform>> | undefined;
|
|
76
|
-
/** Whether the method is currently executing */
|
|
77
|
-
isLoading: boolean;
|
|
78
|
-
/** Alias for isLoading - whether a mutation is pending */
|
|
79
|
-
isPending: boolean;
|
|
80
|
-
/** Whether there was an error */
|
|
81
|
-
isError: boolean;
|
|
82
|
-
/** Whether the method has successfully completed at least once */
|
|
83
|
-
isSuccess: boolean;
|
|
84
|
-
/** The error if one occurred */
|
|
85
|
-
error: ReactorReturnErr<Service, Method, Transform> | null;
|
|
86
|
-
/** Whether this is a query method (true) or mutation method (false) */
|
|
87
|
-
isQuery: boolean;
|
|
88
|
-
/** The function type (query, update, composite_query) */
|
|
89
|
-
functionType: FunctionType;
|
|
90
|
-
/**
|
|
91
|
-
* Call the method with optional arguments.
|
|
92
|
-
* For queries: triggers a refetch
|
|
93
|
-
* For mutations: executes the mutation with the provided args
|
|
94
|
-
*
|
|
95
|
-
* For a query method, `call(args)` fetches those args from the canister
|
|
96
|
-
* even when they are cached, and reports the result to `onSuccess` or
|
|
97
|
-
* `onError` itself. `call()` refetches the hook's own args, as `refetch()`
|
|
98
|
-
* does. Either resolves `undefined` when its fetch fails. A sign-in or
|
|
99
|
-
* sign-out while either is in flight cancels the fetch, which then runs
|
|
100
|
-
* again for the principal signed in, so the call resolves with that
|
|
101
|
-
* principal's answer rather than the previous one's; see
|
|
102
|
-
* `ClientManager.fetchAcrossIdentitySwitch`.
|
|
103
|
-
*/
|
|
104
|
-
call: (args?: ReactorArgs<Service, Method, Transform>) => Promise<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>> | undefined>;
|
|
105
|
-
/**
|
|
106
|
-
* Reset the state (data and error).
|
|
107
|
-
* For queries: resets this hook's own cache entry to its initial state, so
|
|
108
|
-
* `data` goes back to `initialData` when one was given and is cleared
|
|
109
|
-
* otherwise. An enabled hook then refetches. Other args of the same method
|
|
110
|
-
* are left alone.
|
|
111
|
-
* For mutations: resets the mutation state
|
|
112
|
-
*/
|
|
113
|
-
reset: () => void;
|
|
114
|
-
/**
|
|
115
|
-
* For queries only: Refetch the query
|
|
116
|
-
*
|
|
117
|
-
* Resolves with the answer, or `undefined` when the refetch fails, whose
|
|
118
|
-
* error the hook reports to `onError`; `data` keeps the last answer. A
|
|
119
|
-
* sign-in or sign-out while it is in flight makes it refetch for the
|
|
120
|
-
* principal signed in, and it resolves with that principal's answer, as
|
|
121
|
-
* `call()` does.
|
|
122
|
-
*/
|
|
123
|
-
refetch: () => Promise<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>> | undefined>;
|
|
124
|
-
/** The raw query result (only available for query methods) */
|
|
125
|
-
queryResult?: UseQueryResult<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorReturnErr<Service, Method, Transform>>;
|
|
126
|
-
/** The raw mutation result (only available for mutation methods) */
|
|
127
|
-
mutationResult?: UseMutationResult<ReactorQueryData<ReactorReturnOk<Service, Method, Transform>>, ReactorReturnErr<Service, Method, Transform>, ReactorArgs<Service, Method, Transform>>;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* A unified hook for calling canister methods that automatically handles
|
|
131
|
-
* both query and mutation methods based on the Candid interface.
|
|
132
|
-
*/
|
|
133
|
-
export declare function useActorMethod<Service = BaseActor, Method extends FunctionName<Service> = FunctionName<Service>, Transform extends TransformKey = "candid">({ reactor, functionName, args, callConfig, queryKey: customQueryKey, enabled, onSuccess, onError, invalidateQueries, ...queryOptions }: UseActorMethodParameters<Service, Method, Transform>): UseActorMethodResult<Service, Method, Transform>;
|
|
134
|
-
/**
|
|
135
|
-
* Creates a bound useMethod hook for a specific reactor instance.
|
|
136
|
-
*
|
|
137
|
-
* @example
|
|
138
|
-
* ```tsx
|
|
139
|
-
* const { useMethod } = createActorMethodHooks(reactor)
|
|
140
|
-
* ```
|
|
141
|
-
*/
|
|
142
|
-
export declare function createActorMethodHooks<Service = BaseActor, Transform extends TransformKey = "candid">(reactor: Reactor<Service, Transform>): {
|
|
143
|
-
/**
|
|
144
|
-
* Hook for calling methods on the bound reactor.
|
|
145
|
-
*/
|
|
146
|
-
useMethod: <Method extends FunctionName<Service>>(config: Omit<UseActorMethodParameters<Service, Method, Transform>, "reactor">) => UseActorMethodResult<Service, Method, Transform>;
|
|
147
|
-
};
|
|
148
|
-
//# sourceMappingURL=useActorMethod.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActorMethod.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorMethod.ts"],"names":[],"mappings":"AAOA,OAAO,EAIL,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,QAAQ,EACb,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,OAAO,EACP,SAAS,EACT,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,YAAY,EACb,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAOhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD;;;;;;;;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C,UACtC,IAAI,CACV,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EACpD,SAAS,CACV;EAQN"}
|
|
@@ -1,394 +0,0 @@
|
|
|
1
|
-
import { useCallback, useEffect, useInsertionEffect, useMemo, useRef, } from "react";
|
|
2
|
-
import { useQuery, useMutation, hashKey, } from "@tanstack/react-query";
|
|
3
|
-
import { invalidateTargets, normalizeQueryData, pickFetchOptions, useMountQueryClient, } from "../utils.js";
|
|
4
|
-
/**
|
|
5
|
-
* A ref to `value` as of the last committed render, for code that runs outside
|
|
6
|
-
* render: event handlers, timers, effects and TanStack callbacks.
|
|
7
|
-
*
|
|
8
|
-
* Assigning the ref during render would also publish renders that React throws
|
|
9
|
-
* away, such as a transition that suspends or one that a more urgent update
|
|
10
|
-
* interrupts. The tree still on screen would then act on props it never showed,
|
|
11
|
-
* like calling a method it does not render. An insertion effect runs only when
|
|
12
|
-
* its render commits, and before every layout and passive effect of that
|
|
13
|
-
* commit, so no effect anywhere in the tree reads the previous commit's value.
|
|
14
|
-
* React's own `useEffectEvent` also swaps in its new function during the
|
|
15
|
-
* commit, ahead of layout effects. Unlike `useLayoutEffect`, an insertion
|
|
16
|
-
* effect does not warn in a React 18 server render. The initial value serves
|
|
17
|
-
* anything that runs before the first commit.
|
|
18
|
-
*/
|
|
19
|
-
function useCommittedRef(value) {
|
|
20
|
-
const ref = useRef(value);
|
|
21
|
-
useInsertionEffect(() => {
|
|
22
|
-
ref.current = value;
|
|
23
|
-
});
|
|
24
|
-
return ref;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* A unified hook for calling canister methods that automatically handles
|
|
28
|
-
* both query and mutation methods based on the Candid interface.
|
|
29
|
-
*/
|
|
30
|
-
export function useActorMethod({ reactor, functionName, args, callConfig, queryKey: customQueryKey, enabled = true, onSuccess, onError, invalidateQueries, ...queryOptions }) {
|
|
31
|
-
// Determine if this is a query method by checking the IDL
|
|
32
|
-
const isQuery = useMemo(() => {
|
|
33
|
-
if (!reactor)
|
|
34
|
-
throw new Error("Reactor instance is required");
|
|
35
|
-
return reactor.isQueryMethod(functionName);
|
|
36
|
-
}, [reactor, functionName]);
|
|
37
|
-
const functionType = isQuery ? "query" : "update";
|
|
38
|
-
useMountQueryClient(reactor.queryClient);
|
|
39
|
-
// The committed render's callbacks, read at dispatch time: this keeps a
|
|
40
|
-
// rerendered closure from being ignored, and keeps callback identity out of
|
|
41
|
-
// the effect deps.
|
|
42
|
-
const onSuccessRef = useCommittedRef(onSuccess);
|
|
43
|
-
const onErrorRef = useCommittedRef(onError);
|
|
44
|
-
// Build the key for a given set of call arguments.
|
|
45
|
-
//
|
|
46
|
-
// A custom `queryKey` is appended to the canister/function prefix rather than
|
|
47
|
-
// replacing it, matching `useActorQuery`. Used verbatim it would carry no
|
|
48
|
-
// canister id, so the entry would be invisible to the canister-scoped
|
|
49
|
-
// invalidation `ClientManager.updateAgent` runs on identity change and would
|
|
50
|
-
// keep serving the previous principal's data after sign-in or sign-out.
|
|
51
|
-
const buildQueryKey = useCallback((keyArgs) => reactor.generateQueryKey({ functionName, args: keyArgs, queryKey: customQueryKey }, callConfig),
|
|
52
|
-
// `canisterId` is mutable reactor state that `setCanisterId` can change,
|
|
53
|
-
// while `reactor` itself stays the same object — so it has to be a
|
|
54
|
-
// dependency in its own right or the key stays pinned to the old canister.
|
|
55
|
-
[
|
|
56
|
-
reactor,
|
|
57
|
-
reactor.canisterId?.toString(),
|
|
58
|
-
functionName,
|
|
59
|
-
callConfig,
|
|
60
|
-
customQueryKey,
|
|
61
|
-
]);
|
|
62
|
-
const queryKey = useMemo(() => buildQueryKey(args), [buildQueryKey, args]);
|
|
63
|
-
// ============================================================================
|
|
64
|
-
// Query Implementation
|
|
65
|
-
// ============================================================================
|
|
66
|
-
const queryResult = useQuery({
|
|
67
|
-
queryKey,
|
|
68
|
-
// Callbacks deliberately do NOT live here: a queryFn runs once per fetch
|
|
69
|
-
// attempt, so `onError` fired on every retry (four times with the default
|
|
70
|
-
// QueryClient) and `onSuccess` never fired when data came from the cache
|
|
71
|
-
// or a deduped sibling. They are dispatched from the settled observer
|
|
72
|
-
// result below instead.
|
|
73
|
-
//
|
|
74
|
-
// TanStack Query fails a query whose queryFn resolves `undefined`, with
|
|
75
|
-
// "data is undefined", and a successful call can resolve it. A
|
|
76
|
-
// DisplayReactor decodes an `opt` None to `undefined`, and a `()` query
|
|
77
|
-
// returns nothing. Every other query path normalizes the value to `null`.
|
|
78
|
-
queryFn: async () => normalizeQueryData((await reactor.callMethod({
|
|
79
|
-
functionName,
|
|
80
|
-
args,
|
|
81
|
-
callConfig,
|
|
82
|
-
}))),
|
|
83
|
-
enabled: isQuery && enabled,
|
|
84
|
-
...queryOptions,
|
|
85
|
-
}, reactor.queryClient);
|
|
86
|
-
// Dispatch the query callbacks from the settled observer result, once per
|
|
87
|
-
// distinct outcome. TanStack v5 removed `onSuccess`/`onError` from useQuery
|
|
88
|
-
// for exactly this reason, so the settle timestamps are what identify a new
|
|
89
|
-
// result: they also advance for a cache hit on a fresh mount, which is the
|
|
90
|
-
// case that previously never notified at all.
|
|
91
|
-
const notifiedSuccessAt = useRef(undefined);
|
|
92
|
-
const notifiedErrorAt = useRef(undefined);
|
|
93
|
-
const { status, data, error, dataUpdatedAt, errorUpdatedAt, isPlaceholderData, isFetched, } = queryResult;
|
|
94
|
-
useEffect(() => {
|
|
95
|
-
if (!isQuery)
|
|
96
|
-
return;
|
|
97
|
-
// Placeholder data also has `status: "success"`, but no call has returned
|
|
98
|
-
// it: it is the `placeholderData` option, or with `keepPreviousData` the
|
|
99
|
-
// previous args' result standing in while this call is in flight.
|
|
100
|
-
if (isPlaceholderData)
|
|
101
|
-
return;
|
|
102
|
-
// So does `initialData`: an entry starts with it, and `reset()` puts it
|
|
103
|
-
// back, before any fetch of the entry has settled. The first fetch that
|
|
104
|
-
// settles makes the entry fetched, and its result is reported below.
|
|
105
|
-
if (!isFetched)
|
|
106
|
-
return;
|
|
107
|
-
if (status === "success" && dataUpdatedAt !== notifiedSuccessAt.current) {
|
|
108
|
-
notifiedSuccessAt.current = dataUpdatedAt;
|
|
109
|
-
onSuccessRef.current?.(data);
|
|
110
|
-
}
|
|
111
|
-
}, [isQuery, status, data, dataUpdatedAt, isPlaceholderData, isFetched]);
|
|
112
|
-
useEffect(() => {
|
|
113
|
-
if (!isQuery)
|
|
114
|
-
return;
|
|
115
|
-
if (status === "error" && errorUpdatedAt !== notifiedErrorAt.current) {
|
|
116
|
-
notifiedErrorAt.current = errorUpdatedAt;
|
|
117
|
-
onErrorRef.current?.(error);
|
|
118
|
-
}
|
|
119
|
-
}, [isQuery, status, error, errorUpdatedAt]);
|
|
120
|
-
// `call(args)` reports its own outcome, once per call, because the args it
|
|
121
|
-
// fetched usually key an entry this observer does not watch. When they key
|
|
122
|
-
// the entry it does watch, the effects above see the same settle, and each
|
|
123
|
-
// callback used to fire twice for one call. So the settle that ends a call's
|
|
124
|
-
// fetch is marked as notified when it lands in the observed entry, and the
|
|
125
|
-
// effects skip it.
|
|
126
|
-
//
|
|
127
|
-
// A query cache listener sets that mark while TanStack dispatches the
|
|
128
|
-
// settle, before any render can show it. Matching a settle up by its
|
|
129
|
-
// timestamp afterwards could not tell settles apart: two in one millisecond
|
|
130
|
-
// share a timestamp. And a call that an identity switch cancels settles
|
|
131
|
-
// nothing: TanStack reverts the entry to its previous result, timestamp
|
|
132
|
-
// included, so the call's outcome looked reported already, and neither the
|
|
133
|
-
// call nor the effects reported it.
|
|
134
|
-
const observedKeyRef = useCommittedRef(queryKey);
|
|
135
|
-
const markCallSettle = (calledKey) => {
|
|
136
|
-
const { queryClient } = reactor;
|
|
137
|
-
// The hash TanStack files the called entry under, worked out the way
|
|
138
|
-
// `fetchQuery` does. The listener compares it with hashes TanStack has
|
|
139
|
-
// already computed rather than hashing keys itself: the QueryClient may be
|
|
140
|
-
// shared with the app, whose keys a custom `queryKeyHashFn` can let hold
|
|
141
|
-
// values that `hashKey` throws on, inside TanStack's dispatch.
|
|
142
|
-
const calledHash = queryClient.defaultQueryOptions({
|
|
143
|
-
queryKey: calledKey,
|
|
144
|
-
}).queryHash;
|
|
145
|
-
let settled = false;
|
|
146
|
-
return queryClient.getQueryCache().subscribe((event) => {
|
|
147
|
-
if (settled || event.type !== "updated")
|
|
148
|
-
return;
|
|
149
|
-
const { action, query } = event;
|
|
150
|
-
// A fetch settles with one of these. `setQueryData` dispatches a
|
|
151
|
-
// success too, flagged manual, and it does not end this call's fetch.
|
|
152
|
-
const isSettle = action.type === "error" || (action.type === "success" && !action.manual);
|
|
153
|
-
if (!isSettle || query.queryHash !== calledHash)
|
|
154
|
-
return;
|
|
155
|
-
settled = true;
|
|
156
|
-
if (hashKey(calledKey) !== hashKey(observedKeyRef.current))
|
|
157
|
-
return;
|
|
158
|
-
if (action.type === "success") {
|
|
159
|
-
notifiedSuccessAt.current = query.state.dataUpdatedAt;
|
|
160
|
-
}
|
|
161
|
-
else {
|
|
162
|
-
notifiedErrorAt.current = query.state.errorUpdatedAt;
|
|
163
|
-
}
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
// ============================================================================
|
|
167
|
-
// Mutation Implementation
|
|
168
|
-
// ============================================================================
|
|
169
|
-
const mutationResult = useMutation({
|
|
170
|
-
mutationKey: queryKey,
|
|
171
|
-
// The hook's `retry`, `retryDelay`, `networkMode` and `meta`, the options
|
|
172
|
-
// that decide how a call runs, as the query branch's `call()` applies
|
|
173
|
-
// them. They reached only the query branch, so an update's call ignored
|
|
174
|
-
// them: it stayed paused offline under `networkMode: "always"` and
|
|
175
|
-
// reached the MutationCache callbacks without the hook's `meta`. Unset
|
|
176
|
-
// ones are left to the QueryClient's mutation defaults, which retry
|
|
177
|
-
// nothing unless the app set `mutations.retry`: each attempt of an
|
|
178
|
-
// update is a new call the canister runs, so only a `retry` given here
|
|
179
|
-
// or in those defaults sends one again.
|
|
180
|
-
...pickFetchOptions(queryOptions),
|
|
181
|
-
// Normalized like the query branch, so `data`, `call()` and `onSuccess`
|
|
182
|
-
// mean the same thing for both kinds of method. The hook cannot type the
|
|
183
|
-
// two branches apart: a Candid service type does not say which methods
|
|
184
|
-
// are queries.
|
|
185
|
-
mutationFn: async (mutationArgs) => normalizeQueryData((await reactor.callMethod({
|
|
186
|
-
functionName,
|
|
187
|
-
args: mutationArgs ?? args,
|
|
188
|
-
callConfig,
|
|
189
|
-
}))),
|
|
190
|
-
// Invalidation first, then `onSuccess`, as `useActorMutation` and
|
|
191
|
-
// `createMutation` do. TanStack Query waits for the promise returned
|
|
192
|
-
// here before it settles the mutation, so `call()` resolves, and
|
|
193
|
-
// `isPending` turns false, once the invalidated queries that are in use
|
|
194
|
-
// have refetched, and `onSuccess` reads the refetched data. A refetch
|
|
195
|
-
// that fails does not reject `invalidateQueries`, so it cannot turn the
|
|
196
|
-
// update, which has already run on the canister, into a failure.
|
|
197
|
-
onSuccess: async (data) => {
|
|
198
|
-
await invalidateTargets(reactor, invalidateQueries, callConfig);
|
|
199
|
-
onSuccessRef.current?.(data);
|
|
200
|
-
},
|
|
201
|
-
onError: (error) => {
|
|
202
|
-
onErrorRef.current?.(error);
|
|
203
|
-
},
|
|
204
|
-
}, reactor.queryClient);
|
|
205
|
-
// ============================================================================
|
|
206
|
-
// Refetch and Call Functions
|
|
207
|
-
// ============================================================================
|
|
208
|
-
// A query's `call()` and `refetch()` resolve with the answer for the
|
|
209
|
-
// principal signed in when they settle. `ClientManager.updateAgent` cancels
|
|
210
|
-
// a fetch in flight when a sign-in or sign-out switches the principal, so
|
|
211
|
-
// that the previous principal's answer is never cached. TanStack then
|
|
212
|
-
// resolves the fetch with the data it puts the entry back to, which is the
|
|
213
|
-
// previous principal's, or rejects it with a `CancelledError` when the entry
|
|
214
|
-
// had none, and a call used to resolve with, and report, whichever it got.
|
|
215
|
-
// Through `fetchAcrossIdentitySwitch` it runs again for the principal signed
|
|
216
|
-
// in, as `reactor.fetchQuery()` and the factories' `fetch()` do. When the
|
|
217
|
-
// principal switches during that run too, and during each of two more, that
|
|
218
|
-
// rejects with a `CallError`, which is reported to `onError` like any other
|
|
219
|
-
// failure.
|
|
220
|
-
const refetchLatest = async () => {
|
|
221
|
-
if (!isQuery)
|
|
222
|
-
return undefined;
|
|
223
|
-
let runs = 0;
|
|
224
|
-
try {
|
|
225
|
-
const result = await reactor.clientManager.fetchAcrossIdentitySwitch(() =>
|
|
226
|
-
// A run after a switch joins the refetch the switch started for
|
|
227
|
-
// this entry, rather than cancel it and start another.
|
|
228
|
-
queryResult.refetch(runs++ === 0 ? undefined : { cancelRefetch: false }));
|
|
229
|
-
// TanStack's `refetch()` resolves even when the fetch fails, with the
|
|
230
|
-
// entry's last answer still in the result. After a sign-in or sign-out
|
|
231
|
-
// that is the previous principal's: the entry is put back to it when
|
|
232
|
-
// the switch cancels a fetch, and keeps it when the new principal's
|
|
233
|
-
// refetch fails. So a failed refetch resolves `undefined`, as a failed
|
|
234
|
-
// `call(args)` does, and the effects report the failure to `onError`.
|
|
235
|
-
// The hook's `data` keeps the last answer, as TanStack's does.
|
|
236
|
-
return result.isError ? undefined : result.data;
|
|
237
|
-
}
|
|
238
|
-
catch (error) {
|
|
239
|
-
// Only that CallError: `refetch()` itself never rejects. The effects
|
|
240
|
-
// report what the entry settles with, and it settles nothing for this.
|
|
241
|
-
onErrorRef.current?.(error);
|
|
242
|
-
return undefined;
|
|
243
|
-
}
|
|
244
|
-
};
|
|
245
|
-
const callLatest = async (callArgs) => {
|
|
246
|
-
if (isQuery) {
|
|
247
|
-
// For queries, refetch with new args if provided
|
|
248
|
-
if (callArgs !== undefined) {
|
|
249
|
-
// Key on the args actually being called. Reusing the hook's
|
|
250
|
-
// mount-time key would store this result under the previous args'
|
|
251
|
-
// entry — poisoning it for every other reader — and let fetchQuery
|
|
252
|
-
// dedupe onto an in-flight request for the old args, returning that
|
|
253
|
-
// response as though it answered this one.
|
|
254
|
-
const calledKey = buildQueryKey(callArgs);
|
|
255
|
-
// Reported here rather than by the observer effects: this result
|
|
256
|
-
// usually lands under a key the mounted observer (bound to the hook's
|
|
257
|
-
// own args) does not watch. When it is that key, `markCallSettle` has
|
|
258
|
-
// already kept the effects from reporting it as well. Either way the
|
|
259
|
-
// callbacks get what the call settles with.
|
|
260
|
-
try {
|
|
261
|
-
const result = await reactor.clientManager.fetchAcrossIdentitySwitch(async () => {
|
|
262
|
-
// Each run marks the settle of its own fetch. A run a switch
|
|
263
|
-
// overtook may have settled with the previous principal's answer,
|
|
264
|
-
// which the effects must not report either.
|
|
265
|
-
const stopMarking = markCallSettle(calledKey);
|
|
266
|
-
try {
|
|
267
|
-
return await reactor.queryClient.fetchQuery({
|
|
268
|
-
// The options the hook's own fetches run with: `retry`,
|
|
269
|
-
// `retryDelay`, `networkMode` and `meta`. With only a key and
|
|
270
|
-
// a function, a call ran on the QueryClient's defaults. It
|
|
271
|
-
// failed on the first error the hook retried through, stayed
|
|
272
|
-
// paused offline under `networkMode: "always"`, and reached
|
|
273
|
-
// the QueryCache callbacks without the hook's `meta`.
|
|
274
|
-
...pickFetchOptions(queryOptions),
|
|
275
|
-
queryKey: calledKey,
|
|
276
|
-
// Normalize for the same reason as the observer's queryFn.
|
|
277
|
-
queryFn: async () => normalizeQueryData((await reactor.callMethod({
|
|
278
|
-
functionName,
|
|
279
|
-
args: callArgs,
|
|
280
|
-
callConfig,
|
|
281
|
-
}))),
|
|
282
|
-
staleTime: 0,
|
|
283
|
-
});
|
|
284
|
-
}
|
|
285
|
-
finally {
|
|
286
|
-
stopMarking();
|
|
287
|
-
}
|
|
288
|
-
});
|
|
289
|
-
onSuccessRef.current?.(result);
|
|
290
|
-
return result;
|
|
291
|
-
}
|
|
292
|
-
catch (error) {
|
|
293
|
-
onErrorRef.current?.(error);
|
|
294
|
-
return undefined;
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
// Otherwise just refetch
|
|
298
|
-
return refetchLatest();
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
// For mutations, execute with provided args
|
|
302
|
-
return mutationResult
|
|
303
|
-
.mutateAsync(callArgs)
|
|
304
|
-
.catch(() => undefined);
|
|
305
|
-
}
|
|
306
|
-
};
|
|
307
|
-
// ============================================================================
|
|
308
|
-
// Reset Function
|
|
309
|
-
// ============================================================================
|
|
310
|
-
const resetLatest = () => {
|
|
311
|
-
if (isQuery) {
|
|
312
|
-
// Reset, not remove. `removeQueries` drops the entry without notifying
|
|
313
|
-
// its observers, so this hook kept rendering the old data while bound to
|
|
314
|
-
// a query that was no longer in the cache. No later invalidation reached
|
|
315
|
-
// it, including the one an identity switch runs. `resetQueries` notifies
|
|
316
|
-
// the observer and refetches the entry when the hook is enabled. It is
|
|
317
|
-
// `exact` because only this hook's entry should reset. A prefix match on
|
|
318
|
-
// a no-args key would also reset every args variant other hooks render.
|
|
319
|
-
void reactor.queryClient.resetQueries({ queryKey, exact: true });
|
|
320
|
-
}
|
|
321
|
-
else {
|
|
322
|
-
mutationResult.reset();
|
|
323
|
-
}
|
|
324
|
-
};
|
|
325
|
-
// `call`, `reset` and `refetch` keep one identity for the life of the
|
|
326
|
-
// component, as TanStack's own `refetch`, `mutate` and `reset` do, and run
|
|
327
|
-
// the latest committed render's implementation above when invoked. They used
|
|
328
|
-
// to be `useCallback`s listing the query and mutation results, which TanStack
|
|
329
|
-
// Query returns fresh every render, so they changed every render too. An
|
|
330
|
-
// effect that lists one — `react-hooks/exhaustive-deps` requires it as soon
|
|
331
|
-
// as the effect calls it — then re-ran after every render its own call
|
|
332
|
-
// caused: an unbounded loop of canister calls, state-changing ones for an
|
|
333
|
-
// update method.
|
|
334
|
-
const latest = useCommittedRef({
|
|
335
|
-
call: callLatest,
|
|
336
|
-
reset: resetLatest,
|
|
337
|
-
refetch: refetchLatest,
|
|
338
|
-
});
|
|
339
|
-
const call = useCallback((callArgs) => latest.current.call(callArgs), []);
|
|
340
|
-
const reset = useCallback(() => latest.current.reset(), []);
|
|
341
|
-
const refetch = useCallback(() => latest.current.refetch(), []);
|
|
342
|
-
// ============================================================================
|
|
343
|
-
// Return Unified Result
|
|
344
|
-
// ============================================================================
|
|
345
|
-
if (isQuery) {
|
|
346
|
-
return {
|
|
347
|
-
data: queryResult.data,
|
|
348
|
-
isLoading: queryResult.isLoading,
|
|
349
|
-
isPending: queryResult.isLoading,
|
|
350
|
-
isError: queryResult.isError,
|
|
351
|
-
isSuccess: queryResult.isSuccess,
|
|
352
|
-
error: queryResult.error,
|
|
353
|
-
isQuery: true,
|
|
354
|
-
functionType,
|
|
355
|
-
call,
|
|
356
|
-
reset,
|
|
357
|
-
refetch,
|
|
358
|
-
queryResult,
|
|
359
|
-
};
|
|
360
|
-
}
|
|
361
|
-
else {
|
|
362
|
-
return {
|
|
363
|
-
data: mutationResult.data,
|
|
364
|
-
isLoading: mutationResult.isPending,
|
|
365
|
-
isPending: mutationResult.isPending,
|
|
366
|
-
isError: mutationResult.isError,
|
|
367
|
-
isSuccess: mutationResult.isSuccess,
|
|
368
|
-
error: mutationResult.error,
|
|
369
|
-
isQuery: false,
|
|
370
|
-
functionType,
|
|
371
|
-
call,
|
|
372
|
-
reset,
|
|
373
|
-
refetch,
|
|
374
|
-
mutationResult,
|
|
375
|
-
};
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
/**
|
|
379
|
-
* Creates a bound useMethod hook for a specific reactor instance.
|
|
380
|
-
*
|
|
381
|
-
* @example
|
|
382
|
-
* ```tsx
|
|
383
|
-
* const { useMethod } = createActorMethodHooks(reactor)
|
|
384
|
-
* ```
|
|
385
|
-
*/
|
|
386
|
-
export function createActorMethodHooks(reactor) {
|
|
387
|
-
return {
|
|
388
|
-
/**
|
|
389
|
-
* Hook for calling methods on the bound reactor.
|
|
390
|
-
*/
|
|
391
|
-
useMethod: (config) => useActorMethod({ ...config, reactor }),
|
|
392
|
-
};
|
|
393
|
-
}
|
|
394
|
-
//# sourceMappingURL=useActorMethod.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActorMethod.js","sourceRoot":"","sources":["../../src/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ACP,WAAW;SACwC,CAAA;IACvD,CAAC;SAAM,CAAC;QACN,OAAO;YACL,IAAI,EAAE,cAAc,CAAC,IAAI;YACzB,SAAS,EAAE,cAAc,CAAC,SAAS;YACnC,SAAS,EAAE,cAAc,CAAC,SAAS;YACnC,OAAO,EAAE,cAAc,CAAC,OAAO;YAC/B,SAAS,EAAE,cAAc,CAAC,SAAS;YACnC,KAAK,EAAE,cAAc,CAAC,KAAK;YAC3B,OAAO,EAAE,KAAK;YACd,YAAY;YACZ,IAAI;YACJ,KAAK;YACL,OAAO;YACP,cAAc;SACqC,CAAA;IACvD,CAAC;AACH,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,sBAAsB,CAGpC,OAAoC;IACpC,OAAO;QACL;;WAEG;QACH,SAAS,EAAE,CACT,MAGC,EACD,EAAE,CACF,cAAc,CAAC,EAAE,GAAG,MAAM,EAAE,OAAO,EAIlC,CAAC;KACL,CAAA;AACH,CAAC"}
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
import { UseMutationOptions, UseMutationResult } from "@tanstack/react-query";
|
|
2
|
-
import { Reactor, ReactorArgs, ReactorReturnOk, FunctionName, TransformKey, ReactorReturnErr, CanisterError, ErrResult, ActorMethodReturnType, TransformReturnRegistry } from "@ic-reactor/core";
|
|
3
|
-
import { CallConfig } from "@icp-sdk/core/agent";
|
|
4
|
-
import type { InvalidationTarget } from "../types.js";
|
|
5
|
-
export interface UseActorMutationParameters<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TOnMutateResult = unknown> extends Omit<UseMutationOptions<ReactorReturnOk<Service, Method, Transform>, ReactorReturnErr<Service, Method, Transform>, ReactorArgs<Service, Method, Transform>, TOnMutateResult>, "mutationFn"> {
|
|
6
|
-
reactor: Reactor<Service, Transform>;
|
|
7
|
-
functionName: Method;
|
|
8
|
-
callConfig?: CallConfig;
|
|
9
|
-
/**
|
|
10
|
-
* Queries to invalidate upon successful mutation, awaited before
|
|
11
|
-
* `onSuccess` runs.
|
|
12
|
-
*
|
|
13
|
-
* Each entry is a query key, a query object or query factory, or a
|
|
14
|
-
* `{ functionName, args? }` method of `reactor`; see
|
|
15
|
-
* {@link InvalidationTarget}. `undefined` entries are skipped, so
|
|
16
|
-
* `[maybeQuery]` is safe when the optional query object is absent.
|
|
17
|
-
*/
|
|
18
|
-
invalidateQueries?: InvalidationTarget<Service, Transform>[];
|
|
19
|
-
/**
|
|
20
|
-
* Callback for canister-level business logic errors.
|
|
21
|
-
* Called when the canister returns a Result { Err: E } variant.
|
|
22
|
-
* Separate from `onError`, which fires for all errors including network failures.
|
|
23
|
-
*/
|
|
24
|
-
onCanisterError?: (error: CanisterError<TransformReturnRegistry<ErrResult<ActorMethodReturnType<Service[Method]>>, Service>[Transform]>, variables: ReactorArgs<Service, Method, Transform>) => void;
|
|
25
|
-
}
|
|
26
|
-
export type UseActorMutationConfig<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TOnMutateResult = unknown> = Omit<UseActorMutationParameters<Service, Method, Transform, TOnMutateResult>, "reactor">;
|
|
27
|
-
export type UseActorMutationResult<Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TOnMutateResult = unknown> = UseMutationResult<ReactorReturnOk<Service, Method, Transform>, ReactorReturnErr<Service, Method, Transform>, ReactorArgs<Service, Method, Transform>, TOnMutateResult>;
|
|
28
|
-
/**
|
|
29
|
-
* Hook for executing mutation calls on a canister.
|
|
30
|
-
* Use this for component-level mutation flows.
|
|
31
|
-
* For non-React usage, prefer `createMutation(...).execute(args)`.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* const { mutate, isPending } = useReactorMutation({
|
|
35
|
-
* reactor,
|
|
36
|
-
* functionName: "transfer",
|
|
37
|
-
* onSuccess: () => console.log("Success!"),
|
|
38
|
-
* onCanisterError: (err) => console.error("Canister Err:", err.code),
|
|
39
|
-
* })
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* const transferMutation = createMutation(reactor, {
|
|
43
|
-
* functionName: "transfer",
|
|
44
|
-
* onCanisterError: (err) => console.error(err.code),
|
|
45
|
-
* })
|
|
46
|
-
*
|
|
47
|
-
* // Non-React execution path
|
|
48
|
-
* await transferMutation.execute([{ to: "aaaaa-aa", amount: "100" }])
|
|
49
|
-
*/
|
|
50
|
-
export declare const useActorMutation: <Service, Method extends FunctionName<Service>, Transform extends TransformKey = "candid", TOnMutateResult = unknown>({ reactor, functionName, invalidateQueries, onSuccess, onError, onCanisterError, callConfig, ...options }: UseActorMutationParameters<Service, Method, Transform, TOnMutateResult>) => UseActorMutationResult<Service, Method, Transform, TOnMutateResult>;
|
|
51
|
-
//# sourceMappingURL=useActorMutation.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useActorMutation.d.ts","sourceRoot":"","sources":["../../src/hooks/useActorMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,kBAAkB,EAClB,iBAAiB,EAClB,MAAM,uBAAuB,CAAA;AAC9B,OAAO,EACL,OAAO,EACP,WAAW,EACX,eAAe,EACf,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAEhB,aAAa,EACb,SAAS,EACT,qBAAqB,EACrB,uBAAuB,EACxB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAEhD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,aAAa,CAAA;AAErD,MAAM,WAAW,0BAA0B,CACzC,OAAO,EACP,MAAM,SAAS,YAAY,CAAC,OAAO,CAAC,EACpC,SAAS,SAAS,YAAY,GAAG,QAAQ,EACzC,eAAe,GAAG,OAAO,CACzB,SAAQ,IAAI,CACZ,kBAAkB,CAChB,eAAe,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAC3C,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EAC5C,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,SAAS,CAAC,EACvC,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