Skip to content

Commit

Permalink
1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
TemaSM committed Jul 18, 2019
1 parent 690a644 commit feb9183
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 45 deletions.
19 changes: 10 additions & 9 deletions docs/LocalSession.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>


Expand Down Expand Up @@ -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>
Expand Down
11 changes: 6 additions & 5 deletions docs/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -177,7 +178,7 @@ <h4 class="name" id="LocalSession.storageBase"><span class="type-signature">(rea


<div class="description">
<p>lowdb <code><code>storage/adapter base</code></code> constructor (to extend it in your custom storage/adapter)</p>
<p>lowdb <a href="https://git.io/vhMOK">storage/adapter base</a> constructor (to extend it in your custom storage/adapter)</p>
</div>


Expand Down Expand Up @@ -240,7 +241,7 @@ <h4 class="name" id="LocalSession.storageFileAsync"><span class="type-signature"


<div class="description">
<p>lowdb storage/adapter named <code><code>FileAsync</code></code></p>
<p>lowdb storage/adapter named <a href="https://git.io/vhMqm">FileAsync</a></p>
</div>


Expand Down Expand Up @@ -303,7 +304,7 @@ <h4 class="name" id="LocalSession.storageFileSync"><span class="type-signature">


<div class="description">
<p>lowdb storage/adapter named <code><code>FileSync</code></code></p>
<p>lowdb storage/adapter named <a href="https://git.io/vhMqc">FileSync</a></p>
</div>


Expand Down Expand Up @@ -366,7 +367,7 @@ <h4 class="name" id="LocalSession.storageMemory"><span class="type-signature">(r


<div class="description">
<p>lowdb storage/adapter named <code><code>Memory</code></code></p>
<p>lowdb storage/adapter named <a href="https://git.io/vhMqs">Memory</a></p>
</div>


Expand Down Expand Up @@ -398,7 +399,7 @@ <h4 class="name" id="LocalSession.storageMemory"><span class="type-signature">(r
<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>
Expand Down
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -203,7 +204,7 @@ <h2>🎓 Licence &amp; copyright</h2>
<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>
Expand Down
5 changes: 3 additions & 2 deletions docs/module-telegraf-session-local.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -82,7 +83,7 @@ <h1 class="page-title">telegraf-session-local</h1>


<dt class="tag-version">Version:</dt>
<dd class="tag-version"><ul class="dummy"><li>0.0.7</li></ul></dd>
<dd class="tag-version"><ul class="dummy"><li>1.0.0</li></ul></dd>



Expand Down Expand Up @@ -208,7 +209,7 @@ <h3 class="subsection-title">Requires</h3>
<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>
Expand Down
14 changes: 9 additions & 5 deletions docs/scripts/collapse.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
function hideAllButCurrent(){
//by default all submenut items are hidden
//but we need to rehide them for search
document.querySelectorAll("nav > ul > li > ul li").forEach(function(parent) {
parent.style.display = "none";
});

//only current page (if it exists) should be opened
var file = window.location.pathname.split("/").pop();
document.querySelectorAll("nav > ul > li > a[href^='"+file+"']").forEach(function(parent) {
parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
elem.style.display = "block";
});
var file = window.location.pathname.split("/").pop().replace(/\.html/, '');
document.querySelectorAll("nav > ul > li > a").forEach(function(parent) {
var href = parent.attributes.href.value.replace(/\.html/, '');
if (file === href) {
parent.parentNode.querySelectorAll("ul li").forEach(function(elem) {
elem.style.display = "block";
});
}
});
}

Expand Down
12 changes: 12 additions & 0 deletions docs/scripts/nav.js
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();
2 changes: 1 addition & 1 deletion docs/scripts/search.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

var searchAttr = 'data-search-mode';
function contains(a,m){
return (a.textContent || a.innerText || "").toUpperCase().includes(m)
return (a.textContent || a.innerText || "").toUpperCase().indexOf(m) !== -1;
};

//on search
Expand Down
43 changes: 22 additions & 21 deletions docs/session.js.html
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -60,16 +61,16 @@ <h1 class="page-title">session.js</h1>
* Represents a wrapper around locally stored session, it's {@link LocalSession#middleware|middleware} &amp; lowdb
*
* @param {Object} [options] - Options for {@link LocalSession|LocalSession} &amp; {@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 {
Expand Down Expand Up @@ -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 } : {}
Expand All @@ -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')
Expand Down Expand Up @@ -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 || {}
}
Expand All @@ -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 })
Expand All @@ -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] })
Expand All @@ -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()
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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')
Expand All @@ -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 &lt;[email protected]>
* @requires {@link https://www.npmjs.com/package/telegraf|npm: telegraf}
Expand All @@ -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>
Expand Down
Loading

0 comments on commit feb9183

Please sign in to comment.