@synnaxlabs/pluto 0.30.0 → 0.31.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 (207) hide show
  1. package/dist/{Animated-DZSBu1oS.cjs → Animated-Bo0VMLXe.cjs} +1 -1
  2. package/dist/{Animated-CADTcu8B.js → Animated-CqxAz8yC.js} +2 -2
  3. package/dist/Item-Cr7Cee2t.js +110 -0
  4. package/dist/Item-s_R6czdE.cjs +1 -0
  5. package/dist/Keyboard-CIJ6C-6F.js +25 -0
  6. package/dist/Keyboard-D-9KUUCq.cjs +1 -0
  7. package/dist/{LinePlot-CUYMMNNX.js → LinePlot-CVOH06qp.js} +2094 -2090
  8. package/dist/LinePlot-k6OxHynn.cjs +66 -0
  9. package/dist/{Link-CurnG57L.js → Link-B1bLviPV.js} +1 -1
  10. package/dist/{Link-BUlcFhdF.cjs → Link-z1QKdW8G.cjs} +1 -1
  11. package/dist/{List-d1KJe77_.cjs → List-DVMb5TAO.cjs} +1 -1
  12. package/dist/List-L9yD_LRe.js +22 -0
  13. package/dist/Pack-BrxYNh7B.js +137 -0
  14. package/dist/Pack-C_SrDA3a.cjs +1 -0
  15. package/dist/Text-D9wOBnT3.js +32 -0
  16. package/dist/Text-Vzb9NS0-.cjs +1 -0
  17. package/dist/{Toggle-BGyo9v6o.js → Toggle-BrC3s3ox.js} +7802 -7745
  18. package/dist/Toggle-DdnBJm8D.cjs +143 -0
  19. package/dist/{Video-JYqTPKDk.cjs → Video-DR3tjTFZ.cjs} +1 -1
  20. package/dist/{Video-Ciw4h8eF.js → Video-DdIv_1Yq.js} +1 -1
  21. package/dist/{aggregator-Dgqx_W5g.js → aggregator-BNkkZ-Bc.js} +5030 -4323
  22. package/dist/aggregator-LvZi4Kvh.cjs +67 -0
  23. package/dist/align.cjs +1 -1
  24. package/dist/align.js +1 -1
  25. package/dist/button.cjs +1 -1
  26. package/dist/button.js +1 -1
  27. package/dist/color.cjs +1 -1
  28. package/dist/color.js +1 -1
  29. package/dist/{css-CiSR0WsA.js → css-B8RwzK24.js} +96 -96
  30. package/dist/css-LxkguM_s.cjs +1 -0
  31. package/dist/css.cjs +1 -1
  32. package/dist/css.js +2 -2
  33. package/dist/dropdown.cjs +1 -1
  34. package/dist/dropdown.js +1 -1
  35. package/dist/ether.cjs +1 -1
  36. package/dist/ether.js +5 -5
  37. package/dist/external-ArTLjo1-.cjs +1 -0
  38. package/dist/external-B1KQRpm7.js +353 -0
  39. package/dist/{external-5teQpcGD.cjs → external-BGcGef1R.cjs} +1 -1
  40. package/dist/{external-Dds3S09i.js → external-BaV5u1sJ.js} +21 -21
  41. package/dist/{external-Co2r9DLy.cjs → external-BpWJNQQi.cjs} +1 -1
  42. package/dist/{external-B-qyhpkX.js → external-BwdvFk2R.js} +2 -2
  43. package/dist/external-BxX4TXgQ.cjs +1 -0
  44. package/dist/{external-C2rLSz0G.js → external-ByGOTAK0.js} +128 -128
  45. package/dist/{external-CNl6YOd-.cjs → external-CGdoEsew.cjs} +1 -1
  46. package/dist/external-CJt9nz9P.cjs +1 -0
  47. package/dist/{external-Clb-pmsS.cjs → external-Cl_evqYY.cjs} +1 -1
  48. package/dist/{external-CulLnj8B.js → external-Cta1T9rO.js} +20 -20
  49. package/dist/{external-CTth9RPW.cjs → external-CzVXDUkp.cjs} +1 -1
  50. package/dist/{external--tP96O6n.cjs → external-D7bzFwDm.cjs} +1 -1
  51. package/dist/external-DAswAy_H.js +322 -0
  52. package/dist/external-DmH8EJ0I.cjs +1 -0
  53. package/dist/external-DzY80h7T.js +76 -0
  54. package/dist/{external-B6F5s5aQ.js → external-EHAadzLe.js} +6 -6
  55. package/dist/{external-C5nr86pR.cjs → external-MSpJvixc.cjs} +1 -1
  56. package/dist/{external-B8UhV4HB.cjs → external-ZS0XGHuP.cjs} +1 -1
  57. package/dist/{external-B_mVlkww.js → external-n_t7VfzS.js} +1 -1
  58. package/dist/external-oW8IRqfk.js +13 -0
  59. package/dist/{external-BjZo74zS.js → external-qbHFNsHS.js} +74 -74
  60. package/dist/external-vf43rlmJ.js +20 -0
  61. package/dist/header.cjs +1 -1
  62. package/dist/header.js +1 -1
  63. package/dist/index.cjs +1 -1
  64. package/dist/index.js +5417 -4264
  65. package/dist/input.cjs +1 -1
  66. package/dist/input.js +1 -1
  67. package/dist/list.cjs +1 -1
  68. package/dist/list.js +1 -1
  69. package/dist/menu.cjs +1 -1
  70. package/dist/menu.js +1 -1
  71. package/dist/src/align/Pack.d.ts +1 -2
  72. package/dist/src/align/Pack.d.ts.map +1 -1
  73. package/dist/src/align/Space.d.ts +1 -0
  74. package/dist/src/align/Space.d.ts.map +1 -1
  75. package/dist/src/breadcrumb/Breadcrumb.d.ts +1 -1
  76. package/dist/src/breadcrumb/Breadcrumb.d.ts.map +1 -1
  77. package/dist/src/button/Button.d.ts +3 -1
  78. package/dist/src/button/Button.d.ts.map +1 -1
  79. package/dist/src/button/Icon.d.ts +1 -1
  80. package/dist/src/button/Icon.d.ts.map +1 -1
  81. package/dist/src/button/Toggle.d.ts +1 -0
  82. package/dist/src/button/Toggle.d.ts.map +1 -1
  83. package/dist/src/channel/LinePlot.d.ts +2 -1
  84. package/dist/src/channel/LinePlot.d.ts.map +1 -1
  85. package/dist/src/css/css.d.ts +1 -0
  86. package/dist/src/css/css.d.ts.map +1 -1
  87. package/dist/src/dropdown/Dropdown.d.ts.map +1 -1
  88. package/dist/src/icon/Icon.d.ts +5 -0
  89. package/dist/src/icon/Icon.d.ts.map +1 -1
  90. package/dist/src/index.d.ts +1 -0
  91. package/dist/src/index.d.ts.map +1 -1
  92. package/dist/src/input/Numeric.d.ts +3 -2
  93. package/dist/src/input/Numeric.d.ts.map +1 -1
  94. package/dist/src/input/Text.d.ts +3 -1
  95. package/dist/src/input/Text.d.ts.map +1 -1
  96. package/dist/src/input/types.d.ts +3 -1
  97. package/dist/src/input/types.d.ts.map +1 -1
  98. package/dist/src/menu/Item.d.ts +11 -22
  99. package/dist/src/menu/Item.d.ts.map +1 -1
  100. package/dist/src/modal/Modal.d.ts +7 -3
  101. package/dist/src/modal/Modal.d.ts.map +1 -1
  102. package/dist/src/mosaic/Mosaic.d.ts +25 -2
  103. package/dist/src/mosaic/Mosaic.d.ts.map +1 -1
  104. package/dist/src/mosaic/tree.d.ts +21 -1
  105. package/dist/src/mosaic/tree.d.ts.map +1 -1
  106. package/dist/src/mosaic/types.d.ts +6 -1
  107. package/dist/src/mosaic/types.d.ts.map +1 -1
  108. package/dist/src/pluto/Pluto.d.ts.map +1 -1
  109. package/dist/src/select/Alignment.d.ts +12 -0
  110. package/dist/src/select/Alignment.d.ts.map +1 -0
  111. package/dist/src/select/external.d.ts +1 -0
  112. package/dist/src/select/external.d.ts.map +1 -1
  113. package/dist/src/status/aether/aggregator.d.ts.map +1 -1
  114. package/dist/src/tabs/Selector.d.ts +4 -2
  115. package/dist/src/tabs/Selector.d.ts.map +1 -1
  116. package/dist/src/tabs/Tabs.d.ts +129 -7
  117. package/dist/src/tabs/Tabs.d.ts.map +1 -1
  118. package/dist/src/tabs/types.d.ts +7 -1
  119. package/dist/src/tabs/types.d.ts.map +1 -1
  120. package/dist/src/text/Editable.d.ts.map +1 -1
  121. package/dist/src/text/Keyboard.d.ts +1 -1
  122. package/dist/src/text/Keyboard.d.ts.map +1 -1
  123. package/dist/src/text/WithIcon.d.ts +2 -2
  124. package/dist/src/text/WithIcon.d.ts.map +1 -1
  125. package/dist/src/theming/core/theme.d.ts.map +1 -1
  126. package/dist/src/theming/css.d.ts.map +1 -1
  127. package/dist/src/triggers/Provider.d.ts +3 -2
  128. package/dist/src/triggers/Provider.d.ts.map +1 -1
  129. package/dist/src/triggers/hooks.d.ts +3 -4
  130. package/dist/src/triggers/hooks.d.ts.map +1 -1
  131. package/dist/src/triggers/triggers.d.ts +17 -3
  132. package/dist/src/triggers/triggers.d.ts.map +1 -1
  133. package/dist/src/util/rootElement.d.ts +1 -1
  134. package/dist/src/util/rootElement.d.ts.map +1 -1
  135. package/dist/src/vis/axis/canvas.d.ts.map +1 -1
  136. package/dist/src/vis/canvas/Canvas.d.ts.map +1 -1
  137. package/dist/src/vis/diagram/Diagram.d.ts +3 -1
  138. package/dist/src/vis/diagram/Diagram.d.ts.map +1 -1
  139. package/dist/src/vis/diagram/aether/Diagram.d.ts +9 -0
  140. package/dist/src/vis/diagram/aether/Diagram.d.ts.map +1 -1
  141. package/dist/src/vis/grid/grid.d.ts +115 -0
  142. package/dist/src/vis/grid/grid.d.ts.map +1 -0
  143. package/dist/src/vis/grid/grid.spec.d.ts +2 -0
  144. package/dist/src/vis/grid/grid.spec.d.ts.map +1 -0
  145. package/dist/src/vis/grid/index.d.ts +2 -0
  146. package/dist/src/vis/grid/index.d.ts.map +1 -0
  147. package/dist/src/vis/legend/Simple.d.ts +1 -0
  148. package/dist/src/vis/legend/Simple.d.ts.map +1 -1
  149. package/dist/src/vis/light/use.d.ts.map +1 -1
  150. package/dist/src/vis/lineplot/Axis.d.ts.map +1 -1
  151. package/dist/src/vis/lineplot/Legend.d.ts +3 -1
  152. package/dist/src/vis/lineplot/Legend.d.ts.map +1 -1
  153. package/dist/src/vis/lineplot/LinePlot.d.ts +4 -4
  154. package/dist/src/vis/lineplot/LinePlot.d.ts.map +1 -1
  155. package/dist/src/vis/lineplot/aether/LinePlot.d.ts +16 -10
  156. package/dist/src/vis/lineplot/aether/LinePlot.d.ts.map +1 -1
  157. package/dist/src/vis/lineplot/aether/axis.d.ts +2 -2
  158. package/dist/src/vis/lineplot/aether/axis.d.ts.map +1 -1
  159. package/dist/src/vis/measure/Measure.d.ts.map +1 -1
  160. package/dist/src/vis/schematic/Forms.d.ts +7 -1
  161. package/dist/src/vis/schematic/Forms.d.ts.map +1 -1
  162. package/dist/src/vis/schematic/Labeled.d.ts +2 -0
  163. package/dist/src/vis/schematic/Labeled.d.ts.map +1 -1
  164. package/dist/src/vis/schematic/SelectOrientation.d.ts +5 -2
  165. package/dist/src/vis/schematic/SelectOrientation.d.ts.map +1 -1
  166. package/dist/src/vis/schematic/Symbols.d.ts +139 -35
  167. package/dist/src/vis/schematic/Symbols.d.ts.map +1 -1
  168. package/dist/src/vis/schematic/primitives/Primitives.d.ts +42 -3
  169. package/dist/src/vis/schematic/primitives/Primitives.d.ts.map +1 -1
  170. package/dist/src/vis/schematic/registry.d.ts +1 -1
  171. package/dist/src/vis/schematic/registry.d.ts.map +1 -1
  172. package/dist/style.css +1 -1
  173. package/dist/tabs.cjs +1 -1
  174. package/dist/tabs.js +1 -1
  175. package/dist/text.cjs +1 -1
  176. package/dist/text.js +2 -2
  177. package/dist/theming.cjs +1 -1
  178. package/dist/theming.js +2 -2
  179. package/dist/tree.cjs +1 -1
  180. package/dist/tree.js +1 -1
  181. package/dist/triggers.cjs +1 -1
  182. package/dist/triggers.js +1 -1
  183. package/dist/{units-C59nowP2.cjs → units-CMXTKjnN.cjs} +1 -1
  184. package/dist/{units-BAK8qzqy.js → units-CnA_yWxx.js} +1 -1
  185. package/dist/video.cjs +1 -1
  186. package/dist/video.js +1 -1
  187. package/package.json +7 -7
  188. package/dist/Keyboard-Bc_uxMTG.js +0 -13
  189. package/dist/Keyboard-BvHL3Wf2.cjs +0 -1
  190. package/dist/LinePlot-DUHbDcz3.cjs +0 -66
  191. package/dist/List-DD-MkX0Z.js +0 -22
  192. package/dist/Pack-BgzS2BHo.cjs +0 -1
  193. package/dist/Pack-l3j3YWpE.js +0 -134
  194. package/dist/Toggle-DWKDszrQ.cjs +0 -143
  195. package/dist/aggregator-C7n8uv-R.cjs +0 -57
  196. package/dist/css-Cc1vb61S.cjs +0 -1
  197. package/dist/external-1ZU7gP__.cjs +0 -1
  198. package/dist/external-B-gkanM-.js +0 -271
  199. package/dist/external-B0zpdR1h.js +0 -74
  200. package/dist/external-C4beOlX2.cjs +0 -1
  201. package/dist/external-CW9xTNHG.js +0 -353
  202. package/dist/external-Dh0igrIc.js +0 -97
  203. package/dist/external-E30UptW0.js +0 -13
  204. package/dist/external-FuH8ekoj.cjs +0 -1
  205. package/dist/external-HLgDxDKN.cjs +0 -1
  206. package/dist/src/vis/lineplot/aether/grid.d.ts +0 -40
  207. package/dist/src/vis/lineplot/aether/grid.d.ts.map +0 -1
@@ -1,57 +0,0 @@
1
- "use strict";var dc=Object.defineProperty;var fc=(t,e,r)=>e in t?dc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r;var P=(t,e,r)=>fc(t,typeof e!="symbol"?e+"":e,r);const s=require("zod"),O=require("./css-Cc1vb61S.cjs"),Qn=require("react");var yc=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function gc(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}function pc(t){if(t.__esModule)return t;var e=t.default;if(typeof e=="function"){var r=function n(){return this instanceof n?Reflect.construct(e,arguments,this.constructor):e.apply(this,arguments)};r.prototype=e.prototype}else r={};return Object.defineProperty(r,"__esModule",{value:!0}),Object.keys(t).forEach(function(n){var i=Object.getOwnPropertyDescriptor(t,n);Object.defineProperty(r,n,i.get?i:{enumerable:!0,get:function(){return t[n]}})}),r}const Ot=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var mc=Object.defineProperty,wc=(t,e,r)=>e in t?mc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Tt=(t,e,r)=>wc(t,typeof e!="symbol"?e+"":e,r);let bc=class{constructor(){Tt(this,"contentType","application/json"),Tt(this,"decoder"),Tt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,r){return this.decodeString(this.decoder.decode(e),r)}decodeString(e,r){const n=JSON.parse(e),i=O.T(n);return r!=null?r.parse(i):i}encodeString(e){const r=O.v(e);return JSON.stringify(r,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):Ot(i)&&"encode_value"in i?typeof i.value=="bigint"?i.value.toString():i.value:typeof i=="bigint"?i.toString():i)}static registerCustomType(){}},vc=class{constructor(){Tt(this,"contentType","text/csv")}encode(e){const r=this.encodeString(e);return new TextEncoder().encode(r).buffer}decode(e,r){const n=new TextDecoder().decode(e);return this.decodeString(n,r)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Ot(e[0]))throw new Error("Payload must be an array of objects");const r=Object.keys(e[0]),n=[r.join(",")];return e.forEach(i=>{const a=r.map(o=>JSON.stringify(i[o]??""));n.push(a.join(","))}),n.join(`
2
- `)}decodeString(e,r){const[n,...i]=e.trim().split(`
3
- `).map(c=>c.trim());if(n.length===0)return r!=null?r.parse({}):{};const a=n.split(",").map(c=>c.trim()),o={};return a.forEach(c=>{o[c]=[]}),i.forEach(c=>{const u=c.split(",").map(d=>d.trim());a.forEach((d,f)=>{const h=this.parseValue(u[f]);h!=null&&o[d].push(h)})}),r!=null?r.parse(o):o}parseValue(e){if(e==null||e.length===0)return null;const r=Number(e);return isNaN(r)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:r}static registerCustomType(){}},Oc=class{constructor(){Tt(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,r){const n=new TextDecoder().decode(e);return r!=null?r.parse(n):n}};const tr=new bc;new vc;new Oc;const Ri=t=>t!=null&&typeof t=="object"&&"toString"in t,Tc=t=>{if(Ri(t))return(t==null?void 0:t.toString().length)===0;switch(typeof t){case"string":return t.length===0;case"number":return t===0;case"bigint":return t===0n;case"boolean":return!t;case"undefined":return!0;case"object":return t===null}},Lr=(t,e=!1)=>{const r=Ri(t)?"stringer":typeof t;let n;switch(r){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Mi(n):n},Sc=(t,e,r)=>{const n=Lr(e[t],r);return(i,a)=>n(i[t],a[t])},zc=(t,e)=>t.length!==e.length?t.length-e.length:t.every((r,n)=>r===e[n])?0:-1,Nc=(t,e)=>{if(t.length!==e.length)return t.length-e.length;if(t.length===0)return 0;const r=Lr(t[0]),n=[...t].sort(r),i=[...e].sort(r);return n.every((a,o)=>a===i[o])?0:-1},Ec=(t,e)=>t===e?0:t==="first"&&e==="last"?1:-1,Mi=t=>(e,r)=>t(r,e),Ic=0,tn=-1,rn=1,Di=t=>t<0,Pi=t=>t>0,kc=t=>t>=0,Bi=t=>t===0,Ac=(t,e)=>{const r=/([a-zA-Z]+)|(\d+)/g,n=t.replace(/[\s_.-]+/g,"").match(r),i=e.replace(/[\s_.-]+/g,"").match(r);if(!n||!i)return 0;for(let a=0;a<Math.min(n.length,i.length);a++){const o=n[a],c=i[a];if(isNaN(Number(o))&&isNaN(Number(c))){const u=o.localeCompare(c);if(u!==0)return u}else if(!isNaN(Number(o))&&!isNaN(Number(c))){const u=Number(o)-Number(c);if(u!==0)return u}else return isNaN(Number(o))?-1:1}return n.length-i.length},xc=Object.freeze(Object.defineProperty({__proto__:null,EQUAL:0,GREATER_THAN:1,LESS_THAN:-1,isEqualTo:Bi,isGreaterThan:Pi,isGreaterThanEqual:kc,isLessThan:Di,newF:Lr,newFieldF:Sc,order:Ec,primitiveArrays:zc,reverseF:Mi,stringsWithNumbers:Ac,unorderedPrimitiveArrays:Nc},Symbol.toStringTag,{value:"Module"})),Cc=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}},$c=(t,e)=>{let r=null;return e===0?t:(...n)=>{r===null&&(r=setTimeout(()=>{t(...n),r=null},e))}},Ui=(t,e,r=".")=>{const n=t.split(r);return n.map((i,a)=>{const o=e(i,a,n);return o==null?null:typeof o=="string"?o:o.join(r)}).filter(i=>i!=null).join(r)},es=(t,e,r={optional:!1,separator:"."})=>{r.separator??(r.separator=".");const{optional:n,getter:i=(c,u)=>c[u]}=r,a=e.split(r.separator);if(a.length===1&&a[0]==="")return t;let o=t;for(const c of a){const u=i(o,c);if(u==null){if(n)return null;throw new Error(`Path ${e} does not exist. ${c} is null`)}o=u}return o},jc=(t,e,r)=>{const n=e.split(".");let i=t;for(let a=0;a<n.length-1;a++){const o=n[a];i[o]==null&&(i[o]={}),i=i[o]}i[n[n.length-1]]=r},Rc=(t,e)=>{const r=e.split(".");let n=t;for(let i=0;i<r.length-1;i++){const a=r[i];if(n[a]==null)return;n=n[a]}if(Array.isArray(n)){const i=parseInt(r[r.length-1],10);if(isNaN(i))return;n.splice(i,1);return}delete n[r[r.length-1]]},Mc=(t,e)=>{const r=t.split(".");return e<0?r[r.length+e]:r[e]},Dc=(t,e)=>{try{return es(t,e),!0}catch{return!1}},Pc=(t,e)=>{if(e.length===0)return!0;const r=t.split("."),n=e.split(".");if(n.length>r.length)return!1;for(let i=0;i<n.length;i++){const a=r[i],o=n[i];if(o!=="*"&&a!==o)return!1}return!0},Bc=t=>JSON.parse(JSON.stringify(t)),Uc=(t,...e)=>(e.forEach(r=>{let n=t;const i=r.split(".");i.forEach((a,o)=>{o===i.length-1?delete n[a]:a in n&&(n=n[a])})}),t),Lc=(t,e,r="")=>{const n={},i=(a,o,c)=>{if(typeof a!=typeof o||a===null||o===null){n[c]=[a,o];return}if(typeof a=="object"&&typeof o=="object")if(Array.isArray(a)&&Array.isArray(o)){if(a.length!==o.length){n[c]=[a,o];return}for(let u=0;u<a.length;u++)i(a[u],o[u],`${c}[${u}]`)}else new Set([...Object.keys(a),...Object.keys(o)]).forEach(u=>{i(a[u],o[u],c!==""?`${c}.${u}`:u)});else a!==o&&(n[c]=[a,o])};return i(t,e,r),n},An=(t,e)=>{const r=Array.isArray(t),n=Array.isArray(e);if(r!==n)return!1;if(r&&n){const o=t,c=e;if(o.length!==c.length)return!1;for(let u=0;u<o.length;u++)if(!An(o[u],c[u]))return!1;return!0}if(t==null||e==null||typeof t!="object"||typeof e!="object")return t===e;if("equals"in t)return t.equals(e);const i=Object.keys(t),a=Object.keys(e);if(i.length!==a.length)return!1;for(const o of i){const c=t[o],u=e[o];if(typeof c=="object"&&typeof u=="object"){if(!An(c,u))return!1}else if(c!==u)return!1}return!0},Li=(t,e)=>{if(typeof t!="object"||t==null)return t===e;const r=Object.keys(t),n=Object.keys(e);if(n.length>r.length)return!1;for(const i of n){const a=t[i],o=e[i];if(typeof a=="object"&&typeof o=="object"){if(!Li(a,o))return!1}else if(a!==o)return!1}return!0},xn=(t,...e)=>{if(e.length===0)return t;const r=e.shift();if(Ot(t)&&Ot(r))for(const n in r)try{Ot(r[n])?(n in t||Object.assign(t,{[n]:{}}),xn(t[n],r[n])):Object.assign(t,{[n]:r[n]})}catch(i){throw i instanceof TypeError?new TypeError(`.${n}: ${i.message}`):i}return xn(t,...e)},Yc=(t,e,r)=>{const n=(i,a,o)=>{for(const c in a){const u=a[c];if(o!=null&&o.shape[c]){const d=o.shape[c].safeParse(u);d.success&&(i[c]=d.data)}else typeof u=="object"&&!Array.isArray(u)&&u!==null&&o&&o.shape&&o.shape[c]&&(i[c]||(i[c]={}),n(i[c],u,o.shape[c]))}return i};return n({...t},e,r)},Yi=Object.freeze(Object.defineProperty({__proto__:null,copy:Bc,deleteD:Uc,difference:Lc,element:Mc,equal:An,get:es,has:Dc,override:xn,overrideValidItems:Yc,partialEqual:Li,pathsMatch:Pc,remove:Rc,set:jc,transformPath:Ui},Symbol.toStringTag,{value:"Module"}));var qc=Object.defineProperty,_c=(t,e,r)=>e in t?qc(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,m=(t,e,r)=>_c(t,typeof e!="symbol"?e+"":e,r);let Fc=(t,e=21)=>(r=e)=>{let n="",i=r;for(;i--;)n+=t[Math.random()*t.length|0];return n};const Wc="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",qi=Fc(Wc,11),Vc=Object.freeze(Object.defineProperty({__proto__:null,id:qi},Symbol.toStringTag,{value:"Module"})),_i=(t,e)=>{const r=new F(e);if(![V.DAY,V.HOUR,V.MINUTE,V.SECOND,V.MILLISECOND,V.MICROSECOND,V.NANOSECOND].some(i=>i.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof F?new F(n):new V(n)},B=class T{constructor(e,r="UTC"){if(m(this,"value"),m(this,"encodeValue",!0),e==null)this.value=T.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*T.MILLISECOND.valueOf();else if(typeof e=="string")this.value=T.parseDateTimeString(e,r).valueOf();else if(Array.isArray(e))this.value=T.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=T.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=T.MAX:e=T.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,r=1,n=1]){const i=new Date(e,r-1,n,0,0,0,0);return new T(BigInt(i.getTime())*T.MILLISECOND.valueOf()).truncate(T.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=T.hours(parseInt(n??"00",10)).add(T.minutes(parseInt(i??"00",10))).add(T.seconds(parseInt(o??"00",10))).add(T.milliseconds(parseInt(c??"00",10)));return r==="local"&&(u=u.add(T.utcOffset)),u.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return T.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new T(BigInt(n.getTime())*T.MILLISECOND.valueOf(),r).valueOf()}fString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(T.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new V(BigInt(new Date().getTimezoneOffset())*T.MINUTE.valueOf())}static since(e){return new T().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new T(e).valueOf()}span(e){return this.range(e).span}range(e){return new kt(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new T(e).valueOf()}afterEq(e){return this.valueOf()>=new T(e).valueOf()}before(e){return this.valueOf()<new T(e).valueOf()}beforeEq(e){return this.valueOf()<=new T(e).valueOf()}add(e){return new T(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new T(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(T.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return _i(this,e)}get isToday(){return this.truncate(V.DAY).equals(T.now().truncate(V.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new T(new Date)}static max(...e){let r=T.MIN;for(const n of e){const i=new T(n);i.after(r)&&(r=i)}return r}static min(...e){let r=T.MAX;for(const n of e){const i=new T(n);i.before(r)&&(r=i)}return r}static nanoseconds(e){return new T(e)}static microseconds(e){return T.nanoseconds(e*1e3)}static milliseconds(e){return T.microseconds(e*1e3)}static seconds(e){return T.milliseconds(e*1e3)}static minutes(e){return T.seconds(e*60)}static hours(e){return T.minutes(e*60)}static days(e){return T.hours(e*24)}};m(B,"NANOSECOND",B.nanoseconds(1)),m(B,"MICROSECOND",B.microseconds(1)),m(B,"MILLISECOND",B.milliseconds(1)),m(B,"SECOND",B.seconds(1)),m(B,"MINUTE",B.minutes(1)),m(B,"HOUR",B.hours(1)),m(B,"DAY",B.days(1)),m(B,"MAX",new B((1n<<63n)-1n)),m(B,"MIN",new B(0)),m(B,"ZERO",new B(0)),m(B,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new B(t.value)),s.z.string().transform(t=>new B(BigInt(t))),s.z.instanceof(Number).transform(t=>new B(t)),s.z.number().transform(t=>new B(t)),s.z.instanceof(B)]));let F=B;const U=class A{constructor(e){m(this,"value"),m(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new A(e).valueOf()}greaterThan(e){return this.valueOf()>new A(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new A(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new A(e).valueOf()}remainder(e){return _i(this,e)}truncate(e){return new A(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(A.DAY),r=this.truncate(A.HOUR),n=this.truncate(A.MINUTE),i=this.truncate(A.SECOND),a=this.truncate(A.MILLISECOND),o=this.truncate(A.MICROSECOND),c=this.truncate(A.NANOSECOND),u=e,d=r.sub(e),f=n.sub(r),h=i.sub(n),j=a.sub(i),W=o.sub(a),se=c.sub(o);let R="";return u.isZero||(R+=`${u.days}d `),d.isZero||(R+=`${d.hours}h `),f.isZero||(R+=`${f.minutes}m `),h.isZero||(R+=`${h.seconds}s `),j.isZero||(R+=`${j.milliseconds}ms `),W.isZero||(R+=`${W.microseconds}µs `),se.isZero||(R+=`${se.nanoseconds}ns`),R.trim()}get days(){return Number(this.valueOf())/Number(A.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(A.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(A.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(A.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(A.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(A.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new A(e).valueOf()}add(e){return new A(this.valueOf()+new A(e).valueOf())}sub(e){return new A(this.valueOf()-new A(e).valueOf())}static nanoseconds(e=1){return new A(e)}static microseconds(e=1){return A.nanoseconds(e*1e3)}static milliseconds(e=1){return A.microseconds(e*1e3)}static seconds(e=1){return A.milliseconds(e*1e3)}static minutes(e){return A.seconds(e.valueOf()*60)}static hours(e){return A.minutes(e*60)}static days(e){return A.hours(e*24)}};m(U,"NANOSECOND",U.nanoseconds(1)),m(U,"MICROSECOND",U.microseconds(1)),m(U,"MILLISECOND",U.milliseconds(1)),m(U,"SECOND",U.seconds(1)),m(U,"MINUTE",U.minutes(1)),m(U,"HOUR",U.hours(1)),m(U,"DAY",U.days(1)),m(U,"MAX",new U((1n<<63n)-1n)),m(U,"MIN",new U(0)),m(U,"ZERO",new U(0)),m(U,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new U(t.value)),s.z.string().transform(t=>new U(BigInt(t))),s.z.instanceof(Number).transform(t=>new U(t)),s.z.number().transform(t=>new U(t)),s.z.instanceof(U)]));let V=U;const ot=class rr extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new rr(e).valueOf()}get period(){return V.seconds(1/this.valueOf())}sampleCount(e){return new V(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new ce(r).valueOf()}span(e){return V.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new rr(e)}static khz(e){return rr.hz(e*1e3)}};m(ot,"z",s.z.union([s.z.number().transform(t=>new ot(t)),s.z.instanceof(Number).transform(t=>new ot(t)),s.z.instanceof(ot)]));let Gc=ot;const X=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Yr(e*this.valueOf())}};m(X,"UNKNOWN",new X(0)),m(X,"BIT128",new X(16)),m(X,"BIT64",new X(8)),m(X,"BIT32",new X(4)),m(X,"BIT16",new X(2)),m(X,"BIT8",new X(1)),m(X,"z",s.z.union([s.z.number().transform(t=>new X(t)),s.z.instanceof(Number).transform(t=>new X(t)),s.z.instanceof(X)]));let ce=X;const ve=class nr{constructor(e,r){m(this,"start"),m(this,"end"),typeof e=="object"&&"start"in e?(this.start=new F(e.start),this.end=new F(e.end)):(this.start=new F(e),this.end=new F(r))}get span(){return new V(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 nr(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=V.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=F.max(n.start,e.start),a=F.min(n.end,e.end);return a.before(i)?!1:new V(a.sub(i)).greaterThanOrEqual(r)}roughlyEquals(e,r){let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=r.valueOf()&&i<=r.valueOf()}contains(e){return e instanceof nr?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new nr(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}};m(ve,"MAX",new ve(F.MIN,F.MAX)),m(ve,"MIN",new ve(F.MAX,F.MIN)),m(ve,"ZERO",new ve(F.ZERO,F.ZERO)),m(ve,"z",s.z.union([s.z.object({start:F.z,end:F.z}).transform(t=>new ve(t.start,t.end)),s.z.instanceof(ve)]));let kt=ve;const y=class Oe extends String{constructor(e){if(e instanceof Oe||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=Oe.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(Oe.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Oe.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(){return this.valueOf()}get isVariable(){return this.equals(Oe.JSON)||this.equals(Oe.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Oe.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Oe.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return Oe.BIG_INT_TYPES.some(e=>e.equals(this))}};m(y,"UNKNOWN",new y("unknown")),m(y,"FLOAT64",new y("float64")),m(y,"FLOAT32",new y("float32")),m(y,"INT64",new y("int64")),m(y,"INT32",new y("int32")),m(y,"INT16",new y("int16")),m(y,"INT8",new y("int8")),m(y,"UINT64",new y("uint64")),m(y,"UINT32",new y("uint32")),m(y,"UINT16",new y("uint16")),m(y,"UINT8",new y("uint8")),m(y,"BOOLEAN",y.UINT8),m(y,"TIMESTAMP",new y("timestamp")),m(y,"UUID",new y("uuid")),m(y,"STRING",new y("string")),m(y,"JSON",new y("json")),m(y,"ARRAY_CONSTRUCTORS",new Map([[y.UINT8.toString(),Uint8Array],[y.UINT16.toString(),Uint16Array],[y.UINT32.toString(),Uint32Array],[y.UINT64.toString(),BigUint64Array],[y.FLOAT32.toString(),Float32Array],[y.FLOAT64.toString(),Float64Array],[y.INT8.toString(),Int8Array],[y.INT16.toString(),Int16Array],[y.INT32.toString(),Int32Array],[y.INT64.toString(),BigInt64Array],[y.TIMESTAMP.toString(),BigInt64Array],[y.STRING.toString(),Uint8Array],[y.JSON.toString(),Uint8Array],[y.UUID.toString(),Uint8Array]])),m(y,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,y.UINT8],[Uint16Array.name,y.UINT16],[Uint32Array.name,y.UINT32],[BigUint64Array.name,y.UINT64],[Float32Array.name,y.FLOAT32],[Float64Array.name,y.FLOAT64],[Int8Array.name,y.INT8],[Int16Array.name,y.INT16],[Int32Array.name,y.INT32],[BigInt64Array.name,y.INT64]])),m(y,"DENSITIES",new Map([[y.UINT8.toString(),ce.BIT8],[y.UINT16.toString(),ce.BIT16],[y.UINT32.toString(),ce.BIT32],[y.UINT64.toString(),ce.BIT64],[y.FLOAT32.toString(),ce.BIT32],[y.FLOAT64.toString(),ce.BIT64],[y.INT8.toString(),ce.BIT8],[y.INT16.toString(),ce.BIT16],[y.INT32.toString(),ce.BIT32],[y.INT64.toString(),ce.BIT64],[y.TIMESTAMP.toString(),ce.BIT64],[y.STRING.toString(),ce.UNKNOWN],[y.JSON.toString(),ce.UNKNOWN],[y.UUID.toString(),ce.BIT128]])),m(y,"ALL",[y.UNKNOWN,y.FLOAT64,y.FLOAT32,y.INT64,y.INT32,y.INT16,y.INT8,y.UINT64,y.UINT32,y.UINT16,y.UINT8,y.TIMESTAMP,y.UUID,y.STRING,y.JSON]),m(y,"BIG_INT_TYPES",[y.INT64,y.UINT64,y.TIMESTAMP]),m(y,"z",s.z.union([s.z.string().transform(t=>new y(t)),s.z.instanceof(y)]));let M=y;const ie=class Z extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return Z.bytes(this.valueOf()+e.valueOf())}sub(e){return Z.bytes(this.valueOf()-e.valueOf())}truncate(e){return new Z(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return Z.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/Z.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/Z.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/Z.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/Z.TERABYTE.valueOf()}toString(){const e=this.truncate(Z.TERABYTE),r=this.truncate(Z.GIGABYTE),n=this.truncate(Z.MEGABYTE),i=this.truncate(Z.KILOBYTE),a=this.truncate(Z.BYTE),o=e,c=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),c.isZero||(h+=`${c.gigabytes}GB `),u.isZero||(h+=`${u.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new Z(e)}static kilobytes(e=1){return Z.bytes(e.valueOf()*1e3)}static megabytes(e=1){return Z.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return Z.megabytes(e.valueOf()*1e3)}static terabytes(e){return Z.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};m(ie,"BYTE",new ie(1)),m(ie,"KILOBYTE",ie.kilobytes(1)),m(ie,"MEGABYTE",ie.megabytes(1)),m(ie,"GIGABYTE",ie.gigabytes(1)),m(ie,"TERABYTE",ie.terabytes(1)),m(ie,"ZERO",new ie(0)),m(ie,"z",s.z.union([s.z.number().transform(t=>new ie(t)),s.z.instanceof(ie)]));let Yr=ie;const Zc=s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]),Fi=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof F||t instanceof V||t instanceof Date},Kc=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r)-BigInt(n):ct(r,-n),Jc=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Wi?!0:Fi(t),Le=-1;let Wi=class Ie{constructor(e){m(this,"key",""),m(this,"isSynnaxSeries",!0),m(this,"dataType"),m(this,"sampleOffset"),m(this,"gl"),m(this,"_data"),m(this,"_timeRange"),m(this,"alignment",0n),m(this,"_cachedMin"),m(this,"_cachedMax"),m(this,"writePos",Le),m(this,"_refCount",0),m(this,"_cachedLength"),Jc(e)&&(e={data:e});const{dataType:r,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=qi()}=e,{data:u}=e;if(u instanceof Ie||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const h=u;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this._timeRange=h._timeRange,this.alignment=h.alignment,this._cachedMin=h._cachedMin,this._cachedMax=h._cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this._cachedLength=h._cachedLength;return}const d=Fi(u),f=Array.isArray(u);if(r!=null)this.dataType=new M(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(f||d){let h=u;if(!d){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=u[0]}if(typeof h=="string")this.dataType=M.STRING;else if(typeof h=="number")this.dataType=M.FLOAT64;else if(typeof h=="bigint")this.dataType=M.INT64;else if(typeof h=="boolean")this.dataType=M.BOOLEAN;else if(h instanceof F||h instanceof Date||h instanceof F)this.dataType=M.TIMESTAMP;else if(typeof h=="object")this.dataType=M.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new M(u)}if(!f&&!d)this._data=u;else{let h=d?[u]:u;const j=h[0];(j instanceof F||j instanceof Date||j instanceof V)&&(h=h.map(W=>new F(W).valueOf())),this.dataType.equals(M.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.join(`
4
- `)+`
5
- `)):this.dataType.equals(M.JSON)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.map(W=>tr.encodeString(W)).join(`
6
- `)+`
7
- `)):this._data=new this.dataType.Array(h).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=n,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new M(r).Array(e),a=new Ie({data:i.buffer,dataType:r,...n});return a.writePos=0,a}static generateTimestamps(e,r,n){const i=n.spanRange(r.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(n.add(r.span(o)).valueOf());return new Ie({data:a,dataType:M.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,r){const n=new TextEncoder().encode(e.join(`
8
- `)+`
9
- `);return new Ie({data:n,dataType:M.STRING,timeRange:r})}static fromJSON(e,r){const n=new TextEncoder().encode(e.map(i=>tr.encodeString(i)).join(`
10
- `)+`
11
- `);return new Ie({data:n,dataType:M.JSON,timeRange:r})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}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(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");if(this.writePos===Le)return 0;const r=this.capacity-this.writePos,n=r<e.length?e.slice(0,r):e;return this.underlyingData.set(n.data,this.writePos),this.maybeRecomputeMinMax(n),this._cachedLength=void 0,this.writePos+=n.length,n.length}get buffer(){return this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Le?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(M.STRING,M.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
12
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(M.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=M.UUID.density.valueOf(),r=Array(this.length);for(let n=0;n<this.length;n++){const i=this.buffer.slice(n*e,(n+1)*e),a=Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");r[n]=a}return r}parseJSON(e){if(!this.dataType.equals(M.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
13
- `).slice(0,-1).map(r=>e.parse(tr.decodeString(r)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Yr(this.buffer.byteLength)}get capacity(){return this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Le?this.byteCapacity:this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Le?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;return this.data.forEach(r=>{r===10&&e++}),this._cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let i=0;i<this.length;i++)n[i]=Kc(this.dataType,e,this.data[i],r);return new Ie({data:n.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(M.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this._cachedMax=e.reduce((r,n)=>r>n?r:n)}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==null&&(this._cachedMax=this.calcRawMax()),ct(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(M.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this._cachedMin=e.reduce((r,n)=>r<n?r:n)}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==null&&(this._cachedMin=this.calcRawMin()),ct(this._cachedMin,this.sampleOffset))}get bounds(){return O.o(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const r=e._cachedMin??e.calcRawMin();r<this._cachedMin&&(this._cachedMin=r)}if(this._cachedMax!=null){const r=e._cachedMax??e.calcRawMax();r>this._cachedMax&&(this._cachedMax=r)}}enrich(){this.max,this.min}get range(){return ct(this.max,-this.min)}at(e,r){if(this.dataType.isVariable)return this.atVariable(e,r??!1);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return ct(n,this.sampleOffset)}atVariable(e,r){e<0&&(e=this.length+e);let n=0,i=0;for(let o=0;o<this.data.length;o++)if(this.data[o]===10){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}const a=this.data.slice(n,i);return this.dataType.equals(M.STRING)?new TextDecoder().decode(a):O.T(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const i=Lr(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(M.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:i}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Le){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Le}as(e){if(e==="string"){if(!this.dataType.equals(M.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(M.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.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 O.o(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.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 e=new Hc(this);return this.dataType.equals(M.JSON)?new Xc(e):e}return new Qc(this)}slice(e,r){if(e<=0&&(r==null||r>=this.length))return this;const n=this.data.slice(e,r);return new Ie({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}reAlign(e){return new Ie({data:this.buffer,dataType:this.dataType,timeRange:kt.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}},Hc=class{constructor(e){if(m(this,"series"),m(this,"index"),m(this,"decoder"),!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,r=this.series.data;for(;this.index<r.length&&r[this.index]!==10;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}[Symbol.iterator](){return this}};var Rs,Ms;let Xc=class{constructor(e){m(this,"wrapped"),m(this,Rs,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:tr.decodeString(e.value)}}[(Ms=Symbol.iterator,Rs=Symbol.toStringTag,Ms)](){return this}};var Ds,Ps;class Qc{constructor(e){m(this,"series"),m(this,"index"),m(this,Ds,"SeriesIterator"),this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[(Ps=Symbol.iterator,Ds=Symbol.toStringTag,Ps)](){return this}}const ct=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);let el=class{constructor(e){if(m(this,"series"),e.length!==0){const r=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(r))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new M(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?M.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?kt.ZERO:new kt(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,r)=>e+r.length,0)}at(e,r=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,r);e-=n.length}if(r)throw new Error(`[series] - no value at index ${e}`)}get byteLength(){return new Yr(this.series.reduce((e,r)=>e+r.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let r=0;for(const n of this.series)e.set(n.data,r),r+=n.length;return new this.dataType.Array(e)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new tl(this.series)}};var Bs,Us;let tl=class{constructor(e){m(this,"series"),m(this,"seriesIndex"),m(this,"internal"),m(this,Bs,"MultiSeriesIterator"),this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[(Us=Symbol.iterator,Bs=Symbol.toStringTag,Us)](){return this}};s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Vi=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",rl=Vi(),Gi=["MacOS","Windows","Linux","Docker"],nl=s.z.enum(Gi);let nn;const sl=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},il=(t={})=>{const{force:e,default:r}=t;return e??nn??(nn=sl(),nn??r)},Zi=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Gi,RUNTIME:rl,detect:Vi,getOS:il,osZ:nl},Symbol.toStringTag,{value:"Module"})),al=t=>Array.isArray(t)?t:[t],ol=t=>Array.isArray(t)?t:t===null?[]:[t],cl=t=>[...new Set(t)];var ll=Object.defineProperty,ul=(t,e,r)=>e in t?ll(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,lt=(t,e,r)=>ul(t,typeof e!="symbol"?e+"":e,r);const hl=(...t)=>t.map(Ki).join(""),Ki=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),dl=t=>t.endsWith("/")?t.slice(0,-1):t,Ls=class Cn{constructor({host:e,port:r,protocol:n="",pathPrefix:i=""}){lt(this,"protocol"),lt(this,"host"),lt(this,"port"),lt(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=Ki(i)}replace(e){return new Cn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Cn({...this,pathPrefix:hl(this.path,e)})}toString(){return dl(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};lt(Ls,"UNKNOWN",new Ls({host:"unknown",port:0}));var fl=Object.defineProperty,yl=(t,e,r)=>e in t?fl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,xr=(t,e,r)=>yl(t,typeof e!="symbol"?e+"":e,r);let gl=class{constructor(e){xr(this,"sender"),xr(this,"handlers"),this.sender=e,this.handlers=new Map}handle({data:e}){var r;const n=(r=this.handlers.get(e.type))==null?void 0:r.handler;n==null?console.warn(`No handler for ${e.type}`):n(e.payload)}route(e){const r=pl(e,this.sender),n=new ml(r);return this.handlers.set(e,n),n}};const pl=(t,e)=>(r,n)=>e({type:t,payload:r},n);let ml=class{constructor(e){xr(this,"_send"),xr(this,"handler"),this._send=e,this.handler=null}send(e,r=[]){this._send(e,r)}handle(e){this.handler=e}};var wl=Object.defineProperty,bl=(t,e,r)=>e in t?wl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,sr=(t,e,r)=>bl(t,typeof e!="symbol"?e+"":e,r);const qe=class extends Number{};sr(qe,"Absolute",255),sr(qe,"Default",1),sr(qe,"z",s.z.union([s.z.instanceof(qe),s.z.number().int().min(0).max(255).transform(t=>new qe(t)),s.z.instanceof(Number).transform(t=>new qe(t))]));let Ji=qe;const Hi=s.z.object({name:s.z.string(),key:s.z.string()}),vl=t=>s.z.object({subject:Hi,resource:t,authority:Ji.z}),Ol=(...t)=>e=>e.filter(r=>{let n=!1;return r.to!=null&&(n=t.includes(r.to.resource)),r.from!=null&&!n&&(n=t.includes(r.from.resource)),n}),Tl=Object.freeze(Object.defineProperty({__proto__:null,Authority:Ji,filterTransfersByChannelKey:Ol,stateZ:vl,subjectZ:Hi},Symbol.toStringTag,{value:"Module"})),Xi=class ut extends Error{constructor(){super(ut.MESSAGE)}matches(e){return typeof e=="string"?e.includes(ut.MESSAGE):e instanceof ut||e.message.includes(ut.MESSAGE)}};sr(Xi,"MESSAGE","canceled");let Sl=Xi;new Sl;const zl=t=>t?-1:1,$n=s.z.string().regex(/^\d+\.\d+\.\d+$/),Dt=(t,e,r={})=>{r.checkMajor??(r.checkMajor=!0),r.checkMinor??(r.checkMinor=!0),r.checkPatch??(r.checkPatch=!0);const n=$n.parse(t),i=$n.parse(e),[a,o,c]=n.split(".").map(Number),[u,d,f]=i.split(".").map(Number);if(r.checkMajor){if(a<u)return tn;if(a>u)return rn}if(r.checkMinor){if(o<d)return tn;if(o>d)return rn}if(r.checkPatch){if(c<f)return tn;if(c>f)return rn}return Ic},Nl=(t,e,r={})=>Bi(Dt(t,e,r)),Qi=(t,e,r={})=>Pi(Dt(t,e,r)),El=(t,e,r={})=>Di(Dt(t,e,r)),Il=({name:t,migrate:e})=>r=>{try{const n=e(r);return console.log(`${t} migrated: ${r.version} -> ${n.version}`),n}catch(n){throw console.log(`${t} failed to migrate from ${r.version}`),console.error(n),n}},kl=({name:t,migrations:e,targetSchema:r,def:n})=>{const i=Object.keys(e).sort(Dt).pop();if(i==null)return u=>{if(u.version!==n.version)return console.log(`${t} version ${u.version} is newer than latest version of ${n.version}.
14
- Returning default instead.
15
- `),n;try{return r!=null?r.parse(u):u}catch(d){return console.log(`${t} failed to parse default. Exiting with default`),console.error(d),n}};const a=Object.keys(e).length;let o=!1;const c=u=>{try{if(a===0||Qi(u.version,i))return console.log(o?`${t} ${u.version} now up to date`:`${t} version ${u.version} is up to date with target version ${n.version}`),u;const d=u.version,f=e[d],h=f(u);return o=!0,c(h)}catch(d){return console.log(`${t} failed to migrate from ${u.version} to ${i}`),console.error(d),n}};return u=>{try{return c(u)}catch(d){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(d),n}}},Al=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:Dt,createMigration:Il,migrator:kl,semVerNewer:Qi,semVerOlder:El,semVerZ:$n,versionsEqual:Nl},Symbol.toStringTag,{value:"Module"})),xl=t=>{if(t===void 0||typeof t=="string"||typeof t=="number")return t;if(t.toString===void 0)throw new Error("invalid renderer");return t.toString()},Cl=t=>Array.isArray(t)?[...t]:typeof t=="object"&&t!==null?{...t}:t,ts=t=>typeof t=="function",rs=(t,e)=>ts(t)?t(e):t,Pt=t=>ea(t)?t():t,ea=t=>typeof t=="function",ta=({initial:t,value:e,onChange:r})=>{const[n,i]=Qn.useState(Pt(e??t));return e!=null&&r!=null?[e,r]:[n,i]},ra=({initial:t,value:e,onChange:r})=>{const[n,i]=Qn.useState(Pt(e??t));return e!=null&&r!=null?[e,r]:[n,i]},$l=(t,e)=>{const[r,n]=Qn.useState(()=>{const i=localStorage.getItem(e);return i==null?Pt(t):JSON.parse(i)});return[r,i=>{n(i),localStorage.setItem(e,JSON.stringify(i))}]},jl=Object.freeze(Object.defineProperty({__proto__:null,executeInitialSetter:Pt,executeSetter:rs,isInitialSetter:ea,isSetter:ts,usePassthrough:ta,usePersisted:$l,usePurePassthrough:ra},Symbol.toStringTag,{value:"Module"})),na=["h1","h2","h3","h4","h5","p","small"],Rl=s.z.enum(na),Me=s.z.object({size:s.z.number(),weight:s.z.union([s.z.number(),s.z.string()]),lineHeight:s.z.number(),textTransform:s.z.string().optional()}),sa={small:"small",medium:"p",large:"h5",huge:"h2"},Ml={h1:"huge",h2:"huge",h3:"huge",h4:"large",h5:"small",p:"medium",small:"small"};let sn=null;const Dl=()=>(sn==null&&(sn=document.createElement("canvas")),sn),Pl=(t,e,r)=>{if(Zi.RUNTIME==="node")return{width:0,height:0};r==null&&(r=Dl().getContext("2d")),r.font=e;const n=r.measureText(t);return{width:Math.trunc(Math.abs(n.actualBoundingBoxLeft)+Math.abs(n.actualBoundingBoxRight)),height:Math.trunc(Math.abs(n.actualBoundingBoxAscent)+Math.abs(n.actualBoundingBoxDescent))}},Bl=s.z.object({l0:O.Color.z,l1:O.Color.z,l2:O.Color.z,l3:O.Color.z,l4:O.Color.z,l5:O.Color.z,l6:O.Color.z,l7:O.Color.z,l8:O.Color.z,l9:O.Color.z,l10:O.Color.z}),ge=(t,e)=>[t[0],t[1],e,t[3]],Ul=s.z.object({m2:O.Color.z,m1:O.Color.z,z:O.Color.z,p1:O.Color.z,p2:O.Color.z}),Wt=Ul.or(O.Color.z.transform(t=>{const e=t.hsla;return{m2:new O.Color(O.fromHSLA(ge(e,40))),m1:new O.Color(O.fromHSLA(ge(e,45))),z:t,p1:new O.Color(O.fromHSLA(ge(e,55))),p2:new O.Color(O.fromHSLA(ge(e,65)))}})),ia=s.z.object({name:s.z.string(),key:s.z.string(),colors:s.z.object({border:O.Color.z,primary:Wt,gray:Bl,error:Wt,secondary:Wt,warning:Wt,visualization:s.z.object({palettes:s.z.record(s.z.array(O.Color.z))}).optional().default({palettes:{}}),white:O.Color.z,black:O.Color.z,text:O.Color.z,textInverted:O.Color.z,textOnPrimary:O.Color.z.optional().default(O.ZERO),logo:s.z.string()}),sizes:s.z.object({base:s.z.number(),border:s.z.object({radius:s.z.number(),width:s.z.number()}),schematic:s.z.object({elementStrokeWidth:s.z.number()})}),typography:s.z.object({family:s.z.string(),h1:Me,h2:Me,h3:Me,h4:Me,h5:Me,p:Me,small:Me})}).transform(t=>((t.colors.textOnPrimary==null||t.colors.textOnPrimary.isZero)&&(t.colors.textOnPrimary=t.colors.primary.z.pickByContrast(t.colors.text,t.colors.textInverted)),t)),Ll="'Inter Variable', sans-serif",Yl=6,nt=[357,91,55,1],st=[58,100,50,1],ql=["#FCFCFC","#F9F9F9","#F4F4F4","#ededed","#d9d9d9","#ADADAD","#878787","#616161","#404040","#1C1C1C","#050505"],Vt=Object.fromEntries(ql.map((t,e)=>[`l${e}`,t])),jn={key:"synnaxBase",name:"Synnax Base",colors:{primary:{m2:"#041B3D",m1:"#164FA0",z:"#3774D0",p1:"#5E94EE",p2:"#8AB8FF"},secondary:{m2:"#2D8F4E",m1:"#38B261",z:"#50C878",p1:"#73D393",p2:"#96DEAE"},gray:Vt,border:Vt.l3,error:{m2:O.fromHSLA(ge(nt,30)),m1:O.fromHSLA(ge(nt,40)),z:O.fromHSLA(nt),p1:O.fromHSLA(ge(nt,65)),p2:O.fromHSLA(ge(nt,77))},warning:{m2:O.fromHSLA(ge(st,30)),m1:O.fromHSLA(ge(st,40)),z:O.fromHSLA(st),p1:O.fromHSLA(ge(st,65)),p2:O.fromHSLA(ge(st,75))},visualization:{palettes:{default:["#DC136C","#20A4F3","#7AC74F","#FFC43D","#FE5F55","#8075FF","#D90429","#f7aef8","#f18f01","#791e94","#279af1","#d9fff5","#ff6b6b","#52ffb8"]}},logo:"url(#synnax-linear-gradient)",white:"#FFFFFF",black:"#000000",text:Vt.l9,textInverted:Vt.l0},sizes:{base:Yl,border:{radius:3,width:1},schematic:{elementStrokeWidth:2}},typography:{family:Ll,h1:{size:7,weight:"500",lineHeight:7*1.5},h2:{size:4.5,weight:"medium",lineHeight:4.5*1.5},h3:{size:3.5,weight:"medium",lineHeight:3.5*1.5},h4:{size:2.6666,weight:"medium",lineHeight:2.6666*1.5},h5:{size:2.333333,weight:450,lineHeight:2.333333*1.5},p:{size:2.1666666666,weight:"regular",lineHeight:2*1.5},small:{size:1.916666,weight:"regular",lineHeight:1.9166666*1.5}}},aa=Object.freeze({...jn,key:"synnaxLight",name:"Synnax Light"}),_l=["#020202","#060606","#0D0D0D","#191919","#242424","#434343","#646464","#8A8A8A","#AFAFAF","#D5D5D5","#FDFDFD"],Gt=Object.fromEntries(_l.map((t,e)=>[`l${e}`,t])),oa=Object.freeze({...jn,key:"synnaxDark",name:"Synnax Dark",colors:{...jn.colors,gray:Gt,logo:"var(--pluto-text-color)",border:Gt.l3,text:Gt.l9,textInverted:Gt.l0}}),Fl={synnaxDark:oa,synnaxLight:aa},Wl=["small","medium","large","huge"],Vl=s.z.enum(Wl),Gl=t=>Vl.safeParse(t).success,Zl=(t,e,r)=>{const{typography:n,sizes:{base:i}}=t,a=n[Gl(e)?sa[e]:e].size,o=i*a,[c,u]=n.family.split(", ");return r!=null?` ${r} ${o}px ${c}, ${u}`:` ${o}px ${n.family}`};var Kl=Object.defineProperty,Jl=(t,e,r)=>e in t?Kl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,l=(t,e,r)=>Jl(t,typeof e!="symbol"?e+"":e,r),Hl=Object.defineProperty,Xl=(t,e,r)=>e in t?Hl(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,D=(t,e,r)=>Xl(t,typeof e!="symbol"?e+"":e,r);const Ql=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()?e:e[0].toLowerCase()+e.slice(1)},ca=t=>{const e=(r,n=Rn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!an(r))return r;n=nu(n);const i={},a=r;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);n.recursive&&(an(c)?qs(c,n.keepTypesOnRecursion)||(c=e(c,n)):n.recursiveInArray&&Ys(c)&&(c=[...c].map(d=>{let f=d;return an(d)?qs(f,n.keepTypesOnRecursion)||(f=e(d,n)):Ys(d)&&(f=e({key:d},n).key),f}))),i[u]=c}),i};return e},eu=ca(Ql),tu=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),ru=ca(tu),Rn={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},nu=(t=Rn)=>(t.recursive==null?t=Rn:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),Ys=t=>t!=null&&Array.isArray(t),an=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),qs=(t,e)=>(e||[]).some(r=>t instanceof r),la=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var su=Object.defineProperty,iu=(t,e,r)=>e in t?su(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,St=(t,e,r)=>iu(t,typeof e!="symbol"?e+"":e,r);let au=class{constructor(){St(this,"contentType","application/json"),St(this,"decoder"),St(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(t){return this.encoder.encode(this.encodeString(t)).buffer}decode(t,e){return this.decodeString(this.decoder.decode(t),e)}decodeString(t,e){const r=JSON.parse(t),n=eu(r);return e!=null?e.parse(n):n}encodeString(t){const e=ru(t);return JSON.stringify(e,(r,n)=>ArrayBuffer.isView(n)?Array.from(n):la(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},ou=class{constructor(){St(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const r=new TextDecoder().decode(t);return this.decodeString(r,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!la(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),r=[e.join(",")];return t.forEach(n=>{const i=e.map(a=>JSON.stringify(n[a]??""));r.push(i.join(","))}),r.join(`
16
- `)}decodeString(t,e){const[r,...n]=t.trim().split(`
17
- `).map(o=>o.trim());if(r.length===0)return e!=null?e.parse({}):{};const i=r.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),n.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,d)=>{const f=this.parseValue(c[d]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},cu=class{constructor(){St(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const r=new TextDecoder().decode(t);return e!=null?e.parse(r):r}};new au;new ou;new cu;const qr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const ua=s.z.object({width:s.z.number(),height:s.z.number()}),lu=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),uu=["width","height"];s.z.enum(uu);const hu=["start","center","end"],du=["signedWidth","signedHeight"];s.z.enum(du);const Cr=s.z.object({x:s.z.number(),y:s.z.number()}),fu=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),yu=["x","y"],ha=s.z.enum(yu),da=["top","right","bottom","left"];s.z.enum(da);const gu=["left","right"],fa=s.z.enum(gu),pu=["top","bottom"],ya=s.z.enum(pu),ga=["center"],_s=s.z.enum(ga),mu=[...da,...ga],pa=s.z.enum(mu);s.z.enum(hu);const wu=["first","last"];s.z.enum(wu);const bu=s.z.object({lower:s.z.number(),upper:s.z.number()}),vu=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([bu,qr]);s.z.union([vu,qr]);s.z.union([ha,pa]);s.z.union([ha,pa,s.z.instanceof(String)]);const on=(t,e)=>{const r={};if(typeof t=="number"||typeof t=="bigint")e!=null?(r.lower=t,r.upper=e):(r.lower=typeof t=="bigint"?0n:0,r.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=t}else return Fs(t);return Fs(r)},Fs=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;s.z.object({x:fa.or(_s),y:ya.or(_s)});const Ou=s.z.object({x:fa,y:ya}),Tu=Object.freeze({x:"left",y:"top"}),Su=(t,e)=>t.x===e.x&&t.y===e.y,Ws=s.z.union([s.z.number(),Cr,qr,ua,lu,fu]),zu=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},Vs=Object.freeze({x:0,y:0}),Zt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Zt,left:Zt,width:Zt,height:Zt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:Cr,two:Cr,root:Ou});const ns=(t,e,r=0,n=0,i)=>{const a={one:{...Vs},two:{...Vs},root:i??Tu};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},cn=t=>{const e=ns(t);return{lower:e.one.x,upper:e.two.x}},ln=t=>{const e=ns(t);return{lower:e.one.y,upper:e.two.y}},Nu=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t;var Eu=Object.defineProperty,Iu=(t,e,r)=>e in t?Eu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,Ce=(t,e,r)=>Iu(t,typeof e!="symbol"?e+"":e,r);const ku=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;s.z.object({offset:Ws,scale:Ws});const Au=t=>(e,r,n,i)=>r==="dimension"?[e,n]:[e,i?n-t:n+t],xu=t=>(e,r,n,i)=>[e,i?n/t:n*t],Cu=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,d=c-o;if(r==="dimension")return[t,n*(d/u)];const f=(n-i)*(d/u)+o;return[t,f]},$u=t=>(e,r,n)=>[t,n],ju=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:i}=t;return[t,i-(r-n)]},Ru=t=>(e,r,n)=>{const{lower:i,upper:a}=t;return n=ku(n,i,a),[e,n]},Mn=class ht{constructor(){Ce(this,"ops",[]),Ce(this,"currBounds",null),Ce(this,"currType",null),Ce(this,"reversed",!1),this.ops=[]}static translate(e){return new ht().translate(e)}static magnify(e){return new ht().magnify(e)}static scale(e,r){return new ht().scale(e,r)}translate(e){const r=this.new(),n=Au(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=xu(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=on(e,r),i=this.new(),a=Cu(n);return a.type="scale",i.ops.push(a),i}clamp(e,r){const n=on(e,r),i=this.new(),a=Ru(n);return a.type="clamp",i.ops.push(a),i}reBound(e,r){const n=on(e,r),i=this.new(),a=$u(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=ju();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new ht;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||r.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&r.push([i,a])}),r.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}};Ce(Mn,"IDENTITY",new Mn);let Gs=Mn;const Zs=class ke{constructor(e=new Gs,r=new Gs,n=null){Ce(this,"x"),Ce(this,"y"),Ce(this,"currRoot"),this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new ke().translate(e,r)}static translateX(e){return new ke().translateX(e)}static translateY(e){return new ke().translateY(e)}static clamp(e){return new ke().clamp(e)}static magnify(e){return new ke().magnify(e)}static scale(e){return new ke().scale(e)}static reBound(e){return new ke().reBound(e)}translate(e,r){const n=zu(e,r),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(Nu(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!Su(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(cn(e)),r.y=r.y.scale(ln(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(cn(e)),r.y=this.y.reBound(ln(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(cn(e)),r.y=this.y.clamp(ln(e)),r}copy(){const e=new ke;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}box(e){return ns(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};Ce(Zs,"IDENTITY",new Zs);const Mu=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([ua,Mu,Cr,qr]);var Du=Object.defineProperty,Pu=(t,e,r)=>e in t?Du(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,b=(t,e,r)=>Pu(t,typeof e!="symbol"?e+"":e,r);const ma=(t,e)=>{const r=new te(e);if(![re.DAY,re.HOUR,re.MINUTE,re.SECOND,re.MILLISECOND,re.MICROSECOND,re.NANOSECOND].some(i=>i.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof te?new te(n):new re(n)},L=class S{constructor(e,r="UTC"){if(b(this,"value"),b(this,"encodeValue",!0),e==null)this.value=S.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*S.MILLISECOND.valueOf();else if(typeof e=="string")this.value=S.parseDateTimeString(e,r).valueOf();else if(Array.isArray(e))this.value=S.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=S.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=S.MAX:e=S.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,r=1,n=1]){const i=new Date(e,r-1,n,0,0,0,0);return new S(BigInt(i.getTime())*S.MILLISECOND.valueOf()).truncate(S.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=S.hours(parseInt(n??"00",10)).add(S.minutes(parseInt(i??"00",10))).add(S.seconds(parseInt(o??"00",10))).add(S.milliseconds(parseInt(c??"00",10)));return r==="local"&&(u=u.add(S.utcOffset)),u.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return S.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new S(BigInt(n.getTime())*S.MILLISECOND.valueOf(),r).valueOf()}fString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(S.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new re(BigInt(new Date().getTimezoneOffset())*S.MINUTE.valueOf())}static since(e){return new S().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new S(e).valueOf()}span(e){return this.range(e).span}range(e){return new Bu(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new S(e).valueOf()}afterEq(e){return this.valueOf()>=new S(e).valueOf()}before(e){return this.valueOf()<new S(e).valueOf()}beforeEq(e){return this.valueOf()<=new S(e).valueOf()}add(e){return new S(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new S(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(S.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return ma(this,e)}get isToday(){return this.truncate(re.DAY).equals(S.now().truncate(re.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new S(new Date)}static max(...e){let r=S.MIN;for(const n of e){const i=new S(n);i.after(r)&&(r=i)}return r}static min(...e){let r=S.MAX;for(const n of e){const i=new S(n);i.before(r)&&(r=i)}return r}static nanoseconds(e){return new S(e)}static microseconds(e){return S.nanoseconds(e*1e3)}static milliseconds(e){return S.microseconds(e*1e3)}static seconds(e){return S.milliseconds(e*1e3)}static minutes(e){return S.seconds(e*60)}static hours(e){return S.minutes(e*60)}static days(e){return S.hours(e*24)}};b(L,"NANOSECOND",L.nanoseconds(1)),b(L,"MICROSECOND",L.microseconds(1)),b(L,"MILLISECOND",L.milliseconds(1)),b(L,"SECOND",L.seconds(1)),b(L,"MINUTE",L.minutes(1)),b(L,"HOUR",L.hours(1)),b(L,"DAY",L.days(1)),b(L,"MAX",new L((1n<<63n)-1n)),b(L,"MIN",new L(0)),b(L,"ZERO",new L(0)),b(L,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new L(t.value)),s.z.string().transform(t=>new L(BigInt(t))),s.z.instanceof(Number).transform(t=>new L(t)),s.z.number().transform(t=>new L(t)),s.z.instanceof(L)]));let te=L;const Y=class x{constructor(e){b(this,"value"),b(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new x(e).valueOf()}greaterThan(e){return this.valueOf()>new x(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new x(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new x(e).valueOf()}remainder(e){return ma(this,e)}truncate(e){return new x(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(x.DAY),r=this.truncate(x.HOUR),n=this.truncate(x.MINUTE),i=this.truncate(x.SECOND),a=this.truncate(x.MILLISECOND),o=this.truncate(x.MICROSECOND),c=this.truncate(x.NANOSECOND),u=e,d=r.sub(e),f=n.sub(r),h=i.sub(n),j=a.sub(i),W=o.sub(a),se=c.sub(o);let R="";return u.isZero||(R+=`${u.days}d `),d.isZero||(R+=`${d.hours}h `),f.isZero||(R+=`${f.minutes}m `),h.isZero||(R+=`${h.seconds}s `),j.isZero||(R+=`${j.milliseconds}ms `),W.isZero||(R+=`${W.microseconds}µs `),se.isZero||(R+=`${se.nanoseconds}ns`),R.trim()}get days(){return Number(this.valueOf())/Number(x.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(x.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(x.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(x.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(x.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(x.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new x(e).valueOf()}add(e){return new x(this.valueOf()+new x(e).valueOf())}sub(e){return new x(this.valueOf()-new x(e).valueOf())}static nanoseconds(e=1){return new x(e)}static microseconds(e=1){return x.nanoseconds(e*1e3)}static milliseconds(e=1){return x.microseconds(e*1e3)}static seconds(e=1){return x.milliseconds(e*1e3)}static minutes(e){return x.seconds(e.valueOf()*60)}static hours(e){return x.minutes(e*60)}static days(e){return x.hours(e*24)}};b(Y,"NANOSECOND",Y.nanoseconds(1)),b(Y,"MICROSECOND",Y.microseconds(1)),b(Y,"MILLISECOND",Y.milliseconds(1)),b(Y,"SECOND",Y.seconds(1)),b(Y,"MINUTE",Y.minutes(1)),b(Y,"HOUR",Y.hours(1)),b(Y,"DAY",Y.days(1)),b(Y,"MAX",new Y((1n<<63n)-1n)),b(Y,"MIN",new Y(0)),b(Y,"ZERO",new Y(0)),b(Y,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new Y(t.value)),s.z.string().transform(t=>new Y(BigInt(t))),s.z.instanceof(Number).transform(t=>new Y(t)),s.z.number().transform(t=>new Y(t)),s.z.instanceof(Y)]));let re=Y;const Kt=class ir extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ir(e).valueOf()}get period(){return re.seconds(1/this.valueOf())}sampleCount(e){return new re(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new le(r).valueOf()}span(e){return re.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new ir(e)}static khz(e){return ir.hz(e*1e3)}};b(Kt,"z",s.z.union([s.z.number().transform(t=>new Kt(t)),s.z.instanceof(Number).transform(t=>new Kt(t)),s.z.instanceof(Kt)]));const Q=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Uu(e*this.valueOf())}};b(Q,"UNKNOWN",new Q(0)),b(Q,"BIT128",new Q(16)),b(Q,"BIT64",new Q(8)),b(Q,"BIT32",new Q(4)),b(Q,"BIT16",new Q(2)),b(Q,"BIT8",new Q(1)),b(Q,"z",s.z.union([s.z.number().transform(t=>new Q(t)),s.z.instanceof(Number).transform(t=>new Q(t)),s.z.instanceof(Q)]));let le=Q;const Te=class ar{constructor(e,r){b(this,"start"),b(this,"end"),typeof e=="object"&&"start"in e?(this.start=new te(e.start),this.end=new te(e.end)):(this.start=new te(e),this.end=new te(r))}get span(){return new re(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 ar(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=re.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=te.max(n.start,e.start),a=te.min(n.end,e.end);return a.before(i)?!1:new re(a.sub(i)).greaterThanOrEqual(r)}roughlyEquals(e,r){let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=r.valueOf()&&i<=r.valueOf()}contains(e){return e instanceof ar?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new ar(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}};b(Te,"MAX",new Te(te.MIN,te.MAX)),b(Te,"MIN",new Te(te.MAX,te.MIN)),b(Te,"ZERO",new Te(te.ZERO,te.ZERO)),b(Te,"z",s.z.union([s.z.object({start:te.z,end:te.z}).transform(t=>new Te(t.start,t.end)),s.z.instanceof(Te)]));let Bu=Te;const p=class Se extends String{constructor(e){if(e instanceof Se||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=Se.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(Se.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Se.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(){return this.valueOf()}get isVariable(){return this.equals(Se.JSON)||this.equals(Se.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Se.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Se.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return Se.BIG_INT_TYPES.some(e=>e.equals(this))}};b(p,"UNKNOWN",new p("unknown")),b(p,"FLOAT64",new p("float64")),b(p,"FLOAT32",new p("float32")),b(p,"INT64",new p("int64")),b(p,"INT32",new p("int32")),b(p,"INT16",new p("int16")),b(p,"INT8",new p("int8")),b(p,"UINT64",new p("uint64")),b(p,"UINT32",new p("uint32")),b(p,"UINT16",new p("uint16")),b(p,"UINT8",new p("uint8")),b(p,"BOOLEAN",p.UINT8),b(p,"TIMESTAMP",new p("timestamp")),b(p,"UUID",new p("uuid")),b(p,"STRING",new p("string")),b(p,"JSON",new p("json")),b(p,"ARRAY_CONSTRUCTORS",new Map([[p.UINT8.toString(),Uint8Array],[p.UINT16.toString(),Uint16Array],[p.UINT32.toString(),Uint32Array],[p.UINT64.toString(),BigUint64Array],[p.FLOAT32.toString(),Float32Array],[p.FLOAT64.toString(),Float64Array],[p.INT8.toString(),Int8Array],[p.INT16.toString(),Int16Array],[p.INT32.toString(),Int32Array],[p.INT64.toString(),BigInt64Array],[p.TIMESTAMP.toString(),BigInt64Array],[p.STRING.toString(),Uint8Array],[p.JSON.toString(),Uint8Array],[p.UUID.toString(),Uint8Array]])),b(p,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,p.UINT8],[Uint16Array.name,p.UINT16],[Uint32Array.name,p.UINT32],[BigUint64Array.name,p.UINT64],[Float32Array.name,p.FLOAT32],[Float64Array.name,p.FLOAT64],[Int8Array.name,p.INT8],[Int16Array.name,p.INT16],[Int32Array.name,p.INT32],[BigInt64Array.name,p.INT64]])),b(p,"DENSITIES",new Map([[p.UINT8.toString(),le.BIT8],[p.UINT16.toString(),le.BIT16],[p.UINT32.toString(),le.BIT32],[p.UINT64.toString(),le.BIT64],[p.FLOAT32.toString(),le.BIT32],[p.FLOAT64.toString(),le.BIT64],[p.INT8.toString(),le.BIT8],[p.INT16.toString(),le.BIT16],[p.INT32.toString(),le.BIT32],[p.INT64.toString(),le.BIT64],[p.TIMESTAMP.toString(),le.BIT64],[p.STRING.toString(),le.UNKNOWN],[p.JSON.toString(),le.UNKNOWN],[p.UUID.toString(),le.BIT128]])),b(p,"ALL",[p.UNKNOWN,p.FLOAT64,p.FLOAT32,p.INT64,p.INT32,p.INT16,p.INT8,p.UINT64,p.UINT32,p.UINT16,p.UINT8,p.TIMESTAMP,p.UUID,p.STRING,p.JSON]),b(p,"BIG_INT_TYPES",[p.INT64,p.UINT64,p.TIMESTAMP]),b(p,"z",s.z.union([s.z.string().transform(t=>new p(t)),s.z.instanceof(p)]));const ae=class K extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return K.bytes(this.valueOf()+e.valueOf())}sub(e){return K.bytes(this.valueOf()-e.valueOf())}truncate(e){return new K(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return K.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/K.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/K.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/K.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/K.TERABYTE.valueOf()}toString(){const e=this.truncate(K.TERABYTE),r=this.truncate(K.GIGABYTE),n=this.truncate(K.MEGABYTE),i=this.truncate(K.KILOBYTE),a=this.truncate(K.BYTE),o=e,c=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),c.isZero||(h+=`${c.gigabytes}GB `),u.isZero||(h+=`${u.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new K(e)}static kilobytes(e=1){return K.bytes(e.valueOf()*1e3)}static megabytes(e=1){return K.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return K.megabytes(e.valueOf()*1e3)}static terabytes(e){return K.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};b(ae,"BYTE",new ae(1)),b(ae,"KILOBYTE",ae.kilobytes(1)),b(ae,"MEGABYTE",ae.megabytes(1)),b(ae,"GIGABYTE",ae.gigabytes(1)),b(ae,"TERABYTE",ae.terabytes(1)),b(ae,"ZERO",new ae(0)),b(ae,"z",s.z.union([s.z.number().transform(t=>new ae(t)),s.z.instanceof(ae)]));let Uu=ae;s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const wa=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Lu=wa(),ba=["MacOS","Windows","Linux","Docker"],Yu=s.z.enum(ba);let un;const qu=()=>{if(typeof window>"u")return;const t=window.navigator.userAgent.toLowerCase();if(t.includes("mac"))return"MacOS";if(t.includes("win"))return"Windows";if(t.includes("linux"))return"Linux"},_u=(t={})=>{const{force:e,default:r}=t;return e??un??(un=qu(),un??r)},va=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:ba,RUNTIME:Lu,detect:wa,getOS:_u,osZ:Yu},Symbol.toStringTag,{value:"Module"}));var Fu=Object.defineProperty,Wu=(t,e,r)=>e in t?Fu(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,dt=(t,e,r)=>Wu(t,typeof e!="symbol"?e+"":e,r);const Vu=(...t)=>t.map(Oa).join(""),Oa=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Gu=t=>t.endsWith("/")?t.slice(0,-1):t,Zu=(t,e="")=>t===null?"":"?"+Object.entries(t).filter(([,r])=>r==null?!1:Array.isArray(r)?r.length>0:!0).map(([r,n])=>`${e}${r}=${n}`).join("&"),Dn=class Pn{constructor({host:e,port:r,protocol:n="",pathPrefix:i=""}){dt(this,"protocol"),dt(this,"host"),dt(this,"port"),dt(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=Oa(i)}replace(e){return new Pn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Pn({...this,pathPrefix:Vu(this.path,e)})}toString(){return Gu(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};dt(Dn,"UNKNOWN",new Dn({host:"unknown",port:0}));let Ku=Dn;var Ju=Object.defineProperty,Hu=(t,e,r)=>e in t?Ju(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,or=(t,e,r)=>Hu(t,typeof e!="symbol"?e+"":e,r);const Ze=class extends Number{};or(Ze,"Absolute",255),or(Ze,"Default",1),or(Ze,"z",s.z.union([s.z.instanceof(Ze),s.z.number().int().min(0).max(255).transform(t=>new Ze(t)),s.z.instanceof(Number).transform(t=>new Ze(t))]));s.z.object({name:s.z.string(),key:s.z.string()});const Ta=class ft extends Error{constructor(){super(ft.MESSAGE)}matches(e){return typeof e=="string"?e.includes(ft.MESSAGE):e instanceof ft||e.message.includes(ft.MESSAGE)}};or(Ta,"MESSAGE","canceled");let Xu=Ta;new Xu;s.z.string().regex(/^\d+\.\d+\.\d+$/);const he=t=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(t):e instanceof Error?e.message.includes(t):typeof e!="string"?!1:e.includes(t);let be=class extends Error{constructor(e){super(e),D(this,"discriminator","FreighterError"),D(this,"type","")}};const Qu=t=>{if(t==null||typeof t!="object")return!1;const e=t;if(e.discriminator!=="FreighterError")return!1;if(!("type"in e))throw new Error(`Freighter error is missing its type property: ${JSON.stringify(e)}`);return!0},Ks="unknown",Js="nil",eh="freighter",Bt=s.z.object({type:s.z.string(),data:s.z.string()});class th{constructor(){D(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Js,data:""};if(Qu(e))for(const r of this.providers){const n=r.encode(e);if(n!=null)return n}return{type:Ks,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Js)return null;if(e.type===Ks)return new Hs(e.data);for(const r of this.providers){const n=r.decode(e);if(n!=null)return n}return new Hs(e.data)}}const Sa=new th,za=({encode:t,decode:e})=>Sa.register({encode:t,decode:e}),ss=t=>Sa.decode(t);class Hs extends be{constructor(e){super(e),D(this,"type","unknown")}}const _r="freighter.",cr=class Na extends be{constructor(){super("EOF"),D(this,"type",Na.TYPE)}};D(cr,"TYPE",_r+"eof"),D(cr,"matches",he(cr.TYPE));let De=cr;const lr=class Ea extends be{constructor(){super("StreamClosed"),D(this,"type",Ea.TYPE)}};D(lr,"TYPE",_r+"stream_closed"),D(lr,"matches",he(lr.TYPE));let Xe=lr;const ur=class Ia extends be{constructor(e={}){const{message:r="Unreachable",url:n=Ku.UNKNOWN}=e;super(r),D(this,"type",Ia.TYPE),D(this,"url"),this.url=n}};D(ur,"TYPE",_r+"unreachable"),D(ur,"matches",he(ur.TYPE));let We=ur;const rh=t=>{if(!t.type.startsWith(eh))return null;if(De.matches(t))return{type:De.TYPE,data:"EOF"};if(Xe.matches(t))return{type:Xe.TYPE,data:"StreamClosed"};if(We.matches(t))return{type:We.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${t.type}: ${t.message}`)},nh=t=>{if(!t.type.startsWith(_r))return null;switch(t.type){case De.TYPE:return new De;case Xe.TYPE:return new Xe;case We.TYPE:return new We;default:throw new Error(`Unknown error type: ${t.data}`)}};za({encode:rh,decode:nh});class ka{constructor(){D(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,r){let n=0;const i=async a=>{if(n===this.middleware.length)return await r(a);const o=this.middleware[n];return n++,await o(a,i)};return await i(e)}}const Aa="Content-Type",Xs=t=>{if(va.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(t==="http")return e;const r=require("https"),n=new r.Agent({rejectUnauthorized:!1});return async(i,a)=>await e(i,{...a,agent:n})};class sh extends ka{constructor(e,r,n=!1){return super(),D(this,"endpoint"),D(this,"encoder"),D(this,"fetch"),this.endpoint=e.replace({protocol:n?"https":"http"}),this.encoder=r,this.fetch=Xs(this.endpoint.protocol),new Proxy(this,{get:(i,a,o)=>a==="endpoint"?this.endpoint:Reflect.get(i,a,o)})}get headers(){return{[Aa]:this.encoder.contentType}}async send(e,r,n,i){r=n==null?void 0:n.parse(r);let a=null;const o=this.endpoint.child(e),c={};c.method="POST",c.body=this.encoder.encode(r??{});const[,u]=await this.executeMiddleware({target:o.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async d=>{const f={...d,params:{}};c.headers={...this.headers,...d.params};let h;try{h=await Xs(d.protocol)(d.target,c)}catch(W){let se=W;return se.message==="Load failed"&&(se=new We({url:o})),[f,se]}const j=await h.arrayBuffer();if(h!=null&&h.ok)return i!=null&&(a=this.encoder.decode(j,i)),[f,null];try{if(h.status!==400)return[f,new Error(h.statusText)];const W=this.encoder.decode(j,Bt),se=ss(W);return[f,se]}catch(W){return[f,new Error(`[freighter] - failed to decode error: ${h.statusText}: ${W.message}`)]}});return[a,u]}}const v=async(t,e,r,n,i)=>{const[a,o]=await t.send(e,r,n,i);if(o!=null)throw o;return a},ih=()=>va.RUNTIME!=="node"?t=>new WebSocket(t):t=>new(require("ws")).WebSocket(t,{rejectUnauthorized:!1}),ah=s.z.object({type:s.z.union([s.z.literal("data"),s.z.literal("close")]),payload:s.z.unknown().optional(),error:s.z.optional(Bt)});class oh{constructor(e,r,n,i){D(this,"encoder"),D(this,"reqSchema"),D(this,"resSchema"),D(this,"ws"),D(this,"serverClosed"),D(this,"sendClosed"),D(this,"receiveDataQueue",[]),D(this,"receiveCallbacksQueue",[]),this.encoder=r,this.reqSchema=n,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new De;if(this.sendClosed)throw new Xe;return this.ws.send(this.encoder.encode({type:"data",payload:e})),null}async receive(){if(this.serverClosed!=null)return[null,this.serverClosed];const e=await this.receiveMsg();if(e.type==="close"){if(e.error==null)throw new Error("Message error must be defined");return this.serverClosed=ss(e.error),[null,this.serverClosed]}return[this.resSchema.parse(e.payload),null]}received(){return this.receiveDataQueue.length!==0}closeSend(){if(this.sendClosed||this.serverClosed!=null)return;const e={type:"close"};try{this.ws.send(this.encoder.encode(e))}finally{this.sendClosed=!0}}async receiveMsg(){return this.receiveDataQueue.shift()??await new Promise((e,r)=>this.receiveCallbacksQueue.push({resolve:e,reject:r}))}addMessage(e){const r=this.receiveCallbacksQueue.shift();r!=null?r.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,ah)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:dh(e)?De.TYPE:Xe.TYPE,data:""}})}}const ch="freighterctx",lh=1e3,uh=1001,hh=[lh,uh],dh=t=>hh.includes(t.code),xa=class Ca extends ka{constructor(e,r,n=!1){super(),D(this,"baseUrl"),D(this,"encoder"),this.baseUrl=e.replace({protocol:n?"wss":"ws"}),this.encoder=r}async stream(e,r,n){const i=ih();let a;const[,o]=await this.executeMiddleware({target:e,protocol:"websocket",params:{},role:"client"},async c=>{const u=i(this.buildURL(e,c)),d={...c,params:{}};u.binaryType=Ca.MESSAGE_TYPE;const f=await this.wrapSocket(u,r,n);return f instanceof Error?[d,f]:(a=f,[d,null])});if(o!=null)throw o;return a}buildURL(e,r){const n=Zu({[Aa]:this.encoder.contentType,...r.params},ch);return this.baseUrl.child(e).toString()+n}async wrapSocket(e,r,n){return await new Promise(i=>{e.onopen=()=>{i(new oh(e,this.encoder,r,n))},e.onerror=a=>{const o=a;i(new Error(o.message))}})}};D(xa,"MESSAGE_TYPE","arraybuffer");let fh=xa;const yh=t=>{const e=t.replace(/_[a-z]/g,r=>r[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()?e:e[0].toLowerCase()+e.slice(1)},$a=t=>{const e=(r,n=Bn)=>{if(typeof r=="string")return t(r);if(Array.isArray(r))return r.map(o=>e(o,n));if(!hn(r))return r;n=mh(n);const i={},a=r;return Object.keys(a).forEach(o=>{let c=a[o];const u=t(o);n.recursive&&(hn(c)?ei(c,n.keepTypesOnRecursion)||(c=e(c,n)):n.recursiveInArray&&Qs(c)&&(c=[...c].map(d=>{let f=d;return hn(d)?ei(f,n.keepTypesOnRecursion)||(f=e(d,n)):Qs(d)&&(f=e({key:d},n).key),f}))),i[u]=c}),i};return e},ja=$a(yh),gh=t=>t.replace(/([a-z0-9])([A-Z])/g,(e,r,n)=>`${r}_${n.toLowerCase()}`),ph=$a(gh),Bn={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},mh=(t=Bn)=>(t.recursive==null?t=Bn:t.recursiveInArray==null&&(t.recursiveInArray=!1),t),Qs=t=>t!=null&&Array.isArray(t),hn=t=>t!=null&&typeof t=="object"&&!Array.isArray(t),ei=(t,e)=>(e||[]).some(r=>t instanceof r),is=t=>t!=null&&typeof t=="object"&&!Array.isArray(t);var wh=Object.defineProperty,bh=(t,e,r)=>e in t?wh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,zt=(t,e,r)=>bh(t,typeof e!="symbol"?e+"":e,r);let Ra=class{constructor(){zt(this,"contentType","application/json"),zt(this,"decoder"),zt(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(t){return this.encoder.encode(this.encodeString(t)).buffer}decode(t,e){return this.decodeString(this.decoder.decode(t),e)}decodeString(t,e){const r=JSON.parse(t),n=ja(r);return e!=null?e.parse(n):n}encodeString(t){const e=ph(t);return JSON.stringify(e,(r,n)=>ArrayBuffer.isView(n)?Array.from(n):is(n)&&"encode_value"in n?typeof n.value=="bigint"?n.value.toString():n.value:typeof n=="bigint"?n.toString():n)}static registerCustomType(){}},Ma=class{constructor(){zt(this,"contentType","text/csv")}encode(t){const e=this.encodeString(t);return new TextEncoder().encode(e).buffer}decode(t,e){const r=new TextDecoder().decode(t);return this.decodeString(r,e)}encodeString(t){if(!Array.isArray(t)||t.length===0||!is(t[0]))throw new Error("Payload must be an array of objects");const e=Object.keys(t[0]),r=[e.join(",")];return t.forEach(n=>{const i=e.map(a=>JSON.stringify(n[a]??""));r.push(i.join(","))}),r.join(`
18
- `)}decodeString(t,e){const[r,...n]=t.trim().split(`
19
- `).map(o=>o.trim());if(r.length===0)return e!=null?e.parse({}):{};const i=r.split(",").map(o=>o.trim()),a={};return i.forEach(o=>{a[o]=[]}),n.forEach(o=>{const c=o.split(",").map(u=>u.trim());i.forEach((u,d)=>{const f=this.parseValue(c[d]);f!=null&&a[u].push(f)})}),e!=null?e.parse(a):a}parseValue(t){if(t==null||t.length===0)return null;const e=Number(t);return isNaN(e)?t.startsWith('"')&&t.endsWith('"')?t.slice(1,-1):t:e}static registerCustomType(){}},Da=class{constructor(){zt(this,"contentType","text/plain")}encode(t){return new TextEncoder().encode(t).buffer}decode(t,e){const r=new TextDecoder().decode(t);return e!=null?e.parse(r):r}};const He=new Ra,vh=new Ma,Oh=new Da,Th=[He],et=Object.freeze(Object.defineProperty({__proto__:null,CSVCodec:Ma,CSV_CODEC:vh,ENCODERS:Th,JSONCodec:Ra,JSON_CODEC:He,TEXT_CODEC:Oh,TextCodec:Da},Symbol.toStringTag,{value:"Module"})),Sh=t=>t!=null&&typeof t=="object"&&"toString"in t,zh=(t,e=!1)=>{const r=Sh(t)?"stringer":typeof t;let n;switch(r){case"string":n=(i,a)=>i.localeCompare(a);break;case"stringer":n=(i,a)=>i.toString().localeCompare(a.toString());break;case"number":n=(i,a)=>Number(i)-Number(a);break;case"bigint":n=(i,a)=>BigInt(i)-BigInt(a)>0n?1:-1;break;case"boolean":n=(i,a)=>Number(i)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${r}`),()=>-1}return e?Nh(n):n},Nh=t=>(e,r)=>t(r,e),Eh=0,dn=-1,fn=1,Ih=t=>t<0,kh=t=>t>0,Ah=t=>t===0,Fr=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const Pa=s.z.object({width:s.z.number(),height:s.z.number()}),xh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),Ch=["width","height"];s.z.enum(Ch);const $h=["start","center","end"],jh=["signedWidth","signedHeight"];s.z.enum(jh);const $r=s.z.object({x:s.z.number(),y:s.z.number()}),Rh=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),Mh=["x","y"],Ba=s.z.enum(Mh),Ua=["top","right","bottom","left"];s.z.enum(Ua);const Dh=["left","right"],La=s.z.enum(Dh),Ph=["top","bottom"],Ya=s.z.enum(Ph),qa=["center"],ti=s.z.enum(qa),Bh=[...Ua,...qa],_a=s.z.enum(Bh);s.z.enum($h);const Uh=["first","last"];s.z.enum(Uh);const Lh=s.z.object({lower:s.z.number(),upper:s.z.number()}),Yh=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([Lh,Fr]);s.z.union([Yh,Fr]);s.z.union([Ba,_a]);s.z.union([Ba,_a,s.z.instanceof(String)]);const Nt=(t,e)=>{const r={};if(typeof t=="number"||typeof t=="bigint")e!=null?(r.lower=t,r.upper=e):(r.lower=typeof t=="bigint"?0n:0,r.upper=t);else if(Array.isArray(t)){if(t.length!==2)throw new Error("bounds: expected array of length 2");[r.lower,r.upper]=t}else return ri(t);return ri(r)},ri=t=>t.lower>t.upper?{lower:t.upper,upper:t.lower}:t;s.z.object({x:La.or(ti),y:Ya.or(ti)});const qh=s.z.object({x:La,y:Ya}),_h=Object.freeze({x:"left",y:"top"}),Fh=(t,e)=>t.x===e.x&&t.y===e.y,ni=s.z.union([s.z.number(),$r,Fr,Pa,xh,Rh]),Wh=(t,e)=>{if(typeof t=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return t==="x"?{x:e,y:0}:{x:0,y:e}}return typeof t=="number"?{x:t,y:e??t}:Array.isArray(t)?{x:t[0],y:t[1]}:"signedWidth"in t?{x:t.signedWidth,y:t.signedHeight}:"clientX"in t?{x:t.clientX,y:t.clientY}:"width"in t?{x:t.width,y:t.height}:{x:t.x,y:t.y}},si=Object.freeze({x:0,y:0}),Jt=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Jt,left:Jt,width:Jt,height:Jt});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:$r,two:$r,root:qh});const as=(t,e,r=0,n=0,i)=>{const a={one:{...si},two:{...si},root:i??_h};if(typeof t=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:t,y:e},a.two={x:a.one.x+r,y:a.one.y+n},a}return"one"in t&&"two"in t&&"root"in t?{...t,root:i??t.root}:("getBoundingClientRect"in t&&(t=t.getBoundingClientRect()),"left"in t?(a.one={x:t.left,y:t.top},a.two={x:t.right,y:t.bottom},a):(a.one=t,e==null?a.two={x:a.one.x+r,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+r}:"width"in e?a.two={x:a.one.x+e.width,y:a.one.y+e.height}:"signedWidth"in e?a.two={x:a.one.x+e.signedWidth,y:a.one.y+e.signedHeight}:a.two=e,a))},yn=t=>{const e=as(t);return{lower:e.one.x,upper:e.two.x}},gn=t=>{const e=as(t);return{lower:e.one.y,upper:e.two.y}},Vh=t=>typeof t!="object"||t==null?!1:"one"in t&&"two"in t&&"root"in t,Gh=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([Pa,Gh,$r,Fr]);var Zh=Object.defineProperty,Kh=(t,e,r)=>e in t?Zh(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,$e=(t,e,r)=>Kh(t,typeof e!="symbol"?e+"":e,r);const Jh=(t,e,r)=>e!==void 0&&t<e?e:r!==void 0&&t>r?r:t;s.z.object({offset:ni,scale:ni});const Hh=t=>(e,r,n,i)=>r==="dimension"?[e,n]:[e,i?n-t:n+t],Xh=t=>(e,r,n,i)=>[e,i?n/t:n*t],Qh=t=>(e,r,n)=>{if(e===null)return[t,n];const{lower:i,upper:a}=e,{lower:o,upper:c}=t,u=a-i,d=c-o;if(r==="dimension")return[t,n*(d/u)];const f=(n-i)*(d/u)+o;return[t,f]},ed=t=>(e,r,n)=>[t,n],td=()=>(t,e,r)=>{if(t===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[t,r];const{lower:n,upper:i}=t;return[t,i-(r-n)]},rd=t=>(e,r,n)=>{const{lower:i,upper:a}=t;return n=Jh(n,i,a),[e,n]},Un=class yt{constructor(){$e(this,"ops",[]),$e(this,"currBounds",null),$e(this,"currType",null),$e(this,"reversed",!1),this.ops=[]}static translate(e){return new yt().translate(e)}static magnify(e){return new yt().magnify(e)}static scale(e,r){return new yt().scale(e,r)}translate(e){const r=this.new(),n=Hh(e);return n.type="translate",r.ops.push(n),r}magnify(e){const r=this.new(),n=Xh(e);return n.type="magnify",r.ops.push(n),r}scale(e,r){const n=Nt(e,r),i=this.new(),a=Qh(n);return a.type="scale",i.ops.push(a),i}clamp(e,r){const n=Nt(e,r),i=this.new(),a=rd(n);return a.type="clamp",i.ops.push(a),i}reBound(e,r){const n=Nt(e,r),i=this.new(),a=ed(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=td();e.type="invert";const r=this.new();return r.ops.push(e),r}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new yt;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,r){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,r])[1]}reverse(){const e=this.new();e.ops.reverse();const r=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||r.some(([o,c])=>i>=o&&i<=c))return;const a=e.ops.findIndex((o,c)=>o.type==="scale"&&c>i);a!==-1&&r.push([i,a])}),r.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}};$e(Un,"IDENTITY",new Un);let ii=Un;const ai=class Ae{constructor(e=new ii,r=new ii,n=null){$e(this,"x"),$e(this,"y"),$e(this,"currRoot"),this.x=e,this.y=r,this.currRoot=n}static translate(e,r){return new Ae().translate(e,r)}static translateX(e){return new Ae().translateX(e)}static translateY(e){return new Ae().translateY(e)}static clamp(e){return new Ae().clamp(e)}static magnify(e){return new Ae().magnify(e)}static scale(e){return new Ae().scale(e)}static reBound(e){return new Ae().reBound(e)}translate(e,r){const n=Wh(e,r),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}translateX(e){const r=this.copy();return r.x=this.x.translate(e),r}translateY(e){const r=this.copy();return r.y=this.y.translate(e),r}magnify(e){const r=this.copy();return r.x=this.x.magnify(e.x),r.y=this.y.magnify(e.y),r}scale(e){const r=this.copy();if(Vh(e)){const n=this.currRoot;return r.currRoot=e.root,n!=null&&!Fh(n,e.root)&&(n.x!==e.root.x&&(r.x=r.x.invert()),n.y!==e.root.y&&(r.y=r.y.invert())),r.x=r.x.scale(yn(e)),r.y=r.y.scale(gn(e)),r}return r.x=r.x.scale(e.width),r.y=r.y.scale(e.height),r}reBound(e){const r=this.copy();return r.x=this.x.reBound(yn(e)),r.y=this.y.reBound(gn(e)),r}clamp(e){const r=this.copy();return r.x=this.x.clamp(yn(e)),r.y=this.y.clamp(gn(e)),r}copy(){const e=new Ae;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}box(e){return as(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};$e(ai,"IDENTITY",new ai);var nd=Object.defineProperty,sd=(t,e,r)=>e in t?nd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,w=(t,e,r)=>sd(t,typeof e!="symbol"?e+"":e,r);let id=(t,e=21)=>(r=e)=>{let n="",i=r;for(;i--;)n+=t[Math.random()*t.length|0];return n};const ad="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Fa=id(ad,11),od=Object.freeze(Object.defineProperty({__proto__:null,id:Fa},Symbol.toStringTag,{value:"Module"})),Wa=(t,e)=>{const r=new k(e);if(![I.DAY,I.HOUR,I.MINUTE,I.SECOND,I.MILLISECOND,I.MICROSECOND,I.NANOSECOND].some(i=>i.equals(r)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=t.valueOf()%r.valueOf();return t instanceof k?new k(n):new I(n)},q=class z{constructor(e,r="UTC"){if(w(this,"value"),w(this,"encodeValue",!0),e==null)this.value=z.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*z.MILLISECOND.valueOf();else if(typeof e=="string")this.value=z.parseDateTimeString(e,r).valueOf();else if(Array.isArray(e))this.value=z.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),r==="local"&&(n=z.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=z.MAX:e=z.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,r=1,n=1]){const i=new Date(e,r-1,n,0,0,0,0);return new z(BigInt(i.getTime())*z.MILLISECOND.valueOf()).truncate(z.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,r="UTC"){const[n,i,a]=e.split(":");let o="00",c="00";a!=null&&([o,c]=a.split("."));let u=z.hours(parseInt(n??"00",10)).add(z.minutes(parseInt(i??"00",10))).add(z.seconds(parseInt(o??"00",10))).add(z.milliseconds(parseInt(c??"00",10)));return r==="local"&&(u=u.add(z.utcOffset)),u.valueOf()}static parseDateTimeString(e,r="UTC"){if(!e.includes("/")&&!e.includes("-"))return z.parseTimeString(e,r);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new z(BigInt(n.getTime())*z.MILLISECOND.valueOf(),r).valueOf()}fString(e="ISO",r="UTC"){switch(e){case"ISODate":return this.toISOString(r).slice(0,10);case"ISOTime":return this.toISOString(r).slice(11,23);case"time":return this.timeString(!1,r);case"preciseTime":return this.timeString(!0,r);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,r)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,r)}`;default:return this.toISOString(r)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(z.utcOffset).date().toISOString()}timeString(e=!1,r="UTC"){const n=this.toISOString(r);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),r=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${r} ${n}`}static get utcOffset(){return new I(BigInt(new Date().getTimezoneOffset())*z.MINUTE.valueOf())}static since(e){return new z().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new z(e).valueOf()}span(e){return this.range(e).span}range(e){return new ne(this,e).makeValid()}spanRange(e){return this.range(this.add(e)).makeValid()}get isZero(){return this.valueOf()===BigInt(0)}after(e){return this.valueOf()>new z(e).valueOf()}afterEq(e){return this.valueOf()>=new z(e).valueOf()}before(e){return this.valueOf()<new z(e).valueOf()}beforeEq(e){return this.valueOf()<=new z(e).valueOf()}add(e){return new z(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new z(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(z.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Wa(this,e)}get isToday(){return this.truncate(I.DAY).equals(z.now().truncate(I.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new z(new Date)}static max(...e){let r=z.MIN;for(const n of e){const i=new z(n);i.after(r)&&(r=i)}return r}static min(...e){let r=z.MAX;for(const n of e){const i=new z(n);i.before(r)&&(r=i)}return r}static nanoseconds(e){return new z(e)}static microseconds(e){return z.nanoseconds(e*1e3)}static milliseconds(e){return z.microseconds(e*1e3)}static seconds(e){return z.milliseconds(e*1e3)}static minutes(e){return z.seconds(e*60)}static hours(e){return z.minutes(e*60)}static days(e){return z.hours(e*24)}};w(q,"NANOSECOND",q.nanoseconds(1)),w(q,"MICROSECOND",q.microseconds(1)),w(q,"MILLISECOND",q.milliseconds(1)),w(q,"SECOND",q.seconds(1)),w(q,"MINUTE",q.minutes(1)),w(q,"HOUR",q.hours(1)),w(q,"DAY",q.days(1)),w(q,"MAX",new q((1n<<63n)-1n)),w(q,"MIN",new q(0)),w(q,"ZERO",new q(0)),w(q,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new q(t.value)),s.z.string().transform(t=>new q(BigInt(t))),s.z.instanceof(Number).transform(t=>new q(t)),s.z.number().transform(t=>new q(t)),s.z.instanceof(q)]));let k=q;const _=class C{constructor(e){w(this,"value"),w(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new C(e).valueOf()}greaterThan(e){return this.valueOf()>new C(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new C(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new C(e).valueOf()}remainder(e){return Wa(this,e)}truncate(e){return new C(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(C.DAY),r=this.truncate(C.HOUR),n=this.truncate(C.MINUTE),i=this.truncate(C.SECOND),a=this.truncate(C.MILLISECOND),o=this.truncate(C.MICROSECOND),c=this.truncate(C.NANOSECOND),u=e,d=r.sub(e),f=n.sub(r),h=i.sub(n),j=a.sub(i),W=o.sub(a),se=c.sub(o);let R="";return u.isZero||(R+=`${u.days}d `),d.isZero||(R+=`${d.hours}h `),f.isZero||(R+=`${f.minutes}m `),h.isZero||(R+=`${h.seconds}s `),j.isZero||(R+=`${j.milliseconds}ms `),W.isZero||(R+=`${W.microseconds}µs `),se.isZero||(R+=`${se.nanoseconds}ns`),R.trim()}get days(){return Number(this.valueOf())/Number(C.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(C.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(C.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(C.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(C.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(C.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new C(e).valueOf()}add(e){return new C(this.valueOf()+new C(e).valueOf())}sub(e){return new C(this.valueOf()-new C(e).valueOf())}static nanoseconds(e=1){return new C(e)}static microseconds(e=1){return C.nanoseconds(e*1e3)}static milliseconds(e=1){return C.microseconds(e*1e3)}static seconds(e=1){return C.milliseconds(e*1e3)}static minutes(e){return C.seconds(e.valueOf()*60)}static hours(e){return C.minutes(e*60)}static days(e){return C.hours(e*24)}};w(_,"NANOSECOND",_.nanoseconds(1)),w(_,"MICROSECOND",_.microseconds(1)),w(_,"MILLISECOND",_.milliseconds(1)),w(_,"SECOND",_.seconds(1)),w(_,"MINUTE",_.minutes(1)),w(_,"HOUR",_.hours(1)),w(_,"DAY",_.days(1)),w(_,"MAX",new _((1n<<63n)-1n)),w(_,"MIN",new _(0)),w(_,"ZERO",new _(0)),w(_,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(t=>new _(t.value)),s.z.string().transform(t=>new _(BigInt(t))),s.z.instanceof(Number).transform(t=>new _(t)),s.z.number().transform(t=>new _(t)),s.z.instanceof(_)]));let I=_;const gt=class hr extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new hr(e).valueOf()}get period(){return I.seconds(1/this.valueOf())}sampleCount(e){return new I(e).seconds*this.valueOf()}byteCount(e,r){return this.sampleCount(e)*new ue(r).valueOf()}span(e){return I.seconds(e/this.valueOf())}byteSpan(e,r){return this.span(e.valueOf()/r.valueOf())}static hz(e){return new hr(e)}static khz(e){return hr.hz(e*1e3)}};w(gt,"z",s.z.union([s.z.number().transform(t=>new gt(t)),s.z.instanceof(Number).transform(t=>new gt(t)),s.z.instanceof(gt)]));let os=gt;const ee=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new At(e*this.valueOf())}};w(ee,"UNKNOWN",new ee(0)),w(ee,"BIT128",new ee(16)),w(ee,"BIT64",new ee(8)),w(ee,"BIT32",new ee(4)),w(ee,"BIT16",new ee(2)),w(ee,"BIT8",new ee(1)),w(ee,"z",s.z.union([s.z.number().transform(t=>new ee(t)),s.z.instanceof(Number).transform(t=>new ee(t)),s.z.instanceof(ee)]));let ue=ee;const ze=class dr{constructor(e,r){w(this,"start"),w(this,"end"),typeof e=="object"&&"start"in e?(this.start=new k(e.start),this.end=new k(e.end)):(this.start=new k(e),this.end=new k(r))}get span(){return new I(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 dr(this.end,this.start)}equals(e){return this.start.equals(e.start)&&this.end.equals(e.end)}toString(){return`${this.start.toString()} - ${this.end.toString()}`}toPrettyString(){return`${this.start.fString("preciseDate")} - ${this.span.toString()}`}overlapsWith(e,r=I.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=k.max(n.start,e.start),a=k.min(n.end,e.end);return a.before(i)?!1:new I(a.sub(i)).greaterThanOrEqual(r)}roughlyEquals(e,r){let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=r.valueOf()&&i<=r.valueOf()}contains(e){return e instanceof dr?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const r=new dr(this.start,this.end);return e.start.after(this.start)&&(r.start=e.start),e.start.after(this.end)&&(r.end=e.start),e.end.before(this.end)&&(r.end=e.end),e.end.before(this.start)&&(r.start=e.end),r}};w(ze,"MAX",new ze(k.MIN,k.MAX)),w(ze,"MIN",new ze(k.MAX,k.MIN)),w(ze,"ZERO",new ze(k.ZERO,k.ZERO)),w(ze,"z",s.z.union([s.z.object({start:k.z,end:k.z}).transform(t=>new ze(t.start,t.end)),s.z.instanceof(ze)]));let ne=ze;const g=class Ne extends String{constructor(e){if(e instanceof Ne||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const r=Ne.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(r!=null){super(r.valueOf());return}}throw super(Ne.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=Ne.ARRAY_CONSTRUCTORS.get(this.toString());if(e==null)throw new Error(`unable to find array constructor for ${this.valueOf()}`);return e}equals(e){return this.valueOf()===e.valueOf()}matches(...e){return e.some(r=>this.equals(r))}toString(){return this.valueOf()}get isVariable(){return this.equals(Ne.JSON)||this.equals(Ne.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(Ne.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=Ne.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return Ne.BIG_INT_TYPES.some(e=>e.equals(this))}};w(g,"UNKNOWN",new g("unknown")),w(g,"FLOAT64",new g("float64")),w(g,"FLOAT32",new g("float32")),w(g,"INT64",new g("int64")),w(g,"INT32",new g("int32")),w(g,"INT16",new g("int16")),w(g,"INT8",new g("int8")),w(g,"UINT64",new g("uint64")),w(g,"UINT32",new g("uint32")),w(g,"UINT16",new g("uint16")),w(g,"UINT8",new g("uint8")),w(g,"BOOLEAN",g.UINT8),w(g,"TIMESTAMP",new g("timestamp")),w(g,"UUID",new g("uuid")),w(g,"STRING",new g("string")),w(g,"JSON",new g("json")),w(g,"ARRAY_CONSTRUCTORS",new Map([[g.UINT8.toString(),Uint8Array],[g.UINT16.toString(),Uint16Array],[g.UINT32.toString(),Uint32Array],[g.UINT64.toString(),BigUint64Array],[g.FLOAT32.toString(),Float32Array],[g.FLOAT64.toString(),Float64Array],[g.INT8.toString(),Int8Array],[g.INT16.toString(),Int16Array],[g.INT32.toString(),Int32Array],[g.INT64.toString(),BigInt64Array],[g.TIMESTAMP.toString(),BigInt64Array],[g.STRING.toString(),Uint8Array],[g.JSON.toString(),Uint8Array],[g.UUID.toString(),Uint8Array]])),w(g,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,g.UINT8],[Uint16Array.name,g.UINT16],[Uint32Array.name,g.UINT32],[BigUint64Array.name,g.UINT64],[Float32Array.name,g.FLOAT32],[Float64Array.name,g.FLOAT64],[Int8Array.name,g.INT8],[Int16Array.name,g.INT16],[Int32Array.name,g.INT32],[BigInt64Array.name,g.INT64]])),w(g,"DENSITIES",new Map([[g.UINT8.toString(),ue.BIT8],[g.UINT16.toString(),ue.BIT16],[g.UINT32.toString(),ue.BIT32],[g.UINT64.toString(),ue.BIT64],[g.FLOAT32.toString(),ue.BIT32],[g.FLOAT64.toString(),ue.BIT64],[g.INT8.toString(),ue.BIT8],[g.INT16.toString(),ue.BIT16],[g.INT32.toString(),ue.BIT32],[g.INT64.toString(),ue.BIT64],[g.TIMESTAMP.toString(),ue.BIT64],[g.STRING.toString(),ue.UNKNOWN],[g.JSON.toString(),ue.UNKNOWN],[g.UUID.toString(),ue.BIT128]])),w(g,"ALL",[g.UNKNOWN,g.FLOAT64,g.FLOAT32,g.INT64,g.INT32,g.INT16,g.INT8,g.UINT64,g.UINT32,g.UINT16,g.UINT8,g.TIMESTAMP,g.UUID,g.STRING,g.JSON]),w(g,"BIG_INT_TYPES",[g.INT64,g.UINT64,g.TIMESTAMP]),w(g,"z",s.z.union([s.z.string().transform(t=>new g(t)),s.z.instanceof(g)]));let E=g;const oe=class J extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return J.bytes(this.valueOf()+e.valueOf())}sub(e){return J.bytes(this.valueOf()-e.valueOf())}truncate(e){return new J(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return J.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/J.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/J.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/J.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/J.TERABYTE.valueOf()}toString(){const e=this.truncate(J.TERABYTE),r=this.truncate(J.GIGABYTE),n=this.truncate(J.MEGABYTE),i=this.truncate(J.KILOBYTE),a=this.truncate(J.BYTE),o=e,c=r.sub(e),u=n.sub(r),d=i.sub(n),f=a.sub(i);let h="";return o.isZero||(h+=`${o.terabytes}TB `),c.isZero||(h+=`${c.gigabytes}GB `),u.isZero||(h+=`${u.megabytes}MB `),d.isZero||(h+=`${d.kilobytes}KB `),(!f.isZero||h==="")&&(h+=`${f.valueOf()}B`),h.trim()}static bytes(e=1){return new J(e)}static kilobytes(e=1){return J.bytes(e.valueOf()*1e3)}static megabytes(e=1){return J.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return J.megabytes(e.valueOf()*1e3)}static terabytes(e){return J.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};w(oe,"BYTE",new oe(1)),w(oe,"KILOBYTE",oe.kilobytes(1)),w(oe,"MEGABYTE",oe.megabytes(1)),w(oe,"GIGABYTE",oe.gigabytes(1)),w(oe,"TERABYTE",oe.terabytes(1)),w(oe,"ZERO",new oe(0)),w(oe,"z",s.z.union([s.z.number().transform(t=>new oe(t)),s.z.instanceof(oe)]));let At=oe;s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);const Va=t=>{const e=typeof t;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||t instanceof k||t instanceof I||t instanceof Date},cd=(t,e,r,n=0)=>t.usesBigInt&&!e.usesBigInt?Number(r)-Number(n):!t.usesBigInt&&e.usesBigInt?BigInt(r)-BigInt(n):pt(r,-n),ld=t=>t==null?!1:Array.isArray(t)||t instanceof ArrayBuffer||ArrayBuffer.isView(t)&&!(t instanceof DataView)||t instanceof Je?!0:Va(t),Ye=-1;let Je=class xe{constructor(e){w(this,"key",""),w(this,"isSynnaxSeries",!0),w(this,"dataType"),w(this,"sampleOffset"),w(this,"gl"),w(this,"_data"),w(this,"_timeRange"),w(this,"alignment",0n),w(this,"_cachedMin"),w(this,"_cachedMax"),w(this,"writePos",Ye),w(this,"_refCount",0),w(this,"_cachedLength"),ld(e)&&(e={data:e});const{dataType:r,timeRange:n,sampleOffset:i=0,glBufferUsage:a="static",alignment:o=0n,key:c=Fa()}=e,{data:u}=e;if(u instanceof xe||typeof u=="object"&&"isSynnaxSeries"in u&&u.isSynnaxSeries===!0){const h=u;this.key=h.key,this.dataType=h.dataType,this.sampleOffset=h.sampleOffset,this.gl=h.gl,this._data=h._data,this._timeRange=h._timeRange,this.alignment=h.alignment,this._cachedMin=h._cachedMin,this._cachedMax=h._cachedMax,this.writePos=h.writePos,this._refCount=h._refCount,this._cachedLength=h._cachedLength;return}const d=Va(u),f=Array.isArray(u);if(r!=null)this.dataType=new E(r);else{if(u instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(f||d){let h=u;if(!d){if(u.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");h=u[0]}if(typeof h=="string")this.dataType=E.STRING;else if(typeof h=="number")this.dataType=E.FLOAT64;else if(typeof h=="bigint")this.dataType=E.INT64;else if(typeof h=="boolean")this.dataType=E.BOOLEAN;else if(h instanceof k||h instanceof Date||h instanceof k)this.dataType=E.TIMESTAMP;else if(typeof h=="object")this.dataType=E.JSON;else throw new Error(`cannot infer data type of ${typeof h} when constructing a Series from a JS array`)}else this.dataType=new E(u)}if(!f&&!d)this._data=u;else{let h=d?[u]:u;const j=h[0];(j instanceof k||j instanceof Date||j instanceof I)&&(h=h.map(W=>new k(W).valueOf())),this.dataType.equals(E.STRING)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.join(`
20
- `)+`
21
- `)):this.dataType.equals(E.JSON)?(this._cachedLength=h.length,this._data=new TextEncoder().encode(h.map(W=>He.encodeString(W)).join(`
22
- `)+`
23
- `)):this._data=new this.dataType.Array(h).buffer}this.key=c,this.alignment=o,this.sampleOffset=i??0,this._timeRange=n,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:r,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const i=new new E(r).Array(e),a=new xe({data:i.buffer,dataType:r,...n});return a.writePos=0,a}static generateTimestamps(e,r,n){const i=n.spanRange(r.span(e)),a=new BigInt64Array(e);for(let o=0;o<e;o++)a[o]=BigInt(n.add(r.span(o)).valueOf());return new xe({data:a,dataType:E.TIMESTAMP,timeRange:i})}get refCount(){return this._refCount}static fromStrings(e,r){const n=new TextEncoder().encode(e.join(`
24
- `)+`
25
- `);return new xe({data:n,dataType:E.STRING,timeRange:r})}static fromJSON(e,r){const n=new TextEncoder().encode(e.map(i=>He.encodeString(i)).join(`
26
- `)+`
27
- `);return new xe({data:n,dataType:E.JSON,timeRange:r})}acquire(e){this._refCount++,e!=null&&this.updateGLBuffer(e)}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(e){if(!e.dataType.equals(this.dataType))throw new Error("buffer must be of the same type as this array");if(this.writePos===Ye)return 0;const r=this.capacity-this.writePos,n=r<e.length?e.slice(0,r):e;return this.underlyingData.set(n.data,this.writePos),this.maybeRecomputeMinMax(n),this._cachedLength=void 0,this.writePos+=n.length,n.length}get buffer(){return this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Ye?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(E.STRING,E.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
28
- `).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(E.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=E.UUID.density.valueOf(),r=Array(this.length);for(let n=0;n<this.length;n++){const i=this.buffer.slice(n*e,(n+1)*e),a=Array.from(new Uint8Array(i),o=>o.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");r[n]=a}return r}parseJSON(e){if(!this.dataType.equals(E.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
29
- `).slice(0,-1).map(r=>e.parse(He.decodeString(r)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new At(this.buffer.byteLength)}get capacity(){return this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Ye?this.byteCapacity:this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Ye?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;return this.data.forEach(r=>{r===10&&e++}),this._cachedLength=e,e}convert(e,r=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let i=0;i<this.length;i++)n[i]=cd(this.dataType,e,this.data[i],r);return new xe({data:n.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:r,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(E.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((r,n)=>r>n?r:n)}else{const e=this.data;this._cachedMax=e.reduce((r,n)=>r>n?r:n)}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==null&&(this._cachedMax=this.calcRawMax()),pt(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(E.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((r,n)=>r<n?r:n)}else{const e=this.data;this._cachedMin=e.reduce((r,n)=>r<n?r:n)}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==null&&(this._cachedMin=this.calcRawMin()),pt(this._cachedMin,this.sampleOffset))}get bounds(){return Nt(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const r=e._cachedMin??e.calcRawMin();r<this._cachedMin&&(this._cachedMin=r)}if(this._cachedMax!=null){const r=e._cachedMax??e.calcRawMax();r>this._cachedMax&&(this._cachedMax=r)}}enrich(){this.max,this.min}get range(){return pt(this.max,-this.min)}at(e,r){if(this.dataType.isVariable)return this.atVariable(e,r??!1);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(r===!0)throw new Error(`[series] - no value at index ${e}`);return}return pt(n,this.sampleOffset)}atVariable(e,r){e<0&&(e=this.length+e);let n=0,i=0;for(let o=0;o<this.data.length;o++)if(this.data[o]===10){if(e===0){i=o;break}n=o+1,e--}if(i===0&&(i=this.data.length),n>=i||e>0){if(r)throw new Error(`[series] - no value at index ${e}`);return}const a=this.data.slice(n,i);return this.dataType.equals(E.STRING)?new TextDecoder().decode(a):ja(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let r=0,n=this.length-1;const i=zh(e);for(;r<=n;){const a=Math.floor((r+n)/2),o=i(this.at(a,!0),e);if(o===0)return a;o<0?r=a+1:n=a-1}return r}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(E.FLOAT32))throw new Error("Only FLOAT32 arrays can be used in WebGL");const{buffer:r,bufferUsage:n,prevBuffer:i}=this.gl;if(r==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==i)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==Ye){i===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(i).valueOf(),o=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,o.buffer),this.gl.prevBuffer=this.writePos}else e.bufferData(e.ARRAY_BUFFER,this.buffer,n==="static"?e.STATIC_DRAW:e.DYNAMIC_DRAW),this.gl.prevBuffer=Ye}as(e){if(e==="string"){if(!this.dataType.equals(E.STRING))throw new Error(`cannot convert series of type ${this.dataType.toString()} to string`);return this}if(e==="number"){if(!this.dataType.isNumeric)throw new Error(`cannot convert series of type ${this.dataType.toString()} to number`);return this}if(e==="bigint"){if(!this.dataType.equals(E.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.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 Nt(this.alignment,this.alignment+BigInt(this.length))}maybeGarbageCollectGLBuffer(e){this.gl.buffer!=null&&(e.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 e=new ud(this);return this.dataType.equals(E.JSON)?new hd(e):e}return new dd(this)}slice(e,r){if(e<=0&&(r==null||r>=this.length))return this;const n=this.data.slice(e,r);return new xe({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}reAlign(e){return new xe({data:this.buffer,dataType:this.dataType,timeRange:ne.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};class ud{constructor(e){if(w(this,"series"),w(this,"index"),w(this,"decoder"),!e.dataType.isVariable)throw new Error("cannot create a variable series iterator for a non-variable series");this.series=e,this.index=0,this.decoder=new TextDecoder}next(){const e=this.index,r=this.series.data;for(;this.index<r.length&&r[this.index]!==10;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}[Symbol.iterator](){return this}}var oi,ci;class hd{constructor(e){w(this,"wrapped"),w(this,oi,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:He.decodeString(e.value)}}[(ci=Symbol.iterator,oi=Symbol.toStringTag,ci)](){return this}}var li,ui;class dd{constructor(e){w(this,"series"),w(this,"index"),w(this,li,"SeriesIterator"),this.series=e,this.index=0}next(){return this.index>=this.series.length?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[(ui=Symbol.iterator,li=Symbol.toStringTag,ui)](){return this}}const pt=(t,e)=>typeof t=="bigint"&&typeof e=="bigint"||typeof t=="number"&&typeof e=="number"?t+e:e===0?t:t===0?e:Number(t)+Number(e);class fd{constructor(e){if(w(this,"series"),e.length!==0){const r=e[0].dataType;for(let n=1;n<e.length;n++)if(!e[n].dataType.equals(r))throw new Error("[multi-series] - series must have the same data type")}this.series=e}as(e){if(!new E(e).equals(this.dataType))throw new Error(`cannot convert series of type ${this.dataType.toString()} to ${e.toString()}`);return this}get dataType(){return this.series.length===0?E.UNKNOWN:this.series[0].dataType}get timeRange(){return this.series.length===0?ne.ZERO:new ne(this.series[0].timeRange.start,this.series[this.series.length-1].timeRange.end)}push(e){this.series.push(e)}get length(){return this.series.reduce((e,r)=>e+r.length,0)}at(e,r=!1){e<0&&(e=this.length+e);for(const n of this.series){if(e<n.length)return n.at(e,r);e-=n.length}if(r)throw new Error(`[series] - no value at index ${e}`)}get byteLength(){return new At(this.series.reduce((e,r)=>e+r.byteLength.valueOf(),0))}get data(){const e=new this.dataType.Array(this.length);let r=0;for(const n of this.series)e.set(n.data,r),r+=n.length;return new this.dataType.Array(e)}[Symbol.iterator](){return this.series.length===0?{next(){return{done:!0,value:void 0}}}:new yd(this.series)}}var hi,di;class yd{constructor(e){w(this,"series"),w(this,"seriesIndex"),w(this,"internal"),w(this,hi,"MultiSeriesIterator"),this.series=e,this.seriesIndex=0,this.internal=e[0][Symbol.iterator]()}next(){const e=this.internal.next();return e.done===!1?e:this.seriesIndex===this.series.length-1?{done:!0,value:void 0}:(this.internal=this.series[++this.seriesIndex][Symbol.iterator](),this.next())}[(di=Symbol.iterator,hi=Symbol.toStringTag,di)](){return this}}const N=t=>Array.isArray(t)?t:[t],gd=(t,e)=>{let r=null;return e===0?t:(...n)=>{r!==null&&(clearTimeout(r),r=null),r=setTimeout(()=>t(...n),e)}};s.z.object({key:s.z.string(),value:s.z.string()});var pd=Object.defineProperty,md=(t,e,r)=>e in t?pd(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,fr=(t,e,r)=>md(t,typeof e!="symbol"?e+"":e,r);let wd=class{constructor(t,e){fr(this,"handlers"),fr(this,"transform"),fr(this,"closer"),this.transform=t,this.handlers=e??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){let e=t;if(this.transform!=null){const[r,n]=this.transform(t);if(!n)return;e=r}this.handlers.forEach((r,n)=>n(e))}setCloser(t){this.closer=t}async close(){var t;return await((t=this.closer)==null?void 0:t.call(this))}},bd=class{constructor(t){fr(this,"handlers"),this.handlers=t??new Map}onChange(t){return this.handlers.set(t,null),()=>this.handlers.delete(t)}notify(t){this.handlers.forEach((e,r)=>r(t))}};const Ve=Object.freeze(Object.defineProperty({__proto__:null,BaseObserver:bd,Observer:wd},Symbol.toStringTag,{value:"Module"})),cs=s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown()),vd=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser";vd();const Od=["MacOS","Windows","Linux","Docker"];s.z.enum(Od);const fi=t=>[...new Set(t)];var Td=Object.defineProperty,Sd=(t,e,r)=>e in t?Td(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,mt=(t,e,r)=>Sd(t,typeof e!="symbol"?e+"":e,r);const zd=(...t)=>t.map(Ga).join(""),Ga=t=>(t.endsWith("/")||(t+="/"),t.startsWith("/")&&(t=t.slice(1)),t),Nd=t=>t.endsWith("/")?t.slice(0,-1):t,Ln=class Yn{constructor({host:e,port:r,protocol:n="",pathPrefix:i=""}){mt(this,"protocol"),mt(this,"host"),mt(this,"port"),mt(this,"path"),this.protocol=n,this.host=e,this.port=r,this.path=Ga(i)}replace(e){return new Yn({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Yn({...this,pathPrefix:zd(this.path,e)})}toString(){return Nd(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};mt(Ln,"UNKNOWN",new Ln({host:"unknown",port:0}));let Ed=Ln;var Id=Object.defineProperty,kd=(t,e,r)=>e in t?Id(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,yr=(t,e,r)=>kd(t,typeof e!="symbol"?e+"":e,r);const _e=class extends Number{};yr(_e,"Absolute",255),yr(_e,"Default",1),yr(_e,"z",s.z.union([s.z.instanceof(_e),s.z.number().int().min(0).max(255).transform(t=>new _e(t)),s.z.instanceof(Number).transform(t=>new _e(t))]));let Za=_e;const Ka=s.z.object({name:s.z.string(),key:s.z.string()}),Ad=t=>s.z.object({subject:Ka,resource:t,authority:Za.z}),xd=(...t)=>e=>e.filter(r=>{let n=!1;return r.to!=null&&(n=t.includes(r.to.resource)),r.from!=null&&!n&&(n=t.includes(r.from.resource)),n}),Qe=Object.freeze(Object.defineProperty({__proto__:null,Authority:Za,filterTransfersByChannelKey:xd,stateZ:Ad,subjectZ:Ka},Symbol.toStringTag,{value:"Module"})),Ja=class wt extends Error{constructor(){super(wt.MESSAGE)}matches(e){return typeof e=="string"?e.includes(wt.MESSAGE):e instanceof wt||e.message.includes(wt.MESSAGE)}};yr(Ja,"MESSAGE","canceled");let Cd=Ja;new Cd;const qn=s.z.string().regex(/^\d+\.\d+\.\d+$/),Ut=(t,e,r={})=>{r.checkMajor??(r.checkMajor=!0),r.checkMinor??(r.checkMinor=!0),r.checkPatch??(r.checkPatch=!0);const n=qn.parse(t),i=qn.parse(e),[a,o,c]=n.split(".").map(Number),[u,d,f]=i.split(".").map(Number);if(r.checkMajor){if(a<u)return dn;if(a>u)return fn}if(r.checkMinor){if(o<d)return dn;if(o>d)return fn}if(r.checkPatch){if(c<f)return dn;if(c>f)return fn}return Eh},$d=(t,e,r={})=>Ah(Ut(t,e,r)),Ha=(t,e,r={})=>kh(Ut(t,e,r)),jd=(t,e,r={})=>Ih(Ut(t,e,r)),Rd=({name:t,migrate:e})=>r=>{try{const n=e(r);return console.log(`${t} migrated: ${r.version} -> ${n.version}`),n}catch(n){throw console.log(`${t} failed to migrate from ${r.version}`),console.error(n),n}},Md=({name:t,migrations:e,targetSchema:r,def:n})=>{const i=Object.keys(e).sort(Ut).pop();if(i==null)return u=>{if(u.version!==n.version)return console.log(`${t} version ${u.version} is newer than latest version of ${n.version}.
30
- Returning default instead.
31
- `),n;try{return r!=null?r.parse(u):u}catch(d){return console.log(`${t} failed to parse default. Exiting with default`),console.error(d),n}};const a=Object.keys(e).length;let o=!1;const c=u=>{try{if(a===0||Ha(u.version,i))return console.log(o?`${t} ${u.version} now up to date`:`${t} version ${u.version} is up to date with target version ${n.version}`),u;const d=u.version,f=e[d],h=f(u);return o=!0,c(h)}catch(d){return console.log(`${t} failed to migrate from ${u.version} to ${i}`),console.error(d),n}};return u=>{try{return c(u)}catch(d){return console.log(`${t} failed to parse final result. Exiting with default`),console.error(d),n}}},yi=Object.freeze(Object.defineProperty({__proto__:null,compareSemVer:Ut,createMigration:Rd,migrator:Md,semVerNewer:Ha,semVerOlder:jd,semVerZ:qn,versionsEqual:$d},Symbol.toStringTag,{value:"Module"})),Pe="sy.",gr=class Xa extends be{constructor(){super(...arguments),l(this,"type",Xa.TYPE)}};l(gr,"TYPE",Pe+"validation"),l(gr,"matches",he(gr.TYPE));let G=gr;const pr=class Qa extends G{constructor(e,r){super(e+": "+r),l(this,"type",Qa.TYPE),l(this,"field"),l(this,"message"),this.field=e,this.message=r}};l(pr,"TYPE",G.TYPE+".field"),l(pr,"matches",he(pr.TYPE));let gi=pr;const mr=class eo extends be{constructor(){super(...arguments),l(this,"type",eo.TYPE)}};l(mr,"TYPE",Pe+"auth"),l(mr,"matches",he(mr.TYPE));let jr=mr;const wr=class to extends jr{constructor(){super(...arguments),l(this,"type",to.TYPE)}};l(wr,"TYPE",jr.TYPE+".invalid-token"),l(wr,"matches",he(wr.TYPE));let _n=wr;const br=class ro extends be{constructor(e){super(`
32
- Unexpected error encountered:
33
-
34
- ${e}
35
-
36
- Please report this to the Synnax team.
37
- `),l(this,"type",ro.TYPE)}};l(br,"TYPE",Pe+"unexpected"),l(br,"matches",he(br.TYPE));let pe=br;const vr=class no extends be{constructor(){super(...arguments),l(this,"type",no.TYPE)}};l(vr,"TYPE",Pe+"query"),l(vr,"matches",he(vr.TYPE));let we=vr;const Or=class so extends we{constructor(){super(...arguments),l(this,"type",so.TYPE)}};l(Or,"TYPE",we.TYPE+".not_found"),l(Or,"matches",he(Or.TYPE));let Rr=Or;const Tr=class io extends we{constructor(){super(...arguments),l(this,"type",io.TYPE)}};l(Tr,"TYPE",we.TYPE+".multiple_results"),l(Tr,"matches",he(Tr.TYPE));let Mr=Tr;const Sr=class ao extends be{constructor(e,r){super(e),l(this,"type",ao.TYPE),l(this,"path"),this.path=r}};l(Sr,"TYPE",Pe+"route"),l(Sr,"matches",he(Sr.TYPE));let pi=Sr;const zr=class oo extends be{constructor(){super(...arguments),l(this,"type",oo.TYPE)}};l(zr,"TYPE",Pe+"control"),l(zr,"matches",he(zr.TYPE));let Dr=zr;const Nr=class co extends Dr{constructor(){super(...arguments),l(this,"type",co.TYPE)}};l(Nr,"TYPE",Dr.TYPE+".unauthorized"),l(Nr,"matches",he(Nr.TYPE));let mi=Nr;const pn=class lo extends be{constructor(){super(...arguments),l(this,"type",lo.TYPE)}};l(pn,"TYPE",Pe+"contiguity"),l(pn,"matches",he(pn.TYPE));const Dd=t=>{if(!t.type.startsWith(Pe))return null;if(t.type.startsWith(G.TYPE)){if(t.type===gi.TYPE){const e=t.data.split(": ");return e.length<2?new G(t.data):new gi(e[0],e[1])}return new G(t.data)}return t.type.startsWith(jr.TYPE)?t.type.startsWith(_n.TYPE)?new _n(t.data):new jr(t.data):t.type.startsWith(pe.TYPE)?new pe(t.data):t.type.startsWith(we.TYPE)?t.type.startsWith(Rr.TYPE)?new Rr(t.data):t.type.startsWith(Mr.TYPE)?new Mr(t.data):new we(t.data):t.type.startsWith(Dr.TYPE)?t.type.startsWith(mi.TYPE)?new mi(t.data):new Dr(t.data):t.type.startsWith(pi.TYPE)?new pi(t.data,t.data):new pe(t.data)},Pd=()=>{throw new Error("Not implemented")};za({encode:Pd,decode:Dd});const Bd=async(t,e)=>{const[r,n]=await e(t);return n==null?[r,n]:n instanceof We?[r,new We({message:`Cannot reach cluster at ${n.url.host}:${n.url.port}`,url:n.url})]:[r,n]};class uo{constructor(e,r){l(this,"key"),l(this,"name"),this.key=r,this.name=e}get ontologyID(){return new $({type:"group",key:this.key})}}const Ud=s.z.string().uuid(),ho=s.z.object({key:Ud,name:s.z.string()}),ls=s.z.union([s.z.literal("label"),s.z.literal("builtin"),s.z.literal("cluster"),s.z.literal("channel"),s.z.literal("node"),s.z.literal("group"),s.z.literal("range"),s.z.literal("range-alias"),s.z.literal("user"),s.z.literal("workspace"),s.z.literal("schematic"),s.z.literal("lineplot"),s.z.literal("rack"),s.z.literal("device"),s.z.literal("task"),s.z.literal("policy")]),fe=s.z.object({type:ls,key:s.z.string()}),Ld=s.z.string().transform(t=>{const[e,r]=t.split(":");return{type:e,key:r}}),Yd=s.z.union([Ld,fe]),Er=class fo{constructor(e){if(l(this,"type"),l(this,"key"),e instanceof fo)this.type=e.type,this.key=e.key;else if(typeof e=="string"){const[r,n]=e.split(":");this.type=r,this.key=n}else this.type=e.type,this.key=e.key}toString(){return`${this.type}:${this.key}`}get payload(){return{type:this.type,key:this.key}}};l(Er,"z",s.z.union([Yd,s.z.instanceof(Er)]).transform(t=>new Er(t)));let $=Er;new $({type:"builtin",key:"root"});const qd=s.z.object({type:s.z.number()}),_d=s.z.object({type:ls,fields:s.z.record(qd)}),Fd=s.z.object({id:$.z,name:s.z.string(),schema:_d.optional().nullable(),data:s.z.record(s.z.unknown()).optional().nullable()}).transform(t=>({key:t.id.toString(),...t}));s.z.object({from:$.z,type:s.z.string(),to:$.z});const wi=t=>{const[e,r,n]=t.split("->");return{from:new $(e),type:r,to:new $(n)}},Wd=s.z.object({group:ho}),Vd=s.z.object({parent:fe,key:s.z.string().uuid().optional(),name:s.z.string()}),Gd=s.z.object({key:s.z.string(),name:s.z.string()}),Zd=s.z.object({keys:s.z.array(s.z.string())});var Re;let Kd=(Re=class{constructor(t){l(this,"client"),this.client=t}async create(t,e,r){return(await v(this.client,Re.ENDPOINT,{parent:t,name:e,key:r},Vd,Wd)).group}async rename(t,e){await v(this.client,Re.ENDPOINT_RENAME,{key:t,name:e},Gd,s.z.object({}))}async delete(t){await v(this.client,Re.ENDPOINT_DELETE,{keys:t},Zd,s.z.object({}))}},l(Re,"ENDPOINT","/ontology/create-group"),l(Re,"ENDPOINT_RENAME","/ontology/rename-group"),l(Re,"ENDPOINT_DELETE","/ontology/delete-group"),Re),Jd=class{constructor(t){l(this,"creator"),this.creator=new Kd(t)}async create(t,e,r){return this.sugar(await this.creator.create(t,e,r))}async rename(t,e){return await this.creator.rename(t,e)}async delete(...t){return await this.creator.delete(t)}sugar(t){return new uo(t.name,t.key)}};const mn={ADD_CHILDREN:"/ontology/add-children",REMOVE_CHILDREN:"/ontology/remove-children",MOVE_CHILDREN:"/ontology/move-children"},bi=s.z.object({id:fe,children:fe.array()}),Hd=s.z.object({from:fe,to:fe,children:fe.array()});let Xd=class{constructor(t){l(this,"client"),this.client=t}async addChildren(t,...e){await v(this.client,mn.ADD_CHILDREN,{id:new $(t).payload,children:e.map(r=>new $(r).payload)},bi,s.z.object({}))}async removeChildren(t,...e){await v(this.client,mn.REMOVE_CHILDREN,{id:new $(t).payload,children:e.map(r=>new $(r).payload)},bi,s.z.object({}))}async moveChildren(t,e,...r){const n={from:new $(t).payload,to:new $(e).payload,children:r.map(i=>new $(i).payload)};await v(this.client,mn.MOVE_CHILDREN,n,Hd,s.z.object({}))}};const Qd="/ontology/retrieve",ef=s.z.object({ids:fe.array().optional(),children:s.z.boolean().optional(),parents:s.z.boolean().optional(),includeSchema:s.z.boolean().optional(),excludeFieldData:s.z.boolean().optional(),term:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),types:ls.array().optional()}),tf=s.z.object({resources:Fd.array()}),wn=t=>N(t).map(e=>new $(e).payload);let rf=class{constructor(t,e){l(this,"type","ontology"),l(this,"groups"),l(this,"client"),l(this,"writer"),l(this,"framer"),this.client=t,this.writer=new Xd(t),this.groups=new Jd(t),this.framer=e}async search(t,e){return await this.execRetrieve({term:t,...e})}async retrieve(t,e){const r=await this.execRetrieve({ids:wn(t),...e});if(Array.isArray(t))return r;if(r.length===0)throw new we(`No resource found with ID ${t.toString()}`);return r[0]}async page(t,e,r){return await this.execRetrieve({offset:t,limit:e,...r})}async retrieveChildren(t,e){return await this.execRetrieve({ids:wn(t),children:!0,...e})}async retrieveParents(t,e){return await this.execRetrieve({ids:wn(t),parents:!0,...e})}async addChildren(t,...e){return await this.writer.addChildren(t,...e)}async removeChildren(t,...e){return await this.writer.removeChildren(t,...e)}async moveChildren(t,e,...r){return await this.writer.moveChildren(t,e,...r)}async openChangeTracker(){return await Wr.open(this.framer,this)}async openDependentTracker(t){return await us.open(t,this.framer,this)}newSearcherWithOptions(t){return{type:this.type,search:e=>this.search(e,t),retrieve:e=>this.retrieve(e,t),page:(e,r)=>this.page(e,r,t)}}async execRetrieve(t){const{resources:e}=await v(this.client,Qd,t,ef,tf);return e}};const vi="sy_ontology_resource_set",Oi="sy_ontology_resource_delete",Ti="sy_ontology_relationship_set",Si="sy_ontology_relationship_delete";class Wr{constructor(e,r){l(this,"relationships"),l(this,"resources"),l(this,"resourceObs"),l(this,"relationshipObs"),l(this,"streamer"),l(this,"client"),l(this,"closePromise"),this.relationshipObs=new Ve.Observer,this.relationships=this.relationshipObs,this.resourceObs=new Ve.Observer,this.resources=this.resourceObs,this.client=r,this.streamer=e,this.closePromise=this.start()}async close(){this.streamer.close(),await this.closePromise}async start(){for await(const e of this.streamer)await this.update(e)}async update(e){const r=await this.parseResourceSets(e),n=this.parseResourceDeletes(e);r.concat(n).length>0&&this.resourceObs.notify(r.concat(n));const i=this.parseRelationshipSets(e),a=this.parseRelationshipDeletes(e);i.concat(a).length>0&&this.relationshipObs.notify(i.concat(a))}parseRelationshipSets(e){const r=e.get(Ti);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"set",key:wi(n),value:void 0}))}parseRelationshipDeletes(e){const r=e.get(Si);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"delete",key:wi(n)}))}async parseResourceSets(e){const r=e.get(vi);if(r.length===0)return[];const n=Array.from(r.as("string")).map(i=>new $(i));try{return(await this.client.retrieve(n)).map(i=>({variant:"set",key:i.id,value:i}))}catch(i){if(i instanceof we)return[];throw i}}parseResourceDeletes(e){const r=e.get(Oi);return r.length===0?[]:Array.from(r.as("string")).map(n=>({variant:"delete",key:new $(n)}))}static async open(e,r){const n=await e.openStreamer([vi,Oi,Ti,Si]);return new Wr(n,r)}}const zi=t=>t==="from"?"to":"from";class us extends Ve.Observer{constructor({target:e,dependents:r,relationshipType:n="parent",relationshipDirection:i="from",resourceType:a},o,c){super(),l(this,"internal"),l(this,"target"),l(this,"relDir"),l(this,"resourceType"),l(this,"dependents"),l(this,"client"),l(this,"relType"),l(this,"handleResourceChange",u=>{this.dependents=this.dependents.map(d=>{const f=u.find(h=>h.key.toString()==d.id.toString());return f==null||f.variant==="delete"?d:f.value}),this.notify(this.dependents)}),l(this,"handleRelationshipChange",u=>{const d=u.filter(h=>h.variant==="delete"&&h.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||h.key[zi(this.relDir)].type===this.resourceType));this.dependents=this.dependents.filter(h=>!d.some(j=>j.key.to.toString()===h.id.toString()&&j.key.type===this.relType));const f=u.filter(h=>h.variant==="set"&&h.key.type===this.relType&&h.key[this.relDir].toString()===this.target.toString()&&(this.resourceType==null||h.key[zi(this.relDir)].type===this.resourceType));if(f.length===0)return this.notify(this.dependents);this.client.retrieve(f.map(h=>h.key.to)).then(h=>{this.dependents=this.dependents.concat(h),this.notify(this.dependents)})}),this.resourceType=a,this.internal=o,this.target=e,this.dependents=r,this.resourceType!=null&&(this.dependents=this.dependents.filter(u=>u.id.type===this.resourceType)),this.client=c,this.relType=n,this.relDir=i,this.internal.resources.onChange(this.handleResourceChange),this.internal.relationships.onChange(this.handleRelationshipChange)}static async open(e,r,n){const i=await Wr.open(r,n);return new us(e,i,n)}async close(){await this.internal.close()}}const Be=s.z.number(),Lt=s.z.object({name:s.z.string(),key:s.z.number(),rate:os.z,dataType:E.z,leaseholder:s.z.number(),index:s.z.number(),isIndex:s.z.boolean(),internal:s.z.boolean(),virtual:s.z.boolean(),alias:s.z.string().optional()}),yo=Lt.extend({key:s.z.number().optional(),leaseholder:s.z.number().optional(),index:s.z.number().optional(),rate:os.z.optional().default(0),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional().default(!1),virtual:s.z.boolean().optional().default(!1)}),go="channel",nf=t=>new $({type:go,key:t.toString()}),sf=new Error("request for lock canceled");var af=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class of{constructor(e,r=sf){this._value=e,this._cancelError=r,this._queue=[],this._weightedWaiters=[]}acquire(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:r},o=po(this._queue,c=>r<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return af(this,arguments,void 0,function*(r,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield r(a)}finally{o()}})}waitForUnlock(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,r)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),cf(this._weightedWaiters[e-1],{resolve:n,priority:r})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const r=this._value;this._value-=e.weight,e.resolve([r,this._newReleaser(e.weight)])}_newReleaser(e){let r=!1;return()=>{r||(r=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const r=this._weightedWaiters[e-1];r&&(r.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let r=this._value;r>0;r--){const n=this._weightedWaiters[r-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,r){return(this._queue.length===0||this._queue[0].priority<r)&&e<=this._value}}function cf(t,e){const r=po(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function po(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var lf=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class uf{constructor(e){this._semaphore=new of(1,e)}acquire(){return lf(this,arguments,void 0,function*(e=0){const[,r]=yield this._semaphore.acquire(1,e);return r})}runExclusive(e,r=0){return this._semaphore.runExclusive(()=>e(),1,r)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}const Vr=(t,e,{convertNumericStrings:r=!0}={})=>{const n=!Array.isArray(t);let i=N(t);const a=i[0],o=typeof a;let c;return o==="string"&&r&&!isNaN(parseInt(a))&&"number"in e?(c=e.number,i=i.map(u=>parseInt(u))):c=e[o],{single:n,variant:c,normalized:i,actual:t}},Gr=(t,e,r,n)=>{if(n){if(r.length===0)throw new Rr(`${t} not found matching ${JSON.stringify(e)}`);if(r.length>1)throw new Mr(`Expected one ${t} matching ${JSON.stringify(e)}, but found ${r.length}`)}},Ue=t=>s.z.union([s.z.null().transform(()=>[]),t.array()]),hf=s.z.object({leaseholder:s.z.number().optional(),keys:s.z.number().array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),rangeKey:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),dataTypes:E.z.array().optional(),notDataTypes:E.z.array().optional(),virtual:s.z.boolean().optional(),isIndex:s.z.boolean().optional(),internal:s.z.boolean().optional()}),df=s.z.object({channels:Ue(Lt)}),je=t=>Vr(t,{number:"keys",string:"names"}),mo=class wo{constructor(e){l(this,"client"),this.client=e}async search(e,r){return await this.execute({search:e,...r})}async retrieve(e,r){const n=je(e),{variant:i}=n;let{normalized:a}=n;return i==="keys"&&a.indexOf(0)!==-1&&(a=a.filter(o=>o!==0)),a.length===0?[]:await this.execute({[i]:a,...r})}async page(e,r,n){return await this.execute({offset:e,limit:r,...n})}async execute(e){const[r,n]=await this.client.send(wo.ENDPOINT,e,hf,df);if(n!=null)throw n;return r.channels}};l(mo,"ENDPOINT","/channel/retrieve");let hs=mo;class ds{constructor(e){l(this,"cache"),l(this,"namesToKeys"),l(this,"wrapped"),this.cache=new Map,this.namesToKeys=new Map,this.wrapped=e}async search(e,r){return await this.wrapped.search(e,r)}async page(e,r,n){return await this.wrapped.page(e,r,n)}async retrieve(e,r){const{normalized:n}=Vr(e,{string:"names",number:"keys"}),i=[],a=[];if(n.forEach(c=>{const u=this.get(c);u!=null?i.push(...u):a.push(c)}),a.length===0)return i;const o=await this.wrapped.retrieve(a,r);return this.set(o),i.concat(o)}delete(e){const{variant:r,normalized:n}=je(e);r==="names"?n.forEach(i=>{const a=this.namesToKeys.get(i);a!=null&&(a.forEach(o=>this.cache.delete(o)),this.namesToKeys.delete(i))}):n.forEach(i=>{const a=this.cache.get(i);a!=null&&(this.cache.delete(i),this.namesToKeys.delete(a.name))})}rename(e,r){e.forEach((n,i)=>{const a=r[i],o=this.cache.get(n);if(o==null)return;this.cache.delete(n);const c=this.namesToKeys.get(o.name);c!=null&&(c.delete(n),c.size===0&&this.namesToKeys.delete(o.name)),o.name=a,this.cache.set(n,o);const u=this.namesToKeys.get(a);u==null?this.namesToKeys.set(a,new Set([n])):u.add(n)})}set(e){e.forEach(r=>{this.cache.set(r.key,r);const n=this.namesToKeys.get(r.name);n==null?this.namesToKeys.set(r.name,new Set([r.key])):n.add(r.key)})}get(e){if(typeof e=="number"){const i=this.cache.get(e);return i==null?void 0:[i]}const r=this.namesToKeys.get(e);if(r==null)return;const n=[];if(r.forEach(i=>{const a=this.cache.get(i);a!=null&&n.push(a)}),n.length!==0)return n}}class bo{constructor(e,r){l(this,"mu",new uf),l(this,"requests",new Map),l(this,"wrapped"),l(this,"debouncedRun"),this.wrapped=e,this.debouncedRun=gd(()=>{this.run()},r)}async search(e,r){return await this.wrapped.search(e,r)}async page(e,r,n){return await this.wrapped.page(e,r,n)}async retrieve(e){const{normalized:r,variant:n}=je(e);return n==="names"?await this.wrapped.retrieve(r):await new Promise((i,a)=>{this.mu.runExclusive(()=>{this.requests.set(r,{resolve:i,reject:a}),this.debouncedRun()})})}async run(){await this.mu.runExclusive(async()=>{const e=new Set;this.requests.forEach((r,n)=>n.forEach(i=>e.add(i)));try{const r=await this.wrapped.retrieve(Array.from(e));this.requests.forEach((n,i)=>n.resolve(r.filter(a=>i.includes(a.key))))}catch(r){this.requests.forEach(n=>n.reject(r))}finally{this.requests.clear()}})}}const vo=async(t,e)=>{const{normalized:r}=je(e),n=await t.retrieve(r),i=[];if(r.forEach(a=>{n.find(o=>o.name===a||o.key===a)==null&&i.push(a)}),i.length>0)throw new we(`Could not find channels: ${JSON.stringify(i)}`);return n};class Oo{constructor({dataType:e,rate:r,name:n,leaseholder:i=0,key:a=0,isIndex:o=!1,index:c=0,internal:u=!1,virtual:d=!1,frameClient:f,alias:h}){l(this,"_frameClient"),l(this,"key"),l(this,"name"),l(this,"rate"),l(this,"dataType"),l(this,"leaseholder"),l(this,"index"),l(this,"isIndex"),l(this,"internal"),l(this,"alias"),l(this,"virtual"),this.key=a,this.name=n,this.rate=new os(r??0),this.dataType=new E(e),this.leaseholder=i,this.index=c,this.isIndex=o,this.internal=u,this.alias=h,this.virtual=d,this._frameClient=f??null}get framer(){if(this._frameClient==null)throw new G("cannot read from a channel that has not been created");return this._frameClient}get payload(){return Lt.parse({key:this.key,name:this.name,rate:this.rate.valueOf(),dataType:this.dataType.valueOf(),leaseholder:this.leaseholder,index:this.index,isIndex:this.isIndex,internal:this.internal})}get ontologyID(){return new $({type:"channel",key:this.key.toString()})}async read(e){return await this.framer.read(e,this.key)}async write(e,r){return await this.framer.write(e,this.key,r)}}const ff="/channel/retrieve-group",yf=s.z.object({}),gf=s.z.object({group:ho});let To=class{constructor(t,e,r,n){l(this,"type","channel"),l(this,"frameClient"),l(this,"client"),l(this,"retriever"),l(this,"writer"),this.frameClient=t,this.retriever=e,this.client=r,this.writer=n}async create(t,e={}){const{retrieveIfNameExists:r=!1}=e,n=!Array.isArray(t);let i=N(t),a=[];if(r){const o=await this.retriever.retrieve(i.map(u=>u.name)),c=new Set(o.map(u=>u.name));i=i.filter(u=>!c.has(u.name)),a=this.sugar(o)}return a=a.concat(this.sugar(await this.writer.create(i))),n?a[0]:a}async retrieve(t,e){const r=!Array.isArray(t),n=this.sugar(await this.retriever.retrieve(t,e));return Gr("channel",t,n,r),r?n[0]:n}async search(t,e){return this.sugar(await this.retriever.search(t,e))}async delete(t){const{normalized:e,variant:r}=je(t);return r==="keys"?await this.writer.delete({keys:e}):await this.writer.delete({names:e})}async rename(t,e){return await this.writer.rename(N(t),N(e))}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,r)=>await this.page(e,r,t)}}async page(t,e,r){return this.sugar(await this.retriever.page(t,e,r))}createDebouncedBatchRetriever(t=10){return new ds(new bo(new hs(this.client),t))}sugar(t){const{frameClient:e}=this;return t.map(r=>new Oo({...r,frameClient:e}))}async retrieveGroup(){const t=await v(this.client,ff,{},yf,gf);return new uo(t.group.name,t.group.key)}};const pf=s.z.object({channels:yo.array()}),mf=s.z.object({channels:Lt.array()}),wf=s.z.object({keys:Be.array().optional(),names:s.z.string().array().optional()}),bf=s.z.object({}),vf=s.z.object({keys:Be.array(),names:s.z.string().array()}),Of=s.z.object({}),Tf="/channel/create",Sf="/channel/delete",zf="/channel/rename";let So=class{constructor(t,e){l(this,"client"),l(this,"cache"),this.client=t,this.cache=e}async create(t){const{channels:e}=await v(this.client,Tf,{channels:t},pf,mf);return this.cache.set(e),e}async delete(t){await v(this.client,Sf,t,wf,bf),t.keys!=null&&this.cache.delete(t.keys),t.names!=null&&this.cache.delete(t.names)}async rename(t,e){await v(this.client,zf,{keys:t,names:e},vf,Of),this.cache.rename(t,e)}};const Nf=Object.freeze(Object.defineProperty({__proto__:null,CacheRetriever:ds,Channel:Oo,ChannelOntologyType:go,Client:To,ClusterRetriever:hs,DebouncedBatchRetriever:bo,Writer:So,analyzeChannelParams:je,keyZ:Be,newPayload:yo,ontologyID:nf,payload:Lt,retrieveRequired:vo},Symbol.toStringTag,{value:"Module"})),fs=s.z.string().uuid(),ys=s.z.object({key:fs,subjects:fe.array(),objects:fe.array(),actions:s.z.string().array()}),Ef=ys.extend({key:fs.optional()}),If="/access/policy/create",kf="/access/policy/delete",Af="/access/policy/retrieve",xf=s.z.object({policies:Ef.array()}),Cf=s.z.object({policies:ys.array()}),$f=s.z.object({keys:fs.array()}),jf=s.z.object({}),Rf=s.z.object({subject:fe}),Mf=s.z.object({policies:ys.array().optional().default([])});let Df=class{constructor(t){l(this,"client"),this.client=t}async create(t){const e=!Array.isArray(t),{policies:r}=await v(this.client,If,{policies:N(t)},xf,Cf);return e?r[0]:r}async retrieve(t){const{policies:e}=await v(this.client,Af,{subject:t},Rf,Mf);return e}async delete(t){await v(this.client,kf,{keys:N(t)},$f,jf)}};const Pf="/user/register";let Bf=class{constructor(t){l(this,"client"),this.client=t}async register(t,e){const{user:r}=await v(this.client,Pf,{username:t,password:e},zo,No);return r}};s.z.string().uuid();const Uf=s.z.object({key:s.z.string(),username:s.z.string()}),zo=s.z.object({username:s.z.string(),password:s.z.string()}),No=s.z.object({token:s.z.string(),user:Uf}),Ni="/auth/login",Lf=3;let Yf=class{constructor(t,e){l(this,"token"),l(this,"client"),l(this,"credentials"),l(this,"authenticating"),l(this,"authenticated"),l(this,"user"),l(this,"retryCount"),this.client=t,this.authenticated=!1,this.credentials=e,this.retryCount=0}middleware(){const t=async(e,r)=>{if(!this.authenticated&&!e.target.endsWith(Ni)){this.authenticating==null&&(this.authenticating=new Promise((o,c)=>{this.client.send(Ni,this.credentials,zo,No).then(([u,d])=>{if(d!=null)return o(d);this.token=u==null?void 0:u.token,this.user=u==null?void 0:u.user,this.authenticated=!0,o(null)}).catch(c)}));const a=await this.authenticating;if(a!=null)return[e,a]}e.params.Authorization=`Bearer ${this.token}`;const[n,i]=await r(e);return _n.matches(i)&&this.retryCount<Lf?(this.authenticated=!1,this.authenticating=void 0,this.retryCount+=1,t(e,r)):(this.retryCount=0,[n,i])};return t}};const qf=["disconnected","connecting","connected","failed"],_f=s.z.enum(qf),Ff=s.z.object({status:_f,error:s.z.instanceof(Error).optional(),message:s.z.string().optional(),clusterKey:s.z.string(),clientVersion:s.z.string(),clientServerCompatible:s.z.boolean(),nodeVersion:s.z.string().optional()}),Wf=s.z.object({clusterKey:s.z.string(),nodeVersion:s.z.string().optional()}),Eo={clusterKey:"",status:"disconnected",error:void 0,message:"Disconnected",clientServerCompatible:!1,clientVersion:"0.30.0"},Ei=(t,e,r)=>{const n=r?"cluster":"client";return`Synnax cluster node version ${t!=null?t+" ":""}is too ${r?"old":"new"} for client version ${e}.
38
- This may cause compatibility issues. We recommend updating the ${n}. For more information, see
39
- https://docs.synnaxlabs.com/reference/typescript-client/troubleshooting#old-${n}-version`},Ir=class Io{constructor(e,r=I.seconds(30),n,i){l(this,"_state"),l(this,"pollFrequency",I.seconds(30)),l(this,"client"),l(this,"name"),l(this,"interval"),l(this,"clientVersion"),l(this,"onChangeHandlers",[]),l(this,"versionWarned",!1),this._state={...Eo},this.client=e,this.pollFrequency=r,this.clientVersion=n,this.name=i,this.check(),this.startChecking()}stopChecking(){this.interval!=null&&clearInterval(this.interval)}async check(){var e;const r=this._state.status;try{const[n,i]=await this.client.send(Io.ENDPOINT,{},s.z.object({}),Wf);if(i!=null)throw i;const a=n.nodeVersion,o=this.clientVersion,c=this.versionWarned;a==null?(this._state.clientServerCompatible=!1,c||(console.warn(Ei(null,o,!0)),this.versionWarned=!0)):yi.versionsEqual(o,a,{checkMajor:!0,checkMinor:!0,checkPatch:!1})?this._state.clientServerCompatible=!0:(this._state.clientServerCompatible=!1,c||(console.warn(Ei(a,o,yi.semVerNewer(o,a))),this.versionWarned=!0)),this._state.status="connected",this._state.message=`Connected to ${this.name??"cluster"}`,this._state.clusterKey=n.clusterKey,this._state.nodeVersion=n.nodeVersion,this._state.clientVersion=this.clientVersion}catch(n){this._state.status="failed",this._state.error=n,this._state.message=(e=this.state.error)==null?void 0:e.message}return this.onChangeHandlers.length>0&&r!==this._state.status&&this.onChangeHandlers.forEach(n=>n(this.state)),this.state}get state(){return{...this._state}}onChange(e){this.onChangeHandlers.push(e)}startChecking(){this.interval=setInterval(()=>{this.check()},this.pollFrequency.milliseconds)}};l(Ir,"ENDPOINT","/connectivity/check"),l(Ir,"DEFAULT",Eo),l(Ir,"connectionStateZ",Ff);let ko=Ir;const Vf=s.z.object({keys:Be.array().optional(),bounds:ne.z,names:s.z.string().array().optional()}),Gf=s.z.object({}),Zf="/frame/delete";class Kf{constructor(e){l(this,"client"),this.client=e}async delete(e){await v(this.client,Zf,e,Vf,Gf)}}const Ii=t=>{const e=N(t);return e.length===0?null:typeof e[0]=="number"||!isNaN(parseInt(e[0]))?"key":"name"},ki=(t,e)=>{const r=N(t);if(r.length===e.length)return;const n=Ii(t);throw Ii===null?new G("[Frame] - channel keys or names must be provided when constructing a frame."):new G(`[Frame] - ${n}s and series must be the same length.
40
- Got ${r.length} ${n}s and ${e.length} series.`)};let me=class Ke{constructor(e=[],r=[]){if(l(this,"columns",[]),l(this,"series",[]),e instanceof Ke){this.columns=e.columns,this.series=e.series;return}if(e instanceof Map){e.forEach((n,i)=>this.push(i,...N(n)));return}if(typeof e=="object"&&!Array.isArray(e)){if("keys"in e&&"series"in e){const n=e,i=n.series.map(a=>Hf(a));ki(n.keys,i),n.keys.forEach((a,o)=>this.push(a,i[o]))}else Object.entries(e).forEach(([n,i])=>{const a=parseInt(n);if(isNaN(a))this.push(n,...N(i));else return this.push(a,...N(i))});return}if(Array.isArray(e)||["string","number"].includes(typeof e)){const n=N(r),i=N(e);ki(i,n),n.forEach((a,o)=>this.push(i[o],a));return}throw new G(`[Frame] - invalid frame construction parameters. data parameter ust be a frame
41
- payload, a list of lazy series, a lazy array, a map, or a record keyed by channel
42
- name. keys parameter must be a set of channel keys or channel names.`)}get colType(){return this.columns.length===0?null:typeof this.columns[0]=="string"?"name":"key"}get keys(){if(this.colType==="name")throw new pe("colType is not key");return this.columns??[]}get uniqueKeys(){return fi(this.keys)}get names(){if(this.colType==="key")throw new pe("colType is not name");return this.columns??[]}get uniqueNames(){return fi(this.names)}get uniqueColumns(){return this.colType==="key"?this.uniqueKeys:this.uniqueNames}toPayload(){return{series:this.series.map(e=>Xf(e)),keys:this.keys}}get isVertical(){return this.uniqueColumns.length===this.columns.length}get isHorizontal(){return this.uniqueColumns.length===1}get isSquare(){return this.isHorizontal&&this.isVertical}get isWeaklyAligned(){if(this.columns.length<=1)return!0;const e=this.timeRanges;return e.every(r=>r.equals(e[0]))}timeRange(e){if(e==null){if(this.columns.length===0)return ne.ZERO;const n=k.min(...this.series.map(a=>a.timeRange.start)),i=k.max(...this.series.map(a=>a.timeRange.end));return new ne(n,i)}const r=this.get(e);return r==null?ne.ZERO:r.timeRange}latest(){return this.at(-1)}get timeRanges(){return this.uniqueColumns.map(e=>this.timeRange(e))}get(e){return Array.isArray(e)?this.filter(r=>e.includes(r)):new fd(this.series.filter((r,n)=>this.columns[n]===e))}push(e,...r){if(e instanceof Ke){if(this.colType!==null&&e.colType!==this.colType)throw new G("keyVariant must match");this.series.push(...e.series),this.columns.push(...e.columns)}else{if(this.series.push(...r),typeof e=="string"&&this.colType==="key")throw new G("keyVariant must match");if(typeof e!="string"&&this.colType==="name")throw new G("keyVariant must match");this.columns.push(...Array.from({length:r.length},()=>e))}}concat(e){return new Ke([...this.columns,...e.columns],[...this.series,...e.series])}has(e){return typeof e=="string"&&this.colType==="key"||typeof e=="number"&&this.colType==="name"?!1:this.columns.includes(e)}map(e){const r=new Ke;return this.forEach((n,i,a)=>r.push(...e(n,i,a))),r}forEach(e){this.columns.forEach((r,n)=>{const i=this.series[n];e(r,i,n)})}at(e,r=!1){const n={};return this.uniqueColumns.forEach(i=>{n[i]=this.get(i).at(e,r)}),n}filter(e){const r=new Ke;return this.columns.forEach((n,i)=>{const a=this.series[i];e(n,a,i)&&r.push(n,a)}),r}get byteLength(){return new At(this.series.reduce((e,r)=>e.add(r.byteLength),At.ZERO))}get length(){return this.series.reduce((e,r)=>e+r.length,0)}};const Jf=s.z.object({timeRange:ne.z.optional(),alignment:s.z.bigint().or(s.z.string().transform(t=>BigInt(t))).optional(),dataType:E.z,data:s.z.string().transform(t=>new Uint8Array(atob(t).split("").map(e=>e.charCodeAt(0))).buffer)}),gs=s.z.object({keys:s.z.union([s.z.null().transform(()=>[]),s.z.number().array().optional().default([])]),series:s.z.union([s.z.null().transform(()=>[]),Jf.array().optional().default([])])}),Hf=t=>{const{dataType:e,data:r,timeRange:n,alignment:i}=t;return new Je({data:r,dataType:e,timeRange:n,glBufferUsage:"static",alignment:i})},Xf=t=>({timeRange:t._timeRange,dataType:t.dataType,data:new Uint8Array(t.data.buffer),alignment:t.alignment});class Zr{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,r){const n=new Zr(e);return await n.update(r),n}async update(e){const{variant:r,normalized:n}=je(e);if(r==="keys"){this.adapter=null,this.keys=n;return}const i=await this.retriever.retrieve(n),a=new Map;this.adapter=a,n.forEach(o=>{const c=i.find(u=>u.name===o);if(c==null)throw new Error(`Channel ${o} not found`);a.set(c.key,c.name)}),this.keys=Array.from(this.adapter.keys())}adapt(e){if(this.adapter==null)return e;const r=this.adapter;return e.map((n,i)=>{if(typeof n=="number"){const a=r.get(n);if(a==null)throw new Error(`Channel ${n} not found`);return[a,i]}return[n,i]})}}class ps{constructor(e){l(this,"adapter"),l(this,"retriever"),l(this,"keys"),this.retriever=e,this.adapter=null,this.keys=[]}static async open(e,r){const n=new ps(e);return await n.update(r),n}async adaptObjectKeys(e){const r={};for(const[n,i]of Object.entries(e))r[await this.adaptToKey(n)]=i;return r}async update(e){const r=await vo(this.retriever,e);this.adapter=new Map(r.map(n=>[n.name,n.key])),this.keys=r.map(n=>n.key)}async fetchChannel(e){const r=await this.retriever.retrieve(e);if(r.length===0)throw new Error(`Channel ${e} not found`);return r[0]}async adaptToKey(e){return typeof e=="number"?e:(await this.fetchChannel(e)).key}async adapt(e,r){if(typeof e=="string"||typeof e=="number"){if(r==null)throw new G(`
43
- Received a single channel name or key but no series.
44
- `);if(Array.isArray(r)){if(r.some(u=>u instanceof Je||Array.isArray(u)))throw new G(`
45
- Received a single channel name or key but multiple series.
46
- `);r=r}const o=await this.fetchChannel(e),c=new Je({data:r,dataType:o.dataType});return new me(o.key,c)}if(Array.isArray(e)){if(r==null)throw new G(`
47
- Received an array of channel names or keys but no series.
48
- `);if(!Array.isArray(r))throw new G(`
49
- Received an array of channel names or keys but no array of series.
50
- `);const o=[],c=[];for(let u=0;u<e.length;u++){const d=await this.fetchChannel(e[u]);if(u>=r.length)throw new G(`
51
- Received an array of channel names or keys but not enough series.
52
- `);const f=new Je({data:r[u],dataType:d.dataType});o.push(d.key),c.push(f)}return new me(o,c)}if(e instanceof me||e instanceof Map){const o=new me(e);if(this.adapter==null)return o;let c=[];return c=o.columns.map(u=>{var d;const f=typeof u=="string"?(d=this.adapter)==null?void 0:d.get(u):u;if(f==null)throw new G(`
53
- Channel ${u} was not provided in the list of channels when opening the writer
54
- `);return f}),new me(c,o.series)}const n=[],i=[],a=Object.entries(e);for(let o=0;o<a.length;o++){const[c,u]=a[o],d=await this.fetchChannel(c),f=new Je({data:u,dataType:d.dataType});n.push(d.key),i.push(f)}return new me(n,i)}}class ms{constructor(e,r){l(this,"name"),l(this,"stream"),this.stream=r,this.name=e}async receive(){const[e,r]=await this.stream.receive();if(r!=null)throw r;return e}received(){return this.stream.received()}async closeAndAck(){for(this.stream.closeSend();;){const[e,r]=await this.stream.receive();if(e!=null&&console.warn(`${this.name} received unexpected response on closure.
55
- Please report this error to the Synnax team. ${JSON.stringify(e)}`),r!=null){if(De.matches(r))return;throw r}}}closeSend(){this.stream.closeSend()}send(e){const r=this.stream.send(e);if(r!=null)throw r}}const Ai=new I(-1);var ws=(t=>(t[t.Open=0]="Open",t[t.Next=1]="Next",t[t.Prev=2]="Prev",t[t.SeekFirst=3]="SeekFirst",t[t.SeekLast=4]="SeekLast",t[t.SeekLE=5]="SeekLE",t[t.SeekGE=6]="SeekGE",t[t.Valid=7]="Valid",t[t.Error=8]="Error",t))(ws||{}),Ao=(t=>(t[t.None=0]="None",t[t.Ack=1]="Ack",t[t.Data=2]="Data",t))(Ao||{});const Qf=s.z.object({command:s.z.nativeEnum(ws),span:I.z.optional(),bounds:ne.z.optional(),stamp:k.z.optional(),keys:s.z.number().array().optional(),chunkSize:s.z.number().optional()}),ey=s.z.object({variant:s.z.nativeEnum(Ao),ack:s.z.boolean(),command:s.z.nativeEnum(ws),error:Bt.optional().nullable(),frame:gs.optional()}),xo=class Fn{constructor(e,r){l(this,"stream"),l(this,"adapter"),l(this,"value"),this.stream=new ms("Iterator",e),this.value=new me,this.adapter=r}static async _open(e,r,n,i,a={}){const o=await Zr.open(n,r),c=await i.stream(Fn.ENDPOINT,Qf,ey),u=new Fn(c,o);return await u.execute({command:0,keys:o.keys,bounds:new ne(e),chunkSize:a.chunkSize??1e5}),u}async next(e=Ai){return await this.execute({command:1,span:new I(e)})}async prev(e=Ai){return await this.execute({command:2,span:new I(e)})}async seekFirst(){return await this.execute({command:3})}async seekLast(){return await this.execute({command:4})}async seekLE(e){return await this.execute({command:5,stamp:new k(e)})}async seekGE(e){return await this.execute({command:6,stamp:new k(e)})}async valid(){return await this.execute({command:7})}async close(){await this.stream.closeAndAck()}[Symbol.asyncIterator](){return new ry(this)}async execute(e){for(this.stream.send(e),this.value=new me;;){const r=await this.stream.receive();if(r.variant===1)return r.ack;this.value.push(this.adapter.adapt(new me(r.frame)))}}};l(xo,"ENDPOINT","/frame/iterate");let ty=xo;class ry{constructor(e){l(this,"iter"),l(this,"open",!1),this.iter=e}async next(){try{let e=!0;return this.open||(await this.iter.seekFirst()||(e=!1),this.open=!0),await this.iter.next()||(e=!1),e||await this.iter.close(),{done:!e,value:this.iter.value}}catch(e){throw await this.iter.close(),e}}}const ny=s.z.object({keys:s.z.number().array()}),sy=s.z.object({frame:gs,error:Bt.optional().nullable()}),iy="/frame/stream";class bs{constructor(e,r){l(this,"stream"),l(this,"adapter"),this.stream=new ms("Streamer",e),this.adapter=r}get keys(){return this.adapter.keys}static async _open(e,r,{channels:n}){const i=await Zr.open(e,n),a=await r.stream(iy,ny,sy),o=new bs(a,i);a.send({keys:i.keys});const[,c]=await a.receive();if(c!=null)throw c;return o}async next(){try{return{done:!1,value:await this.read()}}catch(e){if(De.matches(e))return{done:!0,value:void 0};throw e}}async read(){return this.adapter.adapt(new me((await this.stream.receive()).frame))}async update(e){await this.adapter.update(e),this.stream.send({keys:this.adapter.keys})}close(){this.stream.closeSend()}[Symbol.asyncIterator](){return this}}class Kr extends Ve.Observer{constructor(e,r){super(r),l(this,"streamer"),l(this,"closePromise"),this.streamer=e,this.closePromise=this.stream()}async close(){this.streamer.close(),await this.closePromise}async stream(){for await(const e of this.streamer)this.notify(e)}}var vs=(t=>(t[t.Open=0]="Open",t[t.Write=1]="Write",t[t.Commit=2]="Commit",t[t.Error=3]="Error",t[t.SetAuthority=4]="SetAuthority",t))(vs||{}),xt=(t=>(t[t.PersistStream=1]="PersistStream",t[t.Persist=2]="Persist",t[t.Stream=3]="Stream",t))(xt||{});const ay=t=>{switch(t){case"persist":return 2;case"stream":return 3;case"persistStream":return 1;default:if(typeof t=="number"&&t in xt)return t;throw new Error(`invalid writer mode: ${t}`)}};new I(-1);const oy=s.z.object({start:k.z.optional(),controlSubject:Qe.subjectZ.optional(),keys:s.z.number().array().optional(),authorities:Qe.Authority.z.array().optional(),mode:s.z.nativeEnum(xt).optional(),errOnUnauthorized:s.z.boolean().optional(),enableAutoCommit:s.z.boolean().optional(),autoIndexPersistInterval:I.z.optional()}),cy=s.z.object({command:s.z.nativeEnum(vs),config:oy.optional(),frame:gs.optional()}),ly=s.z.object({ack:s.z.boolean(),command:s.z.nativeEnum(vs),error:Bt.optional().nullable()});var it;let uy=(it=class{constructor(t,e){l(this,"stream"),l(this,"adapter"),this.stream=new ms("Writer",t),this.adapter=e}static async _open(t,e,{channels:r,start:n=k.now(),authorities:i=Qe.Authority.Absolute,controlSubject:a,mode:o=1,errOnUnauthorized:c=!1,enableAutoCommit:u=!1,autoIndexPersistInterval:d=I.SECOND}){const f=await ps.open(t,r),h=await e.stream(it.ENDPOINT,cy,ly),j=new it(h,f);return await j.execute({command:0,config:{start:new k(n),keys:f.keys,controlSubject:a,authorities:N(i),mode:ay(o),errOnUnauthorized:c,enableAutoCommit:u,autoIndexPersistInterval:d}}),j}async write(t,e){const r=await this.adapter.adapt(t,e);return this.stream.send({command:1,frame:r.toPayload()}),!0}async setAuthority(t,e){let r={keys:[],authorities:[]};if(typeof t=="number"&&e==null)r={keys:[],authorities:[t]};else{let n;typeof t=="string"||typeof t=="number"?n={[t]:e}:n=t,n=await this.adapter.adaptObjectKeys(n),r={keys:Object.keys(n).map(i=>Number(i)),authorities:Object.values(n)}}return(await this.execute({command:4,config:r})).ack}async commit(){return this.errorAccumulated?!1:(await this.execute({command:2})).ack}async error(){this.stream.send({command:3});const t=await this.execute({command:3});return t.error!=null?ss(t.error):null}async close(){await this.stream.closeAndAck()}async execute(t){for(this.stream.send(t);;){const e=await this.stream.receive();if(e.command===t.command)return e;console.warn("writer received unexpected response",e)}}get errorAccumulated(){return this.stream.received()}},l(it,"ENDPOINT","/frame/write"),it),hy=class{constructor(t,e,r){l(this,"streamClient"),l(this,"retriever"),l(this,"deleter"),this.streamClient=t,this.retriever=r,this.deleter=new Kf(e)}async openIterator(t,e,r){return await ty._open(t,e,this.retriever,this.streamClient,r)}async openWriter(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await uy._open(this.retriever,this.streamClient,t)}async openStreamer(t){return(Array.isArray(t)||typeof t!="object")&&(t={channels:t}),await bs._open(this.retriever,this.streamClient,t)}async write(t,e,r){if(r==null){const i=e,a=await this.openWriter({start:t,channels:Object.keys(i),mode:xt.Persist});try{await a.write(i),await a.commit()}finally{await a.close()}return}const n=await this.openWriter({start:t,channels:e,mode:xt.Persist,errOnUnauthorized:!0,enableAutoCommit:!0,autoIndexPersistInterval:I.MAX});try{await n.write(e,r)}finally{await n.close()}}async read(t,e){const{single:r}=je(e),n=await this.readFrame(t,e);return r?n.get(e):n}async readFrame(t,e){const r=await this.openIterator(t,e),n=new me;try{for await(const i of r)n.push(i)}finally{await r.close()}return n}async delete(t,e){const{normalized:r,variant:n}=je(t);return n==="keys"?await this.deleter.delete({keys:r,bounds:e}):await this.deleter.delete({names:r,bounds:e})}};const dy=Qe.Authority,fy=Qe.stateZ(s.z.number()),yy=t=>{var e,r;return t.to==null?`${(e=t.from)==null?void 0:e.resource} - ${(r=t.from)==null?void 0:r.subject.name} -> released`:t.from==null?`${t.to.resource} - released -> ${t.to.subject.name} (${t.to.authority.toString()})`:`${t.to.resource} - ${t.from.subject.name} -> ${t.to.subject.name} (${t.to.authority.toString()})`};class Co extends Kr{constructor(e){super(e,r=>{const n=this.codec.decode(r.series[0].buffer);return this.merge(n),[n.transfers,!0]}),l(this,"states"),l(this,"codec"),this.states=new Map,this.codec=new et.JSONCodec}subjects(){const e=new Map;return this.states.forEach(r=>e.set(r.subject.key,r.subject)),Array.from(e.values())}merge(e){e.transfers.forEach(r=>{r.from==null&&r.to==null&&console.warn("Invalid transfer: ",r),r.to==null?this.states.delete(r.from.resource):this.states.set(r.to.resource,r.to)})}}const gy="sy_node_1_control";let $o=class{constructor(t){l(this,"framer"),this.framer=t}async openStateTracker(){const t=await this.framer.openStreamer(gy);return new Co(t)}};const py=Object.freeze(Object.defineProperty({__proto__:null,Authority:dy,Client:$o,StateTracker:Co,stateZ:fy,transferString:yy},Symbol.toStringTag,{value:"Module"}));let my=class{constructor(t,e,r){l(this,"tasks"),l(this,"racks"),l(this,"devices"),this.tasks=t,this.racks=e,this.devices=r}};const Yt=s.z.number(),Os=s.z.object({key:Yt,name:s.z.string()}),wy=Os.partial({key:!0}),Ts=s.z.string(),Jr=s.z.object({key:Ts,rack:Yt,name:s.z.string(),make:s.z.string(),model:s.z.string(),location:s.z.string(),configured:s.z.boolean().optional(),properties:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:et.JSON_CODEC.decodeString(t)))}),by=Jr.extend({properties:s.z.unknown().transform(t=>et.JSON_CODEC.encodeString(t))}),tt=async(t,e,r,n)=>{const i=await t.openStreamer([e,r]),a=o=>{const c=[];return r!=null&&c.push(...o.get(r).series.flatMap(u=>n("delete",u))),e!=null&&c.push(...o.get(e).series.flatMap(u=>n("set",u))),[c,c.length>0]};return new Kr(i,a)},vy="sy_device_set",Oy="sy_device_delete",bn="/hardware/device/retrieve",Ty="/hardware/device/create",Sy="/hardware/device/delete",zy=s.z.object({devices:by.array()}),Ny=s.z.object({devices:Jr.array()}),Ey=s.z.object({keys:Ts.array()}),Iy=s.z.object({}),vn=s.z.object({search:s.z.string().optional(),limit:s.z.number().optional(),offset:s.z.number().optional(),keys:Ts.array().optional(),names:s.z.string().array().optional(),makes:s.z.string().array().optional()}),On=s.z.object({devices:Ue(Jr)});let ky=class{constructor(t,e){l(this,"type","device"),l(this,"client"),l(this,"frameClient"),this.client=t,this.frameClient=e}async retrieve(t,e){const r=!Array.isArray(t),n=await v(this.client,bn,{keys:N(t),...e},vn,On);return Gr("Device",t,n.devices,r),r?n.devices[0]:n.devices}async search(t,e){return(await v(this.client,bn,{search:t,...e},vn,On)).devices}async page(t,e,r){return(await v(this.client,bn,{offset:t,limit:e,...r},vn,On)).devices}async create(t){const e=!Array.isArray(t),r=await v(this.client,Ty,{devices:N(t)},zy,Ny);return e?r.devices[0]:r.devices}async delete(t){await v(this.client,Sy,{keys:N(t)},Ey,Iy)}async openDeviceTracker(){return await tt(this.frameClient,vy,Oy,Ay)}newSearcherWithOptions(t){return{type:this.type,search:async e=>await this.search(e,t),retrieve:async e=>await this.retrieve(e,t),page:async(e,r)=>await this.page(e,r,t)}}};const Ay=(t,e)=>t==="delete"?e.toStrings().map(r=>({variant:t,key:r,value:void 0})):e.parseJSON(Jr).map(r=>({variant:t,key:r.key,value:r})),Tn="/hardware/rack/retrieve",xy="/hardware/rack/create",Cy="/hardware/rack/delete",Sn=s.z.object({keys:Yt.array().optional(),names:s.z.string().array().optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),zn=s.z.object({racks:Ue(Os)}),$y=s.z.object({racks:wy.array()}),jy=s.z.object({racks:Os.array()}),Ry=s.z.object({keys:Yt.array()}),My=s.z.object({});let Dy=class{constructor(t,e,r){l(this,"type","rack"),l(this,"client"),l(this,"frameClient"),l(this,"tasks"),this.client=t,this.frameClient=e,this.tasks=r}async delete(t){await v(this.client,Cy,{keys:N(t)},Ry,My)}async create(t){const e=!Array.isArray(t),r=await v(this.client,xy,{racks:N(t)},$y,jy),n=this.sugar(r.racks);return e?n[0]:n}async search(t){const e=await v(this.client,Tn,{search:t},Sn,zn);return this.sugar(e.racks)}async page(t,e){const r=await v(this.client,Tn,{offset:t,limit:e},Sn,zn);return this.sugar(r.racks)}async retrieve(t){const{variant:e,normalized:r,single:n}=Vr(t,{string:"names",number:"keys"}),i=await v(this.client,Tn,{[e]:r},Sn,zn),a=this.sugar(i.racks);return Gr("Rack",t,a,n),n?a[0]:a}sugar(t){return t.map(({key:e,name:r})=>new Py(e,r,this.tasks))}};class Py{constructor(e,r,n){l(this,"key"),l(this,"name"),l(this,"tasks"),this.key=e,this.name=r,this.tasks=n}async listTasks(){return await this.tasks.retrieve(this.key)}async retrieveTaskByName(e){return await this.tasks.retrieveByName(e,this.key)}async createTask(e){return e.key=((BigInt(this.key)<<32n)+(BigInt(e.key??0)&0xffffffffn)).toString(),await this.tasks.create(e)}async deleteTask(e){await this.tasks.delete([e])}}const rt=s.z.union([s.z.string(),s.z.bigint().transform(t=>t.toString()),s.z.number().transform(t=>t.toString())]),Pr=s.z.object({task:rt,variant:s.z.string(),key:s.z.string().optional(),details:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t))).or(s.z.array(s.z.unknown())).or(s.z.null())}),Hr=s.z.object({key:rt,name:s.z.string(),type:s.z.string(),internal:s.z.boolean().optional(),config:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:et.JSON_CODEC.decodeString(t))),state:Pr.optional().nullable(),snapshot:s.z.boolean().optional()}),By=Hr.omit({key:!0}).extend({key:rt.transform(t=>t.toString()).optional(),config:s.z.unknown().transform(t=>et.JSON_CODEC.encodeString(t))});s.z.object({task:rt,type:s.z.string(),key:s.z.string(),args:s.z.record(s.z.unknown()).or(s.z.string().transform(t=>t===""?{}:JSON.parse(t)))});const Et="sy_task_state",xi="sy_task_cmd",Ht=new Error("Task not created");class Uy{constructor(e,r,n,i,a=!1,o=!1,c,u=null,d=null,f=null){l(this,"key"),l(this,"name"),l(this,"internal"),l(this,"type"),l(this,"config"),l(this,"snapshot"),l(this,"state"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=e,this.name=r,this.type=n,this.config=i,this.internal=a,this.snapshot=o,c!==null&&(this.state=c),this.frameClient=u,this.ontologyClient=d,this.rangeClient=f}get payload(){return{key:this.key,name:this.name,type:this.type,config:this.config,state:this.state,internal:this.internal}}get ontologyID(){return new $({type:"task",key:this.key})}async executeCommand(e,r){if(this.frameClient==null)throw Ht;const n=await this.frameClient.openWriter(xi),i=od.id();return await n.write(xi,[{task:this.key,type:e,key:i,args:r}]),await n.close(),i}async executeCommandSync(e,r,n){if(this.frameClient==null)throw Ht;const i=await this.frameClient.openStreamer(Et),a=await this.executeCommand(e,r);let o;const c=new Promise(u=>setTimeout(()=>u(!1),new I(n).milliseconds));for(;;){const u=await Promise.any([i.read(),c]);if(u===!1)throw new Error("Command timed out");const d=Pr.safeParse(u.at(-1).sy_task_state);if(d.success){if(o=d.data,o.key===a)break}else console.error(d.error)}return i.close(),o}async openStateObserver(){if(this.frameClient==null)throw Ht;return new Kr(await this.frameClient.openStreamer(Et),e=>{const r=e.get(Et);if(r.length===0)return[null,!1];const n=Pr.safeParse(r.at(-1));if(!n.success)return[null,!1];const i=n.data;return i.task!==this.key?[null,!1]:[i,!0]})}async snapshottedTo(){if(this.ontologyClient==null||this.rangeClient==null)throw Ht;if(!this.snapshot)return null;const e=await this.ontologyClient.retrieveParents(this.ontologyID);return e.length==0?null:e[0]}}const Ly=s.z.object({rack:Yt.optional(),keys:s.z.string().array().optional(),names:s.z.string().array().optional(),offset:s.z.number().optional(),limit:s.z.number().optional(),includeState:s.z.boolean().optional()}),Yy=s.z.object({tasks:Ue(Hr)}),qy="/hardware/task/retrieve",_y="/hardware/task/create",Fy="/hardware/task/delete",Wy="/hardware/task/copy",Vy=s.z.object({tasks:By.array()}),Gy=s.z.object({tasks:Hr.array()}),Zy=s.z.object({keys:rt.array()}),Ky=s.z.object({}),Jy=s.z.object({key:rt,name:s.z.string(),snapshot:s.z.boolean()}),Hy=s.z.object({task:Hr});let Xy=class{constructor(t,e,r,n){l(this,"type","task"),l(this,"client"),l(this,"frameClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.client=t,this.frameClient=e,this.ontologyClient=r,this.rangeClient=n}async create(t){const e=!Array.isArray(t),r=await v(this.client,_y,{tasks:N(t)},Vy,Gy),n=this.sugar(r.tasks);return e?n[0]:n}async delete(t){await v(this.client,Fy,{keys:N(t)},Zy,Ky)}async search(t){return await this.execRetrieve({keys:[t]})}async page(t,e){return await this.execRetrieve({offset:t,limit:e})}async list(t={}){return this.sugar(await this.execRetrieve(t))}async retrieve(t,e){const{single:r,normalized:n,variant:i}=Vr(t,{number:"rack",string:"keys"},{convertNumericStrings:!1}),a={...e};i==="rack"?a.rack=t:a.keys=n;const o=await this.execRetrieve(a),c=this.sugar(o);return r&&i!=="rack"?c[0]:c}async copy(t,e,r){const n=await v(this.client,Wy,{key:t,name:e,snapshot:r},Jy,Hy);return this.sugar([n.task])[0]}async retrieveByName(t,e){const r=await this.execRetrieve({names:[t],rack:e});return Gr("Task",t,r,!0),this.sugar(r)[0]}async execRetrieve(t){return(await v(this.client,qy,t,Ly,Yy)).tasks}sugar(t){return t.map(({key:e,name:r,type:n,config:i,state:a,internal:o,snapshot:c})=>new Uy(e,r,n,i,o,c,a,this.frameClient,this.ontologyClient,this.rangeClient))}async openTracker(){return await tt(this.frameClient,"sy_task_set","sy_task_delete",(t,e)=>Array.from(e).map(r=>({variant:t,key:r.toString(),value:r.toString()})))}async openStateObserver(){return new Kr(await this.frameClient.openStreamer(Et),t=>{const e=t.get(Et);if(e.length===0)return[null,!1];const r=Pr.safeParse(e.at(-1));return r.success?[r.data,!0]:[null,!1]})}};const qt=s.z.string().uuid(),Xr=s.z.object({key:qt,name:s.z.string().min(1),color:s.z.string()}),Qy=s.z.object({keys:qt.array().optional(),for:fe.optional(),search:s.z.string().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),eg=s.z.object({labels:Ue(Xr)});var Xt;let tg=(Xt=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=N(t);return await this.execute({keys:e})}async retrieveFor(t){return await this.execute({for:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){const[e,r]=await this.client.send(Xt.ENDPOINT,t,Qy,eg);if(r!=null)throw r;return e.labels}},l(Xt,"ENDPOINT","/label/retrieve"),Xt);const rg=Xr.extend({key:qt.optional()}),ng=s.z.object({labels:rg.array()}),sg=s.z.object({labels:Xr.array()}),ig=s.z.object({keys:qt.array()}),jo=s.z.object({id:fe,labels:qt.array(),replace:s.z.boolean().optional()}),ag=jo.omit({replace:!0}),Nn=s.z.object({}),og="/label/create",cg="/label/delete",lg="/label/set",ug="/label/remove";let hg=class{constructor(t){l(this,"client"),this.client=t}async create(t){return(await v(this.client,og,{labels:N(t)},ng,sg)).labels}async delete(t){await v(this.client,cg,{keys:N(t)},ig,Nn)}async set(t,e,{replace:r}={}){await v(this.client,lg,{id:t,labels:e,replace:r},jo,Nn)}async remove(t,e){await v(this.client,ug,{id:t,labels:e},ag,Nn)}};const dg="sy_label_set",fg="sy_label_delete";let yg=class{constructor(t,e,r){l(this,"type","label"),l(this,"retriever"),l(this,"writer"),l(this,"frameClient"),l(this,"ontology"),this.writer=new hg(t),this.retriever=new tg(t),this.frameClient=e,this.ontology=r}async search(t){return await this.retriever.search(t)}async retrieve(t){const e=Array.isArray(t),r=await this.retriever.retrieve(t);return e?r:r[0]}async retrieveFor(t){return await this.retriever.retrieveFor(new $(t))}async label(t,e,r={}){await this.writer.set(new $(t),e,r)}async removeLabels(t,e){await this.writer.remove(new $(t),e)}async page(t,e){return await this.retriever.page(t,e)}async create(t){const e=Array.isArray(t),r=await this.writer.create(t);return e?r:r[0]}async delete(t){await this.writer.delete(t)}async openChangeTracker(){return await tt(this.frameClient,dg,fg,gg)}async trackLabelsOf(t){const e=new Ve.Observer,r=(await this.retrieveFor(t)).map(n=>({id:new $({key:n.key,type:"label"}),key:n.key,name:n.name,data:n}));return(await this.ontology.openDependentTracker({target:new $(t),dependents:r,relationshipType:"labeled_by"})).onChange(n=>e.notify(n.map(i=>{var a,o;return{key:i.id.key,color:(a=i.data)==null?void 0:a.color,name:(o=i.data)==null?void 0:o.name}}))),e}};const gg=(t,e)=>t==="delete"?e.toUUIDs().map(r=>({variant:t,key:r})):e.parseJSON(Xr).map(r=>({variant:t,key:r.key,value:r})),de=s.z.string().uuid(),_t=s.z.object({key:de,name:s.z.string().min(1),timeRange:ne.z,color:s.z.string().optional()}),Ro=_t.extend({key:s.z.string().uuid().optional()}),Mo=t=>{const e=N(t),r=e.length===0;let n=!1;return r||(n=de.safeParse(e[0]).success),{single:!Array.isArray(t),variant:n?"keys":"names",normalized:e,actual:t,empty:r}},Do="range",Po="range-alias",pg=t=>new $({type:Do,key:t}),mg=t=>new $({type:Po,key:t}),wg="sy_range_alias_set",bg="sy_range_alias_delete",vg=s.z.object({range:de,aliases:s.z.string().array()}),Og=s.z.object({aliases:s.z.record(s.z.string(),Be)}),Tg=s.z.object({range:de,aliases:s.z.record(Be.or(s.z.string()),s.z.string())}),Sg=s.z.unknown(),zg=s.z.object({range:de,channels:Be.array()}),Ng=s.z.unknown(),Eg=s.z.object({range:de}),Ig=s.z.object({aliases:s.z.record(s.z.string(),s.z.string())}),bt=class vt{constructor(e,r,n){l(this,"frameClient"),l(this,"cache",new Map),l(this,"client"),l(this,"rangeKey"),this.rangeKey=e,this.cache=new Map,this.client=n,this.frameClient=r}async resolve(e){const r=[],n=typeof e=="string",i={};if(n){const o=this.cache.get(e);if(o!=null)return o;r.push(e)}else e.forEach(o=>{const c=this.cache.get(o);c!=null?i[o]=c:r.push(o)});if(r.length===0)return i;const a=await v(this.client,vt.RESOLVE_ENDPOINT,{range:this.rangeKey,aliases:r},vg,Og);return Object.entries(a.aliases).forEach(([o,c])=>this.cache.set(o,c)),n?a.aliases[r[0]]:{...i,...a.aliases}}async set(e){await v(this.client,vt.SET_ENDPOINT,{range:this.rangeKey,aliases:e},Tg,Sg)}async list(){return(await v(this.client,vt.LIST_ENDPOINT,{range:this.rangeKey},Eg,Ig)).aliases}async delete(e){await v(this.client,vt.DELETE_ENDPOINT,{range:this.rangeKey,channels:e},zg,Ng)}async openChangeTracker(){return await tt(this.frameClient,wg,bg,Cg(this.rangeKey))}};l(bt,"SET_ENDPOINT","/range/alias/set"),l(bt,"RESOLVE_ENDPOINT","/range/alias/resolve"),l(bt,"LIST_ENDPOINT","/range/alias/list"),l(bt,"DELETE_ENDPOINT","/range/alias/delete");let kg=bt;const Ag=s.z.object({range:de,channel:Be,alias:s.z.string()}),xg="---",Cg=t=>(e,r)=>e==="delete"?r.toStrings().filter(n=>n.split(xg)[0]===t).map(n=>({variant:e,key:n,value:void 0})):r.parseJSON(Ag).map(n=>({variant:e,key:n.alias,value:n})),$g=s.z.object({range:de,keys:s.z.string().array()}),Ss=s.z.object({range:de,key:s.z.string(),value:s.z.string()}),jg=s.z.object({pairs:Ue(Ss)}),Rg=s.z.object({range:de,pairs:Ss.array()}),Mg=s.z.object({range:de,keys:s.z.string().array()}),kr=class Ar{constructor(e,r,n){l(this,"rangeKey"),l(this,"client"),l(this,"frameClient"),this.rangeKey=e,this.client=r,this.frameClient=n}async get(e){const r=await v(this.client,Ar.GET_ENDPOINT,{range:this.rangeKey,keys:N(e)},$g,jg);return typeof e=="string"?r.pairs[0].value:Object.fromEntries(r.pairs.map(n=>[n.key,n.value]))}async list(){return this.get([])}async set(e,r=""){let n;is(e)?n=Object.entries(e).map(([i,a])=>({range:this.rangeKey,key:i,value:a})):n=[{range:this.rangeKey,key:e,value:r}],await v(this.client,Ar.SET_ENDPOINT,{range:this.rangeKey,pairs:n},Rg,s.z.unknown())}async delete(e){await v(this.client,Ar.DELETE_ENDPOINT,{range:this.rangeKey,keys:N(e)},Mg,s.z.unknown())}async openTracker(){return await tt(this.frameClient,"sy_range_kv_set","sy_range_kv_delete",(e,r)=>e==="delete"?r.toStrings().map(n=>{const[i,a]=n.split("<--->",2);return{variant:e,key:n,value:{range:i,key:a,value:""}}}):r.parseJSON(Ss).map(n=>({variant:e,key:`${n.range}${n.key}`,value:n})))}};l(kr,"GET_ENDPOINT","/range/kv/get"),l(kr,"SET_ENDPOINT","/range/kv/set"),l(kr,"DELETE_ENDPOINT","/range/kv/delete");let Wn=kr;const En=t=>new $({type:"range",key:t});class Bo{constructor(e,r=ne.ZERO,n,i,a,o,c,u,d,f,h){l(this,"key"),l(this,"name"),l(this,"kv"),l(this,"timeRange"),l(this,"color"),l(this,"channels"),l(this,"aliaser"),l(this,"frameClient"),l(this,"labelClient"),l(this,"ontologyClient"),l(this,"rangeClient"),this.key=n,this.name=e,this.timeRange=r,this.frameClient=a,this.color=i,this.kv=o,this.aliaser=c,this.channels=u,this.labelClient=d,this.ontologyClient=f,this.rangeClient=h}get ontologyID(){return new $({key:this.key,type:"range"})}get payload(){return{key:this.key,name:this.name,timeRange:this.timeRange,color:this.color}}async setAlias(e,r){const n=await this.channels.retrieve(e);if(n.length===0)throw new we(`Channel ${e} does not exist`);await this.aliaser.set({[n[0].key]:r})}async deleteAlias(...e){await this.aliaser.delete(e)}async listAliases(){return await this.aliaser.list()}async resolveAlias(e){return await this.aliaser.resolve(e)}async openAliasTracker(){return await this.aliaser.openChangeTracker()}async retrieveParent(){return this.rangeClient.retrieveParent(this.key)}async retrieveChildren(){const e=(await this.ontologyClient.retrieveChildren(this.ontologyID,{excludeFieldData:!0,types:["range"]})).map(r=>r.id.key);return await this.rangeClient.retrieve(e)}async read(e){return await this.frameClient.read(this.timeRange,e)}async labels(){return await this.labelClient.retrieveFor(En(this.key))}async addLabel(...e){await this.labelClient.label(En(this.key),e)}async removeLabel(...e){await this.labelClient.removeLabels(En(this.key),e)}async openChildRangeTracker(){const e=new Ve.Observer,r=(await this.retrieveChildren()).map(i=>{const a=new $({key:i.key,type:"range"});return{id:a,key:a.toString(),name:i.name,data:i.payload}}),n=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:r,resourceType:"range"});return n.onChange(i=>e.notify(this.rangeClient.resourcesToRanges(i))),e.setCloser(async()=>await n.close()),e}async openParentRangeTracker(){const e=new Ve.Observer,r=await this.retrieveParent();if(r==null)return null;const n=new $({key:r.key,type:"range"}),i={id:n,key:n.toString(),name:r.name,data:r.payload},a=await this.ontologyClient.openDependentTracker({target:this.ontologyID,dependents:[i],relationshipDirection:"to"});return a.onChange(o=>{const c=this.rangeClient.resourcesToRanges(o);if(c.length===0)return;const u=c[0];e.notify(u)}),e.setCloser(async()=>await a.close()),e}}const Dg=s.z.object({keys:de.array().optional(),names:s.z.array(s.z.string()).optional(),term:s.z.string().optional(),overlapsWith:ne.z.optional(),limit:s.z.number().int().optional(),offset:s.z.number().int().optional()}),Pg="/range/retrieve",Bg=s.z.object({ranges:Ue(_t)});let Uo=class{constructor(t,e,r,n,i,a){l(this,"type","range"),l(this,"frameClient"),l(this,"writer"),l(this,"unaryClient"),l(this,"channels"),l(this,"labelClient"),l(this,"ontologyClient"),this.frameClient=t,this.writer=e,this.unaryClient=r,this.channels=n,this.labelClient=i,this.ontologyClient=a}async create(t,e){const r=!Array.isArray(t),n=this.sugarMany(await this.writer.create(N(t),e));return r?n[0]:n}async rename(t,e){await this.writer.rename(t,e)}async delete(t){await this.writer.delete(N(t))}async search(t){return this.sugarMany(await this.execRetrieve({term:t}))}async page(t,e){return this.sugarMany(await this.execRetrieve({offset:t,limit:e}))}async retrieve(t){if(typeof t=="object"&&"start"in t)return await this.execRetrieve({overlapsWith:new ne(t)});const{single:e,actual:r,variant:n,normalized:i,empty:a}=Mo(t);if(a)return[];const o=await this.execRetrieve({[n]:i});if(!e)return o;if(o.length===0)throw new Rr(`range matching ${r} not found`);if(o.length>1)throw new Mr(`multiple ranges matching ${r} found`);return o[0]}getKV(t){return new Wn(t,this.unaryClient,this.frameClient)}async execRetrieve(t){const{ranges:e}=await v(this.unaryClient,Pg,t,Dg,Bg);return this.sugarMany(e)}async retrieveParent(t){const e=await this.ontologyClient.retrieveParents({key:t,type:"range"});if(e.length===0)return null;const r=e[0];return r.id.type!=="range"?null:await this.retrieve(r.id.key)}sugarOne(t){return new Bo(t.name,t.timeRange,t.key,t.color,this.frameClient,new Wn(t.key,this.unaryClient,this.frameClient),new kg(t.key,this.frameClient,this.unaryClient),this.channels,this.labelClient,this.ontologyClient,this)}sugarMany(t){return t.map(e=>this.sugarOne(e))}async openTracker(){return await tt(this.frameClient,"sy_range_set","sy_range_delete",(t,e)=>t==="delete"?e.toStrings().map(r=>({variant:t,key:r,value:void 0})):this.sugarMany(e.parseJSON(_t)).map(r=>({variant:t,key:r.key,value:r})))}resourcesToRanges(t){return t.map(e=>this.resourceToRange(e))}resourceToRange(t){var e,r,n;return this.sugarOne({key:t.id.key,name:(e=t.data)==null?void 0:e.name,timeRange:new ne((r=t.data)==null?void 0:r.timeRange),color:(n=t.data)==null?void 0:n.color})}};const Ug=s.z.object({ranges:_t.array()}),Lg=s.z.object({parent:fe.optional(),ranges:Ro.array()}),Yg=s.z.object({keys:de.array()}),qg=s.z.object({}),_g=s.z.object({key:de,name:s.z.string()}),Fg=s.z.object({}),Wg="/range/create",Vg="/range/delete",Gg="/range/rename";let Lo=class{constructor(t){l(this,"client"),this.client=t}async rename(t,e){await v(this.client,Gg,{key:t,name:e},_g,Fg)}async create(t,e){return(await v(this.client,Wg,{ranges:t,...e},Lg,Ug)).ranges}async delete(t){await v(this.client,Vg,{keys:t},Yg,qg)}};const Zg=Object.freeze(Object.defineProperty({__proto__:null,Client:Uo,KV:Wn,Range:Bo,RangeAliasOntologyType:Po,RangeOntologyType:Do,Writer:Lo,analyzeParams:Mo,keyZ:de,newPayloadZ:Ro,payloadZ:_t,rangeAliasOntologyID:mg,rangeOntologyID:pg},Symbol.toStringTag,{value:"Module"})),Kg="/api/v1/";class Jg{constructor(e,r=!1){l(this,"url"),l(this,"unary"),l(this,"stream"),l(this,"secure"),this.secure=r,this.url=e.child(Kg);const n=new et.JSONCodec;this.unary=new sh(this.url,n,this.secure),this.stream=new fh(this.url,n,this.secure)}use(...e){this.unary.use(...e),this.stream.use(...e)}}const zs=s.z.string().uuid(),Ns=s.z.object({key:s.z.string(),name:s.z.string(),data:cs.or(s.z.string().transform(t=>JSON.parse(t)))}),Hg=s.z.object({keys:s.z.string().array()}),Xg=s.z.object({linePlots:Ns.array()});let Qg=class{constructor(t){l(this,"ENDPOINT","/workspace/lineplot/retrieve"),l(this,"client"),this.client=t}async retrieve(t){const e=N(t);return(await v(this.client,this.ENDPOINT,{keys:e},Hg,Xg)).linePlots}};const Ge=s.z.string().uuid(),Yo=t=>JSON.parse(t),qo=s.z.object({name:s.z.string(),key:Ge,layout:cs.or(s.z.string().transform(t=>Yo(t)))}),_o=qo.omit({layout:!0}).extend({layout:s.z.string().transform(t=>Yo(t))}),ep=Ns.partial({key:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),tp=s.z.object({workspace:Ge,linePlots:ep.array()}),rp=s.z.object({linePlots:Ns.array()}),np=s.z.object({keys:zs.array()}),sp=s.z.object({}),ip=s.z.object({key:zs,name:s.z.string()}),ap=s.z.object({}),op=s.z.object({key:zs,data:s.z.string()}),cp=s.z.object({}),lp="/workspace/lineplot/create",up="/workspace/lineplot/delete",hp="/workspace/lineplot/rename",dp="/workspace/lineplot/set-data";let fp=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const r={...e,data:JSON.stringify(e.data)};return(await v(this.client,lp,{workspace:t,linePlots:[r]},tp,rp)).linePlots[0]}async delete(t){const e=N(t);await v(this.client,up,{keys:e},np,sp)}async rename(t,e){await v(this.client,hp,{key:t,name:e},ip,ap)}async setData(t,e){await v(this.client,dp,{key:t,data:JSON.stringify(e)},op,cp)}},yp=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new fp(t),this.retriever=new Qg(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),r=await this.retriever.retrieve(t);return e?r:r[0]}async delete(t){await this.writer.delete(t)}};const gp=s.z.object({keys:Ge.array().optional(),search:s.z.string().optional(),author:s.z.string().uuid().optional(),offset:s.z.number().optional(),limit:s.z.number().optional()}),pp=s.z.object({workspaces:Ue(_o)});var Qt;let mp=(Qt=class{constructor(t){l(this,"client"),this.client=t}async retrieve(t){const e=N(t);return await this.execute({keys:e})}async retrieveByAuthor(t){return await this.execute({author:t})}async search(t){return await this.execute({search:t})}async page(t,e){return await this.execute({offset:t,limit:e})}async execute(t){return(await v(this.client,Qt.ENDPOINT,t,gp,pp)).workspaces}},l(Qt,"ENDPOINT","/workspace/retrieve"),Qt);const Qr=s.z.string().uuid(),wp=s.z.object({key:s.z.string(),name:s.z.string(),data:cs.or(s.z.string().transform(t=>JSON.parse(t))),snapshot:s.z.boolean()}),Es=s.z.object({key:s.z.string(),name:s.z.string(),snapshot:s.z.boolean(),data:s.z.string().transform(t=>JSON.parse(t))}),bp=s.z.object({keys:s.z.string().array()}),vp=s.z.object({schematics:Es.array()});class Op{constructor(e){l(this,"ENDPOINT","/workspace/schematic/retrieve"),l(this,"client"),this.client=e}async retrieve(e){return(await v(this.client,this.ENDPOINT,{keys:N(e)},bp,vp)).schematics}}const Tp=wp.partial({key:!0,snapshot:!0}).transform(t=>({...t,data:JSON.stringify(t.data)})),Sp=s.z.object({workspace:Ge,schematics:Tp.array()}),zp=s.z.object({schematics:Es.array()}),Np=s.z.object({keys:Qr.array()}),Ep=s.z.object({}),Ip=s.z.object({key:Qr,name:s.z.string()}),Ci=s.z.object({}),kp=s.z.object({key:Qr,data:s.z.string()});s.z.object({});const Ap=s.z.object({key:Qr,name:s.z.string(),snapshot:s.z.boolean()}),xp=s.z.object({schematic:Es}),Cp="/workspace/schematic/create",$p="/workspace/schematic/delete",jp="/workspace/schematic/rename",Rp="/workspace/schematic/set-data",Mp="/workspace/schematic/copy";let Dp=class{constructor(t){l(this,"client"),this.client=t}async create(t,e){const r={...e,data:JSON.stringify(e.data)};return(await v(this.client,Cp,{workspace:t,schematics:[r]},Sp,zp)).schematics[0]}async copy(t,e,r){return(await v(this.client,Mp,{key:t,name:e,snapshot:r},Ap,xp)).schematic}async delete(t){const e=N(t);await v(this.client,$p,{keys:e},Np,Ep)}async rename(t,e){await v(this.client,jp,{key:t,name:e},Ip,Ci)}async setData(t,e){await v(this.client,Rp,{key:t,data:JSON.stringify(e)},kp,Ci)}},Pp=class{constructor(t){l(this,"writer"),l(this,"retriever"),this.writer=new Dp(t),this.retriever=new Op(t)}async create(t,e){return await this.writer.create(t,e)}async rename(t,e){await this.writer.rename(t,e)}async setData(t,e){await this.writer.setData(t,e)}async retrieve(t){const e=Array.isArray(t),r=await this.retriever.retrieve(t);return e?r:r[0]}async delete(t){await this.writer.delete(t)}async copy(t,e,r){return await this.writer.copy(t,e,r)}};const Bp=qo.partial({key:!0}).transform(t=>({...t,layout:JSON.stringify(t.layout)})),Up=s.z.object({workspaces:Bp.array()}),Lp=s.z.object({workspaces:_o.array()}),Yp=s.z.object({keys:Ge.array()}),qp=s.z.object({}),_p=s.z.object({key:Ge,name:s.z.string()}),Fp=s.z.object({}),Wp=s.z.object({key:Ge,layout:s.z.string()}),Vp=s.z.object({}),Gp="/workspace/create",Zp="/workspace/delete",Kp="/workspace/rename",Jp="/workspace/set-layout";class Hp{constructor(e){l(this,"client"),this.client=e}async create(e){return(await v(this.client,Gp,{workspaces:N(e)},Up,Lp)).workspaces}async delete(e){await v(this.client,Zp,{keys:N(e)},Yp,qp)}async rename(e,r){await v(this.client,Kp,{key:e,name:r},_p,Fp)}async setLayout(e,r){await v(this.client,Jp,{key:e,layout:JSON.stringify(r)},Wp,Vp)}}class Xp{constructor(e){l(this,"type","workspace"),l(this,"schematic"),l(this,"linePlot"),l(this,"retriever"),l(this,"writer"),this.schematic=new Pp(e),this.linePlot=new yp(e),this.retriever=new mp(e),this.writer=new Hp(e)}async search(e){return await this.retriever.search(e)}async retrieveByAuthor(e){return await this.retriever.retrieveByAuthor(e)}async retrieve(e){const r=Array.isArray(e),n=await this.retriever.retrieve(e);return r?n:n[0]}async page(e,r){return await this.retriever.page(e,r)}async create(e){const r=Array.isArray(e),n=await this.writer.create(e);return r?n:n[0]}async rename(e,r){await this.writer.rename(e,r)}async setLayout(e,r){await this.writer.setLayout(e,r)}async delete(...e){await this.writer.delete(e)}}const Fo=s.z.object({host:s.z.string({required_error:"Host is required"}).min(1,"Host is required"),port:s.z.number({required_error:"Port is required"}).or(s.z.string({required_error:"Port is required"})),username:s.z.string().min(1,"Username is required"),password:s.z.string().min(1,"Password is required"),connectivityPollFrequency:I.z.default(I.seconds(30)),secure:s.z.boolean().optional().default(!1),name:s.z.string().optional()});class Wo extends hy{constructor(e){const r=Fo.parse(e),{host:n,port:i,username:a,password:o,connectivityPollFrequency:c,secure:u}=r,d=new Jg(new Ed({host:n,port:Number(i)}),u);d.use(Bd);let f;a!=null&&o!=null&&(f=new Yf(d.unary,{username:a,password:o}),d.use(f.middleware()));const h=new ds(new hs(d.unary)),j=new So(d.unary,h);super(d.stream,d.unary,h),l(this,"createdAt"),l(this,"props"),l(this,"ranges"),l(this,"channels"),l(this,"auth"),l(this,"user"),l(this,"access"),l(this,"connectivity"),l(this,"ontology"),l(this,"workspaces"),l(this,"labels"),l(this,"hardware"),l(this,"control"),l(this,"transport"),l(this,"clientVersion","0.30.0"),this.createdAt=k.now(),this.props=r,this.auth=f,this.transport=d,this.channels=new To(this,h,d.unary,j),this.connectivity=new ko(d.unary,c,this.clientVersion,r.name),this.control=new $o(this),this.ontology=new rf(d.unary,this);const W=new Lo(this.transport.unary);this.labels=new yg(this.transport.unary,this,this.ontology),this.ranges=new Uo(this,W,this.transport.unary,h,this.labels,this.ontology),this.access=new Df(this.transport.unary),this.user=new Bf(this.transport.unary),this.workspaces=new Xp(this.transport.unary);const se=new ky(this.transport.unary,this),R=new Xy(this.transport.unary,this,this.ontology,this.ranges),hc=new Dy(this.transport.unary,this,R);this.hardware=new my(R,hc,se)}get key(){return this.createdAt.valueOf().toString()}close(){this.connectivity.stopChecking()}}l(Wo,"connectivity",ko);const Qp=Qe.Authority,Vn=(t,e,r="")=>{try{return t.parse(e)}catch(n){if(n instanceof s.z.ZodError){const i=n.errors.map(a=>a.path.length===0?a.message:`${a.path.join(".")}: ${a.message}`);throw new Error(`${r} - ${i.join(`
56
- `)}`)}else throw n}};var em=Object.defineProperty,tm=(t,e,r)=>e in t?em(t,e,{enumerable:!0,configurable:!0,writable:!0,value:r}):t[e]=r,H=(t,e,r)=>tm(t,typeof e!="symbol"?e+"":e,r);const Gn=class Vo{constructor(e,r,n="",i=!1){H(this,"_noop",!1),H(this,"key"),H(this,"path"),H(this,"serviceName"),this.key=e,this.path=r,this.serviceName=n,this._noop=i}child(e){return new Vo(e,this.extendPath(e),this.serviceName,this.noop)}extendPath(e){return`${this.path}.${e}`}get noop(){return this._noop}};H(Gn,"NOOP",new Gn("","",""));let Is=Gn;const Zn=["debug","info","warn","error"],rm=t=>{const e=Zn.indexOf(t);return({level:r})=>Zn.indexOf(r)>=e},nm=t=>{const{include:e,exclude:r}=t;return({path:n})=>!(e!=null&&!e.some(i=>n.startsWith(i))||r!=null&&r.some(i=>n.startsWith(i)))},Kn=class Go{constructor(e={}){H(this,"meta",Is.NOOP),H(this,"filters");const{filters:r=[]}=e;this.filters=r}filter(e){return!this.meta.noop&&this.filters.every(r=>r({key:this.meta.key,path:this.meta.path,level:e}))}child(e){const r=new Go({filters:this.filters});return r.meta=e,r}debug(e,r,n=!1){!this.filter("debug")&&!n||(r==null?console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e):console.log("%cDEBUG","color: #8c00f0;",this.meta.path,e,er(r)))}info(e,r,n=!1){!this.filter("info")&&!n||(r==null?console.log("%cINFO","color: #005eff;",this.meta.path,e):console.log("%cINFO","color: #005eff;",this.meta.path,e,er(r)))}warn(e,r,n=!1){!this.filter("warn")&&!n||(r==null?console.warn("WARN",this.meta.path,e):console.warn("WARN",this.meta.path,e,er(r)))}error(e,r,n=!1){!this.filter("error")&&!n||(r==null?console.error("ERROR",this.meta.path,e):console.error("ERROR",this.meta.path,e,er(r)))}};H(Kn,"NOOP",new Kn);let Zo=Kn;const er=t=>typeof t=="function"?t():t;var sm=typeof globalThis=="object"?globalThis:typeof self=="object"?self:typeof window=="object"?window:typeof global=="object"?global:{},Fe="1.8.0",$i=/^(\d+)\.(\d+)\.(\d+)(-(.+))?$/;function im(t){var e=new Set([t]),r=new Set,n=t.match($i);if(!n)return function(){return!1};var i={major:+n[1],minor:+n[2],patch:+n[3],prerelease:n[4]};if(i.prerelease!=null)return function(c){return c===t};function a(c){return r.add(c),!1}function o(c){return e.add(c),!0}return function(c){if(e.has(c))return!0;if(r.has(c))return!1;var u=c.match($i);if(!u)return a(c);var d={major:+u[1],minor:+u[2],patch:+u[3],prerelease:u[4]};return d.prerelease!=null||i.major!==d.major?a(c):i.major===0?i.minor===d.minor&&i.patch<=d.patch?o(c):a(c):i.minor<=d.minor?o(c):a(c)}}var am=im(Fe),om=Fe.split(".")[0],Ct=Symbol.for("opentelemetry.js.api."+om),$t=sm;function ks(t,e,r,n){var i;n===void 0&&(n=!1);var a=$t[Ct]=(i=$t[Ct])!==null&&i!==void 0?i:{version:Fe};if(!n&&a[t]){var o=new Error("@opentelemetry/api: Attempted duplicate registration of API: "+t);return r.error(o.stack||o.message),!1}if(a.version!==Fe){var o=new Error("@opentelemetry/api: Registration of version v"+a.version+" for "+t+" does not match previously registered API v"+Fe);return r.error(o.stack||o.message),!1}return a[t]=e,r.debug("@opentelemetry/api: Registered a global for "+t+" v"+Fe+"."),!0}function jt(t){var e,r,n=(e=$t[Ct])===null||e===void 0?void 0:e.version;if(!(!n||!am(n)))return(r=$t[Ct])===null||r===void 0?void 0:r[t]}function As(t,e){e.debug("@opentelemetry/api: Unregistering a global for "+t+" v"+Fe+".");var r=$t[Ct];r&&delete r[t]}var cm=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},lm=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},um=function(){function t(e){this._namespace=e.namespace||"DiagComponentLogger"}return t.prototype.debug=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return at("debug",this._namespace,e)},t.prototype.error=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return at("error",this._namespace,e)},t.prototype.info=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return at("info",this._namespace,e)},t.prototype.warn=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return at("warn",this._namespace,e)},t.prototype.verbose=function(){for(var e=[],r=0;r<arguments.length;r++)e[r]=arguments[r];return at("verbose",this._namespace,e)},t}();function at(t,e,r){var n=jt("diag");if(n)return r.unshift(e),n[t].apply(n,lm([],cm(r),!1))}var ye;(function(t){t[t.NONE=0]="NONE",t[t.ERROR=30]="ERROR",t[t.WARN=50]="WARN",t[t.INFO=60]="INFO",t[t.DEBUG=70]="DEBUG",t[t.VERBOSE=80]="VERBOSE",t[t.ALL=9999]="ALL"})(ye||(ye={}));function hm(t,e){t<ye.NONE?t=ye.NONE:t>ye.ALL&&(t=ye.ALL),e=e||{};function r(n,i){var a=e[n];return typeof a=="function"&&t>=i?a.bind(e):function(){}}return{error:r("error",ye.ERROR),warn:r("warn",ye.WARN),info:r("info",ye.INFO),debug:r("debug",ye.DEBUG),verbose:r("verbose",ye.VERBOSE)}}var dm=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},fm=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},ym="diag",Rt=function(){function t(){function e(i){return function(){for(var a=[],o=0;o<arguments.length;o++)a[o]=arguments[o];var c=jt("diag");if(c)return c[i].apply(c,fm([],dm(a),!1))}}var r=this,n=function(i,a){var o,c,u;if(a===void 0&&(a={logLevel:ye.INFO}),i===r){var d=new Error("Cannot use diag as the logger for itself. Please use a DiagLogger implementation like ConsoleDiagLogger or a custom implementation");return r.error((o=d.stack)!==null&&o!==void 0?o:d.message),!1}typeof a=="number"&&(a={logLevel:a});var f=jt("diag"),h=hm((c=a.logLevel)!==null&&c!==void 0?c:ye.INFO,i);if(f&&!a.suppressOverrideMessage){var j=(u=new Error().stack)!==null&&u!==void 0?u:"<failed to generate stacktrace>";f.warn("Current logger will be overwritten from "+j),h.warn("Current logger will overwrite one already registered from "+j)}return ks("diag",h,r,!0)};r.setLogger=n,r.disable=function(){As(ym,r)},r.createComponentLogger=function(i){return new um(i)},r.verbose=e("verbose"),r.debug=e("debug"),r.info=e("info"),r.warn=e("warn"),r.error=e("error")}return t.instance=function(){return this._instance||(this._instance=new t),this._instance},t}(),gm=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},pm=function(t){var e=typeof Symbol=="function"&&Symbol.iterator,r=e&&t[e],n=0;if(r)return r.call(t);if(t&&typeof t.length=="number")return{next:function(){return t&&n>=t.length&&(t=void 0),{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")},mm=function(){function t(e){this._entries=e?new Map(e):new Map}return t.prototype.getEntry=function(e){var r=this._entries.get(e);if(r)return Object.assign({},r)},t.prototype.getAllEntries=function(){return Array.from(this._entries.entries()).map(function(e){var r=gm(e,2),n=r[0],i=r[1];return[n,i]})},t.prototype.setEntry=function(e,r){var n=new t(this._entries);return n._entries.set(e,r),n},t.prototype.removeEntry=function(e){var r=new t(this._entries);return r._entries.delete(e),r},t.prototype.removeEntries=function(){for(var e,r,n=[],i=0;i<arguments.length;i++)n[i]=arguments[i];var a=new t(this._entries);try{for(var o=pm(n),c=o.next();!c.done;c=o.next()){var u=c.value;a._entries.delete(u)}}catch(d){e={error:d}}finally{try{c&&!c.done&&(r=o.return)&&r.call(o)}finally{if(e)throw e.error}}return a},t.prototype.clear=function(){return new t},t}();Rt.instance();function wm(t){return t===void 0&&(t={}),new mm(new Map(Object.entries(t)))}function bm(t){return Symbol.for(t)}var vm=function(){function t(e){var r=this;r._currentContext=e?new Map(e):new Map,r.getValue=function(n){return r._currentContext.get(n)},r.setValue=function(n,i){var a=new t(r._currentContext);return a._currentContext.set(n,i),a},r.deleteValue=function(n){var i=new t(r._currentContext);return i._currentContext.delete(n),i}}return t}(),Om=new vm,Tm={get:function(t,e){if(t!=null)return t[e]},keys:function(t){return t==null?[]:Object.keys(t)}},Sm={set:function(t,e,r){t!=null&&(t[e]=r)}},zm=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},Nm=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},Em=function(){function t(){}return t.prototype.active=function(){return Om},t.prototype.with=function(e,r,n){for(var i=[],a=3;a<arguments.length;a++)i[a-3]=arguments[a];return r.call.apply(r,Nm([n],zm(i),!1))},t.prototype.bind=function(e,r){return r},t.prototype.enable=function(){return this},t.prototype.disable=function(){return this},t}(),Im=function(t,e){var r=typeof Symbol=="function"&&t[Symbol.iterator];if(!r)return t;var n=r.call(t),i,a=[],o;try{for(;(e===void 0||e-- >0)&&!(i=n.next()).done;)a.push(i.value)}catch(c){o={error:c}}finally{try{i&&!i.done&&(r=n.return)&&r.call(n)}finally{if(o)throw o.error}}return a},km=function(t,e,r){if(arguments.length===2)for(var n=0,i=e.length,a;n<i;n++)(a||!(n in e))&&(a||(a=Array.prototype.slice.call(e,0,n)),a[n]=e[n]);return t.concat(a||Array.prototype.slice.call(e))},In="context",Am=new Em,Ko=function(){function t(){}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalContextManager=function(e){return ks(In,e,Rt.instance())},t.prototype.active=function(){return this._getContextManager().active()},t.prototype.with=function(e,r,n){for(var i,a=[],o=3;o<arguments.length;o++)a[o-3]=arguments[o];return(i=this._getContextManager()).with.apply(i,km([e,r,n],Im(a),!1))},t.prototype.bind=function(e,r){return this._getContextManager().bind(e,r)},t.prototype._getContextManager=function(){return jt(In)||Am},t.prototype.disable=function(){this._getContextManager().disable(),As(In,Rt.instance())},t}(),Jn;(function(t){t[t.UNSET=0]="UNSET",t[t.OK=1]="OK",t[t.ERROR=2]="ERROR"})(Jn||(Jn={}));var xm=Ko.getInstance(),Cm=function(){function t(){}return t.prototype.inject=function(e,r){},t.prototype.extract=function(e,r){return e},t.prototype.fields=function(){return[]},t}(),xs=bm("OpenTelemetry Baggage Key");function Jo(t){return t.getValue(xs)||void 0}function $m(){return Jo(Ko.getInstance().active())}function jm(t,e){return t.setValue(xs,e)}function Rm(t){return t.deleteValue(xs)}var kn="propagation",Mm=new Cm,Dm=function(){function t(){this.createBaggage=wm,this.getBaggage=Jo,this.getActiveBaggage=$m,this.setBaggage=jm,this.deleteBaggage=Rm}return t.getInstance=function(){return this._instance||(this._instance=new t),this._instance},t.prototype.setGlobalPropagator=function(e){return ks(kn,e,Rt.instance())},t.prototype.inject=function(e,r,n){return n===void 0&&(n=Sm),this._getGlobalPropagator().inject(e,r,n)},t.prototype.extract=function(e,r,n){return n===void 0&&(n=Tm),this._getGlobalPropagator().extract(e,r,n)},t.prototype.fields=function(){return this._getGlobalPropagator().fields()},t.prototype.disable=function(){As(kn,Rt.instance())},t.prototype._getGlobalPropagator=function(){return jt(kn)||Mm},t}(),Pm=Dm.getInstance();const ji=["bench","debug","prod"],Bm=t=>e=>ji.indexOf(e)>=ji.indexOf(t),Hn=class Ho{constructor(e,r=Bm("debug")){H(this,"meta",Is.NOOP),H(this,"tracer"),H(this,"filter"),this.tracer=e,this.filter=r}child(e){const r=new Ho(this.tracer,this.filter);return r.meta=e,r}debug(e,r){return this.trace(e,"debug",r)}bench(e,r){return this.trace(e,"bench",r)}prod(e,r){return this.trace(e,"prod",r)}trace(e,r,n){return this.meta.noop||!this.filter(r)?n(new ec(e)):this.tracer.startActiveSpan(e,i=>{const a=new Qo(e,i),o=n(a);return i.end(),o})}propagate(e){if(this.meta.noop)return;const r=xm.active();Pm.inject(r,e,{set:(n,i,a)=>{n[i]=a}})}};H(Hn,"NOOP",new Hn);let Xo=Hn;class Qo{constructor(e,r){H(this,"key"),H(this,"otel"),this.key=e,this.otel=r}set(e,r){this.otel.setAttribute(e,r)}recordError(e){e!=null&&(this.otel.recordException(e),this.otel.setStatus({code:Jn.ERROR}))}}class ec{constructor(e){H(this,"key"),this.key=e}set(){}recordError(e){}}const Xn=class tc{constructor({key:e="",serviceName:r="",logger:n=Zo.NOOP,tracer:i=Xo.NOOP,noop:a=!1,__meta:o}){H(this,"meta"),H(this,"T"),H(this,"L"),this.meta=o??new Is(e,e,r,a),this.T=i.child(this.meta),this.L=n.child(this.meta)}child(e){const r=this.meta.child(e);return new tc({__meta:r,tracer:this.T,logger:this.L})}};H(Xn,"NOOP",new Xn({noop:!0}));let Cs=Xn;const Um=Cs.NOOP,rc=Object.freeze(Object.defineProperty({__proto__:null,Instrumentation:Cs,LOG_LEVELS:Zn,Logger:Zo,NOOP:Um,NoopSpan:ec,Tracer:Xo,_Span:Qo,logLevelKeyFiler:nm,logThresholdFilter:rm},Symbol.toStringTag,{value:"Module"})),Lm=new Error("request for lock canceled");var Ym=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class qm{constructor(e,r=Lm){this._value=e,this._cancelError=r,this._queue=[],this._weightedWaiters=[]}acquire(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return new Promise((n,i)=>{const a={resolve:n,reject:i,weight:e,priority:r},o=nc(this._queue,c=>r<=c.priority);o===-1&&e<=this._value?this._dispatchItem(a):this._queue.splice(o+1,0,a)})}runExclusive(e){return Ym(this,arguments,void 0,function*(r,n=1,i=0){const[a,o]=yield this.acquire(n,i);try{return yield r(a)}finally{o()}})}waitForUnlock(e=1,r=0){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);return this._couldLockImmediately(e,r)?Promise.resolve():new Promise(n=>{this._weightedWaiters[e-1]||(this._weightedWaiters[e-1]=[]),_m(this._weightedWaiters[e-1],{resolve:n,priority:r})})}isLocked(){return this._value<=0}getValue(){return this._value}setValue(e){this._value=e,this._dispatchQueue()}release(e=1){if(e<=0)throw new Error(`invalid weight ${e}: must be positive`);this._value+=e,this._dispatchQueue()}cancel(){this._queue.forEach(e=>e.reject(this._cancelError)),this._queue=[]}_dispatchQueue(){for(this._drainUnlockWaiters();this._queue.length>0&&this._queue[0].weight<=this._value;)this._dispatchItem(this._queue.shift()),this._drainUnlockWaiters()}_dispatchItem(e){const r=this._value;this._value-=e.weight,e.resolve([r,this._newReleaser(e.weight)])}_newReleaser(e){let r=!1;return()=>{r||(r=!0,this.release(e))}}_drainUnlockWaiters(){if(this._queue.length===0)for(let e=this._value;e>0;e--){const r=this._weightedWaiters[e-1];r&&(r.forEach(n=>n.resolve()),this._weightedWaiters[e-1]=[])}else{const e=this._queue[0].priority;for(let r=this._value;r>0;r--){const n=this._weightedWaiters[r-1];if(!n)continue;const i=n.findIndex(a=>a.priority<=e);(i===-1?n:n.splice(0,i)).forEach(a=>a.resolve())}}}_couldLockImmediately(e,r){return(this._queue.length===0||this._queue[0].priority<r)&&e<=this._value}}function _m(t,e){const r=nc(t,n=>e.priority<=n.priority);t.splice(r+1,0,e)}function nc(t,e){for(let r=t.length-1;r>=0;r--)if(e(t[r]))return r;return-1}var Fm=function(t,e,r,n){function i(a){return a instanceof r?a:new r(function(o){o(a)})}return new(r||(r=Promise))(function(a,o){function c(f){try{d(n.next(f))}catch(h){o(h)}}function u(f){try{d(n.throw(f))}catch(h){o(h)}}function d(f){f.done?a(f.value):i(f.value).then(c,u)}d((n=n.apply(t,e||[])).next())})};class sc{constructor(e){this._semaphore=new qm(1,e)}acquire(){return Fm(this,arguments,void 0,function*(e=0){const[,r]=yield this._semaphore.acquire(1,e);return r})}runExclusive(e,r=0){return this._semaphore.runExclusive(()=>e(),1,r)}isLocked(){return this._semaphore.isLocked()}waitForUnlock(e=0){return this._semaphore.waitForUnlock(1,e)}release(){this._semaphore.isLocked()&&this._semaphore.release()}cancel(){return this._semaphore.cancel()}}class en{constructor(e,r,n=new Map){P(this,"providers");P(this,"registry");P(this,"sender");P(this,"changedKeys");this.providers=n,this.registry=r,this.changedKeys=[],this.sender=e}propagateState(e,r,n=[]){this.sender.send({key:e,state:r},n)}copyAndMerge(e){const r=new en(this.sender,this.registry,new Map);return e==null||e.providers.forEach((n,i)=>r.providers.set(i,n)),this.providers.forEach((n,i)=>r.providers.set(i,n)),r.changedKeys=[],r}get changed(){return this.changedKeys.length>0}set(e,r,n=!0){this.providers.set(e,r),n&&this.changedKeys.push(e)}setIfNotHas(e,r){this.providers.has(e)||this.set(e,r)}async create(e){const r=this.registry[e.type];if(r==null)throw new Error(`[AetherRoot.create] - could not find component ${e.type}`);const n=new r(e);return await n.internalUpdate(e),n}getOptional(e){return this.providers.get(e)??null}has(e){return this.providers.has(e)}get(e){const r=this.getOptional(e);if(r==null)throw new Error(`[AetherRoot.get] - could not find provider ${e}`);return r}}class $s{constructor(e){P(this,"type");P(this,"key");P(this,"_ctx");P(this,"_internalState");P(this,"_state");P(this,"_prevState");P(this,"_deleted",!1);P(this,"instrumentation");P(this,"schema");this.type=e.type,this.key=e.path[0],this._ctx=e.ctx,this._internalState={},this.instrumentation=e.instrumentation.child(`${this.type}(${this.key})`)}get _schema(){if(this.schema==null)throw new G(`[AetherLeaf] - expected subclass to define component schema, but none was found.
57
- Make sure to defne a property 'schema' on the class.`);return this.schema}setState(e){const r=rs(e,this._state);this._prevState={...this._state},this._state=Vn(this._schema,r,`${this.type}:${this.key}`),this.ctx.propagateState(this.key,r)}get ctx(){if(this._ctx==null)throw new pe("context not defined");return this._ctx}get state(){if(this._state==null)throw new pe("state not defined");return this._state}get internal(){return this._internalState}get prevState(){return this._prevState}get deleted(){return this._deleted}async internalUpdate({variant:e,path:r,ctx:n,state:i}){if(!this.deleted){if(this._ctx=n,e==="state"){this.validatePath(r);const a=Vn(this._schema,i,`${this.type}:${this.key}`);this._state!=null?this.instrumentation.L.debug("updating state",()=>({diff:Yi.difference(this.state,a)})):this.instrumentation.L.debug("setting initial state",{state:i}),this._prevState=this._state??a,this._state=a}else this.instrumentation.L.debug("updating context");await this.afterUpdate()}}async internalDelete(e){this.validatePath(e),this._deleted=!0,await this.afterDelete()}beforeUpdate(){}async afterUpdate(){}async afterDelete(){}validatePath(e){if(e.length===0)throw new pe(`[Leaf.setState] - ${this.type}:${this.key} received an empty path`);const r=e[e.length-1];if(e.length>1)throw new pe(`[Leaf.setState] - ${this.type}:${this.key} received a subPath ${e.join(".")} but is a leaf`);if(r!==this.key)throw new pe(`[Leaf.setState] - ${this.type}:${this.key} received a key ${r} but expected ${this.key}`)}}class Ft extends $s{constructor(r){super(r);P(this,"_children");this._children=new Map}get children(){return Array.from(this._children.values())}async internalUpdate(r){const{variant:n,path:i}=r;if(n==="context")return this._ctx=r.ctx.copyAndMerge(this._ctx),await this.updateContext({...r,ctx:this.ctx});const[a,o]=this.getRequiredKey(i),c={...r,ctx:this.ctx};return o.length===0?await this.updateThis(a,c):await this.updateChild(o,c)}async updateContext(r){await super.internalUpdate(r);for(const n of this.children)await n.internalUpdate({...r,ctx:this.ctx,variant:"context"})}async updateChild(r,n){const i=r[0],a=this.getChild(i);if(a!=null)return await a.internalUpdate({...n,path:r});if(r.length>1)throw new Error(`[Composite.setState] - ${this.type}:${this.key} could not find child with key ${i} while updating `);this._children.set(i,await n.ctx.create({...n,path:r}))}async updateThis(r,n){const i=n.ctx.copyAndMerge(this._ctx);if(r!==this.key)throw new pe(`[Composite.update] - ${this.type}:${this.key} received a key ${r} but expected ${this.key}`);if(await super.internalUpdate({...n,ctx:i}),!!i.changed){this.instrumentation.L.debug("context changed",{changedKeys:i.changedKeys});for(const a of this.children)await a.internalUpdate({...n,ctx:this.ctx,variant:"context"})}}async internalDelete(r){const[n,i]=this.getRequiredKey(r);if(i.length===0){if(n!==this.key)throw new Error(`[Composite.delete] - ${this.type}:${this.key} received a key ${n} but expected ${this.key}`);const o=this.children;this._children=new Map;for(const c of o)await c.internalDelete([c.key]);await super.internalDelete([this.key])}const a=this.getChild(i[0]);a!=null&&(i.length>1?await a.internalDelete(i):(this._children.delete(a.key),await a.internalDelete(i)))}getRequiredKey(r,n){const[i,...a]=r;if(i==null)throw new Error(`Composite ${this.type}:${this.key} received an empty path`+(n!=null?` for ${n}`:""));return[i,a]}getChild(r){return this._children.get(r)??null}childrenOfType(...r){return this.children.filter(n=>r.includes(n.type))}}const Wm=s.z.object({}),Ee=class Ee extends Ft{constructor({worker:r,registry:n,instrumentation:i=rc.Instrumentation.NOOP}){const o={ctx:new en(r,n,new Map),...Ee.ZERO_UPDATE,instrumentation:i};super(o);P(this,"wrap");P(this,"schema",Ee.schema);P(this,"mu",new sc);this.mu.runExclusive(async()=>await this.internalUpdate(o)),this.wrap=r,this.wrap.handle(c=>{this.mu.runExclusive(async()=>await this.handle(c))})}async handle(r){if(r.variant==="delete")await this.internalDelete(r.path);else{const n={...r,variant:"state",ctx:this.ctx,instrumentation:this.instrumentation};await this.internalUpdate(n)}}};P(Ee,"TYPE","root"),P(Ee,"KEY","root"),P(Ee,"ZERO_UPDATE",{path:[Ee.KEY],type:Ee.TYPE,variant:"state",state:{}}),P(Ee,"schema",Wm);let Br=Ee;const ic=t=>new Br(t),Vm=Object.freeze(Object.defineProperty({__proto__:null,Composite:Ft,Context:en,Leaf:$s,Root:Br,render:ic},Symbol.toStringTag,{value:"Module"})),ac="pluto-theming-context",Gm=s.z.object({theme:ia}),It=class It extends Ft{constructor(){super(...arguments);P(this,"schema",It.z)}async afterUpdate(){this.ctx.set(ac,this.state.theme)}};P(It,"TYPE","theming.Provider"),P(It,"z",Gm);let Mt=It;const Zm=t=>t.get(ac),Km={[Mt.TYPE]:Mt},oc=["success","error","warning","info","loading","disabled","secondary"],cc=s.z.enum(oc),lc=s.z.object({key:s.z.string(),variant:cc,message:s.z.string(),description:s.z.string().optional(),time:F.z,data:s.z.record(s.z.unknown()).optional()}),uc=s.z.object({statuses:lc.array()}),js="status.aggregator";class Ur extends Ft{constructor(){super(...arguments);P(this,"schema",uc)}async afterUpdate(){this.ctx.set(js,this)}add(r){const n=F.now();this.setState(i=>({...i,statuses:[...i.statuses,{time:n,key:n.toString(),...r}]}))}}P(Ur,"TYPE","status.Aggregator");const Jm=t=>{const e=t.get(js);return e.add.bind(e)},Hm=t=>{const e=t.getOptional(js);return e!=null?e.add.bind(e):()=>{}},Xm={[Ur.TYPE]:Ur};exports.$=Gc;exports.$y=Wo;exports.A=al;exports.Aggregator=Ur;exports.Ay=Fo;exports.B=xl;exports.B$1=Cs;exports.C=Yr;exports.C$1=zl;exports.ComponentSizeLevels=sa;exports.Composite=Ft;exports.D=G;exports.H=Cl;exports.Hy=Nf;exports.I=ce;exports.LEVELS=na;exports.Leaf=$s;exports.LevelComponentSizes=Ml;exports.Mutex=sc;exports.N=Wi;exports.Provider=Mt;exports.Q=we;exports.REGISTRY=Km;exports.REGISTRY$1=Xm;exports.S=I;exports.S$1=Tc;exports.SYNNAX_DARK=oa;exports.SYNNAX_LIGHT=aa;exports.SYNNAX_THEMES=Fl;exports.Se=pe;exports.U=kt;exports.V=ne;exports.VARIANTS=oc;exports.W=Al;exports._=Yi;exports._$1=Tl;exports.aether=Vm;exports.aggregatorStateZ=uc;exports.c=Ui;exports.commonjsGlobal=yc;exports.d=M;exports.dimensions=Pl;exports.executeInitialSetter=Pt;exports.executeSetter=rs;exports.fontString=Zl;exports.g=rc;exports.getAugmentedNamespace=pc;exports.getDefaultExportFromCjs=gc;exports.id=py;exports.isSetter=ts;exports.k=k;exports.kd=Qp;exports.l=gl;exports.levelZ=Rl;exports.m=F;exports.mt=Vc;exports.n=cl;exports.o=ol;exports.o$1=Cc;exports.prettyParse=Vn;exports.r=$c;exports.render=ic;exports.specZ=Me;exports.specZ$1=lc;exports.state=jl;exports.themeZ=ia;exports.u=es;exports.use=Zm;exports.useAggregate=Jm;exports.useOptionalAggregate=Hm;exports.usePassthrough=ta;exports.usePurePassthrough=ra;exports.variantZ=cc;exports.vd=Zg;exports.w=V;exports.w$1=Zi;exports.wt=Zc;exports.y=xc;exports.yt=el;