@upcoming/bee-js 0.6.0 → 0.7.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/cjs/bee.js +10 -12
- 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/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/cjs/bee.js
CHANGED
|
@@ -58,6 +58,7 @@ const collection_node_1 = require("./utils/collection.node");
|
|
|
58
58
|
const data_1 = require("./utils/data");
|
|
59
59
|
const error_1 = require("./utils/error");
|
|
60
60
|
const file_1 = require("./utils/file");
|
|
61
|
+
const resource_locator_1 = require("./utils/resource-locator");
|
|
61
62
|
const tokens_1 = require("./utils/tokens");
|
|
62
63
|
const type_1 = require("./utils/type");
|
|
63
64
|
const typed_bytes_1 = require("./utils/typed-bytes");
|
|
@@ -122,36 +123,34 @@ class Bee {
|
|
|
122
123
|
/**
|
|
123
124
|
* Download data as a byte array
|
|
124
125
|
*
|
|
125
|
-
* @param
|
|
126
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
126
127
|
* @param options Options that affects the request behavior
|
|
127
128
|
* @throws TypeError if some of the input parameters is not expected type
|
|
128
129
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
129
130
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
130
131
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
131
132
|
*/
|
|
132
|
-
async downloadData(
|
|
133
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
133
|
+
async downloadData(resource, options, requestOptions) {
|
|
134
134
|
if (options) {
|
|
135
135
|
options = (0, type_1.prepareDownloadOptions)(options);
|
|
136
136
|
}
|
|
137
|
-
return bytes.download(this.getRequestOptionsForCall(requestOptions),
|
|
137
|
+
return bytes.download(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), options);
|
|
138
138
|
}
|
|
139
139
|
/**
|
|
140
140
|
* Download data as a Readable stream
|
|
141
141
|
*
|
|
142
|
-
* @param
|
|
142
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
143
143
|
* @param options Options that affects the request behavior
|
|
144
144
|
* @throws TypeError if some of the input parameters is not expected type
|
|
145
145
|
* @throws BeeArgumentError if there is passed ENS domain with invalid unicode characters
|
|
146
146
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
147
147
|
* @see [Bee API reference - `GET /bytes`](https://docs.ethswarm.org/api/#tag/Bytes/paths/~1bytes~1{reference}/get)
|
|
148
148
|
*/
|
|
149
|
-
async downloadReadableData(
|
|
150
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
149
|
+
async downloadReadableData(resource, options, requestOptions) {
|
|
151
150
|
if (options) {
|
|
152
151
|
options = (0, type_1.prepareDownloadOptions)(options);
|
|
153
152
|
}
|
|
154
|
-
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions),
|
|
153
|
+
return bytes.downloadReadable(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), options);
|
|
155
154
|
}
|
|
156
155
|
/**
|
|
157
156
|
* Upload chunk to a Bee node
|
|
@@ -276,7 +275,7 @@ class Bee {
|
|
|
276
275
|
/**
|
|
277
276
|
* Download single file.
|
|
278
277
|
*
|
|
279
|
-
* @param
|
|
278
|
+
* @param resource Swarm reference, Swarm CID, or ENS domain
|
|
280
279
|
* @param path If reference points to manifest, then this parameter defines path to the file
|
|
281
280
|
* @param options Options that affects the request behavior
|
|
282
281
|
* @throws TypeError if some of the input parameters is not expected type
|
|
@@ -285,12 +284,11 @@ class Bee {
|
|
|
285
284
|
* @see [Bee docs - Upload and download](https://docs.ethswarm.org/docs/develop/access-the-swarm/upload-and-download)
|
|
286
285
|
* @see [Bee API reference - `GET /bzz`](https://docs.ethswarm.org/api/#tag/BZZ/paths/~1bzz~1%7Breference%7D~1%7Bpath%7D/get)
|
|
287
286
|
*/
|
|
288
|
-
async downloadFile(
|
|
289
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
287
|
+
async downloadFile(resource, path = '', options, requestOptions) {
|
|
290
288
|
if (options) {
|
|
291
289
|
options = (0, type_1.prepareDownloadOptions)(options);
|
|
292
290
|
}
|
|
293
|
-
return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions),
|
|
291
|
+
return bzz.downloadFile(this.getRequestOptionsForCall(requestOptions), new resource_locator_1.ResourceLocator(resource), path, options);
|
|
294
292
|
}
|
|
295
293
|
/**
|
|
296
294
|
* Download single file as a readable stream
|
|
@@ -61,14 +61,13 @@ exports.head = head;
|
|
|
61
61
|
* @param requestOptions Options for making requests
|
|
62
62
|
* @param hash Bee content reference
|
|
63
63
|
*/
|
|
64
|
-
async function download(requestOptions,
|
|
65
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
64
|
+
async function download(requestOptions, resource, options) {
|
|
66
65
|
if (options) {
|
|
67
66
|
options = (0, type_1.prepareDownloadOptions)(options);
|
|
68
67
|
}
|
|
69
68
|
const response = await (0, http_1.http)(requestOptions, {
|
|
70
69
|
responseType: 'arraybuffer',
|
|
71
|
-
url: `${endpoint}/${
|
|
70
|
+
url: `${endpoint}/${resource}`,
|
|
72
71
|
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
73
72
|
});
|
|
74
73
|
return new bytes_1.Bytes(response.data);
|
|
@@ -80,14 +79,13 @@ exports.download = download;
|
|
|
80
79
|
* @param requestOptions Options for making requests
|
|
81
80
|
* @param hash Bee content reference
|
|
82
81
|
*/
|
|
83
|
-
async function downloadReadable(requestOptions,
|
|
84
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
82
|
+
async function downloadReadable(requestOptions, resource, options) {
|
|
85
83
|
if (options) {
|
|
86
84
|
options = (0, type_1.prepareDownloadOptions)(options);
|
|
87
85
|
}
|
|
88
86
|
const response = await (0, http_1.http)(requestOptions, {
|
|
89
87
|
responseType: 'stream',
|
|
90
|
-
url: `${endpoint}/${
|
|
88
|
+
url: `${endpoint}/${resource}`,
|
|
91
89
|
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
92
90
|
});
|
|
93
91
|
return response.data;
|
package/dist/cjs/modules/bzz.js
CHANGED
|
@@ -51,12 +51,11 @@ exports.uploadFile = uploadFile;
|
|
|
51
51
|
* @param hash Bee file or collection hash
|
|
52
52
|
* @param path If hash is collection then this defines path to a single file in the collection
|
|
53
53
|
*/
|
|
54
|
-
async function downloadFile(requestOptions,
|
|
55
|
-
reference = new typed_bytes_1.Reference(reference);
|
|
54
|
+
async function downloadFile(requestOptions, resource, path = '', options) {
|
|
56
55
|
const response = await (0, http_1.http)(requestOptions, {
|
|
57
56
|
method: 'GET',
|
|
58
57
|
responseType: 'arraybuffer',
|
|
59
|
-
url: `${bzzEndpoint}/${
|
|
58
|
+
url: `${bzzEndpoint}/${resource}/${path}`,
|
|
60
59
|
headers: (0, headers_1.prepareRequestHeaders)(null, options),
|
|
61
60
|
});
|
|
62
61
|
const file = {
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ResourceLocator = void 0;
|
|
4
|
+
const cafe_utility_1 = require("cafe-utility");
|
|
5
|
+
const typed_bytes_1 = require("./typed-bytes");
|
|
6
|
+
class ResourceLocator {
|
|
7
|
+
constructor(raw) {
|
|
8
|
+
this.raw = raw;
|
|
9
|
+
}
|
|
10
|
+
toString() {
|
|
11
|
+
if (cafe_utility_1.Types.isString(this.raw) && this.raw.includes('.eth')) {
|
|
12
|
+
return this.raw;
|
|
13
|
+
}
|
|
14
|
+
return new typed_bytes_1.Reference(this.raw).toHex();
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
exports.ResourceLocator = ResourceLocator;
|