@fireproof/core 0.0.10 → 0.1.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/README.md +1 -1
- package/package.json +3 -2
- package/src/db-index.js +10 -4
- package/src/fireproof.js +1 -1
- package/test/db-index.test.js +29 -2
package/README.md
CHANGED
@@ -96,7 +96,7 @@ Documents changes are persisted to [Filecoin](https://filecoin.io) via [web3.sto
|
|
96
96
|
|
97
97
|
### Cryptographic Proofs
|
98
98
|
|
99
|
-
The [UCAN protocol](https://ucan.xyz)
|
99
|
+
The [UCAN protocol](https://ucan.xyz) verifiably links Fireproof updates to authorized agents via cryptographic proof chains. These proofs are portable like bearer tokens, but because invocations are signed by end-user device keys, UCAN proofs don't need to be hidden to be secure, allowing for delegation of service capabilities across devices and parties. Additionally, Fireproof's Merkle clocks and hash trees are immutable and self-validating, making merging changes safe and efficient. Fireproof makes cryptographic proofs available for all of its operations, making it an ideal verifiable document database for smart contracts and other applications running in trustless environments. [Proof chains provide performance benefits as well](https://purrfect-tracker-45c.notion.site/Data-Routing-23c37b269b4c4c3dacb60d0077113bcb), by allowing recipients to skip costly I/O operations and instead cryptographically verify that changes contain all of the required context.
|
100
100
|
|
101
101
|
## Limitations 💣
|
102
102
|
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@fireproof/core",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1.1",
|
4
4
|
"description": "Realtime database for IPFS",
|
5
5
|
"main": "index.js",
|
6
6
|
"type": "module",
|
@@ -10,6 +10,7 @@
|
|
10
10
|
"test:watch": "npm run test:mocha -- -w --parallel test/*.test.js",
|
11
11
|
"coverage": "c8 -r html -r text npm test",
|
12
12
|
"prepublishOnly" : "cp ../../README.md .",
|
13
|
+
"postpublish": "rm README.md",
|
13
14
|
"lint": "standard",
|
14
15
|
"lint:fix": "standard --fix"
|
15
16
|
},
|
@@ -68,7 +69,7 @@
|
|
68
69
|
"bugs": {
|
69
70
|
"url": "https://github.com/fireproof-storage/fireproof/issues"
|
70
71
|
},
|
71
|
-
"homepage": "https://
|
72
|
+
"homepage": "https://fireproof.storage",
|
72
73
|
"workspaces": [
|
73
74
|
"examples/todomvc"
|
74
75
|
]
|
package/src/db-index.js
CHANGED
@@ -9,7 +9,7 @@ import { cidsToProof } from './fireproof.js'
|
|
9
9
|
|
10
10
|
import * as codec from '@ipld/dag-cbor'
|
11
11
|
// import { create as createBlock } from 'multiformats/block'
|
12
|
-
import { doTransaction } from './blockstore.js'
|
12
|
+
import TransactionBlockstore, { doTransaction } from './blockstore.js'
|
13
13
|
import charwise from 'charwise'
|
14
14
|
|
15
15
|
const ALWAYS_REBUILD = false // todo: make false
|
@@ -109,6 +109,9 @@ export default class DbIndex {
|
|
109
109
|
* @type {Fireproof}
|
110
110
|
*/
|
111
111
|
this.database = database
|
112
|
+
if (!database.indexBlocks) {
|
113
|
+
database.indexBlocks = new TransactionBlockstore(database.name + '.indexes')
|
114
|
+
}
|
112
115
|
/**
|
113
116
|
* The map function to apply to each entry in the database.
|
114
117
|
* @type {Function}
|
@@ -190,13 +193,13 @@ export default class DbIndex {
|
|
190
193
|
// if (!root) {
|
191
194
|
// pass a root to query a snapshot
|
192
195
|
// console.time(callId + '.#updateIndex')
|
193
|
-
await this.#updateIndex(this.database.
|
196
|
+
await this.#updateIndex(this.database.indexBlocks)
|
194
197
|
// console.timeEnd(callId + '.#updateIndex')
|
195
198
|
|
196
199
|
// }
|
197
200
|
// console.time(callId + '.doIndexQuery')
|
198
201
|
// console.log('query', query)
|
199
|
-
const response = await doIndexQuery(this.database.
|
202
|
+
const response = await doIndexQuery(this.database.indexBlocks, this.indexByKey, query)
|
200
203
|
// console.timeEnd(callId + '.doIndexQuery')
|
201
204
|
|
202
205
|
return {
|
@@ -319,7 +322,10 @@ async function loadIndex (blocks, index, indexOpts) {
|
|
319
322
|
|
320
323
|
async function doIndexQuery (blocks, indexByKey, query) {
|
321
324
|
await loadIndex(blocks, indexByKey, dbIndexOpts)
|
322
|
-
if (query
|
325
|
+
if (!query) {
|
326
|
+
const { result, ...all } = await indexByKey.root.getAllEntries()
|
327
|
+
return { result: result.map(({ key: [k, id], value }) => ({ key: k, id, row: value })), ...all }
|
328
|
+
} else if (query.range) {
|
323
329
|
const encodedRange = query.range.map((key) => charwise.encode(key))
|
324
330
|
return indexByKey.root.range(...encodedRange)
|
325
331
|
} else if (query.key) {
|
package/src/fireproof.js
CHANGED
package/test/db-index.test.js
CHANGED
@@ -30,10 +30,10 @@ describe('DbIndex query', () => {
|
|
30
30
|
})
|
31
31
|
})
|
32
32
|
it('query index range', async () => {
|
33
|
-
const result = await index.query({ range: [41,
|
33
|
+
const result = await index.query({ range: [41, 49] })
|
34
34
|
assert(result, 'did return result')
|
35
35
|
assert(result.rows)
|
36
|
-
assert.equal(result.rows.length,
|
36
|
+
assert.equal(result.rows.length, 2, 'two row matched')
|
37
37
|
assert.equal(result.rows[0].key, 43)
|
38
38
|
assert(result.rows[0].value === 'carol', 'correct value')
|
39
39
|
})
|
@@ -47,6 +47,33 @@ describe('DbIndex query', () => {
|
|
47
47
|
assert.equal(result.rows[0].key, 43)
|
48
48
|
assert(result.rows[0].value === 'carol', 'correct value')
|
49
49
|
})
|
50
|
+
it('query index all', async () => {
|
51
|
+
const result = await index.query()
|
52
|
+
assert(result, 'did return result')
|
53
|
+
assert(result.rows)
|
54
|
+
assert.equal(result.rows.length, 6, 'six row matched')
|
55
|
+
assert.equal(result.rows[0].key, 4)
|
56
|
+
assert.equal(result.rows[0].value, 'emily')
|
57
|
+
assert.equal(result.rows[result.rows.length - 1].value, 'dave')
|
58
|
+
})
|
59
|
+
it('query index NaN', async () => {
|
60
|
+
const result = await index.query({ range: [NaN, 44] })
|
61
|
+
assert(result, 'did return result')
|
62
|
+
assert(result.rows)
|
63
|
+
assert.equal(result.rows.length, 5, 'six row matched')
|
64
|
+
assert.equal(result.rows[0].key, 4)
|
65
|
+
assert.equal(result.rows[0].value, 'emily')
|
66
|
+
assert.equal(result.rows[result.rows.length - 1].value, 'carol')
|
67
|
+
})
|
68
|
+
it('query index Infinity', async () => {
|
69
|
+
const result = await index.query({ range: [42, Infinity] })
|
70
|
+
assert(result, 'did return result')
|
71
|
+
assert(result.rows)
|
72
|
+
assert.equal(result.rows.length, 2, 'six row matched')
|
73
|
+
assert.equal(result.rows[0].key, 43)
|
74
|
+
assert.equal(result.rows[0].value, 'carol')
|
75
|
+
assert.equal(result.rows[result.rows.length - 1].value, 'dave')
|
76
|
+
})
|
50
77
|
it('query twice', async () => {
|
51
78
|
let result = await index.query({ range: [41, 44] })
|
52
79
|
assert(result, 'did return result')
|