hypercore-storage 2.0.1 → 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.
Files changed (3) hide show
  1. package/index.js +26 -14
  2. package/lib/streams.js +2 -1
  3. 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
 
@@ -429,11 +430,11 @@ class CorestoreStorage {
429
430
  this.deviceFile = null
430
431
  this.wait = !!opts.wait
431
432
 
433
+ const preopen = this._openDeviceFile()
434
+
432
435
  // tmp sync fix for simplicty since not super deployed yet
433
436
  if (this.bootstrap && !this.readOnly) tmpFixStorage(this.path)
434
437
 
435
- this.rocks = storage === null ? db : new RocksDB(path.join(this.path, 'db'), opts)
436
- this.db = createColumnFamily(this.rocks, opts)
437
438
  this.id = opts.id || null
438
439
  this.view = null
439
440
  this.enters = 0
@@ -441,6 +442,14 @@ class CorestoreStorage {
441
442
  this.flushing = null
442
443
  this.version = 0
443
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
444
453
  }
445
454
 
446
455
  get opened() {
@@ -451,6 +460,19 @@ class CorestoreStorage {
451
460
  return this.db.closed
452
461
  }
453
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
+
454
476
  async ready() {
455
477
  if (this.version === 0) await this._migrateStore()
456
478
  return this.db.ready()
@@ -536,19 +558,9 @@ class CorestoreStorage {
536
558
  try {
537
559
  if (this.version === VERSION) return
538
560
 
561
+ await this._preopen
539
562
  await this.db.ready()
540
563
 
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
564
  const rx = new CorestoreRX(this.db, view)
553
565
  const headPromise = rx.getHead()
554
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore-storage",
3
- "version": "2.0.1",
3
+ "version": "2.0.2",
4
4
  "main": "index.js",
5
5
  "files": [
6
6
  "index.js",