@helia/car 4.0.3 → 4.0.4-ae67092

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.
Files changed (65) hide show
  1. package/README.md +34 -17
  2. package/dist/index.min.js +2 -1
  3. package/dist/index.min.js.map +7 -0
  4. package/dist/src/car.d.ts +17 -0
  5. package/dist/src/car.d.ts.map +1 -0
  6. package/dist/src/car.js +162 -0
  7. package/dist/src/car.js.map +1 -0
  8. package/dist/src/constants.d.ts +10 -0
  9. package/dist/src/constants.d.ts.map +1 -0
  10. package/dist/src/constants.js +10 -0
  11. package/dist/src/constants.js.map +1 -0
  12. package/dist/src/errors.d.ts +9 -0
  13. package/dist/src/errors.d.ts.map +1 -0
  14. package/dist/src/errors.js +9 -0
  15. package/dist/src/errors.js.map +1 -0
  16. package/dist/src/export-strategies/block-exporter.d.ts +10 -0
  17. package/dist/src/export-strategies/block-exporter.d.ts.map +1 -0
  18. package/dist/src/export-strategies/block-exporter.js +12 -0
  19. package/dist/src/export-strategies/block-exporter.js.map +1 -0
  20. package/dist/src/export-strategies/index.d.ts +4 -0
  21. package/dist/src/export-strategies/index.d.ts.map +1 -0
  22. package/dist/src/export-strategies/index.js +4 -0
  23. package/dist/src/export-strategies/index.js.map +1 -0
  24. package/dist/src/export-strategies/subgraph-exporter.d.ts +14 -0
  25. package/dist/src/export-strategies/subgraph-exporter.d.ts.map +1 -0
  26. package/dist/src/export-strategies/subgraph-exporter.js +17 -0
  27. package/dist/src/export-strategies/subgraph-exporter.js.map +1 -0
  28. package/dist/src/export-strategies/unixfs-exporter.d.ts +11 -0
  29. package/dist/src/export-strategies/unixfs-exporter.d.ts.map +1 -0
  30. package/dist/src/export-strategies/unixfs-exporter.js +18 -0
  31. package/dist/src/export-strategies/unixfs-exporter.js.map +1 -0
  32. package/dist/src/index.d.ts +89 -24
  33. package/dist/src/index.d.ts.map +1 -1
  34. package/dist/src/index.js +38 -95
  35. package/dist/src/index.js.map +1 -1
  36. package/dist/src/traversal-strategies/cid-path.d.ts +16 -0
  37. package/dist/src/traversal-strategies/cid-path.d.ts.map +1 -0
  38. package/dist/src/traversal-strategies/cid-path.js +22 -0
  39. package/dist/src/traversal-strategies/cid-path.js.map +1 -0
  40. package/dist/src/traversal-strategies/graph-search.d.ts +14 -0
  41. package/dist/src/traversal-strategies/graph-search.d.ts.map +1 -0
  42. package/dist/src/traversal-strategies/graph-search.js +19 -0
  43. package/dist/src/traversal-strategies/graph-search.js.map +1 -0
  44. package/dist/src/traversal-strategies/index.d.ts +4 -0
  45. package/dist/src/traversal-strategies/index.d.ts.map +1 -0
  46. package/dist/src/traversal-strategies/index.js +4 -0
  47. package/dist/src/traversal-strategies/index.js.map +1 -0
  48. package/dist/src/traversal-strategies/unixfs-path.d.ts +13 -0
  49. package/dist/src/traversal-strategies/unixfs-path.d.ts.map +1 -0
  50. package/dist/src/traversal-strategies/unixfs-path.js +42 -0
  51. package/dist/src/traversal-strategies/unixfs-path.js.map +1 -0
  52. package/package.json +12 -6
  53. package/src/car.ts +218 -0
  54. package/src/constants.ts +11 -0
  55. package/src/errors.ts +8 -0
  56. package/src/export-strategies/block-exporter.ts +13 -0
  57. package/src/export-strategies/index.ts +3 -0
  58. package/src/export-strategies/subgraph-exporter.ts +18 -0
  59. package/src/export-strategies/unixfs-exporter.ts +22 -0
  60. package/src/index.ts +99 -119
  61. package/src/traversal-strategies/cid-path.ts +29 -0
  62. package/src/traversal-strategies/graph-search.ts +25 -0
  63. package/src/traversal-strategies/index.ts +3 -0
  64. package/src/traversal-strategies/unixfs-path.ts +58 -0
  65. package/dist/typedoc-urls.json +0 -10
@@ -0,0 +1,17 @@
1
+ import { CarWriter } from '@ipld/car';
2
+ import { type CID } from 'multiformats/cid';
3
+ import type { CarComponents, Car as CarInterface, ExportCarOptions } from './index.js';
4
+ import type { PutManyBlocksProgressEvents } from '@helia/interface/blocks';
5
+ import type { CarReader } from '@ipld/car';
6
+ import type { AbortOptions } from '@libp2p/interface';
7
+ import type { ProgressOptions } from 'progress-events';
8
+ export declare class Car implements CarInterface {
9
+ #private;
10
+ private readonly components;
11
+ private readonly log;
12
+ constructor(components: CarComponents, init: any);
13
+ import(reader: Pick<CarReader, 'blocks'>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): Promise<void>;
14
+ export(root: CID | CID[], writer: Pick<CarWriter, 'put' | 'close'>, options?: ExportCarOptions): Promise<void>;
15
+ stream(root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined>;
16
+ }
17
+ //# sourceMappingURL=car.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"car.d.ts","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAIrC,OAAO,EAAE,KAAK,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAM3C,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,YAAY,EAAE,gBAAgB,EAAqC,MAAM,YAAY,CAAA;AACzH,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAC1E,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAU,MAAM,mBAAmB,CAAA;AAC7D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AA2BtD,qBAAa,GAAI,YAAW,YAAY;;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,aAAa,EAAE,IAAI,EAAE,GAAG;IAK3C,MAAM,CAAE,MAAM,EAAE,IAAI,CAAC,SAAS,EAAE,QAAQ,CAAC,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,eAAe,CAAC,2BAA2B,CAAC,GAAG,OAAO,CAAC,IAAI,CAAC;IAOhI,MAAM,CAAE,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;IAoF7G,MAAM,CAAE,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;CA4E5G"}
@@ -0,0 +1,162 @@
1
+ import { CarWriter } from '@ipld/car';
2
+ import drain from 'it-drain';
3
+ import map from 'it-map';
4
+ import { createUnsafe } from 'multiformats/block';
5
+ import {} from 'multiformats/cid';
6
+ import defer from 'p-defer';
7
+ import PQueue from 'p-queue';
8
+ import { DAG_WALK_QUEUE_CONCURRENCY } from './constants.js';
9
+ import { SubgraphExporter } from './export-strategies/subgraph-exporter.js';
10
+ import { GraphSearch } from './traversal-strategies/graph-search.js';
11
+ export class Car {
12
+ components;
13
+ log;
14
+ constructor(components, init) {
15
+ this.components = components;
16
+ this.log = components.logger.forComponent('helia:car');
17
+ }
18
+ async import(reader, options) {
19
+ await drain(this.components.blockstore.putMany(map(reader.blocks(), ({ cid, bytes }) => ({ cid, block: bytes })), options));
20
+ }
21
+ async export(root, writer, options) {
22
+ const deferred = defer();
23
+ const roots = Array.isArray(root) ? root : [root];
24
+ // Create traversal-specific context
25
+ const traversalContext = {
26
+ currentPath: [],
27
+ pathsToTarget: null
28
+ };
29
+ const traversalStrategy = options?.traversal;
30
+ const exportStrategy = options?.exporter ?? new SubgraphExporter();
31
+ // use a queue to walk the DAG instead of recursion so we can traverse very
32
+ // large DAGs
33
+ const queue = new PQueue({
34
+ concurrency: DAG_WALK_QUEUE_CONCURRENCY
35
+ });
36
+ let startedExport = false;
37
+ queue.on('idle', () => {
38
+ if (startedExport) {
39
+ // idle event was called, and started exporting, so we are done.
40
+ deferred.resolve();
41
+ }
42
+ else if (!startedExport && traversalContext.pathsToTarget?.length === roots.length) {
43
+ // queue is idle, we haven't started exporting yet, and we have path(s)
44
+ // to the target(s), so we can start the export process.
45
+ this.log.trace('starting export of blocks to the car file');
46
+ startedExport = true;
47
+ for (const path of traversalContext.pathsToTarget) {
48
+ const targetIndex = path.length - 1;
49
+ const targetCid = path[targetIndex];
50
+ // Process all verification blocks in the path except the target
51
+ path.slice(0, -1).forEach(cid => {
52
+ void queue.add(async () => {
53
+ await this.#exportDagNode({ cid, queue, writer, strategy: exportStrategy, options, recursive: false });
54
+ })
55
+ .catch((err) => {
56
+ this.log.error('error during queue operation - %e', err);
57
+ });
58
+ });
59
+ // Process the target block (which will recursively export its DAG)
60
+ void queue.add(async () => {
61
+ await this.#exportDagNode({ cid: targetCid, queue, writer, strategy: exportStrategy, options });
62
+ })
63
+ .catch((err) => {
64
+ this.log.error('error during queue operation - %e', err);
65
+ });
66
+ }
67
+ }
68
+ else {
69
+ // queue is idle, we haven't started exporting yet, and we don't have
70
+ // path(s) to the target(s), so we can't start the export process.
71
+ // this should not happen without a separate error during traversal, but
72
+ // we'll handle it here anyway.
73
+ this.log.trace('no paths to target, skipping export');
74
+ deferred.reject(new Error('Could not traverse to target CID(s)'));
75
+ }
76
+ });
77
+ queue.on('error', (err) => {
78
+ queue.clear();
79
+ deferred.reject(err);
80
+ });
81
+ for (const root of roots) {
82
+ void queue.add(async () => {
83
+ this.log.trace('traversing dag from %c', root);
84
+ await this.#traverseDagNode({ cid: root, queue, strategy: traversalStrategy ?? new GraphSearch(root), traversalContext, parentPath: [], options });
85
+ })
86
+ .catch((err) => {
87
+ this.log.error('error during queue operation - %e', err);
88
+ });
89
+ }
90
+ // wait for the writer to end
91
+ try {
92
+ await deferred.promise;
93
+ }
94
+ finally {
95
+ await writer.close();
96
+ }
97
+ }
98
+ async *stream(root, options) {
99
+ const { writer, out } = CarWriter.create(root);
100
+ // has to be done async so we write to `writer` and read from `out` at the
101
+ // same time
102
+ this.export(root, writer, options)
103
+ .catch((err) => {
104
+ this.log.error('error during streaming export - %e', err);
105
+ });
106
+ for await (const buf of out) {
107
+ yield buf;
108
+ }
109
+ }
110
+ /**
111
+ * Traverse a DAG and stop when we reach the target node
112
+ */
113
+ async #traverseDagNode({ cid, queue, strategy, traversalContext, parentPath, options }) {
114
+ // if we are traversing, we need to gather path(s) to the target(s)
115
+ const currentPath = [...parentPath, cid];
116
+ if (strategy.isTarget(cid)) {
117
+ traversalContext.pathsToTarget = traversalContext.pathsToTarget ?? [];
118
+ traversalContext.pathsToTarget.push([...currentPath]);
119
+ this.log.trace('found path to target %c', cid);
120
+ return;
121
+ }
122
+ const codec = await this.components.getCodec(cid.code);
123
+ const bytes = await this.components.blockstore.get(cid, options);
124
+ // we are recursively traversing the dag
125
+ const decodedBlock = createUnsafe({ bytes, cid, codec });
126
+ for await (const nextCid of strategy.traverse(cid, decodedBlock)) {
127
+ void queue.add(async () => {
128
+ await this.#traverseDagNode({ cid: nextCid, queue, strategy, traversalContext, parentPath: currentPath ?? [], options });
129
+ })
130
+ .catch((err) => {
131
+ this.log.error('error during traversal queue operation - %e', err);
132
+ });
133
+ }
134
+ }
135
+ /**
136
+ * Use an ExportStrategy to export part of all of a DAG
137
+ */
138
+ async #exportDagNode({ cid, queue, writer, strategy, options, recursive = true }) {
139
+ if (options?.blockFilter?.has(cid.multihash.bytes) === true) {
140
+ return;
141
+ }
142
+ const codec = await this.components.getCodec(cid.code);
143
+ const bytes = await this.components.blockstore.get(cid, options);
144
+ // Mark as processed
145
+ options?.blockFilter?.add(cid.multihash.bytes);
146
+ // Write to CAR
147
+ await writer.put({ cid, bytes });
148
+ if (recursive) {
149
+ // we are recursively traversing the dag
150
+ const decodedBlock = createUnsafe({ bytes, cid, codec });
151
+ for await (const nextCid of strategy.export(cid, decodedBlock)) {
152
+ void queue.add(async () => {
153
+ await this.#exportDagNode({ cid: nextCid, queue, writer, strategy, options });
154
+ })
155
+ .catch((err) => {
156
+ this.log.error('error during export queue operation - %e', err);
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0C,EAAE,GAAG,CAAC,CAAA;gBACjE,CAAC,CAAC,CAAA;YACN,CAAC;QACH,CAAC;IACH,CAAC;CACF"}
@@ -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,9 @@
1
+ export declare class NotUnixFSError extends Error {
2
+ static code: string;
3
+ static message: string;
4
+ static name: string;
5
+ code: string;
6
+ message: string;
7
+ name: string;
8
+ }
9
+ //# sourceMappingURL=errors.d.ts.map
@@ -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,4 @@
1
+ export * from './subgraph-exporter.js';
2
+ export * from './block-exporter.js';
3
+ export * from './unixfs-exporter.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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,4 @@
1
+ export * from './subgraph-exporter.js';
2
+ export * from './block-exporter.js';
3
+ export * from './unixfs-exporter.js';
4
+ //# sourceMappingURL=index.js.map
@@ -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"}
@@ -1,39 +1,56 @@
1
1
  /**
2
2
  * @packageDocumentation
3
3
  *
4
- * `@helia/car` provides `import` and `export` methods to read/write Car files to {@link https://github.com/ipfs/helia Helia}'s blockstore.
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 esoteric DAG walkers can be passed as an init option.
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 { CarWriter } from '@ipld/car'
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
- * // ... helia config
22
- * })
23
- * const fs = unixfs(helia)
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
- * // add some UnixFS data
26
- * const cid = await fs.addBytes(Uint8Array.from([0, 1, 2, 3, 4]))
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 { writer, out } = await CarWriter.create(cid)
45
+ * const out = nodeFs.createWriteStream('example.car')
31
46
  *
32
- * // `out` needs to be directed somewhere, see the @ipld/car docs for more information
33
- * Readable.from(out).pipe(nodeFs.createWriteStream('example.car'))
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
- * // write the DAG behind `cid` into the writer
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 { GetBlockProgressEvents, PutManyBlocksProgressEvents } from '@helia/interface/blocks';
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 a filter is passed it will be used to deduplicate blocks exported in the car file
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?: AbortOptions & ProgressOptions<GetBlockProgressEvents>): AsyncGenerator<Uint8Array>;
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}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2DG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAMrC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,sBAAsB,EAAE,2BAA2B,EAAE,MAAM,yBAAyB,CAAA;AAClG,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AAEtD,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,UAAU,CAAA;IACtB,QAAQ,EAAE,WAAW,CAAA;CACtB;AAED,MAAM,WAAW,gBAAiB,SAAQ,YAAY,EAAE,eAAe,CAAC,sBAAsB,CAAC;IAC7F;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,GAAG;IAClB;;;;;;;;;;;;;;;;;;;OAmBG;IACH,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,S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