h3 1.8.0 → 1.8.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.mjs CHANGED
@@ -26,12 +26,29 @@ function useBase(base, handler) {
26
26
  });
27
27
  }
28
28
 
29
+ function hasProp(obj, prop) {
30
+ try {
31
+ return prop in obj;
32
+ } catch {
33
+ return false;
34
+ }
35
+ }
36
+
37
+ var __defProp$1 = Object.defineProperty;
38
+ var __defNormalProp$1 = (obj, key, value) => key in obj ? __defProp$1(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
39
+ var __publicField$1 = (obj, key, value) => {
40
+ __defNormalProp$1(obj, typeof key !== "symbol" ? key + "" : key, value);
41
+ return value;
42
+ };
29
43
  class H3Error extends Error {
30
44
  constructor(message, opts = {}) {
31
45
  super(message, opts);
32
- this.statusCode = 500;
33
- this.fatal = false;
34
- this.unhandled = false;
46
+ __publicField$1(this, "statusCode", 500);
47
+ __publicField$1(this, "fatal", false);
48
+ __publicField$1(this, "unhandled", false);
49
+ __publicField$1(this, "statusMessage");
50
+ __publicField$1(this, "data");
51
+ __publicField$1(this, "cause");
35
52
  if (opts.cause && !this.cause) {
36
53
  this.cause = opts.cause;
37
54
  }
@@ -50,7 +67,7 @@ class H3Error extends Error {
50
67
  return obj;
51
68
  }
52
69
  }
53
- H3Error.__h3_error__ = true;
70
+ __publicField$1(H3Error, "__h3_error__", true);
54
71
  function createError(input) {
55
72
  if (typeof input === "string") {
56
73
  return new H3Error(input);
@@ -61,7 +78,7 @@ function createError(input) {
61
78
  const err = new H3Error(input.message ?? input.statusMessage ?? "", {
62
79
  cause: input.cause || input
63
80
  });
64
- if ("stack" in input) {
81
+ if (hasProp(input, "stack")) {
65
82
  try {
66
83
  Object.defineProperty(err, "stack", {
67
84
  get() {
@@ -297,7 +314,7 @@ function getRequestProtocol(event, opts = {}) {
297
314
  if (opts.xForwardedProto !== false && event.node.req.headers["x-forwarded-proto"] === "https") {
298
315
  return "https";
299
316
  }
300
- return event.node.req.connection.encrypted ? "https" : "http";
317
+ return event.node.req.connection?.encrypted ? "https" : "http";
301
318
  }
302
319
  const DOUBLE_SLASH_RE = /[/\\]{2,}/g;
303
320
  function getRequestPath(event) {
@@ -402,7 +419,7 @@ function readRawBody(event, encoding = "utf8") {
402
419
  }
403
420
  async function readBody(event, options = {}) {
404
421
  const request = event.node.req;
405
- if (ParsedBodySymbol in request) {
422
+ if (hasProp(request, ParsedBodySymbol)) {
406
423
  return request[ParsedBodySymbol];
407
424
  }
408
425
  const contentType = request.headers["content-type"] || "";
@@ -478,7 +495,7 @@ function _parseURLEncodedBody(body) {
478
495
  const form = new URLSearchParams(body);
479
496
  const parsedForm = /* @__PURE__ */ Object.create(null);
480
497
  for (const [key, value] of form.entries()) {
481
- if (key in parsedForm) {
498
+ if (hasProp(parsedForm, key)) {
482
499
  if (!Array.isArray(parsedForm[key])) {
483
500
  parsedForm[key] = [parsedForm[key]];
484
501
  }
@@ -760,7 +777,7 @@ function sendStream(event, stream) {
760
777
  event._handled = true;
761
778
  return Promise.resolve();
762
779
  }
763
- if ("pipeTo" in stream) {
780
+ if (hasProp(stream, "pipeTo") && typeof stream.pipeTo === "function") {
764
781
  return stream.pipeTo(
765
782
  new WritableStream({
766
783
  write(chunk) {
@@ -771,7 +788,7 @@ function sendStream(event, stream) {
771
788
  event.node.res.end();
772
789
  });
773
790
  }
774
- if (typeof stream.pipe === "function") {
791
+ if (hasProp(stream, "pipe") && typeof stream.pipe === "function") {
775
792
  return new Promise((resolve, reject) => {
776
793
  stream.pipe(event.node.res);
777
794
  if (stream.on) {
@@ -1364,13 +1381,29 @@ function idSearchPaths(id, encodings, indexNames) {
1364
1381
  return ids;
1365
1382
  }
1366
1383
 
1384
+ var __defProp = Object.defineProperty;
1385
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
1386
+ var __publicField = (obj, key, value) => {
1387
+ __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
1388
+ return value;
1389
+ };
1367
1390
  class H3Event {
1368
1391
  constructor(req, res) {
1369
- this["__is_event__"] = true;
1392
+ __publicField(this, "__is_event__", true);
1393
+ // Context
1394
+ __publicField(this, "node");
1395
+ // Node
1396
+ __publicField(this, "web");
1370
1397
  // Web
1371
- this.context = {};
1398
+ __publicField(this, "context", {});
1399
+ // Shared
1400
+ // Request
1401
+ __publicField(this, "_method");
1402
+ __publicField(this, "_path");
1403
+ __publicField(this, "_headers");
1404
+ __publicField(this, "_requestBody");
1372
1405
  // Response
1373
- this._handled = false;
1406
+ __publicField(this, "_handled", false);
1374
1407
  this.node = { req, res };
1375
1408
  }
1376
1409
  // --- Request ---
@@ -1416,7 +1449,7 @@ class H3Event {
1416
1449
  }
1417
1450
  }
1418
1451
  function isEvent(input) {
1419
- return "__is_event__" in input;
1452
+ return hasProp(input, "__is_event__");
1420
1453
  }
1421
1454
  function createEvent(req, res) {
1422
1455
  return new H3Event(req, res);
@@ -1477,7 +1510,7 @@ function defineResponseMiddleware(fn) {
1477
1510
  return fn;
1478
1511
  }
1479
1512
  function isEventHandler(input) {
1480
- return "__is_handler__" in input;
1513
+ return hasProp(input, "__is_handler__");
1481
1514
  }
1482
1515
  function toEventHandler(input, _, _route) {
1483
1516
  if (!isEventHandler(input)) {
@@ -1534,94 +1567,8 @@ function defineLazyEventHandler(factory) {
1534
1567
  }
1535
1568
  const lazyEventHandler = defineLazyEventHandler;
1536
1569
 
1537
- class H3Headers {
1538
- constructor(init) {
1539
- if (!init) {
1540
- this._headers = {};
1541
- } else if (Array.isArray(init)) {
1542
- this._headers = Object.fromEntries(
1543
- init.map(([key, value]) => [key.toLowerCase(), value])
1544
- );
1545
- } else if (init && "append" in init) {
1546
- this._headers = Object.fromEntries(init.entries());
1547
- } else {
1548
- this._headers = Object.fromEntries(
1549
- Object.entries(init).map(([key, value]) => [key.toLowerCase(), value])
1550
- );
1551
- }
1552
- }
1553
- [Symbol.iterator]() {
1554
- return this.entries();
1555
- }
1556
- entries() {
1557
- throw Object.entries(this._headers)[Symbol.iterator]();
1558
- }
1559
- keys() {
1560
- return Object.keys(this._headers)[Symbol.iterator]();
1561
- }
1562
- values() {
1563
- throw Object.values(this._headers)[Symbol.iterator]();
1564
- }
1565
- append(name, value) {
1566
- const _name = name.toLowerCase();
1567
- this.set(_name, [this.get(_name), value].filter(Boolean).join(", "));
1568
- }
1569
- delete(name) {
1570
- delete this._headers[name.toLowerCase()];
1571
- }
1572
- get(name) {
1573
- return this._headers[name.toLowerCase()];
1574
- }
1575
- has(name) {
1576
- return name.toLowerCase() in this._headers;
1577
- }
1578
- set(name, value) {
1579
- this._headers[name.toLowerCase()] = String(value);
1580
- }
1581
- forEach(callbackfn) {
1582
- for (const [key, value] of Object.entries(this._headers)) {
1583
- callbackfn(value, key, this);
1584
- }
1585
- }
1586
- }
1587
-
1588
- class H3Response {
1589
- constructor(body = null, init = {}) {
1590
- // TODO: yet to implement
1591
- this.body = null;
1592
- this.type = "default";
1593
- this.bodyUsed = false;
1594
- this.headers = new H3Headers(init.headers);
1595
- this.status = init.status ?? 200;
1596
- this.statusText = init.statusText || "";
1597
- this.redirected = !!init.status && [301, 302, 307, 308].includes(init.status);
1598
- this._body = body;
1599
- this.url = "";
1600
- this.ok = this.status < 300 && this.status > 199;
1601
- }
1602
- clone() {
1603
- return new H3Response(this.body, {
1604
- headers: this.headers,
1605
- status: this.status,
1606
- statusText: this.statusText
1607
- });
1608
- }
1609
- arrayBuffer() {
1610
- return Promise.resolve(this._body);
1611
- }
1612
- blob() {
1613
- return Promise.resolve(this._body);
1614
- }
1615
- formData() {
1616
- return Promise.resolve(this._body);
1617
- }
1618
- json() {
1619
- return Promise.resolve(this._body);
1620
- }
1621
- text() {
1622
- return Promise.resolve(this._body);
1623
- }
1624
- }
1570
+ const H3Headers = globalThis.Headers;
1571
+ const H3Response = globalThis.Response;
1625
1572
 
1626
1573
  function createApp(options = {}) {
1627
1574
  const stack = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "description": "Minimal H(TTP) framework built for high performance and portability.",
5
5
  "repository": "unjs/h3",
6
6
  "license": "MIT",
@@ -23,38 +23,38 @@
23
23
  "cookie-es": "^1.0.0",
24
24
  "defu": "^6.1.2",
25
25
  "destr": "^2.0.1",
26
- "iron-webcrypto": "^0.8.0",
27
- "radix3": "^1.0.1",
28
- "ufo": "^1.2.0",
26
+ "iron-webcrypto": "^0.10.1",
27
+ "radix3": "^1.1.0",
28
+ "ufo": "^1.3.0",
29
29
  "uncrypto": "^0.1.3",
30
- "unenv": "^1.7.1"
30
+ "unenv": "^1.7.4"
31
31
  },
32
32
  "devDependencies": {
33
- "0x": "^5.6.0",
34
- "@types/express": "^4.17.17",
35
- "@types/node": "^20.5.0",
36
- "@types/supertest": "^2.0.12",
37
- "@vitest/coverage-v8": "^0.34.1",
33
+ "0x": "^5.7.0",
34
+ "@types/express": "^4.17.18",
35
+ "@types/node": "^20.7.0",
36
+ "@types/supertest": "^2.0.13",
37
+ "@vitest/coverage-v8": "^0.34.5",
38
38
  "autocannon": "^7.12.0",
39
- "changelogen": "^0.5.4",
39
+ "changelogen": "^0.5.5",
40
40
  "connect": "^3.7.0",
41
- "eslint": "^8.47.0",
41
+ "eslint": "^8.50.0",
42
42
  "eslint-config-unjs": "^0.2.1",
43
43
  "express": "^4.18.2",
44
44
  "get-port": "^7.0.0",
45
- "jiti": "^1.19.1",
46
- "listhen": "^1.3.0",
47
- "node-fetch-native": "^1.2.0",
48
- "prettier": "^3.0.1",
45
+ "jiti": "^1.20.0",
46
+ "listhen": "^1.5.5",
47
+ "node-fetch-native": "^1.4.0",
48
+ "prettier": "^3.0.3",
49
49
  "react": "^18.2.0",
50
50
  "react-dom": "^18.2.0",
51
51
  "supertest": "^6.3.3",
52
- "typescript": "^5.1.6",
53
- "unbuild": "^1.2.1",
54
- "vitest": "^0.34.1",
55
- "zod": "^3.22.0"
52
+ "typescript": "^5.2.2",
53
+ "unbuild": "^2.0.0",
54
+ "vitest": "^0.34.5",
55
+ "zod": "^3.22.2"
56
56
  },
57
- "packageManager": "pnpm@8.6.12",
57
+ "packageManager": "pnpm@8.8.0",
58
58
  "scripts": {
59
59
  "build": "unbuild",
60
60
  "dev": "vitest",