feat!: use Helia's blockBroker interface#406
Conversation
SgtPooki
left a comment
There was a problem hiding this comment.
self review and explainers
| const { doInitHelia } = props | ||
| useEffect(() => { | ||
| props.doInitHelia() | ||
| }, [props]) | ||
| doInitHelia() | ||
| }, [doInitHelia]) |
There was a problem hiding this comment.
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.
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 }) => { |
| * @param {string} props.publicGatewayUrl | ||
| */ | ||
| 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.
this is always true in testing, but may not always be in prod.
| {/* 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> |
| 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.
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.
this is so much nicer =D
| } | ||
|
|
||
| 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.
eslint-config-ipfs auto lint updates
| identify: identifyService(), | ||
| autoNAT: autoNATService() | ||
| autoNAT: autoNATService(), | ||
| delegatedRouting: () => createDelegatedRoutingV1HttpApiClient('https://delegated-ipfs.dev') |
There was a problem hiding this comment.
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.
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/'blockBrokerinterface 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