Skip to content

Commit 1079633

Browse files
committed
refactor(list-objects): remove response validation
1 parent e4ab7d7 commit 1079633

File tree

8 files changed

+33
-65
lines changed

8 files changed

+33
-65
lines changed

src/managers/objects.ts

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@ import type {
55
CreateObjectOptions,
66
CreateObjectResponse,
77
} from "../types/create";
8-
import type { ListObjectsResponse, ListObjectsType } from "../types/list";
8+
import type { ListObjectsOptions, ListObjectsResponse } from "../types/list";
99
import { parsePathLike } from "../utils/path-like";
1010
import { makeCreateObjectPayload } from "../utils/payloads";
11-
import { assertListObjectsResponse } from "../validation/assertions/list";
12-
import { listObjectsPayloadSchema } from "../validation/schemas/list";
1311

1412
export class ObjectsManager {
1513
constructor(private readonly client: SquareCloudBlob) {}
@@ -22,14 +20,11 @@ export class ObjectsManager {
2220
* blob.objects.list();
2321
* ```
2422
*/
25-
async list(options?: ListObjectsType) {
26-
const payload = listObjectsPayloadSchema.parse(options);
27-
28-
const response = await this.client.api.request<ListObjectsResponse>(
23+
async list(options?: ListObjectsOptions) {
24+
const { objects } = await this.client.api.request<ListObjectsResponse>(
2925
"objects",
30-
{ params: payload.params },
26+
{ params: options },
3127
);
32-
const { objects } = assertListObjectsResponse(response);
3328

3429
return objects.map((objectData) => {
3530
const createdAt = new Date(objectData.created_at);
@@ -49,7 +44,7 @@ export class ObjectsManager {
4944
/**
5045
* Uploads an object to the storage.
5146
*
52-
* @param data - An object to upload
47+
* @param options - An object to upload
5348
*
5449
* @example
5550
* ```js
@@ -67,17 +62,17 @@ export class ObjectsManager {
6762
* })
6863
* ```
6964
*/
70-
async create(data: CreateObjectOptions) {
71-
if (data.file instanceof Buffer && !data.mimeType) {
65+
async create(options: CreateObjectOptions) {
66+
if (options.file instanceof Buffer && !options.mimeType) {
7267
throw new SquareCloudBlobError(
7368
"MIME_TYPE_REQUIRED",
7469
"Mime type is required when using a Buffer",
7570
);
7671
}
7772

78-
const payload = makeCreateObjectPayload(data);
73+
const payload = makeCreateObjectPayload(options);
7974
const file = await parsePathLike(payload.file);
80-
const type = payload.mimeType || data.mimeType;
75+
const type = payload.mimeType || options.mimeType;
8176

8277
const formData = new FormData();
8378
formData.append("file", new Blob([new Uint8Array(file)], { type }));

src/types/create.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { MimeTypes } from "../utils/mimetype";
22

3-
export interface CreateObjectOptions {
3+
export type CreateObjectOptions = {
44
/**
55
* A string representing the name of the file.
66
* Must adhere to the a to z, A to Z, 0 to 9, and _ pattern. (3 to 32 characters)
@@ -21,9 +21,9 @@ export interface CreateObjectOptions {
2121
securityHash?: boolean;
2222
/** Set to true if the file should be set for automatic download. */
2323
autoDownload?: boolean;
24-
}
24+
};
2525

26-
export interface CreateObjectResponse {
26+
export type CreateObjectResponse = {
2727
/** The id of the uploaded file. */
2828
id: string;
2929
/** The name of the uploaded file. */
@@ -34,4 +34,4 @@ export interface CreateObjectResponse {
3434
url: string;
3535
/** The prefix of the uploaded file. */
3636
prefix?: string;
37-
}
37+
};

src/types/list.ts

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1-
import type { z } from "zod";
2-
import type {
3-
listObjectsResponseSchema,
4-
listObjectsSchema,
5-
} from "../validation/schemas/list";
1+
export type ListObjectsOptions = {
2+
prefix?: string;
3+
continuationToken?: string;
4+
};
65

7-
export type ListObjectsType = z.infer<typeof listObjectsSchema>;
8-
export type ListObjectsResponse = z.infer<typeof listObjectsResponseSchema>;
6+
export type ListedObject = {
7+
id: string;
8+
size: number;
9+
created_at: Date;
10+
expires_at?: Date;
11+
};
12+
13+
export type ListObjectsResponse = {
14+
objects: ListedObject[];
15+
};

src/types/object.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
export interface BlobObjectData {
1+
export type BlobObjectData = {
22
idOrUrl: string;
33
size: number;
44
expiresAt?: Date;
55
createdAt?: Date;
6-
}
6+
};

src/types/stats.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export interface StatsResponse {
1+
export type StatsResponse = {
22
usage: {
33
/** The total number of objects in your account. */
44
objects: number;
@@ -19,4 +19,4 @@ export interface StatsResponse {
1919
/** The total estimate of all objects, storage and extra storage in your account, in BRL. */
2020
totalEstimate: number;
2121
};
22-
}
22+
};

src/validation/assertions/list.ts

Lines changed: 0 additions & 11 deletions
This file was deleted.

src/validation/schemas/list.ts

Lines changed: 0 additions & 23 deletions
This file was deleted.

test/list.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { ListObjectsType } from "../src";
1+
import type { ListObjectsOptions } from "../src";
22
import { blob } from "./index.test";
33

4-
const listOptions: ListObjectsType = {
4+
const listOptions: ListObjectsOptions = {
55
prefix: "test",
66
};
77

0 commit comments

Comments
 (0)