mtcute/packages/tl
2021-07-25 21:03:40 +03:00
..
binary build: renamed to mtqt 2021-07-25 21:03:40 +03:00
scripts build: renamed to mtqt 2021-07-25 21:03:40 +03:00
tests build: fixed scripts, eslintignore, fixed linter warnings and re-formatted with prettier 2021-06-06 15:20:41 +03:00
.gitignore Initial commit 2021-04-08 12:19:38 +03:00
descriptions.yaml docs(tl): replace male pronouns with gender-neutral 2021-06-03 18:59:43 +03:00
package.json build: renamed to mtqt 2021-07-25 21:03:40 +03:00
raw-errors.json fix(tl): updated schema 2021-07-24 23:21:52 +03:00
raw-schema.d.ts Initial commit 2021-04-08 12:19:38 +03:00
raw-schema.json fix(tl): updated schema 2021-07-24 23:21:52 +03:00
README.md build: renamed to mtqt 2021-07-25 21:03:40 +03:00
tsconfig.json Initial commit 2021-04-08 12:19:38 +03:00
typedoc.json build: renamed to mtqt 2021-07-25 21:03:40 +03:00

@mtqt/tl

TL schema and related utils used for mtqt.

Generated from TL layer 131 (last updated on 24.07.2021).

About

This package contains JSON schema, type declarations, binary (de-)serialization, errors, RSA keys and helper functions.

Package's minor version is always TL schema layer number, so version 1.42.0 means that this version was generated from TL layer 42.

⚠️ Warning: Always use strict or tilde constraint to ensure the same schema is used.

I.e. use "@mtqt/tl": "~1.42.0" or "@mtqt/tl": "1.42.0" instead of "@mtqt/tl": "^1.42.0", since the former would also match 1.43.0, 1.44.0, ... and will probably break your build or runtime

  • 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

@mtqt/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.

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

@mtqt/tl/raw-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 @mtqt/tl.

import * as tlSchema from '@mtqt/tl/raw-schema'
console.log(`Current layer: ${tlSchema.apiLayer}`)
// Current layer: 124

@mtqt/tl/binary/reader

Documentation

Contains mapping used to read TL objects from binary streams.

import readerMap from '@mtqt/tl/binary/reader'
import { BinaryReader } from './binary-reader'

const reader = new BinaryReader(Buffer.from([...]))
console.log(readerMap[0x5bb8e511 /* mt_message */].call(reader))
// { _: 'mt_message', ... }

@mtqt/tl/binary/writer

Documentation

Contains mapping used to write TL objects to binary streams.

import writerMap from '@mtqt/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 ...>