From 5675a4ba2c10ccdf33084fea8995da967a418ee3 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Tue, 29 Aug 2023 15:19:57 +0000 Subject: [PATCH] feat: update generated APIs --- .../clients/src/api/ipfs/v1alpha1/api.gen.ts | 110 +++++++++++++++++- .../src/api/ipfs/v1alpha1/content.gen.ts | 5 +- .../src/api/ipfs/v1alpha1/index.gen.ts | 9 ++ .../src/api/ipfs/v1alpha1/marshalling.gen.ts | 54 +++++++++ .../src/api/ipfs/v1alpha1/types.gen.ts | 79 +++++++++++++ 5 files changed, 255 insertions(+), 2 deletions(-) diff --git a/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts index c8a8a43dc..448676cd4 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/api.gen.ts @@ -8,34 +8,45 @@ import { waitForResource, } from '../../../bridge' import type { Region, WaitForOptions } from '../../../bridge' -import { PIN_TRANSIENT_STATUSES } from './content.gen' +import { NAME_TRANSIENT_STATUSES, PIN_TRANSIENT_STATUSES } from './content.gen' import { + marshalCreateNameRequest, marshalCreatePinByCIDRequest, marshalCreatePinByURLRequest, marshalCreateVolumeRequest, marshalReplacePinRequest, + marshalUpdateNameRequest, marshalUpdateVolumeRequest, + unmarshalListNamesResponse, unmarshalListPinsResponse, unmarshalListVolumesResponse, + unmarshalName, unmarshalPin, unmarshalReplacePinResponse, unmarshalVolume, } from './marshalling.gen' import type { + CreateNameRequest, CreatePinByCIDRequest, CreatePinByURLRequest, CreateVolumeRequest, + DeleteNameRequest, DeletePinRequest, DeleteVolumeRequest, + GetNameRequest, GetPinRequest, GetVolumeRequest, + ListNamesRequest, + ListNamesResponse, ListPinsRequest, ListPinsResponse, ListVolumesRequest, ListVolumesResponse, + Name, Pin, ReplacePinRequest, ReplacePinResponse, + UpdateNameRequest, UpdateVolumeRequest, Volume, } from './types.gen' @@ -327,4 +338,101 @@ export class API extends ParentAPI { )}/pins/${validatePathParam('pinId', request.pinId)}`, urlParams: urlParams(['volume_id', request.volumeId]), }) + + createName = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateNameRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names`, + }, + unmarshalName, + ) + + getName = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/${validatePathParam('nameId', request.nameId)}`, + }, + unmarshalName, + ) + + /** + * Waits for {@link Name} to be in a final state. + * + * @param request - The request {@link GetNameRequest} + * @param options - The waiting options + * @returns A Promise of Name + */ + waitForName = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => Promise.resolve(!NAME_TRANSIENT_STATUSES.includes(res.status))), + this.getName, + request, + options, + ) + + deleteName = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/${validatePathParam('nameId', request.nameId)}`, + }) + + protected pageOfListNames = (request: Readonly = {}) => + this.client.fetch( + { + method: 'GET', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names`, + urlParams: urlParams( + ['order_by', request.orderBy ?? 'created_at_asc'], + ['organization_id', request.organizationId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['project_id', request.projectId], + ), + }, + unmarshalListNamesResponse, + ) + + listNames = (request: Readonly = {}) => + enrichForPagination('names', this.pageOfListNames, request) + + updateName = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateNameRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/ipfs/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/names/${validatePathParam('nameId', request.nameId)}`, + }, + unmarshalName, + ) } diff --git a/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts index 0e003479e..703dee887 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/content.gen.ts @@ -1,6 +1,9 @@ // This file was automatically generated. DO NOT EDIT. // If you have any remark or suggestion do not hesitate to open an issue. -import type { PinStatus } from './types.gen' +import type { NameStatus, PinStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link NameStatus}. */ +export const NAME_TRANSIENT_STATUSES: NameStatus[] = ['queued', 'publishing'] /** Lists transient statutes of the enum {@link PinStatus}. */ export const PIN_TRANSIENT_STATUSES: PinStatus[] = ['queued', 'pinning'] diff --git a/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts index 75f4571bb..24313d7bf 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/index.gen.ts @@ -3,19 +3,27 @@ export { API } from './api.gen' export * from './content.gen' export type { + CreateNameRequest, CreatePinByCIDRequest, CreatePinByURLRequest, CreateVolumeRequest, + DeleteNameRequest, DeletePinRequest, DeleteVolumeRequest, + GetNameRequest, GetPinRequest, GetVolumeRequest, + ListNamesRequest, + ListNamesRequestOrderBy, + ListNamesResponse, ListPinsRequest, ListPinsRequestOrderBy, ListPinsResponse, ListVolumesRequest, ListVolumesRequestOrderBy, ListVolumesResponse, + Name, + NameStatus, Pin, PinCID, PinCIDMeta, @@ -25,6 +33,7 @@ export type { PinStatus, ReplacePinRequest, ReplacePinResponse, + UpdateNameRequest, UpdateVolumeRequest, Volume, } from './types.gen' diff --git a/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts index 5669009e4..ccfa5bba2 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts @@ -7,11 +7,14 @@ import { } from '../../../bridge' import type { DefaultValues } from '../../../bridge' import type { + CreateNameRequest, CreatePinByCIDRequest, CreatePinByURLRequest, CreateVolumeRequest, + ListNamesResponse, ListPinsResponse, ListVolumesResponse, + Name, Pin, PinCID, PinCIDMeta, @@ -19,6 +22,7 @@ import type { PinOptions, ReplacePinRequest, ReplacePinResponse, + UpdateNameRequest, UpdateVolumeRequest, Volume, } from './types.gen' @@ -64,6 +68,26 @@ const unmarshalPinInfo = (data: unknown) => { } as PinInfo } +export const unmarshalName = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Name' failed as data isn't a dictionary.`, + ) + } + + return { + cid: data.cid, + createdAt: unmarshalDate(data.created_at), + key: data.key, + name: data.name, + nameId: data.name_id, + projectId: data.project_id, + status: data.status, + tags: data.tags, + updatedAt: unmarshalDate(data.updated_at), + } as Name +} + export const unmarshalPin = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -101,6 +125,19 @@ export const unmarshalVolume = (data: unknown) => { } as Volume } +export const unmarshalListNamesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListNamesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + names: unmarshalArrayOfObject(data.names, unmarshalName), + totalCount: data.total_count, + } as ListNamesResponse +} + export const unmarshalListPinsResponse = (data: unknown) => { if (!isJSONObject(data)) { throw new TypeError( @@ -147,6 +184,15 @@ const marshalPinOptions = ( required_zones: request.requiredZones, }) +export const marshalCreateNameRequest = ( + request: CreateNameRequest, + defaults: DefaultValues, +): Record => ({ + cid: request.cid, + name: request.name, + project_id: request.projectId ?? defaults.defaultProjectId, +}) + export const marshalCreatePinByCIDRequest = ( request: CreatePinByCIDRequest, defaults: DefaultValues, @@ -193,6 +239,14 @@ export const marshalReplacePinRequest = ( volume_id: request.volumeId, }) +export const marshalUpdateNameRequest = ( + request: UpdateNameRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + tags: request.tags, +}) + export const marshalUpdateVolumeRequest = ( request: UpdateVolumeRequest, defaults: DefaultValues, diff --git a/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts b/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts index 3553940ea..3759d5b01 100644 --- a/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts +++ b/packages/clients/src/api/ipfs/v1alpha1/types.gen.ts @@ -2,10 +2,19 @@ // If you have any remark or suggestion do not hesitate to open an issue. import type { Region } from '../../../bridge' +export type ListNamesRequestOrderBy = 'created_at_asc' | 'created_at_desc' + export type ListPinsRequestOrderBy = 'created_at_asc' | 'created_at_desc' export type ListVolumesRequestOrderBy = 'created_at_asc' | 'created_at_desc' +export type NameStatus = + | 'unknown_status' + | 'queued' + | 'publishing' + | 'failed' + | 'published' + export type PinDetails = | 'unknown_details' | 'pinning_looking_for_provider' @@ -36,6 +45,11 @@ export type PinStatus = | 'failed' | 'pinned' +export interface ListNamesResponse { + names: Name[] + totalCount: number +} + export interface ListPinsResponse { totalCount: number pins: Pin[] @@ -46,6 +60,18 @@ export interface ListVolumesResponse { totalCount: number } +export interface Name { + nameId: string + projectId: string + createdAt?: Date + updatedAt?: Date + tags: string[] + name: string + key: string + cid: string + status: NameStatus +} + export interface Pin { pinId: string status: PinStatus @@ -219,3 +245,56 @@ export type DeletePinRequest = { pinId: string volumeId: string } + +export type CreateNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + projectId?: string + name: string + cid: string +} + +export type GetNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + nameId: string +} + +export type DeleteNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + nameId: string +} + +export type ListNamesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + page?: number + pageSize?: number + orderBy?: ListNamesRequestOrderBy + projectId?: string + organizationId?: string +} + +export type UpdateNameRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + nameId: string + name?: string + tags?: string[] +}