@mtcute/node 0.16.6 → 0.16.7

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.
Files changed (74) hide show
  1. package/cjs/client.d.ts +5 -3
  2. package/cjs/client.js +13 -14
  3. package/cjs/client.js.map +1 -1
  4. package/cjs/common-internals-node/exit-hook.js +1 -3
  5. package/cjs/common-internals-node/exit-hook.js.map +1 -1
  6. package/cjs/common-internals-node/logging.js +15 -15
  7. package/cjs/common-internals-node/logging.js.map +1 -1
  8. package/cjs/common-internals-node/platform.d.ts +1 -1
  9. package/cjs/common-internals-node/platform.js +3 -3
  10. package/cjs/common-internals-node/platform.js.map +1 -1
  11. package/cjs/methods/download-file.d.ts +1 -1
  12. package/cjs/methods/download-file.js +5 -6
  13. package/cjs/methods/download-file.js.map +1 -1
  14. package/cjs/methods/download-node-stream.d.ts +2 -2
  15. package/cjs/methods/download-node-stream.js +1 -2
  16. package/cjs/methods/download-node-stream.js.map +1 -1
  17. package/cjs/sqlite/driver.d.ts +3 -2
  18. package/cjs/sqlite/driver.js.map +1 -1
  19. package/cjs/sqlite/index.d.ts +1 -1
  20. package/cjs/sqlite/index.js.map +1 -1
  21. package/cjs/utils/crypto.d.ts +2 -1
  22. package/cjs/utils/crypto.js +11 -13
  23. package/cjs/utils/crypto.js.map +1 -1
  24. package/cjs/utils/normalize-file.d.ts +4 -8
  25. package/cjs/utils/normalize-file.js +10 -11
  26. package/cjs/utils/normalize-file.js.map +1 -1
  27. package/cjs/utils/stream-utils.d.ts +1 -1
  28. package/cjs/utils/stream-utils.js +9 -10
  29. package/cjs/utils/stream-utils.js.map +1 -1
  30. package/cjs/utils/tcp.d.ts +5 -4
  31. package/cjs/utils/tcp.js +8 -8
  32. package/cjs/utils/tcp.js.map +1 -1
  33. package/cjs/utils/version.js +3 -3
  34. package/cjs/utils/version.js.map +1 -1
  35. package/cjs/worker.d.ts +2 -1
  36. package/cjs/worker.js +7 -7
  37. package/cjs/worker.js.map +1 -1
  38. package/esm/client.d.ts +5 -3
  39. package/esm/client.js +12 -13
  40. package/esm/client.js.map +1 -1
  41. package/esm/common-internals-node/exit-hook.js +0 -1
  42. package/esm/common-internals-node/exit-hook.js.map +1 -1
  43. package/esm/common-internals-node/logging.js +15 -15
  44. package/esm/common-internals-node/logging.js.map +1 -1
  45. package/esm/common-internals-node/platform.d.ts +1 -1
  46. package/esm/common-internals-node/platform.js +3 -3
  47. package/esm/common-internals-node/platform.js.map +1 -1
  48. package/esm/methods/download-file.d.ts +1 -1
  49. package/esm/methods/download-file.js +2 -2
  50. package/esm/methods/download-file.js.map +1 -1
  51. package/esm/methods/download-node-stream.d.ts +2 -2
  52. package/esm/methods/download-node-stream.js.map +1 -1
  53. package/esm/sqlite/driver.d.ts +3 -2
  54. package/esm/sqlite/driver.js.map +1 -1
  55. package/esm/sqlite/index.d.ts +1 -1
  56. package/esm/sqlite/index.js.map +1 -1
  57. package/esm/utils/crypto.d.ts +2 -1
  58. package/esm/utils/crypto.js +4 -6
  59. package/esm/utils/crypto.js.map +1 -1
  60. package/esm/utils/normalize-file.d.ts +4 -8
  61. package/esm/utils/normalize-file.js +5 -5
  62. package/esm/utils/normalize-file.js.map +1 -1
  63. package/esm/utils/stream-utils.d.ts +1 -1
  64. package/esm/utils/stream-utils.js +3 -3
  65. package/esm/utils/stream-utils.js.map +1 -1
  66. package/esm/utils/tcp.d.ts +5 -4
  67. package/esm/utils/tcp.js +6 -6
  68. package/esm/utils/tcp.js.map +1 -1
  69. package/esm/utils/version.js +1 -1
  70. package/esm/utils/version.js.map +1 -1
  71. package/esm/worker.d.ts +2 -1
  72. package/esm/worker.js +4 -4
  73. package/esm/worker.js.map +1 -1
  74. package/package.json +7 -7
package/cjs/client.d.ts CHANGED
@@ -1,5 +1,7 @@
1
- import { FileDownloadLocation, FileDownloadParameters, ITelegramStorageProvider, PartialOnly, User } from '@mtcute/core';
2
- import { BaseTelegramClient as BaseTelegramClientBase, BaseTelegramClientOptions as BaseTelegramClientOptionsBase, TelegramClient as TelegramClientBase, TelegramClientOptions } from '@mtcute/core/client.js';
1
+ import type { Readable } from 'node:stream';
2
+ import type { FileDownloadLocation, FileDownloadParameters, ITelegramStorageProvider, PartialOnly, User } from '@mtcute/core';
3
+ import type { BaseTelegramClientOptions as BaseTelegramClientOptionsBase, TelegramClientOptions } from '@mtcute/core/client.js';
4
+ import { BaseTelegramClient as BaseTelegramClientBase, TelegramClient as TelegramClientBase } from '@mtcute/core/client.js';
3
5
  export type { TelegramClientOptions };
4
6
  export interface BaseTelegramClientOptions extends PartialOnly<Omit<BaseTelegramClientOptionsBase, 'storage'>, 'transport' | 'crypto'> {
5
7
  /**
@@ -42,5 +44,5 @@ export declare class TelegramClient extends TelegramClientBase {
42
44
  start(params?: Parameters<TelegramClientBase['start']>[0]): Promise<User>;
43
45
  run(params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>), then?: (user: User) => void | Promise<void>): void;
44
46
  downloadToFile(filename: string, location: FileDownloadLocation, params?: FileDownloadParameters | undefined): Promise<void>;
45
- downloadAsNodeStream(location: FileDownloadLocation, params?: FileDownloadParameters | undefined): import("stream").Readable;
47
+ downloadAsNodeStream(location: FileDownloadLocation, params?: FileDownloadParameters | undefined): Readable;
46
48
  }
package/cjs/client.js CHANGED
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TelegramClient = exports.BaseTelegramClient = void 0;
4
- const readline_1 = require("readline");
4
+ const node_readline_1 = require("node:readline");
5
5
  const client_js_1 = require("@mtcute/core/client.js");
6
6
  const platform_js_1 = require("@mtcute/core/platform.js");
7
7
  const platform_js_2 = require("./common-internals-node/platform.js");
@@ -10,18 +10,15 @@ const download_node_stream_js_1 = require("./methods/download-node-stream.js");
10
10
  const index_js_1 = require("./sqlite/index.js");
11
11
  const crypto_js_1 = require("./utils/crypto.js");
12
12
  const tcp_js_1 = require("./utils/tcp.js");
13
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
14
13
  let nativeCrypto;
15
14
  try {
16
- /* eslint-disable @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment */
17
- /* eslint-disable import/no-unresolved */
15
+ /* eslint-disable ts/ban-ts-comment,ts/no-unsafe-assignment */
18
16
  // @ts-ignore not in deps
19
17
  // @esm-replace-import
20
- nativeCrypto = (require('@mtcute/crypto-node')).NodeNativeCryptoProvider; // eslint-disable-line
21
- /* eslint-enable @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment */
22
- /* eslint-enable import/no-unresolved */
18
+ nativeCrypto = (require('@mtcute/crypto-node')).NodeNativeCryptoProvider;
19
+ /* eslint-enable ts/ban-ts-comment,ts/no-unsafe-assignment */
23
20
  }
24
- catch (e) { }
21
+ catch { }
25
22
  class BaseTelegramClient extends client_js_1.BaseTelegramClient {
26
23
  constructor(opts) {
27
24
  if (!opts.platformless)
@@ -31,9 +28,9 @@ class BaseTelegramClient extends client_js_1.BaseTelegramClient {
31
28
  crypto: nativeCrypto ? new nativeCrypto() : new crypto_js_1.NodeCryptoProvider(),
32
29
  transport: () => new tcp_js_1.TcpTransport(),
33
30
  ...opts,
34
- storage: typeof opts.storage === 'string' ?
35
- new index_js_1.SqliteStorage(opts.storage) :
36
- opts.storage ?? new index_js_1.SqliteStorage('client.session'),
31
+ storage: typeof opts.storage === 'string'
32
+ ? new index_js_1.SqliteStorage(opts.storage)
33
+ : opts.storage ?? new index_js_1.SqliteStorage('client.session'),
37
34
  });
38
35
  }
39
36
  }
@@ -50,6 +47,8 @@ class TelegramClient extends client_js_1.TelegramClient {
50
47
  super({
51
48
  client: new BaseTelegramClient(opts),
52
49
  disableUpdates: opts.disableUpdates,
50
+ skipConversationUpdates: opts.skipConversationUpdates,
51
+ updates: opts.updates,
53
52
  });
54
53
  }
55
54
  _rl;
@@ -64,12 +63,12 @@ class TelegramClient extends client_js_1.TelegramClient {
64
63
  */
65
64
  input(text) {
66
65
  if (!this._rl) {
67
- this._rl = (0, readline_1.createInterface)({
66
+ this._rl = (0, node_readline_1.createInterface)({
68
67
  input: process.stdin,
69
68
  output: process.stdout,
70
69
  });
71
70
  }
72
- return new Promise((res) => this._rl?.question(text, res));
71
+ return new Promise(res => this._rl?.question(text, res));
73
72
  }
74
73
  close() {
75
74
  this._rl?.close();
@@ -100,7 +99,7 @@ class TelegramClient extends client_js_1.TelegramClient {
100
99
  }
101
100
  this.start(params)
102
101
  .then(then)
103
- .catch((err) => this.emitError(err));
102
+ .catch(err => this.emitError(err));
104
103
  }
105
104
  downloadToFile(filename, location, params) {
106
105
  return (0, download_file_js_1.downloadToFile)(this, filename, location, params);
package/cjs/client.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AAAA,uCAAoE;AAGpE,sDAK+B;AAC/B,0DAAsD;AAEtD,qEAAkE;AAClE,iEAA2D;AAC3D,+EAAwE;AACxE,gDAAiD;AACjD,iDAAsD;AACtD,2CAA6C;AAI7C,8DAA8D;AAC9D,IAAI,YAAiB,CAAA;AAErB,IAAI,CAAC;IACD,iGAAiG;IACjG,yCAAyC;IACzC,0BAA0B;IAC1B,sBAAsB;IACtB,YAAY,GAAG,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,wBAAwB,CAAA,CAAC,sBAAsB;IAC/F,gGAAgG;IAChG,wCAAwC;AAC5C,CAAC;AAAC,OAAO,CAAC,EAAE,CAAC,CAAA,CAAC;AAuBd,MAAa,kBAAmB,SAAQ,8BAAsB;IAC1D,YAAY,IAA+B;QACvC,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,IAAA,yBAAW,EAAC,IAAI,0BAAY,EAAE,CAAC,CAAA;QAEvD,KAAK,CAAC;YACF,2BAA2B;YAC3B,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,8BAAkB,EAAE;Y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AAA,8CAAoB,EAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IACvD,CAAC;CACJ;AAvFD,wCAuFC","sourcesContent":["import { createInterface, Interface as RlInterface } from 'readline'\n\nimport { FileDownloadLocation, FileDownloadParameters, ITelegramStorageProvider, PartialOnly, User } from '@mtcute/core'\nimport {\n BaseTelegramClient as BaseTelegramClientBase,\n BaseTelegramClientOptions as BaseTelegramClientOptionsBase,\n TelegramClient as TelegramClientBase,\n TelegramClientOptions,\n} from '@mtcute/core/client.js'\nimport { setPlatform } from '@mtcute/core/platform.js'\n\nimport { NodePlatform } from './common-internals-node/platform.js'\nimport { downloadToFile } from './methods/download-file.js'\nimport { downloadAsNodeStream } from './methods/download-node-stream.js'\nimport { SqliteStorage } from './sqlite/index.js'\nimport { NodeCryptoProvider } from './utils/crypto.js'\nimport { TcpTransport } from './utils/tcp.js'\n\nexport type { TelegramClientOptions }\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nlet nativeCrypto: any\n\ntry {\n /* eslint-disable @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment */\n /* eslint-disable import/no-unresolved */\n // @ts-ignore not in deps\n // @esm-replace-import\n nativeCrypto = (require('@mtcute/crypto-node')).NodeNativeCryptoProvider // eslint-disable-line\n /* eslint-enable @typescript-eslint/prefer-ts-expect-error, @typescript-eslint/ban-ts-comment */\n /* eslint-enable import/no-unresolved */\n} catch (e) {}\n\nexport interface BaseTelegramClientOptions\n extends PartialOnly<Omit<BaseTelegramClientOptionsBase, 'storage'>, 'transport' | 'crypto'> {\n /**\n * Storage to use for this client.\n *\n * If a string is passed, it will be used as\n * a name for an SQLite database file.\n *\n * @default `\"client.session\"`\n */\n storage?: string | ITelegramStorageProvider\n\n /**\n * **ADVANCED USE ONLY**\n *\n * Whether to not set up the platform.\n * This is useful if you call `setPlatform` yourself.\n */\n platformless?: boolean\n}\n\nexport class BaseTelegramClient extends BaseTelegramClientBase {\n constructor(opts: BaseTelegramClientOptions) {\n if (!opts.platformless) setPlatform(new NodePlatform())\n\n super({\n // eslint-disable-next-line\n crypto: nativeCrypto ? new nativeCrypto() : new NodeCryptoProvider(),\n transport: () => new TcpTransport(),\n ...opts,\n storage:\n typeof opts.storage === 'string' ?\n new SqliteStorage(opts.storage) :\n opts.storage ?? new SqliteStorage('client.session'),\n })\n }\n}\n\n/**\n * Telegram client for use in Node.js\n */\nexport class TelegramClient extends TelegramClientBase {\n constructor(opts: TelegramClientOptions) {\n if ('client' in opts) {\n super(opts)\n\n return\n }\n\n super({\n client: new BaseTelegramClient(opts),\n disableUpdates: opts.disableUpdates,\n })\n }\n\n private _rl?: RlInterface\n\n /**\n * Tiny wrapper over Node `readline` package\n * for simpler user input for `.start()` method.\n *\n * Associated `readline` interface is closed\n * after `start()` returns, or with the client.\n *\n * @param text Text of the question\n */\n input(text: string): Promise<string> {\n if (!this._rl) {\n this._rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n }\n\n return new Promise((res) => this._rl?.question(text, res))\n }\n\n close(): Promise<void> {\n this._rl?.close()\n\n return super.close()\n }\n\n start(params: Parameters<TelegramClientBase['start']>[0] = {}): Promise<User> {\n if (!params.botToken) {\n if (!params.phone) params.phone = () => this.input('phone > ')\n if (!params.code) params.code = () => this.input('code > ')\n\n if (!params.password) {\n params.password = () => this.input('2fa password > ')\n }\n }\n\n return super.start(params).then((user) => {\n if (this._rl) {\n this._rl.close()\n delete this._rl\n }\n\n return user\n })\n }\n\n run(\n params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>),\n then?: (user: User) => void | Promise<void>,\n ): void {\n if (typeof params === 'function') {\n then = params\n params = {}\n }\n\n this.start(params)\n .then(then)\n .catch((err) => this.emitError(err))\n }\n\n downloadToFile(\n filename: string,\n location: FileDownloadLocation,\n params?: FileDownloadParameters | undefined,\n ): Promise<void> {\n return downloadToFile(this, filename, location, params)\n }\n\n downloadAsNodeStream(location: FileDownloadLocation, params?: FileDownloadParameters | undefined) {\n return downloadAsNodeStream(this, location, params)\n }\n}\n"]}
1
+ {"version":3,"file":"client.js","sourceRoot":"","sources":["../../src/client.ts"],"names":[],"mappings":";;;AACA,iDAA+C;AAQ/C,sDAG+B;AAC/B,0DAAsD;AAEtD,qEAAkE;AAClE,iEAA2D;AAC3D,+EAAwE;AACxE,gDAAiD;AACjD,iDAAsD;AACtD,2CAA6C;AAI7C,IAAI,YAAiB,CAAA;AAErB,IAAI,CAAC;IACD,8DAA8D;IAE9D,0BAA0B;IAC1B,sBAAsB;IACtB,YAAY,GAAG,CAAC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,wBAAwB,CAAA;IACxE,6DAA6D;AACjE,CAAC;AAAC,MAAM,CAAC,CAAA,CAAC;AAuBV,MAAa,kBAAmB,SAAQ,8BAAsB;IAC1D,YAAY,IAA+B;QACvC,IAAI,CAAC,IAAI,CAAC,YAAY;YAAE,IAAA,yBAAW,EAAC,IAAI,0BAAY,EAAE,CAAC,CAAA;QAEvD,KAAK,CAAC;YACF,2BAA2B;YAC3B,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC,IAAI,YAAY,EAAE,CAAC,CAAC,CAAC,IAAI,8BAAkB,EAAE;YACpE,SAAS,EAAE,GAAG,EAAE,CAAC,IAAI,qBAAY,EAAE;YACnC,GAAG,IAAI;YACP,OAAO,EACH,OAAO,IAAI,CAAC,OAAO,KAAK,QAAQ;gBAC5B,CAAC,CAAC,IAAI,wBAAa,CAAC,IAAI,CAAC,OAAO,CAAC;gBACjC,CAAC,CAAC,IAAI,CAAC,OAAO,IAAI,IAAI,wBAAa,CAAC,gBAAgB,CAAC;SAChE,CAAC,CAAA;IACN,CAAC;CACJ;AAfD,gDAeC;AAED;;GAEG;AACH,MAAa,cAAe,SAAQ,0BAAkB;IAClD,YAAY,IAA2B;QACnC,IAAI,QAAQ,IAAI,IAAI,EAAE,CAAC;YACnB,KAAK,CAAC,IAAI,CAAC,CAAA;YAEX,OAAM;QACV,CAAC;QA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AO,KAAK,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE;YACrC,IAAI,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAA;gBAChB,OAAO,IAAI,CAAC,GAAG,CAAA;YACnB,CAAC;YAED,OAAO,IAAI,CAAA;QACf,CAAC,CAAC,CAAA;IACN,CAAC;IAED,GAAG,CACC,MAAuF,EACvF,IAA2C;QAE3C,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YAC/B,IAAI,GAAG,MAAM,CAAA;YACb,MAAM,GAAG,EAAE,CAAA;QACf,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC;aACb,IAAI,CAAC,IAAI,CAAC;aACV,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1C,CAAC;IAED,cAAc,CACV,QAAgB,EAChB,QAA8B,EAC9B,MAA2C;QAE3C,OAAO,IAAA,iCAAc,EAAC,IAAI,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IAC3D,CAAC;IAED,oBAAoB,CAAC,QAA8B,EAAE,MAA2C;QAC5F,OAAO,IAAA,8CAAoB,EAAC,IAAI,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;IACvD,CAAC;CACJ;AAzFD,wCAyFC","sourcesContent":["import type { Interface as RlInterface } from 'node:readline'\nimport { createInterface } from 'node:readline'\nimport type { Readable } from 'node:stream'\n\nimport type { FileDownloadLocation, FileDownloadParameters, ITelegramStorageProvider, PartialOnly, User } from '@mtcute/core'\nimport type {\n BaseTelegramClientOptions as BaseTelegramClientOptionsBase,\n TelegramClientOptions,\n} from '@mtcute/core/client.js'\nimport {\n BaseTelegramClient as BaseTelegramClientBase,\n TelegramClient as TelegramClientBase,\n} from '@mtcute/core/client.js'\nimport { setPlatform } from '@mtcute/core/platform.js'\n\nimport { NodePlatform } from './common-internals-node/platform.js'\nimport { downloadToFile } from './methods/download-file.js'\nimport { downloadAsNodeStream } from './methods/download-node-stream.js'\nimport { SqliteStorage } from './sqlite/index.js'\nimport { NodeCryptoProvider } from './utils/crypto.js'\nimport { TcpTransport } from './utils/tcp.js'\n\nexport type { TelegramClientOptions }\n\nlet nativeCrypto: any\n\ntry {\n /* eslint-disable ts/ban-ts-comment,ts/no-unsafe-assignment */\n\n // @ts-ignore not in deps\n // @esm-replace-import\n nativeCrypto = (require('@mtcute/crypto-node')).NodeNativeCryptoProvider\n /* eslint-enable ts/ban-ts-comment,ts/no-unsafe-assignment */\n} catch {}\n\nexport interface BaseTelegramClientOptions\n extends PartialOnly<Omit<BaseTelegramClientOptionsBase, 'storage'>, 'transport' | 'crypto'> {\n /**\n * Storage to use for this client.\n *\n * If a string is passed, it will be used as\n * a name for an SQLite database file.\n *\n * @default `\"client.session\"`\n */\n storage?: string | ITelegramStorageProvider\n\n /**\n * **ADVANCED USE ONLY**\n *\n * Whether to not set up the platform.\n * This is useful if you call `setPlatform` yourself.\n */\n platformless?: boolean\n}\n\nexport class BaseTelegramClient extends BaseTelegramClientBase {\n constructor(opts: BaseTelegramClientOptions) {\n if (!opts.platformless) setPlatform(new NodePlatform())\n\n super({\n // eslint-disable-next-line\n crypto: nativeCrypto ? new nativeCrypto() : new NodeCryptoProvider(),\n transport: () => new TcpTransport(),\n ...opts,\n storage:\n typeof opts.storage === 'string'\n ? new SqliteStorage(opts.storage)\n : opts.storage ?? new SqliteStorage('client.session'),\n })\n }\n}\n\n/**\n * Telegram client for use in Node.js\n */\nexport class TelegramClient extends TelegramClientBase {\n constructor(opts: TelegramClientOptions) {\n if ('client' in opts) {\n super(opts)\n\n return\n }\n\n super({\n client: new BaseTelegramClient(opts),\n disableUpdates: opts.disableUpdates,\n skipConversationUpdates: opts.skipConversationUpdates,\n updates: opts.updates,\n })\n }\n\n private _rl?: RlInterface\n\n /**\n * Tiny wrapper over Node `readline` package\n * for simpler user input for `.start()` method.\n *\n * Associated `readline` interface is closed\n * after `start()` returns, or with the client.\n *\n * @param text Text of the question\n */\n input(text: string): Promise<string> {\n if (!this._rl) {\n this._rl = createInterface({\n input: process.stdin,\n output: process.stdout,\n })\n }\n\n return new Promise(res => this._rl?.question(text, res))\n }\n\n close(): Promise<void> {\n this._rl?.close()\n\n return super.close()\n }\n\n start(params: Parameters<TelegramClientBase['start']>[0] = {}): Promise<User> {\n if (!params.botToken) {\n if (!params.phone) params.phone = () => this.input('phone > ')\n if (!params.code) params.code = () => this.input('code > ')\n\n if (!params.password) {\n params.password = () => this.input('2fa password > ')\n }\n }\n\n return super.start(params).then((user) => {\n if (this._rl) {\n this._rl.close()\n delete this._rl\n }\n\n return user\n })\n }\n\n run(\n params: Parameters<TelegramClient['start']>[0] | ((user: User) => void | Promise<void>),\n then?: (user: User) => void | Promise<void>,\n ): void {\n if (typeof params === 'function') {\n then = params\n params = {}\n }\n\n this.start(params)\n .then(then)\n .catch(err => this.emitError(err))\n }\n\n downloadToFile(\n filename: string,\n location: FileDownloadLocation,\n params?: FileDownloadParameters | undefined,\n ): Promise<void> {\n return downloadToFile(this, filename, location, params)\n }\n\n downloadAsNodeStream(location: FileDownloadLocation, params?: FileDownloadParameters | undefined): Readable {\n return downloadAsNodeStream(this, location, params)\n }\n}\n"]}
@@ -1,11 +1,10 @@
1
1
  "use strict";
2
2
  // roughly based on https://github.com/sindresorhus/exit-hook/blob/main/index.js, MIT license
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.beforeExit = void 0;
4
+ exports.beforeExit = beforeExit;
5
5
  let installed = false;
6
6
  let handled = false;
7
7
  const callbacks = new Set();
8
- // eslint-disable-next-line func-call-spacing
9
8
  const myHandlers = new Map();
10
9
  function register(shouldManuallyExit, signal, event) {
11
10
  function eventHandler() {
@@ -43,5 +42,4 @@ function beforeExit(fn) {
43
42
  callbacks.delete(fn);
44
43
  };
45
44
  }
46
- exports.beforeExit = beforeExit;
47
45
  //# sourceMappingURL=exit-hook.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"exit-hook.js","sourceRoot":"","sources":["../../../src/common-internals-node/exit-hook.ts"],"names":[],"mappings":";AAAA,6FAA6F;;;AAE7F,IAAI,SAAS,GAAG,KAAK,CAAA;AACrB,IAAI,OAAO,GAAG,KAAK,CAAA;AAEnB,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;AACvC,6CAA6C;AAC7C,MAAM,UAAU,GAAG,IAAI,GAAG,EAAsB,CAAA;AAEhD,SAAS,QAAQ,CAAC,kBAA2B,EAAE,MAAc,EAAE,KAAa;IACxE,SAAS,YAAY;QACjB,IAAI,OAAO,EAAE,CAAC;YACV,OAAM;QACV,CAAC;QAED,OAAO,GAAG,IAAI,CAAA;QAEd,KAAK,MAAM,QAAQ,IAAI,SAAS,EAAE,CAAC;YAC/B,QAAQ,EAAE,CAAA;QACd,CAAC;QAED,KAAK,MAAM,CAAC,KAAK,EAAE,OAAO,CAAC,IAAI,UAAU,EAAE,CAAC;YACxC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAA;QAC/B,CAAC;QAED,IAAI,kBAAkB,EAAE,CAAC;YACrB,+CAA+C;YAC/C,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,MAAM,CAAC,CAAA;QACrC,CAAC;IACL,CAAC;IAED,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;IAC/B,UAAU,CAAC,GAAG,CAAC,KAAK,EAAE,YAAY,CAAC,CAAA;AACvC,CAAC;AAED,SAAgB,UAAU,CAAC,EAAc;IACrC,uBAAuB;IACvB,IAAI,OAAO,OAAO,KAAK,WAAW;QAAE,OAAO,GAAG,EAAE,GAAE,CAAC,CAAA;IAEnD,IAAI,CAAC,SAAS,EAAE,CAAC;QACb,SAAS,GAAG,IAAI,CAAA;QAEhB,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,YAAY,CAAC,CAAA;QAC/B,QAAQ,CAAC,IAAI,EAAE,CAAC,EAAE,QAAQ,CAAC,CAAA;QAC3B,QAAQ,CAAC,IAAI,EAAE,EAAE,EAAE,SAAS,CAAC,CAAA;QAC7B,QAAQ,CAAC,KAAK,EAAE,EAAE,EAAE,MAAM,CAAC,CAAA;IAC/B,CAAC;IAED,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAA;IAEjB,OAAO,GAAG,EAAE;QACR,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACxB,CAAC,CAAA;AACL,CAAC;AAlBD,gCAkBC","sourcesContent":["// roughly based on https://github.com/sindresorhus/exit-hook/blob/main/index.js, MIT license\n\nlet installed = false\nlet handled = false\n\nconst callbacks = new Set<() => void>()\n// eslint-disable-next-line func-call-spacing\nconst myHandlers = new Map<string, () => void>()\n\nfunction register(shouldManuallyExit: boolean, signal: number, event: string) {\n function eventHandler() {\n if (handled) {\n return\n }\n\n handled = true\n\n for (const callback of callbacks) {\n callback()\n }\n\n for (const [event, handler] of myHandlers) {\n process.off(event, handler)\n }\n\n if (shouldManuallyExit) {\n // send the signal again and let node handle it\n process.kill(process.pid, signal)\n }\n }\n\n process.on(event, eventHandler)\n myHandlers.set(event, eventHandler)\n}\n\nexport function beforeExit(fn: () => void): () => void {\n // unsupported platform\n if (typeof process === 'undefined') return () => {}\n\n if (!installed) {\n installed = true\n\n register(true, 0, 'beforeExit')\n register(true, 2, 'SIGINT')\n register(true, 15, 'SIGTERM')\n register(false, 15, 'exit')\n }\n\n callbacks.add(fn)\n\n return () => {\n callbacks.delete(fn)\n }\n}\n"]}
1
+ {"version":3,"file":"exit-hook.js","sourceRoot":"","sources":["../../../src/common-internals-node/exit-hook.ts"],"names":[],"mappings":";AAAA,6FAA6F;;AAmC7F,gCAkBC;AAnDD,IAAI,SAAS,GAAG,KAAK,CAAA;AACrB,IAAI,OAAO,GAAG,KAAK,CAAA;AAEnB,MAAM,SAA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E,CAAC,CAAA;IAEjB,OAAO,GAAG,EAAE;QACR,SAAS,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;IACxB,CAAC,CAAA;AACL,CAAC","sourcesContent":["// roughly based on https://github.com/sindresorhus/exit-hook/blob/main/index.js, MIT license\n\nlet installed = false\nlet handled = false\n\nconst callbacks = new Set<() => void>()\n\nconst myHandlers = new Map<string, () => void>()\n\nfunction register(shouldManuallyExit: boolean, signal: number, event: string) {\n function eventHandler() {\n if (handled) {\n return\n }\n\n handled = true\n\n for (const callback of callbacks) {\n callback()\n }\n\n for (const [event, handler] of myHandlers) {\n process.off(event, handler)\n }\n\n if (shouldManuallyExit) {\n // send the signal again and let node handle it\n process.kill(process.pid, signal)\n }\n }\n\n process.on(event, eventHandler)\n myHandlers.set(event, eventHandler)\n}\n\nexport function beforeExit(fn: () => void): () => void {\n // unsupported platform\n if (typeof process === 'undefined') return () => {}\n\n if (!installed) {\n installed = true\n\n register(true, 0, 'beforeExit')\n register(true, 2, 'SIGINT')\n register(true, 15, 'SIGTERM')\n register(false, 15, 'exit')\n }\n\n callbacks.add(fn)\n\n return () => {\n callbacks.delete(fn)\n }\n}\n"]}
@@ -2,17 +2,17 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.defaultLoggingHandler = void 0;
4
4
  const isTty = typeof process === 'object' && Boolean(process.stdout?.isTTY);
5
- const BASE_FORMAT = isTty ? '%s [%s] [%s%s\x1b[0m] ' : '%s [%s] [%s] ';
6
- const LEVEL_NAMES = isTty ?
7
- [
5
+ const BASE_FORMAT = isTty ? '%s [%s] [%s%s\x1B[0m] ' : '%s [%s] [%s] ';
6
+ const LEVEL_NAMES = isTty
7
+ ? [
8
8
  '', // OFF
9
- '\x1b[31mERR\x1b[0m',
10
- '\x1b[33mWRN\x1b[0m',
11
- '\x1b[34mINF\x1b[0m',
12
- '\x1b[36mDBG\x1b[0m',
13
- '\x1b[35mVRB\x1b[0m',
14
- ] :
15
- [
9
+ '\x1B[31mERR\x1B[0m',
10
+ '\x1B[33mWRN\x1B[0m',
11
+ '\x1B[34mINF\x1B[0m',
12
+ '\x1B[36mDBG\x1B[0m',
13
+ '\x1B[35mVRB\x1B[0m',
14
+ ]
15
+ : [
16
16
  '', // OFF
17
17
  'ERR',
18
18
  'WRN',
@@ -20,14 +20,14 @@ const LEVEL_NAMES = isTty ?
20
20
  'DBG',
21
21
  'VRB',
22
22
  ];
23
- const TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\x1b[3${i};1m`);
23
+ const TAG_COLORS = [6, 2, 3, 4, 5, 1].map(i => `\x1B[3${i};1m`);
24
24
  /** @internal */
25
- exports.defaultLoggingHandler = isTty ?
26
- (color, level, tag, fmt, args) => {
25
+ exports.defaultLoggingHandler = isTty
26
+ ? (color, level, tag, fmt, args) => {
27
27
  // eslint-disable-next-line no-console
28
28
  console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args);
29
- } :
30
- (color, level, tag, fmt, args) => {
29
+ }
30
+ : (color, level, tag, fmt, args) => {
31
31
  // eslint-disable-next-line no-console
32
32
  console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], tag, ...args);
33
33
  };
@@ -1 +1 @@
1
- {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../src/common-internals-node/logging.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAE3E,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,eAAe,CAAA;AACtE,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC;IACvB;QACI,EAAE,EAAE,MAAM;QACV,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;KACvB,CAAC,CAAC;IACH;QACI,EAAE,EAAE,MAAM;QACV,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACR,CAAA;AACL,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAEjE,gBAAgB;AACH,QAAA,qBAAqB,GAAG,KAAK,CAAC,CAAC;IACxC,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,IAAe,EAAQ,EAAE;QAC9E,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACjH,CAAC,CAAC,CAAC;IACH,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,IAAe,EAAQ,EAAE;QAC9E,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAC9F,CAAC,CAAA","sourcesContent":["const isTty = typeof process === 'object' && Boolean(process.stdout?.isTTY)\n\nconst BASE_FORMAT = isTty ? '%s [%s] [%s%s\\x1b[0m] ' : '%s [%s] [%s] '\nconst LEVEL_NAMES = isTty ?\n [\n '', // OFF\n '\\x1b[31mERR\\x1b[0m',\n '\\x1b[33mWRN\\x1b[0m',\n '\\x1b[34mINF\\x1b[0m',\n '\\x1b[36mDBG\\x1b[0m',\n '\\x1b[35mVRB\\x1b[0m',\n ] :\n [\n '', // OFF\n 'ERR',\n 'WRN',\n 'INF',\n 'DBG',\n 'VRB',\n ]\nconst TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\\x1b[3${i};1m`)\n\n/** @internal */\nexport const defaultLoggingHandler = isTty ?\n (color: number, level: number, tag: string, fmt: string, args: unknown[]): void => {\n // eslint-disable-next-line no-console\n console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args)\n } :\n (color: number, level: number, tag: string, fmt: string, args: unknown[]): void => {\n // eslint-disable-next-line no-console\n console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], tag, ...args)\n }\n"]}
1
+ {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../../src/common-internals-node/logging.ts"],"names":[],"mappings":";;;AAAA,MAAM,KAAK,GAAG,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,CAAC,OAAO,CAAC,MAAM,EAAE,KAAK,CAAC,CAAA;AAE3E,MAAM,WAAW,GAAG,KAAK,CAAC,CAAC,CAAC,wBAAwB,CAAC,CAAC,CAAC,eAAe,CAAA;AACtE,MAAM,WAAW,GAAG,KAAK;IACrB,CAAC,CAAC;QACE,EAAE,EAAE,MAAM;QACV,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;QACpB,oBAAoB;KACvB;IACD,CAAC,CAAC;QACE,EAAE,EAAE,MAAM;QACV,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;QACL,KAAK;KACR,CAAA;AACL,MAAM,UAAU,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;AAE/D,gBAAgB;AACH,QAAA,qBAAqB,GAMtB,KAAK;IACb,CAAC,CAAC,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,IAAe,EAAQ,EAAE;QAChF,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IACjH,CAAC;IACD,CAAC,CAAC,CAAC,KAAa,EAAE,KAAa,EAAE,GAAW,EAAE,GAAW,EAAE,IAAe,EAAQ,EAAE;QAChF,sCAAsC;QACtC,OAAO,CAAC,GAAG,CAAC,WAAW,GAAG,GAAG,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,WAAW,CAAC,KAAK,CAAC,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC,CAAA;IAC9F,CAAC,CAAA","sourcesContent":["const isTty = typeof process === 'object' && Boolean(process.stdout?.isTTY)\n\nconst BASE_FORMAT = isTty ? '%s [%s] [%s%s\\x1B[0m] ' : '%s [%s] [%s] '\nconst LEVEL_NAMES = isTty\n ? [\n '', // OFF\n '\\x1B[31mERR\\x1B[0m',\n '\\x1B[33mWRN\\x1B[0m',\n '\\x1B[34mINF\\x1B[0m',\n '\\x1B[36mDBG\\x1B[0m',\n '\\x1B[35mVRB\\x1B[0m',\n ]\n : [\n '', // OFF\n 'ERR',\n 'WRN',\n 'INF',\n 'DBG',\n 'VRB',\n ]\nconst TAG_COLORS = [6, 2, 3, 4, 5, 1].map(i => `\\x1B[3${i};1m`)\n\n/** @internal */\nexport const defaultLoggingHandler: (\n color: number,\n level: number,\n tag: string,\n fmt: string,\n args: unknown[]\n) => void = isTty\n ? (color: number, level: number, tag: string, fmt: string, args: unknown[]): void => {\n // eslint-disable-next-line no-console\n console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args)\n }\n : (color: number, level: number, tag: string, fmt: string, args: unknown[]): void => {\n // eslint-disable-next-line no-console\n console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], tag, ...args)\n }\n"]}
@@ -1,4 +1,4 @@
1
- import { ICorePlatform } from '@mtcute/core/platform.js';
1
+ import type { ICorePlatform } from '@mtcute/core/platform.js';
2
2
  import { normalizeFile } from '../utils/normalize-file.js';
3
3
  import { beforeExit } from './exit-hook.js';
4
4
  import { defaultLoggingHandler } from './logging.js';
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.NodePlatform = void 0;
27
- const os = __importStar(require("os"));
27
+ const os = __importStar(require("node:os"));
28
28
  const normalize_file_js_1 = require("../utils/normalize-file.js");
29
29
  const exit_hook_js_1 = require("./exit-hook.js");
30
30
  const logging_js_1 = require("./logging.js");
@@ -35,8 +35,8 @@ class NodePlatform {
35
35
  return `Node.js/${process.version} (${os.type()} ${os.arch()})`;
36
36
  }
37
37
  getDefaultLogLevel() {
38
- const envLogLevel = parseInt(process.env.MTCUTE_LOG_LEVEL ?? '');
39
- if (!isNaN(envLogLevel)) {
38
+ const envLogLevel = Number.parseInt(process.env.MTCUTE_LOG_LEVEL ?? '');
39
+ if (!Number.isNaN(envLogLevel)) {
40
40
  return envLogLevel;
41
41
  }
42
42
  return null;
@@ -1 +1 @@
1
- {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../../src/common-internals-node/platform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,uCAAwB;AAIxB,kEAA0D;AAC1D,iDAA2C;AAC3C,6CAAoD;AAEpD,MAAM,2BAA2B,GAAG,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AAE7G,MAAM,QAAQ,GAAG,CAAC,GAAe,EAAU,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,UAAU,EAAE,GAAG,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AG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAE7E,OAAO,GAAG,CAAA;IACd,CAAC;IACD,YAAY,CAAC,MAAc,EAAE,GAAG,GAAG,KAAK;QACpC,IAAI,GAAG,IAAI,2BAA2B,EAAE,CAAC;YACrC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QAC3C,CAAC;QAED,IAAI,GAAG,EAAE,CAAC;YACN,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;YACrD,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAM,IAAI,GAAG,CAAA;QAC3C,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACxC,CAAC;CACJ;AA5DD,oCA4DC;AAED,YAAY,CAAC,SAAS,CAAC,GAAG,GAAG,kCAAqB,CAAA;AAClD,YAAY,CAAC,SAAS,CAAC,UAAU,GAAG,yBAAU,CAAA;AAC9C,YAAY,CAAC,SAAS,CAAC,aAAa,GAAG,iCAAa,CAAA","sourcesContent":["import * as os from 'os'\n\nimport { ICorePlatform } from '@mtcute/core/platform.js'\n\nimport { normalizeFile } from '../utils/normalize-file.js'\nimport { beforeExit } from './exit-hook.js'\nimport { defaultLoggingHandler } from './logging.js'\n\nconst BUFFER_BASE64_URL_AVAILABLE = typeof Buffer.isEncoding === 'function' && Buffer.isEncoding('base64url')\n\nconst toBuffer = (buf: Uint8Array): Buffer => Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)\n\nexport class NodePlatform implements ICorePlatform {\n // ICorePlatform\n declare log: typeof defaultLoggingHandler\n declare beforeExit: typeof beforeExit\n declare normalizeFile: typeof normalizeFile\n\n getDeviceModel(): string {\n return `Node.js/${process.version} (${os.type()} ${os.arch()})`\n }\n\n getDefaultLogLevel(): number | null {\n const envLogLevel = parseInt(process.env.MTCUTE_LOG_LEVEL ?? '')\n\n if (!isNaN(envLogLevel)) {\n return envLogLevel\n }\n\n return null\n }\n\n // ITlPlatform\n utf8ByteLength(str: string): number {\n return Buffer.byteLength(str, 'utf8')\n }\n utf8Encode(str: string): Uint8Array {\n return Buffer.from(str, 'utf8')\n }\n utf8Decode(buf: Uint8Array): string {\n return toBuffer(buf).toString('utf8')\n }\n\n hexEncode(buf: Uint8Array): string {\n return toBuffer(buf).toString('hex')\n }\n hexDecode(str: string): Uint8Array {\n return Buffer.from(str, 'hex')\n }\n\n base64Encode(buf: Uint8Array, url = false): string {\n const nodeBuffer = toBuffer(buf)\n\n if (url && BUFFER_BASE64_URL_AVAILABLE) return nodeBuffer.toString('base64url')\n\n const str = nodeBuffer.toString('base64')\n if (url) return str.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '')\n\n return str\n }\n base64Decode(string: string, url = false): Uint8Array {\n if (url && BUFFER_BASE64_URL_AVAILABLE) {\n return Buffer.from(string, 'base64url')\n }\n\n if (url) {\n string = string.replace(/-/g, '+').replace(/_/g, '/')\n while (string.length % 4) string += '='\n }\n\n return Buffer.from(string, 'base64')\n }\n}\n\nNodePlatform.prototype.log = defaultLoggingHandler\nNodePlatform.prototype.beforeExit = beforeExit\nNodePlatform.prototype.normalizeFile = normalizeFile\n"]}
1
+ {"version":3,"file":"platform.js","sourceRoot":"","sources":["../../../src/common-internals-node/platform.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,4CAA6B;AAI7B,kEAA0D;AAE1D,iDAA2C;AAC3C,6CAAoD;AAEpD,MAAM,2BAA2B,GAAG,OAAO,MAAM,CAAC,UAAU,KAAK,UAAU,IAAI,MAAM,CAAC,UAAU,CAAC,WAAW,CAAC,CAAA;AAE7G,MAAM,QAAQ,GA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AC,QAAQ,CAAC,WAAW,CAAC,CAAA;QAE/E,MAAM,GAAG,GAAG,UAAU,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAA;QACzC,IAAI,GAAG;YAAE,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;QAE7E,OAAO,GAAG,CAAA;IACd,CAAC;IAED,YAAY,CAAC,MAAc,EAAE,GAAG,GAAG,KAAK;QACpC,IAAI,GAAG,IAAI,2BAA2B,EAAE,CAAC;YACrC,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;QAC3C,CAAC;QAED,IAAI,GAAG,EAAE,CAAC;YACN,MAAM,GAAG,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,GAAG,CAAC,CAAA;YACrD,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC;gBAAE,MAAM,IAAI,GAAG,CAAA;QAC3C,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAA;IACxC,CAAC;CACJ;AAhED,oCAgEC;AAED,YAAY,CAAC,SAAS,CAAC,GAAG,GAAG,kCAAqB,CAAA;AAClD,YAAY,CAAC,SAAS,CAAC,UAAU,GAAG,yBAAU,CAAA;AAC9C,YAAY,CAAC,SAAS,CAAC,aAAa,GAAG,iCAAa,CAAA","sourcesContent":["import * as os from 'node:os'\n\nimport type { ICorePlatform } from '@mtcute/core/platform.js'\n\nimport { normalizeFile } from '../utils/normalize-file.js'\n\nimport { beforeExit } from './exit-hook.js'\nimport { defaultLoggingHandler } from './logging.js'\n\nconst BUFFER_BASE64_URL_AVAILABLE = typeof Buffer.isEncoding === 'function' && Buffer.isEncoding('base64url')\n\nconst toBuffer = (buf: Uint8Array): Buffer => Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength)\n\nexport class NodePlatform implements ICorePlatform {\n // ICorePlatform\n declare log: typeof defaultLoggingHandler\n declare beforeExit: typeof beforeExit\n declare normalizeFile: typeof normalizeFile\n\n getDeviceModel(): string {\n return `Node.js/${process.version} (${os.type()} ${os.arch()})`\n }\n\n getDefaultLogLevel(): number | null {\n const envLogLevel = Number.parseInt(process.env.MTCUTE_LOG_LEVEL ?? '')\n\n if (!Number.isNaN(envLogLevel)) {\n return envLogLevel\n }\n\n return null\n }\n\n // ITlPlatform\n utf8ByteLength(str: string): number {\n return Buffer.byteLength(str, 'utf8')\n }\n\n utf8Encode(str: string): Uint8Array {\n return Buffer.from(str, 'utf8')\n }\n\n utf8Decode(buf: Uint8Array): string {\n return toBuffer(buf).toString('utf8')\n }\n\n hexEncode(buf: Uint8Array): string {\n return toBuffer(buf).toString('hex')\n }\n\n hexDecode(str: string): Uint8Array {\n return Buffer.from(str, 'hex')\n }\n\n base64Encode(buf: Uint8Array, url = false): string {\n const nodeBuffer = toBuffer(buf)\n\n if (url && BUFFER_BASE64_URL_AVAILABLE) return nodeBuffer.toString('base64url')\n\n const str = nodeBuffer.toString('base64')\n if (url) return str.replace(/\\+/g, '-').replace(/\\//g, '_').replace(/=/g, '')\n\n return str\n }\n\n base64Decode(string: string, url = false): Uint8Array {\n if (url && BUFFER_BASE64_URL_AVAILABLE) {\n return Buffer.from(string, 'base64url')\n }\n\n if (url) {\n string = string.replace(/-/g, '+').replace(/_/g, '/')\n while (string.length % 4) string += '='\n }\n\n return Buffer.from(string, 'base64')\n }\n}\n\nNodePlatform.prototype.log = defaultLoggingHandler\nNodePlatform.prototype.beforeExit = beforeExit\nNodePlatform.prototype.normalizeFile = normalizeFile\n"]}
@@ -1,4 +1,4 @@
1
- import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
1
+ import type { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
2
2
  /**
3
3
  * Download a remote file to a local file (only for NodeJS).
4
4
  * Promise will resolve once the download is complete.
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadToFile = void 0;
4
- const fs_1 = require("fs");
5
- const promises_1 = require("fs/promises");
3
+ exports.downloadToFile = downloadToFile;
4
+ const node_fs_1 = require("node:fs");
5
+ const promises_1 = require("node:fs/promises");
6
6
  const core_1 = require("@mtcute/core");
7
7
  const methods_js_1 = require("@mtcute/core/methods.js");
8
8
  /**
@@ -17,12 +17,12 @@ async function downloadToFile(client, filename, location, params) {
17
17
  // early return for inline files
18
18
  await (0, promises_1.writeFile)(filename, location.location);
19
19
  }
20
- const output = (0, fs_1.createWriteStream)(filename);
20
+ const output = (0, node_fs_1.createWriteStream)(filename);
21
21
  if (params?.abortSignal) {
22
22
  params.abortSignal.addEventListener('abort', () => {
23
23
  client.log.debug('aborting file download %s - cleaning up', filename);
24
24
  output.destroy();
25
- (0, fs_1.rmSync)(filename);
25
+ (0, node_fs_1.rmSync)(filename);
26
26
  });
27
27
  }
28
28
  for await (const chunk of (0, methods_js_1.downloadAsIterable)(client, location, params)) {
@@ -30,5 +30,4 @@ async function downloadToFile(client, filename, location, params) {
30
30
  }
31
31
  output.end();
32
32
  }
33
- exports.downloadToFile = downloadToFile;
34
33
  //# sourceMappingURL=download-file.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"download-file.js","sourceRoot":"","sources":["../../../src/methods/download-file.ts"],"names":[],"mappings":";;;AAAA,2BAA8C;AAC9C,0CAAuC;AAEvC,uCAA0G;AAC1G,wDAA4D;AAE5D;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAChC,MAAuB,EACvB,QAAgB,EAChB,QAA8B,EAC9B,MAA+B;IAE/B,IAAI,QAAQ,YAAY,mBAAY,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5E,gCAAgC;QAChC,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,MAAM,GAAG,IAAA,sBAAiB,EAAC,QAAQ,CAAC,CAAA;IAE1C,IAAI,MAAM,EAAE,WAAW,EAAE,CAAC;QACtB,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAC9C,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,yCAAyC,EAAE,QAAQ,CAAC,CAAA;YACrE,MAAM,CAAC,OAAO,EAAE,CAAA;YAChB,IAAA,WAAM,EAAC,QAAQ,CAAC,CAAA;QACpB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAA,+BAAkB,EAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;QACrE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC;IAED,MAAM,CAAC,GAAG,EAAE,CAAA;AAChB,CAAC;AA1BD,wCA0BC","sourcesContent":["import { createWriteStream, rmSync } from 'fs'\nimport { writeFile } from 'fs/promises'\n\nimport { FileDownloadLocation, FileDownloadParameters, FileLocation, ITelegramClient } from '@mtcute/core'\nimport { downloadAsIterable } from '@mtcute/core/methods.js'\n\n/**\n * Download a remote file to a local file (only for NodeJS).\n * Promise will resolve once the download is complete.\n *\n * @param filename Local file name to which the remote file will be downloaded\n * @param params File download parameters\n */\nexport async function downloadToFile(\n client: ITelegramClient,\n filename: string,\n location: FileDownloadLocation,\n params?: FileDownloadParameters,\n): Promise<void> {\n if (location instanceof FileLocation && ArrayBuffer.isView(location.location)) {\n // early return for inline files\n await writeFile(filename, location.location)\n }\n\n const output = createWriteStream(filename)\n\n if (params?.abortSignal) {\n params.abortSignal.addEventListener('abort', () => {\n client.log.debug('aborting file download %s - cleaning up', filename)\n output.destroy()\n rmSync(filename)\n })\n }\n\n for await (const chunk of downloadAsIterable(client, location, params)) {\n output.write(chunk)\n }\n\n output.end()\n}\n"]}
1
+ {"version":3,"file":"download-file.js","sourceRoot":"","sources":["../../../src/methods/download-file.ts"],"names":[],"mappings":";;AAcA,wCA0BC;AAxCD,qCAAmD;AACnD,+CAA4C;AAG5C,uCAA2C;AAC3C,wDAA4D;AAE5D;;;;;;GAMG;AACI,KAAK,UAAU,cAAc,CAChC,MAAuB,EACvB,QAAgB,EAChB,QAA8B,EAC9B,MAA+B;IAE/B,IAAI,QAAQ,YAAY,mBAAY,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5E,gCAAgC;QAChC,MAAM,IAAA,oBAAS,EAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,MAAM,GAAG,IAAA,2BAAiB,EAAC,QAAQ,CAAC,CAAA;IAE1C,IAAI,MAAM,EAAE,WAAW,EAAE,CAAC;QACtB,MAAM,CAAC,WAAW,CAAC,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE;YAC9C,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,yCAAyC,EAAE,QAAQ,CAAC,CAAA;YACrE,MAAM,CAAC,OAAO,EAAE,CAAA;YAChB,IAAA,gBAAM,EAAC,QAAQ,CAAC,CAAA;QACpB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,IAAA,+BAAkB,EAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,CAAC;QACrE,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;IACvB,CAAC;IAED,MAAM,CAAC,GAAG,EAAE,CAAA;AAChB,CAAC","sourcesContent":["import { createWriteStream, rmSync } from 'node:fs'\nimport { writeFile } from 'node:fs/promises'\n\nimport type { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core'\nimport { FileLocation } from '@mtcute/core'\nimport { downloadAsIterable } from '@mtcute/core/methods.js'\n\n/**\n * Download a remote file to a local file (only for NodeJS).\n * Promise will resolve once the download is complete.\n *\n * @param filename Local file name to which the remote file will be downloaded\n * @param params File download parameters\n */\nexport async function downloadToFile(\n client: ITelegramClient,\n filename: string,\n location: FileDownloadLocation,\n params?: FileDownloadParameters,\n): Promise<void> {\n if (location instanceof FileLocation && ArrayBuffer.isView(location.location)) {\n // early return for inline files\n await writeFile(filename, location.location)\n }\n\n const output = createWriteStream(filename)\n\n if (params?.abortSignal) {\n params.abortSignal.addEventListener('abort', () => {\n client.log.debug('aborting file download %s - cleaning up', filename)\n output.destroy()\n rmSync(filename)\n })\n }\n\n for await (const chunk of downloadAsIterable(client, location, params)) {\n output.write(chunk)\n }\n\n output.end()\n}\n"]}
@@ -1,5 +1,5 @@
1
- import { Readable } from 'stream';
2
- import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
1
+ import type { Readable } from 'node:stream';
2
+ import type { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
3
3
  /**
4
4
  * Download a remote file as a Node.js Readable stream.
5
5
  *
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.downloadAsNodeStream = void 0;
3
+ exports.downloadAsNodeStream = downloadAsNodeStream;
4
4
  const methods_js_1 = require("@mtcute/core/methods.js");
5
5
  const stream_utils_js_1 = require("../utils/stream-utils.js");
6
6
  /**
@@ -11,5 +11,4 @@ const stream_utils_js_1 = require("../utils/stream-utils.js");
11
11
  function downloadAsNodeStream(client, location, params) {
12
12
  return (0, stream_utils_js_1.webStreamToNode)((0, methods_js_1.downloadAsStream)(client, location, params));
13
13
  }
14
- exports.downloadAsNodeStream = downloadAsNodeStream;
15
14
  //# sourceMappingURL=download-node-stream.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"download-node-stream.js","sourceRoot":"","sources":["../../../src/methods/download-node-stream.ts"],"names":[],"mappings":";;;AAGA,wDAA0D;AAE1D,8DAA0D;AAE1D;;;;GAIG;AACH,SAAgB,oBAAoB,CAChC,MAAuB,EACvB,QAA8B,EAC9B,MAA+B;IAE/B,OAAO,IAAA,iCAAe,EAAC,IAAA,6BAAgB,EAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;AACtE,CAAC;AAND,oDAMC","sourcesContent":["import { Readable } from 'stream'\n\nimport { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core'\nimport { downloadAsStream } from '@mtcute/core/methods.js'\n\nimport { webStreamToNode } from '../utils/stream-utils.js'\n\n/**\n * Download a remote file as a Node.js Readable stream.\n *\n * @param params File download parameters\n */\nexport function downloadAsNodeStream(\n client: ITelegramClient,\n location: FileDownloadLocation,\n params?: FileDownloadParameters,\n): Readable {\n return webStreamToNode(downloadAsStream(client, location, params))\n}\n"]}
1
+ {"version":3,"file":"download-node-stream.js","sourceRoot":"","sources":["../../../src/methods/download-node-stream.ts"],"names":[],"mappings":";;AAYA,oDAMC;AAfD,wDAA0D;AAE1D,8DAA0D;AAE1D;;;;GAIG;AACH,SAAgB,oBAAoB,CAChC,MAAuB,EACvB,QAA8B,EAC9B,MAA+B;IAE/B,OAAO,IAAA,iCAAe,EAAC,IAAA,6BAAgB,EAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;AACtE,CAAC","sourcesContent":["import type { Readable } from 'node:stream'\n\nimport type { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core'\nimport { downloadAsStream } from '@mtcute/core/methods.js'\n\nimport { webStreamToNode } from '../utils/stream-utils.js'\n\n/**\n * Download a remote file as a Node.js Readable stream.\n *\n * @param params File download parameters\n */\nexport function downloadAsNodeStream(\n client: ITelegramClient,\n location: FileDownloadLocation,\n params?: FileDownloadParameters,\n): Readable {\n return webStreamToNode(downloadAsStream(client, location, params))\n}\n"]}
@@ -1,5 +1,6 @@
1
- import { Options } from 'better-sqlite3';
2
- import { BaseSqliteStorageDriver, ISqliteDatabase } from '@mtcute/core';
1
+ import type { Options } from 'better-sqlite3';
2
+ import type { ISqliteDatabase } from '@mtcute/core';
3
+ import { BaseSqliteStorageDriver } from '@mtcute/core';
3
4
  export interface SqliteStorageDriverOptions {
4
5
  /**
5
6
  * By default, WAL mode is enabled, which
@@ -1 +1 @@
1
- {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/sqlite/driver.ts"],"names":[],"mappings":";;;;;;AAAA,oEAAiD;AAEjD,uCAAuE;AAqBvE,MAAa,mBAAoB,SAAQ,8BAAuB;IAE/C;IACA;IAFb,YACa,WAAW,UAAU,EACrB,MAAmC;QAE5C,KAAK,EAAE,CAAA;QAHE,aAAQ,GAAR,QAAQ,CAAa;QACrB,WAAM,GAAN,MAAM,CAA6B;IAGhD,CAAC;IAED,eAAe;QACX,MAAM,EAAE,GAAG,IAAA,wBAAO,EAAC,IAAI,CAAC,QAAQ,EAAE;YAC9B,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO;YACvB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,OAA8B,CAAC,CAAC,CAAC,SAAS;SAC5F,CAAC,CAAA;QAEF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;YAC3B,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;QACnC,CAAC;QAED,OAAO,EAAqB,CAAA;IAChC,CAAC;CACJ;AApBD,kDAoBC","sourcesContent":["import sqlite3, { Options } from 'better-sqlite3'\n\nimport { BaseSqliteStorageDriver, ISqliteDatabase } from '@mtcute/core'\n\nexport interface SqliteStorageDriverOptions {\n /**\n * By default, WAL mode is enabled, which\n * significantly improves performance.\n * [Learn more](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/performance.md)\n *\n * However, you might encounter some issues,\n * and if you do, you can disable WAL by passing `true`\n *\n * @default false\n */\n disableWal?: boolean\n\n /**\n * Additional options to pass to `better-sqlite3`\n */\n options?: Options\n}\n\nexport class SqliteStorageDriver extends BaseSqliteStorageDriver {\n constructor(\n readonly filename = ':memory:',\n readonly params?: SqliteStorageDriverOptions,\n ) {\n super()\n }\n\n _createDatabase(): ISqliteDatabase {\n const db = sqlite3(this.filename, {\n ...this.params?.options,\n verbose: this._log.mgr.level >= 5 ? (this._log.verbose as Options['verbose']) : undefined,\n })\n\n if (!this.params?.disableWal) {\n db.pragma('journal_mode = WAL')\n }\n\n return db as ISqliteDatabase\n }\n}\n"]}
1
+ {"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/sqlite/driver.ts"],"names":[],"mappings":";;;;;;AACA,oEAAoC;AAEpC,uCAAsD;AAqBtD,MAAa,mBAAoB,SAAQ,8BAAuB;IAE/C;IACA;IAFb,YACa,WAAW,UAAU,EACrB,MAA+C;QAExD,KAAK,EAAE,CAAA;QAHE,aAAQ,GAAR,QAAQ,CAAa;QACrB,WAAM,GAAN,MAAM,CAAyC;IAG5D,CAAC;IAED,eAAe;QACX,MAAM,EAAE,GAAG,IAAA,wBAAO,EAAC,IAAI,CAAC,QAAQ,EAAE;YAC9B,GAAG,IAAI,CAAC,MAAM,EAAE,OAAO;YACvB,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAE,IAAI,CAAC,IAAI,CAAC,OAA8B,CAAC,CAAC,CAAC,SAAS;SAC5F,CAAC,CAAA;QAEF,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,EAAE,CAAC;YAC3B,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAA;QACnC,CAAC;QAED,OAAO,EAAqB,CAAA;IAChC,CAAC;CACJ;AApBD,kDAoBC","sourcesContent":["import type { Options } from 'better-sqlite3'\nimport sqlite3 from 'better-sqlite3'\nimport type { ISqliteDatabase } from '@mtcute/core'\nimport { BaseSqliteStorageDriver } from '@mtcute/core'\n\nexport interface SqliteStorageDriverOptions {\n /**\n * By default, WAL mode is enabled, which\n * significantly improves performance.\n * [Learn more](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/performance.md)\n *\n * However, you might encounter some issues,\n * and if you do, you can disable WAL by passing `true`\n *\n * @default false\n */\n disableWal?: boolean\n\n /**\n * Additional options to pass to `better-sqlite3`\n */\n options?: Options\n}\n\nexport class SqliteStorageDriver extends BaseSqliteStorageDriver {\n constructor(\n readonly filename = ':memory:',\n readonly params?: SqliteStorageDriverOptions | undefined,\n ) {\n super()\n }\n\n _createDatabase(): ISqliteDatabase {\n const db = sqlite3(this.filename, {\n ...this.params?.options,\n verbose: this._log.mgr.level >= 5 ? (this._log.verbose as Options['verbose']) : undefined,\n })\n\n if (!this.params?.disableWal) {\n db.pragma('journal_mode = WAL')\n }\n\n return db as ISqliteDatabase\n }\n}\n"]}
@@ -1,5 +1,5 @@
1
1
  import { BaseSqliteStorage } from '@mtcute/core';
2
- import { SqliteStorageDriverOptions } from './driver.js';
2
+ import type { SqliteStorageDriverOptions } from './driver.js';
3
3
  export { SqliteStorageDriver } from './driver.js';
4
4
  export declare class SqliteStorage extends BaseSqliteStorage {
5
5
  readonly filename: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sqlite/index.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAEhD,2CAA6E;AAE7E,yCAAiD;AAAxC,gHAAA,mBAAmB,OAAA;AAE5B,MAAa,aAAc,SAAQ,wBAAiB;IAEnC;IACA;IAFb,YACa,WAAW,UAAU,EACrB,MAAmC;QAE5C,KAAK,CAAC,IAAI,+BAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;QAHvC,aAAQ,GAAR,QAAQ,CAAa;QACrB,WAAM,GAAN,MAAM,CAA6B;IAGhD,CAAC;CACJ;AAPD,sCAOC","sourcesContent":["import { BaseSqliteStorage } from '@mtcute/core'\n\nimport { SqliteStorageDriver, SqliteStorageDriverOptions } from './driver.js'\n\nexport { SqliteStorageDriver } from './driver.js'\n\nexport class SqliteStorage extends BaseSqliteStorage {\n constructor(\n readonly filename = ':memory:',\n readonly params?: SqliteStorageDriverOptions,\n ) {\n super(new SqliteStorageDriver(filename, params))\n }\n}\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sqlite/index.ts"],"names":[],"mappings":";;;AAAA,uCAAgD;AAGhD,2CAAiD;AAEjD,yCAAiD;AAAxC,gHAAA,mBAAmB,OAAA;AAE5B,MAAa,aAAc,SAAQ,wBAAiB;IAEnC;IACA;IAFb,YACa,WAAW,UAAU,EACrB,MAA+C;QAExD,KAAK,CAAC,IAAI,+BAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;QAHvC,aAAQ,GAAR,QAAQ,CAAa;QACrB,WAAM,GAAN,MAAM,CAAyC;IAG5D,CAAC;CACJ;AAPD,sCAOC","sourcesContent":["import { BaseSqliteStorage } from '@mtcute/core'\n\nimport type { SqliteStorageDriverOptions } from './driver.js'\nimport { SqliteStorageDriver } from './driver.js'\n\nexport { SqliteStorageDriver } from './driver.js'\n\nexport class SqliteStorage extends BaseSqliteStorage {\n constructor(\n readonly filename = ':memory:',\n readonly params?: SqliteStorageDriverOptions | undefined,\n ) {\n super(new SqliteStorageDriver(filename, params))\n }\n}\n"]}
@@ -1,4 +1,5 @@
1
- import { BaseCryptoProvider, IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js';
1
+ import type { IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js';
2
+ import { BaseCryptoProvider } from '@mtcute/core/utils.js';
2
3
  export declare abstract class BaseNodeCryptoProvider extends BaseCryptoProvider {
3
4
  createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr;
4
5
  pbkdf2(password: Uint8Array, salt: Uint8Array, iterations: number, keylen?: number, algo?: string): Promise<Uint8Array>;
@@ -1,40 +1,38 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NodeCryptoProvider = exports.BaseNodeCryptoProvider = void 0;
4
- // eslint-disable-next-line no-restricted-imports
5
- const crypto_1 = require("crypto");
6
- const promises_1 = require("fs/promises");
7
- const zlib_1 = require("zlib");
4
+ const node_crypto_1 = require("node:crypto");
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_zlib_1 = require("node:zlib");
8
7
  const utils_js_1 = require("@mtcute/core/utils.js");
9
8
  const wasm_1 = require("@mtcute/wasm");
10
9
  class BaseNodeCryptoProvider extends utils_js_1.BaseCryptoProvider {
11
10
  createAesCtr(key, iv) {
12
- const cipher = (0, crypto_1.createCipheriv)(`aes-${key.length * 8}-ctr`, key, iv);
11
+ const cipher = (0, node_crypto_1.createCipheriv)(`aes-${key.length * 8}-ctr`, key, iv);
13
12
  const update = (data) => cipher.update(data);
14
13
  return {
15
14
  process: update,
16
15
  };
17
16
  }
18
17
  pbkdf2(password, salt, iterations, keylen = 64, algo = 'sha512') {
19
- return new Promise((resolve, reject) => (0, crypto_1.pbkdf2)(password, salt, iterations, keylen, algo, (err, buf) => err !== null ? reject(err) : resolve(buf)));
18
+ return new Promise((resolve, reject) => (0, node_crypto_1.pbkdf2)(password, salt, iterations, keylen, algo, (err, buf) => err !== null ? reject(err) : resolve(buf)));
20
19
  }
21
20
  sha1(data) {
22
- return (0, crypto_1.createHash)('sha1').update(data).digest();
21
+ return (0, node_crypto_1.createHash)('sha1').update(data).digest();
23
22
  }
24
23
  sha256(data) {
25
- return (0, crypto_1.createHash)('sha256').update(data).digest();
24
+ return (0, node_crypto_1.createHash)('sha256').update(data).digest();
26
25
  }
27
26
  hmacSha256(data, key) {
28
- return (0, crypto_1.createHmac)('sha256', key).update(data).digest();
27
+ return (0, node_crypto_1.createHmac)('sha256', key).update(data).digest();
29
28
  }
30
29
  gzip(data, maxSize) {
31
30
  try {
32
31
  // telegram accepts both zlib and gzip, but zlib is faster and has less overhead, so we use it here
33
- return (0, zlib_1.deflateSync)(data, {
32
+ return (0, node_zlib_1.deflateSync)(data, {
34
33
  maxOutputLength: maxSize,
35
34
  });
36
35
  // hot path, avoid additional runtime checks
37
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
38
36
  }
39
37
  catch (e) {
40
38
  if (e.code === 'ERR_BUFFER_TOO_LARGE') {
@@ -44,10 +42,10 @@ class BaseNodeCryptoProvider extends utils_js_1.BaseCryptoProvider {
44
42
  }
45
43
  }
46
44
  gunzip(data) {
47
- return (0, zlib_1.gunzipSync)(data);
45
+ return (0, node_zlib_1.gunzipSync)(data);
48
46
  }
49
47
  randomFill(buf) {
50
- (0, crypto_1.randomFillSync)(buf);
48
+ (0, node_crypto_1.randomFillSync)(buf);
51
49
  }
52
50
  }
53
51
  exports.BaseNodeCryptoProvider = BaseNodeCryptoProvider;
@@ -1 +1 @@
1
- {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":";;;AAAA,iDAAiD;AACjD,mCAAuF;AACvF,0CAAsC;AAEtC,+BAA8C;AAE9C,oDAAuG;AACvG,uCAAqE;AAErE,MAAsB,sBAAuB,SAAQ,6BAAkB;IACnE,YAAY,CAAC,GAAe,EAAE,EAAc;QACxC,MAAM,MAAM,GAAG,IAAA,uBAAc,EAAC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;QAEnE,MAAM,MAAM,GAAG,CAAC,IAAgB,EAAE,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;QAExD,OAAO;YACH,OAAO,EAAE,MAAM;SAClB,CAAA;IACL,CAAC;IAED,MAAM,CACF,QAAoB,EACpB,IAAgB,EAChB,UAAkB,EAClB,MAAM,GAAG,EAAE,EACX,IAAI,GAAG,QAAQ;QAEf,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,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C;CACJ;AA7DD,wDA6DC;AAED,MAAa,kBAAmB,SAAQ,sBAAsB;IAC1D,KAAK,CAAC,UAAU;QACZ,GAAG;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAA;QAC5D,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,CAAC,CAAA;QACrC,IAAA,eAAQ,EAAC,IAAI,CAAC,CAAA;IAClB,CAAC;IAED,YAAY,CAAC,GAAe,EAAE,EAAc;QACxC,OAAO;YACH,OAAO,CAAC,IAAgB;gBACpB,OAAO,IAAA,oBAAa,EAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;YACvC,CAAC;YACD,OAAO,CAAC,IAAgB;gBACpB,OAAO,IAAA,oBAAa,EAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;YACvC,CAAC;SACJ,CAAA;IACL,CAAC;CACJ;AAlBD,gDAkBC","sourcesContent":["// eslint-disable-next-line no-restricted-imports\nimport { createCipheriv, createHash, createHmac, pbkdf2, randomFillSync } from 'crypto'\nimport { readFile } from 'fs/promises'\nimport { createRequire } from 'module'\nimport { deflateSync, gunzipSync } from 'zlib'\n\nimport { BaseCryptoProvider, IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js'\nimport { ige256Decrypt, ige256Encrypt, initSync } from '@mtcute/wasm'\n\nexport abstract class BaseNodeCryptoProvider extends BaseCryptoProvider {\n createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr {\n const cipher = createCipheriv(`aes-${key.length * 8}-ctr`, key, iv)\n\n const update = (data: Uint8Array) => cipher.update(data)\n\n return {\n process: update,\n }\n }\n\n pbkdf2(\n password: Uint8Array,\n salt: Uint8Array,\n iterations: number,\n keylen = 64,\n algo = 'sha512',\n ): Promise<Uint8Array> {\n return new Promise((resolve, reject) =>\n pbkdf2(password, salt, iterations, keylen, algo, (err: Error | null, buf: Uint8Array) =>\n err !== null ? reject(err) : resolve(buf),\n ),\n )\n }\n\n sha1(data: Uint8Array): Uint8Array {\n return createHash('sha1').update(data).digest()\n }\n\n sha256(data: Uint8Array): Uint8Array {\n return createHash('sha256').update(data).digest()\n }\n\n hmacSha256(data: Uint8Array, key: Uint8Array): Uint8Array {\n return createHmac('sha256', key).update(data).digest()\n }\n\n gzip(data: Uint8Array, maxSize: number): Uint8Array | null {\n try {\n // telegram accepts both zlib and gzip, but zlib is faster and has less overhead, so we use it here\n return deflateSync(data, {\n maxOutputLength: maxSize,\n })\n // hot path, avoid additional runtime checks\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n } catch (e: any) {\n if (e.code === 'ERR_BUFFER_TOO_LARGE') {\n return null\n }\n\n throw e\n }\n }\n\n gunzip(data: Uint8Array): Uint8Array {\n return gunzipSync(data)\n }\n\n randomFill(buf: Uint8Array) {\n randomFillSync(buf)\n }\n}\n\nexport class NodeCryptoProvider extends BaseNodeCryptoProvider implements ICryptoProvider {\n async initialize(): Promise<void> {\n // \n const wasmFile = require.resolve('@mtcute/wasm/mtcute.wasm')\n const wasm = await readFile(wasmFile)\n initSync(wasm)\n }\n\n createAesIge(key: Uint8Array, iv: Uint8Array): IEncryptionScheme {\n return {\n encrypt(data: Uint8Array): Uint8Array {\n return ige256Encrypt(data, key, iv)\n },\n decrypt(data: Uint8Array): Uint8Array {\n return ige256Decrypt(data, key, iv)\n },\n }\n }\n}\n"]}
1
+ {"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":";;;AAAA,6CAA4F;AAC5F,+CAA2C;AAE3C,yCAAmD;AAGnD,oDAA0D;AAC1D,uCAAqE;AAErE,MAAsB,sBAAuB,SAAQ,6BAAkB;IACnE,YAAY,CAAC,GAAe,EAAE,EAAc;QACxC,MAAM,MAAM,GAAG,IAAA,4BAAc,EAAC,OAAO,GAAG,CAAC,MAAM,GAAG,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE,CAAC,CA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I,CAAC,CAAC,IAAI,KAAK,sBAAsB,EAAE,CAAC;gBACpC,OAAO,IAAI,CAAA;YACf,CAAC;YAED,MAAM,CAAC,CAAA;QACX,CAAC;IACL,CAAC;IAED,MAAM,CAAC,IAAgB;QACnB,OAAO,IAAA,sBAAU,EAAC,IAAI,CAAC,CAAA;IAC3B,CAAC;IAED,UAAU,CAAC,GAAe;QACtB,IAAA,4BAAc,EAAC,GAAG,CAAC,CAAA;IACvB,CAAC;CACJ;AA3DD,wDA2DC;AAED,MAAa,kBAAmB,SAAQ,sBAAsB;IAC1D,KAAK,CAAC,UAAU;QACZ,GAAG;QACH,MAAM,QAAQ,GAAG,OAAO,CAAC,OAAO,CAAC,0BAA0B,CAAC,CAAA;QAC5D,MAAM,IAAI,GAAG,MAAM,IAAA,mBAAQ,EAAC,QAAQ,CAAC,CAAA;QACrC,IAAA,eAAQ,EAAC,IAAI,CAAC,CAAA;IAClB,CAAC;IAED,YAAY,CAAC,GAAe,EAAE,EAAc;QACxC,OAAO;YACH,OAAO,CAAC,IAAgB;gBACpB,OAAO,IAAA,oBAAa,EAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;YACvC,CAAC;YACD,OAAO,CAAC,IAAgB;gBACpB,OAAO,IAAA,oBAAa,EAAC,IAAI,EAAE,GAAG,EAAE,EAAE,CAAC,CAAA;YACvC,CAAC;SACJ,CAAA;IACL,CAAC;CACJ;AAlBD,gDAkBC","sourcesContent":["import { createCipheriv, createHash, createHmac, pbkdf2, randomFillSync } from 'node:crypto'\nimport { readFile } from 'node:fs/promises'\nimport { createRequire } from 'node:module'\nimport { deflateSync, gunzipSync } from 'node:zlib'\n\nimport type { IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js'\nimport { BaseCryptoProvider } from '@mtcute/core/utils.js'\nimport { ige256Decrypt, ige256Encrypt, initSync } from '@mtcute/wasm'\n\nexport abstract class BaseNodeCryptoProvider extends BaseCryptoProvider {\n createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr {\n const cipher = createCipheriv(`aes-${key.length * 8}-ctr`, key, iv)\n\n const update = (data: Uint8Array) => cipher.update(data)\n\n return {\n process: update,\n }\n }\n\n pbkdf2(\n password: Uint8Array,\n salt: Uint8Array,\n iterations: number,\n keylen = 64,\n algo = 'sha512',\n ): Promise<Uint8Array> {\n return new Promise((resolve, reject) =>\n pbkdf2(password, salt, iterations, keylen, algo, (err: Error | null, buf: Uint8Array) =>\n err !== null ? reject(err) : resolve(buf)),\n )\n }\n\n sha1(data: Uint8Array): Uint8Array {\n return createHash('sha1').update(data).digest()\n }\n\n sha256(data: Uint8Array): Uint8Array {\n return createHash('sha256').update(data).digest()\n }\n\n hmacSha256(data: Uint8Array, key: Uint8Array): Uint8Array {\n return createHmac('sha256', key).update(data).digest()\n }\n\n gzip(data: Uint8Array, maxSize: number): Uint8Array | null {\n try {\n // telegram accepts both zlib and gzip, but zlib is faster and has less overhead, so we use it here\n return deflateSync(data, {\n maxOutputLength: maxSize,\n })\n // hot path, avoid additional runtime checks\n } catch (e: any) {\n if (e.code === 'ERR_BUFFER_TOO_LARGE') {\n return null\n }\n\n throw e\n }\n }\n\n gunzip(data: Uint8Array): Uint8Array {\n return gunzipSync(data)\n }\n\n randomFill(buf: Uint8Array): void {\n randomFillSync(buf)\n }\n}\n\nexport class NodeCryptoProvider extends BaseNodeCryptoProvider implements ICryptoProvider {\n async initialize(): Promise<void> {\n // \n const wasmFile = require.resolve('@mtcute/wasm/mtcute.wasm')\n const wasm = await readFile(wasmFile)\n initSync(wasm)\n }\n\n createAesIge(key: Uint8Array, iv: Uint8Array): IEncryptionScheme {\n return {\n encrypt(data: Uint8Array): Uint8Array {\n return ige256Encrypt(data, key, iv)\n },\n decrypt(data: Uint8Array): Uint8Array {\n return ige256Decrypt(data, key, iv)\n },\n }\n }\n}\n"]}
@@ -1,10 +1,6 @@
1
- import { UploadFileLike } from '@mtcute/core';
1
+ import type { UploadFileLike } from '@mtcute/core';
2
2
  export declare function normalizeFile(file: UploadFileLike): Promise<{
3
- file: ReadableStream<Uint8Array>;
4
- fileName: string;
5
- fileSize: number;
6
- } | {
7
- file: ReadableStream<Uint8Array>;
8
- fileName?: undefined;
9
- fileSize?: undefined;
3
+ file: UploadFileLike;
4
+ fileName?: string | undefined;
5
+ fileSize?: number;
10
6
  } | null>;
@@ -1,25 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.normalizeFile = void 0;
4
- const fs_1 = require("fs");
5
- const promises_1 = require("fs/promises");
6
- const path_1 = require("path");
7
- const stream_1 = require("stream");
3
+ exports.normalizeFile = normalizeFile;
4
+ const node_fs_1 = require("node:fs");
5
+ const promises_1 = require("node:fs/promises");
6
+ const node_path_1 = require("node:path");
7
+ const node_stream_1 = require("node:stream");
8
8
  const stream_utils_js_1 = require("./stream-utils.js");
9
9
  async function normalizeFile(file) {
10
10
  if (typeof file === 'string') {
11
- file = (0, fs_1.createReadStream)(file);
11
+ file = (0, node_fs_1.createReadStream)(file);
12
12
  }
13
- if (file instanceof fs_1.ReadStream) {
14
- const fileName = (0, path_1.basename)(file.path.toString());
15
- const fileSize = await (0, promises_1.stat)(file.path.toString()).then((stat) => stat.size);
13
+ if (file instanceof node_fs_1.ReadStream) {
14
+ const fileName = (0, node_path_1.basename)(file.path.toString());
15
+ const fileSize = await (0, promises_1.stat)(file.path.toString()).then(stat => stat.size);
16
16
  return {
17
17
  file: (0, stream_utils_js_1.nodeStreamToWeb)(file),
18
18
  fileName,
19
19
  fileSize,
20
20
  };
21
21
  }
22
- if (file instanceof stream_1.Readable) {
22
+ if (file instanceof node_stream_1.Readable) {
23
23
  return {
24
24
  file: (0, stream_utils_js_1.nodeStreamToWeb)(file),
25
25
  };
@@ -27,5 +27,4 @@ async function normalizeFile(file) {
27
27
  // string -> ReadStream, thus already handled
28
28
  return null;
29
29
  }
30
- exports.normalizeFile = normalizeFile;
31
30
  //# sourceMappingURL=normalize-file.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"normalize-file.js","sourceRoot":"","sources":["../../../src/utils/normalize-file.ts"],"names":[],"mappings":";;;AAAA,2BAAiD;AACjD,0CAAkC;AAClC,+BAA+B;AAC/B,mCAAiC;AAIjC,uDAAmD;AAE5C,KAAK,UAAU,aAAa,CAAC,IAAoB;IACpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,IAAI,GAAG,IAAA,qBAAgB,EAAC,IAAI,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,IAAI,YAAY,eAAU,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,IAAA,eAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC/C,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAE3E,OAAO;YACH,IAAI,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC;YAC3B,QAAQ;YACR,QAAQ;SACX,CAAA;IACL,CAAC;IAED,IAAI,IAAI,YAAY,iBAAQ,EAAE,CAAC;QAC3B,OAAO;YACH,IAAI,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC;SAC9B,CAAA;IACL,CAAC;IAED,6CAA6C;IAC7C,OAAO,IAAI,CAAA;AACf,CAAC;AAxBD,sCAwBC","sourcesContent":["import { createReadStream, ReadStream } from 'fs'\nimport { stat } from 'fs/promises'\nimport { basename } from 'path'\nimport { Readable } from 'stream'\n\nimport { UploadFileLike } from '@mtcute/core'\n\nimport { nodeStreamToWeb } from './stream-utils.js'\n\nexport async function normalizeFile(file: UploadFileLike) {\n if (typeof file === 'string') {\n file = createReadStream(file)\n }\n\n if (file instanceof ReadStream) {\n const fileName = basename(file.path.toString())\n const fileSize = await stat(file.path.toString()).then((stat) => stat.size)\n\n return {\n file: nodeStreamToWeb(file),\n fileName,\n fileSize,\n }\n }\n\n if (file instanceof Readable) {\n return {\n file: nodeStreamToWeb(file),\n }\n }\n\n // string -> ReadStream, thus already handled\n return null\n}\n"]}
1
+ {"version":3,"file":"normalize-file.js","sourceRoot":"","sources":["../../../src/utils/normalize-file.ts"],"names":[],"mappings":";;AASA,sCA4BC;AArCD,qCAAsD;AACtD,+CAAuC;AACvC,yCAAoC;AACpC,6CAAsC;AAItC,uDAAmD;AAE5C,KAAK,UAAU,aAAa,CAAC,IAAoB;IAKpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,IAAI,GAAG,IAAA,0BAAgB,EAAC,IAAI,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,IAAI,YAAY,oBAAU,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,IAAA,oBAAQ,EAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC/C,MAAM,QAAQ,GAAG,MAAM,IAAA,eAAI,EAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QAEzE,OAAO;YACH,IAAI,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC;YAC3B,QAAQ;YACR,QAAQ;SACX,CAAA;IACL,CAAC;IAED,IAAI,IAAI,YAAY,sBAAQ,EAAE,CAAC;QAC3B,OAAO;YACH,IAAI,EAAE,IAAA,iCAAe,EAAC,IAAI,CAAC;SAC9B,CAAA;IACL,CAAC;IAED,6CAA6C;IAC7C,OAAO,IAAI,CAAA;AACf,CAAC","sourcesContent":["import { ReadStream, createReadStream } from 'node:fs'\nimport { stat } from 'node:fs/promises'\nimport { basename } from 'node:path'\nimport { Readable } from 'node:stream'\n\nimport type { UploadFileLike } from '@mtcute/core'\n\nimport { nodeStreamToWeb } from './stream-utils.js'\n\nexport async function normalizeFile(file: UploadFileLike): Promise<{\n file: UploadFileLike\n fileName?: string | undefined\n fileSize?: number\n} | null> {\n if (typeof file === 'string') {\n file = createReadStream(file)\n }\n\n if (file instanceof ReadStream) {\n const fileName = basename(file.path.toString())\n const fileSize = await stat(file.path.toString()).then(stat => stat.size)\n\n return {\n file: nodeStreamToWeb(file),\n fileName,\n fileSize,\n }\n }\n\n if (file instanceof Readable) {\n return {\n file: nodeStreamToWeb(file),\n }\n }\n\n // string -> ReadStream, thus already handled\n return null\n}\n"]}
@@ -1,3 +1,3 @@
1
- import { Readable } from 'stream';
1
+ import { Readable } from 'node:stream';
2
2
  export declare function nodeStreamToWeb(stream: Readable): ReadableStream<Uint8Array>;
3
3
  export declare function webStreamToNode(stream: ReadableStream<Uint8Array>): Readable;