@php-wasm/web 0.1.18 → 0.1.19
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-bdd9b9c8.js → index-e5292333.js} +171 -152
- package/index.d.ts +50 -19
- package/package.json +2 -2
|
@@ -8,7 +8,7 @@ const W = [
|
|
|
8
8
|
"7.1",
|
|
9
9
|
"7.0",
|
|
10
10
|
"5.6"
|
|
11
|
-
], Y = W[0],
|
|
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
|
|
109
|
+
class E {
|
|
110
110
|
constructor(e, r, n, s = "", a = 0) {
|
|
111
|
-
this.httpStatusCode = e, this.headers = r, this.
|
|
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.
|
|
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 {
|
|
@@ -138,7 +150,7 @@ class ee {
|
|
|
138
150
|
#n;
|
|
139
151
|
#o;
|
|
140
152
|
#a;
|
|
141
|
-
#
|
|
153
|
+
#l;
|
|
142
154
|
/**
|
|
143
155
|
* @param php - The PHP instance.
|
|
144
156
|
* @param config - Request Handler configuration.
|
|
@@ -150,7 +162,7 @@ class ee {
|
|
|
150
162
|
absoluteUrl: s = location.origin,
|
|
151
163
|
isStaticFilePath: a = () => !1
|
|
152
164
|
} = r;
|
|
153
|
-
this.php = e, this.#e = n, this.#
|
|
165
|
+
this.php = e, this.#e = n, this.#l = a;
|
|
154
166
|
const i = new URL(s);
|
|
155
167
|
this.#r = i.hostname, this.#s = i.port ? Number(i.port) : i.protocol === "https:" ? 443 : 80, this.#t = (i.protocol || "").replace(":", "");
|
|
156
168
|
const o = this.#s !== 443 && this.#s !== 80;
|
|
@@ -214,7 +226,7 @@ class ee {
|
|
|
214
226
|
n.pathname,
|
|
215
227
|
this.#n
|
|
216
228
|
);
|
|
217
|
-
return this.#
|
|
229
|
+
return this.#l(s) ? this.#c(s) : await this.#u(e, n);
|
|
218
230
|
}
|
|
219
231
|
/**
|
|
220
232
|
* Serves a static file from the PHP filesystem.
|
|
@@ -222,16 +234,16 @@ class ee {
|
|
|
222
234
|
* @param path - The requested static file path.
|
|
223
235
|
* @returns The response.
|
|
224
236
|
*/
|
|
225
|
-
#
|
|
237
|
+
#c(e) {
|
|
226
238
|
const r = `${this.#e}${e}`;
|
|
227
239
|
if (!this.php.fileExists(r))
|
|
228
|
-
return new
|
|
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
|
|
246
|
+
return new E(
|
|
235
247
|
200,
|
|
236
248
|
{
|
|
237
249
|
"content-length": [`${n.byteLength}`],
|
|
@@ -263,13 +275,13 @@ class ee {
|
|
|
263
275
|
const a = [];
|
|
264
276
|
if (e.files) {
|
|
265
277
|
s = "POST";
|
|
266
|
-
for (const
|
|
267
|
-
const
|
|
278
|
+
for (const l in e.files) {
|
|
279
|
+
const c = e.files[l];
|
|
268
280
|
a.push({
|
|
269
|
-
key:
|
|
270
|
-
name:
|
|
271
|
-
type:
|
|
272
|
-
data: new Uint8Array(await
|
|
281
|
+
key: l,
|
|
282
|
+
name: c.name,
|
|
283
|
+
type: c.type,
|
|
284
|
+
data: new Uint8Array(await c.arrayBuffer())
|
|
273
285
|
});
|
|
274
286
|
}
|
|
275
287
|
}
|
|
@@ -439,10 +451,10 @@ function g(t = "") {
|
|
|
439
451
|
try {
|
|
440
452
|
return a.apply(this, i);
|
|
441
453
|
} catch (o) {
|
|
442
|
-
const
|
|
443
|
-
if (
|
|
444
|
-
const
|
|
445
|
-
throw new Error(`${p}: ${
|
|
454
|
+
const l = typeof o == "object" ? o?.errno : null;
|
|
455
|
+
if (l in I) {
|
|
456
|
+
const c = I[l], u = typeof i[0] == "string" ? i[0] : null, p = u !== null ? t.replaceAll("{path}", u) : t;
|
|
457
|
+
throw new Error(`${p}: ${c}`, {
|
|
446
458
|
cause: o
|
|
447
459
|
});
|
|
448
460
|
}
|
|
@@ -451,12 +463,12 @@ function g(t = "") {
|
|
|
451
463
|
};
|
|
452
464
|
};
|
|
453
465
|
}
|
|
454
|
-
var re = Object.defineProperty, ne = Object.getOwnPropertyDescriptor,
|
|
466
|
+
var re = Object.defineProperty, ne = Object.getOwnPropertyDescriptor, w = (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",
|
|
471
|
+
const h = "string", y = "number", _ = [], 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 (!
|
|
493
|
+
if (!_[e])
|
|
482
494
|
throw new Error("Invalid PHP runtime id.");
|
|
483
|
-
this.#e =
|
|
495
|
+
this.#e = _[e];
|
|
484
496
|
}
|
|
485
497
|
/** @inheritDoc */
|
|
486
498
|
setPhpIniPath(e) {
|
|
@@ -511,7 +523,7 @@ class m {
|
|
|
511
523
|
host: "example.com:443",
|
|
512
524
|
...ie(e.headers || {})
|
|
513
525
|
};
|
|
514
|
-
if (this.#o(r, e.protocol || "http"), this.#
|
|
526
|
+
if (this.#o(r, e.protocol || "http"), this.#l(n), e.body && this.#c(e.body), e.fileInfos)
|
|
515
527
|
for (const s of e.fileInfos)
|
|
516
528
|
this.#h(s);
|
|
517
529
|
return e.code && this.#d(" ?>" + e.code), await this.#f();
|
|
@@ -572,7 +584,7 @@ class m {
|
|
|
572
584
|
n = parseInt(new URL(e).port, 10);
|
|
573
585
|
} catch {
|
|
574
586
|
}
|
|
575
|
-
(!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this.#e.ccall("wasm_set_request_port", null, [
|
|
587
|
+
(!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this.#e.ccall("wasm_set_request_port", null, [y], [n]), (r === "https" || !r && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
576
588
|
}
|
|
577
589
|
#a(e) {
|
|
578
590
|
this.#e.ccall("wasm_set_request_method", null, [h], [e]);
|
|
@@ -581,11 +593,11 @@ class m {
|
|
|
581
593
|
this.#e.ccall(
|
|
582
594
|
"wasm_set_skip_shebang",
|
|
583
595
|
null,
|
|
584
|
-
[
|
|
596
|
+
[y],
|
|
585
597
|
[e ? 1 : 0]
|
|
586
598
|
);
|
|
587
599
|
}
|
|
588
|
-
#
|
|
600
|
+
#l(e) {
|
|
589
601
|
e.cookie && this.#e.ccall(
|
|
590
602
|
"wasm_set_cookies",
|
|
591
603
|
null,
|
|
@@ -599,7 +611,7 @@ class m {
|
|
|
599
611
|
), e["content-length"] && this.#e.ccall(
|
|
600
612
|
"wasm_set_content_length",
|
|
601
613
|
null,
|
|
602
|
-
[
|
|
614
|
+
[y],
|
|
603
615
|
[parseInt(e["content-length"], 10)]
|
|
604
616
|
);
|
|
605
617
|
for (const r in e)
|
|
@@ -608,11 +620,11 @@ class m {
|
|
|
608
620
|
e[r]
|
|
609
621
|
);
|
|
610
622
|
}
|
|
611
|
-
#
|
|
623
|
+
#c(e) {
|
|
612
624
|
this.#e.ccall("wasm_set_request_body", null, [h], [e]), this.#e.ccall(
|
|
613
625
|
"wasm_set_content_length",
|
|
614
626
|
null,
|
|
615
|
-
[
|
|
627
|
+
[y],
|
|
616
628
|
[e.length]
|
|
617
629
|
);
|
|
618
630
|
}
|
|
@@ -643,7 +655,7 @@ class m {
|
|
|
643
655
|
this.#e.ccall(
|
|
644
656
|
"wasm_add_uploaded_file",
|
|
645
657
|
null,
|
|
646
|
-
[h, h, h, h,
|
|
658
|
+
[h, h, h, h, y, y],
|
|
647
659
|
[r, n, s, i, o, a.byteLength]
|
|
648
660
|
);
|
|
649
661
|
}
|
|
@@ -653,11 +665,11 @@ class m {
|
|
|
653
665
|
async #f() {
|
|
654
666
|
const e = await await this.#e.ccall(
|
|
655
667
|
"wasm_sapi_handle_request",
|
|
656
|
-
|
|
668
|
+
y,
|
|
657
669
|
[],
|
|
658
670
|
[]
|
|
659
671
|
), { headers: r, httpStatusCode: n } = this.#i();
|
|
660
|
-
return new
|
|
672
|
+
return new E(
|
|
661
673
|
n,
|
|
662
674
|
r,
|
|
663
675
|
this.readFileAsBuffer("/tmp/stdout"),
|
|
@@ -711,31 +723,31 @@ class m {
|
|
|
711
723
|
);
|
|
712
724
|
}
|
|
713
725
|
}
|
|
714
|
-
|
|
726
|
+
w([
|
|
715
727
|
g('Could not create directory "{path}"')
|
|
716
728
|
], m.prototype, "mkdirTree", 1);
|
|
717
|
-
|
|
729
|
+
w([
|
|
718
730
|
g('Could not read "{path}"')
|
|
719
731
|
], m.prototype, "readFileAsText", 1);
|
|
720
|
-
|
|
732
|
+
w([
|
|
721
733
|
g('Could not read "{path}"')
|
|
722
734
|
], m.prototype, "readFileAsBuffer", 1);
|
|
723
|
-
|
|
735
|
+
w([
|
|
724
736
|
g('Could not write to "{path}"')
|
|
725
737
|
], m.prototype, "writeFile", 1);
|
|
726
|
-
|
|
738
|
+
w([
|
|
727
739
|
g('Could not unlink "{path}"')
|
|
728
740
|
], m.prototype, "unlink", 1);
|
|
729
|
-
|
|
741
|
+
w([
|
|
730
742
|
g('Could not list files in "{path}"')
|
|
731
743
|
], m.prototype, "listFiles", 1);
|
|
732
|
-
|
|
744
|
+
w([
|
|
733
745
|
g('Could not stat "{path}"')
|
|
734
746
|
], m.prototype, "isDir", 1);
|
|
735
|
-
|
|
747
|
+
w([
|
|
736
748
|
g('Could not stat "{path}"')
|
|
737
749
|
], m.prototype, "fileExists", 1);
|
|
738
|
-
|
|
750
|
+
w([
|
|
739
751
|
g("Could not mount a directory")
|
|
740
752
|
], m.prototype, "mount", 1);
|
|
741
753
|
function ie(t) {
|
|
@@ -746,38 +758,38 @@ function ie(t) {
|
|
|
746
758
|
}
|
|
747
759
|
async function oe(t, e = {}, r = []) {
|
|
748
760
|
let n, s;
|
|
749
|
-
const a = new Promise((
|
|
750
|
-
s =
|
|
751
|
-
}), i = new Promise((
|
|
752
|
-
n =
|
|
761
|
+
const a = new Promise((l) => {
|
|
762
|
+
s = l;
|
|
763
|
+
}), i = new Promise((l) => {
|
|
764
|
+
n = l;
|
|
753
765
|
}), o = t.init(se, {
|
|
754
|
-
onAbort(
|
|
755
|
-
console.error("WASM aborted: "), console.error(
|
|
766
|
+
onAbort(l) {
|
|
767
|
+
console.error("WASM aborted: "), console.error(l);
|
|
756
768
|
},
|
|
757
769
|
ENV: {},
|
|
758
770
|
// Emscripten sometimes prepends a '/' to the path, which
|
|
759
771
|
// breaks vite dev mode. An identity `locateFile` function
|
|
760
772
|
// fixes it.
|
|
761
|
-
locateFile: (
|
|
773
|
+
locateFile: (l) => l,
|
|
762
774
|
...e,
|
|
763
775
|
noInitialRun: !0,
|
|
764
776
|
onRuntimeInitialized() {
|
|
765
777
|
e.onRuntimeInitialized && e.onRuntimeInitialized(), n();
|
|
766
778
|
},
|
|
767
|
-
monitorRunDependencies(
|
|
768
|
-
|
|
779
|
+
monitorRunDependencies(l) {
|
|
780
|
+
l === 0 && (delete o.monitorRunDependencies, s());
|
|
769
781
|
}
|
|
770
782
|
});
|
|
771
|
-
for (const { default:
|
|
772
|
-
|
|
773
|
-
return r.length || s(), await a, await i,
|
|
783
|
+
for (const { default: l } of r)
|
|
784
|
+
l(o);
|
|
785
|
+
return r.length || s(), await a, await i, _.push(o), _.length - 1;
|
|
774
786
|
}
|
|
775
787
|
/**
|
|
776
788
|
* @license
|
|
777
789
|
* Copyright 2019 Google LLC
|
|
778
790
|
* SPDX-License-Identifier: Apache-2.0
|
|
779
791
|
*/
|
|
780
|
-
const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"),
|
|
792
|
+
const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"), le = Symbol("Comlink.releaseProxy"), O = Symbol("Comlink.finalizer"), x = Symbol("Comlink.thrown"), z = (t) => typeof t == "object" && t !== null || typeof t == "function", ce = {
|
|
781
793
|
canHandle: (t) => z(t) && t[D],
|
|
782
794
|
serialize(t) {
|
|
783
795
|
const { port1: e, port2: r } = new MessageChannel();
|
|
@@ -787,7 +799,7 @@ const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"), ce = Symbol(
|
|
|
787
799
|
return t.start(), L(t);
|
|
788
800
|
}
|
|
789
801
|
}, ue = {
|
|
790
|
-
canHandle: (t) => z(t) &&
|
|
802
|
+
canHandle: (t) => z(t) && x in t,
|
|
791
803
|
serialize({ value: t }) {
|
|
792
804
|
let e;
|
|
793
805
|
return t instanceof Error ? e = {
|
|
@@ -802,8 +814,8 @@ const D = Symbol("Comlink.proxy"), ae = Symbol("Comlink.endpoint"), ce = Symbol(
|
|
|
802
814
|
deserialize(t) {
|
|
803
815
|
throw t.isError ? Object.assign(new Error(t.value.message), t.value) : t.value;
|
|
804
816
|
}
|
|
805
|
-
},
|
|
806
|
-
["proxy",
|
|
817
|
+
}, S = /* @__PURE__ */ new Map([
|
|
818
|
+
["proxy", ce],
|
|
807
819
|
["throw", ue]
|
|
808
820
|
]);
|
|
809
821
|
function he(t, e) {
|
|
@@ -820,48 +832,48 @@ function F(t, e = globalThis, r = ["*"]) {
|
|
|
820
832
|
console.warn(`Invalid origin '${s.origin}' for comlink proxy`);
|
|
821
833
|
return;
|
|
822
834
|
}
|
|
823
|
-
const { id: a, type: i, path: o } = Object.assign({ path: [] }, s.data),
|
|
824
|
-
let
|
|
835
|
+
const { id: a, type: i, path: o } = Object.assign({ path: [] }, s.data), l = (s.data.argumentList || []).map(P);
|
|
836
|
+
let c;
|
|
825
837
|
try {
|
|
826
|
-
const u = o.slice(0, -1).reduce((f,
|
|
838
|
+
const u = o.slice(0, -1).reduce((f, R) => f[R], t), p = o.reduce((f, R) => f[R], t);
|
|
827
839
|
switch (i) {
|
|
828
840
|
case "GET":
|
|
829
|
-
|
|
841
|
+
c = p;
|
|
830
842
|
break;
|
|
831
843
|
case "SET":
|
|
832
|
-
u[o.slice(-1)[0]] = P(s.data.value),
|
|
844
|
+
u[o.slice(-1)[0]] = P(s.data.value), c = !0;
|
|
833
845
|
break;
|
|
834
846
|
case "APPLY":
|
|
835
|
-
|
|
847
|
+
c = p.apply(u, l);
|
|
836
848
|
break;
|
|
837
849
|
case "CONSTRUCT":
|
|
838
850
|
{
|
|
839
|
-
const f = new p(...
|
|
840
|
-
|
|
851
|
+
const f = new p(...l);
|
|
852
|
+
c = B(f);
|
|
841
853
|
}
|
|
842
854
|
break;
|
|
843
855
|
case "ENDPOINT":
|
|
844
856
|
{
|
|
845
|
-
const { port1: f, port2:
|
|
846
|
-
F(t,
|
|
857
|
+
const { port1: f, port2: R } = new MessageChannel();
|
|
858
|
+
F(t, R), c = ge(f, [f]);
|
|
847
859
|
}
|
|
848
860
|
break;
|
|
849
861
|
case "RELEASE":
|
|
850
|
-
|
|
862
|
+
c = void 0;
|
|
851
863
|
break;
|
|
852
864
|
default:
|
|
853
865
|
return;
|
|
854
866
|
}
|
|
855
867
|
} catch (u) {
|
|
856
|
-
|
|
868
|
+
c = { value: u, [x]: 0 };
|
|
857
869
|
}
|
|
858
|
-
Promise.resolve(
|
|
859
|
-
const [p, f] =
|
|
860
|
-
e.postMessage(Object.assign(Object.assign({}, p), { id: a }), f), i === "RELEASE" && (e.removeEventListener("message", n),
|
|
870
|
+
Promise.resolve(c).catch((u) => ({ value: u, [x]: 0 })).then((u) => {
|
|
871
|
+
const [p, f] = C(u);
|
|
872
|
+
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
873
|
}).catch((u) => {
|
|
862
|
-
const [p, f] =
|
|
874
|
+
const [p, f] = C({
|
|
863
875
|
value: new TypeError("Unserializable return value"),
|
|
864
|
-
[
|
|
876
|
+
[x]: 0
|
|
865
877
|
});
|
|
866
878
|
e.postMessage(Object.assign(Object.assign({}, p), { id: a }), f);
|
|
867
879
|
});
|
|
@@ -870,87 +882,87 @@ function F(t, e = globalThis, r = ["*"]) {
|
|
|
870
882
|
function de(t) {
|
|
871
883
|
return t.constructor.name === "MessagePort";
|
|
872
884
|
}
|
|
873
|
-
function
|
|
885
|
+
function $(t) {
|
|
874
886
|
de(t) && t.close();
|
|
875
887
|
}
|
|
876
888
|
function L(t, e) {
|
|
877
|
-
return
|
|
889
|
+
return H(t, [], e);
|
|
878
890
|
}
|
|
879
|
-
function
|
|
891
|
+
function v(t) {
|
|
880
892
|
if (t)
|
|
881
893
|
throw new Error("Proxy has been released and is not useable");
|
|
882
894
|
}
|
|
883
|
-
function
|
|
895
|
+
function q(t) {
|
|
884
896
|
return b(t, {
|
|
885
897
|
type: "RELEASE"
|
|
886
898
|
}).then(() => {
|
|
887
|
-
|
|
899
|
+
$(t);
|
|
888
900
|
});
|
|
889
901
|
}
|
|
890
|
-
const k = /* @__PURE__ */ new WeakMap(),
|
|
902
|
+
const k = /* @__PURE__ */ new WeakMap(), T = "FinalizationRegistry" in globalThis && new FinalizationRegistry((t) => {
|
|
891
903
|
const e = (k.get(t) || 0) - 1;
|
|
892
|
-
k.set(t, e), e === 0 &&
|
|
904
|
+
k.set(t, e), e === 0 && q(t);
|
|
893
905
|
});
|
|
894
906
|
function fe(t, e) {
|
|
895
907
|
const r = (k.get(e) || 0) + 1;
|
|
896
|
-
k.set(e, r),
|
|
908
|
+
k.set(e, r), T && T.register(t, e, t);
|
|
897
909
|
}
|
|
898
910
|
function pe(t) {
|
|
899
|
-
|
|
911
|
+
T && T.unregister(t);
|
|
900
912
|
}
|
|
901
|
-
function
|
|
913
|
+
function H(t, e = [], r = function() {
|
|
902
914
|
}) {
|
|
903
915
|
let n = !1;
|
|
904
916
|
const s = new Proxy(r, {
|
|
905
917
|
get(a, i) {
|
|
906
|
-
if (
|
|
918
|
+
if (v(n), i === le)
|
|
907
919
|
return () => {
|
|
908
|
-
pe(s),
|
|
920
|
+
pe(s), q(t), n = !0;
|
|
909
921
|
};
|
|
910
922
|
if (i === "then") {
|
|
911
923
|
if (e.length === 0)
|
|
912
924
|
return { then: () => s };
|
|
913
925
|
const o = b(t, {
|
|
914
926
|
type: "GET",
|
|
915
|
-
path: e.map((
|
|
927
|
+
path: e.map((l) => l.toString())
|
|
916
928
|
}).then(P);
|
|
917
929
|
return o.then.bind(o);
|
|
918
930
|
}
|
|
919
|
-
return
|
|
931
|
+
return H(t, [...e, i]);
|
|
920
932
|
},
|
|
921
933
|
set(a, i, o) {
|
|
922
|
-
|
|
923
|
-
const [
|
|
934
|
+
v(n);
|
|
935
|
+
const [l, c] = C(o);
|
|
924
936
|
return b(t, {
|
|
925
937
|
type: "SET",
|
|
926
938
|
path: [...e, i].map((u) => u.toString()),
|
|
927
|
-
value:
|
|
928
|
-
},
|
|
939
|
+
value: l
|
|
940
|
+
}, c).then(P);
|
|
929
941
|
},
|
|
930
942
|
apply(a, i, o) {
|
|
931
|
-
|
|
932
|
-
const
|
|
933
|
-
if (
|
|
943
|
+
v(n);
|
|
944
|
+
const l = e[e.length - 1];
|
|
945
|
+
if (l === ae)
|
|
934
946
|
return b(t, {
|
|
935
947
|
type: "ENDPOINT"
|
|
936
948
|
}).then(P);
|
|
937
|
-
if (
|
|
938
|
-
return
|
|
939
|
-
const [
|
|
949
|
+
if (l === "bind")
|
|
950
|
+
return H(t, e.slice(0, -1));
|
|
951
|
+
const [c, u] = U(o);
|
|
940
952
|
return b(t, {
|
|
941
953
|
type: "APPLY",
|
|
942
954
|
path: e.map((p) => p.toString()),
|
|
943
|
-
argumentList:
|
|
955
|
+
argumentList: c
|
|
944
956
|
}, u).then(P);
|
|
945
957
|
},
|
|
946
958
|
construct(a, i) {
|
|
947
|
-
|
|
948
|
-
const [o,
|
|
959
|
+
v(n);
|
|
960
|
+
const [o, l] = U(i);
|
|
949
961
|
return b(t, {
|
|
950
962
|
type: "CONSTRUCT",
|
|
951
|
-
path: e.map((
|
|
963
|
+
path: e.map((c) => c.toString()),
|
|
952
964
|
argumentList: o
|
|
953
|
-
},
|
|
965
|
+
}, l).then(P);
|
|
954
966
|
}
|
|
955
967
|
});
|
|
956
968
|
return fe(s, t), s;
|
|
@@ -959,12 +971,12 @@ function me(t) {
|
|
|
959
971
|
return Array.prototype.concat.apply([], t);
|
|
960
972
|
}
|
|
961
973
|
function U(t) {
|
|
962
|
-
const e = t.map(
|
|
974
|
+
const e = t.map(C);
|
|
963
975
|
return [e.map((r) => r[0]), me(e.map((r) => r[1]))];
|
|
964
976
|
}
|
|
965
|
-
const
|
|
977
|
+
const j = /* @__PURE__ */ new WeakMap();
|
|
966
978
|
function ge(t, e) {
|
|
967
|
-
return
|
|
979
|
+
return j.set(t, e), t;
|
|
968
980
|
}
|
|
969
981
|
function B(t) {
|
|
970
982
|
return Object.assign(t, { [D]: !0 });
|
|
@@ -976,8 +988,8 @@ function V(t, e = globalThis, r = "*") {
|
|
|
976
988
|
removeEventListener: e.removeEventListener.bind(e)
|
|
977
989
|
};
|
|
978
990
|
}
|
|
979
|
-
function
|
|
980
|
-
for (const [e, r] of
|
|
991
|
+
function C(t) {
|
|
992
|
+
for (const [e, r] of S)
|
|
981
993
|
if (r.canHandle(t)) {
|
|
982
994
|
const [n, s] = r.serialize(t);
|
|
983
995
|
return [
|
|
@@ -994,34 +1006,34 @@ function T(t) {
|
|
|
994
1006
|
type: "RAW",
|
|
995
1007
|
value: t
|
|
996
1008
|
},
|
|
997
|
-
|
|
1009
|
+
j.get(t) || []
|
|
998
1010
|
];
|
|
999
1011
|
}
|
|
1000
1012
|
function P(t) {
|
|
1001
1013
|
switch (t.type) {
|
|
1002
1014
|
case "HANDLER":
|
|
1003
|
-
return
|
|
1015
|
+
return S.get(t.name).deserialize(t.value);
|
|
1004
1016
|
case "RAW":
|
|
1005
1017
|
return t.value;
|
|
1006
1018
|
}
|
|
1007
1019
|
}
|
|
1008
1020
|
function b(t, e, r) {
|
|
1009
1021
|
return new Promise((n) => {
|
|
1010
|
-
const s =
|
|
1022
|
+
const s = we();
|
|
1011
1023
|
t.addEventListener("message", function a(i) {
|
|
1012
1024
|
!i.data || !i.data.id || i.data.id !== s || (t.removeEventListener("message", a), n(i.data));
|
|
1013
1025
|
}), t.start && t.start(), t.postMessage(Object.assign({ id: s }, e), r);
|
|
1014
1026
|
});
|
|
1015
1027
|
}
|
|
1016
|
-
function
|
|
1028
|
+
function we() {
|
|
1017
1029
|
return new Array(4).fill(0).map(() => Math.floor(Math.random() * Number.MAX_SAFE_INTEGER).toString(16)).join("-");
|
|
1018
1030
|
}
|
|
1019
|
-
function
|
|
1031
|
+
function ve(t) {
|
|
1020
1032
|
G();
|
|
1021
1033
|
const e = t instanceof Worker ? t : V(t);
|
|
1022
1034
|
return L(e);
|
|
1023
1035
|
}
|
|
1024
|
-
function
|
|
1036
|
+
function xe(t, e) {
|
|
1025
1037
|
G();
|
|
1026
1038
|
let r;
|
|
1027
1039
|
const n = new Promise((i) => {
|
|
@@ -1035,7 +1047,7 @@ function _e(t, e) {
|
|
|
1035
1047
|
), [r, a];
|
|
1036
1048
|
}
|
|
1037
1049
|
function G() {
|
|
1038
|
-
|
|
1050
|
+
S.set("EVENT", {
|
|
1039
1051
|
canHandle: (t) => t instanceof CustomEvent,
|
|
1040
1052
|
serialize: (t) => [
|
|
1041
1053
|
{
|
|
@@ -1044,7 +1056,7 @@ function G() {
|
|
|
1044
1056
|
[]
|
|
1045
1057
|
],
|
|
1046
1058
|
deserialize: (t) => t
|
|
1047
|
-
}),
|
|
1059
|
+
}), S.set("FUNCTION", {
|
|
1048
1060
|
canHandle: (t) => typeof t == "function",
|
|
1049
1061
|
serialize(t) {
|
|
1050
1062
|
console.debug("[Comlink][Performance] Proxying a function");
|
|
@@ -1054,6 +1066,14 @@ function G() {
|
|
|
1054
1066
|
deserialize(t) {
|
|
1055
1067
|
return t.start(), L(t);
|
|
1056
1068
|
}
|
|
1069
|
+
}), S.set("PHPResponse", {
|
|
1070
|
+
canHandle: (t) => typeof t == "object" && t !== null && "headers" in t && "bytes" in t && "errors" in t && "exitCode" in t && "httpStatusCode" in t,
|
|
1071
|
+
serialize(t) {
|
|
1072
|
+
return [t.toRawData(), []];
|
|
1073
|
+
},
|
|
1074
|
+
deserialize(t) {
|
|
1075
|
+
return E.fromRawData(t);
|
|
1076
|
+
}
|
|
1057
1077
|
});
|
|
1058
1078
|
}
|
|
1059
1079
|
function J(t) {
|
|
@@ -1074,7 +1094,7 @@ function J(t) {
|
|
|
1074
1094
|
}
|
|
1075
1095
|
});
|
|
1076
1096
|
}
|
|
1077
|
-
async function
|
|
1097
|
+
async function ye(t = Y) {
|
|
1078
1098
|
switch (t) {
|
|
1079
1099
|
case "8.2":
|
|
1080
1100
|
return await import("php_8_2.js");
|
|
@@ -1097,7 +1117,7 @@ async function we(t = Y) {
|
|
|
1097
1117
|
}
|
|
1098
1118
|
throw new Error(`Unsupported PHP version ${t}`);
|
|
1099
1119
|
}
|
|
1100
|
-
class
|
|
1120
|
+
class A extends m {
|
|
1101
1121
|
/**
|
|
1102
1122
|
* Creates a new PHP instance.
|
|
1103
1123
|
*
|
|
@@ -1111,7 +1131,7 @@ class H extends m {
|
|
|
1111
1131
|
* @returns A new PHP instance
|
|
1112
1132
|
*/
|
|
1113
1133
|
static async load(e, r = {}) {
|
|
1114
|
-
return await
|
|
1134
|
+
return await A.loadSync(e, r).phpReady;
|
|
1115
1135
|
}
|
|
1116
1136
|
/**
|
|
1117
1137
|
* Does what load() does, but synchronously returns
|
|
@@ -1119,24 +1139,23 @@ class H extends m {
|
|
|
1119
1139
|
* resolves when the PHP instance is ready.
|
|
1120
1140
|
*
|
|
1121
1141
|
* @see load
|
|
1122
|
-
* @inheritdoc load
|
|
1123
1142
|
*/
|
|
1124
1143
|
static loadSync(e, r = {}) {
|
|
1125
|
-
const n = new
|
|
1144
|
+
const n = new A(void 0, r.requestHandler), a = (async () => {
|
|
1126
1145
|
const i = await Promise.all([
|
|
1127
|
-
|
|
1146
|
+
ye(e),
|
|
1128
1147
|
...r.dataModules || []
|
|
1129
|
-
]), [o, ...
|
|
1148
|
+
]), [o, ...l] = i;
|
|
1130
1149
|
r.downloadMonitor?.setModules(i);
|
|
1131
|
-
const
|
|
1150
|
+
const c = await oe(
|
|
1132
1151
|
o,
|
|
1133
1152
|
{
|
|
1134
1153
|
...r.emscriptenOptions || {},
|
|
1135
1154
|
...r.downloadMonitor?.getEmscriptenOptions() || {}
|
|
1136
1155
|
},
|
|
1137
|
-
|
|
1156
|
+
l
|
|
1138
1157
|
);
|
|
1139
|
-
return n.initializeRuntime(
|
|
1158
|
+
return n.initializeRuntime(c), { dataModules: l };
|
|
1140
1159
|
})();
|
|
1141
1160
|
return {
|
|
1142
1161
|
php: n,
|
|
@@ -1146,7 +1165,7 @@ class H extends m {
|
|
|
1146
1165
|
}
|
|
1147
1166
|
}
|
|
1148
1167
|
const d = /* @__PURE__ */ new WeakMap();
|
|
1149
|
-
class
|
|
1168
|
+
class _e {
|
|
1150
1169
|
/** @inheritDoc */
|
|
1151
1170
|
constructor(e, r) {
|
|
1152
1171
|
d.set(this, {
|
|
@@ -1229,7 +1248,7 @@ function Pe(t, e) {
|
|
|
1229
1248
|
response: e
|
|
1230
1249
|
};
|
|
1231
1250
|
}
|
|
1232
|
-
async function
|
|
1251
|
+
async function ke(t, e, r, n) {
|
|
1233
1252
|
const s = navigator.serviceWorker;
|
|
1234
1253
|
if (!s)
|
|
1235
1254
|
throw new Error("Service workers are not supported in this browser.");
|
|
@@ -1241,14 +1260,14 @@ async function xe(t, e, r, n) {
|
|
|
1241
1260
|
`[window] Reloading the currently registered Service Worker (expected version: ${n}, registered version: ${i})`
|
|
1242
1261
|
);
|
|
1243
1262
|
for (const o of a) {
|
|
1244
|
-
let
|
|
1263
|
+
let l = !1;
|
|
1245
1264
|
try {
|
|
1246
1265
|
await o.update();
|
|
1247
1266
|
} catch {
|
|
1248
|
-
|
|
1267
|
+
l = !0;
|
|
1249
1268
|
}
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1269
|
+
const c = o.waiting || o.installing;
|
|
1270
|
+
c && !l && (i !== null ? c.postMessage("skip-waiting") : l = !0), l && (await o.unregister(), window.location.reload());
|
|
1252
1271
|
}
|
|
1253
1272
|
}
|
|
1254
1273
|
} else
|
|
@@ -1262,7 +1281,7 @@ async function xe(t, e, r, n) {
|
|
|
1262
1281
|
async function(o) {
|
|
1263
1282
|
if (console.debug("Message from ServiceWorker", o), e && o.data.scope !== e)
|
|
1264
1283
|
return;
|
|
1265
|
-
const
|
|
1284
|
+
const l = o.data.args || [], c = o.data.method, u = await t[c](...l);
|
|
1266
1285
|
o.source.postMessage(Pe(o.data.requestId, u));
|
|
1267
1286
|
}
|
|
1268
1287
|
), s.startMessages();
|
|
@@ -1280,10 +1299,10 @@ function Te() {
|
|
|
1280
1299
|
t[n] = r;
|
|
1281
1300
|
}), t;
|
|
1282
1301
|
}
|
|
1283
|
-
const
|
|
1302
|
+
const Ce = function() {
|
|
1284
1303
|
return navigator.userAgent.toLowerCase().indexOf("firefox") > -1 ? "iframe" : "webworker";
|
|
1285
1304
|
}();
|
|
1286
|
-
async function
|
|
1305
|
+
async function Fe(t, e = "webworker", r = {}) {
|
|
1287
1306
|
if (t = Ee(t, r), e === "webworker")
|
|
1288
1307
|
return new Worker(t, { type: "module" });
|
|
1289
1308
|
if (e === "iframe")
|
|
@@ -1306,18 +1325,18 @@ async function Re(t) {
|
|
|
1306
1325
|
}
|
|
1307
1326
|
export {
|
|
1308
1327
|
Y as LatestSupportedPHPVersion,
|
|
1309
|
-
|
|
1328
|
+
A as PHP,
|
|
1310
1329
|
K as PHPBrowser,
|
|
1311
|
-
|
|
1330
|
+
_e as PHPClient,
|
|
1312
1331
|
ee as PHPRequestHandler,
|
|
1313
1332
|
W as SupportedPHPVersions,
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1333
|
+
Se as SupportedPHPVersionsList,
|
|
1334
|
+
ve as consumeAPI,
|
|
1335
|
+
xe as exposeAPI,
|
|
1336
|
+
ye as getPHPLoaderModule,
|
|
1318
1337
|
oe as loadPHPRuntime,
|
|
1319
1338
|
Te as parseWorkerStartupOptions,
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1339
|
+
Ce as recommendedWorkerBackend,
|
|
1340
|
+
ke as registerServiceWorker,
|
|
1341
|
+
Fe as spawnPHPWorkerThread
|
|
1323
1342
|
};
|
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
|
-
|
|
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
|
-
*
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
body?:
|
|
53
|
-
|
|
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?:
|
|
268
|
+
method?: HTTPMethod;
|
|
237
269
|
/**
|
|
238
270
|
* Request headers.
|
|
239
271
|
*/
|
|
@@ -668,7 +700,6 @@ export declare class PHP extends BasePHP {
|
|
|
668
700
|
* resolves when the PHP instance is ready.
|
|
669
701
|
*
|
|
670
702
|
* @see load
|
|
671
|
-
* @inheritdoc load
|
|
672
703
|
*/
|
|
673
704
|
static loadSync(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): {
|
|
674
705
|
php: PHP;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.19",
|
|
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": "
|
|
32
|
+
"gitHead": "ce0d93a79ad524677200b7e956ae1543d774696e"
|
|
33
33
|
}
|