From b8c26dc724239c0c8699d7cc4c9033dc15634e15 Mon Sep 17 00:00:00 2001 From: scaleway-bot Date: Wed, 30 Nov 2022 16:10:12 +0000 Subject: [PATCH 1/3] feat: update generated APIs --- .../clients/src/api/marketplace/v2/api.gen.ts | 199 ++++++++++++++++++ .../src/api/marketplace/v2/marshalling.gen.ts | 134 ++++++++++++ .../src/api/marketplace/v2/types.gen.ts | 146 +++++++++++++ 3 files changed, 479 insertions(+) create mode 100644 packages/clients/src/api/marketplace/v2/api.gen.ts create mode 100644 packages/clients/src/api/marketplace/v2/marshalling.gen.ts create mode 100644 packages/clients/src/api/marketplace/v2/types.gen.ts diff --git a/packages/clients/src/api/marketplace/v2/api.gen.ts b/packages/clients/src/api/marketplace/v2/api.gen.ts new file mode 100644 index 000000000..0cdfba319 --- /dev/null +++ b/packages/clients/src/api/marketplace/v2/api.gen.ts @@ -0,0 +1,199 @@ +// 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, + resolveOneOf, + urlParams, + validatePathParam, +} from '../../../bridge' +import { + unmarshalCategory, + unmarshalImage, + unmarshalListCategoriesResponse, + unmarshalListImagesResponse, + unmarshalListLocalImagesResponse, + unmarshalListVersionsResponse, + unmarshalLocalImage, + unmarshalVersion, +} from './marshalling.gen' +import type { + Category, + GetCategoryRequest, + GetImageRequest, + GetLocalImageRequest, + GetVersionRequest, + Image, + ListCategoriesRequest, + ListCategoriesResponse, + ListImagesRequest, + ListImagesResponse, + ListLocalImagesRequest, + ListLocalImagesResponse, + ListVersionsRequest, + ListVersionsResponse, + LocalImage, + Version, +} from './types.gen' + +/** Marketplace API. */ +export class MarketplaceV2GenAPI extends API { + protected pageOfListImages = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/images`, + urlParams: urlParams( + ['arch', request.arch], + ['category', request.category], + ['include_eol', request.includeEol], + ['order_by', request.orderBy ?? 'name_asc'], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListImagesResponse, + ) + + /** + * List marketplace images + * + * @param request - The request {@link ListImagesRequest} + * @returns A Promise of ListImagesResponse + */ + listImages = (request: Readonly) => + enrichForPagination('images', this.pageOfListImages, request) + + /** + * Get a specific marketplace image + * + * @param request - The request {@link GetImageRequest} + * @returns A Promise of Image + */ + getImage = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/images/${validatePathParam( + 'imageId', + request.imageId, + )}`, + }, + unmarshalImage, + ) + + protected pageOfListVersions = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/versions`, + urlParams: urlParams( + ['image_id', request.imageId], + ['order_by', request.orderBy ?? 'created_at_asc'], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListVersionsResponse, + ) + + listVersions = (request: Readonly) => + enrichForPagination('versions', this.pageOfListVersions, request) + + getVersion = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/versions/${validatePathParam( + 'versionId', + request.versionId, + )}`, + }, + unmarshalVersion, + ) + + protected pageOfListLocalImages = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/local-images`, + urlParams: urlParams( + ['order_by', request.orderBy ?? 'created_at_asc'], + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ...Object.entries( + resolveOneOf([ + { + param: 'image_id', + value: request.imageId, + }, + { + param: 'version_id', + value: request.versionId, + }, + ]), + ), + ), + }, + unmarshalListLocalImagesResponse, + ) + + listLocalImages = (request: Readonly = {}) => + enrichForPagination('localImages', this.pageOfListLocalImages, request) + + getLocalImage = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/local-images/${validatePathParam( + 'localImageId', + request.localImageId, + )}`, + }, + unmarshalLocalImage, + ) + + protected pageOfListCategories = ( + request: Readonly = {}, + ) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/categories`, + urlParams: urlParams( + ['page', request.page], + [ + 'page_size', + request.pageSize ?? this.client.settings.defaultPageSize, + ], + ), + }, + unmarshalListCategoriesResponse, + ) + + listCategories = (request: Readonly = {}) => + enrichForPagination('categories', this.pageOfListCategories, request) + + getCategory = (request: Readonly) => + this.client.fetch( + { + method: 'GET', + path: `/marketplace/v2/categories/${validatePathParam( + 'categoryId', + request.categoryId, + )}`, + }, + unmarshalCategory, + ) +} diff --git a/packages/clients/src/api/marketplace/v2/marshalling.gen.ts b/packages/clients/src/api/marketplace/v2/marshalling.gen.ts new file mode 100644 index 000000000..49e118727 --- /dev/null +++ b/packages/clients/src/api/marketplace/v2/marshalling.gen.ts @@ -0,0 +1,134 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import { + isJSONObject, + unmarshalArrayOfObject, + unmarshalDate, +} from '../../../bridge' +import type { + Category, + Image, + ListCategoriesResponse, + ListImagesResponse, + ListLocalImagesResponse, + ListVersionsResponse, + LocalImage, + Version, +} from './types.gen' + +export const unmarshalCategory = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Category' failed as data isn't a dictionary.`, + ) + } + + return { + description: data.description, + id: data.id, + name: data.name, + } as Category +} + +export const unmarshalImage = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Image' failed as data isn't a dictionary.`, + ) + } + + return { + categories: data.categories, + createdAt: unmarshalDate(data.created_at), + description: data.description, + id: data.id, + label: data.label, + logo: data.logo, + name: data.name, + updatedAt: unmarshalDate(data.updated_at), + validUntil: unmarshalDate(data.valid_until), + } as Image +} + +export const unmarshalLocalImage = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'LocalImage' failed as data isn't a dictionary.`, + ) + } + + return { + arch: data.arch, + compatibleCommercialTypes: data.compatible_commercial_types, + id: data.id, + zone: data.zone, + } as LocalImage +} + +export const unmarshalVersion = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'Version' failed as data isn't a dictionary.`, + ) + } + + return { + createdAt: unmarshalDate(data.created_at), + id: data.id, + name: data.name, + publishedAt: unmarshalDate(data.published_at), + updatedAt: unmarshalDate(data.updated_at), + } as Version +} + +export const unmarshalListCategoriesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListCategoriesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + categories: unmarshalArrayOfObject(data.categories, unmarshalCategory), + totalCount: data.total_count, + } as ListCategoriesResponse +} + +export const unmarshalListImagesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListImagesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + images: unmarshalArrayOfObject(data.images, unmarshalImage), + totalCount: data.total_count, + } as ListImagesResponse +} + +export const unmarshalListLocalImagesResponse = (data: unknown) => { + if (!isJSONObject(data)) { + throw new TypeError( + `Unmarshalling the type 'ListLocalImagesResponse' failed as data isn't a dictionary.`, + ) + } + + return { + localImages: unmarshalArrayOfObject(data.local_images, unmarshalLocalImage), + totalCount: data.total_count, + } as ListLocalImagesResponse +} + +export const unmarshalListVersionsResponse = (data: unknown) => { + 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 +} diff --git a/packages/clients/src/api/marketplace/v2/types.gen.ts b/packages/clients/src/api/marketplace/v2/types.gen.ts new file mode 100644 index 000000000..aff99312d --- /dev/null +++ b/packages/clients/src/api/marketplace/v2/types.gen.ts @@ -0,0 +1,146 @@ +// This file was automatically generated. DO NOT EDIT. +// If you have any remark or suggestion do not hesitate to open an issue. +import type { Zone } from '../../../bridge' + +export type ListImagesRequestOrderBy = + | 'name_asc' + | 'name_desc' + | 'created_at_asc' + | 'created_at_desc' + | 'updated_at_asc' + | 'updated_at_desc' + +export type ListLocalImagesRequestOrderBy = 'created_at_asc' | 'created_at_desc' + +export type ListVersionsRequestOrderBy = 'created_at_asc' | 'created_at_desc' + +export interface Category { + id: string + name: string + description: string +} + +/** Image */ +export interface Image { + /** UUID of this image */ + id: string + /** Name of the image */ + name: string + /** Text description of this image */ + description: string + /** URL of this image's logo */ + logo: string + /** List of categories this image belongs to */ + categories: Array + /** Creation date of this image */ + createdAt?: Date + /** Date of the last modification of this image */ + updatedAt?: Date + /** Expiration date of this image */ + validUntil?: Date + /** Typically an identifier for a distribution (ex. "ubuntu_focal"). */ + label: string +} + +export interface ListCategoriesResponse { + categories: Array + totalCount: number +} + +export interface ListImagesResponse { + images: Array + totalCount: number +} + +export interface ListLocalImagesResponse { + localImages: Array + totalCount: number +} + +export interface ListVersionsResponse { + versions: Array + totalCount: number +} + +/** Local image */ +export interface LocalImage { + /** Version you will typically use to define an image in an API call. */ + id: string + /** List of all commercial types that are compatible with this local image */ + compatibleCommercialTypes: Array + /** Supported architecture for this local image */ + arch: string + /** Availability Zone where this local image is available */ + zone: Zone +} + +/** Version */ +export interface Version { + /** UUID of this version */ + id: string + /** Name of this version */ + name: string + /** Creation date of this image version */ + createdAt?: Date + /** Date of the last modification of this version */ + updatedAt?: Date + /** Date this version was officially published */ + publishedAt?: Date +} + +export type ListImagesRequest = { + /** + * A positive integer lower or equal to 100 to select the number of items to + * display + */ + pageSize?: number + /** A positive integer to choose the page to display */ + page?: number + /** Ordering to use */ + orderBy?: ListImagesRequestOrderBy + /** Choose for which machine architecture to return images */ + arch?: string + /** Choose the category of images to get */ + category?: string + /** Choose to include end-of-life images */ + includeEol: boolean +} + +export type GetImageRequest = { + /** Display the image name */ + imageId: string +} + +export type ListVersionsRequest = { + imageId: string + pageSize?: number + page?: number + orderBy?: ListVersionsRequestOrderBy +} + +export type GetVersionRequest = { + versionId: string +} + +export type ListLocalImagesRequest = { + /** One-of ('scope'): at most one of 'imageId', 'versionId' could be set. */ + imageId?: string + /** One-of ('scope'): at most one of 'imageId', 'versionId' could be set. */ + versionId?: string + pageSize?: number + page?: number + orderBy?: ListLocalImagesRequestOrderBy +} + +export type GetLocalImageRequest = { + localImageId: string +} + +export type ListCategoriesRequest = { + pageSize?: number + page?: number +} + +export type GetCategoryRequest = { + categoryId: string +} From 9bbca39440a4f12f15c519156f9c41d9e89aa4eb Mon Sep 17 00:00:00 2001 From: Vincent Germain Date: Wed, 30 Nov 2022 17:29:05 +0100 Subject: [PATCH 2/3] Create index.ts --- packages/clients/src/api/marketplace/v2/index.ts | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 packages/clients/src/api/marketplace/v2/index.ts diff --git a/packages/clients/src/api/marketplace/v2/index.ts b/packages/clients/src/api/marketplace/v2/index.ts new file mode 100644 index 000000000..a79ef8144 --- /dev/null +++ b/packages/clients/src/api/marketplace/v2/index.ts @@ -0,0 +1,3 @@ +export { MarketplaceV2GenAPI as API } from './api.gen' +export * from './content.gen' +export * from './types.gen' From 2596b8046bd571048b1f651745b084592e851632 Mon Sep 17 00:00:00 2001 From: Vincent Germain Date: Wed, 30 Nov 2022 17:30:00 +0100 Subject: [PATCH 3/3] Update index.ts --- packages/clients/src/api/marketplace/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/clients/src/api/marketplace/index.ts b/packages/clients/src/api/marketplace/index.ts index 994706b3e..fa99cd69c 100644 --- a/packages/clients/src/api/marketplace/index.ts +++ b/packages/clients/src/api/marketplace/index.ts @@ -1 +1,2 @@ export * as v1 from './v1' +export * as v2 from './v2'