@ethersphere/bee-js 13.1.0 → 13.1.1-upcoming.g334b531

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/README.md CHANGED
@@ -69,7 +69,7 @@ types. Where `NumberString` is present, `number` is disallowed in order to avoid
69
69
  ### Byte primitives
70
70
 
71
71
  All the classes below extend `Bytes`, therefore the following methods are available on all of them: `toUint8Array`,
72
- `toHex`, `toBase64`, `toBase32`, `toUtf8`, `toJSON`, `static keccak256`, `static fromUtf8`.
72
+ `toHex`, `toBase64`, `toBase32`, `toUtf8`, `parsePayloadAsJson`, `static keccak256`, `static fromUtf8`.
73
73
 
74
74
  The `toString` method uses `toHex`.
75
75
 
@@ -337,8 +337,7 @@ const uploadResult = await bee.collection.uploadFromDirectory(batchId, './path/t
337
337
  ### Rolling feed (periodically-restarting sequential feed)
338
338
 
339
339
  A rolling feed avoids the unbounded growth of a plain sequential feed by restarting it every
340
- `periodLength` seconds, so old postage-batch eviction never breaks the latest update. See
341
- [ROLLING_FEED.md](./ROLLING_FEED.md) for the full design.
340
+ `periodLength` seconds, so old postage-batch eviction never breaks the latest update.
342
341
 
343
342
  A rolling feed only stays readable while the writer keeps publishing. Keeping it alive is the
344
343
  application's job, not the SDK's, so a writer belongs on a timer — republish on every tick, even
@@ -46,6 +46,7 @@ async function loadRecursively(node, bee, options, requestOptions) {
46
46
  const loaded = core_sdk_1.MantarayNode.unmarshalFromData(data, fork.node.selfAddress);
47
47
  fork.node.targetAddress = loaded.targetAddress;
48
48
  fork.node.forks = loaded.forks;
49
+ fork.node.obfuscationKey = loaded.obfuscationKey;
49
50
  fork.node.path = fork.prefix;
50
51
  fork.node.parent = node;
51
52
  await loadRecursively(fork.node, bee, options, requestOptions);
@@ -171,14 +171,19 @@ const METHOD_MAP = {
171
171
  function transform(sourceFile, checker) {
172
172
  const source = sourceFile.text;
173
173
  const isNewBee = (node) => !!node && ts.isNewExpression(node) && ts.isIdentifier(node.expression) && node.expression.text === 'Bee';
174
- // Does the type annotation mention `Bee` (`Bee`, `Bee | null`, `Bee | undefined`, …)?
174
+ const typeNameText = (name) => (ts.isIdentifier(name) ? name.text : name.right.text);
175
+ // Does the type annotation mention `Bee`, plain or wrapped (`Bee | null`, `Mocked<Bee>`,
176
+ // `jest.Mocked<Bee> & Extra`, …)? Arrays and tuples are left out — they don't expose Bee's members.
175
177
  const typeMentionsBee = (type) => {
176
178
  if (!type)
177
179
  return false;
178
- if (ts.isTypeReferenceNode(type) && ts.isIdentifier(type.typeName) && type.typeName.text === 'Bee')
179
- return true;
180
- if (ts.isUnionTypeNode(type))
180
+ if (ts.isParenthesizedTypeNode(type))
181
+ return typeMentionsBee(type.type);
182
+ if (ts.isUnionTypeNode(type) || ts.isIntersectionTypeNode(type))
181
183
  return type.types.some(typeMentionsBee);
184
+ if (ts.isTypeReferenceNode(type)) {
185
+ return typeNameText(type.typeName) === 'Bee' || (type.typeArguments ?? []).some(typeMentionsBee);
186
+ }
182
187
  return false;
183
188
  };
184
189
  // Syntactic pass — identify Bee bindings from annotations and `new Bee(...)` alone, so
@@ -214,10 +219,17 @@ function transform(sourceFile, checker) {
214
219
  ts.forEachChild(node, collect);
215
220
  };
216
221
  collect(sourceFile);
222
+ const isBeeJsFile = (file) => /[/\\]bee-js[/\\]/.test(file) || /[/\\]bee\.(d\.)?ts$/.test(file);
223
+ // A wrapper type (`Mocked<Bee>`, `Partial<Bee>`, …) has no Bee symbol of its own, but the
224
+ // members it maps over still point back at the Bee class they came from.
225
+ const hasBeeMember = (type, memberName) => (type.getProperty(memberName)?.getDeclarations() ?? []).some(decl => {
226
+ const parent = decl.parent;
227
+ return (ts.isClassDeclaration(parent) && parent.name?.text === 'Bee' && isBeeJsFile(parent.getSourceFile().fileName));
228
+ });
217
229
  // A receiver is a Bee if identified syntactically (above) OR resolved by the type checker
218
230
  // to the `Bee` class declared by bee-js — the latter additionally catches imported/shared
219
- // instances and factory calls (`getBee()`) when the project's types resolve.
220
- const isBeeReceiver = (expr) => {
231
+ // instances, factory calls (`getBee()`) and mock wrappers when the project's types resolve.
232
+ const isBeeReceiver = (expr, memberName) => {
221
233
  if (ts.isIdentifier(expr) && beeNames.has(expr.text))
222
234
  return true;
223
235
  if (ts.isPropertyAccessExpression(expr) &&
@@ -225,17 +237,14 @@ function transform(sourceFile, checker) {
225
237
  beeFields.has(expr.name.text)) {
226
238
  return true;
227
239
  }
228
- const symbol = checker.getTypeAtLocation(expr).getSymbol();
240
+ const type = checker.getTypeAtLocation(expr);
241
+ if (memberName && hasBeeMember(type, memberName))
242
+ return true;
243
+ const symbol = type.getSymbol();
229
244
  if (!symbol || symbol.getName() !== 'Bee') {
230
245
  return false;
231
246
  }
232
- return (symbol.getDeclarations() ?? []).some(decl => {
233
- if (!ts.isClassDeclaration(decl)) {
234
- return false;
235
- }
236
- const file = decl.getSourceFile().fileName;
237
- return /[/\\]bee-js[/\\]/.test(file) || /[/\\]bee\.(d\.)?ts$/.test(file);
238
- });
247
+ return (symbol.getDeclarations() ?? []).some(decl => ts.isClassDeclaration(decl) && isBeeJsFile(decl.getSourceFile().fileName));
239
248
  };
240
249
  // ChunkBuilder.hash() now returns a Reference, not a raw Uint8Array.
241
250
  const isChunkBuilderReceiver = (expr) => {
@@ -434,7 +443,7 @@ function transform(sourceFile, checker) {
434
443
  // Any `<bee>.<method>` access — called or not — so bare method references migrate too.
435
444
  if (ts.isPropertyAccessExpression(node) && ts.isIdentifier(node.name)) {
436
445
  const mapping = METHOD_MAP[node.name.text];
437
- if (mapping && isBeeReceiver(node.expression)) {
446
+ if (mapping && isBeeReceiver(node.expression, node.name.text)) {
438
447
  // Preserve optional chaining on the receiver: `bee?.uploadData` → `bee?.data.upload`.
439
448
  const separator = node.questionDotToken ? '?.' : '.';
440
449
  replacements.push({
@@ -468,7 +477,7 @@ function transform(sourceFile, checker) {
468
477
  text: `${quote}${mapping.newName}${quote}`,
469
478
  });
470
479
  }
471
- else if (mapping && isBeeReceiver(receiverArg)) {
480
+ else if (mapping && isBeeReceiver(receiverArg, methodArg.text)) {
472
481
  replacements.push({
473
482
  start: receiverArg.getStart(sourceFile),
474
483
  end: receiverArg.getEnd(),