diff --git a/packages/clients/src/api/serverless_sqldb/v1alpha1/api.gen.ts b/packages/clients/src/api/serverless_sqldb/v1alpha1/api.gen.ts new file mode 100644 index 000000000..6415e135c --- /dev/null +++ b/packages/clients/src/api/serverless_sqldb/v1alpha1/api.gen.ts @@ -0,0 +1,297 @@ +// 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 '../../../bridge' +import type { Region, WaitForOptions } from '../../../bridge' +import { DATABASE_TRANSIENT_STATUSES } from './content.gen' +import { + marshalCreateDatabaseRequest, + marshalRestoreDatabaseFromBackupRequest, + marshalUpdateDatabaseRequest, + unmarshalDatabase, + unmarshalDatabaseBackup, + unmarshalListDatabaseBackupsResponse, + unmarshalListDatabasesResponse, +} from './marshalling.gen' +import type { + CreateDatabaseRequest, + Database, + DatabaseBackup, + DeleteDatabaseRequest, + ExportDatabaseBackupRequest, + GetDatabaseBackupRequest, + GetDatabaseRequest, + ListDatabaseBackupsRequest, + ListDatabaseBackupsResponse, + ListDatabasesRequest, + ListDatabasesResponse, + RestoreDatabaseFromBackupRequest, + UpdateDatabaseRequest, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** + * Serverless SQL Databases API. + * + * This API allows you to manage your Serverless SQL DB databases. + */ +export class API extends ParentAPI { + /** Lists the available regions of the API. */ + public static readonly LOCALITIES: Region[] = ['fr-par'] + + /** + * Create a new Serverless SQL Database. You must provide the following + * parameters: `organization_id`, `project_id`, `name`, `cpu_min`, `cpu_max`. + * You can also provide `from_backup_id` to create a database from a backup. + * + * @param request - The request {@link CreateDatabaseRequest} + * @returns A Promise of Database + */ + createDatabase = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateDatabaseRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/databases`, + }, + unmarshalDatabase, + ) + + /** + * Get a database information. Retrieve information about your Serverless SQL + * Database. You must provide the `database_id` parameter. + * + * @param request - The request {@link GetDatabaseRequest} + * @returns A Promise of Database + */ + getDatabase = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/databases/${validatePathParam('databaseId', request.databaseId)}`, + }, + unmarshalDatabase, + ) + + /** + * Waits for {@link Database} to be in a final state. + * + * @param request - The request {@link GetDatabaseRequest} + * @param options - The waiting options + * @returns A Promise of Database + */ + waitForDatabase = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve(!DATABASE_TRANSIENT_STATUSES.includes(res.status))), + this.getDatabase, + request, + options, + ) + + /** + * Delete a database. Deletes a database. You must provide the `database_id` + * parameter. All data stored in the database will be permanently deleted. + * + * @param request - The request {@link DeleteDatabaseRequest} + * @returns A Promise of Database + */ + deleteDatabase = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/databases/${validatePathParam('databaseId', request.databaseId)}`, + }, + unmarshalDatabase, + ) + + protected pageOfListDatabases = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/databases`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy], + ['page', request.page], + ['page_size', request.pageSize], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ), + }, + unmarshalListDatabasesResponse, + ) + + /** + * List your Serverless SQL Databases. List all Serverless SQL Databases for a + * given Scaleway Organization or Scaleway Project. By default, the databases + * returned in the list are ordered by creation date in ascending order, + * though this can be modified via the order_by field. For the `name` + * parameter, the value you include will be checked against the whole name + * string to see if it includes the string you put in the parameter. + * + * @param request - The request {@link ListDatabasesRequest} + * @returns A Promise of ListDatabasesResponse + */ + listDatabases = (request: Readonly = {}) => + enrichForPagination('databases', this.pageOfListDatabases, request) + + /** + * Update database information. Update CPU limits of your Serverless SQL + * Database. You must provide the `database_id` parameter. + * + * @param request - The request {@link UpdateDatabaseRequest} + * @returns A Promise of Database + */ + updateDatabase = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateDatabaseRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/databases/${validatePathParam('databaseId', request.databaseId)}`, + }, + unmarshalDatabase, + ) + + /** + * Restore a database from a backup. Restore a database from a backup. You + * must provide the `backup_id` parameter. + * + * @param request - The request {@link RestoreDatabaseFromBackupRequest} + * @returns A Promise of Database + */ + restoreDatabaseFromBackup = ( + request: Readonly, + ) => + this.client.fetch( + { + body: JSON.stringify( + marshalRestoreDatabaseFromBackupRequest( + request, + this.client.settings, + ), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/databases/${validatePathParam( + 'databaseId', + request.databaseId, + )}/restore`, + }, + unmarshalDatabase, + ) + + /** + * Get a database backup information. Retrieve information about your + * Serverless SQL Database backup. You must provide the `backup_id` + * parameter. + * + * @param request - The request {@link GetDatabaseBackupRequest} + * @returns A Promise of DatabaseBackup + */ + getDatabaseBackup = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/backups/${validatePathParam('backupId', request.backupId)}`, + }, + unmarshalDatabaseBackup, + ) + + protected pageOfListDatabaseBackups = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/backups`, + urlParams: urlParams( + ['database_id', request.databaseId], + ['order_by', request.orderBy], + ['page', request.page], + ['page_size', request.pageSize], + ), + }, + unmarshalListDatabaseBackupsResponse, + ) + + /** + * List your Serverless SQL Database backups. List all Serverless SQL Database + * backups for a given Scaleway Project or Database. By default, the backups + * returned in the list are ordered by creation date in ascending order, + * though this can be modified via the order_by field. + * + * @param request - The request {@link ListDatabaseBackupsRequest} + * @returns A Promise of ListDatabaseBackupsResponse + */ + listDatabaseBackups = (request: Readonly) => + enrichForPagination('backups', this.pageOfListDatabaseBackups, request) + + /** + * Export a database backup. Export a database backup providing a download + * link once the export process is completed. You must provide the `backup_id` + * parameter. + * + * @param request - The request {@link ExportDatabaseBackupRequest} + * @returns A Promise of DatabaseBackup + */ + exportDatabaseBackup = (request: Readonly) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/serverless-sqldb/v1alpha1/regions/${validatePathParam( + 'region', + request.region ?? this.client.settings.defaultRegion, + )}/backups/${validatePathParam('backupId', request.backupId)}/export`, + }, + unmarshalDatabaseBackup, + ) +} diff --git a/packages/clients/src/api/serverless_sqldb/v1alpha1/content.gen.ts b/packages/clients/src/api/serverless_sqldb/v1alpha1/content.gen.ts new file mode 100644 index 000000000..b89350238 --- /dev/null +++ b/packages/clients/src/api/serverless_sqldb/v1alpha1/content.gen.ts @@ -0,0 +1,10 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { DatabaseStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link DatabaseStatus}. */ +export const DATABASE_TRANSIENT_STATUSES: DatabaseStatus[] = [ + 'creating', + 'deleting', + 'restoring', +] diff --git a/packages/clients/src/api/serverless_sqldb/v1alpha1/index.gen.ts b/packages/clients/src/api/serverless_sqldb/v1alpha1/index.gen.ts new file mode 100644 index 000000000..1e8adf679 --- /dev/null +++ b/packages/clients/src/api/serverless_sqldb/v1alpha1/index.gen.ts @@ -0,0 +1,24 @@ +// 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 { + CreateDatabaseRequest, + Database, + DatabaseBackup, + DatabaseBackupStatus, + DatabaseStatus, + DeleteDatabaseRequest, + ExportDatabaseBackupRequest, + GetDatabaseBackupRequest, + GetDatabaseRequest, + ListDatabaseBackupsRequest, + ListDatabaseBackupsRequestOrderBy, + ListDatabaseBackupsResponse, + ListDatabasesRequest, + ListDatabasesRequestOrderBy, + ListDatabasesResponse, + RestoreDatabaseFromBackupRequest, + UpdateDatabaseRequest, +} from './types.gen' +export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/serverless_sqldb/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/serverless_sqldb/v1alpha1/marshalling.gen.ts new file mode 100644 index 000000000..ec8b685da --- /dev/null +++ b/packages/clients/src/api/serverless_sqldb/v1alpha1/marshalling.gen.ts @@ -0,0 +1,119 @@ +// 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 '../../../bridge' +import type { DefaultValues } from '../../../bridge' +import type { + CreateDatabaseRequest, + Database, + DatabaseBackup, + ListDatabaseBackupsResponse, + ListDatabasesResponse, + RestoreDatabaseFromBackupRequest, + UpdateDatabaseRequest, +} from './types.gen' + +export const unmarshalDatabaseBackup = (data: unknown): DatabaseBackup => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'DatabaseBackup' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + databaseId: data.database_id, + downloadUrl: data.download_url, + downloadUrlExpiresAt: unmarshalDate(data.download_url_expires_at), + expiresAt: unmarshalDate(data.expires_at), + id: data.id, + organizationId: data.organization_id, + projectId: data.project_id, + region: data.region, + size: data.size, + status: data.status, + } as DatabaseBackup +} + +export const unmarshalDatabase = (data: unknown): Database => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Database' failed as data isn't a dictionary.`, + ) + } + + return { + cpuCurrent: data.cpu_current, + cpuMax: data.cpu_max, + cpuMin: data.cpu_min, + createdAt: unmarshalDate(data.created_at), + endpoint: data.endpoint, + engineMajorVersion: data.engine_major_version, + id: data.id, + name: data.name, + organizationId: data.organization_id, + projectId: data.project_id, + region: data.region, + started: data.started, + status: data.status, + } as Database +} + +export const unmarshalListDatabaseBackupsResponse = ( + data: unknown, +): ListDatabaseBackupsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListDatabaseBackupsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + backups: unmarshalArrayOfObject(data.backups, unmarshalDatabaseBackup), + totalCount: data.total_count, + } as ListDatabaseBackupsResponse +} + +export const unmarshalListDatabasesResponse = ( + data: unknown, +): ListDatabasesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListDatabasesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + databases: unmarshalArrayOfObject(data.databases, unmarshalDatabase), + totalCount: data.total_count, + } as ListDatabasesResponse +} + +export const marshalCreateDatabaseRequest = ( + request: CreateDatabaseRequest, + defaults: DefaultValues, +): Record => ({ + cpu_max: request.cpuMax, + cpu_min: request.cpuMin, + from_backup_id: request.fromBackupId, + name: request.name, + project_id: request.projectId ?? defaults.defaultProjectId, +}) + +export const marshalRestoreDatabaseFromBackupRequest = ( + request: RestoreDatabaseFromBackupRequest, + defaults: DefaultValues, +): Record => ({ + backup_id: request.backupId, +}) + +export const marshalUpdateDatabaseRequest = ( + request: UpdateDatabaseRequest, + defaults: DefaultValues, +): Record => ({ + cpu_max: request.cpuMax, + cpu_min: request.cpuMin, +}) diff --git a/packages/clients/src/api/serverless_sqldb/v1alpha1/types.gen.ts b/packages/clients/src/api/serverless_sqldb/v1alpha1/types.gen.ts new file mode 100644 index 000000000..3c5b86e14 --- /dev/null +++ b/packages/clients/src/api/serverless_sqldb/v1alpha1/types.gen.ts @@ -0,0 +1,223 @@ +// 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 } from '../../../bridge' + +export type DatabaseBackupStatus = + | 'unknown_status' + | 'error' + | 'ready' + | 'locked' + +export type DatabaseStatus = + | 'unknown_status' + | 'error' + | 'creating' + | 'ready' + | 'deleting' + | 'restoring' + | 'locked' + +export type ListDatabaseBackupsRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + +export type ListDatabasesRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + +export interface DatabaseBackup { + /** UUID that uniquely identifies a Serverless SQL Database backup. */ + id: string + /** + * Status of the Serverless SQL Database backup. One of `unknown_status` | + * `error` | `ready` | `locked`. + */ + status: DatabaseBackupStatus + /** The ID of your Scaleway organization. */ + organizationId: string + /** UUID of the Scaleway project. */ + projectId: string + /** UUID of the source Serverless SQL Database the backup is created from. */ + databaseId: string + /** Creation date. */ + createdAt?: Date + /** Expiration date. */ + expiresAt?: Date + /** Size of the database backup. */ + size?: number + /** Download URL of the exported database backup. */ + downloadUrl?: string + /** Expiration date of the download URL. */ + downloadUrlExpiresAt?: Date + /** Region of the database backup. */ + region: Region +} + +export interface Database { + /** UUID that uniquely identifies your Serverless SQL DB Database. */ + id: string + /** Name of the database. */ + name: string + /** + * Status of the Serverless SQL Ddatabase. One of `unknown_status` | `ready` | + * `creating` | `deleting` | `error` | `restoring` | `locked`. + */ + status: DatabaseStatus + /** Endpoint of the database. */ + endpoint: string + /** The ID of your Scaleway organization. */ + organizationId: string + /** Project ID the database belongs to. */ + projectId: string + /** Region of the database. */ + region: Region + /** Creation date. */ + createdAt?: Date + /** The minimum number of CPU units for your Serverless SQL Database. */ + cpuMin: number + /** The maximum number of CPU units for your Serverless SQL Database. */ + cpuMax: number + /** The current number of CPU units allocated to your Serverless SQL Database. */ + cpuCurrent: number + /** Whether your Serverless SQL Database is running or not. */ + started: boolean + /** The major version of the underlying database engine. */ + engineMajorVersion: number +} + +export type CreateDatabaseRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** The ID of your Scaleway project. */ + projectId?: string + /** The name of the Serverless SQL Database to be created. */ + name: string + /** The minimum number of CPU units for your Serverless SQL Database. */ + cpuMin: number + /** The maximum number of CPU units for your Serverless SQL Database. */ + cpuMax: number + /** The ID of the backup to create the database from. */ + fromBackupId?: string +} + +export type DeleteDatabaseRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Serverless SQL Database. */ + databaseId: string +} + +export type ExportDatabaseBackupRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Serverless SQL Database backup. */ + backupId: string +} + +export type GetDatabaseBackupRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Serverless SQL Database backup. */ + backupId: string +} + +export type GetDatabaseRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Serverless SQL DB database. */ + databaseId: string +} + +export type ListDatabaseBackupsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Filter by the UUID of the Serverless SQL Database. */ + databaseId: string + /** Page number. */ + page?: number + /** Page size. */ + pageSize?: number + /** Sorting criteria. One of `created_at_asc`, `created_at_desc`. */ + orderBy?: ListDatabaseBackupsRequestOrderBy +} + +export interface ListDatabaseBackupsResponse { + /** List of the backups. */ + backups: DatabaseBackup[] + /** Length of the backups list. */ + totalCount: number +} + +export type ListDatabasesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Scaleway project. */ + projectId?: string + /** Page number. */ + page?: number + /** Page size. */ + pageSize?: number + /** Filter by the name of the database. */ + name?: string + /** + * Sorting criteria. One of `created_at_asc`, `created_at_desc`, `name_asc`, + * `name_desc`. + */ + orderBy?: ListDatabasesRequestOrderBy +} + +export interface ListDatabasesResponse { + /** List of the databases. */ + databases: Database[] + /** Total count of Serverless SQL Databases. */ + totalCount: number +} + +export type RestoreDatabaseFromBackupRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Serverless SQL Database. */ + databaseId: string + /** UUID of the Serverless SQL Database backup to restore. */ + backupId: string +} + +export type UpdateDatabaseRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Serverless SQL Database. */ + databaseId: string + /** The minimum number of CPU units for your Serverless SQL Database. */ + cpuMin?: number + /** The maximum number of CPU units for your Serverless SQL Database. */ + cpuMax?: number +} diff --git a/packages/clients/src/api/serverless_sqldb/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/serverless_sqldb/v1alpha1/validation-rules.gen.ts new file mode 100644 index 000000000..bacfbd081 --- /dev/null +++ b/packages/clients/src/api/serverless_sqldb/v1alpha1/validation-rules.gen.ts @@ -0,0 +1,62 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +export const CreateDatabaseRequest = { + cpuMax: { + greaterThanOrEqual: 1, + lessThanOrEqual: 15, + }, + cpuMin: { + lessThanOrEqual: 15, + }, + fromBackupId: { + ignoreEmpty: true, + }, + name: { + maxLength: 63, + minLength: 1, + }, +} + +export const Database = { + cpuCurrent: { + lessThanOrEqual: 15, + }, + cpuMax: { + greaterThanOrEqual: 1, + lessThanOrEqual: 15, + }, + cpuMin: { + lessThanOrEqual: 15, + }, +} + +export const ListDatabaseBackupsRequest = { + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 1000, + }, +} + +export const ListDatabasesRequest = { + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 1000, + }, +} + +export const UpdateDatabaseRequest = { + cpuMax: { + greaterThanOrEqual: 1, + lessThanOrEqual: 15, + }, + cpuMin: { + lessThanOrEqual: 15, + }, +}