@synnaxlabs/x 0.44.2 → 0.44.3
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 +15 -15
- package/dist/bounds-8OC_obRs.js +186 -0
- package/dist/bounds-CRK04jp7.cjs +1 -0
- package/dist/bounds.cjs +1 -1
- package/dist/bounds.js +1 -1
- package/dist/deep.cjs +1 -1
- package/dist/deep.js +1 -1
- package/dist/{external-Birv9jaY.js → external-BM_NS5yM.js} +6 -6
- package/dist/external-E3ErJeeM.cjs +1 -0
- package/dist/index.cjs +3 -3
- package/dist/index.js +235 -229
- package/dist/{path-DVFrKaNI.js → path-Blh4wJuA.js} +24 -21
- package/dist/path-CPSfCjde.cjs +1 -0
- package/dist/{scale-C6qKDbRb.cjs → scale-C3fEtXxW.cjs} +1 -1
- package/dist/{scale-EWNUk-bn.js → scale-Db1Gunj0.js} +1 -1
- package/dist/scale.cjs +1 -1
- package/dist/scale.js +1 -1
- package/dist/series-BcF7A8Je.cjs +6 -0
- package/dist/{series-EA1uaEDj.js → series-Cl3Vh_u-.js} +588 -471
- package/dist/spatial.cjs +1 -1
- package/dist/spatial.js +2 -2
- package/dist/src/breaker/breaker.d.ts +2 -1
- package/dist/src/breaker/breaker.d.ts.map +1 -1
- package/dist/src/deep/path.d.ts.map +1 -1
- package/dist/src/id/id.d.ts +3 -1
- package/dist/src/id/id.d.ts.map +1 -1
- package/dist/src/math/math.d.ts +2 -1
- package/dist/src/math/math.d.ts.map +1 -1
- package/dist/src/status/status.d.ts +1 -0
- package/dist/src/status/status.d.ts.map +1 -1
- package/dist/src/strings/strings.d.ts +1 -1
- package/dist/src/strings/strings.d.ts.map +1 -1
- package/dist/src/telem/series.d.ts +7 -0
- package/dist/src/telem/series.d.ts.map +1 -1
- package/dist/src/telem/telem.d.ts +78 -1
- package/dist/src/telem/telem.d.ts.map +1 -1
- package/dist/src/zod/util.d.ts.map +1 -1
- package/dist/telem.cjs +1 -1
- package/dist/telem.js +1 -1
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +1 -1
- package/package.json +3 -3
- package/src/breaker/breaker.ts +4 -0
- package/src/deep/path.spec.ts +14 -0
- package/src/deep/path.ts +9 -2
- package/src/id/id.ts +8 -4
- package/src/math/math.spec.ts +20 -0
- package/src/math/math.ts +32 -29
- package/src/spatial/bounds/bounds.ts +1 -1
- package/src/status/status.ts +11 -0
- package/src/strings/strings.spec.ts +3 -0
- package/src/strings/strings.ts +2 -1
- package/src/telem/series.spec.ts +543 -2
- package/src/telem/series.ts +28 -9
- package/src/telem/telem.spec.ts +556 -0
- package/src/telem/telem.ts +118 -5
- package/src/zod/util.ts +5 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/dist/bounds-D6e9xoHt.cjs +0 -1
- package/dist/bounds-Dj9nG39I.js +0 -174
- package/dist/external-DsmsSN1Y.cjs +0 -1
- package/dist/path-BeMr8xWN.cjs +0 -1
- package/dist/series-CcA_WjbJ.cjs +0 -6
package/src/telem/telem.spec.ts
CHANGED
|
@@ -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", () => {
|
|
@@ -772,6 +1051,151 @@ describe("TimeRange", () => {
|
|
|
772
1051
|
expect(bounds.upper).toBe(tr.end.nanoseconds);
|
|
773
1052
|
});
|
|
774
1053
|
});
|
|
1054
|
+
|
|
1055
|
+
describe("schema", () => {
|
|
1056
|
+
it("should parse object with start and end TimeStamps", () => {
|
|
1057
|
+
const tr = TimeRange.z.parse({
|
|
1058
|
+
start: new TimeStamp(1000),
|
|
1059
|
+
end: new TimeStamp(2000),
|
|
1060
|
+
});
|
|
1061
|
+
expect(tr).toBeInstanceOf(TimeRange);
|
|
1062
|
+
expect(tr.start.valueOf()).toBe(1000n);
|
|
1063
|
+
expect(tr.end.valueOf()).toBe(2000n);
|
|
1064
|
+
});
|
|
1065
|
+
|
|
1066
|
+
it("should pass through existing TimeRange instance", () => {
|
|
1067
|
+
const original = new TimeRange(new TimeStamp(1000), new TimeStamp(2000));
|
|
1068
|
+
const tr = TimeRange.z.parse(original);
|
|
1069
|
+
expect(tr).toStrictEqual(original);
|
|
1070
|
+
expect(tr.start.valueOf()).toBe(1000n);
|
|
1071
|
+
expect(tr.end.valueOf()).toBe(2000n);
|
|
1072
|
+
});
|
|
1073
|
+
|
|
1074
|
+
it("should parse object with various timestamp formats", () => {
|
|
1075
|
+
const tr = TimeRange.z.parse({
|
|
1076
|
+
start: 1000,
|
|
1077
|
+
end: "2000",
|
|
1078
|
+
});
|
|
1079
|
+
expect(tr).toBeInstanceOf(TimeRange);
|
|
1080
|
+
expect(tr.start.valueOf()).toBe(1000n);
|
|
1081
|
+
expect(tr.end.valueOf()).toBe(2000n);
|
|
1082
|
+
});
|
|
1083
|
+
|
|
1084
|
+
const testCases = [
|
|
1085
|
+
{
|
|
1086
|
+
input: { start: 0, end: 1000 },
|
|
1087
|
+
expectedStart: 0n,
|
|
1088
|
+
expectedEnd: 1000n,
|
|
1089
|
+
},
|
|
1090
|
+
{
|
|
1091
|
+
input: { start: new Date("2024-01-01"), end: new Date("2024-01-02") },
|
|
1092
|
+
expectedStart: BigInt(new Date("2024-01-01").getTime()) * 1000000n,
|
|
1093
|
+
expectedEnd: BigInt(new Date("2024-01-02").getTime()) * 1000000n,
|
|
1094
|
+
},
|
|
1095
|
+
];
|
|
1096
|
+
|
|
1097
|
+
testCases.forEach(({ input, expectedStart, expectedEnd }, i) => {
|
|
1098
|
+
it(`should parse test case ${i + 1}`, () => {
|
|
1099
|
+
const tr = TimeRange.z.parse(input);
|
|
1100
|
+
expect(tr).toBeInstanceOf(TimeRange);
|
|
1101
|
+
expect(tr.start.valueOf()).toBe(expectedStart);
|
|
1102
|
+
expect(tr.end.valueOf()).toBe(expectedEnd);
|
|
1103
|
+
});
|
|
1104
|
+
});
|
|
1105
|
+
});
|
|
1106
|
+
});
|
|
1107
|
+
|
|
1108
|
+
describe("Density", () => {
|
|
1109
|
+
describe("schema", () => {
|
|
1110
|
+
it("should parse number", () => {
|
|
1111
|
+
const density = Density.z.parse(8);
|
|
1112
|
+
expect(density).toBeInstanceOf(Density);
|
|
1113
|
+
expect(density.valueOf()).toBe(8);
|
|
1114
|
+
});
|
|
1115
|
+
|
|
1116
|
+
it("should pass through existing Density instance", () => {
|
|
1117
|
+
const original = new Density(4);
|
|
1118
|
+
const density = Density.z.parse(original);
|
|
1119
|
+
expect(density).toBe(original);
|
|
1120
|
+
expect(density.valueOf()).toBe(4);
|
|
1121
|
+
});
|
|
1122
|
+
|
|
1123
|
+
const testCases = [
|
|
1124
|
+
{ input: 1, expected: 1 },
|
|
1125
|
+
{ input: 2, expected: 2 },
|
|
1126
|
+
{ input: 4, expected: 4 },
|
|
1127
|
+
{ input: 8, expected: 8 },
|
|
1128
|
+
{ input: 0, expected: 0 },
|
|
1129
|
+
];
|
|
1130
|
+
|
|
1131
|
+
testCases.forEach(({ input, expected }) => {
|
|
1132
|
+
it(`should parse ${input} to Density with value ${expected}`, () => {
|
|
1133
|
+
const density = Density.z.parse(input);
|
|
1134
|
+
expect(density).toBeInstanceOf(Density);
|
|
1135
|
+
expect(density.valueOf()).toBe(expected);
|
|
1136
|
+
});
|
|
1137
|
+
});
|
|
1138
|
+
});
|
|
1139
|
+
|
|
1140
|
+
describe("arithmetic operations", () => {
|
|
1141
|
+
test("add", () => {
|
|
1142
|
+
const d1 = new Density(8);
|
|
1143
|
+
const d2 = new Density(4);
|
|
1144
|
+
const result = d1.add(d2);
|
|
1145
|
+
expect(result).toBeInstanceOf(Density);
|
|
1146
|
+
expect(result.valueOf()).toBe(12);
|
|
1147
|
+
});
|
|
1148
|
+
|
|
1149
|
+
test("add with number", () => {
|
|
1150
|
+
const d1 = new Density(8);
|
|
1151
|
+
const result = d1.add(4);
|
|
1152
|
+
expect(result).toBeInstanceOf(Density);
|
|
1153
|
+
expect(result.valueOf()).toBe(12);
|
|
1154
|
+
});
|
|
1155
|
+
|
|
1156
|
+
test("sub", () => {
|
|
1157
|
+
const d1 = new Density(8);
|
|
1158
|
+
const d2 = new Density(3);
|
|
1159
|
+
const result = d1.sub(d2);
|
|
1160
|
+
expect(result).toBeInstanceOf(Density);
|
|
1161
|
+
expect(result.valueOf()).toBe(5);
|
|
1162
|
+
});
|
|
1163
|
+
|
|
1164
|
+
test("sub with number", () => {
|
|
1165
|
+
const d1 = new Density(8);
|
|
1166
|
+
const result = d1.sub(3);
|
|
1167
|
+
expect(result).toBeInstanceOf(Density);
|
|
1168
|
+
expect(result.valueOf()).toBe(5);
|
|
1169
|
+
});
|
|
1170
|
+
|
|
1171
|
+
test("mult", () => {
|
|
1172
|
+
const d1 = new Density(4);
|
|
1173
|
+
const result = d1.mult(2);
|
|
1174
|
+
expect(result).toBeInstanceOf(Density);
|
|
1175
|
+
expect(result.valueOf()).toBe(8);
|
|
1176
|
+
});
|
|
1177
|
+
|
|
1178
|
+
test("mult with decimal", () => {
|
|
1179
|
+
const d1 = new Density(8);
|
|
1180
|
+
const result = d1.mult(0.5);
|
|
1181
|
+
expect(result).toBeInstanceOf(Density);
|
|
1182
|
+
expect(result.valueOf()).toBe(4);
|
|
1183
|
+
});
|
|
1184
|
+
|
|
1185
|
+
test("div", () => {
|
|
1186
|
+
const d1 = new Density(8);
|
|
1187
|
+
const result = d1.div(2);
|
|
1188
|
+
expect(result).toBeInstanceOf(Density);
|
|
1189
|
+
expect(result.valueOf()).toBe(4);
|
|
1190
|
+
});
|
|
1191
|
+
|
|
1192
|
+
test("div with decimal", () => {
|
|
1193
|
+
const d1 = new Density(4);
|
|
1194
|
+
const result = d1.div(0.5);
|
|
1195
|
+
expect(result).toBeInstanceOf(Density);
|
|
1196
|
+
expect(result.valueOf()).toBe(8);
|
|
1197
|
+
});
|
|
1198
|
+
});
|
|
775
1199
|
});
|
|
776
1200
|
|
|
777
1201
|
describe("DataType", () => {
|
|
@@ -856,6 +1280,47 @@ describe("DataType", () => {
|
|
|
856
1280
|
}),
|
|
857
1281
|
);
|
|
858
1282
|
});
|
|
1283
|
+
|
|
1284
|
+
describe("schema", () => {
|
|
1285
|
+
it("should parse string", () => {
|
|
1286
|
+
const dt = DataType.z.parse("int32");
|
|
1287
|
+
expect(dt).toBeInstanceOf(DataType);
|
|
1288
|
+
expect(dt.toString()).toBe("int32");
|
|
1289
|
+
});
|
|
1290
|
+
|
|
1291
|
+
it("should pass through existing DataType instance", () => {
|
|
1292
|
+
const original = DataType.INT32;
|
|
1293
|
+
const dt = DataType.z.parse(original);
|
|
1294
|
+
expect(dt).toBe(original);
|
|
1295
|
+
expect(dt.toString()).toBe("int32");
|
|
1296
|
+
});
|
|
1297
|
+
|
|
1298
|
+
const testCases = [
|
|
1299
|
+
{ input: "int8", expected: "int8" },
|
|
1300
|
+
{ input: "int16", expected: "int16" },
|
|
1301
|
+
{ input: "int32", expected: "int32" },
|
|
1302
|
+
{ input: "int64", expected: "int64" },
|
|
1303
|
+
{ input: "uint8", expected: "uint8" },
|
|
1304
|
+
{ input: "uint16", expected: "uint16" },
|
|
1305
|
+
{ input: "uint32", expected: "uint32" },
|
|
1306
|
+
{ input: "uint64", expected: "uint64" },
|
|
1307
|
+
{ input: "float32", expected: "float32" },
|
|
1308
|
+
{ input: "float64", expected: "float64" },
|
|
1309
|
+
{ input: "string", expected: "string" },
|
|
1310
|
+
{ input: "boolean", expected: "boolean" },
|
|
1311
|
+
{ input: "timestamp", expected: "timestamp" },
|
|
1312
|
+
{ input: "uuid", expected: "uuid" },
|
|
1313
|
+
{ input: "json", expected: "json" },
|
|
1314
|
+
];
|
|
1315
|
+
|
|
1316
|
+
testCases.forEach(({ input, expected }) => {
|
|
1317
|
+
it(`should parse "${input}" to DataType with value "${expected}"`, () => {
|
|
1318
|
+
const dt = DataType.z.parse(input);
|
|
1319
|
+
expect(dt).toBeInstanceOf(DataType);
|
|
1320
|
+
expect(dt.toString()).toBe(expected);
|
|
1321
|
+
});
|
|
1322
|
+
});
|
|
1323
|
+
});
|
|
859
1324
|
});
|
|
860
1325
|
|
|
861
1326
|
describe("Size", () => {
|
|
@@ -889,6 +1354,97 @@ describe("Size", () => {
|
|
|
889
1354
|
expect(size.truncate(unit).valueOf()).toEqual(expected.valueOf());
|
|
890
1355
|
});
|
|
891
1356
|
});
|
|
1357
|
+
|
|
1358
|
+
describe("schema", () => {
|
|
1359
|
+
it("should parse number", () => {
|
|
1360
|
+
const size = Size.z.parse(1024);
|
|
1361
|
+
expect(size).toBeInstanceOf(Size);
|
|
1362
|
+
expect(size.valueOf()).toBe(1024);
|
|
1363
|
+
});
|
|
1364
|
+
|
|
1365
|
+
it("should pass through existing Size instance", () => {
|
|
1366
|
+
const original = new Size(2048);
|
|
1367
|
+
const size = Size.z.parse(original);
|
|
1368
|
+
expect(size).toBe(original);
|
|
1369
|
+
expect(size.valueOf()).toBe(2048);
|
|
1370
|
+
});
|
|
1371
|
+
|
|
1372
|
+
const testCases = [
|
|
1373
|
+
{ input: 0, expected: 0 },
|
|
1374
|
+
{ input: 1, expected: 1 },
|
|
1375
|
+
{ input: 1024, expected: 1024 },
|
|
1376
|
+
{ input: 1048576, expected: 1048576 },
|
|
1377
|
+
{ input: 1073741824, expected: 1073741824 },
|
|
1378
|
+
];
|
|
1379
|
+
|
|
1380
|
+
testCases.forEach(({ input, expected }) => {
|
|
1381
|
+
it(`should parse ${input} to Size with value ${expected}`, () => {
|
|
1382
|
+
const size = Size.z.parse(input);
|
|
1383
|
+
expect(size).toBeInstanceOf(Size);
|
|
1384
|
+
expect(size.valueOf()).toBe(expected);
|
|
1385
|
+
});
|
|
1386
|
+
});
|
|
1387
|
+
});
|
|
1388
|
+
|
|
1389
|
+
describe("arithmetic operations", () => {
|
|
1390
|
+
test("add", () => {
|
|
1391
|
+
const s1 = Size.kilobytes(10);
|
|
1392
|
+
const s2 = Size.kilobytes(5);
|
|
1393
|
+
const result = s1.add(s2);
|
|
1394
|
+
expect(result).toBeInstanceOf(Size);
|
|
1395
|
+
expect(result.valueOf()).toBe(15000);
|
|
1396
|
+
});
|
|
1397
|
+
|
|
1398
|
+
test("add with number", () => {
|
|
1399
|
+
const s1 = Size.bytes(100);
|
|
1400
|
+
const result = s1.add(50);
|
|
1401
|
+
expect(result).toBeInstanceOf(Size);
|
|
1402
|
+
expect(result.valueOf()).toBe(150);
|
|
1403
|
+
});
|
|
1404
|
+
|
|
1405
|
+
test("sub", () => {
|
|
1406
|
+
const s1 = Size.kilobytes(10);
|
|
1407
|
+
const s2 = Size.kilobytes(3);
|
|
1408
|
+
const result = s1.sub(s2);
|
|
1409
|
+
expect(result).toBeInstanceOf(Size);
|
|
1410
|
+
expect(result.valueOf()).toBe(7000);
|
|
1411
|
+
});
|
|
1412
|
+
|
|
1413
|
+
test("sub with number", () => {
|
|
1414
|
+
const s1 = Size.bytes(100);
|
|
1415
|
+
const result = s1.sub(30);
|
|
1416
|
+
expect(result).toBeInstanceOf(Size);
|
|
1417
|
+
expect(result.valueOf()).toBe(70);
|
|
1418
|
+
});
|
|
1419
|
+
|
|
1420
|
+
test("mult", () => {
|
|
1421
|
+
const s1 = Size.kilobytes(5);
|
|
1422
|
+
const result = s1.mult(2);
|
|
1423
|
+
expect(result).toBeInstanceOf(Size);
|
|
1424
|
+
expect(result.valueOf()).toBe(10000);
|
|
1425
|
+
});
|
|
1426
|
+
|
|
1427
|
+
test("mult with decimal", () => {
|
|
1428
|
+
const s1 = Size.kilobytes(10);
|
|
1429
|
+
const result = s1.mult(0.5);
|
|
1430
|
+
expect(result).toBeInstanceOf(Size);
|
|
1431
|
+
expect(result.valueOf()).toBe(5000);
|
|
1432
|
+
});
|
|
1433
|
+
|
|
1434
|
+
test("div", () => {
|
|
1435
|
+
const s1 = Size.kilobytes(10);
|
|
1436
|
+
const result = s1.div(2);
|
|
1437
|
+
expect(result).toBeInstanceOf(Size);
|
|
1438
|
+
expect(result.valueOf()).toBe(5000);
|
|
1439
|
+
});
|
|
1440
|
+
|
|
1441
|
+
test("div with decimal", () => {
|
|
1442
|
+
const s1 = Size.kilobytes(5);
|
|
1443
|
+
const result = s1.div(0.5);
|
|
1444
|
+
expect(result).toBeInstanceOf(Size);
|
|
1445
|
+
expect(result.valueOf()).toBe(10000);
|
|
1446
|
+
});
|
|
1447
|
+
});
|
|
892
1448
|
});
|
|
893
1449
|
|
|
894
1450
|
describe("addSamples", () => {
|