<commit_before>'use strict';

export default {
  setup,
};

/**
 * Module dependencies.
 */

import SequelizeStore from 'koa-generic-session-sequelize';
// import convert from 'koa-convert';
import session from 'koa-generic-session';

/**
 * Prepares session middleware and methods without attaching to the stack
 *
 * @param {Object} settings
 * @param {Object} database
 * @param {Object} [store] Store for `koa-generic-sessions`. Uses the database if a store is not provided
 * @return {Object}
 */
function setup(settings, database, store) {
  return {
    // session middleware
    session: session({
      key: 'identityDesk.sid',
      store: store || new SequelizeStore(database),
    }),
    sessionMethods: function(ctx, next) {
      // set the secret keys for Keygrip
      ctx.app.keys = settings.session.keys;

      // attach session methods
      ctx.identityDesk = {
        get(key) {
          if (ctx.session && ctx.session.identityDesk && ctx.session.identityDesk[key] !== undefined) {
            return ctx.session.identityDesk[key];
          } else {
            return undefined;
          }
        },
        set(values) {
          ctx.session = ctx.session || { identityDesk: { values } };
          ctx.session.identityDesk = ctx.session.identityDesk || { values };
          Object.assign(ctx.session.identityDesk, values);
        },
      };

      return next();
    },
  };
}<commit_msg>Fix bug of session data being stored with an extra `values` key<commit_after>'use strict';

export default {
  setup,
};

/**
 * Module dependencies.
 */

import SequelizeStore from 'koa-generic-session-sequelize';
// import convert from 'koa-convert';
import session from 'koa-generic-session';

/**
 * Prepares session middleware and methods without attaching to the stack
 *
 * @param {Object} settings
 * @param {Object} database
 * @param {Object} [store] Store for `koa-generic-sessions`. Uses the database if a store is not provided
 * @return {Object}
 */
function setup(settings, database, store) {
  return {
    // session middleware
    session: session({
      key: 'identityDesk.sid',
      store: store || new SequelizeStore(database),
    }),
    sessionMethods: function(ctx, next) {
      // set the secret keys for Keygrip
      ctx.app.keys = settings.session.keys;

      // attach session methods
      ctx.identityDesk = {
        get(key) {
          if (ctx.session && ctx.session.identityDesk && ctx.session.identityDesk[key] !== undefined) {
            return ctx.session.identityDesk[key];
          } else {
            return undefined;
          }
        },
        set(values) {
          ctx.session = ctx.session || { identityDesk: values };
          ctx.session.identityDesk = ctx.session.identityDesk || values;
          Object.assign(ctx.session.identityDesk, values);
        },
      };

      return next();
    },
  };
}
{'fraction_non_alphanumeric': 0.12465373961218837, 'fraction_numerical': 0.0, 'mean_word_length': 2.5491400491400493, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '100606', 'n_tokens_mistral': 829, 'n_tokens_neox': 819, 'n_words': 221}