@mentaproject/client 0.0.8 → 0.0.9
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/dist/utils/toJSON.js +23 -15
- package/package.json +1 -1
- package/test.ts +8 -1
package/dist/utils/toJSON.js
CHANGED
|
@@ -27,6 +27,7 @@ function convertBigintsToStrings(obj) {
|
|
|
27
27
|
}
|
|
28
28
|
export async function toJSON({ obj, depth = 0 }) {
|
|
29
29
|
const data = {};
|
|
30
|
+
const promises = [];
|
|
30
31
|
for (const key in obj) {
|
|
31
32
|
// skip class related properties
|
|
32
33
|
if (key === "toJSON" || key === "constructor" || key === "rpcClient")
|
|
@@ -36,34 +37,41 @@ export async function toJSON({ obj, depth = 0 }) {
|
|
|
36
37
|
// do not fetch getters if depth is 0
|
|
37
38
|
if (depth === 0)
|
|
38
39
|
continue;
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
;
|
|
47
|
-
data[key] = value;
|
|
48
|
-
continue;
|
|
40
|
+
const promise = async () => {
|
|
41
|
+
const value = await obj[key]();
|
|
42
|
+
// if the value is a class instance, convert it to JSON recursively
|
|
43
|
+
if (typeof value === "object" && isClassInstance(value))
|
|
44
|
+
return data[key] = await toJSON({ obj: value, depth: depth - 1 });
|
|
45
|
+
data[key] = value;
|
|
46
|
+
};
|
|
47
|
+
promises.push(promise());
|
|
49
48
|
}
|
|
49
|
+
;
|
|
50
50
|
if (typeof prop === "object" && isClassInstance(prop)) {
|
|
51
51
|
// If depth is 0, just flatten the object using recursion
|
|
52
52
|
if (depth === 0) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
const promise = async () => {
|
|
54
|
+
data[key] = await toJSON({
|
|
55
|
+
obj: prop,
|
|
56
|
+
depth: depth - 1
|
|
57
|
+
});
|
|
58
|
+
};
|
|
59
|
+
promises.push(promise());
|
|
57
60
|
continue;
|
|
58
61
|
}
|
|
59
62
|
;
|
|
60
63
|
// If depth is not 0, fetch the object
|
|
61
|
-
|
|
64
|
+
const promise = async () => {
|
|
65
|
+
data[key] = await prop.toJSON({ depth: depth - 1 });
|
|
66
|
+
};
|
|
67
|
+
promises.push(promise());
|
|
62
68
|
continue;
|
|
63
69
|
}
|
|
70
|
+
;
|
|
64
71
|
data[key] = prop;
|
|
65
72
|
}
|
|
66
73
|
;
|
|
74
|
+
await Promise.all(promises);
|
|
67
75
|
return convertBigintsToStrings(data);
|
|
68
76
|
}
|
|
69
77
|
;
|
package/package.json
CHANGED
package/test.ts
CHANGED
|
@@ -9,7 +9,14 @@ const viemAccount = privateKeyToAccount(generatePrivateKey());
|
|
|
9
9
|
|
|
10
10
|
const client = new MentaClient({
|
|
11
11
|
account: viemAccount,
|
|
12
|
-
transport: http("https://red-nameless-panorama.quiknode.pro/0f30278c4c66afdc9f8679975e13cd5a92c7d937/"
|
|
12
|
+
transport: http("https://red-nameless-panorama.quiknode.pro/0f30278c4c66afdc9f8679975e13cd5a92c7d937/", {
|
|
13
|
+
batch: {
|
|
14
|
+
batchSize: 15,
|
|
15
|
+
wait: 1000
|
|
16
|
+
},
|
|
17
|
+
onFetchRequest: (r) => console.log(`>>: ${r.url}`),
|
|
18
|
+
// onFetchResponse: (r) => console.log(`<<: ${r.url}`),
|
|
19
|
+
}),
|
|
13
20
|
chain: mainnet
|
|
14
21
|
});
|
|
15
22
|
|