
Security News
Package Maintainers Call for Improvements to GitHub’s New npm Security Plan
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
@kibcode/types-generator
Advanced tools
This repository contains utilities which help developers to generate TypeScript types based on TON-specific files.
This repository contains utilities which help developers to generate TypeScript types based on TON-specific files.
.tlo
file..tlo
file.yarn add --dev @kibcode/types-generator
npm i -D @kibcode/types-generator
BinaryReader
is class which derives TypeLanguage file configuration from
.tlo
binary file. You can find an example of such file
here
.
Creating binary reader from different types of sources will append specific to this source meta information to config.
import {BinaryReader} from '@kibcode/types-generator';
const config = BinaryReader.fromFilePath('...').readConfig();
console.log(config);
import {BinaryReader} from '@kibcode/types-generator';
(async () => {
// To test fetch functionality, you could try this URL:
// https://github.com/newton-blockchain/ton/blob/master/tl/generate/scheme/ton_api.tlo?raw=true
const reader = await BinaryReader.fromFileURL('...');
console.log(reader.readConfig());
})();
To make communication with tonlib easier, this library generates types which are
based on passed .tlo
file.
As a result, it creates .ts
file with namespace, which contains another two.
The first one is responsible for carrying type names, the second one contains
combinators which are presented as interfaces.
import {writeTypes, BinaryReader} from '@kibcode/types-generator';
// Here we should define path to .tlo file.
const tloFilePath = '...';
// Read config from .tlo file.
const config = BinaryReader.fromFile(tloFilePath).readConfig();
// Write types to file.
writeTypes('types.ts', config);
// This will generate root namespace with name "MyRoot" and namespaces
// "MyTypes" and "MyCombinators" for types and combinators respectively.
writeTypes('types.ts', config, {
namespaces: {
types: 'MyTypes',
root: 'MyRoot',
combinators: 'MyCombinators',
}
});
To format TypeScript code, ESLint used. You can set your own linter
configuration by passing linterConfig
option:
writeTypes('types.ts', config, {
linterConfig: {
rules: {
'max-len': ['error', 80],
}
}
});
While formatting TypeScript code, don't forget to pass required components which are mentioned here.
Types generator uses configuration mentioned above by default. So, you could reuse it too:
import {defaultLinterConfig} from '@kibcode/types-generator';
writeTypes('types.ts', config, {
linterConfig: {
...defaultLinterConfig,
rules: {
...defaultLinterConfig.rules,
'max-len': ['error', 80]
},
}
});
Generated client represents abstract class which required such methods
as _request
and _send
to be implemented. Usually, client generation is
connected with types generation. So, it is important to see
[Generating types](#Generating types) section first.
Probably, to implement these methods, you could use Node tonlib implementation.
import {writeClient, BinaryReader} from '@kibcode/types-generator';
// Here we should define path to .tlo file.
const tloFilePath = '...';
// Read config from .tlo file.
const config = BinaryReader.fromFile(tloFilePath).readConfig();
writeClient('client.ts', config, {
// Set import source from which generator should get tonlib root namespace
// declaration.
// As a result, generated class file will contain such import:
// import {Tonlib} from './types';
typesSource: './types',
});
import {writeTypes, writeClient, BinaryReader} from '@kibcode/types-generator';
// Here we should define path to .tlo file.
const tloFilePath = '...';
// Read config from .tlo file.
const config = BinaryReader.fromFile(tloFilePath).readConfig();
const namespaces = {
root: 'MyRoot',
types: 'MyTypes',
combinators: 'MyCombinators',
};
// Write types to file.
writeTypes('types.ts', config, {namespaces});
// This will generate class "MyClass" with functions that will refer to
// types which are placed in MyRoot.MyTypes and MyRoot.MyCombinators
// namespaces.
//
// Additionally, import declaration will have this form:
// import {MyRoot} from './types';
writeClient('client.ts', config, {
typesSource: './types',
names: {
namespaces,
class: 'MyClass',
}
});
Client generator uses the same formatting flow as Types generator does. So, to learn more, follow this section.
You can find examples of generated output in output folder.
FAQs
This repository contains utilities which help developers to generate TypeScript types based on TON-specific files.
The npm package @kibcode/types-generator receives a total of 1 weekly downloads. As such, @kibcode/types-generator popularity was classified as not popular.
We found that @kibcode/types-generator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Maintainers back GitHub’s npm security overhaul but raise concerns about CI/CD workflows, enterprise support, and token management.
Product
Socket Firewall is a free tool that blocks malicious packages at install time, giving developers proactive protection against rising supply chain attacks.
Research
Socket uncovers malicious Rust crates impersonating fast_log to steal Solana and Ethereum wallet keys from source code.