ipx 3.1.1 → 4.0.0-alpha.2

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.mts CHANGED
@@ -1,74 +1,73 @@
1
- import { Color, KernelEnum, Sharp, SharpOptions } from 'sharp';
2
- import { ImageMeta } from 'image-meta';
3
- import { Config } from 'svgo';
4
- import * as h3 from 'h3';
5
- import { Storage, Driver } from 'unstorage';
6
-
1
+ import { ImageMeta } from "./_chunks/libs/image-meta.mjs";
2
+ import { NodeHttpHandler, Server, ServerOptions } from "srvx";
3
+ import { Color, KernelEnum, Sharp, SharpOptions } from "sharp";
4
+ import { Config } from "svgo";
5
+ import { Driver, Storage } from "unstorage";
7
6
  interface HandlerContext {
8
- /**
9
- * Optional quality setting for the output image, affects compression in certain formats.
10
- * @optional
11
- */
12
- quality?: number;
13
- /**
14
- * Specifies the method to fit the image to the dimensions provided, e.g., 'contain', 'cover'.
15
- * @optional
16
- */
17
- fit?: "contain" | "cover" | "fill" | "inside" | "outside";
18
- /**
19
- * The position used for cropping or positioning, specified as a number or string.
20
- * @optional
21
- */
22
- position?: number | string;
23
- /**
24
- * Background colour to be used if necessary, provided as a colour object. See {@link Color}.
25
- * @optional
26
- */
27
- background?: Color;
28
- /**
29
- * Specifies whether to enlarge the image if it is smaller than the desired size.
30
- * @optional
31
- */
32
- enlarge?: boolean;
33
- /**
34
- * The type of kernel to use for image operations such as resizing. See {@link KernelEnum}.
35
- * @optional
36
- */
37
- kernel?: keyof KernelEnum;
38
- /**
39
- * Metadata about the image being processed.
40
- */
41
- meta: ImageMeta;
7
+ /**
8
+ * Optional quality setting for the output image, affects compression in certain formats.
9
+ * @optional
10
+ */
11
+ quality?: number;
12
+ /**
13
+ * Specifies the method to fit the image to the dimensions provided, e.g., 'contain', 'cover'.
14
+ * @optional
15
+ */
16
+ fit?: "contain" | "cover" | "fill" | "inside" | "outside";
17
+ /**
18
+ * The position used for cropping or positioning, specified as a number or string.
19
+ * @optional
20
+ */
21
+ position?: number | string;
22
+ /**
23
+ * Background colour to be used if necessary, provided as a colour object. See {@link Color}.
24
+ * @optional
25
+ */
26
+ background?: Color;
27
+ /**
28
+ * Specifies whether to enlarge the image if it is smaller than the desired size.
29
+ * @optional
30
+ */
31
+ enlarge?: boolean;
32
+ /**
33
+ * The type of kernel to use for image operations such as resizing. See {@link KernelEnum}.
34
+ * @optional
35
+ */
36
+ kernel?: keyof KernelEnum;
37
+ /**
38
+ * Metadata about the image being processed.
39
+ */
40
+ meta: ImageMeta;
42
41
  }
43
42
  interface Handler {
44
- /**
45
- * An array of functions that convert the given string arguments into usable forms.
46
- */
47
- args: ((argument: string) => any)[];
48
- /**
49
- * Defines the order in which this handler should be applied relative to other handlers.
50
- * @optional
51
- */
52
- order?: number;
53
- /**
54
- * Function to apply the effects of this handler to the image pipeline.
55
- * @param {HandlerContext} context - The current image processing context. See {@link HandlerContext}.
56
- * @param {Sharp} pipe - The Sharp instance to use for image processing. See {@link Sharp}.
57
- * @param {...any} arguments_ - Transformed arguments to use in the handler.
58
- */
59
- apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
43
+ /**
44
+ * An array of functions that convert the given string arguments into usable forms.
45
+ */
46
+ args: ((argument: string) => any)[];
47
+ /**
48
+ * Defines the order in which this handler should be applied relative to other handlers.
49
+ * @optional
50
+ */
51
+ order?: number;
52
+ /**
53
+ * Function to apply the effects of this handler to the image pipeline.
54
+ * @param {HandlerContext} context - The current image processing context. See {@link HandlerContext}.
55
+ * @param {Sharp} pipe - The Sharp instance to use for image processing. See {@link Sharp}.
56
+ * @param {...any} arguments_ - Transformed arguments to use in the handler.
57
+ */
58
+ apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
60
59
  }
61
60
  type IPXStorageMeta = {
62
- /**
63
- * The modification time of the stored item.
64
- * @optional
65
- */
66
- mtime?: Date | number | string;
67
- /**
68
- * The maximum age (in seconds) at which the stored item should be considered fresh.
69
- * @optional
70
- */
71
- maxAge?: number | string;
61
+ /**
62
+ * The modification time of the stored item.
63
+ * @optional
64
+ */
65
+ mtime?: Date | number | string;
66
+ /**
67
+ * The maximum age (in seconds) at which the stored item should be considered fresh.
68
+ * @optional
69
+ */
70
+ maxAge?: number | string;
72
71
  };
73
72
  /**
74
73
  * Options specific to image saving operations.
@@ -76,145 +75,77 @@ type IPXStorageMeta = {
76
75
  type IPXStorageOptions = Record<string, unknown>;
77
76
  type MaybePromise<T> = T | Promise<T>;
78
77
  interface IPXStorage {
79
- /**
80
- * A descriptive name for the storage type.
81
- */
82
- name: string;
83
- /**
84
- * Retrieves metadata for an image identified by 'id'.
85
- * @param {string} id - The identifier for the image.
86
- * @param {IPXStorageOptions} [opts] - Optional metadata retrieval options. See {@link IPXStorageOptions}.
87
- * @returns {MaybePromise<IPXStorageMeta | undefined>} A promise or direct return of the metadata, or undefined if not found. See {@link IPXStorageMeta}.
88
- */
89
- getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
90
- /**
91
- * Get the actual data for an image identified by 'id'.
92
- * @param {string} id - The identifier for the image.
93
- * @param {IPXStorageOptions} [opts] - Optional options for the data retrieval. See {@link IPXStorageOptions}.
94
- * @returns {MaybePromise<ArrayBuffer | undefined>} A promise or direct return of the image data as an ArrayBuffer, or undefined if not found. See {@link ArrayBuffer}.
95
- */
96
- getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
78
+ /**
79
+ * A descriptive name for the storage type.
80
+ */
81
+ name: string;
82
+ /**
83
+ * Retrieves metadata for an image identified by 'id'.
84
+ * @param {string} id - The identifier for the image.
85
+ * @param {IPXStorageOptions} [opts] - Optional metadata retrieval options. See {@link IPXStorageOptions}.
86
+ * @returns {MaybePromise<IPXStorageMeta | undefined>} A promise or direct return of the metadata, or undefined if not found. See {@link IPXStorageMeta}.
87
+ */
88
+ getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
89
+ /**
90
+ * Get the actual data for an image identified by 'id'.
91
+ * @param {string} id - The identifier for the image.
92
+ * @param {IPXStorageOptions} [opts] - Optional options for the data retrieval. See {@link IPXStorageOptions}.
93
+ * @returns {MaybePromise<Buffer | ArrayBuffer | undefined>} A promise or direct return of the image data as an ArrayBuffer, or undefined if not found. See {@link ArrayBuffer}.
94
+ */
95
+ getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<Buffer | ArrayBuffer | undefined>;
97
96
  }
98
-
99
- declare const quality: Handler;
100
- declare const fit: Handler;
101
- declare const position: Handler;
102
- declare const background: Handler;
103
- declare const enlarge: Handler;
104
- declare const kernel: Handler;
105
- declare const width: Handler;
106
- declare const height: Handler;
107
- declare const resize: Handler;
108
- declare const trim: Handler;
109
- declare const extend: Handler;
110
- declare const extract: Handler;
111
- declare const rotate: Handler;
112
- declare const flip: Handler;
113
- declare const flop: Handler;
114
- declare const sharpen: Handler;
115
- declare const median: Handler;
116
- declare const blur: Handler;
117
- declare const flatten: Handler;
118
- declare const gamma: Handler;
119
- declare const negate: Handler;
120
- declare const normalize: Handler;
121
- declare const threshold: Handler;
122
- declare const modulate: Handler;
123
- declare const tint: Handler;
124
- declare const grayscale: Handler;
125
- declare const crop: Handler;
126
- declare const q: Handler;
127
- declare const b: Handler;
128
- declare const w: Handler;
129
- declare const h: Handler;
130
- declare const s: Handler;
131
- declare const pos: Handler;
132
-
133
- declare const Handlers_b: typeof b;
134
- declare const Handlers_background: typeof background;
135
- declare const Handlers_blur: typeof blur;
136
- declare const Handlers_crop: typeof crop;
137
- declare const Handlers_enlarge: typeof enlarge;
138
- declare const Handlers_extend: typeof extend;
139
- declare const Handlers_extract: typeof extract;
140
- declare const Handlers_fit: typeof fit;
141
- declare const Handlers_flatten: typeof flatten;
142
- declare const Handlers_flip: typeof flip;
143
- declare const Handlers_flop: typeof flop;
144
- declare const Handlers_gamma: typeof gamma;
145
- declare const Handlers_grayscale: typeof grayscale;
146
- declare const Handlers_h: typeof h;
147
- declare const Handlers_height: typeof height;
148
- declare const Handlers_kernel: typeof kernel;
149
- declare const Handlers_median: typeof median;
150
- declare const Handlers_modulate: typeof modulate;
151
- declare const Handlers_negate: typeof negate;
152
- declare const Handlers_normalize: typeof normalize;
153
- declare const Handlers_pos: typeof pos;
154
- declare const Handlers_position: typeof position;
155
- declare const Handlers_q: typeof q;
156
- declare const Handlers_quality: typeof quality;
157
- declare const Handlers_resize: typeof resize;
158
- declare const Handlers_rotate: typeof rotate;
159
- declare const Handlers_s: typeof s;
160
- declare const Handlers_sharpen: typeof sharpen;
161
- declare const Handlers_threshold: typeof threshold;
162
- declare const Handlers_tint: typeof tint;
163
- declare const Handlers_trim: typeof trim;
164
- declare const Handlers_w: typeof w;
165
- declare const Handlers_width: typeof width;
166
- declare namespace Handlers {
167
- export {
168
- Handlers_b as b,
169
- Handlers_background as background,
170
- Handlers_blur as blur,
171
- Handlers_crop as crop,
172
- Handlers_enlarge as enlarge,
173
- Handlers_extend as extend,
174
- Handlers_extract as extract,
175
- Handlers_fit as fit,
176
- Handlers_flatten as flatten,
177
- Handlers_flip as flip,
178
- Handlers_flop as flop,
179
- Handlers_gamma as gamma,
180
- Handlers_grayscale as grayscale,
181
- Handlers_h as h,
182
- Handlers_height as height,
183
- Handlers_kernel as kernel,
184
- Handlers_median as median,
185
- Handlers_modulate as modulate,
186
- Handlers_negate as negate,
187
- Handlers_normalize as normalize,
188
- Handlers_pos as pos,
189
- Handlers_position as position,
190
- Handlers_q as q,
191
- Handlers_quality as quality,
192
- Handlers_resize as resize,
193
- Handlers_rotate as rotate,
194
- Handlers_s as s,
195
- Handlers_sharpen as sharpen,
196
- Handlers_threshold as threshold,
197
- Handlers_tint as tint,
198
- Handlers_trim as trim,
199
- Handlers_w as w,
200
- Handlers_width as width,
201
- };
202
- }
203
-
204
- type HandlerName = keyof typeof Handlers;
205
-
206
97
  type IPXSourceMeta = {
207
- /**
208
- * The modification time of the source. Used for cache validation.
209
- * @optional
210
- */
211
- mtime?: Date;
212
- /**
213
- * The maximum age (in seconds) that the source should be considered fresh.
214
- * @optional
215
- */
216
- maxAge?: number;
98
+ /**
99
+ * The modification time of the source. Used for cache validation.
100
+ * @optional
101
+ */
102
+ mtime?: Date;
103
+ /**
104
+ * The maximum age (in seconds) that the source should be considered fresh.
105
+ * @optional
106
+ */
107
+ maxAge?: number;
217
108
  };
109
+ type FormatModifier = "jpeg" | "jpg" | "png" | "webp" | "avif" | "gif" | "heif" | "tiff" | "auto" | (string & {});
110
+ interface IPXModifiers {
111
+ format: FormatModifier;
112
+ f: FormatModifier;
113
+ fit: "contain" | "cover" | "fill" | "inside" | "outside" | (string & {});
114
+ resize: string;
115
+ s: string;
116
+ quality: number | string;
117
+ q: number | string;
118
+ background: string;
119
+ b: string;
120
+ position: string;
121
+ pos: string;
122
+ enlarge: true | "true";
123
+ kernel: "nearest" | "cubic" | "mitchell" | "lanczos2" | "lanczos3" | (string & {});
124
+ trim: number | string;
125
+ extend: string;
126
+ extract: string;
127
+ crop: string;
128
+ rotate: number | string;
129
+ flip: true | "true";
130
+ flop: true | "true";
131
+ sharpen: number | string;
132
+ median: number | string;
133
+ blur: number | string;
134
+ flatten: true | "true";
135
+ gamma: string;
136
+ negate: true | "true";
137
+ normalize: true | "true";
138
+ threshold: number | string;
139
+ modulate: string;
140
+ tint: number | string;
141
+ grayscale: true | "true";
142
+ animated: true | "true";
143
+ a: true | "true";
144
+ width: string | number;
145
+ w: string | number;
146
+ height: string | number;
147
+ h: string | number;
148
+ }
218
149
  /**
219
150
  * A function type that defines an IPX image processing instance.
220
151
  *
@@ -232,44 +163,44 @@ type IPXSourceMeta = {
232
163
  * - `process`: A method that returns a promise resolving to an object containing the processed image data, metadata,
233
164
  * and format. The image data can be in the form of a `buffer` or a string, depending on the format and processing.
234
165
  */
235
- type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
236
- getSourceMeta: () => Promise<IPXSourceMeta>;
237
- process: () => Promise<{
238
- data: Buffer | string;
239
- meta?: ImageMeta;
240
- format?: string;
241
- }>;
166
+ type IPX = (id: string, modifiers?: Partial<IPXModifiers>, requestOptions?: any) => {
167
+ getSourceMeta: () => Promise<IPXSourceMeta>;
168
+ process: () => Promise<{
169
+ data: Buffer | string;
170
+ meta?: ImageMeta;
171
+ format?: string;
172
+ }>;
242
173
  };
243
174
  type IPXOptions = {
244
- /**
245
- * Default cache duration in seconds. If not specified, a default of 1 minute is used.
246
- * @optional
247
- */
248
- maxAge?: number;
249
- /**
250
- * A mapping of URL aliases to their corresponding URLs, used to simplify resource identifiers.
251
- * @optional
252
- */
253
- alias?: Record<string, string>;
254
- /**
255
- * Configuration options for the Sharp image processing library.
256
- * @optional
257
- */
258
- sharpOptions?: SharpOptions;
259
- /**
260
- * Primary storage backend for handling image assets.
261
- */
262
- storage: IPXStorage;
263
- /**
264
- * An optional secondary storage backend used when images are fetched via HTTP.
265
- * @optional
266
- */
267
- httpStorage?: IPXStorage;
268
- /**
269
- * Configuration for the SVGO library used when processing SVG images.
270
- * @optional
271
- */
272
- svgo?: false | Config;
175
+ /**
176
+ * Default cache duration in seconds. If not specified, a default of 1 minute is used.
177
+ * @optional
178
+ */
179
+ maxAge?: number;
180
+ /**
181
+ * A mapping of URL aliases to their corresponding URLs, used to simplify resource identifiers.
182
+ * @optional
183
+ */
184
+ alias?: Record<string, string>;
185
+ /**
186
+ * Configuration options for the Sharp image processing library.
187
+ * @optional
188
+ */
189
+ sharpOptions?: SharpOptions;
190
+ /**
191
+ * Primary storage backend for handling image assets.
192
+ */
193
+ storage: IPXStorage;
194
+ /**
195
+ * An optional secondary storage backend used when images are fetched via HTTP.
196
+ * @optional
197
+ */
198
+ httpStorage?: IPXStorage;
199
+ /**
200
+ * Configuration for the SVGO library used when processing SVG images.
201
+ * @optional
202
+ */
203
+ svgo?: false | Config;
273
204
  };
274
205
  /**
275
206
  * Creates an IPX image processing instance with the specified options.
@@ -278,70 +209,36 @@ type IPXOptions = {
278
209
  * @throws {Error} If critical options such as storage are missing or incorrectly configured.
279
210
  */
280
211
  declare function createIPX(userOptions: IPXOptions): IPX;
281
-
282
- /**
283
- * Creates an H3 handler to handle images using IPX.
284
- * @param {IPX} ipx - An IPX instance to handle image requests.
285
- * @returns {H3Event} An H3 event handler that processes image requests, applies modifiers, handles caching,
286
- * and returns the processed image data. See {@link H3Event}.
287
- * @throws {H3Error} If there are problems with the request parameters or processing the image. See {@link H3Error}.
288
- */
289
- declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<string | void | Buffer<ArrayBufferLike> | {
290
- error: {
291
- message: string;
292
- };
293
- }>>;
294
- /**
295
- * Creates an H3 application configured to handle image processing using a supplied IPX instance.
296
- * @param {IPX} ipx - An IPX instance to handle image handling requests.
297
- * @returns {any} An H3 application configured to use the IPX image handler.
298
- */
299
- declare function createIPXH3App(ipx: IPX): h3.App;
300
- /**
301
- * Creates a web server that can handle IPX image processing requests using an H3 application.
302
- * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
303
- * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
304
- */
305
- declare function createIPXWebServer(ipx: IPX): h3.WebHandler;
306
- /**
307
- * Creates a web server that can handle IPX image processing requests using an H3 application.
308
- * @param {IPX} ipx - An IPX instance configured for the server. See {@link IPX}.
309
- * @returns {any} A web handler suitable for use with web server environments that support the H3 library.
310
- */
311
- declare function createIPXNodeServer(ipx: IPX): h3.NodeListener;
312
- /**
313
- * Creates a simple server that can handle IPX image processing requests using an H3 application.
314
- * @param {IPX} ipx - An IPX instance configured for the server.
315
- * @returns {any} A handler suitable for plain HTTP server environments that support the H3 library.
316
- */
317
- declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
318
-
212
+ type FetchHandler = (request: Request | string | URL) => Response | Promise<Response>;
213
+ declare function createIPXFetchHandler(ipx: IPX): FetchHandler;
214
+ declare function createIPXNodeHandler(ipx: IPX): NodeHttpHandler;
215
+ declare function serveIPX(ipx: IPX, opts?: Omit<ServerOptions, "fetch">): Server;
319
216
  type HTTPStorageOptions = {
320
- /**
321
- * Custom options for fetch operations, such as headers or method overrides.
322
- * @optional
323
- */
324
- fetchOptions?: RequestInit;
325
- /**
326
- * Default maximum age (in seconds) for cache control. If not specified, defaults to the environment setting or 300 seconds.
327
- * @optional
328
- */
329
- maxAge?: number;
330
- /**
331
- * Whitelist of domains from which resource fetching is allowed. Can be a single string or an array of strings.
332
- * @optional
333
- */
334
- domains?: string | string[];
335
- /**
336
- * If set to true, allows retrieval from any domain. Overrides the domain whitelist.
337
- * @optional
338
- */
339
- allowAllDomains?: boolean;
340
- /**
341
- * If set to true, ignore the cache control header in responses and use the default or specified maxAge.
342
- * @optional
343
- */
344
- ignoreCacheControl?: boolean;
217
+ /**
218
+ * Custom options for fetch operations, such as headers or method overrides.
219
+ * @optional
220
+ */
221
+ fetchOptions?: RequestInit;
222
+ /**
223
+ * Default maximum age (in seconds) for cache control. If not specified, defaults to the environment setting or 300 seconds.
224
+ * @optional
225
+ */
226
+ maxAge?: number;
227
+ /**
228
+ * Whitelist of domains from which resource fetching is allowed. Can be a single string or an array of strings.
229
+ * @optional
230
+ */
231
+ domains?: string | string[];
232
+ /**
233
+ * If set to true, allows retrieval from any domain. Overrides the domain whitelist.
234
+ * @optional
235
+ */
236
+ allowAllDomains?: boolean;
237
+ /**
238
+ * If set to true, ignore the cache control header in responses and use the default or specified maxAge.
239
+ * @optional
240
+ */
241
+ ignoreCacheControl?: boolean;
345
242
  };
346
243
  /**
347
244
  * Creates an HTTP storage handler for IPX that fetches image data from external URLs.
@@ -352,18 +249,17 @@ type HTTPStorageOptions = {
352
249
  * @throws {H3Error} If validation of the requested URL fails due to a missing hostname or denied host access. See {@link H3Error}.
353
250
  */
354
251
  declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
355
-
356
252
  type NodeFSSOptions = {
357
- /**
358
- * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
359
- * @optional
360
- */
361
- dir?: string | string[];
362
- /**
363
- * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
364
- * @optional
365
- */
366
- maxAge?: number;
253
+ /**
254
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
255
+ * @optional
256
+ */
257
+ dir?: string | string[];
258
+ /**
259
+ * The directory or list of directories from which to serve files. If not specified, the current directory is used by default.
260
+ * @optional
261
+ */
262
+ maxAge?: number;
367
263
  };
368
264
  /**
369
265
  * Creates a file system storage handler for IPX that allows images to be served from local directories specified in the options.
@@ -374,13 +270,12 @@ type NodeFSSOptions = {
374
270
  * @throws {H3Error} If there is a problem accessing the file system module or resolving/reading files. See {@link H3Error}.
375
271
  */
376
272
  declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
377
-
378
273
  type UnstorageIPXStorageOptions = {
379
- /**
380
- * Optional prefix to be placed in front of each storage key, which can help to name or categorise stored items.
381
- * @optional
382
- */
383
- prefix?: string;
274
+ /**
275
+ * Optional prefix to be placed in front of each storage key, which can help to name or categorise stored items.
276
+ * @optional
277
+ */
278
+ prefix?: string;
384
279
  };
385
280
  /**
386
281
  * Adapts an Unstorage driver or storage system to comply with the IPXStorage interface required by IPX.
@@ -392,6 +287,4 @@ type UnstorageIPXStorageOptions = {
392
287
  * @throws {H3Error} If there is a problem retrieving or converting the storage data, detailed error information is thrown. See {@link H3Error}.
393
288
  */
394
289
  declare function unstorageToIPXStorage(storage: Storage | Driver, _options?: UnstorageIPXStorageOptions | string): IPXStorage;
395
-
396
- export { createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
397
- export type { HTTPStorageOptions, Handler, HandlerContext, IPX, IPXOptions, IPXStorage, IPXStorageMeta, IPXStorageOptions, NodeFSSOptions, UnstorageIPXStorageOptions };
290
+ export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXModifiers, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type NodeFSSOptions, type UnstorageIPXStorageOptions, createIPX, createIPXFetchHandler, createIPXNodeHandler, ipxFSStorage, ipxHttpStorage, serveIPX, unstorageToIPXStorage };
package/dist/index.mjs CHANGED
@@ -1,52 +1,32 @@
1
- export { c as createIPX, b as createIPXH3App, a as createIPXH3Handler, e as createIPXNodeServer, f as createIPXPlainServer, d as createIPXWebServer, g as ipxFSStorage, i as ipxHttpStorage } from './shared/ipx.CXJeaylD.mjs';
2
- import { createError } from 'h3';
3
- import 'defu';
4
- import 'ufo';
5
- import 'image-meta';
6
- import 'destr';
7
- import '@fastify/accept-negotiator';
8
- import 'etag';
9
- import 'ofetch';
10
- import 'pathe';
11
-
1
+ import { HTTPError } from "./_chunks/libs/h3.mjs";
2
+ import { createIPX, createIPXFetchHandler, createIPXNodeHandler, ipxFSStorage, ipxHttpStorage, serveIPX } from "./_chunks/node-fs.mjs";
12
3
  function unstorageToIPXStorage(storage, _options = {}) {
13
- const options = typeof _options === "string" ? { prefix: _options } : _options;
14
- const resolveKey = (id) => options.prefix ? `${options.prefix}:${id}` : id;
15
- return {
16
- name: "ipx:" + (storage.name || "unstorage"),
17
- async getMeta(id, opts = {}) {
18
- if (!storage.getMeta) {
19
- return;
20
- }
21
- const storageKey = resolveKey(id);
22
- const meta = await storage.getMeta(storageKey, opts);
23
- return meta;
24
- },
25
- async getData(id, opts = {}) {
26
- if (!storage.getItemRaw) {
27
- return;
28
- }
29
- const storageKey = resolveKey(id);
30
- let data = await storage.getItemRaw(storageKey, opts);
31
- if (!data) {
32
- return;
33
- }
34
- if (data instanceof Blob) {
35
- data = await data.arrayBuffer();
36
- }
37
- try {
38
- return Buffer.from(data);
39
- } catch (error) {
40
- throw createError({
41
- statusCode: 500,
42
- statusText: `IPX_STORAGE_ERROR`,
43
- message: `Failed to parse storage data to Buffer:
44
- ${error.message}`,
45
- cause: error
46
- });
47
- }
48
- }
49
- };
4
+ const options = typeof _options === "string" ? { prefix: _options } : _options;
5
+ const resolveKey = (id) => options.prefix ? `${options.prefix}:${id}` : id;
6
+ return {
7
+ name: "ipx:" + (storage.name || "unstorage"),
8
+ async getMeta(id, opts = {}) {
9
+ if (!storage.getMeta) return;
10
+ const storageKey = resolveKey(id);
11
+ return await storage.getMeta(storageKey, opts);
12
+ },
13
+ async getData(id, opts = {}) {
14
+ if (!storage.getItemRaw) return;
15
+ const storageKey = resolveKey(id);
16
+ let data = await storage.getItemRaw(storageKey, opts);
17
+ if (!data) return;
18
+ if (data instanceof Blob) data = await data.arrayBuffer();
19
+ try {
20
+ return Buffer.from(data);
21
+ } catch (error) {
22
+ throw new HTTPError({
23
+ statusCode: 500,
24
+ statusText: `IPX_STORAGE_ERROR`,
25
+ message: `Failed to parse storage data to Buffer:\n${error.message}`,
26
+ cause: error
27
+ });
28
+ }
29
+ }
30
+ };
50
31
  }
51
-
52
- export { unstorageToIPXStorage };
32
+ export { createIPX, createIPXFetchHandler, createIPXNodeHandler, ipxFSStorage, ipxHttpStorage, serveIPX, unstorageToIPXStorage };