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