@@ -21,53 +21,79 @@ import type {
2121 UpdateServerRequest ,
2222} from './types.gen'
2323
24- const unmarshalServerTypeCPU = ( data : unknown ) => {
24+ export const unmarshalOS = ( data : unknown ) : OS => {
25+ if ( ! isJSONObject ( data ) ) {
26+ throw new TypeError (
27+ `Unmarshalling the type 'OS' failed as data isn't a dictionary.` ,
28+ )
29+ }
30+
31+ return {
32+ compatibleServerTypes : data . compatible_server_types ,
33+ id : data . id ,
34+ imageUrl : data . image_url ,
35+ label : data . label ,
36+ name : data . name ,
37+ } as OS
38+ }
39+
40+ const unmarshalServerTypeCPU = ( data : unknown ) : ServerTypeCPU => {
2541 if ( ! isJSONObject ( data ) ) {
2642 throw new TypeError (
2743 `Unmarshalling the type 'ServerTypeCPU' failed as data isn't a dictionary.` ,
2844 )
2945 }
3046
31- return { coreCount : data . core_count , name : data . name } as ServerTypeCPU
47+ return {
48+ coreCount : data . core_count ,
49+ name : data . name ,
50+ } as ServerTypeCPU
3251}
3352
34- const unmarshalServerTypeDisk = ( data : unknown ) => {
53+ const unmarshalServerTypeDisk = ( data : unknown ) : ServerTypeDisk => {
3554 if ( ! isJSONObject ( data ) ) {
3655 throw new TypeError (
3756 `Unmarshalling the type 'ServerTypeDisk' failed as data isn't a dictionary.` ,
3857 )
3958 }
4059
41- return { capacity : data . capacity , type : data . type } as ServerTypeDisk
60+ return {
61+ capacity : data . capacity ,
62+ type : data . type ,
63+ } as ServerTypeDisk
4264}
4365
44- const unmarshalServerTypeMemory = ( data : unknown ) => {
66+ const unmarshalServerTypeMemory = ( data : unknown ) : ServerTypeMemory => {
4567 if ( ! isJSONObject ( data ) ) {
4668 throw new TypeError (
4769 `Unmarshalling the type 'ServerTypeMemory' failed as data isn't a dictionary.` ,
4870 )
4971 }
5072
51- return { capacity : data . capacity , type : data . type } as ServerTypeMemory
73+ return {
74+ capacity : data . capacity ,
75+ type : data . type ,
76+ } as ServerTypeMemory
5277}
5378
54- export const unmarshalOS = ( data : unknown ) => {
79+ export const unmarshalServerType = ( data : unknown ) : ServerType => {
5580 if ( ! isJSONObject ( data ) ) {
5681 throw new TypeError (
57- `Unmarshalling the type 'OS ' failed as data isn't a dictionary.` ,
82+ `Unmarshalling the type 'ServerType ' failed as data isn't a dictionary.` ,
5883 )
5984 }
6085
6186 return {
62- compatibleServerTypes : data . compatible_server_types ,
63- id : data . id ,
64- imageUrl : data . image_url ,
65- label : data . label ,
87+ cpu : data . cpu ? unmarshalServerTypeCPU ( data . cpu ) : undefined ,
88+ disk : data . disk ? unmarshalServerTypeDisk ( data . disk ) : undefined ,
89+ memory : data . memory ? unmarshalServerTypeMemory ( data . memory ) : undefined ,
90+ minimumLeaseDuration : data . minimum_lease_duration ,
6691 name : data . name ,
67- } as OS
92+ stock : data . stock ,
93+ } as ServerType
6894}
6995
70- export const unmarshalServer = ( data : unknown ) => {
96+ export const unmarshalServer = ( data : unknown ) : Server => {
7197 if ( ! isJSONObject ( data ) ) {
7298 throw new TypeError (
7399 `Unmarshalling the type 'Server' failed as data isn't a dictionary.` ,
@@ -90,24 +116,7 @@ export const unmarshalServer = (data: unknown) => {
90116 } as Server
91117}
92118
93- export const unmarshalServerType = ( data : unknown ) => {
94- if ( ! isJSONObject ( data ) ) {
95- throw new TypeError (
96- `Unmarshalling the type 'ServerType' failed as data isn't a dictionary.` ,
97- )
98- }
99-
100- return {
101- cpu : data . cpu ? unmarshalServerTypeCPU ( data . cpu ) : undefined ,
102- disk : data . disk ? unmarshalServerTypeDisk ( data . disk ) : undefined ,
103- memory : data . memory ? unmarshalServerTypeMemory ( data . memory ) : undefined ,
104- minimumLeaseDuration : data . minimum_lease_duration ,
105- name : data . name ,
106- stock : data . stock ,
107- } as ServerType
108- }
109-
110- export const unmarshalListOSResponse = ( data : unknown ) => {
119+ export const unmarshalListOSResponse = ( data : unknown ) : ListOSResponse => {
111120 if ( ! isJSONObject ( data ) ) {
112121 throw new TypeError (
113122 `Unmarshalling the type 'ListOSResponse' failed as data isn't a dictionary.` ,
@@ -120,7 +129,9 @@ export const unmarshalListOSResponse = (data: unknown) => {
120129 } as ListOSResponse
121130}
122131
123- export const unmarshalListServerTypesResponse = ( data : unknown ) => {
132+ export const unmarshalListServerTypesResponse = (
133+ data : unknown ,
134+ ) : ListServerTypesResponse => {
124135 if ( ! isJSONObject ( data ) ) {
125136 throw new TypeError (
126137 `Unmarshalling the type 'ListServerTypesResponse' failed as data isn't a dictionary.` ,
@@ -132,7 +143,9 @@ export const unmarshalListServerTypesResponse = (data: unknown) => {
132143 } as ListServerTypesResponse
133144}
134145
135- export const unmarshalListServersResponse = ( data : unknown ) => {
146+ export const unmarshalListServersResponse = (
147+ data : unknown ,
148+ ) : ListServersResponse => {
136149 if ( ! isJSONObject ( data ) ) {
137150 throw new TypeError (
138151 `Unmarshalling the type 'ListServersResponse' failed as data isn't a dictionary.` ,
0 commit comments