@ethersphere/bee-js 5.1.1 → 5.1.2
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 +14 -6
- package/dist/223.index.browser.min.js +3 -0
- package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
- package/dist/223.index.browser.min.js.map +1 -0
- package/dist/cjs/bee-debug.js +208 -312
- package/dist/cjs/bee.js +258 -353
- package/dist/cjs/chunk/signer.js +11 -22
- package/dist/cjs/chunk/soc.js +33 -50
- package/dist/cjs/chunk/span.js +1 -1
- package/dist/cjs/feed/index.js +50 -65
- package/dist/cjs/feed/json.js +8 -21
- package/dist/cjs/feed/retrievable.js +14 -27
- package/dist/cjs/modules/bytes.js +25 -37
- package/dist/cjs/modules/bzz.js +63 -68
- package/dist/cjs/modules/chunk.js +17 -27
- package/dist/cjs/modules/debug/balance.js +24 -41
- package/dist/cjs/modules/debug/chequebook.js +71 -96
- package/dist/cjs/modules/debug/chunk.js +13 -26
- package/dist/cjs/modules/debug/connectivity.js +32 -53
- package/dist/cjs/modules/debug/settlements.js +12 -25
- package/dist/cjs/modules/debug/stake.js +20 -33
- package/dist/cjs/modules/debug/stamps.js +45 -66
- package/dist/cjs/modules/debug/states.js +27 -40
- package/dist/cjs/modules/debug/status.js +53 -80
- package/dist/cjs/modules/debug/tag.js +6 -17
- package/dist/cjs/modules/debug/transactions.js +23 -40
- package/dist/cjs/modules/feed.js +17 -27
- package/dist/cjs/modules/pinning.js +24 -41
- package/dist/cjs/modules/pss.js +9 -20
- package/dist/cjs/modules/soc.js +12 -20
- package/dist/cjs/modules/status.js +4 -15
- package/dist/cjs/modules/stewardship.js +10 -23
- package/dist/cjs/modules/tag.js +28 -47
- package/dist/cjs/utils/collection.browser.js +4 -17
- package/dist/cjs/utils/collection.js +11 -22
- package/dist/cjs/utils/collection.node.js +42 -86
- package/dist/cjs/utils/data.browser.js +46 -59
- package/dist/cjs/utils/data.js +22 -35
- package/dist/cjs/utils/eth.js +31 -43
- package/dist/cjs/utils/file.js +9 -20
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +78 -93
- package/dist/cjs/utils/merge.js +1 -1
- package/dist/cjs/utils/sleep.js +2 -13
- package/dist/cjs/utils/type.js +14 -12
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +1 -3
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +209 -450
- package/dist/mjs/bee.js +256 -491
- package/dist/mjs/chunk/bmt.js +4 -10
- package/dist/mjs/chunk/cac.js +0 -3
- package/dist/mjs/chunk/signer.js +12 -63
- package/dist/mjs/chunk/soc.js +33 -85
- package/dist/mjs/chunk/span.js +3 -6
- package/dist/mjs/feed/identifier.js +0 -6
- package/dist/mjs/feed/index.js +53 -97
- package/dist/mjs/feed/json.js +10 -49
- package/dist/mjs/feed/retrievable.js +13 -64
- package/dist/mjs/feed/topic.js +0 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +25 -65
- package/dist/mjs/modules/bzz.js +64 -108
- package/dist/mjs/modules/chunk.js +17 -54
- package/dist/mjs/modules/debug/balance.js +24 -68
- package/dist/mjs/modules/debug/chequebook.js +75 -138
- package/dist/mjs/modules/debug/chunk.js +13 -51
- package/dist/mjs/modules/debug/connectivity.js +32 -76
- package/dist/mjs/modules/debug/settlements.js +12 -50
- package/dist/mjs/modules/debug/stake.js +20 -61
- package/dist/mjs/modules/debug/stamps.js +47 -94
- package/dist/mjs/modules/debug/states.js +25 -66
- package/dist/mjs/modules/debug/status.js +66 -125
- package/dist/mjs/modules/debug/tag.js +6 -41
- package/dist/mjs/modules/debug/transactions.js +25 -69
- package/dist/mjs/modules/feed.js +17 -57
- package/dist/mjs/modules/pinning.js +24 -68
- package/dist/mjs/modules/pss.js +11 -47
- package/dist/mjs/modules/soc.js +14 -48
- package/dist/mjs/modules/status.js +4 -39
- package/dist/mjs/modules/stewardship.js +10 -47
- package/dist/mjs/modules/tag.js +31 -78
- package/dist/mjs/types/debug.js +0 -1
- package/dist/mjs/types/index.js +0 -4
- package/dist/mjs/utils/bytes.js +6 -14
- package/dist/mjs/utils/collection.browser.js +4 -42
- package/dist/mjs/utils/collection.js +11 -57
- package/dist/mjs/utils/collection.node.js +42 -150
- package/dist/mjs/utils/data.browser.js +49 -94
- package/dist/mjs/utils/data.js +19 -62
- package/dist/mjs/utils/error.js +0 -5
- package/dist/mjs/utils/eth.js +37 -95
- package/dist/mjs/utils/file.js +11 -50
- package/dist/mjs/utils/hash.js +0 -1
- package/dist/mjs/utils/headers.js +6 -14
- package/dist/mjs/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +80 -138
- package/dist/mjs/utils/merge.js +3 -7
- package/dist/mjs/utils/pss.js +0 -2
- package/dist/mjs/utils/reference.js +2 -5
- package/dist/mjs/utils/sleep.js +2 -37
- package/dist/mjs/utils/stream.js +0 -23
- package/dist/mjs/utils/tar.js +2 -5
- package/dist/mjs/utils/type.js +18 -82
- package/dist/mjs/utils/uint64.js +0 -1
- package/dist/mjs/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +2 -2
- package/dist/types/bee.d.ts +2 -26
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +8 -7
- package/dist/types/feed/index.d.ts +9 -8
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/modules/bytes.d.ts +6 -5
- package/dist/types/modules/bzz.d.ts +9 -8
- package/dist/types/modules/chunk.d.ts +5 -4
- package/dist/types/modules/debug/balance.d.ts +10 -9
- package/dist/types/modules/debug/chequebook.d.ts +18 -17
- package/dist/types/modules/debug/chunk.d.ts +6 -5
- package/dist/types/modules/debug/connectivity.d.ts +8 -7
- package/dist/types/modules/debug/settlements.d.ts +6 -5
- package/dist/types/modules/debug/stake.d.ts +5 -4
- package/dist/types/modules/debug/stamps.d.ts +8 -7
- package/dist/types/modules/debug/states.d.ts +8 -7
- package/dist/types/modules/debug/status.d.ts +15 -15
- package/dist/types/modules/debug/tag.d.ts +4 -3
- package/dist/types/modules/debug/transactions.d.ts +6 -5
- package/dist/types/modules/feed.d.ts +4 -3
- package/dist/types/modules/pinning.d.ts +8 -7
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +4 -3
- package/dist/types/modules/tag.d.ts +7 -6
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +30 -34
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +6 -6
- package/package.json +34 -39
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/mjs/feed/json.js
CHANGED
|
@@ -1,37 +1,4 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
import { isError } from "../utils/type.js";
|
|
34
|
-
|
|
35
2
|
function serializeJson(data) {
|
|
36
3
|
try {
|
|
37
4
|
const jsonString = JSON.stringify(data);
|
|
@@ -40,24 +7,18 @@ function serializeJson(data) {
|
|
|
40
7
|
if (isError(e)) {
|
|
41
8
|
e.message = `JsonFeed: ${e.message}`;
|
|
42
9
|
}
|
|
43
|
-
|
|
44
10
|
throw e;
|
|
45
11
|
}
|
|
46
12
|
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
const retrievedData = yield bee.downloadData(feedUpdate.reference);
|
|
52
|
-
return retrievedData.json();
|
|
53
|
-
});
|
|
13
|
+
export async function getJsonData(bee, reader) {
|
|
14
|
+
const feedUpdate = await reader.download();
|
|
15
|
+
const retrievedData = await bee.downloadData(feedUpdate.reference);
|
|
16
|
+
return retrievedData.json();
|
|
54
17
|
}
|
|
55
|
-
export function setJsonData(bee, writer, postageBatchId, data, options) {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return writer.upload(postageBatchId, reference);
|
|
62
|
-
});
|
|
18
|
+
export async function setJsonData(bee, writer, postageBatchId, data, options) {
|
|
19
|
+
const serializedData = serializeJson(data);
|
|
20
|
+
const {
|
|
21
|
+
reference
|
|
22
|
+
} = await bee.uploadData(postageBatchId, serializedData, options);
|
|
23
|
+
return writer.upload(postageBatchId, reference);
|
|
63
24
|
}
|
|
@@ -1,52 +1,16 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
import { getFeedUpdateChunkReference } from "./index.js";
|
|
34
2
|
import { readUint64BigEndian } from "../utils/uint64.js";
|
|
35
3
|
import { bytesToHex } from "../utils/hex.js";
|
|
36
|
-
|
|
37
4
|
function makeNumericIndex(index) {
|
|
38
5
|
if (index instanceof Uint8Array) {
|
|
39
6
|
return readUint64BigEndian(index);
|
|
40
7
|
}
|
|
41
|
-
|
|
42
8
|
if (typeof index === 'string') {
|
|
43
9
|
return parseInt(index);
|
|
44
10
|
}
|
|
45
|
-
|
|
46
11
|
if (typeof index === 'number') {
|
|
47
12
|
return index;
|
|
48
13
|
}
|
|
49
|
-
|
|
50
14
|
throw new TypeError('Unknown type of index!');
|
|
51
15
|
}
|
|
52
16
|
/**
|
|
@@ -57,23 +21,17 @@ function makeNumericIndex(index) {
|
|
|
57
21
|
* @param ref
|
|
58
22
|
* @param options
|
|
59
23
|
*/
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
const err = e;
|
|
69
|
-
|
|
70
|
-
if (err.status === 404) {
|
|
71
|
-
return false;
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
throw e;
|
|
24
|
+
async function isChunkRetrievable(bee, ref, options) {
|
|
25
|
+
try {
|
|
26
|
+
await bee.downloadChunk(ref, options);
|
|
27
|
+
return true;
|
|
28
|
+
} catch (e) {
|
|
29
|
+
const err = e;
|
|
30
|
+
if (err.status === 404) {
|
|
31
|
+
return false;
|
|
75
32
|
}
|
|
76
|
-
|
|
33
|
+
throw e;
|
|
34
|
+
}
|
|
77
35
|
}
|
|
78
36
|
/**
|
|
79
37
|
* Creates array of references for all sequence updates chunk up to the given index.
|
|
@@ -82,24 +40,15 @@ function isChunkRetrievable(bee, ref, options) {
|
|
|
82
40
|
* @param topic
|
|
83
41
|
* @param index
|
|
84
42
|
*/
|
|
85
|
-
|
|
86
|
-
|
|
87
43
|
function getAllSequenceUpdateReferences(owner, topic, index) {
|
|
88
44
|
const numIndex = makeNumericIndex(index);
|
|
89
45
|
const updateReferences = new Array(numIndex + 1);
|
|
90
|
-
|
|
91
46
|
for (let i = 0; i <= numIndex; i++) {
|
|
92
47
|
updateReferences[i] = bytesToHex(getFeedUpdateChunkReference(owner, topic, i));
|
|
93
48
|
}
|
|
94
|
-
|
|
95
49
|
return updateReferences;
|
|
96
50
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
return
|
|
100
|
-
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(ref => __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
return isChunkRetrievable(bee, ref, options);
|
|
102
|
-
}));
|
|
103
|
-
return (yield Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
104
|
-
});
|
|
51
|
+
export async function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
|
|
52
|
+
const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map(async ref => isChunkRetrievable(bee, ref, options));
|
|
53
|
+
return (await Promise.all(chunkRetrievablePromises)).every(result => result);
|
|
105
54
|
}
|
package/dist/mjs/feed/topic.js
CHANGED
|
@@ -9,13 +9,11 @@ export function makeTopic(topic) {
|
|
|
9
9
|
assertBytes(topic, TOPIC_BYTES_LENGTH);
|
|
10
10
|
return bytesToHex(topic, TOPIC_HEX_LENGTH);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
12
|
throw new TypeError('invalid topic');
|
|
14
13
|
}
|
|
15
14
|
export function makeTopicFromString(s) {
|
|
16
15
|
if (typeof s !== 'string') {
|
|
17
16
|
throw new TypeError('topic has to be string!');
|
|
18
17
|
}
|
|
19
|
-
|
|
20
18
|
return bytesToHex(keccak256Hash(s), TOPIC_HEX_LENGTH);
|
|
21
19
|
}
|
package/dist/mjs/index.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Bee } from "./bee.js";
|
|
2
2
|
import { BeeDebug } from "./bee-debug.js";
|
|
3
|
-
|
|
4
|
-
export { Utils_1 as Utils };
|
|
3
|
+
export * as Utils from "./utils/expose.js";
|
|
5
4
|
export * from "./types/index.js";
|
|
6
5
|
export * from "./utils/error.js";
|
|
7
6
|
export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from "./modules/debug/status.js";
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
import { prepareData } from "../utils/data.js";
|
|
34
2
|
import { extractUploadHeaders } from "../utils/headers.js";
|
|
35
3
|
import { http } from "../utils/http.js";
|
|
@@ -39,28 +7,26 @@ const endpoint = 'bytes';
|
|
|
39
7
|
/**
|
|
40
8
|
* Upload data to a Bee node
|
|
41
9
|
*
|
|
42
|
-
* @param
|
|
10
|
+
* @param kyOptions Ky Options for making requests
|
|
43
11
|
* @param data Data to be uploaded
|
|
44
12
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
45
13
|
* @param options Additional options like tag, encryption, pinning
|
|
46
14
|
*/
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
}, extractUploadHeaders(postageBatchId, options))
|
|
58
|
-
});
|
|
59
|
-
return {
|
|
60
|
-
reference: response.data.reference,
|
|
61
|
-
tagUid: makeTagUid(response.headers.get('swarm-tag'))
|
|
62
|
-
};
|
|
15
|
+
export async function upload(kyOptions, data, postageBatchId, options) {
|
|
16
|
+
const response = await http(kyOptions, {
|
|
17
|
+
path: endpoint,
|
|
18
|
+
method: 'post',
|
|
19
|
+
responseType: 'json',
|
|
20
|
+
body: await prepareData(data),
|
|
21
|
+
headers: {
|
|
22
|
+
'content-type': 'application/octet-stream',
|
|
23
|
+
...extractUploadHeaders(postageBatchId, options)
|
|
24
|
+
}
|
|
63
25
|
});
|
|
26
|
+
return {
|
|
27
|
+
reference: response.parsedData.reference,
|
|
28
|
+
tagUid: makeTagUid(response.headers.get('swarm-tag'))
|
|
29
|
+
};
|
|
64
30
|
}
|
|
65
31
|
/**
|
|
66
32
|
* Download data as a byte array
|
|
@@ -68,15 +34,12 @@ export function upload(ky, data, postageBatchId, options) {
|
|
|
68
34
|
* @param ky
|
|
69
35
|
* @param hash Bee content reference
|
|
70
36
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
responseType: 'arraybuffer',
|
|
76
|
-
path: `${endpoint}/${hash}`
|
|
77
|
-
});
|
|
78
|
-
return wrapBytesWithHelpers(new Uint8Array(response.data));
|
|
37
|
+
export async function download(kyOptions, hash) {
|
|
38
|
+
const response = await http(kyOptions, {
|
|
39
|
+
responseType: 'arraybuffer',
|
|
40
|
+
path: `${endpoint}/${hash}`
|
|
79
41
|
});
|
|
42
|
+
return wrapBytesWithHelpers(new Uint8Array(response.parsedData));
|
|
80
43
|
}
|
|
81
44
|
/**
|
|
82
45
|
* Download data as a readable stream
|
|
@@ -84,13 +47,10 @@ export function download(ky, hash) {
|
|
|
84
47
|
* @param ky
|
|
85
48
|
* @param hash Bee content reference
|
|
86
49
|
*/
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
responseType: 'stream',
|
|
92
|
-
path: `${endpoint}/${hash}`
|
|
93
|
-
});
|
|
94
|
-
return response.data;
|
|
50
|
+
export async function downloadReadable(kyOptions, hash) {
|
|
51
|
+
const response = await http(kyOptions, {
|
|
52
|
+
responseType: 'stream',
|
|
53
|
+
path: `${endpoint}/${hash}`
|
|
95
54
|
});
|
|
55
|
+
return response.parsedData;
|
|
96
56
|
}
|
package/dist/mjs/modules/bzz.js
CHANGED
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
import { extractUploadHeaders, readFileHeaders } from "../utils/headers.js";
|
|
34
2
|
import { http } from "../utils/http.js";
|
|
35
3
|
import { prepareData } from "../utils/data.js";
|
|
@@ -39,11 +7,10 @@ import { wrapBytesWithHelpers } from "../utils/bytes.js";
|
|
|
39
7
|
import { isReadable } from "../utils/stream.js";
|
|
40
8
|
import { makeTagUid } from "../utils/type.js";
|
|
41
9
|
const bzzEndpoint = 'bzz';
|
|
42
|
-
|
|
43
10
|
function extractFileUploadHeaders(postageBatchId, options) {
|
|
44
11
|
const headers = extractUploadHeaders(postageBatchId, options);
|
|
45
|
-
if (options
|
|
46
|
-
if (options
|
|
12
|
+
if (options?.size) headers['content-length'] = String(options.size);
|
|
13
|
+
if (options?.contentType) headers['content-type'] = options.contentType;
|
|
47
14
|
return headers;
|
|
48
15
|
}
|
|
49
16
|
/**
|
|
@@ -55,106 +22,95 @@ function extractFileUploadHeaders(postageBatchId, options) {
|
|
|
55
22
|
* @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
|
|
56
23
|
* @param options
|
|
57
24
|
*/
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
},
|
|
75
|
-
responseType: 'json'
|
|
76
|
-
});
|
|
77
|
-
return {
|
|
78
|
-
reference: response.data.reference,
|
|
79
|
-
tagUid: makeTagUid(response.headers.get('swarm-tag'))
|
|
80
|
-
};
|
|
25
|
+
export async function uploadFile(kyOptions, data, postageBatchId, name, options) {
|
|
26
|
+
if (isReadable(data) && !options?.contentType) {
|
|
27
|
+
if (!options) options = {};
|
|
28
|
+
options.contentType = 'application/octet-stream';
|
|
29
|
+
}
|
|
30
|
+
const response = await http(kyOptions, {
|
|
31
|
+
method: 'post',
|
|
32
|
+
path: bzzEndpoint,
|
|
33
|
+
body: await prepareData(data),
|
|
34
|
+
headers: {
|
|
35
|
+
...extractFileUploadHeaders(postageBatchId, options)
|
|
36
|
+
},
|
|
37
|
+
searchParams: {
|
|
38
|
+
name
|
|
39
|
+
},
|
|
40
|
+
responseType: 'json'
|
|
81
41
|
});
|
|
42
|
+
return {
|
|
43
|
+
reference: response.parsedData.reference,
|
|
44
|
+
tagUid: makeTagUid(response.headers.get('swarm-tag'))
|
|
45
|
+
};
|
|
82
46
|
}
|
|
83
47
|
/**
|
|
84
48
|
* Download single file as a buffer
|
|
85
49
|
*
|
|
86
|
-
* @param
|
|
50
|
+
* @param kyOptions Ky Options for making requests
|
|
87
51
|
* @param hash Bee file or collection hash
|
|
88
52
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
89
53
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
responseType: 'arraybuffer',
|
|
96
|
-
path: `${bzzEndpoint}/${hash}/${path}`
|
|
97
|
-
});
|
|
98
|
-
const file = Object.assign(Object.assign({}, readFileHeaders(response.headers)), {
|
|
99
|
-
data: wrapBytesWithHelpers(new Uint8Array(response.data))
|
|
100
|
-
});
|
|
101
|
-
return file;
|
|
54
|
+
export async function downloadFile(kyOptions, hash, path = '') {
|
|
55
|
+
const response = await http(kyOptions, {
|
|
56
|
+
method: 'GET',
|
|
57
|
+
responseType: 'arraybuffer',
|
|
58
|
+
path: `${bzzEndpoint}/${hash}/${path}`
|
|
102
59
|
});
|
|
60
|
+
const file = {
|
|
61
|
+
...readFileHeaders(response.headers),
|
|
62
|
+
data: wrapBytesWithHelpers(new Uint8Array(response.parsedData))
|
|
63
|
+
};
|
|
64
|
+
return file;
|
|
103
65
|
}
|
|
104
66
|
/**
|
|
105
67
|
* Download single file as a readable stream
|
|
106
68
|
*
|
|
107
|
-
* @param
|
|
69
|
+
* @param kyOptions Ky Options for making requests
|
|
108
70
|
* @param hash Bee file or collection hash
|
|
109
71
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
110
72
|
*/
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
responseType: 'stream',
|
|
117
|
-
path: `${bzzEndpoint}/${hash}/${path}`
|
|
118
|
-
});
|
|
119
|
-
const file = Object.assign(Object.assign({}, readFileHeaders(response.headers)), {
|
|
120
|
-
data: response.data
|
|
121
|
-
});
|
|
122
|
-
return file;
|
|
73
|
+
export async function downloadFileReadable(kyOptions, hash, path = '') {
|
|
74
|
+
const response = await http(kyOptions, {
|
|
75
|
+
method: 'GET',
|
|
76
|
+
responseType: 'stream',
|
|
77
|
+
path: `${bzzEndpoint}/${hash}/${path}`
|
|
123
78
|
});
|
|
79
|
+
const file = {
|
|
80
|
+
...readFileHeaders(response.headers),
|
|
81
|
+
data: response.parsedData
|
|
82
|
+
};
|
|
83
|
+
return file;
|
|
124
84
|
}
|
|
125
|
-
|
|
126
85
|
function extractCollectionUploadHeaders(postageBatchId, options) {
|
|
127
86
|
const headers = extractUploadHeaders(postageBatchId, options);
|
|
128
|
-
if (options
|
|
129
|
-
if (options
|
|
87
|
+
if (options?.indexDocument) headers['swarm-index-document'] = options.indexDocument;
|
|
88
|
+
if (options?.errorDocument) headers['swarm-error-document'] = options.errorDocument;
|
|
130
89
|
return headers;
|
|
131
90
|
}
|
|
132
91
|
/**
|
|
133
92
|
* Upload collection
|
|
134
|
-
* @param
|
|
93
|
+
* @param kyOptions Ky Options for making requests
|
|
135
94
|
* @param collection Collection of Uint8Array buffers to upload
|
|
136
95
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
137
96
|
* @param options
|
|
138
97
|
*/
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
'swarm-collection': 'true'
|
|
153
|
-
}, extractCollectionUploadHeaders(postageBatchId, options))
|
|
154
|
-
});
|
|
155
|
-
return {
|
|
156
|
-
reference: response.data.reference,
|
|
157
|
-
tagUid: makeTagUid(response.headers.get('swarm-tag'))
|
|
158
|
-
};
|
|
98
|
+
export async function uploadCollection(kyOptions, collection, postageBatchId, options) {
|
|
99
|
+
assertCollection(collection);
|
|
100
|
+
const tarData = makeTar(collection);
|
|
101
|
+
const response = await http(kyOptions, {
|
|
102
|
+
method: 'post',
|
|
103
|
+
path: bzzEndpoint,
|
|
104
|
+
body: tarData,
|
|
105
|
+
responseType: 'json',
|
|
106
|
+
headers: {
|
|
107
|
+
'content-type': 'application/x-tar',
|
|
108
|
+
'swarm-collection': 'true',
|
|
109
|
+
...extractCollectionUploadHeaders(postageBatchId, options)
|
|
110
|
+
}
|
|
159
111
|
});
|
|
112
|
+
return {
|
|
113
|
+
reference: response.parsedData.reference,
|
|
114
|
+
tagUid: makeTagUid(response.headers.get('swarm-tag'))
|
|
115
|
+
};
|
|
160
116
|
}
|
|
@@ -1,35 +1,3 @@
|
|
|
1
|
-
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) {
|
|
3
|
-
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
-
resolve(value);
|
|
5
|
-
});
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
-
function fulfilled(value) {
|
|
10
|
-
try {
|
|
11
|
-
step(generator.next(value));
|
|
12
|
-
} catch (e) {
|
|
13
|
-
reject(e);
|
|
14
|
-
}
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
function rejected(value) {
|
|
18
|
-
try {
|
|
19
|
-
step(generator["throw"](value));
|
|
20
|
-
} catch (e) {
|
|
21
|
-
reject(e);
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function step(result) {
|
|
26
|
-
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
-
});
|
|
31
|
-
};
|
|
32
|
-
|
|
33
1
|
import { extractUploadHeaders } from "../utils/headers.js";
|
|
34
2
|
import { http } from "../utils/http.js";
|
|
35
3
|
import { wrapBytesWithHelpers } from "../utils/bytes.js";
|
|
@@ -46,35 +14,30 @@ const endpoint = 'chunks';
|
|
|
46
14
|
* @param postageBatchId Postage BatchId that will be assigned to uploaded data
|
|
47
15
|
* @param options Additional options like tag, encryption, pinning
|
|
48
16
|
*/
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
responseType: 'json'
|
|
60
|
-
});
|
|
61
|
-
return response.data.reference;
|
|
17
|
+
export async function upload(kyOptions, data, postageBatchId, options) {
|
|
18
|
+
const response = await http(kyOptions, {
|
|
19
|
+
method: 'post',
|
|
20
|
+
path: `${endpoint}`,
|
|
21
|
+
body: data,
|
|
22
|
+
headers: {
|
|
23
|
+
'content-type': 'application/octet-stream',
|
|
24
|
+
...extractUploadHeaders(postageBatchId, options)
|
|
25
|
+
},
|
|
26
|
+
responseType: 'json'
|
|
62
27
|
});
|
|
28
|
+
return response.parsedData.reference;
|
|
63
29
|
}
|
|
64
30
|
/**
|
|
65
31
|
* Download chunk data as a byte array
|
|
66
32
|
*
|
|
67
|
-
* @param
|
|
33
|
+
* @param kyOptions Ky Options for making requests
|
|
68
34
|
* @param hash Bee content reference
|
|
69
35
|
*
|
|
70
36
|
*/
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
responseType: 'arraybuffer',
|
|
76
|
-
path: `${endpoint}/${hash}`
|
|
77
|
-
});
|
|
78
|
-
return wrapBytesWithHelpers(new Uint8Array(response.data));
|
|
37
|
+
export async function download(kyOptions, hash) {
|
|
38
|
+
const response = await http(kyOptions, {
|
|
39
|
+
responseType: 'arraybuffer',
|
|
40
|
+
path: `${endpoint}/${hash}`
|
|
79
41
|
});
|
|
42
|
+
return wrapBytesWithHelpers(new Uint8Array(response.parsedData));
|
|
80
43
|
}
|