-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
66 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
<![endif]--> | ||
<link type="text/css" rel="stylesheet" href="styles/prettify.css"> | ||
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> | ||
<script src="scripts/nav.js" defer></script> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
<body> | ||
|
@@ -238,7 +239,7 @@ <h6>Properties</h6> | |
|
||
|
||
|
||
<td class="description last"><p>Name or path to database file <code>(default: 'sessions.json')</code></p></td> | ||
<td class="description last"><p>Name or path to database file <code>default:</code> <code>'sessions.json'</code></p></td> | ||
</tr> | ||
|
||
|
||
|
@@ -271,7 +272,7 @@ <h6>Properties</h6> | |
|
||
|
||
|
||
<td class="description last"><p>Name of property in <a href="https://telegraf.js.org/#/?id=context">Telegraf Context</a> where session object will be located <code>(default: 'session')</code></p></td> | ||
<td class="description last"><p>Name of property in <a href="https://telegraf.js.org/#/?id=context">Telegraf Context</a> where session object will be located <code>default:</code> <code>'session'</code></p></td> | ||
</tr> | ||
|
||
|
||
|
@@ -304,7 +305,7 @@ <h6>Properties</h6> | |
|
||
|
||
|
||
<td class="description last"><p>Initial state of database. You can use it to pre-init database Arrays/Objects to store your own data <code>(default: {})</code></p></td> | ||
<td class="description last"><p>Initial state of database. You can use it to pre-init database Arrays/Objects to store your own data <code>default:</code> <code>{}</code></p></td> | ||
</tr> | ||
|
||
|
||
|
@@ -370,7 +371,7 @@ <h6>Properties</h6> | |
|
||
|
||
|
||
<td class="description last"><p>lowdb storage option for implementing your own storage read/write operations <code>(default: <a href="global.html#LocalSession.storageFileSync"><code>LocalSession.storageFileSync</code></a>)</code></p> | ||
<td class="description last"><p>lowdb storage option for implementing your own storage read/write operations <code>default:</code> <a href="global.html#LocalSession.storageFileSync"><code>LocalSession.storageFileSync</code></a></p> | ||
<h6>Properties</h6> | ||
|
||
|
||
|
@@ -551,7 +552,7 @@ <h6>Properties</h6> | |
|
||
|
||
|
||
<td class="description last"><p>lowdb storage serialize function, must return data (usually string) <code>(default: <code>JSON.stringify</code>)</code></p></td> | ||
<td class="description last"><p>lowdb storage serialize function, must return data (usually string) <code>default:</code> <a href="https://goo.gl/dmGpZd">JSON.stringify()</a></p></td> | ||
</tr> | ||
|
||
|
||
|
@@ -584,7 +585,7 @@ <h6>Properties</h6> | |
|
||
|
||
|
||
<td class="description last"><p>lowdb storage serialize function, must return an object <code>(default: <code>JSON.parse</code>)</code></p></td> | ||
<td class="description last"><p>lowdb storage deserialize function, must return an object <code>default:</code> <a href="https://goo.gl/wNy3ar">JSON.parse()</a></p></td> | ||
</tr> | ||
|
||
|
||
|
@@ -705,7 +706,7 @@ <h4 class="name" id=".storagefileAsync"><span class="type-signature">(readonly) | |
|
||
|
||
<div class="description"> | ||
<p>lowdb storage named <code><code>fileAsync</code></code> before <code><code>[email protected]</code></code></p> | ||
<p>lowdb storage named <a href="https://git.io/vhM3m">fileAsync</a> before <a href="https://git.io/vhM3Z">[email protected]</a></p> | ||
</div> | ||
|
||
|
||
|
@@ -768,7 +769,7 @@ <h4 class="name" id=".storagefileSync"><span class="type-signature">(readonly) < | |
|
||
|
||
<div class="description"> | ||
<p>lowdb storage named <code><code>fileSync</code></code> before <code><code>[email protected]</code></code></p> | ||
<p>lowdb storage named <a href="https://git.io/vhM3Y">fileSync</a> before <a href="https://git.io/vhM3Z">[email protected]</a></p> | ||
</div> | ||
|
||
|
||
|
@@ -1472,7 +1473,7 @@ <h5>Returns:</h5> | |
<br class="clear"> | ||
|
||
<footer> | ||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. | ||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. | ||
</footer> | ||
|
||
<script>prettyPrint();</script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function scrollToNavItem() { | ||
var path = window.location.href.split('/').pop().replace(/\.html/, ''); | ||
document.querySelectorAll('nav a').forEach(function(link) { | ||
var href = link.attributes.href.value.replace(/\.html/, ''); | ||
if (path === href) { | ||
link.scrollIntoView({block: 'center'}); | ||
return; | ||
} | ||
}) | ||
} | ||
|
||
scrollToNavItem(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ | |
<![endif]--> | ||
<link type="text/css" rel="stylesheet" href="styles/prettify.css"> | ||
<link type="text/css" rel="stylesheet" href="styles/jsdoc.css"> | ||
<script src="scripts/nav.js" defer></script> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
</head> | ||
<body> | ||
|
@@ -60,16 +61,16 @@ <h1 class="page-title">session.js</h1> | |
* Represents a wrapper around locally stored session, it's {@link LocalSession#middleware|middleware} & lowdb | ||
* | ||
* @param {Object} [options] - Options for {@link LocalSession|LocalSession} & {@link https://github.com/typicode/lowdb|lowdb} | ||
* @param {String} [options.database] - Name or path to database file `(default: 'sessions.json')` | ||
* @param {String} [options.property] - Name of property in {@link https://telegraf.js.org/#/?id=context|Telegraf Context} where session object will be located `(default: 'session')` | ||
* @param {Object} [options.state] - Initial state of database. You can use it to pre-init database Arrays/Objects to store your own data `(default: {})` | ||
* @param {String} [options.database] - Name or path to database file `default:` `'sessions.json'` | ||
* @param {String} [options.property] - Name of property in {@link https://telegraf.js.org/#/?id=context|Telegraf Context} where session object will be located `default:` `'session'` | ||
* @param {Object} [options.state] - Initial state of database. You can use it to pre-init database Arrays/Objects to store your own data `default:` `{}` | ||
* @param {Function} [options.getSessionKey] - Function to get identifier for session from {@link https://telegraf.js.org/#/?id=context|Telegraf Context} (may implement it on your own) | ||
* @param {Object} [options.storage] - lowdb storage option for implementing your own storage read/write operations `(default: {@link LocalSession.storageFileSync|LocalSession.storageFileSync})` | ||
* @param {Object} [options.storage] - lowdb storage option for implementing your own storage read/write operations `default:` {@link LocalSession.storageFileSync|LocalSession.storageFileSync} | ||
* @param {Function} [options.storage.read] - lowdb storage read function, must return an object or a Promise | ||
* @param {Function} [options.storage.write] - lowdb storage write function, must return undefined or a Promise | ||
* @param {Object} [options.format] - lowdb storage format option for implementing your own database format for read/write operations | ||
* @param {Function} [options.format.serialize] - lowdb storage serialize function, must return data (usually string) `(default: {@link https://goo.gl/dmGpZd|JSON.stringify})` | ||
* @param {Function} [options.format.deserialize] - lowdb storage serialize function, must return an object `(default: {@link https://goo.gl/wNy3ar|JSON.parse})` | ||
* @param {Function} [options.format.serialize] - lowdb storage serialize function, must return data (usually string) `default:` {@link https://goo.gl/dmGpZd|JSON.stringify()} | ||
* @param {Function} [options.format.deserialize] - lowdb storage deserialize function, must return an object `default:` {@link https://goo.gl/wNy3ar|JSON.parse()} | ||
* @returns Instance of {@link LocalSession|LocalSession} | ||
*/ | ||
class LocalSession { | ||
|
@@ -98,7 +99,7 @@ <h1 class="page-title">session.js</h1> | |
this.DB = undefined | ||
this._adapter = undefined | ||
// DISABLED: this.options.defaultValue = this.options.state // Backward compatability with old lowdb | ||
let defaultAdaptersOptions = Object.assign( | ||
const defaultAdaptersOptions = Object.assign( | ||
{ defaultValue: this.options.state }, | ||
this.options.format.serialize ? { serialize: this.options.format.serialize } : {}, | ||
this.options.format.deserialize ? { deserialize: this.options.format.deserialize } : {} | ||
|
@@ -117,7 +118,7 @@ <h1 class="page-title">session.js</h1> | |
this._adapter = new this.options.storage(this.options.database, defaultAdaptersOptions) | ||
} | ||
debug('Initiating: lowdb instance') | ||
let DbInstance = lowdb(this._adapter) | ||
const DbInstance = lowdb(this._adapter) | ||
// If lowdb initiated with async (Promise) adapter | ||
if (isPromise(DbInstance)) { | ||
debug('DbInstance is Promise like') | ||
|
@@ -155,7 +156,7 @@ <h1 class="page-title">session.js</h1> | |
*/ | ||
getSession (key) { | ||
this._called(arguments) | ||
let session = this.DB.get('sessions').getById(key).value() || {} | ||
const session = this.DB.get('sessions').getById(key).value() || {} | ||
debug('Session state', session) | ||
return session.data || {} | ||
} | ||
|
@@ -180,7 +181,7 @@ <h1 class="page-title">session.js</h1> | |
// If database has record, then just update it | ||
if (this.DB.get('sessions').getById(key).value()) { | ||
debug(' -> Updating') | ||
let session = this.DB.get('sessions').updateById(key, { data: data }).write() | ||
const session = this.DB.get('sessions').updateById(key, { data: data }).write() | ||
// Check if lowdb Storage returned var type is Promise-like or just sync-driven data | ||
if (isPromise(session)) { | ||
return session.then(sess => { return sess }) | ||
|
@@ -192,7 +193,7 @@ <h1 class="page-title">session.js</h1> | |
// If no, so we should push new record into it | ||
else { | ||
debug(' -> Inserting') | ||
let session = this.DB.get('sessions').push({ id: key, data: data }).write() | ||
const session = this.DB.get('sessions').push({ id: key, data: data }).write() | ||
// Check if lowdb Storage returned var type is Promise-like or just sync-driven data | ||
if (isPromise(session)) { | ||
return session.then(_session => { return _session[0] }) | ||
|
@@ -211,7 +212,7 @@ <h1 class="page-title">session.js</h1> | |
* @returns {Promise} | ||
*/ | ||
middleware (property = this.options.property) { | ||
let that = this | ||
const that = this | ||
return (ctx, next) => { | ||
const key = that.getSessionKey(ctx) | ||
if (!key) return next() | ||
|
@@ -238,7 +239,7 @@ <h1 class="page-title">session.js</h1> | |
} | ||
|
||
/** | ||
* lowdb storage named `{@link https://git.io/vhM3Y|fileSync}` before `{@link https://git.io/vhM3Z|[email protected]}` | ||
* lowdb storage named {@link https://git.io/vhM3Y|fileSync} before {@link https://git.io/vhM3Z|[email protected]} | ||
* | ||
* @memberof! LocalSession | ||
* @name LocalSession.storagefileSync | ||
|
@@ -250,7 +251,7 @@ <h1 class="page-title">session.js</h1> | |
} | ||
|
||
/** | ||
* lowdb storage/adapter named `{@link https://git.io/vhMqc|FileSync}` | ||
* lowdb storage/adapter named {@link https://git.io/vhMqc|FileSync} | ||
* | ||
* @memberof! LocalSession | ||
* @name LocalSession.storageFileSync | ||
|
@@ -262,7 +263,7 @@ <h1 class="page-title">session.js</h1> | |
} | ||
|
||
/** | ||
* lowdb storage named `{@link https://git.io/vhM3m|fileAsync}` before `{@link https://git.io/vhM3Z|[email protected]}` | ||
* lowdb storage named {@link https://git.io/vhM3m|fileAsync} before {@link https://git.io/vhM3Z|[email protected]} | ||
* | ||
* @memberof! LocalSession | ||
* @name LocalSession.storagefileAsync | ||
|
@@ -274,7 +275,7 @@ <h1 class="page-title">session.js</h1> | |
} | ||
|
||
/** | ||
* lowdb storage/adapter named `{@link https://git.io/vhMqm|FileAsync}` | ||
* lowdb storage/adapter named {@link https://git.io/vhMqm|FileAsync} | ||
* | ||
* @memberof! LocalSession | ||
* @name LocalSession.storageFileAsync | ||
|
@@ -286,7 +287,7 @@ <h1 class="page-title">session.js</h1> | |
} | ||
|
||
/** | ||
* lowdb storage/adapter named `{@link https://git.io/vhMqs|Memory}` | ||
* lowdb storage/adapter named {@link https://git.io/vhMqs|Memory} | ||
* | ||
* @memberof! LocalSession | ||
* @name LocalSession.storageMemory | ||
|
@@ -298,7 +299,7 @@ <h1 class="page-title">session.js</h1> | |
} | ||
|
||
/** | ||
* lowdb `{@link https://git.io/vhMOK|storage/adapter base}` constructor (to extend it in your custom storage/adapter) | ||
* lowdb {@link https://git.io/vhMOK|storage/adapter base} constructor (to extend it in your custom storage/adapter) | ||
* | ||
* @memberof! LocalSession | ||
* @name LocalSession.storageBase | ||
|
@@ -322,7 +323,7 @@ <h1 class="page-title">session.js</h1> | |
|
||
function _initDB () { | ||
// Use ID based resources, so we can query records by ID (ex.: getById(), removeById(), ...) | ||
this.DB._.mixin(require('lodash-id')) | ||
this.DB._.mixin(require('./lodash-id')) | ||
// If database is empty, fill it with empty Array of sessions and optionally with initial state | ||
this.DB.defaults(Object.assign({ sessions: [] }, this.options.state)).write() | ||
debug('Initiating finished') | ||
|
@@ -337,7 +338,7 @@ <h1 class="page-title">session.js</h1> | |
/** | ||
* @overview {@link http://telegraf.js.org/|Telegraf} Session middleware for storing sessions locally (Memory/FileSync/FileAsync/...) | ||
* @module telegraf-session-local | ||
* @version 0.0.7 | ||
* @version 1.0.0 | ||
* @license MIT | ||
* @author Tema Smirnov <[email protected]> | ||
* @requires {@link https://www.npmjs.com/package/telegraf|npm: telegraf} | ||
|
@@ -361,7 +362,7 @@ <h1 class="page-title">session.js</h1> | |
<br class="clear"> | ||
|
||
<footer> | ||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.2</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. | ||
Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.6.3</a> using the <a href="https://github.com/clenemt/docdash">docdash</a> theme. | ||
</footer> | ||
|
||
<script>prettyPrint();</script> | ||
|
Oops, something went wrong.