@squarecloud/blob
Version:
Official Square Cloud Blob SDK for NodeJS
1 lines • 3.08 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/structures/error.ts","../../../src/validation/assertions/handlers.ts"],"sourcesContent":["export class SquareCloudBlobError extends Error {\n\tconstructor(code: string, message?: string, cause?: unknown) {\n\t\tsuper(message, { cause });\n\n\t\tthis.name = SquareCloudBlobError.name;\n\t\tthis.message = this.getMessage(code);\n\t}\n\n\tprivate getMessage(rawCode: string) {\n\t\tconst code = rawCode\n\t\t\t.replaceAll(\"_\", \" \")\n\t\t\t.toLowerCase()\n\t\t\t.replace(/(^|\\s)\\S/g, (L) => L.toUpperCase());\n\t\tconst message = this.message ? `: ${this.message}` : \"\";\n\n\t\treturn `${code}${message}`;\n\t}\n}\n\nexport class SquareCloudValidationError extends SquareCloudBlobError {\n\tconstructor(...args: ConstructorParameters<typeof SquareCloudBlobError>) {\n\t\tsuper(...args);\n\t\tthis.name = SquareCloudValidationError.name;\n\t}\n}\n","import type { ZodIssue } from \"zod\";\nimport {\n\tSquareCloudBlobError,\n\tSquareCloudValidationError,\n} from \"../../structures/error\";\nimport type {\n\tAPIObjectAssertionProps,\n\tLiteralAssertionProps,\n} from \"../../types/assertions\";\n\nexport function handleLiteralAssertion({\n\tschema,\n\tvalue,\n\texpect,\n\tcode,\n}: LiteralAssertionProps) {\n\ttry {\n\t\tschema.parse(value);\n\t} catch {\n\t\tthrow new SquareCloudValidationError(\n\t\t\tcode ? `INVALID_${code}` : \"VALIDATION_ERROR\",\n\t\t\t`Expect ${expect}, got ${typeof value}`,\n\t\t);\n\t}\n}\n\nexport function handleAPIObjectAssertion({\n\tschema,\n\tvalue,\n\tcode,\n}: APIObjectAssertionProps) {\n\tconst name = code.toLowerCase().replaceAll(\"_\", \" \");\n\n\ttry {\n\t\treturn schema.parse(value);\n\t} catch (err) {\n\t\tconst cause = err.errors?.map((err: ZodIssue) => ({\n\t\t\t...err,\n\t\t\tpath: err.path.join(\" > \"),\n\t\t}));\n\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