Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
chore: split gateway out into own package
Browse files Browse the repository at this point in the history
  • Loading branch information
achingbrain committed Sep 17, 2020
1 parent dc9d91e commit 692b1bf
Show file tree
Hide file tree
Showing 69 changed files with 318 additions and 631 deletions.
2 changes: 1 addition & 1 deletion examples/browser-exchange-files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"ipfs": "^0.50.1",
"it-all": "^1.0.2",
"it-all": "^1.0.4",
"test-ipfs-example": "^2.0.3"
},
"browser": {
Expand Down
2 changes: 1 addition & 1 deletion examples/browser-ipns-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
"ipfs-http-client": "^47.0.0",
"ipfs-utils": "^3.0.0",
"ipns": "^0.8.0",
"it-last": "^1.0.2",
"it-last": "^1.0.4",
"p-retry": "^4.2.0",
"uint8arrays": "^1.1.0"
},
Expand Down
2 changes: 1 addition & 1 deletion examples/custom-ipfs-repo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"datastore-fs": "^2.0.0",
"ipfs": "^0.50.1",
"ipfs-repo": "^6.0.3",
"it-all": "^1.0.2"
"it-all": "^1.0.4"
},
"devDependencies": {
"execa": "^4.0.0",
Expand Down
2 changes: 1 addition & 1 deletion examples/ipfs-101/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
"license": "MIT",
"dependencies": {
"ipfs": "^0.50.1",
"it-all": "^1.0.2",
"it-all": "^1.0.4",
"uint8arrays": "^1.1.0"
},
"devDependencies": {
Expand Down
12 changes: 8 additions & 4 deletions packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,28 @@
"cids": "^1.0.0",
"delay": "^4.4.0",
"dirty-chai": "^2.0.1",
"err-code": "^2.0.3",
"ipfs-unixfs": "^2.0.3",
"ipfs-unixfs-importer": "^3.0.4",
"ipfs-utils": "^3.0.0",
"ipld-block": "^0.10.1",
"ipld-dag-cbor": "^0.17.0",
"ipld-dag-pb": "^0.20.0",
"ipns": "^0.8.0",
"is-ipfs": "^2.0.0",
"iso-random-stream": "^1.1.1",
"it-all": "^1.0.2",
"it-drain": "^1.0.1",
"it-last": "^1.0.2",
"it-map": "^1.0.2",
"it-all": "^1.0.4",
"it-concat": "^1.0.1",
"it-drain": "^1.0.3",
"it-last": "^1.0.4",
"it-map": "^1.0.4",
"it-pushable": "^1.3.1",
"libp2p-crypto": "^0.18.0",
"multiaddr": "^8.0.0",
"multibase": "^3.0.0",
"multihashing-async": "^2.0.1",
"nanoid": "^3.1.12",
"p-map": "^4.0.0",
"peer-id": "^0.14.1",
"readable-stream": "^3.4.0",
"temp-write": "^4.0.0",
Expand Down
18 changes: 12 additions & 6 deletions packages/interface-ipfs-core/src/add.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const testTimeout = require('./utils/test-timeout')
const echoUrl = (text) => `${process.env.ECHO_SERVER}/download?data=${encodeURIComponent(text)}`
const redirectUrl = (url) => `${process.env.ECHO_SERVER}/redirect?to=${encodeURI(url)}`
const uint8ArrayFromString = require('uint8arrays/from-string')
const { nanoid } = require('nanoid')
const last = require('it-last')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
Expand Down Expand Up @@ -365,10 +364,6 @@ module.exports = (common, options) => {
expect(file.size).to.equal(18)
})

it('should not error when passed null options', async () => {
await ipfs.add(uint8ArrayFromString(nanoid()), null)
})

it('should add a file with a v1 CID', async () => {
const file = await ipfs.add(Uint8Array.from([0, 1, 2]), {
cidVersion: 1
Expand Down Expand Up @@ -405,7 +400,18 @@ module.exports = (common, options) => {

before(async function () {
const ipfsd = await common.spawn({
ipfsOptions: { EXPERIMENTAL: { sharding: false } }
ipfsOptions: {
EXPERIMENTAL: {
// enable sharding for js
sharding: true
},
config: {
// enabled sharding for go
Experimental: {
ShardingEnabled: true
}
}
}
})
ipfs = ipfsd.api
})
Expand Down
15 changes: 7 additions & 8 deletions packages/interface-ipfs-core/src/bitswap/unwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@ module.exports = (factory, options) => {
describe('.bitswap.unwant', function () {
this.timeout(60 * 1000)

let ipfs

before(async () => {
ipfs = (await factory.spawn()).api
})

after(() => factory.clean())

it('should throw error for invalid CID input', async () => {
const ipfs = (await factory.spawn()).api

try {
await ipfs.bitswap.unwant('INVALID CID')
} catch (err) {
expect(err).to.exist()
expect(err.code).to.equal('ERR_INVALID_CID')
}
await expect(ipfs.bitswap.unwant('INVALID CID')).to.eventually.be.rejected()
})
})
}
5 changes: 0 additions & 5 deletions packages/interface-ipfs-core/src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const CID = require('cids')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const testTimeout = require('../utils/test-timeout')
const all = require('it-all')
const { nanoid } = require('nanoid')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -99,9 +98,5 @@ module.exports = (common, options) => {
return expect(ipfs.block.put([blob, blob])).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})

it('should not error when passed null options', () => {
return ipfs.block.put(uint8ArrayFromString(nanoid()), null)
})
})
}
1 change: 0 additions & 1 deletion packages/interface-ipfs-core/src/block/rm.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ module.exports = (common, options) => {
it('should throw error for invalid CID input', () => {
return expect(all(ipfs.block.rm('INVALID CID')))
.to.eventually.be.rejected()
.and.to.have.a.property('code').that.equals('ERR_INVALID_CID')
})
})
}
6 changes: 0 additions & 6 deletions packages/interface-ipfs-core/src/block/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
const CID = require('cids')
const { getDescribe, getIt, expect } = require('../utils/mocha')
const testTimeout = require('../utils/test-timeout')
const { nanoid } = require('nanoid')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -50,10 +49,5 @@ module.exports = (common, options) => {
return expect(ipfs.block.stat('invalid')).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})

it('should not error when passed null options', async () => {
const block = await ipfs.block.put(uint8ArrayFromString(nanoid()))
return ipfs.block.stat(block.cid, null)
})
})
}
21 changes: 1 addition & 20 deletions packages/interface-ipfs-core/src/bootstrap/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@

const { getDescribe, getIt, expect } = require('../utils/mocha')
const testTimeout = require('../utils/test-timeout')
const multiaddr = require('multiaddr')
const { isBrowser, isWebWorker } = require('ipfs-utils/src/env')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -34,24 +32,7 @@ module.exports = (common, options) => {
const res = await ipfs.bootstrap.list()

const peers = res.Peers
expect(peers).to.exist()
})

it('bootstrap list should contain dialable nodes', async () => {
const list = await ipfs.bootstrap.list()
const onlyWss = list.some(addr => {
const ma = multiaddr(addr)

return ma.protos().some(proto => proto.name === 'wss')
})

expect(list).to.not.be.empty()

if (isBrowser || isWebWorker) {
expect(onlyWss).to.be.true()
} else {
expect(onlyWss).to.be.false()
}
expect(peers).to.be.an('Array')
})
})
}
1 change: 0 additions & 1 deletion packages/interface-ipfs-core/src/dag/tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ module.exports = (common, options) => {
it('should throw error for invalid CID input', () => {
return expect(all(ipfs.dag.tree('INVALID CID')))
.to.eventually.be.rejected()
.and.to.have.property('code').that.equals('ERR_INVALID_CID')
})
})
}
11 changes: 6 additions & 5 deletions packages/interface-ipfs-core/src/dht/disabled.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
'use strict'

const { getDescribe, getIt, expect } = require('../utils/mocha')
const uint8ArrayFromString = require('uint8arrays/from-string')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand All @@ -16,10 +15,11 @@ module.exports = (factory, options) => {
describe('disabled', function () {
this.timeout(80 * 1000)

let ipfs
let nodeA
let nodeB

before(async () => {
ipfs = (await factory.spawn({
nodeA = (await factory.spawn({
ipfsOptions: {
config: {
Routing: {
Expand All @@ -28,14 +28,15 @@ module.exports = (factory, options) => {
}
}
})).api
nodeB = (await factory.spawn()).api
await nodeA.swarm.connect(nodeB.peerId.addresses[0])
})

after(() => factory.clean())

it('should error when DHT not available', async () => {
await expect(ipfs.dht.put(uint8ArrayFromString('a'), uint8ArrayFromString('b')))
await expect(nodeA.dht.get('/ipns/Qme6KJdKcp85TYbLxuLV7oQzMiLremD7HMoXLZEmgo6Rnh'))
.to.eventually.be.rejected()
.and.to.have.property('code', 'ERR_NOT_ENABLED')
})
})
}
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/src/name-pubsub/pubsub.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { isNode } = require('ipfs-utils/src/env')
const ipns = require('ipns')
const delay = require('delay')
const last = require('it-last')
const waitFor = require('./utils/wait-for')
const waitFor = require('../utils/wait-for')
const uint8ArrayToString = require('uint8arrays/to-string')
const uint8ArrayFromString = require('uint8arrays/from-string')

Expand Down
5 changes: 0 additions & 5 deletions packages/interface-ipfs-core/src/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,5 @@ module.exports = (common, options) => {
it('returns error for request with invalid argument', () => {
return expect(ipfs.object.get('invalid', { enc: 'base58' })).to.eventually.be.rejected.and.be.an.instanceOf(Error)
})

it('should not error when passed null options', async () => {
const cid = await ipfs.object.put(uint8ArrayFromString(nanoid()))
await ipfs.object.get(cid)
})
})
}
15 changes: 0 additions & 15 deletions packages/interface-ipfs-core/src/object/patch/add-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ const { getDescribe, getIt, expect } = require('../../utils/mocha')
const { asDAGLink } = require('../utils')
const CID = require('cids')
const testTimeout = require('../../utils/test-timeout')
const { nanoid } = require('nanoid')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -88,19 +87,5 @@ module.exports = (common, options) => {
it('returns error for request with only one invalid argument', () => {
return expect(ipfs.object.patch.addLink('invalid', null, null)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
})

it('should not error when passed null options', async () => {
const aCid = await ipfs.object.put(uint8ArrayFromString(nanoid()))
const bCid = await ipfs.object.put(uint8ArrayFromString(nanoid()))
const bNode = await ipfs.object.get(bCid)

const link = {
name: 'link-name',
cid: bCid,
size: bNode.size
}

await ipfs.object.patch.addLink(aCid, link, null)
})
})
}
6 changes: 0 additions & 6 deletions packages/interface-ipfs-core/src/object/patch/append-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
const { getDescribe, getIt, expect } = require('../../utils/mocha')
const testTimeout = require('../../utils/test-timeout')
const CID = require('cids')
const { nanoid } = require('nanoid')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -53,10 +52,5 @@ module.exports = (common, options) => {

return expect(ipfs.object.patch.appendData(null, filePath)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
})

it('should not error when passed null options', async () => {
const cid = await ipfs.object.put(uint8ArrayFromString(nanoid()), null)
await ipfs.object.patch.appendData(cid, uint8ArrayFromString(nanoid()), null)
})
})
}
16 changes: 0 additions & 16 deletions packages/interface-ipfs-core/src/object/patch/rm-link.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { getDescribe, getIt, expect } = require('../../utils/mocha')
const { asDAGLink } = require('../utils')
const testTimeout = require('../../utils/test-timeout')
const CID = require('cids')
const { nanoid } = require('nanoid')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -78,20 +77,5 @@ module.exports = (common, options) => {
return expect(ipfs.object.patch.rmLink(root, link)).to.eventually.be.rejected
.and.be.an.instanceOf(Error)
})

it('should not error when passed null options', async () => {
const aCid = await ipfs.object.put(uint8ArrayFromString(nanoid()))
const bCid = await ipfs.object.put(uint8ArrayFromString(nanoid()))
const bNode = await ipfs.object.get(bCid)

const cCid = await ipfs.object.patch.addLink(aCid, {
Name: 'nodeBLink',
Hash: bCid,
Tsize: bNode.size
})
const cNode = await ipfs.object.get(cCid)

await ipfs.object.patch.rmLink(cCid, cNode.Links[0], null)
})
})
}
6 changes: 0 additions & 6 deletions packages/interface-ipfs-core/src/object/patch/set-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
const { getDescribe, getIt, expect } = require('../../utils/mocha')
const testTimeout = require('../../utils/test-timeout')
const CID = require('cids')
const { nanoid } = require('nanoid')

/** @typedef { import("ipfsd-ctl/src/factory") } Factory */
/**
Expand Down Expand Up @@ -57,10 +56,5 @@ module.exports = (common, options) => {

return expect(ipfs.object.patch.setData(null, filePath)).to.eventually.be.rejected.and.be.an.instanceOf(Error)
})

it('should not error when passed null options', async () => {
const cid = await ipfs.object.put(uint8ArrayFromString(nanoid()), null)
await ipfs.object.patch.setData(cid, uint8ArrayFromString(nanoid()), null)
})
})
}
4 changes: 0 additions & 4 deletions packages/interface-ipfs-core/src/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,5 @@ module.exports = (common, options) => {
expect(node1b.Data).to.deep.equal(node.Data)
expect(node1b.Links).to.deep.equal(node.Links)
})

it('should not error when passed null options', () => {
return ipfs.object.put(uint8ArrayFromString(nanoid()), null)
})
})
}
6 changes: 1 addition & 5 deletions packages/interface-ipfs-core/src/stats/bw.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ module.exports = (common, options) => {
it('should throw error for invalid interval option', async () => {
await expect(all(ipfs.stats.bw({ poll: true, interval: 'INVALID INTERVAL' })))
.to.eventually.be.rejected()
.and.to.have.property('code').that.equals('ERR_INVALID_POLL_INTERVAL')
})

it('should not error when passed null options', async () => {
await all(ipfs.stats.bw(null))
.with.property('message').that.matches(/invalid duration/)
})
})
}
Loading

0 comments on commit 692b1bf

Please sign in to comment.