@mtcute/node 0.17.0 → 0.18.0

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 (67) hide show
  1. package/client.cjs +101 -0
  2. package/client.d.cts +40 -0
  3. package/client.d.ts +2 -9
  4. package/client.js +96 -0
  5. package/index.cjs +29 -423
  6. package/index.d.cts +2 -1
  7. package/index.d.ts +2 -1
  8. package/index.js +13 -397
  9. package/{chunks/cjs/BpvQ752Q.js → methods/download-file.cjs} +3 -7
  10. package/methods/download-file.d.cts +9 -0
  11. package/{chunks/es/CnOjjhdK.js → methods/download-file.js} +1 -6
  12. package/methods/download-node-stream.cjs +13 -0
  13. package/methods/download-node-stream.d.cts +8 -0
  14. package/methods/download-node-stream.d.ts +1 -1
  15. package/methods/download-node-stream.js +8 -0
  16. package/methods.cjs +5 -4
  17. package/methods.js +2 -1
  18. package/package.json +16 -13
  19. package/sqlite/driver.cjs +27 -0
  20. package/sqlite/driver.d.cts +25 -0
  21. package/sqlite/driver.d.ts +1 -1
  22. package/sqlite/driver.js +22 -0
  23. package/sqlite/index.cjs +18 -0
  24. package/sqlite/index.d.cts +8 -0
  25. package/sqlite/index.d.ts +1 -1
  26. package/sqlite/index.js +13 -0
  27. package/{chunks/cjs/D7i-4e0W.js → utils/crypto.cjs} +4 -3
  28. package/utils/crypto.d.cts +15 -0
  29. package/{chunks/es/HZgHrOPU.js → utils/crypto.js} +1 -1
  30. package/utils/exit-hook.cjs +46 -0
  31. package/utils/exit-hook.d.ts +1 -0
  32. package/utils/exit-hook.js +41 -0
  33. package/utils/logging.cjs +33 -0
  34. package/utils/logging.d.ts +2 -0
  35. package/utils/logging.js +28 -0
  36. package/utils/normalize-file.cjs +33 -0
  37. package/utils/normalize-file.d.cts +6 -0
  38. package/utils/normalize-file.js +28 -0
  39. package/utils/platform.cjs +44 -0
  40. package/utils/platform.d.cts +11 -0
  41. package/{common-internals-node → utils}/platform.d.ts +1 -8
  42. package/utils/platform.js +22 -0
  43. package/utils/proxies.cjs +73 -0
  44. package/utils/proxies.d.cts +34 -0
  45. package/utils/proxies.d.ts +34 -0
  46. package/utils/proxies.js +63 -0
  47. package/utils/tcp.cjs +18 -0
  48. package/utils/tcp.d.cts +7 -0
  49. package/utils/tcp.d.ts +6 -28
  50. package/utils/tcp.js +13 -0
  51. package/utils.cjs +3 -6
  52. package/utils.d.cts +0 -1
  53. package/utils.d.ts +0 -1
  54. package/utils.js +2 -5
  55. package/worker.cjs +49 -0
  56. package/worker.d.cts +12 -0
  57. package/worker.d.ts +5 -3
  58. package/worker.js +44 -0
  59. package/chunks/cjs/HP2yqAk_.js +0 -79
  60. package/chunks/cjs/package.json +0 -3
  61. package/chunks/es/CKso6cAV.js +0 -75
  62. package/utils/stream-utils.d.ts +0 -3
  63. package/utils/version.d.ts +0 -3
  64. /package/{utils/stream-utils.test.d.ts → sqlite/sqlite.test.d.cts} +0 -0
  65. /package/utils/{tcp.test.d.ts → crypto.test.d.cts} +0 -0
  66. /package/{common-internals-node/exit-hook.d.ts → utils/exit-hook.d.cts} +0 -0
  67. /package/{common-internals-node/logging.d.ts → utils/logging.d.cts} +0 -0
package/index.js CHANGED
@@ -1,406 +1,22 @@
1
- import { createInterface } from "node:readline";
2
- import { BaseTelegramClient as BaseTelegramClient$1, TelegramClient as TelegramClient$1 } from "@mtcute/core/client.js";
3
- import { setPlatform } from "@mtcute/core/platform.js";
4
- import * as os from "node:os";
5
- import { createReadStream, ReadStream } from "node:fs";
6
- import { stat } from "node:fs/promises";
7
- import { basename } from "node:path";
8
- import { Readable } from "node:stream";
9
- import { nodeStreamToWeb } from "./chunks/es/CKso6cAV.js";
10
- import { downloadToFile, downloadAsNodeStream } from "./chunks/es/CnOjjhdK.js";
11
- import { BaseSqliteStorageDriver, BaseSqliteStorage, TransportState, MtcuteError, IntermediatePacketCodec } from "@mtcute/core";
1
+ import { BaseTelegramClient, TelegramClient } from "./client.js";
2
+ import { SqliteStorage } from "./sqlite/index.js";
3
+ import { NodePlatform } from "./utils/platform.js";
4
+ import { HttpProxyTcpTransport, MtProxyTcpTransport, SocksProxyTcpTransport } from "./utils/proxies.js";
5
+ import { TcpTransport } from "./utils/tcp.js";
6
+ import { TelegramWorker, TelegramWorkerPort } from "./worker.js";
12
7
  export * from "@mtcute/core";
13
- import sqlite3 from "better-sqlite3";
14
- import { NodeCryptoProvider } from "./chunks/es/HZgHrOPU.js";
15
- import EventEmitter from "node:events";
16
- import { connect } from "node:net";
17
- import { parentPort, Worker } from "node:worker_threads";
18
- import { TelegramWorker as TelegramWorker$1, TelegramWorkerPort as TelegramWorkerPort$1 } from "@mtcute/core/worker.js";
19
8
  export * from "@mtcute/html-parser";
20
9
  export * from "@mtcute/markdown-parser";
21
- async function normalizeFile(file) {
22
- if (typeof file === "string") {
23
- file = createReadStream(file);
24
- }
25
- if (file instanceof ReadStream) {
26
- const fileName = basename(file.path.toString());
27
- const fileSize = await stat(file.path.toString()).then((stat2) => stat2.size);
28
- return {
29
- file: nodeStreamToWeb(file),
30
- fileName,
31
- fileSize
32
- };
33
- }
34
- if (file instanceof Readable) {
35
- return {
36
- file: nodeStreamToWeb(file)
37
- };
38
- }
39
- return null;
40
- }
41
- let installed = false;
42
- let handled = false;
43
- const callbacks = /* @__PURE__ */ new Set();
44
- const myHandlers = /* @__PURE__ */ new Map();
45
- function register(shouldManuallyExit, signal, event) {
46
- function eventHandler() {
47
- if (handled) {
48
- return;
49
- }
50
- handled = true;
51
- for (const callback of callbacks) {
52
- callback();
53
- }
54
- for (const [event2, handler] of myHandlers) {
55
- process.off(event2, handler);
56
- }
57
- if (shouldManuallyExit) {
58
- process.kill(process.pid, signal);
59
- }
60
- }
61
- process.on(event, eventHandler);
62
- myHandlers.set(event, eventHandler);
63
- }
64
- function beforeExit(fn) {
65
- if (typeof process === "undefined") return () => {
66
- };
67
- if (!installed) {
68
- installed = true;
69
- register(true, 0, "beforeExit");
70
- register(true, 2, "SIGINT");
71
- register(true, 15, "SIGTERM");
72
- register(false, 15, "exit");
73
- }
74
- callbacks.add(fn);
75
- return () => {
76
- callbacks.delete(fn);
77
- };
78
- }
79
- const isTty = typeof process === "object" && Boolean(process.stdout?.isTTY);
80
- const BASE_FORMAT = isTty ? "%s [%s] [%s%s\x1B[0m] " : "%s [%s] [%s] ";
81
- const LEVEL_NAMES = isTty ? [
82
- "",
83
- // OFF
84
- "\x1B[31mERR\x1B[0m",
85
- "\x1B[33mWRN\x1B[0m",
86
- "\x1B[34mINF\x1B[0m",
87
- "\x1B[36mDBG\x1B[0m",
88
- "\x1B[35mVRB\x1B[0m"
89
- ] : [
90
- "",
91
- // OFF
92
- "ERR",
93
- "WRN",
94
- "INF",
95
- "DBG",
96
- "VRB"
97
- ];
98
- const TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\x1B[3${i};1m`);
99
- const defaultLoggingHandler = isTty ? (color, level, tag, fmt, args) => {
100
- console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args);
101
- } : (color, level, tag, fmt, args) => {
102
- console.log(BASE_FORMAT + fmt, (/* @__PURE__ */ new Date()).toISOString(), LEVEL_NAMES[level], tag, ...args);
103
- };
104
- const BUFFER_BASE64_URL_AVAILABLE = typeof Buffer.isEncoding === "function" && Buffer.isEncoding("base64url");
105
- const toBuffer = (buf) => Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
106
- class NodePlatform {
107
- getDeviceModel() {
108
- return `Node.js/${process.version} (${os.type()} ${os.arch()})`;
109
- }
110
- getDefaultLogLevel() {
111
- const envLogLevel = Number.parseInt(process.env.MTCUTE_LOG_LEVEL ?? "");
112
- if (!Number.isNaN(envLogLevel)) {
113
- return envLogLevel;
114
- }
115
- return null;
116
- }
117
- // ITlPlatform
118
- utf8ByteLength(str) {
119
- return Buffer.byteLength(str, "utf8");
120
- }
121
- utf8Encode(str) {
122
- return Buffer.from(str, "utf8");
123
- }
124
- utf8Decode(buf) {
125
- return toBuffer(buf).toString("utf8");
126
- }
127
- hexEncode(buf) {
128
- return toBuffer(buf).toString("hex");
129
- }
130
- hexDecode(str) {
131
- return Buffer.from(str, "hex");
132
- }
133
- base64Encode(buf, url = false) {
134
- const nodeBuffer = toBuffer(buf);
135
- if (url && BUFFER_BASE64_URL_AVAILABLE) return nodeBuffer.toString("base64url");
136
- const str = nodeBuffer.toString("base64");
137
- if (url) return str.replace(/\+/g, "-").replace(/\//g, "_").replace(/=/g, "");
138
- return str;
139
- }
140
- base64Decode(string, url = false) {
141
- if (url && BUFFER_BASE64_URL_AVAILABLE) {
142
- return Buffer.from(string, "base64url");
143
- }
144
- if (url) {
145
- string = string.replace(/-/g, "+").replace(/_/g, "/");
146
- while (string.length % 4) string += "=";
147
- }
148
- return Buffer.from(string, "base64");
149
- }
150
- }
151
- NodePlatform.prototype.log = defaultLoggingHandler;
152
- NodePlatform.prototype.beforeExit = beforeExit;
153
- NodePlatform.prototype.normalizeFile = normalizeFile;
154
- class SqliteStorageDriver extends BaseSqliteStorageDriver {
155
- constructor(filename = ":memory:", params) {
156
- super();
157
- this.filename = filename;
158
- this.params = params;
159
- }
160
- _createDatabase() {
161
- const db = sqlite3(this.filename, {
162
- ...this.params?.options,
163
- verbose: this._log.mgr.level >= 5 ? this._log.verbose : void 0
164
- });
165
- if (!this.params?.disableWal) {
166
- db.pragma("journal_mode = WAL");
167
- }
168
- return db;
169
- }
170
- }
171
- class SqliteStorage extends BaseSqliteStorage {
172
- constructor(filename = ":memory:", params) {
173
- super(new SqliteStorageDriver(filename, params));
174
- this.filename = filename;
175
- this.params = params;
176
- }
177
- }
178
- class BaseTcpTransport extends EventEmitter {
179
- _currentDc = null;
180
- _state = TransportState.Idle;
181
- _socket = null;
182
- _crypto;
183
- log;
184
- packetCodecInitialized = false;
185
- _updateLogPrefix() {
186
- if (this._currentDc) {
187
- this.log.prefix = `[TCP:${this._currentDc.ipAddress}:${this._currentDc.port}] `;
188
- } else {
189
- this.log.prefix = "[TCP:disconnected] ";
190
- }
191
- }
192
- setup(crypto, log) {
193
- this._crypto = crypto;
194
- this.log = log.create("tcp");
195
- this._updateLogPrefix();
196
- }
197
- state() {
198
- return this._state;
199
- }
200
- currentDc() {
201
- return this._currentDc;
202
- }
203
- // eslint-disable-next-line unused-imports/no-unused-vars
204
- connect(dc, testMode) {
205
- if (this._state !== TransportState.Idle) {
206
- throw new MtcuteError("Transport is not IDLE");
207
- }
208
- if (!this.packetCodecInitialized) {
209
- this._packetCodec.setup?.(this._crypto, this.log);
210
- this._packetCodec.on("error", (err) => this.emit("error", err));
211
- this._packetCodec.on("packet", (buf) => this.emit("message", buf));
212
- this.packetCodecInitialized = true;
213
- }
214
- this._state = TransportState.Connecting;
215
- this._currentDc = dc;
216
- this._updateLogPrefix();
217
- this.log.debug("connecting to %j", dc);
218
- this._socket = connect(dc.port, dc.ipAddress, this.handleConnect.bind(this));
219
- this._socket.on("data", (data) => {
220
- this._packetCodec.feed(data);
221
- });
222
- this._socket.on("error", this.handleError.bind(this));
223
- this._socket.on("close", this.close.bind(this));
224
- }
225
- close() {
226
- if (this._state === TransportState.Idle) return;
227
- this.log.info("connection closed");
228
- this._state = TransportState.Idle;
229
- this._socket.removeAllListeners();
230
- this._socket.destroy();
231
- this._socket = null;
232
- this._currentDc = null;
233
- this._packetCodec.reset();
234
- this.emit("close");
235
- }
236
- handleError(error) {
237
- this.log.error("error: %s", error.stack);
238
- if (this.listenerCount("error") > 0) {
239
- this.emit("error", error);
240
- }
241
- }
242
- handleConnect() {
243
- this.log.info("connected");
244
- Promise.resolve(this._packetCodec.tag()).then((initialMessage) => {
245
- if (initialMessage.length) {
246
- this._socket.write(initialMessage, (err) => {
247
- if (err) {
248
- this.log.error("failed to write initial message: %s", err.stack);
249
- this.emit("error");
250
- this.close();
251
- } else {
252
- this._state = TransportState.Ready;
253
- this.emit("ready");
254
- }
255
- });
256
- } else {
257
- this._state = TransportState.Ready;
258
- this.emit("ready");
259
- }
260
- }).catch((err) => this.emit("error", err));
261
- }
262
- async send(bytes) {
263
- const framed = await this._packetCodec.encode(bytes);
264
- if (this._state !== TransportState.Ready) {
265
- throw new MtcuteError("Transport is not READY");
266
- }
267
- return new Promise((resolve, reject) => {
268
- this._socket.write(framed, (error) => {
269
- if (error) {
270
- reject(error);
271
- } else {
272
- resolve();
273
- }
274
- });
275
- });
276
- }
277
- }
278
- class TcpTransport extends BaseTcpTransport {
279
- _packetCodec = new IntermediatePacketCodec();
280
- }
281
- let nativeCrypto;
282
- try {
283
- nativeCrypto = (await import("@mtcute/crypto-node")).NodeNativeCryptoProvider;
284
- } catch {
285
- }
286
- class BaseTelegramClient extends BaseTelegramClient$1 {
287
- constructor(opts) {
288
- if (!opts.platformless) setPlatform(new NodePlatform());
289
- super({
290
- // eslint-disable-next-line
291
- crypto: nativeCrypto ? new nativeCrypto() : new NodeCryptoProvider(),
292
- transport: () => new TcpTransport(),
293
- ...opts,
294
- storage: typeof opts.storage === "string" ? new SqliteStorage(opts.storage) : opts.storage ?? new SqliteStorage("client.session")
295
- });
296
- }
297
- }
298
- class TelegramClient extends TelegramClient$1 {
299
- constructor(opts) {
300
- if ("client" in opts) {
301
- super(opts);
302
- return;
303
- }
304
- super({
305
- client: new BaseTelegramClient(opts),
306
- disableUpdates: opts.disableUpdates,
307
- skipConversationUpdates: opts.skipConversationUpdates,
308
- updates: opts.updates
309
- });
310
- }
311
- _rl;
312
- /**
313
- * Tiny wrapper over Node `readline` package
314
- * for simpler user input for `.start()` method.
315
- *
316
- * Associated `readline` interface is closed
317
- * after `start()` returns, or with the client.
318
- *
319
- * @param text Text of the question
320
- */
321
- input(text) {
322
- if (!this._rl) {
323
- this._rl = createInterface({
324
- input: process.stdin,
325
- output: process.stdout
326
- });
327
- }
328
- return new Promise((res) => this._rl?.question(text, res));
329
- }
330
- close() {
331
- this._rl?.close();
332
- return super.close();
333
- }
334
- start(params = {}) {
335
- if (!params.botToken) {
336
- if (!params.phone) params.phone = () => this.input("phone > ");
337
- if (!params.code) params.code = () => this.input("code > ");
338
- if (!params.password) {
339
- params.password = () => this.input("2fa password > ");
340
- }
341
- }
342
- return super.start(params).then((user) => {
343
- if (this._rl) {
344
- this._rl.close();
345
- delete this._rl;
346
- }
347
- return user;
348
- });
349
- }
350
- run(params, then) {
351
- if (typeof params === "function") {
352
- then = params;
353
- params = {};
354
- }
355
- this.start(params).then(then).catch((err) => this.emitError(err));
356
- }
357
- downloadToFile(filename, location, params) {
358
- return downloadToFile(this, filename, location, params);
359
- }
360
- downloadAsNodeStream(location, params) {
361
- return downloadAsNodeStream(this, location, params);
362
- }
363
- }
364
- let _registered = false;
365
- class TelegramWorker extends TelegramWorker$1 {
366
- registerWorker(handler) {
367
- if (!parentPort) {
368
- throw new Error("TelegramWorker must be created from a worker thread");
369
- }
370
- if (_registered) {
371
- throw new Error("TelegramWorker must be created only once");
372
- }
373
- _registered = true;
374
- const port = parentPort;
375
- const respond = port.postMessage.bind(port);
376
- parentPort.on("message", (message) => handler(message, respond));
377
- return respond;
378
- }
379
- }
380
- class TelegramWorkerPort extends TelegramWorkerPort$1 {
381
- constructor(options) {
382
- setPlatform(new NodePlatform());
383
- super(options);
384
- this.options = options;
385
- }
386
- connectToWorker(worker, handler) {
387
- if (!(worker instanceof Worker)) {
388
- throw new TypeError("Only worker_threads are supported");
389
- }
390
- const send = worker.postMessage.bind(worker);
391
- worker.on("message", handler);
392
- return [
393
- send,
394
- () => {
395
- worker.off("message", handler);
396
- }
397
- ];
398
- }
399
- }
10
+ import { SqliteStorageDriver } from "./sqlite/driver.js";
11
+ import { HttpProxyConnectionError, SocksProxyConnectionError } from "@fuman/net";
400
12
  export {
401
- BaseTcpTransport,
402
13
  BaseTelegramClient,
14
+ HttpProxyConnectionError,
15
+ HttpProxyTcpTransport,
16
+ MtProxyTcpTransport,
403
17
  NodePlatform,
18
+ SocksProxyConnectionError,
19
+ SocksProxyTcpTransport,
404
20
  SqliteStorage,
405
21
  SqliteStorageDriver,
406
22
  TcpTransport,
@@ -1,14 +1,14 @@
1
1
  if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
2
  globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
- console.warn("[@mtcute/node] CommonJS support is deprecated and will be removed soon. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
- console.warn("[@mtcute/node] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
5
  }
6
6
  "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
7
8
  const node_fs = require("node:fs");
8
9
  const promises = require("node:fs/promises");
9
10
  const core = require("@mtcute/core");
10
11
  const methods_js = require("@mtcute/core/methods.js");
11
- const streamUtils = require("./HP2yqAk_.js");
12
12
  async function downloadToFile(client, filename, location, params) {
13
13
  if (location instanceof core.FileLocation && ArrayBuffer.isView(location.location)) {
14
14
  await promises.writeFile(filename, location.location);
@@ -26,8 +26,4 @@ async function downloadToFile(client, filename, location, params) {
26
26
  }
27
27
  output.end();
28
28
  }
29
- function downloadAsNodeStream(client, location, params) {
30
- return streamUtils.webStreamToNode(methods_js.downloadAsStream(client, location, params));
31
- }
32
- exports.downloadAsNodeStream = downloadAsNodeStream;
33
29
  exports.downloadToFile = downloadToFile;
@@ -0,0 +1,9 @@
1
+ import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
2
+ /**
3
+ * Download a remote file to a local file (only for NodeJS).
4
+ * Promise will resolve once the download is complete.
5
+ *
6
+ * @param filename Local file name to which the remote file will be downloaded
7
+ * @param params File download parameters
8
+ */
9
+ export declare function downloadToFile(client: ITelegramClient, filename: string, location: FileDownloadLocation, params?: FileDownloadParameters): Promise<void>;
@@ -1,8 +1,7 @@
1
1
  import { createWriteStream, rmSync } from "node:fs";
2
2
  import { writeFile } from "node:fs/promises";
3
3
  import { FileLocation } from "@mtcute/core";
4
- import { downloadAsIterable, downloadAsStream } from "@mtcute/core/methods.js";
5
- import { webStreamToNode } from "./CKso6cAV.js";
4
+ import { downloadAsIterable } from "@mtcute/core/methods.js";
6
5
  async function downloadToFile(client, filename, location, params) {
7
6
  if (location instanceof FileLocation && ArrayBuffer.isView(location.location)) {
8
7
  await writeFile(filename, location.location);
@@ -20,10 +19,6 @@ async function downloadToFile(client, filename, location, params) {
20
19
  }
21
20
  output.end();
22
21
  }
23
- function downloadAsNodeStream(client, location, params) {
24
- return webStreamToNode(downloadAsStream(client, location, params));
25
- }
26
22
  export {
27
- downloadAsNodeStream,
28
23
  downloadToFile
29
24
  };
@@ -0,0 +1,13 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const node = require("@fuman/node");
9
+ const methods_js = require("@mtcute/core/methods.js");
10
+ function downloadAsNodeStream(client, location, params) {
11
+ return node.webReadableToNode(methods_js.downloadAsStream(client, location, params));
12
+ }
13
+ exports.downloadAsNodeStream = downloadAsNodeStream;
@@ -0,0 +1,8 @@
1
+ import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
2
+ import { Readable } from 'node:stream';
3
+ /**
4
+ * Download a remote file as a Node.js Readable stream.
5
+ *
6
+ * @param params File download parameters
7
+ */
8
+ export declare function downloadAsNodeStream(client: ITelegramClient, location: FileDownloadLocation, params?: FileDownloadParameters): Readable;
@@ -1,5 +1,5 @@
1
- import { Readable } from 'node:stream';
2
1
  import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
2
+ import { Readable } from 'node:stream';
3
3
  /**
4
4
  * Download a remote file as a Node.js Readable stream.
5
5
  *
@@ -0,0 +1,8 @@
1
+ import { webReadableToNode } from "@fuman/node";
2
+ import { downloadAsStream } from "@mtcute/core/methods.js";
3
+ function downloadAsNodeStream(client, location, params) {
4
+ return webReadableToNode(downloadAsStream(client, location, params));
5
+ }
6
+ export {
7
+ downloadAsNodeStream
8
+ };
package/methods.cjs CHANGED
@@ -1,14 +1,15 @@
1
1
  if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
2
  globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
- console.warn("[@mtcute/node] CommonJS support is deprecated and will be removed soon. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
- console.warn("[@mtcute/node] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
5
  }
6
6
  "use strict";
7
7
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
- const downloadNodeStream = require("./chunks/cjs/BpvQ752Q.js");
8
+ const downloadFile = require("./methods/download-file.cjs");
9
+ const downloadNodeStream = require("./methods/download-node-stream.cjs");
9
10
  const methods_js = require("@mtcute/core/methods.js");
11
+ exports.downloadToFile = downloadFile.downloadToFile;
10
12
  exports.downloadAsNodeStream = downloadNodeStream.downloadAsNodeStream;
11
- exports.downloadToFile = downloadNodeStream.downloadToFile;
12
13
  Object.keys(methods_js).forEach((k) => {
13
14
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {
14
15
  enumerable: true,
package/methods.js CHANGED
@@ -1,4 +1,5 @@
1
- import { downloadAsNodeStream, downloadToFile } from "./chunks/es/CnOjjhdK.js";
1
+ import { downloadToFile } from "./methods/download-file.js";
2
+ import { downloadAsNodeStream } from "./methods/download-node-stream.js";
2
3
  export * from "@mtcute/core/methods.js";
3
4
  export {
4
5
  downloadAsNodeStream,
package/package.json CHANGED
@@ -1,11 +1,19 @@
1
1
  {
2
2
  "name": "@mtcute/node",
3
3
  "type": "module",
4
- "version": "0.17.0",
4
+ "version": "0.18.0",
5
5
  "description": "Meta-package for Node.js",
6
- "author": "alina sireneva <alina@tei.su>",
7
6
  "license": "MIT",
8
- "sideEffects": false,
7
+ "dependencies": {
8
+ "@mtcute/core": "^0.18.0",
9
+ "@mtcute/html-parser": "^0.18.0",
10
+ "@mtcute/markdown-parser": "^0.18.0",
11
+ "@mtcute/wasm": "^0.18.0",
12
+ "@fuman/utils": "0.0.4",
13
+ "@fuman/net": "0.0.4",
14
+ "@fuman/node": "0.0.4",
15
+ "better-sqlite3": "11.3.0"
16
+ },
9
17
  "exports": {
10
18
  ".": {
11
19
  "import": {
@@ -38,17 +46,12 @@
38
46
  }
39
47
  }
40
48
  },
41
- "scripts": {},
42
- "dependencies": {
43
- "@mtcute/core": "^0.17.0",
44
- "@mtcute/html-parser": "^0.17.0",
45
- "@mtcute/markdown-parser": "^0.17.0",
46
- "@mtcute/wasm": "^0.17.0",
47
- "better-sqlite3": "11.3.0"
48
- },
49
+ "author": "alina sireneva <alina@tei.su>",
50
+ "sideEffects": false,
49
51
  "homepage": "https://mtcute.dev",
50
52
  "repository": {
51
53
  "type": "git",
52
- "url": "https://github.com/mtcute/mtcute"
53
- }
54
+ "url": "git+https://github.com/mtcute/mtcute.git"
55
+ },
56
+ "scripts": {}
54
57
  }
@@ -0,0 +1,27 @@
1
+ if (typeof globalThis !== "undefined" && !globalThis._MTCUTE_CJS_DEPRECATION_WARNED) {
2
+ globalThis._MTCUTE_CJS_DEPRECATION_WARNED = true;
3
+ console.warn("[mtcute-workspace] CommonJS support is deprecated and will be removed in 0.20.0. Please consider switching to ESM, it's " + (/* @__PURE__ */ new Date()).getFullYear() + " already.");
4
+ console.warn("[mtcute-workspace] Learn more about switching to ESM: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c");
5
+ }
6
+ "use strict";
7
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
8
+ const core = require("@mtcute/core");
9
+ const sqlite3 = require("better-sqlite3");
10
+ class SqliteStorageDriver extends core.BaseSqliteStorageDriver {
11
+ constructor(filename = ":memory:", params) {
12
+ super();
13
+ this.filename = filename;
14
+ this.params = params;
15
+ }
16
+ _createDatabase() {
17
+ const db = sqlite3(this.filename, {
18
+ ...this.params?.options,
19
+ verbose: this._log.mgr.level >= 5 ? this._log.verbose : void 0
20
+ });
21
+ if (!this.params?.disableWal) {
22
+ db.pragma("journal_mode = WAL");
23
+ }
24
+ return db;
25
+ }
26
+ }
27
+ exports.SqliteStorageDriver = SqliteStorageDriver;
@@ -0,0 +1,25 @@
1
+ import { ISqliteDatabase, BaseSqliteStorageDriver } from '@mtcute/core';
2
+ import { Options } from 'better-sqlite3';
3
+ export interface SqliteStorageDriverOptions {
4
+ /**
5
+ * By default, WAL mode is enabled, which
6
+ * significantly improves performance.
7
+ * [Learn more](https://github.com/JoshuaWise/better-sqlite3/blob/master/docs/performance.md)
8
+ *
9
+ * However, you might encounter some issues,
10
+ * and if you do, you can disable WAL by passing `true`
11
+ *
12
+ * @default false
13
+ */
14
+ disableWal?: boolean;
15
+ /**
16
+ * Additional options to pass to `better-sqlite3`
17
+ */
18
+ options?: Options;
19
+ }
20
+ export declare class SqliteStorageDriver extends BaseSqliteStorageDriver {
21
+ readonly filename: string;
22
+ readonly params?: SqliteStorageDriverOptions | undefined;
23
+ constructor(filename?: string, params?: SqliteStorageDriverOptions | undefined);
24
+ _createDatabase(): ISqliteDatabase;
25
+ }
@@ -1,5 +1,5 @@
1
- import { Options } from 'better-sqlite3';
2
1
  import { ISqliteDatabase, BaseSqliteStorageDriver } from '@mtcute/core';
2
+ import { Options } from 'better-sqlite3';
3
3
  export interface SqliteStorageDriverOptions {
4
4
  /**
5
5
  * By default, WAL mode is enabled, which
@@ -0,0 +1,22 @@
1
+ import { BaseSqliteStorageDriver } from "@mtcute/core";
2
+ import sqlite3 from "better-sqlite3";
3
+ class SqliteStorageDriver extends BaseSqliteStorageDriver {
4
+ constructor(filename = ":memory:", params) {
5
+ super();
6
+ this.filename = filename;
7
+ this.params = params;
8
+ }
9
+ _createDatabase() {
10
+ const db = sqlite3(this.filename, {
11
+ ...this.params?.options,
12
+ verbose: this._log.mgr.level >= 5 ? this._log.verbose : void 0
13
+ });
14
+ if (!this.params?.disableWal) {
15
+ db.pragma("journal_mode = WAL");
16
+ }
17
+ return db;
18
+ }
19
+ }
20
+ export {
21
+ SqliteStorageDriver
22
+ };