@ic-reactor/react 1.16.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -15,33 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
17
  });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __rest = (this && this.__rest) || function (s, e) {
35
- var t = {};
36
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
37
- t[p] = s[p];
38
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
39
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
40
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
41
- t[p[i]] = s[p[i]];
42
- }
43
- return t;
44
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
45
35
  Object.defineProperty(exports, "__esModule", { value: true });
46
36
  exports.actorHooks = void 0;
47
37
  const React = __importStar(require("react"));
@@ -52,6 +42,7 @@ const DEFAULT_STATE = {
52
42
  data: undefined,
53
43
  error: undefined,
54
44
  loading: false,
45
+ isLoading: false,
55
46
  };
56
47
  /**
57
48
  * Provides a set of React hooks designed for interacting with actors in an Internet Computer (IC) project using the React framework and Zustand for state management.
@@ -78,13 +69,15 @@ const actorHooks = (actorManager) => {
78
69
  name: state.name,
79
70
  error: state.error,
80
71
  version: state.version,
81
- initialized: state.initialized,
82
- initializing: state.initializing,
72
+ initialized: state.isInitialized,
73
+ isInitialized: state.isInitialized,
74
+ initializing: state.isInitializing,
75
+ isInitializing: state.isInitializing,
83
76
  canisterId,
84
77
  }));
85
78
  };
86
79
  const useMethodState = (functionName, requestKey) => {
87
- const state = useActorStore((state) => { var _a; return (_a = state.methodState[functionName]) === null || _a === void 0 ? void 0 : _a[requestKey]; });
80
+ const state = useActorStore((state) => state.methodState[functionName]?.[requestKey]);
88
81
  const setSharedState = React.useCallback((newState) => {
89
82
  updateMethodState(functionName, requestKey, newState);
90
83
  }, [functionName, requestKey]);
@@ -113,31 +106,35 @@ const actorHooks = (actorManager) => {
113
106
  return visitFunction[functionName];
114
107
  }, [functionName]);
115
108
  };
116
- const useSharedCall = (_a) => {
117
- var { args = [], functionName, throwOnError = false, onError, onLoading, onSuccess, onSuccessResult, onErrorResult } = _a, options = __rest(_a, ["args", "functionName", "throwOnError", "onError", "onLoading", "onSuccess", "onSuccessResult", "onErrorResult"]);
109
+ const useSharedCall = ({ args = [], functionName, throwOnError = false, onError, onLoading, onSuccess, onSuccessResult, onErrorResult, ...options }) => {
118
110
  const requestKey = React.useMemo(() => (0, utils_1.generateRequestHash)(args), [args]);
119
111
  const [sharedState, setSharedState] = useMethodState(functionName, requestKey);
120
- const latestDataRef = React.useRef();
112
+ const latestDataRef = React.useRef(null);
121
113
  const reset = React.useCallback(() => {
122
114
  updateMethodState(functionName, requestKey, DEFAULT_STATE);
123
- latestDataRef.current = undefined;
115
+ latestDataRef.current = null;
124
116
  }, [functionName, requestKey]);
125
- const call = React.useCallback((eventOrReplaceArgs) => __awaiter(void 0, void 0, void 0, function* () {
126
- setSharedState({ error: undefined, loading: true });
127
- onLoading === null || onLoading === void 0 ? void 0 : onLoading(true);
117
+ const call = React.useCallback(async (eventOrReplaceArgs) => {
118
+ setSharedState({ error: undefined, loading: true, isLoading: true });
119
+ onLoading?.(true);
128
120
  try {
129
121
  const replaceArgs = eventOrReplaceArgs instanceof Array ? eventOrReplaceArgs : args;
130
- const data = yield callMethodWithOptions(options)(functionName, ...(replaceArgs !== null && replaceArgs !== void 0 ? replaceArgs : args));
122
+ const data = await callMethodWithOptions(options)(functionName, ...(replaceArgs ?? args));
131
123
  latestDataRef.current = data;
132
- setSharedState({ data, error: undefined, loading: false });
133
- onLoading === null || onLoading === void 0 ? void 0 : onLoading(false);
134
- onSuccess === null || onSuccess === void 0 ? void 0 : onSuccess(data);
124
+ setSharedState({
125
+ data,
126
+ error: undefined,
127
+ loading: false,
128
+ isLoading: false,
129
+ });
130
+ onLoading?.(false);
131
+ onSuccess?.(data);
135
132
  const { isOk, value, error } = (0, utils_1.createCompiledResult)(data);
136
133
  if (isOk) {
137
- onSuccessResult === null || onSuccessResult === void 0 ? void 0 : onSuccessResult(value);
134
+ onSuccessResult?.(value);
138
135
  }
139
136
  else {
140
- onErrorResult === null || onErrorResult === void 0 ? void 0 : onErrorResult(error);
137
+ onErrorResult?.(error);
141
138
  if (throwOnError) {
142
139
  throw error;
143
140
  }
@@ -147,17 +144,19 @@ const actorHooks = (actorManager) => {
147
144
  catch (error) {
148
145
  // eslint-disable-next-line no-console
149
146
  console.error(`Error calling method ${functionName}:`, error);
150
- latestDataRef.current = undefined;
147
+ latestDataRef.current = null;
151
148
  setSharedState({
152
149
  error: error,
153
150
  loading: false,
151
+ isLoading: false,
154
152
  });
155
- onError === null || onError === void 0 ? void 0 : onError(error);
156
- onLoading === null || onLoading === void 0 ? void 0 : onLoading(false);
153
+ onError?.(error);
154
+ onLoading?.(false);
157
155
  if (throwOnError)
158
156
  throw error;
157
+ return undefined;
159
158
  }
160
- }), [
159
+ }, [
161
160
  args,
162
161
  functionName,
163
162
  options,
@@ -168,19 +167,20 @@ const actorHooks = (actorManager) => {
168
167
  throwOnError,
169
168
  ]);
170
169
  const compileResult = () => {
171
- return (0, utils_1.createCompiledResult)(latestDataRef.current || (sharedState === null || sharedState === void 0 ? void 0 : sharedState.data));
170
+ return (0, utils_1.createCompiledResult)(latestDataRef.current || sharedState?.data);
172
171
  };
173
- return Object.assign({ call,
172
+ return {
173
+ call,
174
174
  reset,
175
175
  compileResult,
176
- requestKey }, sharedState);
176
+ requestKey,
177
+ ...sharedState,
178
+ };
177
179
  };
178
- const useQueryCall = (_a) => {
179
- var { refetchOnMount = true, refetchInterval = false } = _a, rest = __rest(_a, ["refetchOnMount", "refetchInterval"]);
180
- const _b = useSharedCall(rest), { call, requestKey } = _b, state = __rest(_b, ["call", "requestKey"]);
181
- const intervalId = React.useRef();
180
+ const useQueryCall = ({ refetchOnMount = true, refetchInterval = false, ...rest }) => {
181
+ const { call, requestKey, ...state } = useSharedCall(rest);
182
+ const intervalId = React.useRef(null);
182
183
  React.useEffect(() => {
183
- var _a, _b, _c;
184
184
  if (refetchInterval) {
185
185
  intervalId.current = setInterval(call, refetchInterval);
186
186
  }
@@ -188,21 +188,25 @@ const actorHooks = (actorManager) => {
188
188
  call();
189
189
  }
190
190
  else if (refetchOnMount && state.data !== undefined) {
191
- (_a = rest.onSuccess) === null || _a === void 0 ? void 0 : _a.call(rest, state.data);
191
+ rest.onSuccess?.(state.data);
192
192
  const { isOk, value, error } = (0, utils_1.createCompiledResult)(state.data);
193
193
  if (isOk) {
194
- (_b = rest.onSuccessResult) === null || _b === void 0 ? void 0 : _b.call(rest, value);
194
+ rest.onSuccessResult?.(value);
195
195
  }
196
196
  else {
197
- (_c = rest.onErrorResult) === null || _c === void 0 ? void 0 : _c.call(rest, error);
197
+ rest.onErrorResult?.(error);
198
198
  }
199
199
  }
200
- return () => clearInterval(intervalId.current);
200
+ return () => {
201
+ if (intervalId.current) {
202
+ clearInterval(intervalId.current);
203
+ }
204
+ };
201
205
  }, [refetchInterval, refetchOnMount, requestKey]);
202
206
  const refetch = () => {
203
207
  call();
204
208
  };
205
- return Object.assign({ call, refetch, intervalId, requestKey }, state);
209
+ return { call, refetch, intervalId, requestKey, ...state };
206
210
  };
207
211
  const useUpdateCall = useSharedCall;
208
212
  const useMethod = (params) => {
@@ -236,21 +240,28 @@ const actorHooks = (actorManager) => {
236
240
  }, [attributes]);
237
241
  let refetchOnMount = params.refetchOnMount;
238
242
  let refetchInterval = params.refetchInterval;
239
- let formRequired = true;
243
+ let isFormRequired = true;
240
244
  switch (attributes.type) {
241
245
  case "query":
242
246
  if (validateArgs(params.args)) {
243
- formRequired = params.refetchOnMount === false ? true : false;
247
+ isFormRequired = params.refetchOnMount === false ? true : false;
244
248
  }
245
249
  else {
246
250
  refetchOnMount = false;
247
251
  refetchInterval = false;
248
252
  }
249
- return Object.assign(Object.assign({ visit,
250
- validateArgs }, useQueryCall(Object.assign(Object.assign({}, params), { refetchOnMount,
251
- refetchInterval }))), { formRequired });
253
+ return {
254
+ visit,
255
+ validateArgs,
256
+ ...useQueryCall({
257
+ ...params,
258
+ refetchOnMount,
259
+ refetchInterval,
260
+ }),
261
+ isFormRequired,
262
+ };
252
263
  case "update":
253
- return Object.assign(Object.assign({ visit, validateArgs }, useUpdateCall(params)), { formRequired });
264
+ return { visit, validateArgs, ...useUpdateCall(params), isFormRequired };
254
265
  default:
255
266
  throw new Error(`Method type ${attributes.type} not found`);
256
267
  }
@@ -1,13 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  var __importDefault = (this && this.__importDefault) || function (mod) {
12
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
13
4
  };
@@ -19,93 +10,104 @@ const utils_1 = require("@ic-reactor/core/dist/utils");
19
10
  const authHooks = (agentManager) => {
20
11
  const { authenticate: authenticator, getIsLocal, getAuth, authStore, } = agentManager;
21
12
  const useAuthState = () => (0, zustand_1.useStore)(authStore);
22
- const useUserPrincipal = () => { var _a, _b; return (_b = (_a = useAuthState()) === null || _a === void 0 ? void 0 : _a.identity) === null || _b === void 0 ? void 0 : _b.getPrincipal(); };
13
+ const useUserPrincipal = () => useAuthState()?.identity?.getPrincipal();
23
14
  const useAuth = ({ onAuthentication, onAuthenticationSuccess, onAuthenticationFailure, onLogin, onLoginSuccess, onLoginError, onLoggedOut, } = {}) => {
24
15
  const [loginState, setLoginState] = react_1.default.useState({
25
16
  loading: false,
17
+ isLoading: false,
26
18
  error: undefined,
27
19
  });
28
- const { authenticated, authenticating, error, identity } = useAuthState();
29
- const authenticate = react_1.default.useCallback(() => __awaiter(void 0, void 0, void 0, function* () {
20
+ const { isAuthenticated, isAuthenticating, error, identity } = useAuthState();
21
+ const authenticate = react_1.default.useCallback(async () => {
30
22
  const authenticatePromise = new Promise((resolve, reject) => {
31
23
  authenticator()
32
24
  .then((identity) => {
33
- onAuthenticationSuccess === null || onAuthenticationSuccess === void 0 ? void 0 : onAuthenticationSuccess(identity);
25
+ onAuthenticationSuccess?.(identity);
34
26
  resolve(identity);
35
27
  })
36
28
  .catch((e) => {
37
- onAuthenticationFailure === null || onAuthenticationFailure === void 0 ? void 0 : onAuthenticationFailure(e);
29
+ onAuthenticationFailure?.(e);
38
30
  reject(e);
39
31
  });
40
32
  });
41
- onAuthentication === null || onAuthentication === void 0 ? void 0 : onAuthentication(() => authenticatePromise);
33
+ onAuthentication?.(() => authenticatePromise);
42
34
  return authenticatePromise;
43
- }), [
35
+ }, [
44
36
  authenticator,
45
37
  onAuthentication,
46
38
  onAuthenticationSuccess,
47
39
  onAuthenticationFailure,
48
40
  ]);
49
- const login = react_1.default.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
50
- setLoginState({ loading: true, error: undefined });
41
+ const login = react_1.default.useCallback(async (options) => {
42
+ setLoginState({ loading: true, isLoading: true, error: undefined });
51
43
  const loginPromise = new Promise((resolve, reject) => {
52
44
  try {
53
45
  const authClient = getAuth();
54
46
  if (!authClient) {
55
47
  throw new Error("Auth client not initialized");
56
48
  }
57
- authClient.login(Object.assign(Object.assign({ identityProvider: getIsLocal()
49
+ authClient.login({
50
+ identityProvider: getIsLocal()
58
51
  ? utils_1.LOCAL_INTERNET_IDENTITY_PROVIDER
59
- : utils_1.IC_INTERNET_IDENTITY_PROVIDER }, options), { onSuccess: (msg) => {
52
+ : utils_1.IC_INTERNET_IDENTITY_PROVIDER,
53
+ ...options,
54
+ onSuccess: (msg) => {
60
55
  authenticate()
61
56
  .then((identity) => {
62
- var _a;
63
57
  const principal = identity.getPrincipal();
64
- (_a = options === null || options === void 0 ? void 0 : options.onSuccess) === null || _a === void 0 ? void 0 : _a.call(options, msg);
65
- onLoginSuccess === null || onLoginSuccess === void 0 ? void 0 : onLoginSuccess(principal);
58
+ options?.onSuccess?.(msg);
59
+ onLoginSuccess?.(principal);
66
60
  resolve(principal);
67
- setLoginState({ loading: false, error: undefined });
61
+ setLoginState({
62
+ loading: false,
63
+ isLoading: false,
64
+ error: undefined,
65
+ });
68
66
  })
69
67
  .catch((error) => {
70
- setLoginState({ loading: false, error });
71
- onLoginError === null || onLoginError === void 0 ? void 0 : onLoginError(error);
68
+ setLoginState({ loading: false, isLoading: false, error });
69
+ onLoginError?.(error);
72
70
  reject(error);
73
71
  });
74
- }, onError: (error) => {
75
- var _a;
76
- (_a = options === null || options === void 0 ? void 0 : options.onError) === null || _a === void 0 ? void 0 : _a.call(options, error);
77
- setLoginState({ loading: false, error });
78
- onLoginError === null || onLoginError === void 0 ? void 0 : onLoginError(error);
72
+ },
73
+ onError: (error) => {
74
+ options?.onError?.(error);
75
+ setLoginState({ loading: false, isLoading: false, error });
76
+ onLoginError?.(error);
79
77
  reject(error);
80
- } }));
78
+ },
79
+ });
81
80
  }
82
81
  catch (e) {
83
82
  const error = e;
84
- setLoginState({ loading: false, error });
85
- onLoginError === null || onLoginError === void 0 ? void 0 : onLoginError(error);
83
+ setLoginState({ loading: false, isLoading: false, error });
84
+ onLoginError?.(error);
86
85
  reject(error);
87
86
  }
88
87
  });
89
- onLogin === null || onLogin === void 0 ? void 0 : onLogin(() => loginPromise);
90
- }), [onLogin, onLoginSuccess, onLoginError, authenticate]);
91
- const logout = react_1.default.useCallback((options) => __awaiter(void 0, void 0, void 0, function* () {
88
+ onLogin?.(() => loginPromise);
89
+ }, [onLogin, onLoginSuccess, onLoginError, authenticate]);
90
+ const logout = react_1.default.useCallback(async (options) => {
92
91
  const authClient = getAuth();
93
92
  if (!authClient) {
94
93
  throw new Error("Auth client not initialized");
95
94
  }
96
- yield authClient.logout(options);
97
- yield authenticate();
98
- onLoggedOut === null || onLoggedOut === void 0 ? void 0 : onLoggedOut();
99
- }), [onLoggedOut]);
95
+ await authClient.logout(options);
96
+ await authenticate();
97
+ onLoggedOut?.();
98
+ }, [onLoggedOut]);
100
99
  return {
101
- authenticated,
102
- authenticating,
100
+ isAuthenticated,
101
+ isAuthenticating,
102
+ authenticated: isAuthenticated,
103
+ authenticating: isAuthenticating,
103
104
  identity,
104
105
  error,
105
106
  login,
106
107
  logout,
107
108
  authenticate,
108
- loginLoading: loginState.loading,
109
+ loginLoading: loginState.isLoading,
110
+ isLoginLoading: loginState.isLoading,
109
111
  loginError: loginState.error,
110
112
  };
111
113
  };
@@ -26,7 +26,7 @@ function extractActorContext(actorContext) {
26
26
  const useVisitMethod = (functionName) => useActorContext().useVisitMethod(functionName);
27
27
  const useVisitService = () => useActorContext().useVisitService();
28
28
  const useActorInterface = () => useActorContext().useActorInterface();
29
- const useInitializeActor = () => { var _a, _b; return (_b = (_a = useActorContext()).useInitializeActor) === null || _b === void 0 ? void 0 : _b.call(_a); };
29
+ const useInitializeActor = () => useActorContext().useInitializeActor?.();
30
30
  return {
31
31
  useActorStore,
32
32
  useActorState,
@@ -1,4 +1,4 @@
1
- import { CallConfig } from "@dfinity/agent";
1
+ import { AgentError, CallConfig } from "@dfinity/agent";
2
2
  import type { IDL, ActorState, AuthClientLoginOptions, ActorMethodParameters, ActorMethodReturnType, Identity, Principal, FunctionName, VisitService, AuthState, HttpAgent, AgentState, BaseActor, MethodAttributes, CompiledResult, ExtractOk, ExtractErr } from "../types";
3
3
  export interface AgentHooksReturnType {
4
4
  useAgent: () => HttpAgent | undefined;
@@ -18,19 +18,80 @@ export interface UseAuthParameters {
18
18
  onLogin?: (promise: () => Promise<Principal>) => void;
19
19
  onLoggedOut?: () => void;
20
20
  }
21
+ /**
22
+ * The return type for authentication hooks.
23
+ */
21
24
  export interface UseAuthReturnType {
25
+ /**
26
+ * Any non-login related error that occurred.
27
+ */
22
28
  error: Error | undefined;
29
+ /**
30
+ * @deprecated Use `isAuthenticated` instead.
31
+ * Indicates whether the user is authenticated.
32
+ */
23
33
  authenticated: boolean;
34
+ /**
35
+ * Indicates whether the user is authenticated.
36
+ */
37
+ isAuthenticated: boolean;
38
+ /**
39
+ * @deprecated Use `isAuthenticating` instead.
40
+ * Indicates whether an authentication request is in progress.
41
+ */
24
42
  authenticating: boolean;
43
+ /**
44
+ * Indicates whether an authentication request is in progress.
45
+ */
46
+ isAuthenticating: boolean;
47
+ /**
48
+ * The current identity object, or `null` if not authenticated.
49
+ */
25
50
  identity: Identity | null;
51
+ /**
52
+ * Initiates the login flow with optional parameters.
53
+ * @param options Login parameters (e.g. redirect URL).
54
+ */
26
55
  login: (options?: LoginParameters) => Promise<void>;
56
+ /**
57
+ * Logs the user out with optional parameters.
58
+ * @param options Logout parameters (e.g. return URL).
59
+ */
27
60
  logout: (options?: LogoutParameters) => Promise<void>;
61
+ /**
62
+ * Triggers the authentication flow and resolves to an `Identity`.
63
+ */
28
64
  authenticate: () => Promise<Identity>;
65
+ /**
66
+ * @deprecated Use `isLoginLoading` instead.
67
+ * Indicates whether the login operation is in progress.
68
+ */
29
69
  loginLoading: boolean;
70
+ /**
71
+ * Indicates whether the login operation is in progress.
72
+ */
73
+ isLoginLoading: boolean;
74
+ /**
75
+ * The error message, if any, occurred during login.
76
+ */
30
77
  loginError: string | undefined;
31
78
  }
79
+ /**
80
+ * Represents the state of a login operation.
81
+ */
32
82
  export type LoginState = {
83
+ /**
84
+ * @deprecated Use `isLoading` instead.
85
+ * Indicates whether the login operation is in progress.
86
+ */
33
87
  loading: boolean;
88
+ /**
89
+ * Indicates whether the login operation is in progress.
90
+ */
91
+ isLoading: boolean;
92
+ /**
93
+ * The error message, if any, occurred during login.
94
+ */
34
95
  error: string | undefined;
35
96
  };
36
97
  export type LoginParameters = AuthClientLoginOptions;
@@ -41,21 +102,37 @@ export type UseActorStore<A> = <T>(callback?: (state: ActorState<A>) => T) => T;
41
102
  export interface UseActorStateReturnType extends Omit<ActorState, "methodState"> {
42
103
  canisterId: string;
43
104
  }
105
+ /**
106
+ * State for shared calls, including the result, error, and loading status.
107
+ */
44
108
  export type UseSharedCallState<A, M extends FunctionName<A>> = {
109
+ /**
110
+ * The data returned from the call, or `undefined` if not yet available.
111
+ */
45
112
  data: ActorMethodReturnType<A[M]> | undefined;
46
- error: Error | undefined;
113
+ /**
114
+ * The error that occurred during the call, or `undefined` if none.
115
+ */
116
+ error: AgentError | undefined;
117
+ /**
118
+ * @deprecated Use `isLoading` instead.
119
+ * Indicates whether the call is in progress.
120
+ */
47
121
  loading: boolean;
122
+ /**
123
+ * Indicates whether the call is in progress.
124
+ */
125
+ isLoading: boolean;
48
126
  };
49
127
  export interface UseSharedCallParameters<A, M extends FunctionName<A>> extends CallConfig {
50
128
  functionName: M;
51
129
  args?: ActorMethodParameters<A[M]>;
52
130
  onLoading?: (loading: boolean) => void;
53
- onError?: (error: Error | undefined) => void;
131
+ onError?: (error: AgentError | undefined) => void;
54
132
  onSuccess?: (data: ActorMethodReturnType<A[M]>) => void;
55
133
  onSuccessResult?: (value: ExtractOk<ActorMethodReturnType<A[M]>>) => void;
56
134
  onErrorResult?: (error: ExtractErr<ActorMethodReturnType<A[M]>>) => void;
57
135
  throwOnError?: boolean;
58
- compileResult?: boolean;
59
136
  }
60
137
  export interface UseSharedCallReturnType<A, M extends FunctionName<A> = FunctionName<A>> extends UseSharedCallState<A, M> {
61
138
  requestKey: string;
@@ -72,26 +149,59 @@ export interface UseQueryCallReturnType<A, M extends FunctionName<A>> extends Us
72
149
  refetch: () => void;
73
150
  }
74
151
  export type UseQueryCall<A> = <M extends FunctionName<A>>(params: UseQueryCallParameters<A, M>) => UseQueryCallReturnType<A, M>;
75
- export interface UseUpdateCallParameters<A, M extends FunctionName<A>> extends UseSharedCallParameters<A, M> {
76
- }
77
- export interface UseUpdateCallReturnType<A, M extends FunctionName<A>> extends UseSharedCallReturnType<A, M> {
78
- }
152
+ export type UseUpdateCallParameters<A, M extends FunctionName<A>> = UseSharedCallParameters<A, M>;
153
+ export type UseUpdateCallReturnType<A, M extends FunctionName<A>> = UseSharedCallReturnType<A, M>;
79
154
  export type UseUpdateCall<A> = <M extends FunctionName<A>>(params: UseUpdateCallParameters<A, M>) => UseUpdateCallReturnType<A, M>;
80
155
  export interface DynamicDataArgs<V = unknown> {
81
156
  label: string;
82
157
  value: V;
83
158
  }
84
- export interface UseMethodParameters<A, M extends FunctionName<A>> extends UseQueryCallParameters<A, M> {
85
- }
159
+ export type UseMethodParameters<A, M extends FunctionName<A>> = UseQueryCallParameters<A, M>;
86
160
  export interface UseMethodReturnType<A, M extends FunctionName<A> = FunctionName<A>> {
161
+ /**
162
+ * @deprecated Use `isLoading` instead.
163
+ * Indicates whether the method call is in progress.
164
+ */
87
165
  loading: boolean;
88
- formRequired: boolean;
166
+ /**
167
+ * Indicates whether the method call is in progress.
168
+ */
169
+ isLoading: boolean;
170
+ /**
171
+ * Indicates whether the argument form is required for the method.
172
+ */
173
+ isFormRequired: boolean;
174
+ /**
175
+ * A unique key representing the current request instance.
176
+ */
89
177
  requestKey: string;
90
- error: Error | undefined;
178
+ /**
179
+ * The error that occurred during the method call, if any.
180
+ */
181
+ error: AgentError | undefined;
182
+ /**
183
+ * The data returned from the method call, or `undefined` if not yet available.
184
+ */
91
185
  data: ActorMethodReturnType<A[M]> | undefined;
92
- validateArgs: (args?: ActorMethodParameters<A[M]> | undefined) => boolean;
186
+ /**
187
+ * Validates the provided arguments against the method signature.
188
+ * @param args Optional arguments for the method.
189
+ * @returns `true` if the arguments match the expected signature, otherwise `false`.
190
+ */
191
+ validateArgs: (args?: ActorMethodParameters<A[M]>) => boolean;
192
+ /**
193
+ * The visit service function corresponding to this method.
194
+ */
93
195
  visit: VisitService<A>[M];
196
+ /**
197
+ * Resets the method state (data, error, loading) to initial values.
198
+ */
94
199
  reset: () => void;
200
+ /**
201
+ * Invokes the method.
202
+ * @param eventOrReplaceArgs Either the arguments for the call or a React mouse event.
203
+ * @returns A promise resolving to the method's return data or `undefined`.
204
+ */
95
205
  call: (eventOrReplaceArgs?: ActorMethodParameters<A[M]> | React.MouseEvent) => Promise<ActorMethodReturnType<A[M]> | undefined>;
96
206
  }
97
207
  export type UseMethod<A> = <M extends FunctionName<A>>(args: UseMethodParameters<A, M>) => UseMethodReturnType<A, M>;
@@ -11,9 +11,9 @@ export interface UseActorManagerParameters<A> extends ActorReConfigParameters {
11
11
  }
12
12
  export interface UseActorReturn<A = BaseActor> {
13
13
  hooks: ActorHooksReturnType<A> | null;
14
- fetching: boolean;
14
+ isFetching: boolean;
15
15
  fetchError: string | null;
16
- authenticating: boolean;
16
+ isAuthenticating: boolean;
17
17
  initializeActor: InitializeActor;
18
18
  }
19
19
  export interface UseActorManagerReturn<A = BaseActor> {