ipx 4.0.0-alpha.2 → 4.0.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.
@@ -2,24 +2,34 @@ import { FastResponse as e, FastURL as t } from "srvx";
2
2
  const n = (() => {
3
3
  let e = function() {};
4
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);
5
+ })(), r = String.raw`%(?:2[146-9A-E]|3[0-9ABD]|4[0-9A-F]|5[0-9ABDF]|6[1-9A-F]|7[0-9ACE])`, i = new RegExp(r, `i`), a = new RegExp(r, `gi`);
6
+ function o(e) {
7
+ return i.test(e);
8
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 {
9
+ function s(e) {
10
+ return e.replace(a, (e) => String.fromCharCode(Number.parseInt(e.slice(1), 16)));
11
+ }
12
+ function c(e) {
13
+ try {
14
+ return decodeURI(e);
15
+ } catch {
16
+ return;
17
+ }
18
+ }
19
+ const l = `h3.internal.event.`, u = Symbol.for(`${l}res`), d = Symbol.for(`${l}res.headers`), f = Symbol.for(`${l}res.err.headers`), p = Symbol.for(`${l}malformed`);
20
+ var m = class {
11
21
  app;
12
22
  req;
13
23
  url;
14
24
  context;
15
25
  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;
26
+ constructor(e, r, i) {
27
+ this.context = e.context = r || e.context || new n(), this.req = e, this.app = i;
28
+ let a = e._url, l = a && a instanceof URL ? a : new t(e.url), u = l.pathname;
29
+ u.includes(`%`) && (c(u) === void 0 ? this[p] = !0 : o(u) && (l = new t(`${l.protocol}//${l.host}${s(u)}${l.search}`))), this.url = l;
20
30
  }
21
31
  get res() {
22
- return this[a] ||= new l();
32
+ return this[u] ||= new h();
23
33
  }
24
34
  get runtime() {
25
35
  return this.req.runtime;
@@ -45,24 +55,24 @@ var c = class {
45
55
  get method() {
46
56
  return this.req.method;
47
57
  }
48
- }, l = class {
58
+ }, h = class {
49
59
  status;
50
60
  statusText;
51
61
  get headers() {
52
- return this[o] ||= new Headers();
62
+ return this[d] ||= new Headers();
53
63
  }
54
64
  get errHeaders() {
55
- return this[s] ||= new Headers();
65
+ return this[f] ||= new Headers();
56
66
  }
57
67
  };
58
- const u = /[^\u0009\u0020-\u007E]/g;
59
- function d(e = ``) {
60
- return e.replace(u, ``);
68
+ const g = /[^\u0009\u0020-\u007E]/g;
69
+ function _(e = ``) {
70
+ return e.replace(g, ``);
61
71
  }
62
- function f(e, t = 200) {
63
- return !e || (typeof e == `string` && (e = +e), e < 100 || e > 599) ? t : e;
72
+ function v(e, t = 200) {
73
+ return !e || (typeof e == `string` && (e = +e), !Number.isInteger(e) || e < 100 || e > 599) ? t : e;
64
74
  }
65
- var p = class e extends Error {
75
+ var y = class e extends Error {
66
76
  get name() {
67
77
  return `HTTPError`;
68
78
  }
@@ -74,7 +84,7 @@ var p = class e extends Error {
74
84
  body;
75
85
  unhandled;
76
86
  static isError(e) {
77
- return e instanceof Error && e?.name === `HTTPError`;
87
+ return e instanceof Error && e?.name === `HTTPError` && e.status > 99;
78
88
  }
79
89
  static status(t, n, r) {
80
90
  return new e({
@@ -86,7 +96,7 @@ var p = class e extends Error {
86
96
  constructor(e, t) {
87
97
  let n, r;
88
98
  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 || [
99
+ let i = v(r?.status || r?.statusCode || r?.cause?.status || r?.cause?.statusCode, 500), a = _(r?.statusText || r?.statusMessage || r?.cause?.statusText || r?.cause?.statusMessage), o = n || r?.message || r?.cause?.message || r?.statusText || r?.statusMessage || [
90
100
  `HTTPError`,
91
101
  i,
92
102
  a
@@ -113,7 +123,7 @@ var p = class e extends Error {
113
123
  };
114
124
  }
115
125
  };
116
- function m(e, t) {
126
+ function b(e, t) {
117
127
  if (e == null) return !0;
118
128
  if (t !== `object`) return t === `boolean` || t === `number` || t === `string`;
119
129
  if (typeof e.toJSON == `function` || Array.isArray(e)) return !0;
@@ -122,91 +132,111 @@ function m(e, t) {
122
132
  let r = Object.getPrototypeOf(e);
123
133
  return r === Object.prototype || r === null;
124
134
  }
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);
135
+ const x = Symbol.for(`h3.internal.event.dispose`), S = Symbol.for(`h3.notFound`), C = Symbol.for(`h3.handled`);
136
+ function w(e, t, n = {}) {
137
+ if (typeof e?.then == `function`) return e.then((e) => w(e, t, n), (e) => w(T(e), t, n));
138
+ let r;
139
+ try {
140
+ r = O(e, t, n);
141
+ } catch (e) {
142
+ return w(T(e), t, n);
143
+ }
144
+ if (typeof r?.then == `function`) return w(r, t, n);
130
145
  let { onResponse: i } = n;
131
- return i ? Promise.resolve(i(r, t)).then(() => r) : r;
146
+ return i ? Promise.resolve().then(() => i(r, t)).catch((e) => {
147
+ n.silent || console.error(e);
148
+ }).then(() => t[x]?.observe(r, e) ?? r) : t[x]?.observe(r, e) ?? r;
149
+ }
150
+ function T(e) {
151
+ if (e === S || e === C || e instanceof Error) return e;
152
+ if (typeof e == `number`) return new y({ status: e });
153
+ let t = new y({
154
+ status: 500,
155
+ unhandled: !0
156
+ });
157
+ return t.cause = e, t;
132
158
  }
133
- var v = class {
134
- #headers;
135
- #init;
159
+ const E = Symbol.for(`h3.HTTPResponse`);
160
+ var D = class {
161
+ #e;
162
+ #t;
136
163
  body;
137
164
  constructor(e, t) {
138
- this.body = e, this.#init = t;
165
+ this.body = e, this.#t = t;
139
166
  }
140
167
  get status() {
141
- return this.#init?.status || 200;
168
+ return this.#t?.status;
142
169
  }
143
170
  get statusText() {
144
- return this.#init?.statusText || `OK`;
171
+ return this.#t?.statusText;
145
172
  }
146
173
  get headers() {
147
- return this.#headers ||= new Headers(this.#init?.headers);
174
+ return this.#e ||= new Headers(this.#t?.headers);
148
175
  }
149
176
  };
150
- function y(t, n, r, i) {
151
- if (t === g) return new e(null);
152
- if (t === h && (t = new p({
177
+ D.prototype[E] = !0;
178
+ function O(t, n, r, i) {
179
+ if (t === C) return new e(null);
180
+ if (t === S && (t = new y({
153
181
  status: 404,
154
182
  message: `Cannot find any route matching [${n.req.method}] ${n.url}`
155
183
  })), 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
- });
184
+ let e = y.isError(t), a = e ? t : new y(t);
185
+ e || (a.unhandled = !0, t?.stack && (a.stack = t.stack)), a.unhandled && !r.silent && console.error(a);
186
+ let { onError: o } = r, s = n[u]?.[f];
187
+ return o && !i ? Promise.resolve().then(() => o(a, n)).catch(T).then((e) => O(e ?? t, n, r, !0)) : (n[u] = void 0, I(a, r.debug, s));
169
188
  }
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)
189
+ let a = n[u], o = a?.[d];
190
+ if (n[u] = void 0, !(t instanceof Response)) {
191
+ let i = P(t, n, r), s = i.status || a?.status, c = s ? v(s) : void 0, l = i.statusText || a?.statusText;
192
+ return new e(F(n.req.method, c) ? null : i.body, {
193
+ status: c,
194
+ statusText: l === void 0 ? void 0 : _(l),
195
+ headers: i.headers && o ? k(i.headers, o) : i.headers || o
178
196
  });
179
197
  }
198
+ return t.status >= 400 && (o = a?.[f]), o && !i && !o.keys().next().done ? new e(F(n.req.method, t.status) ? null : t.body, {
199
+ status: t.status,
200
+ statusText: t.statusText,
201
+ headers: k(t.headers, o)
202
+ }) : n.req.method === `HEAD` && t.body !== null ? new e(null, {
203
+ status: t.status,
204
+ statusText: t.statusText,
205
+ headers: t.headers
206
+ }) : t;
180
207
  }
181
- function b(e, t, n = new Headers(e)) {
208
+ function k(e, t, n = new Headers(e)) {
182
209
  for (let [e, r] of t) e === `set-cookie` ? n.append(e, r) : n.set(e, r);
183
210
  return n;
184
211
  }
185
- const x = (e) => (...t) => {
212
+ const A = (e) => (...t) => {
186
213
  throw Error(`Headers are frozen (${e} ${t.join(`, `)})`);
187
214
  };
188
- var S = class extends Headers {
189
- set = x(`set`);
190
- append = x(`append`);
191
- delete = x(`delete`);
215
+ var j = class extends Headers {
216
+ set = A(`set`);
217
+ append = A(`append`);
218
+ delete = A(`delete`);
192
219
  };
193
- const C = new S({ "content-length": `0` }), w = new S({ "content-type": `application/json;charset=UTF-8` });
194
- function T(e, t, n) {
220
+ const M = new j({ "content-length": `0` }), N = new j({ "content-type": `application/json;charset=UTF-8` });
221
+ function P(e, t, n) {
195
222
  if (e == null) return {
196
223
  body: ``,
197
- headers: C
224
+ headers: M
198
225
  };
199
226
  let r = typeof e;
200
227
  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 {
228
+ if (e instanceof Uint8Array) return {
229
+ body: e,
230
+ headers: new Headers({ "content-length": e.byteLength.toString() })
231
+ };
232
+ if (e instanceof D || e?.[E] === !0) return e;
233
+ if (b(e, r)) return {
204
234
  body: JSON.stringify(e, void 0, n.debug ? 2 : void 0),
205
- headers: w
235
+ headers: N
206
236
  };
207
237
  if (r === `bigint`) return {
208
238
  body: e.toString(),
209
- headers: w
239
+ headers: N
210
240
  };
211
241
  if (e instanceof Blob) {
212
242
  let t = new Headers({
@@ -220,12 +250,12 @@ function T(e, t, n) {
220
250
  }
221
251
  return r === `symbol` ? { body: e.toString() } : r === `function` ? { body: `${e.name}()` } : { body: e };
222
252
  }
223
- function E(e, t) {
253
+ function F(e, t) {
224
254
  return e === `HEAD` || t === 100 || t === 101 || t === 102 || t === 204 || t === 205 || t === 304;
225
255
  }
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({
256
+ function I(t, n, r) {
257
+ let i = t.headers ? k(N, t.headers) : new Headers(N);
258
+ return r && (i = k(i, r)), new e(JSON.stringify({
229
259
  ...t.toJSON(),
230
260
  stack: n && t.stack ? t.stack.split(`
231
261
  `).map((e) => e.trim()) : void 0
@@ -235,33 +265,46 @@ function D(t, n, r) {
235
265
  headers: i
236
266
  });
237
267
  }
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;
268
+ function L(e) {
269
+ let t = (e, t) => t(e);
270
+ for (let n = e.length - 1; n >= 0; n--) {
271
+ let r = e[n], i = t;
272
+ t = (e, t) => z(r, e, t, i);
273
+ }
274
+ return t;
275
+ }
276
+ function R(e, t) {
277
+ let n = L(e);
278
+ return function(e) {
279
+ return n(e, t);
280
+ };
281
+ }
282
+ function z(e, t, n, r) {
283
+ let i, a, o = () => (i || (i = !0, a = r(t, n)), a), s = e(t, o);
284
+ return B(s) ? o() : typeof s?.then == `function` ? s.then((e) => B(e) ? o() : e) : s;
242
285
  }
243
- function k(e) {
244
- return e === void 0 || e === h;
286
+ function B(e) {
287
+ return e === void 0 || e === S;
245
288
  }
246
- function A(e) {
247
- if (typeof e == `function`) return j(e);
289
+ function V(e) {
290
+ if (typeof e == `function`) return H(e);
248
291
  let t = e.handler || (e.fetch ? function(t) {
249
292
  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);
293
+ } : U), n = e.middleware?.length && R(e.middleware, t), r = H(n || t);
294
+ return Object.assign(r, e, n && { fetch: r.fetch });
254
295
  }
255
- function j(e) {
296
+ function H(e) {
256
297
  return `fetch` in e ? e : Object.assign(e, { fetch: (t) => {
257
298
  typeof t == `string` && (t = new URL(t, `http://_`)), t instanceof URL && (t = new Request(t));
258
- let n = new c(t);
299
+ let n = new m(t);
259
300
  try {
260
- return Promise.resolve(_(e(n), n));
301
+ return Promise.resolve(w(e(n), n));
261
302
  } catch (e) {
262
- return Promise.resolve(_(e, n));
303
+ return Promise.resolve(w(T(e), n));
263
304
  }
264
305
  } });
265
306
  }
266
- const M = () => h, N = A;
267
- export { p as HTTPError, N as defineEventHandler };
307
+ const U = () => S;
308
+ String.raw`(?:^|/)(?:\.|%(?:25)*2e){1,2}(?:/|$)`, String.raw`%(?:25)*(?:2f|5c)`;
309
+ const W = V;
310
+ export { y as HTTPError, W as defineEventHandler };
@@ -1,12 +1,8 @@
1
1
  type e = {
2
2
  images?: Omit<e, "images">[];
3
- width: number | undefined;
4
- height: number | undefined;
3
+ width: number;
4
+ height: number;
5
5
  orientation?: number;
6
6
  type?: string;
7
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
8
  export type { e as ImageMeta };