@upcoming/bee-js 0.6.0 → 0.7.1
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/cjs/bee.js +10 -12
- package/dist/cjs/manifest/manifest.js +3 -0
- package/dist/cjs/modules/bytes.js +4 -6
- package/dist/cjs/modules/bzz.js +2 -3
- package/dist/cjs/utils/resource-locator.js +17 -0
- package/dist/index.browser.min.js +1 -1
- package/dist/index.browser.min.js.map +1 -1
- package/dist/mjs/bee.js +10 -12
- package/dist/mjs/manifest/manifest.js +3 -0
- package/dist/mjs/modules/bytes.js +4 -6
- package/dist/mjs/modules/bzz.js +2 -3
- package/dist/mjs/utils/resource-locator.js +13 -0
- package/dist/types/bee.d.ts +6 -6
- package/dist/types/modules/bytes.d.ts +3 -2
- package/dist/types/modules/bzz.d.ts +2 -1
- package/dist/types/utils/resource-locator.d.ts +6 -0
- package/package.json +1 -1
package/dist/mjs/bee.js
CHANGED
|
@@ -32,6 +32,7 @@ import { makeCollectionFromFS } from "./utils/collection.node.js";
|
|
|
32
32
|
import { prepareWebsocketData } from "./utils/data.js";
|
|
33
33
|
import { BeeArgumentError, BeeError } from "./utils/error.js";
|
|
34
34
|
import { fileArrayBuffer, isFile } from "./utils/file.js";
|
|
35
|
+
import { ResourceLocator } from "./utils/resource-locator.js";
|
|
35
36
|
import { BZZ } from "./utils/tokens.js";
|
|
36
37
|
import { asNumberString, assertData, assertFileData, makeTagUid, prepareAllTagsOptions, prepareBeeRequestOptions, prepareCollectionUploadOptions, prepareDownloadOptions, prepareFileUploadOptions, prepareGsocMessageHandler, preparePostageBatchOptions, preparePssMessageHandler, prepareRedundantUploadOptions, prepareTransactionOptions, prepareUploadOptions } from "./utils/type.js";
|
|
37
38
|
import { BatchId, EthAddress, Identifier, PeerAddress, PrivateKey, PublicKey, Reference, Span, Topic, TransactionId } from "./utils/typed-bytes.js";
|
|
@@ -96,36 +97,34 @@ export class Bee {
|
|
|
96
97
|
/**
|
|
97
98
|
* Download data as a byte array
|
|
98
99
|
*
|
|
99
|
-
* @param
|
|
100
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
100
101
|
* @param options Options that affects the request behavior
|
|
101
102
|
* @throws TypeError if some of the input parameters is not expected type
|
|
102
103
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
103
104
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
104
105
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
105
106
|
*/
|
|
106
|
-
async downloadData(
|
|
107
|
-
reference = new Reference(reference);
|
|
107
|
+
async downloadData(resource, options, requestOptions) {
|
|
108
108
|
if (options) {
|
|
109
109
|
options = prepareDownloadOptions(options);
|
|
110
110
|
}
|
|
111
|
-
return bytes.download(this.getRequestOptionsForCall(requestOptions),
|
|
111
|
+
return bytes.download(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
114
|
* Download data as a Readable stream
|
|
115
115
|
*
|
|
116
|
-
* @param
|
|
116
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
117
117
|
* @param options Options that affects the request behavior
|
|
118
118
|
* @throws TypeError if some of the input parameters is not expected type
|
|
119
119
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
120
120
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
121
121
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
122
122
|
*/
|
|
123
|
-
async downloadReadableData(
|
|
124
|
-
reference = new Reference(reference);
|
|
123
|
+
async downloadReadableData(resource, options, requestOptions) {
|
|
125
124
|
if (options) {
|
|
126
125
|
options = prepareDownloadOptions(options);
|
|
127
126
|
}
|
|
128
|
-
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions),
|
|
127
|
+
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), options);
|
|
129
128
|
}
|
|
130
129
|
/**
|
|
131
130
|
* Upload chunk to a Bee node
|
|
@@ -252,7 +251,7 @@ export class Bee {
|
|
|
252
251
|
/**
|
|
253
252
|
* Download single file.
|
|
254
253
|
*
|
|
255
|
-
* @param
|
|
254
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
256
255
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
257
256
|
* @param options Options that affects the request behavior
|
|
258
257
|
* @throws TypeError if some of the input parameters is not expected type
|
|
@@ -261,12 +260,11 @@ export class Bee {
|
|
|
261
260
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
262
261
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
263
262
|
*/
|
|
264
|
-
async downloadFile(
|
|
265
|
-
reference = new Reference(reference);
|
|
263
|
+
async downloadFile(resource, path = '', options, requestOptions) {
|
|
266
264
|
if (options) {
|
|
267
265
|
options = prepareDownloadOptions(options);
|
|
268
266
|
}
|
|
269
|
-
return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions),
|
|
267
|
+
return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions), new ResourceLocator(resource), path, options);
|
|
270
268
|
}
|
|
271
269
|
/**
|
|
272
270
|
* Download single file as a readable stream
|
|
@@ -140,6 +140,9 @@ export class MantarayNode {
|
|
|
140
140
|
}
|
|
141
141
|
const owner = node.metadata['swarm-feed-owner'];
|
|
142
142
|
const topic = node.metadata['swarm-feed-topic'];
|
|
143
|
+
if (!owner || !topic) {
|
|
144
|
+
return Optional.empty();
|
|
145
|
+
}
|
|
143
146
|
return Optional.of(await bee.fetchLatestFeedUpdate(topic, owner, requestOptions));
|
|
144
147
|
}
|
|
145
148
|
/**
|
|
@@ -56,14 +56,13 @@ export async function head(requestOptions, reference) {
|
|
|
56
56
|
* @param requestOptions Options for making requests
|
|
57
57
|
* @param hash Bee content reference
|
|
58
58
|
*/
|
|
59
|
-
export async function download(requestOptions,
|
|
60
|
-
reference = new Reference(reference);
|
|
59
|
+
export async function download(requestOptions, resource, options) {
|
|
61
60
|
if (options) {
|
|
62
61
|
options = prepareDownloadOptions(options);
|
|
63
62
|
}
|
|
64
63
|
const response = await http(requestOptions, {
|
|
65
64
|
responseType: 'arraybuffer',
|
|
66
|
-
url: `${endpoint}/${
|
|
65
|
+
url: `${endpoint}/${resource}`,
|
|
67
66
|
headers: prepareRequestHeaders(null, options)
|
|
68
67
|
});
|
|
69
68
|
return new Bytes(response.data);
|
|
@@ -74,14 +73,13 @@ export async function download(requestOptions, reference, options) {
|
|
|
74
73
|
* @param requestOptions Options for making requests
|
|
75
74
|
* @param hash Bee content reference
|
|
76
75
|
*/
|
|
77
|
-
export async function downloadReadable(requestOptions,
|
|
78
|
-
reference = new Reference(reference);
|
|
76
|
+
export async function downloadReadable(requestOptions, resource, options) {
|
|
79
77
|
if (options) {
|
|
80
78
|
options = prepareDownloadOptions(options);
|
|
81
79
|
}
|
|
82
80
|
const response = await http(requestOptions, {
|
|
83
81
|
responseType: 'stream',
|
|
84
|
-
url: `${endpoint}/${
|
|
82
|
+
url: `${endpoint}/${resource}`,
|
|
85
83
|
headers: prepareRequestHeaders(null, options)
|
|
86
84
|
});
|
|
87
85
|
return response.data;
|
package/dist/mjs/modules/bzz.js
CHANGED
|
@@ -49,12 +49,11 @@ export async function uploadFile(requestOptions, data, postageBatchId, name, opt
|
|
|
49
49
|
* @param hash Bee file or collection hash
|
|
50
50
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
51
51
|
*/
|
|
52
|
-
export async function downloadFile(requestOptions,
|
|
53
|
-
reference = new Reference(reference);
|
|
52
|
+
export async function downloadFile(requestOptions, resource, path = '', options) {
|
|
54
53
|
const response = await http(requestOptions, {
|
|
55
54
|
method: 'GET',
|
|
56
55
|
responseType: 'arraybuffer',
|
|
57
|
-
url: `${bzzEndpoint}/${
|
|
56
|
+
url: `${bzzEndpoint}/${resource}/${path}`,
|
|
58
57
|
headers: prepareRequestHeaders(null, options)
|
|
59
58
|
});
|
|
60
59
|
const file = {
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Types } from 'cafe-utility';
|
|
2
|
+
import { Reference } from "./typed-bytes.js";
|
|
3
|
+
export class ResourceLocator {
|
|
4
|
+
constructor(raw) {
|
|
5
|
+
this.raw = raw;
|
|
6
|
+
}
|
|
7
|
+
toString() {
|
|
8
|
+
if (Types.isString(this.raw) && this.raw.includes('.eth')) {
|
|
9
|
+
return this.raw;
|
|
10
|
+
}
|
|
11
|
+
return new Reference(this.raw).toHex();
|
|
12
|
+
}
|
|
13
|
+
}
|
package/dist/types/bee.d.ts
CHANGED
|
@@ -54,25 +54,25 @@ export declare class Bee {
|
|
|
54
54
|
/**
|
|
55
55
|
* Download data as a byte array
|
|
56
56
|
*
|
|
57
|
-
* @param
|
|
57
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
58
58
|
* @param options Options that affects the request behavior
|
|
59
59
|
* @throws TypeError if some of the input parameters is not expected type
|
|
60
60
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
61
61
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
62
62
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
63
63
|
*/
|
|
64
|
-
downloadData(
|
|
64
|
+
downloadData(resource: Reference | string | Uint8Array, options?: DownloadOptions, requestOptions?: BeeRequestOptions): Promise<Bytes>;
|
|
65
65
|
/**
|
|
66
66
|
* Download data as a Readable stream
|
|
67
67
|
*
|
|
68
|
-
* @param
|
|
68
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
69
69
|
* @param options Options that affects the request behavior
|
|
70
70
|
* @throws TypeError if some of the input parameters is not expected type
|
|
71
71
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
72
72
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
73
73
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
74
74
|
*/
|
|
75
|
-
downloadReadableData(
|
|
75
|
+
downloadReadableData(resource: Reference | Uint8Array | string, options?: DownloadOptions, requestOptions?: BeeRequestOptions): Promise<ReadableStream<Uint8Array>>;
|
|
76
76
|
/**
|
|
77
77
|
* Upload chunk to a Bee node
|
|
78
78
|
*
|
|
@@ -146,7 +146,7 @@ export declare class Bee {
|
|
|
146
146
|
/**
|
|
147
147
|
* Download single file.
|
|
148
148
|
*
|
|
149
|
-
* @param
|
|
149
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
150
150
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
151
151
|
* @param options Options that affects the request behavior
|
|
152
152
|
* @throws TypeError if some of the input parameters is not expected type
|
|
@@ -155,7 +155,7 @@ export declare class Bee {
|
|
|
155
155
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
156
156
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
157
157
|
*/
|
|
158
|
-
downloadFile(
|
|
158
|
+
downloadFile(resource: Reference | Uint8Array | string, path?: string, options?: DownloadOptions, requestOptions?: BeeRequestOptions): Promise<FileData<Bytes>>;
|
|
159
159
|
/**
|
|
160
160
|
* Download single file as a readable stream
|
|
161
161
|
*
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { BeeRequestOptions, DownloadOptions, RedundantUploadOptions, ReferenceInformation } from '../types';
|
|
2
2
|
import { UploadResult } from '../types';
|
|
3
3
|
import { Bytes } from '../utils/bytes';
|
|
4
|
+
import { ResourceLocator } from '../utils/resource-locator';
|
|
4
5
|
import { BatchId, Reference } from '../utils/typed-bytes';
|
|
5
6
|
/**
|
|
6
7
|
* Upload data to a Bee node
|
|
@@ -24,11 +25,11 @@ export declare function head(requestOptions: BeeRequestOptions, reference: Refer
|
|
|
24
25
|
* @param requestOptions Options for making requests
|
|
25
26
|
* @param hash Bee content reference
|
|
26
27
|
*/
|
|
27
|
-
export declare function download(requestOptions: BeeRequestOptions,
|
|
28
|
+
export declare function download(requestOptions: BeeRequestOptions, resource: ResourceLocator, options?: DownloadOptions): Promise<Bytes>;
|
|
28
29
|
/**
|
|
29
30
|
* Download data as a readable stream
|
|
30
31
|
*
|
|
31
32
|
* @param requestOptions Options for making requests
|
|
32
33
|
* @param hash Bee content reference
|
|
33
34
|
*/
|
|
34
|
-
export declare function downloadReadable(requestOptions: BeeRequestOptions,
|
|
35
|
+
export declare function downloadReadable(requestOptions: BeeRequestOptions, resource: ResourceLocator, options?: DownloadOptions): Promise<ReadableStream<Uint8Array>>;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import { Readable } from 'stream';
|
|
3
3
|
import { BeeRequestOptions, Collection, CollectionUploadOptions, DownloadOptions, FileData, FileUploadOptions, UploadResult } from '../types';
|
|
4
4
|
import { Bytes } from '../utils/bytes';
|
|
5
|
+
import { ResourceLocator } from '../utils/resource-locator';
|
|
5
6
|
import { BatchId, Reference } from '../utils/typed-bytes';
|
|
6
7
|
/**
|
|
7
8
|
* Upload single file
|
|
@@ -20,7 +21,7 @@ export declare function uploadFile(requestOptions: BeeRequestOptions, data: stri
|
|
|
20
21
|
* @param hash Bee file or collection hash
|
|
21
22
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
22
23
|
*/
|
|
23
|
-
export declare function downloadFile(requestOptions: BeeRequestOptions,
|
|
24
|
+
export declare function downloadFile(requestOptions: BeeRequestOptions, resource: ResourceLocator, path?: string, options?: DownloadOptions): Promise<FileData<Bytes>>;
|
|
24
25
|
/**
|
|
25
26
|
* Download single file as a readable stream
|
|
26
27
|
*
|