@ipab/ipfs-store 0.1.0-rc.6 → 0.1.0-rc.7
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/dist/configuration.d.ts +4 -0
- package/dist/configuration.d.ts.map +1 -1
- package/dist/configuration.js +19 -1
- package/dist/configuration.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/retention.d.ts +49 -14
- package/dist/retention.d.ts.map +1 -1
- package/dist/retention.js +528 -258
- package/dist/retention.js.map +1 -1
- package/dist/store.d.ts +3 -0
- package/dist/store.d.ts.map +1 -1
- package/dist/store.js +37 -25
- package/dist/store.js.map +1 -1
- package/package.json +1 -1
- package/src/configuration.ts +32 -1
- package/src/index.ts +4 -0
- package/src/retention.ts +741 -273
- package/src/store.ts +73 -22
package/src/store.ts
CHANGED
|
@@ -23,13 +23,26 @@ import {
|
|
|
23
23
|
import { SharedContent } from "./storage.js";
|
|
24
24
|
import { ContentError } from "./errors.js";
|
|
25
25
|
import { join } from "node:path";
|
|
26
|
-
import {
|
|
26
|
+
import {
|
|
27
|
+
Retention,
|
|
28
|
+
type RetentionPort,
|
|
29
|
+
type RetentionCoordinationEvent,
|
|
30
|
+
type RetentionOptions,
|
|
31
|
+
type RetentionSqlEvent,
|
|
32
|
+
type RetentionTelemetry,
|
|
33
|
+
} from "./retention.js";
|
|
27
34
|
import {
|
|
28
35
|
validateConfiguration,
|
|
29
36
|
type IpfsStoreOptions,
|
|
30
37
|
type StoreConfiguration,
|
|
31
38
|
} from "./configuration.js";
|
|
32
39
|
export type { IpfsStoreOptions, StoreConfiguration } from "./configuration.js";
|
|
40
|
+
export type {
|
|
41
|
+
RetentionCoordinationEvent,
|
|
42
|
+
RetentionOptions,
|
|
43
|
+
RetentionSqlEvent,
|
|
44
|
+
RetentionTelemetry,
|
|
45
|
+
};
|
|
33
46
|
export interface IpfsReadOptions {
|
|
34
47
|
signal?: AbortSignal;
|
|
35
48
|
hints?: readonly string[];
|
|
@@ -138,6 +151,7 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
138
151
|
source,
|
|
139
152
|
this.limits.blockBytes,
|
|
140
153
|
);
|
|
154
|
+
store.retentionStore = this.retentionStore ?? this;
|
|
141
155
|
return store;
|
|
142
156
|
}
|
|
143
157
|
/** Independent reader budget/lifetime; closing it never closes the shared backing store. */
|
|
@@ -218,6 +232,25 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
218
232
|
): Promise<void> {
|
|
219
233
|
await this.backend.put(cid, bytes, { signal: this.signal(options) });
|
|
220
234
|
}
|
|
235
|
+
private retentionPort(): RetentionPort {
|
|
236
|
+
return {
|
|
237
|
+
prepare: async (root, signal) => {
|
|
238
|
+
await prepareContent(this.backend, root, {
|
|
239
|
+
signal: signal ?? this.signal({}),
|
|
240
|
+
maxBlockBytes: this.limits.blockBytes,
|
|
241
|
+
maxDagBlocks: this.limits.blocks,
|
|
242
|
+
depth: this.limits.depth,
|
|
243
|
+
retentionBudget: { bytes: 0, limit: this.limits.bytes },
|
|
244
|
+
retainedBlocks: new Map(),
|
|
245
|
+
});
|
|
246
|
+
},
|
|
247
|
+
prepareDirect: async (root, signal) => {
|
|
248
|
+
await this.backend.readBlock(CID.parse(root).toString(), {
|
|
249
|
+
signal: signal ?? this.signal({}),
|
|
250
|
+
});
|
|
251
|
+
},
|
|
252
|
+
};
|
|
253
|
+
}
|
|
221
254
|
private coordinator(): Retention {
|
|
222
255
|
this.signal({}).throwIfAborted();
|
|
223
256
|
if (!this.supportsRetention)
|
|
@@ -230,22 +263,14 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
230
263
|
const config = this.configuration;
|
|
231
264
|
const directory =
|
|
232
265
|
config.coordinationDir ?? join(config.dataDir, "retention");
|
|
233
|
-
this.retention = new Retention(directory, {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
retainedBlocks: new Map(),
|
|
242
|
-
});
|
|
243
|
-
},
|
|
244
|
-
prepareDirect: async (root, signal) => {
|
|
245
|
-
await this.backend.readBlock(CID.parse(root).toString(), {
|
|
246
|
-
signal: signal ?? this.signal({}),
|
|
247
|
-
});
|
|
248
|
-
},
|
|
266
|
+
this.retention = new Retention(directory, this.retentionPort(), {
|
|
267
|
+
...(config.singleProcessCoordination !== undefined
|
|
268
|
+
? { singleProcessCoordination: config.singleProcessCoordination }
|
|
269
|
+
: {}),
|
|
270
|
+
...(config.onCoordinationEvent
|
|
271
|
+
? { onCoordinationEvent: config.onCoordinationEvent }
|
|
272
|
+
: {}),
|
|
273
|
+
...(config.onSqlEvent ? { onSqlEvent: config.onSqlEvent } : {}),
|
|
249
274
|
});
|
|
250
275
|
}
|
|
251
276
|
return this.retention;
|
|
@@ -281,14 +306,24 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
281
306
|
roots: readonly string[],
|
|
282
307
|
options: IpfsReadOptions = {},
|
|
283
308
|
): Promise<void> {
|
|
284
|
-
return this.coordinator().retain(
|
|
309
|
+
return this.coordinator().retain(
|
|
310
|
+
owner,
|
|
311
|
+
roots,
|
|
312
|
+
this.signal(options),
|
|
313
|
+
this.retentionPort(),
|
|
314
|
+
);
|
|
285
315
|
}
|
|
286
316
|
async retainDirect(
|
|
287
317
|
owner: string,
|
|
288
318
|
roots: readonly string[],
|
|
289
319
|
options: IpfsReadOptions = {},
|
|
290
320
|
): Promise<void> {
|
|
291
|
-
return this.coordinator().retainDirect(
|
|
321
|
+
return this.coordinator().retainDirect(
|
|
322
|
+
owner,
|
|
323
|
+
roots,
|
|
324
|
+
this.signal(options),
|
|
325
|
+
this.retentionPort(),
|
|
326
|
+
);
|
|
292
327
|
}
|
|
293
328
|
async confirmRetained(
|
|
294
329
|
owner: string,
|
|
@@ -321,7 +356,12 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
321
356
|
roots: readonly string[] | (() => readonly string[]),
|
|
322
357
|
options: IpfsReadOptions = {},
|
|
323
358
|
): Promise<number> {
|
|
324
|
-
return this.coordinator().reconcile(
|
|
359
|
+
return this.coordinator().reconcile(
|
|
360
|
+
owner,
|
|
361
|
+
roots,
|
|
362
|
+
this.signal(options),
|
|
363
|
+
this.retentionPort(),
|
|
364
|
+
);
|
|
325
365
|
}
|
|
326
366
|
async reconcileDirect(
|
|
327
367
|
owner: string,
|
|
@@ -332,16 +372,25 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
332
372
|
owner,
|
|
333
373
|
roots,
|
|
334
374
|
this.signal(options),
|
|
375
|
+
this.retentionPort(),
|
|
335
376
|
);
|
|
336
377
|
}
|
|
337
378
|
async pin(root: CID | string, options: IpfsReadOptions = {}): Promise<void> {
|
|
338
|
-
return this.coordinator().pin(
|
|
379
|
+
return this.coordinator().pin(
|
|
380
|
+
root.toString(),
|
|
381
|
+
this.signal(options),
|
|
382
|
+
this.retentionPort(),
|
|
383
|
+
);
|
|
339
384
|
}
|
|
340
385
|
async pinDirect(
|
|
341
386
|
root: CID | string,
|
|
342
387
|
options: IpfsReadOptions = {},
|
|
343
388
|
): Promise<void> {
|
|
344
|
-
return this.coordinator().pinDirect(
|
|
389
|
+
return this.coordinator().pinDirect(
|
|
390
|
+
root.toString(),
|
|
391
|
+
this.signal(options),
|
|
392
|
+
this.retentionPort(),
|
|
393
|
+
);
|
|
345
394
|
}
|
|
346
395
|
async unpin(
|
|
347
396
|
root: CID | string,
|
|
@@ -487,6 +536,7 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
487
536
|
root.toString(),
|
|
488
537
|
owner,
|
|
489
538
|
this.signal(options),
|
|
539
|
+
this.retentionPort(),
|
|
490
540
|
);
|
|
491
541
|
}
|
|
492
542
|
async importBlocks(
|
|
@@ -507,6 +557,7 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
|
|
|
507
557
|
owner,
|
|
508
558
|
signal,
|
|
509
559
|
options.onRetained,
|
|
560
|
+
this.retentionPort(),
|
|
510
561
|
);
|
|
511
562
|
}
|
|
512
563
|
async discardImport(
|