@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/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
- }
package/src/index.js DELETED
@@ -1,6 +0,0 @@
1
- import { Fireproof } from './fireproof.js'
2
- import { DbIndex as Index } from './db-index.js'
3
- import { Listener } from './listener.js'
4
- import { Hydrator } from './hydrator.js'
5
-
6
- export { Fireproof, Index, Listener, Hydrator }