@ethersphere/bee-js 10.4.0 → 11.1.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 +7 -8
- 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 +30 -6
- 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 +2 -1
- package/dist/cjs/utils/file.js +2 -3
- package/dist/cjs/utils/headers.js +2 -3
- package/dist/cjs/utils/http.js +17 -3
- package/dist/cjs/utils/pss.js +1 -2
- package/dist/cjs/utils/redundancy.js +3 -4
- package/dist/cjs/utils/stamps.js +12 -13
- 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 +35 -25
- package/dist/cjs/utils/url.js +3 -4
- package/dist/cjs/utils/workaround.js +2 -3
- 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/states.js +3 -0
- package/dist/mjs/modules/debug/status.js +1 -1
- package/dist/mjs/utils/chunk-stream.browser.js +29 -5
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/http.js +17 -1
- package/dist/mjs/utils/type.js +2 -1
- package/dist/types/bee.d.ts +0 -4
- package/dist/types/index.d.ts +1 -0
- 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/types/index.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/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 +10 -13
|
@@ -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,12 +13,14 @@ 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
|
+
const signal = requestOptions?.signal;
|
|
21
|
+
if (signal?.aborted) {
|
|
22
|
+
throw new Error('Request aborted');
|
|
23
|
+
}
|
|
20
24
|
const queue = new cafe_utility_1.AsyncQueue(64, 64);
|
|
21
25
|
let total = 0;
|
|
22
26
|
let processed = 0;
|
|
@@ -26,12 +30,26 @@ async function streamFiles(bee, files, postageBatchId, onUploadProgress, options
|
|
|
26
30
|
postageBatchId = new typed_bytes_1.BatchId(postageBatchId);
|
|
27
31
|
async function onChunk(chunk) {
|
|
28
32
|
await queue.enqueue(async () => {
|
|
29
|
-
|
|
30
|
-
|
|
33
|
+
if (signal?.aborted) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
await bee.uploadChunk(postageBatchId, chunk.build(), options, requestOptions);
|
|
38
|
+
onUploadProgress?.({ total, processed: ++processed });
|
|
39
|
+
}
|
|
40
|
+
catch (err) {
|
|
41
|
+
if (signal?.aborted) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
throw err;
|
|
45
|
+
}
|
|
31
46
|
});
|
|
32
47
|
}
|
|
33
48
|
const mantaray = new manifest_1.MantarayNode();
|
|
34
49
|
for (const file of files) {
|
|
50
|
+
if (signal?.aborted) {
|
|
51
|
+
throw new Error('Request aborted');
|
|
52
|
+
}
|
|
35
53
|
const rootChunk = await new Promise((resolve, reject) => {
|
|
36
54
|
const tree = new cafe_utility_1.MerkleTree(onChunk);
|
|
37
55
|
let offset = 0;
|
|
@@ -40,6 +58,10 @@ async function streamFiles(bee, files, postageBatchId, onUploadProgress, options
|
|
|
40
58
|
reject(reader.error);
|
|
41
59
|
};
|
|
42
60
|
const readNextChunk = async () => {
|
|
61
|
+
if (signal?.aborted) {
|
|
62
|
+
reject(new Error('Request aborted'));
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
43
65
|
if (offset >= file.size) {
|
|
44
66
|
const rootChunk = await tree.finalize();
|
|
45
67
|
resolve(rootChunk);
|
|
@@ -74,9 +96,11 @@ async function streamFiles(bee, files, postageBatchId, onUploadProgress, options
|
|
|
74
96
|
});
|
|
75
97
|
}
|
|
76
98
|
}
|
|
99
|
+
if (signal?.aborted) {
|
|
100
|
+
throw new Error('Request aborted');
|
|
101
|
+
}
|
|
77
102
|
return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
|
|
78
103
|
}
|
|
79
|
-
exports.streamFiles = streamFiles;
|
|
80
104
|
function maybeEnrichMime(mime) {
|
|
81
105
|
if (['text/html', 'text/css'].includes(mime)) {
|
|
82
106
|
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.unmapPostageBatch = exports.mapPostageBatch = 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; } });
|
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"));
|
|
@@ -14,6 +15,7 @@ const MAX_FAILED_ATTEMPTS = 100000;
|
|
|
14
15
|
const DELAY_FAST = 200;
|
|
15
16
|
const DELAY_SLOW = 1000;
|
|
16
17
|
const DELAY_THRESHOLD = cafe_utility_1.Dates.minutes(1) / DELAY_FAST;
|
|
18
|
+
const ABORT_ERROR_MESSAGE = 'Request aborted';
|
|
17
19
|
exports.DEFAULT_HTTP_CONFIG = {
|
|
18
20
|
headers: {
|
|
19
21
|
accept: 'application/json, text/plain, */*',
|
|
@@ -21,6 +23,11 @@ exports.DEFAULT_HTTP_CONFIG = {
|
|
|
21
23
|
maxBodyLength: Infinity,
|
|
22
24
|
maxContentLength: Infinity,
|
|
23
25
|
};
|
|
26
|
+
function throwIfAborted(signal, config, responseData, responseStatus) {
|
|
27
|
+
if (signal?.aborted) {
|
|
28
|
+
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', ABORT_ERROR_MESSAGE, responseData, responseStatus, 'ERR_CANCELED');
|
|
29
|
+
}
|
|
30
|
+
}
|
|
24
31
|
/**
|
|
25
32
|
* Main function to make HTTP requests.
|
|
26
33
|
* @param options User defined settings
|
|
@@ -28,6 +35,10 @@ exports.DEFAULT_HTTP_CONFIG = {
|
|
|
28
35
|
*/
|
|
29
36
|
async function http(options, config) {
|
|
30
37
|
const requestConfig = cafe_utility_1.Objects.deepMerge3(exports.DEFAULT_HTTP_CONFIG, config, options);
|
|
38
|
+
if (options.signal) {
|
|
39
|
+
requestConfig.signal = options.signal;
|
|
40
|
+
throwIfAborted(options.signal, config);
|
|
41
|
+
}
|
|
31
42
|
if (requestConfig.data && typeof Buffer !== 'undefined' && Buffer.isBuffer(requestConfig.data)) {
|
|
32
43
|
requestConfig.data = requestConfig.data.buffer.slice(requestConfig.data.byteOffset, requestConfig.data.byteOffset + requestConfig.data.byteLength);
|
|
33
44
|
}
|
|
@@ -42,6 +53,7 @@ async function http(options, config) {
|
|
|
42
53
|
}
|
|
43
54
|
let failedAttempts = 0;
|
|
44
55
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
56
|
+
throwIfAborted(options.signal, config);
|
|
45
57
|
try {
|
|
46
58
|
debug(`${requestConfig.method || 'get'} ${cafe_utility_1.Strings.joinUrl([
|
|
47
59
|
requestConfig.baseURL,
|
|
@@ -53,12 +65,15 @@ async function http(options, config) {
|
|
|
53
65
|
}
|
|
54
66
|
catch (e) {
|
|
55
67
|
if (e instanceof AxiosError) {
|
|
68
|
+
if (e.code === 'ERR_CANCELED') {
|
|
69
|
+
throwIfAborted({ aborted: true }, config, e.response?.data, e.response?.status);
|
|
70
|
+
}
|
|
56
71
|
if (e.code === 'ECONNABORTED' && options.endlesslyRetry) {
|
|
57
72
|
failedAttempts++;
|
|
58
73
|
await cafe_utility_1.System.sleepMillis(failedAttempts < DELAY_THRESHOLD ? DELAY_FAST : DELAY_SLOW);
|
|
59
74
|
}
|
|
60
75
|
else {
|
|
61
|
-
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.
|
|
76
|
+
throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.response?.statusText);
|
|
62
77
|
}
|
|
63
78
|
}
|
|
64
79
|
else {
|
|
@@ -68,7 +83,6 @@ async function http(options, config) {
|
|
|
68
83
|
}
|
|
69
84
|
throw Error('Max number of failed attempts reached');
|
|
70
85
|
}
|
|
71
|
-
exports.http = http;
|
|
72
86
|
function maybeRunOnRequestHook(options, requestConfig) {
|
|
73
87
|
if (options.onRequest) {
|
|
74
88
|
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,6 +1,17 @@
|
|
|
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");
|
|
@@ -21,7 +32,6 @@ const MAX_UTILIZATION = 0.9;
|
|
|
21
32
|
function getStampUsage(utilization, depth, bucketDepth) {
|
|
22
33
|
return utilization / Math.pow(2, depth - bucketDepth);
|
|
23
34
|
}
|
|
24
|
-
exports.getStampUsage = getStampUsage;
|
|
25
35
|
/**
|
|
26
36
|
* Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
|
|
27
37
|
*
|
|
@@ -32,7 +42,6 @@ exports.getStampUsage = getStampUsage;
|
|
|
32
42
|
function getStampTheoreticalBytes(depth) {
|
|
33
43
|
return 4096 * 2 ** depth;
|
|
34
44
|
}
|
|
35
|
-
exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
|
|
36
45
|
/**
|
|
37
46
|
* Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
|
|
38
47
|
* Optimised for encrypted, medium erasure coding
|
|
@@ -89,7 +98,6 @@ function getStampEffectiveBytes(depth, encryption, erasureCodeLevel) {
|
|
|
89
98
|
}
|
|
90
99
|
return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
|
|
91
100
|
}
|
|
92
|
-
exports.getStampEffectiveBytes = getStampEffectiveBytes;
|
|
93
101
|
function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
|
|
94
102
|
const map = new Map();
|
|
95
103
|
for (let i = 17; i < 35; i++) {
|
|
@@ -97,14 +105,12 @@ function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
|
|
|
97
105
|
}
|
|
98
106
|
return map;
|
|
99
107
|
}
|
|
100
|
-
exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
|
|
101
108
|
/**
|
|
102
109
|
* Utility function that calculates the cost of a postage batch based on its depth and amount.
|
|
103
110
|
*/
|
|
104
111
|
function getStampCost(depth, amount) {
|
|
105
112
|
return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
|
|
106
113
|
}
|
|
107
|
-
exports.getStampCost = getStampCost;
|
|
108
114
|
/**
|
|
109
115
|
* Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
|
|
110
116
|
*
|
|
@@ -116,7 +122,6 @@ function getStampDuration(amount, pricePerBlock, blockTime) {
|
|
|
116
122
|
const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
|
|
117
123
|
return duration_1.Duration.fromSeconds(Number((amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock)));
|
|
118
124
|
}
|
|
119
|
-
exports.getStampDuration = getStampDuration;
|
|
120
125
|
/**
|
|
121
126
|
* Get the postage batch `amount` required for a given `duration`.
|
|
122
127
|
*
|
|
@@ -127,7 +132,6 @@ exports.getStampDuration = getStampDuration;
|
|
|
127
132
|
function getAmountForDuration(duration, pricePerBlock, blockTime) {
|
|
128
133
|
return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock) + 1n;
|
|
129
134
|
}
|
|
130
|
-
exports.getAmountForDuration = getAmountForDuration;
|
|
131
135
|
/**
|
|
132
136
|
* Utility function that calculates the depth required for a postage batch to achieve the specified effective size
|
|
133
137
|
*
|
|
@@ -154,11 +158,9 @@ function getDepthForSize(size, encryption, erasureCodeLevel) {
|
|
|
154
158
|
}
|
|
155
159
|
return 35;
|
|
156
160
|
}
|
|
157
|
-
exports.getDepthForSize = getDepthForSize;
|
|
158
161
|
function convertEnvelopeToMarshaledStamp(envelope) {
|
|
159
162
|
return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
|
|
160
163
|
}
|
|
161
|
-
exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
|
|
162
164
|
function marshalStamp(signature, batchId, timestamp, index) {
|
|
163
165
|
if (signature.length !== 65) {
|
|
164
166
|
throw Error('invalid signature length');
|
|
@@ -174,7 +176,6 @@ function marshalStamp(signature, batchId, timestamp, index) {
|
|
|
174
176
|
}
|
|
175
177
|
return new bytes_1.Bytes(cafe_utility_1.Binary.concatBytes(batchId, index, timestamp, signature));
|
|
176
178
|
}
|
|
177
|
-
exports.marshalStamp = marshalStamp;
|
|
178
179
|
function mapPostageBatch(raw, encryption, erasureCodeLevel) {
|
|
179
180
|
const usage = getStampUsage(raw.utilization, raw.depth, raw.bucketDepth);
|
|
180
181
|
const batchTTL = (0, workaround_1.normalizeBatchTTL)(raw.batchTTL);
|
|
@@ -206,7 +207,6 @@ function mapPostageBatch(raw, encryption, erasureCodeLevel) {
|
|
|
206
207
|
},
|
|
207
208
|
};
|
|
208
209
|
}
|
|
209
|
-
exports.mapPostageBatch = mapPostageBatch;
|
|
210
210
|
function unmapPostageBatch(batch) {
|
|
211
211
|
return {
|
|
212
212
|
batchID: batch.batchID.toHex(),
|
|
@@ -221,4 +221,3 @@ function unmapPostageBatch(batch) {
|
|
|
221
221
|
batchTTL: batch.duration.toSeconds(),
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
-
exports.unmapPostageBatch = unmapPostageBatch;
|
|
@@ -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;
|