autobee 2.0.0 → 2.0.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/index.js +30 -10
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -51,7 +51,9 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
51
51
|
this.getSystemEncryption = this._getEncryptionProvider.bind(this, '_system')
|
|
52
52
|
this.getViewEncryption = this._getEncryptionProvider.bind(this, viewName)
|
|
53
53
|
|
|
54
|
-
const
|
|
54
|
+
const beeStore = store.session()
|
|
55
|
+
const bee = new Hyperbee(beeStore, {
|
|
56
|
+
core: beeStore.get({ preload: this._getCorePreload(viewName) }),
|
|
55
57
|
// defer one tick to ensure consistent state, then return state prom
|
|
56
58
|
preload: async () => {
|
|
57
59
|
await 1
|
|
@@ -69,11 +71,12 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
69
71
|
this._handlers = handlers
|
|
70
72
|
this.stats = { undos: 0, fastForwards: 0, drains: 0, applies: 0, appends: 0 }
|
|
71
73
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
const systemStore = this.store.session()
|
|
75
|
+
this.system = new System(systemStore, this.name, {
|
|
76
|
+
core: systemStore.get({ preload: this._getCorePreload('system') }),
|
|
77
|
+
encrypted: this.encrypted,
|
|
78
|
+
getEncryptionProvider: this.getSystemEncryption
|
|
75
79
|
})
|
|
76
|
-
this.system.auto = this
|
|
77
80
|
|
|
78
81
|
this.bee = bee.snapshot()
|
|
79
82
|
this.view = ApplyView.open(this.bee, this)
|
|
@@ -150,6 +153,7 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
150
153
|
|
|
151
154
|
this._catchupMigratedNodes = null
|
|
152
155
|
this._migratedHead = null
|
|
156
|
+
this._prebooting = null
|
|
153
157
|
|
|
154
158
|
this.ready().catch(noop)
|
|
155
159
|
}
|
|
@@ -181,8 +185,18 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
181
185
|
return !!(this._draining || this._updating)
|
|
182
186
|
}
|
|
183
187
|
|
|
188
|
+
async _getCorePreload(name) {
|
|
189
|
+
await 1
|
|
190
|
+
const result = await this._prebooting
|
|
191
|
+
return {
|
|
192
|
+
name: 'autobee/' + result.local.id + '/' + name,
|
|
193
|
+
encryption: name === 'system' ? this.getSystemEncryption() : this.getViewEncryption(),
|
|
194
|
+
inflightRange: [256, 512]
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
184
198
|
async _open() {
|
|
185
|
-
|
|
199
|
+
this._prebooting = this._preBoot()
|
|
186
200
|
|
|
187
201
|
this._bootingState = this._bootState()
|
|
188
202
|
this._bootingAll = this._bootAll()
|
|
@@ -190,6 +204,8 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
190
204
|
this._bootingState.catch(safetyCatch)
|
|
191
205
|
this._bootingAll.catch(safetyCatch)
|
|
192
206
|
|
|
207
|
+
await this._prebooting
|
|
208
|
+
|
|
193
209
|
await this.bee.ready()
|
|
194
210
|
await this._workingBee.ready()
|
|
195
211
|
await this._bootingState
|
|
@@ -338,6 +354,11 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
338
354
|
if (this.bootFrom) {
|
|
339
355
|
this.bootFrom = getBootOption(await this.bootFrom)
|
|
340
356
|
}
|
|
357
|
+
|
|
358
|
+
return boot(this.store, this.key, this.legacyViews, {
|
|
359
|
+
encryptionKey: this.encryptionKey,
|
|
360
|
+
keyPair: this.keyPair
|
|
361
|
+
})
|
|
341
362
|
}
|
|
342
363
|
|
|
343
364
|
getMostRecentHead() {
|
|
@@ -370,10 +391,7 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
370
391
|
}
|
|
371
392
|
|
|
372
393
|
async _bootStateUnsafe() {
|
|
373
|
-
const result = await
|
|
374
|
-
encryptionKey: this.encryptionKey,
|
|
375
|
-
keyPair: this.keyPair
|
|
376
|
-
})
|
|
394
|
+
const result = await this._prebooting
|
|
377
395
|
|
|
378
396
|
this.key = result.key
|
|
379
397
|
this.bootstrap = result.bootstrap
|
|
@@ -463,6 +481,8 @@ module.exports = class Autobee extends ReadyResource {
|
|
|
463
481
|
async _bootAll() {
|
|
464
482
|
if (!(await this._bootReady())) return
|
|
465
483
|
|
|
484
|
+
await this._prebooting
|
|
485
|
+
|
|
466
486
|
for (const head of this.system.heads) {
|
|
467
487
|
await this.writers.add(head.key)
|
|
468
488
|
}
|