@ic-reactor/core 1.14.2 → 1.16.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.
package/README.md CHANGED
@@ -19,7 +19,7 @@ yarn add @ic-reactor/core
19
19
  or you can use the UMD version:
20
20
 
21
21
  ```html
22
- <script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.14.0/ic-reactor-core.min.js"></script>
22
+ <script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.15.0/ic-reactor-core.min.js"></script>
23
23
  ```
24
24
 
25
25
  ### Using `createReactorCore`
@@ -24,6 +24,7 @@ export declare class ActorManager<A = BaseActor> {
24
24
  private _getActorMethod;
25
25
  callMethod: <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
26
26
  callMethodWithOptions: (options: CallConfig) => <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
27
+ call: <M extends FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
27
28
  get agentManager(): AgentManager;
28
29
  getActor: () => A | null;
29
30
  getState: ActorStore<A>["getState"];
@@ -14,7 +14,14 @@ exports.ActorManager = void 0;
14
14
  const agent_1 = require("@dfinity/agent");
15
15
  const helper_1 = require("../../utils/helper");
16
16
  const candid_1 = require("@dfinity/candid");
17
- const utils_1 = require("../../utils");
17
+ const ACTOR_INITIAL_STATE = {
18
+ name: "",
19
+ version: 0,
20
+ methodState: {},
21
+ initializing: false,
22
+ initialized: false,
23
+ error: undefined,
24
+ };
18
25
  class ActorManager {
19
26
  constructor(actorConfig) {
20
27
  this._actor = null;
@@ -122,6 +129,29 @@ class ActorManager {
122
129
  return data;
123
130
  });
124
131
  };
132
+ this.call = (functionName, ...args) => __awaiter(this, void 0, void 0, function* () {
133
+ const requestHash = (0, helper_1.generateRequestHash)(args);
134
+ try {
135
+ this.updateMethodState(functionName, requestHash, {
136
+ loading: true,
137
+ error: undefined,
138
+ });
139
+ const data = yield this.callMethod(functionName, ...args);
140
+ this.updateMethodState(functionName, requestHash, {
141
+ loading: false,
142
+ data,
143
+ });
144
+ return data;
145
+ }
146
+ catch (error) {
147
+ this.updateMethodState(functionName, requestHash, {
148
+ loading: false,
149
+ error: error,
150
+ data: undefined,
151
+ });
152
+ throw error;
153
+ }
154
+ });
125
155
  // actor store
126
156
  this.getActor = () => {
127
157
  return this._actor;
@@ -129,8 +159,15 @@ class ActorManager {
129
159
  this.getState = () => {
130
160
  return this.actorStore.getState();
131
161
  };
132
- this.subscribeActorState = (listener) => {
133
- const unsubscribe = this.actorStore.subscribe(listener);
162
+ // @ts-expect-error: Overrides subscribe method signature
163
+ this.subscribeActorState = (selectorOrListener, listener, options) => {
164
+ let unsubscribe = () => { };
165
+ if (listener) {
166
+ unsubscribe = this.actorStore.subscribe(selectorOrListener, listener, options);
167
+ }
168
+ else {
169
+ unsubscribe = this.actorStore.subscribe(selectorOrListener);
170
+ }
134
171
  this._subscribers.push(unsubscribe);
135
172
  return unsubscribe;
136
173
  };
@@ -156,7 +193,7 @@ class ActorManager {
156
193
  }
157
194
  this._agentManager = agentManager;
158
195
  // Initialize stores
159
- this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(Object.assign(Object.assign({}, utils_1.ACTOR_INITIAL_STATE), { name }), {
196
+ this.actorStore = (0, helper_1.createStoreWithOptionalDevtools)(Object.assign(Object.assign({}, ACTOR_INITIAL_STATE), { name }), {
160
197
  withDevtools,
161
198
  name: "reactor-actor",
162
199
  store: canisterId.toString(),
@@ -1,5 +1,5 @@
1
1
  import type { AgentManager } from "../agent";
2
- import type { IDL, StoreApiWithDevtools, ActorMethod, ActorSubclass, Principal } from "../../types";
2
+ import type { IDL, ActorMethod, ActorSubclass, Principal, StoreWithAllMiddleware } from "../../types";
3
3
  import { CallConfig } from "@dfinity/agent";
4
4
  export interface DefaultActorType {
5
5
  [key: string]: ActorMethod;
@@ -48,7 +48,7 @@ export type ActorState<A = BaseActor> = {
48
48
  error: Error | undefined;
49
49
  methodState: ActorMethodStates<A>;
50
50
  };
51
- export type ActorStore<A = BaseActor> = StoreApiWithDevtools<ActorState<A>>;
51
+ export type ActorStore<A = BaseActor> = StoreWithAllMiddleware<ActorState<A>>;
52
52
  export type CallActorMethod<A = BaseActor> = <M extends FunctionName<A> = FunctionName<A>>(functionName: M, ...args: ActorMethodParameters<A[M]>) => Promise<ActorMethodReturnType<A[M]>>;
53
53
  export type MethodAttributes<A = BaseActor> = Record<FunctionName<A>, {
54
54
  type: FunctionType;
@@ -8,12 +8,10 @@ export declare class AgentManager {
8
8
  private _subscribers;
9
9
  agentStore: AgentStore;
10
10
  authStore: AuthStore;
11
- private initialAgentState;
12
- private initialAuthState;
13
11
  private updateAgentState;
14
12
  private updateAuthState;
15
13
  constructor(options?: AgentManagerParameters);
16
- private initializeAgent;
14
+ initializeAgent: () => Promise<void>;
17
15
  subscribeAgent: (callback: (agent: HttpAgent) => void, initialize?: boolean) => () => void;
18
16
  unsubscribeAgent: (callback: (agent: HttpAgent) => void) => void;
19
17
  private notifySubscribers;
@@ -26,23 +26,23 @@ const agent_1 = require("@dfinity/agent");
26
26
  const helper_1 = require("../../utils/helper");
27
27
  const auth_client_1 = require("@dfinity/auth-client");
28
28
  const constants_1 = require("../../utils/constants");
29
+ const AGENT_INITIAL_STATE = {
30
+ initialized: false,
31
+ initializing: false,
32
+ error: undefined,
33
+ network: undefined,
34
+ };
35
+ const AUTH_INITIAL_STATE = {
36
+ identity: null,
37
+ authenticating: false,
38
+ authenticated: false,
39
+ error: undefined,
40
+ };
29
41
  class AgentManager {
30
42
  constructor(options) {
31
43
  var _a;
32
44
  this._auth = null;
33
45
  this._subscribers = [];
34
- this.initialAgentState = {
35
- initialized: false,
36
- initializing: false,
37
- error: undefined,
38
- network: "ic",
39
- };
40
- this.initialAuthState = {
41
- identity: null,
42
- authenticating: false,
43
- authenticated: false,
44
- error: undefined,
45
- };
46
46
  this.updateAgentState = (newState, action) => {
47
47
  this.agentStore.setState((state) => (Object.assign(Object.assign({}, state), newState)), false, action);
48
48
  };
@@ -155,15 +155,23 @@ class AgentManager {
155
155
  this.getAgentState = () => {
156
156
  return this.agentStore.getState();
157
157
  };
158
- this.subscribeAgentState = (listener) => {
159
- return this.agentStore.subscribe(listener);
158
+ // @ts-expect-error: Overrides subscribe method signature
159
+ this.subscribeAgentState = (selectorOrListener, listener, options) => {
160
+ if (listener) {
161
+ return this.agentStore.subscribe(selectorOrListener, listener, options);
162
+ }
163
+ return this.agentStore.subscribe(selectorOrListener);
160
164
  };
161
165
  // auth store
162
166
  this.getAuthState = () => {
163
167
  return this.authStore.getState();
164
168
  };
165
- this.subscribeAuthState = (listener) => {
166
- return this.authStore.subscribe(listener);
169
+ // @ts-expect-error: Overrides subscribe method signature
170
+ this.subscribeAuthState = (selectorOrListener, listener, options) => {
171
+ if (listener) {
172
+ return this.authStore.subscribe(selectorOrListener, listener, options);
173
+ }
174
+ return this.authStore.subscribe(selectorOrListener);
167
175
  };
168
176
  this.getAuth = () => {
169
177
  return this._auth;
@@ -175,7 +183,7 @@ class AgentManager {
175
183
  const identity = this.authStore.getState().identity;
176
184
  return identity ? identity.getPrincipal() : null;
177
185
  };
178
- const _b = options || {}, { withDevtools, port = 4943, withLocalEnv, withProcessEnv } = _b, agentOptions = __rest(_b, ["withDevtools", "port", "withLocalEnv", "withProcessEnv"]);
186
+ const _b = options || {}, { withDevtools, port = 4943, withLocalEnv, withProcessEnv, initializeOnCreate = true } = _b, agentOptions = __rest(_b, ["withDevtools", "port", "withLocalEnv", "withProcessEnv", "initializeOnCreate"]);
179
187
  if (withProcessEnv) {
180
188
  const processNetwork = (0, helper_1.getProcessEnvNetwork)();
181
189
  agentOptions.host =
@@ -187,18 +195,20 @@ class AgentManager {
187
195
  else {
188
196
  agentOptions.host = (_a = agentOptions.host) !== null && _a !== void 0 ? _a : constants_1.IC_HOST_NETWORK_URI;
189
197
  }
190
- this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialAgentState, {
198
+ this.agentStore = (0, helper_1.createStoreWithOptionalDevtools)(AGENT_INITIAL_STATE, {
191
199
  withDevtools,
192
200
  name: "reactor-agent",
193
201
  store: "agent",
194
202
  });
195
- this.authStore = (0, helper_1.createStoreWithOptionalDevtools)(this.initialAuthState, {
203
+ this.authStore = (0, helper_1.createStoreWithOptionalDevtools)(AUTH_INITIAL_STATE, {
196
204
  withDevtools,
197
205
  name: "reactor-agent",
198
206
  store: "auth",
199
207
  });
200
208
  this._agent = agent_1.HttpAgent.createSync(agentOptions);
201
- this.initializeAgent();
209
+ if (initializeOnCreate) {
210
+ this.initializeAgent();
211
+ }
202
212
  }
203
213
  }
204
214
  exports.AgentManager = AgentManager;
@@ -1,18 +1,19 @@
1
1
  import type { HttpAgent, HttpAgentOptions, Identity } from "@dfinity/agent";
2
2
  import type { AuthClient } from "@dfinity/auth-client";
3
- import type { StoreApiWithDevtools } from "../../types";
3
+ import type { StoreWithAllMiddleware } from "../../types";
4
4
  export { HttpAgentOptions, AuthClient, Identity };
5
5
  export interface AgentManagerParameters extends HttpAgentOptions {
6
6
  port?: number;
7
7
  withLocalEnv?: boolean;
8
8
  withDevtools?: boolean;
9
9
  withProcessEnv?: boolean;
10
+ initializeOnCreate?: boolean;
10
11
  }
11
12
  export interface AgentState {
12
13
  initialized: boolean;
13
14
  initializing: boolean;
14
15
  error: Error | undefined;
15
- network: string;
16
+ network: string | undefined;
16
17
  }
17
18
  export interface AuthState {
18
19
  identity: Identity | null;
@@ -23,5 +24,5 @@ export interface AuthState {
23
24
  export interface UpdateAgentParameters extends HttpAgentOptions {
24
25
  agent?: HttpAgent;
25
26
  }
26
- export type AgentStore = StoreApiWithDevtools<AgentState>;
27
- export type AuthStore = StoreApiWithDevtools<AuthState>;
27
+ export type AgentStore = StoreWithAllMiddleware<AgentState>;
28
+ export type AuthStore = StoreWithAllMiddleware<AuthState>;
@@ -1,8 +1,15 @@
1
1
  export * from "./agent/types";
2
2
  export * from "./actor/types";
3
3
  export * from "./adapter/types";
4
- import { NamedSet } from "zustand/middleware";
5
- import type { StoreApi } from "zustand";
6
- export interface StoreApiWithDevtools<T> extends StoreApi<T> {
7
- setState: NamedSet<T>;
8
- }
4
+ import { type StateCreator, type StoreApi, type StoreMutatorIdentifier, type Mutate } from "zustand";
5
+ export type StoreWithMiddleware<T, Mis extends [StoreMutatorIdentifier, unknown][] = [], Mos extends [StoreMutatorIdentifier, unknown][] = []> = StateCreator<T, Mis, Mos>;
6
+ export type StoreApiWithMiddleware<T, Mos extends [StoreMutatorIdentifier, unknown][] = []> = Mutate<StoreApi<T>, Mos>;
7
+ export type WithDevtools = ["zustand/devtools", never];
8
+ export type WithSubscribeSelector = ["zustand/subscribeWithSelector", never];
9
+ export type StoreWithAllMiddleware<T> = StoreApiWithMiddleware<T, [
10
+ WithDevtools,
11
+ WithSubscribeSelector
12
+ ]>;
13
+ export type StoreWithSubscribeOnly<T> = StoreApiWithMiddleware<T, [
14
+ WithSubscribeSelector
15
+ ]>;
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
+ // Re-export existing types
17
18
  __exportStar(require("./agent/types"), exports);
18
19
  __exportStar(require("./actor/types"), exports);
19
20
  __exportStar(require("./adapter/types"), exports);
package/dist/types.d.ts CHANGED
@@ -79,17 +79,19 @@ export type ExtractOk<T> = T extends {
79
79
  export type ExtractErr<T> = T extends {
80
80
  Err: infer E;
81
81
  } ? E : never;
82
- export type CompiledResult<T> = ExtractOkErr<T> extends {
83
- OkType: infer U;
84
- ErrType: infer E;
85
- } ? {
82
+ export type CompiledOkResult<U> = {
86
83
  isOk: true;
87
84
  isErr: false;
88
85
  value: U;
89
86
  error: null;
90
- } | {
87
+ };
88
+ export type CompiledErrResult<E> = {
91
89
  isOk: false;
92
90
  isErr: true;
93
91
  value: null;
94
92
  error: E;
95
- } : never;
93
+ };
94
+ export type CompiledResult<T> = ExtractOkErr<T> extends {
95
+ OkType: infer U;
96
+ ErrType: infer E;
97
+ } ? CompiledOkResult<U> | CompiledErrResult<E> : never;
@@ -6,11 +6,3 @@ export declare const DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
6
6
  export declare const DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
7
7
  export declare const IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
8
8
  export declare const LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
9
- export declare const ACTOR_INITIAL_STATE: {
10
- name: string;
11
- version: number;
12
- methodState: {};
13
- initializing: boolean;
14
- initialized: boolean;
15
- error: undefined;
16
- };
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ACTOR_INITIAL_STATE = exports.LOCAL_INTERNET_IDENTITY_PROVIDER = exports.IC_INTERNET_IDENTITY_PROVIDER = exports.DEFAULT_IC_DIDJS_ID = exports.DEFAULT_LOCAL_DIDJS_ID = exports.LOCAL_HOST_NETWORK_URI = exports.IC_HOST_NETWORK_URI = exports.LOCAL_HOSTS = exports.REMOTE_HOSTS = void 0;
3
+ exports.LOCAL_INTERNET_IDENTITY_PROVIDER = exports.IC_INTERNET_IDENTITY_PROVIDER = exports.DEFAULT_IC_DIDJS_ID = exports.DEFAULT_LOCAL_DIDJS_ID = exports.LOCAL_HOST_NETWORK_URI = exports.IC_HOST_NETWORK_URI = exports.LOCAL_HOSTS = exports.REMOTE_HOSTS = void 0;
4
4
  exports.REMOTE_HOSTS = [".github.dev", ".gitpod.io"];
5
5
  exports.LOCAL_HOSTS = ["localhost", "127.0.0.1"];
6
6
  exports.IC_HOST_NETWORK_URI = "https://ic0.app";
@@ -9,11 +9,3 @@ exports.DEFAULT_LOCAL_DIDJS_ID = "bd3sg-teaaa-aaaaa-qaaba-cai";
9
9
  exports.DEFAULT_IC_DIDJS_ID = "a4gq6-oaaaa-aaaab-qaa4q-cai";
10
10
  exports.IC_INTERNET_IDENTITY_PROVIDER = "https://identity.ic0.app/#authorize";
11
11
  exports.LOCAL_INTERNET_IDENTITY_PROVIDER = "http://rdmx6-jaaaa-aaaaa-aaadq-cai.localhost:4943/#authorize";
12
- exports.ACTOR_INITIAL_STATE = {
13
- name: "",
14
- version: 0,
15
- methodState: {},
16
- initializing: false,
17
- initialized: false,
18
- error: undefined,
19
- };
@@ -1,18 +1,59 @@
1
1
  import { DevtoolsOptions } from "zustand/middleware";
2
- import type { CompiledResult, BaseActor, CandidDefenition, IDL } from "../types";
3
- export declare function createStoreWithOptionalDevtools<T>(initialState: T, config: DevtoolsOptions): Omit<import("zustand/vanilla").StoreApi<T>, "setState"> & {
4
- setState<A extends string | {
5
- type: string;
6
- }>(partial: T | Partial<T> | ((state: T) => T | Partial<T>), replace?: boolean | undefined, action?: A | undefined): void;
7
- };
2
+ import type { CompiledResult, BaseActor, CandidDefenition, IDL, ExtractOk, StoreWithAllMiddleware, StoreWithSubscribeOnly } from "../types";
3
+ /**
4
+ * Creates a Zustand store with optional DevTools middleware.
5
+ *
6
+ * @param initialState - The initial state of the store.
7
+ * @param config - Configuration options for DevTools.
8
+ * @returns A Zustand store with DevTools enabled if configured, otherwise a standard store.
9
+ */
10
+ export declare function createStoreWithOptionalDevtools<T extends object>(initialState: T, config: DevtoolsOptions & {
11
+ withDevtools?: boolean;
12
+ }): StoreWithAllMiddleware<T> | StoreWithSubscribeOnly<T>;
8
13
  export declare const importCandidDefinition: (candidDef: string) => Promise<CandidDefenition>;
14
+ /**
15
+ * Checks if the current environment is local or development.
16
+ *
17
+ * @returns `true` if running in a local or development environment, otherwise `false`.
18
+ */
9
19
  export declare const isInLocalOrDevelopment: () => boolean;
20
+ /**
21
+ * Retrieves the network from the process environment variables.
22
+ *
23
+ * @returns The network name, defaulting to "ic" if not specified.
24
+ */
10
25
  export declare const getProcessEnvNetwork: () => string;
26
+ /**
27
+ * Determines the network type based on the provided hostname.
28
+ *
29
+ * @param hostname - The hostname to evaluate.
30
+ * @returns A string indicating the network type: "local", "remote", or "ic".
31
+ */
11
32
  export declare function getNetworkByHostname(hostname: string): "local" | "remote" | "ic";
33
+ /**
34
+ * Checks if a given IDL function is a query.
35
+ *
36
+ * @param func - The IDL function to check.
37
+ * @returns `true` if the function is a query or composite query, otherwise `false`.
38
+ */
12
39
  export declare function isQuery(func: IDL.FuncClass): boolean;
13
40
  export declare const jsonToString: (json: unknown, space?: number) => string;
14
41
  export declare const generateRequestHash: (args?: unknown[]) => `0x${string}`;
15
42
  export declare const generateHash: (field?: unknown) => `0x${string}`;
16
43
  export declare const generateActorHash: (actor: BaseActor) => `0x${string}`;
17
44
  export declare const stringToHash: (str: string) => `0x${string}`;
45
+ /**
46
+ * Helper function for extracting the value from a compiled result { Ok: T } or { Err: E }
47
+ *
48
+ * @param result - The compiled result to extract from.
49
+ * @returns A `CompiledResult` object indicating success or failure.
50
+ */
18
51
  export declare function createCompiledResult<T>(result: T): CompiledResult<T>;
52
+ /**
53
+ * Helper function for extracting the value from a compiled result { Ok: T } or throw the error if { Err: E }
54
+ *
55
+ * @param result - The compiled result to extract from.
56
+ * @returns The extracted value from the compiled result.
57
+ * @throws The error from the compiled result.
58
+ */
59
+ export declare function extractOkResult<T>(result: T): ExtractOk<T>;
@@ -14,20 +14,27 @@ exports.createStoreWithOptionalDevtools = createStoreWithOptionalDevtools;
14
14
  exports.getNetworkByHostname = getNetworkByHostname;
15
15
  exports.isQuery = isQuery;
16
16
  exports.createCompiledResult = createCompiledResult;
17
+ exports.extractOkResult = extractOkResult;
17
18
  const agent_1 = require("@dfinity/agent");
18
19
  const middleware_1 = require("zustand/middleware");
19
- const vanilla_1 = require("zustand/vanilla");
20
+ const zustand_1 = require("zustand");
20
21
  const hash_1 = require("./hash");
21
22
  const constants_1 = require("./constants");
23
+ /**
24
+ * Creates a Zustand store with optional DevTools middleware.
25
+ *
26
+ * @param initialState - The initial state of the store.
27
+ * @param config - Configuration options for DevTools.
28
+ * @returns A Zustand store with DevTools enabled if configured, otherwise a standard store.
29
+ */
22
30
  function createStoreWithOptionalDevtools(initialState, config) {
31
+ const createState = () => initialState;
23
32
  if (config.withDevtools) {
24
- return (0, vanilla_1.createStore)((0, middleware_1.devtools)(() => initialState, Object.assign({ serialize: {
33
+ return (0, zustand_1.createStore)((0, middleware_1.subscribeWithSelector)((0, middleware_1.devtools)(createState, Object.assign({ serialize: {
25
34
  replacer: (_, value) => typeof value === "bigint" ? value.toString() : value,
26
- } }, config)));
27
- }
28
- else {
29
- return (0, vanilla_1.createStore)(() => initialState);
35
+ } }, config))));
30
36
  }
37
+ return (0, zustand_1.createStore)((0, middleware_1.subscribeWithSelector)(createState));
31
38
  }
32
39
  const importCandidDefinition = (candidDef) => __awaiter(void 0, void 0, void 0, function* () {
33
40
  if (typeof window === "undefined") {
@@ -58,10 +65,20 @@ const importCandidDefinition = (candidDef) => __awaiter(void 0, void 0, void 0,
58
65
  }
59
66
  });
60
67
  exports.importCandidDefinition = importCandidDefinition;
68
+ /**
69
+ * Checks if the current environment is local or development.
70
+ *
71
+ * @returns `true` if running in a local or development environment, otherwise `false`.
72
+ */
61
73
  const isInLocalOrDevelopment = () => {
62
74
  return typeof process !== "undefined" && process.env.DFX_NETWORK === "local";
63
75
  };
64
76
  exports.isInLocalOrDevelopment = isInLocalOrDevelopment;
77
+ /**
78
+ * Retrieves the network from the process environment variables.
79
+ *
80
+ * @returns The network name, defaulting to "ic" if not specified.
81
+ */
65
82
  const getProcessEnvNetwork = () => {
66
83
  var _a;
67
84
  if (typeof process === "undefined")
@@ -70,6 +87,12 @@ const getProcessEnvNetwork = () => {
70
87
  return (_a = process.env.DFX_NETWORK) !== null && _a !== void 0 ? _a : "ic";
71
88
  };
72
89
  exports.getProcessEnvNetwork = getProcessEnvNetwork;
90
+ /**
91
+ * Determines the network type based on the provided hostname.
92
+ *
93
+ * @param hostname - The hostname to evaluate.
94
+ * @returns A string indicating the network type: "local", "remote", or "ic".
95
+ */
73
96
  function getNetworkByHostname(hostname) {
74
97
  if (constants_1.LOCAL_HOSTS.some((host) => hostname.endsWith(host))) {
75
98
  return "local";
@@ -81,6 +104,12 @@ function getNetworkByHostname(hostname) {
81
104
  return "ic";
82
105
  }
83
106
  }
107
+ /**
108
+ * Checks if a given IDL function is a query.
109
+ *
110
+ * @param func - The IDL function to check.
111
+ * @returns `true` if the function is a query or composite query, otherwise `false`.
112
+ */
84
113
  function isQuery(func) {
85
114
  return (func.annotations.includes("query") ||
86
115
  func.annotations.includes("composite_query"));
@@ -112,7 +141,12 @@ exports.stringToHash = stringToHash;
112
141
  function toHexString(bytes) {
113
142
  return (0, agent_1.toHex)(bytes);
114
143
  }
115
- /// Helper function for extracting the value from a compiled result { Ok: T } or { Err: E }
144
+ /**
145
+ * Helper function for extracting the value from a compiled result { Ok: T } or { Err: E }
146
+ *
147
+ * @param result - The compiled result to extract from.
148
+ * @returns A `CompiledResult` object indicating success or failure.
149
+ */
116
150
  function createCompiledResult(result) {
117
151
  if (result && typeof result === "object" && "Ok" in result) {
118
152
  return {
@@ -140,3 +174,17 @@ function createCompiledResult(result) {
140
174
  };
141
175
  }
142
176
  }
177
+ /**
178
+ * Helper function for extracting the value from a compiled result { Ok: T } or throw the error if { Err: E }
179
+ *
180
+ * @param result - The compiled result to extract from.
181
+ * @returns The extracted value from the compiled result.
182
+ * @throws The error from the compiled result.
183
+ */
184
+ function extractOkResult(result) {
185
+ const compiledResult = createCompiledResult(result);
186
+ if (compiledResult.isErr) {
187
+ throw compiledResult.error;
188
+ }
189
+ return compiledResult.value;
190
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.14.2",
3
+ "version": "1.16.0",
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",
@@ -32,7 +32,7 @@
32
32
  "@dfinity/identity": ">=2.1",
33
33
  "@dfinity/principal": ">=2.1",
34
34
  "simple-cbor": "^0.4.1",
35
- "zustand": "4.5.5"
35
+ "zustand": "5.0.2"
36
36
  },
37
37
  "peerDependencies": {
38
38
  "@dfinity/agent": ">=2.1",
@@ -42,13 +42,13 @@
42
42
  "@dfinity/principal": ">=2.1"
43
43
  },
44
44
  "devDependencies": {
45
- "@ic-reactor/parser": "^0.4.3",
45
+ "@ic-reactor/parser": "^0.4.4",
46
46
  "@types/node": "^22.9.0",
47
47
  "ts-loader": "^9.5.1",
48
48
  "webpack": "^5.96.1"
49
49
  },
50
50
  "scripts": {
51
- "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
51
+ "test": "NODE_OPTIONS=\"--experimental-vm-modules\" npx jest",
52
52
  "start": "tsc watch",
53
53
  "bundle": "yarn bundle:dev && yarn bundle:prod",
54
54
  "bundle:dev": "npx webpack-cli --mode development",
@@ -60,5 +60,5 @@
60
60
  "engines": {
61
61
  "node": ">=10"
62
62
  },
63
- "gitHead": "77d882f8af5d203240e82350171a57185df38e35"
63
+ "gitHead": "6110fb3f75c7927086d828c912855589e2a33eb3"
64
64
  }