@ic-reactor/react 1.0.5 → 1.0.7
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 +7 -8
- package/dist/context/actor.d.ts +64 -0
- package/dist/context/actor.js +117 -0
- package/dist/context/agent.d.ts +74 -0
- package/dist/context/agent.js +128 -0
- package/dist/{provider → context}/types.d.ts +2 -1
- package/dist/createReactor.d.ts +49 -0
- package/dist/createReactor.js +64 -0
- package/dist/helpers/authHooks.js +14 -18
- package/dist/helpers/extractActorContext.js +0 -82
- package/dist/helpers/extractAgentContext.d.ts +1 -1
- package/dist/helpers/extractAgentContext.js +3 -81
- package/dist/helpers/types.d.ts +15 -15
- package/dist/hooks/actor/hooks.d.ts +1 -0
- package/dist/hooks/actor/hooks.js +5 -0
- package/dist/hooks/actor/index.d.ts +4 -0
- package/dist/{provider/types.js → hooks/actor/index.js} +4 -1
- package/dist/hooks/actor/useActorState.d.ts +21 -0
- package/dist/hooks/actor/useActorState.js +25 -0
- package/dist/hooks/actor/useQueryCall.d.ts +28 -0
- package/dist/hooks/actor/useQueryCall.js +34 -0
- package/dist/hooks/actor/useUpdateCall.d.ts +29 -0
- package/dist/hooks/actor/useUpdateCall.js +35 -0
- package/dist/hooks/actor/useVisitMethod.d.ts +8 -0
- package/dist/hooks/actor/useVisitMethod.js +14 -0
- package/dist/hooks/agent/hooks.d.ts +1 -0
- package/dist/hooks/agent/hooks.js +5 -0
- package/dist/hooks/agent/index.d.ts +6 -0
- package/dist/hooks/agent/index.js +22 -0
- package/dist/hooks/agent/useAgent.d.ts +14 -0
- package/dist/hooks/agent/useAgent.js +18 -0
- package/dist/hooks/agent/useAgentManager.d.ts +15 -0
- package/dist/hooks/agent/useAgentManager.js +18 -0
- package/dist/hooks/agent/useAgentState.d.ts +21 -0
- package/dist/hooks/agent/useAgentState.js +25 -0
- package/dist/hooks/agent/useAuth.d.ts +57 -0
- package/dist/hooks/agent/useAuth.js +61 -0
- package/dist/hooks/agent/useAuthState.d.ts +19 -0
- package/dist/hooks/agent/useAuthState.js +23 -0
- package/dist/hooks/agent/useUserPrincipal.d.ts +17 -0
- package/dist/hooks/agent/useUserPrincipal.js +21 -0
- package/dist/hooks/index.d.ts +3 -0
- package/dist/{provider/hooks → hooks}/index.js +2 -0
- package/dist/{provider/hooks → hooks}/types.d.ts +2 -2
- package/dist/hooks/types.js +2 -0
- package/dist/{provider/hooks → hooks}/useActor.d.ts +6 -4
- package/dist/{provider/hooks → hooks}/useActor.js +14 -16
- package/dist/index.d.ts +6 -2
- package/dist/index.js +6 -2
- package/dist/provider/actor.d.ts +18 -56
- package/dist/provider/actor.js +19 -107
- package/dist/provider/agent.d.ts +20 -62
- package/dist/provider/agent.js +21 -113
- package/dist/types.d.ts +2 -1
- package/dist/types.js +2 -1
- package/package.json +3 -3
- package/dist/main.d.ts +0 -38
- package/dist/main.js +0 -53
- package/dist/provider/ActorProvider.d.ts +0 -27
- package/dist/provider/ActorProvider.js +0 -30
- package/dist/provider/AgentProvider.d.ts +0 -30
- package/dist/provider/AgentProvider.js +0 -33
- package/dist/provider/hooks/index.d.ts +0 -1
- package/dist/provider/index.d.ts +0 -8
- package/dist/provider/index.js +0 -25
- /package/dist/{provider/hooks → context}/types.js +0 -0
|
@@ -35,92 +35,10 @@ function extractActorContext(actorContext) {
|
|
|
35
35
|
}
|
|
36
36
|
return context;
|
|
37
37
|
};
|
|
38
|
-
/**
|
|
39
|
-
* Initializes the actor manager, setting up the actor's state.
|
|
40
|
-
*/
|
|
41
38
|
const initialize = () => useActorContext().initialize();
|
|
42
|
-
/**
|
|
43
|
-
* Hook for accessing the current state of the actor, including the canister ID.
|
|
44
|
-
*
|
|
45
|
-
* @returns An object containing the current state of the actor from Zustand's store and the canister ID.
|
|
46
|
-
* @example
|
|
47
|
-
* ```tsx
|
|
48
|
-
* function ActorStateComponent() {
|
|
49
|
-
* const { canisterId, initializing, error, initialized } = useActorState();
|
|
50
|
-
*
|
|
51
|
-
* return (
|
|
52
|
-
* <div>
|
|
53
|
-
* <p>Canister ID: {canisterId}</p>
|
|
54
|
-
* <p>Initializing: {initializing.toString()}</p>
|
|
55
|
-
* <p>Initialized: {initialized.toString()}</p>
|
|
56
|
-
* <p>Error: {error?.message}</p>
|
|
57
|
-
* </div>
|
|
58
|
-
* );
|
|
59
|
-
* }
|
|
60
|
-
*```
|
|
61
|
-
*/
|
|
62
39
|
const useActorState = () => useActorContext().useActorState();
|
|
63
|
-
/**
|
|
64
|
-
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
65
|
-
*
|
|
66
|
-
* @param options Configuration object for the query call, including refetching options and other configurations passed to useReactorCall.
|
|
67
|
-
* @returns An object containing the query call function and the current call state (data, error, loading, call, reset).
|
|
68
|
-
* @example
|
|
69
|
-
* ```tsx
|
|
70
|
-
* function QueryCallComponent() {
|
|
71
|
-
* const { call, data, loading } = useQueryCall({
|
|
72
|
-
* functionName: 'getUserProfile',
|
|
73
|
-
* args: ['123'],
|
|
74
|
-
* refetchOnMount: true,
|
|
75
|
-
* refetchInterval: 5000, // refetch every 5 seconds
|
|
76
|
-
* });
|
|
77
|
-
*
|
|
78
|
-
* if (loading) return <p>Loading profile...</p>;
|
|
79
|
-
*
|
|
80
|
-
* return (
|
|
81
|
-
* <div>
|
|
82
|
-
* <p>User Profile: {JSON.stringify(data)}</p>
|
|
83
|
-
* <button onClick={call}>Refetch</button>
|
|
84
|
-
* </div>
|
|
85
|
-
* );
|
|
86
|
-
* }
|
|
87
|
-
* ```
|
|
88
|
-
*/
|
|
89
40
|
const useQueryCall = (args) => useActorContext().useQueryCall(args);
|
|
90
|
-
/**
|
|
91
|
-
* Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
92
|
-
*
|
|
93
|
-
* @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
|
|
94
|
-
* @returns An object containing the method call function, a reset function to reset the call state to its default, and the current call state (data, error, loading, call, reset).
|
|
95
|
-
* @example
|
|
96
|
-
* ```tsx
|
|
97
|
-
* function UpdateCallComponent() {
|
|
98
|
-
* const { call, data, loading } = useUpdateCall({
|
|
99
|
-
* functionName: 'updateUserProfile',
|
|
100
|
-
* args: ['123', { name: 'John Doe' }],
|
|
101
|
-
* onLoading: (loading) => console.log('Loading:', loading),
|
|
102
|
-
* onError: (error) => console.error('Error:', error),
|
|
103
|
-
* onSuccess: (data) => console.log('Success:', data),
|
|
104
|
-
* });
|
|
105
|
-
*
|
|
106
|
-
* if (loading) return <p>Updating profile...</p>;
|
|
107
|
-
*
|
|
108
|
-
* return (
|
|
109
|
-
* <div>
|
|
110
|
-
* <p>Updated Profile: {JSON.stringify(data)}</p>
|
|
111
|
-
* <button onClick={call}>Update</button>
|
|
112
|
-
* </div>
|
|
113
|
-
* );
|
|
114
|
-
* }
|
|
115
|
-
* ```
|
|
116
|
-
*/
|
|
117
41
|
const useUpdateCall = (args) => useActorContext().useUpdateCall(args);
|
|
118
|
-
/**
|
|
119
|
-
* Memoizes and returns a visit service function for a specific actor method.
|
|
120
|
-
*
|
|
121
|
-
* @param functionName The name of the actor method to visit.
|
|
122
|
-
* @returns The visit service function for the specified method.
|
|
123
|
-
*/
|
|
124
42
|
const useVisitMethod = (functionName) => useActorContext().useVisitMethod(functionName);
|
|
125
43
|
return {
|
|
126
44
|
useActorState,
|
|
@@ -9,7 +9,7 @@ import type { AgentContext, CreateAgentContextReturnType } from "../types";
|
|
|
9
9
|
* - useAgent: Hook for accessing the current agent instance.
|
|
10
10
|
* - useAuthState: Hook for accessing the current authentication state.
|
|
11
11
|
* - useAgentState: Hook for accessing the current state of the agent.
|
|
12
|
-
* -
|
|
12
|
+
* - useAuth: Hook for accessing the authentication client, optionally accepting arguments for configuration.
|
|
13
13
|
* - useAgentManager: Hook for accessing the AgentManager instance.
|
|
14
14
|
* - useUserPrincipal: Hook for accessing the user's principal.
|
|
15
15
|
*
|
|
@@ -12,7 +12,7 @@ const react_1 = require("react");
|
|
|
12
12
|
* - useAgent: Hook for accessing the current agent instance.
|
|
13
13
|
* - useAuthState: Hook for accessing the current authentication state.
|
|
14
14
|
* - useAgentState: Hook for accessing the current state of the agent.
|
|
15
|
-
* -
|
|
15
|
+
* - useAuth: Hook for accessing the authentication client, optionally accepting arguments for configuration.
|
|
16
16
|
* - useAgentManager: Hook for accessing the AgentManager instance.
|
|
17
17
|
* - useUserPrincipal: Hook for accessing the user's principal.
|
|
18
18
|
*
|
|
@@ -35,98 +35,20 @@ const extractAgentContext = (agentContext) => {
|
|
|
35
35
|
}
|
|
36
36
|
return context;
|
|
37
37
|
};
|
|
38
|
-
/**
|
|
39
|
-
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
*```jsx
|
|
43
|
-
* function AgentManagerComponent() {
|
|
44
|
-
* const agentManager = useAgentManager();
|
|
45
|
-
*
|
|
46
|
-
* // Use agentManager for managing agent configurations, etc.
|
|
47
|
-
* return <div>Agent Manager ready.</div>;
|
|
48
|
-
* }
|
|
49
|
-
*```
|
|
50
|
-
*/
|
|
51
38
|
const useAgentManager = (agentContext) => {
|
|
52
39
|
const context = useAgentContext(agentContext);
|
|
53
40
|
return context.agentManager;
|
|
54
41
|
};
|
|
55
|
-
/**
|
|
56
|
-
* Accesses the current agent instance.
|
|
57
|
-
*
|
|
58
|
-
* @example
|
|
59
|
-
*```jsx
|
|
60
|
-
* function AgentComponent() {
|
|
61
|
-
* const agent = useAgent();
|
|
62
|
-
*
|
|
63
|
-
* // Use agent for interacting with the Internet Computer.
|
|
64
|
-
* return <div>Agent ready.</div>;
|
|
65
|
-
* }
|
|
66
|
-
*```
|
|
67
|
-
*/
|
|
68
42
|
const useAgent = () => useAgentContext().useAgent();
|
|
69
|
-
/**
|
|
70
|
-
* Accesses the current authentication state.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```jsx
|
|
74
|
-
* function AuthStateComponent() {
|
|
75
|
-
* const { isAuthenticated, user } = useAuthState();
|
|
76
|
-
*
|
|
77
|
-
* return (
|
|
78
|
-
* <div>
|
|
79
|
-
* {isAuthenticated ? `User ${user} is authenticated.` : 'User is not authenticated.'}
|
|
80
|
-
* </div>
|
|
81
|
-
* );
|
|
82
|
-
* }
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
43
|
const useAuthState = () => useAgentContext().useAuthState();
|
|
86
|
-
/**
|
|
87
|
-
* Accesses the current state of the agent.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```jsx
|
|
91
|
-
* function AgentStateComponent() {
|
|
92
|
-
* const { initialized, initializing } = useAgentState();
|
|
93
|
-
*
|
|
94
|
-
* return (
|
|
95
|
-
* <div>
|
|
96
|
-
* {initialized
|
|
97
|
-
* ? 'Agent is initialized.'
|
|
98
|
-
* : initializing
|
|
99
|
-
* ? 'Agent is initializing...'
|
|
100
|
-
* : 'Agent is not initialized.'}
|
|
101
|
-
* </div>
|
|
102
|
-
* );
|
|
103
|
-
* }
|
|
104
|
-
* ```
|
|
105
|
-
*/
|
|
106
44
|
const useAgentState = () => useAgentContext().useAgentState();
|
|
107
|
-
const
|
|
108
|
-
/**
|
|
109
|
-
* Accesses the user's principal.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```jsx
|
|
113
|
-
* function UserPrincipalComponent() {
|
|
114
|
-
* const userPrincipal = useUserPrincipal();
|
|
115
|
-
*
|
|
116
|
-
* return (
|
|
117
|
-
* <div>
|
|
118
|
-
* {userPrincipal ? `User principal: ${userPrincipal}` : 'User principal not found.'}
|
|
119
|
-
* </div>
|
|
120
|
-
* );
|
|
121
|
-
* }
|
|
122
|
-
* ```
|
|
123
|
-
*/
|
|
45
|
+
const useAuth = (args) => useAgentContext().useAuth(args);
|
|
124
46
|
const useUserPrincipal = () => useAgentContext().useUserPrincipal();
|
|
125
47
|
return {
|
|
126
48
|
useAgent,
|
|
127
49
|
useAuthState,
|
|
128
50
|
useAgentState,
|
|
129
|
-
|
|
51
|
+
useAuth: useAuth,
|
|
130
52
|
useAgentManager,
|
|
131
53
|
useUserPrincipal,
|
|
132
54
|
};
|
package/dist/helpers/types.d.ts
CHANGED
|
@@ -1,22 +1,15 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import type { ActorState, CanisterId, AuthClientLoginOptions, ActorMethodParameters, ActorMethodReturnType, Identity, Principal, FunctionName, VisitService,
|
|
2
|
+
import type { ActorState, CanisterId, AuthClientLoginOptions, ActorMethodParameters, ActorMethodReturnType, Identity, Principal, FunctionName, VisitService, AuthState, HttpAgent, AgentState, BaseActor } from "@ic-reactor/core/dist/types";
|
|
3
3
|
export interface AgentHooksReturnType {
|
|
4
4
|
useAgent: () => HttpAgent | undefined;
|
|
5
5
|
useAgentState: () => AgentState;
|
|
6
6
|
}
|
|
7
7
|
export interface AuthHooksReturnType {
|
|
8
|
-
|
|
8
|
+
useAuth: (options?: UseAuthParameters) => UseAuthReturnType;
|
|
9
9
|
useAuthState: () => AuthState;
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
export interface ActorHooksReturnType<A = BaseActor> {
|
|
13
|
-
initialize: () => Promise<void>;
|
|
14
|
-
useActorState: () => UseActorState;
|
|
15
|
-
useQueryCall: UseQueryCall<A>;
|
|
16
|
-
useUpdateCall: UseUpdateCall<A>;
|
|
17
|
-
useVisitMethod: <M extends FunctionName<A>>(functionName: M) => VisitService<A>[M];
|
|
10
|
+
useUserPrincipal: () => Principal | undefined;
|
|
18
11
|
}
|
|
19
|
-
export interface
|
|
12
|
+
export interface UseAuthParameters {
|
|
20
13
|
onAuthentication?: (promise: () => Promise<Identity>) => void;
|
|
21
14
|
onAuthenticationSuccess?: (identity: Identity) => void;
|
|
22
15
|
onAuthenticationFailure?: (error: Error) => void;
|
|
@@ -25,9 +18,8 @@ export interface UseAuthClientParameters {
|
|
|
25
18
|
onLogin?: (promise: () => Promise<Principal>) => void;
|
|
26
19
|
onLoggedOut?: () => void;
|
|
27
20
|
}
|
|
28
|
-
export interface
|
|
21
|
+
export interface UseAuthReturnType {
|
|
29
22
|
error: Error | undefined;
|
|
30
|
-
authClient: AuthClient | null;
|
|
31
23
|
authenticated: boolean;
|
|
32
24
|
authenticating: boolean;
|
|
33
25
|
identity: Identity | null;
|
|
@@ -45,6 +37,9 @@ export type LoginParameters = AuthClientLoginOptions;
|
|
|
45
37
|
export type LogoutParameters = {
|
|
46
38
|
returnTo?: string;
|
|
47
39
|
};
|
|
40
|
+
export interface UseActorState extends Omit<ActorState, "methodState"> {
|
|
41
|
+
canisterId: CanisterId;
|
|
42
|
+
}
|
|
48
43
|
export type UseMethodCallParameters<A, M extends FunctionName<A>> = {
|
|
49
44
|
functionName: M;
|
|
50
45
|
args?: ActorMethodParameters<A[M]>;
|
|
@@ -71,6 +66,11 @@ export interface UseMethodCallReturnType<A, M extends FunctionName<A> = Function
|
|
|
71
66
|
export type UseMethodCall<A> = <M extends FunctionName<A>>(args: UseMethodCallParameters<A, M>) => UseMethodCallReturnType<A, M>;
|
|
72
67
|
export type UseQueryCall<A> = <M extends FunctionName<A>>(args: UseQueryCallParameters<A, M>) => UseMethodCallReturnType<A, M>;
|
|
73
68
|
export type UseUpdateCall<A> = <M extends FunctionName<A>>(args: UseUpdateCallParameters<A, M>) => UseMethodCallReturnType<A, M>;
|
|
74
|
-
export
|
|
75
|
-
|
|
69
|
+
export type UseVisitMethod<A> = <M extends FunctionName<A>>(functionName: M) => VisitService<A>[M];
|
|
70
|
+
export interface ActorHooksReturnType<A = BaseActor> {
|
|
71
|
+
initialize: () => Promise<void>;
|
|
72
|
+
useActorState: () => UseActorState;
|
|
73
|
+
useQueryCall: UseQueryCall<A>;
|
|
74
|
+
useUpdateCall: UseUpdateCall<A>;
|
|
75
|
+
useVisitMethod: UseVisitMethod<A>;
|
|
76
76
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const ActorHooks: import("../../types").CreateActorContextReturnType<import("@ic-reactor/core/dist/types").BaseActor>;
|
|
@@ -14,4 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./
|
|
17
|
+
__exportStar(require("./useActorState"), exports);
|
|
18
|
+
__exportStar(require("./useQueryCall"), exports);
|
|
19
|
+
__exportStar(require("./useUpdateCall"), exports);
|
|
20
|
+
__exportStar(require("./useVisitMethod"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hook for accessing the current state of the actor, including the canister ID.
|
|
3
|
+
*
|
|
4
|
+
* @returns An object containing the current state of the actor from Zustand's store and the canister ID.
|
|
5
|
+
* @example
|
|
6
|
+
* ```tsx
|
|
7
|
+
* function ActorStateComponent() {
|
|
8
|
+
* const { canisterId, initializing, error, initialized } = useActorState();
|
|
9
|
+
*
|
|
10
|
+
* return (
|
|
11
|
+
* <div>
|
|
12
|
+
* <p>Canister ID: {canisterId}</p>
|
|
13
|
+
* <p>Initializing: {initializing.toString()}</p>
|
|
14
|
+
* <p>Initialized: {initialized.toString()}</p>
|
|
15
|
+
* <p>Error: {error?.message}</p>
|
|
16
|
+
* </div>
|
|
17
|
+
* );
|
|
18
|
+
* }
|
|
19
|
+
*```
|
|
20
|
+
*/
|
|
21
|
+
export declare const useActorState: () => import("../../types").UseActorState;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useActorState = void 0;
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
|
+
/**
|
|
6
|
+
* Hook for accessing the current state of the actor, including the canister ID.
|
|
7
|
+
*
|
|
8
|
+
* @returns An object containing the current state of the actor from Zustand's store and the canister ID.
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function ActorStateComponent() {
|
|
12
|
+
* const { canisterId, initializing, error, initialized } = useActorState();
|
|
13
|
+
*
|
|
14
|
+
* return (
|
|
15
|
+
* <div>
|
|
16
|
+
* <p>Canister ID: {canisterId}</p>
|
|
17
|
+
* <p>Initializing: {initializing.toString()}</p>
|
|
18
|
+
* <p>Initialized: {initialized.toString()}</p>
|
|
19
|
+
* <p>Error: {error?.message}</p>
|
|
20
|
+
* </div>
|
|
21
|
+
* );
|
|
22
|
+
* }
|
|
23
|
+
*```
|
|
24
|
+
*/
|
|
25
|
+
exports.useActorState = hooks_1.ActorHooks.useActorState;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { FunctionName, UseQueryCallParameters } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
4
|
+
*
|
|
5
|
+
* @param options Configuration object for the query call, including refetching options and other configurations passed to useReactorCall.
|
|
6
|
+
* @returns An object containing the query call function and the current call state (data, error, loading, call, reset).
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function QueryCallComponent() {
|
|
10
|
+
* const { call, data, loading } = useQueryCall({
|
|
11
|
+
* functionName: 'getUserProfile',
|
|
12
|
+
* args: ['123'],
|
|
13
|
+
* refetchOnMount: true,
|
|
14
|
+
* refetchInterval: 5000, // refetch every 5 seconds
|
|
15
|
+
* });
|
|
16
|
+
*
|
|
17
|
+
* if (loading) return <p>Loading profile...</p>;
|
|
18
|
+
*
|
|
19
|
+
* return (
|
|
20
|
+
* <div>
|
|
21
|
+
* <p>User Profile: {JSON.stringify(data)}</p>
|
|
22
|
+
* <button onClick={call}>Refetch</button>
|
|
23
|
+
* </div>
|
|
24
|
+
* );
|
|
25
|
+
* }
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export declare function useQueryCall<A, M extends FunctionName<A> = FunctionName<A>>(args: UseQueryCallParameters<A, M>): import("../../types").UseMethodCallReturnType<A, M>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useQueryCall = void 0;
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
|
+
/**
|
|
6
|
+
* Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
|
|
7
|
+
*
|
|
8
|
+
* @param options Configuration object for the query call, including refetching options and other configurations passed to useReactorCall.
|
|
9
|
+
* @returns An object containing the query call function and the current call state (data, error, loading, call, reset).
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* function QueryCallComponent() {
|
|
13
|
+
* const { call, data, loading } = useQueryCall({
|
|
14
|
+
* functionName: 'getUserProfile',
|
|
15
|
+
* args: ['123'],
|
|
16
|
+
* refetchOnMount: true,
|
|
17
|
+
* refetchInterval: 5000, // refetch every 5 seconds
|
|
18
|
+
* });
|
|
19
|
+
*
|
|
20
|
+
* if (loading) return <p>Loading profile...</p>;
|
|
21
|
+
*
|
|
22
|
+
* return (
|
|
23
|
+
* <div>
|
|
24
|
+
* <p>User Profile: {JSON.stringify(data)}</p>
|
|
25
|
+
* <button onClick={call}>Refetch</button>
|
|
26
|
+
* </div>
|
|
27
|
+
* );
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
function useQueryCall(args) {
|
|
32
|
+
return hooks_1.ActorHooks.useQueryCall(args);
|
|
33
|
+
}
|
|
34
|
+
exports.useQueryCall = useQueryCall;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BaseActor, FunctionName, UseUpdateCallParameters } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
4
|
+
*
|
|
5
|
+
* @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
|
|
6
|
+
* @returns An object containing the method call function, a reset function to reset the call state to its default, and the current call state (data, error, loading, call, reset).
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function UpdateCallComponent() {
|
|
10
|
+
* const { call, data, loading } = useUpdateCall({
|
|
11
|
+
* functionName: 'updateUserProfile',
|
|
12
|
+
* args: ['123', { name: 'John Doe' }],
|
|
13
|
+
* onLoading: (loading) => console.log('Loading:', loading),
|
|
14
|
+
* onError: (error) => console.error('Error:', error),
|
|
15
|
+
* onSuccess: (data) => console.log('Success:', data),
|
|
16
|
+
* });
|
|
17
|
+
*
|
|
18
|
+
* if (loading) return <p>Updating profile...</p>;
|
|
19
|
+
*
|
|
20
|
+
* return (
|
|
21
|
+
* <div>
|
|
22
|
+
* <p>Updated Profile: {JSON.stringify(data)}</p>
|
|
23
|
+
* <button onClick={call}>Update</button>
|
|
24
|
+
* </div>
|
|
25
|
+
* );
|
|
26
|
+
* }
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
export declare function useUpdateCall<A = BaseActor, M extends FunctionName<A> = FunctionName<A>>(args: UseUpdateCallParameters<A, M>): import("../../types").UseMethodCallReturnType<A, M>;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useUpdateCall = void 0;
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
|
+
/**
|
|
6
|
+
* Hook for making update calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
|
|
7
|
+
*
|
|
8
|
+
* @param options Configuration object for the actor method call, including the method name, arguments, and event handlers.
|
|
9
|
+
* @returns An object containing the method call function, a reset function to reset the call state to its default, and the current call state (data, error, loading, call, reset).
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* function UpdateCallComponent() {
|
|
13
|
+
* const { call, data, loading } = useUpdateCall({
|
|
14
|
+
* functionName: 'updateUserProfile',
|
|
15
|
+
* args: ['123', { name: 'John Doe' }],
|
|
16
|
+
* onLoading: (loading) => console.log('Loading:', loading),
|
|
17
|
+
* onError: (error) => console.error('Error:', error),
|
|
18
|
+
* onSuccess: (data) => console.log('Success:', data),
|
|
19
|
+
* });
|
|
20
|
+
*
|
|
21
|
+
* if (loading) return <p>Updating profile...</p>;
|
|
22
|
+
*
|
|
23
|
+
* return (
|
|
24
|
+
* <div>
|
|
25
|
+
* <p>Updated Profile: {JSON.stringify(data)}</p>
|
|
26
|
+
* <button onClick={call}>Update</button>
|
|
27
|
+
* </div>
|
|
28
|
+
* );
|
|
29
|
+
* }
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
function useUpdateCall(args) {
|
|
33
|
+
return hooks_1.ActorHooks.useUpdateCall(args);
|
|
34
|
+
}
|
|
35
|
+
exports.useUpdateCall = useUpdateCall;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { BaseActor, FunctionName } from "../../types";
|
|
2
|
+
/**
|
|
3
|
+
* Memoizes and returns a visit service function for a specific actor method.
|
|
4
|
+
*
|
|
5
|
+
* @param functionName The name of the actor method to visit.
|
|
6
|
+
* @returns The visit service function for the specified method.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useVisitMethod<A = BaseActor>(functionName: FunctionName<A>): <V extends import("@dfinity/candid/lib/cjs/idl").Visitor<unknown, unknown>>(extractorClass: V, data?: import("@ic-reactor/core/dist/classes/actor/types").VisitorType<V>["data"] | undefined) => ReturnType<V["visitFunc"]>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useVisitMethod = void 0;
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
|
+
/**
|
|
6
|
+
* Memoizes and returns a visit service function for a specific actor method.
|
|
7
|
+
*
|
|
8
|
+
* @param functionName The name of the actor method to visit.
|
|
9
|
+
* @returns The visit service function for the specified method.
|
|
10
|
+
*/
|
|
11
|
+
function useVisitMethod(functionName) {
|
|
12
|
+
return hooks_1.ActorHooks.useVisitMethod(functionName);
|
|
13
|
+
}
|
|
14
|
+
exports.useVisitMethod = useVisitMethod;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const AgentHooks: import("../../types").CreateAgentContextReturnType;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./useAgent"), exports);
|
|
18
|
+
__exportStar(require("./useAgentState"), exports);
|
|
19
|
+
__exportStar(require("./useAgentManager"), exports);
|
|
20
|
+
__exportStar(require("./useAuth"), exports);
|
|
21
|
+
__exportStar(require("./useAuthState"), exports);
|
|
22
|
+
__exportStar(require("./useUserPrincipal"), exports);
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accesses the current agent instance.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
*```jsx
|
|
6
|
+
* function AgentComponent() {
|
|
7
|
+
* const agent = useAgent();
|
|
8
|
+
*
|
|
9
|
+
* // Use agent for interacting with the Internet Computer.
|
|
10
|
+
* return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
|
|
11
|
+
* }
|
|
12
|
+
*```
|
|
13
|
+
*/
|
|
14
|
+
export declare const useAgent: () => import("@dfinity/agent").HttpAgent | undefined;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAgent = void 0;
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
|
+
/**
|
|
6
|
+
* Accesses the current agent instance.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*```jsx
|
|
10
|
+
* function AgentComponent() {
|
|
11
|
+
* const agent = useAgent();
|
|
12
|
+
*
|
|
13
|
+
* // Use agent for interacting with the Internet Computer.
|
|
14
|
+
* return <div>{agent.isLocal() ? 'Local' : 'Remote'}</div>;
|
|
15
|
+
* }
|
|
16
|
+
*```
|
|
17
|
+
*/
|
|
18
|
+
exports.useAgent = hooks_1.AgentHooks.useAgent;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
/**
|
|
3
|
+
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
4
|
+
*
|
|
5
|
+
* @example
|
|
6
|
+
*```jsx
|
|
7
|
+
* function AgentManagerComponent() {
|
|
8
|
+
* const agentManager = useAgentManager();
|
|
9
|
+
*
|
|
10
|
+
* // Use agentManager for managing agent configurations, etc.
|
|
11
|
+
* return <div>Agent Manager ready.</div>;
|
|
12
|
+
* }
|
|
13
|
+
*```
|
|
14
|
+
*/
|
|
15
|
+
export declare const useAgentManager: (agentContext?: import("react").Context<import("../../types").AgentContext | null> | undefined) => import("@ic-reactor/core/dist/types").AgentManager;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useAgentManager = void 0;
|
|
4
|
+
const hooks_1 = require("./hooks");
|
|
5
|
+
/**
|
|
6
|
+
* Accesses the `AgentManager` instance for managing agent configurations and state.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
*```jsx
|
|
10
|
+
* function AgentManagerComponent() {
|
|
11
|
+
* const agentManager = useAgentManager();
|
|
12
|
+
*
|
|
13
|
+
* // Use agentManager for managing agent configurations, etc.
|
|
14
|
+
* return <div>Agent Manager ready.</div>;
|
|
15
|
+
* }
|
|
16
|
+
*```
|
|
17
|
+
*/
|
|
18
|
+
exports.useAgentManager = hooks_1.AgentHooks.useAgentManager;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Accesses the current state of the agent.
|
|
3
|
+
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```jsx
|
|
6
|
+
* function AgentStateComponent() {
|
|
7
|
+
* const { initialized, initializing } = useAgentState();
|
|
8
|
+
*
|
|
9
|
+
* return (
|
|
10
|
+
* <div>
|
|
11
|
+
* {initialized
|
|
12
|
+
* ? 'Agent is initialized.'
|
|
13
|
+
* : initializing
|
|
14
|
+
* ? 'Agent is initializing...'
|
|
15
|
+
* : 'Agent is not initialized.'}
|
|
16
|
+
* </div>
|
|
17
|
+
* );
|
|
18
|
+
* }
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export declare const useAgentState: () => import("@ic-reactor/core/dist/types").AgentState;
|