Skip to content
This repository was archived by the owner on Jun 19, 2023. It is now read-only.

Commit 9a548f3

Browse files
brandonljeskew
authored andcommitted
Updated unmarshall for schema type of [any, hash, collection] to consider any provided MarshallingOptions (#119)
1 parent 7da6b78 commit 9a548f3

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

packages/dynamodb-data-marshaller/src/unmarshallItem.spec.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,40 @@ describe('unmarshallItem', () => {
8989
],
9090
});
9191
});
92+
93+
it('should marshall of untyped data, considering provided marshalling options', () => {
94+
const schema: Schema = {
95+
mixedList: {
96+
type: 'Any',
97+
unwrapNumbers: true
98+
}
99+
};
100+
const input = {
101+
mixedList: {
102+
L: [
103+
{S: 'string'},
104+
{N: '123'},
105+
{B: new ArrayBuffer(12)},
106+
{M: {foo: {S: 'bar'}}},
107+
{L: [
108+
{S: 'one string'},
109+
{N: '234'},
110+
{B: new ArrayBuffer(5)},
111+
]},
112+
],
113+
}
114+
};
115+
116+
expect(unmarshallItem(schema, input)).toEqual({
117+
mixedList: [
118+
'string',
119+
123,
120+
new ArrayBuffer(12),
121+
{foo: 'bar'},
122+
['one string', 234, new ArrayBuffer(5)],
123+
],
124+
});
125+
});
92126
});
93127

94128
describe('binary set fields', () => {

packages/dynamodb-data-marshaller/src/unmarshallItem.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ function unmarshallValue(schemaType: SchemaType, input: AttributeValue): any {
5252
case 'Any':
5353
case 'Collection':
5454
case 'Hash':
55-
const autoMarshaller = new Marshaller();
55+
const {
56+
onEmpty = 'leave',
57+
onInvalid = 'throw',
58+
unwrapNumbers = false,
59+
} = schemaType;
60+
const autoMarshaller = new Marshaller({onEmpty, onInvalid, unwrapNumbers});
5661
return autoMarshaller.unmarshallValue(input);
5762
case 'Binary':
5863
if (input.NULL) {

0 commit comments

Comments
 (0)