@ethersphere/bee-js 5.1.1 → 5.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -6
- package/dist/223.index.browser.min.js +3 -0
- package/dist/223.index.browser.min.js.LICENSE.txt +1 -0
- package/dist/223.index.browser.min.js.map +1 -0
- package/dist/cjs/bee-debug.js +208 -312
- package/dist/cjs/bee.js +258 -353
- package/dist/cjs/chunk/signer.js +11 -22
- package/dist/cjs/chunk/soc.js +33 -50
- package/dist/cjs/chunk/span.js +1 -1
- package/dist/cjs/feed/index.js +50 -65
- package/dist/cjs/feed/json.js +8 -21
- package/dist/cjs/feed/retrievable.js +14 -27
- package/dist/cjs/modules/bytes.js +25 -37
- package/dist/cjs/modules/bzz.js +63 -68
- package/dist/cjs/modules/chunk.js +17 -27
- package/dist/cjs/modules/debug/balance.js +24 -41
- package/dist/cjs/modules/debug/chequebook.js +71 -96
- package/dist/cjs/modules/debug/chunk.js +13 -26
- package/dist/cjs/modules/debug/connectivity.js +32 -53
- package/dist/cjs/modules/debug/settlements.js +12 -25
- package/dist/cjs/modules/debug/stake.js +20 -33
- package/dist/cjs/modules/debug/stamps.js +45 -66
- package/dist/cjs/modules/debug/states.js +27 -40
- package/dist/cjs/modules/debug/status.js +53 -80
- package/dist/cjs/modules/debug/tag.js +6 -17
- package/dist/cjs/modules/debug/transactions.js +23 -40
- package/dist/cjs/modules/feed.js +17 -27
- package/dist/cjs/modules/pinning.js +24 -41
- package/dist/cjs/modules/pss.js +9 -20
- package/dist/cjs/modules/soc.js +12 -20
- package/dist/cjs/modules/status.js +4 -15
- package/dist/cjs/modules/stewardship.js +10 -23
- package/dist/cjs/modules/tag.js +28 -47
- package/dist/cjs/utils/collection.browser.js +4 -17
- package/dist/cjs/utils/collection.js +11 -22
- package/dist/cjs/utils/collection.node.js +42 -86
- package/dist/cjs/utils/data.browser.js +46 -59
- package/dist/cjs/utils/data.js +22 -35
- package/dist/cjs/utils/eth.js +31 -43
- package/dist/cjs/utils/file.js +9 -20
- package/dist/cjs/utils/headers.js +4 -4
- package/dist/cjs/utils/http.js +78 -93
- package/dist/cjs/utils/merge.js +1 -1
- package/dist/cjs/utils/sleep.js +2 -13
- package/dist/cjs/utils/type.js +14 -12
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.LICENSE.txt +1 -3
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee-debug.js +209 -450
- package/dist/mjs/bee.js +256 -491
- package/dist/mjs/chunk/bmt.js +4 -10
- package/dist/mjs/chunk/cac.js +0 -3
- package/dist/mjs/chunk/signer.js +12 -63
- package/dist/mjs/chunk/soc.js +33 -85
- package/dist/mjs/chunk/span.js +3 -6
- package/dist/mjs/feed/identifier.js +0 -6
- package/dist/mjs/feed/index.js +53 -97
- package/dist/mjs/feed/json.js +10 -49
- package/dist/mjs/feed/retrievable.js +13 -64
- package/dist/mjs/feed/topic.js +0 -2
- package/dist/mjs/index.js +1 -2
- package/dist/mjs/modules/bytes.js +25 -65
- package/dist/mjs/modules/bzz.js +64 -108
- package/dist/mjs/modules/chunk.js +17 -54
- package/dist/mjs/modules/debug/balance.js +24 -68
- package/dist/mjs/modules/debug/chequebook.js +75 -138
- package/dist/mjs/modules/debug/chunk.js +13 -51
- package/dist/mjs/modules/debug/connectivity.js +32 -76
- package/dist/mjs/modules/debug/settlements.js +12 -50
- package/dist/mjs/modules/debug/stake.js +20 -61
- package/dist/mjs/modules/debug/stamps.js +47 -94
- package/dist/mjs/modules/debug/states.js +25 -66
- package/dist/mjs/modules/debug/status.js +66 -125
- package/dist/mjs/modules/debug/tag.js +6 -41
- package/dist/mjs/modules/debug/transactions.js +25 -69
- package/dist/mjs/modules/feed.js +17 -57
- package/dist/mjs/modules/pinning.js +24 -68
- package/dist/mjs/modules/pss.js +11 -47
- package/dist/mjs/modules/soc.js +14 -48
- package/dist/mjs/modules/status.js +4 -39
- package/dist/mjs/modules/stewardship.js +10 -47
- package/dist/mjs/modules/tag.js +31 -78
- package/dist/mjs/types/debug.js +0 -1
- package/dist/mjs/types/index.js +0 -4
- package/dist/mjs/utils/bytes.js +6 -14
- package/dist/mjs/utils/collection.browser.js +4 -42
- package/dist/mjs/utils/collection.js +11 -57
- package/dist/mjs/utils/collection.node.js +42 -150
- package/dist/mjs/utils/data.browser.js +49 -94
- package/dist/mjs/utils/data.js +19 -62
- package/dist/mjs/utils/error.js +0 -5
- package/dist/mjs/utils/eth.js +37 -95
- package/dist/mjs/utils/file.js +11 -50
- package/dist/mjs/utils/hash.js +0 -1
- package/dist/mjs/utils/headers.js +6 -14
- package/dist/mjs/utils/hex.js +6 -25
- package/dist/mjs/utils/http.js +80 -138
- package/dist/mjs/utils/merge.js +3 -7
- package/dist/mjs/utils/pss.js +0 -2
- package/dist/mjs/utils/reference.js +2 -5
- package/dist/mjs/utils/sleep.js +2 -37
- package/dist/mjs/utils/stream.js +0 -23
- package/dist/mjs/utils/tar.js +2 -5
- package/dist/mjs/utils/type.js +18 -82
- package/dist/mjs/utils/uint64.js +0 -1
- package/dist/mjs/utils/url.js +2 -10
- package/dist/types/bee-debug.d.ts +2 -2
- package/dist/types/bee.d.ts +2 -26
- package/dist/types/chunk/cac.d.ts +1 -1
- package/dist/types/chunk/soc.d.ts +8 -7
- package/dist/types/feed/index.d.ts +9 -8
- package/dist/types/feed/type.d.ts +1 -1
- package/dist/types/modules/bytes.d.ts +6 -5
- package/dist/types/modules/bzz.d.ts +9 -8
- package/dist/types/modules/chunk.d.ts +5 -4
- package/dist/types/modules/debug/balance.d.ts +10 -9
- package/dist/types/modules/debug/chequebook.d.ts +18 -17
- package/dist/types/modules/debug/chunk.d.ts +6 -5
- package/dist/types/modules/debug/connectivity.d.ts +8 -7
- package/dist/types/modules/debug/settlements.d.ts +6 -5
- package/dist/types/modules/debug/stake.d.ts +5 -4
- package/dist/types/modules/debug/stamps.d.ts +8 -7
- package/dist/types/modules/debug/states.d.ts +8 -7
- package/dist/types/modules/debug/status.d.ts +15 -15
- package/dist/types/modules/debug/tag.d.ts +4 -3
- package/dist/types/modules/debug/transactions.d.ts +6 -5
- package/dist/types/modules/feed.d.ts +4 -3
- package/dist/types/modules/pinning.d.ts +8 -7
- package/dist/types/modules/pss.d.ts +4 -3
- package/dist/types/modules/soc.d.ts +3 -2
- package/dist/types/modules/status.d.ts +3 -3
- package/dist/types/modules/stewardship.d.ts +4 -3
- package/dist/types/modules/tag.d.ts +7 -6
- package/dist/types/types/debug.d.ts +1 -1
- package/dist/types/types/index.d.ts +30 -34
- package/dist/types/utils/eth.d.ts +3 -3
- package/dist/types/utils/hex.d.ts +2 -2
- package/dist/types/utils/http.d.ts +6 -6
- package/package.json +34 -39
- package/dist/cjs/types/ky-options.js +0 -8
- package/dist/cjs/types/ky-universal/common.js +0 -8
- package/dist/cjs/types/ky-universal/hooks.js +0 -8
- package/dist/cjs/types/ky-universal/retry.js +0 -8
- package/dist/mjs/types/ky-options.js +0 -7
- package/dist/mjs/types/ky-universal/common.js +0 -7
- package/dist/mjs/types/ky-universal/hooks.js +0 -7
- package/dist/mjs/types/ky-universal/retry.js +0 -7
- package/dist/types/types/ky-options.d.ts +0 -221
- package/dist/types/types/ky-universal/common.d.ts +0 -13
- package/dist/types/types/ky-universal/hooks.d.ts +0 -92
- package/dist/types/types/ky-universal/retry.d.ts +0 -38
package/dist/cjs/bee.js
CHANGED
|
@@ -22,15 +22,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
26
|
exports.Bee = void 0;
|
|
36
27
|
const bzz = __importStar(require("./modules/bzz"));
|
|
@@ -62,6 +53,7 @@ const http_1 = require("./utils/http");
|
|
|
62
53
|
const stream_1 = require("./utils/stream");
|
|
63
54
|
const retrievable_1 = require("./feed/retrievable");
|
|
64
55
|
const swarm_cid_1 = require("@ethersphere/swarm-cid");
|
|
56
|
+
const merge_1 = require("./utils/merge");
|
|
65
57
|
/**
|
|
66
58
|
* The main component that abstracts operations available on the main Bee API.
|
|
67
59
|
*
|
|
@@ -74,35 +66,34 @@ class Bee {
|
|
|
74
66
|
* @param options
|
|
75
67
|
*/
|
|
76
68
|
constructor(url, options) {
|
|
77
|
-
var _a;
|
|
78
69
|
(0, url_1.assertBeeUrl)(url);
|
|
79
70
|
// Remove last slash if present, as our endpoint strings starts with `/...`
|
|
80
71
|
// which could lead to double slash in URL to which Bee responds with
|
|
81
72
|
// unnecessary redirects.
|
|
82
73
|
this.url = (0, url_1.stripLastSlash)(url);
|
|
83
|
-
if (options
|
|
74
|
+
if (options?.signer) {
|
|
84
75
|
this.signer = (0, signer_1.makeSigner)(options.signer);
|
|
85
76
|
}
|
|
86
77
|
const kyOptions = {
|
|
87
78
|
prefixUrl: this.url,
|
|
88
|
-
timeout:
|
|
89
|
-
retry: options
|
|
90
|
-
fetch: options
|
|
79
|
+
timeout: options?.timeout ?? false,
|
|
80
|
+
retry: options?.retry,
|
|
81
|
+
fetch: options?.fetch,
|
|
91
82
|
hooks: {
|
|
92
83
|
beforeRequest: [],
|
|
93
84
|
afterResponse: [],
|
|
94
85
|
},
|
|
95
86
|
};
|
|
96
|
-
if (options
|
|
87
|
+
if (options?.defaultHeaders) {
|
|
97
88
|
kyOptions.headers = options.defaultHeaders;
|
|
98
89
|
}
|
|
99
|
-
if (options
|
|
90
|
+
if (options?.onRequest) {
|
|
100
91
|
kyOptions.hooks.beforeRequest.push((0, http_1.wrapRequestClosure)(options.onRequest));
|
|
101
92
|
}
|
|
102
|
-
if (options
|
|
93
|
+
if (options?.onResponse) {
|
|
103
94
|
kyOptions.hooks.afterResponse.push((0, http_1.wrapResponseClosure)(options.onResponse));
|
|
104
95
|
}
|
|
105
|
-
this.
|
|
96
|
+
this.kyOptions = (0, merge_1.deepMerge)(http_1.DEFAULT_KY_CONFIG, kyOptions);
|
|
106
97
|
}
|
|
107
98
|
/**
|
|
108
99
|
* Upload data to a Bee node
|
|
@@ -115,14 +106,12 @@ class Bee {
|
|
|
115
106
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
116
107
|
* @see [Bee API reference - `POST /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes/post)
|
|
117
108
|
*/
|
|
118
|
-
uploadData(postageBatchId, data, options) {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
return bytes.upload(this.getKy(options), data, postageBatchId, options);
|
|
125
|
-
});
|
|
109
|
+
async uploadData(postageBatchId, data, options) {
|
|
110
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
111
|
+
(0, type_2.assertData)(data);
|
|
112
|
+
if (options)
|
|
113
|
+
(0, type_2.assertUploadOptions)(options);
|
|
114
|
+
return bytes.upload(this.getKyOptionsForCall(options), data, postageBatchId, options);
|
|
126
115
|
}
|
|
127
116
|
/**
|
|
128
117
|
* Download data as a byte array
|
|
@@ -134,12 +123,10 @@ class Bee {
|
|
|
134
123
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
135
124
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
136
125
|
*/
|
|
137
|
-
downloadData(reference, options) {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return bytes.download(this.getKy(options), reference);
|
|
142
|
-
});
|
|
126
|
+
async downloadData(reference, options) {
|
|
127
|
+
(0, type_2.assertRequestOptions)(options);
|
|
128
|
+
(0, type_2.assertReferenceOrEns)(reference);
|
|
129
|
+
return bytes.download(this.getKyOptionsForCall(options), reference);
|
|
143
130
|
}
|
|
144
131
|
/**
|
|
145
132
|
* Download data as a Readable stream
|
|
@@ -151,12 +138,10 @@ class Bee {
|
|
|
151
138
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
152
139
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
153
140
|
*/
|
|
154
|
-
downloadReadableData(reference, options) {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
return bytes.downloadReadable(this.getKy(options), reference);
|
|
159
|
-
});
|
|
141
|
+
async downloadReadableData(reference, options) {
|
|
142
|
+
(0, type_2.assertRequestOptions)(options);
|
|
143
|
+
(0, type_2.assertReferenceOrEns)(reference);
|
|
144
|
+
return bytes.downloadReadable(this.getKyOptionsForCall(options), reference);
|
|
160
145
|
}
|
|
161
146
|
/**
|
|
162
147
|
* Upload chunk to a Bee node
|
|
@@ -169,22 +154,20 @@ class Bee {
|
|
|
169
154
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
170
155
|
* @see [Bee API reference - `POST /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks/post)
|
|
171
156
|
*/
|
|
172
|
-
uploadChunk(postageBatchId, data, options) {
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
return chunk.upload(this.getKy(options), data, postageBatchId, options);
|
|
187
|
-
});
|
|
157
|
+
async uploadChunk(postageBatchId, data, options) {
|
|
158
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
159
|
+
if (!(data instanceof Uint8Array)) {
|
|
160
|
+
throw new TypeError('Data has to be Uint8Array instance!');
|
|
161
|
+
}
|
|
162
|
+
if (data.length < types_1.SPAN_SIZE) {
|
|
163
|
+
throw new error_1.BeeArgumentError(`Chunk has to have size of at least ${types_1.SPAN_SIZE}.`, data);
|
|
164
|
+
}
|
|
165
|
+
if (data.length > types_1.CHUNK_SIZE + types_1.SPAN_SIZE) {
|
|
166
|
+
throw new error_1.BeeArgumentError(`Chunk has to have size of at most ${types_1.CHUNK_SIZE}.`, data);
|
|
167
|
+
}
|
|
168
|
+
if (options)
|
|
169
|
+
(0, type_2.assertUploadOptions)(options);
|
|
170
|
+
return chunk.upload(this.getKyOptionsForCall(options), data, postageBatchId, options);
|
|
188
171
|
}
|
|
189
172
|
/**
|
|
190
173
|
* Download chunk as a byte array
|
|
@@ -196,12 +179,10 @@ class Bee {
|
|
|
196
179
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
197
180
|
* @see [Bee API reference - `GET /chunks`](https://docs.ethswarm.org/api/#tag/Chunk/paths/~1chunks~1{reference}/get)
|
|
198
181
|
*/
|
|
199
|
-
downloadChunk(reference, options) {
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
return chunk.download(this.getKy(options), reference);
|
|
204
|
-
});
|
|
182
|
+
async downloadChunk(reference, options) {
|
|
183
|
+
(0, type_2.assertRequestOptions)(options);
|
|
184
|
+
(0, type_2.assertReferenceOrEns)(reference);
|
|
185
|
+
return chunk.download(this.getKyOptionsForCall(options), reference);
|
|
205
186
|
}
|
|
206
187
|
/**
|
|
207
188
|
* Upload single file to a Bee node.
|
|
@@ -219,32 +200,30 @@ class Bee {
|
|
|
219
200
|
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/File/paths/~1bzz/post)
|
|
220
201
|
* @returns reference is a content hash of the file
|
|
221
202
|
*/
|
|
222
|
-
uploadFile(postageBatchId, data, name, options) {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
}
|
|
247
|
-
});
|
|
203
|
+
async uploadFile(postageBatchId, data, name, options) {
|
|
204
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
205
|
+
(0, type_2.assertFileData)(data);
|
|
206
|
+
if (options)
|
|
207
|
+
(0, type_2.assertFileUploadOptions)(options);
|
|
208
|
+
if (name && typeof name !== 'string') {
|
|
209
|
+
throw new TypeError('name has to be string or undefined!');
|
|
210
|
+
}
|
|
211
|
+
if ((0, file_1.isFile)(data)) {
|
|
212
|
+
const fileData = await (0, file_1.fileArrayBuffer)(data);
|
|
213
|
+
const fileName = name ?? data.name;
|
|
214
|
+
const contentType = data.type;
|
|
215
|
+
const fileOptions = { contentType, ...options };
|
|
216
|
+
return (0, type_2.addCidConversionFunction)(await bzz.uploadFile(this.getKyOptionsForCall(options), fileData, postageBatchId, fileName, fileOptions), swarm_cid_1.ReferenceType.MANIFEST);
|
|
217
|
+
}
|
|
218
|
+
else if ((0, stream_1.isReadable)(data) && options?.tag && !options.size) {
|
|
219
|
+
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
220
|
+
const result = await bzz.uploadFile(this.getKyOptionsForCall(options), data, postageBatchId, name, options);
|
|
221
|
+
await this.updateTag(options.tag, result.reference);
|
|
222
|
+
return (0, type_2.addCidConversionFunction)(result, swarm_cid_1.ReferenceType.MANIFEST);
|
|
223
|
+
}
|
|
224
|
+
else {
|
|
225
|
+
return (0, type_2.addCidConversionFunction)(await bzz.uploadFile(this.getKyOptionsForCall(options), data, postageBatchId, name, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
226
|
+
}
|
|
248
227
|
}
|
|
249
228
|
/**
|
|
250
229
|
* Download single file.
|
|
@@ -258,12 +237,10 @@ class Bee {
|
|
|
258
237
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
259
238
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
260
239
|
*/
|
|
261
|
-
downloadFile(reference, path = '', options) {
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
return bzz.downloadFile(this.getKy(options), reference, path);
|
|
266
|
-
});
|
|
240
|
+
async downloadFile(reference, path = '', options) {
|
|
241
|
+
(0, type_2.assertRequestOptions)(options);
|
|
242
|
+
reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
|
|
243
|
+
return bzz.downloadFile(this.getKyOptionsForCall(options), reference, path);
|
|
267
244
|
}
|
|
268
245
|
/**
|
|
269
246
|
* Download single file as a readable stream
|
|
@@ -277,12 +254,10 @@ class Bee {
|
|
|
277
254
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/access-the-swarm/upload-and-download)
|
|
278
255
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz~1{reference}~1{path}/get)
|
|
279
256
|
*/
|
|
280
|
-
downloadReadableFile(reference, path = '', options) {
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
return bzz.downloadFileReadable(this.getKy(options), reference, path);
|
|
285
|
-
});
|
|
257
|
+
async downloadReadableFile(reference, path = '', options) {
|
|
258
|
+
(0, type_2.assertRequestOptions)(options);
|
|
259
|
+
reference = (0, type_2.makeReferenceOrEns)(reference, swarm_cid_1.ReferenceType.MANIFEST);
|
|
260
|
+
return bzz.downloadFileReadable(this.getKyOptionsForCall(options), reference, path);
|
|
286
261
|
}
|
|
287
262
|
/**
|
|
288
263
|
* Upload collection of files to a Bee node
|
|
@@ -300,14 +275,12 @@ class Bee {
|
|
|
300
275
|
* @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
|
|
301
276
|
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
|
|
302
277
|
*/
|
|
303
|
-
uploadFiles(postageBatchId, fileList, options) {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
310
|
-
});
|
|
278
|
+
async uploadFiles(postageBatchId, fileList, options) {
|
|
279
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
280
|
+
if (options)
|
|
281
|
+
(0, type_2.assertCollectionUploadOptions)(options);
|
|
282
|
+
const data = await (0, collection_1.makeCollectionFromFileList)(fileList);
|
|
283
|
+
return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.getKyOptionsForCall(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
311
284
|
}
|
|
312
285
|
/**
|
|
313
286
|
* Upload Collection that you can assembly yourself.
|
|
@@ -319,14 +292,12 @@ class Bee {
|
|
|
319
292
|
* @param collection
|
|
320
293
|
* @param options Collections and request options
|
|
321
294
|
*/
|
|
322
|
-
uploadCollection(postageBatchId, collection, options) {
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.ky, collection, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
329
|
-
});
|
|
295
|
+
async uploadCollection(postageBatchId, collection, options) {
|
|
296
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
297
|
+
(0, collection_1.assertCollection)(collection);
|
|
298
|
+
if (options)
|
|
299
|
+
(0, type_2.assertCollectionUploadOptions)(options);
|
|
300
|
+
return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.kyOptions, collection, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
330
301
|
}
|
|
331
302
|
/**
|
|
332
303
|
* Upload collection of files.
|
|
@@ -344,37 +315,29 @@ class Bee {
|
|
|
344
315
|
* @see [Bee docs - Upload directory](https://docs.ethswarm.org/docs/access-the-swarm/upload-a-directory/)
|
|
345
316
|
* @see [Bee API reference - `POST /bzz`](https://docs.ethswarm.org/api/#tag/Collection/paths/~1bzz/post)
|
|
346
317
|
*/
|
|
347
|
-
uploadFilesFromDirectory(postageBatchId, dir, options) {
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
return (0, type_2.addCidConversionFunction)(yield bzz.uploadCollection(this.getKy(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
354
|
-
});
|
|
318
|
+
async uploadFilesFromDirectory(postageBatchId, dir, options) {
|
|
319
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
320
|
+
if (options)
|
|
321
|
+
(0, type_2.assertCollectionUploadOptions)(options);
|
|
322
|
+
const data = await (0, collection_node_1.makeCollectionFromFS)(dir);
|
|
323
|
+
return (0, type_2.addCidConversionFunction)(await bzz.uploadCollection(this.getKyOptionsForCall(options), data, postageBatchId, options), swarm_cid_1.ReferenceType.MANIFEST);
|
|
355
324
|
}
|
|
356
325
|
/**
|
|
357
326
|
* Create a new Tag which is meant for tracking progres of syncing data across network.
|
|
358
327
|
*
|
|
359
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
360
|
-
*
|
|
361
328
|
* @param options Options that affects the request behavior
|
|
362
329
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
363
330
|
* @see [Bee API reference - `POST /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/post)
|
|
364
331
|
*/
|
|
365
|
-
createTag(options) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
return tag.createTag(this.getKy(options));
|
|
369
|
-
});
|
|
332
|
+
async createTag(options) {
|
|
333
|
+
(0, type_2.assertRequestOptions)(options);
|
|
334
|
+
return tag.createTag(this.getKyOptionsForCall(options));
|
|
370
335
|
}
|
|
371
336
|
/**
|
|
372
337
|
* Fetches all tags.
|
|
373
338
|
*
|
|
374
339
|
* The listing is limited by options.limit. So you have to iterate using options.offset to get all tags.
|
|
375
340
|
*
|
|
376
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
377
|
-
*
|
|
378
341
|
* @param options Options that affects the request behavior
|
|
379
342
|
* @throws TypeError if limit or offset are not numbers or undefined
|
|
380
343
|
* @throws BeeArgumentError if limit or offset have invalid options
|
|
@@ -382,18 +345,14 @@ class Bee {
|
|
|
382
345
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
383
346
|
* @see [Bee API reference - `GET /tags`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags/get)
|
|
384
347
|
*/
|
|
385
|
-
getAllTags(options) {
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
return tag.getAllTags(this.getKy(options), options === null || options === void 0 ? void 0 : options.offset, options === null || options === void 0 ? void 0 : options.limit);
|
|
390
|
-
});
|
|
348
|
+
async getAllTags(options) {
|
|
349
|
+
(0, type_2.assertRequestOptions)(options);
|
|
350
|
+
(0, type_2.assertAllTagsOptions)(options);
|
|
351
|
+
return tag.getAllTags(this.getKyOptionsForCall(options), options?.offset, options?.limit);
|
|
391
352
|
}
|
|
392
353
|
/**
|
|
393
354
|
* Retrieve tag information from Bee node
|
|
394
355
|
*
|
|
395
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
396
|
-
*
|
|
397
356
|
* @param tagUid UID or tag object to be retrieved
|
|
398
357
|
* @param options Options that affects the request behavior
|
|
399
358
|
* @throws TypeError if tagUid is in not correct format
|
|
@@ -402,18 +361,14 @@ class Bee {
|
|
|
402
361
|
* @see [Bee API reference - `GET /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/get)
|
|
403
362
|
*
|
|
404
363
|
*/
|
|
405
|
-
retrieveTag(tagUid, options) {
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
return tag.retrieveTag(this.getKy(options), tagUid);
|
|
410
|
-
});
|
|
364
|
+
async retrieveTag(tagUid, options) {
|
|
365
|
+
(0, type_2.assertRequestOptions)(options);
|
|
366
|
+
tagUid = (0, type_2.makeTagUid)(tagUid);
|
|
367
|
+
return tag.retrieveTag(this.getKyOptionsForCall(options), tagUid);
|
|
411
368
|
}
|
|
412
369
|
/**
|
|
413
370
|
* Delete Tag
|
|
414
371
|
*
|
|
415
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
416
|
-
*
|
|
417
372
|
* @param tagUid UID or tag object to be retrieved
|
|
418
373
|
* @param options Options that affects the request behavior
|
|
419
374
|
* @throws TypeError if tagUid is in not correct format
|
|
@@ -422,12 +377,10 @@ class Bee {
|
|
|
422
377
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
423
378
|
* @see [Bee API reference - `DELETE /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/delete)
|
|
424
379
|
*/
|
|
425
|
-
deleteTag(tagUid, options) {
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
return tag.deleteTag(this.getKy(options), tagUid);
|
|
430
|
-
});
|
|
380
|
+
async deleteTag(tagUid, options) {
|
|
381
|
+
(0, type_2.assertRequestOptions)(options);
|
|
382
|
+
tagUid = (0, type_2.makeTagUid)(tagUid);
|
|
383
|
+
return tag.deleteTag(this.getKyOptionsForCall(options), tagUid);
|
|
431
384
|
}
|
|
432
385
|
/**
|
|
433
386
|
* Update tag's total chunks count.
|
|
@@ -435,8 +388,6 @@ class Bee {
|
|
|
435
388
|
* This is important if you are uploading individual chunks with a tag. Then upon finishing the final root chunk,
|
|
436
389
|
* you can use this method to update the total chunks count for the tag.
|
|
437
390
|
*
|
|
438
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
439
|
-
*
|
|
440
391
|
* @param tagUid UID or tag object to be retrieved
|
|
441
392
|
* @param reference The root reference that contains all the chunks to be counted
|
|
442
393
|
* @param options Options that affects the request behavior
|
|
@@ -446,69 +397,53 @@ class Bee {
|
|
|
446
397
|
* @see [Bee docs - Syncing / Tags](https://docs.ethswarm.org/docs/access-the-swarm/syncing)
|
|
447
398
|
* @see [Bee API reference - `PATCH /tags/{uid}`](https://docs.ethswarm.org/api/#tag/Tag/paths/~1tags~1{uid}/patch)
|
|
448
399
|
*/
|
|
449
|
-
updateTag(tagUid, reference, options) {
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
return tag.updateTag(this.getKy(options), tagUid, reference);
|
|
455
|
-
});
|
|
400
|
+
async updateTag(tagUid, reference, options) {
|
|
401
|
+
(0, type_2.assertReference)(reference);
|
|
402
|
+
(0, type_2.assertRequestOptions)(options);
|
|
403
|
+
tagUid = (0, type_2.makeTagUid)(tagUid);
|
|
404
|
+
return tag.updateTag(this.getKyOptionsForCall(options), tagUid, reference);
|
|
456
405
|
}
|
|
457
406
|
/**
|
|
458
407
|
* Pin local data with given reference
|
|
459
408
|
*
|
|
460
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
461
|
-
*
|
|
462
409
|
* @param reference Data reference
|
|
463
410
|
* @param options Options that affects the request behavior
|
|
464
411
|
* @throws TypeError if reference is in not correct format
|
|
465
412
|
*
|
|
466
413
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
467
414
|
*/
|
|
468
|
-
pin(reference, options) {
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
return pinning.pin(this.getKy(options), reference);
|
|
473
|
-
});
|
|
415
|
+
async pin(reference, options) {
|
|
416
|
+
(0, type_2.assertRequestOptions)(options);
|
|
417
|
+
(0, type_2.assertReference)(reference);
|
|
418
|
+
return pinning.pin(this.getKyOptionsForCall(options), reference);
|
|
474
419
|
}
|
|
475
420
|
/**
|
|
476
421
|
* Unpin local data with given reference
|
|
477
422
|
*
|
|
478
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
479
|
-
*
|
|
480
423
|
* @param reference Data reference
|
|
481
424
|
* @param options Options that affects the request behavior
|
|
482
425
|
* @throws TypeError if reference is in not correct format
|
|
483
426
|
*
|
|
484
427
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
485
428
|
*/
|
|
486
|
-
unpin(reference, options) {
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
return pinning.unpin(this.getKy(options), reference);
|
|
491
|
-
});
|
|
429
|
+
async unpin(reference, options) {
|
|
430
|
+
(0, type_2.assertRequestOptions)(options);
|
|
431
|
+
(0, type_2.assertReference)(reference);
|
|
432
|
+
return pinning.unpin(this.getKyOptionsForCall(options), reference);
|
|
492
433
|
}
|
|
493
434
|
/**
|
|
494
435
|
* Get list of all locally pinned references
|
|
495
436
|
*
|
|
496
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
497
|
-
*
|
|
498
437
|
* @param options Options that affects the request behavior
|
|
499
438
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
500
439
|
*/
|
|
501
|
-
getAllPins(options) {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
return pinning.getAllPins(this.getKy(options));
|
|
505
|
-
});
|
|
440
|
+
async getAllPins(options) {
|
|
441
|
+
(0, type_2.assertRequestOptions)(options);
|
|
442
|
+
return pinning.getAllPins(this.getKyOptionsForCall(options));
|
|
506
443
|
}
|
|
507
444
|
/**
|
|
508
445
|
* Get pinning status of chunk with given reference
|
|
509
446
|
*
|
|
510
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
511
|
-
*
|
|
512
447
|
* @param reference Bee data reference in hex string (either 64 or 128 chars long) or ENS domain.
|
|
513
448
|
* @param options Options that affects the request behavior
|
|
514
449
|
* @throws TypeError if some of the input parameters is not expected type
|
|
@@ -516,12 +451,10 @@ class Bee {
|
|
|
516
451
|
*
|
|
517
452
|
* @see [Bee docs - Pinning](https://docs.ethswarm.org/docs/access-the-swarm/pinning)
|
|
518
453
|
*/
|
|
519
|
-
getPin(reference, options) {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
return pinning.getPin(this.getKy(options), reference);
|
|
524
|
-
});
|
|
454
|
+
async getPin(reference, options) {
|
|
455
|
+
(0, type_2.assertRequestOptions)(options);
|
|
456
|
+
(0, type_2.assertReference)(reference);
|
|
457
|
+
return pinning.getPin(this.getKyOptionsForCall(options), reference);
|
|
525
458
|
}
|
|
526
459
|
/**
|
|
527
460
|
* Instructs the Bee node to reupload a locally pinned data into the network.
|
|
@@ -534,12 +467,10 @@ class Bee {
|
|
|
534
467
|
*
|
|
535
468
|
* @see [Bee API reference - `PUT /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/put)
|
|
536
469
|
*/
|
|
537
|
-
reuploadPinnedData(reference, options) {
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
yield stewardship.reupload(this.getKy(options), reference);
|
|
542
|
-
});
|
|
470
|
+
async reuploadPinnedData(reference, options) {
|
|
471
|
+
(0, type_2.assertRequestOptions)(options);
|
|
472
|
+
(0, type_2.assertReferenceOrEns)(reference);
|
|
473
|
+
await stewardship.reupload(this.getKyOptionsForCall(options), reference);
|
|
543
474
|
}
|
|
544
475
|
/**
|
|
545
476
|
* Checks if content specified by reference is retrievable from the network.
|
|
@@ -551,12 +482,10 @@ class Bee {
|
|
|
551
482
|
*
|
|
552
483
|
* @see [Bee API reference - `GET /stewardship`](https://docs.ethswarm.org/api/#tag/Stewardship/paths/~1stewardship~1{reference}/get)
|
|
553
484
|
*/
|
|
554
|
-
isReferenceRetrievable(reference, options) {
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
return stewardship.isRetrievable(this.getKy(options), reference);
|
|
559
|
-
});
|
|
485
|
+
async isReferenceRetrievable(reference, options) {
|
|
486
|
+
(0, type_2.assertRequestOptions)(options);
|
|
487
|
+
(0, type_2.assertReferenceOrEns)(reference);
|
|
488
|
+
return stewardship.isRetrievable(this.getKyOptionsForCall(options), reference);
|
|
560
489
|
}
|
|
561
490
|
/**
|
|
562
491
|
* Functions that validates if feed is retrievable in the network.
|
|
@@ -573,29 +502,27 @@ class Bee {
|
|
|
573
502
|
* @param index
|
|
574
503
|
* @param options
|
|
575
504
|
*/
|
|
576
|
-
isFeedRetrievable(type, owner, topic, index, options) {
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
return true;
|
|
584
|
-
}
|
|
585
|
-
catch (e) {
|
|
586
|
-
const err = e;
|
|
587
|
-
// Only if the error is "not-found" then we return false otherwise we re-throw the error
|
|
588
|
-
if ((err === null || err === void 0 ? void 0 : err.status) === 404) {
|
|
589
|
-
return false;
|
|
590
|
-
}
|
|
591
|
-
throw e;
|
|
592
|
-
}
|
|
505
|
+
async isFeedRetrievable(type, owner, topic, index, options) {
|
|
506
|
+
const canonicalOwner = (0, eth_1.makeEthAddress)(owner);
|
|
507
|
+
const canonicalTopic = (0, topic_1.makeTopic)(topic);
|
|
508
|
+
if (!index) {
|
|
509
|
+
try {
|
|
510
|
+
await this.makeFeedReader(type, canonicalTopic, canonicalOwner).download();
|
|
511
|
+
return true;
|
|
593
512
|
}
|
|
594
|
-
|
|
595
|
-
|
|
513
|
+
catch (e) {
|
|
514
|
+
const err = e;
|
|
515
|
+
// Only if the error is "not-found" then we return false otherwise we re-throw the error
|
|
516
|
+
if (err?.status === 404) {
|
|
517
|
+
return false;
|
|
518
|
+
}
|
|
519
|
+
throw e;
|
|
596
520
|
}
|
|
597
|
-
|
|
598
|
-
|
|
521
|
+
}
|
|
522
|
+
if (type !== 'sequence') {
|
|
523
|
+
throw new error_1.BeeError('Only Sequence type of Feeds is supported at the moment');
|
|
524
|
+
}
|
|
525
|
+
return (0, retrievable_1.areAllSequentialFeedsUpdateRetrievable)(this, canonicalOwner, canonicalTopic, index, options);
|
|
599
526
|
}
|
|
600
527
|
/**
|
|
601
528
|
* Send data to recipient or target with Postal Service for Swarm.
|
|
@@ -605,8 +532,6 @@ class Bee {
|
|
|
605
532
|
* most likely for setting up an encrypted communication
|
|
606
533
|
* channel by sending an one-off message.
|
|
607
534
|
*
|
|
608
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
609
|
-
*
|
|
610
535
|
* **Warning! If the recipient Bee node is a light node, then he will never receive the message!**
|
|
611
536
|
* This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
|
|
612
537
|
*
|
|
@@ -621,29 +546,25 @@ class Bee {
|
|
|
621
546
|
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
|
|
622
547
|
* @see [Bee API reference - `POST /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1send~1{topic}~1{targets}/post)
|
|
623
548
|
*/
|
|
624
|
-
pssSend(postageBatchId, topic, target, data, recipient, options) {
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
}
|
|
640
|
-
});
|
|
549
|
+
async pssSend(postageBatchId, topic, target, data, recipient, options) {
|
|
550
|
+
(0, type_2.assertRequestOptions)(options);
|
|
551
|
+
(0, type_2.assertData)(data);
|
|
552
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
553
|
+
(0, type_2.assertAddressPrefix)(target);
|
|
554
|
+
if (typeof topic !== 'string') {
|
|
555
|
+
throw new TypeError('topic has to be an string!');
|
|
556
|
+
}
|
|
557
|
+
if (recipient) {
|
|
558
|
+
(0, type_2.assertPublicKey)(recipient);
|
|
559
|
+
return pss.send(this.getKyOptionsForCall(options), topic, target, data, postageBatchId, recipient);
|
|
560
|
+
}
|
|
561
|
+
else {
|
|
562
|
+
return pss.send(this.getKyOptionsForCall(options), topic, target, data, postageBatchId);
|
|
563
|
+
}
|
|
641
564
|
}
|
|
642
565
|
/**
|
|
643
566
|
* Subscribe to messages for given topic with Postal Service for Swarm
|
|
644
567
|
*
|
|
645
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
646
|
-
*
|
|
647
568
|
* **Warning! If connected Bee node is a light node, then he will never receive any message!**
|
|
648
569
|
* This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
|
|
649
570
|
*
|
|
@@ -678,13 +599,13 @@ class Bee {
|
|
|
678
599
|
topic,
|
|
679
600
|
cancel,
|
|
680
601
|
};
|
|
681
|
-
ws.onmessage = (ev) =>
|
|
682
|
-
const data =
|
|
602
|
+
ws.onmessage = async (ev) => {
|
|
603
|
+
const data = await (0, data_1.prepareWebsocketData)(ev.data);
|
|
683
604
|
// ignore empty messages
|
|
684
605
|
if (data.length > 0) {
|
|
685
606
|
handler.onMessage((0, bytes_1.wrapBytesWithHelpers)(data), subscription);
|
|
686
607
|
}
|
|
687
|
-
}
|
|
608
|
+
};
|
|
688
609
|
ws.onerror = ev => {
|
|
689
610
|
// ignore errors after subscription was cancelled
|
|
690
611
|
if (!cancelled) {
|
|
@@ -706,8 +627,6 @@ class Bee {
|
|
|
706
627
|
* timeout can be provided for the message to arrive or else
|
|
707
628
|
* an error will be thrown.
|
|
708
629
|
*
|
|
709
|
-
* **Warning! Not allowed when node is in Gateway mode!**
|
|
710
|
-
*
|
|
711
630
|
* **Warning! If connected Bee node is a light node, then he will never receive any message!**
|
|
712
631
|
* This is because light nodes does not fully participate in the data exchange in Swarm network and hence the message won't arrive to them.
|
|
713
632
|
*
|
|
@@ -719,37 +638,35 @@ class Bee {
|
|
|
719
638
|
* @see [Bee docs - PSS](https://docs.ethswarm.org/docs/dapps-on-swarm/pss)
|
|
720
639
|
* @see [Bee API reference - `GET /pss`](https://docs.ethswarm.org/api/#tag/Postal-Service-for-Swarm/paths/~1pss~1subscribe~1{topic}/get)
|
|
721
640
|
*/
|
|
722
|
-
pssReceive(topic, timeoutMsec = 0) {
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
},
|
|
743
|
-
});
|
|
744
|
-
if (timeoutMsec > 0) {
|
|
745
|
-
// we need to cast the type because Typescript is getting confused with Node.js'
|
|
746
|
-
// alternative type definitions
|
|
747
|
-
timeout = setTimeout(() => {
|
|
748
|
-
subscription.cancel();
|
|
749
|
-
reject(new error_1.BeeError('pssReceive timeout'));
|
|
750
|
-
}, timeoutMsec);
|
|
751
|
-
}
|
|
641
|
+
async pssReceive(topic, timeoutMsec = 0) {
|
|
642
|
+
if (typeof topic !== 'string') {
|
|
643
|
+
throw new TypeError('topic has to be an string!');
|
|
644
|
+
}
|
|
645
|
+
if (typeof timeoutMsec !== 'number') {
|
|
646
|
+
throw new TypeError('timeoutMsc parameter has to be a number!');
|
|
647
|
+
}
|
|
648
|
+
return new Promise((resolve, reject) => {
|
|
649
|
+
let timeout;
|
|
650
|
+
const subscription = this.pssSubscribe(topic, {
|
|
651
|
+
onError: error => {
|
|
652
|
+
clearTimeout(timeout);
|
|
653
|
+
subscription.cancel();
|
|
654
|
+
reject(error.message);
|
|
655
|
+
},
|
|
656
|
+
onMessage: message => {
|
|
657
|
+
clearTimeout(timeout);
|
|
658
|
+
subscription.cancel();
|
|
659
|
+
resolve(message);
|
|
660
|
+
},
|
|
752
661
|
});
|
|
662
|
+
if (timeoutMsec > 0) {
|
|
663
|
+
// we need to cast the type because Typescript is getting confused with Node.js'
|
|
664
|
+
// alternative type definitions
|
|
665
|
+
timeout = setTimeout(() => {
|
|
666
|
+
subscription.cancel();
|
|
667
|
+
reject(new error_1.BeeError('pssReceive timeout'));
|
|
668
|
+
}, timeoutMsec);
|
|
669
|
+
}
|
|
753
670
|
});
|
|
754
671
|
}
|
|
755
672
|
/**
|
|
@@ -766,18 +683,16 @@ class Bee {
|
|
|
766
683
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
|
|
767
684
|
* @see [Bee API reference - `POST /feeds`](https://docs.ethswarm.org/api/#tag/Feed/paths/~1feeds~1{owner}~1{topic}/post)
|
|
768
685
|
*/
|
|
769
|
-
createFeedManifest(postageBatchId, type, topic, owner, options) {
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
type,
|
|
778
|
-
});
|
|
779
|
-
return (0, type_2.addCidConversionFunction)({ reference }, swarm_cid_1.ReferenceType.FEED);
|
|
686
|
+
async createFeedManifest(postageBatchId, type, topic, owner, options) {
|
|
687
|
+
(0, type_2.assertRequestOptions)(options);
|
|
688
|
+
(0, type_1.assertFeedType)(type);
|
|
689
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
690
|
+
const canonicalTopic = (0, topic_1.makeTopic)(topic);
|
|
691
|
+
const canonicalOwner = (0, eth_1.makeHexEthAddress)(owner);
|
|
692
|
+
const reference = await (0, feed_2.createFeedManifest)(this.getKyOptionsForCall(options), canonicalOwner, canonicalTopic, postageBatchId, {
|
|
693
|
+
type,
|
|
780
694
|
});
|
|
695
|
+
return (0, type_2.addCidConversionFunction)({ reference }, swarm_cid_1.ReferenceType.FEED);
|
|
781
696
|
}
|
|
782
697
|
/**
|
|
783
698
|
* Make a new feed reader for downloading feed updates.
|
|
@@ -794,7 +709,7 @@ class Bee {
|
|
|
794
709
|
(0, type_1.assertFeedType)(type);
|
|
795
710
|
const canonicalTopic = (0, topic_1.makeTopic)(topic);
|
|
796
711
|
const canonicalOwner = (0, eth_1.makeHexEthAddress)(owner);
|
|
797
|
-
return (0, feed_1.makeFeedReader)(this.
|
|
712
|
+
return (0, feed_1.makeFeedReader)(this.getKyOptionsForCall(options), type, canonicalTopic, canonicalOwner);
|
|
798
713
|
}
|
|
799
714
|
/**
|
|
800
715
|
* Make a new feed writer for updating feeds
|
|
@@ -811,7 +726,7 @@ class Bee {
|
|
|
811
726
|
(0, type_1.assertFeedType)(type);
|
|
812
727
|
const canonicalTopic = (0, topic_1.makeTopic)(topic);
|
|
813
728
|
const canonicalSigner = this.resolveSigner(signer);
|
|
814
|
-
return (0, feed_1.makeFeedWriter)(this.
|
|
729
|
+
return (0, feed_1.makeFeedWriter)(this.getKyOptionsForCall(options), type, canonicalTopic, canonicalSigner);
|
|
815
730
|
}
|
|
816
731
|
/**
|
|
817
732
|
* High-level function that allows you to easily set JSON data to feed.
|
|
@@ -831,16 +746,13 @@ class Bee {
|
|
|
831
746
|
*
|
|
832
747
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
|
|
833
748
|
*/
|
|
834
|
-
setJsonFeed(postageBatchId, topic, data, options) {
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
const writer = this.makeFeedWriter(feedType, hashedTopic, options === null || options === void 0 ? void 0 : options.signer, options);
|
|
842
|
-
return (0, json_1.setJsonData)(this, writer, postageBatchId, data, options);
|
|
843
|
-
});
|
|
749
|
+
async setJsonFeed(postageBatchId, topic, data, options) {
|
|
750
|
+
(0, type_2.assertRequestOptions)(options, 'JsonFeedOptions');
|
|
751
|
+
(0, type_2.assertBatchId)(postageBatchId);
|
|
752
|
+
const hashedTopic = this.makeFeedTopic(topic);
|
|
753
|
+
const feedType = options?.type ?? type_1.DEFAULT_FEED_TYPE;
|
|
754
|
+
const writer = this.makeFeedWriter(feedType, hashedTopic, options?.signer, options);
|
|
755
|
+
return (0, json_1.setJsonData)(this, writer, postageBatchId, data, options);
|
|
844
756
|
}
|
|
845
757
|
/**
|
|
846
758
|
* High-level function that allows you to easily get data from feed.
|
|
@@ -861,35 +773,32 @@ class Bee {
|
|
|
861
773
|
*
|
|
862
774
|
* @see [Bee docs - Feeds](https://docs.ethswarm.org/docs/dapps-on-swarm/feeds)
|
|
863
775
|
*/
|
|
864
|
-
getJsonFeed(topic, options) {
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
776
|
+
async getJsonFeed(topic, options) {
|
|
777
|
+
(0, type_2.assertRequestOptions)(options, 'JsonFeedOptions');
|
|
778
|
+
const hashedTopic = this.makeFeedTopic(topic);
|
|
779
|
+
const feedType = options?.type ?? type_1.DEFAULT_FEED_TYPE;
|
|
780
|
+
if (options?.signer && options?.address) {
|
|
781
|
+
throw new error_1.BeeError('Both options "signer" and "address" can not be specified at one time!');
|
|
782
|
+
}
|
|
783
|
+
let address;
|
|
784
|
+
if (options?.address) {
|
|
785
|
+
address = (0, eth_1.makeEthAddress)(options?.address);
|
|
786
|
+
}
|
|
787
|
+
else {
|
|
788
|
+
try {
|
|
789
|
+
address = this.resolveSigner(options?.signer).address;
|
|
876
790
|
}
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
791
|
+
catch (e) {
|
|
792
|
+
if (e instanceof error_1.BeeError) {
|
|
793
|
+
throw new error_1.BeeError('Either address, signer or default signer has to be specified!');
|
|
880
794
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
throw new error_1.BeeError('Either address, signer or default signer has to be specified!');
|
|
884
|
-
}
|
|
885
|
-
else {
|
|
886
|
-
throw e;
|
|
887
|
-
}
|
|
795
|
+
else {
|
|
796
|
+
throw e;
|
|
888
797
|
}
|
|
889
798
|
}
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
799
|
+
}
|
|
800
|
+
const reader = this.makeFeedReader(feedType, hashedTopic, address, options);
|
|
801
|
+
return (0, json_1.getJsonData)(this, reader);
|
|
893
802
|
}
|
|
894
803
|
/**
|
|
895
804
|
* Make a new feed topic from a string
|
|
@@ -914,7 +823,7 @@ class Bee {
|
|
|
914
823
|
const canonicalOwner = (0, eth_1.makeEthAddress)(ownerAddress);
|
|
915
824
|
return {
|
|
916
825
|
owner: (0, eth_1.makeHexEthAddress)(canonicalOwner),
|
|
917
|
-
download: soc_1.downloadSingleOwnerChunk.bind(null, this.
|
|
826
|
+
download: soc_1.downloadSingleOwnerChunk.bind(null, this.getKyOptionsForCall(options), canonicalOwner),
|
|
918
827
|
};
|
|
919
828
|
}
|
|
920
829
|
/**
|
|
@@ -927,7 +836,10 @@ class Bee {
|
|
|
927
836
|
makeSOCWriter(signer, options) {
|
|
928
837
|
(0, type_2.assertRequestOptions)(options);
|
|
929
838
|
const canonicalSigner = this.resolveSigner(signer);
|
|
930
|
-
return
|
|
839
|
+
return {
|
|
840
|
+
...this.makeSOCReader(canonicalSigner.address, options),
|
|
841
|
+
upload: soc_1.uploadSingleOwnerChunkData.bind(null, this.getKyOptionsForCall(options), canonicalSigner),
|
|
842
|
+
};
|
|
931
843
|
}
|
|
932
844
|
/**
|
|
933
845
|
* Ping the Bee node to see if there is a live Bee node on the given URL.
|
|
@@ -935,11 +847,9 @@ class Bee {
|
|
|
935
847
|
* @param options Options that affects the request behavior
|
|
936
848
|
* @throws If connection was not successful throw error
|
|
937
849
|
*/
|
|
938
|
-
checkConnection(options) {
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
return status.checkConnection(this.getKy(options));
|
|
942
|
-
});
|
|
850
|
+
async checkConnection(options) {
|
|
851
|
+
(0, type_2.assertRequestOptions)(options, 'PostageBatchOptions');
|
|
852
|
+
return status.checkConnection(this.getKyOptionsForCall(options));
|
|
943
853
|
}
|
|
944
854
|
/**
|
|
945
855
|
* Ping the Bee node to see if there is a live Bee node on the given URL.
|
|
@@ -947,17 +857,15 @@ class Bee {
|
|
|
947
857
|
* @param options Options that affects the request behavior
|
|
948
858
|
* @returns true if successful, false on error
|
|
949
859
|
*/
|
|
950
|
-
isConnected(options) {
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
return true;
|
|
960
|
-
});
|
|
860
|
+
async isConnected(options) {
|
|
861
|
+
(0, type_2.assertRequestOptions)(options, 'PostageBatchOptions');
|
|
862
|
+
try {
|
|
863
|
+
await status.checkConnection(this.getKyOptionsForCall(options));
|
|
864
|
+
}
|
|
865
|
+
catch (e) {
|
|
866
|
+
return false;
|
|
867
|
+
}
|
|
868
|
+
return true;
|
|
961
869
|
}
|
|
962
870
|
/**
|
|
963
871
|
* @param signer
|
|
@@ -973,11 +881,8 @@ class Bee {
|
|
|
973
881
|
}
|
|
974
882
|
throw new error_1.BeeError('You have to pass Signer as property to either the method call or constructor! Non found.');
|
|
975
883
|
}
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
return this.ky;
|
|
979
|
-
}
|
|
980
|
-
return this.ky.extend(options);
|
|
884
|
+
getKyOptionsForCall(options) {
|
|
885
|
+
return (0, merge_1.deepMerge)(this.kyOptions, options);
|
|
981
886
|
}
|
|
982
887
|
}
|
|
983
888
|
exports.Bee = Bee;
|