@php-wasm/web 0.1.45 → 0.1.46
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.
|
@@ -143,12 +143,12 @@ function fe(t) {
|
|
|
143
143
|
return [];
|
|
144
144
|
}
|
|
145
145
|
}
|
|
146
|
-
class
|
|
146
|
+
class b {
|
|
147
147
|
constructor(e, r, n, s = "", o = 0) {
|
|
148
148
|
this.httpStatusCode = e, this.headers = r, this.bytes = n, this.exitCode = o, this.errors = s;
|
|
149
149
|
}
|
|
150
150
|
static fromRawData(e) {
|
|
151
|
-
return new
|
|
151
|
+
return new b(
|
|
152
152
|
e.httpStatusCode,
|
|
153
153
|
e.headers,
|
|
154
154
|
e.bytes,
|
|
@@ -384,13 +384,13 @@ class be {
|
|
|
384
384
|
#c(e) {
|
|
385
385
|
const r = `${this.#e}${e}`;
|
|
386
386
|
if (!this.php.fileExists(r))
|
|
387
|
-
return new
|
|
387
|
+
return new b(
|
|
388
388
|
404,
|
|
389
389
|
{},
|
|
390
390
|
new TextEncoder().encode("404 File not found")
|
|
391
391
|
);
|
|
392
392
|
const n = this.php.readFileAsBuffer(r);
|
|
393
|
-
return new
|
|
393
|
+
return new b(
|
|
394
394
|
200,
|
|
395
395
|
{
|
|
396
396
|
"content-length": [`${n.byteLength}`],
|
|
@@ -425,13 +425,13 @@ class be {
|
|
|
425
425
|
}, i = [];
|
|
426
426
|
if (e.files && Object.keys(e.files).length) {
|
|
427
427
|
s = "POST";
|
|
428
|
-
for (const
|
|
429
|
-
const
|
|
428
|
+
for (const c in e.files) {
|
|
429
|
+
const h = e.files[c];
|
|
430
430
|
i.push({
|
|
431
|
-
key:
|
|
432
|
-
name:
|
|
433
|
-
type:
|
|
434
|
-
data: new Uint8Array(await
|
|
431
|
+
key: c,
|
|
432
|
+
name: h.name,
|
|
433
|
+
type: h.type,
|
|
434
|
+
data: new Uint8Array(await h.arrayBuffer())
|
|
435
435
|
});
|
|
436
436
|
}
|
|
437
437
|
o["content-type"]?.startsWith("multipart/form-data") && (e.formData = Ee(
|
|
@@ -439,9 +439,20 @@ class be {
|
|
|
439
439
|
), o["content-type"] = "application/x-www-form-urlencoded", delete e.body);
|
|
440
440
|
}
|
|
441
441
|
let a;
|
|
442
|
-
|
|
442
|
+
e.formData !== void 0 ? (s = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", a = new URLSearchParams(
|
|
443
443
|
e.formData
|
|
444
|
-
).toString()) : a = e.body
|
|
444
|
+
).toString()) : a = e.body;
|
|
445
|
+
let l;
|
|
446
|
+
try {
|
|
447
|
+
l = this.#h(r.pathname);
|
|
448
|
+
} catch {
|
|
449
|
+
return new b(
|
|
450
|
+
404,
|
|
451
|
+
{},
|
|
452
|
+
new TextEncoder().encode("404 File not found")
|
|
453
|
+
);
|
|
454
|
+
}
|
|
455
|
+
return await this.php.run({
|
|
445
456
|
relativeUri: Pe(
|
|
446
457
|
j(r),
|
|
447
458
|
this.#s
|
|
@@ -450,7 +461,7 @@ class be {
|
|
|
450
461
|
method: e.method || s,
|
|
451
462
|
body: a,
|
|
452
463
|
fileInfos: i,
|
|
453
|
-
scriptPath:
|
|
464
|
+
scriptPath: l,
|
|
454
465
|
headers: o
|
|
455
466
|
});
|
|
456
467
|
} finally {
|
|
@@ -463,13 +474,18 @@ class be {
|
|
|
463
474
|
* Fall back to index.php as if there was a url rewriting rule in place.
|
|
464
475
|
*
|
|
465
476
|
* @param requestedPath - The requested pathname.
|
|
477
|
+
* @throws {Error} If the requested path doesn't exist.
|
|
466
478
|
* @returns The resolved filesystem path.
|
|
467
479
|
*/
|
|
468
480
|
#h(e) {
|
|
469
481
|
let r = G(e, this.#s);
|
|
470
482
|
r.includes(".php") ? r = r.split(".php")[0] + ".php" : (r.endsWith("/") || (r += "/"), r.endsWith("index.php") || (r += "index.php"));
|
|
471
483
|
const n = `${this.#e}${r}`;
|
|
472
|
-
|
|
484
|
+
if (this.php.fileExists(n))
|
|
485
|
+
return n;
|
|
486
|
+
if (!this.php.fileExists(`${this.#e}/index.php`))
|
|
487
|
+
throw new Error(`File not found: ${n}`);
|
|
488
|
+
return `${this.#e}/index.php`;
|
|
473
489
|
}
|
|
474
490
|
}
|
|
475
491
|
function Ee(t) {
|
|
@@ -665,7 +681,7 @@ var xe = Object.defineProperty, Te = Object.getOwnPropertyDescriptor, w = (t, e,
|
|
|
665
681
|
(i = t[o]) && (s = (n ? i(e, r, s) : i(s)) || s);
|
|
666
682
|
return n && s && xe(e, r, s), s;
|
|
667
683
|
};
|
|
668
|
-
const f = "string",
|
|
684
|
+
const f = "string", E = "number", u = Symbol("__private__dont__use");
|
|
669
685
|
class m {
|
|
670
686
|
/**
|
|
671
687
|
* Initializes a PHP runtime.
|
|
@@ -812,7 +828,7 @@ class m {
|
|
|
812
828
|
(!n || isNaN(n) || n === 80) && (n = r === "https" ? 443 : 80), this[u].ccall(
|
|
813
829
|
"wasm_set_request_port",
|
|
814
830
|
null,
|
|
815
|
-
[
|
|
831
|
+
[E],
|
|
816
832
|
[n]
|
|
817
833
|
), (r === "https" || !r && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
|
|
818
834
|
}
|
|
@@ -838,7 +854,7 @@ class m {
|
|
|
838
854
|
), e["content-length"] && this[u].ccall(
|
|
839
855
|
"wasm_set_content_length",
|
|
840
856
|
null,
|
|
841
|
-
[
|
|
857
|
+
[E],
|
|
842
858
|
[parseInt(e["content-length"], 10)]
|
|
843
859
|
);
|
|
844
860
|
for (const r in e)
|
|
@@ -856,7 +872,7 @@ class m {
|
|
|
856
872
|
), this[u].ccall(
|
|
857
873
|
"wasm_set_content_length",
|
|
858
874
|
null,
|
|
859
|
-
[
|
|
875
|
+
[E],
|
|
860
876
|
[new TextEncoder().encode(e).length]
|
|
861
877
|
);
|
|
862
878
|
}
|
|
@@ -896,7 +912,7 @@ class m {
|
|
|
896
912
|
this[u].ccall(
|
|
897
913
|
"wasm_add_uploaded_file",
|
|
898
914
|
null,
|
|
899
|
-
[f, f, f, f,
|
|
915
|
+
[f, f, f, f, E, E],
|
|
900
916
|
[r, n, s, i, a, o.byteLength]
|
|
901
917
|
);
|
|
902
918
|
}
|
|
@@ -911,32 +927,21 @@ class m {
|
|
|
911
927
|
async #m() {
|
|
912
928
|
let e, r;
|
|
913
929
|
try {
|
|
914
|
-
e = await new Promise(
|
|
915
|
-
r = (
|
|
916
|
-
const
|
|
917
|
-
|
|
930
|
+
e = await new Promise((o, i) => {
|
|
931
|
+
r = (l) => {
|
|
932
|
+
const c = new Error("Rethrown");
|
|
933
|
+
c.cause = l.error, c.betterMessage = l.message, i(c);
|
|
918
934
|
}, this.#n?.addEventListener(
|
|
919
935
|
"error",
|
|
920
936
|
r
|
|
921
937
|
);
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
*/
|
|
930
|
-
await await this[u].ccall(
|
|
931
|
-
"wasm_sapi_handle_request",
|
|
932
|
-
b,
|
|
933
|
-
[],
|
|
934
|
-
[]
|
|
935
|
-
)
|
|
936
|
-
);
|
|
937
|
-
} catch (a) {
|
|
938
|
-
i(a);
|
|
939
|
-
}
|
|
938
|
+
const a = this[u].ccall(
|
|
939
|
+
"wasm_sapi_handle_request",
|
|
940
|
+
E,
|
|
941
|
+
[],
|
|
942
|
+
[]
|
|
943
|
+
);
|
|
944
|
+
return a instanceof Promise ? a.then(o, i) : o(a);
|
|
940
945
|
});
|
|
941
946
|
} catch (o) {
|
|
942
947
|
for (const c in this)
|
|
@@ -952,7 +957,7 @@ class m {
|
|
|
952
957
|
this.#n?.removeEventListener("error", r), this.#r = {};
|
|
953
958
|
}
|
|
954
959
|
const { headers: n, httpStatusCode: s } = this.#s();
|
|
955
|
-
return new
|
|
960
|
+
return new b(
|
|
956
961
|
s,
|
|
957
962
|
n,
|
|
958
963
|
this.readFileAsBuffer("/tmp/stdout"),
|
|
@@ -1159,7 +1164,7 @@ function k(t) {
|
|
|
1159
1164
|
throw new Error("Proxy has been released and is not useable");
|
|
1160
1165
|
}
|
|
1161
1166
|
function ee(t) {
|
|
1162
|
-
return
|
|
1167
|
+
return v(t, {
|
|
1163
1168
|
type: "RELEASE"
|
|
1164
1169
|
}).then(() => {
|
|
1165
1170
|
Z(t);
|
|
@@ -1188,7 +1193,7 @@ function O(t, e = [], r = function() {
|
|
|
1188
1193
|
if (i === "then") {
|
|
1189
1194
|
if (e.length === 0)
|
|
1190
1195
|
return { then: () => s };
|
|
1191
|
-
const a =
|
|
1196
|
+
const a = v(t, {
|
|
1192
1197
|
type: "GET",
|
|
1193
1198
|
path: e.map((l) => l.toString())
|
|
1194
1199
|
}).then(P);
|
|
@@ -1199,7 +1204,7 @@ function O(t, e = [], r = function() {
|
|
|
1199
1204
|
set(o, i, a) {
|
|
1200
1205
|
k(n);
|
|
1201
1206
|
const [l, c] = C(a);
|
|
1202
|
-
return
|
|
1207
|
+
return v(t, {
|
|
1203
1208
|
type: "SET",
|
|
1204
1209
|
path: [...e, i].map((h) => h.toString()),
|
|
1205
1210
|
value: l
|
|
@@ -1209,13 +1214,13 @@ function O(t, e = [], r = function() {
|
|
|
1209
1214
|
k(n);
|
|
1210
1215
|
const l = e[e.length - 1];
|
|
1211
1216
|
if (l === _e)
|
|
1212
|
-
return
|
|
1217
|
+
return v(t, {
|
|
1213
1218
|
type: "ENDPOINT"
|
|
1214
1219
|
}).then(P);
|
|
1215
1220
|
if (l === "bind")
|
|
1216
1221
|
return O(t, e.slice(0, -1));
|
|
1217
1222
|
const [c, h] = Y(a);
|
|
1218
|
-
return
|
|
1223
|
+
return v(t, {
|
|
1219
1224
|
type: "APPLY",
|
|
1220
1225
|
path: e.map((g) => g.toString()),
|
|
1221
1226
|
argumentList: c
|
|
@@ -1224,7 +1229,7 @@ function O(t, e = [], r = function() {
|
|
|
1224
1229
|
construct(o, i) {
|
|
1225
1230
|
k(n);
|
|
1226
1231
|
const [a, l] = Y(i);
|
|
1227
|
-
return
|
|
1232
|
+
return v(t, {
|
|
1228
1233
|
type: "CONSTRUCT",
|
|
1229
1234
|
path: e.map((c) => c.toString()),
|
|
1230
1235
|
argumentList: a
|
|
@@ -1283,7 +1288,7 @@ function P(t) {
|
|
|
1283
1288
|
return t.value;
|
|
1284
1289
|
}
|
|
1285
1290
|
}
|
|
1286
|
-
function
|
|
1291
|
+
function v(t, e, r) {
|
|
1287
1292
|
return new Promise((n) => {
|
|
1288
1293
|
const s = Ne();
|
|
1289
1294
|
t.addEventListener("message", function o(i) {
|
|
@@ -1342,7 +1347,7 @@ function se() {
|
|
|
1342
1347
|
return [t.toRawData(), []];
|
|
1343
1348
|
},
|
|
1344
1349
|
deserialize(t) {
|
|
1345
|
-
return
|
|
1350
|
+
return b.fromRawData(t);
|
|
1346
1351
|
}
|
|
1347
1352
|
}));
|
|
1348
1353
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.46",
|
|
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": "b1e1b4b57b00fb52429f0490af4ccb943f496f74"
|
|
33
33
|
}
|