@ethersphere/bee-js 10.3.0 → 11.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 +17 -10
- package/dist/cjs/chunk/bmt.js +1 -2
- package/dist/cjs/chunk/cac.js +3 -3
- package/dist/cjs/chunk/soc.js +24 -15
- package/dist/cjs/feed/identifier.js +1 -2
- package/dist/cjs/feed/index.js +25 -16
- package/dist/cjs/feed/retrievable.js +1 -2
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/modules/bytes.js +4 -5
- package/dist/cjs/modules/bzz.js +4 -5
- package/dist/cjs/modules/chunk.js +2 -3
- package/dist/cjs/modules/debug/balance.js +4 -5
- package/dist/cjs/modules/debug/chequebook.js +8 -9
- package/dist/cjs/modules/debug/connectivity.js +7 -8
- package/dist/cjs/modules/debug/settlements.js +2 -3
- package/dist/cjs/modules/debug/stake.js +6 -7
- package/dist/cjs/modules/debug/stamps.js +23 -77
- package/dist/cjs/modules/debug/states.js +6 -6
- package/dist/cjs/modules/debug/status.js +9 -9
- package/dist/cjs/modules/debug/transactions.js +4 -5
- package/dist/cjs/modules/envelope.js +1 -2
- package/dist/cjs/modules/feed.js +3 -4
- package/dist/cjs/modules/grantee.js +3 -4
- package/dist/cjs/modules/gsoc.js +2 -3
- package/dist/cjs/modules/pinning.js +4 -5
- package/dist/cjs/modules/pss.js +2 -3
- package/dist/cjs/modules/rchash.js +1 -2
- package/dist/cjs/modules/soc.js +1 -2
- package/dist/cjs/modules/status.js +2 -3
- package/dist/cjs/modules/stewardship.js +2 -3
- package/dist/cjs/modules/tag.js +5 -6
- package/dist/cjs/types/debug.js +3 -3
- package/dist/cjs/types/index.js +2 -2
- package/dist/cjs/utils/bytes.js +2 -2
- package/dist/cjs/utils/chunk-size.js +1 -2
- package/dist/cjs/utils/chunk-stream.browser.js +3 -4
- package/dist/cjs/utils/chunk-stream.js +3 -4
- package/dist/cjs/utils/cid.js +3 -3
- package/dist/cjs/utils/collection.browser.js +2 -3
- package/dist/cjs/utils/collection.js +5 -6
- package/dist/cjs/utils/collection.node.js +2 -3
- package/dist/cjs/utils/data.browser.js +1 -2
- package/dist/cjs/utils/data.js +1 -2
- package/dist/cjs/utils/expose.js +4 -1
- package/dist/cjs/utils/file.js +2 -3
- package/dist/cjs/utils/headers.js +2 -3
- package/dist/cjs/utils/http.js +2 -2
- package/dist/cjs/utils/pss.js +1 -2
- package/dist/cjs/utils/redundancy.js +3 -4
- package/dist/cjs/utils/stamps.js +60 -11
- package/dist/cjs/utils/tar-uploader.browser.js +1 -2
- package/dist/cjs/utils/tar-uploader.js +1 -2
- package/dist/cjs/utils/tar-writer.browser.js +1 -2
- package/dist/cjs/utils/tar-writer.js +1 -2
- package/dist/cjs/utils/type.js +34 -25
- package/dist/cjs/utils/url.js +3 -4
- package/dist/cjs/utils/workaround.js +7 -5
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +0 -3
- package/dist/mjs/modules/debug/stamps.js +37 -110
- package/dist/mjs/modules/debug/states.js +3 -0
- package/dist/mjs/modules/debug/status.js +1 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/stamps.js +48 -0
- package/dist/mjs/utils/workaround.js +5 -2
- package/dist/types/bee.d.ts +0 -4
- package/dist/types/index.d.ts +3 -2
- package/dist/types/modules/bzz.d.ts +0 -1
- package/dist/types/modules/debug/status.d.ts +1 -1
- package/dist/types/modules/gsoc.d.ts +0 -1
- package/dist/types/modules/pss.d.ts +0 -1
- package/dist/types/types/debug.d.ts +1 -0
- package/dist/types/utils/constants.d.ts +3 -3
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/stamps.d.ts +15 -1
- package/dist/types/utils/tar.browser.d.ts +1 -1
- package/dist/types/utils/tar.d.ts +0 -1
- package/dist/types/utils/type.d.ts +0 -1
- package/package.json +9 -12
package/dist/cjs/types/debug.js
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.BeeModes = void 0;
|
|
4
|
+
exports.toBeeMode = toBeeMode;
|
|
4
5
|
var BeeModes;
|
|
5
6
|
(function (BeeModes) {
|
|
6
7
|
BeeModes["FULL"] = "full";
|
|
7
8
|
BeeModes["LIGHT"] = "light";
|
|
8
9
|
BeeModes["ULTRA_LIGHT"] = "ultra-light";
|
|
9
10
|
BeeModes["DEV"] = "dev";
|
|
10
|
-
})(BeeModes
|
|
11
|
+
})(BeeModes || (exports.BeeModes = BeeModes = {}));
|
|
11
12
|
function toBeeMode(value) {
|
|
12
13
|
switch (value) {
|
|
13
14
|
case 'full':
|
|
@@ -22,4 +23,3 @@ function toBeeMode(value) {
|
|
|
22
23
|
throw new Error(`Unknown Bee mode: ${value}`);
|
|
23
24
|
}
|
|
24
25
|
}
|
|
25
|
-
exports.toBeeMode = toBeeMode;
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -47,7 +47,7 @@ var RedundancyLevel;
|
|
|
47
47
|
RedundancyLevel[RedundancyLevel["STRONG"] = 2] = "STRONG";
|
|
48
48
|
RedundancyLevel[RedundancyLevel["INSANE"] = 3] = "INSANE";
|
|
49
49
|
RedundancyLevel[RedundancyLevel["PARANOID"] = 4] = "PARANOID";
|
|
50
|
-
})(RedundancyLevel
|
|
50
|
+
})(RedundancyLevel || (exports.RedundancyLevel = RedundancyLevel = {}));
|
|
51
51
|
/**
|
|
52
52
|
* Specify the retrieve strategy on redundant data.
|
|
53
53
|
* The possible values are NONE, DATA, PROX and RACE.
|
|
@@ -64,7 +64,7 @@ var RedundancyStrategy;
|
|
|
64
64
|
RedundancyStrategy[RedundancyStrategy["DATA"] = 1] = "DATA";
|
|
65
65
|
RedundancyStrategy[RedundancyStrategy["PROX"] = 2] = "PROX";
|
|
66
66
|
RedundancyStrategy[RedundancyStrategy["RACE"] = 3] = "RACE";
|
|
67
|
-
})(RedundancyStrategy
|
|
67
|
+
})(RedundancyStrategy || (exports.RedundancyStrategy = RedundancyStrategy = {}));
|
|
68
68
|
exports.capacityBreakpoints = {
|
|
69
69
|
ENCRYPTION_OFF: {
|
|
70
70
|
[RedundancyLevel.OFF]: [
|
package/dist/cjs/utils/bytes.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.Bytes = void 0;
|
|
7
|
+
exports.parseSizeToBytes = parseSizeToBytes;
|
|
7
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
8
9
|
const debug_1 = __importDefault(require("debug"));
|
|
9
10
|
const debug = (0, debug_1.default)('bee-js:bytes');
|
|
@@ -111,4 +112,3 @@ function parseSizeToBytes(sizeStr) {
|
|
|
111
112
|
const unit = match[2];
|
|
112
113
|
return Math.ceil(value * units[unit]);
|
|
113
114
|
}
|
|
114
|
-
exports.parseSizeToBytes = parseSizeToBytes;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.totalChunks =
|
|
3
|
+
exports.totalChunks = totalChunks;
|
|
4
4
|
function totalChunks(fileSize) {
|
|
5
5
|
const chunkSize = 4096;
|
|
6
6
|
const hashesPerChunk = 128;
|
|
@@ -14,4 +14,3 @@ function totalChunks(fileSize) {
|
|
|
14
14
|
const baseLevelChunks = Math.ceil(fileSize / chunkSize);
|
|
15
15
|
return chunksAtLevel(baseLevelChunks);
|
|
16
16
|
}
|
|
17
|
-
exports.totalChunks = totalChunks;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.hashDirectory = hashDirectory;
|
|
4
|
+
exports.streamDirectory = streamDirectory;
|
|
5
|
+
exports.streamFiles = streamFiles;
|
|
4
6
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
7
|
const __1 = require("..");
|
|
6
8
|
const manifest_1 = require("../manifest/manifest");
|
|
@@ -11,11 +13,9 @@ const typed_bytes_1 = require("./typed-bytes");
|
|
|
11
13
|
async function hashDirectory(_dir) {
|
|
12
14
|
throw new Error('Hashing directories is not supported in browsers!');
|
|
13
15
|
}
|
|
14
|
-
exports.hashDirectory = hashDirectory;
|
|
15
16
|
async function streamDirectory(_bee, _dir, _postageBatchId, _onUploadProgress, _options, _requestOptions) {
|
|
16
17
|
throw new Error('Streaming directories is not supported in browsers!');
|
|
17
18
|
}
|
|
18
|
-
exports.streamDirectory = streamDirectory;
|
|
19
19
|
async function streamFiles(bee, files, postageBatchId, onUploadProgress, options, requestOptions) {
|
|
20
20
|
const queue = new cafe_utility_1.AsyncQueue(64, 64);
|
|
21
21
|
let total = 0;
|
|
@@ -76,7 +76,6 @@ async function streamFiles(bee, files, postageBatchId, onUploadProgress, options
|
|
|
76
76
|
}
|
|
77
77
|
return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
|
|
78
78
|
}
|
|
79
|
-
exports.streamFiles = streamFiles;
|
|
80
79
|
function maybeEnrichMime(mime) {
|
|
81
80
|
if (['text/html', 'text/css'].includes(mime)) {
|
|
82
81
|
return `${mime}; charset=utf-8`;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.hashDirectory = hashDirectory;
|
|
4
|
+
exports.streamDirectory = streamDirectory;
|
|
5
|
+
exports.streamFiles = streamFiles;
|
|
4
6
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
7
|
const fs_1 = require("fs");
|
|
6
8
|
const __1 = require("..");
|
|
@@ -30,7 +32,6 @@ async function hashDirectory(dir) {
|
|
|
30
32
|
}
|
|
31
33
|
return mantaray.calculateSelfAddress();
|
|
32
34
|
}
|
|
33
|
-
exports.hashDirectory = hashDirectory;
|
|
34
35
|
async function streamDirectory(bee, dir, postageBatchId, onUploadProgress, options, requestOptions) {
|
|
35
36
|
const queue = new cafe_utility_1.AsyncQueue(64, 64);
|
|
36
37
|
let total = 0;
|
|
@@ -83,7 +84,6 @@ async function streamDirectory(bee, dir, postageBatchId, onUploadProgress, optio
|
|
|
83
84
|
}
|
|
84
85
|
return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
|
|
85
86
|
}
|
|
86
|
-
exports.streamDirectory = streamDirectory;
|
|
87
87
|
function maybeEnrichMime(mime) {
|
|
88
88
|
if (['text/html', 'text/css'].includes(mime)) {
|
|
89
89
|
return `${mime}; charset=utf-8`;
|
|
@@ -93,4 +93,3 @@ function maybeEnrichMime(mime) {
|
|
|
93
93
|
async function streamFiles(_bee, _files, _postageBatchId, _onUploadProgress, _options, _requestOptions) {
|
|
94
94
|
throw new Error('Streaming files is not supported in Node.js');
|
|
95
95
|
}
|
|
96
|
-
exports.streamFiles = streamFiles;
|
package/dist/cjs/utils/cid.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.SWARM_FEED_CODEC = exports.SWARM_MANIFEST_CODEC = void 0;
|
|
4
|
+
exports.convertReferenceToCid = convertReferenceToCid;
|
|
5
|
+
exports.convertCidToReference = convertCidToReference;
|
|
4
6
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
7
|
const typed_bytes_1 = require("./typed-bytes");
|
|
6
8
|
exports.SWARM_MANIFEST_CODEC = 0xfa;
|
|
@@ -21,7 +23,6 @@ function convertReferenceToCid(reference, type) {
|
|
|
21
23
|
const hash = reference.toBase32().replace(/\=+$/, '');
|
|
22
24
|
return `${base32}${header}${hash}`.toLowerCase();
|
|
23
25
|
}
|
|
24
|
-
exports.convertReferenceToCid = convertReferenceToCid;
|
|
25
26
|
function convertCidToReference(cid) {
|
|
26
27
|
const bytes = cafe_utility_1.Binary.base32ToUint8Array(cid.toUpperCase().slice(1));
|
|
27
28
|
const codec = bytes[1];
|
|
@@ -34,4 +35,3 @@ function convertCidToReference(cid) {
|
|
|
34
35
|
reference,
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
|
-
exports.convertCidToReference = convertCidToReference;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.makeCollectionFromFS = makeCollectionFromFS;
|
|
4
|
+
exports.getFolderSize = getFolderSize;
|
|
4
5
|
/**
|
|
5
6
|
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
6
7
|
* The function loads all the data into memory!
|
|
@@ -10,7 +11,6 @@ exports.getFolderSize = exports.makeCollectionFromFS = void 0;
|
|
|
10
11
|
async function makeCollectionFromFS(_dir) {
|
|
11
12
|
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
12
13
|
}
|
|
13
|
-
exports.makeCollectionFromFS = makeCollectionFromFS;
|
|
14
14
|
/**
|
|
15
15
|
* Calculate folder size recursively
|
|
16
16
|
*
|
|
@@ -20,4 +20,3 @@ exports.makeCollectionFromFS = makeCollectionFromFS;
|
|
|
20
20
|
async function getFolderSize(_dir) {
|
|
21
21
|
throw new Error('Creating Collection from File System is not supported in browsers!');
|
|
22
22
|
}
|
|
23
|
-
exports.getFolderSize = getFolderSize;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isCollection = isCollection;
|
|
4
|
+
exports.assertCollection = assertCollection;
|
|
5
|
+
exports.makeFilePath = makeFilePath;
|
|
6
|
+
exports.makeCollectionFromFileList = makeCollectionFromFileList;
|
|
7
|
+
exports.getCollectionSize = getCollectionSize;
|
|
4
8
|
const error_1 = require("./error");
|
|
5
9
|
function isCollection(data) {
|
|
6
10
|
if (!Array.isArray(data)) {
|
|
@@ -8,13 +12,11 @@ function isCollection(data) {
|
|
|
8
12
|
}
|
|
9
13
|
return data.every(entry => typeof entry === 'object' && entry.path && entry.size !== undefined);
|
|
10
14
|
}
|
|
11
|
-
exports.isCollection = isCollection;
|
|
12
15
|
function assertCollection(data) {
|
|
13
16
|
if (!isCollection(data)) {
|
|
14
17
|
throw new error_1.BeeArgumentError('invalid collection', data);
|
|
15
18
|
}
|
|
16
19
|
}
|
|
17
|
-
exports.assertCollection = assertCollection;
|
|
18
20
|
function makeFilePath(file) {
|
|
19
21
|
if (file.webkitRelativePath && file.webkitRelativePath !== '') {
|
|
20
22
|
return file.webkitRelativePath.replace(/.*?\//i, '');
|
|
@@ -24,7 +26,6 @@ function makeFilePath(file) {
|
|
|
24
26
|
}
|
|
25
27
|
throw new TypeError('file is not valid File object');
|
|
26
28
|
}
|
|
27
|
-
exports.makeFilePath = makeFilePath;
|
|
28
29
|
function makeCollectionFromFileList(fileList) {
|
|
29
30
|
return Array.from(fileList).map(file => ({
|
|
30
31
|
path: makeFilePath(file),
|
|
@@ -32,7 +33,6 @@ function makeCollectionFromFileList(fileList) {
|
|
|
32
33
|
file,
|
|
33
34
|
}));
|
|
34
35
|
}
|
|
35
|
-
exports.makeCollectionFromFileList = makeCollectionFromFileList;
|
|
36
36
|
/**
|
|
37
37
|
* Calculate cumulative size of files
|
|
38
38
|
*
|
|
@@ -42,4 +42,3 @@ exports.makeCollectionFromFileList = makeCollectionFromFileList;
|
|
|
42
42
|
function getCollectionSize(fileList) {
|
|
43
43
|
return Array.from(fileList).reduce((sum, file) => sum + file.size, 0);
|
|
44
44
|
}
|
|
45
|
-
exports.getCollectionSize = getCollectionSize;
|
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.makeCollectionFromFS = makeCollectionFromFS;
|
|
7
|
+
exports.getFolderSize = getFolderSize;
|
|
7
8
|
const fs_1 = __importDefault(require("fs"));
|
|
8
9
|
const path_1 = __importDefault(require("path"));
|
|
9
10
|
/**
|
|
@@ -20,7 +21,6 @@ async function makeCollectionFromFS(dir) {
|
|
|
20
21
|
}
|
|
21
22
|
return buildCollectionRelative(dir, '');
|
|
22
23
|
}
|
|
23
|
-
exports.makeCollectionFromFS = makeCollectionFromFS;
|
|
24
24
|
async function buildCollectionRelative(dir, relativePath) {
|
|
25
25
|
const dirname = path_1.default.join(dir, relativePath);
|
|
26
26
|
const entries = await fs_1.default.promises.opendir(dirname);
|
|
@@ -67,4 +67,3 @@ async function getFolderSize(dir) {
|
|
|
67
67
|
}
|
|
68
68
|
return size;
|
|
69
69
|
}
|
|
70
|
-
exports.getFolderSize = getFolderSize;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareWebsocketData =
|
|
3
|
+
exports.prepareWebsocketData = prepareWebsocketData;
|
|
4
4
|
async function prepareWebsocketData(data) {
|
|
5
5
|
if (typeof data === 'string') {
|
|
6
6
|
return new TextEncoder().encode(data);
|
|
@@ -13,4 +13,3 @@ async function prepareWebsocketData(data) {
|
|
|
13
13
|
}
|
|
14
14
|
throw new TypeError('unknown websocket data type');
|
|
15
15
|
}
|
|
16
|
-
exports.prepareWebsocketData = prepareWebsocketData;
|
package/dist/cjs/utils/data.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.prepareWebsocketData =
|
|
3
|
+
exports.prepareWebsocketData = prepareWebsocketData;
|
|
4
4
|
function isBufferArray(buffer) {
|
|
5
5
|
return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
|
|
6
6
|
}
|
|
@@ -19,4 +19,3 @@ async function prepareWebsocketData(data) {
|
|
|
19
19
|
}
|
|
20
20
|
throw new TypeError('unknown websocket data type');
|
|
21
21
|
}
|
|
22
|
-
exports.prepareWebsocketData = prepareWebsocketData;
|
package/dist/cjs/utils/expose.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStampUsage = exports.getStampTheoreticalBytes = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampDuration = exports.getStampCost = exports.getDepthForSize = exports.getAmountForDuration = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.makeMaxTarget = exports.getFolderSize = exports.makeCollectionFromFileList = exports.getCollectionSize = void 0;
|
|
3
|
+
exports.unmapPostageBatch = exports.mapPostageBatch = exports.getStampUsage = exports.getStampTheoreticalBytes = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampDuration = exports.getStampCost = exports.getDepthForSize = exports.getAmountForDuration = exports.convertEnvelopeToMarshaledStamp = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.makeMaxTarget = exports.getFolderSize = exports.makeCollectionFromFileList = exports.getCollectionSize = void 0;
|
|
4
4
|
var collection_1 = require("./collection");
|
|
5
5
|
Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
|
|
6
6
|
Object.defineProperty(exports, "makeCollectionFromFileList", { enumerable: true, get: function () { return collection_1.makeCollectionFromFileList; } });
|
|
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "approximateOverheadForRedundancyLevel", { enumer
|
|
|
13
13
|
Object.defineProperty(exports, "getRedundancyStat", { enumerable: true, get: function () { return redundancy_1.getRedundancyStat; } });
|
|
14
14
|
Object.defineProperty(exports, "getRedundancyStats", { enumerable: true, get: function () { return redundancy_1.getRedundancyStats; } });
|
|
15
15
|
var stamps_1 = require("./stamps");
|
|
16
|
+
Object.defineProperty(exports, "convertEnvelopeToMarshaledStamp", { enumerable: true, get: function () { return stamps_1.convertEnvelopeToMarshaledStamp; } });
|
|
16
17
|
Object.defineProperty(exports, "getAmountForDuration", { enumerable: true, get: function () { return stamps_1.getAmountForDuration; } });
|
|
17
18
|
Object.defineProperty(exports, "getDepthForSize", { enumerable: true, get: function () { return stamps_1.getDepthForSize; } });
|
|
18
19
|
Object.defineProperty(exports, "getStampCost", { enumerable: true, get: function () { return stamps_1.getStampCost; } });
|
|
@@ -21,3 +22,5 @@ Object.defineProperty(exports, "getStampEffectiveBytes", { enumerable: true, get
|
|
|
21
22
|
Object.defineProperty(exports, "getStampEffectiveBytesBreakpoints", { enumerable: true, get: function () { return stamps_1.getStampEffectiveBytesBreakpoints; } });
|
|
22
23
|
Object.defineProperty(exports, "getStampTheoreticalBytes", { enumerable: true, get: function () { return stamps_1.getStampTheoreticalBytes; } });
|
|
23
24
|
Object.defineProperty(exports, "getStampUsage", { enumerable: true, get: function () { return stamps_1.getStampUsage; } });
|
|
25
|
+
Object.defineProperty(exports, "mapPostageBatch", { enumerable: true, get: function () { return stamps_1.mapPostageBatch; } });
|
|
26
|
+
Object.defineProperty(exports, "unmapPostageBatch", { enumerable: true, get: function () { return stamps_1.unmapPostageBatch; } });
|
package/dist/cjs/utils/file.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isFile = isFile;
|
|
4
|
+
exports.fileArrayBuffer = fileArrayBuffer;
|
|
4
5
|
/**
|
|
5
6
|
* Compatibility functions for working with File API objects
|
|
6
7
|
*
|
|
@@ -17,7 +18,6 @@ function isFile(file) {
|
|
|
17
18
|
typeof f.name === 'string' &&
|
|
18
19
|
(typeof f.stream === 'function' || typeof f.arrayBuffer === 'function'));
|
|
19
20
|
}
|
|
20
|
-
exports.isFile = isFile;
|
|
21
21
|
/**
|
|
22
22
|
* Compatibility helper for browsers where the `arrayBuffer function is
|
|
23
23
|
* missing from `File` objects.
|
|
@@ -35,4 +35,3 @@ async function fileArrayBuffer(file) {
|
|
|
35
35
|
fr.readAsArrayBuffer(file);
|
|
36
36
|
});
|
|
37
37
|
}
|
|
38
|
-
exports.fileArrayBuffer = fileArrayBuffer;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.readFileHeaders = readFileHeaders;
|
|
4
|
+
exports.prepareRequestHeaders = prepareRequestHeaders;
|
|
4
5
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
6
|
const error_1 = require("./error");
|
|
6
7
|
const stamps_1 = require("./stamps");
|
|
@@ -15,7 +16,6 @@ function readFileHeaders(headers) {
|
|
|
15
16
|
contentType,
|
|
16
17
|
};
|
|
17
18
|
}
|
|
18
|
-
exports.readFileHeaders = readFileHeaders;
|
|
19
19
|
function readContentDispositionFilename(header) {
|
|
20
20
|
if (!header) {
|
|
21
21
|
throw new error_1.BeeError('missing content-disposition header');
|
|
@@ -106,7 +106,6 @@ function prepareRequestHeaders(stamp, nullableOptions) {
|
|
|
106
106
|
}
|
|
107
107
|
return headers;
|
|
108
108
|
}
|
|
109
|
-
exports.prepareRequestHeaders = prepareRequestHeaders;
|
|
110
109
|
function isEnvelopeWithBatchId(value) {
|
|
111
110
|
if (!cafe_utility_1.Types.isObject(value)) {
|
|
112
111
|
return false;
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.DEFAULT_HTTP_CONFIG = void 0;
|
|
7
|
+
exports.http = http;
|
|
7
8
|
const axios_1 = __importDefault(require("axios"));
|
|
8
9
|
const cafe_utility_1 = require("cafe-utility");
|
|
9
10
|
const debug_1 = __importDefault(require("debug"));
|
|
@@ -68,7 +69,6 @@ async function http(options, config) {
|
|
|
68
69
|
}
|
|
69
70
|
throw Error('Max number of failed attempts reached');
|
|
70
71
|
}
|
|
71
|
-
exports.http = http;
|
|
72
72
|
function maybeRunOnRequestHook(options, requestConfig) {
|
|
73
73
|
if (options.onRequest) {
|
|
74
74
|
options.onRequest({
|
package/dist/cjs/utils/pss.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.makeMaxTarget =
|
|
3
|
+
exports.makeMaxTarget = makeMaxTarget;
|
|
4
4
|
const types_1 = require("../types");
|
|
5
5
|
const typed_bytes_1 = require("./typed-bytes");
|
|
6
6
|
/**
|
|
@@ -14,4 +14,3 @@ function makeMaxTarget(target) {
|
|
|
14
14
|
target = new typed_bytes_1.PeerAddress(target);
|
|
15
15
|
return target.toHex().slice(0, types_1.PSS_TARGET_HEX_LENGTH_MAX);
|
|
16
16
|
}
|
|
17
|
-
exports.makeMaxTarget = makeMaxTarget;
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.approximateOverheadForRedundancyLevel = approximateOverheadForRedundancyLevel;
|
|
4
|
+
exports.getRedundancyStats = getRedundancyStats;
|
|
5
|
+
exports.getRedundancyStat = getRedundancyStat;
|
|
4
6
|
const __1 = require("..");
|
|
5
7
|
const mediumTable = [
|
|
6
8
|
[94, 68, 46, 28, 14, 5, 1],
|
|
@@ -59,7 +61,6 @@ function approximateOverheadForRedundancyLevel(chunks, level, encrypted) {
|
|
|
59
61
|
}
|
|
60
62
|
return parities[parities.length - 1] / supportedChunks[supportedChunks.length - 1];
|
|
61
63
|
}
|
|
62
|
-
exports.approximateOverheadForRedundancyLevel = approximateOverheadForRedundancyLevel;
|
|
63
64
|
function selectTable(level, encrypted) {
|
|
64
65
|
switch (level) {
|
|
65
66
|
case __1.RedundancyLevel.MEDIUM:
|
|
@@ -102,7 +103,6 @@ function getRedundancyStats() {
|
|
|
102
103
|
paranoid,
|
|
103
104
|
};
|
|
104
105
|
}
|
|
105
|
-
exports.getRedundancyStats = getRedundancyStats;
|
|
106
106
|
function getRedundancyStat(level) {
|
|
107
107
|
if (typeof level === 'string') {
|
|
108
108
|
switch (level.toLowerCase()) {
|
|
@@ -131,4 +131,3 @@ function getRedundancyStat(level) {
|
|
|
131
131
|
throw new Error(`Unknown redundancy level '${level}'`);
|
|
132
132
|
}
|
|
133
133
|
}
|
|
134
|
-
exports.getRedundancyStat = getRedundancyStat;
|
package/dist/cjs/utils/stamps.js
CHANGED
|
@@ -1,12 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getStampUsage = getStampUsage;
|
|
4
|
+
exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
|
|
5
|
+
exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
6
|
+
exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
|
|
7
|
+
exports.getStampCost = getStampCost;
|
|
8
|
+
exports.getStampDuration = getStampDuration;
|
|
9
|
+
exports.getAmountForDuration = getAmountForDuration;
|
|
10
|
+
exports.getDepthForSize = getDepthForSize;
|
|
11
|
+
exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
|
|
12
|
+
exports.marshalStamp = marshalStamp;
|
|
13
|
+
exports.mapPostageBatch = mapPostageBatch;
|
|
14
|
+
exports.unmapPostageBatch = unmapPostageBatch;
|
|
4
15
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
16
|
const types_1 = require("../types");
|
|
6
17
|
const bytes_1 = require("./bytes");
|
|
7
18
|
const duration_1 = require("./duration");
|
|
19
|
+
const size_1 = require("./size");
|
|
8
20
|
const tokens_1 = require("./tokens");
|
|
9
21
|
const type_1 = require("./type");
|
|
22
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
23
|
+
const workaround_1 = require("./workaround");
|
|
10
24
|
const MAX_UTILIZATION = 0.9;
|
|
11
25
|
/**
|
|
12
26
|
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
|
|
@@ -18,7 +32,6 @@ const MAX_UTILIZATION = 0.9;
|
|
|
18
32
|
function getStampUsage(utilization, depth, bucketDepth) {
|
|
19
33
|
return utilization / Math.pow(2, depth - bucketDepth);
|
|
20
34
|
}
|
|
21
|
-
exports.getStampUsage = getStampUsage;
|
|
22
35
|
/**
|
|
23
36
|
* Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
|
|
24
37
|
*
|
|
@@ -29,7 +42,6 @@ exports.getStampUsage = getStampUsage;
|
|
|
29
42
|
function getStampTheoreticalBytes(depth) {
|
|
30
43
|
return 4096 * 2 ** depth;
|
|
31
44
|
}
|
|
32
|
-
exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
|
|
33
45
|
/**
|
|
34
46
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
35
47
|
* Optimised for encrypted, medium erasure coding
|
|
@@ -86,7 +98,6 @@ function getStampEffectiveBytes(depth, encryption, erasureCodeLevel) {
|
|
|
86
98
|
}
|
|
87
99
|
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
88
100
|
}
|
|
89
|
-
exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
90
101
|
function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
|
|
91
102
|
const map = new Map();
|
|
92
103
|
for (let i = 17; i < 35; i++) {
|
|
@@ -94,14 +105,12 @@ function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
|
|
|
94
105
|
}
|
|
95
106
|
return map;
|
|
96
107
|
}
|
|
97
|
-
exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
|
|
98
108
|
/**
|
|
99
109
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
100
110
|
*/
|
|
101
111
|
function getStampCost(depth, amount) {
|
|
102
112
|
return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
|
|
103
113
|
}
|
|
104
|
-
exports.getStampCost = getStampCost;
|
|
105
114
|
/**
|
|
106
115
|
* Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
|
|
107
116
|
*
|
|
@@ -113,7 +122,6 @@ function getStampDuration(amount, pricePerBlock, blockTime) {
|
|
|
113
122
|
const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
|
|
114
123
|
return duration_1.Duration.fromSeconds(Number((amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock)));
|
|
115
124
|
}
|
|
116
|
-
exports.getStampDuration = getStampDuration;
|
|
117
125
|
/**
|
|
118
126
|
* Get the postage batch `amount` required for a given `duration`.
|
|
119
127
|
*
|
|
@@ -124,7 +132,6 @@ exports.getStampDuration = getStampDuration;
|
|
|
124
132
|
function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
125
133
|
return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock) + 1n;
|
|
126
134
|
}
|
|
127
|
-
exports.getAmountForDuration = getAmountForDuration;
|
|
128
135
|
/**
|
|
129
136
|
* Utility function that calculates the depth required for a postage batch to achieve the specified effective size
|
|
130
137
|
*
|
|
@@ -151,11 +158,9 @@ function getDepthForSize(size, encryption, erasureCodeLevel) {
|
|
|
151
158
|
}
|
|
152
159
|
return 35;
|
|
153
160
|
}
|
|
154
|
-
exports.getDepthForSize = getDepthForSize;
|
|
155
161
|
function convertEnvelopeToMarshaledStamp(envelope) {
|
|
156
162
|
return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
|
|
157
163
|
}
|
|
158
|
-
exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
|
|
159
164
|
function marshalStamp(signature, batchId, timestamp, index) {
|
|
160
165
|
if (signature.length !== 65) {
|
|
161
166
|
throw Error('invalid signature length');
|
|
@@ -171,4 +176,48 @@ function marshalStamp(signature, batchId, timestamp, index) {
|
|
|
171
176
|
}
|
|
172
177
|
return new bytes_1.Bytes(cafe_utility_1.Binary.concatBytes(batchId, index, timestamp, signature));
|
|
173
178
|
}
|
|
174
|
-
|
|
179
|
+
function mapPostageBatch(raw, encryption, erasureCodeLevel) {
|
|
180
|
+
const usage = getStampUsage(raw.utilization, raw.depth, raw.bucketDepth);
|
|
181
|
+
const batchTTL = (0, workaround_1.normalizeBatchTTL)(raw.batchTTL);
|
|
182
|
+
const duration = duration_1.Duration.fromSeconds(batchTTL);
|
|
183
|
+
const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, erasureCodeLevel);
|
|
184
|
+
return {
|
|
185
|
+
batchID: new typed_bytes_1.BatchId(raw.batchID),
|
|
186
|
+
utilization: raw.utilization,
|
|
187
|
+
usable: raw.usable,
|
|
188
|
+
label: raw.label,
|
|
189
|
+
depth: raw.depth,
|
|
190
|
+
amount: (0, type_1.asNumberString)(raw.amount),
|
|
191
|
+
bucketDepth: raw.bucketDepth,
|
|
192
|
+
blockNumber: raw.blockNumber,
|
|
193
|
+
immutableFlag: raw.immutableFlag,
|
|
194
|
+
usage,
|
|
195
|
+
usageText: `${Math.round(usage * 100)}%`,
|
|
196
|
+
size: size_1.Size.fromBytes(effectiveBytes),
|
|
197
|
+
remainingSize: size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage))),
|
|
198
|
+
theoreticalSize: size_1.Size.fromBytes(getStampTheoreticalBytes(raw.depth)),
|
|
199
|
+
duration,
|
|
200
|
+
calculateSize(encryption, redundancyLevel) {
|
|
201
|
+
const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, redundancyLevel);
|
|
202
|
+
return size_1.Size.fromBytes(effectiveBytes);
|
|
203
|
+
},
|
|
204
|
+
calculateRemainingSize(encryption, redundancyLevel) {
|
|
205
|
+
const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, redundancyLevel);
|
|
206
|
+
return size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - this.usage)));
|
|
207
|
+
},
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
function unmapPostageBatch(batch) {
|
|
211
|
+
return {
|
|
212
|
+
batchID: batch.batchID.toHex(),
|
|
213
|
+
utilization: batch.utilization,
|
|
214
|
+
usable: batch.usable,
|
|
215
|
+
label: batch.label,
|
|
216
|
+
depth: batch.depth,
|
|
217
|
+
amount: batch.amount,
|
|
218
|
+
bucketDepth: batch.bucketDepth,
|
|
219
|
+
blockNumber: batch.blockNumber,
|
|
220
|
+
immutableFlag: batch.immutableFlag,
|
|
221
|
+
batchTTL: batch.duration.toSeconds(),
|
|
222
|
+
};
|
|
223
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadTar =
|
|
3
|
+
exports.uploadTar = uploadTar;
|
|
4
4
|
const headers_1 = require("./headers");
|
|
5
5
|
const http_1 = require("./http");
|
|
6
6
|
const tar_1 = require("./tar");
|
|
@@ -23,4 +23,3 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
|
23
23
|
});
|
|
24
24
|
return response;
|
|
25
25
|
}
|
|
26
|
-
exports.uploadTar = uploadTar;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadTar =
|
|
3
|
+
exports.uploadTar = uploadTar;
|
|
4
4
|
const headers_1 = require("./headers");
|
|
5
5
|
const http_1 = require("./http");
|
|
6
6
|
const tar_1 = require("./tar");
|
|
@@ -24,4 +24,3 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
|
24
24
|
const response = await responsePromise;
|
|
25
25
|
return response;
|
|
26
26
|
}
|
|
27
|
-
exports.uploadTar = uploadTar;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeTar =
|
|
3
|
+
exports.writeTar = writeTar;
|
|
4
4
|
const file_1 = require("./file");
|
|
5
5
|
async function writeTar(collection, tarStream) {
|
|
6
6
|
for (const item of collection) {
|
|
@@ -14,4 +14,3 @@ async function writeTar(collection, tarStream) {
|
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
|
-
exports.writeTar = writeTar;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.writeTar =
|
|
3
|
+
exports.writeTar = writeTar;
|
|
4
4
|
const fs_1 = require("fs");
|
|
5
5
|
async function writeTar(collection, tarStream) {
|
|
6
6
|
for (const item of collection) {
|
|
@@ -22,4 +22,3 @@ async function writeTar(collection, tarStream) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
|
-
exports.writeTar = writeTar;
|