@synnaxlabs/freighter 0.29.0 → 0.31.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/freighter.cjs +13 -3
- package/dist/freighter.js +1068 -557
- package/dist/http.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/http.ts +0 -17
package/dist/freighter.cjs
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`)}decodeString(e,t){const[n,...
|
|
3
|
-
`).map(h=>h.trim());if(n.length===0)return t!=null?t.parse({}):{};const a=n.split(",").map(h=>h.trim()),c={};return a.forEach(h=>{c[h]=[]}),i.forEach(h=>{const g=h.split(",").map(m=>m.trim());a.forEach((m,O)=>{const w=this.parseValue(g[O]);w!=null&&c[m].push(w)})}),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(){}},nt=class{constructor(){q(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}};new tt;new rt;new nt;const _=s.z.tuple([s.z.number(),s.z.number()]);s.z.tuple([s.z.bigint(),s.z.bigint()]);const xe=s.z.object({width:s.z.number(),height:s.z.number()}),st=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()}),it=["width","height"];s.z.enum(it);const ot=["start","center","end"],at=["signedWidth","signedHeight"];s.z.enum(at);const J=s.z.object({x:s.z.number(),y:s.z.number()}),ut=s.z.object({clientX:s.z.number(),clientY:s.z.number()}),ct=["x","y"],Ue=s.z.enum(ct),Ce=["top","right","bottom","left"];s.z.enum(Ce);const lt=["left","right"],Me=s.z.enum(lt),ht=["top","bottom"],Be=s.z.enum(ht),Re=["center"],we=s.z.enum(Re),dt=[...Ce,...Re],De=s.z.enum(dt);s.z.enum(ot);const ft=["first","last"];s.z.enum(ft);const pt=s.z.object({lower:s.z.number(),upper:s.z.number()}),yt=s.z.object({lower:s.z.bigint(),upper:s.z.bigint()});s.z.union([pt,_]);s.z.union([yt,_]);s.z.union([Ue,De]);s.z.union([Ue,De,s.z.instanceof(String)]);const ne=(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 Oe(r);return Oe(t)},Oe=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r;s.z.object({x:Me.or(we),y:Be.or(we)});const gt=s.z.object({x:Me,y:Be}),mt=Object.freeze({x:"left",y:"top"}),wt=(r,e)=>r.x===e.x&&r.y===e.y,ve=s.z.union([s.z.number(),J,_,xe,st,ut]),Ot=(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}},be=Object.freeze({x:0,y:0}),Z=s.z.union([s.z.number(),s.z.string()]);s.z.object({top:Z,left:Z,width:Z,height:Z});s.z.object({left:s.z.number(),top:s.z.number(),right:s.z.number(),bottom:s.z.number()});s.z.object({one:J,two:J,root:gt});const de=(r,e,t=0,n=0,i)=>{const a={one:{...be},two:{...be},root:i??mt};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:i??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))},se=r=>{const e=de(r);return{lower:e.one.x,upper:e.two.x}},ie=r=>{const e=de(r);return{lower:e.one.y,upper:e.two.y}},vt=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r;var bt=Object.defineProperty,Tt=(r,e,t)=>e in r?bt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e,t)=>Tt(r,typeof e!="symbol"?e+"":e,t);const St=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;s.z.object({offset:ve,scale:ve});const It=r=>(e,t,n,i)=>t==="dimension"?[e,n]:[e,i?n-r:n+r],Nt=r=>(e,t,n,i)=>[e,i?n/r:n*r],Et=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:i,upper:a}=e,{lower:c,upper:h}=r,g=a-i,m=h-c;if(t==="dimension")return[r,n*(m/g)];const O=(n-i)*(m/g)+c;return[r,O]},zt=r=>(e,t,n)=>[r,n],At=()=>(r,e,t)=>{if(r===null)throw new Error("cannot invert without bounds");if(e==="dimension")return[r,t];const{lower:n,upper:i}=r;return[r,i-(t-n)]},$t=r=>(e,t,n)=>{const{lower:i,upper:a}=r;return n=St(n,i,a),[e,n]},ue=class k{constructor(){C(this,"ops",[]),C(this,"currBounds",null),C(this,"currType",null),C(this,"reversed",!1),this.ops=[]}static translate(e){return new k().translate(e)}static magnify(e){return new k().magnify(e)}static scale(e,t){return new k().scale(e,t)}translate(e){const t=this.new(),n=It(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Nt(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=ne(e,t),i=this.new(),a=Et(n);return a.type="scale",i.ops.push(a),i}clamp(e,t){const n=ne(e,t),i=this.new(),a=$t(n);return a.type="clamp",i.ops.push(a),i}reBound(e,t){const n=ne(e,t),i=this.new(),a=zt(n);return a.type="re-bound",i.ops.push(a),i}invert(){const e=At();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 k;return e.ops=this.ops.slice(),e.reversed=this.reversed,e}exec(e,t){return this.currBounds=null,this.ops.reduce(([n,i],a)=>a(n,e,i,this.reversed),[null,t])[1]}reverse(){const e=this.new();e.ops.reverse();const t=[];return e.ops.forEach((n,i)=>{if(n.type==="scale"||t.some(([c,h])=>i>=c&&i<=h))return;const a=e.ops.findIndex((c,h)=>c.type==="scale"&&h>i);a!==-1&&t.push([i,a])}),t.forEach(([n,i])=>{const a=e.ops.slice(n,i);a.unshift(e.ops[i]),e.ops.splice(n,i-n+1,...a)}),e.reversed=!e.reversed,e}};C(ue,"IDENTITY",new ue);let Te=ue;const Se=class U{constructor(e=new Te,t=new Te,n=null){C(this,"x"),C(this,"y"),C(this,"currRoot"),this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new U().translate(e,t)}static translateX(e){return new U().translateX(e)}static translateY(e){return new U().translateY(e)}static clamp(e){return new U().clamp(e)}static magnify(e){return new U().magnify(e)}static scale(e){return new U().scale(e)}static reBound(e){return new U().reBound(e)}translate(e,t){const n=Ot(e,t),i=this.copy();return i.x=this.x.translate(n.x),i.y=this.y.translate(n.y),i}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(vt(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!wt(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(se(e)),t.y=t.y.scale(ie(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(se(e)),t.y=this.y.reBound(ie(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(se(e)),t.y=this.y.clamp(ie(e)),t}copy(){const e=new U;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}box(e){return de(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};C(Se,"IDENTITY",new Se);const xt=s.z.object({signedWidth:s.z.number(),signedHeight:s.z.number()});s.z.union([xe,xt,J,_]);var Ut=Object.defineProperty,Ct=(r,e,t)=>e in r?Ut(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>Ct(r,typeof e!="symbol"?e+"":e,t);const Ye=(r,e)=>{const t=new T(e);if(![S.DAY,S.HOUR,S.MINUTE,S.SECOND,S.MILLISECOND,S.MICROSECOND,S.NANOSECOND].some(i=>i.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 T?new T(n):new S(n)},p=class l{constructor(e,t="UTC"){if(u(this,"value"),u(this,"encodeValue",!0),e==null)this.value=l.now().valueOf();else if(e instanceof Date)this.value=BigInt(e.getTime())*l.MILLISECOND.valueOf();else if(typeof e=="string")this.value=l.parseDateTimeString(e,t).valueOf();else if(Array.isArray(e))this.value=l.parseDate(e);else{let n=BigInt(0);e instanceof Number&&(e=e.valueOf()),t==="local"&&(n=l.utcOffset.valueOf()),typeof e=="number"&&(isFinite(e)?e=Math.trunc(e):(isNaN(e)&&(e=0),e===1/0?e=l.MAX:e=l.MIN)),this.value=BigInt(e.valueOf())+n}}static parseDate([e=1970,t=1,n=1]){const i=new Date(e,t-1,n,0,0,0,0);return new l(BigInt(i.getTime())*l.MILLISECOND.valueOf()).truncate(l.DAY).valueOf()}encode(){return this.value.toString()}valueOf(){return this.value}static parseTimeString(e,t="UTC"){const[n,i,a]=e.split(":");let c="00",h="00";a!=null&&([c,h]=a.split("."));let g=l.hours(parseInt(n??"00",10)).add(l.minutes(parseInt(i??"00",10))).add(l.seconds(parseInt(c??"00",10))).add(l.milliseconds(parseInt(h??"00",10)));return t==="local"&&(g=g.add(l.utcOffset)),g.valueOf()}static parseDateTimeString(e,t="UTC"){if(!e.includes("/")&&!e.includes("-"))return l.parseTimeString(e,t);const n=new Date(e);return e.includes(":")||n.setUTCHours(0,0,0,0),new l(BigInt(n.getTime())*l.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(l.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 S(BigInt(new Date().getTimezoneOffset())*l.MINUTE.valueOf())}static since(e){return new l().span(e)}date(){return new Date(this.milliseconds())}equals(e){return this.valueOf()===new l(e).valueOf()}span(e){return this.range(e).span}range(e){return new Mt(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 l(e).valueOf()}afterEq(e){return this.valueOf()>=new l(e).valueOf()}before(e){return this.valueOf()<new l(e).valueOf()}beforeEq(e){return this.valueOf()<=new l(e).valueOf()}add(e){return new l(this.valueOf()+BigInt(e.valueOf()))}sub(e){return new l(this.valueOf()-BigInt(e.valueOf()))}milliseconds(){return Number(this.valueOf())/Number(l.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return Ye(this,e)}get isToday(){return this.truncate(S.DAY).equals(l.now().truncate(S.DAY))}truncate(e){return this.sub(this.remainder(e))}static now(){return new l(new Date)}static max(...e){let t=l.MIN;for(const n of e){const i=new l(n);i.after(t)&&(t=i)}return t}static min(...e){let t=l.MAX;for(const n of e){const i=new l(n);i.before(t)&&(t=i)}return t}static nanoseconds(e){return new l(e)}static microseconds(e){return l.nanoseconds(e*1e3)}static milliseconds(e){return l.microseconds(e*1e3)}static seconds(e){return l.milliseconds(e*1e3)}static minutes(e){return l.seconds(e*60)}static hours(e){return l.minutes(e*60)}static days(e){return l.hours(e*24)}};u(p,"NANOSECOND",p.nanoseconds(1)),u(p,"MICROSECOND",p.microseconds(1)),u(p,"MILLISECOND",p.milliseconds(1)),u(p,"SECOND",p.seconds(1)),u(p,"MINUTE",p.minutes(1)),u(p,"HOUR",p.hours(1)),u(p,"DAY",p.days(1)),u(p,"MAX",new p((1n<<63n)-1n)),u(p,"MIN",new p(0)),u(p,"ZERO",new p(0)),u(p,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(r=>new p(r.value)),s.z.string().transform(r=>new p(BigInt(r))),s.z.instanceof(Number).transform(r=>new p(r)),s.z.number().transform(r=>new p(r)),s.z.instanceof(p)]));let T=p;const y=class d{constructor(e){u(this,"value"),u(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new d(e).valueOf()}greaterThan(e){return this.valueOf()>new d(e).valueOf()}lessThanOrEqual(e){return this.valueOf()<=new d(e).valueOf()}greaterThanOrEqual(e){return this.valueOf()>=new d(e).valueOf()}remainder(e){return Ye(this,e)}truncate(e){return new d(BigInt(Math.trunc(Number(this.valueOf()/e.valueOf())))*e.valueOf())}toString(){const e=this.truncate(d.DAY),t=this.truncate(d.HOUR),n=this.truncate(d.MINUTE),i=this.truncate(d.SECOND),a=this.truncate(d.MILLISECOND),c=this.truncate(d.MICROSECOND),h=this.truncate(d.NANOSECOND),g=e,m=t.sub(e),O=n.sub(t),w=i.sub(n),z=a.sub(i),L=c.sub(a),x=h.sub(c);let E="";return g.isZero||(E+=`${g.days}d `),m.isZero||(E+=`${m.hours}h `),O.isZero||(E+=`${O.minutes}m `),w.isZero||(E+=`${w.seconds}s `),z.isZero||(E+=`${z.milliseconds}ms `),L.isZero||(E+=`${L.microseconds}µs `),x.isZero||(E+=`${x.nanoseconds}ns`),E.trim()}get days(){return Number(this.valueOf())/Number(d.DAY.valueOf())}get hours(){return Number(this.valueOf())/Number(d.HOUR.valueOf())}get minutes(){return Number(this.valueOf())/Number(d.MINUTE.valueOf())}get seconds(){return Number(this.valueOf())/Number(d.SECOND.valueOf())}get milliseconds(){return Number(this.valueOf())/Number(d.MILLISECOND.valueOf())}get microseconds(){return Number(this.valueOf())/Number(d.MICROSECOND.valueOf())}get nanoseconds(){return Number(this.valueOf())}get isZero(){return this.valueOf()===BigInt(0)}equals(e){return this.valueOf()===new d(e).valueOf()}add(e){return new d(this.valueOf()+new d(e).valueOf())}sub(e){return new d(this.valueOf()-new d(e).valueOf())}static nanoseconds(e=1){return new d(e)}static microseconds(e=1){return d.nanoseconds(e*1e3)}static milliseconds(e=1){return d.microseconds(e*1e3)}static seconds(e=1){return d.milliseconds(e*1e3)}static minutes(e){return d.seconds(e.valueOf()*60)}static hours(e){return d.minutes(e*60)}static days(e){return d.hours(e*24)}};u(y,"NANOSECOND",y.nanoseconds(1)),u(y,"MICROSECOND",y.microseconds(1)),u(y,"MILLISECOND",y.milliseconds(1)),u(y,"SECOND",y.seconds(1)),u(y,"MINUTE",y.minutes(1)),u(y,"HOUR",y.hours(1)),u(y,"DAY",y.days(1)),u(y,"MAX",new y((1n<<63n)-1n)),u(y,"MIN",new y(0)),u(y,"ZERO",new y(0)),u(y,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(r=>new y(r.value)),s.z.string().transform(r=>new y(BigInt(r))),s.z.instanceof(Number).transform(r=>new y(r)),s.z.number().transform(r=>new y(r)),s.z.instanceof(y)]));let S=y;const H=class V extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new V(e).valueOf()}get period(){return S.seconds(1/this.valueOf())}sampleCount(e){return new S(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new N(t).valueOf()}span(e){return S.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new V(e)}static khz(e){return V.hz(e*1e3)}};u(H,"z",s.z.union([s.z.number().transform(r=>new H(r)),s.z.instanceof(Number).transform(r=>new H(r)),s.z.instanceof(H)]));const b=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Bt(e*this.valueOf())}};u(b,"UNKNOWN",new b(0)),u(b,"BIT128",new b(16)),u(b,"BIT64",new b(8)),u(b,"BIT32",new b(4)),u(b,"BIT16",new b(2)),u(b,"BIT8",new b(1)),u(b,"z",s.z.union([s.z.number().transform(r=>new b(r)),s.z.instanceof(Number).transform(r=>new b(r)),s.z.instanceof(b)]));let N=b;const A=class K{constructor(e,t){u(this,"start"),u(this,"end"),typeof e=="object"&&"start"in e?(this.start=new T(e.start),this.end=new T(e.end)):(this.start=new T(e),this.end=new T(t))}get span(){return new S(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 K(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=S.ZERO){e=e.makeValid();const n=this.makeValid();if(this.equals(e))return!0;if(e.end.equals(n.start)||n.end.equals(e.start))return!1;const i=T.max(n.start,e.start),a=T.min(n.end,e.end);return a.before(i)?!1:new S(a.sub(i)).greaterThanOrEqual(t)}roughlyEquals(e,t){let n=this.start.sub(e.start).valueOf(),i=this.end.sub(e.end).valueOf();return n<0&&(n=-n),i<0&&(i=-i),n<=t.valueOf()&&i<=t.valueOf()}contains(e){return e instanceof K?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new K(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(A,"MAX",new A(T.MIN,T.MAX)),u(A,"MIN",new A(T.MAX,T.MIN)),u(A,"ZERO",new A(T.ZERO,T.ZERO)),u(A,"z",s.z.union([s.z.object({start:T.z,end:T.z}).transform(r=>new A(r.start,r.end)),s.z.instanceof(A)]));let Mt=A;const o=class $ extends String{constructor(e){if(e instanceof $||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const t=$.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}}throw super($.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=$.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($.JSON)||this.equals($.STRING)}get isNumeric(){return!this.isVariable&&!this.equals($.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=$.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return $.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(),N.BIT8],[o.UINT16.toString(),N.BIT16],[o.UINT32.toString(),N.BIT32],[o.UINT64.toString(),N.BIT64],[o.FLOAT32.toString(),N.BIT32],[o.FLOAT64.toString(),N.BIT64],[o.INT8.toString(),N.BIT8],[o.INT16.toString(),N.BIT16],[o.INT32.toString(),N.BIT32],[o.INT64.toString(),N.BIT64],[o.TIMESTAMP.toString(),N.BIT64],[o.STRING.toString(),N.UNKNOWN],[o.JSON.toString(),N.UNKNOWN],[o.UUID.toString(),N.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",s.z.union([s.z.string().transform(r=>new o(r)),s.z.instanceof(o)]));const I=class v extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return v.bytes(this.valueOf()+e.valueOf())}sub(e){return v.bytes(this.valueOf()-e.valueOf())}truncate(e){return new v(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return v.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/v.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/v.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/v.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/v.TERABYTE.valueOf()}toString(){const e=this.truncate(v.TERABYTE),t=this.truncate(v.GIGABYTE),n=this.truncate(v.MEGABYTE),i=this.truncate(v.KILOBYTE),a=this.truncate(v.BYTE),c=e,h=t.sub(e),g=n.sub(t),m=i.sub(n),O=a.sub(i);let w="";return c.isZero||(w+=`${c.terabytes}TB `),h.isZero||(w+=`${h.gigabytes}GB `),g.isZero||(w+=`${g.megabytes}MB `),m.isZero||(w+=`${m.kilobytes}KB `),(!O.isZero||w==="")&&(w+=`${O.valueOf()}B`),w.trim()}static bytes(e=1){return new v(e)}static kilobytes(e=1){return v.bytes(e.valueOf()*1e3)}static megabytes(e=1){return v.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return v.megabytes(e.valueOf()*1e3)}static terabytes(e){return v.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};u(I,"BYTE",new I(1)),u(I,"KILOBYTE",I.kilobytes(1)),u(I,"MEGABYTE",I.megabytes(1)),u(I,"GIGABYTE",I.gigabytes(1)),u(I,"TERABYTE",I.terabytes(1)),u(I,"ZERO",new I(0)),u(I,"z",s.z.union([s.z.number().transform(r=>new I(r)),s.z.instanceof(I)]));let Bt=I;s.z.union([s.z.instanceof(Uint8Array),s.z.instanceof(Uint16Array),s.z.instanceof(Uint32Array),s.z.instanceof(BigUint64Array),s.z.instanceof(Float32Array),s.z.instanceof(Float64Array),s.z.instanceof(Int8Array),s.z.instanceof(Int16Array),s.z.instanceof(Int32Array),s.z.instanceof(BigInt64Array)]);s.z.object({key:s.z.string(),value:s.z.string()});s.z.record(s.z.union([s.z.number(),s.z.string(),s.z.symbol()]),s.z.unknown());const Pe=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",Rt=Pe(),je=["MacOS","Windows","Linux","Docker"],Dt=s.z.enum(je);let oe;const Yt=()=>{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"},Pt=(r={})=>{const{force:e,default:t}=r;return e??oe??(oe=Yt(),oe??t)},Le=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:je,RUNTIME:Rt,detect:Pe,getOS:Pt,osZ:Dt},Symbol.toStringTag,{value:"Module"}));var jt=Object.defineProperty,Lt=(r,e,t)=>e in r?jt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,W=(r,e,t)=>Lt(r,typeof e!="symbol"?e+"":e,t);const kt=(...r)=>r.map(ke).join(""),ke=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),Wt=r=>r.endsWith("/")?r.slice(0,-1):r,Ft=(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("&"),ce=class le{constructor({host:e,port:t,protocol:n="",pathPrefix:i=""}){W(this,"protocol"),W(this,"host"),W(this,"port"),W(this,"path"),this.protocol=n,this.host=e,this.port=t,this.path=ke(i)}replace(e){return new le({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new le({...this,pathPrefix:kt(this.path,e)})}toString(){return Wt(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};W(ce,"UNKNOWN",new ce({host:"unknown",port:0}));let qt=ce;var Gt=Object.defineProperty,Zt=(r,e,t)=>e in r?Gt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,X=(r,e,t)=>Zt(r,typeof e!="symbol"?e+"":e,t);const D=class extends Number{};X(D,"Absolute",255),X(D,"Default",1),X(D,"z",s.z.union([s.z.instanceof(D),s.z.number().int().min(0).max(255).transform(r=>new D(r)),s.z.instanceof(Number).transform(r=>new D(r))]));s.z.object({name:s.z.string(),key:s.z.string()});const We=class F extends Error{constructor(){super(F.MESSAGE)}matches(e){return typeof e=="string"?e.includes(F.MESSAGE):e instanceof F||e.message.includes(F.MESSAGE)}};X(We,"MESSAGE","canceled");let Ht=We;new Ht;s.z.string().regex(/^\d+\.\d+\.\d+$/);const ee=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 G extends Error{constructor(t){super(t);f(this,"discriminator","FreighterError");f(this,"type","")}}const Vt=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},Ie="unknown",Ne="nil",Kt="freighter",fe=s.z.object({type:s.z.string(),data:s.z.string()});class Xt{constructor(){f(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:Ne,data:""};if(Vt(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}return{type:Ie,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===Ne)return null;if(e.type===Ie)return new Ee(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Ee(e.data)}}const pe=new Xt,Fe=({encode:r,decode:e})=>pe.register({encode:r,decode:e}),Jt=r=>pe.encode(r),ye=r=>pe.decode(r);class Ee extends G{constructor(t){super(t);f(this,"type","unknown")}}const te="freighter.",Y=class Y extends G{constructor(){super("EOF");f(this,"type",Y.TYPE)}};f(Y,"TYPE",te+"eof"),f(Y,"matches",ee(Y.TYPE));let M=Y;const P=class P extends G{constructor(){super("StreamClosed");f(this,"type",P.TYPE)}};f(P,"TYPE",te+"stream_closed"),f(P,"matches",ee(P.TYPE));let B=P;const j=class j extends G{constructor(t={}){const{message:n="Unreachable",url:i=qt.UNKNOWN}=t;super(n);f(this,"type",j.TYPE);f(this,"url");this.url=i}};f(j,"TYPE",te+"unreachable"),f(j,"matches",ee(j.TYPE));let R=j;const Qt=r=>{if(!r.type.startsWith(Kt))return null;if(M.matches(r))return{type:M.TYPE,data:"EOF"};if(B.matches(r))return{type:B.TYPE,data:"StreamClosed"};if(R.matches(r))return{type:R.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},_t=r=>{if(!r.type.startsWith(te))return null;switch(r.type){case M.TYPE:return new M;case B.TYPE:return new B;case R.TYPE:return new R;default:throw new Error(`Unknown error type: ${r.data}`)}};Fe({encode:Qt,decode:_t});class qe{constructor(){f(this,"middleware",[])}use(...e){this.middleware.push(...e)}async executeMiddleware(e,t){let n=0;const i=async a=>{if(n===this.middleware.length)return await t(a);const c=this.middleware[n];return n++,await c(a,i)};return await i(e)}}const Ge="Content-Type",ze=r=>{if(Le.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(i,a)=>await e(i,{...a,agent:n})};class er extends qe{constructor(t,n,i=!1){super();f(this,"endpoint");f(this,"encoder");f(this,"fetch");return this.endpoint=t.replace({protocol:i?"https":"http"}),this.encoder=n,this.fetch=ze(this.endpoint.protocol),new Proxy(this,{get:(a,c,h)=>c==="endpoint"?this.endpoint:Reflect.get(a,c,h)})}get headers(){return{[Ge]:this.encoder.contentType}}async send(t,n,i,a){n=i==null?void 0:i.parse(n);let c=null;const h=this.endpoint.child(t),g={};g.method="POST",g.body=this.encoder.encode(n??{});const[,m]=await this.executeMiddleware({target:h.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async O=>{const w={...O,params:{}};g.headers={...this.headers,...O.params};let z;try{z=await ze(O.protocol)(O.target,g)}catch(x){let E=x;return E.message==="Load failed"&&(E=new R({url:h})),[w,E]}const L=await z.arrayBuffer();if(z!=null&&z.ok)return a!=null&&(c=this.encoder.decode(L,a)),[w,null];try{if(z.status!==400)return[w,new Error(z.statusText)];const x=this.encoder.decode(L,fe),E=ye(x);return[w,E]}catch(x){return[w,new Error(`[freighter] - failed to decode error: ${z.statusText}: ${x.message}`)]}});return[c,m]}}const tr=async(r,e,t,n,i)=>{const[a,c]=await r.send(e,t,n,i);if(c!=null)throw c;return a},rr=()=>Le.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),nr=s.z.object({type:s.z.union([s.z.literal("data"),s.z.literal("close")]),payload:s.z.unknown().optional(),error:s.z.optional(fe)});class sr{constructor(e,t,n,i){f(this,"encoder");f(this,"reqSchema");f(this,"resSchema");f(this,"ws");f(this,"serverClosed");f(this,"sendClosed");f(this,"receiveDataQueue",[]);f(this,"receiveCallbacksQueue",[]);this.encoder=t,this.reqSchema=n,this.resSchema=i,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new M;if(this.sendClosed)throw new B;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=ye(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,nr)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:cr(e)?M.TYPE:B.TYPE,data:""}})}}const ir="freighterctx",or=1e3,ar=1001,ur=[or,ar],cr=r=>ur.includes(r.code),Q=class Q extends qe{constructor(t,n,i=!1){super();f(this,"baseUrl");f(this,"encoder");this.baseUrl=t.replace({protocol:i?"wss":"ws"}),this.encoder=n}async stream(t,n,i){const a=rr();let c;const[,h]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async g=>{const m=a(this.buildURL(t,g)),O={...g,params:{}};m.binaryType=Q.MESSAGE_TYPE;const w=await this.wrapSocket(m,n,i);return w instanceof Error?[O,w]:(c=w,[O,null])});if(h!=null)throw h;return c}buildURL(t,n){const i=Ft({[Ge]:this.encoder.contentType,...n.params},ir);return this.baseUrl.child(t).toString()+i}async wrapSocket(t,n,i){return await new Promise(a=>{t.onopen=()=>{a(new sr(t,this.encoder,n,i))},t.onerror=c=>{const h=c;a(new Error(h.message))}})}};f(Q,"MESSAGE_TYPE","arraybuffer");let he=Q;exports.BaseTypedError=G;exports.EOF=M;exports.HTTPClient=er;exports.StreamClosed=B;exports.Unreachable=R;exports.WebSocketClient=he;exports.decodeError=ye;exports.encodeError=Jt;exports.errorMatcher=ee;exports.errorZ=fe;exports.registerError=Fe;exports.sendRequired=tr;
|
|
1
|
+
"use strict";var at=Object.defineProperty;var ot=(r,e,t)=>e in r?at(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var p=(r,e,t)=>ot(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("zod"),ut=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:e[0].toLowerCase()+e.slice(1)},Ye=r=>{const e=(t,n=fe)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!ce(t))return t;n=ht(n);const s={},a=t;return Object.keys(a).forEach(c=>{let d=a[c];const f=r(c);n.recursive&&(ce(d)?Ie(d,n.keepTypesOnRecursion)||(d=e(d,n)):n.recursiveInArray&&Se(d)&&(d=[...d].map(y=>{let T=y;return ce(y)?Ie(T,n.keepTypesOnRecursion)||(T=e(y,n)):Se(y)&&(T=e({key:y},n).key),T}))),s[f]=d}),s};return e},ke=Ye(ut),ct=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),lt=Ye(ct),fe={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},ht=(r=fe)=>(r.recursive==null?r=fe:r.recursiveInArray==null&&(r.recursiveInArray=!1),r),Se=r=>r!=null&&Array.isArray(r),ce=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),Ie=(r,e)=>(e||[]).some(t=>r instanceof t),je=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var dt=Object.defineProperty,ft=(r,e,t)=>e in r?dt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,H=(r,e,t)=>ft(r,typeof e!="symbol"?e+"":e,t);let gt=class{constructor(){H(this,"contentType","application/json"),H(this,"decoder"),H(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=ke(n);return t!=null?t.parse(s):s}encodeString(e){const t=lt(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(){}},pt=class{constructor(){H(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
|
+
`)}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(y=>y.trim());a.forEach((y,T)=>{const l=this.parseValue(f[T]);l!=null&&c[y].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(){}},yt=class{constructor(){H(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 ee=new gt;new pt;new yt;const ae=i.z.tuple([i.z.number(),i.z.number()]);i.z.tuple([i.z.bigint(),i.z.bigint()]);const Fe=i.z.object({width:i.z.number(),height:i.z.number()}),mt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()}),wt=["width","height"];i.z.enum(wt);const bt=["start","center","end"],Tt=["signedWidth","signedHeight"];i.z.enum(Tt);const se=i.z.object({x:i.z.number(),y:i.z.number()}),Ot=i.z.object({clientX:i.z.number(),clientY:i.z.number()}),vt=["x","y"],qe=i.z.enum(vt),Ge=["top","right","bottom","left"];i.z.enum(Ge);const St=["left","right"],We=i.z.enum(St),It=["top","bottom"],Ze=i.z.enum(It),Ve=["center"],Ne=i.z.enum(Ve),Nt=[...Ge,...Ve],Je=i.z.enum(Nt);i.z.enum(bt);const Et=["first","last"];i.z.enum(Et);const At=i.z.object({lower:i.z.number(),upper:i.z.number()}),zt=i.z.object({lower:i.z.bigint(),upper:i.z.bigint()});i.z.union([At,ae]);i.z.union([zt,ae]);i.z.union([qe,Je]);i.z.union([qe,Je,i.z.instanceof(String)]);const K=(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 Ee(r);return Ee(t)},Ee=r=>r.lower>r.upper?{lower:r.upper,upper:r.lower}:r;i.z.object({x:We.or(Ne),y:Ze.or(Ne)});const xt=i.z.object({x:We,y:Ze}),Mt=Object.freeze({x:"left",y:"top"}),$t=(r,e)=>r.x===e.x&&r.y===e.y,Ae=i.z.union([i.z.number(),se,ae,Fe,mt,Ot]),Rt=(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}},ze=Object.freeze({x:0,y:0}),Q=i.z.union([i.z.number(),i.z.string()]);i.z.object({top:Q,left:Q,width:Q,height:Q});i.z.object({left:i.z.number(),top:i.z.number(),right:i.z.number(),bottom:i.z.number()});i.z.object({one:se,two:se,root:xt});const we=(r,e,t=0,n=0,s)=>{const a={one:{...ze},two:{...ze},root:s??Mt};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))},le=r=>{const e=we(r);return{lower:e.one.x,upper:e.two.x}},he=r=>{const e=we(r);return{lower:e.one.y,upper:e.two.y}},Bt=r=>typeof r!="object"||r==null?!1:"one"in r&&"two"in r&&"root"in r;var Ut=Object.defineProperty,Ct=(r,e,t)=>e in r?Ut(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,C=(r,e,t)=>Ct(r,typeof e!="symbol"?e+"":e,t);const Dt=(r,e,t)=>e!==void 0&&r<e?e:t!==void 0&&r>t?t:r;i.z.object({offset:Ae,scale:Ae});const Pt=r=>(e,t,n,s)=>t==="dimension"?[e,n]:[e,s?n-r:n+r],Lt=r=>(e,t,n,s)=>[e,s?n/r:n*r],Yt=r=>(e,t,n)=>{if(e===null)return[r,n];const{lower:s,upper:a}=e,{lower:c,upper:d}=r,f=a-s,y=d-c;if(t==="dimension")return[r,n*(y/f)];const T=(n-s)*(y/f)+c;return[r,T]},kt=r=>(e,t,n)=>[r,n],jt=()=>(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)]},Ft=r=>(e,t,n)=>{const{lower:s,upper:a}=r;return n=Dt(n,s,a),[e,n]},ge=class G{constructor(){C(this,"ops",[]),C(this,"currBounds",null),C(this,"currType",null),C(this,"reversed",!1),this.ops=[]}static translate(e){return new G().translate(e)}static magnify(e){return new G().magnify(e)}static scale(e,t){return new G().scale(e,t)}translate(e){const t=this.new(),n=Pt(e);return n.type="translate",t.ops.push(n),t}magnify(e){const t=this.new(),n=Lt(e);return n.type="magnify",t.ops.push(n),t}scale(e,t){const n=K(e,t),s=this.new(),a=Yt(n);return a.type="scale",s.ops.push(a),s}clamp(e,t){const n=K(e,t),s=this.new(),a=Ft(n);return a.type="clamp",s.ops.push(a),s}reBound(e,t){const n=K(e,t),s=this.new(),a=kt(n);return a.type="re-bound",s.ops.push(a),s}invert(){const e=jt();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 G;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}};C(ge,"IDENTITY",new ge);let xe=ge;const Me=class B{constructor(e=new xe,t=new xe,n=null){C(this,"x"),C(this,"y"),C(this,"currRoot"),this.x=e,this.y=t,this.currRoot=n}static translate(e,t){return new B().translate(e,t)}static translateX(e){return new B().translateX(e)}static translateY(e){return new B().translateY(e)}static clamp(e){return new B().clamp(e)}static magnify(e){return new B().magnify(e)}static scale(e){return new B().scale(e)}static reBound(e){return new B().reBound(e)}translate(e,t){const n=Rt(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(Bt(e)){const n=this.currRoot;return t.currRoot=e.root,n!=null&&!$t(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(le(e)),t.y=t.y.scale(he(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(le(e)),t.y=this.y.reBound(he(e)),t}clamp(e){const t=this.copy();return t.x=this.x.clamp(le(e)),t.y=this.y.clamp(he(e)),t}copy(){const e=new B;return e.currRoot=this.currRoot,e.x=this.x,e.y=this.y,e}reverse(){const e=this.copy();return e.x=this.x.reverse(),e.y=this.y.reverse(),e}pos(e){return{x:this.x.pos(e.x),y:this.y.pos(e.y)}}box(e){return we(this.pos(e.one),this.pos(e.two),0,0,this.currRoot??e.root)}};C(Me,"IDENTITY",new Me);const qt=r=>r!=null&&typeof r=="object"&&"toString"in r,Gt=(r,e=!1)=>{const t=qt(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?Wt(n):n},Wt=r=>(e,t)=>r(t,e),Zt=i.z.object({signedWidth:i.z.number(),signedHeight:i.z.number()});i.z.union([Fe,Zt,se,ae]);const Vt=i.z.bigint().or(i.z.string().transform(BigInt));var Jt=Object.defineProperty,Ht=(r,e,t)=>e in r?Jt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>Ht(r,typeof e!="symbol"?e+"":e,t);let Kt=(r,e=21)=>(t=e)=>{let n="",s=t;for(;s--;)n+=r[Math.random()*r.length|0];return n};const Xt="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",Qt=Kt(Xt,11),_t=i.z.enum(["static","dynamic"]),He=(r,e)=>{const t=new O(e);if(![S.DAY,S.HOUR,S.MINUTE,S.SECOND,S.MILLISECOND,S.MICROSECOND,S.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 O?new O(n):new S(n)},m=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",10)).add(h.minutes(parseInt(s??"00",10))).add(h.seconds(parseInt(c??"00",10))).add(h.milliseconds(parseInt(d??"00",10)));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 S(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 be(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()))}milliseconds(){return Number(this.valueOf())/Number(h.MILLISECOND.valueOf())}toString(){return this.date().toISOString()}remainder(e){return He(this,e)}get isToday(){return this.truncate(S.DAY).equals(h.now().truncate(S.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(m,"NANOSECOND",m.nanoseconds(1)),u(m,"MICROSECOND",m.microseconds(1)),u(m,"MILLISECOND",m.milliseconds(1)),u(m,"SECOND",m.seconds(1)),u(m,"MINUTE",m.minutes(1)),u(m,"HOUR",m.hours(1)),u(m,"DAY",m.days(1)),u(m,"MAX",new m((1n<<63n)-1n)),u(m,"MIN",new m(0)),u(m,"ZERO",new m(0)),u(m,"z",i.z.union([i.z.object({value:i.z.bigint()}).transform(r=>new m(r.value)),i.z.string().transform(r=>new m(BigInt(r))),i.z.instanceof(Number).transform(r=>new m(r)),i.z.number().transform(r=>new m(r)),i.z.instanceof(m)]));let O=m;const w=class g{constructor(e){u(this,"value"),u(this,"encodeValue",!0),typeof e=="number"&&(e=Math.trunc(e.valueOf())),this.value=BigInt(e.valueOf())}encode(){return this.value.toString()}valueOf(){return this.value}lessThan(e){return this.valueOf()<new 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 He(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,y=t.sub(e),T=n.sub(t),l=s.sub(n),E=a.sub(s),$=c.sub(a),R=d.sub(c);let z="";return f.isZero||(z+=`${f.days}d `),y.isZero||(z+=`${y.hours}h `),T.isZero||(z+=`${T.minutes}m `),l.isZero||(z+=`${l.seconds}s `),E.isZero||(z+=`${E.milliseconds}ms `),$.isZero||(z+=`${$.microseconds}µs `),R.isZero||(z+=`${R.nanoseconds}ns`),z.trim()}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(e*1e3)}static milliseconds(e=1){return g.microseconds(e*1e3)}static seconds(e=1){return g.milliseconds(e*1e3)}static minutes(e){return g.seconds(e.valueOf()*60)}static hours(e){return g.minutes(e*60)}static days(e){return g.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 S=w;const _=class te extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}toString(){return`${this.valueOf()} Hz`}equals(e){return this.valueOf()===new te(e).valueOf()}get period(){return S.seconds(1/this.valueOf())}sampleCount(e){return new S(e).seconds*this.valueOf()}byteCount(e,t){return this.sampleCount(e)*new A(t).valueOf()}span(e){return S.seconds(e/this.valueOf())}byteSpan(e,t){return this.span(e.valueOf()/t.valueOf())}static hz(e){return new te(e)}static khz(e){return te.hz(e*1e3)}};u(_,"z",i.z.union([i.z.number().transform(r=>new _(r)),i.z.instanceof(Number).transform(r=>new _(r)),i.z.instanceof(_)]));const I=class extends Number{constructor(e){e instanceof Number?super(e.valueOf()):super(e)}length(e){return e.valueOf()/this.valueOf()}size(e){return new Ke(e*this.valueOf())}};u(I,"UNKNOWN",new I(0)),u(I,"BIT128",new I(16)),u(I,"BIT64",new I(8)),u(I,"BIT32",new I(4)),u(I,"BIT16",new I(2)),u(I,"BIT8",new I(1)),u(I,"z",i.z.union([i.z.number().transform(r=>new I(r)),i.z.instanceof(Number).transform(r=>new I(r)),i.z.instanceof(I)]));let A=I;const x=class re{constructor(e,t){u(this,"start"),u(this,"end"),typeof e=="object"&&"start"in e?(this.start=new O(e.start),this.end=new O(e.end)):(this.start=new O(e),this.end=new O(t))}get span(){return new S(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 re(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=S.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=O.max(n.start,e.start),a=O.min(n.end,e.end);return a.before(s)?!1:new S(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 re?this.contains(e.start)&&this.contains(e.end):this.start.beforeEq(e)&&this.end.after(e)}boundBy(e){const t=new re(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(x,"MAX",new x(O.MIN,O.MAX)),u(x,"MIN",new x(O.MAX,O.MIN)),u(x,"ZERO",new x(O.ZERO,O.ZERO)),u(x,"z",i.z.union([i.z.object({start:O.z,end:O.z}).transform(r=>new x(r.start,r.end)),i.z.instanceof(x)]));let be=x;const o=class M extends String{constructor(e){if(e instanceof M||typeof e=="string"||typeof e.valueOf()=="string"){super(e.valueOf());return}else{const t=M.ARRAY_CONSTRUCTOR_DATA_TYPES.get(e.constructor.name);if(t!=null){super(t.valueOf());return}}throw super(M.UNKNOWN.valueOf()),new Error(`unable to find data type for ${e.toString()}`)}get Array(){const e=M.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(M.JSON)||this.equals(M.STRING)}get isNumeric(){return!this.isVariable&&!this.equals(M.UUID)}get isInteger(){return this.toString().startsWith("int")}get isFloat(){return this.toString().startsWith("float")}get density(){const e=M.DENSITIES.get(this.toString());if(e==null)throw new Error(`unable to find density for ${this.valueOf()}`);return e}canSafelyCastTo(e){return this.equals(e)?!0:this.isVariable&&!e.isVariable||!this.isVariable&&e.isVariable?!1:this.isFloat&&e.isInteger||this.isInteger&&e.isFloat?this.density.valueOf()<e.density.valueOf():this.isFloat&&e.isFloat||this.isInteger&&e.isInteger?this.density.valueOf()<=e.density.valueOf():!1}canCastTo(e){return this.isNumeric&&e.isNumeric?!0:this.equals(e)}checkArray(e){return e.constructor===this.Array}toJSON(){return this.toString()}get usesBigInt(){return M.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(),A.BIT8],[o.UINT16.toString(),A.BIT16],[o.UINT32.toString(),A.BIT32],[o.UINT64.toString(),A.BIT64],[o.FLOAT32.toString(),A.BIT32],[o.FLOAT64.toString(),A.BIT64],[o.INT8.toString(),A.BIT8],[o.INT16.toString(),A.BIT16],[o.INT32.toString(),A.BIT32],[o.INT64.toString(),A.BIT64],[o.TIMESTAMP.toString(),A.BIT64],[o.STRING.toString(),A.UNKNOWN],[o.JSON.toString(),A.UNKNOWN],[o.UUID.toString(),A.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 b=o;const N=class v extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return v.bytes(this.valueOf()+e.valueOf())}sub(e){return v.bytes(this.valueOf()-e.valueOf())}truncate(e){return new v(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return v.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/v.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/v.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/v.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/v.TERABYTE.valueOf()}toString(){const e=this.truncate(v.TERABYTE),t=this.truncate(v.GIGABYTE),n=this.truncate(v.MEGABYTE),s=this.truncate(v.KILOBYTE),a=this.truncate(v.BYTE),c=e,d=t.sub(e),f=n.sub(t),y=s.sub(n),T=a.sub(s);let l="";return c.isZero||(l+=`${c.terabytes}TB `),d.isZero||(l+=`${d.gigabytes}GB `),f.isZero||(l+=`${f.megabytes}MB `),y.isZero||(l+=`${y.kilobytes}KB `),(!T.isZero||l==="")&&(l+=`${T.valueOf()}B`),l.trim()}static bytes(e=1){return new v(e)}static kilobytes(e=1){return v.bytes(e.valueOf()*1e3)}static megabytes(e=1){return v.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return v.megabytes(e.valueOf()*1e3)}static terabytes(e){return v.gigabytes(e.valueOf()*1e3)}get isZero(){return this.valueOf()===0}};u(N,"BYTE",new N(1)),u(N,"KILOBYTE",N.kilobytes(1)),u(N,"MEGABYTE",N.megabytes(1)),u(N,"GIGABYTE",N.gigabytes(1)),u(N,"TERABYTE",N.terabytes(1)),u(N,"ZERO",new N(0)),u(N,"z",i.z.union([i.z.number().transform(r=>new N(r)),i.z.instanceof(N)]));let Ke=N;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 Xe=r=>{const e=typeof r;return e==="string"||e==="number"||e==="boolean"||e==="bigint"||r instanceof O||r instanceof S||r instanceof Date},er=(r,e,t,n=0)=>r.usesBigInt&&!e.usesBigInt?Number(t)-Number(n):!r.usesBigInt&&e.usesBigInt?BigInt(t)-BigInt(n):Z(t,-n),tr=r=>r==null?!1:Array.isArray(r)||r instanceof ArrayBuffer||ArrayBuffer.isView(r)&&!(r instanceof DataView)||r instanceof sr?!0:Xe(r),Y=-1,rr=i.z.string().transform(r=>new Uint8Array(atob(r).split("").map(e=>e.charCodeAt(0))).buffer),nr=i.z.union([i.z.null(),i.z.undefined()]).transform(()=>new Uint8Array().buffer),W=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",Y),u(this,"_refCount",0),u(this,"_cachedLength"),tr(e)&&(e={data:e});const{dataType:t,timeRange:n,sampleOffset:s=0,glBufferUsage:a="static",alignment:c=0n,key:d=Qt()}=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 y=Xe(f),T=Array.isArray(f);if(t!=null)this.dataType=new b(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(T||y){let l=f;if(!y){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=b.STRING;else if(typeof l=="number")this.dataType=b.FLOAT64;else if(typeof l=="bigint")this.dataType=b.INT64;else if(typeof l=="boolean")this.dataType=b.BOOLEAN;else if(l instanceof O||l instanceof Date||l instanceof O)this.dataType=b.TIMESTAMP;else if(typeof l=="object")this.dataType=b.JSON;else throw new Error(`cannot infer data type of ${typeof l} when constructing a Series from a JS array`)}else this.dataType=new b(f)}if(!T&&!y)this._data=f;else{let l=y?[f]:f;const E=l[0];(E instanceof O||E instanceof Date||E instanceof S)&&(l=l.map($=>new O($).valueOf())),this.dataType.equals(b.STRING)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(l.join(`
|
|
4
|
+
`)+`
|
|
5
|
+
`)):this.dataType.equals(b.JSON)?(this._cachedLength=l.length,this._data=new TextEncoder().encode(l.map($=>ee.encodeString($)).join(`
|
|
6
|
+
`)+`
|
|
7
|
+
`)):this._data=new this.dataType.Array(l).buffer}this.key=d,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 b(t).Array(e),a=new U({data:s.buffer,dataType:t,...n});return a.writePos=0,a}static generateTimestamps(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:b.TIMESTAMP,timeRange:s})}get refCount(){return this._refCount}static fromStrings(e,t){const n=new TextEncoder().encode(e.join(`
|
|
8
|
+
`)+`
|
|
9
|
+
`);return new U({data:n,dataType:b.STRING,timeRange:t})}static fromJSON(e,t){const n=new TextEncoder().encode(e.map(s=>ee.encodeString(s)).join(`
|
|
10
|
+
`)+`
|
|
11
|
+
`);return new U({data:n,dataType:b.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");if(this.writePos===Y)return 0;const t=this.capacity-this.writePos,n=t<e.length?e.slice(0,t):e;return this.underlyingData.set(n.data,this.writePos),this.maybeRecomputeMinMax(n),this._cachedLength=void 0,this.writePos+=n.length,n.length}get buffer(){return this._data}get underlyingData(){return new this.dataType.Array(this._data)}get data(){return this.writePos===Y?this.underlyingData:new this.dataType.Array(this._data,0,this.writePos)}toStrings(){if(!this.dataType.matches(b.STRING,b.UUID))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
|
|
12
|
+
`).slice(0,-1)}toUUIDs(){if(!this.dataType.equals(b.UUID))throw new Error("cannot convert non-uuid series to uuids");const e=b.UUID.density.valueOf(),t=Array(this.length);for(let n=0;n<this.length;n++){const s=this.buffer.slice(n*e,(n+1)*e),a=Array.from(new Uint8Array(s),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(b.JSON))throw new Error("cannot convert non-string series to strings");return new TextDecoder().decode(this.buffer).split(`
|
|
13
|
+
`).slice(0,-1).map(t=>e.parse(ee.decodeString(t)))}get timeRange(){if(this._timeRange==null)throw new Error("time range not set on series");return this._timeRange}get byteCapacity(){return new Ke(this.buffer.byteLength)}get capacity(){return this.dataType.density.length(this.byteCapacity)}get byteLength(){return this.writePos===Y?this.byteCapacity:this.dataType.density.size(this.writePos)}get length(){return this._cachedLength!=null?this._cachedLength:this.dataType.isVariable?this.calculateCachedLength():this.writePos===Y?this.data.length:this.writePos}calculateCachedLength(){if(!this.dataType.isVariable)throw new Error("cannot calculate length of a non-variable length data type");let e=0;return this.data.forEach(t=>{t===10&&e++}),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]=er(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(b.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==null&&(this._cachedMax=this.calcRawMax()),Z(this._cachedMax,this.sampleOffset))}calcRawMin(){if(this.length===0)return 1/0;if(this.dataType.equals(b.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==null&&(this._cachedMin=this.calcRawMin()),Z(this._cachedMin,this.sampleOffset))}get bounds(){return K(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 Z(this.max,-this.min)}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 Z(n,this.sampleOffset)}atVariable(e,t){e<0&&(e=this.length+e);let n=0,s=0;for(let c=0;c<this.data.length;c++)if(this.data[c]===10){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(b.STRING)?new TextDecoder().decode(a):ke(JSON.parse(new TextDecoder().decode(a)))}binarySearch(e){let t=0,n=this.length-1;const s=Gt(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(b.FLOAT32))throw new Error("Only FLOAT32 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!==Y){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=Y}as(e){if(e==="string"){if(!this.dataType.equals(b.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(b.INT64))throw new Error(`cannot convert series of type ${this.dataType.toString()} to bigint`);return this}throw new Error(`cannot convert series to ${e}`)}get digest(){var e;return{key:this.key,dataType:this.dataType.toString(),sampleOffset:this.sampleOffset,alignment:this.alignmentBounds,timeRange:(e=this._timeRange)==null?void 0:e.toString(),length:this.length,capacity:this.capacity}}get memInfo(){return{key:this.key,length:this.length,byteLength:this.byteLength,glBuffer:this.gl.buffer!=null}}get alignmentBounds(){return K(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 ir(this);return this.dataType.equals(b.JSON)?new ar(e):e}return new or(this)}slice(e,t){if(e<=0&&(t==null||t>=this.length))return this;const n=this.data.slice(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)})}reAlign(e){return new U({data:this.buffer,dataType:this.dataType,timeRange:be.ZERO,sampleOffset:this.sampleOffset,glBufferUsage:"static",alignment:e})}};u(W,"crudeZ",i.z.object({timeRange:be.z.optional(),dataType:b.z,alignment:Vt.optional(),data:i.z.union([rr,nr,i.z.instanceof(ArrayBuffer)]),glBufferUsage:_t.optional().default("static").optional()})),u(W,"z",W.crudeZ.transform(r=>new W(r)));let sr=W;class ir{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]!==10;)this.index++;const n=this.index;return e===n?{done:!0,value:void 0}:(this.index++,{done:!1,value:this.decoder.decode(this.series.buffer.slice(e,n))})}[Symbol.iterator](){return this}}var $e,Re;class ar{constructor(e){u(this,"wrapped"),u(this,$e,"JSONSeriesIterator"),this.wrapped=e}next(){const e=this.wrapped.next();return e.done===!0?{done:!0,value:void 0}:{done:!1,value:ee.decodeString(e.value)}}[(Re=Symbol.iterator,$e=Symbol.toStringTag,Re)](){return this}}var Be,Ue;class or{constructor(e){u(this,"series"),u(this,"index"),u(this,Be,"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)}}[(Ue=Symbol.iterator,Be=Symbol.toStringTag,Ue)](){return this}}const Z=(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);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 Qe=()=>typeof process<"u"&&process.versions!=null&&process.versions.node!=null?"node":typeof window>"u"||window.document===void 0?"webworker":"browser",ur=Qe(),_e=["MacOS","Windows","Linux","Docker"],cr=i.z.enum(_e);let de;const lr=()=>{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"},hr=(r={})=>{const{force:e,default:t}=r;return e??de??(de=lr(),de??t)},et=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:_e,RUNTIME:ur,detect:Qe,getOS:hr,osZ:cr},Symbol.toStringTag,{value:"Module"}));var dr=Object.defineProperty,fr=(r,e,t)=>e in r?dr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,V=(r,e,t)=>fr(r,typeof e!="symbol"?e+"":e,t);const gr=(...r)=>r.map(tt).join(""),tt=r=>(r.endsWith("/")||(r+="/"),r.startsWith("/")&&(r=r.slice(1)),r),pr=r=>r.endsWith("/")?r.slice(0,-1):r,yr=(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("&"),pe=class ye{constructor({host:e,port:t,protocol:n="",pathPrefix:s=""}){V(this,"protocol"),V(this,"host"),V(this,"port"),V(this,"path"),this.protocol=n,this.host=e,this.port=t,this.path=tt(s)}replace(e){return new ye({host:e.host??this.host,port:e.port??this.port,protocol:e.protocol??this.protocol,pathPrefix:e.pathPrefix??this.path})}child(e){return new ye({...this,pathPrefix:gr(this.path,e)})}toString(){return pr(`${this.protocol}://${this.host}:${this.port}/${this.path}`)}};V(pe,"UNKNOWN",new pe({host:"unknown",port:0}));let mr=pe;var wr=Object.defineProperty,br=(r,e,t)=>e in r?wr(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,ne=(r,e,t)=>br(r,typeof e!="symbol"?e+"":e,t);const k=class extends Number{};ne(k,"Absolute",255),ne(k,"Default",1),ne(k,"z",i.z.union([i.z.instanceof(k),i.z.number().int().min(0).max(255).transform(r=>new k(r)),i.z.instanceof(Number).transform(r=>new k(r))]));i.z.object({name:i.z.string(),key:i.z.string()});const rt=class J extends Error{constructor(){super(J.MESSAGE)}matches(e){return typeof e=="string"?e.includes(J.MESSAGE):e instanceof J||e.message.includes(J.MESSAGE)}};ne(rt,"MESSAGE","canceled");let Tr=rt;new Tr;i.z.string().regex(/^\d+\.\d+\.\d+$/);const oe=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 X extends Error{constructor(t){super(t);p(this,"discriminator","FreighterError");p(this,"type","")}}const Or=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},Ce="unknown",De="nil",vr="freighter",Te=i.z.object({type:i.z.string(),data:i.z.string()});class Sr{constructor(){p(this,"providers",[])}register(e){this.providers.push(e)}encode(e){if(e==null)return{type:De,data:""};if(Or(e))for(const t of this.providers){const n=t.encode(e);if(n!=null)return n}return{type:Ce,data:JSON.stringify(e)}}decode(e){if(e==null||e.type===De)return null;if(e.type===Ce)return new Pe(e.data);for(const t of this.providers){const n=t.decode(e);if(n!=null)return n}return new Pe(e.data)}}const Oe=new Sr,nt=({encode:r,decode:e})=>Oe.register({encode:r,decode:e}),Ir=r=>Oe.encode(r),ve=r=>Oe.decode(r);class Pe extends X{constructor(t){super(t);p(this,"type","unknown")}}const ue="freighter.",j=class j extends X{constructor(){super("EOF");p(this,"type",j.TYPE)}};p(j,"TYPE",ue+"eof"),p(j,"matches",oe(j.TYPE));let D=j;const F=class F extends X{constructor(){super("StreamClosed");p(this,"type",F.TYPE)}};p(F,"TYPE",ue+"stream_closed"),p(F,"matches",oe(F.TYPE));let P=F;const q=class q extends X{constructor(t={}){const{message:n="Unreachable",url:s=mr.UNKNOWN}=t;super(n);p(this,"type",q.TYPE);p(this,"url");this.url=s}};p(q,"TYPE",ue+"unreachable"),p(q,"matches",oe(q.TYPE));let L=q;const Nr=r=>{if(!r.type.startsWith(vr))return null;if(D.matches(r))return{type:D.TYPE,data:"EOF"};if(P.matches(r))return{type:P.TYPE,data:"StreamClosed"};if(L.matches(r))return{type:L.TYPE,data:"Unreachable"};throw new Error(`Unknown error type: ${r.type}: ${r.message}`)},Er=r=>{if(!r.type.startsWith(ue))return null;switch(r.type){case D.TYPE:return new D;case P.TYPE:return new P;case L.TYPE:return new L;default:throw new Error(`Unknown error type: ${r.data}`)}};nt({encode:Nr,decode:Er});class st{constructor(){p(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 it="Content-Type",Le=r=>{if(et.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 Ar extends st{constructor(t,n,s=!1){super();p(this,"endpoint");p(this,"encoder");p(this,"fetch");return this.endpoint=t.replace({protocol:s?"https":"http"}),this.encoder=n,this.fetch=Le(this.endpoint.protocol),new Proxy(this,{get:(a,c,d)=>c==="endpoint"?this.endpoint:Reflect.get(a,c,d)})}get headers(){return{[it]: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[,y]=await this.executeMiddleware({target:d.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async T=>{const l={...T,params:{}};f.headers={...this.headers,...T.params};let E;try{E=await Le(T.protocol)(T.target,f)}catch(R){let z=R;return z.message==="Load failed"&&(z=new L({url:d})),[l,z]}const $=await E.arrayBuffer();if(E!=null&&E.ok)return a!=null&&(c=this.encoder.decode($,a)),[l,null];try{if(E.status!==400)return[l,new Error(E.statusText)];const R=this.encoder.decode($,Te),z=ve(R);return[l,z]}catch(R){return[l,new Error(`[freighter] - failed to decode error: ${E.statusText}: ${R.message}`)]}});return[c,y]}}const zr=async(r,e,t,n,s)=>{const[a,c]=await r.send(e,t,n,s);if(c!=null)throw c;return a},xr=()=>et.RUNTIME!=="node"?r=>new WebSocket(r):r=>new(require("ws")).WebSocket(r,{rejectUnauthorized:!1}),Mr=i.z.object({type:i.z.union([i.z.literal("data"),i.z.literal("close")]),payload:i.z.unknown().optional(),error:i.z.optional(Te)});class $r{constructor(e,t,n,s){p(this,"encoder");p(this,"reqSchema");p(this,"resSchema");p(this,"ws");p(this,"serverClosed");p(this,"sendClosed");p(this,"receiveDataQueue",[]);p(this,"receiveCallbacksQueue",[]);this.encoder=t,this.reqSchema=n,this.resSchema=s,this.ws=e,this.sendClosed=!1,this.serverClosed=null,this.listenForMessages()}send(e){if(this.serverClosed!=null)return new D;if(this.sendClosed)throw new P;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=ve(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,Mr)),this.ws.onclose=e=>this.addMessage({type:"close",error:{type:Dr(e)?D.TYPE:P.TYPE,data:""}})}}const Rr="freighterctx",Br=1e3,Ur=1001,Cr=[Br,Ur],Dr=r=>Cr.includes(r.code),ie=class ie extends st{constructor(t,n,s=!1){super();p(this,"baseUrl");p(this,"encoder");this.baseUrl=t.replace({protocol:s?"wss":"ws"}),this.encoder=n}async stream(t,n,s){const a=xr();let c;const[,d]=await this.executeMiddleware({target:t,protocol:"websocket",params:{},role:"client"},async f=>{const y=a(this.buildURL(t,f)),T={...f,params:{}};y.binaryType=ie.MESSAGE_TYPE;const l=await this.wrapSocket(y,n,s);return l instanceof Error?[T,l]:(c=l,[T,null])});if(d!=null)throw d;return c}buildURL(t,n){const s=yr({[it]:this.encoder.contentType,...n.params},Rr);return this.baseUrl.child(t).toString()+s}async wrapSocket(t,n,s){return await new Promise(a=>{t.onopen=()=>{a(new $r(t,this.encoder,n,s))},t.onerror=c=>{const d=c;a(new Error(d.message))}})}};p(ie,"MESSAGE_TYPE","arraybuffer");let me=ie;exports.BaseTypedError=X;exports.EOF=D;exports.HTTPClient=Ar;exports.StreamClosed=P;exports.Unreachable=L;exports.WebSocketClient=me;exports.decodeError=ve;exports.encodeError=Ir;exports.errorMatcher=oe;exports.errorZ=Te;exports.registerError=nt;exports.sendRequired=zr;
|