@php-wasm/universal 2.0.3 → 2.0.5

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/index.js CHANGED
@@ -872,7 +872,7 @@ class PHPExecutionFailureError extends Error {
872
872
  }
873
873
  }
874
874
  const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php", OPCACHE_FILE_FOLDER = "/internal/shared/opcache";
875
- var k, E, x, g, v, T, d, z, W, B, $, V, G, J, Y, K, L, X, O, U;
875
+ var k, E, x, g, v, T, h, z, W, $, B, V, G, J, Y, K, L, X, O, U;
876
876
  class PHP {
877
877
  /**
878
878
  * Initializes a PHP runtime.
@@ -882,7 +882,7 @@ class PHP {
882
882
  * @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
883
883
  */
884
884
  constructor(t) {
885
- _(this, d);
885
+ _(this, h);
886
886
  _(this, k);
887
887
  _(this, E);
888
888
  _(this, x);
@@ -1291,27 +1291,27 @@ class PHP {
1291
1291
  this.runStreamCalled = !0;
1292
1292
  const e = await this.semaphore.acquire();
1293
1293
  let r;
1294
- const s = m(this, d, U).call(this, async () => {
1295
- if (u(this, E) || (await m(this, d, W).call(this), f(this, E, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1294
+ const s = m(this, h, U).call(this, async () => {
1295
+ if (u(this, E) || (await m(this, h, W).call(this), f(this, E, !0)), t.scriptPath && !this.fileExists(t.scriptPath))
1296
1296
  throw new Error(
1297
1297
  `The script path "${t.scriptPath}" does not exist.`
1298
1298
  );
1299
- m(this, d, B).call(this, t.relativeUri || ""), m(this, d, J).call(this, t.method || "GET");
1300
- const n = normalizeHeaders(t.headers || {}), i = n.host || "example.com:443", o = m(this, d, G).call(this, i, t.protocol || "http");
1301
- if (m(this, d, $).call(this, i), m(this, d, V).call(this, o), m(this, d, Y).call(this, n), t.body && (r = m(this, d, K).call(this, t.body)), typeof t.code == "string")
1302
- this.writeFile("/internal/eval.php", t.code), m(this, d, L).call(this, "/internal/eval.php");
1299
+ m(this, h, $).call(this, t.relativeUri || ""), m(this, h, J).call(this, t.method || "GET");
1300
+ const n = normalizeHeaders(t.headers || {}), i = n.host || "example.com:443", o = m(this, h, G).call(this, i, t.protocol || "http");
1301
+ if (m(this, h, B).call(this, i), m(this, h, V).call(this, o), m(this, h, Y).call(this, n), t.body && (r = m(this, h, K).call(this, t.body)), typeof t.code == "string")
1302
+ this.writeFile("/internal/eval.php", t.code), m(this, h, L).call(this, "/internal/eval.php");
1303
1303
  else if (typeof t.scriptPath == "string")
1304
- m(this, d, L).call(this, t.scriptPath || "");
1304
+ m(this, h, L).call(this, t.scriptPath || "");
1305
1305
  else
1306
1306
  throw new TypeError(
1307
1307
  "The request object must have either a `code` or a `scriptPath` property."
1308
1308
  );
1309
- const a = m(this, d, z).call(this, t.$_SERVER, n, o);
1309
+ const a = m(this, h, z).call(this, t.$_SERVER, n, o);
1310
1310
  for (const l in a)
1311
- m(this, d, X).call(this, l, a[l]);
1311
+ m(this, h, X).call(this, l, a[l]);
1312
1312
  const c = t.env || {};
1313
1313
  for (const l in c)
1314
- m(this, d, O).call(this, l, c[l]);
1314
+ m(this, h, O).call(this, l, c[l]);
1315
1315
  return await this[__private__dont__use].ccall(
1316
1316
  "wasm_sapi_handle_request",
1317
1317
  NUMBER,
@@ -1320,14 +1320,7 @@ class PHP {
1320
1320
  { async: !0 }
1321
1321
  );
1322
1322
  });
1323
- return await s.catch((n) => {
1324
- throw this.dispatchEvent({
1325
- type: "request.error",
1326
- error: n,
1327
- // Distinguish between PHP request and PHP-wasm errors
1328
- source: n.source ?? "php-wasm"
1329
- }), n;
1330
- }).finally(() => {
1323
+ return await s.finally(() => {
1331
1324
  r && this[__private__dont__use].free(r);
1332
1325
  }).finally(() => {
1333
1326
  e(), this.dispatchEvent({
@@ -1574,7 +1567,7 @@ class PHP {
1574
1567
  this.cliCalled = !0;
1575
1568
  const r = await this.semaphore.acquire(), s = e.env || {};
1576
1569
  for (const [n, i] of Object.entries(s))
1577
- m(this, d, O).call(this, n, i);
1570
+ m(this, h, O).call(this, n, i);
1578
1571
  t = [t[0], "-c", PHP_INI_PATH, ...t.slice(1)];
1579
1572
  for (const n of t)
1580
1573
  this[__private__dont__use].ccall(
@@ -1583,7 +1576,7 @@ class PHP {
1583
1576
  [STRING],
1584
1577
  [n]
1585
1578
  );
1586
- return await m(this, d, U).call(this, () => this[__private__dont__use].ccall("run_cli", null, [], [], {
1579
+ return await m(this, h, U).call(this, () => this[__private__dont__use].ccall("run_cli", null, [], [], {
1587
1580
  async: !0
1588
1581
  })).then((n) => (n.exitCode.finally(r), n));
1589
1582
  }
@@ -1609,7 +1602,7 @@ class PHP {
1609
1602
  u(this, E) && this.exit(0);
1610
1603
  }
1611
1604
  }
1612
- k = new WeakMap(), E = new WeakMap(), x = new WeakMap(), g = new WeakMap(), v = new WeakMap(), T = new WeakMap(), d = new WeakSet(), /**
1605
+ k = new WeakMap(), E = new WeakMap(), x = new WeakMap(), g = new WeakMap(), v = new WeakMap(), T = new WeakMap(), h = new WeakSet(), /**
1613
1606
  * Prepares the $_SERVER entries for the PHP runtime.
1614
1607
  *
1615
1608
  * @param defaults Default entries to include in $_SERVER.
@@ -1632,7 +1625,7 @@ z = function(t, e, r) {
1632
1625
  return this[__private__dont__use].ccall("php_wasm_init", null, [], [], {
1633
1626
  isAsync: !0
1634
1627
  });
1635
- }, B = function(t) {
1628
+ }, $ = function(t) {
1636
1629
  this[__private__dont__use].ccall(
1637
1630
  "wasm_set_request_uri",
1638
1631
  null,
@@ -1646,7 +1639,7 @@ z = function(t, e, r) {
1646
1639
  [STRING],
1647
1640
  [e]
1648
1641
  );
1649
- }, $ = function(t) {
1642
+ }, B = function(t) {
1650
1643
  this[__private__dont__use].ccall(
1651
1644
  "wasm_set_request_host",
1652
1645
  null,
@@ -1737,23 +1730,23 @@ z = function(t, e, r) {
1737
1730
  );
1738
1731
  }, U = async function(t) {
1739
1732
  const e = this[__private__dont__use], r = await createInvertedReadableStream();
1740
- e.onHeaders = (h) => {
1741
- a || s || r.controller.enqueue(h.slice());
1733
+ e.onHeaders = (d) => {
1734
+ a || s || r.controller.enqueue(d.slice());
1742
1735
  };
1743
1736
  let s = !1;
1744
1737
  const n = () => {
1745
1738
  s || (s = !0, r.controller.close());
1746
1739
  }, i = await createInvertedReadableStream();
1747
- e.onStdout = (h) => {
1748
- n(), !a && i.controller.enqueue(h.slice());
1740
+ e.onStdout = (d) => {
1741
+ n(), !a && i.controller.enqueue(d.slice());
1749
1742
  };
1750
1743
  const o = await createInvertedReadableStream();
1751
- e.onStderr = (h) => {
1752
- a || o.controller.enqueue(h.slice());
1744
+ e.onStderr = (d) => {
1745
+ a || o.controller.enqueue(d.slice());
1753
1746
  };
1754
1747
  let a = !1, c;
1755
1748
  const p = (async () => {
1756
- var h;
1749
+ var d;
1757
1750
  try {
1758
1751
  return await Promise.race([
1759
1752
  t(),
@@ -1780,12 +1773,29 @@ z = function(t, e, r) {
1780
1773
  });
1781
1774
  throw this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify(), y;
1782
1775
  } finally {
1783
- a || (i.controller.close(), o.controller.close(), n(), a = !0), (h = u(this, x)) == null || h.removeEventListener(
1776
+ a || (i.controller.close(), o.controller.close(), n(), a = !0), (d = u(this, x)) == null || d.removeEventListener(
1784
1777
  "error",
1785
1778
  c
1786
1779
  );
1787
1780
  }
1788
- })();
1781
+ })().then(
1782
+ (d) => (d !== 0 && this.dispatchEvent({
1783
+ type: "request.error",
1784
+ error: new Error(
1785
+ `PHP.run() failed with exit code ${d}.`
1786
+ ),
1787
+ // Distinguish between PHP request and PHP-wasm errors
1788
+ source: "php-wasm"
1789
+ }), d),
1790
+ (d) => {
1791
+ throw this.dispatchEvent({
1792
+ type: "request.error",
1793
+ error: d,
1794
+ // Distinguish between PHP request and PHP-wasm errors
1795
+ source: d.source ?? "php-wasm"
1796
+ }), d;
1797
+ }
1798
+ );
1789
1799
  return new StreamedPHPResponse(
1790
1800
  r.stream,
1791
1801
  i.stream,
@@ -2797,18 +2807,18 @@ function expose(t, e = globalThis, r = ["*"], s) {
2797
2807
  }, l = (i.data.argumentList || []).map(fromWireValue);
2798
2808
  let p;
2799
2809
  try {
2800
- const h = c.slice(0, -1).reduce((w, b) => w[b], t), y = c.reduce((w, b) => w[b], t);
2810
+ const d = c.slice(0, -1).reduce((w, b) => w[b], t), y = c.reduce((w, b) => w[b], t);
2801
2811
  switch (a) {
2802
2812
  case MessageType.GET:
2803
2813
  p = y;
2804
2814
  break;
2805
2815
  case MessageType.SET:
2806
- h[c.slice(-1)[0]] = fromWireValue(
2816
+ d[c.slice(-1)[0]] = fromWireValue(
2807
2817
  i.data.value
2808
2818
  ), p = !0;
2809
2819
  break;
2810
2820
  case MessageType.APPLY:
2811
- p = y.apply(h, l);
2821
+ p = y.apply(d, l);
2812
2822
  break;
2813
2823
  case MessageType.CONSTRUCT:
2814
2824
  {
@@ -2828,18 +2838,18 @@ function expose(t, e = globalThis, r = ["*"], s) {
2828
2838
  default:
2829
2839
  return;
2830
2840
  }
2831
- } catch (h) {
2832
- p = { value: h, [throwMarker]: 0 };
2841
+ } catch (d) {
2842
+ p = { value: d, [throwMarker]: 0 };
2833
2843
  }
2834
- Promise.resolve(p).catch((h) => ({ value: h, [throwMarker]: 0 })).then((h) => {
2835
- const [y, w] = toWireValue(h);
2844
+ Promise.resolve(p).catch((d) => ({ value: d, [throwMarker]: 0 })).then((d) => {
2845
+ const [y, w] = toWireValue(d);
2836
2846
  e.postMessage({ ...y, id: o }, w), a === MessageType.RELEASE && (e.removeEventListener("message", n), closeEndPoint(e), finalizer in t && typeof t[finalizer] == "function" && t[finalizer]());
2837
2847
  }).catch(() => {
2838
- const [h, y] = toWireValue({
2848
+ const [d, y] = toWireValue({
2839
2849
  value: new TypeError("Unserializable return value"),
2840
2850
  [throwMarker]: 0
2841
2851
  });
2842
- e.postMessage({ ...h, id: o }, y);
2852
+ e.postMessage({ ...d, id: o }, y);
2843
2853
  }).finally(() => {
2844
2854
  s == null || s(i);
2845
2855
  });
@@ -2916,7 +2926,7 @@ function createProxy(t, e, r = [], s = function() {
2916
2926
  e,
2917
2927
  {
2918
2928
  type: MessageType.SET,
2919
- path: [...r, a].map((h) => h.toString()),
2929
+ path: [...r, a].map((d) => d.toString()),
2920
2930
  value: l
2921
2931
  },
2922
2932
  p
@@ -2931,7 +2941,7 @@ function createProxy(t, e, r = [], s = function() {
2931
2941
  }).then(fromWireValue);
2932
2942
  if (l === "bind")
2933
2943
  return createProxy(t, e, r.slice(0, -1));
2934
- const [p, h] = processArguments(c);
2944
+ const [p, d] = processArguments(c);
2935
2945
  return requestResponseMessage(
2936
2946
  t,
2937
2947
  e,
@@ -2940,7 +2950,7 @@ function createProxy(t, e, r = [], s = function() {
2940
2950
  path: r.map((y) => y.toString()),
2941
2951
  argumentList: p
2942
2952
  },
2943
- h
2953
+ d
2944
2954
  ).then(fromWireValue);
2945
2955
  },
2946
2956
  construct(o, a) {