@ic-reactor/core 1.6.3 → 1.6.4

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.
@@ -8,10 +8,11 @@ export declare class CandidAdapter {
8
8
  constructor({ agentManager, agent, didjsCanisterId, }: CandidAdapterParameters);
9
9
  initializeParser(module?: ReactorParser): Promise<void>;
10
10
  private getDefaultDidJsId;
11
+ fetchCandidDefinition(canisterId: CanisterId): Promise<string>;
11
12
  getCandidDefinition(canisterId: CanisterId): Promise<CandidDefenition>;
12
13
  getFromMetadata(canisterId: CanisterId): Promise<string | undefined>;
13
- getFromTmpHack(canisterId: CanisterId): Promise<string | undefined>;
14
+ getFromTmpHack(canisterId: CanisterId): Promise<string>;
14
15
  dynamicEvalJs(data: string): Promise<CandidDefenition>;
15
- fetchDidTojs(candidSource: string): Promise<[string]>;
16
+ fetchDidTojs(candidSource: string, didjsCanisterId?: string): Promise<[string]>;
16
17
  parseDidToJs(candidSource: string): string;
17
18
  }
@@ -55,26 +55,36 @@ class CandidAdapter {
55
55
  ? constants_1.DEFAULT_LOCAL_DIDJS_ID
56
56
  : constants_1.DEFAULT_IC_DIDJS_ID;
57
57
  }
58
- getCandidDefinition(canisterId) {
58
+ fetchCandidDefinition(canisterId) {
59
59
  return __awaiter(this, void 0, void 0, function* () {
60
+ let candidDef = "";
61
+ // First attempt: Try getting Candid definition from metadata
60
62
  try {
61
- // First attempt: Try getting Candid definition from metadata
62
- const fromMetadata = yield this.getFromMetadata(canisterId).catch(() => {
63
- return undefined;
64
- });
65
- if (fromMetadata)
66
- return this.dynamicEvalJs(fromMetadata);
63
+ candidDef = yield this.getFromMetadata(canisterId);
64
+ if (!candidDef) {
65
+ throw new Error("Cannot retrieve Candid definition from metadata");
66
+ }
67
+ }
68
+ catch (error) {
67
69
  // Second attempt: Try the temporary hack method
68
- const fromTmpHack = yield this.getFromTmpHack(canisterId).catch(() => {
70
+ candidDef = yield this.getFromTmpHack(canisterId).catch(() => {
69
71
  return undefined;
70
72
  });
71
- if (fromTmpHack)
72
- return this.dynamicEvalJs(fromTmpHack);
73
- // If both attempts fail, throw an error
74
- throw "Failed to retrieve Candid definition by any method.";
75
73
  }
76
- catch (err) {
77
- throw new Error(`Error fetching canister ${canisterId}: ${err}`);
74
+ if (!candidDef) {
75
+ throw new Error("Failed to retrieve Candid definition by any method.");
76
+ }
77
+ return candidDef;
78
+ });
79
+ }
80
+ getCandidDefinition(canisterId) {
81
+ return __awaiter(this, void 0, void 0, function* () {
82
+ try {
83
+ const candidDef = yield this.fetchCandidDefinition(canisterId);
84
+ return this.dynamicEvalJs(candidDef);
85
+ }
86
+ catch (error) {
87
+ throw new Error(`Error fetching canister ${canisterId}: ${error}`);
78
88
  }
79
89
  });
80
90
  }
@@ -116,21 +126,21 @@ class CandidAdapter {
116
126
  if (JSON.stringify(candidDef) === JSON.stringify([])) {
117
127
  throw new Error("Cannot compile Candid to JavaScript");
118
128
  }
119
- return (0, utils_1.importCandidDefinition)(candidDef);
129
+ return yield (0, utils_1.importCandidDefinition)(candidDef);
120
130
  }
121
131
  catch (error) {
122
132
  throw new Error(`Error evaluating Candid definition: ${error}`);
123
133
  }
124
134
  });
125
135
  }
126
- fetchDidTojs(candidSource) {
136
+ fetchDidTojs(candidSource, didjsCanisterId) {
127
137
  return __awaiter(this, void 0, void 0, function* () {
128
138
  const didjsInterface = ({ IDL }) => IDL.Service({
129
139
  did_to_js: IDL.Func([IDL.Text], [IDL.Opt(IDL.Text)], ["query"]),
130
140
  });
131
141
  const didjs = agent_1.Actor.createActor(didjsInterface, {
132
142
  agent: this.agent,
133
- canisterId: this.didjsCanisterId,
143
+ canisterId: didjsCanisterId || this.didjsCanisterId,
134
144
  });
135
145
  return didjs.did_to_js(candidSource);
136
146
  });
@@ -1,11 +1,11 @@
1
1
  import { DevtoolsOptions } from "zustand/middleware";
2
- import type { BaseActor, IDL } from "../types";
2
+ import type { BaseActor, CandidDefenition, IDL } from "../types";
3
3
  export declare function createStoreWithOptionalDevtools<T>(initialState: T, config: DevtoolsOptions): Omit<import("zustand/vanilla").StoreApi<T>, "setState"> & {
4
4
  setState<A extends string | {
5
5
  type: string;
6
6
  }>(partial: T | Partial<T> | ((state: T) => T | Partial<T>), replace?: boolean | undefined, action?: A | undefined): void;
7
7
  };
8
- export declare const importCandidDefinition: (candidDef: string) => any;
8
+ export declare const importCandidDefinition: (candidDef: string) => Promise<CandidDefenition>;
9
9
  export declare const isInLocalOrDevelopment: () => boolean;
10
10
  export declare const getProcessEnvNetwork: () => string;
11
11
  export declare function isQuery(func: IDL.FuncClass): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ic-reactor/core",
3
- "version": "1.6.3",
3
+ "version": "1.6.4",
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",
@@ -41,7 +41,7 @@
41
41
  "zustand": "^4.5"
42
42
  },
43
43
  "devDependencies": {
44
- "@ic-reactor/parser": "^0.1.1"
44
+ "@ic-reactor/parser": "^0.1.2"
45
45
  },
46
46
  "scripts": {
47
47
  "test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" jest",
@@ -56,5 +56,5 @@
56
56
  "engines": {
57
57
  "node": ">=10"
58
58
  },
59
- "gitHead": "1837563a23d243a72a7979e09dd89a128ac23e16"
59
+ "gitHead": "5d30e3c8027caa50babc82409fead2169ab6adbd"
60
60
  }