Skip to content

Commit

Permalink
feat: expose apiAddr property (#720)
Browse files Browse the repository at this point in the history
It is used in some tests but is missing from the types.

Also updates deps.
  • Loading branch information
achingbrain committed Feb 22, 2022
1 parent 66a9470 commit 2501f19
Show file tree
Hide file tree
Showing 10 changed files with 36 additions and 78 deletions.
24 changes: 12 additions & 12 deletions .github/workflows/main.yml
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: lts/*
- run: npm install
- run: npm run lint
- run: npm run build
Expand All @@ -30,11 +30,11 @@ jobs:
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
node: [14, 16]
node: [16]
fail-fast: true
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node }}
- run: npm install
Expand All @@ -45,38 +45,38 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: lts/*
- run: npm install
- run: npx aegir test -t browser -t webworker --timeout 10000
test-firefox:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: lts/*
- run: npm install
- run: npx aegir test -t browser -t webworker --timeout 10000 -- --browser firefox
test-electron-main:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: lts/*
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-main --bail --timeout 10000
test-electron-renderer:
needs: check
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
- uses: actions/setup-node@v2
with:
node-version: 16
node-version: lts/*
- run: npm install
- run: npx xvfb-maybe aegir test -t electron-renderer --bail --timeout 10000
2 changes: 1 addition & 1 deletion examples/electron-asar/app.js
Expand Up @@ -43,7 +43,7 @@ ipcMain.on('start', async ({ sender }) => {
sender.send('id', JSON.stringify(id))
await node.stop()
await s.stop()
} catch (error) {
} catch (/** @type {any} */ error) {
sender.send('error', JSON.stringify(error.message))
console.log(error)
}
Expand Down
12 changes: 5 additions & 7 deletions package.json
Expand Up @@ -54,14 +54,12 @@
},
"devDependencies": {
"@types/hapi__hapi": "^20.0.9",
"aegir": "^35.1.1",
"go-ipfs": "^0.9.1",
"ipfs": "^0.59.0",
"aegir": "^36.1.3",
"go-ipfs": "^0.12.0",
"ipfs": "^0.62.1",
"ipfs-client": "^0.7.0",
"ipfs-core-types": "^0.8.0",
"ipfs-http-client": "^53.0.0",
"ipfs-unixfs": "^6.0.6",
"it-last": "^1.0.5",
"ipfs-core-types": "^0.10.1",
"ipfs-http-client": "^56.0.1",
"util": "^0.12.4"
},
"repository": {
Expand Down
14 changes: 7 additions & 7 deletions src/endpoint/routes.js
Expand Up @@ -48,7 +48,7 @@ module.exports = (server, createFactory) => {
const type = request.query.type || 'go'
try {
return { tmpDir: await tmpDir(type) }
} catch (err) {
} catch (/** @type {any} */ err) {
badRequest(err)
}
}
Expand All @@ -62,7 +62,7 @@ module.exports = (server, createFactory) => {

try {
return { version: await nodes[id].version() }
} catch (err) {
} catch (/** @type {any} */ err) {
badRequest(err)
}
},
Expand Down Expand Up @@ -90,7 +90,7 @@ module.exports = (server, createFactory) => {
path: nodes[id].path,
clean: nodes[id].clean
}
} catch (err) {
} catch (/** @type {any} */ err) {
badRequest(err)
}
}
Expand All @@ -112,7 +112,7 @@ module.exports = (server, createFactory) => {
return {
initialized: nodes[id].initialized
}
} catch (err) {
} catch (/** @type {any} */ err) {
badRequest(err)
}
},
Expand All @@ -136,7 +136,7 @@ module.exports = (server, createFactory) => {
gatewayAddr: nodes[id].gatewayAddr ? nodes[id].gatewayAddr.toString() : '',
grpcAddr: nodes[id].grpcAddr ? nodes[id].grpcAddr.toString() : ''
}
} catch (err) {
} catch (/** @type {any} */ err) {
badRequest(err)
}
},
Expand All @@ -158,7 +158,7 @@ module.exports = (server, createFactory) => {
await nodes[id].cleanup()

return h.response().code(200)
} catch (err) {
} catch (/** @type {any} */ err) {
badRequest(err)
}
},
Expand All @@ -178,7 +178,7 @@ module.exports = (server, createFactory) => {
await nodes[id].stop()

return h.response().code(200)
} catch (err) {
} catch (/** @type {any} */ err) {
badRequest(err)
}
},
Expand Down
2 changes: 2 additions & 0 deletions src/ipfsd-client.js
Expand Up @@ -36,6 +36,8 @@ class Client {
this.api = null
/** @type {import('./types').Subprocess | null} */
this.subprocess = null
/** @type {Multiaddr} */
this.apiAddr // eslint-disable-line no-unused-expressions

this._setApi(remoteState.apiAddr)
this._setGateway(remoteState.gatewayAddr)
Expand Down
3 changes: 2 additions & 1 deletion src/ipfsd-daemon.js
Expand Up @@ -52,7 +52,8 @@ class Daemon {
this.initialized = false
this.started = false
this.clean = true
this.apiAddr = null
/** @type {Multiaddr} */
this.apiAddr // eslint-disable-line no-unused-expressions
this.grpcAddr = null
this.gatewayAddr = null
this.api = null
Expand Down
3 changes: 2 additions & 1 deletion src/ipfsd-in-proc.js
Expand Up @@ -29,7 +29,8 @@ class InProc {
this.initialized = false
this.started = false
this.clean = true
this.apiAddr = null
/** @type {Multiaddr} */
this.apiAddr // eslint-disable-line no-unused-expressions
this.api = null
/** @type {import('./types').Subprocess | null} */
this.subprocess = null
Expand Down
2 changes: 2 additions & 0 deletions src/types.d.ts
@@ -1,6 +1,7 @@

import { EventEmitter } from 'events'
import { IPFS } from 'ipfs-core-types'
import type { Multiaddr } from 'multiaddr'

export interface Subprocess {
stderr: EventEmitter | null
Expand All @@ -21,6 +22,7 @@ export interface Controller {
api: IPFS
subprocess?: Subprocess | null
opts: ControllerOptions
apiAddr: Multiaddr
}

export interface RemoteState {
Expand Down
4 changes: 2 additions & 2 deletions src/utils.js
Expand Up @@ -17,7 +17,7 @@ const removeRepo = async (repoPath) => {
await fs.promises.rm(repoPath, {
recursive: true
})
} catch (err) {
} catch (/** @type {any} */ err) {
// ignore
}
}
Expand Down Expand Up @@ -50,7 +50,7 @@ const checkForRunningApi = (repoPath = '') => {
let api
try {
api = fs.readFileSync(path.join(repoPath, 'api'))
} catch (err) {
} catch (/** @type {any} */ err) {
log('Unable to open api file')
}

Expand Down
48 changes: 1 addition & 47 deletions test/factory.spec.js
Expand Up @@ -4,8 +4,6 @@
const { expect } = require('aegir/utils/chai')
const { isNode } = require('ipfs-utils/src/env')
const { createFactory } = require('../src')
const { UnixFS } = require('ipfs-unixfs')
const last = require('it-last')

const defaultOps = {
ipfsHttpModule: require('ipfs-http-client')
Expand Down Expand Up @@ -158,56 +156,12 @@ describe('`Factory spawn()` ', function () {
await ctl2.stop()
try {
await factory.clean()
} catch (error) {
} catch (/** @type {any} */ error) {
expect(error).to.not.exist()
}
expect(ctl1.started).to.be.false()
expect(ctl2.started).to.be.false()
})
}
})

describe('should return a node with sharding enabled', () => {
for (const opts of types) {
it(`type: ${opts.type} remote: ${Boolean(opts.remote)}`, async () => {
const factory = await createFactory()
const node = await factory.spawn({
...opts,
ipfsOptions: {
EXPERIMENTAL: {
// enable sharding for js
sharding: true
},
config: {
// enabled sharding for go
Experimental: {
ShardingEnabled: true
}
}
}
})
expect(node).to.exist()
expect(node.api).to.exist()
expect(node.api.id).to.exist()

const res = await last(node.api.addAll([{ path: 'derp.txt', content: 'hello' }], {
shardSplitThreshold: 0,
wrapWithDirectory: true
}))

if (!res) {
throw new Error('No result from ipfs.addAll')
}

const { cid } = res

const { value: dagNode } = await node.api.dag.get(cid)
const entry = UnixFS.unmarshal(dagNode.Data)

expect(entry.type).to.equal('hamt-sharded-directory')

await node.stop()
})
}
})
})

0 comments on commit 2501f19

Please sign in to comment.