@ethersphere/bee-js 10.1.0 → 10.1.2

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
@@ -1608,7 +1608,7 @@ export class Bee {
1608
1608
  const depth = getDepthForSize(size, encryption, erasureCodeLevel);
1609
1609
  const currentAmount = getAmountForDuration(batch.duration, chainState.currentPrice, blockTime);
1610
1610
  const currentCost = getStampCost(batch.depth, currentAmount);
1611
- const newCost = getStampCost(depth, currentAmount + amount);
1611
+ const newCost = getStampCost(Math.max(batch.depth, depth), currentAmount + amount);
1612
1612
  return newCost.minus(currentCost);
1613
1613
  }
1614
1614
  /**
@@ -1735,13 +1735,15 @@ export class Bee {
1735
1735
  *
1736
1736
  * @param postageBatchId Batch ID
1737
1737
  * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1738
+ * @param encryption Assume that uploads with this postage batch are encrypted, which skews the capacity.
1739
+ * @param erasureCodeLevel Assume that uploads with this postage batch are erasure coded, which skews the capacity.
1738
1740
  *
1739
1741
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1740
1742
  * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
1741
1743
  */
1742
- async getPostageBatch(postageBatchId, requestOptions) {
1744
+ async getPostageBatch(postageBatchId, requestOptions, encryption, erasureCodeLevel) {
1743
1745
  postageBatchId = new BatchId(postageBatchId);
1744
- return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId);
1746
+ return stamps.getPostageBatch(this.getRequestOptionsForCall(requestOptions), postageBatchId, encryption, erasureCodeLevel);
1745
1747
  }
1746
1748
  /**
1747
1749
  * Return detailed information related to buckets for specific postage batch.
@@ -78,6 +78,7 @@ export async function getAllPostageBatches(requestOptions) {
78
78
  name: 'batchTTL'
79
79
  }));
80
80
  const duration = Duration.fromSeconds(batchTTL);
81
+ const effectiveBytes = getStampEffectiveBytes(depth);
81
82
  return {
82
83
  batchID: new BatchId(Types.asString(x.batchID, {
83
84
  name: 'batchID'
@@ -102,14 +103,22 @@ export async function getAllPostageBatches(requestOptions) {
102
103
  }),
103
104
  usage,
104
105
  usageText: `${Math.round(usage * 100)}%`,
105
- size: Size.fromBytes(getStampEffectiveBytes(depth)),
106
- remainingSize: Size.fromBytes(Math.ceil(getStampEffectiveBytes(depth) * (1 - usage))),
106
+ size: Size.fromBytes(effectiveBytes),
107
+ remainingSize: Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage))),
107
108
  theoreticalSize: Size.fromBytes(getStampTheoreticalBytes(depth)),
108
- duration
109
+ duration,
110
+ calculateSize(encryption, redundancyLevel) {
111
+ const effectiveBytes = getStampEffectiveBytes(this.depth, encryption, redundancyLevel);
112
+ return Size.fromBytes(effectiveBytes);
113
+ },
114
+ calculateRemainingSize(encryption, redundancyLevel) {
115
+ const effectiveBytes = getStampEffectiveBytes(this.depth, encryption, redundancyLevel);
116
+ return Size.fromBytes(Math.ceil(effectiveBytes * (1 - this.usage)));
117
+ }
109
118
  };
110
119
  });
111
120
  }
112
- export async function getPostageBatch(requestOptions, postageBatchId) {
121
+ export async function getPostageBatch(requestOptions, postageBatchId, encryption, erasureCodeLevel) {
113
122
  const response = await http(requestOptions, {
114
123
  method: 'get',
115
124
  url: `${STAMPS_ENDPOINT}/${postageBatchId}`,
@@ -132,6 +141,7 @@ export async function getPostageBatch(requestOptions, postageBatchId) {
132
141
  name: 'batchTTL'
133
142
  }));
134
143
  const duration = Duration.fromSeconds(batchTTL);
144
+ const effectiveBytes = getStampEffectiveBytes(depth, encryption, erasureCodeLevel);
135
145
  return {
136
146
  batchID: new BatchId(Types.asString(body.batchID, {
137
147
  name: 'batchID'
@@ -156,10 +166,18 @@ export async function getPostageBatch(requestOptions, postageBatchId) {
156
166
  }),
157
167
  usage,
158
168
  usageText: `${Math.round(usage * 100)}%`,
159
- size: Size.fromBytes(getStampEffectiveBytes(depth)),
160
- remainingSize: Size.fromBytes(Math.ceil(getStampEffectiveBytes(depth) * (1 - usage))),
169
+ size: Size.fromBytes(effectiveBytes),
170
+ remainingSize: Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage))),
161
171
  theoreticalSize: Size.fromBytes(getStampTheoreticalBytes(depth)),
162
- duration
172
+ duration,
173
+ calculateSize(encryption, redundancyLevel) {
174
+ const effectiveBytes = getStampEffectiveBytes(depth, encryption, redundancyLevel);
175
+ return Size.fromBytes(effectiveBytes);
176
+ },
177
+ calculateRemainingSize(encryption, redundancyLevel) {
178
+ const effectiveBytes = getStampEffectiveBytes(depth, encryption, redundancyLevel);
179
+ return Size.fromBytes(Math.ceil(effectiveBytes * (1 - usage)));
180
+ }
163
181
  };
164
182
  }
165
183
  export async function getPostageBatchBuckets(requestOptions, postageBatchId) {
@@ -1158,11 +1158,13 @@ export declare class Bee {
1158
1158
  *
1159
1159
  * @param postageBatchId Batch ID
1160
1160
  * @param requestOptions Options for making requests, such as timeouts, custom HTTP agents, headers, etc.
1161
+ * @param encryption Assume that uploads with this postage batch are encrypted, which skews the capacity.
1162
+ * @param erasureCodeLevel Assume that uploads with this postage batch are erasure coded, which skews the capacity.
1161
1163
  *
1162
1164
  * @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/develop/access-the-swarm/introduction/#keep-your-data-alive)
1163
1165
  * @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/api/#tag/Postage-Stamps/paths/~1stamps~1%7Bbatch_id%7D/get)
1164
1166
  */
1165
- getPostageBatch(postageBatchId: BatchId | Uint8Array | string, requestOptions?: BeeRequestOptions): Promise<PostageBatch>;
1167
+ getPostageBatch(postageBatchId: BatchId | Uint8Array | string, requestOptions?: BeeRequestOptions, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<PostageBatch>;
1166
1168
  /**
1167
1169
  * Return detailed information related to buckets for specific postage batch.
1168
1170
  *
@@ -1,8 +1,8 @@
1
- import type { BeeRequestOptions, GlobalPostageBatch, NumberString, PostageBatch, PostageBatchBuckets, PostageBatchOptions } from '../../types';
1
+ import type { BeeRequestOptions, GlobalPostageBatch, NumberString, PostageBatch, PostageBatchBuckets, PostageBatchOptions, RedundancyLevel } from '../../types';
2
2
  import { BatchId } from '../../utils/typed-bytes';
3
3
  export declare function getGlobalPostageBatches(requestOptions: BeeRequestOptions): Promise<GlobalPostageBatch[]>;
4
4
  export declare function getAllPostageBatches(requestOptions: BeeRequestOptions): Promise<PostageBatch[]>;
5
- export declare function getPostageBatch(requestOptions: BeeRequestOptions, postageBatchId: BatchId): Promise<PostageBatch>;
5
+ export declare function getPostageBatch(requestOptions: BeeRequestOptions, postageBatchId: BatchId, encryption?: boolean, erasureCodeLevel?: RedundancyLevel): Promise<PostageBatch>;
6
6
  export declare function getPostageBatchBuckets(requestOptions: BeeRequestOptions, postageBatchId: BatchId): Promise<PostageBatchBuckets>;
7
7
  export declare function createPostageBatch(requestOptions: BeeRequestOptions, amount: NumberString, depth: number, options?: PostageBatchOptions): Promise<BatchId>;
8
8
  export declare function topUpBatch(requestOptions: BeeRequestOptions, id: BatchId, amount: NumberString): Promise<BatchId>;
@@ -450,6 +450,16 @@ export interface PostageBatch {
450
450
  * Theoretical size in bytes
451
451
  */
452
452
  theoreticalSize: Size;
453
+ /**
454
+ * Calculates the effective size of data that can be uploaded with this postage batch
455
+ * based on whether encryption is used and the desired redundancy level.
456
+ */
457
+ calculateSize(encryption: boolean, redundancyLevel: RedundancyLevel): Size;
458
+ /**
459
+ * Calculates the remaining size of data that can be uploaded with this postage batch
460
+ * based on whether encryption is used and the desired redundancy level.
461
+ */
462
+ calculateRemainingSize(encryption: boolean, redundancyLevel: RedundancyLevel): Size;
453
463
  }
454
464
  export interface BatchBucket {
455
465
  bucketID: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ethersphere/bee-js",
3
- "version": "10.1.0",
3
+ "version": "10.1.2",
4
4
  "description": "Javascript client for Bee",
5
5
  "keywords": [
6
6
  "bee",