ec736f8590
i've been wanting to name a commit like this for my entire life, lol. seriously though, a lot has changed: - extracted TL-related stuff to `@mtcute/tl-utils` and `@mtcute/tl-runtime`, rewrote codegen in TS - updated to layer 134, moved to int64 identifiers - rewritten networking (mtproto), rewritten updates handling - *lots* of refactoring still a very early version though, there are a lot of improvements to be made, but at least it runs, lol also tl-reference will not be updated anytime soon because i want to rewrite it |
||
---|---|---|
.. | ||
binary | ||
data | ||
scripts | ||
tests | ||
.gitignore | ||
api-schema.json | ||
mtp-schema.json | ||
package.json | ||
raw-errors.json | ||
README.md | ||
tsconfig.json | ||
typedoc.json |
@mtcute/tl
TL schema and related utils used for MTCute.
Generated from TL layer 134 (last updated on 20.11.2021).
About
This package contains JSON schema, type declarations, binary (de-)serialization, errors, RSA keys and helper functions.
Package's major version is always TL schema layer number,
so version 42.0.0
means that this version was generated from TL layer 42.
- JSON schema, types, binary (de-)serialization and helper functions are generated directly from
.tl
files that are automatically fetched from TDesktop repository. - Errors are generated
from
errors.csv
that is automatically fetched from Telethon repository. - RSA keys info is generated based on manually extracted PEMs from Telegram for Android source code.
Contents
@mtcute/tl
TypeScript typings and type helpers generated from the schema.
By default, all types are immutable (have their fields marked as readonly
). That is because most of the time you don't
really need to modify the objects, and modifying them will only lead to confusion. However, there are still valid
use-cases for mutable TL objects, so you can use exported
tl.Mutable
type to make a given object type mutable.
tl
is exported as a namespace to allow better code insights, and to avoid cluttering global namespace and very long
import statements.
import { tl } from '@mtcute/tl'
const obj: tl.RawInputPeerChat = { _: 'inputPeerChat', chatId: 42 }
console.log(tl.isAnyInputPeer(obj)) // true
@mtcute/tl/raw-schema
JSON file describing all available TL classes, methods and unions. Can be used to write custom code generators
This very file is used to generate binary serialization and TypeScript typings for
@mtcute/tl
.
import * as tlSchema from '@mtcute/tl/raw-schema'
console.log(`Current layer: ${tlSchema.apiLayer}`)
// Current layer: 124
@mtcute/tl/binary/reader
Contains mapping used to read TL objects from binary streams.
import readerMap from '@mtcute/tl/binary/reader'
import { BinaryReader } from './binary-reader'
const reader = new BinaryReader(Buffer.from([...]))
console.log(readerMap[0x5bb8e511 /* mt_message */].call(reader))
// { _: 'mt_message', ... }
@mtcute/tl/binary/writer
Contains mapping used to write TL objects to binary streams.
import writerMap from '@mtcute/tl/binary/writer'
import { BinaryWriter } from './binary-writer'
const writer = new BinaryWriter()
writerMap[0x5bb8e511 /* mt_message */].call(writer, { ... })
console.log(writer.result())
// Buffer <11 e5 b8 5b ...>