1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226 | // Generated by scripts/gen-api.py from spec/openapi.json — do not edit.
import Foundation
// MARK: - Types
/// Values this build does not know decode as `.unrecognized`.
public enum PinMatch: RawRepresentable, Codable, Sendable, Hashable {
case exact
case iexact
case partial
case ipartial
/// A value the server sent that this version of the package does not list.
case unrecognized(String)
/// Every value the spec listed when this file was generated.
public static let known: [PinMatch] = [.exact, .iexact, .partial, .ipartial]
public init(rawValue: String) {
switch rawValue {
case "exact": self = .exact
case "iexact": self = .iexact
case "partial": self = .partial
case "ipartial": self = .ipartial
default: self = .unrecognized(rawValue)
}
}
public var rawValue: String {
switch self {
case .exact: return "exact"
case .iexact: return "iexact"
case .partial: return "partial"
case .ipartial: return "ipartial"
case .unrecognized(let raw): return raw
}
}
public init(from decoder: any Decoder) throws {
self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}
/// Values this build does not know decode as `.unrecognized`.
public enum PinRequestStatus: RawRepresentable, Codable, Sendable, Hashable {
case queued
case pinning
case pinned
case failed
/// A value the server sent that this version of the package does not list.
case unrecognized(String)
/// Every value the spec listed when this file was generated.
public static let known: [PinRequestStatus] = [.queued, .pinning, .pinned, .failed]
public init(rawValue: String) {
switch rawValue {
case "queued": self = .queued
case "pinning": self = .pinning
case "pinned": self = .pinned
case "failed": self = .failed
default: self = .unrecognized(rawValue)
}
}
public var rawValue: String {
switch self {
case .queued: return "queued"
case .pinning: return "pinning"
case .pinned: return "pinned"
case .failed: return "failed"
case .unrecognized(let raw): return raw
}
}
public init(from decoder: any Decoder) throws {
self.init(rawValue: try decoder.singleValueContainer().decode(String.self))
}
public func encode(to encoder: any Encoder) throws {
var container = encoder.singleValueContainer()
try container.encode(rawValue)
}
}
/// Shared by 4 operations.
public struct PinStatus: Codable, Sendable, Hashable {
public var requestid: String
public var status: PinRequestStatus
public var created: String
public var pin: PinSpec
public var delegates: [String]
public var info: [String: String]
public init(requestid: String, status: PinRequestStatus, created: String, pin: PinSpec, delegates: [String], info: [String: String]) {
self.requestid = requestid
self.status = status
self.created = created
self.pin = pin
self.delegates = delegates
self.info = info
}
enum CodingKeys: String, CodingKey {
case requestid
case status
case created
case pin
case delegates
case info
}
}
/// Used by GET /pins.
public struct PinResults: Codable, Sendable, Hashable {
public var count: Int
public var results: [PinStatus]
public init(count: Int, results: [PinStatus]) {
self.count = count
self.results = results
}
enum CodingKeys: String, CodingKey {
case count
case results
}
}
/// Query parameters of `list`; unset fields are omitted.
public struct PinningServiceListQuery: Sendable, Hashable {
/// Comma-separated, at most 10
public var cid: String?
public var name: String?
public var match: PinMatch?
/// Comma-separated of queued|pinning|pinned|failed; absent = pinned only
public var status: String?
public var before: String?
public var after: String?
/// 1–1000, default 10
public var limit: Int?
public init(cid: String? = nil, name: String? = nil, match: PinMatch? = nil, status: String? = nil, before: String? = nil, after: String? = nil, limit: Int? = nil) {
self.cid = cid
self.name = name
self.match = match
self.status = status
self.before = before
self.after = after
self.limit = limit
}
/// The items in spec order.
public var queryItems: [QueryItem] {
var items: [QueryItem] = []
if let value = cid { items.append(QueryItem("cid", value)) }
if let value = name { items.append(QueryItem("name", value)) }
if let value = match { items.append(QueryItem("match", value.rawValue)) }
if let value = status { items.append(QueryItem("status", value)) }
if let value = before { items.append(QueryItem("before", value)) }
if let value = after { items.append(QueryItem("after", value)) }
if let value = limit { items.append(QueryItem("limit", String(value))) }
return items
}
}
// MARK: - Operations
extension IrdOperation {
public static let pins_list = IrdOperation(method: .get, pathTemplate: "/pins", module: "pins", name: "list", security: .keyOrJwt)
public static let pins_add = IrdOperation(method: .post, pathTemplate: "/pins", module: "pins", name: "add", security: .keyOrJwt)
public static let pins_get = IrdOperation(method: .get, pathTemplate: "/pins/{requestid}", module: "pins", name: "get", security: .keyOrJwt)
public static let pins_replace = IrdOperation(method: .post, pathTemplate: "/pins/{requestid}", module: "pins", name: "replace", security: .keyOrJwt)
public static let pins_remove = IrdOperation(method: .delete, pathTemplate: "/pins/{requestid}", module: "pins", name: "remove", security: .keyOrJwt)
static let pinsOperations: [IrdOperation] = [.pins_list, .pins_add, .pins_get, .pins_replace, .pins_remove]
}
/// The `pins` operations (5).
public struct PinsAPI: Sendable {
let client: IrdClient
/// List pin objects (Pinning Service API)
/// Standard [IPFS Pinning Service API 1.0.0](https://ipfs.github.io/pinning-services-api-spec/) listing.
/// `GET /pins` — 200
public func list(query: PinningServiceListQuery = PinningServiceListQuery()) async throws -> PinResults {
try await client.request(.pins_list, query: query.queryItems)
}
/// Add a pin (Pinning Service API)
/// Standard Pinning Service API pin-add: `202` with a PinStatus whose `requestid` you poll. Billing and funding rules are the native surface's (`recurring.ipfs-pin-hourly`); insufficient credits answer `409 INSUFFICIENT_FUNDS` per the spec.
/// `POST /pins` — 202
public func add(body: PinSpec) async throws -> PinStatus {
try await client.request(.pins_add, body: body)
}
/// Pin object (Pinning Service API)
/// One PinStatus by requestid; foreign or deleted pins are 404.
/// `GET /pins/{requestid}` — 200
public func get(requestId: String) async throws -> PinStatus {
try await client.request(.pins_get, params: ["requestid": requestId])
}
/// Replace a pin (Pinning Service API)
/// Replaces the pinned object: the new pin inserts first (shared blocks stay referenced on the node), then the old one starts deleting. `202` with the NEW requestid.
/// `POST /pins/{requestid}` — 202
public func replace(requestId: String, body: PinSpec) async throws -> PinStatus {
try await client.request(.pins_replace, params: ["requestid": requestId], body: body)
}
/// Remove a pin (Pinning Service API)
/// Stops billing immediately and unpins on the node's next poll. `202` with no body per the spec.
/// `DELETE /pins/{requestid}` — 202
public func remove(requestId: String) async throws {
try await client.requestNoContent(.pins_remove, params: ["requestid": requestId])
}
}
extension IrdClient {
public var pins: PinsAPI { PinsAPI(client: self) }
}
|