@php-wasm/universal
Advanced tools
Comparing version 0.1.45 to 0.1.46
153
index.js
@@ -53,3 +53,3 @@ const v = Symbol("error"), _ = Symbol("message"); | ||
return; | ||
const i = L( | ||
const i = $( | ||
o, | ||
@@ -75,5 +75,5 @@ s.lastAsyncifyStackSource?.stack | ||
} | ||
function L(s, e) { | ||
function $(s, e) { | ||
if (s.message === "unreachable") { | ||
let t = $; | ||
let t = L; | ||
e || (t += ` | ||
@@ -94,3 +94,3 @@ | ||
} | ||
const $ = ` | ||
const L = ` | ||
"unreachable" WASM instruction executed. | ||
@@ -149,3 +149,3 @@ | ||
} | ||
class y { | ||
class g { | ||
constructor(e, t, r, n = "", o = 0) { | ||
@@ -155,3 +155,3 @@ this.httpStatusCode = e, this.headers = t, this.bytes = r, this.exitCode = o, this.errors = n; | ||
static fromRawData(e) { | ||
return new y( | ||
return new g( | ||
e.httpStatusCode, | ||
@@ -186,3 +186,3 @@ e.headers, | ||
} | ||
const F = [ | ||
const C = [ | ||
"8.2", | ||
@@ -197,3 +197,3 @@ "8.1", | ||
"5.6" | ||
], ee = F[0], te = F; | ||
], ee = C[0], te = C; | ||
class q { | ||
@@ -394,3 +394,3 @@ #e; | ||
if (!this.php.fileExists(t)) | ||
return new y( | ||
return new g( | ||
404, | ||
@@ -401,3 +401,3 @@ {}, | ||
const r = this.php.readFileAsBuffer(t); | ||
return new y( | ||
return new g( | ||
200, | ||
@@ -437,9 +437,9 @@ { | ||
n = "POST"; | ||
for (const c in e.files) { | ||
const d = e.files[c]; | ||
for (const u in e.files) { | ||
const m = e.files[u]; | ||
i.push({ | ||
key: c, | ||
name: d.name, | ||
type: d.type, | ||
data: new Uint8Array(await d.arrayBuffer()) | ||
key: u, | ||
name: m.name, | ||
type: m.type, | ||
data: new Uint8Array(await m.arrayBuffer()) | ||
}); | ||
@@ -452,5 +452,16 @@ } | ||
let l; | ||
return e.formData !== void 0 ? (n = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams( | ||
e.formData !== void 0 ? (n = "POST", o["content-type"] = o["content-type"] || "application/x-www-form-urlencoded", l = new URLSearchParams( | ||
e.formData | ||
).toString()) : l = e.body, await this.php.run({ | ||
).toString()) : l = e.body; | ||
let c; | ||
try { | ||
c = this.#u(t.pathname); | ||
} catch { | ||
return new g( | ||
404, | ||
{}, | ||
new TextEncoder().encode("404 File not found") | ||
); | ||
} | ||
return await this.php.run({ | ||
relativeUri: z( | ||
@@ -464,3 +475,3 @@ k(t), | ||
fileInfos: i, | ||
scriptPath: this.#u(t.pathname), | ||
scriptPath: c, | ||
headers: o | ||
@@ -478,2 +489,3 @@ }); | ||
* @param requestedPath - The requested pathname. | ||
* @throws {Error} If the requested path doesn't exist. | ||
* @returns The resolved filesystem path. | ||
@@ -485,3 +497,7 @@ */ | ||
const r = `${this.#e}${t}`; | ||
return this.php.fileExists(r) ? r : `${this.#e}/index.php`; | ||
if (this.php.fileExists(r)) | ||
return r; | ||
if (!this.php.fileExists(`${this.#e}/index.php`)) | ||
throw new Error(`File not found: ${r}`); | ||
return `${this.#e}/index.php`; | ||
} | ||
@@ -497,6 +513,6 @@ } | ||
\r | ||
`), l = o.substring(0, i).trim(), c = o.substring(i + 4).trim(), d = l.match(/name="([^"]+)"/); | ||
if (d) { | ||
const g = d[1]; | ||
e[g] = c; | ||
`), l = o.substring(0, i).trim(), c = o.substring(i + 4).trim(), u = l.match(/name="([^"]+)"/); | ||
if (u) { | ||
const m = u[1]; | ||
e[m] = c; | ||
} | ||
@@ -545,3 +561,3 @@ }), e; | ||
} | ||
const C = { | ||
const F = { | ||
0: "No error occurred. System call completed successfully.", | ||
@@ -633,5 +649,5 @@ 1: "Argument list too long.", | ||
const c = typeof l == "object" ? l?.errno : null; | ||
if (c in C) { | ||
const d = C[c], g = typeof i[0] == "string" ? i[0] : null, U = g !== null ? s.replaceAll("{path}", g) : s; | ||
throw new Error(`${U}: ${d}`, { | ||
if (c in F) { | ||
const u = F[c], m = typeof i[0] == "string" ? i[0] : null, U = m !== null ? s.replaceAll("{path}", m) : s; | ||
throw new Error(`${U}: ${u}`, { | ||
cause: l | ||
@@ -685,4 +701,4 @@ }); | ||
}; | ||
const h = "string", m = "number", a = Symbol("__private__dont__use"); | ||
class u { | ||
const h = "string", y = "number", a = Symbol("__private__dont__use"); | ||
class d { | ||
/** | ||
@@ -833,3 +849,3 @@ * Initializes a PHP runtime. | ||
null, | ||
[m], | ||
[y], | ||
[r] | ||
@@ -860,3 +876,3 @@ ), (t === "https" || !t && r === 443) && this.addServerGlobalEntry("HTTPS", "on"); | ||
null, | ||
[m], | ||
[y], | ||
[parseInt(e["content-length"], 10)] | ||
@@ -879,3 +895,3 @@ ); | ||
null, | ||
[m], | ||
[y], | ||
[new TextEncoder().encode(e).length] | ||
@@ -920,3 +936,3 @@ ); | ||
null, | ||
[h, h, h, h, m, m], | ||
[h, h, h, h, y, y], | ||
[t, r, n, i, l, o.byteLength] | ||
@@ -936,6 +952,6 @@ ); | ||
try { | ||
e = await new Promise(async (o, i) => { | ||
t = (l) => { | ||
const c = new Error("Rethrown"); | ||
c.cause = l.error, c.betterMessage = l.message, i(c); | ||
e = await new Promise((o, i) => { | ||
t = (c) => { | ||
const u = new Error("Rethrown"); | ||
u.cause = c.error, u.betterMessage = c.message, i(u); | ||
}, this.#s?.addEventListener( | ||
@@ -945,24 +961,13 @@ "error", | ||
); | ||
try { | ||
o( | ||
/** | ||
* This is awkward, but Asyncify makes wasm_sapi_handle_request return | ||
* Promise<Promise<number>>. | ||
* | ||
* @TODO: Determine whether this is a bug in emscripten or in our code. | ||
*/ | ||
await await this[a].ccall( | ||
"wasm_sapi_handle_request", | ||
m, | ||
[], | ||
[] | ||
) | ||
); | ||
} catch (l) { | ||
i(l); | ||
} | ||
const l = this[a].ccall( | ||
"wasm_sapi_handle_request", | ||
y, | ||
[], | ||
[] | ||
); | ||
return l instanceof Promise ? l.then(o, i) : o(l); | ||
}); | ||
} catch (o) { | ||
for (const d in this) | ||
typeof this[d] == "function" && (this[d] = () => { | ||
for (const u in this) | ||
typeof this[u] == "function" && (this[u] = () => { | ||
throw new Error( | ||
@@ -979,3 +984,3 @@ "PHP runtime has crashed – see the earlier error for details." | ||
const { headers: r, httpStatusCode: n } = this.#n(); | ||
return new y( | ||
return new g( | ||
n, | ||
@@ -1041,33 +1046,33 @@ r, | ||
p('Could not create directory "{path}"') | ||
], u.prototype, "mkdir", 1); | ||
], d.prototype, "mkdir", 1); | ||
f([ | ||
p('Could not create directory "{path}"') | ||
], u.prototype, "mkdirTree", 1); | ||
], d.prototype, "mkdirTree", 1); | ||
f([ | ||
p('Could not read "{path}"') | ||
], u.prototype, "readFileAsText", 1); | ||
], d.prototype, "readFileAsText", 1); | ||
f([ | ||
p('Could not read "{path}"') | ||
], u.prototype, "readFileAsBuffer", 1); | ||
], d.prototype, "readFileAsBuffer", 1); | ||
f([ | ||
p('Could not write to "{path}"') | ||
], u.prototype, "writeFile", 1); | ||
], d.prototype, "writeFile", 1); | ||
f([ | ||
p('Could not unlink "{path}"') | ||
], u.prototype, "unlink", 1); | ||
], d.prototype, "unlink", 1); | ||
f([ | ||
p('Could not move "{path}"') | ||
], u.prototype, "mv", 1); | ||
], d.prototype, "mv", 1); | ||
f([ | ||
p('Could not remove directory "{path}"') | ||
], u.prototype, "rmdir", 1); | ||
], d.prototype, "rmdir", 1); | ||
f([ | ||
p('Could not list files in "{path}"') | ||
], u.prototype, "listFiles", 1); | ||
], d.prototype, "listFiles", 1); | ||
f([ | ||
p('Could not stat "{path}"') | ||
], u.prototype, "isDir", 1); | ||
], d.prototype, "isDir", 1); | ||
f([ | ||
p('Could not stat "{path}"') | ||
], u.prototype, "fileExists", 1); | ||
], d.prototype, "fileExists", 1); | ||
function H(s) { | ||
@@ -1080,3 +1085,3 @@ const e = {}; | ||
function Z(s) { | ||
return !(s instanceof u); | ||
return !(s instanceof d); | ||
} | ||
@@ -1087,3 +1092,3 @@ function se(s) { | ||
export { | ||
u as BasePHP, | ||
d as BasePHP, | ||
j as DEFAULT_BASE_URL, | ||
@@ -1093,4 +1098,4 @@ ee as LatestSupportedPHPVersion, | ||
G as PHPRequestHandler, | ||
y as PHPResponse, | ||
F as SupportedPHPVersions, | ||
g as PHPResponse, | ||
C as SupportedPHPVersions, | ||
te as SupportedPHPVersionsList, | ||
@@ -1097,0 +1102,0 @@ O as UnhandledRejectionsTarget, |
{ | ||
"name": "@php-wasm/universal", | ||
"version": "0.1.45", | ||
"version": "0.1.46", | ||
"description": "PHP.wasm – emscripten bindings for PHP", | ||
@@ -39,3 +39,3 @@ "repository": { | ||
"license": "GPL-2.0-or-later", | ||
"gitHead": "ca75514c17b912dc8b5dc529f6d123295671320a" | ||
"gitHead": "b1e1b4b57b00fb52429f0490af4ccb943f496f74" | ||
} |
Sorry, the diff of this file is not supported yet
74703
1984