@fireproof/core 0.0.6 → 0.0.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.
Files changed (38) hide show
  1. package/coverage/blockstore.js.html +254 -242
  2. package/coverage/clock.js.html +203 -266
  3. package/coverage/db-index.js.html +426 -213
  4. package/coverage/fireproof.js.html +424 -238
  5. package/coverage/index.html +69 -84
  6. package/coverage/listener.js.html +13 -25
  7. package/coverage/prolly.js.html +267 -219
  8. package/coverage/tmp/coverage-28490-1680373005621-0.json +1 -0
  9. package/coverage/tmp/coverage-28494-1680373004502-0.json +1 -0
  10. package/coverage/tmp/coverage-28500-1680373005593-0.json +1 -0
  11. package/coverage/tmp/coverage-28504-1680373005559-0.json +1 -0
  12. package/coverage/valet.js.html +96 -246
  13. package/hooks/use-fireproof.ts +9 -8
  14. package/package.json +5 -5
  15. package/src/blockstore.js +16 -14
  16. package/src/clock.js +27 -5
  17. package/src/db-index.js +139 -96
  18. package/src/fireproof.js +48 -16
  19. package/src/hydrator.js +10 -0
  20. package/src/listener.js +0 -6
  21. package/src/prolly.js +43 -32
  22. package/src/valet.js +6 -62
  23. package/{src → test}/block.js +6 -6
  24. package/test/clock.test.js +0 -5
  25. package/test/db-index.test.js +11 -10
  26. package/test/fireproof.test.js +74 -19
  27. package/test/helpers.js +1 -1
  28. package/test/hydrator.test.js +75 -0
  29. package/test/prolly.test.js +2 -2
  30. package/test/proofs.test.js +5 -5
  31. package/test/reproduce-fixture-bug.test.js +2 -2
  32. package/coverage/tmp/coverage-42191-1678146904346-0.json +0 -1
  33. package/coverage/tmp/coverage-42193-1678146903521-0.json +0 -1
  34. package/coverage/tmp/coverage-42196-1678146904322-0.json +0 -1
  35. package/coverage/tmp/coverage-42197-1678146904292-0.json +0 -1
  36. package/scripts/propernames/gen.sh +0 -3
  37. package/scripts/randomcid.js +0 -12
  38. package/scripts/words/gen.js +0 -55
@@ -0,0 +1,75 @@
1
+ import { describe, it, beforeEach } from 'mocha'
2
+ import assert from 'node:assert'
3
+ import Fireproof from '../src/fireproof.js'
4
+ import DbIndex from '../src/db-index.js'
5
+ import { fromJSON } from '../src/hydrator.js'
6
+ console.x = function () {}
7
+
8
+ describe('DbIndex query', () => {
9
+ let database, index
10
+ beforeEach(async () => {
11
+ database = Fireproof.storage()
12
+ const docs = [
13
+ { _id: 'a1s3b32a-3c3a-4b5e-9c1c-8c5c0c5c0c5c', name: 'alice', age: 40 },
14
+ { _id: 'b2s3b32a-3c3a-4b5e-9c1c-8c5c0c5c0c5c', name: 'bob', age: 40 },
15
+ { _id: 'c3s3b32a-3c3a-4b5e-9c1c-8c5c0c5c0c5c', name: 'carol', age: 43 },
16
+ { _id: 'd4s3b32a-3c3a-4b5e-9c1c-8c5c0c5c0c5c', name: 'dave', age: 48 },
17
+ { _id: 'e4s3b32a-3c3a-4b5e-9c1c-8c5c0c5c0c5c', name: 'emily', age: 4 },
18
+ { _id: 'f4s3b32a-3c3a-4b5e-9c1c-8c5c0c5c0c5c', name: 'frank', age: 7 }
19
+ ]
20
+ for (const doc of docs) {
21
+ const id = doc._id
22
+ const response = await database.put(doc)
23
+ assert(response)
24
+ assert(response.id, 'should have id')
25
+ assert.equal(response.id, id)
26
+ }
27
+ index = new DbIndex(database, function (doc, map) {
28
+ map(doc.age, doc.name)
29
+ })
30
+ })
31
+ it('serialize database with index', async () => {
32
+ await database.put({ _id: 'rehy', name: 'drate', age: 1 })
33
+ assert.equal((await database.changesSince()).rows.length, 7)
34
+ const result = await index.query({ range: [0, 54] })
35
+ assert.equal(result.rows[0].value, 'drate')
36
+ const serialized = database.toJSON()
37
+ // console.log('serialized', serialized)
38
+ assert.equal(serialized.name, 'global')
39
+ assert.equal(serialized.clock.length, 1)
40
+ assert.equal(serialized.clock[0].constructor.name, 'String')
41
+ assert.equal(serialized.indexes.length, 1)
42
+ assert.equal(serialized.indexes[0].code, `function (doc, map) {
43
+ map(doc.age, doc.name)
44
+ }`)
45
+ assert.equal(serialized.indexes[0].clock.byId.constructor.name, 'String')
46
+ assert.equal(serialized.indexes[0].clock.byKey.constructor.name, 'String')
47
+ assert.equal(serialized.indexes[0].clock.db[0].constructor.name, 'String')
48
+ })
49
+ it('rehydrate database', async () => {
50
+ await database.put({ _id: 'rehy', name: 'drate', age: 1 })
51
+ assert.equal((await database.changesSince()).rows.length, 7)
52
+ const result = await index.query({ range: [0, 54] })
53
+ assert.equal(result.rows[0].value, 'drate')
54
+
55
+ const serialized = JSON.parse(JSON.stringify(database))
56
+ // console.log('serialized', JSON.stringify(serialized))
57
+ // connect it to the same blockstore for testing
58
+ const newDb = fromJSON(serialized, database.blocks)
59
+ assert.equal(newDb.name, 'global')
60
+ assert.equal(newDb.clock.length, 1)
61
+ assert.equal((await newDb.changesSince()).rows.length, 7)
62
+ const newIndex = [...newDb.indexes.values()][0]
63
+ assert.equal(newIndex.mapFun, `function (doc, map) {
64
+ map(doc.age, doc.name)
65
+ }`)
66
+ assert.equal(newIndex.indexById.cid, 'bafyreifuz54ugnq77fur47vwv3dwab7p3gpnf5to6hlnbhv5p4kwo7auoi')
67
+ assert.equal(newIndex.indexById.root, null)
68
+
69
+ assert.equal(newIndex.indexByKey.cid, 'bafyreicr5rpvsxnqchcwk5rxlmdvd3fah2vexmbsp2dvr4cfdxd2q2ycgu')
70
+ assert.equal(newIndex.indexByKey.root, null)
71
+
72
+ const newResult = await newIndex.query({ range: [0, 54] })
73
+ assert.equal(newResult.rows[0].value, 'drate')
74
+ })
75
+ })
@@ -110,7 +110,7 @@ describe('Prolly', () => {
110
110
  assert.equal(bvalue.toString(), data[0][1].toString())
111
111
  })
112
112
 
113
- it.skip('linear put hundreds of values', async () => {
113
+ it.skip('passing, slow: linear put hundreds of values', async () => {
114
114
  const blocks = new Blockstore()
115
115
  const alice = new TestPail(blocks, [])
116
116
 
@@ -173,7 +173,7 @@ class TestPail {
173
173
  /** @param {string} key */
174
174
  async get (key) {
175
175
  const resp = await get(this.blocks, this.head, key)
176
- console.log('prolly GET', key, resp)
176
+ // console.log('prolly GET', key, resp)
177
177
  return resp.result
178
178
  }
179
179
 
@@ -14,11 +14,11 @@ describe('Proofs', () => {
14
14
  doc = await database.get(ok.id, { mvcc: true })
15
15
  })
16
16
 
17
- it.skip('first put result shoud not include proof', async () => {
17
+ it('first put result shoud not include proof', async () => {
18
18
  assert(ok.proof)
19
19
  assert(ok.proof.data)
20
20
  assert(ok.proof.clock)
21
- console.log('ok', ok)
21
+ // console.log('ok', ok)
22
22
  assert.equal(ok.proof.data.length, 0)
23
23
  assert.equal(ok.proof.clock.length, 0)
24
24
 
@@ -31,7 +31,7 @@ describe('Proofs', () => {
31
31
  assert(ok2.proof)
32
32
  assert(ok2.proof.data)
33
33
  assert(ok2.proof.clock)
34
- console.log('ok2', ok2)
34
+ // console.log('ok2', ok2)
35
35
  assert.equal(ok2.proof.data.length, 1)
36
36
  assert.equal(ok2.proof.clock.length, 1)
37
37
 
@@ -47,7 +47,7 @@ describe('Proofs', () => {
47
47
  assert(doc._proof.clock)
48
48
  assert.equal(doc._proof.data.length, 1)
49
49
  assert.equal(doc._proof.clock.length, 1)
50
- assert.equal(doc._proof.data[0], 'bafyreibsbxxd4ueujryihk6xza2ekwhzsh6pzuu5fysft5ilz7cbw6bjju')
51
- assert.equal(doc._proof.clock[0].toString(), 'bafyreiactx5vku7zueq27i5zdrgcjnczxvepceo5yszjqb2exufwrwxg44')
50
+ assert.equal(doc._proof.data[0], 'bafyreieilmvxq6wudu46i2ssmuyrmaszr4onzlqxzlvngrczbn7ppyvloq')
51
+ assert.equal(doc._proof.clock[0].toString(), 'bafyreict4aip45uwnm4xcsn4oikh73t5n7nzdmc2u36rdbguroun2yaf2y')
52
52
  })
53
53
  })
@@ -58,8 +58,8 @@ const reproduceBug = async (database) => {
58
58
  const id = '02pkji8'
59
59
  const doc = await database.get(id)
60
60
  // (await database.put({ completed: !completed, ...doc }))
61
- const ok = await database.put(doc)
61
+ await database.put(doc)
62
62
  await database.todosByList.query({ range: [0, 1] })
63
63
 
64
- console.log('ok', ok)
64
+ // console.log('ok', ok)
65
65
  }