@ethersphere/bee-js 9.7.1 → 9.8.1

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.
@@ -1,6 +1,8 @@
1
1
  import { Binary, MerkleTree, Optional, Uint8ArrayReader } from 'cafe-utility';
2
+ import _debug from 'debug';
2
3
  import { NULL_ADDRESS } from "../index.js";
3
4
  import { Reference } from "../utils/typed-bytes.js";
5
+ const debug = _debug('bee-js:manifest');
4
6
  const ENCODER = new TextEncoder();
5
7
  const DECODER = new TextDecoder();
6
8
  const TYPE_VALUE = 2;
@@ -60,6 +62,11 @@ export class Fork {
60
62
  data.push(new Uint8Array(30 - this.prefix.length));
61
63
  }
62
64
  data.push(this.node.selfAddress);
65
+ debug('marshalling fork', {
66
+ prefixLength: this.prefix.length,
67
+ prefix: DECODER.decode(this.prefix),
68
+ address: Binary.uint8ArrayToHex(this.node.selfAddress)
69
+ });
63
70
  if (this.node.metadata) {
64
71
  const metadataBytes = Binary.padEndToMultiple(new Uint8Array([0x00, 0x00, ...ENCODER.encode(JSON.stringify(this.node.metadata))]), 32, 0x0a);
65
72
  const metadataLengthBytes = Binary.numberToUint16(metadataBytes.length - 2, 'BE');
@@ -72,8 +79,17 @@ export class Fork {
72
79
  const type = Binary.uint8ToNumber(reader.read(1));
73
80
  const prefixLength = Binary.uint8ToNumber(reader.read(1));
74
81
  const prefix = reader.read(prefixLength);
75
- reader.read(30 - prefixLength);
82
+ if (prefixLength < 30) {
83
+ reader.read(30 - prefixLength);
84
+ }
76
85
  const selfAddress = reader.read(addressLength);
86
+ debug('unmarshalling fork', {
87
+ type,
88
+ prefixLength,
89
+ prefix: DECODER.decode(prefix),
90
+ addressLength,
91
+ address: Binary.uint8ArrayToHex(selfAddress)
92
+ });
77
93
  let metadata = undefined;
78
94
  if (isType(type, TYPE_WITH_METADATA)) {
79
95
  const metadataLength = Binary.uint16ToNumber(reader.read(2), 'BE');
@@ -210,7 +226,7 @@ export class MantarayNode {
210
226
  throw new Error('MantarayNode#unmarshal invalid version hash');
211
227
  }
212
228
  const targetAddressLength = Binary.uint8ToNumber(reader.read(1));
213
- const targetAddress = targetAddressLength === 0 ? NULL_ADDRESS : reader.read(targetAddressLength);
229
+ const targetAddress = targetAddressLength ? reader.read(targetAddressLength) : NULL_ADDRESS;
214
230
  const node = new MantarayNode({
215
231
  selfAddress,
216
232
  targetAddress,
@@ -219,7 +235,7 @@ export class MantarayNode {
219
235
  const forkBitmap = reader.read(32);
220
236
  for (let i = 0; i < 256; i++) {
221
237
  if (Binary.getBit(forkBitmap, i, 'LE')) {
222
- const newFork = Fork.unmarshal(reader, targetAddressLength);
238
+ const newFork = Fork.unmarshal(reader, selfAddress.length);
223
239
  node.forks.set(i, newFork);
224
240
  newFork.node.parent = node;
225
241
  }
@@ -232,6 +248,10 @@ export class MantarayNode {
232
248
  addFork(path, reference, metadata) {
233
249
  this.selfAddress = null;
234
250
  path = path instanceof Uint8Array ? path : ENCODER.encode(path);
251
+ debug('adding fork', {
252
+ path: DECODER.decode(path),
253
+ reference: new Reference(reference).represent()
254
+ });
235
255
  // TODO: this should not be ignored
236
256
  // eslint-disable-next-line @typescript-eslint/no-this-alias
237
257
  let tip = this;
@@ -1,6 +1,8 @@
1
1
  import axios from 'axios';
2
2
  import { Dates, Objects, Strings, System } from 'cafe-utility';
3
+ import _debug from 'debug';
3
4
  import { BeeResponseError } from "../index.js";
5
+ const debug = _debug('bee-js:http');
4
6
  const {
5
7
  AxiosError
6
8
  } = axios;
@@ -37,6 +39,12 @@ export async function http(options, config) {
37
39
  let failedAttempts = 0;
38
40
  while (failedAttempts < MAX_FAILED_ATTEMPTS) {
39
41
  try {
42
+ debug(`${requestConfig.method || 'get'} ${Strings.joinUrl([requestConfig.baseURL, requestConfig.url])}`, {
43
+ headers: {
44
+ ...requestConfig.headers
45
+ },
46
+ params: requestConfig.params
47
+ });
40
48
  maybeRunOnRequestHook(options, requestConfig);
41
49
  const response = await axios(requestConfig);
42
50
  return response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "9.7.1",
3
+ "version": "9.8.1",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",
@@ -63,6 +63,7 @@
63
63
  "dependencies": {
64
64
  "axios": "^0.30.0",
65
65
  "cafe-utility": "^31.0.0",
66
+ "debug": "^4.4.1",
66
67
  "isomorphic-ws": "^4.0.1",
67
68
  "semver": "^7.3.5",
68
69
  "ws": "^8.7.0"
@@ -78,6 +79,7 @@
78
79
  "@commitlint/config-conventional": "^17.4.2",
79
80
  "@jest/types": "^29.6.3",
80
81
  "@naholyr/cross-env": "^1.0.0",
82
+ "@types/debug": "^4.1.12",
81
83
  "@types/jest": "^29.5.13",
82
84
  "@types/node": "^18.11.11",
83
85
  "@types/semver": "^7.3.9",