mtcute/packages/tl
alina sireneva 93fe673d2e
All checks were successful
Tests / test-deno (push) Successful in 1m43s
Tests / test-bun (push) Successful in 1m51s
Tests / test-node (node18) (push) Successful in 2m1s
Tests / test-node (node20) (push) Successful in 2m1s
Tests / test-node (node22) (push) Successful in 2m0s
Tests / test-web (chromium) (push) Successful in 2m3s
Tests / test-web (firefox) (push) Successful in 2m13s
Build and deploy typedoc / build (push) Successful in 5m54s
Tests / lint (push) Successful in 6m36s
Tests / e2e (push) Successful in 50s
Tests / e2e-deno (push) Successful in 54s
feat(tl)!: updated to layer 198
2025-01-25 08:41:54 +03:00
..
binary ESM + end-to-end tests (#11) 2023-10-16 19:23:53 +03:00
data feat(tl)!: updated to layer 198 2025-01-25 08:41:54 +03:00
scripts feat(tl): compat schema generation 2025-01-25 08:41:54 +03:00
tests ESM + end-to-end tests (#11) 2023-10-16 19:23:53 +03:00
.gitignore build: initial support for jsr building 2024-04-21 04:53:09 +03:00
api-schema.json feat(tl)!: updated to layer 198 2025-01-25 08:41:54 +03:00
app-config.json chore: migrate to antfu eslint config (+ reformat) 2024-08-18 07:18:13 +03:00
mtp-schema.json chore: migrate to antfu eslint config (+ reformat) 2024-08-18 07:18:13 +03:00
package.json feat(tl)!: updated to layer 198 2025-01-25 08:41:54 +03:00
raw-errors.json chore: migrate to antfu eslint config (+ reformat) 2024-08-18 07:18:13 +03:00
README.md feat(tl)!: updated to layer 198 2025-01-25 08:41:54 +03:00
tsconfig.json chore: migrate to antfu eslint config (+ reformat) 2024-08-18 07:18:13 +03:00
UPDATING.md docs: added info on updating the schema 2024-09-29 00:26:47 +03:00

@mtcute/tl

TL schema and related utils used for mtcute.

Generated from TL layer 198 (last updated on 25.01.2025).

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 multiple sources and are merged together.
  • Errors are generated from errors.csv and official Telegram errors JSON file.
  • RSA keys info is generated based on manually extracted PEMs from Telegram for Android source code.

Exports

Root

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 helper type to make a given object type mutable.

tl is exported as a namespace to allow better code insights, as well as 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
}

/api-schema.json

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

console.log(`Current layer: ${tlSchema.apiLayer}`)
// Current layer: 124

/binary/reader.js

Contains mapping used to read TL objects from binary streams.

import { __tlReaderMap } from '@mtcute/tl/binary/reader.js'
import { TlBinaryReader } from '@mtcute/tl-runtime'

const reader = TlBinaryReader.manual(new Uint8Array([...]))
console.log(readerMap[0x5bb8e511 /* mt_message */](reader))
// { _: 'mt_message', ... }

/binary/writer.js

Contains mapping used to write TL objects to binary streams.

import { __tlWriterMap } from '@mtcute/tl/binary/writer'
import { TlBinaryWriter } from '@mtcute/tl-runtime'

const writer = TlBinaryWriter.manual(100)
writerMap[0x5bb8e511 /* mt_message */](writer, { ... })
console.log(writer.result())
// Uint8Array <11 e5 b8 5b ...>

/binary/rsa-keys.js

Contains RSA keys used when authorizing with Telegram.

old flag also determines if the client should use the old RSA padding scheme.