@upcoming/bee-js 9.7.0 → 9.8.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.
package/dist/mjs/bee.js CHANGED
@@ -1212,6 +1212,20 @@ export class Bee {
1212
1212
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1213
1213
  return getStampCost(depth, amount);
1214
1214
  }
1215
+ async extendStorage(postageBatchId, size, duration, options, encryption, erasureCodeLevel) {
1216
+ const batch = await this.getPostageBatch(postageBatchId, options);
1217
+ const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1218
+ const chainState = await this.getChainState(options);
1219
+ const depthDelta = depth - batch.depth;
1220
+ const multiplier = depthDelta === 0 ? 1n : 2n ** BigInt(depthDelta);
1221
+ const targetAmount = (BigInt(batch.amount) + getAmountForDuration(duration, chainState.currentPrice, this.network === 'gnosis' ? 5 : 15)) * multiplier;
1222
+ const amountDelta = targetAmount - BigInt(batch.amount);
1223
+ const transactionId = await this.topUpBatch(batch.batchID, amountDelta, options);
1224
+ if (depthDelta) {
1225
+ return this.diluteBatch(batch.batchID, depth, options);
1226
+ }
1227
+ return transactionId;
1228
+ }
1215
1229
  async extendStorageSize(postageBatchId, size, options, encryption, erasureCodeLevel) {
1216
1230
  const batch = await this.getPostageBatch(postageBatchId, options);
1217
1231
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
@@ -39,6 +39,7 @@ export async function streamDirectory(bee, dir, postageBatchId, onUploadProgress
39
39
  for (const file of files) {
40
40
  total += totalChunks(file.size);
41
41
  }
42
+ let hasIndexHtml = false;
42
43
  async function onChunk(chunk) {
43
44
  await queue.enqueue(async () => {
44
45
  await bee.uploadChunk(postageBatchId, chunk.build(), options, requestOptions);
@@ -69,10 +70,20 @@ export async function streamDirectory(bee, dir, postageBatchId, onUploadProgress
69
70
  Filename: filename
70
71
  });
71
72
  if (file.path === 'index.html') {
72
- mantaray.addFork('/', NULL_ADDRESS, {
73
- 'website-index-document': 'index.html'
74
- });
73
+ hasIndexHtml = true;
74
+ }
75
+ }
76
+ if (hasIndexHtml || options?.indexDocument || options?.errorDocument) {
77
+ const metadata = {};
78
+ if (options?.indexDocument) {
79
+ metadata['website-index-document'] = options.indexDocument;
80
+ } else if (hasIndexHtml) {
81
+ metadata['website-index-document'] = 'index.html';
82
+ }
83
+ if (options?.errorDocument) {
84
+ metadata['website-error-document'] = options.errorDocument;
75
85
  }
86
+ mantaray.addFork('/', NULL_ADDRESS, metadata);
76
87
  }
77
88
  return mantaray.saveRecursively(bee, postageBatchId, options, requestOptions);
78
89
  }
@@ -193,7 +193,7 @@ export declare class Bee {
193
193
  */
194
194
  uploadFiles(postageBatchId: BatchId | Uint8Array | string, fileList: FileList | File[], options?: CollectionUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
195
195
  hashDirectory(dir: string): Promise<Reference>;
196
- streamDirectory(postageBatchId: BatchId | Uint8Array | string, dir: string, onUploadProgress?: (progress: UploadProgress) => void, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
196
+ streamDirectory(postageBatchId: BatchId | Uint8Array | string, dir: string, onUploadProgress?: (progress: UploadProgress) => void, options?: CollectionUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
197
197
  streamFiles(postageBatchId: BatchId | Uint8Array | string, files: File[] | FileList, onUploadProgress?: (progress: UploadProgress) => void, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
198
198
  /**
199
199
  * Upload Collection that you can assembly yourself.
@@ -689,6 +689,7 @@ export declare class Bee {
689
689
  createPostageBatch(amount: NumberString | string | bigint, depth: number, options?: PostageBatchOptions, requestOptions?: BeeRequestOptions): Promise<BatchId>;
690
690
  buyStorage(size: Size, duration: Duration, options?: PostageBatchOptions, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BatchId>;
691
691
  getStorageCost(size: Size, duration: Duration, options?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BZZ>;
692
+ extendStorage(postageBatchId: BatchId | Uint8Array | string, size: Size, duration: Duration, options?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BatchId>;
692
693
  extendStorageSize(postageBatchId: BatchId | Uint8Array | string, size: Size, options?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BatchId>;
693
694
  extendStorageDuration(postageBatchId: BatchId | Uint8Array | string, duration: Duration, options?: BeeRequestOptions): Promise<BatchId>;
694
695
  getExtensionCost(postageBatchId: BatchId | Uint8Array | string, size: Size, duration: Duration, options?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<BZZ>;
@@ -1,6 +1,6 @@
1
- import { Bee, BeeRequestOptions, UploadOptions, UploadResult } from '..';
1
+ import { Bee, BeeRequestOptions, CollectionUploadOptions, UploadOptions, UploadResult } from '..';
2
2
  import { BatchId } from './typed-bytes';
3
3
  import { UploadProgress } from './upload-progress';
4
4
  export declare function hashDirectory(dir: string): Promise<import("./typed-bytes").Reference>;
5
- export declare function streamDirectory(bee: Bee, dir: string, postageBatchId: BatchId | string | Uint8Array, onUploadProgress?: (progress: UploadProgress) => void, options?: UploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
5
+ export declare function streamDirectory(bee: Bee, dir: string, postageBatchId: BatchId | string | Uint8Array, onUploadProgress?: (progress: UploadProgress) => void, options?: CollectionUploadOptions, requestOptions?: BeeRequestOptions): Promise<UploadResult>;
6
6
  export declare function streamFiles(_bee: Bee, _files: File[] | FileList, _postageBatchId: BatchId, _onUploadProgress?: (progress: UploadProgress) => void, _options?: UploadOptions, _requestOptions?: BeeRequestOptions): Promise<UploadResult>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@upcoming/bee-js",
3
- "version": "9.7.0",
3
+ "version": "9.8.0",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",