Skip to content

Commit e985f34

Browse files
jremy42protobuf-ci-cdremyleone
authored
feat(sdk-js): add new locality type (#2157)
Co-authored-by: protobuf-ci-cd <[email protected]> Co-authored-by: Rémy Léone <[email protected]>
1 parent ba1119f commit e985f34

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

packages/client/src/scw/locality.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,27 @@ export type Zone =
1313
| 'pl-waw-3'
1414
| (string & {})
1515
/* eslint-enable @typescript-eslint/ban-types */
16+
17+
export type ApiLocality =
18+
| { type: 'zone'; zones: Zone[] }
19+
| { type: 'region'; regions: Region[] }
20+
| { type: 'global' }
21+
| { type: 'unspecified' }
22+
23+
24+
export function toApiLocality(
25+
legacy?: { zones?: Zone[]; regions?: Region[] }
26+
): ApiLocality {
27+
if (!legacy) {
28+
return { type: 'unspecified' }
29+
}
30+
const { zones, regions } = legacy
31+
if (zones && zones.length > 0) {
32+
return { type: 'zone', zones }
33+
}
34+
if (regions && regions.length > 0) {
35+
return { type: 'region', regions }
36+
}
37+
38+
return { type: 'global' }
39+
}

0 commit comments

Comments
 (0)