Socket
Socket
Sign inDemoInstall

nestgram

Package Overview
Dependencies
Maintainers
1
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nestgram - npm Package Compare versions

Comparing version 1.8.6 to 1.8.7

1

dist/classes/index.d.ts

@@ -5,2 +5,3 @@ export * from './Context/Answer';

export * from './Helpers/ControllerHelper';
export * from './Helpers/ListenMiddleware';
export * from './Keyboard/Keyboard';

@@ -7,0 +8,0 @@ export * from './Message';

@@ -21,2 +21,3 @@ "use strict";

__exportStar(require("./Helpers/ControllerHelper"), exports);
__exportStar(require("./Helpers/ListenMiddleware"), exports);
__exportStar(require("./Keyboard/Keyboard"), exports);

@@ -23,0 +24,0 @@ __exportStar(require("./Message"), exports);

30

dist/classes/Launch/Handler.js

@@ -126,7 +126,7 @@ "use strict";

}
getHandlers(update) {
async getHandlers(update) {
const privateId = Filter_1.Filter.getPrivateId(update);
if (!privateId)
return this.handlers;
const current = ScopeStore_1.scopeStore.getCurrent(privateId);
const current = await ScopeStore_1.scopeStore.getCurrent(privateId);
if (!current)

@@ -136,7 +136,6 @@ return this.handlers;

}
handleMiddleware(index, update, answer, middlewareIndex = 0) {
const handler = this.getHandlers(update)[index];
async handleMiddleware(index, update, answer, params, middlewareIndex = 0) {
const handler = (await this.getHandlers(update))[index];
if (!handler)
return;
const params = {};
const baseNextFunction = async () => {

@@ -174,4 +173,5 @@ var _a;

handler.controller[getAnswerKey] = answer;
if (getStateKey)
handler.controller[getStateKey] = StateStore_1.stateStore.getStore(Filter_1.Filter.getPrivateId(update));
if (getStateKey) {
handler.controller[getStateKey] = await StateStore_1.stateStore.getStore(Filter_1.Filter.getPrivateId(update), params);
}
try {

@@ -195,6 +195,4 @@ resultMessageToSend = await handlerMethod(...args);

const failNextFunction = (middlewareIndex, handlerIndex) => {
if (handler.middlewares[middlewareIndex]) {
return this.handleMiddleware(handlerIndex, update, answer, middlewareIndex);
}
return this.handleMiddleware(handlerIndex + 1, update, answer, 0);
this.handleMiddleware(handlerIndex + 1, update, answer, params, 0);
return;
};

@@ -205,3 +203,3 @@ handler.middlewares[middlewareIndex](update, answer, params, this.getNextFunction(update, answer, params, handler.middlewares, middlewareIndex, index, baseNextFunction, failNextFunction) || baseNextFunction, failNextFunction.bind(null, middlewareIndex + 1, index));

return;
this.handleMiddleware(index + 1, update, answer);
this.handleMiddleware(index + 1, update, answer, params);
}

@@ -215,7 +213,9 @@ async handleUpdate(update) {

}
// setup data for middlewares
const params = {};
const answer = new Answer_1.Answer(this.token, update);
// handle update
const answer = new Answer_1.Answer(this.token, update);
const handler = this.getHandlers(update)[0];
const handler = (await this.getHandlers(update))[0];
if (handler)
this.handleMiddleware(0, update, answer);
this.handleMiddleware(0, update, answer, params);
}

@@ -222,0 +222,0 @@ }

@@ -12,7 +12,7 @@ "use strict";

throw (0, logger_1.error)(`Can't find scope '${scopeId}'`);
ScopeStore_1.scopeStore.setCurrentScope(userId, scopeId);
await ScopeStore_1.scopeStore.setCurrentScope(userId, scopeId);
return true;
}
async leave(userId) {
ScopeStore_1.scopeStore.setCurrentScope(userId, '');
await ScopeStore_1.scopeStore.setCurrentScope(userId, '');
return true;

@@ -19,0 +19,0 @@ }

@@ -6,6 +6,6 @@ import { IScopeInfo } from '../../types/scope.types';

getScope(scopeId: string): IScopeInfo | undefined;
setCurrentScope(userId: number, scopeId: string): true;
getCurrent(userId: number): string | undefined;
setCurrentScope(userId: number, scopeId: string): Promise<true>;
getCurrent(userId: number): Promise<string | undefined>;
}
export declare const scopeStore: ScopeStore;
export {};

@@ -23,9 +23,9 @@ "use strict";

}
setCurrentScope(userId, scopeId) {
const userState = StateStore_1.stateStore.getStore(userId);
async setCurrentScope(userId, scopeId) {
const userState = await StateStore_1.stateStore.getStore(userId);
userState.__currentScope = scopeId;
return true;
}
getCurrent(userId) {
return StateStore_1.stateStore.getStore(userId).__currentScope;
async getCurrent(userId) {
return (await StateStore_1.stateStore.getStore(userId)).__currentScope;
}

@@ -32,0 +32,0 @@ }

@@ -1,10 +0,21 @@

import { IStateInfo } from '../../types/state.types';
import { CustomGetter, IStateInfo } from '../../types/state.types';
export declare class StateStore<T = any> {
protected states: IStateInfo<T>[];
private defaultValue;
/**
* If you set a custom getter, when the user wants to get the store, he will ask your method. Must return object (state)
* If you want to set a custom getter, use .setCustomGetter method
* */
customGet: (userId: number) => T | any;
getStore(userId: number): T;
private customGetter;
/**
* If you set a custom getter, when the user wants to get the store, he will ask your method
* @param customGetter Custom getter you want to save. Your getter can take user id, params from the handler, and default value as arguments. Getter must return object (state)
* */
setCustomGetter(customGetter: CustomGetter): true;
/**
* Set default value for state
* @param defaultValue Default value you want to set. Must be an object
* */
setDefaultValue(defaultValue: T): true;
getStore(userId: number, params?: any): Promise<T>;
}
export declare const stateStore: StateStore;

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

this.states = [];
this.defaultValue = {};
}
getStore(userId) {
if (this.customGet)
return this.customGet(userId);
/**
* If you set a custom getter, when the user wants to get the store, he will ask your method
* @param customGetter Custom getter you want to save. Your getter can take user id, params from the handler, and default value as arguments. Getter must return object (state)
* */
setCustomGetter(customGetter) {
this.customGetter = customGetter;
return true;
}
/**
* Set default value for state
* @param defaultValue Default value you want to set. Must be an object
* */
setDefaultValue(defaultValue) {
this.defaultValue = defaultValue;
return true;
}
async getStore(userId, params) {
if (this.customGetter) {
let result;
try {
result = await this.customGetter(userId, params, this.defaultValue);
}
catch (e) {
result = this.customGetter(userId, params, this.defaultValue);
}
return result;
}
let state = this.states.find((stateInfo) => stateInfo.userId === userId);
if (!state) {
state = { userId, state: {} };
state = { userId, state: (this.defaultValue || {}) };
this.states.push(state);

@@ -16,0 +41,0 @@ }

/**
* Get state. You can use it to store user data
* @see https://degreetpro.gitbook.io/nestgram/advenced/states
* */
export declare function GetState(): PropertyDecorator;

@@ -6,2 +6,3 @@ "use strict";

* Get state. You can use it to store user data
* @see https://degreetpro.gitbook.io/nestgram/advenced/states
* */

@@ -8,0 +9,0 @@ function GetState() {

@@ -10,4 +10,4 @@ "use strict";

const middlewares = [
...(Reflect.getMetadata('middlewares', descriptor.value) || []),
middleware,
...(Reflect.getMetadata('middlewares', target[key]) || []),
];

@@ -14,0 +14,0 @@ Reflect.defineMetadata('middlewares', middlewares, descriptor.value);

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

const method = descriptor.value;
descriptor.value = function () {
descriptor.value = function handler() {
const data = Reflect.getOwnMetadata('gotIndex', target, propertyName) || {};

@@ -27,0 +27,0 @@ const startArguments = { ...arguments };

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

export declare type CustomGetter = (userId: number, params?: any, defaultValue?: any) => Promise<any> | any;
export interface IStateInfo<T> {

@@ -2,0 +3,0 @@ userId: number;

{
"name": "nestgram",
"description": "Framework for working with Telegram Bot API on TypeScript like Nest.js",
"version": "1.8.6",
"version": "1.8.7",
"main": "dist/index.js",

@@ -6,0 +6,0 @@ "types": "dist/index.d.ts",

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 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