-
Notifications
You must be signed in to change notification settings - Fork 619
fix(util-dynamodb): allow marshall function to handle more input types #3539
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ jspm_packages | |
.DS_Store | ||
.vscode/launch.json | ||
|
||
Makefile | ||
lerna-debug.log | ||
package-lock.json | ||
|
||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
import { marshallInput } from "./utils"; | ||
|
||
describe("marshallInput and processObj", () => { | ||
it("marshallInput should not ignore falsy values", () => { | ||
expect(marshallInput({ Items: [0, false, null, ""] }, [{ key: "Items" }])).toEqual({ | ||
Items: [{ N: "0" }, { BOOL: false }, { NULL: true }, { S: "" }], | ||
}); | ||
}); | ||
}); | ||
|
||
describe("marshallInput for commands", () => { | ||
it("marshals QueryCommand input", () => { | ||
const input = { | ||
TableName: "TestTable", | ||
KeyConditions: { | ||
id: { | ||
AttributeValueList: ["test"], | ||
ComparisonOperator: "EQ", | ||
}, | ||
}, | ||
}; | ||
const inputKeyNodes = [ | ||
{ | ||
key: "KeyConditions", | ||
children: { | ||
children: [{ key: "AttributeValueList" }], | ||
}, | ||
}, | ||
{ | ||
key: "QueryFilter", | ||
children: { | ||
children: [{ key: "AttributeValueList" }], | ||
}, | ||
}, | ||
{ key: "ExclusiveStartKey" }, | ||
{ key: "ExpressionAttributeValues" }, | ||
]; | ||
const output = { | ||
TableName: "TestTable", | ||
KeyConditions: { id: { AttributeValueList: [{ S: "test" }], ComparisonOperator: "EQ" } }, | ||
QueryFilter: undefined, | ||
ExclusiveStartKey: undefined, | ||
ExpressionAttributeValues: undefined, | ||
}; | ||
expect(marshallInput(input, inputKeyNodes)).toEqual(output); | ||
}); | ||
it("marshals ExecuteStatementCommand input", () => { | ||
const input = { | ||
Statement: `SELECT col_1 | ||
FROM some_table | ||
WHERE contains("col_1", ?)`, | ||
Parameters: ["some_param"], | ||
}; | ||
const inputKeyNodes = [{ key: "Parameters" }]; | ||
const output = { | ||
Statement: input.Statement, | ||
Parameters: [{ S: "some_param" }], | ||
}; | ||
expect(marshallInput(input, inputKeyNodes)).toEqual(output); | ||
}); | ||
it("marshals BatchExecuteStatementCommand input", () => { | ||
const input = { | ||
Statements: [ | ||
{ | ||
Statement: ` | ||
UPDATE "table" | ||
SET field1=? | ||
WHERE field2 = ? | ||
AND field3 = ? | ||
`, | ||
Parameters: [false, "field 2 value", 1234], | ||
}, | ||
], | ||
}; | ||
const inputKeyNodes = [{ key: "Statements", children: [{ key: "Parameters" }] }]; | ||
const output = { | ||
Statements: [ | ||
{ | ||
Statement: input.Statements[0].Statement, | ||
Parameters: [ | ||
{ | ||
BOOL: false, | ||
}, | ||
{ S: "field 2 value" }, | ||
{ N: "1234" }, | ||
], | ||
}, | ||
], | ||
}; | ||
expect(marshallInput(input, inputKeyNodes)).toEqual(output); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { convertToAttr } from "./convertToAttr"; | ||
import { marshall } from "./marshall"; | ||
|
||
describe("marshall type discernment", () => { | ||
describe("behaves as convertToAttr for non-collection values or Sets", () => { | ||
it("marshals string", () => { | ||
const value = "hello"; | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
|
||
it("marshals number", () => { | ||
const value = 1578; | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
|
||
it("marshals binary", () => { | ||
const value = new Uint8Array([0, 1, 0, 1]); | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
|
||
it("marshals boolean", () => { | ||
let value = false; | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
value = true; | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
|
||
it("marshals null", () => { | ||
const value = null; | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
it("marshals string set", () => { | ||
const value = new Set(["a", "b"]); | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
|
||
it("marshals number set", () => { | ||
const value = new Set([1, 2]); | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
|
||
it("marshals binary set", () => { | ||
const value = new Set([new Uint8Array([1, 0]), new Uint8Array([0, 1])]); | ||
expect(marshall(value)).toEqual(convertToAttr(value)); | ||
}); | ||
}); | ||
|
||
describe("unwraps one level for input data which are lists or maps", () => { | ||
it("marshals and unwraps map", () => { | ||
expect(marshall({ a: 1, b: { a: 2, b: [1, 2, 3] } })).toEqual({ | ||
a: { N: "1" }, | ||
b: { | ||
M: { | ||
a: { N: "2" }, | ||
b: { | ||
L: [{ N: "1" }, { N: "2" }, { N: "3" }], | ||
}, | ||
}, | ||
}, | ||
}); | ||
}); | ||
|
||
it("marshals and unwraps list", () => { | ||
expect(marshall(["test", 2, null])).toEqual([{ S: "test" }, { N: "2" }, { NULL: true }]); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.