@ethersphere/bee-js 5.0.0 → 6.0.0-pre.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.
Files changed (192) hide show
  1. package/README.md +9 -1
  2. package/dist/index.browser.js +33 -0
  3. package/dist/index.browser.js.map +7 -0
  4. package/dist/src/bee-debug.js +624 -0
  5. package/dist/{mjs → src}/bee.js +243 -340
  6. package/dist/{mjs → src}/chunk/bmt.js +0 -0
  7. package/dist/{mjs → src}/chunk/cac.js +0 -0
  8. package/dist/{mjs → src}/chunk/serialize.js +0 -0
  9. package/dist/{mjs → src}/chunk/signer.js +13 -47
  10. package/dist/{mjs → src}/chunk/soc.js +31 -71
  11. package/dist/{mjs → src}/chunk/span.js +1 -1
  12. package/dist/{mjs → src}/feed/identifier.js +0 -0
  13. package/dist/src/feed/index.js +92 -0
  14. package/dist/src/feed/json.js +27 -0
  15. package/dist/src/feed/retrievable.js +67 -0
  16. package/dist/{mjs → src}/feed/topic.js +0 -0
  17. package/dist/{mjs → src}/feed/type.js +0 -0
  18. package/dist/{mjs → src}/index.js +1 -2
  19. package/dist/src/modules/bytes.js +59 -0
  20. package/dist/src/modules/bzz.js +122 -0
  21. package/dist/src/modules/chunk.js +45 -0
  22. package/dist/src/modules/debug/balance.js +57 -0
  23. package/dist/src/modules/debug/chequebook.js +150 -0
  24. package/dist/src/modules/debug/chunk.js +35 -0
  25. package/dist/src/modules/debug/connectivity.js +45 -0
  26. package/dist/src/modules/debug/settlements.js +29 -0
  27. package/dist/src/modules/debug/stamps.js +64 -0
  28. package/dist/src/modules/debug/states.js +46 -0
  29. package/dist/src/modules/debug/status.js +134 -0
  30. package/dist/src/modules/debug/tag.js +16 -0
  31. package/dist/src/modules/debug/transactions.js +69 -0
  32. package/dist/src/modules/feed.js +67 -0
  33. package/dist/src/modules/pinning.js +60 -0
  34. package/dist/src/modules/pss.js +40 -0
  35. package/dist/src/modules/soc.js +31 -0
  36. package/dist/src/modules/status.js +12 -0
  37. package/dist/src/modules/stewardship.js +24 -0
  38. package/dist/src/modules/tag.js +77 -0
  39. package/dist/{mjs → src}/types/debug.js +0 -0
  40. package/dist/{mjs → src}/types/index.js +0 -0
  41. package/dist/{mjs → src}/utils/bytes.js +3 -2
  42. package/dist/src/utils/collection-browser.js +19 -0
  43. package/dist/src/utils/collection-node.js +74 -0
  44. package/dist/src/utils/collection.js +64 -0
  45. package/dist/src/utils/data.browser.js +72 -0
  46. package/dist/src/utils/data.js +42 -0
  47. package/dist/{mjs → src}/utils/error.js +0 -0
  48. package/dist/{mjs → src}/utils/eth.js +32 -68
  49. package/dist/{mjs → src}/utils/expose.js +1 -1
  50. package/dist/src/utils/file.js +36 -0
  51. package/dist/{mjs → src}/utils/hash.js +0 -0
  52. package/dist/{mjs → src}/utils/headers.js +4 -4
  53. package/dist/{mjs → src}/utils/hex.js +0 -0
  54. package/dist/src/utils/http.js +162 -0
  55. package/dist/{mjs → src}/utils/merge.js +2 -2
  56. package/dist/{mjs → src}/utils/pss.js +0 -0
  57. package/dist/{mjs → src}/utils/reference.js +0 -0
  58. package/dist/src/utils/sleep.js +8 -0
  59. package/dist/{mjs → src}/utils/stamps.js +0 -0
  60. package/dist/{mjs → src}/utils/stream.js +3 -3
  61. package/dist/{mjs → src}/utils/tar.js +0 -0
  62. package/dist/{mjs → src}/utils/type.js +12 -13
  63. package/dist/{mjs → src}/utils/uint64.js +0 -0
  64. package/dist/{mjs → src}/utils/url.js +0 -0
  65. package/dist/types/chunk/bmt.d.ts +1 -1
  66. package/dist/types/chunk/soc.d.ts +1 -1
  67. package/dist/types/chunk/span.d.ts +1 -1
  68. package/dist/types/feed/index.d.ts +1 -1
  69. package/dist/types/index.d.ts +0 -13
  70. package/dist/types/modules/bzz.d.ts +1 -1
  71. package/dist/types/types/index.d.ts +8 -8
  72. package/dist/types/utils/{collection.browser.d.ts → collection-browser.d.ts} +0 -0
  73. package/dist/types/utils/{collection.node.d.ts → collection-node.d.ts} +0 -0
  74. package/dist/types/utils/error.d.ts +1 -1
  75. package/dist/types/utils/eth.d.ts +3 -3
  76. package/dist/types/utils/expose.d.ts +7 -4
  77. package/dist/types/utils/hash.d.ts +1 -1
  78. package/dist/types/utils/hex.d.ts +2 -2
  79. package/dist/types/utils/http.d.ts +3 -3
  80. package/dist/types/utils/stream.d.ts +1 -1
  81. package/dist/types/utils/uint64.d.ts +1 -1
  82. package/package.json +44 -59
  83. package/dist/cjs/bee-debug.js +0 -642
  84. package/dist/cjs/bee.js +0 -983
  85. package/dist/cjs/chunk/bmt.js +0 -55
  86. package/dist/cjs/chunk/cac.js +0 -56
  87. package/dist/cjs/chunk/serialize.js +0 -19
  88. package/dist/cjs/chunk/signer.js +0 -137
  89. package/dist/cjs/chunk/soc.js +0 -176
  90. package/dist/cjs/chunk/span.js +0 -29
  91. package/dist/cjs/feed/identifier.js +0 -35
  92. package/dist/cjs/feed/index.js +0 -132
  93. package/dist/cjs/feed/json.js +0 -41
  94. package/dist/cjs/feed/retrievable.js +0 -72
  95. package/dist/cjs/feed/topic.js +0 -25
  96. package/dist/cjs/feed/type.js +0 -15
  97. package/dist/cjs/index.js +0 -39
  98. package/dist/cjs/modules/bytes.js +0 -74
  99. package/dist/cjs/modules/bzz.js +0 -131
  100. package/dist/cjs/modules/chunk.js +0 -58
  101. package/dist/cjs/modules/debug/balance.js +0 -77
  102. package/dist/cjs/modules/debug/chequebook.js +0 -167
  103. package/dist/cjs/modules/debug/chunk.js +0 -51
  104. package/dist/cjs/modules/debug/connectivity.js +0 -75
  105. package/dist/cjs/modules/debug/settlements.js +0 -45
  106. package/dist/cjs/modules/debug/stamps.js +0 -89
  107. package/dist/cjs/modules/debug/states.js +0 -64
  108. package/dist/cjs/modules/debug/status.js +0 -153
  109. package/dist/cjs/modules/debug/tag.js +0 -30
  110. package/dist/cjs/modules/debug/transactions.js +0 -81
  111. package/dist/cjs/modules/feed.js +0 -76
  112. package/dist/cjs/modules/pinning.js +0 -80
  113. package/dist/cjs/modules/pss.js +0 -55
  114. package/dist/cjs/modules/soc.js +0 -40
  115. package/dist/cjs/modules/status.js +0 -26
  116. package/dist/cjs/modules/stewardship.js +0 -41
  117. package/dist/cjs/modules/tag.js +0 -96
  118. package/dist/cjs/package.json +0 -8
  119. package/dist/cjs/types/debug.js +0 -10
  120. package/dist/cjs/types/index.js +0 -51
  121. package/dist/cjs/types/ky-options.js +0 -8
  122. package/dist/cjs/types/ky-universal/common.js +0 -8
  123. package/dist/cjs/types/ky-universal/hooks.js +0 -8
  124. package/dist/cjs/types/ky-universal/retry.js +0 -8
  125. package/dist/cjs/utils/bytes.js +0 -121
  126. package/dist/cjs/utils/collection.browser.js +0 -36
  127. package/dist/cjs/utils/collection.js +0 -70
  128. package/dist/cjs/utils/collection.node.js +0 -115
  129. package/dist/cjs/utils/data.browser.js +0 -74
  130. package/dist/cjs/utils/data.js +0 -58
  131. package/dist/cjs/utils/error.js +0 -50
  132. package/dist/cjs/utils/eth.js +0 -211
  133. package/dist/cjs/utils/expose.js +0 -44
  134. package/dist/cjs/utils/file.js +0 -49
  135. package/dist/cjs/utils/hash.js +0 -21
  136. package/dist/cjs/utils/headers.js +0 -59
  137. package/dist/cjs/utils/hex.js +0 -150
  138. package/dist/cjs/utils/http.js +0 -172
  139. package/dist/cjs/utils/merge.js +0 -34
  140. package/dist/cjs/utils/pss.js +0 -18
  141. package/dist/cjs/utils/reference.js +0 -36
  142. package/dist/cjs/utils/sleep.js +0 -23
  143. package/dist/cjs/utils/stamps.js +0 -17
  144. package/dist/cjs/utils/stream.js +0 -146
  145. package/dist/cjs/utils/tar.js +0 -25
  146. package/dist/cjs/utils/type.js +0 -426
  147. package/dist/cjs/utils/uint64.js +0 -29
  148. package/dist/cjs/utils/url.js +0 -56
  149. package/dist/index.browser.min.js +0 -3
  150. package/dist/index.browser.min.js.LICENSE.txt +0 -60
  151. package/dist/index.browser.min.js.map +0 -1
  152. package/dist/mjs/bee-debug.js +0 -744
  153. package/dist/mjs/feed/index.js +0 -134
  154. package/dist/mjs/feed/json.js +0 -63
  155. package/dist/mjs/feed/retrievable.js +0 -105
  156. package/dist/mjs/modules/bytes.js +0 -96
  157. package/dist/mjs/modules/bzz.js +0 -160
  158. package/dist/mjs/modules/chunk.js +0 -80
  159. package/dist/mjs/modules/debug/balance.js +0 -97
  160. package/dist/mjs/modules/debug/chequebook.js +0 -198
  161. package/dist/mjs/modules/debug/chunk.js +0 -71
  162. package/dist/mjs/modules/debug/connectivity.js +0 -89
  163. package/dist/mjs/modules/debug/settlements.js +0 -65
  164. package/dist/mjs/modules/debug/stamps.js +0 -108
  165. package/dist/mjs/modules/debug/states.js +0 -84
  166. package/dist/mjs/modules/debug/status.js +0 -182
  167. package/dist/mjs/modules/debug/tag.js +0 -50
  168. package/dist/mjs/modules/debug/transactions.js +0 -103
  169. package/dist/mjs/modules/feed.js +0 -101
  170. package/dist/mjs/modules/pinning.js +0 -100
  171. package/dist/mjs/modules/pss.js +0 -74
  172. package/dist/mjs/modules/soc.js +0 -64
  173. package/dist/mjs/modules/status.js +0 -46
  174. package/dist/mjs/modules/stewardship.js +0 -60
  175. package/dist/mjs/modules/tag.js +0 -119
  176. package/dist/mjs/package.json +0 -8
  177. package/dist/mjs/types/ky-options.js +0 -7
  178. package/dist/mjs/types/ky-universal/common.js +0 -7
  179. package/dist/mjs/types/ky-universal/hooks.js +0 -7
  180. package/dist/mjs/types/ky-universal/retry.js +0 -7
  181. package/dist/mjs/utils/collection.browser.js +0 -56
  182. package/dist/mjs/utils/collection.js +0 -98
  183. package/dist/mjs/utils/collection.node.js +0 -169
  184. package/dist/mjs/utils/data.browser.js +0 -108
  185. package/dist/mjs/utils/data.js +0 -78
  186. package/dist/mjs/utils/file.js +0 -70
  187. package/dist/mjs/utils/http.js +0 -208
  188. package/dist/mjs/utils/sleep.js +0 -43
  189. package/dist/types/types/ky-options.d.ts +0 -221
  190. package/dist/types/types/ky-universal/common.d.ts +0 -13
  191. package/dist/types/types/ky-universal/hooks.d.ts +0 -92
  192. package/dist/types/types/ky-universal/retry.d.ts +0 -38
@@ -1,36 +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
- }; // For ESM compatibility
32
-
33
-
1
+ // For ESM compatibility
34
2
  import pkg from 'js-sha3';
35
3
  const {
36
4
  keccak256,
@@ -130,8 +98,6 @@ export function isHexEthAddress(address) {
130
98
  */
131
99
 
132
100
  export function toLittleEndian(bigEndian, pad = 2) {
133
- var _a;
134
-
135
101
  if (!(Number.isInteger(pad) && pad >= 2 && pad % 2 === 0)) {
136
102
  throw new TypeError('minimal padding for conversion needs to be positive even integer');
137
103
  }
@@ -142,7 +108,7 @@ export function toLittleEndian(bigEndian, pad = 2) {
142
108
 
143
109
  if (hexRep.length % 2 !== 0) hexRep = hexRep.padStart(hexRep.length + 1, '0'); // Match all two pairs in the hexstring, reverse the pairs and join it again
144
110
 
145
- const littleEndian = (_a = hexRep.match(/../g)) === null || _a === void 0 ? void 0 : _a.reverse().join('');
111
+ const littleEndian = hexRep.match(/../g)?.reverse().join('');
146
112
  if (littleEndian) return littleEndian;
147
113
  throw new Error('failed to convert');
148
114
  }
@@ -196,40 +162,38 @@ export function ethToSwarmAddress(ethAddress, networkId = 1) {
196
162
  * @param ethAddress Optional address of the account which the data should be signed with. If not specified `eth_requestAccounts` request is used to get the account address.
197
163
  */
198
164
 
199
- export function makeEthereumWalletSigner(provider, ethAddress) {
200
- return __awaiter(this, void 0, void 0, function* () {
201
- let executorFnc;
165
+ export async function makeEthereumWalletSigner(provider, ethAddress) {
166
+ let executorFnc;
202
167
 
203
- if (typeof provider !== 'object' || provider === null) {
204
- throw new TypeError('We need JsonRPC provider object!');
205
- }
168
+ if (typeof provider !== 'object' || provider === null) {
169
+ throw new TypeError('We need JsonRPC provider object!');
170
+ }
206
171
 
207
- if (provider.request) {
208
- executorFnc = provider.request;
209
- } else if (provider.sendAsync) {
210
- executorFnc = provider.sendAsync;
211
- } else {
212
- throw new Error('Incompatible interface of given provider!');
213
- }
172
+ if (provider.request) {
173
+ executorFnc = provider.request;
174
+ } else if (provider.sendAsync) {
175
+ executorFnc = provider.sendAsync;
176
+ } else {
177
+ throw new Error('Incompatible interface of given provider!');
178
+ }
214
179
 
215
- if (!ethAddress) {
216
- ethAddress = (yield executorFnc({
217
- method: 'eth_requestAccounts'
218
- }))[0];
219
- }
180
+ if (!ethAddress) {
181
+ ethAddress = (await executorFnc({
182
+ method: 'eth_requestAccounts'
183
+ }))[0];
184
+ }
220
185
 
221
- const bytesEthAddress = makeEthAddress(ethAddress);
222
- const hexEthAddress = makeHexEthAddress(ethAddress);
223
- return {
224
- address: bytesEthAddress,
225
- sign: data => __awaiter(this, void 0, void 0, function* () {
226
- const result = yield executorFnc({
227
- jsonrpc: '2.0',
228
- method: 'personal_sign',
229
- params: ['0x' + data.hex(), '0x' + hexEthAddress]
230
- });
231
- return result;
232
- })
233
- };
234
- });
186
+ const bytesEthAddress = makeEthAddress(ethAddress);
187
+ const hexEthAddress = makeHexEthAddress(ethAddress);
188
+ return {
189
+ address: bytesEthAddress,
190
+ sign: async data => {
191
+ const result = await executorFnc({
192
+ jsonrpc: '2.0',
193
+ method: 'personal_sign',
194
+ params: ['0x' + data.hex(), '0x' + hexEthAddress]
195
+ });
196
+ return result;
197
+ }
198
+ };
235
199
  }
@@ -1,5 +1,5 @@
1
1
  export { getCollectionSize } from "./collection.js";
2
- export { getFolderSize } from "./collection.node.js";
2
+ export { getFolderSize } from "./collection-node.js";
3
3
  export { isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual } from "./bytes.js";
4
4
  export { makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString } from "./hex.js";
5
5
  export { makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner } from "./eth.js";
@@ -0,0 +1,36 @@
1
+ /**
2
+ * Compatibility functions for working with File API objects
3
+ *
4
+ * https://developer.mozilla.org/en-US/docs/Web/API/File
5
+ */
6
+ export function isFile(file) {
7
+ // browser
8
+ if (typeof File === 'function') {
9
+ return file instanceof File;
10
+ } // node.js
11
+
12
+
13
+ const f = file;
14
+ return typeof f === 'object' && typeof f.name === 'string' && (typeof f.stream === 'function' || typeof f.arrayBuffer === 'function');
15
+ }
16
+ /**
17
+ * Compatibility helper for browsers where the `arrayBuffer function is
18
+ * missing from `File` objects.
19
+ *
20
+ * @param file A File object
21
+ */
22
+
23
+ export async function fileArrayBuffer(file) {
24
+ if (file.arrayBuffer) {
25
+ return file.arrayBuffer();
26
+ } // workaround for Safari where arrayBuffer is not supported on Files
27
+
28
+
29
+ return new Promise(resolve => {
30
+ const fr = new FileReader();
31
+
32
+ fr.onload = () => resolve(fr.result);
33
+
34
+ fr.readAsArrayBuffer(file);
35
+ });
36
+ }
File without changes
@@ -50,9 +50,9 @@ export function extractUploadHeaders(postageBatchId, options) {
50
50
  const headers = {
51
51
  'swarm-postage-batch-id': postageBatchId
52
52
  };
53
- if (options === null || options === void 0 ? void 0 : options.pin) headers['swarm-pin'] = String(options.pin);
54
- if (options === null || options === void 0 ? void 0 : options.encrypt) headers['swarm-encrypt'] = String(options.encrypt);
55
- if (options === null || options === void 0 ? void 0 : options.tag) headers['swarm-tag'] = String(options.tag);
56
- if (typeof (options === null || options === void 0 ? void 0 : options.deferred) === 'boolean') headers['swarm-deferred-upload'] = options.deferred.toString();
53
+ if (options?.pin) headers['swarm-pin'] = String(options.pin);
54
+ if (options?.encrypt) headers['swarm-encrypt'] = String(options.encrypt);
55
+ if (options?.tag) headers['swarm-tag'] = String(options.tag);
56
+ if (typeof options?.deferred === 'boolean') headers['swarm-deferred-upload'] = options.deferred.toString();
57
57
  return headers;
58
58
  }
File without changes
@@ -0,0 +1,162 @@
1
+ import { BeeError, BeeNotAJsonError, BeeRequestError, BeeResponseError } from "./error.js";
2
+ import kyFactory from 'ky-universal';
3
+ import { normalizeToReadableStream } from "./stream.js";
4
+ import { deepMerge } from "./merge.js";
5
+ import { isObject, isStrictlyObject } from "./type.js";
6
+ const DEFAULT_KY_CONFIG = {
7
+ headers: {
8
+ accept: 'application/json, text/plain, */*',
9
+ 'user-agent': `bee-js`
10
+ }
11
+ };
12
+
13
+ function isHttpError(e) {
14
+ return isObject(e) && typeof e.response !== 'undefined';
15
+ }
16
+
17
+ function isHttpRequestError(e) {
18
+ return isObject(e) && typeof e.request !== 'undefined';
19
+ }
20
+
21
+ function headersToObject(header) {
22
+ return [...header.entries()].reduce((obj, [key, val]) => {
23
+ obj[key] = val;
24
+ return obj;
25
+ }, {});
26
+ }
27
+
28
+ function wrapRequest(request) {
29
+ return {
30
+ url: request.url,
31
+ method: request.method.toUpperCase(),
32
+ headers: headersToObject(request.headers)
33
+ };
34
+ }
35
+
36
+ export function wrapRequestClosure(cb) {
37
+ return async request => {
38
+ await cb(wrapRequest(request));
39
+ };
40
+ }
41
+ export function wrapResponseClosure(cb) {
42
+ return async (request, options, response) => {
43
+ await cb({
44
+ headers: headersToObject(response.headers),
45
+ status: response.status,
46
+ statusText: response.statusText,
47
+ request: wrapRequest(request)
48
+ });
49
+ };
50
+ }
51
+ /**
52
+ * Filters out entries that has undefined value from headers object.
53
+ * Modifies the original object!
54
+ *
55
+ * @param obj
56
+ */
57
+ // eslint-disable-next-line @typescript-eslint/ban-types
58
+
59
+ export function filterHeaders(obj) {
60
+ if (obj === undefined) {
61
+ return undefined;
62
+ }
63
+
64
+ isStrictlyObject(obj);
65
+ const typedObj = obj;
66
+
67
+ for (const key in typedObj) {
68
+ if (typedObj[key] === undefined) {
69
+ delete typedObj[key];
70
+ }
71
+ }
72
+
73
+ if (Object.keys(typedObj).length === 0) {
74
+ return undefined;
75
+ }
76
+
77
+ return typedObj;
78
+ }
79
+ /**
80
+ * Main utility function to make HTTP requests.
81
+ * @param ky
82
+ * @param config
83
+ */
84
+
85
+ export async function http(ky, config) {
86
+ try {
87
+ const {
88
+ path,
89
+ responseType,
90
+ ...kyConfig
91
+ } = config;
92
+ const response = await ky(path, { ...kyConfig,
93
+ searchParams: filterHeaders(kyConfig.searchParams)
94
+ });
95
+
96
+ switch (responseType) {
97
+ case 'stream':
98
+ if (!response.body) {
99
+ throw new BeeError('Response was expected to get data but did not get any!');
100
+ }
101
+
102
+ response.parsedData = normalizeToReadableStream(response.body);
103
+ break;
104
+
105
+ case 'arraybuffer':
106
+ response.parsedData = await response.arrayBuffer();
107
+ break;
108
+
109
+ case 'json':
110
+ try {
111
+ response.parsedData = await response.json();
112
+ } catch (e) {
113
+ throw new BeeNotAJsonError();
114
+ }
115
+
116
+ break;
117
+
118
+ default:
119
+ break;
120
+ // If responseType is not set, then no data are expected
121
+ }
122
+
123
+ return response;
124
+ } catch (e) {
125
+ // Passthrough thrown errors
126
+ if (e instanceof BeeNotAJsonError) {
127
+ throw e;
128
+ }
129
+
130
+ if (isHttpError(e)) {
131
+ let message; // We store the response body here as it can be read only once in Response's lifecycle so to make it exposed
132
+ // to the user in the BeeResponseError, for further analysis.
133
+
134
+ const body = await e.response.text();
135
+
136
+ try {
137
+ // The response can be Bee's JSON with structure `{code, message}` lets try to parse it
138
+ message = JSON.parse(body).message;
139
+ } catch (e) {}
140
+
141
+ if (message) {
142
+ throw new BeeResponseError(e.response.status, e.response, body, config, `${e.response.statusText}: ${message}`);
143
+ } else {
144
+ throw new BeeResponseError(e.response.status, e.response, body, config, e.response.statusText);
145
+ }
146
+ } else if (isHttpRequestError(e)) {
147
+ throw new BeeRequestError(e.message, config);
148
+ } else {
149
+ // Node 18 has native `fetch` implementation called Undici. Errors from this implementation have top level generic
150
+ // message "fetch failed" with the more specific error placed into `cause` property. Instead of "fetch failed" we
151
+ // expose the underlying problem.
152
+ if (e.cause) {
153
+ throw new BeeError(e.cause.message);
154
+ }
155
+
156
+ throw new BeeError(e.message);
157
+ }
158
+ }
159
+ }
160
+ export function makeDefaultKy(kyConfig) {
161
+ return kyFactory.create(deepMerge(DEFAULT_KY_CONFIG, kyConfig));
162
+ }
@@ -25,9 +25,9 @@ export function deepMerge(...sources) {
25
25
  value = deepMerge(returnValue[key], value);
26
26
  }
27
27
 
28
- returnValue = Object.assign(Object.assign({}, returnValue), {
28
+ returnValue = { ...returnValue,
29
29
  [key]: value
30
- });
30
+ };
31
31
  }
32
32
  }
33
33
  }
File without changes
File without changes
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Sleep for N miliseconds
3
+ *
4
+ * @param ms Number of miliseconds to sleep
5
+ */
6
+ export async function sleep(ms) {
7
+ return new Promise(resolve => setTimeout(() => resolve(), ms));
8
+ }
File without changes
@@ -1,7 +1,7 @@
1
- import { Readable as NodeReadableNative } from 'stream';
1
+ import * as streamPackage from 'stream';
2
2
  import { isStrictlyObject } from "./type.js";
3
3
  import { ReadableStream } from 'web-streams-polyfill';
4
- const NodeReadable = NodeReadableNative || class {};
4
+ const NodeReadable = streamPackage?.Readable || class {};
5
5
  /**
6
6
  * Validates if passed object is either browser's ReadableStream
7
7
  * or Node's Readable.
@@ -135,7 +135,7 @@ class NodeReadableWrapper extends NodeReadable {
135
135
 
136
136
 
137
137
  export function readableWebToNode(webStream, options) {
138
- if (!NodeReadableNative) {
138
+ if (!streamPackage?.Readable) {
139
139
  throw new Error("The Node's Readable is not available! If you are running this in browser you have to polyfill 'stream' package!");
140
140
  }
141
141
 
File without changes
@@ -122,8 +122,6 @@ export function assertReferenceOrEns(value) {
122
122
  */
123
123
 
124
124
  export function makeReferenceOrEns(value, expectedCidType) {
125
- var _a;
126
-
127
125
  if (typeof value !== 'string') {
128
126
  throw new TypeError('ReferenceCidOrEns has to be a string!');
129
127
  }
@@ -132,7 +130,7 @@ export function makeReferenceOrEns(value, expectedCidType) {
132
130
  const result = decodeCid(value);
133
131
 
134
132
  if (result.type !== expectedCidType) {
135
- throw new BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${(_a = result.type) !== null && _a !== void 0 ? _a : 'non-Swarm CID'}`);
133
+ throw new BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${result.type ?? 'non-Swarm CID'}`);
136
134
  }
137
135
 
138
136
  return result.reference;
@@ -150,12 +148,13 @@ export function makeReferenceOrEns(value, expectedCidType) {
150
148
  */
151
149
 
152
150
  export function addCidConversionFunction(result, cidType) {
153
- return Object.assign(Object.assign({}, result), {
151
+ return { ...result,
152
+
154
153
  cid() {
155
154
  return encodeReference(result.reference, cidType).toString();
156
155
  }
157
156
 
158
- });
157
+ };
159
158
  }
160
159
  export function assertAddress(value) {
161
160
  assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
@@ -313,19 +312,19 @@ export function assertPostageBatchOptions(value) {
313
312
  const options = value;
314
313
  assertRequestOptions(options, 'PostageBatchOptions');
315
314
 
316
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
315
+ if (options?.gasPrice) {
317
316
  assertNonNegativeInteger(options.gasPrice);
318
317
  }
319
318
 
320
- if ((options === null || options === void 0 ? void 0 : options.immutableFlag) !== undefined) {
319
+ if (options?.immutableFlag !== undefined) {
321
320
  assertBoolean(options.immutableFlag);
322
321
  }
323
322
 
324
- if ((options === null || options === void 0 ? void 0 : options.waitForUsable) !== undefined) {
323
+ if (options?.waitForUsable !== undefined) {
325
324
  assertBoolean(options.waitForUsable);
326
325
  }
327
326
 
328
- if ((options === null || options === void 0 ? void 0 : options.waitForUsableTimeout) !== undefined) {
327
+ if (options?.waitForUsableTimeout !== undefined) {
329
328
  assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
330
329
  }
331
330
  }
@@ -338,11 +337,11 @@ export function assertCashoutOptions(value) {
338
337
  const options = value;
339
338
  assertRequestOptions(options, 'PostageBatchOptions');
340
339
 
341
- if (options === null || options === void 0 ? void 0 : options.gasLimit) {
340
+ if (options?.gasLimit) {
342
341
  assertNonNegativeInteger(options.gasLimit);
343
342
  }
344
343
 
345
- if (options === null || options === void 0 ? void 0 : options.gasPrice) {
344
+ if (options?.gasPrice) {
346
345
  assertNonNegativeInteger(options.gasPrice);
347
346
  }
348
347
  }
@@ -381,7 +380,7 @@ export function assertAllTagsOptions(entry) {
381
380
  assertRequestOptions(entry, 'AllTagsOptions');
382
381
  const options = entry;
383
382
 
384
- if ((options === null || options === void 0 ? void 0 : options.limit) !== undefined) {
383
+ if (options?.limit !== undefined) {
385
384
  if (typeof options.limit !== 'number') {
386
385
  throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
387
386
  }
@@ -395,7 +394,7 @@ export function assertAllTagsOptions(entry) {
395
394
  }
396
395
  }
397
396
 
398
- if ((options === null || options === void 0 ? void 0 : options.offset) !== undefined) {
397
+ if (options?.offset !== undefined) {
399
398
  assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
400
399
  }
401
400
  }
File without changes
File without changes
@@ -1,4 +1,4 @@
1
- import { Bytes } from '../utils/bytes';
1
+ import type { Bytes } from '../utils/bytes';
2
2
  /**
3
3
  * Calculate a Binary Merkle Tree hash for a chunk
4
4
  *
@@ -1,7 +1,7 @@
1
- import { Bytes } from '../utils/bytes';
2
1
  import { Chunk } from './cac';
3
2
  import { UploadOptions, Signature, Signer, BatchId, Reference, Ky, PlainBytesReference } from '../types';
4
3
  import { EthAddress } from '../utils/eth';
4
+ import type { Bytes } from '../utils/bytes';
5
5
  export declare type Identifier = Bytes<32>;
6
6
  /**
7
7
  * With single owner chunks, a user can assign arbitrary data to an
@@ -1,4 +1,4 @@
1
- import { Bytes } from '../utils/bytes';
1
+ import type { Bytes } from '../utils/bytes';
2
2
  export declare const SPAN_SIZE = 8;
3
3
  /**
4
4
  * Create a span for storing the length of the chunk
@@ -1,8 +1,8 @@
1
1
  import { FeedUpdateOptions } from '../modules/feed';
2
2
  import { BatchId, BytesReference, FEED_INDEX_HEX_LENGTH, FeedReader, FeedWriter, Ky, PlainBytesReference, Reference, Signer, Topic, UploadOptions } from '../types';
3
- import { Bytes } from '../utils/bytes';
4
3
  import { HexString } from '../utils/hex';
5
4
  import { EthAddress, HexEthAddress } from '../utils/eth';
5
+ import type { Bytes } from '../utils/bytes';
6
6
  import type { FeedType } from './type';
7
7
  export interface Epoch {
8
8
  time: number;
@@ -5,16 +5,3 @@ export * from './types';
5
5
  export * from './utils/error';
6
6
  export { SUPPORTED_BEE_VERSION, SUPPORTED_BEE_VERSION_EXACT } from './modules/debug/status';
7
7
  export { Bee, BeeDebug };
8
- declare global {
9
- interface Window {
10
- BeeJs: {
11
- Bee: typeof import('./bee').Bee;
12
- BeeDebug: typeof import('./bee-debug').BeeDebug;
13
- Utils: typeof import('./utils/expose');
14
- BeeError: typeof import('./utils/error').BeeError;
15
- BeeRequestError: typeof import('./utils/error').BeeRequestError;
16
- BeeResponseError: typeof import('./utils/error').BeeResponseError;
17
- BeeArgumentError: typeof import('./utils/error').BeeArgumentError;
18
- };
19
- }
20
- }
@@ -1,4 +1,4 @@
1
- import { BatchId, Collection, CollectionUploadOptions, Data, FileData, FileUploadOptions, Ky, Readable, ReferenceOrEns, UploadResult } from '../types';
1
+ import type { BatchId, Collection, CollectionUploadOptions, Data, FileData, FileUploadOptions, Ky, Readable, ReferenceOrEns, UploadResult } from '../types';
2
2
  /**
3
3
  * Upload single file
4
4
  *
@@ -8,10 +8,10 @@ import type { BeeError } from '../utils/error';
8
8
  import type { EthAddress, HexEthAddress } from '../utils/eth';
9
9
  import type { HexString } from '../utils/hex';
10
10
  import type ky from 'ky-universal';
11
+ import type { Options as KyOptions } from 'ky';
11
12
  import type { Readable as NativeReadable } from 'stream';
12
13
  import type { Readable as CompatibilityReadable } from 'readable-stream';
13
14
  import type { ReadableStream as ReadableStreamPonyfill } from 'web-streams-polyfill';
14
- import { Options as KyOptions } from './ky-options';
15
15
  export * from './debug';
16
16
  export declare type Ky = typeof ky;
17
17
  export interface Dictionary<T> {
@@ -266,13 +266,13 @@ export interface Pin {
266
266
  reference: string;
267
267
  }
268
268
  /**
269
- * Helper interface that adds utility functions
270
- * to work more conveniently with bytes in normal
271
- * user scenarios.
272
- *
273
- * Concretely: text(), hex(), json()
269
+ * Interface that represents Data passed from Bee and that allows accessing it in different forms..
274
270
  */
275
- export interface Data extends Uint8Array {
271
+ export interface Data {
272
+ /**
273
+ * The raw binary data in form of Uint8Array
274
+ */
275
+ bytes(): Uint8Array;
276
276
  /**
277
277
  * Converts the binary data using UTF-8 decoding into string.
278
278
  */
@@ -548,4 +548,4 @@ interface JsonMap {
548
548
  [key: string]: AnyJson;
549
549
  }
550
550
  declare type JsonArray = Array<AnyJson>;
551
- declare type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
551
+ export declare type Fetch = (input: RequestInfo, init?: RequestInit) => Promise<Response>;
@@ -1,4 +1,4 @@
1
- import { KyRequestOptions } from '../types';
1
+ import type { KyRequestOptions } from '../types';
2
2
  export declare class BeeError extends Error {
3
3
  constructor(message: string);
4
4
  }
@@ -1,6 +1,6 @@
1
- import { BrandedString, Signer } from '../types';
2
- import { HexString } from './hex';
3
- import { Bytes } from './bytes';
1
+ import type { HexString } from './hex';
2
+ import type { Bytes } from '../utils/bytes';
3
+ import type { BrandedString, Signer } from '../types';
4
4
  export declare type OverlayAddress = BrandedString<'OverlayAddress'>;
5
5
  export declare type EthAddress = Bytes<20>;
6
6
  export declare type HexEthAddress = HexString<40>;
@@ -1,8 +1,11 @@
1
1
  export { getCollectionSize } from './collection';
2
- export { getFolderSize } from './collection.node';
3
- export { Bytes, FlexBytes, isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
4
- export { HexString, PrefixedHexString, makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
5
- export { EthAddress, makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
2
+ export { getFolderSize } from './collection-node';
3
+ export type { Bytes, FlexBytes } from './bytes';
4
+ export { isBytes, assertBytes, isFlexBytes, assertFlexBytes, bytesAtOffset, flexBytesAtOffset, bytesEqual, } from './bytes';
5
+ export type { HexString, PrefixedHexString } from './hex';
6
+ export { makeHexString, hexToBytes, bytesToHex, intToHex, isHexString, assertHexString, assertPrefixedHexString, } from './hex';
7
+ export type { EthAddress } from './eth';
8
+ export { makeEthAddress, makeHexEthAddress, isHexEthAddress, ethToSwarmAddress, toLittleEndian, fromLittleEndian, makeEthereumWalletSigner, } from './eth';
6
9
  export { readableWebToNode, readableNodeToWeb, isReadableStream, isNodeReadable, normalizeToReadableStream, isReadable, } from './stream';
7
10
  export { keccak256Hash } from './hash';
8
11
  export { makeMaxTarget } from './pss';
@@ -1,5 +1,5 @@
1
1
  import { Message } from 'js-sha3';
2
- import { Bytes } from './bytes';
2
+ import type { Bytes } from './bytes';
3
3
  /**
4
4
  * Helper function for calculating the keccak256 hash with
5
5
  * correct types.
@@ -1,5 +1,5 @@
1
- import { Bytes } from './bytes';
2
- import { BrandedType, FlavoredType } from '../types';
1
+ import type { Bytes } from '../utils/bytes';
2
+ import type { BrandedType, FlavoredType } from '../types';
3
3
  /**
4
4
  * Nominal type to represent hex strings WITHOUT '0x' prefix.
5
5
  * For example for 32 bytes hex representation you have to use 64 length.