Skip to content

Commit

Permalink
fix: update exported entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
seekayel committed Nov 30, 2022
1 parent 56d9ffe commit a3347a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 48 deletions.
8 changes: 3 additions & 5 deletions src/DynamoDBStore.js → src/CyclicSessionStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ const { PutCommand, GetCommand, DeleteCommand } = require("@aws-sdk/lib-dynamodb
// @flow

const {
DEFAULT_TABLE_NAME,
DEFAULT_CALLBACK,
DEFAULT_HASH_KEY,
DEFAULT_HASH_PREFIX,
Expand All @@ -26,9 +25,8 @@ class CyclicSessionStore extends Store {
/**
* Constructor.
* @param {Object} options Store
* @param {Function} callback Optional callback for table creation.
*/
constructor (options = {}, callback = DEFAULT_CALLBACK) {
constructor (options = {}) {
super()
debug('Initializing store', options)
// debug('AWS sdk: ', AWS);
Expand Down Expand Up @@ -104,10 +102,10 @@ class CyclicSessionStore extends Store {
}
}
debug(`Saving session '${sid}'`, sess)

this.documentClient.send(new PutCommand(params)).then(callback)
} catch (err) {

console.error('sadfsadfasdf')
console.error(err)

Expand Down
9 changes: 1 addition & 8 deletions src/constants.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
// @flow

// defaults
const DEFAULT_TABLE_NAME = 'sessions'
const DEFAULT_HASH_KEY = 'pk'
const DEFAULT_SORT_KEY = 'sk'
const DEFAULT_TTL = 86400000 // 1 day
const DEFAULT_TOUCH_INTERVAL = 30000 // 30 seconds
const DEFAULT_KEEP_EXPIRED_POLICY = false
const DEFAULT_CALLBACK = (err) => {
if (err) {
throw err
}
}


// aws

module.exports = {
DEFAULT_TABLE_NAME,
DEFAULT_HASH_KEY,
DEFAULT_SORT_KEY,
DEFAULT_TTL,
DEFAULT_TOUCH_INTERVAL,
DEFAULT_KEEP_EXPIRED_POLICY,
DEFAULT_CALLBACK,
}
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

const { DynamoDBStore } = require('./DynamoDBStore.js')
const { CyclicSessionStore } = require('./CyclicSessionStore.js')

module.exports = {
DynamoDBStore
CyclicSessionStore
}
40 changes: 20 additions & 20 deletions test/DynamoDBStore.test.js → test/CyclicSessionStore.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import AWS from 'aws-sdk'; // eslint-disable-line
import { v4 as uuidv4 } from 'uuid';
import DynamoDBStore from '../src/DynamoDBStore';
import CyclicSessionStore from '../src/CyclicSessionStore';
import { toSecondsEpoch } from '../src/util';
import { DEFAULT_TABLE_NAME, DEFAULT_TTL } from '../src/constants';

Expand Down Expand Up @@ -46,7 +46,7 @@ const TEST_OPTIONS = {
// return dynamoService.deleteTable(params).promise();
// });

describe.skip('DynamoDBStore', () => {
describe.skip('CyclicSessionStore', () => {
it('should create a store and a new table', () =>
new Promise((resolve, reject) => {
const options = {
Expand All @@ -57,7 +57,7 @@ describe.skip('DynamoDBStore', () => {
},
dynamoConfig: TEST_OPTIONS.dynamoConfig,
};
const store = new DynamoDBStore(options, (err) => {
const store = new CyclicSessionStore(options, (err) => {
try {
expect(err).toBeUndefined();
resolve();
Expand All @@ -75,7 +75,7 @@ describe.skip('DynamoDBStore', () => {

it('should create a store using an existing table', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
else resolve();
});
Expand All @@ -85,7 +85,7 @@ describe.skip('DynamoDBStore', () => {
it('should create a store with default table values', () =>
new Promise((resolve, reject) => {
const options = { dynamoConfig: TEST_OPTIONS.dynamoConfig };
const store = new DynamoDBStore(options, (err) => {
const store = new CyclicSessionStore(options, (err) => {
try {
expect(err).toBeUndefined();
resolve();
Expand All @@ -103,7 +103,7 @@ describe.skip('DynamoDBStore', () => {

it('should create session with default ttl', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(
const store = new CyclicSessionStore(
{
...TEST_OPTIONS,
ttl: undefined,
Expand Down Expand Up @@ -156,7 +156,7 @@ describe.skip('DynamoDBStore', () => {

it('should create session using the cookie maxAge', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
const sessionId = uuidv4();
Expand Down Expand Up @@ -212,7 +212,7 @@ describe.skip('DynamoDBStore', () => {

it('should handle errors creating sessions', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
const sessionId = uuidv4();
Expand All @@ -228,7 +228,7 @@ describe.skip('DynamoDBStore', () => {

it('should update a session', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
const sessionId = 'abcde';
Expand Down Expand Up @@ -258,7 +258,7 @@ describe.skip('DynamoDBStore', () => {

it('should get an existing session', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
const sessionId = uuidv4();
Expand All @@ -284,7 +284,7 @@ describe.skip('DynamoDBStore', () => {

it('should handle errors getting sessions', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
store.documentClient = null;
Expand All @@ -300,7 +300,7 @@ describe.skip('DynamoDBStore', () => {

it('should receive null for missing sessions', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
store.get(uuidv4(), (err, sess) => {
Expand All @@ -318,7 +318,7 @@ describe.skip('DynamoDBStore', () => {

it('should return null for expired sessions and keep the record', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(
const store = new CyclicSessionStore(
{
...TEST_OPTIONS,
keepExpired: true,
Expand Down Expand Up @@ -365,7 +365,7 @@ describe.skip('DynamoDBStore', () => {

it('should return null for expired sessions and destroy the record', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
const sessionId = uuidv4();
Expand Down Expand Up @@ -406,7 +406,7 @@ describe.skip('DynamoDBStore', () => {

it('should destroy a session', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
const sessionId = uuidv4();
Expand Down Expand Up @@ -436,7 +436,7 @@ describe.skip('DynamoDBStore', () => {

it('should handle errors destroying sessions', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
store.documentClient = null;
Expand All @@ -452,7 +452,7 @@ describe.skip('DynamoDBStore', () => {

it('should touch an existing session', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
const sessionId = uuidv4();
Expand Down Expand Up @@ -506,7 +506,7 @@ describe.skip('DynamoDBStore', () => {
...TEST_OPTIONS,
touchInterval: 30000,
};
const store = new DynamoDBStore(options, (err) => {
const store = new CyclicSessionStore(options, (err) => {
if (err) reject(err);
});
const sessionId = uuidv4();
Expand Down Expand Up @@ -554,7 +554,7 @@ describe.skip('DynamoDBStore', () => {

it('should handle errors touching sessions', () =>
new Promise((resolve, reject) => {
const store = new DynamoDBStore(TEST_OPTIONS, (err) => {
const store = new CyclicSessionStore(TEST_OPTIONS, (err) => {
if (err) reject(err);
});
store.touch(null, null, (err) => {
Expand All @@ -570,7 +570,7 @@ describe.skip('DynamoDBStore', () => {
it('should handle errors creating the session table', () =>
new Promise((resolve, reject) => {
// eslint-disable-next-line
new DynamoDBStore(
new CyclicSessionStore(
{
...TEST_OPTIONS,
table: {
Expand Down
13 changes: 0 additions & 13 deletions test/constants.test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import {
DEFAULT_TABLE_NAME,
DEFAULT_CALLBACK,
DEFAULT_HASH_KEY,
DEFAULT_TTL,
DEFAULT_TOUCH_INTERVAL,
Expand All @@ -12,17 +10,6 @@ describe('constants', () => {
expect(DEFAULT_TOUCH_INTERVAL).toBeDefined();
expect(DEFAULT_TTL).toBeDefined();
expect(DEFAULT_HASH_KEY).toBeDefined();
expect(DEFAULT_CALLBACK).toBeDefined();
expect(DEFAULT_TABLE_NAME).toBeDefined();
expect(DEFAULT_KEEP_EXPIRED_POLICY).toBeDefined();
});

it('default callback raises the appropriate error', () =>
expect(() => {
DEFAULT_CALLBACK('AN ERROR');
}).toThrow('AN ERROR'));

it('default callback raises the appropriate error', () => {
DEFAULT_CALLBACK(null);
});
});

0 comments on commit a3347a2

Please sign in to comment.