@php-wasm/fs-journal 0.5.2 → 0.5.3

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.
Files changed (3) hide show
  1. package/index.cjs +9 -9
  2. package/index.js +484 -398
  3. package/package.json +3 -3
package/index.js CHANGED
@@ -1,15 +1,74 @@
1
- var re = (r, e, t) => {
1
+ var ne = (r, e, t) => {
2
2
  if (!e.has(r))
3
3
  throw TypeError("Cannot " + t);
4
4
  };
5
- var a = (r, e, t) => (re(r, e, "read from private field"), t ? t.call(r) : e.get(r)), c = (r, e, t) => {
5
+ var a = (r, e, t) => (ne(r, e, "read from private field"), t ? t.call(r) : e.get(r)), c = (r, e, t) => {
6
6
  if (e.has(r))
7
7
  throw TypeError("Cannot add the same private member more than once");
8
8
  e instanceof WeakSet ? e.add(r) : e.set(r, t);
9
- }, d = (r, e, t, s) => (re(r, e, "write to private field"), s ? s.call(r, t) : e.set(r, t), t);
10
- var m = (r, e, t) => (re(r, e, "access private method"), t);
11
- const ie = Symbol("error"), ae = Symbol("message");
12
- class ne extends Event {
9
+ }, d = (r, e, t, n) => (ne(r, e, "write to private field"), n ? n.call(r, t) : e.set(r, t), t);
10
+ var m = (r, e, t) => (ne(r, e, "access private method"), t);
11
+ if (typeof File > "u") {
12
+ class r extends Blob {
13
+ constructor(t, n, s) {
14
+ super(t);
15
+ let o;
16
+ 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 || "";
17
+ }
18
+ }
19
+ global.File = r;
20
+ }
21
+ function me(r) {
22
+ return new Promise(function(e, t) {
23
+ r.onload = r.onerror = function(n) {
24
+ r.onload = r.onerror = null, n.type === "load" ? e(r.result) : t(new Error("Failed to read the blob/file"));
25
+ };
26
+ });
27
+ }
28
+ typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
29
+ const e = new FileReader();
30
+ return e.readAsArrayBuffer(this), me(e);
31
+ });
32
+ typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
33
+ const e = new FileReader();
34
+ return e.readAsText(this), me(e);
35
+ });
36
+ function $e() {
37
+ const r = new Uint8Array([1, 2, 3, 4]), t = new File([r], "test").stream();
38
+ try {
39
+ return t.getReader({ mode: "byob" }), t.getReader({ mode: "byob" }), !0;
40
+ } catch {
41
+ return !1;
42
+ }
43
+ }
44
+ (typeof Blob.prototype.stream > "u" || !$e()) && (Blob.prototype.stream = function() {
45
+ let r = 0;
46
+ const e = this;
47
+ return new ReadableStream({
48
+ type: "bytes",
49
+ // 0.5 MB seems like a reasonable chunk size, let's adjust
50
+ // this if needed.
51
+ autoAllocateChunkSize: 512 * 1024,
52
+ async pull(t) {
53
+ const n = t.byobRequest.view, o = await e.slice(r, r + n.byteLength).arrayBuffer(), i = new Uint8Array(o);
54
+ new Uint8Array(n.buffer).set(i);
55
+ const u = i.byteLength;
56
+ t.byobRequest.respond(u), r += u, r >= e.size && t.close();
57
+ }
58
+ });
59
+ });
60
+ if (typeof CustomEvent > "u") {
61
+ class r extends Event {
62
+ constructor(t, n = {}) {
63
+ super(t, n), this.detail = n.detail;
64
+ }
65
+ initCustomEvent() {
66
+ }
67
+ }
68
+ globalThis.CustomEvent = r;
69
+ }
70
+ const ae = Symbol("error"), le = Symbol("message");
71
+ class oe extends Event {
13
72
  /**
14
73
  * Create a new `ErrorEvent`.
15
74
  *
@@ -18,22 +77,22 @@ class ne extends Event {
18
77
  * attributes via object members of the same name.
19
78
  */
20
79
  constructor(e, t = {}) {
21
- super(e), this[ie] = t.error === void 0 ? null : t.error, this[ae] = t.message === void 0 ? "" : t.message;
80
+ super(e), this[ae] = t.error === void 0 ? null : t.error, this[le] = t.message === void 0 ? "" : t.message;
22
81
  }
23
82
  get error() {
24
- return this[ie];
83
+ return this[ae];
25
84
  }
26
85
  get message() {
27
- return this[ae];
86
+ return this[le];
28
87
  }
29
88
  }
30
- Object.defineProperty(ne.prototype, "error", { enumerable: !0 });
31
- Object.defineProperty(ne.prototype, "message", { enumerable: !0 });
32
- const Oe = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ne;
33
- function $e(r) {
89
+ Object.defineProperty(oe.prototype, "error", { enumerable: !0 });
90
+ Object.defineProperty(oe.prototype, "message", { enumerable: !0 });
91
+ const Ie = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : oe;
92
+ function Ne(r) {
34
93
  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;
35
94
  }
36
- class Ie extends EventTarget {
95
+ class Me extends EventTarget {
37
96
  constructor() {
38
97
  super(...arguments), this.listenersCount = 0;
39
98
  }
@@ -47,47 +106,47 @@ class Ie extends EventTarget {
47
106
  return this.listenersCount > 0;
48
107
  }
49
108
  }
50
- function Ne(r) {
109
+ function Le(r) {
51
110
  r.asm = {
52
111
  ...r.asm
53
112
  };
54
- const e = new Ie();
113
+ const e = new Me();
55
114
  for (const t in r.asm)
56
115
  if (typeof r.asm[t] == "function") {
57
- const s = r.asm[t];
58
- r.asm[t] = function(...n) {
116
+ const n = r.asm[t];
117
+ r.asm[t] = function(...s) {
59
118
  var o;
60
119
  try {
61
- return s(...n);
120
+ return n(...s);
62
121
  } catch (i) {
63
122
  if (!(i instanceof Error))
64
123
  throw i;
65
- const h = Me(
124
+ const u = Be(
66
125
  i,
67
126
  (o = r.lastAsyncifyStackSource) == null ? void 0 : o.stack
68
127
  );
69
128
  if (r.lastAsyncifyStackSource && (i.cause = r.lastAsyncifyStackSource), e.hasListeners()) {
70
129
  e.dispatchEvent(
71
- new Oe("error", {
130
+ new Ie("error", {
72
131
  error: i,
73
- message: h
132
+ message: u
74
133
  })
75
134
  );
76
135
  return;
77
136
  }
78
- throw $e(i) || De(h), i;
137
+ throw Ne(i) || qe(u), i;
79
138
  }
80
139
  };
81
140
  }
82
141
  return e;
83
142
  }
84
143
  let se = [];
85
- function Le() {
144
+ function Ue() {
86
145
  return se;
87
146
  }
88
- function Me(r, e) {
147
+ function Be(r, e) {
89
148
  if (r.message === "unreachable") {
90
- let t = Ue;
149
+ let t = De;
91
150
  e || (t += `
92
151
 
93
152
  This stack trace is lacking. For a better one initialize
@@ -96,14 +155,14 @@ the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
96
155
  `), se = je(
97
156
  e || r.stack || ""
98
157
  );
99
- for (const s of se)
100
- t += ` * ${s}
158
+ for (const n of se)
159
+ t += ` * ${n}
101
160
  `;
102
161
  return t;
103
162
  }
104
163
  return r.message;
105
164
  }
106
- const Ue = `
165
+ const De = `
107
166
  "unreachable" WASM instruction executed.
108
167
 
109
168
  The typical reason is a PHP function missing from the ASYNCIFY_ONLY
@@ -127,39 +186,111 @@ the Dockerfile, you'll need to trigger this error again with long stack
127
186
  traces enabled. In node.js, you can do it using the --stack-trace-limit=100
128
187
  CLI option:
129
188
 
130
- `, le = "\x1B[41m", We = "\x1B[1m", ce = "\x1B[0m", he = "\x1B[K";
131
- let ue = !1;
132
- function De(r) {
133
- if (!ue) {
134
- ue = !0, console.log(`${le}
189
+ `, ce = "\x1B[41m", We = "\x1B[1m", ue = "\x1B[0m", he = "\x1B[K";
190
+ let de = !1;
191
+ function qe(r) {
192
+ if (!de) {
193
+ de = !0, console.log(`${ce}
135
194
  ${he}
136
- ${We} WASM ERROR${ce}${le}`);
195
+ ${We} WASM ERROR${ue}${ce}`);
137
196
  for (const e of r.split(`
138
197
  `))
139
198
  console.log(`${he} ${e} `);
140
- console.log(`${ce}`);
199
+ console.log(`${ue}`);
141
200
  }
142
201
  }
143
202
  function je(r) {
144
203
  try {
145
204
  const e = r.split(`
146
205
  `).slice(1).map((t) => {
147
- const s = t.trim().substring(3).split(" ");
206
+ const n = t.trim().substring(3).split(" ");
148
207
  return {
149
- fn: s.length >= 2 ? s[0] : "<unknown>",
208
+ fn: n.length >= 2 ? n[0] : "<unknown>",
150
209
  isWasm: t.includes("wasm://")
151
210
  };
152
211
  }).filter(
153
- ({ fn: t, isWasm: s }) => s && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
212
+ ({ fn: t, isWasm: n }) => n && !t.startsWith("dynCall_") && !t.startsWith("invoke_")
154
213
  ).map(({ fn: t }) => t);
155
214
  return Array.from(new Set(e));
156
215
  } catch {
157
216
  return [];
158
217
  }
159
218
  }
219
+ class ie {
220
+ constructor({ concurrency: e }) {
221
+ this._running = 0, this.concurrency = e, this.queue = [];
222
+ }
223
+ get running() {
224
+ return this._running;
225
+ }
226
+ async acquire() {
227
+ for (; ; )
228
+ if (this._running >= this.concurrency)
229
+ await new Promise((e) => this.queue.push(e));
230
+ else {
231
+ this._running++;
232
+ let e = !1;
233
+ return () => {
234
+ e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
235
+ };
236
+ }
237
+ }
238
+ async run(e) {
239
+ const t = await this.acquire();
240
+ try {
241
+ return await e();
242
+ } finally {
243
+ t();
244
+ }
245
+ }
246
+ }
247
+ function B(...r) {
248
+ let e = r.join("/");
249
+ const t = e[0] === "/", n = e.substring(e.length - 1) === "/";
250
+ return e = ye(e), !e && !t && (e = "."), e && n && (e += "/"), e;
251
+ }
252
+ function ze(r) {
253
+ if (r === "/")
254
+ return "/";
255
+ r = ye(r);
256
+ const e = r.lastIndexOf("/");
257
+ return e === -1 ? r : r.substr(e + 1);
258
+ }
259
+ function ye(r) {
260
+ const e = r[0] === "/";
261
+ return r = Ge(
262
+ r.split("/").filter((t) => !!t),
263
+ !e
264
+ ).join("/"), (e ? "/" : "") + r.replace(/\/$/, "");
265
+ }
266
+ function Ge(r, e) {
267
+ let t = 0;
268
+ for (let n = r.length - 1; n >= 0; n--) {
269
+ const s = r[n];
270
+ s === "." ? r.splice(n, 1) : s === ".." ? (r.splice(n, 1), t++) : t && (r.splice(n, 1), t--);
271
+ }
272
+ if (e)
273
+ for (; t; t--)
274
+ r.unshift("..");
275
+ return r;
276
+ }
277
+ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
278
+ const r = this.getReader();
279
+ try {
280
+ for (; ; ) {
281
+ const { done: e, value: t } = await r.read();
282
+ if (e)
283
+ return;
284
+ yield t;
285
+ }
286
+ } finally {
287
+ r.releaseLock();
288
+ }
289
+ }, ReadableStream.prototype.iterate = // @ts-ignore
290
+ ReadableStream.prototype[Symbol.asyncIterator]);
160
291
  class A {
161
- constructor(e, t, s, n = "", o = 0) {
162
- this.httpStatusCode = e, this.headers = t, this.bytes = s, this.exitCode = o, this.errors = n;
292
+ constructor(e, t, n, s = "", o = 0) {
293
+ this.httpStatusCode = e, this.headers = t, this.bytes = n, this.exitCode = o, this.errors = s;
163
294
  }
164
295
  static fromRawData(e) {
165
296
  return new A(
@@ -192,16 +323,16 @@ class A {
192
323
  return new TextDecoder().decode(this.bytes);
193
324
  }
194
325
  }
195
- var k, H;
196
- class qe {
326
+ var S, H;
327
+ class Je {
197
328
  /**
198
329
  * @param server - The PHP server to browse.
199
330
  * @param config - The browser configuration.
200
331
  */
201
332
  constructor(e, t = {}) {
202
- c(this, k, void 0);
333
+ c(this, S, void 0);
203
334
  c(this, H, void 0);
204
- this.requestHandler = e, d(this, k, {}), d(this, H, {
335
+ this.requestHandler = e, d(this, S, {}), d(this, H, {
205
336
  handleRedirects: !1,
206
337
  maxRedirects: 4,
207
338
  ...t
@@ -222,28 +353,28 @@ class qe {
222
353
  * @returns PHPRequestHandler response.
223
354
  */
224
355
  async request(e, t = 0) {
225
- const s = await this.requestHandler.request({
356
+ const n = await this.requestHandler.request({
226
357
  ...e,
227
358
  headers: {
228
359
  ...e.headers,
229
360
  cookie: this.serializeCookies()
230
361
  }
231
362
  });
232
- if (s.headers["set-cookie"] && this.setCookies(s.headers["set-cookie"]), a(this, H).handleRedirects && s.headers.location && t < a(this, H).maxRedirects) {
233
- const n = new URL(
234
- s.headers.location[0],
363
+ if (n.headers["set-cookie"] && this.setCookies(n.headers["set-cookie"]), a(this, H).handleRedirects && n.headers.location && t < a(this, H).maxRedirects) {
364
+ const s = new URL(
365
+ n.headers.location[0],
235
366
  this.requestHandler.absoluteUrl
236
367
  );
237
368
  return this.request(
238
369
  {
239
- url: n.toString(),
370
+ url: s.toString(),
240
371
  method: "GET",
241
372
  headers: {}
242
373
  },
243
374
  t + 1
244
375
  );
245
376
  }
246
- return s;
377
+ return n;
247
378
  }
248
379
  /** @inheritDoc */
249
380
  pathToInternalUrl(e) {
@@ -266,90 +397,32 @@ class qe {
266
397
  try {
267
398
  if (!t.includes("="))
268
399
  continue;
269
- const s = t.indexOf("="), n = t.substring(0, s), o = t.substring(s + 1).split(";")[0];
270
- a(this, k)[n] = o;
271
- } catch (s) {
272
- console.error(s);
400
+ const n = t.indexOf("="), s = t.substring(0, n), o = t.substring(n + 1).split(";")[0];
401
+ a(this, S)[s] = o;
402
+ } catch (n) {
403
+ console.error(n);
273
404
  }
274
405
  }
275
406
  serializeCookies() {
276
407
  const e = [];
277
- for (const t in a(this, k))
278
- e.push(`${t}=${a(this, k)[t]}`);
408
+ for (const t in a(this, S))
409
+ e.push(`${t}=${a(this, S)[t]}`);
279
410
  return e.join("; ");
280
411
  }
281
412
  }
282
- k = new WeakMap(), H = new WeakMap();
283
- class oe {
284
- constructor({ concurrency: e }) {
285
- this._running = 0, this.concurrency = e, this.queue = [];
286
- }
287
- get running() {
288
- return this._running;
289
- }
290
- async acquire() {
291
- for (; ; )
292
- if (this._running >= this.concurrency)
293
- await new Promise((e) => this.queue.push(e));
294
- else {
295
- this._running++;
296
- let e = !1;
297
- return () => {
298
- e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
299
- };
300
- }
301
- }
302
- async run(e) {
303
- const t = await this.acquire();
304
- try {
305
- return await e();
306
- } finally {
307
- t();
308
- }
309
- }
310
- }
311
- function W(...r) {
312
- let e = r.join("/");
313
- const t = e[0] === "/", s = e.substring(e.length - 1) === "/";
314
- return e = me(e), !e && !t && (e = "."), e && s && (e += "/"), e;
315
- }
316
- function Be(r) {
317
- if (r === "/")
318
- return "/";
319
- r = me(r);
320
- const e = r.lastIndexOf("/");
321
- return e === -1 ? r : r.substr(e + 1);
322
- }
323
- function me(r) {
324
- const e = r[0] === "/";
325
- return r = ze(
326
- r.split("/").filter((t) => !!t),
327
- !e
328
- ).join("/"), (e ? "/" : "") + r.replace(/\/$/, "");
329
- }
330
- function ze(r, e) {
331
- let t = 0;
332
- for (let s = r.length - 1; s >= 0; s--) {
333
- const n = r[s];
334
- n === "." ? r.splice(s, 1) : n === ".." ? (r.splice(s, 1), t++) : t && (r.splice(s, 1), t--);
335
- }
336
- if (e)
337
- for (; t; t--)
338
- r.unshift("..");
339
- return r;
340
- }
341
- const Ge = "http://example.com";
342
- function de(r) {
413
+ S = new WeakMap(), H = new WeakMap();
414
+ const Ye = "http://example.com";
415
+ function fe(r) {
343
416
  return r.toString().substring(r.origin.length);
344
417
  }
345
- function fe(r, e) {
418
+ function pe(r, e) {
346
419
  return !e || !r.startsWith(e) ? r : r.substring(e.length);
347
420
  }
348
- function Je(r, e) {
421
+ function Ve(r, e) {
349
422
  return !e || r.startsWith(e) ? r : e + r;
350
423
  }
351
- var b, O, M, x, $, P, I, N, D, ye, j, ge, q, we;
352
- class Ye {
424
+ var g, O, L, x, $, w, I, N, W, ge, q, we, j, be;
425
+ class Ke {
353
426
  /**
354
427
  * @param php - The PHP instance.
355
428
  * @param config - Request Handler configuration.
@@ -361,7 +434,7 @@ class Ye {
361
434
  * @param fsPath - Absolute path of the static file to serve.
362
435
  * @returns The response.
363
436
  */
364
- c(this, D);
437
+ c(this, W);
365
438
  /**
366
439
  * Runs the requested PHP file with all the request and $_SERVER
367
440
  * superglobals populated.
@@ -369,7 +442,7 @@ class Ye {
369
442
  * @param request - The request.
370
443
  * @returns The response.
371
444
  */
372
- c(this, j);
445
+ c(this, q);
373
446
  /**
374
447
  * Resolve the requested path to the filesystem path of the requested PHP file.
375
448
  *
@@ -379,31 +452,31 @@ class Ye {
379
452
  * @throws {Error} If the requested path doesn't exist.
380
453
  * @returns The resolved filesystem path.
381
454
  */
382
- c(this, q);
383
- c(this, b, void 0);
455
+ c(this, j);
456
+ c(this, g, void 0);
384
457
  c(this, O, void 0);
385
- c(this, M, void 0);
458
+ c(this, L, void 0);
386
459
  c(this, x, void 0);
387
460
  c(this, $, void 0);
388
- c(this, P, void 0);
461
+ c(this, w, void 0);
389
462
  c(this, I, void 0);
390
463
  c(this, N, void 0);
391
- d(this, N, new oe({ concurrency: 1 }));
464
+ d(this, N, new ie({ concurrency: 1 }));
392
465
  const {
393
- documentRoot: s = "/www/",
394
- absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : ""
466
+ documentRoot: n = "/www/",
467
+ absoluteUrl: s = typeof location == "object" ? location == null ? void 0 : location.href : ""
395
468
  } = t;
396
- this.php = e, d(this, b, s);
397
- const o = new URL(n);
398
- d(this, M, o.hostname), d(this, x, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), d(this, O, (o.protocol || "").replace(":", ""));
469
+ this.php = e, d(this, g, n);
470
+ const o = new URL(s);
471
+ d(this, L, o.hostname), d(this, x, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), d(this, O, (o.protocol || "").replace(":", ""));
399
472
  const i = a(this, x) !== 443 && a(this, x) !== 80;
400
473
  d(this, $, [
401
- a(this, M),
474
+ a(this, L),
402
475
  i ? `:${a(this, x)}` : ""
403
- ].join("")), d(this, P, o.pathname.replace(/\/+$/, "")), d(this, I, [
476
+ ].join("")), d(this, w, o.pathname.replace(/\/+$/, "")), d(this, I, [
404
477
  `${a(this, O)}://`,
405
478
  a(this, $),
406
- a(this, P)
479
+ a(this, w)
407
480
  ].join(""));
408
481
  }
409
482
  /** @inheritDoc */
@@ -413,7 +486,7 @@ class Ye {
413
486
  /** @inheritDoc */
414
487
  internalUrlToPath(e) {
415
488
  const t = new URL(e);
416
- return t.pathname.startsWith(a(this, P)) && (t.pathname = t.pathname.slice(a(this, P).length)), de(t);
489
+ return t.pathname.startsWith(a(this, w)) && (t.pathname = t.pathname.slice(a(this, w).length)), fe(t);
417
490
  }
418
491
  get isRequestRunning() {
419
492
  return a(this, N).running > 0;
@@ -424,21 +497,21 @@ class Ye {
424
497
  }
425
498
  /** @inheritDoc */
426
499
  get documentRoot() {
427
- return a(this, b);
500
+ return a(this, g);
428
501
  }
429
502
  /** @inheritDoc */
430
503
  async request(e) {
431
- const t = e.url.startsWith("http://") || e.url.startsWith("https://"), s = new URL(
504
+ const t = e.url.startsWith("http://") || e.url.startsWith("https://"), n = new URL(
432
505
  e.url,
433
- t ? void 0 : Ge
434
- ), n = fe(
435
- s.pathname,
436
- a(this, P)
437
- ), o = `${a(this, b)}${n}`;
438
- return Ze(o) ? await m(this, j, ge).call(this, e, s) : m(this, D, ye).call(this, o);
506
+ t ? void 0 : Ye
507
+ ), s = pe(
508
+ n.pathname,
509
+ a(this, w)
510
+ ), o = `${a(this, g)}${s}`;
511
+ return Xe(o) ? await m(this, q, we).call(this, e, n) : m(this, W, ge).call(this, o);
439
512
  }
440
513
  }
441
- 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) {
514
+ 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) {
442
515
  if (!this.php.fileExists(e))
443
516
  return new A(
444
517
  404,
@@ -457,47 +530,47 @@ b = new WeakMap(), O = new WeakMap(), M = new WeakMap(), x = new WeakMap(), $ =
457
530
  // @TODO: Infer the content-type from the arrayBuffer instead of the file path.
458
531
  // The code below won't return the correct mime-type if the extension
459
532
  // was tampered with.
460
- "content-type": [Ke(e)],
533
+ "content-type": [Qe(e)],
461
534
  "accept-ranges": ["bytes"],
462
535
  "cache-control": ["public, max-age=0"]
463
536
  },
464
537
  t
465
538
  );
466
- }, j = new WeakSet(), ge = async function(e, t) {
467
- var n;
468
- const s = await a(this, N).acquire();
539
+ }, q = new WeakSet(), we = async function(e, t) {
540
+ var s;
541
+ const n = await a(this, N).acquire();
469
542
  try {
470
- this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this, b)), this.php.addServerGlobalEntry(
543
+ this.php.addServerGlobalEntry("DOCUMENT_ROOT", a(this, g)), this.php.addServerGlobalEntry(
471
544
  "HTTPS",
472
545
  a(this, I).startsWith("https://") ? "on" : ""
473
546
  );
474
547
  let o = "GET";
475
548
  const i = {
476
549
  host: a(this, $),
477
- ...Ae(e.headers || {})
478
- }, h = [];
550
+ ...He(e.headers || {})
551
+ }, u = [];
479
552
  if (e.files && Object.keys(e.files).length) {
480
553
  o = "POST";
481
554
  for (const p in e.files) {
482
- const _ = e.files[p];
483
- h.push({
555
+ const R = e.files[p];
556
+ u.push({
484
557
  key: p,
485
- name: _.name,
486
- type: _.type,
487
- data: new Uint8Array(await _.arrayBuffer())
558
+ name: R.name,
559
+ type: R.type,
560
+ data: new Uint8Array(await R.arrayBuffer())
488
561
  });
489
562
  }
490
- (n = i["content-type"]) != null && n.startsWith("multipart/form-data") && (e.formData = Ve(
563
+ (s = i["content-type"]) != null && s.startsWith("multipart/form-data") && (e.formData = Ze(
491
564
  e.body || ""
492
565
  ), i["content-type"] = "application/x-www-form-urlencoded", delete e.body);
493
566
  }
494
- let u;
495
- e.formData !== void 0 ? (o = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", u = new URLSearchParams(
567
+ let h;
568
+ e.formData !== void 0 ? (o = "POST", i["content-type"] = i["content-type"] || "application/x-www-form-urlencoded", h = new URLSearchParams(
496
569
  e.formData
497
- ).toString()) : u = e.body;
570
+ ).toString()) : h = e.body;
498
571
  let f;
499
572
  try {
500
- f = m(this, q, we).call(this, t.pathname);
573
+ f = m(this, j, be).call(this, t.pathname);
501
574
  } catch {
502
575
  return new A(
503
576
  404,
@@ -506,46 +579,46 @@ b = new WeakMap(), O = new WeakMap(), M = new WeakMap(), x = new WeakMap(), $ =
506
579
  );
507
580
  }
508
581
  return await this.php.run({
509
- relativeUri: Je(
510
- de(t),
511
- a(this, P)
582
+ relativeUri: Ve(
583
+ fe(t),
584
+ a(this, w)
512
585
  ),
513
586
  protocol: a(this, O),
514
587
  method: e.method || o,
515
- body: u,
516
- fileInfos: h,
588
+ body: h,
589
+ fileInfos: u,
517
590
  scriptPath: f,
518
591
  headers: i
519
592
  });
520
593
  } finally {
521
- s();
594
+ n();
522
595
  }
523
- }, q = new WeakSet(), we = function(e) {
524
- let t = fe(e, a(this, P));
596
+ }, j = new WeakSet(), be = function(e) {
597
+ let t = pe(e, a(this, w));
525
598
  t.includes(".php") ? t = t.split(".php")[0] + ".php" : (t.endsWith("/") || (t += "/"), t.endsWith("index.php") || (t += "index.php"));
526
- const s = `${a(this, b)}${t}`;
527
- if (this.php.fileExists(s))
528
- return s;
529
- if (!this.php.fileExists(`${a(this, b)}/index.php`))
530
- throw new Error(`File not found: ${s}`);
531
- return `${a(this, b)}/index.php`;
599
+ const n = `${a(this, g)}${t}`;
600
+ if (this.php.fileExists(n))
601
+ return n;
602
+ if (!this.php.fileExists(`${a(this, g)}/index.php`))
603
+ throw new Error(`File not found: ${n}`);
604
+ return `${a(this, g)}/index.php`;
532
605
  };
533
- function Ve(r) {
606
+ function Ze(r) {
534
607
  const e = {}, t = r.match(/--(.*)\r\n/);
535
608
  if (!t)
536
609
  return e;
537
- const s = t[1], n = r.split(`--${s}`);
538
- return n.shift(), n.pop(), n.forEach((o) => {
610
+ const n = t[1], s = r.split(`--${n}`);
611
+ return s.shift(), s.pop(), s.forEach((o) => {
539
612
  const i = o.indexOf(`\r
540
613
  \r
541
- `), h = o.substring(0, i).trim(), u = o.substring(i + 4).trim(), f = h.match(/name="([^"]+)"/);
614
+ `), u = o.substring(0, i).trim(), h = o.substring(i + 4).trim(), f = u.match(/name="([^"]+)"/);
542
615
  if (f) {
543
616
  const p = f[1];
544
- e[p] = u;
617
+ e[p] = h;
545
618
  }
546
619
  }), e;
547
620
  }
548
- function Ke(r) {
621
+ function Qe(r) {
549
622
  switch (r.split(".").pop()) {
550
623
  case "css":
551
624
  return "text/css";
@@ -585,16 +658,16 @@ function Ke(r) {
585
658
  return "application-octet-stream";
586
659
  }
587
660
  }
588
- function Ze(r) {
589
- return Qe(r) || Xe(r);
661
+ function Xe(r) {
662
+ return et(r) || tt(r);
590
663
  }
591
- function Qe(r) {
664
+ function et(r) {
592
665
  return r.endsWith(".php") || r.includes(".php/");
593
666
  }
594
- function Xe(r) {
667
+ function tt(r) {
595
668
  return !r.split("/").pop().includes(".");
596
669
  }
597
- const pe = {
670
+ const D = {
598
671
  0: "No error occurred. System call completed successfully.",
599
672
  1: "Argument list too long.",
600
673
  2: "Permission denied.",
@@ -673,41 +746,46 @@ const pe = {
673
746
  75: "Cross-device link.",
674
747
  76: "Extension: Capabilities insufficient."
675
748
  };
676
- function g(r = "") {
677
- return function(t, s, n) {
678
- const o = n.value;
679
- n.value = function(...i) {
749
+ function rt(r) {
750
+ const e = typeof r == "object" ? r == null ? void 0 : r.errno : null;
751
+ if (e in D)
752
+ return D[e];
753
+ }
754
+ function b(r = "") {
755
+ return function(t, n, s) {
756
+ const o = s.value;
757
+ s.value = function(...i) {
680
758
  try {
681
759
  return o.apply(this, i);
682
- } catch (h) {
683
- const u = typeof h == "object" ? h == null ? void 0 : h.errno : null;
684
- if (u in pe) {
685
- const f = pe[u], p = typeof i[0] == "string" ? i[0] : null, _ = p !== null ? r.replaceAll("{path}", p) : r;
686
- throw new Error(`${_}: ${f}`, {
687
- cause: h
760
+ } catch (u) {
761
+ const h = typeof u == "object" ? u == null ? void 0 : u.errno : null;
762
+ if (h in D) {
763
+ const f = D[h], p = typeof i[0] == "string" ? i[0] : null, R = p !== null ? r.replaceAll("{path}", p) : r;
764
+ throw new Error(`${R}: ${f}`, {
765
+ cause: u
688
766
  });
689
767
  }
690
- throw h;
768
+ throw u;
691
769
  }
692
770
  };
693
771
  };
694
772
  }
695
- const et = /* @__PURE__ */ new Map();
696
- function tt(r) {
697
- return et.get(r);
773
+ const nt = /* @__PURE__ */ new Map();
774
+ function st(r) {
775
+ return nt.get(r);
698
776
  }
699
777
  (function() {
700
778
  var r;
701
779
  return typeof process < "u" && ((r = process.release) == null ? void 0 : r.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
702
780
  })();
703
- var rt = Object.defineProperty, st = Object.getOwnPropertyDescriptor, w = (r, e, t, s) => {
704
- for (var n = s > 1 ? void 0 : s ? st(e, t) : e, o = r.length - 1, i; o >= 0; o--)
705
- (i = r[o]) && (n = (s ? i(e, t, n) : i(n)) || n);
706
- return s && n && rt(e, t, n), n;
781
+ var ot = Object.defineProperty, it = Object.getOwnPropertyDescriptor, E = (r, e, t, n) => {
782
+ for (var s = n > 1 ? void 0 : n ? it(e, t) : e, o = r.length - 1, i; o >= 0; o--)
783
+ (i = r[o]) && (s = (n ? i(e, t, s) : i(s)) || s);
784
+ return n && s && ot(e, t, s), s;
707
785
  };
708
786
  const y = "string", C = "number", l = Symbol("__private__dont__use");
709
- 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;
710
- class E {
787
+ 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;
788
+ class P {
711
789
  /**
712
790
  * Initializes a PHP runtime.
713
791
  *
@@ -716,7 +794,6 @@ class E {
716
794
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
717
795
  */
718
796
  constructor(e, t) {
719
- c(this, B);
720
797
  c(this, z);
721
798
  c(this, G);
722
799
  c(this, J);
@@ -725,6 +802,7 @@ class E {
725
802
  c(this, K);
726
803
  c(this, Z);
727
804
  c(this, Q);
805
+ c(this, X);
728
806
  /**
729
807
  * Adds file information to $_FILES superglobal in PHP.
730
808
  *
@@ -734,36 +812,36 @@ class E {
734
812
  *
735
813
  * @param fileInfo - File details
736
814
  */
737
- c(this, X);
738
815
  c(this, ee);
739
816
  c(this, te);
740
- c(this, S, void 0);
741
- c(this, v, void 0);
742
- c(this, F, void 0);
743
- c(this, R, void 0);
817
+ c(this, re);
818
+ c(this, k, void 0);
744
819
  c(this, T, void 0);
745
- c(this, L, void 0);
820
+ c(this, F, void 0);
821
+ c(this, _, void 0);
822
+ c(this, v, void 0);
823
+ c(this, M, void 0);
746
824
  c(this, U, void 0);
747
- 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(
748
- new Ye(this, t)
825
+ 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(
826
+ new Ke(this, t)
749
827
  ));
750
828
  }
751
829
  addEventListener(e, t) {
752
- a(this, T).has(e) || a(this, T).set(e, /* @__PURE__ */ new Set()), a(this, T).get(e).add(t);
830
+ a(this, v).has(e) || a(this, v).set(e, /* @__PURE__ */ new Set()), a(this, v).get(e).add(t);
753
831
  }
754
832
  removeEventListener(e, t) {
755
- var s;
756
- (s = a(this, T).get(e)) == null || s.delete(t);
833
+ var n;
834
+ (n = a(this, v).get(e)) == null || n.delete(t);
757
835
  }
758
836
  dispatchEvent(e) {
759
- const t = a(this, T).get(e.type);
837
+ const t = a(this, v).get(e.type);
760
838
  if (t)
761
- for (const s of t)
762
- s(e);
839
+ for (const n of t)
840
+ n(e);
763
841
  }
764
842
  /** @inheritDoc */
765
843
  async onMessage(e) {
766
- a(this, L).push(e);
844
+ a(this, M).push(e);
767
845
  }
768
846
  /** @inheritDoc */
769
847
  async setSpawnHandler(e) {
@@ -790,21 +868,21 @@ class E {
790
868
  initializeRuntime(e) {
791
869
  if (this[l])
792
870
  throw new Error("PHP runtime already initialized.");
793
- const t = tt(e);
871
+ const t = st(e);
794
872
  if (!t)
795
873
  throw new Error("Invalid PHP runtime id.");
796
- this[l] = t, t.onMessage = async (s) => {
797
- for (const n of a(this, L)) {
798
- const o = await n(s);
874
+ this[l] = t, t.onMessage = async (n) => {
875
+ for (const s of a(this, M)) {
876
+ const o = await s(n);
799
877
  if (o)
800
878
  return o;
801
879
  }
802
880
  return "";
803
- }, d(this, F, Ne(t));
881
+ }, d(this, F, Le(t));
804
882
  }
805
883
  /** @inheritDoc */
806
884
  setPhpIniPath(e) {
807
- if (a(this, v))
885
+ if (a(this, T))
808
886
  throw new Error("Cannot set PHP ini path after calling run().");
809
887
  this[l].ccall(
810
888
  "wasm_set_phpini_path",
@@ -815,9 +893,9 @@ class E {
815
893
  }
816
894
  /** @inheritDoc */
817
895
  setPhpIniEntry(e, t) {
818
- if (a(this, v))
896
+ if (a(this, T))
819
897
  throw new Error("Cannot set PHP ini entries after calling run().");
820
- a(this, S).push([e, t]);
898
+ a(this, k).push([e, t]);
821
899
  }
822
900
  /** @inheritDoc */
823
901
  chdir(e) {
@@ -833,12 +911,12 @@ class E {
833
911
  async run(e) {
834
912
  const t = await a(this, U).acquire();
835
913
  try {
836
- 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");
837
- const s = Ae(e.headers || {}), n = s.host || "example.com:443";
838
- 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)
914
+ 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");
915
+ const n = He(e.headers || {}), s = n.host || "example.com:443";
916
+ 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)
839
917
  for (const o of e.fileInfos)
840
- m(this, X, Se).call(this, o);
841
- return e.code && m(this, ee, Fe).call(this, " ?>" + e.code), m(this, Q, xe).call(this), await m(this, te, Ce).call(this);
918
+ m(this, ee, Fe).call(this, o);
919
+ return e.code && m(this, te, Ce).call(this, " ?>" + e.code), m(this, X, ke).call(this), await m(this, re, Ae).call(this);
842
920
  } finally {
843
921
  t(), this.dispatchEvent({
844
922
  type: "request.end"
@@ -846,12 +924,12 @@ class E {
846
924
  }
847
925
  }
848
926
  addServerGlobalEntry(e, t) {
849
- a(this, R)[e] = t;
927
+ a(this, _)[e] = t;
850
928
  }
851
929
  defineConstant(e, t) {
852
- let s = {};
930
+ let n = {};
853
931
  try {
854
- s = JSON.parse(
932
+ n = JSON.parse(
855
933
  this.fileExists("/tmp/consts.json") && this.readFileAsText("/tmp/consts.json") || "{}"
856
934
  );
857
935
  } catch {
@@ -859,7 +937,7 @@ class E {
859
937
  this.writeFile(
860
938
  "/tmp/consts.json",
861
939
  JSON.stringify({
862
- ...s,
940
+ ...n,
863
941
  [e]: t
864
942
  })
865
943
  );
@@ -882,29 +960,40 @@ class E {
882
960
  unlink(e) {
883
961
  this[l].FS.unlink(e);
884
962
  }
963
+ /** @inheritDoc */
885
964
  mv(e, t) {
886
- this[l].FS.rename(e, t);
965
+ try {
966
+ this[l].FS.rename(e, t);
967
+ } catch (n) {
968
+ const s = rt(n);
969
+ throw s ? new Error(
970
+ `Could not move ${e} to ${t}: ${s}`,
971
+ {
972
+ cause: n
973
+ }
974
+ ) : n;
975
+ }
887
976
  }
888
977
  rmdir(e, t = { recursive: !0 }) {
889
- t != null && t.recursive && this.listFiles(e).forEach((s) => {
890
- const n = `${e}/${s}`;
891
- this.isDir(n) ? this.rmdir(n, t) : this.unlink(n);
978
+ t != null && t.recursive && this.listFiles(e).forEach((n) => {
979
+ const s = `${e}/${n}`;
980
+ this.isDir(s) ? this.rmdir(s, t) : this.unlink(s);
892
981
  }), this[l].FS.rmdir(e);
893
982
  }
894
983
  listFiles(e, t = { prependPath: !1 }) {
895
984
  if (!this.fileExists(e))
896
985
  return [];
897
986
  try {
898
- const s = this[l].FS.readdir(e).filter(
899
- (n) => n !== "." && n !== ".."
987
+ const n = this[l].FS.readdir(e).filter(
988
+ (s) => s !== "." && s !== ".."
900
989
  );
901
990
  if (t.prependPath) {
902
- const n = e.replace(/\/$/, "");
903
- return s.map((o) => `${n}/${o}`);
991
+ const s = e.replace(/\/$/, "");
992
+ return n.map((o) => `${s}/${o}`);
904
993
  }
905
- return s;
906
- } catch (s) {
907
- return console.error(s, { path: e }), [];
994
+ return n;
995
+ } catch (n) {
996
+ return console.error(n, { path: e }), [];
908
997
  }
909
998
  }
910
999
  isDir(e) {
@@ -923,7 +1012,7 @@ class E {
923
1012
  return this[l]._exit(e);
924
1013
  }
925
1014
  }
926
- 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() {
1015
+ 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() {
927
1016
  if (this.setPhpIniEntry("auto_prepend_file", "/tmp/consts.php"), this.fileExists("/tmp/consts.php") || this.writeFile(
928
1017
  "/tmp/consts.php",
929
1018
  `<?php
@@ -935,8 +1024,8 @@ S = new WeakMap(), v = new WeakMap(), F = new WeakMap(), R = new WeakMap(), T =
935
1024
  }
936
1025
  }
937
1026
  }`
938
- ), a(this, S).length > 0) {
939
- const e = a(this, S).map(([t, s]) => `${t}=${s}`).join(`
1027
+ ), a(this, k).length > 0) {
1028
+ const e = a(this, k).map(([t, n]) => `${t}=${n}`).join(`
940
1029
  `) + `
941
1030
 
942
1031
  `;
@@ -948,24 +1037,24 @@ S = new WeakMap(), v = new WeakMap(), F = new WeakMap(), R = new WeakMap(), T =
948
1037
  );
949
1038
  }
950
1039
  this[l].ccall("php_wasm_init", null, [], []);
951
- }, z = new WeakSet(), be = function() {
1040
+ }, G = new WeakSet(), Pe = function() {
952
1041
  const e = "/tmp/headers.json";
953
1042
  if (!this.fileExists(e))
954
1043
  throw new Error(
955
1044
  "SAPI Error: Could not find response headers file."
956
1045
  );
957
- const t = JSON.parse(this.readFileAsText(e)), s = {};
958
- for (const n of t.headers) {
959
- if (!n.includes(": "))
1046
+ const t = JSON.parse(this.readFileAsText(e)), n = {};
1047
+ for (const s of t.headers) {
1048
+ if (!s.includes(": "))
960
1049
  continue;
961
- const o = n.indexOf(": "), i = n.substring(0, o).toLowerCase(), h = n.substring(o + 2);
962
- i in s || (s[i] = []), s[i].push(h);
1050
+ const o = s.indexOf(": "), i = s.substring(0, o).toLowerCase(), u = s.substring(o + 2);
1051
+ i in n || (n[i] = []), n[i].push(u);
963
1052
  }
964
1053
  return {
965
- headers: s,
1054
+ headers: n,
966
1055
  httpStatusCode: t.status
967
1056
  };
968
- }, G = new WeakSet(), Pe = function(e) {
1057
+ }, J = new WeakSet(), Re = function(e) {
969
1058
  if (this[l].ccall(
970
1059
  "wasm_set_request_uri",
971
1060
  null,
@@ -980,32 +1069,32 @@ S = new WeakMap(), v = new WeakMap(), F = new WeakMap(), R = new WeakMap(), T =
980
1069
  [t]
981
1070
  );
982
1071
  }
983
- }, J = new WeakSet(), _e = function(e, t) {
1072
+ }, Y = new WeakSet(), ve = function(e, t) {
984
1073
  this[l].ccall(
985
1074
  "wasm_set_request_host",
986
1075
  null,
987
1076
  [y],
988
1077
  [e]
989
1078
  );
990
- let s;
1079
+ let n;
991
1080
  try {
992
- s = parseInt(new URL(e).port, 10);
1081
+ n = parseInt(new URL(e).port, 10);
993
1082
  } catch {
994
1083
  }
995
- (!s || isNaN(s) || s === 80) && (s = t === "https" ? 443 : 80), this[l].ccall(
1084
+ (!n || isNaN(n) || n === 80) && (n = t === "https" ? 443 : 80), this[l].ccall(
996
1085
  "wasm_set_request_port",
997
1086
  null,
998
1087
  [C],
999
- [s]
1000
- ), (t === "https" || !t && s === 443) && this.addServerGlobalEntry("HTTPS", "on");
1001
- }, Y = new WeakSet(), Te = function(e) {
1088
+ [n]
1089
+ ), (t === "https" || !t && n === 443) && this.addServerGlobalEntry("HTTPS", "on");
1090
+ }, V = new WeakSet(), Te = function(e) {
1002
1091
  this[l].ccall(
1003
1092
  "wasm_set_request_method",
1004
1093
  null,
1005
1094
  [y],
1006
1095
  [e]
1007
1096
  );
1008
- }, V = new WeakSet(), ve = function(e) {
1097
+ }, K = new WeakSet(), _e = function(e) {
1009
1098
  e.cookie && this[l].ccall(
1010
1099
  "wasm_set_cookies",
1011
1100
  null,
@@ -1023,13 +1112,13 @@ S = new WeakMap(), v = new WeakMap(), F = new WeakMap(), R = new WeakMap(), T =
1023
1112
  [parseInt(e["content-length"], 10)]
1024
1113
  );
1025
1114
  for (const t in e) {
1026
- let s = "HTTP_";
1027
- ["content-type", "content-length"].includes(t.toLowerCase()) && (s = ""), this.addServerGlobalEntry(
1028
- `${s}${t.toUpperCase().replace(/-/g, "_")}`,
1115
+ let n = "HTTP_";
1116
+ ["content-type", "content-length"].includes(t.toLowerCase()) && (n = ""), this.addServerGlobalEntry(
1117
+ `${n}${t.toUpperCase().replace(/-/g, "_")}`,
1029
1118
  e[t]
1030
1119
  );
1031
1120
  }
1032
- }, K = new WeakSet(), Re = function(e) {
1121
+ }, Z = new WeakSet(), Se = function(e) {
1033
1122
  this[l].ccall(
1034
1123
  "wasm_set_request_body",
1035
1124
  null,
@@ -1041,59 +1130,59 @@ S = new WeakMap(), v = new WeakMap(), F = new WeakMap(), R = new WeakMap(), T =
1041
1130
  [C],
1042
1131
  [new TextEncoder().encode(e).length]
1043
1132
  );
1044
- }, Z = new WeakSet(), ke = function(e) {
1133
+ }, Q = new WeakSet(), xe = function(e) {
1045
1134
  this[l].ccall(
1046
1135
  "wasm_set_path_translated",
1047
1136
  null,
1048
1137
  [y],
1049
1138
  [e]
1050
1139
  );
1051
- }, Q = new WeakSet(), xe = function() {
1052
- for (const e in a(this, R))
1140
+ }, X = new WeakSet(), ke = function() {
1141
+ for (const e in a(this, _))
1053
1142
  this[l].ccall(
1054
1143
  "wasm_add_SERVER_entry",
1055
1144
  null,
1056
1145
  [y, y],
1057
- [e, a(this, R)[e]]
1146
+ [e, a(this, _)[e]]
1058
1147
  );
1059
- }, X = new WeakSet(), Se = function(e) {
1060
- const { key: t, name: s, type: n, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
1148
+ }, ee = new WeakSet(), Fe = function(e) {
1149
+ const { key: t, name: n, type: s, data: o } = e, i = `/tmp/${Math.random().toFixed(20)}`;
1061
1150
  this.writeFile(i, o);
1062
- const h = 0;
1151
+ const u = 0;
1063
1152
  this[l].ccall(
1064
1153
  "wasm_add_uploaded_file",
1065
1154
  null,
1066
1155
  [y, y, y, y, C, C],
1067
- [t, s, n, i, h, o.byteLength]
1156
+ [t, n, s, i, u, o.byteLength]
1068
1157
  );
1069
- }, ee = new WeakSet(), Fe = function(e) {
1158
+ }, te = new WeakSet(), Ce = function(e) {
1070
1159
  this[l].ccall(
1071
1160
  "wasm_set_php_code",
1072
1161
  null,
1073
1162
  [y],
1074
1163
  [e]
1075
1164
  );
1076
- }, te = new WeakSet(), Ce = async function() {
1165
+ }, re = new WeakSet(), Ae = async function() {
1077
1166
  var o;
1078
1167
  let e, t;
1079
1168
  try {
1080
- e = await new Promise((i, h) => {
1169
+ e = await new Promise((i, u) => {
1081
1170
  var f;
1082
1171
  t = (p) => {
1083
- const _ = new Error("Rethrown");
1084
- _.cause = p.error, _.betterMessage = p.message, h(_);
1172
+ const R = new Error("Rethrown");
1173
+ R.cause = p.error, R.betterMessage = p.message, u(R);
1085
1174
  }, (f = a(this, F)) == null || f.addEventListener(
1086
1175
  "error",
1087
1176
  t
1088
1177
  );
1089
- const u = this[l].ccall(
1178
+ const h = this[l].ccall(
1090
1179
  "wasm_sapi_handle_request",
1091
1180
  C,
1092
1181
  [],
1093
1182
  [],
1094
1183
  { async: !0 }
1095
1184
  );
1096
- return u instanceof Promise ? u.then(i, h) : i(u);
1185
+ return h instanceof Promise ? h.then(i, u) : i(h);
1097
1186
  });
1098
1187
  } catch (i) {
1099
1188
  for (const p in this)
@@ -1102,92 +1191,89 @@ S = new WeakMap(), v = new WeakMap(), F = new WeakMap(), R = new WeakMap(), T =
1102
1191
  "PHP runtime has crashed – see the earlier error for details."
1103
1192
  );
1104
1193
  });
1105
- this.functionsMaybeMissingFromAsyncify = Le();
1106
- const h = i, u = "betterMessage" in h ? h.betterMessage : h.message, f = new Error(u);
1107
- throw f.cause = h, f;
1194
+ this.functionsMaybeMissingFromAsyncify = Ue();
1195
+ const u = i, h = "betterMessage" in u ? u.betterMessage : u.message, f = new Error(h);
1196
+ throw f.cause = u, f;
1108
1197
  } finally {
1109
- (o = a(this, F)) == null || o.removeEventListener("error", t), d(this, R, {});
1198
+ (o = a(this, F)) == null || o.removeEventListener("error", t), d(this, _, {});
1110
1199
  }
1111
- const { headers: s, httpStatusCode: n } = m(this, z, be).call(this);
1200
+ const { headers: n, httpStatusCode: s } = m(this, G, Pe).call(this);
1112
1201
  return new A(
1113
- n,
1114
1202
  s,
1203
+ n,
1115
1204
  this.readFileAsBuffer("/tmp/stdout"),
1116
1205
  this.readFileAsText("/tmp/stderr"),
1117
1206
  e
1118
1207
  );
1119
1208
  };
1120
- w([
1121
- g('Could not create directory "{path}"')
1122
- ], E.prototype, "mkdir", 1);
1123
- w([
1124
- g('Could not create directory "{path}"')
1125
- ], E.prototype, "mkdirTree", 1);
1126
- w([
1127
- g('Could not read "{path}"')
1128
- ], E.prototype, "readFileAsText", 1);
1129
- w([
1130
- g('Could not read "{path}"')
1131
- ], E.prototype, "readFileAsBuffer", 1);
1132
- w([
1133
- g('Could not write to "{path}"')
1134
- ], E.prototype, "writeFile", 1);
1135
- w([
1136
- g('Could not unlink "{path}"')
1137
- ], E.prototype, "unlink", 1);
1138
- w([
1139
- g('Could not move "{path}"')
1140
- ], E.prototype, "mv", 1);
1141
- w([
1142
- g('Could not remove directory "{path}"')
1143
- ], E.prototype, "rmdir", 1);
1144
- w([
1145
- g('Could not list files in "{path}"')
1146
- ], E.prototype, "listFiles", 1);
1147
- w([
1148
- g('Could not stat "{path}"')
1149
- ], E.prototype, "isDir", 1);
1150
- w([
1151
- g('Could not stat "{path}"')
1152
- ], E.prototype, "fileExists", 1);
1153
- function Ae(r) {
1209
+ E([
1210
+ b('Could not create directory "{path}"')
1211
+ ], P.prototype, "mkdir", 1);
1212
+ E([
1213
+ b('Could not create directory "{path}"')
1214
+ ], P.prototype, "mkdirTree", 1);
1215
+ E([
1216
+ b('Could not read "{path}"')
1217
+ ], P.prototype, "readFileAsText", 1);
1218
+ E([
1219
+ b('Could not read "{path}"')
1220
+ ], P.prototype, "readFileAsBuffer", 1);
1221
+ E([
1222
+ b('Could not write to "{path}"')
1223
+ ], P.prototype, "writeFile", 1);
1224
+ E([
1225
+ b('Could not unlink "{path}"')
1226
+ ], P.prototype, "unlink", 1);
1227
+ E([
1228
+ b('Could not remove directory "{path}"')
1229
+ ], P.prototype, "rmdir", 1);
1230
+ E([
1231
+ b('Could not list files in "{path}"')
1232
+ ], P.prototype, "listFiles", 1);
1233
+ E([
1234
+ b('Could not stat "{path}"')
1235
+ ], P.prototype, "isDir", 1);
1236
+ E([
1237
+ b('Could not stat "{path}"')
1238
+ ], P.prototype, "fileExists", 1);
1239
+ function He(r) {
1154
1240
  const e = {};
1155
1241
  for (const t in r)
1156
1242
  e[t.toLowerCase()] = r[t];
1157
1243
  return e;
1158
1244
  }
1159
- function ut(r, e, t = () => {
1245
+ function pt(r, e, t = () => {
1160
1246
  }) {
1161
- e = ot(e);
1162
- const s = r[l].FS, n = nt(s, (u) => {
1163
- if (u.path.startsWith(e))
1164
- t(u);
1165
- else if (u.operation === "RENAME" && u.toPath.startsWith(e))
1166
- for (const f of He(
1247
+ e = lt(e);
1248
+ const n = r[l].FS, s = at(n, (h) => {
1249
+ if (h.path.startsWith(e))
1250
+ t(h);
1251
+ else if (h.operation === "RENAME" && h.toPath.startsWith(e))
1252
+ for (const f of Oe(
1167
1253
  r,
1168
- u.path,
1169
- u.toPath
1254
+ h.path,
1255
+ h.toPath
1170
1256
  ))
1171
1257
  t(f);
1172
1258
  }), o = {};
1173
- for (const [u] of Object.entries(n))
1174
- o[u] = s[u];
1259
+ for (const [h] of Object.entries(s))
1260
+ o[h] = n[h];
1175
1261
  function i() {
1176
- for (const [u, f] of Object.entries(n))
1177
- s[u] = function(...p) {
1178
- return f(...p), o[u].apply(this, p);
1262
+ for (const [h, f] of Object.entries(s))
1263
+ n[h] = function(...p) {
1264
+ return f(...p), o[h].apply(this, p);
1179
1265
  };
1180
1266
  }
1181
- function h() {
1182
- for (const [u, f] of Object.entries(o))
1183
- r[l].FS[u] = f;
1267
+ function u() {
1268
+ for (const [h, f] of Object.entries(o))
1269
+ r[l].FS[h] = f;
1184
1270
  }
1185
1271
  return r[l].journal = {
1186
1272
  bind: i,
1187
- unbind: h
1188
- }, i(), h;
1273
+ unbind: u
1274
+ }, i(), u;
1189
1275
  }
1190
- const nt = (r, e = () => {
1276
+ const at = (r, e = () => {
1191
1277
  }) => ({
1192
1278
  write(t) {
1193
1279
  e({
@@ -1197,12 +1283,12 @@ const nt = (r, e = () => {
1197
1283
  });
1198
1284
  },
1199
1285
  truncate(t) {
1200
- let s;
1201
- typeof t == "string" ? s = r.lookupPath(t, {
1286
+ let n;
1287
+ typeof t == "string" ? n = r.lookupPath(t, {
1202
1288
  follow: !0
1203
- }).node : s = t, e({
1289
+ }).node : n = t, e({
1204
1290
  operation: "WRITE",
1205
- path: r.getPath(s),
1291
+ path: r.getPath(n),
1206
1292
  nodeType: "file"
1207
1293
  });
1208
1294
  },
@@ -1213,8 +1299,8 @@ const nt = (r, e = () => {
1213
1299
  nodeType: "file"
1214
1300
  });
1215
1301
  },
1216
- mknod(t, s) {
1217
- r.isFile(s) && e({
1302
+ mknod(t, n) {
1303
+ r.isFile(n) && e({
1218
1304
  operation: "CREATE",
1219
1305
  path: t,
1220
1306
  nodeType: "file"
@@ -1234,24 +1320,24 @@ const nt = (r, e = () => {
1234
1320
  nodeType: "directory"
1235
1321
  });
1236
1322
  },
1237
- rename(t, s) {
1323
+ rename(t, n) {
1238
1324
  try {
1239
- const n = r.lookupPath(t, {
1325
+ const s = r.lookupPath(t, {
1240
1326
  follow: !0
1241
- }), o = r.lookupPath(s, {
1327
+ }), o = r.lookupPath(n, {
1242
1328
  parent: !0
1243
1329
  }).path;
1244
1330
  e({
1245
1331
  operation: "RENAME",
1246
- nodeType: r.isDir(n.node.mode) ? "directory" : "file",
1247
- path: n.path,
1248
- toPath: W(o, Be(s))
1332
+ nodeType: r.isDir(s.node.mode) ? "directory" : "file",
1333
+ path: s.path,
1334
+ toPath: B(o, ze(n))
1249
1335
  });
1250
1336
  } catch {
1251
1337
  }
1252
1338
  }
1253
1339
  });
1254
- function dt(r, e) {
1340
+ function mt(r, e) {
1255
1341
  r[l].journal.unbind();
1256
1342
  try {
1257
1343
  for (const t of e)
@@ -1260,18 +1346,18 @@ function dt(r, e) {
1260
1346
  r[l].journal.bind();
1261
1347
  }
1262
1348
  }
1263
- function* He(r, e, t) {
1349
+ function* Oe(r, e, t) {
1264
1350
  if (r.isDir(e)) {
1265
1351
  yield {
1266
1352
  operation: "CREATE",
1267
1353
  path: t,
1268
1354
  nodeType: "directory"
1269
1355
  };
1270
- for (const s of r.listFiles(e))
1271
- yield* He(
1356
+ for (const n of r.listFiles(e))
1357
+ yield* Oe(
1272
1358
  r,
1273
- W(e, s),
1274
- W(t, s)
1359
+ B(e, n),
1360
+ B(t, n)
1275
1361
  );
1276
1362
  } else
1277
1363
  yield {
@@ -1284,17 +1370,17 @@ function* He(r, e, t) {
1284
1370
  path: t
1285
1371
  };
1286
1372
  }
1287
- function ot(r) {
1373
+ function lt(r) {
1288
1374
  return r.replace(/\/$/, "").replace(/\/\/+/g, "/");
1289
1375
  }
1290
- function it(r) {
1376
+ function ct(r) {
1291
1377
  const e = {};
1292
1378
  for (let t = r.length - 1; t >= 0; t--) {
1293
- for (let s = t - 1; s >= 0; s--) {
1294
- const n = at(r[t], r[s]);
1295
- if (n === "none")
1379
+ for (let n = t - 1; n >= 0; n--) {
1380
+ const s = ut(r[t], r[n]);
1381
+ if (s === "none")
1296
1382
  continue;
1297
- const o = r[t], i = r[s];
1383
+ const o = r[t], i = r[n];
1298
1384
  if (o.operation === "RENAME" && i.operation === "RENAME") {
1299
1385
  console.warn(
1300
1386
  "[FS Journal] Normalizing a double rename is not yet supported:",
@@ -1305,55 +1391,55 @@ function it(r) {
1305
1391
  );
1306
1392
  continue;
1307
1393
  }
1308
- (i.operation === "CREATE" || i.operation === "WRITE") && (o.operation === "RENAME" ? n === "same_node" ? (e[s] = [], e[t] = [
1394
+ (i.operation === "CREATE" || i.operation === "WRITE") && (o.operation === "RENAME" ? s === "same_node" ? (e[n] = [], e[t] = [
1309
1395
  {
1310
1396
  ...i,
1311
1397
  path: o.toPath
1312
1398
  },
1313
1399
  ...e[t] || []
1314
- ]) : n === "descendant" && (e[s] = [], e[t] = [
1400
+ ]) : s === "descendant" && (e[n] = [], e[t] = [
1315
1401
  {
1316
1402
  ...i,
1317
- path: W(
1403
+ path: B(
1318
1404
  o.toPath,
1319
1405
  i.path.substring(o.path.length)
1320
1406
  )
1321
1407
  },
1322
1408
  ...e[t] || []
1323
- ]) : o.operation === "WRITE" && n === "same_node" ? e[s] = [] : o.operation === "DELETE" && n === "same_node" && (e[s] = [], e[t] = []));
1409
+ ]) : o.operation === "WRITE" && s === "same_node" ? e[n] = [] : o.operation === "DELETE" && s === "same_node" && (e[n] = [], e[t] = []));
1324
1410
  }
1325
1411
  if (Object.entries(e).length > 0) {
1326
- const s = r.flatMap((n, o) => o in e ? e[o] : [n]);
1327
- return it(s);
1412
+ const n = r.flatMap((s, o) => o in e ? e[o] : [s]);
1413
+ return ct(n);
1328
1414
  }
1329
1415
  }
1330
1416
  return r;
1331
1417
  }
1332
- function at(r, e) {
1333
- 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;
1334
- return o === t ? "same_node" : n && t.startsWith(o + "/") ? "ancestor" : s && o.startsWith(t + "/") ? "descendant" : "none";
1418
+ function ut(r, e) {
1419
+ 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;
1420
+ return o === t ? "same_node" : s && t.startsWith(o + "/") ? "ancestor" : n && o.startsWith(t + "/") ? "descendant" : "none";
1335
1421
  }
1336
- async function ft(r, e) {
1337
- const s = e.filter(
1338
- (n) => n.operation === "WRITE"
1339
- ).map((n) => ct(r, n));
1340
- return await Promise.all(s), e;
1422
+ async function yt(r, e) {
1423
+ const n = e.filter(
1424
+ (s) => s.operation === "WRITE"
1425
+ ).map((s) => dt(r, s));
1426
+ return await Promise.all(n), e;
1341
1427
  }
1342
- const lt = new oe({ concurrency: 15 });
1343
- async function ct(r, e) {
1344
- const t = await lt.acquire();
1428
+ const ht = new ie({ concurrency: 15 });
1429
+ async function dt(r, e) {
1430
+ const t = await ht.acquire();
1345
1431
  try {
1346
1432
  e.data = await r.readFileAsBuffer(e.path);
1347
- } catch (s) {
1433
+ } catch (n) {
1348
1434
  console.warn(
1349
1435
  `Journal failed to hydrate a file on flush: the path ${e.path} no longer exists`
1350
- ), console.error(s);
1436
+ ), console.error(n);
1351
1437
  }
1352
1438
  t();
1353
1439
  }
1354
1440
  export {
1355
- ft as hydrateUpdateFileOps,
1356
- ut as journalFSEvents,
1357
- it as normalizeFilesystemOperations,
1358
- dt as replayFSJournal
1441
+ yt as hydrateUpdateFileOps,
1442
+ pt as journalFSEvents,
1443
+ ct as normalizeFilesystemOperations,
1444
+ mt as replayFSJournal
1359
1445
  };