diff --git a/packages/clients/src/api/file/index.gen.ts b/packages/clients/src/api/file/index.gen.ts new file mode 100644 index 000000000..4e5e04061 --- /dev/null +++ b/packages/clients/src/api/file/index.gen.ts @@ -0,0 +1,6 @@ +/** + * This file is automatically generated from /scripts/generate.js + * PLEASE DO NOT EDIT HERE + */ + +export * as v1alpha1 from './v1alpha1/index.gen' diff --git a/packages/clients/src/api/file/v1alpha1/api.gen.ts b/packages/clients/src/api/file/v1alpha1/api.gen.ts new file mode 100644 index 000000000..9123f5ced --- /dev/null +++ b/packages/clients/src/api/file/v1alpha1/api.gen.ts @@ -0,0 +1,194 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + API as ParentAPI, + enrichForPagination, + urlParams, + validatePathParam, + waitForResource, +} from '@scaleway/sdk-client' +import type { Region as ScwRegion, WaitForOptions } from '@scaleway/sdk-client' +import { FILE_SYSTEM_TRANSIENT_STATUSES as FILE_SYSTEM_TRANSIENT_STATUSES_FILE } from './content.gen' +import { + marshalCreateFileSystemRequest, + marshalUpdateFileSystemRequest, + unmarshalFileSystem, + unmarshalListAttachmentsResponse, + unmarshalListFileSystemsResponse, +} from './marshalling.gen' +import type { + CreateFileSystemRequest, + DeleteFileSystemRequest, + FileSystem, + GetFileSystemRequest, + ListAttachmentsRequest, + ListAttachmentsResponse, + ListFileSystemsRequest, + ListFileSystemsResponse, + UpdateFileSystemRequest, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** + * File Storage API. + +This API allows you to manage your File Storage resources. + */ +export class API extends ParentAPI { + /** Lists the available regions of the API. */ + public static readonly LOCALITIES: ScwRegion[] = ['fr-par'] + + /** + * Get filesystem details. Retrieve all properties and current status of a specific filesystem identified by its ID. + * + * @param request - The request {@link GetFileSystemRequest} + * @returns A Promise of FileSystem + */ + getFileSystem = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/file/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/filesystems/${validatePathParam('filesystemId', request.filesystemId)}`, + }, + unmarshalFileSystem, + ) + + /** + * Waits for {@link FileSystem} to be in a final state. + * + * @param request - The request {@link GetFileSystemRequest} + * @param options - The waiting options + * @returns A Promise of FileSystem + */ + waitForFileSystem = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve( + !FILE_SYSTEM_TRANSIENT_STATUSES_FILE.includes(res.status), + )), + this.getFileSystem, + request, + options, + ) + + protected pageOfListFileSystems = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/file/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/filesystems`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['project_id', request.projectId], + ['tags', request.tags], + ), + }, + unmarshalListFileSystemsResponse, + ) + + /** + * List all filesystems. Retrieve all filesystems in the specified region. Results are ordered by creation date in ascending order by default. +Use the order_by parameter to modify the sorting behavior. + * + * @param request - The request {@link ListFileSystemsRequest} + * @returns A Promise of ListFileSystemsResponse + */ + listFileSystems = (request: Readonly = {}) => + enrichForPagination('filesystems', this.pageOfListFileSystems, request) + + protected pageOfListAttachments = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/file/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/attachments`, + urlParams: urlParams( + ['filesystem_id', request.filesystemId], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['resource_id', request.resourceId], + ['resource_type', request.resourceType], + ), + }, + unmarshalListAttachmentsResponse, + ) + + /** + * List filesystems attachments. List all existing attachments in a specified region. +By default, the attachments listed are ordered by creation date in ascending order. +This can be modified using the `order_by` field. + * + * @param request - The request {@link ListAttachmentsRequest} + * @returns A Promise of ListAttachmentsResponse + */ + listAttachments = (request: Readonly = {}) => + enrichForPagination('attachments', this.pageOfListAttachments, request) + + /** + * Create a new filesystem. To create a new filesystem, you need to provide a name, a size, and a project ID. + * + * @param request - The request {@link CreateFileSystemRequest} + * @returns A Promise of FileSystem + */ + createFileSystem = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateFileSystemRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/file/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/filesystems`, + }, + unmarshalFileSystem, + ) + + /** + * Delete a detached filesystem. You must specify the `filesystem_id` of the filesystem you want to delete. + * + * @param request - The request {@link DeleteFileSystemRequest} + */ + deleteFileSystem = (request: Readonly) => + this.client.fetch({ + method: 'DELETE', + path: `/file/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/filesystems/${validatePathParam('filesystemId', request.filesystemId)}`, + }) + + /** + * Update filesystem properties. Update the technical details of a filesystem, such as its name, tags or its new size. +You can only resize a filesystem to a larger size. + * + * @param request - The request {@link UpdateFileSystemRequest} + * @returns A Promise of FileSystem + */ + updateFileSystem = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateFileSystemRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/file/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/filesystems/${validatePathParam('filesystemId', request.filesystemId)}`, + }, + unmarshalFileSystem, + ) +} diff --git a/packages/clients/src/api/file/v1alpha1/content.gen.ts b/packages/clients/src/api/file/v1alpha1/content.gen.ts new file mode 100644 index 000000000..f7330db6f --- /dev/null +++ b/packages/clients/src/api/file/v1alpha1/content.gen.ts @@ -0,0 +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 { FileSystemStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link FileSystemStatus}. */ +export const FILE_SYSTEM_TRANSIENT_STATUSES: FileSystemStatus[] = [ + 'creating', + 'updating', +] diff --git a/packages/clients/src/api/file/v1alpha1/index.gen.ts b/packages/clients/src/api/file/v1alpha1/index.gen.ts new file mode 100644 index 000000000..6bf286157 --- /dev/null +++ b/packages/clients/src/api/file/v1alpha1/index.gen.ts @@ -0,0 +1,20 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +export { API } from './api.gen' +export * from './content.gen' +export type { + Attachment, + AttachmentResourceType, + CreateFileSystemRequest, + DeleteFileSystemRequest, + FileSystem, + FileSystemStatus, + GetFileSystemRequest, + ListAttachmentsRequest, + ListAttachmentsResponse, + ListFileSystemsRequest, + ListFileSystemsRequestOrderBy, + ListFileSystemsResponse, + UpdateFileSystemRequest, +} from './types.gen' +export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/file/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/file/v1alpha1/marshalling.gen.ts new file mode 100644 index 000000000..77efdc77c --- /dev/null +++ b/packages/clients/src/api/file/v1alpha1/marshalling.gen.ts @@ -0,0 +1,102 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + isJSONObject, + unmarshalArrayOfObject, + unmarshalDate, +} from '@scaleway/sdk-client' +import type { DefaultValues } from '@scaleway/sdk-client' +import type { + Attachment, + CreateFileSystemRequest, + FileSystem, + ListAttachmentsResponse, + ListFileSystemsResponse, + UpdateFileSystemRequest, +} from './types.gen' + +export const unmarshalFileSystem = (data: unknown): FileSystem => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'FileSystem' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + name: data.name, + numberOfAttachments: data.number_of_attachments, + organizationId: data.organization_id, + projectId: data.project_id, + region: data.region, + size: data.size, + status: data.status, + tags: data.tags, + updatedAt: unmarshalDate(data.updated_at), + } as FileSystem +} + +const unmarshalAttachment = (data: unknown): Attachment => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Attachment' failed as data isn't a dictionary.`, + ) + } + + return { + filesystemId: data.filesystem_id, + id: data.id, + resourceId: data.resource_id, + resourceType: data.resource_type, + } as Attachment +} + +export const unmarshalListAttachmentsResponse = ( + data: unknown, +): ListAttachmentsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListAttachmentsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + attachments: unmarshalArrayOfObject(data.attachments, unmarshalAttachment), + totalCount: data.total_count, + } as ListAttachmentsResponse +} + +export const unmarshalListFileSystemsResponse = ( + data: unknown, +): ListFileSystemsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListFileSystemsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + filesystems: unmarshalArrayOfObject(data.filesystems, unmarshalFileSystem), + totalCount: data.total_count, + } as ListFileSystemsResponse +} + +export const marshalCreateFileSystemRequest = ( + request: CreateFileSystemRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + project_id: request.projectId ?? defaults.defaultProjectId, + size: request.size, + tags: request.tags, +}) + +export const marshalUpdateFileSystemRequest = ( + request: UpdateFileSystemRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + size: request.size, + tags: request.tags, +}) diff --git a/packages/clients/src/api/file/v1alpha1/types.gen.ts b/packages/clients/src/api/file/v1alpha1/types.gen.ts new file mode 100644 index 000000000..f646081f4 --- /dev/null +++ b/packages/clients/src/api/file/v1alpha1/types.gen.ts @@ -0,0 +1,263 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { Region as ScwRegion } from '@scaleway/sdk-client' + +export type AttachmentResourceType = 'unknown_resource_type' | 'instance_server' + +export type FileSystemStatus = + | 'unknown_status' + | 'available' + | 'error' + | 'creating' + | 'updating' + +export type ListFileSystemsRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + +/** + * Represents an attachment between a filesystem and a resource. + */ +export interface Attachment { + /** + * UUID of the attachment. + */ + id: string + /** + * UUID of the filesystem. + */ + filesystemId: string + /** + * UUID of the attached resource. + */ + resourceId: string + /** + * The type of the attached resource. + */ + resourceType: AttachmentResourceType +} + +/** + * Represents a filesystem resource and its properties. + */ +export interface FileSystem { + /** + * UUID of the filesystem. + */ + id: string + /** + * Name of the filesystem. + */ + name: string + /** + * Filesystem size in bytes. + */ + size: number + /** + * Current status of the filesystem (e.g. creating, available, ...). + */ + status: FileSystemStatus + /** + * UUID of the project to which the filesystem belongs. + */ + projectId: string + /** + * UUID of the organization to which the filesystem belongs. + */ + organizationId: string + /** + * List of tags assigned to the filesystem. + */ + tags: string[] + /** + * The current number of attachments (mounts) that the filesystem has. + */ + numberOfAttachments: number + /** + * Region where the filesystem is located. + */ + region: ScwRegion + /** + * Creation date of the filesystem. + */ + createdAt?: Date + /** + * Last update date of the properties of the filesystem. + */ + updatedAt?: Date +} + +/** + * Request to create a new filesystem. + */ +export type CreateFileSystemRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * Name of the filesystem. + */ + name: string + /** + * UUID of the project the filesystem belongs to. + */ + projectId?: string + /** + * Must be compliant with the minimum (100 GB) and maximum (10 TB) allowed size. + */ + size: number + /** + * List of tags assigned to the filesystem. + */ + tags?: string[] +} + +/** + * Request to delete a specific filesystem. + */ +export type DeleteFileSystemRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the filesystem. + */ + filesystemId: string +} + +/** + * Request to retrieve a specific filesystem. + */ +export type GetFileSystemRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the filesystem. + */ + filesystemId: string +} + +/** + * Request to list filesystem attachments with filtering and pagination options. + */ +export type ListAttachmentsRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the File Storage volume. + */ + filesystemId?: string + /** + * Filter by resource ID. + */ + resourceId?: string + /** + * Filter by resource type. + */ + resourceType?: AttachmentResourceType + /** + * Page number (starting at 1). + */ + page?: number + /** + * Number of entries per page (default: 20, max: 100). + */ + pageSize?: number +} + +/** + * Response containing a list of filesystem attachments and total count. + */ +export interface ListAttachmentsResponse { + /** + * List of filesystem attachments matching the request criteria. + */ + attachments: Attachment[] + /** + * Total number of filesystem attachments matching the criteria. + */ + totalCount: number +} + +/** + * Request to list filesystems with filtering and pagination options. + */ +export type ListFileSystemsRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * Criteria to use when ordering the list. + */ + orderBy?: ListFileSystemsRequestOrderBy + /** + * Filter by project ID. + */ + projectId?: string + /** + * Page number (starting at 1). + */ + page?: number + /** + * Number of entries per page (default: 20, max: 100). + */ + pageSize?: number + /** + * Filter the return filesystems by their names. + */ + name?: string + /** + * Filter by tags. Only filesystems with one or more matching tags will be returned. + */ + tags?: string[] +} + +/** + * Response containing a list of filesystems and total count. + */ +export interface ListFileSystemsResponse { + /** + * List of filesystems matching the request criteria. + */ + filesystems: FileSystem[] + /** + * Total number of filesystems matching the criteria. + */ + totalCount: number +} + +/** + * Request to update a specific filesystem. + */ +export type UpdateFileSystemRequest = { + /** + * Region to target. If none is passed will use default region from the config. + */ + region?: ScwRegion + /** + * UUID of the filesystem. + */ + filesystemId: string + /** + * When defined, is the new name of the filesystem. + */ + name?: string + /** + * Size in bytes, with a granularity of 100 GB (10^11 bytes). +Must be compliant with the minimum (100 GB) and maximum (10 TB) allowed size. + */ + size?: number + /** + * List of tags assigned to the filesystem. + */ + tags?: string[] +} diff --git a/packages/clients/src/api/file/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/file/v1alpha1/validation-rules.gen.ts new file mode 100644 index 000000000..3bf1d8783 --- /dev/null +++ b/packages/clients/src/api/file/v1alpha1/validation-rules.gen.ts @@ -0,0 +1,40 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +export const CreateFileSystemRequest = { + name: { + minLength: 1, + }, + size: { + greaterThan: 0, + }, +} + +export const ListAttachmentsRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThan: 0, + lessThanOrEqual: 100, + }, +} + +export const ListFileSystemsRequest = { + page: { + greaterThan: 0, + }, + pageSize: { + greaterThan: 0, + lessThanOrEqual: 100, + }, +} + +export const UpdateFileSystemRequest = { + name: { + minLength: 1, + }, + size: { + greaterThan: 0, + }, +} diff --git a/packages/clients/src/api/index.gen.ts b/packages/clients/src/api/index.gen.ts index 5e47484ee..ec92caf95 100644 --- a/packages/clients/src/api/index.gen.ts +++ b/packages/clients/src/api/index.gen.ts @@ -15,6 +15,7 @@ import * as Dedibox from './dedibox/index.gen' import * as DocumentDb from './document_db/index.gen' import * as Domain from './domain/index.gen' import * as EdgeServices from './edge_services/index.gen' +import * as File from './file/index.gen' import * as Flexibleip from './flexibleip/index.gen' import * as Function from './function/index.gen' import * as Iam from './iam/index.gen' @@ -59,6 +60,7 @@ export { DocumentDb, Domain, EdgeServices, + File, Flexibleip, Function, Iam,