@ic-reactor/core 1.5.4-beta.0 → 1.5.4-beta.2
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.
|
@@ -7,7 +7,9 @@ export declare class CandidAdapter {
|
|
|
7
7
|
constructor({ agentManager, agent, didjsCanisterId, }: CandidAdapterParameters);
|
|
8
8
|
private getDefaultDidJsId;
|
|
9
9
|
getCandidDefinition(canisterId: CanisterId): Promise<CandidDefenition>;
|
|
10
|
-
getFromMetadata(canisterId: CanisterId): Promise<
|
|
11
|
-
getFromTmpHack(canisterId: CanisterId): Promise<
|
|
12
|
-
|
|
10
|
+
getFromMetadata(canisterId: CanisterId): Promise<string | undefined>;
|
|
11
|
+
getFromTmpHack(canisterId: CanisterId): Promise<string | undefined>;
|
|
12
|
+
evaluateJs(data: string): Promise<CandidDefenition>;
|
|
13
|
+
fetchDidTojs(candidSource: string): Promise<[string]>;
|
|
14
|
+
parseDidToJs(candidSource: string): Promise<string>;
|
|
13
15
|
}
|
|
@@ -1,4 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -44,13 +67,13 @@ class CandidAdapter {
|
|
|
44
67
|
return undefined;
|
|
45
68
|
});
|
|
46
69
|
if (fromMetadata)
|
|
47
|
-
return fromMetadata;
|
|
70
|
+
return this.evaluateJs(fromMetadata);
|
|
48
71
|
// Second attempt: Try the temporary hack method
|
|
49
72
|
const fromTmpHack = yield this.getFromTmpHack(canisterId).catch(() => {
|
|
50
73
|
return undefined;
|
|
51
74
|
});
|
|
52
75
|
if (fromTmpHack)
|
|
53
|
-
return fromTmpHack;
|
|
76
|
+
return this.evaluateJs(fromTmpHack);
|
|
54
77
|
// If both attempts fail, throw an error
|
|
55
78
|
throw "Failed to retrieve Candid definition by any method.";
|
|
56
79
|
}
|
|
@@ -66,8 +89,7 @@ class CandidAdapter {
|
|
|
66
89
|
canisterId: canisterId,
|
|
67
90
|
paths: ["candid"],
|
|
68
91
|
});
|
|
69
|
-
|
|
70
|
-
return did ? this.didTojs(did) : undefined;
|
|
92
|
+
return status.get("candid");
|
|
71
93
|
});
|
|
72
94
|
}
|
|
73
95
|
getFromTmpHack(canisterId) {
|
|
@@ -79,11 +101,31 @@ class CandidAdapter {
|
|
|
79
101
|
agent: this.agent,
|
|
80
102
|
canisterId,
|
|
81
103
|
});
|
|
82
|
-
|
|
83
|
-
return data ? this.didTojs(data) : undefined;
|
|
104
|
+
return (yield actor.__get_candid_interface_tmp_hack());
|
|
84
105
|
});
|
|
85
106
|
}
|
|
86
|
-
|
|
107
|
+
evaluateJs(data) {
|
|
108
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
109
|
+
try {
|
|
110
|
+
let candidDef = "";
|
|
111
|
+
try {
|
|
112
|
+
candidDef = yield this.parseDidToJs(data);
|
|
113
|
+
}
|
|
114
|
+
catch (error) {
|
|
115
|
+
candidDef = (yield this.fetchDidTojs(data))[0];
|
|
116
|
+
}
|
|
117
|
+
if (JSON.stringify(candidDef) === JSON.stringify([])) {
|
|
118
|
+
throw new Error("Cannot compile Candid to JavaScript");
|
|
119
|
+
}
|
|
120
|
+
const dataUri = "data:text/javascript;charset=utf-8," + encodeURIComponent(candidDef);
|
|
121
|
+
return eval('import("' + dataUri + '")');
|
|
122
|
+
}
|
|
123
|
+
catch (error) {
|
|
124
|
+
throw new Error("Error evaluating Candid definition");
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}
|
|
128
|
+
fetchDidTojs(candidSource) {
|
|
87
129
|
return __awaiter(this, void 0, void 0, function* () {
|
|
88
130
|
const didjsInterface = ({ IDL }) => IDL.Service({
|
|
89
131
|
did_to_js: IDL.Func([IDL.Text], [IDL.Opt(IDL.Text)], ["query"]),
|
|
@@ -92,13 +134,20 @@ class CandidAdapter {
|
|
|
92
134
|
agent: this.agent,
|
|
93
135
|
canisterId: this.didjsCanisterId,
|
|
94
136
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
137
|
+
return didjs.did_to_js(candidSource);
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
parseDidToJs(candidSource) {
|
|
141
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
142
|
+
try {
|
|
143
|
+
// This is a dynamic import if the module is available in the environment
|
|
144
|
+
const parser = yield Promise.resolve().then(() => __importStar(require("@ic-reactor/parser")));
|
|
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");
|
|
98
150
|
}
|
|
99
|
-
const dataUri = "data:text/javascript;charset=utf-8," +
|
|
100
|
-
encodeURIComponent(js[0]);
|
|
101
|
-
return eval('import("' + dataUri + '")');
|
|
102
151
|
});
|
|
103
152
|
}
|
|
104
153
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ic-reactor/core",
|
|
3
|
-
"version": "1.5.4-beta.
|
|
3
|
+
"version": "1.5.4-beta.2",
|
|
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",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"engines": {
|
|
53
53
|
"node": ">=10"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "bf632e49a5a4d1128531a6fc50b5c2f97dee58c9"
|
|
56
56
|
}
|