@upcoming/bee-js 9.9.1 → 11.1.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 (103) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/bee.js +881 -370
  3. package/dist/cjs/chunk/bmt.js +1 -2
  4. package/dist/cjs/chunk/cac.js +27 -32
  5. package/dist/cjs/chunk/soc.js +39 -31
  6. package/dist/cjs/feed/identifier.js +1 -2
  7. package/dist/cjs/feed/index.js +29 -19
  8. package/dist/cjs/feed/retrievable.js +1 -2
  9. package/dist/cjs/index.js +17 -7
  10. package/dist/cjs/manifest/manifest.js +19 -2
  11. package/dist/cjs/modules/bytes.js +4 -5
  12. package/dist/cjs/modules/bzz.js +4 -5
  13. package/dist/cjs/modules/chunk.js +2 -3
  14. package/dist/cjs/modules/debug/balance.js +4 -5
  15. package/dist/cjs/modules/debug/chequebook.js +9 -10
  16. package/dist/cjs/modules/debug/connectivity.js +7 -8
  17. package/dist/cjs/modules/debug/settlements.js +2 -3
  18. package/dist/cjs/modules/debug/stake.js +6 -7
  19. package/dist/cjs/modules/debug/stamps.js +24 -60
  20. package/dist/cjs/modules/debug/states.js +6 -6
  21. package/dist/cjs/modules/debug/status.js +9 -9
  22. package/dist/cjs/modules/debug/transactions.js +4 -5
  23. package/dist/cjs/modules/envelope.js +1 -2
  24. package/dist/cjs/modules/feed.js +3 -4
  25. package/dist/cjs/modules/grantee.js +3 -4
  26. package/dist/cjs/modules/gsoc.js +2 -3
  27. package/dist/cjs/modules/pinning.js +4 -5
  28. package/dist/cjs/modules/pss.js +2 -3
  29. package/dist/cjs/modules/rchash.js +1 -2
  30. package/dist/cjs/modules/soc.js +1 -2
  31. package/dist/cjs/modules/status.js +2 -3
  32. package/dist/cjs/modules/stewardship.js +2 -3
  33. package/dist/cjs/modules/tag.js +5 -6
  34. package/dist/cjs/types/debug.js +3 -3
  35. package/dist/cjs/types/index.js +11 -6
  36. package/dist/cjs/utils/bytes.js +23 -3
  37. package/dist/cjs/utils/chunk-size.js +1 -2
  38. package/dist/cjs/utils/chunk-stream.browser.js +30 -6
  39. package/dist/cjs/utils/chunk-stream.js +3 -4
  40. package/dist/cjs/utils/cid.js +3 -3
  41. package/dist/cjs/utils/collection.browser.js +2 -3
  42. package/dist/cjs/utils/collection.js +5 -6
  43. package/dist/cjs/utils/collection.node.js +2 -3
  44. package/dist/cjs/utils/data.browser.js +1 -2
  45. package/dist/cjs/utils/data.js +1 -2
  46. package/dist/cjs/utils/duration.js +27 -1
  47. package/dist/cjs/utils/expose.js +4 -1
  48. package/dist/cjs/utils/file.js +2 -3
  49. package/dist/cjs/utils/headers.js +2 -3
  50. package/dist/cjs/utils/http.js +25 -5
  51. package/dist/cjs/utils/pss.js +1 -2
  52. package/dist/cjs/utils/redundancy.js +3 -4
  53. package/dist/cjs/utils/size.js +25 -0
  54. package/dist/cjs/utils/stamps.js +60 -11
  55. package/dist/cjs/utils/tar-uploader.browser.js +1 -2
  56. package/dist/cjs/utils/tar-uploader.js +1 -2
  57. package/dist/cjs/utils/tar-writer.browser.js +1 -2
  58. package/dist/cjs/utils/tar-writer.js +1 -2
  59. package/dist/cjs/utils/type.js +37 -25
  60. package/dist/cjs/utils/url.js +3 -4
  61. package/dist/cjs/utils/workaround.js +7 -5
  62. package/dist/index.browser.min.js +1 -1
  63. package/dist/index.browser.min.js.map +1 -1
  64. package/dist/mjs/bee.js +864 -366
  65. package/dist/mjs/chunk/cac.js +21 -30
  66. package/dist/mjs/chunk/soc.js +16 -17
  67. package/dist/mjs/feed/index.js +7 -6
  68. package/dist/mjs/manifest/manifest.js +19 -2
  69. package/dist/mjs/modules/debug/chequebook.js +2 -2
  70. package/dist/mjs/modules/debug/stamps.js +38 -93
  71. package/dist/mjs/modules/debug/states.js +3 -0
  72. package/dist/mjs/modules/debug/status.js +1 -1
  73. package/dist/mjs/types/index.js +8 -3
  74. package/dist/mjs/utils/bytes.js +19 -2
  75. package/dist/mjs/utils/chunk-stream.browser.js +29 -5
  76. package/dist/mjs/utils/duration.js +27 -1
  77. package/dist/mjs/utils/expose.js +1 -1
  78. package/dist/mjs/utils/http.js +25 -3
  79. package/dist/mjs/utils/size.js +25 -0
  80. package/dist/mjs/utils/stamps.js +48 -0
  81. package/dist/mjs/utils/type.js +8 -1
  82. package/dist/mjs/utils/workaround.js +5 -2
  83. package/dist/types/bee.d.ts +756 -252
  84. package/dist/types/chunk/cac.d.ts +27 -13
  85. package/dist/types/chunk/soc.d.ts +43 -11
  86. package/dist/types/index.d.ts +3 -0
  87. package/dist/types/modules/bzz.d.ts +0 -1
  88. package/dist/types/modules/debug/stamps.d.ts +2 -2
  89. package/dist/types/modules/debug/status.d.ts +1 -1
  90. package/dist/types/modules/gsoc.d.ts +0 -1
  91. package/dist/types/modules/pss.d.ts +0 -1
  92. package/dist/types/types/debug.d.ts +2 -1
  93. package/dist/types/types/index.d.ts +53 -6
  94. package/dist/types/utils/constants.d.ts +3 -3
  95. package/dist/types/utils/duration.d.ts +24 -0
  96. package/dist/types/utils/error.d.ts +2 -2
  97. package/dist/types/utils/expose.d.ts +1 -1
  98. package/dist/types/utils/size.d.ts +23 -0
  99. package/dist/types/utils/stamps.d.ts +15 -1
  100. package/dist/types/utils/tar.browser.d.ts +1 -1
  101. package/dist/types/utils/tar.d.ts +0 -1
  102. package/dist/types/utils/type.d.ts +0 -1
  103. package/package.json +10 -13
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.http = exports.DEFAULT_HTTP_CONFIG = void 0;
6
+ exports.DEFAULT_HTTP_CONFIG = void 0;
7
+ exports.http = http;
7
8
  const axios_1 = __importDefault(require("axios"));
8
9
  const cafe_utility_1 = require("cafe-utility");
9
10
  const debug_1 = __importDefault(require("debug"));
@@ -14,6 +15,7 @@ const MAX_FAILED_ATTEMPTS = 100000;
14
15
  const DELAY_FAST = 200;
15
16
  const DELAY_SLOW = 1000;
16
17
  const DELAY_THRESHOLD = cafe_utility_1.Dates.minutes(1) / DELAY_FAST;
18
+ const ABORT_ERROR_MESSAGE = 'Request aborted';
17
19
  exports.DEFAULT_HTTP_CONFIG = {
18
20
  headers: {
19
21
  accept: 'application/json, text/plain, */*',
@@ -21,6 +23,11 @@ exports.DEFAULT_HTTP_CONFIG = {
21
23
  maxBodyLength: Infinity,
22
24
  maxContentLength: Infinity,
23
25
  };
26
+ function throwIfAborted(signal, config, responseData, responseStatus) {
27
+ if (signal?.aborted) {
28
+ throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', ABORT_ERROR_MESSAGE, responseData, responseStatus, 'ERR_CANCELED');
29
+ }
30
+ }
24
31
  /**
25
32
  * Main function to make HTTP requests.
26
33
  * @param options User defined settings
@@ -28,9 +35,11 @@ exports.DEFAULT_HTTP_CONFIG = {
28
35
  */
29
36
  async function http(options, config) {
30
37
  const requestConfig = cafe_utility_1.Objects.deepMerge3(exports.DEFAULT_HTTP_CONFIG, config, options);
31
- if (requestConfig.data && typeof Buffer !== 'undefined' && Buffer.isBuffer(requestConfig.data)) {
32
- requestConfig.data = requestConfig.data.buffer.slice(requestConfig.data.byteOffset, requestConfig.data.byteOffset + requestConfig.data.byteLength);
38
+ if (options.signal) {
39
+ requestConfig.signal = options.signal;
40
+ throwIfAborted(options.signal, config);
33
41
  }
42
+ maybeReplaceBodyBuffers(requestConfig);
34
43
  if (requestConfig.params) {
35
44
  const keys = Object.keys(requestConfig.params);
36
45
  for (const key of keys) {
@@ -42,6 +51,7 @@ async function http(options, config) {
42
51
  }
43
52
  let failedAttempts = 0;
44
53
  while (failedAttempts < MAX_FAILED_ATTEMPTS) {
54
+ throwIfAborted(options.signal, config);
45
55
  try {
46
56
  debug(`${requestConfig.method || 'get'} ${cafe_utility_1.Strings.joinUrl([
47
57
  requestConfig.baseURL,
@@ -53,12 +63,15 @@ async function http(options, config) {
53
63
  }
54
64
  catch (e) {
55
65
  if (e instanceof AxiosError) {
66
+ if (e.code === 'ERR_CANCELED') {
67
+ throwIfAborted({ aborted: true }, config, e.response?.data, e.response?.status);
68
+ }
56
69
  if (e.code === 'ECONNABORTED' && options.endlesslyRetry) {
57
70
  failedAttempts++;
58
71
  await cafe_utility_1.System.sleepMillis(failedAttempts < DELAY_THRESHOLD ? DELAY_FAST : DELAY_SLOW);
59
72
  }
60
73
  else {
61
- throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.code);
74
+ throw new index_1.BeeResponseError(config.method || 'get', config.url || '<unknown>', e.message, e.response?.data, e.response?.status, e.response?.statusText);
62
75
  }
63
76
  }
64
77
  else {
@@ -68,7 +81,6 @@ async function http(options, config) {
68
81
  }
69
82
  throw Error('Max number of failed attempts reached');
70
83
  }
71
- exports.http = http;
72
84
  function maybeRunOnRequestHook(options, requestConfig) {
73
85
  if (options.onRequest) {
74
86
  options.onRequest({
@@ -79,3 +91,11 @@ function maybeRunOnRequestHook(options, requestConfig) {
79
91
  });
80
92
  }
81
93
  }
94
+ function maybeReplaceBodyBuffers(config) {
95
+ if (config.data && config.data instanceof Uint8Array) {
96
+ config.data = config.data.buffer.slice(config.data.byteOffset, config.data.byteOffset + config.data.byteLength);
97
+ }
98
+ if (config.data && typeof Buffer !== 'undefined' && Buffer.isBuffer(config.data)) {
99
+ config.data = config.data.buffer.slice(config.data.byteOffset, config.data.byteOffset + config.data.byteLength);
100
+ }
101
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.makeMaxTarget = void 0;
3
+ exports.makeMaxTarget = makeMaxTarget;
4
4
  const types_1 = require("../types");
5
5
  const typed_bytes_1 = require("./typed-bytes");
6
6
  /**
@@ -14,4 +14,3 @@ function makeMaxTarget(target) {
14
14
  target = new typed_bytes_1.PeerAddress(target);
15
15
  return target.toHex().slice(0, types_1.PSS_TARGET_HEX_LENGTH_MAX);
16
16
  }
17
- exports.makeMaxTarget = makeMaxTarget;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getRedundancyStat = exports.getRedundancyStats = exports.approximateOverheadForRedundancyLevel = void 0;
3
+ exports.approximateOverheadForRedundancyLevel = approximateOverheadForRedundancyLevel;
4
+ exports.getRedundancyStats = getRedundancyStats;
5
+ exports.getRedundancyStat = getRedundancyStat;
4
6
  const __1 = require("..");
5
7
  const mediumTable = [
6
8
  [94, 68, 46, 28, 14, 5, 1],
@@ -59,7 +61,6 @@ function approximateOverheadForRedundancyLevel(chunks, level, encrypted) {
59
61
  }
60
62
  return parities[parities.length - 1] / supportedChunks[supportedChunks.length - 1];
61
63
  }
62
- exports.approximateOverheadForRedundancyLevel = approximateOverheadForRedundancyLevel;
63
64
  function selectTable(level, encrypted) {
64
65
  switch (level) {
65
66
  case __1.RedundancyLevel.MEDIUM:
@@ -102,7 +103,6 @@ function getRedundancyStats() {
102
103
  paranoid,
103
104
  };
104
105
  }
105
- exports.getRedundancyStats = getRedundancyStats;
106
106
  function getRedundancyStat(level) {
107
107
  if (typeof level === 'string') {
108
108
  switch (level.toLowerCase()) {
@@ -131,4 +131,3 @@ function getRedundancyStat(level) {
131
131
  throw new Error(`Unknown redundancy level '${level}'`);
132
132
  }
133
133
  }
134
- exports.getRedundancyStat = getRedundancyStat;
@@ -28,6 +28,31 @@ class Size {
28
28
  static fromGigabytes(gigabytes) {
29
29
  return new Size(gigabytes * 1000 * 1000 * 1000);
30
30
  }
31
+ /**
32
+ * Parses a size string and returns a `Size` instance.
33
+ *
34
+ * Case insensitive. E.g. both `"28MB"` and `"1gb"` are valid.
35
+ *
36
+ * Whitespaces are ignored. E.g. both `"512 kb"` and `"2megabytes"` are valid.
37
+ *
38
+ * Decimal numbers are supported. E.g. `"1.5gb"` is valid.
39
+ *
40
+ * Uses 1000 as the base for conversions. E.g. 1kb = 1000 bytes.
41
+ * This is consistent with the effective stamp utilization table.
42
+ *
43
+ * Supported units:
44
+ * - b, byte, bytes
45
+ * - kb, kilobyte, kilobytes
46
+ * - mb, megabyte, megabytes
47
+ * - gb, gigabyte, gigabytes
48
+ * - tb, terabyte, terabytes
49
+ *
50
+ * @param size - A string representing a size
51
+ * @returns a `Size` instance
52
+ */
53
+ static parseFromString(size) {
54
+ return Size.fromBytes(cafe_utility_1.Numbers.makeStorage(size, 1000));
55
+ }
31
56
  toBytes() {
32
57
  return this.bytes;
33
58
  }
@@ -1,12 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.marshalStamp = exports.convertEnvelopeToMarshaledStamp = exports.getDepthForSize = exports.getAmountForDuration = exports.getStampDuration = exports.getStampCost = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampTheoreticalBytes = exports.getStampUsage = void 0;
3
+ exports.getStampUsage = getStampUsage;
4
+ exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
5
+ exports.getStampEffectiveBytes = getStampEffectiveBytes;
6
+ exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
7
+ exports.getStampCost = getStampCost;
8
+ exports.getStampDuration = getStampDuration;
9
+ exports.getAmountForDuration = getAmountForDuration;
10
+ exports.getDepthForSize = getDepthForSize;
11
+ exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
12
+ exports.marshalStamp = marshalStamp;
13
+ exports.mapPostageBatch = mapPostageBatch;
14
+ exports.unmapPostageBatch = unmapPostageBatch;
4
15
  const cafe_utility_1 = require("cafe-utility");
5
16
  const types_1 = require("../types");
6
17
  const bytes_1 = require("./bytes");
7
18
  const duration_1 = require("./duration");
19
+ const size_1 = require("./size");
8
20
  const tokens_1 = require("./tokens");
9
21
  const type_1 = require("./type");
22
+ const typed_bytes_1 = require("./typed-bytes");
23
+ const workaround_1 = require("./workaround");
10
24
  const MAX_UTILIZATION = 0.9;
11
25
  /**
12
26
  * Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
@@ -18,7 +32,6 @@ const MAX_UTILIZATION = 0.9;
18
32
  function getStampUsage(utilization, depth, bucketDepth) {
19
33
  return utilization / Math.pow(2, depth - bucketDepth);
20
34
  }
21
- exports.getStampUsage = getStampUsage;
22
35
  /**
23
36
  * Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
24
37
  *
@@ -29,7 +42,6 @@ exports.getStampUsage = getStampUsage;
29
42
  function getStampTheoreticalBytes(depth) {
30
43
  return 4096 * 2 ** depth;
31
44
  }
32
- exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
33
45
  /**
34
46
  * Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
35
47
  * Optimised for encrypted, medium erasure coding
@@ -86,7 +98,6 @@ function getStampEffectiveBytes(depth, encryption, erasureCodeLevel) {
86
98
  }
87
99
  return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
88
100
  }
89
- exports.getStampEffectiveBytes = getStampEffectiveBytes;
90
101
  function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
91
102
  const map = new Map();
92
103
  for (let i = 17; i < 35; i++) {
@@ -94,14 +105,12 @@ function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
94
105
  }
95
106
  return map;
96
107
  }
97
- exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
98
108
  /**
99
109
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
100
110
  */
101
111
  function getStampCost(depth, amount) {
102
112
  return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
103
113
  }
104
- exports.getStampCost = getStampCost;
105
114
  /**
106
115
  * Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
107
116
  *
@@ -113,7 +122,6 @@ function getStampDuration(amount, pricePerBlock, blockTime) {
113
122
  const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
114
123
  return duration_1.Duration.fromSeconds(Number((amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock)));
115
124
  }
116
- exports.getStampDuration = getStampDuration;
117
125
  /**
118
126
  * Get the postage batch `amount` required for a given `duration`.
119
127
  *
@@ -124,7 +132,6 @@ exports.getStampDuration = getStampDuration;
124
132
  function getAmountForDuration(duration, pricePerBlock, blockTime) {
125
133
  return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock) + 1n;
126
134
  }
127
- exports.getAmountForDuration = getAmountForDuration;
128
135
  /**
129
136
  * Utility function that calculates the depth required for a postage batch to achieve the specified effective size
130
137
  *
@@ -151,11 +158,9 @@ function getDepthForSize(size, encryption, erasureCodeLevel) {
151
158
  }
152
159
  return 35;
153
160
  }
154
- exports.getDepthForSize = getDepthForSize;
155
161
  function convertEnvelopeToMarshaledStamp(envelope) {
156
162
  return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
157
163
  }
158
- exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
159
164
  function marshalStamp(signature, batchId, timestamp, index) {
160
165
  if (signature.length !== 65) {
161
166
  throw Error('invalid signature length');
@@ -171,4 +176,48 @@ function marshalStamp(signature, batchId, timestamp, index) {
171
176
  }
172
177
  return new bytes_1.Bytes(cafe_utility_1.Binary.concatBytes(batchId, index, timestamp, signature));
173
178
  }
174
- exports.marshalStamp = marshalStamp;
179
+ function mapPostageBatch(raw, encryption, erasureCodeLevel) {
180
+ const usage = getStampUsage(raw.utilization, raw.depth, raw.bucketDepth);
181
+ const batchTTL = (0, workaround_1.normalizeBatchTTL)(raw.batchTTL);
182
+ const duration = duration_1.Duration.fromSeconds(batchTTL);
183
+ const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, erasureCodeLevel);
184
+ return {
185
+ batchID: new typed_bytes_1.BatchId(raw.batchID),
186
+ utilization: raw.utilization,
187
+ usable: raw.usable,
188
+ label: raw.label,
189
+ depth: raw.depth,
190
+ amount: (0, type_1.asNumberString)(raw.amount),
191
+ bucketDepth: raw.bucketDepth,
192
+ blockNumber: raw.blockNumber,
193
+ immutableFlag: raw.immutableFlag,
194
+ usage,
195
+ usageText: `${Math.round(usage * 100)}%`,
196
+ size: size_1.Size.fromBytes(effectiveBytes),
197
+ remainingSize: size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage))),
198
+ theoreticalSize: size_1.Size.fromBytes(getStampTheoreticalBytes(raw.depth)),
199
+ duration,
200
+ calculateSize(encryption, redundancyLevel) {
201
+ const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, redundancyLevel);
202
+ return size_1.Size.fromBytes(effectiveBytes);
203
+ },
204
+ calculateRemainingSize(encryption, redundancyLevel) {
205
+ const effectiveBytes = getStampEffectiveBytes(raw.depth, encryption, redundancyLevel);
206
+ return size_1.Size.fromBytes(Math.ceil(effectiveBytes * (1 - this.usage)));
207
+ },
208
+ };
209
+ }
210
+ function unmapPostageBatch(batch) {
211
+ return {
212
+ batchID: batch.batchID.toHex(),
213
+ utilization: batch.utilization,
214
+ usable: batch.usable,
215
+ label: batch.label,
216
+ depth: batch.depth,
217
+ amount: batch.amount,
218
+ bucketDepth: batch.bucketDepth,
219
+ blockNumber: batch.blockNumber,
220
+ immutableFlag: batch.immutableFlag,
221
+ batchTTL: batch.duration.toSeconds(),
222
+ };
223
+ }
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadTar = void 0;
3
+ exports.uploadTar = uploadTar;
4
4
  const headers_1 = require("./headers");
5
5
  const http_1 = require("./http");
6
6
  const tar_1 = require("./tar");
@@ -23,4 +23,3 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
23
23
  });
24
24
  return response;
25
25
  }
26
- exports.uploadTar = uploadTar;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.uploadTar = void 0;
3
+ exports.uploadTar = uploadTar;
4
4
  const headers_1 = require("./headers");
5
5
  const http_1 = require("./http");
6
6
  const tar_1 = require("./tar");
@@ -24,4 +24,3 @@ async function uploadTar(requestOptions, collection, postageBatchId, options) {
24
24
  const response = await responsePromise;
25
25
  return response;
26
26
  }
27
- exports.uploadTar = uploadTar;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeTar = void 0;
3
+ exports.writeTar = writeTar;
4
4
  const file_1 = require("./file");
5
5
  async function writeTar(collection, tarStream) {
6
6
  for (const item of collection) {
@@ -14,4 +14,3 @@ async function writeTar(collection, tarStream) {
14
14
  }
15
15
  }
16
16
  }
17
- exports.writeTar = writeTar;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.writeTar = void 0;
3
+ exports.writeTar = writeTar;
4
4
  const fs_1 = require("fs");
5
5
  async function writeTar(collection, tarStream) {
6
6
  for (const item of collection) {
@@ -22,4 +22,3 @@ async function writeTar(collection, tarStream) {
22
22
  }
23
23
  }
24
24
  }
25
- exports.writeTar = writeTar;
@@ -15,15 +15,41 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
15
15
  }) : function(o, v) {
16
16
  o["default"] = v;
17
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
- };
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
25
35
  Object.defineProperty(exports, "__esModule", { value: true });
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;
36
+ exports.isReadable = isReadable;
37
+ exports.asNumberString = asNumberString;
38
+ exports.prepareBeeRequestOptions = prepareBeeRequestOptions;
39
+ exports.prepareDownloadOptions = prepareDownloadOptions;
40
+ exports.prepareUploadOptions = prepareUploadOptions;
41
+ exports.prepareRedundantUploadOptions = prepareRedundantUploadOptions;
42
+ exports.prepareFileUploadOptions = prepareFileUploadOptions;
43
+ exports.prepareCollectionUploadOptions = prepareCollectionUploadOptions;
44
+ exports.isTag = isTag;
45
+ exports.preparePssMessageHandler = preparePssMessageHandler;
46
+ exports.prepareGsocMessageHandler = prepareGsocMessageHandler;
47
+ exports.preparePostageBatchOptions = preparePostageBatchOptions;
48
+ exports.prepareTransactionOptions = prepareTransactionOptions;
49
+ exports.assertData = assertData;
50
+ exports.assertFileData = assertFileData;
51
+ exports.prepareAllTagsOptions = prepareAllTagsOptions;
52
+ exports.makeTagUid = makeTagUid;
27
53
  const cafe_utility_1 = require("cafe-utility");
28
54
  const stream = __importStar(require("stream"));
29
55
  const types_1 = require("../types");
@@ -32,14 +58,12 @@ const typed_bytes_1 = require("./typed-bytes");
32
58
  function isReadable(value) {
33
59
  return typeof stream.Readable !== 'undefined' && value instanceof stream.Readable;
34
60
  }
35
- exports.isReadable = isReadable;
36
61
  function asNumberString(value, options) {
37
62
  if (typeof value === 'bigint') {
38
63
  value = value.toString();
39
64
  }
40
65
  return cafe_utility_1.Types.asIntegerString(value, options);
41
66
  }
42
- exports.asNumberString = asNumberString;
43
67
  function prepareBeeRequestOptions(value) {
44
68
  const object = cafe_utility_1.Types.asObject(value, { name: 'BeeRequestOptions' });
45
69
  return {
@@ -50,9 +74,9 @@ function prepareBeeRequestOptions(value) {
50
74
  httpAgent: object.httpAgent,
51
75
  httpsAgent: object.httpsAgent,
52
76
  endlesslyRetry: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'endlesslyRetry' }), object.endlesslyRetry),
77
+ signal: object.signal,
53
78
  };
54
79
  }
55
- exports.prepareBeeRequestOptions = prepareBeeRequestOptions;
56
80
  function prepareDownloadOptions(value) {
57
81
  const object = cafe_utility_1.Types.asObject(value, { name: 'DownloadOptions' });
58
82
  return {
@@ -64,7 +88,6 @@ function prepareDownloadOptions(value) {
64
88
  actTimestamp: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asNumber(x, { name: 'actTimestamp' }), object.actTimestamp),
65
89
  };
66
90
  }
67
- exports.prepareDownloadOptions = prepareDownloadOptions;
68
91
  function prepareUploadOptions(value, name = 'UploadOptions') {
69
92
  const object = cafe_utility_1.Types.asObject(value, { name });
70
93
  return {
@@ -76,7 +99,6 @@ function prepareUploadOptions(value, name = 'UploadOptions') {
76
99
  tag: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'tag', min: 0 }), object.tag),
77
100
  };
78
101
  }
79
- exports.prepareUploadOptions = prepareUploadOptions;
80
102
  function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
81
103
  const uploadOptions = prepareUploadOptions(value, name);
82
104
  const object = cafe_utility_1.Types.asObject(value, { name });
@@ -85,7 +107,6 @@ function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
85
107
  redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
86
108
  };
87
109
  }
88
- exports.prepareRedundantUploadOptions = prepareRedundantUploadOptions;
89
110
  function prepareFileUploadOptions(value) {
90
111
  const uploadOptions = prepareUploadOptions(value, 'FileUploadOptions');
91
112
  const object = cafe_utility_1.Types.asObject(value, { name: 'FileUploadOptions' });
@@ -96,7 +117,6 @@ function prepareFileUploadOptions(value) {
96
117
  redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
97
118
  };
98
119
  }
99
- exports.prepareFileUploadOptions = prepareFileUploadOptions;
100
120
  function prepareCollectionUploadOptions(value) {
101
121
  const uploadOptions = prepareUploadOptions(value, 'CollectionUploadOptions');
102
122
  const object = cafe_utility_1.Types.asObject(value, { name: 'CollectionUploadOptions' });
@@ -107,7 +127,6 @@ function prepareCollectionUploadOptions(value) {
107
127
  redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
108
128
  };
109
129
  }
110
- exports.prepareCollectionUploadOptions = prepareCollectionUploadOptions;
111
130
  function isTag(value) {
112
131
  try {
113
132
  const object = cafe_utility_1.Types.asObject(value, { name: 'Tag' });
@@ -118,23 +137,22 @@ function isTag(value) {
118
137
  return false;
119
138
  }
120
139
  }
121
- exports.isTag = isTag;
122
140
  function preparePssMessageHandler(value) {
123
141
  const object = cafe_utility_1.Types.asObject(value, { name: 'PssMessageHandler' });
124
142
  return {
125
143
  onMessage: cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' }),
126
144
  onError: cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' }),
145
+ onClose: cafe_utility_1.Types.asFunction(object.onClose, { name: 'onClose' }),
127
146
  };
128
147
  }
129
- exports.preparePssMessageHandler = preparePssMessageHandler;
130
148
  function prepareGsocMessageHandler(value) {
131
149
  const object = cafe_utility_1.Types.asObject(value, { name: 'GsocMessageHandler' });
132
150
  return {
133
151
  onMessage: cafe_utility_1.Types.asFunction(object.onMessage, { name: 'onMessage' }),
134
152
  onError: cafe_utility_1.Types.asFunction(object.onError, { name: 'onError' }),
153
+ onClose: cafe_utility_1.Types.asFunction(object.onClose, { name: 'onClose' }),
135
154
  };
136
155
  }
137
- exports.prepareGsocMessageHandler = prepareGsocMessageHandler;
138
156
  function preparePostageBatchOptions(value) {
139
157
  const object = cafe_utility_1.Types.asObject(value, { name: 'PostageBatchOptions' });
140
158
  return {
@@ -145,7 +163,6 @@ function preparePostageBatchOptions(value) {
145
163
  waitForUsableTimeout: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'waitForUsableTimeout', min: 0 }), object.waitForUsableTimeout),
146
164
  };
147
165
  }
148
- exports.preparePostageBatchOptions = preparePostageBatchOptions;
149
166
  function prepareTransactionOptions(value, name = 'TransactionOptions') {
150
167
  const object = cafe_utility_1.Types.asObject(value, { name });
151
168
  return {
@@ -153,7 +170,6 @@ function prepareTransactionOptions(value, name = 'TransactionOptions') {
153
170
  gasPrice: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasPrice', min: 0n }), object.gasPrice),
154
171
  };
155
172
  }
156
- exports.prepareTransactionOptions = prepareTransactionOptions;
157
173
  /**
158
174
  * Check whether the given parameter is valid data to upload
159
175
  * @param value
@@ -164,7 +180,6 @@ function assertData(value) {
164
180
  throw new TypeError('Data must be either string or Uint8Array!');
165
181
  }
166
182
  }
167
- exports.assertData = assertData;
168
183
  /**
169
184
  * Check whether the given parameter is a correct file representation to file upload.
170
185
  * @param value
@@ -175,7 +190,6 @@ function assertFileData(value) {
175
190
  throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
176
191
  }
177
192
  }
178
- exports.assertFileData = assertFileData;
179
193
  /**
180
194
  * Checks whether optional options for AllTags query are valid
181
195
  * @param options
@@ -187,7 +201,6 @@ function prepareAllTagsOptions(value) {
187
201
  offset: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'offset', min: 0 }), object.offset),
188
202
  };
189
203
  }
190
- exports.prepareAllTagsOptions = prepareAllTagsOptions;
191
204
  /**
192
205
  * Utility functions that return Tag UID
193
206
  * @param tagUid
@@ -204,4 +217,3 @@ function makeTagUid(tagUid) {
204
217
  }
205
218
  throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
206
219
  }
207
- exports.makeTagUid = makeTagUid;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.stripLastSlash = exports.assertBeeUrl = exports.isValidBeeUrl = void 0;
3
+ exports.isValidBeeUrl = isValidBeeUrl;
4
+ exports.assertBeeUrl = assertBeeUrl;
5
+ exports.stripLastSlash = stripLastSlash;
4
6
  const error_1 = require("./error");
5
7
  /**
6
8
  * Validates that passed string is valid URL of Bee.
@@ -21,7 +23,6 @@ function isValidBeeUrl(url) {
21
23
  return false;
22
24
  }
23
25
  }
24
- exports.isValidBeeUrl = isValidBeeUrl;
25
26
  /**
26
27
  * Validates that passed string is valid URL of Bee, if not it throws BeeArgumentError.
27
28
  * We support only HTTP and HTTPS protocols.
@@ -33,7 +34,6 @@ function assertBeeUrl(url) {
33
34
  throw new error_1.BeeArgumentError('URL is not valid!', url);
34
35
  }
35
36
  }
36
- exports.assertBeeUrl = assertBeeUrl;
37
37
  /**
38
38
  * Removes trailing slash out of the given string.
39
39
  * @param url
@@ -44,4 +44,3 @@ function stripLastSlash(url) {
44
44
  }
45
45
  return url;
46
46
  }
47
- exports.stripLastSlash = stripLastSlash;
@@ -1,7 +1,8 @@
1
1
  "use strict";
2
2
  // TODO: Remove this file after the issue is fixed
3
3
  Object.defineProperty(exports, "__esModule", { value: true });
4
- exports.normalizeCurrentPrice = exports.normalizeBatchTTL = void 0;
4
+ exports.normalizeBatchTTL = normalizeBatchTTL;
5
+ exports.normalizeCurrentPrice = normalizeCurrentPrice;
5
6
  function normalizeBatchTTL(batchTTL) {
6
7
  if (!Number.isInteger(batchTTL)) {
7
8
  return 1;
@@ -9,12 +10,14 @@ function normalizeBatchTTL(batchTTL) {
9
10
  if (batchTTL < 1) {
10
11
  return 1;
11
12
  }
12
- if (batchTTL > 315569260) {
13
- return 315569260;
13
+ // Cap `batchTTL` (represents seconds) to 100 years.
14
+ // We can assume `storagePrice` is invalid (e.g. 1).
15
+ // This is needed to prevent Date objects breaking.
16
+ if (batchTTL > 3155695200) {
17
+ return 3155695200;
14
18
  }
15
19
  return batchTTL;
16
20
  }
17
- exports.normalizeBatchTTL = normalizeBatchTTL;
18
21
  function normalizeCurrentPrice(currentPrice) {
19
22
  if (!Number.isInteger(currentPrice)) {
20
23
  return 24000;
@@ -24,4 +27,3 @@ function normalizeCurrentPrice(currentPrice) {
24
27
  }
25
28
  return currentPrice;
26
29
  }
27
- exports.normalizeCurrentPrice = normalizeCurrentPrice;