@ethersphere/bee-js 10.4.0 → 11.0.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 (77) hide show
  1. package/dist/cjs/bee.js +17 -10
  2. package/dist/cjs/chunk/bmt.js +1 -2
  3. package/dist/cjs/chunk/cac.js +3 -3
  4. package/dist/cjs/chunk/soc.js +24 -15
  5. package/dist/cjs/feed/identifier.js +1 -2
  6. package/dist/cjs/feed/index.js +25 -16
  7. package/dist/cjs/feed/retrievable.js +1 -2
  8. package/dist/cjs/index.js +17 -7
  9. package/dist/cjs/modules/bytes.js +4 -5
  10. package/dist/cjs/modules/bzz.js +4 -5
  11. package/dist/cjs/modules/chunk.js +2 -3
  12. package/dist/cjs/modules/debug/balance.js +4 -5
  13. package/dist/cjs/modules/debug/chequebook.js +8 -9
  14. package/dist/cjs/modules/debug/connectivity.js +7 -8
  15. package/dist/cjs/modules/debug/settlements.js +2 -3
  16. package/dist/cjs/modules/debug/stake.js +6 -7
  17. package/dist/cjs/modules/debug/stamps.js +7 -8
  18. package/dist/cjs/modules/debug/states.js +6 -6
  19. package/dist/cjs/modules/debug/status.js +9 -9
  20. package/dist/cjs/modules/debug/transactions.js +4 -5
  21. package/dist/cjs/modules/envelope.js +1 -2
  22. package/dist/cjs/modules/feed.js +3 -4
  23. package/dist/cjs/modules/grantee.js +3 -4
  24. package/dist/cjs/modules/gsoc.js +2 -3
  25. package/dist/cjs/modules/pinning.js +4 -5
  26. package/dist/cjs/modules/pss.js +2 -3
  27. package/dist/cjs/modules/rchash.js +1 -2
  28. package/dist/cjs/modules/soc.js +1 -2
  29. package/dist/cjs/modules/status.js +2 -3
  30. package/dist/cjs/modules/stewardship.js +2 -3
  31. package/dist/cjs/modules/tag.js +5 -6
  32. package/dist/cjs/types/debug.js +3 -3
  33. package/dist/cjs/types/index.js +2 -2
  34. package/dist/cjs/utils/bytes.js +2 -2
  35. package/dist/cjs/utils/chunk-size.js +1 -2
  36. package/dist/cjs/utils/chunk-stream.browser.js +3 -4
  37. package/dist/cjs/utils/chunk-stream.js +3 -4
  38. package/dist/cjs/utils/cid.js +3 -3
  39. package/dist/cjs/utils/collection.browser.js +2 -3
  40. package/dist/cjs/utils/collection.js +5 -6
  41. package/dist/cjs/utils/collection.node.js +2 -3
  42. package/dist/cjs/utils/data.browser.js +1 -2
  43. package/dist/cjs/utils/data.js +1 -2
  44. package/dist/cjs/utils/expose.js +2 -1
  45. package/dist/cjs/utils/file.js +2 -3
  46. package/dist/cjs/utils/headers.js +2 -3
  47. package/dist/cjs/utils/http.js +2 -2
  48. package/dist/cjs/utils/pss.js +1 -2
  49. package/dist/cjs/utils/redundancy.js +3 -4
  50. package/dist/cjs/utils/stamps.js +12 -13
  51. package/dist/cjs/utils/tar-uploader.browser.js +1 -2
  52. package/dist/cjs/utils/tar-uploader.js +1 -2
  53. package/dist/cjs/utils/tar-writer.browser.js +1 -2
  54. package/dist/cjs/utils/tar-writer.js +1 -2
  55. package/dist/cjs/utils/type.js +34 -25
  56. package/dist/cjs/utils/url.js +3 -4
  57. package/dist/cjs/utils/workaround.js +2 -3
  58. package/dist/index.browser.min.js +1 -1
  59. package/dist/index.browser.min.js.map +1 -1
  60. package/dist/mjs/bee.js +0 -3
  61. package/dist/mjs/modules/debug/states.js +3 -0
  62. package/dist/mjs/modules/debug/status.js +1 -1
  63. package/dist/mjs/utils/expose.js +1 -1
  64. package/dist/types/bee.d.ts +0 -4
  65. package/dist/types/index.d.ts +1 -0
  66. package/dist/types/modules/bzz.d.ts +0 -1
  67. package/dist/types/modules/debug/status.d.ts +1 -1
  68. package/dist/types/modules/gsoc.d.ts +0 -1
  69. package/dist/types/modules/pss.d.ts +0 -1
  70. package/dist/types/types/debug.d.ts +1 -0
  71. package/dist/types/utils/constants.d.ts +3 -3
  72. package/dist/types/utils/error.d.ts +2 -2
  73. package/dist/types/utils/expose.d.ts +1 -1
  74. package/dist/types/utils/tar.browser.d.ts +1 -1
  75. package/dist/types/utils/tar.d.ts +0 -1
  76. package/dist/types/utils/type.d.ts +0 -1
  77. package/package.json +9 -12
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.streamFiles = exports.streamDirectory = exports.hashDirectory = void 0;
3
+ exports.hashDirectory = hashDirectory;
4
+ exports.streamDirectory = streamDirectory;
5
+ exports.streamFiles = streamFiles;
4
6
  const cafe_utility_1 = require("cafe-utility");
5
7
  const __1 = require("..");
6
8
  const manifest_1 = require("../manifest/manifest");
@@ -11,11 +13,9 @@ const typed_bytes_1 = require("./typed-bytes");
11
13
  async function hashDirectory(_dir) {
12
14
  throw new Error('Hashing directories is not supported in browsers!');
13
15
  }
14
- exports.hashDirectory = hashDirectory;
15
16
  async function streamDirectory(_bee, _dir, _postageBatchId, _onUploadProgress, _options, _requestOptions) {
16
17
  throw new Error('Streaming directories is not supported in browsers!');
17
18
  }
18
- exports.streamDirectory = streamDirectory;
19
19
  async function streamFiles(bee, files, postageBatchId, onUploadProgress, options, requestOptions) {
20
20
  const queue = new cafe_utility_1.AsyncQueue(64, 64);
21
21
  let total = 0;
@@ -76,7 +76,6 @@ async function streamFiles(bee, files, postageBatchId, onUploadProgress, options
76
76
  }
77
77
  return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
78
78
  }
79
- exports.streamFiles = streamFiles;
80
79
  function maybeEnrichMime(mime) {
81
80
  if (['text/html', 'text/css'].includes(mime)) {
82
81
  return `${mime}; charset=utf-8`;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.streamFiles = exports.streamDirectory = exports.hashDirectory = void 0;
3
+ exports.hashDirectory = hashDirectory;
4
+ exports.streamDirectory = streamDirectory;
5
+ exports.streamFiles = streamFiles;
4
6
  const cafe_utility_1 = require("cafe-utility");
5
7
  const fs_1 = require("fs");
6
8
  const __1 = require("..");
@@ -30,7 +32,6 @@ async function hashDirectory(dir) {
30
32
  }
31
33
  return mantaray.calculateSelfAddress();
32
34
  }
33
- exports.hashDirectory = hashDirectory;
34
35
  async function streamDirectory(bee, dir, postageBatchId, onUploadProgress, options, requestOptions) {
35
36
  const queue = new cafe_utility_1.AsyncQueue(64, 64);
36
37
  let total = 0;
@@ -83,7 +84,6 @@ async function streamDirectory(bee, dir, postageBatchId, onUploadProgress, optio
83
84
  }
84
85
  return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
85
86
  }
86
- exports.streamDirectory = streamDirectory;
87
87
  function maybeEnrichMime(mime) {
88
88
  if (['text/html', 'text/css'].includes(mime)) {
89
89
  return `${mime}; charset=utf-8`;
@@ -93,4 +93,3 @@ function maybeEnrichMime(mime) {
93
93
  async function streamFiles(_bee, _files, _postageBatchId, _onUploadProgress, _options, _requestOptions) {
94
94
  throw new Error('Streaming files is not supported in Node.js');
95
95
  }
96
- exports.streamFiles = streamFiles;
@@ -1,6 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.convertCidToReference = exports.convertReferenceToCid = exports.SWARM_FEED_CODEC = exports.SWARM_MANIFEST_CODEC = void 0;
3
+ exports.SWARM_FEED_CODEC = exports.SWARM_MANIFEST_CODEC = void 0;
4
+ exports.convertReferenceToCid = convertReferenceToCid;
5
+ exports.convertCidToReference = convertCidToReference;
4
6
  const cafe_utility_1 = require("cafe-utility");
5
7
  const typed_bytes_1 = require("./typed-bytes");
6
8
  exports.SWARM_MANIFEST_CODEC = 0xfa;
@@ -21,7 +23,6 @@ function convertReferenceToCid(reference, type) {
21
23
  const hash = reference.toBase32().replace(/\=+$/, '');
22
24
  return `${base32}${header}${hash}`.toLowerCase();
23
25
  }
24
- exports.convertReferenceToCid = convertReferenceToCid;
25
26
  function convertCidToReference(cid) {
26
27
  const bytes = cafe_utility_1.Binary.base32ToUint8Array(cid.toUpperCase().slice(1));
27
28
  const codec = bytes[1];
@@ -34,4 +35,3 @@ function convertCidToReference(cid) {
34
35
  reference,
35
36
  };
36
37
  }
37
- exports.convertCidToReference = convertCidToReference;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getFolderSize = exports.makeCollectionFromFS = void 0;
3
+ exports.makeCollectionFromFS = makeCollectionFromFS;
4
+ exports.getFolderSize = getFolderSize;
4
5
  /**
5
6
  * Creates array in the format of Collection with data loaded from directory on filesystem.
6
7
  * The function loads all the data into memory!
@@ -10,7 +11,6 @@ exports.getFolderSize = exports.makeCollectionFromFS = void 0;
10
11
  async function makeCollectionFromFS(_dir) {
11
12
  throw new Error('Creating Collection from File System is not supported in browsers!');
12
13
  }
13
- exports.makeCollectionFromFS = makeCollectionFromFS;
14
14
  /**
15
15
  * Calculate folder size recursively
16
16
  *
@@ -20,4 +20,3 @@ exports.makeCollectionFromFS = makeCollectionFromFS;
20
20
  async function getFolderSize(_dir) {
21
21
  throw new Error('Creating Collection from File System is not supported in browsers!');
22
22
  }
23
- exports.getFolderSize = getFolderSize;
@@ -1,6 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getCollectionSize = exports.makeCollectionFromFileList = exports.makeFilePath = exports.assertCollection = exports.isCollection = void 0;
3
+ exports.isCollection = isCollection;
4
+ exports.assertCollection = assertCollection;
5
+ exports.makeFilePath = makeFilePath;
6
+ exports.makeCollectionFromFileList = makeCollectionFromFileList;
7
+ exports.getCollectionSize = getCollectionSize;
4
8
  const error_1 = require("./error");
5
9
  function isCollection(data) {
6
10
  if (!Array.isArray(data)) {
@@ -8,13 +12,11 @@ function isCollection(data) {
8
12
  }
9
13
  return data.every(entry => typeof entry === 'object' && entry.path && entry.size !== undefined);
10
14
  }
11
- exports.isCollection = isCollection;
12
15
  function assertCollection(data) {
13
16
  if (!isCollection(data)) {
14
17
  throw new error_1.BeeArgumentError('invalid collection', data);
15
18
  }
16
19
  }
17
- exports.assertCollection = assertCollection;
18
20
  function makeFilePath(file) {
19
21
  if (file.webkitRelativePath && file.webkitRelativePath !== '') {
20
22
  return file.webkitRelativePath.replace(/.*?\//i, '');
@@ -24,7 +26,6 @@ function makeFilePath(file) {
24
26
  }
25
27
  throw new TypeError('file is not valid File object');
26
28
  }
27
- exports.makeFilePath = makeFilePath;
28
29
  function makeCollectionFromFileList(fileList) {
29
30
  return Array.from(fileList).map(file => ({
30
31
  path: makeFilePath(file),
@@ -32,7 +33,6 @@ function makeCollectionFromFileList(fileList) {
32
33
  file,
33
34
  }));
34
35
  }
35
- exports.makeCollectionFromFileList = makeCollectionFromFileList;
36
36
  /**
37
37
  * Calculate cumulative size of files
38
38
  *
@@ -42,4 +42,3 @@ exports.makeCollectionFromFileList = makeCollectionFromFileList;
42
42
  function getCollectionSize(fileList) {
43
43
  return Array.from(fileList).reduce((sum, file) => sum + file.size, 0);
44
44
  }
45
- exports.getCollectionSize = getCollectionSize;
@@ -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.getFolderSize = exports.makeCollectionFromFS = void 0;
6
+ exports.makeCollectionFromFS = makeCollectionFromFS;
7
+ exports.getFolderSize = getFolderSize;
7
8
  const fs_1 = __importDefault(require("fs"));
8
9
  const path_1 = __importDefault(require("path"));
9
10
  /**
@@ -20,7 +21,6 @@ async function makeCollectionFromFS(dir) {
20
21
  }
21
22
  return buildCollectionRelative(dir, '');
22
23
  }
23
- exports.makeCollectionFromFS = makeCollectionFromFS;
24
24
  async function buildCollectionRelative(dir, relativePath) {
25
25
  const dirname = path_1.default.join(dir, relativePath);
26
26
  const entries = await fs_1.default.promises.opendir(dirname);
@@ -67,4 +67,3 @@ async function getFolderSize(dir) {
67
67
  }
68
68
  return size;
69
69
  }
70
- exports.getFolderSize = getFolderSize;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareWebsocketData = void 0;
3
+ exports.prepareWebsocketData = prepareWebsocketData;
4
4
  async function prepareWebsocketData(data) {
5
5
  if (typeof data === 'string') {
6
6
  return new TextEncoder().encode(data);
@@ -13,4 +13,3 @@ async function prepareWebsocketData(data) {
13
13
  }
14
14
  throw new TypeError('unknown websocket data type');
15
15
  }
16
- exports.prepareWebsocketData = prepareWebsocketData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareWebsocketData = void 0;
3
+ exports.prepareWebsocketData = prepareWebsocketData;
4
4
  function isBufferArray(buffer) {
5
5
  return Array.isArray(buffer) && buffer.length > 0 && buffer.every(data => data instanceof Buffer);
6
6
  }
@@ -19,4 +19,3 @@ async function prepareWebsocketData(data) {
19
19
  }
20
20
  throw new TypeError('unknown websocket data type');
21
21
  }
22
- exports.prepareWebsocketData = prepareWebsocketData;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unmapPostageBatch = exports.mapPostageBatch = exports.getStampUsage = exports.getStampTheoreticalBytes = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampDuration = exports.getStampCost = exports.getDepthForSize = exports.getAmountForDuration = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.makeMaxTarget = exports.getFolderSize = exports.makeCollectionFromFileList = exports.getCollectionSize = void 0;
3
+ exports.unmapPostageBatch = exports.mapPostageBatch = exports.getStampUsage = exports.getStampTheoreticalBytes = exports.getStampEffectiveBytesBreakpoints = exports.getStampEffectiveBytes = exports.getStampDuration = exports.getStampCost = exports.getDepthForSize = exports.getAmountForDuration = exports.convertEnvelopeToMarshaledStamp = exports.getRedundancyStats = exports.getRedundancyStat = exports.approximateOverheadForRedundancyLevel = exports.makeMaxTarget = exports.getFolderSize = exports.makeCollectionFromFileList = exports.getCollectionSize = void 0;
4
4
  var collection_1 = require("./collection");
5
5
  Object.defineProperty(exports, "getCollectionSize", { enumerable: true, get: function () { return collection_1.getCollectionSize; } });
6
6
  Object.defineProperty(exports, "makeCollectionFromFileList", { enumerable: true, get: function () { return collection_1.makeCollectionFromFileList; } });
@@ -13,6 +13,7 @@ Object.defineProperty(exports, "approximateOverheadForRedundancyLevel", { enumer
13
13
  Object.defineProperty(exports, "getRedundancyStat", { enumerable: true, get: function () { return redundancy_1.getRedundancyStat; } });
14
14
  Object.defineProperty(exports, "getRedundancyStats", { enumerable: true, get: function () { return redundancy_1.getRedundancyStats; } });
15
15
  var stamps_1 = require("./stamps");
16
+ Object.defineProperty(exports, "convertEnvelopeToMarshaledStamp", { enumerable: true, get: function () { return stamps_1.convertEnvelopeToMarshaledStamp; } });
16
17
  Object.defineProperty(exports, "getAmountForDuration", { enumerable: true, get: function () { return stamps_1.getAmountForDuration; } });
17
18
  Object.defineProperty(exports, "getDepthForSize", { enumerable: true, get: function () { return stamps_1.getDepthForSize; } });
18
19
  Object.defineProperty(exports, "getStampCost", { enumerable: true, get: function () { return stamps_1.getStampCost; } });
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.fileArrayBuffer = exports.isFile = void 0;
3
+ exports.isFile = isFile;
4
+ exports.fileArrayBuffer = fileArrayBuffer;
4
5
  /**
5
6
  * Compatibility functions for working with File API objects
6
7
  *
@@ -17,7 +18,6 @@ function isFile(file) {
17
18
  typeof f.name === 'string' &&
18
19
  (typeof f.stream === 'function' || typeof f.arrayBuffer === 'function'));
19
20
  }
20
- exports.isFile = isFile;
21
21
  /**
22
22
  * Compatibility helper for browsers where the `arrayBuffer function is
23
23
  * missing from `File` objects.
@@ -35,4 +35,3 @@ async function fileArrayBuffer(file) {
35
35
  fr.readAsArrayBuffer(file);
36
36
  });
37
37
  }
38
- exports.fileArrayBuffer = fileArrayBuffer;
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.prepareRequestHeaders = exports.readFileHeaders = void 0;
3
+ exports.readFileHeaders = readFileHeaders;
4
+ exports.prepareRequestHeaders = prepareRequestHeaders;
4
5
  const cafe_utility_1 = require("cafe-utility");
5
6
  const error_1 = require("./error");
6
7
  const stamps_1 = require("./stamps");
@@ -15,7 +16,6 @@ function readFileHeaders(headers) {
15
16
  contentType,
16
17
  };
17
18
  }
18
- exports.readFileHeaders = readFileHeaders;
19
19
  function readContentDispositionFilename(header) {
20
20
  if (!header) {
21
21
  throw new error_1.BeeError('missing content-disposition header');
@@ -106,7 +106,6 @@ function prepareRequestHeaders(stamp, nullableOptions) {
106
106
  }
107
107
  return headers;
108
108
  }
109
- exports.prepareRequestHeaders = prepareRequestHeaders;
110
109
  function isEnvelopeWithBatchId(value) {
111
110
  if (!cafe_utility_1.Types.isObject(value)) {
112
111
  return false;
@@ -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"));
@@ -68,7 +69,6 @@ async function http(options, config) {
68
69
  }
69
70
  throw Error('Max number of failed attempts reached');
70
71
  }
71
- exports.http = http;
72
72
  function maybeRunOnRequestHook(options, requestConfig) {
73
73
  if (options.onRequest) {
74
74
  options.onRequest({
@@ -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;
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.unmapPostageBatch = exports.mapPostageBatch = 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");
@@ -21,7 +32,6 @@ const MAX_UTILIZATION = 0.9;
21
32
  function getStampUsage(utilization, depth, bucketDepth) {
22
33
  return utilization / Math.pow(2, depth - bucketDepth);
23
34
  }
24
- exports.getStampUsage = getStampUsage;
25
35
  /**
26
36
  * Utility function that calculates the theoritical maximum size of a postage batch based on its depth.
27
37
  *
@@ -32,7 +42,6 @@ exports.getStampUsage = getStampUsage;
32
42
  function getStampTheoreticalBytes(depth) {
33
43
  return 4096 * 2 ** depth;
34
44
  }
35
- exports.getStampTheoreticalBytes = getStampTheoreticalBytes;
36
45
  /**
37
46
  * Based on https://docs.ethswarm.org/docs/learn/technology/contracts/postage-stamp/#effective-utilisation-table
38
47
  * Optimised for encrypted, medium erasure coding
@@ -89,7 +98,6 @@ function getStampEffectiveBytes(depth, encryption, erasureCodeLevel) {
89
98
  }
90
99
  return Math.ceil(getStampTheoreticalBytes(depth) * MAX_UTILIZATION);
91
100
  }
92
- exports.getStampEffectiveBytes = getStampEffectiveBytes;
93
101
  function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
94
102
  const map = new Map();
95
103
  for (let i = 17; i < 35; i++) {
@@ -97,14 +105,12 @@ function getStampEffectiveBytesBreakpoints(encryption, erasureCodeLevel) {
97
105
  }
98
106
  return map;
99
107
  }
100
- exports.getStampEffectiveBytesBreakpoints = getStampEffectiveBytesBreakpoints;
101
108
  /**
102
109
  * Utility function that calculates the cost of a postage batch based on its depth and amount.
103
110
  */
104
111
  function getStampCost(depth, amount) {
105
112
  return tokens_1.BZZ.fromPLUR(2n ** BigInt(depth) * BigInt(amount));
106
113
  }
107
- exports.getStampCost = getStampCost;
108
114
  /**
109
115
  * Utility function that calculates the TTL of a postage batch based on its amount, price per block and block time.
110
116
  *
@@ -116,7 +122,6 @@ function getStampDuration(amount, pricePerBlock, blockTime) {
116
122
  const amountBigInt = BigInt((0, type_1.asNumberString)(amount));
117
123
  return duration_1.Duration.fromSeconds(Number((amountBigInt * BigInt(blockTime)) / BigInt(pricePerBlock)));
118
124
  }
119
- exports.getStampDuration = getStampDuration;
120
125
  /**
121
126
  * Get the postage batch `amount` required for a given `duration`.
122
127
  *
@@ -127,7 +132,6 @@ exports.getStampDuration = getStampDuration;
127
132
  function getAmountForDuration(duration, pricePerBlock, blockTime) {
128
133
  return (BigInt(duration.toSeconds()) / BigInt(blockTime)) * BigInt(pricePerBlock) + 1n;
129
134
  }
130
- exports.getAmountForDuration = getAmountForDuration;
131
135
  /**
132
136
  * Utility function that calculates the depth required for a postage batch to achieve the specified effective size
133
137
  *
@@ -154,11 +158,9 @@ function getDepthForSize(size, encryption, erasureCodeLevel) {
154
158
  }
155
159
  return 35;
156
160
  }
157
- exports.getDepthForSize = getDepthForSize;
158
161
  function convertEnvelopeToMarshaledStamp(envelope) {
159
162
  return marshalStamp(envelope.signature, envelope.batchId.toUint8Array(), envelope.timestamp, envelope.index);
160
163
  }
161
- exports.convertEnvelopeToMarshaledStamp = convertEnvelopeToMarshaledStamp;
162
164
  function marshalStamp(signature, batchId, timestamp, index) {
163
165
  if (signature.length !== 65) {
164
166
  throw Error('invalid signature length');
@@ -174,7 +176,6 @@ function marshalStamp(signature, batchId, timestamp, index) {
174
176
  }
175
177
  return new bytes_1.Bytes(cafe_utility_1.Binary.concatBytes(batchId, index, timestamp, signature));
176
178
  }
177
- exports.marshalStamp = marshalStamp;
178
179
  function mapPostageBatch(raw, encryption, erasureCodeLevel) {
179
180
  const usage = getStampUsage(raw.utilization, raw.depth, raw.bucketDepth);
180
181
  const batchTTL = (0, workaround_1.normalizeBatchTTL)(raw.batchTTL);
@@ -206,7 +207,6 @@ function mapPostageBatch(raw, encryption, erasureCodeLevel) {
206
207
  },
207
208
  };
208
209
  }
209
- exports.mapPostageBatch = mapPostageBatch;
210
210
  function unmapPostageBatch(batch) {
211
211
  return {
212
212
  batchID: batch.batchID.toHex(),
@@ -221,4 +221,3 @@ function unmapPostageBatch(batch) {
221
221
  batchTTL: batch.duration.toSeconds(),
222
222
  };
223
223
  }
224
- exports.unmapPostageBatch = unmapPostageBatch;
@@ -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 {
@@ -52,7 +76,6 @@ function prepareBeeRequestOptions(value) {
52
76
  endlesslyRetry: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asBoolean(x, { name: 'endlesslyRetry' }), object.endlesslyRetry),
53
77
  };
54
78
  }
55
- exports.prepareBeeRequestOptions = prepareBeeRequestOptions;
56
79
  function prepareDownloadOptions(value) {
57
80
  const object = cafe_utility_1.Types.asObject(value, { name: 'DownloadOptions' });
58
81
  return {
@@ -64,7 +87,6 @@ function prepareDownloadOptions(value) {
64
87
  actTimestamp: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asNumber(x, { name: 'actTimestamp' }), object.actTimestamp),
65
88
  };
66
89
  }
67
- exports.prepareDownloadOptions = prepareDownloadOptions;
68
90
  function prepareUploadOptions(value, name = 'UploadOptions') {
69
91
  const object = cafe_utility_1.Types.asObject(value, { name });
70
92
  return {
@@ -76,7 +98,6 @@ function prepareUploadOptions(value, name = 'UploadOptions') {
76
98
  tag: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'tag', min: 0 }), object.tag),
77
99
  };
78
100
  }
79
- exports.prepareUploadOptions = prepareUploadOptions;
80
101
  function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
81
102
  const uploadOptions = prepareUploadOptions(value, name);
82
103
  const object = cafe_utility_1.Types.asObject(value, { name });
@@ -85,7 +106,6 @@ function prepareRedundantUploadOptions(value, name = 'UploadOptions') {
85
106
  redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
86
107
  };
87
108
  }
88
- exports.prepareRedundantUploadOptions = prepareRedundantUploadOptions;
89
109
  function prepareFileUploadOptions(value) {
90
110
  const uploadOptions = prepareUploadOptions(value, 'FileUploadOptions');
91
111
  const object = cafe_utility_1.Types.asObject(value, { name: 'FileUploadOptions' });
@@ -96,7 +116,6 @@ function prepareFileUploadOptions(value) {
96
116
  redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
97
117
  };
98
118
  }
99
- exports.prepareFileUploadOptions = prepareFileUploadOptions;
100
119
  function prepareCollectionUploadOptions(value) {
101
120
  const uploadOptions = prepareUploadOptions(value, 'CollectionUploadOptions');
102
121
  const object = cafe_utility_1.Types.asObject(value, { name: 'CollectionUploadOptions' });
@@ -107,7 +126,6 @@ function prepareCollectionUploadOptions(value) {
107
126
  redundancyLevel: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'redundancyLevel', min: 0 }), object.redundancyLevel),
108
127
  };
109
128
  }
110
- exports.prepareCollectionUploadOptions = prepareCollectionUploadOptions;
111
129
  function isTag(value) {
112
130
  try {
113
131
  const object = cafe_utility_1.Types.asObject(value, { name: 'Tag' });
@@ -118,7 +136,6 @@ function isTag(value) {
118
136
  return false;
119
137
  }
120
138
  }
121
- exports.isTag = isTag;
122
139
  function preparePssMessageHandler(value) {
123
140
  const object = cafe_utility_1.Types.asObject(value, { name: 'PssMessageHandler' });
124
141
  return {
@@ -127,7 +144,6 @@ function preparePssMessageHandler(value) {
127
144
  onClose: cafe_utility_1.Types.asFunction(object.onClose, { name: 'onClose' }),
128
145
  };
129
146
  }
130
- exports.preparePssMessageHandler = preparePssMessageHandler;
131
147
  function prepareGsocMessageHandler(value) {
132
148
  const object = cafe_utility_1.Types.asObject(value, { name: 'GsocMessageHandler' });
133
149
  return {
@@ -136,7 +152,6 @@ function prepareGsocMessageHandler(value) {
136
152
  onClose: cafe_utility_1.Types.asFunction(object.onClose, { name: 'onClose' }),
137
153
  };
138
154
  }
139
- exports.prepareGsocMessageHandler = prepareGsocMessageHandler;
140
155
  function preparePostageBatchOptions(value) {
141
156
  const object = cafe_utility_1.Types.asObject(value, { name: 'PostageBatchOptions' });
142
157
  return {
@@ -147,7 +162,6 @@ function preparePostageBatchOptions(value) {
147
162
  waitForUsableTimeout: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'waitForUsableTimeout', min: 0 }), object.waitForUsableTimeout),
148
163
  };
149
164
  }
150
- exports.preparePostageBatchOptions = preparePostageBatchOptions;
151
165
  function prepareTransactionOptions(value, name = 'TransactionOptions') {
152
166
  const object = cafe_utility_1.Types.asObject(value, { name });
153
167
  return {
@@ -155,7 +169,6 @@ function prepareTransactionOptions(value, name = 'TransactionOptions') {
155
169
  gasPrice: cafe_utility_1.Types.asOptional(x => asNumberString(x, { name: 'gasPrice', min: 0n }), object.gasPrice),
156
170
  };
157
171
  }
158
- exports.prepareTransactionOptions = prepareTransactionOptions;
159
172
  /**
160
173
  * Check whether the given parameter is valid data to upload
161
174
  * @param value
@@ -166,7 +179,6 @@ function assertData(value) {
166
179
  throw new TypeError('Data must be either string or Uint8Array!');
167
180
  }
168
181
  }
169
- exports.assertData = assertData;
170
182
  /**
171
183
  * Check whether the given parameter is a correct file representation to file upload.
172
184
  * @param value
@@ -177,7 +189,6 @@ function assertFileData(value) {
177
189
  throw new TypeError('Data must be either string, Readable, Uint8Array or File!');
178
190
  }
179
191
  }
180
- exports.assertFileData = assertFileData;
181
192
  /**
182
193
  * Checks whether optional options for AllTags query are valid
183
194
  * @param options
@@ -189,7 +200,6 @@ function prepareAllTagsOptions(value) {
189
200
  offset: cafe_utility_1.Types.asOptional(x => cafe_utility_1.Types.asInteger(x, { name: 'offset', min: 0 }), object.offset),
190
201
  };
191
202
  }
192
- exports.prepareAllTagsOptions = prepareAllTagsOptions;
193
203
  /**
194
204
  * Utility functions that return Tag UID
195
205
  * @param tagUid
@@ -206,4 +216,3 @@ function makeTagUid(tagUid) {
206
216
  }
207
217
  throw new TypeError(`Expected number | Tag | string from tagUid, got: ${tagUid}`);
208
218
  }
209
- exports.makeTagUid = makeTagUid;