@mtcute/node 0.16.6 → 0.16.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chunks/cjs/BpvQ752Q.js +33 -0
- package/chunks/cjs/D7i-4e0W.js +74 -0
- package/chunks/cjs/HP2yqAk_.js +79 -0
- package/chunks/cjs/package.json +3 -0
- package/chunks/es/CKso6cAV.js +75 -0
- package/chunks/es/CnOjjhdK.js +29 -0
- package/chunks/es/HZgHrOPU.js +69 -0
- package/{cjs/client.d.ts → client.d.ts} +3 -2
- package/index.cjs +449 -0
- package/index.d.ts +8 -1
- package/index.js +410 -1
- package/{cjs/methods → methods}/download-node-stream.d.ts +1 -1
- package/methods.cjs +17 -0
- package/methods.d.ts +3 -1
- package/methods.js +6 -1
- package/package.json +49 -33
- package/{esm/sqlite → sqlite}/driver.d.ts +1 -1
- package/sqlite/sqlite.test.d.ts +1 -0
- package/{cjs/utils → utils}/crypto.d.ts +1 -1
- package/utils/crypto.test.d.ts +1 -0
- package/utils/normalize-file.d.ts +6 -0
- package/{cjs/utils → utils}/stream-utils.d.ts +1 -1
- package/utils/stream-utils.test.d.ts +1 -0
- package/{cjs/utils → utils}/tcp.d.ts +3 -3
- package/utils/tcp.test.d.ts +1 -0
- package/utils.cjs +20 -0
- package/utils.d.ts +3 -1
- package/utils.js +9 -1
- package/{cjs/worker.d.ts → worker.d.ts} +1 -1
- package/cjs/client.js +0 -113
- package/cjs/client.js.map +0 -1
- package/cjs/common-internals-node/exit-hook.js +0 -47
- package/cjs/common-internals-node/exit-hook.js.map +0 -1
- package/cjs/common-internals-node/logging.js +0 -34
- package/cjs/common-internals-node/logging.js.map +0 -1
- package/cjs/common-internals-node/platform.js +0 -85
- package/cjs/common-internals-node/platform.js.map +0 -1
- package/cjs/index.js +0 -31
- package/cjs/index.js.map +0 -1
- package/cjs/methods/download-file.js +0 -34
- package/cjs/methods/download-file.js.map +0 -1
- package/cjs/methods/download-node-stream.js +0 -15
- package/cjs/methods/download-node-stream.js.map +0 -1
- package/cjs/methods.js +0 -29
- package/cjs/methods.js.map +0 -1
- package/cjs/package.json +0 -3
- package/cjs/sqlite/driver.d.ts +0 -25
- package/cjs/sqlite/driver.js +0 -29
- package/cjs/sqlite/driver.js.map +0 -1
- package/cjs/sqlite/index.js +0 -18
- package/cjs/sqlite/index.js.map +0 -1
- package/cjs/utils/crypto.js +0 -73
- package/cjs/utils/crypto.js.map +0 -1
- package/cjs/utils/normalize-file.d.ts +0 -10
- package/cjs/utils/normalize-file.js +0 -31
- package/cjs/utils/normalize-file.js.map +0 -1
- package/cjs/utils/stream-utils.js +0 -77
- package/cjs/utils/stream-utils.js.map +0 -1
- package/cjs/utils/tcp.js +0 -126
- package/cjs/utils/tcp.js.map +0 -1
- package/cjs/utils/version.js +0 -21
- package/cjs/utils/version.js.map +0 -1
- package/cjs/utils.js +0 -26
- package/cjs/utils.js.map +0 -1
- package/cjs/worker.js +0 -48
- package/cjs/worker.js.map +0 -1
- package/esm/client.d.ts +0 -46
- package/esm/client.js +0 -108
- package/esm/client.js.map +0 -1
- package/esm/common-internals-node/exit-hook.d.ts +0 -1
- package/esm/common-internals-node/exit-hook.js +0 -43
- package/esm/common-internals-node/exit-hook.js.map +0 -1
- package/esm/common-internals-node/logging.d.ts +0 -2
- package/esm/common-internals-node/logging.js +0 -31
- package/esm/common-internals-node/logging.js.map +0 -1
- package/esm/common-internals-node/platform.d.ts +0 -18
- package/esm/common-internals-node/platform.js +0 -58
- package/esm/common-internals-node/platform.js.map +0 -1
- package/esm/index.d.ts +0 -8
- package/esm/index.js +0 -9
- package/esm/index.js.map +0 -1
- package/esm/methods/download-file.d.ts +0 -9
- package/esm/methods/download-file.js +0 -30
- package/esm/methods/download-file.js.map +0 -1
- package/esm/methods/download-node-stream.d.ts +0 -8
- package/esm/methods/download-node-stream.js +0 -11
- package/esm/methods/download-node-stream.js.map +0 -1
- package/esm/methods.d.ts +0 -3
- package/esm/methods.js +0 -4
- package/esm/methods.js.map +0 -1
- package/esm/sqlite/driver.js +0 -22
- package/esm/sqlite/driver.js.map +0 -1
- package/esm/sqlite/index.d.ts +0 -8
- package/esm/sqlite/index.js +0 -13
- package/esm/sqlite/index.js.map +0 -1
- package/esm/utils/crypto.d.ts +0 -15
- package/esm/utils/crypto.js +0 -71
- package/esm/utils/crypto.js.map +0 -1
- package/esm/utils/normalize-file.d.ts +0 -10
- package/esm/utils/normalize-file.js +0 -27
- package/esm/utils/normalize-file.js.map +0 -1
- package/esm/utils/stream-utils.d.ts +0 -3
- package/esm/utils/stream-utils.js +0 -72
- package/esm/utils/stream-utils.js.map +0 -1
- package/esm/utils/tcp.d.ts +0 -29
- package/esm/utils/tcp.js +0 -118
- package/esm/utils/tcp.js.map +0 -1
- package/esm/utils/version.d.ts +0 -3
- package/esm/utils/version.js +0 -17
- package/esm/utils/version.js.map +0 -1
- package/esm/utils.d.ts +0 -3
- package/esm/utils.js +0 -4
- package/esm/utils.js.map +0 -1
- package/esm/worker.d.ts +0 -10
- package/esm/worker.js +0 -43
- package/esm/worker.js.map +0 -1
- /package/{cjs/common-internals-node → common-internals-node}/exit-hook.d.ts +0 -0
- /package/{cjs/common-internals-node → common-internals-node}/logging.d.ts +0 -0
- /package/{cjs/common-internals-node → common-internals-node}/platform.d.ts +0 -0
- /package/{cjs/index.d.ts → index.d.cts} +0 -0
- /package/{cjs/methods → methods}/download-file.d.ts +0 -0
- /package/{cjs/methods.d.ts → methods.d.cts} +0 -0
- /package/{cjs/sqlite → sqlite}/index.d.ts +0 -0
- /package/{cjs/utils → utils}/version.d.ts +0 -0
- /package/{cjs/utils.d.ts → utils.d.cts} +0 -0
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
const isTty = typeof process === 'object' && Boolean(process.stdout?.isTTY);
|
|
2
|
-
const BASE_FORMAT = isTty ? '%s [%s] [%s%s\x1b[0m] ' : '%s [%s] [%s] ';
|
|
3
|
-
const LEVEL_NAMES = isTty ?
|
|
4
|
-
[
|
|
5
|
-
'', // OFF
|
|
6
|
-
'\x1b[31mERR\x1b[0m',
|
|
7
|
-
'\x1b[33mWRN\x1b[0m',
|
|
8
|
-
'\x1b[34mINF\x1b[0m',
|
|
9
|
-
'\x1b[36mDBG\x1b[0m',
|
|
10
|
-
'\x1b[35mVRB\x1b[0m',
|
|
11
|
-
] :
|
|
12
|
-
[
|
|
13
|
-
'', // OFF
|
|
14
|
-
'ERR',
|
|
15
|
-
'WRN',
|
|
16
|
-
'INF',
|
|
17
|
-
'DBG',
|
|
18
|
-
'VRB',
|
|
19
|
-
];
|
|
20
|
-
const TAG_COLORS = [6, 2, 3, 4, 5, 1].map((i) => `\x1b[3${i};1m`);
|
|
21
|
-
/** @internal */
|
|
22
|
-
export const defaultLoggingHandler = isTty ?
|
|
23
|
-
(color, level, tag, fmt, args) => {
|
|
24
|
-
// eslint-disable-next-line no-console
|
|
25
|
-
console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], TAG_COLORS[color], tag, ...args);
|
|
26
|
-
} :
|
|
27
|
-
(color, level, tag, fmt, args) => {
|
|
28
|
-
// eslint-disable-next-line no-console
|
|
29
|
-
console.log(BASE_FORMAT + fmt, new Date().toISOString(), LEVEL_NAMES[level], tag, ...args);
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=logging.js.map
|
|
@@ -1 +0,0 @@
|
|
|
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;AAChB,MAAM,CAAC,MAAM,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,18 +0,0 @@
|
|
|
1
|
-
import { ICorePlatform } from '@mtcute/core/platform.js';
|
|
2
|
-
import { normalizeFile } from '../utils/normalize-file.js';
|
|
3
|
-
import { beforeExit } from './exit-hook.js';
|
|
4
|
-
import { defaultLoggingHandler } from './logging.js';
|
|
5
|
-
export declare class NodePlatform implements ICorePlatform {
|
|
6
|
-
log: typeof defaultLoggingHandler;
|
|
7
|
-
beforeExit: typeof beforeExit;
|
|
8
|
-
normalizeFile: typeof normalizeFile;
|
|
9
|
-
getDeviceModel(): string;
|
|
10
|
-
getDefaultLogLevel(): number | null;
|
|
11
|
-
utf8ByteLength(str: string): number;
|
|
12
|
-
utf8Encode(str: string): Uint8Array;
|
|
13
|
-
utf8Decode(buf: Uint8Array): string;
|
|
14
|
-
hexEncode(buf: Uint8Array): string;
|
|
15
|
-
hexDecode(str: string): Uint8Array;
|
|
16
|
-
base64Encode(buf: Uint8Array, url?: boolean): string;
|
|
17
|
-
base64Decode(string: string, url?: boolean): Uint8Array;
|
|
18
|
-
}
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
import * as os from 'os';
|
|
2
|
-
import { normalizeFile } from '../utils/normalize-file.js';
|
|
3
|
-
import { beforeExit } from './exit-hook.js';
|
|
4
|
-
import { defaultLoggingHandler } from './logging.js';
|
|
5
|
-
const BUFFER_BASE64_URL_AVAILABLE = typeof Buffer.isEncoding === 'function' && Buffer.isEncoding('base64url');
|
|
6
|
-
const toBuffer = (buf) => Buffer.from(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
7
|
-
export class NodePlatform {
|
|
8
|
-
getDeviceModel() {
|
|
9
|
-
return `Node.js/${process.version} (${os.type()} ${os.arch()})`;
|
|
10
|
-
}
|
|
11
|
-
getDefaultLogLevel() {
|
|
12
|
-
const envLogLevel = parseInt(process.env.MTCUTE_LOG_LEVEL ?? '');
|
|
13
|
-
if (!isNaN(envLogLevel)) {
|
|
14
|
-
return envLogLevel;
|
|
15
|
-
}
|
|
16
|
-
return null;
|
|
17
|
-
}
|
|
18
|
-
// ITlPlatform
|
|
19
|
-
utf8ByteLength(str) {
|
|
20
|
-
return Buffer.byteLength(str, 'utf8');
|
|
21
|
-
}
|
|
22
|
-
utf8Encode(str) {
|
|
23
|
-
return Buffer.from(str, 'utf8');
|
|
24
|
-
}
|
|
25
|
-
utf8Decode(buf) {
|
|
26
|
-
return toBuffer(buf).toString('utf8');
|
|
27
|
-
}
|
|
28
|
-
hexEncode(buf) {
|
|
29
|
-
return toBuffer(buf).toString('hex');
|
|
30
|
-
}
|
|
31
|
-
hexDecode(str) {
|
|
32
|
-
return Buffer.from(str, 'hex');
|
|
33
|
-
}
|
|
34
|
-
base64Encode(buf, url = false) {
|
|
35
|
-
const nodeBuffer = toBuffer(buf);
|
|
36
|
-
if (url && BUFFER_BASE64_URL_AVAILABLE)
|
|
37
|
-
return nodeBuffer.toString('base64url');
|
|
38
|
-
const str = nodeBuffer.toString('base64');
|
|
39
|
-
if (url)
|
|
40
|
-
return str.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
|
|
41
|
-
return str;
|
|
42
|
-
}
|
|
43
|
-
base64Decode(string, url = false) {
|
|
44
|
-
if (url && BUFFER_BASE64_URL_AVAILABLE) {
|
|
45
|
-
return Buffer.from(string, 'base64url');
|
|
46
|
-
}
|
|
47
|
-
if (url) {
|
|
48
|
-
string = string.replace(/-/g, '+').replace(/_/g, '/');
|
|
49
|
-
while (string.length % 4)
|
|
50
|
-
string += '=';
|
|
51
|
-
}
|
|
52
|
-
return Buffer.from(string, 'base64');
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
NodePlatform.prototype.log = defaultLoggingHandler;
|
|
56
|
-
NodePlatform.prototype.beforeExit = beforeExit;
|
|
57
|
-
NodePlatform.prototype.normalizeFile = normalizeFile;
|
|
58
|
-
//# sourceMappingURL=platform.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"platform.js","sourceRoot":"","sources":["../../../src/common-internals-node/platform.ts"],"names":[],"mappings":"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","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"]}
|
package/esm/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
export * from './client.js';
|
|
2
|
-
export * from './common-internals-node/platform.js';
|
|
3
|
-
export * from './sqlite/index.js';
|
|
4
|
-
export * from './utils/tcp.js';
|
|
5
|
-
export * from './worker.js';
|
|
6
|
-
export * from '@mtcute/core';
|
|
7
|
-
export * from '@mtcute/html-parser';
|
|
8
|
-
export * from '@mtcute/markdown-parser';
|
package/esm/index.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
export * from './client.js';
|
|
2
|
-
export * from './common-internals-node/platform.js';
|
|
3
|
-
export * from './sqlite/index.js';
|
|
4
|
-
export * from './utils/tcp.js';
|
|
5
|
-
export * from './worker.js';
|
|
6
|
-
export * from '@mtcute/core';
|
|
7
|
-
export * from '@mtcute/html-parser';
|
|
8
|
-
export * from '@mtcute/markdown-parser';
|
|
9
|
-
//# sourceMappingURL=index.js.map
|
package/esm/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,aAAa,CAAA;AAC3B,cAAc,qCAAqC,CAAA;AACnD,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,aAAa,CAAA;AAC3B,cAAc,cAAc,CAAA;AAC5B,cAAc,qBAAqB,CAAA;AACnC,cAAc,yBAAyB,CAAA","sourcesContent":["export * from './client.js'\nexport * from './common-internals-node/platform.js'\nexport * from './sqlite/index.js'\nexport * from './utils/tcp.js'\nexport * from './worker.js'\nexport * from '@mtcute/core'\nexport * from '@mtcute/html-parser'\nexport * from '@mtcute/markdown-parser'\n"]}
|
|
@@ -1,9 +0,0 @@
|
|
|
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,30 +0,0 @@
|
|
|
1
|
-
import { createWriteStream, rmSync } from 'fs';
|
|
2
|
-
import { writeFile } from 'fs/promises';
|
|
3
|
-
import { FileLocation } from '@mtcute/core';
|
|
4
|
-
import { downloadAsIterable } from '@mtcute/core/methods.js';
|
|
5
|
-
/**
|
|
6
|
-
* Download a remote file to a local file (only for NodeJS).
|
|
7
|
-
* Promise will resolve once the download is complete.
|
|
8
|
-
*
|
|
9
|
-
* @param filename Local file name to which the remote file will be downloaded
|
|
10
|
-
* @param params File download parameters
|
|
11
|
-
*/
|
|
12
|
-
export async function downloadToFile(client, filename, location, params) {
|
|
13
|
-
if (location instanceof FileLocation && ArrayBuffer.isView(location.location)) {
|
|
14
|
-
// early return for inline files
|
|
15
|
-
await writeFile(filename, location.location);
|
|
16
|
-
}
|
|
17
|
-
const output = createWriteStream(filename);
|
|
18
|
-
if (params?.abortSignal) {
|
|
19
|
-
params.abortSignal.addEventListener('abort', () => {
|
|
20
|
-
client.log.debug('aborting file download %s - cleaning up', filename);
|
|
21
|
-
output.destroy();
|
|
22
|
-
rmSync(filename);
|
|
23
|
-
});
|
|
24
|
-
}
|
|
25
|
-
for await (const chunk of downloadAsIterable(client, location, params)) {
|
|
26
|
-
output.write(chunk);
|
|
27
|
-
}
|
|
28
|
-
output.end();
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=download-file.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download-file.js","sourceRoot":"","sources":["../../../src/methods/download-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,IAAI,CAAA;AAC9C,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAA;AAEvC,OAAO,EAAgD,YAAY,EAAmB,MAAM,cAAc,CAAA;AAC1G,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAE5D;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,cAAc,CAChC,MAAuB,EACvB,QAAgB,EAChB,QAA8B,EAC9B,MAA+B;IAE/B,IAAI,QAAQ,YAAY,YAAY,IAAI,WAAW,CAAC,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5E,gCAAgC;QAChC,MAAM,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,QAAQ,CAAC,CAAA;IAChD,CAAC;IAED,MAAM,MAAM,GAAG,iBAAiB,CAAC,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,MAAM,CAAC,QAAQ,CAAC,CAAA;QACpB,CAAC,CAAC,CAAA;IACN,CAAC;IAED,IAAI,KAAK,EAAE,MAAM,KAAK,IAAI,kBAAkB,CAAC,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 '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,8 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
import { FileDownloadLocation, FileDownloadParameters, ITelegramClient } from '@mtcute/core';
|
|
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,11 +0,0 @@
|
|
|
1
|
-
import { downloadAsStream } from '@mtcute/core/methods.js';
|
|
2
|
-
import { webStreamToNode } from '../utils/stream-utils.js';
|
|
3
|
-
/**
|
|
4
|
-
* Download a remote file as a Node.js Readable stream.
|
|
5
|
-
*
|
|
6
|
-
* @param params File download parameters
|
|
7
|
-
*/
|
|
8
|
-
export function downloadAsNodeStream(client, location, params) {
|
|
9
|
-
return webStreamToNode(downloadAsStream(client, location, params));
|
|
10
|
-
}
|
|
11
|
-
//# sourceMappingURL=download-node-stream.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"download-node-stream.js","sourceRoot":"","sources":["../../../src/methods/download-node-stream.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAA;AAE1D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAE1D;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAChC,MAAuB,EACvB,QAA8B,EAC9B,MAA+B;IAE/B,OAAO,eAAe,CAAC,gBAAgB,CAAC,MAAM,EAAE,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;AACtE,CAAC","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"]}
|
package/esm/methods.d.ts
DELETED
package/esm/methods.js
DELETED
package/esm/methods.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"methods.js","sourceRoot":"","sources":["../../src/methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,4BAA4B,CAAA;AAC3D,OAAO,EAAE,oBAAoB,EAAE,MAAM,mCAAmC,CAAA;AACxE,cAAc,yBAAyB,CAAA","sourcesContent":["export { downloadToFile } from './methods/download-file.js'\nexport { downloadAsNodeStream } from './methods/download-node-stream.js'\nexport * from '@mtcute/core/methods.js'\n"]}
|
package/esm/sqlite/driver.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import sqlite3 from 'better-sqlite3';
|
|
2
|
-
import { BaseSqliteStorageDriver } from '@mtcute/core';
|
|
3
|
-
export class SqliteStorageDriver extends BaseSqliteStorageDriver {
|
|
4
|
-
filename;
|
|
5
|
-
params;
|
|
6
|
-
constructor(filename = ':memory:', params) {
|
|
7
|
-
super();
|
|
8
|
-
this.filename = filename;
|
|
9
|
-
this.params = params;
|
|
10
|
-
}
|
|
11
|
-
_createDatabase() {
|
|
12
|
-
const db = sqlite3(this.filename, {
|
|
13
|
-
...this.params?.options,
|
|
14
|
-
verbose: this._log.mgr.level >= 5 ? this._log.verbose : undefined,
|
|
15
|
-
});
|
|
16
|
-
if (!this.params?.disableWal) {
|
|
17
|
-
db.pragma('journal_mode = WAL');
|
|
18
|
-
}
|
|
19
|
-
return db;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
//# sourceMappingURL=driver.js.map
|
package/esm/sqlite/driver.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"driver.js","sourceRoot":"","sources":["../../../src/sqlite/driver.ts"],"names":[],"mappings":"AAAA,OAAO,OAAoB,MAAM,gBAAgB,CAAA;AAEjD,OAAO,EAAE,uBAAuB,EAAmB,MAAM,cAAc,CAAA;AAqBvE,MAAM,OAAO,mBAAoB,SAAQ,uBAAuB;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,OAAO,CAAC,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","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"]}
|
package/esm/sqlite/index.d.ts
DELETED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { BaseSqliteStorage } from '@mtcute/core';
|
|
2
|
-
import { SqliteStorageDriverOptions } from './driver.js';
|
|
3
|
-
export { SqliteStorageDriver } from './driver.js';
|
|
4
|
-
export declare class SqliteStorage extends BaseSqliteStorage {
|
|
5
|
-
readonly filename: string;
|
|
6
|
-
readonly params?: SqliteStorageDriverOptions | undefined;
|
|
7
|
-
constructor(filename?: string, params?: SqliteStorageDriverOptions | undefined);
|
|
8
|
-
}
|
package/esm/sqlite/index.js
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { BaseSqliteStorage } from '@mtcute/core';
|
|
2
|
-
import { SqliteStorageDriver } from './driver.js';
|
|
3
|
-
export { SqliteStorageDriver } from './driver.js';
|
|
4
|
-
export class SqliteStorage extends BaseSqliteStorage {
|
|
5
|
-
filename;
|
|
6
|
-
params;
|
|
7
|
-
constructor(filename = ':memory:', params) {
|
|
8
|
-
super(new SqliteStorageDriver(filename, params));
|
|
9
|
-
this.filename = filename;
|
|
10
|
-
this.params = params;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
package/esm/sqlite/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/sqlite/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAEhD,OAAO,EAAE,mBAAmB,EAA8B,MAAM,aAAa,CAAA;AAE7E,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAA;AAEjD,MAAM,OAAO,aAAc,SAAQ,iBAAiB;IAEnC;IACA;IAFb,YACa,WAAW,UAAU,EACrB,MAAmC;QAE5C,KAAK,CAAC,IAAI,mBAAmB,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,CAAA;QAHvC,aAAQ,GAAR,QAAQ,CAAa;QACrB,WAAM,GAAN,MAAM,CAA6B;IAGhD,CAAC;CACJ","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"]}
|
package/esm/utils/crypto.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { BaseCryptoProvider, IAesCtr, ICryptoProvider, IEncryptionScheme } from '@mtcute/core/utils.js';
|
|
2
|
-
export declare abstract class BaseNodeCryptoProvider extends BaseCryptoProvider {
|
|
3
|
-
createAesCtr(key: Uint8Array, iv: Uint8Array): IAesCtr;
|
|
4
|
-
pbkdf2(password: Uint8Array, salt: Uint8Array, iterations: number, keylen?: number, algo?: string): Promise<Uint8Array>;
|
|
5
|
-
sha1(data: Uint8Array): Uint8Array;
|
|
6
|
-
sha256(data: Uint8Array): Uint8Array;
|
|
7
|
-
hmacSha256(data: Uint8Array, key: Uint8Array): Uint8Array;
|
|
8
|
-
gzip(data: Uint8Array, maxSize: number): Uint8Array | null;
|
|
9
|
-
gunzip(data: Uint8Array): Uint8Array;
|
|
10
|
-
randomFill(buf: Uint8Array): void;
|
|
11
|
-
}
|
|
12
|
-
export declare class NodeCryptoProvider extends BaseNodeCryptoProvider implements ICryptoProvider {
|
|
13
|
-
initialize(): Promise<void>;
|
|
14
|
-
createAesIge(key: Uint8Array, iv: Uint8Array): IEncryptionScheme;
|
|
15
|
-
}
|
package/esm/utils/crypto.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
// eslint-disable-next-line no-restricted-imports
|
|
2
|
-
import { createCipheriv, createHash, createHmac, pbkdf2, randomFillSync } from 'crypto';
|
|
3
|
-
import { readFile } from 'fs/promises';
|
|
4
|
-
import { createRequire } from 'module';
|
|
5
|
-
import { deflateSync, gunzipSync } from 'zlib';
|
|
6
|
-
import { BaseCryptoProvider } from '@mtcute/core/utils.js';
|
|
7
|
-
import { ige256Decrypt, ige256Encrypt, initSync } from '@mtcute/wasm';
|
|
8
|
-
export class BaseNodeCryptoProvider extends BaseCryptoProvider {
|
|
9
|
-
createAesCtr(key, iv) {
|
|
10
|
-
const cipher = createCipheriv(`aes-${key.length * 8}-ctr`, key, iv);
|
|
11
|
-
const update = (data) => cipher.update(data);
|
|
12
|
-
return {
|
|
13
|
-
process: update,
|
|
14
|
-
};
|
|
15
|
-
}
|
|
16
|
-
pbkdf2(password, salt, iterations, keylen = 64, algo = 'sha512') {
|
|
17
|
-
return new Promise((resolve, reject) => pbkdf2(password, salt, iterations, keylen, algo, (err, buf) => err !== null ? reject(err) : resolve(buf)));
|
|
18
|
-
}
|
|
19
|
-
sha1(data) {
|
|
20
|
-
return createHash('sha1').update(data).digest();
|
|
21
|
-
}
|
|
22
|
-
sha256(data) {
|
|
23
|
-
return createHash('sha256').update(data).digest();
|
|
24
|
-
}
|
|
25
|
-
hmacSha256(data, key) {
|
|
26
|
-
return createHmac('sha256', key).update(data).digest();
|
|
27
|
-
}
|
|
28
|
-
gzip(data, maxSize) {
|
|
29
|
-
try {
|
|
30
|
-
// telegram accepts both zlib and gzip, but zlib is faster and has less overhead, so we use it here
|
|
31
|
-
return deflateSync(data, {
|
|
32
|
-
maxOutputLength: maxSize,
|
|
33
|
-
});
|
|
34
|
-
// hot path, avoid additional runtime checks
|
|
35
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
36
|
-
}
|
|
37
|
-
catch (e) {
|
|
38
|
-
if (e.code === 'ERR_BUFFER_TOO_LARGE') {
|
|
39
|
-
return null;
|
|
40
|
-
}
|
|
41
|
-
throw e;
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
gunzip(data) {
|
|
45
|
-
return gunzipSync(data);
|
|
46
|
-
}
|
|
47
|
-
randomFill(buf) {
|
|
48
|
-
randomFillSync(buf);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
export class NodeCryptoProvider extends BaseNodeCryptoProvider {
|
|
52
|
-
async initialize() {
|
|
53
|
-
// @only-if-esm
|
|
54
|
-
const require = createRequire(import.meta.url);
|
|
55
|
-
// @/only-if-esm
|
|
56
|
-
const wasmFile = require.resolve('@mtcute/wasm/mtcute.wasm');
|
|
57
|
-
const wasm = await readFile(wasmFile);
|
|
58
|
-
initSync(wasm);
|
|
59
|
-
}
|
|
60
|
-
createAesIge(key, iv) {
|
|
61
|
-
return {
|
|
62
|
-
encrypt(data) {
|
|
63
|
-
return ige256Encrypt(data, key, iv);
|
|
64
|
-
},
|
|
65
|
-
decrypt(data) {
|
|
66
|
-
return ige256Decrypt(data, key, iv);
|
|
67
|
-
},
|
|
68
|
-
};
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
//# sourceMappingURL=crypto.js.map
|
package/esm/utils/crypto.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../../src/utils/crypto.ts"],"names":[],"mappings":"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","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 // @only-if-esm\n const require = createRequire(import.meta.url)\n // @/only-if-esm\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 +0,0 @@
|
|
|
1
|
-
import { UploadFileLike } from '@mtcute/core';
|
|
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;
|
|
10
|
-
} | null>;
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { createReadStream, ReadStream } from 'fs';
|
|
2
|
-
import { stat } from 'fs/promises';
|
|
3
|
-
import { basename } from 'path';
|
|
4
|
-
import { Readable } from 'stream';
|
|
5
|
-
import { nodeStreamToWeb } from './stream-utils.js';
|
|
6
|
-
export async function normalizeFile(file) {
|
|
7
|
-
if (typeof file === 'string') {
|
|
8
|
-
file = createReadStream(file);
|
|
9
|
-
}
|
|
10
|
-
if (file instanceof ReadStream) {
|
|
11
|
-
const fileName = basename(file.path.toString());
|
|
12
|
-
const fileSize = await stat(file.path.toString()).then((stat) => stat.size);
|
|
13
|
-
return {
|
|
14
|
-
file: nodeStreamToWeb(file),
|
|
15
|
-
fileName,
|
|
16
|
-
fileSize,
|
|
17
|
-
};
|
|
18
|
-
}
|
|
19
|
-
if (file instanceof Readable) {
|
|
20
|
-
return {
|
|
21
|
-
file: nodeStreamToWeb(file),
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
// string -> ReadStream, thus already handled
|
|
25
|
-
return null;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=normalize-file.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"normalize-file.js","sourceRoot":"","sources":["../../../src/utils/normalize-file.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AACjD,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AAC/B,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAIjC,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAEnD,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC,IAAoB;IACpD,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;QAC3B,IAAI,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAA;IACjC,CAAC;IAED,IAAI,IAAI,YAAY,UAAU,EAAE,CAAC;QAC7B,MAAM,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC,CAAA;QAC/C,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,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,eAAe,CAAC,IAAI,CAAC;YAC3B,QAAQ;YACR,QAAQ;SACX,CAAA;IACL,CAAC;IAED,IAAI,IAAI,YAAY,QAAQ,EAAE,CAAC;QAC3B,OAAO;YACH,IAAI,EAAE,eAAe,CAAC,IAAI,CAAC;SAC9B,CAAA;IACL,CAAC;IAED,6CAA6C;IAC7C,OAAO,IAAI,CAAA;AACf,CAAC","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,72 +0,0 @@
|
|
|
1
|
-
import { Readable } from 'stream';
|
|
2
|
-
import { isNodeVersionAfter } from './version.js';
|
|
3
|
-
export function nodeStreamToWeb(stream) {
|
|
4
|
-
if (typeof Readable.toWeb === 'function') {
|
|
5
|
-
return Readable.toWeb(stream);
|
|
6
|
-
}
|
|
7
|
-
// otherwise, use a silly little adapter
|
|
8
|
-
stream.pause();
|
|
9
|
-
return new ReadableStream({
|
|
10
|
-
start(c) {
|
|
11
|
-
stream.on('data', (chunk) => {
|
|
12
|
-
c.enqueue(chunk);
|
|
13
|
-
});
|
|
14
|
-
stream.on('end', () => {
|
|
15
|
-
c.close();
|
|
16
|
-
});
|
|
17
|
-
stream.on('error', (err) => {
|
|
18
|
-
c.error(err);
|
|
19
|
-
});
|
|
20
|
-
},
|
|
21
|
-
pull() {
|
|
22
|
-
stream.resume();
|
|
23
|
-
},
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
export function webStreamToNode(stream) {
|
|
27
|
-
if (typeof Readable.fromWeb === 'function' &&
|
|
28
|
-
isNodeVersionAfter(18, 13, 0) // https://github.com/nodejs/node/issues/42694
|
|
29
|
-
) {
|
|
30
|
-
// @ts-expect-error node typings are wrong lmao
|
|
31
|
-
return Readable.fromWeb(stream);
|
|
32
|
-
}
|
|
33
|
-
const reader = stream.getReader();
|
|
34
|
-
let ended = false;
|
|
35
|
-
const readable = new Readable({
|
|
36
|
-
async read() {
|
|
37
|
-
try {
|
|
38
|
-
const { done, value } = await reader.read();
|
|
39
|
-
if (done) {
|
|
40
|
-
this.push(null);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.push(Buffer.from(value.buffer, value.byteOffset, value.byteLength));
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
catch (err) {
|
|
47
|
-
this.destroy(err);
|
|
48
|
-
}
|
|
49
|
-
},
|
|
50
|
-
destroy(error, cb) {
|
|
51
|
-
if (!ended) {
|
|
52
|
-
void reader
|
|
53
|
-
.cancel(error)
|
|
54
|
-
.catch(() => { })
|
|
55
|
-
.then(() => {
|
|
56
|
-
cb(error);
|
|
57
|
-
});
|
|
58
|
-
return;
|
|
59
|
-
}
|
|
60
|
-
cb(error);
|
|
61
|
-
},
|
|
62
|
-
});
|
|
63
|
-
reader.closed
|
|
64
|
-
.then(() => {
|
|
65
|
-
ended = true;
|
|
66
|
-
})
|
|
67
|
-
.catch((err) => {
|
|
68
|
-
readable.destroy(err);
|
|
69
|
-
});
|
|
70
|
-
return readable;
|
|
71
|
-
}
|
|
72
|
-
//# sourceMappingURL=stream-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"stream-utils.js","sourceRoot":"","sources":["../../../src/utils/stream-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAA;AAEjC,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAEjD,MAAM,UAAU,eAAe,CAAC,MAAgB;IAC5C,IAAI,OAAO,QAAQ,CAAC,KAAK,KAAK,UAAU,EAAE,CAAC;QACvC,OAAO,QAAQ,CAAC,KAAK,CAAC,MAAM,CAA0C,CAAA;IAC1E,CAAC;IAED,wCAAwC;IAExC,MAAM,CAAC,KAAK,EAAE,CAAA;IAEd,OAAO,IAAI,cAAc,CAAC;QACtB,KAAK,CAAC,CAAC;YACH,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,EAAE;gBACxB,CAAC,CAAC,OAAO,CAAC,KAAmB,CAAC,CAAA;YAClC,CAAC,CAAC,CAAA;YACF,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,EAAE;gBAClB,CAAC,CAAC,KAAK,EAAE,CAAA;YACb,CAAC,CAAC,CAAA;YACF,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;gBACvB,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAA;YAChB,CAAC,CAAC,CAAA;QACN,CAAC;QACD,IAAI;YACA,MAAM,CAAC,MAAM,EAAE,CAAA;QACnB,CAAC;KACJ,CAAC,CAAA;AACN,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAAkC;IAC9D,IACI,OAAO,QAAQ,CAAC,OAAO,KAAK,UAAU;QACtC,kBAAkB,CAAC,EAAE,EAAE,EAAE,EAAE,CAAC,CAAC,CAAC,8CAA8C;MAC9E,CAAC;QACC,+CAA+C;QAC/C,OAAO,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,CAAA;IACnC,CAAC;IAED,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,EAAE,CAAA;IACjC,IAAI,KAAK,GAAG,KAAK,CAAA;IAEjB,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC;QAC1B,KAAK,CAAC,IAAI;YACN,IAAI,CAAC;gBACD,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAA;gBAE3C,IAAI,IAAI,EAAE,CAAC;oBACP,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;gBACnB,CAAC;qBAAM,CAAC;oBACJ,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,UAAU,EAAE,KAAK,CAAC,UAAU,CAAC,CAAC,CAAA;gBAC5E,CAAC;YACL,CAAC;YAAC,OAAO,GAAG,EAAE,CAAC;gBACX,IAAI,CAAC,OAAO,CAAC,GAAY,CAAC,CAAA;YAC9B,CAAC;QACL,CAAC;QACD,OAAO,CAAC,KAAK,EAAE,EAAE;YACb,IAAI,CAAC,KAAK,EAAE,CAAC;gBACT,KAAK,MAAM;qBACN,MAAM,CAAC,KAAK,CAAC;qBACb,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC;qBACf,IAAI,CAAC,GAAG,EAAE;oBACP,EAAE,CAAC,KAAK,CAAC,CAAA;gBACb,CAAC,CAAC,CAAA;gBAEN,OAAM;YACV,CAAC;YAED,EAAE,CAAC,KAAK,CAAC,CAAA;QACb,CAAC;KACJ,CAAC,CAAA;IAEF,MAAM,CAAC,MAAM;SACR,IAAI,CAAC,GAAG,EAAE;QACP,KAAK,GAAG,IAAI,CAAA;IAChB,CAAC,CAAC;SACD,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE;QACX,QAAQ,CAAC,OAAO,CAAC,GAAY,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEN,OAAO,QAAQ,CAAA;AACnB,CAAC","sourcesContent":["import { Readable } from 'stream'\n\nimport { isNodeVersionAfter } from './version.js'\n\nexport function nodeStreamToWeb(stream: Readable): ReadableStream<Uint8Array> {\n if (typeof Readable.toWeb === 'function') {\n return Readable.toWeb(stream) as unknown as ReadableStream<Uint8Array>\n }\n\n // otherwise, use a silly little adapter\n\n stream.pause()\n\n return new ReadableStream({\n start(c) {\n stream.on('data', (chunk) => {\n c.enqueue(chunk as Uint8Array)\n })\n stream.on('end', () => {\n c.close()\n })\n stream.on('error', (err) => {\n c.error(err)\n })\n },\n pull() {\n stream.resume()\n },\n })\n}\n\nexport function webStreamToNode(stream: ReadableStream<Uint8Array>): Readable {\n if (\n typeof Readable.fromWeb === 'function' &&\n isNodeVersionAfter(18, 13, 0) // https://github.com/nodejs/node/issues/42694\n ) {\n // @ts-expect-error node typings are wrong lmao\n return Readable.fromWeb(stream)\n }\n\n const reader = stream.getReader()\n let ended = false\n\n const readable = new Readable({\n async read() {\n try {\n const { done, value } = await reader.read()\n\n if (done) {\n this.push(null)\n } else {\n this.push(Buffer.from(value.buffer, value.byteOffset, value.byteLength))\n }\n } catch (err) {\n this.destroy(err as Error)\n }\n },\n destroy(error, cb) {\n if (!ended) {\n void reader\n .cancel(error)\n .catch(() => {})\n .then(() => {\n cb(error)\n })\n\n return\n }\n\n cb(error)\n },\n })\n\n reader.closed\n .then(() => {\n ended = true\n })\n .catch((err) => {\n readable.destroy(err as Error)\n })\n\n return readable\n}\n"]}
|
package/esm/utils/tcp.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import EventEmitter from 'events';
|
|
2
|
-
import { Socket } from 'net';
|
|
3
|
-
import { IntermediatePacketCodec, IPacketCodec, ITelegramTransport, TransportState } from '@mtcute/core';
|
|
4
|
-
import { BasicDcOption, ICryptoProvider, Logger } from '@mtcute/core/utils.js';
|
|
5
|
-
/**
|
|
6
|
-
* Base for TCP transports.
|
|
7
|
-
* Subclasses must provide packet codec in `_packetCodec` property
|
|
8
|
-
*/
|
|
9
|
-
export declare abstract class BaseTcpTransport extends EventEmitter implements ITelegramTransport {
|
|
10
|
-
protected _currentDc: BasicDcOption | null;
|
|
11
|
-
protected _state: TransportState;
|
|
12
|
-
protected _socket: Socket | null;
|
|
13
|
-
abstract _packetCodec: IPacketCodec;
|
|
14
|
-
protected _crypto: ICryptoProvider;
|
|
15
|
-
protected log: Logger;
|
|
16
|
-
packetCodecInitialized: boolean;
|
|
17
|
-
private _updateLogPrefix;
|
|
18
|
-
setup(crypto: ICryptoProvider, log: Logger): void;
|
|
19
|
-
state(): TransportState;
|
|
20
|
-
currentDc(): BasicDcOption | null;
|
|
21
|
-
connect(dc: BasicDcOption, testMode: boolean): void;
|
|
22
|
-
close(): void;
|
|
23
|
-
handleError(error: Error): void;
|
|
24
|
-
handleConnect(): void;
|
|
25
|
-
send(bytes: Uint8Array): Promise<void>;
|
|
26
|
-
}
|
|
27
|
-
export declare class TcpTransport extends BaseTcpTransport {
|
|
28
|
-
_packetCodec: IntermediatePacketCodec;
|
|
29
|
-
}
|