|
| 1 | +// This file was automatically generated. DO NOT EDIT. |
| 2 | +// If you have any remark or suggestion do not hesitate to open an issue. |
| 3 | +import { |
| 4 | + API as ParentAPI, |
| 5 | + enrichForPagination, |
| 6 | + urlParams, |
| 7 | + validatePathParam, |
| 8 | + waitForResource, |
| 9 | +} from '../../../bridge' |
| 10 | +import type { Region, WaitForOptions } from '../../../bridge' |
| 11 | +import { PIN_TRANSIENT_STATUSES } from './content.gen' |
| 12 | +import { |
| 13 | + marshalCreatePinByCIDRequest, |
| 14 | + marshalCreatePinByURLRequest, |
| 15 | + marshalCreateVolumeRequest, |
| 16 | + marshalReplacePinRequest, |
| 17 | + marshalUpdateVolumeRequest, |
| 18 | + unmarshalListPinsResponse, |
| 19 | + unmarshalListVolumesResponse, |
| 20 | + unmarshalPin, |
| 21 | + unmarshalReplacePinResponse, |
| 22 | + unmarshalVolume, |
| 23 | +} from './marshalling.gen' |
| 24 | +import type { |
| 25 | + CreatePinByCIDRequest, |
| 26 | + CreatePinByURLRequest, |
| 27 | + CreateVolumeRequest, |
| 28 | + DeletePinRequest, |
| 29 | + DeleteVolumeRequest, |
| 30 | + GetPinRequest, |
| 31 | + GetVolumeRequest, |
| 32 | + ListPinsRequest, |
| 33 | + ListPinsResponse, |
| 34 | + ListVolumesRequest, |
| 35 | + ListVolumesResponse, |
| 36 | + Pin, |
| 37 | + ReplacePinRequest, |
| 38 | + ReplacePinResponse, |
| 39 | + UpdateVolumeRequest, |
| 40 | + Volume, |
| 41 | +} from './types.gen' |
| 42 | + |
| 43 | +const jsonContentHeaders = { |
| 44 | + 'Content-Type': 'application/json; charset=utf-8', |
| 45 | +} |
| 46 | + |
| 47 | +/** IPFS Pinning service API. */ |
| 48 | +export class API extends ParentAPI { |
| 49 | + /** Lists the available regions of the API. */ |
| 50 | + public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw'] |
| 51 | + |
| 52 | + /** |
| 53 | + * Create a new volume from a Project ID. Volume is identified by an ID and |
| 54 | + * used to host pin references. Volume is personal (at least to your |
| 55 | + * organization) even if IPFS blocks and CID are available to anyone. Should |
| 56 | + * be the first command you made because every pin must be attached to a |
| 57 | + * volume. |
| 58 | + * |
| 59 | + * @param request - The request {@link CreateVolumeRequest} |
| 60 | + * @returns A Promise of Volume |
| 61 | + */ |
| 62 | + createVolume = (request: Readonly<CreateVolumeRequest>) => |
| 63 | + this.client.fetch<Volume>( |
| 64 | + { |
| 65 | + body: JSON.stringify( |
| 66 | + marshalCreateVolumeRequest(request, this.client.settings), |
| 67 | + ), |
| 68 | + headers: jsonContentHeaders, |
| 69 | + method: 'POST', |
| 70 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 71 | + 'region', |
| 72 | + request.region ?? this.client.settings.defaultRegion, |
| 73 | + )}/volumes`, |
| 74 | + }, |
| 75 | + unmarshalVolume, |
| 76 | + ) |
| 77 | + |
| 78 | + /** |
| 79 | + * Retrieve information about a specific volume. |
| 80 | + * |
| 81 | + * @param request - The request {@link GetVolumeRequest} |
| 82 | + * @returns A Promise of Volume |
| 83 | + */ |
| 84 | + getVolume = (request: Readonly<GetVolumeRequest>) => |
| 85 | + this.client.fetch<Volume>( |
| 86 | + { |
| 87 | + method: 'GET', |
| 88 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 89 | + 'region', |
| 90 | + request.region ?? this.client.settings.defaultRegion, |
| 91 | + )}/volumes/${validatePathParam('volumeId', request.volumeId)}`, |
| 92 | + }, |
| 93 | + unmarshalVolume, |
| 94 | + ) |
| 95 | + |
| 96 | + protected pageOfListVolumes = (request: Readonly<ListVolumesRequest> = {}) => |
| 97 | + this.client.fetch<ListVolumesResponse>( |
| 98 | + { |
| 99 | + method: 'GET', |
| 100 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 101 | + 'region', |
| 102 | + request.region ?? this.client.settings.defaultRegion, |
| 103 | + )}/volumes`, |
| 104 | + urlParams: urlParams( |
| 105 | + ['order_by', request.orderBy ?? 'created_at_asc'], |
| 106 | + ['page', request.page], |
| 107 | + [ |
| 108 | + 'page_size', |
| 109 | + request.pageSize ?? this.client.settings.defaultPageSize, |
| 110 | + ], |
| 111 | + [ |
| 112 | + 'project_id', |
| 113 | + request.projectId ?? this.client.settings.defaultProjectId, |
| 114 | + ], |
| 115 | + ), |
| 116 | + }, |
| 117 | + unmarshalListVolumesResponse, |
| 118 | + ) |
| 119 | + |
| 120 | + /** |
| 121 | + * Retrieve information about all volumes from a Project ID. |
| 122 | + * |
| 123 | + * @param request - The request {@link ListVolumesRequest} |
| 124 | + * @returns A Promise of ListVolumesResponse |
| 125 | + */ |
| 126 | + listVolumes = (request: Readonly<ListVolumesRequest> = {}) => |
| 127 | + enrichForPagination('volumes', this.pageOfListVolumes, request) |
| 128 | + |
| 129 | + /** |
| 130 | + * Update volume information (tag, name...). |
| 131 | + * |
| 132 | + * @param request - The request {@link UpdateVolumeRequest} |
| 133 | + * @returns A Promise of Volume |
| 134 | + */ |
| 135 | + updateVolume = (request: Readonly<UpdateVolumeRequest>) => |
| 136 | + this.client.fetch<Volume>( |
| 137 | + { |
| 138 | + body: JSON.stringify( |
| 139 | + marshalUpdateVolumeRequest(request, this.client.settings), |
| 140 | + ), |
| 141 | + headers: jsonContentHeaders, |
| 142 | + method: 'PATCH', |
| 143 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 144 | + 'region', |
| 145 | + request.region ?? this.client.settings.defaultRegion, |
| 146 | + )}/volumes/${validatePathParam('volumeId', request.volumeId)}`, |
| 147 | + }, |
| 148 | + unmarshalVolume, |
| 149 | + ) |
| 150 | + |
| 151 | + /** |
| 152 | + * Delete a volume by its ID and every pin attached to this volume. Can take a |
| 153 | + * while, depending of your pinned content. |
| 154 | + * |
| 155 | + * @param request - The request {@link DeleteVolumeRequest} |
| 156 | + */ |
| 157 | + deleteVolume = (request: Readonly<DeleteVolumeRequest>) => |
| 158 | + this.client.fetch<void>({ |
| 159 | + method: 'DELETE', |
| 160 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 161 | + 'region', |
| 162 | + request.region ?? this.client.settings.defaultRegion, |
| 163 | + )}/volumes/${validatePathParam('volumeId', request.volumeId)}`, |
| 164 | + }) |
| 165 | + |
| 166 | + /** |
| 167 | + * Create a pin request. Will fetch and store the content pointed by the |
| 168 | + * provided URL. The content must be available on the public IPFS network. The |
| 169 | + * content (IPFS blocks) will be host by the pinning service until pin |
| 170 | + * deletion. From that point, any other IPFS peer can fetch and host your |
| 171 | + * content: Make sure to pin public or encrypted content. Many pin requests |
| 172 | + * (from different users) can target the same CID. A pin is defined by its ID |
| 173 | + * (UUID), its status (queued, pinning, pinned or failed) and target CID. |
| 174 | + * |
| 175 | + * @param request - The request {@link CreatePinByURLRequest} |
| 176 | + * @returns A Promise of Pin |
| 177 | + */ |
| 178 | + createPinByURL = (request: Readonly<CreatePinByURLRequest>) => |
| 179 | + this.client.fetch<Pin>( |
| 180 | + { |
| 181 | + body: JSON.stringify( |
| 182 | + marshalCreatePinByURLRequest(request, this.client.settings), |
| 183 | + ), |
| 184 | + headers: jsonContentHeaders, |
| 185 | + method: 'POST', |
| 186 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 187 | + 'region', |
| 188 | + request.region ?? this.client.settings.defaultRegion, |
| 189 | + )}/pins/create-by-url`, |
| 190 | + }, |
| 191 | + unmarshalPin, |
| 192 | + ) |
| 193 | + |
| 194 | + /** |
| 195 | + * Create a pin request. Will fetch and store the content pointed by the |
| 196 | + * provided CID. The content must be available on the public IPFS network. The |
| 197 | + * content (IPFS blocks) will be host by the pinning service until pin |
| 198 | + * deletion. From that point, any other IPFS peer can fetch and host your |
| 199 | + * content: Make sure to pin public or encrypted content. Many pin requests |
| 200 | + * (from different users) can target the same CID. A pin is defined by its ID |
| 201 | + * (UUID), its status (queued, pinning, pinned or failed) and target CID. |
| 202 | + * |
| 203 | + * @param request - The request {@link CreatePinByCIDRequest} |
| 204 | + * @returns A Promise of Pin |
| 205 | + */ |
| 206 | + createPinByCID = (request: Readonly<CreatePinByCIDRequest>) => |
| 207 | + this.client.fetch<Pin>( |
| 208 | + { |
| 209 | + body: JSON.stringify( |
| 210 | + marshalCreatePinByCIDRequest(request, this.client.settings), |
| 211 | + ), |
| 212 | + headers: jsonContentHeaders, |
| 213 | + method: 'POST', |
| 214 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 215 | + 'region', |
| 216 | + request.region ?? this.client.settings.defaultRegion, |
| 217 | + )}/pins/create-by-cid`, |
| 218 | + }, |
| 219 | + unmarshalPin, |
| 220 | + ) |
| 221 | + |
| 222 | + replacePin = (request: Readonly<ReplacePinRequest>) => |
| 223 | + this.client.fetch<ReplacePinResponse>( |
| 224 | + { |
| 225 | + body: JSON.stringify( |
| 226 | + marshalReplacePinRequest(request, this.client.settings), |
| 227 | + ), |
| 228 | + headers: jsonContentHeaders, |
| 229 | + method: 'POST', |
| 230 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 231 | + 'region', |
| 232 | + request.region ?? this.client.settings.defaultRegion, |
| 233 | + )}/pins/${validatePathParam('pinId', request.pinId)}/replace`, |
| 234 | + }, |
| 235 | + unmarshalReplacePinResponse, |
| 236 | + ) |
| 237 | + |
| 238 | + /** |
| 239 | + * Retrieve information about the provided pin ID (not the CID): status, last |
| 240 | + * modification, CID. |
| 241 | + * |
| 242 | + * @param request - The request {@link GetPinRequest} |
| 243 | + * @returns A Promise of Pin |
| 244 | + */ |
| 245 | + getPin = (request: Readonly<GetPinRequest>) => |
| 246 | + this.client.fetch<Pin>( |
| 247 | + { |
| 248 | + method: 'GET', |
| 249 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 250 | + 'region', |
| 251 | + request.region ?? this.client.settings.defaultRegion, |
| 252 | + )}/pins/${validatePathParam('pinId', request.pinId)}`, |
| 253 | + urlParams: urlParams(['volume_id', request.volumeId]), |
| 254 | + }, |
| 255 | + unmarshalPin, |
| 256 | + ) |
| 257 | + |
| 258 | + /** |
| 259 | + * Waits for {@link Pin} to be in a final state. |
| 260 | + * |
| 261 | + * @param request - The request {@link GetPinRequest} |
| 262 | + * @param options - The waiting options |
| 263 | + * @returns A Promise of Pin |
| 264 | + */ |
| 265 | + waitForPin = ( |
| 266 | + request: Readonly<GetPinRequest>, |
| 267 | + options?: Readonly<WaitForOptions<Pin>>, |
| 268 | + ) => |
| 269 | + waitForResource( |
| 270 | + options?.stop ?? |
| 271 | + (res => Promise.resolve(!PIN_TRANSIENT_STATUSES.includes(res.status))), |
| 272 | + this.getPin, |
| 273 | + request, |
| 274 | + options, |
| 275 | + ) |
| 276 | + |
| 277 | + protected pageOfListPins = (request: Readonly<ListPinsRequest>) => |
| 278 | + this.client.fetch<ListPinsResponse>( |
| 279 | + { |
| 280 | + method: 'GET', |
| 281 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 282 | + 'region', |
| 283 | + request.region ?? this.client.settings.defaultRegion, |
| 284 | + )}/pins`, |
| 285 | + urlParams: urlParams( |
| 286 | + ['order_by', request.orderBy ?? 'created_at_asc'], |
| 287 | + ['organization_id', request.organizationId], |
| 288 | + ['page', request.page], |
| 289 | + [ |
| 290 | + 'page_size', |
| 291 | + request.pageSize ?? this.client.settings.defaultPageSize, |
| 292 | + ], |
| 293 | + ['project_id', request.projectId], |
| 294 | + ['status', request.status ?? 'unknown_status'], |
| 295 | + ['volume_id', request.volumeId], |
| 296 | + ), |
| 297 | + }, |
| 298 | + unmarshalListPinsResponse, |
| 299 | + ) |
| 300 | + |
| 301 | + /** |
| 302 | + * Retrieve information about all pins into a volume. |
| 303 | + * |
| 304 | + * @param request - The request {@link ListPinsRequest} |
| 305 | + * @returns A Promise of ListPinsResponse |
| 306 | + */ |
| 307 | + listPins = (request: Readonly<ListPinsRequest>) => |
| 308 | + enrichForPagination('pins', this.pageOfListPins, request) |
| 309 | + |
| 310 | + /** |
| 311 | + * Create an unpin request. If the pin was the last to target a specific CID, |
| 312 | + * the content will be erase from storage. The function is indempotent. |
| 313 | + * |
| 314 | + * @param request - The request {@link DeletePinRequest} |
| 315 | + */ |
| 316 | + deletePin = (request: Readonly<DeletePinRequest>) => |
| 317 | + this.client.fetch<void>({ |
| 318 | + method: 'DELETE', |
| 319 | + path: `/ipfs/v1alpha1/regions/${validatePathParam( |
| 320 | + 'region', |
| 321 | + request.region ?? this.client.settings.defaultRegion, |
| 322 | + )}/pins/${validatePathParam('pinId', request.pinId)}`, |
| 323 | + urlParams: urlParams(['volume_id', request.volumeId]), |
| 324 | + }) |
| 325 | +} |
0 commit comments