@scaleway/sdk-block 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.
Files changed (37) hide show
  1. package/LICENSE +191 -0
  2. package/dist/index.gen.cjs +6 -0
  3. package/dist/index.gen.d.ts +6 -0
  4. package/dist/index.gen.js +6 -0
  5. package/dist/v1/api.gen.cjs +285 -0
  6. package/dist/v1/api.gen.d.ts +134 -0
  7. package/dist/v1/api.gen.js +285 -0
  8. package/dist/v1/content.gen.cjs +22 -0
  9. package/dist/v1/content.gen.d.ts +7 -0
  10. package/dist/v1/content.gen.js +22 -0
  11. package/dist/v1/index.gen.cjs +23 -0
  12. package/dist/v1/index.gen.d.ts +5 -0
  13. package/dist/v1/index.gen.js +23 -0
  14. package/dist/v1/marshalling.gen.cjs +198 -0
  15. package/dist/v1/marshalling.gen.d.ts +14 -0
  16. package/dist/v1/marshalling.gen.js +198 -0
  17. package/dist/v1/types.gen.d.ts +516 -0
  18. package/dist/v1/validation-rules.gen.cjs +56 -0
  19. package/dist/v1/validation-rules.gen.d.ts +47 -0
  20. package/dist/v1/validation-rules.gen.js +56 -0
  21. package/dist/v1alpha1/api.gen.cjs +305 -0
  22. package/dist/v1alpha1/api.gen.d.ts +144 -0
  23. package/dist/v1alpha1/api.gen.js +305 -0
  24. package/dist/v1alpha1/content.gen.cjs +22 -0
  25. package/dist/v1alpha1/content.gen.d.ts +7 -0
  26. package/dist/v1alpha1/content.gen.js +22 -0
  27. package/dist/v1alpha1/index.gen.cjs +23 -0
  28. package/dist/v1alpha1/index.gen.d.ts +5 -0
  29. package/dist/v1alpha1/index.gen.js +23 -0
  30. package/dist/v1alpha1/marshalling.gen.cjs +206 -0
  31. package/dist/v1alpha1/marshalling.gen.d.ts +14 -0
  32. package/dist/v1alpha1/marshalling.gen.js +206 -0
  33. package/dist/v1alpha1/types.gen.d.ts +546 -0
  34. package/dist/v1alpha1/validation-rules.gen.cjs +62 -0
  35. package/dist/v1alpha1/validation-rules.gen.d.ts +52 -0
  36. package/dist/v1alpha1/validation-rules.gen.js +62 -0
  37. package/package.json +51 -0
@@ -0,0 +1,285 @@
1
+ import { API as API$1, urlParams, validatePathParam, enrichForPagination, waitForResource } from "@scaleway/sdk-client";
2
+ import { VOLUME_TRANSIENT_STATUSES, SNAPSHOT_TRANSIENT_STATUSES } from "./content.gen.js";
3
+ import { unmarshalListVolumeTypesResponse, unmarshalListVolumesResponse, marshalCreateVolumeRequest, unmarshalVolume, marshalUpdateVolumeRequest, unmarshalListSnapshotsResponse, unmarshalSnapshot, marshalCreateSnapshotRequest, marshalImportSnapshotFromObjectStorageRequest, marshalExportSnapshotToObjectStorageRequest, marshalUpdateSnapshotRequest } 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 zones of the API. */
9
+ static LOCALITIES = [
10
+ "fr-par-1",
11
+ "fr-par-2",
12
+ "fr-par-3",
13
+ "nl-ams-1",
14
+ "nl-ams-2",
15
+ "nl-ams-3",
16
+ "pl-waw-1",
17
+ "pl-waw-2",
18
+ "pl-waw-3"
19
+ ];
20
+ pageOfListVolumeTypes = (request = {}) => this.client.fetch(
21
+ {
22
+ method: "GET",
23
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/volume-types`,
24
+ urlParams: urlParams(
25
+ ["page", request.page],
26
+ [
27
+ "page_size",
28
+ request.pageSize ?? this.client.settings.defaultPageSize
29
+ ]
30
+ )
31
+ },
32
+ unmarshalListVolumeTypesResponse
33
+ );
34
+ /**
35
+ * List volume types. List all available volume types in a specified zone. The volume types listed are ordered by name in ascending order.
36
+ *
37
+ * @param request - The request {@link ListVolumeTypesRequest}
38
+ * @returns A Promise of ListVolumeTypesResponse
39
+ */
40
+ listVolumeTypes = (request = {}) => enrichForPagination("volumeTypes", this.pageOfListVolumeTypes, request);
41
+ pageOfListVolumes = (request = {}) => this.client.fetch(
42
+ {
43
+ method: "GET",
44
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/volumes`,
45
+ urlParams: urlParams(
46
+ ["name", request.name],
47
+ ["order_by", request.orderBy],
48
+ ["organization_id", request.organizationId],
49
+ ["page", request.page],
50
+ [
51
+ "page_size",
52
+ request.pageSize ?? this.client.settings.defaultPageSize
53
+ ],
54
+ ["product_resource_id", request.productResourceId],
55
+ ["project_id", request.projectId],
56
+ ["tags", request.tags]
57
+ )
58
+ },
59
+ unmarshalListVolumesResponse
60
+ );
61
+ /**
62
+ * List volumes. List all existing volumes in a specified zone. By default, the volumes listed are ordered by creation date in ascending order. This can be modified via the `order_by` field.
63
+ *
64
+ * @param request - The request {@link ListVolumesRequest}
65
+ * @returns A Promise of ListVolumesResponse
66
+ */
67
+ listVolumes = (request = {}) => enrichForPagination("volumes", this.pageOfListVolumes, request);
68
+ /**
69
+ * Create a volume. To create a new volume from scratch, you must specify `from_empty` and the `size`.
70
+ To create a volume from an existing snapshot, specify `from_snapshot` and the `snapshot_id` in the request payload instead, size is optional and can be specified if you need to extend the original size. The volume will take on the same volume class and underlying IOPS limitations as the original snapshot.
71
+ *
72
+ * @param request - The request {@link CreateVolumeRequest}
73
+ * @returns A Promise of Volume
74
+ */
75
+ createVolume = (request = {}) => this.client.fetch(
76
+ {
77
+ body: JSON.stringify(
78
+ marshalCreateVolumeRequest(request, this.client.settings)
79
+ ),
80
+ headers: jsonContentHeaders,
81
+ method: "POST",
82
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/volumes`
83
+ },
84
+ unmarshalVolume
85
+ );
86
+ /**
87
+ * Get a volume. Retrieve technical information about a specific volume. Details such as size, type, and status are returned in the response.
88
+ *
89
+ * @param request - The request {@link GetVolumeRequest}
90
+ * @returns A Promise of Volume
91
+ */
92
+ getVolume = (request) => this.client.fetch(
93
+ {
94
+ method: "GET",
95
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/volumes/${validatePathParam("volumeId", request.volumeId)}`
96
+ },
97
+ unmarshalVolume
98
+ );
99
+ /**
100
+ * Waits for {@link Volume} to be in a final state.
101
+ *
102
+ * @param request - The request {@link GetVolumeRequest}
103
+ * @param options - The waiting options
104
+ * @returns A Promise of Volume
105
+ */
106
+ waitForVolume = (request, options) => waitForResource(
107
+ options?.stop ?? ((res) => Promise.resolve(
108
+ !VOLUME_TRANSIENT_STATUSES.includes(res.status)
109
+ )),
110
+ this.getVolume,
111
+ request,
112
+ options
113
+ );
114
+ /**
115
+ * Delete a detached volume. You must specify the `volume_id` of the volume you want to delete. The volume must not be in the `in_use` status.
116
+ *
117
+ * @param request - The request {@link DeleteVolumeRequest}
118
+ */
119
+ deleteVolume = (request) => this.client.fetch({
120
+ method: "DELETE",
121
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/volumes/${validatePathParam("volumeId", request.volumeId)}`
122
+ });
123
+ /**
124
+ * Update a volume. Update the technical details of a volume, such as its name, tags, or its new size and `volume_type` (within the same Block Storage class).
125
+ You can only resize a volume to a larger size. It is currently not possible to change your Block Storage Class.
126
+ *
127
+ * @param request - The request {@link UpdateVolumeRequest}
128
+ * @returns A Promise of Volume
129
+ */
130
+ updateVolume = (request) => this.client.fetch(
131
+ {
132
+ body: JSON.stringify(
133
+ marshalUpdateVolumeRequest(request, this.client.settings)
134
+ ),
135
+ headers: jsonContentHeaders,
136
+ method: "PATCH",
137
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/volumes/${validatePathParam("volumeId", request.volumeId)}`
138
+ },
139
+ unmarshalVolume
140
+ );
141
+ pageOfListSnapshots = (request = {}) => this.client.fetch(
142
+ {
143
+ method: "GET",
144
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/snapshots`,
145
+ urlParams: urlParams(
146
+ ["name", request.name],
147
+ ["order_by", request.orderBy],
148
+ ["organization_id", request.organizationId],
149
+ ["page", request.page],
150
+ [
151
+ "page_size",
152
+ request.pageSize ?? this.client.settings.defaultPageSize
153
+ ],
154
+ ["project_id", request.projectId],
155
+ ["tags", request.tags],
156
+ ["volume_id", request.volumeId]
157
+ )
158
+ },
159
+ unmarshalListSnapshotsResponse
160
+ );
161
+ /**
162
+ * List all snapshots. List all available snapshots in a specified zone. By default, the snapshots listed are ordered by creation date in ascending order. This can be modified via the `order_by` field.
163
+ *
164
+ * @param request - The request {@link ListSnapshotsRequest}
165
+ * @returns A Promise of ListSnapshotsResponse
166
+ */
167
+ listSnapshots = (request = {}) => enrichForPagination("snapshots", this.pageOfListSnapshots, request);
168
+ /**
169
+ * Get a snapshot. Retrieve technical information about a specific snapshot. Details such as size, volume type, and status are returned in the response.
170
+ *
171
+ * @param request - The request {@link GetSnapshotRequest}
172
+ * @returns A Promise of Snapshot
173
+ */
174
+ getSnapshot = (request) => this.client.fetch(
175
+ {
176
+ method: "GET",
177
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam("snapshotId", request.snapshotId)}`
178
+ },
179
+ unmarshalSnapshot
180
+ );
181
+ /**
182
+ * Waits for {@link Snapshot} to be in a final state.
183
+ *
184
+ * @param request - The request {@link GetSnapshotRequest}
185
+ * @param options - The waiting options
186
+ * @returns A Promise of Snapshot
187
+ */
188
+ waitForSnapshot = (request, options) => waitForResource(
189
+ options?.stop ?? ((res) => Promise.resolve(
190
+ !SNAPSHOT_TRANSIENT_STATUSES.includes(res.status)
191
+ )),
192
+ this.getSnapshot,
193
+ request,
194
+ options
195
+ );
196
+ /**
197
+ * Create a snapshot of a volume. To create a snapshot, the volume must be in the `in_use` or the `available` status.
198
+ If your volume is in a transient state, you need to wait until the end of the current operation.
199
+ *
200
+ * @param request - The request {@link CreateSnapshotRequest}
201
+ * @returns A Promise of Snapshot
202
+ */
203
+ createSnapshot = (request) => this.client.fetch(
204
+ {
205
+ body: JSON.stringify(
206
+ marshalCreateSnapshotRequest(request, this.client.settings)
207
+ ),
208
+ headers: jsonContentHeaders,
209
+ method: "POST",
210
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/snapshots`
211
+ },
212
+ unmarshalSnapshot
213
+ );
214
+ /**
215
+ * Import a snapshot from a Scaleway Object Storage bucket. The bucket must contain a QCOW2 image.
216
+ The bucket can be imported into any Availability Zone as long as it is in the same region as the bucket.
217
+ *
218
+ * @param request - The request {@link ImportSnapshotFromObjectStorageRequest}
219
+ * @returns A Promise of Snapshot
220
+ */
221
+ importSnapshotFromObjectStorage = (request) => this.client.fetch(
222
+ {
223
+ body: JSON.stringify(
224
+ marshalImportSnapshotFromObjectStorageRequest(
225
+ request,
226
+ this.client.settings
227
+ )
228
+ ),
229
+ headers: jsonContentHeaders,
230
+ method: "POST",
231
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/snapshots/import-from-object-storage`
232
+ },
233
+ unmarshalSnapshot
234
+ );
235
+ /**
236
+ * Export a snapshot to a Scaleway Object Storage bucket. The snapshot is exported in QCOW2 format.
237
+ The snapshot must not be in transient state.
238
+ *
239
+ * @param request - The request {@link ExportSnapshotToObjectStorageRequest}
240
+ * @returns A Promise of Snapshot
241
+ */
242
+ exportSnapshotToObjectStorage = (request) => this.client.fetch(
243
+ {
244
+ body: JSON.stringify(
245
+ marshalExportSnapshotToObjectStorageRequest(
246
+ request,
247
+ this.client.settings
248
+ )
249
+ ),
250
+ headers: jsonContentHeaders,
251
+ method: "POST",
252
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam("snapshotId", request.snapshotId)}/export-to-object-storage`
253
+ },
254
+ unmarshalSnapshot
255
+ );
256
+ /**
257
+ * Delete a snapshot. You must specify the `snapshot_id` of the snapshot you want to delete. The snapshot must not be in use.
258
+ *
259
+ * @param request - The request {@link DeleteSnapshotRequest}
260
+ */
261
+ deleteSnapshot = (request) => this.client.fetch({
262
+ method: "DELETE",
263
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam("snapshotId", request.snapshotId)}`
264
+ });
265
+ /**
266
+ * Update a snapshot. Update the name or tags of the snapshot.
267
+ *
268
+ * @param request - The request {@link UpdateSnapshotRequest}
269
+ * @returns A Promise of Snapshot
270
+ */
271
+ updateSnapshot = (request) => this.client.fetch(
272
+ {
273
+ body: JSON.stringify(
274
+ marshalUpdateSnapshotRequest(request, this.client.settings)
275
+ ),
276
+ headers: jsonContentHeaders,
277
+ method: "PATCH",
278
+ path: `/block/v1/zones/${validatePathParam("zone", request.zone ?? this.client.settings.defaultZone)}/snapshots/${validatePathParam("snapshotId", request.snapshotId)}`
279
+ },
280
+ unmarshalSnapshot
281
+ );
282
+ }
283
+ export {
284
+ API
285
+ };
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const REFERENCE_TRANSIENT_STATUSES = [
4
+ "attaching",
5
+ "detaching",
6
+ "creating"
7
+ ];
8
+ const SNAPSHOT_TRANSIENT_STATUSES = [
9
+ "creating",
10
+ "deleting",
11
+ "exporting"
12
+ ];
13
+ const VOLUME_TRANSIENT_STATUSES = [
14
+ "creating",
15
+ "deleting",
16
+ "resizing",
17
+ "snapshotting",
18
+ "updating"
19
+ ];
20
+ exports.REFERENCE_TRANSIENT_STATUSES = REFERENCE_TRANSIENT_STATUSES;
21
+ exports.SNAPSHOT_TRANSIENT_STATUSES = SNAPSHOT_TRANSIENT_STATUSES;
22
+ exports.VOLUME_TRANSIENT_STATUSES = VOLUME_TRANSIENT_STATUSES;
@@ -0,0 +1,7 @@
1
+ import type { ReferenceStatus, SnapshotStatus, VolumeStatus } from './types.gen';
2
+ /** Lists transient statutes of the enum {@link ReferenceStatus}. */
3
+ export declare const REFERENCE_TRANSIENT_STATUSES: ReferenceStatus[];
4
+ /** Lists transient statutes of the enum {@link SnapshotStatus}. */
5
+ export declare const SNAPSHOT_TRANSIENT_STATUSES: SnapshotStatus[];
6
+ /** Lists transient statutes of the enum {@link VolumeStatus}. */
7
+ export declare const VOLUME_TRANSIENT_STATUSES: VolumeStatus[];
@@ -0,0 +1,22 @@
1
+ const REFERENCE_TRANSIENT_STATUSES = [
2
+ "attaching",
3
+ "detaching",
4
+ "creating"
5
+ ];
6
+ const SNAPSHOT_TRANSIENT_STATUSES = [
7
+ "creating",
8
+ "deleting",
9
+ "exporting"
10
+ ];
11
+ const VOLUME_TRANSIENT_STATUSES = [
12
+ "creating",
13
+ "deleting",
14
+ "resizing",
15
+ "snapshotting",
16
+ "updating"
17
+ ];
18
+ export {
19
+ REFERENCE_TRANSIENT_STATUSES,
20
+ SNAPSHOT_TRANSIENT_STATUSES,
21
+ VOLUME_TRANSIENT_STATUSES
22
+ };
@@ -0,0 +1,23 @@
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
+ const validationRules_gen = require("./validation-rules.gen.cjs");
7
+ exports.API = api_gen.API;
8
+ exports.REFERENCE_TRANSIENT_STATUSES = content_gen.REFERENCE_TRANSIENT_STATUSES;
9
+ exports.SNAPSHOT_TRANSIENT_STATUSES = content_gen.SNAPSHOT_TRANSIENT_STATUSES;
10
+ exports.VOLUME_TRANSIENT_STATUSES = content_gen.VOLUME_TRANSIENT_STATUSES;
11
+ exports.marshalCreateSnapshotRequest = marshalling_gen.marshalCreateSnapshotRequest;
12
+ exports.marshalCreateVolumeRequest = marshalling_gen.marshalCreateVolumeRequest;
13
+ exports.marshalExportSnapshotToObjectStorageRequest = marshalling_gen.marshalExportSnapshotToObjectStorageRequest;
14
+ exports.marshalImportSnapshotFromObjectStorageRequest = marshalling_gen.marshalImportSnapshotFromObjectStorageRequest;
15
+ exports.marshalUpdateSnapshotRequest = marshalling_gen.marshalUpdateSnapshotRequest;
16
+ exports.marshalUpdateVolumeRequest = marshalling_gen.marshalUpdateVolumeRequest;
17
+ exports.unmarshalListSnapshotsResponse = marshalling_gen.unmarshalListSnapshotsResponse;
18
+ exports.unmarshalListVolumeTypesResponse = marshalling_gen.unmarshalListVolumeTypesResponse;
19
+ exports.unmarshalListVolumesResponse = marshalling_gen.unmarshalListVolumesResponse;
20
+ exports.unmarshalReference = marshalling_gen.unmarshalReference;
21
+ exports.unmarshalSnapshot = marshalling_gen.unmarshalSnapshot;
22
+ exports.unmarshalVolume = marshalling_gen.unmarshalVolume;
23
+ exports.ValidationRules = validationRules_gen;
@@ -0,0 +1,5 @@
1
+ export { API } from './api.gen';
2
+ export * from './content.gen';
3
+ export * from './marshalling.gen';
4
+ export type { CreateSnapshotRequest, CreateVolumeRequest, CreateVolumeRequestFromEmpty, CreateVolumeRequestFromSnapshot, DeleteSnapshotRequest, DeleteVolumeRequest, ExportSnapshotToObjectStorageRequest, GetSnapshotRequest, GetVolumeRequest, ImportSnapshotFromObjectStorageRequest, ListSnapshotsRequest, ListSnapshotsRequestOrderBy, ListSnapshotsResponse, ListVolumeTypesRequest, ListVolumeTypesResponse, ListVolumesRequest, ListVolumesRequestOrderBy, ListVolumesResponse, Reference, ReferenceStatus, ReferenceType, Snapshot, SnapshotParentVolume, SnapshotStatus, StorageClass, UpdateSnapshotRequest, UpdateVolumeRequest, Volume, VolumeSpecifications, VolumeStatus, VolumeType, } from './types.gen';
5
+ export * as ValidationRules from './validation-rules.gen';
@@ -0,0 +1,23 @@
1
+ import { API } from "./api.gen.js";
2
+ import { REFERENCE_TRANSIENT_STATUSES, SNAPSHOT_TRANSIENT_STATUSES, VOLUME_TRANSIENT_STATUSES } from "./content.gen.js";
3
+ import { marshalCreateSnapshotRequest, marshalCreateVolumeRequest, marshalExportSnapshotToObjectStorageRequest, marshalImportSnapshotFromObjectStorageRequest, marshalUpdateSnapshotRequest, marshalUpdateVolumeRequest, unmarshalListSnapshotsResponse, unmarshalListVolumeTypesResponse, unmarshalListVolumesResponse, unmarshalReference, unmarshalSnapshot, unmarshalVolume } from "./marshalling.gen.js";
4
+ import * as validationRules_gen from "./validation-rules.gen.js";
5
+ export {
6
+ API,
7
+ REFERENCE_TRANSIENT_STATUSES,
8
+ SNAPSHOT_TRANSIENT_STATUSES,
9
+ VOLUME_TRANSIENT_STATUSES,
10
+ validationRules_gen as ValidationRules,
11
+ marshalCreateSnapshotRequest,
12
+ marshalCreateVolumeRequest,
13
+ marshalExportSnapshotToObjectStorageRequest,
14
+ marshalImportSnapshotFromObjectStorageRequest,
15
+ marshalUpdateSnapshotRequest,
16
+ marshalUpdateVolumeRequest,
17
+ unmarshalListSnapshotsResponse,
18
+ unmarshalListVolumeTypesResponse,
19
+ unmarshalListVolumesResponse,
20
+ unmarshalReference,
21
+ unmarshalSnapshot,
22
+ unmarshalVolume
23
+ };
@@ -0,0 +1,198 @@
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 unmarshalReference = (data) => {
6
+ if (!sdkClient.isJSONObject(data)) {
7
+ throw new TypeError(
8
+ `Unmarshalling the type 'Reference' failed as data isn't a dictionary.`
9
+ );
10
+ }
11
+ return {
12
+ createdAt: sdkClient.unmarshalDate(data.created_at),
13
+ id: data.id,
14
+ productResourceId: data.product_resource_id,
15
+ productResourceType: data.product_resource_type,
16
+ status: data.status,
17
+ type: data.type
18
+ };
19
+ };
20
+ const unmarshalSnapshotParentVolume = (data) => {
21
+ if (!sdkClient.isJSONObject(data)) {
22
+ throw new TypeError(
23
+ `Unmarshalling the type 'SnapshotParentVolume' failed as data isn't a dictionary.`
24
+ );
25
+ }
26
+ return {
27
+ id: data.id,
28
+ name: data.name,
29
+ status: data.status,
30
+ type: data.type
31
+ };
32
+ };
33
+ const unmarshalSnapshot = (data) => {
34
+ if (!sdkClient.isJSONObject(data)) {
35
+ throw new TypeError(
36
+ `Unmarshalling the type 'Snapshot' failed as data isn't a dictionary.`
37
+ );
38
+ }
39
+ return {
40
+ class: data.class,
41
+ createdAt: sdkClient.unmarshalDate(data.created_at),
42
+ id: data.id,
43
+ name: data.name,
44
+ parentVolume: data.parent_volume ? unmarshalSnapshotParentVolume(data.parent_volume) : void 0,
45
+ projectId: data.project_id,
46
+ references: sdkClient.unmarshalArrayOfObject(data.references, unmarshalReference),
47
+ size: data.size,
48
+ status: data.status,
49
+ tags: data.tags,
50
+ updatedAt: sdkClient.unmarshalDate(data.updated_at),
51
+ zone: data.zone
52
+ };
53
+ };
54
+ const unmarshalVolumeSpecifications = (data) => {
55
+ if (!sdkClient.isJSONObject(data)) {
56
+ throw new TypeError(
57
+ `Unmarshalling the type 'VolumeSpecifications' failed as data isn't a dictionary.`
58
+ );
59
+ }
60
+ return {
61
+ class: data.class,
62
+ perfIops: data.perf_iops
63
+ };
64
+ };
65
+ const unmarshalVolume = (data) => {
66
+ if (!sdkClient.isJSONObject(data)) {
67
+ throw new TypeError(
68
+ `Unmarshalling the type 'Volume' failed as data isn't a dictionary.`
69
+ );
70
+ }
71
+ return {
72
+ createdAt: sdkClient.unmarshalDate(data.created_at),
73
+ id: data.id,
74
+ lastDetachedAt: sdkClient.unmarshalDate(data.last_detached_at),
75
+ name: data.name,
76
+ parentSnapshotId: data.parent_snapshot_id,
77
+ projectId: data.project_id,
78
+ references: sdkClient.unmarshalArrayOfObject(data.references, unmarshalReference),
79
+ size: data.size,
80
+ specs: data.specs ? unmarshalVolumeSpecifications(data.specs) : void 0,
81
+ status: data.status,
82
+ tags: data.tags,
83
+ type: data.type,
84
+ updatedAt: sdkClient.unmarshalDate(data.updated_at),
85
+ zone: data.zone
86
+ };
87
+ };
88
+ const unmarshalListSnapshotsResponse = (data) => {
89
+ if (!sdkClient.isJSONObject(data)) {
90
+ throw new TypeError(
91
+ `Unmarshalling the type 'ListSnapshotsResponse' failed as data isn't a dictionary.`
92
+ );
93
+ }
94
+ return {
95
+ snapshots: sdkClient.unmarshalArrayOfObject(data.snapshots, unmarshalSnapshot),
96
+ totalCount: data.total_count
97
+ };
98
+ };
99
+ const unmarshalVolumeType = (data) => {
100
+ if (!sdkClient.isJSONObject(data)) {
101
+ throw new TypeError(
102
+ `Unmarshalling the type 'VolumeType' failed as data isn't a dictionary.`
103
+ );
104
+ }
105
+ return {
106
+ pricing: data.pricing ? sdkClient.unmarshalMoney(data.pricing) : void 0,
107
+ snapshotPricing: data.snapshot_pricing ? sdkClient.unmarshalMoney(data.snapshot_pricing) : void 0,
108
+ specs: data.specs ? unmarshalVolumeSpecifications(data.specs) : void 0,
109
+ type: data.type
110
+ };
111
+ };
112
+ const unmarshalListVolumeTypesResponse = (data) => {
113
+ if (!sdkClient.isJSONObject(data)) {
114
+ throw new TypeError(
115
+ `Unmarshalling the type 'ListVolumeTypesResponse' failed as data isn't a dictionary.`
116
+ );
117
+ }
118
+ return {
119
+ totalCount: data.total_count,
120
+ volumeTypes: sdkClient.unmarshalArrayOfObject(data.volume_types, unmarshalVolumeType)
121
+ };
122
+ };
123
+ const unmarshalListVolumesResponse = (data) => {
124
+ if (!sdkClient.isJSONObject(data)) {
125
+ throw new TypeError(
126
+ `Unmarshalling the type 'ListVolumesResponse' failed as data isn't a dictionary.`
127
+ );
128
+ }
129
+ return {
130
+ totalCount: data.total_count,
131
+ volumes: sdkClient.unmarshalArrayOfObject(data.volumes, unmarshalVolume)
132
+ };
133
+ };
134
+ const marshalCreateSnapshotRequest = (request, defaults) => ({
135
+ name: request.name || randomName("snp"),
136
+ project_id: request.projectId ?? defaults.defaultProjectId,
137
+ tags: request.tags,
138
+ volume_id: request.volumeId
139
+ });
140
+ const marshalCreateVolumeRequestFromEmpty = (request, defaults) => ({
141
+ size: request.size
142
+ });
143
+ const marshalCreateVolumeRequestFromSnapshot = (request, defaults) => ({
144
+ size: request.size,
145
+ snapshot_id: request.snapshotId
146
+ });
147
+ const marshalCreateVolumeRequest = (request, defaults) => ({
148
+ name: request.name || randomName("vol"),
149
+ project_id: request.projectId ?? defaults.defaultProjectId,
150
+ tags: request.tags,
151
+ ...sdkClient.resolveOneOf([
152
+ {
153
+ param: "from_empty",
154
+ value: request.fromEmpty !== void 0 ? marshalCreateVolumeRequestFromEmpty(request.fromEmpty) : void 0
155
+ },
156
+ {
157
+ param: "from_snapshot",
158
+ value: request.fromSnapshot !== void 0 ? marshalCreateVolumeRequestFromSnapshot(
159
+ request.fromSnapshot
160
+ ) : void 0
161
+ }
162
+ ]),
163
+ ...sdkClient.resolveOneOf([{ param: "perf_iops", value: request.perfIops }])
164
+ });
165
+ const marshalExportSnapshotToObjectStorageRequest = (request, defaults) => ({
166
+ bucket: request.bucket,
167
+ key: request.key
168
+ });
169
+ const marshalImportSnapshotFromObjectStorageRequest = (request, defaults) => ({
170
+ bucket: request.bucket,
171
+ key: request.key,
172
+ name: request.name,
173
+ project_id: request.projectId ?? defaults.defaultProjectId,
174
+ size: request.size,
175
+ tags: request.tags
176
+ });
177
+ const marshalUpdateSnapshotRequest = (request, defaults) => ({
178
+ name: request.name,
179
+ tags: request.tags
180
+ });
181
+ const marshalUpdateVolumeRequest = (request, defaults) => ({
182
+ name: request.name,
183
+ perf_iops: request.perfIops,
184
+ size: request.size,
185
+ tags: request.tags
186
+ });
187
+ exports.marshalCreateSnapshotRequest = marshalCreateSnapshotRequest;
188
+ exports.marshalCreateVolumeRequest = marshalCreateVolumeRequest;
189
+ exports.marshalExportSnapshotToObjectStorageRequest = marshalExportSnapshotToObjectStorageRequest;
190
+ exports.marshalImportSnapshotFromObjectStorageRequest = marshalImportSnapshotFromObjectStorageRequest;
191
+ exports.marshalUpdateSnapshotRequest = marshalUpdateSnapshotRequest;
192
+ exports.marshalUpdateVolumeRequest = marshalUpdateVolumeRequest;
193
+ exports.unmarshalListSnapshotsResponse = unmarshalListSnapshotsResponse;
194
+ exports.unmarshalListVolumeTypesResponse = unmarshalListVolumeTypesResponse;
195
+ exports.unmarshalListVolumesResponse = unmarshalListVolumesResponse;
196
+ exports.unmarshalReference = unmarshalReference;
197
+ exports.unmarshalSnapshot = unmarshalSnapshot;
198
+ exports.unmarshalVolume = unmarshalVolume;
@@ -0,0 +1,14 @@
1
+ import type { DefaultValues } from '@scaleway/sdk-client';
2
+ import type { CreateSnapshotRequest, CreateVolumeRequest, ExportSnapshotToObjectStorageRequest, ImportSnapshotFromObjectStorageRequest, ListSnapshotsResponse, ListVolumeTypesResponse, ListVolumesResponse, Reference, Snapshot, UpdateSnapshotRequest, UpdateVolumeRequest, Volume } from './types.gen';
3
+ export declare const unmarshalReference: (data: unknown) => Reference;
4
+ export declare const unmarshalSnapshot: (data: unknown) => Snapshot;
5
+ export declare const unmarshalVolume: (data: unknown) => Volume;
6
+ export declare const unmarshalListSnapshotsResponse: (data: unknown) => ListSnapshotsResponse;
7
+ export declare const unmarshalListVolumeTypesResponse: (data: unknown) => ListVolumeTypesResponse;
8
+ export declare const unmarshalListVolumesResponse: (data: unknown) => ListVolumesResponse;
9
+ export declare const marshalCreateSnapshotRequest: (request: CreateSnapshotRequest, defaults: DefaultValues) => Record<string, unknown>;
10
+ export declare const marshalCreateVolumeRequest: (request: CreateVolumeRequest, defaults: DefaultValues) => Record<string, unknown>;
11
+ export declare const marshalExportSnapshotToObjectStorageRequest: (request: ExportSnapshotToObjectStorageRequest, defaults: DefaultValues) => Record<string, unknown>;
12
+ export declare const marshalImportSnapshotFromObjectStorageRequest: (request: ImportSnapshotFromObjectStorageRequest, defaults: DefaultValues) => Record<string, unknown>;
13
+ export declare const marshalUpdateSnapshotRequest: (request: UpdateSnapshotRequest, defaults: DefaultValues) => Record<string, unknown>;
14
+ export declare const marshalUpdateVolumeRequest: (request: UpdateVolumeRequest, defaults: DefaultValues) => Record<string, unknown>;