@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/esm/platform.js CHANGED
@@ -1,13 +1,11 @@
1
1
  import { TlBinaryReader, TlBinaryWriter } from '@mtcute/tl-runtime';
2
2
  import { MtUnsupportedError } from './types/errors.js';
3
- // eslint-disable-next-line
4
- const globalObject = (0, eval)('this');
5
3
  // NB: when using with some bundlers (e.g. vite) re-importing this module will not return the same object
6
4
  // so we need to store the platform in a global object to be able to survive hot-reloads etc.
7
5
  // try to use Symbol if available, otherwise fallback to a string
8
6
  const platformKey = typeof Symbol !== 'undefined' ? Symbol.for('mtcute.platform') : '__MTCUTE_PLATFORM__';
9
- // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
10
- let _platform = globalObject?.[platformKey] ?? null;
7
+ // eslint-disable-next-line
8
+ let _platform = globalThis?.[platformKey] ?? null;
11
9
  export function setPlatform(platform) {
12
10
  if (_platform) {
13
11
  if (_platform.constructor !== platform.constructor) {
@@ -18,9 +16,7 @@ export function setPlatform(platform) {
18
16
  _platform = platform;
19
17
  TlBinaryReader.platform = platform;
20
18
  TlBinaryWriter.platform = platform;
21
- if (globalObject) {
22
- globalObject[platformKey] = platform;
23
- }
19
+ globalThis[platformKey] = platform;
24
20
  }
25
21
  export function getPlatform() {
26
22
  if (!_platform) {
@@ -1 +1 @@
1
- {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../src/platform.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAGhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;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,MAAM,UAAU,WAAW,CAAC,QAAuB;IAC/C,IAAI,SAAS,EAAE,CAAC;QACZ,IAAI,SAAS,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,IAAI,kBAAkB,CAAC,yCAAyC,CAAC,CAAA;QAC3E,CAAC;QAED,OAAM;IACV,CAAC;IAED,SAAS,GAAG,QAAQ,CAAA;IACpB,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAClC,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAElC,IAAI,YAAY,EAAE,CAAC;QACf,YAAY,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAA;IACxC,CAAC;AACL,CAAC;AAED,MAAM,UAAU,WAAW;IACvB,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,IAAI,kBAAkB,CAAC,wDAAwD,CAAC,CAAA;IAC1F,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC","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,OAAO,EAAe,cAAc,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAGhF,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAA;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,MAAM,UAAU,WAAW,CAAC,QAAuB;IAC/C,IAAI,SAAS,EAAE,CAAC;QACZ,IAAI,SAAS,CAAC,WAAW,KAAK,QAAQ,CAAC,WAAW,EAAE,CAAC;YACjD,MAAM,IAAI,kBAAkB,CAAC,yCAAyC,CAAC,CAAA;QAC3E,CAAC;QAED,OAAM;IACV,CAAC;IAED,SAAS,GAAG,QAAQ,CAAA;IACpB,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAAA;IAClC,cAAc,CAAC,QAAQ,GAAG,QAAQ,CAGjC;IAAC,UAAkB,CAAC,WAAW,CAAC,GAAG,QAAQ,CAAA;AAChD,CAAC;AAED,MAAM,UAAU,WAAW;IACvB,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,MAAM,IAAI,kBAAkB,CAAC,wDAAwD,CAAC,CAAA;IAC1F,CAAC;IAED,OAAO,SAAS,CAAA;AACpB,CAAC","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"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mtcute/core",
3
- "version": "0.12.2",
3
+ "version": "0.12.5",
4
4
  "description": "Type-safe library for MTProto (Telegram API)",
5
5
  "author": "alina sireneva <alina@tei.su>",
6
6
  "license": "MIT",