-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat!: use Helia's blockBroker interface #406
Conversation
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.
wow 🤩
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.
self review and explainers
const { doInitHelia } = props | ||
useEffect(() => { | ||
props.doInitHelia() | ||
}, [props]) | ||
doInitHelia() | ||
}, [doInitHelia]) |
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.
this fixes an issue where doInitHelia was being called on every page load.
/** | ||
* replace bigint or other non-JSON-serializable values with appropriate values for the react-inspector | ||
* Note that data for some blocks (e.g. bafyreicnokmhmrnlp2wjhyk2haep4tqxiptwfrp2rrs7rzq7uk766chqvq) currently do not | ||
* look like NormalizedDagNode['data'] | ||
* | ||
* @param {import('../../types').NormalizedDagNode['data']} data | ||
*/ | ||
const getObjectInspectorData = (data) => { | ||
if (data == null) return data | ||
if (data.blockSizes != null) { | ||
data.blockSizes = data.blockSizes.map(Number) | ||
} | ||
return data | ||
} |
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.
needed since the unixfs update uses bigint now.
/** | ||
* @param {object} props | ||
* @param {import('react-i18next').TFunction} props.t | ||
* @param {boolean} props.tReady | ||
* @param {string} props.className | ||
* @param {string} props.type | ||
* @param {string} props.cid | ||
* @param {string} props.localPath | ||
* @param {bigint} props.size | ||
* @param {import('../../types').NormalizedDagNode['data']} props.data | ||
* @param {object[]} props.links | ||
* @param {string} props.format | ||
* @param {Function} props.onLinkClick | ||
* @param {string} props.gatewayUrl | ||
* @param {string} props.publicGatewayUrl | ||
*/ | ||
const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => { |
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.
some types
const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, links, format, onLinkClick, gatewayUrl, publicGatewayUrl, ...props }) => { | ||
if (!tReady) return null |
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.
this is always true in testing, but may not always be in prod.
@@ -130,7 +162,7 @@ const ObjectInfo = ({ t, tReady, className, type, cid, localPath, size, data, li | |||
<div className='dt dt--fixed pt2'> | |||
{/* eslint-disable-next-line jsx-a11y/label-has-associated-control */} | |||
<label className='dtc silver tracked ttu f7' style={{ width: 48 }}>Size</label> | |||
<div className='dtc truncate charcoal monospace'>{humansize(size)}</div> | |||
<div className='dtc truncate charcoal monospace'>{humansize(Number(size))}</div> |
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.
bigint conversion
interface CodecWrapper<DecodedType = any> { | ||
decode: (bytes: Uint8Array) => DecodedType | ||
resolve: (path: string, bytes: Uint8Array) => Promise<ResolveType<DecodedType>> | ||
decode(bytes: Uint8Array): DecodedType | ||
resolve(path: string, bytes: Uint8Array): Promise<ResolveType<DecodedType>> | ||
} |
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.
eslint-config-ipfs auto lint updates
const timeoutId = setTimeout(() => { abortController.abort('Request timed out') }, timeout) | ||
const rawBlock = await Promise.any([kuboClient.block.get(cid), getBlockFromAnyGateway(cid, abortController.signal), helia.blockstore.get(cid, { signal: abortController.signal })]) | ||
abortController.abort('Content obtained') // abort any other requests. | ||
const rawBlock = await helia.blockstore.get(cid, { signal: abortController.signal }) |
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.
this is so much nicer =D
@@ -11,7 +11,7 @@ export interface DigestFn { | |||
(data: Uint8Array): Promise<MultihashDigest<number>> | |||
} | |||
|
|||
export async function addDagNodeToHelia <T> (helia: Helia, codec: { encode: (n: T) => Uint8Array, code: number }, node: T, digestFn?: DigestFn): Promise<CID> { | |||
export async function addDagNodeToHelia <T> (helia: Helia, codec: { encode(n: T): Uint8Array, code: number }, node: T, digestFn?: DigestFn): Promise<CID> { |
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.
eslint-config-ipfs auto lint updates
@@ -52,11 +51,18 @@ export default async function initHelia (kuboClient: ReturnType<typeof createKub | |||
], | |||
services: { | |||
identify: identifyService(), | |||
autoNAT: autoNATService() | |||
autoNAT: autoNATService(), | |||
delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev') |
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.
we use delegated routingv1httpApi instead of local kubo
export default defineConfig((configEnv) => mergeConfig( | ||
viteConfig(configEnv), | ||
defineConfig({ | ||
test: { | ||
globals: true, | ||
environment: 'jsdom', | ||
setupFiles: './test/unit/setup.js', | ||
include: [ | ||
'src/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}' | ||
], | ||
deps: { | ||
inline: [ | ||
'ipld-explorer-components' | ||
] | ||
} | ||
} | ||
} | ||
})) | ||
}) | ||
)) |
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.
clearing out package-lock.json and refreshing it caused an error here.. vitest must've updated their api (they're still pre v1)
## [5.0.0](v4.0.3...v5.0.0) (2023-11-30) ### ⚠ BREAKING CHANGES * update of many ipfs/ipld/libp2p/helia deps that may break consumers. API of ipld-explorer-components has not changed. ### Features * use Helia's blockBroker interface ([#406](#406)) ([c964a76](c964a76)) * use ipfs-css colors and add dag-jose example ([#408](#408)) ([4e96491](4e96491)) ### Trivial Changes * bump protobufjs from 6.11.3 to 6.11.4 ([#393](#393)) ([f8db274](f8db274)) * **ci:** remove circleci config ([#388](#388)) ([13698af](13698af)) * pull new translations ([#390](#390)) ([2caac4a](2caac4a)) * pull new translations ([#396](#396)) ([73799f8](73799f8)) * pull new translations ([#405](#405)) ([5805bd8](5805bd8))
ncu '/ipfs|libp2p|ipld|multi/'
blockBroker
interface for block retrievalUse kubo-rpc-client as a blockBrokerThese updates also put a big dent in dependencies holding back ipfs-webui ipfs/ipfs-webui#1965