From 00efb00b0de7fa8636ec42ad73420275a3948f35 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Tue, 4 Oct 2022 09:44:39 +0000 Subject: [PATCH 1/2] feat: update generated APIs --- packages/clients/src/api/redis/v1/api.gen.ts | 646 ++++++++++++++++++ .../clients/src/api/redis/v1/content.gen.ts | 12 + .../src/api/redis/v1/marshalling.gen.ts | 483 +++++++++++++ .../clients/src/api/redis/v1/types.gen.ts | 539 +++++++++++++++ 4 files changed, 1680 insertions(+) create mode 100644 packages/clients/src/api/redis/v1/api.gen.ts create mode 100644 packages/clients/src/api/redis/v1/content.gen.ts create mode 100644 packages/clients/src/api/redis/v1/marshalling.gen.ts create mode 100644 packages/clients/src/api/redis/v1/types.gen.ts diff --git a/packages/clients/src/api/redis/v1/api.gen.ts b/packages/clients/src/api/redis/v1/api.gen.ts new file mode 100644 index 000000000..28df58146 --- /dev/null +++ b/packages/clients/src/api/redis/v1/api.gen.ts @@ -0,0 +1,646 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + API, + enrichForPagination, + unmarshalScwFile, + urlParams, + validatePathParam, + waitForResource, +} from '../../../bridge' +import type { ScwFile, WaitForOptions, Zone } from '../../../bridge' +import { CLUSTER_TRANSIENT_STATUSES } from './content.gen' +import { + marshalAddAclRulesRequest, + marshalAddClusterSettingsRequest, + marshalAddEndpointsRequest, + marshalCreateClusterRequest, + marshalMigrateClusterRequest, + marshalSetAclRulesRequest, + marshalSetClusterSettingsRequest, + marshalSetEndpointsRequest, + marshalUpdateClusterRequest, + marshalUpdateEndpointRequest, + unmarshalACLRule, + unmarshalAddAclRulesResponse, + unmarshalAddEndpointsResponse, + unmarshalCluster, + unmarshalClusterMetricsResponse, + unmarshalClusterSettingsResponse, + unmarshalEndpoint, + unmarshalListClusterVersionsResponse, + unmarshalListClustersResponse, + unmarshalListNodeTypesResponse, + unmarshalSetAclRulesResponse, + unmarshalSetEndpointsResponse, +} from './marshalling.gen' +import type { + ACLRule, + AddAclRulesRequest, + AddAclRulesResponse, + AddClusterSettingsRequest, + AddEndpointsRequest, + AddEndpointsResponse, + Cluster, + ClusterMetricsResponse, + ClusterSettingsResponse, + CreateClusterRequest, + DeleteAclRuleRequest, + DeleteClusterRequest, + DeleteClusterSettingRequest, + DeleteEndpointRequest, + Endpoint, + GetAclRuleRequest, + GetClusterCertificateRequest, + GetClusterMetricsRequest, + GetClusterRequest, + GetEndpointRequest, + ListClusterVersionsRequest, + ListClusterVersionsResponse, + ListClustersRequest, + ListClustersResponse, + ListNodeTypesRequest, + ListNodeTypesResponse, + MigrateClusterRequest, + RenewClusterCertificateRequest, + SetAclRulesRequest, + SetAclRulesResponse, + SetClusterSettingsRequest, + SetEndpointsRequest, + SetEndpointsResponse, + UpdateClusterRequest, + UpdateEndpointRequest, +} from './types.gen' + +const jsonContentHeaders = { + 'Content-Type': 'application/json; charset=utf-8', +} + +/** Managed Database for Redis™ API. */ +export class RedisV1GenAPI extends API { + /** Lists the available zones of the API. */ + public static readonly LOCALITIES: Zone[] = [ + 'fr-par-1', + 'fr-par-2', + 'nl-ams-1', + 'pl-waw-1', + ] + + /** + * Create a cluster + * + * @param request - The request {@link CreateClusterRequest} + * @returns A Promise of Cluster + */ + createCluster = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalCreateClusterRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters`, + }, + unmarshalCluster, + ) + + /** + * Update a cluster + * + * @param request - The request {@link UpdateClusterRequest} + * @returns A Promise of Cluster + */ + updateCluster = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateClusterRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam('clusterId', request.clusterId)}`, + }, + unmarshalCluster, + ) + + /** + * Get a cluster + * + * @param request - The request {@link GetClusterRequest} + * @returns A Promise of Cluster + */ + getCluster = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam('clusterId', request.clusterId)}`, + }, + unmarshalCluster, + ) + + /** + * Waits for {@link Cluster} to be in a final state. + * + * @param request - The request {@link GetClusterRequest} + * @param options - The waiting options + * @returns A Promise of Cluster + */ + waitForCluster = ( + request: Readonly, + options?: Readonly>, + ) => + waitForResource( + options?.stop ?? + (res => + Promise.resolve(!CLUSTER_TRANSIENT_STATUSES.includes(res.status))), + this.getCluster, + request, + options, + ) + + protected pageOfListClusters = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters`, + urlParams: urlParams( + ['name', request.name], + ['order_by', request.orderBy ?? 'created_at_asc'], + [ + '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], + ), + }, + unmarshalListClustersResponse, + ) + + /** + * List clusters + * + * @param request - The request {@link ListClustersRequest} + * @returns A Promise of ListClustersResponse + */ + listClusters = (request: Readonly = {}) => + enrichForPagination('clusters', this.pageOfListClusters, request) + + /** + * Upgrade your Database for Redis® cluster to a new version or scale it + * vertically / horizontally. Please note: scaling horizontally your Database + * for Redis® cluster won't renew its TLS certificate. In order to refresh the + * SSL certificate, you have to use the dedicated api route. + * + * @param request - The request {@link MigrateClusterRequest} + * @returns A Promise of Cluster + */ + migrateCluster = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalMigrateClusterRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/migrate`, + }, + unmarshalCluster, + ) + + /** + * Delete a cluster + * + * @param request - The request {@link DeleteClusterRequest} + * @returns A Promise of Cluster + */ + deleteCluster = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam('clusterId', request.clusterId)}`, + }, + unmarshalCluster, + ) + + /** + * Get metrics of a cluster + * + * @param request - The request {@link GetClusterMetricsRequest} + * @returns A Promise of ClusterMetricsResponse + */ + getClusterMetrics = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/metrics`, + urlParams: urlParams( + ['end_at', request.endAt], + ['metric_name', request.metricName], + ['start_at', request.startAt], + ), + }, + unmarshalClusterMetricsResponse, + ) + + protected pageOfListNodeTypes = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/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 pageOfListClusterVersions = ( + request: Readonly, + ) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/cluster-versions`, + urlParams: urlParams( + ['include_beta', request.includeBeta], + ['include_deprecated', request.includeDeprecated], + ['include_disabled', request.includeDisabled], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ['version', request.version], + ), + }, + unmarshalListClusterVersionsResponse, + ) + + /** + * List available Redis™ versions + * + * @param request - The request {@link ListClusterVersionsRequest} + * @returns A Promise of ListClusterVersionsResponse + */ + listClusterVersions = (request: Readonly) => + enrichForPagination('versions', this.pageOfListClusterVersions, request) + + /** + * Get the TLS certificate of a cluster + * + * @param request - The request {@link GetClusterCertificateRequest} + * @returns A Promise of ScwFile + */ + getClusterCertificate = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/certificate`, + }, + unmarshalScwFile, + ) + + /** + * Renew the TLS certificate of a cluster + * + * @param request - The request {@link RenewClusterCertificateRequest} + * @returns A Promise of Cluster + */ + renewClusterCertificate = ( + request: Readonly, + ) => + this.client.fetch( + { + body: '{}', + headers: jsonContentHeaders, + method: 'POST', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/renew-certificate`, + }, + unmarshalCluster, + ) + + /** + * Add cluster settings + * + * @param request - The request {@link AddClusterSettingsRequest} + * @returns A Promise of ClusterSettingsResponse + */ + addClusterSettings = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalAddClusterSettingsRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/settings`, + }, + unmarshalClusterSettingsResponse, + ) + + /** + * Delete a cluster setting + * + * @param request - The request {@link DeleteClusterSettingRequest} + * @returns A Promise of Cluster + */ + deleteClusterSetting = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/settings/${validatePathParam('settingName', request.settingName)}`, + }, + unmarshalCluster, + ) + + /** + * Set cluster settings + * + * @param request - The request {@link SetClusterSettingsRequest} + * @returns A Promise of ClusterSettingsResponse + */ + setClusterSettings = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalSetClusterSettingsRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PUT', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/settings`, + }, + unmarshalClusterSettingsResponse, + ) + + /** + * Set ACL rules for a given cluster + * + * @param request - The request {@link SetAclRulesRequest} + * @returns A Promise of SetAclRulesResponse + */ + setAclRules = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalSetAclRulesRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PUT', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam('clusterId', request.clusterId)}/acls`, + }, + unmarshalSetAclRulesResponse, + ) + + /** + * Add ACL rules for a given cluster + * + * @param request - The request {@link AddAclRulesRequest} + * @returns A Promise of AddAclRulesResponse + */ + addAclRules = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalAddAclRulesRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam('clusterId', request.clusterId)}/acls`, + }, + unmarshalAddAclRulesResponse, + ) + + /** + * Delete an ACL rule for a given cluster + * + * @param request - The request {@link DeleteAclRuleRequest} + * @returns A Promise of Cluster + */ + deleteAclRule = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/acls/${validatePathParam('aclId', request.aclId)}`, + }, + unmarshalCluster, + ) + + /** + * Get an ACL rule + * + * @param request - The request {@link GetAclRuleRequest} + * @returns A Promise of ACLRule + */ + getAclRule = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/acls/${validatePathParam('aclId', request.aclId)}`, + }, + unmarshalACLRule, + ) + + /** + * Set endpoints for a given cluster + * + * @param request - The request {@link SetEndpointsRequest} + * @returns A Promise of SetEndpointsResponse + */ + setEndpoints = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalSetEndpointsRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PUT', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/endpoints`, + }, + unmarshalSetEndpointsResponse, + ) + + /** + * Add endpoints for a given cluster + * + * @param request - The request {@link AddEndpointsRequest} + * @returns A Promise of AddEndpointsResponse + */ + addEndpoints = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalAddEndpointsRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'POST', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/clusters/${validatePathParam( + 'clusterId', + request.clusterId, + )}/endpoints`, + }, + unmarshalAddEndpointsResponse, + ) + + /** + * Delete an endpoint for a given cluster + * + * @param request - The request {@link DeleteEndpointRequest} + * @returns A Promise of Cluster + */ + deleteEndpoint = (request: Readonly) => + this.client.fetch( + { + method: 'DELETE', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/endpoints/${validatePathParam('endpointId', request.endpointId)}`, + }, + unmarshalCluster, + ) + + /** + * Get an endpoint + * + * @param request - The request {@link GetEndpointRequest} + * @returns A Promise of Endpoint + */ + getEndpoint = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/endpoints/${validatePathParam('endpointId', request.endpointId)}`, + }, + unmarshalEndpoint, + ) + + updateEndpoint = (request: Readonly) => + this.client.fetch( + { + body: JSON.stringify( + marshalUpdateEndpointRequest(request, this.client.settings), + ), + headers: jsonContentHeaders, + method: 'PATCH', + path: `/redis/v1/zones/${validatePathParam( + 'zone', + request.zone ?? this.client.settings.defaultZone, + )}/endpoints/${validatePathParam('endpointId', request.endpointId)}`, + }, + unmarshalEndpoint, + ) +} diff --git a/packages/clients/src/api/redis/v1/content.gen.ts b/packages/clients/src/api/redis/v1/content.gen.ts new file mode 100644 index 000000000..29e34e152 --- /dev/null +++ b/packages/clients/src/api/redis/v1/content.gen.ts @@ -0,0 +1,12 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { ClusterStatus } from './types.gen' + +/** Lists transient statutes of the enum {@link ClusterStatus}. */ +export const CLUSTER_TRANSIENT_STATUSES: ClusterStatus[] = [ + 'provisioning', + 'configuring', + 'deleting', + 'autohealing', + 'initializing', +] diff --git a/packages/clients/src/api/redis/v1/marshalling.gen.ts b/packages/clients/src/api/redis/v1/marshalling.gen.ts new file mode 100644 index 000000000..114ebe6b7 --- /dev/null +++ b/packages/clients/src/api/redis/v1/marshalling.gen.ts @@ -0,0 +1,483 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import randomName from '@scaleway/random-name' +import { + isJSONObject, + resolveOneOf, + unmarshalArrayOfObject, + unmarshalDate, + unmarshalTimeSeries, +} from '../../../bridge' +import type { DefaultValues } from '../../../bridge' +import type { + ACLRule, + ACLRuleSpec, + AddAclRulesRequest, + AddAclRulesResponse, + AddClusterSettingsRequest, + AddEndpointsRequest, + AddEndpointsResponse, + AvailableClusterSetting, + Cluster, + ClusterMetricsResponse, + ClusterSetting, + ClusterSettingsResponse, + ClusterVersion, + CreateClusterRequest, + Endpoint, + EndpointSpec, + EndpointSpecPrivateNetworkSpec, + EndpointSpecPublicNetworkSpec, + ListClusterVersionsResponse, + ListClustersResponse, + ListNodeTypesResponse, + MigrateClusterRequest, + NodeType, + PrivateNetwork, + PublicNetwork, + SetAclRulesRequest, + SetAclRulesResponse, + SetClusterSettingsRequest, + SetEndpointsRequest, + SetEndpointsResponse, + UpdateClusterRequest, + UpdateEndpointRequest, +} from './types.gen' + +const unmarshalPrivateNetwork = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'PrivateNetwork' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + serviceIps: data.service_ips, + zone: data.zone, + } as PrivateNetwork +} + +const unmarshalPublicNetwork = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'PublicNetwork' failed as data isn't a dictionary.`, + ) + } + + return {} as PublicNetwork +} + +export const unmarshalACLRule = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ACLRule' failed as data isn't a dictionary.`, + ) + } + + return { + description: data.description, + id: data.id, + ipCidr: data.ip_cidr, + } as ACLRule +} + +const unmarshalAvailableClusterSetting = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'AvailableClusterSetting' failed as data isn't a dictionary.`, + ) + } + + return { + defaultValue: data.default_value, + deprecated: data.deprecated, + description: data.description, + maxValue: data.max_value, + minValue: data.min_value, + name: data.name, + regex: data.regex, + type: data.type, + } as AvailableClusterSetting +} + +const unmarshalClusterSetting = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ClusterSetting' failed as data isn't a dictionary.`, + ) + } + + return { name: data.name, value: data.value } as ClusterSetting +} + +export const unmarshalEndpoint = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Endpoint' failed as data isn't a dictionary.`, + ) + } + + return { + id: data.id, + ips: data.ips, + port: data.port, + privateNetwork: data.private_network + ? unmarshalPrivateNetwork(data.private_network) + : undefined, + publicNetwork: data.public_network + ? unmarshalPublicNetwork(data.public_network) + : undefined, + } as Endpoint +} + +export const unmarshalCluster = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Cluster' failed as data isn't a dictionary.`, + ) + } + + return { + aclRules: unmarshalArrayOfObject(data.acl_rules, unmarshalACLRule), + clusterSettings: unmarshalArrayOfObject( + data.cluster_settings, + unmarshalClusterSetting, + ), + clusterSize: data.cluster_size, + createdAt: unmarshalDate(data.created_at), + endpoints: unmarshalArrayOfObject(data.endpoints, unmarshalEndpoint), + id: data.id, + name: data.name, + nodeType: data.node_type, + projectId: data.project_id, + status: data.status, + tags: data.tags, + tlsEnabled: data.tls_enabled, + updatedAt: unmarshalDate(data.updated_at), + version: data.version, + zone: data.zone, + } as Cluster +} + +const unmarshalClusterVersion = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ClusterVersion' failed as data isn't a dictionary.`, + ) + } + + return { + availableSettings: unmarshalArrayOfObject( + data.available_settings, + unmarshalAvailableClusterSetting, + ), + endOfLifeAt: unmarshalDate(data.end_of_life_at), + logoUrl: data.logo_url, + version: data.version, + zone: data.zone, + } as ClusterVersion +} + +const unmarshalNodeType = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'NodeType' failed as data isn't a dictionary.`, + ) + } + + return { + beta: data.beta, + description: data.description, + disabled: data.disabled, + memory: data.memory, + name: data.name, + stockStatus: data.stock_status, + vcpus: data.vcpus, + zone: data.zone, + } as NodeType +} + +export const unmarshalAddAclRulesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'AddAclRulesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + aclRules: unmarshalArrayOfObject(data.acl_rules, unmarshalACLRule), + totalCount: data.total_count, + } as AddAclRulesResponse +} + +export const unmarshalAddEndpointsResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'AddEndpointsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + endpoints: unmarshalArrayOfObject(data.endpoints, unmarshalEndpoint), + totalCount: data.total_count, + } as AddEndpointsResponse +} + +export const unmarshalClusterMetricsResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ClusterMetricsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + timeseries: unmarshalArrayOfObject(data.timeseries, unmarshalTimeSeries), + } as ClusterMetricsResponse +} + +export const unmarshalClusterSettingsResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ClusterSettingsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + settings: unmarshalArrayOfObject(data.settings, unmarshalClusterSetting), + } as ClusterSettingsResponse +} + +export const unmarshalListClusterVersionsResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListClusterVersionsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + totalCount: data.total_count, + versions: unmarshalArrayOfObject(data.versions, unmarshalClusterVersion), + } as ListClusterVersionsResponse +} + +export const unmarshalListClustersResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListClustersResponse' failed as data isn't a dictionary.`, + ) + } + + return { + clusters: unmarshalArrayOfObject(data.clusters, unmarshalCluster), + totalCount: data.total_count, + } as ListClustersResponse +} + +export const unmarshalListNodeTypesResponse = (data: unknown) => { + 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 unmarshalSetAclRulesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SetAclRulesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + aclRules: unmarshalArrayOfObject(data.acl_rules, unmarshalACLRule), + } as SetAclRulesResponse +} + +export const unmarshalSetEndpointsResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'SetEndpointsResponse' failed as data isn't a dictionary.`, + ) + } + + return { + endpoints: unmarshalArrayOfObject(data.endpoints, unmarshalEndpoint), + } as SetEndpointsResponse +} + +const marshalEndpointSpecPrivateNetworkSpec = ( + request: EndpointSpecPrivateNetworkSpec, + defaults: DefaultValues, +): Record => ({ + id: request.id, + service_ips: request.serviceIps, +}) + +const marshalEndpointSpecPublicNetworkSpec = ( + request: EndpointSpecPublicNetworkSpec, + defaults: DefaultValues, +): Record => ({}) + +const marshalACLRuleSpec = ( + request: ACLRuleSpec, + defaults: DefaultValues, +): Record => ({ + description: request.description, + ip_cidr: request.ipCidr, +}) + +const marshalClusterSetting = ( + request: ClusterSetting, + defaults: DefaultValues, +): Record => ({ + name: request.name, + value: request.value, +}) + +const marshalEndpointSpec = ( + request: EndpointSpec, + defaults: DefaultValues, +): Record => ({ + ...resolveOneOf([ + { + param: 'private_network', + value: request.privateNetwork + ? marshalEndpointSpecPrivateNetworkSpec( + request.privateNetwork, + defaults, + ) + : undefined, + }, + { + param: 'public_network', + value: request.publicNetwork + ? marshalEndpointSpecPublicNetworkSpec(request.publicNetwork, defaults) + : undefined, + }, + ]), +}) + +export const marshalAddAclRulesRequest = ( + request: AddAclRulesRequest, + defaults: DefaultValues, +): Record => ({ + acl_rules: request.aclRules.map(elt => marshalACLRuleSpec(elt, defaults)), +}) + +export const marshalAddClusterSettingsRequest = ( + request: AddClusterSettingsRequest, + defaults: DefaultValues, +): Record => ({ + settings: request.settings.map(elt => marshalClusterSetting(elt, defaults)), +}) + +export const marshalAddEndpointsRequest = ( + request: AddEndpointsRequest, + defaults: DefaultValues, +): Record => ({ + endpoints: request.endpoints.map(elt => marshalEndpointSpec(elt, defaults)), +}) + +export const marshalCreateClusterRequest = ( + request: CreateClusterRequest, + defaults: DefaultValues, +): Record => ({ + acl_rules: request.aclRules + ? request.aclRules.map(elt => marshalACLRuleSpec(elt, defaults)) + : undefined, + cluster_settings: request.clusterSettings + ? request.clusterSettings.map(elt => marshalClusterSetting(elt, defaults)) + : undefined, + cluster_size: request.clusterSize, + endpoints: request.endpoints + ? request.endpoints.map(elt => marshalEndpointSpec(elt, defaults)) + : undefined, + name: request.name || randomName('ins'), + node_type: request.nodeType, + password: request.password, + project_id: request.projectId ?? defaults.defaultProjectId, + tags: request.tags, + tls_enabled: request.tlsEnabled, + user_name: request.userName, + version: request.version, +}) + +export const marshalMigrateClusterRequest = ( + request: MigrateClusterRequest, + defaults: DefaultValues, +): Record => ({ + ...resolveOneOf([ + { + param: 'version', + value: request.version, + }, + { + param: 'node_type', + value: request.nodeType, + }, + { + param: 'cluster_size', + value: request.clusterSize, + }, + ]), +}) + +export const marshalSetAclRulesRequest = ( + request: SetAclRulesRequest, + defaults: DefaultValues, +): Record => ({ + acl_rules: request.aclRules.map(elt => marshalACLRuleSpec(elt, defaults)), +}) + +export const marshalSetClusterSettingsRequest = ( + request: SetClusterSettingsRequest, + defaults: DefaultValues, +): Record => ({ + settings: request.settings.map(elt => marshalClusterSetting(elt, defaults)), +}) + +export const marshalSetEndpointsRequest = ( + request: SetEndpointsRequest, + defaults: DefaultValues, +): Record => ({ + endpoints: request.endpoints.map(elt => marshalEndpointSpec(elt, defaults)), +}) + +export const marshalUpdateClusterRequest = ( + request: UpdateClusterRequest, + defaults: DefaultValues, +): Record => ({ + name: request.name, + password: request.password, + tags: request.tags, + user_name: request.userName, +}) + +export const marshalUpdateEndpointRequest = ( + request: UpdateEndpointRequest, + defaults: DefaultValues, +): Record => ({ + ...resolveOneOf([ + { + param: 'private_network', + value: request.privateNetwork + ? marshalEndpointSpecPrivateNetworkSpec( + request.privateNetwork, + defaults, + ) + : undefined, + }, + { + param: 'public_network', + value: request.publicNetwork + ? marshalEndpointSpecPublicNetworkSpec(request.publicNetwork, defaults) + : undefined, + }, + ]), +}) diff --git a/packages/clients/src/api/redis/v1/types.gen.ts b/packages/clients/src/api/redis/v1/types.gen.ts new file mode 100644 index 000000000..e6a8b279c --- /dev/null +++ b/packages/clients/src/api/redis/v1/types.gen.ts @@ -0,0 +1,539 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { TimeSeries, Zone } from '../../../bridge' + +export type AvailableClusterSettingPropertyType = + | 'UNKNOWN' + | 'BOOLEAN' + | 'INT' + | 'STRING' + +export type ClusterStatus = + | 'unknown' + | 'ready' + | 'provisioning' + | 'configuring' + | 'deleting' + | 'error' + | 'autohealing' + | 'locked' + | 'suspended' + | 'initializing' + +export type ListClustersRequestOrderBy = + | 'created_at_asc' + | 'created_at_desc' + | 'name_asc' + | 'name_desc' + +export type NodeTypeStock = + | 'unknown' + | 'low_stock' + | 'out_of_stock' + | 'available' + +/** Acl rule */ +export interface ACLRule { + /** ID of the rule */ + id: string + /** IPv4 network address of the rule */ + ipCidr?: string + /** Description of the rule */ + description?: string +} + +/** Acl rule spec */ +export interface ACLRuleSpec { + /** IPv4 network address of the rule */ + ipCidr: string + /** Description of the rule */ + description: string +} + +/** Add acl rules response */ +export interface AddAclRulesResponse { + /** ACL Rules enabled on the cluster */ + aclRules: Array + /** Total count of acl rules of the cluster */ + totalCount: number +} + +/** Add endpoints response */ +export interface AddEndpointsResponse { + /** Endpoints defined on the cluster */ + endpoints: Array + /** Total count of endpoints of the cluster */ + totalCount: number +} + +/** Available cluster setting */ +export interface AvailableClusterSetting { + /** Name of the setting */ + name: string + /** Default value of the setting */ + defaultValue?: string + /** Type of the setting */ + type: AvailableClusterSettingPropertyType + /** Description of the setting */ + description: string + /** Optional maximum value of the setting */ + maxValue?: number + /** Optional minimum value of the setting */ + minValue?: number + /** Optional validation rule of the setting */ + regex?: string + /** Whether the setting is deprecated */ + deprecated: boolean +} + +/** Cluster */ +export interface Cluster { + /** UUID of the cluster */ + id: string + /** Name of the cluster */ + name: string + /** Project ID the cluster belongs to */ + projectId: string + /** Status of the cluster */ + status: ClusterStatus + /** Redis™ engine version of the cluster */ + version: string + /** List of cluster endpoints */ + endpoints: Array + /** List of tags applied to the cluster */ + tags: Array + /** Node type of the cluster */ + nodeType: string + /** Creation date (Format ISO 8601) */ + createdAt?: Date + /** Update date (Format ISO 8601) */ + updatedAt?: Date + /** Whether or not TLS is enabled */ + tlsEnabled: boolean + /** List of cluster settings */ + clusterSettings: Array + /** List of acl rules */ + aclRules: Array + /** Number of nodes of the cluster */ + clusterSize: number + /** Zone of the cluster */ + zone: Zone +} + +/** Cluster metrics response */ +export interface ClusterMetricsResponse { + /** Time series of metrics of a given cluster */ + timeseries: Array +} + +/** Cluster setting */ +export interface ClusterSetting { + /** Value of the setting */ + value: string + /** Name of the setting */ + name: string +} + +/** Cluster settings response */ +export interface ClusterSettingsResponse { + /** Settings configured for a given cluster */ + settings: Array +} + +/** Cluster version */ +export interface ClusterVersion { + /** Redis™ engine version */ + version: string + /** End of life date */ + endOfLifeAt?: Date + /** Cluster settings available to be set */ + availableSettings: Array + /** Redis™ logo url */ + logoUrl: string + /** Zone of the Managed Database for Redis™ */ + zone: Zone +} + +/** Endpoint */ +export interface Endpoint { + /** TCP port of the endpoint */ + port: number + /** + * Private network details. + * + * One-of ('details'): at most one of 'privateNetwork', 'publicNetwork' could be set. + */ + privateNetwork?: PrivateNetwork + /** + * Public network details. + * + * One-of ('details'): at most one of 'privateNetwork', 'publicNetwork' could be set. + */ + publicNetwork?: PublicNetwork + /** Lis of IPv4 address of the endpoint */ + ips: Array + /** UUID of the endpoint */ + id: string +} + +/** Endpoint spec */ +export interface EndpointSpec { + /** + * Private network spec details. + * + * One-of ('endpointType'): at most one of 'privateNetwork', 'publicNetwork' + * could be set. + */ + privateNetwork?: EndpointSpecPrivateNetworkSpec + /** + * Public network spec details. + * + * One-of ('endpointType'): at most one of 'privateNetwork', 'publicNetwork' + * could be set. + */ + publicNetwork?: EndpointSpecPublicNetworkSpec +} + +/** Endpoint spec. private network spec */ +export interface EndpointSpecPrivateNetworkSpec { + /** UUID of the private network to be connected to the cluster */ + id: string + /** + * Endpoint IPv4 adress with a CIDR notation. You must provide at least one + * IPv4 per node. Check documentation about IP and subnet limitation. + */ + serviceIps: Array +} + +/** Endpoint spec. public network spec */ +export interface EndpointSpecPublicNetworkSpec {} + +/** List cluster versions response */ +export interface ListClusterVersionsResponse { + /** List of the available Redis™ engine versions */ + versions: Array + /** Total count of available Redis™ engine versions */ + totalCount: number +} + +/** List clusters response */ +export interface ListClustersResponse { + /** List all clusters */ + clusters: Array + /** Total count of clusters */ + totalCount: number +} + +/** List node types response */ +export interface ListNodeTypesResponse { + /** Types of the node */ + nodeTypes: Array + /** Total count of node-types available */ + totalCount: number +} + +/** Node type */ +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 + /** The Node Type is currently disabled */ + disabled: boolean + /** The Node Type is currently in beta */ + beta: boolean + /** Zone the Node Type is in */ + zone: Zone +} + +/** Private network */ +export interface PrivateNetwork { + /** UUID of the private network */ + id: string + /** List of IPv4 CIDR notation addresses of the endpoint */ + serviceIps: Array + /** Private network zone */ + zone: Zone +} + +export interface PublicNetwork {} + +/** Set acl rules response */ +export interface SetAclRulesResponse { + /** ACL Rules enabled on the cluster */ + aclRules: Array +} + +/** Set endpoints response */ +export interface SetEndpointsResponse { + /** Endpoints defined on the cluster */ + endpoints: Array +} + +export type CreateClusterRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** The project ID on which to create the cluster */ + projectId?: string + /** Name of the cluster */ + name?: string + /** Redis™ engine version of the cluster */ + version: string + /** Tags to apply to the cluster */ + tags?: Array + /** Type of node to use for the cluster */ + nodeType: string + /** Name of the user created when the cluster is created */ + userName: string + /** Password of the user */ + password: string + /** Number of nodes for the cluster */ + clusterSize?: number + /** List of ACLRuleSpec used to secure your publicly exposed cluster */ + aclRules?: Array + /** + * Zero or multiple EndpointSpec used to expose your cluster publicly and + * inside private networks. If no EndpoindSpec is given the cluster will be + * publicly exposed by default. + */ + endpoints?: Array + /** Whether or not TLS is enabled */ + tlsEnabled: boolean + /** List of cluster settings to be set at cluster initialisation */ + clusterSettings?: Array +} + +export type UpdateClusterRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster to update */ + clusterId: string + /** Name of the cluster */ + name?: string + /** Tags of a given cluster */ + tags?: Array + /** Name of the cluster user */ + userName?: string + /** Password of the cluster user */ + password?: string +} + +export type GetClusterRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster */ + clusterId: string +} + +export type ListClustersRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** Tags of the clusters to filter upon */ + tags?: Array + /** Name of the clusters to filter upon */ + name?: string + /** Criteria to use when ordering cluster listing */ + orderBy?: ListClustersRequestOrderBy + /** Project ID to list the cluster of */ + projectId?: string + /** Organization ID to list the cluster of */ + organizationId?: string + page?: number + pageSize?: number +} + +export type MigrateClusterRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster to update */ + clusterId: string + /** + * Redis™ engine version of the cluster. + * + * One-of ('action'): at most one of 'version', 'nodeType', 'clusterSize' could be set. + */ + version?: string + /** + * Type of node to use for the cluster. + * + * One-of ('action'): at most one of 'version', 'nodeType', 'clusterSize' could be set. + */ + nodeType?: string + /** + * Number of nodes for the cluster. + * + * One-of ('action'): at most one of 'version', 'nodeType', 'clusterSize' could be set. + */ + clusterSize?: number +} + +export type DeleteClusterRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster to delete */ + clusterId: string +} + +export type GetClusterMetricsRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster */ + clusterId: string + /** Start date to gather metrics from */ + startAt?: Date + /** End date to gather metrics from */ + endAt?: Date + /** Name of the metric to gather */ + metricName?: string +} + +export type ListNodeTypesRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** Whether or not to include disabled types */ + includeDisabledTypes: boolean + page?: number + pageSize?: number +} + +export type ListClusterVersionsRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** Whether or not to include disabled Redis™ engine versions */ + includeDisabled: boolean + /** Whether or not to include beta Redis™ engine versions */ + includeBeta: boolean + /** Whether or not to include deprecated Redis™ engine versions */ + includeDeprecated: boolean + /** List Redis™ engine versions that match a given name pattern */ + version?: string + page?: number + pageSize?: number +} + +export type GetClusterCertificateRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster */ + clusterId: string +} + +export type RenewClusterCertificateRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster */ + clusterId: string +} + +export type AddClusterSettingsRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster you want to add settings to */ + clusterId: string + /** Settings to add on the cluster */ + settings: Array +} + +export type DeleteClusterSettingRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster where the settings has to be set */ + clusterId: string + /** Setting name to delete */ + settingName: string +} + +export type SetClusterSettingsRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster where the settings has to be set */ + clusterId: string + /** Settings to define for the cluster */ + settings: Array +} + +export type SetAclRulesRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster where the ACL rules has to be set */ + clusterId: string + /** ACLs rules to define for the cluster */ + aclRules: Array +} + +export type AddAclRulesRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster you want to add acl rules to */ + clusterId: string + /** ACLs rules to add to the cluster */ + aclRules: Array +} + +export type DeleteAclRuleRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the acl rule you want to delete */ + aclId: string +} + +export type GetAclRuleRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the acl rule you want to get */ + aclId: string +} + +export type SetEndpointsRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster where the endpoints has to be set */ + clusterId: string + /** Endpoints to define for the cluster */ + endpoints: Array +} + +export type AddEndpointsRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the cluster you want to add endpoints to */ + clusterId: string + /** Endpoints to add to the cluster */ + endpoints: Array +} + +export type DeleteEndpointRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the endpoint you want to delete */ + endpointId: string +} + +export type GetEndpointRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + /** UUID of the endpoint you want to get */ + endpointId: string +} + +export type UpdateEndpointRequest = { + /** Zone to target. If none is passed will use default zone from the config */ + zone?: Zone + endpointId: string + /** + * One-of ('endpointType'): at most one of 'privateNetwork', 'publicNetwork' + * could be set. + */ + privateNetwork?: EndpointSpecPrivateNetworkSpec + /** + * One-of ('endpointType'): at most one of 'privateNetwork', 'publicNetwork' + * could be set. + */ + publicNetwork?: EndpointSpecPublicNetworkSpec +} From b96d85eee1a8c40b6fde9160b6dce41d0aecc467 Mon Sep 17 00:00:00 2001 From: Vincent Germain Date: Tue, 4 Oct 2022 13:34:40 +0200 Subject: [PATCH 2/2] feat: add index --- packages/clients/src/api/redis/index.ts | 1 + packages/clients/src/api/redis/v1/index.ts | 3 +++ 2 files changed, 4 insertions(+) create mode 100644 packages/clients/src/api/redis/v1/index.ts diff --git a/packages/clients/src/api/redis/index.ts b/packages/clients/src/api/redis/index.ts index e6671523d..0eb660a02 100644 --- a/packages/clients/src/api/redis/index.ts +++ b/packages/clients/src/api/redis/index.ts @@ -1 +1,2 @@ export * as v1alpha1 from './v1alpha1' +export * as v1 from './v1' diff --git a/packages/clients/src/api/redis/v1/index.ts b/packages/clients/src/api/redis/v1/index.ts new file mode 100644 index 000000000..0489f4b03 --- /dev/null +++ b/packages/clients/src/api/redis/v1/index.ts @@ -0,0 +1,3 @@ +export { RedisV1GenAPI as API } from './api.gen' +export * from './content.gen' +export * from './types.gen'