wao 0.3.1 → 0.4.1
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/cjs/accounts.js +12 -12
- package/cjs/ao.js +6 -1
- package/cjs/aoconnect.js +414 -1475
- package/cjs/ar.js +39 -65
- package/cjs/armem.js +54 -0
- package/cjs/gql.js +393 -0
- package/cjs/index.js +7 -0
- package/cjs/tao.js +9 -9
- package/cjs/tar.js +280 -0
- package/cjs/test.js +57 -3
- package/cjs/tgql.js +733 -0
- package/cjs/utils.js +42 -8
- package/cjs/weavedrive.js +979 -0
- package/esm/accounts.js +36 -30
- package/esm/ao.js +4 -1
- package/esm/aoconnect.js +66 -808
- package/esm/ar.js +8 -24
- package/esm/armem.js +42 -0
- package/esm/gql.js +219 -0
- package/esm/index.js +2 -1
- package/esm/tao.js +7 -9
- package/esm/tar.js +106 -0
- package/esm/test.js +13 -2
- package/esm/tgql.js +282 -0
- package/esm/utils.js +10 -14
- package/esm/weavedrive.js +709 -0
- package/package.json +1 -1
package/esm/tgql.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { reverse, includes, map, is, isNil, last, clone, pick } from "ramda"
|
|
2
|
+
|
|
3
|
+
const subs = {
|
|
4
|
+
owner: ["address", "key"],
|
|
5
|
+
fee: ["winston", "ar"],
|
|
6
|
+
quantity: ["winston", "ar"],
|
|
7
|
+
data: ["size", "type"],
|
|
8
|
+
tags: ["name", "value"],
|
|
9
|
+
block: ["id", "timestamp", "height", "previous"],
|
|
10
|
+
parent: ["id"],
|
|
11
|
+
}
|
|
12
|
+
const field = (key, val = true) => {
|
|
13
|
+
if (includes(key, ["id", "anchor", "signature", "recipient"])) {
|
|
14
|
+
return { key }
|
|
15
|
+
} else if (subs[key]) {
|
|
16
|
+
let _subs = []
|
|
17
|
+
if (val === true) val = subs[key]
|
|
18
|
+
else if (is(Object, val) && !is(Array, val)) {
|
|
19
|
+
let _val = []
|
|
20
|
+
let isTrue = false
|
|
21
|
+
let isFalse = false
|
|
22
|
+
for (const k in val)
|
|
23
|
+
if (val[k] === true) isTrue = true
|
|
24
|
+
else if (val[k] === false) isFalse = true
|
|
25
|
+
if (!isTrue && isFalse) {
|
|
26
|
+
for (const k of subs[key]) if (val[k] !== false) _val.push(k)
|
|
27
|
+
} else {
|
|
28
|
+
for (const k in val) if (val[k] === true) _val.push(k)
|
|
29
|
+
}
|
|
30
|
+
val = _val
|
|
31
|
+
} else if (!is(Array, val)) val = subs[key]
|
|
32
|
+
for (const v2 of val) {
|
|
33
|
+
if (is(String, v2) && includes(v2, subs[key])) _subs.push(v2)
|
|
34
|
+
}
|
|
35
|
+
if (_subs.length === 0) return null
|
|
36
|
+
return { key, subs: _subs }
|
|
37
|
+
}
|
|
38
|
+
return null
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const field_blocks = (key, val = true) => {
|
|
42
|
+
if (includes(key, ["id", "timestamp", "height", "previous"])) {
|
|
43
|
+
return { key }
|
|
44
|
+
}
|
|
45
|
+
return null
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
export default class GQL {
|
|
49
|
+
constructor({ mem }) {
|
|
50
|
+
this.mem = mem
|
|
51
|
+
}
|
|
52
|
+
async txs(opt = {}) {
|
|
53
|
+
let block_max = null
|
|
54
|
+
let block_min = null
|
|
55
|
+
let _block = {}
|
|
56
|
+
if (is(Number, opt.block)) {
|
|
57
|
+
_block = { min: opt.block, max: opt.block }
|
|
58
|
+
} else if (is(Array, opt.block) && opt.block.length > 0) {
|
|
59
|
+
_block = {}
|
|
60
|
+
if (!isNil(opt.block[0])) _block.min = opt.block[0]
|
|
61
|
+
if (!isNil(opt.block[1])) _block.max = opt.block[1]
|
|
62
|
+
}
|
|
63
|
+
let first = opt.first ?? 20
|
|
64
|
+
let tags = []
|
|
65
|
+
for (const k in opt.tags ?? {}) {
|
|
66
|
+
if (is(String, opt.tags[k])) {
|
|
67
|
+
tags.push({ name: k, values: [opt.tags[k]] })
|
|
68
|
+
} else if (is(Array, opt.tags[k])) {
|
|
69
|
+
tags.push({ name: k, values: opt.tags[k] })
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
let recipients = null
|
|
73
|
+
if (is(Array, opt.recipients)) recipients = opt.recipients
|
|
74
|
+
else if (is(String, opt.recipient)) recipients = [opt.recipient]
|
|
75
|
+
|
|
76
|
+
let owners = null
|
|
77
|
+
if (is(Array, opt.owners)) owners = opt.owners
|
|
78
|
+
else if (is(String, opt.owner)) owners = [opt.owner]
|
|
79
|
+
|
|
80
|
+
let ids = null
|
|
81
|
+
if (is(Array, opt.ids)) ids = opt.ids
|
|
82
|
+
else if (is(String, opt.id)) ids = [opt.id]
|
|
83
|
+
|
|
84
|
+
let data = []
|
|
85
|
+
let blocks = this.mem.blocks
|
|
86
|
+
if (opt.asc !== true) blocks = reverse(blocks)
|
|
87
|
+
let count = 0
|
|
88
|
+
let after = false
|
|
89
|
+
for (const v of blocks) {
|
|
90
|
+
const block = clone(this.mem.blockmap[v])
|
|
91
|
+
if (!isNil(_block.min) && block.height < _block.min) continue
|
|
92
|
+
if (!isNil(_block.max) && block.height > _block.max) continue
|
|
93
|
+
let txs = block.txs
|
|
94
|
+
if (opt.asc !== true) txs = reverse(txs)
|
|
95
|
+
for (const v2 of txs) {
|
|
96
|
+
if (!isNil(opt.after) && opt.after === v2) {
|
|
97
|
+
after = true
|
|
98
|
+
break
|
|
99
|
+
}
|
|
100
|
+
if (!isNil(opt.after) && count === 0 && !after) continue
|
|
101
|
+
let tx = this.mem.txs[v2]
|
|
102
|
+
if (!isNil(ids) && ids.length > 0) {
|
|
103
|
+
if (!includes(tx.id, ids)) continue
|
|
104
|
+
}
|
|
105
|
+
if (!isNil(owners) && owners.length > 0) {
|
|
106
|
+
if (!includes(tx.owner, owners)) continue
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (!isNil(recipients) && recipients.length > 0) {
|
|
110
|
+
if (!includes(tx.recipient, recipients)) continue
|
|
111
|
+
}
|
|
112
|
+
let tag_unmatch = false
|
|
113
|
+
for (const v of tags) {
|
|
114
|
+
let ex = false
|
|
115
|
+
for (const v2 of tx.tags) {
|
|
116
|
+
if (v2.name === v.name && includes(v2.value, v.values)) {
|
|
117
|
+
ex = true
|
|
118
|
+
break
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
if (!ex) {
|
|
122
|
+
tag_unmatch = true
|
|
123
|
+
break
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (tag_unmatch) continue
|
|
127
|
+
let _tx = {
|
|
128
|
+
cursor: tx.id,
|
|
129
|
+
...tx,
|
|
130
|
+
block: pick(["id", "timestamp", "height", "previous"], block),
|
|
131
|
+
anchor: tx.anchor ?? "",
|
|
132
|
+
signature: tx.signature ?? "",
|
|
133
|
+
owner: { address: tx.owner, key: "" },
|
|
134
|
+
fee: { ar: 0, winston: 0 },
|
|
135
|
+
quantity: { ar: 0, winston: 0 },
|
|
136
|
+
data: { size: 0, type: "" },
|
|
137
|
+
}
|
|
138
|
+
if (!isNil(opt.fields)) {
|
|
139
|
+
let _tx2 = { cursor: tx.id }
|
|
140
|
+
let fields = []
|
|
141
|
+
if (is(Array, opt.fields) && opt.fields.length > 0) {
|
|
142
|
+
for (const v of opt.fields) {
|
|
143
|
+
if (is(String, v)) {
|
|
144
|
+
const fld = field(v)
|
|
145
|
+
if (fld) fields.push(fld)
|
|
146
|
+
} else if (is(Object, v) && !is(Array, v)) {
|
|
147
|
+
for (const k in v) {
|
|
148
|
+
const fld = field(k, v[k])
|
|
149
|
+
if (fld) fields.push(fld)
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
} else if (is(Object, opt.fields) && !is(Array, opt.fields)) {
|
|
154
|
+
for (const k in opt.fields) {
|
|
155
|
+
const fld = field(k, opt.fields[k])
|
|
156
|
+
if (fld) fields.push(fld)
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
for (const f of fields) {
|
|
160
|
+
if (isNil(f.subs)) {
|
|
161
|
+
_tx2[f.key] = _tx[f.key] ?? ""
|
|
162
|
+
} else {
|
|
163
|
+
let subs = {}
|
|
164
|
+
_tx2[f.key] = {}
|
|
165
|
+
if (is(Array, _tx[f.key])) {
|
|
166
|
+
_tx2[f.key] = map(pick(f.subs))(_tx[f.key])
|
|
167
|
+
} else {
|
|
168
|
+
for (const f2 of f.subs) {
|
|
169
|
+
_tx2[f.key][f2] = _tx[f.key][f2] ?? ""
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
_tx = _tx2
|
|
175
|
+
}
|
|
176
|
+
data.push(_tx)
|
|
177
|
+
count += 1
|
|
178
|
+
if (count >= first) break
|
|
179
|
+
}
|
|
180
|
+
if (count >= first) break
|
|
181
|
+
}
|
|
182
|
+
if (opt.next === true) {
|
|
183
|
+
let cursor = null
|
|
184
|
+
if (data.length > 0) cursor = last(data).cursor
|
|
185
|
+
const next = !cursor
|
|
186
|
+
? null
|
|
187
|
+
: async () => {
|
|
188
|
+
let _opt = clone(opt)
|
|
189
|
+
_opt.after = cursor
|
|
190
|
+
return await this.txs(_opt)
|
|
191
|
+
}
|
|
192
|
+
return { data, next }
|
|
193
|
+
} else {
|
|
194
|
+
return data
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
async blocks(opt = {}) {
|
|
198
|
+
let block_max = null
|
|
199
|
+
let block_min = null
|
|
200
|
+
let _block = {}
|
|
201
|
+
if (is(Number, opt.block)) {
|
|
202
|
+
_block = { min: opt.block, max: opt.block }
|
|
203
|
+
} else if (is(Array, opt.block) && opt.block.length > 0) {
|
|
204
|
+
_block = {}
|
|
205
|
+
if (!isNil(opt.block[0])) _block.min = opt.block[0]
|
|
206
|
+
if (!isNil(opt.block[1])) _block.max = opt.block[1]
|
|
207
|
+
}
|
|
208
|
+
let first = opt.first ?? 20
|
|
209
|
+
|
|
210
|
+
let ids = null
|
|
211
|
+
if (is(Array, opt.ids)) ids = opt.ids
|
|
212
|
+
else if (is(String, opt.id)) ids = [opt.id]
|
|
213
|
+
|
|
214
|
+
let data = []
|
|
215
|
+
let blocks = this.mem.blocks
|
|
216
|
+
if (opt.asc !== true) blocks = reverse(blocks)
|
|
217
|
+
let count = 0
|
|
218
|
+
let after = false
|
|
219
|
+
for (const v of blocks) {
|
|
220
|
+
let block = clone({ ...this.mem.blockmap[v], cursor: v })
|
|
221
|
+
delete block.txs
|
|
222
|
+
if (!isNil(_block.min) && block.height < _block.min) continue
|
|
223
|
+
if (!isNil(_block.max) && block.height > _block.max) continue
|
|
224
|
+
if (!isNil(ids) && ids.length > 0) if (!includes(v.id, ids)) continue
|
|
225
|
+
if (!isNil(opt.fields)) {
|
|
226
|
+
let block2 = { cursor: block.id }
|
|
227
|
+
let fields = []
|
|
228
|
+
if (is(Array, opt.fields) && opt.fields.length > 0) {
|
|
229
|
+
for (const v of opt.fields) {
|
|
230
|
+
if (is(String, v)) {
|
|
231
|
+
const fld = field_blocks(v)
|
|
232
|
+
if (fld) fields.push(fld)
|
|
233
|
+
} else if (is(Object, v) && !is(Array, v)) {
|
|
234
|
+
for (const k in v) {
|
|
235
|
+
const fld = field_blocks(k, v[k])
|
|
236
|
+
if (fld) fields.push(fld)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
} else if (is(Object, opt.fields) && !is(Array, opt.fields)) {
|
|
241
|
+
for (const k in opt.fields) {
|
|
242
|
+
const fld = field_blocks(k, opt.fields[k])
|
|
243
|
+
if (fld) fields.push(fld)
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
for (const f of fields) {
|
|
247
|
+
if (isNil(f.subs)) {
|
|
248
|
+
block2[f.key] = block[f.key] ?? ""
|
|
249
|
+
} else {
|
|
250
|
+
let subs = {}
|
|
251
|
+
block2[f.key] = {}
|
|
252
|
+
if (is(Array, block[f.key])) {
|
|
253
|
+
block2[f.key] = map(pick(f.subs))(block[f.key])
|
|
254
|
+
} else {
|
|
255
|
+
for (const f2 of f.subs) {
|
|
256
|
+
block2[f.key][f2] = block[f.key][f2] ?? ""
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
block = block2
|
|
262
|
+
}
|
|
263
|
+
data.push(block)
|
|
264
|
+
count += 1
|
|
265
|
+
if (count >= first) break
|
|
266
|
+
}
|
|
267
|
+
if (opt.next === true) {
|
|
268
|
+
let cursor = null
|
|
269
|
+
if (data.length > 0) cursor = last(data).cursor
|
|
270
|
+
const next = !cursor
|
|
271
|
+
? null
|
|
272
|
+
: async () => {
|
|
273
|
+
let _opt = clone(opt)
|
|
274
|
+
_opt.after = cursor
|
|
275
|
+
return await this.txs(_opt)
|
|
276
|
+
}
|
|
277
|
+
return { data, next }
|
|
278
|
+
} else {
|
|
279
|
+
return data
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
}
|
package/esm/utils.js
CHANGED
|
@@ -91,18 +91,6 @@ const isData = (data, res) => {
|
|
|
91
91
|
return false
|
|
92
92
|
}
|
|
93
93
|
|
|
94
|
-
const query = txid => `query {
|
|
95
|
-
transactions(ids: ["${txid}"]) {
|
|
96
|
-
edges { node { id tags { name value } owner { address } } }
|
|
97
|
-
}
|
|
98
|
-
}`
|
|
99
|
-
|
|
100
|
-
const queries = to => `query {
|
|
101
|
-
transactions (recipients: ["${to}"]){
|
|
102
|
-
edges { node { id recipient tags { name value } owner { address } } }
|
|
103
|
-
}
|
|
104
|
-
}`
|
|
105
|
-
|
|
106
94
|
const isLocalhost = v => includes(v, ["localhost", "127.0.0.1"])
|
|
107
95
|
|
|
108
96
|
const udl = ({ payment, access, derivations, commercial, training }) => {
|
|
@@ -211,6 +199,10 @@ const srcs = {
|
|
|
211
199
|
|
|
212
200
|
const buildTags = (act, tags) => {
|
|
213
201
|
let _tags = []
|
|
202
|
+
if (isNil(tags) && typeof act !== "string") {
|
|
203
|
+
tags = act
|
|
204
|
+
act = null
|
|
205
|
+
}
|
|
214
206
|
if (act) _tags.push(action(act))
|
|
215
207
|
for (const k in tags) {
|
|
216
208
|
if (is(Array)(tags[k])) for (const v of tags[k]) _tags.push(tag(k, v))
|
|
@@ -271,6 +263,11 @@ const isCheckComplete = (checks, check) => {
|
|
|
271
263
|
return true
|
|
272
264
|
}
|
|
273
265
|
|
|
266
|
+
const dirname = async () =>
|
|
267
|
+
typeof __dirname != "undefined"
|
|
268
|
+
? __dirname
|
|
269
|
+
: (await import("./dirname.js")).default
|
|
270
|
+
|
|
274
271
|
function isJSON(obj) {
|
|
275
272
|
if (obj === null || obj === undefined) return false
|
|
276
273
|
if (
|
|
@@ -306,8 +303,6 @@ export {
|
|
|
306
303
|
srcs,
|
|
307
304
|
getTagVal,
|
|
308
305
|
isData,
|
|
309
|
-
query,
|
|
310
|
-
queries,
|
|
311
306
|
getTag,
|
|
312
307
|
tagEq,
|
|
313
308
|
searchTag,
|
|
@@ -321,4 +316,5 @@ export {
|
|
|
321
316
|
isLocalhost,
|
|
322
317
|
udl,
|
|
323
318
|
isJSON,
|
|
319
|
+
dirname,
|
|
324
320
|
}
|