Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#19] Update to HTTP API v0.5 #21

Merged
merged 2 commits into from
May 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
## Release 0.4.0 (in progress)

**Features**

* Update to Reduct HTTP API v0.5, [PR-21](https://github.com/reduct-storage/reduct-js/pull/21)

## Release 0.3.0 (2022-04-30)

**Features**:

* Use `bigint` instead of `BigInt`, [PR-13](https://github.com/reduct-storage/reduct-js/pull/13)
* Use Buffer read and write records, [PR-18](https://github.com/reduct-storage/reduct-js/pull/18)
* Use Buffer read and write records, [PR-18](https://github.com/reduct-storage/reduct-js/pull/18)

**Bugs**:

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Asynchronous HTTP client for [Reduct Storage](https://reduct-storage.dev) writte
## Features

* Promise based
* Support Reduct Storage API v0.4
* Support Reduct Storage API v0.5
* Token authentication

## Getting Started
Expand Down
2 changes: 1 addition & 1 deletion src/Client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export type ClientOptions = {
}

export class Client {
private httpClient: AxiosInstance;
private readonly httpClient: AxiosInstance;

/**
* HTTP Client for Reduct Storage
Expand Down
28 changes: 27 additions & 1 deletion src/ServerInfo.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
import {BucketSettings} from "./BucketSettings";


export class ServerDefaults {
readonly bucket: BucketSettings = {};
}

/**
* Represents information about storage
*/
Expand Down Expand Up @@ -32,6 +39,11 @@ export class ServerInfo {
*/
readonly latestRecord: bigint = 0n;

/**
* Default settings
*/
readonly defaults: ServerDefaults = {bucket: {}};

static parse(data: Original): ServerInfo {
return {
version: data.version,
Expand All @@ -40,8 +52,22 @@ export class ServerInfo {
usage: BigInt(data.usage),
oldestRecord: BigInt(data.oldest_record),
latestRecord: BigInt(data.latest_record),
defaults: {
bucket: BucketSettings.parse(data.defaults.bucket)
}
};
}
}

type Original = { version: string; bucket_count: string; uptime: string; usage: string; oldest_record: string; latest_record: string; }
type Original = {
version: string;
bucket_count: string;
uptime: string;
usage: string;
oldest_record: string;
latest_record: string;
defaults: {
bucket: { quota_size: string; max_block_size: string; quota_type: string };

}
}
6 changes: 6 additions & 0 deletions test/Client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@ describe("Client", () => {
expect(info.uptime).toBeGreaterThanOrEqual(0);
expect(info.oldestRecord).toEqual(1000_000n);
expect(info.latestRecord).toEqual(2000_000n);

expect(info.defaults.bucket).toEqual({
maxBlockSize: 67108864n,
quotaSize: 0n,
quotaType: QuotaType.NONE,
});
});

it("should get list of buckets", async () => {
Expand Down