ipx 4.0.0-alpha.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.
@@ -1 +1,25 @@
1
- import{r as __require,t as __commonJSMin}from"../rolldown-runtime.mjs";var require_etag=__commonJSMin(((t,n)=>{n.exports=s;var r=__require(`crypto`),i=__require(`fs`).Stats,a=Object.prototype.toString;function o(e){if(e.length===0)return`"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"`;var t=r.createHash(`sha1`).update(e,`utf8`).digest(`base64`).substring(0,27);return`"`+(typeof e==`string`?Buffer.byteLength(e,`utf8`):e.length).toString(16)+`-`+t+`"`}function s(e,t){if(e==null)throw TypeError(`argument entity is required`);var n=c(e),r=t&&typeof t.weak==`boolean`?t.weak:n;if(!n&&typeof e!=`string`&&!Buffer.isBuffer(e))throw TypeError(`argument entity must be string, Buffer, or fs.Stats`);var i=n?l(e):o(e);return r?`W/`+i:i}function c(e){return typeof i==`function`&&e instanceof i?!0:e&&typeof e==`object`&&`ctime`in e&&a.call(e.ctime)===`[object Date]`&&`mtime`in e&&a.call(e.mtime)===`[object Date]`&&`ino`in e&&typeof e.ino==`number`&&`size`in e&&typeof e.size==`number`}function l(e){var t=e.mtime.getTime().toString(16);return`"`+e.size.toString(16)+`-`+t+`"`}}));export{require_etag as t};
1
+ import { __commonJSMin as e, __require as t } from "../rolldown-runtime.mjs";
2
+ var n = e(((e, n) => {
3
+ n.exports = s;
4
+ var r = t(`crypto`), i = t(`fs`).Stats, a = Object.prototype.toString;
5
+ function o(e) {
6
+ if (e.length === 0) return `"0-2jmj7l5rSw0yVb/vlWAYkK/YBwk"`;
7
+ var t = r.createHash(`sha1`).update(e, `utf8`).digest(`base64`).substring(0, 27);
8
+ return `"` + (typeof e == `string` ? Buffer.byteLength(e, `utf8`) : e.length).toString(16) + `-` + t + `"`;
9
+ }
10
+ function s(e, t) {
11
+ if (e == null) throw TypeError(`argument entity is required`);
12
+ var n = c(e), r = t && typeof t.weak == `boolean` ? t.weak : n;
13
+ if (!n && typeof e != `string` && !Buffer.isBuffer(e)) throw TypeError(`argument entity must be string, Buffer, or fs.Stats`);
14
+ var i = n ? l(e) : o(e);
15
+ return r ? `W/` + i : i;
16
+ }
17
+ function c(e) {
18
+ return typeof i == `function` && e instanceof i ? !0 : e && typeof e == `object` && `ctime` in e && a.call(e.ctime) === `[object Date]` && `mtime` in e && a.call(e.mtime) === `[object Date]` && `ino` in e && typeof e.ino == `number` && `size` in e && typeof e.size == `number`;
19
+ }
20
+ function l(e) {
21
+ var t = e.mtime.getTime().toString(16);
22
+ return `"` + e.size.toString(16) + `-` + t + `"`;
23
+ }
24
+ }));
25
+ export { n as require_etag };
@@ -1,2 +1,267 @@
1
- import{FastResponse,FastURL}from"srvx";const NullProtoObj=(()=>{let e=function(){};return e.prototype=Object.create(null),Object.freeze(e.prototype),e})(),kEventNS=`h3.internal.event.`,kEventRes=Symbol.for(`${kEventNS}res`),kEventResHeaders=Symbol.for(`${kEventNS}res.headers`);var H3Event=class{app;req;url;context;static __is_event__=!0;constructor(e,E,D){this.context=E||e.context||new NullProtoObj,this.req=e,this.app=D;let O=e._url;this.url=O&&O instanceof URL?O:new FastURL(e.url)}get res(){return this[kEventRes]||=new H3EventResponse}get runtime(){return this.req.runtime}waitUntil(e){this.req.waitUntil?.(e)}toString(){return`[${this.req.method}] ${this.req.url}`}toJSON(){return this.toString()}get node(){return this.req.runtime?.node}get headers(){return this.req.headers}get path(){return this.url.pathname+this.url.search}get method(){return this.req.method}},H3EventResponse=class{status;statusText;get headers(){return this[kEventResHeaders]||=new Headers}};const DISALLOWED_STATUS_CHARS=/[^\u0009\u0020-\u007E]/g;function sanitizeStatusMessage(e=``){return e.replace(DISALLOWED_STATUS_CHARS,``)}function sanitizeStatusCode(e,w=200){return!e||(typeof e==`string`&&(e=+e),e<100||e>599)?w:e}var HTTPError=class e extends Error{get name(){return`HTTPError`}status;statusText;headers;cause;data;body;unhandled;static isError(e){return e instanceof Error&&e?.name===`HTTPError`}static status(w,T,E){return new e({...E,statusText:T,status:w})}constructor(e,w){let T,E;typeof e==`string`?(T=e,E=w):E=e;let D=sanitizeStatusCode(E?.status||E?.cause?.status||E?.status||E?.statusCode,500),O=sanitizeStatusMessage(E?.statusText||E?.cause?.statusText||E?.statusText||E?.statusMessage),k=T||E?.message||E?.cause?.message||E?.statusText||E?.statusMessage||[`HTTPError`,D,O].filter(Boolean).join(` `);super(k,{cause:E}),this.cause=E,Error.captureStackTrace?.(this,this.constructor),this.status=D,this.statusText=O||void 0;let A=E?.headers||E?.cause?.headers;this.headers=A?new Headers(A):void 0,this.unhandled=E?.unhandled??E?.cause?.unhandled??void 0,this.data=E?.data,this.body=E?.body}get statusCode(){return this.status}get statusMessage(){return this.statusText}toJSON(){let e=this.unhandled;return{status:this.status,statusText:this.statusText,unhandled:e,message:e?`HTTPError`:this.message,data:e?void 0:this.data,...e?void 0:this.body}}};function isJSONSerializable(e,w){if(e==null)return!0;if(w!==`object`)return w===`boolean`||w===`number`||w===`string`;if(typeof e.toJSON==`function`||Array.isArray(e))return!0;if(typeof e.pipe==`function`||typeof e.pipeTo==`function`)return!1;if(e instanceof NullProtoObj)return!0;let E=Object.getPrototypeOf(e);return E===Object.prototype||E===null}const kNotFound=Symbol.for(`h3.notFound`),kHandled=Symbol.for(`h3.handled`);function toResponse(e,w,T={}){if(typeof e?.then==`function`)return(e.catch?.(e=>e)||Promise.resolve(e)).then(e=>toResponse(e,w,T));let E=prepareResponse(e,w,T);if(typeof E?.then==`function`)return toResponse(E,w,T);let{onResponse:D}=T;return D?Promise.resolve(D(E,w)).then(()=>E):E}var HTTPResponse=class{#headers;#init;body;constructor(e,w){this.body=e,this.#init=w}get status(){return this.#init?.status||200}get statusText(){return this.#init?.statusText||`OK`}get headers(){return this.#headers||=new Headers(this.#init?.headers)}};function prepareResponse(w,T,E,k){if(w===kHandled)return new FastResponse(null);if(w===kNotFound&&(w=new HTTPError({status:404,message:`Cannot find any route matching [${T.req.method}] ${T.url}`})),w&&w instanceof Error){let e=HTTPError.isError(w),D=e?w:new HTTPError(w);e||(D.unhandled=!0,w?.stack&&(D.stack=w.stack)),D.unhandled&&!E.silent&&console.error(D);let{onError:O}=E;return O&&!k?Promise.resolve(O(D,T)).catch(e=>e).then(e=>prepareResponse(e??w,T,E,!0)):errorResponse(D,E.debug)}let A=T[kEventRes],j=A?.[kEventResHeaders];if(!(w instanceof Response)){let D=prepareResponseBody(w,T,E),O=D.status||A?.status;return new FastResponse(nullBody(T.req.method,O)?null:D.body,{status:O,statusText:D.statusText||A?.statusText,headers:D.headers&&j?mergeHeaders$1(D.headers,j):D.headers||j})}if(!j||k||!w.ok)return w;try{return mergeHeaders$1(w.headers,j,w.headers),w}catch{return new FastResponse(nullBody(T.req.method,w.status)?null:w.body,{status:w.status,statusText:w.statusText,headers:mergeHeaders$1(w.headers,j)})}}function mergeHeaders$1(e,w,T=new Headers(e)){for(let[e,E]of w)e===`set-cookie`?T.append(e,E):T.set(e,E);return T}const frozenHeaders=()=>{throw Error(`Headers are frozen`)};var FrozenHeaders=class extends Headers{constructor(e){super(e),this.set=this.append=this.delete=frozenHeaders}};const emptyHeaders=new FrozenHeaders({"content-length":`0`}),jsonHeaders=new FrozenHeaders({"content-type":`application/json;charset=UTF-8`});function prepareResponseBody(e,w,T){if(e==null)return{body:``,headers:emptyHeaders};let E=typeof e;if(E===`string`)return{body:e};if(e instanceof Uint8Array)return w.res.headers.set(`content-length`,e.byteLength.toString()),{body:e};if(e instanceof HTTPResponse||e?.constructor?.name===`HTTPResponse`)return e;if(isJSONSerializable(e,E))return{body:JSON.stringify(e,void 0,T.debug?2:void 0),headers:jsonHeaders};if(E===`bigint`)return{body:e.toString(),headers:jsonHeaders};if(e instanceof Blob){let w=new Headers({"content-type":e.type,"content-length":e.size.toString()}),T=e.name;return T&&(T=encodeURIComponent(T),w.set(`content-disposition`,`filename="${T}"; filename*=UTF-8''${T}`)),{body:e.stream(),headers:w}}return E===`symbol`?{body:e.toString()}:E===`function`?{body:`${e.name}()`}:{body:e}}function nullBody(e,w){return e===`HEAD`||w===100||w===101||w===102||w===204||w===205||w===304}function errorResponse(w,T){return new FastResponse(JSON.stringify({...w.toJSON(),stack:T&&w.stack?w.stack.split(`
2
- `).map(e=>e.trim()):void 0},void 0,T?2:void 0),{status:w.status,statusText:w.statusText,headers:w.headers?mergeHeaders$1(jsonHeaders,w.headers):new Headers(jsonHeaders)})}function callMiddleware(e,w,T,E=0){if(E===w.length)return T(e);let D=w[E],O,k,A=()=>O?k:(O=!0,k=callMiddleware(e,w,T,E+1),k),j=D(e,A);return isUnhandledResponse(j)?A():typeof j?.then==`function`?j.then(e=>isUnhandledResponse(e)?A():e):j}function isUnhandledResponse(e){return e===void 0||e===kNotFound}function defineHandler(e){if(typeof e==`function`)return handlerWithFetch(e);let w=e.handler||(e.fetch?function(w){return e.fetch(w.req)}:NoHandler);return Object.assign(handlerWithFetch(e.middleware?.length?function(T){return callMiddleware(T,e.middleware,w)}:w),e)}function handlerWithFetch(e){return`fetch`in e?e:Object.assign(e,{fetch:w=>{typeof w==`string`&&(w=new URL(w,`http://_`)),w instanceof URL&&(w=new Request(w));let T=new H3Event(w);try{return Promise.resolve(toResponse(e(T),T))}catch(e){return Promise.resolve(toResponse(e,T))}}})}const NoHandler=()=>kNotFound,defineEventHandler=defineHandler;export{defineEventHandler as n,HTTPError as t};
1
+ import { FastResponse as e, FastURL as t } from "srvx";
2
+ const n = (() => {
3
+ let e = function() {};
4
+ return e.prototype = Object.create(null), Object.freeze(e.prototype), e;
5
+ })();
6
+ function r(e) {
7
+ return decodeURI(e.includes(`%25`) ? e.replace(/%25/g, `%2525`) : e);
8
+ }
9
+ const i = `h3.internal.event.`, a = Symbol.for(`${i}res`), o = Symbol.for(`${i}res.headers`), s = Symbol.for(`${i}res.err.headers`);
10
+ var c = class {
11
+ app;
12
+ req;
13
+ url;
14
+ context;
15
+ static __is_event__ = !0;
16
+ constructor(e, i, a) {
17
+ this.context = i || e.context || new n(), this.req = e, this.app = a;
18
+ let o = e._url, s = o && o instanceof URL ? o : new t(e.url);
19
+ s.pathname.includes(`%`) && (s.pathname = r(s.pathname)), this.url = s;
20
+ }
21
+ get res() {
22
+ return this[a] ||= new l();
23
+ }
24
+ get runtime() {
25
+ return this.req.runtime;
26
+ }
27
+ waitUntil(e) {
28
+ this.req.waitUntil?.(e);
29
+ }
30
+ toString() {
31
+ return `[${this.req.method}] ${this.req.url}`;
32
+ }
33
+ toJSON() {
34
+ return this.toString();
35
+ }
36
+ get node() {
37
+ return this.req.runtime?.node;
38
+ }
39
+ get headers() {
40
+ return this.req.headers;
41
+ }
42
+ get path() {
43
+ return this.url.pathname + this.url.search;
44
+ }
45
+ get method() {
46
+ return this.req.method;
47
+ }
48
+ }, l = class {
49
+ status;
50
+ statusText;
51
+ get headers() {
52
+ return this[o] ||= new Headers();
53
+ }
54
+ get errHeaders() {
55
+ return this[s] ||= new Headers();
56
+ }
57
+ };
58
+ const u = /[^\u0009\u0020-\u007E]/g;
59
+ function d(e = ``) {
60
+ return e.replace(u, ``);
61
+ }
62
+ function f(e, t = 200) {
63
+ return !e || (typeof e == `string` && (e = +e), e < 100 || e > 599) ? t : e;
64
+ }
65
+ var p = class e extends Error {
66
+ get name() {
67
+ return `HTTPError`;
68
+ }
69
+ status;
70
+ statusText;
71
+ headers;
72
+ cause;
73
+ data;
74
+ body;
75
+ unhandled;
76
+ static isError(e) {
77
+ return e instanceof Error && e?.name === `HTTPError`;
78
+ }
79
+ static status(t, n, r) {
80
+ return new e({
81
+ ...r,
82
+ statusText: n,
83
+ status: t
84
+ });
85
+ }
86
+ constructor(e, t) {
87
+ let n, r;
88
+ typeof e == `string` ? (n = e, r = t) : r = e;
89
+ let i = f(r?.status || r?.statusCode || r?.cause?.status || r?.cause?.statusCode, 500), a = d(r?.statusText || r?.statusMessage || r?.cause?.statusText || r?.cause?.statusMessage), o = n || r?.message || r?.cause?.message || r?.statusText || r?.statusMessage || [
90
+ `HTTPError`,
91
+ i,
92
+ a
93
+ ].filter(Boolean).join(` `);
94
+ super(o, { cause: r }), this.cause = r, this.status = i, this.statusText = a || void 0;
95
+ let s = r?.headers || r?.cause?.headers;
96
+ this.headers = s ? new Headers(s) : void 0, this.unhandled = r?.unhandled ?? r?.cause?.unhandled ?? void 0, this.data = r?.data, this.body = r?.body;
97
+ }
98
+ get statusCode() {
99
+ return this.status;
100
+ }
101
+ get statusMessage() {
102
+ return this.statusText;
103
+ }
104
+ toJSON() {
105
+ let e = this.unhandled;
106
+ return {
107
+ status: this.status,
108
+ statusText: this.statusText,
109
+ unhandled: e,
110
+ message: e ? `HTTPError` : this.message,
111
+ data: e ? void 0 : this.data,
112
+ ...e ? void 0 : this.body
113
+ };
114
+ }
115
+ };
116
+ function m(e, t) {
117
+ if (e == null) return !0;
118
+ if (t !== `object`) return t === `boolean` || t === `number` || t === `string`;
119
+ if (typeof e.toJSON == `function` || Array.isArray(e)) return !0;
120
+ if (typeof e.pipe == `function` || typeof e.pipeTo == `function`) return !1;
121
+ if (e instanceof n) return !0;
122
+ let r = Object.getPrototypeOf(e);
123
+ return r === Object.prototype || r === null;
124
+ }
125
+ const h = Symbol.for(`h3.notFound`), g = Symbol.for(`h3.handled`);
126
+ function _(e, t, n = {}) {
127
+ if (typeof e?.then == `function`) return e.then((e) => _(e, t, n), (e) => _(typeof e == `number` ? new p({ status: e }) : e, t, n));
128
+ let r = y(e, t, n);
129
+ if (typeof r?.then == `function`) return _(r, t, n);
130
+ let { onResponse: i } = n;
131
+ return i ? Promise.resolve(i(r, t)).then(() => r) : r;
132
+ }
133
+ var v = class {
134
+ #headers;
135
+ #init;
136
+ body;
137
+ constructor(e, t) {
138
+ this.body = e, this.#init = t;
139
+ }
140
+ get status() {
141
+ return this.#init?.status || 200;
142
+ }
143
+ get statusText() {
144
+ return this.#init?.statusText || `OK`;
145
+ }
146
+ get headers() {
147
+ return this.#headers ||= new Headers(this.#init?.headers);
148
+ }
149
+ };
150
+ function y(t, n, r, i) {
151
+ if (t === g) return new e(null);
152
+ if (t === h && (t = new p({
153
+ status: 404,
154
+ message: `Cannot find any route matching [${n.req.method}] ${n.url}`
155
+ })), t && t instanceof Error) {
156
+ let e = p.isError(t), o = e ? t : new p(t);
157
+ e || (o.unhandled = !0, t?.stack && (o.stack = t.stack)), o.unhandled && !r.silent && console.error(o);
158
+ let { onError: c } = r, l = n[a]?.[s];
159
+ return c && !i ? Promise.resolve(c(o, n)).catch((e) => e).then((e) => y(e ?? t, n, r, !0)) : D(o, r.debug, l);
160
+ }
161
+ let c = n[a], l = c?.[o];
162
+ if (n[a] = void 0, !(t instanceof Response)) {
163
+ let i = T(t, n, r), a = i.status || c?.status;
164
+ return new e(E(n.req.method, a) ? null : i.body, {
165
+ status: a,
166
+ statusText: i.statusText || c?.statusText,
167
+ headers: i.headers && l ? b(i.headers, l) : i.headers || l
168
+ });
169
+ }
170
+ if (!l || i || !t.ok) return t;
171
+ try {
172
+ return b(t.headers, l, t.headers), t;
173
+ } catch {
174
+ return new e(E(n.req.method, t.status) ? null : t.body, {
175
+ status: t.status,
176
+ statusText: t.statusText,
177
+ headers: b(t.headers, l)
178
+ });
179
+ }
180
+ }
181
+ function b(e, t, n = new Headers(e)) {
182
+ for (let [e, r] of t) e === `set-cookie` ? n.append(e, r) : n.set(e, r);
183
+ return n;
184
+ }
185
+ const x = (e) => (...t) => {
186
+ throw Error(`Headers are frozen (${e} ${t.join(`, `)})`);
187
+ };
188
+ var S = class extends Headers {
189
+ set = x(`set`);
190
+ append = x(`append`);
191
+ delete = x(`delete`);
192
+ };
193
+ const C = new S({ "content-length": `0` }), w = new S({ "content-type": `application/json;charset=UTF-8` });
194
+ function T(e, t, n) {
195
+ if (e == null) return {
196
+ body: ``,
197
+ headers: C
198
+ };
199
+ let r = typeof e;
200
+ if (r === `string`) return { body: e };
201
+ if (e instanceof Uint8Array) return t.res.headers.set(`content-length`, e.byteLength.toString()), { body: e };
202
+ if (e instanceof v || e?.constructor?.name === `HTTPResponse`) return e;
203
+ if (m(e, r)) return {
204
+ body: JSON.stringify(e, void 0, n.debug ? 2 : void 0),
205
+ headers: w
206
+ };
207
+ if (r === `bigint`) return {
208
+ body: e.toString(),
209
+ headers: w
210
+ };
211
+ if (e instanceof Blob) {
212
+ let t = new Headers({
213
+ "content-type": e.type,
214
+ "content-length": e.size.toString()
215
+ }), n = e.name;
216
+ return n && (n = encodeURIComponent(n), t.set(`content-disposition`, `filename="${n}"; filename*=UTF-8''${n}`)), {
217
+ body: e.stream(),
218
+ headers: t
219
+ };
220
+ }
221
+ return r === `symbol` ? { body: e.toString() } : r === `function` ? { body: `${e.name}()` } : { body: e };
222
+ }
223
+ function E(e, t) {
224
+ return e === `HEAD` || t === 100 || t === 101 || t === 102 || t === 204 || t === 205 || t === 304;
225
+ }
226
+ function D(t, n, r) {
227
+ let i = t.headers ? b(w, t.headers) : new Headers(w);
228
+ return r && (i = b(i, r)), new e(JSON.stringify({
229
+ ...t.toJSON(),
230
+ stack: n && t.stack ? t.stack.split(`
231
+ `).map((e) => e.trim()) : void 0
232
+ }, void 0, n ? 2 : void 0), {
233
+ status: t.status,
234
+ statusText: t.statusText,
235
+ headers: i
236
+ });
237
+ }
238
+ function O(e, t, n, r = 0) {
239
+ if (r === t.length) return n(e);
240
+ let i = t[r], a, o, s = () => a ? o : (a = !0, o = O(e, t, n, r + 1), o), c = i(e, s);
241
+ return k(c) ? s() : typeof c?.then == `function` ? c.then((e) => k(e) ? s() : e) : c;
242
+ }
243
+ function k(e) {
244
+ return e === void 0 || e === h;
245
+ }
246
+ function A(e) {
247
+ if (typeof e == `function`) return j(e);
248
+ let t = e.handler || (e.fetch ? function(t) {
249
+ return e.fetch(t.req);
250
+ } : M);
251
+ return Object.assign(j(e.middleware?.length ? function(n) {
252
+ return O(n, e.middleware, t);
253
+ } : t), e);
254
+ }
255
+ function j(e) {
256
+ return `fetch` in e ? e : Object.assign(e, { fetch: (t) => {
257
+ typeof t == `string` && (t = new URL(t, `http://_`)), t instanceof URL && (t = new Request(t));
258
+ let n = new c(t);
259
+ try {
260
+ return Promise.resolve(_(e(n), n));
261
+ } catch (e) {
262
+ return Promise.resolve(_(e, n));
263
+ }
264
+ } });
265
+ }
266
+ const M = () => h, N = A;
267
+ export { p as HTTPError, N as defineEventHandler };
@@ -0,0 +1,12 @@
1
+ type e = {
2
+ images?: Omit<e, "images">[];
3
+ width: number | undefined;
4
+ height: number | undefined;
5
+ orientation?: number;
6
+ type?: string;
7
+ };
8
+ /**
9
+ * @param {Uint8Array|string} input - Uint8Array or relative/absolute path of the image file
10
+ * @param {Function=} [callback] - optional function for async detection
11
+ */
12
+ export type { e as ImageMeta };