@ethersphere/bee-js 6.0.0-pre.0 → 6.0.0-pre.10

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 (193) hide show
  1. package/README.md +18 -17
  2. package/dist/cjs/bee-debug.js +572 -0
  3. package/dist/cjs/bee.js +876 -0
  4. package/dist/cjs/chunk/bmt.js +55 -0
  5. package/dist/cjs/chunk/cac.js +56 -0
  6. package/dist/cjs/chunk/serialize.js +19 -0
  7. package/dist/cjs/chunk/signer.js +126 -0
  8. package/dist/cjs/chunk/soc.js +159 -0
  9. package/dist/cjs/chunk/span.js +29 -0
  10. package/dist/cjs/feed/identifier.js +35 -0
  11. package/dist/cjs/feed/index.js +116 -0
  12. package/dist/cjs/feed/json.js +28 -0
  13. package/dist/cjs/feed/retrievable.js +58 -0
  14. package/dist/cjs/feed/topic.js +25 -0
  15. package/dist/cjs/feed/type.js +15 -0
  16. package/dist/cjs/index.js +39 -0
  17. package/dist/cjs/modules/bytes.js +61 -0
  18. package/dist/cjs/modules/bzz.js +125 -0
  19. package/dist/cjs/modules/chunk.js +48 -0
  20. package/dist/cjs/modules/debug/balance.js +60 -0
  21. package/dist/cjs/modules/debug/chequebook.js +142 -0
  22. package/dist/cjs/modules/debug/chunk.js +38 -0
  23. package/dist/cjs/modules/debug/connectivity.js +54 -0
  24. package/dist/cjs/modules/debug/settlements.js +32 -0
  25. package/dist/cjs/modules/debug/stake.js +57 -0
  26. package/dist/cjs/modules/debug/stamps.js +68 -0
  27. package/dist/cjs/modules/debug/states.js +64 -0
  28. package/dist/cjs/modules/debug/status.js +148 -0
  29. package/dist/cjs/modules/debug/tag.js +19 -0
  30. package/dist/cjs/modules/debug/transactions.js +64 -0
  31. package/dist/cjs/modules/feed.js +66 -0
  32. package/dist/cjs/modules/pinning.js +63 -0
  33. package/dist/cjs/modules/pss.js +43 -0
  34. package/dist/cjs/modules/soc.js +32 -0
  35. package/dist/cjs/modules/status.js +15 -0
  36. package/dist/cjs/modules/stewardship.js +28 -0
  37. package/dist/cjs/modules/tag.js +77 -0
  38. package/dist/cjs/package.json +8 -0
  39. package/dist/cjs/types/debug.js +10 -0
  40. package/dist/cjs/types/index.js +51 -0
  41. package/dist/cjs/utils/bytes.js +121 -0
  42. package/dist/cjs/utils/collection.browser.js +23 -0
  43. package/dist/cjs/utils/collection.js +59 -0
  44. package/dist/cjs/utils/collection.node.js +71 -0
  45. package/dist/cjs/utils/data.browser.js +61 -0
  46. package/dist/cjs/utils/data.js +45 -0
  47. package/dist/cjs/utils/error.js +16 -0
  48. package/dist/cjs/utils/eth.js +199 -0
  49. package/dist/cjs/utils/expose.js +44 -0
  50. package/dist/cjs/utils/file.js +38 -0
  51. package/dist/cjs/utils/hash.js +21 -0
  52. package/dist/cjs/utils/headers.js +59 -0
  53. package/dist/cjs/utils/hex.js +150 -0
  54. package/dist/cjs/utils/http.js +40 -0
  55. package/dist/cjs/utils/pss.js +18 -0
  56. package/dist/cjs/utils/reference.js +36 -0
  57. package/dist/cjs/utils/stamps.js +17 -0
  58. package/dist/cjs/utils/stream.js +146 -0
  59. package/dist/cjs/utils/tar.js +25 -0
  60. package/dist/cjs/utils/type.js +434 -0
  61. package/dist/cjs/utils/uint64.js +29 -0
  62. package/dist/cjs/utils/url.js +56 -0
  63. package/dist/index.browser.min.js +3 -0
  64. package/dist/index.browser.min.js.LICENSE.txt +50 -0
  65. package/dist/index.browser.min.js.map +1 -0
  66. package/dist/{src → mjs}/bee-debug.js +102 -183
  67. package/dist/{src → mjs}/bee.js +82 -232
  68. package/dist/{src → mjs}/chunk/bmt.js +4 -10
  69. package/dist/{src → mjs}/chunk/cac.js +0 -3
  70. package/dist/{src → mjs}/chunk/signer.js +1 -18
  71. package/dist/{src → mjs}/chunk/soc.js +17 -29
  72. package/dist/{src → mjs}/chunk/span.js +2 -5
  73. package/dist/{src → mjs}/feed/identifier.js +0 -6
  74. package/dist/{src → mjs}/feed/index.js +24 -27
  75. package/dist/{src → mjs}/feed/json.js +2 -5
  76. package/dist/{src → mjs}/feed/retrievable.js +7 -21
  77. package/dist/{src → mjs}/feed/topic.js +0 -2
  78. package/dist/{src → mjs}/index.js +2 -2
  79. package/dist/{src → mjs}/modules/bytes.js +16 -20
  80. package/dist/{src → mjs}/modules/bzz.js +33 -40
  81. package/dist/{src → mjs}/modules/chunk.js +11 -13
  82. package/dist/mjs/modules/debug/balance.js +53 -0
  83. package/dist/mjs/modules/debug/chequebook.js +135 -0
  84. package/dist/{src → mjs}/modules/debug/chunk.js +10 -12
  85. package/dist/mjs/modules/debug/connectivity.js +45 -0
  86. package/dist/mjs/modules/debug/settlements.js +27 -0
  87. package/dist/mjs/modules/debug/stake.js +51 -0
  88. package/dist/mjs/modules/debug/stamps.js +61 -0
  89. package/dist/mjs/modules/debug/states.js +58 -0
  90. package/dist/{src → mjs}/modules/debug/status.js +46 -37
  91. package/dist/mjs/modules/debug/tag.js +15 -0
  92. package/dist/mjs/modules/debug/transactions.js +59 -0
  93. package/dist/{src → mjs}/modules/feed.js +15 -21
  94. package/dist/mjs/modules/pinning.js +56 -0
  95. package/dist/{src → mjs}/modules/pss.js +7 -10
  96. package/dist/{src → mjs}/modules/soc.js +6 -7
  97. package/dist/mjs/modules/status.js +11 -0
  98. package/dist/mjs/modules/stewardship.js +23 -0
  99. package/dist/mjs/modules/tag.js +72 -0
  100. package/dist/mjs/package.json +8 -0
  101. package/dist/{src → mjs}/types/debug.js +0 -1
  102. package/dist/{src → mjs}/types/index.js +0 -4
  103. package/dist/{src → mjs}/utils/bytes.js +8 -17
  104. package/dist/{src/utils/collection-browser.js → mjs/utils/collection.browser.js} +0 -1
  105. package/dist/{src → mjs}/utils/collection.js +0 -12
  106. package/dist/{src/utils/collection-node.js → mjs/utils/collection.node.js} +0 -13
  107. package/dist/{src → mjs}/utils/data.browser.js +2 -11
  108. package/dist/{src → mjs}/utils/data.js +0 -7
  109. package/dist/mjs/utils/error.js +11 -0
  110. package/dist/{src → mjs}/utils/eth.js +6 -28
  111. package/dist/{src → mjs}/utils/expose.js +1 -1
  112. package/dist/{src → mjs}/utils/file.js +4 -9
  113. package/dist/{src → mjs}/utils/hash.js +0 -1
  114. package/dist/{src → mjs}/utils/headers.js +5 -13
  115. package/dist/{src → mjs}/utils/hex.js +6 -25
  116. package/dist/mjs/utils/http.js +34 -0
  117. package/dist/{src → mjs}/utils/pss.js +0 -2
  118. package/dist/{src → mjs}/utils/reference.js +2 -5
  119. package/dist/{src → mjs}/utils/stream.js +3 -26
  120. package/dist/{src → mjs}/utils/tar.js +3 -6
  121. package/dist/{src → mjs}/utils/type.js +23 -80
  122. package/dist/{src → mjs}/utils/uint64.js +0 -1
  123. package/dist/{src → mjs}/utils/url.js +2 -10
  124. package/dist/types/bee-debug.d.ts +71 -46
  125. package/dist/types/bee.d.ts +34 -58
  126. package/dist/types/chunk/bmt.d.ts +1 -1
  127. package/dist/types/chunk/cac.d.ts +1 -1
  128. package/dist/types/chunk/soc.d.ts +9 -9
  129. package/dist/types/chunk/span.d.ts +1 -1
  130. package/dist/types/feed/index.d.ts +10 -10
  131. package/dist/types/feed/json.d.ts +2 -2
  132. package/dist/types/feed/retrievable.d.ts +2 -2
  133. package/dist/types/feed/type.d.ts +1 -1
  134. package/dist/types/index.d.ts +13 -2
  135. package/dist/types/modules/bytes.d.ts +5 -5
  136. package/dist/types/modules/bzz.d.ts +8 -8
  137. package/dist/types/modules/chunk.d.ts +4 -4
  138. package/dist/types/modules/debug/balance.d.ts +9 -9
  139. package/dist/types/modules/debug/chequebook.d.ts +17 -17
  140. package/dist/types/modules/debug/chunk.d.ts +5 -5
  141. package/dist/types/modules/debug/connectivity.d.ts +7 -7
  142. package/dist/types/modules/debug/settlements.d.ts +5 -5
  143. package/dist/types/modules/debug/stake.d.ts +21 -0
  144. package/dist/types/modules/debug/stamps.d.ts +7 -7
  145. package/dist/types/modules/debug/states.d.ts +7 -7
  146. package/dist/types/modules/debug/status.d.ts +21 -15
  147. package/dist/types/modules/debug/tag.d.ts +3 -3
  148. package/dist/types/modules/debug/transactions.d.ts +5 -5
  149. package/dist/types/modules/feed.d.ts +3 -3
  150. package/dist/types/modules/pinning.d.ts +7 -7
  151. package/dist/types/modules/pss.d.ts +3 -3
  152. package/dist/types/modules/soc.d.ts +2 -2
  153. package/dist/types/modules/status.d.ts +3 -3
  154. package/dist/types/modules/stewardship.d.ts +3 -3
  155. package/dist/types/modules/tag.d.ts +6 -6
  156. package/dist/types/types/debug.d.ts +35 -2
  157. package/dist/types/types/index.d.ts +48 -89
  158. package/dist/types/utils/error.d.ts +0 -26
  159. package/dist/types/utils/eth.d.ts +6 -6
  160. package/dist/types/utils/expose.d.ts +4 -7
  161. package/dist/types/utils/hash.d.ts +1 -1
  162. package/dist/types/utils/headers.d.ts +1 -1
  163. package/dist/types/utils/hex.d.ts +4 -4
  164. package/dist/types/utils/http.d.ts +11 -21
  165. package/dist/types/utils/stream.d.ts +1 -1
  166. package/dist/types/utils/type.d.ts +3 -2
  167. package/dist/types/utils/uint64.d.ts +1 -1
  168. package/package.json +59 -52
  169. package/dist/index.browser.js +0 -33
  170. package/dist/index.browser.js.map +0 -7
  171. package/dist/src/modules/debug/balance.js +0 -57
  172. package/dist/src/modules/debug/chequebook.js +0 -150
  173. package/dist/src/modules/debug/connectivity.js +0 -45
  174. package/dist/src/modules/debug/settlements.js +0 -29
  175. package/dist/src/modules/debug/stamps.js +0 -64
  176. package/dist/src/modules/debug/states.js +0 -46
  177. package/dist/src/modules/debug/tag.js +0 -16
  178. package/dist/src/modules/debug/transactions.js +0 -69
  179. package/dist/src/modules/pinning.js +0 -60
  180. package/dist/src/modules/status.js +0 -12
  181. package/dist/src/modules/stewardship.js +0 -24
  182. package/dist/src/modules/tag.js +0 -77
  183. package/dist/src/utils/error.js +0 -47
  184. package/dist/src/utils/http.js +0 -162
  185. package/dist/src/utils/merge.js +0 -36
  186. package/dist/src/utils/sleep.js +0 -8
  187. package/dist/types/utils/merge.d.ts +0 -8
  188. package/dist/types/utils/sleep.d.ts +0 -6
  189. /package/dist/{src → mjs}/chunk/serialize.js +0 -0
  190. /package/dist/{src → mjs}/feed/type.js +0 -0
  191. /package/dist/{src → mjs}/utils/stamps.js +0 -0
  192. /package/dist/types/utils/{collection-browser.d.ts → collection.browser.d.ts} +0 -0
  193. /package/dist/types/utils/{collection-node.d.ts → collection.node.d.ts} +0 -0
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isRetrievable = exports.reupload = void 0;
4
+ const http_1 = require("../utils/http");
5
+ const stewardshipEndpoint = 'stewardship';
6
+ /**
7
+ * Reupload locally pinned data
8
+ * @param ky Ky instance
9
+ * @param reference
10
+ * @param options
11
+ * @throws BeeResponseError if not locally pinned or invalid data
12
+ */
13
+ async function reupload(requestOptions, reference) {
14
+ await (0, http_1.http)(requestOptions, {
15
+ method: 'put',
16
+ url: `${stewardshipEndpoint}/${reference}`,
17
+ });
18
+ }
19
+ exports.reupload = reupload;
20
+ async function isRetrievable(requestOptions, reference) {
21
+ const response = await (0, http_1.http)(requestOptions, {
22
+ method: 'get',
23
+ responseType: 'json',
24
+ url: `${stewardshipEndpoint}/${reference}`,
25
+ });
26
+ return response.data.isRetrievable;
27
+ }
28
+ exports.isRetrievable = isRetrievable;
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.updateTag = exports.deleteTag = exports.getAllTags = exports.retrieveTag = exports.createTag = void 0;
4
+ const http_1 = require("../utils/http");
5
+ const endpoint = 'tags';
6
+ /**
7
+ * Create new tag on the Bee node
8
+ *
9
+ * @param url Bee tag URL
10
+ */
11
+ async function createTag(requestOptions) {
12
+ const response = await (0, http_1.http)(requestOptions, {
13
+ method: 'post',
14
+ url: endpoint,
15
+ responseType: 'json',
16
+ });
17
+ return response.data;
18
+ }
19
+ exports.createTag = createTag;
20
+ /**
21
+ * Retrieve tag information from Bee node
22
+ *
23
+ * @param url Bee tag URL
24
+ * @param uid UID of tag to be retrieved
25
+ */
26
+ async function retrieveTag(requestOptions, uid) {
27
+ const response = await (0, http_1.http)(requestOptions, {
28
+ url: `${endpoint}/${uid}`,
29
+ responseType: 'json',
30
+ });
31
+ return response.data;
32
+ }
33
+ exports.retrieveTag = retrieveTag;
34
+ /**
35
+ * Get limited listing of all tags.
36
+ *
37
+ * @param url
38
+ * @param offset
39
+ * @param limit
40
+ */
41
+ async function getAllTags(requestOptions, offset, limit) {
42
+ const response = await (0, http_1.http)(requestOptions, {
43
+ url: endpoint,
44
+ params: { offset, limit },
45
+ responseType: 'json',
46
+ });
47
+ return response.data.tags;
48
+ }
49
+ exports.getAllTags = getAllTags;
50
+ /**
51
+ * Removes tag from the Bee node.
52
+ * @param url
53
+ * @param uid
54
+ */
55
+ async function deleteTag(requestOptions, uid) {
56
+ await (0, http_1.http)(requestOptions, {
57
+ method: 'delete',
58
+ url: `${endpoint}/${uid}`,
59
+ });
60
+ }
61
+ exports.deleteTag = deleteTag;
62
+ /**
63
+ * Updates tag
64
+ * @param url
65
+ * @param uid
66
+ * @param reference
67
+ */
68
+ async function updateTag(requestOptions, uid, reference) {
69
+ await (0, http_1.http)(requestOptions, {
70
+ method: 'patch',
71
+ url: `${endpoint}/${uid}`,
72
+ data: {
73
+ reference,
74
+ },
75
+ });
76
+ }
77
+ exports.updateTag = updateTag;
@@ -0,0 +1,8 @@
1
+ {
2
+ "type": "commonjs",
3
+ "browser": {
4
+ "stream": false,
5
+ "./utils/data.js": "./utils/data.browser.js",
6
+ "./utils/collection.node.js": "./utils/collection.browser.js"
7
+ }
8
+ }
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BeeModes = void 0;
4
+ var BeeModes;
5
+ (function (BeeModes) {
6
+ BeeModes["FULL"] = "full";
7
+ BeeModes["LIGHT"] = "light";
8
+ BeeModes["ULTRA_LIGHT"] = "ultra-light";
9
+ BeeModes["DEV"] = "dev";
10
+ })(BeeModes = exports.BeeModes || (exports.BeeModes = {}));
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SIGNATURE_BYTES_LENGTH = exports.SIGNATURE_HEX_LENGTH = exports.TOPIC_HEX_LENGTH = exports.TOPIC_BYTES_LENGTH = exports.FEED_INDEX_HEX_LENGTH = exports.TAGS_LIMIT_MAX = exports.TAGS_LIMIT_MIN = exports.STAMPS_DEPTH_MAX = exports.STAMPS_DEPTH_MIN = exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = exports.REFERENCE_BYTES_LENGTH = exports.ENCRYPTED_REFERENCE_HEX_LENGTH = exports.REFERENCE_HEX_LENGTH = exports.BATCH_ID_HEX_LENGTH = exports.PUBKEY_HEX_LENGTH = exports.PSS_TARGET_HEX_LENGTH_MAX = exports.ADDRESS_HEX_LENGTH = exports.CHUNK_SIZE = exports.BRANCHES = exports.SECTION_SIZE = exports.SPAN_SIZE = void 0;
18
+ __exportStar(require("./debug"), exports);
19
+ exports.SPAN_SIZE = 8;
20
+ exports.SECTION_SIZE = 32;
21
+ exports.BRANCHES = 128;
22
+ exports.CHUNK_SIZE = exports.SECTION_SIZE * exports.BRANCHES;
23
+ exports.ADDRESS_HEX_LENGTH = 64;
24
+ exports.PSS_TARGET_HEX_LENGTH_MAX = 6;
25
+ exports.PUBKEY_HEX_LENGTH = 66;
26
+ exports.BATCH_ID_HEX_LENGTH = 64;
27
+ exports.REFERENCE_HEX_LENGTH = 64;
28
+ exports.ENCRYPTED_REFERENCE_HEX_LENGTH = 128;
29
+ exports.REFERENCE_BYTES_LENGTH = 32;
30
+ exports.ENCRYPTED_REFERENCE_BYTES_LENGTH = 64;
31
+ /**
32
+ * Minimal depth that can be used for creation of postage batch
33
+ */
34
+ exports.STAMPS_DEPTH_MIN = 17;
35
+ /**
36
+ * Maximal depth that can be used for creation of postage batch
37
+ */
38
+ exports.STAMPS_DEPTH_MAX = 255;
39
+ exports.TAGS_LIMIT_MIN = 1;
40
+ exports.TAGS_LIMIT_MAX = 1000;
41
+ exports.FEED_INDEX_HEX_LENGTH = 16;
42
+ /*********************************************************
43
+ * Writers and Readers interfaces
44
+ */
45
+ exports.TOPIC_BYTES_LENGTH = 32;
46
+ exports.TOPIC_HEX_LENGTH = 64;
47
+ /*********************************************************
48
+ * Ethereum compatible signing interfaces and definitions
49
+ */
50
+ exports.SIGNATURE_HEX_LENGTH = 130;
51
+ exports.SIGNATURE_BYTES_LENGTH = 65;
@@ -0,0 +1,121 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.wrapBytesWithHelpers = exports.makeBytes = exports.bytesEqual = exports.flexBytesAtOffset = exports.bytesAtOffset = exports.assertFlexBytes = exports.isFlexBytes = exports.assertBytes = exports.hasBytesAtOffset = exports.isBytes = void 0;
4
+ const hex_1 = require("./hex");
5
+ /**
6
+ * Type guard for `Bytes<T>` type
7
+ *
8
+ * @param b The byte array
9
+ * @param length The length of the byte array
10
+ */
11
+ function isBytes(b, length) {
12
+ return b instanceof Uint8Array && b.length === length;
13
+ }
14
+ exports.isBytes = isBytes;
15
+ /**
16
+ * Function that verifies if passed data are Bytes and if the array has "length" number of bytes under given offset.
17
+ * @param data
18
+ * @param offset
19
+ * @param length
20
+ */
21
+ function hasBytesAtOffset(data, offset, length) {
22
+ if (!(data instanceof Uint8Array)) {
23
+ throw new TypeError('Data has to an Uint8Array!');
24
+ }
25
+ const offsetBytes = data.slice(offset, offset + length);
26
+ return isBytes(offsetBytes, length);
27
+ }
28
+ exports.hasBytesAtOffset = hasBytesAtOffset;
29
+ /**
30
+ * Verifies if a byte array has a certain length
31
+ *
32
+ * @param b The byte array
33
+ * @param length The specified length
34
+ */
35
+ function assertBytes(b, length) {
36
+ if (!isBytes(b, length)) {
37
+ throw new TypeError(`Parameter is not valid Bytes of length: ${length} !== ${b.length}`);
38
+ }
39
+ }
40
+ exports.assertBytes = assertBytes;
41
+ /**
42
+ * Type guard for FlexBytes<Min,Max> type
43
+ *
44
+ * @param b The byte array
45
+ * @param min Minimum size of the array
46
+ * @param max Maximum size of the array
47
+ */
48
+ function isFlexBytes(b, min, max) {
49
+ return b instanceof Uint8Array && b.length >= min && b.length <= max;
50
+ }
51
+ exports.isFlexBytes = isFlexBytes;
52
+ /**
53
+ * Verifies if a byte array has a certain length between min and max
54
+ *
55
+ * @param b The byte array
56
+ * @param min Minimum size of the array
57
+ * @param max Maximum size of the array
58
+ */
59
+ function assertFlexBytes(b, min, max) {
60
+ if (!isFlexBytes(b, min, max)) {
61
+ throw new TypeError(`Parameter is not valid FlexBytes of min: ${min}, max: ${max}, length: ${b.length}`);
62
+ }
63
+ }
64
+ exports.assertFlexBytes = assertFlexBytes;
65
+ /**
66
+ * Return `length` bytes starting from `offset`
67
+ *
68
+ * @param data The original data
69
+ * @param offset The offset to start from
70
+ * @param length The length of data to be returned
71
+ */
72
+ function bytesAtOffset(data, offset, length) {
73
+ const offsetBytes = data.slice(offset, offset + length);
74
+ // We are returning strongly typed Bytes so we have to verify that length is really what we claim
75
+ assertBytes(offsetBytes, length);
76
+ return offsetBytes;
77
+ }
78
+ exports.bytesAtOffset = bytesAtOffset;
79
+ /**
80
+ * Return flex bytes starting from `offset`
81
+ *
82
+ * @param data The original data
83
+ * @param offset The offset to start from
84
+ * @param _min The minimum size of the data
85
+ * @param _max The maximum size of the data
86
+ */
87
+ function flexBytesAtOffset(data, offset,
88
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
89
+ _min,
90
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
91
+ _max) {
92
+ return data.slice(offset);
93
+ }
94
+ exports.flexBytesAtOffset = flexBytesAtOffset;
95
+ /**
96
+ * Returns true if two byte arrays are equal
97
+ *
98
+ * @param a Byte array to compare
99
+ * @param b Byte array to compare
100
+ */
101
+ function bytesEqual(a, b) {
102
+ return a.length === b.length && a.every((value, index) => value === b[index]);
103
+ }
104
+ exports.bytesEqual = bytesEqual;
105
+ /**
106
+ * Returns a new byte array filled with zeroes with the specified length
107
+ *
108
+ * @param length The length of data to be returned
109
+ */
110
+ function makeBytes(length) {
111
+ return new Uint8Array(length);
112
+ }
113
+ exports.makeBytes = makeBytes;
114
+ function wrapBytesWithHelpers(data) {
115
+ return Object.assign(data, {
116
+ text: () => new TextDecoder('utf-8').decode(data),
117
+ json: () => JSON.parse(new TextDecoder('utf-8').decode(data)),
118
+ hex: () => (0, hex_1.bytesToHex)(data),
119
+ });
120
+ }
121
+ exports.wrapBytesWithHelpers = wrapBytesWithHelpers;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getFolderSize = exports.makeCollectionFromFS = void 0;
4
+ /**
5
+ * Creates array in the format of Collection with data loaded from directory on filesystem.
6
+ * The function loads all the data into memory!
7
+ *
8
+ * @param dir path to the directory
9
+ */
10
+ async function makeCollectionFromFS(dir) {
11
+ throw new Error('Creating Collection from File System is not supported in browsers!');
12
+ }
13
+ exports.makeCollectionFromFS = makeCollectionFromFS;
14
+ /**
15
+ * Calculate folder size recursively
16
+ *
17
+ * @param dir the path to the folder to check
18
+ * @returns size in bytes
19
+ */
20
+ async function getFolderSize(dir) {
21
+ throw new Error('Creating Collection from File System is not supported in browsers!');
22
+ }
23
+ exports.getFolderSize = getFolderSize;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCollectionSize = exports.makeCollectionFromFileList = exports.assertCollection = exports.isCollection = void 0;
4
+ const error_1 = require("./error");
5
+ const file_1 = require("./file");
6
+ const type_1 = require("./type");
7
+ function isCollection(data) {
8
+ if (!Array.isArray(data)) {
9
+ return false;
10
+ }
11
+ return data.every(entry => typeof entry === 'object' && entry.data && entry.path && (0, type_1.isUint8Array)(entry.data));
12
+ }
13
+ exports.isCollection = isCollection;
14
+ function assertCollection(data) {
15
+ if (!isCollection(data)) {
16
+ throw new error_1.BeeArgumentError('invalid collection', data);
17
+ }
18
+ }
19
+ exports.assertCollection = assertCollection;
20
+ function makeFilePath(file) {
21
+ if (file.webkitRelativePath && file.webkitRelativePath !== '') {
22
+ return file.webkitRelativePath.replace(/.*?\//i, '');
23
+ }
24
+ if (file.name) {
25
+ return file.name;
26
+ }
27
+ throw new TypeError('file is not valid File object');
28
+ }
29
+ async function makeCollectionFromFileList(fileList) {
30
+ const collection = [];
31
+ for (let i = 0; i < fileList.length; i++) {
32
+ const file = fileList[i];
33
+ if (file) {
34
+ collection.push({
35
+ path: makeFilePath(file),
36
+ data: new Uint8Array(await (0, file_1.fileArrayBuffer)(file)),
37
+ });
38
+ }
39
+ }
40
+ return collection;
41
+ }
42
+ exports.makeCollectionFromFileList = makeCollectionFromFileList;
43
+ /**
44
+ * Calculate cumulative size of files
45
+ *
46
+ * @param fileList list of files to check
47
+ * @returns size in bytes
48
+ */
49
+ function getCollectionSize(fileList) {
50
+ let sum = 0;
51
+ for (let i = 0; i < fileList.length; i++) {
52
+ const file = fileList[i];
53
+ if (file) {
54
+ sum += file.size;
55
+ }
56
+ }
57
+ return sum;
58
+ }
59
+ exports.getCollectionSize = getCollectionSize;
@@ -0,0 +1,71 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getFolderSize = exports.makeCollectionFromFS = void 0;
7
+ const fs_1 = __importDefault(require("fs"));
8
+ const path_1 = __importDefault(require("path"));
9
+ /**
10
+ * Creates array in the format of Collection with data loaded from directory on filesystem.
11
+ * The function loads all the data into memory!
12
+ *
13
+ * @param dir path to the directory
14
+ */
15
+ async function makeCollectionFromFS(dir) {
16
+ if (typeof dir !== 'string') {
17
+ throw new TypeError('dir has to be string!');
18
+ }
19
+ if (dir === '') {
20
+ throw new TypeError('dir must not be empty string!');
21
+ }
22
+ return buildCollectionRelative(dir, '');
23
+ }
24
+ exports.makeCollectionFromFS = makeCollectionFromFS;
25
+ async function buildCollectionRelative(dir, relativePath) {
26
+ // Handles case when the dir is not existing or it is a file ==> throws an error
27
+ const dirname = path_1.default.join(dir, relativePath);
28
+ const entries = await fs_1.default.promises.opendir(dirname);
29
+ let collection = [];
30
+ for await (const entry of entries) {
31
+ const fullPath = path_1.default.join(dir, relativePath, entry.name);
32
+ const entryPath = path_1.default.join(relativePath, entry.name);
33
+ if (entry.isFile()) {
34
+ collection.push({
35
+ path: entryPath,
36
+ data: new Uint8Array(await fs_1.default.promises.readFile(fullPath)),
37
+ });
38
+ }
39
+ else if (entry.isDirectory()) {
40
+ collection = [...(await buildCollectionRelative(dir, entryPath)), ...collection];
41
+ }
42
+ }
43
+ return collection;
44
+ }
45
+ /**
46
+ * Calculate folder size recursively
47
+ *
48
+ * @param dir the path to the folder to check
49
+ * @returns size in bytes
50
+ */
51
+ async function getFolderSize(dir) {
52
+ if (typeof dir !== 'string') {
53
+ throw new TypeError('dir has to be string!');
54
+ }
55
+ if (dir === '') {
56
+ throw new TypeError('dir must not be empty string!');
57
+ }
58
+ const entries = await fs_1.default.promises.opendir(dir);
59
+ let size = 0;
60
+ for await (const entry of entries) {
61
+ if (entry.isFile()) {
62
+ const stats = await fs_1.default.promises.stat(path_1.default.join(dir, entry.name));
63
+ size += stats.size;
64
+ }
65
+ else if (entry.isDirectory()) {
66
+ size += await getFolderSize(path_1.default.join(dir, entry.name));
67
+ }
68
+ }
69
+ return size;
70
+ }
71
+ exports.getFolderSize = getFolderSize;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.prepareWebsocketData = exports.prepareData = void 0;
4
+ const stream_1 = require("./stream");
5
+ /**
6
+ * Validates input and converts to Uint8Array
7
+ *
8
+ * @param data any string, ArrayBuffer or Uint8Array
9
+ */
10
+ async function prepareData(data) {
11
+ if (typeof data === 'string')
12
+ return new Blob([data], { type: 'text/plain' });
13
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
14
+ return new Blob([data], { type: 'application/octet-stream' });
15
+ }
16
+ if (data instanceof Blob) {
17
+ return data;
18
+ }
19
+ // Currently it is not possible to stream requests from browsers
20
+ // there are already first experiments on this field (Chromium)
21
+ // but till it is fully implemented across browsers-land we have to
22
+ // buffer the data before sending the requests.
23
+ if ((0, stream_1.isNodeReadable)(data)) {
24
+ return new Promise(resolve => {
25
+ const buffers = [];
26
+ data.on('data', d => {
27
+ buffers.push(d);
28
+ });
29
+ data.on('end', () => {
30
+ resolve(new Blob(buffers, { type: 'application/octet-stream' }));
31
+ });
32
+ });
33
+ }
34
+ if ((0, stream_1.isReadableStream)(data)) {
35
+ return new Promise(async (resolve) => {
36
+ const reader = data.getReader();
37
+ const buffers = [];
38
+ let done, value;
39
+ do {
40
+ ;
41
+ ({ done, value } = await reader.read());
42
+ if (!done) {
43
+ buffers.push(value);
44
+ }
45
+ } while (!done);
46
+ resolve(new Blob(buffers, { type: 'application/octet-stream' }));
47
+ });
48
+ }
49
+ throw new TypeError('unknown data type');
50
+ }
51
+ exports.prepareData = prepareData;
52
+ async function prepareWebsocketData(data) {
53
+ if (typeof data === 'string')
54
+ return new TextEncoder().encode(data);
55
+ if (data instanceof ArrayBuffer)
56
+ return new Uint8Array(data);
57
+ if (data instanceof Blob)
58
+ return new Uint8Array(await new Response(data).arrayBuffer());
59
+ throw new TypeError('unknown websocket data type');
60
+ }
61
+ exports.prepareWebsocketData = prepareWebsocketData;
@@ -0,0 +1,45 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.prepareWebsocketData = exports.prepareData = void 0;
7
+ const fetch_blob_1 = __importDefault(require("fetch-blob"));
8
+ const stream_1 = require("./stream");
9
+ /**
10
+ * Prepare data for valid input for node-fetch.
11
+ *
12
+ * node-fetch is not using WHATWG ReadableStream but NodeJS Readable so we need to convert in case of ReadableStream,
13
+ * but the typings are set to use ReadableStream so hence why type conversion here.
14
+ *
15
+ * @param data any string, ArrayBuffer, Uint8Array or Readable
16
+ */
17
+ async function prepareData(data) {
18
+ if (typeof data === 'string')
19
+ return new fetch_blob_1.default([data], { type: 'text/plain' });
20
+ if (data instanceof Uint8Array || data instanceof ArrayBuffer) {
21
+ return new fetch_blob_1.default([data], { type: 'application/octet-stream' });
22
+ }
23
+ if (data instanceof fetch_blob_1.default || (0, stream_1.isNodeReadable)(data))
24
+ return data;
25
+ if ((0, stream_1.isReadableStream)(data)) {
26
+ return (0, stream_1.readableWebToNode)(data);
27
+ }
28
+ throw new TypeError('unknown data type');
29
+ }
30
+ exports.prepareData = prepareData;
31
+ function isBufferArray(buffer) {
32
+ return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
33
+ }
34
+ async function prepareWebsocketData(data) {
35
+ if (typeof data === 'string')
36
+ return new TextEncoder().encode(data);
37
+ if (data instanceof Buffer)
38
+ return new Uint8Array(data);
39
+ if (data instanceof ArrayBuffer)
40
+ return new Uint8Array(data);
41
+ if (isBufferArray(data))
42
+ return new Uint8Array(Buffer.concat(data));
43
+ throw new TypeError('unknown websocket data type');
44
+ }
45
+ exports.prepareWebsocketData = prepareWebsocketData;
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BeeArgumentError = exports.BeeError = void 0;
4
+ class BeeError extends Error {
5
+ constructor(message) {
6
+ super(message);
7
+ }
8
+ }
9
+ exports.BeeError = BeeError;
10
+ class BeeArgumentError extends BeeError {
11
+ constructor(message, value) {
12
+ super(message);
13
+ this.value = value;
14
+ }
15
+ }
16
+ exports.BeeArgumentError = BeeArgumentError;