weavedb-node-client 0.5.7 → 0.5.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.
Files changed (2) hide show
  1. package/index.js +34 -3
  2. 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,
@@ -23,9 +39,11 @@ class SDK extends Base {
23
39
  EthWallet,
24
40
  web3,
25
41
  arweave,
42
+ arweave_wallet,
26
43
  }) {
27
44
  super()
28
45
  this.contractTxId = contractTxId
46
+ this.arweave_wallet = arweave_wallet
29
47
  this.arweave = Arweave.init(arweave)
30
48
  this.client = new weavedb_proto.DB(rpc, grpc.credentials.createInsecure())
31
49
  if (typeof window === "object") {
@@ -42,10 +60,21 @@ class SDK extends Base {
42
60
  if (!isNil(EthWallet)) this.setEthWallet(EthWallet)
43
61
  }
44
62
 
45
- async _request(func, query) {
63
+ parseQuery(func, query) {
64
+ let nocache = false
65
+ if (includes(func)(reads) && is(Boolean, last(query))) {
66
+ nocache = last(query)
67
+ query = init(query)
68
+ }
69
+ return { nocache, query }
70
+ }
71
+
72
+ async _request(func, query, nocache = false) {
73
+ if (!includes(func)(reads)) nocache = false
46
74
  const request = {
47
75
  method: `${func}@${this.contractTxId}`,
48
76
  query: JSON.stringify(query),
77
+ nocache,
49
78
  }
50
79
  const _query = () =>
51
80
  new Promise(ret => {
@@ -71,7 +100,9 @@ class SDK extends Base {
71
100
  }
72
101
 
73
102
  async request(func, ...query) {
74
- return await this._request(func, query)
103
+ let nocache = false
104
+ ;({ nocache, query } = this.parseQuery(func, query))
105
+ return await this._request(func, query, nocache)
75
106
  }
76
107
 
77
108
  async getNonce(addr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "weavedb-node-client",
3
- "version": "0.5.7",
3
+ "version": "0.5.9",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "engines": {