@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.
Files changed (85) hide show
  1. package/dist/cjs/chunk/bmt.js +7 -2
  2. package/dist/cjs/chunk/signer.js +9 -4
  3. package/dist/cjs/modules/debug/status.js +5 -5
  4. package/dist/cjs/package.json +1 -0
  5. package/dist/cjs/types/ky-options.js +8 -0
  6. package/dist/cjs/types/ky-universal/common.js +8 -0
  7. package/dist/cjs/types/ky-universal/hooks.js +8 -0
  8. package/dist/cjs/types/ky-universal/retry.js +8 -0
  9. package/dist/cjs/utils/eth.js +8 -3
  10. package/dist/cjs/utils/hash.js +7 -2
  11. package/dist/cjs/utils/stream.js +14 -5
  12. package/dist/index.browser.min.js +3 -0
  13. package/dist/index.browser.min.js.LICENSE.txt +52 -0
  14. package/dist/index.browser.min.js.map +1 -0
  15. package/dist/mjs/bee-debug.js +608 -508
  16. package/dist/mjs/bee.js +935 -836
  17. package/dist/mjs/chunk/bmt.js +34 -24
  18. package/dist/mjs/chunk/cac.js +24 -22
  19. package/dist/mjs/chunk/serialize.js +9 -9
  20. package/dist/mjs/chunk/signer.js +92 -73
  21. package/dist/mjs/chunk/soc.js +78 -66
  22. package/dist/mjs/chunk/span.js +19 -16
  23. package/dist/mjs/feed/index.js +110 -101
  24. package/dist/mjs/feed/json.js +21 -17
  25. package/dist/mjs/feed/topic.js +18 -17
  26. package/dist/mjs/feed/type.js +5 -5
  27. package/dist/mjs/index.js +7 -7
  28. package/dist/mjs/modules/bytes.js +33 -30
  29. package/dist/mjs/modules/bzz.js +80 -77
  30. package/dist/mjs/modules/chunk.js +22 -20
  31. package/dist/mjs/modules/debug/balance.js +26 -22
  32. package/dist/mjs/modules/debug/chequebook.js +84 -65
  33. package/dist/mjs/modules/debug/chunk.js +15 -13
  34. package/dist/mjs/modules/debug/connectivity.js +34 -34
  35. package/dist/mjs/modules/debug/settlements.js +14 -12
  36. package/dist/mjs/modules/debug/stamps.js +52 -47
  37. package/dist/mjs/modules/debug/states.js +16 -14
  38. package/dist/mjs/modules/debug/status.js +55 -35
  39. package/dist/mjs/modules/debug/tag.js +8 -7
  40. package/dist/mjs/modules/debug/transactions.js +31 -25
  41. package/dist/mjs/modules/feed.js +39 -33
  42. package/dist/mjs/modules/pinning.js +34 -28
  43. package/dist/mjs/modules/pss.js +18 -14
  44. package/dist/mjs/modules/soc.js +18 -15
  45. package/dist/mjs/modules/status.js +6 -5
  46. package/dist/mjs/modules/stewardship.js +13 -12
  47. package/dist/mjs/modules/tag.js +38 -30
  48. package/dist/mjs/package.json +1 -0
  49. package/dist/mjs/types/debug.js +5 -4
  50. package/dist/mjs/types/index.js +6 -2
  51. package/dist/mjs/types/ky-options.js +7 -0
  52. package/dist/mjs/types/ky-universal/common.js +7 -0
  53. package/dist/mjs/types/ky-universal/hooks.js +7 -0
  54. package/dist/mjs/types/ky-universal/retry.js +7 -0
  55. package/dist/mjs/utils/bytes.js +32 -26
  56. package/dist/mjs/utils/collection.browser.js +4 -3
  57. package/dist/mjs/utils/collection.js +47 -35
  58. package/dist/mjs/utils/collection.node.js +53 -42
  59. package/dist/mjs/utils/data.browser.js +64 -48
  60. package/dist/mjs/utils/data.js +29 -25
  61. package/dist/mjs/utils/error.js +47 -39
  62. package/dist/mjs/utils/eth.js +119 -104
  63. package/dist/mjs/utils/expose.js +9 -9
  64. package/dist/mjs/utils/file.js +22 -19
  65. package/dist/mjs/utils/hash.js +10 -5
  66. package/dist/mjs/utils/headers.js +43 -39
  67. package/dist/mjs/utils/hex.js +78 -63
  68. package/dist/mjs/utils/http.js +119 -100
  69. package/dist/mjs/utils/merge.js +26 -20
  70. package/dist/mjs/utils/pss.js +8 -6
  71. package/dist/mjs/utils/stamps.js +7 -3
  72. package/dist/mjs/utils/stream.js +107 -82
  73. package/dist/mjs/utils/tar.js +17 -14
  74. package/dist/mjs/utils/type.js +249 -209
  75. package/dist/mjs/utils/uint64.js +16 -16
  76. package/dist/mjs/utils/url.js +32 -25
  77. package/dist/types/types/index.d.ts +1 -1
  78. package/dist/types/types/ky-options.d.ts +221 -0
  79. package/dist/types/types/ky-universal/common.d.ts +13 -0
  80. package/dist/types/types/ky-universal/hooks.d.ts +92 -0
  81. package/dist/types/types/ky-universal/retry.d.ts +38 -0
  82. package/dist/types/utils/stream.d.ts +11 -8
  83. package/package.json +9 -6
  84. package/dist/index.js +0 -28326
  85. package/dist/index.js.map +0 -1
@@ -8,6 +8,10 @@
8
8
  * @param depth
9
9
  * @param bucketDepth
10
10
  */
11
- export function getStampUsage({ utilization, depth, bucketDepth }) {
12
- return utilization / Math.pow(2, depth - bucketDepth);
13
- }
11
+ export function getStampUsage({
12
+ utilization,
13
+ depth,
14
+ bucketDepth
15
+ }) {
16
+ return utilization / Math.pow(2, depth - bucketDepth);
17
+ }
@@ -1,38 +1,42 @@
1
- import { isStrictlyObject } from './type';
2
- import { ReadableStream } from 'web-streams-polyfill/ponyfill';
3
- import { Readable as NodeReadable } from 'readable-stream';
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
- return isReadableStream(entry) || isNodeReadable(entry);
13
+ return isReadableStream(entry) || isNodeReadable(entry);
12
14
  }
13
15
  export function isReadableStream(entry) {
14
- if (!isStrictlyObject(entry)) {
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
- if (!isStrictlyObject(entry)) {
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
- return new ReadableStream({
49
- start(controller) {
50
- nodeStream.pause();
51
- nodeStream.on('data', chunk => {
52
- if (Buffer.isBuffer(chunk)) {
53
- controller.enqueue(new Uint8Array(chunk.buffer));
54
- }
55
- else {
56
- controller.enqueue(chunk);
57
- }
58
- nodeStream.pause();
59
- });
60
- nodeStream.on('end', () => controller.close());
61
- nodeStream.on('error', e => controller.error(e));
62
- },
63
- pull() {
64
- nodeStream.resume();
65
- },
66
- cancel() {
67
- nodeStream.pause();
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
- _webStream;
80
- _reader;
81
- _reading;
82
- constructor(webStream, options) {
83
- super(options);
84
- this._webStream = webStream;
85
- this._reader = webStream.getReader();
86
- this._reading = false;
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
- _read() {
89
- if (this._reading) {
90
- return;
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
- this._reading = true;
93
- const doRead = () => {
94
- this._reader.read().then(res => {
95
- if (res.done) {
96
- this.push(null);
97
- return;
98
- }
99
- if (this.push(res.value)) {
100
- return doRead();
101
- }
102
- else {
103
- this._reading = false;
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 are outdated.
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
- return new NodeReadableWrapper(webStream, options);
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
- if (isNodeReadable(stream)) {
125
- return readableNodeToWeb(stream);
126
- }
127
- else if (isReadableStream(stream)) {
128
- return stream;
129
- }
130
- throw new TypeError('Passed stream is not Node Readable nor ReadableStream!');
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
+ }
@@ -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
- const codes = new TextEncoder().encode(path);
6
- return {
7
- length: codes.length,
8
- charCodeAt: index => codes[index],
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
- const tar = new Tar();
13
- for (const entry of data) {
14
- const path = fixUnicodePath(entry.path);
15
- tar.append(path, entry.data);
16
- }
17
- return tar.out;
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
+ }