@xube/kit-aws-data-schema 0.2.8 → 0.2.12
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 -73
- package/dist/decode/reading.d.ts.map +1 -1
- package/dist/decode/reading.js +51 -7
- 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 +181 -0
- package/src/decode/reading.ts +78 -12
- 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,85 @@
|
|
|
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 ReadingV1Schema: z.ZodObject<
|
|
82
|
-
|
|
83
|
-
component: z.ZodOptional<z.ZodString>;
|
|
84
|
-
}, {
|
|
36
|
+
export declare const ReadingV1Schema: z.ZodObject<{
|
|
37
|
+
type: z.ZodString;
|
|
85
38
|
s: z.ZodNumber;
|
|
86
39
|
us: z.ZodOptional<z.ZodNumber>;
|
|
87
|
-
|
|
40
|
+
data: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
88
41
|
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
42
|
component: z.ZodOptional<z.ZodString>;
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
43
|
+
v: z.ZodDefault<z.ZodLiteral<1>>;
|
|
44
|
+
}, z.core.$loose>;
|
|
45
|
+
export type ReadingV1 = z.infer<typeof ReadingV1Schema>;
|
|
46
|
+
export declare const isReadingV1: (item: unknown) => item is ReadingV1;
|
|
47
|
+
export declare const ReadingV2MetadataSchema: z.ZodObject<{
|
|
48
|
+
v: z.ZodLiteral<2>;
|
|
49
|
+
tm: z.ZodNumber;
|
|
50
|
+
bo: z.ZodOptional<z.ZodBoolean>;
|
|
51
|
+
so: z.ZodOptional<z.ZodBoolean>;
|
|
52
|
+
}, z.core.$strip>;
|
|
53
|
+
export type ReadingV2Metadata = z.infer<typeof ReadingV2MetadataSchema>;
|
|
54
|
+
export declare const isReadingV2Metadata: (item: unknown) => item is ReadingV2Metadata;
|
|
55
|
+
export declare const ReadingV2Schema: z.ZodObject<{
|
|
56
|
+
data: z.ZodUnion<readonly [z.ZodCustom<Uint8Array, Uint8Array>, z.ZodString]>;
|
|
96
57
|
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
58
|
component: z.ZodOptional<z.ZodString>;
|
|
100
|
-
|
|
59
|
+
v: z.ZodLiteral<2>;
|
|
60
|
+
tm: z.ZodNumber;
|
|
61
|
+
bo: z.ZodOptional<z.ZodBoolean>;
|
|
62
|
+
so: z.ZodOptional<z.ZodBoolean>;
|
|
63
|
+
}, z.core.$loose>;
|
|
64
|
+
export type ReadingV2 = z.infer<typeof ReadingV2Schema>;
|
|
65
|
+
export declare const isReadingV2: (item: unknown) => item is ReadingV2;
|
|
66
|
+
export declare const ReadingSchema: z.ZodPreprocess<z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
67
|
+
type: z.ZodString;
|
|
101
68
|
s: z.ZodNumber;
|
|
102
69
|
us: z.ZodOptional<z.ZodNumber>;
|
|
103
|
-
|
|
70
|
+
data: z.ZodUnion<readonly [z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, z.core.$loose>]>;
|
|
104
71
|
id: z.ZodString;
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
72
|
+
component: z.ZodOptional<z.ZodString>;
|
|
73
|
+
v: z.ZodDefault<z.ZodLiteral<1>>;
|
|
74
|
+
}, z.core.$loose>, z.ZodObject<{
|
|
75
|
+
data: z.ZodUnion<readonly [z.ZodCustom<Uint8Array, Uint8Array>, z.ZodString]>;
|
|
76
|
+
id: z.ZodString;
|
|
77
|
+
component: z.ZodOptional<z.ZodString>;
|
|
78
|
+
v: z.ZodLiteral<2>;
|
|
79
|
+
tm: z.ZodNumber;
|
|
80
|
+
bo: z.ZodOptional<z.ZodBoolean>;
|
|
81
|
+
so: z.ZodOptional<z.ZodBoolean>;
|
|
82
|
+
}, z.core.$loose>], "v">>;
|
|
83
|
+
export type Reading = z.infer<typeof ReadingSchema>;
|
|
84
|
+
export declare const isReading: (item: unknown) => item is Reading;
|
|
108
85
|
//# 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;AAOlD,eAAO,MAAM,eAAe;;;;;;;;iBAS1B,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACxD,eAAO,MAAM,WAAW,SAAU,OAAO,KAAG,IAAI,IAAI,SACX,CAAC;AAE1C,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,eAAe;;;;;;;;iBAI1B,CAAC;AACH,MAAM,MAAM,SAAS,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,eAAe,CAAC,CAAC;AACxD,eAAO,MAAM,WAAW,SAAU,OAAO,KAAG,IAAI,IAAI,SACX,CAAC;AAiB1C,eAAO,MAAM,aAAa;;;;;;;;;;;;;;;;yBAMzB,CAAC;AACF,MAAM,MAAM,OAAO,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,aAAa,CAAC,CAAC;AACpD,eAAO,MAAM,SAAS,SAAU,OAAO,KAAG,IAAI,IAAI,OACX,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.isReadingV1 = exports.ReadingV1Schema = exports.isReadingMetadataV1 = exports.ReadingMetadataV1Schema = exports.isDeviceReadingTypes = exports.DeviceReadingSchemas = exports.isDeviceReadingV1 = exports.DeviceReadingV1Schema = exports.isDeviceReadingMetadataV1 = exports.DeviceReadingMetadataV1Schema = exports.ReadingDataTypesSchema = void 0;
|
|
3
|
+
exports.isReading = exports.ReadingSchema = exports.isReadingV2 = exports.ReadingV2Schema = exports.isReadingV2Metadata = exports.ReadingV2MetadataSchema = exports.isReadingV1 = exports.ReadingV1Schema = 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,52 @@ 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
|
-
|
|
26
|
-
.
|
|
27
|
-
data: exports.ReadingDataTypesSchema,
|
|
29
|
+
const ReadingCommonShape = {
|
|
30
|
+
id: zod_1.z.string(),
|
|
28
31
|
component: zod_1.z.string().optional(),
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
.
|
|
32
|
+
};
|
|
33
|
+
exports.ReadingV1Schema = zod_1.z.looseObject({
|
|
34
|
+
[constants_1.READING_VERSION_IDENTIFIER]: zod_1.z
|
|
35
|
+
.literal(exports.READING_VERSION_1)
|
|
36
|
+
.default(exports.READING_VERSION_1),
|
|
37
|
+
...ReadingCommonShape,
|
|
38
|
+
type: zod_1.z.string(),
|
|
39
|
+
s: zod_1.z.number(),
|
|
40
|
+
us: zod_1.z.number().optional(),
|
|
41
|
+
data: exports.ReadingDataTypesSchema,
|
|
42
|
+
});
|
|
32
43
|
const isReadingV1 = (item) => exports.ReadingV1Schema.safeParse(item).success;
|
|
33
44
|
exports.isReadingV1 = isReadingV1;
|
|
45
|
+
exports.ReadingV2MetadataSchema = zod_1.z.object({
|
|
46
|
+
[constants_1.READING_VERSION_IDENTIFIER]: zod_1.z.literal(exports.READING_VERSION_2),
|
|
47
|
+
tm: zod_1.z.number(),
|
|
48
|
+
bo: zod_1.z.boolean().optional(),
|
|
49
|
+
so: zod_1.z.boolean().optional(),
|
|
50
|
+
});
|
|
51
|
+
const isReadingV2Metadata = (item) => exports.ReadingV2MetadataSchema.safeParse(item).success;
|
|
52
|
+
exports.isReadingV2Metadata = isReadingV2Metadata;
|
|
53
|
+
exports.ReadingV2Schema = zod_1.z.looseObject({
|
|
54
|
+
...exports.ReadingV2MetadataSchema.shape,
|
|
55
|
+
...ReadingCommonShape,
|
|
56
|
+
data: zod_1.z.union([zod_1.z.instanceof(Uint8Array), zod_1.z.string()]),
|
|
57
|
+
});
|
|
58
|
+
const isReadingV2 = (item) => exports.ReadingV2Schema.safeParse(item).success;
|
|
59
|
+
exports.isReadingV2 = isReadingV2;
|
|
60
|
+
const injectDefaultVersionIfMissing = (item) => {
|
|
61
|
+
if (item === null ||
|
|
62
|
+
typeof item !== "object" ||
|
|
63
|
+
Array.isArray(item) ||
|
|
64
|
+
constants_1.READING_VERSION_IDENTIFIER in item) {
|
|
65
|
+
return item;
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
...item,
|
|
69
|
+
[constants_1.READING_VERSION_IDENTIFIER]: exports.DEFAULT_READING_VERSION,
|
|
70
|
+
};
|
|
71
|
+
};
|
|
72
|
+
exports.ReadingSchema = zod_1.z.preprocess(injectDefaultVersionIfMissing, zod_1.z.discriminatedUnion(constants_1.READING_VERSION_IDENTIFIER, [
|
|
73
|
+
exports.ReadingV1Schema,
|
|
74
|
+
exports.ReadingV2Schema,
|
|
75
|
+
]));
|
|
76
|
+
const isReading = (item) => exports.ReadingSchema.safeParse(item).success;
|
|
77
|
+
exports.isReading = isReading;
|
|
@@ -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.12",
|
|
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.12"
|
|
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.12",
|
|
25
|
+
"@xube/kit-constants": "^0.2.12",
|
|
26
|
+
"@xube/kit-generator": "^0.2.12",
|
|
27
|
+
"@xube/kit-log": "^0.2.12",
|
|
28
|
+
"@xube/kit-schema": "^0.2.12",
|
|
29
|
+
"zod": "^4.4.3",
|
|
30
|
+
"zod-validation-error": "^5.0.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/src/constants.ts
CHANGED
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
import { Buffer } from "buffer";
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_READING_VERSION,
|
|
4
|
+
READING_VERSION_1,
|
|
5
|
+
READING_VERSION_2,
|
|
6
|
+
ReadingSchema,
|
|
7
|
+
ReadingV1,
|
|
8
|
+
ReadingV1Schema,
|
|
9
|
+
ReadingV2,
|
|
10
|
+
ReadingV2Schema,
|
|
11
|
+
isReading,
|
|
12
|
+
isReadingV1,
|
|
13
|
+
isReadingV2,
|
|
14
|
+
} from "./reading";
|
|
15
|
+
|
|
16
|
+
const legacyV1 = {
|
|
17
|
+
data: "S,+000.30,+001.74,M,00,33",
|
|
18
|
+
s: 1697578841,
|
|
19
|
+
us: 214981,
|
|
20
|
+
type: "data",
|
|
21
|
+
id: "dev1",
|
|
22
|
+
component: "c",
|
|
23
|
+
};
|
|
24
|
+
const explicitV1 = { ...legacyV1, v: READING_VERSION_1 };
|
|
25
|
+
const blobV2Binary = {
|
|
26
|
+
v: READING_VERSION_2,
|
|
27
|
+
id: "dev1",
|
|
28
|
+
component: "c",
|
|
29
|
+
tm: 1780859506366,
|
|
30
|
+
bo: false,
|
|
31
|
+
so: false,
|
|
32
|
+
data: Buffer.from([0x01, 0x02, 0x03]),
|
|
33
|
+
};
|
|
34
|
+
const blobV2String = {
|
|
35
|
+
v: READING_VERSION_2,
|
|
36
|
+
id: "dev1",
|
|
37
|
+
tm: 1,
|
|
38
|
+
bo: false,
|
|
39
|
+
so: false,
|
|
40
|
+
data: "blob-as-string",
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
describe("ReadingSchema (discriminated union)", () => {
|
|
44
|
+
describe("v1 (timestamped)", () => {
|
|
45
|
+
it("parses a legacy record missing `v` and injects DEFAULT_READING_VERSION", () => {
|
|
46
|
+
const parsed = ReadingSchema.parse(legacyV1) as ReadingV1;
|
|
47
|
+
expect(parsed.v).toBe(DEFAULT_READING_VERSION);
|
|
48
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
49
|
+
expect(parsed.data).toBe(legacyV1.data);
|
|
50
|
+
expect(parsed.id).toBe(legacyV1.id);
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it("parses an explicit v=1 record without mutating other fields", () => {
|
|
54
|
+
const parsed = ReadingSchema.parse(explicitV1) as ReadingV1;
|
|
55
|
+
expect(parsed).toEqual(explicitV1);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
it("preserves passthrough fields", () => {
|
|
59
|
+
const parsed = ReadingSchema.parse({
|
|
60
|
+
...explicitV1,
|
|
61
|
+
extra: "passthrough",
|
|
62
|
+
}) as ReadingV1 & { extra: string };
|
|
63
|
+
expect(parsed.extra).toBe("passthrough");
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("does not overwrite an explicit v on a record that already has one", () => {
|
|
67
|
+
// Preprocess only injects v when missing — must not clobber existing v.
|
|
68
|
+
const parsed = ReadingSchema.parse(explicitV1) as ReadingV1;
|
|
69
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
describe("v2 (blob)", () => {
|
|
74
|
+
it("parses a v=2 record with a Uint8Array data payload", () => {
|
|
75
|
+
const parsed = ReadingSchema.parse(blobV2Binary) as ReadingV2;
|
|
76
|
+
expect(parsed.v).toBe(READING_VERSION_2);
|
|
77
|
+
expect(parsed.tm).toBe(blobV2Binary.tm);
|
|
78
|
+
expect(parsed.data).toBeInstanceOf(Uint8Array);
|
|
79
|
+
expect((parsed.data as Uint8Array).length).toBe(3);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("parses a v=2 record with a string data payload", () => {
|
|
83
|
+
expect(ReadingSchema.parse(blobV2String)).toEqual(blobV2String);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("rejects a v=2 record missing the required tm field", () => {
|
|
87
|
+
const { tm: _tm, ...withoutTm } = blobV2String;
|
|
88
|
+
expect(ReadingSchema.safeParse(withoutTm).success).toBe(false);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("rejects a v=2 record missing the required data field", () => {
|
|
92
|
+
const { data: _data, ...withoutData } = blobV2String;
|
|
93
|
+
expect(ReadingSchema.safeParse(withoutData).success).toBe(false);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("rejects a v=2 record missing the required id field", () => {
|
|
97
|
+
const { id: _id, ...withoutId } = blobV2String;
|
|
98
|
+
expect(ReadingSchema.safeParse(withoutId).success).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe("invalid input", () => {
|
|
103
|
+
it("rejects an unknown v value", () => {
|
|
104
|
+
expect(ReadingSchema.safeParse({ v: 99, foo: "bar" }).success).toBe(
|
|
105
|
+
false,
|
|
106
|
+
);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
it.each([
|
|
110
|
+
["null", null],
|
|
111
|
+
["undefined", undefined],
|
|
112
|
+
["string", "not-an-object"],
|
|
113
|
+
["number", 42],
|
|
114
|
+
["boolean", true],
|
|
115
|
+
["array", [1, 2, 3]],
|
|
116
|
+
])("rejects %s input without crashing", (_label, input) => {
|
|
117
|
+
expect(ReadingSchema.safeParse(input).success).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it("rejects an empty object (preprocess injects v=1, then required v1 fields fail)", () => {
|
|
121
|
+
expect(ReadingSchema.safeParse({}).success).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
describe("ReadingV1Schema (standalone)", () => {
|
|
127
|
+
it("defaults v to READING_VERSION_1 when missing", () => {
|
|
128
|
+
const parsed = ReadingV1Schema.parse(legacyV1) as ReadingV1;
|
|
129
|
+
expect(parsed.v).toBe(READING_VERSION_1);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("rejects an explicit v=2 (literal check)", () => {
|
|
133
|
+
expect(
|
|
134
|
+
ReadingV1Schema.safeParse({ ...legacyV1, v: READING_VERSION_2 }).success,
|
|
135
|
+
).toBe(false);
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
describe("ReadingV2Schema (standalone)", () => {
|
|
140
|
+
it("requires v=2 explicitly (no default)", () => {
|
|
141
|
+
expect(
|
|
142
|
+
ReadingV2Schema.safeParse({ tm: 1, payload: "x" }).success,
|
|
143
|
+
).toBe(false);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("accepts a valid v=2 record", () => {
|
|
147
|
+
expect(ReadingV2Schema.safeParse(blobV2String).success).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
describe("type-narrowing predicates", () => {
|
|
152
|
+
it("isReadingV1 accepts legacy and explicit v1, rejects v2", () => {
|
|
153
|
+
expect(isReadingV1(legacyV1)).toBe(true);
|
|
154
|
+
expect(isReadingV1(explicitV1)).toBe(true);
|
|
155
|
+
expect(isReadingV1(blobV2Binary)).toBe(false);
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
it("isReadingV2 accepts v2, rejects v1 and legacy", () => {
|
|
159
|
+
expect(isReadingV2(blobV2Binary)).toBe(true);
|
|
160
|
+
expect(isReadingV2(blobV2String)).toBe(true);
|
|
161
|
+
expect(isReadingV2(legacyV1)).toBe(false);
|
|
162
|
+
expect(isReadingV2(explicitV1)).toBe(false);
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it("isReading accepts both kinds, rejects garbage", () => {
|
|
166
|
+
expect(isReading(legacyV1)).toBe(true);
|
|
167
|
+
expect(isReading(explicitV1)).toBe(true);
|
|
168
|
+
expect(isReading(blobV2Binary)).toBe(true);
|
|
169
|
+
expect(isReading(blobV2String)).toBe(true);
|
|
170
|
+
expect(isReading({ foo: "bar" })).toBe(false);
|
|
171
|
+
expect(isReading(null)).toBe(false);
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("DEFAULT_READING_VERSION", () => {
|
|
176
|
+
it("currently equals READING_VERSION_1", () => {
|
|
177
|
+
// If this fails, the preprocess no longer assumes legacy-records-are-v1 —
|
|
178
|
+
// make sure all consumers and the migration story are aware before flipping.
|
|
179
|
+
expect(DEFAULT_READING_VERSION).toBe(READING_VERSION_1);
|
|
180
|
+
});
|
|
181
|
+
});
|
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,77 @@ 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
|
-
|
|
33
|
-
.
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
43
|
+
const ReadingCommonShape = {
|
|
44
|
+
id: z.string(),
|
|
45
|
+
component: z.string().optional(),
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const ReadingV1Schema = z.looseObject({
|
|
49
|
+
[READING_VERSION_IDENTIFIER]: z
|
|
50
|
+
.literal(READING_VERSION_1)
|
|
51
|
+
.default(READING_VERSION_1),
|
|
52
|
+
...ReadingCommonShape,
|
|
53
|
+
type: z.string(),
|
|
54
|
+
s: z.number(),
|
|
55
|
+
us: z.number().optional(),
|
|
56
|
+
data: ReadingDataTypesSchema,
|
|
57
|
+
});
|
|
39
58
|
export type ReadingV1 = z.infer<typeof ReadingV1Schema>;
|
|
40
59
|
export const isReadingV1 = (item: unknown): item is ReadingV1 =>
|
|
41
60
|
ReadingV1Schema.safeParse(item).success;
|
|
61
|
+
|
|
62
|
+
export const ReadingV2MetadataSchema = z.object({
|
|
63
|
+
[READING_VERSION_IDENTIFIER]: z.literal(READING_VERSION_2),
|
|
64
|
+
tm: z.number(),
|
|
65
|
+
bo: z.boolean().optional(),
|
|
66
|
+
so: z.boolean().optional(),
|
|
67
|
+
});
|
|
68
|
+
export type ReadingV2Metadata = z.infer<typeof ReadingV2MetadataSchema>;
|
|
69
|
+
export const isReadingV2Metadata = (
|
|
70
|
+
item: unknown,
|
|
71
|
+
): item is ReadingV2Metadata =>
|
|
72
|
+
ReadingV2MetadataSchema.safeParse(item).success;
|
|
73
|
+
|
|
74
|
+
export const ReadingV2Schema = z.looseObject({
|
|
75
|
+
...ReadingV2MetadataSchema.shape,
|
|
76
|
+
...ReadingCommonShape,
|
|
77
|
+
data: z.union([z.instanceof(Uint8Array), z.string()]),
|
|
78
|
+
});
|
|
79
|
+
export type ReadingV2 = z.infer<typeof ReadingV2Schema>;
|
|
80
|
+
export const isReadingV2 = (item: unknown): item is ReadingV2 =>
|
|
81
|
+
ReadingV2Schema.safeParse(item).success;
|
|
82
|
+
|
|
83
|
+
const injectDefaultVersionIfMissing = (item: unknown): unknown => {
|
|
84
|
+
if (
|
|
85
|
+
item === null ||
|
|
86
|
+
typeof item !== "object" ||
|
|
87
|
+
Array.isArray(item) ||
|
|
88
|
+
READING_VERSION_IDENTIFIER in item
|
|
89
|
+
) {
|
|
90
|
+
return item;
|
|
91
|
+
}
|
|
92
|
+
return {
|
|
93
|
+
...item,
|
|
94
|
+
[READING_VERSION_IDENTIFIER]: DEFAULT_READING_VERSION,
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const ReadingSchema = z.preprocess(
|
|
99
|
+
injectDefaultVersionIfMissing,
|
|
100
|
+
z.discriminatedUnion(READING_VERSION_IDENTIFIER, [
|
|
101
|
+
ReadingV1Schema,
|
|
102
|
+
ReadingV2Schema,
|
|
103
|
+
]),
|
|
104
|
+
);
|
|
105
|
+
export type Reading = z.infer<typeof ReadingSchema>;
|
|
106
|
+
export const isReading = (item: unknown): item is Reading =>
|
|
107
|
+
ReadingSchema.safeParse(item).success;
|
|
@@ -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
|