@php-wasm/fs-journal 0.7.0 → 0.7.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.cjs +8 -12
- package/index.js +401 -603
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
var
|
|
1
|
+
var D = (e, t, r) => {
|
|
2
2
|
if (!t.has(e))
|
|
3
3
|
throw TypeError("Cannot " + r);
|
|
4
4
|
};
|
|
5
|
-
var
|
|
5
|
+
var h = (e, t, r) => (D(e, t, "read from private field"), r ? r.call(e) : t.get(e)), u = (e, t, r) => {
|
|
6
6
|
if (t.has(e))
|
|
7
7
|
throw TypeError("Cannot add the same private member more than once");
|
|
8
8
|
t instanceof WeakSet ? t.add(e) : t.set(e, r);
|
|
9
|
-
},
|
|
10
|
-
var
|
|
9
|
+
}, f = (e, t, r, s) => (D(e, t, "write to private field"), s ? s.call(e, r) : t.set(e, r), r);
|
|
10
|
+
var p = (e, t, r) => (D(e, t, "access private method"), r);
|
|
11
11
|
const currentJsRuntime = function() {
|
|
12
12
|
var e;
|
|
13
13
|
return typeof process < "u" && ((e = process.release) == null ? void 0 : e.name) === "node" ? "NODE" : typeof window < "u" ? "WEB" : (
|
|
@@ -18,25 +18,25 @@ const currentJsRuntime = function() {
|
|
|
18
18
|
}();
|
|
19
19
|
if (currentJsRuntime === "NODE") {
|
|
20
20
|
let e = function(r) {
|
|
21
|
-
return new Promise(function(s,
|
|
22
|
-
r.onload = r.onerror = function(
|
|
23
|
-
r.onload = r.onerror = null,
|
|
21
|
+
return new Promise(function(s, i) {
|
|
22
|
+
r.onload = r.onerror = function(n) {
|
|
23
|
+
r.onload = r.onerror = null, n.type === "load" ? s(r.result) : i(new Error("Failed to read the blob/file"));
|
|
24
24
|
};
|
|
25
25
|
});
|
|
26
26
|
}, t = function() {
|
|
27
|
-
const r = new Uint8Array([1, 2, 3, 4]),
|
|
27
|
+
const r = new Uint8Array([1, 2, 3, 4]), i = new File([r], "test").stream();
|
|
28
28
|
try {
|
|
29
|
-
return
|
|
29
|
+
return i.getReader({ mode: "byob" }), !0;
|
|
30
30
|
} catch {
|
|
31
31
|
return !1;
|
|
32
32
|
}
|
|
33
33
|
};
|
|
34
34
|
if (typeof File > "u") {
|
|
35
35
|
class r extends Blob {
|
|
36
|
-
constructor(
|
|
37
|
-
super(
|
|
36
|
+
constructor(i, n, o) {
|
|
37
|
+
super(i);
|
|
38
38
|
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 =
|
|
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 = n || "";
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
global.File = r;
|
|
@@ -55,14 +55,14 @@ if (currentJsRuntime === "NODE") {
|
|
|
55
55
|
// 0.5 MB seems like a reasonable chunk size, let's adjust
|
|
56
56
|
// this if needed.
|
|
57
57
|
autoAllocateChunkSize: 512 * 1024,
|
|
58
|
-
async pull(
|
|
59
|
-
const
|
|
58
|
+
async pull(i) {
|
|
59
|
+
const n = i.byobRequest.view, a = await s.slice(
|
|
60
60
|
r,
|
|
61
|
-
r +
|
|
62
|
-
).arrayBuffer(),
|
|
63
|
-
new Uint8Array(
|
|
64
|
-
const
|
|
65
|
-
|
|
61
|
+
r + n.byteLength
|
|
62
|
+
).arrayBuffer(), l = new Uint8Array(a);
|
|
63
|
+
new Uint8Array(n.buffer).set(l);
|
|
64
|
+
const c = l.byteLength;
|
|
65
|
+
i.byobRequest.respond(c), r += c, r >= s.size && i.close();
|
|
66
66
|
}
|
|
67
67
|
});
|
|
68
68
|
});
|
|
@@ -102,6 +102,171 @@ const ErrorEvent = typeof globalThis.ErrorEvent == "function" ? globalThis.Error
|
|
|
102
102
|
function isExitCodeZero(e) {
|
|
103
103
|
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;
|
|
104
104
|
}
|
|
105
|
+
const logToConsole = (e, ...t) => {
|
|
106
|
+
switch (e.severity) {
|
|
107
|
+
case "Debug":
|
|
108
|
+
console.debug(e.message, ...t);
|
|
109
|
+
break;
|
|
110
|
+
case "Info":
|
|
111
|
+
console.info(e.message, ...t);
|
|
112
|
+
break;
|
|
113
|
+
case "Warn":
|
|
114
|
+
console.warn(e.message, ...t);
|
|
115
|
+
break;
|
|
116
|
+
case "Error":
|
|
117
|
+
console.error(e.message, ...t);
|
|
118
|
+
break;
|
|
119
|
+
case "Fatal":
|
|
120
|
+
console.error(e.message, ...t);
|
|
121
|
+
break;
|
|
122
|
+
default:
|
|
123
|
+
console.log(e.message, ...t);
|
|
124
|
+
}
|
|
125
|
+
}, prepareLogMessage = (e, ...t) => [
|
|
126
|
+
typeof e == "object" ? JSON.stringify(e) : e,
|
|
127
|
+
...t.map((r) => JSON.stringify(r))
|
|
128
|
+
].join(" "), logs = [], addToLogArray = (e) => {
|
|
129
|
+
logs.push(e);
|
|
130
|
+
}, logToMemory = (e) => {
|
|
131
|
+
if (e.raw === !0)
|
|
132
|
+
addToLogArray(e.message);
|
|
133
|
+
else {
|
|
134
|
+
const t = formatLogEntry(
|
|
135
|
+
typeof e.message == "object" ? prepareLogMessage(e.message) : e.message,
|
|
136
|
+
e.severity ?? "Info",
|
|
137
|
+
e.prefix ?? "JavaScript"
|
|
138
|
+
);
|
|
139
|
+
addToLogArray(t);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
class Logger extends EventTarget {
|
|
143
|
+
// constructor
|
|
144
|
+
constructor(t = []) {
|
|
145
|
+
super(), this.handlers = t, this.fatalErrorEvent = "playground-fatal-error";
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Get all logs.
|
|
149
|
+
* @returns string[]
|
|
150
|
+
*/
|
|
151
|
+
getLogs() {
|
|
152
|
+
return this.handlers.includes(logToMemory) ? [...logs] : (this.error(`Logs aren't stored because the logToMemory handler isn't registered.
|
|
153
|
+
If you're using a custom logger instance, make sure to register logToMemory handler.
|
|
154
|
+
`), []);
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Log message with severity.
|
|
158
|
+
*
|
|
159
|
+
* @param message any
|
|
160
|
+
* @param severity LogSeverity
|
|
161
|
+
* @param raw boolean
|
|
162
|
+
* @param args any
|
|
163
|
+
*/
|
|
164
|
+
logMessage(t, ...r) {
|
|
165
|
+
for (const s of this.handlers)
|
|
166
|
+
s(t, ...r);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Log message
|
|
170
|
+
*
|
|
171
|
+
* @param message any
|
|
172
|
+
* @param args any
|
|
173
|
+
*/
|
|
174
|
+
log(t, ...r) {
|
|
175
|
+
this.logMessage(
|
|
176
|
+
{
|
|
177
|
+
message: t,
|
|
178
|
+
severity: void 0,
|
|
179
|
+
prefix: "JavaScript",
|
|
180
|
+
raw: !1
|
|
181
|
+
},
|
|
182
|
+
...r
|
|
183
|
+
);
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
* Log debug message
|
|
187
|
+
*
|
|
188
|
+
* @param message any
|
|
189
|
+
* @param args any
|
|
190
|
+
*/
|
|
191
|
+
debug(t, ...r) {
|
|
192
|
+
this.logMessage(
|
|
193
|
+
{
|
|
194
|
+
message: t,
|
|
195
|
+
severity: "Debug",
|
|
196
|
+
prefix: "JavaScript",
|
|
197
|
+
raw: !1
|
|
198
|
+
},
|
|
199
|
+
...r
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Log info message
|
|
204
|
+
*
|
|
205
|
+
* @param message any
|
|
206
|
+
* @param args any
|
|
207
|
+
*/
|
|
208
|
+
info(t, ...r) {
|
|
209
|
+
this.logMessage(
|
|
210
|
+
{
|
|
211
|
+
message: t,
|
|
212
|
+
severity: "Info",
|
|
213
|
+
prefix: "JavaScript",
|
|
214
|
+
raw: !1
|
|
215
|
+
},
|
|
216
|
+
...r
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Log warning message
|
|
221
|
+
*
|
|
222
|
+
* @param message any
|
|
223
|
+
* @param args any
|
|
224
|
+
*/
|
|
225
|
+
warn(t, ...r) {
|
|
226
|
+
this.logMessage(
|
|
227
|
+
{
|
|
228
|
+
message: t,
|
|
229
|
+
severity: "Warn",
|
|
230
|
+
prefix: "JavaScript",
|
|
231
|
+
raw: !1
|
|
232
|
+
},
|
|
233
|
+
...r
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Log error message
|
|
238
|
+
*
|
|
239
|
+
* @param message any
|
|
240
|
+
* @param args any
|
|
241
|
+
*/
|
|
242
|
+
error(t, ...r) {
|
|
243
|
+
this.logMessage(
|
|
244
|
+
{
|
|
245
|
+
message: t,
|
|
246
|
+
severity: "Error",
|
|
247
|
+
prefix: "JavaScript",
|
|
248
|
+
raw: !1
|
|
249
|
+
},
|
|
250
|
+
...r
|
|
251
|
+
);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
const logger = new Logger([logToMemory, logToConsole]), formatLogEntry = (e, t, r) => {
|
|
255
|
+
const s = /* @__PURE__ */ new Date(), i = new Intl.DateTimeFormat("en-GB", {
|
|
256
|
+
year: "numeric",
|
|
257
|
+
month: "short",
|
|
258
|
+
day: "2-digit",
|
|
259
|
+
timeZone: "UTC"
|
|
260
|
+
}).format(s).replace(/ /g, "-"), n = new Intl.DateTimeFormat("en-GB", {
|
|
261
|
+
hour: "2-digit",
|
|
262
|
+
minute: "2-digit",
|
|
263
|
+
second: "2-digit",
|
|
264
|
+
hour12: !1,
|
|
265
|
+
timeZone: "UTC",
|
|
266
|
+
timeZoneName: "short"
|
|
267
|
+
}).format(s);
|
|
268
|
+
return `[${i + " " + n}] ${r} ${t}: ${e}`;
|
|
269
|
+
};
|
|
105
270
|
class UnhandledRejectionsTarget extends EventTarget {
|
|
106
271
|
constructor() {
|
|
107
272
|
super(...arguments), this.listenersCount = 0;
|
|
@@ -124,16 +289,16 @@ function improveWASMErrorReporting(e) {
|
|
|
124
289
|
for (const r in e.asm)
|
|
125
290
|
if (typeof e.asm[r] == "function") {
|
|
126
291
|
const s = e.asm[r];
|
|
127
|
-
e.asm[r] = function(...
|
|
128
|
-
var
|
|
292
|
+
e.asm[r] = function(...i) {
|
|
293
|
+
var n;
|
|
129
294
|
try {
|
|
130
|
-
return s(...
|
|
295
|
+
return s(...i);
|
|
131
296
|
} catch (o) {
|
|
132
297
|
if (!(o instanceof Error))
|
|
133
298
|
throw o;
|
|
134
299
|
const a = clarifyErrorMessage(
|
|
135
300
|
o,
|
|
136
|
-
(
|
|
301
|
+
(n = e.lastAsyncifyStackSource) == null ? void 0 : n.stack
|
|
137
302
|
);
|
|
138
303
|
if (e.lastAsyncifyStackSource && (o.cause = e.lastAsyncifyStackSource), t.hasListeners()) {
|
|
139
304
|
t.dispatchEvent(
|
|
@@ -200,13 +365,13 @@ CLI option:
|
|
|
200
365
|
let logged = !1;
|
|
201
366
|
function showCriticalErrorBox(e) {
|
|
202
367
|
if (!logged && (logged = !0, !(e != null && e.trim().startsWith("Program terminated with exit")))) {
|
|
203
|
-
|
|
368
|
+
logger.log(`${redBg}
|
|
204
369
|
${eol}
|
|
205
370
|
${bold} WASM ERROR${reset}${redBg}`);
|
|
206
371
|
for (const t of e.split(`
|
|
207
372
|
`))
|
|
208
|
-
|
|
209
|
-
|
|
373
|
+
logger.log(`${eol} ${t} `);
|
|
374
|
+
logger.log(`${reset}`);
|
|
210
375
|
}
|
|
211
376
|
}
|
|
212
377
|
function extractPHPFunctionsFromStack(e) {
|
|
@@ -298,8 +463,8 @@ function normalizePath$1(e) {
|
|
|
298
463
|
function normalizePathsArray(e, t) {
|
|
299
464
|
let r = 0;
|
|
300
465
|
for (let s = e.length - 1; s >= 0; s--) {
|
|
301
|
-
const
|
|
302
|
-
|
|
466
|
+
const i = e[s];
|
|
467
|
+
i === "." ? e.splice(s, 1) : i === ".." ? (e.splice(s, 1), r++) : r && (e.splice(s, 1), r--);
|
|
303
468
|
}
|
|
304
469
|
if (t)
|
|
305
470
|
for (; r; r--)
|
|
@@ -307,18 +472,18 @@ function normalizePathsArray(e, t) {
|
|
|
307
472
|
return e;
|
|
308
473
|
}
|
|
309
474
|
function splitShellCommand(e) {
|
|
310
|
-
let s = 0,
|
|
311
|
-
const
|
|
475
|
+
let s = 0, i = "";
|
|
476
|
+
const n = [];
|
|
312
477
|
let o = "";
|
|
313
478
|
for (let a = 0; a < e.length; a++) {
|
|
314
|
-
const
|
|
315
|
-
|
|
479
|
+
const l = e[a];
|
|
480
|
+
l === "\\" ? ((e[a + 1] === '"' || e[a + 1] === "'") && a++, o += e[a]) : s === 0 ? l === '"' || l === "'" ? (s = 1, i = l) : l.match(/\s/) ? (o.trim().length && n.push(o.trim()), o = l) : n.length && !o ? o = n.pop() + l : o += l : s === 1 && (l === i ? (s = 0, i = "") : o += l);
|
|
316
481
|
}
|
|
317
|
-
return o &&
|
|
482
|
+
return o && n.push(o.trim()), n;
|
|
318
483
|
}
|
|
319
484
|
function createSpawnHandler(e) {
|
|
320
485
|
return function(t, r = [], s = {}) {
|
|
321
|
-
const
|
|
486
|
+
const i = new ChildProcess(), n = new ProcessApi(i);
|
|
322
487
|
return setTimeout(async () => {
|
|
323
488
|
let o = [];
|
|
324
489
|
if (r.length)
|
|
@@ -329,8 +494,13 @@ function createSpawnHandler(e) {
|
|
|
329
494
|
o = t;
|
|
330
495
|
else
|
|
331
496
|
throw new Error("Invalid command ", t);
|
|
332
|
-
|
|
333
|
-
|
|
497
|
+
try {
|
|
498
|
+
await e(o, n, s);
|
|
499
|
+
} catch (a) {
|
|
500
|
+
i.emit("error", a), typeof a == "object" && a !== null && "message" in a && typeof a.message == "string" && n.stderr(a.message), n.exit(1);
|
|
501
|
+
}
|
|
502
|
+
i.emit("spawn", !0);
|
|
503
|
+
}), i;
|
|
334
504
|
};
|
|
335
505
|
}
|
|
336
506
|
class EventEmitter {
|
|
@@ -400,9 +570,33 @@ ReadableStream.prototype[Symbol.asyncIterator] || (ReadableStream.prototype[Symb
|
|
|
400
570
|
}
|
|
401
571
|
}, ReadableStream.prototype.iterate = // @ts-ignore
|
|
402
572
|
ReadableStream.prototype[Symbol.asyncIterator]);
|
|
573
|
+
const responseTexts = {
|
|
574
|
+
500: "Internal Server Error",
|
|
575
|
+
502: "Bad Gateway",
|
|
576
|
+
404: "Not Found",
|
|
577
|
+
403: "Forbidden",
|
|
578
|
+
401: "Unauthorized",
|
|
579
|
+
400: "Bad Request",
|
|
580
|
+
301: "Moved Permanently",
|
|
581
|
+
302: "Found",
|
|
582
|
+
307: "Temporary Redirect",
|
|
583
|
+
308: "Permanent Redirect",
|
|
584
|
+
204: "No Content",
|
|
585
|
+
201: "Created",
|
|
586
|
+
200: "OK"
|
|
587
|
+
};
|
|
403
588
|
class PHPResponse {
|
|
404
|
-
constructor(t, r, s,
|
|
405
|
-
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode =
|
|
589
|
+
constructor(t, r, s, i = "", n = 0) {
|
|
590
|
+
this.httpStatusCode = t, this.headers = r, this.bytes = s, this.exitCode = n, this.errors = i;
|
|
591
|
+
}
|
|
592
|
+
static forHttpCode(t, r = "") {
|
|
593
|
+
return new PHPResponse(
|
|
594
|
+
t,
|
|
595
|
+
{},
|
|
596
|
+
new TextEncoder().encode(
|
|
597
|
+
r || responseTexts[t] || ""
|
|
598
|
+
)
|
|
599
|
+
);
|
|
406
600
|
}
|
|
407
601
|
static fromRawData(t) {
|
|
408
602
|
return new PHPResponse(
|
|
@@ -435,410 +629,6 @@ class PHPResponse {
|
|
|
435
629
|
return new TextDecoder().decode(this.bytes);
|
|
436
630
|
}
|
|
437
631
|
}
|
|
438
|
-
const DEFAULT_BASE_URL = "http://example.com";
|
|
439
|
-
function toRelativeUrl(e) {
|
|
440
|
-
return e.toString().substring(e.origin.length);
|
|
441
|
-
}
|
|
442
|
-
function removePathPrefix(e, t) {
|
|
443
|
-
return !t || !e.startsWith(t) ? e : e.substring(t.length);
|
|
444
|
-
}
|
|
445
|
-
function ensurePathPrefix(e, t) {
|
|
446
|
-
return !t || e.startsWith(t) ? e : t + e;
|
|
447
|
-
}
|
|
448
|
-
async function encodeAsMultipart(e) {
|
|
449
|
-
const t = `----${Math.random().toString(36).slice(2)}`, r = `multipart/form-data; boundary=${t}`, s = new TextEncoder(), n = [];
|
|
450
|
-
for (const [c, u] of Object.entries(e))
|
|
451
|
-
n.push(`--${t}\r
|
|
452
|
-
`), n.push(`Content-Disposition: form-data; name="${c}"`), u instanceof File && n.push(`; filename="${u.name}"`), n.push(`\r
|
|
453
|
-
`), u instanceof File && (n.push("Content-Type: application/octet-stream"), n.push(`\r
|
|
454
|
-
`)), n.push(`\r
|
|
455
|
-
`), u instanceof File ? n.push(await fileToUint8Array(u)) : n.push(u), n.push(`\r
|
|
456
|
-
`);
|
|
457
|
-
n.push(`--${t}--\r
|
|
458
|
-
`);
|
|
459
|
-
const i = n.reduce((c, u) => c + u.length, 0), o = new Uint8Array(i);
|
|
460
|
-
let a = 0;
|
|
461
|
-
for (const c of n)
|
|
462
|
-
o.set(
|
|
463
|
-
typeof c == "string" ? s.encode(c) : c,
|
|
464
|
-
a
|
|
465
|
-
), a += c.length;
|
|
466
|
-
return { bytes: o, contentType: r };
|
|
467
|
-
}
|
|
468
|
-
function fileToUint8Array(e) {
|
|
469
|
-
return new Promise((t) => {
|
|
470
|
-
const r = new FileReader();
|
|
471
|
-
r.onload = () => {
|
|
472
|
-
t(new Uint8Array(r.result));
|
|
473
|
-
}, r.readAsArrayBuffer(e);
|
|
474
|
-
});
|
|
475
|
-
}
|
|
476
|
-
class HttpCookieStore {
|
|
477
|
-
constructor() {
|
|
478
|
-
this.cookies = {};
|
|
479
|
-
}
|
|
480
|
-
rememberCookiesFromResponseHeaders(t) {
|
|
481
|
-
if (t != null && t["set-cookie"])
|
|
482
|
-
for (const r of t["set-cookie"])
|
|
483
|
-
try {
|
|
484
|
-
if (!r.includes("="))
|
|
485
|
-
continue;
|
|
486
|
-
const s = r.indexOf("="), n = r.substring(0, s), i = r.substring(s + 1).split(";")[0];
|
|
487
|
-
this.cookies[n] = i;
|
|
488
|
-
} catch (s) {
|
|
489
|
-
console.error(s);
|
|
490
|
-
}
|
|
491
|
-
}
|
|
492
|
-
getCookieRequestHeader() {
|
|
493
|
-
const t = [];
|
|
494
|
-
for (const r in this.cookies)
|
|
495
|
-
t.push(`${r}=${this.cookies[r]}`);
|
|
496
|
-
return t.join("; ");
|
|
497
|
-
}
|
|
498
|
-
}
|
|
499
|
-
var m, b, A, P, S, _, T, v, F, H, Z, N, X, O, ee;
|
|
500
|
-
class PHPRequestHandler {
|
|
501
|
-
/**
|
|
502
|
-
* @param php - The PHP instance.
|
|
503
|
-
* @param config - Request Handler configuration.
|
|
504
|
-
*/
|
|
505
|
-
constructor(t, r = {}) {
|
|
506
|
-
/**
|
|
507
|
-
* Serves a static file from the PHP filesystem.
|
|
508
|
-
*
|
|
509
|
-
* @param fsPath - Absolute path of the static file to serve.
|
|
510
|
-
* @returns The response.
|
|
511
|
-
*/
|
|
512
|
-
d(this, H);
|
|
513
|
-
/**
|
|
514
|
-
* Runs the requested PHP file with all the request and $_SERVER
|
|
515
|
-
* superglobals populated.
|
|
516
|
-
*
|
|
517
|
-
* @param request - The request.
|
|
518
|
-
* @returns The response.
|
|
519
|
-
*/
|
|
520
|
-
d(this, N);
|
|
521
|
-
/**
|
|
522
|
-
* Resolve the requested path to the filesystem path of the requested PHP file.
|
|
523
|
-
*
|
|
524
|
-
* Fall back to index.php as if there was a url rewriting rule in place.
|
|
525
|
-
*
|
|
526
|
-
* @param requestedPath - The requested pathname.
|
|
527
|
-
* @throws {Error} If the requested path doesn't exist.
|
|
528
|
-
* @returns The resolved filesystem path.
|
|
529
|
-
*/
|
|
530
|
-
d(this, O);
|
|
531
|
-
d(this, m, void 0);
|
|
532
|
-
d(this, b, void 0);
|
|
533
|
-
d(this, A, void 0);
|
|
534
|
-
d(this, P, void 0);
|
|
535
|
-
d(this, S, void 0);
|
|
536
|
-
d(this, _, void 0);
|
|
537
|
-
d(this, T, void 0);
|
|
538
|
-
d(this, v, void 0);
|
|
539
|
-
d(this, F, void 0);
|
|
540
|
-
p(this, v, new Semaphore({ concurrency: 1 }));
|
|
541
|
-
const {
|
|
542
|
-
documentRoot: s = "/www/",
|
|
543
|
-
absoluteUrl: n = typeof location == "object" ? location == null ? void 0 : location.href : "",
|
|
544
|
-
rewriteRules: i = []
|
|
545
|
-
} = r;
|
|
546
|
-
this.php = t, p(this, F, new HttpCookieStore()), p(this, m, s);
|
|
547
|
-
const o = new URL(n);
|
|
548
|
-
p(this, A, o.hostname), p(this, P, o.port ? Number(o.port) : o.protocol === "https:" ? 443 : 80), p(this, b, (o.protocol || "").replace(":", ""));
|
|
549
|
-
const a = l(this, P) !== 443 && l(this, P) !== 80;
|
|
550
|
-
p(this, S, [
|
|
551
|
-
l(this, A),
|
|
552
|
-
a ? `:${l(this, P)}` : ""
|
|
553
|
-
].join("")), p(this, _, o.pathname.replace(/\/+$/, "")), p(this, T, [
|
|
554
|
-
`${l(this, b)}://`,
|
|
555
|
-
l(this, S),
|
|
556
|
-
l(this, _)
|
|
557
|
-
].join("")), this.rewriteRules = i;
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
561
|
-
* root.
|
|
562
|
-
*
|
|
563
|
-
* @param path The server path to convert to an absolute URL.
|
|
564
|
-
* @returns The absolute URL.
|
|
565
|
-
*/
|
|
566
|
-
pathToInternalUrl(t) {
|
|
567
|
-
return `${this.absoluteUrl}${t}`;
|
|
568
|
-
}
|
|
569
|
-
/**
|
|
570
|
-
* Converts an absolute URL based at the PHPRequestHandler to a relative path
|
|
571
|
-
* without the server pathname and scope.
|
|
572
|
-
*
|
|
573
|
-
* @param internalUrl An absolute URL based at the PHPRequestHandler root.
|
|
574
|
-
* @returns The relative path.
|
|
575
|
-
*/
|
|
576
|
-
internalUrlToPath(t) {
|
|
577
|
-
const r = new URL(t);
|
|
578
|
-
return r.pathname.startsWith(l(this, _)) && (r.pathname = r.pathname.slice(l(this, _).length)), toRelativeUrl(r);
|
|
579
|
-
}
|
|
580
|
-
get isRequestRunning() {
|
|
581
|
-
return l(this, v).running > 0;
|
|
582
|
-
}
|
|
583
|
-
/**
|
|
584
|
-
* The absolute URL of this PHPRequestHandler instance.
|
|
585
|
-
*/
|
|
586
|
-
get absoluteUrl() {
|
|
587
|
-
return l(this, T);
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* The directory in the PHP filesystem where the server will look
|
|
591
|
-
* for the files to serve. Default: `/var/www`.
|
|
592
|
-
*/
|
|
593
|
-
get documentRoot() {
|
|
594
|
-
return l(this, m);
|
|
595
|
-
}
|
|
596
|
-
/**
|
|
597
|
-
* Serves the request – either by serving a static file, or by
|
|
598
|
-
* dispatching it to the PHP runtime.
|
|
599
|
-
*
|
|
600
|
-
* The request() method mode behaves like a web server and only works if
|
|
601
|
-
* the PHP was initialized with a `requestHandler` option (which the online version
|
|
602
|
-
* of WordPress Playground does by default).
|
|
603
|
-
*
|
|
604
|
-
* In the request mode, you pass an object containing the request information
|
|
605
|
-
* (method, headers, body, etc.) and the path to the PHP file to run:
|
|
606
|
-
*
|
|
607
|
-
* ```ts
|
|
608
|
-
* const php = PHP.load('7.4', {
|
|
609
|
-
* requestHandler: {
|
|
610
|
-
* documentRoot: "/www"
|
|
611
|
-
* }
|
|
612
|
-
* })
|
|
613
|
-
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
|
|
614
|
-
* const result = await php.request({
|
|
615
|
-
* method: "GET",
|
|
616
|
-
* headers: {
|
|
617
|
-
* "Content-Type": "text/plain"
|
|
618
|
-
* },
|
|
619
|
-
* body: "Hello world!",
|
|
620
|
-
* path: "/www/index.php"
|
|
621
|
-
* });
|
|
622
|
-
* // result.text === "Hello world!"
|
|
623
|
-
* ```
|
|
624
|
-
*
|
|
625
|
-
* The `request()` method cannot be used in conjunction with `cli()`.
|
|
626
|
-
*
|
|
627
|
-
* @example
|
|
628
|
-
* ```js
|
|
629
|
-
* const output = await php.request({
|
|
630
|
-
* method: 'GET',
|
|
631
|
-
* url: '/index.php',
|
|
632
|
-
* headers: {
|
|
633
|
-
* 'X-foo': 'bar',
|
|
634
|
-
* },
|
|
635
|
-
* body: {
|
|
636
|
-
* foo: 'bar',
|
|
637
|
-
* },
|
|
638
|
-
* });
|
|
639
|
-
* console.log(output.stdout); // "Hello world!"
|
|
640
|
-
* ```
|
|
641
|
-
*
|
|
642
|
-
* @param request - PHP Request data.
|
|
643
|
-
*/
|
|
644
|
-
async request(t) {
|
|
645
|
-
const r = t.url.startsWith("http://") || t.url.startsWith("https://"), s = new URL(
|
|
646
|
-
// Remove the hash part of the URL as it's not meant for the server.
|
|
647
|
-
t.url.split("#")[0],
|
|
648
|
-
r ? void 0 : DEFAULT_BASE_URL
|
|
649
|
-
), n = applyRewriteRules(
|
|
650
|
-
removePathPrefix(
|
|
651
|
-
decodeURIComponent(s.pathname),
|
|
652
|
-
l(this, _)
|
|
653
|
-
),
|
|
654
|
-
this.rewriteRules
|
|
655
|
-
), i = joinPaths(l(this, m), n);
|
|
656
|
-
return seemsLikeAPHPRequestHandlerPath(i) ? await f(this, N, X).call(this, t, s) : f(this, H, Z).call(this, i);
|
|
657
|
-
}
|
|
658
|
-
}
|
|
659
|
-
m = new WeakMap(), b = new WeakMap(), A = new WeakMap(), P = new WeakMap(), S = new WeakMap(), _ = new WeakMap(), T = new WeakMap(), v = new WeakMap(), F = new WeakMap(), H = new WeakSet(), Z = function(t) {
|
|
660
|
-
if (!this.php.fileExists(t))
|
|
661
|
-
return new PHPResponse(
|
|
662
|
-
404,
|
|
663
|
-
// Let the service worker know that no static file was found
|
|
664
|
-
// and that it's okay to issue a real fetch() to the server.
|
|
665
|
-
{
|
|
666
|
-
"x-file-type": ["static"]
|
|
667
|
-
},
|
|
668
|
-
new TextEncoder().encode("404 File not found")
|
|
669
|
-
);
|
|
670
|
-
const r = this.php.readFileAsBuffer(t);
|
|
671
|
-
return new PHPResponse(
|
|
672
|
-
200,
|
|
673
|
-
{
|
|
674
|
-
"content-length": [`${r.byteLength}`],
|
|
675
|
-
// @TODO: Infer the content-type from the arrayBuffer instead of the file path.
|
|
676
|
-
// The code below won't return the correct mime-type if the extension
|
|
677
|
-
// was tampered with.
|
|
678
|
-
"content-type": [inferMimeType(t)],
|
|
679
|
-
"accept-ranges": ["bytes"],
|
|
680
|
-
"cache-control": ["public, max-age=0"]
|
|
681
|
-
},
|
|
682
|
-
r
|
|
683
|
-
);
|
|
684
|
-
}, N = new WeakSet(), X = async function(t, r) {
|
|
685
|
-
var n;
|
|
686
|
-
if (l(this, v).running > 0 && ((n = t.headers) == null ? void 0 : n["x-request-issuer"]) === "php")
|
|
687
|
-
return console.warn(
|
|
688
|
-
"Possible deadlock: Called request() before the previous request() have finished. PHP likely issued an HTTP call to itself. Normally this would lead to infinite waiting as Request 1 holds the lock that the Request 2 is waiting to acquire. That's not useful, so PHPRequestHandler will return error 502 instead."
|
|
689
|
-
), new PHPResponse(
|
|
690
|
-
502,
|
|
691
|
-
{},
|
|
692
|
-
new TextEncoder().encode("502 Bad Gateway")
|
|
693
|
-
);
|
|
694
|
-
const s = await l(this, v).acquire();
|
|
695
|
-
try {
|
|
696
|
-
let i = "GET";
|
|
697
|
-
const o = {
|
|
698
|
-
host: l(this, S),
|
|
699
|
-
...normalizeHeaders(t.headers || {}),
|
|
700
|
-
cookie: l(this, F).getCookieRequestHeader()
|
|
701
|
-
};
|
|
702
|
-
let a = t.body;
|
|
703
|
-
if (typeof a == "object" && !(a instanceof Uint8Array)) {
|
|
704
|
-
i = "POST";
|
|
705
|
-
const { bytes: u, contentType: h } = await encodeAsMultipart(a);
|
|
706
|
-
a = u, o["content-type"] = h;
|
|
707
|
-
}
|
|
708
|
-
let c;
|
|
709
|
-
try {
|
|
710
|
-
c = f(this, O, ee).call(this, decodeURIComponent(r.pathname));
|
|
711
|
-
} catch {
|
|
712
|
-
return new PHPResponse(
|
|
713
|
-
404,
|
|
714
|
-
{},
|
|
715
|
-
new TextEncoder().encode("404 File not found")
|
|
716
|
-
);
|
|
717
|
-
}
|
|
718
|
-
try {
|
|
719
|
-
const u = await this.php.run({
|
|
720
|
-
relativeUri: ensurePathPrefix(
|
|
721
|
-
toRelativeUrl(r),
|
|
722
|
-
l(this, _)
|
|
723
|
-
),
|
|
724
|
-
protocol: l(this, b),
|
|
725
|
-
method: t.method || i,
|
|
726
|
-
$_SERVER: {
|
|
727
|
-
REMOTE_ADDR: "127.0.0.1",
|
|
728
|
-
DOCUMENT_ROOT: l(this, m),
|
|
729
|
-
HTTPS: l(this, T).startsWith("https://") ? "on" : ""
|
|
730
|
-
},
|
|
731
|
-
body: a,
|
|
732
|
-
scriptPath: c,
|
|
733
|
-
headers: o
|
|
734
|
-
});
|
|
735
|
-
return l(this, F).rememberCookiesFromResponseHeaders(
|
|
736
|
-
u.headers
|
|
737
|
-
), u;
|
|
738
|
-
} catch (u) {
|
|
739
|
-
const h = u;
|
|
740
|
-
if (h != null && h.response)
|
|
741
|
-
return h.response;
|
|
742
|
-
throw u;
|
|
743
|
-
}
|
|
744
|
-
} finally {
|
|
745
|
-
s();
|
|
746
|
-
}
|
|
747
|
-
}, O = new WeakSet(), ee = function(t) {
|
|
748
|
-
let r = removePathPrefix(t, l(this, _));
|
|
749
|
-
r = applyRewriteRules(r, this.rewriteRules), r.includes(".php") ? r = r.split(".php")[0] + ".php" : this.php.isDir(`${l(this, m)}${r}`) ? (r.endsWith("/") || (r = `${r}/`), r = `${r}index.php`) : r = "/index.php";
|
|
750
|
-
const s = `${l(this, m)}${r}`;
|
|
751
|
-
if (this.php.fileExists(s))
|
|
752
|
-
return s;
|
|
753
|
-
throw new Error(`File not found: ${s}`);
|
|
754
|
-
};
|
|
755
|
-
function inferMimeType(e) {
|
|
756
|
-
switch (e.split(".").pop()) {
|
|
757
|
-
case "css":
|
|
758
|
-
return "text/css";
|
|
759
|
-
case "js":
|
|
760
|
-
return "application/javascript";
|
|
761
|
-
case "png":
|
|
762
|
-
return "image/png";
|
|
763
|
-
case "jpg":
|
|
764
|
-
case "jpeg":
|
|
765
|
-
return "image/jpeg";
|
|
766
|
-
case "gif":
|
|
767
|
-
return "image/gif";
|
|
768
|
-
case "svg":
|
|
769
|
-
return "image/svg+xml";
|
|
770
|
-
case "woff":
|
|
771
|
-
return "font/woff";
|
|
772
|
-
case "woff2":
|
|
773
|
-
return "font/woff2";
|
|
774
|
-
case "ttf":
|
|
775
|
-
return "font/ttf";
|
|
776
|
-
case "otf":
|
|
777
|
-
return "font/otf";
|
|
778
|
-
case "eot":
|
|
779
|
-
return "font/eot";
|
|
780
|
-
case "ico":
|
|
781
|
-
return "image/x-icon";
|
|
782
|
-
case "html":
|
|
783
|
-
return "text/html";
|
|
784
|
-
case "json":
|
|
785
|
-
return "application/json";
|
|
786
|
-
case "xml":
|
|
787
|
-
return "application/xml";
|
|
788
|
-
case "txt":
|
|
789
|
-
case "md":
|
|
790
|
-
return "text/plain";
|
|
791
|
-
case "pdf":
|
|
792
|
-
return "application/pdf";
|
|
793
|
-
case "webp":
|
|
794
|
-
return "image/webp";
|
|
795
|
-
case "mp3":
|
|
796
|
-
return "audio/mpeg";
|
|
797
|
-
case "mp4":
|
|
798
|
-
return "video/mp4";
|
|
799
|
-
case "csv":
|
|
800
|
-
return "text/csv";
|
|
801
|
-
case "xls":
|
|
802
|
-
return "application/vnd.ms-excel";
|
|
803
|
-
case "xlsx":
|
|
804
|
-
return "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
805
|
-
case "doc":
|
|
806
|
-
return "application/msword";
|
|
807
|
-
case "docx":
|
|
808
|
-
return "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
809
|
-
case "ppt":
|
|
810
|
-
return "application/vnd.ms-powerpoint";
|
|
811
|
-
case "pptx":
|
|
812
|
-
return "application/vnd.openxmlformats-officedocument.presentationml.presentation";
|
|
813
|
-
case "zip":
|
|
814
|
-
return "application/zip";
|
|
815
|
-
case "rar":
|
|
816
|
-
return "application/x-rar-compressed";
|
|
817
|
-
case "tar":
|
|
818
|
-
return "application/x-tar";
|
|
819
|
-
case "gz":
|
|
820
|
-
return "application/gzip";
|
|
821
|
-
case "7z":
|
|
822
|
-
return "application/x-7z-compressed";
|
|
823
|
-
default:
|
|
824
|
-
return "application-octet-stream";
|
|
825
|
-
}
|
|
826
|
-
}
|
|
827
|
-
function seemsLikeAPHPRequestHandlerPath(e) {
|
|
828
|
-
return seemsLikeAPHPFile(e) || seemsLikeADirectoryRoot(e);
|
|
829
|
-
}
|
|
830
|
-
function seemsLikeAPHPFile(e) {
|
|
831
|
-
return e.endsWith(".php") || e.includes(".php/");
|
|
832
|
-
}
|
|
833
|
-
function seemsLikeADirectoryRoot(e) {
|
|
834
|
-
return !e.split("/").pop().includes(".");
|
|
835
|
-
}
|
|
836
|
-
function applyRewriteRules(e, t) {
|
|
837
|
-
for (const r of t)
|
|
838
|
-
if (new RegExp(r.match).test(e))
|
|
839
|
-
return e.replace(r.match, r.replacement);
|
|
840
|
-
return e;
|
|
841
|
-
}
|
|
842
632
|
const FileErrorCodes = {
|
|
843
633
|
0: "No error occurred. System call completed successfully.",
|
|
844
634
|
1: "Argument list too long.",
|
|
@@ -924,16 +714,16 @@ function getEmscriptenFsError(e) {
|
|
|
924
714
|
return FileErrorCodes[t];
|
|
925
715
|
}
|
|
926
716
|
function rethrowFileSystemError(e = "") {
|
|
927
|
-
return function(r, s,
|
|
928
|
-
const
|
|
929
|
-
|
|
717
|
+
return function(r, s, i) {
|
|
718
|
+
const n = i.value;
|
|
719
|
+
i.value = function(...o) {
|
|
930
720
|
try {
|
|
931
|
-
return
|
|
721
|
+
return n.apply(this, o);
|
|
932
722
|
} catch (a) {
|
|
933
|
-
const
|
|
934
|
-
if (
|
|
935
|
-
const
|
|
936
|
-
throw new Error(`${g}: ${
|
|
723
|
+
const l = typeof a == "object" ? a == null ? void 0 : a.errno : null;
|
|
724
|
+
if (l in FileErrorCodes) {
|
|
725
|
+
const c = FileErrorCodes[l], d = typeof o[0] == "string" ? o[0] : null, g = d !== null ? e.replaceAll("{path}", d) : e;
|
|
726
|
+
throw new Error(`${g}: ${c}`, {
|
|
937
727
|
cause: a
|
|
938
728
|
});
|
|
939
729
|
}
|
|
@@ -951,9 +741,9 @@ function getLoadedRuntime(e) {
|
|
|
951
741
|
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";
|
|
952
742
|
})();
|
|
953
743
|
var __defProp = Object.defineProperty, __getOwnPropDesc = Object.getOwnPropertyDescriptor, __decorateClass = (e, t, r, s) => {
|
|
954
|
-
for (var
|
|
955
|
-
(o = e[
|
|
956
|
-
return s &&
|
|
744
|
+
for (var i = s > 1 ? void 0 : s ? __getOwnPropDesc(t, r) : t, n = e.length - 1, o; n >= 0; n--)
|
|
745
|
+
(o = e[n]) && (i = (s ? o(t, r, i) : o(i)) || i);
|
|
746
|
+
return s && i && __defProp(t, r, i), i;
|
|
957
747
|
};
|
|
958
748
|
const STRING = "string", NUMBER = "number", __private__dont__use = Symbol("__private__dont__use");
|
|
959
749
|
class PHPExecutionFailureError extends Error {
|
|
@@ -961,16 +751,16 @@ class PHPExecutionFailureError extends Error {
|
|
|
961
751
|
super(t), this.response = r, this.source = s;
|
|
962
752
|
}
|
|
963
753
|
}
|
|
964
|
-
var
|
|
754
|
+
var E, w, v, _, y, m, P, b, $, S, U, R, q, T, W, F, z, C, j, x, G, k, J, I, Q, N, V, A, Y, M, Z, O, K, H, X, B, ee;
|
|
965
755
|
class BasePHP {
|
|
966
756
|
/**
|
|
967
757
|
* Initializes a PHP runtime.
|
|
968
758
|
*
|
|
969
759
|
* @internal
|
|
970
760
|
* @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
|
|
971
|
-
* @param
|
|
761
|
+
* @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
972
762
|
*/
|
|
973
|
-
constructor(e
|
|
763
|
+
constructor(e) {
|
|
974
764
|
/**
|
|
975
765
|
* Prepares the $_SERVER entries for the PHP runtime.
|
|
976
766
|
*
|
|
@@ -980,46 +770,46 @@ class BasePHP {
|
|
|
980
770
|
* was provided.
|
|
981
771
|
* @returns Computed $_SERVER entries.
|
|
982
772
|
*/
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
773
|
+
u(this, b);
|
|
774
|
+
u(this, S);
|
|
775
|
+
u(this, R);
|
|
776
|
+
u(this, T);
|
|
777
|
+
u(this, F);
|
|
778
|
+
u(this, C);
|
|
779
|
+
u(this, x);
|
|
780
|
+
u(this, k);
|
|
781
|
+
u(this, I);
|
|
782
|
+
u(this, N);
|
|
783
|
+
u(this, A);
|
|
784
|
+
u(this, M);
|
|
785
|
+
u(this, O);
|
|
786
|
+
u(this, H);
|
|
787
|
+
u(this, B);
|
|
788
|
+
u(this, E, void 0);
|
|
789
|
+
u(this, w, void 0);
|
|
790
|
+
u(this, v, void 0);
|
|
791
|
+
u(this, _, void 0);
|
|
792
|
+
u(this, y, void 0);
|
|
793
|
+
u(this, m, void 0);
|
|
794
|
+
u(this, P, void 0);
|
|
795
|
+
f(this, E, []), f(this, _, !1), f(this, y, null), f(this, m, /* @__PURE__ */ new Map()), f(this, P, []), this.semaphore = new Semaphore({ concurrency: 1 }), e !== void 0 && this.initializeRuntime(e);
|
|
1006
796
|
}
|
|
1007
797
|
addEventListener(e, t) {
|
|
1008
|
-
|
|
798
|
+
h(this, m).has(e) || h(this, m).set(e, /* @__PURE__ */ new Set()), h(this, m).get(e).add(t);
|
|
1009
799
|
}
|
|
1010
800
|
removeEventListener(e, t) {
|
|
1011
801
|
var r;
|
|
1012
|
-
(r =
|
|
802
|
+
(r = h(this, m).get(e)) == null || r.delete(t);
|
|
1013
803
|
}
|
|
1014
804
|
dispatchEvent(e) {
|
|
1015
|
-
const t =
|
|
805
|
+
const t = h(this, m).get(e.type);
|
|
1016
806
|
if (t)
|
|
1017
807
|
for (const r of t)
|
|
1018
808
|
r(e);
|
|
1019
809
|
}
|
|
1020
810
|
/** @inheritDoc */
|
|
1021
811
|
async onMessage(e) {
|
|
1022
|
-
|
|
812
|
+
h(this, P).push(e);
|
|
1023
813
|
}
|
|
1024
814
|
/** @inheritDoc */
|
|
1025
815
|
async setSpawnHandler(handler) {
|
|
@@ -1048,13 +838,13 @@ class BasePHP {
|
|
|
1048
838
|
if (!t)
|
|
1049
839
|
throw new Error("Invalid PHP runtime id.");
|
|
1050
840
|
this[__private__dont__use] = t, t.onMessage = async (r) => {
|
|
1051
|
-
for (const s of
|
|
1052
|
-
const
|
|
1053
|
-
if (
|
|
1054
|
-
return
|
|
841
|
+
for (const s of h(this, P)) {
|
|
842
|
+
const i = await s(r);
|
|
843
|
+
if (i)
|
|
844
|
+
return i;
|
|
1055
845
|
}
|
|
1056
846
|
return "";
|
|
1057
|
-
},
|
|
847
|
+
}, f(this, y, improveWASMErrorReporting(t)), this.dispatchEvent({
|
|
1058
848
|
type: "runtime.initialized"
|
|
1059
849
|
});
|
|
1060
850
|
}
|
|
@@ -1069,13 +859,13 @@ class BasePHP {
|
|
|
1069
859
|
throw new Error(
|
|
1070
860
|
"Could not set SAPI name. This can only be done before the PHP WASM module is initialized.Did you already dispatch any requests?"
|
|
1071
861
|
);
|
|
1072
|
-
|
|
862
|
+
f(this, v, e);
|
|
1073
863
|
}
|
|
1074
864
|
/** @inheritDoc */
|
|
1075
865
|
setPhpIniPath(e) {
|
|
1076
|
-
if (
|
|
866
|
+
if (h(this, _))
|
|
1077
867
|
throw new Error("Cannot set PHP ini path after calling run().");
|
|
1078
|
-
|
|
868
|
+
f(this, w, e), this[__private__dont__use].ccall(
|
|
1079
869
|
"wasm_set_phpini_path",
|
|
1080
870
|
null,
|
|
1081
871
|
["string"],
|
|
@@ -1084,17 +874,22 @@ class BasePHP {
|
|
|
1084
874
|
}
|
|
1085
875
|
/** @inheritDoc */
|
|
1086
876
|
setPhpIniEntry(e, t) {
|
|
1087
|
-
if (
|
|
877
|
+
if (h(this, _))
|
|
1088
878
|
throw new Error("Cannot set PHP ini entries after calling run().");
|
|
1089
|
-
|
|
879
|
+
h(this, E).push([e, t]);
|
|
1090
880
|
}
|
|
1091
881
|
/** @inheritDoc */
|
|
1092
882
|
chdir(e) {
|
|
1093
883
|
this[__private__dont__use].FS.chdir(e);
|
|
1094
884
|
}
|
|
1095
|
-
/**
|
|
885
|
+
/**
|
|
886
|
+
* Do not use. Use new PHPRequestHandler() instead.
|
|
887
|
+
* @deprecated
|
|
888
|
+
*/
|
|
1096
889
|
async request(e) {
|
|
1097
|
-
if (
|
|
890
|
+
if (logger.warn(
|
|
891
|
+
"PHP.request() is deprecated. Please use new PHPRequestHandler() instead."
|
|
892
|
+
), !this.requestHandler)
|
|
1098
893
|
throw new Error("No request handler available.");
|
|
1099
894
|
return this.requestHandler.request(e);
|
|
1100
895
|
}
|
|
@@ -1103,30 +898,30 @@ class BasePHP {
|
|
|
1103
898
|
const t = await this.semaphore.acquire();
|
|
1104
899
|
let r;
|
|
1105
900
|
try {
|
|
1106
|
-
if (
|
|
901
|
+
if (h(this, _) || (p(this, S, U).call(this), f(this, _, !0)), e.scriptPath && !this.fileExists(e.scriptPath))
|
|
1107
902
|
throw new Error(
|
|
1108
903
|
`The script path "${e.scriptPath}" does not exist.`
|
|
1109
904
|
);
|
|
1110
|
-
|
|
1111
|
-
const s = normalizeHeaders(e.headers || {}),
|
|
1112
|
-
|
|
1113
|
-
const o =
|
|
1114
|
-
for (const
|
|
1115
|
-
|
|
905
|
+
p(this, A, Y).call(this, e.scriptPath || ""), p(this, T, W).call(this, e.relativeUri || ""), p(this, k, J).call(this, e.method || "GET");
|
|
906
|
+
const s = normalizeHeaders(e.headers || {}), i = s.host || "example.com:443", n = p(this, x, G).call(this, i, e.protocol || "http");
|
|
907
|
+
p(this, F, z).call(this, i), p(this, C, j).call(this, n), p(this, I, Q).call(this, s), e.body && (r = p(this, N, V).call(this, e.body)), typeof e.code == "string" && p(this, H, X).call(this, " ?>" + e.code);
|
|
908
|
+
const o = p(this, b, $).call(this, e.$_SERVER, s, n);
|
|
909
|
+
for (const c in o)
|
|
910
|
+
p(this, M, Z).call(this, c, o[c]);
|
|
1116
911
|
const a = e.env || {};
|
|
1117
|
-
for (const
|
|
1118
|
-
|
|
1119
|
-
const
|
|
1120
|
-
if (
|
|
1121
|
-
|
|
1122
|
-
const
|
|
1123
|
-
`PHP.run() failed with exit code ${
|
|
1124
|
-
|
|
912
|
+
for (const c in a)
|
|
913
|
+
p(this, O, K).call(this, c, a[c]);
|
|
914
|
+
const l = await p(this, B, ee).call(this);
|
|
915
|
+
if (l.exitCode !== 0) {
|
|
916
|
+
logger.warn("PHP.run() output was:", l.text);
|
|
917
|
+
const c = new PHPExecutionFailureError(
|
|
918
|
+
`PHP.run() failed with exit code ${l.exitCode} and the following output: ` + l.errors,
|
|
919
|
+
l,
|
|
1125
920
|
"request"
|
|
1126
921
|
);
|
|
1127
|
-
throw
|
|
922
|
+
throw logger.error(c), c;
|
|
1128
923
|
}
|
|
1129
|
-
return
|
|
924
|
+
return l;
|
|
1130
925
|
} catch (s) {
|
|
1131
926
|
throw this.dispatchEvent({
|
|
1132
927
|
type: "request.error",
|
|
@@ -1207,11 +1002,11 @@ class BasePHP {
|
|
|
1207
1002
|
);
|
|
1208
1003
|
if (t.prependPath) {
|
|
1209
1004
|
const s = e.replace(/\/$/, "");
|
|
1210
|
-
return r.map((
|
|
1005
|
+
return r.map((i) => `${s}/${i}`);
|
|
1211
1006
|
}
|
|
1212
1007
|
return r;
|
|
1213
1008
|
} catch (r) {
|
|
1214
|
-
return
|
|
1009
|
+
return logger.error(r, { path: e }), [];
|
|
1215
1010
|
}
|
|
1216
1011
|
}
|
|
1217
1012
|
isDir(e) {
|
|
@@ -1242,7 +1037,7 @@ class BasePHP {
|
|
|
1242
1037
|
this.exit();
|
|
1243
1038
|
} catch {
|
|
1244
1039
|
}
|
|
1245
|
-
this.initializeRuntime(e),
|
|
1040
|
+
this.initializeRuntime(e), h(this, w) && this.setPhpIniPath(h(this, w)), h(this, v) && this.setSapiName(h(this, v)), t && copyFS(r, this[__private__dont__use].FS, t);
|
|
1246
1041
|
}
|
|
1247
1042
|
exit(e = 0) {
|
|
1248
1043
|
this.dispatchEvent({
|
|
@@ -1252,20 +1047,23 @@ class BasePHP {
|
|
|
1252
1047
|
this[__private__dont__use]._exit(e);
|
|
1253
1048
|
} catch {
|
|
1254
1049
|
}
|
|
1255
|
-
|
|
1050
|
+
f(this, _, !1), f(this, y, null), delete this[__private__dont__use].onMessage, delete this[__private__dont__use];
|
|
1051
|
+
}
|
|
1052
|
+
[Symbol.dispose]() {
|
|
1053
|
+
h(this, _) && this.exit(0);
|
|
1256
1054
|
}
|
|
1257
1055
|
}
|
|
1258
|
-
|
|
1056
|
+
E = new WeakMap(), w = new WeakMap(), v = new WeakMap(), _ = new WeakMap(), y = new WeakMap(), m = new WeakMap(), P = new WeakMap(), b = new WeakSet(), $ = function(e, t, r) {
|
|
1259
1057
|
const s = {
|
|
1260
1058
|
...e || {}
|
|
1261
1059
|
};
|
|
1262
1060
|
s.HTTPS = s.HTTPS || r === 443 ? "on" : "off";
|
|
1263
|
-
for (const
|
|
1264
|
-
let
|
|
1265
|
-
["content-type", "content-length"].includes(
|
|
1061
|
+
for (const i in t) {
|
|
1062
|
+
let n = "HTTP_";
|
|
1063
|
+
["content-type", "content-length"].includes(i.toLowerCase()) && (n = ""), s[`${n}${i.toUpperCase().replace(/-/g, "_")}`] = t[i];
|
|
1266
1064
|
}
|
|
1267
1065
|
return s;
|
|
1268
|
-
},
|
|
1066
|
+
}, S = new WeakSet(), U = function() {
|
|
1269
1067
|
if (this.setPhpIniEntry("auto_prepend_file", "/internal/consts.php"), this.fileExists("/internal/consts.php") || this.writeFile(
|
|
1270
1068
|
"/internal/consts.php",
|
|
1271
1069
|
`<?php
|
|
@@ -1277,8 +1075,8 @@ R = new WeakMap(), x = new WeakMap(), k = new WeakMap(), y = new WeakMap(), w =
|
|
|
1277
1075
|
}
|
|
1278
1076
|
}
|
|
1279
1077
|
}`
|
|
1280
|
-
),
|
|
1281
|
-
const e =
|
|
1078
|
+
), h(this, E).length > 0) {
|
|
1079
|
+
const e = h(this, E).map(([t, r]) => `${t}=${r}`).join(`
|
|
1282
1080
|
`) + `
|
|
1283
1081
|
|
|
1284
1082
|
`;
|
|
@@ -1290,7 +1088,7 @@ R = new WeakMap(), x = new WeakMap(), k = new WeakMap(), y = new WeakMap(), w =
|
|
|
1290
1088
|
);
|
|
1291
1089
|
}
|
|
1292
1090
|
this[__private__dont__use].ccall("php_wasm_init", null, [], []);
|
|
1293
|
-
},
|
|
1091
|
+
}, R = new WeakSet(), q = function() {
|
|
1294
1092
|
const e = "/internal/headers.json";
|
|
1295
1093
|
if (!this.fileExists(e))
|
|
1296
1094
|
throw new Error(
|
|
@@ -1300,14 +1098,14 @@ R = new WeakMap(), x = new WeakMap(), k = new WeakMap(), y = new WeakMap(), w =
|
|
|
1300
1098
|
for (const s of t.headers) {
|
|
1301
1099
|
if (!s.includes(": "))
|
|
1302
1100
|
continue;
|
|
1303
|
-
const
|
|
1304
|
-
|
|
1101
|
+
const i = s.indexOf(": "), n = s.substring(0, i).toLowerCase(), o = s.substring(i + 2);
|
|
1102
|
+
n in r || (r[n] = []), r[n].push(o);
|
|
1305
1103
|
}
|
|
1306
1104
|
return {
|
|
1307
1105
|
headers: r,
|
|
1308
1106
|
httpStatusCode: t.status
|
|
1309
1107
|
};
|
|
1310
|
-
},
|
|
1108
|
+
}, T = new WeakSet(), W = function(e) {
|
|
1311
1109
|
if (this[__private__dont__use].ccall(
|
|
1312
1110
|
"wasm_set_request_uri",
|
|
1313
1111
|
null,
|
|
@@ -1322,35 +1120,35 @@ R = new WeakMap(), x = new WeakMap(), k = new WeakMap(), y = new WeakMap(), w =
|
|
|
1322
1120
|
[t]
|
|
1323
1121
|
);
|
|
1324
1122
|
}
|
|
1325
|
-
},
|
|
1123
|
+
}, F = new WeakSet(), z = function(e) {
|
|
1326
1124
|
this[__private__dont__use].ccall(
|
|
1327
1125
|
"wasm_set_request_host",
|
|
1328
1126
|
null,
|
|
1329
1127
|
[STRING],
|
|
1330
1128
|
[e]
|
|
1331
1129
|
);
|
|
1332
|
-
},
|
|
1130
|
+
}, C = new WeakSet(), j = function(e) {
|
|
1333
1131
|
this[__private__dont__use].ccall(
|
|
1334
1132
|
"wasm_set_request_port",
|
|
1335
1133
|
null,
|
|
1336
1134
|
[NUMBER],
|
|
1337
1135
|
[e]
|
|
1338
1136
|
);
|
|
1339
|
-
},
|
|
1137
|
+
}, x = new WeakSet(), G = function(e, t) {
|
|
1340
1138
|
let r;
|
|
1341
1139
|
try {
|
|
1342
1140
|
r = parseInt(new URL(e).port, 10);
|
|
1343
1141
|
} catch {
|
|
1344
1142
|
}
|
|
1345
1143
|
return (!r || isNaN(r) || r === 80) && (r = t === "https" ? 443 : 80), r;
|
|
1346
|
-
},
|
|
1144
|
+
}, k = new WeakSet(), J = function(e) {
|
|
1347
1145
|
this[__private__dont__use].ccall(
|
|
1348
1146
|
"wasm_set_request_method",
|
|
1349
1147
|
null,
|
|
1350
1148
|
[STRING],
|
|
1351
1149
|
[e]
|
|
1352
1150
|
);
|
|
1353
|
-
},
|
|
1151
|
+
}, I = new WeakSet(), Q = function(e) {
|
|
1354
1152
|
e.cookie && this[__private__dont__use].ccall(
|
|
1355
1153
|
"wasm_set_cookies",
|
|
1356
1154
|
null,
|
|
@@ -1367,9 +1165,9 @@ R = new WeakMap(), x = new WeakMap(), k = new WeakMap(), y = new WeakMap(), w =
|
|
|
1367
1165
|
[NUMBER],
|
|
1368
1166
|
[parseInt(e["content-length"], 10)]
|
|
1369
1167
|
);
|
|
1370
|
-
},
|
|
1168
|
+
}, N = new WeakSet(), V = function(e) {
|
|
1371
1169
|
let t, r;
|
|
1372
|
-
typeof e == "string" ? (
|
|
1170
|
+
typeof e == "string" ? (logger.warn(
|
|
1373
1171
|
"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"
|
|
1374
1172
|
), r = this[__private__dont__use].lengthBytesUTF8(e), t = r + 1) : (r = e.byteLength, t = e.byteLength);
|
|
1375
1173
|
const s = this[__private__dont__use].malloc(t);
|
|
@@ -1390,45 +1188,45 @@ R = new WeakMap(), x = new WeakMap(), k = new WeakMap(), y = new WeakMap(), w =
|
|
|
1390
1188
|
[NUMBER],
|
|
1391
1189
|
[r]
|
|
1392
1190
|
), s;
|
|
1393
|
-
},
|
|
1191
|
+
}, A = new WeakSet(), Y = function(e) {
|
|
1394
1192
|
this[__private__dont__use].ccall(
|
|
1395
1193
|
"wasm_set_path_translated",
|
|
1396
1194
|
null,
|
|
1397
1195
|
[STRING],
|
|
1398
1196
|
[e]
|
|
1399
1197
|
);
|
|
1400
|
-
},
|
|
1198
|
+
}, M = new WeakSet(), Z = function(e, t) {
|
|
1401
1199
|
this[__private__dont__use].ccall(
|
|
1402
1200
|
"wasm_add_SERVER_entry",
|
|
1403
1201
|
null,
|
|
1404
1202
|
[STRING, STRING],
|
|
1405
1203
|
[e, t]
|
|
1406
1204
|
);
|
|
1407
|
-
},
|
|
1205
|
+
}, O = new WeakSet(), K = function(e, t) {
|
|
1408
1206
|
this[__private__dont__use].ccall(
|
|
1409
1207
|
"wasm_add_ENV_entry",
|
|
1410
1208
|
null,
|
|
1411
1209
|
[STRING, STRING],
|
|
1412
1210
|
[e, t]
|
|
1413
1211
|
);
|
|
1414
|
-
},
|
|
1212
|
+
}, H = new WeakSet(), X = function(e) {
|
|
1415
1213
|
this[__private__dont__use].ccall(
|
|
1416
1214
|
"wasm_set_php_code",
|
|
1417
1215
|
null,
|
|
1418
1216
|
[STRING],
|
|
1419
1217
|
[e]
|
|
1420
1218
|
);
|
|
1421
|
-
},
|
|
1422
|
-
var
|
|
1219
|
+
}, B = new WeakSet(), ee = async function() {
|
|
1220
|
+
var i;
|
|
1423
1221
|
let e, t;
|
|
1424
1222
|
try {
|
|
1425
|
-
e = await new Promise((
|
|
1426
|
-
var
|
|
1427
|
-
t = (
|
|
1428
|
-
|
|
1429
|
-
const
|
|
1430
|
-
|
|
1431
|
-
}, (
|
|
1223
|
+
e = await new Promise((n, o) => {
|
|
1224
|
+
var l;
|
|
1225
|
+
t = (c) => {
|
|
1226
|
+
logger.error(c), logger.error(c.error);
|
|
1227
|
+
const d = new Error("Rethrown");
|
|
1228
|
+
d.cause = c.error, d.betterMessage = c.message, o(d);
|
|
1229
|
+
}, (l = h(this, y)) == null || l.addEventListener(
|
|
1432
1230
|
"error",
|
|
1433
1231
|
t
|
|
1434
1232
|
);
|
|
@@ -1439,22 +1237,22 @@ R = new WeakMap(), x = new WeakMap(), k = new WeakMap(), y = new WeakMap(), w =
|
|
|
1439
1237
|
[],
|
|
1440
1238
|
{ async: !0 }
|
|
1441
1239
|
);
|
|
1442
|
-
return a instanceof Promise ? a.then(
|
|
1240
|
+
return a instanceof Promise ? a.then(n, o) : n(a);
|
|
1443
1241
|
});
|
|
1444
|
-
} catch (
|
|
1445
|
-
for (const
|
|
1446
|
-
typeof this[
|
|
1242
|
+
} catch (n) {
|
|
1243
|
+
for (const c in this)
|
|
1244
|
+
typeof this[c] == "function" && (this[c] = () => {
|
|
1447
1245
|
throw new Error(
|
|
1448
1246
|
"PHP runtime has crashed – see the earlier error for details."
|
|
1449
1247
|
);
|
|
1450
1248
|
});
|
|
1451
1249
|
this.functionsMaybeMissingFromAsyncify = getFunctionsMaybeMissingFromAsyncify();
|
|
1452
|
-
const o =
|
|
1453
|
-
throw
|
|
1250
|
+
const o = n, a = "betterMessage" in o ? o.betterMessage : o.message, l = new Error(a);
|
|
1251
|
+
throw l.cause = o, logger.error(l), l;
|
|
1454
1252
|
} finally {
|
|
1455
|
-
(
|
|
1253
|
+
(i = h(this, y)) == null || i.removeEventListener("error", t);
|
|
1456
1254
|
}
|
|
1457
|
-
const { headers: r, httpStatusCode: s } =
|
|
1255
|
+
const { headers: r, httpStatusCode: s } = p(this, R, q).call(this);
|
|
1458
1256
|
return new PHPResponse(
|
|
1459
1257
|
e === 0 ? s : 500,
|
|
1460
1258
|
r,
|
|
@@ -1513,48 +1311,48 @@ function copyFS(e, t, r) {
|
|
|
1513
1311
|
return;
|
|
1514
1312
|
}
|
|
1515
1313
|
t.mkdirTree(r);
|
|
1516
|
-
const
|
|
1517
|
-
for (const
|
|
1518
|
-
copyFS(e, t, joinPaths(r,
|
|
1314
|
+
const i = e.readdir(r).filter((n) => n !== "." && n !== "..");
|
|
1315
|
+
for (const n of i)
|
|
1316
|
+
copyFS(e, t, joinPaths(r, n));
|
|
1519
1317
|
}
|
|
1520
1318
|
function journalFSEvents(e, t, r = () => {
|
|
1521
1319
|
}) {
|
|
1522
1320
|
function s() {
|
|
1523
1321
|
t = normalizePath(t);
|
|
1524
|
-
const
|
|
1525
|
-
if (
|
|
1526
|
-
r(
|
|
1527
|
-
else if (
|
|
1322
|
+
const n = e[__private__dont__use].FS, o = createFSHooks(n, (d) => {
|
|
1323
|
+
if (d.path.startsWith(t))
|
|
1324
|
+
r(d);
|
|
1325
|
+
else if (d.operation === "RENAME" && d.toPath.startsWith(t))
|
|
1528
1326
|
for (const g of recordExistingPath(
|
|
1529
1327
|
e,
|
|
1530
|
-
|
|
1531
|
-
|
|
1328
|
+
d.path,
|
|
1329
|
+
d.toPath
|
|
1532
1330
|
))
|
|
1533
1331
|
r(g);
|
|
1534
1332
|
}), a = {};
|
|
1535
|
-
for (const [
|
|
1536
|
-
a[
|
|
1537
|
-
function
|
|
1538
|
-
for (const [
|
|
1539
|
-
|
|
1540
|
-
return g(...
|
|
1333
|
+
for (const [d] of Object.entries(o))
|
|
1334
|
+
a[d] = n[d];
|
|
1335
|
+
function l() {
|
|
1336
|
+
for (const [d, g] of Object.entries(o))
|
|
1337
|
+
n[d] = function(...L) {
|
|
1338
|
+
return g(...L), a[d].apply(this, L);
|
|
1541
1339
|
};
|
|
1542
1340
|
}
|
|
1543
|
-
function
|
|
1544
|
-
for (const [
|
|
1545
|
-
e[__private__dont__use].FS[
|
|
1341
|
+
function c() {
|
|
1342
|
+
for (const [d, g] of Object.entries(a))
|
|
1343
|
+
e[__private__dont__use].FS[d] = g;
|
|
1546
1344
|
}
|
|
1547
1345
|
e[__private__dont__use].journal = {
|
|
1548
|
-
bind:
|
|
1549
|
-
unbind:
|
|
1550
|
-
},
|
|
1346
|
+
bind: l,
|
|
1347
|
+
unbind: c
|
|
1348
|
+
}, l();
|
|
1551
1349
|
}
|
|
1552
1350
|
e.addEventListener("runtime.initialized", s), e[__private__dont__use] && s();
|
|
1553
|
-
function
|
|
1351
|
+
function i() {
|
|
1554
1352
|
e[__private__dont__use].journal.unbind(), delete e[__private__dont__use].journal;
|
|
1555
1353
|
}
|
|
1556
|
-
return e.addEventListener("runtime.beforedestroy",
|
|
1557
|
-
return e.removeEventListener("runtime.initialized", s), e.removeEventListener("runtime.beforedestroy",
|
|
1354
|
+
return e.addEventListener("runtime.beforedestroy", i), function() {
|
|
1355
|
+
return e.removeEventListener("runtime.initialized", s), e.removeEventListener("runtime.beforedestroy", i), e[__private__dont__use].journal.unbind();
|
|
1558
1356
|
};
|
|
1559
1357
|
}
|
|
1560
1358
|
const createFSHooks = (e, t = () => {
|
|
@@ -1606,16 +1404,16 @@ const createFSHooks = (e, t = () => {
|
|
|
1606
1404
|
},
|
|
1607
1405
|
rename(r, s) {
|
|
1608
1406
|
try {
|
|
1609
|
-
const
|
|
1407
|
+
const i = e.lookupPath(r, {
|
|
1610
1408
|
follow: !0
|
|
1611
|
-
}),
|
|
1409
|
+
}), n = e.lookupPath(s, {
|
|
1612
1410
|
parent: !0
|
|
1613
1411
|
}).path;
|
|
1614
1412
|
t({
|
|
1615
1413
|
operation: "RENAME",
|
|
1616
|
-
nodeType: e.isDir(
|
|
1617
|
-
path:
|
|
1618
|
-
toPath: joinPaths(
|
|
1414
|
+
nodeType: e.isDir(i.node.mode) ? "directory" : "file",
|
|
1415
|
+
path: i.path,
|
|
1416
|
+
toPath: joinPaths(n, basename(s))
|
|
1619
1417
|
});
|
|
1620
1418
|
} catch {
|
|
1621
1419
|
}
|
|
@@ -1661,52 +1459,52 @@ function normalizeFilesystemOperations(e) {
|
|
|
1661
1459
|
const t = {};
|
|
1662
1460
|
for (let r = e.length - 1; r >= 0; r--) {
|
|
1663
1461
|
for (let s = r - 1; s >= 0; s--) {
|
|
1664
|
-
const
|
|
1665
|
-
if (
|
|
1462
|
+
const i = checkRelationship(e[r], e[s]);
|
|
1463
|
+
if (i === "none")
|
|
1666
1464
|
continue;
|
|
1667
|
-
const
|
|
1668
|
-
if (
|
|
1669
|
-
|
|
1465
|
+
const n = e[r], o = e[s];
|
|
1466
|
+
if (n.operation === "RENAME" && o.operation === "RENAME") {
|
|
1467
|
+
logger.warn(
|
|
1670
1468
|
"[FS Journal] Normalizing a double rename is not yet supported:",
|
|
1671
1469
|
{
|
|
1672
|
-
current:
|
|
1470
|
+
current: n,
|
|
1673
1471
|
last: o
|
|
1674
1472
|
}
|
|
1675
1473
|
);
|
|
1676
1474
|
continue;
|
|
1677
1475
|
}
|
|
1678
|
-
(o.operation === "CREATE" || o.operation === "WRITE") && (
|
|
1476
|
+
(o.operation === "CREATE" || o.operation === "WRITE") && (n.operation === "RENAME" ? i === "same_node" ? (t[s] = [], t[r] = [
|
|
1679
1477
|
{
|
|
1680
1478
|
...o,
|
|
1681
|
-
path:
|
|
1479
|
+
path: n.toPath
|
|
1682
1480
|
},
|
|
1683
1481
|
...t[r] || []
|
|
1684
|
-
]) :
|
|
1482
|
+
]) : i === "descendant" && (t[s] = [], t[r] = [
|
|
1685
1483
|
{
|
|
1686
1484
|
...o,
|
|
1687
1485
|
path: joinPaths(
|
|
1688
|
-
|
|
1689
|
-
o.path.substring(
|
|
1486
|
+
n.toPath,
|
|
1487
|
+
o.path.substring(n.path.length)
|
|
1690
1488
|
)
|
|
1691
1489
|
},
|
|
1692
1490
|
...t[r] || []
|
|
1693
|
-
]) :
|
|
1491
|
+
]) : n.operation === "WRITE" && i === "same_node" ? t[s] = [] : n.operation === "DELETE" && i === "same_node" && (t[s] = [], t[r] = []));
|
|
1694
1492
|
}
|
|
1695
1493
|
if (Object.entries(t).length > 0) {
|
|
1696
|
-
const s = e.flatMap((
|
|
1494
|
+
const s = e.flatMap((i, n) => n in t ? t[n] : [i]);
|
|
1697
1495
|
return normalizeFilesystemOperations(s);
|
|
1698
1496
|
}
|
|
1699
1497
|
}
|
|
1700
1498
|
return e;
|
|
1701
1499
|
}
|
|
1702
1500
|
function checkRelationship(e, t) {
|
|
1703
|
-
const r = e.path, s = e.operation !== "WRITE" && e.nodeType === "directory",
|
|
1704
|
-
return
|
|
1501
|
+
const r = e.path, s = e.operation !== "WRITE" && e.nodeType === "directory", i = t.operation !== "WRITE" && t.nodeType === "directory", n = t.operation === "RENAME" ? t.toPath : t.path;
|
|
1502
|
+
return n === r ? "same_node" : i && r.startsWith(n + "/") ? "ancestor" : s && n.startsWith(r + "/") ? "descendant" : "none";
|
|
1705
1503
|
}
|
|
1706
1504
|
async function hydrateUpdateFileOps(e, t) {
|
|
1707
1505
|
const s = t.filter(
|
|
1708
|
-
(
|
|
1709
|
-
).map((
|
|
1506
|
+
(i) => i.operation === "WRITE"
|
|
1507
|
+
).map((i) => hydrateOp(e, i));
|
|
1710
1508
|
return await Promise.all(s), t;
|
|
1711
1509
|
}
|
|
1712
1510
|
const hydrateLock = new Semaphore({ concurrency: 15 });
|
|
@@ -1715,9 +1513,9 @@ async function hydrateOp(e, t) {
|
|
|
1715
1513
|
try {
|
|
1716
1514
|
t.data = await e.readFileAsBuffer(t.path);
|
|
1717
1515
|
} catch (s) {
|
|
1718
|
-
|
|
1516
|
+
logger.warn(
|
|
1719
1517
|
`Journal failed to hydrate a file on flush: the path ${t.path} no longer exists`
|
|
1720
|
-
),
|
|
1518
|
+
), logger.error(s);
|
|
1721
1519
|
}
|
|
1722
1520
|
r();
|
|
1723
1521
|
}
|