Skip to content

Commit

Permalink
fix: replace deprecated type DebugPostageBatch with PostageBatch (#594)
Browse files Browse the repository at this point in the history
* fix: replace deprecated DebugPostageBatch with the renamed type PostageBatch

* chore: fix linter issues
  • Loading branch information
vojtechsimetka authored Mar 21, 2022
1 parent 9485058 commit 265557d
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
6 changes: 3 additions & 3 deletions src/bee-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import type {
NumberString,
ExtendedTag,
PostageBatchBuckets,
DebugPostageBatch,
PostageBatch,
Ky,
TransactionInfo,
TransactionHash,
Expand Down Expand Up @@ -577,7 +577,7 @@ export class BeeDebug {
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
* @see [Bee Debug API reference - `GET /stamps/${id}`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps~1{id}/get)
*/
async getPostageBatch(postageBatchId: BatchId | string, options?: RequestOptions): Promise<DebugPostageBatch> {
async getPostageBatch(postageBatchId: BatchId | string, options?: RequestOptions): Promise<PostageBatch> {
assertRequestOptions(options)
assertBatchId(postageBatchId)

Expand Down Expand Up @@ -608,7 +608,7 @@ export class BeeDebug {
* @see [Bee docs - Keep your data alive / Postage stamps](https://docs.ethswarm.org/docs/access-the-swarm/keep-your-data-alive)
* @see [Bee Debug API reference - `GET /stamps`](https://docs.ethswarm.org/debug-api/#tag/Postage-Stamps/paths/~1stamps/get)
*/
async getAllPostageBatch(options?: RequestOptions): Promise<DebugPostageBatch[]> {
async getAllPostageBatch(options?: RequestOptions): Promise<PostageBatch[]> {
assertRequestOptions(options)

return stamps.getAllPostageBatches(this.getKy(options))
Expand Down
17 changes: 5 additions & 12 deletions src/modules/debug/stamps.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,17 @@
import type {
BatchId,
DebugPostageBatch,
Ky,
NumberString,
PostageBatchBuckets,
PostageBatchOptions,
} from '../../types'
import type { BatchId, PostageBatch, Ky, NumberString, PostageBatchBuckets, PostageBatchOptions } from '../../types'
import { http } from '../../utils/http'

const STAMPS_ENDPOINT = 'stamps'

interface GetAllStampsResponse {
stamps: DebugPostageBatch[]
stamps: PostageBatch[]
}

interface StampResponse {
batchID: BatchId
}

export async function getAllPostageBatches(ky: Ky): Promise<DebugPostageBatch[]> {
export async function getAllPostageBatches(ky: Ky): Promise<PostageBatch[]> {
const response = await http<GetAllStampsResponse>(ky, {
method: 'get',
path: `${STAMPS_ENDPOINT}`,
Expand All @@ -28,8 +21,8 @@ export async function getAllPostageBatches(ky: Ky): Promise<DebugPostageBatch[]>
return response.data.stamps || []
}

export async function getPostageBatch(ky: Ky, postageBatchId: BatchId): Promise<DebugPostageBatch> {
const response = await http<DebugPostageBatch>(ky, {
export async function getPostageBatch(ky: Ky, postageBatchId: BatchId): Promise<PostageBatch> {
const response = await http<PostageBatch>(ky, {
method: 'get',
path: `${STAMPS_ENDPOINT}/${postageBatchId}`,
responseType: 'json',
Expand Down
4 changes: 2 additions & 2 deletions src/utils/stamps.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { DebugPostageBatch } from '../types'
import { PostageBatch } from '../types'

/**
* Utility function that calculates usage of postage batch based on its utilization, depth and bucket depth.
Expand All @@ -10,6 +10,6 @@ import { DebugPostageBatch } from '../types'
* @param depth
* @param bucketDepth
*/
export function getStampUsage({ utilization, depth, bucketDepth }: DebugPostageBatch): number {
export function getStampUsage({ utilization, depth, bucketDepth }: PostageBatch): number {
return utilization / Math.pow(2, depth - bucketDepth)
}
4 changes: 2 additions & 2 deletions test/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ReadableStream as ReadableStreamPolyfill } from 'web-streams-polyfill'

import ky from 'ky-universal'

import type { Ky, BeeGenericResponse, Reference, Address, BatchId, DebugPostageBatch } from '../src/types'
import type { Ky, BeeGenericResponse, Reference, Address, BatchId, PostageBatch } from '../src/types'
import { bytesToHex, HexString } from '../src/utils/hex'
import { deleteChunkFromLocalStorage } from '../src/modules/debug/chunk'
import { BeeResponseError } from '../src'
Expand Down Expand Up @@ -346,7 +346,7 @@ export async function getOrCreatePostageBatch(
amount?: string,
depth?: number,
immutable?: boolean,
): Promise<DebugPostageBatch> {
): Promise<PostageBatch> {
// Non-usable stamps are ignored by Bee
const allUsableStamps = (await stamps.getAllPostageBatches(beeDebugKy())).filter(stamp => stamp.usable)

Expand Down

0 comments on commit 265557d

Please sign in to comment.