@ic-reactor/react 1.7.7 → 1.7.9

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.
Files changed (81) hide show
  1. package/dist/context/actor/create.d.ts +63 -0
  2. package/dist/context/actor/create.js +106 -0
  3. package/dist/context/actor/hooks/useActorInterface.js +11 -0
  4. package/dist/{hooks/actor → context/actor/hooks}/useActorState.d.ts +1 -1
  5. package/dist/{hooks/actor → context/actor/hooks}/useActorState.js +2 -5
  6. package/dist/{hooks/actor → context/actor/hooks}/useActorStore.d.ts +1 -1
  7. package/dist/{hooks/actor → context/actor/hooks}/useActorStore.js +2 -5
  8. package/dist/{hooks/actor → context/actor/hooks}/useMethod.d.ts +1 -1
  9. package/dist/{hooks/actor → context/actor/hooks}/useMethod.js +2 -5
  10. package/dist/{hooks/actor → context/actor/hooks}/useMethodAttributes.d.ts +1 -1
  11. package/dist/{hooks/actor → context/actor/hooks}/useMethodAttributes.js +2 -5
  12. package/dist/{hooks/actor → context/actor/hooks}/useMethodNames.d.ts +1 -1
  13. package/dist/{hooks/actor → context/actor/hooks}/useMethodNames.js +2 -5
  14. package/dist/{hooks/actor → context/actor/hooks}/useQueryCall.d.ts +1 -1
  15. package/dist/{hooks/actor → context/actor/hooks}/useQueryCall.js +2 -5
  16. package/dist/{hooks/actor → context/actor/hooks}/useUpdateCall.d.ts +1 -1
  17. package/dist/{hooks/actor → context/actor/hooks}/useUpdateCall.js +2 -5
  18. package/dist/{hooks/actor → context/actor/hooks}/useVisitMethod.d.ts +1 -1
  19. package/dist/{hooks/actor → context/actor/hooks}/useVisitMethod.js +2 -5
  20. package/dist/{hooks/actor → context/actor/hooks}/useVisitService.d.ts +1 -1
  21. package/dist/{hooks/actor → context/actor/hooks}/useVisitService.js +2 -5
  22. package/dist/context/actor/index.d.ts +15 -63
  23. package/dist/context/actor/index.js +29 -103
  24. package/dist/{provider/actor.d.ts → context/actor/provider.d.ts} +2 -2
  25. package/dist/{provider/actor.js → context/actor/provider.js} +3 -6
  26. package/dist/context/actor/types.d.ts +1 -0
  27. package/dist/context/adapter/create.d.ts +2 -0
  28. package/dist/context/adapter/create.js +50 -0
  29. package/dist/{hooks/adapter → context/adapter/hooks}/useCandidAdapter.js +2 -5
  30. package/dist/context/adapter/index.d.ts +6 -2
  31. package/dist/context/adapter/index.js +20 -47
  32. package/dist/{provider/adapter.d.ts → context/adapter/provider.d.ts} +1 -1
  33. package/dist/{provider/adapter.js → context/adapter/provider.js} +2 -5
  34. package/dist/context/agent/create.d.ts +74 -0
  35. package/dist/context/agent/create.js +112 -0
  36. package/dist/{hooks/agent → context/agent/hooks}/useAgent.js +2 -5
  37. package/dist/{hooks/agent → context/agent/hooks}/useAgentManager.js +2 -5
  38. package/dist/{hooks/agent → context/agent/hooks}/useAgentState.js +2 -5
  39. package/dist/{hooks/agent → context/agent/hooks}/useAuth.d.ts +1 -1
  40. package/dist/{hooks/agent → context/agent/hooks}/useAuth.js +2 -5
  41. package/dist/{hooks/agent → context/agent/hooks}/useAuthState.js +2 -5
  42. package/dist/{hooks/agent → context/agent/hooks}/useUserPrincipal.js +2 -5
  43. package/dist/context/agent/index.d.ts +11 -74
  44. package/dist/context/agent/index.js +25 -109
  45. package/dist/{provider/agent.d.ts → context/agent/provider.d.ts} +1 -1
  46. package/dist/{provider/agent.js → context/agent/provider.js} +2 -5
  47. package/dist/hooks/index.d.ts +0 -3
  48. package/dist/hooks/index.js +0 -3
  49. package/dist/hooks/types.d.ts +2 -0
  50. package/dist/hooks/useActor.js +17 -11
  51. package/dist/index.d.ts +3 -2
  52. package/dist/index.js +3 -2
  53. package/dist/types.d.ts +2 -0
  54. package/dist/types.js +2 -0
  55. package/package.json +3 -3
  56. package/dist/context/index.d.ts +0 -3
  57. package/dist/context/index.js +0 -19
  58. package/dist/context/types.d.ts +0 -3
  59. package/dist/context/types.js +0 -19
  60. package/dist/hooks/actor/hooks.d.ts +0 -2
  61. package/dist/hooks/actor/hooks.js +0 -5
  62. package/dist/hooks/actor/index.d.ts +0 -10
  63. package/dist/hooks/actor/index.js +0 -26
  64. package/dist/hooks/actor/useActorInterface.js +0 -14
  65. package/dist/hooks/adapter/hooks.d.ts +0 -2
  66. package/dist/hooks/adapter/hooks.js +0 -5
  67. package/dist/hooks/adapter/index.d.ts +0 -1
  68. package/dist/hooks/adapter/index.js +0 -17
  69. package/dist/hooks/agent/hooks.d.ts +0 -2
  70. package/dist/hooks/agent/hooks.js +0 -5
  71. package/dist/hooks/agent/index.d.ts +0 -6
  72. package/dist/hooks/agent/index.js +0 -22
  73. package/dist/provider/index.d.ts +0 -3
  74. package/dist/provider/index.js +0 -19
  75. /package/dist/{hooks/actor → context/actor/hooks}/useActorInterface.d.ts +0 -0
  76. /package/dist/{hooks/adapter → context/adapter/hooks}/useCandidAdapter.d.ts +0 -0
  77. /package/dist/{hooks/agent → context/agent/hooks}/useAgent.d.ts +0 -0
  78. /package/dist/{hooks/agent → context/agent/hooks}/useAgentManager.d.ts +0 -0
  79. /package/dist/{hooks/agent → context/agent/hooks}/useAgentState.d.ts +0 -0
  80. /package/dist/{hooks/agent → context/agent/hooks}/useAuthState.d.ts +0 -0
  81. /package/dist/{hooks/agent → context/agent/hooks}/useUserPrincipal.d.ts +0 -0
@@ -0,0 +1,63 @@
1
+ import type { BaseActor } from "../../types";
2
+ import type { CreateActorContextParameters, CreateActorContextReturnType } from "./types";
3
+ /**
4
+ * Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
5
+ * This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
6
+ *
7
+ * @param reactorParameters A partial configuration object for the actor context, allowing customization and specification of actor-related settings.
8
+ * - `canisterId`: The default Canister ID to be used if not overridden in the `ActorProvider` component.
9
+ * - Other configurations can include properties related to the actor's interaction, such as agent options or authentication requirements.
10
+ *
11
+ * @returns An object containing the `ActorProvider` component and various hooks for interacting with the actor.
12
+ * - `ActorProvider`: A context provider component that allows child components to access and interact with the configured actor.
13
+ * - Hooks: Custom hooks derived from the actor context, facilitating interactions like querying or updating the actor's state.
14
+ *
15
+ * @example
16
+ * ```jsx
17
+ * import React from 'react';
18
+ * import { createActorContext } from '@ic-reactor/react';
19
+ * import { backend, canisterId, idlFactory } from './declarations/candid'; // Assuming 'declarations/candid' is where your actor interface is defined.
20
+ *
21
+ * // Initialize the actor context with configuration options
22
+ * const { ActorProvider, useActorState, useQueryCall, useUpdateCall } = createActorContext<typeof backend>({
23
+ * canisterId,
24
+ * idlFactory, // Optional, wrap the ActorProvider with CandidAdapterProvider
25
+ * });
26
+ *
27
+ * // A sample component that utilizes the actor context
28
+ * const App = () => (
29
+ * <AgentProvider>
30
+ * <ActorProvider>
31
+ * <div>
32
+ * <h1>IC Actor Interaction Example</h1>
33
+ * <ActorComponent />
34
+ * </div>
35
+ * </ActorProvider>
36
+ * </AgentProvider>
37
+ * );
38
+ *
39
+ * export default App;
40
+ *
41
+ * // A sample component that uses the actor hooks
42
+ * const ActorComponent = () => {
43
+ * const { data, loading, error } = useQueryCall({
44
+ * functionName: 'backendMethodName',
45
+ * args: [],
46
+ * refetchInterval: 10000,
47
+ * refetchOnMount: true,
48
+ * });
49
+
50
+ * return (
51
+ * <div>
52
+ * {loading && <p>Loading...</p>}
53
+ * {error && <p>Error: {error.message}</p>}
54
+ * {data && <p>Actor data: {data}</p>}
55
+ * </div>
56
+ * );
57
+ * };
58
+ * ```
59
+ *
60
+ * This function streamlines the process of setting up a context for IC actor interactions within a React app,
61
+ * it provides a type-safe and efficient way to manage actor state and interactions.
62
+ */
63
+ export declare function createActorContext<A = BaseActor>(contextConfig?: CreateActorContextParameters): CreateActorContextReturnType<A>;
@@ -0,0 +1,106 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.createActorContext = void 0;
18
+ const react_1 = __importDefault(require("react"));
19
+ const useActor_1 = require("../../hooks/useActor");
20
+ const extractActorContext_1 = require("../../helpers/extractActorContext");
21
+ /**
22
+ * Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
23
+ * This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
24
+ *
25
+ * @param reactorParameters A partial configuration object for the actor context, allowing customization and specification of actor-related settings.
26
+ * - `canisterId`: The default Canister ID to be used if not overridden in the `ActorProvider` component.
27
+ * - Other configurations can include properties related to the actor's interaction, such as agent options or authentication requirements.
28
+ *
29
+ * @returns An object containing the `ActorProvider` component and various hooks for interacting with the actor.
30
+ * - `ActorProvider`: A context provider component that allows child components to access and interact with the configured actor.
31
+ * - Hooks: Custom hooks derived from the actor context, facilitating interactions like querying or updating the actor's state.
32
+ *
33
+ * @example
34
+ * ```jsx
35
+ * import React from 'react';
36
+ * import { createActorContext } from '@ic-reactor/react';
37
+ * import { backend, canisterId, idlFactory } from './declarations/candid'; // Assuming 'declarations/candid' is where your actor interface is defined.
38
+ *
39
+ * // Initialize the actor context with configuration options
40
+ * const { ActorProvider, useActorState, useQueryCall, useUpdateCall } = createActorContext<typeof backend>({
41
+ * canisterId,
42
+ * idlFactory, // Optional, wrap the ActorProvider with CandidAdapterProvider
43
+ * });
44
+ *
45
+ * // A sample component that utilizes the actor context
46
+ * const App = () => (
47
+ * <AgentProvider>
48
+ * <ActorProvider>
49
+ * <div>
50
+ * <h1>IC Actor Interaction Example</h1>
51
+ * <ActorComponent />
52
+ * </div>
53
+ * </ActorProvider>
54
+ * </AgentProvider>
55
+ * );
56
+ *
57
+ * export default App;
58
+ *
59
+ * // A sample component that uses the actor hooks
60
+ * const ActorComponent = () => {
61
+ * const { data, loading, error } = useQueryCall({
62
+ * functionName: 'backendMethodName',
63
+ * args: [],
64
+ * refetchInterval: 10000,
65
+ * refetchOnMount: true,
66
+ * });
67
+
68
+ * return (
69
+ * <div>
70
+ * {loading && <p>Loading...</p>}
71
+ * {error && <p>Error: {error.message}</p>}
72
+ * {data && <p>Actor data: {data}</p>}
73
+ * </div>
74
+ * );
75
+ * };
76
+ * ```
77
+ *
78
+ * This function streamlines the process of setting up a context for IC actor interactions within a React app,
79
+ * it provides a type-safe and efficient way to manage actor state and interactions.
80
+ */
81
+ function createActorContext(contextConfig = {}) {
82
+ const { canisterId: defaultCanisterId } = contextConfig, defaultConfig = __rest(contextConfig, ["canisterId"]);
83
+ const ActorContext = react_1.default.createContext(null);
84
+ const ActorProvider = (_a) => {
85
+ var { children, canisterId = defaultCanisterId, loadingComponent = react_1.default.createElement("div", null, "Fetching canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "canisterId", "loadingComponent", "authenticatingComponent"]);
86
+ if (!canisterId) {
87
+ throw new Error("canisterId is required");
88
+ }
89
+ const config = react_1.default.useMemo(() => (Object.assign(Object.assign({}, defaultConfig), restConfig)), [defaultConfig, restConfig]);
90
+ const { fetchError, authenticating, hooks } = (0, useActor_1.useActor)(Object.assign({ canisterId }, config));
91
+ return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, hooks === null
92
+ ? fetchError
93
+ ? fetchError
94
+ : authenticating
95
+ ? authenticatingComponent
96
+ : loadingComponent
97
+ : children));
98
+ };
99
+ ActorProvider.displayName = "ActorProvider";
100
+ const ActorHookProvider = ({ hooks, children, }) => {
101
+ return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, children));
102
+ };
103
+ return Object.assign({ ActorProvider,
104
+ ActorHookProvider }, (0, extractActorContext_1.extractActorContext)(ActorContext));
105
+ }
106
+ exports.createActorContext = createActorContext;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useActorInterface = void 0;
4
+ const __1 = require("..");
5
+ /**
6
+ *
7
+ */
8
+ function useActorInterface() {
9
+ return __1.ActorHooks.useActorInterface();
10
+ }
11
+ exports.useActorInterface = useActorInterface;
@@ -18,4 +18,4 @@
18
18
  * }
19
19
  *```
20
20
  */
21
- export declare const useActorState: () => import("../../types").UseActorStateReturnType;
21
+ export declare const useActorState: () => import("../../../types").UseActorStateReturnType;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useActorState = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Hook for accessing the current state of the actor, including the canister ID.
10
7
  *
@@ -25,4 +22,4 @@ const hooks_1 = __importDefault(require("./hooks"));
25
22
  * }
26
23
  *```
27
24
  */
28
- exports.useActorState = hooks_1.default.useActorState;
25
+ exports.useActorState = __1.ActorHooks.useActorState;
@@ -29,4 +29,4 @@
29
29
  * @see ActorManager for more details about the architecture and management of actor stores.
30
30
  * @see ActorState for the structure and possible states an actor can hold.
31
31
  */
32
- export declare const useActorStore: import("../../types").UseActorStore<import("@ic-reactor/core/dist/types").BaseActor>;
32
+ export declare const useActorStore: import("../../../types").UseActorStore<import("@ic-reactor/core/dist/types").BaseActor>;
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useActorStore = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Provides a hook for accessing the state of an actor from the actor's store.
10
7
  * This hook is part of a set of utilities that facilitate interactions with
@@ -36,4 +33,4 @@ const hooks_1 = __importDefault(require("./hooks"));
36
33
  * @see ActorManager for more details about the architecture and management of actor stores.
37
34
  * @see ActorState for the structure and possible states an actor can hold.
38
35
  */
39
- exports.useActorStore = hooks_1.default.useActorStore;
36
+ exports.useActorStore = __1.ActorHooks.useActorStore;
@@ -1,4 +1,4 @@
1
- import { BaseActor, FunctionName, UseMethodParameters, UseMethodReturnType } from "../../types";
1
+ import type { BaseActor, FunctionName, UseMethodParameters, UseMethodReturnType } from "../../../types";
2
2
  /**
3
3
  * Hook for making dynamically update or query calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
4
4
  *
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useMethod = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Hook for making dynamically update or query calls to actors, handling loading states, and managing errors. It supports custom event handlers for loading, success, and error events.
10
7
  *
@@ -33,6 +30,6 @@ const hooks_1 = __importDefault(require("./hooks"));
33
30
  * ```
34
31
  */
35
32
  function useMethod(args) {
36
- return hooks_1.default.useMethod(args);
33
+ return __1.ActorHooks.useMethod(args);
37
34
  }
38
35
  exports.useMethod = useMethod;
@@ -1,4 +1,4 @@
1
- import type { BaseActor } from "../../types";
1
+ import type { BaseActor } from "../../../types";
2
2
  /**
3
3
  * Hook for accessing the method attributes of an actor.
4
4
  *
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useMethodAttributes = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Hook for accessing the method attributes of an actor.
10
7
  *
11
8
  * @returns An array of method attributes for the actor.
12
9
  */
13
- const useMethodAttributes = () => hooks_1.default.useMethodAttributes();
10
+ const useMethodAttributes = () => __1.ActorHooks.useMethodAttributes();
14
11
  exports.useMethodAttributes = useMethodAttributes;
@@ -1,4 +1,4 @@
1
- import type { BaseActor } from "../../types";
1
+ import type { BaseActor } from "../../../types";
2
2
  /**
3
3
  * Hook for accessing the method names of an actor.
4
4
  *
@@ -1,14 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useMethodNames = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Hook for accessing the method names of an actor.
10
7
  *
11
8
  * @returns An array of method names for the actor.
12
9
  */
13
- const useMethodNames = () => hooks_1.default.useMethodNames();
10
+ const useMethodNames = () => __1.ActorHooks.useMethodNames();
14
11
  exports.useMethodNames = useMethodNames;
@@ -1,4 +1,4 @@
1
- import { BaseActor, FunctionName, UseQueryCallParameters, UseSharedCallReturnType } from "../../types";
1
+ import type { BaseActor, FunctionName, UseQueryCallParameters, UseSharedCallReturnType } from "../../../types";
2
2
  /**
3
3
  * Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
4
4
  *
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useQueryCall = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Hook for making query calls to actors. It supports automatic refetching on component mount and at specified intervals.
10
7
  *
@@ -32,6 +29,6 @@ const hooks_1 = __importDefault(require("./hooks"));
32
29
  * ```
33
30
  */
34
31
  function useQueryCall(args) {
35
- return hooks_1.default.useQueryCall(args);
32
+ return __1.ActorHooks.useQueryCall(args);
36
33
  }
37
34
  exports.useQueryCall = useQueryCall;
@@ -1,4 +1,4 @@
1
- import type { BaseActor, FunctionName, UseUpdateCallParameters, UseSharedCallReturnType } from "../../types";
1
+ import type { BaseActor, FunctionName, UseUpdateCallParameters, UseSharedCallReturnType } from "../../../types";
2
2
  /**
3
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
4
  *
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useUpdateCall = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
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.
10
7
  *
@@ -33,6 +30,6 @@ const hooks_1 = __importDefault(require("./hooks"));
33
30
  * ```
34
31
  */
35
32
  function useUpdateCall(args) {
36
- return hooks_1.default.useUpdateCall(args);
33
+ return __1.ActorHooks.useUpdateCall(args);
37
34
  }
38
35
  exports.useUpdateCall = useUpdateCall;
@@ -1,4 +1,4 @@
1
- import type { BaseActor, FunctionName } from "../../types";
1
+ import type { FunctionName, BaseActor } from "../../../types";
2
2
  /**
3
3
  * Memoizes and returns a visit service function for a specific actor method.
4
4
  *
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useVisitMethod = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Memoizes and returns a visit service function for a specific actor method.
10
7
  *
@@ -12,6 +9,6 @@ const hooks_1 = __importDefault(require("./hooks"));
12
9
  * @returns The visit service function for the specified method.
13
10
  */
14
11
  function useVisitMethod(functionName) {
15
- return hooks_1.default.useVisitMethod(functionName);
12
+ return __1.ActorHooks.useVisitMethod(functionName);
16
13
  }
17
14
  exports.useVisitMethod = useVisitMethod;
@@ -1,4 +1,4 @@
1
- import type { BaseActor } from "../../types";
1
+ import type { BaseActor } from "../../../types";
2
2
  /**
3
3
  * Memoizes and returns a visit service function for a specific actor method.
4
4
  *
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.useVisitService = void 0;
7
- const hooks_1 = __importDefault(require("./hooks"));
4
+ const __1 = require("..");
8
5
  /**
9
6
  * Memoizes and returns a visit service function for a specific actor method.
10
7
  *
@@ -12,6 +9,6 @@ const hooks_1 = __importDefault(require("./hooks"));
12
9
  * @returns The visit service function for the specified method.
13
10
  */
14
11
  function useVisitService() {
15
- return hooks_1.default.useVisitService();
12
+ return __1.ActorHooks.useVisitService();
16
13
  }
17
14
  exports.useVisitService = useVisitService;
@@ -1,63 +1,15 @@
1
- import type { BaseActor } from "../../types";
2
- import type { CreateActorContextParameters, CreateActorContextReturnType } from "./types";
3
- /**
4
- * Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
5
- * This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
6
- *
7
- * @param reactorParameters A partial configuration object for the actor context, allowing customization and specification of actor-related settings.
8
- * - `canisterId`: The default Canister ID to be used if not overridden in the `ActorProvider` component.
9
- * - Other configurations can include properties related to the actor's interaction, such as agent options or authentication requirements.
10
- *
11
- * @returns An object containing the `ActorProvider` component and various hooks for interacting with the actor.
12
- * - `ActorProvider`: A context provider component that allows child components to access and interact with the configured actor.
13
- * - Hooks: Custom hooks derived from the actor context, facilitating interactions like querying or updating the actor's state.
14
- *
15
- * @example
16
- * ```jsx
17
- * import React from 'react';
18
- * import { createActorContext } from '@ic-reactor/react';
19
- * import { backend, canisterId, idlFactory } from './declarations/candid'; // Assuming 'declarations/candid' is where your actor interface is defined.
20
- *
21
- * // Initialize the actor context with configuration options
22
- * const { ActorProvider, useActorState, useQueryCall, useUpdateCall } = createActorContext<typeof backend>({
23
- * canisterId,
24
- * idlFactory, // Optional, wrap the ActorProvider with CandidAdapterProvider
25
- * });
26
- *
27
- * // A sample component that utilizes the actor context
28
- * const App = () => (
29
- * <AgentProvider>
30
- * <ActorProvider>
31
- * <div>
32
- * <h1>IC Actor Interaction Example</h1>
33
- * <ActorComponent />
34
- * </div>
35
- * </ActorProvider>
36
- * </AgentProvider>
37
- * );
38
- *
39
- * export default App;
40
- *
41
- * // A sample component that uses the actor hooks
42
- * const ActorComponent = () => {
43
- * const { data, loading, error } = useQueryCall({
44
- * functionName: 'backendMethodName',
45
- * args: [],
46
- * refetchInterval: 10000,
47
- * refetchOnMount: true,
48
- * });
49
-
50
- * return (
51
- * <div>
52
- * {loading && <p>Loading...</p>}
53
- * {error && <p>Error: {error.message}</p>}
54
- * {data && <p>Actor data: {data}</p>}
55
- * </div>
56
- * );
57
- * };
58
- * ```
59
- *
60
- * This function streamlines the process of setting up a context for IC actor interactions within a React app,
61
- * it provides a type-safe and efficient way to manage actor state and interactions.
62
- */
63
- export declare function createActorContext<A = BaseActor>(contextConfig?: CreateActorContextParameters): CreateActorContextReturnType<A>;
1
+ import { createActorContext } from "./create";
2
+ export { createActorContext };
3
+ /** @ignore */
4
+ export declare const ActorHooks: import("./types").CreateActorContextReturnType<import("@ic-reactor/core/dist/types").BaseActor>;
5
+ export * from "./provider";
6
+ export * from "./hooks/useMethodNames";
7
+ export * from "./hooks/useQueryCall";
8
+ export * from "./hooks/useUpdateCall";
9
+ export * from "./hooks/useMethodAttributes";
10
+ export * from "./hooks/useActorStore";
11
+ export * from "./hooks/useActorState";
12
+ export * from "./hooks/useVisitMethod";
13
+ export * from "./hooks/useVisitService";
14
+ export * from "./hooks/useActorInterface";
15
+ export * from "./hooks/useMethod";
@@ -1,106 +1,32 @@
1
1
  "use strict";
2
- var __rest = (this && this.__rest) || function (s, e) {
3
- var t = {};
4
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
- t[p] = s[p];
6
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
- t[p[i]] = s[p[i]];
10
- }
11
- return t;
12
- };
13
- var __importDefault = (this && this.__importDefault) || function (mod) {
14
- return (mod && mod.__esModule) ? mod : { "default": mod };
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
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.createActorContext = void 0;
18
- const react_1 = __importDefault(require("react"));
19
- const useActor_1 = require("../../hooks/useActor");
20
- const extractActorContext_1 = require("../../helpers/extractActorContext");
21
- /**
22
- * Creates a React context specifically designed for managing the state and interactions with an actor on the Internet Computer (IC) blockchain.
23
- * This context facilitates the dynamic creation and management of IC actors within React applications, leveraging the provided configuration options.
24
- *
25
- * @param reactorParameters A partial configuration object for the actor context, allowing customization and specification of actor-related settings.
26
- * - `canisterId`: The default Canister ID to be used if not overridden in the `ActorProvider` component.
27
- * - Other configurations can include properties related to the actor's interaction, such as agent options or authentication requirements.
28
- *
29
- * @returns An object containing the `ActorProvider` component and various hooks for interacting with the actor.
30
- * - `ActorProvider`: A context provider component that allows child components to access and interact with the configured actor.
31
- * - Hooks: Custom hooks derived from the actor context, facilitating interactions like querying or updating the actor's state.
32
- *
33
- * @example
34
- * ```jsx
35
- * import React from 'react';
36
- * import { createActorContext } from '@ic-reactor/react';
37
- * import { backend, canisterId, idlFactory } from './declarations/candid'; // Assuming 'declarations/candid' is where your actor interface is defined.
38
- *
39
- * // Initialize the actor context with configuration options
40
- * const { ActorProvider, useActorState, useQueryCall, useUpdateCall } = createActorContext<typeof backend>({
41
- * canisterId,
42
- * idlFactory, // Optional, wrap the ActorProvider with CandidAdapterProvider
43
- * });
44
- *
45
- * // A sample component that utilizes the actor context
46
- * const App = () => (
47
- * <AgentProvider>
48
- * <ActorProvider>
49
- * <div>
50
- * <h1>IC Actor Interaction Example</h1>
51
- * <ActorComponent />
52
- * </div>
53
- * </ActorProvider>
54
- * </AgentProvider>
55
- * );
56
- *
57
- * export default App;
58
- *
59
- * // A sample component that uses the actor hooks
60
- * const ActorComponent = () => {
61
- * const { data, loading, error } = useQueryCall({
62
- * functionName: 'backendMethodName',
63
- * args: [],
64
- * refetchInterval: 10000,
65
- * refetchOnMount: true,
66
- * });
67
-
68
- * return (
69
- * <div>
70
- * {loading && <p>Loading...</p>}
71
- * {error && <p>Error: {error.message}</p>}
72
- * {data && <p>Actor data: {data}</p>}
73
- * </div>
74
- * );
75
- * };
76
- * ```
77
- *
78
- * This function streamlines the process of setting up a context for IC actor interactions within a React app,
79
- * it provides a type-safe and efficient way to manage actor state and interactions.
80
- */
81
- function createActorContext(contextConfig = {}) {
82
- const { canisterId: defaultCanisterId } = contextConfig, defaultConfig = __rest(contextConfig, ["canisterId"]);
83
- const ActorContext = react_1.default.createContext(null);
84
- const ActorProvider = (_a) => {
85
- var { children, canisterId = defaultCanisterId, loadingComponent = react_1.default.createElement("div", null, "Fetching canister..."), authenticatingComponent = react_1.default.createElement("div", null, "Authenticating...") } = _a, restConfig = __rest(_a, ["children", "canisterId", "loadingComponent", "authenticatingComponent"]);
86
- if (!canisterId) {
87
- throw new Error("canisterId is required");
88
- }
89
- const config = react_1.default.useMemo(() => (Object.assign(Object.assign({}, defaultConfig), restConfig)), [defaultConfig, restConfig]);
90
- const { fetchError, authenticating, hooks } = (0, useActor_1.useActor)(Object.assign({ canisterId }, config));
91
- return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, hooks === null
92
- ? fetchError
93
- ? fetchError
94
- : authenticating
95
- ? authenticatingComponent
96
- : loadingComponent
97
- : children));
98
- };
99
- ActorProvider.displayName = "ActorProvider";
100
- const ActorHookProvider = ({ hooks, children, }) => {
101
- return (react_1.default.createElement(ActorContext.Provider, { value: hooks }, children));
102
- };
103
- return Object.assign({ ActorProvider,
104
- ActorHookProvider }, (0, extractActorContext_1.extractActorContext)(ActorContext));
105
- }
106
- exports.createActorContext = createActorContext;
17
+ exports.ActorHooks = exports.createActorContext = void 0;
18
+ const create_1 = require("./create");
19
+ Object.defineProperty(exports, "createActorContext", { enumerable: true, get: function () { return create_1.createActorContext; } });
20
+ /** @ignore */
21
+ exports.ActorHooks = (0, create_1.createActorContext)();
22
+ __exportStar(require("./provider"), exports);
23
+ __exportStar(require("./hooks/useMethodNames"), exports);
24
+ __exportStar(require("./hooks/useQueryCall"), exports);
25
+ __exportStar(require("./hooks/useUpdateCall"), exports);
26
+ __exportStar(require("./hooks/useMethodAttributes"), exports);
27
+ __exportStar(require("./hooks/useActorStore"), exports);
28
+ __exportStar(require("./hooks/useActorState"), exports);
29
+ __exportStar(require("./hooks/useVisitMethod"), exports);
30
+ __exportStar(require("./hooks/useVisitService"), exports);
31
+ __exportStar(require("./hooks/useActorInterface"), exports);
32
+ __exportStar(require("./hooks/useMethod"), exports);