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

telegraf

Package Overview
Dependencies
Maintainers
3
Versions
241
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

telegraf - npm Package Compare versions

Comparing version 4.12.2 to 4.12.3-canary.1

lib/core/network/payload.js

34

lib/core/helpers/formatting.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.linkOrMention = exports._fmt = exports.join = exports.FmtString = void 0;
exports.linkOrMention = exports._fmt = exports.replace = exports.join = exports.FmtString = void 0;
const util_1 = require("../../util");

@@ -66,2 +66,34 @@ class FmtString {

exports.join = join;
const replace = (source, search, value) => {
var _a;
const v = FmtString.normalise(value);
let entities = undefined;
if (typeof search === 'string') {
const offset = source.indexOf(search);
const length = search.length;
source = source.slice(0, offset) + v.text + source.slice(offset + length);
entities = (_a = v.entities) === null || _a === void 0 ? void 0 : _a.map((e) => ({ ...e, offset: e.offset + offset }));
}
else {
let index = 0; // context position in source string
let acc = ''; // incremental return value
let correction = 0;
let regexArray;
while ((regexArray = search.exec(source))) {
const offset = regexArray.index;
const length = regexArray[0].length;
acc += source.slice(index, offset) + v.text;
if (v.entities && v.entities.length)
(entities !== null && entities !== void 0 ? entities : (entities = [])).push(...v.entities.map((e) => ({
...e,
offset: e.offset + offset + correction,
})));
index = offset + length;
correction += v.text.length - length;
}
source = acc + source.slice(index);
}
return new FmtString(source, entities);
};
exports.replace = replace;
function _fmt(kind, opts) {

@@ -68,0 +100,0 @@ return function fmt(parts, ...items) {

29

lib/format.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.join = exports.mention = exports.link = exports.pre = exports.code = exports.underline = exports.strikethrough = exports.spoiler = exports.italic = exports.bold = exports.fmt = exports.FmtString = void 0;
exports.replace = exports.join = exports.FmtString = exports.mention = exports.link = exports.pre = exports.code = exports.underline = exports.strikethrough = exports.spoiler = exports.italic = exports.bold = exports.fmt = void 0;
const formatting_1 = require("./core/helpers/formatting");
Object.defineProperty(exports, "FmtString", { enumerable: true, get: function () { return formatting_1.FmtString; } });
Object.defineProperty(exports, "join", { enumerable: true, get: function () { return formatting_1.join; } });
const fmt = (0, formatting_1._fmt)();
exports.fmt = fmt;
const bold = (0, formatting_1._fmt)('bold');
exports.bold = bold;
const italic = (0, formatting_1._fmt)('italic');
exports.italic = italic;
const spoiler = (0, formatting_1._fmt)('spoiler');
exports.spoiler = spoiler;
const strikethrough = (0, formatting_1._fmt)('strikethrough');
exports.strikethrough = strikethrough;
const underline = (0, formatting_1._fmt)('underline');
exports.underline = underline;
const code = (0, formatting_1._fmt)('code');
exports.code = code;
exports.fmt = (0, formatting_1._fmt)();
exports.bold = (0, formatting_1._fmt)('bold');
exports.italic = (0, formatting_1._fmt)('italic');
exports.spoiler = (0, formatting_1._fmt)('spoiler');
exports.strikethrough = (0, formatting_1._fmt)('strikethrough');
exports.underline = (0, formatting_1._fmt)('underline');
exports.code = (0, formatting_1._fmt)('code');
const pre = (language) => (0, formatting_1._fmt)('pre', { language });

@@ -26,4 +18,7 @@ exports.pre = pre;

const mention = (name, user) => typeof user === 'number'
? link(name, 'tg://user?id=' + user)
? (0, exports.link)(name, 'tg://user?id=' + user)
: (0, formatting_1.linkOrMention)(name, { type: 'text_mention', user });
exports.mention = mention;
var formatting_2 = require("./core/helpers/formatting");
Object.defineProperty(exports, "join", { enumerable: true, get: function () { return formatting_2.join; } });
Object.defineProperty(exports, "replace", { enumerable: true, get: function () { return formatting_2.replace; } });

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

*
* > ⚠️ Session data is kept only in memory by default, which means that all data will be lost when the process is terminated.
* > ⚠️ Session data is kept only in memory by default, which means that all data will be lost when the process is terminated.
* >

@@ -25,5 +25,6 @@ * > If you want to store data across restarts, or share it among workers, you should use

function session(options) {
var _a, _b;
var _a, _b, _c;
const getSessionKey = (_a = options === null || options === void 0 ? void 0 : options.getSessionKey) !== null && _a !== void 0 ? _a : defaultGetSessionKey;
const store = (_b = options === null || options === void 0 ? void 0 : options.store) !== null && _b !== void 0 ? _b : new MemorySessionStore();
const prop = (_b = options === null || options === void 0 ? void 0 : options.property) !== null && _b !== void 0 ? _b : 'session';
const store = (_c = options === null || options === void 0 ? void 0 : options.store) !== null && _c !== void 0 ? _c : new MemorySessionStore();
// caches value from store in-memory while simultaneous updates share it

@@ -44,3 +45,7 @@ // when counter reaches 0, the cached ref will be freed from memory

if (!key) {
ctx.session = undefined;
Object.defineProperty(ctx, prop, {
get() {
undefined;
},
});
return await next();

@@ -87,3 +92,3 @@ }

let touched = false;
Object.defineProperty(ctx, 'session', {
Object.defineProperty(ctx, prop, {
get() {

@@ -110,3 +115,3 @@ touched = true;

if (touched)
if (ctx.session == null) {
if (ctx[prop] == null) {
debug(`(${updId}) ctx.session missing, removing from store`);

@@ -117,3 +122,3 @@ await store.delete(key);

debug(`(${updId}) ctx.session found, updating store`);
await store.set(key, ctx.session);
await store.set(key, ctx[prop]);
}

@@ -120,0 +125,0 @@ }

{
"name": "telegraf",
"version": "4.12.2",
"version": "4.12.3-canary.1",
"description": "Modern Telegram Bot Framework",

@@ -5,0 +5,0 @@ "license": "MIT",

@@ -84,2 +84,44 @@ import { MessageEntity, User } from 'typegram'

export const replace = (
source: string,
search: string | RegExp,
value: string | FmtString
): FmtString => {
const v = FmtString.normalise(value)
let entities: MessageEntity[] | undefined = undefined
if (typeof search === 'string') {
const offset = source.indexOf(search)
const length = search.length
source = source.slice(0, offset) + v.text + source.slice(offset + length)
entities = v.entities?.map((e) => ({ ...e, offset: e.offset + offset }))
} else {
let index = 0 // context position in source string
let acc = '' // incremental return value
let correction = 0
let regexArray
while ((regexArray = search.exec(source))) {
const offset = regexArray.index
const length = regexArray[0].length
acc += source.slice(index, offset) + v.text
if (v.entities && v.entities.length)
(entities ??= []).push(
...v.entities.map((e) => ({
...e,
offset: e.offset + offset + correction,
}))
)
index = offset + length
correction += v.text.length - length
}
source = acc + source.slice(index)
}
return new FmtString(source, entities)
}
/** Internal constructor for all fmt helpers */

@@ -86,0 +128,0 @@ export function _fmt(

import { User } from 'typegram'
import { FmtString, _fmt, linkOrMention, join } from './core/helpers/formatting'
import { FmtString, _fmt, linkOrMention } from './core/helpers/formatting'
export { FmtString }
export const fmt = _fmt()
export const bold = _fmt('bold')
export const italic = _fmt('italic')
export const spoiler = _fmt('spoiler')
export const strikethrough = _fmt('strikethrough')
export const underline = _fmt('underline')
export const code = _fmt('code')
export const pre = (language: string) => _fmt('pre', { language })
const fmt = _fmt()
const bold = _fmt('bold')
const italic = _fmt('italic')
const spoiler = _fmt('spoiler')
const strikethrough = _fmt('strikethrough')
const underline = _fmt('underline')
const code = _fmt('code')
const pre = (language: string) => _fmt('pre', { language })
const link = (content: string | FmtString, url: string) =>
export const link = (content: string | FmtString, url: string) =>
linkOrMention(content, { type: 'text_link', url })
const mention = (name: string | FmtString, user: number | User) =>
export const mention = (name: string | FmtString, user: number | User) =>
typeof user === 'number'

@@ -23,14 +21,3 @@ ? link(name, 'tg://user?id=' + user)

export {
fmt,
bold,
italic,
spoiler,
strikethrough,
underline,
code,
pre,
link,
mention,
join,
}
export { FmtString }
export { join, replace } from './core/helpers/formatting'

@@ -24,3 +24,3 @@ import BaseScene from './base'

export interface SceneSession<S extends SceneSessionData = SceneSessionData> {
__scenes: S
__scenes?: S
}

@@ -27,0 +27,0 @@

import { Context } from './context'
import { Any, MaybePromise } from './util'
import { MaybePromise } from './util'
import { MiddlewareFn } from './middleware'

@@ -7,12 +7,26 @@ import d from 'debug'

export interface SessionStore<T> {
get: (name: string) => MaybePromise<T | undefined>
set: (name: string, value: T) => MaybePromise<Any>
delete: (name: string) => MaybePromise<Any>
export interface SyncSessionStore<T> {
get: (name: string) => T | undefined
set: (name: string, value: T) => void
delete: (name: string) => void
}
interface SessionOptions<S extends object, C extends Context = Context> {
getSessionKey?: (ctx: C) => Promise<string | undefined>
export interface AsyncSessionStore<T> {
get: (name: string) => Promise<T | undefined>
set: (name: string, value: T) => Promise<unknown>
delete: (name: string) => Promise<unknown>
}
export type SessionStore<T> = SyncSessionStore<T> | AsyncSessionStore<T>
interface SessionOptions<
S extends object,
C extends Context = Context,
Property extends string = 'session'
> {
getSessionKey?: (ctx: C) => MaybePromise<string | undefined>
store?: SessionStore<S>
defaultSession?: (ctx: C) => S
/** Defaults to `session`. If provided, property name will be used instead of `ctx.session`. */
property?: Property
}

@@ -30,3 +44,3 @@

*
* > ⚠️ Session data is kept only in memory by default, which means that all data will be lost when the process is terminated.
* > ⚠️ Session data is kept only in memory by default, which means that all data will be lost when the process is terminated.
* >

@@ -39,6 +53,9 @@ * > If you want to store data across restarts, or share it among workers, you should use

*/
export function session<S extends object, C extends Context = Context>(
options?: SessionOptions<S, C>
): MiddlewareFn<C & { session?: S }> {
export function session<
S extends object,
C extends Context = Context,
P extends string = 'session'
>(options?: SessionOptions<S, C, P>): MiddlewareFn<C & { [session in P]?: S }> {
const getSessionKey = options?.getSessionKey ?? defaultGetSessionKey
const prop = options?.property ?? ('session' as P)
const store = options?.store ?? new MemorySessionStore()

@@ -61,3 +78,7 @@ // caches value from store in-memory while simultaneous updates share it

if (!key) {
ctx.session = undefined
Object.defineProperty(ctx, prop, {
get() {
undefined
},
})
return await next()

@@ -106,3 +127,3 @@ }

Object.defineProperty(ctx, 'session', {
Object.defineProperty(ctx, prop, {
get() {

@@ -130,3 +151,3 @@ touched = true

if (touched)
if (ctx.session == null) {
if (ctx[prop] == null) {
debug(`(${updId}) ctx.session missing, removing from store`)

@@ -136,3 +157,3 @@ await store.delete(key)

debug(`(${updId}) ctx.session found, updating store`)
await store.set(key, ctx.session)
await store.set(key, ctx[prop] as S)
}

@@ -153,3 +174,3 @@ }

/** @deprecated Use `Map` */
export class MemorySessionStore<T> implements SessionStore<T> {
export class MemorySessionStore<T> implements SyncSessionStore<T> {
private readonly store = new Map<string, { session: T; expires: number }>()

@@ -156,0 +177,0 @@

@@ -24,2 +24,3 @@ import { MessageEntity, User } from 'typegram';

export declare const join: (fragments: Iterable<FmtString | string | Any>, separator?: string | FmtString) => FmtString;
export declare const replace: (source: string, search: string | RegExp, value: string | FmtString) => FmtString;
/** Internal constructor for all fmt helpers */

@@ -26,0 +27,0 @@ export declare function _fmt(kind?: Types.Containers): (parts: TemplateParts, ...items: (Any | FmtString)[]) => FmtString;

import { User } from 'typegram';
import { FmtString, join } from './core/helpers/formatting';
import { FmtString } from './core/helpers/formatting';
export declare const fmt: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
export declare const bold: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
export declare const italic: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
export declare const spoiler: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
export declare const strikethrough: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
export declare const underline: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
export declare const code: (parts: string | FmtString | readonly (string | FmtString)[], ...items: ({} | null | undefined)[]) => FmtString;
export declare const pre: (language: string) => (parts: string | FmtString | readonly (string | FmtString)[], ...items: ({} | null | undefined)[]) => FmtString;
export declare const link: (content: string | FmtString, url: string) => FmtString;
export declare const mention: (name: string | FmtString, user: number | User) => FmtString;
export { FmtString };
declare const fmt: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
declare const bold: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
declare const italic: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
declare const spoiler: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
declare const strikethrough: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
declare const underline: (parts: string | FmtString | readonly (string | FmtString)[], ...items: (FmtString | ({} | null | undefined))[]) => FmtString;
declare const code: (parts: string | FmtString | readonly (string | FmtString)[], ...items: ({} | null | undefined)[]) => FmtString;
declare const pre: (language: string) => (parts: string | FmtString | readonly (string | FmtString)[], ...items: ({} | null | undefined)[]) => FmtString;
declare const link: (content: string | FmtString, url: string) => FmtString;
declare const mention: (name: string | FmtString, user: number | User) => FmtString;
export { fmt, bold, italic, spoiler, strikethrough, underline, code, pre, link, mention, join, };
export { join, replace } from './core/helpers/formatting';
//# sourceMappingURL=format.d.ts.map

@@ -14,3 +14,3 @@ import BaseScene from './base';

export interface SceneSession<S extends SceneSessionData = SceneSessionData> {
__scenes: S;
__scenes?: S;
}

@@ -17,0 +17,0 @@ export interface SceneContextSceneOptions<D extends SceneSessionData> {

import { Context } from './context';
import { Any, MaybePromise } from './util';
import { MaybePromise } from './util';
import { MiddlewareFn } from './middleware';
export interface SessionStore<T> {
get: (name: string) => MaybePromise<T | undefined>;
set: (name: string, value: T) => MaybePromise<Any>;
delete: (name: string) => MaybePromise<Any>;
export interface SyncSessionStore<T> {
get: (name: string) => T | undefined;
set: (name: string, value: T) => void;
delete: (name: string) => void;
}
interface SessionOptions<S extends object, C extends Context = Context> {
getSessionKey?: (ctx: C) => Promise<string | undefined>;
export interface AsyncSessionStore<T> {
get: (name: string) => Promise<T | undefined>;
set: (name: string, value: T) => Promise<unknown>;
delete: (name: string) => Promise<unknown>;
}
export type SessionStore<T> = SyncSessionStore<T> | AsyncSessionStore<T>;
interface SessionOptions<S extends object, C extends Context = Context, Property extends string = 'session'> {
getSessionKey?: (ctx: C) => MaybePromise<string | undefined>;
store?: SessionStore<S>;
defaultSession?: (ctx: C) => S;
/** Defaults to `session`. If provided, property name will be used instead of `ctx.session`. */
property?: Property;
}

@@ -23,3 +31,3 @@ export interface SessionContext<S extends object> extends Context {

*
* > ⚠️ Session data is kept only in memory by default, which means that all data will be lost when the process is terminated.
* > ⚠️ Session data is kept only in memory by default, which means that all data will be lost when the process is terminated.
* >

@@ -32,7 +40,7 @@ * > If you want to store data across restarts, or share it among workers, you should use

*/
export declare function session<S extends object, C extends Context = Context>(options?: SessionOptions<S, C>): MiddlewareFn<C & {
session?: S;
export declare function session<S extends object, C extends Context = Context, P extends string = 'session'>(options?: SessionOptions<S, C, P>): MiddlewareFn<C & {
[session in P]?: S;
}>;
/** @deprecated Use `Map` */
export declare class MemorySessionStore<T> implements SessionStore<T> {
export declare class MemorySessionStore<T> implements SyncSessionStore<T> {
private readonly ttl;

@@ -39,0 +47,0 @@ private readonly store;

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

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