mtcute/packages/tl
Alina Tumanova f5976a2d74
ESM + end-to-end tests (#11)
* feat: moved tl-runtime to esm and native ArrayBuffers

* feat: migration to esm

* fix(core): web-related fixes

* test: finally, some good fucking e2e

* chore: fixed linters etc

* ci: added e2e to ci

* build(tl): fixed gen-code on node 20

* fix: codegen Uint8Array, not Buffer

never `git reset --hard` kids

* build: only do type-aware linting for `packages/*`

* build: ignore no-unresolved in ci for e2e

* fix: node 16 doesn't have subtle crypto apparently?

* fix(tests): use Uint8Array

for gods sake please can i just merge this already

* ci: don't parallel tasks in ci

because machines are utter garbage and it may just randomly break

* ci: pass secrets to e2e tests

* ci: separate cli command for ci

apparently im retarded

* fix: run codegen in e2e

im actually retarded

* ci: more fixes for e2e

* ci: debugging stuff

* ci: still debugging

* ci: hopefully fix ci???
2023-10-16 19:23:53 +03:00
..
binary ESM + end-to-end tests (#11) 2023-10-16 19:23:53 +03:00
data feat: more stories-related stuff 2023-10-04 20:50:57 +03:00
scripts ESM + end-to-end tests (#11) 2023-10-16 19:23:53 +03:00
tests ESM + end-to-end tests (#11) 2023-10-16 19:23:53 +03:00
.gitignore feat(tl): generate diff file for simpler update flow 2022-10-30 18:38:31 +03:00
api-schema.json feat: more stories-related stuff 2023-10-04 20:50:57 +03:00
mtp-schema.json fix: rebase fixes 2023-07-24 00:14:37 +03:00
package.json ESM + end-to-end tests (#11) 2023-10-16 19:23:53 +03:00
raw-errors.json refactor: reworked errors codegen 2023-09-06 23:54:51 +03:00
README.md feat: stories and boosts 2023-10-04 19:26:21 +03:00
tsconfig.json feat(tl): updated to 164 layer 2023-09-24 20:22:09 +03:00

@mtcute/tl

TL schema and related utils used for mtcute.

Generated from TL layer 165 (last updated on 04.10.2023).

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

Documentation

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.

MTProto schema is available in namespace mtp, also exported by this package.

import { tl } from '@mtcute/tl'
const obj: tl.RawInputPeerChat = { _: 'inputPeerChat', chatId: 42 }
console.log(tl.isAnyInputPeer(obj)) // true

RPC errors are also exposed in this package in tl.errors namespace:

import { tl } from '@mtcute/tl'
try {
    await client.call(...)
} catch (e) {
    if (e instanceof tl.errors.ChatInvalidError) {
        console.log('invalid chat')
    } else throw e
}

@mtcute/tl/api-schema

Documentation

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

Documentation

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

Documentation

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 ...>