weavedb-node-client 0.5.7 → 0.5.8
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/index.js +33 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const { all, complement, isNil } = require("ramda")
|
|
1
|
+
const { init, all, complement, isNil, is, last, includes } = require("ramda")
|
|
2
2
|
const Base = require("weavedb-base")
|
|
3
3
|
const PROTO_PATH = __dirname + "/weavedb.proto"
|
|
4
4
|
const grpc = require("@grpc/grpc-js")
|
|
@@ -13,6 +13,22 @@ const packageDefinition = protoLoader.loadSync(PROTO_PATH, {
|
|
|
13
13
|
const weavedb_proto = grpc.loadPackageDefinition(packageDefinition).weavedb
|
|
14
14
|
let Arweave = require("arweave")
|
|
15
15
|
|
|
16
|
+
const reads = [
|
|
17
|
+
"get",
|
|
18
|
+
"cget",
|
|
19
|
+
"getIndexes",
|
|
20
|
+
"getCrons",
|
|
21
|
+
"getSchema",
|
|
22
|
+
"getRules",
|
|
23
|
+
"getIds",
|
|
24
|
+
"getOwner",
|
|
25
|
+
"getAddressLink",
|
|
26
|
+
"getAlgorithms",
|
|
27
|
+
"getLinkedContract",
|
|
28
|
+
"getEvolve",
|
|
29
|
+
"getVersion",
|
|
30
|
+
]
|
|
31
|
+
|
|
16
32
|
class SDK extends Base {
|
|
17
33
|
constructor({
|
|
18
34
|
rpc,
|
|
@@ -42,10 +58,22 @@ class SDK extends Base {
|
|
|
42
58
|
if (!isNil(EthWallet)) this.setEthWallet(EthWallet)
|
|
43
59
|
}
|
|
44
60
|
|
|
45
|
-
|
|
61
|
+
parseQuery(func, query) {
|
|
62
|
+
let nocache = false
|
|
63
|
+
if (includes(func)(reads) && is(Boolean, last(query))) {
|
|
64
|
+
nocache = last(query)
|
|
65
|
+
query = init(query)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return { nocache, query }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async _request(func, query, nocache = false) {
|
|
72
|
+
if (!includes(func)(reads)) nocache = false
|
|
46
73
|
const request = {
|
|
47
74
|
method: `${func}@${this.contractTxId}`,
|
|
48
75
|
query: JSON.stringify(query),
|
|
76
|
+
nocache,
|
|
49
77
|
}
|
|
50
78
|
const _query = () =>
|
|
51
79
|
new Promise(ret => {
|
|
@@ -71,7 +99,9 @@ class SDK extends Base {
|
|
|
71
99
|
}
|
|
72
100
|
|
|
73
101
|
async request(func, ...query) {
|
|
74
|
-
|
|
102
|
+
let nocache = false
|
|
103
|
+
;({ nocache, query } = this.parseQuery(func, query))
|
|
104
|
+
return await this._request(func, query, nocache)
|
|
75
105
|
}
|
|
76
106
|
|
|
77
107
|
async getNonce(addr) {
|