Skip to content
This repository has been archived by the owner on Mar 10, 2020. It is now read-only.

refactor: convert bootstrap API to async/await #1154

Merged
merged 2 commits into from
Nov 14, 2019

Conversation

alanshaw
Copy link
Contributor

No description provided.

@alanshaw alanshaw force-pushed the refactor/bootstrap-async-await branch from e26688b to ea05976 Compare November 12, 2019 20:22
@alanshaw
Copy link
Contributor Author

ping @hugomrdias @achingbrain 🙏

opts = {}
module.exports = configure(({ ky }) => {
return async (addr, options) => {
if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we trying to support an options object as the first argument? If so, is this necessary? The spec says addr is not optional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's what the current code does. So you can pass add(null, { default: true }) or add({ default: true }) to add the default bootstrappers. Same sort of situation for rm (with all option).

So addr is required unless you're passing the default option.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should leave it like this in this PR.

But i agree with alex and we should make an issue to improve this in the future cause from https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/BOOTSTRAP.md#ipfsbootstrapaddaddr-options i would understand i could do add({ default: true }) maybe we can simplify to:
if first param is undefined use defaults.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes, quite right. Sigh.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But i agree with alex and we should make an issue to improve this in the future

❤️ me too. I'm just trying to get everything switched to async/await first and then take a second pass at API changes.

src/bootstrap/rm.js Show resolved Hide resolved
if (addr) searchParams.set('arg', `${addr}`)
if (options.all != null) searchParams.set('all', options.all)

const res = await ky.post('bootstrap/rm', {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the commit history, what happened with DELETE here? Our HTTP API is all POST, all the time so this is fine like this, but that aside I thought DELETE was ok to use in browsers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I couldn't be bothered to dig in at the time but thinking about it now it's because browsers are respecting CORS and our default ipfsd-ctl config does not include DELETE https://github.com/ipfs/js-ipfsd-ctl/blob/7928c1eee092a9b96a59328294c84c9f065217a3/src/defaults/config.json#L5-L9

Copy link
Contributor

@hugomrdias hugomrdias Nov 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to add DELETE to ctl? ?
In this case i would use POST cause its more RPC than REST
i would only use DELETE if the url was https://host/bootstrap/{addr}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not suggesting changing this to DELETE, I just wanted to know what happened 😉

if (addr) searchParams.set('arg', `${addr}`)
if (options.all != null) searchParams.set('all', options.all)

const res = await ky.post('bootstrap/rm', {
Copy link
Contributor

@hugomrdias hugomrdias Nov 14, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you want me to add DELETE to ctl? ?
In this case i would use POST cause its more RPC than REST
i would only use DELETE if the url was https://host/bootstrap/{addr}

opts = {}
module.exports = configure(({ ky }) => {
return async (addr, options) => {
if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO we should leave it like this in this PR.

But i agree with alex and we should make an issue to improve this in the future cause from https://github.com/ipfs/interface-js-ipfs-core/blob/master/SPEC/BOOTSTRAP.md#ipfsbootstrapaddaddr-options i would understand i could do add({ default: true }) maybe we can simplify to:
if first param is undefined use defaults.

@alanshaw alanshaw merged commit 14c5b9e into master Nov 14, 2019
@alanshaw alanshaw deleted the refactor/bootstrap-async-await branch November 14, 2019 13:24
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants