@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,41 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.setJsonData = exports.getJsonData = void 0;
13
- const type_1 = require("../utils/type");
14
- function serializeJson(data) {
15
- try {
16
- const jsonString = JSON.stringify(data);
17
- return new TextEncoder().encode(jsonString);
18
- }
19
- catch (e) {
20
- if ((0, type_1.isError)(e)) {
21
- e.message = `JsonFeed: ${e.message}`;
22
- }
23
- throw e;
24
- }
25
- }
26
- function getJsonData(bee, reader) {
27
- return __awaiter(this, void 0, void 0, function* () {
28
- const feedUpdate = yield reader.download();
29
- const retrievedData = yield bee.downloadData(feedUpdate.reference);
30
- return retrievedData.json();
31
- });
32
- }
33
- exports.getJsonData = getJsonData;
34
- function setJsonData(bee, writer, postageBatchId, data, options) {
35
- return __awaiter(this, void 0, void 0, function* () {
36
- const serializedData = serializeJson(data);
37
- const { reference } = yield bee.uploadData(postageBatchId, serializedData, options);
38
- return writer.upload(postageBatchId, reference);
39
- });
40
- }
41
- exports.setJsonData = setJsonData;
@@ -1,72 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.areAllSequentialFeedsUpdateRetrievable = void 0;
13
- const index_1 = require("./index");
14
- const uint64_1 = require("../utils/uint64");
15
- const hex_1 = require("../utils/hex");
16
- function makeNumericIndex(index) {
17
- if (index instanceof Uint8Array) {
18
- return (0, uint64_1.readUint64BigEndian)(index);
19
- }
20
- if (typeof index === 'string') {
21
- return parseInt(index);
22
- }
23
- if (typeof index === 'number') {
24
- return index;
25
- }
26
- throw new TypeError('Unknown type of index!');
27
- }
28
- /**
29
- * Function that checks if a chunk is retrievable by actually downloading it.
30
- * The /stewardship/{reference} endpoint does not support verification of chunks, but only manifest's references.
31
- *
32
- * @param bee
33
- * @param ref
34
- * @param options
35
- */
36
- function isChunkRetrievable(bee, ref, options) {
37
- return __awaiter(this, void 0, void 0, function* () {
38
- try {
39
- yield bee.downloadChunk(ref, options);
40
- return true;
41
- }
42
- catch (e) {
43
- const err = e;
44
- if (err.status === 404) {
45
- return false;
46
- }
47
- throw e;
48
- }
49
- });
50
- }
51
- /**
52
- * Creates array of references for all sequence updates chunk up to the given index.
53
- *
54
- * @param owner
55
- * @param topic
56
- * @param index
57
- */
58
- function getAllSequenceUpdateReferences(owner, topic, index) {
59
- const numIndex = makeNumericIndex(index);
60
- const updateReferences = new Array(numIndex + 1);
61
- for (let i = 0; i <= numIndex; i++) {
62
- updateReferences[i] = (0, hex_1.bytesToHex)((0, index_1.getFeedUpdateChunkReference)(owner, topic, i));
63
- }
64
- return updateReferences;
65
- }
66
- function areAllSequentialFeedsUpdateRetrievable(bee, owner, topic, index, options) {
67
- return __awaiter(this, void 0, void 0, function* () {
68
- const chunkRetrievablePromises = getAllSequenceUpdateReferences(owner, topic, index).map((ref) => __awaiter(this, void 0, void 0, function* () { return isChunkRetrievable(bee, ref, options); }));
69
- return (yield Promise.all(chunkRetrievablePromises)).every(result => result);
70
- });
71
- }
72
- exports.areAllSequentialFeedsUpdateRetrievable = areAllSequentialFeedsUpdateRetrievable;
@@ -1,25 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeTopicFromString = exports.makeTopic = void 0;
4
- const hash_1 = require("../utils/hash");
5
- const bytes_1 = require("../utils/bytes");
6
- const hex_1 = require("../utils/hex");
7
- const types_1 = require("../types");
8
- function makeTopic(topic) {
9
- if (typeof topic === 'string') {
10
- return (0, hex_1.makeHexString)(topic, types_1.TOPIC_HEX_LENGTH);
11
- }
12
- else if (topic instanceof Uint8Array) {
13
- (0, bytes_1.assertBytes)(topic, types_1.TOPIC_BYTES_LENGTH);
14
- return (0, hex_1.bytesToHex)(topic, types_1.TOPIC_HEX_LENGTH);
15
- }
16
- throw new TypeError('invalid topic');
17
- }
18
- exports.makeTopic = makeTopic;
19
- function makeTopicFromString(s) {
20
- if (typeof s !== 'string') {
21
- throw new TypeError('topic has to be string!');
22
- }
23
- return (0, hex_1.bytesToHex)((0, hash_1.keccak256Hash)(s), types_1.TOPIC_HEX_LENGTH);
24
- }
25
- exports.makeTopicFromString = makeTopicFromString;
@@ -1,15 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertFeedType = exports.isFeedType = exports.DEFAULT_FEED_TYPE = void 0;
4
- const feedTypes = ['sequence', 'epoch'];
5
- exports.DEFAULT_FEED_TYPE = 'sequence';
6
- function isFeedType(type) {
7
- return typeof type === 'string' && feedTypes.includes(type);
8
- }
9
- exports.isFeedType = isFeedType;
10
- function assertFeedType(type) {
11
- if (!isFeedType(type)) {
12
- throw new TypeError('invalid feed type');
13
- }
14
- }
15
- exports.assertFeedType = assertFeedType;
package/dist/cjs/index.js DELETED
@@ -1,39 +0,0 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
26
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
27
- };
28
- Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.BeeDebug = exports.Bee = exports.SUPPORTED_BEE_VERSION_EXACT = exports.SUPPORTED_BEE_VERSION = exports.Utils = void 0;
30
- const bee_1 = require("./bee");
31
- Object.defineProperty(exports, "Bee", { enumerable: true, get: function () { return bee_1.Bee; } });
32
- const bee_debug_1 = require("./bee-debug");
33
- Object.defineProperty(exports, "BeeDebug", { enumerable: true, get: function () { return bee_debug_1.BeeDebug; } });
34
- exports.Utils = __importStar(require("./utils/expose"));
35
- __exportStar(require("./types"), exports);
36
- __exportStar(require("./utils/error"), exports);
37
- var status_1 = require("./modules/debug/status");
38
- Object.defineProperty(exports, "SUPPORTED_BEE_VERSION", { enumerable: true, get: function () { return status_1.SUPPORTED_BEE_VERSION; } });
39
- Object.defineProperty(exports, "SUPPORTED_BEE_VERSION_EXACT", { enumerable: true, get: function () { return status_1.SUPPORTED_BEE_VERSION_EXACT; } });
@@ -1,74 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.downloadReadable = exports.download = exports.upload = void 0;
13
- const data_1 = require("../utils/data");
14
- const headers_1 = require("../utils/headers");
15
- const http_1 = require("../utils/http");
16
- const bytes_1 = require("../utils/bytes");
17
- const type_1 = require("../utils/type");
18
- const endpoint = 'bytes';
19
- /**
20
- * Upload data to a Bee node
21
- *
22
- * @param ky Ky instance
23
- * @param data Data to be uploaded
24
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
25
- * @param options Additional options like tag, encryption, pinning
26
- */
27
- function upload(ky, data, postageBatchId, options) {
28
- return __awaiter(this, void 0, void 0, function* () {
29
- const response = yield (0, http_1.http)(ky, {
30
- path: endpoint,
31
- method: 'post',
32
- responseType: 'json',
33
- body: yield (0, data_1.prepareData)(data),
34
- headers: Object.assign({ 'content-type': 'application/octet-stream' }, (0, headers_1.extractUploadHeaders)(postageBatchId, options)),
35
- });
36
- return {
37
- reference: response.data.reference,
38
- tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
39
- };
40
- });
41
- }
42
- exports.upload = upload;
43
- /**
44
- * Download data as a byte array
45
- *
46
- * @param ky
47
- * @param hash Bee content reference
48
- */
49
- function download(ky, hash) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const response = yield (0, http_1.http)(ky, {
52
- responseType: 'arraybuffer',
53
- path: `${endpoint}/${hash}`,
54
- });
55
- return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
56
- });
57
- }
58
- exports.download = download;
59
- /**
60
- * Download data as a readable stream
61
- *
62
- * @param ky
63
- * @param hash Bee content reference
64
- */
65
- function downloadReadable(ky, hash) {
66
- return __awaiter(this, void 0, void 0, function* () {
67
- const response = yield (0, http_1.http)(ky, {
68
- responseType: 'stream',
69
- path: `${endpoint}/${hash}`,
70
- });
71
- return response.data;
72
- });
73
- }
74
- exports.downloadReadable = downloadReadable;
@@ -1,131 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.uploadCollection = exports.downloadFileReadable = exports.downloadFile = exports.uploadFile = void 0;
13
- const headers_1 = require("../utils/headers");
14
- const http_1 = require("../utils/http");
15
- const data_1 = require("../utils/data");
16
- const tar_1 = require("../utils/tar");
17
- const collection_1 = require("../utils/collection");
18
- const bytes_1 = require("../utils/bytes");
19
- const stream_1 = require("../utils/stream");
20
- const type_1 = require("../utils/type");
21
- const bzzEndpoint = 'bzz';
22
- function extractFileUploadHeaders(postageBatchId, options) {
23
- const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
24
- if (options === null || options === void 0 ? void 0 : options.size)
25
- headers['content-length'] = String(options.size);
26
- if (options === null || options === void 0 ? void 0 : options.contentType)
27
- headers['content-type'] = options.contentType;
28
- return headers;
29
- }
30
- /**
31
- * Upload single file
32
- *
33
- * @param ky
34
- * @param data Files data
35
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
36
- * @param name Name that will be attached to the uploaded file. Wraps the data into manifest with set index document.
37
- * @param options
38
- */
39
- function uploadFile(ky, data, postageBatchId, name, options) {
40
- return __awaiter(this, void 0, void 0, function* () {
41
- if ((0, stream_1.isReadable)(data) && !(options === null || options === void 0 ? void 0 : options.contentType)) {
42
- if (!options)
43
- options = {};
44
- options.contentType = 'application/octet-stream';
45
- }
46
- const response = yield (0, http_1.http)(ky, {
47
- method: 'post',
48
- path: bzzEndpoint,
49
- body: yield (0, data_1.prepareData)(data),
50
- headers: Object.assign({}, extractFileUploadHeaders(postageBatchId, options)),
51
- searchParams: { name },
52
- responseType: 'json',
53
- });
54
- return {
55
- reference: response.data.reference,
56
- tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
57
- };
58
- });
59
- }
60
- exports.uploadFile = uploadFile;
61
- /**
62
- * Download single file as a buffer
63
- *
64
- * @param ky Ky instance for given Bee class instance
65
- * @param hash Bee file or collection hash
66
- * @param path If hash is collection then this defines path to a single file in the collection
67
- */
68
- function downloadFile(ky, hash, path = '') {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const response = yield (0, http_1.http)(ky, {
71
- method: 'GET',
72
- responseType: 'arraybuffer',
73
- path: `${bzzEndpoint}/${hash}/${path}`,
74
- });
75
- const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data)) });
76
- return file;
77
- });
78
- }
79
- exports.downloadFile = downloadFile;
80
- /**
81
- * Download single file as a readable stream
82
- *
83
- * @param ky Ky instance for given Bee class instance
84
- * @param hash Bee file or collection hash
85
- * @param path If hash is collection then this defines path to a single file in the collection
86
- */
87
- function downloadFileReadable(ky, hash, path = '') {
88
- return __awaiter(this, void 0, void 0, function* () {
89
- const response = yield (0, http_1.http)(ky, {
90
- method: 'GET',
91
- responseType: 'stream',
92
- path: `${bzzEndpoint}/${hash}/${path}`,
93
- });
94
- const file = Object.assign(Object.assign({}, (0, headers_1.readFileHeaders)(response.headers)), { data: response.data });
95
- return file;
96
- });
97
- }
98
- exports.downloadFileReadable = downloadFileReadable;
99
- function extractCollectionUploadHeaders(postageBatchId, options) {
100
- const headers = (0, headers_1.extractUploadHeaders)(postageBatchId, options);
101
- if (options === null || options === void 0 ? void 0 : options.indexDocument)
102
- headers['swarm-index-document'] = options.indexDocument;
103
- if (options === null || options === void 0 ? void 0 : options.errorDocument)
104
- headers['swarm-error-document'] = options.errorDocument;
105
- return headers;
106
- }
107
- /**
108
- * Upload collection
109
- * @param ky Ky instance for given Bee class instance
110
- * @param collection Collection of Uint8Array buffers to upload
111
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
112
- * @param options
113
- */
114
- function uploadCollection(ky, collection, postageBatchId, options) {
115
- return __awaiter(this, void 0, void 0, function* () {
116
- (0, collection_1.assertCollection)(collection);
117
- const tarData = (0, tar_1.makeTar)(collection);
118
- const response = yield (0, http_1.http)(ky, {
119
- method: 'post',
120
- path: bzzEndpoint,
121
- body: tarData,
122
- responseType: 'json',
123
- headers: Object.assign({ 'content-type': 'application/x-tar', 'swarm-collection': 'true' }, extractCollectionUploadHeaders(postageBatchId, options)),
124
- });
125
- return {
126
- reference: response.data.reference,
127
- tagUid: (0, type_1.makeTagUid)(response.headers.get('swarm-tag')),
128
- };
129
- });
130
- }
131
- exports.uploadCollection = uploadCollection;
@@ -1,58 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.download = exports.upload = void 0;
13
- const headers_1 = require("../utils/headers");
14
- const http_1 = require("../utils/http");
15
- const bytes_1 = require("../utils/bytes");
16
- const endpoint = 'chunks';
17
- /**
18
- * Upload chunk to a Bee node
19
- *
20
- * The chunk data consists of 8 byte span and up to 4096 bytes of payload data.
21
- * The span stores the length of the payload in uint64 little endian encoding.
22
- * Upload expects the chuck data to be set accordingly.
23
- *
24
- * @param ky Ky instance
25
- * @param data Chunk data to be uploaded
26
- * @param postageBatchId Postage BatchId that will be assigned to uploaded data
27
- * @param options Additional options like tag, encryption, pinning
28
- */
29
- function upload(ky, data, postageBatchId, options) {
30
- return __awaiter(this, void 0, void 0, function* () {
31
- const response = yield (0, http_1.http)(ky, {
32
- method: 'post',
33
- path: `${endpoint}`,
34
- body: data,
35
- headers: Object.assign({ 'content-type': 'application/octet-stream' }, (0, headers_1.extractUploadHeaders)(postageBatchId, options)),
36
- responseType: 'json',
37
- });
38
- return response.data.reference;
39
- });
40
- }
41
- exports.upload = upload;
42
- /**
43
- * Download chunk data as a byte array
44
- *
45
- * @param ky Ky instance for given Bee class instance
46
- * @param hash Bee content reference
47
- *
48
- */
49
- function download(ky, hash) {
50
- return __awaiter(this, void 0, void 0, function* () {
51
- const response = yield (0, http_1.http)(ky, {
52
- responseType: 'arraybuffer',
53
- path: `${endpoint}/${hash}`,
54
- });
55
- return (0, bytes_1.wrapBytesWithHelpers)(new Uint8Array(response.data));
56
- });
57
- }
58
- exports.download = download;
@@ -1,77 +0,0 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.getPastDueConsumptionPeerBalance = exports.getPastDueConsumptionBalances = exports.getPeerBalance = exports.getAllBalances = void 0;
13
- const http_1 = require("../../utils/http");
14
- const balancesEndpoint = 'balances';
15
- const consumedEndpoint = 'consumed';
16
- /**
17
- * Get the balances with all known peers including prepaid services
18
- *
19
- * @param ky Ky debug instance
20
- */
21
- function getAllBalances(ky) {
22
- return __awaiter(this, void 0, void 0, function* () {
23
- const response = yield (0, http_1.http)(ky, {
24
- path: balancesEndpoint,
25
- responseType: 'json',
26
- });
27
- return response.data;
28
- });
29
- }
30
- exports.getAllBalances = getAllBalances;
31
- /**
32
- * Get the balances with a specific peer including prepaid services
33
- *
34
- * @param ky Ky debug instance
35
- * @param address Swarm address of peer
36
- */
37
- function getPeerBalance(ky, address) {
38
- return __awaiter(this, void 0, void 0, function* () {
39
- const response = yield (0, http_1.http)(ky, {
40
- path: `${balancesEndpoint}/${address}`,
41
- responseType: 'json',
42
- });
43
- return response.data;
44
- });
45
- }
46
- exports.getPeerBalance = getPeerBalance;
47
- /**
48
- * Get the past due consumption balances with all known peers
49
- *
50
- * @param ky Ky debug instance
51
- */
52
- function getPastDueConsumptionBalances(ky) {
53
- return __awaiter(this, void 0, void 0, function* () {
54
- const response = yield (0, http_1.http)(ky, {
55
- path: consumedEndpoint,
56
- responseType: 'json',
57
- });
58
- return response.data;
59
- });
60
- }
61
- exports.getPastDueConsumptionBalances = getPastDueConsumptionBalances;
62
- /**
63
- * Get the past due consumption balance with a specific peer
64
- *
65
- * @param ky Ky debug instance
66
- * @param address Swarm address of peer
67
- */
68
- function getPastDueConsumptionPeerBalance(ky, address) {
69
- return __awaiter(this, void 0, void 0, function* () {
70
- const response = yield (0, http_1.http)(ky, {
71
- path: `${consumedEndpoint}/${address}`,
72
- responseType: 'json',
73
- });
74
- return response.data;
75
- });
76
- }
77
- exports.getPastDueConsumptionPeerBalance = getPastDueConsumptionPeerBalance;