Socket
Socket
Sign inDemoInstall

@solana/options

Package Overview
Dependencies
Maintainers
14
Versions
1047
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@solana/options - npm Package Compare versions

Comparing version 2.0.0-experimental.47afb90 to 2.0.0-experimental.49dc7f3

dist/types/index.d.ts.map

26

dist/index.development.js

@@ -26,3 +26,3 @@ this.globalThis = this.globalThis || {};

if (data.fixedSize === null) {
throw new Error(message ?? "Expected a fixed-size codec, got a variable-size one.");
throw new Error(message != null ? message : "Expected a fixed-size codec, got a variable-size one.");
}

@@ -73,3 +73,3 @@ }

decode: decoder.decode,
description: description ?? encoder.description,
description: description != null ? description : encoder.description,
encode: encoder.encode,

@@ -90,2 +90,3 @@ fixedSize: encoder.fixedSize,

function sharedNumberFactory(input) {
var _a;
let littleEndian;

@@ -98,3 +99,3 @@ let defaultDescription = input.name;

return {
description: input.config.description ?? defaultDescription,
description: (_a = input.config.description) != null ? _a : defaultDescription,
fixedSize: input.size,

@@ -136,4 +137,4 @@ littleEndian,

function toArrayBuffer(bytes, offset, length) {
const bytesOffset = bytes.byteOffset + (offset ?? 0);
const bytesLength = length ?? bytes.byteLength;
const bytesOffset = bytes.byteOffset + (offset != null ? offset : 0);
const bytesLength = length != null ? length : bytes.byteLength;
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength);

@@ -177,3 +178,3 @@ }

return {
description: description ?? `option(${item.description + descriptionSuffix})`,
description: description != null ? description : `option(${item.description + descriptionSuffix})`,
fixedSize,

@@ -184,4 +185,5 @@ maxSize: sumCodecSizes([prefix.maxSize, item.maxSize])

function getOptionEncoder(item, config = {}) {
const prefix = config.prefix ?? getU8Encoder();
const fixed = config.fixed ?? false;
var _a, _b;
const prefix = (_a = config.prefix) != null ? _a : getU8Encoder();
const fixed = (_b = config.fixed) != null ? _b : false;
return {

@@ -199,11 +201,13 @@ ...optionCodecHelper(item, prefix, fixed, config.description),

function getOptionDecoder(item, config = {}) {
const prefix = config.prefix ?? getU8Decoder();
const fixed = config.fixed ?? false;
var _a, _b;
const prefix = (_a = config.prefix) != null ? _a : getU8Decoder();
const fixed = (_b = config.fixed) != null ? _b : false;
return {
...optionCodecHelper(item, prefix, fixed, config.description),
decode: (bytes, offset = 0) => {
var _a2, _b2;
if (bytes.length - offset <= 0) {
return [none(), offset];
}
const fixedOffset = offset + (prefix.fixedSize ?? 0) + (item.fixedSize ?? 0);
const fixedOffset = offset + ((_a2 = prefix.fixedSize) != null ? _a2 : 0) + ((_b2 = item.fixedSize) != null ? _b2 : 0);
const [isSome2, prefixOffset] = prefix.decode(bytes, offset);

@@ -210,0 +214,0 @@ offset = prefixOffset;

@@ -98,1 +98,3 @@ import { fixBytes, mergeBytes, combineCodec, assertFixedSizeCodec } from '@solana/codecs-core';

export { getOptionCodec, getOptionDecoder, getOptionEncoder, isNone, isOption, isSome, none, some, unwrapOption, unwrapOptionRecursively, wrapNullable };
//# sourceMappingURL=out.js.map
//# sourceMappingURL=index.native.js.map

@@ -5,15 +5,15 @@ this.globalThis = this.globalThis || {};

var p=e=>({__option:"Some",value:e}),c=()=>({__option:"None"}),u=e=>!!(e&&typeof e=="object"&&"__option"in e&&(e.__option==="Some"&&"value"in e||e.__option==="None")),f=e=>e.__option==="Some",L=e=>e.__option==="None";function m(e,n,t=0){if(n.length-t<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function l(e,n,t,r=0){let i=t.length-r;if(i<n)throw new Error(`Codec [${e}] expected ${n} bytes, got ${i}.`)}function g(e,n){if(e.fixedSize===null)throw new Error(n??"Expected a fixed-size codec, got a variable-size one.")}var z=e=>{let n=e.filter(o=>o.length);if(n.length===0)return e.length?e[0]:new Uint8Array;if(n.length===1)return n[0];let t=n.reduce((o,a)=>o+a.length,0),r=new Uint8Array(t),i=0;return n.forEach(o=>{r.set(o,i),i+=o.length;}),r},E=(e,n)=>{if(e.length>=n)return e;let t=new Uint8Array(n).fill(0);return t.set(e),t},U=(e,n)=>E(e.length<=n?e:e.slice(0,n),n);function x(e,n,t){if(e.fixedSize!==n.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${n.fixedSize}].`);if(e.maxSize!==n.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${n.maxSize}].`);if(t===void 0&&e.description!==n.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${n.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:n.decode,description:t??e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function B(e,n,t,r){if(r<n||r>t)throw new Error(`Codec [${e}] expected number to be in the range [${n}, ${t}], got ${r}.`)}function T(e){let n,t=e.name;return e.size>1&&(n=!("endian"in e.config)||e.config.endian===0,t+=n?"(le)":"(be)"),{description:e.config.description??t,fixedSize:e.size,littleEndian:n,maxSize:e.size}}function b(e){let n=T(e);return {description:n.description,encode(t){e.range&&B(e.name,e.range[0],e.range[1],t);let r=new ArrayBuffer(e.size);return e.set(new DataView(r),t,n.littleEndian),new Uint8Array(r)},fixedSize:n.fixedSize,maxSize:n.maxSize}}function N(e){let n=T(e);return {decode(t,r=0){m(n.description,t,r),l(n.description,e.size,t,r);let i=new DataView(D(t,r,e.size));return [e.get(i,n.littleEndian),r+e.size]},description:n.description,fixedSize:n.fixedSize,maxSize:n.maxSize}}function D(e,n,t){let r=e.byteOffset+(n??0),i=t??e.byteLength;return e.buffer.slice(r,r+i)}var S=(e={})=>b({config:e,name:"u8",range:[0,+"0xff"],set:(n,t)=>n.setUint8(0,t),size:1}),O=(e={})=>N({config:e,get:n=>n.getUint8(0),name:"u8",size:1});function q(e,n){return f(e)?e.value:n?n():null}var v=e=>e!==null?p(e):c();function A(e){return e.reduce((n,t)=>n===null||t===null?null:n+t,0)}function C(e,n,t,r){let i=`; ${n.description}`,o=e.fixedSize===0?n.fixedSize:null;return t&&(g(e,"Fixed options can only be used with fixed-size codecs."),g(n,"Fixed options can only be used with fixed-size prefix."),i+="; fixed",o=n.fixedSize+e.fixedSize),{description:r??`option(${e.description+i})`,fixedSize:o,maxSize:A([n.maxSize,e.maxSize])}}function _(e,n={}){let t=n.prefix??S(),r=n.fixed??!1;return {...C(e,t,r,n.description),encode:i=>{let o=u(i)?i:v(i),a=t.encode(Number(f(o))),s=f(o)?e.encode(o.value):new Uint8Array;return s=r?U(s,e.fixedSize):s,z([a,s])}}}function F(e,n={}){let t=n.prefix??O(),r=n.fixed??!1;return {...C(e,t,r,n.description),decode:(i,o=0)=>{if(i.length-o<=0)return [c(),o];let a=o+(t.fixedSize??0)+(e.fixedSize??0),[s,h]=t.decode(i,o);if(o=h,s===0)return [c(),r?a:o];let[y,I]=e.decode(i,o);return o=I,[p(y),r?a:o]}}}function ce(e,n={}){return x(_(e,n),F(e,n))}function w(e,n){if(!e||ArrayBuffer.isView(e))return e;let t=r=>n?w(r,n):w(r);return u(e)?f(e)?t(e.value):n?n():null:Array.isArray(e)?e.map(t):typeof e=="object"?Object.fromEntries(Object.entries(e).map(([r,i])=>[r,t(i)])):e}
var x=e=>({__option:"Some",value:e}),p=()=>({__option:"None"}),g=e=>!!(e&&typeof e=="object"&&"__option"in e&&(e.__option==="Some"&&"value"in e||e.__option==="None")),d=e=>e.__option==="Some",R=e=>e.__option==="None";function T(e,n,t=0){if(n.length-t<=0)throw new Error(`Codec [${e}] cannot decode empty byte arrays.`)}function S(e,n,t,r=0){let o=t.length-r;if(o<n)throw new Error(`Codec [${e}] expected ${n} bytes, got ${o}.`)}function m(e,n){if(e.fixedSize===null)throw new Error(n!=null?n:"Expected a fixed-size codec, got a variable-size one.")}var O=e=>{let n=e.filter(i=>i.length);if(n.length===0)return e.length?e[0]:new Uint8Array;if(n.length===1)return n[0];let t=n.reduce((i,a)=>i+a.length,0),r=new Uint8Array(t),o=0;return n.forEach(i=>{r.set(i,o),o+=i.length;}),r},D=(e,n)=>{if(e.length>=n)return e;let t=new Uint8Array(n).fill(0);return t.set(e),t},v=(e,n)=>D(e.length<=n?e:e.slice(0,n),n);function l(e,n,t){if(e.fixedSize!==n.fixedSize)throw new Error(`Encoder and decoder must have the same fixed size, got [${e.fixedSize}] and [${n.fixedSize}].`);if(e.maxSize!==n.maxSize)throw new Error(`Encoder and decoder must have the same max size, got [${e.maxSize}] and [${n.maxSize}].`);if(t===void 0&&e.description!==n.description)throw new Error(`Encoder and decoder must have the same description, got [${e.description}] and [${n.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.`);return {decode:n.decode,description:t!=null?t:e.description,encode:e.encode,fixedSize:e.fixedSize,maxSize:e.maxSize}}function A(e,n,t,r){if(r<n||r>t)throw new Error(`Codec [${e}] expected number to be in the range [${n}, ${t}], got ${r}.`)}function C(e){var r;let n,t=e.name;return e.size>1&&(n=!("endian"in e.config)||e.config.endian===0,t+=n?"(le)":"(be)"),{description:(r=e.config.description)!=null?r:t,fixedSize:e.size,littleEndian:n,maxSize:e.size}}function _(e){let n=C(e);return {description:n.description,encode(t){e.range&&A(e.name,e.range[0],e.range[1],t);let r=new ArrayBuffer(e.size);return e.set(new DataView(r),t,n.littleEndian),new Uint8Array(r)},fixedSize:n.fixedSize,maxSize:n.maxSize}}function F(e){let n=C(e);return {decode(t,r=0){T(n.description,t,r),S(n.description,e.size,t,r);let o=new DataView($(t,r,e.size));return [e.get(o,n.littleEndian),r+e.size]},description:n.description,fixedSize:n.fixedSize,maxSize:n.maxSize}}function $(e,n,t){let r=e.byteOffset+(n!=null?n:0),o=t!=null?t:e.byteLength;return e.buffer.slice(r,r+o)}var w=(e={})=>_({config:e,name:"u8",range:[0,+"0xff"],set:(n,t)=>n.setUint8(0,t),size:1}),h=(e={})=>F({config:e,get:n=>n.getUint8(0),name:"u8",size:1});function W(e,n){return d(e)?e.value:n?n():null}var y=e=>e!==null?x(e):p();function L(e){return e.reduce((n,t)=>n===null||t===null?null:n+t,0)}function I(e,n,t,r){let o=`; ${n.description}`,i=e.fixedSize===0?n.fixedSize:null;return t&&(m(e,"Fixed options can only be used with fixed-size codecs."),m(n,"Fixed options can only be used with fixed-size prefix."),o+="; fixed",i=n.fixedSize+e.fixedSize),{description:r!=null?r:`option(${e.description+o})`,fixedSize:i,maxSize:L([n.maxSize,e.maxSize])}}function V(e,n={}){var o,i;let t=(o=n.prefix)!=null?o:w(),r=(i=n.fixed)!=null?i:!1;return {...I(e,t,r,n.description),encode:a=>{let f=g(a)?a:y(a),u=t.encode(Number(d(f))),c=d(f)?e.encode(f.value):new Uint8Array;return c=r?v(c,e.fixedSize):c,O([u,c])}}}function k(e,n={}){var o,i;let t=(o=n.prefix)!=null?o:h(),r=(i=n.fixed)!=null?i:!1;return {...I(e,t,r,n.description),decode:(a,f=0)=>{var z,U;if(a.length-f<=0)return [p(),f];let u=f+((z=t.fixedSize)!=null?z:0)+((U=e.fixedSize)!=null?U:0),[c,B]=t.decode(a,f);if(f=B,c===0)return [p(),r?u:f];let[b,N]=e.decode(a,f);return f=N,[x(b),r?u:f]}}}function ge(e,n={}){return l(V(e,n),k(e,n))}function E(e,n){if(!e||ArrayBuffer.isView(e))return e;let t=r=>n?E(r,n):E(r);return g(e)?d(e)?t(e.value):n?n():null:Array.isArray(e)?e.map(t):typeof e=="object"?Object.fromEntries(Object.entries(e).map(([r,o])=>[r,t(o)])):e}
exports.getOptionCodec = ce;
exports.getOptionDecoder = F;
exports.getOptionEncoder = _;
exports.isNone = L;
exports.isOption = u;
exports.isSome = f;
exports.none = c;
exports.some = p;
exports.unwrapOption = q;
exports.unwrapOptionRecursively = w;
exports.wrapNullable = v;
exports.getOptionCodec = ge;
exports.getOptionDecoder = k;
exports.getOptionEncoder = V;
exports.isNone = R;
exports.isOption = g;
exports.isSome = d;
exports.none = p;
exports.some = x;
exports.unwrapOption = W;
exports.unwrapOptionRecursively = E;
exports.wrapNullable = y;

@@ -20,0 +20,0 @@ return exports;

{
"name": "@solana/options",
"version": "2.0.0-experimental.47afb90",
"version": "2.0.0-experimental.49dc7f3",
"description": "Managing and serializing Rust-like Option types in JavaScript",

@@ -52,4 +52,4 @@ "exports": {

"dependencies": {
"@solana/codecs-core": "2.0.0-experimental.47afb90",
"@solana/codecs-numbers": "2.0.0-experimental.47afb90"
"@solana/codecs-core": "2.0.0-experimental.49dc7f3",
"@solana/codecs-numbers": "2.0.0-experimental.49dc7f3"
},

@@ -71,3 +71,3 @@ "devDependencies": {

"prettier": "^2.8",
"tsup": "7.2.0",
"tsup": "^8.0.1",
"typescript": "^5.2.2",

@@ -74,0 +74,0 @@ "version-from-git": "^1.1.1",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc