@mtcute/core 0.29.0 → 0.29.1

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.
@@ -9,6 +9,7 @@ const utils = require("@fuman/utils");
9
9
  const client = require("../network/client.cjs");
10
10
  const functionUtils = require("../utils/function-utils.cjs");
11
11
  const logger = require("../utils/logger.cjs");
12
+ const miscUtils = require("../utils/misc-utils.cjs");
12
13
  const typeAssertions = require("../utils/type-assertions.cjs");
13
14
  require("@mtcute/tl-runtime");
14
15
  const appConfigManager = require("./managers/app-config-manager.cjs");
@@ -31,7 +32,7 @@ class BaseTelegramClient {
31
32
  this.log = this.params.logger ?? new logger.LogManager("client", params.platform);
32
33
  this.platform = this.params.platform;
33
34
  this.mt = new client.MtClient({
34
- ...this.params,
35
+ ...miscUtils.dropUndefined(this.params),
35
36
  logger: this.log.create("mtproto"),
36
37
  onError: (err) => {
37
38
  if (this.onError.length > 0) {
@@ -59,7 +60,7 @@ class BaseTelegramClient {
59
60
  this.crypto = this.mt.crypto;
60
61
  this.storage = new storage.TelegramStorageManager(this.mt.storage, {
61
62
  provider: this.params.storage,
62
- ...this.params.storageOptions
63
+ ...miscUtils.dropUndefined(this.params.storageOptions)
63
64
  });
64
65
  this.timers = new timers.TimersManager(async (spec, abortSignal) => {
65
66
  await this.call(spec.request, {
package/highlevel/base.js CHANGED
@@ -2,6 +2,7 @@ import { unknownToError, Emitter } from "@fuman/utils";
2
2
  import { MtClient } from "../network/client.js";
3
3
  import { asyncResettable } from "../utils/function-utils.js";
4
4
  import { LogManager } from "../utils/logger.js";
5
+ import { dropUndefined } from "../utils/misc-utils.js";
5
6
  import { isTlRpcError } from "../utils/type-assertions.js";
6
7
  import "@mtcute/tl-runtime";
7
8
  import { AppConfigManager } from "./managers/app-config-manager.js";
@@ -24,7 +25,7 @@ class BaseTelegramClient {
24
25
  this.log = this.params.logger ?? new LogManager("client", params.platform);
25
26
  this.platform = this.params.platform;
26
27
  this.mt = new MtClient({
27
- ...this.params,
28
+ ...dropUndefined(this.params),
28
29
  logger: this.log.create("mtproto"),
29
30
  onError: (err) => {
30
31
  if (this.onError.length > 0) {
@@ -52,7 +53,7 @@ class BaseTelegramClient {
52
53
  this.crypto = this.mt.crypto;
53
54
  this.storage = new TelegramStorageManager(this.mt.storage, {
54
55
  provider: this.params.storage,
55
- ...this.params.storageOptions
56
+ ...dropUndefined(this.params.storageOptions)
56
57
  });
57
58
  this.timers = new TimersManager(async (spec, abortSignal) => {
58
59
  await this.call(spec.request, {
@@ -18,7 +18,7 @@ export type PeerType = 'user' | 'bot' | 'group' | 'channel' | 'supergroup';
18
18
  * > * Telegram has moved to int64 IDs. Though, Levin [has confirmed](https://t.me/tdlibchat/25071)
19
19
  * > that new IDs *will* still fit into int53, meaning JS integers are fine.
20
20
  */
21
- export type InputPeerLike = 'me' | 'self' | 'some_username' | (string & {}) | number | tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | {
21
+ export type InputPeerLike = 'me' | 'self' | 'some_username' | (string & {}) | number | tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | tl.RawUser | tl.RawChannel | tl.RawChat | {
22
22
  inputPeer: tl.TypeInputPeer;
23
23
  };
24
24
  /**
@@ -18,7 +18,7 @@ export type PeerType = 'user' | 'bot' | 'group' | 'channel' | 'supergroup';
18
18
  * > * Telegram has moved to int64 IDs. Though, Levin [has confirmed](https://t.me/tdlibchat/25071)
19
19
  * > that new IDs *will* still fit into int53, meaning JS integers are fine.
20
20
  */
21
- export type InputPeerLike = 'me' | 'self' | 'some_username' | (string & {}) | number | tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | {
21
+ export type InputPeerLike = 'me' | 'self' | 'some_username' | (string & {}) | number | tl.TypePeer | tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | tl.RawUser | tl.RawChannel | tl.RawChat | {
22
22
  inputPeer: tl.TypeInputPeer;
23
23
  };
24
24
  /**
@@ -5,6 +5,7 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
5
5
  }
6
6
  "use strict";
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const utils$1 = require("@fuman/utils");
8
9
  const utils = require("../../types/utils.cjs");
9
10
  const errors = require("../types/errors.cjs");
10
11
  const innerTl = require("../../tl/inner-tl.cjs");
@@ -12,6 +13,26 @@ const INVITE_LINK_REGEX = /^(?:https?:\/\/)?(?:www\.)?t(?:elegram)?\.(?:org|me|d
12
13
  function toInputPeer(res) {
13
14
  if (innerTl.isAnyInputPeer(res)) return res;
14
15
  switch (res._) {
16
+ case "user": {
17
+ return {
18
+ _: "inputPeerUser",
19
+ userId: res.id,
20
+ accessHash: utils$1.asNonNull(res.accessHash)
21
+ };
22
+ }
23
+ case "chat": {
24
+ return {
25
+ _: "inputPeerChat",
26
+ chatId: res.id
27
+ };
28
+ }
29
+ case "channel": {
30
+ return {
31
+ _: "inputPeerChannel",
32
+ channelId: res.id,
33
+ accessHash: utils$1.asNonNull(res.accessHash)
34
+ };
35
+ }
15
36
  case "inputChannelEmpty":
16
37
  case "inputUserEmpty":
17
38
  return { _: "inputPeerEmpty" };
@@ -1,7 +1,7 @@
1
1
  import { InputPeerLike } from '../types/peers/index.js';
2
2
  import { tl } from '../../tl/index.js';
3
3
  export declare const INVITE_LINK_REGEX: RegExp;
4
- export declare function toInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): tl.TypeInputPeer;
4
+ export declare function toInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | tl.RawUser | tl.RawChat | tl.RawChannel): tl.TypeInputPeer;
5
5
  export declare function toInputUser(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel, input?: InputPeerLike): tl.TypeInputUser;
6
6
  export declare function toInputChannel(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel, input?: InputPeerLike): tl.TypeInputChannel;
7
7
  export declare function isInputPeerUser(obj: tl.TypeInputPeer): obj is tl.RawInputPeerUser | tl.RawInputPeerUserFromMessage | tl.RawInputPeerSelf;
@@ -1,7 +1,7 @@
1
1
  import { InputPeerLike } from '../types/peers/index.js';
2
2
  import { tl } from '../../tl/index.js';
3
3
  export declare const INVITE_LINK_REGEX: RegExp;
4
- export declare function toInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel): tl.TypeInputPeer;
4
+ export declare function toInputPeer(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel | tl.RawUser | tl.RawChat | tl.RawChannel): tl.TypeInputPeer;
5
5
  export declare function toInputUser(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel, input?: InputPeerLike): tl.TypeInputUser;
6
6
  export declare function toInputChannel(res: tl.TypeInputPeer | tl.TypeInputUser | tl.TypeInputChannel, input?: InputPeerLike): tl.TypeInputChannel;
7
7
  export declare function isInputPeerUser(obj: tl.TypeInputPeer): obj is tl.RawInputPeerUser | tl.RawInputPeerUserFromMessage | tl.RawInputPeerSelf;
@@ -1,3 +1,4 @@
1
+ import { asNonNull } from "@fuman/utils";
1
2
  import { assertNever } from "../../types/utils.js";
2
3
  import { MtInvalidPeerTypeError } from "../types/errors.js";
3
4
  import { isAnyInputPeer, isAnyInputUser, isAnyInputChannel } from "../../tl/inner-tl.js";
@@ -5,6 +6,26 @@ const INVITE_LINK_REGEX = /^(?:https?:\/\/)?(?:www\.)?t(?:elegram)?\.(?:org|me|d
5
6
  function toInputPeer(res) {
6
7
  if (isAnyInputPeer(res)) return res;
7
8
  switch (res._) {
9
+ case "user": {
10
+ return {
11
+ _: "inputPeerUser",
12
+ userId: res.id,
13
+ accessHash: asNonNull(res.accessHash)
14
+ };
15
+ }
16
+ case "chat": {
17
+ return {
18
+ _: "inputPeerChat",
19
+ chatId: res.id
20
+ };
21
+ }
22
+ case "channel": {
23
+ return {
24
+ _: "inputPeerChannel",
25
+ channelId: res.id,
26
+ accessHash: asNonNull(res.accessHash)
27
+ };
28
+ }
8
29
  case "inputChannelEmpty":
9
30
  case "inputUserEmpty":
10
31
  return { _: "inputPeerEmpty" };
@@ -12,6 +12,7 @@ const writer = require("../tl/binary/writer.cjs");
12
12
  const dcs = require("../utils/dcs.cjs");
13
13
  const functionUtils = require("../utils/function-utils.cjs");
14
14
  const logger = require("../utils/logger.cjs");
15
+ const miscUtils = require("../utils/misc-utils.cjs");
15
16
  const typeAssertions = require("../utils/type-assertions.cjs");
16
17
  require("@mtcute/tl-runtime");
17
18
  const configManager = require("./config-manager.cjs");
@@ -46,7 +47,7 @@ class MtClient {
46
47
  readerMap: this._readerMap,
47
48
  writerMap: this._writerMap,
48
49
  platform: params.platform,
49
- ...params.storageOptions
50
+ ...miscUtils.dropUndefined(params.storageOptions)
50
51
  });
51
52
  this.network = new networkManager.NetworkManager(
52
53
  {
@@ -71,7 +72,7 @@ class MtClient {
71
72
  onUpdate: this.onUpdate.emit.bind(this.onUpdate),
72
73
  stopSignal: this.stopSignal,
73
74
  platform: params.platform,
74
- ...params.network
75
+ ...miscUtils.dropUndefined(params.network)
75
76
  },
76
77
  this._config
77
78
  );
package/network/client.js CHANGED
@@ -5,6 +5,7 @@ import { __tlWriterMap } from "../tl/binary/writer.js";
5
5
  import { defaultTestIpv6Dc, defaultTestDc, defaultProductionIpv6Dc, defaultProductionDc } from "../utils/dcs.js";
6
6
  import { asyncResettable } from "../utils/function-utils.js";
7
7
  import { LogManager } from "../utils/logger.js";
8
+ import { dropUndefined } from "../utils/misc-utils.js";
8
9
  import { isTlRpcError } from "../utils/type-assertions.js";
9
10
  import "@mtcute/tl-runtime";
10
11
  import { ConfigManager } from "./config-manager.js";
@@ -39,7 +40,7 @@ class MtClient {
39
40
  readerMap: this._readerMap,
40
41
  writerMap: this._writerMap,
41
42
  platform: params.platform,
42
- ...params.storageOptions
43
+ ...dropUndefined(params.storageOptions)
43
44
  });
44
45
  this.network = new NetworkManager(
45
46
  {
@@ -64,7 +65,7 @@ class MtClient {
64
65
  onUpdate: this.onUpdate.emit.bind(this.onUpdate),
65
66
  stopSignal: this.stopSignal,
66
67
  platform: params.platform,
67
- ...params.network
68
+ ...dropUndefined(params.network)
68
69
  },
69
70
  this._config
70
71
  );
@@ -7,7 +7,9 @@ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WAR
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
8
  const net = require("@fuman/net");
9
9
  const utils = require("@fuman/utils");
10
+ const miscUtils = require("../utils/misc-utils.cjs");
10
11
  const typeAssertions = require("../utils/type-assertions.cjs");
12
+ require("@mtcute/tl-runtime");
11
13
  const _default = require("./middlewares/default.cjs");
12
14
  const multiSessionConnection = require("./multi-session-connection.cjs");
13
15
  const serverSalt = require("./server-salt.cjs");
@@ -224,12 +226,12 @@ class NetworkManager {
224
226
  _: "initConnection",
225
227
  deviceModel,
226
228
  systemVersion: "1.0",
227
- appVersion: "0.29.0",
229
+ appVersion: "0.29.1",
228
230
  systemLangCode: "en",
229
231
  langPack: "",
230
232
  // "langPacks are for official apps only"
231
233
  langCode: "en",
232
- ...params.initConnectionOptions ?? {},
234
+ ...miscUtils.dropUndefined(params.initConnectionOptions),
233
235
  apiId: params.apiId,
234
236
  // eslint-disable-next-line
235
237
  query: null
@@ -1,6 +1,8 @@
1
1
  import { defaultReconnectionStrategy } from "@fuman/net";
2
2
  import { asNonNull, Deferred, LruMap, composeMiddlewares } from "@fuman/utils";
3
+ import { dropUndefined } from "../utils/misc-utils.js";
3
4
  import { isTlRpcError, assertTypeIs } from "../utils/type-assertions.js";
5
+ import "@mtcute/tl-runtime";
4
6
  import { basic } from "./middlewares/default.js";
5
7
  import { MultiSessionConnection } from "./multi-session-connection.js";
6
8
  import { ServerSaltManager } from "./server-salt.js";
@@ -217,12 +219,12 @@ class NetworkManager {
217
219
  _: "initConnection",
218
220
  deviceModel,
219
221
  systemVersion: "1.0",
220
- appVersion: "0.29.0",
222
+ appVersion: "0.29.1",
221
223
  systemLangCode: "en",
222
224
  langPack: "",
223
225
  // "langPacks are for official apps only"
224
226
  langCode: "en",
225
- ...params.initConnectionOptions ?? {},
227
+ ...dropUndefined(params.initConnectionOptions),
226
228
  apiId: params.apiId,
227
229
  // eslint-disable-next-line
228
230
  query: null
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
3
  "type": "module",
4
- "version": "0.29.0",
4
+ "version": "0.29.1",
5
5
  "description": "Type-safe library for MTProto (Telegram API)",
6
6
  "license": "MIT",
7
7
  "scripts": {},
@@ -23,5 +23,13 @@ function sleepWithAbort(ms, signal) {
23
23
  function getRandomInt(top) {
24
24
  return Math.floor(Math.random() * top);
25
25
  }
26
+ function dropUndefined(obj) {
27
+ if (!obj) return void 0;
28
+ for (const key in obj) {
29
+ if (obj[key] === void 0) delete obj[key];
30
+ }
31
+ return obj;
32
+ }
33
+ exports.dropUndefined = dropUndefined;
26
34
  exports.getRandomInt = getRandomInt;
27
35
  exports.sleepWithAbort = sleepWithAbort;
@@ -1,2 +1,4 @@
1
1
  export declare function sleepWithAbort(ms: number, signal: AbortSignal): Promise<void>;
2
2
  export declare function getRandomInt(top: number): number;
3
+ export declare function dropUndefined<T extends object>(obj: T): T;
4
+ export declare function dropUndefined<T extends object>(obj?: T): T | undefined;
@@ -1,2 +1,4 @@
1
1
  export declare function sleepWithAbort(ms: number, signal: AbortSignal): Promise<void>;
2
2
  export declare function getRandomInt(top: number): number;
3
+ export declare function dropUndefined<T extends object>(obj: T): T;
4
+ export declare function dropUndefined<T extends object>(obj?: T): T | undefined;
@@ -16,7 +16,15 @@ function sleepWithAbort(ms, signal) {
16
16
  function getRandomInt(top) {
17
17
  return Math.floor(Math.random() * top);
18
18
  }
19
+ function dropUndefined(obj) {
20
+ if (!obj) return void 0;
21
+ for (const key in obj) {
22
+ if (obj[key] === void 0) delete obj[key];
23
+ }
24
+ return obj;
25
+ }
19
26
  export {
27
+ dropUndefined,
20
28
  getRandomInt,
21
29
  sleepWithAbort
22
30
  };
package/utils.cjs CHANGED
@@ -73,6 +73,7 @@ exports.longFromFastString = longUtils.longFromFastString;
73
73
  exports.longToFastString = longUtils.longToFastString;
74
74
  exports.randomLong = longUtils.randomLong;
75
75
  exports.removeFromLongArray = longUtils.removeFromLongArray;
76
+ exports.dropUndefined = miscUtils$1.dropUndefined;
76
77
  exports.getRandomInt = miscUtils$1.getRandomInt;
77
78
  exports.sleepWithAbort = miscUtils$1.sleepWithAbort;
78
79
  exports.getAllPeersFrom = peerUtils$1.getAllPeersFrom;
package/utils.js CHANGED
@@ -9,7 +9,7 @@ import { EarlyTimer } from "./utils/early-timer.js";
9
9
  import { asyncResettable, throttle } from "./utils/function-utils.js";
10
10
  import { LogManager, Logger } from "./utils/logger.js";
11
11
  import { LongMap, LongSet, compareLongs, longFromBuffer, longFromFastString, longToFastString, randomLong, removeFromLongArray } from "./utils/long-utils.js";
12
- import { getRandomInt, sleepWithAbort } from "./utils/misc-utils.js";
12
+ import { dropUndefined, getRandomInt, sleepWithAbort } from "./utils/misc-utils.js";
13
13
  import { getAllPeersFrom, getBarePeerId, getBasicPeerType, getMarkedPeerId, parseMarkedPeerId, toggleChannelIdMark } from "./utils/peer-utils.js";
14
14
  import { SortedArray } from "./utils/sorted-array.js";
15
15
  import { jsonToTlJson, tlJsonToJson } from "./utils/tl-json.js";
@@ -68,6 +68,7 @@ export {
68
68
  deserializePeersIndex,
69
69
  deserializePeersIndexWithCompat,
70
70
  determinePartSize,
71
+ dropUndefined,
71
72
  encodeInlineMessageId,
72
73
  encodeWaveform,
73
74
  extractFileName,