@solana/codecs-data-structures
Advanced tools
Comparing version 2.0.0-experimental.cd89114 to 2.0.0-experimental.ce145c8
@@ -358,3 +358,3 @@ import { mergeBytes, combineCodec, assertByteArrayHasEnoughBytesForCodec, assertFixedSizeCodec, assertByteArrayIsNotEmptyForCodec, fixEncoder, fixDecoder, fixBytes } from '@solana/codecs-core'; | ||
function nullableCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${getArrayLikeCodecSizeDescription(prefix)}`; | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
@@ -392,3 +392,3 @@ if (fixed) { | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.slice(offset).length === 0) { | ||
if (bytes.length - offset <= 0) { | ||
return [null, offset]; | ||
@@ -621,3 +621,1 @@ } | ||
export { assertValidNumberOfItemsForCodec, decodeArrayLikeCodecSize, getArrayCodec, getArrayDecoder, getArrayEncoder, getArrayLikeCodecSizeDescription, getArrayLikeCodecSizeFromChildren, getArrayLikeCodecSizePrefix, getBitArrayCodec, getBitArrayDecoder, getBitArrayEncoder, getBooleanCodec, getBooleanDecoder, getBooleanEncoder, getBytesCodec, getBytesDecoder, getBytesEncoder, getDataEnumCodec, getDataEnumDecoder, getDataEnumEncoder, getMapCodec, getMapDecoder, getMapEncoder, getNullableCodec, getNullableDecoder, getNullableEncoder, getScalarEnumCodec, getScalarEnumDecoder, getScalarEnumEncoder, getSetCodec, getSetDecoder, getSetEncoder, getStructCodec, getStructDecoder, getStructEncoder, getTupleCodec, getTupleDecoder, getTupleEncoder, getUnitCodec, getUnitDecoder, getUnitEncoder }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -549,3 +549,3 @@ this.globalThis = this.globalThis || {}; | ||
function nullableCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${getArrayLikeCodecSizeDescription(prefix)}`; | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
@@ -583,3 +583,3 @@ if (fixed) { | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.slice(offset).length === 0) { | ||
if (bytes.length - offset <= 0) { | ||
return [null, offset]; | ||
@@ -586,0 +586,0 @@ } |
@@ -358,3 +358,3 @@ import { mergeBytes, combineCodec, assertByteArrayHasEnoughBytesForCodec, assertFixedSizeCodec, assertByteArrayIsNotEmptyForCodec, fixEncoder, fixDecoder, fixBytes } from '@solana/codecs-core'; | ||
function nullableCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${getArrayLikeCodecSizeDescription(prefix)}`; | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
@@ -392,3 +392,3 @@ if (fixed) { | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.slice(offset).length === 0) { | ||
if (bytes.length - offset <= 0) { | ||
return [null, offset]; | ||
@@ -395,0 +395,0 @@ } |
@@ -358,3 +358,3 @@ import { mergeBytes, combineCodec, assertByteArrayHasEnoughBytesForCodec, assertFixedSizeCodec, assertByteArrayIsNotEmptyForCodec, fixEncoder, fixDecoder, fixBytes } from '@solana/codecs-core'; | ||
function nullableCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${getArrayLikeCodecSizeDescription(prefix)}`; | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
@@ -392,3 +392,3 @@ if (fixed) { | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.slice(offset).length === 0) { | ||
if (bytes.length - offset <= 0) { | ||
return [null, offset]; | ||
@@ -395,0 +395,0 @@ } |
@@ -5,12 +5,12 @@ this.globalThis = this.globalThis || {}; | ||
function C(e,r,n=0){if(r.length-n<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function D(e,r,n,o=0){let t=n.length-o;if(t<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${t}.`)}function O(e,r){if(e.fixedSize===null)throw new Error(r??"Expected a fixed-size codec, got a variable-size one.")}var x=e=>{let r=e.filter(i=>i.length);if(r.length===0)return e.length?e[0]:new Uint8Array;if(r.length===1)return r[0];let n=r.reduce((i,c)=>i+c.length,0),o=new Uint8Array(n),t=0;return r.forEach(i=>{o.set(i,t),t+=i.length;}),o},G=(e,r)=>{if(e.length>=r)return e;let n=new Uint8Array(r).fill(0);return n.set(e),n},v=(e,r)=>G(e.length<=r?e:e.slice(0,r),r);function u(e,r,n){if(e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);if(n===void 0&&e.description!==r.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${r.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:r.decode,description:n??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function w(e,r,n){return {description:n??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function k(e,r,n){return {...w(e,r,n),encode:o=>v(e.encode(o),r)}}function I(e,r,n){return {...w(e,r,n),decode:(o,t=0)=>{D("fixCodec",r,o,t),(t>0||o.length>r)&&(o=o.slice(t,t+r)),e.fixedSize!==null&&(o=v(o,e.fixedSize));let[i]=e.decode(o,0);return [i,t+r]}}}function q(e,r,n,o){if(o<r||o>n)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${n}], got ${o}.`)}function $(e){let r,n=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===0,n+=r?"(le)":"(be)"),{description:e.options.description??n,fixedSize:e.size,littleEndian:r,maxSize:e.size}}function _(e){let r=$(e);return {description:r.description,encode(n){e.range&&q(e.name,e.range[0],e.range[1],n);let o=new ArrayBuffer(e.size);return e.set(new DataView(o),n,r.littleEndian),new Uint8Array(o)},fixedSize:r.fixedSize,maxSize:r.maxSize}}function F(e){let r=$(e);return {decode(n,o=0){C(r.description,n,o),D(r.description,e.size,n,o);let t=new DataView(J(n,o,e.size));return [e.get(t,r.littleEndian),o+e.size]},description:r.description,fixedSize:r.fixedSize,maxSize:r.maxSize}}function J(e,r,n){let o=e.byteOffset+(r??0),t=n??e.byteLength;return e.buffer.slice(o,o+t)}var N=(e={})=>_({name:"u32",options:e,range:[0,+"0xffffffff"],set:(r,n,o)=>r.setUint32(0,n,o),size:4}),U=(e={})=>F({get:(r,n)=>r.getUint32(0,n),name:"u32",options:e,size:4});var S=(e={})=>_({name:"u8",options:e,range:[0,+"0xff"],set:(r,n)=>r.setUint8(0,n),size:1}),b=(e={})=>F({get:r=>r.getUint8(0),name:"u8",options:e,size:1});function L(e){return e.reduce((r,n)=>r===null||n===null?null:Math.max(r,n),0)}function l(e){return e.reduce((r,n)=>r===null||n===null?null:r+n,0)}function h(e,r,n,o){if(typeof e=="number")return [e,o];if(typeof e=="object")return e.decode(n,o);if(e==="remainder"){let t=l(r);if(t===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');let i=n.slice(o).length;if(i%t!==0)throw new Error(`The remainder of the byte array (${i} bytes) cannot be split into chunks of ${t} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${i} modulo ${t} should be equal to zero.`);return [i/t,o]}throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(e)}`)}function y(e){return typeof e=="object"?e.description:`${e}`}function g(e,r){if(typeof e!="number")return null;if(e===0)return 0;let n=l(r);return n===null?null:n*e}function A(e,r){return typeof e=="object"?e.encode(r):new Uint8Array}function T(e,r,n){if(r!==n)throw new Error(`Expected [${e}] to have ${r} items, got ${n}.`)}function V(e,r,n){if(r==="remainder"&&e.fixedSize===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:n??`array(${e.description}; ${y(r)})`,fixedSize:g(r,[e.fixedSize]),maxSize:g(r,[e.maxSize])}}function Q(e,r={}){let n=r.size??N();return {...V(e,n,r.description),encode:o=>(typeof n=="number"&&T("array",n,o.length),x([A(n,o.length),...o.map(t=>e.encode(t))]))}}function X(e,r={}){let n=r.size??U();return {...V(e,n,r.description),decode:(o,t=0)=>{if(typeof n=="object"&&o.slice(t).length===0)return [[],t];let[i,c]=h(n,[e.fixedSize],o,t);t=c;let d=[];for(let a=0;a<i;a+=1){let[s,f]=e.decode(o,t);d.push(s),t=f;}return [d,t]}}}function We(e,r={}){return u(Q(e,r),X(e,r))}var Y=(e,r={})=>{let n=typeof r=="boolean"?{backward:r}:r,o=n.backward??!1,t=o?"; backward":"";return {description:n.description??`bitArray(${e}${t})`,encode(i){let c=[];for(let d=0;d<e;d+=1){let a=0;for(let s=0;s<8;s+=1){let f=Number(i[d*8+s]??0);a|=f<<(o?s:7-s);}o?c.unshift(a):c.push(a);}return new Uint8Array(c)},fixedSize:e,maxSize:e}},Z=(e,r={})=>{let n=typeof r=="boolean"?{backward:r}:r,o=n.backward??!1,t=o?"; backward":"";return {decode(i,c=0){D("bitArray",e,i,c);let d=[],a=i.slice(c,c+e);return a=o?a.reverse():a,a.forEach(s=>{for(let f=0;f<8;f+=1)o?(d.push(!!(s&1)),s>>=1):(d.push(!!(s&128)),s<<=1);}),[d,c+e]},description:n.description??`bitArray(${e}${t})`,fixedSize:e,maxSize:e}},er=(e,r={})=>u(Y(e,r),Z(e,r));function ee(e={}){let r=e.size??S();return O(r,"Codec [bool] requires a fixed size."),{description:e.description??`bool(${r.description})`,encode:n=>r.encode(n?1:0),fixedSize:r.fixedSize,maxSize:r.fixedSize}}function re(e={}){let r=e.size??b();return O(r,"Codec [bool] requires a fixed size."),{decode:(n,o=0)=>{C("bool",n,o);let[t,i]=r.decode(n,o);return [t===1,i]},description:e.description??`bool(${r.description})`,fixedSize:r.fixedSize,maxSize:r.fixedSize}}function mr(e={}){return u(ee(e),re(e))}function ne(e={}){let r=e.size??"variable",n=typeof r=="object"?r.description:`${r}`,o=e.description??`bytes(${n})`,t={description:o,encode:i=>i,fixedSize:null,maxSize:null};return r==="variable"?t:typeof r=="number"?k(t,r,o):{...t,encode:i=>{let c=t.encode(i),d=r.encode(c.length);return x([d,c])}}}function oe(e={}){let r=e.size??"variable",n=typeof r=="object"?r.description:`${r}`,o=e.description??`bytes(${n})`,t={decode:(i,c=0)=>{let d=i.slice(c);return [d,c+d.length]},description:o,fixedSize:null,maxSize:null};return r==="variable"?t:typeof r=="number"?I(t,r,o):{...t,decode:(i,c=0)=>{C("bytes",i,c);let[d,a]=r.decode(i,c),s=Number(d);c=a;let f=i.slice(c,c+s);D("bytes",s,f);let[m,E]=t.decode(f);return c+=E,[m,c]}}}function br(e={}){return u(ne(e),oe(e))}function K(e,r,n){let o=e.map(([d,a])=>`${String(d)}${a?`: ${a.description}`:""}`).join(", "),i=e.every((d,a,s)=>d[1].fixedSize===s[0][1].fixedSize)?e[0][1].fixedSize:null,c=L(e.map(([,d])=>d.maxSize));return {description:n??`dataEnum(${o}; ${r.description})`,fixedSize:e.length===0?r.fixedSize:l([r.fixedSize,i]),maxSize:e.length===0?r.maxSize:l([r.maxSize,c])}}function te(e,r={}){let n=r.size??S();return {...K(e,n,r.description),encode:o=>{let t=e.findIndex(([a])=>o.__kind===a);if(t<0)throw new Error(`Invalid data enum variant. Expected one of [${e.map(([a])=>a).join(", ")}], got "${o.__kind}".`);let i=n.encode(t),d=e[t][1].encode(o);return x([i,d])}}}function ie(e,r={}){let n=r.size??b();return {...K(e,n,r.description),decode:(o,t=0)=>{C("dataEnum",o,t);let[i,c]=n.decode(o,t);t=c;let d=e[Number(i)]??null;if(!d)throw new Error(`Enum discriminator out of range. Expected a number between 0 and ${e.length-1}, got ${i}.`);let[a,s]=d[1].decode(o,t);return t=s,[{__kind:d[0],...a??{}},t]}}}function Ir(e,r={}){return u(te(e,r),ie(e,r))}function P(e,r,n,o){if(n==="remainder"&&(e.fixedSize===null||r.fixedSize===null))throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:o??`map(${e.description}, ${r.description}; ${y(n)})`,fixedSize:g(n,[e.fixedSize,r.fixedSize]),maxSize:g(n,[e.maxSize,r.maxSize])}}function ce(e,r,n={}){let o=n.size??N();return {...P(e,r,o,n.description),encode:t=>{typeof o=="number"&&T("map",o,t.size);let i=Array.from(t,([c,d])=>x([e.encode(c),r.encode(d)]));return x([A(o,t.size),...i])}}}function de(e,r,n={}){let o=n.size??U();return {...P(e,r,o,n.description),decode:(t,i=0)=>{let c=new Map;if(typeof o=="object"&&t.slice(i).length===0)return [c,i];let[d,a]=h(o,[e.fixedSize,r.fixedSize],t,i);i=a;for(let s=0;s<d;s+=1){let[f,m]=e.decode(t,i);i=m;let[E,B]=r.decode(t,i);i=B,c.set(f,E);}return [c,i]}}}function Qr(e,r,n={}){return u(ce(e,r,n),de(e,r,n))}function j(e,r,n,o){let t=`; ${y(r)}`,i=e.fixedSize===0?r.fixedSize:null;return n&&(O(e,"Fixed nullables can only be used with fixed-size codecs."),O(r,"Fixed nullables can only be used with fixed-size prefix."),t+="; fixed",i=r.fixedSize+e.fixedSize),{description:o??`nullable(${e.description+t})`,fixedSize:i,maxSize:l([r.maxSize,e.maxSize])}}function ae(e,r={}){let n=r.prefix??S(),o=r.fixed??!1;return {...j(e,n,o,r.description),encode:t=>{let i=n.encode(+(t!==null)),c=t!==null?e.encode(t):new Uint8Array;return c=o?v(c,e.fixedSize):c,x([i,c])}}}function se(e,r={}){let n=r.prefix??b(),o=r.fixed??!1;return {...j(e,n,o,r.description),decode:(t,i=0)=>{if(t.slice(i).length===0)return [null,i];let c=i+(n.fixedSize??0)+(e.fixedSize??0),[d,a]=n.decode(t,i);if(i=a,d===0)return [null,o?c:i];let[s,f]=e.decode(t,i);return i=f,[s,o?c:i]}}}function mn(e,r={}){return u(ae(e,r),se(e,r))}function M(e,r,n){let o=Object.keys(e),t=Object.values(e),i=t.some(f=>typeof f=="number"),c=t.filter(f=>typeof f=="string").join(", "),d=0,a=i?t.length/2-1:t.length-1,s=i?[...o]:[...new Set([...o,...t])];return {description:n??`enum(${c}; ${r.description})`,enumKeys:o,enumValues:t,fixedSize:r.fixedSize,isNumericEnum:i,maxRange:a,maxSize:r.maxSize,minRange:d,stringValues:s}}function ue(e,r={}){let n=r.size??S(),{description:o,fixedSize:t,maxSize:i,minRange:c,maxRange:d,stringValues:a,enumKeys:s,enumValues:f}=M(e,n,r.description);return {description:o,encode:m=>{let E=typeof m=="number"&&(m<c||m>d),B=typeof m=="string"&&!a.includes(m);if(E||B)throw new Error(`Invalid scalar enum variant. Expected one of [${a.join(", ")}] or a number between ${c} and ${d}, got "${m}".`);if(typeof m=="number")return n.encode(m);let z=f.indexOf(m);return z>=0?n.encode(z):n.encode(s.indexOf(m))},fixedSize:t,maxSize:i}}function fe(e,r={}){let n=r.size??b(),{description:o,fixedSize:t,maxSize:i,minRange:c,maxRange:d,isNumericEnum:a,enumValues:s}=M(e,n,r.description);return {decode:(f,m=0)=>{C("enum",f,m);let[E,B]=n.decode(f,m),z=Number(E);if(m=B,z<c||z>d)throw new Error(`Enum discriminator out of range. Expected a number between ${c} and ${d}, got ${z}.`);return [a?z:s[z],m]},description:o,fixedSize:t,maxSize:i}}function On(e,r={}){return u(ue(e,r),fe(e,r))}function H(e,r,n){if(r==="remainder"&&e.fixedSize===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:n??`set(${e.description}; ${y(r)})`,fixedSize:g(r,[e.fixedSize]),maxSize:g(r,[e.maxSize])}}function me(e,r={}){let n=r.size??N();return {...H(e,n,r.description),encode:o=>{typeof n=="number"&&o.size!==n&&T("set",n,o.size);let t=Array.from(o,i=>e.encode(i));return x([A(n,o.size),...t])}}}function pe(e,r={}){let n=r.size??U();return {...H(e,n,r.description),decode:(o,t=0)=>{let i=new Set;if(typeof n=="object"&&o.slice(t).length===0)return [i,t];let[c,d]=h(n,[e.fixedSize],o,t);t=d;for(let a=0;a<c;a+=1){let[s,f]=e.decode(o,t);t=f,i.add(s);}return [i,t]}}}function Pn(e,r={}){return u(me(e,r),pe(e,r))}function R(e,r){let n=e.map(([o,t])=>`${String(o)}: ${t.description}`).join(", ");return {description:r??`struct(${n})`,fixedSize:l(e.map(([,o])=>o.fixedSize)),maxSize:l(e.map(([,o])=>o.maxSize))}}function xe(e,r={}){return {...R(e,r.description),encode:n=>{let o=e.map(([t,i])=>i.encode(n[t]));return x(o)}}}function le(e,r={}){return {...R(e,r.description),decode:(n,o=0)=>{let t={};return e.forEach(([i,c])=>{let[d,a]=c.decode(n,o);o=a,t[i]=d;}),[t,o]}}}function Xn(e,r={}){return u(xe(e,r),le(e,r))}function W(e,r){let n=e.map(o=>o.description).join(", ");return {description:r??`tuple(${n})`,fixedSize:l(e.map(o=>o.fixedSize)),maxSize:l(e.map(o=>o.maxSize))}}function Ce(e,r={}){return {...W(e,r.description),encode:n=>(T("tuple",e.length,n.length),x(e.map((o,t)=>o.encode(n[t]))))}}function ge(e,r={}){return {...W(e,r.description),decode:(n,o=0)=>{let t=[];return e.forEach(i=>{let[c,d]=i.decode(n,o);t.push(c),o=d;}),[t,o]}}}function so(e,r={}){return u(Ce(e,r),ge(e,r))}function ze(e={}){return {description:e.description??"unit",encode:()=>new Uint8Array,fixedSize:0,maxSize:0}}function Se(e={}){return {decode:(r,n=0)=>[void 0,n],description:e.description??"unit",fixedSize:0,maxSize:0}}function go(e={}){return u(ze(e),Se(e))} | ||
function C(e,r,n=0){if(r.length-n<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function E(e,r,n,o=0){let t=n.length-o;if(t<r)throw new Error(`Codec [${e}] expected ${r} bytes, got ${t}.`)}function D(e,r){if(e.fixedSize===null)throw new Error(r??"Expected a fixed-size codec, got a variable-size one.")}var x=e=>{let r=e.filter(i=>i.length);if(r.length===0)return e.length?e[0]:new Uint8Array;if(r.length===1)return r[0];let n=r.reduce((i,c)=>i+c.length,0),o=new Uint8Array(n),t=0;return r.forEach(i=>{o.set(i,t),t+=i.length;}),o},G=(e,r)=>{if(e.length>=r)return e;let n=new Uint8Array(r).fill(0);return n.set(e),n},v=(e,r)=>G(e.length<=r?e:e.slice(0,r),r);function u(e,r,n){if(e.fixedSize!==r.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${r.fixedSize}].`);if(e.maxSize!==r.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${r.maxSize}].`);if(n===void 0&&e.description!==r.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${r.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:r.decode,description:n??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function w(e,r,n){return {description:n??`fixed(${r}, ${e.description})`,fixedSize:r,maxSize:r}}function k(e,r,n){return {...w(e,r,n),encode:o=>v(e.encode(o),r)}}function I(e,r,n){return {...w(e,r,n),decode:(o,t=0)=>{E("fixCodec",r,o,t),(t>0||o.length>r)&&(o=o.slice(t,t+r)),e.fixedSize!==null&&(o=v(o,e.fixedSize));let[i]=e.decode(o,0);return [i,t+r]}}}function q(e,r,n,o){if(o<r||o>n)throw new Error(`Codec [${e}] expected number to be in the range [${r}, ${n}], got ${o}.`)}function $(e){let r,n=e.name;return e.size>1&&(r=!("endian"in e.options)||e.options.endian===0,n+=r?"(le)":"(be)"),{description:e.options.description??n,fixedSize:e.size,littleEndian:r,maxSize:e.size}}function _(e){let r=$(e);return {description:r.description,encode(n){e.range&&q(e.name,e.range[0],e.range[1],n);let o=new ArrayBuffer(e.size);return e.set(new DataView(o),n,r.littleEndian),new Uint8Array(o)},fixedSize:r.fixedSize,maxSize:r.maxSize}}function F(e){let r=$(e);return {decode(n,o=0){C(r.description,n,o),E(r.description,e.size,n,o);let t=new DataView(J(n,o,e.size));return [e.get(t,r.littleEndian),o+e.size]},description:r.description,fixedSize:r.fixedSize,maxSize:r.maxSize}}function J(e,r,n){let o=e.byteOffset+(r??0),t=n??e.byteLength;return e.buffer.slice(o,o+t)}var O=(e={})=>_({name:"u32",options:e,range:[0,+"0xffffffff"],set:(r,n,o)=>r.setUint32(0,n,o),size:4}),N=(e={})=>F({get:(r,n)=>r.getUint32(0,n),name:"u32",options:e,size:4});var S=(e={})=>_({name:"u8",options:e,range:[0,+"0xff"],set:(r,n)=>r.setUint8(0,n),size:1}),b=(e={})=>F({get:r=>r.getUint8(0),name:"u8",options:e,size:1});function V(e){return e.reduce((r,n)=>r===null||n===null?null:Math.max(r,n),0)}function l(e){return e.reduce((r,n)=>r===null||n===null?null:r+n,0)}function U(e,r,n,o){if(typeof e=="number")return [e,o];if(typeof e=="object")return e.decode(n,o);if(e==="remainder"){let t=l(r);if(t===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');let i=n.slice(o).length;if(i%t!==0)throw new Error(`The remainder of the byte array (${i} bytes) cannot be split into chunks of ${t} bytes. Codecs of "remainder" size must have a remainder that is a multiple of its item size. In other words, ${i} modulo ${t} should be equal to zero.`);return [i/t,o]}throw new Error(`Unrecognized array-like codec size: ${JSON.stringify(e)}`)}function h(e){return typeof e=="object"?e.description:`${e}`}function g(e,r){if(typeof e!="number")return null;if(e===0)return 0;let n=l(r);return n===null?null:n*e}function B(e,r){return typeof e=="object"?e.encode(r):new Uint8Array}function y(e,r,n){if(r!==n)throw new Error(`Expected [${e}] to have ${r} items, got ${n}.`)}function L(e,r,n){if(r==="remainder"&&e.fixedSize===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:n??`array(${e.description}; ${h(r)})`,fixedSize:g(r,[e.fixedSize]),maxSize:g(r,[e.maxSize])}}function Q(e,r={}){let n=r.size??O();return {...L(e,n,r.description),encode:o=>(typeof n=="number"&&y("array",n,o.length),x([B(n,o.length),...o.map(t=>e.encode(t))]))}}function X(e,r={}){let n=r.size??N();return {...L(e,n,r.description),decode:(o,t=0)=>{if(typeof n=="object"&&o.slice(t).length===0)return [[],t];let[i,c]=U(n,[e.fixedSize],o,t);t=c;let d=[];for(let a=0;a<i;a+=1){let[s,f]=e.decode(o,t);d.push(s),t=f;}return [d,t]}}}function We(e,r={}){return u(Q(e,r),X(e,r))}var Y=(e,r={})=>{let n=typeof r=="boolean"?{backward:r}:r,o=n.backward??!1,t=o?"; backward":"";return {description:n.description??`bitArray(${e}${t})`,encode(i){let c=[];for(let d=0;d<e;d+=1){let a=0;for(let s=0;s<8;s+=1){let f=Number(i[d*8+s]??0);a|=f<<(o?s:7-s);}o?c.unshift(a):c.push(a);}return new Uint8Array(c)},fixedSize:e,maxSize:e}},Z=(e,r={})=>{let n=typeof r=="boolean"?{backward:r}:r,o=n.backward??!1,t=o?"; backward":"";return {decode(i,c=0){E("bitArray",e,i,c);let d=[],a=i.slice(c,c+e);return a=o?a.reverse():a,a.forEach(s=>{for(let f=0;f<8;f+=1)o?(d.push(!!(s&1)),s>>=1):(d.push(!!(s&128)),s<<=1);}),[d,c+e]},description:n.description??`bitArray(${e}${t})`,fixedSize:e,maxSize:e}},er=(e,r={})=>u(Y(e,r),Z(e,r));function ee(e={}){let r=e.size??S();return D(r,"Codec [bool] requires a fixed size."),{description:e.description??`bool(${r.description})`,encode:n=>r.encode(n?1:0),fixedSize:r.fixedSize,maxSize:r.fixedSize}}function re(e={}){let r=e.size??b();return D(r,"Codec [bool] requires a fixed size."),{decode:(n,o=0)=>{C("bool",n,o);let[t,i]=r.decode(n,o);return [t===1,i]},description:e.description??`bool(${r.description})`,fixedSize:r.fixedSize,maxSize:r.fixedSize}}function mr(e={}){return u(ee(e),re(e))}function ne(e={}){let r=e.size??"variable",n=typeof r=="object"?r.description:`${r}`,o=e.description??`bytes(${n})`,t={description:o,encode:i=>i,fixedSize:null,maxSize:null};return r==="variable"?t:typeof r=="number"?k(t,r,o):{...t,encode:i=>{let c=t.encode(i),d=r.encode(c.length);return x([d,c])}}}function oe(e={}){let r=e.size??"variable",n=typeof r=="object"?r.description:`${r}`,o=e.description??`bytes(${n})`,t={decode:(i,c=0)=>{let d=i.slice(c);return [d,c+d.length]},description:o,fixedSize:null,maxSize:null};return r==="variable"?t:typeof r=="number"?I(t,r,o):{...t,decode:(i,c=0)=>{C("bytes",i,c);let[d,a]=r.decode(i,c),s=Number(d);c=a;let f=i.slice(c,c+s);E("bytes",s,f);let[m,T]=t.decode(f);return c+=T,[m,c]}}}function br(e={}){return u(ne(e),oe(e))}function K(e,r,n){let o=e.map(([d,a])=>`${String(d)}${a?`: ${a.description}`:""}`).join(", "),i=e.every((d,a,s)=>d[1].fixedSize===s[0][1].fixedSize)?e[0][1].fixedSize:null,c=V(e.map(([,d])=>d.maxSize));return {description:n??`dataEnum(${o}; ${r.description})`,fixedSize:e.length===0?r.fixedSize:l([r.fixedSize,i]),maxSize:e.length===0?r.maxSize:l([r.maxSize,c])}}function te(e,r={}){let n=r.size??S();return {...K(e,n,r.description),encode:o=>{let t=e.findIndex(([a])=>o.__kind===a);if(t<0)throw new Error(`Invalid data enum variant. Expected one of [${e.map(([a])=>a).join(", ")}], got "${o.__kind}".`);let i=n.encode(t),d=e[t][1].encode(o);return x([i,d])}}}function ie(e,r={}){let n=r.size??b();return {...K(e,n,r.description),decode:(o,t=0)=>{C("dataEnum",o,t);let[i,c]=n.decode(o,t);t=c;let d=e[Number(i)]??null;if(!d)throw new Error(`Enum discriminator out of range. Expected a number between 0 and ${e.length-1}, got ${i}.`);let[a,s]=d[1].decode(o,t);return t=s,[{__kind:d[0],...a??{}},t]}}}function Ir(e,r={}){return u(te(e,r),ie(e,r))}function P(e,r,n,o){if(n==="remainder"&&(e.fixedSize===null||r.fixedSize===null))throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:o??`map(${e.description}, ${r.description}; ${h(n)})`,fixedSize:g(n,[e.fixedSize,r.fixedSize]),maxSize:g(n,[e.maxSize,r.maxSize])}}function ce(e,r,n={}){let o=n.size??O();return {...P(e,r,o,n.description),encode:t=>{typeof o=="number"&&y("map",o,t.size);let i=Array.from(t,([c,d])=>x([e.encode(c),r.encode(d)]));return x([B(o,t.size),...i])}}}function de(e,r,n={}){let o=n.size??N();return {...P(e,r,o,n.description),decode:(t,i=0)=>{let c=new Map;if(typeof o=="object"&&t.slice(i).length===0)return [c,i];let[d,a]=U(o,[e.fixedSize,r.fixedSize],t,i);i=a;for(let s=0;s<d;s+=1){let[f,m]=e.decode(t,i);i=m;let[T,A]=r.decode(t,i);i=A,c.set(f,T);}return [c,i]}}}function Qr(e,r,n={}){return u(ce(e,r,n),de(e,r,n))}function j(e,r,n,o){let t=`; ${r.description}`,i=e.fixedSize===0?r.fixedSize:null;return n&&(D(e,"Fixed nullables can only be used with fixed-size codecs."),D(r,"Fixed nullables can only be used with fixed-size prefix."),t+="; fixed",i=r.fixedSize+e.fixedSize),{description:o??`nullable(${e.description+t})`,fixedSize:i,maxSize:l([r.maxSize,e.maxSize])}}function ae(e,r={}){let n=r.prefix??S(),o=r.fixed??!1;return {...j(e,n,o,r.description),encode:t=>{let i=n.encode(+(t!==null)),c=t!==null?e.encode(t):new Uint8Array;return c=o?v(c,e.fixedSize):c,x([i,c])}}}function se(e,r={}){let n=r.prefix??b(),o=r.fixed??!1;return {...j(e,n,o,r.description),decode:(t,i=0)=>{if(t.length-i<=0)return [null,i];let c=i+(n.fixedSize??0)+(e.fixedSize??0),[d,a]=n.decode(t,i);if(i=a,d===0)return [null,o?c:i];let[s,f]=e.decode(t,i);return i=f,[s,o?c:i]}}}function fn(e,r={}){return u(ae(e,r),se(e,r))}function M(e,r,n){let o=Object.keys(e),t=Object.values(e),i=t.some(f=>typeof f=="number"),c=t.filter(f=>typeof f=="string").join(", "),d=0,a=i?t.length/2-1:t.length-1,s=i?[...o]:[...new Set([...o,...t])];return {description:n??`enum(${c}; ${r.description})`,enumKeys:o,enumValues:t,fixedSize:r.fixedSize,isNumericEnum:i,maxRange:a,maxSize:r.maxSize,minRange:d,stringValues:s}}function ue(e,r={}){let n=r.size??S(),{description:o,fixedSize:t,maxSize:i,minRange:c,maxRange:d,stringValues:a,enumKeys:s,enumValues:f}=M(e,n,r.description);return {description:o,encode:m=>{let T=typeof m=="number"&&(m<c||m>d),A=typeof m=="string"&&!a.includes(m);if(T||A)throw new Error(`Invalid scalar enum variant. Expected one of [${a.join(", ")}] or a number between ${c} and ${d}, got "${m}".`);if(typeof m=="number")return n.encode(m);let z=f.indexOf(m);return z>=0?n.encode(z):n.encode(s.indexOf(m))},fixedSize:t,maxSize:i}}function fe(e,r={}){let n=r.size??b(),{description:o,fixedSize:t,maxSize:i,minRange:c,maxRange:d,isNumericEnum:a,enumValues:s}=M(e,n,r.description);return {decode:(f,m=0)=>{C("enum",f,m);let[T,A]=n.decode(f,m),z=Number(T);if(m=A,z<c||z>d)throw new Error(`Enum discriminator out of range. Expected a number between ${c} and ${d}, got ${z}.`);return [a?z:s[z],m]},description:o,fixedSize:t,maxSize:i}}function Dn(e,r={}){return u(ue(e,r),fe(e,r))}function H(e,r,n){if(r==="remainder"&&e.fixedSize===null)throw new Error('Codecs of "remainder" size must have fixed-size items.');return {description:n??`set(${e.description}; ${h(r)})`,fixedSize:g(r,[e.fixedSize]),maxSize:g(r,[e.maxSize])}}function me(e,r={}){let n=r.size??O();return {...H(e,n,r.description),encode:o=>{typeof n=="number"&&o.size!==n&&y("set",n,o.size);let t=Array.from(o,i=>e.encode(i));return x([B(n,o.size),...t])}}}function pe(e,r={}){let n=r.size??N();return {...H(e,n,r.description),decode:(o,t=0)=>{let i=new Set;if(typeof n=="object"&&o.slice(t).length===0)return [i,t];let[c,d]=U(n,[e.fixedSize],o,t);t=d;for(let a=0;a<c;a+=1){let[s,f]=e.decode(o,t);t=f,i.add(s);}return [i,t]}}}function Kn(e,r={}){return u(me(e,r),pe(e,r))}function R(e,r){let n=e.map(([o,t])=>`${String(o)}: ${t.description}`).join(", ");return {description:r??`struct(${n})`,fixedSize:l(e.map(([,o])=>o.fixedSize)),maxSize:l(e.map(([,o])=>o.maxSize))}}function xe(e,r={}){return {...R(e,r.description),encode:n=>{let o=e.map(([t,i])=>i.encode(n[t]));return x(o)}}}function le(e,r={}){return {...R(e,r.description),decode:(n,o=0)=>{let t={};return e.forEach(([i,c])=>{let[d,a]=c.decode(n,o);o=a,t[i]=d;}),[t,o]}}}function Qn(e,r={}){return u(xe(e,r),le(e,r))}function W(e,r){let n=e.map(o=>o.description).join(", ");return {description:r??`tuple(${n})`,fixedSize:l(e.map(o=>o.fixedSize)),maxSize:l(e.map(o=>o.maxSize))}}function Ce(e,r={}){return {...W(e,r.description),encode:n=>(y("tuple",e.length,n.length),x(e.map((o,t)=>o.encode(n[t]))))}}function ge(e,r={}){return {...W(e,r.description),decode:(n,o=0)=>{let t=[];return e.forEach(i=>{let[c,d]=i.decode(n,o);t.push(c),o=d;}),[t,o]}}}function ao(e,r={}){return u(Ce(e,r),ge(e,r))}function ze(e={}){return {description:e.description??"unit",encode:()=>new Uint8Array,fixedSize:0,maxSize:0}}function Se(e={}){return {decode:(r,n=0)=>[void 0,n],description:e.description??"unit",fixedSize:0,maxSize:0}}function Co(e={}){return u(ze(e),Se(e))} | ||
exports.assertValidNumberOfItemsForCodec = T; | ||
exports.decodeArrayLikeCodecSize = h; | ||
exports.assertValidNumberOfItemsForCodec = y; | ||
exports.decodeArrayLikeCodecSize = U; | ||
exports.getArrayCodec = We; | ||
exports.getArrayDecoder = X; | ||
exports.getArrayEncoder = Q; | ||
exports.getArrayLikeCodecSizeDescription = y; | ||
exports.getArrayLikeCodecSizeDescription = h; | ||
exports.getArrayLikeCodecSizeFromChildren = g; | ||
exports.getArrayLikeCodecSizePrefix = A; | ||
exports.getArrayLikeCodecSizePrefix = B; | ||
exports.getBitArrayCodec = er; | ||
@@ -31,18 +31,18 @@ exports.getBitArrayDecoder = Z; | ||
exports.getMapEncoder = ce; | ||
exports.getNullableCodec = mn; | ||
exports.getNullableCodec = fn; | ||
exports.getNullableDecoder = se; | ||
exports.getNullableEncoder = ae; | ||
exports.getScalarEnumCodec = On; | ||
exports.getScalarEnumCodec = Dn; | ||
exports.getScalarEnumDecoder = fe; | ||
exports.getScalarEnumEncoder = ue; | ||
exports.getSetCodec = Pn; | ||
exports.getSetCodec = Kn; | ||
exports.getSetDecoder = pe; | ||
exports.getSetEncoder = me; | ||
exports.getStructCodec = Xn; | ||
exports.getStructCodec = Qn; | ||
exports.getStructDecoder = le; | ||
exports.getStructEncoder = xe; | ||
exports.getTupleCodec = so; | ||
exports.getTupleCodec = ao; | ||
exports.getTupleDecoder = ge; | ||
exports.getTupleEncoder = Ce; | ||
exports.getUnitCodec = go; | ||
exports.getUnitCodec = Co; | ||
exports.getUnitDecoder = Se; | ||
@@ -49,0 +49,0 @@ exports.getUnitEncoder = ze; |
@@ -29,3 +29,3 @@ import { BaseCodecOptions, Codec, Decoder, Encoder } from '@solana/codecs-core'; | ||
*/ | ||
export declare function getScalarEnumEncoder<T>(constructor: ScalarEnum<T>, options?: ScalarEnumCodecOptions<NumberCodec>): Encoder<T>; | ||
export declare function getScalarEnumEncoder<T>(constructor: ScalarEnum<T>, options?: ScalarEnumCodecOptions<NumberEncoder>): Encoder<T>; | ||
/** | ||
@@ -37,3 +37,3 @@ * Creates a scalar enum decoder. | ||
*/ | ||
export declare function getScalarEnumDecoder<T>(constructor: ScalarEnum<T>, options?: ScalarEnumCodecOptions<NumberCodec>): Decoder<T>; | ||
export declare function getScalarEnumDecoder<T>(constructor: ScalarEnum<T>, options?: ScalarEnumCodecOptions<NumberDecoder>): Decoder<T>; | ||
/** | ||
@@ -40,0 +40,0 @@ * Creates a scalar enum codec. |
{ | ||
"name": "@solana/codecs-data-structures", | ||
"version": "2.0.0-experimental.cd89114", | ||
"version": "2.0.0-experimental.ce145c8", | ||
"description": "Codecs for various data structures", | ||
@@ -52,9 +52,9 @@ "exports": { | ||
"dependencies": { | ||
"@solana/codecs-core": "2.0.0-experimental.cd89114", | ||
"@solana/codecs-numbers": "2.0.0-experimental.cd89114" | ||
"@solana/codecs-core": "2.0.0-experimental.ce145c8", | ||
"@solana/codecs-numbers": "2.0.0-experimental.ce145c8" | ||
}, | ||
"devDependencies": { | ||
"@solana/eslint-config-solana": "^1.0.2", | ||
"@swc/jest": "^0.2.28", | ||
"@types/jest": "^29.5.5", | ||
"@swc/jest": "^0.2.29", | ||
"@types/jest": "^29.5.6", | ||
"@typescript-eslint/eslint-plugin": "^6.7.0", | ||
@@ -64,7 +64,7 @@ "@typescript-eslint/parser": "^6.3.0", | ||
"eslint": "^8.45.0", | ||
"eslint-plugin-jest": "^27.2.3", | ||
"eslint-plugin-jest": "^27.4.2", | ||
"eslint-plugin-sort-keys-fix": "^1.1.2", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.6.4", | ||
"jest-runner-eslint": "^2.1.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jest-runner-eslint": "^2.1.2", | ||
"jest-runner-prettier": "^1.0.0", | ||
@@ -75,3 +75,3 @@ "prettier": "^2.8", | ||
"version-from-git": "^1.1.1", | ||
"@solana/codecs-strings": "2.0.0-experimental.cd89114", | ||
"@solana/codecs-strings": "2.0.0-experimental.ce145c8", | ||
"build-scripts": "0.0.0", | ||
@@ -94,8 +94,8 @@ "test-config": "0.0.0", | ||
"publish-packages": "pnpm publish --tag experimental --access public --no-git-checks", | ||
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/*", | ||
"style:fix": "pnpm eslint --fix src/* && pnpm prettier -w src/* package.json", | ||
"test:lint": "jest -c node_modules/test-config/jest-lint.config.ts --rootDir . --silent", | ||
"test:prettier": "jest -c node_modules/test-config/jest-prettier.config.ts --rootDir . --silent", | ||
"test:treeshakability:browser": "agadoo dist/index.browser.js", | ||
"test:treeshakability:native": "agadoo dist/index.node.js", | ||
"test:treeshakability:node": "agadoo dist/index.native.js", | ||
"test:treeshakability:native": "agadoo dist/index.native.js", | ||
"test:treeshakability:node": "agadoo dist/index.node.js", | ||
"test:typecheck": "tsc --noEmit", | ||
@@ -102,0 +102,0 @@ "test:unit:browser": "jest -c node_modules/test-config/jest-unit.config.browser.ts --rootDir . --silent", |
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
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
641530
5234
+ Added@solana/codecs-core@2.0.0-experimental.ce145c8(transitive)
+ Added@solana/codecs-numbers@2.0.0-experimental.ce145c8(transitive)
- Removed@solana/codecs-core@2.0.0-experimental.cd89114(transitive)
- Removed@solana/codecs-numbers@2.0.0-experimental.cd89114(transitive)