@ethersphere/bee-js 12.3.1 → 12.3.2-upcoming.g270c9ca

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.
package/dist/cjs/index.js CHANGED
@@ -45,9 +45,9 @@ var cafe_utility_1 = require("cafe-utility");
45
45
  Object.defineProperty(exports, "MerkleTree", { enumerable: true, get: function () { return cafe_utility_1.MerkleTree; } });
46
46
  var manifest_1 = require("./manifest/manifest");
47
47
  Object.defineProperty(exports, "MantarayNode", { enumerable: true, get: function () { return manifest_1.MantarayNode; } });
48
- var status_1 = require("./modules/debug/status");
49
- Object.defineProperty(exports, "SUPPORTED_BEE_VERSION", { enumerable: true, get: function () { return status_1.SUPPORTED_BEE_VERSION; } });
50
- Object.defineProperty(exports, "SUPPORTED_BEE_VERSION_EXACT", { enumerable: true, get: function () { return status_1.SUPPORTED_BEE_VERSION_EXACT; } });
48
+ var version_1 = require("./version");
49
+ Object.defineProperty(exports, "SUPPORTED_BEE_VERSION", { enumerable: true, get: function () { return version_1.SUPPORTED_BEE_VERSION; } });
50
+ Object.defineProperty(exports, "SUPPORTED_BEE_VERSION_EXACT", { enumerable: true, get: function () { return version_1.SUPPORTED_BEE_VERSION_EXACT; } });
51
51
  __exportStar(require("./types"), exports);
52
52
  var bytes_1 = require("./utils/bytes");
53
53
  Object.defineProperty(exports, "Bytes", { enumerable: true, get: function () { return bytes_1.Bytes; } });
@@ -59,7 +59,10 @@ class Fork {
59
59
  throw Error('Fork#marshal node.selfAddress is not set');
60
60
  }
61
61
  const data = [];
62
- data.push(new Uint8Array([this.node.determineType()]));
62
+ // Re-emit the type byte read from the chunk when the node is untouched, so an
63
+ // unmarshal → marshal round-trip is byte-identical. determineType() can only
64
+ // recompute it correctly once the node's children are loaded/built in memory.
65
+ data.push(new Uint8Array([this.node.type ?? this.node.determineType()]));
63
66
  data.push(cafe_utility_1.Binary.numberToUint8(this.prefix.length));
64
67
  data.push(this.prefix);
65
68
  if (this.prefix.length < 30) {
@@ -99,7 +102,7 @@ class Fork {
99
102
  const metadataLength = cafe_utility_1.Binary.uint16ToNumber(reader.read(2), 'BE');
100
103
  metadata = JSON.parse(DECODER.decode(reader.read(metadataLength)));
101
104
  }
102
- return new Fork(prefix, new MantarayNode({ selfAddress, metadata, path: prefix }));
105
+ return new Fork(prefix, new MantarayNode({ selfAddress, metadata, path: prefix, type }));
103
106
  }
104
107
  }
105
108
  exports.Fork = Fork;
@@ -112,6 +115,7 @@ class MantarayNode {
112
115
  this.path = new Uint8Array(0);
113
116
  this.forks = new Map();
114
117
  this.parent = null;
118
+ this.type = null;
115
119
  if (options?.targetAddress) {
116
120
  this.targetAddress = options.targetAddress;
117
121
  }
@@ -130,6 +134,7 @@ class MantarayNode {
130
134
  if (options?.parent) {
131
135
  this.parent = options.parent;
132
136
  }
137
+ this.type = options?.type ?? null;
133
138
  }
134
139
  get fullPath() {
135
140
  return cafe_utility_1.Binary.concatBytes(this.parent?.fullPath ?? new Uint8Array(0), this.path);
@@ -184,11 +189,23 @@ class MantarayNode {
184
189
  fork.node.selfAddress = (await fork.node.calculateSelfAddress()).toUint8Array();
185
190
  }
186
191
  }
192
+ const hasEntry = !cafe_utility_1.Binary.equals(this.targetAddress, __1.NULL_ADDRESS);
193
+ let refBytesSize = 0;
194
+ if (hasEntry) {
195
+ refBytesSize = this.targetAddress.length;
196
+ }
197
+ else {
198
+ for (const fork of this.forks.values()) {
199
+ if (fork.node.selfAddress) {
200
+ refBytesSize = fork.node.selfAddress.length;
201
+ break;
202
+ }
203
+ }
204
+ }
187
205
  const header = new Uint8Array(32);
188
206
  header.set(VERSION_02_HASH, 0);
189
- header.set(cafe_utility_1.Binary.equals(this.targetAddress, __1.NULL_ADDRESS) && cafe_utility_1.Binary.equals(this.path, new Uint8Array([47]))
190
- ? cafe_utility_1.Binary.numberToUint8(0)
191
- : cafe_utility_1.Binary.numberToUint8(this.targetAddress.length), 31);
207
+ header.set(cafe_utility_1.Binary.numberToUint8(refBytesSize), 31);
208
+ const entry = hasEntry ? this.targetAddress : new Uint8Array(refBytesSize);
192
209
  const forkBitmap = new Uint8Array(32);
193
210
  for (const fork of this.forks.keys()) {
194
211
  cafe_utility_1.Binary.setBit(forkBitmap, fork, 1, 'LE');
@@ -199,9 +216,7 @@ class MantarayNode {
199
216
  forks.push(this.forks.get(i).marshal());
200
217
  }
201
218
  }
202
- const data = cafe_utility_1.Binary.xorCypher(cafe_utility_1.Binary.concatBytes(header, cafe_utility_1.Binary.equals(this.targetAddress, __1.NULL_ADDRESS) && cafe_utility_1.Binary.equals(this.path, new Uint8Array([47]))
203
- ? new Uint8Array(0)
204
- : this.targetAddress, forkBitmap, ...forks), this.obfuscationKey);
219
+ const data = cafe_utility_1.Binary.xorCypher(cafe_utility_1.Binary.concatBytes(header, entry, forkBitmap, ...forks), this.obfuscationKey);
205
220
  return cafe_utility_1.Binary.concatBytes(this.obfuscationKey, data);
206
221
  }
207
222
  /**
@@ -231,11 +246,13 @@ class MantarayNode {
231
246
  const targetAddress = targetAddressLength ? reader.read(targetAddressLength) : __1.NULL_ADDRESS;
232
247
  const node = new MantarayNode({ selfAddress, targetAddress, obfuscationKey });
233
248
  const forkBitmap = reader.read(32);
234
- for (let i = 0; i < 256; i++) {
235
- if (cafe_utility_1.Binary.getBit(forkBitmap, i, 'LE')) {
236
- const newFork = Fork.unmarshal(reader, selfAddress.length);
237
- node.forks.set(i, newFork);
238
- newFork.node.parent = node;
249
+ if (targetAddressLength > 0) {
250
+ for (let i = 0; i < 256; i++) {
251
+ if (cafe_utility_1.Binary.getBit(forkBitmap, i, 'LE')) {
252
+ const newFork = Fork.unmarshal(reader, selfAddress.length);
253
+ node.forks.set(i, newFork);
254
+ newFork.node.parent = node;
255
+ }
239
256
  }
240
257
  }
241
258
  return node;
@@ -245,6 +262,7 @@ class MantarayNode {
245
262
  */
246
263
  addFork(path, reference, metadata) {
247
264
  this.selfAddress = null;
265
+ this.type = null;
248
266
  path = path instanceof Uint8Array ? path : ENCODER.encode(path);
249
267
  debug('adding fork', { path: DECODER.decode(path), reference: new typed_bytes_1.Reference(reference).represent() });
250
268
  // TODO: this should not be ignored
@@ -273,12 +291,14 @@ class MantarayNode {
273
291
  tip.forks.set(remainingPath[0], fork);
274
292
  fork.node.parent = tip;
275
293
  tip.selfAddress = null;
294
+ tip.type = null;
276
295
  tip = newFork.node;
277
296
  }
278
297
  else {
279
298
  tip.forks.set(remainingPath[0], newFork);
280
299
  newFork.node.parent = tip;
281
300
  tip.selfAddress = null;
301
+ tip.type = null;
282
302
  tip = newFork.node;
283
303
  }
284
304
  }
@@ -288,6 +308,7 @@ class MantarayNode {
288
308
  */
289
309
  removeFork(path) {
290
310
  this.selfAddress = null;
311
+ this.type = null;
291
312
  path = path instanceof Uint8Array ? path : ENCODER.encode(path);
292
313
  if (path.length === 0) {
293
314
  throw Error('MantarayNode#removeFork [path] parameter cannot be empty');
@@ -405,13 +426,20 @@ class MantarayNode {
405
426
  }
406
427
  determineType() {
407
428
  let type = 0;
408
- if (!cafe_utility_1.Binary.equals(this.targetAddress, __1.NULL_ADDRESS) || cafe_utility_1.Binary.equals(this.path, PATH_SEPARATOR)) {
429
+ // Mirror Bee (pkg/manifest/mantaray/node.go): Add() marks every explicitly
430
+ // added leaf as a value (makeValue), even one with a null entry such as a
431
+ // metadata-only "/" node. In final-state terms a leaf (no forks) is always an
432
+ // added entry, so it is a value; a node with forks is a value only when it also
433
+ // carries an entry. The path-separator flag is set only when a separator occurs
434
+ // past the first byte (IndexRune > 0), so a prefix that merely starts with '/'
435
+ // does not qualify.
436
+ if (!cafe_utility_1.Binary.equals(this.targetAddress, __1.NULL_ADDRESS) || this.forks.size === 0) {
409
437
  type |= TYPE_VALUE;
410
438
  }
411
439
  if (this.forks.size > 0) {
412
440
  type |= TYPE_EDGE;
413
441
  }
414
- if (cafe_utility_1.Binary.indexOf(this.path, PATH_SEPARATOR) !== -1 && !cafe_utility_1.Binary.equals(this.path, PATH_SEPARATOR)) {
442
+ if (cafe_utility_1.Binary.indexOf(this.path, PATH_SEPARATOR) > 0) {
415
443
  type |= TYPE_WITH_PATH_SEPARATOR;
416
444
  }
417
445
  if (this.metadata) {
@@ -3,7 +3,6 @@ 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.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
7
6
  exports.getDebugStatus = getDebugStatus;
8
7
  exports.getHealth = getHealth;
9
8
  exports.getReadiness = getReadiness;
@@ -14,9 +13,7 @@ exports.getVersions = getVersions;
14
13
  const major_js_1 = __importDefault(require("semver/functions/major.js"));
15
14
  const status_1 = require("../../types/schema/status");
16
15
  const http_1 = require("../../utils/http");
17
- exports.SUPPORTED_BEE_VERSION_EXACT = '2.8.1-7cf53193';
18
- exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
19
- exports.SUPPORTED_API_VERSION = '8.1.0';
16
+ const version_1 = require("../../version");
20
17
  const NODE_INFO_URL = 'node';
21
18
  const STATUS_URL = 'status';
22
19
  const HEALTH_URL = 'health';
@@ -77,7 +74,7 @@ async function getNodeInfo(requestOptions) {
77
74
  */
78
75
  async function isSupportedExactVersion(requestOptions) {
79
76
  const { version } = await getHealth(requestOptions);
80
- return version === exports.SUPPORTED_BEE_VERSION_EXACT;
77
+ return version === version_1.SUPPORTED_BEE_VERSION_EXACT;
81
78
  }
82
79
  /**
83
80
  * Connects to a node and checks if its Main API versions matches with the one that bee-js supports.
@@ -88,7 +85,7 @@ async function isSupportedExactVersion(requestOptions) {
88
85
  */
89
86
  async function isSupportedApiVersion(requestOptions) {
90
87
  const { apiVersion } = await getHealth(requestOptions);
91
- return (0, major_js_1.default)(apiVersion) === (0, major_js_1.default)(exports.SUPPORTED_API_VERSION);
88
+ return (0, major_js_1.default)(apiVersion) === (0, major_js_1.default)(version_1.SUPPORTED_API_VERSION);
92
89
  }
93
90
  /**
94
91
  * Returns object with all versions specified by the connected Bee node (properties prefixed with `bee*`)
@@ -99,8 +96,8 @@ async function isSupportedApiVersion(requestOptions) {
99
96
  async function getVersions(requestOptions) {
100
97
  const { version, apiVersion } = await getHealth(requestOptions);
101
98
  return {
102
- supportedBeeVersion: exports.SUPPORTED_BEE_VERSION_EXACT,
103
- supportedBeeApiVersion: exports.SUPPORTED_API_VERSION,
99
+ supportedBeeVersion: version_1.SUPPORTED_BEE_VERSION_EXACT,
100
+ supportedBeeApiVersion: version_1.SUPPORTED_API_VERSION,
104
101
  beeVersion: version,
105
102
  beeApiVersion: apiVersion,
106
103
  };
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ // AUTO-GENERATED from package.json "engines" by scripts/generate-version.cjs — do not edit by hand.
3
+ // Run `npm run generate:version` to regenerate.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.SUPPORTED_API_VERSION = exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT = void 0;
6
+ /** Exact supported Bee version, including the commit hash suffix. */
7
+ exports.SUPPORTED_BEE_VERSION_EXACT = '2.8.1-7cf53193';
8
+ /** Supported Bee version without the commit hash suffix. */
9
+ exports.SUPPORTED_BEE_VERSION = exports.SUPPORTED_BEE_VERSION_EXACT.split('-')[0];
10
+ /** Supported Bee API version. */
11
+ exports.SUPPORTED_API_VERSION = '8.1.0';