@ipab/ipfs-store 0.1.0-rc.0 → 0.1.0-rc.2
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 +144 -227
- package/dist/configuration.d.ts +2 -6
- package/dist/configuration.d.ts.map +1 -1
- package/dist/configuration.js +3 -10
- package/dist/configuration.js.map +1 -1
- package/dist/errors.d.ts +2 -2
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -3
- package/dist/index.js.map +1 -1
- package/dist/node.d.ts.map +1 -1
- package/dist/node.js +6 -4
- package/dist/node.js.map +1 -1
- package/dist/retention.d.ts +7 -8
- package/dist/retention.d.ts.map +1 -1
- package/dist/retention.js +32 -61
- package/dist/retention.js.map +1 -1
- package/dist/storage.d.ts +3 -0
- package/dist/storage.d.ts.map +1 -1
- package/dist/storage.js +59 -1
- package/dist/storage.js.map +1 -1
- package/dist/store.d.ts +13 -1
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +67 -43
- package/dist/store.js.map +1 -1
- package/package.json +6 -6
- package/src/configuration.ts +10 -24
- package/src/errors.ts +0 -2
- package/src/index.ts +12 -3
- package/src/node.ts +8 -4
- package/src/retention.ts +44 -83
- package/src/storage.ts +69 -1
- package/src/store.ts +94 -58
- package/dist/kubo.d.ts +0 -38
- package/dist/kubo.d.ts.map +0 -1
- package/dist/kubo.js +0 -189
- package/dist/kubo.js.map +0 -1
- package/src/kubo.ts +0 -293
package/src/storage.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { randomUUID } from "node:crypto";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
link,
|
|
4
|
+
lstat,
|
|
5
|
+
mkdir,
|
|
6
|
+
open,
|
|
7
|
+
readdir,
|
|
8
|
+
rm,
|
|
9
|
+
unlink,
|
|
10
|
+
} from "node:fs/promises";
|
|
3
11
|
import { join } from "node:path";
|
|
4
12
|
import { CID } from "multiformats/cid";
|
|
5
13
|
import type { GatewayClient, IpfsClient } from "./index.js";
|
|
@@ -56,6 +64,66 @@ export class SharedContent implements GatewayClient {
|
|
|
56
64
|
await verifyBlock(cid, bytes);
|
|
57
65
|
return bytes;
|
|
58
66
|
}
|
|
67
|
+
async readLocalBlock(cid: CID, signal: AbortSignal): Promise<Uint8Array> {
|
|
68
|
+
signal.throwIfAborted();
|
|
69
|
+
this.lifetime.signal.throwIfAborted();
|
|
70
|
+
try {
|
|
71
|
+
const bytes = await this.local(cid);
|
|
72
|
+
signal.throwIfAborted();
|
|
73
|
+
return bytes;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
if ((error as NodeJS.ErrnoException).code !== "ENOENT") throw error;
|
|
76
|
+
throw new ContentError(
|
|
77
|
+
"missing_block",
|
|
78
|
+
`Missing local content block: ${cid.toString()}`,
|
|
79
|
+
{ cause: error },
|
|
80
|
+
);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
async inventory(signal: AbortSignal): Promise<Map<string, number>> {
|
|
84
|
+
signal.throwIfAborted();
|
|
85
|
+
this.lifetime.signal.throwIfAborted();
|
|
86
|
+
const directory = join(this.directory, "blocks");
|
|
87
|
+
const blocks = new Map<string, number>();
|
|
88
|
+
try {
|
|
89
|
+
const metadata = await lstat(directory);
|
|
90
|
+
if (!metadata.isDirectory() || metadata.isSymbolicLink())
|
|
91
|
+
throw new Error("Invalid shared content directory.");
|
|
92
|
+
} catch (error) {
|
|
93
|
+
if ((error as NodeJS.ErrnoException).code === "ENOENT") return blocks;
|
|
94
|
+
throw error;
|
|
95
|
+
}
|
|
96
|
+
for (const name of await readdir(directory)) {
|
|
97
|
+
signal.throwIfAborted();
|
|
98
|
+
let cid: CID;
|
|
99
|
+
try {
|
|
100
|
+
cid = CID.parse(name);
|
|
101
|
+
} catch {
|
|
102
|
+
// Unknown files and in-flight publications are not Store-owned blocks.
|
|
103
|
+
continue;
|
|
104
|
+
}
|
|
105
|
+
if (name !== cid.toV1().toString()) continue;
|
|
106
|
+
const metadata = await lstat(join(directory, name));
|
|
107
|
+
if (!metadata.isFile() || metadata.isSymbolicLink())
|
|
108
|
+
throw new Error("Invalid shared content block.");
|
|
109
|
+
blocks.set(name, metadata.size);
|
|
110
|
+
}
|
|
111
|
+
return blocks;
|
|
112
|
+
}
|
|
113
|
+
async removeBlock(key: string, signal: AbortSignal): Promise<number> {
|
|
114
|
+
signal.throwIfAborted();
|
|
115
|
+
this.lifetime.signal.throwIfAborted();
|
|
116
|
+
const path = join(
|
|
117
|
+
this.directory,
|
|
118
|
+
"blocks",
|
|
119
|
+
CID.parse(key).toV1().toString(),
|
|
120
|
+
);
|
|
121
|
+
const metadata = await lstat(path);
|
|
122
|
+
if (!metadata.isFile() || metadata.isSymbolicLink())
|
|
123
|
+
throw new Error("Invalid shared content block.");
|
|
124
|
+
await unlink(path);
|
|
125
|
+
return metadata.size;
|
|
126
|
+
}
|
|
59
127
|
put(
|
|
60
128
|
cid: CID,
|
|
61
129
|
bytes: Uint8Array,
|
package/src/store.ts
CHANGED
|
@@ -22,10 +22,7 @@ import {
|
|
|
22
22
|
} from "./dag.js";
|
|
23
23
|
import { SharedContent } from "./storage.js";
|
|
24
24
|
import { ContentError } from "./errors.js";
|
|
25
|
-
import { createHash } from "node:crypto";
|
|
26
|
-
import { homedir } from "node:os";
|
|
27
25
|
import { join } from "node:path";
|
|
28
|
-
import { KuboContent } from "./kubo.js";
|
|
29
26
|
import { Retention } from "./retention.js";
|
|
30
27
|
import {
|
|
31
28
|
validateConfiguration,
|
|
@@ -38,6 +35,14 @@ export interface IpfsReadOptions {
|
|
|
38
35
|
hints?: readonly string[];
|
|
39
36
|
allowGateway?: (url: URL) => boolean;
|
|
40
37
|
}
|
|
38
|
+
export interface StoreUsage {
|
|
39
|
+
cachedBytes: number;
|
|
40
|
+
pinnedBytes: number;
|
|
41
|
+
}
|
|
42
|
+
export interface StoreGcResult {
|
|
43
|
+
removedBlocks: number;
|
|
44
|
+
reclaimedBytes: number;
|
|
45
|
+
}
|
|
41
46
|
export type UnixfsNode = Extract<
|
|
42
47
|
UnixFSEntry,
|
|
43
48
|
{ type: "file" | "raw" | "directory" }
|
|
@@ -51,7 +56,7 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
51
56
|
private readonly retainedBlocks = new Map<string, Uint8Array>();
|
|
52
57
|
private readonly retentionBudget: { bytes: number; limit: number };
|
|
53
58
|
private readonly gateway: GatewayClient | undefined;
|
|
54
|
-
private backend: SharedContent | ContentBlocks
|
|
59
|
+
private backend: SharedContent | ContentBlocks;
|
|
55
60
|
private retention?: Retention;
|
|
56
61
|
private retentionStore?: IpfsStore;
|
|
57
62
|
private coordinated = true;
|
|
@@ -71,19 +76,15 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
71
76
|
)
|
|
72
77
|
throw new Error("Invalid IPFS content capacity.");
|
|
73
78
|
this.retentionBudget = { bytes: 0, limit: this.limits.bytes };
|
|
74
|
-
this.gateway =
|
|
75
|
-
config.
|
|
76
|
-
|
|
77
|
-
: undefined;
|
|
79
|
+
this.gateway = config.gateway
|
|
80
|
+
? createIpfsGatewayClient(config.gateway, { allowPath: true })
|
|
81
|
+
: undefined;
|
|
78
82
|
this.source = this.gateway;
|
|
79
|
-
this.backend =
|
|
80
|
-
config.
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
this.limits.blockBytes,
|
|
85
|
-
config.timeoutMs,
|
|
86
|
-
);
|
|
83
|
+
this.backend = new SharedContent(
|
|
84
|
+
config.dataDir,
|
|
85
|
+
this.source,
|
|
86
|
+
this.limits.blockBytes,
|
|
87
|
+
);
|
|
87
88
|
}
|
|
88
89
|
/** Adapt a caller-owned CAR or block port without reading configuration or owning its close. */
|
|
89
90
|
static fromClient(
|
|
@@ -116,9 +117,9 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
116
117
|
get supportsRetention(): boolean {
|
|
117
118
|
return this.coordinated;
|
|
118
119
|
}
|
|
119
|
-
/** Explicit host read-through port
|
|
120
|
+
/** Explicit host read-through port; publication and retention always stay local. */
|
|
120
121
|
withLocalSource(source: IpfsClient): IpfsStore {
|
|
121
|
-
if (
|
|
122
|
+
if (!this.supportsRetention)
|
|
122
123
|
throw new ContentError(
|
|
123
124
|
"read_only",
|
|
124
125
|
"Only coordinated local stores accept a local source.",
|
|
@@ -157,7 +158,6 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
157
158
|
]);
|
|
158
159
|
}
|
|
159
160
|
private client(options: IpfsReadOptions): IpfsClient {
|
|
160
|
-
if (this.backend instanceof KuboContent) return this.backend;
|
|
161
161
|
if (!options.hints?.length || !options.allowGateway) return this.backend;
|
|
162
162
|
const source = withGatewayHints(
|
|
163
163
|
this.source ?? {
|
|
@@ -222,17 +222,7 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
222
222
|
if (!this.retention) {
|
|
223
223
|
const config = this.configuration;
|
|
224
224
|
const directory =
|
|
225
|
-
config.coordinationDir ??
|
|
226
|
-
(config.backend === "local"
|
|
227
|
-
? join(config.dataDir, "retention")
|
|
228
|
-
: join(
|
|
229
|
-
homedir(),
|
|
230
|
-
".silvermoon.work",
|
|
231
|
-
"retention",
|
|
232
|
-
createHash("sha256").update(config.apiUrl).digest("hex"),
|
|
233
|
-
));
|
|
234
|
-
const kubo =
|
|
235
|
-
this.backend instanceof KuboContent ? this.backend : undefined;
|
|
225
|
+
config.coordinationDir ?? join(config.dataDir, "retention");
|
|
236
226
|
this.retention = new Retention(directory, {
|
|
237
227
|
prepare: async (root, signal) => {
|
|
238
228
|
await prepareContent(this.backend, root, {
|
|
@@ -244,16 +234,6 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
244
234
|
retainedBlocks: new Map(),
|
|
245
235
|
});
|
|
246
236
|
},
|
|
247
|
-
...(kubo
|
|
248
|
-
? {
|
|
249
|
-
status: (root, signal) =>
|
|
250
|
-
kubo.pinStatus(root, signal ? { signal } : {}),
|
|
251
|
-
pin: (root, name, signal) =>
|
|
252
|
-
kubo.pin(root, name, signal ? { signal } : {}),
|
|
253
|
-
unpin: (root, signal) =>
|
|
254
|
-
kubo.unpin(root, signal ? { signal } : {}),
|
|
255
|
-
}
|
|
256
|
-
: {}),
|
|
257
237
|
});
|
|
258
238
|
}
|
|
259
239
|
return this.retention;
|
|
@@ -307,6 +287,78 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
307
287
|
pins(): readonly string[] {
|
|
308
288
|
return this.coordinator().pins();
|
|
309
289
|
}
|
|
290
|
+
private localMaintenance(): SharedContent {
|
|
291
|
+
this.signal({}).throwIfAborted();
|
|
292
|
+
if (!this.supportsRetention || !(this.backend instanceof SharedContent))
|
|
293
|
+
throw new ContentError(
|
|
294
|
+
"unsupported_content",
|
|
295
|
+
"Space queries and garbage collection require a coordinated local Store.",
|
|
296
|
+
);
|
|
297
|
+
return this.backend;
|
|
298
|
+
}
|
|
299
|
+
private async localClosure(
|
|
300
|
+
backend: SharedContent,
|
|
301
|
+
roots: readonly string[],
|
|
302
|
+
signal: AbortSignal,
|
|
303
|
+
): Promise<Map<string, number>> {
|
|
304
|
+
const blocks = new Map<string, number>();
|
|
305
|
+
for (const root of roots) {
|
|
306
|
+
const retainedBlocks = new Map<string, Uint8Array>();
|
|
307
|
+
await prepareContent(
|
|
308
|
+
{
|
|
309
|
+
block: {
|
|
310
|
+
get: (value) => backend.readLocalBlock(CID.parse(value), signal),
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
root,
|
|
314
|
+
{
|
|
315
|
+
signal,
|
|
316
|
+
maxBlockBytes: this.limits.blockBytes,
|
|
317
|
+
maxDagBlocks: this.limits.blocks,
|
|
318
|
+
depth: this.limits.depth,
|
|
319
|
+
retentionBudget: { bytes: 0, limit: this.limits.bytes },
|
|
320
|
+
retainedBlocks,
|
|
321
|
+
},
|
|
322
|
+
);
|
|
323
|
+
for (const [key, bytes] of retainedBlocks)
|
|
324
|
+
blocks.set(key, bytes.byteLength);
|
|
325
|
+
}
|
|
326
|
+
return blocks;
|
|
327
|
+
}
|
|
328
|
+
async usage(options: IpfsReadOptions = {}): Promise<StoreUsage> {
|
|
329
|
+
const backend = this.localMaintenance();
|
|
330
|
+
const signal = this.signal(options);
|
|
331
|
+
return this.coordinator().maintain(async ({ pinned }) => {
|
|
332
|
+
const inventory = await backend.inventory(signal);
|
|
333
|
+
const blocks = await this.localClosure(backend, pinned, signal);
|
|
334
|
+
return {
|
|
335
|
+
cachedBytes: [...inventory.values()].reduce(
|
|
336
|
+
(sum, size) => sum + size,
|
|
337
|
+
0,
|
|
338
|
+
),
|
|
339
|
+
pinnedBytes: [...blocks.values()].reduce((sum, size) => sum + size, 0),
|
|
340
|
+
};
|
|
341
|
+
}, signal);
|
|
342
|
+
}
|
|
343
|
+
async gc(options: IpfsReadOptions = {}): Promise<StoreGcResult> {
|
|
344
|
+
const backend = this.localMaintenance();
|
|
345
|
+
const signal = this.signal(options);
|
|
346
|
+
return this.coordinator().maintain(async ({ roots, staged }) => {
|
|
347
|
+
const inventory = await backend.inventory(signal);
|
|
348
|
+
const marked = await this.localClosure(backend, roots, signal);
|
|
349
|
+
for (const key of staged) marked.set(key, 0);
|
|
350
|
+
let removedBlocks = 0;
|
|
351
|
+
let reclaimedBytes = 0;
|
|
352
|
+
// Complete verification before any deletion. New publications outside this snapshot survive.
|
|
353
|
+
for (const key of inventory.keys()) {
|
|
354
|
+
signal.throwIfAborted();
|
|
355
|
+
if (marked.has(key)) continue;
|
|
356
|
+
reclaimedBytes += await backend.removeBlock(key, signal);
|
|
357
|
+
removedBlocks++;
|
|
358
|
+
}
|
|
359
|
+
return { removedBlocks, reclaimedBytes };
|
|
360
|
+
}, signal);
|
|
361
|
+
}
|
|
310
362
|
async stageBlock(
|
|
311
363
|
session: string,
|
|
312
364
|
cid: CID,
|
|
@@ -314,26 +366,10 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
314
366
|
options: IpfsReadOptions = {},
|
|
315
367
|
): Promise<void> {
|
|
316
368
|
const signal = this.signal(options);
|
|
317
|
-
// Atomic raw-leaf pins protect even a parent arriving before its children.
|
|
318
|
-
// Kubo keys block bytes by multihash; the alias neither reencodes nor duplicates the payload.
|
|
319
|
-
const staged =
|
|
320
|
-
this.backend instanceof KuboContent
|
|
321
|
-
? CID.createV1(0x55, cid.multihash)
|
|
322
|
-
: cid;
|
|
323
369
|
return this.coordinator().stage(
|
|
324
370
|
session,
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
if (this.backend instanceof KuboContent) {
|
|
328
|
-
await this.backend.put(staged, bytes, { signal }, claim);
|
|
329
|
-
if (claim)
|
|
330
|
-
await this.backend.pin(staged.toString(), name, { signal });
|
|
331
|
-
if (cid.code !== staged.code)
|
|
332
|
-
await this.backend.put(cid, bytes, { signal });
|
|
333
|
-
} else {
|
|
334
|
-
await this.backend.put(cid, bytes, { signal });
|
|
335
|
-
}
|
|
336
|
-
},
|
|
371
|
+
cid.toString(),
|
|
372
|
+
() => this.backend.put(cid, bytes, { signal }),
|
|
337
373
|
signal,
|
|
338
374
|
);
|
|
339
375
|
}
|
package/dist/kubo.d.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { CID } from "multiformats/cid";
|
|
2
|
-
export interface PinRecord {
|
|
3
|
-
Type: string;
|
|
4
|
-
Name?: string;
|
|
5
|
-
}
|
|
6
|
-
export declare class KuboContent {
|
|
7
|
-
private readonly apiUrl;
|
|
8
|
-
private readonly blockBytes;
|
|
9
|
-
private readonly timeoutMs;
|
|
10
|
-
private readonly lifetime;
|
|
11
|
-
private readonly pending;
|
|
12
|
-
constructor(apiUrl: string, blockBytes: number, timeoutMs?: number);
|
|
13
|
-
private request;
|
|
14
|
-
private fetch;
|
|
15
|
-
private json;
|
|
16
|
-
readonly block: {
|
|
17
|
-
get: (value: string, options?: {
|
|
18
|
-
signal?: AbortSignal;
|
|
19
|
-
}) => Promise<Uint8Array<ArrayBufferLike>>;
|
|
20
|
-
};
|
|
21
|
-
readBlock(value: string, options?: {
|
|
22
|
-
signal?: AbortSignal;
|
|
23
|
-
}): Promise<Uint8Array>;
|
|
24
|
-
put(cid: CID, bytes: Uint8Array, options?: {
|
|
25
|
-
signal?: AbortSignal;
|
|
26
|
-
}, staged?: boolean): Promise<void>;
|
|
27
|
-
pinStatus(cid: string, options?: {
|
|
28
|
-
signal?: AbortSignal;
|
|
29
|
-
}): Promise<PinRecord | undefined>;
|
|
30
|
-
pin(cid: string, name: string, options?: {
|
|
31
|
-
signal?: AbortSignal;
|
|
32
|
-
}, recursive?: boolean): Promise<void>;
|
|
33
|
-
unpin(cid: string, options?: {
|
|
34
|
-
signal?: AbortSignal;
|
|
35
|
-
}): Promise<void>;
|
|
36
|
-
close(): Promise<void>;
|
|
37
|
-
}
|
|
38
|
-
//# sourceMappingURL=kubo.d.ts.map
|
package/dist/kubo.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kubo.d.ts","sourceRoot":"","sources":["../src/kubo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AAIvC,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AACD,qBAAa,WAAW;IAIpB,OAAO,CAAC,QAAQ,CAAC,MAAM;IACvB,OAAO,CAAC,QAAQ,CAAC,UAAU;IAC3B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAL5B,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAyB;IAClD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+B;gBAEpC,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,SAAS,SAAS;IAErC,OAAO,CAAC,OAAO;YAcD,KAAK;YA+FL,IAAI;IAelB,QAAQ,CAAC,KAAK;qBACC,MAAM,YAAW;YAAE,MAAM,CAAC,EAAE,WAAW,CAAA;SAAE;MAEtD;IACI,SAAS,CACb,KAAK,EAAE,MAAM,EACb,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GACrC,OAAO,CAAC,UAAU,CAAC;IAahB,GAAG,CACP,GAAG,EAAE,GAAG,EACR,KAAK,EAAE,UAAU,EACjB,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,EACtC,MAAM,UAAQ,GACb,OAAO,CAAC,IAAI,CAAC;IAqCV,SAAS,CACb,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GACrC,OAAO,CAAC,SAAS,GAAG,SAAS,CAAC;IAuC3B,GAAG,CACP,GAAG,EAAE,MAAM,EACX,IAAI,EAAE,MAAM,EACZ,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,EACtC,SAAS,UAAO,GACf,OAAO,CAAC,IAAI,CAAC;IAiBV,KAAK,CACT,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAO,GACrC,OAAO,CAAC,IAAI,CAAC;IAmBV,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
package/dist/kubo.js
DELETED
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
import { CID } from "multiformats/cid";
|
|
2
|
-
import { verifyBlock } from "./dag.js";
|
|
3
|
-
import { ContentError } from "./errors.js";
|
|
4
|
-
export class KuboContent {
|
|
5
|
-
apiUrl;
|
|
6
|
-
blockBytes;
|
|
7
|
-
timeoutMs;
|
|
8
|
-
lifetime = new AbortController();
|
|
9
|
-
pending = new Set();
|
|
10
|
-
constructor(apiUrl, blockBytes, timeoutMs = 30_000) {
|
|
11
|
-
this.apiUrl = apiUrl;
|
|
12
|
-
this.blockBytes = blockBytes;
|
|
13
|
-
this.timeoutMs = timeoutMs;
|
|
14
|
-
}
|
|
15
|
-
request(command, args, maxBytes, options = {}, body) {
|
|
16
|
-
const operation = this.fetch(command, args, maxBytes, options, body);
|
|
17
|
-
this.pending.add(operation);
|
|
18
|
-
void operation
|
|
19
|
-
.finally(() => this.pending.delete(operation))
|
|
20
|
-
.catch(() => { });
|
|
21
|
-
return operation;
|
|
22
|
-
}
|
|
23
|
-
async fetch(command, args, maxBytes, options, body) {
|
|
24
|
-
const signal = AbortSignal.any([
|
|
25
|
-
this.lifetime.signal,
|
|
26
|
-
AbortSignal.timeout(this.timeoutMs),
|
|
27
|
-
...(options.signal ? [options.signal] : []),
|
|
28
|
-
]);
|
|
29
|
-
signal.throwIfAborted();
|
|
30
|
-
const url = new URL(this.apiUrl);
|
|
31
|
-
url.pathname = `${url.pathname.replace(/\/(?:api\/v0\/?)?$/, "")}/api/v0/${command}`;
|
|
32
|
-
const headers = {};
|
|
33
|
-
if (url.username || url.password) {
|
|
34
|
-
headers.Authorization = `Basic ${Buffer.from(`${decodeURIComponent(url.username)}:${decodeURIComponent(url.password)}`).toString("base64")}`;
|
|
35
|
-
url.username = "";
|
|
36
|
-
url.password = "";
|
|
37
|
-
}
|
|
38
|
-
for (const [key, value] of Object.entries(args))
|
|
39
|
-
url.searchParams.set(key, value);
|
|
40
|
-
let response;
|
|
41
|
-
try {
|
|
42
|
-
response = await fetch(url, {
|
|
43
|
-
method: "POST",
|
|
44
|
-
...(body ? { body } : {}),
|
|
45
|
-
headers,
|
|
46
|
-
signal,
|
|
47
|
-
redirect: "error",
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
catch {
|
|
51
|
-
signal.throwIfAborted();
|
|
52
|
-
throw new ContentError("rpc_unavailable", `Kubo ${command} RPC is unavailable.`);
|
|
53
|
-
}
|
|
54
|
-
const bound = response.ok ? maxBytes : Math.min(maxBytes, 8192);
|
|
55
|
-
const reader = response.body?.getReader();
|
|
56
|
-
const parts = [];
|
|
57
|
-
let size = 0;
|
|
58
|
-
try {
|
|
59
|
-
if (reader)
|
|
60
|
-
for (;;) {
|
|
61
|
-
const item = await reader.read();
|
|
62
|
-
if (item.done)
|
|
63
|
-
break;
|
|
64
|
-
const chunk = item.value;
|
|
65
|
-
if (!(chunk instanceof Uint8Array))
|
|
66
|
-
throw new ContentError("rpc_failed", "Kubo RPC must return bytes.");
|
|
67
|
-
size += chunk.byteLength;
|
|
68
|
-
if (size > bound)
|
|
69
|
-
throw new ContentError("capacity_exceeded", "Kubo RPC response capacity exceeded.");
|
|
70
|
-
parts.push(chunk);
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
catch (error) {
|
|
74
|
-
signal.throwIfAborted();
|
|
75
|
-
if (error instanceof ContentError)
|
|
76
|
-
throw error;
|
|
77
|
-
throw new ContentError("rpc_unavailable", `Kubo ${command} response was interrupted.`);
|
|
78
|
-
}
|
|
79
|
-
finally {
|
|
80
|
-
await reader?.cancel().catch(() => { });
|
|
81
|
-
reader?.releaseLock();
|
|
82
|
-
}
|
|
83
|
-
signal.throwIfAborted();
|
|
84
|
-
if (!response.ok) {
|
|
85
|
-
if (command === "pin/ls" &&
|
|
86
|
-
response.status === 500 &&
|
|
87
|
-
/is not pinned/i.test(Buffer.concat(parts, size).toString()))
|
|
88
|
-
return Buffer.from('{"Keys":{}}');
|
|
89
|
-
const body = Buffer.concat(parts, size).toString();
|
|
90
|
-
const missing = command === "block/get" &&
|
|
91
|
-
/(?:not found|could not find|blockservice: key not found|block not found|no such block)/i.test(body);
|
|
92
|
-
throw new ContentError(response.status === 404 || missing ? "missing_block" : "rpc_failed", missing
|
|
93
|
-
? "Kubo block is missing."
|
|
94
|
-
: `Kubo ${command} RPC failed (HTTP ${response.status}); operation outcome may be unknown.`);
|
|
95
|
-
}
|
|
96
|
-
return Buffer.concat(parts, size);
|
|
97
|
-
}
|
|
98
|
-
async json(command, args, options, body) {
|
|
99
|
-
const bytes = await this.request(command, args, 1024 * 1024, options, body);
|
|
100
|
-
try {
|
|
101
|
-
return JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
102
|
-
}
|
|
103
|
-
catch {
|
|
104
|
-
throw new ContentError("rpc_failed", `Invalid Kubo ${command} response.`);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
block = {
|
|
108
|
-
get: (value, options = {}) => this.readBlock(value, options),
|
|
109
|
-
};
|
|
110
|
-
async readBlock(value, options = {}) {
|
|
111
|
-
const cid = CID.parse(value);
|
|
112
|
-
if (cid.multihash.code !== 0x12)
|
|
113
|
-
throw new Error("Unsupported content hash.");
|
|
114
|
-
const bytes = await this.request("block/get", { arg: value }, this.blockBytes, options);
|
|
115
|
-
await verifyBlock(cid, bytes);
|
|
116
|
-
return bytes;
|
|
117
|
-
}
|
|
118
|
-
async put(cid, bytes, options = {}, staged = false) {
|
|
119
|
-
if (bytes.byteLength > this.blockBytes)
|
|
120
|
-
throw new ContentError("capacity_exceeded", "Content block capacity exceeded.");
|
|
121
|
-
const snapshot = Uint8Array.from(bytes);
|
|
122
|
-
await verifyBlock(cid, snapshot);
|
|
123
|
-
const format = new Map([
|
|
124
|
-
[0x55, "raw"],
|
|
125
|
-
[0x70, "dag-pb"],
|
|
126
|
-
[0x71, "dag-cbor"],
|
|
127
|
-
]).get(cid.code);
|
|
128
|
-
if (!format)
|
|
129
|
-
throw new ContentError("unsupported_content", "Unsupported Kubo block codec.");
|
|
130
|
-
const body = new FormData();
|
|
131
|
-
body.append("file", new Blob([snapshot]), "block");
|
|
132
|
-
const result = (await this.json("block/put", {
|
|
133
|
-
"cid-codec": format,
|
|
134
|
-
mhtype: "sha2-256",
|
|
135
|
-
mhlen: "32",
|
|
136
|
-
pin: String(staged),
|
|
137
|
-
}, options, body));
|
|
138
|
-
if (!result.Key || !CID.parse(result.Key).toV1().equals(cid.toV1()))
|
|
139
|
-
throw new ContentError("rpc_failed", "Kubo returned a different block CID.");
|
|
140
|
-
}
|
|
141
|
-
async pinStatus(cid, options = {}) {
|
|
142
|
-
const result = await this.json("pin/ls", { arg: cid, type: "all", names: "true" }, options);
|
|
143
|
-
if (!result ||
|
|
144
|
-
typeof result !== "object" ||
|
|
145
|
-
!("Keys" in result) ||
|
|
146
|
-
!result.Keys ||
|
|
147
|
-
typeof result.Keys !== "object" ||
|
|
148
|
-
Array.isArray(result.Keys))
|
|
149
|
-
throw new ContentError("rpc_failed", "Invalid Kubo pin listing.");
|
|
150
|
-
const status = Object.entries(result.Keys).find(([key]) => CID.parse(key).toV1().equals(CID.parse(cid).toV1()))?.[1];
|
|
151
|
-
if (status === undefined)
|
|
152
|
-
return undefined;
|
|
153
|
-
if (!status || typeof status !== "object")
|
|
154
|
-
throw new ContentError("rpc_failed", "Invalid Kubo pin status.");
|
|
155
|
-
let type = "Type" in status ? status.Type : undefined;
|
|
156
|
-
const name = "Name" in status ? status.Name : undefined;
|
|
157
|
-
if (typeof type === "string" && type.startsWith("indirect through ")) {
|
|
158
|
-
try {
|
|
159
|
-
CID.parse(type.slice("indirect through ".length));
|
|
160
|
-
}
|
|
161
|
-
catch {
|
|
162
|
-
throw new ContentError("rpc_failed", "Invalid Kubo pin status.");
|
|
163
|
-
}
|
|
164
|
-
type = "indirect";
|
|
165
|
-
}
|
|
166
|
-
if (typeof type !== "string" ||
|
|
167
|
-
!["recursive", "direct", "indirect"].includes(type) ||
|
|
168
|
-
(name !== undefined && typeof name !== "string"))
|
|
169
|
-
throw new ContentError("rpc_failed", "Invalid Kubo pin status.");
|
|
170
|
-
return { Type: type, ...(name === undefined ? {} : { Name: name }) };
|
|
171
|
-
}
|
|
172
|
-
async pin(cid, name, options = {}, recursive = true) {
|
|
173
|
-
const result = (await this.json("pin/add", { arg: cid, recursive: String(recursive), name }, options));
|
|
174
|
-
if (!Array.isArray(result.Pins) ||
|
|
175
|
-
!result.Pins.some((value) => CID.parse(value).toV1().equals(CID.parse(cid).toV1())))
|
|
176
|
-
throw new ContentError("rpc_failed", "Kubo pin confirmation did not include the requested CID.");
|
|
177
|
-
}
|
|
178
|
-
async unpin(cid, options = {}) {
|
|
179
|
-
const result = (await this.json("pin/rm", { arg: cid, recursive: "true" }, options));
|
|
180
|
-
if (!Array.isArray(result.Pins) ||
|
|
181
|
-
!result.Pins.some((value) => CID.parse(value).toV1().equals(CID.parse(cid).toV1())))
|
|
182
|
-
throw new ContentError("rpc_failed", "Kubo unpin confirmation did not include the requested CID.");
|
|
183
|
-
}
|
|
184
|
-
async close() {
|
|
185
|
-
this.lifetime.abort(new Error("Kubo content store is closed."));
|
|
186
|
-
await Promise.allSettled([...this.pending]);
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
//# sourceMappingURL=kubo.js.map
|
package/dist/kubo.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"kubo.js","sourceRoot":"","sources":["../src/kubo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AACvC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C,MAAM,OAAO,WAAW;IAIH;IACA;IACA;IALF,QAAQ,GAAG,IAAI,eAAe,EAAE,CAAC;IACjC,OAAO,GAAG,IAAI,GAAG,EAAoB,CAAC;IACvD,YACmB,MAAc,EACd,UAAkB,EAClB,YAAY,MAAM;QAFlB,WAAM,GAAN,MAAM,CAAQ;QACd,eAAU,GAAV,UAAU,CAAQ;QAClB,cAAS,GAAT,SAAS,CAAS;IAClC,CAAC;IACI,OAAO,CACb,OAAe,EACf,IAA4B,EAC5B,QAAgB,EAChB,UAAoC,EAAE,EACtC,IAAe;QAEf,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;QACrE,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QAC5B,KA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