@ic-reactor/core 1.5.4-beta.2 → 1.6.0-beta.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 +1 -1
- package/dist/classes/candid/index.d.ts +5 -2
- package/dist/classes/candid/index.js +22 -18
- package/dist/utils/helper.d.ts +1 -0
- package/dist/utils/helper.js +11 -1
- package/package.json +5 -2
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.5.
|
|
22
|
+
<script src="https://github.com/B3Pay/ic-reactor/releases/download/v1.5.4-beta.2/ic-reactor-core.min.js"></script>
|
|
23
23
|
```
|
|
24
24
|
|
|
25
25
|
### Using `createReactorCore`
|
|
@@ -1,15 +1,18 @@
|
|
|
1
|
+
/// <reference path="../../../src/classes/candid/parser.d.ts" />
|
|
1
2
|
import { HttpAgent } from "@dfinity/agent";
|
|
2
3
|
import type { CanisterId, CandidAdapterParameters, CandidDefenition } from "../../types";
|
|
3
4
|
export declare class CandidAdapter {
|
|
4
5
|
agent: HttpAgent;
|
|
5
6
|
didjsCanisterId: string;
|
|
7
|
+
parserModule?: typeof import("@ic-reactor/parser");
|
|
6
8
|
unsubscribeAgent: () => void;
|
|
7
9
|
constructor({ agentManager, agent, didjsCanisterId, }: CandidAdapterParameters);
|
|
10
|
+
initializeParser(): Promise<void>;
|
|
8
11
|
private getDefaultDidJsId;
|
|
9
12
|
getCandidDefinition(canisterId: CanisterId): Promise<CandidDefenition>;
|
|
10
13
|
getFromMetadata(canisterId: CanisterId): Promise<string | undefined>;
|
|
11
14
|
getFromTmpHack(canisterId: CanisterId): Promise<string | undefined>;
|
|
12
|
-
|
|
15
|
+
dynamicEvalJs(data: string): Promise<CandidDefenition>;
|
|
13
16
|
fetchDidTojs(candidSource: string): Promise<[string]>;
|
|
14
|
-
parseDidToJs(candidSource: string):
|
|
17
|
+
parseDidToJs(candidSource: string): string;
|
|
15
18
|
}
|
|
@@ -35,6 +35,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
35
35
|
exports.CandidAdapter = void 0;
|
|
36
36
|
const agent_1 = require("@dfinity/agent");
|
|
37
37
|
const constants_1 = require("../../utils/constants");
|
|
38
|
+
const utils_1 = require("../../utils");
|
|
38
39
|
class CandidAdapter {
|
|
39
40
|
constructor({ agentManager, agent, didjsCanisterId, }) {
|
|
40
41
|
this.unsubscribeAgent = () => { };
|
|
@@ -53,6 +54,17 @@ class CandidAdapter {
|
|
|
53
54
|
}
|
|
54
55
|
this.didjsCanisterId = didjsCanisterId || this.getDefaultDidJsId();
|
|
55
56
|
}
|
|
57
|
+
initializeParser() {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
59
|
+
try {
|
|
60
|
+
this.parserModule = yield Promise.resolve().then(() => __importStar(require("@ic-reactor/parser")));
|
|
61
|
+
yield this.parserModule.default();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
throw new Error(`Error initializing parser: ${error}`);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
56
68
|
getDefaultDidJsId() {
|
|
57
69
|
var _a, _b;
|
|
58
70
|
return ((_b = (_a = this.agent).isLocal) === null || _b === void 0 ? void 0 : _b.call(_a)) === true
|
|
@@ -67,13 +79,13 @@ class CandidAdapter {
|
|
|
67
79
|
return undefined;
|
|
68
80
|
});
|
|
69
81
|
if (fromMetadata)
|
|
70
|
-
return this.
|
|
82
|
+
return this.dynamicEvalJs(fromMetadata);
|
|
71
83
|
// Second attempt: Try the temporary hack method
|
|
72
84
|
const fromTmpHack = yield this.getFromTmpHack(canisterId).catch(() => {
|
|
73
85
|
return undefined;
|
|
74
86
|
});
|
|
75
87
|
if (fromTmpHack)
|
|
76
|
-
return this.
|
|
88
|
+
return this.dynamicEvalJs(fromTmpHack);
|
|
77
89
|
// If both attempts fail, throw an error
|
|
78
90
|
throw "Failed to retrieve Candid definition by any method.";
|
|
79
91
|
}
|
|
@@ -104,12 +116,12 @@ class CandidAdapter {
|
|
|
104
116
|
return (yield actor.__get_candid_interface_tmp_hack());
|
|
105
117
|
});
|
|
106
118
|
}
|
|
107
|
-
|
|
119
|
+
dynamicEvalJs(data) {
|
|
108
120
|
return __awaiter(this, void 0, void 0, function* () {
|
|
109
121
|
try {
|
|
110
122
|
let candidDef = "";
|
|
111
123
|
try {
|
|
112
|
-
candidDef =
|
|
124
|
+
candidDef = this.parseDidToJs(data);
|
|
113
125
|
}
|
|
114
126
|
catch (error) {
|
|
115
127
|
candidDef = (yield this.fetchDidTojs(data))[0];
|
|
@@ -117,11 +129,10 @@ class CandidAdapter {
|
|
|
117
129
|
if (JSON.stringify(candidDef) === JSON.stringify([])) {
|
|
118
130
|
throw new Error("Cannot compile Candid to JavaScript");
|
|
119
131
|
}
|
|
120
|
-
|
|
121
|
-
return eval('import("' + dataUri + '")');
|
|
132
|
+
return (0, utils_1.importCandidDefinition)(candidDef);
|
|
122
133
|
}
|
|
123
134
|
catch (error) {
|
|
124
|
-
throw new Error(
|
|
135
|
+
throw new Error(`Error evaluating Candid definition: ${error}`);
|
|
125
136
|
}
|
|
126
137
|
});
|
|
127
138
|
}
|
|
@@ -138,17 +149,10 @@ class CandidAdapter {
|
|
|
138
149
|
});
|
|
139
150
|
}
|
|
140
151
|
parseDidToJs(candidSource) {
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
yield parser.default();
|
|
146
|
-
return parser.did_to_js(candidSource);
|
|
147
|
-
}
|
|
148
|
-
catch (error) {
|
|
149
|
-
throw new Error("@ic-reactor/parser module is not available");
|
|
150
|
-
}
|
|
151
|
-
});
|
|
152
|
+
if (!this.parserModule) {
|
|
153
|
+
throw new Error("Parser module not available");
|
|
154
|
+
}
|
|
155
|
+
return this.parserModule.did_to_js(candidSource);
|
|
152
156
|
}
|
|
153
157
|
}
|
|
154
158
|
exports.CandidAdapter = CandidAdapter;
|
package/dist/utils/helper.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare function createStoreWithOptionalDevtools<T>(initialState: T, conf
|
|
|
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
9
|
export declare const isInLocalOrDevelopment: () => boolean;
|
|
9
10
|
export declare const getProcessEnvNetwork: () => string;
|
|
10
11
|
export declare function isQuery(func: IDL.FuncClass): boolean;
|
package/dist/utils/helper.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.isQuery = exports.getProcessEnvNetwork = exports.isInLocalOrDevelopment = exports.createStoreWithOptionalDevtools = void 0;
|
|
3
|
+
exports.stringToHash = exports.generateActorHash = exports.generateHash = exports.generateRequestHash = exports.jsonToString = exports.isQuery = exports.getProcessEnvNetwork = exports.isInLocalOrDevelopment = exports.importCandidDefinition = exports.createStoreWithOptionalDevtools = void 0;
|
|
4
4
|
const agent_1 = require("@dfinity/agent");
|
|
5
5
|
const middleware_1 = require("zustand/middleware");
|
|
6
6
|
const vanilla_1 = require("zustand/vanilla");
|
|
@@ -15,6 +15,16 @@ function createStoreWithOptionalDevtools(initialState, config) {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.createStoreWithOptionalDevtools = createStoreWithOptionalDevtools;
|
|
18
|
+
const importCandidDefinition = (candidDef) => {
|
|
19
|
+
try {
|
|
20
|
+
const dataUri = "data:text/javascript;charset=utf-8," + encodeURIComponent(candidDef);
|
|
21
|
+
return eval('import("' + dataUri + '")');
|
|
22
|
+
}
|
|
23
|
+
catch (error) {
|
|
24
|
+
throw new Error("Error importing Candid definition");
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
exports.importCandidDefinition = importCandidDefinition;
|
|
18
28
|
const isInLocalOrDevelopment = () => {
|
|
19
29
|
return typeof process !== "undefined" && process.env.DFX_NETWORK === "local";
|
|
20
30
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.6.0-beta.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",
|
|
@@ -40,6 +40,9 @@
|
|
|
40
40
|
"@dfinity/principal": "^1.2",
|
|
41
41
|
"zustand": "^4.5"
|
|
42
42
|
},
|
|
43
|
+
"devDependencies": {
|
|
44
|
+
"@ic-reactor/parser": "^0.1.0-beta.0"
|
|
45
|
+
},
|
|
43
46
|
"scripts": {
|
|
44
47
|
"test": "NODE_OPTIONS=\"$NODE_OPTIONS --experimental-vm-modules\" npx jest",
|
|
45
48
|
"start": "tsc watch",
|
|
@@ -52,5 +55,5 @@
|
|
|
52
55
|
"engines": {
|
|
53
56
|
"node": ">=10"
|
|
54
57
|
},
|
|
55
|
-
"gitHead": "
|
|
58
|
+
"gitHead": "4911f0639b420406550150f789f34ecf3e6167c1"
|
|
56
59
|
}
|