From fe81394df5bcb133a7369430722cf2f94c0af5d0 Mon Sep 17 00:00:00 2001 From: yutak23 Date: Wed, 13 Nov 2024 17:35:09 +0900 Subject: [PATCH 1/2] test: add should store data correctly with specialKeys option --- test/test.js | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/test/test.js b/test/test.js index 66b23f7..8f8c6fc 100644 --- a/test/test.js +++ b/test/test.js @@ -193,6 +193,44 @@ describe("DynamoDBStore", () => { ); }); }); + + it("should store data correctly with specialKeys option", async () => { + const store = new DynamoDBStore({ + client: client, + table: tableName, + specialKeys: [ + { name: 'number_field', type: 'N' } + ] + }); + const randomNum = Math.floor(Math.random() * 1000) + 1; + + await new Promise((resolve, reject) => { + store.set( + sessionId, + { + cookie: { + maxAge: 2000, + }, + number_field: randomNum, + }, + (err) => { + if (err) return reject(err); + resolve(); + } + ); + }); + + return new Promise((resolve, reject) => { + store.get(sessionId, function (err, res) { + if (err) return reject(err); + + res.cookie.should.eql({ maxAge: 2000 }); + res.number_field.should.eql(randomNum); + + resolve(); + }); + }); + }); }); describe("Getting", () => { From 25185cb67cc77bde3af5a02efd7cafa648775362 Mon Sep 17 00:00:00 2001 From: yutak23 Date: Thu, 14 Nov 2024 18:13:29 +0900 Subject: [PATCH 2/2] fix: NUMBER_VALUE cannot be converted to String on specialKeys --- lib/connect-dynamodb.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/connect-dynamodb.js b/lib/connect-dynamodb.js index 6d476a3..fce270c 100644 --- a/lib/connect-dynamodb.js +++ b/lib/connect-dynamodb.js @@ -228,7 +228,7 @@ module.exports = function (connect) { this.specialKeys.forEach((key) => { if (typeof sess[key.name] !== "undefined") { const item = {}; - item[key.type] = sess[key.name]; + item[key.type] = key.type === 'N' ? JSON.stringify(sess[key.name]) : sess[key.name]; params.Item[key.name] = item; } else { missingKeys.push(key.name);