Skip to content

Commit 4492a27

Browse files
committed
feat: export encodeType/decodeType, fix flow types
1 parent 8bc405a commit 4492a27

File tree

2 files changed

+42
-5
lines changed

2 files changed

+42
-5
lines changed

spBv1.0.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ function encodeType(typeString) {
247247
return 0
248248
}
249249
}
250+
exports.encodeType = encodeType
250251

251252
function decodeType(typeInt) {
252253
switch (typeInt) {
@@ -292,6 +293,7 @@ function decodeType(typeInt) {
292293
return 'PropertySetList'
293294
}
294295
}
296+
exports.decodeType = decodeType
295297

296298
function encodeTypes(typeArray) {
297299
let types = []

spBv1.0.js.flow

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ export type NumberDataType =
1212
| 'Float'
1313
| 'Double'
1414

15+
export type BigIntDataType = 'Int64' | 'UInt64'
16+
1517
export type StringDataType = 'String' | 'Text' | 'UUID'
1618

1719
export type MetaData = {|
@@ -32,6 +34,12 @@ export type NumberPropertyValue = {|
3234
value?: ?number,
3335
|}
3436

37+
export type BigIntPropertyValue = {|
38+
type: BigIntDataType,
39+
// $FlowFixMe
40+
value?: ?bigint,
41+
|}
42+
3543
export type StringPropertyValue = {|
3644
type: StringDataType,
3745
value?: ?string,
@@ -44,7 +52,8 @@ export type BooleanPropertyValue = {|
4452

4553
export type DateTimePropertyValue = {|
4654
type: 'DateTime',
47-
value?: ?(Date | number),
55+
// $FlowFixMe
56+
value?: ?(Date | number | bigint),
4857
|}
4958

5059
export type PropertySetValue = {|
@@ -59,6 +68,7 @@ export type PropertySetListValue = {|
5968

6069
export type PropertyValue =
6170
| NumberPropertyValue
71+
| BigIntPropertyValue
6272
| StringPropertyValue
6373
| BooleanPropertyValue
6474
| DateTimePropertyValue
@@ -70,6 +80,8 @@ export type PropertySet = { [key: string]: PropertyValue }
7080
export type MetricBase = {|
7181
name?: ?string,
7282
alias?: ?number,
83+
// $FlowFixMe
84+
timestamp?: ?(number | bigint),
7385
isHistorical?: ?boolean,
7486
isTransient?: ?boolean,
7587
metadata?: ?MetaData,
@@ -82,10 +94,18 @@ export type NumberMetric = {|
8294
value?: ?number,
8395
|}
8496

97+
export type BigIntMetric = {|
98+
...MetricBase,
99+
type: BigIntDataType,
100+
// $FlowFixMe
101+
value?: ?bigint,
102+
|}
103+
85104
export type DateTimeMetric = {|
86105
...MetricBase,
87106
type: 'DateTime',
88-
value?: ?(Date | number),
107+
// $FlowFixMe
108+
value?: ?(Date | number | bigint),
89109
|}
90110

91111
export type BooleanMetric = {|
@@ -104,16 +124,19 @@ export type DataSetValueTypes = {|
104124
Int8: number,
105125
Int16: number,
106126
Int32: number,
107-
Int64: number,
127+
// $FlowFixMe
128+
Int64: number | bigint,
108129
UInt8: number,
109130
UInt16: number,
110131
UInt32: number,
111-
UInt64: number,
132+
// $FlowFixMe
133+
UInt64: number | bigint,
112134
Float: number,
113135
Double: number,
114136
Boolean: boolean,
115137
String: string,
116-
DateTime: Date | number,
138+
// $FlowFixMe
139+
DateTime: Date | number | bigint,
117140
Text: string,
118141
UUID: string,
119142
|}
@@ -155,6 +178,7 @@ export type TemplateMetric = {|
155178

156179
export type Metric =
157180
| NumberMetric
181+
| BigIntMetric
158182
| BooleanMetric
159183
| StringMetric
160184
| DateTimeMetric
@@ -167,6 +191,13 @@ export type NumberParameter = {|
167191
value?: ?number,
168192
|}
169193

194+
export type BigIntParameter = {|
195+
name?: ?string,
196+
type: BigIntDataType,
197+
// $FlowFixMe
198+
value?: ?bigint,
199+
|}
200+
170201
export type BooleanParameter = {|
171202
name?: ?string,
172203
type: 'Boolean',
@@ -187,6 +218,7 @@ export type DateTimeParameter = {|
187218

188219
export type Parameter =
189220
| NumberParameter
221+
| BigIntParameter
190222
| BooleanParameter
191223
| StringParameter
192224
| DateTimeParameter
@@ -209,3 +241,6 @@ declare export function encodePayload(
209241
payload: $DeepReadOnly<Payload>
210242
): Uint8Array
211243
declare export function decodePayload(payload: Uint8Array): Payload
244+
245+
declare export function encodeType(typeString: string): number
246+
declare export function decodeType(typeInt: number): ?string

0 commit comments

Comments
 (0)