Skip to content

Commit

Permalink
fix(validate-types): resolve attr type changed to number when is bigint
Browse files Browse the repository at this point in the history
  • Loading branch information
amccarthy1 committed Oct 5, 2023
1 parent 90f7013 commit d0bb431
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/__tests__/validateTypes.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ describe('validateTypes', () => {
})

it('converts arrays of bigints to sets', async () => {
const result = validateTypes()({ type: 'set', setType: 'bigint' }, 'attr', [
const attr = { type: 'set', setType: 'bigint' }
const result = validateTypes()(attr, 'attr', [
BigInt(-1234),
BigInt('123000000000000000000001')
])
expect(result).toEqual(new Set([
toDynamoBigInt(BigInt(-1234)),
toDynamoBigInt(BigInt('123000000000000000000001'))
]))
// Should not mutate the attribute
expect(attr.setType).toEqual('bigint')
})
})
2 changes: 0 additions & 2 deletions src/lib/validateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ export default () => (mapping: any, field: any, value: any) => {
if (value instanceof Set) {

if (mapping.setType === 'bigint') {
mapping.setType = 'number'
value = Array.from(value).map((n) => toDynamoBigInt(n))
}

Expand All @@ -78,7 +77,6 @@ export default () => (mapping: any, field: any, value: any) => {
const actualSetType = typeOf(value[0])?.toLowerCase?.()

if (mapping.setType === 'bigint') {
mapping.setType = 'number'
value = value.map((n) => toDynamoBigInt(n))
}

Expand Down

0 comments on commit d0bb431

Please sign in to comment.