@synnaxlabs/freighter 0.25.0 → 0.26.7

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.
@@ -1,3 +1,3 @@
1
- "use strict";var Ze=Object.defineProperty;var He=(r,e,t)=>e in r?Ze(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var f=(r,e,t)=>He(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ve=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)},Ae=r=>{const e=(t,n=ae)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(a=>e(a,n));if(!re(t))return null;n=Qe(n);const i={};return Object.keys(t).forEach(a=>{let c=t[a];const h=r(a);n.recursive&&(re(c)?we(c,n.keepTypesOnRecursion)||(c=e(c,n)):n.recursiveInArray&&ge(c)&&(c=[...c].map(p=>{let m=p;return re(p)?we(m,n.keepTypesOnRecursion)||(m=e(p,n)):ge(p)&&(m=e({key:p},n).key),m}))),i[h]=c}),i};return e},Ke=Ae(Ve),Xe=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Je=Ae(Xe),ae={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Qe=(r=ae)=>(r.recursive==null?r=ae:r.recursiveInArray==null&&(r.recursiveInArray=!1),r),ge=r=>r!=null&&Array.isArray(r),re=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),we=(r,e)=>(e||[]).some(t=>r instanceof t),$e=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var _e=Object.defineProperty,et=(r,e,t)=>e in r?_e(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,G=(r,e,t)=>et(r,typeof e!="symbol"?e+"":e,t);let tt=class{constructor(){G(this,"contentType","application/json"),G(this,"decoder"),G(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),i=Ke(n);return t!=null?t.parse(i):i}encodeString(e){const t=Je(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):$e(i)&&"encode_value"in i?typeof i.value=="bigint"?i.value.toString():i.value:typeof i=="bigint"?i.toString():i)}static registerCustomType(){}},rt=class{constructor(){G(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||!$e(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(i=>{const a=t.map(c=>JSON.stringify(i[c]??""));n.push(a.join(","))}),n.join(`
1
+ "use strict";var Ze=Object.defineProperty;var He=(r,e,t)=>e in r?Ze(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var f=(r,e,t)=>He(r,typeof e!="symbol"?e+"":e,t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("zod"),Ve=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)},Ae=r=>{const e=(t,n=ae)=>{if(typeof t=="string")return r(t);if(Array.isArray(t))return t.map(c=>e(c,n));if(!re(t))return t;n=Qe(n);const i={},a=t;return Object.keys(a).forEach(c=>{let h=a[c];const g=r(c);n.recursive&&(re(h)?we(h,n.keepTypesOnRecursion)||(h=e(h,n)):n.recursiveInArray&&ge(h)&&(h=[...h].map(w=>{let O=w;return re(w)?we(O,n.keepTypesOnRecursion)||(O=e(w,n)):ge(w)&&(O=e({key:w},n).key),O}))),i[g]=h}),i};return e},Ke=Ae(Ve),Xe=r=>r.replace(/([a-z0-9])([A-Z])/g,(e,t,n)=>`${t}_${n.toLowerCase()}`),Je=Ae(Xe),ae={recursive:!0,recursiveInArray:!0,keepTypesOnRecursion:[Number,String,Uint8Array]},Qe=(r=ae)=>(r.recursive==null?r=ae:r.recursiveInArray==null&&(r.recursiveInArray=!1),r),ge=r=>r!=null&&Array.isArray(r),re=r=>r!=null&&typeof r=="object"&&!Array.isArray(r),we=(r,e)=>(e||[]).some(t=>r instanceof t),$e=r=>r!=null&&typeof r=="object"&&!Array.isArray(r);var _e=Object.defineProperty,et=(r,e,t)=>e in r?_e(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,G=(r,e,t)=>et(r,typeof e!="symbol"?e+"":e,t);let tt=class{constructor(){G(this,"contentType","application/json"),G(this,"decoder"),G(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),i=Ke(n);return t!=null?t.parse(i):i}encodeString(e){const t=Je(e);return JSON.stringify(t,(n,i)=>ArrayBuffer.isView(i)?Array.from(i):$e(i)&&"encode_value"in i?typeof i.value=="bigint"?i.value.toString():i.value:typeof i=="bigint"?i.toString():i)}static registerCustomType(){}},rt=class{constructor(){G(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||!$e(e[0]))throw new Error("Payload must be an array of objects");const t=Object.keys(e[0]),n=[t.join(",")];return e.forEach(i=>{const a=t.map(c=>JSON.stringify(i[c]??""));n.push(a.join(","))}),n.join(`
2
2
  `)}decodeString(e,t){const[n,...i]=e.trim().split(`
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 p=h.split(",").map(m=>m.trim());a.forEach((m,v)=>{const w=this.parseValue(p[v]);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(){G(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),Me=["top","right","bottom","left"];s.z.enum(Me);const lt=["left","right"],Ce=s.z.enum(lt),ht=["top","bottom"],Be=s.z.enum(ht),Re=["center"],me=s.z.enum(Re),dt=[...Me,...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:Ce.or(me),y:Be.or(me)});const gt=s.z.object({x:Ce,y:Be}),wt=Object.freeze({x:"left",y:"top"}),mt=(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??wt};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,M=(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,p=a-i,m=h-c;if(t==="dimension")return[r,n*(m/p)];const v=(n-i)*(m/p)+c;return[r,v]},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(){M(this,"ops",[]),M(this,"currBounds",null),M(this,"currType",null),M(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}};M(ue,"IDENTITY",new ue);let Te=ue;const Se=class U{constructor(e=new Te,t=new Te,n=null){M(this,"x"),M(this,"y"),M(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&&!mt(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)}};M(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,Mt=(r,e,t)=>e in r?Ut(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,u=(r,e,t)=>Mt(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)},y=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 p=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"&&(p=p.add(l.utcOffset)),p.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 Ct(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(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 T=y;const g=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),p=e,m=t.sub(e),v=n.sub(t),w=i.sub(n),z=a.sub(i),j=c.sub(a),x=h.sub(c);let E="";return p.isZero||(E+=`${p.days}d `),m.isZero||(E+=`${m.hours}h `),v.isZero||(E+=`${v.minutes}m `),w.isZero||(E+=`${w.seconds}s `),z.isZero||(E+=`${z.milliseconds}ms `),j.isZero||(E+=`${j.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(g,"NANOSECOND",g.nanoseconds(1)),u(g,"MICROSECOND",g.microseconds(1)),u(g,"MILLISECOND",g.milliseconds(1)),u(g,"SECOND",g.seconds(1)),u(g,"MINUTE",g.minutes(1)),u(g,"HOUR",g.hours(1)),u(g,"DAY",g.days(1)),u(g,"MAX",new g((1n<<63n)-1n)),u(g,"MIN",new g(0)),u(g,"ZERO",new g(0)),u(g,"z",s.z.union([s.z.object({value:s.z.bigint()}).transform(r=>new g(r.value)),s.z.string().transform(r=>new g(BigInt(r))),s.z.instanceof(Number).transform(r=>new g(r)),s.z.number().transform(r=>new g(r)),s.z.instanceof(g)]));let S=g;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}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 Ct=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()}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 O extends Number{constructor(e){super(e.valueOf())}largerThan(e){return this.valueOf()>e.valueOf()}smallerThan(e){return this.valueOf()<e.valueOf()}add(e){return O.bytes(this.valueOf()+e.valueOf())}sub(e){return O.bytes(this.valueOf()-e.valueOf())}truncate(e){return new O(Math.trunc(this.valueOf()/e.valueOf())*e.valueOf())}remainder(e){return O.bytes(this.valueOf()%e.valueOf())}get gigabytes(){return this.valueOf()/O.GIGABYTE.valueOf()}get megabytes(){return this.valueOf()/O.MEGABYTE.valueOf()}get kilobytes(){return this.valueOf()/O.KILOBYTE.valueOf()}get terabytes(){return this.valueOf()/O.TERABYTE.valueOf()}toString(){const e=this.truncate(O.TERABYTE),t=this.truncate(O.GIGABYTE),n=this.truncate(O.MEGABYTE),i=this.truncate(O.KILOBYTE),a=this.truncate(O.BYTE),c=e,h=t.sub(e),p=n.sub(t),m=i.sub(n),v=a.sub(i);let w="";return c.isZero||(w+=`${c.terabytes}TB `),h.isZero||(w+=`${h.gigabytes}GB `),p.isZero||(w+=`${p.megabytes}MB `),m.isZero||(w+=`${m.kilobytes}KB `),(!v.isZero||w==="")&&(w+=`${v.valueOf()}B`),w.trim()}static bytes(e=1){return new O(e)}static kilobytes(e=1){return O.bytes(e.valueOf()*1e3)}static megabytes(e=1){return O.kilobytes(e.valueOf()*1e3)}static gigabytes(e=1){return O.megabytes(e.valueOf()*1e3)}static terabytes(e){return O.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.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(),Le=["MacOS","Windows","Linux","Docker"],Dt=s.z.enum(Le);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)},je=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Le,RUNTIME:Rt,detect:Pe,getOS:Pt,osZ:Dt},Symbol.toStringTag,{value:"Module"}));var Lt=Object.defineProperty,jt=(r,e,t)=>e in r?Lt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,W=(r,e,t)=>jt(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 Gt=ce;var qt=Object.defineProperty,Zt=(r,e,t)=>e in r?qt(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 q 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 q{constructor(t){super(t);f(this,"type","unknown")}}const te="freighter.",Y=class Y extends q{constructor(){super("EOF");f(this,"type",Y.TYPE)}};f(Y,"TYPE",te+"eof"),f(Y,"matches",ee(Y.TYPE));let C=Y;const P=class P extends q{constructor(){super("StreamClosed");f(this,"type",P.TYPE)}};f(P,"TYPE",te+"stream_closed"),f(P,"matches",ee(P.TYPE));let B=P;const L=class L extends q{constructor(t={}){const{message:n="Unreachable",url:i=Gt.UNKNOWN}=t;super(n);f(this,"type",L.TYPE);f(this,"url");this.url=i}};f(L,"TYPE",te+"unreachable"),f(L,"matches",ee(L.TYPE));let R=L;const Qt=r=>{if(!r.type.startsWith(Kt))return null;if(C.matches(r))return{type:C.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 C.TYPE:return new C;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 Ge{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 qe="Content-Type",ze=r=>{if(je.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 Ge{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{[qe]: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),p={};p.method="POST",p.body=this.encoder.encode(n??{});const[,m]=await this.executeMiddleware({target:h.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async v=>{const w={...v,params:{}};p.headers={...this.headers,...v.params};let z;try{z=await ze(v.protocol)(v.target,p)}catch(x){let E=x;return E.message==="Load failed"&&(E=new R({url:h})),[w,E]}const j=await z.arrayBuffer();if(z!=null&&z.ok)return a!=null&&(c=this.encoder.decode(j,a)),[w,null];try{if(z.status!==400)return[w,new Error(z.statusText)];const x=this.encoder.decode(j,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=()=>je.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 C;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)?C.TYPE:B.TYPE,data:""}})}}const ir="freighterctx",or=1e3,ar=1001,ur=[or,ar],cr=r=>ur.includes(r.code),Q=class Q extends Ge{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 p=>{const m=a(this.buildURL(t,p)),v={...p,params:{}};m.binaryType=Q.MESSAGE_TYPE;const w=await this.wrapSocket(m,n,i);return w instanceof Error?[v,w]:(c=w,[v,null])});if(h!=null)throw h;return c}buildURL(t,n){const i=Ft({[qe]: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=q;exports.EOF=C;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;
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(w=>w.trim());a.forEach((w,O)=>{const m=this.parseValue(g[O]);m!=null&&c[w].push(m)})}),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(){G(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"],me=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(me),y:Be.or(me)});const gt=s.z.object({x:Me,y:Be}),wt=Object.freeze({x:"left",y:"top"}),mt=(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??wt};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,w=h-c;if(t==="dimension")return[r,n*(w/g)];const O=(n-i)*(w/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&&!mt(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,w=t.sub(e),O=n.sub(t),m=i.sub(n),z=a.sub(i),j=c.sub(a),x=h.sub(c);let E="";return g.isZero||(E+=`${g.days}d `),w.isZero||(E+=`${w.hours}h `),O.isZero||(E+=`${O.minutes}m `),m.isZero||(E+=`${m.seconds}s `),z.isZero||(E+=`${z.milliseconds}ms `),j.isZero||(E+=`${j.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}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()}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),w=i.sub(n),O=a.sub(i);let m="";return c.isZero||(m+=`${c.terabytes}TB `),h.isZero||(m+=`${h.gigabytes}GB `),g.isZero||(m+=`${g.megabytes}MB `),w.isZero||(m+=`${w.kilobytes}KB `),(!O.isZero||m==="")&&(m+=`${O.valueOf()}B`),m.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.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(),Le=["MacOS","Windows","Linux","Docker"],Dt=s.z.enum(Le);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)},je=Object.freeze(Object.defineProperty({__proto__:null,OPERATING_SYSTEMS:Le,RUNTIME:Rt,detect:Pe,getOS:Pt,osZ:Dt},Symbol.toStringTag,{value:"Module"}));var Lt=Object.defineProperty,jt=(r,e,t)=>e in r?Lt(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t,W=(r,e,t)=>jt(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 Gt=ce;var qt=Object.defineProperty,Zt=(r,e,t)=>e in r?qt(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 q 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 q{constructor(t){super(t);f(this,"type","unknown")}}const te="freighter.",Y=class Y extends q{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 q{constructor(){super("StreamClosed");f(this,"type",P.TYPE)}};f(P,"TYPE",te+"stream_closed"),f(P,"matches",ee(P.TYPE));let B=P;const L=class L extends q{constructor(t={}){const{message:n="Unreachable",url:i=Gt.UNKNOWN}=t;super(n);f(this,"type",L.TYPE);f(this,"url");this.url=i}};f(L,"TYPE",te+"unreachable"),f(L,"matches",ee(L.TYPE));let R=L;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 Ge{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 qe="Content-Type",ze=r=>{if(je.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 Ge{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{[qe]: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[,w]=await this.executeMiddleware({target:h.toString(),protocol:this.endpoint.protocol,params:{},role:"client"},async O=>{const m={...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})),[m,E]}const j=await z.arrayBuffer();if(z!=null&&z.ok)return a!=null&&(c=this.encoder.decode(j,a)),[m,null];try{if(z.status!==400)return[m,new Error(z.statusText)];const x=this.encoder.decode(j,fe),E=ye(x);return[m,E]}catch(x){return[m,new Error(`[freighter] - failed to decode error: ${z.statusText}: ${x.message}`)]}});return[c,w]}}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=()=>je.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 Ge{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 w=a(this.buildURL(t,g)),O={...g,params:{}};w.binaryType=Q.MESSAGE_TYPE;const m=await this.wrapSocket(w,n,i);return m instanceof Error?[O,m]:(c=m,[O,null])});if(h!=null)throw h;return c}buildURL(t,n){const i=Ft({[qe]: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=q;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;
package/dist/freighter.js CHANGED
@@ -8,17 +8,17 @@ const Ve = (r) => {
8
8
  }, Ee = (r) => {
9
9
  const e = (t, n = oe) => {
10
10
  if (typeof t == "string") return r(t);
11
- if (Array.isArray(t)) return t.map((a) => e(a, n));
12
- if (!te(t)) return null;
11
+ if (Array.isArray(t)) return t.map((c) => e(c, n));
12
+ if (!te(t)) return t;
13
13
  n = Je(n);
14
- const i = {};
15
- return Object.keys(t).forEach((a) => {
16
- let c = t[a];
17
- const h = r(a);
18
- n.recursive && (te(c) ? pe(c, n.keepTypesOnRecursion) || (c = e(c, n)) : n.recursiveInArray && fe(c) && (c = [...c].map((p) => {
19
- let m = p;
20
- return te(p) ? pe(m, n.keepTypesOnRecursion) || (m = e(p, n)) : fe(p) && (m = e({ key: p }, n).key), m;
21
- }))), i[h] = c;
14
+ const i = {}, a = t;
15
+ return Object.keys(a).forEach((c) => {
16
+ let h = a[c];
17
+ const g = r(c);
18
+ n.recursive && (te(h) ? pe(h, n.keepTypesOnRecursion) || (h = e(h, n)) : n.recursiveInArray && fe(h) && (h = [...h].map((w) => {
19
+ let O = w;
20
+ return te(w) ? pe(O, n.keepTypesOnRecursion) || (O = e(w, n)) : fe(w) && (O = e({ key: w }, n).key), O;
21
+ }))), i[g] = h;
22
22
  }), i;
23
23
  };
24
24
  return e;
@@ -79,10 +79,10 @@ let et = class {
79
79
  return a.forEach((h) => {
80
80
  c[h] = [];
81
81
  }), i.forEach((h) => {
82
- const p = h.split(",").map((m) => m.trim());
83
- a.forEach((m, v) => {
84
- const w = this.parseValue(p[v]);
85
- w != null && c[m].push(w);
82
+ const g = h.split(",").map((w) => w.trim());
83
+ a.forEach((w, O) => {
84
+ const m = this.parseValue(g[O]);
85
+ m != null && c[w].push(m);
86
86
  });
87
87
  }), t != null ? t.parse(c) : c;
88
88
  }
@@ -209,10 +209,10 @@ const It = (r) => (e, t, n, i) => t === "dimension" ? [e, n] : [
209
209
  i ? n / r : n * r
210
210
  ], Nt = (r) => (e, t, n) => {
211
211
  if (e === null) return [r, n];
212
- const { lower: i, upper: a } = e, { lower: c, upper: h } = r, p = a - i, m = h - c;
213
- if (t === "dimension") return [r, n * (m / p)];
214
- const v = (n - i) * (m / p) + c;
215
- return [r, v];
212
+ const { lower: i, upper: a } = e, { lower: c, upper: h } = r, g = a - i, w = h - c;
213
+ if (t === "dimension") return [r, n * (w / g)];
214
+ const O = (n - i) * (w / g) + c;
215
+ return [r, O];
216
216
  }, Et = (r) => (e, t, n) => [r, n], At = () => (r, e, t) => {
217
217
  if (r === null) throw new Error("cannot invert without bounds");
218
218
  if (e === "dimension") return [r, t];
@@ -391,7 +391,7 @@ const De = (r, e) => {
391
391
  );
392
392
  const n = r.valueOf() % t.valueOf();
393
393
  return r instanceof T ? new T(n) : new I(n);
394
- }, y = class l {
394
+ }, p = class l {
395
395
  constructor(e, t = "UTC") {
396
396
  if (u(this, "value"), u(this, "encodeValue", !0), e == null) this.value = l.now().valueOf();
397
397
  else if (e instanceof Date)
@@ -418,8 +418,8 @@ const De = (r, e) => {
418
418
  const [n, i, a] = e.split(":");
419
419
  let c = "00", h = "00";
420
420
  a != null && ([c, h] = a.split("."));
421
- let p = 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)));
422
- return t === "local" && (p = p.add(l.utcOffset)), p.valueOf();
421
+ 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)));
422
+ return t === "local" && (g = g.add(l.utcOffset)), g.valueOf();
423
423
  }
424
424
  static parseDateTimeString(e, t = "UTC") {
425
425
  if (!e.includes("/") && !e.includes("-"))
@@ -669,25 +669,25 @@ const De = (r, e) => {
669
669
  return l.hours(e * 24);
670
670
  }
671
671
  };
672
- u(y, "NANOSECOND", y.nanoseconds(1)), /** One microsecond after the unix epoch */
673
- u(y, "MICROSECOND", y.microseconds(1)), /** One millisecond after the unix epoch */
674
- u(y, "MILLISECOND", y.milliseconds(1)), /** One second after the unix epoch */
675
- u(y, "SECOND", y.seconds(1)), /** One minute after the unix epoch */
676
- u(y, "MINUTE", y.minutes(1)), /** One hour after the unix epoch */
677
- u(y, "HOUR", y.hours(1)), /** One day after the unix epoch */
678
- u(y, "DAY", y.days(1)), /** The maximum possible value for a timestamp */
679
- u(y, "MAX", new y((1n << 63n) - 1n)), /** The minimum possible value for a timestamp */
680
- u(y, "MIN", new y(0)), /** The unix epoch */
681
- u(y, "ZERO", new y(0)), /** A zod schema for validating timestamps */
682
- u(y, "z", s.union([
683
- s.object({ value: s.bigint() }).transform((r) => new y(r.value)),
684
- s.string().transform((r) => new y(BigInt(r))),
685
- s.instanceof(Number).transform((r) => new y(r)),
686
- s.number().transform((r) => new y(r)),
687
- s.instanceof(y)
672
+ u(p, "NANOSECOND", p.nanoseconds(1)), /** One microsecond after the unix epoch */
673
+ u(p, "MICROSECOND", p.microseconds(1)), /** One millisecond after the unix epoch */
674
+ u(p, "MILLISECOND", p.milliseconds(1)), /** One second after the unix epoch */
675
+ u(p, "SECOND", p.seconds(1)), /** One minute after the unix epoch */
676
+ u(p, "MINUTE", p.minutes(1)), /** One hour after the unix epoch */
677
+ u(p, "HOUR", p.hours(1)), /** One day after the unix epoch */
678
+ u(p, "DAY", p.days(1)), /** The maximum possible value for a timestamp */
679
+ u(p, "MAX", new p((1n << 63n) - 1n)), /** The minimum possible value for a timestamp */
680
+ u(p, "MIN", new p(0)), /** The unix epoch */
681
+ u(p, "ZERO", new p(0)), /** A zod schema for validating timestamps */
682
+ u(p, "z", s.union([
683
+ s.object({ value: s.bigint() }).transform((r) => new p(r.value)),
684
+ s.string().transform((r) => new p(BigInt(r))),
685
+ s.instanceof(Number).transform((r) => new p(r)),
686
+ s.number().transform((r) => new p(r)),
687
+ s.instanceof(p)
688
688
  ]));
689
- let T = y;
690
- const g = class d {
689
+ let T = p;
690
+ const y = class d {
691
691
  constructor(e) {
692
692
  u(this, "value"), u(this, "encodeValue", !0), typeof e == "number" && (e = Math.trunc(e.valueOf())), this.value = BigInt(e.valueOf());
693
693
  }
@@ -718,9 +718,9 @@ const g = class d {
718
718
  );
719
719
  }
720
720
  toString() {
721
- 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), p = e, m = t.sub(e), v = n.sub(t), w = i.sub(n), A = a.sub(i), k = c.sub(a), U = h.sub(c);
721
+ 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, w = t.sub(e), O = n.sub(t), m = i.sub(n), A = a.sub(i), k = c.sub(a), U = h.sub(c);
722
722
  let E = "";
723
- return p.isZero || (E += `${p.days}d `), m.isZero || (E += `${m.hours}h `), v.isZero || (E += `${v.minutes}m `), w.isZero || (E += `${w.seconds}s `), A.isZero || (E += `${A.milliseconds}ms `), k.isZero || (E += `${k.microseconds}µs `), U.isZero || (E += `${U.nanoseconds}ns`), E.trim();
723
+ return g.isZero || (E += `${g.days}d `), w.isZero || (E += `${w.hours}h `), O.isZero || (E += `${O.minutes}m `), m.isZero || (E += `${m.seconds}s `), A.isZero || (E += `${A.milliseconds}ms `), k.isZero || (E += `${k.microseconds}µs `), U.isZero || (E += `${U.nanoseconds}ns`), E.trim();
724
724
  }
725
725
  /** @returns the decimal number of days in the timespan */
726
726
  get days() {
@@ -844,24 +844,24 @@ const g = class d {
844
844
  return d.hours(e * 24);
845
845
  }
846
846
  };
847
- u(g, "NANOSECOND", g.nanoseconds(1)), /** A microsecond. */
848
- u(g, "MICROSECOND", g.microseconds(1)), /** A millisecond. */
849
- u(g, "MILLISECOND", g.milliseconds(1)), /** A second. */
850
- u(g, "SECOND", g.seconds(1)), /** A minute. */
851
- u(g, "MINUTE", g.minutes(1)), /** Represents an hour. */
852
- u(g, "HOUR", g.hours(1)), /** Represents a day. */
853
- u(g, "DAY", g.days(1)), /** The maximum possible value for a TimeSpan. */
854
- u(g, "MAX", new g((1n << 63n) - 1n)), /** The minimum possible value for a TimeSpan. */
855
- u(g, "MIN", new g(0)), /** The zero value for a TimeSpan. */
856
- u(g, "ZERO", new g(0)), /** A zod schema for validating and transforming timespans */
857
- u(g, "z", s.union([
858
- s.object({ value: s.bigint() }).transform((r) => new g(r.value)),
859
- s.string().transform((r) => new g(BigInt(r))),
860
- s.instanceof(Number).transform((r) => new g(r)),
861
- s.number().transform((r) => new g(r)),
862
- s.instanceof(g)
847
+ u(y, "NANOSECOND", y.nanoseconds(1)), /** A microsecond. */
848
+ u(y, "MICROSECOND", y.microseconds(1)), /** A millisecond. */
849
+ u(y, "MILLISECOND", y.milliseconds(1)), /** A second. */
850
+ u(y, "SECOND", y.seconds(1)), /** A minute. */
851
+ u(y, "MINUTE", y.minutes(1)), /** Represents an hour. */
852
+ u(y, "HOUR", y.hours(1)), /** Represents a day. */
853
+ u(y, "DAY", y.days(1)), /** The maximum possible value for a TimeSpan. */
854
+ u(y, "MAX", new y((1n << 63n) - 1n)), /** The minimum possible value for a TimeSpan. */
855
+ u(y, "MIN", new y(0)), /** The zero value for a TimeSpan. */
856
+ u(y, "ZERO", new y(0)), /** A zod schema for validating and transforming timespans */
857
+ u(y, "z", s.union([
858
+ s.object({ value: s.bigint() }).transform((r) => new y(r.value)),
859
+ s.string().transform((r) => new y(BigInt(r))),
860
+ s.instanceof(Number).transform((r) => new y(r)),
861
+ s.number().transform((r) => new y(r)),
862
+ s.instanceof(y)
863
863
  ]));
864
- let I = g;
864
+ let I = y;
865
865
  const z = class V extends Number {
866
866
  constructor(e) {
867
867
  e instanceof Number ? super(e.valueOf()) : super(e);
@@ -1222,7 +1222,7 @@ u(o, "z", s.union([
1222
1222
  s.string().transform((r) => new o(r)),
1223
1223
  s.instanceof(o)
1224
1224
  ]));
1225
- const S = class O extends Number {
1225
+ const S = class v extends Number {
1226
1226
  constructor(e) {
1227
1227
  super(e.valueOf());
1228
1228
  }
@@ -1235,33 +1235,33 @@ const S = class O extends Number {
1235
1235
  return this.valueOf() < e.valueOf();
1236
1236
  }
1237
1237
  add(e) {
1238
- return O.bytes(this.valueOf() + e.valueOf());
1238
+ return v.bytes(this.valueOf() + e.valueOf());
1239
1239
  }
1240
1240
  sub(e) {
1241
- return O.bytes(this.valueOf() - e.valueOf());
1241
+ return v.bytes(this.valueOf() - e.valueOf());
1242
1242
  }
1243
1243
  truncate(e) {
1244
- return new O(Math.trunc(this.valueOf() / e.valueOf()) * e.valueOf());
1244
+ return new v(Math.trunc(this.valueOf() / e.valueOf()) * e.valueOf());
1245
1245
  }
1246
1246
  remainder(e) {
1247
- return O.bytes(this.valueOf() % e.valueOf());
1247
+ return v.bytes(this.valueOf() % e.valueOf());
1248
1248
  }
1249
1249
  get gigabytes() {
1250
- return this.valueOf() / O.GIGABYTE.valueOf();
1250
+ return this.valueOf() / v.GIGABYTE.valueOf();
1251
1251
  }
1252
1252
  get megabytes() {
1253
- return this.valueOf() / O.MEGABYTE.valueOf();
1253
+ return this.valueOf() / v.MEGABYTE.valueOf();
1254
1254
  }
1255
1255
  get kilobytes() {
1256
- return this.valueOf() / O.KILOBYTE.valueOf();
1256
+ return this.valueOf() / v.KILOBYTE.valueOf();
1257
1257
  }
1258
1258
  get terabytes() {
1259
- return this.valueOf() / O.TERABYTE.valueOf();
1259
+ return this.valueOf() / v.TERABYTE.valueOf();
1260
1260
  }
1261
1261
  toString() {
1262
- const e = this.truncate(O.TERABYTE), t = this.truncate(O.GIGABYTE), n = this.truncate(O.MEGABYTE), i = this.truncate(O.KILOBYTE), a = this.truncate(O.BYTE), c = e, h = t.sub(e), p = n.sub(t), m = i.sub(n), v = a.sub(i);
1263
- let w = "";
1264
- return c.isZero || (w += `${c.terabytes}TB `), h.isZero || (w += `${h.gigabytes}GB `), p.isZero || (w += `${p.megabytes}MB `), m.isZero || (w += `${m.kilobytes}KB `), (!v.isZero || w === "") && (w += `${v.valueOf()}B`), w.trim();
1262
+ 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), w = i.sub(n), O = a.sub(i);
1263
+ let m = "";
1264
+ return c.isZero || (m += `${c.terabytes}TB `), h.isZero || (m += `${h.gigabytes}GB `), g.isZero || (m += `${g.megabytes}MB `), w.isZero || (m += `${w.kilobytes}KB `), (!O.isZero || m === "") && (m += `${O.valueOf()}B`), m.trim();
1265
1265
  }
1266
1266
  /**
1267
1267
  * Creates a Size from the given number of bytes.
@@ -1270,7 +1270,7 @@ const S = class O extends Number {
1270
1270
  * @returns A Size representing the given number of bytes.
1271
1271
  */
1272
1272
  static bytes(e = 1) {
1273
- return new O(e);
1273
+ return new v(e);
1274
1274
  }
1275
1275
  /**
1276
1276
  * Creates a Size from the given number if kilobytes.
@@ -1279,7 +1279,7 @@ const S = class O extends Number {
1279
1279
  * @returns A Size representing the given number of kilobytes.
1280
1280
  */
1281
1281
  static kilobytes(e = 1) {
1282
- return O.bytes(e.valueOf() * 1e3);
1282
+ return v.bytes(e.valueOf() * 1e3);
1283
1283
  }
1284
1284
  /**
1285
1285
  * Creates a Size from the given number of megabytes.
@@ -1288,7 +1288,7 @@ const S = class O extends Number {
1288
1288
  * @returns A Size representing the given number of megabytes.
1289
1289
  */
1290
1290
  static megabytes(e = 1) {
1291
- return O.kilobytes(e.valueOf() * 1e3);
1291
+ return v.kilobytes(e.valueOf() * 1e3);
1292
1292
  }
1293
1293
  /**
1294
1294
  * Creates a Size from the given number of gigabytes.
@@ -1297,7 +1297,7 @@ const S = class O extends Number {
1297
1297
  * @returns A Size representing the given number of gigabytes.
1298
1298
  */
1299
1299
  static gigabytes(e = 1) {
1300
- return O.megabytes(e.valueOf() * 1e3);
1300
+ return v.megabytes(e.valueOf() * 1e3);
1301
1301
  }
1302
1302
  /**
1303
1303
  * Creates a Size from the given number of terabytes.
@@ -1306,7 +1306,7 @@ const S = class O extends Number {
1306
1306
  * @returns A Size representing the given number of terabytes.
1307
1307
  */
1308
1308
  static terabytes(e) {
1309
- return O.gigabytes(e.valueOf() * 1e3);
1309
+ return v.gigabytes(e.valueOf() * 1e3);
1310
1310
  }
1311
1311
  get isZero() {
1312
1312
  return this.valueOf() === 0;
@@ -1585,38 +1585,38 @@ class yr extends Ge {
1585
1585
  async send(t, n, i, a) {
1586
1586
  n = i == null ? void 0 : i.parse(n);
1587
1587
  let c = null;
1588
- const h = this.endpoint.child(t), p = {};
1589
- p.method = "POST", p.body = this.encoder.encode(n ?? {});
1590
- const [, m] = await this.executeMiddleware(
1588
+ const h = this.endpoint.child(t), g = {};
1589
+ g.method = "POST", g.body = this.encoder.encode(n ?? {});
1590
+ const [, w] = await this.executeMiddleware(
1591
1591
  {
1592
1592
  target: h.toString(),
1593
1593
  protocol: this.endpoint.protocol,
1594
1594
  params: {},
1595
1595
  role: "client"
1596
1596
  },
1597
- async (v) => {
1598
- const w = { ...v, params: {} };
1599
- p.headers = {
1597
+ async (O) => {
1598
+ const m = { ...O, params: {} };
1599
+ g.headers = {
1600
1600
  ...this.headers,
1601
- ...v.params
1601
+ ...O.params
1602
1602
  };
1603
1603
  let A;
1604
1604
  try {
1605
- A = await Se(v.protocol)(v.target, p);
1605
+ A = await Se(O.protocol)(O.target, g);
1606
1606
  } catch (U) {
1607
1607
  let E = U;
1608
- return E.message === "Load failed" && (E = new D({ url: h })), [w, E];
1608
+ return E.message === "Load failed" && (E = new D({ url: h })), [m, E];
1609
1609
  }
1610
1610
  const k = await A.arrayBuffer();
1611
1611
  if (A != null && A.ok)
1612
- return a != null && (c = this.encoder.decode(k, a)), [w, null];
1612
+ return a != null && (c = this.encoder.decode(k, a)), [m, null];
1613
1613
  try {
1614
- if (A.status !== 400) return [w, new Error(A.statusText)];
1614
+ if (A.status !== 400) return [m, new Error(A.statusText)];
1615
1615
  const U = this.encoder.decode(k, We), E = Fe(U);
1616
- return [w, E];
1616
+ return [m, E];
1617
1617
  } catch (U) {
1618
1618
  return [
1619
- w,
1619
+ m,
1620
1620
  new Error(
1621
1621
  `[freighter] - failed to decode error: ${A.statusText}: ${U.message}`
1622
1622
  )
@@ -1624,7 +1624,7 @@ class yr extends Ge {
1624
1624
  }
1625
1625
  }
1626
1626
  );
1627
- return [c, m];
1627
+ return [c, w];
1628
1628
  }
1629
1629
  }
1630
1630
  const gr = async (r, e, t, n, i) => {
@@ -1713,11 +1713,11 @@ const rr = "freighterctx", nr = 1e3, sr = 1001, ir = [nr, sr], or = (r) => ir.in
1713
1713
  let c;
1714
1714
  const [, h] = await this.executeMiddleware(
1715
1715
  { target: t, protocol: "websocket", params: {}, role: "client" },
1716
- async (p) => {
1717
- const m = a(this.buildURL(t, p)), v = { ...p, params: {} };
1718
- m.binaryType = J.MESSAGE_TYPE;
1719
- const w = await this.wrapSocket(m, n, i);
1720
- return w instanceof Error ? [v, w] : (c = w, [v, null]);
1716
+ async (g) => {
1717
+ const w = a(this.buildURL(t, g)), O = { ...g, params: {} };
1718
+ w.binaryType = J.MESSAGE_TYPE;
1719
+ const m = await this.wrapSocket(w, n, i);
1720
+ return m instanceof Error ? [O, m] : (c = m, [O, null]);
1721
1721
  }
1722
1722
  );
1723
1723
  if (h != null) throw h;
package/dist/http.d.ts CHANGED
@@ -13,9 +13,9 @@ export declare const CONTENT_TYPE_HEADER_KEY = "Content-Type";
13
13
  */
14
14
  export declare class HTTPClient extends MiddlewareCollector implements UnaryClient {
15
15
  endpoint: URL;
16
- encoder: binary.EncoderDecoder;
16
+ encoder: binary.Codec;
17
17
  fetch: typeof fetch;
18
- constructor(endpoint: URL, encoder: binary.EncoderDecoder, secure?: boolean);
18
+ constructor(endpoint: URL, encoder: binary.Codec, secure?: boolean);
19
19
  get headers(): Record<string, string>;
20
20
  send<RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>(target: string, req: z.input<RQ> | z.output<RQ>, reqSchema: RQ, resSchema: RS): Promise<[z.output<RS> | null, Error | null]>;
21
21
  }
@@ -1 +1 @@
1
- {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,MAAM,EAAU,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AAC9D,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAAgB,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,uBAAuB,iBAAiB,CAAC;AAYtD;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,mBAAoB,YAAW,WAAW;IACxE,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC;IAC/B,KAAK,EAAE,OAAO,KAAK,CAAC;gBAER,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,GAAE,OAAe;IAclF,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpC;IAEK,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAC9D,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAC/B,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;CAuDhD"}
1
+ {"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAE,KAAK,MAAM,EAAW,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AAC/D,OAAO,EAAE,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC;AAG7B,OAAO,EAAgB,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C,eAAO,MAAM,uBAAuB,iBAAiB,CAAC;AAYtD;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,mBAAoB,YAAW,WAAW;IACxE,QAAQ,EAAE,GAAG,CAAC;IACd,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;IACtB,KAAK,EAAE,OAAO,KAAK,CAAC;gBAER,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,GAAE,OAAe;IAczE,IAAI,OAAO,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAIpC;IAEK,IAAI,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAC9D,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,EAC/B,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,KAAK,GAAG,IAAI,CAAC,CAAC;CAuDhD"}
@@ -10,14 +10,14 @@ export declare const FREIGHTER_METADATA_PREFIX = "freighterctx";
10
10
  */
11
11
  export declare class WebSocketClient extends MiddlewareCollector implements StreamClient {
12
12
  baseUrl: URL;
13
- encoder: binary.EncoderDecoder;
13
+ encoder: binary.Codec;
14
14
  static readonly MESSAGE_TYPE = "arraybuffer";
15
15
  /**
16
16
  * @param encoder - The encoder to use for encoding messages and decoding
17
17
  * responses.
18
18
  * @param baseEndpoint - A base url to use as a prefix for all requests.
19
19
  */
20
- constructor(baseEndpoint: URL, encoder: binary.EncoderDecoder, secure?: boolean);
20
+ constructor(baseEndpoint: URL, encoder: binary.Codec, secure?: boolean);
21
21
  /** Implements the StreamClient interface. */
22
22
  stream<RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>(target: string, reqSchema: RQ, resSchema: RS): Promise<Stream<RQ, RS>>;
23
23
  private buildURL;
@@ -1 +1 @@
1
- {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,MAAM,EAA6B,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAgB,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAgHrD,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAQxD;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,mBAAoB,YAAW,YAAY;IAC9E,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,cAAc,CAAC;IAE/B,MAAM,CAAC,QAAQ,CAAC,YAAY,iBAAiB;IAE7C;;;;OAIG;gBACS,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,cAAc,EAAE,MAAM,UAAQ;IAM7E,6CAA6C;IACvC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAChE,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAmB1B,OAAO,CAAC,QAAQ;YAWF,UAAU;CAezB"}
1
+ {"version":3,"file":"websocket.d.ts","sourceRoot":"","sources":["../src/websocket.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,MAAM,EAA6B,KAAK,GAAG,EAAE,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EAAgB,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,KAAK,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AA2GrD,eAAO,MAAM,yBAAyB,iBAAiB,CAAC;AAQxD;;;GAGG;AACH,qBAAa,eAAgB,SAAQ,mBAAoB,YAAW,YAAY;IAC9E,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,MAAM,CAAC,KAAK,CAAC;IAEtB,MAAM,CAAC,QAAQ,CAAC,YAAY,iBAAiB;IAE7C;;;;OAIG;gBACS,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,UAAQ;IAMpE,6CAA6C;IACvC,MAAM,CAAC,EAAE,SAAS,CAAC,CAAC,UAAU,EAAE,EAAE,SAAS,CAAC,CAAC,UAAU,GAAG,EAAE,EAChE,MAAM,EAAE,MAAM,EACd,SAAS,EAAE,EAAE,EACb,SAAS,EAAE,EAAE,GACZ,OAAO,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAmB1B,OAAO,CAAC,QAAQ;YAWF,UAAU;CAezB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@synnaxlabs/freighter",
3
- "version": "0.25.0",
3
+ "version": "0.26.7",
4
4
  "type": "module",
5
5
  "description": "a modular transport abstraction",
6
6
  "repository": "https://github.com/synnaxlabs/synnax/tree/main/freighter/ts",
@@ -17,8 +17,8 @@
17
17
  "node-fetch": "2.6.11",
18
18
  "ws": "^8.17.0",
19
19
  "zod": "3.23.8",
20
- "@synnaxlabs/alamos": "0.25.0",
21
- "@synnaxlabs/x": "0.25.0"
20
+ "@synnaxlabs/alamos": "0.26.7",
21
+ "@synnaxlabs/x": "0.26.7"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@types/node": "^20.12.7",
@@ -26,9 +26,9 @@
26
26
  "typescript": "^5.4.5",
27
27
  "vite": "5.2.11",
28
28
  "vitest": "^1.5.0",
29
- "@synnaxlabs/vite-plugin": "0.0.1",
30
29
  "@synnaxlabs/tsconfig": "0.0.2",
31
- "eslint-config-synnaxlabs": "0.0.1"
30
+ "eslint-config-synnaxlabs": "0.0.1",
31
+ "@synnaxlabs/vite-plugin": "0.0.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "zod": "^3.23.8"
package/src/http.spec.ts CHANGED
@@ -7,7 +7,7 @@
7
7
  // License, use of this software will be governed by the Apache License, Version 2.0,
8
8
  // included in the file licenses/APL.txt.
9
9
 
10
- import { binary,URL } from "@synnaxlabs/x";
10
+ import { binary, URL } from "@synnaxlabs/x";
11
11
  import { describe, expect, test } from "vitest";
12
12
  import { z } from "zod";
13
13
 
@@ -20,7 +20,7 @@ const ENDPOINT = new URL({
20
20
  pathPrefix: "unary",
21
21
  });
22
22
 
23
- const client = new HTTPClient(ENDPOINT, new binary.JSONEncoderDecoder());
23
+ const client = new HTTPClient(ENDPOINT, new binary.JSONCodec());
24
24
 
25
25
  const messageZ = z.object({
26
26
  id: z.number().optional(),
package/src/http.ts CHANGED
@@ -17,7 +17,7 @@
17
17
  // License, use of this software will be governed by the Apache License, Version 2.0,
18
18
  // included in the file licenses/APL.txt.
19
19
 
20
- import { type binary,runtime, type URL } from "@synnaxlabs/x";
20
+ import { type binary, runtime, type URL } from "@synnaxlabs/x";
21
21
  import { type z } from "zod";
22
22
 
23
23
  import { decodeError, errorZ, Unreachable } from "@/errors";
@@ -45,10 +45,10 @@ const resolveFetchAPI = (protocol: "http" | "https"): typeof fetch => {
45
45
  */
46
46
  export class HTTPClient extends MiddlewareCollector implements UnaryClient {
47
47
  endpoint: URL;
48
- encoder: binary.EncoderDecoder;
48
+ encoder: binary.Codec;
49
49
  fetch: typeof fetch;
50
50
 
51
- constructor(endpoint: URL, encoder: binary.EncoderDecoder, secure: boolean = false) {
51
+ constructor(endpoint: URL, encoder: binary.Codec, secure: boolean = false) {
52
52
  super();
53
53
  this.endpoint = endpoint.replace({ protocol: secure ? "https" : "http" });
54
54
  this.encoder = encoder;
@@ -74,7 +74,7 @@ export class HTTPClient extends MiddlewareCollector implements UnaryClient {
74
74
  reqSchema: RQ,
75
75
  resSchema: RS,
76
76
  ): Promise<[z.output<RS> | null, Error | null]> {
77
- req = reqSchema?.parse(req)
77
+ req = reqSchema?.parse(req);
78
78
  let res: RS | null = null;
79
79
  const url = this.endpoint.child(target);
80
80
  const request: RequestInit = {};
@@ -31,7 +31,7 @@ const MessageSchema = z.object({
31
31
  message: z.string().optional(),
32
32
  });
33
33
 
34
- const client = new WebSocketClient(url, new binary.JSONEncoderDecoder());
34
+ const client = new WebSocketClient(url, new binary.JSONCodec());
35
35
 
36
36
  class MyCustomError extends BaseTypedError {
37
37
  code: number;
@@ -105,7 +105,7 @@ describe("websocket", () => {
105
105
  });
106
106
 
107
107
  test("middleware", async () => {
108
- const myClient = new WebSocketClient(url, new binary.JSONEncoderDecoder());
108
+ const myClient = new WebSocketClient(url, new binary.JSONCodec());
109
109
  let c = 0;
110
110
  myClient.use(async (md, next): Promise<[Context, Error | null]> => {
111
111
  if (md.params !== undefined) {
package/src/websocket.ts CHANGED
@@ -38,7 +38,7 @@ type ReceiveCallbacksQueue = Array<{
38
38
  class WebSocketStream<RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>
39
39
  implements Stream<RQ, RS>
40
40
  {
41
- private readonly encoder: binary.EncoderDecoder;
41
+ private readonly encoder: binary.Codec;
42
42
  private readonly reqSchema: RQ;
43
43
  private readonly resSchema: RS;
44
44
  private readonly ws: WebSocket;
@@ -47,12 +47,7 @@ class WebSocketStream<RQ extends z.ZodTypeAny, RS extends z.ZodTypeAny = RQ>
47
47
  private readonly receiveDataQueue: Message[] = [];
48
48
  private readonly receiveCallbacksQueue: ReceiveCallbacksQueue = [];
49
49
 
50
- constructor(
51
- ws: WebSocket,
52
- encoder: binary.EncoderDecoder,
53
- reqSchema: RQ,
54
- resSchema: RS,
55
- ) {
50
+ constructor(ws: WebSocket, encoder: binary.Codec, reqSchema: RQ, resSchema: RS) {
56
51
  this.encoder = encoder;
57
52
  this.reqSchema = reqSchema;
58
53
  this.resSchema = resSchema;
@@ -139,7 +134,7 @@ const isNormalClosure = (ev: CloseEvent): boolean => NORMAL_CLOSURES.includes(ev
139
134
  */
140
135
  export class WebSocketClient extends MiddlewareCollector implements StreamClient {
141
136
  baseUrl: URL;
142
- encoder: binary.EncoderDecoder;
137
+ encoder: binary.Codec;
143
138
 
144
139
  static readonly MESSAGE_TYPE = "arraybuffer";
145
140
 
@@ -148,7 +143,7 @@ export class WebSocketClient extends MiddlewareCollector implements StreamClient
148
143
  * responses.
149
144
  * @param baseEndpoint - A base url to use as a prefix for all requests.
150
145
  */
151
- constructor(baseEndpoint: URL, encoder: binary.EncoderDecoder, secure = false) {
146
+ constructor(baseEndpoint: URL, encoder: binary.Codec, secure = false) {
152
147
  super();
153
148
  this.baseUrl = baseEndpoint.replace({ protocol: secure ? "wss" : "ws" });
154
149
  this.encoder = encoder;