UNPKG

1.53 kBTypeScriptView Raw
1import { IncomingMessage, ServerResponse } from 'http';
2
3interface SourceData {
4 mtime?: Date;
5 maxAge?: number;
6 getData: () => Promise<Buffer>;
7}
8declare type Source = (src: string) => Promise<SourceData>;
9declare type SourceFactory = (options?: any) => Source;
10
11interface ImageMeta {
12 width: number;
13 height: number;
14 type: string;
15 mimeType: string;
16}
17interface IPXInputOptions {
18 source?: string;
19 modifiers?: Record<string, string>;
20}
21interface IPXCTX {
22 sources: Record<string, Source>;
23}
24declare type IPX = (id: string, opts?: IPXInputOptions) => {
25 src: () => Promise<SourceData>;
26 data: () => Promise<{
27 data: Buffer;
28 meta: ImageMeta;
29 format: string;
30 }>;
31};
32interface IPXOptions {
33 dir?: false | string;
34 domains?: false | string[];
35 alias: Record<string, string>;
36 sharp?: {
37 [key: string]: any;
38 };
39}
40declare function createIPX(userOptions: Partial<IPXOptions>): IPX;
41
42interface IPXHRequest {
43 url: string;
44 headers?: Record<string, string>;
45}
46interface IPXHResponse {
47 statusCode: number;
48 statusMessage: string;
49 headers: Record<string, string>;
50 data: any;
51}
52declare function handleRequest(req: IPXHRequest, ipx: IPX): Promise<IPXHResponse>;
53declare function createIPXMiddleware(ipx: IPX): (req: IncomingMessage, res: ServerResponse) => void;
54
55export { IPX, IPXCTX, IPXHRequest, IPXHResponse, IPXInputOptions, IPXOptions, ImageMeta, Source, SourceData, SourceFactory, createIPX, createIPXMiddleware, handleRequest };