@synnaxlabs/x 0.47.0 → 0.49.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.
Files changed (244) hide show
  1. package/.turbo/turbo-build.log +7 -105
  2. package/dist/src/deep/join.d.ts.map +1 -0
  3. package/dist/src/deep/path.d.ts +1 -1
  4. package/dist/src/deep/path.d.ts.map +1 -1
  5. package/dist/src/destructor/destructor.d.ts +7 -0
  6. package/dist/src/destructor/destructor.d.ts.map +1 -0
  7. package/dist/src/destructor/index.d.ts +2 -0
  8. package/dist/src/destructor/index.d.ts.map +1 -0
  9. package/dist/src/index.d.ts +5 -10
  10. package/dist/src/index.d.ts.map +1 -1
  11. package/dist/src/math/constants.d.ts +1 -0
  12. package/dist/src/math/constants.d.ts.map +1 -1
  13. package/dist/src/migrate/migrate.d.ts +4 -4
  14. package/dist/src/migrate/migrate.d.ts.map +1 -1
  15. package/dist/src/narrow/index.d.ts +2 -0
  16. package/dist/src/narrow/index.d.ts.map +1 -0
  17. package/dist/src/narrow/narrow.d.ts +4 -0
  18. package/dist/src/narrow/narrow.d.ts.map +1 -0
  19. package/dist/src/narrow/narrow.spec.d.ts +2 -0
  20. package/dist/src/narrow/narrow.spec.d.ts.map +1 -0
  21. package/dist/src/numeric/numeric.d.ts +0 -1
  22. package/dist/src/numeric/numeric.d.ts.map +1 -1
  23. package/dist/src/observe/observe.d.ts +4 -4
  24. package/dist/src/observe/observe.d.ts.map +1 -1
  25. package/dist/src/optional/index.d.ts +2 -0
  26. package/dist/src/optional/index.d.ts.map +1 -0
  27. package/dist/src/optional/optional.d.ts.map +1 -0
  28. package/dist/src/scheduler/index.d.ts +2 -0
  29. package/dist/src/scheduler/index.d.ts.map +1 -0
  30. package/dist/src/{flush.d.ts → scheduler/scheduler.d.ts} +1 -1
  31. package/dist/src/scheduler/scheduler.d.ts.map +1 -0
  32. package/dist/src/scheduler/scheduler.spec.d.ts +2 -0
  33. package/dist/src/scheduler/scheduler.spec.d.ts.map +1 -0
  34. package/dist/src/shallow/copy.d.ts +2 -0
  35. package/dist/src/shallow/copy.d.ts.map +1 -0
  36. package/dist/src/shallow/copy.spec.d.ts +2 -0
  37. package/dist/src/shallow/copy.spec.d.ts.map +1 -0
  38. package/dist/src/shallow/index.d.ts +2 -0
  39. package/dist/src/shallow/index.d.ts.map +1 -0
  40. package/dist/src/spatial/base.d.ts +5 -38
  41. package/dist/src/spatial/base.d.ts.map +1 -1
  42. package/dist/src/spatial/direction/direction.d.ts +2 -1
  43. package/dist/src/spatial/direction/direction.d.ts.map +1 -1
  44. package/dist/src/spatial/external.d.ts +2 -1
  45. package/dist/src/spatial/external.d.ts.map +1 -1
  46. package/dist/src/spatial/location/location.d.ts +2 -2
  47. package/dist/src/spatial/location/location.d.ts.map +1 -1
  48. package/dist/src/spatial/sticky/index.d.ts +2 -0
  49. package/dist/src/spatial/sticky/index.d.ts.map +1 -0
  50. package/dist/src/spatial/sticky/sticky.d.ts +74 -0
  51. package/dist/src/spatial/sticky/sticky.d.ts.map +1 -0
  52. package/dist/src/spatial/sticky/sticky.spec.d.ts +2 -0
  53. package/dist/src/spatial/sticky/sticky.spec.d.ts.map +1 -0
  54. package/dist/src/spatial/xy/xy.d.ts +10 -2
  55. package/dist/src/spatial/xy/xy.d.ts.map +1 -1
  56. package/dist/src/status/status.d.ts +2 -2
  57. package/dist/src/status/status.d.ts.map +1 -1
  58. package/dist/src/telem/series.d.ts +4 -4
  59. package/dist/src/telem/series.d.ts.map +1 -1
  60. package/dist/src/telem/telem.d.ts +14 -1
  61. package/dist/src/telem/telem.d.ts.map +1 -1
  62. package/dist/src/types/index.d.ts +2 -0
  63. package/dist/src/types/index.d.ts.map +1 -0
  64. package/dist/src/zod/external.d.ts +1 -0
  65. package/dist/src/zod/external.d.ts.map +1 -1
  66. package/dist/src/zod/schemas.d.ts +3 -0
  67. package/dist/src/zod/schemas.d.ts.map +1 -0
  68. package/dist/src/zod/schemas.spec.d.ts +2 -0
  69. package/dist/src/zod/schemas.spec.d.ts.map +1 -0
  70. package/dist/x.cjs +12 -0
  71. package/dist/x.js +5521 -0
  72. package/package.json +12 -150
  73. package/src/binary/codec.ts +2 -2
  74. package/src/deep/merge.ts +3 -3
  75. package/src/deep/path.ts +1 -1
  76. package/src/{destructor.ts → destructor/destructor.ts} +1 -1
  77. package/src/{invert.ts → destructor/index.ts} +1 -1
  78. package/src/index.ts +5 -10
  79. package/src/math/constants.ts +1 -0
  80. package/src/migrate/migrate.spec.ts +238 -0
  81. package/src/migrate/migrate.ts +67 -7
  82. package/src/{mock → narrow}/index.ts +1 -1
  83. package/src/narrow/narrow.spec.ts +70 -0
  84. package/src/{identity.ts → narrow/narrow.ts} +6 -0
  85. package/src/numeric/numeric.ts +0 -5
  86. package/src/observe/observe.ts +4 -4
  87. package/src/{replace.ts → optional/index.ts} +1 -1
  88. package/src/scheduler/index.ts +10 -0
  89. package/src/scheduler/scheduler.spec.ts +82 -0
  90. package/src/shallow/copy.spec.ts +141 -0
  91. package/src/{shallowCopy.ts → shallow/copy.ts} +1 -1
  92. package/src/shallow/index.ts +10 -0
  93. package/src/spatial/base.ts +6 -15
  94. package/src/spatial/direction/direction.ts +2 -0
  95. package/src/spatial/external.ts +2 -1
  96. package/src/spatial/location/location.spec.ts +16 -0
  97. package/src/spatial/location/location.ts +7 -7
  98. package/src/spatial/sticky/index.ts +10 -0
  99. package/src/spatial/sticky/sticky.spec.ts +584 -0
  100. package/src/spatial/sticky/sticky.ts +98 -0
  101. package/src/spatial/xy/xy.spec.ts +55 -0
  102. package/src/spatial/xy/xy.ts +27 -2
  103. package/src/status/status.ts +5 -5
  104. package/src/telem/series.ts +5 -6
  105. package/src/telem/telem.spec.ts +87 -28
  106. package/src/telem/telem.ts +49 -9
  107. package/src/{clamp → types}/index.ts +1 -1
  108. package/src/zod/external.ts +1 -0
  109. package/src/zod/schemas.spec.ts +51 -0
  110. package/src/zod/schemas.ts +14 -0
  111. package/tsconfig.tsbuildinfo +1 -1
  112. package/vite.config.ts +1 -36
  113. package/dist/array.cjs +0 -1
  114. package/dist/array.js +0 -4
  115. package/dist/base-DRybODwJ.js +0 -42
  116. package/dist/base-KIBsp6TI.cjs +0 -1
  117. package/dist/binary.cjs +0 -1
  118. package/dist/binary.js +0 -4
  119. package/dist/bounds-4BWKPqaP.js +0 -183
  120. package/dist/bounds-C2TKFgVk.cjs +0 -1
  121. package/dist/bounds.cjs +0 -1
  122. package/dist/bounds.js +0 -4
  123. package/dist/box-BXWXSkKu.js +0 -203
  124. package/dist/box-rH3ggwXk.cjs +0 -1
  125. package/dist/box.cjs +0 -1
  126. package/dist/box.js +0 -4
  127. package/dist/caseconv.cjs +0 -1
  128. package/dist/caseconv.js +0 -4
  129. package/dist/change-C-YELKx6.cjs +0 -1
  130. package/dist/change-DLl6DccR.js +0 -12
  131. package/dist/change.cjs +0 -1
  132. package/dist/change.js +0 -4
  133. package/dist/compare-Bnx9CdjS.js +0 -119
  134. package/dist/compare-GPoFaKRW.cjs +0 -1
  135. package/dist/compare.cjs +0 -1
  136. package/dist/compare.js +0 -36
  137. package/dist/debounce.cjs +0 -1
  138. package/dist/debounce.js +0 -17
  139. package/dist/deep.cjs +0 -1
  140. package/dist/deep.js +0 -247
  141. package/dist/destructor.cjs +0 -1
  142. package/dist/destructor.js +0 -1
  143. package/dist/dimensions-Cg5Owbwn.cjs +0 -1
  144. package/dist/dimensions-DC0uLPwn.js +0 -43
  145. package/dist/dimensions.cjs +0 -1
  146. package/dist/dimensions.js +0 -4
  147. package/dist/direction-C_b4tfRN.js +0 -19
  148. package/dist/direction-DqQB9M37.cjs +0 -1
  149. package/dist/direction.cjs +0 -1
  150. package/dist/direction.js +0 -4
  151. package/dist/external-2YWy569j.js +0 -23
  152. package/dist/external-B6edOwoQ.cjs +0 -1
  153. package/dist/external-B80i4ymZ.js +0 -29
  154. package/dist/external-B9AAGv50.cjs +0 -1
  155. package/dist/external-BYuXBYJh.js +0 -40
  156. package/dist/external-BxmTQZ6m.cjs +0 -1
  157. package/dist/external-DLiGrXn7.cjs +0 -1
  158. package/dist/external-Du5qzfYv.js +0 -35
  159. package/dist/get-CtJEJIC_.js +0 -82
  160. package/dist/get-D2VRwUw4.cjs +0 -1
  161. package/dist/identity.cjs +0 -1
  162. package/dist/identity.js +0 -4
  163. package/dist/index-Bfvg0v-N.cjs +0 -3
  164. package/dist/index-Bv029kh3.js +0 -19
  165. package/dist/index-CqisIWWC.cjs +0 -1
  166. package/dist/index-CyNZHQFw.cjs +0 -1
  167. package/dist/index-qmkoZBNO.js +0 -57
  168. package/dist/index-yz34Wc2p.js +0 -92
  169. package/dist/index.cjs +0 -5
  170. package/dist/index.js +0 -985
  171. package/dist/kv.cjs +0 -1
  172. package/dist/kv.js +0 -4
  173. package/dist/link.cjs +0 -1
  174. package/dist/link.js +0 -10
  175. package/dist/location-0qDBiCqP.cjs +0 -1
  176. package/dist/location-BIzpxczO.js +0 -95
  177. package/dist/location.cjs +0 -1
  178. package/dist/location.js +0 -4
  179. package/dist/observe.cjs +0 -1
  180. package/dist/observe.js +0 -48
  181. package/dist/record-BwjIgrpU.cjs +0 -1
  182. package/dist/record-tSFQKmdG.js +0 -19
  183. package/dist/record.cjs +0 -1
  184. package/dist/record.js +0 -4
  185. package/dist/runtime.cjs +0 -1
  186. package/dist/runtime.js +0 -4
  187. package/dist/scale-BXy1w8R_.cjs +0 -1
  188. package/dist/scale-DJCMZbfU.js +0 -228
  189. package/dist/scale.cjs +0 -1
  190. package/dist/scale.js +0 -4
  191. package/dist/series-Bh0pHoUF.cjs +0 -6
  192. package/dist/series-Cf8rT2IX.js +0 -2810
  193. package/dist/spatial-DnsaOypA.js +0 -11
  194. package/dist/spatial-DrxzaD5U.cjs +0 -1
  195. package/dist/spatial.cjs +0 -1
  196. package/dist/spatial.js +0 -18
  197. package/dist/src/clamp/index.d.ts +0 -2
  198. package/dist/src/clamp/index.d.ts.map +0 -1
  199. package/dist/src/destructor.d.ts +0 -7
  200. package/dist/src/destructor.d.ts.map +0 -1
  201. package/dist/src/flush.d.ts.map +0 -1
  202. package/dist/src/identity.d.ts +0 -3
  203. package/dist/src/identity.d.ts.map +0 -1
  204. package/dist/src/invert.d.ts +0 -2
  205. package/dist/src/invert.d.ts.map +0 -1
  206. package/dist/src/join.d.ts.map +0 -1
  207. package/dist/src/mock/index.d.ts +0 -2
  208. package/dist/src/mock/index.d.ts.map +0 -1
  209. package/dist/src/optional.d.ts.map +0 -1
  210. package/dist/src/renderable.d.ts +0 -5
  211. package/dist/src/renderable.d.ts.map +0 -1
  212. package/dist/src/replace.d.ts +0 -2
  213. package/dist/src/replace.d.ts.map +0 -1
  214. package/dist/src/shallowCopy.d.ts +0 -2
  215. package/dist/src/shallowCopy.d.ts.map +0 -1
  216. package/dist/src/telem/generate.d.ts +0 -3
  217. package/dist/src/telem/generate.d.ts.map +0 -1
  218. package/dist/src/transform.d.ts +0 -6
  219. package/dist/src/transform.d.ts.map +0 -1
  220. package/dist/src/undefined.d.ts +0 -2
  221. package/dist/src/undefined.d.ts.map +0 -1
  222. package/dist/telem.cjs +0 -1
  223. package/dist/telem.js +0 -18
  224. package/dist/unique.cjs +0 -1
  225. package/dist/unique.js +0 -4
  226. package/dist/url.cjs +0 -1
  227. package/dist/url.js +0 -51
  228. package/dist/worker.cjs +0 -1
  229. package/dist/worker.js +0 -43
  230. package/dist/xy-C-MUIjVs.cjs +0 -1
  231. package/dist/xy-DnrCAZaw.js +0 -154
  232. package/dist/xy.cjs +0 -1
  233. package/dist/xy.js +0 -4
  234. package/dist/zod.cjs +0 -1
  235. package/dist/zod.js +0 -4
  236. package/src/renderable.ts +0 -20
  237. package/src/telem/generate.ts +0 -17
  238. package/src/transform.ts +0 -17
  239. package/src/undefined.ts +0 -14
  240. /package/dist/src/{join.d.ts → deep/join.d.ts} +0 -0
  241. /package/dist/src/{optional.d.ts → optional/optional.d.ts} +0 -0
  242. /package/src/{join.ts → deep/join.ts} +0 -0
  243. /package/src/{optional.ts → optional/optional.ts} +0 -0
  244. /package/src/{flush.ts → scheduler/scheduler.ts} +0 -0
@@ -1,2810 +0,0 @@
1
- import { z as o } from "zod";
2
- import { J as k } from "./index-yz34Wc2p.js";
3
- import { s as ft } from "./index-qmkoZBNO.js";
4
- import { V as R, i as U, n as ct } from "./compare-Bnx9CdjS.js";
5
- import { a as P, s as F, m as C, d as Y, c as L, e as X, f as $, g as ht, t as dt, h as gt } from "./bounds-4BWKPqaP.js";
6
- import "./box-BXWXSkKu.js";
7
- import "./dimensions-DC0uLPwn.js";
8
- import "./base-DRybODwJ.js";
9
- import "./location-BIzpxczO.js";
10
- import "./scale-DJCMZbfU.js";
11
- import "./xy-DnrCAZaw.js";
12
- let _ = (u, t = 21) => (e = t) => {
13
- let s = "", i = e | 0;
14
- for (; i--; )
15
- s += u[Math.random() * u.length | 0];
16
- return s;
17
- };
18
- const tt = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", Ot = `0123456789${tt}`, et = 11, wt = _(tt, 1), bt = _(Ot, et - 1), st = () => `${wt()}${bt()}`, Dt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
19
- __proto__: null,
20
- LENGTH: et,
21
- create: st
22
- }, Symbol.toStringTag, { value: "Module" })), nt = (u, t) => (e) => e instanceof t || typeof e == "object" && e !== null && "discriminator" in e && e.discriminator === u, zt = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
23
- __proto__: null,
24
- createMatcher: nt
25
- }, Symbol.toStringTag, { value: "Module" })), It = o.enum(["static", "dynamic"]), _t = 2 ** 8 - 1, te = 2 ** 16 - 1, ee = 2 ** 32 - 1, se = 2n ** 64n - 1n, ne = 2 ** 64 - 1, re = -128, ie = 2 ** 7 - 1, ae = -32768, ue = 2 ** 15 - 1, oe = -2147483648, le = 2 ** 31 - 1, fe = -(2n ** 63n), G = 2n ** 63n - 1n, ce = -9223372036854776e3, Nt = 2 ** 63 - 1, K = 365, p = 30, mt = o.union([
26
- o.tuple([o.int()]),
27
- o.tuple([o.int(), o.int().min(1).max(12)]),
28
- o.tuple([o.int(), o.int().min(1).max(12), o.int().min(1).max(31)])
29
- ]), rt = (u, t) => {
30
- const e = new r(t);
31
- if (![
32
- a.DAY,
33
- a.HOUR,
34
- a.MINUTE,
35
- a.SECOND,
36
- a.MILLISECOND,
37
- a.MICROSECOND,
38
- a.NANOSECOND
39
- ].some((i) => i.equals(e)))
40
- throw new Error(
41
- "Invalid argument for remainder. Must be an even TimeSpan or Timestamp"
42
- );
43
- const s = u.valueOf() % e.valueOf();
44
- return u instanceof r ? new r(s) : new a(s);
45
- };
46
- class r extends R {
47
- constructor(t, e = "UTC") {
48
- if (t == null) super(r.now().valueOf());
49
- else if (t instanceof Date)
50
- super(BigInt(t.getTime()) * r.MILLISECOND.valueOf());
51
- else if (typeof t == "string")
52
- super(r.parseDateTimeString(t, e).valueOf());
53
- else if (Array.isArray(t)) super(r.parseDate(t));
54
- else {
55
- let s = 0n;
56
- t instanceof Number && (t = t.valueOf()), e === "local" && (s = r.utcOffset.valueOf()), typeof t == "number" && (isFinite(t) ? t === Nt ? t = G : t = Math.trunc(t) : (isNaN(t) && (t = 0), t === 1 / 0 ? t = r.MAX : t = r.MIN)), U(t) && (t = t.value), super(BigInt(t.valueOf()) + s);
57
- }
58
- }
59
- static parseDate([t = 1970, e = 1, s = 1]) {
60
- const i = new Date(t, e - 1, s, 0, 0, 0, 0);
61
- return new r(BigInt(i.getTime()) * r.MILLISECOND.valueOf()).truncate(r.DAY).valueOf();
62
- }
63
- /**
64
- * @returns the primitive value of the TimeStamp. Overrides standard JS valueOf()
65
- * method.
66
- */
67
- valueOf() {
68
- return this.value;
69
- }
70
- static parseTimeString(t, e = "UTC") {
71
- const [s, i, l] = t.split(":");
72
- let h = "00", M = "00";
73
- l != null && ([h, M] = l.split("."));
74
- let y = r.hours(parseInt(s ?? "00")).add(r.minutes(parseInt(i ?? "00"))).add(r.seconds(parseInt(h ?? "00"))).add(r.milliseconds(parseInt(M ?? "00")));
75
- return e === "local" && (y = y.add(r.utcOffset)), y.valueOf();
76
- }
77
- static parseDateTimeString(t, e = "UTC") {
78
- if (!t.includes("/") && !t.includes("-"))
79
- return r.parseTimeString(t, e);
80
- const s = new Date(t);
81
- return t.includes(":") || s.setUTCHours(0, 0, 0, 0), new r(
82
- BigInt(s.getTime()) * r.MILLISECOND.valueOf(),
83
- e
84
- ).valueOf();
85
- }
86
- toISOString(t = "UTC") {
87
- return t === "UTC" ? this.date().toISOString() : this.sub(r.utcOffset).date().toISOString();
88
- }
89
- timeString(t = !1, e = "UTC") {
90
- const s = this.toISOString(e);
91
- return t ? s.slice(11, 23) : s.slice(11, 19);
92
- }
93
- dateString() {
94
- const t = this.date(), e = t.toLocaleString("default", { month: "short" }), s = t.toLocaleString("default", { day: "numeric" });
95
- return `${e} ${s}`;
96
- }
97
- /** @returns The UTC offset for the time zone of the machine. */
98
- static get utcOffset() {
99
- return new a(
100
- BigInt((/* @__PURE__ */ new Date()).getTimezoneOffset()) * r.MINUTE.valueOf()
101
- );
102
- }
103
- /**
104
- * @returns a TimeSpan representing the amount time elapsed since
105
- * the other timestamp.
106
- * @param other - The other timestamp.
107
- */
108
- static since(t) {
109
- return new r().span(t);
110
- }
111
- /** @returns A JavaScript Date object representing the TimeStamp. */
112
- date() {
113
- return new Date(this.milliseconds);
114
- }
115
- /**
116
- * Checks if the TimeStamp is equal to another TimeStamp.
117
- *
118
- * @param other - The other TimeStamp to compare to.
119
- * @returns True if the TimeStamps are equal, false otherwise.
120
- */
121
- equals(t) {
122
- return this.valueOf() === new r(t).valueOf();
123
- }
124
- /**
125
- * Creates a TimeSpan representing the duration between the two timestamps.
126
- *
127
- * @param other - The other TimeStamp to compare to.
128
- * @returns A TimeSpan representing the duration between the two timestamps.
129
- * The span is guaranteed to be positive.
130
- */
131
- span(t) {
132
- return this.range(t).span;
133
- }
134
- /**
135
- * Creates a TimeRange spanning the given TimeStamp.
136
- *
137
- * @param other - The other TimeStamp to compare to.
138
- * @returns A TimeRange spanning the given TimeStamp that is guaranteed to be
139
- * valid, regardless of the TimeStamp order.
140
- */
141
- range(t) {
142
- return new m(this, t).makeValid();
143
- }
144
- /**
145
- * Creates a TimeRange starting at the TimeStamp and spanning the given
146
- * TimeSpan.
147
- *
148
- * @param other - The TimeSpan to span.
149
- * @returns A TimeRange starting at the TimeStamp and spanning the given
150
- * TimeSpan. The TimeRange is guaranteed to be valid.
151
- */
152
- spanRange(t) {
153
- return this.range(this.add(t)).makeValid();
154
- }
155
- /**
156
- * Checks if the TimeStamp represents the unix epoch.
157
- *
158
- * @returns True if the TimeStamp represents the unix epoch, false otherwise.
159
- */
160
- get isZero() {
161
- return this.valueOf() === 0n;
162
- }
163
- /**
164
- * Checks if the TimeStamp is after the given TimeStamp.
165
- *
166
- * @param other - The other TimeStamp to compare to.
167
- * @returns True if the TimeStamp is after the given TimeStamp, false
168
- * otherwise.
169
- */
170
- after(t) {
171
- return this.valueOf() > new r(t).valueOf();
172
- }
173
- /**
174
- * Checks if the TimeStamp is after or equal to the given TimeStamp.
175
- *
176
- * @param other - The other TimeStamp to compare to.
177
- * @returns True if the TimeStamp is after or equal to the given TimeStamp,
178
- * false otherwise.
179
- */
180
- afterEq(t) {
181
- return this.valueOf() >= new r(t).valueOf();
182
- }
183
- /**
184
- * Checks if the TimeStamp is before the given TimeStamp.
185
- *
186
- * @param other - The other TimeStamp to compare to.
187
- * @returns True if the TimeStamp is before the given TimeStamp, false
188
- * otherwise.
189
- */
190
- before(t) {
191
- return this.valueOf() < new r(t).valueOf();
192
- }
193
- /**
194
- * Checks if TimeStamp is before or equal to the current timestamp.
195
- *
196
- * @param other - The other TimeStamp to compare to.
197
- * @returns True if TimeStamp is before or equal to the current timestamp,
198
- * false otherwise.
199
- */
200
- beforeEq(t) {
201
- return this.valueOf() <= new r(t).valueOf();
202
- }
203
- /**
204
- * Adds a TimeSpan to the TimeStamp.
205
- *
206
- * @param span - The TimeSpan to add.
207
- * @returns A new TimeStamp representing the sum of the TimeStamp and
208
- * TimeSpan.
209
- */
210
- add(t) {
211
- return new r(P(this.valueOf(), new a(t).valueOf()));
212
- }
213
- /**
214
- * Subtracts a TimeSpan from the TimeStamp.
215
- *
216
- * @param span - The TimeSpan to subtract.
217
- * @returns A new TimeStamp representing the difference of the TimeStamp and
218
- * TimeSpan.
219
- */
220
- sub(t) {
221
- return new r(F(this.valueOf(), new a(t).valueOf()));
222
- }
223
- /**
224
- * @returns the floating point number of hours since the unix epoch to the timestamp
225
- * value.
226
- */
227
- get hours() {
228
- return Number(this.valueOf()) / Number(a.HOUR.valueOf());
229
- }
230
- /**
231
- * @returns the floating point number of minutes since the unix epoch to the timestamp
232
- * value.
233
- */
234
- get minutes() {
235
- return Number(this.valueOf()) / Number(a.MINUTE.valueOf());
236
- }
237
- /**
238
- * @returns the floating point number of days since the unix epoch to the timestamp
239
- * value.
240
- */
241
- get days() {
242
- return Number(this.valueOf()) / Number(a.DAY.valueOf());
243
- }
244
- /**
245
- * @returns the floating point number of seconds since the unix epoch to the timestamp
246
- * value.
247
- */
248
- get seconds() {
249
- return Number(this.valueOf()) / Number(a.SECOND.valueOf());
250
- }
251
- /** @returns the floating point number of milliseconds since the unix epoch. */
252
- get milliseconds() {
253
- return Number(this.valueOf()) / Number(r.MILLISECOND.valueOf());
254
- }
255
- /** @returns the floating point number of microseconds since the unix epoch. */
256
- get microseconds() {
257
- return Number(this.valueOf()) / Number(r.MICROSECOND.valueOf());
258
- }
259
- /**
260
- * @returns the floating point number of nanoseconds since the unix epoch.
261
- * Note that since we're converting to float64, this reduces the resolution
262
- * to a quarter of a microsecond.
263
- */
264
- get nanoseconds() {
265
- return Number(this.valueOf());
266
- }
267
- /** @returns the integer year that the timestamp corresponds to. */
268
- get year() {
269
- return this.date().getUTCFullYear();
270
- }
271
- /**
272
- * @returns a copy of the timestamp with the year changed.
273
- * @param year the value to set the year to.
274
- */
275
- setYear(t) {
276
- const e = this.date();
277
- return e.setUTCFullYear(t), new r(e);
278
- }
279
- /** @returns the integer month that the timestamp corresponds to with its year. */
280
- get month() {
281
- return this.date().getUTCMonth();
282
- }
283
- /**
284
- * @returns a copy of the timestamp with the month changed.
285
- * @param month the value to set the month to.
286
- */
287
- setMonth(t) {
288
- const e = this.date();
289
- return e.setUTCMonth(t), new r(e);
290
- }
291
- /** @returns the integer day that the timestamp corresponds to within its month. */
292
- get day() {
293
- return this.date().getUTCDate();
294
- }
295
- /**
296
- * @returns a copy of the timestamp with the day changed.
297
- * @param day the value the set the day to.
298
- */
299
- setDay(t) {
300
- const e = this.date();
301
- return e.setUTCDate(t), new r(e);
302
- }
303
- /**
304
- * @returns the integer hour that the timestamp corresponds to within its day.
305
- */
306
- get hour() {
307
- return this.date().getUTCHours();
308
- }
309
- /**
310
- * @returns the integer hour that the timestamp corresponds to within its day in local time.
311
- */
312
- get localHour() {
313
- return this.date().getHours();
314
- }
315
- /**
316
- * @returns a copy of the timestamp with the hour changed.
317
- * @param hour the value to set the hour to.
318
- */
319
- setLocalHour(t) {
320
- const e = this.date();
321
- return e.setHours(t), new r(e);
322
- }
323
- /**
324
- * @returns a copy of the timestamp with the hour changed.
325
- * @param hour the value to set the hour to.
326
- */
327
- setHour(t) {
328
- const e = this.date();
329
- return e.setUTCHours(t), new r(e);
330
- }
331
- /** @returns the integer minute that the timestamp corresponds to within its hour. */
332
- get minute() {
333
- return this.date().getUTCMinutes();
334
- }
335
- /**
336
- * @returns a copy of the timestamp with the minute changed.
337
- * @param minute the value to set the minute to.
338
- */
339
- setMinute(t) {
340
- const e = this.date();
341
- return e.setUTCMinutes(t), new r(e);
342
- }
343
- /**
344
- * @returns the integer second that the timestamp corresponds to within its
345
- * minute.
346
- */
347
- get second() {
348
- return this.date().getUTCSeconds();
349
- }
350
- /**
351
- * @returns a copy of the timestamp with the second changed.
352
- * @param second the value to set the second to.
353
- */
354
- setSecond(t) {
355
- const e = this.date();
356
- return e.setUTCSeconds(t), new r(e);
357
- }
358
- /**
359
- * @returns the integer millisecond that the timestamp corresponds to within its
360
- * second.
361
- */
362
- get millisecond() {
363
- return this.date().getUTCMilliseconds();
364
- }
365
- /**
366
- * @returns a copy of the timestamp with the milliseconds changed.
367
- * @param millisecond the value to set the millisecond to.
368
- */
369
- setMillisecond(t) {
370
- const e = this.date();
371
- return e.setUTCMilliseconds(t), new r(e);
372
- }
373
- /**
374
- * Returns a string representation of the TimeStamp.
375
- *
376
- * @param format - Optional format for the string representation. Defaults to "ISO".
377
- * @param tzInfo - Optional timezone info. Defaults to "UTC".
378
- * @returns A string representation of the TimeStamp.
379
- */
380
- toString(t = "ISO", e = "UTC") {
381
- switch (t) {
382
- case "ISODate":
383
- return this.toISOString(e).slice(0, 10);
384
- case "ISOTime":
385
- return this.toISOString(e).slice(11, 23);
386
- case "time":
387
- return this.timeString(!1, e);
388
- case "preciseTime":
389
- return this.timeString(!0, e);
390
- case "date":
391
- return this.dateString();
392
- case "preciseDate":
393
- return `${this.dateString()} ${this.timeString(!0, e)}`;
394
- case "dateTime":
395
- return `${this.dateString()} ${this.timeString(!1, e)}`;
396
- default:
397
- return this.toISOString(e);
398
- }
399
- }
400
- /**
401
- * @returns A new TimeStamp that is the remainder of the TimeStamp divided by the
402
- * given span. This is useful in cases where you want only part of a TimeStamp's value
403
- * i.e., the hours, minutes, seconds, milliseconds, microseconds, and nanoseconds but
404
- * not the days, years, etc.
405
- *
406
- * @param divisor - The TimeSpan to divide by. Must be an even TimeSpan or TimeStamp. Even
407
- * means it must be a day, hour, minute, second, millisecond, or microsecond, etc.
408
- *
409
- * @example TimeStamp.now().remainder(TimeStamp.DAY) // => TimeStamp representing the current day
410
- */
411
- remainder(t) {
412
- return rt(this, t);
413
- }
414
- /** @returns true if the day portion TimeStamp is today, false otherwise. */
415
- get isToday() {
416
- return this.truncate(a.DAY).equals(r.now().truncate(a.DAY));
417
- }
418
- /**
419
- * Truncates the TimeStamp to the nearest multiple of the given span.
420
- *
421
- * @param span - The TimeSpan to truncate to.
422
- * @returns A new TimeStamp that is truncated to the nearest multiple of the given span.
423
- */
424
- truncate(t) {
425
- return this.sub(this.remainder(t));
426
- }
427
- /**
428
- * @returns A new TimeStamp representing the current time in UTC. It's important to
429
- * note that this TimeStamp is only accurate to the millisecond level (that's the best
430
- * JavaScript can do).
431
- */
432
- static now() {
433
- return new r(/* @__PURE__ */ new Date());
434
- }
435
- /**
436
- * Finds the maximum timestamp among the provided timestamps.
437
- *
438
- * @param timestamps - The timestamps to compare.
439
- * @returns The maximum (latest) timestamp from the input.
440
- */
441
- static max(...t) {
442
- let e = r.MIN;
443
- for (const s of t) {
444
- const i = new r(s);
445
- i.after(e) && (e = i);
446
- }
447
- return e;
448
- }
449
- /**
450
- * Finds the minimum timestamp among the provided timestamps.
451
- *
452
- * @param timestamps - The timestamps to compare.
453
- * @returns The minimum (earliest) timestamp from the input.
454
- */
455
- static min(...t) {
456
- let e = r.MAX;
457
- for (const s of t) {
458
- const i = new r(s);
459
- i.before(e) && (e = i);
460
- }
461
- return e;
462
- }
463
- /**
464
- * Creates a TimeStamp representing the given number of nanoseconds.
465
- *
466
- * @param value - The number of nanoseconds.
467
- * @returns A TimeStamp representing the given number of nanoseconds.
468
- */
469
- static nanoseconds(t, e = "UTC") {
470
- return new r(t, e);
471
- }
472
- /** One nanosecond after the unix epoch */
473
- static NANOSECOND = r.nanoseconds(1);
474
- /** @returns a new TimeStamp n microseconds after the unix epoch */
475
- static microseconds(t, e = "UTC") {
476
- return r.nanoseconds(t * 1e3, e);
477
- }
478
- /** One microsecond after the unix epoch */
479
- static MICROSECOND = r.microseconds(1);
480
- /** @returns a new TimeStamp n milliseconds after the unix epoch */
481
- static milliseconds(t, e = "UTC") {
482
- return r.microseconds(t * 1e3, e);
483
- }
484
- /** One millisecond after the unix epoch */
485
- static MILLISECOND = r.milliseconds(1);
486
- /** @returns a new TimeStamp n seconds after the unix epoch */
487
- static seconds(t, e = "UTC") {
488
- return r.milliseconds(t * 1e3, e);
489
- }
490
- /** One second after the unix epoch */
491
- static SECOND = r.seconds(1);
492
- /** @returns a new TimeStamp n minutes after the unix epoch */
493
- static minutes(t, e = "UTC") {
494
- return r.seconds(t * 60, e);
495
- }
496
- /** One minute after the unix epoch */
497
- static MINUTE = r.minutes(1);
498
- /** @returns a new TimeStamp n hours after the unix epoch */
499
- static hours(t, e = "UTC") {
500
- return r.minutes(t * 60, e);
501
- }
502
- /** One hour after the unix epoch */
503
- static HOUR = r.hours(1);
504
- /** @returns a new TimeStamp n days after the unix epoch */
505
- static days(t, e = "UTC") {
506
- return r.hours(t * 24, e);
507
- }
508
- /** One day after the unix epoch */
509
- static DAY = r.days(1);
510
- /** The maximum possible value for a timestamp */
511
- static MAX = new r(G);
512
- /** The minimum possible value for a timestamp */
513
- static MIN = new r(0);
514
- /** The unix epoch */
515
- static ZERO = new r(0);
516
- /** A zod schema for validating timestamps */
517
- static z = o.union([
518
- o.instanceof(r),
519
- o.object({ value: o.bigint() }).transform((t) => new r(t.value)),
520
- o.string().transform((t) => new r(BigInt(t))),
521
- o.number().transform((t) => new r(t)),
522
- o.bigint().transform((t) => new r(t)),
523
- o.date().transform((t) => new r(t)),
524
- o.custom((t) => t instanceof a).transform((t) => new r(t)),
525
- mt.transform((t) => new r(t))
526
- ]);
527
- /**
528
- * Sorts two timestamps.
529
- *
530
- * @param a - The first timestamp.
531
- * @param b - The second timestamp.
532
- * @returns A number indicating the order of the two timestamps (positive if a is
533
- * greater than b, negative if a is less than b, and 0 if they are equal).
534
- */
535
- static sort(t, e) {
536
- return Number(t.valueOf() - e.valueOf());
537
- }
538
- }
539
- class a extends R {
540
- constructor(t) {
541
- typeof t == "number" && (t = Math.trunc(t.valueOf())), U(t) && (t = t.value), super(BigInt(t.valueOf()));
542
- }
543
- /**
544
- * Creates a TimeSpan representing the given number of seconds.
545
- *
546
- * @param span - The number of seconds.
547
- * @returns A TimeSpan representing the given number of seconds.
548
- */
549
- static fromSeconds(t) {
550
- return t instanceof a ? t : t instanceof v ? t.period : t instanceof r ? new a(t) : (U(t) && (t = t.value), ["number", "bigint"].includes(typeof t) ? a.seconds(t) : new a(t));
551
- }
552
- /**
553
- * Creates a TimeSpan representing the given number of milliseconds.
554
- *
555
- * @param span - The number of milliseconds.
556
- * @returns A TimeSpan representing the given number of milliseconds.
557
- */
558
- static fromMilliseconds(t) {
559
- return t instanceof a ? t : t instanceof v ? t.period : t instanceof r ? new a(t) : (U(t) && (t = t.value), ["number", "bigint"].includes(typeof t) ? a.milliseconds(t) : new a(t));
560
- }
561
- /**
562
- * @returns the primitive value of the TimeSpan. Overrides standard JS valueOf()
563
- * method.
564
- */
565
- valueOf() {
566
- return this.value;
567
- }
568
- /**
569
- * Checks if the TimeSpan is less than another TimeSpan.
570
- *
571
- * @param other - The TimeSpan to compare against.
572
- * @returns True if the TimeSpan is less than the other TimeSpan, false otherwise.
573
- */
574
- lessThan(t) {
575
- return this.valueOf() < new a(t).valueOf();
576
- }
577
- /**
578
- * Checks if the TimeSpan is greater than another TimeSpan.
579
- *
580
- * @param other - The TimeSpan to compare against.
581
- * @returns True if the TimeSpan is greater than the other TimeSpan, false otherwise.
582
- */
583
- greaterThan(t) {
584
- return this.valueOf() > new a(t).valueOf();
585
- }
586
- /**
587
- * Checks if the TimeSpan is less than or equal to another TimeSpan.
588
- *
589
- * @param other - The TimeSpan to compare against.
590
- * @returns True if the TimeSpan is less than or equal to the other TimeSpan, false otherwise.
591
- */
592
- lessThanOrEqual(t) {
593
- return this.valueOf() <= new a(t).valueOf();
594
- }
595
- /**
596
- * Checks if the TimeSpan is greater than or equal to another TimeSpan.
597
- *
598
- * @param other - The TimeSpan to compare against.
599
- * @returns True if the TimeSpan is greater than or equal to the other TimeSpan, false otherwise.
600
- */
601
- greaterThanOrEqual(t) {
602
- return this.valueOf() >= new a(t).valueOf();
603
- }
604
- /**
605
- * Calculates the remainder of the TimeSpan when divided by another TimeSpan.
606
- *
607
- * @param divisor - The TimeSpan to divide by.
608
- * @returns A new TimeSpan representing the remainder.
609
- */
610
- remainder(t) {
611
- return rt(this, t);
612
- }
613
- /**
614
- * Truncates the TimeSpan to the nearest multiple of the given span.
615
- *
616
- * @param span - The TimeSpan to truncate to.
617
- * @returns A new TimeSpan that is truncated to the nearest multiple of the given span.
618
- */
619
- truncate(t) {
620
- return new a(
621
- BigInt(Math.trunc(Number(this.valueOf() / t.valueOf()))) * t.valueOf()
622
- );
623
- }
624
- /**
625
- * Returns a string representation of the TimeSpan.
626
- *
627
- * @param format - Optional format for the string representation. Defaults to "full".
628
- * - "full": Shows all non-zero units with full precision (e.g., "2d 3h 45m 12s 500ms")
629
- * - "semantic": Shows 1-2 most significant units (e.g., "2d 3h")
630
- * @returns A string representation of the TimeSpan.
631
- */
632
- toString(t = "full") {
633
- if (t === "semantic") return this.toSemanticString();
634
- const e = this.truncate(a.DAY), s = this.truncate(a.HOUR), i = this.truncate(a.MINUTE), l = this.truncate(a.SECOND), h = this.truncate(a.MILLISECOND), M = this.truncate(a.MICROSECOND), y = this.truncate(a.NANOSECOND), O = e, b = s.sub(e), I = i.sub(s), f = l.sub(i), A = h.sub(l), B = M.sub(h), E = y.sub(M);
635
- let d = "";
636
- return O.isZero || (d += `${O.days}d `), b.isZero || (d += `${b.hours}h `), I.isZero || (d += `${I.minutes}m `), f.isZero || (d += `${f.seconds}s `), A.isZero || (d += `${A.milliseconds}ms `), B.isZero || (d += `${B.microseconds}µs `), E.isZero || (d += `${E.nanoseconds}ns`), d.trim();
637
- }
638
- toSemanticString() {
639
- const t = this.valueOf() < 0n ? -this.valueOf() : this.valueOf(), e = new a(t), s = this.valueOf() < 0n;
640
- if (e.valueOf() === 0n) return "0s";
641
- if (e.lessThan(a.SECOND)) return "< 1s";
642
- const i = e.days, l = e.hours, h = e.minutes, M = e.seconds, y = Math.floor(i / K), O = Math.floor(i / p), b = Math.floor(i / 7), I = Math.floor(i), f = Math.floor(l), A = Math.floor(h), B = Math.floor(M), E = s ? "-" : "";
643
- if (y >= 1) {
644
- let d = `${y}y`;
645
- if (y < 2) {
646
- const w = Math.floor(
647
- i % K / p
648
- );
649
- w > 0 && (d += ` ${w}mo`);
650
- }
651
- return E + d;
652
- }
653
- if (b >= 1 && i < p && i % 7 === 0) {
654
- let d = `${b}w`;
655
- const w = Math.floor(i % 7), T = Math.floor(l - b * 7 * 24);
656
- return b < 2 && (w > 0 ? d += ` ${w}d` : T > 0 && T < 24 && (d += ` ${T}h`)), E + d;
657
- }
658
- if (O >= 1) {
659
- let d = `${O}mo`;
660
- if (O < 3) {
661
- const w = Math.floor(i % p);
662
- w > 0 && (d += ` ${w}d`);
663
- }
664
- return E + d;
665
- }
666
- if (b >= 1) {
667
- let d = `${b}w`;
668
- const w = Math.floor(i % 7), T = Math.floor(l - b * 7 * 24);
669
- return b < 2 && (w > 0 ? d += ` ${w}d` : T > 0 && T < 24 && (d += ` ${T}h`)), E + d;
670
- }
671
- if (I >= 1) {
672
- let d = `${I}d`;
673
- const w = Math.floor(l - I * 24);
674
- return I < 2 && w > 0 && (d += ` ${w}h`), E + d;
675
- }
676
- if (f >= 1) {
677
- let d = `${f}h`;
678
- if (f < 3) {
679
- const w = Math.floor(h - f * 60);
680
- w > 0 && (d += ` ${w}m`);
681
- }
682
- return E + d;
683
- }
684
- if (A >= 1) {
685
- let d = `${A}m`;
686
- if (A < 5) {
687
- const w = Math.floor(M - A * 60);
688
- w > 0 && (d += ` ${w}s`);
689
- }
690
- return E + d;
691
- }
692
- return `${E}${B}s`;
693
- }
694
- /**
695
- * Multiplies the TimeSpan by a scalar value.
696
- *
697
- * @param value - The scalar value to multiply by.
698
- * @returns A new TimeSpan that is this TimeSpan multiplied by the provided value.
699
- */
700
- mult(t) {
701
- return new a(C(this.valueOf(), t));
702
- }
703
- /**
704
- * Divides the TimeSpan by a scalar value.
705
- *
706
- * @param value - The scalar value to divide by.
707
- * @returns A new TimeSpan that is this TimeSpan divided by the provided value.
708
- */
709
- div(t) {
710
- return new a(Y(this.valueOf(), t));
711
- }
712
- /** @returns the decimal number of days in the TimeSpan. */
713
- get days() {
714
- return Number(this.valueOf()) / Number(a.DAY.valueOf());
715
- }
716
- /** @returns the decimal number of hours in the TimeSpan. */
717
- get hours() {
718
- return Number(this.valueOf()) / Number(a.HOUR.valueOf());
719
- }
720
- /** @returns the decimal number of minutes in the TimeSpan. */
721
- get minutes() {
722
- return Number(this.valueOf()) / Number(a.MINUTE.valueOf());
723
- }
724
- /** @returns The number of seconds in the TimeSpan. */
725
- get seconds() {
726
- return Number(this.valueOf()) / Number(a.SECOND.valueOf());
727
- }
728
- /** @returns The number of milliseconds in the TimeSpan. */
729
- get milliseconds() {
730
- return Number(this.valueOf()) / Number(a.MILLISECOND.valueOf());
731
- }
732
- /** @returns The number of microseconds in the TimeSpan. */
733
- get microseconds() {
734
- return Number(this.valueOf()) / Number(a.MICROSECOND.valueOf());
735
- }
736
- /** @returns The number of nanoseconds in the TimeSpan. */
737
- get nanoseconds() {
738
- return Number(this.valueOf());
739
- }
740
- /**
741
- * Checks if the TimeSpan represents a zero duration.
742
- *
743
- * @returns True if the TimeSpan represents a zero duration, false otherwise.
744
- */
745
- get isZero() {
746
- return this.valueOf() === 0n;
747
- }
748
- /**
749
- * Checks if the TimeSpan is equal to another TimeSpan.
750
- *
751
- * @returns True if the TimeSpans are equal, false otherwise.
752
- */
753
- equals(t) {
754
- return this.valueOf() === new a(t).valueOf();
755
- }
756
- /**
757
- * Adds a TimeSpan to the TimeSpan.
758
- *
759
- * @returns A new TimeSpan representing the sum of the two TimeSpans.
760
- */
761
- add(t) {
762
- return new a(this.valueOf() + new a(t).valueOf());
763
- }
764
- /**
765
- * Creates a TimeSpan representing the duration between the two timestamps.
766
- *
767
- * @param other
768
- */
769
- sub(t) {
770
- return new a(this.valueOf() - new a(t).valueOf());
771
- }
772
- /**
773
- * Creates a TimeSpan representing the given number of nanoseconds.
774
- *
775
- * @param value - The number of nanoseconds.
776
- * @returns A TimeSpan representing the given number of nanoseconds.
777
- */
778
- static nanoseconds(t = 1) {
779
- return new a(t);
780
- }
781
- /** A nanosecond. */
782
- static NANOSECOND = a.nanoseconds(1);
783
- /**
784
- * Creates a TimeSpan representing the given number of microseconds.
785
- *
786
- * @param value - The number of microseconds.
787
- * @returns A TimeSpan representing the given number of microseconds.
788
- */
789
- static microseconds(t = 1) {
790
- return a.nanoseconds(C(t, 1e3));
791
- }
792
- /** A microsecond. */
793
- static MICROSECOND = a.microseconds(1);
794
- /**
795
- * Creates a TimeSpan representing the given number of milliseconds.
796
- *
797
- * @param value - The number of milliseconds.
798
- * @returns A TimeSpan representing the given number of milliseconds.
799
- */
800
- static milliseconds(t = 1) {
801
- return a.microseconds(C(t, 1e3));
802
- }
803
- /** A millisecond. */
804
- static MILLISECOND = a.milliseconds(1);
805
- /**
806
- * Creates a TimeSpan representing the given number of seconds.
807
- *
808
- * @param value - The number of seconds.
809
- * @returns A TimeSpan representing the given number of seconds.
810
- */
811
- static seconds(t = 1) {
812
- return a.milliseconds(C(t, 1e3));
813
- }
814
- /** A second. */
815
- static SECOND = a.seconds(1);
816
- /**
817
- * Creates a TimeSpan representing the given number of minutes.
818
- *
819
- * @param value - The number of minutes.
820
- * @returns A TimeSpan representing the given number of minutes.
821
- */
822
- static minutes(t = 1) {
823
- return a.seconds(C(t, 60));
824
- }
825
- /** A minute. */
826
- static MINUTE = a.minutes(1);
827
- /**
828
- * Creates a TimeSpan representing the given number of hours.
829
- *
830
- * @param value - The number of hours.
831
- * @returns A TimeSpan representing the given number of hours.
832
- */
833
- static hours(t) {
834
- return a.minutes(C(t, 60));
835
- }
836
- /** Represents an hour. */
837
- static HOUR = a.hours(1);
838
- /**
839
- * Creates a TimeSpan representing the given number of days.
840
- *
841
- * @param value - The number of days.
842
- * @returns A TimeSpan representing the given number of days.
843
- */
844
- static days(t) {
845
- return a.hours(C(t, 24));
846
- }
847
- /** Represents a day. */
848
- static DAY = a.days(1);
849
- /** The maximum possible value for a TimeSpan. */
850
- static MAX = new a(G);
851
- /** The minimum possible value for a TimeSpan. */
852
- static MIN = new a(0);
853
- /** The zero value for a TimeSpan. */
854
- static ZERO = new a(0);
855
- /** A zod schema for validating and transforming time spans */
856
- static z = o.union([
857
- o.object({ value: o.bigint() }).transform((t) => new a(t.value)),
858
- o.string().transform((t) => new a(BigInt(t))),
859
- o.number().transform((t) => new a(t)),
860
- o.bigint().transform((t) => new a(t)),
861
- o.instanceof(a),
862
- o.instanceof(r).transform((t) => new a(t)),
863
- o.custom((t) => t instanceof v).transform((t) => new a(t))
864
- ]);
865
- }
866
- class v extends R {
867
- constructor(t) {
868
- U(t) && (t = t.value), super(t.valueOf());
869
- }
870
- /** @returns a pretty string representation of the rate in the format "X Hz". */
871
- toString() {
872
- return `${this.valueOf()} Hz`;
873
- }
874
- /** @returns The number of seconds in the Rate. */
875
- equals(t) {
876
- return this.valueOf() === new v(t).valueOf();
877
- }
878
- /**
879
- * Calculates the period of the Rate as a TimeSpan.
880
- *
881
- * @returns A TimeSpan representing the period of the Rate.
882
- */
883
- get period() {
884
- return a.seconds(1 / this.valueOf());
885
- }
886
- /**
887
- * Calculates the number of samples in the given TimeSpan at this rate.
888
- *
889
- * @param duration - The duration to calculate the sample count from.
890
- * @returns The number of samples in the given TimeSpan at this rate.
891
- */
892
- sampleCount(t) {
893
- return new a(t).seconds * this.valueOf();
894
- }
895
- /**
896
- * Calculates the number of bytes in the given TimeSpan at this rate.
897
- *
898
- * @param span - The duration to calculate the byte count from.
899
- * @param density - The density of the data in bytes per sample.
900
- * @returns The number of bytes in the given TimeSpan at this rate.
901
- */
902
- byteCount(t, e) {
903
- return this.sampleCount(t) * new g(e).valueOf();
904
- }
905
- /**
906
- * Calculates a TimeSpan given the number of samples at this rate.
907
- *
908
- * @param sampleCount - The number of samples in the span.
909
- * @returns A TimeSpan that corresponds to the given number of samples.
910
- */
911
- span(t) {
912
- return a.seconds(t / this.valueOf());
913
- }
914
- /**
915
- * Calculates a TimeSpan given the number of bytes at this rate.
916
- *
917
- * @param size - The number of bytes in the span.
918
- * @param density - The density of the data in bytes per sample.
919
- * @returns A TimeSpan that corresponds to the given number of bytes.
920
- */
921
- byteSpan(t, e) {
922
- return this.span(t.valueOf() / new g(e).valueOf());
923
- }
924
- /**
925
- * Adds another Rate to this Rate.
926
- *
927
- * @param other - The Rate to add.
928
- * @returns A new Rate representing the sum of the two rates.
929
- */
930
- add(t) {
931
- return new v(P(this.valueOf(), new v(t).valueOf()));
932
- }
933
- /**
934
- * Subtracts another Rate from this Rate.
935
- *
936
- * @param other - The Rate to subtract.
937
- * @returns A new Rate representing the difference of the two rates.
938
- */
939
- sub(t) {
940
- return new v(F(this.valueOf(), new v(t).valueOf()));
941
- }
942
- /**
943
- * Multiplies this Rate by a scalar value.
944
- *
945
- * @param value - The scalar value to multiply by.
946
- * @returns A new Rate representing this Rate multiplied by the value.
947
- */
948
- mult(t) {
949
- return new v(C(this.valueOf(), t));
950
- }
951
- /**
952
- * Divides this Rate by a scalar value.
953
- *
954
- * @param value - The scalar value to divide by.
955
- * @returns A new Rate representing this Rate divided by the value.
956
- */
957
- div(t) {
958
- return new v(Y(this.valueOf(), t));
959
- }
960
- /**
961
- * Creates a Rate representing the given number of Hz.
962
- *
963
- * @param value - The number of Hz.
964
- * @returns A Rate representing the given number of Hz.
965
- */
966
- static hz(t) {
967
- return new v(t);
968
- }
969
- /**
970
- * Creates a Rate representing the given number of kHz.
971
- *
972
- * @param value - The number of kHz.
973
- * @returns A Rate representing the given number of kHz.
974
- */
975
- static khz(t) {
976
- return v.hz(t * 1e3);
977
- }
978
- /** A zod schema for validating and transforming rates */
979
- static z = o.union([
980
- o.number().transform((t) => new v(t)),
981
- o.instanceof(v)
982
- ]);
983
- }
984
- class g extends R {
985
- /**
986
- * Creates a Density representing the given number of bytes per value.
987
- *
988
- * @class
989
- * @param value - The number of bytes per value.
990
- * @returns A Density representing the given number of bytes per value.
991
- */
992
- constructor(t) {
993
- U(t) && (t = t.value), super(t.valueOf());
994
- }
995
- /**
996
- * Calculates the number of values in the given Size.
997
- *
998
- * @param size - The Size to calculate the value count from.
999
- * @returns The number of values in the given Size.
1000
- */
1001
- length(t) {
1002
- return t.valueOf() / this.valueOf();
1003
- }
1004
- /**
1005
- * Calculates a Size representing the given number of values.
1006
- *
1007
- * @param sampleCount - The number of values in the Size.
1008
- * @returns A Size representing the given number of values.
1009
- */
1010
- size(t) {
1011
- return new c(t * this.valueOf());
1012
- }
1013
- /**
1014
- * Adds another Density to this Density.
1015
- *
1016
- * @param other - The Density to add.
1017
- * @returns A new Density representing the sum of the two densities.
1018
- */
1019
- add(t) {
1020
- return new g(P(this.valueOf(), new g(t).valueOf()));
1021
- }
1022
- /**
1023
- * Subtracts another Density from this Density.
1024
- *
1025
- * @param other - The Density to subtract.
1026
- * @returns A new Density representing the difference of the two densities.
1027
- */
1028
- sub(t) {
1029
- return new g(F(this.valueOf(), new g(t).valueOf()));
1030
- }
1031
- /**
1032
- * Multiplies this Density by a scalar value.
1033
- *
1034
- * @param value - The scalar value to multiply by.
1035
- * @returns A new Density representing this Density multiplied by the value.
1036
- */
1037
- mult(t) {
1038
- return new g(C(this.valueOf(), t));
1039
- }
1040
- /**
1041
- * Divides this Density by a scalar value.
1042
- *
1043
- * @param value - The scalar value to divide by.
1044
- * @returns A new Density representing this Density divided by the value.
1045
- */
1046
- div(t) {
1047
- return new g(Y(this.valueOf(), t));
1048
- }
1049
- /** Unknown/Invalid Density. */
1050
- static UNKNOWN = new g(0);
1051
- /** 128 bits per value. */
1052
- static BIT128 = new g(16);
1053
- /** 64 bits per value. */
1054
- static BIT64 = new g(8);
1055
- /** 32 bits per value. */
1056
- static BIT32 = new g(4);
1057
- /** 16 bits per value. */
1058
- static BIT16 = new g(2);
1059
- /** 8 bits per value. */
1060
- static BIT8 = new g(1);
1061
- /** A zod schema for validating and transforming densities */
1062
- static z = o.union([
1063
- o.number().transform((t) => new g(t)),
1064
- o.instanceof(g)
1065
- ]);
1066
- }
1067
- class m {
1068
- /**
1069
- * The starting TimeStamp of the TimeRange.
1070
- *
1071
- * Note that this value is not guaranteed to be before or equal to the ending value.
1072
- * To ensure that this is the case, call TimeRange.make_valid().
1073
- *
1074
- * In most cases, operations should treat start as inclusive.
1075
- */
1076
- start;
1077
- /**
1078
- * The starting TimeStamp of the TimeRange.
1079
- *
1080
- * Note that this value is not guaranteed to be before or equal to the ending value.
1081
- * To ensure that this is the case, call TimeRange.make_valid().
1082
- *
1083
- * In most cases, operations should treat end as exclusive.
1084
- */
1085
- end;
1086
- /**
1087
- * Creates a TimeRange from the given start and end TimeStamps.
1088
- *
1089
- * @param start - A TimeStamp representing the start of the range.
1090
- * @param end - A TimeStamp representing the end of the range.
1091
- */
1092
- constructor(t, e) {
1093
- typeof t == "object" && "start" in t ? (this.start = new r(t.start), this.end = new r(t.end)) : (this.start = new r(t), this.end = new r(e));
1094
- }
1095
- /** @returns The TimeSpan occupied by the TimeRange. */
1096
- get span() {
1097
- return new a(this.end.valueOf() - this.start.valueOf());
1098
- }
1099
- /**
1100
- * Checks if the timestamp is valid i.e. the start is before the end.
1101
- *
1102
- * @returns True if the TimeRange is valid.
1103
- */
1104
- get isValid() {
1105
- return this.start.valueOf() <= this.end.valueOf();
1106
- }
1107
- /**
1108
- * Makes sure the TimeRange is valid i.e. the start is before the end.
1109
- *
1110
- * @returns A TimeRange that is valid.
1111
- */
1112
- makeValid() {
1113
- return this.isValid ? this : this.swap();
1114
- }
1115
- /**
1116
- * Checks if the TimeRange is zero (both start and end are TimeStamp.ZERO).
1117
- *
1118
- * @returns True if both start and end are TimeStamp.ZERO, false otherwise.
1119
- */
1120
- get isZero() {
1121
- return this.start.isZero && this.end.isZero;
1122
- }
1123
- /**
1124
- * @returns the TimeRange as a numeric object with start and end properties.
1125
- */
1126
- get numeric() {
1127
- return { start: Number(this.start.valueOf()), end: Number(this.end.valueOf()) };
1128
- }
1129
- /**
1130
- * Creates a new TimeRange with the start and end swapped.
1131
- *
1132
- * @returns A TimeRange with the start and end swapped.
1133
- */
1134
- swap() {
1135
- return new m(this.end, this.start);
1136
- }
1137
- get numericBounds() {
1138
- return {
1139
- lower: Number(this.start.valueOf()),
1140
- upper: Number(this.end.valueOf())
1141
- };
1142
- }
1143
- /**
1144
- * Checks if the TimeRange is equal to the given TimeRange.
1145
- *
1146
- * @param other - The TimeRange to compare to.
1147
- * @returns True if the TimeRange is equal to the given TimeRange.
1148
- */
1149
- equals(t, e = a.ZERO) {
1150
- if (e.isZero)
1151
- return this.start.equals(t.start) && this.end.equals(t.end);
1152
- let s = this.start.sub(t.start).valueOf(), i = this.end.sub(t.end).valueOf();
1153
- return s < 0 && (s = -s), i < 0 && (i = -i), s <= e.valueOf() && i <= e.valueOf();
1154
- }
1155
- /**
1156
- * Returns a string representation of the TimeRange.
1157
- *
1158
- * @returns A string representation of the TimeRange.
1159
- */
1160
- toString() {
1161
- return `${this.start.toString()} - ${this.end.toString()}`;
1162
- }
1163
- /**
1164
- * Returns a pretty string representation of the TimeRange.
1165
- *
1166
- * @returns A pretty string representation of the TimeRange.
1167
- */
1168
- toPrettyString() {
1169
- return `${this.start.toString("preciseDate")} - ${this.span.toString()}`;
1170
- }
1171
- /**
1172
- * Checks if the two time ranges overlap. If the two time ranges are equal, returns
1173
- * true. If the start of one range is equal to the end of the other, it returns false.
1174
- * Just follow the rule [start, end), i.e., start is inclusive, and the end is exclusive.
1175
- *
1176
- * @param other - The other TimeRange to compare to.
1177
- * @param delta - A TimeSpan representing the minimum amount of overlap for
1178
- * overlap to return true. This allows for a slight amount of leeway when
1179
- * checking for overlap.
1180
- * @returns True if the two TimeRanges overlap, false otherwise.
1181
- */
1182
- overlapsWith(t, e = a.ZERO) {
1183
- t = t.makeValid();
1184
- const s = this.makeValid();
1185
- if (this.equals(t)) return !0;
1186
- if (t.end.equals(s.start) || s.end.equals(t.start)) return !1;
1187
- const i = r.max(s.start, t.start), l = r.min(s.end, t.end);
1188
- return l.before(i) ? !1 : new a(l.sub(i)).greaterThanOrEqual(e);
1189
- }
1190
- contains(t) {
1191
- return t instanceof m ? this.contains(t.start) && this.contains(t.end) : this.start.beforeEq(t) && this.end.after(t);
1192
- }
1193
- /**
1194
- * Returns a new TimeRange that is bound by the given TimeRange.
1195
- *
1196
- * @param other - The TimeRange to bound by.
1197
- * @returns A new TimeRange that is bound by the given TimeRange.
1198
- * @example
1199
- * const range = new TimeRange(new TimeStamp(1000), new TimeStamp(2000));
1200
- * const other = new TimeRange(new TimeStamp(1500), new TimeStamp(2500));
1201
- * const bounded = range.boundBy(other);
1202
- * console.log(bounded); // TimeRange(1500, 2000)
1203
- */
1204
- boundBy(t) {
1205
- const e = new m(this.start, this.end);
1206
- return t.start.after(this.start) && (e.start = t.start), t.start.after(this.end) && (e.end = t.start), t.end.before(this.end) && (e.end = t.end), t.end.before(this.start) && (e.start = t.end), e;
1207
- }
1208
- static max(...t) {
1209
- return new m(
1210
- r.min(...t.map((e) => e.start)),
1211
- r.max(...t.map((e) => e.end))
1212
- );
1213
- }
1214
- /** The maximum possible time range. */
1215
- static MAX = new m(r.MIN, r.MAX);
1216
- /** A time range whose start and end are both zero. */
1217
- static ZERO = new m(r.ZERO, r.ZERO);
1218
- /** A zod schema for validating and transforming time ranges */
1219
- static z = o.union([
1220
- o.object({ start: r.z, end: r.z }).transform((t) => new m(t.start, t.end)),
1221
- o.instanceof(m)
1222
- ]);
1223
- /**
1224
- * Sorts two time ranges. The range with the earlier start time is considered less than
1225
- * the range with the later start time. If the start times are equal, the range with the
1226
- * earlier end time is considered less than the range with the later end time.
1227
- *
1228
- * @param a - The first time range.
1229
- * @param b - The second time range.
1230
- * @returns A number indicating the order of the two time ranges. This number is
1231
- * positive if a is earlier than b, negative if a is later than b, and 0 if they are
1232
- * equal.
1233
- */
1234
- static sort(t, e) {
1235
- return r.sort(t.start, e.start) || r.sort(t.end, e.end);
1236
- }
1237
- /**
1238
- * Simplify takes the list of `TimeRange`s, makes all of them valid, sorts them, and
1239
- * merges any overlapping ranges.
1240
- *
1241
- * @param ranges - The list of `TimeRange`s to simplify.
1242
- * @returns A list of simplified `TimeRange`s.
1243
- */
1244
- static simplify(t) {
1245
- return t.map((e) => e.makeValid()).sort((e, s) => m.sort(e, s)).reduce((e, s) => {
1246
- if (s.span.isZero) return e;
1247
- if (e.length === 0)
1248
- return e.push(s), e;
1249
- const i = e[e.length - 1];
1250
- return i.overlapsWith(s) || i.end.equals(s.start) ? i.end = r.max(i.end, s.end) : e.push(s), e;
1251
- }, []);
1252
- }
1253
- }
1254
- class n extends R {
1255
- constructor(t) {
1256
- if (U(t) && (t = t.value), t instanceof n || typeof t == "string" || typeof t.valueOf() == "string")
1257
- super(t.valueOf());
1258
- else {
1259
- const e = n.ARRAY_CONSTRUCTOR_DATA_TYPES.get(t.constructor.name);
1260
- if (e == null)
1261
- throw new Error(`unable to find data type for ${t.toString()}`);
1262
- super(e.valueOf());
1263
- }
1264
- }
1265
- /**
1266
- * @returns the TypedArray constructor for the DataType.
1267
- */
1268
- get Array() {
1269
- const t = n.ARRAY_CONSTRUCTORS.get(this.toString());
1270
- if (t == null)
1271
- throw new Error(`unable to find array constructor for ${this.valueOf()}`);
1272
- return t;
1273
- }
1274
- /**
1275
- * @returns true if the DataType is equal to the given DataType.
1276
- */
1277
- equals(t) {
1278
- return this.valueOf() === t.valueOf();
1279
- }
1280
- /**
1281
- * @returns true if the DataType is equal to any of the given DataTypes.
1282
- */
1283
- matches(...t) {
1284
- return t.some((e) => this.equals(e));
1285
- }
1286
- /** @returns a string representation of the DataType. If short is true, a 1-4
1287
- * character representation (i64, str, etc.) is returned instead. */
1288
- toString(t = !1) {
1289
- return t ? n.SHORT_STRINGS.get(this.valueOf()) ?? this.valueOf() : this.valueOf();
1290
- }
1291
- /**
1292
- * @returns true if the DataType has a variable density.
1293
- * @example DataType.STRING.isVariable // true
1294
- * @example DataType.INT32.isVariable // false
1295
- */
1296
- get isVariable() {
1297
- return this.equals(n.JSON) || this.equals(n.STRING);
1298
- }
1299
- /**
1300
- * @returns true if the DataType is numeric.
1301
- * @example DataType.INT32.isNumeric // true
1302
- * @example DataType.STRING.isNumeric // false
1303
- */
1304
- get isNumeric() {
1305
- return !this.isVariable && !this.equals(n.UUID);
1306
- }
1307
- /**
1308
- * @returns true if the DataType is an integer.
1309
- * @example DataType.INT32.isInteger // true
1310
- * @example DataType.FLOAT32.isInteger // false
1311
- */
1312
- get isInteger() {
1313
- const t = this.toString();
1314
- return t.startsWith("int") || t.startsWith("uint");
1315
- }
1316
- /**
1317
- * @returns true if the DataType is a floating point number.
1318
- * @example DataType.FLOAT32.isFloat // true
1319
- * @example DataType.INT32.isFloat // false
1320
- */
1321
- get isFloat() {
1322
- return this.toString().startsWith("float");
1323
- }
1324
- /**
1325
- * @returns the density of the DataType.
1326
- * @example DataType.INT16.density // Density.BIT32
1327
- * @example DataType.FLOAT32.density // Density.BIT32
1328
- */
1329
- get density() {
1330
- const t = n.DENSITIES.get(this.toString());
1331
- if (t == null) throw new Error(`unable to find density for ${this.valueOf()}`);
1332
- return t;
1333
- }
1334
- /**
1335
- * @returns true if the DataType is an unsigned integer.
1336
- * @example DataType.UINT32.isUnsigned // true
1337
- * @example DataType.INT32.isUnsigned // false
1338
- */
1339
- get isUnsignedInteger() {
1340
- return this.equals(n.UINT8) || this.equals(n.UINT16) || this.equals(n.UINT32) || this.equals(n.UINT64);
1341
- }
1342
- /**
1343
- * @returns true if the DataType is a signed integer.
1344
- * @example DataType.INT32.isSigned // true
1345
- * @example DataType.UINT32.isSigned // false
1346
- */
1347
- get isSignedInteger() {
1348
- return this.equals(n.INT8) || this.equals(n.INT16) || this.equals(n.INT32) || this.equals(n.INT64);
1349
- }
1350
- /** @returns true if the data type can be cast to the other data type without loss of precision. */
1351
- canSafelyCastTo(t) {
1352
- return this.equals(t) ? !0 : !this.isNumeric || !t.isNumeric || this.isVariable || t.isVariable || this.isUnsignedInteger && t.isSignedInteger ? !1 : this.isFloat ? t.isFloat && this.density.valueOf() <= t.density.valueOf() : this.equals(n.INT32) && t.equals(n.FLOAT64) || this.equals(n.INT8) && t.equals(n.FLOAT32) ? !0 : this.isInteger && t.isInteger ? this.density.valueOf() <= t.density.valueOf() && this.isUnsignedInteger === t.isUnsignedInteger : !1;
1353
- }
1354
- /** @returns true if the data type can be cast to the other data type, even if there is a loss of precision. */
1355
- canCastTo(t) {
1356
- return this.isNumeric && t.isNumeric ? !0 : this.equals(t);
1357
- }
1358
- /**
1359
- * Checks whether the given TypedArray is of the same type as the DataType.
1360
- *
1361
- * @param array - The TypedArray to check.
1362
- * @returns True if the TypedArray is of the same type as the DataType.
1363
- */
1364
- checkArray(t) {
1365
- return t.constructor === this.Array;
1366
- }
1367
- /** @returns true if the data type uses bigints to store values. */
1368
- get usesBigInt() {
1369
- return n.BIG_INT_TYPES.some((t) => t.equals(this));
1370
- }
1371
- /** Represents an Unknown/Invalid DataType. */
1372
- static UNKNOWN = new n("unknown");
1373
- /** Represents a 64-bit floating point value. */
1374
- static FLOAT64 = new n("float64");
1375
- /** Represents a 32-bit floating point value. */
1376
- static FLOAT32 = new n("float32");
1377
- /** Represents a 64-bit signed integer value. */
1378
- static INT64 = new n("int64");
1379
- /** Represents a 32-bit signed integer value. */
1380
- static INT32 = new n("int32");
1381
- /** Represents a 16-bit signed integer value. */
1382
- static INT16 = new n("int16");
1383
- /** Represents a 8-bit signed integer value. */
1384
- static INT8 = new n("int8");
1385
- /** Represents a 64-bit unsigned integer value. */
1386
- static UINT64 = new n("uint64");
1387
- /** Represents a 32-bit unsigned integer value. */
1388
- static UINT32 = new n("uint32");
1389
- /** Represents a 16-bit unsigned integer value. */
1390
- static UINT16 = new n("uint16");
1391
- /** Represents a 8-bit unsigned integer value. */
1392
- static UINT8 = new n("uint8");
1393
- /** Represents a boolean value. Stored as a 8-bit unsigned integer. */
1394
- static BOOLEAN = new n("boolean");
1395
- /** Represents a 64-bit unix epoch. */
1396
- static TIMESTAMP = new n("timestamp");
1397
- /** Represents a UUID data type. */
1398
- static UUID = new n("uuid");
1399
- /** Represents a string data type. Strings have an unknown density, and are separate
1400
- * by a newline character. */
1401
- static STRING = new n("string");
1402
- /** Represents a JSON data type. JSON has an unknown density, and is separated by a
1403
- * newline character. */
1404
- static JSON = new n("json");
1405
- static ARRAY_CONSTRUCTORS = /* @__PURE__ */ new Map([
1406
- [n.UINT8.toString(), Uint8Array],
1407
- [n.UINT16.toString(), Uint16Array],
1408
- [n.UINT32.toString(), Uint32Array],
1409
- [n.UINT64.toString(), BigUint64Array],
1410
- [n.FLOAT32.toString(), Float32Array],
1411
- [n.FLOAT64.toString(), Float64Array],
1412
- [n.INT8.toString(), Int8Array],
1413
- [n.INT16.toString(), Int16Array],
1414
- [n.INT32.toString(), Int32Array],
1415
- [n.INT64.toString(), BigInt64Array],
1416
- [n.TIMESTAMP.toString(), BigInt64Array],
1417
- [n.STRING.toString(), Uint8Array],
1418
- [n.JSON.toString(), Uint8Array],
1419
- [n.UUID.toString(), Uint8Array]
1420
- ]);
1421
- static ARRAY_CONSTRUCTOR_DATA_TYPES = /* @__PURE__ */ new Map([
1422
- [Uint8Array.name, n.UINT8],
1423
- [Uint16Array.name, n.UINT16],
1424
- [Uint32Array.name, n.UINT32],
1425
- [BigUint64Array.name, n.UINT64],
1426
- [Float32Array.name, n.FLOAT32],
1427
- [Float64Array.name, n.FLOAT64],
1428
- [Int8Array.name, n.INT8],
1429
- [Int16Array.name, n.INT16],
1430
- [Int32Array.name, n.INT32],
1431
- [BigInt64Array.name, n.INT64]
1432
- ]);
1433
- static DENSITIES = /* @__PURE__ */ new Map([
1434
- [n.UINT8.toString(), g.BIT8],
1435
- [n.UINT16.toString(), g.BIT16],
1436
- [n.UINT32.toString(), g.BIT32],
1437
- [n.UINT64.toString(), g.BIT64],
1438
- [n.FLOAT32.toString(), g.BIT32],
1439
- [n.FLOAT64.toString(), g.BIT64],
1440
- [n.INT8.toString(), g.BIT8],
1441
- [n.INT16.toString(), g.BIT16],
1442
- [n.INT32.toString(), g.BIT32],
1443
- [n.INT64.toString(), g.BIT64],
1444
- [n.TIMESTAMP.toString(), g.BIT64],
1445
- [n.STRING.toString(), g.UNKNOWN],
1446
- [n.JSON.toString(), g.UNKNOWN],
1447
- [n.UUID.toString(), g.BIT128]
1448
- ]);
1449
- /** All the data types. */
1450
- static ALL = [
1451
- n.UNKNOWN,
1452
- n.FLOAT64,
1453
- n.FLOAT32,
1454
- n.INT64,
1455
- n.INT32,
1456
- n.INT16,
1457
- n.INT8,
1458
- n.UINT64,
1459
- n.UINT32,
1460
- n.UINT16,
1461
- n.UINT8,
1462
- n.TIMESTAMP,
1463
- n.UUID,
1464
- n.STRING,
1465
- n.JSON
1466
- ];
1467
- static SHORT_STRINGS = /* @__PURE__ */ new Map([
1468
- [n.UINT8.toString(), "u8"],
1469
- [n.UINT16.toString(), "u16"],
1470
- [n.UINT32.toString(), "u32"],
1471
- [n.UINT64.toString(), "u64"],
1472
- [n.INT8.toString(), "i8"],
1473
- [n.INT16.toString(), "i16"],
1474
- [n.INT32.toString(), "i32"],
1475
- [n.INT64.toString(), "i64"],
1476
- [n.FLOAT32.toString(), "f32"],
1477
- [n.FLOAT64.toString(), "f64"],
1478
- [n.BOOLEAN.toString(), "bool"],
1479
- [n.TIMESTAMP.toString(), "ts"],
1480
- [n.UUID.toString(), "uuid"],
1481
- [n.STRING.toString(), "str"],
1482
- [n.JSON.toString(), "json"]
1483
- ]);
1484
- static BIG_INT_TYPES = [n.INT64, n.UINT64, n.TIMESTAMP];
1485
- /** A zod schema for a DataType. */
1486
- static z = o.union([
1487
- o.string().transform((t) => new n(t)),
1488
- o.instanceof(n)
1489
- ]);
1490
- }
1491
- class c extends R {
1492
- constructor(t) {
1493
- U(t) && (t = t.value), super(t.valueOf());
1494
- }
1495
- /** @returns true if the Size is larger than the other size. */
1496
- largerThan(t) {
1497
- return U(t) && (t = t.value), this.valueOf() > t.valueOf();
1498
- }
1499
- /** @returns true if the Size is smaller than the other size. */
1500
- smallerThan(t) {
1501
- return U(t) && (t = t.value), this.valueOf() < t.valueOf();
1502
- }
1503
- /** @returns a new Size representing the sum of the two Sizes. */
1504
- add(t) {
1505
- return U(t) && (t = t.value), new c(P(this.valueOf(), t.valueOf()));
1506
- }
1507
- /** @returns a new Size representing the difference of the two Sizes. */
1508
- sub(t) {
1509
- return U(t) && (t = t.value), new c(F(this.valueOf(), t.valueOf()));
1510
- }
1511
- /**
1512
- * Multiplies this Size by a scalar value.
1513
- *
1514
- * @param value - The scalar value to multiply by.
1515
- * @returns A new Size representing this Size multiplied by the value.
1516
- */
1517
- mult(t) {
1518
- return new c(C(this.valueOf(), t));
1519
- }
1520
- /**
1521
- * Divides this Size by a scalar value.
1522
- *
1523
- * @param value - The scalar value to divide by.
1524
- * @returns A new Size representing this Size divided by the value.
1525
- */
1526
- div(t) {
1527
- return new c(Y(this.valueOf(), t));
1528
- }
1529
- /** @returns a new Size representing the truncated value of the Size. */
1530
- truncate(t) {
1531
- return new c(
1532
- Math.trunc(this.valueOf() / new c(t).valueOf()) * new c(t).valueOf()
1533
- );
1534
- }
1535
- /** @returns a new Size representing the remainder of the Size. */
1536
- remainder(t) {
1537
- return c.bytes(this.valueOf() % new c(t).valueOf());
1538
- }
1539
- /** @returns the number of gigabytes in the Size. */
1540
- get gigabytes() {
1541
- return this.valueOf() / c.GIGABYTE.valueOf();
1542
- }
1543
- /** @returns the number of megabytes in the Size. */
1544
- get megabytes() {
1545
- return this.valueOf() / c.MEGABYTE.valueOf();
1546
- }
1547
- /** @returns the number of kilobytes in the Size. */
1548
- get kilobytes() {
1549
- return this.valueOf() / c.KILOBYTE.valueOf();
1550
- }
1551
- /** @returns the number of terabytes in the Size. */
1552
- get terabytes() {
1553
- return this.valueOf() / c.TERABYTE.valueOf();
1554
- }
1555
- /** @returns a nicely formatted string representation of the Size. */
1556
- toString() {
1557
- const t = this.truncate(c.TERABYTE), e = this.truncate(c.GIGABYTE), s = this.truncate(c.MEGABYTE), i = this.truncate(c.KILOBYTE), l = this.truncate(c.BYTE), h = t, M = e.sub(t), y = s.sub(e), O = i.sub(s), b = l.sub(i);
1558
- let I = "";
1559
- return h.isZero || (I += `${h.terabytes}TB `), M.isZero || (I += `${M.gigabytes}GB `), y.isZero || (I += `${y.megabytes}MB `), O.isZero || (I += `${O.kilobytes}KB `), (!b.isZero || I === "") && (I += `${b.valueOf()}B`), I.trim();
1560
- }
1561
- /**
1562
- * Creates a Size from the given number of bytes.
1563
- *
1564
- * @param value - The number of bytes.
1565
- * @returns A Size representing the given number of bytes.
1566
- */
1567
- static bytes(t = 1) {
1568
- return new c(t);
1569
- }
1570
- /** A single byte */
1571
- static BYTE = new c(1);
1572
- /**
1573
- * Creates a Size from the given number if kilobytes.
1574
- *
1575
- * @param value - The number of kilobytes.
1576
- * @returns A Size representing the given number of kilobytes.
1577
- */
1578
- static kilobytes(t = 1) {
1579
- return c.bytes(new c(t).valueOf() * 1e3);
1580
- }
1581
- /** A kilobyte */
1582
- static KILOBYTE = c.kilobytes(1);
1583
- /**
1584
- * Creates a Size from the given number of megabytes.
1585
- *
1586
- * @param value - The number of megabytes.
1587
- * @returns A Size representing the given number of megabytes.
1588
- */
1589
- static megabytes(t = 1) {
1590
- return c.kilobytes(new c(t).valueOf() * 1e3);
1591
- }
1592
- /** A megabyte */
1593
- static MEGABYTE = c.megabytes(1);
1594
- /**
1595
- * Creates a Size from the given number of gigabytes.
1596
- *
1597
- * @param value - The number of gigabytes.
1598
- * @returns A Size representing the given number of gigabytes.
1599
- */
1600
- static gigabytes(t = 1) {
1601
- return c.megabytes(new c(t).valueOf() * 1e3);
1602
- }
1603
- /** A gigabyte */
1604
- static GIGABYTE = c.gigabytes(1);
1605
- /**
1606
- * Creates a Size from the given number of terabytes.
1607
- *
1608
- * @param value - The number of terabytes.
1609
- * @returns A Size representing the given number of terabytes.
1610
- */
1611
- static terabytes(t) {
1612
- return c.gigabytes(new c(t).valueOf() * 1e3);
1613
- }
1614
- /** A terabyte. */
1615
- static TERABYTE = c.terabytes(1);
1616
- /** The zero value for Size */
1617
- static ZERO = new c(0);
1618
- /** A zod schema for a Size. */
1619
- static z = o.union([
1620
- o.number().transform((t) => new c(t)),
1621
- o.instanceof(c)
1622
- ]);
1623
- /** @returns true if the Size is zero. */
1624
- get isZero() {
1625
- return this.valueOf() === 0;
1626
- }
1627
- }
1628
- const he = o.object({
1629
- start: o.number(),
1630
- end: o.number()
1631
- }), de = o.union([
1632
- o.instanceof(Uint8Array),
1633
- o.instanceof(Uint16Array),
1634
- o.instanceof(Uint32Array),
1635
- o.instanceof(BigUint64Array),
1636
- o.instanceof(Float32Array),
1637
- o.instanceof(Float64Array),
1638
- o.instanceof(Int8Array),
1639
- o.instanceof(Int16Array),
1640
- o.instanceof(Int32Array),
1641
- o.instanceof(BigInt64Array)
1642
- ]), it = (u) => {
1643
- const t = typeof u;
1644
- return t === "string" || t === "number" || t === "boolean" || t === "bigint" || u instanceof r || u instanceof a || u instanceof Date;
1645
- }, vt = (u, t, e, s = 0) => u.usesBigInt && !t.usesBigInt ? Number(e) - Number(s) : !u.usesBigInt && t.usesBigInt ? BigInt(e.valueOf()) - BigInt(s.valueOf()) : q(e, -s), q = (u, t) => t == 0 ? u : u == 0 ? t : typeof u == "bigint" && typeof t == "bigint" || typeof u == "number" && typeof t == "number" ? u + t : Number(u) + Number(t), yt = "00000000-0000-0000-0000-000000000000", Mt = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/i;
1646
- function At(u) {
1647
- return typeof u == "string" && Mt.test(u);
1648
- }
1649
- const N = [];
1650
- for (let u = 0; u < 256; ++u)
1651
- N.push((u + 256).toString(16).slice(1));
1652
- function at(u, t = 0) {
1653
- return (N[u[t + 0]] + N[u[t + 1]] + N[u[t + 2]] + N[u[t + 3]] + "-" + N[u[t + 4]] + N[u[t + 5]] + "-" + N[u[t + 6]] + N[u[t + 7]] + "-" + N[u[t + 8]] + N[u[t + 9]] + "-" + N[u[t + 10]] + N[u[t + 11]] + N[u[t + 12]] + N[u[t + 13]] + N[u[t + 14]] + N[u[t + 15]]).toLowerCase();
1654
- }
1655
- function Ut(u, t = 0) {
1656
- const e = at(u, t);
1657
- if (!At(e))
1658
- throw TypeError("Stringified UUID is invalid");
1659
- return e;
1660
- }
1661
- let Z;
1662
- const Et = new Uint8Array(16);
1663
- function Bt() {
1664
- if (!Z) {
1665
- if (typeof crypto > "u" || !crypto.getRandomValues)
1666
- throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");
1667
- Z = crypto.getRandomValues.bind(crypto);
1668
- }
1669
- return Z(Et);
1670
- }
1671
- const Ct = typeof crypto < "u" && crypto.randomUUID && crypto.randomUUID.bind(crypto), Q = { randomUUID: Ct };
1672
- function xt(u, t, e) {
1673
- u = u || {};
1674
- const s = u.random ?? u.rng?.() ?? Bt();
1675
- if (s.length < 16)
1676
- throw new Error("Random bytes length must be >= 16");
1677
- return s[6] = s[6] & 15 | 64, s[8] = s[8] & 63 | 128, at(s);
1678
- }
1679
- function St(u, t, e) {
1680
- return Q.randomUUID && !u ? Q.randomUUID() : xt(u);
1681
- }
1682
- const Tt = () => St(), j = (u, t) => Ut(u, t), Rt = yt, ge = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
1683
- __proto__: null,
1684
- ZERO: Rt,
1685
- create: Tt,
1686
- parse: j
1687
- }, Symbol.toStringTag, { value: "Module" })), S = -1, H = {
1688
- [Symbol.iterator]: () => H,
1689
- next: () => ({ done: !0, value: void 0 })
1690
- }, Lt = o.string().transform(
1691
- (u) => new Uint8Array(
1692
- atob(u).split("").map((t) => t.charCodeAt(0))
1693
- ).buffer
1694
- ), $t = o.union([o.null(), o.undefined()]).transform(() => new Uint8Array().buffer), J = 10, ut = (u, t) => {
1695
- if (u === "number" && !t.isNumeric)
1696
- throw new Error(`cannot convert series of type ${t.toString()} to number`);
1697
- if (u === "bigint" && !t.usesBigInt)
1698
- throw new Error(`cannot convert series of type ${t.toString()} to bigint`);
1699
- }, ot = "sy_x_telem_series";
1700
- class x {
1701
- /**
1702
- * A unique identifier for the series. If specified by the user, it is their
1703
- * responsibility to ensure that it is unique. If not specified, a new ID will be
1704
- * generated.
1705
- */
1706
- key;
1707
- /**
1708
- * A discriminator used for identifying instances of the series class even
1709
- * when bundlers mangle the class name.
1710
- */
1711
- discriminator = ot;
1712
- /** The data type of the series. */
1713
- dataType;
1714
- /**
1715
- * A sample offset that can be used to shift the values of all samples upwards or
1716
- * downwards. Useful to convert series to lower precision data types while preserving
1717
- * the relative range of actual values.
1718
- */
1719
- sampleOffset;
1720
- /**
1721
- * Stores information about the buffer state of this array into a WebGL buffer.
1722
- */
1723
- gl;
1724
- /** The underlying data. */
1725
- _data;
1726
- /** The time range occupied by the series' data. */
1727
- timeRange = m.ZERO;
1728
- /**
1729
- * Alignment defines the location of the series relative to other series in a logical
1730
- * group. Useful for defining the position of the series within a channel's data.
1731
- */
1732
- alignment = 0n;
1733
- /**
1734
- * Alignment multiple defines the number of alignment steps taken per sample. This is
1735
- * useful for when the samples in a series represent a partial view of the raw data
1736
- * i.e. decimation or averaging.
1737
- */
1738
- alignmentMultiple = 1n;
1739
- /** A cached minimum value. */
1740
- cachedMin;
1741
- /** A cached maximum value. */
1742
- cachedMax;
1743
- /** The write position of the buffer. */
1744
- writePos = S;
1745
- /** Tracks the number of entities currently using this array. */
1746
- _refCount = 0;
1747
- /** Caches the length of the array for variable length data types. */
1748
- cachedLength;
1749
- /** Caches the indexes of the array for variable length data types. */
1750
- _cachedIndexes;
1751
- /**
1752
- * A zod schema that can be used to validate that a particular value
1753
- * can be constructed into a series.
1754
- */
1755
- static crudeZ = o.object({
1756
- timeRange: m.z.optional(),
1757
- dataType: n.z,
1758
- alignment: o.coerce.bigint().optional(),
1759
- data: o.union([
1760
- Lt,
1761
- $t,
1762
- o.instanceof(ArrayBuffer),
1763
- o.instanceof(Uint8Array)
1764
- ]),
1765
- glBufferUsage: It.optional().default("static").optional()
1766
- });
1767
- /**
1768
- * A zod schema that validates and constructs a series from it's crude
1769
- * representation.
1770
- */
1771
- static z = x.crudeZ.transform((t) => new x(t));
1772
- /**
1773
- * The Series constructor accepts either a SeriesArgs object or a CrudeSeries value.
1774
- *
1775
- * SeriesArgs interface properties:
1776
- * @property {CrudeSeries | null} [data] - The data to construct the series from. Can be:
1777
- * - A typed array (e.g. Float32Array, Int32Array)
1778
- * - A JS array of numbers, strings, or objects
1779
- * - A single value (number, string, bigint, etc.)
1780
- * - An ArrayBuffer
1781
- * - Another Series instance
1782
- * @property {CrudeDataType} [dataType] - The data type of the series. If not provided,
1783
- * will be inferred from the data. Required when constructing from an ArrayBuffer, or
1784
- * an empty JS array.
1785
- * @property {TimeRange} [timeRange] - The time range occupied by the series' data.
1786
- * Defaults to TimeRange.ZERO.
1787
- * @property {math.Numeric} [sampleOffset] - An offset to apply to each sample value.
1788
- * Useful for converting arrays to lower precision while preserving relative range.
1789
- * Defaults to 0.
1790
- * @property {GLBufferUsage} [glBufferUsage] - The WebGL buffer usage hint. Can be
1791
- * "static" or "dynamic". Defaults to "static".
1792
- * @property {bigint} [alignment] - The logical position of the series relative to other
1793
- * series in a group. Defaults to 0n.
1794
- * @property {string} [key] - A unique identifier for the series. If not provided,
1795
- * a new ID will be generated.
1796
- *
1797
- * @example
1798
- * // Create a series from a typed array
1799
- * const s1 = new Series(new Float32Array([1, 2, 3]));
1800
- *
1801
- * @example
1802
- * // Create a series from a JS array with explicit data type
1803
- * const s2 = new Series({ data: [1, 2, 3], dataType: DataType.FLOAT32 });
1804
- *
1805
- * @example
1806
- * // Create a series from a single value (data type inferred)
1807
- * const s3 = new Series(1); // Creates a FLOAT64 series
1808
- * const s4 = new Series("abc"); // Creates a STRING series
1809
- * const s5 = new Series(1n); // Creates an INT64 series
1810
- *
1811
- * @example
1812
- * // Create a series from objects (automatically uses JSON data type)
1813
- * const s6 = new Series([{ a: 1, b: "apple" }]);
1814
- *
1815
- * @example
1816
- * // Create a series with time range and alignment
1817
- * const s7 = new Series({
1818
- * data: new Float32Array([1, 2, 3]),
1819
- * timeRange: new TimeRange(1, 2),
1820
- * alignment: 1n
1821
- * });
1822
- *
1823
- * @example
1824
- * // Create a series from another series (copies properties)
1825
- * const s8 = new Series(s1);
1826
- *
1827
- * @example
1828
- * // Create a series with sample offset
1829
- * const s9 = new Series({
1830
- * data: new Float32Array([1, 2, 3]),
1831
- * sampleOffset: 2
1832
- * }); // Values will be 3, 4, 5
1833
- *
1834
- * @example
1835
- * // Create a series with WebGL buffer usage
1836
- * const s10 = new Series({
1837
- * data: new Float32Array([1, 2, 3]),
1838
- * glBufferUsage: "dynamic"
1839
- * });
1840
- *
1841
- * @throws Error if constructing from an empty JS array without specifying data type
1842
- * @throws Error if constructing from an ArrayBuffer without specifying data type
1843
- * @throws Error if data type cannot be inferred from input
1844
- */
1845
- constructor(t) {
1846
- pt(t) && (t = { data: t }), t.data ??= [];
1847
- const {
1848
- dataType: e,
1849
- timeRange: s,
1850
- sampleOffset: i = 0,
1851
- glBufferUsage: l = "static",
1852
- alignment: h = 0n,
1853
- alignmentMultiple: M = 1n,
1854
- key: y = st(),
1855
- data: O
1856
- } = t;
1857
- if (lt(O)) {
1858
- const f = O;
1859
- this.key = f.key, this.dataType = f.dataType, this.sampleOffset = f.sampleOffset, this.gl = f.gl, this._data = f._data, this.timeRange = f.timeRange, this.alignment = f.alignment, this.alignmentMultiple = f.alignmentMultiple, this.cachedMin = f.cachedMin, this.cachedMax = f.cachedMax, this.writePos = f.writePos, this._refCount = f._refCount, this.cachedLength = f.cachedLength;
1860
- return;
1861
- }
1862
- const b = it(O), I = Array.isArray(O);
1863
- if (e != null) this.dataType = new n(e);
1864
- else {
1865
- if (O instanceof ArrayBuffer)
1866
- throw new Error(
1867
- "cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type."
1868
- );
1869
- if (I || b) {
1870
- let f = O;
1871
- if (!b) {
1872
- if (O.length === 0)
1873
- throw new Error(
1874
- "cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type."
1875
- );
1876
- f = O[0];
1877
- }
1878
- if (typeof f == "string") this.dataType = n.STRING;
1879
- else if (typeof f == "number") this.dataType = n.FLOAT64;
1880
- else if (typeof f == "bigint") this.dataType = n.INT64;
1881
- else if (typeof f == "boolean") this.dataType = n.BOOLEAN;
1882
- else if (f instanceof r || f instanceof Date || f instanceof r)
1883
- this.dataType = n.TIMESTAMP;
1884
- else if (typeof f == "object") this.dataType = n.JSON;
1885
- else
1886
- throw new Error(
1887
- `cannot infer data type of ${typeof f} when constructing a Series from a JS array`
1888
- );
1889
- } else this.dataType = new n(O);
1890
- }
1891
- if (!I && !b) this._data = O;
1892
- else if (I && O.length === 0)
1893
- this._data = new this.dataType.Array([]).buffer;
1894
- else {
1895
- let f = b ? [O] : O;
1896
- const A = f[0];
1897
- (A instanceof r || A instanceof Date || A instanceof a) && (f = f.map((B) => new r(B).valueOf())), this.dataType.equals(n.STRING) ? (this.cachedLength = f.length, this._data = new TextEncoder().encode(`${f.join(`
1898
- `)}
1899
- `).buffer) : this.dataType.equals(n.JSON) ? (this.cachedLength = f.length, this._data = new TextEncoder().encode(
1900
- `${f.map((B) => k.encodeString(B)).join(`
1901
- `)}
1902
- `
1903
- ).buffer) : this.dataType.usesBigInt && typeof A == "number" ? this._data = new this.dataType.Array(
1904
- f.map((B) => BigInt(Math.round(B)))
1905
- ).buffer : !this.dataType.usesBigInt && typeof A == "bigint" ? this._data = new this.dataType.Array(
1906
- f.map(Number)
1907
- ).buffer : this._data = new this.dataType.Array(f).buffer;
1908
- }
1909
- this.key = y, this.alignment = h, this.alignmentMultiple = M, this.sampleOffset = i ?? 0, this.timeRange = s ?? m.ZERO, this.gl = {
1910
- control: null,
1911
- buffer: null,
1912
- prevBuffer: 0,
1913
- bufferUsage: l
1914
- };
1915
- }
1916
- /**
1917
- * Allocates a new series with a given capacity and data type.
1918
- * @param args.capacity the capacity of the series in samples. If the data type is of
1919
- * variable density (i.e. JSON, STRING, BYTES), this is the capacity in bytes.
1920
- * @param args.dataType the data type of the series.
1921
- * @param args.rest the rest of the arguments to pass to the series constructor.
1922
- */
1923
- static alloc({ capacity: t, dataType: e, ...s }) {
1924
- if (t === 0)
1925
- throw new Error("[Series] - cannot allocate an array of length 0");
1926
- const i = new new n(e).Array(t), l = new x({ data: i.buffer, dataType: e, ...s });
1927
- return l.writePos = 0, l;
1928
- }
1929
- /**
1930
- * @returns the number of references to this series i.e. the number of times this
1931
- * series has been acquired (by calling acquire) and not released (by calling
1932
- * release).
1933
- */
1934
- get refCount() {
1935
- return this._refCount;
1936
- }
1937
- /**
1938
- * Acquires a reference to this series, optionally buffering its data into the
1939
- * specified buffer controller. This method is useful for managing the life span
1940
- * of series buffered to the GPU.
1941
- * @param gl the buffer controller to buffer the series to. If not provided, the series
1942
- * will not be buffered to the GPU.
1943
- */
1944
- acquire(t) {
1945
- this._refCount++, t != null && this.updateGLBuffer(t);
1946
- }
1947
- /**
1948
- * Releases a reference to this series. If the reference count to the series reaches
1949
- * 0 and the series has been buffered to the GPU, the series will be deleted from
1950
- * the GPU.
1951
- */
1952
- release() {
1953
- this._refCount--, this.refCount === 0 && this.gl.control != null ? this.maybeGarbageCollectGLBuffer(this.gl.control) : this.refCount < 0 && console.warn("cannot release a series with a negative reference count");
1954
- }
1955
- /**
1956
- * Writes the given series to this series. If the series being written exceeds the
1957
- * remaining of series being written to, only the portion that fits will be written.
1958
- * @param other the series to write to this series. The data type of the series written
1959
- * must be the same as the data type of the series being written to.
1960
- * @returns the number of samples written. If the entire series fits, this value is
1961
- * equal to the length of the series being written.
1962
- */
1963
- write(t) {
1964
- if (!t.dataType.equals(this.dataType))
1965
- throw new Error("buffer must be of the same type as this array");
1966
- return this.dataType.isVariable ? this.writeVariable(t) : this.writeFixed(t);
1967
- }
1968
- writeVariable(t) {
1969
- if (this.writePos === S) return 0;
1970
- const e = this.byteCapacity.valueOf() - this.writePos, s = t.subBytes(0, e);
1971
- return this.writeToUnderlyingData(s), this.writePos += s.byteLength.valueOf(), this.cachedLength != null && (this.cachedLength += s.length, this.calculateCachedLength()), s.length;
1972
- }
1973
- writeFixed(t) {
1974
- if (this.writePos === S) return 0;
1975
- const e = this.capacity - this.writePos, s = t.sub(0, e);
1976
- return this.writeToUnderlyingData(s), this.cachedLength = void 0, this.maybeRecomputeMinMax(s), this.writePos += s.length, s.length;
1977
- }
1978
- writeToUnderlyingData(t) {
1979
- this.underlyingData.set(
1980
- t.data,
1981
- this.writePos
1982
- );
1983
- }
1984
- /** @returns the underlying buffer backing this array. */
1985
- get buffer() {
1986
- return typeof this._data == "object" && "buffer" in this._data ? this._data.buffer : this._data;
1987
- }
1988
- get underlyingData() {
1989
- return new this.dataType.Array(this._data);
1990
- }
1991
- /**
1992
- * Returns a native JS typed array with the proper data type.
1993
- * If the series is not full, returns a view of the data up to the write position.
1994
- * @returns A typed array containing the series data.
1995
- */
1996
- get data() {
1997
- return this.writePos === S ? this.underlyingData : new this.dataType.Array(this._data, 0, this.writePos);
1998
- }
1999
- /**
2000
- * Returns an array of the values in the series as strings.
2001
- * For variable length data types (like STRING or JSON), this decodes the underlying buffer.
2002
- * @returns An array of string representations of the series values.
2003
- */
2004
- toStrings() {
2005
- return this.dataType.isVariable ? new TextDecoder().decode(this.underlyingData).split(`
2006
- `).slice(0, -1) : Array.from(this).map((t) => t.toString());
2007
- }
2008
- /**
2009
- * Parses a JSON series into an array of values using the provided zod schema.
2010
- * @template Z The zod schema type.
2011
- * @param schema The zod schema to use to parse the JSON series.
2012
- * @throws Error if the series does not have a data type of JSON.
2013
- * @returns An array of values parsed from the JSON series.
2014
- */
2015
- parseJSON(t) {
2016
- if (!this.dataType.equals(n.JSON))
2017
- throw new Error("cannot parse non-JSON series as JSON");
2018
- return this.toStrings().map((e) => t.parse(k.decodeString(e)));
2019
- }
2020
- /**
2021
- * Returns the capacity of the series in bytes.
2022
- * @returns The size of the underlying buffer in bytes.
2023
- */
2024
- get byteCapacity() {
2025
- return new c(this.underlyingData.byteLength);
2026
- }
2027
- /**
2028
- * Returns the capacity of the series in samples.
2029
- * For variable length data types, this is the capacity in bytes.
2030
- * @returns The number of samples that can be stored in the series.
2031
- */
2032
- get capacity() {
2033
- return this.dataType.isVariable ? this.byteCapacity.valueOf() : this.dataType.density.length(this.byteCapacity);
2034
- }
2035
- /**
2036
- * Returns the length of the series in bytes.
2037
- * For variable length data types, this is the actual number of bytes used.
2038
- * @returns The size of the data in bytes.
2039
- */
2040
- get byteLength() {
2041
- return this.writePos === S ? this.byteCapacity : this.dataType.isVariable ? new c(this.writePos) : this.dataType.density.size(this.writePos);
2042
- }
2043
- /**
2044
- * Returns the number of samples in this array.
2045
- * For variable length data types, this is calculated by counting newlines.
2046
- * @returns The number of samples in the series.
2047
- */
2048
- get length() {
2049
- return this.cachedLength != null ? this.cachedLength : this.dataType.isVariable ? this.calculateCachedLength() : this.writePos === S ? this.byteCapacity.valueOf() / this.dataType.density.valueOf() : this.writePos;
2050
- }
2051
- calculateCachedLength() {
2052
- if (!this.dataType.isVariable)
2053
- throw new Error("cannot calculate length of a non-variable length data type");
2054
- let t = 0;
2055
- const e = [0];
2056
- return this.data.forEach((s, i) => {
2057
- s === J && (t++, e.push(i + 1));
2058
- }), this._cachedIndexes = e, this.cachedLength = t, t;
2059
- }
2060
- /**
2061
- * Creates a new array with a different data type.
2062
- * @param target the data type to convert to.
2063
- * @param sampleOffset an offset to apply to each sample. This can help with precision
2064
- * issues when converting between data types.
2065
- *
2066
- * WARNING: This method is expensive and copies the entire underlying array. There
2067
- * also may be untimely precision issues when converting between data types.
2068
- */
2069
- convert(t, e = 0) {
2070
- if (this.dataType.equals(t)) return this;
2071
- const s = new t.Array(this.length);
2072
- for (let i = 0; i < this.length; i++)
2073
- s[i] = vt(this.dataType, t, this.data[i], e);
2074
- return new x({
2075
- data: s.buffer,
2076
- dataType: t,
2077
- timeRange: this.timeRange,
2078
- sampleOffset: e,
2079
- glBufferUsage: this.gl.bufferUsage,
2080
- alignment: this.alignment
2081
- });
2082
- }
2083
- calcRawMax() {
2084
- if (this.length === 0) return -1 / 0;
2085
- if (this.dataType.equals(n.TIMESTAMP))
2086
- this.cachedMax = this.data[this.data.length - 1];
2087
- else if (this.dataType.usesBigInt) {
2088
- const t = this.data;
2089
- this.cachedMax = t.reduce((e, s) => e > s ? e : s);
2090
- } else {
2091
- const t = this.data;
2092
- this.cachedMax = t.reduce((e, s) => e > s ? e : s);
2093
- }
2094
- return this.cachedMax;
2095
- }
2096
- /** @returns the maximum value in the array */
2097
- get max() {
2098
- return this.calcMax();
2099
- }
2100
- calcMax() {
2101
- if (this.dataType.isVariable)
2102
- throw new Error("cannot calculate maximum on a variable length data type");
2103
- return this.writePos === 0 ? -1 / 0 : (this.cachedMax ??= this.calcRawMax(), q(this.cachedMax, this.sampleOffset));
2104
- }
2105
- calcRawMin() {
2106
- if (this.length === 0) return 1 / 0;
2107
- if (this.dataType.equals(n.TIMESTAMP)) this.cachedMin = this.data[0];
2108
- else if (this.dataType.usesBigInt) {
2109
- const t = this.data;
2110
- this.cachedMin = t.reduce((e, s) => e < s ? e : s);
2111
- } else {
2112
- const t = this.data;
2113
- this.cachedMin = t.reduce((e, s) => e < s ? e : s);
2114
- }
2115
- return this.cachedMin;
2116
- }
2117
- /** @returns the minimum value in the array */
2118
- get min() {
2119
- return this.calcMin();
2120
- }
2121
- calcMin() {
2122
- if (this.dataType.isVariable)
2123
- throw new Error("cannot calculate minimum on a variable length data type");
2124
- return this.writePos === 0 ? 1 / 0 : (this.cachedMin ??= this.calcRawMin(), q(this.cachedMin, this.sampleOffset));
2125
- }
2126
- /** @returns the bounds of the series. */
2127
- get bounds() {
2128
- return L(Number(this.min), Number(this.max), { makeValid: !1 });
2129
- }
2130
- maybeRecomputeMinMax(t) {
2131
- if (this.cachedMin != null) {
2132
- const e = t.cachedMin ?? t.calcRawMin();
2133
- e < this.cachedMin && (this.cachedMin = e);
2134
- }
2135
- if (this.cachedMax != null) {
2136
- const e = t.cachedMax ?? t.calcRawMax();
2137
- e > this.cachedMax && (this.cachedMax = e);
2138
- }
2139
- }
2140
- atAlignment(t, e) {
2141
- const s = Number((t - this.alignment) / this.alignmentMultiple);
2142
- if (s < 0 || s >= this.length) {
2143
- if (e === !0) throw new Error(`[series] - no value at index ${s}`);
2144
- return;
2145
- }
2146
- return this.at(s, e);
2147
- }
2148
- at(t, e = !1) {
2149
- if (this.dataType.isVariable) return this.atVariable(t, e ?? !1);
2150
- if (this.dataType.equals(n.UUID)) return this.atUUID(t, e);
2151
- t < 0 && (t = this.length + t);
2152
- const s = this.data[t];
2153
- if (s == null) {
2154
- if (e === !0) throw new Error(`[series] - no value at index ${t}`);
2155
- return;
2156
- }
2157
- return q(s, this.sampleOffset);
2158
- }
2159
- atUUID(t, e) {
2160
- t < 0 && (t = this.length + t);
2161
- const s = j(
2162
- new Uint8Array(this.buffer, t * this.dataType.density.valueOf())
2163
- );
2164
- if (s == null) {
2165
- if (e) throw new Error(`[series] - no value at index ${t}`);
2166
- return;
2167
- }
2168
- return s;
2169
- }
2170
- atVariable(t, e) {
2171
- let s = 0, i = 0;
2172
- if (this._cachedIndexes != null)
2173
- s = this._cachedIndexes[t], i = this._cachedIndexes[t + 1] - 1;
2174
- else {
2175
- t < 0 && (t = this.length + t);
2176
- for (let h = 0; h < this.data.length; h++)
2177
- if (this.data[h] === J) {
2178
- if (t === 0) {
2179
- i = h;
2180
- break;
2181
- }
2182
- s = h + 1, t--;
2183
- }
2184
- if (i === 0 && (i = this.data.length), s >= i || t > 0) {
2185
- if (e) throw new Error(`[series] - no value at index ${t}`);
2186
- return;
2187
- }
2188
- }
2189
- const l = this.data.slice(s, i);
2190
- return this.dataType.equals(n.STRING) ? new TextDecoder().decode(l) : ft(JSON.parse(new TextDecoder().decode(l)));
2191
- }
2192
- /**
2193
- * @returns the index of the first sample that is greater than or equal to the given value.
2194
- * The underlying array must be sorted. If it is not, the behavior of this method is undefined.
2195
- * @param value the value to search for.
2196
- */
2197
- binarySearch(t) {
2198
- let e = 0, s = this.length - 1;
2199
- const i = ct(t);
2200
- for (; e <= s; ) {
2201
- const l = Math.floor((e + s) / 2), h = i(this.at(l, !0), t);
2202
- if (h === 0) return l;
2203
- h < 0 ? e = l + 1 : s = l - 1;
2204
- }
2205
- return e;
2206
- }
2207
- /**
2208
- * Updates the WebGL buffer for the series if it is not up to date. This method
2209
- * should be called whenever a series has been previously buffered to the GPU and
2210
- * then modified via calls to write().
2211
- * @param gl the buffer controller to update the buffer for. This controller should
2212
- * be the same buffer previously passed to {@method acquire} or {@method updateGLBuffer}.
2213
- */
2214
- updateGLBuffer(t) {
2215
- if (this.gl.control = t, !this.dataType.equals(n.FLOAT32) && !this.dataType.equals(n.UINT8))
2216
- throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");
2217
- const { buffer: e, bufferUsage: s, prevBuffer: i } = this.gl;
2218
- if (e == null && (this.gl.buffer = t.createBuffer()), this.writePos !== i)
2219
- if (t.bindBuffer(t.ARRAY_BUFFER, this.gl.buffer), this.writePos !== S) {
2220
- i === 0 && t.bufferData(t.ARRAY_BUFFER, this.byteCapacity.valueOf(), t.STATIC_DRAW);
2221
- const l = this.dataType.density.size(i).valueOf(), h = this.underlyingData.slice(this.gl.prevBuffer, this.writePos);
2222
- t.bufferSubData(t.ARRAY_BUFFER, l, h.buffer), this.gl.prevBuffer = this.writePos;
2223
- } else
2224
- t.bufferData(
2225
- t.ARRAY_BUFFER,
2226
- this.buffer,
2227
- s === "static" ? t.STATIC_DRAW : t.DYNAMIC_DRAW
2228
- ), this.gl.prevBuffer = S;
2229
- }
2230
- as(t) {
2231
- return ut(t, this.dataType), this;
2232
- }
2233
- /** @returns a digest containing information about the series. */
2234
- get digest() {
2235
- return {
2236
- key: this.key,
2237
- dataType: this.dataType.toString(),
2238
- sampleOffset: this.sampleOffset,
2239
- alignment: {
2240
- lower: z(this.alignmentBounds.lower),
2241
- upper: z(this.alignmentBounds.upper),
2242
- multiple: this.alignmentMultiple
2243
- },
2244
- timeRange: this.timeRange.toString(),
2245
- length: this.length,
2246
- capacity: this.capacity
2247
- };
2248
- }
2249
- /**
2250
- * @returns the alignment bounds of the series, representing the logical space
2251
- * occupied by the series in a group of series. This is typically used to order the
2252
- * series within a channel's data.
2253
- *
2254
- * The lower bound is the alignment of the first sample, and the upper bound is the
2255
- * alignment of the last sample + 1. The lower bound is inclusive, while the upper bound
2256
- * is exclusive.
2257
- */
2258
- get alignmentBounds() {
2259
- return L(
2260
- this.alignment,
2261
- this.alignment + BigInt(this.length) * this.alignmentMultiple
2262
- );
2263
- }
2264
- maybeGarbageCollectGLBuffer(t) {
2265
- this.gl.buffer != null && (t.deleteBuffer(this.gl.buffer), this.gl.buffer = null, this.gl.prevBuffer = 0, this.gl.control = null);
2266
- }
2267
- /**
2268
- * @returns the WebGL buffer for the series. This method should only be called after
2269
- * the series has been buffered to the GPU via a call to {@method acquire} or
2270
- * {@method updateGLBuffer}.
2271
- * @throws if the series has not been buffered to the GPU.
2272
- */
2273
- get glBuffer() {
2274
- if (this.gl.buffer == null) throw new Error("gl buffer not initialized");
2275
- return this.gl.prevBuffer !== this.writePos && console.warn("buffer not updated"), this.gl.buffer;
2276
- }
2277
- [Symbol.iterator]() {
2278
- if (this.dataType.isVariable) {
2279
- const t = new qt(this);
2280
- return this.dataType.equals(n.JSON) ? new W(t) : t;
2281
- }
2282
- return this.dataType.equals(n.UUID) ? new Pt(this) : new Ft(this);
2283
- }
2284
- /**
2285
- * Returns a slice of the series from start to end.
2286
- * @param start The start index (inclusive).
2287
- * @param end The end index (exclusive).
2288
- * @returns A new series containing the sliced data.
2289
- */
2290
- slice(t, e) {
2291
- return this.sliceSub(!1, t, e);
2292
- }
2293
- /**
2294
- * Returns a subarray view of the series from start to end.
2295
- * @param start The start index (inclusive).
2296
- * @param end The end index (exclusive).
2297
- * @returns A new series containing the subarray data.
2298
- */
2299
- sub(t, e) {
2300
- return this.sliceSub(!0, t, e);
2301
- }
2302
- /**
2303
- * Returns an iterator over a portion of the series.
2304
- * @param start The start index (inclusive).
2305
- * @param end The end index (exclusive).
2306
- * @returns An iterator over the specified range.
2307
- */
2308
- subIterator(t, e) {
2309
- return new D(this, t, e ?? this.length);
2310
- }
2311
- /**
2312
- * Returns an iterator over a portion of the series based on alignment.
2313
- * @param start The start alignment (inclusive).
2314
- * @param end The end alignment (exclusive).
2315
- * @returns An iterator over the specified alignment range.
2316
- */
2317
- subAlignmentIterator(t, e) {
2318
- const s = Math.ceil(
2319
- Number(t - this.alignment) / Number(this.alignmentMultiple)
2320
- ), i = Math.ceil(
2321
- Number(e - this.alignment) / Number(this.alignmentMultiple)
2322
- );
2323
- return new D(this, s, i);
2324
- }
2325
- subBytes(t, e) {
2326
- if (t >= 0 && (e == null || e >= this.byteLength.valueOf())) return this;
2327
- const s = this.data.subarray(t, e);
2328
- return new x({
2329
- data: s,
2330
- dataType: this.dataType,
2331
- timeRange: this.timeRange,
2332
- sampleOffset: this.sampleOffset,
2333
- glBufferUsage: this.gl.bufferUsage,
2334
- alignment: this.alignment + BigInt(t)
2335
- });
2336
- }
2337
- sliceSub(t, e, s) {
2338
- if (e <= 0 && (s == null || s >= this.length)) return this;
2339
- let i;
2340
- return t ? i = this.data.subarray(e, s) : i = this.data.slice(e, s), new x({
2341
- data: i,
2342
- dataType: this.dataType,
2343
- timeRange: this.timeRange,
2344
- sampleOffset: this.sampleOffset,
2345
- glBufferUsage: this.gl.bufferUsage,
2346
- alignment: this.alignment + BigInt(e)
2347
- });
2348
- }
2349
- /**
2350
- * Creates a new series with a different alignment.
2351
- * @param alignment The new alignment value.
2352
- * @returns A new series with the specified alignment.
2353
- */
2354
- reAlign(t) {
2355
- return new x({
2356
- data: this.buffer,
2357
- dataType: this.dataType,
2358
- timeRange: m.ZERO,
2359
- sampleOffset: this.sampleOffset,
2360
- glBufferUsage: "static",
2361
- alignment: t
2362
- });
2363
- }
2364
- /**
2365
- * Returns a string representation of the series.
2366
- * For series with more than 10 elements, shows the first 5 and last 5 elements.
2367
- * @returns A string representation of the series.
2368
- */
2369
- toString() {
2370
- let t = `Series(${this.dataType.toString()} ${this.length} [`;
2371
- if (this.length <= 10) t += Array.from(this).map((e) => e.toString());
2372
- else {
2373
- for (let e = 0; e < 5; e++)
2374
- t += `${this.at(e)?.toString()}`, t += ",";
2375
- t += "...,";
2376
- for (let e = -5; e < 0; e++)
2377
- t += this.at(e)?.toString(), e < -1 && (t += ",");
2378
- }
2379
- return t += "])", t;
2380
- }
2381
- }
2382
- const pt = (u) => u == null ? !1 : Array.isArray(u) || u instanceof ArrayBuffer || ArrayBuffer.isView(u) && !(u instanceof DataView) || u instanceof x ? !0 : it(u), lt = nt(ot, x);
2383
- class D {
2384
- series;
2385
- end;
2386
- index;
2387
- constructor(t, e, s) {
2388
- this.series = t;
2389
- const i = L(0, t.length + 1);
2390
- this.end = X(i, s), this.index = X(i, e);
2391
- }
2392
- next() {
2393
- return this.index >= this.end ? { done: !0, value: void 0 } : { done: !1, value: this.series.at(this.index++, !0) };
2394
- }
2395
- }
2396
- class qt {
2397
- series;
2398
- index;
2399
- decoder;
2400
- constructor(t) {
2401
- if (!t.dataType.isVariable)
2402
- throw new Error(
2403
- "cannot create a variable series iterator for a non-variable series"
2404
- );
2405
- this.series = t, this.index = 0, this.decoder = new TextDecoder();
2406
- }
2407
- next() {
2408
- const t = this.index, e = this.series.data;
2409
- for (; this.index < e.length && e[this.index] !== J; ) this.index++;
2410
- const s = this.index;
2411
- return t === s ? { done: !0, value: void 0 } : (this.index++, { done: !1, value: this.decoder.decode(this.series.buffer.slice(t, s)) });
2412
- }
2413
- }
2414
- class W {
2415
- wrapped;
2416
- static schema = o.record(o.string(), o.unknown());
2417
- constructor(t) {
2418
- this.wrapped = t;
2419
- }
2420
- next() {
2421
- const t = this.wrapped.next();
2422
- return t.done === !0 ? { done: !0, value: void 0 } : {
2423
- done: !1,
2424
- value: k.decodeString(t.value, W.schema)
2425
- };
2426
- }
2427
- }
2428
- class Pt {
2429
- series;
2430
- index;
2431
- data;
2432
- density;
2433
- constructor(t) {
2434
- if (!t.dataType.equals(n.UUID))
2435
- throw new Error("cannot create a UUID series iterator for a non-UUID series");
2436
- this.series = t, this.index = 0, this.data = new Uint8Array(t.buffer), this.density = n.UUID.density.valueOf();
2437
- }
2438
- next() {
2439
- if (this.index >= this.series.length) return { done: !0, value: void 0 };
2440
- const t = j(this.data, this.index * this.density);
2441
- return this.index++, { done: !1, value: t };
2442
- }
2443
- }
2444
- class Ft {
2445
- series;
2446
- index;
2447
- constructor(t) {
2448
- this.series = t, this.index = 0;
2449
- }
2450
- next() {
2451
- return this.index >= this.series.length ? { done: !0, value: void 0 } : {
2452
- done: !1,
2453
- value: this.series.at(this.index++, !0)
2454
- };
2455
- }
2456
- }
2457
- class Oe {
2458
- /** The array of series in this collection */
2459
- series;
2460
- /**
2461
- * The MultiSeries constructor accepts an optional array of Series instances. All series
2462
- * in the collection must have the same data type.
2463
- *
2464
- * @example
2465
- * // Create an empty MultiSeries
2466
- * const ms1 = new MultiSeries();
2467
- *
2468
- * @example
2469
- * // Create a MultiSeries from multiple numeric series
2470
- * const s1 = new Series(new Float32Array([1, 2, 3]));
2471
- * const s2 = new Series(new Float32Array([4, 5, 6]));
2472
- * const ms2 = new MultiSeries([s1, s2]);
2473
- *
2474
- * @example
2475
- * // Create a MultiSeries from string series
2476
- * const s3 = new Series(["apple", "banana"]);
2477
- * const s4 = new Series(["carrot", "date"]);
2478
- * const ms3 = new MultiSeries([s3, s4]);
2479
- *
2480
- * @example
2481
- * // Create a MultiSeries from JSON series
2482
- * const s5 = new Series([{ a: 1, b: "apple" }]);
2483
- * const s6 = new Series([{ a: 2, b: "banana" }]);
2484
- * const ms4 = new MultiSeries([s5, s6]);
2485
- *
2486
- * @example
2487
- * // Add series to an existing MultiSeries
2488
- * const ms5 = new MultiSeries();
2489
- * ms5.push(s1);
2490
- * ms5.push(s2);
2491
- *
2492
- * @example
2493
- * // Combine two MultiSeries
2494
- * const ms6 = new MultiSeries([s1]);
2495
- * const ms7 = new MultiSeries([s2]);
2496
- * ms6.push(ms7);
2497
- *
2498
- * @throws Error if attempting to add a series with a different data type
2499
- */
2500
- constructor(t = []) {
2501
- if (t.length !== 0) {
2502
- const e = t[0].dataType;
2503
- for (let s = 1; s < t.length; s++)
2504
- if (!t[s].dataType.equals(e))
2505
- throw new Error("[multi-series] - series must have the same data type");
2506
- }
2507
- this.series = t;
2508
- }
2509
- as(t) {
2510
- return ut(t, this.dataType), this;
2511
- }
2512
- /**
2513
- * Returns the data type of the series in this collection. If the collection is empty,
2514
- * returns DataType.UNKNOWN.
2515
- */
2516
- get dataType() {
2517
- return this.series.length === 0 ? n.UNKNOWN : this.series[0].dataType;
2518
- }
2519
- /**
2520
- * Returns the combined time range of all series in the collection. If the collection
2521
- * is empty, returns TimeRange.ZERO. The time range spans from the start of the first
2522
- * series to the end of the last series.
2523
- */
2524
- get timeRange() {
2525
- return this.series.length === 0 ? m.ZERO : new m(
2526
- this.series[0].timeRange.start,
2527
- this.series[this.series.length - 1].timeRange.end
2528
- );
2529
- }
2530
- /**
2531
- * Returns the alignment of the first series in the collection. If the collection is
2532
- * empty, returns 0n.
2533
- */
2534
- get alignment() {
2535
- return this.series.length === 0 ? 0n : this.series[0].alignment;
2536
- }
2537
- /**
2538
- * Returns the alignment bounds of the entire collection. The lower bound is the
2539
- * alignment of the first series, and the upper bound is the alignment of the last
2540
- * series + its length. If the collection is empty, returns bounds.construct(0n, 0n).
2541
- */
2542
- get alignmentBounds() {
2543
- return this.series.length === 0 ? L(0n, 0n) : L(
2544
- this.series[0].alignmentBounds.lower,
2545
- this.series[this.series.length - 1].alignmentBounds.upper
2546
- );
2547
- }
2548
- push(t) {
2549
- const e = () => new Error(
2550
- `cannot push a ${t.dataType.toString()} series to a ${this.dataType.toString()} multi-series`
2551
- ), s = t.dataType.equals(this.dataType);
2552
- if (lt(t)) {
2553
- if (this.series.length !== 0 && !s) throw e();
2554
- this.series.push(t);
2555
- } else {
2556
- if (this.series.length !== 0 && t.series.length !== 0 && !s)
2557
- throw e();
2558
- this.series.push(...t.series);
2559
- }
2560
- }
2561
- /**
2562
- * Returns the total length of all series in the collection.
2563
- * @returns The sum of the lengths of all series.
2564
- */
2565
- get length() {
2566
- return this.series.reduce((t, e) => t + e.length, 0);
2567
- }
2568
- atAlignment(t, e) {
2569
- for (const s of this.series)
2570
- if ($(s.alignmentBounds, t))
2571
- return s.atAlignment(t, e);
2572
- if (e) throw new Error(`[series] - no value at alignment ${t}`);
2573
- }
2574
- at(t, e = !1) {
2575
- t < 0 && (t = this.length + t);
2576
- for (const s of this.series) {
2577
- if (t < s.length) return s.at(t, e);
2578
- t -= s.length;
2579
- }
2580
- if (e) throw new Error(`[series] - no value at index ${t}`);
2581
- }
2582
- /**
2583
- * Returns an iterator over a portion of the multi-series.
2584
- * @param start - The start index (inclusive).
2585
- * @param end - The end index (exclusive).
2586
- * @returns An iterator over the specified range.
2587
- */
2588
- subIterator(t, e) {
2589
- return new V(this, t, e ?? this.length);
2590
- }
2591
- /**
2592
- * Returns an iterator over a portion of the multi-series based on alignment.
2593
- * @param start - The start alignment (inclusive).
2594
- * @param end - The end alignment (exclusive).
2595
- * @returns An iterator over the specified alignment range.
2596
- */
2597
- subAlignmentIterator(t, e) {
2598
- if (t >= this.alignmentBounds.upper || e <= this.alignmentBounds.lower)
2599
- return H;
2600
- let s = 0;
2601
- for (let l = 0; l < this.series.length; l++) {
2602
- const h = this.series[l];
2603
- if (t < h.alignment) break;
2604
- if (t >= h.alignmentBounds.upper) s += h.length;
2605
- else if ($(h.alignmentBounds, t)) {
2606
- s += Math.ceil(
2607
- Number(t - h.alignment) / Number(h.alignmentMultiple)
2608
- );
2609
- break;
2610
- }
2611
- }
2612
- let i = 0;
2613
- for (let l = 0; l < this.series.length; l++) {
2614
- const h = this.series[l];
2615
- if (e < h.alignment) break;
2616
- if (e >= h.alignmentBounds.upper) i += h.length;
2617
- else if ($(h.alignmentBounds, e)) {
2618
- i += Math.ceil(
2619
- Number(e - h.alignment) / Number(h.alignmentMultiple)
2620
- );
2621
- break;
2622
- }
2623
- }
2624
- return new V(this, s, i);
2625
- }
2626
- /**
2627
- * Returns an iterator over the specified alignment range and span.
2628
- * @param start - The start alignment (inclusive).
2629
- * @param span - The number of samples to include.
2630
- * @returns An iterator over the specified range.
2631
- */
2632
- subAlignmentSpanIterator(t, e) {
2633
- if (t >= this.alignmentBounds.upper) return H;
2634
- e = Math.min(e, Number(this.distance(t, this.alignmentBounds.upper)));
2635
- let s = 0;
2636
- for (let i = 0; i < this.series.length; i++) {
2637
- const l = this.series[i];
2638
- if (t < l.alignment) break;
2639
- if (t >= l.alignmentBounds.upper) s += l.length;
2640
- else if ($(l.alignmentBounds, t)) {
2641
- s += Number(t - l.alignment);
2642
- break;
2643
- }
2644
- }
2645
- return new V(this, s, s + e);
2646
- }
2647
- /**
2648
- * Updates the WebGL buffer for all series in the collection.
2649
- * @param gl - The WebGL buffer controller to use.
2650
- */
2651
- updateGLBuffer(t) {
2652
- this.series.forEach((e) => e.updateGLBuffer(t));
2653
- }
2654
- /**
2655
- * Returns the bounds containing the minimum and maximum values across all series.
2656
- */
2657
- get bounds() {
2658
- return ht(this.series.map((t) => t.bounds));
2659
- }
2660
- /**
2661
- * Returns the sum of the byte lengths of all series.
2662
- */
2663
- get byteLength() {
2664
- return new c(this.series.reduce((t, e) => t + e.byteLength.valueOf(), 0));
2665
- }
2666
- /**
2667
- * Returns a combined typed array containing all data from all series.
2668
- * @returns A typed array containing all data from all series.
2669
- */
2670
- get data() {
2671
- const t = new this.dataType.Array(this.length);
2672
- let e = 0;
2673
- for (const s of this.series)
2674
- t.set(s.data, e), e += s.length;
2675
- return new this.dataType.Array(t.buffer);
2676
- }
2677
- /**
2678
- * Traverses the alignment space by a given distance from a start point.
2679
- * @param start - The starting alignment.
2680
- * @param dist - The distance to traverse.
2681
- * @returns The resulting alignment after traversal.
2682
- */
2683
- traverseAlignment(t, e) {
2684
- const s = this.series.map((i) => i.alignmentBounds);
2685
- return dt(s, t, e);
2686
- }
2687
- /**
2688
- * Acquires a reference to the WebGL buffer for all series.
2689
- * @param gl - Optional WebGL buffer controller to use.
2690
- */
2691
- acquire(t) {
2692
- this.series.forEach((e) => e.acquire(t));
2693
- }
2694
- /**
2695
- * Releases the WebGL buffer reference for all series.
2696
- */
2697
- release() {
2698
- this.series.forEach((t) => t.release());
2699
- }
2700
- /**
2701
- * Calculates the number of samples between two alignments in the multi-series.
2702
- * @param start - The starting alignment.
2703
- * @param end - The ending alignment.
2704
- * @returns The distance between the alignments.
2705
- */
2706
- distance(t, e) {
2707
- const s = this.series.map((i) => i.alignmentBounds);
2708
- return gt(s, t, e);
2709
- }
2710
- /**
2711
- * Parses a JSON multi-series into an array of values using the provided zod schema.
2712
- * @template Z - The zod schema type.
2713
- * @param schema - The zod schema to use to parse the JSON series.
2714
- * @throws Error if the series does not have a data type of JSON.
2715
- * @returns An array of values parsed from the JSON series.
2716
- */
2717
- parseJSON(t) {
2718
- if (!this.dataType.equals(n.JSON))
2719
- throw new Error("cannot parse non-JSON series as JSON");
2720
- return this.series.flatMap((e) => e.parseJSON(t));
2721
- }
2722
- /**
2723
- * Returns an iterator over all values in the multi-series.
2724
- * @returns An iterator that yields all values from all series in sequence.
2725
- */
2726
- [Symbol.iterator]() {
2727
- return this.series.length === 0 ? {
2728
- next() {
2729
- return { done: !0, value: void 0 };
2730
- }
2731
- } : new Yt(this.series);
2732
- }
2733
- /**
2734
- * Returns an array of the values in the multi-series as strings.
2735
- * For variable length data types (like STRING or JSON), this decodes the underlying buffer.
2736
- * @returns An array of string representations of the multi-series values.
2737
- */
2738
- toStrings() {
2739
- return this.series.flatMap((t) => t.toStrings());
2740
- }
2741
- }
2742
- class Yt {
2743
- series;
2744
- seriesIndex;
2745
- internal;
2746
- constructor(t) {
2747
- this.series = t, this.seriesIndex = 0, this.internal = t[0][Symbol.iterator]();
2748
- }
2749
- next() {
2750
- const t = this.internal.next();
2751
- return t.done === !1 ? t : this.seriesIndex === this.series.length - 1 ? { done: !0, value: void 0 } : (this.internal = this.series[++this.seriesIndex][Symbol.iterator](), this.next());
2752
- }
2753
- [Symbol.iterator]() {
2754
- return this;
2755
- }
2756
- }
2757
- class V {
2758
- series;
2759
- index;
2760
- end;
2761
- constructor(t, e, s) {
2762
- this.series = t, this.end = s, this.index = e;
2763
- }
2764
- next() {
2765
- return this.index >= this.end ? { done: !0, value: void 0 } : { done: !1, value: this.series.at(this.index++, !0) };
2766
- }
2767
- [Symbol.iterator]() {
2768
- return this;
2769
- }
2770
- }
2771
- const z = (u) => {
2772
- const t = u >> 32n, e = u & 0xffffffffn;
2773
- return { domain: t, sample: e };
2774
- };
2775
- export {
2776
- Dt as A,
2777
- zt as B,
2778
- ge as C,
2779
- g as D,
2780
- Oe as M,
2781
- v as R,
2782
- x as S,
2783
- r as T,
2784
- a,
2785
- m as b,
2786
- n as c,
2787
- c as d,
2788
- it as e,
2789
- vt as f,
2790
- q as g,
2791
- ue as h,
2792
- pt as i,
2793
- le as j,
2794
- G as k,
2795
- Nt as l,
2796
- ie as m,
2797
- he as n,
2798
- te as o,
2799
- ee as p,
2800
- se as q,
2801
- ne as r,
2802
- _t as s,
2803
- de as t,
2804
- ae as u,
2805
- oe as v,
2806
- fe as w,
2807
- ce as x,
2808
- re as y,
2809
- st as z
2810
- };