zkjson 0.2.4 → 0.3.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/db.js +20 -4
- package/doc.js +1 -7
- package/package.json +1 -1
package/db.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const newMemEmptyTrie = require("./circomlibjs").newMemEmptyTrie
|
|
2
2
|
const snarkjs = require("snarkjs")
|
|
3
|
-
const { range } = require("ramda")
|
|
3
|
+
const { is, indexOf, range, isNil } = require("ramda")
|
|
4
4
|
const { pad, toSignal, encode, toIndex } = require("./encoder")
|
|
5
5
|
const Collection = require("./collection")
|
|
6
6
|
|
|
@@ -28,6 +28,7 @@ class DB {
|
|
|
28
28
|
this.size_json = size_json
|
|
29
29
|
this.size_txs = size_txs
|
|
30
30
|
this.count = 0
|
|
31
|
+
this.ids = []
|
|
31
32
|
}
|
|
32
33
|
|
|
33
34
|
async init() {
|
|
@@ -277,9 +278,24 @@ class DB {
|
|
|
277
278
|
col_root,
|
|
278
279
|
}
|
|
279
280
|
}
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
281
|
+
getID(num) {
|
|
282
|
+
if (!isNil(num)) {
|
|
283
|
+
if (indexOf(num)(this.ids) !== -1) {
|
|
284
|
+
throw Error("id exists")
|
|
285
|
+
}
|
|
286
|
+
return num
|
|
287
|
+
} else {
|
|
288
|
+
while (indexOf(this.count)(this.ids) !== -1) {
|
|
289
|
+
this.count++
|
|
290
|
+
}
|
|
291
|
+
return this.count++
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
async addCollection(num) {
|
|
295
|
+
if (!isNil(num) && (!is(Number, num) || Math.round(num) !== num)) {
|
|
296
|
+
throw Error("id is not an integer")
|
|
297
|
+
}
|
|
298
|
+
const id = this.getID(num)
|
|
283
299
|
const col = await this.tree.find(id)
|
|
284
300
|
if (col.found) throw Error("collection exists")
|
|
285
301
|
const _col = new Collection({
|
package/doc.js
CHANGED
|
@@ -11,13 +11,7 @@ const {
|
|
|
11
11
|
} = require("./encoder")
|
|
12
12
|
|
|
13
13
|
module.exports = class Doc {
|
|
14
|
-
constructor({
|
|
15
|
-
size_val = 256,
|
|
16
|
-
size_path = 256,
|
|
17
|
-
size_json = 256,
|
|
18
|
-
wasm,
|
|
19
|
-
zkey,
|
|
20
|
-
}) {
|
|
14
|
+
constructor({ size_val = 8, size_path = 4, size_json = 256, wasm, zkey }) {
|
|
21
15
|
this.size_val = size_val
|
|
22
16
|
this.size_path = size_path
|
|
23
17
|
this.size_json = size_json
|