@squarecloud/blob
Version:
Official Square Cloud Blob SDK for NodeJS
1 lines • 3.63 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/validation/schemas/common.ts","../../../src/structures/error.ts","../../../src/validation/assertions/handlers.ts","../../../src/validation/assertions/literal.ts"],"sourcesContent":["import { z } from \"zod\";\n\nexport const stringSchema = z.string();\n\nexport const nameLikeSchema = z\n\t.string()\n\t.min(3)\n\t.max(32)\n\t.regex(/^[a-zA-Z0-9_]{3,32}$/, {\n\t\tmessage: \"Name must contain only letters, numbers and _\",\n\t});\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 { stringSchema } from \"../schemas/common\";\nimport { handleLiteralAssertion } from \"./handlers\";\n\nexport function assertString(\n\tvalue: unknown,\n\tcode?: string,\n): asserts value is string {\n\thandleLiteralAssertion({\n\t\tschema: stringSchema,\n\t\texpect: \"string\",\n\t\tvalue,\n\t\tcode,\n\t});\n}\n"],"mappings":";AAAA,SAAS,SAAS;AAEX,IAAM,eAAe,EAAE,OAAO;AAE9B,IAAM,iBAAiB,EAC5B,OAAO,EACP,IAAI,CAAC,EACL,IAAI,EAAE,EACN,MAAM,wBAAwB;AAAA,EAC9B,SAAS;AACV,CAAC;;;ACVK,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;AAC7C,UAAM,UAAU,KAAK,UAAU,KAAK,KAAK,OAAO,KAAK;AAErD,WAAO,GAAG,IAAI,GAAG,OAAO;AAAA,EACzB;AACD;AAEO,IAAM,6BAAN,MAAM,oCAAmC,qBAAqB;AAAA,EACpE,eAAe,MAA0D;AACxE,UAAM,GAAG,IAAI;AACb,SAAK,OAAO,4BAA2B;AAAA,EACxC;AACD;;;ACdO,SAAS,uBAAuB;AAAA,EACtC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,GAA0B;AACzB,MAAI;AACH,WAAO,MAAM,KAAK;AAAA,EACnB,QAAQ;AACP,UAAM,IAAI;AAAA,MACT,OAAO,WAAW,IAAI,KAAK;AAAA,MAC3B,UAAU,MAAM,SAAS,OAAO,KAAK;AAAA,IACtC;AAAA,EACD;AACD;;;ACrBO,SAAS,aACf,OACA,MAC0B;AAC1B,yBAAuB;AAAA,IACtB,QAAQ;AAAA,IACR,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EACD,CAAC;AACF;","names":[]}