@php-wasm/web 0.1.18 → 0.1.20

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.
@@ -8,7 +8,7 @@ const W = [
8
8
  "7.1",
9
9
  "7.0",
10
10
  "5.6"
11
- ], Y = W[0], ve = W;
11
+ ], Y = W[0], Se = W;
12
12
  class K {
13
13
  #e;
14
14
  #t;
@@ -106,9 +106,27 @@ class Z {
106
106
  };
107
107
  }
108
108
  }
109
- class O {
109
+ class E {
110
110
  constructor(e, r, n, s = "", a = 0) {
111
- this.httpStatusCode = e, this.headers = r, this.body = n, this.exitCode = a, this.errors = s;
111
+ this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = a, this.errors = s;
112
+ }
113
+ static fromRawData(e) {
114
+ return new E(
115
+ e.httpStatusCode,
116
+ e.headers,
117
+ e.bytes,
118
+ e.errors,
119
+ e.exitCode
120
+ );
121
+ }
122
+ toRawData() {
123
+ return {
124
+ headers: this.headers,
125
+ bytes: this.bytes,
126
+ errors: this.errors,
127
+ exitCode: this.exitCode,
128
+ httpStatusCode: this.httpStatusCode
129
+ };
112
130
  }
113
131
  /**
114
132
  * Response body as JSON.
@@ -120,13 +138,7 @@ class O {
120
138
  * Response body as text.
121
139
  */
122
140
  get text() {
123
- return new TextDecoder().decode(this.body);
124
- }
125
- /**
126
- * Response body as bytes.
127
- */
128
- get bytes() {
129
- return this.body;
141
+ return new TextDecoder().decode(this.bytes);
130
142
  }
131
143
  }
132
144
  class ee {
@@ -147,7 +159,7 @@ class ee {
147
159
  this.#a = new Z({ concurrency: 1 });
148
160
  const {
149
161
  documentRoot: n = "/www/",
150
- absoluteUrl: s = location.origin,
162
+ absoluteUrl: s = typeof location == "object" ? location?.href : "",
151
163
  isStaticFilePath: a = () => !1
152
164
  } = r;
153
165
  this.php = e, this.#e = n, this.#c = a;
@@ -225,13 +237,13 @@ class ee {
225
237
  #l(e) {
226
238
  const r = `${this.#e}${e}`;
227
239
  if (!this.php.fileExists(r))
228
- return new O(
240
+ return new E(
229
241
  404,
230
242
  {},
231
243
  new TextEncoder().encode("404 File not found")
232
244
  );
233
245
  const n = this.php.readFileAsBuffer(r);
234
- return new O(
246
+ return new E(
235
247
  200,
236
248
  {
237
249
  "content-length": [`${n.byteLength}`],
@@ -432,7 +444,7 @@ const I = {
432
444
  75: "Cross-device link.",
433
445
  76: "Extension: Capabilities insufficient."
434
446
  };
435
- function g(t = "") {
447
+ function y(t = "") {
436
448
  return function(r, n, s) {
437
449
  const a = s.value;
438
450
  s.value = function(...i) {
@@ -451,12 +463,12 @@ function g(t = "") {
451
463
  };
452
464
  };
453
465
  }
454
- var re = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, y = (t, e, r, n) => {
466
+ var re = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, g = (t, e, r, n) => {
455
467
  for (var s = n > 1 ? void 0 : n ? ne(e, r) : e, a = t.length - 1, i; a >= 0; a--)
456
468
  (i = t[a]) && (s = (n ? i(e, r, s) : i(s)) || s);
457
469
  return n && s && re(e, r, s), s;
458
470
  };
459
- const h = "string", w = "number", S = [], se = function() {
471
+ const d = "string", w = "number", x = [], se = function() {
460
472
  return typeof window < "u" && !{}.TEST ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
461
473
  }();
462
474
  class m {
@@ -478,9 +490,9 @@ class m {
478
490
  initializeRuntime(e) {
479
491
  if (this.#e)
480
492
  throw new Error("PHP runtime already initialized.");
481
- if (!S[e])
493
+ if (!x[e])
482
494
  throw new Error("Invalid PHP runtime id.");
483
- this.#e = S[e];
495
+ this.#e = x[e];
484
496
  }
485
497
  /** @inheritDoc */
486
498
  setPhpIniPath(e) {
@@ -525,7 +537,7 @@ class m {
525
537
  this.#e.ccall(
526
538
  "wasm_set_phpini_entries",
527
539
  null,
528
- [h],
540
+ [d],
529
541
  [e]
530
542
  );
531
543
  }
@@ -533,7 +545,7 @@ class m {
533
545
  }
534
546
  cli(e) {
535
547
  for (const r of e)
536
- this.#e.ccall("wasm_add_cli_arg", null, [h], [r]);
548
+ this.#e.ccall("wasm_add_cli_arg", null, [d], [r]);
537
549
  return this.#e.ccall("run_cli", null, [], [], { async: !0 });
538
550
  }
539
551
  #i() {
@@ -555,18 +567,18 @@ class m {
555
567
  };
556
568
  }
557
569
  #n(e) {
558
- if (this.#e.ccall("wasm_set_request_uri", null, [h], [e]), e.includes("?")) {
570
+ if (this.#e.ccall("wasm_set_request_uri", null, [d], [e]), e.includes("?")) {
559
571
  const r = e.substring(e.indexOf("?") + 1);
560
572
  this.#e.ccall(
561
573
  "wasm_set_query_string",
562
574
  null,
563
- [h],
575
+ [d],
564
576
  [r]
565
577
  );
566
578
  }
567
579
  }
568
580
  #o(e, r) {
569
- this.#e.ccall("wasm_set_request_host", null, [h], [e]);
581
+ this.#e.ccall("wasm_set_request_host", null, [d], [e]);
570
582
  let n;
571
583
  try {
572
584
  n = parseInt(new URL(e).port, 10);
@@ -575,7 +587,7 @@ class m {
575
587
  (!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this.#e.ccall("wasm_set_request_port", null, [w], [n]), (r === "https" || !r && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
576
588
  }
577
589
  #a(e) {
578
- this.#e.ccall("wasm_set_request_method", null, [h], [e]);
590
+ this.#e.ccall("wasm_set_request_method", null, [d], [e]);
579
591
  }
580
592
  setSkipShebang(e) {
581
593
  this.#e.ccall(
@@ -589,12 +601,12 @@ class m {
589
601
  e.cookie && this.#e.ccall(
590
602
  "wasm_set_cookies",
591
603
  null,
592
- [h],
604
+ [d],
593
605
  [e.cookie]
594
606
  ), e["content-type"] && this.#e.ccall(
595
607
  "wasm_set_content_type",
596
608
  null,
597
- [h],
609
+ [d],
598
610
  [e["content-type"]]
599
611
  ), e["content-length"] && this.#e.ccall(
600
612
  "wasm_set_content_length",
@@ -609,7 +621,7 @@ class m {
609
621
  );
610
622
  }
611
623
  #l(e) {
612
- this.#e.ccall("wasm_set_request_body", null, [h], [e]), this.#e.ccall(
624
+ this.#e.ccall("wasm_set_request_body", null, [d], [e]), this.#e.ccall(
613
625
  "wasm_set_content_length",
614
626
  null,
615
627
  [w],
@@ -617,13 +629,13 @@ class m {
617
629
  );
618
630
  }
619
631
  #u(e) {
620
- this.#e.ccall("wasm_set_path_translated", null, [h], [e]);
632
+ this.#e.ccall("wasm_set_path_translated", null, [d], [e]);
621
633
  }
622
634
  addServerGlobalEntry(e, r) {
623
635
  this.#e.ccall(
624
636
  "wasm_add_SERVER_entry",
625
637
  null,
626
- [h, h],
638
+ [d, d],
627
639
  [e, r]
628
640
  );
629
641
  }
@@ -643,12 +655,12 @@ class m {
643
655
  this.#e.ccall(
644
656
  "wasm_add_uploaded_file",
645
657
  null,
646
- [h, h, h, h, w, w],
658
+ [d, d, d, d, w, w],
647
659
  [r, n, s, i, o, a.byteLength]
648
660
  );
649
661
  }
650
662
  #d(e) {
651
- this.#e.ccall("wasm_set_php_code", null, [h], [e]);
663
+ this.#e.ccall("wasm_set_php_code", null, [d], [e]);
652
664
  }
653
665
  async #f() {
654
666
  const e = await await this.#e.ccall(
@@ -657,7 +669,7 @@ class m {
657
669
  [],
658
670
  []
659
671
  ), { headers: r, httpStatusCode: n } = this.#i();
660
- return new O(
672
+ return new E(
661
673
  n,
662
674
  r,
663
675
  this.readFileAsBuffer("/tmp/stdout"),
@@ -665,9 +677,12 @@ class m {
665
677
  e
666
678
  );
667
679
  }
668
- mkdirTree(e) {
680
+ mkdir(e) {
669
681
  this.#e.FS.mkdirTree(e);
670
682
  }
683
+ mkdirTree(e) {
684
+ this.mkdir(e);
685
+ }
671
686
  readFileAsText(e) {
672
687
  return new TextDecoder().decode(this.readFileAsBuffer(e));
673
688
  }
@@ -706,37 +721,40 @@ class m {
706
721
  mount(e, r) {
707
722
  this.#e.FS.mount(
708
723
  this.#e.FS.filesystems.NODEFS,
709
- e,
724
+ typeof e == "object" ? e : { root: e },
710
725
  r
711
726
  );
712
727
  }
713
728
  }
714
- y([
715
- g('Could not create directory "{path}"')
729
+ g([
730
+ y('Could not create directory "{path}"')
731
+ ], m.prototype, "mkdir", 1);
732
+ g([
733
+ y('Could not create directory "{path}"')
716
734
  ], m.prototype, "mkdirTree", 1);
717
- y([
718
- g('Could not read "{path}"')
735
+ g([
736
+ y('Could not read "{path}"')
719
737
  ], m.prototype, "readFileAsText", 1);
720
- y([
721
- g('Could not read "{path}"')
738
+ g([
739
+ y('Could not read "{path}"')
722
740
  ], m.prototype, "readFileAsBuffer", 1);
723
- y([
724
- g('Could not write to "{path}"')
741
+ g([
742
+ y('Could not write to "{path}"')
725
743
  ], m.prototype, "writeFile", 1);
726
- y([
727
- g('Could not unlink "{path}"')
744
+ g([
745
+ y('Could not unlink "{path}"')
728
746
  ], m.prototype, "unlink", 1);
729
- y([
730
- g('Could not list files in "{path}"')
747
+ g([
748
+ y('Could not list files in "{path}"')
731
749
  ], m.prototype, "listFiles", 1);
732
- y([
733
- g('Could not stat "{path}"')
750
+ g([
751
+ y('Could not stat "{path}"')
734
752
  ], m.prototype, "isDir", 1);
735
- y([
736
- g('Could not stat "{path}"')
753
+ g([
754
+ y('Could not stat "{path}"')
737
755
  ], m.prototype, "fileExists", 1);
738
- y([
739
- g("Could not mount a directory")
756
+ g([
757
+ y("Could not mount a directory")
740
758
  ], m.prototype, "mount", 1);
741
759
  function ie(t) {
742
760
  const e = {};
@@ -770,14 +788,14 @@ async function oe(t, e = {}, r = []) {
770
788
  });
771
789
  for (const { default: c } of r)
772
790
  c(o);
773
- return r.length || s(), await a, await i, S.push(o), S.length - 1;
791
+ return r.length || s(), await a, await i, x.push(o), x.length - 1;
774
792
  }
775
793
  /**
776
794
  * @license
777
795
  * Copyright 2019 Google LLC
778
796
  * SPDX-License-Identifier: Apache-2.0
779
797
  */
780
- const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"), ce = Symbol("Comlink.releaseProxy"), C = Symbol("Comlink.finalizer"), v = Symbol("Comlink.thrown"), z = (t) => typeof t == "object" && t !== null || typeof t == "function", le = {
798
+ const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"), ce = Symbol("Comlink.releaseProxy"), O = Symbol("Comlink.finalizer"), k = Symbol("Comlink.thrown"), z = (t) => typeof t == "object" && t !== null || typeof t == "function", le = {
781
799
  canHandle: (t) => z(t) && t[D],
782
800
  serialize(t) {
783
801
  const { port1: e, port2: r } = new MessageChannel();
@@ -787,7 +805,7 @@ const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"), ce = Symbol(
787
805
  return t.start(), L(t);
788
806
  }
789
807
  }, ue = {
790
- canHandle: (t) => z(t) && v in t,
808
+ canHandle: (t) => z(t) && k in t,
791
809
  serialize({ value: t }) {
792
810
  let e;
793
811
  return t instanceof Error ? e = {
@@ -802,7 +820,7 @@ const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"), ce = Symbol(
802
820
  deserialize(t) {
803
821
  throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
804
822
  }
805
- }, _ = /* @__PURE__ */ new Map([
823
+ }, S = /* @__PURE__ */ new Map([
806
824
  ["proxy", le],
807
825
  ["throw", ue]
808
826
  ]);
@@ -823,7 +841,7 @@ function F(t, e = globalThis, r = ["*"]) {
823
841
  const { id: a, type: i, path: o } = Object.assign({ path: [] }, s.data), c = (s.data.argumentList || []).map(P);
824
842
  let l;
825
843
  try {
826
- const u = o.slice(0, -1).reduce((f, E) => f[E], t), p = o.reduce((f, E) => f[E], t);
844
+ const u = o.slice(0, -1).reduce((f, R) => f[R], t), p = o.reduce((f, R) => f[R], t);
827
845
  switch (i) {
828
846
  case "GET":
829
847
  l = p;
@@ -842,8 +860,8 @@ function F(t, e = globalThis, r = ["*"]) {
842
860
  break;
843
861
  case "ENDPOINT":
844
862
  {
845
- const { port1: f, port2: E } = new MessageChannel();
846
- F(t, E), l = ge(f, [f]);
863
+ const { port1: f, port2: R } = new MessageChannel();
864
+ F(t, R), l = ye(f, [f]);
847
865
  }
848
866
  break;
849
867
  case "RELEASE":
@@ -853,15 +871,15 @@ function F(t, e = globalThis, r = ["*"]) {
853
871
  return;
854
872
  }
855
873
  } catch (u) {
856
- l = { value: u, [v]: 0 };
874
+ l = { value: u, [k]: 0 };
857
875
  }
858
- Promise.resolve(l).catch((u) => ({ value: u, [v]: 0 })).then((u) => {
859
- const [p, f] = T(u);
860
- e.postMessage(Object.assign(Object.assign({}, p), { id: a }), f), i === "RELEASE" && (e.removeEventListener("message", n), j(e), C in t && typeof t[C] == "function" && t[C]());
876
+ Promise.resolve(l).catch((u) => ({ value: u, [k]: 0 })).then((u) => {
877
+ const [p, f] = C(u);
878
+ e.postMessage(Object.assign(Object.assign({}, p), { id: a }), f), i === "RELEASE" && (e.removeEventListener("message", n), $(e), O in t && typeof t[O] == "function" && t[O]());
861
879
  }).catch((u) => {
862
- const [p, f] = T({
880
+ const [p, f] = C({
863
881
  value: new TypeError("Unserializable return value"),
864
- [v]: 0
882
+ [k]: 0
865
883
  });
866
884
  e.postMessage(Object.assign(Object.assign({}, p), { id: a }), f);
867
885
  });
@@ -870,42 +888,42 @@ function F(t, e = globalThis, r = ["*"]) {
870
888
  function de(t) {
871
889
  return t.constructor.name === "MessagePort";
872
890
  }
873
- function j(t) {
891
+ function $(t) {
874
892
  de(t) && t.close();
875
893
  }
876
894
  function L(t, e) {
877
- return A(t, [], e);
895
+ return H(t, [], e);
878
896
  }
879
- function R(t) {
897
+ function v(t) {
880
898
  if (t)
881
899
  throw new Error("Proxy has been released and is not useable");
882
900
  }
883
- function $(t) {
901
+ function q(t) {
884
902
  return b(t, {
885
903
  type: "RELEASE"
886
904
  }).then(() => {
887
- j(t);
905
+ $(t);
888
906
  });
889
907
  }
890
- const k = /* @__PURE__ */ new WeakMap(), x = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
891
- const e = (k.get(t) || 0) - 1;
892
- k.set(t, e), e === 0 && $(t);
908
+ const _ = /* @__PURE__ */ new WeakMap(), T = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
909
+ const e = (_.get(t) || 0) - 1;
910
+ _.set(t, e), e === 0 && q(t);
893
911
  });
894
912
  function fe(t, e) {
895
- const r = (k.get(e) || 0) + 1;
896
- k.set(e, r), x && x.register(t, e, t);
913
+ const r = (_.get(e) || 0) + 1;
914
+ _.set(e, r), T && T.register(t, e, t);
897
915
  }
898
916
  function pe(t) {
899
- x && x.unregister(t);
917
+ T && T.unregister(t);
900
918
  }
901
- function A(t, e = [], r = function() {
919
+ function H(t, e = [], r = function() {
902
920
  }) {
903
921
  let n = !1;
904
922
  const s = new Proxy(r, {
905
923
  get(a, i) {
906
- if (R(n), i === ce)
924
+ if (v(n), i === ce)
907
925
  return () => {
908
- pe(s), $(t), n = !0;
926
+ pe(s), q(t), n = !0;
909
927
  };
910
928
  if (i === "then") {
911
929
  if (e.length === 0)
@@ -916,11 +934,11 @@ function A(t, e = [], r = function() {
916
934
  }).then(P);
917
935
  return o.then.bind(o);
918
936
  }
919
- return A(t, [...e, i]);
937
+ return H(t, [...e, i]);
920
938
  },
921
939
  set(a, i, o) {
922
- R(n);
923
- const [c, l] = T(o);
940
+ v(n);
941
+ const [c, l] = C(o);
924
942
  return b(t, {
925
943
  type: "SET",
926
944
  path: [...e, i].map((u) => u.toString()),
@@ -928,14 +946,14 @@ function A(t, e = [], r = function() {
928
946
  }, l).then(P);
929
947
  },
930
948
  apply(a, i, o) {
931
- R(n);
949
+ v(n);
932
950
  const c = e[e.length - 1];
933
951
  if (c === ae)
934
952
  return b(t, {
935
953
  type: "ENDPOINT"
936
954
  }).then(P);
937
955
  if (c === "bind")
938
- return A(t, e.slice(0, -1));
956
+ return H(t, e.slice(0, -1));
939
957
  const [l, u] = U(o);
940
958
  return b(t, {
941
959
  type: "APPLY",
@@ -944,7 +962,7 @@ function A(t, e = [], r = function() {
944
962
  }, u).then(P);
945
963
  },
946
964
  construct(a, i) {
947
- R(n);
965
+ v(n);
948
966
  const [o, c] = U(i);
949
967
  return b(t, {
950
968
  type: "CONSTRUCT",
@@ -959,12 +977,12 @@ function me(t) {
959
977
  return Array.prototype.concat.apply([], t);
960
978
  }
961
979
  function U(t) {
962
- const e = t.map(T);
980
+ const e = t.map(C);
963
981
  return [e.map((r) => r[0]), me(e.map((r) => r[1]))];
964
982
  }
965
- const q = /* @__PURE__ */ new WeakMap();
966
- function ge(t, e) {
967
- return q.set(t, e), t;
983
+ const j = /* @__PURE__ */ new WeakMap();
984
+ function ye(t, e) {
985
+ return j.set(t, e), t;
968
986
  }
969
987
  function B(t) {
970
988
  return Object.assign(t, { [D]: !0 });
@@ -976,8 +994,8 @@ function V(t, e = globalThis, r = "*") {
976
994
  removeEventListener: e.removeEventListener.bind(e)
977
995
  };
978
996
  }
979
- function T(t) {
980
- for (const [e, r] of _)
997
+ function C(t) {
998
+ for (const [e, r] of S)
981
999
  if (r.canHandle(t)) {
982
1000
  const [n, s] = r.serialize(t);
983
1001
  return [
@@ -994,34 +1012,34 @@ function T(t) {
994
1012
  type: "RAW",
995
1013
  value: t
996
1014
  },
997
- q.get(t) || []
1015
+ j.get(t) || []
998
1016
  ];
999
1017
  }
1000
1018
  function P(t) {
1001
1019
  switch (t.type) {
1002
1020
  case "HANDLER":
1003
- return _.get(t.name).deserialize(t.value);
1021
+ return S.get(t.name).deserialize(t.value);
1004
1022
  case "RAW":
1005
1023
  return t.value;
1006
1024
  }
1007
1025
  }
1008
1026
  function b(t, e, r) {
1009
1027
  return new Promise((n) => {
1010
- const s = ye();
1028
+ const s = ge();
1011
1029
  t.addEventListener("message", function a(i) {
1012
1030
  !i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", a), n(i.data));
1013
1031
  }), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), r);
1014
1032
  });
1015
1033
  }
1016
- function ye() {
1034
+ function ge() {
1017
1035
  return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
1018
1036
  }
1019
- function Se(t) {
1037
+ function ve(t) {
1020
1038
  G();
1021
1039
  const e = t instanceof Worker ? t : V(t);
1022
1040
  return L(e);
1023
1041
  }
1024
- function _e(t, e) {
1042
+ function ke(t, e) {
1025
1043
  G();
1026
1044
  let r;
1027
1045
  const n = new Promise((i) => {
@@ -1035,7 +1053,7 @@ function _e(t, e) {
1035
1053
  ), [r, a];
1036
1054
  }
1037
1055
  function G() {
1038
- _.set("EVENT", {
1056
+ S.set("EVENT", {
1039
1057
  canHandle: (t) => t instanceof CustomEvent,
1040
1058
  serialize: (t) => [
1041
1059
  {
@@ -1044,7 +1062,7 @@ function G() {
1044
1062
  []
1045
1063
  ],
1046
1064
  deserialize: (t) => t
1047
- }), _.set("FUNCTION", {
1065
+ }), S.set("FUNCTION", {
1048
1066
  canHandle: (t) => typeof t == "function",
1049
1067
  serialize(t) {
1050
1068
  console.debug("[Comlink][Performance] Proxying a function");
@@ -1054,6 +1072,14 @@ function G() {
1054
1072
  deserialize(t) {
1055
1073
  return t.start(), L(t);
1056
1074
  }
1075
+ }), S.set("PHPResponse", {
1076
+ canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
1077
+ serialize(t) {
1078
+ return [t.toRawData(), []];
1079
+ },
1080
+ deserialize(t) {
1081
+ return E.fromRawData(t);
1082
+ }
1057
1083
  });
1058
1084
  }
1059
1085
  function J(t) {
@@ -1097,7 +1123,7 @@ async function we(t = Y) {
1097
1123
  }
1098
1124
  throw new Error(`Unsupported PHP version ${t}`);
1099
1125
  }
1100
- class H extends m {
1126
+ class A extends m {
1101
1127
  /**
1102
1128
  * Creates a new PHP instance.
1103
1129
  *
@@ -1111,7 +1137,7 @@ class H extends m {
1111
1137
  * @returns A new PHP instance
1112
1138
  */
1113
1139
  static async load(e, r = {}) {
1114
- return await H.loadSync(e, r).phpReady;
1140
+ return await A.loadSync(e, r).phpReady;
1115
1141
  }
1116
1142
  /**
1117
1143
  * Does what load() does, but synchronously returns
@@ -1119,10 +1145,9 @@ class H extends m {
1119
1145
  * resolves when the PHP instance is ready.
1120
1146
  *
1121
1147
  * @see load
1122
- * @inheritdoc load
1123
1148
  */
1124
1149
  static loadSync(e, r = {}) {
1125
- const n = new H(void 0, r.requestHandler), a = (async () => {
1150
+ const n = new A(void 0, r.requestHandler), a = (async () => {
1126
1151
  const i = await Promise.all([
1127
1152
  we(e),
1128
1153
  ...r.dataModules || []
@@ -1145,11 +1170,11 @@ class H extends m {
1145
1170
  };
1146
1171
  }
1147
1172
  }
1148
- const d = /* @__PURE__ */ new WeakMap();
1149
- class ke {
1173
+ const h = /* @__PURE__ */ new WeakMap();
1174
+ class xe {
1150
1175
  /** @inheritDoc */
1151
1176
  constructor(e, r) {
1152
- d.set(this, {
1177
+ h.set(this, {
1153
1178
  php: e,
1154
1179
  monitor: r
1155
1180
  }), this.absoluteUrl = Promise.resolve(
@@ -1160,66 +1185,70 @@ class ke {
1160
1185
  }
1161
1186
  /** @inheritDoc @php-wasm/web!PHPRequestHandler.pathToInternalUrl */
1162
1187
  async pathToInternalUrl(e) {
1163
- return d.get(this).php.requestHandler.server.pathToInternalUrl(e);
1188
+ return h.get(this).php.requestHandler.server.pathToInternalUrl(e);
1164
1189
  }
1165
1190
  /** @inheritDoc @php-wasm/web!PHPRequestHandler.internalUrlToPath */
1166
1191
  async internalUrlToPath(e) {
1167
- return d.get(this).php.requestHandler.server.internalUrlToPath(e);
1192
+ return h.get(this).php.requestHandler.server.internalUrlToPath(e);
1168
1193
  }
1169
1194
  async onDownloadProgress(e) {
1170
- d.get(this).monitor?.addEventListener("progress", e);
1195
+ h.get(this).monitor?.addEventListener("progress", e);
1171
1196
  }
1172
1197
  /** @inheritDoc @php-wasm/web!PHPRequestHandler.request */
1173
1198
  request(e, r) {
1174
- return d.get(this).php.request(e, r);
1199
+ return h.get(this).php.request(e, r);
1175
1200
  }
1176
1201
  /** @inheritDoc @php-wasm/web!PHP.run */
1177
1202
  async run(e) {
1178
- return d.get(this).php.run(e);
1203
+ return h.get(this).php.run(e);
1179
1204
  }
1180
1205
  /** @inheritDoc @php-wasm/web!PHP.chdir */
1181
1206
  chdir(e) {
1182
- return d.get(this).php.chdir(e);
1207
+ return h.get(this).php.chdir(e);
1183
1208
  }
1184
1209
  /** @inheritDoc @php-wasm/web!PHP.setPhpIniPath */
1185
1210
  setPhpIniPath(e) {
1186
- return d.get(this).php.setPhpIniPath(e);
1211
+ return h.get(this).php.setPhpIniPath(e);
1187
1212
  }
1188
1213
  /** @inheritDoc @php-wasm/web!PHP.setPhpIniEntry */
1189
1214
  setPhpIniEntry(e, r) {
1190
- d.get(this).php.setPhpIniEntry(e, r);
1215
+ h.get(this).php.setPhpIniEntry(e, r);
1216
+ }
1217
+ /** @inheritDoc @php-wasm/web!PHP.mkdir */
1218
+ mkdir(e) {
1219
+ h.get(this).php.mkdir(e);
1191
1220
  }
1192
1221
  /** @inheritDoc @php-wasm/web!PHP.mkdirTree */
1193
1222
  mkdirTree(e) {
1194
- d.get(this).php.mkdirTree(e);
1223
+ h.get(this).php.mkdirTree(e);
1195
1224
  }
1196
1225
  /** @inheritDoc @php-wasm/web!PHP.readFileAsText */
1197
1226
  async readFileAsText(e) {
1198
- return d.get(this).php.readFileAsText(e);
1227
+ return h.get(this).php.readFileAsText(e);
1199
1228
  }
1200
1229
  /** @inheritDoc @php-wasm/web!PHP.readFileAsBuffer */
1201
1230
  async readFileAsBuffer(e) {
1202
- return d.get(this).php.readFileAsBuffer(e);
1231
+ return h.get(this).php.readFileAsBuffer(e);
1203
1232
  }
1204
1233
  /** @inheritDoc @php-wasm/web!PHP.writeFile */
1205
1234
  writeFile(e, r) {
1206
- d.get(this).php.writeFile(e, r);
1235
+ h.get(this).php.writeFile(e, r);
1207
1236
  }
1208
1237
  /** @inheritDoc @php-wasm/web!PHP.unlink */
1209
1238
  unlink(e) {
1210
- d.get(this).php.unlink(e);
1239
+ h.get(this).php.unlink(e);
1211
1240
  }
1212
1241
  /** @inheritDoc @php-wasm/web!PHP.listFiles */
1213
1242
  async listFiles(e) {
1214
- return d.get(this).php.listFiles(e);
1243
+ return h.get(this).php.listFiles(e);
1215
1244
  }
1216
1245
  /** @inheritDoc @php-wasm/web!PHP.isDir */
1217
1246
  async isDir(e) {
1218
- return d.get(this).php.isDir(e);
1247
+ return h.get(this).php.isDir(e);
1219
1248
  }
1220
1249
  /** @inheritDoc @php-wasm/web!PHP.fileExists */
1221
1250
  async fileExists(e) {
1222
- return d.get(this).php.fileExists(e);
1251
+ return h.get(this).php.fileExists(e);
1223
1252
  }
1224
1253
  }
1225
1254
  function Pe(t, e) {
@@ -1229,7 +1258,7 @@ function Pe(t, e) {
1229
1258
  response: e
1230
1259
  };
1231
1260
  }
1232
- async function xe(t, e, r, n) {
1261
+ async function _e(t, e, r, n) {
1233
1262
  const s = navigator.serviceWorker;
1234
1263
  if (!s)
1235
1264
  throw new Error("Service workers are not supported in this browser.");
@@ -1280,10 +1309,10 @@ function Te() {
1280
1309
  t[n] = r;
1281
1310
  }), t;
1282
1311
  }
1283
- const Fe = function() {
1312
+ const Ce = function() {
1284
1313
  return navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
1285
1314
  }();
1286
- async function Ce(t, e = "webworker", r = {}) {
1315
+ async function Fe(t, e = "webworker", r = {}) {
1287
1316
  if (t = Ee(t, r), e === "webworker")
1288
1317
  return new Worker(t, { type: "module" });
1289
1318
  if (e === "iframe")
@@ -1306,18 +1335,18 @@ async function Re(t) {
1306
1335
  }
1307
1336
  export {
1308
1337
  Y as LatestSupportedPHPVersion,
1309
- H as PHP,
1338
+ A as PHP,
1310
1339
  K as PHPBrowser,
1311
- ke as PHPClient,
1340
+ xe as PHPClient,
1312
1341
  ee as PHPRequestHandler,
1313
1342
  W as SupportedPHPVersions,
1314
- ve as SupportedPHPVersionsList,
1315
- Se as consumeAPI,
1316
- _e as exposeAPI,
1343
+ Se as SupportedPHPVersionsList,
1344
+ ve as consumeAPI,
1345
+ ke as exposeAPI,
1317
1346
  we as getPHPLoaderModule,
1318
1347
  oe as loadPHPRuntime,
1319
1348
  Te as parseWorkerStartupOptions,
1320
- Fe as recommendedWorkerBackend,
1321
- xe as registerServiceWorker,
1322
- Ce as spawnPHPWorkerThread
1349
+ Ce as recommendedWorkerBackend,
1350
+ _e as registerServiceWorker,
1351
+ Fe as spawnPHPWorkerThread
1323
1352
  };
package/index.d.ts CHANGED
@@ -2,11 +2,7 @@
2
2
 
3
3
  import * as Comlink from 'comlink';
4
4
 
5
- /**
6
- * PHP response. Body is an `ArrayBuffer` because it can
7
- * contain binary data.
8
- */
9
- export declare class PHPResponse {
5
+ export interface PHPResponseData {
10
6
  /**
11
7
  * Response headers.
12
8
  */
@@ -15,7 +11,7 @@ export declare class PHPResponse {
15
11
  * Response body. Contains the output from `echo`,
16
12
  * `print`, inline HTML etc.
17
13
  */
18
- private readonly body;
14
+ readonly bytes: ArrayBuffer;
19
15
  /**
20
16
  * Stderr contents, if any.
21
17
  */
@@ -29,7 +25,28 @@ export declare class PHPResponse {
29
25
  * Response HTTP status code, e.g. 200.
30
26
  */
31
27
  readonly httpStatusCode: number;
28
+ }
29
+ /**
30
+ * PHP response. Body is an `ArrayBuffer` because it can
31
+ * contain binary data.
32
+ *
33
+ * This type is used in Comlink.transferHandlers.set('PHPResponse', { ... })
34
+ * so be sure to update that if you change this type.
35
+ */
36
+ export declare class PHPResponse implements PHPResponseData {
37
+ /** @inheritDoc */
38
+ readonly headers: Record<string, string[]>;
39
+ /** @inheritDoc */
40
+ readonly bytes: ArrayBuffer;
41
+ /** @inheritDoc */
42
+ readonly errors: string;
43
+ /** @inheritDoc */
44
+ readonly exitCode: number;
45
+ /** @inheritDoc */
46
+ readonly httpStatusCode: number;
32
47
  constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
48
+ static fromRawData(data: PHPResponseData): PHPResponse;
49
+ toRawData(): PHPResponseData;
33
50
  /**
34
51
  * Response body as JSON.
35
52
  */
@@ -38,20 +55,36 @@ export declare class PHPResponse {
38
55
  * Response body as text.
39
56
  */
40
57
  get text(): string;
58
+ }
59
+ export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
60
+ export type PHPRequestHeaders = Record<string, string>;
61
+ export interface PHPRequest {
41
62
  /**
42
- * Response body as bytes.
63
+ * Request method. Default: `GET`.
64
+ */
65
+ method?: HTTPMethod;
66
+ /**
67
+ * Request path or absolute URL.
43
68
  */
44
- get bytes(): ArrayBuffer;
45
- }
46
- export type PHPRequest = Pick<PHPRunOptions, "method" | "headers"> & {
47
69
  url: string;
70
+ /**
71
+ * Request headers.
72
+ */
73
+ headers?: PHPRequestHeaders;
74
+ /**
75
+ * Uploaded files
76
+ */
48
77
  files?: Record<string, File>;
49
- } & ((Pick<PHPRunOptions, "body"> & {
50
- formData?: never;
51
- }) | {
52
- body?: never;
53
- formData: Record<string, unknown>;
54
- });
78
+ /**
79
+ * Request body without the files.
80
+ */
81
+ body?: string;
82
+ /**
83
+ * Form data. If set, the request body will be ignored and
84
+ * the content-type header will be set to `application/x-www-form-urlencoded`.
85
+ */
86
+ formData?: Record<string, unknown>;
87
+ }
55
88
  export interface PHPRequestHandlerConfiguration {
56
89
  /**
57
90
  * The directory in the PHP filesystem where the server will look
@@ -210,7 +243,6 @@ export declare class PHPBrowser implements WithRequestHandler {
210
243
  request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
211
244
  }
212
245
  export type RuntimeType = "NODE" | "WEB" | "WORKER";
213
- export type PHPRequestHeaders = Record<string, string>;
214
246
  export interface FileInfo {
215
247
  key: string;
216
248
  name: string;
@@ -233,7 +265,7 @@ export interface PHPRunOptions {
233
265
  /**
234
266
  * Request method. Default: `GET`.
235
267
  */
236
- method?: "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
268
+ method?: HTTPMethod;
237
269
  /**
238
270
  * Request headers.
239
271
  */
@@ -272,11 +304,11 @@ export interface WithNodeFilesystem {
272
304
  /**
273
305
  * Mounts a Node.js filesystem to a given path in the PHP filesystem.
274
306
  *
275
- * @param settings - The Node.js filesystem settings.
276
- * @param path - The path to mount the filesystem to.
307
+ * @param localPath - The path of a real local directory you want to mount.
308
+ * @param virtualFSPath - Where to mount it in the virtual filesystem.
277
309
  * @see {@link https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.mount}
278
310
  */
279
- mount(settings: any, path: string): void;
311
+ mount(localPath: string | MountSettings, virtualFSPath: string): void;
280
312
  }
281
313
  export interface WithFilesystem {
282
314
  /**
@@ -286,6 +318,10 @@ export interface WithFilesystem {
286
318
  *
287
319
  * @param path - The directory path to create.
288
320
  */
321
+ mkdir(path: string): void;
322
+ /**
323
+ * @deprecated Use mkdir instead.
324
+ */
289
325
  mkdirTree(path: string): void;
290
326
  /**
291
327
  * Reads a file from the PHP filesystem and returns it as a string.
@@ -448,6 +484,8 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
448
484
  setSkipShebang(shouldSkip: boolean): void;
449
485
  addServerGlobalEntry(key: string, value: string): void;
450
486
  /** @inheritDoc */
487
+ mkdir(path: string): void;
488
+ /** @inheritDoc */
451
489
  mkdirTree(path: string): void;
452
490
  /** @inheritDoc */
453
491
  readFileAsText(path: string): string;
@@ -464,7 +502,7 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
464
502
  /** @inheritDoc */
465
503
  fileExists(path: string): boolean;
466
504
  /** @inheritDoc */
467
- mount(settings: MountSettings, path: string): void;
505
+ mount(localPath: string | MountSettings, virtualFSPath: string): void;
468
506
  }
469
507
  /**
470
508
  * Output of the PHP.wasm runtime.
@@ -668,7 +706,6 @@ export declare class PHP extends BasePHP {
668
706
  * resolves when the PHP instance is ready.
669
707
  *
670
708
  * @see load
671
- * @inheritdoc load
672
709
  */
673
710
  static loadSync(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): {
674
711
  php: PHP;
@@ -712,6 +749,8 @@ export declare class PHPClient implements Promisify<WithPHPIniBindings & WithFil
712
749
  setPhpIniPath(path: string): void;
713
750
  /** @inheritDoc @php-wasm/web!PHP.setPhpIniEntry */
714
751
  setPhpIniEntry(key: string, value: string): void;
752
+ /** @inheritDoc @php-wasm/web!PHP.mkdir */
753
+ mkdir(path: string): void;
715
754
  /** @inheritDoc @php-wasm/web!PHP.mkdirTree */
716
755
  mkdirTree(path: string): void;
717
756
  /** @inheritDoc @php-wasm/web!PHP.readFileAsText */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/web",
3
- "version": "0.1.18",
3
+ "version": "0.1.20",
4
4
  "description": "PHP.wasm for the web",
5
5
  "repository": {
6
6
  "type": "git",
@@ -29,5 +29,5 @@
29
29
  "type": "module",
30
30
  "main": "index.js",
31
31
  "types": "index.d.ts",
32
- "gitHead": "2de8f9182b249b7e87694efaa06e7f25b64b7bb3"
32
+ "gitHead": "bbe56ef04fa9740506efed428ef8c89de7223d96"
33
33
  }