UNPKG

@squarecloud/blob

Version:
57 lines (54 loc) 1.48 kB
// src/validation/schemas/common.ts import { z } from "zod"; var stringSchema = z.string(); var nameLikeSchema = z.string().min(3).max(32).regex(/^[a-zA-Z0-9_]{3,32}$/, { message: "Name must contain only letters, numbers and _" }); // 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}`; } }; var SquareCloudValidationError = class _SquareCloudValidationError extends SquareCloudBlobError { constructor(...args) { super(...args); this.name = _SquareCloudValidationError.name; } }; // src/validation/assertions/handlers.ts function handleLiteralAssertion({ schema, value, expect, code }) { try { schema.parse(value); } catch { throw new SquareCloudValidationError( code ? `INVALID_${code}` : "VALIDATION_ERROR", `Expect ${expect}, got ${typeof value}` ); } } // src/validation/assertions/literal.ts function assertString(value, code) { handleLiteralAssertion({ schema: stringSchema, expect: "string", value, code }); } export { assertString }; //# sourceMappingURL=literal.mjs.map