Comparing version 1.0.0 to 1.1.0
import { Encoder, Decoder, Codec } from "../types"; | ||
export declare const Bytes: { | ||
(nBytes: number): Codec<Uint8Array>; | ||
enc: (nBytes: number) => Encoder<Uint8Array>; | ||
dec: (nBytes: number) => Decoder<Uint8Array>; | ||
(nBytes?: number | undefined): Codec<Uint8Array>; | ||
enc: (nBytes?: number | undefined) => Encoder<Uint8Array>; | ||
dec: (nBytes?: number | undefined) => Decoder<Uint8Array>; | ||
}; |
@@ -306,5 +306,5 @@ var __defProp = Object.defineProperty; | ||
// src/codecs/Bytes.ts | ||
var BytesEnc = (nBytes) => (bytes) => bytes.length === nBytes ? bytes : bytes.slice(0, nBytes); | ||
var BytesEnc = (nBytes) => nBytes === void 0 ? (bytes) => mergeUint8(compact.enc(bytes.length), bytes) : (bytes) => bytes.length === nBytes ? bytes : bytes.slice(0, nBytes); | ||
var BytesDec = (nBytes) => toInternalBytes((bytes) => { | ||
const len = nBytes !== Infinity ? nBytes : bytes.byteLength - bytes.i; | ||
const len = nBytes === void 0 ? compact.dec(bytes) : nBytes !== Infinity ? nBytes : bytes.byteLength - bytes.i; | ||
const result = new Uint8Array(bytes.buffer.slice(bytes.i, bytes.i + len)); | ||
@@ -311,0 +311,0 @@ bytes.i += len; |
@@ -1,2 +0,2 @@ | ||
var E=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var oe=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},ce=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of te(e))!ne.call(t,o)&&o!==n&&E(t,o,{get:()=>e[o],enumerable:!(r=ee(e,o))||r.enumerable});return t};var ie=t=>ce(E({},"__esModule",{value:!0}),t);var v=(t,e,n)=>(re(t,typeof e!="symbol"?e+"":e,n),n);var he={};oe(he,{Bytes:()=>C,Enum:()=>b,Option:()=>B,Result:()=>U,Struct:()=>w,Tuple:()=>g,Vector:()=>k,_void:()=>L,bool:()=>l,compact:()=>f,createCodec:()=>c,enhanceCodec:()=>R,enhanceDecoder:()=>T,enhanceEncoder:()=>I,i128:()=>ye,i16:()=>ue,i256:()=>De,i32:()=>fe,i64:()=>pe,i8:()=>me,str:()=>S,u128:()=>ge,u16:()=>O,u256:()=>Oe,u32:()=>D,u64:()=>K,u8:()=>a});module.exports=ie(he);var c=(t,e)=>{let n=[t,e];return n.enc=t,n.dec=e,n},I=(t,e)=>n=>t(e(n)),T=(t,e)=>n=>e(t(n)),R=([t,e],n,r)=>c(I(t,n),T(e,r));var V={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function de(t){let e=t.length%2,n=(t[1]==="x"?2:0)+e,r=(t.length-n)/2+e,o=new Uint8Array(r);e&&(o[0]=0|V[t[2]]);for(let i=0;i<r;){let s=n+i*2,p=V[t[s]],x=V[t[s+1]];o[e+i++]=p<<4|x}return o}var A=class extends Uint8Array{constructor(n){super(n);v(this,"i",0);v(this,"v");this.v=new DataView(n)}},d=t=>e=>t(e instanceof A?e:new A(e instanceof Uint8Array?e.buffer:typeof e=="string"?de(e).buffer:e));var m=(...t)=>{let e=t.length,n=0;for(let o=0;o<e;o++)n+=t[o].byteLength;let r=new Uint8Array(n);for(let o=0,i=0;o<e;o++){let s=t[o];r.set(s,i),i+=s.byteLength}return r};function y(t,e){let n=Object.keys(t),r=n.length,o={};for(let i=0;i<r;i++){let s=n[i];o[s]=e(t[s],s)}return o}function se(t,e){return d(n=>{let r=n.v[e](n.i,!0);return n.i+=t,r})}function ae(t,e){return n=>{let r=new Uint8Array(t);return new DataView(r.buffer)[e](0,n,!0),r}}function u(t,e,n){return c(ae(t,n),se(t,e))}var a=u(1,"getUint8","setUint8"),O=u(2,"getUint16","setUint16"),D=u(4,"getUint32","setUint32"),K=u(8,"getBigUint64","setBigUint64"),me=u(1,"getInt8","setInt8"),ue=u(2,"getInt16","setInt16"),fe=u(4,"getInt32","setInt32"),pe=u(8,"getBigInt64","setBigInt64"),h=t=>{let e=new Uint8Array(16),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),e},_=t=>d(e=>{let{v:n,i:r}=e,o=n.getBigUint64(r,!0),i=n[t](r+8,!0);return e.i+=16,i<<64n|o}),ge=c(h,_("getBigUint64")),ye=c(h,_("getBigInt64")),j=t=>{let e=new Uint8Array(32),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),n.setBigInt64(16,t>>128n,!0),n.setBigInt64(24,t>>192n,!0),e},M=t=>d(e=>{let n=e.v.getBigUint64(e.i,!0);return e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<64n,e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<128n,e.i+=8,n|=e.v[t](e.i,!0)<<192n,e.i+=8,n}),Oe=c(j,M("getBigUint64")),De=c(j,M("getBigInt64"));var l=R(a,t=>t?1:0,Boolean);var le=[a[1],O[1],D[1]],xe=d(t=>{let e=t[t.i],n=e&3;if(n<3)return le[n](t)>>>2;let r=(e>>>2)+4;t.i++;let o=0n,i=r/8|0,s=0n;for(let x=0;x<i;x++)o=K[1](t)<<s|o,s+=64n;let p=r%8;return p>3&&(o=BigInt(D[1](t))<<s|o,s+=32n,p-=4),p>1&&(o=BigInt(O[1](t))<<s|o,s+=16n,p-=2),p&&(o=BigInt(a[1](t))<<s|o),o}),Ee=1n<<56n,Ie=1<<24,Te=256,Ae=4294967295n,Ke=1<<6,Ce=1<<14,be=1<<30,Be=t=>{if(t<0)throw new Error(`Wrong compact input (${t})`);let e=Number(t)<<2;if(t<Ke)return a[0](e);if(t<Ce)return O[0](e|1);if(t<be)return D[0](e|2);let n=[new Uint8Array(1)],r=BigInt(t);for(;r>=Ee;)n.push(K[0](r)),r>>=64n;r>=Ie&&(n.push(D[0](Number(r&Ae))),r>>=32n);let o=Number(r);o>=Te&&(n.push(O[0](o)),o>>=16),o&&n.push(a[0](o));let i=m(...n);return i[0]=i.length-5<<2|3,i},f=c(Be,xe);var Ue=new TextEncoder,we=t=>{let e=Ue.encode(t);return m(f.enc(e.length),e)},ke=new TextDecoder,ve=d(t=>{let e=f.dec(t),n=new DataView(t.buffer,t.i,e);return t.i+=e,ke.decode(n)}),S=c(we,ve);var Re=()=>{},Ve=new Uint8Array(0),L=c(()=>Ve,Re);var N=t=>e=>e.length===t?e:e.slice(0,t),P=t=>d(e=>{let n=t!==1/0?t:e.byteLength-e.i,r=new Uint8Array(e.buffer.slice(e.i,e.i+n));return e.i+=n,r}),C=t=>c(N(t),P(t));C.enc=N;C.dec=P;var Y=t=>{let e=Object.keys(t);return({tag:n,value:r})=>m(a.enc(e.indexOf(n)),t[n](r))},F=t=>{let e=Object.entries(t);return d(n=>{let r=a.dec(n),[o,i]=e[r];return{tag:o,value:i(n)}})},b=t=>c(Y(y(t,([e])=>e)),F(y(t,([,e])=>e)));b.enc=Y;b.dec=F;var H=t=>d(e=>{let n=a.dec(e);if(n!==0)return t===l[1]?n===1:t(e)}),W=t=>e=>{let n=new Uint8Array(1);return e===void 0?(n[0]=0,n):(n[0]=1,t===l[0]?(n[0]=e?1:2,n):m(n,t(e)))},B=t=>c(W(t[0]),H(t[1]));B.enc=W;B.dec=H;var G=(t,e)=>d(n=>{let r=a[1](n)===0,i=(r?t:e)(n);return{success:r,value:i}}),X=(t,e)=>({success:n,value:r})=>m(a[0](n?0:1),(n?t:e)(r)),U=(t,e)=>c(X(t[0],e[0]),G(t[1],e[1]));U.dec=G;U.enc=X;var $=(...t)=>d(e=>t.map(n=>n(e))),q=(...t)=>e=>m(...e.map((n,r)=>t[r](n))),g=(...t)=>c(q(...t.map(([e])=>e)),$(...t.map(([,e])=>e)));g.enc=q;g.dec=$;var J=t=>{let e=Object.keys(t);return I(g.enc(...Object.values(t)),n=>e.map(r=>n[r]))},Q=t=>{let e=Object.keys(t);return T(g.dec(...Object.values(t)),n=>Object.fromEntries(n.map((r,o)=>[e[o],r])))},w=t=>c(J(y(t,e=>e[0])),Q(y(t,e=>e[1])));w.enc=J;w.dec=Q;var Z=(t,e)=>e>=0?n=>m(...n.map(t)):n=>m(f.enc(n.length),...n.map(t)),z=(t,e)=>d(n=>{let r=e>=0?e:f.dec(n),o=new Array(r);for(let i=0;i<r;i++)o[i]=t(n);return o}),k=(t,e)=>c(Z(t[0],e),z(t[1],e));k.enc=Z;k.dec=z; | ||
var E=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var ne=Object.prototype.hasOwnProperty;var re=(t,e,n)=>e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var oe=(t,e)=>{for(var n in e)E(t,n,{get:e[n],enumerable:!0})},ce=(t,e,n,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of te(e))!ne.call(t,o)&&o!==n&&E(t,o,{get:()=>e[o],enumerable:!(r=ee(e,o))||r.enumerable});return t};var ie=t=>ce(E({},"__esModule",{value:!0}),t);var v=(t,e,n)=>(re(t,typeof e!="symbol"?e+"":e,n),n);var he={};oe(he,{Bytes:()=>C,Enum:()=>b,Option:()=>U,Result:()=>w,Struct:()=>B,Tuple:()=>g,Vector:()=>k,_void:()=>L,bool:()=>D,compact:()=>u,createCodec:()=>c,enhanceCodec:()=>R,enhanceDecoder:()=>T,enhanceEncoder:()=>I,i128:()=>Oe,i16:()=>ue,i256:()=>ye,i32:()=>fe,i64:()=>pe,i8:()=>me,str:()=>S,u128:()=>ge,u16:()=>l,u256:()=>le,u32:()=>y,u64:()=>K,u8:()=>m});module.exports=ie(he);var c=(t,e)=>{let n=[t,e];return n.enc=t,n.dec=e,n},I=(t,e)=>n=>t(e(n)),T=(t,e)=>n=>e(t(n)),R=([t,e],n,r)=>c(I(t,n),T(e,r));var V={0:0,1:1,2:2,3:3,4:4,5:5,6:6,7:7,8:8,9:9,a:10,b:11,c:12,d:13,e:14,f:15,A:10,B:11,C:12,D:13,E:14,F:15};function de(t){let e=t.length%2,n=(t[1]==="x"?2:0)+e,r=(t.length-n)/2+e,o=new Uint8Array(r);e&&(o[0]=0|V[t[2]]);for(let i=0;i<r;){let s=n+i*2,p=V[t[s]],x=V[t[s+1]];o[e+i++]=p<<4|x}return o}var A=class extends Uint8Array{constructor(n){super(n);v(this,"i",0);v(this,"v");this.v=new DataView(n)}},d=t=>e=>t(e instanceof A?e:new A(e instanceof Uint8Array?e.buffer:typeof e=="string"?de(e).buffer:e));var a=(...t)=>{let e=t.length,n=0;for(let o=0;o<e;o++)n+=t[o].byteLength;let r=new Uint8Array(n);for(let o=0,i=0;o<e;o++){let s=t[o];r.set(s,i),i+=s.byteLength}return r};function O(t,e){let n=Object.keys(t),r=n.length,o={};for(let i=0;i<r;i++){let s=n[i];o[s]=e(t[s],s)}return o}function se(t,e){return d(n=>{let r=n.v[e](n.i,!0);return n.i+=t,r})}function ae(t,e){return n=>{let r=new Uint8Array(t);return new DataView(r.buffer)[e](0,n,!0),r}}function f(t,e,n){return c(ae(t,n),se(t,e))}var m=f(1,"getUint8","setUint8"),l=f(2,"getUint16","setUint16"),y=f(4,"getUint32","setUint32"),K=f(8,"getBigUint64","setBigUint64"),me=f(1,"getInt8","setInt8"),ue=f(2,"getInt16","setInt16"),fe=f(4,"getInt32","setInt32"),pe=f(8,"getBigInt64","setBigInt64"),h=t=>{let e=new Uint8Array(16),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),e},_=t=>d(e=>{let{v:n,i:r}=e,o=n.getBigUint64(r,!0),i=n[t](r+8,!0);return e.i+=16,i<<64n|o}),ge=c(h,_("getBigUint64")),Oe=c(h,_("getBigInt64")),j=t=>{let e=new Uint8Array(32),n=new DataView(e.buffer);return n.setBigInt64(0,t,!0),n.setBigInt64(8,t>>64n,!0),n.setBigInt64(16,t>>128n,!0),n.setBigInt64(24,t>>192n,!0),e},M=t=>d(e=>{let n=e.v.getBigUint64(e.i,!0);return e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<64n,e.i+=8,n|=e.v.getBigUint64(e.i,!0)<<128n,e.i+=8,n|=e.v[t](e.i,!0)<<192n,e.i+=8,n}),le=c(j,M("getBigUint64")),ye=c(j,M("getBigInt64"));var D=R(m,t=>t?1:0,Boolean);var De=[m[1],l[1],y[1]],xe=d(t=>{let e=t[t.i],n=e&3;if(n<3)return De[n](t)>>>2;let r=(e>>>2)+4;t.i++;let o=0n,i=r/8|0,s=0n;for(let x=0;x<i;x++)o=K[1](t)<<s|o,s+=64n;let p=r%8;return p>3&&(o=BigInt(y[1](t))<<s|o,s+=32n,p-=4),p>1&&(o=BigInt(l[1](t))<<s|o,s+=16n,p-=2),p&&(o=BigInt(m[1](t))<<s|o),o}),Ee=1n<<56n,Ie=1<<24,Te=256,Ae=4294967295n,Ke=1<<6,Ce=1<<14,be=1<<30,Ue=t=>{if(t<0)throw new Error(`Wrong compact input (${t})`);let e=Number(t)<<2;if(t<Ke)return m[0](e);if(t<Ce)return l[0](e|1);if(t<be)return y[0](e|2);let n=[new Uint8Array(1)],r=BigInt(t);for(;r>=Ee;)n.push(K[0](r)),r>>=64n;r>=Ie&&(n.push(y[0](Number(r&Ae))),r>>=32n);let o=Number(r);o>=Te&&(n.push(l[0](o)),o>>=16),o&&n.push(m[0](o));let i=a(...n);return i[0]=i.length-5<<2|3,i},u=c(Ue,xe);var we=new TextEncoder,Be=t=>{let e=we.encode(t);return a(u.enc(e.length),e)},ke=new TextDecoder,ve=d(t=>{let e=u.dec(t),n=new DataView(t.buffer,t.i,e);return t.i+=e,ke.decode(n)}),S=c(Be,ve);var Re=()=>{},Ve=new Uint8Array(0),L=c(()=>Ve,Re);var N=t=>t===void 0?e=>a(u.enc(e.length),e):e=>e.length===t?e:e.slice(0,t),P=t=>d(e=>{let n=t===void 0?u.dec(e):t!==1/0?t:e.byteLength-e.i,r=new Uint8Array(e.buffer.slice(e.i,e.i+n));return e.i+=n,r}),C=t=>c(N(t),P(t));C.enc=N;C.dec=P;var Y=t=>{let e=Object.keys(t);return({tag:n,value:r})=>a(m.enc(e.indexOf(n)),t[n](r))},F=t=>{let e=Object.entries(t);return d(n=>{let r=m.dec(n),[o,i]=e[r];return{tag:o,value:i(n)}})},b=t=>c(Y(O(t,([e])=>e)),F(O(t,([,e])=>e)));b.enc=Y;b.dec=F;var H=t=>d(e=>{let n=m.dec(e);if(n!==0)return t===D[1]?n===1:t(e)}),W=t=>e=>{let n=new Uint8Array(1);return e===void 0?(n[0]=0,n):(n[0]=1,t===D[0]?(n[0]=e?1:2,n):a(n,t(e)))},U=t=>c(W(t[0]),H(t[1]));U.enc=W;U.dec=H;var G=(t,e)=>d(n=>{let r=m[1](n)===0,i=(r?t:e)(n);return{success:r,value:i}}),X=(t,e)=>({success:n,value:r})=>a(m[0](n?0:1),(n?t:e)(r)),w=(t,e)=>c(X(t[0],e[0]),G(t[1],e[1]));w.dec=G;w.enc=X;var $=(...t)=>d(e=>t.map(n=>n(e))),q=(...t)=>e=>a(...e.map((n,r)=>t[r](n))),g=(...t)=>c(q(...t.map(([e])=>e)),$(...t.map(([,e])=>e)));g.enc=q;g.dec=$;var J=t=>{let e=Object.keys(t);return I(g.enc(...Object.values(t)),n=>e.map(r=>n[r]))},Q=t=>{let e=Object.keys(t);return T(g.dec(...Object.values(t)),n=>Object.fromEntries(n.map((r,o)=>[e[o],r])))},B=t=>c(J(O(t,e=>e[0])),Q(O(t,e=>e[1])));B.enc=J;B.dec=Q;var Z=(t,e)=>e>=0?n=>a(...n.map(t)):n=>a(u.enc(n.length),...n.map(t)),z=(t,e)=>d(n=>{let r=e>=0?e:u.dec(n),o=new Array(r);for(let i=0;i<r;i++)o[i]=t(n);return o}),k=(t,e)=>c(Z(t[0],e),z(t[1],e));k.enc=Z;k.dec=z; | ||
//# sourceMappingURL=scale-ts.cjs.production.min.js.map |
@@ -257,5 +257,5 @@ var __defProp = Object.defineProperty; | ||
// src/codecs/Bytes.ts | ||
var BytesEnc = (nBytes) => (bytes) => bytes.length === nBytes ? bytes : bytes.slice(0, nBytes); | ||
var BytesEnc = (nBytes) => nBytes === void 0 ? (bytes) => mergeUint8(compact.enc(bytes.length), bytes) : (bytes) => bytes.length === nBytes ? bytes : bytes.slice(0, nBytes); | ||
var BytesDec = (nBytes) => toInternalBytes((bytes) => { | ||
const len = nBytes !== Infinity ? nBytes : bytes.byteLength - bytes.i; | ||
const len = nBytes === void 0 ? compact.dec(bytes) : nBytes !== Infinity ? nBytes : bytes.byteLength - bytes.i; | ||
const result = new Uint8Array(bytes.buffer.slice(bytes.i, bytes.i + len)); | ||
@@ -262,0 +262,0 @@ bytes.i += len; |
{ | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"repository": { | ||
@@ -4,0 +4,0 @@ "type": "git", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
176312