Skip to content

Commit 6db8a15

Browse files
feat: add initialized option
1 parent 2e73c15 commit 6db8a15

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-1
lines changed

index.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ declare namespace ConnectDynamoDB {
3232
* Upgrade to DynamoDB's TimeToLive configuration.
3333
*/
3434
reapInterval?: number;
35+
/**
36+
* Disable initialization.
37+
* Useful if the table already exists or if you want to skip existence checks in a serverless environment such as AWS Lambda.
38+
*/
39+
initialized?: boolean;
3540
}
3641

3742
interface DynamoDBStoreOptionsSpecialKey {

index.test-d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ const options: DynamoDBStoreOptions = {
3333
writeCapacityUnits: 25,
3434
specialKeys: specialKeysOptions,
3535
skipThrowMissingSpecialKeys: true,
36+
initialized: true,
3637
};
3738

3839
expectType<express.RequestHandler>(

lib/connect-dynamodb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ module.exports = function (connect) {
4545
function DynamoDBStore(options) {
4646
options = options || {};
4747
Store.call(this, options);
48-
this.initialized = false;
48+
this.initialized = options.initialized || false;
4949
this.prefix = null == options.prefix ? "sess:" : options.prefix;
5050
this.hashKey = null == options.hashKey ? "id" : options.hashKey;
5151
this.readCapacityUnits =

test/test.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,28 @@ describe("DynamoDBStore", () => {
148148
await client.send(new DeleteTableCommand({ TableName: tableName }));
149149
});
150150
});
151+
152+
describe("skip initializing", () => {
153+
const tableName = "sessions-test-" + Math.random().toString();
154+
const store = new DynamoDBStore({
155+
client,
156+
table: tableName,
157+
initialized: true,
158+
});
159+
const describeSessionsTableSpy = sinon.spy(
160+
store,
161+
"describeSessionsTable"
162+
);
163+
const createSessionsTableSpy = sinon.spy(store, "createSessionsTable");
164+
165+
it("Should skip table existence checks and creation", async () => {
166+
describeSessionsTableSpy.notCalled.should.equal(true);
167+
createSessionsTableSpy.notCalled.should.equal(true);
168+
await store.initialize();
169+
describeSessionsTableSpy.notCalled.should.equal(true);
170+
createSessionsTableSpy.notCalled.should.equal(true);
171+
});
172+
});
151173
});
152174

153175
describe("Setting", () => {

0 commit comments

Comments
 (0)