corestore 6.0.1-alpha.12 → 6.0.1-alpha.13

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 CHANGED
@@ -202,7 +202,7 @@ module.exports = class Corestore extends EventEmitter {
202
202
 
203
203
  async _close () {
204
204
  await this._opening
205
- if (!this._namespace.equals(DEFAULT_NAMESPACE)) return // namespaces should not release resources on close
205
+ if (!b4a.equals(this._namespace, DEFAULT_NAMESPACE)) return // namespaces should not release resources on close
206
206
  const closePromises = []
207
207
  for (const core of this.cores.values()) {
208
208
  closePromises.push(core.close())
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "corestore",
3
- "version": "6.0.1-alpha.12",
3
+ "version": "6.0.1-alpha.13",
4
4
  "description": "A Hypercore factory that simplifies managing collections of cores.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -22,9 +22,8 @@
22
22
  "devDependencies": {
23
23
  "brittle": "^1.6.0",
24
24
  "random-access-file": "^2.2.0",
25
- "random-access-memory": "^3.1.2",
26
- "standardx": "^7.0.0",
27
- "tmp-promise": "^3.0.2"
25
+ "random-access-memory": "^4.0.0",
26
+ "standardx": "^7.0.0"
28
27
  },
29
28
  "dependencies": {
30
29
  "b4a": "^1.3.1",
package/test/all.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const { test, configure } = require('brittle')
2
2
  const crypto = require('hypercore-crypto')
3
3
  const ram = require('random-access-memory')
4
- const tmp = require('tmp-promise')
4
+ const os = require('os')
5
+ const path = require('path')
5
6
 
6
7
  const Corestore = require('..')
7
8
 
@@ -99,8 +100,8 @@ test('replicating cores created after replication begins', async function (t) {
99
100
  })
100
101
 
101
102
  test('replicating cores using discovery key hook', async function (t) {
102
- const dir = await tmp.dir({ unsafeCleanup: true })
103
- let store1 = new Corestore(dir.path)
103
+ const dir = tmpdir()
104
+ let store1 = new Corestore(dir)
104
105
  const store2 = new Corestore(ram)
105
106
 
106
107
  const core = store1.get({ name: 'main' })
@@ -108,15 +109,13 @@ test('replicating cores using discovery key hook', async function (t) {
108
109
  const key = core.key
109
110
 
110
111
  await store1.close()
111
- store1 = new Corestore(dir.path)
112
+ store1 = new Corestore(dir)
112
113
 
113
114
  const s = store1.replicate(true, { live: true })
114
115
  s.pipe(store2.replicate(false, { live: true })).pipe(s)
115
116
 
116
117
  const core2 = store2.get(key)
117
118
  t.alike(await core2.get(0), Buffer.from('hello'))
118
-
119
- await dir.cleanup()
120
119
  })
121
120
 
122
121
  test('nested namespaces', async function (t) {
@@ -144,9 +143,9 @@ test('core uncached when all sessions close', async function (t) {
144
143
  })
145
144
 
146
145
  test('writable core loaded from name userData', async function (t) {
147
- const dir = await tmp.dir({ unsafeCleanup: true })
146
+ const dir = tmpdir()
148
147
 
149
- let store = new Corestore(dir.path)
148
+ let store = new Corestore(dir)
150
149
  let core = store.get({ name: 'main' })
151
150
  await core.ready()
152
151
  const key = core.key
@@ -156,7 +155,7 @@ test('writable core loaded from name userData', async function (t) {
156
155
  t.is(core.length, 1)
157
156
 
158
157
  await store.close()
159
- store = new Corestore(dir.path)
158
+ store = new Corestore(dir)
160
159
  core = store.get(key)
161
160
  await core.ready()
162
161
 
@@ -165,25 +164,21 @@ test('writable core loaded from name userData', async function (t) {
165
164
  t.is(core.length, 2)
166
165
  t.alike(await core.get(0), Buffer.from('hello'))
167
166
  t.alike(await core.get(1), Buffer.from('world'))
168
-
169
- await dir.cleanup()
170
167
  })
171
168
 
172
169
  test('storage locking', async function (t) {
173
- const dir = await tmp.dir({ unsafeCleanup: true })
170
+ const dir = tmpdir()
174
171
 
175
- const store1 = new Corestore(dir.path)
172
+ const store1 = new Corestore(dir)
176
173
  await store1.ready()
177
174
 
178
- const store2 = new Corestore(dir.path)
175
+ const store2 = new Corestore(dir)
179
176
  try {
180
177
  await store2.ready()
181
178
  t.fail('dir should have been locked')
182
179
  } catch {
183
180
  t.pass('dir was locked')
184
181
  }
185
-
186
- await dir.cleanup()
187
182
  })
188
183
 
189
184
  test('closing a namespace does not close cores', async function (t) {
@@ -205,3 +200,7 @@ test('closing a namespace does not close cores', async function (t) {
205
200
  t.ok(core1.closed)
206
201
  t.ok(core2.closed)
207
202
  })
203
+
204
+ function tmpdir () {
205
+ return path.join(os.tmpdir(), 'corestore-' + Math.random().toString(16).slice(2))
206
+ }
package/test/keys.js CHANGED
@@ -41,7 +41,7 @@ test('short user-provided token will throw', async t => {
41
41
  })
42
42
 
43
43
  test('persistent storage regenerates keys correctly', async t => {
44
- const testPath = p.resolve(__dirname, 'test-data')
44
+ const testPath = p.join(__dirname, 'test-data')
45
45
 
46
46
  const keys1 = await KeyManager.fromStorage((name) => raf(testPath, { directory: testPath }))
47
47
  const kp1 = await keys1.createHypercoreKeyPair('core1')
@@ -51,6 +51,9 @@ test('persistent storage regenerates keys correctly', async t => {
51
51
 
52
52
  t.alike(kp1.publicKey, kp2.publicKey)
53
53
 
54
+ await keys1.close()
55
+ await keys2.close()
56
+
54
57
  await fs.promises.rm(testPath, { recursive: true })
55
58
  })
56
59