@ethersphere/bee-js 3.3.2 → 3.3.3-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.
- package/dist/mjs/bee-debug.js +294 -189
- package/dist/mjs/bee.js +316 -237
- package/dist/mjs/chunk/signer.js +46 -12
- package/dist/mjs/chunk/soc.js +71 -31
- package/dist/mjs/chunk/span.js +1 -1
- package/dist/mjs/feed/index.js +86 -42
- package/dist/mjs/feed/json.js +46 -10
- package/dist/mjs/index.js +2 -1
- package/dist/mjs/modules/bytes.js +61 -24
- package/dist/mjs/modules/bzz.js +96 -58
- package/dist/mjs/modules/chunk.js +51 -16
- package/dist/mjs/modules/debug/balance.js +60 -20
- package/dist/mjs/modules/debug/chequebook.js +115 -67
- package/dist/mjs/modules/debug/chunk.js +47 -11
- package/dist/mjs/modules/debug/connectivity.js +76 -32
- package/dist/mjs/modules/debug/settlements.js +46 -10
- package/dist/mjs/modules/debug/stamps.js +91 -47
- package/dist/mjs/modules/debug/states.js +48 -12
- package/dist/mjs/modules/debug/status.js +97 -49
- package/dist/mjs/modules/debug/tag.js +39 -5
- package/dist/mjs/modules/debug/transactions.js +65 -25
- package/dist/mjs/modules/feed.js +50 -16
- package/dist/mjs/modules/pinning.js +67 -27
- package/dist/mjs/modules/pss.js +44 -10
- package/dist/mjs/modules/soc.js +47 -14
- package/dist/mjs/modules/status.js +37 -3
- package/dist/mjs/modules/stewardship.js +46 -10
- package/dist/mjs/modules/tag.js +73 -31
- package/dist/mjs/utils/collection.browser.js +41 -4
- package/dist/mjs/utils/collection.js +45 -11
- package/dist/mjs/utils/collection.node.js +137 -42
- package/dist/mjs/utils/data.browser.js +88 -52
- package/dist/mjs/utils/data.js +57 -21
- package/dist/mjs/utils/error.js +0 -9
- package/dist/mjs/utils/eth.js +68 -32
- package/dist/mjs/utils/file.js +42 -8
- package/dist/mjs/utils/headers.js +4 -4
- package/dist/mjs/utils/http.js +110 -64
- package/dist/mjs/utils/merge.js +2 -2
- package/dist/mjs/utils/stream.js +0 -4
- package/dist/mjs/utils/type.js +6 -6
- package/package.json +2 -2
package/dist/mjs/bee.js
CHANGED
|
@@ -1,3 +1,35 @@
|
|
|
1
|
+
var __awaiter = this && this.__awaiter || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) {
|
|
3
|
+
return value instanceof P ? value : new P(function (resolve) {
|
|
4
|
+
resolve(value);
|
|
5
|
+
});
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function rejected(value) {
|
|
18
|
+
try {
|
|
19
|
+
step(generator["throw"](value));
|
|
20
|
+
} catch (e) {
|
|
21
|
+
reject(e);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function step(result) {
|
|
26
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
30
|
+
});
|
|
31
|
+
};
|
|
32
|
+
|
|
1
33
|
import * as bzz from "./modules/bzz.js";
|
|
2
34
|
import * as stewardship from "./modules/stewardship.js";
|
|
3
35
|
import * as tag from "./modules/tag.js";
|
|
@@ -33,57 +65,43 @@ import { isReadable } from "./utils/stream.js";
|
|
|
33
65
|
*/
|
|
34
66
|
|
|
35
67
|
export class Bee {
|
|
36
|
-
/**
|
|
37
|
-
* URL on which is the main API of Bee node exposed
|
|
38
|
-
*/
|
|
39
|
-
url;
|
|
40
|
-
/**
|
|
41
|
-
* Default Signer object used for signing operations, mainly Feeds.
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
signer;
|
|
45
|
-
/**
|
|
46
|
-
* Ky instance that defines connection to Bee node
|
|
47
|
-
* @private
|
|
48
|
-
*/
|
|
49
|
-
|
|
50
|
-
ky;
|
|
51
68
|
/**
|
|
52
69
|
* @param url URL on which is the main API of Bee node exposed
|
|
53
70
|
* @param options
|
|
54
71
|
*/
|
|
55
|
-
|
|
56
72
|
constructor(url, options) {
|
|
73
|
+
var _a;
|
|
74
|
+
|
|
57
75
|
assertBeeUrl(url); // Remove last slash if present, as our endpoint strings starts with `/...`
|
|
58
76
|
// which could lead to double slash in URL to which Bee responds with
|
|
59
77
|
// unnecessary redirects.
|
|
60
78
|
|
|
61
79
|
this.url = stripLastSlash(url);
|
|
62
80
|
|
|
63
|
-
if (options
|
|
81
|
+
if (options === null || options === void 0 ? void 0 : options.signer) {
|
|
64
82
|
this.signer = makeSigner(options.signer);
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
const kyOptions = {
|
|
68
86
|
prefixUrl: this.url,
|
|
69
|
-
timeout: options
|
|
70
|
-
retry: options
|
|
71
|
-
fetch: options
|
|
87
|
+
timeout: (_a = options === null || options === void 0 ? void 0 : options.timeout) !== null && _a !== void 0 ? _a : false,
|
|
88
|
+
retry: options === null || options === void 0 ? void 0 : options.retry,
|
|
89
|
+
fetch: options === null || options === void 0 ? void 0 : options.fetch,
|
|
72
90
|
hooks: {
|
|
73
91
|
beforeRequest: [],
|
|
74
92
|
afterResponse: []
|
|
75
93
|
}
|
|
76
94
|
};
|
|
77
95
|
|
|
78
|
-
if (options
|
|
96
|
+
if (options === null || options === void 0 ? void 0 : options.defaultHeaders) {
|
|
79
97
|
kyOptions.headers = options.defaultHeaders;
|
|
80
98
|
}
|
|
81
99
|
|
|
82
|
-
if (options
|
|
100
|
+
if (options === null || options === void 0 ? void 0 : options.onRequest) {
|
|
83
101
|
kyOptions.hooks.beforeRequest.push(wrapRequestClosure(options.onRequest));
|
|
84
102
|
}
|
|
85
103
|
|
|
86
|
-
if (options
|
|
104
|
+
if (options === null || options === void 0 ? void 0 : options.onResponse) {
|
|
87
105
|
kyOptions.hooks.afterResponse.push(wrapResponseClosure(options.onResponse));
|
|
88
106
|
}
|
|
89
107
|
|
|
@@ -102,11 +120,13 @@ export class Bee {
|
|
|
102
120
|
*/
|
|
103
121
|
|
|
104
122
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
123
|
+
uploadData(postageBatchId, data, options) {
|
|
124
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
125
|
+
assertBatchId(postageBatchId);
|
|
126
|
+
assertData(data);
|
|
127
|
+
if (options) assertUploadOptions(options);
|
|
128
|
+
return bytes.upload(this.getKy(options), data, postageBatchId, options);
|
|
129
|
+
});
|
|
110
130
|
}
|
|
111
131
|
/**
|
|
112
132
|
* Download data as a byte array
|
|
@@ -118,10 +138,12 @@ export class Bee {
|
|
|
118
138
|
*/
|
|
119
139
|
|
|
120
140
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
141
|
+
downloadData(reference, options) {
|
|
142
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
143
|
+
assertRequestOptions(options);
|
|
144
|
+
assertReference(reference);
|
|
145
|
+
return bytes.download(this.getKy(options), reference);
|
|
146
|
+
});
|
|
125
147
|
}
|
|
126
148
|
/**
|
|
127
149
|
* Download data as a Readable stream
|
|
@@ -133,10 +155,12 @@ export class Bee {
|
|
|
133
155
|
*/
|
|
134
156
|
|
|
135
157
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
158
|
+
downloadReadableData(reference, options) {
|
|
159
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
160
|
+
assertRequestOptions(options);
|
|
161
|
+
assertReference(reference);
|
|
162
|
+
return bytes.downloadReadable(this.getKy(options), reference);
|
|
163
|
+
});
|
|
140
164
|
}
|
|
141
165
|
/**
|
|
142
166
|
* Upload chunk to a Bee node
|
|
@@ -151,23 +175,25 @@ export class Bee {
|
|
|
151
175
|
*/
|
|
152
176
|
|
|
153
177
|
|
|
154
|
-
|
|
155
|
-
|
|
178
|
+
uploadChunk(postageBatchId, data, options) {
|
|
179
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
180
|
+
assertBatchId(postageBatchId);
|
|
156
181
|
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
182
|
+
if (!(data instanceof Uint8Array)) {
|
|
183
|
+
throw new TypeError('Data has to be Uint8Array instance!');
|
|
184
|
+
}
|
|
160
185
|
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
186
|
+
if (data.length < SPAN_SIZE) {
|
|
187
|
+
throw new BeeArgumentError(`Chunk has to have size of at least ${SPAN_SIZE}.`, data);
|
|
188
|
+
}
|
|
164
189
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
190
|
+
if (data.length > CHUNK_SIZE + SPAN_SIZE) {
|
|
191
|
+
throw new BeeArgumentError(`Chunk has to have size of at most ${CHUNK_SIZE}.`, data);
|
|
192
|
+
}
|
|
168
193
|
|
|
169
|
-
|
|
170
|
-
|
|
194
|
+
if (options) assertUploadOptions(options);
|
|
195
|
+
return chunk.upload(this.getKy(options), data, postageBatchId, options);
|
|
196
|
+
});
|
|
171
197
|
}
|
|
172
198
|
/**
|
|
173
199
|
* Download chunk as a byte array
|
|
@@ -179,10 +205,12 @@ export class Bee {
|
|
|
179
205
|
*/
|
|
180
206
|
|
|
181
207
|
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
208
|
+
downloadChunk(reference, options) {
|
|
209
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
210
|
+
assertRequestOptions(options);
|
|
211
|
+
assertReference(reference);
|
|
212
|
+
return chunk.download(this.getKy(options), reference);
|
|
213
|
+
});
|
|
186
214
|
}
|
|
187
215
|
/**
|
|
188
216
|
* Upload single file to a Bee node.
|
|
@@ -202,32 +230,33 @@ export class Bee {
|
|
|
202
230
|
*/
|
|
203
231
|
|
|
204
232
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
233
|
+
uploadFile(postageBatchId, data, name, options) {
|
|
234
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
235
|
+
assertBatchId(postageBatchId);
|
|
236
|
+
assertFileData(data);
|
|
237
|
+
if (options) assertFileUploadOptions(options);
|
|
209
238
|
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
239
|
+
if (name && typeof name !== 'string') {
|
|
240
|
+
throw new TypeError('name has to be string or undefined!');
|
|
241
|
+
}
|
|
213
242
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
}
|
|
243
|
+
if (isFile(data)) {
|
|
244
|
+
const fileData = yield fileArrayBuffer(data);
|
|
245
|
+
const fileName = name !== null && name !== void 0 ? name : data.name;
|
|
246
|
+
const contentType = data.type;
|
|
247
|
+
const fileOptions = Object.assign({
|
|
248
|
+
contentType
|
|
249
|
+
}, options);
|
|
250
|
+
return bzz.uploadFile(this.getKy(options), fileData, postageBatchId, fileName, fileOptions);
|
|
251
|
+
} else if (isReadable(data) && (options === null || options === void 0 ? void 0 : options.tag) && !options.size) {
|
|
252
|
+
// TODO: Needed until https://github.com/ethersphere/bee/issues/2317 is resolved
|
|
253
|
+
const result = yield bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
|
|
254
|
+
yield this.updateTag(options.tag, result.reference);
|
|
255
|
+
return result;
|
|
256
|
+
} else {
|
|
257
|
+
return bzz.uploadFile(this.getKy(options), data, postageBatchId, name, options);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
231
260
|
}
|
|
232
261
|
/**
|
|
233
262
|
* Download single file.
|
|
@@ -242,10 +271,12 @@ export class Bee {
|
|
|
242
271
|
*/
|
|
243
272
|
|
|
244
273
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
274
|
+
downloadFile(reference, path = '', options) {
|
|
275
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
276
|
+
assertRequestOptions(options);
|
|
277
|
+
assertReference(reference);
|
|
278
|
+
return bzz.downloadFile(this.getKy(options), reference, path);
|
|
279
|
+
});
|
|
249
280
|
}
|
|
250
281
|
/**
|
|
251
282
|
* Download single file as a readable stream
|
|
@@ -259,10 +290,12 @@ export class Bee {
|
|
|
259
290
|
*/
|
|
260
291
|
|
|
261
292
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
293
|
+
downloadReadableFile(reference, path = '', options) {
|
|
294
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
+
assertRequestOptions(options);
|
|
296
|
+
assertReference(reference);
|
|
297
|
+
return bzz.downloadFileReadable(this.getKy(options), reference, path);
|
|
298
|
+
});
|
|
266
299
|
}
|
|
267
300
|
/**
|
|
268
301
|
* Upload collection of files to a Bee node
|
|
@@ -282,11 +315,13 @@ export class Bee {
|
|
|
282
315
|
*/
|
|
283
316
|
|
|
284
317
|
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
318
|
+
uploadFiles(postageBatchId, fileList, options) {
|
|
319
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
320
|
+
assertBatchId(postageBatchId);
|
|
321
|
+
if (options) assertCollectionUploadOptions(options);
|
|
322
|
+
const data = yield makeCollectionFromFileList(fileList);
|
|
323
|
+
return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
|
|
324
|
+
});
|
|
290
325
|
}
|
|
291
326
|
/**
|
|
292
327
|
* Upload Collection that you can assembly yourself.
|
|
@@ -300,11 +335,13 @@ export class Bee {
|
|
|
300
335
|
*/
|
|
301
336
|
|
|
302
337
|
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
338
|
+
uploadCollection(postageBatchId, collection, options) {
|
|
339
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
340
|
+
assertBatchId(postageBatchId);
|
|
341
|
+
assertCollection(collection);
|
|
342
|
+
if (options) assertCollectionUploadOptions(options);
|
|
343
|
+
return bzz.uploadCollection(this.ky, collection, postageBatchId, options);
|
|
344
|
+
});
|
|
308
345
|
}
|
|
309
346
|
/**
|
|
310
347
|
* Upload collection of files.
|
|
@@ -324,11 +361,13 @@ export class Bee {
|
|
|
324
361
|
*/
|
|
325
362
|
|
|
326
363
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
364
|
+
uploadFilesFromDirectory(postageBatchId, dir, options) {
|
|
365
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
366
|
+
assertBatchId(postageBatchId);
|
|
367
|
+
if (options) assertCollectionUploadOptions(options);
|
|
368
|
+
const data = yield makeCollectionFromFS(dir);
|
|
369
|
+
return bzz.uploadCollection(this.getKy(options), data, postageBatchId, options);
|
|
370
|
+
});
|
|
332
371
|
}
|
|
333
372
|
/**
|
|
334
373
|
* Create a new Tag which is meant for tracking progres of syncing data across network.
|
|
@@ -341,9 +380,11 @@ export class Bee {
|
|
|
341
380
|
*/
|
|
342
381
|
|
|
343
382
|
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
383
|
+
createTag(options) {
|
|
384
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
385
|
+
assertRequestOptions(options);
|
|
386
|
+
return tag.createTag(this.getKy(options));
|
|
387
|
+
});
|
|
347
388
|
}
|
|
348
389
|
/**
|
|
349
390
|
* Fetches all tags.
|
|
@@ -361,10 +402,12 @@ export class Bee {
|
|
|
361
402
|
*/
|
|
362
403
|
|
|
363
404
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
405
|
+
getAllTags(options) {
|
|
406
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
407
|
+
assertRequestOptions(options);
|
|
408
|
+
assertAllTagsOptions(options);
|
|
409
|
+
return tag.getAllTags(this.getKy(options), options === null || options === void 0 ? void 0 : options.offset, options === null || options === void 0 ? void 0 : options.limit);
|
|
410
|
+
});
|
|
368
411
|
}
|
|
369
412
|
/**
|
|
370
413
|
* Retrieve tag information from Bee node
|
|
@@ -381,10 +424,12 @@ export class Bee {
|
|
|
381
424
|
*/
|
|
382
425
|
|
|
383
426
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
427
|
+
retrieveTag(tagUid, options) {
|
|
428
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
429
|
+
assertRequestOptions(options);
|
|
430
|
+
tagUid = makeTagUid(tagUid);
|
|
431
|
+
return tag.retrieveTag(this.getKy(options), tagUid);
|
|
432
|
+
});
|
|
388
433
|
}
|
|
389
434
|
/**
|
|
390
435
|
* Delete Tag
|
|
@@ -401,10 +446,12 @@ export class Bee {
|
|
|
401
446
|
*/
|
|
402
447
|
|
|
403
448
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
449
|
+
deleteTag(tagUid, options) {
|
|
450
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
451
|
+
assertRequestOptions(options);
|
|
452
|
+
tagUid = makeTagUid(tagUid);
|
|
453
|
+
return tag.deleteTag(this.getKy(options), tagUid);
|
|
454
|
+
});
|
|
408
455
|
}
|
|
409
456
|
/**
|
|
410
457
|
* Update tag's total chunks count.
|
|
@@ -425,11 +472,13 @@ export class Bee {
|
|
|
425
472
|
*/
|
|
426
473
|
|
|
427
474
|
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
475
|
+
updateTag(tagUid, reference, options) {
|
|
476
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
477
|
+
assertReference(reference);
|
|
478
|
+
assertRequestOptions(options);
|
|
479
|
+
tagUid = makeTagUid(tagUid);
|
|
480
|
+
return tag.updateTag(this.getKy(options), tagUid, reference);
|
|
481
|
+
});
|
|
433
482
|
}
|
|
434
483
|
/**
|
|
435
484
|
* Pin local data with given reference
|
|
@@ -444,10 +493,12 @@ export class Bee {
|
|
|
444
493
|
*/
|
|
445
494
|
|
|
446
495
|
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
496
|
+
pin(reference, options) {
|
|
497
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
498
|
+
assertRequestOptions(options);
|
|
499
|
+
assertReference(reference);
|
|
500
|
+
return pinning.pin(this.getKy(options), reference);
|
|
501
|
+
});
|
|
451
502
|
}
|
|
452
503
|
/**
|
|
453
504
|
* Unpin local data with given reference
|
|
@@ -462,10 +513,12 @@ export class Bee {
|
|
|
462
513
|
*/
|
|
463
514
|
|
|
464
515
|
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
516
|
+
unpin(reference, options) {
|
|
517
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
518
|
+
assertRequestOptions(options);
|
|
519
|
+
assertReference(reference);
|
|
520
|
+
return pinning.unpin(this.getKy(options), reference);
|
|
521
|
+
});
|
|
469
522
|
}
|
|
470
523
|
/**
|
|
471
524
|
* Get list of all locally pinned references
|
|
@@ -477,9 +530,11 @@ export class Bee {
|
|
|
477
530
|
*/
|
|
478
531
|
|
|
479
532
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
533
|
+
getAllPins(options) {
|
|
534
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
535
|
+
assertRequestOptions(options);
|
|
536
|
+
return pinning.getAllPins(this.getKy(options));
|
|
537
|
+
});
|
|
483
538
|
}
|
|
484
539
|
/**
|
|
485
540
|
* Get pinning status of chunk with given reference
|
|
@@ -494,10 +549,12 @@ export class Bee {
|
|
|
494
549
|
*/
|
|
495
550
|
|
|
496
551
|
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
552
|
+
getPin(reference, options) {
|
|
553
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
554
|
+
assertRequestOptions(options);
|
|
555
|
+
assertReference(reference);
|
|
556
|
+
return pinning.getPin(this.getKy(options), reference);
|
|
557
|
+
});
|
|
501
558
|
}
|
|
502
559
|
/**
|
|
503
560
|
* Instructs the Bee node to reupload a locally pinned data into the network.
|
|
@@ -511,10 +568,12 @@ export class Bee {
|
|
|
511
568
|
*/
|
|
512
569
|
|
|
513
570
|
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
571
|
+
reuploadPinnedData(reference, options) {
|
|
572
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
573
|
+
assertRequestOptions(options);
|
|
574
|
+
assertReference(reference);
|
|
575
|
+
yield stewardship.reupload(this.getKy(options), reference);
|
|
576
|
+
});
|
|
518
577
|
}
|
|
519
578
|
/**
|
|
520
579
|
* Checks if content specified by reference is retrievable from the network.
|
|
@@ -526,10 +585,12 @@ export class Bee {
|
|
|
526
585
|
*/
|
|
527
586
|
|
|
528
587
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
588
|
+
isReferenceRetrievable(reference, options) {
|
|
589
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
590
|
+
assertRequestOptions(options);
|
|
591
|
+
assertReference(reference);
|
|
592
|
+
return stewardship.isRetrievable(this.getKy(options), reference);
|
|
593
|
+
});
|
|
533
594
|
}
|
|
534
595
|
/**
|
|
535
596
|
* Send data to recipient or target with Postal Service for Swarm.
|
|
@@ -557,22 +618,24 @@ export class Bee {
|
|
|
557
618
|
*/
|
|
558
619
|
|
|
559
620
|
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
621
|
+
pssSend(postageBatchId, topic, target, data, recipient, options) {
|
|
622
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
623
|
+
assertRequestOptions(options);
|
|
624
|
+
assertData(data);
|
|
625
|
+
assertBatchId(postageBatchId);
|
|
626
|
+
assertAddressPrefix(target);
|
|
565
627
|
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
628
|
+
if (typeof topic !== 'string') {
|
|
629
|
+
throw new TypeError('topic has to be an string!');
|
|
630
|
+
}
|
|
569
631
|
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
632
|
+
if (recipient) {
|
|
633
|
+
assertPublicKey(recipient);
|
|
634
|
+
return pss.send(this.getKy(options), topic, target, data, postageBatchId, recipient);
|
|
635
|
+
} else {
|
|
636
|
+
return pss.send(this.getKy(options), topic, target, data, postageBatchId);
|
|
637
|
+
}
|
|
638
|
+
});
|
|
576
639
|
}
|
|
577
640
|
/**
|
|
578
641
|
* Subscribe to messages for given topic with Postal Service for Swarm
|
|
@@ -617,13 +680,13 @@ export class Bee {
|
|
|
617
680
|
cancel
|
|
618
681
|
};
|
|
619
682
|
|
|
620
|
-
ws.onmessage =
|
|
621
|
-
const data =
|
|
683
|
+
ws.onmessage = ev => __awaiter(this, void 0, void 0, function* () {
|
|
684
|
+
const data = yield prepareWebsocketData(ev.data); // ignore empty messages
|
|
622
685
|
|
|
623
686
|
if (data.length > 0) {
|
|
624
687
|
handler.onMessage(wrapBytesWithHelpers(data), subscription);
|
|
625
688
|
}
|
|
626
|
-
};
|
|
689
|
+
});
|
|
627
690
|
|
|
628
691
|
ws.onerror = ev => {
|
|
629
692
|
// ignore errors after subscription was cancelled
|
|
@@ -662,38 +725,40 @@ export class Bee {
|
|
|
662
725
|
*/
|
|
663
726
|
|
|
664
727
|
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
728
|
+
pssReceive(topic, timeoutMsec = 0) {
|
|
729
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
730
|
+
if (typeof topic !== 'string') {
|
|
731
|
+
throw new TypeError('topic has to be an string!');
|
|
732
|
+
}
|
|
669
733
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
734
|
+
if (typeof timeoutMsec !== 'number') {
|
|
735
|
+
throw new TypeError('timeoutMsc parameter has to be a number!');
|
|
736
|
+
}
|
|
673
737
|
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
738
|
+
return new Promise((resolve, reject) => {
|
|
739
|
+
let timeout;
|
|
740
|
+
const subscription = this.pssSubscribe(topic, {
|
|
741
|
+
onError: error => {
|
|
742
|
+
clearTimeout(timeout);
|
|
743
|
+
subscription.cancel();
|
|
744
|
+
reject(error.message);
|
|
745
|
+
},
|
|
746
|
+
onMessage: message => {
|
|
747
|
+
clearTimeout(timeout);
|
|
748
|
+
subscription.cancel();
|
|
749
|
+
resolve(message);
|
|
750
|
+
}
|
|
751
|
+
});
|
|
752
|
+
|
|
753
|
+
if (timeoutMsec > 0) {
|
|
754
|
+
// we need to cast the type because Typescript is getting confused with Node.js'
|
|
755
|
+
// alternative type definitions
|
|
756
|
+
timeout = setTimeout(() => {
|
|
757
|
+
subscription.cancel();
|
|
758
|
+
reject(new BeeError('pssReceive timeout'));
|
|
759
|
+
}, timeoutMsec);
|
|
686
760
|
}
|
|
687
761
|
});
|
|
688
|
-
|
|
689
|
-
if (timeoutMsec > 0) {
|
|
690
|
-
// we need to cast the type because Typescript is getting confused with Node.js'
|
|
691
|
-
// alternative type definitions
|
|
692
|
-
timeout = setTimeout(() => {
|
|
693
|
-
subscription.cancel();
|
|
694
|
-
reject(new BeeError('pssReceive timeout'));
|
|
695
|
-
}, timeoutMsec);
|
|
696
|
-
}
|
|
697
762
|
});
|
|
698
763
|
}
|
|
699
764
|
/**
|
|
@@ -712,14 +777,16 @@ export class Bee {
|
|
|
712
777
|
*/
|
|
713
778
|
|
|
714
779
|
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
780
|
+
createFeedManifest(postageBatchId, type, topic, owner, options) {
|
|
781
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
782
|
+
assertRequestOptions(options);
|
|
783
|
+
assertFeedType(type);
|
|
784
|
+
assertBatchId(postageBatchId);
|
|
785
|
+
const canonicalTopic = makeTopic(topic);
|
|
786
|
+
const canonicalOwner = makeHexEthAddress(owner);
|
|
787
|
+
return createFeedManifest(this.getKy(options), canonicalOwner, canonicalTopic, postageBatchId, {
|
|
788
|
+
type
|
|
789
|
+
});
|
|
723
790
|
});
|
|
724
791
|
}
|
|
725
792
|
/**
|
|
@@ -780,13 +847,17 @@ export class Bee {
|
|
|
780
847
|
*/
|
|
781
848
|
|
|
782
849
|
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
850
|
+
setJsonFeed(postageBatchId, topic, data, options) {
|
|
851
|
+
var _a;
|
|
852
|
+
|
|
853
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
854
|
+
assertRequestOptions(options, 'JsonFeedOptions');
|
|
855
|
+
assertBatchId(postageBatchId);
|
|
856
|
+
const hashedTopic = this.makeFeedTopic(topic);
|
|
857
|
+
const feedType = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : DEFAULT_FEED_TYPE;
|
|
858
|
+
const writer = this.makeFeedWriter(feedType, hashedTopic, options === null || options === void 0 ? void 0 : options.signer, options);
|
|
859
|
+
return setJsonData(this, writer, postageBatchId, data, options);
|
|
860
|
+
});
|
|
790
861
|
}
|
|
791
862
|
/**
|
|
792
863
|
* High-level function that allows you to easily get data from feed.
|
|
@@ -809,33 +880,37 @@ export class Bee {
|
|
|
809
880
|
*/
|
|
810
881
|
|
|
811
882
|
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
const hashedTopic = this.makeFeedTopic(topic);
|
|
815
|
-
const feedType = options?.type ?? DEFAULT_FEED_TYPE;
|
|
883
|
+
getJsonFeed(topic, options) {
|
|
884
|
+
var _a;
|
|
816
885
|
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
886
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
887
|
+
assertRequestOptions(options, 'JsonFeedOptions');
|
|
888
|
+
const hashedTopic = this.makeFeedTopic(topic);
|
|
889
|
+
const feedType = (_a = options === null || options === void 0 ? void 0 : options.type) !== null && _a !== void 0 ? _a : DEFAULT_FEED_TYPE;
|
|
820
890
|
|
|
821
|
-
|
|
891
|
+
if ((options === null || options === void 0 ? void 0 : options.signer) && (options === null || options === void 0 ? void 0 : options.address)) {
|
|
892
|
+
throw new BeeError('Both options "signer" and "address" can not be specified at one time!');
|
|
893
|
+
}
|
|
822
894
|
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
895
|
+
let address;
|
|
896
|
+
|
|
897
|
+
if (options === null || options === void 0 ? void 0 : options.address) {
|
|
898
|
+
address = makeEthAddress(options === null || options === void 0 ? void 0 : options.address);
|
|
899
|
+
} else {
|
|
900
|
+
try {
|
|
901
|
+
address = this.resolveSigner(options === null || options === void 0 ? void 0 : options.signer).address;
|
|
902
|
+
} catch (e) {
|
|
903
|
+
if (e instanceof BeeError) {
|
|
904
|
+
throw new BeeError('Either address, signer or default signer has to be specified!');
|
|
905
|
+
} else {
|
|
906
|
+
throw e;
|
|
907
|
+
}
|
|
833
908
|
}
|
|
834
909
|
}
|
|
835
|
-
}
|
|
836
910
|
|
|
837
|
-
|
|
838
|
-
|
|
911
|
+
const reader = this.makeFeedReader(feedType, hashedTopic, address, options);
|
|
912
|
+
return getJsonData(this, reader);
|
|
913
|
+
});
|
|
839
914
|
}
|
|
840
915
|
/**
|
|
841
916
|
* Make a new feed topic from a string
|
|
@@ -879,9 +954,9 @@ export class Bee {
|
|
|
879
954
|
makeSOCWriter(signer, options) {
|
|
880
955
|
assertRequestOptions(options);
|
|
881
956
|
const canonicalSigner = this.resolveSigner(signer);
|
|
882
|
-
return {
|
|
957
|
+
return Object.assign(Object.assign({}, this.makeSOCReader(canonicalSigner.address, options)), {
|
|
883
958
|
upload: uploadSingleOwnerChunkData.bind(null, this.getKy(options), canonicalSigner)
|
|
884
|
-
};
|
|
959
|
+
});
|
|
885
960
|
}
|
|
886
961
|
/**
|
|
887
962
|
* Ping the Bee node to see if there is a live Bee node on the given URL.
|
|
@@ -891,9 +966,11 @@ export class Bee {
|
|
|
891
966
|
*/
|
|
892
967
|
|
|
893
968
|
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
969
|
+
checkConnection(options) {
|
|
970
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
971
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
972
|
+
return status.checkConnection(this.getKy(options));
|
|
973
|
+
});
|
|
897
974
|
}
|
|
898
975
|
/**
|
|
899
976
|
* Ping the Bee node to see if there is a live Bee node on the given URL.
|
|
@@ -903,16 +980,18 @@ export class Bee {
|
|
|
903
980
|
*/
|
|
904
981
|
|
|
905
982
|
|
|
906
|
-
|
|
907
|
-
|
|
983
|
+
isConnected(options) {
|
|
984
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
985
|
+
assertRequestOptions(options, 'PostageBatchOptions');
|
|
908
986
|
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
987
|
+
try {
|
|
988
|
+
yield status.checkConnection(this.getKy(options));
|
|
989
|
+
} catch (e) {
|
|
990
|
+
return false;
|
|
991
|
+
}
|
|
914
992
|
|
|
915
|
-
|
|
993
|
+
return true;
|
|
994
|
+
});
|
|
916
995
|
}
|
|
917
996
|
/**
|
|
918
997
|
* @param signer
|