@solana/options
Advanced tools
Comparing version 2.0.0-experimental.5586a1b to 2.0.0-experimental.782d1ea
@@ -0,1 +1,4 @@ | ||
import { fixBytes, mergeBytes, combineCodec, assertFixedSizeCodec } from '@solana/codecs-core'; | ||
import { getU8Encoder, getU8Decoder } from '@solana/codecs-numbers'; | ||
// src/option.ts | ||
@@ -16,2 +19,60 @@ var some = (value) => ({ __option: "Some", value }); | ||
// src/option-codec.ts | ||
function sumCodecSizes(sizes) { | ||
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0); | ||
} | ||
function optionCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
if (fixed) { | ||
assertFixedSizeCodec(item, "Fixed options can only be used with fixed-size codecs."); | ||
assertFixedSizeCodec(prefix, "Fixed options can only be used with fixed-size prefix."); | ||
descriptionSuffix += "; fixed"; | ||
fixedSize = prefix.fixedSize + item.fixedSize; | ||
} | ||
return { | ||
description: description ?? `option(${item.description + descriptionSuffix})`, | ||
fixedSize, | ||
maxSize: sumCodecSizes([prefix.maxSize, item.maxSize]) | ||
}; | ||
} | ||
function getOptionEncoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Encoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
encode: (optionOrNullable) => { | ||
const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable); | ||
const prefixByte = prefix.encode(Number(isSome(option))); | ||
let itemBytes = isSome(option) ? item.encode(option.value) : new Uint8Array(); | ||
itemBytes = fixed ? fixBytes(itemBytes, item.fixedSize) : itemBytes; | ||
return mergeBytes([prefixByte, itemBytes]); | ||
} | ||
}; | ||
} | ||
function getOptionDecoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Decoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.length - offset <= 0) { | ||
return [none(), offset]; | ||
} | ||
const fixedOffset = offset + (prefix.fixedSize ?? 0) + (item.fixedSize ?? 0); | ||
const [isSome2, prefixOffset] = prefix.decode(bytes, offset); | ||
offset = prefixOffset; | ||
if (isSome2 === 0) { | ||
return [none(), fixed ? fixedOffset : offset]; | ||
} | ||
const [value, newOffset] = item.decode(bytes, offset); | ||
offset = newOffset; | ||
return [some(value), fixed ? fixedOffset : offset]; | ||
} | ||
}; | ||
} | ||
function getOptionCodec(item, options = {}) { | ||
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options)); | ||
} | ||
// src/unwrap-option-recursively.ts | ||
@@ -37,4 +98,4 @@ function unwrapOptionRecursively(input, fallback) { | ||
export { isNone, isOption, isSome, none, some, unwrapOption, unwrapOptionRecursively, wrapNullable }; | ||
export { getOptionCodec, getOptionDecoder, getOptionEncoder, isNone, isOption, isSome, none, some, unwrapOption, unwrapOptionRecursively, wrapNullable }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.browser.js.map |
@@ -12,2 +12,140 @@ this.globalThis = this.globalThis || {}; | ||
// ../codecs-core/dist/index.browser.js | ||
function assertByteArrayIsNotEmptyForCodec(codecDescription, bytes, offset = 0) { | ||
if (bytes.length - offset <= 0) { | ||
throw new Error(`Codec [${codecDescription}] cannot decode empty byte arrays.`); | ||
} | ||
} | ||
function assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset = 0) { | ||
const bytesLength = bytes.length - offset; | ||
if (bytesLength < expected) { | ||
throw new Error(`Codec [${codecDescription}] expected ${expected} bytes, got ${bytesLength}.`); | ||
} | ||
} | ||
function assertFixedSizeCodec(data, message) { | ||
if (data.fixedSize === null) { | ||
throw new Error(message ?? "Expected a fixed-size codec, got a variable-size one."); | ||
} | ||
} | ||
var mergeBytes = (byteArrays) => { | ||
const nonEmptyByteArrays = byteArrays.filter((arr) => arr.length); | ||
if (nonEmptyByteArrays.length === 0) { | ||
return byteArrays.length ? byteArrays[0] : new Uint8Array(); | ||
} | ||
if (nonEmptyByteArrays.length === 1) { | ||
return nonEmptyByteArrays[0]; | ||
} | ||
const totalLength = nonEmptyByteArrays.reduce((total, arr) => total + arr.length, 0); | ||
const result = new Uint8Array(totalLength); | ||
let offset = 0; | ||
nonEmptyByteArrays.forEach((arr) => { | ||
result.set(arr, offset); | ||
offset += arr.length; | ||
}); | ||
return result; | ||
}; | ||
var padBytes = (bytes, length) => { | ||
if (bytes.length >= length) | ||
return bytes; | ||
const paddedBytes = new Uint8Array(length).fill(0); | ||
paddedBytes.set(bytes); | ||
return paddedBytes; | ||
}; | ||
var fixBytes = (bytes, length) => padBytes(bytes.length <= length ? bytes : bytes.slice(0, length), length); | ||
function combineCodec(encoder, decoder, description) { | ||
if (encoder.fixedSize !== decoder.fixedSize) { | ||
throw new Error( | ||
`Encoder and decoder must have the same fixed size, got [${encoder.fixedSize}] and [${decoder.fixedSize}].` | ||
); | ||
} | ||
if (encoder.maxSize !== decoder.maxSize) { | ||
throw new Error( | ||
`Encoder and decoder must have the same max size, got [${encoder.maxSize}] and [${decoder.maxSize}].` | ||
); | ||
} | ||
if (description === void 0 && encoder.description !== decoder.description) { | ||
throw new Error( | ||
`Encoder and decoder must have the same description, got [${encoder.description}] and [${decoder.description}]. Pass a custom description as a third argument if you want to override the description and bypass this error.` | ||
); | ||
} | ||
return { | ||
decode: decoder.decode, | ||
description: description ?? encoder.description, | ||
encode: encoder.encode, | ||
fixedSize: encoder.fixedSize, | ||
maxSize: encoder.maxSize | ||
}; | ||
} | ||
// ../codecs-numbers/dist/index.browser.js | ||
function assertNumberIsBetweenForCodec(codecDescription, min, max, value) { | ||
if (value < min || value > max) { | ||
throw new Error( | ||
`Codec [${codecDescription}] expected number to be in the range [${min}, ${max}], got ${value}.` | ||
); | ||
} | ||
} | ||
function sharedNumberFactory(input) { | ||
let littleEndian; | ||
let defaultDescription = input.name; | ||
if (input.size > 1) { | ||
littleEndian = !("endian" in input.options) || input.options.endian === 0; | ||
defaultDescription += littleEndian ? "(le)" : "(be)"; | ||
} | ||
return { | ||
description: input.options.description ?? defaultDescription, | ||
fixedSize: input.size, | ||
littleEndian, | ||
maxSize: input.size | ||
}; | ||
} | ||
function numberEncoderFactory(input) { | ||
const codecData = sharedNumberFactory(input); | ||
return { | ||
description: codecData.description, | ||
encode(value) { | ||
if (input.range) { | ||
assertNumberIsBetweenForCodec(input.name, input.range[0], input.range[1], value); | ||
} | ||
const arrayBuffer = new ArrayBuffer(input.size); | ||
input.set(new DataView(arrayBuffer), value, codecData.littleEndian); | ||
return new Uint8Array(arrayBuffer); | ||
}, | ||
fixedSize: codecData.fixedSize, | ||
maxSize: codecData.maxSize | ||
}; | ||
} | ||
function numberDecoderFactory(input) { | ||
const codecData = sharedNumberFactory(input); | ||
return { | ||
decode(bytes, offset = 0) { | ||
assertByteArrayIsNotEmptyForCodec(codecData.description, bytes, offset); | ||
assertByteArrayHasEnoughBytesForCodec(codecData.description, input.size, bytes, offset); | ||
const view = new DataView(toArrayBuffer(bytes, offset, input.size)); | ||
return [input.get(view, codecData.littleEndian), offset + input.size]; | ||
}, | ||
description: codecData.description, | ||
fixedSize: codecData.fixedSize, | ||
maxSize: codecData.maxSize | ||
}; | ||
} | ||
function toArrayBuffer(bytes, offset, length) { | ||
const bytesOffset = bytes.byteOffset + (offset ?? 0); | ||
const bytesLength = length ?? bytes.byteLength; | ||
return bytes.buffer.slice(bytesOffset, bytesOffset + bytesLength); | ||
} | ||
var getU8Encoder = (options = {}) => numberEncoderFactory({ | ||
name: "u8", | ||
options, | ||
range: [0, Number("0xff")], | ||
set: (view, value) => view.setUint8(0, value), | ||
size: 1 | ||
}); | ||
var getU8Decoder = (options = {}) => numberDecoderFactory({ | ||
get: (view) => view.getUint8(0), | ||
name: "u8", | ||
options, | ||
size: 1 | ||
}); | ||
// src/unwrap-option.ts | ||
@@ -21,2 +159,60 @@ function unwrapOption(option, fallback) { | ||
// src/option-codec.ts | ||
function sumCodecSizes(sizes) { | ||
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0); | ||
} | ||
function optionCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
if (fixed) { | ||
assertFixedSizeCodec(item, "Fixed options can only be used with fixed-size codecs."); | ||
assertFixedSizeCodec(prefix, "Fixed options can only be used with fixed-size prefix."); | ||
descriptionSuffix += "; fixed"; | ||
fixedSize = prefix.fixedSize + item.fixedSize; | ||
} | ||
return { | ||
description: description ?? `option(${item.description + descriptionSuffix})`, | ||
fixedSize, | ||
maxSize: sumCodecSizes([prefix.maxSize, item.maxSize]) | ||
}; | ||
} | ||
function getOptionEncoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Encoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
encode: (optionOrNullable) => { | ||
const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable); | ||
const prefixByte = prefix.encode(Number(isSome(option))); | ||
let itemBytes = isSome(option) ? item.encode(option.value) : new Uint8Array(); | ||
itemBytes = fixed ? fixBytes(itemBytes, item.fixedSize) : itemBytes; | ||
return mergeBytes([prefixByte, itemBytes]); | ||
} | ||
}; | ||
} | ||
function getOptionDecoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Decoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.length - offset <= 0) { | ||
return [none(), offset]; | ||
} | ||
const fixedOffset = offset + (prefix.fixedSize ?? 0) + (item.fixedSize ?? 0); | ||
const [isSome2, prefixOffset] = prefix.decode(bytes, offset); | ||
offset = prefixOffset; | ||
if (isSome2 === 0) { | ||
return [none(), fixed ? fixedOffset : offset]; | ||
} | ||
const [value, newOffset] = item.decode(bytes, offset); | ||
offset = newOffset; | ||
return [some(value), fixed ? fixedOffset : offset]; | ||
} | ||
}; | ||
} | ||
function getOptionCodec(item, options = {}) { | ||
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options)); | ||
} | ||
// src/unwrap-option-recursively.ts | ||
@@ -42,2 +238,5 @@ function unwrapOptionRecursively(input, fallback) { | ||
exports.getOptionCodec = getOptionCodec; | ||
exports.getOptionDecoder = getOptionDecoder; | ||
exports.getOptionEncoder = getOptionEncoder; | ||
exports.isNone = isNone; | ||
@@ -44,0 +243,0 @@ exports.isOption = isOption; |
@@ -0,1 +1,4 @@ | ||
import { fixBytes, mergeBytes, combineCodec, assertFixedSizeCodec } from '@solana/codecs-core'; | ||
import { getU8Encoder, getU8Decoder } from '@solana/codecs-numbers'; | ||
// src/option.ts | ||
@@ -16,2 +19,60 @@ var some = (value) => ({ __option: "Some", value }); | ||
// src/option-codec.ts | ||
function sumCodecSizes(sizes) { | ||
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0); | ||
} | ||
function optionCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
if (fixed) { | ||
assertFixedSizeCodec(item, "Fixed options can only be used with fixed-size codecs."); | ||
assertFixedSizeCodec(prefix, "Fixed options can only be used with fixed-size prefix."); | ||
descriptionSuffix += "; fixed"; | ||
fixedSize = prefix.fixedSize + item.fixedSize; | ||
} | ||
return { | ||
description: description ?? `option(${item.description + descriptionSuffix})`, | ||
fixedSize, | ||
maxSize: sumCodecSizes([prefix.maxSize, item.maxSize]) | ||
}; | ||
} | ||
function getOptionEncoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Encoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
encode: (optionOrNullable) => { | ||
const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable); | ||
const prefixByte = prefix.encode(Number(isSome(option))); | ||
let itemBytes = isSome(option) ? item.encode(option.value) : new Uint8Array(); | ||
itemBytes = fixed ? fixBytes(itemBytes, item.fixedSize) : itemBytes; | ||
return mergeBytes([prefixByte, itemBytes]); | ||
} | ||
}; | ||
} | ||
function getOptionDecoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Decoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.length - offset <= 0) { | ||
return [none(), offset]; | ||
} | ||
const fixedOffset = offset + (prefix.fixedSize ?? 0) + (item.fixedSize ?? 0); | ||
const [isSome2, prefixOffset] = prefix.decode(bytes, offset); | ||
offset = prefixOffset; | ||
if (isSome2 === 0) { | ||
return [none(), fixed ? fixedOffset : offset]; | ||
} | ||
const [value, newOffset] = item.decode(bytes, offset); | ||
offset = newOffset; | ||
return [some(value), fixed ? fixedOffset : offset]; | ||
} | ||
}; | ||
} | ||
function getOptionCodec(item, options = {}) { | ||
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options)); | ||
} | ||
// src/unwrap-option-recursively.ts | ||
@@ -37,4 +98,4 @@ function unwrapOptionRecursively(input, fallback) { | ||
export { isNone, isOption, isSome, none, some, unwrapOption, unwrapOptionRecursively, wrapNullable }; | ||
export { getOptionCodec, getOptionDecoder, getOptionEncoder, isNone, isOption, isSome, none, some, unwrapOption, unwrapOptionRecursively, wrapNullable }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.native.js.map |
@@ -0,1 +1,4 @@ | ||
import { fixBytes, mergeBytes, combineCodec, assertFixedSizeCodec } from '@solana/codecs-core'; | ||
import { getU8Encoder, getU8Decoder } from '@solana/codecs-numbers'; | ||
// src/option.ts | ||
@@ -16,2 +19,60 @@ var some = (value) => ({ __option: "Some", value }); | ||
// src/option-codec.ts | ||
function sumCodecSizes(sizes) { | ||
return sizes.reduce((all, size) => all === null || size === null ? null : all + size, 0); | ||
} | ||
function optionCodecHelper(item, prefix, fixed, description) { | ||
let descriptionSuffix = `; ${prefix.description}`; | ||
let fixedSize = item.fixedSize === 0 ? prefix.fixedSize : null; | ||
if (fixed) { | ||
assertFixedSizeCodec(item, "Fixed options can only be used with fixed-size codecs."); | ||
assertFixedSizeCodec(prefix, "Fixed options can only be used with fixed-size prefix."); | ||
descriptionSuffix += "; fixed"; | ||
fixedSize = prefix.fixedSize + item.fixedSize; | ||
} | ||
return { | ||
description: description ?? `option(${item.description + descriptionSuffix})`, | ||
fixedSize, | ||
maxSize: sumCodecSizes([prefix.maxSize, item.maxSize]) | ||
}; | ||
} | ||
function getOptionEncoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Encoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
encode: (optionOrNullable) => { | ||
const option = isOption(optionOrNullable) ? optionOrNullable : wrapNullable(optionOrNullable); | ||
const prefixByte = prefix.encode(Number(isSome(option))); | ||
let itemBytes = isSome(option) ? item.encode(option.value) : new Uint8Array(); | ||
itemBytes = fixed ? fixBytes(itemBytes, item.fixedSize) : itemBytes; | ||
return mergeBytes([prefixByte, itemBytes]); | ||
} | ||
}; | ||
} | ||
function getOptionDecoder(item, options = {}) { | ||
const prefix = options.prefix ?? getU8Decoder(); | ||
const fixed = options.fixed ?? false; | ||
return { | ||
...optionCodecHelper(item, prefix, fixed, options.description), | ||
decode: (bytes, offset = 0) => { | ||
if (bytes.length - offset <= 0) { | ||
return [none(), offset]; | ||
} | ||
const fixedOffset = offset + (prefix.fixedSize ?? 0) + (item.fixedSize ?? 0); | ||
const [isSome2, prefixOffset] = prefix.decode(bytes, offset); | ||
offset = prefixOffset; | ||
if (isSome2 === 0) { | ||
return [none(), fixed ? fixedOffset : offset]; | ||
} | ||
const [value, newOffset] = item.decode(bytes, offset); | ||
offset = newOffset; | ||
return [some(value), fixed ? fixedOffset : offset]; | ||
} | ||
}; | ||
} | ||
function getOptionCodec(item, options = {}) { | ||
return combineCodec(getOptionEncoder(item, options), getOptionDecoder(item, options)); | ||
} | ||
// src/unwrap-option-recursively.ts | ||
@@ -37,4 +98,4 @@ function unwrapOptionRecursively(input, fallback) { | ||
export { isNone, isOption, isSome, none, some, unwrapOption, unwrapOptionRecursively, wrapNullable }; | ||
export { getOptionCodec, getOptionDecoder, getOptionEncoder, isNone, isOption, isSome, none, some, unwrapOption, unwrapOptionRecursively, wrapNullable }; | ||
//# sourceMappingURL=out.js.map | ||
//# sourceMappingURL=index.node.js.map |
@@ -5,12 +5,15 @@ this.globalThis = this.globalThis || {}; | ||
var i=n=>({__option:"Some",value:n}),T=()=>({__option:"None"}),a=n=>!!(n&&typeof n=="object"&&"__option"in n&&(n.__option==="Some"&&"value"in n||n.__option==="None")),t=n=>n.__option==="Some",l=n=>n.__option==="None";function x(n,o){return t(n)?n.value:o?o():null}var d=n=>n!==null?i(n):T();function s(n,o){if(!n||ArrayBuffer.isView(n))return n;let p=e=>o?s(e,o):s(e);return a(n)?t(n)?p(n.value):o?o():null:Array.isArray(n)?n.map(p):typeof n=="object"?Object.fromEntries(Object.entries(n).map(([e,U])=>[e,p(U)])):n} | ||
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} | ||
exports.isNone = l; | ||
exports.isOption = a; | ||
exports.isSome = t; | ||
exports.none = T; | ||
exports.some = i; | ||
exports.unwrapOption = x; | ||
exports.unwrapOptionRecursively = s; | ||
exports.wrapNullable = d; | ||
exports.getOptionCodec = se; | ||
exports.getOptionDecoder = F; | ||
exports.getOptionEncoder = _; | ||
exports.isNone = L; | ||
exports.isOption = u; | ||
exports.isSome = f; | ||
exports.none = s; | ||
exports.some = p; | ||
exports.unwrapOption = q; | ||
exports.unwrapOptionRecursively = h; | ||
exports.wrapNullable = v; | ||
@@ -17,0 +20,0 @@ return exports; |
export * from './option'; | ||
export * from './option-codec'; | ||
export * from './unwrap-option'; | ||
export * from './unwrap-option-recursively'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@solana/options", | ||
"version": "2.0.0-experimental.5586a1b", | ||
"version": "2.0.0-experimental.782d1ea", | ||
"description": "Managing and serializing Rust-like Option types in JavaScript", | ||
@@ -52,4 +52,4 @@ "exports": { | ||
"dependencies": { | ||
"@solana/codecs-core": "2.0.0-experimental.5586a1b", | ||
"@solana/codecs-numbers": "2.0.0-experimental.5586a1b" | ||
"@solana/codecs-core": "2.0.0-experimental.782d1ea", | ||
"@solana/codecs-numbers": "2.0.0-experimental.782d1ea" | ||
}, | ||
@@ -56,0 +56,0 @@ "devDependencies": { |
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
142358
27
1008
25
+ Added@solana/codecs-core@2.0.0-experimental.782d1ea(transitive)
+ Added@solana/codecs-numbers@2.0.0-experimental.782d1ea(transitive)
- Removed@solana/codecs-core@2.0.0-experimental.5586a1b(transitive)
- Removed@solana/codecs-numbers@2.0.0-experimental.5586a1b(transitive)