in packages/dynamodb-data-marshaller/src/unmarshallItem.ts [50:124]
function unmarshallValue(schemaType: SchemaType, input: AttributeValue): any {
switch (schemaType.type) {
case 'Any':
case 'Collection':
case 'Hash':
const {
onEmpty = 'leave',
onInvalid = 'throw',
unwrapNumbers = false,
} = schemaType;
const autoMarshaller = new Marshaller({onEmpty, onInvalid, unwrapNumbers});
return autoMarshaller.unmarshallValue(input);
case 'Binary':
if (input.NULL) {
return new Uint8Array(0);
}
return input.B;
case 'Boolean':
return input.BOOL;
case 'Custom':
return schemaType.unmarshall(input);
case 'Date':
return input.N ? new Date(Number(input.N) * 1000) : undefined;
case 'Document':
return input.M
? unmarshallItem(
schemaType.members,
input.M,
schemaType.valueConstructor
) : undefined;
case 'List':
return input.L ? unmarshallList(schemaType, input.L) : undefined;
case 'Map':
return input.M ? unmarshallMap(schemaType, input.M) : undefined;
case 'Null':
return input.NULL ? null : undefined;
case 'Number':
return typeof input.N === 'string' ? Number(input.N) : undefined;
case 'Set':
switch (schemaType.memberType) {
case 'Binary':
if (input.NULL) {
return new BinarySet();
}
return typeof input.BS !== 'undefined'
? new BinarySet(input.BS as Array<Uint8Array>)
: undefined;
case 'Number':
if (input.NULL) {
return new Set<number>();
}
return input.NS ? unmarshallNumberSet(input.NS) : undefined;
case 'String':
if (input.NULL) {
return new Set<string>();
}
return input.SS ? unmarshallStringSet(input.SS) : undefined;
default:
throw new InvalidSchemaError(
schemaType,
`Unrecognized set member type: ${schemaType.memberType}`
);
}
case 'String':
return input.NULL ? '' : input.S;
case 'Tuple':
return input.L ? unmarshallTuple(schemaType, input.L) : undefined;
}
throw new InvalidSchemaError(schemaType, 'Unrecognized schema node');
}