@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/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
- 'got car',
87
- roots.map(c => c.toString()),
88
- this.database.clock.map(c => c.toString())
89
- )
90
- console.log(
91
- 'got blocks',
92
- [...blz].map(({ cid }) => cid.toString())
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
- 'queue worker',
44
- tasks.length,
45
- tasks.reduce((acc, t) => acc + t.value.length, 0)
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 => {