@synnaxlabs/x 0.42.3 → 0.44.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 +78 -78
- 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/binary.cjs +1 -1
- package/dist/binary.js +1 -1
- package/dist/bounds-D6e9xoHt.cjs +1 -0
- package/dist/bounds-Dj9nG39I.js +174 -0
- package/dist/bounds.cjs +1 -1
- package/dist/bounds.js +1 -1
- package/dist/{box-0YrQibkB.cjs → box-BcGdqkt4.cjs} +1 -1
- package/dist/{box-Cc8IzcNo.js → box-D_qdUyEe.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 +1 -1
- package/dist/compare.cjs +1 -1
- package/dist/compare.js +1 -1
- package/dist/deep.cjs +1 -1
- package/dist/deep.js +100 -88
- package/dist/{direction-C-b6XTeU.cjs → direction-386XDm2w.cjs} +1 -1
- package/dist/{direction-BL0PhD1k.js → direction-8etxfKaR.js} +4 -3
- package/dist/direction.cjs +1 -1
- package/dist/direction.js +1 -1
- package/dist/external-B9AAGv50.cjs +1 -0
- package/dist/external-BFgJjMcS.js +23 -0
- package/dist/{external-DqPrWKvU.js → external-BYuXBYJh.js} +10 -17
- package/dist/external-mffsMzJx.cjs +1 -0
- package/dist/index-B1m2qvBT.cjs +1 -0
- package/dist/index-B5l_quQn.js +92 -0
- package/dist/index-BQe8OIgm.cjs +3 -0
- package/dist/index-D2xcvEO5.js +46 -0
- package/dist/index-DdhM_E4k.cjs +1 -0
- package/dist/{index-QGplUHuy.js → index-PNh31WTW.js} +64 -37
- package/dist/index.cjs +3 -3
- package/dist/index.js +472 -428
- package/dist/kv.cjs +1 -1
- package/dist/kv.js +1 -1
- package/dist/{location-C3aeu046.js → location-Ar5y2DX2.js} +1 -1
- package/dist/{location-BGl5Ddds.cjs → location-DZi8ftXp.cjs} +1 -1
- package/dist/location.cjs +1 -1
- package/dist/location.js +1 -1
- package/dist/observe.cjs +1 -1
- package/dist/observe.js +16 -20
- package/dist/path-BXdMenka.js +101 -0
- package/dist/path-st_E5-LJ.cjs +1 -0
- package/dist/position-DAL0Qqdf.cjs +1 -0
- package/dist/position-bA6pUwLn.js +85 -0
- package/dist/position.cjs +1 -1
- package/dist/position.js +1 -1
- package/dist/record-CAcQ5PNX.js +14 -0
- package/dist/record-YvCh7bzB.cjs +1 -0
- package/dist/record.cjs +1 -1
- package/dist/record.js +2 -10
- package/dist/scale-Bzn1Cl0r.cjs +1 -0
- package/dist/{scale-DfJe9755.js → scale-CdTNWu-d.js} +55 -59
- package/dist/scale.cjs +1 -1
- package/dist/scale.js +1 -1
- package/dist/series-BeJyqCoP.js +2568 -0
- package/dist/series-anlpaR_I.cjs +6 -0
- package/dist/spatial.cjs +1 -1
- package/dist/spatial.js +6 -6
- 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 +7 -15
- package/dist/src/binary/codec.d.ts.map +1 -1
- package/dist/src/breaker/breaker.d.ts +5 -5
- package/dist/src/breaker/breaker.d.ts.map +1 -1
- package/dist/src/caseconv/caseconv.d.ts +0 -1
- package/dist/src/caseconv/caseconv.d.ts.map +1 -1
- package/dist/src/change/change.d.ts +2 -2
- package/dist/src/change/change.d.ts.map +1 -1
- package/dist/src/color/color.d.ts +60 -36
- 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 +6 -6
- package/dist/src/color/gradient.d.ts.map +1 -1
- package/dist/src/color/palette.d.ts +9 -9
- package/dist/src/color/palette.d.ts.map +1 -1
- package/dist/src/compare/compare.d.ts +8 -8
- package/dist/src/compare/compare.d.ts.map +1 -1
- package/dist/src/control/control.d.ts +39 -39
- 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.map +1 -1
- package/dist/src/deep/path.d.ts +6 -6
- package/dist/src/deep/path.d.ts.map +1 -1
- package/dist/src/destructor.d.ts +6 -2
- package/dist/src/destructor.d.ts.map +1 -1
- package/dist/src/errors/errors.d.ts +65 -35
- package/dist/src/errors/errors.d.ts.map +1 -1
- package/dist/src/flush.d.ts +11 -0
- package/dist/src/flush.d.ts.map +1 -0
- package/dist/src/id/id.d.ts +1 -0
- package/dist/src/id/id.d.ts.map +1 -1
- package/dist/src/identity.d.ts +2 -2
- package/dist/src/identity.d.ts.map +1 -1
- package/dist/src/index.d.ts +7 -2
- 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 +39 -8
- package/dist/src/jsonrpc/jsonrpc.d.ts.map +1 -1
- package/dist/src/kv/types.d.ts +1 -1
- package/dist/src/kv/types.d.ts.map +1 -1
- package/dist/src/map/index.d.ts +2 -0
- package/dist/src/map/index.d.ts.map +1 -0
- package/dist/src/map/map.d.ts +2 -0
- package/dist/src/map/map.d.ts.map +1 -0
- package/dist/src/map/map.spec.d.ts +2 -0
- package/dist/src/map/map.spec.d.ts.map +1 -0
- package/dist/src/math/math.d.ts +2 -4
- package/dist/src/math/math.d.ts.map +1 -1
- package/dist/src/migrate/migrate.d.ts +4 -4
- package/dist/src/migrate/migrate.d.ts.map +1 -1
- package/dist/src/optional.d.ts +0 -3
- package/dist/src/optional.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/index.d.ts +2 -0
- package/dist/src/record/index.d.ts.map +1 -0
- package/dist/src/record/record.d.ts +90 -0
- package/dist/src/record/record.d.ts.map +1 -0
- package/dist/src/record/record.spec.d.ts.map +1 -0
- 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/spatial/base.d.ts +9 -9
- 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 +6 -6
- package/dist/src/spatial/box/box.d.ts.map +1 -1
- package/dist/src/spatial/dimensions/dimensions.d.ts +4 -4
- package/dist/src/spatial/dimensions/dimensions.d.ts.map +1 -1
- package/dist/src/spatial/direction/direction.d.ts +2 -2
- package/dist/src/spatial/direction/direction.d.ts.map +1 -1
- package/dist/src/spatial/location/location.d.ts +3 -3
- package/dist/src/spatial/location/location.d.ts.map +1 -1
- package/dist/src/spatial/scale/scale.d.ts +10 -10
- package/dist/src/spatial/scale/scale.d.ts.map +1 -1
- package/dist/src/spatial/xy/xy.d.ts +4 -4
- 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/status.d.ts +42 -0
- package/dist/src/status/status.d.ts.map +1 -0
- package/dist/src/status/status.spec.d.ts +2 -0
- package/dist/src/status/status.spec.d.ts.map +1 -0
- package/dist/src/strings/strings.d.ts +16 -0
- package/dist/src/strings/strings.d.ts.map +1 -1
- 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/series.d.ts +473 -66
- package/dist/src/telem/series.d.ts.map +1 -1
- package/dist/src/telem/telem.d.ts +274 -61
- package/dist/src/telem/telem.d.ts.map +1 -1
- package/dist/src/testutil/testutil.d.ts +1 -0
- package/dist/src/testutil/testutil.d.ts.map +1 -1
- package/dist/src/testutil/testutil.spec.d.ts +2 -0
- package/dist/src/testutil/testutil.spec.d.ts.map +1 -0
- 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 +2 -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/toArray.d.ts +3 -0
- package/dist/src/zod/toArray.d.ts.map +1 -0
- package/dist/src/zod/toArray.spec.d.ts +2 -0
- package/dist/src/zod/toArray.spec.d.ts.map +1 -0
- package/dist/src/zod/util.d.ts +1 -1
- package/dist/src/zod/util.d.ts.map +1 -1
- package/dist/telem.cjs +1 -1
- package/dist/telem.js +10 -11
- package/dist/url.cjs +1 -1
- package/dist/url.js +16 -19
- package/dist/worker.cjs +1 -1
- package/dist/worker.js +18 -22
- package/dist/zod.cjs +1 -1
- package/dist/zod.js +1 -1
- package/eslint.config.js +1 -1
- package/package.json +20 -23
- package/src/array/index.ts +10 -0
- package/src/array/toArray.spec.ts +56 -0
- package/src/array/toArray.ts +28 -0
- package/src/binary/codec.spec.ts +200 -277
- package/src/binary/codec.ts +19 -75
- package/src/breaker/breaker.ts +2 -2
- package/src/caseconv/caseconv.ts +14 -14
- package/src/change/change.ts +1 -1
- package/src/color/color.spec.ts +113 -2
- package/src/color/color.ts +88 -58
- package/src/color/external.ts +0 -1
- package/src/color/gradient.ts +19 -27
- package/src/compare/compare.ts +10 -10
- 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 +1 -2
- package/src/deep/merge.ts +15 -6
- package/src/deep/path.spec.ts +41 -0
- package/src/deep/path.ts +48 -17
- package/src/destructor.ts +6 -2
- package/src/errors/errors.spec.ts +20 -20
- package/src/errors/errors.ts +67 -43
- package/src/flush.ts +21 -0
- package/src/id/id.spec.ts +1 -1
- package/src/id/id.ts +3 -1
- package/src/identity.ts +2 -2
- package/src/index.ts +7 -2
- 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 +35 -6
- package/src/map/index.ts +10 -0
- package/src/map/map.spec.ts +132 -0
- package/src/map/map.ts +17 -0
- package/src/math/math.ts +19 -27
- package/src/migrate/migrate.spec.ts +1 -1
- package/src/migrate/migrate.ts +7 -7
- package/src/optional.ts +0 -4
- 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/index.ts +10 -0
- package/src/record/record.spec.ts +319 -0
- package/src/record/record.ts +118 -0
- package/src/renderable.ts +1 -1
- package/src/replace.ts +9 -0
- package/src/runtime/detect.ts +0 -2
- package/src/spatial/bounds/bounds.spec.ts +20 -0
- package/src/spatial/bounds/bounds.ts +101 -18
- package/src/spatial/dimensions/dimensions.ts +2 -2
- package/src/spatial/direction/direction.ts +1 -1
- package/src/status/index.ts +10 -0
- package/src/status/status.spec.ts +25 -0
- package/src/status/status.ts +91 -0
- package/src/strings/strings.spec.ts +51 -13
- package/src/strings/strings.ts +20 -0
- package/src/sync/index.ts +9 -0
- package/src/sync/mutex.ts +9 -4
- package/src/telem/series.spec.ts +912 -105
- package/src/telem/series.ts +577 -201
- package/src/telem/telem.spec.ts +262 -90
- package/src/telem/telem.ts +335 -125
- package/src/testutil/testutil.spec.ts +161 -0
- package/src/testutil/testutil.ts +12 -0
- 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 +2 -1
- package/src/zod/nullToUndefined.spec.ts +31 -0
- package/src/zod/nullToUndefined.ts +23 -0
- package/src/zod/toArray.spec.ts +182 -0
- package/src/{toArray.ts → zod/toArray.ts} +3 -4
- package/src/zod/util.spec.ts +1 -1
- package/src/zod/util.ts +7 -7
- package/tsconfig.json +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/vite.config.ts +2 -3
- package/dist/bounds-BQo7rvs9.cjs +0 -1
- package/dist/bounds-Bn5_l4Z3.js +0 -173
- package/dist/external-C-dNgNQw.cjs +0 -1
- package/dist/external-C8TFju8Q.js +0 -29
- package/dist/external-DWQITF5_.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/path-1tZLZ4AN.cjs +0 -1
- package/dist/path-DD6ytXzr.js +0 -76
- 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/search.cjs +0 -1
- package/dist/search.js +0 -14
- package/dist/series-B9JERcqi.js +0 -1977
- package/dist/series-DqJ6f97G.cjs +0 -11
- 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/record.d.ts +0 -18
- package/dist/src/record.d.ts.map +0 -1
- package/dist/src/record.spec.d.ts.map +0 -1
- package/dist/src/search.d.ts +0 -18
- package/dist/src/search.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/src/color/transformColorsToHex.ts +0 -30
- package/src/primitive.ts +0 -46
- package/src/record.spec.ts +0 -38
- package/src/record.ts +0 -47
- package/src/search.ts +0 -42
- package/src/zod/integer.spec.ts +0 -148
- package/src/zod/integer.ts +0 -38
- /package/dist/src/{record.spec.d.ts → record/record.spec.d.ts} +0 -0
package/src/telem/telem.ts
CHANGED
|
@@ -10,11 +10,13 @@
|
|
|
10
10
|
import { z } from "zod";
|
|
11
11
|
|
|
12
12
|
import { math } from "@/math";
|
|
13
|
-
import {
|
|
13
|
+
import { primitive } from "@/primitive";
|
|
14
14
|
import { type bounds } from "@/spatial";
|
|
15
15
|
|
|
16
|
+
/** Time zone specification when working with time stamps. */
|
|
16
17
|
export type TZInfo = "UTC" | "local";
|
|
17
18
|
|
|
19
|
+
/** Different string formats for time stamps. */
|
|
18
20
|
export type TimeStampStringFormat =
|
|
19
21
|
| "ISO"
|
|
20
22
|
| "ISODate"
|
|
@@ -26,7 +28,20 @@ export type TimeStampStringFormat =
|
|
|
26
28
|
| "shortDate"
|
|
27
29
|
| "dateTime";
|
|
28
30
|
|
|
29
|
-
|
|
31
|
+
const dateComponentsZ = z.union([
|
|
32
|
+
z.tuple([z.int()]),
|
|
33
|
+
z.tuple([z.int(), z.int().min(1).max(12)]),
|
|
34
|
+
z.tuple([z.int(), z.int().min(1).max(12), z.int().min(1).max(31)]),
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A triple of numbers representing a date.
|
|
39
|
+
*
|
|
40
|
+
* @param year - The year.
|
|
41
|
+
* @param month - The month.
|
|
42
|
+
* @param day - The day.
|
|
43
|
+
*/
|
|
44
|
+
export type DateComponents = z.infer<typeof dateComponentsZ>;
|
|
30
45
|
|
|
31
46
|
const remainder = <T extends TimeStamp | TimeSpan>(
|
|
32
47
|
value: T,
|
|
@@ -52,7 +67,7 @@ const remainder = <T extends TimeStamp | TimeSpan>(
|
|
|
52
67
|
};
|
|
53
68
|
|
|
54
69
|
/**
|
|
55
|
-
|
|
70
|
+
UTC timestamp. Synnax uses a nanosecond precision int64 timestamp.
|
|
56
71
|
*
|
|
57
72
|
* @param value - The timestamp value to parse. This can be any of the following:
|
|
58
73
|
*
|
|
@@ -72,21 +87,19 @@ const remainder = <T extends TimeStamp | TimeSpan>(
|
|
|
72
87
|
* @example ts = new TimeStamp([2021, 1, 1]).add(1 * TimeSpan.HOUR) // 1/1/2021 at 1am UTC
|
|
73
88
|
* @example ts = new TimeStamp("2021-01-01T12:30:00Z") // 1/1/2021 at 12:30pm UTC
|
|
74
89
|
*/
|
|
75
|
-
export class TimeStamp
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
readonly encodeValue = true;
|
|
80
|
-
|
|
90
|
+
export class TimeStamp
|
|
91
|
+
extends primitive.ValueExtension<bigint>
|
|
92
|
+
implements primitive.Stringer
|
|
93
|
+
{
|
|
81
94
|
constructor(value?: CrudeTimeStamp, tzInfo: TZInfo = "UTC") {
|
|
82
|
-
if (value == null)
|
|
95
|
+
if (value == null) super(TimeStamp.now().valueOf());
|
|
83
96
|
else if (value instanceof Date)
|
|
84
|
-
|
|
97
|
+
super(BigInt(value.getTime()) * TimeStamp.MILLISECOND.valueOf());
|
|
85
98
|
else if (typeof value === "string")
|
|
86
|
-
|
|
87
|
-
else if (Array.isArray(value))
|
|
99
|
+
super(TimeStamp.parseDateTimeString(value, tzInfo).valueOf());
|
|
100
|
+
else if (Array.isArray(value)) super(TimeStamp.parseDate(value));
|
|
88
101
|
else {
|
|
89
|
-
let offset
|
|
102
|
+
let offset = 0n;
|
|
90
103
|
if (value instanceof Number) value = value.valueOf();
|
|
91
104
|
if (tzInfo === "local") offset = TimeStamp.utcOffset.valueOf();
|
|
92
105
|
if (typeof value === "number")
|
|
@@ -96,7 +109,7 @@ export class TimeStamp implements Stringer {
|
|
|
96
109
|
if (value === Infinity) value = TimeStamp.MAX;
|
|
97
110
|
else value = TimeStamp.MIN;
|
|
98
111
|
}
|
|
99
|
-
|
|
112
|
+
super(BigInt(value.valueOf()) + offset);
|
|
100
113
|
}
|
|
101
114
|
}
|
|
102
115
|
|
|
@@ -108,6 +121,10 @@ export class TimeStamp implements Stringer {
|
|
|
108
121
|
.valueOf();
|
|
109
122
|
}
|
|
110
123
|
|
|
124
|
+
/**
|
|
125
|
+
* @returns the primitive value of the TimeStamp. Overrides standard JS valueOf()
|
|
126
|
+
* method.
|
|
127
|
+
*/
|
|
111
128
|
valueOf(): bigint {
|
|
112
129
|
return this.value;
|
|
113
130
|
}
|
|
@@ -138,6 +155,13 @@ export class TimeStamp implements Stringer {
|
|
|
138
155
|
).valueOf();
|
|
139
156
|
}
|
|
140
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Formats the TimeStamp as a string in the specified format.
|
|
160
|
+
*
|
|
161
|
+
* @param format - The format to use for the string representation.
|
|
162
|
+
* @param tzInfo - The timezone to use when creating the string representation.
|
|
163
|
+
* @returns A string representation of the TimeStamp in the specified format.
|
|
164
|
+
*/
|
|
141
165
|
fString(format: TimeStampStringFormat = "ISO", tzInfo: TZInfo = "UTC"): string {
|
|
142
166
|
switch (format) {
|
|
143
167
|
case "ISODate":
|
|
@@ -176,6 +200,7 @@ export class TimeStamp implements Stringer {
|
|
|
176
200
|
return `${month} ${day}`;
|
|
177
201
|
}
|
|
178
202
|
|
|
203
|
+
/** @returns The UTC offset for the time zone of the machine. */
|
|
179
204
|
static get utcOffset(): TimeSpan {
|
|
180
205
|
return new TimeSpan(
|
|
181
206
|
BigInt(new Date().getTimezoneOffset()) * TimeStamp.MINUTE.valueOf(),
|
|
@@ -246,7 +271,7 @@ export class TimeStamp implements Stringer {
|
|
|
246
271
|
* @returns True if the TimeStamp represents the unix epoch, false otherwise.
|
|
247
272
|
*/
|
|
248
273
|
get isZero(): boolean {
|
|
249
|
-
return this.valueOf() ===
|
|
274
|
+
return this.valueOf() === 0n;
|
|
250
275
|
}
|
|
251
276
|
|
|
252
277
|
/**
|
|
@@ -352,7 +377,7 @@ export class TimeStamp implements Stringer {
|
|
|
352
377
|
return Number(this.valueOf()) / Number(TimeStamp.MILLISECOND.valueOf());
|
|
353
378
|
}
|
|
354
379
|
|
|
355
|
-
/** @returns the floating point number of microseconds since the unix epoch */
|
|
380
|
+
/** @returns the floating point number of microseconds since the unix epoch. */
|
|
356
381
|
get microseconds(): number {
|
|
357
382
|
return Number(this.valueOf()) / Number(TimeStamp.MICROSECOND.valueOf());
|
|
358
383
|
}
|
|
@@ -368,7 +393,7 @@ export class TimeStamp implements Stringer {
|
|
|
368
393
|
|
|
369
394
|
/** @returns the integer year that the timestamp corresponds to. */
|
|
370
395
|
get year(): number {
|
|
371
|
-
return this.date().
|
|
396
|
+
return this.date().getUTCFullYear();
|
|
372
397
|
}
|
|
373
398
|
|
|
374
399
|
/**
|
|
@@ -377,7 +402,7 @@ export class TimeStamp implements Stringer {
|
|
|
377
402
|
*/
|
|
378
403
|
setYear(year: number): TimeStamp {
|
|
379
404
|
const d = this.date();
|
|
380
|
-
d.
|
|
405
|
+
d.setUTCFullYear(year);
|
|
381
406
|
return new TimeStamp(d);
|
|
382
407
|
}
|
|
383
408
|
|
|
@@ -430,7 +455,7 @@ export class TimeStamp implements Stringer {
|
|
|
430
455
|
|
|
431
456
|
/** @returns the integer minute that the timestamp corresponds to within its hour. */
|
|
432
457
|
get minute(): number {
|
|
433
|
-
return this.date().
|
|
458
|
+
return this.date().getUTCMinutes();
|
|
434
459
|
}
|
|
435
460
|
|
|
436
461
|
/**
|
|
@@ -448,7 +473,7 @@ export class TimeStamp implements Stringer {
|
|
|
448
473
|
* minute.
|
|
449
474
|
*/
|
|
450
475
|
get second(): number {
|
|
451
|
-
return this.date().
|
|
476
|
+
return this.date().getUTCSeconds();
|
|
452
477
|
}
|
|
453
478
|
|
|
454
479
|
/**
|
|
@@ -466,7 +491,7 @@ export class TimeStamp implements Stringer {
|
|
|
466
491
|
* its second.
|
|
467
492
|
*/
|
|
468
493
|
get millisecond(): number {
|
|
469
|
-
return this.date().
|
|
494
|
+
return this.date().getUTCMilliseconds();
|
|
470
495
|
}
|
|
471
496
|
|
|
472
497
|
/**
|
|
@@ -475,7 +500,7 @@ export class TimeStamp implements Stringer {
|
|
|
475
500
|
*/
|
|
476
501
|
setMillisecond(millisecond: number): TimeStamp {
|
|
477
502
|
const d = this.date();
|
|
478
|
-
d.
|
|
503
|
+
d.setUTCMilliseconds(millisecond);
|
|
479
504
|
return new TimeStamp(d);
|
|
480
505
|
}
|
|
481
506
|
|
|
@@ -504,6 +529,12 @@ export class TimeStamp implements Stringer {
|
|
|
504
529
|
return this.truncate(TimeSpan.DAY).equals(TimeStamp.now().truncate(TimeSpan.DAY));
|
|
505
530
|
}
|
|
506
531
|
|
|
532
|
+
/**
|
|
533
|
+
* Truncates the TimeStamp to the nearest multiple of the given span.
|
|
534
|
+
*
|
|
535
|
+
* @param span - The TimeSpan to truncate to.
|
|
536
|
+
* @returns A new TimeStamp that is truncated to the nearest multiple of the given span.
|
|
537
|
+
*/
|
|
507
538
|
truncate(span: TimeSpan | TimeStamp): TimeStamp {
|
|
508
539
|
return this.sub(this.remainder(span));
|
|
509
540
|
}
|
|
@@ -517,7 +548,12 @@ export class TimeStamp implements Stringer {
|
|
|
517
548
|
return new TimeStamp(new Date());
|
|
518
549
|
}
|
|
519
550
|
|
|
520
|
-
/**
|
|
551
|
+
/**
|
|
552
|
+
* Finds the maximum timestamp among the provided timestamps.
|
|
553
|
+
*
|
|
554
|
+
* @param timestamps - The timestamps to compare.
|
|
555
|
+
* @returns The maximum (latest) timestamp from the input.
|
|
556
|
+
*/
|
|
521
557
|
static max(...timestamps: CrudeTimeStamp[]): TimeStamp {
|
|
522
558
|
let max = TimeStamp.MIN;
|
|
523
559
|
for (const ts of timestamps) {
|
|
@@ -527,7 +563,12 @@ export class TimeStamp implements Stringer {
|
|
|
527
563
|
return max;
|
|
528
564
|
}
|
|
529
565
|
|
|
530
|
-
/**
|
|
566
|
+
/**
|
|
567
|
+
* Finds the minimum timestamp among the provided timestamps.
|
|
568
|
+
*
|
|
569
|
+
* @param timestamps - The timestamps to compare.
|
|
570
|
+
* @returns The minimum (earliest) timestamp from the input.
|
|
571
|
+
*/
|
|
531
572
|
static min(...timestamps: CrudeTimeStamp[]): TimeStamp {
|
|
532
573
|
let min = TimeStamp.MAX;
|
|
533
574
|
for (const ts of timestamps) {
|
|
@@ -537,7 +578,12 @@ export class TimeStamp implements Stringer {
|
|
|
537
578
|
return min;
|
|
538
579
|
}
|
|
539
580
|
|
|
540
|
-
/**
|
|
581
|
+
/**
|
|
582
|
+
* Creates a TimeStamp representing the given number of nanoseconds.
|
|
583
|
+
*
|
|
584
|
+
* @param value - The number of nanoseconds.
|
|
585
|
+
* @returns A TimeStamp representing the given number of nanoseconds.
|
|
586
|
+
*/
|
|
541
587
|
static nanoseconds(value: number, tzInfo: TZInfo = "UTC"): TimeStamp {
|
|
542
588
|
return new TimeStamp(value, tzInfo);
|
|
543
589
|
}
|
|
@@ -604,24 +650,45 @@ export class TimeStamp implements Stringer {
|
|
|
604
650
|
|
|
605
651
|
/** A zod schema for validating timestamps */
|
|
606
652
|
static readonly z = z.union([
|
|
653
|
+
z.instanceof(TimeStamp),
|
|
607
654
|
z.object({ value: z.bigint() }).transform((v) => new TimeStamp(v.value)),
|
|
608
655
|
z.string().transform((n) => new TimeStamp(BigInt(n))),
|
|
609
|
-
z.instanceof(Number).transform((n) => new TimeStamp(n)),
|
|
610
656
|
z.number().transform((n) => new TimeStamp(n)),
|
|
611
|
-
z.
|
|
657
|
+
z.bigint().transform((n) => new TimeStamp(n)),
|
|
658
|
+
z.date().transform((d) => new TimeStamp(d)),
|
|
659
|
+
z.custom<TimeSpan>((v) => v instanceof TimeSpan).transform((v) => new TimeStamp(v)),
|
|
660
|
+
dateComponentsZ.transform((v) => new TimeStamp(v)),
|
|
612
661
|
]);
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* Sorts two timestamps.
|
|
665
|
+
*
|
|
666
|
+
* @param a - The first timestamp.
|
|
667
|
+
* @param b - The second timestamp.
|
|
668
|
+
* @returns A number indicating the order of the two timestamps (positive if a is
|
|
669
|
+
* greater than b, negative if a is less than b, and 0 if they are equal).
|
|
670
|
+
*/
|
|
671
|
+
static sort(a: TimeStamp, b: TimeStamp): number {
|
|
672
|
+
return Number(a.valueOf() - b.valueOf());
|
|
673
|
+
}
|
|
613
674
|
}
|
|
614
675
|
|
|
615
676
|
/** TimeSpan represents a nanosecond precision duration. */
|
|
616
|
-
export class TimeSpan
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
677
|
+
export class TimeSpan
|
|
678
|
+
extends primitive.ValueExtension<bigint>
|
|
679
|
+
implements primitive.Stringer
|
|
680
|
+
{
|
|
620
681
|
constructor(value: CrudeTimeSpan) {
|
|
621
682
|
if (typeof value === "number") value = Math.trunc(value.valueOf());
|
|
622
|
-
|
|
683
|
+
super(BigInt(value.valueOf()));
|
|
623
684
|
}
|
|
624
685
|
|
|
686
|
+
/**
|
|
687
|
+
* Creates a TimeSpan representing the given number of seconds.
|
|
688
|
+
*
|
|
689
|
+
* @param span - The number of seconds.
|
|
690
|
+
* @returns A TimeSpan representing the given number of seconds.
|
|
691
|
+
*/
|
|
625
692
|
static fromSeconds(span: CrudeTimeSpan): TimeSpan {
|
|
626
693
|
if (span instanceof TimeSpan) return span;
|
|
627
694
|
if (span instanceof Rate) return span.period;
|
|
@@ -630,6 +697,12 @@ export class TimeSpan implements Stringer {
|
|
|
630
697
|
return new TimeSpan(span);
|
|
631
698
|
}
|
|
632
699
|
|
|
700
|
+
/**
|
|
701
|
+
* Creates a TimeSpan representing the given number of milliseconds.
|
|
702
|
+
*
|
|
703
|
+
* @param span - The number of milliseconds.
|
|
704
|
+
* @returns A TimeSpan representing the given number of milliseconds.
|
|
705
|
+
*/
|
|
633
706
|
static fromMilliseconds(span: CrudeTimeSpan): TimeSpan {
|
|
634
707
|
if (span instanceof TimeSpan) return span;
|
|
635
708
|
if (span instanceof Rate) return span.period;
|
|
@@ -638,40 +711,81 @@ export class TimeSpan implements Stringer {
|
|
|
638
711
|
return new TimeSpan(span);
|
|
639
712
|
}
|
|
640
713
|
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
714
|
+
/**
|
|
715
|
+
* @returns the primitive value of the TimeSpan. Overrides standard JS valueOf()
|
|
716
|
+
* method.
|
|
717
|
+
*/
|
|
645
718
|
valueOf(): bigint {
|
|
646
719
|
return this.value;
|
|
647
720
|
}
|
|
648
721
|
|
|
722
|
+
/**
|
|
723
|
+
* Checks if the TimeSpan is less than another TimeSpan.
|
|
724
|
+
*
|
|
725
|
+
* @param other - The TimeSpan to compare against.
|
|
726
|
+
* @returns True if the TimeSpan is less than the other TimeSpan, false otherwise.
|
|
727
|
+
*/
|
|
649
728
|
lessThan(other: CrudeTimeSpan): boolean {
|
|
650
729
|
return this.valueOf() < new TimeSpan(other).valueOf();
|
|
651
730
|
}
|
|
652
731
|
|
|
732
|
+
/**
|
|
733
|
+
* Checks if the TimeSpan is greater than another TimeSpan.
|
|
734
|
+
*
|
|
735
|
+
* @param other - The TimeSpan to compare against.
|
|
736
|
+
* @returns True if the TimeSpan is greater than the other TimeSpan, false otherwise.
|
|
737
|
+
*/
|
|
653
738
|
greaterThan(other: CrudeTimeSpan): boolean {
|
|
654
739
|
return this.valueOf() > new TimeSpan(other).valueOf();
|
|
655
740
|
}
|
|
656
741
|
|
|
742
|
+
/**
|
|
743
|
+
* Checks if the TimeSpan is less than or equal to another TimeSpan.
|
|
744
|
+
*
|
|
745
|
+
* @param other - The TimeSpan to compare against.
|
|
746
|
+
* @returns True if the TimeSpan is less than or equal to the other TimeSpan, false otherwise.
|
|
747
|
+
*/
|
|
657
748
|
lessThanOrEqual(other: CrudeTimeSpan): boolean {
|
|
658
749
|
return this.valueOf() <= new TimeSpan(other).valueOf();
|
|
659
750
|
}
|
|
660
751
|
|
|
752
|
+
/**
|
|
753
|
+
* Checks if the TimeSpan is greater than or equal to another TimeSpan.
|
|
754
|
+
*
|
|
755
|
+
* @param other - The TimeSpan to compare against.
|
|
756
|
+
* @returns True if the TimeSpan is greater than or equal to the other TimeSpan, false otherwise.
|
|
757
|
+
*/
|
|
661
758
|
greaterThanOrEqual(other: CrudeTimeSpan): boolean {
|
|
662
759
|
return this.valueOf() >= new TimeSpan(other).valueOf();
|
|
663
760
|
}
|
|
664
761
|
|
|
762
|
+
/**
|
|
763
|
+
* Calculates the remainder of the TimeSpan when divided by another TimeSpan.
|
|
764
|
+
*
|
|
765
|
+
* @param divisor - The TimeSpan to divide by.
|
|
766
|
+
* @returns A new TimeSpan representing the remainder.
|
|
767
|
+
*/
|
|
665
768
|
remainder(divisor: TimeSpan): TimeSpan {
|
|
666
769
|
return remainder(this, divisor);
|
|
667
770
|
}
|
|
668
771
|
|
|
772
|
+
/**
|
|
773
|
+
* Truncates the TimeSpan to the nearest multiple of the given span.
|
|
774
|
+
*
|
|
775
|
+
* @param span - The TimeSpan to truncate to.
|
|
776
|
+
* @returns A new TimeSpan that is truncated to the nearest multiple of the given span.
|
|
777
|
+
*/
|
|
669
778
|
truncate(span: TimeSpan): TimeSpan {
|
|
670
779
|
return new TimeSpan(
|
|
671
780
|
BigInt(Math.trunc(Number(this.valueOf() / span.valueOf()))) * span.valueOf(),
|
|
672
781
|
);
|
|
673
782
|
}
|
|
674
783
|
|
|
784
|
+
/**
|
|
785
|
+
* Returns a string representation of the TimeSpan.
|
|
786
|
+
*
|
|
787
|
+
* @returns A string representation of the TimeSpan.
|
|
788
|
+
*/
|
|
675
789
|
toString(): string {
|
|
676
790
|
const totalDays = this.truncate(TimeSpan.DAY);
|
|
677
791
|
const totalHours = this.truncate(TimeSpan.HOUR);
|
|
@@ -699,21 +813,27 @@ export class TimeSpan implements Stringer {
|
|
|
699
813
|
return str.trim();
|
|
700
814
|
}
|
|
701
815
|
|
|
816
|
+
/**
|
|
817
|
+
* Multiplies the TimeSpan by a scalar value.
|
|
818
|
+
*
|
|
819
|
+
* @param value - The scalar value to multiply by.
|
|
820
|
+
* @returns A new TimeSpan that is this TimeSpan multiplied by the provided value.
|
|
821
|
+
*/
|
|
702
822
|
mult(value: number): TimeSpan {
|
|
703
823
|
return new TimeSpan(this.valueOf() * BigInt(value));
|
|
704
824
|
}
|
|
705
825
|
|
|
706
|
-
/** @returns the decimal number of days in the
|
|
826
|
+
/** @returns the decimal number of days in the TimeSpan. */
|
|
707
827
|
get days(): number {
|
|
708
828
|
return Number(this.valueOf()) / Number(TimeSpan.DAY.valueOf());
|
|
709
829
|
}
|
|
710
830
|
|
|
711
|
-
/** @returns the decimal number of hours in the
|
|
831
|
+
/** @returns the decimal number of hours in the TimeSpan. */
|
|
712
832
|
get hours(): number {
|
|
713
833
|
return Number(this.valueOf()) / Number(TimeSpan.HOUR.valueOf());
|
|
714
834
|
}
|
|
715
835
|
|
|
716
|
-
/** @returns the decimal number of minutes in the
|
|
836
|
+
/** @returns the decimal number of minutes in the TimeSpan. */
|
|
717
837
|
get minutes(): number {
|
|
718
838
|
return Number(this.valueOf()) / Number(TimeSpan.MINUTE.valueOf());
|
|
719
839
|
}
|
|
@@ -728,10 +848,12 @@ export class TimeSpan implements Stringer {
|
|
|
728
848
|
return Number(this.valueOf()) / Number(TimeSpan.MILLISECOND.valueOf());
|
|
729
849
|
}
|
|
730
850
|
|
|
851
|
+
/** @returns The number of microseconds in the TimeSpan. */
|
|
731
852
|
get microseconds(): number {
|
|
732
853
|
return Number(this.valueOf()) / Number(TimeSpan.MICROSECOND.valueOf());
|
|
733
854
|
}
|
|
734
855
|
|
|
856
|
+
/** @returns The number of nanoseconds in the TimeSpan. */
|
|
735
857
|
get nanoseconds(): number {
|
|
736
858
|
return Number(this.valueOf());
|
|
737
859
|
}
|
|
@@ -742,7 +864,7 @@ export class TimeSpan implements Stringer {
|
|
|
742
864
|
* @returns True if the TimeSpan represents a zero duration, false otherwise.
|
|
743
865
|
*/
|
|
744
866
|
get isZero(): boolean {
|
|
745
|
-
return this.valueOf() ===
|
|
867
|
+
return this.valueOf() === 0n;
|
|
746
868
|
}
|
|
747
869
|
|
|
748
870
|
/**
|
|
@@ -876,17 +998,18 @@ export class TimeSpan implements Stringer {
|
|
|
876
998
|
static readonly z = z.union([
|
|
877
999
|
z.object({ value: z.bigint() }).transform((v) => new TimeSpan(v.value)),
|
|
878
1000
|
z.string().transform((n) => new TimeSpan(BigInt(n))),
|
|
879
|
-
z.instanceof(Number).transform((n) => new TimeSpan(n)),
|
|
880
1001
|
z.number().transform((n) => new TimeSpan(n)),
|
|
881
1002
|
z.instanceof(TimeSpan),
|
|
882
1003
|
]);
|
|
883
1004
|
}
|
|
884
1005
|
|
|
885
1006
|
/** Rate represents a data rate in Hz. */
|
|
886
|
-
export class Rate
|
|
1007
|
+
export class Rate
|
|
1008
|
+
extends primitive.ValueExtension<number>
|
|
1009
|
+
implements primitive.Stringer
|
|
1010
|
+
{
|
|
887
1011
|
constructor(value: CrudeRate) {
|
|
888
|
-
|
|
889
|
-
else super(value);
|
|
1012
|
+
super(value.valueOf());
|
|
890
1013
|
}
|
|
891
1014
|
|
|
892
1015
|
/** @returns a pretty string representation of the rate in the format "X Hz". */
|
|
@@ -973,13 +1096,15 @@ export class Rate extends Number implements Stringer {
|
|
|
973
1096
|
/** A zod schema for validating and transforming rates */
|
|
974
1097
|
static readonly z = z.union([
|
|
975
1098
|
z.number().transform((n) => new Rate(n)),
|
|
976
|
-
z.instanceof(Number).transform((n) => new Rate(n)),
|
|
977
1099
|
z.instanceof(Rate),
|
|
978
1100
|
]);
|
|
979
1101
|
}
|
|
980
1102
|
|
|
981
1103
|
/** Density represents the number of bytes in a value. */
|
|
982
|
-
export class Density
|
|
1104
|
+
export class Density
|
|
1105
|
+
extends primitive.ValueExtension<number>
|
|
1106
|
+
implements primitive.Stringer
|
|
1107
|
+
{
|
|
983
1108
|
/**
|
|
984
1109
|
* Creates a Density representing the given number of bytes per value.
|
|
985
1110
|
*
|
|
@@ -988,14 +1113,25 @@ export class Density extends Number implements Stringer {
|
|
|
988
1113
|
* @returns A Density representing the given number of bytes per value.
|
|
989
1114
|
*/
|
|
990
1115
|
constructor(value: CrudeDensity) {
|
|
991
|
-
|
|
992
|
-
else super(value);
|
|
1116
|
+
super(value.valueOf());
|
|
993
1117
|
}
|
|
994
1118
|
|
|
1119
|
+
/**
|
|
1120
|
+
* Calculates the number of values in the given Size.
|
|
1121
|
+
*
|
|
1122
|
+
* @param size - The Size to calculate the value count from.
|
|
1123
|
+
* @returns The number of values in the given Size.
|
|
1124
|
+
*/
|
|
995
1125
|
length(size: Size): number {
|
|
996
1126
|
return size.valueOf() / this.valueOf();
|
|
997
1127
|
}
|
|
998
1128
|
|
|
1129
|
+
/**
|
|
1130
|
+
* Calculates a Size representing the given number of values.
|
|
1131
|
+
*
|
|
1132
|
+
* @param sampleCount - The number of values in the Size.
|
|
1133
|
+
* @returns A Size representing the given number of values.
|
|
1134
|
+
*/
|
|
999
1135
|
size(sampleCount: number): Size {
|
|
1000
1136
|
return new Size(sampleCount * this.valueOf());
|
|
1001
1137
|
}
|
|
@@ -1016,7 +1152,6 @@ export class Density extends Number implements Stringer {
|
|
|
1016
1152
|
/** A zod schema for validating and transforming densities */
|
|
1017
1153
|
static readonly z = z.union([
|
|
1018
1154
|
z.number().transform((n) => new Density(n)),
|
|
1019
|
-
z.instanceof(Number).transform((n) => new Density(n)),
|
|
1020
1155
|
z.instanceof(Density),
|
|
1021
1156
|
]);
|
|
1022
1157
|
}
|
|
@@ -1028,7 +1163,7 @@ export class Density extends Number implements Stringer {
|
|
|
1028
1163
|
* @property start - A TimeStamp representing the start of the range.
|
|
1029
1164
|
* @property end - A Timestamp representing the end of the range.
|
|
1030
1165
|
*/
|
|
1031
|
-
export class TimeRange implements Stringer {
|
|
1166
|
+
export class TimeRange implements primitive.Stringer {
|
|
1032
1167
|
/**
|
|
1033
1168
|
* The starting TimeStamp of the TimeRange.
|
|
1034
1169
|
*
|
|
@@ -1140,10 +1275,20 @@ export class TimeRange implements Stringer {
|
|
|
1140
1275
|
return startDist <= delta.valueOf() && endDist <= delta.valueOf();
|
|
1141
1276
|
}
|
|
1142
1277
|
|
|
1278
|
+
/**
|
|
1279
|
+
* Returns a string representation of the TimeRange.
|
|
1280
|
+
*
|
|
1281
|
+
* @returns A string representation of the TimeRange.
|
|
1282
|
+
*/
|
|
1143
1283
|
toString(): string {
|
|
1144
1284
|
return `${this.start.toString()} - ${this.end.toString()}`;
|
|
1145
1285
|
}
|
|
1146
1286
|
|
|
1287
|
+
/**
|
|
1288
|
+
* Returns a pretty string representation of the TimeRange.
|
|
1289
|
+
*
|
|
1290
|
+
* @returns A pretty string representation of the TimeRange.
|
|
1291
|
+
*/
|
|
1147
1292
|
toPrettyString(): string {
|
|
1148
1293
|
return `${this.start.fString("preciseDate")} - ${this.span.toString()}`;
|
|
1149
1294
|
}
|
|
@@ -1182,8 +1327,20 @@ export class TimeRange implements Stringer {
|
|
|
1182
1327
|
return overlapDuration.greaterThanOrEqual(delta);
|
|
1183
1328
|
}
|
|
1184
1329
|
|
|
1330
|
+
/**
|
|
1331
|
+
* Checks if the TimeRange contains the given TimeRange or TimeStamp.
|
|
1332
|
+
*
|
|
1333
|
+
* @param other - The TimeRange or TimeStamp to check if it is contained in the TimeRange.
|
|
1334
|
+
* @returns True if the TimeRange contains the given TimeRange or TimeStamp.
|
|
1335
|
+
*/
|
|
1185
1336
|
contains(other: TimeRange): boolean;
|
|
1186
1337
|
|
|
1338
|
+
/**
|
|
1339
|
+
* Checks if the TimeRange contains the given TimeStamp.
|
|
1340
|
+
*
|
|
1341
|
+
* @param ts - The TimeStamp to check if it is contained in the TimeRange.
|
|
1342
|
+
* @returns True if the TimeRange contains the given TimeStamp.
|
|
1343
|
+
*/
|
|
1187
1344
|
contains(ts: CrudeTimeStamp): boolean;
|
|
1188
1345
|
|
|
1189
1346
|
contains(other: TimeRange | CrudeTimeStamp): boolean {
|
|
@@ -1192,6 +1349,17 @@ export class TimeRange implements Stringer {
|
|
|
1192
1349
|
return this.start.beforeEq(other) && this.end.after(other);
|
|
1193
1350
|
}
|
|
1194
1351
|
|
|
1352
|
+
/**
|
|
1353
|
+
* Returns a new TimeRange that is bound by the given TimeRange.
|
|
1354
|
+
*
|
|
1355
|
+
* @param other - The TimeRange to bound by.
|
|
1356
|
+
* @returns A new TimeRange that is bound by the given TimeRange.
|
|
1357
|
+
* @example
|
|
1358
|
+
* const range = new TimeRange(new TimeStamp(1000), new TimeStamp(2000));
|
|
1359
|
+
* const other = new TimeRange(new TimeStamp(1500), new TimeStamp(2500));
|
|
1360
|
+
* const bounded = range.boundBy(other);
|
|
1361
|
+
* console.log(bounded); // TimeRange(1500, 2000)
|
|
1362
|
+
*/
|
|
1195
1363
|
boundBy(other: TimeRange): TimeRange {
|
|
1196
1364
|
const next = new TimeRange(this.start, this.end);
|
|
1197
1365
|
if (other.start.after(this.start)) next.start = other.start;
|
|
@@ -1224,41 +1392,41 @@ export class TimeRange implements Stringer {
|
|
|
1224
1392
|
.transform((v) => new TimeRange(v.start, v.end)),
|
|
1225
1393
|
z.instanceof(TimeRange),
|
|
1226
1394
|
]);
|
|
1227
|
-
}
|
|
1228
|
-
|
|
1229
|
-
export const sortTimeRange = (a: TimeRange, b: TimeRange): -1 | 0 | 1 => {
|
|
1230
|
-
if (a.start.before(b.start)) return -1;
|
|
1231
|
-
if (a.start.after(b.start)) return 1;
|
|
1232
|
-
if (a.end.before(b.end)) return -1;
|
|
1233
|
-
if (a.end.after(b.end)) return 1;
|
|
1234
|
-
return 0;
|
|
1235
|
-
};
|
|
1236
|
-
|
|
1237
|
-
/** DataType is a string that represents a data type. */
|
|
1238
|
-
export class DataType implements Stringer {
|
|
1239
|
-
readonly value: string;
|
|
1240
|
-
readonly encodeValue = true;
|
|
1241
1395
|
|
|
1242
|
-
|
|
1243
|
-
|
|
1396
|
+
/**
|
|
1397
|
+
* Sorts two time ranges. The range with the earlier start time is considered less than
|
|
1398
|
+
* the range with the later start time. If the start times are equal, the range with the
|
|
1399
|
+
* earlier end time is considered less than the range with the later end time.
|
|
1400
|
+
*
|
|
1401
|
+
* @param a - The first time range.
|
|
1402
|
+
* @param b - The second time range.
|
|
1403
|
+
* @returns A number indicating the order of the two time ranges. This number is
|
|
1404
|
+
* positive if a is earlier than b, negative if a is later than b, and 0 if they are
|
|
1405
|
+
* equal.
|
|
1406
|
+
*/
|
|
1407
|
+
static sort(a: TimeRange, b: TimeRange): number {
|
|
1408
|
+
return TimeStamp.sort(a.start, b.start) || TimeStamp.sort(a.end, b.end);
|
|
1244
1409
|
}
|
|
1410
|
+
}
|
|
1245
1411
|
|
|
1412
|
+
/** DataType is a string that represents a data type. */
|
|
1413
|
+
export class DataType
|
|
1414
|
+
extends primitive.ValueExtension<string>
|
|
1415
|
+
implements primitive.Stringer
|
|
1416
|
+
{
|
|
1246
1417
|
constructor(value: CrudeDataType) {
|
|
1247
1418
|
if (
|
|
1248
1419
|
value instanceof DataType ||
|
|
1249
1420
|
typeof value === "string" ||
|
|
1250
1421
|
typeof value.valueOf() === "string"
|
|
1251
|
-
)
|
|
1252
|
-
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
return;
|
|
1422
|
+
)
|
|
1423
|
+
super(value.valueOf() as string);
|
|
1424
|
+
else {
|
|
1425
|
+
const t = DataType.ARRAY_CONSTRUCTOR_DATA_TYPES.get(value.constructor.name);
|
|
1426
|
+
if (t == null)
|
|
1427
|
+
throw new Error(`unable to find data type for ${value.toString()}`);
|
|
1428
|
+
super(t.valueOf());
|
|
1259
1429
|
}
|
|
1260
|
-
this.value = DataType.UNKNOWN.valueOf();
|
|
1261
|
-
throw new Error(`unable to find data type for ${value.toString()}`);
|
|
1262
1430
|
}
|
|
1263
1431
|
|
|
1264
1432
|
/**
|
|
@@ -1290,31 +1458,60 @@ export class DataType implements Stringer {
|
|
|
1290
1458
|
return this.valueOf();
|
|
1291
1459
|
}
|
|
1292
1460
|
|
|
1461
|
+
/**
|
|
1462
|
+
* @returns true if the DataType has a variable density.
|
|
1463
|
+
* @example DataType.STRING.isVariable // true
|
|
1464
|
+
* @example DataType.INT32.isVariable // false
|
|
1465
|
+
*/
|
|
1293
1466
|
get isVariable(): boolean {
|
|
1294
1467
|
return this.equals(DataType.JSON) || this.equals(DataType.STRING);
|
|
1295
1468
|
}
|
|
1296
1469
|
|
|
1470
|
+
/**
|
|
1471
|
+
* @returns true if the DataType is numeric.
|
|
1472
|
+
* @example DataType.INT32.isNumeric // true
|
|
1473
|
+
* @example DataType.STRING.isNumeric // false
|
|
1474
|
+
*/
|
|
1297
1475
|
get isNumeric(): boolean {
|
|
1298
1476
|
return !this.isVariable && !this.equals(DataType.UUID);
|
|
1299
1477
|
}
|
|
1300
1478
|
|
|
1479
|
+
/**
|
|
1480
|
+
* @returns true if the DataType is an integer.
|
|
1481
|
+
* @example DataType.INT32.isInteger // true
|
|
1482
|
+
* @example DataType.FLOAT32.isInteger // false
|
|
1483
|
+
*/
|
|
1301
1484
|
get isInteger(): boolean {
|
|
1302
1485
|
const str = this.toString();
|
|
1303
1486
|
return str.startsWith("int") || str.startsWith("uint");
|
|
1304
1487
|
}
|
|
1305
1488
|
|
|
1489
|
+
/**
|
|
1490
|
+
* @returns true if the DataType is a floating point number.
|
|
1491
|
+
* @example DataType.FLOAT32.isFloat // true
|
|
1492
|
+
* @example DataType.INT32.isFloat // false
|
|
1493
|
+
*/
|
|
1306
1494
|
get isFloat(): boolean {
|
|
1307
1495
|
return this.toString().startsWith("float");
|
|
1308
1496
|
}
|
|
1309
1497
|
|
|
1498
|
+
/**
|
|
1499
|
+
* @returns the density of the DataType.
|
|
1500
|
+
* @example DataType.INT16.density // Density.BIT32
|
|
1501
|
+
* @example DataType.FLOAT32.density // Density.BIT32
|
|
1502
|
+
*/
|
|
1310
1503
|
get density(): Density {
|
|
1311
1504
|
const v = DataType.DENSITIES.get(this.toString());
|
|
1312
1505
|
if (v == null) throw new Error(`unable to find density for ${this.valueOf()}`);
|
|
1313
1506
|
return v;
|
|
1314
1507
|
}
|
|
1315
1508
|
|
|
1316
|
-
/**
|
|
1317
|
-
|
|
1509
|
+
/**
|
|
1510
|
+
* @returns true if the DataType is an unsigned integer.
|
|
1511
|
+
* @example DataType.UINT32.isUnsigned // true
|
|
1512
|
+
* @example DataType.INT32.isUnsigned // false
|
|
1513
|
+
*/
|
|
1514
|
+
get isUnsignedInteger(): boolean {
|
|
1318
1515
|
return (
|
|
1319
1516
|
this.equals(DataType.UINT8) ||
|
|
1320
1517
|
this.equals(DataType.UINT16) ||
|
|
@@ -1323,8 +1520,12 @@ export class DataType implements Stringer {
|
|
|
1323
1520
|
);
|
|
1324
1521
|
}
|
|
1325
1522
|
|
|
1326
|
-
/**
|
|
1327
|
-
|
|
1523
|
+
/**
|
|
1524
|
+
* @returns true if the DataType is a signed integer.
|
|
1525
|
+
* @example DataType.INT32.isSigned // true
|
|
1526
|
+
* @example DataType.UINT32.isSigned // false
|
|
1527
|
+
*/
|
|
1528
|
+
get isSignedInteger(): boolean {
|
|
1328
1529
|
return (
|
|
1329
1530
|
this.equals(DataType.INT8) ||
|
|
1330
1531
|
this.equals(DataType.INT16) ||
|
|
@@ -1338,7 +1539,7 @@ export class DataType implements Stringer {
|
|
|
1338
1539
|
if (this.equals(other)) return true;
|
|
1339
1540
|
if (!this.isNumeric || !other.isNumeric) return false;
|
|
1340
1541
|
if (this.isVariable || other.isVariable) return false;
|
|
1341
|
-
if (this.
|
|
1542
|
+
if (this.isUnsignedInteger && other.isSignedInteger) return false;
|
|
1342
1543
|
|
|
1343
1544
|
if (this.isFloat)
|
|
1344
1545
|
return other.isFloat && this.density.valueOf() <= other.density.valueOf();
|
|
@@ -1347,7 +1548,7 @@ export class DataType implements Stringer {
|
|
|
1347
1548
|
if (this.isInteger && other.isInteger)
|
|
1348
1549
|
return (
|
|
1349
1550
|
this.density.valueOf() <= other.density.valueOf() &&
|
|
1350
|
-
this.
|
|
1551
|
+
this.isUnsignedInteger === other.isUnsignedInteger
|
|
1351
1552
|
);
|
|
1352
1553
|
|
|
1353
1554
|
return false;
|
|
@@ -1359,10 +1560,17 @@ export class DataType implements Stringer {
|
|
|
1359
1560
|
return this.equals(other);
|
|
1360
1561
|
}
|
|
1361
1562
|
|
|
1362
|
-
|
|
1363
|
-
|
|
1563
|
+
/**
|
|
1564
|
+
* Checks whether the given TypedArray is of the same type as the DataType.
|
|
1565
|
+
*
|
|
1566
|
+
* @param array - The TypedArray to check.
|
|
1567
|
+
* @returns True if the TypedArray is of the same type as the DataType.
|
|
1568
|
+
*/
|
|
1569
|
+
checkArray(array: TypedArray): boolean {
|
|
1570
|
+
return array.constructor === this.Array;
|
|
1364
1571
|
}
|
|
1365
1572
|
|
|
1573
|
+
/** @returns true if the data type uses bigints to store values. */
|
|
1366
1574
|
get usesBigInt(): boolean {
|
|
1367
1575
|
return DataType.BIG_INT_TYPES.some((t) => t.equals(this));
|
|
1368
1576
|
}
|
|
@@ -1402,27 +1610,25 @@ export class DataType implements Stringer {
|
|
|
1402
1610
|
* newline character. */
|
|
1403
1611
|
static readonly JSON = new DataType("json");
|
|
1404
1612
|
|
|
1405
|
-
static readonly ARRAY_CONSTRUCTORS: Map<string, TypedArrayConstructor> =
|
|
1406
|
-
string,
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
1421
|
-
|
|
1422
|
-
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
static readonly ARRAY_CONSTRUCTOR_DATA_TYPES: Map<string, DataType> = new Map<
|
|
1613
|
+
private static readonly ARRAY_CONSTRUCTORS: Map<string, TypedArrayConstructor> =
|
|
1614
|
+
new Map<string, TypedArrayConstructor>([
|
|
1615
|
+
[DataType.UINT8.toString(), Uint8Array],
|
|
1616
|
+
[DataType.UINT16.toString(), Uint16Array],
|
|
1617
|
+
[DataType.UINT32.toString(), Uint32Array],
|
|
1618
|
+
[DataType.UINT64.toString(), BigUint64Array],
|
|
1619
|
+
[DataType.FLOAT32.toString(), Float32Array],
|
|
1620
|
+
[DataType.FLOAT64.toString(), Float64Array],
|
|
1621
|
+
[DataType.INT8.toString(), Int8Array],
|
|
1622
|
+
[DataType.INT16.toString(), Int16Array],
|
|
1623
|
+
[DataType.INT32.toString(), Int32Array],
|
|
1624
|
+
[DataType.INT64.toString(), BigInt64Array],
|
|
1625
|
+
[DataType.TIMESTAMP.toString(), BigInt64Array],
|
|
1626
|
+
[DataType.STRING.toString(), Uint8Array],
|
|
1627
|
+
[DataType.JSON.toString(), Uint8Array],
|
|
1628
|
+
[DataType.UUID.toString(), Uint8Array],
|
|
1629
|
+
]);
|
|
1630
|
+
|
|
1631
|
+
private static readonly ARRAY_CONSTRUCTOR_DATA_TYPES: Map<string, DataType> = new Map<
|
|
1426
1632
|
string,
|
|
1427
1633
|
DataType
|
|
1428
1634
|
>([
|
|
@@ -1438,7 +1644,7 @@ export class DataType implements Stringer {
|
|
|
1438
1644
|
[BigInt64Array.name, DataType.INT64],
|
|
1439
1645
|
]);
|
|
1440
1646
|
|
|
1441
|
-
static readonly DENSITIES = new Map<string, Density>([
|
|
1647
|
+
private static readonly DENSITIES = new Map<string, Density>([
|
|
1442
1648
|
[DataType.UINT8.toString(), Density.BIT8],
|
|
1443
1649
|
[DataType.UINT16.toString(), Density.BIT16],
|
|
1444
1650
|
[DataType.UINT32.toString(), Density.BIT32],
|
|
@@ -1484,9 +1690,12 @@ export class DataType implements Stringer {
|
|
|
1484
1690
|
}
|
|
1485
1691
|
|
|
1486
1692
|
/**
|
|
1487
|
-
* The Size of an
|
|
1693
|
+
* The Size of an element in bytes.
|
|
1488
1694
|
*/
|
|
1489
|
-
export class Size
|
|
1695
|
+
export class Size
|
|
1696
|
+
extends primitive.ValueExtension<number>
|
|
1697
|
+
implements primitive.Stringer
|
|
1698
|
+
{
|
|
1490
1699
|
constructor(value: CrudeSize) {
|
|
1491
1700
|
super(value.valueOf());
|
|
1492
1701
|
}
|
|
@@ -1501,38 +1710,47 @@ export class Size extends Number implements Stringer {
|
|
|
1501
1710
|
return this.valueOf() < other.valueOf();
|
|
1502
1711
|
}
|
|
1503
1712
|
|
|
1713
|
+
/** @returns a new Size representing the sum of the two Sizes. */
|
|
1504
1714
|
add(other: CrudeSize): Size {
|
|
1505
1715
|
return Size.bytes(this.valueOf() + other.valueOf());
|
|
1506
1716
|
}
|
|
1507
1717
|
|
|
1718
|
+
/** @returns a new Size representing the difference of the two Sizes. */
|
|
1508
1719
|
sub(other: CrudeSize): Size {
|
|
1509
1720
|
return Size.bytes(this.valueOf() - other.valueOf());
|
|
1510
1721
|
}
|
|
1511
1722
|
|
|
1723
|
+
/** @returns a new Size representing the truncated value of the Size. */
|
|
1512
1724
|
truncate(span: CrudeSize): Size {
|
|
1513
1725
|
return new Size(Math.trunc(this.valueOf() / span.valueOf()) * span.valueOf());
|
|
1514
1726
|
}
|
|
1515
1727
|
|
|
1728
|
+
/** @returns a new Size representing the remainder of the Size. */
|
|
1516
1729
|
remainder(span: CrudeSize): Size {
|
|
1517
1730
|
return Size.bytes(this.valueOf() % span.valueOf());
|
|
1518
1731
|
}
|
|
1519
1732
|
|
|
1733
|
+
/** @returns the number of gigabytes in the Size. */
|
|
1520
1734
|
get gigabytes(): number {
|
|
1521
1735
|
return this.valueOf() / Size.GIGABYTE.valueOf();
|
|
1522
1736
|
}
|
|
1523
1737
|
|
|
1738
|
+
/** @returns the number of megabytes in the Size. */
|
|
1524
1739
|
get megabytes(): number {
|
|
1525
1740
|
return this.valueOf() / Size.MEGABYTE.valueOf();
|
|
1526
1741
|
}
|
|
1527
1742
|
|
|
1743
|
+
/** @returns the number of kilobytes in the Size. */
|
|
1528
1744
|
get kilobytes(): number {
|
|
1529
1745
|
return this.valueOf() / Size.KILOBYTE.valueOf();
|
|
1530
1746
|
}
|
|
1531
1747
|
|
|
1748
|
+
/** @returns the number of terabytes in the Size. */
|
|
1532
1749
|
get terabytes(): number {
|
|
1533
1750
|
return this.valueOf() / Size.TERABYTE.valueOf();
|
|
1534
1751
|
}
|
|
1535
1752
|
|
|
1753
|
+
/** @returns a nicely formatted string representation of the Size. */
|
|
1536
1754
|
toString(): string {
|
|
1537
1755
|
const totalTB = this.truncate(Size.TERABYTE);
|
|
1538
1756
|
const totalGB = this.truncate(Size.GIGABYTE);
|
|
@@ -1627,6 +1845,7 @@ export class Size extends Number implements Stringer {
|
|
|
1627
1845
|
z.instanceof(Size),
|
|
1628
1846
|
]);
|
|
1629
1847
|
|
|
1848
|
+
/** @returns true if the Size is zero. */
|
|
1630
1849
|
get isZero(): boolean {
|
|
1631
1850
|
return this.valueOf() === 0;
|
|
1632
1851
|
}
|
|
@@ -1634,31 +1853,22 @@ export class Size extends Number implements Stringer {
|
|
|
1634
1853
|
|
|
1635
1854
|
export type CrudeTimeStamp =
|
|
1636
1855
|
| bigint
|
|
1637
|
-
| BigInt
|
|
1638
1856
|
| TimeStamp
|
|
1639
1857
|
| TimeSpan
|
|
1640
1858
|
| number
|
|
1641
1859
|
| Date
|
|
1642
1860
|
| string
|
|
1643
|
-
| DateComponents
|
|
1644
|
-
| Number;
|
|
1861
|
+
| DateComponents;
|
|
1645
1862
|
export type TimeStampT = number;
|
|
1646
|
-
export type CrudeTimeSpan =
|
|
1647
|
-
| bigint
|
|
1648
|
-
| BigInt
|
|
1649
|
-
| TimeSpan
|
|
1650
|
-
| TimeStamp
|
|
1651
|
-
| number
|
|
1652
|
-
| Number
|
|
1653
|
-
| Rate;
|
|
1863
|
+
export type CrudeTimeSpan = bigint | TimeSpan | TimeStamp | number | Rate;
|
|
1654
1864
|
export type TimeSpanT = number;
|
|
1655
|
-
export type CrudeRate = Rate | number
|
|
1865
|
+
export type CrudeRate = Rate | number;
|
|
1656
1866
|
export type RateT = number;
|
|
1657
|
-
export type CrudeDensity = Density | number
|
|
1867
|
+
export type CrudeDensity = Density | number;
|
|
1658
1868
|
export type DensityT = number;
|
|
1659
1869
|
export type CrudeDataType = DataType | string | TypedArray;
|
|
1660
1870
|
export type DataTypeT = string;
|
|
1661
|
-
export type CrudeSize = Size | number
|
|
1871
|
+
export type CrudeSize = Size | number;
|
|
1662
1872
|
export type SizeT = number;
|
|
1663
1873
|
export interface CrudeTimeRange {
|
|
1664
1874
|
start: CrudeTimeStamp;
|
|
@@ -1727,11 +1937,11 @@ export const convertDataType = (
|
|
|
1727
1937
|
target: DataType,
|
|
1728
1938
|
value: math.Numeric,
|
|
1729
1939
|
offset: math.Numeric = 0,
|
|
1730
|
-
): math.
|
|
1940
|
+
): math.Numeric => {
|
|
1731
1941
|
if (source.usesBigInt && !target.usesBigInt) return Number(value) - Number(offset);
|
|
1732
1942
|
if (!source.usesBigInt && target.usesBigInt)
|
|
1733
1943
|
return BigInt(value.valueOf()) - BigInt(offset.valueOf());
|
|
1734
|
-
return addSamples(value, -offset)
|
|
1944
|
+
return addSamples(value, -offset);
|
|
1735
1945
|
};
|
|
1736
1946
|
|
|
1737
1947
|
export const addSamples = (a: math.Numeric, b: math.Numeric): math.Numeric => {
|