8000 fix: use ipfs-core-types instead of redefining ipld by achingbrain · Pull Request #121 · ipfs/js-ipfs-unixfs · GitHub
[go: up one dir, main page]

Skip to content

fix: use ipfs-core-types instead of redefining ipld #121

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

Merged
merged 2 commits into from
Feb 23, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: use ipfs-core-types instead of redefining ipld
Adds timeout and signal options to exporter
  • Loading branch information
achingbrain committed Feb 19, 2021
commit f37923e9d3abafa8d96d7767db14f251d5d98b9e
1 change: 1 addition & 0 deletions packages/ipfs-unixfs-exporter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"abort-controller": "^3.0.0",
"aegir": "^30.3.0",
"detect-node": "^2.0.4",
"ipfs-core-types": "^0.3.0",
"ipfs-unixfs-importer": "^6.0.0",
"ipld": "^0.28.0",
"ipld-dag-pb": "^0.21.0",
Expand Down
13 changes: 6 additions & 7 deletions packages/ipfs-unixfs-exporter/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const last = require('it-last')
/**
* @typedef {import('ipfs-unixfs')} UnixFS
* @typedef {import('ipld-dag-pb').DAGNode} DAGNode
* @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD
*
* @typedef {object} UnixFSFile
* @property {'file'} type
Expand Down Expand Up @@ -59,13 +60,11 @@ const last = require('it-last')
*/

/**
* @typedef {object} IPLDResolver
* @property {(cid: CID, options?: any) => Promise<any>} get
* @property {(node: any, codec: number, options?: any) => Promise<CID>} put
*
* @typedef {object} ExporterOptions
* @property {number} [offset=0]
* @property {number} [length]
* @property {AbortSignal} [signal]
* @property {number} [timeout]
*/

const toPathComponents = (path = '') => {
Expand Down Expand Up @@ -112,7 +111,7 @@ const cidAndRest = (path) => {

/**
* @param {string | CID} path
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {ExporterOptions} [options]
*/
const walkPath = async function * (path, ipld, options = {}) {
Expand Down Expand Up @@ -149,7 +148,7 @@ const walkPath = async function * (path, ipld, options = {}) {

/**
* @param {string | CID} path
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {ExporterOptions} [options]
*/
const exporter = async (path, ipld, options = {}) => {
Expand All @@ -164,7 +163,7 @@ const exporter = async (path, ipld, options = {}) => {

/**
* @param {string | CID} path
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {ExporterOptions} [options]
*/
const recursive = async function * (path, ipld, options = {}) {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-unixfs-exporter/src/resolvers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const errCode = require('err-code')

/**
* @typedef {import('../').IPLDResolver} IPLDResolver
* @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD
* @typedef {import('../').ExporterOptions} ExporterOptions
* @typedef {import('../').UnixFSEntry} UnixFSEntry
* @typedef {import('cids')} CID
Expand All @@ -23,9 +23,9 @@ const errCode = require('err-code')

/**
*
* @typedef {(cid: CID, name: string, path: string, toResolve: string[], depth: number, ipld: IPLDResolver, options: ExporterOptions) => Promise<ResolveResult>} Resolve
* @typedef {(cid: CID, name: string, path: string, toResolve: string[], depth: number, ipld: IPLD, options: ExporterOptions) => Promise<ResolveResult>} Resolve
*
* @typedef {(cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, ipld: IPLDResolver, options: ExporterOptions) => Promise<ResolveResult>} Resolver
* @typedef {(cid: CID, name: string, path: string, toResolve: string[], resolve: Resolve, depth: number, ipld: IPLD, options: ExporterOptions) => Promise<ResolveResult>} Resolver
*
* @type {{ [ key: string ]: Resolver }}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ const errCode = require(& 628C #39;err-code')

/**
* @typedef {import('../../../').ExporterOptions} ExporterOptions
* @typedef {import('../../../').IPLDResolver} IPLDResolver
* @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD
* @typedef {import('ipld-dag-pb').DAGNode} DAGNode
*
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {DAGNode} node
* @param {number} start
* @param {number} end
Expand Down Expand Up @@ -61,7 +61,10 @@ async function * emitBytes (ipld, node, start, end, streamPosition = 0, options)
if ((start >= childStart && start < childEnd) || // child has offset byte
(end > childStart && end <= childEnd) || // child has end byte
(start < childStart && end > childEnd)) { // child is between offset and end bytes
const child = await ipld.get(childLink.Hash, options)
const child = await ipld.get(childLink.Hash, {
signal: options.signal,
timeout: options.timeout
})

for await (const buf of emitBytes(ipld, child, start, end, streamPosition, options)) {
streamPosition += buf.length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @typedef {import('../../../').ExporterOptions} ExporterOptions
* @typedef {import('ipld-dag-pb').DAGNode} DAGNode
* @typedef {import('../../').Resolve} Resolve
* @typedef {import('../../../').IPLDResolver} IPLDResolver
* @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD
* @typedef {import('../').UnixfsV1DirectoryContent} UnixfsV1DirectoryContent
*
* @type {import('../').UnixfsV1Resolver}
Expand All @@ -26,7 +26,7 @@ const hamtShardedDirectoryContent = (cid, node, unixfs, path, resolve, depth, ip
* @param {string} path
* @param {Resolve} resolve
* @param {number} depth
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {ExporterOptions} options
*
* @returns {UnixfsV1DirectoryContent}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const findShardCid = require('../../utils/find-cid-in-shard')

/**
* @typedef {import('../../').ExporterOptions} ExporterOptions
* @typedef {import('../../').IPLDResolver} IPLDResolver
* @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD
* @typedef {import('../').UnixFSEntry} UnixFSEntry
* @typedef {import('cids')} CID
* @typedef {import('ipld-dag-pb').DAGNode} DAGNode
Expand All @@ -28,7 +28,7 @@ const findLinkCid = (node, name) => {
* @typedef {AsyncIterable<UnixFSEntry> | Iterable<UnixFSEntry>} UnixfsV1DirectoryContent
*
* @typedef {UnixfsV1FileContent | UnixfsV1DirectoryContent} UnixfsV1Content
* @typedef {(cid: CID, node: DAGNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, ipld: IPLDResolver) => (options: ExporterOptions) => UnixfsV1Content } UnixfsV1Resolver
* @typedef {(cid: CID, node: DAGNode, unixfs: UnixFS, path: string, resolve: Resolve, depth: number, ipld: IPLD) => (options: ExporterOptions) => UnixfsV1Content } UnixfsV1Resolver
*
* @type {{ [key: string]: UnixfsV1Resolver }}
*/
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-unixfs-exporter/src/utils/find-cid-in-shard.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const multihashing = require('multihashing-async')

/**
* @typedef {import('../').ExporterOptions} ExporterOptions
* @typedef {import('../').IPLDResolver} IPLDResolver
* @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD
* @typedef {import('cids')} CID
*/

Expand Down Expand Up @@ -90,7 +90,7 @@ const toBucketPath = (position) => {
*
* @param {import('ipld-dag-pb').DAGNode} node
* @param {string} name
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {ShardTraversalContext} [context]
* @param {ExporterOptions} [options]
* @returns {Promise<CID|null>}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const SHARD_SPLIT_THRESHOLD = 10
describe('exporter sharded', function () {
this.timeout(30000)

/** @type {import('../src').IPLDResolver} */
/** @type {import('ipfs-core-types/src/ipld').IPLD} */
let ipld
/** @type {import('ipfs-unixfs-importer').BlockAPI} */
let block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const ONE_MEG = Math.pow(1024, 2)
const exporter = require('./../src')

describe('exporter subtree', () => {
/** @type {import('../src').IPLDResolver} */
/** @type {import('ipfs-core-types/src/ipld').IPLD} */
let ipld
/** @type {import('ipfs-unixfs-importer').BlockAPI} */
let block
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-unixfs-exporter/test/exporter.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const uint8ArrayConcat = require('uint8arrays/concat')
const ONE_MEG = Math.pow(1024, 2)

describe('exporter', () => {
/** @type {import('../src').IPLDResolver} */
/** @type {import('ipfs-core-types/src/ipld').IPLD} */
let ipld
/** @type {import('ipfs-unixfs-importer').BlockAPI} */
let block
Expand Down Expand Up @@ -134,7 +134,7 @@ describe('exporter', () => {
}

/**
* @param {import('../src').IPLDResolver} ipld
* @param {import('ipfs-core-types/src/ipld').IPLD} ipld
* @param {'file' | 'directory' | 'raw'} type
* @param {Uint8Array | ArrayLike<number> | undefined} data
* @param {{ node: DAGNode, cid: CID }[]} children
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-unixfs-exporter/test/helpers/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const multicodec = require('multicodec')
const mh = require('multihashing-async').multihash

/**
* @param {import('../../src/').IPLDResolver} ipld
* @param {import('ipfs-core-types/src/ipld').IPLD} ipld
*/
function createBlockApi (ipld) {
// make ipld behave like the block api, some tests need to pull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* @param {import('cids')} cid
* @param {import('../../src').IPLDResolver} ipld
* @param {import('ipfs-core-types/src/ipld').IPLD} ipld
*/
module.exports = function (cid, ipld) {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const uint8ArrayConcat = require('uint8arrays/concat')
*/

describe('builder: directory sharding', () => {
/** @type {import('../src').IPLDResolver} */
/** @type {import('ipfs-core-types/src/ipld').IPLD} */
let ipld
/** @type {import('ipfs-unixfs-importer').BlockAPI} */
let block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const uint8ArrayConcat = require('uint8arrays/concat')

describe('import and export: directory', () => {
const rootHash = 'QmdCrquDwd7RfZ6GCZFEVADwe8uyyw1YmF9mtAB7etDgmK'
/** @type {import('../src').IPLDResolver} */
/** @type {import('ipfs-core-types/src/ipld').IPLD} */
let ipld
/** @type {import('ipfs-unixfs-importer').BlockAPI} */
let block
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-unixfs-exporter/test/import-export.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ describe('import and export', function () {
const importerOptions = { strategy: strategy }

describe('using builder: ' + strategy, () => {
/** @type {import('../src').IPLDResolver} */
/** @type {import('ipfs-core-types/src/ipld').IPLD} */
let ipld
/** @type {import('ipfs-unixfs-importer').BlockAPI} */
let block
Expand Down
10 changes: 5 additions & 5 deletions packages/ipfs-unixfs-exporter/test/importer.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const last = require('it-last')
const CID = require('cids')

/**
* @typedef {import('../src').IPLDResolver} IPLDResolver
* @typedef {import('ipfs-core-types/src/ipld').IPLD} IPLD
* @typedef {import('ipfs-unixfs-importer').BlockAPI} BlockAPI
* @typedef {import('ipld-dag-pb').DAGNode} DAGNode
*/
Expand Down Expand Up @@ -200,7 +200,7 @@ const strategyOverrides = {

/**
* @param {BlockAPI} block
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {import('ipfs-unixfs-importer').UserImporterOptions} options
* @param {*} expected
*/
Expand Down Expand Up @@ -233,7 +233,7 @@ const checkLeafNodeTypes = async (block, ipld, options, expected) => {

/**
* @param {BlockAPI} block
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
* @param {import('ipfs-unixfs-importer').UserImporterOptions} options
* @param {*} expected
*/
Expand Down Expand Up @@ -355,7 +355,7 @@ strategies.forEach((strategy) => {
describe('importer: ' + strategy, function () {
this.timeout(30 * 1000)

/** @type {IPLDResolver} */
/** @type {IPLD} */
let ipld
/** @type {BlockAPI} */
let block
Expand Down Expand Up @@ -1076,7 +1076,7 @@ strategies.forEach((strategy) => {
})

describe('configuration', () => {
/** @type {IPLDResolver} */
/** @type {IPLD} */
let ipld
/** @type {BlockAPI} */
let block
Expand Down
3 changes: 2 additions & 1 deletion packages/ipfs-unixfs-exporter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "aegir/src/config/tsconfig.aegir.json",
"compilerOptions": {
"outDir": "dist"
"outDir": "dist",
"importsNotUsedAsValues": "preserve"
},
"include": [
"src",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-unixfs-importer/test/benchmark.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const CHUNK_SIZE = 65536
describe.skip('benchmark', function () {
this.timeout(30 * 1000)

/** @type {import('./helpers/block').IPLDResolver} */
/** @type {import('./helpers/block').IPLD} */
let ipld
/** @type {import('../src').BlockAPI} */
let block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const blockApi = require('./helpers/block')
const defaultOptions = require('../src/options')

describe('builder: onlyHash', () => {
/** @type {import('./helpers/block').IPLDResolver} */
/** @type {import('./helpers/block').IPLD} */
let ipld
/** @type {import('../src').BlockAPI} */
let block
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-unixfs-importer/test/builder.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
const defaultOptions = require('../src/options')

describe('builder', () => {
/** @type {import('./helpers/block').IPLDResolver} */
/** @type {import('./helpers/block').IPLD} */
let ipld
/** @type {import('../src').BlockAPI} */
let block
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-unixfs-importer/test/chunker-custom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const iter = async function * () {
}

describe('custom chunker', function () {
/** @type {import('./helpers/block').IPLDResolver} */
/** @type {import('./helpers/block').IPLD} */
let ipld
/** @type {import('../src').BlockAPI} */
let block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ strategies.forEach(strategy => {
}

describe('go-ipfs interop using importer:' + strategy, () => {
/** @type {import('./helpers/block').IPLDResolver} */
/** @type {import('./helpers/block').IPLD} */
let ipld
/** @type {import('../src').BlockAPI} */
let block
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-unixfs-importer/test/helpers/block.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ const mh = require('multihashing-async').multihash

/**
* @typedef {import('cids')} CID
* @typedef {object} IPLDResolver
* @typedef {object} IPLD
* @property {(cid: CID, options?: any) => Promise<any>} get
* @property {(node: any, codec: number, options?: any) => Promise<CID>} put
*/

/**
*
* @param {IPLDResolver} ipld
* @param {IPLD} ipld
*/
function createBlockApi (ipld) {
// make ipld behave like the block api, some tests need to pull
Expand Down
0