@fireproof/core 0.3.22 → 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/dist/src/{index.d.ts → fireproof.d.ts} +145 -122
- package/dist/src/{index.js → fireproof.js} +199 -153
- package/dist/src/fireproof.js.map +1 -0
- package/dist/src/{index.mjs → fireproof.mjs} +200 -153
- package/dist/src/fireproof.mjs.map +1 -0
- package/hooks/use-fireproof.js +38 -63
- package/package.json +13 -14
- package/src/blockstore.js +8 -4
- package/src/database.js +339 -0
- package/src/db-index.js +3 -3
- package/src/fireproof.js +65 -322
- package/src/listener.js +10 -8
- package/src/prolly.js +10 -6
- package/src/utils.js +16 -0
- package/dist/main.js +0 -2
- package/dist/main.js.LICENSE.txt +0 -17
- package/dist/src/index.js.map +0 -1
- package/dist/src/index.mjs.map +0 -1
- package/src/hydrator.js +0 -54
- package/src/index.js +0 -6
package/src/hydrator.js
DELETED
@@ -1,54 +0,0 @@
|
|
1
|
-
import { DbIndex } from './db-index.js'
|
2
|
-
import { Fireproof } from './fireproof.js'
|
3
|
-
import { CID } from 'multiformats'
|
4
|
-
|
5
|
-
const parseCID = cid => typeof cid === 'string' ? CID.parse(cid) : cid
|
6
|
-
|
7
|
-
export class Hydrator {
|
8
|
-
static fromJSON (json, database) {
|
9
|
-
database.hydrate({ clock: json.clock.map(c => parseCID(c)), name: json.name, key: json.key })
|
10
|
-
if (json.indexes) {
|
11
|
-
for (const { name, code, clock: { byId, byKey, db } } of json.indexes) {
|
12
|
-
DbIndex.fromJSON(database, {
|
13
|
-
clock: {
|
14
|
-
byId: byId ? parseCID(byId) : null,
|
15
|
-
byKey: byKey ? parseCID(byKey) : null,
|
16
|
-
db: db ? db.map(c => parseCID(c)) : null
|
17
|
-
},
|
18
|
-
code,
|
19
|
-
name
|
20
|
-
})
|
21
|
-
}
|
22
|
-
}
|
23
|
-
return database
|
24
|
-
}
|
25
|
-
|
26
|
-
static snapshot (database, clock) {
|
27
|
-
const definition = database.toJSON()
|
28
|
-
const withBlocks = new Fireproof(database.blocks)
|
29
|
-
if (clock) {
|
30
|
-
definition.clock = clock.map(c => parseCID(c))
|
31
|
-
definition.indexes.forEach(index => {
|
32
|
-
index.clock.byId = null
|
33
|
-
index.clock.byKey = null
|
34
|
-
index.clock.db = null
|
35
|
-
})
|
36
|
-
}
|
37
|
-
const snappedDb = this.fromJSON(definition, withBlocks)
|
38
|
-
;([...database.indexes.values()]).forEach(index => {
|
39
|
-
snappedDb.indexes.get(index.mapFnString).mapFn = index.mapFn
|
40
|
-
})
|
41
|
-
return snappedDb
|
42
|
-
}
|
43
|
-
|
44
|
-
static async zoom (database, clock) {
|
45
|
-
;([...database.indexes.values()]).forEach(index => {
|
46
|
-
index.indexById = { root: null, cid: null }
|
47
|
-
index.indexByKey = { root: null, cid: null }
|
48
|
-
index.dbHead = null
|
49
|
-
})
|
50
|
-
database.clock = clock.map(c => parseCID(c))
|
51
|
-
await database.notifyReset() // hmm... indexes should listen to this? might be more complex than worth it. so far this is the only caller
|
52
|
-
return database
|
53
|
-
}
|
54
|
-
}
|