@ic-reactor/core 1.16.0 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,24 +1,4 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __rest = (this && this.__rest) || function (s, e) {
12
- var t = {};
13
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
- t[p] = s[p];
15
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
- t[p[i]] = s[p[i]];
19
- }
20
- return t;
21
- };
22
2
  Object.defineProperty(exports, "__esModule", { value: true });
23
3
  exports.createReactorCore = void 0;
24
4
  const createReactorStore_1 = require("./createReactorStore");
@@ -32,7 +12,7 @@ const utils_1 = require("./utils");
32
12
  * @includeExample ./packages/core/README.md:32-86
33
13
  */
34
14
  const createReactorCore = (config) => {
35
- const _a = (0, createReactorStore_1.createReactorStore)(config), { subscribeActorState, updateMethodState, callMethodWithOptions, callMethod, getState, agentManager } = _a, rest = __rest(_a, ["subscribeActorState", "updateMethodState", "callMethodWithOptions", "callMethod", "getState", "agentManager"]);
15
+ const { subscribeActorState, updateMethodState, callMethodWithOptions, callMethod, getState, agentManager, ...rest } = (0, createReactorStore_1.createReactorStore)(config);
36
16
  const actorMethod = (functionName, args, options = {}) => {
37
17
  const requestHash = (0, utils_1.generateRequestHash)(args);
38
18
  const updateState = (newState = {}) => {
@@ -64,13 +44,13 @@ const createReactorCore = (config) => {
64
44
  });
65
45
  return unsubscribe;
66
46
  };
67
- const call = (replaceArgs) => __awaiter(void 0, void 0, void 0, function* () {
47
+ const call = async (replaceArgs) => {
68
48
  updateState({
69
49
  loading: true,
70
50
  error: undefined,
71
51
  });
72
52
  try {
73
- const data = yield callMethodWithOptions(options)(functionName, ...(replaceArgs !== null && replaceArgs !== void 0 ? replaceArgs : args));
53
+ const data = await callMethodWithOptions(options)(functionName, ...(replaceArgs ?? args));
74
54
  updateState({ data, loading: false });
75
55
  return data;
76
56
  }
@@ -81,7 +61,7 @@ const createReactorCore = (config) => {
81
61
  });
82
62
  throw error;
83
63
  }
84
- });
64
+ };
85
65
  return {
86
66
  requestHash,
87
67
  subscribe,
@@ -97,10 +77,9 @@ const createReactorCore = (config) => {
97
77
  throw error;
98
78
  }
99
79
  };
100
- const queryCall = (_a) => {
101
- var { functionName, args = [], refetchOnMount = true, refetchInterval = false } = _a, options = __rest(_a, ["functionName", "args", "refetchOnMount", "refetchInterval"]);
80
+ const queryCall = ({ functionName, args = [], refetchOnMount = true, refetchInterval = false, ...options }) => {
102
81
  let intervalId = null;
103
- const _b = actorMethod(functionName, args, options), { call } = _b, rest = __rest(_b, ["call"]);
82
+ const { call, ...rest } = actorMethod(functionName, args, options);
104
83
  if (refetchInterval) {
105
84
  intervalId = setInterval(() => {
106
85
  call();
@@ -114,17 +93,20 @@ const createReactorCore = (config) => {
114
93
  let dataPromise = Promise.resolve();
115
94
  if (refetchOnMount)
116
95
  dataPromise = call();
117
- return Object.assign(Object.assign({}, rest), { call, dataPromise, intervalId, clearRefetchInterval });
96
+ return { ...rest, call, dataPromise, intervalId, clearRefetchInterval };
118
97
  };
119
- const updateCall = (_a) => {
120
- var { functionName, args = [] } = _a, options = __rest(_a, ["functionName", "args"]);
98
+ const updateCall = ({ functionName, args = [], ...options }) => {
121
99
  return actorMethod(functionName, args, options);
122
100
  };
123
- return Object.assign(Object.assign({ getState,
101
+ return {
102
+ getState,
124
103
  queryCall,
125
104
  updateCall,
126
105
  callMethod,
127
106
  callMethodWithOptions,
128
- subscribeActorState }, agentManager), rest);
107
+ subscribeActorState,
108
+ ...agentManager,
109
+ ...rest,
110
+ };
129
111
  };
130
112
  exports.createReactorCore = createReactorCore;
@@ -1,15 +1,4 @@
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
2
  Object.defineProperty(exports, "__esModule", { value: true });
14
3
  exports.createReactorStore = void 0;
15
4
  const createActorManager_1 = require("./createActorManager");
@@ -23,9 +12,12 @@ const createAgentManager_1 = require("./createAgentManager");
23
12
  * @includeExample ./packages/core/README.md:200-225
24
13
  */
25
14
  const createReactorStore = (config) => {
26
- const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager } = config, agentParameters = __rest(config, ["idlFactory", "canisterId", "withDevtools", "initializeOnCreate", "withVisitor", "agentManager"]);
15
+ const { idlFactory, canisterId, withDevtools = false, initializeOnCreate = true, withVisitor = false, agentManager: maybeAgentManager, ...agentParameters } = config;
27
16
  const agentManager = maybeAgentManager ||
28
- (0, createAgentManager_1.createAgentManager)(Object.assign({ withDevtools }, agentParameters));
17
+ (0, createAgentManager_1.createAgentManager)({
18
+ withDevtools,
19
+ ...agentParameters,
20
+ });
29
21
  const actorManager = (0, createActorManager_1.createActorManager)({
30
22
  idlFactory,
31
23
  canisterId,
package/dist/index.js CHANGED
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
39
  exports.utils = exports.types = exports.classes = void 0;
30
40
  __exportStar(require("./createReactorCore"), exports);
package/dist/types.d.ts CHANGED
@@ -48,8 +48,7 @@ export interface ActorUpdateParameters<A, M extends FunctionName<A>> extends Cal
48
48
  export type ActorMethodCall<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(functionName: M, args: ActorMethodParameters<A[M]>, options?: CallConfig) => ActorUpdateReturnType<A, M>;
49
49
  export type ActorQuery<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(params: ActorQueryParameters<A, M>) => ActorQueryReturnType<A, M>;
50
50
  export type ActorUpdate<A = Record<string, ActorMethod>> = <M extends FunctionName<A>>(params: ActorUpdateParameters<A, M>) => ActorUpdateReturnType<A, M>;
51
- export interface CreateReactorCoreParameters extends CreateReactorStoreParameters {
52
- }
51
+ export type CreateReactorCoreParameters = CreateReactorStoreParameters;
53
52
  export interface CreateReactorCoreReturnType<A = BaseActor> extends AgentManager, Omit<ActorManager<A>, "updateMethodState"> {
54
53
  queryCall: ActorQuery<A>;
55
54
  updateCall: ActorUpdate<A>;
@@ -1,5 +1,10 @@
1
1
  import { DevtoolsOptions } from "zustand/middleware";
2
- import type { CompiledResult, BaseActor, CandidDefenition, IDL, ExtractOk, StoreWithAllMiddleware, StoreWithSubscribeOnly } from "../types";
2
+ import type { CompiledResult, BaseActor, CandidDefenition, IDL, ExtractOk, StoreWithAllMiddleware } from "../types";
3
+ /**
4
+ * No operation function that does nothing.
5
+ * It can be used as a placeholder or for logging purposes.
6
+ */
7
+ export declare function noop(): void;
3
8
  /**
4
9
  * Creates a Zustand store with optional DevTools middleware.
5
10
  *
@@ -9,7 +14,7 @@ import type { CompiledResult, BaseActor, CandidDefenition, IDL, ExtractOk, Store
9
14
  */
10
15
  export declare function createStoreWithOptionalDevtools<T extends object>(initialState: T, config: DevtoolsOptions & {
11
16
  withDevtools?: boolean;
12
- }): StoreWithAllMiddleware<T> | StoreWithSubscribeOnly<T>;
17
+ }): StoreWithAllMiddleware<T>;
13
18
  export declare const importCandidDefinition: (candidDef: string) => Promise<CandidDefenition>;
14
19
  /**
15
20
  * Checks if the current environment is local or development.
@@ -1,25 +1,26 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.getProcessEnvNetwork = exports.isInLocalOrDevelopment = exports.importCandidDefinition = void 0;
4
+ exports.noop = noop;
13
5
  exports.createStoreWithOptionalDevtools = createStoreWithOptionalDevtools;
14
6
  exports.getNetworkByHostname = getNetworkByHostname;
15
7
  exports.isQuery = isQuery;
16
8
  exports.createCompiledResult = createCompiledResult;
17
9
  exports.extractOkResult = extractOkResult;
18
- const agent_1 = require("@dfinity/agent");
10
+ const sha2_1 = require("@noble/hashes/sha2");
11
+ const utils_1 = require("@noble/hashes/utils");
19
12
  const middleware_1 = require("zustand/middleware");
20
13
  const zustand_1 = require("zustand");
21
14
  const hash_1 = require("./hash");
22
15
  const constants_1 = require("./constants");
16
+ /**
17
+ * No operation function that does nothing.
18
+ * It can be used as a placeholder or for logging purposes.
19
+ */
20
+ function noop() {
21
+ // eslint-disable-next-line no-console
22
+ console.warn("No operation function called");
23
+ }
23
24
  /**
24
25
  * Creates a Zustand store with optional DevTools middleware.
25
26
  *
@@ -29,24 +30,26 @@ const constants_1 = require("./constants");
29
30
  */
30
31
  function createStoreWithOptionalDevtools(initialState, config) {
31
32
  const createState = () => initialState;
32
- if (config.withDevtools) {
33
- return (0, zustand_1.createStore)((0, middleware_1.subscribeWithSelector)((0, middleware_1.devtools)(createState, Object.assign({ serialize: {
34
- replacer: (_, value) => typeof value === "bigint" ? value.toString() : value,
35
- } }, config))));
36
- }
37
- return (0, zustand_1.createStore)((0, middleware_1.subscribeWithSelector)(createState));
33
+ return (0, zustand_1.createStore)((0, middleware_1.subscribeWithSelector)((0, middleware_1.devtools)(createState, {
34
+ enabled: !!config.withDevtools,
35
+ serialize: {
36
+ replacer: (_, value) => typeof value === "bigint" ? value.toString() : value,
37
+ },
38
+ ...config,
39
+ })));
38
40
  }
39
- const importCandidDefinition = (candidDef) => __awaiter(void 0, void 0, void 0, function* () {
41
+ const importCandidDefinition = async (candidDef) => {
40
42
  if (typeof window === "undefined") {
41
- // Node.js environment
43
+ // Node.js environment - use dynamic evaluation
42
44
  try {
43
- const loaderFunction = new Function(`
44
- return import("data:text/javascript;charset=utf-8, ${encodeURIComponent(candidDef)}")
45
- `);
46
- return loaderFunction();
45
+ const moduleExports = {};
46
+ const moduleCode = candidDef.replace(/export const /g, "moduleExports.");
47
+ const func = new Function("moduleExports", moduleCode);
48
+ func(moduleExports);
49
+ return moduleExports;
47
50
  }
48
51
  catch (error) {
49
- throw new Error(`Error importing candid definition in NodeJs: ${error}`);
52
+ throw new Error(`Error importing candid definition in NodeJs: ${error.message}`);
50
53
  }
51
54
  }
52
55
  else {
@@ -63,7 +66,7 @@ const importCandidDefinition = (candidDef) => __awaiter(void 0, void 0, void 0,
63
66
  throw new Error(`Error importing candid definition: ${error}`);
64
67
  }
65
68
  }
66
- });
69
+ };
67
70
  exports.importCandidDefinition = importCandidDefinition;
68
71
  /**
69
72
  * Checks if the current environment is local or development.
@@ -80,11 +83,10 @@ exports.isInLocalOrDevelopment = isInLocalOrDevelopment;
80
83
  * @returns The network name, defaulting to "ic" if not specified.
81
84
  */
82
85
  const getProcessEnvNetwork = () => {
83
- var _a;
84
86
  if (typeof process === "undefined")
85
87
  return "ic";
86
88
  else
87
- return (_a = process.env.DFX_NETWORK) !== null && _a !== void 0 ? _a : "ic";
89
+ return process.env.DFX_NETWORK ?? "ic";
88
90
  };
89
91
  exports.getProcessEnvNetwork = getProcessEnvNetwork;
90
92
  /**
@@ -125,22 +127,19 @@ const generateRequestHash = (args = []) => {
125
127
  exports.generateRequestHash = generateRequestHash;
126
128
  const generateHash = (field) => {
127
129
  const serializedArgs = JSON.stringify(field);
128
- return (0, exports.stringToHash)(serializedArgs !== null && serializedArgs !== void 0 ? serializedArgs : "");
130
+ return (0, exports.stringToHash)(serializedArgs ?? "");
129
131
  };
130
132
  exports.generateHash = generateHash;
131
133
  const generateActorHash = (actor) => {
132
134
  const serializedArgs = JSON.stringify(actor);
133
- return (0, exports.stringToHash)(serializedArgs !== null && serializedArgs !== void 0 ? serializedArgs : "");
135
+ return (0, exports.stringToHash)(serializedArgs ?? "");
134
136
  };
135
137
  exports.generateActorHash = generateActorHash;
136
138
  const stringToHash = (str) => {
137
- const hashBytes = (0, agent_1.hash)(new TextEncoder().encode(str));
138
- return `0x${toHexString(hashBytes)}`;
139
+ const hashBytes = (0, sha2_1.sha256)(str);
140
+ return `0x${(0, utils_1.bytesToHex)(hashBytes)}`;
139
141
  };
140
142
  exports.stringToHash = stringToHash;
141
- function toHexString(bytes) {
142
- return (0, agent_1.toHex)(bytes);
143
- }
144
143
  /**
145
144
  * Helper function for extracting the value from a compiled result { Ok: T } or { Err: E }
146
145
  *
@@ -164,6 +163,15 @@ function createCompiledResult(result) {
164
163
  error: result.Err,
165
164
  };
166
165
  }
166
+ else if (result) {
167
+ // For non-Result types
168
+ return {
169
+ isOk: true,
170
+ isErr: false,
171
+ value: result,
172
+ error: null,
173
+ };
174
+ }
167
175
  else {
168
176
  // For non-Result types
169
177
  return {
@@ -18,13 +18,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
18
18
  var __exportStar = (this && this.__exportStar) || function(m, exports) {
19
19
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
20
  };
21
- var __importStar = (this && this.__importStar) || function (mod) {
22
- if (mod && mod.__esModule) return mod;
23
- var result = {};
24
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
- __setModuleDefault(result, mod);
26
- return result;
27
- };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
28
38
  Object.defineProperty(exports, "__esModule", { value: true });
29
39
  exports.agent = exports.principal = exports.candid = void 0;
30
40
  __exportStar(require("./helper"), exports);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.16.0",
3
+ "version": "2.0.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",
@@ -26,39 +26,35 @@
26
26
  },
27
27
  "homepage": "https://b3pay.github.io/ic-reactor/modules/core.html",
28
28
  "dependencies": {
29
- "@dfinity/agent": ">=2.1",
30
- "@dfinity/auth-client": ">=2.1",
31
- "@dfinity/candid": ">=2.1",
32
- "@dfinity/identity": ">=2.1",
33
- "@dfinity/principal": ">=2.1",
34
- "simple-cbor": "^0.4.1",
35
- "zustand": "5.0.2"
29
+ "@dfinity/agent": "^3.1.0",
30
+ "@dfinity/auth-client": "^3.1.0",
31
+ "@dfinity/candid": "^3.1.0",
32
+ "@dfinity/identity": "^3.1.0",
33
+ "@dfinity/principal": "^3.1.0",
34
+ "zustand": "5.0.6"
36
35
  },
37
36
  "peerDependencies": {
38
- "@dfinity/agent": ">=2.1",
39
- "@dfinity/auth-client": ">=2.1",
40
- "@dfinity/candid": ">=2.1",
41
- "@dfinity/identity": ">=2.1",
42
- "@dfinity/principal": ">=2.1"
37
+ "@dfinity/agent": ">=3.1.0",
38
+ "@dfinity/auth-client": ">=3.1.0",
39
+ "@dfinity/candid": ">=3.1.0",
40
+ "@dfinity/identity": ">=3.1.0",
41
+ "@dfinity/principal": ">=3.1.0"
43
42
  },
44
43
  "devDependencies": {
45
- "@ic-reactor/parser": "^0.4.4",
46
- "@types/node": "^22.9.0",
47
- "ts-loader": "^9.5.1",
48
- "webpack": "^5.96.1"
44
+ "@ic-reactor/parser": "0.4.5"
49
45
  },
50
46
  "scripts": {
51
- "test": "NODE_OPTIONS=\"--experimental-vm-modules\" npx jest",
52
- "start": "tsc watch",
53
- "bundle": "yarn bundle:dev && yarn bundle:prod",
54
- "bundle:dev": "npx webpack-cli --mode development",
55
- "bundle:prod": "npx webpack-cli --mode production",
56
- "build:tsc": "tsc",
57
- "build": "yarn build:tsc && yarn bundle",
58
- "clean": "npx rimraf dist && npx rimraf umd && npx rimraf node_modules"
47
+ "test": "bun test",
48
+ "start": "bun run tsc --watch",
49
+ "build:tsc": "bun run tsc",
50
+ "build": "bun run build:tsc && bun run bundle",
51
+ "bundle": "bun run bundle:dev && bun run bundle:prod",
52
+ "bundle:dev": "bun run webpack-cli --mode development",
53
+ "bundle:prod": "bun run webpack-cli --mode production",
54
+ "clean": "bun run rimraf dist && bun run rimraf umd && bun run rimraf node_modules"
59
55
  },
60
56
  "engines": {
61
- "node": ">=10"
57
+ "node": ">=22.0.0"
62
58
  },
63
- "gitHead": "6110fb3f75c7927086d828c912855589e2a33eb3"
59
+ "gitHead": "2677a090df726dc4f4216eb406b135a32334507b"
64
60
  }