mcwhittemore / dyno-item-size

A simple node utility to calculate the size of a item as DynamoDB does.
14 stars 4 forks source link

Erorr calculating size of objects with objects as properties #4

Closed mjmarianetti closed 6 years ago

mjmarianetti commented 7 years ago

Hi, I am trying to use this package with the following item structure:

var item = { // properties, subitems: { id1: { // properties }, id2: { // properties } } }

it is returning NaN for size, read and write. I guess it have a problem with this type of object

mcwhittemore commented 7 years ago

@mjmarianetti - this doesn't currently handle objects as values. I'm not 100% sure how DynamoDB calculates the size in this situation, but I think we should figure this out and get it added. Have you solved this yourself? Would you be up to making a PR to fix this?

mjmarianetti commented 7 years ago

@mcwhittemore I solved it doing JSON.stringify in the element. I tried converting it to an array and it ouputs the same size.

let element = JSON.stringify(item); dynoItemSize(element).

If you can confirm that this is the way it has to be done, I'll do it.

mcwhittemore commented 7 years ago

The AWSSDK converts { name: 'newcastle', score: '10' } into { M: { name: { S: 'newcastle' }, score: { S: '10' } } } so the base of figuing out the size of an object is to call dynoItemSize when an object is found. That said, I'd guess the size cost of an object is more than the sum of its parts. I've yet to find documentation that explains this.

mcwhittemore commented 6 years ago

This should be fixed now and part of 0.3.0 on npm.