UNPKG

@squarecloud/blob

Version:
67 lines (64 loc) 1.83 kB
// src/validation/schemas/list.ts import { z } from "zod"; var listObjectsSchema = z.object({ /** Filter by prefix */ prefix: z.string().optional(), /** Return objects after this token */ continuationToken: z.string().optional() }); var listObjectsPayloadSchema = listObjectsSchema.optional().transform((params) => ({ params })); var listObjectResponseSchema = z.object({ id: z.string(), size: z.number(), created_at: z.coerce.date(), expires_at: z.coerce.date().optional() }); var listObjectsResponseSchema = z.object({ objects: z.array(listObjectResponseSchema).default([]) }); // src/structures/error.ts var SquareCloudBlobError = class _SquareCloudBlobError extends Error { constructor(code, message, cause) { super(message, { cause }); this.name = _SquareCloudBlobError.name; this.message = this.getMessage(code); } getMessage(rawCode) { const code = rawCode.replaceAll("_", " ").toLowerCase().replace(/(^|\s)\S/g, (L) => L.toUpperCase()); const message = this.message ? `: ${this.message}` : ""; return `${code}${message}`; } }; // src/validation/assertions/handlers.ts function handleAPIObjectAssertion({ schema, value, code }) { const name = code.toLowerCase().replaceAll("_", " "); try { return schema.parse(value); } catch (err) { const cause = err.errors?.map((err2) => ({ ...err2, path: err2.path.join(" > ") })); throw new SquareCloudBlobError( `INVALID_API_${code}`, `Invalid ${name} object received from API`, { cause } ); } } // src/validation/assertions/list.ts function assertListObjectsResponse(value) { return handleAPIObjectAssertion({ schema: listObjectsResponseSchema, code: "LIST_OBJECTS", value }); } export { assertListObjectsResponse }; //# sourceMappingURL=list.mjs.map