This repository was archived by the owner on Feb 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: remove ky from http-client and utils #2810
Merged
Merged
Changes from 7 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
85b8802
fix: prototype for ky removal
hugomrdias a1a7230
fix: adjustments from feedback
hugomrdias b16c080
fix: lint and globalThis
hugomrdias 10c3734
fix: add missing dep
hugomrdias 7cfde8e
fix: add missing option and defaults
hugomrdias 185cd8e
fix: add validation
hugomrdias 6a3db3f
fix: removed ky
hugomrdias 1c619bb
fix: re-add configure
hugomrdias 44ac9e3
fix: remove ky from utils
hugomrdias ef9435d
fix: fix textdecoder in node 10 and revert http server changes
hugomrdias 9b27599
chore: a TODO
hugomrdias cc69bce
chore: bundle size and remove comments
hugomrdias File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,56 +2,45 @@ | |
|
||
const ndjson = require('iterable-ndjson') | ||
const CID = require('cids') | ||
const configure = require('../lib/configure') | ||
const toIterable = require('stream-to-it/source') | ||
const { toFormData } = require('./form-data') | ||
const toCamel = require('../lib/object-to-camel') | ||
const merge = require('merge-options') | ||
|
||
module.exports = configure(({ ky }) => { | ||
return async function * add (input, options) { | ||
options = options || {} | ||
/** @typedef { import("./../lib/api") } API */ | ||
|
||
const searchParams = new URLSearchParams(options.searchParams) | ||
|
||
searchParams.set('stream-channels', true) | ||
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) | ||
Comment on lines
-17
to
-34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's nice that this is much DRYer now There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can resolve this comment thread |
||
module.exports = (/** @type {API} */ api) => { | ||
return async function * add (input, options = {}) { | ||
// extract functions here | ||
const progressFn = options.progress | ||
// default or mutate/force options here | ||
options = merge( | ||
options, | ||
{ | ||
'stream-channels': true, | ||
progress: Boolean(progressFn), | ||
hash: options.hashAlg // TODO fix this either is hash or hashAlg | ||
} | ||
) | ||
|
||
const res = await ky.post('add', { | ||
const res = await api.post('add', { | ||
searchParams: options, | ||
body: await toFormData(input), | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams, | ||
body: await toFormData(input) | ||
signal: options.signal | ||
}) | ||
|
||
for await (let file of ndjson(toIterable(res.body))) { | ||
file = toCamel(file) | ||
|
||
if (options.progress && file.bytes) { | ||
options.progress(file.bytes) | ||
if (progressFn && file.bytes) { | ||
progressFn(file.bytes) | ||
} else { | ||
yield toCoreInterface(file) | ||
} | ||
} | ||
} | ||
}) | ||
} | ||
|
||
function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) { | ||
const output = { | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,30 @@ | ||
'use strict' | ||
|
||
const configure = require('../lib/configure') | ||
const Big = require('bignumber.js') | ||
const { BigNumber } = require('bignumber.js') | ||
const CID = require('cids') | ||
|
||
module.exports = configure(({ ky }) => { | ||
return async (options) => { | ||
options = options || {} | ||
|
||
const res = await ky.post('bitswap/stat', { | ||
module.exports = api => { | ||
return async (options = {}) => { | ||
const res = await api.post('bitswap/stat', { | ||
searchParams: options, | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams: options.searchParams | ||
}).json() | ||
signal: options.signal | ||
}) | ||
|
||
return toCoreInterface(res) | ||
return toCoreInterface(await res.json()) | ||
} | ||
}) | ||
} | ||
|
||
function toCoreInterface (res) { | ||
return { | ||
provideBufLen: res.ProvideBufLen, | ||
wantlist: (res.Wantlist || []).map(k => new CID(k['/'])), | ||
peers: (res.Peers || []), | ||
blocksReceived: new Big(res.BlocksReceived), | ||
dataReceived: new Big(res.DataReceived), | ||
blocksSent: new Big(res.BlocksSent), | ||
dataSent: new Big(res.DataSent), | ||
dupBlksReceived: new Big(res.DupBlksReceived), | ||
dupDataReceived: new Big(res.DupDataReceived) | ||
blocksReceived: new BigNumber(res.BlocksReceived), | ||
dataReceived: new BigNumber(res.DataReceived), | ||
blocksSent: new BigNumber(res.BlocksSent), | ||
dataSent: new BigNumber(res.DataSent), | ||
dupBlksReceived: new BigNumber(res.DupBlksReceived), | ||
dupDataReceived: new BigNumber(res.DupDataReceived) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,17 @@ | ||
'use strict' | ||
|
||
const CID = require('cids') | ||
const configure = require('../lib/configure') | ||
|
||
module.exports = configure(({ ky }) => { | ||
return async (cid, options) => { | ||
options = options || {} | ||
module.exports = api => { | ||
return async (cid, options = {}) => { | ||
options.arg = typeof cid === 'string' ? cid : new CID(cid).toString() | ||
|
||
const searchParams = new URLSearchParams(options.searchParams) | ||
|
||
if (typeof cid === 'string') { | ||
searchParams.set('arg', cid) | ||
} else { | ||
searchParams.set('arg', new CID(cid).toString()) | ||
} | ||
|
||
const res = await ky.post('bitswap/unwant', { | ||
const res = await api.post('bitswap/unwant', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams | ||
}).json() | ||
searchParams: options | ||
}) | ||
|
||
return res | ||
return res.json() | ||
} | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,19 @@ | ||
'use strict' | ||
|
||
const CID = require('cids') | ||
const configure = require('../lib/configure') | ||
|
||
module.exports = configure(({ ky }) => { | ||
return async (peerId, options) => { | ||
options = options || {} | ||
|
||
const searchParams = new URLSearchParams(options.searchParams) | ||
|
||
if (peerId) { | ||
if (typeof peerId === 'string') { | ||
searchParams.set('peer', peerId) | ||
} else { | ||
searchParams.set('peer', new CID(peerId).toString()) | ||
} | ||
module.exports = api => { | ||
return async (peer, options = {}) => { | ||
if (peer) { | ||
options.peer = typeof peer === 'string' ? peer : new CID(peer).toString() | ||
} | ||
|
||
const res = await ky.post('bitswap/wantlist', { | ||
const res = await (await api.post('bitswap/wantlist', { | ||
timeout: options.timeout, | ||
signal: options.signal, | ||
headers: options.headers, | ||
searchParams | ||
}).json() | ||
searchParams: options | ||
})).json() | ||
|
||
return (res.Keys || []).map(k => new CID(k['/'])) | ||
} | ||
}) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.