@ic-reactor/core 1.6.2 → 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.
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.6.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.6.2/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
|
|
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
|
-
|
|
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
|
-
|
|
77
|
-
throw new Error(
|
|
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
|
});
|
|
@@ -11,4 +11,4 @@ export interface CandidDefenition {
|
|
|
11
11
|
idl: typeof IDL;
|
|
12
12
|
}) => never[];
|
|
13
13
|
}
|
|
14
|
-
export type ReactorParser = typeof import("@ic-reactor/parser") | typeof import("@ic-reactor/parser/dist/
|
|
14
|
+
export type ReactorParser = typeof import("@ic-reactor/parser") | typeof import("@ic-reactor/parser/dist/nodejs") | typeof import("@ic-reactor/parser/dist/bundler");
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -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) =>
|
|
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
|
+
"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.
|
|
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": "
|
|
59
|
+
"gitHead": "5d30e3c8027caa50babc82409fead2169ab6adbd"
|
|
60
60
|
}
|