@ic-reactor/core 1.0.3 → 1.0.5

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 CHANGED
@@ -203,7 +203,7 @@ const { agentManager, callMethod } = createReactorStore<Candid>({
203
203
 
204
204
  // Usage example
205
205
  await agentManager.authenticate()
206
- const authClient = agentManager.getAuthClient()
206
+ const authClient = agentManager.getAuth()
207
207
 
208
208
  authClient?.login({
209
209
  onSuccess: () => {
@@ -1,6 +1,6 @@
1
- import type { CanisterId, ActorMethodArgs, ActorMethodReturnType, ActorStore, ActorManagerOptions, FunctionName, VisitService, BaseActor, ActorMethodState } from "./types";
1
+ import type { CanisterId, ActorMethodParameters, ActorMethodReturnType, ActorStore, ActorManagerParameters, FunctionName, VisitService, BaseActor, ActorMethodState } from "./types";
2
2
  import type { AgentManager } from "../agent";
3
- import type { UpdateAgentOptions } from "../types";
3
+ import type { UpdateAgentParameters } from "../../types";
4
4
  export declare class ActorManager<A = BaseActor> {
5
5
  private _actor;
6
6
  private _idlFactory;
@@ -15,11 +15,11 @@ export declare class ActorManager<A = BaseActor> {
15
15
  loading: boolean;
16
16
  error: Error | undefined;
17
17
  }>) => void;
18
- constructor(actorConfig: ActorManagerOptions);
19
- initialize: (options?: UpdateAgentOptions) => Promise<void>;
18
+ constructor(actorConfig: ActorManagerParameters);
19
+ initialize: (options?: UpdateAgentParameters) => Promise<void>;
20
20
  extractService(): VisitService<A>;
21
21
  private initializeActor;
22
- callMethod: <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodArgs<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
22
+ callMethod: <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
23
23
  get agentManager(): AgentManager;
24
24
  getActor: () => A | null;
25
25
  getState: ActorStore<A>["getState"];
@@ -12,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.ActorManager = void 0;
13
13
  /* eslint-disable no-console */
14
14
  const agent_1 = require("@dfinity/agent");
15
- const helper_1 = require("../tools/helper");
15
+ const helper_1 = require("../../tools/helper");
16
16
  const candid_1 = require("@dfinity/candid");
17
17
  class ActorManager {
18
18
  constructor(actorConfig) {
@@ -1,15 +1,15 @@
1
1
  import type { IDL } from "@dfinity/candid";
2
2
  import type { StoreApi } from "zustand";
3
3
  import type { AgentManager } from "../agent";
4
- import type { ActorMethod, ActorSubclass, Principal } from "../types";
4
+ import type { ActorMethod, ActorSubclass, Principal } from "../../types";
5
5
  export interface DefaultActorType {
6
6
  [key: string]: ActorMethod;
7
7
  }
8
8
  export type BaseActor<T = DefaultActorType> = ActorSubclass<T>;
9
- export type FunctionName<A = BaseActor> = keyof A & string;
9
+ export type FunctionName<A = BaseActor> = Extract<keyof A, string>;
10
10
  export type FunctionType = "query" | "update";
11
11
  export type CanisterId = string | Principal;
12
- export interface ActorManagerOptions {
12
+ export interface ActorManagerParameters {
13
13
  agentManager: AgentManager;
14
14
  idlFactory: IDL.InterfaceFactory;
15
15
  canisterId: CanisterId;
@@ -24,7 +24,7 @@ export type VisitorType<V> = V extends IDL.Visitor<infer D, infer R> ? {
24
24
  export type VisitService<A = BaseActor, M extends FunctionName<A> = FunctionName<A>> = {
25
25
  [K in M]: <V extends IDL.Visitor<unknown, unknown>>(extractorClass: V, data?: VisitorType<V>["data"]) => ReturnType<V["visitFunc"]>;
26
26
  };
27
- export type ActorMethodArgs<T> = T extends ActorMethod<infer Args, any> ? Args : never;
27
+ export type ActorMethodParameters<T> = T extends ActorMethod<infer Args, any> ? Args : never;
28
28
  export type ActorMethodReturnType<T> = T extends ActorMethod<any, infer Ret> ? Ret : never;
29
29
  export interface ActorMethodState<A = BaseActor, M extends FunctionName<A> = FunctionName<A>> {
30
30
  [key: string]: {
@@ -43,4 +43,4 @@ export type ActorState<A = BaseActor> = {
43
43
  methodState: ActorMethodStates<A>;
44
44
  };
45
45
  export type ActorStore<A = BaseActor> = StoreApi<ActorState<A>>;
46
- export type CallActorMethod<A = BaseActor> = <M extends FunctionName<A> = FunctionName<A>>(functionName: M, ...args: ActorMethodArgs<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
46
+ export type CallActorMethod<A = BaseActor> = <M extends FunctionName<A> = FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
@@ -1,7 +1,8 @@
1
1
  import { HttpAgent } from "@dfinity/agent";
2
- import type { AgentStore, AgentManagerOptions, UpdateAgentOptions, AuthStore } from "./types";
2
+ import type { AgentStore, AgentManagerParameters, UpdateAgentParameters, AuthStore, AuthClient } from "./types";
3
3
  export declare class AgentManager {
4
4
  private _agent;
5
+ private _auth;
5
6
  private _subscribers;
6
7
  agentStore: AgentStore;
7
8
  authStore: AuthStore;
@@ -10,19 +11,19 @@ export declare class AgentManager {
10
11
  private initialAuthState;
11
12
  private updateAgentState;
12
13
  private updateAuthState;
13
- constructor(options?: AgentManagerOptions);
14
+ constructor(options?: AgentManagerParameters);
14
15
  private initializeAgent;
15
16
  subscribeAgent: (callback: (agent: HttpAgent) => void) => () => void;
16
17
  unsubscribeAgent: (callback: (agent: HttpAgent) => void) => void;
17
18
  private notifySubscribers;
18
- updateAgent: (options?: UpdateAgentOptions) => Promise<void>;
19
+ updateAgent: (options?: UpdateAgentParameters) => Promise<void>;
19
20
  authenticate: () => Promise<import("@dfinity/agent").Identity>;
20
21
  getAgent: () => HttpAgent;
21
22
  getAgentState: AgentStore["getState"];
22
23
  subscribeAgentState: AgentStore["subscribe"];
23
24
  getAuthState: AuthStore["getState"];
24
25
  subscribeAuthState: AuthStore["subscribe"];
25
- getAuthClient: () => import("@dfinity/auth-client").AuthClient | null;
26
+ getAuth: () => AuthClient | null;
26
27
  getIdentity: () => import("@dfinity/agent").Identity | null;
27
28
  getPrincipal: () => import("@dfinity/principal").Principal | null;
28
29
  }
@@ -45,10 +45,11 @@ var __rest = (this && this.__rest) || function (s, e) {
45
45
  Object.defineProperty(exports, "__esModule", { value: true });
46
46
  exports.AgentManager = void 0;
47
47
  const agent_1 = require("@dfinity/agent");
48
- const helper_1 = require("../tools/helper");
49
- const constants_1 = require("../tools/constants");
48
+ const helper_1 = require("../../tools/helper");
49
+ const constants_1 = require("../../tools/constants");
50
50
  class AgentManager {
51
51
  constructor(options) {
52
+ this._auth = null;
52
53
  this._subscribers = [];
53
54
  this.initialAgentState = {
54
55
  initialized: false,
@@ -57,7 +58,6 @@ class AgentManager {
57
58
  };
58
59
  this.initialAuthState = {
59
60
  identity: null,
60
- authClient: null,
61
61
  authenticating: false,
62
62
  authenticated: false,
63
63
  error: undefined,
@@ -110,13 +110,12 @@ class AgentManager {
110
110
  console.error("Failed to import @dfinity/auth-client:", error);
111
111
  throw new Error("Authentication failed: @dfinity/auth-client package is missing.");
112
112
  });
113
- const authClient = yield AuthClient.create();
114
- const authenticated = yield authClient.isAuthenticated();
115
- const identity = authClient.getIdentity();
113
+ this._auth = yield AuthClient.create();
114
+ const authenticated = yield this._auth.isAuthenticated();
115
+ const identity = this._auth.getIdentity();
116
116
  this._agent.replaceIdentity(identity);
117
117
  this.notifySubscribers();
118
118
  this.updateAuthState({
119
- authClient,
120
119
  authenticated,
121
120
  identity,
122
121
  authenticating: false,
@@ -145,8 +144,8 @@ class AgentManager {
145
144
  this.subscribeAuthState = (listener) => {
146
145
  return this.authStore.subscribe(listener);
147
146
  };
148
- this.getAuthClient = () => {
149
- return this.authStore.getState().authClient;
147
+ this.getAuth = () => {
148
+ return this._auth;
150
149
  };
151
150
  this.getIdentity = () => {
152
151
  return this.authStore.getState().identity;
@@ -155,7 +154,7 @@ class AgentManager {
155
154
  const identity = this.authStore.getState().identity;
156
155
  return identity ? identity.getPrincipal() : null;
157
156
  };
158
- const _a = options || {}, { withDevtools, port = 4943, isLocalEnv, host: optionHost } = _a, agentOptions = __rest(_a, ["withDevtools", "port", "isLocalEnv", "host"]);
157
+ const _a = options || {}, { withDevtools, port = 4943, isLocalEnv, host: optionHost } = _a, agentParameters = __rest(_a, ["withDevtools", "port", "isLocalEnv", "host"]);
159
158
  const host = isLocalEnv
160
159
  ? `http://127.0.0.1:${port}`
161
160
  : optionHost
@@ -171,7 +170,7 @@ class AgentManager {
171
170
  withDevtools,
172
171
  store: "auth",
173
172
  });
174
- this._agent = new agent_1.HttpAgent(Object.assign(Object.assign({}, agentOptions), { host }));
173
+ this._agent = new agent_1.HttpAgent(Object.assign(Object.assign({}, agentParameters), { host }));
175
174
  this.isLocalEnv = this._agent.isLocal();
176
175
  this.initializeAgent();
177
176
  }
@@ -2,7 +2,7 @@ import type { HttpAgent, HttpAgentOptions, Identity } from "@dfinity/agent";
2
2
  import type { AuthClient } from "@dfinity/auth-client";
3
3
  import type { StoreApi } from "zustand";
4
4
  export { HttpAgentOptions, AuthClient, Identity };
5
- export interface AgentManagerOptions extends HttpAgentOptions {
5
+ export interface AgentManagerParameters extends HttpAgentOptions {
6
6
  port?: number;
7
7
  isLocalEnv?: boolean;
8
8
  withDevtools?: boolean;
@@ -14,12 +14,11 @@ export interface AgentState {
14
14
  }
15
15
  export interface AuthState {
16
16
  identity: Identity | null;
17
- authClient: AuthClient | null;
18
17
  authenticating: boolean;
19
18
  authenticated: boolean;
20
19
  error: Error | undefined;
21
20
  }
22
- export interface UpdateAgentOptions extends HttpAgentOptions {
21
+ export interface UpdateAgentParameters extends HttpAgentOptions {
23
22
  agent?: HttpAgent;
24
23
  }
25
24
  export type AgentStore = StoreApi<AgentState>;
@@ -1,9 +1,9 @@
1
1
  import { HttpAgent } from "@dfinity/agent";
2
- import type { CanisterId, CandidAdapterOptions, CandidDefenition } from "../types";
2
+ import type { CanisterId, CandidAdapterParameters, CandidDefenition } from "../../types";
3
3
  export declare class CandidAdapter {
4
4
  agent: HttpAgent;
5
5
  didjsCanisterId: string;
6
- constructor({ agentManager, agent, didjsCanisterId }: CandidAdapterOptions);
6
+ constructor({ agentManager, agent, didjsCanisterId, }: CandidAdapterParameters);
7
7
  private getDefaultDidJsId;
8
8
  getCandidDefinition(canisterId: CanisterId): Promise<CandidDefenition>;
9
9
  getFromMetadata(canisterId: CanisterId): Promise<CandidDefenition | undefined>;
@@ -12,9 +12,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.CandidAdapter = void 0;
13
13
  const agent_1 = require("@dfinity/agent");
14
14
  const principal_1 = require("@dfinity/principal");
15
- const constants_1 = require("../tools/constants");
15
+ const constants_1 = require("../../tools/constants");
16
16
  class CandidAdapter {
17
- constructor({ agentManager, agent, didjsCanisterId }) {
17
+ constructor({ agentManager, agent, didjsCanisterId, }) {
18
18
  if (agent) {
19
19
  this.agent = agent;
20
20
  }
@@ -1,6 +1,6 @@
1
1
  import type { AgentManager } from "../agent";
2
- import type { IDL, HttpAgent } from "../types";
3
- export interface CandidAdapterOptions {
2
+ import type { IDL, HttpAgent } from "../../types";
3
+ export interface CandidAdapterParameters {
4
4
  agentManager?: AgentManager;
5
5
  agent?: HttpAgent;
6
6
  didjsCanisterId?: string;
@@ -0,0 +1,3 @@
1
+ export * from "./actor";
2
+ export * from "./agent";
3
+ export * from "./candid";
@@ -0,0 +1,19 @@
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("./actor"), exports);
18
+ __exportStar(require("./agent"), exports);
19
+ __exportStar(require("./candid"), exports);
package/dist/index.d.ts CHANGED
@@ -1,8 +1,6 @@
1
1
  export * from "./main";
2
2
  export * from "./store";
3
3
  export * from "./other";
4
- export * from "./actor";
5
- export * from "./agent";
6
- export * from "./candid";
4
+ export * as classes from "./classes";
7
5
  export * as types from "./types";
8
6
  export * as tools from "./tools";
package/dist/index.js CHANGED
@@ -26,12 +26,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
26
26
  return result;
27
27
  };
28
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.tools = exports.types = void 0;
29
+ exports.tools = exports.types = exports.classes = void 0;
30
30
  __exportStar(require("./main"), exports);
31
31
  __exportStar(require("./store"), exports);
32
32
  __exportStar(require("./other"), exports);
33
- __exportStar(require("./actor"), exports);
34
- __exportStar(require("./agent"), exports);
35
- __exportStar(require("./candid"), exports);
33
+ exports.classes = __importStar(require("./classes"));
36
34
  exports.types = __importStar(require("./types"));
37
35
  exports.tools = __importStar(require("./tools"));
package/dist/main.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { BaseActor, ReactorCore, CreateReactorOptions } from "./types";
1
+ import type { BaseActor, CreateReactorCoreParameters, CreateReactorCoreReturnType } from "./types";
2
2
  /**
3
3
  * The Core module is the main entry point for the library.
4
4
  * Create a new actor manager with the given options.
@@ -7,4 +7,4 @@ import type { BaseActor, ReactorCore, CreateReactorOptions } from "./types";
7
7
  * @category Main
8
8
  * @includeExample ./packages/core/README.md:26-80
9
9
  */
10
- export declare const createReactorCore: <A = BaseActor>({ isLocalEnv, withProcessEnv, ...options }: CreateReactorOptions) => ReactorCore<A>;
10
+ export declare const createReactorCore: <A = BaseActor>(config: CreateReactorCoreParameters) => CreateReactorCoreReturnType<A>;
package/dist/main.js CHANGED
@@ -32,11 +32,9 @@ const store_1 = require("./store");
32
32
  * @category Main
33
33
  * @includeExample ./packages/core/README.md:26-80
34
34
  */
35
- const createReactorCore = (_a) => {
36
- var { isLocalEnv, withProcessEnv = false } = _a, options = __rest(_a, ["isLocalEnv", "withProcessEnv"]);
37
- isLocalEnv = isLocalEnv || (withProcessEnv ? (0, tools_1.isInLocalOrDevelopment)() : false);
38
- const _b = (0, store_1.createReactorStore)(Object.assign({ isLocalEnv }, options)), { subscribeActorState, updateMethodState, callMethod, getState, agentManager } = _b, rest = __rest(_b, ["subscribeActorState", "updateMethodState", "callMethod", "getState", "agentManager"]);
39
- const reActorMethod = (functionName, ...args) => {
35
+ const createReactorCore = (config) => {
36
+ const _a = (0, store_1.createReactorStore)(config), { subscribeActorState, updateMethodState, callMethod, getState, agentManager } = _a, rest = __rest(_a, ["subscribeActorState", "updateMethodState", "callMethod", "getState", "agentManager"]);
37
+ const actorMethod = (functionName, ...args) => {
40
38
  const requestHash = (0, tools_1.generateRequestHash)(args);
41
39
  const updateState = (newState = {}) => {
42
40
  updateMethodState(functionName, requestHash, newState);
@@ -101,7 +99,7 @@ const createReactorCore = (_a) => {
101
99
  };
102
100
  const queryCall = ({ functionName, args = [], refetchOnMount = true, refetchInterval = false, }) => {
103
101
  let intervalId = null;
104
- const _a = reActorMethod(functionName, ...args), { call } = _a, rest = __rest(_a, ["call"]);
102
+ const _a = actorMethod(functionName, ...args), { call } = _a, rest = __rest(_a, ["call"]);
105
103
  if (refetchInterval) {
106
104
  intervalId = setInterval(() => {
107
105
  call();
@@ -113,22 +111,22 @@ const createReactorCore = (_a) => {
113
111
  return Object.assign(Object.assign({}, rest), { call, dataPromise, intervalId });
114
112
  };
115
113
  const updateCall = ({ functionName, args = [] }) => {
116
- return reActorMethod(functionName, ...args);
114
+ return actorMethod(functionName, ...args);
117
115
  };
118
116
  const login = (options) => __awaiter(void 0, void 0, void 0, function* () {
119
- const authClient = agentManager.getAuthClient();
117
+ const authClient = agentManager.getAuth();
120
118
  if (!authClient) {
121
119
  yield agentManager.authenticate();
122
120
  }
123
121
  if (!authClient) {
124
122
  throw new Error("Auth client not initialized");
125
123
  }
126
- yield authClient.login(Object.assign({ identityProvider: isLocalEnv
124
+ yield authClient.login(Object.assign({ identityProvider: agentManager.isLocalEnv
127
125
  ? constants_1.IC_INTERNET_IDENTITY_PROVIDER
128
126
  : constants_1.LOCAL_INTERNET_IDENTITY_PROVIDER }, options));
129
127
  });
130
128
  const logout = (options) => __awaiter(void 0, void 0, void 0, function* () {
131
- const authClient = agentManager.getAuthClient();
129
+ const authClient = agentManager.getAuth();
132
130
  if (!authClient) {
133
131
  throw new Error("Auth client not initialized");
134
132
  }
package/dist/other.d.ts CHANGED
@@ -1,7 +1,7 @@
1
- import { ActorManager } from "./actor";
2
- import { AgentManager } from "./agent";
3
- import { CandidAdapter } from "./candid";
4
- import { ActorManagerOptions, AgentManagerOptions, BaseActor, CandidAdapterOptions } from "./types";
1
+ import { ActorManager } from "./classes/actor";
2
+ import { AgentManager } from "./classes/agent";
3
+ import { CandidAdapter } from "./classes/candid";
4
+ import { CandidAdapterParameters, ActorManagerParameters, AgentManagerParameters, BaseActor } from "./types";
5
5
  /**
6
6
  * The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
7
7
  * It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
@@ -10,7 +10,7 @@ import { ActorManagerOptions, AgentManagerOptions, BaseActor, CandidAdapterOptio
10
10
  * @category Main
11
11
  * @includeExample ./packages/core/README.md:145-186
12
12
  */
13
- export declare const createCandidAdapter: (options: CandidAdapterOptions) => CandidAdapter;
13
+ export declare const createCandidAdapter: (config: CandidAdapterParameters) => CandidAdapter;
14
14
  /**
15
15
  * Agent manager handles the lifecycle of the `@dfinity/agent`.
16
16
  * It is responsible for creating agent and managing the agent's state.
@@ -20,7 +20,7 @@ export declare const createCandidAdapter: (options: CandidAdapterOptions) => Can
20
20
  * @category Main
21
21
  * @includeExample ./packages/core/README.md:226-254
22
22
  */
23
- export declare const createAgentManager: (options?: AgentManagerOptions) => AgentManager;
23
+ export declare const createAgentManager: (config?: AgentManagerParameters) => AgentManager;
24
24
  /**
25
25
  * Actor manager handles the lifecycle of the actors.
26
26
  * It is responsible for creating and managing the actors.
@@ -30,4 +30,4 @@ export declare const createAgentManager: (options?: AgentManagerOptions) => Agen
30
30
  * @category Main
31
31
  * @includeExample ./packages/core/README.md:262-277
32
32
  */
33
- export declare const createActorManager: <A = BaseActor>(options: ActorManagerOptions) => ActorManager<A>;
33
+ export declare const createActorManager: <A = BaseActor>(config: ActorManagerParameters) => ActorManager<A>;
package/dist/other.js CHANGED
@@ -1,9 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.createActorManager = exports.createAgentManager = exports.createCandidAdapter = void 0;
4
- const actor_1 = require("./actor");
5
- const agent_1 = require("./agent");
6
- const candid_1 = require("./candid");
4
+ const actor_1 = require("./classes/actor");
5
+ const agent_1 = require("./classes/agent");
6
+ const candid_1 = require("./classes/candid");
7
7
  /**
8
8
  * The `CandidAdapter` class is used to interact with a canister and retrieve its Candid interface definition.
9
9
  * It provides methods to fetch the Candid definition either from the canister's metadata or by using a temporary hack method.
@@ -12,8 +12,8 @@ const candid_1 = require("./candid");
12
12
  * @category Main
13
13
  * @includeExample ./packages/core/README.md:145-186
14
14
  */
15
- const createCandidAdapter = (options) => {
16
- return new candid_1.CandidAdapter(options);
15
+ const createCandidAdapter = (config) => {
16
+ return new candid_1.CandidAdapter(config);
17
17
  };
18
18
  exports.createCandidAdapter = createCandidAdapter;
19
19
  /**
@@ -25,8 +25,8 @@ exports.createCandidAdapter = createCandidAdapter;
25
25
  * @category Main
26
26
  * @includeExample ./packages/core/README.md:226-254
27
27
  */
28
- const createAgentManager = (options) => {
29
- return new agent_1.AgentManager(options);
28
+ const createAgentManager = (config) => {
29
+ return new agent_1.AgentManager(config);
30
30
  };
31
31
  exports.createAgentManager = createAgentManager;
32
32
  /**
@@ -38,7 +38,7 @@ exports.createAgentManager = createAgentManager;
38
38
  * @category Main
39
39
  * @includeExample ./packages/core/README.md:262-277
40
40
  */
41
- const createActorManager = (options) => {
42
- return new actor_1.ActorManager(options);
41
+ const createActorManager = (config) => {
42
+ return new actor_1.ActorManager(config);
43
43
  };
44
44
  exports.createActorManager = createActorManager;
package/dist/store.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { ActorManager } from "./actor";
2
- import type { BaseActor, CreateReactorStoreOptions } from "./types";
1
+ import { ActorManager } from "./classes/actor";
2
+ import type { BaseActor, CreateReactorStoreParameters } from "./types";
3
3
  /**
4
4
  * Create a new actor manager with the given options.
5
5
  * Its create a new agent manager if not provided.
@@ -8,4 +8,4 @@ import type { BaseActor, CreateReactorStoreOptions } from "./types";
8
8
  * @category Main
9
9
  * @includeExample ./packages/core/README.md:194-220
10
10
  */
11
- export declare const createReactorStore: <A = BaseActor>(options: CreateReactorStoreOptions) => ActorManager<A>;
11
+ export declare const createReactorStore: <A = BaseActor>(config: CreateReactorStoreParameters) => ActorManager<A>;
package/dist/store.js CHANGED
@@ -13,6 +13,7 @@ var __rest = (this && this.__rest) || function (s, e) {
13
13
  Object.defineProperty(exports, "__esModule", { value: true });
14
14
  exports.createReactorStore = void 0;
15
15
  const other_1 = require("./other");
16
+ const tools_1 = require("./tools");
16
17
  /**
17
18
  * Create a new actor manager with the given options.
18
19
  * Its create a new agent manager if not provided.
@@ -21,10 +22,14 @@ const other_1 = require("./other");
21
22
  * @category Main
22
23
  * @includeExample ./packages/core/README.md:194-220
23
24
  */
24
- const createReactorStore = (options) => {
25
- const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager } = options, agentOptions = __rest(options, ["idlFactory", "canisterId", "withDevtools", "initializeOnCreate", "withVisitor", "agentManager"]);
25
+ const createReactorStore = (config) => {
26
+ const isLocalEnv = config.withProcessEnv
27
+ ? (0, tools_1.isInLocalOrDevelopment)()
28
+ : undefined;
29
+ const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager } = config, agentParameters = __rest(config, ["idlFactory", "canisterId", "withDevtools", "initializeOnCreate", "withVisitor", "agentManager"]);
26
30
  const agentManager = maybeAgentManager ||
27
- (0, other_1.createAgentManager)(Object.assign({ withDevtools }, agentOptions));
31
+ (0, other_1.createAgentManager)(Object.assign({ withDevtools,
32
+ isLocalEnv }, agentParameters));
28
33
  const actorManager = (0, other_1.createActorManager)({
29
34
  idlFactory,
30
35
  canisterId,
@@ -1,9 +1,9 @@
1
- import { BaseActor } from "../types";
2
- interface StoreOptions {
1
+ import type { BaseActor } from "../types";
2
+ interface StoreParameters {
3
3
  withDevtools?: boolean;
4
4
  store: string;
5
5
  }
6
- export declare function createStoreWithOptionalDevtools<T>(initialState: T, options: StoreOptions): Omit<import("zustand/vanilla").StoreApi<T>, "setState"> & {
6
+ export declare function createStoreWithOptionalDevtools<T>(initialState: T, config: StoreParameters): Omit<import("zustand/vanilla").StoreApi<T>, "setState"> & {
7
7
  setState<A extends string | {
8
8
  type: string;
9
9
  }>(partial: T | Partial<T> | ((state: T) => T | Partial<T>), replace?: boolean | undefined, action?: A | undefined): void;
@@ -5,11 +5,11 @@ const agent_1 = require("@dfinity/agent");
5
5
  const candid_1 = require("@dfinity/candid");
6
6
  const middleware_1 = require("zustand/middleware");
7
7
  const vanilla_1 = require("zustand/vanilla");
8
- function createStoreWithOptionalDevtools(initialState, options) {
9
- if (options.withDevtools) {
8
+ function createStoreWithOptionalDevtools(initialState, config) {
9
+ if (config.withDevtools) {
10
10
  return (0, vanilla_1.createStore)((0, middleware_1.devtools)(() => initialState, {
11
11
  name: "Reactor",
12
- store: options.store,
12
+ store: config.store,
13
13
  }));
14
14
  }
15
15
  else {
package/dist/types.d.ts CHANGED
@@ -2,19 +2,18 @@
2
2
  import type { ActorMethod, ActorSubclass, HttpAgentOptions, HttpAgent, Identity } from "@dfinity/agent";
3
3
  import type { Principal } from "@dfinity/principal";
4
4
  import type { IDL } from "@dfinity/candid";
5
- import type { ActorManager } from "./actor";
6
- import type { ActorManagerOptions, ActorMethodArgs, ActorMethodReturnType, ActorMethodState, BaseActor, FunctionName } from "./actor/types";
7
- import type { AgentManager } from "./agent";
5
+ import type { ActorManagerParameters, ActorMethodParameters, ActorMethodReturnType, ActorMethodState, BaseActor, FunctionName } from "./classes/actor/types";
6
+ import type { ActorManager } from "./classes/actor";
7
+ import type { AgentManager } from "./classes/agent";
8
8
  import type { AuthClientLoginOptions } from "@dfinity/auth-client";
9
- export * from "./agent/types";
10
- export * from "./actor/types";
11
- export * from "./candid/types";
12
- export type { ActorMethod, HttpAgentOptions, ActorSubclass, Principal, HttpAgent, Identity, IDL, };
13
- export interface CreateReactorOptions extends CreateReactorStoreOptions {
14
- withProcessEnv?: boolean;
15
- }
16
- export interface CreateReactorStoreOptions extends HttpAgentOptions, Omit<ActorManagerOptions, "agentManager"> {
9
+ export * from "./classes/agent/types";
10
+ export * from "./classes/actor/types";
11
+ export * from "./classes/candid/types";
12
+ export type { ActorManager, AgentManager };
13
+ export type { ActorMethod, AuthClientLoginOptions, HttpAgentOptions, ActorSubclass, Principal, HttpAgent, Identity, IDL, };
14
+ export interface CreateReactorStoreParameters extends HttpAgentOptions, Omit<ActorManagerParameters, "agentManager"> {
17
15
  agentManager?: AgentManager;
16
+ withProcessEnv?: boolean;
18
17
  isLocalEnv?: boolean;
19
18
  port?: number;
20
19
  }
@@ -25,8 +24,8 @@ export type ActorGetStateFunction<A, M extends FunctionName<A>> = {
25
24
  (): ActorMethodState<A, M>[string];
26
25
  };
27
26
  export type ActorSubscribeFunction<A, M extends FunctionName<A>> = (callback: (state: ActorMethodState<A, M>[string]) => void) => () => void;
28
- export type ActorCallFunction<A, M extends FunctionName<A>> = (replaceArgs?: ActorMethodArgs<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
29
- export type ActorQueryReturn<A, M extends FunctionName<A>> = {
27
+ export type ActorCallFunction<A, M extends FunctionName<A>> = (replaceArgs?: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
28
+ export type ActorQueryReturnType<A, M extends FunctionName<A>> = {
30
29
  intervalId: NodeJS.Timeout | null;
31
30
  requestHash: string;
32
31
  getState: ActorGetStateFunction<A, M>;
@@ -34,28 +33,31 @@ export type ActorQueryReturn<A, M extends FunctionName<A>> = {
34
33
  call: ActorCallFunction<A, M>;
35
34
  dataPromise: Promise<ActorMethodReturnType<A[M]>>;
36
35
  };
37
- export type ActorUpdateReturn<A, M extends FunctionName<A>> = {
36
+ export type ActorUpdateReturnType<A, M extends FunctionName<A>> = {
38
37
  requestHash: string;
39
38
  getState: ActorGetStateFunction<A, M>;
40
39
  subscribe: ActorSubscribeFunction<A, M>;
41
40
  call: ActorCallFunction<A, M>;
42
41
  };
43
- export type ActorQueryArgs<A, M extends FunctionName<A>> = {
42
+ export type ActorQueryParameters<A, M extends FunctionName<A>> = {
44
43
  functionName: M;
45
- args?: ActorMethodArgs<A[M]>;
44
+ args?: ActorMethodParameters<A[M]>;
46
45
  refetchOnMount?: boolean;
47
46
  refetchInterval?: number | false;
48
47
  };
49
- export type ActorUpdateArgs<A, M extends FunctionName<A>> = {
48
+ export type ActorUpdateParameters<A, M extends FunctionName<A>> = {
50
49
  functionName: M;
51
- args?: ActorMethodArgs<A[M]>;
50
+ args?: ActorMethodParameters<A[M]>;
52
51
  };
53
- export type ActorMethodCall<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodArgs<A[M]>) => ActorUpdateReturn<A, M>;
54
- export type ActorQuery<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(options: ActorQueryArgs<A, M>) => ActorQueryReturn<A, M>;
55
- export type ActorUpdate<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(options: ActorUpdateArgs<A, M>) => ActorUpdateReturn<A, M>;
56
- export interface ReactorCore<A = BaseActor> extends AgentManager, Omit<ActorManager<A>, "updateMethodState"> {
57
- login: (options?: AuthClientLoginOptions) => Promise<void>;
58
- logout: (options?: {
52
+ export type ActorMethodCall<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => ActorUpdateReturnType<A, M>;
53
+ export type ActorQuery<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(config: ActorQueryParameters<A, M>) => ActorQueryReturnType<A, M>;
54
+ export type ActorUpdate<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(config: ActorUpdateParameters<A, M>) => ActorUpdateReturnType<A, M>;
55
+ export interface CreateReactorCoreParameters extends CreateReactorStoreParameters {
56
+ withProcessEnv?: boolean;
57
+ }
58
+ export interface CreateReactorCoreReturnType<A = BaseActor> extends AgentManager, Omit<ActorManager<A>, "updateMethodState"> {
59
+ login: (config?: AuthClientLoginOptions) => Promise<void>;
60
+ logout: (config?: {
59
61
  returnTo?: string;
60
62
  }) => Promise<void>;
61
63
  queryCall: ActorQuery<A>;
package/dist/types.js CHANGED
@@ -14,6 +14,6 @@ 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("./agent/types"), exports);
18
- __exportStar(require("./actor/types"), exports);
19
- __exportStar(require("./candid/types"), exports);
17
+ __exportStar(require("./classes/agent/types"), exports);
18
+ __exportStar(require("./classes/actor/types"), exports);
19
+ __exportStar(require("./classes/candid/types"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "A library for intracting with the Internet Computer canisters",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -43,5 +43,5 @@
43
43
  "engines": {
44
44
  "node": ">=10"
45
45
  },
46
- "gitHead": "acf8b5da61713482264c9eb5c227dc94a7e43cbc"
46
+ "gitHead": "c52ec12bc91d5a0e2c5fc7c6e163530a1aa5e47f"
47
47
  }
File without changes
File without changes
File without changes