Initial commit

This commit is contained in:
Ammaar Reshi
2025-01-04 14:06:53 +00:00
parent 7082408604
commit d6025af146
23760 changed files with 3299690 additions and 0 deletions

10
node_modules/memorystore/.travis.yml generated vendored Normal file
View File

@ -0,0 +1,10 @@
language: node_js
node_js:
- "10"
- "12"
- "14"
cache:
directories:
- node_modules

21
node_modules/memorystore/LICENSE generated vendored Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2017 Rocco Musolino
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

71
node_modules/memorystore/README.md generated vendored Normal file
View File

@ -0,0 +1,71 @@
# memorystore [![NPM Version](https://img.shields.io/npm/v/memorystore.svg)](https://www.npmjs.com/package/memorystore) ![node](https://img.shields.io/node/v/memorystore.svg) [![Build Status](https://travis-ci.org/roccomuso/memorystore.svg?branch=master)](https://travis-ci.org/roccomuso/memorystore) [![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
> express-session full featured `MemoryStore` module without leaks!
A session store implementation for Express using [lru-cache](https://github.com/isaacs/node-lru-cache).
Because the default `MemoryStore` for [express-session](https://github.com/expressjs/session) will lead to a memory leak due to it haven't a suitable way to make them expire.
The sessions are still stored in memory, so they're not shared with other processes or services.
## Setup
$ npm install express-session memorystore
Pass the `express-session` store into `memorystore` to create a `MemoryStore` constructor.
```javascript
const session = require('express-session')
const MemoryStore = require('memorystore')(session)
app.use(session({
cookie: { maxAge: 86400000 },
store: new MemoryStore({
checkPeriod: 86400000 // prune expired entries every 24h
}),
resave: false,
secret: 'keyboard cat'
}))
```
## Options
* `checkPeriod` Define how long MemoryStore will check for expired. The period is in ms. The automatic check is disabled by default! Not setting this is kind of silly, since that's the whole purpose of this lib.
* `max` The maximum size of the cache, checked by applying the length
function to all values in the cache. It defaults to `Infinity`.
* `ttl` Session TTL (expiration) in milliseconds. Defaults to session.maxAge (if set), or one day. This may also be set to a function of the form `(options, sess, sessionID) => number`.
* `dispose` Function that is called on sessions when they are dropped
from the cache. This can be handy if you want to close file
descriptors or do other cleanup tasks when sessions are no longer
accessible. Called with `key, value`. It's called *before*
actually removing the item from the internal cache, so if you want
to immediately put it back in, you'll have to do that in a
`nextTick` or `setTimeout` callback or it won't do anything.
* `stale` By default, if you set a `maxAge`, it'll only actually pull
stale items out of the cache when you `get(key)`. (That is, it's
not pre-emptively doing a `setTimeout` or anything.) If you set
`stale:true`, it'll return the stale value before deleting it. If
you don't set this, then it'll return `undefined` when you try to
get a stale entry, as if it had already been deleted.
* `noDisposeOnSet` By default, if you set a `dispose()` method, then it'll be called whenever a `set()` operation overwrites an existing key. If you set this option, `dispose()` will only be called when a key falls out of the cache, not when it is overwritten.
* `serializer` An object containing `stringify` and `parse` methods compatible with Javascript's `JSON` to override the serializer used.
## Methods
`memorystore` implements all the **required**, **recommended** and **optional** methods of the [express-session](https://github.com/expressjs/session#session-store-implementation) store. Plus a few more:
- `startInterval()` and `stopInterval()` methods to start/clear the automatic check for expired.
- `prune()` that you can use to manually remove only the expired entries from the store.
## Debug
To enable debug set the env var `DEBUG=memorystore`
# Author
Rocco Musolino ([@roccomuso](https://twitter.com/roccomuso))
# License
MIT

81
node_modules/memorystore/index.d.ts generated vendored Normal file
View File

@ -0,0 +1,81 @@
import expressSession, {
MemoryStore as ExpressMemoryStore,
} from "express-session";
interface MemoryStoreOptions {
/**
* Define how long MemoryStore will check for expired.
* The period is in ms. The automatic check is disabled by default!
* Not setting this is kind of silly, since that's the whole purpose of
* this lib.
*/
checkPeriod?: number;
/**
* The maximum size of the cache, checked by applying the length
* function to all values in the cache. It defaults to `Infinity`.
*/
max?: number;
/**
* Session TTL (expiration) in milliseconds.
* Defaults to `session.maxAge` (if set), or one day.
*/
ttl?: number | ((options: any, sess: any, sessionId: any) => number);
/**
* Function that is called on sessions when they are dropped from the
* cache. This can be handy if you want to close file descriptors or do
* other cleanup tasks when sessions are no longer accessible. It's
* called before actually removing the item from the internal cache, so
* if you want to immediately put it back in, you'll have to do that in
* a `nextTick` or `setTimeout` callback or it won't do anything.
*/
dispose?: (key: any, value: any) => void;
/**
* By default, if you set a `maxAge`, it'll only actually pull stale
* items out of the cache when you `get(key)`. (That is, it's not
* pre-emptively doing a setTimeout or anything.) If you set
* `stale:true`, it'll return the stale value before deleting it. If
* you don't set this, then it'll return undefined when you try to get
* a stale entry, as if it had already been deleted.
*/
stale?: boolean;
/**
* By default, if you set a `dispose()` method, then it'll be called
* whenever a `set()` operation overwrites an existing key. If you set
* this option, `dispose()` will only be called when a key falls out of
* the cache, not when it is overwritten.
*/
noDisposeOnSet?: boolean;
/**
* An object compatible with Javascript's JSON to override the
* serializer used.
*/
serializer?: {
stringify: (arg: object) => string;
parse: (str: string) => object;
};
}
declare class MemoryStore extends ExpressMemoryStore {
constructor(options: MemoryStoreOptions);
/** method to start the automatic check for expired. */
startInterval(): void;
/** method to clear the automatic check for expired. */
stopInterval(): void;
/** use to manually remove only the expired entries from the store. */
prune(): void;
}
/**
* Sample usage:
* ```
* import session from 'express-session';
* import createMemoryStore from 'memorystore';
* const MemoryStore = createMemoryStore(session);
* ...
* app.use(session({ store: new MemoryStore({ ...options }) }));
* ```
*/
declare function createMemoryStore(
session: typeof expressSession
): typeof MemoryStore;
export = createMemoryStore;

1
node_modules/memorystore/index.js generated vendored Normal file
View File

@ -0,0 +1 @@
module.exports = require('./lib/memorystore.js')

295
node_modules/memorystore/lib/memorystore.js generated vendored Normal file
View File

@ -0,0 +1,295 @@
/*!
* memorystore
* Copyright(c) 2020 Rocco Musolino <@roccomuso>
* MIT Licensed
*/
var debug = require('debug')('memorystore')
var LRU = require('lru-cache')
var util = require('util')
/**
* One day in milliseconds.
*/
var oneDay = 86400000
function getTTL (options, sess, sid) {
if (typeof options.ttl === 'number') return options.ttl
if (typeof options.ttl === 'function') return options.ttl(options, sess, sid)
if (options.ttl) throw new TypeError('`options.ttl` must be a number or function.')
var maxAge = (sess && sess.cookie) ? sess.cookie.maxAge : null
return (typeof maxAge === 'number'
? Math.floor(maxAge)
: oneDay)
}
function prune (store) {
debug('Pruning expired entries')
store.forEach(function (value, key) {
store.get(key)
})
}
var defer = typeof setImmediate === 'function'
? setImmediate
: function (fn) { process.nextTick(fn.bind.apply(fn, arguments)) }
/**
* Return the `MemoryStore` extending `express`'s session Store.
*
* @param {object} express session
* @return {Function}
* @api public
*/
module.exports = function (session) {
/**
* Express's session Store.
*/
var Store = session.Store
/**
* Initialize MemoryStore with the given `options`.
*
* @param {Object} options
* @api public
*/
function MemoryStore (options) {
if (!(this instanceof MemoryStore)) {
throw new TypeError('Cannot call MemoryStore constructor as a function')
}
options = options || {}
Store.call(this, options)
this.options = {}
this.options.checkPeriod = options.checkPeriod
this.options.max = options.max || Infinity
this.options.ttl = options.ttl
this.options.dispose = options.dispose
this.options.stale = options.stale
this.options.noDisposeOnSet = options.noDisposeOnSet
this.serializer = options.serializer || JSON
this.store = LRU(this.options)
debug('Init MemoryStore')
this.startInterval()
}
/**
* Inherit from `Store`.
*/
util.inherits(MemoryStore, Store)
/**
* Attempt to fetch session by the given `sid`.
*
* @param {String} sid
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.get = function (sid, fn) {
var store = this.store
debug('GET "%s"', sid)
var data = store.get(sid)
if (!data) return fn()
debug('GOT %s', data)
var err = null
var result
try {
result = this.serializer.parse(data)
} catch (er) {
err = er
}
fn && defer(fn, err, result)
}
/**
* Commit the given `sess` object associated with the given `sid`.
*
* @param {String} sid
* @param {Session} sess
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.set = function (sid, sess, fn) {
var store = this.store
var ttl = getTTL(this.options, sess, sid)
try {
var jsess = this.serializer.stringify(sess)
} catch (err) {
fn && defer(fn, err)
}
store.set(sid, jsess, ttl)
debug('SET "%s" %s ttl:%s', sid, jsess, ttl)
fn && defer(fn, null)
}
/**
* Destroy the session associated with the given `sid`.
*
* @param {String} sid
* @api public
*/
MemoryStore.prototype.destroy = function (sid, fn) {
var store = this.store
if (Array.isArray(sid)) {
sid.forEach(function (s) {
debug('DEL "%s"', s)
store.del(s)
})
} else {
debug('DEL "%s"', sid)
store.del(sid)
}
fn && defer(fn, null)
}
/**
* Refresh the time-to-live for the session with the given `sid`.
*
* @param {String} sid
* @param {Session} sess
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.touch = function (sid, sess, fn) {
var store = this.store
var ttl = getTTL(this.options, sess, sid)
debug('EXPIRE "%s" ttl:%s', sid, ttl)
var err = null
if (store.get(sid) !== undefined) {
try {
var s = this.serializer.parse(store.get(sid))
s.cookie = sess.cookie
store.set(sid, this.serializer.stringify(s), ttl)
} catch (e) {
err = e
}
}
fn && defer(fn, err)
}
/**
* Fetch all sessions' ids
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.ids = function (fn) {
var store = this.store
var Ids = store.keys()
debug('Getting IDs: %s', Ids)
fn && defer(fn, null, Ids)
}
/**
* Fetch all sessions
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.all = function (fn) {
var store = this.store
var self = this
debug('Fetching all sessions')
var err = null
var result = {}
try {
store.forEach(function (val, key) {
result[key] = self.serializer.parse(val)
})
} catch (e) {
err = e
}
fn && defer(fn, err, result)
}
/**
* Delete all sessions from the store
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.clear = function (fn) {
var store = this.store
debug('delete all sessions from the store')
store.reset()
fn && defer(fn, null)
}
/**
* Get the count of all sessions in the store
*
* @param {Function} fn
* @api public
*/
MemoryStore.prototype.length = function (fn) {
var store = this.store
debug('getting length', store.itemCount)
fn && defer(fn, null, store.itemCount)
}
/**
* Start the check interval
* @api public
*/
MemoryStore.prototype.startInterval = function () {
var self = this
var ms = this.options.checkPeriod
if (ms && typeof ms === 'number') {
clearInterval(this._checkInterval)
debug('starting periodic check for expired sessions')
this._checkInterval = setInterval(function () {
prune(self.store) // iterates over the entire cache proactively pruning old entries
}, Math.floor(ms)).unref()
}
}
/**
* Stop the check interval
* @api public
*/
MemoryStore.prototype.stopInterval = function () {
debug('stopping periodic check for expired sessions')
clearInterval(this._checkInterval)
}
/**
* Remove only expired entries from the store
* @api public
*/
MemoryStore.prototype.prune = function () {
prune(this.store)
}
return MemoryStore
}

View File

@ -0,0 +1,15 @@
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

View File

@ -0,0 +1,158 @@
# lru cache
A cache object that deletes the least-recently-used items.
[![Build Status](https://travis-ci.org/isaacs/node-lru-cache.svg?branch=master)](https://travis-ci.org/isaacs/node-lru-cache) [![Coverage Status](https://coveralls.io/repos/isaacs/node-lru-cache/badge.svg?service=github)](https://coveralls.io/github/isaacs/node-lru-cache)
## Installation:
```javascript
npm install lru-cache --save
```
## Usage:
```javascript
var LRU = require("lru-cache")
, options = { max: 500
, length: function (n, key) { return n * 2 + key.length }
, dispose: function (key, n) { n.close() }
, maxAge: 1000 * 60 * 60 }
, cache = LRU(options)
, otherCache = LRU(50) // sets just the max size
cache.set("key", "value")
cache.get("key") // "value"
// non-string keys ARE fully supported
// but note that it must be THE SAME object, not
// just a JSON-equivalent object.
var someObject = { a: 1 }
cache.set(someObject, 'a value')
// Object keys are not toString()-ed
cache.set('[object Object]', 'a different value')
assert.equal(cache.get(someObject), 'a value')
// A similar object with same keys/values won't work,
// because it's a different object identity
assert.equal(cache.get({ a: 1 }), undefined)
cache.reset() // empty the cache
```
If you put more stuff in it, then items will fall out.
If you try to put an oversized thing in it, then it'll fall out right
away.
## Options
* `max` The maximum size of the cache, checked by applying the length
function to all values in the cache. Not setting this is kind of
silly, since that's the whole purpose of this lib, but it defaults
to `Infinity`.
* `maxAge` Maximum age in ms. Items are not pro-actively pruned out
as they age, but if you try to get an item that is too old, it'll
drop it and return undefined instead of giving it to you.
* `length` Function that is used to calculate the length of stored
items. If you're storing strings or buffers, then you probably want
to do something like `function(n, key){return n.length}`. The default is
`function(){return 1}`, which is fine if you want to store `max`
like-sized things. The item is passed as the first argument, and
the key is passed as the second argumnet.
* `dispose` Function that is called on items when they are dropped
from the cache. This can be handy if you want to close file
descriptors or do other cleanup tasks when items are no longer
accessible. Called with `key, value`. It's called *before*
actually removing the item from the internal cache, so if you want
to immediately put it back in, you'll have to do that in a
`nextTick` or `setTimeout` callback or it won't do anything.
* `stale` By default, if you set a `maxAge`, it'll only actually pull
stale items out of the cache when you `get(key)`. (That is, it's
not pre-emptively doing a `setTimeout` or anything.) If you set
`stale:true`, it'll return the stale value before deleting it. If
you don't set this, then it'll return `undefined` when you try to
get a stale entry, as if it had already been deleted.
* `noDisposeOnSet` By default, if you set a `dispose()` method, then
it'll be called whenever a `set()` operation overwrites an existing
key. If you set this option, `dispose()` will only be called when a
key falls out of the cache, not when it is overwritten.
## API
* `set(key, value, maxAge)`
* `get(key) => value`
Both of these will update the "recently used"-ness of the key.
They do what you think. `maxAge` is optional and overrides the
cache `maxAge` option if provided.
If the key is not found, `get()` will return `undefined`.
The key and val can be any value.
* `peek(key)`
Returns the key value (or `undefined` if not found) without
updating the "recently used"-ness of the key.
(If you find yourself using this a lot, you *might* be using the
wrong sort of data structure, but there are some use cases where
it's handy.)
* `del(key)`
Deletes a key out of the cache.
* `reset()`
Clear the cache entirely, throwing away all values.
* `has(key)`
Check if a key is in the cache, without updating the recent-ness
or deleting it for being stale.
* `forEach(function(value,key,cache), [thisp])`
Just like `Array.prototype.forEach`. Iterates over all the keys
in the cache, in order of recent-ness. (Ie, more recently used
items are iterated over first.)
* `rforEach(function(value,key,cache), [thisp])`
The same as `cache.forEach(...)` but items are iterated over in
reverse order. (ie, less recently used items are iterated over
first.)
* `keys()`
Return an array of the keys in the cache.
* `values()`
Return an array of the values in the cache.
* `length`
Return total length of objects in cache taking into account
`length` options function.
* `itemCount`
Return total quantity of objects currently in cache. Note, that
`stale` (see options) items are returned as part of this item
count.
* `dump()`
Return an array of the cache entries ready for serialization and usage
with 'destinationCache.load(arr)`.
* `load(cacheEntriesArray)`
Loads another cache entries array, obtained with `sourceCache.dump()`,
into the cache. The destination cache is reset before loading new entries
* `prune()`
Manually iterates over the entire cache proactively pruning old entries

View File

@ -0,0 +1,468 @@
'use strict'
module.exports = LRUCache
// This will be a proper iterable 'Map' in engines that support it,
// or a fakey-fake PseudoMap in older versions.
var Map = require('pseudomap')
var util = require('util')
// A linked list to keep track of recently-used-ness
var Yallist = require('yallist')
// use symbols if possible, otherwise just _props
var hasSymbol = typeof Symbol === 'function' && process.env._nodeLRUCacheForceNoSymbol !== '1'
var makeSymbol
if (hasSymbol) {
makeSymbol = function (key) {
return Symbol(key)
}
} else {
makeSymbol = function (key) {
return '_' + key
}
}
var MAX = makeSymbol('max')
var LENGTH = makeSymbol('length')
var LENGTH_CALCULATOR = makeSymbol('lengthCalculator')
var ALLOW_STALE = makeSymbol('allowStale')
var MAX_AGE = makeSymbol('maxAge')
var DISPOSE = makeSymbol('dispose')
var NO_DISPOSE_ON_SET = makeSymbol('noDisposeOnSet')
var LRU_LIST = makeSymbol('lruList')
var CACHE = makeSymbol('cache')
function naiveLength () { return 1 }
// lruList is a yallist where the head is the youngest
// item, and the tail is the oldest. the list contains the Hit
// objects as the entries.
// Each Hit object has a reference to its Yallist.Node. This
// never changes.
//
// cache is a Map (or PseudoMap) that matches the keys to
// the Yallist.Node object.
function LRUCache (options) {
if (!(this instanceof LRUCache)) {
return new LRUCache(options)
}
if (typeof options === 'number') {
options = { max: options }
}
if (!options) {
options = {}
}
var max = this[MAX] = options.max
// Kind of weird to have a default max of Infinity, but oh well.
if (!max ||
!(typeof max === 'number') ||
max <= 0) {
this[MAX] = Infinity
}
var lc = options.length || naiveLength
if (typeof lc !== 'function') {
lc = naiveLength
}
this[LENGTH_CALCULATOR] = lc
this[ALLOW_STALE] = options.stale || false
this[MAX_AGE] = options.maxAge || 0
this[DISPOSE] = options.dispose
this[NO_DISPOSE_ON_SET] = options.noDisposeOnSet || false
this.reset()
}
// resize the cache when the max changes.
Object.defineProperty(LRUCache.prototype, 'max', {
set: function (mL) {
if (!mL || !(typeof mL === 'number') || mL <= 0) {
mL = Infinity
}
this[MAX] = mL
trim(this)
},
get: function () {
return this[MAX]
},
enumerable: true
})
Object.defineProperty(LRUCache.prototype, 'allowStale', {
set: function (allowStale) {
this[ALLOW_STALE] = !!allowStale
},
get: function () {
return this[ALLOW_STALE]
},
enumerable: true
})
Object.defineProperty(LRUCache.prototype, 'maxAge', {
set: function (mA) {
if (!mA || !(typeof mA === 'number') || mA < 0) {
mA = 0
}
this[MAX_AGE] = mA
trim(this)
},
get: function () {
return this[MAX_AGE]
},
enumerable: true
})
// resize the cache when the lengthCalculator changes.
Object.defineProperty(LRUCache.prototype, 'lengthCalculator', {
set: function (lC) {
if (typeof lC !== 'function') {
lC = naiveLength
}
if (lC !== this[LENGTH_CALCULATOR]) {
this[LENGTH_CALCULATOR] = lC
this[LENGTH] = 0
this[LRU_LIST].forEach(function (hit) {
hit.length = this[LENGTH_CALCULATOR](hit.value, hit.key)
this[LENGTH] += hit.length
}, this)
}
trim(this)
},
get: function () { return this[LENGTH_CALCULATOR] },
enumerable: true
})
Object.defineProperty(LRUCache.prototype, 'length', {
get: function () { return this[LENGTH] },
enumerable: true
})
Object.defineProperty(LRUCache.prototype, 'itemCount', {
get: function () { return this[LRU_LIST].length },
enumerable: true
})
LRUCache.prototype.rforEach = function (fn, thisp) {
thisp = thisp || this
for (var walker = this[LRU_LIST].tail; walker !== null;) {
var prev = walker.prev
forEachStep(this, fn, walker, thisp)
walker = prev
}
}
function forEachStep (self, fn, node, thisp) {
var hit = node.value
if (isStale(self, hit)) {
del(self, node)
if (!self[ALLOW_STALE]) {
hit = undefined
}
}
if (hit) {
fn.call(thisp, hit.value, hit.key, self)
}
}
LRUCache.prototype.forEach = function (fn, thisp) {
thisp = thisp || this
for (var walker = this[LRU_LIST].head; walker !== null;) {
var next = walker.next
forEachStep(this, fn, walker, thisp)
walker = next
}
}
LRUCache.prototype.keys = function () {
return this[LRU_LIST].toArray().map(function (k) {
return k.key
}, this)
}
LRUCache.prototype.values = function () {
return this[LRU_LIST].toArray().map(function (k) {
return k.value
}, this)
}
LRUCache.prototype.reset = function () {
if (this[DISPOSE] &&
this[LRU_LIST] &&
this[LRU_LIST].length) {
this[LRU_LIST].forEach(function (hit) {
this[DISPOSE](hit.key, hit.value)
}, this)
}
this[CACHE] = new Map() // hash of items by key
this[LRU_LIST] = new Yallist() // list of items in order of use recency
this[LENGTH] = 0 // length of items in the list
}
LRUCache.prototype.dump = function () {
return this[LRU_LIST].map(function (hit) {
if (!isStale(this, hit)) {
return {
k: hit.key,
v: hit.value,
e: hit.now + (hit.maxAge || 0)
}
}
}, this).toArray().filter(function (h) {
return h
})
}
LRUCache.prototype.dumpLru = function () {
return this[LRU_LIST]
}
/* istanbul ignore next */
LRUCache.prototype.inspect = function (n, opts) {
var str = 'LRUCache {'
var extras = false
var as = this[ALLOW_STALE]
if (as) {
str += '\n allowStale: true'
extras = true
}
var max = this[MAX]
if (max && max !== Infinity) {
if (extras) {
str += ','
}
str += '\n max: ' + util.inspect(max, opts)
extras = true
}
var maxAge = this[MAX_AGE]
if (maxAge) {
if (extras) {
str += ','
}
str += '\n maxAge: ' + util.inspect(maxAge, opts)
extras = true
}
var lc = this[LENGTH_CALCULATOR]
if (lc && lc !== naiveLength) {
if (extras) {
str += ','
}
str += '\n length: ' + util.inspect(this[LENGTH], opts)
extras = true
}
var didFirst = false
this[LRU_LIST].forEach(function (item) {
if (didFirst) {
str += ',\n '
} else {
if (extras) {
str += ',\n'
}
didFirst = true
str += '\n '
}
var key = util.inspect(item.key).split('\n').join('\n ')
var val = { value: item.value }
if (item.maxAge !== maxAge) {
val.maxAge = item.maxAge
}
if (lc !== naiveLength) {
val.length = item.length
}
if (isStale(this, item)) {
val.stale = true
}
val = util.inspect(val, opts).split('\n').join('\n ')
str += key + ' => ' + val
})
if (didFirst || extras) {
str += '\n'
}
str += '}'
return str
}
LRUCache.prototype.set = function (key, value, maxAge) {
maxAge = maxAge || this[MAX_AGE]
var now = maxAge ? Date.now() : 0
var len = this[LENGTH_CALCULATOR](value, key)
if (this[CACHE].has(key)) {
if (len > this[MAX]) {
del(this, this[CACHE].get(key))
return false
}
var node = this[CACHE].get(key)
var item = node.value
// dispose of the old one before overwriting
// split out into 2 ifs for better coverage tracking
if (this[DISPOSE]) {
if (!this[NO_DISPOSE_ON_SET]) {
this[DISPOSE](key, item.value)
}
}
item.now = now
item.maxAge = maxAge
item.value = value
this[LENGTH] += len - item.length
item.length = len
this.get(key)
trim(this)
return true
}
var hit = new Entry(key, value, len, now, maxAge)
// oversized objects fall out of cache automatically.
if (hit.length > this[MAX]) {
if (this[DISPOSE]) {
this[DISPOSE](key, value)
}
return false
}
this[LENGTH] += hit.length
this[LRU_LIST].unshift(hit)
this[CACHE].set(key, this[LRU_LIST].head)
trim(this)
return true
}
LRUCache.prototype.has = function (key) {
if (!this[CACHE].has(key)) return false
var hit = this[CACHE].get(key).value
if (isStale(this, hit)) {
return false
}
return true
}
LRUCache.prototype.get = function (key) {
return get(this, key, true)
}
LRUCache.prototype.peek = function (key) {
return get(this, key, false)
}
LRUCache.prototype.pop = function () {
var node = this[LRU_LIST].tail
if (!node) return null
del(this, node)
return node.value
}
LRUCache.prototype.del = function (key) {
del(this, this[CACHE].get(key))
}
LRUCache.prototype.load = function (arr) {
// reset the cache
this.reset()
var now = Date.now()
// A previous serialized cache has the most recent items first
for (var l = arr.length - 1; l >= 0; l--) {
var hit = arr[l]
var expiresAt = hit.e || 0
if (expiresAt === 0) {
// the item was created without expiration in a non aged cache
this.set(hit.k, hit.v)
} else {
var maxAge = expiresAt - now
// dont add already expired items
if (maxAge > 0) {
this.set(hit.k, hit.v, maxAge)
}
}
}
}
LRUCache.prototype.prune = function () {
var self = this
this[CACHE].forEach(function (value, key) {
get(self, key, false)
})
}
function get (self, key, doUse) {
var node = self[CACHE].get(key)
if (node) {
var hit = node.value
if (isStale(self, hit)) {
del(self, node)
if (!self[ALLOW_STALE]) hit = undefined
} else {
if (doUse) {
self[LRU_LIST].unshiftNode(node)
}
}
if (hit) hit = hit.value
}
return hit
}
function isStale (self, hit) {
if (!hit || (!hit.maxAge && !self[MAX_AGE])) {
return false
}
var stale = false
var diff = Date.now() - hit.now
if (hit.maxAge) {
stale = diff > hit.maxAge
} else {
stale = self[MAX_AGE] && (diff > self[MAX_AGE])
}
return stale
}
function trim (self) {
if (self[LENGTH] > self[MAX]) {
for (var walker = self[LRU_LIST].tail;
self[LENGTH] > self[MAX] && walker !== null;) {
// We know that we're about to delete this one, and also
// what the next least recently used key will be, so just
// go ahead and set it now.
var prev = walker.prev
del(self, walker)
walker = prev
}
}
}
function del (self, node) {
if (node) {
var hit = node.value
if (self[DISPOSE]) {
self[DISPOSE](hit.key, hit.value)
}
self[LENGTH] -= hit.length
self[CACHE].delete(hit.key)
self[LRU_LIST].removeNode(node)
}
}
// classy, since V8 prefers predictable objects.
function Entry (key, value, length, now, maxAge) {
this.key = key
this.value = value
this.length = length
this.now = now
this.maxAge = maxAge || 0
}

View File

@ -0,0 +1,36 @@
{
"name": "lru-cache",
"description": "A cache object that deletes the least-recently-used items.",
"version": "4.1.5",
"author": "Isaac Z. Schlueter <i@izs.me>",
"keywords": [
"mru",
"lru",
"cache"
],
"scripts": {
"test": "tap test/*.js --100 -J",
"snap": "TAP_SNAPSHOT=1 tap test/*.js -J",
"posttest": "standard test/*.js index.js",
"coveragerport": "tap --coverage-report=html",
"lintfix": "standard --fix test/*.js index.js",
"preversion": "npm test",
"postversion": "npm publish --tag=legacy",
"postpublish": "git push origin --all; git push origin --tags"
},
"main": "index.js",
"repository": "git://github.com/isaacs/node-lru-cache.git",
"devDependencies": {
"benchmark": "^2.1.4",
"standard": "^12.0.1",
"tap": "^12.1.0"
},
"license": "ISC",
"dependencies": {
"pseudomap": "^1.0.2",
"yallist": "^2.1.2"
},
"files": [
"index.js"
]
}

15
node_modules/memorystore/node_modules/yallist/LICENSE generated vendored Normal file
View File

@ -0,0 +1,15 @@
The ISC License
Copyright (c) Isaac Z. Schlueter and Contributors
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

204
node_modules/memorystore/node_modules/yallist/README.md generated vendored Normal file
View File

@ -0,0 +1,204 @@
# yallist
Yet Another Linked List
There are many doubly-linked list implementations like it, but this
one is mine.
For when an array would be too big, and a Map can't be iterated in
reverse order.
[![Build Status](https://travis-ci.org/isaacs/yallist.svg?branch=master)](https://travis-ci.org/isaacs/yallist) [![Coverage Status](https://coveralls.io/repos/isaacs/yallist/badge.svg?service=github)](https://coveralls.io/github/isaacs/yallist)
## basic usage
```javascript
var yallist = require('yallist')
var myList = yallist.create([1, 2, 3])
myList.push('foo')
myList.unshift('bar')
// of course pop() and shift() are there, too
console.log(myList.toArray()) // ['bar', 1, 2, 3, 'foo']
myList.forEach(function (k) {
// walk the list head to tail
})
myList.forEachReverse(function (k, index, list) {
// walk the list tail to head
})
var myDoubledList = myList.map(function (k) {
return k + k
})
// now myDoubledList contains ['barbar', 2, 4, 6, 'foofoo']
// mapReverse is also a thing
var myDoubledListReverse = myList.mapReverse(function (k) {
return k + k
}) // ['foofoo', 6, 4, 2, 'barbar']
var reduced = myList.reduce(function (set, entry) {
set += entry
return set
}, 'start')
console.log(reduced) // 'startfoo123bar'
```
## api
The whole API is considered "public".
Functions with the same name as an Array method work more or less the
same way.
There's reverse versions of most things because that's the point.
### Yallist
Default export, the class that holds and manages a list.
Call it with either a forEach-able (like an array) or a set of
arguments, to initialize the list.
The Array-ish methods all act like you'd expect. No magic length,
though, so if you change that it won't automatically prune or add
empty spots.
### Yallist.create(..)
Alias for Yallist function. Some people like factories.
#### yallist.head
The first node in the list
#### yallist.tail
The last node in the list
#### yallist.length
The number of nodes in the list. (Change this at your peril. It is
not magic like Array length.)
#### yallist.toArray()
Convert the list to an array.
#### yallist.forEach(fn, [thisp])
Call a function on each item in the list.
#### yallist.forEachReverse(fn, [thisp])
Call a function on each item in the list, in reverse order.
#### yallist.get(n)
Get the data at position `n` in the list. If you use this a lot,
probably better off just using an Array.
#### yallist.getReverse(n)
Get the data at position `n`, counting from the tail.
#### yallist.map(fn, thisp)
Create a new Yallist with the result of calling the function on each
item.
#### yallist.mapReverse(fn, thisp)
Same as `map`, but in reverse.
#### yallist.pop()
Get the data from the list tail, and remove the tail from the list.
#### yallist.push(item, ...)
Insert one or more items to the tail of the list.
#### yallist.reduce(fn, initialValue)
Like Array.reduce.
#### yallist.reduceReverse
Like Array.reduce, but in reverse.
#### yallist.reverse
Reverse the list in place.
#### yallist.shift()
Get the data from the list head, and remove the head from the list.
#### yallist.slice([from], [to])
Just like Array.slice, but returns a new Yallist.
#### yallist.sliceReverse([from], [to])
Just like yallist.slice, but the result is returned in reverse.
#### yallist.toArray()
Create an array representation of the list.
#### yallist.toArrayReverse()
Create a reversed array representation of the list.
#### yallist.unshift(item, ...)
Insert one or more items to the head of the list.
#### yallist.unshiftNode(node)
Move a Node object to the front of the list. (That is, pull it out of
wherever it lives, and make it the new head.)
If the node belongs to a different list, then that list will remove it
first.
#### yallist.pushNode(node)
Move a Node object to the end of the list. (That is, pull it out of
wherever it lives, and make it the new tail.)
If the node belongs to a list already, then that list will remove it
first.
#### yallist.removeNode(node)
Remove a node from the list, preserving referential integrity of head
and tail and other nodes.
Will throw an error if you try to have a list remove a node that
doesn't belong to it.
### Yallist.Node
The class that holds the data and is actually the list.
Call with `var n = new Node(value, previousNode, nextNode)`
Note that if you do direct operations on Nodes themselves, it's very
easy to get into weird states where the list is broken. Be careful :)
#### node.next
The next node in the list.
#### node.prev
The previous node in the list.
#### node.value
The data the node contains.
#### node.list
The list to which this node belongs. (Null if it does not belong to
any list.)

View File

@ -0,0 +1,7 @@
var Yallist = require('./yallist.js')
Yallist.prototype[Symbol.iterator] = function* () {
for (let walker = this.head; walker; walker = walker.next) {
yield walker.value
}
}

View File

@ -0,0 +1,29 @@
{
"name": "yallist",
"version": "2.1.2",
"description": "Yet Another Linked List",
"main": "yallist.js",
"directories": {
"test": "test"
},
"files": [
"yallist.js",
"iterator.js"
],
"dependencies": {},
"devDependencies": {
"tap": "^10.3.0"
},
"scripts": {
"test": "tap test/*.js --100",
"preversion": "npm test",
"postversion": "npm publish",
"postpublish": "git push origin --all; git push origin --tags"
},
"repository": {
"type": "git",
"url": "git+https://github.com/isaacs/yallist.git"
},
"author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
"license": "ISC"
}

View File

@ -0,0 +1,370 @@
module.exports = Yallist
Yallist.Node = Node
Yallist.create = Yallist
function Yallist (list) {
var self = this
if (!(self instanceof Yallist)) {
self = new Yallist()
}
self.tail = null
self.head = null
self.length = 0
if (list && typeof list.forEach === 'function') {
list.forEach(function (item) {
self.push(item)
})
} else if (arguments.length > 0) {
for (var i = 0, l = arguments.length; i < l; i++) {
self.push(arguments[i])
}
}
return self
}
Yallist.prototype.removeNode = function (node) {
if (node.list !== this) {
throw new Error('removing node which does not belong to this list')
}
var next = node.next
var prev = node.prev
if (next) {
next.prev = prev
}
if (prev) {
prev.next = next
}
if (node === this.head) {
this.head = next
}
if (node === this.tail) {
this.tail = prev
}
node.list.length--
node.next = null
node.prev = null
node.list = null
}
Yallist.prototype.unshiftNode = function (node) {
if (node === this.head) {
return
}
if (node.list) {
node.list.removeNode(node)
}
var head = this.head
node.list = this
node.next = head
if (head) {
head.prev = node
}
this.head = node
if (!this.tail) {
this.tail = node
}
this.length++
}
Yallist.prototype.pushNode = function (node) {
if (node === this.tail) {
return
}
if (node.list) {
node.list.removeNode(node)
}
var tail = this.tail
node.list = this
node.prev = tail
if (tail) {
tail.next = node
}
this.tail = node
if (!this.head) {
this.head = node
}
this.length++
}
Yallist.prototype.push = function () {
for (var i = 0, l = arguments.length; i < l; i++) {
push(this, arguments[i])
}
return this.length
}
Yallist.prototype.unshift = function () {
for (var i = 0, l = arguments.length; i < l; i++) {
unshift(this, arguments[i])
}
return this.length
}
Yallist.prototype.pop = function () {
if (!this.tail) {
return undefined
}
var res = this.tail.value
this.tail = this.tail.prev
if (this.tail) {
this.tail.next = null
} else {
this.head = null
}
this.length--
return res
}
Yallist.prototype.shift = function () {
if (!this.head) {
return undefined
}
var res = this.head.value
this.head = this.head.next
if (this.head) {
this.head.prev = null
} else {
this.tail = null
}
this.length--
return res
}
Yallist.prototype.forEach = function (fn, thisp) {
thisp = thisp || this
for (var walker = this.head, i = 0; walker !== null; i++) {
fn.call(thisp, walker.value, i, this)
walker = walker.next
}
}
Yallist.prototype.forEachReverse = function (fn, thisp) {
thisp = thisp || this
for (var walker = this.tail, i = this.length - 1; walker !== null; i--) {
fn.call(thisp, walker.value, i, this)
walker = walker.prev
}
}
Yallist.prototype.get = function (n) {
for (var i = 0, walker = this.head; walker !== null && i < n; i++) {
// abort out of the list early if we hit a cycle
walker = walker.next
}
if (i === n && walker !== null) {
return walker.value
}
}
Yallist.prototype.getReverse = function (n) {
for (var i = 0, walker = this.tail; walker !== null && i < n; i++) {
// abort out of the list early if we hit a cycle
walker = walker.prev
}
if (i === n && walker !== null) {
return walker.value
}
}
Yallist.prototype.map = function (fn, thisp) {
thisp = thisp || this
var res = new Yallist()
for (var walker = this.head; walker !== null;) {
res.push(fn.call(thisp, walker.value, this))
walker = walker.next
}
return res
}
Yallist.prototype.mapReverse = function (fn, thisp) {
thisp = thisp || this
var res = new Yallist()
for (var walker = this.tail; walker !== null;) {
res.push(fn.call(thisp, walker.value, this))
walker = walker.prev
}
return res
}
Yallist.prototype.reduce = function (fn, initial) {
var acc
var walker = this.head
if (arguments.length > 1) {
acc = initial
} else if (this.head) {
walker = this.head.next
acc = this.head.value
} else {
throw new TypeError('Reduce of empty list with no initial value')
}
for (var i = 0; walker !== null; i++) {
acc = fn(acc, walker.value, i)
walker = walker.next
}
return acc
}
Yallist.prototype.reduceReverse = function (fn, initial) {
var acc
var walker = this.tail
if (arguments.length > 1) {
acc = initial
} else if (this.tail) {
walker = this.tail.prev
acc = this.tail.value
} else {
throw new TypeError('Reduce of empty list with no initial value')
}
for (var i = this.length - 1; walker !== null; i--) {
acc = fn(acc, walker.value, i)
walker = walker.prev
}
return acc
}
Yallist.prototype.toArray = function () {
var arr = new Array(this.length)
for (var i = 0, walker = this.head; walker !== null; i++) {
arr[i] = walker.value
walker = walker.next
}
return arr
}
Yallist.prototype.toArrayReverse = function () {
var arr = new Array(this.length)
for (var i = 0, walker = this.tail; walker !== null; i++) {
arr[i] = walker.value
walker = walker.prev
}
return arr
}
Yallist.prototype.slice = function (from, to) {
to = to || this.length
if (to < 0) {
to += this.length
}
from = from || 0
if (from < 0) {
from += this.length
}
var ret = new Yallist()
if (to < from || to < 0) {
return ret
}
if (from < 0) {
from = 0
}
if (to > this.length) {
to = this.length
}
for (var i = 0, walker = this.head; walker !== null && i < from; i++) {
walker = walker.next
}
for (; walker !== null && i < to; i++, walker = walker.next) {
ret.push(walker.value)
}
return ret
}
Yallist.prototype.sliceReverse = function (from, to) {
to = to || this.length
if (to < 0) {
to += this.length
}
from = from || 0
if (from < 0) {
from += this.length
}
var ret = new Yallist()
if (to < from || to < 0) {
return ret
}
if (from < 0) {
from = 0
}
if (to > this.length) {
to = this.length
}
for (var i = this.length, walker = this.tail; walker !== null && i > to; i--) {
walker = walker.prev
}
for (; walker !== null && i > from; i--, walker = walker.prev) {
ret.push(walker.value)
}
return ret
}
Yallist.prototype.reverse = function () {
var head = this.head
var tail = this.tail
for (var walker = head; walker !== null; walker = walker.prev) {
var p = walker.prev
walker.prev = walker.next
walker.next = p
}
this.head = tail
this.tail = head
return this
}
function push (self, item) {
self.tail = new Node(item, self.tail, null, self)
if (!self.head) {
self.head = self.tail
}
self.length++
}
function unshift (self, item) {
self.head = new Node(item, null, self.head, self)
if (!self.tail) {
self.tail = self.head
}
self.length++
}
function Node (value, prev, next, list) {
if (!(this instanceof Node)) {
return new Node(value, prev, next, list)
}
this.list = list
this.value = value
if (prev) {
prev.next = this
this.prev = prev
} else {
this.prev = null
}
if (next) {
next.prev = this
this.next = next
} else {
this.next = null
}
}

44
node_modules/memorystore/package.json generated vendored Normal file
View File

@ -0,0 +1,44 @@
{
"name": "memorystore",
"version": "1.6.7",
"description": "express-session full featured MemoryStore layer without leaks!",
"main": "index.js",
"types": "index.d.ts",
"scripts": {
"test": "mocha --check-leaks --bail --no-exit test/"
},
"repository": {
"type": "git",
"url": "git+https://github.com/roccomuso/memorystore.git"
},
"engines": {
"node": ">=0.10"
},
"keywords": [
"express-session",
"session",
"memory",
"store",
"memorystore",
"noleak",
"ram"
],
"author": "Rocco Musolino (roccomuso)",
"license": "MIT",
"bugs": {
"url": "https://github.com/roccomuso/memorystore/issues"
},
"homepage": "https://github.com/roccomuso/memorystore#readme",
"dependencies": {
"debug": "^4.3.0",
"lru-cache": "^4.0.3"
},
"devDependencies": {
"mocha": "9.2.0"
},
"standard": {
"env": [
"mocha"
]
}
}

304
node_modules/memorystore/test/store.js generated vendored Normal file
View File

@ -0,0 +1,304 @@
var assert = require('assert')
// express-session way
var MemoryStore = require('../')({Store: function () {}})
var session = {MemoryStore: MemoryStore}
describe('MemoryStore', function (done) {
afterEach(function () {
// runs after each test in this block
this.store.stopInterval()
})
it('constructor should use default options', function (done) {
this.store = new session.MemoryStore()
var store = this.store
assert.ok(store.options, 'should have an option object')
assert.equal(store.options.max, Infinity, 'max option should be Infinity')
assert.equal(store.options.checkPeriod, undefined, 'checkPeriod undefined by default')
assert.ok(store.store, 'should have the LRU cache store')
assert.equal(store._checkInterval, undefined, 'should not have the pruning loop')
done()
})
it('should set options', function (done) {
this.store = new session.MemoryStore({
max: 10,
checkPeriod: 10 * 1000,
ttl: 36000,
dispose: null,
stale: true
})
var store = this.store
assert.equal(store.options.max, 10, 'should set the max option')
assert.equal(store.options.checkPeriod, 10 * 1000, 'should set checkPeriod')
assert.equal(store.options.ttl, 36000, 'should set the TTL')
assert.equal(store.options.dispose, null, 'should set dispose')
assert.equal(store.options.stale, true, 'should set stale')
done()
})
it('should not set the interval to check for expired entries by default', function (done) {
this.store = new session.MemoryStore()
var store = this.store
assert.equal(store._checkInterval, undefined, 'should not exists')
done()
})
it('should only contain 10 items', function (done) {
this.store = new session.MemoryStore({max: 10})
var store = this.store
for (var i = 0; i < 15; i++) {
store.set(i, {cookie: { expires: new Date((new Date()).valueOf() + 60 * 10 * 1000) }})
}
store.length(function (err, length) {
if (err) return done(err)
assert.equal(length, 10)
done()
})
})
it('should delete the first item', function (done) {
this.store = new session.MemoryStore({max: 10})
var store = this.store
for (var i = 0; i < 15; i++) {
store.set(i, {cookie: { expires: new Date((new Date()).valueOf() + 60 * 10 * 1000) }})
}
store.destroy(14)
store.length(function (err, length) {
if (err) return done(err)
assert.equal(length, 9)
done()
})
})
it('should delete the last item', function (done) {
this.store = new session.MemoryStore({max: 10})
var store = this.store
for (var i = 0; i < 10; i++) {
store.set(i, {cookie: { expires: new Date((new Date()).valueOf() + 60 * 10 * 1000) }})
}
store.destroy(0)
store.destroy(1)
store.length(function (err, length) {
if (err) return done(err)
assert.equal(length, 8)
})
for (i = 10; i < 12; i++) {
store.set(i, {cookie: { expires: new Date((new Date()).valueOf() + 60 * 10 * 1000) }})
}
store.length(function (err, length) {
if (err) return done(err)
assert.equal(length, 10)
done()
})
})
it('should set and get a sample entry', function (done) {
this.store = new session.MemoryStore()
var store = this.store
store.set('hello', {cookie: {}, sample: true})
store.get('hello', function (err, val) {
if (err) return done(err)
assert.equal(val.sample, true, 'set and got expected value')
done()
})
})
it('should set TTL from cookie.maxAge', function (done) {
this.store = new session.MemoryStore()
var store = this.store
store.set('hello', {cookie: {maxAge: 400}, sample: true})
store.get('hello', function (err, val) {
if (err) return done(err)
assert.equal(val.sample, true, 'entry should be valid')
})
setTimeout(function () {
store.get('hello', function (err, val) {
if (err) return done(err)
assert.equal(val, undefined, 'entry should be expired')
done()
})
}, 500)
})
it('should not get empty entry', function (done) {
this.store = new session.MemoryStore()
var store = this.store
store.get('', function (err, val) {
if (err) return done(err)
assert.equal(val, undefined)
done()
})
})
it('should not get a deleted entry', function (done) {
this.store = new session.MemoryStore()
var store = this.store
store.set('foo', {cookie: {}})
store.get('foo', function (err, val) {
if (err) return done(err)
assert.ok(val, 'entry exists')
store.destroy('foo')
store.get('foo', function (err, val) {
if (err) return done(err)
assert.equal(val, undefined, 'entry actually deleted')
done()
})
})
})
it('should not get an expired entry', function (done) {
this.store = new session.MemoryStore()
var store = this.store
store.set('hello', {cookie: {maxAge: 200}, sample: true})
setTimeout(function () {
store.get('hello', function (err, val) {
if (err) return done(err)
assert.equal(val, undefined, 'entry should be expired')
done()
})
}, 300)
})
it('should enable automatic prune for expired entries', function (done) {
this.store = new session.MemoryStore({checkPeriod: 300})
var store = this.store
store.set('foo', {cookie: {maxAge: 150}})
store.set('bar', {cookie: {maxAge: 150}})
store.length(function (err, count) {
if (err) return done(err)
assert.equal(count, 2, 'should count 2 entries')
})
setTimeout(function () {
store.length(function (err, count) {
if (err) return done(err)
assert.equal(count, 0, 'expired entries should be pruned')
done()
})
}, 500)
})
it('automatic check for expired entries should be disabled', function (done) {
this.store = new session.MemoryStore()
var store = this.store
store.set('foo', {cookie: {maxAge: 150}})
store.set('bar', {cookie: {maxAge: 150}})
store.length(function (err, count) {
if (err) return done(err)
assert.equal(count, 2, 'should count 2 entries')
})
setTimeout(function () {
store.length(function (err, count) {
if (err) return done(err)
assert.equal(count, 2, 'expired entries should not be pruned')
done()
})
}, 500)
})
it('should touch a given entry', function (done) {
this.store = new session.MemoryStore()
var store = this.store
store.set('hei', {cookie: {maxAge: 50}})
store.touch('hei', {cookie: {maxAge: 300}})
setTimeout(function () {
store.get('hei', function (err, val) {
if (err) return done(err)
assert.ok(val, 'entry should be touched')
done()
})
}, 200)
})
it('should fetch all entries Ids', function (done) {
this.store = new session.MemoryStore()
var store = this.store
var k = 10
var i = 0
for (i = 0; i < k; i++) { store.set('sess' + i, {cookie: {maxAge: 1000}}) }
store.ids(function (err, ids) {
if (err) return done(err)
assert.ok(Array.isArray(ids), 'ids should be an Array')
i = 10
ids.forEach(function (sid) {
assert.equal(sid, 'sess' + (--i), 'got expected key')
})
done()
})
})
it('should fetch all entries values', function (done) {
this.store = new session.MemoryStore()
var store = this.store
var k = 10
var i = 0
for (i = 0; i < k; i++) { store.set('sess-' + i, {cookie: {maxAge: 1000}, i: i}) }
store.all(function (err, all) {
if (err) return done(err)
assert.equal(typeof all, 'object', 'all should be an Object')
Object.keys(all).forEach(function (sid) {
var v = sid.split('-')[1]
assert.equal(all[sid].i, v, 'got expected value')
})
done()
})
})
it('should count all entries in the store', function (done) {
this.store = new session.MemoryStore()
var store = this.store
var k = 10
var i = 0
for (i = 0; i < k; i++) { store.set(i, {cookie: {maxAge: 1000}}) }
store.length(function (err, n) {
if (err) return done(err)
assert.equal(n, k, 'Got expected lenght')
done()
})
})
it('should delete all entries from the store', function (done) {
this.store = new session.MemoryStore()
var store = this.store
var k = 10
var i = 0
for (i = 0; i < k; i++) { store.set(i, {cookie: {maxAge: 1000}}) }
store.length(function (err, n) {
if (err) return done(err)
assert.equal(n, k, 'store is not empty')
})
store.clear()
store.length(function (err, n) {
if (err) return done(err)
assert.equal(n, 0, 'store should be empty')
done()
})
})
})