@mtcute/core 0.12.2 → 0.12.5

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/cjs/platform.js CHANGED
@@ -9,14 +9,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.getPlatform = exports.setPlatform = void 0;
10
10
  const tl_runtime_1 = require("@mtcute/tl-runtime");
11
11
  const errors_js_1 = require("./types/errors.js");
12
- // eslint-disable-next-line
13
- const globalObject = (0, eval)('this');
14
12
  // NB: when using with some bundlers (e.g. vite) re-importing this module will not return the same object
15
13
  // so we need to store the platform in a global object to be able to survive hot-reloads etc.
16
14
  // try to use Symbol if available, otherwise fallback to a string
17
15
  const platformKey = typeof Symbol !== 'undefined' ? Symbol.for('mtcute.platform') : '__MTCUTE_PLATFORM__';
18
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
19
- let _platform = globalObject?.[platformKey] ?? null;
16
+ // eslint-disable-next-line
17
+ let _platform = globalThis?.[platformKey] ?? null;
20
18
  function setPlatform(platform) {
21
19
  if (_platform) {
22
20
  if (_platform.constructor !== platform.constructor) {
@@ -27,9 +25,7 @@ function setPlatform(platform) {
27
25
  _platform = platform;
28
26
  tl_runtime_1.TlBinaryReader.platform = platform;
29
27
  tl_runtime_1.TlBinaryWriter.platform = platform;
30
- if (globalObject) {
31
- globalObject[platformKey] = platform;
32
- }
28
+ globalThis[platformKey] = platform;
33
29
  }
34
30
  exports.setPlatform = setPlatform;
35
31
  function getPlatform() {
@@ -1 +1 @@
1
- {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":";;;AAAA,mDAAgF;AAGhF,iDAAsD;AAiBtD,2BAA2B;AAC3B,MAAM,YAAY,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,CAAA;AAEtC,yGAAyG;AACzG,6FAA6F;AAC7F,iEAAiE;AACjE,MAAM,WAAW,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAA;AAEzG,mEAAmE;AACnE,IAAI,SAAS,GAAyB,YAAY,EAAE,CAAC,WAAW,CAAC,IAAI,IAAI,CAAA;AAEzE,SAAgB,WAAW,CAAC,QAAuB;IAC/C,IAAI,SAAS,EAAE,CAAC;QACZ,IAAI,SAAS,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,IAAI,8BAAkB,CAAC,yCAAyC,CAAC,CAAA;QAC3E,CAAC;QAED,OAAM;IACV,CAAC;IAED,SAAS,GAAG,QAAQ,CAAA;IACpB,2BAAc,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAClC,2BAAc,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAElC,IAAI,YAAY,EAAE,CAAC;QACf,YAAY,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAA;IACxC,CAAC;AACL,CAAC;AAhBD,kCAgBC;AAED,SAAgB,WAAW;IACvB,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,IAAI,8BAAkB,CAAC,wDAAwD,CAAC,CAAA;IAC1F,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC;AAND,kCAMC","sourcesContent":["import { ITlPlatform, TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime'\n\nimport { UploadFileLike } from './highlevel/types/files/utils.js'\nimport { MtUnsupportedError } from './types/errors.js'\nimport { MaybePromise } from './types/index.js'\n\nexport interface ICorePlatform extends ITlPlatform {\n beforeExit(fn: () => void): () => void\n log(color: number, level: number, tag: string, fmt: string, args: unknown[]): void\n getDefaultLogLevel(): number | null\n getDeviceModel(): string\n normalizeFile?(file: UploadFileLike): MaybePromise<{\n file?: UploadFileLike\n fileSize?: number\n fileName?: string\n } | null>\n onNetworkChanged?(fn: (connected: boolean) => void): () => void\n isOnline?(): boolean\n}\n\n// eslint-disable-next-line\nconst globalObject = (0, eval)('this')\n\n// NB: when using with some bundlers (e.g. vite) re-importing this module will not return the same object\n// so we need to store the platform in a global object to be able to survive hot-reloads etc.\n// try to use Symbol if available, otherwise fallback to a string\nconst platformKey = typeof Symbol !== 'undefined' ? Symbol.for('mtcute.platform') : '__MTCUTE_PLATFORM__'\n\n// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment\nlet _platform: ICorePlatform | null = globalObject?.[platformKey] ?? null\n\nexport function setPlatform(platform: ICorePlatform): void {\n if (_platform) {\n if (_platform.constructor !== platform.constructor) {\n throw new MtUnsupportedError('Platform may not be changed at runtime!')\n }\n\n return\n }\n\n _platform = platform\n TlBinaryReader.platform = platform\n TlBinaryWriter.platform = platform\n\n if (globalObject) {\n globalObject[platformKey] = platform\n }\n}\n\nexport function getPlatform(): ICorePlatform {\n if (!_platform) {\n throw new MtUnsupportedError('Platform is not set! Have you instantiated the client?')\n }\n\n return _platform\n}\n"]}
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":";;;AAAA,mDAAgF;AAGhF,iDAAsD;AAiBtD,yGAAyG;AACzG,6FAA6F;AAC7F,iEAAiE;AACjE,MAAM,WAAW,GAAG,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,qBAAqB,CAAA;AAEzG,2BAA2B;AAC3B,IAAI,SAAS,GAA0B,UAAkB,EAAE,CAAC,WAAW,CAAC,IAAI,IAAI,CAAA;AAEhF,SAAgB,WAAW,CAAC,QAAuB;IAC/C,IAAI,SAAS,EAAE,CAAC;QACZ,IAAI,SAAS,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,IAAI,8BAAkB,CAAC,yCAAyC,CAAC,CAAA;QAC3E,CAAC;QAED,OAAM;IACV,CAAC;IAED,SAAS,GAAG,QAAQ,CAAA;IACpB,2BAAc,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAClC,2BAAc,CAAC,QAAQ,GAAG,QAAQ,CAGjC;IAAC,UAAkB,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAA;AAChD,CAAC;AAfD,kCAeC;AAED,SAAgB,WAAW;IACvB,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,IAAI,8BAAkB,CAAC,wDAAwD,CAAC,CAAA;IAC1F,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC;AAND,kCAMC","sourcesContent":["import { ITlPlatform, TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime'\n\nimport { UploadFileLike } from './highlevel/types/files/utils.js'\nimport { MtUnsupportedError } from './types/errors.js'\nimport { MaybePromise } from './types/index.js'\n\nexport interface ICorePlatform extends ITlPlatform {\n beforeExit(fn: () => void): () => void\n log(color: number, level: number, tag: string, fmt: string, args: unknown[]): void\n getDefaultLogLevel(): number | null\n getDeviceModel(): string\n normalizeFile?(file: UploadFileLike): MaybePromise<{\n file?: UploadFileLike\n fileSize?: number\n fileName?: string\n } | null>\n onNetworkChanged?(fn: (connected: boolean) => void): () => void\n isOnline?(): boolean\n}\n\n// NB: when using with some bundlers (e.g. vite) re-importing this module will not return the same object\n// so we need to store the platform in a global object to be able to survive hot-reloads etc.\n// try to use Symbol if available, otherwise fallback to a string\nconst platformKey = typeof Symbol !== 'undefined' ? Symbol.for('mtcute.platform') : '__MTCUTE_PLATFORM__'\n\n// eslint-disable-next-line\nlet _platform: ICorePlatform | null = (globalThis as any)?.[platformKey] ?? null\n\nexport function setPlatform(platform: ICorePlatform): void {\n if (_platform) {\n if (_platform.constructor !== platform.constructor) {\n throw new MtUnsupportedError('Platform may not be changed at runtime!')\n }\n\n return\n }\n\n _platform = platform\n TlBinaryReader.platform = platform\n TlBinaryWriter.platform = platform\n\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n ;(globalThis as any)[platformKey] = platform\n}\n\nexport function getPlatform(): ICorePlatform {\n if (!_platform) {\n throw new MtUnsupportedError('Platform is not set! Have you instantiated the client?')\n }\n\n return _platform\n}\n"]}
@@ -260,7 +260,7 @@ export class TelegramClient extends EventEmitter {
260
260
  this._client.onUpdate(makeParsedUpdateHandler({
261
261
  messageGroupingInterval,
262
262
  onUpdate: (update) => {
263
- if (Conversation.handleUpdate(this._client, update) && skipConversationUpdates)
263
+ if (Conversation.handleUpdate(this, update) && skipConversationUpdates)
264
264
  return;
265
265
  this.emit('update', update);
266
266
  this.emit(update.name, update.data);