import Foundation
// Companions that collect every page. Cursor listings follow `next_cursor`; offset
// listings walk `limit`/`offset` (default 100) until a short page.
extension RegistrationsAPI {
public func listAll(query: RegistrationListQuery = RegistrationListQuery()) async throws -> [Registration] {
try await Paginator.cursor(fetch: { (cursor: String?) in
var q = query
if let cursor { q.cursor = cursor }
return try await list(query: q)
}, items: \.registrations, next: \.nextCursor)
}
public func listAllActions(query: ListActionsQuery = ListActionsQuery()) async throws -> [RegistrationAction] {
try await Paginator.cursor(fetch: { (cursor: Int?) in
var q = query
if let cursor { q.cursor = cursor }
return try await listActions(query: q)
}, items: \.actions, next: \.nextCursor)
}
}
extension CreditsAPI {
public func ledgerAll(query: LedgerQuery = LedgerQuery()) async throws -> [LedgerEntry] {
try await Paginator.cursor(fetch: { (cursor: Int?) in
var q = query
if let cursor { q.cursor = cursor }
return try await ledger(query: q)
}, items: \.entries, next: \.nextCursor)
}
}
extension DomainsAPI {
public func directoryAll(query: DirectoryQuery = DirectoryQuery()) async throws -> [DirectoryEntry] {
try await Paginator.cursor(fetch: { (cursor: String?) in
var q = query
if let cursor { q.cursor = cursor }
return try await directory(query: q)
}, items: \.entries, next: \.nextCursor)
}
}
extension SupportAPI {
public func listAllThreads(query: ListThreadsQuery = ListThreadsQuery()) async throws -> [SupportThread] {
try await Paginator.cursor(fetch: { (cursor: String?) in
var q = query
if let cursor { q.cursor = cursor }
return try await listThreads(query: q)
}, items: \.threads, next: \.nextCursor)
}
}
extension IPFSAPI {
public func listAllPins(query: ListPinsQuery = ListPinsQuery()) async throws -> [Pin] {
try await Paginator.offset(limit: query.limit, offset: query.offset, fetch: { limit, offset in
var q = query
q.limit = limit
q.offset = offset
return try await listPins(query: q)
}, items: \.pins)
}
public func listAllDomainPins(id: String, query: ListDomainPinsQuery = ListDomainPinsQuery()) async throws -> [DomainPin] {
try await Paginator.offset(limit: query.limit, offset: query.offset, fetch: { limit, offset in
var q = query
q.limit = limit
q.offset = offset
return try await listDomainPins(id: id, query: q)
}, items: \.pins)
}
}