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