Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 109 additions & 1 deletion packages/clients/src/api/ipfs/v1alpha1/api.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -327,4 +338,101 @@ export class API extends ParentAPI {
)}/pins/${validatePathParam('pinId', request.pinId)}`,
urlParams: urlParams(['volume_id', request.volumeId]),
})

createName = (request: Readonly<CreateNameRequest>) =>
this.client.fetch<Name>(
{
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<GetNameRequest>) =>
this.client.fetch<Name>(
{
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<GetNameRequest>,
options?: Readonly<WaitForOptions<Name>>,
) =>
waitForResource(
options?.stop ??
(res => Promise.resolve(!NAME_TRANSIENT_STATUSES.includes(res.status))),
this.getName,
request,
options,
)

deleteName = (request: Readonly<DeleteNameRequest>) =>
this.client.fetch<void>({
method: 'DELETE',
path: `/ipfs/v1alpha1/regions/${validatePathParam(
'region',
request.region ?? this.client.settings.defaultRegion,
)}/names/${validatePathParam('nameId', request.nameId)}`,
})

protected pageOfListNames = (request: Readonly<ListNamesRequest> = {}) =>
this.client.fetch<ListNamesResponse>(
{
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<ListNamesRequest> = {}) =>
enrichForPagination('names', this.pageOfListNames, request)

updateName = (request: Readonly<UpdateNameRequest>) =>
this.client.fetch<Name>(
{
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,
)
}
5 changes: 4 additions & 1 deletion packages/clients/src/api/ipfs/v1alpha1/content.gen.ts
Original file line number Diff line number Diff line change
@@ -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']
9 changes: 9 additions & 0 deletions packages/clients/src/api/ipfs/v1alpha1/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,6 +33,7 @@ export type {
PinStatus,
ReplacePinRequest,
ReplacePinResponse,
UpdateNameRequest,
UpdateVolumeRequest,
Volume,
} from './types.gen'
54 changes: 54 additions & 0 deletions packages/clients/src/api/ipfs/v1alpha1/marshalling.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ import {
} from '../../../bridge'
import type { DefaultValues } from '../../../bridge'
import type {
CreateNameRequest,
CreatePinByCIDRequest,
CreatePinByURLRequest,
CreateVolumeRequest,
ListNamesResponse,
ListPinsResponse,
ListVolumesResponse,
Name,
Pin,
PinCID,
PinCIDMeta,
PinInfo,
PinOptions,
ReplacePinRequest,
ReplacePinResponse,
UpdateNameRequest,
UpdateVolumeRequest,
Volume,
} from './types.gen'
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -147,6 +184,15 @@ const marshalPinOptions = (
required_zones: request.requiredZones,
})

export const marshalCreateNameRequest = (
request: CreateNameRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
cid: request.cid,
name: request.name,
project_id: request.projectId ?? defaults.defaultProjectId,
})

export const marshalCreatePinByCIDRequest = (
request: CreatePinByCIDRequest,
defaults: DefaultValues,
Expand Down Expand Up @@ -193,6 +239,14 @@ export const marshalReplacePinRequest = (
volume_id: request.volumeId,
})

export const marshalUpdateNameRequest = (
request: UpdateNameRequest,
defaults: DefaultValues,
): Record<string, unknown> => ({
name: request.name,
tags: request.tags,
})

export const marshalUpdateVolumeRequest = (
request: UpdateVolumeRequest,
defaults: DefaultValues,
Expand Down
Loading