@@ -9,79 +9,110 @@ function consolidateDataMetrics(target, source) {
99 if ( ! resTarget . usedCapacity ) {
1010 Object . assign ( resTarget , {
1111 usedCapacity : {
12- current : 0 ,
13- nonCurrent : 0 ,
14- _currentCold : 0 ,
15- _nonCurrentCold : 0 ,
16- _currentRestored : 0 ,
17- _currentRestoring : 0 ,
18- _nonCurrentRestored : 0 ,
19- _nonCurrentRestoring : 0 ,
20- _inflightsPreScan : 0 ,
21- _incompleteMPUParts : 0 ,
12+ current : 0n ,
13+ nonCurrent : 0n ,
14+ _currentCold : 0n ,
15+ _nonCurrentCold : 0n ,
16+ _currentRestored : 0n ,
17+ _currentRestoring : 0n ,
18+ _nonCurrentRestored : 0n ,
19+ _nonCurrentRestoring : 0n ,
20+ _inflightsPreScan : 0n ,
21+ _incompleteMPUParts : 0n ,
2222 } ,
2323 } ) ;
2424 }
2525 if ( ! resTarget . objectCount ) {
2626 Object . assign ( resTarget , {
2727 objectCount : {
28- current : 0 ,
29- nonCurrent : 0 ,
30- _currentCold : 0 ,
31- _nonCurrentCold : 0 ,
32- _currentRestored : 0 ,
33- _currentRestoring : 0 ,
34- _nonCurrentRestored : 0 ,
35- _nonCurrentRestoring : 0 ,
36- _incompleteMPUUploads : 0 ,
37- deleteMarker : 0 ,
28+ current : 0n ,
29+ nonCurrent : 0n ,
30+ _currentCold : 0n ,
31+ _nonCurrentCold : 0n ,
32+ _currentRestored : 0n ,
33+ _currentRestoring : 0n ,
34+ _nonCurrentRestored : 0n ,
35+ _nonCurrentRestoring : 0n ,
36+ _incompleteMPUUploads : 0n ,
37+ deleteMarker : 0n ,
3838 } ,
3939 } ) ;
4040 }
4141 if ( ! source ) {
4242 return resTarget ;
4343 }
4444 const { usedCapacity, objectCount, accountOwnerID } = source ;
45- resTarget . usedCapacity . current += usedCapacity && usedCapacity . current ? usedCapacity . current : 0 ;
46- resTarget . usedCapacity . nonCurrent += usedCapacity && usedCapacity . nonCurrent ? usedCapacity . nonCurrent : 0 ;
47- resTarget . usedCapacity . _currentCold += usedCapacity && usedCapacity . _currentCold ? usedCapacity . _currentCold : 0 ;
48- resTarget . usedCapacity . _nonCurrentCold += usedCapacity && usedCapacity . _nonCurrentCold ? usedCapacity . _nonCurrentCold : 0 ;
49- resTarget . usedCapacity . _currentRestoring += usedCapacity && usedCapacity . _currentRestoring ? usedCapacity . _currentRestoring : 0 ;
50- resTarget . usedCapacity . _currentRestored += usedCapacity && usedCapacity . _currentRestored ? usedCapacity . _currentRestored : 0 ;
51- resTarget . usedCapacity . _nonCurrentRestoring += usedCapacity && usedCapacity . _nonCurrentRestoring ? usedCapacity . _nonCurrentRestoring : 0 ;
52- resTarget . usedCapacity . _nonCurrentRestored += usedCapacity && usedCapacity . _nonCurrentRestored ? usedCapacity . _nonCurrentRestored : 0 ;
53- resTarget . usedCapacity . _incompleteMPUParts += usedCapacity && usedCapacity . _incompleteMPUParts ? usedCapacity . _incompleteMPUParts : 0 ;
45+ resTarget . usedCapacity . current += BigInt ( usedCapacity ? .current || 0n ) ;
46+ resTarget . usedCapacity . nonCurrent += BigInt ( usedCapacity ? .nonCurrent || 0n ) ;
47+ resTarget . usedCapacity . _currentCold += BigInt ( usedCapacity ? ._currentCold || 0n ) ;
48+ resTarget . usedCapacity . _nonCurrentCold += BigInt ( usedCapacity ? ._nonCurrentCold || 0n ) ;
49+ resTarget . usedCapacity . _currentRestoring += BigInt ( usedCapacity ? ._currentRestoring || 0n ) ;
50+ resTarget . usedCapacity . _currentRestored += BigInt ( usedCapacity ? ._currentRestored || 0n ) ;
51+ resTarget . usedCapacity . _nonCurrentRestoring += BigInt ( usedCapacity ? ._nonCurrentRestoring || 0n ) ;
52+ resTarget . usedCapacity . _nonCurrentRestored += BigInt ( usedCapacity ? ._nonCurrentRestored || 0n ) ;
53+ resTarget . usedCapacity . _incompleteMPUParts += BigInt ( usedCapacity ? ._incompleteMPUParts || 0n ) ;
5454
55- resTarget . objectCount . current += objectCount && objectCount . current ? objectCount . current : 0 ;
56- resTarget . objectCount . nonCurrent += objectCount && objectCount . nonCurrent ? objectCount . nonCurrent : 0 ;
57- resTarget . objectCount . deleteMarker += objectCount && objectCount . deleteMarker ? objectCount . deleteMarker : 0 ;
58- resTarget . objectCount . _currentCold += objectCount && objectCount . _currentCold ? objectCount . _currentCold : 0 ;
59- resTarget . objectCount . _nonCurrentCold += objectCount && objectCount . _nonCurrentCold ? objectCount . _nonCurrentCold : 0 ;
60- resTarget . objectCount . _currentRestoring += objectCount && objectCount . _currentRestoring ? objectCount . _currentRestoring : 0 ;
61- resTarget . objectCount . _currentRestored += objectCount && objectCount . _currentRestored ? objectCount . _currentRestored : 0 ;
62- resTarget . objectCount . _nonCurrentRestoring += objectCount && objectCount . _nonCurrentRestoring ? objectCount . _nonCurrentRestoring : 0 ;
63- resTarget . objectCount . _nonCurrentRestored += objectCount && objectCount . _nonCurrentRestored ? objectCount . _nonCurrentRestored : 0 ;
64- resTarget . objectCount . _incompleteMPUUploads += objectCount && objectCount . _incompleteMPUUploads ? objectCount . _incompleteMPUUploads : 0 ;
55+ resTarget . objectCount . current += BigInt ( objectCount ? .current || 0n ) ;
56+ resTarget . objectCount . nonCurrent += BigInt ( objectCount ? .nonCurrent || 0n ) ;
57+ resTarget . objectCount . deleteMarker += BigInt ( objectCount ? .deleteMarker || 0n ) ;
58+ resTarget . objectCount . _currentCold += BigInt ( objectCount ? ._currentCold || 0n ) ;
59+ resTarget . objectCount . _nonCurrentCold += BigInt ( objectCount ? ._nonCurrentCold || 0n ) ;
60+ resTarget . objectCount . _currentRestoring += BigInt ( objectCount ? ._currentRestoring || 0n ) ;
61+ resTarget . objectCount . _currentRestored += BigInt ( objectCount ? ._currentRestored || 0n ) ;
62+ resTarget . objectCount . _nonCurrentRestoring += BigInt ( objectCount ? ._nonCurrentRestoring || 0n ) ;
63+ resTarget . objectCount . _nonCurrentRestored += BigInt ( objectCount ? ._nonCurrentRestored || 0n ) ;
64+ resTarget . objectCount . _incompleteMPUUploads += BigInt ( objectCount ? ._incompleteMPUUploads || 0n ) ;
6565
66- resTarget . usedCapacity . _inflightsPreScan += usedCapacity && usedCapacity . _inflightsPreScan ? usedCapacity . _inflightsPreScan : 0 ;
66+ resTarget . usedCapacity . _inflightsPreScan += BigInt ( usedCapacity ? ._inflightsPreScan || 0n ) ;
6767 if ( accountOwnerID ) {
6868 resTarget . accountOwnerID = accountOwnerID ;
6969 }
7070
7171 resTarget . usedCapacity . current += usedCapacity
72- ? usedCapacity . _currentCold + usedCapacity . _currentRestored + usedCapacity . _currentRestoring
73- + usedCapacity . _incompleteMPUParts : 0 ;
72+ ? BigInt ( usedCapacity . _currentCold ) + BigInt ( usedCapacity . _currentRestored ) + BigInt ( usedCapacity . _currentRestoring )
73+ + BigInt ( usedCapacity . _incompleteMPUParts ) : 0n ;
7474 resTarget . usedCapacity . nonCurrent += usedCapacity
75- ? usedCapacity . _nonCurrentCold + usedCapacity . _nonCurrentRestored + usedCapacity . _nonCurrentRestoring : 0 ;
75+ ? BigInt ( usedCapacity . _nonCurrentCold ) + BigInt ( usedCapacity . _nonCurrentRestored ) + BigInt ( usedCapacity . _nonCurrentRestoring ) : 0n ;
7676 resTarget . objectCount . current += objectCount
77- ? objectCount . _currentCold + objectCount . _currentRestored + objectCount . _currentRestoring
78- + objectCount . _incompleteMPUUploads : 0 ;
77+ ? BigInt ( objectCount . _currentCold ) + BigInt ( objectCount . _currentRestored ) + BigInt ( objectCount . _currentRestoring )
78+ + BigInt ( objectCount . _incompleteMPUUploads ) : 0n ;
7979 resTarget . objectCount . nonCurrent += objectCount
80- ? objectCount . _nonCurrentCold + objectCount . _nonCurrentRestored + objectCount . _nonCurrentRestoring : 0 ;
80+ ? BigInt ( objectCount . _nonCurrentCold ) + BigInt ( objectCount . _nonCurrentRestored ) + BigInt ( objectCount . _nonCurrentRestoring ) : 0n ;
8181
8282 return resTarget ;
8383}
8484
85+ function serializeBigInts ( obj ) {
86+ if ( typeof obj !== 'object' || obj === null ) {
87+ return typeof obj === 'bigint' ? { __bigint : obj . toString ( ) } : obj ;
88+ }
89+ const result = Array . isArray ( obj ) ? [ ] : { } ;
90+ for ( const key in obj ) {
91+ if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
92+ result [ key ] = serializeBigInts ( obj [ key ] ) ;
93+ }
94+ }
95+ return result ;
96+ }
97+
98+ function deserializeBigInts ( obj ) {
99+ if ( ! obj || typeof obj !== 'object' ) {
100+ return obj ;
101+ }
102+ if ( obj . __bigint !== undefined ) {
103+ return BigInt ( obj . __bigint ) ;
104+ }
105+ const result = Array . isArray ( obj ) ? [ ] : { } ;
106+ for ( const key in obj ) {
107+ if ( Object . prototype . hasOwnProperty . call ( obj , key ) ) {
108+ result [ key ] = deserializeBigInts ( obj [ key ] ) ;
109+ }
110+ }
111+ return result ;
112+ }
113+
85114module . exports = {
86115 consolidateDataMetrics,
116+ serializeBigInts,
117+ deserializeBigInts,
87118} ;
0 commit comments