node-telegram-bot-api-middleware-context
Advanced tools
Comparing version 0.0.1 to 0.1.0
22
index.js
@@ -1,2 +0,14 @@ | ||
module.exports = function createContextMiddleware() { | ||
/** | ||
* @typedef {Object} MiddlewareContext | ||
* | ||
* @property {Object<string, any>} msg | ||
* @property {number} chatId | ||
* @property {Object<string, any>} ctx - Added context property | ||
*/ | ||
/** | ||
* Creates context middleware function. | ||
* @return {function(this: MiddlewareContext)} Context middleware function | ||
*/ | ||
function createContextMiddleware() { | ||
const contextStore = new WeakMap() | ||
@@ -9,2 +21,3 @@ | ||
get() { | ||
/** @type T */ | ||
let ctx = contextStore.get(key) | ||
@@ -22,2 +35,3 @@ | ||
set: function(obj, prop, val) { | ||
obj[prop] = val | ||
contextStore.set(key, obj) | ||
@@ -31,3 +45,3 @@ return true | ||
throw new Error( | ||
"Values cannot be assigned directly to 'this.ctx'. Use custom properties to save data, e.g. 'this.ctx.myProperty = myValue'." | ||
"Value cannot be assigned directly to 'this.ctx'. Use custom properties to save data, e.g. 'this.ctx.myProperty = myValue'." | ||
) | ||
@@ -38,2 +52,4 @@ }, | ||
} | ||
} | ||
} | ||
module.export = createContextMiddleware |
{ | ||
"name": "node-telegram-bot-api-middleware-context", | ||
"version": "0.0.1", | ||
"version": "0.1.0", | ||
"description": "Request context creation middleware for 'node-telegram-bot-api-middleware'.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
5407
5
45
60