diff --git a/src/CoreApi/AddFileOptions.cs b/src/CoreApi/AddFileOptions.cs index d0129233..71008255 100644 --- a/src/CoreApi/AddFileOptions.cs +++ b/src/CoreApi/AddFileOptions.cs @@ -17,6 +17,14 @@ public class AddFileOptions /// public bool? Pin { get; set; } + /// + /// Optional name to assign to the pin when pinning during add (Kubo v0.37.0+). + /// + /// + /// Forwarded as the 'pin-name' parameter to the add RPC. Effective when pinning is enabled. + /// + public string? PinName { get; set; } + /// /// Chunking algorithm, size-[bytes], rabin-[min]-[avg]-[max] or buzhash. Required: no. /// diff --git a/src/CoreApi/BlocksPinnedProgress.cs b/src/CoreApi/BlocksPinnedProgress.cs new file mode 100644 index 00000000..6e4c7633 --- /dev/null +++ b/src/CoreApi/BlocksPinnedProgress.cs @@ -0,0 +1,12 @@ +namespace Ipfs.CoreApi; + +/// +/// Progress notification for pin/add reporting cumulative blocks pinned. +/// +public record BlocksPinnedProgress +{ + /// + /// The cumulative number of blocks pinned so far. + /// + public int BlocksPinned { get; init; } +} diff --git a/src/CoreApi/IPinApi.cs b/src/CoreApi/IPinApi.cs index 2746ae9e..6c3f6d86 100644 --- a/src/CoreApi/IPinApi.cs +++ b/src/CoreApi/IPinApi.cs @@ -1,6 +1,9 @@ using System.Collections.Generic; +using System.Collections; using System.Threading; using System.Threading.Tasks; +using System.Runtime.CompilerServices; +using System; namespace Ipfs.CoreApi { @@ -17,9 +20,8 @@ public interface IPinApi /// A CID or path to an existing object, such as "QmXarR6rgkQ2fDSHjSY5nM2kuCXKYGViky5nohtwgF65Ec/about" /// or "QmZTR5bcpQD7cFgTorqxZDYaew1Wqgfbd2ud9QqGPAkK2V" /// - /// - /// true to recursively pin links of the object; otherwise, false to only pin - /// the specified object. Default is true. + /// + /// Options for pinning (name and recursion). If null, defaults are used. /// /// /// Is used to stop the task. When cancelled, the is raised. @@ -28,7 +30,17 @@ public interface IPinApi /// A task that represents the asynchronous operation. The task's value /// is a sequence of that were pinned. /// - Task> AddAsync(string path, bool recursive = true, CancellationToken cancel = default); + Task> AddAsync(string path, PinAddOptions options, CancellationToken cancel = default); + + /// + /// Adds an IPFS object to the pinset with progress reporting. + /// + /// The CID or path of the object to pin. + /// Options for pinning (name and recursion). + /// Receives cumulative blocks-pinned updates. + /// Cancellation token. + /// Pinned CIDs on completion. + Task> AddAsync(string path, PinAddOptions options, IProgress progress, CancellationToken cancel = default); /// /// List all the objects pinned to local storage. @@ -36,11 +48,8 @@ public interface IPinApi /// /// Is used to stop the task. When cancelled, the is raised. /// - /// - /// A task that represents the asynchronous operation. The task's value - /// is a sequence of . - /// - Task> ListAsync(CancellationToken cancel = default); + /// An async sequence of . + IAsyncEnumerable ListAsync(CancellationToken cancel = default); /// /// List all the objects pinned to local storage. @@ -51,15 +60,24 @@ public interface IPinApi /// /// Is used to stop the task. When cancelled, the is raised. /// - /// - /// A task that represents the asynchronous operation. The task's value - /// is a sequence of . - /// - Task> ListAsync(PinType type, CancellationToken cancel = default); + /// An async sequence of . + IAsyncEnumerable ListAsync(PinType type, CancellationToken cancel = default); + + /// + /// List pinned objects with advanced options. + /// + /// List options (type filter, names, stream, etc.). + /// Cancellation token. + /// An async sequence of . + IAsyncEnumerable ListAsync(PinListOptions options, CancellationToken cancel = default); /// /// Unpin an object. /// + /// + /// Unpinning does not delete the object's blocks; they become eligible for garbage + /// collection and are removed only when GC runs on the node. + /// /// /// The CID of the object. /// @@ -75,5 +93,7 @@ public interface IPinApi /// is a sequence of that were unpinned. /// Task> RemoveAsync(Cid id, bool recursive = true, CancellationToken cancel = default); + + } } diff --git a/src/CoreApi/PinAddOptions.cs b/src/CoreApi/PinAddOptions.cs new file mode 100644 index 00000000..7101abd3 --- /dev/null +++ b/src/CoreApi/PinAddOptions.cs @@ -0,0 +1,20 @@ +using System.Collections.Generic; + +namespace Ipfs.CoreApi; + +/// +/// Options for pin add. +/// +public record PinAddOptions +{ + /// + /// Optional name for created pin(s). + /// + public string? Name { get; set; } + + /// + /// True to recursively pin links of the object; otherwise, false to only pin the specified object. + /// Default is true. + /// + public bool Recursive { get; set; } = true; +} diff --git a/src/CoreApi/PinListItem.cs b/src/CoreApi/PinListItem.cs new file mode 100644 index 00000000..813bf17f --- /dev/null +++ b/src/CoreApi/PinListItem.cs @@ -0,0 +1,23 @@ +namespace Ipfs.CoreApi; + +/// +/// A unified representation of a pin list entry that works for both +/// streaming and non-streaming list responses. +/// +public record PinListItem +{ + /// + /// The CID of the pinned object. + /// + public Ipfs.Cid Cid { get; init; } = null!; + + /// + /// The pin type (direct, indirect, recursive). + /// + public PinType Type { get; init; } + + /// + /// Optional pin name (present when names are requested and set). + /// + public string? Name { get; init; } +} diff --git a/src/CoreApi/PinListOptions.cs b/src/CoreApi/PinListOptions.cs new file mode 100644 index 00000000..efb43822 --- /dev/null +++ b/src/CoreApi/PinListOptions.cs @@ -0,0 +1,34 @@ +namespace Ipfs.CoreApi; + +/// +/// Options for pin list. +/// +public record PinListOptions +{ + /// + /// The type of pinned keys to list. Can be "direct", "indirect", "recursive", or "all". + /// Default is "all". + /// + public PinType Type { get; set; } = PinType.All; + + /// + /// Output only the CIDs of pins. + /// + public bool Quiet { get; set; } + + /// + /// Limit returned pins to ones with names that contain the value provided (case-sensitive, partial match). + /// Implies Names = true. + /// + public string? Name { get; set; } + + /// + /// Enable streaming of pins as they are discovered. + /// + public bool Stream { get; set; } + + /// + /// Include pin names in the output (slower, disabled by default). + /// + public bool Names { get; set; } +}