Skip to content

Commit 53f910f

Browse files
committed
new stats method
1 parent c65e226 commit 53f910f

File tree

7 files changed

+51
-4
lines changed

7 files changed

+51
-4
lines changed

.changeset/lovely-garlics-wait.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@squarecloud/blob": minor
3+
---
4+
5+
New `SquareCloudBlob#stats` method for checking account stats

package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
"build:ts": "tsup ./src",
1414
"lint": "biome check --apply .",
1515
"test": "node --env-file=.env -r ts-node/register",
16-
"test:list": "npm run test ./test/list.test.ts",
17-
"test:create": "npm run test ./test/create.test.ts",
18-
"test:delete": "npm run test ./test/delete.test.ts",
19-
"test:mime": "npm run test ./test/mimetypes.test.ts",
16+
"test:stats": "npm test ./test/stats.test.ts",
17+
"test:list": "npm test ./test/list.test.ts",
18+
"test:create": "npm test ./test/create.test.ts",
19+
"test:delete": "npm test ./test/delete.test.ts",
20+
"test:mime": "npm test ./test/mimetypes.test.ts",
2021
"prepare": "husky"
2122
},
2223
"engines": {

src/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { APIManager } from "./managers/api";
22
import { ObjectsManager } from "./managers/objects";
3+
import type { StatsResponse } from "./types/stats";
4+
import { assertStatsResponse } from "./validation/assertions/stats";
35

46
export class SquareCloudBlob {
57
public static apiInfo = {
@@ -13,6 +15,11 @@ export class SquareCloudBlob {
1315
constructor(apiKey: string) {
1416
this.api = new APIManager(apiKey);
1517
}
18+
19+
async stats() {
20+
const { response } = await this.api.request<StatsResponse>("account/stats");
21+
return assertStatsResponse(response);
22+
}
1623
}
1724

1825
export * from "./structures/object";

src/types/stats.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import type { z } from "zod";
2+
import type { statsResponseSchema } from "../validation/schemas/stats";
3+
4+
export type StatsResponse = z.infer<typeof statsResponseSchema>;

src/validation/assertions/stats.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import type { StatsResponse } from "../../types/stats";
2+
import { statsResponseSchema } from "../schemas/stats";
3+
import { handleAPIObjectAssertion } from "./handlers";
4+
5+
export function assertStatsResponse(value: unknown): StatsResponse {
6+
return handleAPIObjectAssertion({
7+
schema: statsResponseSchema,
8+
code: "ACCOUNT_STATS",
9+
value,
10+
});
11+
}

src/validation/schemas/stats.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { z } from "zod";
2+
3+
export const statsResponseSchema = z.object({
4+
/** The total number of objects in your account. */
5+
objects: z.number(),
6+
/** The total size of all objects in your account, in bytes. */
7+
size: z.number(),
8+
/** The total price of storage for all objects in your account, in BRL. */
9+
storagePrice: z.number(),
10+
/** The total price of all objects in your account, in BRL. */
11+
objectsPrice: z.number(),
12+
/** The total price of all objects in your account, in BRL. */
13+
totalEstimate: z.number(),
14+
});

test/stats.test.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Check account stats
2+
3+
import { blob } from "./index.test";
4+
5+
blob.stats().then(console.log);

0 commit comments

Comments
 (0)