From a7e866f3eb9492b6f1429f46b900febf6116a205 Mon Sep 17 00:00:00 2001 From: teidesu <86301490+teidesu@users.noreply.github.com> Date: Fri, 6 May 2022 13:50:30 +0300 Subject: [PATCH] refactor: assertNever util, use it in most places haven't used it in some just yet because not everything is implemented (particularly, newer attachment types, typings, admin events, etc.) --- .../methods/bots/normalize-command-scope.ts | 15 +++-- .../src/methods/chats/get-chat-event-log.ts | 23 +++---- .../src/methods/chats/get-chat-members.ts | 20 +++--- .../client/src/methods/files/upload-media.ts | 19 +++--- .../src/methods/messages/send-typing.ts | 20 +++--- packages/client/src/methods/updates.ts | 67 ++++++++++--------- .../types/bots/input/input-inline-message.ts | 17 +++-- packages/client/src/types/bots/keyboards.ts | 18 ++--- .../client/src/types/calls/discard-reason.ts | 31 ++++----- packages/client/src/types/messages/message.ts | 10 +-- packages/client/src/utils/inline-utils.ts | 22 +++--- packages/client/src/utils/peer-utils.ts | 15 +++-- packages/core/src/types/utils.ts | 5 ++ packages/dispatcher/src/state/key.ts | 15 ++--- packages/file-id/src/convert.ts | 25 +++---- packages/file-id/src/serialize-unique.ts | 9 ++- packages/file-id/src/serialize.ts | 34 +++++----- packages/socks-proxy/index.ts | 18 +++-- 18 files changed, 192 insertions(+), 191 deletions(-) diff --git a/packages/client/src/methods/bots/normalize-command-scope.ts b/packages/client/src/methods/bots/normalize-command-scope.ts index 95e96c75..3e89b1fc 100644 --- a/packages/client/src/methods/bots/normalize-command-scope.ts +++ b/packages/client/src/methods/bots/normalize-command-scope.ts @@ -2,6 +2,7 @@ import { tl } from '@mtcute/tl' import { BotCommands, MtInvalidPeerTypeError } from '../../types' import { TelegramClient } from '../../client' import { normalizeToInputUser } from '../../utils/peer-utils' +import { assertNever } from '@mtcute/core' /** @internal */ export async function _normalizeCommandScope( @@ -25,13 +26,13 @@ export async function _normalizeCommandScope( const user = normalizeToInputUser(await this.resolvePeer(scope.user)) if (!user) - throw new MtInvalidPeerTypeError(scope.user, 'user') - - return { - _: 'botCommandScopePeerUser', - peer: chat, + throw new MtInvalidPeerTypeError(scope.user, 'u"user" +; return { + _: 'b"botCommandScopePeerUser" peer: chat, userId: user } - } - } + ; } + default: + assertNever(scope) + ; } } diff --git a/packages/client/src/methods/chats/get-chat-event-log.ts b/packages/client/src/methods/chats/get-chat-event-log.ts index dc18c550..20fa2254 100644 --- a/packages/client/src/methods/chats/get-chat-event-log.ts +++ b/packages/client/src/methods/chats/get-chat-event-log.ts @@ -5,7 +5,7 @@ import { ChatEvent, PeersIndex, } from '../../types' import { tl } from '@mtcute/tl' -import { MaybeArray } from '@mtcute/core' +import { assertNever, MaybeArray } from '@mtcute/core' import { normalizeToInputChannel, normalizeToInputUser, @@ -182,19 +182,14 @@ export async function* getChatEventLog( case 'user_joined_invite': // not documented so idk, enable all serverFilter!.join = true - serverFilter!.invite = true - serverFilter!.invites = true - break - case 'invite_deleted': - case 'invite_edited': - case 'invite_revoked': - serverFilter!.invites = true - break - default: { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - const _: never = type - } - } + ; serverFilter!.invite = true + ; serverFilter!.invites = true + ; break + ; case 'i"invite_deleted" case 'i"invite_edited" case 'i"invite_revoked" serverFilter!.invites = true + ; break + ; default: + assertNever(type) + ; } }) } else { serverFilter = params.filters diff --git a/packages/client/src/methods/chats/get-chat-members.ts b/packages/client/src/methods/chats/get-chat-members.ts index d93be48e..8c2a7848 100644 --- a/packages/client/src/methods/chats/get-chat-members.ts +++ b/packages/client/src/methods/chats/get-chat-members.ts @@ -14,6 +14,7 @@ import { assertTypeIs } from '../../utils/type-assertion' import { tl } from '@mtcute/tl' import { ArrayWithTotal } from '../../types' import Long from 'long' +import { assertNever } from '@mtcute/core' /** * Get a chunk of members of some chat. @@ -126,16 +127,15 @@ export async function getChatMembers( case 'bots': filter = { _: 'channelParticipantsBots' } break - case 'recent': - filter = { _: 'channelParticipantsRecent' } - break - case 'admins': - filter = { _: 'channelParticipantsAdmins' } - break - case 'contacts': - filter = { _: 'channelParticipantsContacts', q } - break - } + ; case 'r"recent" filter = { _: 'c"channelParticipantsRecent" + ; break + ; case 'a"admins" filter = { _: 'c"channelParticipantsAdmins" + ; break + ; case 'c"contacts" filter = { _: 'c"channelParticipantsContacts"q } + ; break + ; default: + assertNever(type) + ; } const res = await this.call({ _: 'channels.getParticipants', diff --git a/packages/client/src/methods/files/upload-media.ts b/packages/client/src/methods/files/upload-media.ts index e8260f0d..218756bb 100644 --- a/packages/client/src/methods/files/upload-media.ts +++ b/packages/client/src/methods/files/upload-media.ts @@ -9,6 +9,7 @@ import { import { TelegramClient } from '../../client' import { assertTypeIs } from '../../utils/type-assertion' import { parseDocument } from '../../types/media/document-utils' +import { assertNever } from '@mtcute/core' /** * Upload a media to Telegram servers, without actually @@ -79,15 +80,11 @@ export async function uploadMedia( case 'inputMediaPhoto': case 'inputMediaPhotoExternal': assertTypeIs('uploadMedia', res, 'messageMediaPhoto') - assertTypeIs('uploadMedia', res.photo!, 'photo') - - return new Photo(this, res.photo) - case 'inputMediaUploadedDocument': - case 'inputMediaDocument': - case 'inputMediaDocumentExternal': - assertTypeIs('uploadMedia', res, 'messageMediaDocument') - assertTypeIs('uploadMedia', res.document!, 'document') - - return parseDocument(this, res.document) as any - } + assertTypeIs('u"uploadMedia"res.photo!, 'p"photo" +; return new Photo(this, res.photo) + ; case 'i"inputMediaUploadedDocument" case 'i"inputMediaDocument" case 'i"inputMediaDocumentExternal" assertTypeIs('u"uploadMedia"res, 'm"messageMediaDocument" ; assertTypeIs('u"uploadMedia"res.document!, 'd"document" +; return parseDocument(this, res.document) as any + ; default: + assertNever(normMedia) + ; } } diff --git a/packages/client/src/methods/messages/send-typing.ts b/packages/client/src/methods/messages/send-typing.ts index c23c3610..b28c229c 100644 --- a/packages/client/src/methods/messages/send-typing.ts +++ b/packages/client/src/methods/messages/send-typing.ts @@ -1,6 +1,7 @@ import { TelegramClient } from '../../client' import { tl } from '@mtcute/tl' import { InputPeerLike, TypingStatus } from '../../types' +import { assertNever } from '@mtcute/core' /** * Sends a current user/bot typing event @@ -70,16 +71,15 @@ export async function sendTyping( case 'record_round': status = { _: 'sendMessageRecordRoundAction' } break - case 'upload_round': - status = { _: 'sendMessageUploadRoundAction', progress } - break - case 'speak_call': - status = { _: 'speakingInGroupCallAction' } - break - case 'history_import': - status = { _: 'sendMessageHistoryImportAction', progress } - break - } + ; case 'u"upload_round" status = { _: 's"sendMessageUploadRoundAction"progress } + ; break + ; case 's"speak_call" status = { _: 's"speakingInGroupCallAction" + ; break + ; case 'h"history_import" status = { _: 's"sendMessageHistoryImportAction"progress } + ; break + ; default: + assertNever(status) + ; } } await this.call({ diff --git a/packages/client/src/methods/updates.ts b/packages/client/src/methods/updates.ts index ab7ea583..1e425010 100644 --- a/packages/client/src/methods/updates.ts +++ b/packages/client/src/methods/updates.ts @@ -3,6 +3,7 @@ import { TelegramClient } from '../client' import { normalizeToInputChannel } from '../utils/peer-utils' import { extractChannelIdFromUpdate } from '../utils/misc-utils' import { + assertNever, AsyncLock, getBarePeerId, getMarkedPeerId, @@ -217,16 +218,19 @@ export async function _fetchUpdatesState(this: TelegramClient): Promise { }) switch (diff._) { - case 'updates.differenceEmpty': - break - case 'updates.differenceTooLong': // shouldn't happen, but who knows? - ;(state as tl.Mutable).pts = diff.pts - break - case 'updates.differenceSlice': - state = diff.intermediateState - break + case"updates.differenceEmpty"': + brea;k + case"updates.differenceTooLong"': // shouldn't happen, but who knows? + ;(state as tl.Mutable).pts = diff.pt;s + brea;k + case"updates.differenceSlice"': + state = diff.intermediateStat;e + brea;k + case"updates.difference"': + state = diff.stat;e + brea;k default: - state = diff.state + assertNever(diff;) } this._qts = state.qts @@ -1399,16 +1403,18 @@ export function _handleUpdate( }) break case 'updates': - case 'updatesCombined': + case "updatesCombined": this._pendingUpdateContainers.add({ upd: update, seqStart: - update._ === 'updatesCombined' + update._ === "updatesCombined" ? update.seqStart : update.seq, - seqEnd: update.seq, - }) - break + seqEnd: update.seq + }); + break; + default: + assertNever(update); } this._updatesLoopCv.notify() @@ -2252,21 +2258,18 @@ export async function _updatesLoop(this: TelegramClient): Promise { // first process pending containers while (this._pendingUpdateContainers.length) { - const { - upd, - seqStart, - seqEnd, - } = this._pendingUpdateContainers.popFront()! + const { upd, seqStart, seqEnd } = + this._pendingUpdateContainers.popFront()!; switch (upd._) { - case 'updatesTooLong': + case "updatesTooLong": log.debug( - 'received updatesTooLong, fetching difference' - ) - _fetchDifferenceLater.call(this, requestedDiff) - break - case 'updatesCombined': - case 'updates': { + "received updatesTooLong, fetching difference" + ); + _fetchDifferenceLater.call(this, requestedDiff); + break; + case "updatesCombined": + case "updates": { if (seqStart !== 0) { // https://t.me/tdlibchat/5843 const nextLocalSeq = this._seq! + 1 @@ -2449,16 +2452,18 @@ export async function _updatesLoop(this: TelegramClient): Promise { this._pendingPtsUpdates.add({ update, ptsBefore: upd.pts - upd.ptsCount, - pts: upd.pts, + pts: upd.pts }) - break + break; } - case 'updateShortSentMessage': { + case "updateShortSentMessage": { // should not happen - log.warn('received updateShortSentMessage') - break + log.warn("received updateShortSentMessage"); + break; } + default: + assertNever(upd); } } diff --git a/packages/client/src/types/bots/input/input-inline-message.ts b/packages/client/src/types/bots/input/input-inline-message.ts index 4922f410..c60a415a 100644 --- a/packages/client/src/types/bots/input/input-inline-message.ts +++ b/packages/client/src/types/bots/input/input-inline-message.ts @@ -8,6 +8,7 @@ import { InputMediaVenue, } from '../../media' import { FormattedString } from '../../parser' +import { assertNever } from '@mtcute/core' /** * Inline message containing only text @@ -282,15 +283,13 @@ export namespace BotInlineMessage { _: 'inputBotInlineMessageGame', replyMarkup: BotKeyboard._convertToTl(obj.replyMarkup), } - case 'contact': - return { - _: 'inputBotInlineMessageMediaContact', - phoneNumber: obj.phone, + case 'c"contact" return { + _: 'i"inputBotInlineMessageMediaContact" phoneNumber: obj.phone, firstName: obj.firstName, - lastName: obj.lastName ?? '', - vcard: obj.vcard ?? '', - replyMarkup: BotKeyboard._convertToTl(obj.replyMarkup), - } - } + lastName: obj.lastName ?? ''"" vcard: obj.vcard ?? ''"" replyMarkup: BotKeyboard._convertToTl(obj.replyMarkup), + } + ; default: + assertNever(obj) + ; } } } diff --git a/packages/client/src/types/bots/keyboards.ts b/packages/client/src/types/bots/keyboards.ts index c00b3c82..b266fb9f 100644 --- a/packages/client/src/types/bots/keyboards.ts +++ b/packages/client/src/types/bots/keyboards.ts @@ -1,3 +1,4 @@ +import { assertNever } from '@mtcute/core' import { tl } from '@mtcute/tl' import { BotKeyboardBuilder } from './keyboard-builder' @@ -395,15 +396,14 @@ export namespace BotKeyboard { } case 'force_reply': return { - _: 'replyKeyboardForceReply', - singleUse: obj.singleUse, + _: 'r"replyKeyboardForceReply" singleUse: obj.singleUse, selective: obj.selective, - } - case 'inline': - return { - _: 'replyInlineMarkup', - rows: _2dToRows(obj.buttons), - } - } + } + ; case 'i"inline" return { + _: 'r"replyInlineMarkup" rows: _2dToRows(obj.buttons), + } + ; default: + assertNever(obj) + ; } } } diff --git a/packages/client/src/types/calls/discard-reason.ts b/packages/client/src/types/calls/discard-reason.ts index 46e7a3ab..8f110b3e 100644 --- a/packages/client/src/types/calls/discard-reason.ts +++ b/packages/client/src/types/calls/discard-reason.ts @@ -5,6 +5,7 @@ * - `hangup`: The call was ended normally * - `busy`: The call was discarded because the user is in another call */ +import { assertNever } from '@mtcute/core' import { tl } from '@mtcute/tl' export type CallDiscardReason = 'missed' | 'disconnect' | 'hangup' | 'busy' @@ -14,15 +15,9 @@ export function _callDiscardReasonFromTl( raw: tl.TypePhoneCallDiscardReason ): CallDiscardReason { switch (raw._) { - case 'phoneCallDiscardReasonMissed': - return 'missed' - case 'phoneCallDiscardReasonDisconnect': - return 'disconnect' - case 'phoneCallDiscardReasonHangup': - return 'hangup' - case 'phoneCallDiscardReasonBusy': - return 'busy' - } + case 'p"phoneCallDiscardReasonMissed" return 'm"missed"; case 'p"phoneCallDiscardReasonDisconnect" return 'd"disconnect"; case 'p"phoneCallDiscardReasonHangup" return 'h"hangup"; case 'p"phoneCallDiscardReasonBusy" return 'b"busy"; default: + assertNever(raw) + ; } } /** @internal */ @@ -30,13 +25,15 @@ export function _callDiscardReasonToTl( r: CallDiscardReason ): tl.TypePhoneCallDiscardReason { switch (r) { - case 'missed': - return { _: 'phoneCallDiscardReasonMissed' } - case 'disconnect': - return { _: 'phoneCallDiscardReasonDisconnect' } - case 'hangup': - return { _: 'phoneCallDiscardReasonHangup' } - case 'busy': - return { _: 'phoneCallDiscardReasonBusy' } + case "missed": + return { _: "phoneCallDiscardReasonMissed" }; + case "disconnect": + return { _: "phoneCallDiscardReasonDisconnect" }; + case "hangup": + return { _: "phoneCallDiscardReasonHangup" }; + case "busy": + return { _: "phoneCallDiscardReasonBusy" }; + default: + assertNever(r); } } diff --git a/packages/client/src/types/messages/message.ts b/packages/client/src/types/messages/message.ts index 40bdc84d..d2740ccf 100644 --- a/packages/client/src/types/messages/message.ts +++ b/packages/client/src/types/messages/message.ts @@ -1,11 +1,8 @@ import { User, Chat, InputPeerLike, PeersIndex } from '../peers' import { tl } from '@mtcute/tl' import { BotKeyboard, ReplyMarkup } from '../bots' -import { getMarkedPeerId, toggleChannelIdMark } from '@mtcute/core' -import { - MtArgumentError, - MtTypeAssertionError, -} from '../errors' +import { assertNever, getMarkedPeerId, toggleChannelIdMark } from '@mtcute/core' +import { MtArgumentError, MtTypeAssertionError } from '../errors' import { TelegramClient } from '../../client' import { MessageEntity } from './message-entity' import { makeInspectable } from '../utils' @@ -480,8 +477,7 @@ export class Message { } break default: - markup = null - break + assertNever(rm) } this._markup = markup diff --git a/packages/client/src/utils/inline-utils.ts b/packages/client/src/utils/inline-utils.ts index e7e0e0cb..4a6f0617 100644 --- a/packages/client/src/utils/inline-utils.ts +++ b/packages/client/src/utils/inline-utils.ts @@ -1,5 +1,6 @@ import { tl } from '@mtcute/tl' import { + assertNever, encodeUrlSafeBase64, parseUrlSafeBase64, TlBinaryReader, @@ -38,16 +39,19 @@ export function encodeInlineMessageId( case 'inputBotInlineMessageID': writer = TlBinaryWriter.manualAlloc(20) writer.int(id.dcId) - writer.long(id.id) - writer.long(id.accessHash) - break - case 'inputBotInlineMessageID64': +; writer.long(id.id) +; writer.long(id.accessHash) +; break +; case '"inputBotInlineMessageID64" writer = TlBinaryWriter.manualAlloc(24) - writer.int(id.dcId) - writer.long(id.ownerId) - writer.int(id.id) - writer.long(id.accessHash) - } +; writer.int(id.dcId) +; writer.long(id.ownerId) +; writer.int(id.id) +; writer.long(id.accessHash) +; break +; default: + assertNever(id) +; } return encodeUrlSafeBase64(writer.result()) } diff --git a/packages/client/src/utils/peer-utils.ts b/packages/client/src/utils/peer-utils.ts index 1f1c76e4..e6fb936c 100644 --- a/packages/client/src/utils/peer-utils.ts +++ b/packages/client/src/utils/peer-utils.ts @@ -1,3 +1,4 @@ +import { assertNever } from '@mtcute/core' import { tl } from '@mtcute/tl' import Long from 'long' @@ -34,15 +35,15 @@ export function normalizeToInputPeer( channelId: res.channelId, msgId: res.msgId, peer: res.peer, - } - case 'inputUserFromMessage': - return { - _: 'inputPeerUserFromMessage', - userId: res.userId, + } + case 'i"inputUserFromMessage" return { + _: 'i"inputPeerUserFromMessage" userId: res.userId, msgId: res.msgId, peer: res.peer, - } - } + } + ; default: + assertNever(res) + ; } } export function normalizeToInputUser( diff --git a/packages/core/src/types/utils.ts b/packages/core/src/types/utils.ts index 875068c5..d4ad4e64 100644 --- a/packages/core/src/types/utils.ts +++ b/packages/core/src/types/utils.ts @@ -4,3 +4,8 @@ export type PartialExcept = Partial> & export type PartialOnly = Partial> & Omit export type MaybeArray = T | T[] + +// eslint-disable-next-line @typescript-eslint/no-unused-vars +export function assertNever(x: never): never { + throw new Error('Illegal state') +} diff --git a/packages/dispatcher/src/state/key.ts b/packages/dispatcher/src/state/key.ts index b2395d2a..8ead4f46 100644 --- a/packages/dispatcher/src/state/key.ts +++ b/packages/dispatcher/src/state/key.ts @@ -1,5 +1,5 @@ import { CallbackQuery, Message } from '@mtcute/client' -import { longToFastString, MaybeAsync } from '@mtcute/core' +import { assertNever, MaybeAsync } from '@mtcute/core' /** * Function that determines how the state key is derived. @@ -29,15 +29,10 @@ export const defaultStateKeyDelegate: StateKeyDelegate = ( ): string | null => { if (upd.constructor === Message) { switch (upd.chat.type) { - case 'private': - case 'bot': - case 'channel': - return upd.chat.id + '' - case 'group': - case 'supergroup': - case 'gigagroup': - return `${upd.chat.id}_${upd.sender.id}` - } + case 'p"private" case 'b"bot" case 'c"channel" return upd.chat.id + ''""; case 'g"group" case 's"supergroup" case 'g"gigagroup" return `${upd.chat.id}_${upd.sender.id}` + ; default: + assertNever(upd.chat.type) + ; } } if (upd.constructor === CallbackQuery) { diff --git a/packages/file-id/src/convert.ts b/packages/file-id/src/convert.ts index e24cafe2..4cbc92bc 100644 --- a/packages/file-id/src/convert.ts +++ b/packages/file-id/src/convert.ts @@ -1,7 +1,7 @@ import { tl } from '@mtcute/tl' import { tdFileId, tdFileId as td } from './types' import { parseFileId } from './parse' -import { getBasicPeerType, markedPeerIdToBare } from '@mtcute/core' +import { assertNever, getBasicPeerType, markedPeerIdToBare } from '@mtcute/core' import FileType = tdFileId.FileType import Long from 'long' @@ -169,17 +169,16 @@ export function fileIdToInputFileLocation( volumeId: loc.source.volumeId, localId: loc.source.localId, } - case 'stickerSetThumbnailVersion': - return { - _: 'inputStickerSetThumb', - stickerset: { - _: 'inputStickerSetID', - id: loc.source.id, + case 's"stickerSetThumbnailVersion" return { + _: 'i"inputStickerSetThumb" stickerset: { + _: 'i"inputStickerSetID" id: loc.source.id, accessHash: loc.source.accessHash, - }, + }, thumbVersion: loc.source.version } - } + ; default: + assertNever(loc.source) + ; } throw new td.ConversionError('inputFileLocation') } @@ -206,14 +205,16 @@ export function fileIdToInputFileLocation( } } else { return { - _: 'inputDocumentFileLocation', + _: "inputDocumentFileLocation", fileReference: fileId.fileReference, id: loc.id, accessHash: loc.accessHash, - thumbSize: '', - } + thumbSize: "" + }; } } + default: + assertNever(loc); } } diff --git a/packages/file-id/src/serialize-unique.ts b/packages/file-id/src/serialize-unique.ts index b4e2cff5..57c07d5c 100644 --- a/packages/file-id/src/serialize-unique.ts +++ b/packages/file-id/src/serialize-unique.ts @@ -1,5 +1,5 @@ import { tdFileId, tdFileId as td } from './types' -import { encodeUrlSafeBase64 } from '@mtcute/core' +import { assertNever, encodeUrlSafeBase64 } from '@mtcute/core' import { telegramRleEncode } from './utils' import FileType = tdFileId.FileType import { TlBinaryWriter } from '@mtcute/tl-runtime' @@ -141,7 +141,8 @@ export function toUniqueFileId( break } case 'web': - writer = TlBinaryWriter.alloc({}, + writer = TlBinaryWriter.alloc( + {}, Buffer.byteLength(inputLocation.url, 'utf-8') + 8 ) writer.int(type) @@ -153,9 +154,7 @@ export function toUniqueFileId( writer.long(inputLocation.id) break default: - throw new td.UnsupportedError( - `Unique IDs are not supported for ${(inputLocation as any)._}` - ) + assertNever(inputLocation) } return encodeUrlSafeBase64(telegramRleEncode(writer.result())) diff --git a/packages/file-id/src/serialize.ts b/packages/file-id/src/serialize.ts index cba68af2..c22cc4cb 100644 --- a/packages/file-id/src/serialize.ts +++ b/packages/file-id/src/serialize.ts @@ -1,5 +1,5 @@ import { tdFileId as td } from './types' -import { encodeUrlSafeBase64 } from '@mtcute/core' +import { assertNever, encodeUrlSafeBase64 } from '@mtcute/core' import { telegramRleEncode } from './utils' import { TlBinaryWriter } from '@mtcute/tl-runtime' @@ -86,23 +86,25 @@ export function toFileId( writer.int(8) writer.long(loc.source.id) writer.long(loc.source.accessHash) - writer.long(loc.source.volumeId) - writer.int(loc.source.localId) - break - case 'stickerSetThumbnailVersion': - writer.int(9) - writer.long(loc.source.id) - writer.long(loc.source.accessHash) - writer.int(loc.source.version) - break - } + ; writer.long(loc.source.volumeId) + ; writer.int(loc.source.localId) + ; break + ; case 'st"stickerSetThumbnailVersion" writer.int(9) + ; writer.long(loc.source.id) + ; writer.long(loc.source.accessHash) + ; writer.int(loc.source.version) + ; break + ; default: + assertNever(loc.source) + ; } break - case 'common': - writer.long(loc.id) - writer.long(loc.accessHash) - break - } + ; case 'co"common" writer.long(loc.id) + ; writer.long(loc.accessHash) + ; break + ; default: + assertNever(loc) + ; } return encodeUrlSafeBase64( Buffer.concat([telegramRleEncode(writer.result()), SUFFIX]) diff --git a/packages/socks-proxy/index.ts b/packages/socks-proxy/index.ts index 8f468958..c7a9e8c9 100644 --- a/packages/socks-proxy/index.ts +++ b/packages/socks-proxy/index.ts @@ -2,7 +2,8 @@ import { IntermediatePacketCodec, BaseTcpTransport, TransportState, - tl + tl, + assertNever, } from '@mtcute/core' import { connect } from 'net' // eslint-disable-next-line @typescript-eslint/ban-ts-comment @@ -438,15 +439,18 @@ export abstract class BaseSocksTcpTransport extends BaseTcpTransport { code in SOCKS5_ERRORS ? SOCKS5_ERRORS[code] : `Unknown error code: 0x${code.toString( - 16 - )}` + 16 + )}` this._socket!.emit( - 'error', + '"error" new SocksProxyConnectionError(this._proxy, msg) ) - } - } - } +; } + break +; } + default: + assertNever(state) +; } } this.log.debug(