@helia/car 4.0.3 → 4.0.4-313e2c1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +34 -17
- package/dist/index.min.js +1 -1
- package/dist/src/car.d.ts +17 -0
- package/dist/src/car.d.ts.map +1 -0
- package/dist/src/car.js +162 -0
- package/dist/src/car.js.map +1 -0
- package/dist/src/constants.d.ts +10 -0
- package/dist/src/constants.d.ts.map +1 -0
- package/dist/src/constants.js +10 -0
- package/dist/src/constants.js.map +1 -0
- package/dist/src/errors.d.ts +9 -0
- package/dist/src/errors.d.ts.map +1 -0
- package/dist/src/errors.js +9 -0
- package/dist/src/errors.js.map +1 -0
- package/dist/src/export-strategies/block-exporter.d.ts +10 -0
- package/dist/src/export-strategies/block-exporter.d.ts.map +1 -0
- package/dist/src/export-strategies/block-exporter.js +12 -0
- package/dist/src/export-strategies/block-exporter.js.map +1 -0
- package/dist/src/export-strategies/index.d.ts +4 -0
- package/dist/src/export-strategies/index.d.ts.map +1 -0
- package/dist/src/export-strategies/index.js +4 -0
- package/dist/src/export-strategies/index.js.map +1 -0
- package/dist/src/export-strategies/subgraph-exporter.d.ts +14 -0
- package/dist/src/export-strategies/subgraph-exporter.d.ts.map +1 -0
- package/dist/src/export-strategies/subgraph-exporter.js +17 -0
- package/dist/src/export-strategies/subgraph-exporter.js.map +1 -0
- package/dist/src/export-strategies/unixfs-exporter.d.ts +11 -0
- package/dist/src/export-strategies/unixfs-exporter.d.ts.map +1 -0
- package/dist/src/export-strategies/unixfs-exporter.js +18 -0
- package/dist/src/export-strategies/unixfs-exporter.js.map +1 -0
- package/dist/src/index.d.ts +89 -24
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +38 -95
- package/dist/src/index.js.map +1 -1
- package/dist/src/traversal-strategies/cid-path.d.ts +16 -0
- package/dist/src/traversal-strategies/cid-path.d.ts.map +1 -0
- package/dist/src/traversal-strategies/cid-path.js +22 -0
- package/dist/src/traversal-strategies/cid-path.js.map +1 -0
- package/dist/src/traversal-strategies/graph-search.d.ts +14 -0
- package/dist/src/traversal-strategies/graph-search.d.ts.map +1 -0
- package/dist/src/traversal-strategies/graph-search.js +19 -0
- package/dist/src/traversal-strategies/graph-search.js.map +1 -0
- package/dist/src/traversal-strategies/index.d.ts +4 -0
- package/dist/src/traversal-strategies/index.d.ts.map +1 -0
- package/dist/src/traversal-strategies/index.js +4 -0
- package/dist/src/traversal-strategies/index.js.map +1 -0
- package/dist/src/traversal-strategies/unixfs-path.d.ts +13 -0
- package/dist/src/traversal-strategies/unixfs-path.d.ts.map +1 -0
- package/dist/src/traversal-strategies/unixfs-path.js +42 -0
- package/dist/src/traversal-strategies/unixfs-path.js.map +1 -0
- package/package.json +12 -6
- package/src/car.ts +218 -0
- package/src/constants.ts +11 -0
- package/src/errors.ts +8 -0
- package/src/export-strategies/block-exporter.ts +13 -0
- package/src/export-strategies/index.ts +3 -0
- package/src/export-strategies/subgraph-exporter.ts +18 -0
- package/src/export-strategies/unixfs-exporter.ts +22 -0
- package/src/index.ts +99 -119
- package/src/traversal-strategies/cid-path.ts +29 -0
- package/src/traversal-strategies/graph-search.ts +25 -0
- package/src/traversal-strategies/index.ts +3 -0
- package/src/traversal-strategies/unixfs-path.ts +58 -0
- package/dist/typedoc-urls.json +0 -10
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export declare const DAG_WALK_QUEUE_CONCURRENCY = 1;
|
|
2
|
+
/**
|
|
3
|
+
* The multicodec code for dag-pb binary data
|
|
4
|
+
*/
|
|
5
|
+
export declare const DAG_PB_CODEC_CODE = 112;
|
|
6
|
+
/**
|
|
7
|
+
* The multicodec code for raw binary data
|
|
8
|
+
*/
|
|
9
|
+
export declare const RAW_PB_CODEC_CODE = 85;
|
|
10
|
+
//# sourceMappingURL=constants.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,0BAA0B,IAAI,CAAA;AAE3C;;GAEG;AACH,eAAO,MAAM,iBAAiB,MAAO,CAAA;AAErC;;GAEG;AACH,eAAO,MAAM,iBAAiB,KAAO,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const DAG_WALK_QUEUE_CONCURRENCY = 1;
|
|
2
|
+
/**
|
|
3
|
+
* The multicodec code for dag-pb binary data
|
|
4
|
+
*/
|
|
5
|
+
export const DAG_PB_CODEC_CODE = 0x70;
|
|
6
|
+
/**
|
|
7
|
+
* The multicodec code for raw binary data
|
|
8
|
+
*/
|
|
9
|
+
export const RAW_PB_CODEC_CODE = 0x55;
|
|
10
|
+
//# sourceMappingURL=constants.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"constants.js","sourceRoot":"","sources":["../../src/constants.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,0BAA0B,GAAG,CAAC,CAAA;AAE3C;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAA;AAErC;;GAEG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAAG,IAAI,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,qBAAa,cAAe,SAAQ,KAAK;IACvC,MAAM,CAAC,IAAI,SAAmB;IAC9B,MAAM,CAAC,OAAO,SAAsB;IACpC,MAAM,CAAC,IAAI,SAAmB;IAC9B,IAAI,SAAmB;IACvB,OAAO,SAAsB;IAC7B,IAAI,SAAmB;CACxB"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export class NotUnixFSError extends Error {
|
|
2
|
+
static code = 'ERR_NOT_UNIXFS';
|
|
3
|
+
static message = 'Not a UnixFS node';
|
|
4
|
+
static name = 'NotUnixFSError';
|
|
5
|
+
code = 'ERR_NOT_UNIXFS';
|
|
6
|
+
message = 'Not a UnixFS node';
|
|
7
|
+
name = 'NotUnixFSError';
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../../src/errors.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,cAAe,SAAQ,KAAK;IACvC,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,MAAM,CAAC,OAAO,GAAG,mBAAmB,CAAA;IACpC,MAAM,CAAC,IAAI,GAAG,gBAAgB,CAAA;IAC9B,IAAI,GAAG,gBAAgB,CAAA;IACvB,OAAO,GAAG,mBAAmB,CAAA;IAC7B,IAAI,GAAG,gBAAgB,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type CID } from 'multiformats/cid';
|
|
2
|
+
import { type ExportStrategy } from '../index.js';
|
|
3
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
4
|
+
/**
|
|
5
|
+
* Yields the first block from the first CID and stops
|
|
6
|
+
*/
|
|
7
|
+
export declare class BlockExporter implements ExportStrategy {
|
|
8
|
+
export(cid: CID, block: BlockView<any, any, any, 0 | 1>): AsyncGenerator<CID, void, undefined>;
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=block-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/block-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAE7D;;GAEG;AACH,qBAAa,aAAc,YAAW,cAAc;IAC1C,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC;CAIxG"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import {} from 'multiformats/cid';
|
|
2
|
+
import {} from '../index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Yields the first block from the first CID and stops
|
|
5
|
+
*/
|
|
6
|
+
export class BlockExporter {
|
|
7
|
+
async *export(cid, block) {
|
|
8
|
+
// don't yield the block, index.ts will add it to the car file and then
|
|
9
|
+
// we're done
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=block-exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/block-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAuB,MAAM,aAAa,CAAA;AAGjD;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,KAAK,CAAC,CAAE,MAAM,CAAE,GAAQ,EAAE,KAAsC;QAC9D,uEAAuE;QACvE,aAAa;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/export-strategies/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAA;AACtC,cAAc,qBAAqB,CAAA;AACnC,cAAc,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type CID } from 'multiformats/cid';
|
|
2
|
+
import { type ExportStrategy } from '../index.js';
|
|
3
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
4
|
+
/**
|
|
5
|
+
* Traverses the DAG breadth-first starting at the target CID and yields all
|
|
6
|
+
* encountered blocks.
|
|
7
|
+
*
|
|
8
|
+
* Blocks linked to from the target block are traversed using codecs defined in
|
|
9
|
+
* the helia config.
|
|
10
|
+
*/
|
|
11
|
+
export declare class SubgraphExporter implements ExportStrategy {
|
|
12
|
+
export(_cid: CID, block: BlockView<any, any, any, 0 | 1>): AsyncGenerator<CID, void, undefined>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=subgraph-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subgraph-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/subgraph-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAE7D;;;;;;GAMG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IAC7C,MAAM,CAAE,IAAI,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC;CAKzG"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import {} from 'multiformats/cid';
|
|
2
|
+
import {} from '../index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Traverses the DAG breadth-first starting at the target CID and yields all
|
|
5
|
+
* encountered blocks.
|
|
6
|
+
*
|
|
7
|
+
* Blocks linked to from the target block are traversed using codecs defined in
|
|
8
|
+
* the helia config.
|
|
9
|
+
*/
|
|
10
|
+
export class SubgraphExporter {
|
|
11
|
+
async *export(_cid, block) {
|
|
12
|
+
for await (const [, linkedCid] of block.links()) {
|
|
13
|
+
yield linkedCid;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=subgraph-exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"subgraph-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/subgraph-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,kBAAkB,CAAA;AAC3C,OAAO,EAAuB,MAAM,aAAa,CAAA;AAGjD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAC3B,KAAK,CAAC,CAAE,MAAM,CAAE,IAAS,EAAE,KAAsC;QAC/D,IAAI,KAAK,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAChD,MAAM,SAAS,CAAA;QACjB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { ExportStrategy } from '../index.js';
|
|
2
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
4
|
+
/**
|
|
5
|
+
* This exporter is used when you want to generate a car file that contains a
|
|
6
|
+
* single UnixFS file or directory
|
|
7
|
+
*/
|
|
8
|
+
export declare class UnixFSExporter implements ExportStrategy {
|
|
9
|
+
export(cid: CID, block: BlockView<any, any, any, 0 | 1>): AsyncGenerator<CID, void, undefined>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=unixfs-exporter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unixfs-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/unixfs-exporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;GAGG;AACH,qBAAa,cAAe,YAAW,cAAc;IAC3C,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC;CAUxG"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DAG_PB_CODEC_CODE, RAW_PB_CODEC_CODE } from '../constants.js';
|
|
2
|
+
import { NotUnixFSError } from '../errors.js';
|
|
3
|
+
/**
|
|
4
|
+
* This exporter is used when you want to generate a car file that contains a
|
|
5
|
+
* single UnixFS file or directory
|
|
6
|
+
*/
|
|
7
|
+
export class UnixFSExporter {
|
|
8
|
+
async *export(cid, block) {
|
|
9
|
+
if (cid.code !== DAG_PB_CODEC_CODE && cid.code !== RAW_PB_CODEC_CODE) {
|
|
10
|
+
throw new NotUnixFSError('Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs');
|
|
11
|
+
}
|
|
12
|
+
// yield all the blocks that make up the file or directory
|
|
13
|
+
for await (const [, linkedCid] of block.links()) {
|
|
14
|
+
yield linkedCid;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=unixfs-exporter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"unixfs-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/unixfs-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAK7C;;;GAGG;AACH,MAAM,OAAO,cAAc;IACzB,KAAK,CAAC,CAAE,MAAM,CAAE,GAAQ,EAAE,KAAsC;QAC9D,IAAI,GAAG,CAAC,IAAI,KAAK,iBAAiB,IAAI,GAAG,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;YACrE,MAAM,IAAI,cAAc,CAAC,iFAAiF,CAAC,CAAA;QAC7G,CAAC;QAED,0DAA0D;QAC1D,IAAI,KAAK,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,IAAI,KAAK,CAAC,KAAK,EAAE,EAAE,CAAC;YAChD,MAAM,SAAS,CAAA;QACjB,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -1,39 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
* `@helia/car` provides `import` and `export` methods to read/write Car files
|
|
4
|
+
* `@helia/car` provides `import` and `export` methods to read/write Car files
|
|
5
|
+
* to {@link https://github.com/ipfs/helia Helia}'s blockstore.
|
|
5
6
|
*
|
|
6
7
|
* See the {@link Car} interface for all available operations.
|
|
7
8
|
*
|
|
8
|
-
* By default it supports `dag-pb`, `dag-cbor`, `dag-json` and `raw` CIDs, more
|
|
9
|
+
* By default it supports `dag-pb`, `dag-cbor`, `dag-json` and `raw` CIDs, more
|
|
10
|
+
* esoteric DAG walkers can be passed as an init option.
|
|
9
11
|
*
|
|
10
12
|
* @example Exporting a DAG as a CAR file
|
|
11
13
|
*
|
|
12
14
|
* ```typescript
|
|
13
15
|
* import { createHelia } from 'helia'
|
|
14
|
-
* import { unixfs } from '@helia/unixfs'
|
|
15
16
|
* import { car } from '@helia/car'
|
|
16
|
-
* import {
|
|
17
|
-
* import { Readable } from 'node:stream'
|
|
17
|
+
* import { CID } from 'multiformats/cid'
|
|
18
18
|
* import nodeFs from 'node:fs'
|
|
19
19
|
*
|
|
20
|
-
* const helia = await createHelia(
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* const
|
|
20
|
+
* const helia = await createHelia()
|
|
21
|
+
* const cid = CID.parse('QmFoo...')
|
|
22
|
+
*
|
|
23
|
+
* const c = car(helia)
|
|
24
|
+
* const out = nodeFs.createWriteStream('example.car')
|
|
25
|
+
*
|
|
26
|
+
* for await (const buf of c.stream(cid)) {
|
|
27
|
+
* out.write(buf)
|
|
28
|
+
* }
|
|
29
|
+
*
|
|
30
|
+
* out.end()
|
|
31
|
+
* ```
|
|
24
32
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
33
|
+
* @example Exporting a part of a UnixFS DAG as a CAR file
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { createHelia } from 'helia'
|
|
37
|
+
* import { car, UnixFSPath } from '@helia/car'
|
|
38
|
+
* import { CID } from 'multiformats/cid'
|
|
39
|
+
* import nodeFs from 'node:fs'
|
|
40
|
+
*
|
|
41
|
+
* const helia = await createHelia()
|
|
42
|
+
* const cid = CID.parse('QmFoo...')
|
|
27
43
|
*
|
|
28
|
-
* // export it as a Car
|
|
29
44
|
* const c = car(helia)
|
|
30
|
-
* const
|
|
45
|
+
* const out = nodeFs.createWriteStream('example.car')
|
|
31
46
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
47
|
+
* for await (const buf of c.stream(cid, {
|
|
48
|
+
* traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
49
|
+
* })) {
|
|
50
|
+
* out.write(buf)
|
|
51
|
+
* }
|
|
34
52
|
*
|
|
35
|
-
*
|
|
36
|
-
* await c.export(cid, writer)
|
|
53
|
+
* out.end()
|
|
37
54
|
* ```
|
|
38
55
|
*
|
|
39
56
|
* @example Importing all blocks from a CAR file
|
|
@@ -58,24 +75,72 @@
|
|
|
58
75
|
* await c.import(reader)
|
|
59
76
|
* ```
|
|
60
77
|
*/
|
|
61
|
-
import { CarWriter } from '@ipld/car';
|
|
62
78
|
import type { CodecLoader } from '@helia/interface';
|
|
63
|
-
import type {
|
|
64
|
-
import type { CarReader } from '@ipld/car';
|
|
65
|
-
import type { AbortOptions } from '@libp2p/interface';
|
|
79
|
+
import type { PutManyBlocksProgressEvents, GetBlockProgressEvents } from '@helia/interface/blocks';
|
|
80
|
+
import type { CarWriter, CarReader } from '@ipld/car';
|
|
81
|
+
import type { AbortOptions, ComponentLogger } from '@libp2p/interface';
|
|
66
82
|
import type { Filter } from '@libp2p/utils/filters';
|
|
67
83
|
import type { Blockstore } from 'interface-blockstore';
|
|
84
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
68
85
|
import type { CID } from 'multiformats/cid';
|
|
69
86
|
import type { ProgressOptions } from 'progress-events';
|
|
70
87
|
export interface CarComponents {
|
|
88
|
+
logger: ComponentLogger;
|
|
71
89
|
blockstore: Blockstore;
|
|
72
90
|
getCodec: CodecLoader;
|
|
73
91
|
}
|
|
92
|
+
/**
|
|
93
|
+
* Interface for different traversal strategies.
|
|
94
|
+
*
|
|
95
|
+
* While traversing the DAG, it will yield blocks that it has traversed.
|
|
96
|
+
*/
|
|
97
|
+
export interface TraversalStrategy {
|
|
98
|
+
/**
|
|
99
|
+
* Traverse the DAG and yield the next CID to traverse
|
|
100
|
+
*/
|
|
101
|
+
traverse<T extends BlockView<any, any, any, 0 | 1>>(cid: CID, block: T): AsyncGenerator<CID, void, undefined>;
|
|
102
|
+
/**
|
|
103
|
+
* Returns true if the current CID is the target and we should switch to the
|
|
104
|
+
* export strategy
|
|
105
|
+
*/
|
|
106
|
+
isTarget(cid: CID): boolean;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Interface for different export strategies.
|
|
110
|
+
*
|
|
111
|
+
* When traversal has ended the export begins starting at the target CID, and
|
|
112
|
+
* the export strategy may do further traversal and writing to the car file.
|
|
113
|
+
*/
|
|
114
|
+
export interface ExportStrategy {
|
|
115
|
+
/**
|
|
116
|
+
* Export the DAG and yield the next CID to traverse
|
|
117
|
+
*/
|
|
118
|
+
export<T extends BlockView<any, any, any, 0 | 1>>(cid: CID, block: T): AsyncGenerator<CID, void, undefined>;
|
|
119
|
+
}
|
|
120
|
+
export * from './export-strategies/index.js';
|
|
121
|
+
export * from './traversal-strategies/index.js';
|
|
74
122
|
export interface ExportCarOptions extends AbortOptions, ProgressOptions<GetBlockProgressEvents> {
|
|
75
123
|
/**
|
|
76
|
-
* If
|
|
124
|
+
* If true, the blockstore will not do any network requests.
|
|
125
|
+
*
|
|
126
|
+
* @default false
|
|
127
|
+
*/
|
|
128
|
+
offline?: boolean;
|
|
129
|
+
/**
|
|
130
|
+
* If a filter is passed it will be used to deduplicate blocks exported in the
|
|
131
|
+
* car file
|
|
77
132
|
*/
|
|
78
133
|
blockFilter?: Filter;
|
|
134
|
+
/**
|
|
135
|
+
* The traversal strategy to use for the export. This determines how the dag
|
|
136
|
+
* is traversed: either depth first, breadth first, or a custom strategy.
|
|
137
|
+
*/
|
|
138
|
+
traversal?: TraversalStrategy;
|
|
139
|
+
/**
|
|
140
|
+
* Export strategy to use for the export. This should be used to change the
|
|
141
|
+
* blocks included in the exported car file. (e.g. https://specs.ipfs.tech/http-gateways/trustless-gateway/#dag-scope-request-query-parameter)
|
|
142
|
+
*/
|
|
143
|
+
exporter?: ExportStrategy;
|
|
79
144
|
}
|
|
80
145
|
/**
|
|
81
146
|
* The Car interface provides operations for importing and exporting Car files
|
|
@@ -141,7 +206,7 @@ export interface Car {
|
|
|
141
206
|
*
|
|
142
207
|
* ```typescript
|
|
143
208
|
* import { createHelia } from 'helia'
|
|
144
|
-
* import { car } from '@helia/car
|
|
209
|
+
* import { car } from '@helia/car'
|
|
145
210
|
* import { CID } from 'multiformats/cid'
|
|
146
211
|
*
|
|
147
212
|
* const helia = await createHelia()
|
|
@@ -154,7 +219,7 @@ export interface Car {
|
|
|
154
219
|
* }
|
|
155
220
|
* ```
|
|
156
221
|
*/
|
|
157
|
-
stream(root: CID | CID[], options?:
|
|
222
|
+
stream(root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined>;
|
|
158
223
|
}
|
|
159
224
|
/**
|
|
160
225
|
* Create a {@link Car} instance for use with {@link https://github.com/ipfs/helia Helia}
|
package/dist/src/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,MAAM,yBAAyB,CAAA;AAClG,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrD,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,eAAe,CAAA;IACvB,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,WAAW,CAAA;CACtB;AAED;;;;GAIG;AACH,MAAM,WAAW,iBAAiB;IAChC;;OAEG;IACH,QAAQ,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;IAE7G;;;OAGG;IACH,QAAQ,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAAA;CAC5B;AAED;;;;;GAKG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;CAC5G;AAED,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iCAAiC,CAAA;AAE/C,MAAM,WAAW,gBAAiB,SAAQ,YAAY,EAAE,eAAe,CAAC,sBAAsB,CAAC;IAE7F;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAA;IAEjB;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB;;;OAGG;IACH,SAAS,CAAC,EAAE,iBAAiB,CAAA;IAE7B;;;OAGG;IACH,QAAQ,CAAC,EAAE,cAAc,CAAA;CAC1B;AAED;;;GAGG;AACH,MAAM,WAAW,GAAG;IAClB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE/H;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA6BG;IACH,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,KAAK,GAAG,OAAO,CAAC,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,OAAO,CAAC,IAAI,CAAC,CAAA;IAE9G;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAAA;CACnG;AAED;;GAEG;AACH,wBAAgB,GAAG,CAAE,KAAK,EAAE,aAAa,EAAE,IAAI,GAAE,GAAQ,GAAG,GAAG,CAE9D"}
|
package/dist/src/index.js
CHANGED
|
@@ -1,39 +1,56 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @packageDocumentation
|
|
3
3
|
*
|
|
4
|
-
* `@helia/car` provides `import` and `export` methods to read/write Car files
|
|
4
|
+
* `@helia/car` provides `import` and `export` methods to read/write Car files
|
|
5
|
+
* to {@link https://github.com/ipfs/helia Helia}'s blockstore.
|
|
5
6
|
*
|
|
6
7
|
* See the {@link Car} interface for all available operations.
|
|
7
8
|
*
|
|
8
|
-
* By default it supports `dag-pb`, `dag-cbor`, `dag-json` and `raw` CIDs, more
|
|
9
|
+
* By default it supports `dag-pb`, `dag-cbor`, `dag-json` and `raw` CIDs, more
|
|
10
|
+
* esoteric DAG walkers can be passed as an init option.
|
|
9
11
|
*
|
|
10
12
|
* @example Exporting a DAG as a CAR file
|
|
11
13
|
*
|
|
12
14
|
* ```typescript
|
|
13
15
|
* import { createHelia } from 'helia'
|
|
14
|
-
* import { unixfs } from '@helia/unixfs'
|
|
15
16
|
* import { car } from '@helia/car'
|
|
16
|
-
* import {
|
|
17
|
-
* import { Readable } from 'node:stream'
|
|
17
|
+
* import { CID } from 'multiformats/cid'
|
|
18
18
|
* import nodeFs from 'node:fs'
|
|
19
19
|
*
|
|
20
|
-
* const helia = await createHelia(
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* const
|
|
20
|
+
* const helia = await createHelia()
|
|
21
|
+
* const cid = CID.parse('QmFoo...')
|
|
22
|
+
*
|
|
23
|
+
* const c = car(helia)
|
|
24
|
+
* const out = nodeFs.createWriteStream('example.car')
|
|
25
|
+
*
|
|
26
|
+
* for await (const buf of c.stream(cid)) {
|
|
27
|
+
* out.write(buf)
|
|
28
|
+
* }
|
|
24
29
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
30
|
+
* out.end()
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Exporting a part of a UnixFS DAG as a CAR file
|
|
34
|
+
*
|
|
35
|
+
* ```typescript
|
|
36
|
+
* import { createHelia } from 'helia'
|
|
37
|
+
* import { car, UnixFSPath } from '@helia/car'
|
|
38
|
+
* import { CID } from 'multiformats/cid'
|
|
39
|
+
* import nodeFs from 'node:fs'
|
|
40
|
+
*
|
|
41
|
+
* const helia = await createHelia()
|
|
42
|
+
* const cid = CID.parse('QmFoo...')
|
|
27
43
|
*
|
|
28
|
-
* // export it as a Car
|
|
29
44
|
* const c = car(helia)
|
|
30
|
-
* const
|
|
45
|
+
* const out = nodeFs.createWriteStream('example.car')
|
|
31
46
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
47
|
+
* for await (const buf of c.stream(cid, {
|
|
48
|
+
* traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
49
|
+
* })) {
|
|
50
|
+
* out.write(buf)
|
|
51
|
+
* }
|
|
34
52
|
*
|
|
35
|
-
*
|
|
36
|
-
* await c.export(cid, writer)
|
|
53
|
+
* out.end()
|
|
37
54
|
* ```
|
|
38
55
|
*
|
|
39
56
|
* @example Importing all blocks from a CAR file
|
|
@@ -58,87 +75,13 @@
|
|
|
58
75
|
* await c.import(reader)
|
|
59
76
|
* ```
|
|
60
77
|
*/
|
|
61
|
-
import {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
import { createUnsafe } from 'multiformats/block';
|
|
65
|
-
import defer from 'p-defer';
|
|
66
|
-
import PQueue from 'p-queue';
|
|
67
|
-
const DAG_WALK_QUEUE_CONCURRENCY = 1;
|
|
68
|
-
class DefaultCar {
|
|
69
|
-
components;
|
|
70
|
-
constructor(components, init) {
|
|
71
|
-
this.components = components;
|
|
72
|
-
}
|
|
73
|
-
async import(reader, options) {
|
|
74
|
-
await drain(this.components.blockstore.putMany(map(reader.blocks(), ({ cid, bytes }) => ({ cid, block: bytes })), options));
|
|
75
|
-
}
|
|
76
|
-
async export(root, writer, options) {
|
|
77
|
-
const deferred = defer();
|
|
78
|
-
const roots = Array.isArray(root) ? root : [root];
|
|
79
|
-
// use a queue to walk the DAG instead of recursion so we can traverse very large DAGs
|
|
80
|
-
const queue = new PQueue({
|
|
81
|
-
concurrency: DAG_WALK_QUEUE_CONCURRENCY
|
|
82
|
-
});
|
|
83
|
-
queue.on('idle', () => {
|
|
84
|
-
deferred.resolve();
|
|
85
|
-
});
|
|
86
|
-
queue.on('error', (err) => {
|
|
87
|
-
queue.clear();
|
|
88
|
-
deferred.reject(err);
|
|
89
|
-
});
|
|
90
|
-
for (const root of roots) {
|
|
91
|
-
void queue.add(async () => {
|
|
92
|
-
await this.#walkDag(root, queue, async (cid, bytes) => {
|
|
93
|
-
// if a filter has been passed, skip blocks that have already been written
|
|
94
|
-
if (options?.blockFilter?.has(cid.multihash.bytes) === true) {
|
|
95
|
-
return;
|
|
96
|
-
}
|
|
97
|
-
options?.blockFilter?.add(cid.multihash.bytes);
|
|
98
|
-
await writer.put({ cid, bytes });
|
|
99
|
-
}, options);
|
|
100
|
-
})
|
|
101
|
-
.catch(() => { });
|
|
102
|
-
}
|
|
103
|
-
// wait for the writer to end
|
|
104
|
-
try {
|
|
105
|
-
await deferred.promise;
|
|
106
|
-
}
|
|
107
|
-
finally {
|
|
108
|
-
await writer.close();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
async *stream(root, options) {
|
|
112
|
-
const { writer, out } = CarWriter.create(root);
|
|
113
|
-
// has to be done async so we write to `writer` and read from `out` at the
|
|
114
|
-
// same time
|
|
115
|
-
this.export(root, writer, options)
|
|
116
|
-
.catch(() => { });
|
|
117
|
-
for await (const buf of out) {
|
|
118
|
-
yield buf;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
/**
|
|
122
|
-
* Walk the DAG behind the passed CID, ensure all blocks are present in the blockstore
|
|
123
|
-
* and update the pin count for them
|
|
124
|
-
*/
|
|
125
|
-
async #walkDag(cid, queue, withBlock, options) {
|
|
126
|
-
const codec = await this.components.getCodec(cid.code);
|
|
127
|
-
const bytes = await this.components.blockstore.get(cid, options);
|
|
128
|
-
await withBlock(cid, bytes);
|
|
129
|
-
const block = createUnsafe({ bytes, cid, codec });
|
|
130
|
-
// walk dag, ensure all blocks are present
|
|
131
|
-
for await (const [, cid] of block.links()) {
|
|
132
|
-
void queue.add(async () => {
|
|
133
|
-
await this.#walkDag(cid, queue, withBlock, options);
|
|
134
|
-
});
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
}
|
|
78
|
+
import { Car as CarClass } from './car.js';
|
|
79
|
+
export * from './export-strategies/index.js';
|
|
80
|
+
export * from './traversal-strategies/index.js';
|
|
138
81
|
/**
|
|
139
82
|
* Create a {@link Car} instance for use with {@link https://github.com/ipfs/helia Helia}
|
|
140
83
|
*/
|
|
141
84
|
export function car(helia, init = {}) {
|
|
142
|
-
return new
|
|
85
|
+
return new CarClass(helia, init);
|
|
143
86
|
}
|
|
144
87
|
//# sourceMappingURL=index.js.map
|
package/dist/src/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4EG;AAEH,OAAO,EAAE,GAAG,IAAI,QAAQ,EAAE,MAAM,UAAU,CAAA;AAgD1C,cAAc,8BAA8B,CAAA;AAC5C,cAAc,iCAAiC,CAAA;AAgH/C;;GAEG;AACH,MAAM,UAAU,GAAG,CAAE,KAAoB,EAAE,OAAY,EAAE;IACvD,OAAO,IAAI,QAAQ,CAAC,KAAK,EAAE,IAAI,CAAC,CAAA;AAClC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { TraversalStrategy } from '../index.js';
|
|
2
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
4
|
+
/**
|
|
5
|
+
* Simple strategy that traverses a known path to a target CID.
|
|
6
|
+
*
|
|
7
|
+
* All this strategy does is yield the next CID in the known path.
|
|
8
|
+
*/
|
|
9
|
+
export declare class CIDPath implements TraversalStrategy {
|
|
10
|
+
private readonly pathToTarget;
|
|
11
|
+
private readonly target;
|
|
12
|
+
constructor(pathToTarget: CID[]);
|
|
13
|
+
isTarget(cid: CID): boolean;
|
|
14
|
+
traverse<T extends BlockView<any, any, any, 0 | 1>>(cid: CID, _block?: T): AsyncGenerator<CID, void, undefined>;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=cid-path.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid-path.d.ts","sourceRoot":"","sources":["../../../src/traversal-strategies/cid-path.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;;GAIG;AACH,qBAAa,OAAQ,YAAW,iBAAiB;IAC/C,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAO;IACpC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAK;gBAEf,YAAY,EAAE,GAAG,EAAE;IAKhC,QAAQ,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO;IAIpB,QAAQ,CAAE,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC;CAMzH"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Simple strategy that traverses a known path to a target CID.
|
|
3
|
+
*
|
|
4
|
+
* All this strategy does is yield the next CID in the known path.
|
|
5
|
+
*/
|
|
6
|
+
export class CIDPath {
|
|
7
|
+
pathToTarget;
|
|
8
|
+
target;
|
|
9
|
+
constructor(pathToTarget) {
|
|
10
|
+
this.pathToTarget = pathToTarget;
|
|
11
|
+
this.target = pathToTarget[pathToTarget.length - 1];
|
|
12
|
+
}
|
|
13
|
+
isTarget(cid) {
|
|
14
|
+
return this.target.equals(cid);
|
|
15
|
+
}
|
|
16
|
+
async *traverse(cid, _block) {
|
|
17
|
+
const givenCidIndex = this.pathToTarget.indexOf(cid);
|
|
18
|
+
const nextCid = this.pathToTarget[givenCidIndex + 1];
|
|
19
|
+
yield nextCid;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=cid-path.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cid-path.js","sourceRoot":"","sources":["../../../src/traversal-strategies/cid-path.ts"],"names":[],"mappings":"AAIA;;;;GAIG;AACH,MAAM,OAAO,OAAO;IACD,YAAY,CAAO;IACnB,MAAM,CAAK;IAE5B,YAAa,YAAmB;QAC9B,IAAI,CAAC,YAAY,GAAG,YAAY,CAAA;QAChC,IAAI,CAAC,MAAM,GAAG,YAAY,CAAC,YAAY,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;IACrD,CAAC;IAED,QAAQ,CAAE,GAAQ;QAChB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAA;IAChC,CAAC;IAED,KAAK,CAAC,CAAE,QAAQ,CAA6C,GAAQ,EAAE,MAAU;QAC/E,MAAM,aAAa,GAAG,IAAI,CAAC,YAAY,CAAC,OAAO,CAAC,GAAG,CAAC,CAAA;QACpD,MAAM,OAAO,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,GAAG,CAAC,CAAC,CAAA;QAEpD,MAAM,OAAO,CAAA;IACf,CAAC;CACF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { TraversalStrategy } from '../index.js';
|
|
2
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
4
|
+
/**
|
|
5
|
+
* A traversal strategy that performs a breadth-first search (so as to not load blocks unnecessarily) looking for a
|
|
6
|
+
* target CID. Traversal stops when we reach the target CID or run out of nodes.
|
|
7
|
+
*/
|
|
8
|
+
export declare class GraphSearch implements TraversalStrategy {
|
|
9
|
+
private readonly target;
|
|
10
|
+
constructor(target: CID);
|
|
11
|
+
isTarget(cid: CID): boolean;
|
|
12
|
+
traverse<T extends BlockView<any, any, any, 0 | 1>>(cid: CID, block: T): AsyncGenerator<CID, void, undefined>;
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=graph-search.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"graph-search.d.ts","sourceRoot":"","sources":["../../../src/traversal-strategies/graph-search.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAA;AACpD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAA;AAC7D,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;GAGG;AACH,qBAAa,WAAY,YAAW,iBAAiB;IACnD,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAK;gBAEf,MAAM,EAAE,GAAG;IAIxB,QAAQ,CAAE,GAAG,EAAE,GAAG,GAAG,OAAO;IAIpB,QAAQ,CAAE,CAAC,SAAS,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,GAAG,cAAc,CAAC,GAAG,EAAE,IAAI,EAAE,SAAS,CAAC;CAKvH"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A traversal strategy that performs a breadth-first search (so as to not load blocks unnecessarily) looking for a
|
|
3
|
+
* target CID. Traversal stops when we reach the target CID or run out of nodes.
|
|
4
|
+
*/
|
|
5
|
+
export class GraphSearch {
|
|
6
|
+
target;
|
|
7
|
+
constructor(target) {
|
|
8
|
+
this.target = target;
|
|
9
|
+
}
|
|
10
|
+
isTarget(cid) {
|
|
11
|
+
return this.target.equals(cid);
|
|
12
|
+
}
|
|
13
|
+
async *traverse(cid, block) {
|
|
14
|
+
for await (const [, linkedCid] of block.links()) {
|
|
15
|
+
yield linkedCid;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
//# sourceMappingURL=graph-search.js.map
|