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

feat: remove ky from http-client and utils #2810

Merged
merged 12 commits into from
Mar 11, 2020
Merged

feat: remove ky from http-client and utils #2810

merged 12 commits into from
Mar 11, 2020

Conversation

hugomrdias
Copy link
Member

@hugomrdias hugomrdias commented Mar 3, 2020

This PR removes ky and simplifies a couples things searchParams handling, baseUrl normalization and native fetch options usage.

Native fetch options can be passed into the contructor or methods and are merged properly, methods now use the third argument to receive these options.

left some comments in the code to explain some of the ideas, please review so i can continue refactoring if approved.

No support for retries or hooks will implement as needed.

closes #2801

related
https://github.com/ipfs/interface-js-ipfs-core/issues/58

@hugomrdias hugomrdias added the pkg:http-client Issues related only to ipfs-http-client label Mar 3, 2020
@hugomrdias hugomrdias self-assigned this Mar 3, 2020
@achingbrain
Copy link
Member

Looks good so far 👍

Comment on lines -17 to -34
if (options.chunker) searchParams.set('chunker', options.chunker)
if (options.cidVersion) searchParams.set('cid-version', options.cidVersion)
if (options.cidBase) searchParams.set('cid-base', options.cidBase)
if (options.enableShardingExperiment != null) searchParams.set('enable-sharding-experiment', options.enableShardingExperiment)
if (options.hashAlg) searchParams.set('hash', options.hashAlg)
if (options.onlyHash != null) searchParams.set('only-hash', options.onlyHash)
if (options.pin != null) searchParams.set('pin', options.pin)
if (options.progress) searchParams.set('progress', true)
if (options.quiet != null) searchParams.set('quiet', options.quiet)
if (options.quieter != null) searchParams.set('quieter', options.quieter)
if (options.rawLeaves != null) searchParams.set('raw-leaves', options.rawLeaves)
if (options.shardSplitThreshold) searchParams.set('shard-split-threshold', options.shardSplitThreshold)
if (options.silent) searchParams.set('silent', options.silent)
if (options.trickle != null) searchParams.set('trickle', options.trickle)
if (options.wrapWithDirectory != null) searchParams.set('wrap-with-directory', options.wrapWithDirectory)
if (options.preload != null) searchParams.set('preload', options.preload)
if (options.fileImportConcurrency != null) searchParams.set('file-import-concurrency', options.fileImportConcurrency)
if (options.blockWriteConcurrency != null) searchParams.set('block-write-concurrency', options.blockWriteConcurrency)
Copy link
Contributor

Choose a reason for hiding this comment

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

It's nice that this is much DRYer now

Copy link
Contributor

Choose a reason for hiding this comment

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

We can resolve this comment thread

@pcowgill
Copy link
Contributor

pcowgill commented Mar 9, 2020

@hugomrdias What work remains before this PR will leave the draft stage? Thanks!

headers: config.headers,
base: normalizeURL(config).toString(),
handleError: errorHandler,
// apply two mutations camelCase to kebad-case and remove undefined/null key/value pairs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// apply two mutations camelCase to kebad-case and remove undefined/null key/value pairs
// apply two mutations camelCase to kebab-case and remove undefined/null key/value pairs

throw error
}

var KEBAB_REGEX = /[A-Z\u00C0-\u00D6\u00D8-\u00DE]/g
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be helpful to insert a comment above this line explaining in plain text what this regex is intended to catch beyond A-Z

Copy link
Contributor

Choose a reason for hiding this comment

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

@hugomrdias Curious for your thoughts on this when you get a chance. Thanks!

url.port = config.port || location.port
} else {
url.host = config.host || 'localhost'
url.port = config.port || '5001'
Copy link
Contributor

Choose a reason for hiding this comment

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

Defaults to go-ipfs rather than js-ipfs (5002)?

@pcowgill
Copy link
Contributor

pcowgill commented Mar 9, 2020

Once dag.put is refactored to use the new api.post function I can check whether #2825 is still an issue in this feature branch.

Copy link
Member

@achingbrain achingbrain left a comment

Choose a reason for hiding this comment

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

This is a monster. Let's get it in and address any problems with follow up PRs.

packages/ipfs-http-client/src/add/index.js Show resolved Hide resolved
@hugomrdias hugomrdias marked this pull request as ready for review March 11, 2020 19:11
headers: opts.headers,
base: normalizeInput(opts.url).toString(),
handleError: errorHandler,
// apply two mutations camelCase to kebad-case and remove undefined/null key/value pairs
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// apply two mutations camelCase to kebad-case and remove undefined/null key/value pairs
// apply two mutations camelCase to kebab-case and remove undefined/null key/value pairs

@hugomrdias hugomrdias changed the title remove ky from http-client feat: remove ky from http-client and utils Mar 11, 2020
@hugomrdias hugomrdias merged commit 9bc9625 into master Mar 11, 2020
@hugomrdias hugomrdias deleted the feat/remove-ky branch March 11, 2020 19:47
@achingbrain
Copy link
Member

Let's get it in and address any problems with follow up PRs.

I didn't mean merge while CI was red 🤣

@hugomrdias
Copy link
Member Author

fixing it, for some reason i just so green 🤣

mistakia pushed a commit to mistakia/js-ipfs that referenced this pull request Mar 22, 2020
- we now use a simpler http lib 
- bundle size reduced
- some tests are now more stable
- search params handling is cleaner 

closes ipfs#2801
SgtPooki referenced this pull request in ipfs/js-kubo-rpc-client Aug 18, 2022
- we now use a simpler http lib 
- bundle size reduced
- some tests are now more stable
- search params handling is cleaner 

closes #2801
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
pkg:http-client Issues related only to ipfs-http-client
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tracking issue for ky removal
3 participants