f5976a2d74
* 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???
42 lines
1.3 KiB
TypeScript
42 lines
1.3 KiB
TypeScript
// Downloads latest MTProto .tl schema
|
|
|
|
import * as cheerio from 'cheerio'
|
|
import { writeFile } from 'fs/promises'
|
|
|
|
import { parseTlToEntries } from '@mtcute/tl-utils'
|
|
|
|
import { CORE_DOMAIN, MTP_SCHEMA_JSON_FILE } from './constants.js'
|
|
import { fetchRetry } from './utils.js'
|
|
|
|
async function fetchMtprotoSchema(): Promise<string> {
|
|
const html = await fetchRetry(`${CORE_DOMAIN}/schema/mtproto`)
|
|
const $ = cheerio.load(html)
|
|
|
|
// cheerio doesn't always unescape them
|
|
return $('#dev_page_content pre code').text().replace(/</g, '<').replace(/>/g, '>')
|
|
}
|
|
|
|
async function main() {
|
|
console.log('Downloading MTProto schema...')
|
|
const schema = await fetchMtprotoSchema()
|
|
|
|
console.log('Parsing...')
|
|
let entries = parseTlToEntries(schema, { prefix: 'mt_' })
|
|
|
|
// remove manually parsed types
|
|
entries = entries.filter(
|
|
(it) => !['mt_msg_container', 'mt_message', 'mt_msg_copy', 'mt_gzip_packed', 'mt_rpc_result'].includes(it.name),
|
|
)
|
|
|
|
// mtproto is handled internally, for simplicity we make them all classes
|
|
entries.forEach((entry) => {
|
|
entry.kind = 'class'
|
|
})
|
|
|
|
console.log('Writing to file...')
|
|
await writeFile(MTP_SCHEMA_JSON_FILE, JSON.stringify(entries))
|
|
|
|
console.log('Done!')
|
|
}
|
|
|
|
main().catch(console.error)
|