@ethersphere/bee-js 4.1.0 → 5.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 (202) hide show
  1. package/README.md +2 -2
  2. package/dist/cjs/{src/bee-debug.js → bee-debug.js} +8 -4
  3. package/dist/cjs/{src/bee.js → bee.js} +9 -3
  4. package/dist/cjs/{src/chunk → chunk}/bmt.js +0 -0
  5. package/dist/cjs/{src/chunk → chunk}/cac.js +0 -0
  6. package/dist/cjs/{src/chunk → chunk}/serialize.js +0 -0
  7. package/dist/cjs/{src/chunk → chunk}/signer.js +0 -0
  8. package/dist/cjs/{src/chunk → chunk}/soc.js +5 -1
  9. package/dist/cjs/{src/chunk → chunk}/span.js +0 -0
  10. package/dist/cjs/{src/feed → feed}/identifier.js +0 -0
  11. package/dist/cjs/{src/feed → feed}/index.js +5 -1
  12. package/dist/cjs/{src/feed → feed}/json.js +0 -0
  13. package/dist/cjs/{src/feed → feed}/retrievable.js +0 -0
  14. package/dist/cjs/{src/feed → feed}/topic.js +0 -0
  15. package/dist/cjs/{src/feed → feed}/type.js +0 -0
  16. package/dist/cjs/{src/index.js → index.js} +5 -1
  17. package/dist/cjs/{src/modules → modules}/bytes.js +0 -0
  18. package/dist/cjs/{src/modules → modules}/bzz.js +0 -0
  19. package/dist/cjs/{src/modules → modules}/chunk.js +0 -0
  20. package/dist/cjs/{src/modules → modules}/debug/balance.js +0 -0
  21. package/dist/cjs/{src/modules → modules}/debug/chequebook.js +0 -0
  22. package/dist/cjs/{src/modules → modules}/debug/chunk.js +0 -0
  23. package/dist/cjs/{src/modules → modules}/debug/connectivity.js +2 -2
  24. package/dist/cjs/{src/modules → modules}/debug/settlements.js +0 -0
  25. package/dist/cjs/{src/modules → modules}/debug/stamps.js +1 -1
  26. package/dist/cjs/{src/modules → modules}/debug/states.js +0 -0
  27. package/dist/cjs/{src/modules → modules}/debug/status.js +3 -3
  28. package/dist/cjs/{src/modules → modules}/debug/tag.js +0 -0
  29. package/dist/cjs/{src/modules → modules}/debug/transactions.js +0 -0
  30. package/dist/cjs/{src/modules → modules}/feed.js +0 -0
  31. package/dist/cjs/{src/modules → modules}/pinning.js +1 -5
  32. package/dist/cjs/{src/modules → modules}/pss.js +0 -0
  33. package/dist/cjs/{src/modules → modules}/soc.js +0 -0
  34. package/dist/cjs/{src/modules → modules}/status.js +0 -0
  35. package/dist/cjs/{src/modules → modules}/stewardship.js +0 -0
  36. package/dist/cjs/{src/modules → modules}/tag.js +0 -0
  37. package/dist/cjs/{src/types → types}/debug.js +0 -0
  38. package/dist/cjs/{src/types → types}/index.js +5 -1
  39. package/dist/cjs/{src/types → types}/ky-options.js +0 -0
  40. package/dist/cjs/{src/types → types}/ky-universal/common.js +0 -0
  41. package/dist/cjs/{src/types → types}/ky-universal/hooks.js +0 -0
  42. package/dist/cjs/{src/types → types}/ky-universal/retry.js +0 -0
  43. package/dist/cjs/{src/utils → utils}/bytes.js +0 -0
  44. package/dist/cjs/{src/utils → utils}/collection.browser.js +0 -0
  45. package/dist/cjs/{src/utils → utils}/collection.js +0 -0
  46. package/dist/cjs/{src/utils → utils}/collection.node.js +0 -0
  47. package/dist/cjs/{src/utils → utils}/data.browser.js +0 -0
  48. package/dist/cjs/{src/utils → utils}/data.js +0 -0
  49. package/dist/cjs/{src/utils → utils}/error.js +0 -0
  50. package/dist/cjs/{src/utils → utils}/eth.js +0 -0
  51. package/dist/cjs/{src/utils → utils}/expose.js +0 -0
  52. package/dist/cjs/{src/utils → utils}/file.js +0 -0
  53. package/dist/cjs/{src/utils → utils}/hash.js +0 -0
  54. package/dist/cjs/{src/utils → utils}/headers.js +0 -0
  55. package/dist/cjs/{src/utils → utils}/hex.js +0 -0
  56. package/dist/cjs/{src/utils → utils}/http.js +0 -0
  57. package/dist/cjs/{src/utils → utils}/merge.js +0 -0
  58. package/dist/cjs/{src/utils → utils}/pss.js +0 -0
  59. package/dist/cjs/{src/utils → utils}/reference.js +0 -0
  60. package/dist/cjs/utils/sleep.js +23 -0
  61. package/dist/cjs/{src/utils → utils}/stamps.js +0 -0
  62. package/dist/cjs/{src/utils → utils}/stream.js +0 -0
  63. package/dist/cjs/{src/utils → utils}/tar.js +0 -0
  64. package/dist/cjs/{src/utils → utils}/type.js +1 -1
  65. package/dist/cjs/{src/utils → utils}/uint64.js +0 -0
  66. package/dist/cjs/{src/utils → utils}/url.js +0 -0
  67. package/dist/index.browser.min.js +1 -1
  68. package/dist/index.browser.min.js.map +1 -1
  69. package/dist/mjs/{src/bee-debug.js → bee-debug.js} +2 -2
  70. package/dist/mjs/{src/bee.js → bee.js} +4 -2
  71. package/dist/mjs/{src/chunk → chunk}/bmt.js +0 -0
  72. package/dist/mjs/{src/chunk → chunk}/cac.js +0 -0
  73. package/dist/mjs/{src/chunk → chunk}/serialize.js +0 -0
  74. package/dist/mjs/{src/chunk → chunk}/signer.js +0 -0
  75. package/dist/mjs/{src/chunk → chunk}/soc.js +0 -0
  76. package/dist/mjs/{src/chunk → chunk}/span.js +0 -0
  77. package/dist/mjs/{src/feed → feed}/identifier.js +0 -0
  78. package/dist/mjs/{src/feed → feed}/index.js +0 -0
  79. package/dist/mjs/{src/feed → feed}/json.js +0 -0
  80. package/dist/mjs/{src/feed → feed}/retrievable.js +0 -0
  81. package/dist/mjs/{src/feed → feed}/topic.js +0 -0
  82. package/dist/mjs/{src/feed → feed}/type.js +0 -0
  83. package/dist/mjs/{src/index.js → index.js} +0 -0
  84. package/dist/mjs/{src/modules → modules}/bytes.js +0 -0
  85. package/dist/mjs/{src/modules → modules}/bzz.js +0 -0
  86. package/dist/mjs/{src/modules → modules}/chunk.js +0 -0
  87. package/dist/mjs/{src/modules → modules}/debug/balance.js +0 -0
  88. package/dist/mjs/{src/modules → modules}/debug/chequebook.js +0 -0
  89. package/dist/mjs/{src/modules → modules}/debug/chunk.js +0 -0
  90. package/dist/mjs/{src/modules → modules}/debug/connectivity.js +2 -2
  91. package/dist/mjs/{src/modules → modules}/debug/settlements.js +0 -0
  92. package/dist/mjs/{src/modules → modules}/debug/stamps.js +1 -1
  93. package/dist/mjs/{src/modules → modules}/debug/states.js +0 -0
  94. package/dist/mjs/{src/modules → modules}/debug/status.js +3 -3
  95. package/dist/mjs/{src/modules → modules}/debug/tag.js +0 -0
  96. package/dist/mjs/{src/modules → modules}/debug/transactions.js +0 -0
  97. package/dist/mjs/{src/modules → modules}/feed.js +0 -0
  98. package/dist/mjs/{src/modules → modules}/pinning.js +1 -7
  99. package/dist/mjs/{src/modules → modules}/pss.js +0 -0
  100. package/dist/mjs/{src/modules → modules}/soc.js +0 -0
  101. package/dist/mjs/{src/modules → modules}/status.js +0 -0
  102. package/dist/mjs/{src/modules → modules}/stewardship.js +0 -0
  103. package/dist/mjs/{src/modules → modules}/tag.js +0 -0
  104. package/dist/mjs/{src/types → types}/debug.js +0 -0
  105. package/dist/mjs/{src/types → types}/index.js +0 -0
  106. package/dist/mjs/{src/types → types}/ky-options.js +0 -0
  107. package/dist/mjs/{src/types → types}/ky-universal/common.js +0 -0
  108. package/dist/mjs/{src/types → types}/ky-universal/hooks.js +0 -0
  109. package/dist/mjs/{src/types → types}/ky-universal/retry.js +0 -0
  110. package/dist/mjs/{src/utils → utils}/bytes.js +0 -0
  111. package/dist/mjs/{src/utils → utils}/collection.browser.js +0 -0
  112. package/dist/mjs/{src/utils → utils}/collection.js +0 -0
  113. package/dist/mjs/{src/utils → utils}/collection.node.js +0 -0
  114. package/dist/mjs/{src/utils → utils}/data.browser.js +0 -0
  115. package/dist/mjs/{src/utils → utils}/data.js +0 -0
  116. package/dist/mjs/{src/utils → utils}/error.js +0 -0
  117. package/dist/mjs/{src/utils → utils}/eth.js +0 -0
  118. package/dist/mjs/{src/utils → utils}/expose.js +0 -0
  119. package/dist/mjs/{src/utils → utils}/file.js +0 -0
  120. package/dist/mjs/{src/utils → utils}/hash.js +0 -0
  121. package/dist/mjs/{src/utils → utils}/headers.js +0 -0
  122. package/dist/mjs/{src/utils → utils}/hex.js +0 -0
  123. package/dist/mjs/{src/utils → utils}/http.js +0 -0
  124. package/dist/mjs/{src/utils → utils}/merge.js +0 -0
  125. package/dist/mjs/{src/utils → utils}/pss.js +0 -0
  126. package/dist/mjs/{src/utils → utils}/reference.js +0 -0
  127. package/dist/mjs/utils/sleep.js +43 -0
  128. package/dist/mjs/{src/utils → utils}/stamps.js +0 -0
  129. package/dist/mjs/{src/utils → utils}/stream.js +0 -0
  130. package/dist/mjs/{src/utils → utils}/tar.js +0 -0
  131. package/dist/mjs/{src/utils → utils}/type.js +1 -1
  132. package/dist/mjs/{src/utils → utils}/uint64.js +0 -0
  133. package/dist/mjs/{src/utils → utils}/url.js +0 -0
  134. package/dist/types/{src/bee-debug.d.ts → bee-debug.d.ts} +0 -0
  135. package/dist/types/{src/bee.d.ts → bee.d.ts} +2 -3
  136. package/dist/types/{src/chunk → chunk}/bmt.d.ts +0 -0
  137. package/dist/types/{src/chunk → chunk}/cac.d.ts +0 -0
  138. package/dist/types/{src/chunk → chunk}/serialize.d.ts +0 -0
  139. package/dist/types/{src/chunk → chunk}/signer.d.ts +0 -0
  140. package/dist/types/{src/chunk → chunk}/soc.d.ts +0 -0
  141. package/dist/types/{src/chunk → chunk}/span.d.ts +0 -0
  142. package/dist/types/{src/feed → feed}/identifier.d.ts +0 -0
  143. package/dist/types/{src/feed → feed}/index.d.ts +0 -0
  144. package/dist/types/{src/feed → feed}/json.d.ts +0 -0
  145. package/dist/types/{src/feed → feed}/retrievable.d.ts +0 -0
  146. package/dist/types/{src/feed → feed}/topic.d.ts +0 -0
  147. package/dist/types/{src/feed → feed}/type.d.ts +0 -0
  148. package/dist/types/{src/index.d.ts → index.d.ts} +0 -0
  149. package/dist/types/{src/modules → modules}/bytes.d.ts +0 -0
  150. package/dist/types/{src/modules → modules}/bzz.d.ts +0 -0
  151. package/dist/types/{src/modules → modules}/chunk.d.ts +0 -0
  152. package/dist/types/{src/modules → modules}/debug/balance.d.ts +0 -0
  153. package/dist/types/{src/modules → modules}/debug/chequebook.d.ts +0 -0
  154. package/dist/types/{src/modules → modules}/debug/chunk.d.ts +0 -0
  155. package/dist/types/{src/modules → modules}/debug/connectivity.d.ts +0 -0
  156. package/dist/types/{src/modules → modules}/debug/settlements.d.ts +0 -0
  157. package/dist/types/{src/modules → modules}/debug/stamps.d.ts +0 -0
  158. package/dist/types/{src/modules → modules}/debug/states.d.ts +0 -0
  159. package/dist/types/{src/modules → modules}/debug/status.d.ts +3 -3
  160. package/dist/types/{src/modules → modules}/debug/tag.d.ts +0 -0
  161. package/dist/types/{src/modules → modules}/debug/transactions.d.ts +0 -0
  162. package/dist/types/{src/modules → modules}/feed.d.ts +0 -0
  163. package/dist/types/{src/modules → modules}/pinning.d.ts +1 -1
  164. package/dist/types/{src/modules → modules}/pss.d.ts +0 -0
  165. package/dist/types/{src/modules → modules}/soc.d.ts +0 -0
  166. package/dist/types/{src/modules → modules}/status.d.ts +0 -0
  167. package/dist/types/{src/modules → modules}/stewardship.d.ts +0 -0
  168. package/dist/types/{src/modules → modules}/tag.d.ts +0 -0
  169. package/dist/types/{src/types → types}/debug.d.ts +2 -7
  170. package/dist/types/{src/types → types}/index.d.ts +25 -8
  171. package/dist/types/{src/types → types}/ky-options.d.ts +0 -0
  172. package/dist/types/{src/types → types}/ky-universal/common.d.ts +0 -0
  173. package/dist/types/{src/types → types}/ky-universal/hooks.d.ts +0 -0
  174. package/dist/types/{src/types → types}/ky-universal/retry.d.ts +0 -0
  175. package/dist/types/{src/utils → utils}/bytes.d.ts +0 -0
  176. package/dist/types/{src/utils → utils}/collection.browser.d.ts +0 -0
  177. package/dist/types/{src/utils → utils}/collection.d.ts +0 -0
  178. package/dist/types/{src/utils → utils}/collection.node.d.ts +0 -0
  179. package/dist/types/{src/utils → utils}/data.browser.d.ts +0 -0
  180. package/dist/types/{src/utils → utils}/data.d.ts +0 -0
  181. package/dist/types/{src/utils → utils}/error.d.ts +0 -0
  182. package/dist/types/{src/utils → utils}/eth.d.ts +0 -0
  183. package/dist/types/{src/utils → utils}/expose.d.ts +0 -0
  184. package/dist/types/{src/utils → utils}/file.d.ts +0 -0
  185. package/dist/types/{src/utils → utils}/hash.d.ts +0 -0
  186. package/dist/types/{src/utils → utils}/headers.d.ts +0 -0
  187. package/dist/types/{src/utils → utils}/hex.d.ts +0 -0
  188. package/dist/types/{src/utils → utils}/http.d.ts +0 -0
  189. package/dist/types/{src/utils → utils}/merge.d.ts +0 -0
  190. package/dist/types/{src/utils → utils}/pss.d.ts +0 -0
  191. package/dist/types/{src/utils → utils}/reference.d.ts +0 -0
  192. package/dist/types/utils/sleep.d.ts +6 -0
  193. package/dist/types/{src/utils → utils}/stamps.d.ts +0 -0
  194. package/dist/types/{src/utils → utils}/stream.d.ts +0 -0
  195. package/dist/types/{src/utils → utils}/tar.d.ts +0 -0
  196. package/dist/types/{src/utils → utils}/type.d.ts +6 -2
  197. package/dist/types/{src/utils → utils}/uint64.d.ts +0 -0
  198. package/dist/types/{src/utils → utils}/url.d.ts +0 -0
  199. package/package.json +10 -10
  200. package/dist/cjs/test/utils.js +0 -419
  201. package/dist/mjs/test/utils.js +0 -458
  202. package/dist/types/test/utils.d.ts +0 -119
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "4.1.0",
3
+ "version": "5.0.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -77,16 +77,16 @@
77
77
  "tar-js": "^0.3.0",
78
78
  "utf-8-validate": "^5.0.9",
79
79
  "web-streams-polyfill": "^4.0.0-beta.1",
80
- "ws": "^8.6.0"
80
+ "ws": "^8.7.0"
81
81
  },
82
82
  "devDependencies": {
83
83
  "@babel/cli": "^7.17.10",
84
- "@babel/core": "^7.17.9",
84
+ "@babel/core": "^7.18.2",
85
85
  "@babel/plugin-proposal-class-properties": "^7.16.7",
86
86
  "@babel/plugin-transform-runtime": "^7.17.0",
87
87
  "@babel/preset-env": "^7.17.10",
88
88
  "@babel/preset-typescript": "^7.14.5",
89
- "@commitlint/cli": "^16.2.3",
89
+ "@commitlint/cli": "^17.0.2",
90
90
  "@commitlint/config-conventional": "^16.2.1",
91
91
  "@ethersphere/bee-factory": "^0.4.1",
92
92
  "@fluffy-spoon/substitute": "^1.208.0",
@@ -126,17 +126,17 @@
126
126
  "puppeteer": "^14.1.0",
127
127
  "rimraf": "^3.0.2",
128
128
  "terser-webpack-plugin": "^5.3.1",
129
- "ts-node": "^10.7.0",
129
+ "ts-node": "^10.8.0",
130
130
  "typescript": "^4.5.4",
131
- "webpack": "^5.72.0",
131
+ "webpack": "^5.72.1",
132
132
  "webpack-bundle-analyzer": "^4.5.0",
133
133
  "webpack-cli": "^4.9.2"
134
134
  },
135
135
  "engines": {
136
- "node": ">=12.0.0",
136
+ "node": ">=14.0.0",
137
137
  "npm": ">=6.0.0",
138
- "beeApiVersion": "3.0.1",
139
- "beeDebugApiVersion": "2.0.1",
140
- "bee": "1.6.0-6ceadd35"
138
+ "beeApiVersion": "3.0.2",
139
+ "beeDebugApiVersion": "3.0.2",
140
+ "bee": "1.7.0-bbf13011"
141
141
  }
142
142
  }
@@ -1,419 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
- }) : (function(o, m, k, k2) {
6
- if (k2 === undefined) k2 = k;
7
- o[k2] = m[k];
8
- }));
9
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
- Object.defineProperty(o, "default", { enumerable: true, value: v });
11
- }) : function(o, v) {
12
- o["default"] = v;
13
- });
14
- var __importStar = (this && this.__importStar) || function (mod) {
15
- if (mod && mod.__esModule) return mod;
16
- var result = {};
17
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
- __setModuleDefault(result, mod);
19
- return result;
20
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __importDefault = (this && this.__importDefault) || function (mod) {
31
- return (mod && mod.__esModule) ? mod : { "default": mod };
32
- };
33
- Object.defineProperty(exports, "__esModule", { value: true });
34
- exports.testIdentity = exports.testJsonEns = exports.testJsonCid = exports.testJsonHash = exports.testJsonStringPayload = exports.testJsonPayload = exports.testBatchId = exports.testAddress = exports.testChunkHash = exports.testChunkData = exports.testChunkSpan = exports.testChunkPayload = exports.WAITING_USABLE_STAMP_TIMEOUT = exports.BLOCKCHAIN_TRANSACTION_TIMEOUT = exports.FEED_TIMEOUT = exports.PSS_TIMEOUT = exports.BIG_FILE_TIMEOUT = exports.ERR_TIMEOUT = exports.createdResponse = exports.okResponse = exports.invalidReference = exports.makeTestTarget = exports.getOrCreatePostageBatch = exports.waitForBatchToBeUsable = exports.shorten = exports.tryDeleteChunkFromLocalStorage = exports.beePeerDebugKy = exports.beePeerDebugUrl = exports.beeDebugKy = exports.beeDebugUrl = exports.getPostageBatch = exports.beePeerKy = exports.beePeerUrl = exports.beeKy = exports.beeUrl = exports.randomByteArray = exports.createReadableStream = exports.createRandomNodeReadable = exports.readWholeUint8ArrayReadableStream = exports.sleep = exports.commonMatchers = void 0;
35
- const stream_1 = require("stream");
36
- const web_streams_polyfill_1 = require("web-streams-polyfill");
37
- const ky_universal_1 = __importDefault(require("ky-universal"));
38
- const hex_1 = require("../src/utils/hex");
39
- const chunk_1 = require("../src/modules/debug/chunk");
40
- const src_1 = require("../src");
41
- const bytes_1 = require("../src/utils/bytes");
42
- const stamps = __importStar(require("../src/modules/debug/stamps"));
43
- /**
44
- * Load common own Jest Matchers which can be used to check particular return values.
45
- */
46
- function commonMatchers() {
47
- expect.extend({
48
- toBeHashReference(received) {
49
- const result = {
50
- pass: false,
51
- message: () => 'Given input is not a Swarm hash reference',
52
- };
53
- if (typeof received === 'string' && /^[0-9a-fA-F]{64}$/.test(received)) {
54
- result.pass = true;
55
- result.message = () => 'Given string is semantically valid Swarm hash reference';
56
- }
57
- return result;
58
- },
59
- toBeBeeResponse(received, expectedStatusCode) {
60
- const result = {
61
- pass: false,
62
- message: () => `Bee response does not have status code ${expectedStatusCode}. Got: ${received.code}\nResponse message: ${received.message}`,
63
- };
64
- if (received.code === expectedStatusCode) {
65
- result.pass = true;
66
- result.message = () => 'Bee response meets with its requirements';
67
- }
68
- return result;
69
- },
70
- toBeOneOf(received, argument) {
71
- const validValues = Array.isArray(argument) ? argument : [argument];
72
- let containsValidValue = false;
73
- for (const validValue of validValues) {
74
- try {
75
- expect(received).toEqual(validValue);
76
- containsValidValue = true;
77
- // eslint-disable-next-line no-empty
78
- }
79
- catch (e) { }
80
- }
81
- if (containsValidValue) {
82
- return {
83
- message: () => `expected ${JSON.stringify(received)} not to be one of [${validValues.join(', ')}]`,
84
- pass: true,
85
- };
86
- }
87
- return {
88
- message: () => `expected ${JSON.stringify(received)} to be one of [${validValues.join(', ')}]`,
89
- pass: false,
90
- };
91
- },
92
- toBeType(received, argument) {
93
- const initialType = typeof received;
94
- const isArray = Array.isArray(received) ? 'array' : initialType;
95
- const type = initialType === 'object' ? isArray : initialType;
96
- return type === argument
97
- ? {
98
- message: () => `expected ${received} to be type ${argument}`,
99
- pass: true,
100
- }
101
- : {
102
- message: () => `expected ${received} to be type ${argument}`,
103
- pass: false,
104
- };
105
- },
106
- toBeNumberString(received) {
107
- const message = () => `expected ${received} to be a number in a string type`;
108
- return /^-?(0|[1-9][0-9]*)$/g.test(received)
109
- ? {
110
- message,
111
- pass: true,
112
- }
113
- : {
114
- message,
115
- pass: false,
116
- };
117
- },
118
- });
119
- }
120
- exports.commonMatchers = commonMatchers;
121
- /**
122
- * Sleep for N miliseconds
123
- *
124
- * @param ms Number of miliseconds to sleep
125
- */
126
- function sleep(ms) {
127
- return __awaiter(this, void 0, void 0, function* () {
128
- return new Promise(resolve => setTimeout(() => resolve(), ms));
129
- });
130
- }
131
- exports.sleep = sleep;
132
- /**
133
- * Helper function that reads whole content of ReadableStream
134
- * @param stream
135
- */
136
- function readWholeUint8ArrayReadableStream(stream) {
137
- return __awaiter(this, void 0, void 0, function* () {
138
- const reader = stream.getReader();
139
- let buff = [];
140
- let readResult;
141
- do {
142
- readResult = yield reader.read();
143
- if (readResult.value)
144
- buff = [...buff, ...readResult.value];
145
- } while (!readResult.done);
146
- return new Uint8Array(buff);
147
- });
148
- }
149
- exports.readWholeUint8ArrayReadableStream = readWholeUint8ArrayReadableStream;
150
- function createRandomNodeReadable(totalSize, chunkSize = 1000) {
151
- if (totalSize % chunkSize !== 0) {
152
- throw new Error(`totalSize ${totalSize} is not dividable without remainder by chunkSize ${chunkSize}`);
153
- }
154
- const stream = new stream_1.Readable();
155
- // eslint-disable-next-line @typescript-eslint/no-empty-function
156
- stream._read = () => { };
157
- for (let i = 0; i < totalSize / chunkSize; i++) {
158
- stream.push(randomByteArray(chunkSize));
159
- }
160
- stream.push(null);
161
- return stream;
162
- }
163
- exports.createRandomNodeReadable = createRandomNodeReadable;
164
- function createReadableStream(iterable) {
165
- const iter = iterable[Symbol.iterator]();
166
- return new web_streams_polyfill_1.ReadableStream({
167
- pull(controller) {
168
- return __awaiter(this, void 0, void 0, function* () {
169
- const result = iter.next();
170
- if (result.done) {
171
- controller.close();
172
- return;
173
- }
174
- controller.enqueue(result.value);
175
- });
176
- },
177
- });
178
- }
179
- exports.createReadableStream = createReadableStream;
180
- /**
181
- * Lehmer random number generator with seed (minstd_rand in C++11)
182
- * !!! Very fast but not well distributed pseudo-random function !!!
183
- *
184
- * @param seed Seed for the pseudo-random generator
185
- */
186
- function lrng(seed) {
187
- return () => ((Math.pow(2, 31) - 1) & (seed = Math.imul(48271, seed))) / Math.pow(2, 31);
188
- }
189
- /**
190
- * Utility function for generating random Buffer
191
- * !!! IT IS NOT CRYPTO SAFE !!!
192
- * For that use `crypto.randomBytes()`
193
- *
194
- * @param length Number of bytes to generate
195
- * @param seed Seed for the pseudo-random generator
196
- */
197
- function randomByteArray(length, seed = 500) {
198
- const rand = lrng(seed);
199
- const buf = new Uint8Array(length);
200
- for (let i = 0; i < length; ++i) {
201
- buf[i] = (rand() * 0xff) << 0;
202
- }
203
- return buf;
204
- }
205
- exports.randomByteArray = randomByteArray;
206
- /**
207
- * Returns a url for testing the Bee public API
208
- */
209
- function beeUrl() {
210
- return process.env.BEE_API_URL || 'http://127.0.0.1:1633';
211
- }
212
- exports.beeUrl = beeUrl;
213
- function beeKy() {
214
- return ky_universal_1.default.create({ prefixUrl: beeUrl(), timeout: false });
215
- }
216
- exports.beeKy = beeKy;
217
- /**
218
- * Returns a url of another peer for testing the Bee public API
219
- */
220
- function beePeerUrl() {
221
- return process.env.BEE_PEER_API_URL || 'http://127.0.0.1:11633';
222
- }
223
- exports.beePeerUrl = beePeerUrl;
224
- function beePeerKy() {
225
- return ky_universal_1.default.create({ prefixUrl: beePeerUrl(), timeout: false });
226
- }
227
- exports.beePeerKy = beePeerKy;
228
- /**
229
- * Helper function that create monster batch for all the tests.
230
- * There is semaphore mechanism that allows only creation of one batch across all the
231
- * parallel running tests that have to wait until it is created.
232
- */
233
- function getPostageBatch(url = beeDebugUrl()) {
234
- let stamp;
235
- switch (url) {
236
- case beeDebugUrl():
237
- stamp = process.env.BEE_POSTAGE;
238
- break;
239
- case beePeerDebugUrl():
240
- stamp = process.env.BEE_PEER_POSTAGE;
241
- break;
242
- default:
243
- throw new Error('Unknown URL ' + url);
244
- }
245
- if (!stamp) {
246
- throw new Error('There is no postage stamp configured for URL ' + url);
247
- }
248
- return stamp;
249
- }
250
- exports.getPostageBatch = getPostageBatch;
251
- /**
252
- * Returns a url for testing the Bee Debug API
253
- */
254
- function beeDebugUrl() {
255
- return process.env.BEE_DEBUG_API_URL || 'http://127.0.0.1:1635';
256
- }
257
- exports.beeDebugUrl = beeDebugUrl;
258
- function beeDebugKy() {
259
- return ky_universal_1.default.create({ prefixUrl: beeDebugUrl(), timeout: false });
260
- }
261
- exports.beeDebugKy = beeDebugKy;
262
- /**
263
- * Returns a url for testing the Bee Debug API
264
- */
265
- function beePeerDebugUrl() {
266
- return process.env.BEE_PEER_DEBUG_API_URL || 'http://127.0.0.1:11635';
267
- }
268
- exports.beePeerDebugUrl = beePeerDebugUrl;
269
- function beePeerDebugKy() {
270
- return ky_universal_1.default.create({ prefixUrl: beePeerDebugUrl(), timeout: false });
271
- }
272
- exports.beePeerDebugKy = beePeerDebugKy;
273
- /**
274
- * Try to delete a chunk from local storage, ignoring all errors
275
- *
276
- * @param address Swarm address of chunk
277
- */
278
- function tryDeleteChunkFromLocalStorage(address) {
279
- return __awaiter(this, void 0, void 0, function* () {
280
- if (typeof address !== 'string') {
281
- (0, bytes_1.assertBytes)(address, 32);
282
- address = (0, hex_1.bytesToHex)(address);
283
- }
284
- try {
285
- yield (0, chunk_1.deleteChunkFromLocalStorage)(beeDebugKy(), address);
286
- }
287
- catch (e) {
288
- // ignore not found errors
289
- if (e instanceof src_1.BeeResponseError && e.status === 404) {
290
- return;
291
- }
292
- throw e;
293
- }
294
- });
295
- }
296
- exports.tryDeleteChunkFromLocalStorage = tryDeleteChunkFromLocalStorage;
297
- /**
298
- * Formatting utility for displaying long strings like hexstrings.
299
- *
300
- * @param inputStr
301
- * @param len
302
- */
303
- function shorten(inputStr, len = 17) {
304
- const str = typeof inputStr === 'string' ? inputStr : inputStr.toString();
305
- if (str.length <= len) {
306
- return str;
307
- }
308
- return `${str.slice(0, 6)}...${str.slice(-6)} (length: ${str.length})`;
309
- }
310
- exports.shorten = shorten;
311
- function timeout(ms, message = 'Execution reached timeout!') {
312
- return __awaiter(this, void 0, void 0, function* () {
313
- yield sleep(ms);
314
- throw new Error(message);
315
- });
316
- }
317
- function waitForBatchToBeUsable(batchId, pollingInterval = 200) {
318
- return __awaiter(this, void 0, void 0, function* () {
319
- yield Promise.race([
320
- timeout(USABLE_TIMEOUT, 'Awaiting of usable postage batch timed out!'),
321
- () => __awaiter(this, void 0, void 0, function* () {
322
- let stamp;
323
- do {
324
- yield sleep(pollingInterval);
325
- stamp = yield stamps.getPostageBatch(beeDebugKy(), batchId);
326
- } while (!stamp.usable);
327
- }),
328
- ]);
329
- });
330
- }
331
- exports.waitForBatchToBeUsable = waitForBatchToBeUsable;
332
- const DEFAULT_BATCH_AMOUNT = '1';
333
- const DEFAULT_BATCH_DEPTH = 17;
334
- /**
335
- * Returns already existing batch or will create one.
336
- *
337
- * If some specification is passed then it is guaranteed that the batch will have this property(ies)
338
- *
339
- * @param amount
340
- * @param depth
341
- * @param immutable
342
- */
343
- function getOrCreatePostageBatch(amount, depth, immutable) {
344
- return __awaiter(this, void 0, void 0, function* () {
345
- // Non-usable stamps are ignored by Bee
346
- const allUsableStamps = (yield stamps.getAllPostageBatches(beeDebugKy())).filter(stamp => stamp.usable);
347
- if (allUsableStamps.length === 0) {
348
- const batchId = yield stamps.createPostageBatch(beeDebugKy(), amount !== null && amount !== void 0 ? amount : DEFAULT_BATCH_AMOUNT, depth !== null && depth !== void 0 ? depth : DEFAULT_BATCH_DEPTH);
349
- yield waitForBatchToBeUsable(batchId);
350
- return stamps.getPostageBatch(beeDebugKy(), batchId);
351
- }
352
- // User does not want any specific batch, lets give him the first one
353
- if (amount === undefined && depth === undefined && immutable === undefined) {
354
- return allUsableStamps[0];
355
- }
356
- // User wants some specific batch
357
- for (const stamp of allUsableStamps) {
358
- let meetingAllCriteria = false;
359
- if (amount !== undefined) {
360
- meetingAllCriteria = amount === stamp.amount;
361
- }
362
- else {
363
- meetingAllCriteria = true;
364
- }
365
- if (depth !== undefined) {
366
- meetingAllCriteria = meetingAllCriteria && depth === stamp.depth;
367
- }
368
- if (immutable !== undefined) {
369
- meetingAllCriteria = meetingAllCriteria && immutable === stamp.immutableFlag;
370
- }
371
- if (meetingAllCriteria) {
372
- return stamp;
373
- }
374
- }
375
- // No stamp meeting the criteria was found ==> we need to create a new one
376
- const batchId = yield stamps.createPostageBatch(beeDebugKy(), amount !== null && amount !== void 0 ? amount : DEFAULT_BATCH_AMOUNT, depth !== null && depth !== void 0 ? depth : DEFAULT_BATCH_DEPTH);
377
- yield waitForBatchToBeUsable(batchId);
378
- return stamps.getPostageBatch(beeDebugKy(), batchId);
379
- });
380
- }
381
- exports.getOrCreatePostageBatch = getOrCreatePostageBatch;
382
- function makeTestTarget(target) {
383
- return target.slice(0, 2);
384
- }
385
- exports.makeTestTarget = makeTestTarget;
386
- exports.invalidReference = '0000000000000000000000000000000000000000000000000000000000000000';
387
- exports.okResponse = {
388
- code: 200,
389
- message: 'OK',
390
- };
391
- exports.createdResponse = {
392
- code: 201,
393
- message: 'Created',
394
- };
395
- const USABLE_TIMEOUT = 7000;
396
- exports.ERR_TIMEOUT = 40000;
397
- exports.BIG_FILE_TIMEOUT = 100000;
398
- exports.PSS_TIMEOUT = 120000;
399
- exports.FEED_TIMEOUT = 120000;
400
- exports.BLOCKCHAIN_TRANSACTION_TIMEOUT = 40000;
401
- exports.WAITING_USABLE_STAMP_TIMEOUT = 130000;
402
- exports.testChunkPayload = new Uint8Array([1, 2, 3]);
403
- // span is the payload length encoded as uint64 little endian
404
- exports.testChunkSpan = new Uint8Array([exports.testChunkPayload.length, 0, 0, 0, 0, 0, 0, 0]);
405
- exports.testChunkData = new Uint8Array([...exports.testChunkSpan, ...exports.testChunkPayload]);
406
- // the hash is hardcoded because we would need the bmt hasher otherwise
407
- exports.testChunkHash = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
408
- exports.testAddress = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
409
- exports.testBatchId = 'ca6357a08e317d15ec560fef34e4c45f8f19f01c372aa70f1da72bfa7f1a4338';
410
- exports.testJsonPayload = [{ some: 'object' }];
411
- exports.testJsonStringPayload = JSON.stringify(exports.testJsonPayload);
412
- exports.testJsonHash = '872a858115b8bee4408b1427b49e472883fdc2512d5a8f2d428b97ecc8f7ccfa';
413
- exports.testJsonCid = 'bah5acgzaq4vilaivxc7oiqelcqt3jhshfcb73qsrfvni6lkcrol6zshxzt5a';
414
- exports.testJsonEns = 'testing.eth';
415
- exports.testIdentity = {
416
- privateKey: '634fb5a872396d9693e5c9f9d7233cfa93f395c093371017ff44aa9ae6564cdd',
417
- publicKey: '03c32bb011339667a487b6c1c35061f15f7edc36aa9a0f8648aba07a4b8bd741b4',
418
- address: '8d3766440f0d7b949a5e32995d09619a7f86e632',
419
- };