ipx 1.3.0 → 2.0.0-1

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.cts CHANGED
@@ -1,19 +1,7 @@
1
- import { Sharp, Color, KernelEnum, SharpOptions } from 'sharp';
2
- import { IncomingMessage, ServerResponse } from 'node:http';
1
+ import { Color, KernelEnum, Sharp, SharpOptions } from 'sharp';
2
+ import * as h3 from 'h3';
3
+ import { Storage, Driver } from 'unstorage';
3
4
 
4
- interface ImageMeta {
5
- width: number;
6
- height: number;
7
- type: string;
8
- mimeType: string;
9
- }
10
- interface SourceData {
11
- mtime?: Date;
12
- maxAge?: number;
13
- getData: () => Promise<Buffer>;
14
- }
15
- type Source = (source: string, requestOptions?: any) => Promise<SourceData>;
16
- type SourceFactory<T = Record<string, any>> = (options: T) => Source;
17
5
  interface HandlerContext {
18
6
  quality?: number;
19
7
  fit?: "contain" | "cover" | "fill" | "inside" | "outside";
@@ -28,6 +16,23 @@ interface Handler {
28
16
  order?: number;
29
17
  apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
30
18
  }
19
+ type IPXStorageMeta = {
20
+ mtime?: Date | number | string;
21
+ maxAge?: number | string;
22
+ };
23
+ type IPXStorageOptions = Record<string, unknown>;
24
+ type MaybePromise<T> = T | Promise<T>;
25
+ interface IPXStorage {
26
+ name: string;
27
+ getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
28
+ getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
29
+ }
30
+ interface ImageMeta {
31
+ width: number;
32
+ height: number;
33
+ type: string;
34
+ mimeType: string;
35
+ }
31
36
 
32
37
  declare const quality: Handler;
33
38
  declare const fit: Handler;
@@ -102,43 +107,51 @@ declare namespace Handlers {
102
107
 
103
108
  type HandlerName = keyof typeof Handlers;
104
109
 
105
- interface IPXCTX {
106
- sources: Record<string, Source>;
107
- }
110
+ type IPXSourceMeta = {
111
+ mtime?: Date;
112
+ maxAge?: number;
113
+ };
108
114
  type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
109
- src: () => Promise<SourceData>;
110
- data: () => Promise<{
115
+ getSourceMeta: () => Promise<IPXSourceMeta>;
116
+ process: () => Promise<{
111
117
  data: Buffer;
112
118
  meta: ImageMeta;
113
119
  format: string;
114
120
  }>;
115
121
  };
116
- interface IPXOptions {
117
- dir?: false | string;
122
+ type IPXOptions = {
118
123
  maxAge?: number;
119
- domains?: false | string[];
120
- alias: Record<string, string>;
121
- fetchOptions: RequestInit;
122
- sharp?: SharpOptions;
123
- }
124
- declare function createIPX(userOptions: Partial<IPXOptions>): IPX;
124
+ alias?: Record<string, string>;
125
+ sharpOptions?: SharpOptions;
126
+ storage: IPXStorage;
127
+ httpStorage?: IPXStorage;
128
+ };
129
+ declare function createIPX(userOptions: IPXOptions): IPX;
125
130
 
126
- interface IPXHRequest {
127
- url: string;
128
- headers?: Record<string, string>;
129
- options?: any;
130
- }
131
- interface IPXHResponse {
132
- statusCode: number;
133
- statusMessage: string;
134
- headers: Record<string, string>;
135
- body: any;
136
- error?: any;
137
- }
138
- interface MiddlewareOptions {
139
- fallthrough?: boolean;
140
- }
141
- declare function handleRequest(request: IPXHRequest, ipx: IPX): Promise<IPXHResponse>;
142
- declare function createIPXMiddleware(ipx: IPX, options?: Partial<MiddlewareOptions>): (request: IncomingMessage, res: ServerResponse, next?: ((err?: any) => void) | undefined) => Promise<void>;
131
+ declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<Buffer | {
132
+ error: {
133
+ message: string;
134
+ };
135
+ } | null>>;
136
+ declare function createIPXH3App(ipx: IPX): h3.App;
137
+ declare function createIPXWebServer(ipx: IPX): h3.WebHandler;
138
+ declare function createIPXNodeServer(ipx: IPX): h3.NodeListener;
139
+ declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
140
+
141
+ type HTTPStorageOptions = {
142
+ fetchOptions?: RequestInit;
143
+ maxAge?: number;
144
+ domains?: string | string[];
145
+ allowAllDomains?: boolean;
146
+ };
147
+ declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
148
+
149
+ type NodeFSSOptions = {
150
+ dir?: string;
151
+ maxAge?: number;
152
+ };
153
+ declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
154
+
155
+ declare function unstorageToIPXStorage(storage: Storage | Driver, prefix: string): IPXStorage;
143
156
 
144
- export { type IPX, type IPXCTX, type IPXHRequest, type IPXHResponse, type IPXOptions, type MiddlewareOptions, type Source, type SourceData, type SourceFactory, createIPX, createIPXMiddleware, handleRequest };
157
+ export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type ImageMeta, type NodeFSSOptions, createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
package/dist/index.d.mts CHANGED
@@ -1,19 +1,7 @@
1
- import { Sharp, Color, KernelEnum, SharpOptions } from 'sharp';
2
- import { IncomingMessage, ServerResponse } from 'node:http';
1
+ import { Color, KernelEnum, Sharp, SharpOptions } from 'sharp';
2
+ import * as h3 from 'h3';
3
+ import { Storage, Driver } from 'unstorage';
3
4
 
4
- interface ImageMeta {
5
- width: number;
6
- height: number;
7
- type: string;
8
- mimeType: string;
9
- }
10
- interface SourceData {
11
- mtime?: Date;
12
- maxAge?: number;
13
- getData: () => Promise<Buffer>;
14
- }
15
- type Source = (source: string, requestOptions?: any) => Promise<SourceData>;
16
- type SourceFactory<T = Record<string, any>> = (options: T) => Source;
17
5
  interface HandlerContext {
18
6
  quality?: number;
19
7
  fit?: "contain" | "cover" | "fill" | "inside" | "outside";
@@ -28,6 +16,23 @@ interface Handler {
28
16
  order?: number;
29
17
  apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
30
18
  }
19
+ type IPXStorageMeta = {
20
+ mtime?: Date | number | string;
21
+ maxAge?: number | string;
22
+ };
23
+ type IPXStorageOptions = Record<string, unknown>;
24
+ type MaybePromise<T> = T | Promise<T>;
25
+ interface IPXStorage {
26
+ name: string;
27
+ getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
28
+ getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
29
+ }
30
+ interface ImageMeta {
31
+ width: number;
32
+ height: number;
33
+ type: string;
34
+ mimeType: string;
35
+ }
31
36
 
32
37
  declare const quality: Handler;
33
38
  declare const fit: Handler;
@@ -102,43 +107,51 @@ declare namespace Handlers {
102
107
 
103
108
  type HandlerName = keyof typeof Handlers;
104
109
 
105
- interface IPXCTX {
106
- sources: Record<string, Source>;
107
- }
110
+ type IPXSourceMeta = {
111
+ mtime?: Date;
112
+ maxAge?: number;
113
+ };
108
114
  type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
109
- src: () => Promise<SourceData>;
110
- data: () => Promise<{
115
+ getSourceMeta: () => Promise<IPXSourceMeta>;
116
+ process: () => Promise<{
111
117
  data: Buffer;
112
118
  meta: ImageMeta;
113
119
  format: string;
114
120
  }>;
115
121
  };
116
- interface IPXOptions {
117
- dir?: false | string;
122
+ type IPXOptions = {
118
123
  maxAge?: number;
119
- domains?: false | string[];
120
- alias: Record<string, string>;
121
- fetchOptions: RequestInit;
122
- sharp?: SharpOptions;
123
- }
124
- declare function createIPX(userOptions: Partial<IPXOptions>): IPX;
124
+ alias?: Record<string, string>;
125
+ sharpOptions?: SharpOptions;
126
+ storage: IPXStorage;
127
+ httpStorage?: IPXStorage;
128
+ };
129
+ declare function createIPX(userOptions: IPXOptions): IPX;
125
130
 
126
- interface IPXHRequest {
127
- url: string;
128
- headers?: Record<string, string>;
129
- options?: any;
130
- }
131
- interface IPXHResponse {
132
- statusCode: number;
133
- statusMessage: string;
134
- headers: Record<string, string>;
135
- body: any;
136
- error?: any;
137
- }
138
- interface MiddlewareOptions {
139
- fallthrough?: boolean;
140
- }
141
- declare function handleRequest(request: IPXHRequest, ipx: IPX): Promise<IPXHResponse>;
142
- declare function createIPXMiddleware(ipx: IPX, options?: Partial<MiddlewareOptions>): (request: IncomingMessage, res: ServerResponse, next?: ((err?: any) => void) | undefined) => Promise<void>;
131
+ declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<Buffer | {
132
+ error: {
133
+ message: string;
134
+ };
135
+ } | null>>;
136
+ declare function createIPXH3App(ipx: IPX): h3.App;
137
+ declare function createIPXWebServer(ipx: IPX): h3.WebHandler;
138
+ declare function createIPXNodeServer(ipx: IPX): h3.NodeListener;
139
+ declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
140
+
141
+ type HTTPStorageOptions = {
142
+ fetchOptions?: RequestInit;
143
+ maxAge?: number;
144
+ domains?: string | string[];
145
+ allowAllDomains?: boolean;
146
+ };
147
+ declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
148
+
149
+ type NodeFSSOptions = {
150
+ dir?: string;
151
+ maxAge?: number;
152
+ };
153
+ declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
154
+
155
+ declare function unstorageToIPXStorage(storage: Storage | Driver, prefix: string): IPXStorage;
143
156
 
144
- export { type IPX, type IPXCTX, type IPXHRequest, type IPXHResponse, type IPXOptions, type MiddlewareOptions, type Source, type SourceData, type SourceFactory, createIPX, createIPXMiddleware, handleRequest };
157
+ export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type ImageMeta, type NodeFSSOptions, createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };
package/dist/index.d.ts CHANGED
@@ -1,19 +1,7 @@
1
- import { Sharp, Color, KernelEnum, SharpOptions } from 'sharp';
2
- import { IncomingMessage, ServerResponse } from 'node:http';
1
+ import { Color, KernelEnum, Sharp, SharpOptions } from 'sharp';
2
+ import * as h3 from 'h3';
3
+ import { Storage, Driver } from 'unstorage';
3
4
 
4
- interface ImageMeta {
5
- width: number;
6
- height: number;
7
- type: string;
8
- mimeType: string;
9
- }
10
- interface SourceData {
11
- mtime?: Date;
12
- maxAge?: number;
13
- getData: () => Promise<Buffer>;
14
- }
15
- type Source = (source: string, requestOptions?: any) => Promise<SourceData>;
16
- type SourceFactory<T = Record<string, any>> = (options: T) => Source;
17
5
  interface HandlerContext {
18
6
  quality?: number;
19
7
  fit?: "contain" | "cover" | "fill" | "inside" | "outside";
@@ -28,6 +16,23 @@ interface Handler {
28
16
  order?: number;
29
17
  apply: (context: HandlerContext, pipe: Sharp, ...arguments_: any[]) => any;
30
18
  }
19
+ type IPXStorageMeta = {
20
+ mtime?: Date | number | string;
21
+ maxAge?: number | string;
22
+ };
23
+ type IPXStorageOptions = Record<string, unknown>;
24
+ type MaybePromise<T> = T | Promise<T>;
25
+ interface IPXStorage {
26
+ name: string;
27
+ getMeta: (id: string, opts?: IPXStorageOptions) => MaybePromise<IPXStorageMeta | undefined>;
28
+ getData: (id: string, opts?: IPXStorageOptions) => MaybePromise<ArrayBuffer | undefined>;
29
+ }
30
+ interface ImageMeta {
31
+ width: number;
32
+ height: number;
33
+ type: string;
34
+ mimeType: string;
35
+ }
31
36
 
32
37
  declare const quality: Handler;
33
38
  declare const fit: Handler;
@@ -102,43 +107,51 @@ declare namespace Handlers {
102
107
 
103
108
  type HandlerName = keyof typeof Handlers;
104
109
 
105
- interface IPXCTX {
106
- sources: Record<string, Source>;
107
- }
110
+ type IPXSourceMeta = {
111
+ mtime?: Date;
112
+ maxAge?: number;
113
+ };
108
114
  type IPX = (id: string, modifiers?: Partial<Record<HandlerName | "f" | "format" | "a" | "animated", string>>, requestOptions?: any) => {
109
- src: () => Promise<SourceData>;
110
- data: () => Promise<{
115
+ getSourceMeta: () => Promise<IPXSourceMeta>;
116
+ process: () => Promise<{
111
117
  data: Buffer;
112
118
  meta: ImageMeta;
113
119
  format: string;
114
120
  }>;
115
121
  };
116
- interface IPXOptions {
117
- dir?: false | string;
122
+ type IPXOptions = {
118
123
  maxAge?: number;
119
- domains?: false | string[];
120
- alias: Record<string, string>;
121
- fetchOptions: RequestInit;
122
- sharp?: SharpOptions;
123
- }
124
- declare function createIPX(userOptions: Partial<IPXOptions>): IPX;
124
+ alias?: Record<string, string>;
125
+ sharpOptions?: SharpOptions;
126
+ storage: IPXStorage;
127
+ httpStorage?: IPXStorage;
128
+ };
129
+ declare function createIPX(userOptions: IPXOptions): IPX;
125
130
 
126
- interface IPXHRequest {
127
- url: string;
128
- headers?: Record<string, string>;
129
- options?: any;
130
- }
131
- interface IPXHResponse {
132
- statusCode: number;
133
- statusMessage: string;
134
- headers: Record<string, string>;
135
- body: any;
136
- error?: any;
137
- }
138
- interface MiddlewareOptions {
139
- fallthrough?: boolean;
140
- }
141
- declare function handleRequest(request: IPXHRequest, ipx: IPX): Promise<IPXHResponse>;
142
- declare function createIPXMiddleware(ipx: IPX, options?: Partial<MiddlewareOptions>): (request: IncomingMessage, res: ServerResponse, next?: ((err?: any) => void) | undefined) => Promise<void>;
131
+ declare function createIPXH3Handler(ipx: IPX): h3.EventHandler<h3.EventHandlerRequest, Promise<Buffer | {
132
+ error: {
133
+ message: string;
134
+ };
135
+ } | null>>;
136
+ declare function createIPXH3App(ipx: IPX): h3.App;
137
+ declare function createIPXWebServer(ipx: IPX): h3.WebHandler;
138
+ declare function createIPXNodeServer(ipx: IPX): h3.NodeListener;
139
+ declare function createIPXPlainServer(ipx: IPX): h3.PlainHandler;
140
+
141
+ type HTTPStorageOptions = {
142
+ fetchOptions?: RequestInit;
143
+ maxAge?: number;
144
+ domains?: string | string[];
145
+ allowAllDomains?: boolean;
146
+ };
147
+ declare function ipxHttpStorage(_options?: HTTPStorageOptions): IPXStorage;
148
+
149
+ type NodeFSSOptions = {
150
+ dir?: string;
151
+ maxAge?: number;
152
+ };
153
+ declare function ipxFSStorage(_options?: NodeFSSOptions): IPXStorage;
154
+
155
+ declare function unstorageToIPXStorage(storage: Storage | Driver, prefix: string): IPXStorage;
143
156
 
144
- export { type IPX, type IPXCTX, type IPXHRequest, type IPXHResponse, type IPXOptions, type MiddlewareOptions, type Source, type SourceData, type SourceFactory, createIPX, createIPXMiddleware, handleRequest };
157
+ export { type HTTPStorageOptions, type Handler, type HandlerContext, type IPX, type IPXOptions, type IPXStorage, type IPXStorageMeta, type IPXStorageOptions, type ImageMeta, type NodeFSSOptions, createIPX, createIPXH3App, createIPXH3Handler, createIPXNodeServer, createIPXPlainServer, createIPXWebServer, ipxFSStorage, ipxHttpStorage, unstorageToIPXStorage };