@ethersphere/bee-js 9.8.0 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/bee.js +819 -364
- package/dist/cjs/manifest/manifest.js +6 -3
- package/dist/cjs/modules/debug/chequebook.js +1 -1
- package/dist/cjs/types/index.js +285 -4
- package/dist/cjs/utils/bytes.js +19 -1
- package/dist/cjs/utils/duration.js +6 -2
- package/dist/cjs/utils/stamps.js +36 -13
- package/dist/cjs/utils/type.js +2 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +818 -364
- package/dist/mjs/manifest/manifest.js +6 -3
- package/dist/mjs/modules/debug/chequebook.js +2 -2
- package/dist/mjs/types/index.js +1275 -4
- package/dist/mjs/utils/bytes.js +17 -0
- package/dist/mjs/utils/duration.js +7 -3
- package/dist/mjs/utils/stamps.js +35 -14
- package/dist/mjs/utils/type.js +6 -0
- package/dist/types/bee.d.ts +701 -249
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +108 -6
- package/dist/types/utils/bytes.d.ts +1 -0
- package/dist/types/utils/duration.d.ts +2 -0
- package/dist/types/utils/stamps.d.ts +4 -4
- package/package.json +1 -1
package/dist/mjs/utils/bytes.js
CHANGED
|
@@ -67,4 +67,21 @@ export class Bytes {
|
|
|
67
67
|
represent() {
|
|
68
68
|
return this.toHex();
|
|
69
69
|
}
|
|
70
|
+
}
|
|
71
|
+
export function parseSizeToBytes(sizeStr) {
|
|
72
|
+
const units = {
|
|
73
|
+
B: 1,
|
|
74
|
+
kB: 1000,
|
|
75
|
+
MB: 1000 ** 2,
|
|
76
|
+
GB: 1000 ** 3,
|
|
77
|
+
TB: 1000 ** 4,
|
|
78
|
+
PB: 1000 ** 5
|
|
79
|
+
};
|
|
80
|
+
const match = sizeStr.match(/^([\d.]+)\s*(B|kB|MB|GB|TB|PB)$/);
|
|
81
|
+
if (!match) {
|
|
82
|
+
throw new Error(`Invalid size format: ${sizeStr}`);
|
|
83
|
+
}
|
|
84
|
+
const value = parseFloat(match[1]);
|
|
85
|
+
const unit = match[2];
|
|
86
|
+
return Math.ceil(value * units[unit]);
|
|
70
87
|
}
|
|
@@ -2,8 +2,8 @@ import { Dates } from 'cafe-utility';
|
|
|
2
2
|
export class Duration {
|
|
3
3
|
constructor(seconds) {
|
|
4
4
|
this.seconds = Math.ceil(seconds);
|
|
5
|
-
if (seconds
|
|
6
|
-
|
|
5
|
+
if (seconds < 0) {
|
|
6
|
+
this.seconds = 0;
|
|
7
7
|
}
|
|
8
8
|
}
|
|
9
9
|
static fromMilliseconds(milliseconds) {
|
|
@@ -48,4 +48,8 @@ export class Duration {
|
|
|
48
48
|
represent() {
|
|
49
49
|
return Dates.secondsToHumanTime(this.seconds);
|
|
50
50
|
}
|
|
51
|
-
|
|
51
|
+
isZero() {
|
|
52
|
+
return this.seconds === 0;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
Duration.ZERO = new Duration(0);
|
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Binary } from 'cafe-utility';
|
|
2
|
-
import {
|
|
2
|
+
import { capacityBreakpoints } from "../types/index.js";
|
|
3
|
+
import { Bytes, parseSizeToBytes } from "./bytes.js";
|
|
3
4
|
import { Duration } from "./duration.js";
|
|
4
5
|
import { BZZ } from "./tokens.js";
|
|
5
6
|
import { asNumberString } from "./type.js";
|
|
@@ -37,24 +38,33 @@ const effectiveSizeBreakpoints = [[17, 0.00004089], [18, 0.00609], [19, 0.10249]
|
|
|
37
38
|
*
|
|
38
39
|
* @returns {number} The effective size of the postage batch in bytes.
|
|
39
40
|
*/
|
|
40
|
-
export function getStampEffectiveBytes(depth) {
|
|
41
|
+
export function getStampEffectiveBytes(depth, encryption, erasureCodeLevel) {
|
|
41
42
|
if (depth < 17) {
|
|
42
43
|
return 0;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
45
|
+
if (encryption !== undefined && erasureCodeLevel !== undefined) {
|
|
46
|
+
const encryptionKey = encryption ? 'ENCRYPTION_ON' : 'ENCRYPTION_OFF';
|
|
47
|
+
const breakpoints = capacityBreakpoints[encryptionKey][erasureCodeLevel];
|
|
48
|
+
const entry = breakpoints.find(item => item.batchDepth === depth);
|
|
49
|
+
if (entry?.effectiveVolume) {
|
|
50
|
+
return parseSizeToBytes(entry.effectiveVolume);
|
|
51
|
+
}
|
|
52
|
+
} else {
|
|
53
|
+
const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
|
|
54
|
+
if (depth === d) {
|
|
55
|
+
return size;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
if (breakpoint) {
|
|
59
|
+
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
47
60
|
}
|
|
48
|
-
});
|
|
49
|
-
if (breakpoint) {
|
|
50
|
-
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
51
61
|
}
|
|
52
62
|
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
53
63
|
}
|
|
54
|
-
export function getStampEffectiveBytesBreakpoints() {
|
|
64
|
+
export function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
|
|
55
65
|
const map = new Map();
|
|
56
66
|
for (let i = 17; i < 35; i++) {
|
|
57
|
-
map.set(i, getStampEffectiveBytes(i));
|
|
67
|
+
map.set(i, getStampEffectiveBytes(i, encryption, erasureCodeLevel));
|
|
58
68
|
}
|
|
59
69
|
return map;
|
|
60
70
|
}
|
|
@@ -91,10 +101,21 @@ export function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
|
91
101
|
* @param size The effective size of the postage batch
|
|
92
102
|
* @returns
|
|
93
103
|
*/
|
|
94
|
-
export function getDepthForSize(size) {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
104
|
+
export function getDepthForSize(size, encryption, erasureCodeLevel) {
|
|
105
|
+
if (encryption !== undefined && erasureCodeLevel !== undefined) {
|
|
106
|
+
const encryptionKey = encryption ? 'ENCRYPTION_ON' : 'ENCRYPTION_OFF';
|
|
107
|
+
const breakpoints = capacityBreakpoints[encryptionKey][erasureCodeLevel];
|
|
108
|
+
const entry = breakpoints.find(item => {
|
|
109
|
+
return size.toBytes() <= parseSizeToBytes(item.effectiveVolume);
|
|
110
|
+
});
|
|
111
|
+
if (entry?.effectiveVolume) {
|
|
112
|
+
return entry.batchDepth;
|
|
113
|
+
}
|
|
114
|
+
} else {
|
|
115
|
+
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
116
|
+
if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
|
|
117
|
+
return depth;
|
|
118
|
+
}
|
|
98
119
|
}
|
|
99
120
|
}
|
|
100
121
|
return 35;
|
package/dist/mjs/utils/type.js
CHANGED
|
@@ -158,6 +158,9 @@ export function preparePssMessageHandler(value) {
|
|
|
158
158
|
}),
|
|
159
159
|
onError: Types.asFunction(object.onError, {
|
|
160
160
|
name: 'onError'
|
|
161
|
+
}),
|
|
162
|
+
onClose: Types.asFunction(object.onClose, {
|
|
163
|
+
name: 'onClose'
|
|
161
164
|
})
|
|
162
165
|
};
|
|
163
166
|
}
|
|
@@ -171,6 +174,9 @@ export function prepareGsocMessageHandler(value) {
|
|
|
171
174
|
}),
|
|
172
175
|
onError: Types.asFunction(object.onError, {
|
|
173
176
|
name: 'onError'
|
|
177
|
+
}),
|
|
178
|
+
onClose: Types.asFunction(object.onClose, {
|
|
179
|
+
name: 'onClose'
|
|
174
180
|
})
|
|
175
181
|
};
|
|
176
182
|
}
|