Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert objects to DynamoDB Maps for storage #92

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion lib/typeUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ function valueToObject(value) {
return {N: String(value)}
default:
if (Array.isArray(value)) {
if (value.length == 0)
return {L: []}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what are the implications here if the type of this list isn't of attributes?


var firstItemType = typeof value[0]

// check that all of the items are of the same type; that of the first element's
Expand All @@ -108,9 +111,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") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we move this condition to the top level switch?

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
Expand Down Expand Up @@ -139,7 +146,7 @@ function objectToType(obj) {
* Convert a Dynamo AttributeValue to a javascript primitive value
*
* @param {!AWSAttributeValue} obj
* @return {string|number|Array.<string>|Array.<number>|boolean} a javascript primitive value
* @return {string|number|Array.<string>|Array.<number>|boolean|Object} a javascript primitive value
*/
function objectToValue(obj) {
switch (objectToType(obj)) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"dependencies": {
"kew": "0.7.0",
"typ": "0.6.3",
"aws-sdk": "2.2.47"
"aws-sdk": "2.5.1"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a reason here why we're updating the sdk?

Copy link
Author

@danielpanzella danielpanzella Aug 29, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apologies, but this is something I did 2 years ago while implementing something for a former client, and I don't honestly recall the context here. If this PR is useful to others I can try and setup something to test it with the previous aws-sdk and see what happens, but I cannot promise when I will have time to do so.

Please consider this a response to all three of your questions.

},
"devDependencies": {
"closure-npc": "0.1.3",
Expand Down