Skip to content

Commit abb64f3

Browse files
Gozalaachingbrainhugomrdias
authored
chore: make IPFS API static (remove api-manager) (#3365)
- 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 <[email protected]> Co-authored-by: Hugo Dias <[email protected]>
1 parent 61e8297 commit abb64f3

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080
"aegir": "^29.2.2",
8181
"go-ipfs": "^0.7.0",
8282
"ipfs-core": "^0.3.0",
83-
"ipfsd-ctl": "^7.0.2",
83+
"ipfsd-ctl": "^7.1.1",
8484
"it-all": "^1.0.4",
8585
"it-concat": "^1.0.1",
8686
"nock": "^13.0.2",

src/block/put.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ module.exports = configure(api => {
2323
mhlen: length,
2424
version: data.cid.version
2525
}
26+
// @ts-ignore - data is typed as block so TS complains about
27+
// Uint8Array assignment.
2628
data = data.data
2729
} else if (options.cid) {
2830
const cid = new CID(options.cid)
@@ -64,7 +66,7 @@ module.exports = configure(api => {
6466
throw err
6567
}
6668

67-
return new Block(data, new CID(res.Key))
69+
return new Block(/** @type {Uint8Array} */(data), new CID(res.Key))
6870
}
6971

7072
return put

src/dag/put.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,21 +23,24 @@ module.exports = configure((api, opts) => {
2323
throw new Error('Failed to put DAG node. Provide `format` AND `hashAlg` options')
2424
}
2525

26+
let encodingOptions
2627
if (options.cid) {
2728
const cid = new CID(options.cid)
28-
options = {
29+
encodingOptions = {
2930
...options,
3031
format: multicodec.getName(cid.code),
3132
hashAlg: multihash.decode(cid.multihash).name
3233
}
3334
delete options.cid
35+
} else {
36+
encodingOptions = options
3437
}
3538

3639
const settings = {
3740
format: 'dag-cbor',
3841
hashAlg: 'sha2-256',
3942
inputEnc: 'raw',
40-
...options
43+
...encodingOptions
4144
}
4245

4346
const format = await load(settings.format)

0 commit comments

Comments
 (0)