Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tdlib-native

Package Overview
Dependencies
Maintainers
0
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tdlib-native - npm Package Compare versions

Comparing version 2.5.0 to 2.6.0

dist/assert.d.ts

15

dist/addon/addon.js
"use strict";
const path$1 = require("path"),
path = require("./path.js"),
module$1 = require("module");
/**
module$1 = require("module"),
assert = require("../assert.js"); /**
*

@@ -21,3 +21,3 @@ *

}
const isMusl = () => !process.report?.getReport()?.header?.glibcVersionRuntime;
const isGlibc = () => !!process.report?.getReport()?.header?.glibcVersionRuntime;
/**

@@ -31,7 +31,6 @@ *

if (process.platform === "linux") {
if (isMusl()) {
throw new Error(
"TDLib build for MUSL libc is not ready yet. You can ask for do it quicker: https://github.com/AlexXanderGrib/node-tdlib/issues"
);
}
assert.assert(
isGlibc(),
"TDLib build for MUSL libc is not ready yet. You can ask for do it quicker: https://github.com/AlexXanderGrib/node-tdlib/issues"
);
packageName += "-glibc";

@@ -38,0 +37,0 @@ }

"use strict";
const path = require("path");
/**
const path = require("path"); /**
*

@@ -5,0 +4,0 @@ *

@@ -1,4 +0,3 @@

/// <reference types="node" />
import { Client } from "./client";
import { setTdlibParameters$DirectInput, phoneNumberAuthenticationSettings$Input, authenticationCodeInfo, emailAddressAuthenticationCodeInfo, registerUser$DirectInput, TermsOfService } from "./types";
import { setTdlibParameters$DirectInput, phoneNumberAuthenticationSettings$Input, authenticationCodeInfo, emailAddressAuthenticationCodeInfo, registerUser$DirectInput, TermsOfService } from "./generated/types";
type AuthenticateOptions = {

@@ -5,0 +4,0 @@ readonly signal?: AbortSignal;

"use strict";
const types = require("./generated/types.js");
/**
const types = require("./generated/types.js"); /**
*

@@ -95,3 +94,3 @@ *

code: {
_: "emailAddressAuthenticationCode",
[types.typename]: "emailAddressAuthenticationCode",
code: await wait(this._state.emailCode, state.code_info)

@@ -98,0 +97,0 @@ }

"use strict";
const base64abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/**

@@ -13,18 +13,16 @@ * Encodes

let index;
const l = bytes.length;
for (index = 2; index < l; index += 3) {
result += base64abc[bytes[index - 2] >> 2];
result += base64abc[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += base64abc[((bytes[index - 1] & 0x0f) << 2) | (bytes[+index] >> 6)];
result += base64abc[bytes[+index] & 0x3f];
for (index = 2; index < bytes.length; index += 3) {
result += alphabet[bytes[index - 2] >> 2];
result += alphabet[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += alphabet[((bytes[index - 1] & 0x0f) << 2) | (bytes[index] >> 6)];
result += alphabet[bytes[index] & 0x3f];
}
if (index === l + 1) {
result += base64abc[bytes[index - 2] >> 2];
result += base64abc[(bytes[index - 2] & 0x03) << 4];
if (index === bytes.length + 1) {
result += alphabet[bytes[index - 2] >> 2];
result += alphabet[(bytes[index - 2] & 0x03) << 4];
result += "==";
}
if (index === l) {
result += base64abc[bytes[index - 2] >> 2];
result += base64abc[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += base64abc[(bytes[index - 1] & 0x0f) << 2];
} else if (index === bytes.length) {
result += alphabet[bytes[index - 2] >> 2];
result += alphabet[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += alphabet[(bytes[index - 1] & 0x0f) << 2];
result += "=";

@@ -31,0 +29,0 @@ }

import type { TDLib } from "./shared/client";
import { error, Update, $AsyncApi, $SyncApi, $MethodsDict } from "./generated/types";
import { error, Update, $AsyncApi, $SyncApi, $MethodsDict, typename } from "./generated/types";
import { Observable } from "./event-bus";
import { TDLibOptions } from "./options";
type OmitType<T extends {
_: string;
}> = Omit<T, "_">;
[typename]: string;
}> = Omit<T, typename>;
/**

@@ -17,3 +17,3 @@ *

export declare class TDError extends Error implements error {
readonly _ = "error";
readonly [typename] = "error";
readonly code: number;

@@ -69,2 +69,3 @@ readonly method: string;

readonly syncApi: $SyncApi;
readonly _tdlibOptions: TDLibOptions;
/**

@@ -82,4 +83,13 @@ *

/**
* Disables logging of TDLib instance
*
* @static
* @param {TDLib} lib
* @memberof Client
* @returns {void}
*/
static disableLogs(lib: TDLib): void;
/**
*
*
* @template {keyof $SyncApi} T

@@ -86,0 +96,0 @@ * @param {TDLib|Client} executor

@@ -7,4 +7,6 @@ "use strict";

debug = require("debug"),
options = require("./options.js");
options = require("./options.js"),
assert = require("./assert.js");
const debugJson = debug("tdlib-native:json");
const tag = "@extra";
/**

@@ -19,3 +21,3 @@ *

class TDError extends Error {
_ = "error";
[types.typename] = "error";
code;

@@ -48,3 +50,3 @@ method;

return {
_: this._,
[types.typename]: this[types.typename],
name: this.name,

@@ -82,2 +84,3 @@ message: this.message,

syncApi = new types.$SyncApi(this);
_tdlibOptions = new options.TDLibOptions(this.api);
/**

@@ -96,7 +99,11 @@ *

const data = async.promiseWithResolvers();
assignTemporary(parameters, { _: method, "@extra": extra }, (merged) => {
const value = json.serialize(merged);
debugJson("Sent %s", value);
this._adapter.send(this._client, value);
});
assignTemporary(
parameters,
{ [types.typename]: method, [tag]: extra },
(merged) => {
const value = json.serialize(merged);
debugJson("Sent %s", value);
this._adapter.send(this._client, value);
}
);
this._requests.set(extra, data);

@@ -106,3 +113,3 @@ try {

} catch (error) {
if (typeof error === "object" && error && "_" in error) {
if (typeof error === "object" && error && types.typename in error) {
const value = error;

@@ -115,4 +122,15 @@ throw new TDError(value.message, { code: value.code, method, parameters });

/**
* Disables logging of TDLib instance
*
* @static
* @param {TDLib} lib
* @memberof Client
* @returns {void}
*/
static disableLogs(lib) {
Client.execute(lib, "setLogVerbosityLevel", { new_verbosity_level: 0 });
}
/**
*
*
* @template {keyof $SyncApi} T

@@ -144,3 +162,3 @@ * @param {TDLib|Client} executor

parameters,
{ _: method, "@extra": extra },
{ [types.typename]: method, [tag]: extra },
(merged) => {

@@ -153,20 +171,22 @@ const value = json.serialize(merged);

debugJson("Received sync %s", value);
if (!value) {
throw new TDError("Method returned null", { method, parameters });
}
assert.assert(
value,
new TDError("Method returned null", { method, parameters })
);
let data;
try {
data = json.deserialize(value);
if (typeof data !== "object" || !data || !("_" in data)) {
throw new TDError("Returned not an object", { method, parameters });
}
} catch {
throw new TDError("Method returned invalid json", { method, parameters });
}
if (data._ === "error") {
assert.assert(
typeof data === "object" && data && types.typename in data,
new TDError("Returned not an object", { method, parameters })
);
if (data[types.typename] === "error") {
const error = data;
throw new TDError(error.message, { code: error.code, method, parameters });
}
if ("@extra" in data && data["@extra"]) {
delete data["@extra"];
if (tag in data && data[tag]) {
delete data[tag];
}

@@ -211,7 +231,7 @@ return data;

}
const extra = data?.["@extra"];
const extra = data?.[tag];
if (extra) {
const async = this._requests.get(extra);
delete data["@extra"];
if (data._ === "error") {
delete data[tag];
if (data[types.typename] === "error") {
async?.reject(data);

@@ -224,3 +244,3 @@ } else {

}
if (data._.startsWith("update")) {
if (data[types.typename].startsWith("update")) {
this._updates.emit(data);

@@ -237,3 +257,3 @@ }

get tdlibOptions() {
return options.TDLibOptions.for(this.api);
return this._tdlibOptions;
}

@@ -257,8 +277,9 @@ /**

start() {
if (this._state === "PAUSED") {
this._state = "RUNNING";
this._thread();
return this;
}
throw new Error("Cannot start: This client is running or destroyed");
assert.assert(
this._state === "PAUSED",
"Cannot start: This client is running or destroyed"
);
this._state = "RUNNING";
this._thread();
return this;
}

@@ -272,7 +293,8 @@ /**

pause() {
if (this._state === "RUNNING") {
this._state = "PAUSED";
return this;
}
throw new Error("Cannot pause: This client is paused or destroyed");
assert.assert(
this._state === "RUNNING",
"Cannot pause: This client is paused or destroyed"
);
this._state = "PAUSED";
return this;
}

@@ -279,0 +301,0 @@ /**

"use strict";
/**
const assert = require("./assert.js"); /**
*

@@ -35,5 +35,3 @@ *

subscribe(handler) {
if (this._completed) {
throw new Error("Completed");
}
assert.assert(!this._completed, "Completed");
const cached = this._subscriptions.get(handler);

@@ -40,0 +38,0 @@ if (cached) return cached;

"use strict";
const base64 = require("./base64.js");
const mainKey = /"_":/g;
const tdKey = /"@type":/g;
const base64 = require("./base64.js"),
types = require("./generated/types.js");
const tdTypename = "@type";
const mainKey = new RegExp(`"${types.typename}":`, "g");
const tdKey = new RegExp(`"${tdTypename}":`, "g");
/**

@@ -40,3 +42,3 @@ *

const json = JSON.stringify(data, replacer);
return json.replace(mainKey, '"@type":');
return json.replace(mainKey, `"${tdTypename}":`);
}

@@ -52,5 +54,5 @@ /**

function deserialize(json) {
return JSON.parse(json.replace(tdKey, '"_":'));
return JSON.parse(json.replace(tdKey, `"${types.typename}":`));
}
exports.deserialize = deserialize;
exports.serialize = serialize;

@@ -1,3 +0,2 @@

/// <reference types="node" />
import { replyMarkupForceReply, replyMarkupRemoveKeyboard, replyMarkupShowKeyboard$Input, KeyboardButtonType$Input, replyMarkupInlineKeyboard$Input, InlineKeyboardButtonType$Input } from "./types";
import { replyMarkupForceReply, replyMarkupRemoveKeyboard, replyMarkupShowKeyboard$Input, KeyboardButtonType$Input, replyMarkupInlineKeyboard$Input, InlineKeyboardButtonType$Input } from "./generated/types";
/**

@@ -4,0 +3,0 @@ *

"use strict";
/**
const types = require("./generated/types.js"); /**
*

@@ -11,3 +11,3 @@ *

return {
_: "replyMarkupForceReply",
[types.typename]: "replyMarkupForceReply",
input_field_placeholder: placeholder,

@@ -26,3 +26,3 @@ is_personal: personal

return {
_: "replyMarkupRemoveKeyboard",
[types.typename]: "replyMarkupRemoveKeyboard",
is_personal: personal

@@ -66,3 +66,3 @@ };

textButton(text) {
return this.button(text, { _: "keyboardButtonTypeText" });
return this.button(text, { [types.typename]: "keyboardButtonTypeText" });
}

@@ -78,3 +78,3 @@ /**

button(text, type) {
this._currentRow.push({ _: "keyboardButton", text, type });
this._currentRow.push({ [types.typename]: "keyboardButton", text, type });
return this;

@@ -157,3 +157,3 @@ }

return {
_: "replyMarkupShowKeyboard",
[types.typename]: "replyMarkupShowKeyboard",
is_persistent: this._options.persistent || false,

@@ -216,3 +216,3 @@ resize_keyboard: this._options.resize || false,

return this.button(text, {
_: "inlineKeyboardButtonTypeCallback",
[types.typename]: "inlineKeyboardButtonTypeCallback",
data: typeof data === "string" ? encoder.encode(data) : new Uint8Array(data)

@@ -231,3 +231,3 @@ });

return this.button(text, {
_: "inlineKeyboardButtonTypeUrl",
[types.typename]: "inlineKeyboardButtonTypeUrl",
url: url.toString()

@@ -245,3 +245,3 @@ });

button(text, type) {
this._currentRow.push({ _: "inlineKeyboardButton", text, type });
this._currentRow.push({ [types.typename]: "inlineKeyboardButton", text, type });
return this;

@@ -269,3 +269,3 @@ }

return {
_: "replyMarkupInlineKeyboard",
[types.typename]: "replyMarkupInlineKeyboard",
rows: this._buttons

@@ -272,0 +272,0 @@ };

@@ -1,2 +0,2 @@

import { $AsyncApi } from "./types";
import { $AsyncApi } from "./generated/types";
type integer = bigint;

@@ -138,3 +138,2 @@ type TDLibOptionsWritable = {

export declare class TDLibOptions {
private static readonly _instanceCache;
/**

@@ -147,2 +146,3 @@ *

* @memberof TDLibOptions
* @deprecated Removed instance caching, use `new TDLibOptions()` instead
*/

@@ -156,3 +156,3 @@ static for(api: $AsyncApi): TDLibOptions;

*/
private constructor();
constructor(api: $AsyncApi);
/**

@@ -159,0 +159,0 @@ *

"use strict";
const types = require("./generated/types.js");
/**
const types = require("./generated/types.js"); /**
*

@@ -10,3 +9,2 @@ * @see https://core.telegram.org/tdlib/options

class TDLibOptions {
static _instanceCache = new WeakMap();
/**

@@ -19,11 +17,6 @@ *

* @memberof TDLibOptions
* @deprecated Removed instance caching, use `new TDLibOptions()` instead
*/
static for(api) {
const existing = TDLibOptions._instanceCache.get(api);
if (existing) {
return existing;
}
const options = new TDLibOptions(api);
TDLibOptions._instanceCache.set(api, options);
return options;
return new TDLibOptions(api);
}

@@ -50,3 +43,3 @@ _api;

.getOption({ name: key })
.catch(() => ({ _: types.OptionValue$Type.Empty }));
.catch(() => ({ [types.typename]: types.OptionValue$Type.Empty }));
switch (value._) {

@@ -74,3 +67,3 @@ case types.OptionValue$Type.Integer: {

async set(key, value) {
let option = { _: types.OptionValue$Type.Empty };
let option = { [types.typename]: types.OptionValue$Type.Empty };
switch (typeof value) {

@@ -80,3 +73,3 @@ case "number":

option = {
_: types.OptionValue$Type.Integer,
[types.typename]: types.OptionValue$Type.Integer,
value: BigInt(value).toString()

@@ -87,7 +80,7 @@ };

case "boolean": {
option = { _: types.OptionValue$Type.Boolean, value };
option = { [types.typename]: types.OptionValue$Type.Boolean, value };
break;
}
case "string": {
option = { _: types.OptionValue$Type.String, value };
option = { [types.typename]: types.OptionValue$Type.String, value };
break;

@@ -94,0 +87,0 @@ }

@@ -168,1 +168,2 @@ "use strict";

exports.default = types;
exports.typename = types.typename;
{
"name": "tdlib-native",
"version": "2.5.0",
"version": "2.6.0",
"description": "🚀 Telegram TDLib native nodejs wrapper",
"packageManager": "npm@9.8.0",
"packageManager": "npm@10.2.0",
"scripts": {

@@ -98,27 +98,28 @@ "test": "jest",

"@types/jest": "^29.5.12",
"@types/node": "^18.19.34",
"@typescript-eslint/eslint-plugin": "^5.62.0",
"@typescript-eslint/parser": "^5.62.0",
"@types/node": "^20.14.10",
"@typescript-eslint/eslint-plugin": "^7.16.1",
"@typescript-eslint/parser": "^7.16.1",
"dotenv": "^16.4.5",
"eslint": "^8.57.0",
"eslint-config-google": "^0.14.0",
"eslint-config-prettier": "^8.10.0",
"eslint-config-prettier": "^9.1.0",
"eslint-plugin-import": "^2.29.1",
"eslint-plugin-prettier": "^4.2.1",
"eslint-plugin-promise": "^6.2.0",
"eslint-plugin-security": "^1.7.1",
"eslint-plugin-unicorn": "^46.0.1",
"glob": "^9.3.5",
"eslint-plugin-prettier": "^5.1.3",
"eslint-plugin-promise": "^6.4.0",
"eslint-plugin-security": "^3.0.1",
"eslint-plugin-unicorn": "^54.0.0",
"glob": "^11.0.0",
"jest": "^29.7.0",
"node-gyp": "^9.4.1",
"prettier": "^2.8.8",
"rimraf": "^4.4.1",
"rollup": "^3.29.4",
"node-gyp": "^10.2.0",
"prettier": "^3.3.3",
"rimraf": "^6.0.1",
"rollup": "^4.18.1",
"rollup-plugin-cleanup": "^3.2.1",
"rollup-plugin-prettier": "^3.1.0",
"rollup-plugin-typescript2": "^0.34.1",
"ts-jest": "^29.1.4",
"rollup-plugin-prettier": "^4.1.1",
"rollup-plugin-typescript2": "^0.36.0",
"ts-jest": "^29.2.2",
"ts-node": "^10.9.2",
"typedoc-plugin-markdown": "^3.17.1",
"typescript": "^5.4.5"
"typedoc-plugin-markdown": "^4.2.1",
"typescript": "^5.5.3",
"typedoc": "^0.26.4"
},

@@ -130,8 +131,7 @@ "engines": {

"debug": "^4.3.5",
"node-addon-api": "^6.1.0",
"typedoc": "^0.25.13"
"node-addon-api": "^8.1.0"
},
"optionalDependencies": {
"@tdlib-native/tdjson-darwin-arm64": "1.8.33-commit.cb164927417f22811c74cd8678ed4a5ab7cb80ba",
"@tdlib-native/tdjson-darwin-x64": "1.8.33-commit.cb164927417f22811c74cd8678ed4a5ab7cb80ba",
"@tdlib-native/tdjson-darwin-arm64": "1.8.33-commit.cb164927417f22811c74cd8678ed4a5ab7cb80ba",
"@tdlib-native/tdjson-linux-x64-glibc": "1.8.33-commit.cb164927417f22811c74cd8678ed4a5ab7cb80ba",

@@ -138,0 +138,0 @@ "@tdlib-native/tdjson-win32-x64": "1.8.33-commit.cb164927417f22811c74cd8678ed4a5ab7cb80ba"

@@ -57,5 +57,3 @@ # TDLib Native

// Make TDLib shut up. Immediately
Client.execute(adapter, "setLogVerbosityLevel", {
new_verbosity_level: 0
});
Client.disableLogs(adapter);

@@ -62,0 +60,0 @@ const client = new Client(adapter);

@@ -5,3 +5,3 @@ import { TDLibAddon } from "../addon";

import { Meta } from "../generated/meta";
import type { error } from "../types";
import type { error } from "../generated/types";

@@ -8,0 +8,0 @@ let adapter: TDLibAddon;

@@ -5,2 +5,3 @@ import path from "path";

import { createRequire } from "module";
import { assert } from "../assert";

@@ -42,4 +43,4 @@ export interface Addon {

const isMusl = () =>
!(process.report?.getReport() as any)?.header?.glibcVersionRuntime;
const isGlibc = () =>
!!(process.report?.getReport() as any)?.header?.glibcVersionRuntime;

@@ -55,7 +56,6 @@ /**

if (process.platform === "linux") {
if (isMusl()) {
throw new Error(
"TDLib build for MUSL libc is not ready yet. You can ask for do it quicker: https://github.com/AlexXanderGrib/node-tdlib/issues"
);
}
assert(
isGlibc(),
"TDLib build for MUSL libc is not ready yet. You can ask for do it quicker: https://github.com/AlexXanderGrib/node-tdlib/issues"
);

@@ -62,0 +62,0 @@ packageName += "-glibc";

@@ -11,4 +11,5 @@ import { Client } from "./client";

AuthorizationState$Type,
Update$Type
} from "./types";
Update$Type,
typename
} from "./generated/types";

@@ -172,3 +173,3 @@ type AuthenticateOptions = {

code: {
_: "emailAddressAuthenticationCode",
[typename]: "emailAddressAuthenticationCode",
code: await wait(this._state.emailCode, state.code_info)

@@ -175,0 +176,0 @@ }

@@ -1,2 +0,2 @@

const base64abc = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

@@ -13,20 +13,20 @@ /**

let index;
const l = bytes.length;
for (index = 2; index < l; index += 3) {
result += base64abc[bytes[index - 2] >> 2];
result += base64abc[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += base64abc[((bytes[index - 1] & 0x0f) << 2) | (bytes[+index] >> 6)];
result += base64abc[bytes[+index] & 0x3f];
for (index = 2; index < bytes.length; index += 3) {
result += alphabet[bytes[index - 2] >> 2];
result += alphabet[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += alphabet[((bytes[index - 1] & 0x0f) << 2) | (bytes[index] >> 6)];
result += alphabet[bytes[index] & 0x3f];
}
if (index === l + 1) {
if (index === bytes.length + 1) {
// 1 octet yet to write
result += base64abc[bytes[index - 2] >> 2];
result += base64abc[(bytes[index - 2] & 0x03) << 4];
result += alphabet[bytes[index - 2] >> 2];
result += alphabet[(bytes[index - 2] & 0x03) << 4];
result += "==";
}
if (index === l) {
} else if (index === bytes.length) {
// 2 octets yet to write
result += base64abc[bytes[index - 2] >> 2];
result += base64abc[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += base64abc[(bytes[index - 1] & 0x0f) << 2];
result += alphabet[bytes[index - 2] >> 2];
result += alphabet[((bytes[index - 2] & 0x03) << 4) | (bytes[index - 1] >> 4)];
result += alphabet[(bytes[index - 1] & 0x0f) << 2];
result += "=";

@@ -33,0 +33,0 @@ }

import type { TDLib, TDLibClient } from "./shared/client";
import { error, Update, $AsyncApi, $SyncApi, $MethodsDict } from "./generated/types";
import * as JSON from "./json";
import {
error,
Update,
$AsyncApi,
$SyncApi,
$MethodsDict,
typename
} from "./generated/types";
import { deserialize, serialize } from "./json";
import { PromiseWithResolvers, promiseWithResolvers } from "./shared/async";

@@ -8,7 +15,10 @@ import { EventBus, Observable } from "./event-bus";

import { TDLibOptions } from "./options";
import { assert } from "./assert";
const debugJson = debug("tdlib-native:json");
type OmitType<T extends { _: string }> = Omit<T, "_">;
const tag = "@extra";
type OmitType<T extends { [typename]: string }> = Omit<T, typename>;
const enum ClientState {

@@ -29,3 +39,3 @@ RUNNING = "RUNNING",

export class TDError extends Error implements error {
readonly _ = "error";
readonly [typename] = "error";
readonly code: number;

@@ -61,3 +71,3 @@ readonly method: string;

return {
_: this._,
[typename]: this[typename],
name: this.name,

@@ -98,2 +108,3 @@ message: this.message,

readonly syncApi = new $SyncApi(this);
readonly _tdlibOptions = new TDLibOptions(this.api);

@@ -117,4 +128,4 @@ /**

assignTemporary(parameters, { _: method, "@extra": extra }, (merged) => {
const value = JSON.serialize(merged);
assignTemporary(parameters, { [typename]: method, [tag]: extra }, (merged) => {
const value = serialize(merged);
debugJson("Sent %s", value);

@@ -129,3 +140,3 @@ this._adapter.send(this._client, value);

} catch (error) {
if (typeof error === "object" && error && "_" in error) {
if (typeof error === "object" && error && typename in error) {
const value = error as error;

@@ -140,4 +151,16 @@ throw new TDError(value.message, { code: value.code, method, parameters });

/**
* Disables logging of TDLib instance
*
* @static
* @param {TDLib} lib
* @memberof Client
* @returns {void}
*/
static disableLogs(lib: TDLib): void {
Client.execute(lib, "setLogVerbosityLevel", { new_verbosity_level: 0 });
}
/**
*
*
* @template {keyof $SyncApi} T

@@ -176,5 +199,5 @@ * @param {TDLib|Client} executor

parameters,
{ _: method, "@extra": extra },
{ [typename]: method, [tag]: extra },
(merged) => {
const value = JSON.serialize(merged);
const value = serialize(merged);
debugJson("Sent sync %s", value);

@@ -189,5 +212,3 @@

if (!value) {
throw new TDError("Method returned null", { method, parameters });
}
assert(value, new TDError("Method returned null", { method, parameters }));

@@ -197,7 +218,3 @@ let data: unknown;

try {
data = JSON.deserialize(value);
if (typeof data !== "object" || !data || !("_" in data)) {
throw new TDError("Returned not an object", { method, parameters });
}
data = deserialize(value);
} catch {

@@ -207,3 +224,8 @@ throw new TDError("Method returned invalid json", { method, parameters });

if (data._ === "error") {
assert(
typeof data === "object" && data && typename in data,
new TDError("Returned not an object", { method, parameters })
);
if (data[typename] === "error") {
const error = data as error;

@@ -213,4 +235,4 @@ throw new TDError(error.message, { code: error.code, method, parameters });

if ("@extra" in data && data["@extra"]) {
delete data["@extra"];
if (tag in data && data[tag]) {
delete data[tag];
}

@@ -256,3 +278,3 @@

try {
data = JSON.deserialize(value);
data = deserialize(value);
} catch {

@@ -266,9 +288,9 @@ continue;

const extra = data?.["@extra"];
const extra = data?.[tag];
if (extra) {
const async = this._requests.get(extra);
delete data["@extra"];
delete data[tag];
if (data._ === "error") {
if (data[typename] === "error") {
async?.reject(data);

@@ -284,3 +306,3 @@ } else {

if (data._.startsWith("update")) {
if (data[typename].startsWith("update")) {
this._updates.emit(data);

@@ -298,3 +320,3 @@ }

get tdlibOptions(): TDLibOptions {
return TDLibOptions.for(this.api);
return this._tdlibOptions;
}

@@ -320,9 +342,10 @@

start(): this {
if (this._state === ClientState.PAUSED) {
this._state = ClientState.RUNNING;
this._thread();
return this;
}
assert(
this._state === ClientState.PAUSED,
"Cannot start: This client is running or destroyed"
);
throw new Error("Cannot start: This client is running or destroyed");
this._state = ClientState.RUNNING;
this._thread();
return this;
}

@@ -337,8 +360,9 @@

pause(): this {
if (this._state === ClientState.RUNNING) {
this._state = ClientState.PAUSED;
return this;
}
assert(
this._state === ClientState.RUNNING,
"Cannot pause: This client is paused or destroyed"
);
throw new Error("Cannot pause: This client is paused or destroyed");
this._state = ClientState.PAUSED;
return this;
}

@@ -345,0 +369,0 @@

@@ -0,1 +1,3 @@

import { assert } from "./assert";
export type Subscription<T> = (value: T) => void;

@@ -50,5 +52,3 @@ export type Unsubscribe = () => void;

subscribe(handler: Subscription<T>): Unsubscribe {
if (this._completed) {
throw new Error("Completed");
}
assert(!this._completed, "Completed");

@@ -55,0 +55,0 @@ const cached = this._subscriptions.get(handler);

import { encode } from "./base64";
import { typename } from "./generated/types";
const mainKey = /"_":/g;
const tdKey = /"@type":/g;
const tdTypename = "@type";
const mainKey = new RegExp(`"${typename}":`, "g");
const tdKey = new RegExp(`"${tdTypename}":`, "g");
/**

@@ -45,3 +48,3 @@ *

const json = JSON.stringify(data, replacer);
return json.replace(mainKey, '"@type":');
return json.replace(mainKey, `"${tdTypename}":`);
}

@@ -58,3 +61,3 @@

export function deserialize<T = unknown>(json: string): T {
return JSON.parse(json.replace(tdKey, '"_":'));
return JSON.parse(json.replace(tdKey, `"${typename}":`));
}

@@ -9,4 +9,5 @@ import {

replyMarkupInlineKeyboard$Input,
InlineKeyboardButtonType$Input
} from "./types";
InlineKeyboardButtonType$Input,
typename
} from "./generated/types";

@@ -25,3 +26,3 @@ /**

return {
_: "replyMarkupForceReply",
[typename]: "replyMarkupForceReply",
input_field_placeholder: placeholder,

@@ -43,3 +44,3 @@ is_personal: personal

return {
_: "replyMarkupRemoveKeyboard",
[typename]: "replyMarkupRemoveKeyboard",
is_personal: personal

@@ -94,3 +95,3 @@ };

textButton(text: string): this {
return this.button(text, { _: "keyboardButtonTypeText" });
return this.button(text, { [typename]: "keyboardButtonTypeText" });
}

@@ -107,3 +108,3 @@

button(text: string, type: KeyboardButtonType$Input): this {
this._currentRow.push({ _: "keyboardButton", text, type });
this._currentRow.push({ [typename]: "keyboardButton", text, type });
return this;

@@ -194,3 +195,3 @@ }

return {
_: "replyMarkupShowKeyboard",
[typename]: "replyMarkupShowKeyboard",
is_persistent: this._options.persistent || false,

@@ -258,3 +259,3 @@ resize_keyboard: this._options.resize || false,

return this.button(text, {
_: "inlineKeyboardButtonTypeCallback",
[typename]: "inlineKeyboardButtonTypeCallback",
data: typeof data === "string" ? encoder.encode(data) : new Uint8Array(data)

@@ -274,3 +275,3 @@ });

return this.button(text, {
_: "inlineKeyboardButtonTypeUrl",
[typename]: "inlineKeyboardButtonTypeUrl",
url: url.toString()

@@ -289,3 +290,3 @@ });

button(text: string, type: InlineKeyboardButtonType$Input): this {
this._currentRow.push({ _: "inlineKeyboardButton", text, type });
this._currentRow.push({ [typename]: "inlineKeyboardButton", text, type });
return this;

@@ -316,3 +317,3 @@ }

return {
_: "replyMarkupInlineKeyboard",
[typename]: "replyMarkupInlineKeyboard",
rows: this._buttons

@@ -319,0 +320,0 @@ };

@@ -1,2 +0,7 @@

import { $AsyncApi, OptionValue, OptionValue$Type } from "./types";
import {
$AsyncApi,
OptionValue,
OptionValue$Type,
typename
} from "./generated/types";

@@ -144,4 +149,2 @@ type integer = bigint;

export class TDLibOptions {
private static readonly _instanceCache = new WeakMap<$AsyncApi, TDLibOptions>();
/**

@@ -154,13 +157,6 @@ *

* @memberof TDLibOptions
* @deprecated Removed instance caching, use `new TDLibOptions()` instead
*/
static for(api: $AsyncApi): TDLibOptions {
const existing = TDLibOptions._instanceCache.get(api);
if (existing) {
return existing;
}
const options = new TDLibOptions(api);
TDLibOptions._instanceCache.set(api, options);
return options;
return new TDLibOptions(api);
}

@@ -175,3 +171,3 @@

*/
private constructor(api: $AsyncApi) {
constructor(api: $AsyncApi) {
this._api = api;

@@ -191,3 +187,3 @@ }

.getOption({ name: key })
.catch((): OptionValue => ({ _: OptionValue$Type.Empty }));
.catch((): OptionValue => ({ [typename]: OptionValue$Type.Empty }));

@@ -222,3 +218,3 @@ switch (value._) {

): Promise<void> {
let option: OptionValue = { _: OptionValue$Type.Empty };
let option: OptionValue = { [typename]: OptionValue$Type.Empty };

@@ -229,3 +225,3 @@ switch (typeof value) {

option = {
_: OptionValue$Type.Integer,
[typename]: OptionValue$Type.Integer,
value: BigInt(value).toString()

@@ -237,3 +233,3 @@ };

case "boolean": {
option = { _: OptionValue$Type.Boolean, value };
option = { [typename]: OptionValue$Type.Boolean, value };
break;

@@ -243,3 +239,3 @@ }

case "string": {
option = { _: OptionValue$Type.String, value };
option = { [typename]: OptionValue$Type.String, value };
break;

@@ -246,0 +242,0 @@ }

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc