@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.
Files changed (151) hide show
  1. package/README.md +14 -6
  2. package/dist/223.index.browser.min.js +3 -0
  3. package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
  4. package/dist/223.index.browser.min.js.map +1 -0
  5. package/dist/cjs/bee-debug.js +208 -312
  6. package/dist/cjs/bee.js +258 -353
  7. package/dist/cjs/chunk/signer.js +11 -22
  8. package/dist/cjs/chunk/soc.js +33 -50
  9. package/dist/cjs/chunk/span.js +1 -1
  10. package/dist/cjs/feed/index.js +50 -65
  11. package/dist/cjs/feed/json.js +8 -21
  12. package/dist/cjs/feed/retrievable.js +14 -27
  13. package/dist/cjs/modules/bytes.js +25 -37
  14. package/dist/cjs/modules/bzz.js +63 -68
  15. package/dist/cjs/modules/chunk.js +17 -27
  16. package/dist/cjs/modules/debug/balance.js +24 -41
  17. package/dist/cjs/modules/debug/chequebook.js +71 -96
  18. package/dist/cjs/modules/debug/chunk.js +13 -26
  19. package/dist/cjs/modules/debug/connectivity.js +32 -53
  20. package/dist/cjs/modules/debug/settlements.js +12 -25
  21. package/dist/cjs/modules/debug/stake.js +20 -33
  22. package/dist/cjs/modules/debug/stamps.js +45 -66
  23. package/dist/cjs/modules/debug/states.js +27 -40
  24. package/dist/cjs/modules/debug/status.js +53 -80
  25. package/dist/cjs/modules/debug/tag.js +6 -17
  26. package/dist/cjs/modules/debug/transactions.js +23 -40
  27. package/dist/cjs/modules/feed.js +17 -27
  28. package/dist/cjs/modules/pinning.js +24 -41
  29. package/dist/cjs/modules/pss.js +9 -20
  30. package/dist/cjs/modules/soc.js +12 -20
  31. package/dist/cjs/modules/status.js +4 -15
  32. package/dist/cjs/modules/stewardship.js +10 -23
  33. package/dist/cjs/modules/tag.js +28 -47
  34. package/dist/cjs/utils/collection.browser.js +4 -17
  35. package/dist/cjs/utils/collection.js +11 -22
  36. package/dist/cjs/utils/collection.node.js +42 -86
  37. package/dist/cjs/utils/data.browser.js +46 -59
  38. package/dist/cjs/utils/data.js +22 -35
  39. package/dist/cjs/utils/eth.js +31 -43
  40. package/dist/cjs/utils/file.js +9 -20
  41. package/dist/cjs/utils/headers.js +4 -4
  42. package/dist/cjs/utils/http.js +78 -93
  43. package/dist/cjs/utils/merge.js +1 -1
  44. package/dist/cjs/utils/sleep.js +2 -13
  45. package/dist/cjs/utils/type.js +14 -12
  46. package/dist/index.browser.min.js +1 -1
  47. package/dist/index.browser.min.js.LICENSE.txt +1 -3
  48. package/dist/index.browser.min.js.map +1 -1
  49. package/dist/mjs/bee-debug.js +209 -450
  50. package/dist/mjs/bee.js +256 -491
  51. package/dist/mjs/chunk/bmt.js +4 -10
  52. package/dist/mjs/chunk/cac.js +0 -3
  53. package/dist/mjs/chunk/signer.js +12 -63
  54. package/dist/mjs/chunk/soc.js +33 -85
  55. package/dist/mjs/chunk/span.js +3 -6
  56. package/dist/mjs/feed/identifier.js +0 -6
  57. package/dist/mjs/feed/index.js +53 -97
  58. package/dist/mjs/feed/json.js +10 -49
  59. package/dist/mjs/feed/retrievable.js +13 -64
  60. package/dist/mjs/feed/topic.js +0 -2
  61. package/dist/mjs/index.js +1 -2
  62. package/dist/mjs/modules/bytes.js +25 -65
  63. package/dist/mjs/modules/bzz.js +64 -108
  64. package/dist/mjs/modules/chunk.js +17 -54
  65. package/dist/mjs/modules/debug/balance.js +24 -68
  66. package/dist/mjs/modules/debug/chequebook.js +75 -138
  67. package/dist/mjs/modules/debug/chunk.js +13 -51
  68. package/dist/mjs/modules/debug/connectivity.js +32 -76
  69. package/dist/mjs/modules/debug/settlements.js +12 -50
  70. package/dist/mjs/modules/debug/stake.js +20 -61
  71. package/dist/mjs/modules/debug/stamps.js +47 -94
  72. package/dist/mjs/modules/debug/states.js +25 -66
  73. package/dist/mjs/modules/debug/status.js +66 -125
  74. package/dist/mjs/modules/debug/tag.js +6 -41
  75. package/dist/mjs/modules/debug/transactions.js +25 -69
  76. package/dist/mjs/modules/feed.js +17 -57
  77. package/dist/mjs/modules/pinning.js +24 -68
  78. package/dist/mjs/modules/pss.js +11 -47
  79. package/dist/mjs/modules/soc.js +14 -48
  80. package/dist/mjs/modules/status.js +4 -39
  81. package/dist/mjs/modules/stewardship.js +10 -47
  82. package/dist/mjs/modules/tag.js +31 -78
  83. package/dist/mjs/types/debug.js +0 -1
  84. package/dist/mjs/types/index.js +0 -4
  85. package/dist/mjs/utils/bytes.js +6 -14
  86. package/dist/mjs/utils/collection.browser.js +4 -42
  87. package/dist/mjs/utils/collection.js +11 -57
  88. package/dist/mjs/utils/collection.node.js +42 -150
  89. package/dist/mjs/utils/data.browser.js +49 -94
  90. package/dist/mjs/utils/data.js +19 -62
  91. package/dist/mjs/utils/error.js +0 -5
  92. package/dist/mjs/utils/eth.js +37 -95
  93. package/dist/mjs/utils/file.js +11 -50
  94. package/dist/mjs/utils/hash.js +0 -1
  95. package/dist/mjs/utils/headers.js +6 -14
  96. package/dist/mjs/utils/hex.js +6 -25
  97. package/dist/mjs/utils/http.js +80 -138
  98. package/dist/mjs/utils/merge.js +3 -7
  99. package/dist/mjs/utils/pss.js +0 -2
  100. package/dist/mjs/utils/reference.js +2 -5
  101. package/dist/mjs/utils/sleep.js +2 -37
  102. package/dist/mjs/utils/stream.js +0 -23
  103. package/dist/mjs/utils/tar.js +2 -5
  104. package/dist/mjs/utils/type.js +18 -82
  105. package/dist/mjs/utils/uint64.js +0 -1
  106. package/dist/mjs/utils/url.js +2 -10
  107. package/dist/types/bee-debug.d.ts +2 -2
  108. package/dist/types/bee.d.ts +2 -26
  109. package/dist/types/chunk/cac.d.ts +1 -1
  110. package/dist/types/chunk/soc.d.ts +8 -7
  111. package/dist/types/feed/index.d.ts +9 -8
  112. package/dist/types/feed/type.d.ts +1 -1
  113. package/dist/types/modules/bytes.d.ts +6 -5
  114. package/dist/types/modules/bzz.d.ts +9 -8
  115. package/dist/types/modules/chunk.d.ts +5 -4
  116. package/dist/types/modules/debug/balance.d.ts +10 -9
  117. package/dist/types/modules/debug/chequebook.d.ts +18 -17
  118. package/dist/types/modules/debug/chunk.d.ts +6 -5
  119. package/dist/types/modules/debug/connectivity.d.ts +8 -7
  120. package/dist/types/modules/debug/settlements.d.ts +6 -5
  121. package/dist/types/modules/debug/stake.d.ts +5 -4
  122. package/dist/types/modules/debug/stamps.d.ts +8 -7
  123. package/dist/types/modules/debug/states.d.ts +8 -7
  124. package/dist/types/modules/debug/status.d.ts +15 -15
  125. package/dist/types/modules/debug/tag.d.ts +4 -3
  126. package/dist/types/modules/debug/transactions.d.ts +6 -5
  127. package/dist/types/modules/feed.d.ts +4 -3
  128. package/dist/types/modules/pinning.d.ts +8 -7
  129. package/dist/types/modules/pss.d.ts +4 -3
  130. package/dist/types/modules/soc.d.ts +3 -2
  131. package/dist/types/modules/status.d.ts +3 -3
  132. package/dist/types/modules/stewardship.d.ts +4 -3
  133. package/dist/types/modules/tag.d.ts +7 -6
  134. package/dist/types/types/debug.d.ts +1 -1
  135. package/dist/types/types/index.d.ts +30 -34
  136. package/dist/types/utils/eth.d.ts +3 -3
  137. package/dist/types/utils/hex.d.ts +2 -2
  138. package/dist/types/utils/http.d.ts +6 -6
  139. package/package.json +34 -39
  140. package/dist/cjs/types/ky-options.js +0 -8
  141. package/dist/cjs/types/ky-universal/common.js +0 -8
  142. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  143. package/dist/cjs/types/ky-universal/retry.js +0 -8
  144. package/dist/mjs/types/ky-options.js +0 -7
  145. package/dist/mjs/types/ky-universal/common.js +0 -7
  146. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  147. package/dist/mjs/types/ky-universal/retry.js +0 -7
  148. package/dist/types/types/ky-options.d.ts +0 -221
  149. package/dist/types/types/ky-universal/common.d.ts +0 -13
  150. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  151. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -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
- export function getJsonData(bee, reader) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const feedUpdate = yield reader.download();
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
- return __awaiter(this, void 0, void 0, function* () {
57
- const serializedData = serializeJson(data);
58
- const {
59
- reference
60
- } = yield bee.uploadData(postageBatchId, serializedData, options);
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
- function isChunkRetrievable(bee, ref, options) {
63
- return __awaiter(this, void 0, void 0, function* () {
64
- try {
65
- yield bee.downloadChunk(ref, options);
66
- return true;
67
- } catch (e) {
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
- export function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
99
- return __awaiter(this, void 0, void 0, function* () {
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
  }
@@ -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
- import * as Utils_1 from "./utils/expose.js";
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 ky Ky instance
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
- export function upload(ky, data, postageBatchId, options) {
49
- return __awaiter(this, void 0, void 0, function* () {
50
- const response = yield http(ky, {
51
- path: endpoint,
52
- method: 'post',
53
- responseType: 'json',
54
- body: yield prepareData(data),
55
- headers: Object.assign({
56
- 'content-type': 'application/octet-stream'
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
- export function download(ky, hash) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const response = yield http(ky, {
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
- export function downloadReadable(ky, hash) {
89
- return __awaiter(this, void 0, void 0, function* () {
90
- const response = yield http(ky, {
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
  }
@@ -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 === null || options === void 0 ? void 0 : options.size) headers['content-length'] = String(options.size);
46
- if (options === null || options === void 0 ? void 0 : options.contentType) headers['content-type'] = options.contentType;
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
- export function uploadFile(ky, data, postageBatchId, name, options) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- if (isReadable(data) && !(options === null || options === void 0 ? void 0 : options.contentType)) {
63
- if (!options) options = {};
64
- options.contentType = 'application/octet-stream';
65
- }
66
-
67
- const response = yield http(ky, {
68
- method: 'post',
69
- path: bzzEndpoint,
70
- body: yield prepareData(data),
71
- headers: Object.assign({}, extractFileUploadHeaders(postageBatchId, options)),
72
- searchParams: {
73
- name
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 ky Ky instance for given Bee class instance
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
- export function downloadFile(ky, hash, path = '') {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- const response = yield http(ky, {
94
- method: 'GET',
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 ky Ky instance for given Bee class instance
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
- export function downloadFileReadable(ky, hash, path = '') {
113
- return __awaiter(this, void 0, void 0, function* () {
114
- const response = yield http(ky, {
115
- method: 'GET',
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 === null || options === void 0 ? void 0 : options.indexDocument) headers['swarm-index-document'] = options.indexDocument;
129
- if (options === null || options === void 0 ? void 0 : options.errorDocument) headers['swarm-error-document'] = options.errorDocument;
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 ky Ky instance for given Bee class instance
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
- export function uploadCollection(ky, collection, postageBatchId, options) {
142
- return __awaiter(this, void 0, void 0, function* () {
143
- assertCollection(collection);
144
- const tarData = makeTar(collection);
145
- const response = yield http(ky, {
146
- method: 'post',
147
- path: bzzEndpoint,
148
- body: tarData,
149
- responseType: 'json',
150
- headers: Object.assign({
151
- 'content-type': 'application/x-tar',
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
- export function upload(ky, data, postageBatchId, options) {
51
- return __awaiter(this, void 0, void 0, function* () {
52
- const response = yield http(ky, {
53
- method: 'post',
54
- path: `${endpoint}`,
55
- body: data,
56
- headers: Object.assign({
57
- 'content-type': 'application/octet-stream'
58
- }, extractUploadHeaders(postageBatchId, options)),
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 ky Ky instance for given Bee class instance
33
+ * @param kyOptions Ky Options for making requests
68
34
  * @param hash Bee content reference
69
35
  *
70
36
  */
71
-
72
- export function download(ky, hash) {
73
- return __awaiter(this, void 0, void 0, function* () {
74
- const response = yield http(ky, {
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
  }