@synnaxlabs/x 0.42.1 → 0.43.0
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/.turbo/turbo-build.log +93 -105
- package/.vscode/settings.json +4 -6
- package/README.md +1 -7
- package/dist/array.cjs +1 -0
- package/dist/array.js +7 -0
- package/dist/base-B5lQIJKc.js +38 -0
- package/dist/base-CTq-lhpU.cjs +1 -0
- package/dist/binary.cjs +1 -1
- package/dist/binary.js +1 -1
- package/dist/bounds.cjs +1 -1
- package/dist/bounds.js +2 -2
- package/dist/box.cjs +1 -1
- package/dist/box.js +1 -1
- package/dist/caseconv.cjs +1 -1
- package/dist/caseconv.js +2 -2
- package/dist/change.cjs +1 -1
- package/dist/change.js +10 -2
- package/dist/compare.cjs +1 -1
- package/dist/compare.js +1 -1
- package/dist/deep.cjs +1 -1
- package/dist/deep.js +92 -79
- package/dist/dimensions.cjs +1 -1
- package/dist/dimensions.js +41 -2
- package/dist/direction.cjs +1 -1
- package/dist/direction.js +1 -1
- package/dist/index-4GlOgZuh.js +99 -0
- package/dist/{direction-C-b6XTeU.cjs → index-B58dnYRu.cjs} +1 -1
- package/dist/index-BMGaoK93.cjs +1 -0
- package/dist/index-BTet04Hd.cjs +6 -0
- package/dist/{scale-DfJe9755.js → index-BUa-NXAX.js} +46 -46
- package/dist/{xy-D_LqxaGt.js → index-C-qYOegc.js} +62 -62
- package/dist/index-C07SBJhr.js +128 -0
- package/dist/{bounds-Bn5_l4Z3.js → index-C9EdKeu1.js} +77 -76
- package/dist/index-CM8ZDZ6s.cjs +1 -0
- package/dist/index-CV2JaHfw.cjs +1 -0
- package/dist/index-CeBvOwG8.cjs +3 -0
- package/dist/index-ClrGyGDp.js +205 -0
- package/dist/index-CqQXXeCI.cjs +1 -0
- package/dist/{location-C3aeu046.js → index-D6V-8SKw.js} +26 -26
- package/dist/index-DBGAIs_7.js +2492 -0
- package/dist/index-DEdq2tza.cjs +1 -0
- package/dist/index-DKMnHBGR.cjs +1 -0
- package/dist/index-Dql5FMcH.js +47 -0
- package/dist/{direction-BL0PhD1k.js → index-DxU1zwsd.js} +1 -1
- package/dist/index-WwMnwoLy.cjs +1 -0
- package/dist/index.cjs +5 -3
- package/dist/index.js +5372 -649
- package/dist/kv.cjs +1 -1
- package/dist/kv.js +45 -2
- package/dist/location.cjs +1 -1
- package/dist/location.js +1 -1
- package/dist/position.cjs +1 -1
- package/dist/position.js +83 -2
- package/dist/record.cjs +1 -1
- package/dist/record.js +8 -10
- package/dist/runtime.cjs +1 -1
- package/dist/runtime.js +27 -2
- package/dist/scale.cjs +1 -1
- package/dist/scale.js +1 -1
- package/dist/schemas-55Usj0Fg.js +3998 -0
- package/dist/schemas-DbXuI2Qr.cjs +27 -0
- package/dist/spatial.cjs +1 -1
- package/dist/spatial.js +25 -18
- package/dist/src/array/index.d.ts +2 -0
- package/dist/src/array/index.d.ts.map +1 -0
- package/dist/src/array/toArray.d.ts +19 -0
- package/dist/src/array/toArray.d.ts.map +1 -0
- package/dist/src/array/toArray.spec.d.ts +2 -0
- package/dist/src/array/toArray.spec.d.ts.map +1 -0
- package/dist/src/binary/codec.d.ts +8 -16
- package/dist/src/binary/codec.d.ts.map +1 -1
- package/dist/src/breaker/breaker.d.ts +6 -6
- package/dist/src/breaker/breaker.d.ts.map +1 -1
- package/dist/src/caseconv/caseconv.d.ts +1 -1
- package/dist/src/caseconv/caseconv.d.ts.map +1 -1
- package/dist/src/change/change.d.ts +3 -3
- package/dist/src/change/change.d.ts.map +1 -1
- package/dist/src/color/color.d.ts +63 -28
- package/dist/src/color/color.d.ts.map +1 -1
- package/dist/src/color/external.d.ts +0 -1
- package/dist/src/color/external.d.ts.map +1 -1
- package/dist/src/color/gradient.d.ts +9 -5
- package/dist/src/color/gradient.d.ts.map +1 -1
- package/dist/src/color/palette.d.ts +14 -6
- package/dist/src/color/palette.d.ts.map +1 -1
- package/dist/src/compare/compare.d.ts +4 -4
- package/dist/src/compare/compare.d.ts.map +1 -1
- package/dist/src/control/control.d.ts +32 -32
- package/dist/src/control/control.d.ts.map +1 -1
- package/dist/src/debounce/debounce.d.ts +1 -1
- package/dist/src/debounce/debounce.d.ts.map +1 -1
- package/dist/src/deep/delete.d.ts +1 -1
- package/dist/src/deep/delete.d.ts.map +1 -1
- package/dist/src/deep/difference.d.ts.map +1 -1
- package/dist/src/deep/equal.d.ts +4 -4
- package/dist/src/deep/equal.d.ts.map +1 -1
- package/dist/src/deep/merge.d.ts +1 -1
- package/dist/src/deep/merge.d.ts.map +1 -1
- package/dist/src/errors/errors.d.ts +62 -36
- package/dist/src/errors/errors.d.ts.map +1 -1
- package/dist/src/index.d.ts +4 -1
- package/dist/src/index.d.ts.map +1 -1
- package/dist/src/instance/index.d.ts +2 -0
- package/dist/src/instance/index.d.ts.map +1 -0
- package/dist/src/instance/matcher.d.ts +79 -0
- package/dist/src/instance/matcher.d.ts.map +1 -0
- package/dist/src/instance/matcher.spec.d.ts +2 -0
- package/dist/src/instance/matcher.spec.d.ts.map +1 -0
- package/dist/src/jsonrpc/jsonrpc.d.ts +40 -9
- package/dist/src/jsonrpc/jsonrpc.d.ts.map +1 -1
- package/dist/src/kv/types.d.ts +2 -2
- package/dist/src/kv/types.d.ts.map +1 -1
- package/dist/src/migrate/migrate.d.ts +5 -5
- package/dist/src/migrate/migrate.d.ts.map +1 -1
- package/dist/src/notation/notation.d.ts +1 -1
- package/dist/src/notation/notation.d.ts.map +1 -1
- package/dist/src/primitive/index.d.ts +2 -0
- package/dist/src/primitive/index.d.ts.map +1 -0
- package/dist/src/primitive/primitive.d.ts +39 -0
- package/dist/src/primitive/primitive.d.ts.map +1 -0
- package/dist/src/primitive/primitive.spec.d.ts +2 -0
- package/dist/src/primitive/primitive.spec.d.ts.map +1 -0
- package/dist/src/record.d.ts +2 -2
- package/dist/src/record.d.ts.map +1 -1
- package/dist/src/renderable.d.ts +1 -1
- package/dist/src/renderable.d.ts.map +1 -1
- package/dist/src/replace.d.ts.map +1 -1
- package/dist/src/runtime/detect.d.ts.map +1 -1
- package/dist/src/runtime/os.d.ts +1 -1
- package/dist/src/runtime/os.d.ts.map +1 -1
- package/dist/src/spatial/base.d.ts +10 -10
- package/dist/src/spatial/base.d.ts.map +1 -1
- package/dist/src/spatial/bounds/bounds.d.ts +82 -16
- package/dist/src/spatial/bounds/bounds.d.ts.map +1 -1
- package/dist/src/spatial/box/box.d.ts +7 -7
- package/dist/src/spatial/box/box.d.ts.map +1 -1
- package/dist/src/spatial/dimensions/dimensions.d.ts +5 -5
- package/dist/src/spatial/dimensions/dimensions.d.ts.map +1 -1
- package/dist/src/spatial/direction/direction.d.ts +1 -1
- package/dist/src/spatial/location/location.d.ts +4 -4
- package/dist/src/spatial/location/location.d.ts.map +1 -1
- package/dist/src/spatial/scale/scale.d.ts +11 -11
- package/dist/src/spatial/scale/scale.d.ts.map +1 -1
- package/dist/src/spatial/xy/xy.d.ts +5 -5
- package/dist/src/spatial/xy/xy.d.ts.map +1 -1
- package/dist/src/status/index.d.ts +2 -0
- package/dist/src/status/index.d.ts.map +1 -0
- package/dist/src/status/types.d.ts +11 -0
- package/dist/src/status/types.d.ts.map +1 -0
- package/dist/src/sync/index.d.ts.map +1 -1
- package/dist/src/sync/mutex.d.ts +0 -1
- package/dist/src/sync/mutex.d.ts.map +1 -1
- package/dist/src/telem/gl.d.ts +1 -1
- package/dist/src/telem/gl.d.ts.map +1 -1
- package/dist/src/telem/series.d.ts +468 -62
- package/dist/src/telem/series.d.ts.map +1 -1
- package/dist/src/telem/telem.d.ts +243 -53
- package/dist/src/telem/telem.d.ts.map +1 -1
- package/dist/src/uuid/index.d.ts +2 -0
- package/dist/src/uuid/index.d.ts.map +1 -0
- package/dist/src/uuid/uuid.d.ts +35 -0
- package/dist/src/uuid/uuid.d.ts.map +1 -0
- package/dist/src/uuid/uuid.spec.d.ts +2 -0
- package/dist/src/uuid/uuid.spec.d.ts.map +1 -0
- package/dist/src/zod/external.d.ts +1 -1
- package/dist/src/zod/external.d.ts.map +1 -1
- package/dist/src/zod/nullToUndefined.d.ts +3 -0
- package/dist/src/zod/nullToUndefined.d.ts.map +1 -0
- package/dist/src/zod/nullToUndefined.spec.d.ts +2 -0
- package/dist/src/zod/nullToUndefined.spec.d.ts.map +1 -0
- package/dist/src/zod/util.d.ts +2 -2
- package/dist/src/zod/util.d.ts.map +1 -1
- package/dist/telem.cjs +1 -1
- package/dist/telem.js +1 -1
- package/dist/xy.cjs +1 -1
- package/dist/xy.js +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +19 -2
- package/eslint.config.js +1 -1
- package/package.json +16 -14
- package/src/{toArray.ts → array/index.ts} +1 -5
- package/src/array/toArray.spec.ts +56 -0
- package/src/array/toArray.ts +28 -0
- package/src/binary/codec.spec.ts +201 -278
- package/src/binary/codec.ts +20 -76
- package/src/breaker/breaker.ts +3 -3
- package/src/caseconv/caseconv.ts +6 -4
- package/src/change/change.ts +2 -2
- package/src/color/color.spec.ts +121 -2
- package/src/color/color.ts +90 -54
- package/src/color/external.ts +0 -1
- package/src/color/gradient.ts +20 -28
- package/src/color/palette.ts +1 -1
- package/src/compare/compare.ts +5 -5
- package/src/control/control.ts +22 -19
- package/src/debounce/debounce.ts +1 -1
- package/src/deep/delete.ts +5 -4
- package/src/deep/difference.ts +6 -2
- package/src/deep/equal.spec.ts +1 -1
- package/src/deep/equal.ts +5 -5
- package/src/deep/merge.spec.ts +13 -1
- package/src/deep/merge.ts +16 -7
- package/src/deep/path.ts +1 -1
- package/src/errors/errors.ts +65 -44
- package/src/index.ts +4 -1
- package/src/instance/index.ts +10 -0
- package/src/instance/matcher.spec.ts +78 -0
- package/src/instance/matcher.ts +98 -0
- package/src/jsonrpc/jsonrpc.spec.ts +2 -1
- package/src/jsonrpc/jsonrpc.ts +36 -7
- package/src/kv/types.ts +1 -1
- package/src/migrate/migrate.spec.ts +1 -1
- package/src/migrate/migrate.ts +7 -7
- package/src/notation/notation.ts +1 -1
- package/src/primitive/index.ts +10 -0
- package/src/primitive/primitive.spec.ts +126 -0
- package/src/primitive/primitive.ts +82 -0
- package/src/record.ts +3 -5
- package/src/renderable.ts +1 -1
- package/src/replace.ts +9 -0
- package/src/runtime/detect.ts +0 -2
- package/src/runtime/os.ts +1 -1
- package/src/spatial/base.ts +1 -1
- package/src/spatial/bounds/bounds.spec.ts +20 -0
- package/src/spatial/bounds/bounds.ts +101 -18
- package/src/spatial/box/box.ts +1 -1
- package/src/spatial/dimensions/dimensions.ts +3 -3
- package/src/spatial/location/location.ts +1 -1
- package/src/spatial/scale/scale.ts +1 -1
- package/src/spatial/xy/xy.ts +1 -1
- package/src/status/index.ts +10 -0
- package/src/status/types.ts +22 -0
- package/src/sync/index.ts +9 -0
- package/src/sync/mutex.ts +9 -4
- package/src/telem/gl.ts +1 -1
- package/src/telem/series.spec.ts +735 -68
- package/src/telem/series.ts +536 -195
- package/src/telem/telem.spec.ts +60 -7
- package/src/telem/telem.ts +287 -95
- package/src/uuid/index.ts +10 -0
- package/src/uuid/uuid.spec.ts +82 -0
- package/src/uuid/uuid.ts +48 -0
- package/src/zod/external.ts +1 -1
- package/src/zod/nullToUndefined.spec.ts +31 -0
- package/src/zod/nullToUndefined.ts +23 -0
- package/src/zod/util.spec.ts +1 -1
- package/src/zod/util.ts +6 -6
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.config.ts +1 -1
- package/dist/base-BAM2mqCy.cjs +0 -1
- package/dist/base-DFq0vvGn.js +0 -38
- package/dist/bounds-BQo7rvs9.cjs +0 -1
- package/dist/box-0YrQibkB.cjs +0 -1
- package/dist/box-Cc8IzcNo.js +0 -205
- package/dist/change-C-YELKx6.cjs +0 -1
- package/dist/change-DLl6DccR.js +0 -12
- package/dist/dimensions-CRgergMS.js +0 -43
- package/dist/dimensions-D2QGoNXO.cjs +0 -1
- package/dist/external-BPgtxa8d.js +0 -29
- package/dist/external-C-dNgNQw.cjs +0 -1
- package/dist/external-C8TFju8Q.js +0 -29
- package/dist/external-DWQITF5_.cjs +0 -1
- package/dist/external-DqPrWKvU.js +0 -47
- package/dist/external-uXk0Avrg.cjs +0 -1
- package/dist/index-BywOGO8U.js +0 -1074
- package/dist/index-CYYjI7Uf.cjs +0 -1
- package/dist/index-C_6NXBlg.cjs +0 -3
- package/dist/index-Dd8DLyMx.cjs +0 -1
- package/dist/index-DizUWH6z.js +0 -47
- package/dist/index-QGplUHuy.js +0 -98
- package/dist/location-BGl5Ddds.cjs +0 -1
- package/dist/position-Cai5-wi1.cjs +0 -1
- package/dist/position-DIglP1l2.js +0 -85
- package/dist/scale-BtZINJ-A.cjs +0 -1
- package/dist/series-B9JERcqi.js +0 -1977
- package/dist/series-DqJ6f97G.cjs +0 -11
- package/dist/spatial-BSWPzMkK.js +0 -11
- package/dist/spatial-DGpZ2sO3.cjs +0 -1
- package/dist/src/color/transformColorsToHex.d.ts +0 -6
- package/dist/src/color/transformColorsToHex.d.ts.map +0 -1
- package/dist/src/primitive.d.ts +0 -9
- package/dist/src/primitive.d.ts.map +0 -1
- package/dist/src/toArray.d.ts +0 -3
- package/dist/src/toArray.d.ts.map +0 -1
- package/dist/src/zod/integer.d.ts +0 -10
- package/dist/src/zod/integer.d.ts.map +0 -1
- package/dist/src/zod/integer.spec.d.ts +0 -2
- package/dist/src/zod/integer.spec.d.ts.map +0 -1
- package/dist/toArray.cjs +0 -1
- package/dist/toArray.js +0 -5
- package/dist/xy-B7065J2S.cjs +0 -1
- package/src/color/transformColorsToHex.ts +0 -30
- package/src/primitive.ts +0 -46
- package/src/zod/integer.spec.ts +0 -148
- package/src/zod/integer.ts +0 -38
package/src/binary/codec.spec.ts
CHANGED
|
@@ -8,363 +8,286 @@
|
|
|
8
8
|
// included in the file licenses/APL.txt.
|
|
9
9
|
|
|
10
10
|
import { describe, expect, it } from "vitest";
|
|
11
|
-
import { z } from "zod";
|
|
11
|
+
import { z } from "zod/v4";
|
|
12
12
|
|
|
13
13
|
import { binary } from "@/binary";
|
|
14
|
-
import { JSON_CODEC, MSGPACK_CODEC } from "@/binary/codec";
|
|
15
14
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
15
|
+
describe("Codec", () => {
|
|
16
|
+
const sampleSchema = z.object({
|
|
17
|
+
channelKey: z.string(),
|
|
18
|
+
timeStamp: z.number(),
|
|
19
|
+
value: z.unknown(),
|
|
20
|
+
});
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
22
|
+
binary.ENCODERS.forEach((e) => {
|
|
23
|
+
describe(`encoder ${e.contentType}`, () => {
|
|
24
|
+
it("should correctly encode and decode items", () => {
|
|
25
|
+
const sample = {
|
|
26
|
+
channelKey: "test",
|
|
27
|
+
timeStamp: 123,
|
|
28
|
+
value: [1, 2, 3],
|
|
29
|
+
};
|
|
30
|
+
const encoded = e.encode(sample);
|
|
31
|
+
expect(e.decode(encoded, sampleSchema)).toEqual(sample);
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("JSON", () => {
|
|
37
|
+
it("should correctly convert keys to snake case", () => {
|
|
25
38
|
const sample = {
|
|
26
39
|
channelKey: "test",
|
|
27
40
|
timeStamp: 123,
|
|
28
|
-
value: [1, 2, 3],
|
|
41
|
+
value: new Array([1, 2, 3]),
|
|
29
42
|
};
|
|
30
|
-
const encoded =
|
|
31
|
-
|
|
43
|
+
const encoded = binary.JSON_CODEC.encodeString(sample);
|
|
44
|
+
const parse = JSON.parse(encoded);
|
|
45
|
+
expect(parse.channel_key).toEqual("test");
|
|
32
46
|
});
|
|
33
|
-
});
|
|
34
|
-
});
|
|
35
47
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
});
|
|
47
|
-
it("should correctly decode keys from snake case", () => {
|
|
48
|
-
const sample = {
|
|
49
|
-
channel_key: "test",
|
|
50
|
-
time_stamp: 123,
|
|
51
|
-
value: new Array([1, 2, 3]),
|
|
52
|
-
};
|
|
53
|
-
const encoded = JSON.stringify(sample);
|
|
54
|
-
const decoded = binary.JSON_CODEC.decodeString(encoded, sampleSchema);
|
|
55
|
-
expect(decoded.channelKey).toEqual("test");
|
|
48
|
+
it("should correctly decode keys from snake case", () => {
|
|
49
|
+
const sample = {
|
|
50
|
+
channel_key: "test",
|
|
51
|
+
time_stamp: 123,
|
|
52
|
+
value: new Array([1, 2, 3]),
|
|
53
|
+
};
|
|
54
|
+
const encoded = JSON.stringify(sample);
|
|
55
|
+
const decoded = binary.JSON_CODEC.decodeString(encoded, sampleSchema);
|
|
56
|
+
expect(decoded.channelKey).toEqual("test");
|
|
57
|
+
});
|
|
56
58
|
});
|
|
57
|
-
});
|
|
58
59
|
|
|
59
|
-
describe("CSV", () => {
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
describe("CSV", () => {
|
|
61
|
+
it("should correctly decode CSV data with valid input", () => {
|
|
62
|
+
const sample = `
|
|
62
63
|
channelKey,timeStamp,value
|
|
63
64
|
test,123,5
|
|
64
65
|
test2,124,6
|
|
65
66
|
`;
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
67
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
68
|
+
expect(decoded).toEqual({
|
|
69
|
+
channelKey: ["test", "test2"],
|
|
70
|
+
timeStamp: [123, 124],
|
|
71
|
+
value: [5, 6],
|
|
72
|
+
});
|
|
71
73
|
});
|
|
72
|
-
});
|
|
73
74
|
|
|
74
|
-
|
|
75
|
-
|
|
75
|
+
it("should handle empty CSV data", () => {
|
|
76
|
+
const sample = `
|
|
76
77
|
`;
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
79
|
+
expect(decoded).toEqual({});
|
|
80
|
+
});
|
|
80
81
|
|
|
81
|
-
|
|
82
|
-
|
|
82
|
+
it("should handle CSV with only headers", () => {
|
|
83
|
+
const sample = `
|
|
83
84
|
channelKey,timeStamp,value
|
|
84
85
|
`;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
86
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
87
|
+
expect(decoded).toEqual({
|
|
88
|
+
channelKey: [],
|
|
89
|
+
timeStamp: [],
|
|
90
|
+
value: [],
|
|
91
|
+
});
|
|
90
92
|
});
|
|
91
|
-
});
|
|
92
93
|
|
|
93
|
-
|
|
94
|
-
|
|
94
|
+
it("should handle CSV with missing values", () => {
|
|
95
|
+
const sample = `
|
|
95
96
|
channelKey,timeStamp,value
|
|
96
97
|
test,123,
|
|
97
98
|
test2,124,6
|
|
98
99
|
`;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
101
|
+
expect(decoded).toEqual({
|
|
102
|
+
channelKey: ["test", "test2"],
|
|
103
|
+
timeStamp: [123, 124],
|
|
104
|
+
value: [6],
|
|
105
|
+
});
|
|
104
106
|
});
|
|
105
|
-
});
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
108
|
+
it("should handle CSV with extra values", () => {
|
|
109
|
+
const sample = `
|
|
109
110
|
channelKey,timeStamp,value
|
|
110
111
|
test,123,5,extra
|
|
111
112
|
test2,124,6
|
|
112
113
|
`;
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
114
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
115
|
+
expect(decoded).toEqual({
|
|
116
|
+
channelKey: ["test", "test2"],
|
|
117
|
+
timeStamp: [123, 124],
|
|
118
|
+
value: [5, 6],
|
|
119
|
+
});
|
|
118
120
|
});
|
|
119
|
-
});
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
122
|
+
it("should handle CSV with different types of values", () => {
|
|
123
|
+
const sample = `
|
|
123
124
|
key,number,string
|
|
124
125
|
test,123,"hello"
|
|
125
126
|
test2,456,"world"
|
|
126
127
|
`;
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
128
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
129
|
+
expect(decoded).toEqual({
|
|
130
|
+
key: ["test", "test2"],
|
|
131
|
+
number: [123, 456],
|
|
132
|
+
string: ["hello", "world"],
|
|
133
|
+
});
|
|
132
134
|
});
|
|
133
|
-
});
|
|
134
135
|
|
|
135
|
-
|
|
136
|
-
|
|
136
|
+
it("should handle CSV with spaces around values", () => {
|
|
137
|
+
const sample = `
|
|
137
138
|
key, number , string
|
|
138
139
|
test , 123 , "hello"
|
|
139
140
|
test2 , 456 , "world"
|
|
140
141
|
`;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
142
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
143
|
+
expect(decoded).toEqual({
|
|
144
|
+
key: ["test", "test2"],
|
|
145
|
+
number: [123, 456],
|
|
146
|
+
string: ["hello", "world"],
|
|
147
|
+
});
|
|
146
148
|
});
|
|
147
|
-
});
|
|
148
149
|
|
|
149
|
-
|
|
150
|
-
|
|
150
|
+
it("should handle CSV with empty rows", () => {
|
|
151
|
+
const sample = `
|
|
151
152
|
key,number,string
|
|
152
153
|
test,123,"hello"
|
|
153
154
|
,
|
|
154
155
|
test2,456,"world"
|
|
155
156
|
`;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
157
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
158
|
+
expect(decoded).toEqual({
|
|
159
|
+
key: ["test", "test2"],
|
|
160
|
+
number: [123, 456],
|
|
161
|
+
string: ["hello", "world"],
|
|
162
|
+
});
|
|
161
163
|
});
|
|
162
|
-
});
|
|
163
164
|
|
|
164
|
-
|
|
165
|
-
|
|
165
|
+
it("should handle CSV with single column", () => {
|
|
166
|
+
const sample = `
|
|
166
167
|
key
|
|
167
168
|
test
|
|
168
169
|
test2
|
|
169
170
|
`;
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
171
|
+
const decoded = binary.CSV_CODEC.decodeString(sample);
|
|
172
|
+
expect(decoded).toEqual({
|
|
173
|
+
key: ["test", "test2"],
|
|
174
|
+
});
|
|
173
175
|
});
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should correctly encode array of objects to CSV", () => {
|
|
177
|
-
const sampleData = [
|
|
178
|
-
{ name: "John", age: 30, city: "New York" },
|
|
179
|
-
{ name: "Alice", age: 25, city: "Boston" },
|
|
180
|
-
{ name: "Bob", age: 40, city: "Chicago" },
|
|
181
|
-
];
|
|
182
|
-
|
|
183
|
-
const encoded = binary.CSV_CODEC.encodeString(sampleData);
|
|
184
|
-
expect(encoded).toBe(
|
|
185
|
-
'name,age,city\n"John",30,"New York"\n"Alice",25,"Boston"\n"Bob",40,"Chicago"',
|
|
186
|
-
);
|
|
187
|
-
});
|
|
188
176
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
it("should handle objects with null and undefined values", () => {
|
|
203
|
-
const sampleData = [
|
|
204
|
-
{ name: "John", age: null, city: undefined },
|
|
205
|
-
{ name: "Alice", age: 25, city: null },
|
|
206
|
-
];
|
|
207
|
-
|
|
208
|
-
const encoded = binary.CSV_CODEC.encodeString(sampleData);
|
|
209
|
-
expect(encoded).toBe('name,age,city\n"John","",""\n"Alice",25,""');
|
|
210
|
-
});
|
|
177
|
+
it("should correctly encode array of objects to CSV", () => {
|
|
178
|
+
const sampleData = [
|
|
179
|
+
{ name: "John", age: 30, city: "New York" },
|
|
180
|
+
{ name: "Alice", age: 25, city: "Boston" },
|
|
181
|
+
{ name: "Bob", age: 40, city: "Chicago" },
|
|
182
|
+
];
|
|
183
|
+
|
|
184
|
+
const encoded = binary.CSV_CODEC.encodeString(sampleData);
|
|
185
|
+
expect(encoded).toBe(
|
|
186
|
+
'name,age,city\n"John",30,"New York"\n"Alice",25,"Boston"\n"Bob",40,"Chicago"',
|
|
187
|
+
);
|
|
188
|
+
});
|
|
211
189
|
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
190
|
+
it("should handle objects with missing values", () => {
|
|
191
|
+
const sampleData = [
|
|
192
|
+
{ name: "John", age: 30, city: "New York" },
|
|
193
|
+
{ name: "Alice", age: 25 },
|
|
194
|
+
{ name: "Bob", city: "Chicago" },
|
|
195
|
+
];
|
|
196
|
+
|
|
197
|
+
const encoded = binary.CSV_CODEC.encodeString(sampleData);
|
|
198
|
+
expect(encoded).toBe(
|
|
199
|
+
'name,age,city\n"John",30,"New York"\n"Alice",25,""\n"Bob","","Chicago"',
|
|
200
|
+
);
|
|
201
|
+
});
|
|
217
202
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
203
|
+
it("should handle objects with null and undefined values", () => {
|
|
204
|
+
const sampleData = [
|
|
205
|
+
{ name: "John", age: null, city: undefined },
|
|
206
|
+
{ name: "Alice", age: 25, city: null },
|
|
207
|
+
];
|
|
221
208
|
|
|
222
|
-
|
|
223
|
-
|
|
209
|
+
const encoded = binary.CSV_CODEC.encodeString(sampleData);
|
|
210
|
+
expect(encoded).toBe('name,age,city\n"John","",""\n"Alice",25,""');
|
|
211
|
+
});
|
|
224
212
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
213
|
+
it("should handle different data types in objects", () => {
|
|
214
|
+
const sampleData = [
|
|
215
|
+
{ name: "John", active: true, score: 98.5 },
|
|
216
|
+
{ name: "Alice", active: false, score: 92.3 },
|
|
217
|
+
];
|
|
229
218
|
|
|
230
|
-
|
|
231
|
-
|
|
219
|
+
const encoded = binary.CSV_CODEC.encodeString(sampleData);
|
|
220
|
+
expect(encoded).toBe('name,active,score\n"John",true,98.5\n"Alice",false,92.3');
|
|
221
|
+
});
|
|
232
222
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}).toThrow("Payload must be an array of objects");
|
|
236
|
-
});
|
|
223
|
+
it("should throw error when encoding empty array", () => {
|
|
224
|
+
const sampleData: unknown[] = [];
|
|
237
225
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
];
|
|
226
|
+
expect(() => {
|
|
227
|
+
binary.CSV_CODEC.encodeString(sampleData);
|
|
228
|
+
}).toThrow("Payload must be an array of objects");
|
|
229
|
+
});
|
|
243
230
|
|
|
244
|
-
|
|
245
|
-
|
|
231
|
+
it("should throw error when encoding non-array data", () => {
|
|
232
|
+
const sampleData = { name: "John", age: 30 };
|
|
246
233
|
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
city: ["New York", "Boston"],
|
|
234
|
+
expect(() => {
|
|
235
|
+
binary.CSV_CODEC.encodeString(sampleData);
|
|
236
|
+
}).toThrow("Payload must be an array of objects");
|
|
251
237
|
});
|
|
252
|
-
});
|
|
253
|
-
});
|
|
254
238
|
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
value: [1, 2, 3],
|
|
261
|
-
};
|
|
262
|
-
const encoded = binary.MSGPACK_CODEC.encode(sample);
|
|
263
|
-
const decoded = binary.MSGPACK_CODEC.decode(encoded);
|
|
264
|
-
expect(decoded).toEqual(sample);
|
|
265
|
-
});
|
|
239
|
+
it("should round-trip encode and decode CSV data", () => {
|
|
240
|
+
const sampleData = [
|
|
241
|
+
{ name: "John", age: 30, city: "New York" },
|
|
242
|
+
{ name: "Alice", age: 25, city: "Boston" },
|
|
243
|
+
];
|
|
266
244
|
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
channelKey: "test",
|
|
270
|
-
timeStamp: 123,
|
|
271
|
-
value: [1, 2, 3],
|
|
272
|
-
};
|
|
273
|
-
const encoded = binary.MSGPACK_CODEC.encode(sample);
|
|
274
|
-
const decoded = binary.MSGPACK_CODEC.decode(encoded, sampleSchema);
|
|
275
|
-
expect(decoded).toEqual(sample);
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
it("should handle complex nested objects", () => {
|
|
279
|
-
const sample = {
|
|
280
|
-
channelKey: "test",
|
|
281
|
-
timeStamp: 123,
|
|
282
|
-
nestedObject: {
|
|
283
|
-
innerKey: "value",
|
|
284
|
-
numberArray: [1, 2, 3],
|
|
285
|
-
deepNesting: {
|
|
286
|
-
anotherKey: true,
|
|
287
|
-
},
|
|
288
|
-
},
|
|
289
|
-
};
|
|
290
|
-
const encoded = binary.MSGPACK_CODEC.encode(sample);
|
|
291
|
-
const decoded = binary.MSGPACK_CODEC.decode(encoded);
|
|
292
|
-
expect(decoded).toEqual(sample);
|
|
293
|
-
});
|
|
245
|
+
const encoded = binary.CSV_CODEC.encode(sampleData);
|
|
246
|
+
const decoded = binary.CSV_CODEC.decode(encoded);
|
|
294
247
|
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
};
|
|
302
|
-
const encoded = binary.MSGPACK_CODEC.encode(sample);
|
|
303
|
-
const decoded = binary.MSGPACK_CODEC.decode<typeof sampleSchema>(encoded);
|
|
304
|
-
|
|
305
|
-
// Check that the structure is preserved
|
|
306
|
-
expect(decoded.channelKey).toEqual(sample.channelKey);
|
|
307
|
-
expect(decoded.timeStamp).toEqual(sample.timeStamp);
|
|
308
|
-
|
|
309
|
-
// Verify that binary data is handled properly
|
|
310
|
-
// Note: The exact format might depend on msgpack implementation
|
|
311
|
-
expect(
|
|
312
|
-
Array.isArray(decoded.value) || ArrayBuffer.isView(decoded.value),
|
|
313
|
-
).toBeTruthy();
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
class CustomValueEncoder {
|
|
317
|
-
readonly encodeValue = true;
|
|
318
|
-
|
|
319
|
-
value = "cat";
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
it("should correctly encode and decode custom value", () => {
|
|
323
|
-
const sample = {
|
|
324
|
-
channelKey: "test",
|
|
325
|
-
timeStamp: 123,
|
|
326
|
-
value: new CustomValueEncoder(),
|
|
327
|
-
};
|
|
328
|
-
const encoded = binary.MSGPACK_CODEC.encode(sample);
|
|
329
|
-
const decoded = binary.MSGPACK_CODEC.decode(encoded, sampleSchema);
|
|
330
|
-
expect(decoded).toEqual({ ...sample, value: "cat" });
|
|
248
|
+
expect(decoded).toEqual({
|
|
249
|
+
name: ["John", "Alice"],
|
|
250
|
+
age: [30, 25],
|
|
251
|
+
city: ["New York", "Boston"],
|
|
252
|
+
});
|
|
253
|
+
});
|
|
331
254
|
});
|
|
332
|
-
});
|
|
333
255
|
|
|
334
|
-
describe("
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
256
|
+
describe("Text", () => {
|
|
257
|
+
it("should correctly encode and decode text", () => {
|
|
258
|
+
const sampleText = "Hello, world!";
|
|
259
|
+
const encoded = binary.TEXT_CODEC.encode(sampleText);
|
|
260
|
+
const decoded = binary.TEXT_CODEC.decode(encoded);
|
|
261
|
+
expect(decoded).toEqual(sampleText);
|
|
262
|
+
});
|
|
341
263
|
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
264
|
+
it("should handle empty strings", () => {
|
|
265
|
+
const sampleText = "";
|
|
266
|
+
const encoded = binary.TEXT_CODEC.encode(sampleText);
|
|
267
|
+
const decoded = binary.TEXT_CODEC.decode(encoded);
|
|
268
|
+
expect(decoded).toEqual(sampleText);
|
|
269
|
+
});
|
|
348
270
|
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
271
|
+
it("should validate text with schema", () => {
|
|
272
|
+
const textSchema = z.string();
|
|
273
|
+
const sampleText = "Validation test";
|
|
274
|
+
const encoded = binary.TEXT_CODEC.encode(sampleText);
|
|
275
|
+
const decoded = binary.TEXT_CODEC.decode(encoded, textSchema);
|
|
276
|
+
expect(decoded).toEqual(sampleText);
|
|
277
|
+
});
|
|
356
278
|
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
279
|
+
it("should handle special characters", () => {
|
|
280
|
+
const sampleText = "Special characters: äöü!@#$%^&*()_+";
|
|
281
|
+
const encoded = binary.TEXT_CODEC.encode(sampleText);
|
|
282
|
+
const decoded = binary.TEXT_CODEC.decode(encoded);
|
|
283
|
+
expect(decoded).toEqual(sampleText);
|
|
284
|
+
});
|
|
363
285
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
286
|
+
it("should handle multi-line text", () => {
|
|
287
|
+
const sampleText = "Line 1\nLine 2\nLine 3";
|
|
288
|
+
const encoded = binary.TEXT_CODEC.encode(sampleText);
|
|
289
|
+
const decoded = binary.TEXT_CODEC.decode(encoded);
|
|
290
|
+
expect(decoded).toEqual(sampleText);
|
|
291
|
+
});
|
|
369
292
|
});
|
|
370
293
|
});
|