Skip to content

Commit 1c42f42

Browse files
authored
deps: update interface-datastore and friends (#409)
1 parent ae9cf3e commit 1c42f42

File tree

8 files changed

+224
-111
lines changed

8 files changed

+224
-111
lines changed

.github/workflows/js-test-and-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
runs-on: ${{ matrix.os }}
2626
strategy:
2727
matrix:
28-
os: [windows-latest, ubuntu-latest, macos-latest]
28+
os: [ubuntu-latest, macos-latest]
2929
node: [16]
3030
fail-fast: true
3131
steps:

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ logs
1010
*.log
1111

1212
coverage
13+
.coverage
1314

1415
# Runtime data
1516
pids

packages/ipfs-repo-migrations/package.json

+8-8
Original file line numberDiff line numberDiff line change
@@ -173,11 +173,11 @@
173173
"dependencies": {
174174
"@ipld/dag-pb": "^2.1.0",
175175
"cborg": "^1.3.4",
176-
"datastore-core": "^7.0.0",
176+
"datastore-core": "^8.0.1",
177177
"debug": "^4.1.0",
178178
"fnv1a": "^1.0.1",
179-
"interface-blockstore": "^2.0.2",
180-
"interface-datastore": "^6.0.2",
179+
"interface-blockstore": "^3.0.0",
180+
"interface-datastore": "^7.0.0",
181181
"it-length": "^1.0.1",
182182
"multiaddr": "^10.0.1",
183183
"multiformats": "^9.0.4",
@@ -192,11 +192,11 @@
192192
"@types/varint": "^6.0.0",
193193
"aegir": "^37.5.0",
194194
"aws-sdk": "^2.884.0",
195-
"blockstore-core": "^1.0.2",
196-
"blockstore-datastore-adapter": "^2.0.1",
197-
"datastore-fs": "^7.0.0",
198-
"datastore-level": "^8.0.0",
199-
"datastore-s3": "^9.0.0",
195+
"blockstore-core": "^2.0.0",
196+
"blockstore-datastore-adapter": "^3.0.1",
197+
"datastore-fs": "^8.0.0",
198+
"datastore-level": "^9.0.0",
199+
"datastore-s3": "^10.0.0",
200200
"protobufjs-cli": "^1.0.0",
201201
"just-safe-set": "^4.1.1",
202202
"level-5": "npm:level@^5.0.0",

packages/ipfs-repo-migrations/test/fixtures/repo.js

+17-8
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,35 @@
1-
21
import loadFixture from 'aegir/fixtures'
32
import { CONFIG_KEY, VERSION_KEY } from '../../src/utils.js'
3+
import fs from 'fs/promises'
44

55
/**
66
* @typedef {import('../../src/types').Backends} Backends
7+
* @typedef {import('../types').SetupOptions} SetupOptions
8+
* @typedef {import('../types').CreateBackends} CreateBackends
79
*/
810

911
/**
10-
*
11-
* @param {(dir: string) => import('../../src/types').Backends} createBackends
12-
* @param {*} prefix
13-
* @returns
12+
* @param {CreateBackends} createBackends
13+
* @param {SetupOptions} [opts]
1414
*/
15-
export async function createRepo (createBackends, prefix) {
16-
const dir = `${prefix ? `${prefix}/` : ''}test-repo-for-${Date.now()}`
17-
const backends = createBackends(dir)
15+
export async function createRepo (createBackends, opts = {}) {
16+
let dir = opts.dir
17+
const prefix = opts.prefix ?? ''
18+
19+
if (dir == null) {
20+
dir = [prefix, `test-repo-for-${Date.now()}`].filter(Boolean).join('/')
21+
await fs.mkdir(dir, {
22+
recursive: true
23+
})
24+
}
1825

26+
const backends = createBackends(dir, opts.createBackends)
1927
await backends.root.open()
2028
await backends.root.close()
2129

2230
return {
2331
dir,
32+
prefix,
2433
backends
2534
}
2635
}

packages/ipfs-repo-migrations/test/migrations/migration-10-test.js

+126-70
Original file line numberDiff line numberDiff line change
@@ -53,128 +53,184 @@ async function validate (store) {
5353
if (store instanceof BaseBlockstore) {
5454
const key = CID.parse(`b${name.toLowerCase()}`)
5555

56-
expect(await store.has(key)).to.be.true(`Could not read key ${name}`)
57-
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]}`)
56+
await expect(store.has(key)).to.eventually.be.true(`Could not read key ${name} from blockstore`)
57+
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]} from blockstore`)
5858
} else {
5959
const key = new Key(`/${name}`)
6060

61-
await expect(store.has(key)).to.eventually.be.true(`Could not read key ${name}`)
62-
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]}`)
61+
await expect(store.has(key)).to.eventually.be.true(`Could not read key ${name} from datastore`)
62+
expect(equals(await store.get(key), keys[name])).to.be.true(`Could not read value for key ${keys[name]} from datastore`)
6363
}
6464
}
6565

6666
await store.close()
6767
}
6868

69-
/**
70-
* @param {Backends} backends
71-
* @param {*} LevelImpl
72-
* @returns {Backends}
73-
*/
74-
function withLevels (backends, LevelImpl) {
75-
const output = {
76-
...backends
77-
}
78-
79-
Object.entries(backends)
80-
.forEach(([key, value]) => {
81-
// @ts-ignore it's ok
82-
output[key] = withLevel(value, LevelImpl)
83-
})
84-
85-
return output
86-
}
87-
88-
/**
89-
* @param {Datastore} store
90-
* @param {*} LevelImpl
91-
*/
92-
function withLevel (store, LevelImpl) {
93-
let parent = {
94-
child: store
95-
}
96-
97-
while (parent.child) {
98-
if (parent.child.constructor.name === 'LevelDatastore') {
99-
// @ts-ignore undocumented properties
100-
parent.child.database = LevelImpl
101-
// @ts-ignore undocumented properties
102-
delete parent.child.db
103-
104-
return store
105-
}
106-
107-
// @ts-ignore undocumented properties
108-
parent = parent.child
109-
}
110-
111-
return store
112-
}
113-
11469
/**
11570
* @param {import('../types').SetupFunction} setup
11671
* @param {import('../types').CleanupFunction} cleanup
11772
*/
11873
export function test (setup, cleanup) {
11974
describe('migration 10', function () {
12075
this.timeout(1024 * 1000)
121-
/** @type {string} */
122-
let dir
123-
/** @type {import('../../src/types').Backends} */
124-
let backends
125-
126-
beforeEach(async () => {
127-
({ dir, backends } = await setup())
128-
})
129-
130-
afterEach(async () => {
131-
await cleanup(dir)
132-
})
13376

13477
describe('forwards', () => {
78+
/** @type {string} */
79+
let dir
80+
/** @type {import('../../src/types').Backends} */
81+
let backends
82+
/** @type {string} */
83+
let prefix
84+
13585
beforeEach(async () => {
86+
({ dir, prefix, backends } = await setup({
87+
createBackends: {
88+
createLevel: (path) => new Level5(path, {
89+
valueEncoding: 'binary'
90+
})
91+
}
92+
}))
93+
13694
for (const backend of Object.values(backends)) {
137-
await bootstrap(withLevel(backend, Level5))
95+
await bootstrap(backend)
96+
}
97+
})
98+
99+
afterEach(async () => {
100+
if (dir != null) {
101+
await cleanup(dir)
138102
}
139103
})
140104

141105
it('should migrate keys and values forward', async () => {
142-
await migration.migrate(withLevels(backends, Level6), () => {})
106+
({ backends } = await setup({
107+
dir,
108+
prefix,
109+
createBackends: {
110+
createLevel: (path) => new Level6(path, {
111+
valueEncoding: 'binary'
112+
})
113+
}
114+
}))
115+
116+
await migration.migrate(backends, () => {})
143117

144118
for (const backend of Object.values(backends)) {
145-
await validate(withLevel(backend, Level6))
119+
await validate(backend)
146120
}
147121
})
148122
})
149123

150124
describe('backwards using [email protected]', () => {
125+
/** @type {string} */
126+
let dir
127+
/** @type {import('../../src/types').Backends} */
128+
let backends
129+
/** @type {string} */
130+
let prefix
131+
151132
beforeEach(async () => {
133+
({ dir, prefix, backends } = await setup({
134+
createBackends: {
135+
createLevel: (path) => new Level6(path, {
136+
valueEncoding: 'binary'
137+
})
138+
}
139+
}))
140+
152141
for (const backend of Object.values(backends)) {
153-
await bootstrap(withLevel(backend, Level6))
142+
await bootstrap(backend)
143+
}
144+
})
145+
146+
afterEach(async () => {
147+
if (dir != null) {
148+
await cleanup(dir)
154149
}
155150
})
156151

157152
it('should migrate keys and values backward', async () => {
158-
await migration.revert(withLevels(backends, Level6), () => {})
153+
({ backends } = await setup({
154+
dir,
155+
prefix,
156+
createBackends: {
157+
createLevel: (path) => new Level6(path, {
158+
valueEncoding: 'binary'
159+
})
160+
}
161+
}))
162+
163+
await migration.revert(backends, () => {})
164+
165+
;({ backends } = await setup({
166+
dir,
167+
prefix,
168+
createBackends: {
169+
createLevel: (path) => new Level5(path, {
170+
valueEncoding: 'binary'
171+
})
172+
}
173+
}))
159174

160175
for (const backend of Object.values(backends)) {
161-
await validate(withLevel(backend, Level5))
176+
await validate(backend)
162177
}
163178
})
164179
})
165180

166181
describe('backwards using [email protected]', () => {
182+
/** @type {string} */
183+
let dir
184+
/** @type {import('../../src/types').Backends} */
185+
let backends
186+
/** @type {string} */
187+
let prefix
188+
167189
beforeEach(async () => {
190+
({ dir, prefix, backends } = await setup({
191+
createBackends: {
192+
createLevel: (path) => new Level6(path, {
193+
valueEncoding: 'binary'
194+
})
195+
}
196+
}))
197+
168198
for (const backend of Object.values(backends)) {
169-
await bootstrap(withLevel(backend, Level6))
199+
await bootstrap(backend)
200+
}
201+
})
202+
203+
afterEach(async () => {
204+
if (dir != null) {
205+
await cleanup(dir)
170206
}
171207
})
172208

173209
it('should migrate keys and values backward', async () => {
174-
await migration.revert(withLevels(backends, Level5), () => {})
210+
({ backends } = await setup({
211+
dir,
212+
prefix,
213+
createBackends: {
214+
createLevel: (path) => new Level5(path, {
215+
valueEncoding: 'binary'
216+
})
217+
}
218+
}))
219+
220+
await migration.revert(backends, () => {})
221+
222+
;({ backends } = await setup({
223+
dir,
224+
prefix,
225+
createBackends: {
226+
createLevel: (path) => new Level5(path, {
227+
valueEncoding: 'binary'
228+
})
229+
}
230+
}))
175231

176232
for (const backend of Object.values(backends)) {
177-
await validate(withLevel(backend, Level5))
233+
await validate(backend)
178234
}
179235
})
180236
})

0 commit comments

Comments
 (0)