Options
All
  • Public
  • Public/Protected
  • All
Menu

@metaplex-foundation/beet

Index

Other

DataEnumBeet<T, Kind>: [Kind, FixableBeet<T[Kind], any> | FixedSizeBeet<T[Kind], any>]

Turns a Record<K, Beet<V>> into a discriminated union { __kind: K, dataBeet: Beet<V> }.

Type Parameters

DataEnumKeyAsKind<T>: { [ K in DataEnumKind<T>]: { __kind: K } & T[K] }[keyof T]

Turns a Record<K, V> into a discriminated union { __kind: K, ...V }.

Type Parameters

  • T

DataEnumKind<T>: keyof T

Enum Variant Kinds

Type Parameters

  • T

Enum<T>: {} | number | T

Type Parameters

  • T

aliasesTypeMap: AliasesTypeMap = ...
  • isBeetStruct(beet: any): beet is BeetStruct<any, any>

TypeDefinition

AliasesExports: keyof __module
AliasesTypeMap: Record<AliasesTypeMapKey, SupportedTypeDefinition & { beet: AliasesExports }>
AliasesTypeMapKey: "Uint8Array"
CollectionsExports: keyof __module
CollectionsTypeMap: Record<CollectionsTypeMapKey, SupportedTypeDefinition & { beet: CollectionsExports }>
CollectionsTypeMapKey: "Array" | "FixedSizeArray" | "UniformFixedSizeArray" | "Buffer" | "FixedSizeUint8Array" | "Uint8Array"
CompositesExports: keyof __module
CompositesTypeMap: Record<CompositesTypeMapKey, SupportedTypeDefinition & { beet: CompositesExports }>
CompositesTypeMapKey: "option"
EnumsExports: keyof __module
EnumsTypeMap: Record<EnumsTypeMapKey, SupportedTypeDefinition & { beet: EnumsExports }>
EnumsTypeMapKey: "fixedScalarEnum" | "dataEnum"
NumbersExports: keyof __module
NumbersTypeMap: Record<NumbersTypeMapKey, SupportedTypeDefinition & { beet: NumbersExports }>
NumbersTypeMapKey: "u8" | "u16" | "u32" | "u64" | "u128" | "u256" | "u512" | "i8" | "i16" | "i32" | "i64" | "i128" | "i256" | "i512" | "bool"
StringExports: keyof __module
StringTypeMap: Record<StringTypeMapKey, SupportedTypeDefinition & { beet: StringExports }>
StringTypeMapKey: "string" | "fixedSizeString"
SupportedTypeDefinition: { arg?: typeof BEET_TYPE_ARG_LEN | typeof BEET_TYPE_ARG_INNER; beet: string; isFixable: boolean; pack?: string; sourcePack: string; ts: string }

Defines a type supported by beet.

property

beet is the Beet reader/writer to use for serialization

  • this could also be a function that produces it (when arg is set)
property

isFixable if true the size of structs of this type depends on the value/data they hold and needs to be fixed with a value or data NOTE: that if this is false, the struct is considered fixed size which means it has the same size no matter what value it holds

property

sourcPack the package where the definition is exported, i.e. beet or beet-solana

property

ts is the TypeScript type representing the deserialized type

property

arg specifies the type of arg to provide to create the Beet type

  • len: for fixed size arrays and strings
  • beet.Beet: an inner Beet type 'T' for composite types like Option
property

pack specifies which package is exporting the ts type if it is not built in

Type declaration

  • Optional arg?: typeof BEET_TYPE_ARG_LEN | typeof BEET_TYPE_ARG_INNER
  • beet: string
  • isFixable: boolean
  • Optional pack?: string
  • sourcePack: string
  • ts: string
TuplesExports: keyof __module
TuplesTypeMap: Record<TuplesTypeMapKey, SupportedTypeDefinition & { beet: TuplesExports }>
TuplesTypeMapKey: "FixedSizeTuple" | "Tuple"
bytes: FixableBeet<Uint8Array, Uint8Array> = uint8Array

Alias for uint8Array.

collectionsTypeMap: CollectionsTypeMap = ...

Maps collections beet exports to metadata which describes in which package it is defined as well as which TypeScript type is used to represent the deserialized value in JavaScript.

compositesTypeMap: CompositesTypeMap = ...

Maps composite beet exports to metadata which describes in which package it is defined as well as which TypeScript type is used to represent the deserialized value in JavaScript.

enumsTypeMap: EnumsTypeMap = ...

Maps composite beet exports to metadata which describes in which package it is defined as well as which TypeScript type is used to represent the deserialized value in JavaScript.

numbersTypeMap: NumbersTypeMap = ...

Maps primitive beet exports to metadata which describes in which package it is defined as well as which TypeScript type is used to represent the deserialized value in JavaScript.

stringTypeMap: StringTypeMap = ...

Maps string beet exports to metadata which describes in which package it is defined as well as which TypeScript type is used to represent the deserialized value in JavaScript.

supportedTypeMap: Record<BeetTypeMapKey, SupportedTypeDefinition & { beet: BeetExports }> = ...

Maps all Beet de/serializers to metadata which describes in which package it is defined as well as which TypeScript type is used to represent the deserialized value in JavaScript.

tuplesTypeMap: TuplesTypeMap = ...

Maps collections beet exports to metadata which describes in which package it is defined as well as which TypeScript type is used to represent the deserialized value in JavaScript.

beet

Beet<T, V>: FixedSizeBeet<T, V> | FixableBeet<T, V>

Type Parameters

  • T

  • V = Partial<T>

BeetBase: { description: string }

Base Beet type.

Type declaration

  • description: string

    Describes the type of data that is de/serialized and serves for debugging and diagnostics only.

BeetField<T, V>: [keyof T & string, FixedSizeBeet<T[keyof T], V> | FixableBeet<T[keyof T], V>]

Specifies a field that is part of the type {@link T} along with its De/Serializer.

Type Parameters

  • T

    the type of which the field is a member

  • V = Partial<T>

BeetReadWrite<T, V>: { byteSize: number; read: any; write: any }

Specifies the read/write methods that a beet may implement.

Type Parameters

  • T

  • V = Partial<T>

Type declaration

  • byteSize: number

    Number of bytes that are used to store the value in a {@link Buffer}

  • read:function
    • read(buf: Buffer, offset: number): T
    • Reads the data in the provided buffer and deserializes it into a value of type {@link T}.

      Parameters

      • buf: Buffer

        containing the data to deserialize

      • offset: number

        at which to start reading from the buffer

      Returns T

      deserialized instance of type {@link T}.

  • write:function
    • write(buf: Buffer, offset: number, value: T | V): void
    • Writes the value of type {@link T} to the provided buffer.

      Parameters

      • buf: Buffer

        the buffer to write the serialized value to

      • offset: number

        at which to start writing into the buffer

      • value: T | V

        to write

      Returns void

ElementCollectionBeet: { elementByteSize: number; lenPrefixByteSize: number; length: number }

Implemented by ElementCollectionFixedSizeBeets to expose information about collection elements and collection size.

Type declaration

  • elementByteSize: number

    For arrays and strings this indicates the byte size of each element.

  • lenPrefixByteSize: number

    For arrays and strings this indicates the byte size of the number that indicates its length.

    Thus the size of each element for arrays is (this.byteSize - lenPrefixSize) / elementCount

  • length: number

    For arrays and strings this indicates the amount of elements/chars.

ElementCollectionFixedSizeBeet<T, V>: BeetBase & BeetReadWrite<T, V> & ElementCollectionBeet

Beet for Collections

Type Parameters

  • T

  • V = Partial<T>

FixableBeet<T, V>: BeetBase & { toFixedFromData: any; toFixedFromValue: any }

Template for De/Serializer which has a dynamic size, meaning its Buffer size when serialized changes depending on the data it contains.

It is fixable in the sense that a FixedSizeBeet can be derived from it by providing either the value or serialized data for the particular instance.

Type Parameters

  • T

    is the data type which is being de/serialized

  • V = Partial<T>

    is the value type passed to the write which includes all properties needed to produce {@link T}, defaults to Partial<T>

FixedBeetField<T>: [keyof T, FixedSizeBeet<T[keyof T]>]

Specifies a field that is part of the type {@link T} along with its De/Serializer.

Type Parameters

  • T

    the type of which the field is a member

FixedSizeBeet<T, V>: ScalarFixedSizeBeet<T, V> | ElementCollectionFixedSizeBeet<T, V>

Template for De/Serializer which is of fixed size, meaning its Buffer size when serialized doesn't change depending on the data it contains.

Type Parameters

  • T

    is the data type which is being de/serialized

  • V = Partial<T>

    is the value type passed to the write which includes all properties needed to produce {@link T}, defaults to Partial<T>

ScalarFixedSizeBeet<T, V>: BeetBase & BeetReadWrite<T, V>

Scalar Beet

Type Parameters

  • T

  • V = Partial<T>

bignum: number | BN

Represents a number that can be larger than the builtin Integer type. It is backed by BN for large numbers.

  • Converts the provided beet into a {@link FixedBeet} unless it already is. The sizes for FixableBeets are determined from the provided data.

    Type Parameters

    • T

    • V = Partial<T>

    Parameters

    • beet: Beet<T, V>

      to convert

    • buf: Buffer

      containing serialized data that the fixed beet needs to process

    • offset: number

      at which the data for the beet starts

    Returns ScalarFixedSizeBeet<T, V> | ScalarFixedSizeBeet<T, Partial<T>>

  • Converts the provided beet into a {@link FixedBeet} unless it already is. The sizes for FixableBeets are determined from the provided value.

    Type Parameters

    • T

    • V = Partial<T>

    Parameters

    • beet: Beet<T, V>

      to convert

    • val: V

      value that the fixed beet needs to process

    Returns ScalarFixedSizeBeet<T, V> | ScalarFixedSizeBeet<T, Partial<T>>

beet/collection

uint8Array: FixableBeet<Uint8Array, Uint8Array> = ...

A De/Serializer for {@link Uint8Array}s that just copies/reads the array bytes to/from the provided buffer.

utf8String: FixableBeet<string, string> = ...

De/Serializes a UTF8 string of any size.

  • Wraps an array De/Serializer with with elements of type {@link T} which do not all have the same size.

    Type Parameters

    • T

      type of elements held in the array

    • V = Partial<T>

    Parameters

    • element: Beet<T, V>

      the De/Serializer for the element types

    Returns FixableBeet<T[], V[]>

  • De/Serializes an array with a specific number of elements of type {@link T} which do not all have the same size.

    Type Parameters

    • T

      type of elements held in the array

    • V = Partial<T>

    Parameters

    • elements: FixedSizeBeet<T, V>[]

      the De/Serializers for the element types

    • elementsByteSize: number

      size of all elements in the array combined

    Returns FixedSizeBeet<T[], V[]>

  • A De/Serializer for raw {@link Buffer}s that just copies/reads the buffer bytes to/from the provided buffer.

    Parameters

    • bytes: number

      the byte size of the buffer to de/serialize

    Returns FixedSizeBeet<Buffer>

  • De/Serializes a tuple with all fixed size tuple elements . Since each tuple element can be of a different type not much type safety can be provided here.

    Type Parameters

    • T extends any[]

    Parameters

    • elements: FixedSizeBeet<any, Partial<any>>[]

      the De/Serializer for each tuple element type

    Returns FixedSizeBeet<any>

  • fixedSizeUint8Array(len: number, lenPrefix?: boolean): FixedSizeBeet<Uint8Array>
  • A De/Serializer for {@link Uint8Array}s of known size that just copies/reads the array bytes to/from the provided buffer.

    Parameters

    • len: number
    • lenPrefix: boolean = false

    Returns FixedSizeBeet<Uint8Array>

  • fixedSizeUtf8String(stringByteLength: number): FixedSizeBeet<string, string>
  • De/Serializes a UTF8 string of a particular size.

    Parameters

    • stringByteLength: number

      the number of bytes of the string

    Returns FixedSizeBeet<string, string>

  • De/Serializes a tuple which contains some non-fixed size tuple elements.

    Since each tuple element can be of a different type not much type safety can be provided here.

    Type Parameters

    • T extends any[]

    Parameters

    Returns FixableBeet<T>

  • De/Serializes an array with a specific number of elements of type {@link T} which all have the same size.

    Type Parameters

    • T

      type of elements held in the array

    • V = Partial<T>

    Parameters

    • element: FixedSizeBeet<T, V>

      the De/Serializer for the element type

    • len: number

      the number of elements in the array

    • lenPrefix: boolean = false

      if true a 4 byte number indicating the size of the array will be included before serialized array data

    Returns ElementCollectionBeet & FixedSizeBeet<T[], V[]>

beet/composite

UniformDataEnum<Kind, Data>: { data: Data; kind: Kind & number }

Represents an Enum type which contains fixed size data and whose data is uniform across all variants.

Type Parameters

  • Kind

    the enum variant, i.e. Color.Red

  • Data

    the data value, i.e. '#f00'

Type declaration

  • data: Data
  • kind: Kind & number
  • De/Serializes an Option of type {@link T} represented by COption.

    The de/serialized type is prefixed with 1 if the inner value is present and with 0 if not. This matches the COption type borsh representation.

    Type Parameters

    • T

      inner option type

    • V = T

    Parameters

    • inner: Beet<T, V>

      the De/Serializer for the inner type

    Returns FixableBeet<COption<T>>

  • De/Serializes Some case of an Option of type {@link T} represented by COption.

    The de/serialized type is prefixed with 1. This matches the COption::Some type borsh representation.

    Type Parameters

    • T

      inner option type

    Parameters

    • inner: FixedSizeBeet<T, Partial<T>>

      the De/Serializer for the inner type

    Returns FixedSizeBeet<COption<T>>

beet/enum

  • dataEnum<T, Key>(variants: DataEnumBeet<T, Key>[]): { description: string; toFixedFromData: any; toFixedFromValue: any }
  • De/serializes Data Enums. They are represented as a discriminated unions in TypeScript.

    NOTE: only structs, i.e. BeetArgsStruct and FixableBeetArgsStruct are supported as the data of each enum variant.

    Example

    type Simple = {
    First: { n1: number }
    Second: { n2: number }
    }

    const beet = dataEnum<Simple>([
    ['First', new BeetArgsStruct<Simple['First']>([['n1', u32]])],
    ['Second', new BeetArgsStruct<Simple['Second']>([['n2', u32]])],
    ])

    Type Parameters

    • T

    • Key extends string | number | symbol = keyof T

    Parameters

    Returns { description: string; toFixedFromData: any; toFixedFromValue: any }

    • description: string
    • toFixedFromData:function
      • toFixedFromData(buf: Buffer, offset: number): FixedSizeBeet<EnumDataVariant<Key, T[Key]>, Partial<EnumDataVariant<Key, T[Key]>>>
    • toFixedFromValue:function
      • toFixedFromValue(val: any): FixedSizeBeet<EnumDataVariant<Key, T[Key]>, Partial<EnumDataVariant<Key, T[Key]>>>
  • De/serializer for enums with up to 255 less variants which have no data.

    Type Parameters

    • T

    Parameters

    • enumType: Enum<T>

      type of enum to process, i.e. Color or Direction

    Returns FixedSizeBeet<Enum<T>, Enum<T>>

  • De/Serializes an Enum that contains a type of data, i.e. a {@link Struct}. The main difference to a Rust enum is that the type of data has to be the same for all enum variants.

    Type Parameters

    • Kind

    • Data

    Parameters

    • inner: FixedSizeBeet<Data, Partial<Data>>

      the De/Serializer for the data type

    Returns FixedSizeBeet<UniformDataEnum<Kind, Data>>

beet/option

COption<T>: T | null

Represents the Rust Option type {@link T}.

Type Parameters

  • T

    inner option type

  • De/Serializes None case of an Option of type {@link T} represented by COption.

    The de/serialized type is prefixed with 0. This matches the COption::None type borsh representation.

    Type Parameters

    • T

      inner option type

    Parameters

    • description: string

    Returns FixedSizeBeet<COption<T>>

beet/primitive

bool: FixedSizeBeet<boolean> = ...

De/Serializer booleans aka bool.

i128: FixedSizeBeet<bignum> = ...

De/Serializer for 128-bit signed integers aka i128 which serializes to a JavaScript BigNum via BN.

i16: FixedSizeBeet<number> = ...

De/Serializer 16-bit signed integers aka i16.

i256: FixedSizeBeet<bignum> = ...

De/Serializer for 256-bit signed integers aka i256 which serializes to a JavaScript BigNum via BN.

i32: FixedSizeBeet<number> = ...

De/Serializer 32-bit signed integers aka i32.

i512: FixedSizeBeet<bignum> = ...

De/Serializer for 512-bit signed integers aka i512 which serializes to a JavaScript BigNum via BN.

i64: FixedSizeBeet<bignum> = ...

De/Serializer for 64-bit signed integers aka i64 which serializes to a JavaScript BigNum via BN.

i8: FixedSizeBeet<number> = ...

De/Serializer 8-bit signed integers aka i8.

u128: FixedSizeBeet<bignum> = ...

De/Serializer for 128-bit unsigned integers aka u128 which serializes to a JavaScript BigNum via BN.

u16: FixedSizeBeet<number> = ...

De/Serializer 16-bit unsigned integers aka u16.

u256: FixedSizeBeet<bignum> = ...

De/Serializer for 256-bit unsigned integers aka u256 which serializes to a JavaScript BigNum via BN.

u32: FixedSizeBeet<number> = ...

De/Serializer for 32-bit unsigned integers aka u32.

u512: FixedSizeBeet<bignum> = ...

De/Serializer for 512-bit unsigned integers aka u512 which serializes to a JavaScript BigNum via BN.

u64: FixedSizeBeet<bignum> = ...

De/Serializer for 64-bit unsigned integers aka u64 which serializes to a JavaScript BigNum via BN.

u8: FixedSizeBeet<number> = ...

De/Serializer for 8-bit unsigned integers aka u8.

Generated using TypeDoc