ipx 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,5 +1,12 @@
1
+ import { Sharp, Color, SharpOptions } from 'sharp';
1
2
  import { IncomingMessage, ServerResponse } from 'node:http';
2
3
 
4
+ interface ImageMeta {
5
+ width: number;
6
+ height: number;
7
+ type: string;
8
+ mimeType: string;
9
+ }
3
10
  interface SourceData {
4
11
  mtime?: Date;
5
12
  maxAge?: number;
@@ -7,17 +14,128 @@ interface SourceData {
7
14
  }
8
15
  type Source = (source: string, requestOptions?: any) => Promise<SourceData>;
9
16
  type SourceFactory<T = Record<string, any>> = (options: T) => Source;
17
+ interface HandlerContext {
18
+ quality?: number;
19
+ fit?: "contain" | "cover" | "fill" | "inside" | "outside";
20
+ position?: number | string;
21
+ background?: Color;
22
+ enlarge?: boolean;
23
+ meta: ImageMeta;
24
+ }
25
+ interface Handler {
26
+ args: ((argument: string) => any)[];
27
+ order?: number;
28
+ apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
29
+ }
10
30
 
11
- interface ImageMeta {
12
- width: number;
13
- height: number;
14
- type: string;
15
- mimeType: string;
31
+ declare const quality: Handler;
32
+ declare const fit: Handler;
33
+ declare const position: Handler;
34
+ declare const background: Handler;
35
+ declare const enlarge: Handler;
36
+ declare const width: Handler;
37
+ declare const height: Handler;
38
+ declare const resize: Handler;
39
+ declare const trim: Handler;
40
+ declare const extend: Handler;
41
+ declare const extract: Handler;
42
+ declare const rotate: Handler;
43
+ declare const flip: Handler;
44
+ declare const flop: Handler;
45
+ declare const sharpen: Handler;
46
+ declare const median: Handler;
47
+ declare const blur: Handler;
48
+ declare const flatten: Handler;
49
+ declare const gamma: Handler;
50
+ declare const negate: Handler;
51
+ declare const normalize: Handler;
52
+ declare const threshold: Handler;
53
+ declare const modulate: Handler;
54
+ declare const tint: Handler;
55
+ declare const grayscale: Handler;
56
+ declare const crop: Handler;
57
+ declare const q: Handler;
58
+ declare const b: Handler;
59
+ declare const w: Handler;
60
+ declare const h: Handler;
61
+ declare const s: Handler;
62
+ declare const pos: Handler;
63
+
64
+ declare const Handlers_b: typeof b;
65
+ declare const Handlers_background: typeof background;
66
+ declare const Handlers_blur: typeof blur;
67
+ declare const Handlers_crop: typeof crop;
68
+ declare const Handlers_enlarge: typeof enlarge;
69
+ declare const Handlers_extend: typeof extend;
70
+ declare const Handlers_extract: typeof extract;
71
+ declare const Handlers_fit: typeof fit;
72
+ declare const Handlers_flatten: typeof flatten;
73
+ declare const Handlers_flip: typeof flip;
74
+ declare const Handlers_flop: typeof flop;
75
+ declare const Handlers_gamma: typeof gamma;
76
+ declare const Handlers_grayscale: typeof grayscale;
77
+ declare const Handlers_h: typeof h;
78
+ declare const Handlers_height: typeof height;
79
+ declare const Handlers_median: typeof median;
80
+ declare const Handlers_modulate: typeof modulate;
81
+ declare const Handlers_negate: typeof negate;
82
+ declare const Handlers_normalize: typeof normalize;
83
+ declare const Handlers_pos: typeof pos;
84
+ declare const Handlers_position: typeof position;
85
+ declare const Handlers_q: typeof q;
86
+ declare const Handlers_quality: typeof quality;
87
+ declare const Handlers_resize: typeof resize;
88
+ declare const Handlers_rotate: typeof rotate;
89
+ declare const Handlers_s: typeof s;
90
+ declare const Handlers_sharpen: typeof sharpen;
91
+ declare const Handlers_threshold: typeof threshold;
92
+ declare const Handlers_tint: typeof tint;
93
+ declare const Handlers_trim: typeof trim;
94
+ declare const Handlers_w: typeof w;
95
+ declare const Handlers_width: typeof width;
96
+ declare namespace Handlers {
97
+ export {
98
+ Handlers_b as b,
99
+ Handlers_background as background,
100
+ Handlers_blur as blur,
101
+ Handlers_crop as crop,
102
+ Handlers_enlarge as enlarge,
103
+ Handlers_extend as extend,
104
+ Handlers_extract as extract,
105
+ Handlers_fit as fit,
106
+ Handlers_flatten as flatten,
107
+ Handlers_flip as flip,
108
+ Handlers_flop as flop,
109
+ Handlers_gamma as gamma,
110
+ Handlers_grayscale as grayscale,
111
+ Handlers_h as h,
112
+ Handlers_height as height,
113
+ Handlers_median as median,
114
+ Handlers_modulate as modulate,
115
+ Handlers_negate as negate,
116
+ Handlers_normalize as normalize,
117
+ Handlers_pos as pos,
118
+ Handlers_position as position,
119
+ Handlers_q as q,
120
+ Handlers_quality as quality,
121
+ Handlers_resize as resize,
122
+ Handlers_rotate as rotate,
123
+ Handlers_s as s,
124
+ Handlers_sharpen as sharpen,
125
+ Handlers_threshold as threshold,
126
+ Handlers_tint as tint,
127
+ Handlers_trim as trim,
128
+ Handlers_w as w,
129
+ Handlers_width as width,
130
+ };
16
131
  }
132
+
133
+ type HandlerName = keyof typeof Handlers;
134
+
17
135
  interface IPXCTX {
18
136
  sources: Record<string, Source>;
19
137
  }
20
- type IPX = (id: string, modifiers?: Record<string, string>, requestOptions?: any) => {
138
+ type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
21
139
  src: () => Promise<SourceData>;
22
140
  data: () => Promise<{
23
141
  data: Buffer;
@@ -31,9 +149,7 @@ interface IPXOptions {
31
149
  domains?: false | string[];
32
150
  alias: Record<string, string>;
33
151
  fetchOptions: RequestInit;
34
- sharp?: {
35
- [key: string]: any;
36
- };
152
+ sharp?: SharpOptions;
37
153
  }
38
154
  declare function createIPX(userOptions: Partial<IPXOptions>): IPX;
39
155
 
@@ -47,8 +163,12 @@ interface IPXHResponse {
47
163
  statusMessage: string;
48
164
  headers: Record<string, string>;
49
165
  body: any;
166
+ error?: any;
167
+ }
168
+ interface MiddlewareOptions {
169
+ fallthrough?: boolean;
50
170
  }
51
171
  declare function handleRequest(request: IPXHRequest, ipx: IPX): Promise<IPXHResponse>;
52
- declare function createIPXMiddleware(ipx: IPX): (request: IncomingMessage, res: ServerResponse) => Promise<void>;
172
+ declare function createIPXMiddleware(ipx: IPX, options?: Partial<MiddlewareOptions>): (request: IncomingMessage, res: ServerResponse, next?: ((err?: any) => void) | undefined) => Promise<void>;
53
173
 
54
- export { IPX, IPXCTX, IPXHRequest, IPXHResponse, IPXOptions, ImageMeta, Source, SourceData, SourceFactory, createIPX, createIPXMiddleware, handleRequest };
174
+ export { IPX, IPXCTX, IPXHRequest, IPXHResponse, IPXOptions, MiddlewareOptions, Source, SourceData, SourceFactory, createIPX, createIPXMiddleware, handleRequest };