@php-wasm/fs-journal 0.7.20 → 0.9.2

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,30 +1,20 @@
1
- var H = (e, t, r) => {
2
- if (!t.has(e))
3
- throw TypeError("Cannot " + r);
4
- };
5
- var f = (e, t, r) => (H(e, t, "read from private field"), r ? r.call(e) : t.get(e)), d = (e, t, r) => {
6
- if (t.has(e))
7
- throw TypeError("Cannot add the same private member more than once");
8
- t instanceof WeakSet ? t.add(e) : t.set(e, r);
9
- }, p = (e, t, r, s) => (H(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
10
- var h = (e, t, r) => (H(e, t, "access private method"), r);
11
- const currentJsRuntime = function() {
12
- var e;
13
- return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
1
+ const C = function() {
2
+ var r;
3
+ return typeof process < "u" && ((r = process.release) == null ? void 0 : r.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
14
4
  // @ts-ignore
15
5
  typeof WorkerGlobalScope < "u" && // @ts-ignore
16
6
  self instanceof WorkerGlobalScope ? "WORKER" : "NODE"
17
7
  );
18
8
  }();
19
- if (currentJsRuntime === "NODE") {
20
- let e = function(r) {
21
- return new Promise(function(s, n) {
22
- r.onload = r.onerror = function(i) {
23
- r.onload = r.onerror = null, i.type === "load" ? s(r.result) : n(new Error("Failed to read the blob/file"));
9
+ if (C === "NODE") {
10
+ let r = function(t) {
11
+ return new Promise(function(o, n) {
12
+ t.onload = t.onerror = function(i) {
13
+ t.onload = t.onerror = null, i.type === "load" ? o(t.result) : n(new Error("Failed to read the blob/file"));
24
14
  };
25
15
  });
26
- }, t = function() {
27
- const r = new Uint8Array([1, 2, 3, 4]), n = new File([r], "test").stream();
16
+ }, e = function() {
17
+ const t = new Uint8Array([1, 2, 3, 4]), n = new File([t], "test").stream();
28
18
  try {
29
19
  return n.getReader({ mode: "byob" }), !0;
30
20
  } catch {
@@ -32,111 +22,52 @@ if (currentJsRuntime === "NODE") {
32
22
  }
33
23
  };
34
24
  if (typeof File > "u") {
35
- class r extends Blob {
36
- constructor(n, i, o) {
25
+ class t extends Blob {
26
+ constructor(n, i, s) {
37
27
  super(n);
38
28
  let a;
39
- o != null && o.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = i || "";
29
+ s != null && s.lastModified && (a = /* @__PURE__ */ new Date()), (!a || isNaN(a.getFullYear())) && (a = /* @__PURE__ */ new Date()), this.lastModifiedDate = a, this.lastModified = a.getMilliseconds(), this.name = i || "";
40
30
  }
41
31
  }
42
- global.File = r;
32
+ global.File = t;
43
33
  }
44
34
  typeof Blob.prototype.arrayBuffer > "u" && (Blob.prototype.arrayBuffer = function() {
45
- const s = new FileReader();
46
- return s.readAsArrayBuffer(this), e(s);
35
+ const o = new FileReader();
36
+ return o.readAsArrayBuffer(this), r(o);
47
37
  }), typeof Blob.prototype.text > "u" && (Blob.prototype.text = function() {
48
- const s = new FileReader();
49
- return s.readAsText(this), e(s);
50
- }), (typeof Blob.prototype.stream > "u" || !t()) && (Blob.prototype.stream = function() {
51
- let r = 0;
52
- const s = this;
38
+ const o = new FileReader();
39
+ return o.readAsText(this), r(o);
40
+ }), (typeof Blob.prototype.stream > "u" || !e()) && (Blob.prototype.stream = function() {
41
+ let t = 0;
42
+ const o = this;
53
43
  return new ReadableStream({
54
44
  type: "bytes",
55
45
  // 0.5 MB seems like a reasonable chunk size, let's adjust
56
46
  // this if needed.
57
47
  autoAllocateChunkSize: 512 * 1024,
58
48
  async pull(n) {
59
- const i = n.byobRequest.view, a = await s.slice(
60
- r,
61
- r + i.byteLength
62
- ).arrayBuffer(), l = new Uint8Array(a);
63
- new Uint8Array(i.buffer).set(l);
64
- const c = l.byteLength;
65
- n.byobRequest.respond(c), r += c, r >= s.size && n.close();
49
+ const i = n.byobRequest.view, a = await o.slice(
50
+ t,
51
+ t + i.byteLength
52
+ ).arrayBuffer(), m = new Uint8Array(a);
53
+ new Uint8Array(i.buffer).set(m);
54
+ const h = m.byteLength;
55
+ n.byobRequest.respond(h), t += h, t >= o.size && n.close();
66
56
  }
67
57
  });
68
58
  });
69
59
  }
70
- if (currentJsRuntime === "NODE" && typeof CustomEvent > "u") {
71
- class e extends Event {
72
- constructor(r, s = {}) {
73
- super(r, s), this.detail = s.detail;
60
+ if (C === "NODE" && typeof CustomEvent > "u") {
61
+ class r extends Event {
62
+ constructor(t, o = {}) {
63
+ super(t, o), this.detail = o.detail;
74
64
  }
75
65
  initCustomEvent() {
76
66
  }
77
67
  }
78
- globalThis.CustomEvent = e;
68
+ globalThis.CustomEvent = r;
79
69
  }
80
- const responseTexts = {
81
- 500: "Internal Server Error",
82
- 502: "Bad Gateway",
83
- 404: "Not Found",
84
- 403: "Forbidden",
85
- 401: "Unauthorized",
86
- 400: "Bad Request",
87
- 301: "Moved Permanently",
88
- 302: "Found",
89
- 307: "Temporary Redirect",
90
- 308: "Permanent Redirect",
91
- 204: "No Content",
92
- 201: "Created",
93
- 200: "OK"
94
- };
95
- class PHPResponse {
96
- constructor(t, r, s, n = "", i = 0) {
97
- this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = i, this.errors = n;
98
- }
99
- static forHttpCode(t, r = "") {
100
- return new PHPResponse(
101
- t,
102
- {},
103
- new TextEncoder().encode(
104
- r || responseTexts[t] || ""
105
- )
106
- );
107
- }
108
- static fromRawData(t) {
109
- return new PHPResponse(
110
- t.httpStatusCode,
111
- t.headers,
112
- t.bytes,
113
- t.errors,
114
- t.exitCode
115
- );
116
- }
117
- toRawData() {
118
- return {
119
- headers: this.headers,
120
- bytes: this.bytes,
121
- errors: this.errors,
122
- exitCode: this.exitCode,
123
- httpStatusCode: this.httpStatusCode
124
- };
125
- }
126
- /**
127
- * Response body as JSON.
128
- */
129
- get json() {
130
- return JSON.parse(this.text);
131
- }
132
- /**
133
- * Response body as text.
134
- */
135
- get text() {
136
- return new TextDecoder().decode(this.bytes);
137
- }
138
- }
139
- const FileErrorCodes = {
70
+ const E = {
140
71
  0: "No error occurred. System call completed successfully.",
141
72
  1: "Argument list too long.",
142
73
  2: "Permission denied.",
@@ -215,22 +146,22 @@ const FileErrorCodes = {
215
146
  75: "Cross-device link.",
216
147
  76: "Extension: Capabilities insufficient."
217
148
  };
218
- function getEmscriptenFsError(e) {
219
- const t = typeof e == "object" ? e == null ? void 0 : e.errno : null;
220
- if (t in FileErrorCodes)
221
- return FileErrorCodes[t];
149
+ function O(r) {
150
+ const e = typeof r == "object" ? r == null ? void 0 : r.errno : null;
151
+ if (e in E)
152
+ return E[e];
222
153
  }
223
- function rethrowFileSystemError(e = "") {
224
- return function(r, s, n) {
154
+ function u(r = "") {
155
+ return function(t, o, n) {
225
156
  const i = n.value;
226
- n.value = function(...o) {
157
+ n.value = function(...s) {
227
158
  try {
228
- return i.apply(this, o);
159
+ return i.apply(this, s);
229
160
  } catch (a) {
230
- const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
231
- if (l in FileErrorCodes) {
232
- const c = FileErrorCodes[l], u = typeof o[0] == "string" ? o[0] : null, g = u !== null ? e.replaceAll("{path}", u) : e;
233
- throw new Error(`${g}: ${c}`, {
161
+ const m = typeof a == "object" ? a == null ? void 0 : a.errno : null;
162
+ if (m in E) {
163
+ const h = E[m], l = typeof s[1] == "string" ? s[1] : null, y = l !== null ? r.replaceAll("{path}", l) : r;
164
+ throw new Error(`${y}: ${h}`, {
234
165
  cause: a
235
166
  });
236
167
  }
@@ -239,52 +170,61 @@ function rethrowFileSystemError(e = "") {
239
170
  };
240
171
  };
241
172
  }
242
- const logToConsole = (e, ...t) => {
243
- switch (typeof e.message == "string" ? e.message = prepareLogMessage(e.message) : e.message.message && typeof e.message.message == "string" && (e.message.message = prepareLogMessage(e.message.message)), e.severity) {
173
+ const x = "playground-log", R = (r, ...e) => {
174
+ b.dispatchEvent(
175
+ new CustomEvent(x, {
176
+ detail: {
177
+ log: r,
178
+ args: e
179
+ }
180
+ })
181
+ );
182
+ }, I = (r, ...e) => {
183
+ switch (typeof r.message == "string" ? r.message = w(r.message) : r.message.message && typeof r.message.message == "string" && (r.message.message = w(r.message.message)), r.severity) {
244
184
  case "Debug":
245
- console.debug(e.message, ...t);
185
+ console.debug(r.message, ...e);
246
186
  break;
247
187
  case "Info":
248
- console.info(e.message, ...t);
188
+ console.info(r.message, ...e);
249
189
  break;
250
190
  case "Warn":
251
- console.warn(e.message, ...t);
191
+ console.warn(r.message, ...e);
252
192
  break;
253
193
  case "Error":
254
- console.error(e.message, ...t);
194
+ console.error(r.message, ...e);
255
195
  break;
256
196
  case "Fatal":
257
- console.error(e.message, ...t);
197
+ console.error(r.message, ...e);
258
198
  break;
259
199
  default:
260
- console.log(e.message, ...t);
261
- }
262
- }, prepareLogMessage$1 = (e) => e instanceof Error ? [e.message, e.stack].join(`
263
- `) : JSON.stringify(e, null, 2), logs = [], addToLogArray = (e) => {
264
- logs.push(e);
265
- }, logToMemory = (e) => {
266
- if (e.raw === !0)
267
- addToLogArray(e.message);
200
+ console.log(r.message, ...e);
201
+ }
202
+ }, B = (r) => r instanceof Error ? [r.message, r.stack].join(`
203
+ `) : JSON.stringify(r, null, 2), N = [], A = (r) => {
204
+ N.push(r);
205
+ }, v = (r) => {
206
+ if (r.raw === !0)
207
+ A(r.message);
268
208
  else {
269
- const t = formatLogEntry(
270
- typeof e.message == "object" ? prepareLogMessage$1(e.message) : e.message,
271
- e.severity ?? "Info",
272
- e.prefix ?? "JavaScript"
209
+ const e = W(
210
+ typeof r.message == "object" ? B(r.message) : r.message,
211
+ r.severity ?? "Info",
212
+ r.prefix ?? "JavaScript"
273
213
  );
274
- addToLogArray(t);
214
+ A(e);
275
215
  }
276
216
  };
277
- class Logger extends EventTarget {
217
+ class P extends EventTarget {
278
218
  // constructor
279
- constructor(t = []) {
280
- super(), this.handlers = t, this.fatalErrorEvent = "playground-fatal-error";
219
+ constructor(e = []) {
220
+ super(), this.handlers = e, this.fatalErrorEvent = "playground-fatal-error";
281
221
  }
282
222
  /**
283
223
  * Get all logs.
284
224
  * @returns string[]
285
225
  */
286
226
  getLogs() {
287
- return this.handlers.includes(logToMemory) ? [...logs] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
227
+ return this.handlers.includes(v) ? [...N] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
288
228
  If you're using a custom logger instance, make sure to register logToMemory handler.
289
229
  `), []);
290
230
  }
@@ -296,9 +236,9 @@ class Logger extends EventTarget {
296
236
  * @param raw boolean
297
237
  * @param args any
298
238
  */
299
- logMessage(t, ...r) {
300
- for (const s of this.handlers)
301
- s(t, ...r);
239
+ logMessage(e, ...t) {
240
+ for (const o of this.handlers)
241
+ o(e, ...t);
302
242
  }
303
243
  /**
304
244
  * Log message
@@ -306,15 +246,15 @@ class Logger extends EventTarget {
306
246
  * @param message any
307
247
  * @param args any
308
248
  */
309
- log(t, ...r) {
249
+ log(e, ...t) {
310
250
  this.logMessage(
311
251
  {
312
- message: t,
252
+ message: e,
313
253
  severity: void 0,
314
254
  prefix: "JavaScript",
315
255
  raw: !1
316
256
  },
317
- ...r
257
+ ...t
318
258
  );
319
259
  }
320
260
  /**
@@ -323,15 +263,15 @@ class Logger extends EventTarget {
323
263
  * @param message any
324
264
  * @param args any
325
265
  */
326
- debug(t, ...r) {
266
+ debug(e, ...t) {
327
267
  this.logMessage(
328
268
  {
329
- message: t,
269
+ message: e,
330
270
  severity: "Debug",
331
271
  prefix: "JavaScript",
332
272
  raw: !1
333
273
  },
334
- ...r
274
+ ...t
335
275
  );
336
276
  }
337
277
  /**
@@ -340,15 +280,15 @@ class Logger extends EventTarget {
340
280
  * @param message any
341
281
  * @param args any
342
282
  */
343
- info(t, ...r) {
283
+ info(e, ...t) {
344
284
  this.logMessage(
345
285
  {
346
- message: t,
286
+ message: e,
347
287
  severity: "Info",
348
288
  prefix: "JavaScript",
349
289
  raw: !1
350
290
  },
351
- ...r
291
+ ...t
352
292
  );
353
293
  }
354
294
  /**
@@ -357,15 +297,15 @@ class Logger extends EventTarget {
357
297
  * @param message any
358
298
  * @param args any
359
299
  */
360
- warn(t, ...r) {
300
+ warn(e, ...t) {
361
301
  this.logMessage(
362
302
  {
363
- message: t,
303
+ message: e,
364
304
  severity: "Warn",
365
305
  prefix: "JavaScript",
366
306
  raw: !1
367
307
  },
368
- ...r
308
+ ...t
369
309
  );
370
310
  }
371
311
  /**
@@ -374,211 +314,54 @@ class Logger extends EventTarget {
374
314
  * @param message any
375
315
  * @param args any
376
316
  */
377
- error(t, ...r) {
317
+ error(e, ...t) {
378
318
  this.logMessage(
379
319
  {
380
- message: t,
320
+ message: e,
381
321
  severity: "Error",
382
322
  prefix: "JavaScript",
383
323
  raw: !1
384
324
  },
385
- ...r
325
+ ...t
386
326
  );
387
327
  }
388
328
  }
389
- const getDefaultHandlers = () => {
329
+ const M = () => {
390
330
  try {
391
331
  if (process.env.NODE_ENV === "test")
392
- return [logToMemory];
332
+ return [v, R];
393
333
  } catch {
394
334
  }
395
- return [logToMemory, logToConsole];
396
- }, logger = new Logger(getDefaultHandlers()), prepareLogMessage = (e) => e.replace(/\t/g, ""), formatLogEntry = (e, t, r) => {
397
- const s = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
335
+ return [v, I, R];
336
+ }, b = new P(M()), w = (r) => r.replace(/\t/g, ""), W = (r, e, t) => {
337
+ const o = /* @__PURE__ */ new Date(), n = new Intl.DateTimeFormat("en-GB", {
398
338
  year: "numeric",
399
339
  month: "short",
400
340
  day: "2-digit",
401
341
  timeZone: "UTC"
402
- }).format(s).replace(/ /g, "-"), i = new Intl.DateTimeFormat("en-GB", {
342
+ }).format(o).replace(/ /g, "-"), i = new Intl.DateTimeFormat("en-GB", {
403
343
  hour: "2-digit",
404
344
  minute: "2-digit",
405
345
  second: "2-digit",
406
346
  hour12: !1,
407
347
  timeZone: "UTC",
408
348
  timeZoneName: "short"
409
- }).format(s), o = n + " " + i;
410
- return e = prepareLogMessage(e), `[${o}] ${r} ${t}: ${e}`;
411
- }, loadedRuntimes = /* @__PURE__ */ new Map();
412
- function getLoadedRuntime(e) {
413
- return loadedRuntimes.get(e);
414
- }
415
- (function() {
416
- var e;
417
- return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : typeof WorkerGlobalScope < "u" && self instanceof WorkerGlobalScope ? "WORKER" : "NODE";
418
- })();
419
- const kError = Symbol("error"), kMessage = Symbol("message");
420
- class ErrorEvent2 extends Event {
421
- /**
422
- * Create a new `ErrorEvent`.
423
- *
424
- * @param type The name of the event
425
- * @param options A dictionary object that allows for setting
426
- * attributes via object members of the same name.
427
- */
428
- constructor(t, r = {}) {
429
- super(t), this[kError] = r.error === void 0 ? null : r.error, this[kMessage] = r.message === void 0 ? "" : r.message;
430
- }
431
- get error() {
432
- return this[kError];
433
- }
434
- get message() {
435
- return this[kMessage];
436
- }
437
- }
438
- Object.defineProperty(ErrorEvent2.prototype, "error", { enumerable: !0 });
439
- Object.defineProperty(ErrorEvent2.prototype, "message", { enumerable: !0 });
440
- const ErrorEvent = typeof globalThis.ErrorEvent == "function" ? globalThis.ErrorEvent : ErrorEvent2;
441
- function isExitCodeZero(e) {
442
- return e instanceof Error ? "exitCode" in e && (e == null ? void 0 : e.exitCode) === 0 || (e == null ? void 0 : e.name) === "ExitStatus" && "status" in e && e.status === 0 : !1;
443
- }
444
- class UnhandledRejectionsTarget extends EventTarget {
445
- constructor() {
446
- super(...arguments), this.listenersCount = 0;
447
- }
448
- addEventListener(t, r) {
449
- ++this.listenersCount, super.addEventListener(t, r);
450
- }
451
- removeEventListener(t, r) {
452
- --this.listenersCount, super.removeEventListener(t, r);
453
- }
454
- hasListeners() {
455
- return this.listenersCount > 0;
456
- }
457
- }
458
- function improveWASMErrorReporting(e) {
459
- e.asm = {
460
- ...e.asm
461
- };
462
- const t = new UnhandledRejectionsTarget();
463
- for (const r in e.asm)
464
- if (typeof e.asm[r] == "function") {
465
- const s = e.asm[r];
466
- e.asm[r] = function(...n) {
467
- var i;
468
- try {
469
- return s(...n);
470
- } catch (o) {
471
- if (!(o instanceof Error))
472
- throw o;
473
- const a = clarifyErrorMessage(
474
- o,
475
- (i = e.lastAsyncifyStackSource) == null ? void 0 : i.stack
476
- );
477
- if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
478
- t.dispatchEvent(
479
- new ErrorEvent("error", {
480
- error: o,
481
- message: a
482
- })
483
- );
484
- return;
485
- }
486
- throw isExitCodeZero(o) || showCriticalErrorBox(a), o;
487
- }
488
- };
489
- }
490
- return t;
491
- }
492
- let functionsMaybeMissingFromAsyncify = [];
493
- function getFunctionsMaybeMissingFromAsyncify() {
494
- return functionsMaybeMissingFromAsyncify;
495
- }
496
- function clarifyErrorMessage(e, t) {
497
- if (e.message === "unreachable") {
498
- let r = UNREACHABLE_ERROR;
499
- t || (r += `
500
-
501
- This stack trace is lacking. For a better one initialize
502
- the PHP runtime with { debug: true }, e.g. PHPNode.load('8.1', { debug: true }).
503
-
504
- `), functionsMaybeMissingFromAsyncify = extractPHPFunctionsFromStack(
505
- t || e.stack || ""
506
- );
507
- for (const s of functionsMaybeMissingFromAsyncify)
508
- r += ` * ${s}
509
- `;
510
- return r;
511
- }
512
- return e.message;
513
- }
514
- const UNREACHABLE_ERROR = `
515
- "unreachable" WASM instruction executed.
516
-
517
- The typical reason is a PHP function missing from the ASYNCIFY_ONLY
518
- list when building PHP.wasm.
519
-
520
- You will need to file a new issue in the WordPress Playground repository
521
- and paste this error message there:
522
-
523
- https://github.com/WordPress/wordpress-playground/issues/new
524
-
525
- If you're a core developer, the typical fix is to:
526
-
527
- * Isolate a minimal reproduction of the error
528
- * Add a reproduction of the error to php-asyncify.spec.ts in the WordPress Playground repository
529
- * Run 'npm run fix-asyncify'
530
- * Commit the changes, push to the repo, release updated NPM packages
531
-
532
- Below is a list of all the PHP functions found in the stack trace to
533
- help with the minimal reproduction. If they're all already listed in
534
- the Dockerfile, you'll need to trigger this error again with long stack
535
- traces enabled. In node.js, you can do it using the --stack-trace-limit=100
536
- CLI option:
537
-
538
- `, redBg = "\x1B[41m", bold = "\x1B[1m", reset = "\x1B[0m", eol = "\x1B[K";
539
- let logged = !1;
540
- function showCriticalErrorBox(e) {
541
- if (!logged && (logged = !0, !(e != null && e.trim().startsWith("Program terminated with exit")))) {
542
- logger.log(`${redBg}
543
- ${eol}
544
- ${bold} WASM ERROR${reset}${redBg}`);
545
- for (const t of e.split(`
546
- `))
547
- logger.log(`${eol} ${t} `);
548
- logger.log(`${reset}`);
549
- }
550
- }
551
- function extractPHPFunctionsFromStack(e) {
552
- try {
553
- const t = e.split(`
554
- `).slice(1).map((r) => {
555
- const s = r.trim().substring(3).split(" ");
556
- return {
557
- fn: s.length >= 2 ? s[0] : "<unknown>",
558
- isWasm: r.includes("wasm://")
559
- };
560
- }).filter(
561
- ({ fn: r, isWasm: s }) => s && !r.startsWith("dynCall_") && !r.startsWith("invoke_")
562
- ).map(({ fn: r }) => r);
563
- return Array.from(new Set(t));
564
- } catch {
565
- return [];
566
- }
567
- }
568
- const SleepFinished = Symbol("SleepFinished");
569
- function sleep(e) {
570
- return new Promise((t) => {
571
- setTimeout(() => t(SleepFinished), e);
349
+ }).format(o), s = n + " " + i;
350
+ return r = w(r), `[${s}] ${t} ${e}: ${r}`;
351
+ }, D = Symbol("SleepFinished");
352
+ function L(r) {
353
+ return new Promise((e) => {
354
+ setTimeout(() => e(D), r);
572
355
  });
573
356
  }
574
- class AcquireTimeoutError extends Error {
357
+ class S extends Error {
575
358
  constructor() {
576
359
  super("Acquiring lock timed out");
577
360
  }
578
361
  }
579
- class Semaphore {
580
- constructor({ concurrency: t, timeout: r }) {
581
- this._running = 0, this.concurrency = t, this.timeout = r, this.queue = [];
362
+ class $ {
363
+ constructor({ concurrency: e, timeout: t }) {
364
+ this._running = 0, this.concurrency = e, this.timeout = t, this.queue = [];
582
365
  }
583
366
  get remaining() {
584
367
  return this.concurrency - this.running;
@@ -589,965 +372,416 @@ class Semaphore {
589
372
  async acquire() {
590
373
  for (; ; )
591
374
  if (this._running >= this.concurrency) {
592
- const t = new Promise((r) => {
593
- this.queue.push(r);
375
+ const e = new Promise((t) => {
376
+ this.queue.push(t);
594
377
  });
595
- this.timeout !== void 0 ? await Promise.race([t, sleep(this.timeout)]).then(
596
- (r) => {
597
- if (r === SleepFinished)
598
- throw new AcquireTimeoutError();
378
+ this.timeout !== void 0 ? await Promise.race([e, L(this.timeout)]).then(
379
+ (t) => {
380
+ if (t === D)
381
+ throw new S();
599
382
  }
600
- ) : await t;
383
+ ) : await e;
601
384
  } else {
602
385
  this._running++;
603
- let t = !1;
386
+ let e = !1;
604
387
  return () => {
605
- t || (t = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
388
+ e || (e = !0, this._running--, this.queue.length > 0 && this.queue.shift()());
606
389
  };
607
390
  }
608
391
  }
609
- async run(t) {
610
- const r = await this.acquire();
392
+ async run(e) {
393
+ const t = await this.acquire();
611
394
  try {
612
- return await t();
395
+ return await e();
613
396
  } finally {
614
- r();
397
+ t();
615
398
  }
616
399
  }
617
400
  }
618
- function joinPaths(...e) {
619
- let t = e.join("/");
620
- const r = t[0] === "/", s = t.substring(t.length - 1) === "/";
621
- return t = normalizePath$1(t), !t && !r && (t = "."), t && s && (t += "/"), t;
401
+ function g(...r) {
402
+ let e = r.join("/");
403
+ const t = e[0] === "/", o = e.substring(e.length - 1) === "/";
404
+ return e = T(e), !e && !t && (e = "."), e && o && (e += "/"), e;
622
405
  }
623
- function dirname(e) {
624
- if (e === "/")
406
+ function _(r) {
407
+ if (r === "/")
625
408
  return "/";
626
- e = normalizePath$1(e);
627
- const t = e.lastIndexOf("/");
628
- return t === -1 ? "" : t === 0 ? "/" : e.substr(0, t);
409
+ r = T(r);
410
+ const e = r.lastIndexOf("/");
411
+ return e === -1 ? "" : e === 0 ? "/" : r.substr(0, e);
629
412
  }
630
- function basename(e) {
631
- if (e === "/")
413
+ function q(r) {
414
+ if (r === "/")
632
415
  return "/";
633
- e = normalizePath$1(e);
634
- const t = e.lastIndexOf("/");
635
- return t === -1 ? e : e.substr(t + 1);
636
- }
637
- function normalizePath$1(e) {
638
- const t = e[0] === "/";
639
- return e = normalizePathsArray(
640
- e.split("/").filter((r) => !!r),
641
- !t
642
- ).join("/"), (t ? "/" : "") + e.replace(/\/$/, "");
643
- }
644
- function normalizePathsArray(e, t) {
645
- let r = 0;
646
- for (let s = e.length - 1; s >= 0; s--) {
647
- const n = e[s];
648
- n === "." ? e.splice(s, 1) : n === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
649
- }
650
- if (t)
651
- for (; r; r--)
652
- e.unshift("..");
653
- return e;
654
- }
655
- function splitShellCommand(e) {
656
- let s = 0, n = "";
657
- const i = [];
658
- let o = "";
659
- for (let a = 0; a < e.length; a++) {
660
- const l = e[a];
661
- l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, o += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, n = l) : l.match(/\s/) ? (o.trim().length && i.push(o.trim()), o = l) : i.length && !o ? o = i.pop() + l : o += l : s === 1 && (l === n ? (s = 0, n = "") : o += l);
662
- }
663
- return o && i.push(o.trim()), i;
664
- }
665
- function createSpawnHandler(e) {
666
- return function(t, r = [], s = {}) {
667
- const n = new ChildProcess(), i = new ProcessApi(n);
668
- return setTimeout(async () => {
669
- let o = [];
670
- if (r.length)
671
- o = [t, ...r];
672
- else if (typeof t == "string")
673
- o = splitShellCommand(t);
674
- else if (Array.isArray(t))
675
- o = t;
676
- else
677
- throw new Error("Invalid command ", t);
678
- try {
679
- await e(o, i, s);
680
- } catch (a) {
681
- n.emit("error", a), typeof a == "object" && a !== null && "message" in a && typeof a.message == "string" && i.stderr(a.message), i.exit(1);
682
- }
683
- n.emit("spawn", !0);
684
- }), n;
685
- };
686
- }
687
- class EventEmitter {
688
- constructor() {
689
- this.listeners = {};
690
- }
691
- emit(t, r) {
692
- this.listeners[t] && this.listeners[t].forEach(function(s) {
693
- s(r);
694
- });
695
- }
696
- on(t, r) {
697
- this.listeners[t] || (this.listeners[t] = []), this.listeners[t].push(r);
698
- }
699
- }
700
- class ProcessApi extends EventEmitter {
701
- constructor(t) {
702
- super(), this.childProcess = t, this.exited = !1, this.stdinData = [], t.on("stdin", (r) => {
703
- this.stdinData ? this.stdinData.push(r.slice()) : this.emit("stdin", r);
704
- });
705
- }
706
- stdout(t) {
707
- typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stdout.emit("data", t);
708
- }
709
- stdoutEnd() {
710
- this.childProcess.stdout.emit("end", {});
711
- }
712
- stderr(t) {
713
- typeof t == "string" && (t = new TextEncoder().encode(t)), this.childProcess.stderr.emit("data", t);
714
- }
715
- stderrEnd() {
716
- this.childProcess.stderr.emit("end", {});
717
- }
718
- exit(t) {
719
- this.exited || (this.exited = !0, this.childProcess.emit("exit", t));
720
- }
721
- flushStdin() {
722
- if (this.stdinData)
723
- for (let t = 0; t < this.stdinData.length; t++)
724
- this.emit("stdin", this.stdinData[t]);
725
- this.stdinData = null;
726
- }
727
- }
728
- let lastPid = 9743;
729
- class ChildProcess extends EventEmitter {
730
- constructor(t = lastPid++) {
731
- super(), this.pid = t, this.stdout = new EventEmitter(), this.stderr = new EventEmitter();
732
- const r = this;
733
- this.stdin = {
734
- write: (s) => {
735
- r.emit("stdin", s);
736
- }
737
- };
738
- }
739
- }
740
- var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
741
- for (var n = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, i = e.length - 1, o; i >= 0; i--)
742
- (o = e[i]) && (n = (s ? o(t, r, n) : o(n)) || n);
743
- return s && n && __defProp(t, r, n), n;
416
+ r = T(r);
417
+ const e = r.lastIndexOf("/");
418
+ return e === -1 ? r : r.substr(e + 1);
419
+ }
420
+ function T(r) {
421
+ const e = r[0] === "/";
422
+ return r = j(
423
+ r.split("/").filter((t) => !!t),
424
+ !e
425
+ ).join("/"), (e ? "/" : "") + r.replace(/\/$/, "");
426
+ }
427
+ function j(r, e) {
428
+ let t = 0;
429
+ for (let o = r.length - 1; o >= 0; o--) {
430
+ const n = r[o];
431
+ n === "." ? r.splice(o, 1) : n === ".." ? (r.splice(o, 1), t++) : t && (r.splice(o, 1), t--);
432
+ }
433
+ if (e)
434
+ for (; t; t--)
435
+ r.unshift("..");
436
+ return r;
437
+ }
438
+ var J = Object.defineProperty, z = Object.getOwnPropertyDescriptor, d = (r, e, t, o) => {
439
+ for (var n = o > 1 ? void 0 : o ? z(e, t) : e, i = r.length - 1, s; i >= 0; i--)
440
+ (s = r[i]) && (n = (o ? s(e, t, n) : s(n)) || n);
441
+ return o && n && J(e, t, n), n;
744
442
  };
745
- const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
746
- class PHPExecutionFailureError extends Error {
747
- constructor(t, r, s) {
748
- super(t), this.response = r, this.source = s;
749
- }
750
- }
751
- const PHP_INI_PATH = "/internal/shared/php.ini", AUTO_PREPEND_SCRIPT = "/internal/shared/auto_prepend_file.php";
752
- var E, m, y, _, w, P, B, b, L, R, U, S, $, T, q, F, W, x, z, C, j, k, G, N, J, v, O, A, V, M, Q, I, Y;
753
- class BasePHP {
754
- /**
755
- * Initializes a PHP runtime.
756
- *
757
- * @internal
758
- * @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
759
- * @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
760
- */
761
- constructor(e) {
762
- /**
763
- * Prepares the $_SERVER entries for the PHP runtime.
764
- *
765
- * @param defaults Default entries to include in $_SERVER.
766
- * @param headers HTTP headers to include in $_SERVER (as HTTP_ prefixed entries).
767
- * @param port HTTP port, used to determine infer $_SERVER['HTTPS'] value if none
768
- * was provided.
769
- * @returns Computed $_SERVER entries.
770
- */
771
- d(this, P);
772
- d(this, b);
773
- d(this, R);
774
- d(this, S);
775
- d(this, T);
776
- d(this, F);
777
- d(this, x);
778
- d(this, C);
779
- d(this, k);
780
- d(this, N);
781
- d(this, v);
782
- d(this, A);
783
- d(this, M);
784
- d(this, I);
785
- d(this, E, void 0);
786
- d(this, m, void 0);
787
- d(this, y, void 0);
788
- d(this, _, void 0);
789
- d(this, w, void 0);
790
- p(this, m, !1), p(this, y, null), p(this, _, /* @__PURE__ */ new Map()), p(this, w, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e);
443
+ const f = class c {
444
+ static readFileAsText(e, t) {
445
+ return new TextDecoder().decode(c.readFileAsBuffer(e, t));
791
446
  }
792
- addEventListener(e, t) {
793
- f(this, _).has(e) || f(this, _).set(e, /* @__PURE__ */ new Set()), f(this, _).get(e).add(t);
447
+ static readFileAsBuffer(e, t) {
448
+ return e.readFile(t);
794
449
  }
795
- removeEventListener(e, t) {
796
- var r;
797
- (r = f(this, _).get(e)) == null || r.delete(t);
450
+ static writeFile(e, t, o) {
451
+ e.writeFile(t, o);
798
452
  }
799
- dispatchEvent(e) {
800
- const t = f(this, _).get(e.type);
801
- if (t)
802
- for (const r of t)
803
- r(e);
804
- }
805
- /** @inheritDoc */
806
- async onMessage(e) {
807
- f(this, w).push(e);
808
- }
809
- /** @inheritDoc */
810
- async setSpawnHandler(handler) {
811
- typeof handler == "string" && (handler = createSpawnHandler(eval(handler))), this[__private__dont__use].spawnProcess = handler;
812
- }
813
- /** @inheritDoc */
814
- get absoluteUrl() {
815
- return this.requestHandler.absoluteUrl;
816
- }
817
- /** @inheritDoc */
818
- get documentRoot() {
819
- return this.requestHandler.documentRoot;
820
- }
821
- /** @inheritDoc */
822
- pathToInternalUrl(e) {
823
- return this.requestHandler.pathToInternalUrl(e);
824
- }
825
- /** @inheritDoc */
826
- internalUrlToPath(e) {
827
- return this.requestHandler.internalUrlToPath(e);
828
- }
829
- initializeRuntime(e) {
830
- if (this[__private__dont__use])
831
- throw new Error("PHP runtime already initialized.");
832
- const t = getLoadedRuntime(e);
833
- if (!t)
834
- throw new Error("Invalid PHP runtime id.");
835
- this[__private__dont__use] = t, this[__private__dont__use].ccall(
836
- "wasm_set_phpini_path",
837
- null,
838
- ["string"],
839
- [PHP_INI_PATH]
840
- ), this.fileExists(PHP_INI_PATH) || this.writeFile(
841
- PHP_INI_PATH,
842
- [
843
- "auto_prepend_file=" + AUTO_PREPEND_SCRIPT,
844
- "memory_limit=256M",
845
- "ignore_repeated_errors = 1",
846
- "error_reporting = E_ALL",
847
- "display_errors = 1",
848
- "html_errors = 1",
849
- "display_startup_errors = On",
850
- "log_errors = 1",
851
- "always_populate_raw_post_data = -1",
852
- "upload_max_filesize = 2000M",
853
- "post_max_size = 2000M",
854
- "disable_functions = curl_exec,curl_multi_exec",
855
- "allow_url_fopen = Off",
856
- "allow_url_include = Off",
857
- "session.save_path = /home/web_user",
858
- "implicit_flush = 1",
859
- "output_buffering = 0",
860
- "max_execution_time = 0",
861
- "max_input_time = -1"
862
- ].join(`
863
- `)
864
- ), this.fileExists(AUTO_PREPEND_SCRIPT) || this.writeFile(
865
- AUTO_PREPEND_SCRIPT,
866
- `<?php
867
- // Define constants set via defineConstant() calls
868
- if(file_exists('/internal/shared/consts.json')) {
869
- $consts = json_decode(file_get_contents('/internal/shared/consts.json'), true);
870
- foreach ($consts as $const => $value) {
871
- if (!defined($const) && is_scalar($value)) {
872
- define($const, $value);
873
- }
874
- }
875
- }
876
- // Preload all the files from /internal/shared/preload
877
- foreach (glob('/internal/shared/preload/*.php') as $file) {
878
- require_once $file;
879
- }
880
- `
881
- ), t.onMessage = async (r) => {
882
- for (const s of f(this, w)) {
883
- const n = await s(r);
884
- if (n)
885
- return n;
886
- }
887
- return "";
888
- }, p(this, y, improveWASMErrorReporting(t)), this.dispatchEvent({
889
- type: "runtime.initialized"
890
- });
891
- }
892
- /** @inheritDoc */
893
- async setSapiName(e) {
894
- if (this[__private__dont__use].ccall(
895
- "wasm_set_sapi_name",
896
- NUMBER,
897
- [STRING],
898
- [e]
899
- ) !== 0)
900
- throw new Error(
901
- "Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
902
- );
903
- p(this, E, e);
904
- }
905
- /** @inheritDoc */
906
- chdir(e) {
907
- this[__private__dont__use].FS.chdir(e);
453
+ static unlink(e, t) {
454
+ e.unlink(t);
908
455
  }
909
456
  /**
910
- * Do not use. Use new PHPRequestHandler() instead.
911
- * @deprecated
457
+ * Moves a file or directory in the PHP filesystem to a
458
+ * new location.
459
+ *
460
+ * @param oldPath The path to rename.
461
+ * @param newPath The new path.
912
462
  */
913
- async request(e) {
914
- if (logger.warn(
915
- "PHP.request() is deprecated. Please use new PHPRequestHandler() instead."
916
- ), !this.requestHandler)
917
- throw new Error("No request handler available.");
918
- return this.requestHandler.request(e);
919
- }
920
- /** @inheritDoc */
921
- async run(e) {
922
- const t = await this.semaphore.acquire();
923
- let r;
463
+ static mv(e, t, o) {
924
464
  try {
925
- if (f(this, m) || (h(this, b, L).call(this), p(this, m, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
926
- throw new Error(
927
- `The script path "${e.scriptPath}" does not exist.`
928
- );
929
- h(this, S, $).call(this, e.relativeUri || ""), h(this, C, j).call(this, e.method || "GET");
930
- const s = normalizeHeaders(e.headers || {}), n = s.host || "example.com:443", i = h(this, x, z).call(this, n, e.protocol || "http");
931
- h(this, T, q).call(this, n), h(this, F, W).call(this, i), h(this, k, G).call(this, s), e.body && (r = h(this, N, J).call(this, e.body)), typeof e.code == "string" ? (this.writeFile("/internal/eval.php", e.code), h(this, v, O).call(this, "/internal/eval.php")) : h(this, v, O).call(this, e.scriptPath || "");
932
- const o = h(this, P, B).call(this, e.$_SERVER, s, i);
933
- for (const c in o)
934
- h(this, A, V).call(this, c, o[c]);
935
- const a = e.env || {};
936
- for (const c in a)
937
- h(this, M, Q).call(this, c, a[c]);
938
- const l = await h(this, I, Y).call(this);
939
- if (l.exitCode !== 0) {
940
- logger.warn("PHP.run() output was:", l.text);
941
- const c = new PHPExecutionFailureError(
942
- `PHP.run() failed with exit code ${l.exitCode} and the following output: ` + l.errors,
943
- l,
944
- "request"
945
- );
946
- throw logger.error(c), c;
947
- }
948
- return l;
949
- } catch (s) {
950
- throw this.dispatchEvent({
951
- type: "request.error",
952
- error: s,
953
- // Distinguish between PHP request and PHP-wasm errors
954
- source: s.source ?? "php-wasm"
955
- }), s;
956
- } finally {
957
- try {
958
- r && this[__private__dont__use].free(r);
959
- } finally {
960
- t(), this.dispatchEvent({
961
- type: "request.end"
962
- });
963
- }
964
- }
965
- }
966
- defineConstant(e, t) {
967
- let r = {};
968
- try {
969
- r = JSON.parse(
970
- this.fileExists("/internal/shared/consts.json") && this.readFileAsText("/internal/shared/consts.json") || "{}"
971
- );
972
- } catch {
973
- }
974
- this.writeFile(
975
- "/internal/shared/consts.json",
976
- JSON.stringify({
977
- ...r,
978
- [e]: t
979
- })
980
- );
981
- }
982
- mkdir(e) {
983
- this[__private__dont__use].FS.mkdirTree(e);
984
- }
985
- mkdirTree(e) {
986
- this.mkdir(e);
987
- }
988
- readFileAsText(e) {
989
- return new TextDecoder().decode(this.readFileAsBuffer(e));
990
- }
991
- readFileAsBuffer(e) {
992
- return this[__private__dont__use].FS.readFile(e);
993
- }
994
- writeFile(e, t) {
995
- this[__private__dont__use].FS.writeFile(e, t);
996
- }
997
- unlink(e) {
998
- this[__private__dont__use].FS.unlink(e);
999
- }
1000
- /** @inheritDoc */
1001
- mv(e, t) {
1002
- const r = this[__private__dont__use].FS;
1003
- try {
1004
- const s = r.lookupPath(e).node.mount, n = this.fileExists(t) ? r.lookupPath(t).node.mount : r.lookupPath(dirname(t)).node.mount;
1005
- s.mountpoint !== n.mountpoint ? (copyRecursive(r, e, t), this.rmdir(e, { recursive: !0 })) : r.rename(e, t);
1006
- } catch (s) {
1007
- const n = getEmscriptenFsError(s);
1008
- throw n ? new Error(
1009
- `Could not move ${e} to ${t}: ${n}`,
465
+ const n = e.lookupPath(t).node.mount, i = c.fileExists(e, o) ? e.lookupPath(o).node.mount : e.lookupPath(_(o)).node.mount;
466
+ n.mountpoint !== i.mountpoint ? (c.copyRecursive(e, t, o), c.rmdir(e, t, { recursive: !0 })) : e.rename(t, o);
467
+ } catch (n) {
468
+ const i = O(n);
469
+ throw i ? new Error(
470
+ `Could not move ${t} to ${o}: ${i}`,
1010
471
  {
1011
- cause: s
472
+ cause: n
1012
473
  }
1013
- ) : s;
474
+ ) : n;
1014
475
  }
1015
476
  }
1016
- rmdir(e, t = { recursive: !0 }) {
1017
- t != null && t.recursive && this.listFiles(e).forEach((r) => {
1018
- const s = `${e}/${r}`;
1019
- this.isDir(s) ? this.rmdir(s, t) : this.unlink(s);
1020
- }), this[__private__dont__use].FS.rmdir(e);
477
+ static rmdir(e, t, o = { recursive: !0 }) {
478
+ o != null && o.recursive && c.listFiles(e, t).forEach((n) => {
479
+ const i = `${t}/${n}`;
480
+ c.isDir(e, i) ? c.rmdir(e, i, o) : c.unlink(e, i);
481
+ }), e.rmdir(t);
1021
482
  }
1022
- listFiles(e, t = { prependPath: !1 }) {
1023
- if (!this.fileExists(e))
483
+ static listFiles(e, t, o = { prependPath: !1 }) {
484
+ if (!c.fileExists(e, t))
1024
485
  return [];
1025
486
  try {
1026
- const r = this[__private__dont__use].FS.readdir(e).filter(
1027
- (s) => s !== "." && s !== ".."
487
+ const n = e.readdir(t).filter(
488
+ (i) => i !== "." && i !== ".."
1028
489
  );
1029
- if (t.prependPath) {
1030
- const s = e.replace(/\/$/, "");
1031
- return r.map((n) => `${s}/${n}`);
490
+ if (o.prependPath) {
491
+ const i = t.replace(/\/$/, "");
492
+ return n.map((s) => `${i}/${s}`);
1032
493
  }
1033
- return r;
1034
- } catch (r) {
1035
- return logger.error(r, { path: e }), [];
494
+ return n;
495
+ } catch (n) {
496
+ return b.error(n, { path: t }), [];
1036
497
  }
1037
498
  }
1038
- isDir(e) {
1039
- return this.fileExists(e) ? this[__private__dont__use].FS.isDir(
1040
- this[__private__dont__use].FS.lookupPath(e).node.mode
1041
- ) : !1;
499
+ static isDir(e, t) {
500
+ return c.fileExists(e, t) ? e.isDir(e.lookupPath(t).node.mode) : !1;
1042
501
  }
1043
- fileExists(e) {
502
+ static fileExists(e, t) {
1044
503
  try {
1045
- return this[__private__dont__use].FS.lookupPath(e), !0;
504
+ return e.lookupPath(t), !0;
1046
505
  } catch {
1047
506
  return !1;
1048
507
  }
1049
508
  }
1050
- /**
1051
- * Hot-swaps the PHP runtime for a new one without
1052
- * interrupting the operations of this PHP instance.
1053
- *
1054
- * @param runtime
1055
- * @param cwd. Internal, the VFS path to recreate in the new runtime.
1056
- * This arg is temporary and will be removed once BasePHP
1057
- * is fully decoupled from the request handler and
1058
- * accepts a constructor-level cwd argument.
1059
- */
1060
- hotSwapPHPRuntime(e, t) {
1061
- const r = this[__private__dont__use].FS;
1062
- try {
1063
- this.exit();
1064
- } catch {
1065
- }
1066
- this.initializeRuntime(e), f(this, E) && this.setSapiName(f(this, E)), t && copyFS(r, this[__private__dont__use].FS, t);
1067
- }
1068
- exit(e = 0) {
1069
- this.dispatchEvent({
1070
- type: "runtime.beforedestroy"
1071
- });
1072
- try {
1073
- this[__private__dont__use]._exit(e);
1074
- } catch {
1075
- }
1076
- p(this, m, !1), p(this, y, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
1077
- }
1078
- [Symbol.dispose]() {
1079
- f(this, m) && this.exit(0);
1080
- }
1081
- }
1082
- E = new WeakMap(), m = new WeakMap(), y = new WeakMap(), _ = new WeakMap(), w = new WeakMap(), P = new WeakSet(), B = function(e, t, r) {
1083
- const s = {
1084
- ...e || {}
1085
- };
1086
- s.HTTPS = s.HTTPS || r === 443 ? "on" : "off";
1087
- for (const n in t) {
1088
- let i = "HTTP_";
1089
- ["content-type", "content-length"].includes(n.toLowerCase()) && (i = ""), s[`${i}${n.toUpperCase().replace(/-/g, "_")}`] = t[n];
1090
- }
1091
- return s;
1092
- }, b = new WeakSet(), L = function() {
1093
- this[__private__dont__use].ccall("php_wasm_init", null, [], []);
1094
- }, R = new WeakSet(), U = function() {
1095
- const e = "/internal/headers.json";
1096
- if (!this.fileExists(e))
1097
- throw new Error(
1098
- "SAPI Error: Could not find response headers file."
1099
- );
1100
- const t = JSON.parse(this.readFileAsText(e)), r = {};
1101
- for (const s of t.headers) {
1102
- if (!s.includes(": "))
1103
- continue;
1104
- const n = s.indexOf(": "), i = s.substring(0, n).toLowerCase(), o = s.substring(n + 2);
1105
- i in r || (r[i] = []), r[i].push(o);
509
+ static mkdir(e, t) {
510
+ e.mkdirTree(t);
1106
511
  }
1107
- return {
1108
- headers: r,
1109
- httpStatusCode: t.status
1110
- };
1111
- }, S = new WeakSet(), $ = function(e) {
1112
- if (this[__private__dont__use].ccall(
1113
- "wasm_set_request_uri",
1114
- null,
1115
- [STRING],
1116
- [e]
1117
- ), e.includes("?")) {
1118
- const t = e.substring(e.indexOf("?") + 1);
1119
- this[__private__dont__use].ccall(
1120
- "wasm_set_query_string",
1121
- null,
1122
- [STRING],
1123
- [t]
1124
- );
1125
- }
1126
- }, T = new WeakSet(), q = function(e) {
1127
- this[__private__dont__use].ccall(
1128
- "wasm_set_request_host",
1129
- null,
1130
- [STRING],
1131
- [e]
1132
- );
1133
- }, F = new WeakSet(), W = function(e) {
1134
- this[__private__dont__use].ccall(
1135
- "wasm_set_request_port",
1136
- null,
1137
- [NUMBER],
1138
- [e]
1139
- );
1140
- }, x = new WeakSet(), z = function(e, t) {
1141
- let r;
1142
- try {
1143
- r = parseInt(new URL(e).port, 10);
1144
- } catch {
1145
- }
1146
- return (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), r;
1147
- }, C = new WeakSet(), j = function(e) {
1148
- this[__private__dont__use].ccall(
1149
- "wasm_set_request_method",
1150
- null,
1151
- [STRING],
1152
- [e]
1153
- );
1154
- }, k = new WeakSet(), G = function(e) {
1155
- e.cookie && this[__private__dont__use].ccall(
1156
- "wasm_set_cookies",
1157
- null,
1158
- [STRING],
1159
- [e.cookie]
1160
- ), e["content-type"] && this[__private__dont__use].ccall(
1161
- "wasm_set_content_type",
1162
- null,
1163
- [STRING],
1164
- [e["content-type"]]
1165
- ), e["content-length"] && this[__private__dont__use].ccall(
1166
- "wasm_set_content_length",
1167
- null,
1168
- [NUMBER],
1169
- [parseInt(e["content-length"], 10)]
1170
- );
1171
- }, N = new WeakSet(), J = function(e) {
1172
- let t, r;
1173
- typeof e == "string" ? (logger.warn(
1174
- "Passing a string as the request body is deprecated. Please use a Uint8Array instead. See https://github.com/WordPress/wordpress-playground/issues/997 for more details"
1175
- ), r = this[__private__dont__use].lengthBytesUTF8(e), t = r + 1) : (r = e.byteLength, t = e.byteLength);
1176
- const s = this[__private__dont__use].malloc(t);
1177
- if (!s)
1178
- throw new Error("Could not allocate memory for the request body.");
1179
- return typeof e == "string" ? this[__private__dont__use].stringToUTF8(
1180
- e,
1181
- s,
1182
- t + 1
1183
- ) : this[__private__dont__use].HEAPU8.set(e, s), this[__private__dont__use].ccall(
1184
- "wasm_set_request_body",
1185
- null,
1186
- [NUMBER],
1187
- [s]
1188
- ), this[__private__dont__use].ccall(
1189
- "wasm_set_content_length",
1190
- null,
1191
- [NUMBER],
1192
- [r]
1193
- ), s;
1194
- }, v = new WeakSet(), O = function(e) {
1195
- this[__private__dont__use].ccall(
1196
- "wasm_set_path_translated",
1197
- null,
1198
- [STRING],
1199
- [e]
1200
- );
1201
- }, A = new WeakSet(), V = function(e, t) {
1202
- this[__private__dont__use].ccall(
1203
- "wasm_add_SERVER_entry",
1204
- null,
1205
- [STRING, STRING],
1206
- [e, t]
1207
- );
1208
- }, M = new WeakSet(), Q = function(e, t) {
1209
- this[__private__dont__use].ccall(
1210
- "wasm_add_ENV_entry",
1211
- null,
1212
- [STRING, STRING],
1213
- [e, t]
1214
- );
1215
- }, I = new WeakSet(), Y = async function() {
1216
- var n;
1217
- let e, t;
1218
- try {
1219
- e = await new Promise((i, o) => {
1220
- var l;
1221
- t = (c) => {
1222
- logger.error(c), logger.error(c.error);
1223
- const u = new Error("Rethrown");
1224
- u.cause = c.error, u.betterMessage = c.message, o(u);
1225
- }, (l = f(this, y)) == null || l.addEventListener(
1226
- "error",
1227
- t
1228
- );
1229
- const a = this[__private__dont__use].ccall(
1230
- "wasm_sapi_handle_request",
1231
- NUMBER,
1232
- [],
1233
- [],
1234
- { async: !0 }
512
+ static copyRecursive(e, t, o) {
513
+ const n = e.lookupPath(t).node;
514
+ if (e.isDir(n.mode)) {
515
+ e.mkdirTree(o);
516
+ const i = e.readdir(t).filter(
517
+ (s) => s !== "." && s !== ".."
1235
518
  );
1236
- return a instanceof Promise ? a.then(i, o) : i(a);
1237
- });
1238
- } catch (i) {
1239
- for (const c in this)
1240
- typeof this[c] == "function" && (this[c] = () => {
1241
- throw new Error(
1242
- "PHP runtime has crashed – see the earlier error for details."
519
+ for (const s of i)
520
+ c.copyRecursive(
521
+ e,
522
+ g(t, s),
523
+ g(o, s)
1243
524
  );
1244
- });
1245
- this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
1246
- const o = i, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
1247
- throw l.cause = o, logger.error(l), l;
1248
- } finally {
1249
- (n = f(this, y)) == null || n.removeEventListener("error", t);
525
+ } else
526
+ e.writeFile(o, e.readFile(t));
1250
527
  }
1251
- const { headers: r, httpStatusCode: s } = h(this, R, U).call(this);
1252
- return new PHPResponse(
1253
- e === 0 ? s : 500,
1254
- r,
1255
- this.readFileAsBuffer("/internal/stdout"),
1256
- this.readFileAsText("/internal/stderr"),
1257
- e
1258
- );
1259
528
  };
1260
- __decorateClass([
1261
- rethrowFileSystemError('Could not create directory "{path}"')
1262
- ], BasePHP.prototype, "mkdir", 1);
1263
- __decorateClass([
1264
- rethrowFileSystemError('Could not create directory "{path}"')
1265
- ], BasePHP.prototype, "mkdirTree", 1);
1266
- __decorateClass([
1267
- rethrowFileSystemError('Could not read "{path}"')
1268
- ], BasePHP.prototype, "readFileAsText", 1);
1269
- __decorateClass([
1270
- rethrowFileSystemError('Could not read "{path}"')
1271
- ], BasePHP.prototype, "readFileAsBuffer", 1);
1272
- __decorateClass([
1273
- rethrowFileSystemError('Could not write to "{path}"')
1274
- ], BasePHP.prototype, "writeFile", 1);
1275
- __decorateClass([
1276
- rethrowFileSystemError('Could not unlink "{path}"')
1277
- ], BasePHP.prototype, "unlink", 1);
1278
- __decorateClass([
1279
- rethrowFileSystemError('Could not remove directory "{path}"')
1280
- ], BasePHP.prototype, "rmdir", 1);
1281
- __decorateClass([
1282
- rethrowFileSystemError('Could not list files in "{path}"')
1283
- ], BasePHP.prototype, "listFiles", 1);
1284
- __decorateClass([
1285
- rethrowFileSystemError('Could not stat "{path}"')
1286
- ], BasePHP.prototype, "isDir", 1);
1287
- __decorateClass([
1288
- rethrowFileSystemError('Could not stat "{path}"')
1289
- ], BasePHP.prototype, "fileExists", 1);
1290
- function normalizeHeaders(e) {
1291
- const t = {};
1292
- for (const r in e)
1293
- t[r.toLowerCase()] = e[r];
1294
- return t;
1295
- }
1296
- function copyFS(e, t, r) {
1297
- let s;
1298
- try {
1299
- s = e.lookupPath(r);
1300
- } catch {
1301
- return;
1302
- }
1303
- if (!("contents" in s.node))
1304
- return;
1305
- if (!e.isDir(s.node.mode)) {
1306
- t.writeFile(r, e.readFile(r));
1307
- return;
1308
- }
1309
- t.mkdirTree(r);
1310
- const n = e.readdir(r).filter((i) => i !== "." && i !== "..");
1311
- for (const i of n)
1312
- copyFS(e, t, joinPaths(r, i));
1313
- }
1314
- function copyRecursive(e, t, r) {
1315
- const s = e.lookupPath(t).node;
1316
- if (e.isDir(s.mode)) {
1317
- e.mkdirTree(r);
1318
- const n = e.readdir(t).filter(
1319
- (i) => i !== "." && i !== ".."
1320
- );
1321
- for (const i of n)
1322
- copyRecursive(
1323
- e,
1324
- joinPaths(t, i),
1325
- joinPaths(r, i)
1326
- );
1327
- } else
1328
- e.writeFile(r, e.readFile(t));
1329
- }
529
+ d([
530
+ u('Could not read "{path}"')
531
+ ], f, "readFileAsText", 1);
532
+ d([
533
+ u('Could not read "{path}"')
534
+ ], f, "readFileAsBuffer", 1);
535
+ d([
536
+ u('Could not write to "{path}"')
537
+ ], f, "writeFile", 1);
538
+ d([
539
+ u('Could not unlink "{path}"')
540
+ ], f, "unlink", 1);
541
+ d([
542
+ u('Could not remove directory "{path}"')
543
+ ], f, "rmdir", 1);
544
+ d([
545
+ u('Could not list files in "{path}"')
546
+ ], f, "listFiles", 1);
547
+ d([
548
+ u('Could not stat "{path}"')
549
+ ], f, "isDir", 1);
550
+ d([
551
+ u('Could not stat "{path}"')
552
+ ], f, "fileExists", 1);
553
+ d([
554
+ u('Could not create directory "{path}"')
555
+ ], f, "mkdir", 1);
556
+ d([
557
+ u('Could not copy files from "{path}"')
558
+ ], f, "copyRecursive", 1);
559
+ (function() {
560
+ var r;
561
+ 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";
562
+ })();
563
+ const p = Symbol("__private__dont__use");
1330
564
  ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symbol.asyncIterator] = async function* () {
1331
- const e = this.getReader();
565
+ const r = this.getReader();
1332
566
  try {
1333
567
  for (; ; ) {
1334
- const { done: t, value: r } = await e.read();
1335
- if (t)
568
+ const { done: e, value: t } = await r.read();
569
+ if (e)
1336
570
  return;
1337
- yield r;
571
+ yield t;
1338
572
  }
1339
573
  } finally {
1340
- e.releaseLock();
574
+ r.releaseLock();
1341
575
  }
1342
576
  }, ReadableStream.prototype.iterate = // @ts-ignore
1343
577
  ReadableStream.prototype[Symbol.asyncIterator]);
1344
- function journalFSEvents(e, t, r = () => {
578
+ function Y(r, e, t = () => {
1345
579
  }) {
1346
- function s() {
1347
- t = normalizePath(t);
1348
- const i = e[__private__dont__use].FS, o = createFSHooks(i, (u) => {
1349
- if (u.path.startsWith(t))
1350
- r(u);
1351
- else if (u.operation === "RENAME" && u.toPath.startsWith(t))
1352
- for (const g of recordExistingPath(
1353
- e,
1354
- u.path,
1355
- u.toPath
580
+ function o() {
581
+ e = H(e);
582
+ const i = r[p].FS, s = G(i, (l) => {
583
+ if (l.path.startsWith(e))
584
+ t(l);
585
+ else if (l.operation === "RENAME" && l.toPath.startsWith(e))
586
+ for (const y of F(
587
+ r,
588
+ l.path,
589
+ l.toPath
1356
590
  ))
1357
- r(g);
591
+ t(y);
1358
592
  }), a = {};
1359
- for (const [u] of Object.entries(o))
1360
- a[u] = i[u];
1361
- function l() {
1362
- for (const [u, g] of Object.entries(o))
1363
- i[u] = function(...D) {
1364
- return g(...D), a[u].apply(this, D);
593
+ for (const [l] of Object.entries(s))
594
+ a[l] = i[l];
595
+ function m() {
596
+ for (const [l, y] of Object.entries(s))
597
+ i[l] = function(...k) {
598
+ return y(...k), a[l].apply(this, k);
1365
599
  };
1366
600
  }
1367
- function c() {
1368
- for (const [u, g] of Object.entries(a))
1369
- e[__private__dont__use].FS[u] = g;
601
+ function h() {
602
+ for (const [l, y] of Object.entries(a))
603
+ r[p].FS[l] = y;
1370
604
  }
1371
- e[__private__dont__use].journal = {
1372
- bind: l,
1373
- unbind: c
1374
- }, l();
605
+ r[p].journal = {
606
+ bind: m,
607
+ unbind: h
608
+ }, m();
1375
609
  }
1376
- e.addEventListener("runtime.initialized", s), e[__private__dont__use] && s();
610
+ r.addEventListener("runtime.initialized", o), r[p] && o();
1377
611
  function n() {
1378
- e[__private__dont__use].journal.unbind(), delete e[__private__dont__use].journal;
612
+ r[p].journal.unbind(), delete r[p].journal;
1379
613
  }
1380
- return e.addEventListener("runtime.beforedestroy", n), function() {
1381
- return e.removeEventListener("runtime.initialized", s), e.removeEventListener("runtime.beforedestroy", n), e[__private__dont__use].journal.unbind();
614
+ return r.addEventListener("runtime.beforedestroy", n), function() {
615
+ return r.removeEventListener("runtime.initialized", o), r.removeEventListener("runtime.beforedestroy", n), r[p].journal.unbind();
1382
616
  };
1383
617
  }
1384
- const createFSHooks = (e, t = () => {
618
+ const G = (r, e = () => {
1385
619
  }) => ({
1386
- write(r) {
1387
- t({
620
+ write(t) {
621
+ e({
1388
622
  operation: "WRITE",
1389
- path: r.path,
623
+ path: t.path,
1390
624
  nodeType: "file"
1391
625
  });
1392
626
  },
1393
- truncate(r) {
1394
- let s;
1395
- typeof r == "string" ? s = e.lookupPath(r, {
627
+ truncate(t) {
628
+ let o;
629
+ typeof t == "string" ? o = r.lookupPath(t, {
1396
630
  follow: !0
1397
- }).node : s = r, t({
631
+ }).node : o = t, e({
1398
632
  operation: "WRITE",
1399
- path: e.getPath(s),
633
+ path: r.getPath(o),
1400
634
  nodeType: "file"
1401
635
  });
1402
636
  },
1403
- unlink(r) {
1404
- t({
637
+ unlink(t) {
638
+ e({
1405
639
  operation: "DELETE",
1406
- path: r,
640
+ path: t,
1407
641
  nodeType: "file"
1408
642
  });
1409
643
  },
1410
- mknod(r, s) {
1411
- e.isFile(s) && t({
644
+ mknod(t, o) {
645
+ r.isFile(o) && e({
1412
646
  operation: "CREATE",
1413
- path: r,
647
+ path: t,
1414
648
  nodeType: "file"
1415
649
  });
1416
650
  },
1417
- mkdir(r) {
1418
- t({
651
+ mkdir(t) {
652
+ e({
1419
653
  operation: "CREATE",
1420
- path: r,
654
+ path: t,
1421
655
  nodeType: "directory"
1422
656
  });
1423
657
  },
1424
- rmdir(r) {
1425
- t({
658
+ rmdir(t) {
659
+ e({
1426
660
  operation: "DELETE",
1427
- path: r,
661
+ path: t,
1428
662
  nodeType: "directory"
1429
663
  });
1430
664
  },
1431
- rename(r, s) {
665
+ rename(t, o) {
1432
666
  try {
1433
- const n = e.lookupPath(r, {
667
+ const n = r.lookupPath(t, {
1434
668
  follow: !0
1435
- }), i = e.lookupPath(s, {
669
+ }), i = r.lookupPath(o, {
1436
670
  parent: !0
1437
671
  }).path;
1438
- t({
672
+ e({
1439
673
  operation: "RENAME",
1440
- nodeType: e.isDir(n.node.mode) ? "directory" : "file",
674
+ nodeType: r.isDir(n.node.mode) ? "directory" : "file",
1441
675
  path: n.path,
1442
- toPath: joinPaths(i, basename(s))
676
+ toPath: g(i, q(o))
1443
677
  });
1444
678
  } catch {
1445
679
  }
1446
680
  }
1447
681
  });
1448
- function replayFSJournal(e, t) {
1449
- e[__private__dont__use].journal.unbind();
682
+ function Q(r, e) {
683
+ r[p].journal.unbind();
1450
684
  try {
1451
- for (const r of t)
1452
- r.operation === "CREATE" ? r.nodeType === "file" ? e.writeFile(r.path, " ") : e.mkdir(r.path) : r.operation === "DELETE" ? r.nodeType === "file" ? e.unlink(r.path) : e.rmdir(r.path) : r.operation === "WRITE" ? e.writeFile(r.path, r.data) : r.operation === "RENAME" && e.mv(r.path, r.toPath);
685
+ for (const t of e)
686
+ t.operation === "CREATE" ? t.nodeType === "file" ? r.writeFile(t.path, " ") : r.mkdir(t.path) : t.operation === "DELETE" ? t.nodeType === "file" ? r.unlink(t.path) : r.rmdir(t.path) : t.operation === "WRITE" ? r.writeFile(t.path, t.data) : t.operation === "RENAME" && r.mv(t.path, t.toPath);
1453
687
  } finally {
1454
- e[__private__dont__use].journal.bind();
688
+ r[p].journal.bind();
1455
689
  }
1456
690
  }
1457
- function* recordExistingPath(e, t, r) {
1458
- if (e.isDir(t)) {
691
+ function* F(r, e, t) {
692
+ if (r.isDir(e)) {
1459
693
  yield {
1460
694
  operation: "CREATE",
1461
- path: r,
695
+ path: t,
1462
696
  nodeType: "directory"
1463
697
  };
1464
- for (const s of e.listFiles(t))
1465
- yield* recordExistingPath(
1466
- e,
1467
- joinPaths(t, s),
1468
- joinPaths(r, s)
698
+ for (const o of r.listFiles(e))
699
+ yield* F(
700
+ r,
701
+ g(e, o),
702
+ g(t, o)
1469
703
  );
1470
704
  } else
1471
705
  yield {
1472
706
  operation: "CREATE",
1473
- path: r,
707
+ path: t,
1474
708
  nodeType: "file"
1475
709
  }, yield {
1476
710
  operation: "WRITE",
1477
711
  nodeType: "file",
1478
- path: r
712
+ path: t
1479
713
  };
1480
714
  }
1481
- function normalizePath(e) {
1482
- return e.replace(/\/$/, "").replace(/\/\/+/g, "/");
715
+ function H(r) {
716
+ return r.replace(/\/$/, "").replace(/\/\/+/g, "/");
1483
717
  }
1484
- function normalizeFilesystemOperations(e) {
1485
- const t = {};
1486
- for (let r = e.length - 1; r >= 0; r--) {
1487
- for (let s = r - 1; s >= 0; s--) {
1488
- const n = checkRelationship(e[r], e[s]);
718
+ function U(r) {
719
+ const e = {};
720
+ for (let t = r.length - 1; t >= 0; t--) {
721
+ for (let o = t - 1; o >= 0; o--) {
722
+ const n = Z(r[t], r[o]);
1489
723
  if (n === "none")
1490
724
  continue;
1491
- const i = e[r], o = e[s];
1492
- if (i.operation === "RENAME" && o.operation === "RENAME") {
1493
- logger.warn(
725
+ const i = r[t], s = r[o];
726
+ if (i.operation === "RENAME" && s.operation === "RENAME") {
727
+ b.warn(
1494
728
  "[FS Journal] Normalizing a double rename is not yet supported:",
1495
729
  {
1496
730
  current: i,
1497
- last: o
731
+ last: s
1498
732
  }
1499
733
  );
1500
734
  continue;
1501
735
  }
1502
- (o.operation === "CREATE" || o.operation === "WRITE") && (i.operation === "RENAME" ? n === "same_node" ? (t[s] = [], t[r] = [
736
+ (s.operation === "CREATE" || s.operation === "WRITE") && (i.operation === "RENAME" ? n === "same_node" ? (e[o] = [], e[t] = [
1503
737
  {
1504
- ...o,
738
+ ...s,
1505
739
  path: i.toPath
1506
740
  },
1507
- ...t[r] || []
1508
- ]) : n === "descendant" && (t[s] = [], t[r] = [
741
+ ...e[t] || []
742
+ ]) : n === "descendant" && (e[o] = [], e[t] = [
1509
743
  {
1510
- ...o,
1511
- path: joinPaths(
744
+ ...s,
745
+ path: g(
1512
746
  i.toPath,
1513
- o.path.substring(i.path.length)
747
+ s.path.substring(i.path.length)
1514
748
  )
1515
749
  },
1516
- ...t[r] || []
1517
- ]) : i.operation === "WRITE" && n === "same_node" ? t[s] = [] : i.operation === "DELETE" && n === "same_node" && (t[s] = [], t[r] = []));
750
+ ...e[t] || []
751
+ ]) : i.operation === "WRITE" && n === "same_node" ? e[o] = [] : i.operation === "DELETE" && n === "same_node" && (e[o] = [], e[t] = []));
1518
752
  }
1519
- if (Object.entries(t).length > 0) {
1520
- const s = e.flatMap((n, i) => i in t ? t[i] : [n]);
1521
- return normalizeFilesystemOperations(s);
753
+ if (Object.entries(e).length > 0) {
754
+ const o = r.flatMap((n, i) => i in e ? e[i] : [n]);
755
+ return U(o);
1522
756
  }
1523
757
  }
1524
- return e;
758
+ return r;
1525
759
  }
1526
- function checkRelationship(e, t) {
1527
- const r = e.path, s = e.operation !== "WRITE" && e.nodeType === "directory", n = t.operation !== "WRITE" && t.nodeType === "directory", i = t.operation === "RENAME" ? t.toPath : t.path;
1528
- return i === r ? "same_node" : n && r.startsWith(i + "/") ? "ancestor" : s && i.startsWith(r + "/") ? "descendant" : "none";
760
+ function Z(r, e) {
761
+ const t = r.path, o = r.operation !== "WRITE" && r.nodeType === "directory", n = e.operation !== "WRITE" && e.nodeType === "directory", i = e.operation === "RENAME" ? e.toPath : e.path;
762
+ return i === t ? "same_node" : n && t.startsWith(i + "/") ? "ancestor" : o && i.startsWith(t + "/") ? "descendant" : "none";
1529
763
  }
1530
- async function hydrateUpdateFileOps(e, t) {
1531
- const s = t.filter(
764
+ async function X(r, e) {
765
+ const o = e.filter(
1532
766
  (n) => n.operation === "WRITE"
1533
- ).map((n) => hydrateOp(e, n));
1534
- return await Promise.all(s), t;
767
+ ).map((n) => V(r, n));
768
+ return await Promise.all(o), e;
1535
769
  }
1536
- const hydrateLock = new Semaphore({ concurrency: 15 });
1537
- async function hydrateOp(e, t) {
1538
- const r = await hydrateLock.acquire();
770
+ const K = new $({ concurrency: 15 });
771
+ async function V(r, e) {
772
+ const t = await K.acquire();
1539
773
  try {
1540
- t.data = await e.readFileAsBuffer(t.path);
1541
- } catch (s) {
1542
- logger.warn(
1543
- `Journal failed to hydrate a file on flush: the path ${t.path} no longer exists`
1544
- ), logger.error(s);
774
+ e.data = await r.readFileAsBuffer(e.path);
775
+ } catch (o) {
776
+ b.warn(
777
+ `Journal failed to hydrate a file on flush: the path ${e.path} no longer exists`
778
+ ), b.error(o);
1545
779
  }
1546
- r();
780
+ t();
1547
781
  }
1548
782
  export {
1549
- hydrateUpdateFileOps,
1550
- journalFSEvents,
1551
- normalizeFilesystemOperations,
1552
- replayFSJournal
783
+ X as hydrateUpdateFileOps,
784
+ Y as journalFSEvents,
785
+ U as normalizeFilesystemOperations,
786
+ Q as replayFSJournal
1553
787
  };