@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
@@ -1,20 +1,16 @@
1
- import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX, } from '../types';
2
- import { BeeArgumentError } from './error';
3
- import { isFile } from './file';
4
- import { assertHexString, assertPrefixedHexString } from './hex';
5
- import { isReadable } from './stream';
1
+ import { ADDRESS_HEX_LENGTH, BATCH_ID_HEX_LENGTH, ENCRYPTED_REFERENCE_HEX_LENGTH, PUBKEY_HEX_LENGTH, REFERENCE_HEX_LENGTH, TAGS_LIMIT_MAX, TAGS_LIMIT_MIN, PSS_TARGET_HEX_LENGTH_MAX } from "../types/index.js";
2
+ import { BeeArgumentError } from "./error.js";
3
+ import { isFile } from "./file.js";
4
+ import { assertHexString, assertPrefixedHexString } from "./hex.js";
5
+ import { isReadable } from "./stream.js";
6
6
  export function isUint8Array(obj) {
7
- return obj instanceof Uint8Array;
7
+ return obj instanceof Uint8Array;
8
8
  }
9
9
  export function isInteger(value) {
10
- return ((typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value)) ||
11
- (typeof value === 'number' &&
12
- value > Number.MIN_SAFE_INTEGER &&
13
- value < Number.MAX_SAFE_INTEGER &&
14
- Number.isInteger(value)));
10
+ return typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value) || typeof value === 'number' && value > Number.MIN_SAFE_INTEGER && value < Number.MAX_SAFE_INTEGER && Number.isInteger(value);
15
11
  }
16
12
  export function isObject(value) {
17
- return value !== null && typeof value === 'object';
13
+ return value !== null && typeof value === 'object';
18
14
  }
19
15
  /**
20
16
  * Generally it is discouraged to use `object` type, but in this case I think
@@ -26,271 +22,315 @@ export function isObject(value) {
26
22
  * @param value
27
23
  */
28
24
  // eslint-disable-next-line @typescript-eslint/ban-types
25
+
29
26
  export function isStrictlyObject(value) {
30
- return isObject(value) && !Array.isArray(value);
27
+ return isObject(value) && !Array.isArray(value);
31
28
  }
32
29
  /**
33
30
  * Asserts if object is Error
34
31
  *
35
32
  * @param e
36
33
  */
34
+
37
35
  export function isError(e) {
38
- return e instanceof Error;
39
- }
40
- // eslint-disable-next-line @typescript-eslint/ban-types
36
+ return e instanceof Error;
37
+ } // eslint-disable-next-line @typescript-eslint/ban-types
38
+
41
39
  export function assertStrictlyObject(value, name = 'value') {
42
- if (!isStrictlyObject(value)) {
43
- throw new TypeError(`${name} has to be an object that is not null nor array!`);
44
- }
40
+ if (!isStrictlyObject(value)) {
41
+ throw new TypeError(`${name} has to be an object that is not null nor array!`);
42
+ }
45
43
  }
46
44
  export function assertBoolean(value, name = 'value') {
47
- if (value !== true && value !== false)
48
- throw new TypeError(`${name} is not boolean`);
45
+ if (value !== true && value !== false) throw new TypeError(`${name} is not boolean`);
49
46
  }
50
47
  export function assertInteger(value, name = 'value') {
51
- if (!isInteger(value))
52
- throw new TypeError(`${name} is not integer`);
48
+ if (!isInteger(value)) throw new TypeError(`${name} is not integer`);
53
49
  }
54
50
  export function assertNonNegativeInteger(value, name = 'Value') {
55
- assertInteger(value, name);
56
- if (Number(value) < 0)
57
- throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
51
+ assertInteger(value, name);
52
+ if (Number(value) < 0) throw new BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
58
53
  }
59
54
  export function assertReference(value) {
60
- try {
61
- assertHexString(value, REFERENCE_HEX_LENGTH);
62
- }
63
- catch (e) {
64
- assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH);
65
- }
55
+ try {
56
+ assertHexString(value, REFERENCE_HEX_LENGTH);
57
+ } catch (e) {
58
+ assertHexString(value, ENCRYPTED_REFERENCE_HEX_LENGTH);
59
+ }
66
60
  }
67
61
  export function assertAddress(value) {
68
- assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
62
+ assertHexString(value, ADDRESS_HEX_LENGTH, 'Address');
69
63
  }
70
64
  export function assertBatchId(value) {
71
- assertHexString(value, BATCH_ID_HEX_LENGTH, 'BatchId');
65
+ assertHexString(value, BATCH_ID_HEX_LENGTH, 'BatchId');
72
66
  }
73
67
  export function assertRequestOptions(value, name = 'RequestOptions') {
74
- if (value === undefined) {
75
- return;
76
- }
77
- if (!isStrictlyObject(value)) {
78
- throw new TypeError(`${name} has to be an object!`);
79
- }
80
- const options = value;
81
- if (options.retry) {
82
- assertNonNegativeInteger(options.retry, `${name}.retry`);
83
- }
84
- if (options.timeout) {
85
- assertNonNegativeInteger(options.timeout, `${name}.timeout`);
86
- }
87
- if (options.fetch && typeof options.fetch !== 'function') {
88
- throw new TypeError(`${name}.fetch has to be a function or undefined!`);
89
- }
68
+ if (value === undefined) {
69
+ return;
70
+ }
71
+
72
+ if (!isStrictlyObject(value)) {
73
+ throw new TypeError(`${name} has to be an object!`);
74
+ }
75
+
76
+ const options = value;
77
+
78
+ if (options.retry) {
79
+ assertNonNegativeInteger(options.retry, `${name}.retry`);
80
+ }
81
+
82
+ if (options.timeout) {
83
+ assertNonNegativeInteger(options.timeout, `${name}.timeout`);
84
+ }
85
+
86
+ if (options.fetch && typeof options.fetch !== 'function') {
87
+ throw new TypeError(`${name}.fetch has to be a function or undefined!`);
88
+ }
90
89
  }
91
90
  export function assertUploadOptions(value, name = 'UploadOptions') {
92
- if (!isStrictlyObject(value)) {
93
- throw new TypeError(`${name} has to be an object!`);
94
- }
95
- assertRequestOptions(value, name);
96
- const options = value;
97
- if (options.pin && typeof options.pin !== 'boolean') {
98
- throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
99
- }
100
- if (options.encrypt && typeof options.encrypt !== 'boolean') {
101
- throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
102
- }
103
- if (options.tag) {
104
- if (typeof options.tag !== 'number') {
105
- throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
106
- }
107
- assertNonNegativeInteger(options.tag, 'options.tag');
108
- }
91
+ if (!isStrictlyObject(value)) {
92
+ throw new TypeError(`${name} has to be an object!`);
93
+ }
94
+
95
+ assertRequestOptions(value, name);
96
+ const options = value;
97
+
98
+ if (options.pin && typeof options.pin !== 'boolean') {
99
+ throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
100
+ }
101
+
102
+ if (options.encrypt && typeof options.encrypt !== 'boolean') {
103
+ throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
104
+ }
105
+
106
+ if (options.tag) {
107
+ if (typeof options.tag !== 'number') {
108
+ throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
109
+ }
110
+
111
+ assertNonNegativeInteger(options.tag, 'options.tag');
112
+ }
109
113
  }
110
114
  export function assertFileUploadOptions(value) {
111
- assertUploadOptions(value, 'FileUploadOptions');
112
- const options = value;
113
- if (options.size) {
114
- if (typeof options.size !== 'number') {
115
- throw new TypeError('tag property in FileUploadOptions has to be number or undefined!');
116
- }
117
- assertNonNegativeInteger(options.size, 'options.size');
118
- }
119
- if (options.contentType && typeof options.contentType !== 'string') {
120
- throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
121
- }
115
+ assertUploadOptions(value, 'FileUploadOptions');
116
+ const options = value;
117
+
118
+ if (options.size) {
119
+ if (typeof options.size !== 'number') {
120
+ throw new TypeError('tag property in FileUploadOptions has to be number or undefined!');
121
+ }
122
+
123
+ assertNonNegativeInteger(options.size, 'options.size');
124
+ }
125
+
126
+ if (options.contentType && typeof options.contentType !== 'string') {
127
+ throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
128
+ }
122
129
  }
123
130
  export function assertCollectionUploadOptions(value) {
124
- assertUploadOptions(value, 'CollectionUploadOptions');
125
- const options = value;
126
- if (options.indexDocument && typeof options.indexDocument !== 'string') {
127
- throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!');
128
- }
129
- if (options.errorDocument && typeof options.errorDocument !== 'string') {
130
- throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!');
131
- }
131
+ assertUploadOptions(value, 'CollectionUploadOptions');
132
+ const options = value;
133
+
134
+ if (options.indexDocument && typeof options.indexDocument !== 'string') {
135
+ throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!');
136
+ }
137
+
138
+ if (options.errorDocument && typeof options.errorDocument !== 'string') {
139
+ throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!');
140
+ }
132
141
  }
133
142
  export function isTag(value) {
134
- if (!isStrictlyObject(value)) {
135
- return false;
136
- }
137
- const tag = value;
138
- const numberProperties = ['total', 'processed', 'synced', 'uid'];
139
- const correctNumberProperties = numberProperties.every(numberProperty => typeof tag[numberProperty] === 'number');
140
- if (!correctNumberProperties || !tag.startedAt || typeof tag.startedAt !== 'string') {
141
- return false;
142
- }
143
- return true;
143
+ if (!isStrictlyObject(value)) {
144
+ return false;
145
+ }
146
+
147
+ const tag = value;
148
+ const numberProperties = ['total', 'processed', 'synced', 'uid'];
149
+ const correctNumberProperties = numberProperties.every(numberProperty => typeof tag[numberProperty] === 'number');
150
+
151
+ if (!correctNumberProperties || !tag.startedAt || typeof tag.startedAt !== 'string') {
152
+ return false;
153
+ }
154
+
155
+ return true;
144
156
  }
145
157
  export function assertTag(value) {
146
- if (!isStrictlyObject(value)) {
147
- throw new TypeError('Tag is not an object!');
148
- }
149
- const tag = value;
150
- const numberProperties = ['total', 'processed', 'synced', 'uid'];
151
- for (const numberProperty of numberProperties) {
152
- if (!tag[numberProperty]) {
153
- throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
154
- }
155
- if (typeof tag[numberProperty] !== 'number') {
156
- throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
157
- }
158
- }
159
- if (!tag.startedAt) {
160
- throw new TypeError("Tag's property 'startedAt' has to be specified!");
161
- }
162
- if (typeof tag.startedAt !== 'string') {
163
- throw new TypeError("Tag's property 'startedAt' has to be string!");
164
- }
158
+ if (!isStrictlyObject(value)) {
159
+ throw new TypeError('Tag is not an object!');
160
+ }
161
+
162
+ const tag = value;
163
+ const numberProperties = ['total', 'processed', 'synced', 'uid'];
164
+
165
+ for (const numberProperty of numberProperties) {
166
+ if (!tag[numberProperty]) {
167
+ throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
168
+ }
169
+
170
+ if (typeof tag[numberProperty] !== 'number') {
171
+ throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
172
+ }
173
+ }
174
+
175
+ if (!tag.startedAt) {
176
+ throw new TypeError("Tag's property 'startedAt' has to be specified!");
177
+ }
178
+
179
+ if (typeof tag.startedAt !== 'string') {
180
+ throw new TypeError("Tag's property 'startedAt' has to be string!");
181
+ }
165
182
  }
166
183
  export function assertAddressPrefix(value) {
167
- assertHexString(value, undefined, 'AddressPrefix');
168
- if (value.length > PSS_TARGET_HEX_LENGTH_MAX) {
169
- throw new BeeArgumentError(`AddressPrefix must have length of ${PSS_TARGET_HEX_LENGTH_MAX} at most! Got string with ${value.length}`, value);
170
- }
184
+ assertHexString(value, undefined, 'AddressPrefix');
185
+
186
+ if (value.length > PSS_TARGET_HEX_LENGTH_MAX) {
187
+ throw new BeeArgumentError(`AddressPrefix must have length of ${PSS_TARGET_HEX_LENGTH_MAX} at most! Got string with ${value.length}`, value);
188
+ }
171
189
  }
172
190
  export function assertPssMessageHandler(value) {
173
- if (!isStrictlyObject(value)) {
174
- throw new TypeError('PssMessageHandler has to be object!');
175
- }
176
- const handler = value;
177
- if (typeof handler.onMessage !== 'function') {
178
- throw new TypeError('onMessage property of PssMessageHandler has to be function!');
179
- }
180
- if (typeof handler.onError !== 'function') {
181
- throw new TypeError('onError property of PssMessageHandler has to be function!');
182
- }
191
+ if (!isStrictlyObject(value)) {
192
+ throw new TypeError('PssMessageHandler has to be object!');
193
+ }
194
+
195
+ const handler = value;
196
+
197
+ if (typeof handler.onMessage !== 'function') {
198
+ throw new TypeError('onMessage property of PssMessageHandler has to be function!');
199
+ }
200
+
201
+ if (typeof handler.onError !== 'function') {
202
+ throw new TypeError('onError property of PssMessageHandler has to be function!');
203
+ }
183
204
  }
184
205
  export function assertPublicKey(value) {
185
- assertHexString(value, PUBKEY_HEX_LENGTH, 'PublicKey');
206
+ assertHexString(value, PUBKEY_HEX_LENGTH, 'PublicKey');
186
207
  }
187
208
  export function assertPostageBatchOptions(value) {
188
- if (value === undefined) {
189
- return;
190
- }
191
- assertStrictlyObject(value);
192
- const options = value;
193
- assertRequestOptions(options, 'PostageBatchOptions');
194
- if (options?.gasPrice) {
195
- assertNonNegativeInteger(options.gasPrice);
196
- }
197
- if (options?.immutableFlag !== undefined) {
198
- assertBoolean(options.immutableFlag);
199
- }
209
+ if (value === undefined) {
210
+ return;
211
+ }
212
+
213
+ assertStrictlyObject(value);
214
+ const options = value;
215
+ assertRequestOptions(options, 'PostageBatchOptions');
216
+
217
+ if (options?.gasPrice) {
218
+ assertNonNegativeInteger(options.gasPrice);
219
+ }
220
+
221
+ if (options?.immutableFlag !== undefined) {
222
+ assertBoolean(options.immutableFlag);
223
+ }
200
224
  }
201
225
  export function assertCashoutOptions(value) {
202
- if (value === undefined) {
203
- return;
204
- }
205
- assertStrictlyObject(value);
206
- const options = value;
207
- assertRequestOptions(options, 'PostageBatchOptions');
208
- if (options?.gasLimit) {
209
- assertNonNegativeInteger(options.gasLimit);
210
- }
211
- if (options?.gasPrice) {
212
- assertNonNegativeInteger(options.gasPrice);
213
- }
226
+ if (value === undefined) {
227
+ return;
228
+ }
229
+
230
+ assertStrictlyObject(value);
231
+ const options = value;
232
+ assertRequestOptions(options, 'PostageBatchOptions');
233
+
234
+ if (options?.gasLimit) {
235
+ assertNonNegativeInteger(options.gasLimit);
236
+ }
237
+
238
+ if (options?.gasPrice) {
239
+ assertNonNegativeInteger(options.gasPrice);
240
+ }
214
241
  }
215
242
  /**
216
243
  * Check whether the given parameter is valid data to upload
217
244
  * @param value
218
245
  * @throws TypeError if not valid
219
246
  */
247
+
220
248
  export function assertData(value) {
221
- if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
222
- throw new TypeError('Data must be either string or Uint8Array!');
223
- }
249
+ if (typeof value !== 'string' && !(value instanceof Uint8Array)) {
250
+ throw new TypeError('Data must be either string or Uint8Array!');
251
+ }
224
252
  }
225
253
  /**
226
254
  * Check whether the given parameter is a correct file representation to file upload.
227
255
  * @param value
228
256
  * @throws TypeError if not valid
229
257
  */
258
+
230
259
  export function assertFileData(value) {
231
- if (typeof value !== 'string' && !(value instanceof Uint8Array) && !isFile(value) && !isReadable(value)) {
232
- throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
233
- }
260
+ if (typeof value !== 'string' && !(value instanceof Uint8Array) && !isFile(value) && !isReadable(value)) {
261
+ throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
262
+ }
234
263
  }
235
264
  /**
236
265
  * Checks whether optional options for AllTags query are valid
237
266
  * @param options
238
267
  */
268
+
239
269
  export function assertAllTagsOptions(entry) {
240
- if (entry !== undefined && !isStrictlyObject(entry)) {
241
- throw new TypeError('options has to be an object or undefined!');
242
- }
243
- assertRequestOptions(entry, 'AllTagsOptions');
244
- const options = entry;
245
- if (options?.limit !== undefined) {
246
- if (typeof options.limit !== 'number') {
247
- throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
248
- }
249
- if (options.limit < TAGS_LIMIT_MIN) {
250
- throw new BeeArgumentError(`AllTagsOptions.limit has to be at least ${TAGS_LIMIT_MIN}`, options.limit);
251
- }
252
- if (options.limit > TAGS_LIMIT_MAX) {
253
- throw new BeeArgumentError(`AllTagsOptions.limit has to be at most ${TAGS_LIMIT_MAX}`, options.limit);
254
- }
255
- }
256
- if (options?.offset !== undefined) {
257
- assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
258
- }
270
+ if (entry !== undefined && !isStrictlyObject(entry)) {
271
+ throw new TypeError('options has to be an object or undefined!');
272
+ }
273
+
274
+ assertRequestOptions(entry, 'AllTagsOptions');
275
+ const options = entry;
276
+
277
+ if (options?.limit !== undefined) {
278
+ if (typeof options.limit !== 'number') {
279
+ throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
280
+ }
281
+
282
+ if (options.limit < TAGS_LIMIT_MIN) {
283
+ throw new BeeArgumentError(`AllTagsOptions.limit has to be at least ${TAGS_LIMIT_MIN}`, options.limit);
284
+ }
285
+
286
+ if (options.limit > TAGS_LIMIT_MAX) {
287
+ throw new BeeArgumentError(`AllTagsOptions.limit has to be at most ${TAGS_LIMIT_MAX}`, options.limit);
288
+ }
289
+ }
290
+
291
+ if (options?.offset !== undefined) {
292
+ assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
293
+ }
259
294
  }
260
295
  /**
261
296
  * Utility functions that return Tag UID
262
297
  * @param tagUid
263
298
  */
299
+
264
300
  export function makeTagUid(tagUid) {
265
- if (tagUid === undefined || tagUid === null) {
266
- throw new TypeError('TagUid was expected but got undefined or null instead!');
267
- }
268
- if (isTag(tagUid)) {
269
- return tagUid.uid;
270
- }
271
- else if (typeof tagUid === 'number') {
272
- assertNonNegativeInteger(tagUid, 'UID');
273
- return tagUid;
274
- }
275
- else if (typeof tagUid === 'string') {
276
- const int = parseInt(tagUid);
277
- if (isNaN(int)) {
278
- throw new TypeError('Passed tagUid string is not valid integer!');
279
- }
280
- if (int < 0) {
281
- throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
282
- }
283
- return int;
284
- }
285
- throw new TypeError('tagUid has to be either Tag or a number (UID)!');
301
+ if (tagUid === undefined || tagUid === null) {
302
+ throw new TypeError('TagUid was expected but got undefined or null instead!');
303
+ }
304
+
305
+ if (isTag(tagUid)) {
306
+ return tagUid.uid;
307
+ } else if (typeof tagUid === 'number') {
308
+ assertNonNegativeInteger(tagUid, 'UID');
309
+ return tagUid;
310
+ } else if (typeof tagUid === 'string') {
311
+ const int = parseInt(tagUid);
312
+
313
+ if (isNaN(int)) {
314
+ throw new TypeError('Passed tagUid string is not valid integer!');
315
+ }
316
+
317
+ if (int < 0) {
318
+ throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
319
+ }
320
+
321
+ return int;
322
+ }
323
+
324
+ throw new TypeError('tagUid has to be either Tag or a number (UID)!');
286
325
  }
287
326
  export function assertTransactionHash(transactionHash) {
288
- if (typeof transactionHash !== 'string') {
289
- throw new TypeError('TransactionHash has to be a string!');
290
- }
291
- assertPrefixedHexString(transactionHash, 'TransactionHash');
292
- // Hash is 64 long + '0x' prefix = 66
293
- if (transactionHash.length !== 66) {
294
- throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
295
- }
296
- }
327
+ if (typeof transactionHash !== 'string') {
328
+ throw new TypeError('TransactionHash has to be a string!');
329
+ }
330
+
331
+ assertPrefixedHexString(transactionHash, 'TransactionHash'); // Hash is 64 long + '0x' prefix = 66
332
+
333
+ if (transactionHash.length !== 66) {
334
+ throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
335
+ }
336
+ }
@@ -1,23 +1,23 @@
1
- import { makeBytes } from './bytes';
2
- // TODO handle bigger values than 32 bit
1
+ import { makeBytes } from "./bytes.js"; // TODO handle bigger values than 32 bit
3
2
  // For now it's good enough because we only use these functions
4
3
  // sequential feed indexes.
4
+
5
5
  export function writeUint64LittleEndian(value, bytes = makeBytes(8)) {
6
- const dataView = new DataView(bytes.buffer);
7
- const valueLower32 = value & 0xffffffff;
8
- const littleEndian = true;
9
- dataView.setUint32(0, valueLower32, littleEndian);
10
- dataView.setUint32(4, 0, littleEndian);
11
- return bytes;
6
+ const dataView = new DataView(bytes.buffer);
7
+ const valueLower32 = value & 0xffffffff;
8
+ const littleEndian = true;
9
+ dataView.setUint32(0, valueLower32, littleEndian);
10
+ dataView.setUint32(4, 0, littleEndian);
11
+ return bytes;
12
12
  }
13
13
  export function writeUint64BigEndian(value, bytes = makeBytes(8)) {
14
- const dataView = new DataView(bytes.buffer);
15
- const valueLower32 = value & 0xffffffff;
16
- dataView.setUint32(0, 0);
17
- dataView.setUint32(4, valueLower32);
18
- return bytes;
14
+ const dataView = new DataView(bytes.buffer);
15
+ const valueLower32 = value & 0xffffffff;
16
+ dataView.setUint32(0, 0);
17
+ dataView.setUint32(4, valueLower32);
18
+ return bytes;
19
19
  }
20
20
  export function readUint64BigEndian(bytes) {
21
- const dataView = new DataView(bytes.buffer);
22
- return dataView.getUint32(4);
23
- }
21
+ const dataView = new DataView(bytes.buffer);
22
+ return dataView.getUint32(4);
23
+ }