Skip to content

Commit

Permalink
chore: make IPFS API static (remove api-manager) (#3365)
Browse files Browse the repository at this point in the history
- api-manager is gone.
- There is now Storage component that is glorified `{keychain, repo, peerId}` tuple, that one can `async start` and it takes care of repo bootstrapping (which `init` used to do). As per discussion with @achingbrain `init` was mostly there for historical reasons.
- There is now `Network` service component that is glorified `{peerId, libp2p, bitswap}` tuple.
   - All components that depended upon `libp2p` or `peerId` depend on `network` service now.
   - They can do `await network.use(options)` and get tuple when node is started (if it is starting or started) or an exception if start has not been initiated.
   - This way IPFS node is no longer mutated and APIs that depend on node been started throw if called before start.
- lot of TS typings were added to be able to make this changes with more confidence.
- Set of interfaces were added for things like datastore, repo, bitswap
   - create can be passed implementations and it's useful to decouple interface from a concrete implementation.
   - We had no types for those and it helped having interfaces to increase coverage and enable making these changes.
      > I would like to migrate those to other repos, but doing it as would be more effective than having to coordinate changes across many repos.
- circular dependencies between pinmanager and dag APIs are resolved.

Co-authored-by: Alex Potsides <alex@achingbrain.net>
Co-authored-by: Hugo Dias <hugomrdias@gmail.com>
  • Loading branch information
3 people authored Dec 4, 2020
1 parent 61e8297 commit abb64f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"aegir": "^29.2.2",
"go-ipfs": "^0.7.0",
"ipfs-core": "^0.3.0",
"ipfsd-ctl": "^7.0.2",
"ipfsd-ctl": "^7.1.1",
"it-all": "^1.0.4",
"it-concat": "^1.0.1",
"nock": "^13.0.2",
Expand Down
4 changes: 3 additions & 1 deletion src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = configure(api => {
mhlen: length,
version: data.cid.version
}
// @ts-ignore - data is typed as block so TS complains about
// Uint8Array assignment.
data = data.data
} else if (options.cid) {
const cid = new CID(options.cid)
Expand Down Expand Up @@ -64,7 +66,7 @@ module.exports = configure(api => {
throw err
}

return new Block(data, new CID(res.Key))
return new Block(/** @type {Uint8Array} */(data), new CID(res.Key))
}

return put
Expand Down
7 changes: 5 additions & 2 deletions src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,24 @@ module.exports = configure((api, opts) => {
throw new Error('Failed to put DAG node. Provide `format` AND `hashAlg` options')
}

let encodingOptions
if (options.cid) {
const cid = new CID(options.cid)
options = {
encodingOptions = {
...options,
format: multicodec.getName(cid.code),
hashAlg: multihash.decode(cid.multihash).name
}
delete options.cid
} else {
encodingOptions = options
}

const settings = {
format: 'dag-cbor',
hashAlg: 'sha2-256',
inputEnc: 'raw',
...options
...encodingOptions
}

const format = await load(settings.format)
Expand Down

0 comments on commit abb64f3

Please sign in to comment.