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