@helia/car 5.0.1 → 5.1.0-faac4ad3
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 +54 -4
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +4 -4
- package/dist/src/car.d.ts +1 -2
- package/dist/src/car.d.ts.map +1 -1
- package/dist/src/car.js +46 -124
- package/dist/src/car.js.map +1 -1
- package/dist/src/errors.d.ts +8 -0
- package/dist/src/errors.d.ts.map +1 -1
- package/dist/src/errors.js +8 -0
- package/dist/src/errors.js.map +1 -1
- package/dist/src/export-strategies/block-exporter.d.ts +5 -2
- package/dist/src/export-strategies/block-exporter.d.ts.map +1 -1
- package/dist/src/export-strategies/block-exporter.js +9 -3
- package/dist/src/export-strategies/block-exporter.js.map +1 -1
- package/dist/src/export-strategies/subgraph-exporter.d.ts +5 -2
- package/dist/src/export-strategies/subgraph-exporter.d.ts.map +1 -1
- package/dist/src/export-strategies/subgraph-exporter.js +8 -3
- package/dist/src/export-strategies/subgraph-exporter.js.map +1 -1
- package/dist/src/export-strategies/unixfs-exporter.d.ts +10 -4
- package/dist/src/export-strategies/unixfs-exporter.d.ts.map +1 -1
- package/dist/src/export-strategies/unixfs-exporter.js +15 -8
- package/dist/src/export-strategies/unixfs-exporter.js.map +1 -1
- package/dist/src/index.d.ts +64 -12
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/index.js +56 -6
- package/dist/src/index.js.map +1 -1
- package/dist/src/traversal-strategies/cid-path.d.ts +9 -6
- package/dist/src/traversal-strategies/cid-path.d.ts.map +1 -1
- package/dist/src/traversal-strategies/cid-path.js +35 -12
- package/dist/src/traversal-strategies/cid-path.js.map +1 -1
- package/dist/src/traversal-strategies/graph-search.d.ts +15 -7
- package/dist/src/traversal-strategies/graph-search.d.ts.map +1 -1
- package/dist/src/traversal-strategies/graph-search.js +57 -11
- package/dist/src/traversal-strategies/graph-search.js.map +1 -1
- package/dist/src/traversal-strategies/unixfs-path.d.ts +53 -3
- package/dist/src/traversal-strategies/unixfs-path.d.ts.map +1 -1
- package/dist/src/traversal-strategies/unixfs-path.js +70 -30
- package/dist/src/traversal-strategies/unixfs-path.js.map +1 -1
- package/package.json +7 -5
- package/src/car.ts +54 -163
- package/src/errors.ts +10 -0
- package/src/export-strategies/block-exporter.ts +13 -4
- package/src/export-strategies/subgraph-exporter.ts +13 -4
- package/src/export-strategies/unixfs-exporter.ts +20 -9
- package/src/index.ts +66 -15
- package/src/traversal-strategies/cid-path.ts +43 -13
- package/src/traversal-strategies/graph-search.ts +70 -12
- package/src/traversal-strategies/unixfs-path.ts +77 -41
- package/dist/typedoc-urls.json +0 -20
package/dist/src/car.d.ts
CHANGED
|
@@ -5,10 +5,9 @@ import type { AbortOptions } from '@libp2p/interface';
|
|
|
5
5
|
import type { CID } from 'multiformats/cid';
|
|
6
6
|
import type { ProgressOptions } from 'progress-events';
|
|
7
7
|
export declare class Car implements CarInterface {
|
|
8
|
-
#private;
|
|
9
8
|
private readonly components;
|
|
10
9
|
private readonly log;
|
|
11
|
-
constructor(components: CarComponents
|
|
10
|
+
constructor(components: CarComponents);
|
|
12
11
|
import(reader: Pick<CarReader, 'blocks'>, options?: AbortOptions & ProgressOptions<PutManyBlocksProgressEvents>): Promise<void>;
|
|
13
12
|
export(root: CID | CID[], options?: ExportCarOptions): AsyncGenerator<Uint8Array, void, undefined>;
|
|
14
13
|
private _export;
|
package/dist/src/car.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"car.d.ts","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"car.d.ts","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,aAAa,EAAE,GAAG,IAAI,YAAY,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AACtF,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;AAEtD,qBAAa,GAAI,YAAW,YAAY;IACtC,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAe;IAC1C,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAQ;gBAEf,UAAU,EAAE,aAAa;IAKhC,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;IAO9H,MAAM,CAAE,IAAI,EAAE,GAAG,GAAG,GAAG,EAAE,EAAE,OAAO,CAAC,EAAE,gBAAgB,GAAG,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC;YAkC7F,OAAO;CAgEtB"}
|
package/dist/src/car.js
CHANGED
|
@@ -1,17 +1,14 @@
|
|
|
1
1
|
import { CarWriter } from '@ipld/car';
|
|
2
|
-
import { Queue } from '@libp2p/utils';
|
|
3
2
|
import drain from 'it-drain';
|
|
4
3
|
import map from 'it-map';
|
|
5
|
-
import toBuffer from 'it-to-buffer';
|
|
6
|
-
import { createUnsafe } from 'multiformats/block';
|
|
7
4
|
import { raceSignal } from 'race-signal';
|
|
8
|
-
import {
|
|
5
|
+
import { DAG_PB_CODEC_CODE } from "./constants.js";
|
|
9
6
|
import { SubgraphExporter } from './export-strategies/subgraph-exporter.js';
|
|
10
|
-
import {
|
|
7
|
+
import { UnixFSExporter } from './index.js';
|
|
11
8
|
export class Car {
|
|
12
9
|
components;
|
|
13
10
|
log;
|
|
14
|
-
constructor(components
|
|
11
|
+
constructor(components) {
|
|
15
12
|
this.components = components;
|
|
16
13
|
this.log = components.logger.forComponent('helia:car');
|
|
17
14
|
}
|
|
@@ -47,132 +44,57 @@ export class Car {
|
|
|
47
44
|
}
|
|
48
45
|
}
|
|
49
46
|
async _export(root, writer, options) {
|
|
50
|
-
const deferred = Promise.withResolvers();
|
|
51
47
|
const roots = Array.isArray(root) ? root : [root];
|
|
52
|
-
// Create traversal-specific context
|
|
53
|
-
const traversalContext = {
|
|
54
|
-
currentPath: [],
|
|
55
|
-
pathsToTarget: null
|
|
56
|
-
};
|
|
57
48
|
const traversalStrategy = options?.traversal;
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
.catch((err) => {
|
|
84
|
-
this.log.error('error during queue operation - %e', err);
|
|
49
|
+
for (const root of roots) {
|
|
50
|
+
const exportStrategy = options?.exporter ?? (root.code === DAG_PB_CODEC_CODE ? new UnixFSExporter() : new SubgraphExporter());
|
|
51
|
+
let current = root;
|
|
52
|
+
let underRoot = false;
|
|
53
|
+
if (traversalStrategy != null) {
|
|
54
|
+
for await (const { cid, bytes } of traversalStrategy.traverse(current, this.components.blockstore, this.components.getCodec, options)) {
|
|
55
|
+
this.log.trace('next CID on path to %c is %c', root, cid);
|
|
56
|
+
current = cid;
|
|
57
|
+
// the traversal is under the root we are exporting
|
|
58
|
+
if (root.equals(cid)) {
|
|
59
|
+
underRoot = true;
|
|
60
|
+
}
|
|
61
|
+
// include the traversal block if we are under the root CID or it has
|
|
62
|
+
// been explicitly requested
|
|
63
|
+
if (underRoot || options?.includeTraversalBlocks === true) {
|
|
64
|
+
// eslint-disable-next-line max-depth
|
|
65
|
+
if (options?.blockFilter?.has(cid.multihash.bytes) === true) {
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
// mark as processed
|
|
69
|
+
options?.blockFilter?.add(cid.multihash.bytes);
|
|
70
|
+
// store block on path to target
|
|
71
|
+
await writer.put({
|
|
72
|
+
cid,
|
|
73
|
+
bytes
|
|
85
74
|
});
|
|
86
|
-
}
|
|
87
|
-
// Process the target block (which will recursively export its DAG)
|
|
88
|
-
queue.add(async () => {
|
|
89
|
-
await this.#exportDagNode({ cid: targetCid, queue, writer, strategy: exportStrategy, options });
|
|
90
|
-
})
|
|
91
|
-
.catch((err) => {
|
|
92
|
-
this.log.error('error during queue operation - %e', err);
|
|
93
|
-
});
|
|
75
|
+
}
|
|
94
76
|
}
|
|
95
77
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
// we
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
this.log.trace('traversing dag from %c', root);
|
|
112
|
-
await this.#traverseDagNode({ cid: root, queue, strategy: traversalStrategy ?? new GraphSearch(root), traversalContext, parentPath: [], options });
|
|
113
|
-
})
|
|
114
|
-
.catch((err) => {
|
|
115
|
-
this.log.error('error during queue operation - %e', err);
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
// wait for the writer to end
|
|
119
|
-
try {
|
|
120
|
-
await deferred.promise;
|
|
121
|
-
}
|
|
122
|
-
finally {
|
|
123
|
-
await writer.close();
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
/**
|
|
127
|
-
* Traverse a DAG and stop when we reach the target node
|
|
128
|
-
*/
|
|
129
|
-
async #traverseDagNode({ cid, queue, strategy, traversalContext, parentPath, options }) {
|
|
130
|
-
// if we are traversing, we need to gather path(s) to the target(s)
|
|
131
|
-
const currentPath = [...parentPath, cid];
|
|
132
|
-
if (strategy.isTarget(cid)) {
|
|
133
|
-
traversalContext.pathsToTarget = traversalContext.pathsToTarget ?? [];
|
|
134
|
-
traversalContext.pathsToTarget.push([...currentPath]);
|
|
135
|
-
this.log.trace('found path to target %c', cid);
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
const codec = await this.components.getCodec(cid.code);
|
|
139
|
-
const bytes = await toBuffer(this.components.blockstore.get(cid, options));
|
|
140
|
-
// we are recursively traversing the dag
|
|
141
|
-
const decodedBlock = createUnsafe({ bytes, cid, codec });
|
|
142
|
-
for await (const nextCid of strategy.traverse(cid, decodedBlock)) {
|
|
143
|
-
void queue.add(async () => {
|
|
144
|
-
await this.#traverseDagNode({ cid: nextCid, queue, strategy, traversalContext, parentPath: currentPath ?? [], options });
|
|
145
|
-
})
|
|
146
|
-
.catch((err) => {
|
|
147
|
-
this.log.error('error during traversal queue operation - %e', err);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Use an ExportStrategy to export part of all of a DAG
|
|
153
|
-
*/
|
|
154
|
-
async #exportDagNode({ cid, queue, writer, strategy, options, recursive = true }) {
|
|
155
|
-
if (options?.blockFilter?.has(cid.multihash.bytes) === true) {
|
|
156
|
-
return;
|
|
157
|
-
}
|
|
158
|
-
const codec = await this.components.getCodec(cid.code);
|
|
159
|
-
const bytes = await toBuffer(this.components.blockstore.get(cid, options));
|
|
160
|
-
// Mark as processed
|
|
161
|
-
options?.blockFilter?.add(cid.multihash.bytes);
|
|
162
|
-
// Write to CAR
|
|
163
|
-
await writer.put({ cid, bytes });
|
|
164
|
-
if (recursive) {
|
|
165
|
-
// we are recursively traversing the dag
|
|
166
|
-
const decodedBlock = createUnsafe({ bytes, cid, codec });
|
|
167
|
-
for await (const nextCid of strategy.export(cid, decodedBlock)) {
|
|
168
|
-
void queue.add(async () => {
|
|
169
|
-
await this.#exportDagNode({ cid: nextCid, queue, writer, strategy, options });
|
|
170
|
-
})
|
|
171
|
-
.catch((err) => {
|
|
172
|
-
this.log.error('error during export queue operation - %e', err);
|
|
78
|
+
for await (const { cid, bytes } of exportStrategy.export(current, this.components.blockstore, this.components.getCodec, options)) {
|
|
79
|
+
if (options?.blockFilter?.has(cid.multihash.bytes) === true) {
|
|
80
|
+
continue;
|
|
81
|
+
}
|
|
82
|
+
// skip the export target block if we have already included it during
|
|
83
|
+
// traversal
|
|
84
|
+
if (underRoot && cid.equals(current)) {
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
// mark as processed
|
|
88
|
+
options?.blockFilter?.add(cid.multihash.bytes);
|
|
89
|
+
// write to CAR
|
|
90
|
+
await writer.put({
|
|
91
|
+
cid,
|
|
92
|
+
bytes
|
|
173
93
|
});
|
|
174
94
|
}
|
|
175
95
|
}
|
|
96
|
+
// wait for the writer to end
|
|
97
|
+
await writer.close();
|
|
176
98
|
}
|
|
177
99
|
}
|
|
178
100
|
//# sourceMappingURL=car.js.map
|
package/dist/src/car.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"car.js","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,
|
|
1
|
+
{"version":3,"file":"car.js","sourceRoot":"","sources":["../../src/car.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AACrC,OAAO,KAAK,MAAM,UAAU,CAAA;AAC5B,OAAO,GAAG,MAAM,QAAQ,CAAA;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0CAA0C,CAAA;AAC3E,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAQ3C,MAAM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BACf,GAAG;oBACH,KAAK;iBACN,CAAC,CAAA;YACJ,CAAC;QACH,CAAC;QAED,6BAA6B;QAC7B,MAAM,MAAM,CAAC,KAAK,EAAE,CAAA;IACtB,CAAC;CACF"}
|
package/dist/src/errors.d.ts
CHANGED
|
@@ -6,4 +6,12 @@ export declare class NotUnixFSError extends Error {
|
|
|
6
6
|
message: string;
|
|
7
7
|
name: string;
|
|
8
8
|
}
|
|
9
|
+
export declare class NotDescendantError extends Error {
|
|
10
|
+
static name: string;
|
|
11
|
+
name: string;
|
|
12
|
+
}
|
|
13
|
+
export declare class InvalidTraversalError extends Error {
|
|
14
|
+
static name: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}
|
|
9
17
|
//# sourceMappingURL=errors.d.ts.map
|
package/dist/src/errors.d.ts.map
CHANGED
|
@@ -1 +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"}
|
|
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;AAED,qBAAa,kBAAmB,SAAQ,KAAK;IAC3C,MAAM,CAAC,IAAI,SAAuB;IAClC,IAAI,SAAuB;CAC5B;AAED,qBAAa,qBAAsB,SAAQ,KAAK;IAC9C,MAAM,CAAC,IAAI,SAA0B;IACrC,IAAI,SAA0B;CAC/B"}
|
package/dist/src/errors.js
CHANGED
|
@@ -6,4 +6,12 @@ export class NotUnixFSError extends Error {
|
|
|
6
6
|
message = 'Not a UnixFS node';
|
|
7
7
|
name = 'NotUnixFSError';
|
|
8
8
|
}
|
|
9
|
+
export class NotDescendantError extends Error {
|
|
10
|
+
static name = 'NotDescendantError';
|
|
11
|
+
name = 'NotDescendantError';
|
|
12
|
+
}
|
|
13
|
+
export class InvalidTraversalError extends Error {
|
|
14
|
+
static name = 'InvalidTraversalError';
|
|
15
|
+
name = 'InvalidTraversalError';
|
|
16
|
+
}
|
|
9
17
|
//# sourceMappingURL=errors.js.map
|
package/dist/src/errors.js.map
CHANGED
|
@@ -1 +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"}
|
|
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;;AAGzB,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAC3C,MAAM,CAAC,IAAI,GAAG,oBAAoB,CAAA;IAClC,IAAI,GAAG,oBAAoB,CAAA;;AAG7B,MAAM,OAAO,qBAAsB,SAAQ,KAAK;IAC9C,MAAM,CAAC,IAAI,GAAG,uBAAuB,CAAA;IACrC,IAAI,GAAG,uBAAuB,CAAA"}
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import type { ExportStrategy } from '../index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CodecLoader } from '@helia/interface';
|
|
3
|
+
import type { AbortOptions } from '@libp2p/interface';
|
|
4
|
+
import type { Blockstore } from 'interface-blockstore';
|
|
5
|
+
import type { BlockView } from 'multiformats';
|
|
3
6
|
import type { CID } from 'multiformats/cid';
|
|
4
7
|
/**
|
|
5
8
|
* Yields the first block from the first CID and stops
|
|
6
9
|
*/
|
|
7
10
|
export declare class BlockExporter implements ExportStrategy {
|
|
8
|
-
export(cid: CID,
|
|
11
|
+
export(cid: CID, blockstore: Blockstore, getCodec: CodecLoader, options?: AbortOptions): AsyncGenerator<BlockView<unknown, number, number, 0 | 1>, void, undefined>;
|
|
9
12
|
}
|
|
10
13
|
//# sourceMappingURL=block-exporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/block-exporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"block-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/block-exporter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;GAEG;AACH,qBAAa,aAAc,YAAW,cAAc;IAC1C,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC;CAQ7K"}
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import toBuffer from 'it-to-buffer';
|
|
2
|
+
import { createUnsafe } from 'multiformats/block';
|
|
1
3
|
/**
|
|
2
4
|
* Yields the first block from the first CID and stops
|
|
3
5
|
*/
|
|
4
6
|
export class BlockExporter {
|
|
5
|
-
async *export(cid,
|
|
6
|
-
|
|
7
|
-
|
|
7
|
+
async *export(cid, blockstore, getCodec, options) {
|
|
8
|
+
const bytes = await toBuffer(blockstore.get(cid, options));
|
|
9
|
+
yield createUnsafe({
|
|
10
|
+
cid,
|
|
11
|
+
bytes,
|
|
12
|
+
codec: await getCodec(cid.code)
|
|
13
|
+
});
|
|
8
14
|
}
|
|
9
15
|
}
|
|
10
16
|
//# sourceMappingURL=block-exporter.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"block-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/block-exporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"block-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/block-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,cAAc,CAAA;AACnC,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAA;AAQjD;;GAEG;AACH,MAAM,OAAO,aAAa;IACxB,KAAK,CAAC,CAAE,MAAM,CAAE,GAAQ,EAAE,UAAsB,EAAE,QAAqB,EAAE,OAAsB;QAC7F,MAAM,KAAK,GAAG,MAAM,QAAQ,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAA;QAC1D,MAAM,YAAY,CAAC;YACjB,GAAG;YACH,KAAK;YACL,KAAK,EAAE,MAAM,QAAQ,CAAC,GAAG,CAAC,IAAI,CAAC;SAChC,CAAC,CAAA;IACJ,CAAC;CACF"}
|
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import type { ExportStrategy } from '../index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CodecLoader } from '@helia/interface';
|
|
3
|
+
import type { AbortOptions } from '@libp2p/interface';
|
|
4
|
+
import type { Blockstore } from 'interface-blockstore';
|
|
5
|
+
import type { BlockView } from 'multiformats';
|
|
3
6
|
import type { CID } from 'multiformats/cid';
|
|
4
7
|
/**
|
|
5
8
|
* Traverses the DAG breadth-first starting at the target CID and yields all
|
|
@@ -9,6 +12,6 @@ import type { CID } from 'multiformats/cid';
|
|
|
9
12
|
* the helia config.
|
|
10
13
|
*/
|
|
11
14
|
export declare class SubgraphExporter implements ExportStrategy {
|
|
12
|
-
export(
|
|
15
|
+
export(cid: CID, blockstore: Blockstore, getCodec: CodecLoader, options?: AbortOptions): AsyncGenerator<BlockView<unknown, number, number, 0 | 1>, void, undefined>;
|
|
13
16
|
}
|
|
14
17
|
//# sourceMappingURL=subgraph-exporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subgraph-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/subgraph-exporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subgraph-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/subgraph-exporter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;;;;GAMG;AACH,qBAAa,gBAAiB,YAAW,cAAc;IAC7C,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC;CAU7K"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { breadthFirstWalker } from '@helia/utils';
|
|
1
2
|
/**
|
|
2
3
|
* Traverses the DAG breadth-first starting at the target CID and yields all
|
|
3
4
|
* encountered blocks.
|
|
@@ -6,9 +7,13 @@
|
|
|
6
7
|
* the helia config.
|
|
7
8
|
*/
|
|
8
9
|
export class SubgraphExporter {
|
|
9
|
-
async *export(
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
async *export(cid, blockstore, getCodec, options) {
|
|
11
|
+
const walker = breadthFirstWalker({
|
|
12
|
+
blockstore,
|
|
13
|
+
getCodec
|
|
14
|
+
});
|
|
15
|
+
for await (const node of walker.walk(cid, options)) {
|
|
16
|
+
yield node.block;
|
|
12
17
|
}
|
|
13
18
|
}
|
|
14
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"subgraph-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/subgraph-exporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"subgraph-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/subgraph-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAQjD;;;;;;GAMG;AACH,MAAM,OAAO,gBAAgB;IAC3B,KAAK,CAAC,CAAE,MAAM,CAAE,GAAQ,EAAE,UAAsB,EAAE,QAAqB,EAAE,OAAsB;QAC7F,MAAM,MAAM,GAAG,kBAAkB,CAAC;YAChC,UAAU;YACV,QAAQ;SACT,CAAC,CAAA;QAEF,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,CAAC,KAAK,CAAA;QAClB,CAAC;IACH,CAAC;CACF"}
|
|
@@ -1,11 +1,17 @@
|
|
|
1
1
|
import type { ExportStrategy } from '../index.js';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CodecLoader } from '@helia/interface';
|
|
3
|
+
import type { AbortOptions } from '@libp2p/interface';
|
|
4
|
+
import type { Blockstore } from 'interface-blockstore';
|
|
5
|
+
import type { BlockView } from 'multiformats';
|
|
3
6
|
import type { CID } from 'multiformats/cid';
|
|
4
7
|
/**
|
|
5
|
-
*
|
|
6
|
-
*
|
|
8
|
+
* Traverses the DAG depth-first starting at the target CID and yields all
|
|
9
|
+
* encountered blocks.
|
|
10
|
+
*
|
|
11
|
+
* Blocks linked to from the target block are traversed using codecs defined in
|
|
12
|
+
* the helia config.
|
|
7
13
|
*/
|
|
8
14
|
export declare class UnixFSExporter implements ExportStrategy {
|
|
9
|
-
export(cid: CID,
|
|
15
|
+
export(cid: CID, blockstore: Blockstore, getCodec: CodecLoader, options?: AbortOptions): AsyncGenerator<BlockView<unknown, number, number, 0 | 1>, void, undefined>;
|
|
10
16
|
}
|
|
11
17
|
//# sourceMappingURL=unixfs-exporter.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"unixfs-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/unixfs-exporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"unixfs-exporter.d.ts","sourceRoot":"","sources":["../../../src/export-strategies/unixfs-exporter.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACjD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAA;AACrD,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AAC7C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAA;AAE3C;;;;;;GAMG;AACH,qBAAa,cAAe,YAAW,cAAc;IAC3C,MAAM,CAAE,GAAG,EAAE,GAAG,EAAE,UAAU,EAAE,UAAU,EAAE,QAAQ,EAAE,WAAW,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,cAAc,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC;CAc7K"}
|
|
@@ -1,17 +1,24 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { depthFirstWalker } from '@helia/utils';
|
|
2
|
+
import { DAG_PB_CODEC_CODE, RAW_PB_CODEC_CODE } from "../constants.js";
|
|
3
|
+
import { NotUnixFSError } from "../errors.js";
|
|
3
4
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
5
|
+
* Traverses the DAG depth-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.
|
|
6
10
|
*/
|
|
7
11
|
export class UnixFSExporter {
|
|
8
|
-
async *export(cid,
|
|
12
|
+
async *export(cid, blockstore, getCodec, options) {
|
|
9
13
|
if (cid.code !== DAG_PB_CODEC_CODE && cid.code !== RAW_PB_CODEC_CODE) {
|
|
10
14
|
throw new NotUnixFSError('Target CID was not UnixFS - use the SubGraphExporter to export arbitrary graphs');
|
|
11
15
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
16
|
+
const walker = depthFirstWalker({
|
|
17
|
+
blockstore,
|
|
18
|
+
getCodec
|
|
19
|
+
});
|
|
20
|
+
for await (const node of walker.walk(cid, options)) {
|
|
21
|
+
yield node.block;
|
|
15
22
|
}
|
|
16
23
|
}
|
|
17
24
|
}
|
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"unixfs-exporter.js","sourceRoot":"","sources":["../../../src/export-strategies/unixfs-exporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAC/C,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,MAAM,iBAAiB,CAAA;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAQ7C;;;;;;GAMG;AACH,MAAM,OAAO,cAAc;IACzB,KAAK,CAAC,CAAE,MAAM,CAAE,GAAQ,EAAE,UAAsB,EAAE,QAAqB,EAAE,OAAsB;QAC7F,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,MAAM,MAAM,GAAG,gBAAgB,CAAC;YAC9B,UAAU;YACV,QAAQ;SACT,CAAC,CAAA;QAEF,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;YACnD,MAAM,IAAI,CAAC,KAAK,CAAA;QAClB,CAAC;IACH,CAAC;CACF"}
|
package/dist/src/index.d.ts
CHANGED
|
@@ -23,7 +23,9 @@
|
|
|
23
23
|
* const c = car(helia)
|
|
24
24
|
* const out = nodeFs.createWriteStream('example.car')
|
|
25
25
|
*
|
|
26
|
-
* for await (const buf of c.export(cid
|
|
26
|
+
* for await (const buf of c.export(cid, {
|
|
27
|
+
* signal: AbortSignal.timeout(5_000)
|
|
28
|
+
* })) {
|
|
27
29
|
* out.write(buf)
|
|
28
30
|
* }
|
|
29
31
|
*
|
|
@@ -32,6 +34,14 @@
|
|
|
32
34
|
*
|
|
33
35
|
* @example Exporting a part of a UnixFS DAG as a CAR file
|
|
34
36
|
*
|
|
37
|
+
* Here the graph traversal will start at `root` and include the blocks for
|
|
38
|
+
* `root`, `/foo`, `/bar`, and all the blocks that make up `baz.txt`.
|
|
39
|
+
*
|
|
40
|
+
* If there are other files/directories in the UnixFS DAG under `root`, they
|
|
41
|
+
* will not be included.
|
|
42
|
+
*
|
|
43
|
+
* `root` will be the only entry in the CAR file roots.
|
|
44
|
+
*
|
|
35
45
|
* ```typescript
|
|
36
46
|
* import { createHelia } from 'helia'
|
|
37
47
|
* import { car, UnixFSPath } from '@helia/car'
|
|
@@ -39,12 +49,13 @@
|
|
|
39
49
|
* import nodeFs from 'node:fs'
|
|
40
50
|
*
|
|
41
51
|
* const helia = await createHelia()
|
|
42
|
-
* const
|
|
52
|
+
* const root = CID.parse('QmFoo...')
|
|
43
53
|
*
|
|
44
54
|
* const c = car(helia)
|
|
45
55
|
* const out = nodeFs.createWriteStream('example.car')
|
|
46
56
|
*
|
|
47
|
-
* for await (const buf of c.export(
|
|
57
|
+
* for await (const buf of c.export(root, {
|
|
58
|
+
* signal: AbortSignal.timeout(5_000),
|
|
48
59
|
* traversal: new UnixFSPath('/foo/bar/baz.txt')
|
|
49
60
|
* })) {
|
|
50
61
|
* out.write(buf)
|
|
@@ -53,6 +64,43 @@
|
|
|
53
64
|
* out.end()
|
|
54
65
|
* ```
|
|
55
66
|
*
|
|
67
|
+
* @example Including traversal path above the root in a CAR
|
|
68
|
+
*
|
|
69
|
+
* The `includeTraversalBlocks` option will include the traversal blocks in the
|
|
70
|
+
* CAR when they would otherwise be excluded (for example when the traversal
|
|
71
|
+
* starts in a parent of the export root).
|
|
72
|
+
*
|
|
73
|
+
* Here `baz` is the CID for `baz.txt`.
|
|
74
|
+
*
|
|
75
|
+
* The CAR file will include the blocks for `parent`, `/foo`, `/bar`, and
|
|
76
|
+
* `/baz.txt`.
|
|
77
|
+
*
|
|
78
|
+
* `baz` will be the only entry in the CAR file roots.
|
|
79
|
+
*
|
|
80
|
+
* ```typescript
|
|
81
|
+
* import { createHelia } from 'helia'
|
|
82
|
+
* import { car, UnixFSPath } from '@helia/car'
|
|
83
|
+
* import { CID } from 'multiformats/cid'
|
|
84
|
+
* import nodeFs from 'node:fs'
|
|
85
|
+
*
|
|
86
|
+
* const helia = await createHelia()
|
|
87
|
+
* const parent = CID.parse('QmFoo...')
|
|
88
|
+
* const baz = CID.parse('QmBar...')
|
|
89
|
+
*
|
|
90
|
+
* const c = car(helia)
|
|
91
|
+
* const out = nodeFs.createWriteStream('example.car')
|
|
92
|
+
*
|
|
93
|
+
* for await (const buf of c.export(baz, {
|
|
94
|
+
* signal: AbortSignal.timeout(5_000),
|
|
95
|
+
* traversal: new UnixFSPath(parent, '/foo/bar/baz.txt'),
|
|
96
|
+
* includeTraversalBlocks: true
|
|
97
|
+
* })) {
|
|
98
|
+
* out.write(buf)
|
|
99
|
+
* }
|
|
100
|
+
*
|
|
101
|
+
* out.end()
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
56
104
|
* @example Importing all blocks from a CAR file
|
|
57
105
|
*
|
|
58
106
|
* ```typescript
|
|
@@ -72,7 +120,9 @@
|
|
|
72
120
|
* const reader = await CarReader.fromIterable(inStream)
|
|
73
121
|
*
|
|
74
122
|
* const c = car(helia)
|
|
75
|
-
* await c.import(reader
|
|
123
|
+
* await c.import(reader, {
|
|
124
|
+
* signal: AbortSignal.timeout(5_000)
|
|
125
|
+
* })
|
|
76
126
|
* ```
|
|
77
127
|
*/
|
|
78
128
|
import type { CodecLoader } from '@helia/interface';
|
|
@@ -98,12 +148,7 @@ export interface TraversalStrategy {
|
|
|
98
148
|
/**
|
|
99
149
|
* Traverse the DAG and yield the next CID to traverse
|
|
100
150
|
*/
|
|
101
|
-
traverse
|
|
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;
|
|
151
|
+
traverse(root: CID, blockstore: Blockstore, getCodec: CodecLoader, options?: AbortOptions): AsyncGenerator<BlockView<unknown, number, number, 0 | 1>, void, undefined>;
|
|
107
152
|
}
|
|
108
153
|
/**
|
|
109
154
|
* Interface for different export strategies.
|
|
@@ -115,7 +160,7 @@ export interface ExportStrategy {
|
|
|
115
160
|
/**
|
|
116
161
|
* Export the DAG and yield the next CID to traverse
|
|
117
162
|
*/
|
|
118
|
-
export
|
|
163
|
+
export(cid: CID, blockstore: Blockstore, getCodec: CodecLoader, options?: AbortOptions): AsyncGenerator<BlockView<unknown, number, number, 0 | 1>, void, undefined>;
|
|
119
164
|
}
|
|
120
165
|
export * from './export-strategies/index.js';
|
|
121
166
|
export * from './traversal-strategies/index.js';
|
|
@@ -141,6 +186,13 @@ export interface ExportCarOptions extends AbortOptions, ProgressOptions<GetBlock
|
|
|
141
186
|
* blocks included in the exported car file. (e.g. https://specs.ipfs.tech/http-gateways/trustless-gateway/#dag-scope-request-query-parameter)
|
|
142
187
|
*/
|
|
143
188
|
exporter?: ExportStrategy;
|
|
189
|
+
/**
|
|
190
|
+
* If `true`, and the traversal strategy starts above the root, include the
|
|
191
|
+
* traversed blocks in the CAR file before the root and subsequent blocks
|
|
192
|
+
*
|
|
193
|
+
* @default false
|
|
194
|
+
*/
|
|
195
|
+
includeTraversalBlocks?: boolean;
|
|
144
196
|
}
|
|
145
197
|
/**
|
|
146
198
|
* The Car interface provides operations for importing and exporting Car files
|
|
@@ -193,5 +245,5 @@ export interface Car {
|
|
|
193
245
|
/**
|
|
194
246
|
* Create a {@link Car} instance for use with {@link https://github.com/ipfs/helia Helia}
|
|
195
247
|
*/
|
|
196
|
-
export declare function car(helia: CarComponents
|
|
248
|
+
export declare function car(helia: CarComponents): Car;
|
|
197
249
|
//# sourceMappingURL=index.d.ts.map
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8HG;AAGH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA;AACnD,OAAO,KAAK,EAAE,2BAA2B,EAAE,sBAAsB,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAA;AACnH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,WAAW,CAAA;AAC1C,OAAO,KAAK,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACtE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AAC3C,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,W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