@scaleway/sdk-registry 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,266 @@
1
+ import { API as API$1, urlParams, validatePathParam, enrichForPagination, waitForResource } from "@scaleway/sdk-client";
2
+ import { NAMESPACE_TRANSIENT_STATUSES, IMAGE_TRANSIENT_STATUSES, TAG_TRANSIENT_STATUSES } from "./content.gen.js";
3
+ import { unmarshalListNamespacesResponse, unmarshalNamespace, marshalCreateNamespaceRequest, marshalUpdateNamespaceRequest, unmarshalListImagesResponse, unmarshalImage, marshalUpdateImageRequest, unmarshalListTagsResponse, unmarshalTag } from "./marshalling.gen.js";
4
+ const jsonContentHeaders = {
5
+ "Content-Type": "application/json; charset=utf-8"
6
+ };
7
+ class API extends API$1 {
8
+ /** Lists the available regions of the API. */
9
+ static LOCALITIES = [
10
+ "fr-par",
11
+ "nl-ams",
12
+ "pl-waw"
13
+ ];
14
+ pageOfListNamespaces = (request = {}) => this.client.fetch(
15
+ {
16
+ method: "GET",
17
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/namespaces`,
18
+ urlParams: urlParams(
19
+ ["name", request.name],
20
+ ["order_by", request.orderBy],
21
+ ["organization_id", request.organizationId],
22
+ ["page", request.page],
23
+ [
24
+ "page_size",
25
+ request.pageSize ?? this.client.settings.defaultPageSize
26
+ ],
27
+ ["project_id", request.projectId]
28
+ )
29
+ },
30
+ unmarshalListNamespacesResponse
31
+ );
32
+ /**
33
+ * List namespaces. List all namespaces in a specified region. By default, the namespaces listed are ordered by creation date in ascending order. This can be modified via the order_by field. You can also define additional parameters for your query, such as the `instance_id` and `project_id` parameters.
34
+ *
35
+ * @param request - The request {@link ListNamespacesRequest}
36
+ * @returns A Promise of ListNamespacesResponse
37
+ */
38
+ listNamespaces = (request = {}) => enrichForPagination("namespaces", this.pageOfListNamespaces, request);
39
+ /**
40
+ * Get a namespace. Retrieve information about a given namespace, specified by its `namespace_id` and region. Full details about the namespace, such as `description`, `project_id`, `status`, `endpoint`, `is_public`, `size`, and `image_count` are returned in the response.
41
+ *
42
+ * @param request - The request {@link GetNamespaceRequest}
43
+ * @returns A Promise of Namespace
44
+ */
45
+ getNamespace = (request) => this.client.fetch(
46
+ {
47
+ method: "GET",
48
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/namespaces/${validatePathParam("namespaceId", request.namespaceId)}`
49
+ },
50
+ unmarshalNamespace
51
+ );
52
+ /**
53
+ * Waits for {@link Namespace} to be in a final state.
54
+ *
55
+ * @param request - The request {@link GetNamespaceRequest}
56
+ * @param options - The waiting options
57
+ * @returns A Promise of Namespace
58
+ */
59
+ waitForNamespace = (request, options) => waitForResource(
60
+ options?.stop ?? ((res) => Promise.resolve(
61
+ !NAMESPACE_TRANSIENT_STATUSES.includes(res.status)
62
+ )),
63
+ this.getNamespace,
64
+ request,
65
+ options
66
+ );
67
+ /**
68
+ * Create a namespace. Create a new Container Registry namespace. You must specify the namespace name and region in which you want it to be created. Optionally, you can specify the `project_id` and `is_public` in the request payload.
69
+ *
70
+ * @param request - The request {@link CreateNamespaceRequest}
71
+ * @returns A Promise of Namespace
72
+ */
73
+ createNamespace = (request) => this.client.fetch(
74
+ {
75
+ body: JSON.stringify(
76
+ marshalCreateNamespaceRequest(request, this.client.settings)
77
+ ),
78
+ headers: jsonContentHeaders,
79
+ method: "POST",
80
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/namespaces`
81
+ },
82
+ unmarshalNamespace
83
+ );
84
+ /**
85
+ * Update a namespace. Update the parameters of a given namespace, specified by its `namespace_id` and `region`. You can update the `description` and `is_public` parameters.
86
+ *
87
+ * @param request - The request {@link UpdateNamespaceRequest}
88
+ * @returns A Promise of Namespace
89
+ */
90
+ updateNamespace = (request) => this.client.fetch(
91
+ {
92
+ body: JSON.stringify(
93
+ marshalUpdateNamespaceRequest(request, this.client.settings)
94
+ ),
95
+ headers: jsonContentHeaders,
96
+ method: "PATCH",
97
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/namespaces/${validatePathParam("namespaceId", request.namespaceId)}`
98
+ },
99
+ unmarshalNamespace
100
+ );
101
+ /**
102
+ * Delete a namespace. Delete a given namespace. You must specify, in the endpoint, the `region` and `namespace_id` parameters of the namespace you want to delete.
103
+ *
104
+ * @param request - The request {@link DeleteNamespaceRequest}
105
+ * @returns A Promise of Namespace
106
+ */
107
+ deleteNamespace = (request) => this.client.fetch(
108
+ {
109
+ method: "DELETE",
110
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/namespaces/${validatePathParam("namespaceId", request.namespaceId)}`
111
+ },
112
+ unmarshalNamespace
113
+ );
114
+ pageOfListImages = (request = {}) => this.client.fetch(
115
+ {
116
+ method: "GET",
117
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/images`,
118
+ urlParams: urlParams(
119
+ ["name", request.name],
120
+ ["namespace_id", request.namespaceId],
121
+ ["order_by", request.orderBy],
122
+ ["organization_id", request.organizationId],
123
+ ["page", request.page],
124
+ [
125
+ "page_size",
126
+ request.pageSize ?? this.client.settings.defaultPageSize
127
+ ],
128
+ ["project_id", request.projectId]
129
+ )
130
+ },
131
+ unmarshalListImagesResponse
132
+ );
133
+ /**
134
+ * List images. List all images in a specified region. By default, the images listed are ordered by creation date in ascending order. This can be modified via the order_by field. You can also define additional parameters for your query, such as the `namespace_id` and `project_id` parameters.
135
+ *
136
+ * @param request - The request {@link ListImagesRequest}
137
+ * @returns A Promise of ListImagesResponse
138
+ */
139
+ listImages = (request = {}) => enrichForPagination("images", this.pageOfListImages, request);
140
+ /**
141
+ * Get an image. Retrieve information about a given container image, specified by its `image_id` and region. Full details about the image, such as `name`, `namespace_id`, `status`, `visibility`, and `size` are returned in the response.
142
+ *
143
+ * @param request - The request {@link GetImageRequest}
144
+ * @returns A Promise of Image
145
+ */
146
+ getImage = (request) => this.client.fetch(
147
+ {
148
+ method: "GET",
149
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/images/${validatePathParam("imageId", request.imageId)}`
150
+ },
151
+ unmarshalImage
152
+ );
153
+ /**
154
+ * Waits for {@link Image} to be in a final state.
155
+ *
156
+ * @param request - The request {@link GetImageRequest}
157
+ * @param options - The waiting options
158
+ * @returns A Promise of Image
159
+ */
160
+ waitForImage = (request, options) => waitForResource(
161
+ options?.stop ?? ((res) => Promise.resolve(
162
+ !IMAGE_TRANSIENT_STATUSES.includes(res.status)
163
+ )),
164
+ this.getImage,
165
+ request,
166
+ options
167
+ );
168
+ /**
169
+ * Update an image. Update the parameters of a given image, specified by its `image_id` and `region`. You can update the `visibility` parameter.
170
+ *
171
+ * @param request - The request {@link UpdateImageRequest}
172
+ * @returns A Promise of Image
173
+ */
174
+ updateImage = (request) => this.client.fetch(
175
+ {
176
+ body: JSON.stringify(
177
+ marshalUpdateImageRequest(request, this.client.settings)
178
+ ),
179
+ headers: jsonContentHeaders,
180
+ method: "PATCH",
181
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/images/${validatePathParam("imageId", request.imageId)}`
182
+ },
183
+ unmarshalImage
184
+ );
185
+ /**
186
+ * Delete an image. Delete a given image. You must specify, in the endpoint, the `region` and `image_id` parameters of the image you want to delete.
187
+ *
188
+ * @param request - The request {@link DeleteImageRequest}
189
+ * @returns A Promise of Image
190
+ */
191
+ deleteImage = (request) => this.client.fetch(
192
+ {
193
+ method: "DELETE",
194
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/images/${validatePathParam("imageId", request.imageId)}`
195
+ },
196
+ unmarshalImage
197
+ );
198
+ pageOfListTags = (request) => this.client.fetch(
199
+ {
200
+ method: "GET",
201
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/images/${validatePathParam("imageId", request.imageId)}/tags`,
202
+ urlParams: urlParams(
203
+ ["name", request.name],
204
+ ["order_by", request.orderBy],
205
+ ["page", request.page],
206
+ [
207
+ "page_size",
208
+ request.pageSize ?? this.client.settings.defaultPageSize
209
+ ]
210
+ )
211
+ },
212
+ unmarshalListTagsResponse
213
+ );
214
+ /**
215
+ * List tags. List all tags for a given image, specified by region. By default, the tags listed are ordered by creation date in ascending order. This can be modified via the order_by field. You can also define additional parameters for your query, such as the `name`.
216
+ *
217
+ * @param request - The request {@link ListTagsRequest}
218
+ * @returns A Promise of ListTagsResponse
219
+ */
220
+ listTags = (request) => enrichForPagination("tags", this.pageOfListTags, request);
221
+ /**
222
+ * Get a tag. Retrieve information about a given image tag, specified by its `tag_id` and region. Full details about the tag, such as `name`, `image_id`, `status`, and `digest` are returned in the response.
223
+ *
224
+ * @param request - The request {@link GetTagRequest}
225
+ * @returns A Promise of Tag
226
+ */
227
+ getTag = (request) => this.client.fetch(
228
+ {
229
+ method: "GET",
230
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/tags/${validatePathParam("tagId", request.tagId)}`
231
+ },
232
+ unmarshalTag
233
+ );
234
+ /**
235
+ * Waits for {@link Tag} to be in a final state.
236
+ *
237
+ * @param request - The request {@link GetTagRequest}
238
+ * @param options - The waiting options
239
+ * @returns A Promise of Tag
240
+ */
241
+ waitForTag = (request, options) => waitForResource(
242
+ options?.stop ?? ((res) => Promise.resolve(
243
+ !TAG_TRANSIENT_STATUSES.includes(res.status)
244
+ )),
245
+ this.getTag,
246
+ request,
247
+ options
248
+ );
249
+ /**
250
+ * Delete a tag. Delete a given image tag. You must specify, in the endpoint, the `region` and `tag_id` parameters of the tag you want to delete.
251
+ *
252
+ * @param request - The request {@link DeleteTagRequest}
253
+ * @returns A Promise of Tag
254
+ */
255
+ deleteTag = (request) => this.client.fetch(
256
+ {
257
+ method: "DELETE",
258
+ path: `/registry/v1/regions/${validatePathParam("region", request.region ?? this.client.settings.defaultRegion)}/tags/${validatePathParam("tagId", request.tagId)}`,
259
+ urlParams: urlParams(["force", request.force])
260
+ },
261
+ unmarshalTag
262
+ );
263
+ }
264
+ export {
265
+ API
266
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const IMAGE_TRANSIENT_STATUSES = ["deleting"];
4
+ const NAMESPACE_TRANSIENT_STATUSES = ["deleting"];
5
+ const TAG_TRANSIENT_STATUSES = ["deleting"];
6
+ exports.IMAGE_TRANSIENT_STATUSES = IMAGE_TRANSIENT_STATUSES;
7
+ exports.NAMESPACE_TRANSIENT_STATUSES = NAMESPACE_TRANSIENT_STATUSES;
8
+ exports.TAG_TRANSIENT_STATUSES = TAG_TRANSIENT_STATUSES;
@@ -0,0 +1,7 @@
1
+ import type { ImageStatus, NamespaceStatus, TagStatus } from './types.gen';
2
+ /** Lists transient statutes of the enum {@link ImageStatus}. */
3
+ export declare const IMAGE_TRANSIENT_STATUSES: ImageStatus[];
4
+ /** Lists transient statutes of the enum {@link NamespaceStatus}. */
5
+ export declare const NAMESPACE_TRANSIENT_STATUSES: NamespaceStatus[];
6
+ /** Lists transient statutes of the enum {@link TagStatus}. */
7
+ export declare const TAG_TRANSIENT_STATUSES: TagStatus[];
@@ -0,0 +1,8 @@
1
+ const IMAGE_TRANSIENT_STATUSES = ["deleting"];
2
+ const NAMESPACE_TRANSIENT_STATUSES = ["deleting"];
3
+ const TAG_TRANSIENT_STATUSES = ["deleting"];
4
+ export {
5
+ IMAGE_TRANSIENT_STATUSES,
6
+ NAMESPACE_TRANSIENT_STATUSES,
7
+ TAG_TRANSIENT_STATUSES
8
+ };
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const api_gen = require("./api.gen.cjs");
4
+ const content_gen = require("./content.gen.cjs");
5
+ const marshalling_gen = require("./marshalling.gen.cjs");
6
+ exports.API = api_gen.API;
7
+ exports.IMAGE_TRANSIENT_STATUSES = content_gen.IMAGE_TRANSIENT_STATUSES;
8
+ exports.NAMESPACE_TRANSIENT_STATUSES = content_gen.NAMESPACE_TRANSIENT_STATUSES;
9
+ exports.TAG_TRANSIENT_STATUSES = content_gen.TAG_TRANSIENT_STATUSES;
10
+ exports.marshalCreateNamespaceRequest = marshalling_gen.marshalCreateNamespaceRequest;
11
+ exports.marshalUpdateImageRequest = marshalling_gen.marshalUpdateImageRequest;
12
+ exports.marshalUpdateNamespaceRequest = marshalling_gen.marshalUpdateNamespaceRequest;
13
+ exports.unmarshalImage = marshalling_gen.unmarshalImage;
14
+ exports.unmarshalListImagesResponse = marshalling_gen.unmarshalListImagesResponse;
15
+ exports.unmarshalListNamespacesResponse = marshalling_gen.unmarshalListNamespacesResponse;
16
+ exports.unmarshalListTagsResponse = marshalling_gen.unmarshalListTagsResponse;
17
+ exports.unmarshalNamespace = marshalling_gen.unmarshalNamespace;
18
+ exports.unmarshalTag = marshalling_gen.unmarshalTag;
@@ -0,0 +1,4 @@
1
+ export { API } from './api.gen';
2
+ export * from './content.gen';
3
+ export * from './marshalling.gen';
4
+ export type { CreateNamespaceRequest, DeleteImageRequest, DeleteNamespaceRequest, DeleteTagRequest, GetImageRequest, GetNamespaceRequest, GetTagRequest, Image, ImageStatus, ImageVisibility, ListImagesRequest, ListImagesRequestOrderBy, ListImagesResponse, ListNamespacesRequest, ListNamespacesRequestOrderBy, ListNamespacesResponse, ListTagsRequest, ListTagsRequestOrderBy, ListTagsResponse, Namespace, NamespaceStatus, Tag, TagStatus, UpdateImageRequest, UpdateNamespaceRequest, } from './types.gen';
@@ -0,0 +1,18 @@
1
+ import { API } from "./api.gen.js";
2
+ import { IMAGE_TRANSIENT_STATUSES, NAMESPACE_TRANSIENT_STATUSES, TAG_TRANSIENT_STATUSES } from "./content.gen.js";
3
+ import { marshalCreateNamespaceRequest, marshalUpdateImageRequest, marshalUpdateNamespaceRequest, unmarshalImage, unmarshalListImagesResponse, unmarshalListNamespacesResponse, unmarshalListTagsResponse, unmarshalNamespace, unmarshalTag } from "./marshalling.gen.js";
4
+ export {
5
+ API,
6
+ IMAGE_TRANSIENT_STATUSES,
7
+ NAMESPACE_TRANSIENT_STATUSES,
8
+ TAG_TRANSIENT_STATUSES,
9
+ marshalCreateNamespaceRequest,
10
+ marshalUpdateImageRequest,
11
+ marshalUpdateNamespaceRequest,
12
+ unmarshalImage,
13
+ unmarshalListImagesResponse,
14
+ unmarshalListNamespacesResponse,
15
+ unmarshalListTagsResponse,
16
+ unmarshalNamespace,
17
+ unmarshalTag
18
+ };
@@ -0,0 +1,128 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const randomName = require("@scaleway/random-name");
4
+ const sdkClient = require("@scaleway/sdk-client");
5
+ const unmarshalImage = (data) => {
6
+ if (!sdkClient.isJSONObject(data)) {
7
+ throw new TypeError(
8
+ `Unmarshalling the type 'Image' failed as data isn't a dictionary.`
9
+ );
10
+ }
11
+ return {
12
+ createdAt: sdkClient.unmarshalDate(data.created_at),
13
+ id: data.id,
14
+ name: data.name,
15
+ namespaceId: data.namespace_id,
16
+ size: data.size,
17
+ status: data.status,
18
+ statusMessage: data.status_message,
19
+ tags: data.tags,
20
+ updatedAt: sdkClient.unmarshalDate(data.updated_at),
21
+ visibility: data.visibility
22
+ };
23
+ };
24
+ const unmarshalNamespace = (data) => {
25
+ if (!sdkClient.isJSONObject(data)) {
26
+ throw new TypeError(
27
+ `Unmarshalling the type 'Namespace' failed as data isn't a dictionary.`
28
+ );
29
+ }
30
+ return {
31
+ createdAt: sdkClient.unmarshalDate(data.created_at),
32
+ description: data.description,
33
+ endpoint: data.endpoint,
34
+ id: data.id,
35
+ imageCount: data.image_count,
36
+ isPublic: data.is_public,
37
+ name: data.name,
38
+ organizationId: data.organization_id,
39
+ projectId: data.project_id,
40
+ region: data.region,
41
+ size: data.size,
42
+ status: data.status,
43
+ statusMessage: data.status_message,
44
+ updatedAt: sdkClient.unmarshalDate(data.updated_at)
45
+ };
46
+ };
47
+ const unmarshalTag = (data) => {
48
+ if (!sdkClient.isJSONObject(data)) {
49
+ throw new TypeError(
50
+ `Unmarshalling the type 'Tag' failed as data isn't a dictionary.`
51
+ );
52
+ }
53
+ return {
54
+ createdAt: sdkClient.unmarshalDate(data.created_at),
55
+ digest: data.digest,
56
+ id: data.id,
57
+ imageId: data.image_id,
58
+ name: data.name,
59
+ status: data.status,
60
+ updatedAt: sdkClient.unmarshalDate(data.updated_at)
61
+ };
62
+ };
63
+ const unmarshalListImagesResponse = (data) => {
64
+ if (!sdkClient.isJSONObject(data)) {
65
+ throw new TypeError(
66
+ `Unmarshalling the type 'ListImagesResponse' failed as data isn't a dictionary.`
67
+ );
68
+ }
69
+ return {
70
+ images: sdkClient.unmarshalArrayOfObject(data.images, unmarshalImage),
71
+ totalCount: data.total_count
72
+ };
73
+ };
74
+ const unmarshalListNamespacesResponse = (data) => {
75
+ if (!sdkClient.isJSONObject(data)) {
76
+ throw new TypeError(
77
+ `Unmarshalling the type 'ListNamespacesResponse' failed as data isn't a dictionary.`
78
+ );
79
+ }
80
+ return {
81
+ namespaces: sdkClient.unmarshalArrayOfObject(data.namespaces, unmarshalNamespace),
82
+ totalCount: data.total_count
83
+ };
84
+ };
85
+ const unmarshalListTagsResponse = (data) => {
86
+ if (!sdkClient.isJSONObject(data)) {
87
+ throw new TypeError(
88
+ `Unmarshalling the type 'ListTagsResponse' failed as data isn't a dictionary.`
89
+ );
90
+ }
91
+ return {
92
+ tags: sdkClient.unmarshalArrayOfObject(data.tags, unmarshalTag),
93
+ totalCount: data.total_count
94
+ };
95
+ };
96
+ const marshalCreateNamespaceRequest = (request, defaults) => ({
97
+ description: request.description,
98
+ is_public: request.isPublic,
99
+ name: request.name || randomName("ns"),
100
+ ...sdkClient.resolveOneOf([
101
+ {
102
+ default: defaults.defaultProjectId,
103
+ param: "project_id",
104
+ value: request.projectId
105
+ },
106
+ {
107
+ default: defaults.defaultOrganizationId,
108
+ param: "organization_id",
109
+ value: request.organizationId
110
+ }
111
+ ])
112
+ });
113
+ const marshalUpdateImageRequest = (request, defaults) => ({
114
+ visibility: request.visibility
115
+ });
116
+ const marshalUpdateNamespaceRequest = (request, defaults) => ({
117
+ description: request.description,
118
+ is_public: request.isPublic
119
+ });
120
+ exports.marshalCreateNamespaceRequest = marshalCreateNamespaceRequest;
121
+ exports.marshalUpdateImageRequest = marshalUpdateImageRequest;
122
+ exports.marshalUpdateNamespaceRequest = marshalUpdateNamespaceRequest;
123
+ exports.unmarshalImage = unmarshalImage;
124
+ exports.unmarshalListImagesResponse = unmarshalListImagesResponse;
125
+ exports.unmarshalListNamespacesResponse = unmarshalListNamespacesResponse;
126
+ exports.unmarshalListTagsResponse = unmarshalListTagsResponse;
127
+ exports.unmarshalNamespace = unmarshalNamespace;
128
+ exports.unmarshalTag = unmarshalTag;
@@ -0,0 +1,11 @@
1
+ import type { DefaultValues } from '@scaleway/sdk-client';
2
+ import type { CreateNamespaceRequest, Image, ListImagesResponse, ListNamespacesResponse, ListTagsResponse, Namespace, Tag, UpdateImageRequest, UpdateNamespaceRequest } from './types.gen';
3
+ export declare const unmarshalImage: (data: unknown) => Image;
4
+ export declare const unmarshalNamespace: (data: unknown) => Namespace;
5
+ export declare const unmarshalTag: (data: unknown) => Tag;
6
+ export declare const unmarshalListImagesResponse: (data: unknown) => ListImagesResponse;
7
+ export declare const unmarshalListNamespacesResponse: (data: unknown) => ListNamespacesResponse;
8
+ export declare const unmarshalListTagsResponse: (data: unknown) => ListTagsResponse;
9
+ export declare const marshalCreateNamespaceRequest: (request: CreateNamespaceRequest, defaults: DefaultValues) => Record<string, unknown>;
10
+ export declare const marshalUpdateImageRequest: (request: UpdateImageRequest, defaults: DefaultValues) => Record<string, unknown>;
11
+ export declare const marshalUpdateNamespaceRequest: (request: UpdateNamespaceRequest, defaults: DefaultValues) => Record<string, unknown>;
@@ -0,0 +1,128 @@
1
+ import randomName from "@scaleway/random-name";
2
+ import { resolveOneOf, isJSONObject, unmarshalDate, unmarshalArrayOfObject } from "@scaleway/sdk-client";
3
+ const unmarshalImage = (data) => {
4
+ if (!isJSONObject(data)) {
5
+ throw new TypeError(
6
+ `Unmarshalling the type 'Image' failed as data isn't a dictionary.`
7
+ );
8
+ }
9
+ return {
10
+ createdAt: unmarshalDate(data.created_at),
11
+ id: data.id,
12
+ name: data.name,
13
+ namespaceId: data.namespace_id,
14
+ size: data.size,
15
+ status: data.status,
16
+ statusMessage: data.status_message,
17
+ tags: data.tags,
18
+ updatedAt: unmarshalDate(data.updated_at),
19
+ visibility: data.visibility
20
+ };
21
+ };
22
+ const unmarshalNamespace = (data) => {
23
+ if (!isJSONObject(data)) {
24
+ throw new TypeError(
25
+ `Unmarshalling the type 'Namespace' failed as data isn't a dictionary.`
26
+ );
27
+ }
28
+ return {
29
+ createdAt: unmarshalDate(data.created_at),
30
+ description: data.description,
31
+ endpoint: data.endpoint,
32
+ id: data.id,
33
+ imageCount: data.image_count,
34
+ isPublic: data.is_public,
35
+ name: data.name,
36
+ organizationId: data.organization_id,
37
+ projectId: data.project_id,
38
+ region: data.region,
39
+ size: data.size,
40
+ status: data.status,
41
+ statusMessage: data.status_message,
42
+ updatedAt: unmarshalDate(data.updated_at)
43
+ };
44
+ };
45
+ const unmarshalTag = (data) => {
46
+ if (!isJSONObject(data)) {
47
+ throw new TypeError(
48
+ `Unmarshalling the type 'Tag' failed as data isn't a dictionary.`
49
+ );
50
+ }
51
+ return {
52
+ createdAt: unmarshalDate(data.created_at),
53
+ digest: data.digest,
54
+ id: data.id,
55
+ imageId: data.image_id,
56
+ name: data.name,
57
+ status: data.status,
58
+ updatedAt: unmarshalDate(data.updated_at)
59
+ };
60
+ };
61
+ const unmarshalListImagesResponse = (data) => {
62
+ if (!isJSONObject(data)) {
63
+ throw new TypeError(
64
+ `Unmarshalling the type 'ListImagesResponse' failed as data isn't a dictionary.`
65
+ );
66
+ }
67
+ return {
68
+ images: unmarshalArrayOfObject(data.images, unmarshalImage),
69
+ totalCount: data.total_count
70
+ };
71
+ };
72
+ const unmarshalListNamespacesResponse = (data) => {
73
+ if (!isJSONObject(data)) {
74
+ throw new TypeError(
75
+ `Unmarshalling the type 'ListNamespacesResponse' failed as data isn't a dictionary.`
76
+ );
77
+ }
78
+ return {
79
+ namespaces: unmarshalArrayOfObject(data.namespaces, unmarshalNamespace),
80
+ totalCount: data.total_count
81
+ };
82
+ };
83
+ const unmarshalListTagsResponse = (data) => {
84
+ if (!isJSONObject(data)) {
85
+ throw new TypeError(
86
+ `Unmarshalling the type 'ListTagsResponse' failed as data isn't a dictionary.`
87
+ );
88
+ }
89
+ return {
90
+ tags: unmarshalArrayOfObject(data.tags, unmarshalTag),
91
+ totalCount: data.total_count
92
+ };
93
+ };
94
+ const marshalCreateNamespaceRequest = (request, defaults) => ({
95
+ description: request.description,
96
+ is_public: request.isPublic,
97
+ name: request.name || randomName("ns"),
98
+ ...resolveOneOf([
99
+ {
100
+ default: defaults.defaultProjectId,
101
+ param: "project_id",
102
+ value: request.projectId
103
+ },
104
+ {
105
+ default: defaults.defaultOrganizationId,
106
+ param: "organization_id",
107
+ value: request.organizationId
108
+ }
109
+ ])
110
+ });
111
+ const marshalUpdateImageRequest = (request, defaults) => ({
112
+ visibility: request.visibility
113
+ });
114
+ const marshalUpdateNamespaceRequest = (request, defaults) => ({
115
+ description: request.description,
116
+ is_public: request.isPublic
117
+ });
118
+ export {
119
+ marshalCreateNamespaceRequest,
120
+ marshalUpdateImageRequest,
121
+ marshalUpdateNamespaceRequest,
122
+ unmarshalImage,
123
+ unmarshalListImagesResponse,
124
+ unmarshalListNamespacesResponse,
125
+ unmarshalListTagsResponse,
126
+ unmarshalNamespace,
127
+ unmarshalTag
128
+ };