@synnaxlabs/x 0.41.0 → 0.42.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 (158) hide show
  1. package/.turbo/turbo-build.log +23 -23
  2. package/dist/binary.cjs +1 -1
  3. package/dist/binary.js +2 -2
  4. package/dist/{bounds-M-SZ3X1Z.cjs → bounds-BQo7rvs9.cjs} +1 -1
  5. package/dist/{bounds-DQrjn60Q.js → bounds-Bn5_l4Z3.js} +10 -9
  6. package/dist/bounds.cjs +1 -1
  7. package/dist/bounds.js +1 -1
  8. package/dist/compare.cjs +1 -1
  9. package/dist/compare.js +1 -1
  10. package/dist/deep.cjs +1 -1
  11. package/dist/deep.js +66 -69
  12. package/dist/{dimensions-PWy5QZoM.cjs → dimensions-D2QGoNXO.cjs} +1 -1
  13. package/dist/dimensions.cjs +1 -1
  14. package/dist/{external-CvWr1nhS.cjs → external-DWQITF5_.cjs} +1 -1
  15. package/dist/index-BywOGO8U.js +1074 -0
  16. package/dist/index-CYYjI7Uf.cjs +1 -0
  17. package/dist/index-C_6NXBlg.cjs +3 -0
  18. package/dist/{index-BVC_8Cg9.js → index-QGplUHuy.js} +1 -1
  19. package/dist/index.cjs +3 -3
  20. package/dist/index.js +702 -243
  21. package/dist/record.js +3 -1
  22. package/dist/{scale-DL9VFGhL.cjs → scale-BtZINJ-A.cjs} +1 -1
  23. package/dist/{scale-DQwBWnwc.js → scale-DfJe9755.js} +1 -1
  24. package/dist/scale.cjs +1 -1
  25. package/dist/scale.js +1 -1
  26. package/dist/{series-D0zxMWxP.js → series-B9JERcqi.js} +571 -492
  27. package/dist/series-DqJ6f97G.cjs +11 -0
  28. package/dist/spatial.cjs +1 -1
  29. package/dist/spatial.js +2 -2
  30. package/dist/src/binary/{encoder.d.ts → codec.d.ts} +14 -8
  31. package/dist/src/binary/codec.d.ts.map +1 -0
  32. package/dist/src/binary/codec.spec.d.ts +2 -0
  33. package/dist/src/binary/codec.spec.d.ts.map +1 -0
  34. package/dist/src/binary/index.d.ts +1 -1
  35. package/dist/src/binary/index.d.ts.map +1 -1
  36. package/dist/src/breaker/breaker.d.ts +14 -21
  37. package/dist/src/breaker/breaker.d.ts.map +1 -1
  38. package/dist/src/change/change.d.ts +5 -18
  39. package/dist/src/change/change.d.ts.map +1 -1
  40. package/dist/src/color/color.d.ts +126 -0
  41. package/dist/src/color/color.d.ts.map +1 -0
  42. package/dist/src/color/color.spec.d.ts +2 -0
  43. package/dist/src/color/color.spec.d.ts.map +1 -0
  44. package/dist/src/color/external.d.ts +5 -0
  45. package/dist/src/color/external.d.ts.map +1 -0
  46. package/dist/src/color/gradient.d.ts +18 -0
  47. package/dist/src/color/gradient.d.ts.map +1 -0
  48. package/dist/src/color/index.d.ts +2 -0
  49. package/dist/src/color/index.d.ts.map +1 -0
  50. package/dist/src/color/palette.d.ts +19 -0
  51. package/dist/src/color/palette.d.ts.map +1 -0
  52. package/dist/src/color/transformColorsToHex.d.ts +6 -0
  53. package/dist/src/color/transformColorsToHex.d.ts.map +1 -0
  54. package/dist/src/control/control.d.ts +69 -74
  55. package/dist/src/control/control.d.ts.map +1 -1
  56. package/dist/src/deep/merge.d.ts +1 -1
  57. package/dist/src/deep/merge.d.ts.map +1 -1
  58. package/dist/src/errors/errors.d.ts +127 -7
  59. package/dist/src/errors/errors.d.ts.map +1 -1
  60. package/dist/src/errors/errors.spec.d.ts +2 -0
  61. package/dist/src/errors/errors.spec.d.ts.map +1 -0
  62. package/dist/src/index.d.ts +4 -0
  63. package/dist/src/index.d.ts.map +1 -1
  64. package/dist/src/jsonrpc/jsonrpc.d.ts +10 -7
  65. package/dist/src/jsonrpc/jsonrpc.d.ts.map +1 -1
  66. package/dist/src/kv/types.d.ts +1 -7
  67. package/dist/src/kv/types.d.ts.map +1 -1
  68. package/dist/src/migrate/migrate.d.ts +1 -1
  69. package/dist/src/notation/notation.d.ts +5 -1
  70. package/dist/src/notation/notation.d.ts.map +1 -1
  71. package/dist/src/record.d.ts +2 -1
  72. package/dist/src/record.d.ts.map +1 -1
  73. package/dist/src/replace.d.ts +2 -0
  74. package/dist/src/replace.d.ts.map +1 -0
  75. package/dist/src/runtime/os.d.ts +9 -1
  76. package/dist/src/runtime/os.d.ts.map +1 -1
  77. package/dist/src/singleton/define.d.ts +9 -0
  78. package/dist/src/singleton/define.d.ts.map +1 -0
  79. package/dist/src/singleton/define.spec.d.ts +2 -0
  80. package/dist/src/singleton/define.spec.d.ts.map +1 -0
  81. package/dist/src/singleton/index.d.ts +2 -0
  82. package/dist/src/singleton/index.d.ts.map +1 -0
  83. package/dist/src/spatial/base.d.ts +74 -70
  84. package/dist/src/spatial/base.d.ts.map +1 -1
  85. package/dist/src/spatial/box/box.d.ts +18 -76
  86. package/dist/src/spatial/box/box.d.ts.map +1 -1
  87. package/dist/src/spatial/dimensions/dimensions.d.ts +5 -29
  88. package/dist/src/spatial/dimensions/dimensions.d.ts.map +1 -1
  89. package/dist/src/spatial/direction/direction.d.ts +9 -1
  90. package/dist/src/spatial/direction/direction.d.ts.map +1 -1
  91. package/dist/src/spatial/location/location.d.ts +43 -22
  92. package/dist/src/spatial/location/location.d.ts.map +1 -1
  93. package/dist/src/spatial/scale/scale.d.ts +12 -120
  94. package/dist/src/spatial/scale/scale.d.ts.map +1 -1
  95. package/dist/src/spatial/xy/xy.d.ts +5 -29
  96. package/dist/src/spatial/xy/xy.d.ts.map +1 -1
  97. package/dist/src/sync/index.d.ts +2 -0
  98. package/dist/src/sync/index.d.ts.map +1 -0
  99. package/dist/src/sync/mutex.d.ts +8 -0
  100. package/dist/src/sync/mutex.d.ts.map +1 -0
  101. package/dist/src/telem/gl.d.ts +4 -1
  102. package/dist/src/telem/gl.d.ts.map +1 -1
  103. package/dist/src/telem/series.d.ts +46 -125
  104. package/dist/src/telem/series.d.ts.map +1 -1
  105. package/dist/src/telem/telem.d.ts +101 -86
  106. package/dist/src/telem/telem.d.ts.map +1 -1
  107. package/dist/src/toArray.d.ts +1 -1
  108. package/dist/src/toArray.d.ts.map +1 -1
  109. package/dist/src/zod/util.d.ts.map +1 -1
  110. package/dist/telem.cjs +1 -1
  111. package/dist/telem.js +1 -1
  112. package/dist/toArray.cjs +1 -1
  113. package/dist/toArray.js +1 -1
  114. package/dist/zod.cjs +1 -1
  115. package/package.json +7 -4
  116. package/src/binary/codec.spec.ts +370 -0
  117. package/src/binary/{encoder.ts → codec.ts} +55 -11
  118. package/src/binary/index.ts +1 -1
  119. package/src/breaker/breaker.spec.ts +16 -25
  120. package/src/breaker/breaker.ts +36 -19
  121. package/src/color/color.spec.ts +673 -0
  122. package/src/color/color.ts +317 -0
  123. package/src/color/external.ts +13 -0
  124. package/src/color/gradient.ts +78 -0
  125. package/src/color/index.ts +10 -0
  126. package/src/color/palette.ts +28 -0
  127. package/src/color/transformColorsToHex.ts +30 -0
  128. package/src/control/control.ts +30 -22
  129. package/src/deep/merge.ts +2 -8
  130. package/src/errors/errors.spec.ts +152 -0
  131. package/src/errors/errors.ts +225 -10
  132. package/src/index.ts +4 -0
  133. package/src/jsonrpc/jsonrpc.ts +12 -8
  134. package/src/migrate/migrate.ts +2 -2
  135. package/src/primitive.ts +1 -1
  136. package/src/record.ts +5 -1
  137. package/src/replace.ts +1 -0
  138. package/src/singleton/define.spec.ts +93 -0
  139. package/src/singleton/define.ts +27 -0
  140. package/src/singleton/index.ts +10 -0
  141. package/src/sync/index.ts +1 -0
  142. package/src/sync/mutex.ts +16 -0
  143. package/src/telem/series.spec.ts +32 -0
  144. package/src/telem/series.ts +54 -19
  145. package/src/telem/telem.spec.ts +151 -10
  146. package/src/telem/telem.ts +126 -73
  147. package/src/toArray.ts +2 -2
  148. package/src/zod/util.spec.ts +17 -1
  149. package/src/zod/util.ts +4 -2
  150. package/tsconfig.tsbuildinfo +1 -1
  151. package/dist/index-BG3Scw3G.cjs +0 -1
  152. package/dist/index-C3QzbIwt.js +0 -101
  153. package/dist/index-CnclyYpG.cjs +0 -3
  154. package/dist/series-BMma2b5q.cjs +0 -11
  155. package/dist/src/binary/encoder.d.ts.map +0 -1
  156. package/dist/src/binary/encoder.spec.d.ts +0 -2
  157. package/dist/src/binary/encoder.spec.d.ts.map +0 -1
  158. package/src/binary/encoder.spec.ts +0 -174
@@ -1,101 +0,0 @@
1
- var m = Object.defineProperty;
2
- var C = (o, e, t) => e in o ? m(o, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : o[e] = t;
3
- var i = (o, e, t) => C(o, typeof e != "symbol" ? e + "" : e, t);
4
- import { s as y, b } from "./index-DizUWH6z.js";
5
- import { isObject as l } from "./identity.js";
6
- class f {
7
- constructor() {
8
- i(this, "contentType", "application/json");
9
- i(this, "decoder");
10
- i(this, "encoder");
11
- this.decoder = new TextDecoder(), this.encoder = new TextEncoder();
12
- }
13
- encode(e) {
14
- return this.encoder.encode(this.encodeString(e)).buffer;
15
- }
16
- decode(e, t) {
17
- return this.decodeString(this.decoder.decode(e), t);
18
- }
19
- decodeString(e, t) {
20
- const n = JSON.parse(e), r = y(n);
21
- return t != null ? t.parse(r) : r;
22
- }
23
- encodeString(e) {
24
- const t = b(e);
25
- return JSON.stringify(t, (n, r) => ArrayBuffer.isView(r) ? Array.from(r) : l(r) && "encode_value" in r ? typeof r.value == "bigint" ? r.value.toString() : r.value : typeof r == "bigint" ? r.toString() : r);
26
- }
27
- static registerCustomType() {
28
- }
29
- }
30
- class p {
31
- constructor() {
32
- i(this, "contentType", "text/csv");
33
- }
34
- encode(e) {
35
- const t = this.encodeString(e);
36
- return new TextEncoder().encode(t).buffer;
37
- }
38
- decode(e, t) {
39
- const n = new TextDecoder().decode(e);
40
- return this.decodeString(n, t);
41
- }
42
- encodeString(e) {
43
- if (!Array.isArray(e) || e.length === 0 || !l(e[0]))
44
- throw new Error("Payload must be an array of objects");
45
- const t = Object.keys(e[0]), n = [t.join(",")];
46
- return e.forEach((r) => {
47
- const d = t.map((c) => JSON.stringify(r[c] ?? ""));
48
- n.push(d.join(","));
49
- }), n.join(`
50
- `);
51
- }
52
- decodeString(e, t) {
53
- const [n, ...r] = e.trim().split(`
54
- `).map((s) => s.trim());
55
- if (n.length === 0)
56
- return t != null ? t.parse({}) : {};
57
- const d = n.split(",").map((s) => s.trim()), c = {};
58
- return d.forEach((s) => {
59
- c[s] = [];
60
- }), r.forEach((s) => {
61
- const h = s.split(",").map((u) => u.trim());
62
- d.forEach((u, T) => {
63
- const a = this.parseValue(h[T]);
64
- a != null && c[u].push(a);
65
- });
66
- }), t != null ? t.parse(c) : c;
67
- }
68
- parseValue(e) {
69
- if (e == null || e.length === 0) return null;
70
- const t = Number(e);
71
- return isNaN(t) ? e.startsWith('"') && e.endsWith('"') ? e.slice(1, -1) : e : t;
72
- }
73
- static registerCustomType() {
74
- }
75
- }
76
- class g {
77
- constructor() {
78
- i(this, "contentType", "text/plain");
79
- }
80
- encode(e) {
81
- return new TextEncoder().encode(e).buffer;
82
- }
83
- decode(e, t) {
84
- const n = new TextDecoder().decode(e);
85
- return t != null ? t.parse(n) : n;
86
- }
87
- }
88
- const S = new f(), E = new p(), w = new g(), O = [S], _ = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
89
- __proto__: null,
90
- CSVCodec: p,
91
- CSV_CODEC: E,
92
- ENCODERS: O,
93
- JSONCodec: f,
94
- JSON_CODEC: S,
95
- TEXT_CODEC: w,
96
- TextCodec: g
97
- }, Symbol.toStringTag, { value: "Module" }));
98
- export {
99
- S as J,
100
- _ as e
101
- };
@@ -1,3 +0,0 @@
1
- "use strict";var y=Object.defineProperty;var O=(o,e,t)=>e in o?y(o,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):o[e]=t;var i=(o,e,t)=>O(o,typeof e!="symbol"?e+"":e,t);const f=require("./index-Dd8DLyMx.cjs"),p=require("./identity.cjs");class S{constructor(){i(this,"contentType","application/json");i(this,"decoder");i(this,"encoder");this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const r=JSON.parse(e),n=f.snakeToCamel(r);return t!=null?t.parse(n):n}encodeString(e){const t=f.camelToSnake(e);return JSON.stringify(t,(r,n)=>ArrayBuffer.isView(n)?Array.from(n):p.isObject(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}}class g{constructor(){i(this,"contentType","text/csv")}encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t).buffer}decode(e,t){const r=new TextDecoder().decode(e);return this.decodeString(r,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!p.isObject(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),r=[t.join(",")];return e.forEach(n=>{const d=t.map(s=>JSON.stringify(n[s]??""));r.push(d.join(","))}),r.join(`
2
- `)}decodeString(e,t){const[r,...n]=e.trim().split(`
3
- `).map(c=>c.trim());if(r.length===0)return t!=null?t.parse({}):{};const d=r.split(",").map(c=>c.trim()),s={};return d.forEach(c=>{s[c]=[]}),n.forEach(c=>{const C=c.split(",").map(u=>u.trim());d.forEach((u,T)=>{const l=this.parseValue(C[T]);l!=null&&s[u].push(l)})}),t!=null?t.parse(s):s}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}static registerCustomType(){}}class h{constructor(){i(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,t){const r=new TextDecoder().decode(e);return t!=null?t.parse(r):r}}const a=new S,E=new g,b=new h,w=[a],m=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:g,CSV_CODEC:E,ENCODERS:w,JSONCodec:S,JSON_CODEC:a,TEXT_CODEC:b,TextCodec:h},Symbol.toStringTag,{value:"Module"}));exports.JSON_CODEC=a;exports.encoder=m;
@@ -1,11 +0,0 @@
1
- "use strict";var et=Object.defineProperty;var rt=(o,t,e)=>t in o?et(o,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):o[t]=e;var s=(o,t,e)=>rt(o,typeof t!="symbol"?t+"":t,e);const l=require("zod"),D=require("./index-CnclyYpG.cjs"),nt=require("./index-Dd8DLyMx.cjs"),st=require("./index-BG3Scw3G.cjs"),w=require("./bounds-M-SZ3X1Z.cjs");require("./box-0YrQibkB.cjs");require("./dimensions-PWy5QZoM.cjs");require("./base-BAM2mqCy.cjs");require("./location-BGl5Ddds.cjs");require("./scale-DL9VFGhL.cjs");require("./xy-B7065J2S.cjs");let it=(o,t=21)=>(e=t)=>{let r="",a=e|0;for(;a--;)r+=o[Math.random()*o.length|0];return r};const at="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",ut=it(at,11),K=()=>ut(),ot=Object.freeze(Object.defineProperty({__proto__:null,create:K},Symbol.toStringTag,{value:"Module"})),lt=l.z.enum(["static","dynamic"]),X=(o,t)=>{const e=new m(t);if(![O.DAY,O.HOUR,O.MINUTE,O.SECOND,O.MILLISECOND,O.MICROSECOND,O.NANOSECOND].some(a=>a.equals(e)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const r=o.valueOf()%e.valueOf();return o instanceof m?new m(r):new O(r)},i=class i{constructor(t,e="UTC"){s(this,"value");s(this,"encodeValue",!0);if(t==null)this.value=i.now().valueOf();else if(t instanceof Date)this.value=BigInt(t.getTime())*i.MILLISECOND.valueOf();else if(typeof t=="string")this.value=i.parseDateTimeString(t,e).valueOf();else if(Array.isArray(t))this.value=i.parseDate(t);else{let r=BigInt(0);t instanceof Number&&(t=t.valueOf()),e==="local"&&(r=i.utcOffset.valueOf()),typeof t=="number"&&(isFinite(t)?t=Math.trunc(t):(isNaN(t)&&(t=0),t===1/0?t=i.MAX:t=i.MIN)),this.value=BigInt(t.valueOf())+r}}static parseDate([t=1970,e=1,r=1]){const a=new Date(t,e-1,r,0,0,0,0);return new i(BigInt(a.getTime())*i.MILLISECOND.valueOf()).truncate(i.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(t,e="UTC"){const[r,a,f]=t.split(":");let h="00",p="00";f!=null&&([h,p]=f.split("."));let y=i.hours(parseInt(r??"00")).add(i.minutes(parseInt(a??"00"))).add(i.seconds(parseInt(h??"00"))).add(i.milliseconds(parseInt(p??"00")));return e==="local"&&(y=y.add(i.utcOffset)),y.valueOf()}static parseDateTimeString(t,e="UTC"){if(!t.includes("/")&&!t.includes("-"))return i.parseTimeString(t,e);const r=new Date(t);return t.includes(":")||r.setUTCHours(0,0,0,0),new i(BigInt(r.getTime())*i.MILLISECOND.valueOf(),e).valueOf()}fString(t="ISO",e="UTC"){switch(t){case"ISODate":return this.toISOString(e).slice(0,10);case"ISOTime":return this.toISOString(e).slice(11,23);case"time":return this.timeString(!1,e);case"preciseTime":return this.timeString(!0,e);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,e)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,e)}`;default:return this.toISOString(e)}}toISOString(t="UTC"){return t==="UTC"?this.date().toISOString():this.sub(i.utcOffset).date().toISOString()}timeString(t=!1,e="UTC"){const r=this.toISOString(e);return t?r.slice(11,23):r.slice(11,19)}dateString(){const t=this.date(),e=t.toLocaleString("default",{month:"short"}),r=t.toLocaleString("default",{day:"numeric"});return`${e} ${r}`}static get utcOffset(){return new O(BigInt(new Date().getTimezoneOffset())*i.MINUTE.valueOf())}static since(t){return new i().span(t)}date(){return new Date(this.milliseconds)}equals(t){return this.valueOf()===new i(t).valueOf()}span(t){return this.range(t).span}range(t){return new R(this,t).makeValid()}spanRange(t){return this.range(this.add(t)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(t){return this.valueOf()>new i(t).valueOf()}afterEq(t){return this.valueOf()>=new i(t).valueOf()}before(t){return this.valueOf()<new i(t).valueOf()}beforeEq(t){return this.valueOf()<=new i(t).valueOf()}add(t){return new i(this.valueOf()+BigInt(t.valueOf()))}sub(t){return new i(this.valueOf()-BigInt(t.valueOf()))}get hours(){return Number(this.valueOf())/Number(O.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(O.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(O.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(O.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(i.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(i.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getFullYear()}setYear(t){const e=this.date();return e.setFullYear(t),new i(e)}get month(){return this.date().getMonth()}setMonth(t){const e=this.date();return e.setMonth(t),new i(e)}get day(){return this.date().getDate()}setDay(t){const e=this.date();return e.setDate(t),new i(e)}get hour(){return this.date().getHours()}setHour(t){const e=this.date();return e.setHours(t),new i(e)}get minute(){return this.date().getMinutes()}setMinute(t){const e=this.date();return e.setMinutes(t),new i(e)}get second(){return this.date().getSeconds()}setSecond(t){const e=this.date();return e.setSeconds(t),new i(e)}get millisecond(){return this.date().getMilliseconds()}setMillisecond(t){const e=this.date();return e.setMilliseconds(t),new i(e)}toString(){return this.date().toISOString()}remainder(t){return X(this,t)}get isToday(){return this.truncate(O.DAY).equals(i.now().truncate(O.DAY))}truncate(t){return this.sub(this.remainder(t))}static now(){return new i(new Date)}static max(...t){let e=i.MIN;for(const r of t){const a=new i(r);a.after(e)&&(e=a)}return e}static min(...t){let e=i.MAX;for(const r of t){const a=new i(r);a.before(e)&&(e=a)}return e}static nanoseconds(t){return new i(t)}static microseconds(t){return i.nanoseconds(t*1e3)}static milliseconds(t){return i.microseconds(t*1e3)}static seconds(t){return i.milliseconds(t*1e3)}static minutes(t){return i.seconds(t*60)}static hours(t){return i.minutes(t*60)}static days(t){return i.hours(t*24)}};s(i,"NANOSECOND",i.nanoseconds(1)),s(i,"MICROSECOND",i.microseconds(1)),s(i,"MILLISECOND",i.milliseconds(1)),s(i,"SECOND",i.seconds(1)),s(i,"MINUTE",i.minutes(1)),s(i,"HOUR",i.hours(1)),s(i,"DAY",i.days(1)),s(i,"MAX",new i((1n<<63n)-1n)),s(i,"MIN",new i(0)),s(i,"ZERO",new i(0)),s(i,"z",l.z.union([l.z.object({value:l.z.bigint()}).transform(t=>new i(t.value)),l.z.string().transform(t=>new i(BigInt(t))),l.z.instanceof(Number).transform(t=>new i(t)),l.z.number().transform(t=>new i(t)),l.z.instanceof(i)]));let m=i;const u=class u{constructor(t){s(this,"value");s(this,"encodeValue",!0);typeof t=="number"&&(t=Math.trunc(t.valueOf())),this.value=BigInt(t.valueOf())}static fromSeconds(t){return t instanceof u?t:t instanceof L?t.period:t instanceof m?new u(t):["number","bigint"].includes(typeof t)?u.seconds(t):new u(t)}static fromMilliseconds(t){return t instanceof u?t:t instanceof L?t.period:t instanceof m?new u(t):["number","bigint"].includes(typeof t)?u.milliseconds(t):new u(t)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(t){return this.valueOf()<new u(t).valueOf()}greaterThan(t){return this.valueOf()>new u(t).valueOf()}lessThanOrEqual(t){return this.valueOf()<=new u(t).valueOf()}greaterThanOrEqual(t){return this.valueOf()>=new u(t).valueOf()}remainder(t){return X(this,t)}truncate(t){return new u(BigInt(Math.trunc(Number(this.valueOf()/t.valueOf())))*t.valueOf())}toString(){const t=this.truncate(u.DAY),e=this.truncate(u.HOUR),r=this.truncate(u.MINUTE),a=this.truncate(u.SECOND),f=this.truncate(u.MILLISECOND),h=this.truncate(u.MICROSECOND),p=this.truncate(u.NANOSECOND),y=t,S=e.sub(t),B=r.sub(e),c=a.sub(r),E=f.sub(a),v=h.sub(f),Y=p.sub(h);let M="";return y.isZero||(M+=`${y.days}d `),S.isZero||(M+=`${S.hours}h `),B.isZero||(M+=`${B.minutes}m `),c.isZero||(M+=`${c.seconds}s `),E.isZero||(M+=`${E.milliseconds}ms `),v.isZero||(M+=`${v.microseconds}µs `),Y.isZero||(M+=`${Y.nanoseconds}ns`),M.trim()}mult(t){return new u(this.valueOf()*BigInt(t))}get days(){return Number(this.valueOf())/Number(u.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(u.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(u.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(u.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(u.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(u.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(t){return this.valueOf()===new u(t).valueOf()}add(t){return new u(this.valueOf()+new u(t).valueOf())}sub(t){return new u(this.valueOf()-new u(t).valueOf())}static nanoseconds(t=1){return new u(t)}static microseconds(t=1){return u.nanoseconds(w.mult(t,1e3))}static milliseconds(t=1){return u.microseconds(w.mult(t,1e3))}static seconds(t=1){return u.milliseconds(w.mult(t,1e3))}static minutes(t=1){return u.seconds(w.mult(t,60))}static hours(t){return u.minutes(w.mult(t,60))}static days(t){return u.hours(w.mult(t,24))}};s(u,"NANOSECOND",u.nanoseconds(1)),s(u,"MICROSECOND",u.microseconds(1)),s(u,"MILLISECOND",u.milliseconds(1)),s(u,"SECOND",u.seconds(1)),s(u,"MINUTE",u.minutes(1)),s(u,"HOUR",u.hours(1)),s(u,"DAY",u.days(1)),s(u,"MAX",new u((1n<<63n)-1n)),s(u,"MIN",new u(0)),s(u,"ZERO",new u(0)),s(u,"z",l.z.union([l.z.object({value:l.z.bigint()}).transform(t=>new u(t.value)),l.z.string().transform(t=>new u(BigInt(t))),l.z.instanceof(Number).transform(t=>new u(t)),l.z.number().transform(t=>new u(t)),l.z.instanceof(u)]));let O=u;const A=class A extends Number{constructor(t){t instanceof Number?super(t.valueOf()):super(t)}toString(){return`${this.valueOf()} Hz`}equals(t){return this.valueOf()===new A(t).valueOf()}get period(){return O.seconds(1/this.valueOf())}sampleCount(t){return new O(t).seconds*this.valueOf()}byteCount(t,e){return this.sampleCount(t)*new I(e).valueOf()}span(t){return O.seconds(t/this.valueOf())}byteSpan(t,e){return this.span(t.valueOf()/e.valueOf())}static hz(t){return new A(t)}static khz(t){return A.hz(t*1e3)}};s(A,"z",l.z.union([l.z.number().transform(t=>new A(t)),l.z.instanceof(Number).transform(t=>new A(t)),l.z.instanceof(A)]));let L=A;const b=class b extends Number{constructor(t){t instanceof Number?super(t.valueOf()):super(t)}length(t){return t.valueOf()/this.valueOf()}size(t){return new C(t*this.valueOf())}};s(b,"UNKNOWN",new b(0)),s(b,"BIT128",new b(16)),s(b,"BIT64",new b(8)),s(b,"BIT32",new b(4)),s(b,"BIT16",new b(2)),s(b,"BIT8",new b(1)),s(b,"z",l.z.union([l.z.number().transform(t=>new b(t)),l.z.instanceof(Number).transform(t=>new b(t)),l.z.instanceof(b)]));let I=b;const T=class T{constructor(t,e){s(this,"start");s(this,"end");typeof t=="object"&&"start"in t?(this.start=new m(t.start),this.end=new m(t.end)):(this.start=new m(t),this.end=new m(e))}get span(){return new O(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new T(this.end,this.start)}equals(t){return this.start.equals(t.start)&&this.end.equals(t.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(t,e=O.ZERO){t=t.makeValid();const r=this.makeValid();if(this.equals(t))return!0;if(t.end.equals(r.start)||r.end.equals(t.start))return!1;const a=m.max(r.start,t.start),f=m.min(r.end,t.end);return f.before(a)?!1:new O(f.sub(a)).greaterThanOrEqual(e)}roughlyEquals(t,e){let r=this.start.sub(t.start).valueOf(),a=this.end.sub(t.end).valueOf();return r<0&&(r=-r),a<0&&(a=-a),r<=e.valueOf()&&a<=e.valueOf()}contains(t){return t instanceof T?this.contains(t.start)&&this.contains(t.end):this.start.beforeEq(t)&&this.end.after(t)}boundBy(t){const e=new T(this.start,this.end);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}};s(T,"MAX",new T(m.MIN,m.MAX)),s(T,"MIN",new T(m.MAX,m.MIN)),s(T,"ZERO",new T(m.ZERO,m.ZERO)),s(T,"z",l.z.union([l.z.object({start:m.z,end:m.z}).transform(t=>new T(t.start,t.end)),l.z.instanceof(T)]));let R=T;const ct=(o,t)=>o.start.before(t.start)?-1:o.start.after(t.start)?1:o.end.before(t.end)?-1:o.end.after(t.end)?1:0,n=class n extends String{constructor(t){if(t instanceof n||typeof t=="string"||typeof t.valueOf()=="string"){super(t.valueOf());return}const e=n.ARRAY_CONSTRUCTOR_DATA_TYPES.get(t.constructor.name);if(e!=null){super(e.valueOf());return}throw super(n.UNKNOWN.valueOf()),new Error(`unable to find data type for ${t.toString()}`)}get Array(){const t=n.ARRAY_CONSTRUCTORS.get(this.toString());if(t==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return t}equals(t){return this.valueOf()===t.valueOf()}matches(...t){return t.some(e=>this.equals(e))}toString(){return this.valueOf()}get isVariable(){return this.equals(n.JSON)||this.equals(n.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(n.UUID)}get isInteger(){const t=this.toString();return t.startsWith("int")||t.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const t=n.DENSITIES.get(this.toString());if(t==null)throw new Error(`unable to find density for ${this.valueOf()}`);return t}get isUnsigned(){return this.equals(n.UINT8)||this.equals(n.UINT16)||this.equals(n.UINT32)||this.equals(n.UINT64)}get isSigned(){return this.equals(n.INT8)||this.equals(n.INT16)||this.equals(n.INT32)||this.equals(n.INT64)}canSafelyCastTo(t){return this.equals(t)?!0:!this.isNumeric||!t.isNumeric||this.isVariable||t.isVariable||this.isUnsigned&&t.isSigned?!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.isUnsigned===t.isUnsigned:!1}canCastTo(t){return this.isNumeric&&t.isNumeric?!0:this.equals(t)}checkArray(t){return t.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return n.BIG_INT_TYPES.some(t=>t.equals(this))}};s(n,"UNKNOWN",new n("unknown")),s(n,"FLOAT64",new n("float64")),s(n,"FLOAT32",new n("float32")),s(n,"INT64",new n("int64")),s(n,"INT32",new n("int32")),s(n,"INT16",new n("int16")),s(n,"INT8",new n("int8")),s(n,"UINT64",new n("uint64")),s(n,"UINT32",new n("uint32")),s(n,"UINT16",new n("uint16")),s(n,"UINT8",new n("uint8")),s(n,"BOOLEAN",n.UINT8),s(n,"TIMESTAMP",new n("timestamp")),s(n,"UUID",new n("uuid")),s(n,"STRING",new n("string")),s(n,"JSON",new n("json")),s(n,"ARRAY_CONSTRUCTORS",new Map([[n.UINT8.toString(),Uint8Array],[n.UINT16.toString(),Uint16Array],[n.UINT32.toString(),Uint32Array],[n.UINT64.toString(),BigUint64Array],[n.FLOAT32.toString(),Float32Array],[n.FLOAT64.toString(),Float64Array],[n.INT8.toString(),Int8Array],[n.INT16.toString(),Int16Array],[n.INT32.toString(),Int32Array],[n.INT64.toString(),BigInt64Array],[n.TIMESTAMP.toString(),BigInt64Array],[n.STRING.toString(),Uint8Array],[n.JSON.toString(),Uint8Array],[n.UUID.toString(),Uint8Array]])),s(n,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,n.UINT8],[Uint16Array.name,n.UINT16],[Uint32Array.name,n.UINT32],[BigUint64Array.name,n.UINT64],[Float32Array.name,n.FLOAT32],[Float64Array.name,n.FLOAT64],[Int8Array.name,n.INT8],[Int16Array.name,n.INT16],[Int32Array.name,n.INT32],[BigInt64Array.name,n.INT64]])),s(n,"DENSITIES",new Map([[n.UINT8.toString(),I.BIT8],[n.UINT16.toString(),I.BIT16],[n.UINT32.toString(),I.BIT32],[n.UINT64.toString(),I.BIT64],[n.FLOAT32.toString(),I.BIT32],[n.FLOAT64.toString(),I.BIT64],[n.INT8.toString(),I.BIT8],[n.INT16.toString(),I.BIT16],[n.INT32.toString(),I.BIT32],[n.INT64.toString(),I.BIT64],[n.TIMESTAMP.toString(),I.BIT64],[n.STRING.toString(),I.UNKNOWN],[n.JSON.toString(),I.UNKNOWN],[n.UUID.toString(),I.BIT128]])),s(n,"ALL",[n.UNKNOWN,n.FLOAT64,n.FLOAT32,n.INT64,n.INT32,n.INT16,n.INT8,n.UINT64,n.UINT32,n.UINT16,n.UINT8,n.TIMESTAMP,n.UUID,n.STRING,n.JSON]),s(n,"BIG_INT_TYPES",[n.INT64,n.UINT64,n.TIMESTAMP]),s(n,"z",l.z.union([l.z.string().transform(t=>new n(t)),l.z.instanceof(n)]));let g=n;const d=class d extends Number{constructor(t){super(t.valueOf())}largerThan(t){return this.valueOf()>t.valueOf()}smallerThan(t){return this.valueOf()<t.valueOf()}add(t){return d.bytes(this.valueOf()+t.valueOf())}sub(t){return d.bytes(this.valueOf()-t.valueOf())}truncate(t){return new d(Math.trunc(this.valueOf()/t.valueOf())*t.valueOf())}remainder(t){return d.bytes(this.valueOf()%t.valueOf())}get gigabytes(){return this.valueOf()/d.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/d.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/d.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/d.TERABYTE.valueOf()}toString(){const t=this.truncate(d.TERABYTE),e=this.truncate(d.GIGABYTE),r=this.truncate(d.MEGABYTE),a=this.truncate(d.KILOBYTE),f=this.truncate(d.BYTE),h=t,p=e.sub(t),y=r.sub(e),S=a.sub(r),B=f.sub(a);let c="";return h.isZero||(c+=`${h.terabytes}TB `),p.isZero||(c+=`${p.gigabytes}GB `),y.isZero||(c+=`${y.megabytes}MB `),S.isZero||(c+=`${S.kilobytes}KB `),(!B.isZero||c==="")&&(c+=`${B.valueOf()}B`),c.trim()}static bytes(t=1){return new d(t)}static kilobytes(t=1){return d.bytes(t.valueOf()*1e3)}static megabytes(t=1){return d.kilobytes(t.valueOf()*1e3)}static gigabytes(t=1){return d.megabytes(t.valueOf()*1e3)}static terabytes(t){return d.gigabytes(t.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};s(d,"BYTE",new d(1)),s(d,"KILOBYTE",d.kilobytes(1)),s(d,"MEGABYTE",d.megabytes(1)),s(d,"GIGABYTE",d.gigabytes(1)),s(d,"TERABYTE",d.terabytes(1)),s(d,"ZERO",new d(0)),s(d,"z",l.z.union([l.z.number().transform(t=>new d(t)),l.z.instanceof(d)]));let C=d;const ft=l.z.union([l.z.instanceof(Uint8Array),l.z.instanceof(Uint16Array),l.z.instanceof(Uint32Array),l.z.instanceof(BigUint64Array),l.z.instanceof(Float32Array),l.z.instanceof(Float64Array),l.z.instanceof(Int8Array),l.z.instanceof(Int16Array),l.z.instanceof(Int32Array),l.z.instanceof(BigInt64Array)]),F=o=>{const t=typeof o;return t==="string"||t==="number"||t==="boolean"||t==="bigint"||o instanceof m||o instanceof O||o instanceof Date},Q=(o,t,e,r=0)=>o.usesBigInt&&!t.usesBigInt?Number(e)-Number(r):!o.usesBigInt&&t.usesBigInt?BigInt(e.valueOf())-BigInt(r.valueOf()):x(e,-r).valueOf(),x=(o,t)=>typeof o=="bigint"&&typeof t=="bigint"||typeof o=="number"&&typeof t=="number"?o+t:t===0?o:o===0?t:Number(o)+Number(t),_=o=>o==null?!1:Array.isArray(o)||o instanceof ArrayBuffer||ArrayBuffer.isView(o)&&!(o instanceof DataView)||o instanceof z?!0:F(o),U=-1,$={[Symbol.iterator]:()=>$,next:()=>({done:!0,value:void 0})},ht=l.z.string().transform(o=>new Uint8Array(atob(o).split("").map(t=>t.charCodeAt(0))).buffer),dt=l.z.union([l.z.null(),l.z.undefined()]).transform(()=>new Uint8Array().buffer),P=10,tt=(o,t)=>{if(o==="string"&&!t.isVariable)throw new Error(`cannot convert series of type ${t.toString()} to string`);if(o==="number"&&!t.isNumeric)throw new Error(`cannot convert series of type ${t.toString()} to number`);if(o==="bigint"&&!t.usesBigInt)throw new Error(`cannot convert series of type ${t.toString()} to bigint`)},N=class N{constructor(t){s(this,"key","");s(this,"isSynnaxSeries",!0);s(this,"dataType");s(this,"sampleOffset");s(this,"gl");s(this,"_data");s(this,"_timeRange");s(this,"alignment",0n);s(this,"_cachedMin");s(this,"_cachedMax");s(this,"writePos",U);s(this,"_refCount",0);s(this,"_cachedLength");s(this,"_cachedIndexes");_(t)&&(t={data:t});const{dataType:e,timeRange:r,sampleOffset:a=0,glBufferUsage:f="static",alignment:h=0n,key:p=K()}=t,y=t.data??[];if(y instanceof N||typeof y=="object"&&"isSynnaxSeries"in y&&y.isSynnaxSeries===!0){const c=y;this.key=c.key,this.dataType=c.dataType,this.sampleOffset=c.sampleOffset,this.gl=c.gl,this._data=c._data,this._timeRange=c._timeRange,this.alignment=c.alignment,this._cachedMin=c._cachedMin,this._cachedMax=c._cachedMax,this.writePos=c.writePos,this._refCount=c._refCount,this._cachedLength=c._cachedLength;return}const S=F(y),B=Array.isArray(y);if(e!=null)this.dataType=new g(e);else{if(y instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(B||S){let c=y;if(!S){if(y.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");c=y[0]}if(typeof c=="string")this.dataType=g.STRING;else if(typeof c=="number")this.dataType=g.FLOAT64;else if(typeof c=="bigint")this.dataType=g.INT64;else if(typeof c=="boolean")this.dataType=g.BOOLEAN;else if(c instanceof m||c instanceof Date||c instanceof m)this.dataType=g.TIMESTAMP;else if(typeof c=="object")this.dataType=g.JSON;else throw new Error(`cannot infer data type of ${typeof c} when constructing a Series from a JS array`)}else this.dataType=new g(y)}if(!B&&!S)this._data=y;else{let c=S?[y]:y;const E=c[0];(E instanceof m||E instanceof Date||E instanceof O)&&(c=c.map(v=>new m(v).valueOf())),this.dataType.equals(g.STRING)?(this._cachedLength=c.length,this._data=new TextEncoder().encode(`${c.join(`
2
- `)}
3
- `).buffer):this.dataType.equals(g.JSON)?(this._cachedLength=c.length,this._data=new TextEncoder().encode(`${c.map(v=>D.JSON_CODEC.encodeString(v)).join(`
4
- `)}
5
- `).buffer):this.dataType.usesBigInt&&typeof E=="number"?this._data=new this.dataType.Array(c.map(v=>BigInt(Math.round(v)))).buffer:!this.dataType.usesBigInt&&typeof E=="bigint"?this._data=new this.dataType.Array(c.map(v=>Number(v))).buffer:this._data=new this.dataType.Array(c).buffer}this.key=p,this.alignment=h,this.sampleOffset=a??0,this._timeRange=r,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:f}}static alloc({capacity:t,dataType:e,...r}){if(t===0)throw new Error("[Series] - cannot allocate an array of length 0");const a=new new g(e).Array(t),f=new N({data:a.buffer,dataType:e,...r});return f.writePos=0,f}static createTimestamps(t,e,r){const a=r.spanRange(e.span(t)),f=new BigInt64Array(t);for(let h=0;h<t;h++)f[h]=BigInt(r.add(e.span(h)).valueOf());return new N({data:f,dataType:g.TIMESTAMP,timeRange:a})}get refCount(){return this._refCount}static fromStrings(t,e){const r=new TextEncoder().encode(`${t.join(`
6
- `)}
7
- `);return new N({data:r,dataType:g.STRING,timeRange:e})}static fromJSON(t,e){const r=new TextEncoder().encode(`${t.map(a=>D.JSON_CODEC.encodeString(a)).join(`
8
- `)}
9
- `);return new N({data:r,dataType:g.JSON,timeRange:e})}acquire(t){this._refCount++,t!=null&&this.updateGLBuffer(t)}release(){if(this._refCount--,this._refCount===0&&this.gl.control!=null)this.maybeGarbageCollectGLBuffer(this.gl.control);else if(this._refCount<0)throw new Error("cannot release an array with a negative reference count")}write(t){if(!t.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");return this.dataType.isVariable?this.writeVariable(t):this.writeFixed(t)}writeVariable(t){if(this.writePos===U)return 0;const e=this.byteCapacity.valueOf()-this.writePos,r=t.subBytes(0,e);return this.writeToUnderlyingData(r),this.writePos+=r.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=r.length,this.calculateCachedLength()),r.length}writeFixed(t){if(this.writePos===U)return 0;const e=this.capacity-this.writePos,r=t.sub(0,e);return this.writeToUnderlyingData(r),this._cachedLength=void 0,this.maybeRecomputeMinMax(r),this.writePos+=r.length,r.length}writeToUnderlyingData(t){this.underlyingData.set(t.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===U?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(g.STRING,g.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
10
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(g.UUID))throw new Error("cannot convert non-uuid series to uuids");const t=g.UUID.density.valueOf(),e=Array(this.length);for(let r=0;r<this.length;r++){const a=this.underlyingData.slice(r*t,(r+1)*t),f=Array.from(new Uint8Array(a.buffer),h=>h.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");e[r]=f}return e}parseJSON(t){if(!this.dataType.equals(g.JSON))throw new Error("cannot parse non-JSON series as JSON");return new TextDecoder().decode(this.underlyingData).split(`
11
- `).slice(0,-1).map(e=>t.parse(D.JSON_CODEC.decodeString(e)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new C(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===U?this.byteCapacity:this.dataType.isVariable?new C(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===U?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let t=0;const e=[0];return this.data.forEach((r,a)=>{r===P&&(t++,e.push(a+1))}),this._cachedIndexes=e,this._cachedLength=t,t}convert(t,e=0){if(this.dataType.equals(t))return this;const r=new t.Array(this.length);for(let a=0;a<this.length;a++)r[a]=Q(this.dataType,t,this.data[a],e);return new N({data:r.buffer,dataType:t,timeRange:this._timeRange,sampleOffset:e,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(g.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const t=this.data;this._cachedMax=t.reduce((e,r)=>e>r?e:r)}else{const t=this.data;this._cachedMax=t.reduce((e,r)=>e>r?e:r)}return this._cachedMax}get max(){if(this.dataType.isVariable)throw new Error("cannot calculate maximum on a variable length data type");return this.writePos===0?-1/0:(this._cachedMax??(this._cachedMax=this.calcRawMax()),x(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(g.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const t=this.data;this._cachedMin=t.reduce((e,r)=>e<r?e:r)}else{const t=this.data;this._cachedMin=t.reduce((e,r)=>e<r?e:r)}return this._cachedMin}get min(){if(this.dataType.isVariable)throw new Error("cannot calculate minimum on a variable length data type");return this.writePos===0?1/0:(this._cachedMin??(this._cachedMin=this.calcRawMin()),x(this._cachedMin,this.sampleOffset))}get bounds(){return w.construct(Number(this.min),Number(this.max))}maybeRecomputeMinMax(t){if(this._cachedMin!=null){const e=t._cachedMin??t.calcRawMin();e<this._cachedMin&&(this._cachedMin=e)}if(this._cachedMax!=null){const e=t._cachedMax??t.calcRawMax();e>this._cachedMax&&(this._cachedMax=e)}}enrich(){this.max,this.min}get range(){return x(this.max,-this.min)}atAlignment(t,e){const r=Number(t-this.alignment);if(r<0||r>=this.length){if(e===!0)throw new Error(`[series] - no value at index ${r}`);return}return this.at(r,e)}at(t,e){if(this.dataType.isVariable)return this.atVariable(t,e??!1);t<0&&(t=this.length+t);const r=this.data[t];if(r==null){if(e===!0)throw new Error(`[series] - no value at index ${t}`);return}return x(r,this.sampleOffset)}atVariable(t,e){let r=0,a=0;if(this._cachedIndexes!=null)r=this._cachedIndexes[t],a=this._cachedIndexes[t+1]-1;else{t<0&&(t=this.length+t);for(let h=0;h<this.data.length;h++)if(this.data[h]===P){if(t===0){a=h;break}r=h+1,t--}if(a===0&&(a=this.data.length),r>=a||t>0){if(e)throw new Error(`[series] - no value at index ${t}`);return}}const f=this.data.slice(r,a);return this.dataType.equals(g.STRING)?new TextDecoder().decode(f):nt.snakeToCamel(JSON.parse(new TextDecoder().decode(f)))}binarySearch(t){let e=0,r=this.length-1;const a=st.newF(t);for(;e<=r;){const f=Math.floor((e+r)/2),h=a(this.at(f,!0),t);if(h===0)return f;h<0?e=f+1:r=f-1}return e}updateGLBuffer(t){if(this.gl.control=t,!this.dataType.equals(g.FLOAT32)&&!this.dataType.equals(g.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:e,bufferUsage:r,prevBuffer:a}=this.gl;if(e==null&&(this.gl.buffer=t.createBuffer()),this.writePos!==a)if(t.bindBuffer(t.ARRAY_BUFFER,this.gl.buffer),this.writePos!==U){a===0&&t.bufferData(t.ARRAY_BUFFER,this.byteCapacity.valueOf(),t.STATIC_DRAW);const f=this.dataType.density.size(a).valueOf(),h=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);t.bufferSubData(t.ARRAY_BUFFER,f,h.buffer),this.gl.prevBuffer=this.writePos}else t.bufferData(t.ARRAY_BUFFER,this.buffer,r==="static"?t.STATIC_DRAW:t.DYNAMIC_DRAW),this.gl.prevBuffer=U}as(t){return tt(t,this.dataType),this}get digest(){var t;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:k(this.alignmentBounds.lower),upper:k(this.alignmentBounds.upper)},timeRange:(t=this._timeRange)==null?void 0:t.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return w.construct(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(t){this.gl.buffer!=null&&(t.deleteBuffer(this.gl.buffer),this.gl.buffer=null,this.gl.prevBuffer=0,this.gl.control=null)}get glBuffer(){if(this.gl.buffer==null)throw new Error("gl buffer not initialized");return this.gl.prevBuffer!==this.writePos&&console.warn("buffer not updated"),this.gl.buffer}[Symbol.iterator](){if(this.dataType.isVariable){const t=new gt(this);return this.dataType.equals(g.JSON)?new mt(t):t}return new Ot(this)}slice(t,e){return this.sliceSub(!1,t,e)}sub(t,e){return this.sliceSub(!0,t,e)}subIterator(t,e){return new Z(this,t,e??this.length)}subAlignmentIterator(t,e){return new Z(this,Number(t-this.alignment),Number(e-this.alignment))}subBytes(t,e){if(t>=0&&(e==null||e>=this.byteLength.valueOf()))return this;const r=this.data.subarray(t,e);return new N({data:r,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}sliceSub(t,e,r){if(e<=0&&(r==null||r>=this.length))return this;let a;return t?a=this.data.subarray(e,r):a=this.data.slice(e,r),new N({data:a,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}reAlign(t){return new N({data:this.buffer,dataType:this.dataType,timeRange:R.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:t})}};s(N,"crudeZ",l.z.object({timeRange:R.z.optional(),dataType:g.z,alignment:l.z.coerce.bigint().optional(),data:l.z.union([ht,dt,l.z.instanceof(ArrayBuffer),l.z.instanceof(Uint8Array)]),glBufferUsage:lt.optional().default("static").optional()})),s(N,"z",N.crudeZ.transform(t=>new N(t)));let z=N;class Z{constructor(t,e,r){s(this,"series");s(this,"end");s(this,"index");this.series=t;const a=w.construct(0,t.length);this.end=w.clamp(a,r),this.index=w.clamp(a,e)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class gt{constructor(t){s(this,"series");s(this,"index");s(this,"decoder");if(!t.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=t,this.index=0,this.decoder=new TextDecoder}next(){const t=this.index,e=this.series.data;for(;this.index<e.length&&e[this.index]!==P;)this.index++;const r=this.index;return t===r?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(t,r))})}[Symbol.iterator](){return this}}var V,G;class mt{constructor(t){s(this,"wrapped");s(this,V,"JSONSeriesIterator");this.wrapped=t}next(){const t=this.wrapped.next();return t.done===!0?{done:!0,value:void 0}:{done:!1,value:D.JSON_CODEC.decodeString(t.value)}}[(G=Symbol.iterator,V=Symbol.toStringTag,G)](){return this}}var J,W;class Ot{constructor(t){s(this,"series");s(this,"index");s(this,J,"SeriesIterator");this.series=t,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[(W=Symbol.iterator,J=Symbol.toStringTag,W)](){return this}}class yt{constructor(t){s(this,"series");if(t.length!==0){const e=t[0].dataType;for(let r=1;r<t.length;r++)if(!t[r].dataType.equals(e))throw new Error("[multi-series] - series must have the same data type")}this.series=t}as(t){return tt(t,this.dataType),this}get dataType(){return this.series.length===0?g.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?R.ZERO:new R(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}get alignment(){return this.series.length===0?0n:this.series[0].alignment}get alignmentBounds(){return this.series.length===0?w.construct(0n,0n):w.construct(this.series[0].alignmentBounds.lower,this.series[this.series.length-1].alignmentBounds.upper)}push(t){this.series.push(t)}get length(){return this.series.reduce((t,e)=>t+e.length,0)}atAlignment(t,e){if(this.series.length===0){if(e)throw new Error(`[series] - no value at alignment ${t}`);return}for(const r of this.series)if(w.contains(r.alignmentBounds,t))return r.atAlignment(t,e);if(e)throw new Error(`[series] - no value at alignment ${t}`)}at(t,e=!1){t<0&&(t=this.length+t);for(const r of this.series){if(t<r.length)return r.at(t,e);t-=r.length}if(e)throw new Error(`[series] - no value at index ${t}`)}subIterator(t,e){return new q(this,t,e??this.length)}subAlignmentIterator(t,e){if(t>=this.alignmentBounds.upper||e<=this.alignmentBounds.lower)return $;let r=0;for(let f=0;f<this.series.length;f++){const h=this.series[f];if(t<h.alignment)break;if(t>=h.alignmentBounds.upper)r+=h.length;else if(w.contains(h.alignmentBounds,t)){r+=Number(t-h.alignment);break}}let a=0;for(let f=0;f<this.series.length;f++){const h=this.series[f];if(e<h.alignment)break;if(e>=h.alignmentBounds.upper)a+=h.length;else if(w.contains(h.alignmentBounds,e)){a+=Number(e-h.alignment);break}}return new q(this,r,a)}subAlignmentSpanIterator(t,e){if(t>=this.alignmentBounds.upper)return $;let r=0;for(let a=0;a<this.series.length;a++){const f=this.series[a];if(t<f.alignment)break;if(t>=f.alignmentBounds.upper)r+=f.length;else if(w.contains(f.alignmentBounds,t)){r+=Number(t-f.alignment);break}}return new q(this,r,r+e)}get byteLength(){return new C(this.series.reduce((t,e)=>t+e.byteLength.valueOf(),0))}get data(){const t=new this.dataType.Array(this.length);let e=0;for(const r of this.series)t.set(r.data,e),e+=r.length;return new this.dataType.Array(t.buffer)}traverseAlignment(t,e){const r=this.series.map(a=>a.alignmentBounds);return w.traverse(r,t,e)}distance(t,e){const r=this.series.map(a=>a.alignmentBounds);return w.distance(r,t,e)}parseJSON(t){if(!this.dataType.equals(g.JSON))throw new Error("cannot parse non-JSON series as JSON");return this.series.flatMap(e=>e.parseJSON(t))}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new wt(this.series)}}var j,H;class wt{constructor(t){s(this,"series");s(this,"seriesIndex");s(this,"internal");s(this,j,"MultiSeriesIterator");this.series=t,this.seriesIndex=0,this.internal=t[0][Symbol.iterator]()}next(){const t=this.internal.next();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())}[(H=Symbol.iterator,j=Symbol.toStringTag,H)](){return this}}class q{constructor(t,e,r){s(this,"series");s(this,"index");s(this,"end");this.series=t,this.end=r,this.index=e}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}const k=o=>{const t=o>>32n,e=o&0xffffffffn;return{domain:t,sample:e}};exports.DataType=g;exports.Density=I;exports.MultiSeries=yt;exports.Rate=L;exports.Series=z;exports.Size=C;exports.TimeRange=R;exports.TimeSpan=O;exports.TimeStamp=m;exports.addSamples=x;exports.convertDataType=Q;exports.id=ot;exports.isCrudeSeries=_;exports.isTelemValue=F;exports.sortTimeRange=ct;exports.typedArrayZ=ft;
@@ -1 +0,0 @@
1
- {"version":3,"file":"encoder.d.ts","sourceRoot":"","sources":["../../../src/binary/encoder.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,CAAC,EAAE,KAAK,SAAS,EAAE,MAAM,KAAK,CAAC;AAK7C;;;GAGG;AACH,MAAM,WAAW,KAAK;IACpB,2CAA2C;IAC3C,WAAW,EAAE,MAAM,CAAC;IAEpB;;;;;OAKG;IACH,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,WAAW,CAAC;IAE1C;;;;;OAKG;IACH,MAAM,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,UAAU,GAAG,WAAW,EAAE,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;CACzE;AAED,mDAAmD;AACnD,qBAAa,SAAU,YAAW,KAAK;IACrC,WAAW,SAAsB;IACjC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;IACtC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAc;;IAOtC,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW;IAIrC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAC3B,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,MAAM,CAAC,EAAE,CAAC,GACT,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAId,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAM3E,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAatC,MAAM,CAAC,kBAAkB,IAAI,IAAI;CAClC;AAED;;GAEG;AACH,qBAAa,QAAS,YAAW,KAAK;IACpC,WAAW,SAAc;IAEzB,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW;IAKrC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAC3B,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,MAAM,CAAC,EAAE,CAAC,GACT,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IAKd,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,MAAM;IAetC,YAAY,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;IA0B3E,OAAO,CAAC,UAAU;IAQlB,MAAM,CAAC,kBAAkB,IAAI,IAAI;CAClC;AAED,qBAAa,SAAU,YAAW,KAAK;IACrC,WAAW,SAAgB;IAE3B,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,WAAW;IAIrC,MAAM,CAAC,CAAC,SAAS,CAAC,CAAC,UAAU,EAC3B,IAAI,EAAE,UAAU,GAAG,WAAW,EAC9B,MAAM,CAAC,EAAE,CAAC,GACT,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;CAIf;AAED,eAAO,MAAM,UAAU,WAAkB,CAAC;AAC1C,eAAO,MAAM,SAAS,UAAiB,CAAC;AACxC,eAAO,MAAM,UAAU,WAAkB,CAAC;AAE1C,eAAO,MAAM,QAAQ,EAAE,KAAK,EAAiB,CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=encoder.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"encoder.spec.d.ts","sourceRoot":"","sources":["../../../src/binary/encoder.spec.ts"],"names":[],"mappings":""}
@@ -1,174 +0,0 @@
1
- // Copyright 2025 Synnax Labs, Inc.
2
- //
3
- // Use of this software is governed by the Business Source License included in the file
4
- // licenses/BSL.txt.
5
- //
6
- // As of the Change Date specified in that file, in accordance with the Business Source
7
- // License, use of this software will be governed by the Apache License, Version 2.0,
8
- // included in the file licenses/APL.txt.
9
-
10
- import { describe, expect, it } from "vitest";
11
- import { z } from "zod";
12
-
13
- import { binary } from "@/binary";
14
-
15
- const sampleSchema = z.object({
16
- channelKey: z.string(),
17
- timeStamp: z.number(),
18
- value: z.unknown(),
19
- });
20
-
21
- binary.ENCODERS.forEach((e) => {
22
- describe(`encoder ${e.contentType}`, () => {
23
- it("should correctly encode and decode items", () => {
24
- const sample = {
25
- channelKey: "test",
26
- timeStamp: 123,
27
- value: [1, 2, 3],
28
- };
29
- const encoded = e.encode(sample);
30
- expect(e.decode(encoded, sampleSchema)).toEqual(sample);
31
- });
32
- });
33
- });
34
-
35
- describe("JSON", () => {
36
- it("should correctly convert keys to snake case", () => {
37
- const sample = {
38
- channelKey: "test",
39
- timeStamp: 123,
40
- value: new Array([1, 2, 3]),
41
- };
42
- const encoded = binary.JSON_CODEC.encodeString(sample);
43
- const parse = JSON.parse(encoded);
44
- expect(parse.channel_key).toEqual("test");
45
- });
46
- it("should correctly decode keys from snake case", () => {
47
- const sample = {
48
- channel_key: "test",
49
- time_stamp: 123,
50
- value: new Array([1, 2, 3]),
51
- };
52
- const encoded = JSON.stringify(sample);
53
- const decoded = binary.JSON_CODEC.decodeString(encoded, sampleSchema);
54
- expect(decoded.channelKey).toEqual("test");
55
- });
56
-
57
- describe("CSVCodec", () => {
58
- it("should correctly decode CSV data with valid input", () => {
59
- const sample = `
60
- channelKey,timeStamp,value
61
- test,123,5
62
- test2,124,6
63
- `;
64
- const decoded = binary.CSV_CODEC.decodeString(sample);
65
- expect(decoded).toEqual({
66
- channelKey: ["test", "test2"],
67
- timeStamp: [123, 124],
68
- value: [5, 6],
69
- });
70
- });
71
-
72
- it("should handle empty CSV data", () => {
73
- const sample = `
74
- `;
75
- const decoded = binary.CSV_CODEC.decodeString(sample);
76
- expect(decoded).toEqual({});
77
- });
78
-
79
- it("should handle CSV with only headers", () => {
80
- const sample = `
81
- channelKey,timeStamp,value
82
- `;
83
- const decoded = binary.CSV_CODEC.decodeString(sample);
84
- expect(decoded).toEqual({
85
- channelKey: [],
86
- timeStamp: [],
87
- value: [],
88
- });
89
- });
90
-
91
- it("should handle CSV with missing values", () => {
92
- const sample = `
93
- channelKey,timeStamp,value
94
- test,123,
95
- test2,124,6
96
- `;
97
- const decoded = binary.CSV_CODEC.decodeString(sample);
98
- expect(decoded).toEqual({
99
- channelKey: ["test", "test2"],
100
- timeStamp: [123, 124],
101
- value: [6],
102
- });
103
- });
104
-
105
- it("should handle CSV with extra values", () => {
106
- const sample = `
107
- channelKey,timeStamp,value
108
- test,123,5,extra
109
- test2,124,6
110
- `;
111
- const decoded = binary.CSV_CODEC.decodeString(sample);
112
- expect(decoded).toEqual({
113
- channelKey: ["test", "test2"],
114
- timeStamp: [123, 124],
115
- value: [5, 6],
116
- });
117
- });
118
-
119
- it("should handle CSV with different types of values", () => {
120
- const sample = `
121
- key,number,string
122
- test,123,"hello"
123
- test2,456,"world"
124
- `;
125
- const decoded = binary.CSV_CODEC.decodeString(sample);
126
- expect(decoded).toEqual({
127
- key: ["test", "test2"],
128
- number: [123, 456],
129
- string: ["hello", "world"],
130
- });
131
- });
132
-
133
- it("should handle CSV with spaces around values", () => {
134
- const sample = `
135
- key, number , string
136
- test , 123 , "hello"
137
- test2 , 456 , "world"
138
- `;
139
- const decoded = binary.CSV_CODEC.decodeString(sample);
140
- expect(decoded).toEqual({
141
- key: ["test", "test2"],
142
- number: [123, 456],
143
- string: ["hello", "world"],
144
- });
145
- });
146
-
147
- it("should handle CSV with empty rows", () => {
148
- const sample = `
149
- key,number,string
150
- test,123,"hello"
151
- ,
152
- test2,456,"world"
153
- `;
154
- const decoded = binary.CSV_CODEC.decodeString(sample);
155
- expect(decoded).toEqual({
156
- key: ["test", "test2"],
157
- number: [123, 456],
158
- string: ["hello", "world"],
159
- });
160
- });
161
-
162
- it("should handle CSV with single column", () => {
163
- const sample = `
164
- key
165
- test
166
- test2
167
- `;
168
- const decoded = binary.CSV_CODEC.decodeString(sample);
169
- expect(decoded).toEqual({
170
- key: ["test", "test2"],
171
- });
172
- });
173
- });
174
- });