@helia/car 4.0.4 → 4.1.0-d43efc7
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 +2 -1
- package/dist/index.min.js.map +7 -0
- package/dist/src/car.d.ts +17 -0
- package/dist/src/car.d.ts.map +1 -0
- package/dist/src/car.js +161 -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 +10 -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 +15 -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 +13 -7
- 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,17 @@
|
|
|
1
|
+
import { CarWriter } from '@ipld/car';
|
|
2
|
+
import type { CarComponents, Car as CarInterface, ExportCarOptions } from './index.js';
|
|
3
|
+
import type { PutManyBlocksProgressEvents } from '@helia/interface/blocks';
|
|
4
|
+
import type { CarReader } from '@ipld/car';
|
|
5
|
+
import type { AbortOptions } from '@libp2p/interface';
|
|
6
|
+
import type { CID } from 'multiformats/cid';
|
|
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;AASrC,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,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAC3C,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"}
|
package/dist/src/car.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
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 defer from 'p-defer';
|
|
6
|
+
import PQueue from 'p-queue';
|
|
7
|
+
import { DAG_WALK_QUEUE_CONCURRENCY } from './constants.js';
|
|
8
|
+
import { SubgraphExporter } from './export-strategies/subgraph-exporter.js';
|
|
9
|
+
import { GraphSearch } from './traversal-strategies/graph-search.js';
|
|
10
|
+
export class Car {
|
|
11
|
+
components;
|
|
12
|
+
log;
|
|
13
|
+
constructor(components, init) {
|
|
14
|
+
this.components = components;
|
|
15
|
+
this.log = components.logger.forComponent('helia:car');
|
|
16
|
+
}
|
|
17
|
+
async import(reader, options) {
|
|
18
|
+
await drain(this.components.blockstore.putMany(map(reader.blocks(), ({ cid, bytes }) => ({ cid, block: bytes })), options));
|
|
19
|
+
}
|
|
20
|
+
async export(root, writer, options) {
|
|
21
|
+
const deferred = defer();
|
|
22
|
+
const roots = Array.isArray(root) ? root : [root];
|
|
23
|
+
// Create traversal-specific context
|
|
24
|
+
const traversalContext = {
|
|
25
|
+
currentPath: [],
|
|
26
|
+
pathsToTarget: null
|
|
27
|
+
};
|
|
28
|
+
const traversalStrategy = options?.traversal;
|
|
29
|
+
const exportStrategy = options?.exporter ?? new SubgraphExporter();
|
|
30
|
+
// use a queue to walk the DAG instead of recursion so we can traverse very
|
|
31
|
+
// large DAGs
|
|
32
|
+
const queue = new PQueue({
|
|
33
|
+
concurrency: DAG_WALK_QUEUE_CONCURRENCY
|
|
34
|
+
});
|
|
35
|
+
let startedExport = false;
|
|
36
|
+
queue.on('idle', () => {
|
|
37
|
+
if (startedExport) {
|
|
38
|
+
// idle event was called, and started exporting, so we are done.
|
|
39
|
+
deferred.resolve();
|
|
40
|
+
}
|
|
41
|
+
else if (!startedExport && traversalContext.pathsToTarget?.length === roots.length) {
|
|
42
|
+
// queue is idle, we haven't started exporting yet, and we have path(s)
|
|
43
|
+
// to the target(s), so we can start the export process.
|
|
44
|
+
this.log.trace('starting export of blocks to the car file');
|
|
45
|
+
startedExport = true;
|
|
46
|
+
for (const path of traversalContext.pathsToTarget) {
|
|
47
|
+
const targetIndex = path.length - 1;
|
|
48
|
+
const targetCid = path[targetIndex];
|
|
49
|
+
// Process all verification blocks in the path except the target
|
|
50
|
+
path.slice(0, -1).forEach(cid => {
|
|
51
|
+
void queue.add(async () => {
|
|
52
|
+
await this.#exportDagNode({ cid, queue, writer, strategy: exportStrategy, options, recursive: false });
|
|
53
|
+
})
|
|
54
|
+
.catch((err) => {
|
|
55
|
+
this.log.error('error during queue operation - %e', err);
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
// Process the target block (which will recursively export its DAG)
|
|
59
|
+
void queue.add(async () => {
|
|
60
|
+
await this.#exportDagNode({ cid: targetCid, queue, writer, strategy: exportStrategy, options });
|
|
61
|
+
})
|
|
62
|
+
.catch((err) => {
|
|
63
|
+
this.log.error('error during queue operation - %e', err);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
// queue is idle, we haven't started exporting yet, and we don't have
|
|
69
|
+
// path(s) to the target(s), so we can't start the export process.
|
|
70
|
+
// this should not happen without a separate error during traversal, but
|
|
71
|
+
// we'll handle it here anyway.
|
|
72
|
+
this.log.trace('no paths to target, skipping export');
|
|
73
|
+
deferred.reject(new Error('Could not traverse to target CID(s)'));
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
queue.on('error', (err) => {
|
|
77
|
+
queue.clear();
|
|
78
|
+
deferred.reject(err);
|
|
79
|
+
});
|
|
80
|
+
for (const root of roots) {
|
|
81
|
+
void queue.add(async () => {
|
|
82
|
+
this.log.trace('traversing dag from %c', root);
|
|
83
|
+
await this.#traverseDagNode({ cid: root, queue, strategy: traversalStrategy ?? new GraphSearch(root), traversalContext, parentPath: [], options });
|
|
84
|
+
})
|
|
85
|
+
.catch((err) => {
|
|
86
|
+
this.log.error('error during queue operation - %e', err);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
// wait for the writer to end
|
|
90
|
+
try {
|
|
91
|
+
await deferred.promise;
|
|
92
|
+
}
|
|
93
|
+
finally {
|
|
94
|
+
await writer.close();
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
async *stream(root, options) {
|
|
98
|
+
const { writer, out } = CarWriter.create(root);
|
|
99
|
+
// has to be done async so we write to `writer` and read from `out` at the
|
|
100
|
+
// same time
|
|
101
|
+
this.export(root, writer, options)
|
|
102
|
+
.catch((err) => {
|
|
103
|
+
this.log.error('error during streaming export - %e', err);
|
|
104
|
+
});
|
|
105
|
+
for await (const buf of out) {
|
|
106
|
+
yield buf;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Traverse a DAG and stop when we reach the target node
|
|
111
|
+
*/
|
|
112
|
+
async #traverseDagNode({ cid, queue, strategy, traversalContext, parentPath, options }) {
|
|
113
|
+
// if we are traversing, we need to gather path(s) to the target(s)
|
|
114
|
+
const currentPath = [...parentPath, cid];
|
|
115
|
+
if (strategy.isTarget(cid)) {
|
|
116
|
+
traversalContext.pathsToTarget = traversalContext.pathsToTarget ?? [];
|
|
117
|
+
traversalContext.pathsToTarget.push([...currentPath]);
|
|
118
|
+
this.log.trace('found path to target %c', cid);
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
const codec = await this.components.getCodec(cid.code);
|
|
122
|
+
const bytes = await this.components.blockstore.get(cid, options);
|
|
123
|
+
// we are recursively traversing the dag
|
|
124
|
+
const decodedBlock = createUnsafe({ bytes, cid, codec });
|
|
125
|
+
for await (const nextCid of strategy.traverse(cid, decodedBlock)) {
|
|
126
|
+
void queue.add(async () => {
|
|
127
|
+
await this.#traverseDagNode({ cid: nextCid, queue, strategy, traversalContext, parentPath: currentPath ?? [], options });
|
|
128
|
+
})
|
|
129
|
+
.catch((err) => {
|
|
130
|
+
this.log.error('error during traversal queue operation - %e', err);
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Use an ExportStrategy to export part of all of a DAG
|
|
136
|
+
*/
|
|
137
|
+
async #exportDagNode({ cid, queue, writer, strategy, options, recursive = true }) {
|
|
138
|
+
if (options?.blockFilter?.has(cid.multihash.bytes) === true) {
|
|
139
|
+
return;
|
|
140
|
+
}
|
|
141
|
+
const codec = await this.components.getCodec(cid.code);
|
|
142
|
+
const bytes = await this.components.blockstore.get(cid, options);
|
|
143
|
+
// Mark as processed
|
|
144
|
+
options?.blockFilter?.add(cid.multihash.bytes);
|
|
145
|
+
// Write to CAR
|
|
146
|
+
await writer.put({ cid, bytes });
|
|
147
|
+
if (recursive) {
|
|
148
|
+
// we are recursively traversing the dag
|
|
149
|
+
const decodedBlock = createUnsafe({ bytes, cid, codec });
|
|
150
|
+
for await (const nextCid of strategy.export(cid, decodedBlock)) {
|
|
151
|
+
void queue.add(async () => {
|
|
152
|
+
await this.#exportDagNode({ cid: nextCid, queue, writer, strategy, options });
|
|
153
|
+
})
|
|
154
|
+
.catch((err) => {
|
|
155
|
+
this.log.error('error during export queue operation - %e', err);
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=car.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1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|
|
|
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 { ExportStrategy } from '../index.js';
|
|
2
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
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,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;;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,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Yields the first block from the first CID and stops
|
|
3
|
+
*/
|
|
4
|
+
export class BlockExporter {
|
|
5
|
+
async *export(cid, block) {
|
|
6
|
+
// don't yield the block, index.ts will add it to the car file and then
|
|
7
|
+
// we're done
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# 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":"AAIA;;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 { ExportStrategy } from '../index.js';
|
|
2
|
+
import type { BlockView } from 'multiformats/block/interface';
|
|
3
|
+
import type { CID } from 'multiformats/cid';
|
|
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,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;;;;;;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,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Traverses the DAG breadth-first starting at the target CID and yields all
|
|
3
|
+
* encountered blocks.
|
|
4
|
+
*
|
|
5
|
+
* Blocks linked to from the target block are traversed using codecs defined in
|
|
6
|
+
* the helia config.
|
|
7
|
+
*/
|
|
8
|
+
export class SubgraphExporter {
|
|
9
|
+
async *export(_cid, block) {
|
|
10
|
+
for await (const [, linkedCid] of block.links()) {
|
|
11
|
+
yield linkedCid;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
//# 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":"AAIA;;;;;;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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