@squarecloud/blob
Version:
Official Square Cloud Blob SDK for NodeJS
1 lines • 7.65 kB
Source Map (JSON)
{"version":3,"sources":["../../../src/validation/schemas/create.ts","../../../src/utils/mimetype/mimetypes.ts","../../../src/utils/mimetype/index.ts","../../../src/validation/schemas/common.ts"],"sourcesContent":["import { z } from \"zod\";\nimport { MimeTypeUtil } from \"../../utils/mimetype\";\nimport { nameLikeSchema } from \"./common\";\n\nexport const createObjectSchema = z\n\t.object({\n\t\t/** A string representing the name for the file. */\n\t\tname: nameLikeSchema,\n\t\t/** Use absolute path, Buffer or Blob */\n\t\tfile: z.string().or(z.instanceof(Buffer)),\n\t\t/** A string representing the MIME type of the file. */\n\t\tmimeType: z.enum(MimeTypeUtil.mimeTypes).optional(),\n\t\t/** A string representing the prefix for the file. */\n\t\tprefix: nameLikeSchema.optional(),\n\t\t/** A number indicating the expiration period of the file, ranging from 1 to 365 days. */\n\t\texpiresIn: z.number().min(1).max(365).optional(),\n\t\t/** Set to true if a security hash is required. */\n\t\tsecurityHash: z.boolean().optional(),\n\t\t/** Set to true if the file should be set for automatic download. */\n\t\tautoDownload: z.boolean().optional(),\n\t})\n\t.refine(({ file, mimeType }) => !(file instanceof Buffer && !mimeType), {\n\t\tmessage: \"mimeType is required if file is a Buffer\",\n\t\tpath: [\"mimeType\"],\n\t});\n\nexport const createObjectPayloadSchema = createObjectSchema.transform(\n\t({ file, securityHash, autoDownload, expiresIn, ...rest }) => ({\n\t\tfile,\n\t\tmimeType:\n\t\t\ttypeof file === \"string\"\n\t\t\t\t? MimeTypeUtil.fromExtension(file.split(\".\")[1])\n\t\t\t\t: undefined,\n\t\tparams: {\n\t\t\t...rest,\n\t\t\texpire: expiresIn,\n\t\t\tsecurity_hash: securityHash,\n\t\t\tauto_download: autoDownload,\n\t\t},\n\t}),\n);\n\nexport const createObjectResponseSchema = z.object({\n\t/** The id of the uploaded file. */\n\tid: z.string(),\n\t/** The name of the uploaded file. */\n\tname: z.string(),\n\t/** The prefix of the uploaded file. */\n\tprefix: z.string().optional(),\n\t/** The size of the uploaded file. */\n\tsize: z.number(),\n\t/** The URL of the uploaded file. (File distributed in Square Cloud CDN) */\n\turl: z.string(),\n});\n","export const mimeTypesWithExtension = {\n\t\"video/mp4\": [\"mp4\"],\n\t\"video/mpeg\": [\"mpeg\"],\n\t\"video/webm\": [\"webm\"],\n\t\"video/x-flv\": [\"flv\"],\n\t\"video/x-m4v\": [\"m4v\"],\n\t\"image/jpeg\": [\"jpg\", \"jpeg\"],\n\t\"image/png\": [\"png\"],\n\t\"image/apng\": [\"apng\"],\n\t\"image/tiff\": [\"tiff\"],\n\t\"image/gif\": [\"gif\"],\n\t\"image/webp\": [\"webp\"],\n\t\"image/bmp\": [\"bmp\"],\n\t\"image/svg+xml\": [\"svg\"],\n\t\"image/x-icon\": [\"ico\"],\n\t\"image/ico\": [\"ico\"],\n\t\"image/cur\": [\"cur\"],\n\t\"image/heic\": [\"heic\"],\n\t\"image/heif\": [\"heif\"],\n\t\"audio/wav\": [\"wav\"],\n\t\"audio/ogg\": [\"ogg\"],\n\t\"audio/opus\": [\"opus\"],\n\t\"audio/mp4\": [\"mp4\"],\n\t\"audio/mpeg\": [\"mp3\"],\n\t\"audio/aac\": [\"aac\"],\n\t\"text/plain\": [\"txt\"],\n\t\"text/html\": [\"html\"],\n\t\"text/css\": [\"css\"],\n\t\"text/csv\": [\"csv\"],\n\t\"text/x-sql\": [\"sql\"],\n\t\"application/xml\": [\"xml\"],\n\t\"application/sql\": [\"sql\"],\n\t\"application/x-sql\": [\"sql\"],\n\t\"application/x-sqlite3\": [\"sqlite3\"],\n\t\"application/x-pkcs12\": [\"pfx\"],\n\t\"application/pdf\": [\"pdf\"],\n\t\"application/json\": [\"json\"],\n\t\"application/javascript\": [\"js\"],\n};\n\nexport const mimeTypes = Object.keys(mimeTypesWithExtension) as [\n\tMimeType,\n\t...MimeType[],\n];\n\nexport type MimeType = keyof typeof mimeTypesWithExtension;\n","import { type MimeType, mimeTypes, mimeTypesWithExtension } from \"./mimetypes\";\n\n// biome-ignore lint/complexity/noStaticOnlyClass: organization\nexport class MimeTypeUtil {\n\t/** Supported mime types with their extensions */\n\tstatic mimeTypesWithExtension = mimeTypesWithExtension;\n\t/** All supported mime types */\n\tstatic mimeTypes = mimeTypes;\n\n\t/**\n\t * Returns the corresponding MIME type for a given file extension.\n\t *\n\t * @param extension - The file extension to search for.\n\t * @return The MIME type associated with the extension, or \"text/plain\" if not found.\n\t *\n\t * @example\n\t * ```js\n\t * \tMimeTypeUtil.fromExtension(\"jpeg\") // \"image/jpeg\" | Supported\n\t * \tMimeTypeUtil.fromExtension(\"json\") // \"application/json\" | Supported\n\t * \tMimeTypeUtil.fromExtension(\"potato\") // \"text/plain\" | Unsupported, defaults to text/plain\n\t * ```\n\t */\n\tstatic fromExtension(extension: string): MimeType {\n\t\tconst entries = Object.entries(mimeTypesWithExtension);\n\t\tconst mimeType = entries.find(([, extensions]) =>\n\t\t\textensions.includes(extension),\n\t\t)?.[0];\n\n\t\treturn (mimeType as MimeType) || \"text/plain\";\n\t}\n}\n\nexport * from \"./enum\";\nexport { MimeType } from \"./mimetypes\";\n","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"],"mappings":";;;;;;;;AAAA,SAAS,KAAAA,UAAS;;;ACAX,IAAM,yBAAyB;AAAA,EACrC,aAAa,CAAC,KAAK;AAAA,EACnB,cAAc,CAAC,MAAM;AAAA,EACrB,cAAc,CAAC,MAAM;AAAA,EACrB,eAAe,CAAC,KAAK;AAAA,EACrB,eAAe,CAAC,KAAK;AAAA,EACrB,cAAc,CAAC,OAAO,MAAM;AAAA,EAC5B,aAAa,CAAC,KAAK;AAAA,EACnB,cAAc,CAAC,MAAM;AAAA,EACrB,cAAc,CAAC,MAAM;AAAA,EACrB,aA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