@ipab/ipfs-store 0.1.0-rc.3 → 0.1.0-rc.5

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/src/store.ts CHANGED
@@ -234,6 +234,11 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
234
234
  retainedBlocks: new Map(),
235
235
  });
236
236
  },
237
+ prepareDirect: async (root, signal) => {
238
+ await this.backend.readBlock(CID.parse(root).toString(), {
239
+ signal: signal ?? this.signal({}),
240
+ });
241
+ },
237
242
  });
238
243
  }
239
244
  return this.retention;
@@ -242,6 +247,28 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
242
247
  this.signal({}).throwIfAborted();
243
248
  this.coordinator().register(owner, roots);
244
249
  }
250
+ registerDirectOwner(owner: string, roots: readonly string[]): void {
251
+ this.signal({}).throwIfAborted();
252
+ this.coordinator().registerDirect(owner, roots);
253
+ }
254
+ async registerOwnerAsync(
255
+ owner: string,
256
+ roots: readonly string[],
257
+ options: IpfsReadOptions = {},
258
+ ): Promise<void> {
259
+ return this.coordinator().registerAsync(owner, roots, this.signal(options));
260
+ }
261
+ async registerDirectOwnerAsync(
262
+ owner: string,
263
+ roots: readonly string[],
264
+ options: IpfsReadOptions = {},
265
+ ): Promise<void> {
266
+ return this.coordinator().registerDirectAsync(
267
+ owner,
268
+ roots,
269
+ this.signal(options),
270
+ );
271
+ }
245
272
  async retain(
246
273
  owner: string,
247
274
  roots: readonly string[],
@@ -249,6 +276,13 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
249
276
  ): Promise<void> {
250
277
  return this.coordinator().retain(owner, roots, this.signal(options));
251
278
  }
279
+ async retainDirect(
280
+ owner: string,
281
+ roots: readonly string[],
282
+ options: IpfsReadOptions = {},
283
+ ): Promise<void> {
284
+ return this.coordinator().retainDirect(owner, roots, this.signal(options));
285
+ }
252
286
  async confirmRetained(
253
287
  owner: string,
254
288
  roots: readonly string[],
@@ -256,6 +290,13 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
256
290
  ): Promise<void> {
257
291
  return this.coordinator().confirm(owner, roots, this.signal(options));
258
292
  }
293
+ async confirmDirectRetained(
294
+ owner: string,
295
+ roots: readonly string[],
296
+ options: IpfsReadOptions = {},
297
+ ): Promise<void> {
298
+ return this.coordinator().confirmDirect(owner, roots, this.signal(options));
299
+ }
259
300
  async recoverOwner(
260
301
  owner: string,
261
302
  roots: readonly string[] | (() => readonly string[]),
@@ -275,18 +316,47 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
275
316
  ): Promise<number> {
276
317
  return this.coordinator().reconcile(owner, roots, this.signal(options));
277
318
  }
319
+ async reconcileDirect(
320
+ owner: string,
321
+ roots: readonly string[] | (() => readonly string[]),
322
+ options: IpfsReadOptions = {},
323
+ ): Promise<number> {
324
+ return this.coordinator().reconcileDirect(
325
+ owner,
326
+ roots,
327
+ this.signal(options),
328
+ );
329
+ }
278
330
  async pin(root: CID | string, options: IpfsReadOptions = {}): Promise<void> {
279
331
  return this.coordinator().pin(root.toString(), this.signal(options));
280
332
  }
333
+ async pinDirect(
334
+ root: CID | string,
335
+ options: IpfsReadOptions = {},
336
+ ): Promise<void> {
337
+ return this.coordinator().pinDirect(root.toString(), this.signal(options));
338
+ }
281
339
  async unpin(
282
340
  root: CID | string,
283
341
  options: IpfsReadOptions = {},
284
342
  ): Promise<void> {
285
343
  return this.coordinator().unpin(root.toString(), this.signal(options));
286
344
  }
345
+ async unpinDirect(
346
+ root: CID | string,
347
+ options: IpfsReadOptions = {},
348
+ ): Promise<void> {
349
+ return this.coordinator().unpinDirect(
350
+ root.toString(),
351
+ this.signal(options),
352
+ );
353
+ }
287
354
  pins(): readonly string[] {
288
355
  return this.coordinator().pins();
289
356
  }
357
+ directPins(): readonly string[] {
358
+ return this.coordinator().directPins();
359
+ }
290
360
  private localMaintenance(): SharedContent {
291
361
  this.signal({}).throwIfAborted();
292
362
  if (!this.supportsRetention || !(this.backend instanceof SharedContent))
@@ -328,9 +398,13 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
328
398
  async usage(options: IpfsReadOptions = {}): Promise<StoreUsage> {
329
399
  const backend = this.localMaintenance();
330
400
  const signal = this.signal(options);
331
- return this.coordinator().maintain(async ({ pinned }) => {
401
+ return this.coordinator().maintain(async ({ pinned, directPinned }) => {
332
402
  const inventory = await backend.inventory(signal);
333
403
  const blocks = await this.localClosure(backend, pinned, signal);
404
+ for (const key of directPinned) {
405
+ const bytes = await backend.readLocalBlock(CID.parse(key), signal);
406
+ blocks.set(key, bytes.byteLength);
407
+ }
334
408
  return {
335
409
  cachedBytes: [...inventory.values()].reduce(
336
410
  (sum, size) => sum + size,
@@ -343,21 +417,28 @@ export class IpfsStore implements IpfsClient, IpfsAccess {
343
417
  async gc(options: IpfsReadOptions = {}): Promise<StoreGcResult> {
344
418
  const backend = this.localMaintenance();
345
419
  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);
420
+ return this.coordinator().maintain(
421
+ async ({ roots, directRoots, staged }) => {
422
+ const inventory = await backend.inventory(signal);
423
+ const marked = await this.localClosure(backend, roots, signal);
424
+ for (const key of directRoots) {
425
+ const bytes = await backend.readLocalBlock(CID.parse(key), signal);
426
+ marked.set(key, bytes.byteLength);
427
+ }
428
+ for (const key of staged) marked.set(key, 0);
429
+ let removedBlocks = 0;
430
+ let reclaimedBytes = 0;
431
+ // Complete verification before any deletion. New publications outside this snapshot survive.
432
+ for (const key of inventory.keys()) {
433
+ signal.throwIfAborted();
434
+ if (marked.has(key)) continue;
435
+ reclaimedBytes += await backend.removeBlock(key, signal);
436
+ removedBlocks++;
437
+ }
438
+ return { removedBlocks, reclaimedBytes };
439
+ },
440
+ signal,
441
+ );
361
442
  }
362
443
  async stageBlock(
363
444
  session: string,