feat(core): allow sending fully custom payloads

This commit is contained in:
alina 🌸 2024-06-26 11:22:08 +03:00
parent 66d5862bdb
commit fe1047df8b
Signed by: teidesu
SSH key fingerprint: SHA256:uNeCpw6aTSU4aIObXLvHfLkDa82HWH9EiOj9AXOIRpI
4 changed files with 23 additions and 3 deletions

View file

@ -2,7 +2,7 @@
TL schema and related utils used for mtcute.
Generated from TL layer **182** (last updated on 25.06.2024).
Generated from TL layer **182** (last updated on 26.06.2024).
## About

File diff suppressed because one or more lines are too long

View file

@ -5,3 +5,10 @@
mtcute.dummyUpdate pts:int pts_count:int channel_id:int53 = Update;
mtcute.dummyInputPeerMinUser user_id:int = InputPeer;
mtcute.dummyInputPeerMinChannel channel_id:int = InputPeer;
---functions---
// temporary solution to allow users to call arbitrary methods not present in the schema,
// without having to override client's schema readers/writers map.
// will become redundant after esm tl rewrite
mtcute.customMethod bytes:bytes = bytes;

View file

@ -28,7 +28,8 @@ async function generateTypings(apiSchema: TlFullSchema, apiLayer: number, mtpSch
await writeFile(OUT_TYPINGS_JS_FILE, ESM_PRELUDE + apiJs + '\n\n' + mtpJs)
}
const removeInternalEntries = (entries: TlEntry[]) => entries.filter((it) => !it.name.startsWith('mtcute.'))
const removeInternalEntries = (entries: TlEntry[]) =>
entries.filter((it) => !it.name.startsWith('mtcute.') || it.name === 'mtcute.customMethod')
async function generateReaders(apiSchema: TlFullSchema, mtpSchema: TlFullSchema) {
console.log('Generating readers...')
@ -56,6 +57,18 @@ async function generateWriters(apiSchema: TlFullSchema, mtpSchema: TlFullSchema)
includeStaticSizes: true,
})
// for mtcute.customMethod we want to generate a writer that writes obj.bytes directly
const newCode = code.replace(
/^('mtcute.customMethod':function\(w,v\){)w.uint\(2440218877\);w.bytes\(h\(v,'bytes'\)\)/m,
"$1w.raw(h(v,'bytes'))",
)
if (newCode === code) {
throw new Error('Failed to replace customMethod writer')
}
code = newCode
code += '\nexports.__tlWriterMap = m;'
await writeFile(OUT_WRITERS_FILE, ESM_PRELUDE + code)