diff --git a/packages/clients/src/api/index.gen.ts b/packages/clients/src/api/index.gen.ts index c44bfc83f..665edb26e 100644 --- a/packages/clients/src/api/index.gen.ts +++ b/packages/clients/src/api/index.gen.ts @@ -29,6 +29,7 @@ import * as Lb from './lb/index.gen' import * as LlmInference from './llm_inference/index.gen' import * as Marketplace from './marketplace/index.gen' import * as Mnq from './mnq/index.gen' +import * as Mongodb from './mongodb/index.gen' import * as Qaas from './qaas/index.gen' import * as Rdb from './rdb/index.gen' import * as Redis from './redis/index.gen' @@ -69,6 +70,7 @@ export { LlmInference, Marketplace, Mnq, + Mongodb, Qaas, Rdb, Redis, diff --git a/packages/clients/src/api/mongodb/index.gen.ts b/packages/clients/src/api/mongodb/index.gen.ts new file mode 100644 index 000000000..6dec29b44 --- /dev/null +++ b/packages/clients/src/api/mongodb/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/mongodb/v1alpha1/api.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/api.gen.ts new file mode 100644 index 000000000..ed5383009 --- /dev/null +++ b/packages/clients/src/api/mongodb/v1alpha1/api.gen.ts @@ -0,0 +1,467 @@ +// 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 { INSTANCE_TRANSIENT_STATUSES } from './content.gen' +import { + marshalCreateInstanceRequest, + marshalCreateSnapshotRequest, + marshalRestoreSnapshotRequest, + marshalUpdateInstanceRequest, + marshalUpdateSnapshotRequest, + marshalUpdateUserRequest, + marshalUpgradeInstanceRequest, + unmarshalInstance, + unmarshalListInstancesResponse, + unmarshalListNodeTypesResponse, + unmarshalListSnapshotsResponse, + unmarshalListUsersResponse, + unmarshalListVersionsResponse, + unmarshalSnapshot, + unmarshalUser, +} from './marshalling.gen' +import type { + CreateInstanceRequest, + CreateSnapshotRequest, + DeleteInstanceRequest, + DeleteSnapshotRequest, + GetInstanceCertificateRequest, + GetInstanceRequest, + Instance, + ListInstancesRequest, + ListInstancesResponse, + ListNodeTypesRequest, + ListNodeTypesResponse, + ListSnapshotsRequest, + ListSnapshotsResponse, + ListUsersRequest, + ListUsersResponse, + ListVersionsRequest, + ListVersionsResponse, + RestoreSnapshotRequest, + Snapshot, + UpdateInstanceRequest, + UpdateSnapshotRequest, + UpdateUserRequest, + UpgradeInstanceRequest, + User, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** + * Managed Database for MongoDB. + * + * This API allows you to manage your Managed Databases for MongoDB. + */ +export class API extends ParentAPI { + /** Lists the available regions of the API. */ + public static readonly LOCALITIES: Region[] = ['fr-par', 'nl-ams', 'pl-waw'] + + protected pageOfListNodeTypes = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/node-types`, + urlParams: urlParams( + ['include_disabled_types', request.includeDisabledTypes], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListNodeTypesResponse, + ) + + /** + * List available node types. + * + * @param request - The request {@link ListNodeTypesRequest} + * @returns A Promise of ListNodeTypesResponse + */ + listNodeTypes = (request: Readonly = {}) => + enrichForPagination('nodeTypes', this.pageOfListNodeTypes, request) + + protected pageOfListVersions = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/versions`, + urlParams: urlParams( + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['version', request.version], + ), + }, + unmarshalListVersionsResponse, + ) + + /** + * List available MongoDB™ versions. + * + * @param request - The request {@link ListVersionsRequest} + * @returns A Promise of ListVersionsResponse + */ + listVersions = (request: Readonly = {}) => + enrichForPagination('versions', this.pageOfListVersions, request) + + protected pageOfListInstances = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy], + [ + 'organization_id', + request.organizationId ?? + this.client.settings.defaultOrganizationId, + ], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ['tags', request.tags], + ), + }, + unmarshalListInstancesResponse, + ) + + /** + * List MongoDB™ Database Instances. List all MongoDB™ Database Instances in + * the specified region, for a given Scaleway Project. By default, the + * MongoDB™ Database Instances returned in the list are ordered by creation + * date in ascending order, though this can be modified via the order_by + * field. You can define additional parameters for your query, such as `tags` + * and `name`. 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 ListInstancesRequest} + * @returns A Promise of ListInstancesResponse + */ + listInstances = (request: Readonly = {}) => + enrichForPagination('instances', this.pageOfListInstances, request) + + /** + * Get a MongoDB™ Database Instance. Retrieve information about a given + * MongoDB™ Database Instance, specified by the `region` and `instance_id` + * parameters. Its full details, including name, status, IP address and port, + * are returned in the response object. + * + * @param request - The request {@link GetInstanceRequest} + * @returns A Promise of Instance + */ + getInstance = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}`, + }, + unmarshalInstance, + ) + + /** + * Waits for {@link Instance} to be in a final state. + * + * @param request - The request {@link GetInstanceRequest} + * @param options - The waiting options + * @returns A Promise of Instance + */ + waitForInstance = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve(!INSTANCE_TRANSIENT_STATUSES.includes(res.status))), + this.getInstance, + request, + options, + ) + + /** + * Create a MongoDB™ Database Instance. Create a new MongoDB™ Database + * Instance. + * + * @param request - The request {@link CreateInstanceRequest} + * @returns A Promise of Instance + */ + createInstance = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateInstanceRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances`, + }, + unmarshalInstance, + ) + + /** + * Update a MongoDB™ Database Instance. Update the parameters of a MongoDB™ + * Database Instance. + * + * @param request - The request {@link UpdateInstanceRequest} + * @returns A Promise of Instance + */ + updateInstance = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateInstanceRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}`, + }, + unmarshalInstance, + ) + + /** + * Delete a MongoDB™ Database Instance. Delete a given MongoDB™ Database + * Instance, specified by the `region` and `instance_id` parameters. Deleting + * a MongoDB™ Database Instance is permanent, and cannot be undone. Note that + * upon deletion all your data will be lost. + * + * @param request - The request {@link DeleteInstanceRequest} + * @returns A Promise of Instance + */ + deleteInstance = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}`, + }, + unmarshalInstance, + ) + + /** + * Upgrade a Database Instance. Upgrade your current Database Instance + * specifications like volume size. + * + * @param request - The request {@link UpgradeInstanceRequest} + * @returns A Promise of Instance + */ + upgradeInstance = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpgradeInstanceRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/upgrade`, + }, + unmarshalInstance, + ) + + /** + * Get the certificate of a Database Instance. Retrieve the certificate of a + * given Database Instance, specified by the `instance_id` parameter. + * + * @param request - The request {@link GetInstanceCertificateRequest} + * @returns A Promise of Blob + */ + getInstanceCertificate = (request: Readonly) => + this.client.fetch({ + method: 'GET', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/certificate`, + urlParams: urlParams(['dl', 1]), + responseType: 'blob', + }) + + /** + * Create a Database Instance snapshot. Create a new snapshot of a Database + * Instance. You must define the `name` and `instance_id` parameters in the + * request. + * + * @param request - The request {@link CreateSnapshotRequest} + * @returns A Promise of Snapshot + */ + createSnapshot = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateSnapshotRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/snapshots`, + }, + unmarshalSnapshot, + ) + + updateSnapshot = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateSnapshotRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`, + }, + unmarshalSnapshot, + ) + + /** + * Restore a Database Instance snapshot. Restore a given snapshot of a + * Database Instance. You must specify, in the endpoint, the `snapshot_id` + * parameter of the snapshot you want to restore, the `instance_name` of the + * new Database Instance, `node_type` of the new Database Instance and + * `node_number` of the new Database Instance. + * + * @param request - The request {@link RestoreSnapshotRequest} + * @returns A Promise of Instance + */ + restoreSnapshot = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalRestoreSnapshotRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}/restore`, + }, + unmarshalInstance, + ) + + protected pageOfListSnapshots = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/snapshots`, + urlParams: urlParams( + ['instance_id', request.instanceId], + ['name', request.name], + ['order_by', request.orderBy], + [ + 'organization_id', + request.organizationId ?? + this.client.settings.defaultOrganizationId, + ], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + [ + 'project_id', + request.projectId ?? this.client.settings.defaultProjectId, + ], + ), + }, + unmarshalListSnapshotsResponse, + ) + + /** + * List snapshots. List snapshots. You can include the `instance_id` or + * `project_id` in your query to get the list of snapshots for specific + * Database Instances and/or Projects. By default, the details 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 ListSnapshotsRequest} + * @returns A Promise of ListSnapshotsResponse + */ + listSnapshots = (request: Readonly = {}) => + enrichForPagination('snapshots', this.pageOfListSnapshots, request) + + /** + * Delete a Database Instance snapshot. Delete a given snapshot of a Database + * Instance. You must specify, in the endpoint, the `snapshot_id` parameter of + * the snapshot you want to delete. + * + * @param request - The request {@link DeleteSnapshotRequest} + * @returns A Promise of Snapshot + */ + deleteSnapshot = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/snapshots/${validatePathParam('snapshotId', request.snapshotId)}`, + }, + unmarshalSnapshot, + ) + + protected pageOfListUsers = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/users`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListUsersResponse, + ) + + /** + * List users of a Database Instance. List all users of a given Database + * Instance. + * + * @param request - The request {@link ListUsersRequest} + * @returns A Promise of ListUsersResponse + */ + listUsers = (request: Readonly) => + enrichForPagination('users', this.pageOfListUsers, request) + + /** + * Update a user on a Database Instance. Update the parameters of a user on a + * Database Instance. You can update the `password` parameter, but you cannot + * change the name of the user. + * + * @param request - The request {@link UpdateUserRequest} + * @returns A Promise of User + */ + updateUser = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateUserRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/mongodb/v1alpha1/regions/${validatePathParam('region', request.region ?? this.client.settings.defaultRegion)}/instances/${validatePathParam('instanceId', request.instanceId)}/users/${validatePathParam('name', request.name)}`, + }, + unmarshalUser, + ) +} diff --git a/packages/clients/src/api/mongodb/v1alpha1/content.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/content.gen.ts new file mode 100644 index 000000000..9b9df80fd --- /dev/null +++ b/packages/clients/src/api/mongodb/v1alpha1/content.gen.ts @@ -0,0 +1,19 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { InstanceStatus, SnapshotStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link InstanceStatus}. */ +export const INSTANCE_TRANSIENT_STATUSES: InstanceStatus[] = [ + 'provisioning', + 'configuring', + 'deleting', + 'initializing', + 'snapshotting', +] + +/** Lists transient statutes of the enum {@link SnapshotStatus}. */ +export const SNAPSHOT_TRANSIENT_STATUSES: SnapshotStatus[] = [ + 'creating', + 'restoring', + 'deleting', +] diff --git a/packages/clients/src/api/mongodb/v1alpha1/index.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/index.gen.ts new file mode 100644 index 000000000..097cb493b --- /dev/null +++ b/packages/clients/src/api/mongodb/v1alpha1/index.gen.ts @@ -0,0 +1,54 @@ +// 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 { + CreateInstanceRequest, + CreateInstanceRequestVolumeDetails, + CreateSnapshotRequest, + DeleteInstanceRequest, + DeleteSnapshotRequest, + Endpoint, + EndpointPrivateNetworkDetails, + EndpointPublicDetails, + EndpointSpec, + EndpointSpecPrivateNetworkDetails, + EndpointSpecPublicDetails, + GetInstanceCertificateRequest, + GetInstanceRequest, + Instance, + InstanceSetting, + InstanceStatus, + ListInstancesRequest, + ListInstancesRequestOrderBy, + ListInstancesResponse, + ListNodeTypesRequest, + ListNodeTypesResponse, + ListSnapshotsRequest, + ListSnapshotsRequestOrderBy, + ListSnapshotsResponse, + ListUsersRequest, + ListUsersRequestOrderBy, + ListUsersResponse, + ListVersionsRequest, + ListVersionsResponse, + NodeType, + NodeTypeStock, + NodeTypeVolumeType, + RestoreSnapshotRequest, + RestoreSnapshotRequestVolumeDetails, + Setting, + SettingPropertyType, + Snapshot, + SnapshotStatus, + SnapshotVolumeType, + UpdateInstanceRequest, + UpdateSnapshotRequest, + UpdateUserRequest, + UpgradeInstanceRequest, + User, + Version, + Volume, + VolumeType, +} from './types.gen' +export * as ValidationRules from './validation-rules.gen' diff --git a/packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts new file mode 100644 index 000000000..209d01605 --- /dev/null +++ b/packages/clients/src/api/mongodb/v1alpha1/marshalling.gen.ts @@ -0,0 +1,462 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + isJSONObject, + resolveOneOf, + unmarshalArrayOfObject, + unmarshalDate, +} from '../../../bridge' +import type { DefaultValues } from '../../../bridge' +import type { + CreateInstanceRequest, + CreateInstanceRequestVolumeDetails, + CreateSnapshotRequest, + Endpoint, + EndpointPrivateNetworkDetails, + EndpointPublicDetails, + EndpointSpec, + EndpointSpecPrivateNetworkDetails, + EndpointSpecPublicDetails, + Instance, + InstanceSetting, + ListInstancesResponse, + ListNodeTypesResponse, + ListSnapshotsResponse, + ListUsersResponse, + ListVersionsResponse, + NodeType, + NodeTypeVolumeType, + RestoreSnapshotRequest, + RestoreSnapshotRequestVolumeDetails, + Setting, + Snapshot, + SnapshotVolumeType, + UpdateInstanceRequest, + UpdateSnapshotRequest, + UpdateUserRequest, + UpgradeInstanceRequest, + User, + Version, + Volume, +} from './types.gen' + +const unmarshalEndpointPrivateNetworkDetails = ( + data: unknown, +): EndpointPrivateNetworkDetails => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'EndpointPrivateNetworkDetails' failed as data isn't a dictionary.`, + ) + } + + return { + privateNetworkId: data.private_network_id, + } as EndpointPrivateNetworkDetails +} + +const unmarshalEndpointPublicDetails = ( + data: unknown, +): EndpointPublicDetails => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'EndpointPublicDetails' failed as data isn't a dictionary.`, + ) + } + + return {} as EndpointPublicDetails +} + +const unmarshalEndpoint = (data: unknown): Endpoint => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Endpoint' failed as data isn't a dictionary.`, + ) + } + + return { + dnsRecords: data.dns_records, + id: data.id, + ips: data.ips, + port: data.port, + privateNetwork: data.private_network + ? unmarshalEndpointPrivateNetworkDetails(data.private_network) + : undefined, + public: data.public + ? unmarshalEndpointPublicDetails(data.public) + : undefined, + } as Endpoint +} + +export const unmarshalInstanceSetting = (data: unknown): InstanceSetting => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'InstanceSetting' failed as data isn't a dictionary.`, + ) + } + + return { + name: data.name, + value: data.value, + } as InstanceSetting +} + +export const unmarshalVolume = (data: unknown): Volume => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Volume' failed as data isn't a dictionary.`, + ) + } + + return { + size: data.size, + type: data.type, + } as Volume +} + +export const unmarshalInstance = (data: unknown): Instance => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Instance' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + endpoints: unmarshalArrayOfObject(data.endpoints, unmarshalEndpoint), + id: data.id, + name: data.name, + nodeNumber: data.node_number, + nodeType: data.node_type, + projectId: data.project_id, + region: data.region, + settings: unmarshalArrayOfObject(data.settings, unmarshalInstanceSetting), + status: data.status, + tags: data.tags, + version: data.version, + volume: data.volume ? unmarshalVolume(data.volume) : undefined, + } as Instance +} + +const unmarshalSnapshotVolumeType = (data: unknown): SnapshotVolumeType => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SnapshotVolumeType' failed as data isn't a dictionary.`, + ) + } + + return { + type: data.type, + } as SnapshotVolumeType +} + +export const unmarshalSnapshot = (data: unknown): Snapshot => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Snapshot' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + expiresAt: unmarshalDate(data.expires_at), + id: data.id, + instanceId: data.instance_id, + instanceName: data.instance_name, + name: data.name, + nodeType: data.node_type, + region: data.region, + size: data.size, + status: data.status, + updatedAt: unmarshalDate(data.updated_at), + volumeType: data.volume_type + ? unmarshalSnapshotVolumeType(data.volume_type) + : undefined, + } as Snapshot +} + +export const unmarshalUser = (data: unknown): User => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'User' failed as data isn't a dictionary.`, + ) + } + + return { + name: data.name, + } as User +} + +export const unmarshalListInstancesResponse = ( + data: unknown, +): ListInstancesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListInstancesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + instances: unmarshalArrayOfObject(data.instances, unmarshalInstance), + totalCount: data.total_count, + } as ListInstancesResponse +} + +const unmarshalNodeTypeVolumeType = (data: unknown): NodeTypeVolumeType => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'NodeTypeVolumeType' failed as data isn't a dictionary.`, + ) + } + + return { + chunkSize: data.chunk_size, + description: data.description, + maxSize: data.max_size, + minSize: data.min_size, + type: data.type, + } as NodeTypeVolumeType +} + +const unmarshalNodeType = (data: unknown): NodeType => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'NodeType' failed as data isn't a dictionary.`, + ) + } + + return { + availableVolumeTypes: unmarshalArrayOfObject( + data.available_volume_types, + unmarshalNodeTypeVolumeType, + ), + beta: data.beta, + description: data.description, + disabled: data.disabled, + instanceRange: data.instance_range, + memory: data.memory, + name: data.name, + stockStatus: data.stock_status, + vcpus: data.vcpus, + } as NodeType +} + +export const unmarshalListNodeTypesResponse = ( + data: unknown, +): ListNodeTypesResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListNodeTypesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + nodeTypes: unmarshalArrayOfObject(data.node_types, unmarshalNodeType), + totalCount: data.total_count, + } as ListNodeTypesResponse +} + +export const unmarshalListSnapshotsResponse = ( + data: unknown, +): ListSnapshotsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListSnapshotsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + snapshots: unmarshalArrayOfObject(data.snapshots, unmarshalSnapshot), + totalCount: data.total_count, + } as ListSnapshotsResponse +} + +export const unmarshalListUsersResponse = ( + data: unknown, +): ListUsersResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListUsersResponse' failed as data isn't a dictionary.`, + ) + } + + return { + totalCount: data.total_count, + users: unmarshalArrayOfObject(data.users, unmarshalUser), + } as ListUsersResponse +} + +const unmarshalSetting = (data: unknown): Setting => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Setting' failed as data isn't a dictionary.`, + ) + } + + return { + defaultValue: data.default_value, + description: data.description, + floatMax: data.float_max, + floatMin: data.float_min, + hotConfigurable: data.hot_configurable, + intMax: data.int_max, + intMin: data.int_min, + name: data.name, + propertyType: data.property_type, + stringConstraint: data.string_constraint, + unit: data.unit, + } as Setting +} + +const unmarshalVersion = (data: unknown): Version => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Version' failed as data isn't a dictionary.`, + ) + } + + return { + availableSettings: unmarshalArrayOfObject( + data.available_settings, + unmarshalSetting, + ), + endOfLifeAt: unmarshalDate(data.end_of_life_at), + version: data.version, + } as Version +} + +export const unmarshalListVersionsResponse = ( + data: unknown, +): ListVersionsResponse => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListVersionsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + totalCount: data.total_count, + versions: unmarshalArrayOfObject(data.versions, unmarshalVersion), + } as ListVersionsResponse +} + +const marshalEndpointSpecPrivateNetworkDetails = ( + request: EndpointSpecPrivateNetworkDetails, + defaults: DefaultValues, +): Record => ({ + private_network_id: request.privateNetworkId, +}) + +const marshalEndpointSpecPublicDetails = ( + request: EndpointSpecPublicDetails, + defaults: DefaultValues, +): Record => ({}) + +const marshalCreateInstanceRequestVolumeDetails = ( + request: CreateInstanceRequestVolumeDetails, + defaults: DefaultValues, +): Record => ({ + volume_size: request.volumeSize, + volume_type: request.volumeType, +}) + +const marshalEndpointSpec = ( + request: EndpointSpec, + defaults: DefaultValues, +): Record => ({ + ...resolveOneOf([ + { + param: 'public', + value: + request.public !== undefined + ? marshalEndpointSpecPublicDetails(request.public, defaults) + : undefined, + }, + { + param: 'private_network', + value: + request.privateNetwork !== undefined + ? marshalEndpointSpecPrivateNetworkDetails( + request.privateNetwork, + defaults, + ) + : undefined, + }, + ]), +}) + +export const marshalCreateInstanceRequest = ( + request: CreateInstanceRequest, + defaults: DefaultValues, +): Record => ({ + endpoints: + request.endpoints !== undefined + ? request.endpoints.map(elt => marshalEndpointSpec(elt, defaults)) + : undefined, + name: request.name, + node_number: request.nodeNumber, + node_type: request.nodeType, + password: request.password, + project_id: request.projectId ?? defaults.defaultProjectId, + tags: request.tags, + user_name: request.userName, + version: request.version, + volume: + request.volume !== undefined + ? marshalCreateInstanceRequestVolumeDetails(request.volume, defaults) + : undefined, +}) + +export const marshalCreateSnapshotRequest = ( + request: CreateSnapshotRequest, + defaults: DefaultValues, +): Record => ({ + expires_at: request.expiresAt, + name: request.name, +}) + +const marshalRestoreSnapshotRequestVolumeDetails = ( + request: RestoreSnapshotRequestVolumeDetails, + defaults: DefaultValues, +): Record => ({ + volume_type: request.volumeType, +}) + +export const marshalRestoreSnapshotRequest = ( + request: RestoreSnapshotRequest, + defaults: DefaultValues, +): Record => ({ + instance_name: request.instanceName, + node_number: request.nodeNumber, + node_type: request.nodeType, + volume: marshalRestoreSnapshotRequestVolumeDetails(request.volume, defaults), +}) + +export const marshalUpdateInstanceRequest = ( + request: UpdateInstanceRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + tags: request.tags, +}) + +export const marshalUpdateSnapshotRequest = ( + request: UpdateSnapshotRequest, + defaults: DefaultValues, +): Record => ({ + expires_at: request.expiresAt, + name: request.name, +}) + +export const marshalUpdateUserRequest = ( + request: UpdateUserRequest, + defaults: DefaultValues, +): Record => ({ + password: request.password, +}) + +export const marshalUpgradeInstanceRequest = ( + request: UpgradeInstanceRequest, + defaults: DefaultValues, +): Record => ({ + ...resolveOneOf([{ param: 'volume_size', value: request.volumeSize }]), +}) diff --git a/packages/clients/src/api/mongodb/v1alpha1/types.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/types.gen.ts new file mode 100644 index 000000000..9ab5c41e2 --- /dev/null +++ b/packages/clients/src/api/mongodb/v1alpha1/types.gen.ts @@ -0,0 +1,531 @@ +// 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 InstanceStatus = + | 'unknown_status' + | 'ready' + | 'provisioning' + | 'configuring' + | 'deleting' + | 'error' + | 'initializing' + | 'locked' + | 'snapshotting' + +export type ListInstancesRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + | 'status_asc' + | 'status_desc' + +export type ListSnapshotsRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + | 'expires_at_asc' + | 'expires_at_desc' + +export type ListUsersRequestOrderBy = 'name_asc' | 'name_desc' + +export type NodeTypeStock = + | 'unknown_stock' + | 'low_stock' + | 'out_of_stock' + | 'available' + +export type SettingPropertyType = 'BOOLEAN' | 'INT' | 'STRING' | 'FLOAT' + +export type SnapshotStatus = + | 'unknown_status' + | 'creating' + | 'ready' + | 'restoring' + | 'deleting' + | 'error' + | 'locked' + +export type VolumeType = 'unknown_type' | 'sbs_5k' | 'sbs_15k' + +/** Private Network details. */ +export interface EndpointPrivateNetworkDetails { + /** UUID of the private network. */ + privateNetworkId: string +} + +export interface EndpointPublicDetails {} + +export interface EndpointSpecPrivateNetworkDetails { + /** UUID of the private network. */ + privateNetworkId: string +} + +export interface EndpointSpecPublicDetails {} + +export interface Endpoint { + /** UUID of the endpoint. */ + id: string + /** List of IPv4 addresses of the endpoint. */ + ips: string[] + /** List of DNS records of the endpoint. */ + dnsRecords: string[] + /** TCP port of the endpoint. */ + port: number + /** + * Private Network endpoint details. + * + * One-of ('details'): at most one of 'privateNetwork', 'public' could be set. + */ + privateNetwork?: EndpointPrivateNetworkDetails + /** + * Public endpoint details. + * + * One-of ('details'): at most one of 'privateNetwork', 'public' could be set. + */ + public?: EndpointPublicDetails +} + +export interface InstanceSetting { + /** Name of the settings. */ + name: string + /** Value of the settings. */ + value: string +} + +export interface Volume { + /** Type of volume where data is stored. */ + type: VolumeType + /** Volume size. */ + size: number +} + +export interface NodeTypeVolumeType { + /** Volume Type. */ + type: VolumeType + /** The description of the Volume. */ + description: string + /** Mimimum size required for the Volume. */ + minSize: number + /** Maximum size required for the Volume. */ + maxSize: number + /** Minimum increment level for a Block Storage volume size. */ + chunkSize: number +} + +export interface SnapshotVolumeType { + type: VolumeType +} + +export interface Setting { + /** Setting name from the database engine. */ + name: string + /** Value set when not specified. */ + defaultValue: string + /** Setting can be applied without restarting. */ + hotConfigurable: boolean + /** Setting description. */ + description: string + /** Setting type. */ + propertyType: SettingPropertyType + /** Setting base unit. */ + unit?: string + /** Validation regex for string type settings. */ + stringConstraint?: string + /** Minimum value for int types. */ + intMin?: number + /** Maximum value for int types. */ + intMax?: number + /** Minimum value for float types. */ + floatMin?: number + /** Maximum value for float types. */ + floatMax?: number +} + +export interface CreateInstanceRequestVolumeDetails { + /** Volume size. */ + volumeSize: number + /** Type of volume where data is stored. */ + volumeType: VolumeType +} + +export interface EndpointSpec { + /** One-of ('details'): at most one of 'public', 'privateNetwork' could be set. */ + public?: EndpointSpecPublicDetails + /** One-of ('details'): at most one of 'public', 'privateNetwork' could be set. */ + privateNetwork?: EndpointSpecPrivateNetworkDetails +} + +export interface Instance { + /** UUID of the Database Instance. */ + id: string + /** Name of the Database Instance. */ + name: string + /** Project ID the Database Instance belongs to. */ + projectId: string + /** Status of the Database Instance. */ + status: InstanceStatus + /** MongoDB™ engine version of the Database Instance. */ + version: string + /** List of tags applied to the Database Instance. */ + tags: string[] + /** Advanced settings of the Database Instance. */ + settings: InstanceSetting[] + /** Number of node in the Database Instance. */ + nodeNumber: number + /** Node type of the Database Instance. */ + nodeType: string + /** Volumes of the Database Instance. */ + volume?: Volume + /** List of Database Instance endpoints. */ + endpoints: Endpoint[] + /** Creation date (must follow the ISO 8601 format). */ + createdAt?: Date + /** Region the Database Instance is in. */ + region: Region +} + +export interface NodeType { + /** Node Type name identifier. */ + name: string + /** Current stock status for the Node Type. */ + stockStatus: NodeTypeStock + /** Current specs of the offer. */ + description: string + /** Number of virtual CPUs. */ + vcpus: number + /** Quantity of RAM. */ + memory: number + /** Available storage options for the Node Type. */ + availableVolumeTypes: NodeTypeVolumeType[] + /** The Node Type is currently disabled. */ + disabled: boolean + /** The Node Type is currently in beta. */ + beta: boolean + /** Instance range associated with the NodeType offer. */ + instanceRange: string +} + +export interface Snapshot { + /** UUID of the snapshot. */ + id: string + /** UUID of the Database Instance. */ + instanceId: string + /** Name of the snapshot. */ + name: string + /** Status of the snapshot. */ + status: SnapshotStatus + /** Size of the snapshot. */ + size: number + /** Expiration date (must follow the ISO 8601 format). */ + expiresAt?: Date + /** Creation date (must follow the ISO 8601 format). */ + createdAt?: Date + /** Updated date (must follow the ISO 8601 format). */ + updatedAt?: Date + /** Name of the Database Instance of the snapshot. */ + instanceName: string + /** Source node type. */ + nodeType: string + /** Type of volume where data is stored sbs_5k or sbs_15k. */ + volumeType?: SnapshotVolumeType + /** Region of this snapshot. */ + region: Region +} + +export interface User { + /** + * Name of the user (Length must be between 1 and 63 characters. First + * character must be an alphabet character (a-zA-Z). Only a-zA-Z0-9_$- + * characters are accepted). + */ + name: string +} + +export interface Version { + /** MongoDB™ engine version. */ + version: string + /** Date of End of Life. */ + endOfLifeAt?: Date + /** Instance settings available to be updated. */ + availableSettings: Setting[] +} + +export interface RestoreSnapshotRequestVolumeDetails { + /** Type of volume where data is stored. */ + volumeType: VolumeType +} + +export type CreateInstanceRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** The Project ID on which the Database Instance will be created. */ + projectId?: string + /** Name of the Database Instance. */ + name: string + /** Version of the MongoDB™ engine. */ + version: string + /** Tags to apply to the Database Instance. */ + tags?: string[] + /** Number of node to use for the Database Instance. */ + nodeNumber: number + /** Type of node to use for the Database Instance. */ + nodeType: string + /** Username created when the Database Instance is created. */ + userName: string + /** Password of the initial user. */ + password: string + /** Instance volume information. */ + volume?: CreateInstanceRequestVolumeDetails + /** One or multiple EndpointSpec used to expose your Database Instance. */ + endpoints?: EndpointSpec[] +} + +export type CreateSnapshotRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance to snapshot. */ + instanceId: string + /** Name of the snapshot. */ + name: string + /** Expiration date of the snapshot (must follow the ISO 8601 format). */ + expiresAt?: Date +} + +export type DeleteInstanceRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance to delete. */ + instanceId: string +} + +export type DeleteSnapshotRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the snapshot. */ + snapshotId: string +} + +export type GetInstanceCertificateRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance. */ + instanceId: string +} + +export type GetInstanceRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance. */ + instanceId: string +} + +export type ListInstancesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** List Database Instances that have a given tag. */ + tags?: string[] + /** Lists Database Instances that match a name pattern. */ + name?: string + /** Criteria to use when ordering Database Instance listings. */ + orderBy?: ListInstancesRequestOrderBy + /** Organization ID the Database Instance belongs to. */ + organizationId?: string + /** Project ID to list the Database Instance of. */ + projectId?: string + page?: number + pageSize?: number +} + +export interface ListInstancesResponse { + /** List of all Database Instances available in an Organization or Project. */ + instances: Instance[] + /** Total count of Database Instances available in a Organization or Project. */ + totalCount: number +} + +export type ListNodeTypesRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Defines whether or not to include disabled types. */ + includeDisabledTypes?: boolean + page?: number + pageSize?: number +} + +export interface ListNodeTypesResponse { + /** Types of the node. */ + nodeTypes: NodeType[] + /** Total count of node-types available. */ + totalCount: number +} + +export type ListSnapshotsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** Instance ID the snapshots belongs to. */ + instanceId?: string + /** Lists Database snapshots that match a name pattern. */ + name?: string + /** Criteria to use when ordering snapshot listings. */ + orderBy?: ListSnapshotsRequestOrderBy + /** Organization ID the snapshots belongs to. */ + organizationId?: string + /** Project ID to list the snapshots of. */ + projectId?: string + page?: number + pageSize?: number +} + +export interface ListSnapshotsResponse { + /** List of all Database Snapshots available in an Organization or Project. */ + snapshots: Snapshot[] + /** Total count of Database Snapshots available in a Organization or Project. */ + totalCount: number +} + +export type ListUsersRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance. */ + instanceId: string + /** Name of the user. */ + name?: string + /** Criteria to use when requesting user listing. */ + orderBy?: ListUsersRequestOrderBy + page?: number + pageSize?: number +} + +export interface ListUsersResponse { + /** List of users in a Database Instance. */ + users: User[] + /** Total count of users present on a Database Instance. */ + totalCount: number +} + +export type ListVersionsRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + version?: string + page?: number + pageSize?: number +} + +export interface ListVersionsResponse { + /** Available MongoDB™ engine version. */ + versions: Version[] + /** Total count of MongoDB™ engine version available. */ + totalCount: number +} + +export type RestoreSnapshotRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the snapshot. */ + snapshotId: string + /** Name of the new Database Instance. */ + instanceName: string + /** Node type to use for the new Database Instance. */ + nodeType: string + /** Number of nodes to use for the new Database Instance. */ + nodeNumber: number + /** Instance volume information. */ + volume: RestoreSnapshotRequestVolumeDetails +} + +export type UpdateInstanceRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance to update. */ + instanceId: string + /** Name of the Database Instance. */ + name?: string + /** Tags of a Database Instance. */ + tags?: string[] +} + +export type UpdateSnapshotRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Snapshot. */ + snapshotId: string + /** Name of the snapshot. */ + name?: string + /** Expiration date of the snapshot (must follow the ISO 8601 format). */ + expiresAt?: Date +} + +export type UpdateUserRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance the user belongs to. */ + instanceId: string + /** Name of the database user. */ + name: string + /** Password of the database user. */ + password?: string +} + +export type UpgradeInstanceRequest = { + /** + * Region to target. If none is passed will use default region from the + * config. + */ + region?: Region + /** UUID of the Database Instance you want to upgrade. */ + instanceId: string + /** + * Increase your block storage volume size. + * + * One-of ('upgradeTarget'): at most one of 'volumeSize' could be set. + */ + volumeSize?: number +} diff --git a/packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts b/packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts new file mode 100644 index 000000000..9762ef08b --- /dev/null +++ b/packages/clients/src/api/mongodb/v1alpha1/validation-rules.gen.ts @@ -0,0 +1,147 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. + +export const CreateInstanceRequest = { + name: { + maxLength: 255, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, + nodeNumber: { + greaterThanOrEqual: 1, + lessThanOrEqual: 3, + }, + nodeType: { + maxLength: 128, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, + password: { + maxLength: 128, + minLength: 8, + }, + userName: { + maxLength: 63, + minLength: 1, + pattern: /^[a-zA-Z0-9_\-]*$/, + }, + version: { + pattern: /^[0-9]+\.[0-9]+\.[0-9]+$/, + }, +} + +export const CreateSnapshotRequest = { + name: { + maxLength: 255, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, +} + +export const ListInstancesRequest = { + name: { + maxLength: 255, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, +} + +export const ListNodeTypesRequest = { + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, +} + +export const ListSnapshotsRequest = { + name: { + maxLength: 255, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, +} + +export const ListUsersRequest = { + name: { + maxLength: 63, + minLength: 1, + pattern: /^[a-zA-Z0-9_\-]*$/, + }, + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, +} + +export const ListVersionsRequest = { + page: { + greaterThanOrEqual: 1, + }, + pageSize: { + greaterThanOrEqual: 1, + lessThanOrEqual: 100, + }, + version: { + pattern: /^[0-9]+\.[0-9]+\.[0-9]+$/, + }, +} + +export const RestoreSnapshotRequest = { + instanceName: { + maxLength: 255, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, + nodeNumber: { + greaterThanOrEqual: 1, + lessThanOrEqual: 3, + }, +} + +export const UpdateInstanceRequest = { + name: { + maxLength: 255, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, +} + +export const UpdateSnapshotRequest = { + name: { + maxLength: 255, + minLength: 1, + pattern: /^[A-Za-z0-9\-_]+$/, + }, +} + +export const UpdateUserRequest = { + name: { + maxLength: 63, + minLength: 1, + pattern: /^[a-zA-Z0-9_\-]*$/, + }, + password: { + maxLength: 128, + minLength: 8, + }, +}