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.72efece to 2.0.0-experimental.735654a

22

dist/index.browser.js

@@ -38,7 +38,7 @@ import { fixBytes, mergeBytes, combineCodec, assertFixedSizeCodec } from '@solana/codecs-core';

}
function getOptionEncoder(item, options = {}) {
const prefix = options.prefix ?? getU8Encoder();
const fixed = options.fixed ?? false;
function getOptionEncoder(item, config = {}) {
const prefix = config.prefix ?? getU8Encoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
encode: (optionOrNullable) => {

@@ -53,7 +53,7 @@ const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable);

}
function getOptionDecoder(item, options = {}) {
const prefix = options.prefix ?? getU8Decoder();
const fixed = options.fixed ?? false;
function getOptionDecoder(item, config = {}) {
const prefix = config.prefix ?? getU8Decoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
decode: (bytes, offset = 0) => {

@@ -75,4 +75,4 @@ if (bytes.length - offset <= 0) {

}
function getOptionCodec(item, options = {}) {
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options));
function getOptionCodec(item, config = {}) {
return combineCodec(getOptionEncoder(item, config), getOptionDecoder(item, config));
}

@@ -101,1 +101,3 @@

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

@@ -91,7 +91,7 @@ this.globalThis = this.globalThis || {};

if (input.size > 1) {
littleEndian = !("endian" in input.options) || input.options.endian === 0;
littleEndian = !("endian" in input.config) || input.config.endian === 0;
defaultDescription += littleEndian ? "(le)" : "(be)";
}
return {
description: input.options.description ?? defaultDescription,
description: input.config.description ?? defaultDescription,
fixedSize: input.size,

@@ -137,5 +137,5 @@ littleEndian,

}
var getU8Encoder = (options = {}) => numberEncoderFactory({
var getU8Encoder = (config = {}) => numberEncoderFactory({
config,
name: "u8",
options,
range: [0, Number("0xff")],

@@ -145,6 +145,6 @@ set: (view, value) => view.setUint8(0, value),

});
var getU8Decoder = (options = {}) => numberDecoderFactory({
var getU8Decoder = (config = {}) => numberDecoderFactory({
config,
get: (view) => view.getUint8(0),
name: "u8",
options,
size: 1

@@ -180,7 +180,7 @@ });

}
function getOptionEncoder(item, options = {}) {
const prefix = options.prefix ?? getU8Encoder();
const fixed = options.fixed ?? false;
function getOptionEncoder(item, config = {}) {
const prefix = config.prefix ?? getU8Encoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
encode: (optionOrNullable) => {

@@ -195,7 +195,7 @@ const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable);

}
function getOptionDecoder(item, options = {}) {
const prefix = options.prefix ?? getU8Decoder();
const fixed = options.fixed ?? false;
function getOptionDecoder(item, config = {}) {
const prefix = config.prefix ?? getU8Decoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
decode: (bytes, offset = 0) => {

@@ -217,4 +217,4 @@ if (bytes.length - offset <= 0) {

}
function getOptionCodec(item, options = {}) {
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options));
function getOptionCodec(item, config = {}) {
return combineCodec(getOptionEncoder(item, config), getOptionDecoder(item, config));
}

@@ -221,0 +221,0 @@

@@ -38,7 +38,7 @@ import { fixBytes, mergeBytes, combineCodec, assertFixedSizeCodec } from '@solana/codecs-core';

}
function getOptionEncoder(item, options = {}) {
const prefix = options.prefix ?? getU8Encoder();
const fixed = options.fixed ?? false;
function getOptionEncoder(item, config = {}) {
const prefix = config.prefix ?? getU8Encoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
encode: (optionOrNullable) => {

@@ -53,7 +53,7 @@ const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable);

}
function getOptionDecoder(item, options = {}) {
const prefix = options.prefix ?? getU8Decoder();
const fixed = options.fixed ?? false;
function getOptionDecoder(item, config = {}) {
const prefix = config.prefix ?? getU8Decoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
decode: (bytes, offset = 0) => {

@@ -75,4 +75,4 @@ if (bytes.length - offset <= 0) {

}
function getOptionCodec(item, options = {}) {
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options));
function getOptionCodec(item, config = {}) {
return combineCodec(getOptionEncoder(item, config), getOptionDecoder(item, config));
}

@@ -79,0 +79,0 @@

@@ -38,7 +38,7 @@ import { fixBytes, mergeBytes, combineCodec, assertFixedSizeCodec } from '@solana/codecs-core';

}
function getOptionEncoder(item, options = {}) {
const prefix = options.prefix ?? getU8Encoder();
const fixed = options.fixed ?? false;
function getOptionEncoder(item, config = {}) {
const prefix = config.prefix ?? getU8Encoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
encode: (optionOrNullable) => {

@@ -53,7 +53,7 @@ const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable);

}
function getOptionDecoder(item, options = {}) {
const prefix = options.prefix ?? getU8Decoder();
const fixed = options.fixed ?? false;
function getOptionDecoder(item, config = {}) {
const prefix = config.prefix ?? getU8Decoder();
const fixed = config.fixed ?? false;
return {
...optionCodecHelper(item, prefix, fixed, options.description),
...optionCodecHelper(item, prefix, fixed, config.description),
decode: (bytes, offset = 0) => {

@@ -75,4 +75,4 @@ if (bytes.length - offset <= 0) {

}
function getOptionCodec(item, options = {}) {
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options));
function getOptionCodec(item, config = {}) {
return combineCodec(getOptionEncoder(item, config), getOptionDecoder(item, config));
}

@@ -79,0 +79,0 @@

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

var p=e=>({__option:"Some",value:e}),s=()=>({__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 o=t.length-r;if(o<n)throw new Error(`Codec [${e}] expected ${n} bytes, got ${o}.`)}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(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},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.options)||e.options.endian===0,t+=n?"(le)":"(be)"),{description:e.options.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 o=new DataView(D(t,r,e.size));return [e.get(o,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),o=t??e.byteLength;return e.buffer.slice(r,r+o)}var S=(e={})=>b({name:"u8",options:e,range:[0,+"0xff"],set:(n,t)=>n.setUint8(0,t),size:1}),O=(e={})=>N({get:n=>n.getUint8(0),name:"u8",options:e,size:1});function q(e,n){return f(e)?e.value:n?n():null}var v=e=>e!==null?p(e):s();function A(e){return e.reduce((n,t)=>n===null||t===null?null:n+t,0)}function w(e,n,t,r){let o=`; ${n.description}`,i=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."),o+="; fixed",i=n.fixedSize+e.fixedSize),{description:r??`option(${e.description+o})`,fixedSize:i,maxSize:A([n.maxSize,e.maxSize])}}function _(e,n={}){let t=n.prefix??S(),r=n.fixed??!1;return {...w(e,t,r,n.description),encode:o=>{let i=u(o)?o:v(o),a=t.encode(Number(f(i))),c=f(i)?e.encode(i.value):new Uint8Array;return c=r?U(c,e.fixedSize):c,z([a,c])}}}function F(e,n={}){let t=n.prefix??O(),r=n.fixed??!1;return {...w(e,t,r,n.description),decode:(o,i=0)=>{if(o.length-i<=0)return [s(),i];let a=i+(t.fixedSize??0)+(e.fixedSize??0),[c,C]=t.decode(o,i);if(i=C,c===0)return [s(),r?a:i];let[y,I]=e.decode(o,i);return i=I,[p(y),r?a:i]}}}function se(e,n={}){return x(_(e,n),F(e,n))}function h(e,n){if(!e||ArrayBuffer.isView(e))return e;let t=r=>n?h(r,n):h(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,o])=>[r,t(o)])):e}
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}
exports.getOptionCodec = se;
exports.getOptionCodec = ce;
exports.getOptionDecoder = F;

@@ -14,6 +14,6 @@ exports.getOptionEncoder = _;

exports.isSome = f;
exports.none = s;
exports.none = c;
exports.some = p;
exports.unwrapOption = q;
exports.unwrapOptionRecursively = h;
exports.unwrapOptionRecursively = w;
exports.wrapNullable = v;

@@ -20,0 +20,0 @@

@@ -1,6 +0,6 @@

import { BaseCodecOptions, Codec, Decoder, Encoder } from '@solana/codecs-core';
import { BaseCodecConfig, Codec, Decoder, Encoder } from '@solana/codecs-core';
import { NumberCodec, NumberDecoder, NumberEncoder } from '@solana/codecs-numbers';
import { Option, OptionOrNullable } from './option';
/** Defines the options for option codecs. */
export type OptionCodecOptions<TPrefix extends NumberCodec | NumberEncoder | NumberDecoder> = BaseCodecOptions & {
/** Defines the config for option codecs. */
export type OptionCodecConfig<TPrefix extends NumberCodec | NumberEncoder | NumberDecoder> = BaseCodecConfig & {
/**

@@ -25,5 +25,5 @@ * The codec to use for the boolean prefix.

* @param item - The encoder to use for the value that may be present.
* @param options - A set of options for the encoder.
* @param config - A set of config for the encoder.
*/
export declare function getOptionEncoder<T>(item: Encoder<T>, options?: OptionCodecOptions<NumberEncoder>): Encoder<OptionOrNullable<T>>;
export declare function getOptionEncoder<T>(item: Encoder<T>, config?: OptionCodecConfig<NumberEncoder>): Encoder<OptionOrNullable<T>>;
/**

@@ -33,5 +33,5 @@ * Creates a decoder for an optional value using `null` as the `None` value.

* @param item - The decoder to use for the value that may be present.
* @param options - A set of options for the decoder.
* @param config - A set of config for the decoder.
*/
export declare function getOptionDecoder<T>(item: Decoder<T>, options?: OptionCodecOptions<NumberDecoder>): Decoder<Option<T>>;
export declare function getOptionDecoder<T>(item: Decoder<T>, config?: OptionCodecConfig<NumberDecoder>): Decoder<Option<T>>;
/**

@@ -41,5 +41,5 @@ * Creates a codec for an optional value using `null` as the `None` value.

* @param item - The codec to use for the value that may be present.
* @param options - A set of options for the codec.
* @param config - A set of config for the codec.
*/
export declare function getOptionCodec<T, U extends T = T>(item: Codec<T, U>, options?: OptionCodecOptions<NumberCodec>): Codec<OptionOrNullable<T>, Option<U>>;
export declare function getOptionCodec<T, U extends T = T>(item: Codec<T, U>, config?: OptionCodecConfig<NumberCodec>): Codec<OptionOrNullable<T>, Option<U>>;
//# sourceMappingURL=option-codec.d.ts.map
{
"name": "@solana/options",
"version": "2.0.0-experimental.72efece",
"version": "2.0.0-experimental.735654a",
"description": "Managing and serializing Rust-like Option types in JavaScript",

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

"dependencies": {
"@solana/codecs-core": "2.0.0-experimental.72efece",
"@solana/codecs-numbers": "2.0.0-experimental.72efece"
"@solana/codecs-core": "2.0.0-experimental.735654a",
"@solana/codecs-numbers": "2.0.0-experimental.735654a"
},
"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",

@@ -76,4 +76,4 @@ "prettier": "^2.8",

"build-scripts": "0.0.0",
"test-config": "0.0.0",
"tsconfig": "0.0.0"
"tsconfig": "0.0.0",
"test-config": "0.0.0"
},

@@ -80,0 +80,0 @@ "bundlewatch": {

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

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