@fireproof/core 0.5.13 → 0.5.15
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/hooks/use-fireproof.js +2 -1
- package/dist/src/blockstore.js +4 -4
- package/dist/src/clock.js +109 -37
- package/dist/src/crypto.js +1 -1
- package/dist/src/database.js +20 -19
- package/dist/src/db-index.js +8 -7
- package/dist/src/fireproof.d.ts +4 -3
- package/dist/src/fireproof.js +428 -309
- package/dist/src/fireproof.js.map +1 -1
- package/dist/src/fireproof.mjs +428 -309
- package/dist/src/fireproof.mjs.map +1 -1
- package/dist/src/listener.js +2 -3
- package/dist/src/prolly.js +74 -25
- package/dist/src/sha1.js +2 -1
- package/dist/src/sync.js +28 -9
- package/dist/src/valet.js +5 -1
- package/package.json +2 -2
- package/src/blockstore.js +1 -0
- package/src/clock.js +123 -37
- package/src/crypto.js +1 -1
- package/src/database.js +15 -12
- package/src/db-index.js +3 -2
- package/src/prolly.js +82 -24
- package/src/sync.js +20 -13
- package/src/valet.js +5 -5
package/src/sync.js
CHANGED
@@ -23,10 +23,15 @@ export class Sync {
|
|
23
23
|
this.pushBacklogResolve = resolve
|
24
24
|
this.pushBacklogReject = reject
|
25
25
|
})
|
26
|
+
this.isReady = false
|
26
27
|
// this.pushBacklog.then(() => {
|
27
28
|
// // console.log('sync backlog resolved')
|
28
29
|
// this.database.notifyReset()
|
29
30
|
// })
|
31
|
+
// this.connected = new Promise((resolve, reject) => {
|
32
|
+
// this.readyResolve = resolve
|
33
|
+
// this.readyReject = reject
|
34
|
+
// })
|
30
35
|
}
|
31
36
|
|
32
37
|
async offer () {
|
@@ -75,22 +80,22 @@ export class Sync {
|
|
75
80
|
// console.log('not a car', data.toString())
|
76
81
|
}
|
77
82
|
if (reader) {
|
78
|
-
console.log('got car')
|
83
|
+
// console.log('got car')
|
79
84
|
this.status = 'parking car'
|
80
85
|
const blz = new Set()
|
81
86
|
for await (const block of reader.blocks()) {
|
82
87
|
blz.add(block)
|
83
88
|
}
|
84
89
|
const roots = await reader.getRoots()
|
85
|
-
console.log(
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
)
|
90
|
-
console.log(
|
91
|
-
|
92
|
-
|
93
|
-
)
|
90
|
+
// console.log(
|
91
|
+
// 'got car',
|
92
|
+
// roots.map(c => c.toString()),
|
93
|
+
// this.database.clock.map(c => c.toString())
|
94
|
+
// )
|
95
|
+
// console.log(
|
96
|
+
// 'got blocks!',
|
97
|
+
// [...blz].map(({ cid }) => cid.toString())
|
98
|
+
// )
|
94
99
|
// @ts-ignore
|
95
100
|
reader.entries = reader.blocks
|
96
101
|
await this.database.blocks.commit(
|
@@ -129,7 +134,7 @@ export class Sync {
|
|
129
134
|
} else if (message.clock) {
|
130
135
|
const reqCidDiff = message
|
131
136
|
// this might be a CID diff
|
132
|
-
console.log('got diff', reqCidDiff)
|
137
|
+
// console.log('got diff', reqCidDiff)
|
133
138
|
const carBlock = await Sync.makeCar(this.database, null, reqCidDiff.cids)
|
134
139
|
if (!carBlock) {
|
135
140
|
// we are full synced
|
@@ -138,9 +143,10 @@ export class Sync {
|
|
138
143
|
this.peer.send(JSON.stringify({ ok: true }))
|
139
144
|
// this.pushBacklogResolve({ ok: true })
|
140
145
|
} else {
|
141
|
-
console.log('do send', carBlock.bytes.length)
|
146
|
+
// console.log('do send diff', carBlock.bytes.length)
|
142
147
|
this.status = 'sending diff car'
|
143
148
|
this.peer.send(carBlock.bytes)
|
149
|
+
// console.log('sent diff car')
|
144
150
|
// this.pushBacklogResolve({ ok: true })
|
145
151
|
}
|
146
152
|
}
|
@@ -154,7 +160,7 @@ export class Sync {
|
|
154
160
|
}
|
155
161
|
|
156
162
|
async sendUpdate (blockstore) {
|
157
|
-
if (!this.peer) return
|
163
|
+
if (!this.peer || !this.isReady) return
|
158
164
|
// console.log('send update from', this.database.instanceId)
|
159
165
|
// todo should send updates since last sync
|
160
166
|
const newCar = await blocksToCarBlock(blockstore.lastCid, blockstore)
|
@@ -164,6 +170,7 @@ export class Sync {
|
|
164
170
|
|
165
171
|
async startSync () {
|
166
172
|
// console.log('start sync', this.peer.initiator)
|
173
|
+
this.isReady = true
|
167
174
|
const allCIDs = await this.database.allStoredCIDs()
|
168
175
|
// console.log('allCIDs', allCIDs)
|
169
176
|
const reqCidDiff = {
|
package/src/valet.js
CHANGED
@@ -39,11 +39,11 @@ export class Valet {
|
|
39
39
|
this.name = name
|
40
40
|
this.setKeyMaterial(keyMaterial)
|
41
41
|
this.uploadQueue = cargoQueue(async (tasks, callback) => {
|
42
|
-
console.log(
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
)
|
42
|
+
// console.log(
|
43
|
+
// 'queue worker',
|
44
|
+
// tasks.length,
|
45
|
+
// tasks.reduce((acc, t) => acc + t.value.length, 0)
|
46
|
+
// )
|
47
47
|
if (this.uploadFunction) {
|
48
48
|
// todo we can coalesce these into a single car file
|
49
49
|
return await this.withDB(async db => {
|