@xube/kit-aws-data-schema 0.2.8 → 0.2.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +2 -1
- package/dist/decode/aggregate.d.ts +9 -93
- package/dist/decode/aggregate.d.ts.map +1 -1
- package/dist/decode/reading.d.ts +50 -71
- package/dist/decode/reading.d.ts.map +1 -1
- package/dist/decode/reading.js +38 -8
- package/dist/get/get-data-by-date-range.d.ts +15 -161
- package/dist/get/get-data-by-date-range.d.ts.map +1 -1
- package/dist/get/get-data-by-date-range.js +2 -1
- package/dist/message/message.d.ts +1 -15
- package/dist/message/message.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/constants.ts +3 -1
- package/src/decode/reading.test.ts +231 -0
- package/src/decode/reading.ts +63 -15
- package/src/get/get-data-by-date-range.ts +2 -1
package/dist/constants.d.ts
CHANGED
package/dist/constants.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,eAAO,MAAM,uBAAuB,oBAAoB,CAAC"}
|
|
1
|
+
{"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../src/constants.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,SAAS,CAAC;AAEhC,eAAO,MAAM,uBAAuB,oBAAoB,CAAC;AAEzD,eAAO,MAAM,0BAA0B,MAAM,CAAC"}
|
package/dist/constants.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.DATA_TABLE_NAME_ENV_VAR = exports.DATA_TYPE = void 0;
|
|
3
|
+
exports.READING_VERSION_IDENTIFIER = exports.DATA_TABLE_NAME_ENV_VAR = exports.DATA_TYPE = void 0;
|
|
4
4
|
exports.DATA_TYPE = "data";
|
|
5
5
|
exports.DATA_TABLE_NAME_ENV_VAR = "DATA_TABLE_NAME";
|
|
6
|
+
exports.READING_VERSION_IDENTIFIER = "v";
|
|
@@ -1,118 +1,34 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
export declare const AggregateMetadataSchema: z.ZodObject<{
|
|
3
3
|
v: z.ZodNumber;
|
|
4
|
-
},
|
|
5
|
-
v: number;
|
|
6
|
-
}, {
|
|
7
|
-
v: number;
|
|
8
|
-
}>;
|
|
4
|
+
}, z.core.$strip>;
|
|
9
5
|
export type AggregateMetadata = z.infer<typeof AggregateMetadataSchema>;
|
|
10
6
|
export declare const isAggregateMetadata: (obj: unknown) => obj is AggregateMetadata;
|
|
11
7
|
export declare const AggregateMetaDataV1Version: number;
|
|
12
|
-
export declare const AggregateMetadataV1Schema: z.ZodObject<
|
|
13
|
-
v: z.ZodNumber;
|
|
14
|
-
}, {
|
|
8
|
+
export declare const AggregateMetadataV1Schema: z.ZodObject<{
|
|
15
9
|
v: z.ZodLiteral<number>;
|
|
16
10
|
s: z.ZodNumber;
|
|
17
11
|
m: z.ZodArray<z.ZodObject<{
|
|
18
12
|
m: z.ZodObject<{
|
|
19
13
|
s: z.ZodNumber;
|
|
20
14
|
us: z.ZodNumber;
|
|
21
|
-
},
|
|
22
|
-
s: number;
|
|
23
|
-
us: number;
|
|
24
|
-
}, {
|
|
25
|
-
s: number;
|
|
26
|
-
us: number;
|
|
27
|
-
}>;
|
|
15
|
+
}, z.core.$strip>;
|
|
28
16
|
s: z.ZodOptional<z.ZodNumber>;
|
|
29
|
-
},
|
|
30
|
-
|
|
31
|
-
s: number;
|
|
32
|
-
us: number;
|
|
33
|
-
};
|
|
34
|
-
s?: number | undefined;
|
|
35
|
-
}, {
|
|
36
|
-
m: {
|
|
37
|
-
s: number;
|
|
38
|
-
us: number;
|
|
39
|
-
};
|
|
40
|
-
s?: number | undefined;
|
|
41
|
-
}>, "many">;
|
|
42
|
-
}>, "strip", z.ZodTypeAny, {
|
|
43
|
-
s: number;
|
|
44
|
-
m: {
|
|
45
|
-
m: {
|
|
46
|
-
s: number;
|
|
47
|
-
us: number;
|
|
48
|
-
};
|
|
49
|
-
s?: number | undefined;
|
|
50
|
-
}[];
|
|
51
|
-
v: number;
|
|
52
|
-
}, {
|
|
53
|
-
s: number;
|
|
54
|
-
m: {
|
|
55
|
-
m: {
|
|
56
|
-
s: number;
|
|
57
|
-
us: number;
|
|
58
|
-
};
|
|
59
|
-
s?: number | undefined;
|
|
60
|
-
}[];
|
|
61
|
-
v: number;
|
|
62
|
-
}>;
|
|
17
|
+
}, z.core.$strip>>;
|
|
18
|
+
}, z.core.$strip>;
|
|
63
19
|
export type AggregateMetadataV1 = z.infer<typeof AggregateMetadataV1Schema>;
|
|
64
20
|
export declare const isAggregateMetadataV1: (obj: unknown) => obj is AggregateMetadataV1;
|
|
65
|
-
export declare const AggregateMetadataSchemas: z.ZodObject<
|
|
66
|
-
v: z.ZodNumber;
|
|
67
|
-
}, {
|
|
21
|
+
export declare const AggregateMetadataSchemas: z.ZodObject<{
|
|
68
22
|
v: z.ZodLiteral<number>;
|
|
69
23
|
s: z.ZodNumber;
|
|
70
24
|
m: z.ZodArray<z.ZodObject<{
|
|
71
25
|
m: z.ZodObject<{
|
|
72
26
|
s: z.ZodNumber;
|
|
73
27
|
us: z.ZodNumber;
|
|
74
|
-
},
|
|
75
|
-
s: number;
|
|
76
|
-
us: number;
|
|
77
|
-
}, {
|
|
78
|
-
s: number;
|
|
79
|
-
us: number;
|
|
80
|
-
}>;
|
|
28
|
+
}, z.core.$strip>;
|
|
81
29
|
s: z.ZodOptional<z.ZodNumber>;
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
s: number;
|
|
85
|
-
us: number;
|
|
86
|
-
};
|
|
87
|
-
s?: number | undefined;
|
|
88
|
-
}, {
|
|
89
|
-
m: {
|
|
90
|
-
s: number;
|
|
91
|
-
us: number;
|
|
92
|
-
};
|
|
93
|
-
s?: number | undefined;
|
|
94
|
-
}>, "many">;
|
|
95
|
-
}>, "strip", z.ZodTypeAny, {
|
|
96
|
-
s: number;
|
|
97
|
-
m: {
|
|
98
|
-
m: {
|
|
99
|
-
s: number;
|
|
100
|
-
us: number;
|
|
101
|
-
};
|
|
102
|
-
s?: number | undefined;
|
|
103
|
-
}[];
|
|
104
|
-
v: number;
|
|
105
|
-
}, {
|
|
106
|
-
s: number;
|
|
107
|
-
m: {
|
|
108
|
-
m: {
|
|
109
|
-
s: number;
|
|
110
|
-
us: number;
|
|
111
|
-
};
|
|
112
|
-
s?: number | undefined;
|
|
113
|
-
}[];
|
|
114
|
-
v: number;
|
|
115
|
-
}>;
|
|
30
|
+
}, z.core.$strip>>;
|
|
31
|
+
}, z.core.$strip>;
|
|
116
32
|
export type AggregateMetadataTypes = z.infer<typeof AggregateMetadataSchemas>;
|
|
117
33
|
export declare const isAggregateMetadataTypes: (obj: unknown) => obj is AggregateMetadataTypes;
|
|
118
34
|
//# sourceMappingURL=aggregate.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../../src/decode/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,eAAO,MAAM,uBAAuB
|
|
1
|
+
{"version":3,"file":"aggregate.d.ts","sourceRoot":"","sources":["../../src/decode/aggregate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,CAAC,EAAC,MAAM,KAAK,CAAC;AAGtB,eAAO,MAAM,uBAAuB;;iBAGlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,eAAO,MAAM,mBAAmB,QAAS,OAAO,KAAG,GAAG,IAAI,iBACR,CAAC;AAEnD,eAAO,MAAM,0BAA0B,EAAE,MAAU,CAAA;AACnD,eAAO,MAAM,yBAAyB;;;;;;;;;;iBAInC,CAAC;AACJ,MAAM,MAAM,mBAAmB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,yBAAyB,CAAC,CAAC;AAC5E,eAAO,MAAM,qBAAqB,QAAS,OAAO,KAAG,GAAG,IAAI,mBACV,CAAC;AAEnD,eAAO,MAAM,wBAAwB;;;;;;;;;;iBACV,CAAC;AAE5B,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,wBAAwB,CAAC,CAAC;AAC9E,eAAO,MAAM,wBAAwB,QAAS,OAAO,KAAG,GAAG,IAAI,sBACf,CAAC"}
|
package/dist/decode/reading.d.ts
CHANGED
|
@@ -1,108 +1,87 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
export declare const
|
|
2
|
+
export declare const READING_VERSION_1 = 1;
|
|
3
|
+
export declare const READING_VERSION_2 = 2;
|
|
4
|
+
export declare const DEFAULT_READING_VERSION = 1;
|
|
5
|
+
export declare const ReadingDataTypesSchema: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
3
6
|
export declare const DeviceReadingMetadataV1Schema: z.ZodObject<{
|
|
4
7
|
s: z.ZodNumber;
|
|
5
8
|
us: z.ZodNumber;
|
|
6
|
-
},
|
|
7
|
-
s: number;
|
|
8
|
-
us: number;
|
|
9
|
-
}, {
|
|
10
|
-
s: number;
|
|
11
|
-
us: number;
|
|
12
|
-
}>;
|
|
9
|
+
}, z.core.$strip>;
|
|
13
10
|
export type DeviceReadingMetadataV1 = z.infer<typeof DeviceReadingMetadataV1Schema>;
|
|
14
11
|
export declare const isDeviceReadingMetadataV1: (item: unknown) => item is DeviceReadingMetadataV1;
|
|
15
12
|
export declare const DeviceReadingV1Schema: z.ZodObject<{
|
|
16
13
|
m: z.ZodObject<{
|
|
17
14
|
s: z.ZodNumber;
|
|
18
15
|
us: z.ZodNumber;
|
|
19
|
-
},
|
|
20
|
-
s: number;
|
|
21
|
-
us: number;
|
|
22
|
-
}, {
|
|
23
|
-
s: number;
|
|
24
|
-
us: number;
|
|
25
|
-
}>;
|
|
16
|
+
}, z.core.$strip>;
|
|
26
17
|
s: z.ZodOptional<z.ZodNumber>;
|
|
27
|
-
},
|
|
28
|
-
m: {
|
|
29
|
-
s: number;
|
|
30
|
-
us: number;
|
|
31
|
-
};
|
|
32
|
-
s?: number | undefined;
|
|
33
|
-
}, {
|
|
34
|
-
m: {
|
|
35
|
-
s: number;
|
|
36
|
-
us: number;
|
|
37
|
-
};
|
|
38
|
-
s?: number | undefined;
|
|
39
|
-
}>;
|
|
18
|
+
}, z.core.$strip>;
|
|
40
19
|
export type DeviceReadingV1 = z.infer<typeof DeviceReadingV1Schema>;
|
|
41
20
|
export declare const isDeviceReadingV1: (item: unknown) => item is DeviceReadingV1;
|
|
42
21
|
export declare const DeviceReadingSchemas: z.ZodObject<{
|
|
43
22
|
m: z.ZodObject<{
|
|
44
23
|
s: z.ZodNumber;
|
|
45
24
|
us: z.ZodNumber;
|
|
46
|
-
},
|
|
47
|
-
s: number;
|
|
48
|
-
us: number;
|
|
49
|
-
}, {
|
|
50
|
-
s: number;
|
|
51
|
-
us: number;
|
|
52
|
-
}>;
|
|
25
|
+
}, z.core.$strip>;
|
|
53
26
|
s: z.ZodOptional<z.ZodNumber>;
|
|
54
|
-
},
|
|
55
|
-
m: {
|
|
56
|
-
s: number;
|
|
57
|
-
us: number;
|
|
58
|
-
};
|
|
59
|
-
s?: number | undefined;
|
|
60
|
-
}, {
|
|
61
|
-
m: {
|
|
62
|
-
s: number;
|
|
63
|
-
us: number;
|
|
64
|
-
};
|
|
65
|
-
s?: number | undefined;
|
|
66
|
-
}>;
|
|
27
|
+
}, z.core.$strip>;
|
|
67
28
|
export type DeviceReadingTypes = z.infer<typeof DeviceReadingSchemas>;
|
|
68
29
|
export declare const isDeviceReadingTypes: (item: unknown) => item is DeviceReadingTypes;
|
|
69
30
|
export declare const ReadingMetadataV1Schema: z.ZodObject<{
|
|
70
31
|
s: z.ZodNumber;
|
|
71
32
|
us: z.ZodNumber;
|
|
72
|
-
},
|
|
73
|
-
s: number;
|
|
74
|
-
us: number;
|
|
75
|
-
}, {
|
|
76
|
-
s: number;
|
|
77
|
-
us: number;
|
|
78
|
-
}>;
|
|
33
|
+
}, z.core.$strip>;
|
|
79
34
|
export type ReadingMetadataV1 = z.infer<typeof ReadingMetadataV1Schema>;
|
|
80
35
|
export declare const isReadingMetadataV1: (item: unknown) => item is ReadingMetadataV1;
|
|
81
|
-
export declare const
|
|
82
|
-
|
|
36
|
+
export declare const ReadingV2MetadataSchema: z.ZodObject<{
|
|
37
|
+
v: z.ZodLiteral<2>;
|
|
38
|
+
tm: z.ZodNumber;
|
|
39
|
+
bo: z.ZodOptional<z.ZodBoolean>;
|
|
40
|
+
so: z.ZodOptional<z.ZodBoolean>;
|
|
41
|
+
}, z.core.$strip>;
|
|
42
|
+
export type ReadingV2Metadata = z.infer<typeof ReadingV2MetadataSchema>;
|
|
43
|
+
export declare const isReadingV2Metadata: (item: unknown) => item is ReadingV2Metadata;
|
|
44
|
+
export declare const ReadingSchema: z.ZodObject<{
|
|
45
|
+
v: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
|
|
46
|
+
id: z.ZodString;
|
|
83
47
|
component: z.ZodOptional<z.ZodString>;
|
|
84
|
-
|
|
48
|
+
type: z.ZodString;
|
|
85
49
|
s: z.ZodNumber;
|
|
86
50
|
us: z.ZodOptional<z.ZodNumber>;
|
|
87
|
-
|
|
51
|
+
data: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
52
|
+
bo: z.ZodOptional<z.ZodBoolean>;
|
|
53
|
+
so: z.ZodOptional<z.ZodBoolean>;
|
|
54
|
+
}, z.core.$loose>;
|
|
55
|
+
export type Reading = z.infer<typeof ReadingSchema>;
|
|
56
|
+
export declare const isReading: (item: unknown) => item is Reading;
|
|
57
|
+
export declare const isReadingV1: (item: unknown) => item is Reading & {
|
|
58
|
+
v: typeof READING_VERSION_1;
|
|
59
|
+
};
|
|
60
|
+
export declare const isReadingV2: (item: unknown) => item is Reading & {
|
|
61
|
+
v: typeof READING_VERSION_2;
|
|
62
|
+
};
|
|
63
|
+
export declare const ReadingV1Schema: z.ZodObject<{
|
|
64
|
+
v: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
|
|
88
65
|
id: z.ZodString;
|
|
89
|
-
}>, "passthrough", z.ZodTypeAny, z.objectOutputType<z.objectUtil.extendShape<{
|
|
90
|
-
data: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>]>;
|
|
91
66
|
component: z.ZodOptional<z.ZodString>;
|
|
92
|
-
|
|
67
|
+
type: z.ZodString;
|
|
93
68
|
s: z.ZodNumber;
|
|
94
69
|
us: z.ZodOptional<z.ZodNumber>;
|
|
95
|
-
|
|
70
|
+
data: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
71
|
+
bo: z.ZodOptional<z.ZodBoolean>;
|
|
72
|
+
so: z.ZodOptional<z.ZodBoolean>;
|
|
73
|
+
}, z.core.$loose>;
|
|
74
|
+
export type ReadingV1 = Reading;
|
|
75
|
+
export declare const ReadingV2Schema: z.ZodObject<{
|
|
76
|
+
v: z.ZodDefault<z.ZodUnion<readonly [z.ZodLiteral<1>, z.ZodLiteral<2>]>>;
|
|
96
77
|
id: z.ZodString;
|
|
97
|
-
}>, z.ZodTypeAny, "passthrough">, z.objectInputType<z.objectUtil.extendShape<{
|
|
98
|
-
data: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>]>;
|
|
99
78
|
component: z.ZodOptional<z.ZodString>;
|
|
100
|
-
|
|
79
|
+
type: z.ZodString;
|
|
101
80
|
s: z.ZodNumber;
|
|
102
81
|
us: z.ZodOptional<z.ZodNumber>;
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
export
|
|
82
|
+
data: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
83
|
+
bo: z.ZodOptional<z.ZodBoolean>;
|
|
84
|
+
so: z.ZodOptional<z.ZodBoolean>;
|
|
85
|
+
}, z.core.$loose>;
|
|
86
|
+
export type ReadingV2 = Reading;
|
|
108
87
|
//# sourceMappingURL=reading.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"reading.d.ts","sourceRoot":"","sources":["../../src/decode/reading.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"reading.d.ts","sourceRoot":"","sources":["../../src/decode/reading.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,eAAO,MAAM,iBAAiB,IAAI,CAAC;AACnC,eAAO,MAAM,iBAAiB,IAAI,CAAC;AAEnC,eAAO,MAAM,uBAAuB,IAAoB,CAAC;AAEzD,eAAO,MAAM,sBAAsB,+FAAyB,CAAC;AAE7D,eAAO,MAAM,6BAA6B;;;iBAGxC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AACF,eAAO,MAAM,yBAAyB,SAC9B,OAAO,KACZ,IAAI,IAAI,uBAC4C,CAAC;AAExD,eAAO,MAAM,qBAAqB;;;;;;iBAGhC,CAAC;AACH,MAAM,MAAM,eAAe,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC;AACpE,eAAO,MAAM,iBAAiB,SAAU,OAAO,KAAG,IAAI,IAAI,eACX,CAAC;AAEhD,eAAO,MAAM,oBAAoB;;;;;;iBAAwB,CAAC;AAC1D,MAAM,MAAM,kBAAkB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,oBAAoB,CAAC,CAAC;AACtE,eAAO,MAAM,oBAAoB,SACzB,OAAO,KACZ,IAAI,IAAI,kBAAkE,CAAC;AAE9E,eAAO,MAAM,uBAAuB;;;iBAAgC,CAAC;AACrE,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,eAAO,MAAM,mBAAmB,SAAU,OAAO,KAAG,IAAI,IAAI,iBACX,CAAC;AAElD,eAAO,MAAM,uBAAuB;;;;;iBAKlC,CAAC;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,uBAAuB,CAAC,CAAC;AACxE,eAAO,MAAM,mBAAmB,SACxB,OAAO,KACZ,IAAI,IAAI,iBACsC,CAAC;AAElD,eAAO,MAAM,aAAa;;;;;;;;;;iBAYxB,CAAC;AACH,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,eAAO,MAAM,SAAS,SAAU,OAAO,KAAG,IAAI,IAAI,OACX,CAAC;AAExC,eAAO,MAAM,WAAW,SAChB,OAAO,KACZ,IAAI,IAAI,OAAO,GAAG;IAAE,CAAC,EAAE,OAAO,iBAAiB,CAAA;CAGjD,CAAC;AAEF,eAAO,MAAM,WAAW,SAChB,OAAO,KACZ,IAAI,IAAI,OAAO,GAAG;IAAE,CAAC,EAAE,OAAO,iBAAiB,CAAA;CAGjD,CAAC;AAEF,eAAO,MAAM,eAAe;;;;;;;;;;iBAAgB,CAAC;AAC7C,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC;AAChC,eAAO,MAAM,eAAe;;;;;;;;;;iBAAgB,CAAC;AAC7C,MAAM,MAAM,SAAS,GAAG,OAAO,CAAC"}
|
package/dist/decode/reading.js
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.ReadingV2Schema = exports.ReadingV1Schema = exports.isReadingV2 = exports.isReadingV1 = exports.isReading = exports.ReadingSchema = exports.isReadingV2Metadata = exports.ReadingV2MetadataSchema = exports.isReadingMetadataV1 = exports.ReadingMetadataV1Schema = exports.isDeviceReadingTypes = exports.DeviceReadingSchemas = exports.isDeviceReadingV1 = exports.DeviceReadingV1Schema = exports.isDeviceReadingMetadataV1 = exports.DeviceReadingMetadataV1Schema = exports.ReadingDataTypesSchema = exports.DEFAULT_READING_VERSION = exports.READING_VERSION_2 = exports.READING_VERSION_1 = void 0;
|
|
4
4
|
const zod_1 = require("zod");
|
|
5
5
|
const kit_schema_1 = require("@xube/kit-schema");
|
|
6
|
+
const constants_1 = require("../constants");
|
|
7
|
+
exports.READING_VERSION_1 = 1;
|
|
8
|
+
exports.READING_VERSION_2 = 2;
|
|
9
|
+
exports.DEFAULT_READING_VERSION = exports.READING_VERSION_1;
|
|
6
10
|
exports.ReadingDataTypesSchema = kit_schema_1.GenericDataTypesSchema;
|
|
7
11
|
exports.DeviceReadingMetadataV1Schema = zod_1.z.object({
|
|
8
12
|
s: zod_1.z.number(), //Seconds,
|
|
@@ -22,12 +26,38 @@ exports.isDeviceReadingTypes = isDeviceReadingTypes;
|
|
|
22
26
|
exports.ReadingMetadataV1Schema = exports.DeviceReadingMetadataV1Schema;
|
|
23
27
|
const isReadingMetadataV1 = (item) => exports.ReadingMetadataV1Schema.safeParse(item).success;
|
|
24
28
|
exports.isReadingMetadataV1 = isReadingMetadataV1;
|
|
25
|
-
exports.
|
|
26
|
-
.
|
|
27
|
-
|
|
29
|
+
exports.ReadingV2MetadataSchema = zod_1.z.object({
|
|
30
|
+
[constants_1.READING_VERSION_IDENTIFIER]: zod_1.z.literal(exports.READING_VERSION_2),
|
|
31
|
+
tm: zod_1.z.number().refine((tm) => tm > 0, { message: "tm must be positive" }),
|
|
32
|
+
bo: zod_1.z.boolean().optional(),
|
|
33
|
+
so: zod_1.z.boolean().optional(),
|
|
34
|
+
});
|
|
35
|
+
const isReadingV2Metadata = (item) => exports.ReadingV2MetadataSchema.safeParse(item).success;
|
|
36
|
+
exports.isReadingV2Metadata = isReadingV2Metadata;
|
|
37
|
+
exports.ReadingSchema = zod_1.z.looseObject({
|
|
38
|
+
[constants_1.READING_VERSION_IDENTIFIER]: zod_1.z
|
|
39
|
+
.union([zod_1.z.literal(exports.READING_VERSION_1), zod_1.z.literal(exports.READING_VERSION_2)])
|
|
40
|
+
.default(exports.DEFAULT_READING_VERSION),
|
|
41
|
+
id: zod_1.z.string(),
|
|
28
42
|
component: zod_1.z.string().optional(),
|
|
29
|
-
|
|
30
|
-
.
|
|
31
|
-
.
|
|
32
|
-
|
|
43
|
+
type: zod_1.z.string(),
|
|
44
|
+
s: zod_1.z.number(),
|
|
45
|
+
us: zod_1.z.number().optional(),
|
|
46
|
+
data: exports.ReadingDataTypesSchema,
|
|
47
|
+
bo: zod_1.z.boolean().optional(),
|
|
48
|
+
so: zod_1.z.boolean().optional(),
|
|
49
|
+
});
|
|
50
|
+
const isReading = (item) => exports.ReadingSchema.safeParse(item).success;
|
|
51
|
+
exports.isReading = isReading;
|
|
52
|
+
const isReadingV1 = (item) => {
|
|
53
|
+
const result = exports.ReadingSchema.safeParse(item);
|
|
54
|
+
return result.success && result.data.v === exports.READING_VERSION_1;
|
|
55
|
+
};
|
|
33
56
|
exports.isReadingV1 = isReadingV1;
|
|
57
|
+
const isReadingV2 = (item) => {
|
|
58
|
+
const result = exports.ReadingSchema.safeParse(item);
|
|
59
|
+
return result.success && result.data.v === exports.READING_VERSION_2;
|
|
60
|
+
};
|
|
61
|
+
exports.isReadingV2 = isReadingV2;
|
|
62
|
+
exports.ReadingV1Schema = exports.ReadingSchema;
|
|
63
|
+
exports.ReadingV2Schema = exports.ReadingSchema;
|
|
@@ -2,58 +2,20 @@ import { z } from "zod";
|
|
|
2
2
|
export declare const GetDataByDateRangeRequestSchema: z.ZodObject<{
|
|
3
3
|
devices: z.ZodArray<z.ZodObject<{
|
|
4
4
|
id: z.ZodString;
|
|
5
|
-
components: z.ZodArray<z.ZodString
|
|
6
|
-
},
|
|
7
|
-
id: string;
|
|
8
|
-
components: string[];
|
|
9
|
-
}, {
|
|
10
|
-
id: string;
|
|
11
|
-
components: string[];
|
|
12
|
-
}>, "many">;
|
|
5
|
+
components: z.ZodArray<z.ZodString>;
|
|
6
|
+
}, z.core.$strip>>;
|
|
13
7
|
dateRange: z.ZodObject<{
|
|
14
8
|
start: z.ZodString;
|
|
15
9
|
end: z.ZodString;
|
|
16
|
-
},
|
|
17
|
-
|
|
18
|
-
end: string;
|
|
19
|
-
}, {
|
|
20
|
-
start: string;
|
|
21
|
-
end: string;
|
|
22
|
-
}>;
|
|
23
|
-
}, "strip", z.ZodTypeAny, {
|
|
24
|
-
devices: {
|
|
25
|
-
id: string;
|
|
26
|
-
components: string[];
|
|
27
|
-
}[];
|
|
28
|
-
dateRange: {
|
|
29
|
-
start: string;
|
|
30
|
-
end: string;
|
|
31
|
-
};
|
|
32
|
-
}, {
|
|
33
|
-
devices: {
|
|
34
|
-
id: string;
|
|
35
|
-
components: string[];
|
|
36
|
-
}[];
|
|
37
|
-
dateRange: {
|
|
38
|
-
start: string;
|
|
39
|
-
end: string;
|
|
40
|
-
};
|
|
41
|
-
}>;
|
|
10
|
+
}, z.core.$strip>;
|
|
11
|
+
}, z.core.$strip>;
|
|
42
12
|
export type GetDataByDateRangeRequest = z.infer<typeof GetDataByDateRangeRequestSchema>;
|
|
43
13
|
export declare const isGetDataByDateRangeRequest: (object: unknown) => object is GetDataByDateRangeRequest;
|
|
44
14
|
export declare const ComponentDataEntryResponseSchema: z.ZodObject<{
|
|
45
15
|
seconds: z.ZodNumber;
|
|
46
16
|
microseconds: z.ZodOptional<z.ZodNumber>;
|
|
47
|
-
readings: z.
|
|
48
|
-
},
|
|
49
|
-
seconds: number;
|
|
50
|
-
readings: {};
|
|
51
|
-
microseconds?: number | undefined;
|
|
52
|
-
}, {
|
|
53
|
-
seconds: number;
|
|
54
|
-
readings: {};
|
|
55
|
-
microseconds?: number | undefined;
|
|
56
|
-
}>;
|
|
17
|
+
readings: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
18
|
+
}, z.core.$strip>;
|
|
57
19
|
export type ComponentDataEntryResponse = z.infer<typeof ComponentDataEntryResponseSchema>;
|
|
58
20
|
export declare const DeviceDataEntryResponseSchema: z.ZodObject<{
|
|
59
21
|
id: z.ZodString;
|
|
@@ -62,52 +24,10 @@ export declare const DeviceDataEntryResponseSchema: z.ZodObject<{
|
|
|
62
24
|
data: z.ZodArray<z.ZodObject<{
|
|
63
25
|
seconds: z.ZodNumber;
|
|
64
26
|
microseconds: z.ZodOptional<z.ZodNumber>;
|
|
65
|
-
readings: z.
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
microseconds?: number | undefined;
|
|
70
|
-
}, {
|
|
71
|
-
seconds: number;
|
|
72
|
-
readings: {};
|
|
73
|
-
microseconds?: number | undefined;
|
|
74
|
-
}>, "many">;
|
|
75
|
-
}, "strip", z.ZodTypeAny, {
|
|
76
|
-
data: {
|
|
77
|
-
seconds: number;
|
|
78
|
-
readings: {};
|
|
79
|
-
microseconds?: number | undefined;
|
|
80
|
-
}[];
|
|
81
|
-
id: string;
|
|
82
|
-
}, {
|
|
83
|
-
data: {
|
|
84
|
-
seconds: number;
|
|
85
|
-
readings: {};
|
|
86
|
-
microseconds?: number | undefined;
|
|
87
|
-
}[];
|
|
88
|
-
id: string;
|
|
89
|
-
}>, "many">;
|
|
90
|
-
}, "strip", z.ZodTypeAny, {
|
|
91
|
-
id: string;
|
|
92
|
-
components: {
|
|
93
|
-
data: {
|
|
94
|
-
seconds: number;
|
|
95
|
-
readings: {};
|
|
96
|
-
microseconds?: number | undefined;
|
|
97
|
-
}[];
|
|
98
|
-
id: string;
|
|
99
|
-
}[];
|
|
100
|
-
}, {
|
|
101
|
-
id: string;
|
|
102
|
-
components: {
|
|
103
|
-
data: {
|
|
104
|
-
seconds: number;
|
|
105
|
-
readings: {};
|
|
106
|
-
microseconds?: number | undefined;
|
|
107
|
-
}[];
|
|
108
|
-
id: string;
|
|
109
|
-
}[];
|
|
110
|
-
}>;
|
|
27
|
+
readings: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
28
|
+
}, z.core.$strip>>;
|
|
29
|
+
}, z.core.$strip>>;
|
|
30
|
+
}, z.core.$strip>;
|
|
111
31
|
export type DeviceDataEntryResponse = z.infer<typeof DeviceDataEntryResponseSchema>;
|
|
112
32
|
export declare const GetDataByDateRangeResponseSchema: z.ZodObject<{
|
|
113
33
|
devices: z.ZodArray<z.ZodObject<{
|
|
@@ -117,76 +37,10 @@ export declare const GetDataByDateRangeResponseSchema: z.ZodObject<{
|
|
|
117
37
|
data: z.ZodArray<z.ZodObject<{
|
|
118
38
|
seconds: z.ZodNumber;
|
|
119
39
|
microseconds: z.ZodOptional<z.ZodNumber>;
|
|
120
|
-
readings: z.
|
|
121
|
-
},
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}, {
|
|
126
|
-
seconds: number;
|
|
127
|
-
readings: {};
|
|
128
|
-
microseconds?: number | undefined;
|
|
129
|
-
}>, "many">;
|
|
130
|
-
}, "strip", z.ZodTypeAny, {
|
|
131
|
-
data: {
|
|
132
|
-
seconds: number;
|
|
133
|
-
readings: {};
|
|
134
|
-
microseconds?: number | undefined;
|
|
135
|
-
}[];
|
|
136
|
-
id: string;
|
|
137
|
-
}, {
|
|
138
|
-
data: {
|
|
139
|
-
seconds: number;
|
|
140
|
-
readings: {};
|
|
141
|
-
microseconds?: number | undefined;
|
|
142
|
-
}[];
|
|
143
|
-
id: string;
|
|
144
|
-
}>, "many">;
|
|
145
|
-
}, "strip", z.ZodTypeAny, {
|
|
146
|
-
id: string;
|
|
147
|
-
components: {
|
|
148
|
-
data: {
|
|
149
|
-
seconds: number;
|
|
150
|
-
readings: {};
|
|
151
|
-
microseconds?: number | undefined;
|
|
152
|
-
}[];
|
|
153
|
-
id: string;
|
|
154
|
-
}[];
|
|
155
|
-
}, {
|
|
156
|
-
id: string;
|
|
157
|
-
components: {
|
|
158
|
-
data: {
|
|
159
|
-
seconds: number;
|
|
160
|
-
readings: {};
|
|
161
|
-
microseconds?: number | undefined;
|
|
162
|
-
}[];
|
|
163
|
-
id: string;
|
|
164
|
-
}[];
|
|
165
|
-
}>, "many">;
|
|
166
|
-
}, "strip", z.ZodTypeAny, {
|
|
167
|
-
devices: {
|
|
168
|
-
id: string;
|
|
169
|
-
components: {
|
|
170
|
-
data: {
|
|
171
|
-
seconds: number;
|
|
172
|
-
readings: {};
|
|
173
|
-
microseconds?: number | undefined;
|
|
174
|
-
}[];
|
|
175
|
-
id: string;
|
|
176
|
-
}[];
|
|
177
|
-
}[];
|
|
178
|
-
}, {
|
|
179
|
-
devices: {
|
|
180
|
-
id: string;
|
|
181
|
-
components: {
|
|
182
|
-
data: {
|
|
183
|
-
seconds: number;
|
|
184
|
-
readings: {};
|
|
185
|
-
microseconds?: number | undefined;
|
|
186
|
-
}[];
|
|
187
|
-
id: string;
|
|
188
|
-
}[];
|
|
189
|
-
}[];
|
|
190
|
-
}>;
|
|
40
|
+
readings: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
41
|
+
}, z.core.$strip>>;
|
|
42
|
+
}, z.core.$strip>>;
|
|
43
|
+
}, z.core.$strip>>;
|
|
44
|
+
}, z.core.$strip>;
|
|
191
45
|
export type GetDataByDateRangeResponse = z.infer<typeof GetDataByDateRangeResponseSchema>;
|
|
192
46
|
//# sourceMappingURL=get-data-by-date-range.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-data-by-date-range.d.ts","sourceRoot":"","sources":["../../src/get/get-data-by-date-range.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"get-data-by-date-range.d.ts","sourceRoot":"","sources":["../../src/get/get-data-by-date-range.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAGxB,eAAO,MAAM,+BAA+B;;;;;;;;;iBAY1C,CAAC;AACH,MAAM,MAAM,yBAAyB,GAAG,CAAC,CAAC,KAAK,CAC7C,OAAO,+BAA+B,CACvC,CAAC;AACF,eAAO,MAAM,2BAA2B,WAC9B,OAAO,KACd,MAAM,IAAI,yBAGZ,CAAC;AAEF,eAAO,MAAM,gCAAgC;;;;iBAI3C,CAAC;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,gCAAgC,CACxC,CAAC;AACF,eAAO,MAAM,6BAA6B;;;;;;;;;;iBAQxC,CAAC;AACH,MAAM,MAAM,uBAAuB,GAAG,CAAC,CAAC,KAAK,CAC3C,OAAO,6BAA6B,CACrC,CAAC;AAEF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;iBAE3C,CAAC;AACH,MAAM,MAAM,0BAA0B,GAAG,CAAC,CAAC,KAAK,CAC9C,OAAO,gCAAgC,CACxC,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.GetDataByDateRangeResponseSchema = exports.DeviceDataEntryResponseSchema = exports.ComponentDataEntryResponseSchema = exports.isGetDataByDateRangeRequest = exports.GetDataByDateRangeRequestSchema = void 0;
|
|
4
|
+
const kit_schema_1 = require("@xube/kit-schema");
|
|
4
5
|
const zod_1 = require("zod");
|
|
5
6
|
exports.GetDataByDateRangeRequestSchema = zod_1.z.object({
|
|
6
7
|
devices: zod_1.z.array(zod_1.z.object({
|
|
@@ -21,7 +22,7 @@ exports.isGetDataByDateRangeRequest = isGetDataByDateRangeRequest;
|
|
|
21
22
|
exports.ComponentDataEntryResponseSchema = zod_1.z.object({
|
|
22
23
|
seconds: zod_1.z.number(),
|
|
23
24
|
microseconds: zod_1.z.number().optional(),
|
|
24
|
-
readings:
|
|
25
|
+
readings: kit_schema_1.GenericDataTypesSchema,
|
|
25
26
|
});
|
|
26
27
|
exports.DeviceDataEntryResponseSchema = zod_1.z.object({
|
|
27
28
|
id: zod_1.z.string(),
|
|
@@ -6,21 +6,7 @@ export declare const DataMessageSchema: z.ZodObject<{
|
|
|
6
6
|
component: z.ZodOptional<z.ZodString>;
|
|
7
7
|
request: z.ZodOptional<z.ZodString>;
|
|
8
8
|
timestamp: z.ZodNumber;
|
|
9
|
-
},
|
|
10
|
-
payload: string;
|
|
11
|
-
account: string;
|
|
12
|
-
device: string;
|
|
13
|
-
timestamp: number;
|
|
14
|
-
component?: string | undefined;
|
|
15
|
-
request?: string | undefined;
|
|
16
|
-
}, {
|
|
17
|
-
payload: string;
|
|
18
|
-
account: string;
|
|
19
|
-
device: string;
|
|
20
|
-
timestamp: number;
|
|
21
|
-
component?: string | undefined;
|
|
22
|
-
request?: string | undefined;
|
|
23
|
-
}>;
|
|
9
|
+
}, z.core.$strip>;
|
|
24
10
|
export type DataMessage = z.infer<typeof DataMessageSchema>;
|
|
25
11
|
export declare const isDataMessage: (item: unknown) => item is DataMessage;
|
|
26
12
|
//# sourceMappingURL=message.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/message/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../../src/message/message.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB,eAAO,MAAM,iBAAiB;;;;;;;iBAO5B,CAAC;AACH,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,iBAAiB,CAAC,CAAC;AAC5D,eAAO,MAAM,aAAa,SAAU,OAAO,KAAG,IAAI,IAAI,WACX,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@xube/kit-aws-data-schema",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.13",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -18,15 +18,15 @@
|
|
|
18
18
|
},
|
|
19
19
|
"homepage": "https://github.com/XubeLtd/dev-kit#readme",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@xube/kit-build": "^0.2.
|
|
21
|
+
"@xube/kit-build": "^0.2.13"
|
|
22
22
|
},
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@xube/kit-aws-schema": "^0.2.
|
|
25
|
-
"@xube/kit-constants": "^0.2.
|
|
26
|
-
"@xube/kit-generator": "^0.2.
|
|
27
|
-
"@xube/kit-log": "^0.2.
|
|
28
|
-
"@xube/kit-schema": "^0.2.
|
|
29
|
-
"zod": "^
|
|
30
|
-
"zod-validation-error": "^
|
|
24
|
+
"@xube/kit-aws-schema": "^0.2.13",
|
|
25
|
+
"@xube/kit-constants": "^0.2.13",
|
|
26
|
+
"@xube/kit-generator": "^0.2.13",
|
|
27
|
+
"@xube/kit-log": "^0.2.13",
|
|
28
|
+
"@xube/kit-schema": "^0.2.13",
|
|
29
|
+
"zod": "^4.4.3",
|
|
30
|
+
"zod-validation-error": "^5.0.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/constants.ts
CHANGED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DEFAULT_READING_VERSION,
|
|
3
|
+
READING_VERSION_1,
|
|
4
|
+
READING_VERSION_2,
|
|
5
|
+
Reading,
|
|
6
|
+
ReadingSchema,
|
|
7
|
+
ReadingV2Metadata,
|
|
8
|
+
ReadingV2MetadataSchema,
|
|
9
|
+
isReading,
|
|
10
|
+
isReadingV1,
|
|
11
|
+
isReadingV2,
|
|
12
|
+
isReadingV2Metadata,
|
|
13
|
+
} from "./reading";
|
|
14
|
+
|
|
15
|
+
const baseV1 = {
|
|
16
|
+
v: READING_VERSION_1,
|
|
17
|
+
id: "dev1",
|
|
18
|
+
component: "componentA",
|
|
19
|
+
type: "data",
|
|
20
|
+
s: 1697578841,
|
|
21
|
+
us: 214981,
|
|
22
|
+
data: "S,+000.30,+001.74,M,00,33",
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const baseV2 = {
|
|
26
|
+
v: READING_VERSION_2,
|
|
27
|
+
id: "dev1",
|
|
28
|
+
component: "componentA",
|
|
29
|
+
type: "data",
|
|
30
|
+
s: 1780859506,
|
|
31
|
+
us: 366000,
|
|
32
|
+
data: "AQIDBA==",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
describe("ReadingSchema (unified storage shape)", () => {
|
|
36
|
+
describe("v1 rows", () => {
|
|
37
|
+
it("parses a v1 row with neither bo nor so", () => {
|
|
38
|
+
const parsed = ReadingSchema.parse(baseV1) as Reading;
|
|
39
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
40
|
+
expect(parsed.s).toBe(baseV1.s);
|
|
41
|
+
expect(parsed.us).toBe(baseV1.us);
|
|
42
|
+
expect(parsed.bo).toBeUndefined();
|
|
43
|
+
expect(parsed.so).toBeUndefined();
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("parses a v1 row with only bo", () => {
|
|
47
|
+
const parsed = ReadingSchema.parse({ ...baseV1, bo: true }) as Reading;
|
|
48
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
49
|
+
expect(parsed.bo).toBe(true);
|
|
50
|
+
expect(parsed.so).toBeUndefined();
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("parses a v1 row with only so", () => {
|
|
54
|
+
const parsed = ReadingSchema.parse({ ...baseV1, so: false }) as Reading;
|
|
55
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
56
|
+
expect(parsed.bo).toBeUndefined();
|
|
57
|
+
expect(parsed.so).toBe(false);
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
it("parses a v1 row with both bo and so", () => {
|
|
61
|
+
const parsed = ReadingSchema.parse({
|
|
62
|
+
...baseV1,
|
|
63
|
+
bo: false,
|
|
64
|
+
so: true,
|
|
65
|
+
}) as Reading;
|
|
66
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
67
|
+
expect(parsed.bo).toBe(false);
|
|
68
|
+
expect(parsed.so).toBe(true);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
describe("v2 rows", () => {
|
|
73
|
+
it("parses a v2 row with neither bo nor so", () => {
|
|
74
|
+
const parsed = ReadingSchema.parse(baseV2) as Reading;
|
|
75
|
+
expect(parsed.v).toBe(READING_VERSION_2);
|
|
76
|
+
expect(parsed.s).toBe(baseV2.s);
|
|
77
|
+
expect(parsed.us).toBe(baseV2.us);
|
|
78
|
+
expect(parsed.bo).toBeUndefined();
|
|
79
|
+
expect(parsed.so).toBeUndefined();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("parses a v2 row with only bo", () => {
|
|
83
|
+
const parsed = ReadingSchema.parse({ ...baseV2, bo: true }) as Reading;
|
|
84
|
+
expect(parsed.v).toBe(READING_VERSION_2);
|
|
85
|
+
expect(parsed.bo).toBe(true);
|
|
86
|
+
expect(parsed.so).toBeUndefined();
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("parses a v2 row with only so", () => {
|
|
90
|
+
const parsed = ReadingSchema.parse({ ...baseV2, so: false }) as Reading;
|
|
91
|
+
expect(parsed.v).toBe(READING_VERSION_2);
|
|
92
|
+
expect(parsed.bo).toBeUndefined();
|
|
93
|
+
expect(parsed.so).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("parses a v2 row with both bo and so", () => {
|
|
97
|
+
const parsed = ReadingSchema.parse({
|
|
98
|
+
...baseV2,
|
|
99
|
+
bo: false,
|
|
100
|
+
so: true,
|
|
101
|
+
}) as Reading;
|
|
102
|
+
expect(parsed.v).toBe(READING_VERSION_2);
|
|
103
|
+
expect(parsed.bo).toBe(false);
|
|
104
|
+
expect(parsed.so).toBe(true);
|
|
105
|
+
});
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
describe("legacy + default behaviour", () => {
|
|
109
|
+
it("parses a legacy row (no v field) and defaults to v1", () => {
|
|
110
|
+
const { v: _omit, ...legacy } = baseV1;
|
|
111
|
+
const parsed = ReadingSchema.parse(legacy) as Reading;
|
|
112
|
+
expect(parsed.v).toBe(DEFAULT_READING_VERSION);
|
|
113
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
it("preserves passthrough fields (looseObject)", () => {
|
|
117
|
+
const parsed = ReadingSchema.parse({
|
|
118
|
+
...baseV1,
|
|
119
|
+
extra: "passthrough",
|
|
120
|
+
}) as Reading & { extra: string };
|
|
121
|
+
expect(parsed.extra).toBe("passthrough");
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("rejects an unknown v value", () => {
|
|
125
|
+
expect(ReadingSchema.safeParse({ ...baseV1, v: 99 }).success).toBe(false);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("rejects a row missing required core fields", () => {
|
|
129
|
+
const { id: _id, ...withoutId } = baseV1;
|
|
130
|
+
expect(ReadingSchema.safeParse(withoutId).success).toBe(false);
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
it.each([
|
|
134
|
+
["null", null],
|
|
135
|
+
["undefined", undefined],
|
|
136
|
+
["string", "not-an-object"],
|
|
137
|
+
["number", 42],
|
|
138
|
+
["boolean", true],
|
|
139
|
+
["array", [1, 2, 3]],
|
|
140
|
+
])("rejects %s input without crashing", (_label, input) => {
|
|
141
|
+
expect(ReadingSchema.safeParse(input).success).toBe(false);
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
describe("type-narrowing predicates", () => {
|
|
147
|
+
const v1Both = { ...baseV1, bo: true, so: true };
|
|
148
|
+
const v2Both = { ...baseV2, bo: true, so: true };
|
|
149
|
+
|
|
150
|
+
it("isReading accepts any valid reading", () => {
|
|
151
|
+
expect(isReading(baseV1)).toBe(true);
|
|
152
|
+
expect(isReading(v1Both)).toBe(true);
|
|
153
|
+
expect(isReading(baseV2)).toBe(true);
|
|
154
|
+
expect(isReading(v2Both)).toBe(true);
|
|
155
|
+
expect(isReading({ foo: "bar" })).toBe(false);
|
|
156
|
+
expect(isReading(null)).toBe(false);
|
|
157
|
+
});
|
|
158
|
+
|
|
159
|
+
it("isReadingV1 narrows to v=1 only", () => {
|
|
160
|
+
expect(isReadingV1(baseV1)).toBe(true);
|
|
161
|
+
expect(isReadingV1(v1Both)).toBe(true);
|
|
162
|
+
expect(isReadingV1(baseV2)).toBe(false);
|
|
163
|
+
expect(isReadingV1(v2Both)).toBe(false);
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
it("isReadingV2 narrows to v=2 only", () => {
|
|
167
|
+
expect(isReadingV2(baseV2)).toBe(true);
|
|
168
|
+
expect(isReadingV2(v2Both)).toBe(true);
|
|
169
|
+
expect(isReadingV2(baseV1)).toBe(false);
|
|
170
|
+
expect(isReadingV2(v1Both)).toBe(false);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("ReadingV2MetadataSchema (wire-format header)", () => {
|
|
175
|
+
const minimal: ReadingV2Metadata = {
|
|
176
|
+
v: READING_VERSION_2,
|
|
177
|
+
tm: 1780859506366,
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
it("accepts minimal v2 metadata (no bo, no so)", () => {
|
|
181
|
+
expect(ReadingV2MetadataSchema.safeParse(minimal).success).toBe(true);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("accepts v2 metadata with only bo", () => {
|
|
185
|
+
expect(
|
|
186
|
+
ReadingV2MetadataSchema.safeParse({ ...minimal, bo: true }).success,
|
|
187
|
+
).toBe(true);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("accepts v2 metadata with only so", () => {
|
|
191
|
+
expect(
|
|
192
|
+
ReadingV2MetadataSchema.safeParse({ ...minimal, so: false }).success,
|
|
193
|
+
).toBe(true);
|
|
194
|
+
});
|
|
195
|
+
|
|
196
|
+
it("accepts v2 metadata with both bo and so", () => {
|
|
197
|
+
expect(
|
|
198
|
+
ReadingV2MetadataSchema.safeParse({
|
|
199
|
+
...minimal,
|
|
200
|
+
bo: false,
|
|
201
|
+
so: true,
|
|
202
|
+
}).success,
|
|
203
|
+
).toBe(true);
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
it("rejects v2 metadata with tm = 0 or negative", () => {
|
|
207
|
+
expect(ReadingV2MetadataSchema.safeParse({ ...minimal, tm: 0 }).success).toBe(
|
|
208
|
+
false,
|
|
209
|
+
);
|
|
210
|
+
expect(
|
|
211
|
+
ReadingV2MetadataSchema.safeParse({ ...minimal, tm: -1 }).success,
|
|
212
|
+
).toBe(false);
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
it("rejects v2 metadata missing tm", () => {
|
|
216
|
+
const { tm: _tm, ...noTm } = minimal;
|
|
217
|
+
expect(ReadingV2MetadataSchema.safeParse(noTm).success).toBe(false);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
it("isReadingV2Metadata matches the schema", () => {
|
|
221
|
+
expect(isReadingV2Metadata(minimal)).toBe(true);
|
|
222
|
+
expect(isReadingV2Metadata({ ...minimal, bo: true, so: false })).toBe(true);
|
|
223
|
+
expect(isReadingV2Metadata({ v: 1, tm: 1 })).toBe(false);
|
|
224
|
+
});
|
|
225
|
+
});
|
|
226
|
+
|
|
227
|
+
describe("DEFAULT_READING_VERSION", () => {
|
|
228
|
+
it("currently equals READING_VERSION_1", () => {
|
|
229
|
+
expect(DEFAULT_READING_VERSION).toBe(READING_VERSION_1);
|
|
230
|
+
});
|
|
231
|
+
});
|
package/src/decode/reading.ts
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
2
|
+
import { GenericDataTypesSchema } from "@xube/kit-schema";
|
|
3
|
+
import { READING_VERSION_IDENTIFIER } from "../constants";
|
|
4
|
+
|
|
5
|
+
export const READING_VERSION_1 = 1;
|
|
6
|
+
export const READING_VERSION_2 = 2;
|
|
7
|
+
|
|
8
|
+
export const DEFAULT_READING_VERSION = READING_VERSION_1;
|
|
3
9
|
|
|
4
10
|
export const ReadingDataTypesSchema = GenericDataTypesSchema;
|
|
5
11
|
|
|
@@ -7,8 +13,12 @@ export const DeviceReadingMetadataV1Schema = z.object({
|
|
|
7
13
|
s: z.number(), //Seconds,
|
|
8
14
|
us: z.number(), //Microseconds
|
|
9
15
|
});
|
|
10
|
-
export type DeviceReadingMetadataV1 = z.infer<
|
|
11
|
-
|
|
16
|
+
export type DeviceReadingMetadataV1 = z.infer<
|
|
17
|
+
typeof DeviceReadingMetadataV1Schema
|
|
18
|
+
>;
|
|
19
|
+
export const isDeviceReadingMetadataV1 = (
|
|
20
|
+
item: unknown,
|
|
21
|
+
): item is DeviceReadingMetadataV1 =>
|
|
12
22
|
DeviceReadingMetadataV1Schema.safeParse(item).success;
|
|
13
23
|
|
|
14
24
|
export const DeviceReadingV1Schema = z.object({
|
|
@@ -21,21 +31,59 @@ export const isDeviceReadingV1 = (item: unknown): item is DeviceReadingV1 =>
|
|
|
21
31
|
|
|
22
32
|
export const DeviceReadingSchemas = DeviceReadingV1Schema;
|
|
23
33
|
export type DeviceReadingTypes = z.infer<typeof DeviceReadingSchemas>;
|
|
24
|
-
export const isDeviceReadingTypes = (
|
|
25
|
-
|
|
34
|
+
export const isDeviceReadingTypes = (
|
|
35
|
+
item: unknown,
|
|
36
|
+
): item is DeviceReadingTypes => DeviceReadingSchemas.safeParse(item).success;
|
|
26
37
|
|
|
27
38
|
export const ReadingMetadataV1Schema = DeviceReadingMetadataV1Schema;
|
|
28
39
|
export type ReadingMetadataV1 = z.infer<typeof ReadingMetadataV1Schema>;
|
|
29
40
|
export const isReadingMetadataV1 = (item: unknown): item is ReadingMetadataV1 =>
|
|
30
41
|
ReadingMetadataV1Schema.safeParse(item).success;
|
|
31
42
|
|
|
32
|
-
export const
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
export
|
|
40
|
-
|
|
41
|
-
|
|
43
|
+
export const ReadingV2MetadataSchema = z.object({
|
|
44
|
+
[READING_VERSION_IDENTIFIER]: z.literal(READING_VERSION_2),
|
|
45
|
+
tm: z.number().refine((tm) => tm > 0, { message: "tm must be positive" }),
|
|
46
|
+
bo: z.boolean().optional(),
|
|
47
|
+
so: z.boolean().optional(),
|
|
48
|
+
});
|
|
49
|
+
export type ReadingV2Metadata = z.infer<typeof ReadingV2MetadataSchema>;
|
|
50
|
+
export const isReadingV2Metadata = (
|
|
51
|
+
item: unknown,
|
|
52
|
+
): item is ReadingV2Metadata =>
|
|
53
|
+
ReadingV2MetadataSchema.safeParse(item).success;
|
|
54
|
+
|
|
55
|
+
export const ReadingSchema = z.looseObject({
|
|
56
|
+
[READING_VERSION_IDENTIFIER]: z
|
|
57
|
+
.union([z.literal(READING_VERSION_1), z.literal(READING_VERSION_2)])
|
|
58
|
+
.default(DEFAULT_READING_VERSION),
|
|
59
|
+
id: z.string(),
|
|
60
|
+
component: z.string().optional(),
|
|
61
|
+
type: z.string(),
|
|
62
|
+
s: z.number(),
|
|
63
|
+
us: z.number().optional(),
|
|
64
|
+
data: ReadingDataTypesSchema,
|
|
65
|
+
bo: z.boolean().optional(),
|
|
66
|
+
so: z.boolean().optional(),
|
|
67
|
+
});
|
|
68
|
+
export type Reading = z.infer<typeof ReadingSchema>;
|
|
69
|
+
export const isReading = (item: unknown): item is Reading =>
|
|
70
|
+
ReadingSchema.safeParse(item).success;
|
|
71
|
+
|
|
72
|
+
export const isReadingV1 = (
|
|
73
|
+
item: unknown,
|
|
74
|
+
): item is Reading & { v: typeof READING_VERSION_1 } => {
|
|
75
|
+
const result = ReadingSchema.safeParse(item);
|
|
76
|
+
return result.success && result.data.v === READING_VERSION_1;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
export const isReadingV2 = (
|
|
80
|
+
item: unknown,
|
|
81
|
+
): item is Reading & { v: typeof READING_VERSION_2 } => {
|
|
82
|
+
const result = ReadingSchema.safeParse(item);
|
|
83
|
+
return result.success && result.data.v === READING_VERSION_2;
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const ReadingV1Schema = ReadingSchema;
|
|
87
|
+
export type ReadingV1 = Reading;
|
|
88
|
+
export const ReadingV2Schema = ReadingSchema;
|
|
89
|
+
export type ReadingV2 = Reading;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { XubeLog } from "@xube/kit-log";
|
|
2
|
+
import { GenericDataTypesSchema } from "@xube/kit-schema";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { fromZodError } from "zod-validation-error";
|
|
4
5
|
|
|
@@ -28,7 +29,7 @@ export const isGetDataByDateRangeRequest = (
|
|
|
28
29
|
export const ComponentDataEntryResponseSchema = z.object({
|
|
29
30
|
seconds: z.number(),
|
|
30
31
|
microseconds: z.number().optional(),
|
|
31
|
-
readings:
|
|
32
|
+
readings: GenericDataTypesSchema,
|
|
32
33
|
});
|
|
33
34
|
export type ComponentDataEntryResponse = z.infer<
|
|
34
35
|
typeof ComponentDataEntryResponseSchema
|