@upcoming/bee-js 0.3.0 → 0.5.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-dev.js +78 -0
- package/dist/cjs/bee.js +69 -113
- package/dist/cjs/feed/retrievable.js +4 -4
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/modules/bytes.js +12 -4
- package/dist/cjs/modules/bzz.js +12 -27
- package/dist/cjs/modules/chunk.js +6 -3
- package/dist/cjs/modules/debug/connectivity.js +2 -1
- package/dist/cjs/modules/feed.js +1 -1
- package/dist/cjs/modules/grantee.js +9 -8
- package/dist/cjs/modules/pss.js +1 -1
- package/dist/cjs/modules/soc.js +4 -2
- package/dist/cjs/utils/collection.js +1 -1
- package/dist/cjs/utils/collection.node.js +0 -1
- package/dist/cjs/utils/expose.js +2 -1
- package/dist/cjs/utils/headers.js +61 -54
- package/dist/cjs/utils/http.js +9 -0
- package/dist/cjs/utils/tar-uploader.browser.js +2 -2
- package/dist/cjs/utils/tar-uploader.js +2 -2
- package/dist/cjs/utils/type.js +119 -191
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-dev.js +98 -0
- package/dist/mjs/bee.js +75 -117
- package/dist/mjs/feed/retrievable.js +4 -4
- package/dist/mjs/index.js +2 -1
- package/dist/mjs/modules/bytes.js +13 -7
- package/dist/mjs/modules/bzz.js +9 -25
- package/dist/mjs/modules/chunk.js +7 -6
- package/dist/mjs/modules/debug/connectivity.js +1 -1
- package/dist/mjs/modules/feed.js +2 -2
- package/dist/mjs/modules/grantee.js +12 -11
- package/dist/mjs/modules/pss.js +2 -2
- package/dist/mjs/modules/soc.js +4 -4
- package/dist/mjs/utils/collection.js +1 -1
- package/dist/mjs/utils/collection.node.js +0 -1
- package/dist/mjs/utils/expose.js +1 -1
- package/dist/mjs/utils/headers.js +59 -50
- package/dist/mjs/utils/http.js +9 -0
- package/dist/mjs/utils/tar-uploader.browser.js +2 -2
- package/dist/mjs/utils/tar-uploader.js +2 -2
- package/dist/mjs/utils/type.js +202 -163
- package/dist/types/bee-dev.d.ts +5 -0
- package/dist/types/bee.d.ts +21 -21
- package/dist/types/feed/retrievable.d.ts +2 -2
- package/dist/types/index.d.ts +3 -1
- package/dist/types/modules/bytes.d.ts +4 -4
- package/dist/types/modules/bzz.d.ts +5 -10
- package/dist/types/modules/chunk.d.ts +2 -2
- package/dist/types/modules/debug/chequebook.d.ts +2 -2
- package/dist/types/modules/debug/connectivity.d.ts +2 -1
- package/dist/types/modules/grantee.d.ts +4 -4
- package/dist/types/types/debug.d.ts +0 -1
- package/dist/types/types/index.d.ts +12 -6
- package/dist/types/utils/collection.d.ts +1 -1
- package/dist/types/utils/collection.node.d.ts +0 -1
- package/dist/types/utils/expose.d.ts +1 -1
- package/dist/types/utils/headers.d.ts +2 -4
- package/dist/types/utils/tar-uploader.browser.d.ts +2 -2
- package/dist/types/utils/tar-uploader.d.ts +2 -2
- package/dist/types/utils/type.d.ts +12 -18
- package/package.json +2 -2
|
@@ -12,9 +12,9 @@ const index_1 = require("./index");
|
|
|
12
12
|
* @param ref
|
|
13
13
|
* @param options
|
|
14
14
|
*/
|
|
15
|
-
async function isChunkRetrievable(bee, reference, requestOptions) {
|
|
15
|
+
async function isChunkRetrievable(bee, reference, options, requestOptions) {
|
|
16
16
|
try {
|
|
17
|
-
await bee.downloadChunk(reference, requestOptions);
|
|
17
|
+
await bee.downloadChunk(reference, options, requestOptions);
|
|
18
18
|
return true;
|
|
19
19
|
}
|
|
20
20
|
catch (e) {
|
|
@@ -40,8 +40,8 @@ function getAllSequenceUpdateReferences(owner, topic, index) {
|
|
|
40
40
|
}
|
|
41
41
|
return updateReferences;
|
|
42
42
|
}
|
|
43
|
-
async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, requestOptions) {
|
|
44
|
-
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async (reference) => isChunkRetrievable(bee, reference, requestOptions));
|
|
43
|
+
async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options, requestOptions) {
|
|
44
|
+
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async (reference) => isChunkRetrievable(bee, reference, options, requestOptions));
|
|
45
45
|
return (await Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
46
46
|
}
|
|
47
47
|
exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
|
package/dist/cjs/index.js
CHANGED
|
@@ -26,9 +26,11 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
26
26
|
return result;
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
-
exports.Bee = exports.Utils = exports.Bytes = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.MantarayNode = exports.MerkleTree = void 0;
|
|
29
|
+
exports.BeeDev = exports.Bee = exports.Utils = exports.Bytes = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.MantarayNode = exports.MerkleTree = void 0;
|
|
30
30
|
const bee_1 = require("./bee");
|
|
31
31
|
Object.defineProperty(exports, "Bee", { enumerable: true, get: function () { return bee_1.Bee; } });
|
|
32
|
+
const bee_dev_1 = require("./bee-dev");
|
|
33
|
+
Object.defineProperty(exports, "BeeDev", { enumerable: true, get: function () { return bee_dev_1.BeeDev; } });
|
|
32
34
|
var cafe_utility_1 = require("cafe-utility");
|
|
33
35
|
Object.defineProperty(exports, "MerkleTree", { enumerable: true, get: function () { return cafe_utility_1.MerkleTree; } });
|
|
34
36
|
var manifest_1 = require("./manifest/manifest");
|
|
@@ -24,14 +24,16 @@ async function upload(requestOptions, data, postageBatchId, options) {
|
|
|
24
24
|
data,
|
|
25
25
|
headers: {
|
|
26
26
|
'content-type': 'application/octet-stream',
|
|
27
|
-
...(0, headers_1.
|
|
27
|
+
...(0, headers_1.prepareRequestHeaders)(postageBatchId, options),
|
|
28
28
|
},
|
|
29
29
|
});
|
|
30
30
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
31
31
|
return {
|
|
32
32
|
reference: new typed_bytes_1.Reference(cafe_utility_1.Types.asHexString(body.reference)),
|
|
33
33
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
34
|
-
historyAddress: response.headers['swarm-act-history-address']
|
|
34
|
+
historyAddress: response.headers['swarm-act-history-address']
|
|
35
|
+
? cafe_utility_1.Optional.of(new typed_bytes_1.Reference(response.headers['swarm-act-history-address']))
|
|
36
|
+
: cafe_utility_1.Optional.empty(),
|
|
35
37
|
};
|
|
36
38
|
}
|
|
37
39
|
exports.upload = upload;
|
|
@@ -61,10 +63,13 @@ exports.head = head;
|
|
|
61
63
|
*/
|
|
62
64
|
async function download(requestOptions, reference, options) {
|
|
63
65
|
reference = new typed_bytes_1.Reference(reference);
|
|
66
|
+
if (options) {
|
|
67
|
+
options = (0, type_1.prepareDownloadOptions)(options);
|
|
68
|
+
}
|
|
64
69
|
const response = await (0, http_1.http)(requestOptions, {
|
|
65
70
|
responseType: 'arraybuffer',
|
|
66
71
|
url: `${endpoint}/${reference}`,
|
|
67
|
-
headers: (0, headers_1.
|
|
72
|
+
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
68
73
|
});
|
|
69
74
|
return new bytes_1.Bytes(response.data);
|
|
70
75
|
}
|
|
@@ -77,10 +82,13 @@ exports.download = download;
|
|
|
77
82
|
*/
|
|
78
83
|
async function downloadReadable(requestOptions, reference, options) {
|
|
79
84
|
reference = new typed_bytes_1.Reference(reference);
|
|
85
|
+
if (options) {
|
|
86
|
+
options = (0, type_1.prepareDownloadOptions)(options);
|
|
87
|
+
}
|
|
80
88
|
const response = await (0, http_1.http)(requestOptions, {
|
|
81
89
|
responseType: 'stream',
|
|
82
90
|
url: `${endpoint}/${reference}`,
|
|
83
|
-
headers: (0, headers_1.
|
|
91
|
+
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
84
92
|
});
|
|
85
93
|
return response.data;
|
|
86
94
|
}
|
package/dist/cjs/modules/bzz.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.uploadCollection = exports.
|
|
3
|
+
exports.uploadCollection = exports.downloadFileReadable = exports.downloadFile = exports.uploadFile = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const bytes_1 = require("../utils/bytes");
|
|
6
6
|
const collection_1 = require("../utils/collection");
|
|
@@ -10,14 +10,6 @@ const tar_uploader_1 = require("../utils/tar-uploader");
|
|
|
10
10
|
const type_1 = require("../utils/type");
|
|
11
11
|
const typed_bytes_1 = require("../utils/typed-bytes");
|
|
12
12
|
const bzzEndpoint = 'bzz';
|
|
13
|
-
function extractFileUploadHeaders(postageBatchId, options) {
|
|
14
|
-
const headers = (0, headers_1.extractRedundantUploadHeaders)(postageBatchId, options);
|
|
15
|
-
if (options?.size)
|
|
16
|
-
headers['content-length'] = String(options.size);
|
|
17
|
-
if (options?.contentType)
|
|
18
|
-
headers['content-type'] = options.contentType;
|
|
19
|
-
return headers;
|
|
20
|
-
}
|
|
21
13
|
/**
|
|
22
14
|
* Upload single file
|
|
23
15
|
*
|
|
@@ -38,9 +30,7 @@ async function uploadFile(requestOptions, data, postageBatchId, name, options) {
|
|
|
38
30
|
method: 'post',
|
|
39
31
|
url: bzzEndpoint,
|
|
40
32
|
data,
|
|
41
|
-
headers:
|
|
42
|
-
...extractFileUploadHeaders(postageBatchId, options),
|
|
43
|
-
},
|
|
33
|
+
headers: (0, headers_1.prepareRequestHeaders)(postageBatchId, options),
|
|
44
34
|
params: { name },
|
|
45
35
|
responseType: 'json',
|
|
46
36
|
});
|
|
@@ -48,7 +38,9 @@ async function uploadFile(requestOptions, data, postageBatchId, name, options) {
|
|
|
48
38
|
return {
|
|
49
39
|
reference: new typed_bytes_1.Reference(cafe_utility_1.Types.asHexString(body.reference)),
|
|
50
40
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
51
|
-
historyAddress: response.headers['swarm-act-history-address']
|
|
41
|
+
historyAddress: response.headers['swarm-act-history-address']
|
|
42
|
+
? cafe_utility_1.Optional.of(new typed_bytes_1.Reference(response.headers['swarm-act-history-address']))
|
|
43
|
+
: cafe_utility_1.Optional.empty(),
|
|
52
44
|
};
|
|
53
45
|
}
|
|
54
46
|
exports.uploadFile = uploadFile;
|
|
@@ -65,7 +57,7 @@ async function downloadFile(requestOptions, reference, path = '', options) {
|
|
|
65
57
|
method: 'GET',
|
|
66
58
|
responseType: 'arraybuffer',
|
|
67
59
|
url: `${bzzEndpoint}/${reference}/${path}`,
|
|
68
|
-
headers: (0, headers_1.
|
|
60
|
+
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
69
61
|
});
|
|
70
62
|
const file = {
|
|
71
63
|
...(0, headers_1.readFileHeaders)(response.headers),
|
|
@@ -87,7 +79,7 @@ async function downloadFileReadable(requestOptions, reference, path = '', option
|
|
|
87
79
|
method: 'GET',
|
|
88
80
|
responseType: 'stream',
|
|
89
81
|
url: `${bzzEndpoint}/${reference}/${path}`,
|
|
90
|
-
headers: (0, headers_1.
|
|
82
|
+
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
91
83
|
});
|
|
92
84
|
const file = {
|
|
93
85
|
...(0, headers_1.readFileHeaders)(response.headers),
|
|
@@ -96,17 +88,8 @@ async function downloadFileReadable(requestOptions, reference, path = '', option
|
|
|
96
88
|
return file;
|
|
97
89
|
}
|
|
98
90
|
exports.downloadFileReadable = downloadFileReadable;
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
if (options?.indexDocument) {
|
|
102
|
-
headers['swarm-index-document'] = options.indexDocument;
|
|
103
|
-
}
|
|
104
|
-
if (options?.errorDocument) {
|
|
105
|
-
headers['swarm-error-document'] = options.errorDocument;
|
|
106
|
-
}
|
|
107
|
-
return headers;
|
|
108
|
-
}
|
|
109
|
-
exports.extractCollectionUploadHeaders = extractCollectionUploadHeaders;
|
|
91
|
+
/*******************************************************************************************************************/
|
|
92
|
+
// Collections
|
|
110
93
|
/**
|
|
111
94
|
* Upload collection
|
|
112
95
|
* @param requestOptions Options for making requests
|
|
@@ -121,7 +104,9 @@ async function uploadCollection(requestOptions, collection, postageBatchId, opti
|
|
|
121
104
|
return {
|
|
122
105
|
reference: new typed_bytes_1.Reference(cafe_utility_1.Types.asHexString(body.reference)),
|
|
123
106
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
124
|
-
historyAddress: response.headers['swarm-act-history-address']
|
|
107
|
+
historyAddress: response.headers['swarm-act-history-address']
|
|
108
|
+
? cafe_utility_1.Optional.of(new typed_bytes_1.Reference(response.headers['swarm-act-history-address']))
|
|
109
|
+
: cafe_utility_1.Optional.empty(),
|
|
125
110
|
};
|
|
126
111
|
}
|
|
127
112
|
exports.uploadCollection = uploadCollection;
|
|
@@ -26,7 +26,7 @@ async function upload(requestOptions, data, stamp, options) {
|
|
|
26
26
|
data,
|
|
27
27
|
headers: {
|
|
28
28
|
'content-type': 'application/octet-stream',
|
|
29
|
-
...(0, headers_1.
|
|
29
|
+
...(0, headers_1.prepareRequestHeaders)(stamp, options),
|
|
30
30
|
},
|
|
31
31
|
responseType: 'json',
|
|
32
32
|
});
|
|
@@ -34,7 +34,9 @@ async function upload(requestOptions, data, stamp, options) {
|
|
|
34
34
|
return {
|
|
35
35
|
reference: new typed_bytes_1.Reference(cafe_utility_1.Types.asString(body.reference, { name: 'reference' })),
|
|
36
36
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
37
|
-
historyAddress: response.headers['swarm-act-history-address']
|
|
37
|
+
historyAddress: response.headers['swarm-act-history-address']
|
|
38
|
+
? cafe_utility_1.Optional.of(new typed_bytes_1.Reference(response.headers['swarm-act-history-address']))
|
|
39
|
+
: cafe_utility_1.Optional.empty(),
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
exports.upload = upload;
|
|
@@ -45,11 +47,12 @@ exports.upload = upload;
|
|
|
45
47
|
* @param hash Bee content reference
|
|
46
48
|
*
|
|
47
49
|
*/
|
|
48
|
-
async function download(requestOptions, reference) {
|
|
50
|
+
async function download(requestOptions, reference, options) {
|
|
49
51
|
reference = new typed_bytes_1.Reference(reference);
|
|
50
52
|
const response = await (0, http_1.http)(requestOptions, {
|
|
51
53
|
responseType: 'arraybuffer',
|
|
52
54
|
url: `${endpoint}/${reference}`,
|
|
55
|
+
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
53
56
|
});
|
|
54
57
|
return new Uint8Array(response.data);
|
|
55
58
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.pingPeer = exports.getTopology = exports.removePeer = exports.getBlocklist = exports.getPeers = exports.getNodeAddresses = void 0;
|
|
3
|
+
exports.asBin = exports.pingPeer = exports.getTopology = exports.removePeer = exports.getBlocklist = exports.getPeers = exports.getNodeAddresses = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const http_1 = require("../../utils/http");
|
|
6
6
|
const typed_bytes_1 = require("../../utils/typed-bytes");
|
|
@@ -129,3 +129,4 @@ function asBin(value, name) {
|
|
|
129
129
|
})),
|
|
130
130
|
};
|
|
131
131
|
}
|
|
132
|
+
exports.asBin = asBin;
|
package/dist/cjs/modules/feed.js
CHANGED
|
@@ -22,7 +22,7 @@ async function createFeedManifest(requestOptions, owner, topic, stamp, options)
|
|
|
22
22
|
method: 'post',
|
|
23
23
|
responseType: 'json',
|
|
24
24
|
url: `${feedEndpoint}/${owner}/${topic}`,
|
|
25
|
-
headers: (0, headers_1.
|
|
25
|
+
headers: (0, headers_1.prepareRequestHeaders)(stamp, options),
|
|
26
26
|
});
|
|
27
27
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
28
28
|
return new typed_bytes_1.Reference(cafe_utility_1.Types.asHexString(body.reference));
|
|
@@ -12,11 +12,11 @@ async function getGrantees(reference, requestOptions) {
|
|
|
12
12
|
url: `${granteeEndpoint}/${reference}`,
|
|
13
13
|
responseType: 'json',
|
|
14
14
|
});
|
|
15
|
-
const body = cafe_utility_1.Types.asArray(response.data, { name: 'response.data' }).map(x => cafe_utility_1.Types.asString(x, { name: 'grantee' }));
|
|
15
|
+
const body = cafe_utility_1.Types.asArray(response.data, { name: 'response.data' }).map(x => new typed_bytes_1.PublicKey(cafe_utility_1.Types.asString(x, { name: 'grantee' })));
|
|
16
16
|
return {
|
|
17
17
|
status: response.status,
|
|
18
18
|
statusText: response.statusText,
|
|
19
|
-
|
|
19
|
+
grantees: body,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
exports.getGrantees = getGrantees;
|
|
@@ -24,10 +24,8 @@ async function createGrantees(requestOptions, postageBatchId, grantees) {
|
|
|
24
24
|
const response = await (0, http_1.http)(requestOptions, {
|
|
25
25
|
method: 'post',
|
|
26
26
|
url: granteeEndpoint,
|
|
27
|
-
data: { grantees },
|
|
28
|
-
headers:
|
|
29
|
-
...(0, headers_1.extractRedundantUploadHeaders)(postageBatchId),
|
|
30
|
-
},
|
|
27
|
+
data: { grantees: grantees.map(x => x.toCompressedHex()) },
|
|
28
|
+
headers: (0, headers_1.prepareRequestHeaders)(postageBatchId),
|
|
31
29
|
responseType: 'json',
|
|
32
30
|
});
|
|
33
31
|
const body = cafe_utility_1.Types.asObject(response.data, { name: 'response.data' });
|
|
@@ -43,9 +41,12 @@ async function patchGrantees(postageBatchId, reference, historyRef, grantees, re
|
|
|
43
41
|
const response = await (0, http_1.http)(requestOptions, {
|
|
44
42
|
method: 'patch',
|
|
45
43
|
url: `${granteeEndpoint}/${reference}`,
|
|
46
|
-
data:
|
|
44
|
+
data: {
|
|
45
|
+
add: grantees.add?.map(x => x.toCompressedHex()),
|
|
46
|
+
revoke: grantees.revoke?.map(x => x.toCompressedHex()),
|
|
47
|
+
},
|
|
47
48
|
headers: {
|
|
48
|
-
...(0, headers_1.
|
|
49
|
+
...(0, headers_1.prepareRequestHeaders)(postageBatchId),
|
|
49
50
|
'swarm-act-history-address': historyRef.toHex(),
|
|
50
51
|
},
|
|
51
52
|
responseType: 'json',
|
package/dist/cjs/modules/pss.js
CHANGED
|
@@ -26,7 +26,7 @@ async function send(requestOptions, topic, target, data, postageBatchId, recipie
|
|
|
26
26
|
data,
|
|
27
27
|
responseType: 'json',
|
|
28
28
|
params: { recipient },
|
|
29
|
-
headers: (0, headers_1.
|
|
29
|
+
headers: (0, headers_1.prepareRequestHeaders)(postageBatchId),
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
exports.send = send;
|
package/dist/cjs/modules/soc.js
CHANGED
|
@@ -25,7 +25,7 @@ async function upload(requestOptions, owner, identifier, signature, data, stamp,
|
|
|
25
25
|
data,
|
|
26
26
|
headers: {
|
|
27
27
|
'content-type': 'application/octet-stream',
|
|
28
|
-
...(0, headers_1.
|
|
28
|
+
...(0, headers_1.prepareRequestHeaders)(stamp, options),
|
|
29
29
|
},
|
|
30
30
|
responseType: 'json',
|
|
31
31
|
params: { sig: signature.toHex() },
|
|
@@ -34,7 +34,9 @@ async function upload(requestOptions, owner, identifier, signature, data, stamp,
|
|
|
34
34
|
return {
|
|
35
35
|
reference: new typed_bytes_1.Reference(cafe_utility_1.Types.asHexString(body.reference)),
|
|
36
36
|
tagUid: response.headers['swarm-tag'] ? (0, type_1.makeTagUid)(response.headers['swarm-tag']) : undefined,
|
|
37
|
-
historyAddress: response.headers['swarm-act-history-address']
|
|
37
|
+
historyAddress: response.headers['swarm-act-history-address']
|
|
38
|
+
? cafe_utility_1.Optional.of(new typed_bytes_1.Reference(response.headers['swarm-act-history-address']))
|
|
39
|
+
: cafe_utility_1.Optional.empty(),
|
|
38
40
|
};
|
|
39
41
|
}
|
|
40
42
|
exports.upload = upload;
|
|
@@ -25,7 +25,7 @@ function makeFilePath(file) {
|
|
|
25
25
|
throw new TypeError('file is not valid File object');
|
|
26
26
|
}
|
|
27
27
|
exports.makeFilePath = makeFilePath;
|
|
28
|
-
|
|
28
|
+
function makeCollectionFromFileList(fileList) {
|
|
29
29
|
return Array.from(fileList).map(file => ({
|
|
30
30
|
path: makeFilePath(file),
|
|
31
31
|
size: file.size,
|
|
@@ -8,7 +8,6 @@ const fs_1 = __importDefault(require("fs"));
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
/**
|
|
10
10
|
* Creates array in the format of Collection with data loaded from directory on filesystem.
|
|
11
|
-
* The function loads all the data into memory!
|
|
12
11
|
*
|
|
13
12
|
* @param dir path to the directory
|
|
14
13
|
*/
|
package/dist/cjs/utils/expose.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.getStampCost = exports.getDepthForCapacity = exports.getAmountForTtl = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.makeMaxTarget = exports.getFolderSize = exports.getCollectionSize = void 0;
|
|
3
|
+
exports.getStampUsage = exports.getStampTtlSeconds = exports.getStampMaximumCapacityBytes = exports.getStampEffectiveBytes = exports.getStampCost = exports.getDepthForCapacity = exports.getAmountForTtl = 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
|
+
Object.defineProperty(exports, "makeCollectionFromFileList", { enumerable: true, get: function () { return collection_1.makeCollectionFromFileList; } });
|
|
6
7
|
var collection_node_1 = require("./collection.node");
|
|
7
8
|
Object.defineProperty(exports, "getFolderSize", { enumerable: true, get: function () { return collection_node_1.getFolderSize; } });
|
|
8
9
|
var pss_1 = require("./pss");
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.prepareRequestHeaders = exports.readFileHeaders = void 0;
|
|
4
4
|
const cafe_utility_1 = require("cafe-utility");
|
|
5
5
|
const error_1 = require("./error");
|
|
6
6
|
const stamps_1 = require("./stamps");
|
|
7
7
|
const typed_bytes_1 = require("./typed-bytes");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
function readFileHeaders(headers) {
|
|
9
|
+
const name = readContentDispositionFilename(headers['content-disposition']);
|
|
10
|
+
const tagUid = readTagUid(headers['swarm-tag-uid']);
|
|
11
|
+
const contentType = headers['content-type'] || undefined;
|
|
12
|
+
return {
|
|
13
|
+
name,
|
|
14
|
+
tagUid,
|
|
15
|
+
contentType,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
exports.readFileHeaders = readFileHeaders;
|
|
16
19
|
function readContentDispositionFilename(header) {
|
|
17
20
|
if (!header) {
|
|
18
21
|
throw new error_1.BeeError('missing content-disposition header');
|
|
@@ -31,47 +34,73 @@ function readTagUid(header) {
|
|
|
31
34
|
}
|
|
32
35
|
return parseInt(header, 10);
|
|
33
36
|
}
|
|
34
|
-
function
|
|
35
|
-
const name = readContentDispositionFilename(headers['content-disposition']);
|
|
36
|
-
const tagUid = readTagUid(headers['swarm-tag-uid']);
|
|
37
|
-
const contentType = headers['content-type'] || undefined;
|
|
38
|
-
return {
|
|
39
|
-
name,
|
|
40
|
-
tagUid,
|
|
41
|
-
contentType,
|
|
42
|
-
};
|
|
43
|
-
}
|
|
44
|
-
exports.readFileHeaders = readFileHeaders;
|
|
45
|
-
function extractUploadHeaders(stamp, options) {
|
|
46
|
-
if (!stamp) {
|
|
47
|
-
throw new error_1.BeeError('Stamp has to be specified!');
|
|
48
|
-
}
|
|
37
|
+
function prepareRequestHeaders(stamp, nullableOptions) {
|
|
49
38
|
const headers = {};
|
|
50
39
|
if (isEnvelopeWithBatchId(stamp)) {
|
|
51
40
|
headers['swarm-postage-stamp'] = (0, stamps_1.convertEnvelopeToMarshaledStamp)(stamp).toHex();
|
|
52
41
|
}
|
|
53
|
-
else {
|
|
42
|
+
else if (stamp) {
|
|
54
43
|
stamp = new typed_bytes_1.BatchId(stamp);
|
|
55
44
|
headers['swarm-postage-batch-id'] = stamp.toHex();
|
|
56
45
|
}
|
|
57
|
-
if (
|
|
46
|
+
if (!nullableOptions) {
|
|
47
|
+
return headers;
|
|
48
|
+
}
|
|
49
|
+
const options = cafe_utility_1.Types.asObject(nullableOptions);
|
|
50
|
+
if (options.size) {
|
|
51
|
+
headers['content-length'] = String(options.size);
|
|
52
|
+
}
|
|
53
|
+
if (options.contentType) {
|
|
54
|
+
headers['content-type'] = String(options.contentType);
|
|
55
|
+
}
|
|
56
|
+
if (options.redundancyLevel) {
|
|
57
|
+
headers['swarm-redundancy-level'] = String(options.redundancyLevel);
|
|
58
|
+
}
|
|
59
|
+
if (cafe_utility_1.Types.isBoolean(options.act)) {
|
|
58
60
|
headers['swarm-act'] = String(options.act);
|
|
59
61
|
}
|
|
60
|
-
if (options
|
|
62
|
+
if (cafe_utility_1.Types.isBoolean(options.pin)) {
|
|
61
63
|
headers['swarm-pin'] = String(options.pin);
|
|
62
64
|
}
|
|
63
|
-
if (options
|
|
64
|
-
headers['swarm-encrypt'] =
|
|
65
|
+
if (cafe_utility_1.Types.isBoolean(options.encrypt)) {
|
|
66
|
+
headers['swarm-encrypt'] = options.encrypt.toString();
|
|
65
67
|
}
|
|
66
|
-
if (options
|
|
68
|
+
if (options.tag) {
|
|
67
69
|
headers['swarm-tag'] = String(options.tag);
|
|
68
70
|
}
|
|
69
|
-
if (
|
|
71
|
+
if (cafe_utility_1.Types.isBoolean(options.deferred)) {
|
|
70
72
|
headers['swarm-deferred-upload'] = options.deferred.toString();
|
|
71
73
|
}
|
|
74
|
+
if (options.redundancyStrategy) {
|
|
75
|
+
headers['swarm-redundancy-strategy'] = String(options.redundancyStrategy);
|
|
76
|
+
}
|
|
77
|
+
if (cafe_utility_1.Types.isBoolean(options.fallback)) {
|
|
78
|
+
headers['swarm-redundancy-fallback-mode'] = options.fallback.toString();
|
|
79
|
+
}
|
|
80
|
+
if (options.timeoutMs) {
|
|
81
|
+
headers['swarm-chunk-retrieval-timeout'] = String(options.timeoutMs);
|
|
82
|
+
}
|
|
83
|
+
if (options.indexDocument) {
|
|
84
|
+
headers['swarm-index-document'] = String(options.indexDocument);
|
|
85
|
+
}
|
|
86
|
+
if (options.errorDocument) {
|
|
87
|
+
headers['swarm-error-document'] = String(options.errorDocument);
|
|
88
|
+
}
|
|
89
|
+
if (options.actPublisher) {
|
|
90
|
+
headers['swarm-act-publisher'] = new typed_bytes_1.PublicKey(options.actPublisher).toCompressedHex();
|
|
91
|
+
}
|
|
92
|
+
if (options.actHistoryAddress) {
|
|
93
|
+
headers['swarm-act-history-address'] = new typed_bytes_1.Reference(options.actHistoryAddress).toHex();
|
|
94
|
+
}
|
|
95
|
+
if (options.actTimestamp) {
|
|
96
|
+
headers['swarm-act-timestamp'] = String(options.actTimestamp);
|
|
97
|
+
}
|
|
98
|
+
if (options.actPublisher || options.actHistoryAddress || options.actTimestamp) {
|
|
99
|
+
headers['swarm-act'] = 'true';
|
|
100
|
+
}
|
|
72
101
|
return headers;
|
|
73
102
|
}
|
|
74
|
-
exports.
|
|
103
|
+
exports.prepareRequestHeaders = prepareRequestHeaders;
|
|
75
104
|
function isEnvelopeWithBatchId(value) {
|
|
76
105
|
if (!cafe_utility_1.Types.isObject(value)) {
|
|
77
106
|
return false;
|
|
@@ -83,25 +112,3 @@ function isEnvelopeWithBatchId(value) {
|
|
|
83
112
|
envelope.timestamp !== undefined &&
|
|
84
113
|
envelope.batchId !== undefined);
|
|
85
114
|
}
|
|
86
|
-
function extractRedundantUploadHeaders(postageBatchId, options) {
|
|
87
|
-
const headers = extractUploadHeaders(postageBatchId, options);
|
|
88
|
-
if (options?.redundancyLevel) {
|
|
89
|
-
headers['swarm-redundancy-level'] = String(options.redundancyLevel);
|
|
90
|
-
}
|
|
91
|
-
return headers;
|
|
92
|
-
}
|
|
93
|
-
exports.extractRedundantUploadHeaders = extractRedundantUploadHeaders;
|
|
94
|
-
function extractDownloadHeaders(options) {
|
|
95
|
-
const headers = {};
|
|
96
|
-
if (options?.redundancyStrategy) {
|
|
97
|
-
headers['swarm-redundancy-strategy'] = String(options.redundancyStrategy);
|
|
98
|
-
}
|
|
99
|
-
if (options?.fallback === false) {
|
|
100
|
-
headers['swarm-redundancy-fallback-mode'] = 'false';
|
|
101
|
-
}
|
|
102
|
-
if (options?.timeoutMs !== undefined) {
|
|
103
|
-
headers['swarm-chunk-retrieval-timeout'] = String(options.timeoutMs);
|
|
104
|
-
}
|
|
105
|
-
return headers;
|
|
106
|
-
}
|
|
107
|
-
exports.extractDownloadHeaders = extractDownloadHeaders;
|
package/dist/cjs/utils/http.js
CHANGED
|
@@ -45,6 +45,15 @@ exports.DEFAULT_HTTP_CONFIG = {
|
|
|
45
45
|
*/
|
|
46
46
|
async function http(options, config) {
|
|
47
47
|
const requestConfig = cafe_utility_1.Objects.deepMerge3(exports.DEFAULT_HTTP_CONFIG, config, options);
|
|
48
|
+
if (requestConfig.params) {
|
|
49
|
+
const keys = Object.keys(requestConfig.params);
|
|
50
|
+
for (const key of keys) {
|
|
51
|
+
const value = requestConfig.params[key];
|
|
52
|
+
if (value === undefined) {
|
|
53
|
+
delete requestConfig.params[key];
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
48
57
|
let failedAttempts = 0;
|
|
49
58
|
while (failedAttempts < MAX_FAILED_ATTEMPTS) {
|
|
50
59
|
try {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadTar = void 0;
|
|
4
|
-
const
|
|
4
|
+
const headers_1 = require("./headers");
|
|
5
5
|
const http_1 = require("./http");
|
|
6
6
|
const tar_1 = require("./tar");
|
|
7
7
|
const tar_writer_1 = require("./tar-writer");
|
|
@@ -18,7 +18,7 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
|
18
18
|
headers: {
|
|
19
19
|
'content-type': 'application/x-tar',
|
|
20
20
|
'swarm-collection': 'true',
|
|
21
|
-
...(0,
|
|
21
|
+
...(0, headers_1.prepareRequestHeaders)(postageBatchId, options),
|
|
22
22
|
},
|
|
23
23
|
});
|
|
24
24
|
return response;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.uploadTar = void 0;
|
|
4
|
-
const
|
|
4
|
+
const headers_1 = require("./headers");
|
|
5
5
|
const http_1 = require("./http");
|
|
6
6
|
const tar_1 = require("./tar");
|
|
7
7
|
const tar_writer_1 = require("./tar-writer");
|
|
@@ -16,7 +16,7 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
|
|
|
16
16
|
headers: {
|
|
17
17
|
'content-type': 'application/x-tar',
|
|
18
18
|
'swarm-collection': 'true',
|
|
19
|
-
...(0,
|
|
19
|
+
...(0, headers_1.prepareRequestHeaders)(postageBatchId, options),
|
|
20
20
|
},
|
|
21
21
|
});
|
|
22
22
|
await (0, tar_writer_1.writeTar)(collection, tarStream);
|