-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathformat.ts
More file actions
51 lines (47 loc) · 1.55 KB
/
format.ts
File metadata and controls
51 lines (47 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { google } from '@google-cloud/bigquery-reservation/build/protos/protos'
import cuid from 'cuid'
import { GcpBigQueryReservationCapacity } from '../../types/generated'
import { toISOString } from '../../utils/dateutils'
import { enumKeyToString } from '../../utils/format'
import { RawGcpBigQueryReservationCapacityCommitment } from './data'
export default ({
service,
region,
}: {
service: RawGcpBigQueryReservationCapacityCommitment
region: string
}): GcpBigQueryReservationCapacity => {
const {
name,
slotCount,
plan,
state,
commitmentStartTime,
commitmentEndTime,
failureStatus,
renewalPlan,
projectId,
} = service
return {
id: name || cuid(),
name,
slotCount: slotCount?.toString() || '0',
plan: enumKeyToString(google.cloud.bigquery.reservation.v1.CapacityCommitment.CommitmentPlan, plan),
state: enumKeyToString(google.cloud.bigquery.reservation.v1.CapacityCommitment.State, state),
commitmentStartTime: toISOString(commitmentStartTime?.seconds?.toString()),
commitmentEndTime: toISOString(commitmentEndTime?.seconds?.toString()),
failureStatusCode: failureStatus?.code || 0,
failureStatusMessage: failureStatus?.message || '',
failureStatusDetails: failureStatus?.details?.map(({
type_url,
value,
}) => ({
id: cuid(),
typeUrl: type_url || '',
value: value?.toString() || '' ,
})) || [],
renewalPlan: enumKeyToString(google.cloud.bigquery.reservation.v1.CapacityCommitment.CommitmentPlan, renewalPlan),
projectId,
region,
}
}