@mtcute/tl 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright 2023 Alina Sireneva
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
package/README.md ADDED
@@ -0,0 +1,103 @@
1
+ # @mtcute/tl
2
+
3
+ TL schema and related utils used for mtcute.
4
+
5
+ Generated from TL layer **166** (last updated on 29.10.2023).
6
+
7
+ ## About
8
+
9
+ This package contains JSON schema, type declarations, binary (de-)serialization, errors, RSA keys and helper functions.
10
+
11
+ Package's major version is always TL schema layer number,
12
+ so version `42.0.0` means that this version was generated from TL layer 42.
13
+
14
+ - JSON schema, types, binary (de-)serialization and helper functions are generated directly from `.tl` files that are
15
+ automatically fetched from multiple sources and are merged together.
16
+ - Errors are generated from
17
+ [`errors.csv`](https://github.com/LonamiWebs/Telethon/blob/master/telethon_generator/data/errors.csv)
18
+ and official Telegram errors JSON file.
19
+ - RSA keys info is generated based on manually extracted PEMs from Telegram for Android source code.
20
+
21
+ ## Exports
22
+
23
+ ### Root
24
+
25
+ TypeScript typings and type helpers generated from the schema.
26
+
27
+ By default, all types are immutable (have their fields marked as `readonly`). That is because most of the time you don't
28
+ really need to modify the objects, and modifying them will only lead to confusion. However, there are still valid
29
+ use-cases for mutable TL objects, so you can use exported
30
+ `tl.Mutable` helper type to make a given object type mutable.
31
+
32
+ `tl` is exported as a namespace to allow better code insights,
33
+ as well as to avoid cluttering global namespace and very long import statements.
34
+
35
+ MTProto schema is available in namespace `mtp`, also exported by this package.
36
+
37
+ ```typescript
38
+ import { tl } from '@mtcute/tl'
39
+ const obj: tl.RawInputPeerChat = { _: 'inputPeerChat', chatId: 42 }
40
+ console.log(tl.isAnyInputPeer(obj)) // true
41
+ ```
42
+
43
+
44
+ RPC errors are also exposed in this package in `tl.errors` namespace:
45
+
46
+ ```typescript
47
+ import { tl } from '@mtcute/tl'
48
+ try {
49
+ await client.call(...)
50
+ } catch (e) {
51
+ if (e instanceof tl.errors.ChatInvalidError) {
52
+ console.log('invalid chat')
53
+ } else throw e
54
+ }
55
+ ```
56
+
57
+ ### `/api-schema.json`
58
+
59
+ [Documentation](./modules/api_schema.html)
60
+
61
+ JSON file describing all available TL classes, methods and unions. Can be used to write custom code generators
62
+ > This very file is used to generate binary serialization and TypeScript typings for `@mtcute/tl`.
63
+
64
+ ```typescript
65
+ import * as tlSchema from '@mtcute/tl/raw-schema.json'
66
+
67
+ console.log(`Current layer: ${tlSchema.apiLayer}`)
68
+ // Current layer: 124
69
+ ```
70
+
71
+ ### `/binary/reader.js`
72
+
73
+ Contains mapping used to read TL objects from binary streams.
74
+
75
+ ```typescript
76
+ import { __tlReaderMap } from '@mtcute/tl/binary/reader.js'
77
+ import { TlBinaryReader } from '@mtcute/tl-runtime'
78
+
79
+ const reader = TlBinaryReader.manual(new Uint8Array([...]))
80
+ console.log(readerMap[0x5bb8e511 /* mt_message */](reader))
81
+ // { _: 'mt_message', ... }
82
+ ```
83
+
84
+ ### `/binary/writer.js`
85
+
86
+ Contains mapping used to write TL objects to binary streams.
87
+
88
+ ```typescript
89
+ import { __tlWriterMap } from '@mtcute/tl/binary/writer'
90
+ import { TlBinaryWriter } from '@mtcute/tl-runtime'
91
+
92
+ const writer = TlBinaryWriter.manual(100)
93
+ writerMap[0x5bb8e511 /* mt_message */](writer, { ... })
94
+ console.log(writer.result())
95
+ // Uint8Array <11 e5 b8 5b ...>
96
+ ```
97
+
98
+ ### `/binary/rsa-keys.js`
99
+
100
+ Contains RSA keys used when authorizing with Telegram.
101
+
102
+ `old` flag also determines if the client should use the old
103
+ RSA padding scheme.