@upcoming/bee-js 9.9.1 → 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/README.md +2 -2
- package/dist/cjs/bee.js +881 -370
- package/dist/cjs/chunk/bmt.js +1 -2
- package/dist/cjs/chunk/cac.js +27 -32
- package/dist/cjs/chunk/soc.js +39 -31
- package/dist/cjs/feed/identifier.js +1 -2
- package/dist/cjs/feed/index.js +29 -19
- package/dist/cjs/feed/retrievable.js +1 -2
- package/dist/cjs/index.js +17 -7
- package/dist/cjs/manifest/manifest.js +19 -2
- 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 +9 -10
- 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 +24 -60
- 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 +11 -6
- package/dist/cjs/utils/bytes.js +23 -3
- 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/duration.js +27 -1
- 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 +25 -5
- package/dist/cjs/utils/pss.js +1 -2
- package/dist/cjs/utils/redundancy.js +3 -4
- package/dist/cjs/utils/size.js +25 -0
- 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 +37 -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 +864 -366
- package/dist/mjs/chunk/cac.js +21 -30
- package/dist/mjs/chunk/soc.js +16 -17
- package/dist/mjs/feed/index.js +7 -6
- package/dist/mjs/manifest/manifest.js +19 -2
- package/dist/mjs/modules/debug/chequebook.js +2 -2
- package/dist/mjs/modules/debug/stamps.js +38 -93
- package/dist/mjs/modules/debug/states.js +3 -0
- package/dist/mjs/modules/debug/status.js +1 -1
- package/dist/mjs/types/index.js +8 -3
- package/dist/mjs/utils/bytes.js +19 -2
- package/dist/mjs/utils/chunk-stream.browser.js +29 -5
- package/dist/mjs/utils/duration.js +27 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/http.js +25 -3
- package/dist/mjs/utils/size.js +25 -0
- package/dist/mjs/utils/stamps.js +48 -0
- package/dist/mjs/utils/type.js +8 -1
- package/dist/mjs/utils/workaround.js +5 -2
- package/dist/types/bee.d.ts +756 -252
- package/dist/types/chunk/cac.d.ts +27 -13
- package/dist/types/chunk/soc.d.ts +43 -11
- package/dist/types/index.d.ts +3 -0
- package/dist/types/modules/bzz.d.ts +0 -1
- package/dist/types/modules/debug/stamps.d.ts +2 -2
- 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 +2 -1
- package/dist/types/types/index.d.ts +53 -6
- package/dist/types/utils/constants.d.ts +3 -3
- package/dist/types/utils/duration.d.ts +24 -0
- package/dist/types/utils/error.d.ts +2 -2
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/size.d.ts +23 -0
- 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 +10 -13
package/dist/cjs/modules/pss.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.send = send;
|
|
7
|
+
exports.subscribe = subscribe;
|
|
7
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
8
9
|
const isomorphic_ws_1 = __importDefault(require("isomorphic-ws"));
|
|
9
10
|
const headers_1 = require("../utils/headers");
|
|
@@ -30,7 +31,6 @@ async function send(requestOptions, topic, target, data, postageBatchId, recipie
|
|
|
30
31
|
headers: (0, headers_1.prepareRequestHeaders)(postageBatchId),
|
|
31
32
|
});
|
|
32
33
|
}
|
|
33
|
-
exports.send = send;
|
|
34
34
|
/**
|
|
35
35
|
* Subscribe for messages on the given topic
|
|
36
36
|
*
|
|
@@ -46,4 +46,3 @@ function subscribe(url, topic, headers) {
|
|
|
46
46
|
headers,
|
|
47
47
|
});
|
|
48
48
|
}
|
|
49
|
-
exports.subscribe = subscribe;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rchash =
|
|
3
|
+
exports.rchash = rchash;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const http_1 = require("../utils/http");
|
|
6
6
|
const RCHASH_ENDPOINT = 'rchash';
|
|
@@ -12,4 +12,3 @@ async function rchash(requestOptions, depth, anchor1, anchor2) {
|
|
|
12
12
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
13
13
|
return cafe_utility_1.Types.asNumber(body.durationSeconds, { name: 'durationSeconds' });
|
|
14
14
|
}
|
|
15
|
-
exports.rchash = rchash;
|
package/dist/cjs/modules/soc.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.upload =
|
|
3
|
+
exports.upload = upload;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const headers_1 = require("../utils/headers");
|
|
6
6
|
const http_1 = require("../utils/http");
|
|
@@ -39,4 +39,3 @@ async function upload(requestOptions, owner, identifier, signature, data, stamp,
|
|
|
39
39
|
: cafe_utility_1.Optional.empty(),
|
|
40
40
|
};
|
|
41
41
|
}
|
|
42
|
-
exports.upload = upload;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.checkConnection = checkConnection;
|
|
4
|
+
exports.isGateway = isGateway;
|
|
4
5
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
6
|
const http_1 = require("../utils/http");
|
|
6
7
|
/**
|
|
@@ -13,7 +14,6 @@ async function checkConnection(requestOptions) {
|
|
|
13
14
|
url: '',
|
|
14
15
|
});
|
|
15
16
|
}
|
|
16
|
-
exports.checkConnection = checkConnection;
|
|
17
17
|
async function isGateway(requestOptions) {
|
|
18
18
|
try {
|
|
19
19
|
const response = await (0, http_1.http)(requestOptions, {
|
|
@@ -26,4 +26,3 @@ async function isGateway(requestOptions) {
|
|
|
26
26
|
return false;
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
-
exports.isGateway = isGateway;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.reupload = reupload;
|
|
4
|
+
exports.isRetrievable = isRetrievable;
|
|
4
5
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
6
|
const http_1 = require("../utils/http");
|
|
6
7
|
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
@@ -18,7 +19,6 @@ async function reupload(requestOptions, stamp, reference) {
|
|
|
18
19
|
headers: { 'swarm-postage-batch-id': stamp.toHex() },
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
|
-
exports.reupload = reupload;
|
|
22
22
|
async function isRetrievable(requestOptions, reference) {
|
|
23
23
|
reference = new typed_bytes_1.Reference(reference);
|
|
24
24
|
const response = await (0, http_1.http)(requestOptions, {
|
|
@@ -29,4 +29,3 @@ async function isRetrievable(requestOptions, reference) {
|
|
|
29
29
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
30
30
|
return cafe_utility_1.Types.asBoolean(body.isRetrievable, { name: 'isRetrievable' });
|
|
31
31
|
}
|
|
32
|
-
exports.isRetrievable = isRetrievable;
|
package/dist/cjs/modules/tag.js
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.createTag = createTag;
|
|
4
|
+
exports.retrieveTag = retrieveTag;
|
|
5
|
+
exports.getAllTags = getAllTags;
|
|
6
|
+
exports.deleteTag = deleteTag;
|
|
7
|
+
exports.updateTag = updateTag;
|
|
4
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
9
|
const http_1 = require("../utils/http");
|
|
6
10
|
const endpoint = 'tags';
|
|
@@ -27,7 +31,6 @@ async function createTag(requestOptions) {
|
|
|
27
31
|
uid: cafe_utility_1.Types.asNumber(body.uid, { name: 'uid' }),
|
|
28
32
|
};
|
|
29
33
|
}
|
|
30
|
-
exports.createTag = createTag;
|
|
31
34
|
/**
|
|
32
35
|
* Retrieve tag information from Bee node
|
|
33
36
|
*
|
|
@@ -51,7 +54,6 @@ async function retrieveTag(requestOptions, uid) {
|
|
|
51
54
|
uid: cafe_utility_1.Types.asNumber(body.uid, { name: 'uid' }),
|
|
52
55
|
};
|
|
53
56
|
}
|
|
54
|
-
exports.retrieveTag = retrieveTag;
|
|
55
57
|
/**
|
|
56
58
|
* Get limited listing of all tags.
|
|
57
59
|
*
|
|
@@ -78,7 +80,6 @@ async function getAllTags(requestOptions, offset, limit) {
|
|
|
78
80
|
uid: cafe_utility_1.Types.asNumber(x.uid, { name: 'uid' }),
|
|
79
81
|
}));
|
|
80
82
|
}
|
|
81
|
-
exports.getAllTags = getAllTags;
|
|
82
83
|
/**
|
|
83
84
|
* Removes tag from the Bee node.
|
|
84
85
|
* @param url
|
|
@@ -90,7 +91,6 @@ async function deleteTag(requestOptions, uid) {
|
|
|
90
91
|
url: `${endpoint}/${uid}`,
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
|
-
exports.deleteTag = deleteTag;
|
|
94
94
|
/**
|
|
95
95
|
* Updates tag
|
|
96
96
|
* @param url
|
|
@@ -106,4 +106,3 @@ async function updateTag(requestOptions, uid, reference) {
|
|
|
106
106
|
},
|
|
107
107
|
});
|
|
108
108
|
}
|
|
109
|
-
exports.updateTag = updateTag;
|
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
|
@@ -14,23 +14,28 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.capacityBreakpoints = exports.RedundancyStrategy = exports.RedundancyLevel = exports.
|
|
17
|
+
exports.capacityBreakpoints = exports.RedundancyStrategy = exports.RedundancyLevel = exports.TAGS_LIMIT_MAX = exports.TAGS_LIMIT_MIN = exports.STAMPS_DEPTH_MAX = exports.STAMPS_DEPTH_MIN = exports.PSS_TARGET_HEX_LENGTH_MAX = exports.CHUNK_SIZE = exports.BRANCHES = exports.SECTION_SIZE = void 0;
|
|
18
18
|
__exportStar(require("./debug"), exports);
|
|
19
19
|
exports.SECTION_SIZE = 32;
|
|
20
20
|
exports.BRANCHES = 128;
|
|
21
21
|
exports.CHUNK_SIZE = exports.SECTION_SIZE * exports.BRANCHES;
|
|
22
22
|
exports.PSS_TARGET_HEX_LENGTH_MAX = 4;
|
|
23
23
|
/**
|
|
24
|
-
*
|
|
24
|
+
* Minimum postage batch depth.
|
|
25
25
|
*/
|
|
26
26
|
exports.STAMPS_DEPTH_MIN = 17;
|
|
27
27
|
/**
|
|
28
|
-
*
|
|
28
|
+
* Maximum postage batch depth.
|
|
29
29
|
*/
|
|
30
30
|
exports.STAMPS_DEPTH_MAX = 255;
|
|
31
|
+
/**
|
|
32
|
+
* Minimum tags API page size.
|
|
33
|
+
*/
|
|
31
34
|
exports.TAGS_LIMIT_MIN = 1;
|
|
35
|
+
/**
|
|
36
|
+
* Maximum tags API page size.
|
|
37
|
+
*/
|
|
32
38
|
exports.TAGS_LIMIT_MAX = 1000;
|
|
33
|
-
exports.FEED_INDEX_HEX_LENGTH = 16;
|
|
34
39
|
/**
|
|
35
40
|
* Add redundancy to the data being uploaded so that downloaders can download it with better UX.
|
|
36
41
|
* 0 value is default and does not add any redundancy to the file.
|
|
@@ -42,7 +47,7 @@ var RedundancyLevel;
|
|
|
42
47
|
RedundancyLevel[RedundancyLevel["STRONG"] = 2] = "STRONG";
|
|
43
48
|
RedundancyLevel[RedundancyLevel["INSANE"] = 3] = "INSANE";
|
|
44
49
|
RedundancyLevel[RedundancyLevel["PARANOID"] = 4] = "PARANOID";
|
|
45
|
-
})(RedundancyLevel
|
|
50
|
+
})(RedundancyLevel || (exports.RedundancyLevel = RedundancyLevel = {}));
|
|
46
51
|
/**
|
|
47
52
|
* Specify the retrieve strategy on redundant data.
|
|
48
53
|
* The possible values are NONE, DATA, PROX and RACE.
|
|
@@ -59,7 +64,7 @@ var RedundancyStrategy;
|
|
|
59
64
|
RedundancyStrategy[RedundancyStrategy["DATA"] = 1] = "DATA";
|
|
60
65
|
RedundancyStrategy[RedundancyStrategy["PROX"] = 2] = "PROX";
|
|
61
66
|
RedundancyStrategy[RedundancyStrategy["RACE"] = 3] = "RACE";
|
|
62
|
-
})(RedundancyStrategy
|
|
67
|
+
})(RedundancyStrategy || (exports.RedundancyStrategy = RedundancyStrategy = {}));
|
|
63
68
|
exports.capacityBreakpoints = {
|
|
64
69
|
ENCRYPTION_OFF: {
|
|
65
70
|
[RedundancyLevel.OFF]: [
|
package/dist/cjs/utils/bytes.js
CHANGED
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
2
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
6
|
+
exports.Bytes = void 0;
|
|
7
|
+
exports.parseSizeToBytes = parseSizeToBytes;
|
|
4
8
|
const cafe_utility_1 = require("cafe-utility");
|
|
9
|
+
const debug_1 = __importDefault(require("debug"));
|
|
10
|
+
const debug = (0, debug_1.default)('bee-js:bytes');
|
|
5
11
|
const DECODER = new TextDecoder();
|
|
6
12
|
const ENCODER = new TextEncoder();
|
|
7
13
|
class Bytes {
|
|
8
14
|
constructor(bytes, byteLength) {
|
|
15
|
+
if (!bytes) {
|
|
16
|
+
throw Error(`Bytes#constructor: constructor parameter is falsy: ${bytes}`);
|
|
17
|
+
}
|
|
9
18
|
if (bytes instanceof Bytes) {
|
|
10
19
|
this.bytes = bytes.bytes;
|
|
11
20
|
}
|
|
@@ -15,9 +24,21 @@ class Bytes {
|
|
|
15
24
|
else if (bytes instanceof ArrayBuffer) {
|
|
16
25
|
this.bytes = new Uint8Array(bytes);
|
|
17
26
|
}
|
|
18
|
-
else {
|
|
27
|
+
else if (bytes instanceof Uint8Array) {
|
|
19
28
|
this.bytes = bytes;
|
|
20
29
|
}
|
|
30
|
+
else {
|
|
31
|
+
const unknownInput = bytes;
|
|
32
|
+
const toHex = cafe_utility_1.Objects.getDeep(unknownInput, 'toHex');
|
|
33
|
+
if (cafe_utility_1.Types.isFunction(toHex)) {
|
|
34
|
+
const hex = toHex.call(unknownInput);
|
|
35
|
+
this.bytes = cafe_utility_1.Binary.hexToUint8Array(cafe_utility_1.Types.asHexString(hex, { name: 'Bytes#constructor(bytes)' }));
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
debug('bytes', bytes);
|
|
39
|
+
throw new Error(`Bytes#constructor: unsupported type: ${typeof bytes}`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
21
42
|
this.length = this.bytes.length;
|
|
22
43
|
if (byteLength) {
|
|
23
44
|
if (Array.isArray(byteLength)) {
|
|
@@ -91,4 +112,3 @@ function parseSizeToBytes(sizeStr) {
|
|
|
91
112
|
const unit = match[2];
|
|
92
113
|
return Math.ceil(value * units[unit]);
|
|
93
114
|
}
|
|
94
|
-
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,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;
|
|
@@ -6,7 +6,7 @@ class Duration {
|
|
|
6
6
|
constructor(seconds) {
|
|
7
7
|
this.seconds = Math.ceil(seconds);
|
|
8
8
|
if (seconds < 0) {
|
|
9
|
-
|
|
9
|
+
this.seconds = 0;
|
|
10
10
|
}
|
|
11
11
|
}
|
|
12
12
|
static fromMilliseconds(milliseconds) {
|
|
@@ -30,6 +30,32 @@ class Duration {
|
|
|
30
30
|
static fromEndDate(endDate, startDate) {
|
|
31
31
|
return new Duration((endDate.getTime() - (startDate ?? new Date()).getTime()) / 1000);
|
|
32
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Parses a duration string and returns a `Duration` instance.
|
|
35
|
+
*
|
|
36
|
+
* Case insensitive. E.g. both `"28h"` and `"1D"` are valid.
|
|
37
|
+
*
|
|
38
|
+
* Whitespaces are ignored. E.g. both `"5 d"` and `"2weeks"` are valid.
|
|
39
|
+
*
|
|
40
|
+
* Decimal numbers are supported. E.g. `"1.5h"` is valid.
|
|
41
|
+
*
|
|
42
|
+
* Supported units:
|
|
43
|
+
*
|
|
44
|
+
* - ms, milli, millis, millisecond, milliseconds
|
|
45
|
+
* - s, sec, second, seconds
|
|
46
|
+
* - m, min, minute, minutes
|
|
47
|
+
* - h, hour, hours
|
|
48
|
+
* - d, day, days
|
|
49
|
+
* - w, week, weeks
|
|
50
|
+
* - month, months
|
|
51
|
+
* - y, year, years
|
|
52
|
+
*
|
|
53
|
+
* @param duration - A string representing a duration
|
|
54
|
+
* @returns a `Duration` instance
|
|
55
|
+
*/
|
|
56
|
+
static parseFromString(duration) {
|
|
57
|
+
return Duration.fromSeconds(cafe_utility_1.Dates.make(duration) / 1000);
|
|
58
|
+
}
|
|
33
59
|
toSeconds() {
|
|
34
60
|
return this.seconds;
|
|
35
61
|
}
|
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;
|