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

@telegraf/session

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@telegraf/session - npm Package Compare versions

Comparing version 2.0.0-beta.2 to 2.0.0-beta.3

4

mongodb.d.ts

@@ -31,5 +31,5 @@ import { MongoClient, MongoClientOptions } from "mongodb";

}
export type Opts = NewClientOpts | ExistingClientOpts;
/** @unstable */
export declare const Mongo: <Session>(opts: Opts) => SessionStore<Session>;
export declare function Mongo<Session>(opts: NewClientOpts): SessionStore<Session>;
export declare function Mongo<Session>(opts: ExistingClientOpts): SessionStore<Session>;
export {};

@@ -15,4 +15,3 @@ "use strict";

const defaults_1 = require("./defaults");
/** @unstable */
const Mongo = (opts) => {
function Mongo(opts) {
var _a;

@@ -51,3 +50,3 @@ let client;

};
};
}
exports.Mongo = Mongo;
import { Pool, PoolOptions } from "mysql2";
import { SessionStore } from "./types";
interface NewPoolOpts {

@@ -29,5 +30,5 @@ host?: string | undefined;

}
export type Opts = NewPoolOpts | ExistingPoolOpts;
/** @unstable */
export declare const MySQL: <Session>(opts: Opts) => import("./types").SessionStore<Session>;
export declare function MySQL<Session>(opts: NewPoolOpts): SessionStore<Session>;
export declare function MySQL<Session>(opts: ExistingPoolOpts): SessionStore<Session>;
export {};

@@ -7,14 +7,15 @@ "use strict";

const kysely_2 = require("./kysely");
/** @unstable */
const MySQL = (opts) => (0, kysely_2.KyselyStore)({
config: "pool" in opts
? { dialect: new kysely_1.MysqlDialect({ pool: opts.pool }) }
: {
dialect: new kysely_1.MysqlDialect({
pool: (0, mysql2_1.createPool)(Object.assign({ host: opts.host, port: opts.port, database: opts.database, user: opts.user, password: opts.password }, opts.config)),
}),
},
table: opts.table,
onInitError: opts.onInitError,
});
function MySQL(opts) {
return (0, kysely_2.KyselyStore)({
config: "pool" in opts
? { dialect: new kysely_1.MysqlDialect({ pool: opts.pool }) }
: {
dialect: new kysely_1.MysqlDialect({
pool: (0, mysql2_1.createPool)(Object.assign({ host: opts.host, port: opts.port, database: opts.database, user: opts.user, password: opts.password }, opts.config)),
}),
},
table: opts.table,
onInitError: opts.onInitError,
});
}
exports.MySQL = MySQL;
{
"name": "@telegraf/session",
"version": "2.0.0-beta.2",
"version": "2.0.0-beta.3",
"description": "Session store adapters for Telegraf",

@@ -5,0 +5,0 @@ "main": "./memory.js",

import { Pool, PoolConfig } from "pg";
import { SessionStore } from "./types";
interface NewPoolOpts {

@@ -29,5 +30,5 @@ host?: string | undefined;

}
export type Opts = NewPoolOpts | ExistingPoolOpts;
/** @unstable */
export declare const Postgres: <Session>(opts: Opts) => import("./types").SessionStore<Session>;
export declare function Postgres<Session>(opts: NewPoolOpts): SessionStore<Session>;
export declare function Postgres<Session>(opts: ExistingPoolOpts): SessionStore<Session>;
export {};

@@ -7,14 +7,15 @@ "use strict";

const kysely_2 = require("./kysely");
/** @unstable */
const Postgres = (opts) => (0, kysely_2.KyselyStore)({
config: "pool" in opts
? { dialect: new kysely_1.PostgresDialect({ pool: opts.pool }) }
: {
dialect: new kysely_1.PostgresDialect({
pool: new pg_1.Pool(Object.assign({ host: opts.host, port: opts.port, database: opts.database, user: opts.user, password: opts.password }, opts.config)),
}),
},
table: opts.table,
onInitError: opts.onInitError,
});
function Postgres(opts) {
return (0, kysely_2.KyselyStore)({
config: "pool" in opts
? { dialect: new kysely_1.PostgresDialect({ pool: opts.pool }) }
: {
dialect: new kysely_1.PostgresDialect({
pool: new pg_1.Pool(Object.assign({ host: opts.host, port: opts.port, database: opts.database, user: opts.user, password: opts.password }, opts.config)),
}),
},
table: opts.table,
onInitError: opts.onInitError,
});
}
exports.Postgres = Postgres;

@@ -7,3 +7,3 @@ # `@telegraf/session`

>
> Read one of the following sections before using this module. You're not meant to import the default route!
> Read one of the following sections before using this module. You're not meant to import the default path!

@@ -31,3 +31,5 @@ An in-memory session module is bundled with Telegraf. The following modules are available here:

const store = Redis({ url: "redis://127.0.0.1:6379" });
const store = Redis({
url: "redis://127.0.0.1:6379",
});

@@ -40,2 +42,4 @@ const bot = new Telegraf(token, opts);

To reuse an existing Redis client, use `Redis({ client })` instead.
## MongoDB

@@ -54,3 +58,6 @@

const store = Mongo({ url: "mongodb://127.0.0.1:27017", database: "telegraf-bot" });
const store = Mongo({
url: "mongodb://127.0.0.1:27017",
database: "telegraf-bot",
});

@@ -63,2 +70,4 @@ const bot = new Telegraf(token, opts);

To reuse an existing MongoDB client, use `Mongo({ client })` instead.
## SQLite

@@ -78,3 +87,5 @@

const store = SQLite({ filename: "./telegraf-sessions.sqlite" });
const store = SQLite({
filename: "./telegraf-sessions.sqlite",
});

@@ -87,2 +98,4 @@ const bot = new Telegraf(token, opts);

To reuse an existing Better-SQLite3 database instance, use `SQLite({ database })` instead.
## PostgreSQL

@@ -115,2 +128,4 @@

To reuse an existing pg pool, use `Postgres({ pool })` instead.
## MySQL / MariaDB

@@ -142,6 +157,8 @@

To reuse an existing MySQL2 pool, use `MySQL({ pool })` instead.
## Background
Since [telegraf#1372](https://github.com/telegraf/telegraf/issues/1372), it has been known that all asynchronous session middleware have been prone to race-conditions. This was addressed in [telegraf#1713](https://github.com/telegraf/telegraf/pull/1713), but third-party session middleware continue to be affected. Since Telegraf 1.12.0, it's recommended that third-party middleware only provide the store parameter for session, instead of implementing session themselves. This way, they can take advantage of the safety provided by Telegraf's builtin session. Of course, if your plugin has an exceptional case, it may need to implement a middleware.
Since [telegraf#1372](https://github.com/telegraf/telegraf/issues/1372), it has been known that all asynchronous session middleware have been prone to race-conditions. This was addressed in [telegraf#1713](https://github.com/telegraf/telegraf/pull/1713), but third-party session middleware continue to be affected. Since Telegraf 1.12.0, it's recommended that third-party plugins only provide the store parameter for session, instead of implementing session themselves. This way, they can take advantage of the safety provided by Telegraf's builtin session. Of course, if your plugin has an exceptional usecase, it may need to implement its own middleware.
To begin to solve this problem, we officially maintain the 5 most common storage backends. This package is considered beta, and while it appears stable, it may have changes and bugfixes before a semver stable release.
To begin to solve this problem, we officially maintain the 5 most common storage backends. This package is considered beta, and may have minor breaking changes and bugfixes before a semver stable release. Feedback is welcome via issues and in the group: [TelegrafJSChat](https://t.me/TelegrafJSChat)

@@ -24,5 +24,5 @@ import { createClient } from "redis";

}
export type Opts = NewClientOpts | ExistingClientOpts;
/** @unstable */
export declare const Redis: <Session>(opts: Opts) => SessionStore<Session>;
export declare function Redis<Session>(opts: NewClientOpts): SessionStore<Session>;
export declare function Redis<Session>(opts: ExistingClientOpts): SessionStore<Session>;
export {};

@@ -14,4 +14,3 @@ "use strict";

const redis_1 = require("redis");
/** @unstable */
const Redis = (opts) => {
function Redis(opts) {
let client;

@@ -45,3 +44,3 @@ if ("client" in opts)

};
};
}
exports.Redis = Redis;
import { Database as Db, Options } from "better-sqlite3";
import { SessionStore } from "./types";
interface NewDatabaseOpts {

@@ -22,5 +23,5 @@ /** Filename to use for SQLite sessions. */

}
export type Opts = NewDatabaseOpts | ExistingDatabaseOpts;
/** @unstable */
export declare const SQLite: <Session>(opts: Opts) => import("./types").SessionStore<Session>;
export declare function SQLite<Session>(opts: NewDatabaseOpts): SessionStore<Session>;
export declare function SQLite<Session>(opts: ExistingDatabaseOpts): SessionStore<Session>;
export {};

@@ -7,9 +7,10 @@ "use strict";

const Database = require("better-sqlite3");
/** @unstable */
const SQLite = (opts) => (0, kysely_2.KyselyStore)({
config: "database" in opts
? { dialect: new kysely_1.SqliteDialect({ database: opts.database }) }
: { dialect: new kysely_1.SqliteDialect({ database: new Database(opts.filename, opts.config) }) },
onInitError: opts.onInitError,
});
function SQLite(opts) {
return (0, kysely_2.KyselyStore)({
config: "database" in opts
? { dialect: new kysely_1.SqliteDialect({ database: opts.database }) }
: { dialect: new kysely_1.SqliteDialect({ database: new Database(opts.filename, opts.config) }) },
onInitError: opts.onInitError,
});
}
exports.SQLite = SQLite;
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