@nexim/upload-types
Version:
TypeScript types and interfaces for Nexim Media Upload Service, including image preset configurations and file handling types
8 lines (7 loc) • 4.01 kB
Source Map (JSON)
{
"version": 3,
"sources": ["../src/main.ts"],
"sourcesContent": ["import { packageTracer } from '@alwatr/package-tracer';\n\nimport type { ErrorResponse } from '@alwatr/nanotron';\n\n__dev_mode__: packageTracer.add(__package_name__, __package_version__);\n\n/**\n * Configuration for image format and quality settings.\n */\nexport interface UploadImageFormat {\n /**\n * The target image format.\n */\n type: 'webp' | 'jpeg' | 'png' | 'avif';\n\n /**\n * The suffix to append to the file name for this format.\n */\n appendName: string;\n\n /**\n * Format-specific options (e.g., quality, compression settings).\n */\n formatOptions: {\n quality: number;\n mozjpeg?: boolean;\n [key: string]: unknown;\n };\n}\n\n/**\n * Client-side configuration for image processing.\n */\nexport interface UploadImageClientConfig {\n /**\n * The quality of the image (0-100).\n */\n quality: number;\n\n /**\n * The target height of the image. -1 to maintain aspect ratio.\n */\n height: number;\n\n /**\n * The target width of the image. -1 to maintain aspect ratio.\n */\n width: number;\n}\n\n/**\n * Complete configuration preset for image upload and processing.\n * Defines both client-side and server-side processing parameters.\n *\n * @example\n * ```ts\n * const preset: UploadImagePreset = {\n * client: {\n * width: 1280,\n * height: -1, // Maintain aspect ratio\n * quality: 80\n * },\n * format: [\n * {\n * type: 'jpeg',\n * appendName: '@2x.jpeg',\n * formatOptions: { quality: 75, mozjpeg: true },\n * },\n * {\n * type: 'avif',\n * appendName: '@2x.avif',\n * formatOptions: { quality: 70 },\n * },\n * ],\n * };\n * ```\n */\nexport interface UploadImagePreset {\n /**\n * Client-side processing configuration.\n */\n client: UploadImageClientConfig;\n\n /**\n * List of formats to generate on the server.\n */\n format: UploadImageFormat[];\n}\n\n/**\n * Details about an uploaded file stored in the system.\n * Includes common fields and type-specific fields using a discriminated union.\n *\n * @example\n * ```ts\n * // Regular file type\n * const fileDetail: FileDetail = {\n * userId: 'user_123',\n * description: 'Monthly report',\n * type: 'file',\n * };\n *\n * // Image file with multiple variants\n * const imageDetail: FileDetail = {\n * userId: 'user_456',\n * description: 'Product photo',\n * type: 'image',\n * variants: ['@1x.jpeg', '@1x.webp', '@2x.jpeg', '@2x.webp'],\n * };\n * ```\n */\nexport type FileDetail = {\n /** ID of the user who uploaded the file */\n userId: string;\n\n /** Description of the file for maintenance */\n description: string;\n} & (\n | {\n /** Indicates this is a regular file */\n type: 'file';\n } |\n {\n /** Indicates this is an image with multiple format variants */\n type: 'image';\n /** List of file name suffixes for each variant */\n variants: string[];\n }\n);\n\n/**\n * The error response type from the service API.\n * Inherits from the base ErrorResponse type.\n *\n * @internal\n */\nexport type ErrorServiceResponse = ErrorResponse;\n\n/**\n * The success response type from the service API.\n * Contains a data payload of the specified generic type.\n *\n * @internal\n */\nexport type SuccessServiceResponse<TData extends Json> = {\n ok: true;\n data: TData;\n};\n\n/**\n * Combined type representing either a success or error response.\n *\n * @internal\n */\nexport type ServiceResponse<TData extends Json> = SuccessServiceResponse<TData> | ErrorResponse;\n\n/**\n * User authentication information used for validating upload requests.\n *\n * @example\n * ```ts\n * const auth: UserAuth = {\n * id: 'user_12345',\n * token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...',\n * };\n * ```\n */\nexport type UserAuth = {\n id: string;\n token: string;\n};\n"],
"mappings": ";;AAAA,OAAS,kBAAqB,yBAI9B,aAAc,cAAc,IAAI,sBAAkB,eAAmB",
"names": []
}