build: migrated to pnpm, updated and cleaned up deps

This commit is contained in:
teidesu 2022-04-28 16:58:09 +03:00
parent 87f668bc30
commit 2289cc690d
32 changed files with 3709 additions and 6777 deletions

View file

@ -25,29 +25,16 @@ Work-in-progress library for MTProto in TypeScript.
> If you encounter errors related to storage, either > If you encounter errors related to storage, either
> reset your storage by removing the file, or fix it manually. > reset your storage by removing the file, or fix it manually.
What currently works:
- [x] TCP Connection in NodeJS
- [x] Sending & receiving text messages
- [x] Uploading & downloading files
- [x] HTML & Markdown parse modes
- [x] Type-safe filter system
What is not done yet:
- pretty much everything else
## Setting up for development: ## Setting up for development:
```bash ```bash
git clone https://github.com/mtcute/mtcute git clone https://github.com/mtcute/mtcute
cd mtcute cd mtcute
yarn install pnpm install
npx lerna link
# generate code from tl schema # generate code from tl schema
cd packages/tl cd packages/tl
yarn generate-code pnpm run gen-code
``` ```
## Acknowledgements ## Acknowledgements

View file

@ -1,11 +0,0 @@
{
"command": {
"create": {
"license": "MIT",
"author": "Alisa Sireneva <me@tei.su>"
}
},
"version": "independent",
"npmClient": "yarn",
"useWorkspaces": true
}

View file

@ -13,40 +13,27 @@
"publish-all": "node scripts/publish.js all" "publish-all": "node scripts/publish.js all"
}, },
"dependencies": { "dependencies": {
"node-gyp": "^8.0.0" "node-gyp": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/chai": "^4.2.14", "@types/chai": "^4.3.1",
"@types/debug": "^4.1.5", "@types/mocha": "^9.1.1",
"@types/mocha": "^8.2.0",
"@types/node": "^14.14.22", "@types/node": "^14.14.22",
"@types/node-forge": "^0.9.7", "@types/node-forge": "^1.0.2",
"@types/node-fetch": "^2.5.10",
"@types/pako": "^1.0.1",
"@types/ws": "^7.4.0", "@types/ws": "^7.4.0",
"@typescript-eslint/eslint-plugin": "^4.15.0", "@typescript-eslint/eslint-plugin": "^4.15.0",
"@typescript-eslint/parser": "^4.15.0", "@typescript-eslint/parser": "^4.15.0",
"benchmark": "^2.1.4", "chai": "^4.3.6",
"chai": "^4.2.0", "eslint": "^7.32.0",
"cheerio": "^1.0.0-rc.5", "eslint-config-prettier": "^8.5.0",
"eager-async-pool": "^1.0.0", "mocha": "^9.2.2",
"eslint": "^7.19.0", "node-forge": "^1.3.1",
"eslint-config-prettier": "7.2.0", "prettier": "^2.6.2",
"lerna": "^4.0.0", "ts-node": "^10.7.0",
"mocha": "^8.2.1", "typedoc": "^0.22.15",
"node-fetch": "^2.6.1", "typescript": "^4.6.3",
"node-forge": "^0.10.0",
"node-html-parser": "^3.0.4",
"prettier": "2.2.1",
"ts-node": "^9.1.1",
"typedoc": "^0.20.28",
"typescript": "^4.1.3",
"nyc": "^15.1.0", "nyc": "^15.1.0",
"glob": "^7.1.7",
"rimraf": "^3.0.2", "rimraf": "^3.0.2",
"dotenv-flow": "^3.2.0" "dotenv-flow": "^3.2.0"
}, }
"workspaces": [
"packages/*"
]
} }

View file

@ -14,9 +14,9 @@
"dependencies": { "dependencies": {
"@types/long": "^4.0.1", "@types/long": "^4.0.1",
"@types/node": "^15.12.1", "@types/node": "^15.12.1",
"@mtcute/tl": "~139.0", "@mtcute/tl": "workspace:139.0",
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"@mtcute/file-id": "^1.0.0", "@mtcute/file-id": "workspace:^1.0.0",
"eager-async-pool": "^1.0.0", "eager-async-pool": "^1.0.0",
"file-type": "^16.2.0", "file-type": "^16.2.0",
"long": "^4.0.0" "long": "^4.0.0"

View file

@ -100,7 +100,7 @@ export async function* downloadAsIterable(
}, },
{ connection } { connection }
) )
} catch (e) { } catch (e: any) {
if (e.constructor === tl.errors.FileMigrateXError) { if (e.constructor === tl.errors.FileMigrateXError) {
connection = this._downloadConnections[e.new_dc] connection = this._downloadConnections[e.new_dc]
if (!connection) { if (!connection) {

View file

@ -361,7 +361,7 @@ export async function _saveStorage(
} }
await this.storage.save?.() await this.storage.save?.()
} catch (err) { } catch (err: any) {
this._emitError(err) this._emitError(err)
} }
} }

View file

@ -489,7 +489,7 @@ export class Conversation {
it.promise.resolve(msg) it.promise.resolve(msg)
this._queuedNewMessage.popFront() this._queuedNewMessage.popFront()
} }
} catch (e) { } catch (e: any) {
this.client['_emitError'](e) this.client['_emitError'](e)
} }

View file

@ -71,7 +71,7 @@ export function makeInspectable(
val = val.toJSON(true) val = val.toJSON(true)
} }
ret[it] = val ret[it] = val
} catch (e) { } catch (e: any) {
ret[it] = "Error: " + e.message ret[it] = "Error: " + e.message
} }
}) })

View file

@ -20,8 +20,8 @@
"dependencies": { "dependencies": {
"@types/node": "^15.12.1", "@types/node": "^15.12.1",
"@types/events": "^3.0.0", "@types/events": "^3.0.0",
"@mtcute/tl": "~139.0", "@mtcute/tl": "workspace:139.0",
"@mtcute/tl-runtime": "^1.0.0", "@mtcute/tl-runtime": "workspace:^1.0.0",
"big-integer": "1.6.48", "big-integer": "1.6.48",
"long": "^4.0.0", "long": "^4.0.0",
"events": "3.2.0" "events": "3.2.0"

View file

@ -659,7 +659,7 @@ export class BaseTelegramClient extends EventEmitter {
await this._cachePeersFrom(res) await this._cachePeersFrom(res)
return res return res
} catch (e) { } catch (e: any) {
lastError = e lastError = e
if (e instanceof tl.errors.InternalError) { if (e instanceof tl.errors.InternalError) {

View file

@ -1166,7 +1166,7 @@ export class SessionConnection extends PersistentConnection {
try { try {
this._doFlush() this._doFlush()
} catch (e) { } catch (e: any) {
this.log.error('flush error: %s', e.stack) this.log.error('flush error: %s', e.stack)
// should not happen unless there's a bug in the code // should not happen unless there's a bug in the code
} }

View file

@ -17,6 +17,6 @@
"docs": "npx typedoc" "docs": "npx typedoc"
}, },
"dependencies": { "dependencies": {
"@mtcute/core": "^1.0.0" "@mtcute/core": "workspace:^1.0.0"
} }
} }

View file

@ -12,9 +12,9 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@mtcute/tl": "~139.0", "@mtcute/tl": "workspace:139.0",
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"@mtcute/client": "^1.0.0", "@mtcute/client": "workspace:^1.0.0",
"events": "^3.2.0" "events": "^3.2.0"
} }
} }

View file

@ -447,7 +447,7 @@ export class Dispatcher<State = never, SceneName extends string = string> {
break break
} }
} catch (e) { } catch (e: any) {
if (this._errorHandler) { if (this._errorHandler) {
const handled = await this._errorHandler( const handled = await this._errorHandler(
e, e,

View file

@ -225,7 +225,7 @@ export class UpdateState<State, SceneName extends string = string> {
async throttle(key: string, limit: number, window: number): Promise<[number, number]> { async throttle(key: string, limit: number, window: number): Promise<[number, number]> {
try { try {
return await this.rateLimit(key, limit, window) return await this.rateLimit(key, limit, window)
} catch (e) { } catch (e: any) {
if (e.constructor === RateLimitError) { if (e.constructor === RateLimitError) {
await sleep(e.reset - Date.now()) await sleep(e.reset - Date.now())
return this.throttle(key, limit, window) return this.throttle(key, limit, window)

View file

@ -12,9 +12,9 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@mtcute/tl": "~139.0", "@mtcute/tl": "workspace:139.0",
"@mtcute/tl-runtime": "^1.0.0", "@mtcute/tl-runtime": "workspace:^1.0.0",
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"long": "^4.0.0" "long": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {

View file

@ -13,7 +13,7 @@
"docs": "npx typedoc" "docs": "npx typedoc"
}, },
"dependencies": { "dependencies": {
"@mtcute/tl": "~139.0", "@mtcute/tl": "workspace:~139.0",
"htmlparser2": "^6.0.1", "htmlparser2": "^6.0.1",
"long": "^4.0.0" "long": "^4.0.0"
}, },

View file

@ -12,6 +12,6 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@mtcute/core": "^1.0.0" "@mtcute/core": "workspace:^1.0.0"
} }
} }

View file

@ -13,11 +13,11 @@
"docs": "npx typedoc" "docs": "npx typedoc"
}, },
"dependencies": { "dependencies": {
"@mtcute/tl": "~139.0", "@mtcute/tl": "workspace:139.0",
"long": "^4.0.0" "long": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@mtcute/client": "^1.0.0", "@mtcute/client": "workspace:^1.0.0",
"@types/long": "^4.0.1" "@types/long": "^4.0.1"
} }
} }

View file

@ -12,7 +12,7 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"big-integer": "1.6.48" "big-integer": "1.6.48"
} }
} }

View file

@ -12,11 +12,11 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"@mtcute/client": "^1.0.0", "@mtcute/client": "workspace:^1.0.0",
"@mtcute/sqlite": "^1.0.0", "@mtcute/sqlite": "workspace:^1.0.0",
"@mtcute/markdown-parser": "^1.0.0", "@mtcute/markdown-parser": "workspace:^1.0.0",
"@mtcute/html-parser": "^1.0.0", "@mtcute/html-parser": "workspace:^1.0.0",
"@mtcute/dispatcher": "^1.0.0" "@mtcute/dispatcher": "workspace:^1.0.0"
} }
} }

View file

@ -12,7 +12,7 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"ip6": "^0.2.6" "ip6": "^0.2.6"
} }
} }

View file

@ -7,11 +7,11 @@ import {
LruMap, LruMap,
TlBinaryWriter, TlBinaryWriter,
toggleChannelIdMark, toggleChannelIdMark,
tl,
throttle,
Logger,
} from '@mtcute/core' } from '@mtcute/core'
import { tl } from '@mtcute/tl'
import sqlite3 from 'better-sqlite3' import sqlite3 from 'better-sqlite3'
import { throttle } from '@mtcute/core'
import { Logger } from '@mtcute/core/src/utils/logger'
import { TlBinaryReader, TlReaderMap, TlWriterMap } from '../tl-runtime' import { TlBinaryReader, TlReaderMap, TlWriterMap } from '../tl-runtime'
// todo: add testMode to "self" // todo: add testMode to "self"
@ -54,46 +54,57 @@ const CURRENT_VERSION = 2
// language=SQLite // language=SQLite
const SCHEMA = ` const SCHEMA = `
create table kv ( create table kv
key text primary key, (
key text primary key,
value text not null value text not null
); );
create table state ( create table state
key text primary key, (
value text not null, key text primary key,
value text not null,
expires number expires number
); );
create table auth_keys ( create table auth_keys
dc integer primary key, (
dc integer primary key,
key blob not null key blob not null
); );
create table pts ( create table pts
(
channel_id integer primary key, channel_id integer primary key,
pts integer not null pts integer not null
); );
create table entities ( create table entities
id integer primary key, (
hash text not null, id integer primary key,
type text not null, hash text not null,
type text not null,
username text, username text,
phone text, phone text,
updated integer not null, updated integer not null,
"full" blob "full" blob
); );
create index idx_entities_username on entities (username); create index idx_entities_username on entities (username);
create index idx_entities_phone on entities (phone); create index idx_entities_phone on entities (phone);
` `
const RESET = ` const RESET = `
delete from kv where key <> 'ver'; delete
delete from state; from kv
delete from auth_keys; where key <> 'ver';
delete from pts; delete
delete from entities from state;
delete
from auth_keys;
delete
from pts;
delete
from entities
` `
const USERNAME_TTL = 86400000 // 24 hours const USERNAME_TTL = 86400000 // 24 hours

View file

@ -12,8 +12,8 @@
"build": "tsc" "build": "tsc"
}, },
"dependencies": { "dependencies": {
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"@mtcute/tl-runtime": "^1.0.0", "@mtcute/tl-runtime": "workspace:^1.0.0",
"better-sqlite3": "^7.4.0", "better-sqlite3": "^7.4.0",
"long": "^4.0.0" "long": "^4.0.0"
}, },

View file

@ -16,10 +16,10 @@
}, },
"dependencies": { "dependencies": {
"long": "4.0.0", "long": "4.0.0",
"crc-32": "1.2.0",
"pako": "2.0.2" "pako": "2.0.2"
}, },
"devDependencies": { "devDependencies": {
"@types/long": "4.0.1" "@types/long": "4.0.1",
"@types/pako": "^1.0.1"
} }
} }

View file

@ -8,7 +8,7 @@ export function gzipDeflate(buf: Buffer, maxRatio?: number): Buffer | null {
if (maxRatio) { if (maxRatio) {
try { try {
return deflateSync(buf, { maxOutputLength: Math.floor(buf.length * maxRatio) }) return deflateSync(buf, { maxOutputLength: Math.floor(buf.length * maxRatio) })
} catch (e) { } catch (e: any) {
if (e.code === 'ERR_BUFFER_TOO_LARGE') { if (e.code === 'ERR_BUFFER_TOO_LARGE') {
return null return null
} }

View file

@ -1,6 +1,11 @@
import { typedArrayToBuffer } from '../buffer-utils'
import { Data, Deflate, inflate } from 'pako' import { Data, Deflate, inflate } from 'pako'
export function typedArrayToBuffer(arr: NodeJS.TypedArray): Buffer {
return ArrayBuffer.isView(arr)
? Buffer.from(arr.buffer, arr.byteOffset, arr.byteLength)
: Buffer.from(arr)
}
export function gzipInflate(buf: Buffer): Buffer { export function gzipInflate(buf: Buffer): Buffer {
return typedArrayToBuffer(inflate(buf)) return typedArrayToBuffer(inflate(buf))
} }

View file

@ -15,11 +15,6 @@
"./platform/gzip.js": "./platform/gzip.web.js" "./platform/gzip.js": "./platform/gzip.web.js"
}, },
"dependencies": { "dependencies": {
"long": "4.0.0", "crc-32": "1.2.0"
"crc-32": "1.2.0",
"pako": "2.0.2"
},
"devDependencies": {
"@types/long": "4.0.1"
} }
} }

View file

@ -21,10 +21,12 @@
"long": "^4.0.0" "long": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@mtcute/tl-utils": "^1.0.0", "@mtcute/tl-utils": "workspace:^1.0.0",
"@mtcute/core": "^1.0.0", "@mtcute/core": "workspace:^1.0.0",
"cheerio": "^1.0.0-rc.5", "cheerio": "^1.0.0-rc.5",
"csv-parser": "^3.0.0", "csv-parser": "^3.0.0",
"js-yaml": "^4.0.0" "js-yaml": "^4.0.0",
"node-fetch": "^2.6.1",
"@types/node-fetch": "^2.5.10"
} }
} }

3606
pnpm-lock.yaml Normal file

File diff suppressed because it is too large Load diff

2
pnpm-workspace.yaml Normal file
View file

@ -0,0 +1,2 @@
packages:
- packages/*

6652
yarn.lock

File diff suppressed because it is too large Load diff