File tree Expand file tree Collapse file tree 7 files changed +51
-4
lines changed Expand file tree Collapse file tree 7 files changed +51
-4
lines changed Original file line number Diff line number Diff line change 1+ ---
2+ " @squarecloud/blob " : minor
3+ ---
4+
5+ New ` SquareCloudBlob#stats ` method for checking account stats
Original file line number Diff line number Diff line change 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" : {
Original file line number Diff line number Diff line change 11import { APIManager } from "./managers/api" ;
22import { ObjectsManager } from "./managers/objects" ;
3+ import type { StatsResponse } from "./types/stats" ;
4+ import { assertStatsResponse } from "./validation/assertions/stats" ;
35
46export 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
1825export * from "./structures/object" ;
Original file line number Diff line number Diff line change 1+ import type { z } from "zod" ;
2+ import type { statsResponseSchema } from "../validation/schemas/stats" ;
3+
4+ export type StatsResponse = z . infer < typeof statsResponseSchema > ;
Original file line number Diff line number Diff line change 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+ }
Original file line number Diff line number Diff line change 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+ } ) ;
Original file line number Diff line number Diff line change 1+ // Check account stats
2+
3+ import { blob } from "./index.test" ;
4+
5+ blob . stats ( ) . then ( console . log ) ;
You can’t perform that action at this time.
0 commit comments