@ethersphere/bee-js 9.1.2 → 9.2.1
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/README.md +3 -0
- package/dist/cjs/bee.js +18 -1
- package/dist/cjs/utils/size.js +6 -0
- package/dist/cjs/utils/stamps.js +33 -33
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +18 -1
- package/dist/mjs/utils/size.js +6 -0
- package/dist/mjs/utils/stamps.js +16 -22
- package/dist/types/bee.d.ts +13 -0
- package/dist/types/utils/size.d.ts +2 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -348,6 +348,9 @@ const bee = new Bee('http://localhost:1633', {
|
|
|
348
348
|
Stay up to date by joining the [official Discord](https://discord.gg/GU22h2utj6) and by keeping an eye on the
|
|
349
349
|
[releases tab](https://github.com/ethersphere/bee-js/releases).
|
|
350
350
|
|
|
351
|
+
We are using [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for our commit messages and pull
|
|
352
|
+
requests, following the [Semantic Versioning](https://semver.org/) rules.
|
|
353
|
+
|
|
351
354
|
There are some ways you can make this module better:
|
|
352
355
|
|
|
353
356
|
- Consult our [open issues](https://github.com/ethersphere/bee-js/issues) and take on one of them
|
package/dist/cjs/bee.js
CHANGED
|
@@ -1283,14 +1283,31 @@ class Bee {
|
|
|
1283
1283
|
*
|
|
1284
1284
|
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1285
1285
|
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1286
|
+
* @deprecated Use `getPostageBatches` instead
|
|
1286
1287
|
*/
|
|
1287
1288
|
async getAllPostageBatch(options) {
|
|
1288
|
-
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1289
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
|
|
1289
1290
|
}
|
|
1290
1291
|
/**
|
|
1291
1292
|
* Return all globally available postage batches.
|
|
1293
|
+
* @deprecated Use `getGlobalPostageBatches` instead
|
|
1292
1294
|
*/
|
|
1293
1295
|
async getAllGlobalPostageBatch(options) {
|
|
1296
|
+
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options)); // TODO: remove in June 2025
|
|
1297
|
+
}
|
|
1298
|
+
/**
|
|
1299
|
+
* Return all postage batches that belong to the node.
|
|
1300
|
+
*
|
|
1301
|
+
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
|
|
1302
|
+
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps/get)
|
|
1303
|
+
*/
|
|
1304
|
+
async getPostageBatches(options) {
|
|
1305
|
+
return stamps.getAllPostageBatches(this.getRequestOptionsForCall(options));
|
|
1306
|
+
}
|
|
1307
|
+
/**
|
|
1308
|
+
* Return all globally available postage batches.
|
|
1309
|
+
*/
|
|
1310
|
+
async getGlobalPostageBatches(options) {
|
|
1294
1311
|
return stamps.getGlobalPostageBatches(this.getRequestOptionsForCall(options));
|
|
1295
1312
|
}
|
|
1296
1313
|
/**
|
package/dist/cjs/utils/size.js
CHANGED
|
@@ -19,6 +19,12 @@ class Size {
|
|
|
19
19
|
static fromBytes(bytes) {
|
|
20
20
|
return new Size(bytes);
|
|
21
21
|
}
|
|
22
|
+
static fromKilobytes(kilobytes) {
|
|
23
|
+
return new Size(kilobytes * 1000);
|
|
24
|
+
}
|
|
25
|
+
static fromMegabytes(megabytes) {
|
|
26
|
+
return new Size(megabytes * 1000 * 1000);
|
|
27
|
+
}
|
|
22
28
|
static fromGigabytes(gigabytes) {
|
|
23
29
|
return new Size(gigabytes * 1000 * 1000 * 1000);
|
|
24
30
|
}
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -6,6 +6,7 @@ const bytes_1 = require("./bytes");
|
|
|
6
6
|
const duration_1 = require("./duration");
|
|
7
7
|
const tokens_1 = require("./tokens");
|
|
8
8
|
const type_1 = require("./type");
|
|
9
|
+
const MAX_UTILIZATION = 0.9;
|
|
9
10
|
/**
|
|
10
11
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
11
12
|
*
|
|
@@ -30,35 +31,27 @@ function getStampTheoreticalBytes(depth) {
|
|
|
30
31
|
exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
|
|
31
32
|
/**
|
|
32
33
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
34
|
+
* Optimised for encrypted, medium erasure coding
|
|
33
35
|
*/
|
|
34
|
-
const utilisationRateMap = {
|
|
35
|
-
22: 0.2867,
|
|
36
|
-
23: 0.4956,
|
|
37
|
-
24: 0.6433,
|
|
38
|
-
25: 0.7478,
|
|
39
|
-
26: 0.8217,
|
|
40
|
-
27: 0.8739,
|
|
41
|
-
28: 0.9108,
|
|
42
|
-
29: 0.9369,
|
|
43
|
-
30: 0.9554,
|
|
44
|
-
31: 0.9685,
|
|
45
|
-
32: 0.9777,
|
|
46
|
-
33: 0.9842,
|
|
47
|
-
34: 0.9889,
|
|
48
|
-
};
|
|
49
36
|
const effectiveSizeBreakpoints = [
|
|
50
|
-
[
|
|
51
|
-
[
|
|
52
|
-
[
|
|
53
|
-
[
|
|
54
|
-
[
|
|
55
|
-
[
|
|
56
|
-
[
|
|
57
|
-
[
|
|
58
|
-
[
|
|
59
|
-
[
|
|
60
|
-
[
|
|
61
|
-
[
|
|
37
|
+
[17, 0.00004089],
|
|
38
|
+
[18, 0.00609],
|
|
39
|
+
[19, 0.10249],
|
|
40
|
+
[20, 0.62891],
|
|
41
|
+
[21, 2.38],
|
|
42
|
+
[22, 7.07],
|
|
43
|
+
[23, 18.24],
|
|
44
|
+
[24, 43.04],
|
|
45
|
+
[25, 96.5],
|
|
46
|
+
[26, 208.52],
|
|
47
|
+
[27, 435.98],
|
|
48
|
+
[28, 908.81],
|
|
49
|
+
[29, 1870],
|
|
50
|
+
[30, 3810],
|
|
51
|
+
[31, 7730],
|
|
52
|
+
[32, 15610],
|
|
53
|
+
[33, 31430],
|
|
54
|
+
[34, 63150],
|
|
62
55
|
];
|
|
63
56
|
/**
|
|
64
57
|
* Utility function that calculates the effective size of a postage batch based on its depth.
|
|
@@ -69,16 +62,23 @@ const effectiveSizeBreakpoints = [
|
|
|
69
62
|
* @returns {number} The effective size of the postage batch in bytes.
|
|
70
63
|
*/
|
|
71
64
|
function getStampEffectiveBytes(depth) {
|
|
72
|
-
if (depth <
|
|
65
|
+
if (depth < 17) {
|
|
73
66
|
return 0;
|
|
74
67
|
}
|
|
75
|
-
const
|
|
76
|
-
|
|
68
|
+
const breakpoint = effectiveSizeBreakpoints.find(([d, size]) => {
|
|
69
|
+
if (depth === d) {
|
|
70
|
+
return size;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
if (breakpoint) {
|
|
74
|
+
return breakpoint[1] * 1000 * 1000 * 1000;
|
|
75
|
+
}
|
|
76
|
+
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
77
77
|
}
|
|
78
78
|
exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
79
79
|
function getStampEffectiveBytesBreakpoints() {
|
|
80
80
|
const map = new Map();
|
|
81
|
-
for (let i =
|
|
81
|
+
for (let i = 17; i < 35; i++) {
|
|
82
82
|
map.set(i, getStampEffectiveBytes(i));
|
|
83
83
|
}
|
|
84
84
|
return map;
|
|
@@ -122,11 +122,11 @@ exports.getAmountForDuration = getAmountForDuration;
|
|
|
122
122
|
*/
|
|
123
123
|
function getDepthForSize(size) {
|
|
124
124
|
for (const [depth, sizeBreakpoint] of effectiveSizeBreakpoints) {
|
|
125
|
-
if (size.
|
|
125
|
+
if (size.toBytes() <= sizeBreakpoint * 1000 * 1000 * 1000) {
|
|
126
126
|
return depth;
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
|
-
return
|
|
129
|
+
return 35;
|
|
130
130
|
}
|
|
131
131
|
exports.getDepthForSize = getDepthForSize;
|
|
132
132
|
function convertEnvelopeToMarshaledStamp(envelope) {
|