@xube/kit-schema 0.0.47

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/base.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { z } from "zod";
2
+ export declare const BaseDataSchema: z.ZodObject<{
3
+ s: z.ZodNumber;
4
+ us: z.ZodOptional<z.ZodNumber>;
5
+ type: z.ZodString;
6
+ id: z.ZodString;
7
+ }, "strip", z.ZodTypeAny, {
8
+ s: number;
9
+ type: string;
10
+ id: string;
11
+ us?: number | undefined;
12
+ }, {
13
+ s: number;
14
+ type: string;
15
+ id: string;
16
+ us?: number | undefined;
17
+ }>;
package/dist/base.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseDataSchema = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.BaseDataSchema = zod_1.z.object({
6
+ s: zod_1.z.number(),
7
+ us: zod_1.z.number().optional(),
8
+ type: zod_1.z.string(),
9
+ id: zod_1.z.string(), //Id of item
10
+ });
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const zod_openapi_1 = require("@anatine/zod-openapi");
4
+ const time_series_1 = require("./time-series");
5
+ console.log((0, zod_openapi_1.generateSchema)(time_series_1.TimeSeriesSchema));
@@ -0,0 +1,2 @@
1
+ export { validate as validateBaseData } from './validators/baseData';
2
+ export * from './types/baseData';
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.validateBaseData = void 0;
18
+ var baseData_1 = require("./validators/baseData");
19
+ Object.defineProperty(exports, "validateBaseData", { enumerable: true, get: function () { return baseData_1.validate; } });
20
+ __exportStar(require("./types/baseData"), exports);
@@ -0,0 +1,14 @@
1
+ /**
2
+ * I am a generated file.
3
+ *
4
+ * If you change me, you and other developers will be sad.
5
+ *
6
+ * #StayGeneratedStayHappy
7
+ */
8
+ export type BaseData = {
9
+ s: number;
10
+ us?: number | undefined;
11
+ type: string;
12
+ id: string;
13
+ };
14
+ export declare const isBaseData: (item: unknown) => item is BaseData;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /**
3
+ * I am a generated file.
4
+ *
5
+ * If you change me, you and other developers will be sad.
6
+ *
7
+ * #StayGeneratedStayHappy
8
+ */
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.isBaseData = void 0;
14
+ const kit_log_1 = require("@xube/kit-log");
15
+ const baseData_1 = __importDefault(require("../validators/baseData"));
16
+ const isBaseData = (item) => {
17
+ const isValid = (0, baseData_1.default)(item);
18
+ if (!isValid) {
19
+ kit_log_1.XubeLog.getInstance().info(JSON.stringify(baseData_1.default.errors, null, 2));
20
+ }
21
+ return isValid;
22
+ };
23
+ exports.isBaseData = isBaseData;
@@ -0,0 +1,13 @@
1
+ export function validate(data: any, { instancePath, parentData, parentDataProperty, rootData }?: {
2
+ instancePath?: string | undefined;
3
+ parentData: any;
4
+ parentDataProperty: any;
5
+ rootData?: any;
6
+ }): boolean;
7
+ export default validate10;
8
+ declare function validate10(data: any, { instancePath, parentData, parentDataProperty, rootData }?: {
9
+ instancePath?: string | undefined;
10
+ parentData: any;
11
+ parentDataProperty: any;
12
+ rootData?: any;
13
+ }): boolean;
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validate = void 0;
4
+ exports.validate = validate10;
5
+ exports.default = validate10;
6
+ const schema27 = { "$ref": "#/definitions/basedataJsonSchema", "definitions": { "basedataJsonSchema": { "type": "object", "properties": { "s": { "type": "number" }, "us": { "type": "number" }, "type": { "type": "string" }, "id": { "type": "string" } }, "required": ["s", "type", "id"], "additionalProperties": false } }, "$schema": "http://json-schema.org/draft-07/schema#" };
7
+ const schema28 = { "type": "object", "properties": { "s": { "type": "number" }, "us": { "type": "number" }, "type": { "type": "string" }, "id": { "type": "string" } }, "required": ["s", "type", "id"], "additionalProperties": false };
8
+ function validate10(data, { instancePath = "", parentData, parentDataProperty, rootData = data } = {}) { let vErrors = null; let errors = 0; if (data && typeof data == "object" && !Array.isArray(data)) {
9
+ if (data.s === undefined) {
10
+ const err0 = { instancePath, schemaPath: "#/definitions/basedataJsonSchema/required", keyword: "required", params: { missingProperty: "s" }, message: "must have required property '" + "s" + "'" };
11
+ if (vErrors === null) {
12
+ vErrors = [err0];
13
+ }
14
+ else {
15
+ vErrors.push(err0);
16
+ }
17
+ errors++;
18
+ }
19
+ if (data.type === undefined) {
20
+ const err1 = { instancePath, schemaPath: "#/definitions/basedataJsonSchema/required", keyword: "required", params: { missingProperty: "type" }, message: "must have required property '" + "type" + "'" };
21
+ if (vErrors === null) {
22
+ vErrors = [err1];
23
+ }
24
+ else {
25
+ vErrors.push(err1);
26
+ }
27
+ errors++;
28
+ }
29
+ if (data.id === undefined) {
30
+ const err2 = { instancePath, schemaPath: "#/definitions/basedataJsonSchema/required", keyword: "required", params: { missingProperty: "id" }, message: "must have required property '" + "id" + "'" };
31
+ if (vErrors === null) {
32
+ vErrors = [err2];
33
+ }
34
+ else {
35
+ vErrors.push(err2);
36
+ }
37
+ errors++;
38
+ }
39
+ for (const key0 in data) {
40
+ if (!((((key0 === "s") || (key0 === "us")) || (key0 === "type")) || (key0 === "id"))) {
41
+ const err3 = { instancePath, schemaPath: "#/definitions/basedataJsonSchema/additionalProperties", keyword: "additionalProperties", params: { additionalProperty: key0 }, message: "must NOT have additional properties" };
42
+ if (vErrors === null) {
43
+ vErrors = [err3];
44
+ }
45
+ else {
46
+ vErrors.push(err3);
47
+ }
48
+ errors++;
49
+ }
50
+ }
51
+ if (data.s !== undefined) {
52
+ let data0 = data.s;
53
+ if (!((typeof data0 == "number") && (isFinite(data0)))) {
54
+ const err4 = { instancePath: instancePath + "/s", schemaPath: "#/definitions/basedataJsonSchema/properties/s/type", keyword: "type", params: { type: "number" }, message: "must be number" };
55
+ if (vErrors === null) {
56
+ vErrors = [err4];
57
+ }
58
+ else {
59
+ vErrors.push(err4);
60
+ }
61
+ errors++;
62
+ }
63
+ }
64
+ if (data.us !== undefined) {
65
+ let data1 = data.us;
66
+ if (!((typeof data1 == "number") && (isFinite(data1)))) {
67
+ const err5 = { instancePath: instancePath + "/us", schemaPath: "#/definitions/basedataJsonSchema/properties/us/type", keyword: "type", params: { type: "number" }, message: "must be number" };
68
+ if (vErrors === null) {
69
+ vErrors = [err5];
70
+ }
71
+ else {
72
+ vErrors.push(err5);
73
+ }
74
+ errors++;
75
+ }
76
+ }
77
+ if (data.type !== undefined) {
78
+ if (typeof data.type !== "string") {
79
+ const err6 = { instancePath: instancePath + "/type", schemaPath: "#/definitions/basedataJsonSchema/properties/type/type", keyword: "type", params: { type: "string" }, message: "must be string" };
80
+ if (vErrors === null) {
81
+ vErrors = [err6];
82
+ }
83
+ else {
84
+ vErrors.push(err6);
85
+ }
86
+ errors++;
87
+ }
88
+ }
89
+ if (data.id !== undefined) {
90
+ if (typeof data.id !== "string") {
91
+ const err7 = { instancePath: instancePath + "/id", schemaPath: "#/definitions/basedataJsonSchema/properties/id/type", keyword: "type", params: { type: "string" }, message: "must be string" };
92
+ if (vErrors === null) {
93
+ vErrors = [err7];
94
+ }
95
+ else {
96
+ vErrors.push(err7);
97
+ }
98
+ errors++;
99
+ }
100
+ }
101
+ }
102
+ else {
103
+ const err8 = { instancePath, schemaPath: "#/definitions/basedataJsonSchema/type", keyword: "type", params: { type: "object" }, message: "must be object" };
104
+ if (vErrors === null) {
105
+ vErrors = [err8];
106
+ }
107
+ else {
108
+ vErrors.push(err8);
109
+ }
110
+ errors++;
111
+ } validate10.errors = vErrors; return errors === 0; }
@@ -0,0 +1,3 @@
1
+ export * from "./base";
2
+ export * from "./time-series";
3
+ export * from "./generated/index";
package/dist/index.js ADDED
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./base"), exports);
18
+ __exportStar(require("./time-series"), exports);
19
+ __exportStar(require("./generated/index"), exports);
@@ -0,0 +1,190 @@
1
+ import { z } from "zod";
2
+ export declare const SourceTypes: {
3
+ readonly device: "device";
4
+ readonly component: "component";
5
+ readonly platform: "platform";
6
+ };
7
+ export declare const SourceTypeSchema: z.ZodNativeEnum<{
8
+ readonly device: "device";
9
+ readonly component: "component";
10
+ readonly platform: "platform";
11
+ }>;
12
+ export type SourceType = z.infer<typeof SourceTypeSchema>;
13
+ export declare const TriggerTypes: {
14
+ readonly data: "data";
15
+ readonly event: "event";
16
+ };
17
+ export declare const TriggerTypeSchema: z.ZodNativeEnum<{
18
+ readonly data: "data";
19
+ readonly event: "event";
20
+ }>;
21
+ export type TriggerType = z.infer<typeof TriggerTypeSchema>;
22
+ export declare const TimeUnit: {
23
+ readonly us: "us";
24
+ readonly ms: "ms";
25
+ readonly s: "s";
26
+ readonly m: "m";
27
+ readonly h: "h";
28
+ readonly d: "d";
29
+ };
30
+ export declare const TimeUnitSchema: z.ZodNativeEnum<{
31
+ readonly us: "us";
32
+ readonly ms: "ms";
33
+ readonly s: "s";
34
+ readonly m: "m";
35
+ readonly h: "h";
36
+ readonly d: "d";
37
+ }>;
38
+ export type TimeUnit = z.infer<typeof TimeUnitSchema>;
39
+ export declare const GenericDataTypesSchema: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>]>;
40
+ export declare const TimeSeriesEntrySchema: z.ZodObject<{
41
+ v: z.ZodString;
42
+ m: z.ZodObject<{
43
+ id: z.ZodString;
44
+ trigger: z.ZodNativeEnum<{
45
+ readonly data: "data";
46
+ readonly event: "event";
47
+ }>;
48
+ source: z.ZodNativeEnum<{
49
+ readonly device: "device";
50
+ readonly component: "component";
51
+ readonly platform: "platform";
52
+ }>;
53
+ }, "strip", z.ZodTypeAny, {
54
+ id: string;
55
+ trigger: "data" | "event";
56
+ source: "device" | "component" | "platform";
57
+ }, {
58
+ id: string;
59
+ trigger: "data" | "event";
60
+ source: "device" | "component" | "platform";
61
+ }>;
62
+ t0: z.ZodString;
63
+ dtt: z.ZodDefault<z.ZodNativeEnum<{
64
+ readonly us: "us";
65
+ readonly ms: "ms";
66
+ readonly s: "s";
67
+ readonly m: "m";
68
+ readonly h: "h";
69
+ readonly d: "d";
70
+ }>>;
71
+ dt: z.ZodNumber;
72
+ dataT: z.ZodOptional<z.ZodArray<z.ZodObject<{
73
+ i: z.ZodNumber;
74
+ dt: z.ZodNumber;
75
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
76
+ i: z.ZodNumber;
77
+ dt: z.ZodNumber;
78
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
79
+ i: z.ZodNumber;
80
+ dt: z.ZodNumber;
81
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
82
+ data: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>]>, "many">;
83
+ }, "strip", z.ZodTypeAny, {
84
+ data: (string | number | boolean | z.objectOutputType<{}, z.ZodTypeAny, "passthrough">)[];
85
+ m: {
86
+ id: string;
87
+ trigger: "data" | "event";
88
+ source: "device" | "component" | "platform";
89
+ };
90
+ v: string;
91
+ t0: string;
92
+ dtt: "s" | "us" | "ms" | "m" | "h" | "d";
93
+ dt: number;
94
+ dataT?: z.objectOutputType<{
95
+ i: z.ZodNumber;
96
+ dt: z.ZodNumber;
97
+ }, z.ZodTypeAny, "passthrough">[] | undefined;
98
+ }, {
99
+ data: (string | number | boolean | z.objectInputType<{}, z.ZodTypeAny, "passthrough">)[];
100
+ m: {
101
+ id: string;
102
+ trigger: "data" | "event";
103
+ source: "device" | "component" | "platform";
104
+ };
105
+ v: string;
106
+ t0: string;
107
+ dt: number;
108
+ dtt?: "s" | "us" | "ms" | "m" | "h" | "d" | undefined;
109
+ dataT?: z.objectInputType<{
110
+ i: z.ZodNumber;
111
+ dt: z.ZodNumber;
112
+ }, z.ZodTypeAny, "passthrough">[] | undefined;
113
+ }>;
114
+ export type TimeSeriesEntry = z.infer<typeof TimeSeriesEntrySchema>;
115
+ export declare const TimeSeriesSchema: z.ZodArray<z.ZodObject<{
116
+ v: z.ZodString;
117
+ m: z.ZodObject<{
118
+ id: z.ZodString;
119
+ trigger: z.ZodNativeEnum<{
120
+ readonly data: "data";
121
+ readonly event: "event";
122
+ }>;
123
+ source: z.ZodNativeEnum<{
124
+ readonly device: "device";
125
+ readonly component: "component";
126
+ readonly platform: "platform";
127
+ }>;
128
+ }, "strip", z.ZodTypeAny, {
129
+ id: string;
130
+ trigger: "data" | "event";
131
+ source: "device" | "component" | "platform";
132
+ }, {
133
+ id: string;
134
+ trigger: "data" | "event";
135
+ source: "device" | "component" | "platform";
136
+ }>;
137
+ t0: z.ZodString;
138
+ dtt: z.ZodDefault<z.ZodNativeEnum<{
139
+ readonly us: "us";
140
+ readonly ms: "ms";
141
+ readonly s: "s";
142
+ readonly m: "m";
143
+ readonly h: "h";
144
+ readonly d: "d";
145
+ }>>;
146
+ dt: z.ZodNumber;
147
+ dataT: z.ZodOptional<z.ZodArray<z.ZodObject<{
148
+ i: z.ZodNumber;
149
+ dt: z.ZodNumber;
150
+ }, "passthrough", z.ZodTypeAny, z.objectOutputType<{
151
+ i: z.ZodNumber;
152
+ dt: z.ZodNumber;
153
+ }, z.ZodTypeAny, "passthrough">, z.objectInputType<{
154
+ i: z.ZodNumber;
155
+ dt: z.ZodNumber;
156
+ }, z.ZodTypeAny, "passthrough">>, "many">>;
157
+ data: z.ZodArray<z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodObject<{}, "passthrough", z.ZodTypeAny, z.objectOutputType<{}, z.ZodTypeAny, "passthrough">, z.objectInputType<{}, z.ZodTypeAny, "passthrough">>]>, "many">;
158
+ }, "strip", z.ZodTypeAny, {
159
+ data: (string | number | boolean | z.objectOutputType<{}, z.ZodTypeAny, "passthrough">)[];
160
+ m: {
161
+ id: string;
162
+ trigger: "data" | "event";
163
+ source: "device" | "component" | "platform";
164
+ };
165
+ v: string;
166
+ t0: string;
167
+ dtt: "s" | "us" | "ms" | "m" | "h" | "d";
168
+ dt: number;
169
+ dataT?: z.objectOutputType<{
170
+ i: z.ZodNumber;
171
+ dt: z.ZodNumber;
172
+ }, z.ZodTypeAny, "passthrough">[] | undefined;
173
+ }, {
174
+ data: (string | number | boolean | z.objectInputType<{}, z.ZodTypeAny, "passthrough">)[];
175
+ m: {
176
+ id: string;
177
+ trigger: "data" | "event";
178
+ source: "device" | "component" | "platform";
179
+ };
180
+ v: string;
181
+ t0: string;
182
+ dt: number;
183
+ dtt?: "s" | "us" | "ms" | "m" | "h" | "d" | undefined;
184
+ dataT?: z.objectInputType<{
185
+ i: z.ZodNumber;
186
+ dt: z.ZodNumber;
187
+ }, z.ZodTypeAny, "passthrough">[] | undefined;
188
+ }>, "many">;
189
+ export type TimeSeries = z.infer<typeof TimeSeriesSchema>;
190
+ export declare const timeSeriesExample: TimeSeries;
@@ -0,0 +1,93 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.timeSeriesExample = exports.TimeSeriesSchema = exports.TimeSeriesEntrySchema = exports.GenericDataTypesSchema = exports.TimeUnitSchema = exports.TimeUnit = exports.TriggerTypeSchema = exports.TriggerTypes = exports.SourceTypeSchema = exports.SourceTypes = void 0;
4
+ const zod_1 = require("zod");
5
+ exports.SourceTypes = {
6
+ device: "device",
7
+ component: "component",
8
+ platform: "platform",
9
+ };
10
+ exports.SourceTypeSchema = zod_1.z.nativeEnum(exports.SourceTypes);
11
+ exports.TriggerTypes = {
12
+ data: "data",
13
+ event: "event",
14
+ };
15
+ exports.TriggerTypeSchema = zod_1.z.nativeEnum(exports.TriggerTypes);
16
+ exports.TimeUnit = {
17
+ us: "us",
18
+ ms: "ms",
19
+ s: "s",
20
+ m: "m",
21
+ h: "h",
22
+ d: "d",
23
+ };
24
+ exports.TimeUnitSchema = zod_1.z.nativeEnum(exports.TimeUnit);
25
+ exports.GenericDataTypesSchema = zod_1.z.union([
26
+ zod_1.z.string(),
27
+ zod_1.z.number(),
28
+ zod_1.z.boolean(),
29
+ zod_1.z.object({}).passthrough(),
30
+ ]);
31
+ exports.TimeSeriesEntrySchema = zod_1.z.object({
32
+ v: zod_1.z.string(),
33
+ m: zod_1.z.object({
34
+ id: zod_1.z.string(),
35
+ trigger: exports.TriggerTypeSchema,
36
+ source: exports.SourceTypeSchema,
37
+ }),
38
+ t0: zod_1.z.string().datetime(),
39
+ dtt: exports.TimeUnitSchema.default("ms"),
40
+ dt: zod_1.z.number(),
41
+ dataT: zod_1.z
42
+ .array(zod_1.z
43
+ .object({
44
+ i: zod_1.z.number(),
45
+ dt: zod_1.z.number(), //only if t is not present
46
+ })
47
+ .passthrough())
48
+ .optional(),
49
+ data: zod_1.z.array(exports.GenericDataTypesSchema),
50
+ });
51
+ exports.TimeSeriesSchema = zod_1.z.array(exports.TimeSeriesEntrySchema);
52
+ exports.timeSeriesExample = [
53
+ {
54
+ v: "1",
55
+ m: {
56
+ id: "DEVICE_1234567890",
57
+ trigger: "data",
58
+ source: "device", //Options are "device", "component", or "platform"
59
+ },
60
+ t0: "2023-10-13T01:29:55.1024001Z",
61
+ dtt: "ms",
62
+ dt: 1,
63
+ dataT: [
64
+ {
65
+ i: 4,
66
+ dt: 3, //diff in time with dtt as the unit
67
+ },
68
+ ],
69
+ data: [
70
+ //This is the data readings array
71
+ {
72
+ x: 1,
73
+ y: 0.5,
74
+ z: -0.2,
75
+ },
76
+ {
77
+ x: 1.4,
78
+ y: 3.5,
79
+ z: -0.2,
80
+ },
81
+ {
82
+ x: 0.1,
83
+ y: 0.2,
84
+ z: -1.2,
85
+ },
86
+ {
87
+ x: 0.8,
88
+ y: 0.2,
89
+ z: -0.9,
90
+ },
91
+ ],
92
+ },
93
+ ];
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@xube/kit-schema",
3
+ "version": "0.0.47",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "test": "echo \"Error: no test specified\" && exit 1",
8
+ "generate": "npx ts-node ./src/generator.ts"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+ssh://git@github.com/XubeLtd/data-logger.git"
13
+ },
14
+ "author": "Xube Pty Ltd",
15
+ "license": "MIT",
16
+ "bugs": {
17
+ "url": "https://github.com/XubeLtd/data-logger/issues"
18
+ },
19
+ "homepage": "https://github.com/XubeLtd/data-logger#readme",
20
+ "dependencies": {
21
+ "@anatine/zod-openapi": "^2.2.0",
22
+ "@xube/kit-constants": "^0.0.47",
23
+ "@xube/kit-generator": "^0.0.47",
24
+ "@xube/kit-log": "^0.0.47",
25
+ "zod": "^3.22.4"
26
+ },
27
+ "devDependencies": {
28
+ "@xube/kit-build": "^0.0.47"
29
+ }
30
+ }
package/src/base.ts ADDED
@@ -0,0 +1,8 @@
1
+ import {z} from "zod";
2
+
3
+ export const BaseDataSchema = z.object({
4
+ s: z.number(), //Seconds
5
+ us: z.number().optional(), //Microseconds
6
+ type: z.string(), //Type of item (ie. data, event, etc)
7
+ id: z.string(), //Id of item
8
+ });
@@ -0,0 +1,4 @@
1
+ import { generateSchema } from '@anatine/zod-openapi';
2
+ import { TimeSeriesSchema } from './time-series';
3
+
4
+ console.log(generateSchema(TimeSeriesSchema))
@@ -0,0 +1,2 @@
1
+ export {validate as validateBaseData} from './validators/baseData'
2
+ export * from './types/baseData'
@@ -0,0 +1,29 @@
1
+
2
+ /**
3
+ * I am a generated file.
4
+ *
5
+ * If you change me, you and other developers will be sad.
6
+ *
7
+ * #StayGeneratedStayHappy
8
+ */
9
+
10
+ export type BaseData = {
11
+ s: number;
12
+ us?: number | undefined;
13
+ type: string;
14
+ id: string;
15
+ };
16
+
17
+
18
+
19
+ import { XubeLog } from "@xube/kit-log";
20
+ import validate from "../validators/baseData";
21
+
22
+ export const isBaseData = (item: unknown): item is BaseData => {
23
+ const isValid: boolean = validate(item);
24
+ if(!isValid){
25
+ XubeLog.getInstance().info(JSON.stringify((validate as typeof validate & {errors: object}).errors, null, 2));
26
+ }
27
+ return isValid;
28
+ }
29
+
@@ -0,0 +1 @@
1
+ "use strict";export const validate = validate10;export default validate10;const schema27 = {"$ref":"#/definitions/basedataJsonSchema","definitions":{"basedataJsonSchema":{"type":"object","properties":{"s":{"type":"number"},"us":{"type":"number"},"type":{"type":"string"},"id":{"type":"string"}},"required":["s","type","id"],"additionalProperties":false}},"$schema":"http://json-schema.org/draft-07/schema#"};const schema28 = {"type":"object","properties":{"s":{"type":"number"},"us":{"type":"number"},"type":{"type":"string"},"id":{"type":"string"}},"required":["s","type","id"],"additionalProperties":false};function validate10(data, {instancePath="", parentData, parentDataProperty, rootData=data}={}){let vErrors = null;let errors = 0;if(data && typeof data == "object" && !Array.isArray(data)){if(data.s === undefined){const err0 = {instancePath,schemaPath:"#/definitions/basedataJsonSchema/required",keyword:"required",params:{missingProperty: "s"},message:"must have required property '"+"s"+"'"};if(vErrors === null){vErrors = [err0];}else {vErrors.push(err0);}errors++;}if(data.type === undefined){const err1 = {instancePath,schemaPath:"#/definitions/basedataJsonSchema/required",keyword:"required",params:{missingProperty: "type"},message:"must have required property '"+"type"+"'"};if(vErrors === null){vErrors = [err1];}else {vErrors.push(err1);}errors++;}if(data.id === undefined){const err2 = {instancePath,schemaPath:"#/definitions/basedataJsonSchema/required",keyword:"required",params:{missingProperty: "id"},message:"must have required property '"+"id"+"'"};if(vErrors === null){vErrors = [err2];}else {vErrors.push(err2);}errors++;}for(const key0 in data){if(!((((key0 === "s") || (key0 === "us")) || (key0 === "type")) || (key0 === "id"))){const err3 = {instancePath,schemaPath:"#/definitions/basedataJsonSchema/additionalProperties",keyword:"additionalProperties",params:{additionalProperty: key0},message:"must NOT have additional properties"};if(vErrors === null){vErrors = [err3];}else {vErrors.push(err3);}errors++;}}if(data.s !== undefined){let data0 = data.s;if(!((typeof data0 == "number") && (isFinite(data0)))){const err4 = {instancePath:instancePath+"/s",schemaPath:"#/definitions/basedataJsonSchema/properties/s/type",keyword:"type",params:{type: "number"},message:"must be number"};if(vErrors === null){vErrors = [err4];}else {vErrors.push(err4);}errors++;}}if(data.us !== undefined){let data1 = data.us;if(!((typeof data1 == "number") && (isFinite(data1)))){const err5 = {instancePath:instancePath+"/us",schemaPath:"#/definitions/basedataJsonSchema/properties/us/type",keyword:"type",params:{type: "number"},message:"must be number"};if(vErrors === null){vErrors = [err5];}else {vErrors.push(err5);}errors++;}}if(data.type !== undefined){if(typeof data.type !== "string"){const err6 = {instancePath:instancePath+"/type",schemaPath:"#/definitions/basedataJsonSchema/properties/type/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err6];}else {vErrors.push(err6);}errors++;}}if(data.id !== undefined){if(typeof data.id !== "string"){const err7 = {instancePath:instancePath+"/id",schemaPath:"#/definitions/basedataJsonSchema/properties/id/type",keyword:"type",params:{type: "string"},message:"must be string"};if(vErrors === null){vErrors = [err7];}else {vErrors.push(err7);}errors++;}}}else {const err8 = {instancePath,schemaPath:"#/definitions/basedataJsonSchema/type",keyword:"type",params:{type: "object"},message:"must be object"};if(vErrors === null){vErrors = [err8];}else {vErrors.push(err8);}errors++;}validate10.errors = vErrors;return errors === 0;}
@@ -0,0 +1,12 @@
1
+ import {
2
+ generateExportIndex,
3
+ generateTypeSchemaFiles,
4
+ } from "@xube/kit-generator";
5
+
6
+ import { BaseDataSchema } from "./base";
7
+
8
+ const generatedFilePaths: string[] = [
9
+ ...generateTypeSchemaFiles("baseData", BaseDataSchema, __dirname),
10
+ ];
11
+
12
+ generateExportIndex(generatedFilePaths, __dirname);
package/src/index.ts ADDED
@@ -0,0 +1,4 @@
1
+ export * from "./base";
2
+ export * from "./time-series";
3
+
4
+ export * from "./generated/index";
@@ -0,0 +1,104 @@
1
+ import { z } from "zod";
2
+
3
+ export const SourceTypes = {
4
+ device: "device",
5
+ component: "component",
6
+ platform: "platform",
7
+ } as const;
8
+ export const SourceTypeSchema = z.nativeEnum(SourceTypes);
9
+ export type SourceType = z.infer<typeof SourceTypeSchema>;
10
+
11
+ export const TriggerTypes = {
12
+ data: "data",
13
+ event: "event",
14
+ } as const;
15
+ export const TriggerTypeSchema = z.nativeEnum(TriggerTypes);
16
+ export type TriggerType = z.infer<typeof TriggerTypeSchema>;
17
+
18
+ export const TimeUnit = {
19
+ us: "us",
20
+ ms: "ms",
21
+ s: "s",
22
+ m: "m",
23
+ h: "h",
24
+ d: "d",
25
+ } as const;
26
+ export const TimeUnitSchema = z.nativeEnum(TimeUnit);
27
+ export type TimeUnit = z.infer<typeof TimeUnitSchema>;
28
+
29
+ export const GenericDataTypesSchema = z.union([
30
+ z.string(),
31
+ z.number(),
32
+ z.boolean(),
33
+ z.object({}).passthrough(),
34
+ ]);
35
+
36
+ export const TimeSeriesEntrySchema = z.object({
37
+ v: z.string(),
38
+ m: z.object({
39
+ id: z.string(),
40
+ trigger: TriggerTypeSchema,
41
+ source: SourceTypeSchema,
42
+ }),
43
+ t0: z.string().datetime(), //in microseconds since epoch
44
+ dtt: TimeUnitSchema.default("ms"), //delta type - time unit
45
+ dt: z.number(), //in microseconds
46
+ dataT: z
47
+ .array(
48
+ z
49
+ .object({
50
+ i: z.number(),
51
+ dt: z.number(), //only if t is not present
52
+ })
53
+ .passthrough()
54
+ )
55
+ .optional(),
56
+ data: z.array(GenericDataTypesSchema),
57
+ });
58
+ export type TimeSeriesEntry = z.infer<typeof TimeSeriesEntrySchema>;
59
+
60
+ export const TimeSeriesSchema = z.array(TimeSeriesEntrySchema);
61
+ export type TimeSeries = z.infer<typeof TimeSeriesSchema>;
62
+
63
+ export const timeSeriesExample: TimeSeries = [
64
+ {
65
+ v: "1", //Version of the schema
66
+ m: {
67
+ id: "DEVICE_1234567890", //This is the device, or component id
68
+ trigger: "data", //Options are "data" or "event"
69
+ source: "device", //Options are "device", "component", or "platform"
70
+ },
71
+ t0: "2023-10-13T01:29:55.1024001Z", //microseconds since epoch
72
+ dtt: "ms", //Time unit for dt. Default is ms
73
+ dt: 1, //In milliseconds. This is 1 ms
74
+ dataT: [
75
+ {
76
+ i: 4, // index of the data reading in Y
77
+ dt: 3, //diff in time with dtt as the unit
78
+ },
79
+ ],
80
+ data: [
81
+ //This is the data readings array
82
+ {
83
+ x: 1,
84
+ y: 0.5,
85
+ z: -0.2,
86
+ },
87
+ {
88
+ x: 1.4,
89
+ y: 3.5,
90
+ z: -0.2,
91
+ },
92
+ {
93
+ x: 0.1,
94
+ y: 0.2,
95
+ z: -1.2,
96
+ },
97
+ {
98
+ x: 0.8,
99
+ y: 0.2,
100
+ z: -0.9,
101
+ },
102
+ ],
103
+ },
104
+ ];
package/tsconfig.json ADDED
@@ -0,0 +1,19 @@
1
+ {
2
+ "extends": "../kit-build/tsconfig.json",
3
+ "compilerOptions": {
4
+ "rootDir": "./src",
5
+ "outDir": "./dist"
6
+ },
7
+ "exclude": ["**/*.test.ts", "**/*.mock.ts", "dist", "./src/generator.ts"],
8
+ "references": [
9
+ {
10
+ "path": "../kit-generator"
11
+ },
12
+ {
13
+ "path": "../kit-constants"
14
+ },
15
+ {
16
+ "path": "../kit-log"
17
+ }
18
+ ]
19
+ }