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

refactor: convert object API to async/await #2666

Merged
merged 2 commits into from
Dec 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/core/components/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ exports.bitswap = {
exports.config = require('./config')
exports.id = require('./id')
exports.init = require('./init')
exports.object = {
data: require('./object/data'),
get: require('./object/get'),
links: require('./object/links'),
new: require('./object/new'),
patch: {
addLink: require('./object/patch/add-link'),
appendData: require('./object/patch/append-data'),
rmLink: require('./object/patch/rm-link'),
setData: require('./object/patch/set-data')
},
put: require('./object/put'),
stat: require('./object/stat')
}
exports.ping = require('./ping')
exports.start = require('./start')
exports.stop = require('./stop')
Expand All @@ -17,6 +31,5 @@ exports.version = require('./version')
exports.legacy = { // TODO: these will be removed as the new API is completed
dag: require('./dag'),
libp2p: require('./libp2p'),
object: require('./object'),
pin: require('./pin')
}
18 changes: 17 additions & 1 deletion src/core/components/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,20 @@ module.exports = ({
})

const dag = Commands.legacy.dag({ _ipld: ipld, _preload: preload })
const object = Commands.legacy.object({ _ipld: ipld, _preload: preload, dag, _gcLock: gcLock })
const object = {
data: Commands.object.data({ ipld, preload }),
get: Commands.object.get({ ipld, preload }),
links: Commands.object.links({ dag }),
new: Commands.object.new({ ipld, preload }),
patch: {
addLink: Commands.object.patch.addLink({ ipld, gcLock, preload }),
appendData: Commands.object.patch.appendData({ ipld, gcLock, preload }),
rmLink: Commands.object.patch.rmLink({ ipld, gcLock, preload }),
setData: Commands.object.patch.setData({ ipld, gcLock, preload })
},
put: Commands.object.put({ ipld, gcLock, preload }),
stat: Commands.object.stat({ ipld, preload })
}

const pinManager = new PinManager(repo, dag)
await pinManager.load()
Expand Down Expand Up @@ -134,6 +147,7 @@ module.exports = ({
initOptions: options,
ipld,
keychain,
object,
peerInfo,
pinManager,
preload,
Expand Down Expand Up @@ -276,6 +290,7 @@ function createApi ({
initOptions,
ipld,
keychain,
object,
peerInfo,
pinManager,
preload,
Expand All @@ -302,6 +317,7 @@ function createApi ({
config: Commands.config({ repo }),
id: Commands.id({ peerInfo }),
init: () => { throw new AlreadyInitializedError() },
object,
start,
version: Commands.version({ repo })
}
Expand Down
302 changes: 0 additions & 302 deletions src/core/components/object.js

This file was deleted.

9 changes: 9 additions & 0 deletions src/core/components/object/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'use strict'

module.exports = ({ ipld, preload }) => {
const get = require('./get')({ ipld, preload })
return async function data (multihash, options) {
const node = await get(multihash, options)
return node.Data
}
}
Loading