@ethersphere/bee-js 8.3.1 → 9.0.2

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 (224) hide show
  1. package/README.md +192 -50
  2. package/dist/cjs/bee-dev.js +78 -0
  3. package/dist/cjs/bee.js +341 -417
  4. package/dist/cjs/chunk/bmt.js +15 -32
  5. package/dist/cjs/chunk/cac.js +26 -36
  6. package/dist/cjs/chunk/soc.js +56 -51
  7. package/dist/cjs/feed/identifier.js +3 -28
  8. package/dist/cjs/feed/index.js +95 -44
  9. package/dist/cjs/feed/retrievable.js +11 -22
  10. package/dist/cjs/index.js +17 -1
  11. package/dist/cjs/manifest/manifest.js +369 -0
  12. package/dist/cjs/modules/bytes.js +24 -12
  13. package/dist/cjs/modules/bzz.js +24 -34
  14. package/dist/cjs/modules/chunk.js +13 -7
  15. package/dist/cjs/modules/debug/balance.js +29 -4
  16. package/dist/cjs/modules/debug/chequebook.js +60 -16
  17. package/dist/cjs/modules/debug/connectivity.js +82 -4
  18. package/dist/cjs/modules/debug/settlements.js +22 -2
  19. package/dist/cjs/modules/debug/stake.js +29 -11
  20. package/dist/cjs/modules/debug/stamps.js +88 -7
  21. package/dist/cjs/modules/debug/states.js +25 -3
  22. package/dist/cjs/modules/debug/status.js +45 -47
  23. package/dist/cjs/modules/debug/transactions.js +27 -5
  24. package/dist/cjs/modules/envelope.js +8 -6
  25. package/dist/cjs/modules/feed.js +25 -10
  26. package/dist/cjs/modules/grantee.js +18 -12
  27. package/dist/cjs/modules/gsoc.js +24 -0
  28. package/dist/cjs/modules/pinning.js +13 -2
  29. package/dist/cjs/modules/pss.js +9 -3
  30. package/dist/cjs/modules/soc.js +9 -4
  31. package/dist/cjs/modules/stewardship.js +7 -3
  32. package/dist/cjs/modules/tag.js +35 -3
  33. package/dist/cjs/package.json +1 -0
  34. package/dist/cjs/stamper/stamper.js +43 -0
  35. package/dist/cjs/types/debug.js +16 -1
  36. package/dist/cjs/types/index.js +2 -24
  37. package/dist/cjs/utils/bytes.js +67 -115
  38. package/dist/cjs/utils/chunk-size.js +17 -0
  39. package/dist/cjs/utils/chunk-stream.browser.js +85 -0
  40. package/dist/cjs/utils/chunk-stream.js +84 -0
  41. package/dist/cjs/utils/cid.js +5 -6
  42. package/dist/cjs/utils/collection.browser.js +2 -2
  43. package/dist/cjs/utils/collection.js +3 -2
  44. package/dist/cjs/utils/collection.node.js +0 -2
  45. package/dist/cjs/utils/constants.js +7 -3
  46. package/dist/cjs/utils/data.browser.js +6 -3
  47. package/dist/cjs/utils/data.js +8 -4
  48. package/dist/cjs/utils/duration.js +51 -0
  49. package/dist/cjs/utils/expose.js +11 -40
  50. package/dist/cjs/utils/headers.js +79 -52
  51. package/dist/cjs/utils/http.js +34 -10
  52. package/dist/cjs/utils/mime.js +78 -0
  53. package/dist/cjs/utils/pss.js +3 -4
  54. package/dist/cjs/utils/redundancy.js +18 -14
  55. package/dist/cjs/utils/resource-locator.js +17 -0
  56. package/dist/cjs/utils/size.js +35 -0
  57. package/dist/cjs/utils/stamps.js +67 -51
  58. package/dist/cjs/utils/tar-uploader.browser.js +2 -2
  59. package/dist/cjs/utils/tar-uploader.js +2 -2
  60. package/dist/cjs/utils/tokens.js +144 -0
  61. package/dist/cjs/utils/type.js +142 -350
  62. package/dist/cjs/utils/typed-bytes.js +179 -0
  63. package/dist/cjs/utils/upload-progress.js +2 -0
  64. package/dist/cjs/utils/url.js +0 -4
  65. package/dist/cjs/utils/workaround.js +27 -0
  66. package/dist/index.browser.min.js +1 -2
  67. package/dist/index.browser.min.js.map +1 -1
  68. package/dist/mjs/bee-dev.js +98 -0
  69. package/dist/mjs/bee.js +367 -411
  70. package/dist/mjs/chunk/bmt.js +13 -29
  71. package/dist/mjs/chunk/cac.js +26 -34
  72. package/dist/mjs/chunk/soc.js +57 -53
  73. package/dist/mjs/feed/identifier.js +3 -26
  74. package/dist/mjs/feed/index.js +98 -51
  75. package/dist/mjs/feed/retrievable.js +12 -23
  76. package/dist/mjs/index.js +10 -1
  77. package/dist/mjs/manifest/manifest.js +371 -0
  78. package/dist/mjs/modules/bytes.js +27 -15
  79. package/dist/mjs/modules/bzz.js +25 -32
  80. package/dist/mjs/modules/chunk.js +16 -8
  81. package/dist/mjs/modules/debug/balance.js +61 -4
  82. package/dist/mjs/modules/debug/chequebook.js +116 -16
  83. package/dist/mjs/modules/debug/connectivity.js +144 -3
  84. package/dist/mjs/modules/debug/settlements.js +46 -2
  85. package/dist/mjs/modules/debug/stake.js +69 -11
  86. package/dist/mjs/modules/debug/stamps.js +184 -7
  87. package/dist/mjs/modules/debug/states.js +55 -3
  88. package/dist/mjs/modules/debug/status.js +97 -45
  89. package/dist/mjs/modules/debug/transactions.js +61 -5
  90. package/dist/mjs/modules/envelope.js +11 -9
  91. package/dist/mjs/modules/feed.js +26 -10
  92. package/dist/mjs/modules/grantee.js +35 -13
  93. package/dist/mjs/modules/gsoc.js +16 -0
  94. package/dist/mjs/modules/pinning.js +23 -2
  95. package/dist/mjs/modules/pss.js +10 -4
  96. package/dist/mjs/modules/soc.js +10 -5
  97. package/dist/mjs/modules/stewardship.js +14 -4
  98. package/dist/mjs/modules/tag.js +93 -3
  99. package/dist/mjs/package.json +2 -1
  100. package/dist/mjs/stamper/stamper.js +39 -0
  101. package/dist/mjs/types/debug.js +15 -1
  102. package/dist/mjs/types/index.js +2 -24
  103. package/dist/mjs/utils/bytes.js +63 -104
  104. package/dist/mjs/utils/chunk-size.js +13 -0
  105. package/dist/mjs/utils/chunk-stream.browser.js +85 -0
  106. package/dist/mjs/utils/chunk-stream.js +87 -0
  107. package/dist/mjs/utils/cid.js +5 -6
  108. package/dist/mjs/utils/collection.browser.js +2 -2
  109. package/dist/mjs/utils/collection.js +2 -2
  110. package/dist/mjs/utils/collection.node.js +0 -2
  111. package/dist/mjs/utils/constants.js +6 -2
  112. package/dist/mjs/utils/data.browser.js +9 -3
  113. package/dist/mjs/utils/data.js +12 -4
  114. package/dist/mjs/utils/duration.js +47 -0
  115. package/dist/mjs/utils/expose.js +2 -7
  116. package/dist/mjs/utils/headers.js +73 -48
  117. package/dist/mjs/utils/http.js +33 -11
  118. package/dist/mjs/utils/mime.js +75 -0
  119. package/dist/mjs/utils/pss.js +3 -4
  120. package/dist/mjs/utils/redundancy.js +18 -8
  121. package/dist/mjs/utils/resource-locator.js +13 -0
  122. package/dist/mjs/utils/size.js +31 -0
  123. package/dist/mjs/utils/stamps.js +47 -44
  124. package/dist/mjs/utils/tar-uploader.browser.js +2 -2
  125. package/dist/mjs/utils/tar-uploader.js +2 -2
  126. package/dist/mjs/utils/tokens.js +139 -0
  127. package/dist/mjs/utils/type.js +216 -310
  128. package/dist/mjs/utils/typed-bytes.js +160 -0
  129. package/dist/mjs/utils/upload-progress.js +1 -0
  130. package/dist/mjs/utils/url.js +0 -4
  131. package/dist/mjs/utils/workaround.js +22 -0
  132. package/dist/types/bee-dev.d.ts +5 -0
  133. package/dist/types/bee.d.ts +88 -165
  134. package/dist/types/chunk/bmt.d.ts +2 -2
  135. package/dist/types/chunk/cac.d.ts +7 -24
  136. package/dist/types/chunk/soc.d.ts +15 -15
  137. package/dist/types/feed/identifier.d.ts +2 -4
  138. package/dist/types/feed/index.d.ts +14 -18
  139. package/dist/types/feed/retrievable.d.ts +3 -4
  140. package/dist/types/index.d.ts +28 -1
  141. package/dist/types/manifest/manifest.d.ts +106 -0
  142. package/dist/types/modules/bytes.d.ts +8 -5
  143. package/dist/types/modules/bzz.d.ts +8 -10
  144. package/dist/types/modules/chunk.d.ts +4 -3
  145. package/dist/types/modules/debug/balance.d.ts +3 -2
  146. package/dist/types/modules/debug/chequebook.d.ts +7 -6
  147. package/dist/types/modules/debug/connectivity.d.ts +5 -3
  148. package/dist/types/modules/debug/settlements.d.ts +2 -1
  149. package/dist/types/modules/debug/stake.d.ts +4 -2
  150. package/dist/types/modules/debug/stamps.d.ts +5 -4
  151. package/dist/types/modules/debug/status.d.ts +6 -25
  152. package/dist/types/modules/debug/transactions.d.ts +5 -4
  153. package/dist/types/modules/envelope.d.ts +3 -2
  154. package/dist/types/modules/feed.d.ts +20 -16
  155. package/dist/types/modules/grantee.d.ts +7 -6
  156. package/dist/types/modules/gsoc.d.ts +7 -0
  157. package/dist/types/modules/pinning.d.ts +2 -4
  158. package/dist/types/modules/pss.d.ts +4 -3
  159. package/dist/types/modules/soc.d.ts +3 -2
  160. package/dist/types/modules/stewardship.d.ts +4 -4
  161. package/dist/types/modules/tag.d.ts +2 -1
  162. package/dist/types/stamper/stamper.d.ts +15 -0
  163. package/dist/types/types/debug.d.ts +63 -115
  164. package/dist/types/types/index.d.ts +103 -204
  165. package/dist/types/utils/bytes.d.ts +16 -90
  166. package/dist/types/utils/chunk-size.d.ts +1 -0
  167. package/dist/types/utils/chunk-stream.browser.d.ts +6 -0
  168. package/dist/types/utils/chunk-stream.d.ts +6 -0
  169. package/dist/types/utils/cid.d.ts +3 -2
  170. package/dist/types/utils/collection.browser.d.ts +2 -2
  171. package/dist/types/utils/collection.d.ts +2 -1
  172. package/dist/types/utils/collection.node.d.ts +0 -1
  173. package/dist/types/utils/constants.d.ts +4 -1
  174. package/dist/types/utils/duration.d.ts +17 -0
  175. package/dist/types/utils/error.d.ts +2 -2
  176. package/dist/types/utils/expose.d.ts +2 -7
  177. package/dist/types/utils/headers.d.ts +3 -4
  178. package/dist/types/utils/mime.d.ts +1 -0
  179. package/dist/types/utils/pss.d.ts +2 -2
  180. package/dist/types/utils/resource-locator.d.ts +6 -0
  181. package/dist/types/utils/size.d.ts +16 -0
  182. package/dist/types/utils/stamps.d.ts +27 -33
  183. package/dist/types/utils/tar-uploader.browser.d.ts +3 -4
  184. package/dist/types/utils/tar-uploader.d.ts +3 -4
  185. package/dist/types/utils/tokens.d.ts +77 -0
  186. package/dist/types/utils/type.d.ts +20 -52
  187. package/dist/types/utils/typed-bytes.d.ts +68 -0
  188. package/dist/types/utils/upload-progress.d.ts +4 -0
  189. package/dist/types/utils/workaround.d.ts +2 -0
  190. package/package.json +11 -17
  191. package/dist/cjs/chunk/signer.js +0 -126
  192. package/dist/cjs/chunk/span.js +0 -25
  193. package/dist/cjs/feed/json.js +0 -28
  194. package/dist/cjs/feed/topic.js +0 -25
  195. package/dist/cjs/feed/type.js +0 -15
  196. package/dist/cjs/modules/debug/chunk.js +0 -21
  197. package/dist/cjs/modules/debug/tag.js +0 -19
  198. package/dist/cjs/utils/eth.js +0 -216
  199. package/dist/cjs/utils/hash.js +0 -21
  200. package/dist/cjs/utils/hex.js +0 -150
  201. package/dist/cjs/utils/reference.js +0 -36
  202. package/dist/index.browser.min.js.LICENSE.txt +0 -8
  203. package/dist/mjs/chunk/signer.js +0 -114
  204. package/dist/mjs/chunk/span.js +0 -21
  205. package/dist/mjs/feed/json.js +0 -26
  206. package/dist/mjs/feed/topic.js +0 -19
  207. package/dist/mjs/feed/type.js +0 -10
  208. package/dist/mjs/modules/debug/chunk.js +0 -17
  209. package/dist/mjs/modules/debug/tag.js +0 -15
  210. package/dist/mjs/utils/eth.js +0 -192
  211. package/dist/mjs/utils/hash.js +0 -16
  212. package/dist/mjs/utils/hex.js +0 -135
  213. package/dist/mjs/utils/reference.js +0 -29
  214. package/dist/types/chunk/signer.d.ts +0 -31
  215. package/dist/types/chunk/span.d.ts +0 -10
  216. package/dist/types/feed/json.d.ts +0 -4
  217. package/dist/types/feed/topic.d.ts +0 -3
  218. package/dist/types/feed/type.d.ts +0 -6
  219. package/dist/types/modules/debug/chunk.d.ts +0 -10
  220. package/dist/types/modules/debug/tag.d.ts +0 -8
  221. package/dist/types/utils/eth.d.ts +0 -67
  222. package/dist/types/utils/hash.d.ts +0 -9
  223. package/dist/types/utils/hex.d.ts +0 -86
  224. package/dist/types/utils/reference.d.ts +0 -2
@@ -1,331 +1,159 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.assertTransactionHash = exports.makeTagUid = exports.assertAllTagsOptions = exports.assertFileData = exports.assertData = exports.assertCashoutOptions = exports.assertTransactionOptions = 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.addCidConversionFunction = exports.makeReferenceOrEns = exports.assertReferenceOrEns = exports.assertReference = exports.assertPositiveInteger = exports.assertNonNegativeInteger = exports.assertInteger = exports.assertBoolean = exports.assertStrictlyObject = exports.isError = exports.isStrictlyObject = exports.isObject = exports.isInteger = exports.isReadable = void 0;
4
- const stream_1 = require("stream");
26
+ exports.makeTagUid = exports.prepareAllTagsOptions = exports.assertFileData = exports.assertData = exports.prepareTransactionOptions = exports.preparePostageBatchOptions = exports.prepareGsocMessageHandler = exports.preparePssMessageHandler = exports.isTag = exports.prepareCollectionUploadOptions = exports.prepareFileUploadOptions = exports.prepareRedundantUploadOptions = exports.prepareUploadOptions = exports.prepareDownloadOptions = exports.prepareBeeRequestOptions = exports.asNumberString = exports.isReadable = void 0;
27
+ const cafe_utility_1 = require("cafe-utility");
28
+ const stream = __importStar(require("stream"));
5
29
  const types_1 = require("../types");
6
- const cid_1 = require("./cid");
7
- const error_1 = require("./error");
8
30
  const file_1 = require("./file");
9
- const hex_1 = require("./hex");
10
- function isReadable(obj) {
11
- return typeof stream_1.Readable !== 'undefined' && obj instanceof stream_1.Readable;
31
+ const typed_bytes_1 = require("./typed-bytes");
32
+ function isReadable(value) {
33
+ return typeof stream.Readable !== 'undefined' && value instanceof stream.Readable;
12
34
  }
13
35
  exports.isReadable = isReadable;
14
- function isInteger(value) {
15
- return ((typeof value === 'string' && /^-?(0|[1-9][0-9]*)$/g.test(value)) ||
16
- (typeof value === 'number' &&
17
- value > Number.MIN_SAFE_INTEGER &&
18
- value < Number.MAX_SAFE_INTEGER &&
19
- Number.isInteger(value)));
20
- }
21
- exports.isInteger = isInteger;
22
- function isObject(value) {
23
- return value !== null && typeof value === 'object';
24
- }
25
- exports.isObject = isObject;
26
- function isStrictlyObject(value) {
27
- return isObject(value) && !Array.isArray(value);
28
- }
29
- exports.isStrictlyObject = isStrictlyObject;
30
- /**
31
- * Asserts if object is Error
32
- *
33
- * @param e
34
- */
35
- function isError(e) {
36
- return e instanceof Error;
37
- }
38
- exports.isError = isError;
39
- // eslint-disable-next-line @typescript-eslint/ban-types
40
- function assertStrictlyObject(value, name = 'value') {
41
- if (!isStrictlyObject(value)) {
42
- throw new TypeError(`${name} has to be an object that is not null nor array!`);
36
+ function asNumberString(value, options) {
37
+ if (typeof value === 'bigint') {
38
+ value = value.toString();
43
39
  }
40
+ return cafe_utility_1.Types.asIntegerString(value, options);
44
41
  }
45
- exports.assertStrictlyObject = assertStrictlyObject;
46
- function assertBoolean(value, name = 'value') {
47
- if (value !== true && value !== false)
48
- throw new TypeError(`${name} is not boolean`);
49
- }
50
- exports.assertBoolean = assertBoolean;
51
- function assertInteger(value, name = 'value') {
52
- if (!isInteger(value))
53
- throw new TypeError(`${name} is not integer`);
54
- }
55
- exports.assertInteger = assertInteger;
56
- function assertNonNegativeInteger(value, name = 'Value') {
57
- assertInteger(value, name);
58
- if (Number(value) < 0)
59
- throw new error_1.BeeArgumentError(`${name} has to be bigger or equal to zero`, value);
60
- }
61
- exports.assertNonNegativeInteger = assertNonNegativeInteger;
62
- function assertPositiveInteger(value, name = 'Value') {
63
- assertInteger(value, name);
64
- if (Number(value) <= 0)
65
- throw new error_1.BeeArgumentError(`${name} has to be bigger then zero`, value);
66
- }
67
- exports.assertPositiveInteger = assertPositiveInteger;
68
- function assertReference(value) {
69
- try {
70
- (0, hex_1.assertHexString)(value, types_1.REFERENCE_HEX_LENGTH);
71
- }
72
- catch (e) {
73
- (0, hex_1.assertHexString)(value, types_1.ENCRYPTED_REFERENCE_HEX_LENGTH);
74
- }
75
- }
76
- exports.assertReference = assertReference;
77
- function assertReferenceOrEns(value) {
78
- if (typeof value !== 'string') {
79
- throw new TypeError('ReferenceOrEns has to be a string!');
80
- }
81
- if ((0, hex_1.isHexString)(value)) {
82
- assertReference(value);
83
- return;
84
- }
85
- /**
86
- * a.asdf - VALID
87
- * test.eth - VALID
88
- * ADAM.ETH - VALID
89
- * ADAM UHLIR.ETH - INVALID
90
- * test.whatever.eth - VALID
91
- * -adg.ets - INVALID
92
- * adg-.ets - INVALID
93
- * as-a.com - VALID
94
- * ethswarm.org - VALID
95
- * http://asdf.asf - INVALID
96
- * řš+ýí.šě+ř.čě - VALID
97
- * tsg.asg?asg - INVALID
98
- * tsg.asg:1599 - INVALID
99
- * ethswarm.something- - INVALID
100
- * ethswarm.-something - INVALID
101
- * ethswarm.some-thing - VALID
102
- *
103
- * The idea of this regex is to match strings that are 1 to 63 characters long and do not start or end with dash character
104
- *
105
- * This part matches 2-63 character string that does not start or end with -
106
- * [^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s] <regexp1>
107
- *
108
- * For 1 character long string we use the part after |
109
- * [^-.\/?:\s] <regexp2>
110
- *
111
- * This is terminated in a group with . character an repeated at least once
112
- * (<regexp1>|<regexp2>\.)+
113
- *
114
- * This covers everything but top level domain which is 2 to 63 characters long so we can just use the <regexp2> again
115
- * ^(<regexp1>|<regexp2>\.)+<regexp1>$
116
- */
117
- const DOMAIN_REGEX = /^(?:(?:[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]|[^-.\/?:\s]{1,2})\.)+[^-.\/?:\s][^.\/?:\s]{0,61}[^-.\/?:\s]$/;
118
- // We are doing best-effort validation of domain here. The proper way would be to do validation using IDNA UTS64 standard
119
- // but that would give us high penalty to our dependencies as the library (idna-uts46-hx) that does this validation and translation
120
- // adds 160kB minified size which is significant. We expects that full validation will be done on Bee side.
121
- if (!DOMAIN_REGEX.test(value)) {
122
- throw new TypeError('ReferenceOrEns is not valid Reference, but also not valid ENS domain.');
123
- }
124
- }
125
- exports.assertReferenceOrEns = assertReferenceOrEns;
126
- /**
127
- * Function that mainly converts Swarm CID into hex encoded Swarm Reference
128
- *
129
- * @param value
130
- * @param expectedCidType
131
- */
132
- function makeReferenceOrEns(value, expectedCidType) {
133
- if (typeof value !== 'string') {
134
- throw new TypeError('ReferenceCidOrEns has to be a string!');
135
- }
136
- try {
137
- const result = (0, cid_1.convertCidToReference)(value);
138
- if (result.type !== expectedCidType) {
139
- throw new error_1.BeeError(`CID was expected to be of type ${expectedCidType}, but got instead ${result.type ?? 'non-Swarm CID'}`);
140
- }
141
- return result.reference;
142
- }
143
- catch (e) {
144
- if (e instanceof error_1.BeeError)
145
- throw e;
146
- }
147
- assertReferenceOrEns(value);
148
- return value;
149
- }
150
- exports.makeReferenceOrEns = makeReferenceOrEns;
151
- /**
152
- * Function that adds getter which converts the reference into CID base32 encoded string.
153
- * @param result
154
- * @param cidType feed or manifest
155
- */
156
- function addCidConversionFunction(result, cidType) {
42
+ exports.asNumberString = asNumberString;
43
+ function prepareBeeRequestOptions(value) {
44
+ const object = cafe_utility_1.Types.asObject(value, { name: 'BeeRequestOptions' });
157
45
  return {
158
- ...result,
159
- cid() {
160
- return (0, cid_1.convertReferenceToCid)(result.reference, cidType);
161
- },
46
+ baseURL: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'baseURL' }), object.baseURL),
47
+ timeout: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'timeout', min: 0 }), object.timeout),
48
+ headers: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asStringMap(x, { name: 'headers' }), object.headers),
49
+ onRequest: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asFunction(x, { name: 'onRequest' }), object.onRequest),
50
+ httpAgent: object.httpAgent,
51
+ httpsAgent: object.httpsAgent,
52
+ endlesslyRetry: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'endlesslyRetry' }), object.endlesslyRetry),
162
53
  };
163
54
  }
164
- exports.addCidConversionFunction = addCidConversionFunction;
165
- function assertAddress(value) {
166
- (0, hex_1.assertHexString)(value, types_1.ADDRESS_HEX_LENGTH, 'Address');
167
- }
168
- exports.assertAddress = assertAddress;
169
- function assertBatchId(value) {
170
- (0, hex_1.assertHexString)(value, types_1.BATCH_ID_HEX_LENGTH, 'BatchId');
55
+ exports.prepareBeeRequestOptions = prepareBeeRequestOptions;
56
+ function prepareDownloadOptions(value) {
57
+ const object = cafe_utility_1.Types.asObject(value, { name: 'DownloadOptions' });
58
+ return {
59
+ redundancyStrategy: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyStrategy' }), object.redundancyStrategy),
60
+ fallback: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'fallback' }), object.fallback),
61
+ timeoutMs: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'timeoutMs', min: 0 }), object.timeoutMs),
62
+ actPublisher: cafe_utility_1.Types.asOptional(x => new typed_bytes_1.PublicKey(x), object.actPublisher),
63
+ actHistoryAddress: cafe_utility_1.Types.asOptional(x => new typed_bytes_1.Reference(x), object.actHistoryAddress),
64
+ actTimestamp: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asNumber(x, { name: 'actTimestamp' }), object.actTimestamp),
65
+ };
171
66
  }
172
- exports.assertBatchId = assertBatchId;
173
- function assertRequestOptions(value, name = 'RequestOptions') {
174
- if (value === undefined) {
175
- return;
176
- }
177
- if (!isStrictlyObject(value)) {
178
- throw new TypeError(`${name} has to be an object!`);
179
- }
180
- const options = value;
181
- if (options.timeout) {
182
- assertNonNegativeInteger(options.timeout, `${name}.timeout`);
183
- }
67
+ exports.prepareDownloadOptions = prepareDownloadOptions;
68
+ function prepareUploadOptions(value, name = 'UploadOptions') {
69
+ const object = cafe_utility_1.Types.asObject(value, { name });
70
+ return {
71
+ act: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'act' }), object.act),
72
+ actHistoryAddress: cafe_utility_1.Types.asOptional(x => new typed_bytes_1.Reference(x), object.actHistoryAddress),
73
+ deferred: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'deferred' }), object.deferred),
74
+ encrypt: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'encrypt' }), object.encrypt),
75
+ pin: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'pin' }), object.pin),
76
+ tag: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'tag', min: 0 }), object.tag),
77
+ };
184
78
  }
185
- exports.assertRequestOptions = assertRequestOptions;
186
- function assertUploadOptions(value, name = 'UploadOptions') {
187
- if (!isStrictlyObject(value)) {
188
- throw new TypeError(`${name} has to be an object!`);
189
- }
190
- assertRequestOptions(value, name);
191
- const options = value;
192
- if (options.pin && typeof options.pin !== 'boolean') {
193
- throw new TypeError(`options.pin property in ${name} has to be boolean or undefined!`);
194
- }
195
- if (options.encrypt && typeof options.encrypt !== 'boolean') {
196
- throw new TypeError(`options.encrypt property in ${name} has to be boolean or undefined!`);
197
- }
198
- if (options.tag) {
199
- if (typeof options.tag !== 'number') {
200
- throw new TypeError(`options.tag property in ${name} has to be number or undefined!`);
201
- }
202
- assertNonNegativeInteger(options.tag, 'options.tag');
203
- }
79
+ exports.prepareUploadOptions = prepareUploadOptions;
80
+ function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
81
+ const uploadOptions = prepareUploadOptions(value, name);
82
+ const object = cafe_utility_1.Types.asObject(value, { name });
83
+ return {
84
+ ...uploadOptions,
85
+ redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
86
+ };
204
87
  }
205
- exports.assertUploadOptions = assertUploadOptions;
206
- function assertFileUploadOptions(value) {
207
- assertUploadOptions(value, 'FileUploadOptions');
208
- const options = value;
209
- if (options.size) {
210
- if (typeof options.size !== 'number') {
211
- throw new TypeError('tag property in FileUploadOptions has to be number or undefined!');
212
- }
213
- assertNonNegativeInteger(options.size, 'options.size');
214
- }
215
- if (options.contentType && typeof options.contentType !== 'string') {
216
- throw new TypeError('contentType property in FileUploadOptions has to be string or undefined!');
217
- }
88
+ exports.prepareRedundantUploadOptions = prepareRedundantUploadOptions;
89
+ function prepareFileUploadOptions(value) {
90
+ const uploadOptions = prepareUploadOptions(value, 'FileUploadOptions');
91
+ const object = cafe_utility_1.Types.asObject(value, { name: 'FileUploadOptions' });
92
+ return {
93
+ ...uploadOptions,
94
+ size: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'size', min: 0 }), object.size),
95
+ contentType: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'contentType' }), object.contentType),
96
+ redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
97
+ };
218
98
  }
219
- exports.assertFileUploadOptions = assertFileUploadOptions;
220
- function assertCollectionUploadOptions(value) {
221
- assertUploadOptions(value, 'CollectionUploadOptions');
222
- const options = value;
223
- if (options.indexDocument && typeof options.indexDocument !== 'string') {
224
- throw new TypeError('indexDocument property in CollectionUploadOptions has to be string or undefined!');
225
- }
226
- if (options.errorDocument && typeof options.errorDocument !== 'string') {
227
- throw new TypeError('errorDocument property in CollectionUploadOptions has to be string or undefined!');
228
- }
99
+ exports.prepareFileUploadOptions = prepareFileUploadOptions;
100
+ function prepareCollectionUploadOptions(value) {
101
+ const uploadOptions = prepareUploadOptions(value, 'CollectionUploadOptions');
102
+ const object = cafe_utility_1.Types.asObject(value, { name: 'CollectionUploadOptions' });
103
+ return {
104
+ ...uploadOptions,
105
+ errorDocument: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'errorDocument' }), object.errorDocument),
106
+ indexDocument: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'indexDocument' }), object.indexDocument),
107
+ redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
108
+ };
229
109
  }
230
- exports.assertCollectionUploadOptions = assertCollectionUploadOptions;
110
+ exports.prepareCollectionUploadOptions = prepareCollectionUploadOptions;
231
111
  function isTag(value) {
232
- if (!isStrictlyObject(value)) {
112
+ try {
113
+ const object = cafe_utility_1.Types.asObject(value, { name: 'Tag' });
114
+ cafe_utility_1.Types.asInteger(object.uid, { name: 'Tag.uid' });
115
+ return true;
116
+ }
117
+ catch {
233
118
  return false;
234
119
  }
235
- return Boolean(value.uid);
236
120
  }
237
121
  exports.isTag = isTag;
238
- function assertTag(value) {
239
- if (!isStrictlyObject(value)) {
240
- throw new TypeError('Tag is not an object!');
241
- }
242
- const tag = value;
243
- const numberProperties = ['total', 'processed', 'synced', 'uid'];
244
- for (const numberProperty of numberProperties) {
245
- if (!tag[numberProperty]) {
246
- throw new TypeError(`Tag's property '${numberProperty}' has to be specified!`);
247
- }
248
- if (typeof tag[numberProperty] !== 'number') {
249
- throw new TypeError(`Tag's property '${numberProperty}' has to be number!`);
250
- }
251
- }
252
- if (!tag.startedAt) {
253
- throw new TypeError("Tag's property 'startedAt' has to be specified!");
254
- }
255
- if (typeof tag.startedAt !== 'string') {
256
- throw new TypeError("Tag's property 'startedAt' has to be string!");
257
- }
258
- }
259
- exports.assertTag = assertTag;
260
- function assertAddressPrefix(value) {
261
- (0, hex_1.assertHexString)(value, undefined, 'AddressPrefix');
262
- if (value.length > types_1.PSS_TARGET_HEX_LENGTH_MAX) {
263
- 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);
264
- }
265
- }
266
- exports.assertAddressPrefix = assertAddressPrefix;
267
- function assertPssMessageHandler(value) {
268
- if (!isStrictlyObject(value)) {
269
- throw new TypeError('PssMessageHandler has to be object!');
270
- }
271
- const handler = value;
272
- if (typeof handler.onMessage !== 'function') {
273
- throw new TypeError('onMessage property of PssMessageHandler has to be function!');
274
- }
275
- if (typeof handler.onError !== 'function') {
276
- throw new TypeError('onError property of PssMessageHandler has to be function!');
277
- }
278
- }
279
- exports.assertPssMessageHandler = assertPssMessageHandler;
280
- function assertPublicKey(value) {
281
- (0, hex_1.assertHexString)(value, types_1.PUBKEY_HEX_LENGTH, 'PublicKey');
122
+ function preparePssMessageHandler(value) {
123
+ const object = cafe_utility_1.Types.asObject(value, { name: 'PssMessageHandler' });
124
+ return {
125
+ onMessage: cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' }),
126
+ onError: cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' }),
127
+ };
282
128
  }
283
- exports.assertPublicKey = assertPublicKey;
284
- function assertPostageBatchOptions(value) {
285
- if (value === undefined) {
286
- return;
287
- }
288
- assertStrictlyObject(value);
289
- const options = value;
290
- assertRequestOptions(options, 'PostageBatchOptions');
291
- if (options?.gasPrice) {
292
- assertNonNegativeInteger(options.gasPrice);
293
- }
294
- if (options?.immutableFlag !== undefined) {
295
- assertBoolean(options.immutableFlag);
296
- }
297
- if (options?.waitForUsable !== undefined) {
298
- assertBoolean(options.waitForUsable);
299
- }
300
- if (options?.waitForUsableTimeout !== undefined) {
301
- assertNonNegativeInteger(options.waitForUsableTimeout, 'options.waitForUsableTimeout');
302
- }
129
+ exports.preparePssMessageHandler = preparePssMessageHandler;
130
+ function prepareGsocMessageHandler(value) {
131
+ const object = cafe_utility_1.Types.asObject(value, { name: 'GsocMessageHandler' });
132
+ return {
133
+ onMessage: cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' }),
134
+ onError: cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' }),
135
+ };
303
136
  }
304
- exports.assertPostageBatchOptions = assertPostageBatchOptions;
305
- function assertTransactionOptions(value, name = 'TransactionOptions') {
306
- if (value === undefined) {
307
- return;
308
- }
309
- assertStrictlyObject(value, name);
310
- const options = value;
311
- if (options?.gasLimit) {
312
- assertNonNegativeInteger(options.gasLimit, name);
313
- }
314
- if (options?.gasPrice) {
315
- assertNonNegativeInteger(options.gasPrice, name);
316
- }
137
+ exports.prepareGsocMessageHandler = prepareGsocMessageHandler;
138
+ function preparePostageBatchOptions(value) {
139
+ const object = cafe_utility_1.Types.asObject(value, { name: 'PostageBatchOptions' });
140
+ return {
141
+ gasPrice: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasPrice' }), object.gasPrice),
142
+ immutableFlag: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'immutableFlag' }), object.immutableFlag),
143
+ label: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asString(x, { name: 'label' }), object.label),
144
+ waitForUsable: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'waitForUsable' }), object.waitForUsable),
145
+ waitForUsableTimeout: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'waitForUsableTimeout', min: 0 }), object.waitForUsableTimeout),
146
+ };
317
147
  }
318
- exports.assertTransactionOptions = assertTransactionOptions;
319
- function assertCashoutOptions(value) {
320
- if (value === undefined) {
321
- return;
322
- }
323
- assertStrictlyObject(value);
324
- const options = value;
325
- assertRequestOptions(options, 'CashoutOptions');
326
- assertTransactionOptions(options, 'CashoutOptions');
148
+ exports.preparePostageBatchOptions = preparePostageBatchOptions;
149
+ function prepareTransactionOptions(value, name = 'TransactionOptions') {
150
+ const object = cafe_utility_1.Types.asObject(value, { name });
151
+ return {
152
+ gasLimit: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasLimit', min: 0n }), object.gasLimit),
153
+ gasPrice: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasPrice', min: 0n }), object.gasPrice),
154
+ };
327
155
  }
328
- exports.assertCashoutOptions = assertCashoutOptions;
156
+ exports.prepareTransactionOptions = prepareTransactionOptions;
329
157
  /**
330
158
  * Check whether the given parameter is valid data to upload
331
159
  * @param value
@@ -352,64 +180,28 @@ exports.assertFileData = assertFileData;
352
180
  * Checks whether optional options for AllTags query are valid
353
181
  * @param options
354
182
  */
355
- function assertAllTagsOptions(entry) {
356
- if (entry !== undefined && !isStrictlyObject(entry)) {
357
- throw new TypeError('options has to be an object or undefined!');
358
- }
359
- assertRequestOptions(entry, 'AllTagsOptions');
360
- const options = entry;
361
- if (options?.limit !== undefined) {
362
- if (typeof options.limit !== 'number') {
363
- throw new TypeError('AllTagsOptions.limit has to be a number or undefined!');
364
- }
365
- if (options.limit < types_1.TAGS_LIMIT_MIN) {
366
- throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at least ${types_1.TAGS_LIMIT_MIN}`, options.limit);
367
- }
368
- if (options.limit > types_1.TAGS_LIMIT_MAX) {
369
- throw new error_1.BeeArgumentError(`AllTagsOptions.limit has to be at most ${types_1.TAGS_LIMIT_MAX}`, options.limit);
370
- }
371
- }
372
- if (options?.offset !== undefined) {
373
- assertNonNegativeInteger(options.offset, 'AllTagsOptions.offset');
374
- }
183
+ function prepareAllTagsOptions(value) {
184
+ const object = cafe_utility_1.Types.asObject(value, { name: 'AllTagsOptions' });
185
+ return {
186
+ limit: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'limit', min: types_1.TAGS_LIMIT_MIN, max: types_1.TAGS_LIMIT_MAX }), object.limit),
187
+ offset: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'offset', min: 0 }), object.offset),
188
+ };
375
189
  }
376
- exports.assertAllTagsOptions = assertAllTagsOptions;
190
+ exports.prepareAllTagsOptions = prepareAllTagsOptions;
377
191
  /**
378
192
  * Utility functions that return Tag UID
379
193
  * @param tagUid
380
194
  */
381
195
  function makeTagUid(tagUid) {
382
196
  if (tagUid === undefined || tagUid === null) {
383
- throw new TypeError('TagUid was expected but got undefined or null instead!');
197
+ throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
384
198
  }
385
199
  if (isTag(tagUid)) {
386
200
  return tagUid.uid;
387
201
  }
388
- else if (typeof tagUid === 'number') {
389
- assertNonNegativeInteger(tagUid, 'UID');
390
- return tagUid;
391
- }
392
- else if (typeof tagUid === 'string') {
393
- const int = parseInt(tagUid);
394
- if (isNaN(int)) {
395
- throw new TypeError('Passed tagUid string is not valid integer!');
396
- }
397
- if (int < 0) {
398
- throw new TypeError(`TagUid was expected to be positive non-negative integer! Got ${int}`);
399
- }
400
- return int;
202
+ else if (typeof tagUid === 'number' || typeof tagUid === 'string') {
203
+ return cafe_utility_1.Types.asNumber(tagUid, { name: 'tagUid', min: 0 });
401
204
  }
402
- throw new TypeError('tagUid has to be either Tag or a number (UID)!');
205
+ throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
403
206
  }
404
207
  exports.makeTagUid = makeTagUid;
405
- function assertTransactionHash(transactionHash) {
406
- if (typeof transactionHash !== 'string') {
407
- throw new TypeError('TransactionHash has to be a string!');
408
- }
409
- (0, hex_1.assertPrefixedHexString)(transactionHash, 'TransactionHash');
410
- // Hash is 64 long + '0x' prefix = 66
411
- if (transactionHash.length !== 66) {
412
- throw new TypeError('TransactionHash has to be prefixed hex string with total length 66 (prefix including)');
413
- }
414
- }
415
- exports.assertTransactionHash = assertTransactionHash;