hypercore-storage 2.0.1 → 2.0.3
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 +25 -14
- package/lib/streams.js +2 -1
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -194,8 +194,9 @@ class HypercoreStorage {
|
|
|
194
194
|
}
|
|
195
195
|
|
|
196
196
|
atomize(atom) {
|
|
197
|
-
if (this.atom && this.atom !== atom)
|
|
197
|
+
if (this.atom && this.atom !== atom) {
|
|
198
198
|
throw new Error('Cannot atomize and atomized session with a new atom')
|
|
199
|
+
}
|
|
199
200
|
return new HypercoreStorage(this.store, this.db.session(), this.core, atom.view, atom)
|
|
200
201
|
}
|
|
201
202
|
|
|
@@ -432,8 +433,6 @@ class CorestoreStorage {
|
|
|
432
433
|
// tmp sync fix for simplicty since not super deployed yet
|
|
433
434
|
if (this.bootstrap && !this.readOnly) tmpFixStorage(this.path)
|
|
434
435
|
|
|
435
|
-
this.rocks = storage === null ? db : new RocksDB(path.join(this.path, 'db'), opts)
|
|
436
|
-
this.db = createColumnFamily(this.rocks, opts)
|
|
437
436
|
this.id = opts.id || null
|
|
438
437
|
this.view = null
|
|
439
438
|
this.enters = 0
|
|
@@ -441,6 +440,15 @@ class CorestoreStorage {
|
|
|
441
440
|
this.flushing = null
|
|
442
441
|
this.version = 0
|
|
443
442
|
this.migrating = null
|
|
443
|
+
|
|
444
|
+
const preopen = this._openDeviceFile()
|
|
445
|
+
|
|
446
|
+
this.preopen = preopen
|
|
447
|
+
this.rocks =
|
|
448
|
+
storage === null ? db : new RocksDB(path.join(this.path, 'db'), { ...opts, preopen })
|
|
449
|
+
this.db = createColumnFamily(this.rocks, opts)
|
|
450
|
+
|
|
451
|
+
preopen.catch(noop) // awaited in rocks
|
|
444
452
|
}
|
|
445
453
|
|
|
446
454
|
get opened() {
|
|
@@ -451,6 +459,19 @@ class CorestoreStorage {
|
|
|
451
459
|
return this.db.closed
|
|
452
460
|
}
|
|
453
461
|
|
|
462
|
+
async _openDeviceFile() {
|
|
463
|
+
if ((this.bootstrap && !this.readOnly && !this.allowBackup) || this.wait) {
|
|
464
|
+
const corestoreFile = path.join(this.path, 'CORESTORE')
|
|
465
|
+
|
|
466
|
+
this.deviceFile = new DeviceFile(corestoreFile, {
|
|
467
|
+
wait: this.wait,
|
|
468
|
+
data: { id: this.id }
|
|
469
|
+
})
|
|
470
|
+
|
|
471
|
+
await this.deviceFile.ready()
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
454
475
|
async ready() {
|
|
455
476
|
if (this.version === 0) await this._migrateStore()
|
|
456
477
|
return this.db.ready()
|
|
@@ -536,19 +557,9 @@ class CorestoreStorage {
|
|
|
536
557
|
try {
|
|
537
558
|
if (this.version === VERSION) return
|
|
538
559
|
|
|
560
|
+
await this._preopen
|
|
539
561
|
await this.db.ready()
|
|
540
562
|
|
|
541
|
-
if (this.bootstrap && !this.readOnly && !this.allowBackup) {
|
|
542
|
-
const corestoreFile = path.join(this.path, 'CORESTORE')
|
|
543
|
-
|
|
544
|
-
this.deviceFile = new DeviceFile(corestoreFile, {
|
|
545
|
-
wait: this.wait,
|
|
546
|
-
data: { id: this.id }
|
|
547
|
-
})
|
|
548
|
-
|
|
549
|
-
await this.deviceFile.ready()
|
|
550
|
-
}
|
|
551
|
-
|
|
552
563
|
const rx = new CorestoreRX(this.db, view)
|
|
553
564
|
const headPromise = rx.getHead()
|
|
554
565
|
|
package/lib/streams.js
CHANGED
|
@@ -105,8 +105,9 @@ function createUserDataStream(
|
|
|
105
105
|
view,
|
|
106
106
|
{ gt = null, gte = '', lte = null, lt = null, reverse = false } = {}
|
|
107
107
|
) {
|
|
108
|
-
if (gt !== null || lte !== null)
|
|
108
|
+
if (gt !== null || lte !== null) {
|
|
109
109
|
throw new Error('gt and lte not yet supported for user data streams')
|
|
110
|
+
}
|
|
110
111
|
|
|
111
112
|
const s = core.userData(ptr.dataPointer, gte)
|
|
112
113
|
const e = lt === null ? core.userDataEnd(ptr.dataPointer) : core.userData(ptr.dataPointer, lt)
|