@synnaxlabs/x 0.44.2 → 0.44.4

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.
Files changed (131) hide show
  1. package/.turbo/turbo-build.log +35 -39
  2. package/dist/base-BLNViP3D.cjs +1 -0
  3. package/dist/{base-DFq0vvGn.js → base-BORMP3mH.js} +14 -11
  4. package/dist/bounds-BQqppNFf.js +186 -0
  5. package/dist/bounds-BXbqBINt.cjs +1 -0
  6. package/dist/bounds.cjs +1 -1
  7. package/dist/bounds.js +1 -1
  8. package/dist/{box-CO_2_DGG.js → box-DRH5SOaY.js} +67 -73
  9. package/dist/box-qgxWXNhm.cjs +1 -0
  10. package/dist/box.cjs +1 -1
  11. package/dist/box.js +1 -1
  12. package/dist/deep.cjs +1 -1
  13. package/dist/deep.js +1 -1
  14. package/dist/{dimensions-CRgergMS.js → dimensions-RaRkesPq.js} +1 -1
  15. package/dist/{dimensions-D2QGoNXO.cjs → dimensions-qY12pyfC.cjs} +1 -1
  16. package/dist/dimensions.cjs +1 -1
  17. package/dist/dimensions.js +1 -1
  18. package/dist/direction-DKdfJwj7.js +19 -0
  19. package/dist/direction-XCdrc4is.cjs +1 -0
  20. package/dist/direction.cjs +1 -1
  21. package/dist/direction.js +1 -1
  22. package/dist/{external-Birv9jaY.js → external-BM_NS5yM.js} +6 -6
  23. package/dist/external-E3ErJeeM.cjs +1 -0
  24. package/dist/index.cjs +3 -3
  25. package/dist/index.js +244 -240
  26. package/dist/{location-Ar5y2DX2.js → location-CGLioInQ.js} +16 -21
  27. package/dist/location-DJ_K4SlP.cjs +1 -0
  28. package/dist/location.cjs +1 -1
  29. package/dist/location.js +1 -1
  30. package/dist/{path-DVFrKaNI.js → path-Blh4wJuA.js} +24 -21
  31. package/dist/path-CPSfCjde.cjs +1 -0
  32. package/dist/record-BwjIgrpU.cjs +1 -0
  33. package/dist/record-tSFQKmdG.js +19 -0
  34. package/dist/record.cjs +1 -1
  35. package/dist/record.js +1 -1
  36. package/dist/{scale-C6qKDbRb.cjs → scale-76Azh2EE.cjs} +1 -1
  37. package/dist/{scale-EWNUk-bn.js → scale-BhIvACdB.js} +4 -4
  38. package/dist/scale.cjs +1 -1
  39. package/dist/scale.js +1 -1
  40. package/dist/{series-EA1uaEDj.js → series-kgnLXSDr.js} +622 -489
  41. package/dist/series-tAhThbnz.cjs +6 -0
  42. package/dist/{spatial-DGpZ2sO3.cjs → spatial-BsGadoUr.cjs} +1 -1
  43. package/dist/{spatial-BSWPzMkK.js → spatial-QY891r0E.js} +1 -1
  44. package/dist/spatial.cjs +1 -1
  45. package/dist/spatial.js +14 -16
  46. package/dist/src/breaker/breaker.d.ts +2 -1
  47. package/dist/src/breaker/breaker.d.ts.map +1 -1
  48. package/dist/src/deep/path.d.ts.map +1 -1
  49. package/dist/src/id/id.d.ts +3 -1
  50. package/dist/src/id/id.d.ts.map +1 -1
  51. package/dist/src/math/math.d.ts +2 -1
  52. package/dist/src/math/math.d.ts.map +1 -1
  53. package/dist/src/record/record.d.ts +18 -0
  54. package/dist/src/record/record.d.ts.map +1 -1
  55. package/dist/src/spatial/base.d.ts +12 -0
  56. package/dist/src/spatial/base.d.ts.map +1 -1
  57. package/dist/src/spatial/direction/direction.d.ts +5 -1
  58. package/dist/src/spatial/direction/direction.d.ts.map +1 -1
  59. package/dist/src/spatial/external.d.ts +0 -1
  60. package/dist/src/spatial/external.d.ts.map +1 -1
  61. package/dist/src/spatial/xy/xy.d.ts +3 -0
  62. package/dist/src/spatial/xy/xy.d.ts.map +1 -1
  63. package/dist/src/status/status.d.ts +1 -0
  64. package/dist/src/status/status.d.ts.map +1 -1
  65. package/dist/src/strings/strings.d.ts +1 -1
  66. package/dist/src/strings/strings.d.ts.map +1 -1
  67. package/dist/src/telem/series.d.ts +7 -0
  68. package/dist/src/telem/series.d.ts.map +1 -1
  69. package/dist/src/telem/telem.d.ts +86 -1
  70. package/dist/src/telem/telem.d.ts.map +1 -1
  71. package/dist/src/zod/util.d.ts.map +1 -1
  72. package/dist/telem.cjs +1 -1
  73. package/dist/telem.js +1 -1
  74. package/dist/xy-BKIJiLu_.cjs +1 -0
  75. package/dist/{xy-C_-hb3Q2.js → xy-CBuhMaIo.js} +41 -31
  76. package/dist/xy.cjs +1 -1
  77. package/dist/xy.js +1 -1
  78. package/dist/zod.cjs +1 -1
  79. package/dist/zod.js +1 -1
  80. package/package.json +3 -8
  81. package/src/breaker/breaker.ts +4 -0
  82. package/src/deep/path.spec.ts +14 -0
  83. package/src/deep/path.ts +9 -2
  84. package/src/id/id.ts +8 -4
  85. package/src/math/math.spec.ts +20 -0
  86. package/src/math/math.ts +32 -29
  87. package/src/record/record.spec.ts +31 -0
  88. package/src/record/record.ts +23 -0
  89. package/src/spatial/base.ts +4 -0
  90. package/src/spatial/bounds/bounds.ts +1 -1
  91. package/src/spatial/direction/direction.spec.ts +35 -1
  92. package/src/spatial/direction/direction.ts +12 -0
  93. package/src/spatial/external.ts +0 -1
  94. package/src/spatial/xy/xy.spec.ts +124 -7
  95. package/src/spatial/xy/xy.ts +15 -2
  96. package/src/status/status.ts +11 -0
  97. package/src/strings/strings.spec.ts +3 -0
  98. package/src/strings/strings.ts +2 -1
  99. package/src/telem/series.spec.ts +543 -2
  100. package/src/telem/series.ts +28 -9
  101. package/src/telem/telem.spec.ts +606 -0
  102. package/src/telem/telem.ts +143 -5
  103. package/src/zod/util.ts +5 -3
  104. package/tsconfig.tsbuildinfo +1 -1
  105. package/vite.config.ts +0 -1
  106. package/dist/base-BAM2mqCy.cjs +0 -1
  107. package/dist/bounds-D6e9xoHt.cjs +0 -1
  108. package/dist/bounds-Dj9nG39I.js +0 -174
  109. package/dist/box-Cxki783Y.cjs +0 -1
  110. package/dist/direction-386XDm2w.cjs +0 -1
  111. package/dist/direction-8etxfKaR.js +0 -17
  112. package/dist/external-DsmsSN1Y.cjs +0 -1
  113. package/dist/location-DZi8ftXp.cjs +0 -1
  114. package/dist/path-BeMr8xWN.cjs +0 -1
  115. package/dist/position-DSy2hONH.cjs +0 -1
  116. package/dist/position-PQ6op54I.js +0 -85
  117. package/dist/position.cjs +0 -1
  118. package/dist/position.js +0 -4
  119. package/dist/record-CAcQ5PNX.js +0 -14
  120. package/dist/record-YvCh7bzB.cjs +0 -1
  121. package/dist/series-CcA_WjbJ.cjs +0 -6
  122. package/dist/src/spatial/position/index.d.ts +0 -2
  123. package/dist/src/spatial/position/index.d.ts.map +0 -1
  124. package/dist/src/spatial/position/position.d.ts +0 -20
  125. package/dist/src/spatial/position/position.d.ts.map +0 -1
  126. package/dist/src/spatial/position/position.spec.d.ts +0 -2
  127. package/dist/src/spatial/position/position.spec.d.ts.map +0 -1
  128. package/dist/xy-CUE3QDNn.cjs +0 -1
  129. package/src/spatial/position/index.ts +0 -10
  130. package/src/spatial/position/position.spec.ts +0 -211
  131. package/src/spatial/position/position.ts +0 -157
@@ -251,6 +251,50 @@ describe("TimeStamp", () => {
251
251
  expect(ts.sub(TimeSpan.microseconds()).equals(new TimeStamp(0))).toBe(true);
252
252
  });
253
253
 
254
+ describe("arithmetic operations", () => {
255
+ test("add with TimeSpan", () => {
256
+ const ts = new TimeStamp(1000);
257
+ const result = ts.add(TimeSpan.microseconds(500));
258
+ expect(result).toBeInstanceOf(TimeStamp);
259
+ expect(result.valueOf()).toBe(501000n);
260
+ });
261
+
262
+ test("add with number", () => {
263
+ const ts = new TimeStamp(1000);
264
+ const result = ts.add(500);
265
+ expect(result).toBeInstanceOf(TimeStamp);
266
+ expect(result.valueOf()).toBe(1500n);
267
+ });
268
+
269
+ test("add with bigint", () => {
270
+ const ts = new TimeStamp(1000n);
271
+ const result = ts.add(500n);
272
+ expect(result).toBeInstanceOf(TimeStamp);
273
+ expect(result.valueOf()).toBe(1500n);
274
+ });
275
+
276
+ test("sub with TimeSpan", () => {
277
+ const ts = new TimeStamp(1000);
278
+ const result = ts.sub(TimeSpan.nanoseconds(300));
279
+ expect(result).toBeInstanceOf(TimeStamp);
280
+ expect(result.valueOf()).toBe(700n);
281
+ });
282
+
283
+ test("sub with number", () => {
284
+ const ts = new TimeStamp(1000);
285
+ const result = ts.sub(300);
286
+ expect(result).toBeInstanceOf(TimeStamp);
287
+ expect(result.valueOf()).toBe(700n);
288
+ });
289
+
290
+ test("sub with bigint", () => {
291
+ const ts = new TimeStamp(1000n);
292
+ const result = ts.sub(300n);
293
+ expect(result).toBeInstanceOf(TimeStamp);
294
+ expect(result.valueOf()).toBe(700n);
295
+ });
296
+ });
297
+
254
298
  describe("fString", () => {
255
299
  const ts = new TimeStamp([2022, 12, 15], "UTC")
256
300
  .add(TimeSpan.hours(12))
@@ -508,6 +552,94 @@ describe("TimeSpan", () => {
508
552
  expect(TimeSpan.seconds(1).sub(TimeSpan.SECOND).isZero).toBe(true);
509
553
  });
510
554
 
555
+ describe("arithmetic operations", () => {
556
+ test("add with TimeSpan", () => {
557
+ const ts1 = new TimeSpan(1000);
558
+ const ts2 = new TimeSpan(500);
559
+ const result = ts1.add(ts2);
560
+ expect(result).toBeInstanceOf(TimeSpan);
561
+ expect(result.valueOf()).toBe(1500n);
562
+ });
563
+
564
+ test("add with number", () => {
565
+ const ts = new TimeSpan(1000);
566
+ const result = ts.add(500);
567
+ expect(result).toBeInstanceOf(TimeSpan);
568
+ expect(result.valueOf()).toBe(1500n);
569
+ });
570
+
571
+ test("add with bigint", () => {
572
+ const ts = new TimeSpan(1000n);
573
+ const result = ts.add(500n);
574
+ expect(result).toBeInstanceOf(TimeSpan);
575
+ expect(result.valueOf()).toBe(1500n);
576
+ });
577
+
578
+ test("sub with TimeSpan", () => {
579
+ const ts1 = new TimeSpan(1000);
580
+ const ts2 = new TimeSpan(300);
581
+ const result = ts1.sub(ts2);
582
+ expect(result).toBeInstanceOf(TimeSpan);
583
+ expect(result.valueOf()).toBe(700n);
584
+ });
585
+
586
+ test("sub with number", () => {
587
+ const ts = new TimeSpan(1000);
588
+ const result = ts.sub(300);
589
+ expect(result).toBeInstanceOf(TimeSpan);
590
+ expect(result.valueOf()).toBe(700n);
591
+ });
592
+
593
+ test("sub with bigint", () => {
594
+ const ts = new TimeSpan(1000n);
595
+ const result = ts.sub(300n);
596
+ expect(result).toBeInstanceOf(TimeSpan);
597
+ expect(result.valueOf()).toBe(700n);
598
+ });
599
+
600
+ test("mult", () => {
601
+ const ts = new TimeSpan(1000);
602
+ const result = ts.mult(2);
603
+ expect(result).toBeInstanceOf(TimeSpan);
604
+ expect(result.valueOf()).toBe(2000n);
605
+ });
606
+
607
+ test("mult with decimal", () => {
608
+ const ts = new TimeSpan(1000);
609
+ const result = ts.mult(0.5);
610
+ expect(result).toBeInstanceOf(TimeSpan);
611
+ expect(result.valueOf()).toBe(500n);
612
+ });
613
+
614
+ test("mult with negative", () => {
615
+ const ts = new TimeSpan(1000);
616
+ const result = ts.mult(-2);
617
+ expect(result).toBeInstanceOf(TimeSpan);
618
+ expect(result.valueOf()).toBe(-2000n);
619
+ });
620
+
621
+ test("div", () => {
622
+ const ts = new TimeSpan(1000);
623
+ const result = ts.div(2);
624
+ expect(result).toBeInstanceOf(TimeSpan);
625
+ expect(result.valueOf()).toBe(500n);
626
+ });
627
+
628
+ test("div with decimal", () => {
629
+ const ts = new TimeSpan(1000);
630
+ const result = ts.div(0.5);
631
+ expect(result).toBeInstanceOf(TimeSpan);
632
+ expect(result.valueOf()).toBe(2000n);
633
+ });
634
+
635
+ test("div resulting in fractional nanoseconds truncates", () => {
636
+ const ts = new TimeSpan(1001);
637
+ const result = ts.div(2);
638
+ expect(result).toBeInstanceOf(TimeSpan);
639
+ expect(result.valueOf()).toBe(500n); // 1001/2 = 500.5, truncated to 500
640
+ });
641
+ });
642
+
511
643
  const TRUNCATE_TESTS = [
512
644
  [TimeSpan.days(1).add(TimeSpan.nanoseconds(50)), TimeSpan.DAY, TimeSpan.days(1)],
513
645
  [TimeSpan.hours(1).add(TimeSpan.minutes(30)), TimeSpan.HOUR, TimeSpan.hours(1)],
@@ -559,6 +691,63 @@ describe("TimeSpan", () => {
559
691
  expect(ts.toString()).toEqual(expected);
560
692
  });
561
693
  });
694
+
695
+ describe("schema", () => {
696
+ it("should parse bigint", () => {
697
+ const ts = TimeSpan.z.parse(1000000000n);
698
+ expect(ts).toBeInstanceOf(TimeSpan);
699
+ expect(ts.valueOf()).toBe(1000000000n);
700
+ });
701
+
702
+ it("should parse number", () => {
703
+ const ts = TimeSpan.z.parse(987654321);
704
+ expect(ts).toBeInstanceOf(TimeSpan);
705
+ expect(ts.valueOf()).toBe(987654321n);
706
+ });
707
+
708
+ it("should parse string representation of bigint", () => {
709
+ const ts = TimeSpan.z.parse("123456789000");
710
+ expect(ts).toBeInstanceOf(TimeSpan);
711
+ expect(ts.valueOf()).toBe(123456789000n);
712
+ });
713
+
714
+ it("should parse object with value property", () => {
715
+ const ts = TimeSpan.z.parse({ value: 555555555n });
716
+ expect(ts).toBeInstanceOf(TimeSpan);
717
+ expect(ts.valueOf()).toBe(555555555n);
718
+ });
719
+
720
+ it("should pass through existing TimeSpan instance", () => {
721
+ const original = new TimeSpan(777777777n);
722
+ const ts = TimeSpan.z.parse(original);
723
+ expect(ts).toStrictEqual(original);
724
+ expect(ts.valueOf()).toBe(777777777n);
725
+ });
726
+
727
+ it("should parse TimeStamp", () => {
728
+ const timestamp = new TimeStamp(999999999n);
729
+ const ts = TimeSpan.z.parse(timestamp);
730
+ expect(ts).toBeInstanceOf(TimeSpan);
731
+ expect(ts.valueOf()).toBe(999999999n);
732
+ });
733
+
734
+ it("should parse Rate", () => {
735
+ const rate = new Rate(100);
736
+ const ts = TimeSpan.z.parse(rate);
737
+ expect(ts).toBeInstanceOf(TimeSpan);
738
+ // The schema transforms Rate to TimeSpan using new TimeSpan(rate)
739
+ // which uses rate.valueOf() directly (100) as nanoseconds
740
+ expect(ts.valueOf()).toBe(100n);
741
+ });
742
+
743
+ it("should handle edge cases", () => {
744
+ const ts1 = TimeSpan.z.parse(0);
745
+ expect(ts1.valueOf()).toBe(0n);
746
+
747
+ const ts2 = TimeSpan.z.parse(Number.MAX_SAFE_INTEGER);
748
+ expect(ts2.valueOf()).toBe(BigInt(Number.MAX_SAFE_INTEGER));
749
+ });
750
+ });
562
751
  });
563
752
 
564
753
  describe("Rate", () => {
@@ -585,6 +774,96 @@ describe("Rate", () => {
585
774
 
586
775
  test("Hz", () => expect(Rate.hz(1).equals(1)).toBe(true));
587
776
  test("KHz", () => expect(Rate.khz(1).equals(1e3)).toBe(true));
777
+
778
+ describe("schema", () => {
779
+ it("should parse number", () => {
780
+ const rate = Rate.z.parse(50);
781
+ expect(rate).toBeInstanceOf(Rate);
782
+ expect(rate.valueOf()).toBe(50);
783
+ });
784
+
785
+ it("should pass through existing Rate instance", () => {
786
+ const original = new Rate(100);
787
+ const rate = Rate.z.parse(original);
788
+ expect(rate).toBe(original);
789
+ expect(rate.valueOf()).toBe(100);
790
+ });
791
+
792
+ const testCases = [
793
+ { input: 1, expected: 1 },
794
+ { input: 0.5, expected: 0.5 },
795
+ { input: 1000, expected: 1000 },
796
+ { input: 0, expected: 0 },
797
+ ];
798
+
799
+ testCases.forEach(({ input, expected }) => {
800
+ it(`should parse ${input} to Rate with value ${expected}`, () => {
801
+ const rate = Rate.z.parse(input);
802
+ expect(rate).toBeInstanceOf(Rate);
803
+ expect(rate.valueOf()).toBe(expected);
804
+ });
805
+ });
806
+ });
807
+
808
+ describe("arithmetic operations", () => {
809
+ test("add", () => {
810
+ const r1 = new Rate(100);
811
+ const r2 = new Rate(50);
812
+ const result = r1.add(r2);
813
+ expect(result).toBeInstanceOf(Rate);
814
+ expect(result.valueOf()).toBe(150);
815
+ });
816
+
817
+ test("add with number", () => {
818
+ const r1 = new Rate(100);
819
+ const result = r1.add(50);
820
+ expect(result).toBeInstanceOf(Rate);
821
+ expect(result.valueOf()).toBe(150);
822
+ });
823
+
824
+ test("sub", () => {
825
+ const r1 = new Rate(100);
826
+ const r2 = new Rate(30);
827
+ const result = r1.sub(r2);
828
+ expect(result).toBeInstanceOf(Rate);
829
+ expect(result.valueOf()).toBe(70);
830
+ });
831
+
832
+ test("sub with number", () => {
833
+ const r1 = new Rate(100);
834
+ const result = r1.sub(30);
835
+ expect(result).toBeInstanceOf(Rate);
836
+ expect(result.valueOf()).toBe(70);
837
+ });
838
+
839
+ test("mult", () => {
840
+ const r1 = new Rate(100);
841
+ const result = r1.mult(2);
842
+ expect(result).toBeInstanceOf(Rate);
843
+ expect(result.valueOf()).toBe(200);
844
+ });
845
+
846
+ test("mult with decimal", () => {
847
+ const r1 = new Rate(100);
848
+ const result = r1.mult(0.5);
849
+ expect(result).toBeInstanceOf(Rate);
850
+ expect(result.valueOf()).toBe(50);
851
+ });
852
+
853
+ test("div", () => {
854
+ const r1 = new Rate(100);
855
+ const result = r1.div(2);
856
+ expect(result).toBeInstanceOf(Rate);
857
+ expect(result.valueOf()).toBe(50);
858
+ });
859
+
860
+ test("div with decimal", () => {
861
+ const r1 = new Rate(100);
862
+ const result = r1.div(0.5);
863
+ expect(result).toBeInstanceOf(Rate);
864
+ expect(result.valueOf()).toBe(200);
865
+ });
866
+ });
588
867
  });
589
868
 
590
869
  describe("TimeRange", () => {
@@ -743,6 +1022,56 @@ describe("TimeRange", () => {
743
1022
  });
744
1023
  });
745
1024
  });
1025
+
1026
+ describe("simplify", () => {
1027
+ it("should merge overlapping time ranges", () => {
1028
+ const trs = [
1029
+ new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(4)),
1030
+ new TimeRange(TimeSpan.seconds(2), TimeSpan.seconds(3)),
1031
+ new TimeRange(TimeSpan.seconds(3), TimeSpan.seconds(5)),
1032
+ new TimeRange(TimeSpan.seconds(6), TimeSpan.seconds(7)),
1033
+ ];
1034
+ const expected = [
1035
+ new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(5)),
1036
+ new TimeRange(TimeSpan.seconds(6), TimeSpan.seconds(7)),
1037
+ ];
1038
+ const simplified = TimeRange.simplify(trs);
1039
+ expect(simplified).toEqual(expected);
1040
+ });
1041
+ it("should merge time ranges that are adjacent", () => {
1042
+ const trs = [
1043
+ new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(4)),
1044
+ new TimeRange(TimeSpan.seconds(4), TimeSpan.seconds(5)),
1045
+ ];
1046
+ const expected = [new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(5))];
1047
+ const simplified = TimeRange.simplify(trs);
1048
+ expect(simplified).toEqual(expected);
1049
+ });
1050
+ it("should remove zero length time ranges", () => {
1051
+ const trs = [
1052
+ new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(4)),
1053
+ new TimeRange(TimeSpan.seconds(5), TimeSpan.seconds(5)),
1054
+ ];
1055
+ const expected = [new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(4))];
1056
+ const simplified = TimeRange.simplify(trs);
1057
+ expect(simplified).toEqual(expected);
1058
+ });
1059
+ it("should make ranges valid by swapping start and end", () => {
1060
+ const trs = [
1061
+ new TimeRange(TimeSpan.seconds(4), TimeSpan.seconds(1)),
1062
+ new TimeRange(TimeSpan.seconds(2), TimeSpan.seconds(3)),
1063
+ ];
1064
+ const expected = [new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(4))];
1065
+ const simplified = TimeRange.simplify(trs);
1066
+ expect(simplified).toEqual(expected);
1067
+ });
1068
+ it("should work with zero ranges", () => {
1069
+ const trs: TimeRange[] = [];
1070
+ const expected: TimeRange[] = [];
1071
+ const simplified = TimeRange.simplify(trs);
1072
+ expect(simplified).toEqual(expected);
1073
+ });
1074
+ });
746
1075
  describe("numericBounds", () => {
747
1076
  it("should return correct numeric bounds for a valid time range", () => {
748
1077
  const tr = new TimeRange(TimeSpan.seconds(1), TimeSpan.seconds(4));
@@ -772,6 +1101,151 @@ describe("TimeRange", () => {
772
1101
  expect(bounds.upper).toBe(tr.end.nanoseconds);
773
1102
  });
774
1103
  });
1104
+
1105
+ describe("schema", () => {
1106
+ it("should parse object with start and end TimeStamps", () => {
1107
+ const tr = TimeRange.z.parse({
1108
+ start: new TimeStamp(1000),
1109
+ end: new TimeStamp(2000),
1110
+ });
1111
+ expect(tr).toBeInstanceOf(TimeRange);
1112
+ expect(tr.start.valueOf()).toBe(1000n);
1113
+ expect(tr.end.valueOf()).toBe(2000n);
1114
+ });
1115
+
1116
+ it("should pass through existing TimeRange instance", () => {
1117
+ const original = new TimeRange(new TimeStamp(1000), new TimeStamp(2000));
1118
+ const tr = TimeRange.z.parse(original);
1119
+ expect(tr).toStrictEqual(original);
1120
+ expect(tr.start.valueOf()).toBe(1000n);
1121
+ expect(tr.end.valueOf()).toBe(2000n);
1122
+ });
1123
+
1124
+ it("should parse object with various timestamp formats", () => {
1125
+ const tr = TimeRange.z.parse({
1126
+ start: 1000,
1127
+ end: "2000",
1128
+ });
1129
+ expect(tr).toBeInstanceOf(TimeRange);
1130
+ expect(tr.start.valueOf()).toBe(1000n);
1131
+ expect(tr.end.valueOf()).toBe(2000n);
1132
+ });
1133
+
1134
+ const testCases = [
1135
+ {
1136
+ input: { start: 0, end: 1000 },
1137
+ expectedStart: 0n,
1138
+ expectedEnd: 1000n,
1139
+ },
1140
+ {
1141
+ input: { start: new Date("2024-01-01"), end: new Date("2024-01-02") },
1142
+ expectedStart: BigInt(new Date("2024-01-01").getTime()) * 1000000n,
1143
+ expectedEnd: BigInt(new Date("2024-01-02").getTime()) * 1000000n,
1144
+ },
1145
+ ];
1146
+
1147
+ testCases.forEach(({ input, expectedStart, expectedEnd }, i) => {
1148
+ it(`should parse test case ${i + 1}`, () => {
1149
+ const tr = TimeRange.z.parse(input);
1150
+ expect(tr).toBeInstanceOf(TimeRange);
1151
+ expect(tr.start.valueOf()).toBe(expectedStart);
1152
+ expect(tr.end.valueOf()).toBe(expectedEnd);
1153
+ });
1154
+ });
1155
+ });
1156
+ });
1157
+
1158
+ describe("Density", () => {
1159
+ describe("schema", () => {
1160
+ it("should parse number", () => {
1161
+ const density = Density.z.parse(8);
1162
+ expect(density).toBeInstanceOf(Density);
1163
+ expect(density.valueOf()).toBe(8);
1164
+ });
1165
+
1166
+ it("should pass through existing Density instance", () => {
1167
+ const original = new Density(4);
1168
+ const density = Density.z.parse(original);
1169
+ expect(density).toBe(original);
1170
+ expect(density.valueOf()).toBe(4);
1171
+ });
1172
+
1173
+ const testCases = [
1174
+ { input: 1, expected: 1 },
1175
+ { input: 2, expected: 2 },
1176
+ { input: 4, expected: 4 },
1177
+ { input: 8, expected: 8 },
1178
+ { input: 0, expected: 0 },
1179
+ ];
1180
+
1181
+ testCases.forEach(({ input, expected }) => {
1182
+ it(`should parse ${input} to Density with value ${expected}`, () => {
1183
+ const density = Density.z.parse(input);
1184
+ expect(density).toBeInstanceOf(Density);
1185
+ expect(density.valueOf()).toBe(expected);
1186
+ });
1187
+ });
1188
+ });
1189
+
1190
+ describe("arithmetic operations", () => {
1191
+ test("add", () => {
1192
+ const d1 = new Density(8);
1193
+ const d2 = new Density(4);
1194
+ const result = d1.add(d2);
1195
+ expect(result).toBeInstanceOf(Density);
1196
+ expect(result.valueOf()).toBe(12);
1197
+ });
1198
+
1199
+ test("add with number", () => {
1200
+ const d1 = new Density(8);
1201
+ const result = d1.add(4);
1202
+ expect(result).toBeInstanceOf(Density);
1203
+ expect(result.valueOf()).toBe(12);
1204
+ });
1205
+
1206
+ test("sub", () => {
1207
+ const d1 = new Density(8);
1208
+ const d2 = new Density(3);
1209
+ const result = d1.sub(d2);
1210
+ expect(result).toBeInstanceOf(Density);
1211
+ expect(result.valueOf()).toBe(5);
1212
+ });
1213
+
1214
+ test("sub with number", () => {
1215
+ const d1 = new Density(8);
1216
+ const result = d1.sub(3);
1217
+ expect(result).toBeInstanceOf(Density);
1218
+ expect(result.valueOf()).toBe(5);
1219
+ });
1220
+
1221
+ test("mult", () => {
1222
+ const d1 = new Density(4);
1223
+ const result = d1.mult(2);
1224
+ expect(result).toBeInstanceOf(Density);
1225
+ expect(result.valueOf()).toBe(8);
1226
+ });
1227
+
1228
+ test("mult with decimal", () => {
1229
+ const d1 = new Density(8);
1230
+ const result = d1.mult(0.5);
1231
+ expect(result).toBeInstanceOf(Density);
1232
+ expect(result.valueOf()).toBe(4);
1233
+ });
1234
+
1235
+ test("div", () => {
1236
+ const d1 = new Density(8);
1237
+ const result = d1.div(2);
1238
+ expect(result).toBeInstanceOf(Density);
1239
+ expect(result.valueOf()).toBe(4);
1240
+ });
1241
+
1242
+ test("div with decimal", () => {
1243
+ const d1 = new Density(4);
1244
+ const result = d1.div(0.5);
1245
+ expect(result).toBeInstanceOf(Density);
1246
+ expect(result.valueOf()).toBe(8);
1247
+ });
1248
+ });
775
1249
  });
776
1250
 
777
1251
  describe("DataType", () => {
@@ -856,6 +1330,47 @@ describe("DataType", () => {
856
1330
  }),
857
1331
  );
858
1332
  });
1333
+
1334
+ describe("schema", () => {
1335
+ it("should parse string", () => {
1336
+ const dt = DataType.z.parse("int32");
1337
+ expect(dt).toBeInstanceOf(DataType);
1338
+ expect(dt.toString()).toBe("int32");
1339
+ });
1340
+
1341
+ it("should pass through existing DataType instance", () => {
1342
+ const original = DataType.INT32;
1343
+ const dt = DataType.z.parse(original);
1344
+ expect(dt).toBe(original);
1345
+ expect(dt.toString()).toBe("int32");
1346
+ });
1347
+
1348
+ const testCases = [
1349
+ { input: "int8", expected: "int8" },
1350
+ { input: "int16", expected: "int16" },
1351
+ { input: "int32", expected: "int32" },
1352
+ { input: "int64", expected: "int64" },
1353
+ { input: "uint8", expected: "uint8" },
1354
+ { input: "uint16", expected: "uint16" },
1355
+ { input: "uint32", expected: "uint32" },
1356
+ { input: "uint64", expected: "uint64" },
1357
+ { input: "float32", expected: "float32" },
1358
+ { input: "float64", expected: "float64" },
1359
+ { input: "string", expected: "string" },
1360
+ { input: "boolean", expected: "boolean" },
1361
+ { input: "timestamp", expected: "timestamp" },
1362
+ { input: "uuid", expected: "uuid" },
1363
+ { input: "json", expected: "json" },
1364
+ ];
1365
+
1366
+ testCases.forEach(({ input, expected }) => {
1367
+ it(`should parse "${input}" to DataType with value "${expected}"`, () => {
1368
+ const dt = DataType.z.parse(input);
1369
+ expect(dt).toBeInstanceOf(DataType);
1370
+ expect(dt.toString()).toBe(expected);
1371
+ });
1372
+ });
1373
+ });
859
1374
  });
860
1375
 
861
1376
  describe("Size", () => {
@@ -889,6 +1404,97 @@ describe("Size", () => {
889
1404
  expect(size.truncate(unit).valueOf()).toEqual(expected.valueOf());
890
1405
  });
891
1406
  });
1407
+
1408
+ describe("schema", () => {
1409
+ it("should parse number", () => {
1410
+ const size = Size.z.parse(1024);
1411
+ expect(size).toBeInstanceOf(Size);
1412
+ expect(size.valueOf()).toBe(1024);
1413
+ });
1414
+
1415
+ it("should pass through existing Size instance", () => {
1416
+ const original = new Size(2048);
1417
+ const size = Size.z.parse(original);
1418
+ expect(size).toBe(original);
1419
+ expect(size.valueOf()).toBe(2048);
1420
+ });
1421
+
1422
+ const testCases = [
1423
+ { input: 0, expected: 0 },
1424
+ { input: 1, expected: 1 },
1425
+ { input: 1024, expected: 1024 },
1426
+ { input: 1048576, expected: 1048576 },
1427
+ { input: 1073741824, expected: 1073741824 },
1428
+ ];
1429
+
1430
+ testCases.forEach(({ input, expected }) => {
1431
+ it(`should parse ${input} to Size with value ${expected}`, () => {
1432
+ const size = Size.z.parse(input);
1433
+ expect(size).toBeInstanceOf(Size);
1434
+ expect(size.valueOf()).toBe(expected);
1435
+ });
1436
+ });
1437
+ });
1438
+
1439
+ describe("arithmetic operations", () => {
1440
+ test("add", () => {
1441
+ const s1 = Size.kilobytes(10);
1442
+ const s2 = Size.kilobytes(5);
1443
+ const result = s1.add(s2);
1444
+ expect(result).toBeInstanceOf(Size);
1445
+ expect(result.valueOf()).toBe(15000);
1446
+ });
1447
+
1448
+ test("add with number", () => {
1449
+ const s1 = Size.bytes(100);
1450
+ const result = s1.add(50);
1451
+ expect(result).toBeInstanceOf(Size);
1452
+ expect(result.valueOf()).toBe(150);
1453
+ });
1454
+
1455
+ test("sub", () => {
1456
+ const s1 = Size.kilobytes(10);
1457
+ const s2 = Size.kilobytes(3);
1458
+ const result = s1.sub(s2);
1459
+ expect(result).toBeInstanceOf(Size);
1460
+ expect(result.valueOf()).toBe(7000);
1461
+ });
1462
+
1463
+ test("sub with number", () => {
1464
+ const s1 = Size.bytes(100);
1465
+ const result = s1.sub(30);
1466
+ expect(result).toBeInstanceOf(Size);
1467
+ expect(result.valueOf()).toBe(70);
1468
+ });
1469
+
1470
+ test("mult", () => {
1471
+ const s1 = Size.kilobytes(5);
1472
+ const result = s1.mult(2);
1473
+ expect(result).toBeInstanceOf(Size);
1474
+ expect(result.valueOf()).toBe(10000);
1475
+ });
1476
+
1477
+ test("mult with decimal", () => {
1478
+ const s1 = Size.kilobytes(10);
1479
+ const result = s1.mult(0.5);
1480
+ expect(result).toBeInstanceOf(Size);
1481
+ expect(result.valueOf()).toBe(5000);
1482
+ });
1483
+
1484
+ test("div", () => {
1485
+ const s1 = Size.kilobytes(10);
1486
+ const result = s1.div(2);
1487
+ expect(result).toBeInstanceOf(Size);
1488
+ expect(result.valueOf()).toBe(5000);
1489
+ });
1490
+
1491
+ test("div with decimal", () => {
1492
+ const s1 = Size.kilobytes(5);
1493
+ const result = s1.div(0.5);
1494
+ expect(result).toBeInstanceOf(Size);
1495
+ expect(result.valueOf()).toBe(10000);
1496
+ });
1497
+ });
892
1498
  });
893
1499
 
894
1500
  describe("addSamples", () => {