npmtest-session-file-store (v0.0.1)

Code coverage report for node-npmtest-session-file-store/node_modules/session-file-store/lib/session-file-store.js

Statements: 13.33% (4 / 30)      Branches: 0% (0 / 2)      Functions: 0% (0 / 10)      Lines: 13.33% (4 / 30)      Ignored: none     

All files » node-npmtest-session-file-store/node_modules/session-file-store/lib/ » session-file-store.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 1401 1                   1                   1                                                                                                                                                                                                                                            
var helpers = require('./session-file-helpers');
var fs = require('fs-extra');
 
/**
 * https://github.com/expressjs/session#session-store-implementation
 *
 * @param {object} session  express session
 * @return {Function} the `FileStore` extending `express`'s session Store
 *
 * @api public
 */
module.exports = function (session) {
  var Store = session.Store;
 
  /**
   * Initialize FileStore with the given `options`
   *
   * @param {Object} options (optional)
   *
   * @api public
   */
  function FileStore(options) {
    var self = this;
 
    options = options || {};
    Store.call(self, options);
 
    self.options = helpers.defaults(options);
    fs.mkdirsSync(self.options.path);
    helpers.scheduleReap(self.options);
    options.reapIntervalObject = self.options.reapIntervalObject;
  }
 
  /**
   * Inherit from Store
   */
  FileStore.prototype.__proto__ = Store.prototype;
 
  /**
   * Attempts to fetch session from a session file by the given `sessionId`
   *
   * @param  {String}   sessionId
   * @param  {Function} callback
   *
   * @api public
   */
  FileStore.prototype.get = function (sessionId, callback) {
    helpers.get(sessionId, this.options, callback);
  };
 
  /**
   * Attempts to commit the given session associated with the given `sessionId` to a session file
   *
   * @param {String}   sessionId
   * @param {Object}   session
   * @param {Function} callback (optional)
   *
   * @api public
   */
  FileStore.prototype.set = function (sessionId, session, callback) {
    helpers.set(sessionId, session, this.options, callback);
  };
 
  /**
   * Touch the given session object associated with the given `sessionId`
   *
   * @param {string} sessionId
   * @param {object} session
   * @param {function} callback
   *
   * @api public
   */
 
  FileStore.prototype.touch = function (sessionId, session, callback) {
    // will update last access time
    helpers.set(sessionId, session, this.options, callback);
  };
 
  /**
   * Attempts to unlink a given session by its id
   *
   * @param  {String}   sessionId   Files are serialized to disk by their
   *                                sessionId
   * @param  {Function} callback
   *
   * @api public
   */
  FileStore.prototype.destroy = function (sessionId, callback) {
    helpers.destroy(sessionId, this.options, callback);
  };
 
  /**
   * Attempts to fetch number of the session files
   *
   * @param  {Function} callback
   *
   * @api public
   */
  FileStore.prototype.length = function (callback) {
    helpers.length(this.options, callback);
  };
 
  /**
   * Attempts to clear out all of the existing session files
   *
   * @param  {Function} callback
   *
   * @api public
   */
  FileStore.prototype.clear = function (callback) {
    helpers.clear(this.options, callback);
  };
 
  /**
   * Attempts to find all of the session files
   *
   * @param  {Function} callback
   *
   * @api public
   */
  FileStore.prototype.list = function (callback) {
    helpers.list(this.options, callback);
  };
 
  /**
   * Attempts to detect whether a session file is already expired or not
   *
   * @param  {String}   sessionId
   * @param  {Function} callback
   *
   * @api public
   */
  FileStore.prototype.expired = function (sessionId, callback) {
    helpers.expired(sessionId, this.options, callback);
  };
 
  return FileStore;
};