diff --git a/.npmrc b/.npmrc new file mode 100644 index 00000000..62f0ebfa --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +@mtcute:registry=https://npm.tei.su diff --git a/README.md b/README.md index 71680f3f..d0f0926d 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,18 @@ Work-in-progress library for MTProto in TypeScript. > If you encounter errors related to storage, either > reset your storage by removing the file, or fix it manually. +## Installation + +MTCute is currently only published in my private NPM registry. + +You can install it by running: + +```bash +npm config set --location project @mtcute:registry https://npm.tei.su + +npm install @mtcute/node # or any other package +``` + ## Setting up for development: ```bash diff --git a/packages/core/src/utils/platform/crypto.ts b/packages/core/src/utils/platform/crypto.ts index 8ee77398..5e527d61 100644 --- a/packages/core/src/utils/platform/crypto.ts +++ b/packages/core/src/utils/platform/crypto.ts @@ -4,5 +4,4 @@ import { randomBytes } from 'crypto' /** @internal */ export const _defaultCryptoProviderFactory = () => new NodeCryptoProvider() -/** @internal */ export const _randomBytes = randomBytes diff --git a/packages/core/src/utils/platform/crypto.web.ts b/packages/core/src/utils/platform/crypto.web.ts index 8f1a979b..11b42dfa 100644 --- a/packages/core/src/utils/platform/crypto.web.ts +++ b/packages/core/src/utils/platform/crypto.web.ts @@ -4,7 +4,6 @@ import { typedArrayToBuffer } from '../buffer-utils' /** @internal */ export const _defaultCryptoProviderFactory = () => new ForgeCryptoProvider() -/** @internal */ export function _randomBytes(size: number): Buffer { const ret = new Uint8Array(size) crypto.getRandomValues(ret) diff --git a/packages/crypto-node/package.json b/packages/crypto-node/package.json index c9e79282..2cd15263 100644 --- a/packages/crypto-node/package.json +++ b/packages/crypto-node/package.json @@ -2,6 +2,7 @@ "name": "@mtcute/crypto-node", "version": "1.0.0", "description": "Native crypto implementation for NodeJS", + "author": "Alisa Sireneva ", "main": "src/index.ts", "private": true, "license": "LGPL-3.0", diff --git a/packages/sqlite/index.ts b/packages/sqlite/index.ts index 455c64d9..ee0f3db3 100644 --- a/packages/sqlite/index.ts +++ b/packages/sqlite/index.ts @@ -10,9 +10,11 @@ import { tl, throttle, Logger, + TlBinaryReader, + TlReaderMap, + TlWriterMap, } from '@mtcute/core' import sqlite3 from 'better-sqlite3' -import { TlBinaryReader, TlReaderMap, TlWriterMap } from '../tl-runtime' // todo: add testMode to "self" diff --git a/packages/tl-runtime/README.md b/packages/tl-runtime/README.md new file mode 100644 index 00000000..7a78a8dc --- /dev/null +++ b/packages/tl-runtime/README.md @@ -0,0 +1,9 @@ +# @mtcute/tl-runtime + +This package contains runtime for TL (de-)serialization. +It only contains binary reader and writer implementations, +and is used by `@mtcute/core`. + +`@mtcute/tl-utils` on the other hand has utilities like codegen +and schema manipulation, which is only needed at runtime if you +are patching the schema (which is a rare case anyways). diff --git a/packages/tl-runtime/tsconfig.json b/packages/tl-runtime/tsconfig.json index 0d69ea46..d4fa0ff8 100644 --- a/packages/tl-runtime/tsconfig.json +++ b/packages/tl-runtime/tsconfig.json @@ -4,8 +4,7 @@ "outDir": "./dist" }, "include": [ - "./src/reader.ts", - "./src/writer.ts", + "./src", ], "typedocOptions": { "name": "@mtcute/tl-runtime", @@ -14,8 +13,7 @@ "listInvalidSymbolLinks": true, "excludePrivate": true, "entryPoints": [ - "./src/reader.ts", - "./src/writer.ts" + "./src/index.ts" ] } } diff --git a/packages/tl-utils/README.md b/packages/tl-utils/README.md new file mode 100644 index 00000000..df53f058 --- /dev/null +++ b/packages/tl-utils/README.md @@ -0,0 +1,3 @@ +# @mtcute/tl-utils + +This package contains utilities for TL schema parsing and manipulation. diff --git a/scripts/publish.js b/scripts/publish.js index 8e60edb9..9f43cb38 100644 --- a/scripts/publish.js +++ b/scripts/publish.js @@ -20,13 +20,11 @@ function publishSinglePackage(name) { 'binary/rsa-keys.js', 'binary/writer.d.ts', 'binary/writer.js', - 'errors.d.ts', - 'errors.js', 'index.d.ts', 'index.js', 'raw-errors.json', - 'raw-schema.d.ts', - 'raw-schema.json', + 'mtp-schema.json', + 'api-schema.json', 'package.json', 'README.md', ] @@ -39,7 +37,7 @@ function publishSinglePackage(name) { } else { // build ts cp.execSync( - 'yarn run ' + (name === 'crypto-node' ? 'build-ts' : 'build'), + 'pnpm run ' + (name === 'crypto-node' ? 'build-ts' : 'build'), { cwd: dir, stdio: 'inherit', @@ -56,15 +54,9 @@ function publishSinglePackage(name) { content = content.replace('/// ', '') } - if (content.match(/@mtcute\/[a-z]+\/src/)) { + if (content.match(/@mtcute\/[a-z-]+\/src/)) { changed = true - content = content.replace(/(@mtcute\/[a-z]+)\/src/g, '$1') - } - - if (content.trim().match(/^export {};?$/)) { - // no public exports, we can safely remove this module - changed = false - fs.unlinkSync(f) + content = content.replace(/(@mtcute\/[a-z-]+)\/src/g, '$1') } if (changed) fs.writeFileSync(f, content) @@ -75,9 +67,9 @@ function publishSinglePackage(name) { let content = fs.readFileSync(f, 'utf8') let changed = false - if (content.match(/@mtcute\/[a-z]+\/src/)) { + if (content.match(/@mtcute\/[a-z-]+\/src/)) { changed = true - content = content.replace(/(@mtcute\/[a-z]+)\/src/g, '$1') + content = content.replace(/(@mtcute\/[a-z-]+)\/src/g, '$1') } if (changed) fs.writeFileSync(f, content) @@ -192,9 +184,28 @@ function publishSinglePackage(name) { throw new Error(`${name}'s package.json does not contain "main"`) // since "src" is compiled to "dist", we need to remove that prefix - packJson.main = packJson.main.replace(/^(?:\.\/)?src\//, '') + packJson.main = packJson.main + .replace(/^(?:\.\/)?src\//, '') + .replace(/\.ts$/, '.js') packJson.private = false + function replaceWorkspaceDependencies(field) { + if (packJson[field]) { + const dependencies = packJson[field] + for (const name of Object.keys(dependencies)) { + const value = dependencies[name] + if (value.startsWith('workspace:')) { + dependencies[name] = value.replace('workspace:', '') + } + } + } + } + + replaceWorkspaceDependencies('dependencies') + replaceWorkspaceDependencies('devDependencies') + replaceWorkspaceDependencies('peerDependencies') + replaceWorkspaceDependencies('optionalDependencies') + fs.writeFileSync( path.join(dir, 'dist/package.json'), JSON.stringify(packJson, null, 4) @@ -225,7 +236,7 @@ function publishSinglePackage(name) { console.log('[i] Publishing %s', name) // publish to npm - cp.execSync('yarn publish', { + cp.execSync('npm publish', { cwd: dir, stdio: 'inherit', }) @@ -243,6 +254,7 @@ if (require.main === module) { if (arg === 'all') { for (const f of fs.readdirSync(path.join(__dirname, '../packages'))) { if (LOCAL.indexOf(f) > -1) continue + if (f[0] === '.') continue publishSinglePackage(f) }