Skip to content

Commit 7a11917

Browse files
feat(marketplace): add v2 (#265)
Co-authored-by: Vincent Germain <[email protected]>
1 parent 574588f commit 7a11917

File tree

5 files changed

+483
-0
lines changed

5 files changed

+483
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export * as v1 from './v1'
2+
export * as v2 from './v2'
Lines changed: 199 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
API,
5+
enrichForPagination,
6+
resolveOneOf,
7+
urlParams,
8+
validatePathParam,
9+
} from '../../../bridge'
10+
import {
11+
unmarshalCategory,
12+
unmarshalImage,
13+
unmarshalListCategoriesResponse,
14+
unmarshalListImagesResponse,
15+
unmarshalListLocalImagesResponse,
16+
unmarshalListVersionsResponse,
17+
unmarshalLocalImage,
18+
unmarshalVersion,
19+
} from './marshalling.gen'
20+
import type {
21+
Category,
22+
GetCategoryRequest,
23+
GetImageRequest,
24+
GetLocalImageRequest,
25+
GetVersionRequest,
26+
Image,
27+
ListCategoriesRequest,
28+
ListCategoriesResponse,
29+
ListImagesRequest,
30+
ListImagesResponse,
31+
ListLocalImagesRequest,
32+
ListLocalImagesResponse,
33+
ListVersionsRequest,
34+
ListVersionsResponse,
35+
LocalImage,
36+
Version,
37+
} from './types.gen'
38+
39+
/** Marketplace API. */
40+
export class MarketplaceV2GenAPI extends API {
41+
protected pageOfListImages = (request: Readonly<ListImagesRequest>) =>
42+
this.client.fetch<ListImagesResponse>(
43+
{
44+
method: 'GET',
45+
path: `/marketplace/v2/images`,
46+
urlParams: urlParams(
47+
['arch', request.arch],
48+
['category', request.category],
49+
['include_eol', request.includeEol],
50+
['order_by', request.orderBy ?? 'name_asc'],
51+
['page', request.page],
52+
[
53+
'page_size',
54+
request.pageSize ?? this.client.settings.defaultPageSize,
55+
],
56+
),
57+
},
58+
unmarshalListImagesResponse,
59+
)
60+
61+
/**
62+
* List marketplace images
63+
*
64+
* @param request - The request {@link ListImagesRequest}
65+
* @returns A Promise of ListImagesResponse
66+
*/
67+
listImages = (request: Readonly<ListImagesRequest>) =>
68+
enrichForPagination('images', this.pageOfListImages, request)
69+
70+
/**
71+
* Get a specific marketplace image
72+
*
73+
* @param request - The request {@link GetImageRequest}
74+
* @returns A Promise of Image
75+
*/
76+
getImage = (request: Readonly<GetImageRequest>) =>
77+
this.client.fetch<Image>(
78+
{
79+
method: 'GET',
80+
path: `/marketplace/v2/images/${validatePathParam(
81+
'imageId',
82+
request.imageId,
83+
)}`,
84+
},
85+
unmarshalImage,
86+
)
87+
88+
protected pageOfListVersions = (request: Readonly<ListVersionsRequest>) =>
89+
this.client.fetch<ListVersionsResponse>(
90+
{
91+
method: 'GET',
92+
path: `/marketplace/v2/versions`,
93+
urlParams: urlParams(
94+
['image_id', request.imageId],
95+
['order_by', request.orderBy ?? 'created_at_asc'],
96+
['page', request.page],
97+
[
98+
'page_size',
99+
request.pageSize ?? this.client.settings.defaultPageSize,
100+
],
101+
),
102+
},
103+
unmarshalListVersionsResponse,
104+
)
105+
106+
listVersions = (request: Readonly<ListVersionsRequest>) =>
107+
enrichForPagination('versions', this.pageOfListVersions, request)
108+
109+
getVersion = (request: Readonly<GetVersionRequest>) =>
110+
this.client.fetch<Version>(
111+
{
112+
method: 'GET',
113+
path: `/marketplace/v2/versions/${validatePathParam(
114+
'versionId',
115+
request.versionId,
116+
)}`,
117+
},
118+
unmarshalVersion,
119+
)
120+
121+
protected pageOfListLocalImages = (
122+
request: Readonly<ListLocalImagesRequest> = {},
123+
) =>
124+
this.client.fetch<ListLocalImagesResponse>(
125+
{
126+
method: 'GET',
127+
path: `/marketplace/v2/local-images`,
128+
urlParams: urlParams(
129+
['order_by', request.orderBy ?? 'created_at_asc'],
130+
['page', request.page],
131+
[
132+
'page_size',
133+
request.pageSize ?? this.client.settings.defaultPageSize,
134+
],
135+
...Object.entries(
136+
resolveOneOf([
137+
{
138+
param: 'image_id',
139+
value: request.imageId,
140+
},
141+
{
142+
param: 'version_id',
143+
value: request.versionId,
144+
},
145+
]),
146+
),
147+
),
148+
},
149+
unmarshalListLocalImagesResponse,
150+
)
151+
152+
listLocalImages = (request: Readonly<ListLocalImagesRequest> = {}) =>
153+
enrichForPagination('localImages', this.pageOfListLocalImages, request)
154+
155+
getLocalImage = (request: Readonly<GetLocalImageRequest>) =>
156+
this.client.fetch<LocalImage>(
157+
{
158+
method: 'GET',
159+
path: `/marketplace/v2/local-images/${validatePathParam(
160+
'localImageId',
161+
request.localImageId,
162+
)}`,
163+
},
164+
unmarshalLocalImage,
165+
)
166+
167+
protected pageOfListCategories = (
168+
request: Readonly<ListCategoriesRequest> = {},
169+
) =>
170+
this.client.fetch<ListCategoriesResponse>(
171+
{
172+
method: 'GET',
173+
path: `/marketplace/v2/categories`,
174+
urlParams: urlParams(
175+
['page', request.page],
176+
[
177+
'page_size',
178+
request.pageSize ?? this.client.settings.defaultPageSize,
179+
],
180+
),
181+
},
182+
unmarshalListCategoriesResponse,
183+
)
184+
185+
listCategories = (request: Readonly<ListCategoriesRequest> = {}) =>
186+
enrichForPagination('categories', this.pageOfListCategories, request)
187+
188+
getCategory = (request: Readonly<GetCategoryRequest>) =>
189+
this.client.fetch<Category>(
190+
{
191+
method: 'GET',
192+
path: `/marketplace/v2/categories/${validatePathParam(
193+
'categoryId',
194+
request.categoryId,
195+
)}`,
196+
},
197+
unmarshalCategory,
198+
)
199+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export { MarketplaceV2GenAPI as API } from './api.gen'
2+
export * from './content.gen'
3+
export * from './types.gen'
Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
// This file was automatically generated. DO NOT EDIT.
2+
// If you have any remark or suggestion do not hesitate to open an issue.
3+
import {
4+
isJSONObject,
5+
unmarshalArrayOfObject,
6+
unmarshalDate,
7+
} from '../../../bridge'
8+
import type {
9+
Category,
10+
Image,
11+
ListCategoriesResponse,
12+
ListImagesResponse,
13+
ListLocalImagesResponse,
14+
ListVersionsResponse,
15+
LocalImage,
16+
Version,
17+
} from './types.gen'
18+
19+
export const unmarshalCategory = (data: unknown) => {
20+
if (!isJSONObject(data)) {
21+
throw new TypeError(
22+
`Unmarshalling the type 'Category' failed as data isn't a dictionary.`,
23+
)
24+
}
25+
26+
return {
27+
description: data.description,
28+
id: data.id,
29+
name: data.name,
30+
} as Category
31+
}
32+
33+
export const unmarshalImage = (data: unknown) => {
34+
if (!isJSONObject(data)) {
35+
throw new TypeError(
36+
`Unmarshalling the type 'Image' failed as data isn't a dictionary.`,
37+
)
38+
}
39+
40+
return {
41+
categories: data.categories,
42+
createdAt: unmarshalDate(data.created_at),
43+
description: data.description,
44+
id: data.id,
45+
label: data.label,
46+
logo: data.logo,
47+
name: data.name,
48+
updatedAt: unmarshalDate(data.updated_at),
49+
validUntil: unmarshalDate(data.valid_until),
50+
} as Image
51+
}
52+
53+
export const unmarshalLocalImage = (data: unknown) => {
54+
if (!isJSONObject(data)) {
55+
throw new TypeError(
56+
`Unmarshalling the type 'LocalImage' failed as data isn't a dictionary.`,
57+
)
58+
}
59+
60+
return {
61+
arch: data.arch,
62+
compatibleCommercialTypes: data.compatible_commercial_types,
63+
id: data.id,
64+
zone: data.zone,
65+
} as LocalImage
66+
}
67+
68+
export const unmarshalVersion = (data: unknown) => {
69+
if (!isJSONObject(data)) {
70+
throw new TypeError(
71+
`Unmarshalling the type 'Version' failed as data isn't a dictionary.`,
72+
)
73+
}
74+
75+
return {
76+
createdAt: unmarshalDate(data.created_at),
77+
id: data.id,
78+
name: data.name,
79+
publishedAt: unmarshalDate(data.published_at),
80+
updatedAt: unmarshalDate(data.updated_at),
81+
} as Version
82+
}
83+
84+
export const unmarshalListCategoriesResponse = (data: unknown) => {
85+
if (!isJSONObject(data)) {
86+
throw new TypeError(
87+
`Unmarshalling the type 'ListCategoriesResponse' failed as data isn't a dictionary.`,
88+
)
89+
}
90+
91+
return {
92+
categories: unmarshalArrayOfObject(data.categories, unmarshalCategory),
93+
totalCount: data.total_count,
94+
} as ListCategoriesResponse
95+
}
96+
97+
export const unmarshalListImagesResponse = (data: unknown) => {
98+
if (!isJSONObject(data)) {
99+
throw new TypeError(
100+
`Unmarshalling the type 'ListImagesResponse' failed as data isn't a dictionary.`,
101+
)
102+
}
103+
104+
return {
105+
images: unmarshalArrayOfObject(data.images, unmarshalImage),
106+
totalCount: data.total_count,
107+
} as ListImagesResponse
108+
}
109+
110+
export const unmarshalListLocalImagesResponse = (data: unknown) => {
111+
if (!isJSONObject(data)) {
112+
throw new TypeError(
113+
`Unmarshalling the type 'ListLocalImagesResponse' failed as data isn't a dictionary.`,
114+
)
115+
}
116+
117+
return {
118+
localImages: unmarshalArrayOfObject(data.local_images, unmarshalLocalImage),
119+
totalCount: data.total_count,
120+
} as ListLocalImagesResponse
121+
}
122+
123+
export const unmarshalListVersionsResponse = (data: unknown) => {
124+
if (!isJSONObject(data)) {
125+
throw new TypeError(
126+
`Unmarshalling the type 'ListVersionsResponse' failed as data isn't a dictionary.`,
127+
)
128+
}
129+
130+
return {
131+
totalCount: data.total_count,
132+
versions: unmarshalArrayOfObject(data.versions, unmarshalVersion),
133+
} as ListVersionsResponse
134+
}

0 commit comments

Comments
 (0)