@synnaxlabs/freighter 0.40.0 → 0.41.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/freighter.cjs +8 -8
- package/dist/freighter.js +194 -200
- package/package.json +8 -8
package/dist/freighter.cjs
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var ft=Object.defineProperty;var dt=(r,e,t)=>e in r?ft(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var y=(r,e,t)=>dt(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),gt=r=>{const e=r.replace(/_[a-z]/g,t=>t[1].toUpperCase());return e.length>1&&e[0]===e[0].toUpperCase()&&e[1]===e[1].toUpperCase()||e.length===0?e:e[0].toLowerCase()+e.slice(1)},Ve=r=>{const e=(t,n=pe)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!he(t))return t;n=mt(n);const s={},a=t;return Object.keys(a).forEach(c=>{let f=a[c];const d=r(c);n.recursive&&(he(f)?Ae(f,n.keepTypesOnRecursion)||(f=e(f,n)):n.recursiveInArray&&Ee(f)&&(f=[...f].map(p=>{let m=p;return he(p)?Ae(m,n.keepTypesOnRecursion)||(m=e(p,n)):Ee(p)&&(m=e({key:p},n).key),m}))),s[d]=f}),s};return e},Ze=Ve(gt),pt=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),yt=Ve(pt),pe={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},mt=(r=pe)=>(r.recursive==null?r=pe:r.recursiveInArray??(r.recursiveInArray=!1),r),Ee=r=>r!=null&&Array.isArray(r),he=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Ae=(r,e)=>(e||[]).some(t=>r instanceof t),Je=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var wt=Object.defineProperty,bt=(r,e,t)=>e in r?wt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,_=(r,e,t)=>bt(r,typeof e!="symbol"?e+"":e,t);let Ot=class{constructor(){_(this,"contentType","application/json"),_(this,"decoder"),_(this,"encoder"),this.decoder=new TextDecoder,this.encoder=new TextEncoder}encode(e){return this.encoder.encode(this.encodeString(e)).buffer}decode(e,t){return this.decodeString(this.decoder.decode(e),t)}decodeString(e,t){const n=JSON.parse(e),s=Ze(n);return t!=null?t.parse(s):s}encodeString(e){const t=yt(e);return JSON.stringify(t,(n,s)=>ArrayBuffer.isView(s)?Array.from(s):Je(s)&&"encode_value"in s?typeof s.value=="bigint"?s.value.toString():s.value:typeof s=="bigint"?s.toString():s)}static registerCustomType(){}},Tt=class{constructor(){_(this,"contentType","text/csv")}encode(e){const t=this.encodeString(e);return new TextEncoder().encode(t).buffer}decode(e,t){const n=new TextDecoder().decode(e);return this.decodeString(n,t)}encodeString(e){if(!Array.isArray(e)||e.length===0||!Je(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(s=>{const a=t.map(c=>JSON.stringify(s[c]??""));n.push(a.join(","))}),n.join(`
|
|
2
2
|
`)}decodeString(e,t){const[n,...s]=e.trim().split(`
|
|
3
|
-
`).map(d=>d.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(d=>d.trim()),c={};return a.forEach(d=>{c[d]=[]}),s.forEach(d=>{const f=d.split(",").map(p=>p.trim());a.forEach((p,m)=>{const l=this.parseValue(f[m]);l!=null&&c[p].push(l)})}),t!=null?t.parse(c):c}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}static registerCustomType(){}},vt=class{constructor(){_(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,t){const n=new TextDecoder().decode(e);return t!=null?t.parse(n):n}};const re=new Tt;new Ot;new vt;const St=r=>r!=null&&typeof r=="object"&&"toString"in r,It=(r,e=!1)=>{const t=St(r)?"stringer":typeof r;let n;switch(t){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Nt(n):n},Nt=r=>(e,t)=>r(t,e),ue=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const He=i.z.object({width:i.z.number(),height:i.z.number()}),Et=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),At=["width","height"];i.z.enum(At);const xt=["start","center","end"],zt=["signedWidth","signedHeight"];i.z.enum(zt);const ie=i.z.object({x:i.z.number(),y:i.z.number()}),Mt=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),$t=["x","y"],Xe=i.z.enum($t),Ke=["top","right","bottom","left"];i.z.enum(Ke);const Ut=["left","right"],Qe=i.z.enum(Ut),Bt=["top","bottom"],_e=i.z.enum(Bt),et=["center"],xe=i.z.enum(et),Rt=[...Ke,...et],tt=i.z.enum(Rt);i.z.enum(xt);const Ct=["first","last"];i.z.enum(Ct);const Dt=i.z.object({lower:i.z.number(),upper:i.z.number()}),Pt=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([Dt,ue]);i.z.union([Pt,ue]);i.z.enum([...Xe.options,...tt.options]);i.z.union([Xe,tt,i.z.instanceof(String)]);const Lt=r=>typeof r=="bigint"||r instanceof BigInt,q=(r,e)=>Lt(r)?r.valueOf()*BigInt(e.valueOf()):r.valueOf()*Number(e.valueOf()),j=(r,e)=>{const t={};if(typeof r=="number"||typeof r=="bigint")e!=null?(t.lower=r,t.upper=e):(t.lower=typeof r=="bigint"?0n:0,t.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[t.lower,t.upper]=r}else return ze(r);return ze(t)},ze=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,Me=(r,e)=>{const t=j(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};i.z.object({x:Qe.or(xe),y:_e.or(xe)});const Yt=i.z.object({x:Qe,y:_e}),kt=Object.freeze({x:"left",y:"top"}),jt=(r,e)=>r.x===e.x&&r.y===e.y,$e=i.z.union([i.z.number(),ie,ue,He,Et,Mt]),qt=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},Ue=Object.freeze({x:0,y:0}),te=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:te,left:te,width:te,height:te});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:ie,two:ie,root:Yt});const ve=(r,e,t=0,n=0,s)=>{const a={one:{...Ue},two:{...Ue},root:s??kt};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:s??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"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))},de=r=>{const e=ve(r);return{lower:e.one.x,upper:e.two.x}},fe=r=>{const e=ve(r);return{lower:e.one.y,upper:e.two.y}},Ft=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Gt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([He,Gt,ie,ue]);var Wt=Object.defineProperty,Vt=(r,e,t)=>e in r?Wt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,D=(r,e,t)=>Vt(r,typeof e!="symbol"?e+"":e,t);const Zt=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;i.z.object({offset:$e,scale:$e});i.z.object({offset:i.z.number(),scale:i.z.number()});const Jt=r=>(e,t,n,s)=>t==="dimension"?[e,n]:[e,s?n-r:n+r],Ht=r=>(e,t,n,s)=>[e,s?n/r:n*r],Xt=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:s,upper:a}=e,{lower:c,upper:d}=r,f=a-s,p=d-c;if(t==="dimension")return[r,n*(p/f)];const m=(n-s)*(p/f)+c;return[r,m]},Kt=r=>(e,t,n)=>[r,n],Qt=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:s}=r;return[r,s-(t-n)]},_t=r=>(e,t,n)=>{const{lower:s,upper:a}=r;return n=Zt(n,s,a),[e,n]},ye=class V{constructor(){D(this,"ops",[]),D(this,"currBounds",null),D(this,"currType",null),D(this,"reversed",!1),this.ops=[]}static translate(e){return new V().translate(e)}static magnify(e){return new V().magnify(e)}static scale(e,t){return new V().scale(e,t)}translate(e){const t=this.new(),n=Jt(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Ht(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=j(e,t),s=this.new(),a=Xt(n);return a.type="scale",s.ops.push(a),s}clamp(e,t){const n=j(e,t),s=this.new(),a=_t(n);return a.type="clamp",s.ops.push(a),s}reBound(e,t){const n=j(e,t),s=this.new(),a=Kt(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Qt();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new V;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||t.some(([c,d])=>s>=c&&s<=d))return;const a=e.ops.findIndex((c,d)=>c.type==="scale"&&d>s);a!==-1&&t.push([s,a])}),t.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};D(ye,"IDENTITY",new ye);let Be=ye;const Re=class C{constructor(e=new Be,t=new Be,n=null){D(this,"x"),D(this,"y"),D(this,"currRoot"),this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new C().translate(e,t)}static translateX(e){return new C().translateX(e)}static translateY(e){return new C().translateY(e)}static clamp(e){return new C().clamp(e)}static magnify(e){return new C().magnify(e)}static scale(e){return new C().scale(e)}static reBound(e){return new C().reBound(e)}translate(e,t){const n=qt(e,t),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(Ft(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!jt(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(de(e)),t.y=t.y.scale(fe(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(de(e)),t.y=this.y.reBound(fe(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(de(e)),t.y=this.y.clamp(fe(e)),t}copy(){const e=new C;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)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return ve(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}};D(Re,"IDENTITY",new Re);var er=Object.defineProperty,tr=(r,e,t)=>e in r?er(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>tr(r,typeof e!="symbol"?e+"":e,t);let rr=(r,e=21)=>(t=e)=>{let n="",s=t|0;for(;s--;)n+=r[Math.random()*r.length|0];return n};const nr="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",sr=rr(nr,11),ir=()=>sr(),ar=i.z.enum(["static","dynamic"]),rt=(r,e)=>{const t=new v(e);if(![O.DAY,O.HOUR,O.MINUTE,O.SECOND,O.MILLISECOND,O.MICROSECOND,O.NANOSECOND].some(s=>s.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=r.valueOf()%t.valueOf();return r instanceof v?new v(n):new O(n)},b=class h{constructor(e,t="UTC"){if(u(this,"value"),u(this,"encodeValue",!0),e==null)this.value=h.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*h.MILLISECOND.valueOf();else if(typeof e=="string")this.value=h.parseDateTimeString(e,t).valueOf();else if(Array.isArray(e))this.value=h.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=h.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=h.MAX:e=h.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,t=1,n=1]){const s=new Date(e,t-1,n,0,0,0,0);return new h(BigInt(s.getTime())*h.MILLISECOND.valueOf()).truncate(h.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,s,a]=e.split(":");let c="00",d="00";a!=null&&([c,d]=a.split("."));let f=h.hours(parseInt(n??"00")).add(h.minutes(parseInt(s??"00"))).add(h.seconds(parseInt(c??"00"))).add(h.milliseconds(parseInt(d??"00")));return t==="local"&&(f=f.add(h.utcOffset)),f.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return h.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new h(BigInt(n.getTime())*h.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(h.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${t} ${n}`}static get utcOffset(){return new O(BigInt(new Date().getTimezoneOffset())*h.MINUTE.valueOf())}static since(e){return new h().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new h(e).valueOf()}span(e){return this.range(e).span}range(e){return new Se(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 h(e).valueOf()}afterEq(e){return this.valueOf()>=new h(e).valueOf()}before(e){return this.valueOf()<new h(e).valueOf()}beforeEq(e){return this.valueOf()<=new h(e).valueOf()}add(e){return new h(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new h(this.valueOf()-BigInt(e.valueOf()))}get hours(){return Number(this.valueOf())/Number(O.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(O.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(O.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(O.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(h.MILLISECOND.valueOf())}get year(){return this.date().getFullYear()}setYear(e){const t=this.date();return t.setFullYear(e),new h(t)}get month(){return this.date().getMonth()}setMonth(e){const t=this.date();return t.setMonth(e),new h(t)}get day(){return this.date().getDate()}setDay(e){const t=this.date();return t.setDate(e),new h(t)}get hour(){return this.date().getHours()}setHour(e){const t=this.date();return t.setHours(e),new h(t)}get minute(){return this.date().getMinutes()}setMinute(e){const t=this.date();return t.setMinutes(e),new h(t)}get second(){return this.date().getSeconds()}setSecond(e){const t=this.date();return t.setSeconds(e),new h(t)}get millisecond(){return this.date().getMilliseconds()}setMillisecond(e){const t=this.date();return t.setMilliseconds(e),new h(t)}toString(){return this.date().toISOString()}remainder(e){return rt(this,e)}get isToday(){return this.truncate(O.DAY).equals(h.now().truncate(O.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new h(new Date)}static max(...e){let t=h.MIN;for(const n of e){const s=new h(n);s.after(t)&&(t=s)}return t}static min(...e){let t=h.MAX;for(const n of e){const s=new h(n);s.before(t)&&(t=s)}return t}static nanoseconds(e){return new h(e)}static microseconds(e){return h.nanoseconds(e*1e3)}static milliseconds(e){return h.microseconds(e*1e3)}static seconds(e){return h.milliseconds(e*1e3)}static minutes(e){return h.seconds(e*60)}static hours(e){return h.minutes(e*60)}static days(e){return h.hours(e*24)}};u(b,"NANOSECOND",b.nanoseconds(1)),u(b,"MICROSECOND",b.microseconds(1)),u(b,"MILLISECOND",b.milliseconds(1)),u(b,"SECOND",b.seconds(1)),u(b,"MINUTE",b.minutes(1)),u(b,"HOUR",b.hours(1)),u(b,"DAY",b.days(1)),u(b,"MAX",new b((1n<<63n)-1n)),u(b,"MIN",new b(0)),u(b,"ZERO",new b(0)),u(b,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new b(r.value)),i.z.string().transform(r=>new b(BigInt(r))),i.z.instanceof(Number).transform(r=>new b(r)),i.z.number().transform(r=>new b(r)),i.z.instanceof(b)]));let v=b;const T=class g{constructor(e){u(this,"value"),u(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof v?new g(e):["number","bigint"].includes(typeof e)?g.seconds(e):new g(e)}static fromMilliseconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof v?new g(e):["number","bigint"].includes(typeof e)?g.milliseconds(e):new g(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new g(e).valueOf()}greaterThan(e){return this.valueOf()>new g(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new g(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new g(e).valueOf()}remainder(e){return rt(this,e)}truncate(e){return new g(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(g.DAY),t=this.truncate(g.HOUR),n=this.truncate(g.MINUTE),s=this.truncate(g.SECOND),a=this.truncate(g.MILLISECOND),c=this.truncate(g.MICROSECOND),d=this.truncate(g.NANOSECOND),f=e,p=t.sub(e),m=n.sub(t),l=s.sub(n),N=a.sub(s),M=c.sub(a),B=d.sub(c);let z="";return f.isZero||(z+=`${f.days}d `),p.isZero||(z+=`${p.hours}h `),m.isZero||(z+=`${m.minutes}m `),l.isZero||(z+=`${l.seconds}s `),N.isZero||(z+=`${N.milliseconds}ms `),M.isZero||(z+=`${M.microseconds}µs `),B.isZero||(z+=`${B.nanoseconds}ns`),z.trim()}mult(e){return new g(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(g.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(g.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(g.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(g.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(g.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(g.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new g(e).valueOf()}add(e){return new g(this.valueOf()+new g(e).valueOf())}sub(e){return new g(this.valueOf()-new g(e).valueOf())}static nanoseconds(e=1){return new g(e)}static microseconds(e=1){return g.nanoseconds(q(e,1e3))}static milliseconds(e=1){return g.microseconds(q(e,1e3))}static seconds(e=1){return g.milliseconds(q(e,1e3))}static minutes(e=1){return g.seconds(q(e,60))}static hours(e){return g.minutes(q(e,60))}static days(e){return g.hours(q(e,24))}};u(T,"NANOSECOND",T.nanoseconds(1)),u(T,"MICROSECOND",T.microseconds(1)),u(T,"MILLISECOND",T.milliseconds(1)),u(T,"SECOND",T.seconds(1)),u(T,"MINUTE",T.minutes(1)),u(T,"HOUR",T.hours(1)),u(T,"DAY",T.days(1)),u(T,"MAX",new T((1n<<63n)-1n)),u(T,"MIN",new T(0)),u(T,"ZERO",new T(0)),u(T,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new T(r.value)),i.z.string().transform(r=>new T(BigInt(r))),i.z.instanceof(Number).transform(r=>new T(r)),i.z.number().transform(r=>new T(r)),i.z.instanceof(T)]));let O=T;const Z=class ne extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ne(e).valueOf()}get period(){return O.seconds(1/this.valueOf())}sampleCount(e){return new O(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new x(t).valueOf()}span(e){return O.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new ne(e)}static khz(e){return ne.hz(e*1e3)}};u(Z,"z",i.z.union([i.z.number().transform(r=>new Z(r)),i.z.instanceof(Number).transform(r=>new Z(r)),i.z.instanceof(Z)]));let Ce=Z;const E=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new me(e*this.valueOf())}};u(E,"UNKNOWN",new E(0)),u(E,"BIT128",new E(16)),u(E,"BIT64",new E(8)),u(E,"BIT32",new E(4)),u(E,"BIT16",new E(2)),u(E,"BIT8",new E(1)),u(E,"z",i.z.union([i.z.number().transform(r=>new E(r)),i.z.instanceof(Number).transform(r=>new E(r)),i.z.instanceof(E)]));let x=E;const $=class se{constructor(e,t){u(this,"start"),u(this,"end"),typeof e=="object"&&"start"in e?(this.start=new v(e.start),this.end=new v(e.end)):(this.start=new v(e),this.end=new v(t))}get span(){return new O(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new se(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,t=O.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 s=v.max(n.start,e.start),a=v.min(n.end,e.end);return a.before(s)?!1:new O(a.sub(s)).greaterThanOrEqual(t)}roughlyEquals(e,t){let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=t.valueOf()&&s<=t.valueOf()}contains(e){return e instanceof se?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new se(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}};u($,"MAX",new $(v.MIN,v.MAX)),u($,"MIN",new $(v.MAX,v.MIN)),u($,"ZERO",new $(v.ZERO,v.ZERO)),u($,"z",i.z.union([i.z.object({start:v.z,end:v.z}).transform(r=>new $(r.start,r.end)),i.z.instanceof($)]));let Se=$;const o=class S extends String{constructor(e){if(e instanceof S||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const t=S.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}throw super(S.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=S.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(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(S.JSON)||this.equals(S.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(S.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=S.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsigned(){return this.equals(S.UINT8)||this.equals(S.UINT16)||this.equals(S.UINT32)||this.equals(S.UINT64)}get isSigned(){return this.equals(S.INT8)||this.equals(S.INT16)||this.equals(S.INT32)||this.equals(S.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsigned&&e.isSigned?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(S.INT32)&&e.equals(S.FLOAT64)||this.equals(S.INT8)&&e.equals(S.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsigned===e.isUnsigned:!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 S.BIG_INT_TYPES.some(e=>e.equals(this))}};u(o,"UNKNOWN",new o("unknown")),u(o,"FLOAT64",new o("float64")),u(o,"FLOAT32",new o("float32")),u(o,"INT64",new o("int64")),u(o,"INT32",new o("int32")),u(o,"INT16",new o("int16")),u(o,"INT8",new o("int8")),u(o,"UINT64",new o("uint64")),u(o,"UINT32",new o("uint32")),u(o,"UINT16",new o("uint16")),u(o,"UINT8",new o("uint8")),u(o,"BOOLEAN",o.UINT8),u(o,"TIMESTAMP",new o("timestamp")),u(o,"UUID",new o("uuid")),u(o,"STRING",new o("string")),u(o,"JSON",new o("json")),u(o,"ARRAY_CONSTRUCTORS",new Map([[o.UINT8.toString(),Uint8Array],[o.UINT16.toString(),Uint16Array],[o.UINT32.toString(),Uint32Array],[o.UINT64.toString(),BigUint64Array],[o.FLOAT32.toString(),Float32Array],[o.FLOAT64.toString(),Float64Array],[o.INT8.toString(),Int8Array],[o.INT16.toString(),Int16Array],[o.INT32.toString(),Int32Array],[o.INT64.toString(),BigInt64Array],[o.TIMESTAMP.toString(),BigInt64Array],[o.STRING.toString(),Uint8Array],[o.JSON.toString(),Uint8Array],[o.UUID.toString(),Uint8Array]])),u(o,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,o.UINT8],[Uint16Array.name,o.UINT16],[Uint32Array.name,o.UINT32],[BigUint64Array.name,o.UINT64],[Float32Array.name,o.FLOAT32],[Float64Array.name,o.FLOAT64],[Int8Array.name,o.INT8],[Int16Array.name,o.INT16],[Int32Array.name,o.INT32],[BigInt64Array.name,o.INT64]])),u(o,"DENSITIES",new Map([[o.UINT8.toString(),x.BIT8],[o.UINT16.toString(),x.BIT16],[o.UINT32.toString(),x.BIT32],[o.UINT64.toString(),x.BIT64],[o.FLOAT32.toString(),x.BIT32],[o.FLOAT64.toString(),x.BIT64],[o.INT8.toString(),x.BIT8],[o.INT16.toString(),x.BIT16],[o.INT32.toString(),x.BIT32],[o.INT64.toString(),x.BIT64],[o.TIMESTAMP.toString(),x.BIT64],[o.STRING.toString(),x.UNKNOWN],[o.JSON.toString(),x.UNKNOWN],[o.UUID.toString(),x.BIT128]])),u(o,"ALL",[o.UNKNOWN,o.FLOAT64,o.FLOAT32,o.INT64,o.INT32,o.INT16,o.INT8,o.UINT64,o.UINT32,o.UINT16,o.UINT8,o.TIMESTAMP,o.UUID,o.STRING,o.JSON]),u(o,"BIG_INT_TYPES",[o.INT64,o.UINT64,o.TIMESTAMP]),u(o,"z",i.z.union([i.z.string().transform(r=>new o(r)),i.z.instanceof(o)]));let w=o;const A=class I extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return I.bytes(this.valueOf()+e.valueOf())}sub(e){return I.bytes(this.valueOf()-e.valueOf())}truncate(e){return new I(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return I.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/I.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/I.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/I.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/I.TERABYTE.valueOf()}toString(){const e=this.truncate(I.TERABYTE),t=this.truncate(I.GIGABYTE),n=this.truncate(I.MEGABYTE),s=this.truncate(I.KILOBYTE),a=this.truncate(I.BYTE),c=e,d=t.sub(e),f=n.sub(t),p=s.sub(n),m=a.sub(s);let l="";return c.isZero||(l+=`${c.terabytes}TB `),d.isZero||(l+=`${d.gigabytes}GB `),f.isZero||(l+=`${f.megabytes}MB `),p.isZero||(l+=`${p.kilobytes}KB `),(!m.isZero||l==="")&&(l+=`${m.valueOf()}B`),l.trim()}static bytes(e=1){return new I(e)}static kilobytes(e=1){return I.bytes(e.valueOf()*1e3)}static megabytes(e=1){return I.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return I.megabytes(e.valueOf()*1e3)}static terabytes(e){return I.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};u(A,"BYTE",new A(1)),u(A,"KILOBYTE",A.kilobytes(1)),u(A,"MEGABYTE",A.megabytes(1)),u(A,"GIGABYTE",A.gigabytes(1)),u(A,"TERABYTE",A.terabytes(1)),u(A,"ZERO",new A(0)),u(A,"z",i.z.union([i.z.number().transform(r=>new A(r)),i.z.instanceof(A)]));let me=A;i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const nt=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof v||r instanceof O||r instanceof Date},or=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):J(t,-n).valueOf(),J=(r,e)=>typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:e===0?r:r===0?e:Number(r)+Number(e),ur=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof hr?!0:nt(r),k=-1,cr=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),lr=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),we=10,H=class U{constructor(e){u(this,"key",""),u(this,"isSynnaxSeries",!0),u(this,"dataType"),u(this,"sampleOffset"),u(this,"gl"),u(this,"_data"),u(this,"_timeRange"),u(this,"alignment",0n),u(this,"_cachedMin"),u(this,"_cachedMax"),u(this,"writePos",k),u(this,"_refCount",0),u(this,"_cachedLength"),u(this,"_cachedIndexes"),ur(e)&&(e={data:e});const{dataType:t,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:c=0n,key:d=ir()}=e,f=e.data??[];if(f instanceof U||typeof f=="object"&&"isSynnaxSeries"in f&&f.isSynnaxSeries===!0){const l=f;this.key=l.key,this.dataType=l.dataType,this.sampleOffset=l.sampleOffset,this.gl=l.gl,this._data=l._data,this._timeRange=l._timeRange,this.alignment=l.alignment,this._cachedMin=l._cachedMin,this._cachedMax=l._cachedMax,this.writePos=l.writePos,this._refCount=l._refCount,this._cachedLength=l._cachedLength;return}const p=nt(f),m=Array.isArray(f);if(t!=null)this.dataType=new w(t);else{if(f instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(m||p){let l=f;if(!p){if(f.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");l=f[0]}if(typeof l=="string")this.dataType=w.STRING;else if(typeof l=="number")this.dataType=w.FLOAT64;else if(typeof l=="bigint")this.dataType=w.INT64;else if(typeof l=="boolean")this.dataType=w.BOOLEAN;else if(l instanceof v||l instanceof Date||l instanceof v)this.dataType=w.TIMESTAMP;else if(typeof l=="object")this.dataType=w.JSON;else throw new Error(`cannot infer data type of ${typeof l} when constructing a Series from a JS array`)}else this.dataType=new w(f)}if(!m&&!p)this._data=f;else{let l=p?[f]:f;const N=l[0];(N instanceof v||N instanceof Date||N instanceof O)&&(l=l.map(M=>new v(M).valueOf())),this.dataType.equals(w.STRING)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(`${l.join(`
|
|
3
|
+
`).map(f=>f.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(f=>f.trim()),c={};return a.forEach(f=>{c[f]=[]}),s.forEach(f=>{const d=f.split(",").map(p=>p.trim());a.forEach((p,m)=>{const l=this.parseValue(d[m]);l!=null&&c[p].push(l)})}),t!=null?t.parse(c):c}parseValue(e){if(e==null||e.length===0)return null;const t=Number(e);return isNaN(t)?e.startsWith('"')&&e.endsWith('"')?e.slice(1,-1):e:t}static registerCustomType(){}},vt=class{constructor(){_(this,"contentType","text/plain")}encode(e){return new TextEncoder().encode(e).buffer}decode(e,t){const n=new TextDecoder().decode(e);return t!=null?t.parse(n):n}};const re=new Ot;new Tt;new vt;const St=r=>r!=null&&typeof r=="object"&&"toString"in r,It=(r,e=!1)=>{const t=St(r)?"stringer":typeof r;let n;switch(t){case"string":n=(s,a)=>s.localeCompare(a);break;case"stringer":n=(s,a)=>s.toString().localeCompare(a.toString());break;case"number":n=(s,a)=>Number(s)-Number(a);break;case"bigint":n=(s,a)=>BigInt(s)-BigInt(a)>0n?1:-1;break;case"boolean":n=(s,a)=>Number(s)-Number(a);break;case"undefined":n=()=>0;break;default:return console.warn(`sortFunc: unknown type ${t}`),()=>-1}return e?Nt(n):n},Nt=r=>(e,t)=>r(t,e),ue=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const He=i.z.object({width:i.z.number(),height:i.z.number()}),Et=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),At=["width","height"];i.z.enum(At);const xt=["start","center","end"],zt=["signedWidth","signedHeight"];i.z.enum(zt);const ie=i.z.object({x:i.z.number(),y:i.z.number()}),Mt=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),$t=["x","y"],Ke=i.z.enum($t),Xe=["top","right","bottom","left"];i.z.enum(Xe);const Ut=["left","right"],Qe=i.z.enum(Ut),Bt=["top","bottom"],_e=i.z.enum(Bt),et=["center"],xe=i.z.enum(et),Rt=[...Xe,...et],tt=i.z.enum(Rt);i.z.enum(xt);const Ct=["first","last"];i.z.enum(Ct);const Dt=i.z.object({lower:i.z.number(),upper:i.z.number()}),Pt=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([Dt,ue]);i.z.union([Pt,ue]);i.z.enum([...Ke.options,...tt.options]);i.z.union([Ke,tt,i.z.instanceof(String)]);const Lt=r=>typeof r=="bigint"||r instanceof BigInt,q=(r,e)=>Lt(r)?r.valueOf()*BigInt(e.valueOf()):r.valueOf()*Number(e.valueOf()),j=(r,e)=>{const t={};if(typeof r=="number"||typeof r=="bigint")e!=null?(t.lower=r,t.upper=e):(t.lower=typeof r=="bigint"?0n:0,t.upper=r);else if(Array.isArray(r)){if(r.length!==2)throw new Error("bounds: expected array of length 2");[t.lower,t.upper]=r}else return ze(r);return ze(t)},ze=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r,Me=(r,e)=>{const t=j(r);return e<t.lower?t.lower:e>=t.upper?t.upper-(typeof t.upper=="number"?1:1n):e};i.z.object({x:Qe.or(xe),y:_e.or(xe)});const Yt=i.z.object({x:Qe,y:_e}),kt=Object.freeze({x:"left",y:"top"}),jt=(r,e)=>r.x===e.x&&r.y===e.y,$e=i.z.union([i.z.number(),ie,ue,He,Et,Mt]),qt=(r,e)=>{if(typeof r=="string"){if(e===void 0)throw new Error("The y coordinate must be given.");return r==="x"?{x:e,y:0}:{x:0,y:e}}return typeof r=="number"?{x:r,y:e??r}:Array.isArray(r)?{x:r[0],y:r[1]}:"signedWidth"in r?{x:r.signedWidth,y:r.signedHeight}:"clientX"in r?{x:r.clientX,y:r.clientY}:"width"in r?{x:r.width,y:r.height}:{x:r.x,y:r.y}},Ue=Object.freeze({x:0,y:0}),te=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:te,left:te,width:te,height:te});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:ie,two:ie,root:Yt});const ve=(r,e,t=0,n=0,s)=>{const a={one:{...Ue},two:{...Ue},root:s??kt};if(typeof r=="number"){if(typeof e!="number")throw new Error("Box constructor called with invalid arguments");return a.one={x:r,y:e},a.two={x:a.one.x+t,y:a.one.y+n},a}return"one"in r&&"two"in r&&"root"in r?{...r,root:s??r.root}:("getBoundingClientRect"in r&&(r=r.getBoundingClientRect()),"left"in r?(a.one={x:r.left,y:r.top},a.two={x:r.right,y:r.bottom},a):(a.one=r,e==null?a.two={x:a.one.x+t,y:a.one.y+n}:typeof e=="number"?a.two={x:a.one.x+e,y:a.one.y+t}:"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))},fe=r=>{const e=ve(r);return{lower:e.one.x,upper:e.two.x}},de=r=>{const e=ve(r);return{lower:e.one.y,upper:e.two.y}},Ft=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r,Gt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([He,Gt,ie,ue]);var Wt=Object.defineProperty,Vt=(r,e,t)=>e in r?Wt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,D=(r,e,t)=>Vt(r,typeof e!="symbol"?e+"":e,t);const Zt=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;i.z.object({offset:$e,scale:$e});i.z.object({offset:i.z.number(),scale:i.z.number()});const Jt=r=>(e,t,n,s)=>t==="dimension"?[e,n]:[e,s?n-r:n+r],Ht=r=>(e,t,n,s)=>[e,s?n/r:n*r],Kt=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:s,upper:a}=e,{lower:c,upper:f}=r,d=a-s,p=f-c;if(t==="dimension")return[r,n*(p/d)];const m=(n-s)*(p/d)+c;return[r,m]},Xt=r=>(e,t,n)=>[r,n],Qt=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:s}=r;return[r,s-(t-n)]},_t=r=>(e,t,n)=>{const{lower:s,upper:a}=r;return n=Zt(n,s,a),[e,n]},ye=class V{constructor(){D(this,"ops",[]),D(this,"currBounds",null),D(this,"currType",null),D(this,"reversed",!1),this.ops=[]}static translate(e){return new V().translate(e)}static magnify(e){return new V().magnify(e)}static scale(e,t){return new V().scale(e,t)}translate(e){const t=this.new(),n=Jt(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Ht(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=j(e,t),s=this.new(),a=Kt(n);return a.type="scale",s.ops.push(a),s}clamp(e,t){const n=j(e,t),s=this.new(),a=_t(n);return a.type="clamp",s.ops.push(a),s}reBound(e,t){const n=j(e,t),s=this.new(),a=Xt(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=Qt();e.type="invert";const t=this.new();return t.ops.push(e),t}pos(e){return this.exec("position",e)}dim(e){return this.exec("dimension",e)}new(){const e=new V;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,s],a)=>a(n,e,s,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,s)=>{if(n.type==="scale"||t.some(([c,f])=>s>=c&&s<=f))return;const a=e.ops.findIndex((c,f)=>c.type==="scale"&&f>s);a!==-1&&t.push([s,a])}),t.forEach(([n,s])=>{const a=e.ops.slice(n,s);a.unshift(e.ops[s]),e.ops.splice(n,s-n+1,...a)}),e.reversed=!e.reversed,e}get transform(){return{scale:this.dim(1),offset:this.pos(0)}}};D(ye,"IDENTITY",new ye);let Be=ye;const Re=class C{constructor(e=new Be,t=new Be,n=null){D(this,"x"),D(this,"y"),D(this,"currRoot"),this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new C().translate(e,t)}static translateX(e){return new C().translateX(e)}static translateY(e){return new C().translateY(e)}static clamp(e){return new C().clamp(e)}static magnify(e){return new C().magnify(e)}static scale(e){return new C().scale(e)}static reBound(e){return new C().reBound(e)}translate(e,t){const n=qt(e,t),s=this.copy();return s.x=this.x.translate(n.x),s.y=this.y.translate(n.y),s}translateX(e){const t=this.copy();return t.x=this.x.translate(e),t}translateY(e){const t=this.copy();return t.y=this.y.translate(e),t}magnify(e){const t=this.copy();return t.x=this.x.magnify(e.x),t.y=this.y.magnify(e.y),t}scale(e){const t=this.copy();if(Ft(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!jt(n,e.root)&&(n.x!==e.root.x&&(t.x=t.x.invert()),n.y!==e.root.y&&(t.y=t.y.invert())),t.x=t.x.scale(fe(e)),t.y=t.y.scale(de(e)),t}return t.x=t.x.scale(e.width),t.y=t.y.scale(e.height),t}reBound(e){const t=this.copy();return t.x=this.x.reBound(fe(e)),t.y=this.y.reBound(de(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(fe(e)),t.y=this.y.clamp(de(e)),t}copy(){const e=new C;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)}}dim(e){return{x:this.x.dim(e.x),y:this.y.dim(e.y)}}box(e){return ve(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}get transform(){return{scale:this.dim({x:1,y:1}),offset:this.pos({x:0,y:0})}}};D(Re,"IDENTITY",new Re);var er=Object.defineProperty,tr=(r,e,t)=>e in r?er(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>tr(r,typeof e!="symbol"?e+"":e,t);let rr=(r,e=21)=>(t=e)=>{let n="",s=t|0;for(;s--;)n+=r[Math.random()*r.length|0];return n};const nr="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",sr=rr(nr,11),ir=()=>sr(),ar=i.z.enum(["static","dynamic"]),rt=(r,e)=>{const t=new v(e);if(![O.DAY,O.HOUR,O.MINUTE,O.SECOND,O.MILLISECOND,O.MICROSECOND,O.NANOSECOND].some(s=>s.equals(t)))throw new Error("Invalid argument for remainder. Must be an even TimeSpan or Timestamp");const n=r.valueOf()%t.valueOf();return r instanceof v?new v(n):new O(n)},w=class h{constructor(e,t="UTC"){if(u(this,"value"),u(this,"encodeValue",!0),e==null)this.value=h.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*h.MILLISECOND.valueOf();else if(typeof e=="string")this.value=h.parseDateTimeString(e,t).valueOf();else if(Array.isArray(e))this.value=h.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=h.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=h.MAX:e=h.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,t=1,n=1]){const s=new Date(e,t-1,n,0,0,0,0);return new h(BigInt(s.getTime())*h.MILLISECOND.valueOf()).truncate(h.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,s,a]=e.split(":");let c="00",f="00";a!=null&&([c,f]=a.split("."));let d=h.hours(parseInt(n??"00")).add(h.minutes(parseInt(s??"00"))).add(h.seconds(parseInt(c??"00"))).add(h.milliseconds(parseInt(f??"00")));return t==="local"&&(d=d.add(h.utcOffset)),d.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return h.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new h(BigInt(n.getTime())*h.MILLISECOND.valueOf(),t).valueOf()}fString(e="ISO",t="UTC"){switch(e){case"ISODate":return this.toISOString(t).slice(0,10);case"ISOTime":return this.toISOString(t).slice(11,23);case"time":return this.timeString(!1,t);case"preciseTime":return this.timeString(!0,t);case"date":return this.dateString();case"preciseDate":return`${this.dateString()} ${this.timeString(!0,t)}`;case"dateTime":return`${this.dateString()} ${this.timeString(!1,t)}`;default:return this.toISOString(t)}}toISOString(e="UTC"){return e==="UTC"?this.date().toISOString():this.sub(h.utcOffset).date().toISOString()}timeString(e=!1,t="UTC"){const n=this.toISOString(t);return e?n.slice(11,23):n.slice(11,19)}dateString(){const e=this.date(),t=e.toLocaleString("default",{month:"short"}),n=e.toLocaleString("default",{day:"numeric"});return`${t} ${n}`}static get utcOffset(){return new O(BigInt(new Date().getTimezoneOffset())*h.MINUTE.valueOf())}static since(e){return new h().span(e)}date(){return new Date(this.milliseconds)}equals(e){return this.valueOf()===new h(e).valueOf()}span(e){return this.range(e).span}range(e){return new Se(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 h(e).valueOf()}afterEq(e){return this.valueOf()>=new h(e).valueOf()}before(e){return this.valueOf()<new h(e).valueOf()}beforeEq(e){return this.valueOf()<=new h(e).valueOf()}add(e){return new h(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new h(this.valueOf()-BigInt(e.valueOf()))}get hours(){return Number(this.valueOf())/Number(O.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(O.MINUTE.valueOf())}get days(){return Number(this.valueOf())/Number(O.DAY.valueOf())}get seconds(){return Number(this.valueOf())/Number(O.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(h.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(h.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get year(){return this.date().getFullYear()}setYear(e){const t=this.date();return t.setFullYear(e),new h(t)}get month(){return this.date().getMonth()}setMonth(e){const t=this.date();return t.setMonth(e),new h(t)}get day(){return this.date().getDate()}setDay(e){const t=this.date();return t.setDate(e),new h(t)}get hour(){return this.date().getHours()}setHour(e){const t=this.date();return t.setHours(e),new h(t)}get minute(){return this.date().getMinutes()}setMinute(e){const t=this.date();return t.setMinutes(e),new h(t)}get second(){return this.date().getSeconds()}setSecond(e){const t=this.date();return t.setSeconds(e),new h(t)}get millisecond(){return this.date().getMilliseconds()}setMillisecond(e){const t=this.date();return t.setMilliseconds(e),new h(t)}toString(){return this.date().toISOString()}remainder(e){return rt(this,e)}get isToday(){return this.truncate(O.DAY).equals(h.now().truncate(O.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new h(new Date)}static max(...e){let t=h.MIN;for(const n of e){const s=new h(n);s.after(t)&&(t=s)}return t}static min(...e){let t=h.MAX;for(const n of e){const s=new h(n);s.before(t)&&(t=s)}return t}static nanoseconds(e){return new h(e)}static microseconds(e){return h.nanoseconds(e*1e3)}static milliseconds(e){return h.microseconds(e*1e3)}static seconds(e){return h.milliseconds(e*1e3)}static minutes(e){return h.seconds(e*60)}static hours(e){return h.minutes(e*60)}static days(e){return h.hours(e*24)}};u(w,"NANOSECOND",w.nanoseconds(1)),u(w,"MICROSECOND",w.microseconds(1)),u(w,"MILLISECOND",w.milliseconds(1)),u(w,"SECOND",w.seconds(1)),u(w,"MINUTE",w.minutes(1)),u(w,"HOUR",w.hours(1)),u(w,"DAY",w.days(1)),u(w,"MAX",new w((1n<<63n)-1n)),u(w,"MIN",new w(0)),u(w,"ZERO",new w(0)),u(w,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new w(r.value)),i.z.string().transform(r=>new w(BigInt(r))),i.z.instanceof(Number).transform(r=>new w(r)),i.z.number().transform(r=>new w(r)),i.z.instanceof(w)]));let v=w;const b=class g{constructor(e){u(this,"value"),u(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}static fromSeconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof v?new g(e):["number","bigint"].includes(typeof e)?g.seconds(e):new g(e)}static fromMilliseconds(e){return e instanceof g?e:e instanceof Ce?e.period:e instanceof v?new g(e):["number","bigint"].includes(typeof e)?g.milliseconds(e):new g(e)}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new g(e).valueOf()}greaterThan(e){return this.valueOf()>new g(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new g(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new g(e).valueOf()}remainder(e){return rt(this,e)}truncate(e){return new g(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(g.DAY),t=this.truncate(g.HOUR),n=this.truncate(g.MINUTE),s=this.truncate(g.SECOND),a=this.truncate(g.MILLISECOND),c=this.truncate(g.MICROSECOND),f=this.truncate(g.NANOSECOND),d=e,p=t.sub(e),m=n.sub(t),l=s.sub(n),N=a.sub(s),M=c.sub(a),B=f.sub(c);let z="";return d.isZero||(z+=`${d.days}d `),p.isZero||(z+=`${p.hours}h `),m.isZero||(z+=`${m.minutes}m `),l.isZero||(z+=`${l.seconds}s `),N.isZero||(z+=`${N.milliseconds}ms `),M.isZero||(z+=`${M.microseconds}µs `),B.isZero||(z+=`${B.nanoseconds}ns`),z.trim()}mult(e){return new g(this.valueOf()*BigInt(e))}get days(){return Number(this.valueOf())/Number(g.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(g.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(g.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(g.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(g.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(g.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new g(e).valueOf()}add(e){return new g(this.valueOf()+new g(e).valueOf())}sub(e){return new g(this.valueOf()-new g(e).valueOf())}static nanoseconds(e=1){return new g(e)}static microseconds(e=1){return g.nanoseconds(q(e,1e3))}static milliseconds(e=1){return g.microseconds(q(e,1e3))}static seconds(e=1){return g.milliseconds(q(e,1e3))}static minutes(e=1){return g.seconds(q(e,60))}static hours(e){return g.minutes(q(e,60))}static days(e){return g.hours(q(e,24))}};u(b,"NANOSECOND",b.nanoseconds(1)),u(b,"MICROSECOND",b.microseconds(1)),u(b,"MILLISECOND",b.milliseconds(1)),u(b,"SECOND",b.seconds(1)),u(b,"MINUTE",b.minutes(1)),u(b,"HOUR",b.hours(1)),u(b,"DAY",b.days(1)),u(b,"MAX",new b((1n<<63n)-1n)),u(b,"MIN",new b(0)),u(b,"ZERO",new b(0)),u(b,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new b(r.value)),i.z.string().transform(r=>new b(BigInt(r))),i.z.instanceof(Number).transform(r=>new b(r)),i.z.number().transform(r=>new b(r)),i.z.instanceof(b)]));let O=b;const Z=class ne extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new ne(e).valueOf()}get period(){return O.seconds(1/this.valueOf())}sampleCount(e){return new O(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new x(t).valueOf()}span(e){return O.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new ne(e)}static khz(e){return ne.hz(e*1e3)}};u(Z,"z",i.z.union([i.z.number().transform(r=>new Z(r)),i.z.instanceof(Number).transform(r=>new Z(r)),i.z.instanceof(Z)]));let Ce=Z;const E=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new me(e*this.valueOf())}};u(E,"UNKNOWN",new E(0)),u(E,"BIT128",new E(16)),u(E,"BIT64",new E(8)),u(E,"BIT32",new E(4)),u(E,"BIT16",new E(2)),u(E,"BIT8",new E(1)),u(E,"z",i.z.union([i.z.number().transform(r=>new E(r)),i.z.instanceof(Number).transform(r=>new E(r)),i.z.instanceof(E)]));let x=E;const $=class se{constructor(e,t){u(this,"start"),u(this,"end"),typeof e=="object"&&"start"in e?(this.start=new v(e.start),this.end=new v(e.end)):(this.start=new v(e),this.end=new v(t))}get span(){return new O(this.end.valueOf()-this.start.valueOf())}get isValid(){return this.start.valueOf()<=this.end.valueOf()}makeValid(){return this.isValid?this:this.swap()}get isZero(){return this.span.isZero}get numeric(){return{start:Number(this.start.valueOf()),end:Number(this.end.valueOf())}}swap(){return new se(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,t=O.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 s=v.max(n.start,e.start),a=v.min(n.end,e.end);return a.before(s)?!1:new O(a.sub(s)).greaterThanOrEqual(t)}roughlyEquals(e,t){let n=this.start.sub(e.start).valueOf(),s=this.end.sub(e.end).valueOf();return n<0&&(n=-n),s<0&&(s=-s),n<=t.valueOf()&&s<=t.valueOf()}contains(e){return e instanceof se?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new se(this.start,this.end);return e.start.after(this.start)&&(t.start=e.start),e.start.after(this.end)&&(t.end=e.start),e.end.before(this.end)&&(t.end=e.end),e.end.before(this.start)&&(t.start=e.end),t}};u($,"MAX",new $(v.MIN,v.MAX)),u($,"MIN",new $(v.MAX,v.MIN)),u($,"ZERO",new $(v.ZERO,v.ZERO)),u($,"z",i.z.union([i.z.object({start:v.z,end:v.z}).transform(r=>new $(r.start,r.end)),i.z.instanceof($)]));let Se=$;const o=class S extends String{constructor(e){if(e instanceof S||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}const t=S.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}throw super(S.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=S.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(t=>this.equals(t))}toString(){return this.valueOf()}get isVariable(){return this.equals(S.JSON)||this.equals(S.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(S.UUID)}get isInteger(){const e=this.toString();return e.startsWith("int")||e.startsWith("uint")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=S.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}get isUnsigned(){return this.equals(S.UINT8)||this.equals(S.UINT16)||this.equals(S.UINT32)||this.equals(S.UINT64)}get isSigned(){return this.equals(S.INT8)||this.equals(S.INT16)||this.equals(S.INT32)||this.equals(S.INT64)}canSafelyCastTo(e){return this.equals(e)?!0:!this.isNumeric||!e.isNumeric||this.isVariable||e.isVariable||this.isUnsigned&&e.isSigned?!1:this.isFloat?e.isFloat&&this.density.valueOf()<=e.density.valueOf():this.equals(S.INT32)&&e.equals(S.FLOAT64)||this.equals(S.INT8)&&e.equals(S.FLOAT32)?!0:this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf()&&this.isUnsigned===e.isUnsigned:!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 S.BIG_INT_TYPES.some(e=>e.equals(this))}};u(o,"UNKNOWN",new o("unknown")),u(o,"FLOAT64",new o("float64")),u(o,"FLOAT32",new o("float32")),u(o,"INT64",new o("int64")),u(o,"INT32",new o("int32")),u(o,"INT16",new o("int16")),u(o,"INT8",new o("int8")),u(o,"UINT64",new o("uint64")),u(o,"UINT32",new o("uint32")),u(o,"UINT16",new o("uint16")),u(o,"UINT8",new o("uint8")),u(o,"BOOLEAN",o.UINT8),u(o,"TIMESTAMP",new o("timestamp")),u(o,"UUID",new o("uuid")),u(o,"STRING",new o("string")),u(o,"JSON",new o("json")),u(o,"ARRAY_CONSTRUCTORS",new Map([[o.UINT8.toString(),Uint8Array],[o.UINT16.toString(),Uint16Array],[o.UINT32.toString(),Uint32Array],[o.UINT64.toString(),BigUint64Array],[o.FLOAT32.toString(),Float32Array],[o.FLOAT64.toString(),Float64Array],[o.INT8.toString(),Int8Array],[o.INT16.toString(),Int16Array],[o.INT32.toString(),Int32Array],[o.INT64.toString(),BigInt64Array],[o.TIMESTAMP.toString(),BigInt64Array],[o.STRING.toString(),Uint8Array],[o.JSON.toString(),Uint8Array],[o.UUID.toString(),Uint8Array]])),u(o,"ARRAY_CONSTRUCTOR_DATA_TYPES",new Map([[Uint8Array.name,o.UINT8],[Uint16Array.name,o.UINT16],[Uint32Array.name,o.UINT32],[BigUint64Array.name,o.UINT64],[Float32Array.name,o.FLOAT32],[Float64Array.name,o.FLOAT64],[Int8Array.name,o.INT8],[Int16Array.name,o.INT16],[Int32Array.name,o.INT32],[BigInt64Array.name,o.INT64]])),u(o,"DENSITIES",new Map([[o.UINT8.toString(),x.BIT8],[o.UINT16.toString(),x.BIT16],[o.UINT32.toString(),x.BIT32],[o.UINT64.toString(),x.BIT64],[o.FLOAT32.toString(),x.BIT32],[o.FLOAT64.toString(),x.BIT64],[o.INT8.toString(),x.BIT8],[o.INT16.toString(),x.BIT16],[o.INT32.toString(),x.BIT32],[o.INT64.toString(),x.BIT64],[o.TIMESTAMP.toString(),x.BIT64],[o.STRING.toString(),x.UNKNOWN],[o.JSON.toString(),x.UNKNOWN],[o.UUID.toString(),x.BIT128]])),u(o,"ALL",[o.UNKNOWN,o.FLOAT64,o.FLOAT32,o.INT64,o.INT32,o.INT16,o.INT8,o.UINT64,o.UINT32,o.UINT16,o.UINT8,o.TIMESTAMP,o.UUID,o.STRING,o.JSON]),u(o,"BIG_INT_TYPES",[o.INT64,o.UINT64,o.TIMESTAMP]),u(o,"z",i.z.union([i.z.string().transform(r=>new o(r)),i.z.instanceof(o)]));let T=o;const A=class I extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return I.bytes(this.valueOf()+e.valueOf())}sub(e){return I.bytes(this.valueOf()-e.valueOf())}truncate(e){return new I(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return I.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/I.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/I.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/I.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/I.TERABYTE.valueOf()}toString(){const e=this.truncate(I.TERABYTE),t=this.truncate(I.GIGABYTE),n=this.truncate(I.MEGABYTE),s=this.truncate(I.KILOBYTE),a=this.truncate(I.BYTE),c=e,f=t.sub(e),d=n.sub(t),p=s.sub(n),m=a.sub(s);let l="";return c.isZero||(l+=`${c.terabytes}TB `),f.isZero||(l+=`${f.gigabytes}GB `),d.isZero||(l+=`${d.megabytes}MB `),p.isZero||(l+=`${p.kilobytes}KB `),(!m.isZero||l==="")&&(l+=`${m.valueOf()}B`),l.trim()}static bytes(e=1){return new I(e)}static kilobytes(e=1){return I.bytes(e.valueOf()*1e3)}static megabytes(e=1){return I.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return I.megabytes(e.valueOf()*1e3)}static terabytes(e){return I.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};u(A,"BYTE",new A(1)),u(A,"KILOBYTE",A.kilobytes(1)),u(A,"MEGABYTE",A.megabytes(1)),u(A,"GIGABYTE",A.gigabytes(1)),u(A,"TERABYTE",A.terabytes(1)),u(A,"ZERO",new A(0)),u(A,"z",i.z.union([i.z.number().transform(r=>new A(r)),i.z.instanceof(A)]));let me=A;i.z.union([i.z.instanceof(Uint8Array),i.z.instanceof(Uint16Array),i.z.instanceof(Uint32Array),i.z.instanceof(BigUint64Array),i.z.instanceof(Float32Array),i.z.instanceof(Float64Array),i.z.instanceof(Int8Array),i.z.instanceof(Int16Array),i.z.instanceof(Int32Array),i.z.instanceof(BigInt64Array)]);const nt=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof v||r instanceof O||r instanceof Date},or=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t.valueOf())-BigInt(n.valueOf()):J(t,-n).valueOf(),J=(r,e)=>typeof r=="bigint"&&typeof e=="bigint"||typeof r=="number"&&typeof e=="number"?r+e:e===0?r:r===0?e:Number(r)+Number(e),ur=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof fr?!0:nt(r),k=-1,cr=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),lr=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),we=10,hr=(r,e)=>{if(r==="string"&&!e.isVariable)throw new Error(`cannot convert series of type ${e.toString()} to string`);if(r==="number"&&!e.isNumeric)throw new Error(`cannot convert series of type ${e.toString()} to number`);if(r==="bigint"&&!e.usesBigInt)throw new Error(`cannot convert series of type ${e.toString()} to bigint`)},H=class U{constructor(e){u(this,"key",""),u(this,"isSynnaxSeries",!0),u(this,"dataType"),u(this,"sampleOffset"),u(this,"gl"),u(this,"_data"),u(this,"_timeRange"),u(this,"alignment",0n),u(this,"_cachedMin"),u(this,"_cachedMax"),u(this,"writePos",k),u(this,"_refCount",0),u(this,"_cachedLength"),u(this,"_cachedIndexes"),ur(e)&&(e={data:e});const{dataType:t,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:c=0n,key:f=ir()}=e,d=e.data??[];if(d instanceof U||typeof d=="object"&&"isSynnaxSeries"in d&&d.isSynnaxSeries===!0){const l=d;this.key=l.key,this.dataType=l.dataType,this.sampleOffset=l.sampleOffset,this.gl=l.gl,this._data=l._data,this._timeRange=l._timeRange,this.alignment=l.alignment,this._cachedMin=l._cachedMin,this._cachedMax=l._cachedMax,this.writePos=l.writePos,this._refCount=l._refCount,this._cachedLength=l._cachedLength;return}const p=nt(d),m=Array.isArray(d);if(t!=null)this.dataType=new T(t);else{if(d instanceof ArrayBuffer)throw new Error("cannot infer data type from an ArrayBuffer instance when constructing a Series. Please provide a data type.");if(m||p){let l=d;if(!p){if(d.length===0)throw new Error("cannot infer data type from a zero length JS array when constructing a Series. Please provide a data type.");l=d[0]}if(typeof l=="string")this.dataType=T.STRING;else if(typeof l=="number")this.dataType=T.FLOAT64;else if(typeof l=="bigint")this.dataType=T.INT64;else if(typeof l=="boolean")this.dataType=T.BOOLEAN;else if(l instanceof v||l instanceof Date||l instanceof v)this.dataType=T.TIMESTAMP;else if(typeof l=="object")this.dataType=T.JSON;else throw new Error(`cannot infer data type of ${typeof l} when constructing a Series from a JS array`)}else this.dataType=new T(d)}if(!m&&!p)this._data=d;else{let l=p?[d]:d;const N=l[0];(N instanceof v||N instanceof Date||N instanceof O)&&(l=l.map(M=>new v(M).valueOf())),this.dataType.equals(T.STRING)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(`${l.join(`
|
|
4
4
|
`)}
|
|
5
|
-
`).buffer):this.dataType.equals(
|
|
5
|
+
`).buffer):this.dataType.equals(T.JSON)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(`${l.map(M=>re.encodeString(M)).join(`
|
|
6
6
|
`)}
|
|
7
|
-
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(l.map(M=>BigInt(Math.round(M)))).buffer:!this.dataType.usesBigInt&&typeof N=="bigint"?this._data=new this.dataType.Array(l.map(M=>Number(M))).buffer:this._data=new this.dataType.Array(l).buffer}this.key=
|
|
7
|
+
`).buffer):this.dataType.usesBigInt&&typeof N=="number"?this._data=new this.dataType.Array(l.map(M=>BigInt(Math.round(M)))).buffer:!this.dataType.usesBigInt&&typeof N=="bigint"?this._data=new this.dataType.Array(l.map(M=>Number(M))).buffer:this._data=new this.dataType.Array(l).buffer}this.key=f,this.alignment=c,this.sampleOffset=s??0,this._timeRange=n,this.gl={control:null,buffer:null,prevBuffer:0,bufferUsage:a}}static alloc({capacity:e,dataType:t,...n}){if(e===0)throw new Error("[Series] - cannot allocate an array of length 0");const s=new new T(t).Array(e),a=new U({data:s.buffer,dataType:t,...n});return a.writePos=0,a}static createTimestamps(e,t,n){const s=n.spanRange(t.span(e)),a=new BigInt64Array(e);for(let c=0;c<e;c++)a[c]=BigInt(n.add(t.span(c)).valueOf());return new U({data:a,dataType:T.TIMESTAMP,timeRange:s})}get refCount(){return this._refCount}static fromStrings(e,t){const n=new TextEncoder().encode(`${e.join(`
|
|
8
8
|
`)}
|
|
9
|
-
`);return new U({data:n,dataType:
|
|
9
|
+
`);return new U({data:n,dataType:T.STRING,timeRange:t})}static fromJSON(e,t){const n=new TextEncoder().encode(`${e.map(s=>re.encodeString(s)).join(`
|
|
10
10
|
`)}
|
|
11
|
-
`);return new U({data:n,dataType:
|
|
12
|
-
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(
|
|
13
|
-
`).slice(0,-1).map(t=>e.parse(re.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new me(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===k?this.byteCapacity:this.dataType.isVariable?new me(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===k?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;const t=[0];return this.data.forEach((n,s)=>{n===we&&(e++,t.push(s+1))}),this._cachedIndexes=t,this._cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=or(this.dataType,e,this.data[s],t);return new U({data:n.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(w.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((t,n)=>t>n?t:n)}else{const e=this.data;this._cachedMax=e.reduce((t,n)=>t>n?t: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??(this._cachedMax=this.calcRawMax()),J(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(w.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((t,n)=>t<n?t:n)}else{const e=this.data;this._cachedMin=e.reduce((t,n)=>t<n?t: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??(this._cachedMin=this.calcRawMin()),J(this._cachedMin,this.sampleOffset))}get bounds(){return j(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const t=e._cachedMin??e.calcRawMin();t<this._cachedMin&&(this._cachedMin=t)}if(this._cachedMax!=null){const t=e._cachedMax??e.calcRawMax();t>this._cachedMax&&(this._cachedMax=t)}}enrich(){this.max,this.min}get range(){return J(this.max,-this.min)}atAlignment(e,t){const n=Number(e-this.alignment);if(n<0||n>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t){if(this.dataType.isVariable)return this.atVariable(e,t??!1);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return J(n,this.sampleOffset)}atVariable(e,t){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let c=0;c<this.data.length;c++)if(this.data[c]===we){if(e===0){s=c;break}n=c+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(w.STRING)?new TextDecoder().decode(a):Ze(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const s=It(e);for(;t<=n;){const a=Math.floor((t+n)/2),c=s(this.at(a,!0),e);if(c===0)return a;c<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(w.FLOAT32)&&!this.dataType.equals(w.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:s}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==k){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,c.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=k}as(e){if(e==="string"){if(!this.dataType.equals(w.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(w.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:{lower:je(this.alignmentBounds.lower),upper:je(this.alignmentBounds.upper)},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 j(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 dr(this);return this.dataType.equals(w.JSON)?new fr(e):e}return new gr(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new De(this,e,t??this.length)}subAlignmentIterator(e,t){return new De(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new U({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,n){if(t<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(t,n):s=this.data.slice(t,n),new U({data:s,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new U({data:this.buffer,dataType:this.dataType,timeRange:Se.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};u(H,"crudeZ",i.z.object({timeRange:Se.z.optional(),dataType:w.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([cr,lr,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:ar.optional().default("static").optional()})),u(H,"z",H.crudeZ.transform(r=>new H(r)));let hr=H;class De{constructor(e,t,n){u(this,"series"),u(this,"end"),u(this,"index"),this.series=e;const s=j(0,e.length);this.end=Me(s,n),this.index=Me(s,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class dr{constructor(e){if(u(this,"series"),u(this,"index"),u(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,t=this.series.data;for(;this.index<t.length&&t[this.index]!==we;)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 Pe,Le;class fr{constructor(e){u(this,"wrapped"),u(this,Pe,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:re.decodeString(e.value)}}[(Le=Symbol.iterator,Pe=Symbol.toStringTag,Le)](){return this}}var Ye,ke;class gr{constructor(e){u(this,"series"),u(this,"index"),u(this,Ye,"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)}}[(ke=Symbol.iterator,Ye=Symbol.toStringTag,ke)](){return this}}const je=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const st=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",pr=st(),it=["macOS","Windows","Linux"],yr=["macos","windows","linux"],mr={macos:"macOS",windows:"Windows",linux:"Linux"},wr=i.z.enum(it).or(i.z.enum(yr).transform(r=>mr[r])),br=()=>{if(typeof window>"u")return;const r=window.navigator.userAgent.toLowerCase();if(r.includes("mac"))return"macOS";if(r.includes("win"))return"Windows";if(r.includes("linux"))return"Linux"};let ge;const Tr=(r={})=>{const{force:e,default:t}=r;return e??ge??(ge=br(),ge??t)},at=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:it,RUNTIME:pr,detect:st,getOS:Tr,osZ:wr},Symbol.toStringTag,{value:"Module"}));var Or=Object.defineProperty,vr=(r,e,t)=>e in r?Or(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,X=(r,e,t)=>vr(r,typeof e!="symbol"?e+"":e,t);const Sr=(...r)=>r.map(ot).join(""),ot=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Ir=r=>r.endsWith("/")?r.slice(0,-1):r,Nr=(r,e="")=>r===null?"":`?${Object.entries(r).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,n])=>`${e}${t}=${n}`).join("&")}`,be=class Te{constructor({host:e,port:t,protocol:n="",pathPrefix:s=""}){X(this,"protocol"),X(this,"host"),X(this,"port"),X(this,"path"),this.protocol=n,this.host=e,this.port=t,this.path=ot(s)}replace(e){return new Te({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Te({...this,pathPrefix:Sr(this.path,e)})}toString(){return Ir(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};X(be,"UNKNOWN",new be({host:"unknown",port:0}));let Er=be;const Ar=-128,xr=127;i.z.number().int().min(Ar).max(xr);const zr=-32768,Mr=32767;i.z.number().int().min(zr).max(Mr);const $r=-2147483648,Ur=2147483647;i.z.number().int().min($r).max(Ur);const Br=-9223372036854775808n,Rr=9223372036854775807n;i.z.bigint().min(Br).max(Rr);const Cr=255;i.z.number().int().min(0).max(Cr);const Dr=65535;i.z.number().int().min(0).max(Dr);const Pr=4294967295;i.z.number().int().min(0).max(Pr);const Lr=18446744073709551615n;i.z.bigint().min(0n).max(Lr);var Yr=Object.defineProperty,kr=(r,e,t)=>e in r?Yr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,K=(r,e,t)=>kr(r,typeof e!="symbol"?e+"":e,t);const jr=async r=>await new Promise(e=>setTimeout(e,O.fromMilliseconds(r).milliseconds)),qr=i.z.object({interval:O.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Fr=(r={})=>{const e=r.sleepFn||jr,t=r.maxRetries??5,n=r.scale??1;let s=0,a=new O(r.interval??O.milliseconds(1));return async()=>s>=t?!1:(await e(a),a=a.mult(n),s++,!0)},Gr=Object.freeze(Object.defineProperty({__proto__:null,breakerConfig:qr,create:Fr},Symbol.toStringTag,{value:"Module"})),R=class extends Number{};K(R,"ABSOLUTE",255),K(R,"MINIMUM",0),K(R,"BOUNDS",{lower:R.MINIMUM,upper:R.ABSOLUTE+1}),K(R,"z",i.z.union([i.z.instanceof(R),i.z.number().int().min(0).max(255).transform(r=>new R(r)),i.z.instanceof(Number).transform(r=>new R(r))]));i.z.object({name:i.z.string(),key:i.z.string()});const ut=class Q extends Error{constructor(){super(Q.MESSAGE)}matches(e){return typeof e=="string"?e.includes(Q.MESSAGE):e instanceof Q||e.message.includes(Q.MESSAGE)}};K(ut,"MESSAGE","canceled");let Wr=ut;new Wr;i.z.string().regex(/^\d+\.\d+\.\d+$/);const ce=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(r):e instanceof Error?e.message.includes(r):typeof e!="string"?!1:e.includes(r);class ee extends Error{constructor(){super(...arguments);y(this,"discriminator","FreighterError");y(this,"type","")}}const Vr=r=>{if(r==null||typeof r!="object")return!1;const e=r;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},qe="unknown",Fe="nil",Zr="freighter",Ie=i.z.object({type:i.z.string(),data:i.z.string()});class Jr{constructor(){y(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Fe,data:""};if(Vr(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}return{type:qe,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Fe)return null;if(e.type===qe)return new Ge(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Ge(e.data)}}const Ne=new Jr,ct=({encode:r,decode:e})=>Ne.register({encode:r,decode:e}),Hr=r=>Ne.encode(r),ae=r=>Ne.decode(r);class Ge extends ee{constructor(){super(...arguments);y(this,"type","unknown")}}const le="freighter.",F=class F extends ee{constructor(){super("EOF");y(this,"type",F.TYPE)}};y(F,"TYPE",`${le}eof`),y(F,"matches",ce(F.TYPE));let P=F;const G=class G extends ee{constructor(){super("StreamClosed");y(this,"type",G.TYPE)}};y(G,"TYPE",`${le}stream_closed`),y(G,"matches",ce(G.TYPE));let L=G;const W=class W extends ee{constructor(t={}){const{message:n="Unreachable",url:s=Er.UNKNOWN}=t;super(n);y(this,"type",W.TYPE);y(this,"url");this.url=s}};y(W,"TYPE",`${le}unreachable`),y(W,"matches",ce(W.TYPE));let Y=W;const Xr=r=>{if(!r.type.startsWith(Zr))return null;if(P.matches(r))return{type:P.TYPE,data:"EOF"};if(L.matches(r))return{type:L.TYPE,data:"StreamClosed"};if(Y.matches(r))return{type:Y.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Kr=r=>{if(!r.type.startsWith(le))return null;switch(r.type){case P.TYPE:return new P;case L.TYPE:return new L;case Y.TYPE:return new Y;default:throw new Error(`Unknown error type: ${r.data}`)}};ct({encode:Xr,decode:Kr});class lt{constructor(){y(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const s=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,s)};return await s(e)}}const ht="Content-Type",We=r=>{if(at.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(r==="http")return e;const t=require("https"),n=new t.Agent({rejectUnauthorized:!1});return async(s,a)=>await e(s,{...a,agent:n})};class Qr extends lt{constructor(t,n,s=!1){super();y(this,"endpoint");y(this,"encoder");y(this,"fetch");return this.endpoint=t.replace({protocol:s?"https":"http"}),this.encoder=n,this.fetch=We(this.endpoint.protocol),new Proxy(this,{get:(a,c,d)=>c==="endpoint"?this.endpoint:Reflect.get(a,c,d)})}get headers(){return{[ht]:this.encoder.contentType}}async send(t,n,s,a){n=s==null?void 0:s.parse(n);let c=null;const d=this.endpoint.child(t),f={};f.method="POST",f.body=this.encoder.encode(n??{});const[,p]=await this.executeMiddleware({target:d.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async m=>{const l={...m,params:{}};f.headers={...this.headers,...m.params};let N;try{N=await We(m.protocol)(m.target,f)}catch(B){let z=B;return z.message==="Load failed"&&(z=new Y({url:d})),[l,z]}const M=await N.arrayBuffer();if(N!=null&&N.ok)return a!=null&&(c=this.encoder.decode(M,a)),[l,null];try{if(N.status!==400)return[l,new Error(N.statusText)];const B=this.encoder.decode(M,Ie),z=ae(B);return[l,z]}catch(B){return[l,new Error(`[freighter] - failed to decode error: ${N.statusText}: ${B.message}`)]}});return[c,p]}}const _r=(r,e)=>{class t{constructor(s){y(this,"wrapped");this.wrapped=s}use(...s){this.wrapped.use(...s)}async send(s,a,c,d){const f=Gr.create(e);do{const[p,m]=await this.wrapped.send(s,a,c,d);if(m==null||!Y.matches(m))return[p,m];if(!await f())return[p,m]}while(!0)}}return new t(r)},en=async(r,e,t,n,s)=>{const[a,c]=await r.send(e,t,n,s);if(c!=null)throw c;return a},tn=()=>at.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),rn=i.z.object({type:i.z.enum(["data","close","open"]),payload:i.z.unknown().optional(),error:i.z.optional(Ie)});class nn{constructor(e,t,n,s){y(this,"encoder");y(this,"reqSchema");y(this,"resSchema");y(this,"ws");y(this,"serverClosed");y(this,"sendClosed");y(this,"receiveDataQueue",[]);y(this,"receiveCallbacksQueue",[]);this.encoder=t,this.reqSchema=n,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return ae(e.error)}return null}send(e){if(this.serverClosed!=null)return new P;if(this.sendClosed)throw new L;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=ae(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(){const e=this.receiveDataQueue.shift();return e??await new Promise((t,n)=>this.receiveCallbacksQueue.push({resolve:t,reject:n}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,rn)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:cn(e)?P.TYPE:L.TYPE,data:""}})}}const sn="freighterctx",an=1e3,on=1001,un=[an,on],cn=r=>un.includes(r.code),oe=class oe extends lt{constructor(t,n,s=!1){super();y(this,"baseUrl");y(this,"encoder");this.baseUrl=t.replace({protocol:s?"wss":"ws"}),this.encoder=n}async stream(t,n,s){const a=tn();let c;const[,d]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async f=>{const p=a(this.buildURL(t,f)),m={...f,params:{}};p.binaryType=oe.MESSAGE_TYPE;const l=await this.wrapSocket(p,n,s);return l instanceof Error?[m,l]:(c=l,[m,null])});if(d!=null)throw d;return c}buildURL(t,n){const s=Nr({[ht]:this.encoder.contentType,...n.params},sn);return this.baseUrl.child(t).toString()+s}async wrapSocket(t,n,s){return await new Promise(a=>{t.onopen=()=>{const c=new nn(t,this.encoder,n,s);c.receiveOpenAck().then(d=>{d!=null?a(d):a(c)}).catch(d=>a(d))},t.onerror=c=>{const d=c;a(new Error(d.message))}})}};y(oe,"MESSAGE_TYPE","arraybuffer");let Oe=oe;exports.BaseTypedError=ee;exports.EOF=P;exports.HTTPClient=Qr;exports.StreamClosed=L;exports.Unreachable=Y;exports.WebSocketClient=Oe;exports.decodeError=ae;exports.encodeError=Hr;exports.errorMatcher=ce;exports.errorZ=Ie;exports.registerError=ct;exports.sendRequired=en;exports.unaryWithBreaker=_r;
|
|
11
|
+
`);return new U({data:n,dataType:T.JSON,timeRange:t})}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");return this.dataType.isVariable?this.writeVariable(e):this.writeFixed(e)}writeVariable(e){if(this.writePos===k)return 0;const t=this.byteCapacity.valueOf()-this.writePos,n=e.subBytes(0,t);return this.writeToUnderlyingData(n),this.writePos+=n.byteLength.valueOf(),this._cachedLength!=null&&(this._cachedLength+=n.length,this.calculateCachedLength()),n.length}writeFixed(e){if(this.writePos===k)return 0;const t=this.capacity-this.writePos,n=e.sub(0,t);return this.writeToUnderlyingData(n),this._cachedLength=void 0,this.maybeRecomputeMinMax(n),this.writePos+=n.length,n.length}writeToUnderlyingData(e){this.underlyingData.set(e.data,this.writePos)}get buffer(){return typeof this._data=="object"&&"buffer"in this._data?this._data.buffer:this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===k?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(T.STRING,T.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.underlyingData).split(`
|
|
12
|
+
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(T.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=T.UUID.density.valueOf(),t=Array(this.length);for(let n=0;n<this.length;n++){const s=this.underlyingData.slice(n*e,(n+1)*e),a=Array.from(new Uint8Array(s.buffer),c=>c.toString(16).padStart(2,"0")).join("").replace(/(.{8})(.{4})(.{4})(.{4})(.{12})/,"$1-$2-$3-$4-$5");t[n]=a}return t}parseJSON(e){if(!this.dataType.equals(T.JSON))throw new Error("cannot parse non-JSON series as JSON");return new TextDecoder().decode(this.underlyingData).split(`
|
|
13
|
+
`).slice(0,-1).map(t=>e.parse(re.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new me(this.underlyingData.byteLength)}get capacity(){return this.dataType.isVariable?this.byteCapacity.valueOf():this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===k?this.byteCapacity:this.dataType.isVariable?new me(this.writePos):this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===k?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;const t=[0];return this.data.forEach((n,s)=>{n===we&&(e++,t.push(s+1))}),this._cachedIndexes=t,this._cachedLength=e,e}convert(e,t=0){if(this.dataType.equals(e))return this;const n=new e.Array(this.length);for(let s=0;s<this.length;s++)n[s]=or(this.dataType,e,this.data[s],t);return new U({data:n.buffer,dataType:e,timeRange:this._timeRange,sampleOffset:t,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment})}calcRawMax(){if(this.length===0)return-1/0;if(this.dataType.equals(T.TIMESTAMP))this._cachedMax=this.data[this.data.length-1];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMax=e.reduce((t,n)=>t>n?t:n)}else{const e=this.data;this._cachedMax=e.reduce((t,n)=>t>n?t: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??(this._cachedMax=this.calcRawMax()),J(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(T.TIMESTAMP))this._cachedMin=this.data[0];else if(this.dataType.usesBigInt){const e=this.data;this._cachedMin=e.reduce((t,n)=>t<n?t:n)}else{const e=this.data;this._cachedMin=e.reduce((t,n)=>t<n?t: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??(this._cachedMin=this.calcRawMin()),J(this._cachedMin,this.sampleOffset))}get bounds(){return j(Number(this.min),Number(this.max))}maybeRecomputeMinMax(e){if(this._cachedMin!=null){const t=e._cachedMin??e.calcRawMin();t<this._cachedMin&&(this._cachedMin=t)}if(this._cachedMax!=null){const t=e._cachedMax??e.calcRawMax();t>this._cachedMax&&(this._cachedMax=t)}}enrich(){this.max,this.min}get range(){return J(this.max,-this.min)}atAlignment(e,t){const n=Number(e-this.alignment);if(n<0||n>=this.length){if(t===!0)throw new Error(`[series] - no value at index ${n}`);return}return this.at(n,t)}at(e,t){if(this.dataType.isVariable)return this.atVariable(e,t??!1);e<0&&(e=this.length+e);const n=this.data[e];if(n==null){if(t===!0)throw new Error(`[series] - no value at index ${e}`);return}return J(n,this.sampleOffset)}atVariable(e,t){let n=0,s=0;if(this._cachedIndexes!=null)n=this._cachedIndexes[e],s=this._cachedIndexes[e+1]-1;else{e<0&&(e=this.length+e);for(let c=0;c<this.data.length;c++)if(this.data[c]===we){if(e===0){s=c;break}n=c+1,e--}if(s===0&&(s=this.data.length),n>=s||e>0){if(t)throw new Error(`[series] - no value at index ${e}`);return}}const a=this.data.slice(n,s);return this.dataType.equals(T.STRING)?new TextDecoder().decode(a):Ze(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const s=It(e);for(;t<=n;){const a=Math.floor((t+n)/2),c=s(this.at(a,!0),e);if(c===0)return a;c<0?t=a+1:n=a-1}return t}updateGLBuffer(e){if(this.gl.control=e,!this.dataType.equals(T.FLOAT32)&&!this.dataType.equals(T.UINT8))throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");const{buffer:t,bufferUsage:n,prevBuffer:s}=this.gl;if(t==null&&(this.gl.buffer=e.createBuffer()),this.writePos!==s)if(e.bindBuffer(e.ARRAY_BUFFER,this.gl.buffer),this.writePos!==k){s===0&&e.bufferData(e.ARRAY_BUFFER,this.byteCapacity.valueOf(),e.STATIC_DRAW);const a=this.dataType.density.size(s).valueOf(),c=this.underlyingData.slice(this.gl.prevBuffer,this.writePos);e.bufferSubData(e.ARRAY_BUFFER,a,c.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=k}as(e){return hr(e,this.dataType),this}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:{lower:je(this.alignmentBounds.lower),upper:je(this.alignmentBounds.upper)},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 j(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 dr(this);return this.dataType.equals(T.JSON)?new gr(e):e}return new pr(this)}slice(e,t){return this.sliceSub(!1,e,t)}sub(e,t){return this.sliceSub(!0,e,t)}subIterator(e,t){return new De(this,e,t??this.length)}subAlignmentIterator(e,t){return new De(this,Number(e-this.alignment),Number(t-this.alignment))}subBytes(e,t){if(e>=0&&(t==null||t>=this.byteLength.valueOf()))return this;const n=this.data.subarray(e,t);return new U({data:n,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(e)})}sliceSub(e,t,n){if(t<=0&&(n==null||n>=this.length))return this;let s;return e?s=this.data.subarray(t,n):s=this.data.slice(t,n),new U({data:s,dataType:this.dataType,timeRange:this._timeRange,sampleOffset:this.sampleOffset,glBufferUsage:this.gl.bufferUsage,alignment:this.alignment+BigInt(t)})}reAlign(e){return new U({data:this.buffer,dataType:this.dataType,timeRange:Se.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};u(H,"crudeZ",i.z.object({timeRange:Se.z.optional(),dataType:T.z,alignment:i.z.coerce.bigint().optional(),data:i.z.union([cr,lr,i.z.instanceof(ArrayBuffer),i.z.instanceof(Uint8Array)]),glBufferUsage:ar.optional().default("static").optional()})),u(H,"z",H.crudeZ.transform(r=>new H(r)));let fr=H;class De{constructor(e,t,n){u(this,"series"),u(this,"end"),u(this,"index"),this.series=e;const s=j(0,e.length);this.end=Me(s,n),this.index=Me(s,t)}next(){return this.index>=this.end?{done:!0,value:void 0}:{done:!1,value:this.series.at(this.index++,!0)}}[Symbol.iterator](){return this}}class dr{constructor(e){if(u(this,"series"),u(this,"index"),u(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,t=this.series.data;for(;this.index<t.length&&t[this.index]!==we;)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 Pe,Le;class gr{constructor(e){u(this,"wrapped"),u(this,Pe,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:re.decodeString(e.value)}}[(Le=Symbol.iterator,Pe=Symbol.toStringTag,Le)](){return this}}var Ye,ke;class pr{constructor(e){u(this,"series"),u(this,"index"),u(this,Ye,"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)}}[(ke=Symbol.iterator,Ye=Symbol.toStringTag,ke)](){return this}}const je=r=>{const e=r>>32n,t=r&0xffffffffn;return{domain:e,sample:t}};i.z.object({key:i.z.string(),value:i.z.string()});i.z.record(i.z.union([i.z.number(),i.z.string(),i.z.symbol()]),i.z.unknown());const st=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",yr=st(),it=["macOS","Windows","Linux"],mr=["macos","windows","linux"],wr={macos:"macOS",windows:"Windows",linux:"Linux"},br=i.z.enum(it).or(i.z.enum(mr).transform(r=>wr[r])),Or=()=>{if(typeof window>"u")return;const r=window.navigator.userAgent.toLowerCase();if(r.includes("mac"))return"macOS";if(r.includes("win"))return"Windows";if(r.includes("linux"))return"Linux"};let ge;const Tr=(r={})=>{const{force:e,default:t}=r;return e??ge??(ge=Or(),ge??t)},at=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:it,RUNTIME:yr,detect:st,getOS:Tr,osZ:br},Symbol.toStringTag,{value:"Module"}));var vr=Object.defineProperty,Sr=(r,e,t)=>e in r?vr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,K=(r,e,t)=>Sr(r,typeof e!="symbol"?e+"":e,t);const Ir=(...r)=>r.map(ot).join(""),ot=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Nr=r=>r.endsWith("/")?r.slice(0,-1):r,Er=(r,e="")=>r===null?"":`?${Object.entries(r).filter(([,t])=>t==null?!1:Array.isArray(t)?t.length>0:!0).map(([t,n])=>`${e}${t}=${n}`).join("&")}`,be=class Oe{constructor({host:e,port:t,protocol:n="",pathPrefix:s=""}){K(this,"protocol"),K(this,"host"),K(this,"port"),K(this,"path"),this.protocol=n,this.host=e,this.port=t,this.path=ot(s)}replace(e){return new Oe({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new Oe({...this,pathPrefix:Ir(this.path,e)})}toString(){return Nr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};K(be,"UNKNOWN",new be({host:"unknown",port:0}));let Ar=be;const xr=-128,zr=127;i.z.number().int().min(xr).max(zr);const Mr=-32768,$r=32767;i.z.number().int().min(Mr).max($r);const Ur=-2147483648,Br=2147483647;i.z.number().int().min(Ur).max(Br);const Rr=-9223372036854775808n,Cr=9223372036854775807n;i.z.bigint().min(Rr).max(Cr);const Dr=255;i.z.number().int().min(0).max(Dr);const Pr=65535;i.z.number().int().min(0).max(Pr);const Lr=4294967295;i.z.number().int().min(0).max(Lr);const Yr=18446744073709551615n;i.z.bigint().min(0n).max(Yr);var kr=Object.defineProperty,jr=(r,e,t)=>e in r?kr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,X=(r,e,t)=>jr(r,typeof e!="symbol"?e+"":e,t);const qr=async r=>await new Promise(e=>setTimeout(e,O.fromMilliseconds(r).milliseconds)),Fr=i.z.object({interval:O.z.optional(),maxRetries:i.z.number().optional(),scale:i.z.number().optional()}),Gr=(r={})=>{const e=r.sleepFn||qr,t=r.maxRetries??5,n=r.scale??1;let s=0,a=new O(r.interval??O.milliseconds(1));return async()=>s>=t?!1:(await e(a),a=a.mult(n),s++,!0)},Wr=Object.freeze(Object.defineProperty({__proto__:null,breakerConfig:Fr,create:Gr},Symbol.toStringTag,{value:"Module"})),R=class extends Number{};X(R,"ABSOLUTE",255),X(R,"MINIMUM",0),X(R,"BOUNDS",{lower:R.MINIMUM,upper:R.ABSOLUTE+1}),X(R,"z",i.z.union([i.z.instanceof(R),i.z.number().int().min(0).max(255).transform(r=>new R(r)),i.z.instanceof(Number).transform(r=>new R(r))]));i.z.object({name:i.z.string(),key:i.z.string()});const ut=class Q extends Error{constructor(){super(Q.MESSAGE)}matches(e){return typeof e=="string"?e.includes(Q.MESSAGE):e instanceof Q||e.message.includes(Q.MESSAGE)}};X(ut,"MESSAGE","canceled");let Vr=ut;new Vr;i.z.string().regex(/^\d+\.\d+\.\d+$/);const Zr=["standard","scientific","engineering"];i.z.enum(Zr);const ce=r=>e=>e!=null&&typeof e=="object"&&"type"in e&&typeof e.type=="string"?e.type.includes(r):e instanceof Error?e.message.includes(r):typeof e!="string"?!1:e.includes(r);class ee extends Error{constructor(){super(...arguments);y(this,"discriminator","FreighterError");y(this,"type","")}}const Jr=r=>{if(r==null||typeof r!="object")return!1;const e=r;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},qe="unknown",Fe="nil",Hr="freighter",Ie=i.z.object({type:i.z.string(),data:i.z.string()});class Kr{constructor(){y(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Fe,data:""};if(Jr(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}return{type:qe,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Fe)return null;if(e.type===qe)return new Ge(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Ge(e.data)}}const Ne=new Kr,ct=({encode:r,decode:e})=>Ne.register({encode:r,decode:e}),Xr=r=>Ne.encode(r),ae=r=>Ne.decode(r);class Ge extends ee{constructor(){super(...arguments);y(this,"type","unknown")}}const le="freighter.",F=class F extends ee{constructor(){super("EOF");y(this,"type",F.TYPE)}};y(F,"TYPE",`${le}eof`),y(F,"matches",ce(F.TYPE));let P=F;const G=class G extends ee{constructor(){super("StreamClosed");y(this,"type",G.TYPE)}};y(G,"TYPE",`${le}stream_closed`),y(G,"matches",ce(G.TYPE));let L=G;const W=class W extends ee{constructor(t={}){const{message:n="Unreachable",url:s=Ar.UNKNOWN}=t;super(n);y(this,"type",W.TYPE);y(this,"url");this.url=s}};y(W,"TYPE",`${le}unreachable`),y(W,"matches",ce(W.TYPE));let Y=W;const Qr=r=>{if(!r.type.startsWith(Hr))return null;if(P.matches(r))return{type:P.TYPE,data:"EOF"};if(L.matches(r))return{type:L.TYPE,data:"StreamClosed"};if(Y.matches(r))return{type:Y.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},_r=r=>{if(!r.type.startsWith(le))return null;switch(r.type){case P.TYPE:return new P;case L.TYPE:return new L;case Y.TYPE:return new Y;default:throw new Error(`Unknown error type: ${r.data}`)}};ct({encode:Qr,decode:_r});class lt{constructor(){y(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const s=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,s)};return await s(e)}}const ht="Content-Type",We=r=>{if(at.RUNTIME!=="node")return fetch;const e=require("node-fetch");if(r==="http")return e;const t=require("https"),n=new t.Agent({rejectUnauthorized:!1});return async(s,a)=>await e(s,{...a,agent:n})};class en extends lt{constructor(t,n,s=!1){super();y(this,"endpoint");y(this,"encoder");y(this,"fetch");return this.endpoint=t.replace({protocol:s?"https":"http"}),this.encoder=n,this.fetch=We(this.endpoint.protocol),new Proxy(this,{get:(a,c,f)=>c==="endpoint"?this.endpoint:Reflect.get(a,c,f)})}get headers(){return{[ht]:this.encoder.contentType}}async send(t,n,s,a){n=s==null?void 0:s.parse(n);let c=null;const f=this.endpoint.child(t),d={};d.method="POST",d.body=this.encoder.encode(n??{});const[,p]=await this.executeMiddleware({target:f.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async m=>{const l={...m,params:{}};d.headers={...this.headers,...m.params};let N;try{N=await We(m.protocol)(m.target,d)}catch(B){let z=B;return z.message==="Load failed"&&(z=new Y({url:f})),[l,z]}const M=await N.arrayBuffer();if(N!=null&&N.ok)return a!=null&&(c=this.encoder.decode(M,a)),[l,null];try{if(N.status!==400)return[l,new Error(N.statusText)];const B=this.encoder.decode(M,Ie),z=ae(B);return[l,z]}catch(B){return[l,new Error(`[freighter] - failed to decode error: ${N.statusText}: ${B.message}`)]}});return[c,p]}}const tn=(r,e)=>{class t{constructor(s){y(this,"wrapped");this.wrapped=s}use(...s){this.wrapped.use(...s)}async send(s,a,c,f){const d=Wr.create(e);do{const[p,m]=await this.wrapped.send(s,a,c,f);if(m==null||!Y.matches(m))return[p,m];if(!await d())return[p,m]}while(!0)}}return new t(r)},rn=async(r,e,t,n,s)=>{const[a,c]=await r.send(e,t,n,s);if(c!=null)throw c;return a},nn=()=>at.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),sn=i.z.object({type:i.z.enum(["data","close","open"]),payload:i.z.unknown().optional(),error:i.z.optional(Ie)});class an{constructor(e,t,n,s){y(this,"encoder");y(this,"reqSchema");y(this,"resSchema");y(this,"ws");y(this,"serverClosed");y(this,"sendClosed");y(this,"receiveDataQueue",[]);y(this,"receiveCallbacksQueue",[]);this.encoder=t,this.reqSchema=n,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}async receiveOpenAck(){const e=await this.receiveMsg();if(e.type!=="open"){if(e.error==null)throw new Error("Message error must be defined");return ae(e.error)}return null}send(e){if(this.serverClosed!=null)return new P;if(this.sendClosed)throw new L;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=ae(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(){const e=this.receiveDataQueue.shift();return e??await new Promise((t,n)=>this.receiveCallbacksQueue.push({resolve:t,reject:n}))}addMessage(e){const t=this.receiveCallbacksQueue.shift();t!=null?t.resolve(e):this.receiveDataQueue.push(e)}listenForMessages(){this.ws.onmessage=e=>this.addMessage(this.encoder.decode(e.data,sn)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:hn(e)?P.TYPE:L.TYPE,data:""}})}}const on="freighterctx",un=1e3,cn=1001,ln=[un,cn],hn=r=>ln.includes(r.code),oe=class oe extends lt{constructor(t,n,s=!1){super();y(this,"baseUrl");y(this,"encoder");this.baseUrl=t.replace({protocol:s?"wss":"ws"}),this.encoder=n}async stream(t,n,s){const a=nn();let c;const[,f]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async d=>{const p=a(this.buildURL(t,d)),m={...d,params:{}};p.binaryType=oe.MESSAGE_TYPE;const l=await this.wrapSocket(p,n,s);return l instanceof Error?[m,l]:(c=l,[m,null])});if(f!=null)throw f;return c}buildURL(t,n){const s=Er({[ht]:this.encoder.contentType,...n.params},on);return this.baseUrl.child(t).toString()+s}async wrapSocket(t,n,s){return await new Promise(a=>{t.onopen=()=>{const c=new an(t,this.encoder,n,s);c.receiveOpenAck().then(f=>{f!=null?a(f):a(c)}).catch(f=>a(f))},t.onerror=c=>{const f=c;a(new Error(f.message))}})}};y(oe,"MESSAGE_TYPE","arraybuffer");let Te=oe;exports.BaseTypedError=ee;exports.EOF=P;exports.HTTPClient=en;exports.StreamClosed=L;exports.Unreachable=Y;exports.WebSocketClient=Te;exports.decodeError=ae;exports.encodeError=Xr;exports.errorMatcher=ce;exports.errorZ=Ie;exports.registerError=ct;exports.sendRequired=rn;exports.unaryWithBreaker=tn;
|
package/dist/freighter.js
CHANGED
|
@@ -5,7 +5,7 @@ import { z as i } from "zod";
|
|
|
5
5
|
const dt = (r) => {
|
|
6
6
|
const e = r.replace(/_[a-z]/g, (t) => t[1].toUpperCase());
|
|
7
7
|
return e.length > 1 && e[0] === e[0].toUpperCase() && e[1] === e[1].toUpperCase() || e.length === 0 ? e : e[0].toLowerCase() + e.slice(1);
|
|
8
|
-
},
|
|
8
|
+
}, Ve = (r) => {
|
|
9
9
|
const e = (t, n = de) => {
|
|
10
10
|
if (typeof t == "string") return r(t);
|
|
11
11
|
if (Array.isArray(t)) return t.map((c) => e(c, n));
|
|
@@ -22,14 +22,14 @@ const dt = (r) => {
|
|
|
22
22
|
}), s;
|
|
23
23
|
};
|
|
24
24
|
return e;
|
|
25
|
-
},
|
|
25
|
+
}, ze = Ve(dt), gt = (r) => (
|
|
26
26
|
// Don't convert the first character and don't convert a character that is after a
|
|
27
27
|
// non-alphanumeric character
|
|
28
28
|
r.replace(
|
|
29
29
|
/([a-z0-9])([A-Z])/g,
|
|
30
30
|
(e, t, n) => `${t}_${n.toLowerCase()}`
|
|
31
31
|
)
|
|
32
|
-
), pt =
|
|
32
|
+
), pt = Ve(gt), de = {
|
|
33
33
|
recursive: !0,
|
|
34
34
|
recursiveInArray: !0,
|
|
35
35
|
keepTypesOnRecursion: [Number, String, Uint8Array]
|
|
@@ -46,7 +46,7 @@ let bt = class {
|
|
|
46
46
|
return this.decodeString(this.decoder.decode(e), t);
|
|
47
47
|
}
|
|
48
48
|
decodeString(e, t) {
|
|
49
|
-
const n = JSON.parse(e), s =
|
|
49
|
+
const n = JSON.parse(e), s = ze(n);
|
|
50
50
|
return t != null ? t.parse(s) : s;
|
|
51
51
|
}
|
|
52
52
|
encodeString(e) {
|
|
@@ -55,7 +55,7 @@ let bt = class {
|
|
|
55
55
|
}
|
|
56
56
|
static registerCustomType() {
|
|
57
57
|
}
|
|
58
|
-
},
|
|
58
|
+
}, Ot = class {
|
|
59
59
|
constructor() {
|
|
60
60
|
_(this, "contentType", "text/csv");
|
|
61
61
|
}
|
|
@@ -100,7 +100,7 @@ let bt = class {
|
|
|
100
100
|
}
|
|
101
101
|
static registerCustomType() {
|
|
102
102
|
}
|
|
103
|
-
},
|
|
103
|
+
}, Tt = class {
|
|
104
104
|
constructor() {
|
|
105
105
|
_(this, "contentType", "text/plain");
|
|
106
106
|
}
|
|
@@ -113,8 +113,8 @@ let bt = class {
|
|
|
113
113
|
}
|
|
114
114
|
};
|
|
115
115
|
const te = new bt();
|
|
116
|
-
new Tt();
|
|
117
116
|
new Ot();
|
|
117
|
+
new Tt();
|
|
118
118
|
const vt = (r) => r != null && typeof r == "object" && "toString" in r, St = (r, e = !1) => {
|
|
119
119
|
const t = vt(r) ? "stringer" : typeof r;
|
|
120
120
|
let n;
|
|
@@ -150,9 +150,9 @@ const Je = i.object({ width: i.number(), height: i.number() }), Nt = i.object({
|
|
|
150
150
|
i.enum(Et);
|
|
151
151
|
const At = ["start", "center", "end"], xt = ["signedWidth", "signedHeight"];
|
|
152
152
|
i.enum(xt);
|
|
153
|
-
const se = i.object({ x: i.number(), y: i.number() }), Mt = i.object({ clientX: i.number(), clientY: i.number() }), $t = ["x", "y"], He = i.enum($t),
|
|
154
|
-
i.enum(
|
|
155
|
-
const Ut = ["left", "right"],
|
|
153
|
+
const se = i.object({ x: i.number(), y: i.number() }), Mt = i.object({ clientX: i.number(), clientY: i.number() }), $t = ["x", "y"], He = i.enum($t), Ke = ["top", "right", "bottom", "left"];
|
|
154
|
+
i.enum(Ke);
|
|
155
|
+
const Ut = ["left", "right"], Xe = i.enum(Ut), Bt = ["top", "bottom"], Qe = i.enum(Bt), _e = ["center"], Ee = i.enum(_e), Rt = [...Ke, ..._e], et = i.enum(Rt);
|
|
156
156
|
i.enum(At);
|
|
157
157
|
const Ct = ["first", "last"];
|
|
158
158
|
i.enum(Ct);
|
|
@@ -175,10 +175,10 @@ const Pt = (r) => typeof r == "bigint" || r instanceof BigInt, F = (r, e) => Pt(
|
|
|
175
175
|
return e < t.lower ? t.lower : e >= t.upper ? t.upper - (typeof t.upper == "number" ? 1 : 1n) : e;
|
|
176
176
|
};
|
|
177
177
|
i.object({
|
|
178
|
-
x:
|
|
178
|
+
x: Xe.or(Ee),
|
|
179
179
|
y: Qe.or(Ee)
|
|
180
180
|
});
|
|
181
|
-
const Yt = i.object({ x:
|
|
181
|
+
const Yt = i.object({ x: Xe, y: Qe }), kt = Object.freeze({ x: "left", y: "top" }), jt = (r, e) => r.x === e.x && r.y === e.y, Me = i.union([
|
|
182
182
|
i.number(),
|
|
183
183
|
se,
|
|
184
184
|
ae,
|
|
@@ -209,7 +209,7 @@ i.object({
|
|
|
209
209
|
two: se,
|
|
210
210
|
root: Yt
|
|
211
211
|
});
|
|
212
|
-
const
|
|
212
|
+
const Oe = (r, e, t = 0, n = 0, s) => {
|
|
213
213
|
const a = {
|
|
214
214
|
one: { ...$e },
|
|
215
215
|
two: { ...$e },
|
|
@@ -228,15 +228,15 @@ const Te = (r, e, t = 0, n = 0, s) => {
|
|
|
228
228
|
y: a.one.y + e.signedHeight
|
|
229
229
|
} : a.two = e, a));
|
|
230
230
|
}, le = (r) => {
|
|
231
|
-
const e =
|
|
231
|
+
const e = Oe(r);
|
|
232
232
|
return { lower: e.one.x, upper: e.two.x };
|
|
233
233
|
}, he = (r) => {
|
|
234
|
-
const e =
|
|
234
|
+
const e = Oe(r);
|
|
235
235
|
return { lower: e.one.y, upper: e.two.y };
|
|
236
236
|
}, Ft = (r) => typeof r != "object" || r == null ? !1 : "one" in r && "two" in r && "root" in r, Gt = i.object({ signedWidth: i.number(), signedHeight: i.number() });
|
|
237
237
|
i.union([Je, Gt, se, ae]);
|
|
238
|
-
var Wt = Object.defineProperty,
|
|
239
|
-
const
|
|
238
|
+
var Wt = Object.defineProperty, Vt = (r, e, t) => e in r ? Wt(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, L = (r, e, t) => Vt(r, typeof e != "symbol" ? e + "" : e, t);
|
|
239
|
+
const zt = (r, e, t) => e !== void 0 && r < e ? e : t !== void 0 && r > t ? t : r;
|
|
240
240
|
i.object({ offset: Me, scale: Me });
|
|
241
241
|
i.object({ offset: i.number(), scale: i.number() });
|
|
242
242
|
const Zt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
|
|
@@ -251,15 +251,15 @@ const Zt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
|
|
|
251
251
|
if (t === "dimension") return [r, n * (p / d)];
|
|
252
252
|
const m = (n - s) * (p / d) + c;
|
|
253
253
|
return [r, m];
|
|
254
|
-
},
|
|
254
|
+
}, Kt = (r) => (e, t, n) => [r, n], Xt = () => (r, e, t) => {
|
|
255
255
|
if (r === null) throw new Error("cannot invert without bounds");
|
|
256
256
|
if (e === "dimension") return [r, t];
|
|
257
257
|
const { lower: n, upper: s } = r;
|
|
258
258
|
return [r, s - (t - n)];
|
|
259
259
|
}, Qt = (r) => (e, t, n) => {
|
|
260
260
|
const { lower: s, upper: a } = r;
|
|
261
|
-
return n =
|
|
262
|
-
}, ge = class
|
|
261
|
+
return n = zt(n, s, a), [e, n];
|
|
262
|
+
}, ge = class z {
|
|
263
263
|
constructor() {
|
|
264
264
|
L(this, "ops", []), L(this, "currBounds", null), L(this, "currType", null), L(this, "reversed", !1), this.ops = [];
|
|
265
265
|
}
|
|
@@ -269,7 +269,7 @@ const Zt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
|
|
|
269
269
|
* @param value - The amount to translate by.
|
|
270
270
|
*/
|
|
271
271
|
static translate(e) {
|
|
272
|
-
return new
|
|
272
|
+
return new z().translate(e);
|
|
273
273
|
}
|
|
274
274
|
/**
|
|
275
275
|
* @returns a new scale with a magnification as its first operation. Any number provided
|
|
@@ -277,10 +277,10 @@ const Zt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
|
|
|
277
277
|
* @param value - The amount to translate by.
|
|
278
278
|
*/
|
|
279
279
|
static magnify(e) {
|
|
280
|
-
return new
|
|
280
|
+
return new z().magnify(e);
|
|
281
281
|
}
|
|
282
282
|
static scale(e, t) {
|
|
283
|
-
return new
|
|
283
|
+
return new z().scale(e, t);
|
|
284
284
|
}
|
|
285
285
|
/**
|
|
286
286
|
* @returns a copy of the scale with a translation as its next operation. Any
|
|
@@ -311,11 +311,11 @@ const Zt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
|
|
|
311
311
|
return a.type = "clamp", s.ops.push(a), s;
|
|
312
312
|
}
|
|
313
313
|
reBound(e, t) {
|
|
314
|
-
const n = q(e, t), s = this.new(), a =
|
|
314
|
+
const n = q(e, t), s = this.new(), a = Kt(n);
|
|
315
315
|
return a.type = "re-bound", s.ops.push(a), s;
|
|
316
316
|
}
|
|
317
317
|
invert() {
|
|
318
|
-
const e =
|
|
318
|
+
const e = Xt();
|
|
319
319
|
e.type = "invert";
|
|
320
320
|
const t = this.new();
|
|
321
321
|
return t.ops.push(e), t;
|
|
@@ -327,7 +327,7 @@ const Zt = (r) => (e, t, n, s) => t === "dimension" ? [e, n] : [
|
|
|
327
327
|
return this.exec("dimension", e);
|
|
328
328
|
}
|
|
329
329
|
new() {
|
|
330
|
-
const e = new
|
|
330
|
+
const e = new z();
|
|
331
331
|
return e.ops = this.ops.slice(), e.reversed = this.reversed, e;
|
|
332
332
|
}
|
|
333
333
|
exec(e, t) {
|
|
@@ -428,7 +428,7 @@ const Be = class D {
|
|
|
428
428
|
return { x: this.x.dim(e.x), y: this.y.dim(e.y) };
|
|
429
429
|
}
|
|
430
430
|
box(e) {
|
|
431
|
-
return
|
|
431
|
+
return Oe(
|
|
432
432
|
this.pos(e.one),
|
|
433
433
|
this.pos(e.two),
|
|
434
434
|
0,
|
|
@@ -467,7 +467,7 @@ const rr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", nr
|
|
|
467
467
|
);
|
|
468
468
|
const n = r.valueOf() % t.valueOf();
|
|
469
469
|
return r instanceof v ? new v(n) : new O(n);
|
|
470
|
-
},
|
|
470
|
+
}, w = class h {
|
|
471
471
|
constructor(e, t = "UTC") {
|
|
472
472
|
if (u(this, "value"), u(this, "encodeValue", !0), e == null) this.value = h.now().valueOf();
|
|
473
473
|
else if (e instanceof Date)
|
|
@@ -581,7 +581,7 @@ const rr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", nr
|
|
|
581
581
|
* valid, regardless of the TimeStamp order.
|
|
582
582
|
*/
|
|
583
583
|
range(e) {
|
|
584
|
-
return new
|
|
584
|
+
return new Te(this, e).makeValid();
|
|
585
585
|
}
|
|
586
586
|
/**
|
|
587
587
|
* Creates a TimeRange starting at the TimeStamp and spanning the given
|
|
@@ -696,6 +696,12 @@ const rr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", nr
|
|
|
696
696
|
get milliseconds() {
|
|
697
697
|
return Number(this.valueOf()) / Number(h.MILLISECOND.valueOf());
|
|
698
698
|
}
|
|
699
|
+
get microseconds() {
|
|
700
|
+
return Number(this.valueOf()) / Number(h.MICROSECOND.valueOf());
|
|
701
|
+
}
|
|
702
|
+
get nanoseconds() {
|
|
703
|
+
return Number(this.valueOf());
|
|
704
|
+
}
|
|
699
705
|
/** @returns the integer year that the timestamp corresponds to. */
|
|
700
706
|
get year() {
|
|
701
707
|
return this.date().getFullYear();
|
|
@@ -827,25 +833,25 @@ const rr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz", nr
|
|
|
827
833
|
return h.hours(e * 24);
|
|
828
834
|
}
|
|
829
835
|
};
|
|
830
|
-
u(
|
|
831
|
-
u(
|
|
832
|
-
u(
|
|
833
|
-
u(
|
|
834
|
-
u(
|
|
835
|
-
u(
|
|
836
|
-
u(
|
|
837
|
-
u(
|
|
838
|
-
u(
|
|
839
|
-
u(
|
|
840
|
-
u(
|
|
841
|
-
i.object({ value: i.bigint() }).transform((r) => new
|
|
842
|
-
i.string().transform((r) => new
|
|
843
|
-
i.instanceof(Number).transform((r) => new
|
|
844
|
-
i.number().transform((r) => new
|
|
845
|
-
i.instanceof(
|
|
836
|
+
u(w, "NANOSECOND", w.nanoseconds(1)), /** One microsecond after the unix epoch */
|
|
837
|
+
u(w, "MICROSECOND", w.microseconds(1)), /** One millisecond after the unix epoch */
|
|
838
|
+
u(w, "MILLISECOND", w.milliseconds(1)), /** One second after the unix epoch */
|
|
839
|
+
u(w, "SECOND", w.seconds(1)), /** One minute after the unix epoch */
|
|
840
|
+
u(w, "MINUTE", w.minutes(1)), /** One hour after the unix epoch */
|
|
841
|
+
u(w, "HOUR", w.hours(1)), /** One day after the unix epoch */
|
|
842
|
+
u(w, "DAY", w.days(1)), /** The maximum possible value for a timestamp */
|
|
843
|
+
u(w, "MAX", new w((1n << 63n) - 1n)), /** The minimum possible value for a timestamp */
|
|
844
|
+
u(w, "MIN", new w(0)), /** The unix epoch */
|
|
845
|
+
u(w, "ZERO", new w(0)), /** A zod schema for validating timestamps */
|
|
846
|
+
u(w, "z", i.union([
|
|
847
|
+
i.object({ value: i.bigint() }).transform((r) => new w(r.value)),
|
|
848
|
+
i.string().transform((r) => new w(BigInt(r))),
|
|
849
|
+
i.instanceof(Number).transform((r) => new w(r)),
|
|
850
|
+
i.number().transform((r) => new w(r)),
|
|
851
|
+
i.instanceof(w)
|
|
846
852
|
]));
|
|
847
|
-
let v =
|
|
848
|
-
const
|
|
853
|
+
let v = w;
|
|
854
|
+
const b = class g {
|
|
849
855
|
constructor(e) {
|
|
850
856
|
u(this, "value"), u(this, "encodeValue", !0), typeof e == "number" && (e = Math.trunc(e.valueOf())), this.value = BigInt(e.valueOf());
|
|
851
857
|
}
|
|
@@ -1011,24 +1017,24 @@ const T = class g {
|
|
|
1011
1017
|
return g.hours(F(e, 24));
|
|
1012
1018
|
}
|
|
1013
1019
|
};
|
|
1014
|
-
u(
|
|
1015
|
-
u(
|
|
1016
|
-
u(
|
|
1017
|
-
u(
|
|
1018
|
-
u(
|
|
1019
|
-
u(
|
|
1020
|
-
u(
|
|
1021
|
-
u(
|
|
1022
|
-
u(
|
|
1023
|
-
u(
|
|
1024
|
-
u(
|
|
1025
|
-
i.object({ value: i.bigint() }).transform((r) => new
|
|
1026
|
-
i.string().transform((r) => new
|
|
1027
|
-
i.instanceof(Number).transform((r) => new
|
|
1028
|
-
i.number().transform((r) => new
|
|
1029
|
-
i.instanceof(
|
|
1020
|
+
u(b, "NANOSECOND", b.nanoseconds(1)), /** A microsecond. */
|
|
1021
|
+
u(b, "MICROSECOND", b.microseconds(1)), /** A millisecond. */
|
|
1022
|
+
u(b, "MILLISECOND", b.milliseconds(1)), /** A second. */
|
|
1023
|
+
u(b, "SECOND", b.seconds(1)), /** A minute. */
|
|
1024
|
+
u(b, "MINUTE", b.minutes(1)), /** Represents an hour. */
|
|
1025
|
+
u(b, "HOUR", b.hours(1)), /** Represents a day. */
|
|
1026
|
+
u(b, "DAY", b.days(1)), /** The maximum possible value for a TimeSpan. */
|
|
1027
|
+
u(b, "MAX", new b((1n << 63n) - 1n)), /** The minimum possible value for a TimeSpan. */
|
|
1028
|
+
u(b, "MIN", new b(0)), /** The zero value for a TimeSpan. */
|
|
1029
|
+
u(b, "ZERO", new b(0)), /** A zod schema for validating and transforming timespans */
|
|
1030
|
+
u(b, "z", i.union([
|
|
1031
|
+
i.object({ value: i.bigint() }).transform((r) => new b(r.value)),
|
|
1032
|
+
i.string().transform((r) => new b(BigInt(r))),
|
|
1033
|
+
i.instanceof(Number).transform((r) => new b(r)),
|
|
1034
|
+
i.number().transform((r) => new b(r)),
|
|
1035
|
+
i.instanceof(b)
|
|
1030
1036
|
]));
|
|
1031
|
-
let O =
|
|
1037
|
+
let O = b;
|
|
1032
1038
|
const Z = class re extends Number {
|
|
1033
1039
|
constructor(e) {
|
|
1034
1040
|
e instanceof Number ? super(e.valueOf()) : super(e);
|
|
@@ -1244,7 +1250,7 @@ u(U, "z", i.union([
|
|
|
1244
1250
|
i.object({ start: v.z, end: v.z }).transform((r) => new U(r.start, r.end)),
|
|
1245
1251
|
i.instanceof(U)
|
|
1246
1252
|
]));
|
|
1247
|
-
let
|
|
1253
|
+
let Te = U;
|
|
1248
1254
|
const o = class S extends String {
|
|
1249
1255
|
constructor(e) {
|
|
1250
1256
|
if (e instanceof S || typeof e == "string" || typeof e.valueOf() == "string") {
|
|
@@ -1411,7 +1417,7 @@ u(o, "z", i.union([
|
|
|
1411
1417
|
i.string().transform((r) => new o(r)),
|
|
1412
1418
|
i.instanceof(o)
|
|
1413
1419
|
]));
|
|
1414
|
-
let
|
|
1420
|
+
let T = o;
|
|
1415
1421
|
const A = class I extends Number {
|
|
1416
1422
|
constructor(e) {
|
|
1417
1423
|
super(e.valueOf());
|
|
@@ -1528,11 +1534,18 @@ i.union([
|
|
|
1528
1534
|
const rt = (r) => {
|
|
1529
1535
|
const e = typeof r;
|
|
1530
1536
|
return e === "string" || e === "number" || e === "boolean" || e === "bigint" || r instanceof v || r instanceof O || r instanceof Date;
|
|
1531
|
-
}, ar = (r, e, t, n = 0) => r.usesBigInt && !e.usesBigInt ? Number(t) - Number(n) : !r.usesBigInt && e.usesBigInt ? BigInt(t.valueOf()) - BigInt(n.valueOf()) : J(t, -n).valueOf(), J = (r, e) => typeof r == "bigint" && typeof e == "bigint" || typeof r == "number" && typeof e == "number" ? r + e : e === 0 ? r : r === 0 ? e : Number(r) + Number(e), or = (r) => r == null ? !1 : Array.isArray(r) || r instanceof ArrayBuffer || ArrayBuffer.isView(r) && !(r instanceof DataView) || r instanceof
|
|
1537
|
+
}, ar = (r, e, t, n = 0) => r.usesBigInt && !e.usesBigInt ? Number(t) - Number(n) : !r.usesBigInt && e.usesBigInt ? BigInt(t.valueOf()) - BigInt(n.valueOf()) : J(t, -n).valueOf(), J = (r, e) => typeof r == "bigint" && typeof e == "bigint" || typeof r == "number" && typeof e == "number" ? r + e : e === 0 ? r : r === 0 ? e : Number(r) + Number(e), or = (r) => r == null ? !1 : Array.isArray(r) || r instanceof ArrayBuffer || ArrayBuffer.isView(r) && !(r instanceof DataView) || r instanceof hr ? !0 : rt(r), P = -1, ur = i.string().transform(
|
|
1532
1538
|
(r) => new Uint8Array(
|
|
1533
1539
|
atob(r).split("").map((e) => e.charCodeAt(0))
|
|
1534
1540
|
).buffer
|
|
1535
|
-
), cr = i.union([i.null(), i.undefined()]).transform(() => new Uint8Array().buffer), ye = 10,
|
|
1541
|
+
), cr = i.union([i.null(), i.undefined()]).transform(() => new Uint8Array().buffer), ye = 10, lr = (r, e) => {
|
|
1542
|
+
if (r === "string" && !e.isVariable)
|
|
1543
|
+
throw new Error(`cannot convert series of type ${e.toString()} to string`);
|
|
1544
|
+
if (r === "number" && !e.isNumeric)
|
|
1545
|
+
throw new Error(`cannot convert series of type ${e.toString()} to number`);
|
|
1546
|
+
if (r === "bigint" && !e.usesBigInt)
|
|
1547
|
+
throw new Error(`cannot convert series of type ${e.toString()} to bigint`);
|
|
1548
|
+
}, H = class B {
|
|
1536
1549
|
constructor(e) {
|
|
1537
1550
|
u(this, "key", ""), u(this, "isSynnaxSeries", !0), u(this, "dataType"), u(this, "sampleOffset"), u(this, "gl"), u(this, "_data"), u(this, "_timeRange"), u(this, "alignment", 0n), u(this, "_cachedMin"), u(this, "_cachedMax"), u(this, "writePos", P), u(this, "_refCount", 0), u(this, "_cachedLength"), u(this, "_cachedIndexes"), or(e) && (e = { data: e });
|
|
1538
1551
|
const {
|
|
@@ -1549,7 +1562,7 @@ const rt = (r) => {
|
|
|
1549
1562
|
return;
|
|
1550
1563
|
}
|
|
1551
1564
|
const p = rt(d), m = Array.isArray(d);
|
|
1552
|
-
if (t != null) this.dataType = new
|
|
1565
|
+
if (t != null) this.dataType = new T(t);
|
|
1553
1566
|
else {
|
|
1554
1567
|
if (d instanceof ArrayBuffer)
|
|
1555
1568
|
throw new Error(
|
|
@@ -1564,26 +1577,26 @@ const rt = (r) => {
|
|
|
1564
1577
|
);
|
|
1565
1578
|
l = d[0];
|
|
1566
1579
|
}
|
|
1567
|
-
if (typeof l == "string") this.dataType =
|
|
1568
|
-
else if (typeof l == "number") this.dataType =
|
|
1569
|
-
else if (typeof l == "bigint") this.dataType =
|
|
1570
|
-
else if (typeof l == "boolean") this.dataType =
|
|
1580
|
+
if (typeof l == "string") this.dataType = T.STRING;
|
|
1581
|
+
else if (typeof l == "number") this.dataType = T.FLOAT64;
|
|
1582
|
+
else if (typeof l == "bigint") this.dataType = T.INT64;
|
|
1583
|
+
else if (typeof l == "boolean") this.dataType = T.BOOLEAN;
|
|
1571
1584
|
else if (l instanceof v || l instanceof Date || l instanceof v)
|
|
1572
|
-
this.dataType =
|
|
1573
|
-
else if (typeof l == "object") this.dataType =
|
|
1585
|
+
this.dataType = T.TIMESTAMP;
|
|
1586
|
+
else if (typeof l == "object") this.dataType = T.JSON;
|
|
1574
1587
|
else
|
|
1575
1588
|
throw new Error(
|
|
1576
1589
|
`cannot infer data type of ${typeof l} when constructing a Series from a JS array`
|
|
1577
1590
|
);
|
|
1578
|
-
} else this.dataType = new
|
|
1591
|
+
} else this.dataType = new T(d);
|
|
1579
1592
|
}
|
|
1580
1593
|
if (!m && !p) this._data = d;
|
|
1581
1594
|
else {
|
|
1582
1595
|
let l = p ? [d] : d;
|
|
1583
1596
|
const N = l[0];
|
|
1584
|
-
(N instanceof v || N instanceof Date || N instanceof O) && (l = l.map(($) => new v($).valueOf())), this.dataType.equals(
|
|
1597
|
+
(N instanceof v || N instanceof Date || N instanceof O) && (l = l.map(($) => new v($).valueOf())), this.dataType.equals(T.STRING) ? (this._cachedLength = l.length, this._data = new TextEncoder().encode(`${l.join(`
|
|
1585
1598
|
`)}
|
|
1586
|
-
`).buffer) : this.dataType.equals(
|
|
1599
|
+
`).buffer) : this.dataType.equals(T.JSON) ? (this._cachedLength = l.length, this._data = new TextEncoder().encode(
|
|
1587
1600
|
`${l.map(($) => te.encodeString($)).join(`
|
|
1588
1601
|
`)}
|
|
1589
1602
|
`
|
|
@@ -1603,7 +1616,7 @@ const rt = (r) => {
|
|
|
1603
1616
|
static alloc({ capacity: e, dataType: t, ...n }) {
|
|
1604
1617
|
if (e === 0)
|
|
1605
1618
|
throw new Error("[Series] - cannot allocate an array of length 0");
|
|
1606
|
-
const s = new new
|
|
1619
|
+
const s = new new T(t).Array(e), a = new B({
|
|
1607
1620
|
data: s.buffer,
|
|
1608
1621
|
dataType: t,
|
|
1609
1622
|
...n
|
|
@@ -1614,7 +1627,7 @@ const rt = (r) => {
|
|
|
1614
1627
|
const s = n.spanRange(t.span(e)), a = new BigInt64Array(e);
|
|
1615
1628
|
for (let c = 0; c < e; c++)
|
|
1616
1629
|
a[c] = BigInt(n.add(t.span(c)).valueOf());
|
|
1617
|
-
return new B({ data: a, dataType:
|
|
1630
|
+
return new B({ data: a, dataType: T.TIMESTAMP, timeRange: s });
|
|
1618
1631
|
}
|
|
1619
1632
|
get refCount() {
|
|
1620
1633
|
return this._refCount;
|
|
@@ -1625,7 +1638,7 @@ const rt = (r) => {
|
|
|
1625
1638
|
`)}
|
|
1626
1639
|
`
|
|
1627
1640
|
);
|
|
1628
|
-
return new B({ data: n, dataType:
|
|
1641
|
+
return new B({ data: n, dataType: T.STRING, timeRange: t });
|
|
1629
1642
|
}
|
|
1630
1643
|
static fromJSON(e, t) {
|
|
1631
1644
|
const n = new TextEncoder().encode(
|
|
@@ -1633,7 +1646,7 @@ const rt = (r) => {
|
|
|
1633
1646
|
`)}
|
|
1634
1647
|
`
|
|
1635
1648
|
);
|
|
1636
|
-
return new B({ data: n, dataType:
|
|
1649
|
+
return new B({ data: n, dataType: T.JSON, timeRange: t });
|
|
1637
1650
|
}
|
|
1638
1651
|
acquire(e) {
|
|
1639
1652
|
this._refCount++, e != null && this.updateGLBuffer(e);
|
|
@@ -1685,15 +1698,15 @@ const rt = (r) => {
|
|
|
1685
1698
|
return this.writePos === P ? this.underlyingData : new this.dataType.Array(this._data, 0, this.writePos);
|
|
1686
1699
|
}
|
|
1687
1700
|
toStrings() {
|
|
1688
|
-
if (!this.dataType.matches(
|
|
1701
|
+
if (!this.dataType.matches(T.STRING, T.UUID))
|
|
1689
1702
|
throw new Error("cannot convert non-string series to strings");
|
|
1690
1703
|
return new TextDecoder().decode(this.underlyingData).split(`
|
|
1691
1704
|
`).slice(0, -1);
|
|
1692
1705
|
}
|
|
1693
1706
|
toUUIDs() {
|
|
1694
|
-
if (!this.dataType.equals(
|
|
1707
|
+
if (!this.dataType.equals(T.UUID))
|
|
1695
1708
|
throw new Error("cannot convert non-uuid series to uuids");
|
|
1696
|
-
const e =
|
|
1709
|
+
const e = T.UUID.density.valueOf(), t = Array(this.length);
|
|
1697
1710
|
for (let n = 0; n < this.length; n++) {
|
|
1698
1711
|
const s = this.underlyingData.slice(n * e, (n + 1) * e), a = Array.from(
|
|
1699
1712
|
new Uint8Array(s.buffer),
|
|
@@ -1704,7 +1717,7 @@ const rt = (r) => {
|
|
|
1704
1717
|
return t;
|
|
1705
1718
|
}
|
|
1706
1719
|
parseJSON(e) {
|
|
1707
|
-
if (!this.dataType.equals(
|
|
1720
|
+
if (!this.dataType.equals(T.JSON))
|
|
1708
1721
|
throw new Error("cannot parse non-JSON series as JSON");
|
|
1709
1722
|
return new TextDecoder().decode(this.underlyingData).split(`
|
|
1710
1723
|
`).slice(0, -1).map((t) => e.parse(te.decodeString(t)));
|
|
@@ -1764,7 +1777,7 @@ const rt = (r) => {
|
|
|
1764
1777
|
}
|
|
1765
1778
|
calcRawMax() {
|
|
1766
1779
|
if (this.length === 0) return -1 / 0;
|
|
1767
|
-
if (this.dataType.equals(
|
|
1780
|
+
if (this.dataType.equals(T.TIMESTAMP))
|
|
1768
1781
|
this._cachedMax = this.data[this.data.length - 1];
|
|
1769
1782
|
else if (this.dataType.usesBigInt) {
|
|
1770
1783
|
const e = this.data;
|
|
@@ -1783,7 +1796,7 @@ const rt = (r) => {
|
|
|
1783
1796
|
}
|
|
1784
1797
|
calcRawMin() {
|
|
1785
1798
|
if (this.length === 0) return 1 / 0;
|
|
1786
|
-
if (this.dataType.equals(
|
|
1799
|
+
if (this.dataType.equals(T.TIMESTAMP)) this._cachedMin = this.data[0];
|
|
1787
1800
|
else if (this.dataType.usesBigInt) {
|
|
1788
1801
|
const e = this.data;
|
|
1789
1802
|
this._cachedMin = e.reduce((t, n) => t < n ? t : n);
|
|
@@ -1857,7 +1870,7 @@ const rt = (r) => {
|
|
|
1857
1870
|
}
|
|
1858
1871
|
}
|
|
1859
1872
|
const a = this.data.slice(n, s);
|
|
1860
|
-
return this.dataType.equals(
|
|
1873
|
+
return this.dataType.equals(T.STRING) ? new TextDecoder().decode(a) : ze(JSON.parse(new TextDecoder().decode(a)));
|
|
1861
1874
|
}
|
|
1862
1875
|
/**
|
|
1863
1876
|
* @returns the index of the first sample that is greater than or equal to the given value.
|
|
@@ -1875,7 +1888,7 @@ const rt = (r) => {
|
|
|
1875
1888
|
return t;
|
|
1876
1889
|
}
|
|
1877
1890
|
updateGLBuffer(e) {
|
|
1878
|
-
if (this.gl.control = e, !this.dataType.equals(
|
|
1891
|
+
if (this.gl.control = e, !this.dataType.equals(T.FLOAT32) && !this.dataType.equals(T.UINT8))
|
|
1879
1892
|
throw new Error("Only FLOAT32 and UINT8 arrays can be used in WebGL");
|
|
1880
1893
|
const { buffer: t, bufferUsage: n, prevBuffer: s } = this.gl;
|
|
1881
1894
|
if (t == null && (this.gl.buffer = e.createBuffer()), this.writePos !== s)
|
|
@@ -1891,28 +1904,7 @@ const rt = (r) => {
|
|
|
1891
1904
|
), this.gl.prevBuffer = P;
|
|
1892
1905
|
}
|
|
1893
1906
|
as(e) {
|
|
1894
|
-
|
|
1895
|
-
if (!this.dataType.equals(w.STRING))
|
|
1896
|
-
throw new Error(
|
|
1897
|
-
`cannot convert series of type ${this.dataType.toString()} to string`
|
|
1898
|
-
);
|
|
1899
|
-
return this;
|
|
1900
|
-
}
|
|
1901
|
-
if (e === "number") {
|
|
1902
|
-
if (!this.dataType.isNumeric)
|
|
1903
|
-
throw new Error(
|
|
1904
|
-
`cannot convert series of type ${this.dataType.toString()} to number`
|
|
1905
|
-
);
|
|
1906
|
-
return this;
|
|
1907
|
-
}
|
|
1908
|
-
if (e === "bigint") {
|
|
1909
|
-
if (!this.dataType.equals(w.INT64))
|
|
1910
|
-
throw new Error(
|
|
1911
|
-
`cannot convert series of type ${this.dataType.toString()} to bigint`
|
|
1912
|
-
);
|
|
1913
|
-
return this;
|
|
1914
|
-
}
|
|
1915
|
-
throw new Error(`cannot convert series to ${e}`);
|
|
1907
|
+
return lr(e, this.dataType), this;
|
|
1916
1908
|
}
|
|
1917
1909
|
get digest() {
|
|
1918
1910
|
var e;
|
|
@@ -1949,10 +1941,10 @@ const rt = (r) => {
|
|
|
1949
1941
|
}
|
|
1950
1942
|
[Symbol.iterator]() {
|
|
1951
1943
|
if (this.dataType.isVariable) {
|
|
1952
|
-
const e = new
|
|
1953
|
-
return this.dataType.equals(
|
|
1944
|
+
const e = new fr(this);
|
|
1945
|
+
return this.dataType.equals(T.JSON) ? new dr(e) : e;
|
|
1954
1946
|
}
|
|
1955
|
-
return new
|
|
1947
|
+
return new gr(this);
|
|
1956
1948
|
}
|
|
1957
1949
|
slice(e, t) {
|
|
1958
1950
|
return this.sliceSub(!1, e, t);
|
|
@@ -1998,7 +1990,7 @@ const rt = (r) => {
|
|
|
1998
1990
|
return new B({
|
|
1999
1991
|
data: this.buffer,
|
|
2000
1992
|
dataType: this.dataType,
|
|
2001
|
-
timeRange:
|
|
1993
|
+
timeRange: Te.ZERO,
|
|
2002
1994
|
sampleOffset: this.sampleOffset,
|
|
2003
1995
|
glBufferUsage: "static",
|
|
2004
1996
|
alignment: e
|
|
@@ -2006,8 +1998,8 @@ const rt = (r) => {
|
|
|
2006
1998
|
}
|
|
2007
1999
|
};
|
|
2008
2000
|
u(H, "crudeZ", i.object({
|
|
2009
|
-
timeRange:
|
|
2010
|
-
dataType:
|
|
2001
|
+
timeRange: Te.z.optional(),
|
|
2002
|
+
dataType: T.z,
|
|
2011
2003
|
alignment: i.coerce.bigint().optional(),
|
|
2012
2004
|
data: i.union([
|
|
2013
2005
|
ur,
|
|
@@ -2017,7 +2009,7 @@ u(H, "crudeZ", i.object({
|
|
|
2017
2009
|
]),
|
|
2018
2010
|
glBufferUsage: ir.optional().default("static").optional()
|
|
2019
2011
|
})), u(H, "z", H.crudeZ.transform((r) => new H(r)));
|
|
2020
|
-
let
|
|
2012
|
+
let hr = H;
|
|
2021
2013
|
class Ce {
|
|
2022
2014
|
constructor(e, t, n) {
|
|
2023
2015
|
u(this, "series"), u(this, "end"), u(this, "index"), this.series = e;
|
|
@@ -2031,7 +2023,7 @@ class Ce {
|
|
|
2031
2023
|
return this;
|
|
2032
2024
|
}
|
|
2033
2025
|
}
|
|
2034
|
-
class
|
|
2026
|
+
class fr {
|
|
2035
2027
|
constructor(e) {
|
|
2036
2028
|
if (u(this, "series"), u(this, "index"), u(this, "decoder"), !e.dataType.isVariable)
|
|
2037
2029
|
throw new Error(
|
|
@@ -2050,7 +2042,7 @@ class hr {
|
|
|
2050
2042
|
}
|
|
2051
2043
|
}
|
|
2052
2044
|
var De, Le;
|
|
2053
|
-
class
|
|
2045
|
+
class dr {
|
|
2054
2046
|
constructor(e) {
|
|
2055
2047
|
u(this, "wrapped"), u(this, De, "JSONSeriesIterator"), this.wrapped = e;
|
|
2056
2048
|
}
|
|
@@ -2066,7 +2058,7 @@ class fr {
|
|
|
2066
2058
|
}
|
|
2067
2059
|
}
|
|
2068
2060
|
var Pe, Ye;
|
|
2069
|
-
class
|
|
2061
|
+
class gr {
|
|
2070
2062
|
constructor(e) {
|
|
2071
2063
|
u(this, "series"), u(this, "index"), u(this, Pe, "SeriesIterator"), this.series = e, this.index = 0;
|
|
2072
2064
|
}
|
|
@@ -2089,13 +2081,13 @@ i.record(
|
|
|
2089
2081
|
i.union([i.number(), i.string(), i.symbol()]),
|
|
2090
2082
|
i.unknown()
|
|
2091
2083
|
);
|
|
2092
|
-
const nt = () => typeof process < "u" && process.versions != null && process.versions.node != null ? "node" : typeof window > "u" || window.document === void 0 ? "webworker" : "browser",
|
|
2084
|
+
const nt = () => typeof process < "u" && process.versions != null && process.versions.node != null ? "node" : typeof window > "u" || window.document === void 0 ? "webworker" : "browser", pr = nt(), st = ["macOS", "Windows", "Linux"], yr = ["macos", "windows", "linux"], mr = {
|
|
2093
2085
|
macos: "macOS",
|
|
2094
2086
|
windows: "Windows",
|
|
2095
2087
|
linux: "Linux"
|
|
2096
|
-
},
|
|
2097
|
-
i.enum(
|
|
2098
|
-
),
|
|
2088
|
+
}, wr = i.enum(st).or(
|
|
2089
|
+
i.enum(yr).transform((r) => mr[r])
|
|
2090
|
+
), br = () => {
|
|
2099
2091
|
if (typeof window > "u") return;
|
|
2100
2092
|
const r = window.navigator.userAgent.toLowerCase();
|
|
2101
2093
|
if (r.includes("mac")) return "macOS";
|
|
@@ -2103,19 +2095,19 @@ const nt = () => typeof process < "u" && process.versions != null && process.ver
|
|
|
2103
2095
|
if (r.includes("linux")) return "Linux";
|
|
2104
2096
|
};
|
|
2105
2097
|
let fe;
|
|
2106
|
-
const
|
|
2098
|
+
const Or = (r = {}) => {
|
|
2107
2099
|
const { force: e, default: t } = r;
|
|
2108
|
-
return e ?? fe ?? (fe =
|
|
2100
|
+
return e ?? fe ?? (fe = br(), fe ?? t);
|
|
2109
2101
|
}, it = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2110
2102
|
__proto__: null,
|
|
2111
2103
|
OPERATING_SYSTEMS: st,
|
|
2112
|
-
RUNTIME:
|
|
2104
|
+
RUNTIME: pr,
|
|
2113
2105
|
detect: nt,
|
|
2114
|
-
getOS:
|
|
2115
|
-
osZ:
|
|
2106
|
+
getOS: Or,
|
|
2107
|
+
osZ: wr
|
|
2116
2108
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
2117
|
-
var Tr = Object.defineProperty,
|
|
2118
|
-
const
|
|
2109
|
+
var Tr = Object.defineProperty, vr = (r, e, t) => e in r ? Tr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, K = (r, e, t) => vr(r, typeof e != "symbol" ? e + "" : e, t);
|
|
2110
|
+
const Sr = (...r) => r.map(at).join(""), at = (r) => (r.endsWith("/") || (r += "/"), r.startsWith("/") && (r = r.slice(1)), r), Ir = (r) => r.endsWith("/") ? r.slice(0, -1) : r, Nr = (r, e = "") => r === null ? "" : `?${Object.entries(r).filter(([, t]) => t == null ? !1 : Array.isArray(t) ? t.length > 0 : !0).map(([t, n]) => `${e}${t}=${n}`).join("&")}`, me = class we {
|
|
2119
2111
|
/**
|
|
2120
2112
|
* @param host - The hostname or IP address of the server.
|
|
2121
2113
|
* @param port - The port number of the server.
|
|
@@ -2123,7 +2115,7 @@ const vr = (...r) => r.map(at).join(""), at = (r) => (r.endsWith("/") || (r += "
|
|
|
2123
2115
|
* @param pathPrefix - A path prefix to use for all requests. Defaults to "".
|
|
2124
2116
|
*/
|
|
2125
2117
|
constructor({ host: e, port: t, protocol: n = "", pathPrefix: s = "" }) {
|
|
2126
|
-
|
|
2118
|
+
K(this, "protocol"), K(this, "host"), K(this, "port"), K(this, "path"), this.protocol = n, this.host = e, this.port = t, this.path = at(s);
|
|
2127
2119
|
}
|
|
2128
2120
|
/**
|
|
2129
2121
|
* Replaces creates a new URL with the specified properties replaced.
|
|
@@ -2146,56 +2138,56 @@ const vr = (...r) => r.map(at).join(""), at = (r) => (r.endsWith("/") || (r += "
|
|
|
2146
2138
|
child(e) {
|
|
2147
2139
|
return new we({
|
|
2148
2140
|
...this,
|
|
2149
|
-
pathPrefix:
|
|
2141
|
+
pathPrefix: Sr(this.path, e)
|
|
2150
2142
|
});
|
|
2151
2143
|
}
|
|
2152
2144
|
/** @returns a string representation of the url */
|
|
2153
2145
|
toString() {
|
|
2154
|
-
return
|
|
2146
|
+
return Ir(
|
|
2155
2147
|
`${this.protocol}://${this.host}:${this.port}/${this.path}`
|
|
2156
2148
|
);
|
|
2157
2149
|
}
|
|
2158
2150
|
};
|
|
2159
|
-
|
|
2160
|
-
let
|
|
2161
|
-
const
|
|
2162
|
-
i.number().int().min(
|
|
2163
|
-
const
|
|
2164
|
-
i.number().int().min(
|
|
2165
|
-
const
|
|
2166
|
-
i.number().int().min(
|
|
2167
|
-
const
|
|
2168
|
-
i.bigint().min(
|
|
2169
|
-
const
|
|
2170
|
-
i.number().int().min(0).max(Cr);
|
|
2171
|
-
const Dr = 65535;
|
|
2151
|
+
K(me, "UNKNOWN", new me({ host: "unknown", port: 0 }));
|
|
2152
|
+
let Er = me;
|
|
2153
|
+
const Ar = -128, xr = 127;
|
|
2154
|
+
i.number().int().min(Ar).max(xr);
|
|
2155
|
+
const Mr = -32768, $r = 32767;
|
|
2156
|
+
i.number().int().min(Mr).max($r);
|
|
2157
|
+
const Ur = -2147483648, Br = 2147483647;
|
|
2158
|
+
i.number().int().min(Ur).max(Br);
|
|
2159
|
+
const Rr = -9223372036854775808n, Cr = 9223372036854775807n;
|
|
2160
|
+
i.bigint().min(Rr).max(Cr);
|
|
2161
|
+
const Dr = 255;
|
|
2172
2162
|
i.number().int().min(0).max(Dr);
|
|
2173
|
-
const Lr =
|
|
2163
|
+
const Lr = 65535;
|
|
2174
2164
|
i.number().int().min(0).max(Lr);
|
|
2175
|
-
const Pr =
|
|
2176
|
-
i.
|
|
2177
|
-
|
|
2178
|
-
|
|
2165
|
+
const Pr = 4294967295;
|
|
2166
|
+
i.number().int().min(0).max(Pr);
|
|
2167
|
+
const Yr = 18446744073709551615n;
|
|
2168
|
+
i.bigint().min(0n).max(Yr);
|
|
2169
|
+
var kr = Object.defineProperty, jr = (r, e, t) => e in r ? kr(r, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[e] = t, X = (r, e, t) => jr(r, typeof e != "symbol" ? e + "" : e, t);
|
|
2170
|
+
const qr = async (r) => await new Promise(
|
|
2179
2171
|
(e) => setTimeout(e, O.fromMilliseconds(r).milliseconds)
|
|
2180
|
-
),
|
|
2172
|
+
), Fr = i.object({
|
|
2181
2173
|
interval: O.z.optional(),
|
|
2182
2174
|
maxRetries: i.number().optional(),
|
|
2183
2175
|
scale: i.number().optional()
|
|
2184
|
-
}),
|
|
2185
|
-
const e = r.sleepFn ||
|
|
2176
|
+
}), Gr = (r = {}) => {
|
|
2177
|
+
const e = r.sleepFn || qr, t = r.maxRetries ?? 5, n = r.scale ?? 1;
|
|
2186
2178
|
let s = 0, a = new O(r.interval ?? O.milliseconds(1));
|
|
2187
2179
|
return async () => s >= t ? !1 : (await e(a), a = a.mult(n), s++, !0);
|
|
2188
|
-
},
|
|
2180
|
+
}, Wr = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
2189
2181
|
__proto__: null,
|
|
2190
|
-
breakerConfig:
|
|
2191
|
-
create:
|
|
2182
|
+
breakerConfig: Fr,
|
|
2183
|
+
create: Gr
|
|
2192
2184
|
}, Symbol.toStringTag, { value: "Module" })), C = class extends Number {
|
|
2193
2185
|
};
|
|
2194
|
-
|
|
2186
|
+
X(C, "ABSOLUTE", 255), X(C, "MINIMUM", 0), X(C, "BOUNDS", {
|
|
2195
2187
|
lower: C.MINIMUM,
|
|
2196
2188
|
// upper bound is exclusive, so we add 1
|
|
2197
2189
|
upper: C.ABSOLUTE + 1
|
|
2198
|
-
}),
|
|
2190
|
+
}), X(C, "z", i.union([
|
|
2199
2191
|
i.instanceof(C),
|
|
2200
2192
|
i.number().int().min(0).max(255).transform((r) => new C(r)),
|
|
2201
2193
|
i.instanceof(Number).transform((r) => new C(r))
|
|
@@ -2213,10 +2205,12 @@ const ot = class Q extends Error {
|
|
|
2213
2205
|
return typeof e == "string" ? e.includes(Q.MESSAGE) : e instanceof Q || e.message.includes(Q.MESSAGE);
|
|
2214
2206
|
}
|
|
2215
2207
|
};
|
|
2216
|
-
|
|
2217
|
-
let
|
|
2218
|
-
new
|
|
2208
|
+
X(ot, "MESSAGE", "canceled");
|
|
2209
|
+
let Vr = ot;
|
|
2210
|
+
new Vr();
|
|
2219
2211
|
i.string().regex(/^\d+\.\d+\.\d+$/);
|
|
2212
|
+
const zr = ["standard", "scientific", "engineering"];
|
|
2213
|
+
i.enum(zr);
|
|
2220
2214
|
const ve = (r) => (e) => e != null && typeof e == "object" && "type" in e && typeof e.type == "string" ? e.type.includes(r) : e instanceof Error ? e.message.includes(r) : typeof e != "string" ? !1 : e.includes(r);
|
|
2221
2215
|
class oe extends Error {
|
|
2222
2216
|
constructor() {
|
|
@@ -2225,7 +2219,7 @@ class oe extends Error {
|
|
|
2225
2219
|
y(this, "type", "");
|
|
2226
2220
|
}
|
|
2227
2221
|
}
|
|
2228
|
-
const
|
|
2222
|
+
const Zr = (r) => {
|
|
2229
2223
|
if (r == null || typeof r != "object") return !1;
|
|
2230
2224
|
const e = r;
|
|
2231
2225
|
if (e.discriminator !== "FreighterError") return !1;
|
|
@@ -2234,8 +2228,8 @@ const zr = (r) => {
|
|
|
2234
2228
|
`Freighter error is missing its type property: ${JSON.stringify(e)}`
|
|
2235
2229
|
);
|
|
2236
2230
|
return !0;
|
|
2237
|
-
}, je = "unknown", qe = "nil",
|
|
2238
|
-
class
|
|
2231
|
+
}, je = "unknown", qe = "nil", Jr = "freighter", ut = i.object({ type: i.string(), data: i.string() });
|
|
2232
|
+
class Hr {
|
|
2239
2233
|
constructor() {
|
|
2240
2234
|
y(this, "providers", []);
|
|
2241
2235
|
}
|
|
@@ -2244,7 +2238,7 @@ class Zr {
|
|
|
2244
2238
|
}
|
|
2245
2239
|
encode(e) {
|
|
2246
2240
|
if (e == null) return { type: qe, data: "" };
|
|
2247
|
-
if (
|
|
2241
|
+
if (Zr(e))
|
|
2248
2242
|
for (const t of this.providers) {
|
|
2249
2243
|
const n = t.encode(e);
|
|
2250
2244
|
if (n != null) return n;
|
|
@@ -2261,10 +2255,10 @@ class Zr {
|
|
|
2261
2255
|
return new Fe(e.data);
|
|
2262
2256
|
}
|
|
2263
2257
|
}
|
|
2264
|
-
const Se = new
|
|
2258
|
+
const Se = new Hr(), Kr = ({
|
|
2265
2259
|
encode: r,
|
|
2266
2260
|
decode: e
|
|
2267
|
-
}) => Se.register({ encode: r, decode: e }),
|
|
2261
|
+
}) => Se.register({ encode: r, decode: e }), pn = (r) => Se.encode(r), be = (r) => Se.decode(r);
|
|
2268
2262
|
class Fe extends oe {
|
|
2269
2263
|
constructor() {
|
|
2270
2264
|
super(...arguments);
|
|
@@ -2287,26 +2281,26 @@ const W = class W extends oe {
|
|
|
2287
2281
|
};
|
|
2288
2282
|
y(W, "TYPE", `${ue}stream_closed`), y(W, "matches", ve(W.TYPE));
|
|
2289
2283
|
let k = W;
|
|
2290
|
-
const
|
|
2284
|
+
const V = class V extends oe {
|
|
2291
2285
|
constructor(t = {}) {
|
|
2292
|
-
const { message: n = "Unreachable", url: s =
|
|
2286
|
+
const { message: n = "Unreachable", url: s = Er.UNKNOWN } = t;
|
|
2293
2287
|
super(n);
|
|
2294
|
-
y(this, "type",
|
|
2288
|
+
y(this, "type", V.TYPE);
|
|
2295
2289
|
y(this, "url");
|
|
2296
2290
|
this.url = s;
|
|
2297
2291
|
}
|
|
2298
2292
|
};
|
|
2299
|
-
y(
|
|
2300
|
-
let j =
|
|
2301
|
-
const
|
|
2302
|
-
if (!r.type.startsWith(
|
|
2293
|
+
y(V, "TYPE", `${ue}unreachable`), y(V, "matches", ve(V.TYPE));
|
|
2294
|
+
let j = V;
|
|
2295
|
+
const Xr = (r) => {
|
|
2296
|
+
if (!r.type.startsWith(Jr)) return null;
|
|
2303
2297
|
if (Y.matches(r)) return { type: Y.TYPE, data: "EOF" };
|
|
2304
2298
|
if (k.matches(r))
|
|
2305
2299
|
return { type: k.TYPE, data: "StreamClosed" };
|
|
2306
2300
|
if (j.matches(r))
|
|
2307
2301
|
return { type: j.TYPE, data: "Unreachable" };
|
|
2308
2302
|
throw new Error(`Unknown error type: ${r.type}: ${r.message}`);
|
|
2309
|
-
},
|
|
2303
|
+
}, Qr = (r) => {
|
|
2310
2304
|
if (!r.type.startsWith(ue)) return null;
|
|
2311
2305
|
switch (r.type) {
|
|
2312
2306
|
case Y.TYPE:
|
|
@@ -2319,9 +2313,9 @@ const Hr = (r) => {
|
|
|
2319
2313
|
throw new Error(`Unknown error type: ${r.data}`);
|
|
2320
2314
|
}
|
|
2321
2315
|
};
|
|
2322
|
-
|
|
2323
|
-
encode:
|
|
2324
|
-
decode:
|
|
2316
|
+
Kr({
|
|
2317
|
+
encode: Xr,
|
|
2318
|
+
decode: Qr
|
|
2325
2319
|
});
|
|
2326
2320
|
class ct {
|
|
2327
2321
|
constructor() {
|
|
@@ -2357,7 +2351,7 @@ const lt = "Content-Type", Ge = (r) => {
|
|
|
2357
2351
|
const t = require("https"), n = new t.Agent({ rejectUnauthorized: !1 });
|
|
2358
2352
|
return async (s, a) => await e(s, { ...a, agent: n });
|
|
2359
2353
|
};
|
|
2360
|
-
class
|
|
2354
|
+
class yn extends ct {
|
|
2361
2355
|
constructor(t, n, s = !1) {
|
|
2362
2356
|
super();
|
|
2363
2357
|
y(this, "endpoint");
|
|
@@ -2417,7 +2411,7 @@ class gn extends ct {
|
|
|
2417
2411
|
return [c, p];
|
|
2418
2412
|
}
|
|
2419
2413
|
}
|
|
2420
|
-
const
|
|
2414
|
+
const mn = (r, e) => {
|
|
2421
2415
|
class t {
|
|
2422
2416
|
constructor(s) {
|
|
2423
2417
|
y(this, "wrapped");
|
|
@@ -2427,7 +2421,7 @@ const pn = (r, e) => {
|
|
|
2427
2421
|
this.wrapped.use(...s);
|
|
2428
2422
|
}
|
|
2429
2423
|
async send(s, a, c, f) {
|
|
2430
|
-
const d =
|
|
2424
|
+
const d = Wr.create(e);
|
|
2431
2425
|
do {
|
|
2432
2426
|
const [p, m] = await this.wrapped.send(s, a, c, f);
|
|
2433
2427
|
if (m == null || !j.matches(m)) return [p, m];
|
|
@@ -2436,16 +2430,16 @@ const pn = (r, e) => {
|
|
|
2436
2430
|
}
|
|
2437
2431
|
}
|
|
2438
2432
|
return new t(r);
|
|
2439
|
-
},
|
|
2433
|
+
}, wn = async (r, e, t, n, s) => {
|
|
2440
2434
|
const [a, c] = await r.send(e, t, n, s);
|
|
2441
2435
|
if (c != null) throw c;
|
|
2442
2436
|
return a;
|
|
2443
|
-
},
|
|
2437
|
+
}, _r = () => it.RUNTIME !== "node" ? (r) => new WebSocket(r) : (r) => new (require("ws")).WebSocket(r, { rejectUnauthorized: !1 }), en = i.object({
|
|
2444
2438
|
type: i.enum(["data", "close", "open"]),
|
|
2445
2439
|
payload: i.unknown().optional(),
|
|
2446
2440
|
error: i.optional(ut)
|
|
2447
2441
|
});
|
|
2448
|
-
class
|
|
2442
|
+
class tn {
|
|
2449
2443
|
constructor(e, t, n, s) {
|
|
2450
2444
|
y(this, "encoder");
|
|
2451
2445
|
y(this, "reqSchema");
|
|
@@ -2506,13 +2500,13 @@ class _r {
|
|
|
2506
2500
|
t != null ? t.resolve(e) : this.receiveDataQueue.push(e);
|
|
2507
2501
|
}
|
|
2508
2502
|
listenForMessages() {
|
|
2509
|
-
this.ws.onmessage = (e) => this.addMessage(this.encoder.decode(e.data,
|
|
2503
|
+
this.ws.onmessage = (e) => this.addMessage(this.encoder.decode(e.data, en)), this.ws.onclose = (e) => this.addMessage({
|
|
2510
2504
|
type: "close",
|
|
2511
|
-
error: { type:
|
|
2505
|
+
error: { type: on(e) ? Y.TYPE : k.TYPE, data: "" }
|
|
2512
2506
|
});
|
|
2513
2507
|
}
|
|
2514
2508
|
}
|
|
2515
|
-
const
|
|
2509
|
+
const rn = "freighterctx", nn = 1e3, sn = 1001, an = [nn, sn], on = (r) => an.includes(r.code), ie = class ie extends ct {
|
|
2516
2510
|
/**
|
|
2517
2511
|
* @param encoder - The encoder to use for encoding messages and decoding
|
|
2518
2512
|
* responses.
|
|
@@ -2526,7 +2520,7 @@ const en = "freighterctx", tn = 1e3, rn = 1001, nn = [tn, rn], sn = (r) => nn.in
|
|
|
2526
2520
|
}
|
|
2527
2521
|
/** Implements the StreamClient interface. */
|
|
2528
2522
|
async stream(t, n, s) {
|
|
2529
|
-
const a =
|
|
2523
|
+
const a = _r();
|
|
2530
2524
|
let c;
|
|
2531
2525
|
const [, f] = await this.executeMiddleware(
|
|
2532
2526
|
{ target: t, protocol: "websocket", params: {}, role: "client" },
|
|
@@ -2541,19 +2535,19 @@ const en = "freighterctx", tn = 1e3, rn = 1001, nn = [tn, rn], sn = (r) => nn.in
|
|
|
2541
2535
|
return c;
|
|
2542
2536
|
}
|
|
2543
2537
|
buildURL(t, n) {
|
|
2544
|
-
const s =
|
|
2538
|
+
const s = Nr(
|
|
2545
2539
|
{
|
|
2546
2540
|
[lt]: this.encoder.contentType,
|
|
2547
2541
|
...n.params
|
|
2548
2542
|
},
|
|
2549
|
-
|
|
2543
|
+
rn
|
|
2550
2544
|
);
|
|
2551
2545
|
return this.baseUrl.child(t).toString() + s;
|
|
2552
2546
|
}
|
|
2553
2547
|
async wrapSocket(t, n, s) {
|
|
2554
2548
|
return await new Promise((a) => {
|
|
2555
2549
|
t.onopen = () => {
|
|
2556
|
-
const c = new
|
|
2550
|
+
const c = new tn(t, this.encoder, n, s);
|
|
2557
2551
|
c.receiveOpenAck().then((f) => {
|
|
2558
2552
|
f != null ? a(f) : a(c);
|
|
2559
2553
|
}).catch((f) => a(f));
|
|
@@ -2569,15 +2563,15 @@ let We = ie;
|
|
|
2569
2563
|
export {
|
|
2570
2564
|
oe as BaseTypedError,
|
|
2571
2565
|
Y as EOF,
|
|
2572
|
-
|
|
2566
|
+
yn as HTTPClient,
|
|
2573
2567
|
k as StreamClosed,
|
|
2574
2568
|
j as Unreachable,
|
|
2575
2569
|
We as WebSocketClient,
|
|
2576
2570
|
be as decodeError,
|
|
2577
|
-
|
|
2571
|
+
pn as encodeError,
|
|
2578
2572
|
ve as errorMatcher,
|
|
2579
2573
|
ut as errorZ,
|
|
2580
|
-
|
|
2581
|
-
|
|
2582
|
-
|
|
2574
|
+
Kr as registerError,
|
|
2575
|
+
wn as sendRequired,
|
|
2576
|
+
mn as unaryWithBreaker
|
|
2583
2577
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@synnaxlabs/freighter",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "a modular transport abstraction",
|
|
6
6
|
"repository": "https://github.com/synnaxlabs/synnax/tree/main/freighter/ts",
|
|
@@ -17,18 +17,18 @@
|
|
|
17
17
|
"node-fetch": "^2.7.0",
|
|
18
18
|
"ws": "^8.18.1",
|
|
19
19
|
"zod": "^3.24.2",
|
|
20
|
-
"@synnaxlabs/alamos": "0.
|
|
21
|
-
"@synnaxlabs/x": "0.
|
|
20
|
+
"@synnaxlabs/alamos": "0.41.0",
|
|
21
|
+
"@synnaxlabs/x": "0.41.0"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
24
|
"@types/node": "^22.13.10",
|
|
25
|
-
"eslint": "^9.
|
|
25
|
+
"eslint": "^9.24.0",
|
|
26
26
|
"madge": "^8.0.0",
|
|
27
|
-
"typescript": "^5.8.
|
|
28
|
-
"vite": "^6.2.
|
|
29
|
-
"vitest": "^
|
|
30
|
-
"@synnaxlabs/tsconfig": "0.0.2",
|
|
27
|
+
"typescript": "^5.8.3",
|
|
28
|
+
"vite": "^6.2.5",
|
|
29
|
+
"vitest": "^3.1.1",
|
|
31
30
|
"@synnaxlabs/vite-plugin": "0.0.1",
|
|
31
|
+
"@synnaxlabs/tsconfig": "0.0.2",
|
|
32
32
|
"eslint-config-synnaxlabs": "0.0.1"
|
|
33
33
|
},
|
|
34
34
|
"main": "dist/freighter.cjs",
|