@squarecloud/blob
Version:
Official Square Cloud Blob SDK for NodeJS
1 lines • 4.07 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/validation/schemas/stats.ts","../../../src/structures/error.ts","../../../src/validation/assertions/handlers.ts","../../../src/validation/assertions/stats.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const statsResponseSchema = z.object({\n\t/** The total number of objects in your account. */\n\tobjects: z.number(),\n\t/** The total size of all objects in your account, in bytes. */\n\tsize: z.number(),\n\t/** The total price of storage for all objects in your account, in BRL. */\n\tstoragePrice: z.number(),\n\t/** The total price of all objects in your account, in BRL. */\n\tobjectsPrice: z.number(),\n\t/** The total price of all objects in your account, in BRL. */\n\ttotalEstimate: z.number(),\n});\n","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\n\t\tthrow new SquareCloudBlobError(\n\t\t\t`INVALID_API_${code}`,\n\t\t\t`Invalid ${name} object received from API`,\n\t\t\t{ cause },\n\t\t);\n\t}\n}\n","import type { StatsResponse } from \"../../types/stats\";\nimport { statsResponseSchema } from \"../schemas/stats\";\nimport { handleAPIObjectAssertion } from \"./handlers\";\n\nexport function assertStatsResponse(value: unknown): StatsResponse {\n\treturn handleAPIObjectAssertion({\n\t\tschema: statsResponseSchema,\n\t\tcode: \"ACCOUNT_STATS\",\n\t\tvalue,\n\t});\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,sBAAsB,EAAE,OAAO;AAAA;AAAA,EAE3C,SAAS,EAAE,OAAO;AAAA;AAAA,EAElB,MAAM,EAAE,OAAO;AAAA;AAAA,EAEf,cAAc,EAAE,OAAO;AAAA;AAAA,EAEvB,cAAc,EAAE,OAAO;AAAA;AAAA,EAEvB,eAAe,EAAE,OAAO;AACzB,CAAC;;;ACbM,IAAM,uBAAN,MAAM,8BAA6B,MAAM;AAAA,EAC/C,YAAY,MAAc,SAAkB,OAAiB;AAC5D,UAAM,SAAS,EAAE,MAAM,CAAC;AAExB,SAAK,OAAO,sBAAqB;AACjC,SAAK,UAAU,KAAK,WAAW,IAAI;AAAA,EACpC;AAAA,EAEQ,WAAW,SAAiB;AACnC,UAAM,OAAO,QACX,WAAW,KAAK,GAAG,EACnB,YAAY,EACZ,QAAQ,aAAa,CAAC,MAAM,EAAE,YAAY,CAAC;AAC7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