UNPKG

@ton-community/tlb-runtime

Version:

TL‑B Runtime is a library for parsing and (de)serializing data according to TL‑B schemas

46 lines (45 loc) 1.88 kB
import { Builder, Slice, Cell, Dictionary, BitString, Address, ExternalAddress, DictionaryKeyTypes } from '@ton/core'; import { Result } from './Result'; export interface TypedCell { kind: string; } export type ParsedCell = string | number | bigint | boolean | null | unknown | BitString | Address | ExternalAddress | Dictionary<DictionaryKeyTypes, ParsedCell> | Cell | { [key: string]: ParsedCell; } | ParsedCell[] | TypedCell; export declare class TLBRuntimeError extends Error { } export declare class TLBSchemaError extends TLBRuntimeError { } export declare class TLBDataError extends TLBRuntimeError { } export interface TLBRuntimeConfig { autoText: boolean; } export declare class TLBRuntime<T extends ParsedCell = ParsedCell> { readonly schema: string; private readonly types; private readonly lastTypeName; private readonly config; private readonly tagMap; private maxSizeTag; private constructor(); static from<T extends ParsedCell = ParsedCell>(schema: string, config?: Partial<TLBRuntimeConfig>): Result<TLBRuntime<T>>; changeSchema(schema: string): Result<TLBRuntime<T>>; parseCell(data: Cell | string): ParsedCell; encodeCell(data: ParsedCell | string): Cell; private findByTag; deserialize(data: Cell | string, findByTag?: boolean): Result<T>; deserializeByTypeName(typeName: string, slice: Slice): Result<T>; serialize(data: T): Result<Builder>; serializeByTypeName(typeKind: string, data: T): Result<Builder>; private deserializeType; private deserializeConstructor; private deserializeField; private extractNumericProperty; private deserializeFieldType; private serializeType; private serializeField; private serializeFieldType; private loadBigInt; } export declare function parseTLB<T extends ParsedCell = ParsedCell>(schema: string): TLBRuntime<T>;