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