hypercore 10.0.0-alpha.48 → 10.0.0-alpha.50

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 +4 -2
  2. package/lib/errors.js +19 -11
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -185,10 +185,12 @@ module.exports = class Hypercore extends EventEmitter {
185
185
  }
186
186
 
187
187
  const sparse = opts.sparse === false ? false : this.sparse
188
+ const onwait = opts.onwait === undefined ? this.onwait : opts.onwait
188
189
  const Clz = opts.class || Hypercore
189
190
  const s = new Clz(this.storage, this.key, {
190
191
  ...opts,
191
192
  sparse,
193
+ onwait,
192
194
  _opening: this.opening,
193
195
  _sessions: this.sessions
194
196
  })
@@ -662,8 +664,8 @@ module.exports = class Hypercore extends EventEmitter {
662
664
  if (this.cache) this.cache.set(index, req)
663
665
  } else {
664
666
  if (opts && opts.wait === false) return null
665
- if (opts && opts.onwait) opts.onwait(index)
666
- else if (this.onwait) this.onwait(index)
667
+ if (opts && opts.onwait) opts.onwait(index, this)
668
+ else if (this.onwait) this.onwait(index, this)
667
669
 
668
670
  const activeRequests = (opts && opts.activeRequests) || this.activeRequests
669
671
 
package/lib/errors.js CHANGED
@@ -1,42 +1,50 @@
1
1
  module.exports = class HypercoreError extends Error {
2
- constructor (msg, code) {
3
- super(msg)
2
+ constructor (msg, code, fn = HypercoreError) {
3
+ super(`${code}: ${msg}`)
4
4
  this.code = code
5
+
6
+ if (Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, fn)
8
+ }
9
+ }
10
+
11
+ get name () {
12
+ return 'HypercoreError'
5
13
  }
6
14
 
7
15
  static BAD_ARGUMENT (msg) {
8
- return new HypercoreError(msg, 'BAD_ARGUMENT')
16
+ return new HypercoreError(msg, 'BAD_ARGUMENT', HypercoreError.BAD_ARGUMENT)
9
17
  }
10
18
 
11
19
  static STORAGE_EMPTY (msg) {
12
- return new HypercoreError(msg, 'STORAGE_EMPTY')
20
+ return new HypercoreError(msg, 'STORAGE_EMPTY', HypercoreError.STORAGE_EMPTY)
13
21
  }
14
22
 
15
23
  static STORAGE_CONFLICT (msg) {
16
- return new HypercoreError(msg, 'STORAGE_CONFLICT')
24
+ return new HypercoreError(msg, 'STORAGE_CONFLICT', HypercoreError.STORAGE_CONFLICT)
17
25
  }
18
26
 
19
27
  static INVALID_SIGNATURE (msg) {
20
- return new HypercoreError(msg, 'INVALID_SIGNATURE')
28
+ return new HypercoreError(msg, 'INVALID_SIGNATURE', HypercoreError.INVALID_SIGNATURE)
21
29
  }
22
30
 
23
31
  static INVALID_CAPABILITY (msg) {
24
- return new HypercoreError(msg, 'INVALID_CAPABILITY')
32
+ return new HypercoreError(msg, 'INVALID_CAPABILITY', HypercoreError.INVALID_CAPABILITY)
25
33
  }
26
34
 
27
35
  static SNAPSHOT_NOT_AVAILABLE (msg = 'Snapshot is not available') {
28
- return new HypercoreError(msg, 'SNAPSHOT_NOT_AVAILABLE')
36
+ return new HypercoreError(msg, 'SNAPSHOT_NOT_AVAILABLE', HypercoreError.SNAPSHOT_NOT_AVAILABLE)
29
37
  }
30
38
 
31
39
  static REQUEST_CANCELLED (msg = 'Request was cancelled') {
32
- return new HypercoreError(msg, 'REQUEST_CANCELLED')
40
+ return new HypercoreError(msg, 'REQUEST_CANCELLED', HypercoreError.REQUEST_CANCELLED)
33
41
  }
34
42
 
35
43
  static SESSION_NOT_WRITABLE (msg = 'Session is not writable') {
36
- return new HypercoreError(msg, 'SESSION_NOT_WRITABLE')
44
+ return new HypercoreError(msg, 'SESSION_NOT_WRITABLE', HypercoreError.SESSION_NOT_WRITABLE)
37
45
  }
38
46
 
39
47
  static SESSION_CLOSED (msg = 'Session is closed') {
40
- return new HypercoreError(msg, 'SESSION_CLOSED')
48
+ return new HypercoreError(msg, 'SESSION_CLOSED', HypercoreError.SESSION_CLOSED)
41
49
  }
42
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hypercore",
3
- "version": "10.0.0-alpha.48",
3
+ "version": "10.0.0-alpha.50",
4
4
  "description": "Hypercore 10",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -32,7 +32,7 @@
32
32
  "lib/**.js"
33
33
  ],
34
34
  "dependencies": {
35
- "@hyperswarm/secret-stream": "^5.2.0",
35
+ "@hyperswarm/secret-stream": "^6.0.0",
36
36
  "b4a": "^1.1.0",
37
37
  "big-sparse-array": "^1.0.2",
38
38
  "codecs": "^3.0.0",