npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@polyprogrammist_test/tlbgen

v1.0.17

Published

This package allows you to generate `Typescript` code for serializing and deserializing structures according to the `TLB` scheme provided.

Downloads

7

Readme

TLB Generator

This package allows you to generate Typescript code for serializing and deserializing structures according to the TLB scheme provided.

Here you can find documentation for creating TLB schemes, and more advanced article is here.

This package uses TLB-Parser to get AST of the scheme.

Installation

npm install @polyprogrammist_test/tlbgen

Usage

CLI

Create a file with TLB scheme according to the documentation. This is an example of such a file (call it example.tlb):

t$_ x:# y:(uint 5) = A;

Then do:

npx tlbgen example.tlb

It will create a file called example.tlb.ts with the following code:

export interface A {
    readonly kind: 'A';
    readonly x: number;
    readonly y: number;
}
export function loadA(slice: Slice): A {
    let x: number = slice.loadUint(32);
    let y: number = slice.loadUint(5);
    return {
        kind: 'A',
        x: x,
        y: y,
    }

}
export function storeA(a: A): (builder: Builder) => void {
    return ((builder: Builder) => {
        builder.storeUint(a.x, 32);
        builder.storeUint(a.y, 5);
    })

}

You also can set an output file with -o option: npx tlbgen -o other_file.ts example.tlb.

One of the examples where you can see various abilities of the tool is block.tlb. The generation result for it is here.

Node JS

Also you can use the tool from inside JS or TS code.

import { generateCode } from "@polyprogrammist_test/tlbgen"
generateCode('example.tlb', 'example.tlb.ts', "typescript")

Integration with ton-core

It is integrated with ton-core in a way it uses several built-in types from there.

Built-in types supported are:

  • Bool -> boolean (loaded with loadBoolean, stored with storeBit)
  • MsgAddressInt -> Address (loaded with loadAddress, stored with storeAddress)
  • MsgAddressExt -> ExternalAddress | null (loaded with loadMaybeExternalAddress, stored with storeAddress)
  • MsgAddress -> Address | ExternalAddress | null (loaded with loadAddressAny, stored with storeAddress)
  • VarUInteger -> bigint (loaded with loadVarUintBig, stored with storeVarUint)
  • VarInteger -> bigint (loaded with loadVarIntBig, stored with storeVarInt)
  • Bit -> boolean (loaded with loadBit, stored with storeBit)
  • Grams -> bigint (loaded with loadCoins, stored with storeCoins)
  • HashmapE n Value -> Dictionary<bigint, Value> (or Dictionary<number, Value> if n <= 64) (loaded with Dictionary.load, stored with storeDict)
  • HashmapAugE n Value Extra -> Dictionary<bigint, {value: Value, extra: Extra}> (or number instead of bigint if n <= 64) (loaded with Dictionary.load, stored with storeDict)

Please note that the tricky thing here with HashmapAugE is that in TLB scheme extra is stored not only with values, but in intermediate nodes as well. However Dictionary in ton-core doesn't store the intermediate nodes. That is why HashmapAugE can be correctly loaded by the generated code, but storing is incorrect.

License

This package is released under the MIT License.