Skip to content

Commit c10534f

Browse files
author
protobuf-ci-cd
committed
feat(sdk-js): add new locality type
1 parent 9948d9e commit c10534f

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

packages/client/src/scw/locality.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,26 @@ 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+
return { type: 'global' }
38+
}

0 commit comments

Comments
 (0)