-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.min.js
More file actions
1 lines (1 loc) · 2 KB
/
index.min.js
File metadata and controls
1 lines (1 loc) · 2 KB
1
const utf8=require("utf8"),Decimal=require("decimal.js"),{marshall:e}=require("@aws-sdk/util-dynamodb"),NESTED_OVERHEAD=1,MAP_LIST_OVERHEAD=3;function sizeInBytes(e){if(!e)return 0;var r=0;return Object.keys(e).forEach(t=>{e.hasOwnProperty(t)&&(r+=utf8.encode(t).length,r+=attributeSizeBytes(e[t]))}),r}function attributeSizeBytes(e){if(!e)return 0;if(e.hasOwnProperty("S"))return utf8.encode(e.S).length;if(e.hasOwnProperty("N"))return numberSizeBytes(e.N);if(e.hasOwnProperty("B"))return atob(e.B).length;if(e.hasOwnProperty("BOOL")||e.hasOwnProperty("NULL"))return 1;if(e.hasOwnProperty("SS")){for(var r=0,t=0;t<e.SS.length;t++)r+=utf8.encode(e.SS[t]).length;return r}if(e.hasOwnProperty("NS")){for(var r=0,t=0;t<e.NS.length;t++)r+=numberSizeBytes(e.NS[t]);return r}if(e.hasOwnProperty("BS")){for(var r=0,t=0;t<e.BS.length;t++)r+=atob(e.BS[t]).length;return r}if(e.hasOwnProperty("M")){var r=3;return Object.keys(e.M).forEach(t=>{e.M.hasOwnProperty(t)&&(r+=utf8.encode(t).length,r+=attributeSizeBytes(e.M[t]),r+=1)}),r}if(e.hasOwnProperty("L")){for(var r=3,t=0;t<e.L.length;t++)r+=attributeSizeBytes(e.L[t]),r+=1;return r}throw"Unknown data type: Ensure your are using the correct JSON type (DDB JSON/Native JSON)!"}function numberSizeBytes(e){var r=new Decimal(e);if(0==r)return 1;var t=r.toFixed(),n=measure(t.replace("-",""))+1;return t.startsWith("-")&&n++,n>21&&(n=21),n}function measure(e){if(-1!==e.indexOf(".")){var r=e.split("."),t=r[0],n=r[1];return"0"===t&&(t="",n=zeros(n,!0)),t.length%2!=0&&(t="Z"+t),n.length%2!=0&&(n+="Z"),measure(t+n)}return Math.ceil((e=zeros(e,!0,!0)).length/2)}function zeros(e,r,t){for(;r;){var n=e.replace(/^(0{2})/,"");if(n.length==e.length)break;e=n}for(;t;){var n=e.replace(/(0{2})$/,"");if(n.length==e.length)break;e=n}return e}exports.CalculateSize=(r,t)=>{if(t)try{r=e(r)}catch(n){throw n}var i=sizeInBytes(r),a=Math.ceil(i/4096),u=Math.ceil(i/1024);let s={rcu:a,wcu:u,size:i};return s},exports.IsUnderLimit=(r,t)=>{if(t)try{r=e(r)}catch(n){throw n}let i=this.CalculateSize(r);return i.size<4e5};