hypercore-storage 2.0.0 → 2.0.2
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 +26 -16
- 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
|
|
|
@@ -428,13 +429,12 @@ class CorestoreStorage {
|
|
|
428
429
|
this.allowBackup = !!opts.allowBackup
|
|
429
430
|
this.deviceFile = null
|
|
430
431
|
this.wait = !!opts.wait
|
|
431
|
-
|
|
432
|
+
|
|
433
|
+
const preopen = this._openDeviceFile()
|
|
432
434
|
|
|
433
435
|
// tmp sync fix for simplicty since not super deployed yet
|
|
434
436
|
if (this.bootstrap && !this.readOnly) tmpFixStorage(this.path)
|
|
435
437
|
|
|
436
|
-
this.rocks = storage === null ? db : new RocksDB(path.join(this.path, 'db'), opts)
|
|
437
|
-
this.db = createColumnFamily(this.rocks, opts)
|
|
438
438
|
this.id = opts.id || null
|
|
439
439
|
this.view = null
|
|
440
440
|
this.enters = 0
|
|
@@ -442,6 +442,14 @@ class CorestoreStorage {
|
|
|
442
442
|
this.flushing = null
|
|
443
443
|
this.version = 0
|
|
444
444
|
this.migrating = null
|
|
445
|
+
this.preopen = preopen
|
|
446
|
+
|
|
447
|
+
this.rocks =
|
|
448
|
+
storage === null ? db : new RocksDB(path.join(this.path, 'db'), { ...opts, preopen })
|
|
449
|
+
|
|
450
|
+
this.db = createColumnFamily(this.rocks, opts)
|
|
451
|
+
|
|
452
|
+
preopen.catch(noop) // awaited in rocks
|
|
445
453
|
}
|
|
446
454
|
|
|
447
455
|
get opened() {
|
|
@@ -452,6 +460,19 @@ class CorestoreStorage {
|
|
|
452
460
|
return this.db.closed
|
|
453
461
|
}
|
|
454
462
|
|
|
463
|
+
async _openDeviceFile() {
|
|
464
|
+
if ((this.bootstrap && !this.readOnly && !this.allowBackup) || this.wait) {
|
|
465
|
+
const corestoreFile = path.join(this.path, 'CORESTORE')
|
|
466
|
+
|
|
467
|
+
this.deviceFile = new DeviceFile(corestoreFile, {
|
|
468
|
+
wait: this.wait,
|
|
469
|
+
data: { id: this.id }
|
|
470
|
+
})
|
|
471
|
+
|
|
472
|
+
await this.deviceFile.ready()
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
455
476
|
async ready() {
|
|
456
477
|
if (this.version === 0) await this._migrateStore()
|
|
457
478
|
return this.db.ready()
|
|
@@ -537,20 +558,9 @@ class CorestoreStorage {
|
|
|
537
558
|
try {
|
|
538
559
|
if (this.version === VERSION) return
|
|
539
560
|
|
|
561
|
+
await this._preopen
|
|
540
562
|
await this.db.ready()
|
|
541
563
|
|
|
542
|
-
if (this.bootstrap && !this.readOnly && !this.allowBackup) {
|
|
543
|
-
const corestoreFile = path.join(this.path, 'CORESTORE')
|
|
544
|
-
|
|
545
|
-
this.deviceFile = new DeviceFile(corestoreFile, {
|
|
546
|
-
wait: this.wait,
|
|
547
|
-
lock: this.lock,
|
|
548
|
-
data: { id: this.id }
|
|
549
|
-
})
|
|
550
|
-
|
|
551
|
-
await this.deviceFile.ready()
|
|
552
|
-
}
|
|
553
|
-
|
|
554
564
|
const rx = new CorestoreRX(this.db, view)
|
|
555
565
|
const headPromise = rx.getHead()
|
|
556
566
|
|
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)
|