@php-wasm/fs-journal
Advanced tools
Comparing version 0.5.2 to 0.5.3
882
index.js
@@ -1,13 +0,72 @@ | ||
var re = (r, e, t) => { | ||
var ne = (r, e, t) => { | ||
if (!e.has(r)) | ||
throw TypeError("Cannot " + t); | ||
}; | ||
var a = (r, e, t) => (re(r, e, "read from private field"), t ? t.call(r) : e.get(r)), c = (r, e, t) => { | ||
var a = (r, e, t) => (ne(r, e, "read from private field"), t ? t.call(r) : e.get(r)), c = (r, e, t) => { | ||
if (e.has(r)) | ||
throw TypeError("Cannot add the same private member more than once"); | ||
e instanceof WeakSet ? e.add(r) : e.set(r, t); | ||
}, d = (r, e, t, s) => (re(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t); | ||
var m = (r, e, t) => (re(r, e, "access private method"), t); | ||
const ie = Symbol("error"), ae = Symbol("message"); | ||
class ne extends Event { | ||
}, d = (r, e, t, n) => (ne(r, e, "write to private field"), n ? n.call(r, t) : e.set(r, t), t); | ||
var m = (r, e, t) => (ne(r, e, "access private method"), t); | ||
if (typeof File > "u") { | ||
class r extends Blob { | ||
constructor(t, n, s) { | ||
super(t); | ||
let o; | ||
s != null && s.lastModified && (o = /* @__PURE__ */ new Date()), (!o || isNaN(o.getFullYear())) && (o = /* @__PURE__ */ new Date()), this.lastModifiedDate = o, this.lastModified = o.getMilliseconds(), this.name = n || ""; | ||
} | ||
} | ||
global.File = r; | ||
} | ||
function me(r) { | ||
return new Promise(function(e, t) { | ||
r.onload = r.onerror = function(n) { | ||
r.onload = r.onerror = null, n.type === "load" ? e(r.result) : t(new Error("Failed to read the blob/file")); | ||
}; | ||
}); | ||
} | ||
typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() { | ||
const e = new FileReader(); | ||
return e.readAsArrayBuffer(this), me(e); | ||
}); | ||
typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() { | ||
const e = new FileReader(); | ||
return e.readAsText(this), me(e); | ||
}); | ||
function $e() { | ||
const r = new Uint8Array([1, 2, 3, 4]), t = new File([r], "test").stream(); | ||
try { | ||
return t.getReader({ mode: "byob" }), t.getReader({ mode: "byob" }), !0; | ||
} catch { | ||
return !1; | ||
} | ||
} | ||
(typeof Blob.prototype.stream > "u" || !$e()) && (Blob.prototype.stream = function() { | ||
let r = 0; | ||
const e = this; | ||
return new ReadableStream({ | ||
type: "bytes", | ||
// 0.5 MB seems like a reasonable chunk size, let's adjust | ||
// this if needed. | ||
autoAllocateChunkSize: 512 * 1024, | ||
async pull(t) { | ||
const n = t.byobRequest.view, o = await e.slice(r, r + n.byteLength).arrayBuffer(), i = new Uint8Array(o); | ||
new Uint8Array(n.buffer).set(i); | ||
const u = i.byteLength; | ||
t.byobRequest.respond(u), r += u, r >= e.size && t.close(); | ||
} | ||
}); | ||
}); | ||
if (typeof CustomEvent > "u") { | ||
class r extends Event { | ||
constructor(t, n = {}) { | ||
super(t, n), this.detail = n.detail; | ||
} | ||
initCustomEvent() { | ||
} | ||
} | ||
globalThis.CustomEvent = r; | ||
} | ||
const ae = Symbol("error"), le = Symbol("message"); | ||
class oe extends Event { | ||
/** | ||
@@ -21,18 +80,18 @@ * Create a new `ErrorEvent`. | ||
constructor(e, t = {}) { | ||
super(e), this[ie] = t.error === void 0 ? null : t.error, this[ae] = t.message === void 0 ? "" : t.message; | ||
super(e), this[ae] = t.error === void 0 ? null : t.error, this[le] = t.message === void 0 ? "" : t.message; | ||
} | ||
get error() { | ||
return this[ie]; | ||
return this[ae]; | ||
} | ||
get message() { | ||
return this[ae]; | ||
return this[le]; | ||
} | ||
} | ||
Object.defineProperty(ne.prototype, "error", { enumerable: !0 }); | ||
Object.defineProperty(ne.prototype, "message", { enumerable: !0 }); | ||
const Oe = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ne; | ||
function $e(r) { | ||
Object.defineProperty(oe.prototype, "error", { enumerable: !0 }); | ||
Object.defineProperty(oe.prototype, "message", { enumerable: !0 }); | ||
const Ie = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : oe; | ||
function Ne(r) { | ||
return r instanceof Error ? "exitCode" in r && (r == null ? void 0 : r.exitCode) === 0 || (r == null ? void 0 : r.name) === "ExitStatus" && "status" in r && r.status === 0 : !1; | ||
} | ||
class Ie extends EventTarget { | ||
class Me extends EventTarget { | ||
constructor() { | ||
@@ -51,18 +110,18 @@ super(...arguments), this.listenersCount = 0; | ||
} | ||
function Ne(r) { | ||
function Le(r) { | ||
r.asm = { | ||
...r.asm | ||
}; | ||
const e = new Ie(); | ||
const e = new Me(); | ||
for (const t in r.asm) | ||
if (typeof r.asm[t] == "function") { | ||
const s = r.asm[t]; | ||
r.asm[t] = function(...n) { | ||
const n = r.asm[t]; | ||
r.asm[t] = function(...s) { | ||
var o; | ||
try { | ||
return s(...n); | ||
return n(...s); | ||
} catch (i) { | ||
if (!(i instanceof Error)) | ||
throw i; | ||
const h = Me( | ||
const u = Be( | ||
i, | ||
@@ -73,5 +132,5 @@ (o = r.lastAsyncifyStackSource) == null ? void 0 : o.stack | ||
e.dispatchEvent( | ||
new Oe("error", { | ||
new Ie("error", { | ||
error: i, | ||
message: h | ||
message: u | ||
}) | ||
@@ -81,3 +140,3 @@ ); | ||
} | ||
throw $e(i) || De(h), i; | ||
throw Ne(i) || qe(u), i; | ||
} | ||
@@ -89,8 +148,8 @@ }; | ||
let se = []; | ||
function Le() { | ||
function Ue() { | ||
return se; | ||
} | ||
function Me(r, e) { | ||
function Be(r, e) { | ||
if (r.message === "unreachable") { | ||
let t = Ue; | ||
let t = De; | ||
e || (t += ` | ||
@@ -104,4 +163,4 @@ | ||
); | ||
for (const s of se) | ||
t += ` * ${s} | ||
for (const n of se) | ||
t += ` * ${n} | ||
`; | ||
@@ -112,3 +171,3 @@ return t; | ||
} | ||
const Ue = ` | ||
const De = ` | ||
"unreachable" WASM instruction executed. | ||
@@ -137,13 +196,13 @@ | ||
`, le = "\x1B[41m", We = "\x1B[1m", ce = "\x1B[0m", he = "\x1B[K"; | ||
let ue = !1; | ||
function De(r) { | ||
if (!ue) { | ||
ue = !0, console.log(`${le} | ||
`, ce = "\x1B[41m", We = "\x1B[1m", ue = "\x1B[0m", he = "\x1B[K"; | ||
let de = !1; | ||
function qe(r) { | ||
if (!de) { | ||
de = !0, console.log(`${ce} | ||
${he} | ||
${We} WASM ERROR${ce}${le}`); | ||
${We} WASM ERROR${ue}${ce}`); | ||
for (const e of r.split(` | ||
`)) | ||
console.log(`${he} ${e} `); | ||
console.log(`${ce}`); | ||
console.log(`${ue}`); | ||
} | ||
@@ -155,9 +214,9 @@ } | ||
`).slice(1).map((t) => { | ||
const s = t.trim().substring(3).split(" "); | ||
const n = t.trim().substring(3).split(" "); | ||
return { | ||
fn: s.length >= 2 ? s[0] : "<unknown>", | ||
fn: n.length >= 2 ? n[0] : "<unknown>", | ||
isWasm: t.includes("wasm://") | ||
}; | ||
}).filter( | ||
({ fn: t, isWasm: s }) => s && !t.startsWith("dynCall_") && !t.startsWith("invoke_") | ||
({ fn: t, isWasm: n }) => n && !t.startsWith("dynCall_") && !t.startsWith("invoke_") | ||
).map(({ fn: t }) => t); | ||
@@ -169,5 +228,77 @@ return Array.from(new Set(e)); | ||
} | ||
class ie { | ||
constructor({ concurrency: e }) { | ||
this._running = 0, this.concurrency = e, this.queue = []; | ||
} | ||
get running() { | ||
return this._running; | ||
} | ||
async acquire() { | ||
for (; ; ) | ||
if (this._running >= this.concurrency) | ||
await new Promise((e) => this.queue.push(e)); | ||
else { | ||
this._running++; | ||
let e = !1; | ||
return () => { | ||
e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()()); | ||
}; | ||
} | ||
} | ||
async run(e) { | ||
const t = await this.acquire(); | ||
try { | ||
return await e(); | ||
} finally { | ||
t(); | ||
} | ||
} | ||
} | ||
function B(...r) { | ||
let e = r.join("/"); | ||
const t = e[0] === "/", n = e.substring(e.length - 1) === "/"; | ||
return e = ye(e), !e && !t && (e = "."), e && n && (e += "/"), e; | ||
} | ||
function ze(r) { | ||
if (r === "/") | ||
return "/"; | ||
r = ye(r); | ||
const e = r.lastIndexOf("/"); | ||
return e === -1 ? r : r.substr(e + 1); | ||
} | ||
function ye(r) { | ||
const e = r[0] === "/"; | ||
return r = Ge( | ||
r.split("/").filter((t) => !!t), | ||
!e | ||
).join("/"), (e ? "/" : "") + r.replace(/\/$/, ""); | ||
} | ||
function Ge(r, e) { | ||
let t = 0; | ||
for (let n = r.length - 1; n >= 0; n--) { | ||
const s = r[n]; | ||
s === "." ? r.splice(n, 1) : s === ".." ? (r.splice(n, 1), t++) : t && (r.splice(n, 1), t--); | ||
} | ||
if (e) | ||
for (; t; t--) | ||
r.unshift(".."); | ||
return r; | ||
} | ||
ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () { | ||
const r = this.getReader(); | ||
try { | ||
for (; ; ) { | ||
const { done: e, value: t } = await r.read(); | ||
if (e) | ||
return; | ||
yield t; | ||
} | ||
} finally { | ||
r.releaseLock(); | ||
} | ||
}, ReadableStream.prototype.iterate = // @ts-ignore | ||
ReadableStream.prototype[Symbol.asyncIterator]); | ||
class A { | ||
constructor(e, t, s, n = "", o = 0) { | ||
this.httpStatusCode = e, this.headers = t, this.bytes = s, this.exitCode = o, this.errors = n; | ||
constructor(e, t, n, s = "", o = 0) { | ||
this.httpStatusCode = e, this.headers = t, this.bytes = n, this.exitCode = o, this.errors = s; | ||
} | ||
@@ -205,4 +336,4 @@ static fromRawData(e) { | ||
} | ||
var k, H; | ||
class qe { | ||
var S, H; | ||
class Je { | ||
/** | ||
@@ -213,5 +344,5 @@ * @param server - The PHP server to browse. | ||
constructor(e, t = {}) { | ||
c(this, k, void 0); | ||
c(this, S, void 0); | ||
c(this, H, void 0); | ||
this.requestHandler = e, d(this, k, {}), d(this, H, { | ||
this.requestHandler = e, d(this, S, {}), d(this, H, { | ||
handleRedirects: !1, | ||
@@ -237,3 +368,3 @@ maxRedirects: 4, | ||
async request(e, t = 0) { | ||
const s = await this.requestHandler.request({ | ||
const n = await this.requestHandler.request({ | ||
...e, | ||
@@ -245,5 +376,5 @@ headers: { | ||
}); | ||
if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), a(this, H).handleRedirects && s.headers.location && t < a(this, H).maxRedirects) { | ||
const n = new URL( | ||
s.headers.location[0], | ||
if (n.headers["set-cookie"] && this.setCookies(n.headers["set-cookie"]), a(this, H).handleRedirects && n.headers.location && t < a(this, H).maxRedirects) { | ||
const s = new URL( | ||
n.headers.location[0], | ||
this.requestHandler.absoluteUrl | ||
@@ -253,3 +384,3 @@ ); | ||
{ | ||
url: n.toString(), | ||
url: s.toString(), | ||
method: "GET", | ||
@@ -261,3 +392,3 @@ headers: {} | ||
} | ||
return s; | ||
return n; | ||
} | ||
@@ -285,6 +416,6 @@ /** @inheritDoc */ | ||
continue; | ||
const s = t.indexOf("="), n = t.substring(0, s), o = t.substring(s + 1).split(";")[0]; | ||
a(this, k)[n] = o; | ||
} catch (s) { | ||
console.error(s); | ||
const n = t.indexOf("="), s = t.substring(0, n), o = t.substring(n + 1).split(";")[0]; | ||
a(this, S)[s] = o; | ||
} catch (n) { | ||
console.error(n); | ||
} | ||
@@ -294,78 +425,20 @@ } | ||
const e = []; | ||
for (const t in a(this, k)) | ||
e.push(`${t}=${a(this, k)[t]}`); | ||
for (const t in a(this, S)) | ||
e.push(`${t}=${a(this, S)[t]}`); | ||
return e.join("; "); | ||
} | ||
} | ||
k = new WeakMap(), H = new WeakMap(); | ||
class oe { | ||
constructor({ concurrency: e }) { | ||
this._running = 0, this.concurrency = e, this.queue = []; | ||
} | ||
get running() { | ||
return this._running; | ||
} | ||
async acquire() { | ||
for (; ; ) | ||
if (this._running >= this.concurrency) | ||
await new Promise((e) => this.queue.push(e)); | ||
else { | ||
this._running++; | ||
let e = !1; | ||
return () => { | ||
e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()()); | ||
}; | ||
} | ||
} | ||
async run(e) { | ||
const t = await this.acquire(); | ||
try { | ||
return await e(); | ||
} finally { | ||
t(); | ||
} | ||
} | ||
} | ||
function W(...r) { | ||
let e = r.join("/"); | ||
const t = e[0] === "/", s = e.substring(e.length - 1) === "/"; | ||
return e = me(e), !e && !t && (e = "."), e && s && (e += "/"), e; | ||
} | ||
function Be(r) { | ||
if (r === "/") | ||
return "/"; | ||
r = me(r); | ||
const e = r.lastIndexOf("/"); | ||
return e === -1 ? r : r.substr(e + 1); | ||
} | ||
function me(r) { | ||
const e = r[0] === "/"; | ||
return r = ze( | ||
r.split("/").filter((t) => !!t), | ||
!e | ||
).join("/"), (e ? "/" : "") + r.replace(/\/$/, ""); | ||
} | ||
function ze(r, e) { | ||
let t = 0; | ||
for (let s = r.length - 1; s >= 0; s--) { | ||
const n = r[s]; | ||
n === "." ? r.splice(s, 1) : n === ".." ? (r.splice(s, 1), t++) : t && (r.splice(s, 1), t--); | ||
} | ||
if (e) | ||
for (; t; t--) | ||
r.unshift(".."); | ||
return r; | ||
} | ||
const Ge = "http://example.com"; | ||
function de(r) { | ||
S = new WeakMap(), H = new WeakMap(); | ||
const Ye = "http://example.com"; | ||
function fe(r) { | ||
return r.toString().substring(r.origin.length); | ||
} | ||
function fe(r, e) { | ||
function pe(r, e) { | ||
return !e || !r.startsWith(e) ? r : r.substring(e.length); | ||
} | ||
function Je(r, e) { | ||
function Ve(r, e) { | ||
return !e || r.startsWith(e) ? r : e + r; | ||
} | ||
var b, O, M, x, $, P, I, N, D, ye, j, ge, q, we; | ||
class Ye { | ||
var g, O, L, x, $, w, I, N, W, ge, q, we, j, be; | ||
class Ke { | ||
/** | ||
@@ -382,3 +455,3 @@ * @param php - The PHP instance. | ||
*/ | ||
c(this, D); | ||
c(this, W); | ||
/** | ||
@@ -391,3 +464,3 @@ * Runs the requested PHP file with all the request and $_SERVER | ||
*/ | ||
c(this, j); | ||
c(this, q); | ||
/** | ||
@@ -402,27 +475,27 @@ * Resolve the requested path to the filesystem path of the requested PHP file. | ||
*/ | ||
c(this, q); | ||
c(this, b, void 0); | ||
c(this, j); | ||
c(this, g, void 0); | ||
c(this, O, void 0); | ||
c(this, M, void 0); | ||
c(this, L, void 0); | ||
c(this, x, void 0); | ||
c(this, $, void 0); | ||
c(this, P, void 0); | ||
c(this, w, void 0); | ||
c(this, I, void 0); | ||
c(this, N, void 0); | ||
d(this, N, new oe({ concurrency: 1 })); | ||
d(this, N, new ie({ concurrency: 1 })); | ||
const { | ||
documentRoot: s = "/www/", | ||
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : "" | ||
documentRoot: n = "/www/", | ||
absoluteUrl: s = typeof location == "object" ? location == null ? void 0 : location.href : "" | ||
} = t; | ||
this.php = e, d(this, b, s); | ||
const o = new URL(n); | ||
d(this, M, o.hostname), d(this, x, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), d(this, O, (o.protocol || "").replace(":", "")); | ||
this.php = e, d(this, g, n); | ||
const o = new URL(s); | ||
d(this, L, o.hostname), d(this, x, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), d(this, O, (o.protocol || "").replace(":", "")); | ||
const i = a(this, x) !== 443 && a(this, x) !== 80; | ||
d(this, $, [ | ||
a(this, M), | ||
a(this, L), | ||
i ? `:${a(this, x)}` : "" | ||
].join("")), d(this, P, o.pathname.replace(/\/+$/, "")), d(this, I, [ | ||
].join("")), d(this, w, o.pathname.replace(/\/+$/, "")), d(this, I, [ | ||
`${a(this, O)}://`, | ||
a(this, $), | ||
a(this, P) | ||
a(this, w) | ||
].join("")); | ||
@@ -437,3 +510,3 @@ } | ||
const t = new URL(e); | ||
return t.pathname.startsWith(a(this, P)) && (t.pathname = t.pathname.slice(a(this, P).length)), de(t); | ||
return t.pathname.startsWith(a(this, w)) && (t.pathname = t.pathname.slice(a(this, w).length)), fe(t); | ||
} | ||
@@ -449,17 +522,17 @@ get isRequestRunning() { | ||
get documentRoot() { | ||
return a(this, b); | ||
return a(this, g); | ||
} | ||
/** @inheritDoc */ | ||
async request(e) { | ||
const t = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL( | ||
const t = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL( | ||
e.url, | ||
t ? void 0 : Ge | ||
), n = fe( | ||
s.pathname, | ||
a(this, P) | ||
), o = `${a(this, b)}${n}`; | ||
return Ze(o) ? await m(this, j, ge).call(this, e, s) : m(this, D, ye).call(this, o); | ||
t ? void 0 : Ye | ||
), s = pe( | ||
n.pathname, | ||
a(this, w) | ||
), o = `${a(this, g)}${s}`; | ||
return Xe(o) ? await m(this, q, we).call(this, e, n) : m(this, W, ge).call(this, o); | ||
} | ||
} | ||
b = new WeakMap(), O = new WeakMap(), M = new WeakMap(), x = new WeakMap(), $ = new WeakMap(), P = new WeakMap(), I = new WeakMap(), N = new WeakMap(), D = new WeakSet(), ye = function(e) { | ||
g = new WeakMap(), O = new WeakMap(), L = new WeakMap(), x = new WeakMap(), $ = new WeakMap(), w = new WeakMap(), I = new WeakMap(), N = new WeakMap(), W = new WeakSet(), ge = function(e) { | ||
if (!this.php.fileExists(e)) | ||
@@ -483,3 +556,3 @@ return new A( | ||
// was tampered with. | ||
"content-type": [Ke(e)], | ||
"content-type": [Qe(e)], | ||
"accept-ranges": ["bytes"], | ||
@@ -490,7 +563,7 @@ "cache-control": ["public, max-age=0"] | ||
); | ||
}, j = new WeakSet(), ge = async function(e, t) { | ||
var n; | ||
const s = await a(this, N).acquire(); | ||
}, q = new WeakSet(), we = async function(e, t) { | ||
var s; | ||
const n = await a(this, N).acquire(); | ||
try { | ||
this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this, b)), this.php.addServerGlobalEntry( | ||
this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this, g)), this.php.addServerGlobalEntry( | ||
"HTTPS", | ||
@@ -502,26 +575,26 @@ a(this, I).startsWith("https://") ? "on" : "" | ||
host: a(this, $), | ||
...Ae(e.headers || {}) | ||
}, h = []; | ||
...He(e.headers || {}) | ||
}, u = []; | ||
if (e.files && Object.keys(e.files).length) { | ||
o = "POST"; | ||
for (const p in e.files) { | ||
const _ = e.files[p]; | ||
h.push({ | ||
const R = e.files[p]; | ||
u.push({ | ||
key: p, | ||
name: _.name, | ||
type: _.type, | ||
data: new Uint8Array(await _.arrayBuffer()) | ||
name: R.name, | ||
type: R.type, | ||
data: new Uint8Array(await R.arrayBuffer()) | ||
}); | ||
} | ||
(n = i["content-type"]) != null && n.startsWith("multipart/form-data") && (e.formData = Ve( | ||
(s = i["content-type"]) != null && s.startsWith("multipart/form-data") && (e.formData = Ze( | ||
e.body || "" | ||
), i["content-type"] = "application/x-www-form-urlencoded", delete e.body); | ||
} | ||
let u; | ||
e.formData !== void 0 ? (o = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", u = new URLSearchParams( | ||
let h; | ||
e.formData !== void 0 ? (o = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", h = new URLSearchParams( | ||
e.formData | ||
).toString()) : u = e.body; | ||
).toString()) : h = e.body; | ||
let f; | ||
try { | ||
f = m(this, q, we).call(this, t.pathname); | ||
f = m(this, j, be).call(this, t.pathname); | ||
} catch { | ||
@@ -535,10 +608,10 @@ return new A( | ||
return await this.php.run({ | ||
relativeUri: Je( | ||
de(t), | ||
a(this, P) | ||
relativeUri: Ve( | ||
fe(t), | ||
a(this, w) | ||
), | ||
protocol: a(this, O), | ||
method: e.method || o, | ||
body: u, | ||
fileInfos: h, | ||
body: h, | ||
fileInfos: u, | ||
scriptPath: f, | ||
@@ -548,30 +621,30 @@ headers: i | ||
} finally { | ||
s(); | ||
n(); | ||
} | ||
}, q = new WeakSet(), we = function(e) { | ||
let t = fe(e, a(this, P)); | ||
}, j = new WeakSet(), be = function(e) { | ||
let t = pe(e, a(this, w)); | ||
t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php")); | ||
const s = `${a(this, b)}${t}`; | ||
if (this.php.fileExists(s)) | ||
return s; | ||
if (!this.php.fileExists(`${a(this, b)}/index.php`)) | ||
throw new Error(`File not found: ${s}`); | ||
return `${a(this, b)}/index.php`; | ||
const n = `${a(this, g)}${t}`; | ||
if (this.php.fileExists(n)) | ||
return n; | ||
if (!this.php.fileExists(`${a(this, g)}/index.php`)) | ||
throw new Error(`File not found: ${n}`); | ||
return `${a(this, g)}/index.php`; | ||
}; | ||
function Ve(r) { | ||
function Ze(r) { | ||
const e = {}, t = r.match(/--(.*)\r\n/); | ||
if (!t) | ||
return e; | ||
const s = t[1], n = r.split(`--${s}`); | ||
return n.shift(), n.pop(), n.forEach((o) => { | ||
const n = t[1], s = r.split(`--${n}`); | ||
return s.shift(), s.pop(), s.forEach((o) => { | ||
const i = o.indexOf(`\r | ||
\r | ||
`), h = o.substring(0, i).trim(), u = o.substring(i + 4).trim(), f = h.match(/name="([^"]+)"/); | ||
`), u = o.substring(0, i).trim(), h = o.substring(i + 4).trim(), f = u.match(/name="([^"]+)"/); | ||
if (f) { | ||
const p = f[1]; | ||
e[p] = u; | ||
e[p] = h; | ||
} | ||
}), e; | ||
} | ||
function Ke(r) { | ||
function Qe(r) { | ||
switch (r.split(".").pop()) { | ||
@@ -616,12 +689,12 @@ case "css": | ||
} | ||
function Ze(r) { | ||
return Qe(r) || Xe(r); | ||
function Xe(r) { | ||
return et(r) || tt(r); | ||
} | ||
function Qe(r) { | ||
function et(r) { | ||
return r.endsWith(".php") || r.includes(".php/"); | ||
} | ||
function Xe(r) { | ||
function tt(r) { | ||
return !r.split("/").pop().includes("."); | ||
} | ||
const pe = { | ||
const D = { | ||
0: "No error occurred. System call completed successfully.", | ||
@@ -705,17 +778,22 @@ 1: "Argument list too long.", | ||
}; | ||
function g(r = "") { | ||
return function(t, s, n) { | ||
const o = n.value; | ||
n.value = function(...i) { | ||
function rt(r) { | ||
const e = typeof r == "object" ? r == null ? void 0 : r.errno : null; | ||
if (e in D) | ||
return D[e]; | ||
} | ||
function b(r = "") { | ||
return function(t, n, s) { | ||
const o = s.value; | ||
s.value = function(...i) { | ||
try { | ||
return o.apply(this, i); | ||
} catch (h) { | ||
const u = typeof h == "object" ? h == null ? void 0 : h.errno : null; | ||
if (u in pe) { | ||
const f = pe[u], p = typeof i[0] == "string" ? i[0] : null, _ = p !== null ? r.replaceAll("{path}", p) : r; | ||
throw new Error(`${_}: ${f}`, { | ||
cause: h | ||
} catch (u) { | ||
const h = typeof u == "object" ? u == null ? void 0 : u.errno : null; | ||
if (h in D) { | ||
const f = D[h], p = typeof i[0] == "string" ? i[0] : null, R = p !== null ? r.replaceAll("{path}", p) : r; | ||
throw new Error(`${R}: ${f}`, { | ||
cause: u | ||
}); | ||
} | ||
throw h; | ||
throw u; | ||
} | ||
@@ -725,5 +803,5 @@ }; | ||
} | ||
const et = /* @__PURE__ */ new Map(); | ||
function tt(r) { | ||
return et.get(r); | ||
const nt = /* @__PURE__ */ new Map(); | ||
function st(r) { | ||
return nt.get(r); | ||
} | ||
@@ -734,10 +812,10 @@ (function() { | ||
})(); | ||
var rt = Object.defineProperty, st = Object.getOwnPropertyDescriptor, w = (r, e, t, s) => { | ||
for (var n = s > 1 ? void 0 : s ? st(e, t) : e, o = r.length - 1, i; o >= 0; o--) | ||
(i = r[o]) && (n = (s ? i(e, t, n) : i(n)) || n); | ||
return s && n && rt(e, t, n), n; | ||
var ot = Object.defineProperty, it = Object.getOwnPropertyDescriptor, E = (r, e, t, n) => { | ||
for (var s = n > 1 ? void 0 : n ? it(e, t) : e, o = r.length - 1, i; o >= 0; o--) | ||
(i = r[o]) && (s = (n ? i(e, t, s) : i(s)) || s); | ||
return n && s && ot(e, t, s), s; | ||
}; | ||
const y = "string", C = "number", l = Symbol("__private__dont__use"); | ||
var S, v, F, R, T, L, U, B, Ee, z, be, G, Pe, J, _e, Y, Te, V, ve, K, Re, Z, ke, Q, xe, X, Se, ee, Fe, te, Ce; | ||
class E { | ||
var k, T, F, _, v, M, U, z, Ee, G, Pe, J, Re, Y, ve, V, Te, K, _e, Z, Se, Q, xe, X, ke, ee, Fe, te, Ce, re, Ae; | ||
class P { | ||
/** | ||
@@ -751,3 +829,2 @@ * Initializes a PHP runtime. | ||
constructor(e, t) { | ||
c(this, B); | ||
c(this, z); | ||
@@ -761,2 +838,3 @@ c(this, G); | ||
c(this, Q); | ||
c(this, X); | ||
/** | ||
@@ -771,32 +849,32 @@ * Adds file information to $_FILES superglobal in PHP. | ||
*/ | ||
c(this, X); | ||
c(this, ee); | ||
c(this, te); | ||
c(this, S, void 0); | ||
c(this, re); | ||
c(this, k, void 0); | ||
c(this, T, void 0); | ||
c(this, F, void 0); | ||
c(this, _, void 0); | ||
c(this, v, void 0); | ||
c(this, F, void 0); | ||
c(this, R, void 0); | ||
c(this, T, void 0); | ||
c(this, L, void 0); | ||
c(this, M, void 0); | ||
c(this, U, void 0); | ||
d(this, S, []), d(this, v, !1), d(this, F, null), d(this, R, {}), d(this, T, /* @__PURE__ */ new Map()), d(this, L, []), d(this, U, new oe({ concurrency: 1 })), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new qe( | ||
new Ye(this, t) | ||
d(this, k, []), d(this, T, !1), d(this, F, null), d(this, _, {}), d(this, v, /* @__PURE__ */ new Map()), d(this, M, []), d(this, U, new ie({ concurrency: 1 })), e !== void 0 && this.initializeRuntime(e), t && (this.requestHandler = new Je( | ||
new Ke(this, t) | ||
)); | ||
} | ||
addEventListener(e, t) { | ||
a(this, T).has(e) || a(this, T).set(e, /* @__PURE__ */ new Set()), a(this, T).get(e).add(t); | ||
a(this, v).has(e) || a(this, v).set(e, /* @__PURE__ */ new Set()), a(this, v).get(e).add(t); | ||
} | ||
removeEventListener(e, t) { | ||
var s; | ||
(s = a(this, T).get(e)) == null || s.delete(t); | ||
var n; | ||
(n = a(this, v).get(e)) == null || n.delete(t); | ||
} | ||
dispatchEvent(e) { | ||
const t = a(this, T).get(e.type); | ||
const t = a(this, v).get(e.type); | ||
if (t) | ||
for (const s of t) | ||
s(e); | ||
for (const n of t) | ||
n(e); | ||
} | ||
/** @inheritDoc */ | ||
async onMessage(e) { | ||
a(this, L).push(e); | ||
a(this, M).push(e); | ||
} | ||
@@ -828,8 +906,8 @@ /** @inheritDoc */ | ||
throw new Error("PHP runtime already initialized."); | ||
const t = tt(e); | ||
const t = st(e); | ||
if (!t) | ||
throw new Error("Invalid PHP runtime id."); | ||
this[l] = t, t.onMessage = async (s) => { | ||
for (const n of a(this, L)) { | ||
const o = await n(s); | ||
this[l] = t, t.onMessage = async (n) => { | ||
for (const s of a(this, M)) { | ||
const o = await s(n); | ||
if (o) | ||
@@ -839,7 +917,7 @@ return o; | ||
return ""; | ||
}, d(this, F, Ne(t)); | ||
}, d(this, F, Le(t)); | ||
} | ||
/** @inheritDoc */ | ||
setPhpIniPath(e) { | ||
if (a(this, v)) | ||
if (a(this, T)) | ||
throw new Error("Cannot set PHP ini path after calling run()."); | ||
@@ -855,5 +933,5 @@ this[l].ccall( | ||
setPhpIniEntry(e, t) { | ||
if (a(this, v)) | ||
if (a(this, T)) | ||
throw new Error("Cannot set PHP ini entries after calling run()."); | ||
a(this, S).push([e, t]); | ||
a(this, k).push([e, t]); | ||
} | ||
@@ -874,8 +952,8 @@ /** @inheritDoc */ | ||
try { | ||
a(this, v) || (m(this, B, Ee).call(this), d(this, v, !0)), m(this, Z, ke).call(this, e.scriptPath || ""), m(this, G, Pe).call(this, e.relativeUri || ""), m(this, Y, Te).call(this, e.method || "GET"); | ||
const s = Ae(e.headers || {}), n = s.host || "example.com:443"; | ||
if (m(this, J, _e).call(this, n, e.protocol || "http"), m(this, V, ve).call(this, s), e.body && m(this, K, Re).call(this, e.body), e.fileInfos) | ||
a(this, T) || (m(this, z, Ee).call(this), d(this, T, !0)), m(this, Q, xe).call(this, e.scriptPath || ""), m(this, J, Re).call(this, e.relativeUri || ""), m(this, V, Te).call(this, e.method || "GET"); | ||
const n = He(e.headers || {}), s = n.host || "example.com:443"; | ||
if (m(this, Y, ve).call(this, s, e.protocol || "http"), m(this, K, _e).call(this, n), e.body && m(this, Z, Se).call(this, e.body), e.fileInfos) | ||
for (const o of e.fileInfos) | ||
m(this, X, Se).call(this, o); | ||
return e.code && m(this, ee, Fe).call(this, " ?>" + e.code), m(this, Q, xe).call(this), await m(this, te, Ce).call(this); | ||
m(this, ee, Fe).call(this, o); | ||
return e.code && m(this, te, Ce).call(this, " ?>" + e.code), m(this, X, ke).call(this), await m(this, re, Ae).call(this); | ||
} finally { | ||
@@ -888,8 +966,8 @@ t(), this.dispatchEvent({ | ||
addServerGlobalEntry(e, t) { | ||
a(this, R)[e] = t; | ||
a(this, _)[e] = t; | ||
} | ||
defineConstant(e, t) { | ||
let s = {}; | ||
let n = {}; | ||
try { | ||
s = JSON.parse( | ||
n = JSON.parse( | ||
this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}" | ||
@@ -902,3 +980,3 @@ ); | ||
JSON.stringify({ | ||
...s, | ||
...n, | ||
[e]: t | ||
@@ -926,9 +1004,20 @@ }) | ||
} | ||
/** @inheritDoc */ | ||
mv(e, t) { | ||
this[l].FS.rename(e, t); | ||
try { | ||
this[l].FS.rename(e, t); | ||
} catch (n) { | ||
const s = rt(n); | ||
throw s ? new Error( | ||
`Could not move ${e} to ${t}: ${s}`, | ||
{ | ||
cause: n | ||
} | ||
) : n; | ||
} | ||
} | ||
rmdir(e, t = { recursive: !0 }) { | ||
t != null && t.recursive && this.listFiles(e).forEach((s) => { | ||
const n = `${e}/${s}`; | ||
this.isDir(n) ? this.rmdir(n, t) : this.unlink(n); | ||
t != null && t.recursive && this.listFiles(e).forEach((n) => { | ||
const s = `${e}/${n}`; | ||
this.isDir(s) ? this.rmdir(s, t) : this.unlink(s); | ||
}), this[l].FS.rmdir(e); | ||
@@ -940,12 +1029,12 @@ } | ||
try { | ||
const s = this[l].FS.readdir(e).filter( | ||
(n) => n !== "." && n !== ".." | ||
const n = this[l].FS.readdir(e).filter( | ||
(s) => s !== "." && s !== ".." | ||
); | ||
if (t.prependPath) { | ||
const n = e.replace(/\/$/, ""); | ||
return s.map((o) => `${n}/${o}`); | ||
const s = e.replace(/\/$/, ""); | ||
return n.map((o) => `${s}/${o}`); | ||
} | ||
return s; | ||
} catch (s) { | ||
return console.error(s, { path: e }), []; | ||
return n; | ||
} catch (n) { | ||
return console.error(n, { path: e }), []; | ||
} | ||
@@ -969,3 +1058,3 @@ } | ||
} | ||
S = new WeakMap(), v = new WeakMap(), F = new WeakMap(), R = new WeakMap(), T = new WeakMap(), L = new WeakMap(), U = new WeakMap(), B = new WeakSet(), Ee = function() { | ||
k = new WeakMap(), T = new WeakMap(), F = new WeakMap(), _ = new WeakMap(), v = new WeakMap(), M = new WeakMap(), U = new WeakMap(), z = new WeakSet(), Ee = function() { | ||
if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile( | ||
@@ -982,4 +1071,4 @@ "/tmp/consts.php", | ||
}` | ||
), a(this, S).length > 0) { | ||
const e = a(this, S).map(([t, s]) => `${t}=${s}`).join(` | ||
), a(this, k).length > 0) { | ||
const e = a(this, k).map(([t, n]) => `${t}=${n}`).join(` | ||
`) + ` | ||
@@ -996,3 +1085,3 @@ | ||
this[l].ccall("php_wasm_init", null, [], []); | ||
}, z = new WeakSet(), be = function() { | ||
}, G = new WeakSet(), Pe = function() { | ||
const e = "/tmp/headers.json"; | ||
@@ -1003,14 +1092,14 @@ if (!this.fileExists(e)) | ||
); | ||
const t = JSON.parse(this.readFileAsText(e)), s = {}; | ||
for (const n of t.headers) { | ||
if (!n.includes(": ")) | ||
const t = JSON.parse(this.readFileAsText(e)), n = {}; | ||
for (const s of t.headers) { | ||
if (!s.includes(": ")) | ||
continue; | ||
const o = n.indexOf(": "), i = n.substring(0, o).toLowerCase(), h = n.substring(o + 2); | ||
i in s || (s[i] = []), s[i].push(h); | ||
const o = s.indexOf(": "), i = s.substring(0, o).toLowerCase(), u = s.substring(o + 2); | ||
i in n || (n[i] = []), n[i].push(u); | ||
} | ||
return { | ||
headers: s, | ||
headers: n, | ||
httpStatusCode: t.status | ||
}; | ||
}, G = new WeakSet(), Pe = function(e) { | ||
}, J = new WeakSet(), Re = function(e) { | ||
if (this[l].ccall( | ||
@@ -1030,3 +1119,3 @@ "wasm_set_request_uri", | ||
} | ||
}, J = new WeakSet(), _e = function(e, t) { | ||
}, Y = new WeakSet(), ve = function(e, t) { | ||
this[l].ccall( | ||
@@ -1038,14 +1127,14 @@ "wasm_set_request_host", | ||
); | ||
let s; | ||
let n; | ||
try { | ||
s = parseInt(new URL(e).port, 10); | ||
n = parseInt(new URL(e).port, 10); | ||
} catch { | ||
} | ||
(!s || isNaN(s) || s === 80) && (s = t === "https" ? 443 : 80), this[l].ccall( | ||
(!n || isNaN(n) || n === 80) && (n = t === "https" ? 443 : 80), this[l].ccall( | ||
"wasm_set_request_port", | ||
null, | ||
[C], | ||
[s] | ||
), (t === "https" || !t && s === 443) && this.addServerGlobalEntry("HTTPS", "on"); | ||
}, Y = new WeakSet(), Te = function(e) { | ||
[n] | ||
), (t === "https" || !t && n === 443) && this.addServerGlobalEntry("HTTPS", "on"); | ||
}, V = new WeakSet(), Te = function(e) { | ||
this[l].ccall( | ||
@@ -1057,3 +1146,3 @@ "wasm_set_request_method", | ||
); | ||
}, V = new WeakSet(), ve = function(e) { | ||
}, K = new WeakSet(), _e = function(e) { | ||
e.cookie && this[l].ccall( | ||
@@ -1076,9 +1165,9 @@ "wasm_set_cookies", | ||
for (const t in e) { | ||
let s = "HTTP_"; | ||
["content-type", "content-length"].includes(t.toLowerCase()) && (s = ""), this.addServerGlobalEntry( | ||
`${s}${t.toUpperCase().replace(/-/g, "_")}`, | ||
let n = "HTTP_"; | ||
["content-type", "content-length"].includes(t.toLowerCase()) && (n = ""), this.addServerGlobalEntry( | ||
`${n}${t.toUpperCase().replace(/-/g, "_")}`, | ||
e[t] | ||
); | ||
} | ||
}, K = new WeakSet(), Re = function(e) { | ||
}, Z = new WeakSet(), Se = function(e) { | ||
this[l].ccall( | ||
@@ -1095,3 +1184,3 @@ "wasm_set_request_body", | ||
); | ||
}, Z = new WeakSet(), ke = function(e) { | ||
}, Q = new WeakSet(), xe = function(e) { | ||
this[l].ccall( | ||
@@ -1103,4 +1192,4 @@ "wasm_set_path_translated", | ||
); | ||
}, Q = new WeakSet(), xe = function() { | ||
for (const e in a(this, R)) | ||
}, X = new WeakSet(), ke = function() { | ||
for (const e in a(this, _)) | ||
this[l].ccall( | ||
@@ -1110,8 +1199,8 @@ "wasm_add_SERVER_entry", | ||
[y, y], | ||
[e, a(this, R)[e]] | ||
[e, a(this, _)[e]] | ||
); | ||
}, X = new WeakSet(), Se = function(e) { | ||
const { key: t, name: s, type: n, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`; | ||
}, ee = new WeakSet(), Fe = function(e) { | ||
const { key: t, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`; | ||
this.writeFile(i, o); | ||
const h = 0; | ||
const u = 0; | ||
this[l].ccall( | ||
@@ -1121,5 +1210,5 @@ "wasm_add_uploaded_file", | ||
[y, y, y, y, C, C], | ||
[t, s, n, i, h, o.byteLength] | ||
[t, n, s, i, u, o.byteLength] | ||
); | ||
}, ee = new WeakSet(), Fe = function(e) { | ||
}, te = new WeakSet(), Ce = function(e) { | ||
this[l].ccall( | ||
@@ -1131,11 +1220,11 @@ "wasm_set_php_code", | ||
); | ||
}, te = new WeakSet(), Ce = async function() { | ||
}, re = new WeakSet(), Ae = async function() { | ||
var o; | ||
let e, t; | ||
try { | ||
e = await new Promise((i, h) => { | ||
e = await new Promise((i, u) => { | ||
var f; | ||
t = (p) => { | ||
const _ = new Error("Rethrown"); | ||
_.cause = p.error, _.betterMessage = p.message, h(_); | ||
const R = new Error("Rethrown"); | ||
R.cause = p.error, R.betterMessage = p.message, u(R); | ||
}, (f = a(this, F)) == null || f.addEventListener( | ||
@@ -1145,3 +1234,3 @@ "error", | ||
); | ||
const u = this[l].ccall( | ||
const h = this[l].ccall( | ||
"wasm_sapi_handle_request", | ||
@@ -1153,3 +1242,3 @@ C, | ||
); | ||
return u instanceof Promise ? u.then(i, h) : i(u); | ||
return h instanceof Promise ? h.then(i, u) : i(h); | ||
}); | ||
@@ -1163,12 +1252,12 @@ } catch (i) { | ||
}); | ||
this.functionsMaybeMissingFromAsyncify = Le(); | ||
const h = i, u = "betterMessage" in h ? h.betterMessage : h.message, f = new Error(u); | ||
throw f.cause = h, f; | ||
this.functionsMaybeMissingFromAsyncify = Ue(); | ||
const u = i, h = "betterMessage" in u ? u.betterMessage : u.message, f = new Error(h); | ||
throw f.cause = u, f; | ||
} finally { | ||
(o = a(this, F)) == null || o.removeEventListener("error", t), d(this, R, {}); | ||
(o = a(this, F)) == null || o.removeEventListener("error", t), d(this, _, {}); | ||
} | ||
const { headers: s, httpStatusCode: n } = m(this, z, be).call(this); | ||
const { headers: n, httpStatusCode: s } = m(this, G, Pe).call(this); | ||
return new A( | ||
s, | ||
n, | ||
s, | ||
this.readFileAsBuffer("/tmp/stdout"), | ||
@@ -1179,36 +1268,33 @@ this.readFileAsText("/tmp/stderr"), | ||
}; | ||
w([ | ||
g('Could not create directory "{path}"') | ||
], E.prototype, "mkdir", 1); | ||
w([ | ||
g('Could not create directory "{path}"') | ||
], E.prototype, "mkdirTree", 1); | ||
w([ | ||
g('Could not read "{path}"') | ||
], E.prototype, "readFileAsText", 1); | ||
w([ | ||
g('Could not read "{path}"') | ||
], E.prototype, "readFileAsBuffer", 1); | ||
w([ | ||
g('Could not write to "{path}"') | ||
], E.prototype, "writeFile", 1); | ||
w([ | ||
g('Could not unlink "{path}"') | ||
], E.prototype, "unlink", 1); | ||
w([ | ||
g('Could not move "{path}"') | ||
], E.prototype, "mv", 1); | ||
w([ | ||
g('Could not remove directory "{path}"') | ||
], E.prototype, "rmdir", 1); | ||
w([ | ||
g('Could not list files in "{path}"') | ||
], E.prototype, "listFiles", 1); | ||
w([ | ||
g('Could not stat "{path}"') | ||
], E.prototype, "isDir", 1); | ||
w([ | ||
g('Could not stat "{path}"') | ||
], E.prototype, "fileExists", 1); | ||
function Ae(r) { | ||
E([ | ||
b('Could not create directory "{path}"') | ||
], P.prototype, "mkdir", 1); | ||
E([ | ||
b('Could not create directory "{path}"') | ||
], P.prototype, "mkdirTree", 1); | ||
E([ | ||
b('Could not read "{path}"') | ||
], P.prototype, "readFileAsText", 1); | ||
E([ | ||
b('Could not read "{path}"') | ||
], P.prototype, "readFileAsBuffer", 1); | ||
E([ | ||
b('Could not write to "{path}"') | ||
], P.prototype, "writeFile", 1); | ||
E([ | ||
b('Could not unlink "{path}"') | ||
], P.prototype, "unlink", 1); | ||
E([ | ||
b('Could not remove directory "{path}"') | ||
], P.prototype, "rmdir", 1); | ||
E([ | ||
b('Could not list files in "{path}"') | ||
], P.prototype, "listFiles", 1); | ||
E([ | ||
b('Could not stat "{path}"') | ||
], P.prototype, "isDir", 1); | ||
E([ | ||
b('Could not stat "{path}"') | ||
], P.prototype, "fileExists", 1); | ||
function He(r) { | ||
const e = {}; | ||
@@ -1219,34 +1305,34 @@ for (const t in r) | ||
} | ||
function ut(r, e, t = () => { | ||
function pt(r, e, t = () => { | ||
}) { | ||
e = ot(e); | ||
const s = r[l].FS, n = nt(s, (u) => { | ||
if (u.path.startsWith(e)) | ||
t(u); | ||
else if (u.operation === "RENAME" && u.toPath.startsWith(e)) | ||
for (const f of He( | ||
e = lt(e); | ||
const n = r[l].FS, s = at(n, (h) => { | ||
if (h.path.startsWith(e)) | ||
t(h); | ||
else if (h.operation === "RENAME" && h.toPath.startsWith(e)) | ||
for (const f of Oe( | ||
r, | ||
u.path, | ||
u.toPath | ||
h.path, | ||
h.toPath | ||
)) | ||
t(f); | ||
}), o = {}; | ||
for (const [u] of Object.entries(n)) | ||
o[u] = s[u]; | ||
for (const [h] of Object.entries(s)) | ||
o[h] = n[h]; | ||
function i() { | ||
for (const [u, f] of Object.entries(n)) | ||
s[u] = function(...p) { | ||
return f(...p), o[u].apply(this, p); | ||
for (const [h, f] of Object.entries(s)) | ||
n[h] = function(...p) { | ||
return f(...p), o[h].apply(this, p); | ||
}; | ||
} | ||
function h() { | ||
for (const [u, f] of Object.entries(o)) | ||
r[l].FS[u] = f; | ||
function u() { | ||
for (const [h, f] of Object.entries(o)) | ||
r[l].FS[h] = f; | ||
} | ||
return r[l].journal = { | ||
bind: i, | ||
unbind: h | ||
}, i(), h; | ||
unbind: u | ||
}, i(), u; | ||
} | ||
const nt = (r, e = () => { | ||
const at = (r, e = () => { | ||
}) => ({ | ||
@@ -1261,8 +1347,8 @@ write(t) { | ||
truncate(t) { | ||
let s; | ||
typeof t == "string" ? s = r.lookupPath(t, { | ||
let n; | ||
typeof t == "string" ? n = r.lookupPath(t, { | ||
follow: !0 | ||
}).node : s = t, e({ | ||
}).node : n = t, e({ | ||
operation: "WRITE", | ||
path: r.getPath(s), | ||
path: r.getPath(n), | ||
nodeType: "file" | ||
@@ -1278,4 +1364,4 @@ }); | ||
}, | ||
mknod(t, s) { | ||
r.isFile(s) && e({ | ||
mknod(t, n) { | ||
r.isFile(n) && e({ | ||
operation: "CREATE", | ||
@@ -1300,7 +1386,7 @@ path: t, | ||
}, | ||
rename(t, s) { | ||
rename(t, n) { | ||
try { | ||
const n = r.lookupPath(t, { | ||
const s = r.lookupPath(t, { | ||
follow: !0 | ||
}), o = r.lookupPath(s, { | ||
}), o = r.lookupPath(n, { | ||
parent: !0 | ||
@@ -1310,5 +1396,5 @@ }).path; | ||
operation: "RENAME", | ||
nodeType: r.isDir(n.node.mode) ? "directory" : "file", | ||
path: n.path, | ||
toPath: W(o, Be(s)) | ||
nodeType: r.isDir(s.node.mode) ? "directory" : "file", | ||
path: s.path, | ||
toPath: B(o, ze(n)) | ||
}); | ||
@@ -1319,3 +1405,3 @@ } catch { | ||
}); | ||
function dt(r, e) { | ||
function mt(r, e) { | ||
r[l].journal.unbind(); | ||
@@ -1329,3 +1415,3 @@ try { | ||
} | ||
function* He(r, e, t) { | ||
function* Oe(r, e, t) { | ||
if (r.isDir(e)) { | ||
@@ -1337,7 +1423,7 @@ yield { | ||
}; | ||
for (const s of r.listFiles(e)) | ||
yield* He( | ||
for (const n of r.listFiles(e)) | ||
yield* Oe( | ||
r, | ||
W(e, s), | ||
W(t, s) | ||
B(e, n), | ||
B(t, n) | ||
); | ||
@@ -1355,13 +1441,13 @@ } else | ||
} | ||
function ot(r) { | ||
function lt(r) { | ||
return r.replace(/\/$/, "").replace(/\/\/+/g, "/"); | ||
} | ||
function it(r) { | ||
function ct(r) { | ||
const e = {}; | ||
for (let t = r.length - 1; t >= 0; t--) { | ||
for (let s = t - 1; s >= 0; s--) { | ||
const n = at(r[t], r[s]); | ||
if (n === "none") | ||
for (let n = t - 1; n >= 0; n--) { | ||
const s = ut(r[t], r[n]); | ||
if (s === "none") | ||
continue; | ||
const o = r[t], i = r[s]; | ||
const o = r[t], i = r[n]; | ||
if (o.operation === "RENAME" && i.operation === "RENAME") { | ||
@@ -1377,3 +1463,3 @@ console.warn( | ||
} | ||
(i.operation === "CREATE" || i.operation === "WRITE") && (o.operation === "RENAME" ? n === "same_node" ? (e[s] = [], e[t] = [ | ||
(i.operation === "CREATE" || i.operation === "WRITE") && (o.operation === "RENAME" ? s === "same_node" ? (e[n] = [], e[t] = [ | ||
{ | ||
@@ -1384,6 +1470,6 @@ ...i, | ||
...e[t] || [] | ||
]) : n === "descendant" && (e[s] = [], e[t] = [ | ||
]) : s === "descendant" && (e[n] = [], e[t] = [ | ||
{ | ||
...i, | ||
path: W( | ||
path: B( | ||
o.toPath, | ||
@@ -1394,7 +1480,7 @@ i.path.substring(o.path.length) | ||
...e[t] || [] | ||
]) : o.operation === "WRITE" && n === "same_node" ? e[s] = [] : o.operation === "DELETE" && n === "same_node" && (e[s] = [], e[t] = [])); | ||
]) : o.operation === "WRITE" && s === "same_node" ? e[n] = [] : o.operation === "DELETE" && s === "same_node" && (e[n] = [], e[t] = [])); | ||
} | ||
if (Object.entries(e).length > 0) { | ||
const s = r.flatMap((n, o) => o in e ? e[o] : [n]); | ||
return it(s); | ||
const n = r.flatMap((s, o) => o in e ? e[o] : [s]); | ||
return ct(n); | ||
} | ||
@@ -1404,21 +1490,21 @@ } | ||
} | ||
function at(r, e) { | ||
const t = r.path, s = r.operation !== "WRITE" && r.nodeType === "directory", n = e.operation !== "WRITE" && e.nodeType === "directory", o = e.operation === "RENAME" ? e.toPath : e.path; | ||
return o === t ? "same_node" : n && t.startsWith(o + "/") ? "ancestor" : s && o.startsWith(t + "/") ? "descendant" : "none"; | ||
function ut(r, e) { | ||
const t = r.path, n = r.operation !== "WRITE" && r.nodeType === "directory", s = e.operation !== "WRITE" && e.nodeType === "directory", o = e.operation === "RENAME" ? e.toPath : e.path; | ||
return o === t ? "same_node" : s && t.startsWith(o + "/") ? "ancestor" : n && o.startsWith(t + "/") ? "descendant" : "none"; | ||
} | ||
async function ft(r, e) { | ||
const s = e.filter( | ||
(n) => n.operation === "WRITE" | ||
).map((n) => ct(r, n)); | ||
return await Promise.all(s), e; | ||
async function yt(r, e) { | ||
const n = e.filter( | ||
(s) => s.operation === "WRITE" | ||
).map((s) => dt(r, s)); | ||
return await Promise.all(n), e; | ||
} | ||
const lt = new oe({ concurrency: 15 }); | ||
async function ct(r, e) { | ||
const t = await lt.acquire(); | ||
const ht = new ie({ concurrency: 15 }); | ||
async function dt(r, e) { | ||
const t = await ht.acquire(); | ||
try { | ||
e.data = await r.readFileAsBuffer(e.path); | ||
} catch (s) { | ||
} catch (n) { | ||
console.warn( | ||
`Journal failed to hydrate a file on flush: the path ${e.path} no longer exists` | ||
), console.error(s); | ||
), console.error(n); | ||
} | ||
@@ -1428,6 +1514,6 @@ t(); | ||
export { | ||
ft as hydrateUpdateFileOps, | ||
ut as journalFSEvents, | ||
it as normalizeFilesystemOperations, | ||
dt as replayFSJournal | ||
yt as hydrateUpdateFileOps, | ||
pt as journalFSEvents, | ||
ct as normalizeFilesystemOperations, | ||
mt as replayFSJournal | ||
}; |
{ | ||
"name": "@php-wasm/fs-journal", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"description": "Bindings to journal the PHP filesystem", | ||
@@ -39,7 +39,7 @@ "repository": { | ||
"license": "GPL-2.0-or-later", | ||
"gitHead": "630288218e307d9a5e93d92b428ed30ae6a5fa2f", | ||
"gitHead": "3d0f04ee35f15e9a7906818352f6ccdd34f46fbe", | ||
"engines": { | ||
"node": ">=16.15.1", | ||
"node": ">=18.18.2", | ||
"npm": ">=8.11.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
71296
1696