-
Notifications
You must be signed in to change notification settings - Fork 1.2k
feat: support identity hash in block.get + dag.get #3616
Changes from 4 commits
4705cb0
e2da92a
db4d9d1
1a96c39
4376618
94df79c
178318c
7bdf168
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ const BLOCK_RM_CONCURRENCY = 256 | |
* @typedef {import('ipfs-core-types/src/refs').API} RefsAPI | ||
* @typedef {import('ipfs-repo')} IPFSRepo | ||
* @typedef {import('interface-datastore').Key} Key | ||
* @typedef {import('ipfs-repo/src/types').Block} Block | ||
*/ | ||
|
||
/** | ||
|
@@ -101,7 +102,7 @@ async function createMarkedSet ({ pin, refs, repo }) { | |
* @param {object} arg | ||
* @param {IPFSRepo} arg.repo | ||
* @param {Set<string>} markedSet | ||
* @param {AsyncIterable<CID>} blockKeys | ||
* @param {AsyncIterable<CID|Block>} blockKeys | ||
*/ | ||
async function * deleteUnmarkedBlocks ({ repo }, markedSet, blockKeys) { | ||
// Iterate through all blocks and find those that are not in the marked set | ||
|
@@ -110,12 +111,16 @@ async function * deleteUnmarkedBlocks ({ repo }, markedSet, blockKeys) { | |
let removedBlocksCount = 0 | ||
|
||
/** | ||
* @param {CID} cid | ||
* @param {Block|CID} cid | ||
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. Why did this get added? Seems a bit weird to loosen the input type to accept a Block or a CID, then ignore anything that isn't a CID. 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. that is the current return type to blocks.query -- which is accurate cause that's what you get if you don't specify keys-only 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. there is a TODO in the blockstore to seperate the keys only method, probably cause that's such an arbirtrarily wide return type 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. I see - I think we can do something clever with input arguments to disambiguate the return type - it-pushable takes this approach though changing return types always seems a bit wrong to me. 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. oh right function overloading in TS -- capturing the keysOnly properly may be difficult but yes that could work! |
||
*/ | ||
const removeBlock = async (cid) => { | ||
blocksCount++ | ||
|
||
try { | ||
if (!CID.isCID(cid)) { | ||
return null | ||
} | ||
|
||
const b32 = multibase.encode('base32', cid.multihash).toString() | ||
|
||
if (markedSet.has(b32)) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this not be
import('ipld-block')
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had to make that reduced type in the interface over in
js-ipfs-repo
to resolve the other type error with BitswapThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@achingbrain I'm actually gonna need a bit of assistance from you to verify the proper solution here.
The reason this is no ipld-block is I pushed a new commit to my branch on
js-ipfs-repo
to narrow the Block used for the Blockstore interface - hannahhoward/js-ipfs-repo@dd812a6The reason I did this is cause of a type error that was happening in ipfs-core/src/components/network.js --- and here the reason is that IPFSBitswap expects a Blockstore that is defined in
ipfs-core-types
, which in turn uses a much more limited block interface.Here's where I get lost --
ipfs-core-types
is part of this repo, but looks like it was massively rewritten just recently? However,ipfs-bitswap
seems to just reference the last release, which has this limited Blockstore interface -- it appears to be gone from the source code that's in this repo.I feel like I lack the context here to understand what the proper typing solution is. What I have compiles and typechecks, but I think perhaps getting to ipld-block properly is something that should be handled by someone who knows what's going on with
ipfs-core-types
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit in flux at the moment. The initial
ipfs-core-types
was published in an earlier attempt at typing the API and contained a mishmash of shared interfaces, internal and external, as well as partial typings of other modules which should really live in those modules.ipfs-bitswap
used types from this module which on balance was a mistake as it creates a dependency loop that is hard to break.Since then the various low-level modules have had types added,
ipfs-core-types
has been rewritten to only contain the public API and all the partial typings have been removed, so internals likeipfs-bitswap
should not depend on it, instead getting types directly from the modules they use, unless they consume the public API, which they shouldn't as we're back to dependency loops again.It's possible that bitswap and the repo (which were typed early in this exercise) need a pass to remove their own partial typings of other modules and other extraneous cruft.