Skip to content

Commit 2501f19

Browse files
authored
feat: expose apiAddr property (#720)
It is used in some tests but is missing from the types. Also updates deps.
1 parent 66a9470 commit 2501f19

File tree

10 files changed

+36
-78
lines changed

10 files changed

+36
-78
lines changed

.github/workflows/main.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ jobs:
1212
runs-on: ubuntu-latest
1313
steps:
1414
- uses: actions/checkout@v2
15-
- uses: actions/setup-node@v1
15+
- uses: actions/setup-node@v2
1616
with:
17-
node-version: 16
17+
node-version: lts/*
1818
- run: npm install
1919
- run: npm run lint
2020
- run: npm run build
@@ -30,11 +30,11 @@ jobs:
3030
strategy:
3131
matrix:
3232
os: [windows-latest, ubuntu-latest, macos-latest]
33-
node: [14, 16]
33+
node: [16]
3434
fail-fast: true
3535
steps:
3636
- uses: actions/checkout@v2
37-
- uses: actions/setup-node@v1
37+
- uses: actions/setup-node@v2
3838
with:
3939
node-version: ${{ matrix.node }}
4040
- run: npm install
@@ -45,38 +45,38 @@ jobs:
4545
runs-on: ubuntu-latest
4646
steps:
4747
- uses: actions/checkout@v2
48-
- uses: actions/setup-node@v1
48+
- uses: actions/setup-node@v2
4949
with:
50-
node-version: 16
50+
node-version: lts/*
5151
- run: npm install
5252
- run: npx aegir test -t browser -t webworker --timeout 10000
5353
test-firefox:
5454
needs: check
5555
runs-on: ubuntu-latest
5656
steps:
5757
- uses: actions/checkout@v2
58-
- uses: actions/setup-node@v1
58+
- uses: actions/setup-node@v2
5959
with:
60-
node-version: 16
60+
node-version: lts/*
6161
- run: npm install
6262
- run: npx aegir test -t browser -t webworker --timeout 10000 -- --browser firefox
6363
test-electron-main:
6464
needs: check
6565
runs-on: ubuntu-latest
6666
steps:
6767
- uses: actions/checkout@v2
68-
- uses: actions/setup-node@v1
68+
- uses: actions/setup-node@v2
6969
with:
70-
node-version: 16
70+
node-version: lts/*
7171
- run: npm install
7272
- run: npx xvfb-maybe aegir test -t electron-main --bail --timeout 10000
7373
test-electron-renderer:
7474
needs: check
7575
runs-on: ubuntu-latest
7676
steps:
7777
- uses: actions/checkout@v2
78-
- uses: actions/setup-node@v1
78+
- uses: actions/setup-node@v2
7979
with:
80-
node-version: 16
80+
node-version: lts/*
8181
- run: npm install
8282
- run: npx xvfb-maybe aegir test -t electron-renderer --bail --timeout 10000

examples/electron-asar/app.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ ipcMain.on('start', async ({ sender }) => {
4343
sender.send('id', JSON.stringify(id))
4444
await node.stop()
4545
await s.stop()
46-
} catch (error) {
46+
} catch (/** @type {any} */ error) {
4747
sender.send('error', JSON.stringify(error.message))
4848
console.log(error)
4949
}

package.json

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,12 @@
5454
},
5555
"devDependencies": {
5656
"@types/hapi__hapi": "^20.0.9",
57-
"aegir": "^35.1.1",
58-
"go-ipfs": "^0.9.1",
59-
"ipfs": "^0.59.0",
57+
"aegir": "^36.1.3",
58+
"go-ipfs": "^0.12.0",
59+
"ipfs": "^0.62.1",
6060
"ipfs-client": "^0.7.0",
61-
"ipfs-core-types": "^0.8.0",
62-
"ipfs-http-client": "^53.0.0",
63-
"ipfs-unixfs": "^6.0.6",
64-
"it-last": "^1.0.5",
61+
"ipfs-core-types": "^0.10.1",
62+
"ipfs-http-client": "^56.0.1",
6563
"util": "^0.12.4"
6664
},
6765
"repository": {

src/endpoint/routes.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ module.exports = (server, createFactory) => {
4848
const type = request.query.type || 'go'
4949
try {
5050
return { tmpDir: await tmpDir(type) }
51-
} catch (err) {
51+
} catch (/** @type {any} */ err) {
5252
badRequest(err)
5353
}
5454
}
@@ -62,7 +62,7 @@ module.exports = (server, createFactory) => {
6262

6363
try {
6464
return { version: await nodes[id].version() }
65-
} catch (err) {
65+
} catch (/** @type {any} */ err) {
6666
badRequest(err)
6767
}
6868
},
@@ -90,7 +90,7 @@ module.exports = (server, createFactory) => {
9090
path: nodes[id].path,
9191
clean: nodes[id].clean
9292
}
93-
} catch (err) {
93+
} catch (/** @type {any} */ err) {
9494
badRequest(err)
9595
}
9696
}
@@ -112,7 +112,7 @@ module.exports = (server, createFactory) => {
112112
return {
113113
initialized: nodes[id].initialized
114114
}
115-
} catch (err) {
115+
} catch (/** @type {any} */ err) {
116116
badRequest(err)
117117
}
118118
},
@@ -136,7 +136,7 @@ module.exports = (server, createFactory) => {
136136
gatewayAddr: nodes[id].gatewayAddr ? nodes[id].gatewayAddr.toString() : '',
137137
grpcAddr: nodes[id].grpcAddr ? nodes[id].grpcAddr.toString() : ''
138138
}
139-
} catch (err) {
139+
} catch (/** @type {any} */ err) {
140140
badRequest(err)
141141
}
142142
},
@@ -158,7 +158,7 @@ module.exports = (server, createFactory) => {
158158
await nodes[id].cleanup()
159159

160160
return h.response().code(200)
161-
} catch (err) {
161+
} catch (/** @type {any} */ err) {
162162
badRequest(err)
163163
}
164164
},
@@ -178,7 +178,7 @@ module.exports = (server, createFactory) => {
178178
await nodes[id].stop()
179179

180180
return h.response().code(200)
181-
} catch (err) {
181+
} catch (/** @type {any} */ err) {
182182
badRequest(err)
183183
}
184184
},

src/ipfsd-client.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class Client {
3636
this.api = null
3737
/** @type {import('./types').Subprocess | null} */
3838
this.subprocess = null
39+
/** @type {Multiaddr} */
40+
this.apiAddr // eslint-disable-line no-unused-expressions
3941

4042
this._setApi(remoteState.apiAddr)
4143
this._setGateway(remoteState.gatewayAddr)

src/ipfsd-daemon.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ class Daemon {
5252
this.initialized = false
5353
this.started = false
5454
this.clean = true
55-
this.apiAddr = null
55+
/** @type {Multiaddr} */
56+
this.apiAddr // eslint-disable-line no-unused-expressions
5657
this.grpcAddr = null
5758
this.gatewayAddr = null
5859
this.api = null

src/ipfsd-in-proc.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ class InProc {
2929
this.initialized = false
3030
this.started = false
3131
this.clean = true
32-
this.apiAddr = null
32+
/** @type {Multiaddr} */
33+
this.apiAddr // eslint-disable-line no-unused-expressions
3334
this.api = null
3435
/** @type {import('./types').Subprocess | null} */
3536
this.subprocess = null

src/types.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11

22
import { EventEmitter } from 'events'
33
import { IPFS } from 'ipfs-core-types'
4+
import type { Multiaddr } from 'multiaddr'
45

56
export interface Subprocess {
67
stderr: EventEmitter | null
@@ -21,6 +22,7 @@ export interface Controller {
2122
api: IPFS
2223
subprocess?: Subprocess | null
2324
opts: ControllerOptions
25+
apiAddr: Multiaddr
2426
}
2527

2628
export interface RemoteState {

src/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const removeRepo = async (repoPath) => {
1717
await fs.promises.rm(repoPath, {
1818
recursive: true
1919
})
20-
} catch (err) {
20+
} catch (/** @type {any} */ err) {
2121
// ignore
2222
}
2323
}
@@ -50,7 +50,7 @@ const checkForRunningApi = (repoPath = '') => {
5050
let api
5151
try {
5252
api = fs.readFileSync(path.join(repoPath, 'api'))
53-
} catch (err) {
53+
} catch (/** @type {any} */ err) {
5454
log('Unable to open api file')
5555
}
5656

test/factory.spec.js

Lines changed: 1 addition & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
const { expect } = require('aegir/utils/chai')
55
const { isNode } = require('ipfs-utils/src/env')
66
const { createFactory } = require('../src')
7-
const { UnixFS } = require('ipfs-unixfs')
8-
const last = require('it-last')
97

108
const defaultOps = {
119
ipfsHttpModule: require('ipfs-http-client')
@@ -158,56 +156,12 @@ describe('`Factory spawn()` ', function () {
158156
await ctl2.stop()
159157
try {
160158
await factory.clean()
161-
} catch (error) {
159+
} catch (/** @type {any} */ error) {
162160
expect(error).to.not.exist()
163161
}
164162
expect(ctl1.started).to.be.false()
165163
expect(ctl2.started).to.be.false()
166164
})
167165
}
168166
})
169-
170-
describe('should return a node with sharding enabled', () => {
171-
for (const opts of types) {
172-
it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => {
173-
const factory = await createFactory()
174-
const node = await factory.spawn({
175-
...opts,
176-
ipfsOptions: {
177-
EXPERIMENTAL: {
178-
// enable sharding for js
179-
sharding: true
180-
},
181-
config: {
182-
// enabled sharding for go
183-
Experimental: {
184-
ShardingEnabled: true
185-
}
186-
}
187-
}
188-
})
189-
expect(node).to.exist()
190-
expect(node.api).to.exist()
191-
expect(node.api.id).to.exist()
192-
193-
const res = await last(node.api.addAll([{ path: 'derp.txt', content: 'hello' }], {
194-
shardSplitThreshold: 0,
195-
wrapWithDirectory: true
196-
}))
197-
198-
if (!res) {
199-
throw new Error('No result from ipfs.addAll')
200-
}
201-
202-
const { cid } = res
203-
204-
const { value: dagNode } = await node.api.dag.get(cid)
205-
const entry = UnixFS.unmarshal(dagNode.Data)
206-
207-
expect(entry.type).to.equal('hamt-sharded-directory')
208-
209-
await node.stop()
210-
})
211-
}
212-
})
213167
})

0 commit comments

Comments
 (0)