From 1b3988f5f0f8b470b4b08dc705c2eb13d278e5c7 Mon Sep 17 00:00:00 2001 From: Dan Panzella Date: Fri, 3 Jun 2016 16:18:44 -0700 Subject: [PATCH 1/4] Convert objects to DynamoDB Maps for storage --- lib/typeUtil.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/typeUtil.js b/lib/typeUtil.js index 6bd94bd..e8eefe3 100644 --- a/lib/typeUtil.js +++ b/lib/typeUtil.js @@ -111,6 +111,8 @@ function valueToObject(value) { } else { throw new Error('Invalid dynamo set value. Type: ' + firstItemType + ', Value: ' + value[0]) } + } else if (typeof value == "object") { + return {M: packObjectOrArray(value)}; } else { // TODO(nick): I'm pretty sure this should be an error. But there is a bunch // of code relying on this behavior, so just log the error for now and From 0184449e720dc137e89792ea11fc7e5471f83d6b Mon Sep 17 00:00:00 2001 From: Dan Panzella Date: Tue, 14 Jun 2016 11:25:08 -0700 Subject: [PATCH 2/4] Add support for arrays of objects as well, remove semi-colon as it seems that is the standard. Correct JSDoc annotation as the objectToValue function can also return objects --- lib/typeUtil.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/typeUtil.js b/lib/typeUtil.js index e8eefe3..203cdbd 100644 --- a/lib/typeUtil.js +++ b/lib/typeUtil.js @@ -108,11 +108,13 @@ function valueToObject(value) { } return {NS: numArray} + } else if (firstItemType === "object") { + return {L: value.map(valueToObject)} } else { throw new Error('Invalid dynamo set value. Type: ' + firstItemType + ', Value: ' + value[0]) } } else if (typeof value == "object") { - return {M: packObjectOrArray(value)}; + return {M: packObjectOrArray(value)} } else { // TODO(nick): I'm pretty sure this should be an error. But there is a bunch // of code relying on this behavior, so just log the error for now and @@ -141,7 +143,7 @@ function objectToType(obj) { * Convert a Dynamo AttributeValue to a javascript primitive value * * @param {!AWSAttributeValue} obj - * @return {string|number|Array.|Array.|boolean} a javascript primitive value + * @return {string|number|Array.|Array.|boolean|Object} a javascript primitive value */ function objectToValue(obj) { switch (objectToType(obj)) { From 77cab589efb0dca4babe33a8870b3f06ab573472 Mon Sep 17 00:00:00 2001 From: Dan Panzella Date: Wed, 15 Jun 2016 11:57:28 -0700 Subject: [PATCH 3/4] Handle empty arrays --- lib/typeUtil.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/typeUtil.js b/lib/typeUtil.js index 203cdbd..732b91e 100644 --- a/lib/typeUtil.js +++ b/lib/typeUtil.js @@ -90,6 +90,9 @@ function valueToObject(value) { return {N: String(value)} default: if (Array.isArray(value)) { + if (value.length == 0) + return {L: []} + var firstItemType = typeof value[0] // check that all of the items are of the same type; that of the first element's From d6daba4fce7f99a5ca53d30c7d5d1c3e33802b7c Mon Sep 17 00:00:00 2001 From: Dan Panzella Date: Wed, 17 Aug 2016 16:36:12 -0700 Subject: [PATCH 4/4] update aws sdk --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 5e4774f..301283e 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,7 @@ "dependencies": { "kew": "0.7.0", "typ": "0.6.3", - "aws-sdk": "2.2.47" + "aws-sdk": "2.5.1" }, "devDependencies": { "closure-npc": "0.1.3",