@ethersphere/bee-js 3.3.0 → 3.3.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/chunk/bmt.js +7 -2
- package/dist/cjs/chunk/signer.js +9 -4
- package/dist/cjs/modules/debug/status.js +5 -5
- package/dist/cjs/package.json +1 -0
- package/dist/cjs/types/ky-options.js +8 -0
- package/dist/cjs/types/ky-universal/common.js +8 -0
- package/dist/cjs/types/ky-universal/hooks.js +8 -0
- package/dist/cjs/types/ky-universal/retry.js +8 -0
- package/dist/cjs/utils/eth.js +8 -3
- package/dist/cjs/utils/hash.js +7 -2
- package/dist/cjs/utils/stream.js +14 -5
- package/dist/index.browser.min.js +3 -0
- package/dist/index.browser.min.js.LICENSE.txt +52 -0
- package/dist/index.browser.min.js.map +1 -0
- package/dist/mjs/bee-debug.js +608 -508
- package/dist/mjs/bee.js +935 -836
- package/dist/mjs/chunk/bmt.js +34 -24
- package/dist/mjs/chunk/cac.js +24 -22
- package/dist/mjs/chunk/serialize.js +9 -9
- package/dist/mjs/chunk/signer.js +92 -73
- package/dist/mjs/chunk/soc.js +78 -66
- package/dist/mjs/chunk/span.js +19 -16
- package/dist/mjs/feed/index.js +110 -101
- package/dist/mjs/feed/json.js +21 -17
- package/dist/mjs/feed/topic.js +18 -17
- package/dist/mjs/feed/type.js +5 -5
- package/dist/mjs/index.js +7 -7
- package/dist/mjs/modules/bytes.js +33 -30
- package/dist/mjs/modules/bzz.js +80 -77
- package/dist/mjs/modules/chunk.js +22 -20
- package/dist/mjs/modules/debug/balance.js +26 -22
- package/dist/mjs/modules/debug/chequebook.js +84 -65
- package/dist/mjs/modules/debug/chunk.js +15 -13
- package/dist/mjs/modules/debug/connectivity.js +34 -34
- package/dist/mjs/modules/debug/settlements.js +14 -12
- package/dist/mjs/modules/debug/stamps.js +52 -47
- package/dist/mjs/modules/debug/states.js +16 -14
- package/dist/mjs/modules/debug/status.js +55 -35
- package/dist/mjs/modules/debug/tag.js +8 -7
- package/dist/mjs/modules/debug/transactions.js +31 -25
- package/dist/mjs/modules/feed.js +39 -33
- package/dist/mjs/modules/pinning.js +34 -28
- package/dist/mjs/modules/pss.js +18 -14
- package/dist/mjs/modules/soc.js +18 -15
- package/dist/mjs/modules/status.js +6 -5
- package/dist/mjs/modules/stewardship.js +13 -12
- package/dist/mjs/modules/tag.js +38 -30
- package/dist/mjs/package.json +1 -0
- package/dist/mjs/types/debug.js +5 -4
- package/dist/mjs/types/index.js +6 -2
- package/dist/mjs/types/ky-options.js +7 -0
- package/dist/mjs/types/ky-universal/common.js +7 -0
- package/dist/mjs/types/ky-universal/hooks.js +7 -0
- package/dist/mjs/types/ky-universal/retry.js +7 -0
- package/dist/mjs/utils/bytes.js +32 -26
- package/dist/mjs/utils/collection.browser.js +4 -3
- package/dist/mjs/utils/collection.js +47 -35
- package/dist/mjs/utils/collection.node.js +53 -42
- package/dist/mjs/utils/data.browser.js +64 -48
- package/dist/mjs/utils/data.js +29 -25
- package/dist/mjs/utils/error.js +47 -39
- package/dist/mjs/utils/eth.js +119 -104
- package/dist/mjs/utils/expose.js +9 -9
- package/dist/mjs/utils/file.js +22 -19
- package/dist/mjs/utils/hash.js +10 -5
- package/dist/mjs/utils/headers.js +43 -39
- package/dist/mjs/utils/hex.js +78 -63
- package/dist/mjs/utils/http.js +119 -100
- package/dist/mjs/utils/merge.js +26 -20
- package/dist/mjs/utils/pss.js +8 -6
- package/dist/mjs/utils/stamps.js +7 -3
- package/dist/mjs/utils/stream.js +107 -82
- package/dist/mjs/utils/tar.js +17 -14
- package/dist/mjs/utils/type.js +249 -209
- package/dist/mjs/utils/uint64.js +16 -16
- package/dist/mjs/utils/url.js +32 -25
- package/dist/types/types/index.d.ts +1 -1
- package/dist/types/types/ky-options.d.ts +221 -0
- package/dist/types/types/ky-universal/common.d.ts +13 -0
- package/dist/types/types/ky-universal/hooks.d.ts +92 -0
- package/dist/types/types/ky-universal/retry.d.ts +38 -0
- package/dist/types/utils/stream.d.ts +11 -8
- package/package.json +9 -6
- package/dist/index.js +0 -28326
- package/dist/index.js.map +0 -1
package/dist/mjs/utils/stamps.js
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
* @param depth
|
|
9
9
|
* @param bucketDepth
|
|
10
10
|
*/
|
|
11
|
-
export function getStampUsage({
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export function getStampUsage({
|
|
12
|
+
utilization,
|
|
13
|
+
depth,
|
|
14
|
+
bucketDepth
|
|
15
|
+
}) {
|
|
16
|
+
return utilization / Math.pow(2, depth - bucketDepth);
|
|
17
|
+
}
|
package/dist/mjs/utils/stream.js
CHANGED
|
@@ -1,38 +1,42 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { Readable as NodeReadableNative } from 'stream';
|
|
2
|
+
import { isStrictlyObject } from "./type.js";
|
|
3
|
+
import { ReadableStream } from 'web-streams-polyfill/dist/ponyfill.js';
|
|
4
|
+
const NodeReadable = NodeReadableNative || class {};
|
|
4
5
|
/**
|
|
5
6
|
* Validates if passed object is either browser's ReadableStream
|
|
6
7
|
* or Node's Readable.
|
|
7
8
|
*
|
|
8
9
|
* @param entry
|
|
9
10
|
*/
|
|
11
|
+
|
|
10
12
|
export function isReadable(entry) {
|
|
11
|
-
|
|
13
|
+
return isReadableStream(entry) || isNodeReadable(entry);
|
|
12
14
|
}
|
|
13
15
|
export function isReadableStream(entry) {
|
|
14
|
-
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
17
|
-
const browserReadable = entry;
|
|
18
|
-
if (typeof browserReadable.getReader === 'function' &&
|
|
19
|
-
browserReadable.locked !== undefined &&
|
|
20
|
-
typeof browserReadable.cancel === 'function' &&
|
|
21
|
-
typeof browserReadable.pipeTo === 'function' &&
|
|
22
|
-
typeof browserReadable.pipeThrough === 'function') {
|
|
23
|
-
return true;
|
|
24
|
-
}
|
|
16
|
+
if (!isStrictlyObject(entry)) {
|
|
25
17
|
return false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const browserReadable = entry;
|
|
21
|
+
|
|
22
|
+
if (typeof browserReadable.getReader === 'function' && browserReadable.locked !== undefined && typeof browserReadable.cancel === 'function' && typeof browserReadable.pipeTo === 'function' && typeof browserReadable.pipeThrough === 'function') {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return false;
|
|
26
27
|
}
|
|
27
28
|
export function isNodeReadable(entry) {
|
|
28
|
-
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
const nodeReadable = entry;
|
|
32
|
-
if (typeof nodeReadable.pipe === 'function' && nodeReadable.readable && typeof nodeReadable._read === 'function') {
|
|
33
|
-
return true;
|
|
34
|
-
}
|
|
29
|
+
if (!isStrictlyObject(entry)) {
|
|
35
30
|
return false;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const nodeReadable = entry;
|
|
34
|
+
|
|
35
|
+
if (typeof nodeReadable.pipe === 'function' && nodeReadable.readable && typeof nodeReadable._read === 'function') {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
return false;
|
|
36
40
|
}
|
|
37
41
|
/**
|
|
38
42
|
* Function that converts Node's Readable into WHATWG ReadableStream
|
|
@@ -44,29 +48,33 @@ export function isNodeReadable(entry) {
|
|
|
44
48
|
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
45
49
|
* @param nodeStream
|
|
46
50
|
*/
|
|
51
|
+
|
|
47
52
|
export function readableNodeToWeb(nodeStream) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
53
|
+
return new ReadableStream({
|
|
54
|
+
start(controller) {
|
|
55
|
+
nodeStream.pause();
|
|
56
|
+
nodeStream.on('data', chunk => {
|
|
57
|
+
if (Buffer.isBuffer(chunk)) {
|
|
58
|
+
controller.enqueue(new Uint8Array(chunk.buffer));
|
|
59
|
+
} else {
|
|
60
|
+
controller.enqueue(chunk);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
nodeStream.pause();
|
|
64
|
+
});
|
|
65
|
+
nodeStream.on('end', () => controller.close());
|
|
66
|
+
nodeStream.on('error', e => controller.error(e));
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
pull() {
|
|
70
|
+
nodeStream.resume();
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
cancel() {
|
|
74
|
+
nodeStream.pause();
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
});
|
|
70
78
|
}
|
|
71
79
|
/**
|
|
72
80
|
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
@@ -75,57 +83,74 @@ export function readableNodeToWeb(nodeStream) {
|
|
|
75
83
|
* @author https://github.com/gwicke
|
|
76
84
|
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
77
85
|
*/
|
|
86
|
+
|
|
78
87
|
class NodeReadableWrapper extends NodeReadable {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
88
|
+
_webStream;
|
|
89
|
+
_reader;
|
|
90
|
+
_reading;
|
|
91
|
+
|
|
92
|
+
constructor(webStream, options) {
|
|
93
|
+
super(options);
|
|
94
|
+
this._webStream = webStream;
|
|
95
|
+
this._reader = webStream.getReader();
|
|
96
|
+
this._reading = false;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
_read() {
|
|
100
|
+
if (this._reading) {
|
|
101
|
+
return;
|
|
87
102
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
103
|
+
|
|
104
|
+
this._reading = true;
|
|
105
|
+
|
|
106
|
+
const doRead = () => {
|
|
107
|
+
this._reader.read().then(res => {
|
|
108
|
+
if (res.done) {
|
|
109
|
+
this.push(null);
|
|
110
|
+
return;
|
|
91
111
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
};
|
|
107
|
-
doRead();
|
|
108
|
-
}
|
|
112
|
+
|
|
113
|
+
if (this.push(res.value)) {
|
|
114
|
+
return doRead();
|
|
115
|
+
} else {
|
|
116
|
+
this._reading = false;
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
doRead();
|
|
122
|
+
}
|
|
123
|
+
|
|
109
124
|
}
|
|
110
125
|
/**
|
|
111
126
|
* Function that converts WHATWG ReadableStream into Node's Readable
|
|
112
127
|
*
|
|
113
128
|
* Taken over from https://github.com/gwicke/node-web-streams/blob/master/lib/conversions.js
|
|
114
|
-
* Because it uses forked web-streams-polyfill that
|
|
129
|
+
* Because it uses forked web-streams-polyfill that is outdated.
|
|
130
|
+
*
|
|
131
|
+
* **Warning!**
|
|
132
|
+
* If you want to use this function in browser you have to polyfill `stream` package with your bundler.
|
|
115
133
|
*
|
|
116
134
|
* @author https://github.com/gwicke
|
|
117
135
|
* @licence Apache License 2.0 https://github.com/gwicke/node-web-streams/blob/master/LICENSE
|
|
118
136
|
* @param webStream
|
|
137
|
+
* @param options
|
|
119
138
|
*/
|
|
139
|
+
|
|
140
|
+
|
|
120
141
|
export function readableWebToNode(webStream, options) {
|
|
121
|
-
|
|
142
|
+
if (!NodeReadableNative) {
|
|
143
|
+
throw new Error("The Node's Readable is not available! If you are running this in browser you have to polyfill 'stream' package!");
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
return new NodeReadableWrapper(webStream, options);
|
|
122
147
|
}
|
|
123
148
|
export function normalizeToReadableStream(stream) {
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
}
|
|
149
|
+
if (isNodeReadable(stream)) {
|
|
150
|
+
return readableNodeToWeb(stream);
|
|
151
|
+
} else if (isReadableStream(stream)) {
|
|
152
|
+
return stream;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
throw new TypeError('Passed stream is not Node Readable nor ReadableStream!');
|
|
156
|
+
}
|
package/dist/mjs/utils/tar.js
CHANGED
|
@@ -1,18 +1,21 @@
|
|
|
1
|
-
import Tar from 'tar-js';
|
|
2
|
-
// converts a string to utf8 Uint8Array and returns it as a string-like
|
|
1
|
+
import Tar from 'tar-js'; // converts a string to utf8 Uint8Array and returns it as a string-like
|
|
3
2
|
// object that `tar.append` accepts as path
|
|
3
|
+
|
|
4
4
|
function fixUnicodePath(path) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+
const codes = new TextEncoder().encode(path);
|
|
6
|
+
return {
|
|
7
|
+
length: codes.length,
|
|
8
|
+
charCodeAt: index => codes[index]
|
|
9
|
+
};
|
|
10
10
|
}
|
|
11
|
+
|
|
11
12
|
export function makeTar(data) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
13
|
+
const tar = new Tar();
|
|
14
|
+
|
|
15
|
+
for (const entry of data) {
|
|
16
|
+
const path = fixUnicodePath(entry.path);
|
|
17
|
+
tar.append(path, entry.data);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return tar.out;
|
|
21
|
+
}
|