@wp-playground/client 0.7.19 → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.cjs +150 -162
- package/index.d.ts +873 -643
- package/index.js +3609 -4093
- package/package.json +2 -2
package/index.d.ts
CHANGED
|
@@ -195,478 +195,427 @@ export declare class PHPResponse implements PHPResponseData {
|
|
|
195
195
|
*/
|
|
196
196
|
get text(): string;
|
|
197
197
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
*/
|
|
201
|
-
export
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
export
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
type
|
|
198
|
+
export type RuntimeType = "NODE" | "WEB" | "WORKER";
|
|
199
|
+
export type PHPRuntimeId = number;
|
|
200
|
+
/** Other WebAssembly declarations, for compatibility with older versions of Typescript */
|
|
201
|
+
export declare namespace Emscripten {
|
|
202
|
+
export interface RootFS extends Emscripten.FileSystemInstance {
|
|
203
|
+
filesystems: Record<string, Emscripten.FileSystemType>;
|
|
204
|
+
}
|
|
205
|
+
export interface FileSystemType {
|
|
206
|
+
mount(mount: FS.Mount): FS.FSNode;
|
|
207
|
+
syncfs(mount: FS.Mount, populate: () => unknown, done: (err?: number | null) => unknown): void;
|
|
208
|
+
}
|
|
209
|
+
export type EnvironmentType = "WEB" | "NODE" | "SHELL" | "WORKER";
|
|
210
|
+
export type JSType = "number" | "string" | "array" | "boolean";
|
|
211
|
+
export type TypeCompatibleWithC = number | string | any[] | boolean;
|
|
212
|
+
export type CIntType = "i8" | "i16" | "i32" | "i64";
|
|
213
|
+
export type CFloatType = "float" | "double";
|
|
214
|
+
export type CPointerType = "i8*" | "i16*" | "i32*" | "i64*" | "float*" | "double*" | "*";
|
|
215
|
+
export type CType = CIntType | CFloatType | CPointerType;
|
|
216
|
+
export interface CCallOpts {
|
|
217
|
+
async?: boolean | undefined;
|
|
218
|
+
}
|
|
219
|
+
type NamespaceToInstance<T> = {
|
|
220
|
+
[K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : never;
|
|
221
|
+
};
|
|
222
|
+
export type FileSystemInstance = NamespaceToInstance<typeof FS> & {
|
|
223
|
+
mkdirTree(path: string): void;
|
|
224
|
+
lookupPath(path: string, opts?: any): FS.Lookup;
|
|
225
|
+
};
|
|
226
|
+
export interface EmscriptenModule {
|
|
227
|
+
print(str: string): void;
|
|
228
|
+
printErr(str: string): void;
|
|
229
|
+
arguments: string[];
|
|
230
|
+
environment: Emscripten.EnvironmentType;
|
|
231
|
+
preInit: Array<{
|
|
232
|
+
(): void;
|
|
233
|
+
}>;
|
|
234
|
+
preRun: Array<{
|
|
235
|
+
(): void;
|
|
236
|
+
}>;
|
|
237
|
+
postRun: Array<{
|
|
238
|
+
(): void;
|
|
239
|
+
}>;
|
|
240
|
+
onAbort: {
|
|
241
|
+
(what: any): void;
|
|
242
|
+
};
|
|
243
|
+
onRuntimeInitialized: {
|
|
244
|
+
(): void;
|
|
245
|
+
};
|
|
246
|
+
preinitializedWebGLContext: WebGLRenderingContext;
|
|
247
|
+
noInitialRun: boolean;
|
|
248
|
+
noExitRuntime: boolean;
|
|
249
|
+
logReadFiles: boolean;
|
|
250
|
+
filePackagePrefixURL: string;
|
|
251
|
+
wasmBinary: ArrayBuffer;
|
|
252
|
+
destroy(object: object): void;
|
|
253
|
+
getPreloadedPackage(remotePackageName: string, remotePackageSize: number): ArrayBuffer;
|
|
254
|
+
instantiateWasm(imports: WebAssembly.Imports, successCallback: (module: WebAssembly.Instance) => void): WebAssembly.Exports | undefined;
|
|
255
|
+
locateFile(url: string, scriptDirectory: string): string;
|
|
256
|
+
onCustomMessage(event: MessageEvent): void;
|
|
257
|
+
HEAP: Int32Array;
|
|
258
|
+
IHEAP: Int32Array;
|
|
259
|
+
FHEAP: Float64Array;
|
|
260
|
+
HEAP8: Int8Array;
|
|
261
|
+
HEAP16: Int16Array;
|
|
262
|
+
HEAP32: Int32Array;
|
|
263
|
+
HEAPU8: Uint8Array;
|
|
264
|
+
HEAPU16: Uint16Array;
|
|
265
|
+
HEAPU32: Uint32Array;
|
|
266
|
+
HEAPF32: Float32Array;
|
|
267
|
+
HEAPF64: Float64Array;
|
|
268
|
+
HEAP64: BigInt64Array;
|
|
269
|
+
HEAPU64: BigUint64Array;
|
|
270
|
+
TOTAL_STACK: number;
|
|
271
|
+
TOTAL_MEMORY: number;
|
|
272
|
+
FAST_MEMORY: number;
|
|
273
|
+
addOnPreRun(cb: () => any): void;
|
|
274
|
+
addOnInit(cb: () => any): void;
|
|
275
|
+
addOnPreMain(cb: () => any): void;
|
|
276
|
+
addOnExit(cb: () => any): void;
|
|
277
|
+
addOnPostRun(cb: () => any): void;
|
|
278
|
+
preloadedImages: any;
|
|
279
|
+
preloadedAudios: any;
|
|
280
|
+
_malloc(size: number): number;
|
|
281
|
+
_free(ptr: number): void;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* A factory function is generated when setting the `MODULARIZE` build option
|
|
285
|
+
* to `1` in your Emscripten build. It return a Promise that resolves to an
|
|
286
|
+
* initialized, ready-to-call `EmscriptenModule` instance.
|
|
287
|
+
*
|
|
288
|
+
* By default, the factory function will be named `Module`. It's recommended to
|
|
289
|
+
* use the `EXPORT_ES6` option, in which the factory function will be the
|
|
290
|
+
* default export. If used without `EXPORT_ES6`, the factory function will be a
|
|
291
|
+
* global variable. You can rename the variable using the `EXPORT_NAME` build
|
|
292
|
+
* option. It's left to you to export any global variables as needed in your
|
|
293
|
+
* application's types.
|
|
294
|
+
* @param moduleOverrides Default properties for the initialized module.
|
|
295
|
+
*/
|
|
296
|
+
export type EmscriptenModuleFactory<T extends EmscriptenModule = EmscriptenModule> = (moduleOverrides?: Partial<T>) => Promise<T>;
|
|
297
|
+
export namespace FS {
|
|
298
|
+
interface Lookup {
|
|
299
|
+
path: string;
|
|
300
|
+
node: FSNode;
|
|
301
|
+
}
|
|
302
|
+
interface Analyze {
|
|
303
|
+
isRoot: boolean;
|
|
304
|
+
exists: boolean;
|
|
305
|
+
error: Error;
|
|
306
|
+
name: string;
|
|
307
|
+
path: Lookup["path"];
|
|
308
|
+
object: Lookup["node"];
|
|
309
|
+
parentExists: boolean;
|
|
310
|
+
parentPath: Lookup["path"];
|
|
311
|
+
parentObject: Lookup["node"];
|
|
312
|
+
}
|
|
313
|
+
interface Mount {
|
|
314
|
+
type: Emscripten.FileSystemType;
|
|
315
|
+
opts: object;
|
|
316
|
+
mountpoint: string;
|
|
317
|
+
mounts: Mount[];
|
|
318
|
+
root: FSNode;
|
|
319
|
+
}
|
|
320
|
+
class FSStream {
|
|
321
|
+
constructor();
|
|
322
|
+
object: FSNode;
|
|
323
|
+
readonly isRead: boolean;
|
|
324
|
+
readonly isWrite: boolean;
|
|
325
|
+
readonly isAppend: boolean;
|
|
326
|
+
flags: number;
|
|
327
|
+
position: number;
|
|
328
|
+
}
|
|
329
|
+
class FSNode {
|
|
330
|
+
parent: FSNode;
|
|
331
|
+
mount: Mount;
|
|
332
|
+
mounted?: Mount;
|
|
333
|
+
id: number;
|
|
334
|
+
name: string;
|
|
335
|
+
mode: number;
|
|
336
|
+
rdev: number;
|
|
337
|
+
readMode: number;
|
|
338
|
+
writeMode: number;
|
|
339
|
+
constructor(parent: FSNode, name: string, mode: number, rdev: number);
|
|
340
|
+
read: boolean;
|
|
341
|
+
write: boolean;
|
|
342
|
+
readonly isFolder: boolean;
|
|
343
|
+
readonly isDevice: boolean;
|
|
344
|
+
}
|
|
345
|
+
interface ErrnoError extends Error {
|
|
346
|
+
name: "ErronoError";
|
|
347
|
+
errno: number;
|
|
348
|
+
code: string;
|
|
349
|
+
}
|
|
350
|
+
function lookupPath(path: string, opts: any): Lookup;
|
|
351
|
+
function getPath(node: FSNode): string;
|
|
352
|
+
function analyzePath(path: string, dontResolveLastLink?: boolean): Analyze;
|
|
353
|
+
function isFile(mode: number): boolean;
|
|
354
|
+
function isDir(mode: number): boolean;
|
|
355
|
+
function isLink(mode: number): boolean;
|
|
356
|
+
function isChrdev(mode: number): boolean;
|
|
357
|
+
function isBlkdev(mode: number): boolean;
|
|
358
|
+
function isFIFO(mode: number): boolean;
|
|
359
|
+
function isSocket(mode: number): boolean;
|
|
360
|
+
function major(dev: number): number;
|
|
361
|
+
function minor(dev: number): number;
|
|
362
|
+
function makedev(ma: number, mi: number): number;
|
|
363
|
+
function registerDevice(dev: number, ops: any): void;
|
|
364
|
+
function syncfs(populate: boolean, callback: (e: any) => any): void;
|
|
365
|
+
function syncfs(callback: (e: any) => any, populate?: boolean): void;
|
|
366
|
+
function mount(type: Emscripten.FileSystemType, opts: any, mountpoint: string): any;
|
|
367
|
+
function unmount(mountpoint: string): void;
|
|
368
|
+
function mkdir(path: string, mode?: number): any;
|
|
369
|
+
function mkdev(path: string, mode?: number, dev?: number): any;
|
|
370
|
+
function symlink(oldpath: string, newpath: string): any;
|
|
371
|
+
function rename(old_path: string, new_path: string): void;
|
|
372
|
+
function rmdir(path: string): void;
|
|
373
|
+
function readdir(path: string): any;
|
|
374
|
+
function unlink(path: string): void;
|
|
375
|
+
function readlink(path: string): string;
|
|
376
|
+
function stat(path: string, dontFollow?: boolean): any;
|
|
377
|
+
function lstat(path: string): any;
|
|
378
|
+
function chmod(path: string, mode: number, dontFollow?: boolean): void;
|
|
379
|
+
function lchmod(path: string, mode: number): void;
|
|
380
|
+
function fchmod(fd: number, mode: number): void;
|
|
381
|
+
function chown(path: string, uid: number, gid: number, dontFollow?: boolean): void;
|
|
382
|
+
function lchown(path: string, uid: number, gid: number): void;
|
|
383
|
+
function fchown(fd: number, uid: number, gid: number): void;
|
|
384
|
+
function truncate(path: string, len: number): void;
|
|
385
|
+
function ftruncate(fd: number, len: number): void;
|
|
386
|
+
function utime(path: string, atime: number, mtime: number): void;
|
|
387
|
+
function open(path: string, flags: string, mode?: number, fd_start?: number, fd_end?: number): FSStream;
|
|
388
|
+
function close(stream: FSStream): void;
|
|
389
|
+
function llseek(stream: FSStream, offset: number, whence: number): any;
|
|
390
|
+
function read(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position?: number): number;
|
|
391
|
+
function write(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position?: number, canOwn?: boolean): number;
|
|
392
|
+
function allocate(stream: FSStream, offset: number, length: number): void;
|
|
393
|
+
function mmap(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position: number, prot: number, flags: number): any;
|
|
394
|
+
function ioctl(stream: FSStream, cmd: any, arg: any): any;
|
|
395
|
+
function readFile(path: string, opts: {
|
|
396
|
+
encoding: "binary";
|
|
397
|
+
flags?: string | undefined;
|
|
398
|
+
}): Uint8Array;
|
|
399
|
+
function readFile(path: string, opts: {
|
|
400
|
+
encoding: "utf8";
|
|
401
|
+
flags?: string | undefined;
|
|
402
|
+
}): string;
|
|
403
|
+
function readFile(path: string, opts?: {
|
|
404
|
+
flags?: string | undefined;
|
|
405
|
+
}): Uint8Array;
|
|
406
|
+
function writeFile(path: string, data: string | ArrayBufferView, opts?: {
|
|
407
|
+
flags?: string | undefined;
|
|
408
|
+
}): void;
|
|
409
|
+
function cwd(): string;
|
|
410
|
+
function chdir(path: string): void;
|
|
411
|
+
function init(input: null | (() => number | null), output: null | ((c: number) => any), error: null | ((c: number) => any)): void;
|
|
412
|
+
function createLazyFile(parent: string | FSNode, name: string, url: string, canRead: boolean, canWrite: boolean): FSNode;
|
|
413
|
+
function createPreloadedFile(parent: string | FSNode, name: string, url: string, canRead: boolean, canWrite: boolean, onload?: () => void, onerror?: () => void, dontCreateFile?: boolean, canOwn?: boolean): void;
|
|
414
|
+
function createDataFile(parent: string | FSNode, name: string, data: ArrayBufferView, canRead: boolean, canWrite: boolean, canOwn: boolean): FSNode;
|
|
415
|
+
}
|
|
416
|
+
export const MEMFS: Emscripten.FileSystemType;
|
|
417
|
+
export const NODEFS: Emscripten.FileSystemType;
|
|
418
|
+
export const IDBFS: Emscripten.FileSystemType;
|
|
419
|
+
type StringToType<R> = R extends Emscripten.JSType ? {
|
|
420
|
+
number: number;
|
|
421
|
+
string: string;
|
|
422
|
+
array: number[] | string[] | boolean[] | Uint8Array | Int8Array;
|
|
423
|
+
boolean: boolean;
|
|
424
|
+
null: null;
|
|
425
|
+
}[R] : never;
|
|
426
|
+
type ArgsToType<T extends Array<Emscripten.JSType | null>> = Extract<{
|
|
427
|
+
[P in keyof T]: StringToType<T[P]>;
|
|
428
|
+
}, any[]>;
|
|
429
|
+
type ReturnToType<R extends Emscripten.JSType | null> = R extends null ? null : StringToType<Exclude<R, null>>;
|
|
430
|
+
export function cwrap<I extends Array<Emscripten.JSType | null> | [
|
|
431
|
+
], R extends Emscripten.JSType | null>(ident: string, returnType: R, argTypes: I, opts?: Emscripten.CCallOpts): (...arg: ArgsToType<I>) => ReturnToType<R>;
|
|
432
|
+
export function ccall<I extends Array<Emscripten.JSType | null> | [
|
|
433
|
+
], R extends Emscripten.JSType | null>(ident: string, returnType: R, argTypes: I, args: ArgsToType<I>, opts?: Emscripten.CCallOpts): ReturnToType<R>;
|
|
434
|
+
export function setValue(ptr: number, value: any, type: Emscripten.CType, noSafe?: boolean): void;
|
|
435
|
+
export function getValue(ptr: number, type: Emscripten.CType, noSafe?: boolean): number;
|
|
436
|
+
export function allocate(slab: number[] | ArrayBufferView | number, types: Emscripten.CType | Emscripten.CType[], allocator: number, ptr?: number): number;
|
|
437
|
+
export function stackAlloc(size: number): number;
|
|
438
|
+
export function stackSave(): number;
|
|
439
|
+
export function stackRestore(ptr: number): void;
|
|
440
|
+
export function UTF8ToString(ptr: number, maxBytesToRead?: number): string;
|
|
441
|
+
export function stringToUTF8(str: string, outPtr: number, maxBytesToRead?: number): void;
|
|
442
|
+
export function lengthBytesUTF8(str: string): number;
|
|
443
|
+
export function allocateUTF8(str: string): number;
|
|
444
|
+
export function allocateUTF8OnStack(str: string): number;
|
|
445
|
+
export function UTF16ToString(ptr: number): string;
|
|
446
|
+
export function stringToUTF16(str: string, outPtr: number, maxBytesToRead?: number): void;
|
|
447
|
+
export function lengthBytesUTF16(str: string): number;
|
|
448
|
+
export function UTF32ToString(ptr: number): string;
|
|
449
|
+
export function stringToUTF32(str: string, outPtr: number, maxBytesToRead?: number): void;
|
|
450
|
+
export function lengthBytesUTF32(str: string): number;
|
|
451
|
+
export function intArrayFromString(stringy: string, dontAddNull?: boolean, length?: number): number[];
|
|
452
|
+
export function intArrayToString(array: number[]): string;
|
|
453
|
+
export function writeStringToMemory(str: string, buffer: number, dontAddNull: boolean): void;
|
|
454
|
+
export function writeArrayToMemory(array: number[], buffer: number): void;
|
|
455
|
+
export function writeAsciiToMemory(str: string, buffer: number, dontAddNull: boolean): void;
|
|
456
|
+
export function addRunDependency(id: any): void;
|
|
457
|
+
export function removeRunDependency(id: any): void;
|
|
458
|
+
export function addFunction(func: (...args: any[]) => any, signature?: string): number;
|
|
459
|
+
export function removeFunction(funcPtr: number): void;
|
|
460
|
+
export const ALLOC_NORMAL: number;
|
|
461
|
+
export const ALLOC_STACK: number;
|
|
462
|
+
export const ALLOC_STATIC: number;
|
|
463
|
+
export const ALLOC_DYNAMIC: number;
|
|
464
|
+
export const ALLOC_NONE: number;
|
|
465
|
+
export {};
|
|
223
466
|
}
|
|
224
|
-
|
|
225
|
-
* Represents an event related to the PHP instance.
|
|
226
|
-
* This is intentionally not an extension of CustomEvent
|
|
227
|
-
* to make it isomorphic between different JavaScript runtimes.
|
|
228
|
-
*/
|
|
229
|
-
export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
|
|
230
|
-
/**
|
|
231
|
-
* A callback function that handles PHP events.
|
|
232
|
-
*/
|
|
233
|
-
export type PHPEventListener = (event: PHPEvent) => void;
|
|
234
|
-
export interface IsomorphicLocalPHP {
|
|
235
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
236
|
-
request(request: PHPRequest): Promise<PHPResponse>;
|
|
237
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
238
|
-
pathToInternalUrl(path: string): string;
|
|
239
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
240
|
-
internalUrlToPath(internalUrl: string): string;
|
|
241
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
242
|
-
absoluteUrl: string;
|
|
243
|
-
/** @deprecated Use PHPRequestHandler instead. */
|
|
244
|
-
documentRoot: string;
|
|
467
|
+
export interface RmDirOptions {
|
|
245
468
|
/**
|
|
246
|
-
*
|
|
247
|
-
*
|
|
469
|
+
* If true, recursively removes the directory and all its contents.
|
|
470
|
+
* Default: true.
|
|
248
471
|
*/
|
|
249
|
-
|
|
472
|
+
recursive?: boolean;
|
|
473
|
+
}
|
|
474
|
+
export interface ListFilesOptions {
|
|
250
475
|
/**
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
* @param value - The value of the constant.
|
|
476
|
+
* If true, prepend given folder path to all file names.
|
|
477
|
+
* Default: false.
|
|
254
478
|
*/
|
|
255
|
-
|
|
479
|
+
prependPath: boolean;
|
|
480
|
+
}
|
|
481
|
+
export interface SemaphoreOptions {
|
|
256
482
|
/**
|
|
257
|
-
*
|
|
258
|
-
* @param eventType - The type of event to listen for.
|
|
259
|
-
* @param listener - The listener function to be called when the event is triggered.
|
|
483
|
+
* The maximum number of concurrent locks.
|
|
260
484
|
*/
|
|
261
|
-
|
|
485
|
+
concurrency: number;
|
|
262
486
|
/**
|
|
263
|
-
*
|
|
264
|
-
* @param eventType - The type of event to remove the listener from.
|
|
265
|
-
* @param listener - The listener function to be removed.
|
|
487
|
+
* The maximum time to wait for a lock to become available.
|
|
266
488
|
*/
|
|
267
|
-
|
|
489
|
+
timeout?: number;
|
|
490
|
+
}
|
|
491
|
+
declare class Semaphore {
|
|
492
|
+
private _running;
|
|
493
|
+
private concurrency;
|
|
494
|
+
private timeout?;
|
|
495
|
+
private queue;
|
|
496
|
+
constructor({ concurrency, timeout }: SemaphoreOptions);
|
|
497
|
+
get remaining(): number;
|
|
498
|
+
get running(): number;
|
|
499
|
+
acquire(): Promise<() => void>;
|
|
500
|
+
run<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
501
|
+
}
|
|
502
|
+
export declare function phpVar(value: unknown): string;
|
|
503
|
+
export declare function phpVars<T extends Record<string, unknown>>(vars: T): Record<keyof T, string>;
|
|
504
|
+
export type PHPFactoryOptions = {
|
|
505
|
+
isPrimary: boolean;
|
|
506
|
+
};
|
|
507
|
+
export type PHPFactory = (options: PHPFactoryOptions) => Promise<PHP>;
|
|
508
|
+
export interface ProcessManagerOptions {
|
|
268
509
|
/**
|
|
269
|
-
*
|
|
270
|
-
*
|
|
271
|
-
* @param path - The path to the php.ini file.
|
|
510
|
+
* The maximum number of PHP instances that can exist at
|
|
511
|
+
* the same time.
|
|
272
512
|
*/
|
|
273
|
-
|
|
513
|
+
maxPhpInstances?: number;
|
|
274
514
|
/**
|
|
275
|
-
*
|
|
515
|
+
* The number of milliseconds to wait for a PHP instance when
|
|
516
|
+
* we have reached the maximum number of PHP instances and
|
|
517
|
+
* cannot spawn a new one. If the timeout is reached, we assume
|
|
518
|
+
* all the PHP instances are deadlocked and a throw MaxPhpInstancesError.
|
|
276
519
|
*
|
|
277
|
-
*
|
|
278
|
-
* @param value - The value to set for the key.
|
|
520
|
+
* Default: 5000
|
|
279
521
|
*/
|
|
280
|
-
|
|
522
|
+
timeout?: number;
|
|
281
523
|
/**
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* it will create the directories `/root/php` and `/root/php/data`.
|
|
285
|
-
*
|
|
286
|
-
* @param path - The directory path to create.
|
|
524
|
+
* The primary PHP instance that's never killed. This instance
|
|
525
|
+
* contains the reference filesystem used by all other PHP instances.
|
|
287
526
|
*/
|
|
288
|
-
|
|
527
|
+
primaryPhp?: PHP;
|
|
289
528
|
/**
|
|
290
|
-
*
|
|
529
|
+
* A factory function used for spawning new PHP instances.
|
|
291
530
|
*/
|
|
292
|
-
|
|
531
|
+
phpFactory?: PHPFactory;
|
|
532
|
+
}
|
|
533
|
+
export interface SpawnedPHP {
|
|
534
|
+
php: PHP;
|
|
535
|
+
reap: () => void;
|
|
536
|
+
}
|
|
537
|
+
declare class PHPProcessManager implements AsyncDisposable {
|
|
538
|
+
private primaryPhp?;
|
|
539
|
+
private primaryIdle;
|
|
540
|
+
private nextInstance;
|
|
293
541
|
/**
|
|
294
|
-
*
|
|
295
|
-
*
|
|
296
|
-
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
297
|
-
* @param path - The file path to read.
|
|
298
|
-
* @returns The file contents.
|
|
542
|
+
* All spawned PHP instances, including the primary PHP instance.
|
|
543
|
+
* Used for bookkeeping and reaping all instances on dispose.
|
|
299
544
|
*/
|
|
300
|
-
|
|
545
|
+
private allInstances;
|
|
546
|
+
private phpFactory?;
|
|
547
|
+
private maxPhpInstances;
|
|
548
|
+
private semaphore;
|
|
549
|
+
constructor(options?: ProcessManagerOptions);
|
|
301
550
|
/**
|
|
302
|
-
*
|
|
551
|
+
* Get the primary PHP instance.
|
|
303
552
|
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
* @returns The file contents.
|
|
307
|
-
*/
|
|
308
|
-
readFileAsBuffer(path: string): Uint8Array;
|
|
309
|
-
/**
|
|
310
|
-
* Overwrites data in a file in the PHP filesystem.
|
|
311
|
-
* Creates a new file if one doesn't exist yet.
|
|
553
|
+
* If the primary PHP instance is not set, it will be spawned
|
|
554
|
+
* using the provided phpFactory.
|
|
312
555
|
*
|
|
313
|
-
* @
|
|
314
|
-
* @param data - The data to write to the file.
|
|
556
|
+
* @throws {Error} when called twice before the first call is resolved.
|
|
315
557
|
*/
|
|
316
|
-
|
|
558
|
+
getPrimaryPhp(): Promise<PHP>;
|
|
317
559
|
/**
|
|
318
|
-
*
|
|
560
|
+
* Get a PHP instance.
|
|
319
561
|
*
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*/
|
|
323
|
-
unlink(path: string): void;
|
|
324
|
-
/**
|
|
325
|
-
* Moves a file or directory in the PHP filesystem to a
|
|
326
|
-
* new location.
|
|
562
|
+
* It could be either the primary PHP instance, an idle disposable PHP instance,
|
|
563
|
+
* or a newly spawned PHP instance – depending on the resource availability.
|
|
327
564
|
*
|
|
328
|
-
* @
|
|
329
|
-
*
|
|
565
|
+
* @throws {MaxPhpInstancesError} when the maximum number of PHP instances is reached
|
|
566
|
+
* and the waiting timeout is exceeded.
|
|
330
567
|
*/
|
|
331
|
-
|
|
568
|
+
acquirePHPInstance(): Promise<SpawnedPHP>;
|
|
332
569
|
/**
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
570
|
+
* Initiated spawning of a new PHP instance.
|
|
571
|
+
* This function is synchronous on purpose – it needs to synchronously
|
|
572
|
+
* add the spawn promise to the allInstances array without waiting
|
|
573
|
+
* for PHP to spawn.
|
|
337
574
|
*/
|
|
338
|
-
|
|
575
|
+
private spawn;
|
|
339
576
|
/**
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
* @param path - The directory path to list.
|
|
343
|
-
* @param options - Options for the listing.
|
|
344
|
-
* @returns The list of files and directories in the given directory.
|
|
577
|
+
* Actually acquires the lock and spawns a new PHP instance.
|
|
345
578
|
*/
|
|
346
|
-
|
|
579
|
+
private doSpawn;
|
|
580
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
581
|
+
}
|
|
582
|
+
export type RewriteRule = {
|
|
583
|
+
match: RegExp;
|
|
584
|
+
replacement: string;
|
|
585
|
+
};
|
|
586
|
+
export interface BaseConfiguration {
|
|
347
587
|
/**
|
|
348
|
-
*
|
|
349
|
-
*
|
|
350
|
-
* @param path – The path to check.
|
|
351
|
-
* @returns True if the path is a directory, false otherwise.
|
|
588
|
+
* The directory in the PHP filesystem where the server will look
|
|
589
|
+
* for the files to serve. Default: `/var/www`.
|
|
352
590
|
*/
|
|
353
|
-
|
|
591
|
+
documentRoot?: string;
|
|
354
592
|
/**
|
|
355
|
-
*
|
|
356
|
-
*
|
|
357
|
-
* @param path - The file path to check.
|
|
358
|
-
* @returns True if the file exists, false otherwise.
|
|
593
|
+
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
359
594
|
*/
|
|
360
|
-
|
|
595
|
+
absoluteUrl?: string;
|
|
361
596
|
/**
|
|
362
|
-
*
|
|
363
|
-
* This is the directory that will be used as the base for relative paths.
|
|
364
|
-
* For example, if the current working directory is `/root/php`, and the
|
|
365
|
-
* path is `data`, the absolute path will be `/root/php/data`.
|
|
366
|
-
*
|
|
367
|
-
* @param path - The new working directory.
|
|
597
|
+
* Rewrite rules
|
|
368
598
|
*/
|
|
369
|
-
|
|
599
|
+
rewriteRules?: RewriteRule[];
|
|
600
|
+
}
|
|
601
|
+
export type PHPRequestHandlerFactoryArgs = PHPFactoryOptions & {
|
|
602
|
+
requestHandler: PHPRequestHandler;
|
|
603
|
+
};
|
|
604
|
+
export type PHPRequestHandlerConfiguration = BaseConfiguration & ({
|
|
370
605
|
/**
|
|
371
|
-
*
|
|
372
|
-
*
|
|
373
|
-
* This low-level method directly interacts with the WebAssembly
|
|
374
|
-
* PHP interpreter.
|
|
375
|
-
*
|
|
376
|
-
* Every time you call run(), it prepares the PHP
|
|
377
|
-
* environment and:
|
|
378
|
-
*
|
|
379
|
-
* * Resets the internal PHP state
|
|
380
|
-
* * Populates superglobals ($_SERVER, $_GET, etc.)
|
|
381
|
-
* * Handles file uploads
|
|
382
|
-
* * Populates input streams (stdin, argv, etc.)
|
|
383
|
-
* * Sets the current working directory
|
|
384
|
-
*
|
|
385
|
-
* You can use run() in two primary modes:
|
|
386
|
-
*
|
|
387
|
-
* ### Code snippet mode
|
|
388
|
-
*
|
|
389
|
-
* In this mode, you pass a string containing PHP code to run.
|
|
390
|
-
*
|
|
391
|
-
* ```ts
|
|
392
|
-
* const result = await php.run({
|
|
393
|
-
* code: `<?php echo "Hello world!";`
|
|
394
|
-
* });
|
|
395
|
-
* // result.text === "Hello world!"
|
|
396
|
-
* ```
|
|
397
|
-
*
|
|
398
|
-
* In this mode, information like __DIR__ or __FILE__ isn't very
|
|
399
|
-
* useful because the code is not associated with any file.
|
|
606
|
+
* PHPProcessManager is required because the request handler needs
|
|
607
|
+
* to make a decision for each request.
|
|
400
608
|
*
|
|
401
|
-
*
|
|
402
|
-
*
|
|
403
|
-
*
|
|
404
|
-
* ### File mode
|
|
405
|
-
*
|
|
406
|
-
* In the file mode, you pass a scriptPath and PHP executes a file
|
|
407
|
-
* found at a that path:
|
|
408
|
-
*
|
|
409
|
-
* ```ts
|
|
410
|
-
* php.writeFile(
|
|
411
|
-
* "/www/index.php",
|
|
412
|
-
* `<?php echo "Hello world!";"`
|
|
413
|
-
* );
|
|
414
|
-
* const result = await php.run({
|
|
415
|
-
* scriptPath: "/www/index.php"
|
|
416
|
-
* });
|
|
417
|
-
* // result.text === "Hello world!"
|
|
418
|
-
* ```
|
|
419
|
-
*
|
|
420
|
-
* In this mode, you can rely on path-related information like __DIR__
|
|
421
|
-
* or __FILE__.
|
|
422
|
-
*
|
|
423
|
-
* Under the hood, the PHP file is executed with the `php_execute_script`
|
|
424
|
-
* C function.
|
|
425
|
-
*
|
|
426
|
-
* The `run()` method cannot be used in conjunction with `cli()`.
|
|
427
|
-
*
|
|
428
|
-
* @example
|
|
429
|
-
* ```js
|
|
430
|
-
* const result = await php.run(`<?php
|
|
431
|
-
* $fp = fopen('php://stderr', 'w');
|
|
432
|
-
* fwrite($fp, "Hello, world!");
|
|
433
|
-
* `);
|
|
434
|
-
* // result.errors === "Hello, world!"
|
|
435
|
-
* ```
|
|
436
|
-
*
|
|
437
|
-
* @param options - PHP runtime options.
|
|
438
|
-
*/
|
|
439
|
-
run(options: PHPRunOptions): Promise<PHPResponse>;
|
|
440
|
-
/**
|
|
441
|
-
* Listens to message sent by the PHP code.
|
|
442
|
-
*
|
|
443
|
-
* To dispatch messages, call:
|
|
444
|
-
*
|
|
445
|
-
* post_message_to_js(string $data)
|
|
446
|
-
*
|
|
447
|
-
* Arguments:
|
|
448
|
-
* $data (string) – Data to pass to JavaScript.
|
|
449
|
-
*
|
|
450
|
-
* @example
|
|
451
|
-
*
|
|
452
|
-
* ```ts
|
|
453
|
-
* const php = await PHP.load('8.0');
|
|
454
|
-
*
|
|
455
|
-
* php.onMessage(
|
|
456
|
-
* // The data is always passed as a string
|
|
457
|
-
* function (data: string) {
|
|
458
|
-
* // Let's decode and log the data:
|
|
459
|
-
* console.log(JSON.parse(data));
|
|
460
|
-
* }
|
|
461
|
-
* );
|
|
462
|
-
*
|
|
463
|
-
* // Now that we have a listener in place, let's
|
|
464
|
-
* // dispatch a message:
|
|
465
|
-
* await php.run({
|
|
466
|
-
* code: `<?php
|
|
467
|
-
* post_message_to_js(
|
|
468
|
-
* json_encode([
|
|
469
|
-
* 'post_id' => '15',
|
|
470
|
-
* 'post_title' => 'This is a blog post!'
|
|
471
|
-
* ])
|
|
472
|
-
* ));
|
|
473
|
-
* `,
|
|
474
|
-
* });
|
|
475
|
-
* ```
|
|
476
|
-
*
|
|
477
|
-
* @param listener Callback function to handle the message.
|
|
478
|
-
*/
|
|
479
|
-
onMessage(listener: MessageListener): void;
|
|
480
|
-
}
|
|
481
|
-
export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void;
|
|
482
|
-
export interface EventEmitter {
|
|
483
|
-
on(event: string, listener: (...args: any[]) => void): this;
|
|
484
|
-
emit(event: string, ...args: any[]): boolean;
|
|
485
|
-
}
|
|
486
|
-
export type ChildProcess = EventEmitter & {
|
|
487
|
-
stdout: EventEmitter;
|
|
488
|
-
stderr: EventEmitter;
|
|
489
|
-
};
|
|
490
|
-
export type SpawnHandler = (command: string, args: string[]) => ChildProcess;
|
|
491
|
-
/**
|
|
492
|
-
* The omited methods must either be called synchronously before
|
|
493
|
-
* the PHP internal state is initialized, or with a complex argument
|
|
494
|
-
* that can't be serialized over a remote connection. Therefeore,
|
|
495
|
-
* they don't make sense in a remote PHP instance.
|
|
496
|
-
*/
|
|
497
|
-
export type IsomorphicRemotePHP = Remote<Omit<IsomorphicLocalPHP, "setSapiName" | "setPhpIniEntry" | "setPhpIniPath">>;
|
|
498
|
-
export type UniversalPHP = IsomorphicLocalPHP | IsomorphicRemotePHP;
|
|
499
|
-
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
500
|
-
export type PHPRequestHeaders = Record<string, string>;
|
|
501
|
-
export interface PHPRequest {
|
|
502
|
-
/**
|
|
503
|
-
* Request method. Default: `GET`.
|
|
504
|
-
*/
|
|
505
|
-
method?: HTTPMethod;
|
|
506
|
-
/**
|
|
507
|
-
* Request path or absolute URL.
|
|
508
|
-
*/
|
|
509
|
-
url: string;
|
|
510
|
-
/**
|
|
511
|
-
* Request headers.
|
|
512
|
-
*/
|
|
513
|
-
headers?: PHPRequestHeaders;
|
|
514
|
-
/**
|
|
515
|
-
* Request body.
|
|
516
|
-
* If an object is given, the request will be encoded as multipart
|
|
517
|
-
* and sent with a `multipart/form-data` header.
|
|
518
|
-
*/
|
|
519
|
-
body?: string | Uint8Array | Record<string, string | Uint8Array | File>;
|
|
520
|
-
}
|
|
521
|
-
export interface PHPRunOptions {
|
|
522
|
-
/**
|
|
523
|
-
* Request path following the domain:port part.
|
|
524
|
-
*/
|
|
525
|
-
relativeUri?: string;
|
|
526
|
-
/**
|
|
527
|
-
* Path of the .php file to execute.
|
|
528
|
-
*/
|
|
529
|
-
scriptPath?: string;
|
|
530
|
-
/**
|
|
531
|
-
* Request protocol.
|
|
532
|
-
*/
|
|
533
|
-
protocol?: string;
|
|
534
|
-
/**
|
|
535
|
-
* Request method. Default: `GET`.
|
|
536
|
-
*/
|
|
537
|
-
method?: HTTPMethod;
|
|
538
|
-
/**
|
|
539
|
-
* Request headers.
|
|
540
|
-
*/
|
|
541
|
-
headers?: PHPRequestHeaders;
|
|
542
|
-
/**
|
|
543
|
-
* Request body.
|
|
544
|
-
*/
|
|
545
|
-
body?: string | Uint8Array;
|
|
546
|
-
/**
|
|
547
|
-
* Environment variables to set for this run.
|
|
548
|
-
*/
|
|
549
|
-
env?: Record<string, string>;
|
|
550
|
-
/**
|
|
551
|
-
* $_SERVER entries to set for this run.
|
|
552
|
-
*/
|
|
553
|
-
$_SERVER?: Record<string, string>;
|
|
554
|
-
/**
|
|
555
|
-
* The code snippet to eval instead of a php file.
|
|
556
|
-
*/
|
|
557
|
-
code?: string;
|
|
558
|
-
}
|
|
559
|
-
/**
|
|
560
|
-
* Output of the PHP.wasm runtime.
|
|
561
|
-
*/
|
|
562
|
-
export interface PHPOutput {
|
|
563
|
-
/** Exit code of the PHP process. 0 means success, 1 and 2 mean error. */
|
|
564
|
-
exitCode: number;
|
|
565
|
-
/** Stdout data */
|
|
566
|
-
stdout: ArrayBuffer;
|
|
567
|
-
/** Stderr lines */
|
|
568
|
-
stderr: string[];
|
|
569
|
-
}
|
|
570
|
-
export interface RmDirOptions {
|
|
571
|
-
/**
|
|
572
|
-
* If true, recursively removes the directory and all its contents.
|
|
573
|
-
* Default: true.
|
|
574
|
-
*/
|
|
575
|
-
recursive?: boolean;
|
|
576
|
-
}
|
|
577
|
-
export interface ListFilesOptions {
|
|
578
|
-
/**
|
|
579
|
-
* If true, prepend given folder path to all file names.
|
|
580
|
-
* Default: false.
|
|
581
|
-
*/
|
|
582
|
-
prependPath: boolean;
|
|
583
|
-
}
|
|
584
|
-
export type RuntimeType = "NODE" | "WEB" | "WORKER";
|
|
585
|
-
export type PHPRuntimeId = number;
|
|
586
|
-
export type PHPRuntime = any;
|
|
587
|
-
export type PHPLoaderModule = {
|
|
588
|
-
dependencyFilename: string;
|
|
589
|
-
dependenciesTotalSize: number;
|
|
590
|
-
init: (jsRuntime: string, options: EmscriptenOptions) => PHPRuntime;
|
|
591
|
-
};
|
|
592
|
-
export type EmscriptenOptions = {
|
|
593
|
-
onAbort?: (message: string) => void;
|
|
594
|
-
/**
|
|
595
|
-
* Set to true for debugging tricky WebAssembly errors.
|
|
596
|
-
*/
|
|
597
|
-
debug?: boolean;
|
|
598
|
-
ENV?: Record<string, string>;
|
|
599
|
-
locateFile?: (path: string) => string;
|
|
600
|
-
noInitialRun?: boolean;
|
|
601
|
-
print?: (message: string) => void;
|
|
602
|
-
printErr?: (message: string) => void;
|
|
603
|
-
quit?: (status: number, toThrow: any) => void;
|
|
604
|
-
onRuntimeInitialized?: () => void;
|
|
605
|
-
monitorRunDependencies?: (left: number) => void;
|
|
606
|
-
onMessage?: (listener: EmscriptenMessageListener) => void;
|
|
607
|
-
instantiateWasm?: (info: WebAssembly.Imports, receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void) => void;
|
|
608
|
-
} & Record<string, any>;
|
|
609
|
-
export type EmscriptenMessageListener = (type: string, data: string) => void;
|
|
610
|
-
export interface SemaphoreOptions {
|
|
611
|
-
/**
|
|
612
|
-
* The maximum number of concurrent locks.
|
|
613
|
-
*/
|
|
614
|
-
concurrency: number;
|
|
615
|
-
/**
|
|
616
|
-
* The maximum time to wait for a lock to become available.
|
|
617
|
-
*/
|
|
618
|
-
timeout?: number;
|
|
619
|
-
}
|
|
620
|
-
declare class Semaphore {
|
|
621
|
-
private _running;
|
|
622
|
-
private concurrency;
|
|
623
|
-
private timeout?;
|
|
624
|
-
private queue;
|
|
625
|
-
constructor({ concurrency, timeout }: SemaphoreOptions);
|
|
626
|
-
get remaining(): number;
|
|
627
|
-
get running(): number;
|
|
628
|
-
acquire(): Promise<() => void>;
|
|
629
|
-
run<T>(fn: () => T | Promise<T>): Promise<T>;
|
|
630
|
-
}
|
|
631
|
-
export declare function phpVar(value: unknown): string;
|
|
632
|
-
export declare function phpVars<T extends Record<string, unknown>>(vars: T): Record<keyof T, string>;
|
|
633
|
-
export type RewriteRule = {
|
|
634
|
-
match: RegExp;
|
|
635
|
-
replacement: string;
|
|
636
|
-
};
|
|
637
|
-
export interface BaseConfiguration {
|
|
638
|
-
/**
|
|
639
|
-
* The directory in the PHP filesystem where the server will look
|
|
640
|
-
* for the files to serve. Default: `/var/www`.
|
|
641
|
-
*/
|
|
642
|
-
documentRoot?: string;
|
|
643
|
-
/**
|
|
644
|
-
* Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
|
|
645
|
-
*/
|
|
646
|
-
absoluteUrl?: string;
|
|
647
|
-
/**
|
|
648
|
-
* Rewrite rules
|
|
649
|
-
*/
|
|
650
|
-
rewriteRules?: RewriteRule[];
|
|
651
|
-
}
|
|
652
|
-
export type PHPRequestHandlerFactoryArgs<PHP extends BasePHP> = PHPFactoryOptions & {
|
|
653
|
-
requestHandler: PHPRequestHandler<PHP>;
|
|
654
|
-
};
|
|
655
|
-
export type PHPRequestHandlerConfiguration<PHP extends BasePHP> = BaseConfiguration & ({
|
|
656
|
-
/**
|
|
657
|
-
* PHPProcessManager is required because the request handler needs
|
|
658
|
-
* to make a decision for each request.
|
|
659
|
-
*
|
|
660
|
-
* Static assets are served using the primary PHP's filesystem, even
|
|
661
|
-
* when serving 100 static files concurrently. No new PHP interpreter
|
|
662
|
-
* is ever created as there's no need for it.
|
|
609
|
+
* Static assets are served using the primary PHP's filesystem, even
|
|
610
|
+
* when serving 100 static files concurrently. No new PHP interpreter
|
|
611
|
+
* is ever created as there's no need for it.
|
|
663
612
|
*
|
|
664
613
|
* Dynamic PHP requests, however, require grabbing an available PHP
|
|
665
614
|
* interpreter, and that's where the PHPProcessManager comes in.
|
|
666
615
|
*/
|
|
667
|
-
processManager: PHPProcessManager
|
|
616
|
+
processManager: PHPProcessManager;
|
|
668
617
|
} | {
|
|
669
|
-
phpFactory: (requestHandler: PHPRequestHandlerFactoryArgs
|
|
618
|
+
phpFactory: (requestHandler: PHPRequestHandlerFactoryArgs) => Promise<PHP>;
|
|
670
619
|
/**
|
|
671
620
|
* The maximum number of PHP instances that can exist at
|
|
672
621
|
* the same time.
|
|
@@ -727,10 +676,10 @@ export type PHPRequestHandlerConfiguration<PHP extends BasePHP> = BaseConfigurat
|
|
|
727
676
|
* // "Hi from PHP!"
|
|
728
677
|
* ```
|
|
729
678
|
*/
|
|
730
|
-
export declare class PHPRequestHandler
|
|
679
|
+
export declare class PHPRequestHandler {
|
|
731
680
|
#private;
|
|
732
681
|
rewriteRules: RewriteRule[];
|
|
733
|
-
processManager: PHPProcessManager
|
|
682
|
+
processManager: PHPProcessManager;
|
|
734
683
|
/**
|
|
735
684
|
* The request handler needs to decide whether to serve a static asset or
|
|
736
685
|
* run the PHP interpreter. For static assets it should just reuse the primary
|
|
@@ -742,7 +691,7 @@ export declare class PHPRequestHandler<PHP extends BasePHP> {
|
|
|
742
691
|
* @param php - The PHP instance.
|
|
743
692
|
* @param config - Request Handler configuration.
|
|
744
693
|
*/
|
|
745
|
-
constructor(config: PHPRequestHandlerConfiguration
|
|
694
|
+
constructor(config: PHPRequestHandlerConfiguration);
|
|
746
695
|
getPrimaryPhp(): Promise<PHP>;
|
|
747
696
|
/**
|
|
748
697
|
* Converts a path to an absolute URL based at the PHPRequestHandler
|
|
@@ -820,10 +769,12 @@ export declare class PHPRequestHandler<PHP extends BasePHP> {
|
|
|
820
769
|
request(request: PHPRequest): Promise<PHPResponse>;
|
|
821
770
|
}
|
|
822
771
|
declare const __private__dont__use: unique symbol;
|
|
823
|
-
|
|
772
|
+
export type UnmountFunction = (() => Promise<any>) | (() => any);
|
|
773
|
+
export type MountHandler = (php: PHP, FS: Emscripten.RootFS, vfsMountPoint: string) => UnmountFunction | Promise<UnmountFunction>;
|
|
774
|
+
declare class PHP implements Disposable {
|
|
824
775
|
#private;
|
|
825
776
|
protected [__private__dont__use]: any;
|
|
826
|
-
requestHandler?: PHPRequestHandler
|
|
777
|
+
requestHandler?: PHPRequestHandler;
|
|
827
778
|
/**
|
|
828
779
|
* An exclusive lock that prevent multiple requests from running at
|
|
829
780
|
* the same time.
|
|
@@ -837,152 +788,471 @@ declare abstract class BasePHP implements IsomorphicLocalPHP, Disposable {
|
|
|
837
788
|
* @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
|
|
838
789
|
*/
|
|
839
790
|
constructor(PHPRuntimeId?: PHPRuntimeId);
|
|
791
|
+
/**
|
|
792
|
+
* Adds an event listener for a PHP event.
|
|
793
|
+
* @param eventType - The type of event to listen for.
|
|
794
|
+
* @param listener - The listener function to be called when the event is triggered.
|
|
795
|
+
*/
|
|
840
796
|
addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
797
|
+
/**
|
|
798
|
+
* Removes an event listener for a PHP event.
|
|
799
|
+
* @param eventType - The type of event to remove the listener from.
|
|
800
|
+
* @param listener - The listener function to be removed.
|
|
801
|
+
*/
|
|
841
802
|
removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
842
803
|
dispatchEvent<Event extends PHPEvent>(event: Event): void;
|
|
843
|
-
/**
|
|
844
|
-
|
|
845
|
-
|
|
804
|
+
/**
|
|
805
|
+
* Listens to message sent by the PHP code.
|
|
806
|
+
*
|
|
807
|
+
* To dispatch messages, call:
|
|
808
|
+
*
|
|
809
|
+
* post_message_to_js(string $data)
|
|
810
|
+
*
|
|
811
|
+
* Arguments:
|
|
812
|
+
* $data (string) – Data to pass to JavaScript.
|
|
813
|
+
*
|
|
814
|
+
* @example
|
|
815
|
+
*
|
|
816
|
+
* ```ts
|
|
817
|
+
* const php = await PHP.load('8.0');
|
|
818
|
+
*
|
|
819
|
+
* php.onMessage(
|
|
820
|
+
* // The data is always passed as a string
|
|
821
|
+
* function (data: string) {
|
|
822
|
+
* // Let's decode and log the data:
|
|
823
|
+
* console.log(JSON.parse(data));
|
|
824
|
+
* }
|
|
825
|
+
* );
|
|
826
|
+
*
|
|
827
|
+
* // Now that we have a listener in place, let's
|
|
828
|
+
* // dispatch a message:
|
|
829
|
+
* await php.run({
|
|
830
|
+
* code: `<?php
|
|
831
|
+
* post_message_to_js(
|
|
832
|
+
* json_encode([
|
|
833
|
+
* 'post_id' => '15',
|
|
834
|
+
* 'post_title' => 'This is a blog post!'
|
|
835
|
+
* ])
|
|
836
|
+
* ));
|
|
837
|
+
* `,
|
|
838
|
+
* });
|
|
839
|
+
* ```
|
|
840
|
+
*
|
|
841
|
+
* @param listener Callback function to handle the message.
|
|
842
|
+
*/
|
|
843
|
+
onMessage(listener: MessageListener): void;
|
|
846
844
|
setSpawnHandler(handler: SpawnHandler | string): Promise<void>;
|
|
847
|
-
/** @
|
|
845
|
+
/** @deprecated Use PHPRequestHandler instead. */
|
|
848
846
|
get absoluteUrl(): string;
|
|
849
|
-
/** @
|
|
847
|
+
/** @deprecated Use PHPRequestHandler instead. */
|
|
850
848
|
get documentRoot(): string;
|
|
851
|
-
/** @
|
|
849
|
+
/** @deprecated Use PHPRequestHandler instead. */
|
|
852
850
|
pathToInternalUrl(path: string): string;
|
|
853
|
-
/** @
|
|
851
|
+
/** @deprecated Use PHPRequestHandler instead. */
|
|
854
852
|
internalUrlToPath(internalUrl: string): string;
|
|
855
853
|
initializeRuntime(runtimeId: PHPRuntimeId): void;
|
|
856
854
|
/** @inheritDoc */
|
|
857
855
|
setSapiName(newName: string): Promise<void>;
|
|
858
|
-
/**
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
856
|
+
/**
|
|
857
|
+
* Changes the current working directory in the PHP filesystem.
|
|
858
|
+
* This is the directory that will be used as the base for relative paths.
|
|
859
|
+
* For example, if the current working directory is `/root/php`, and the
|
|
860
|
+
* path is `data`, the absolute path will be `/root/php/data`.
|
|
861
|
+
*
|
|
862
|
+
* @param path - The new working directory.
|
|
863
|
+
*/
|
|
863
864
|
chdir(path: string): void;
|
|
864
865
|
/**
|
|
865
866
|
* Do not use. Use new PHPRequestHandler() instead.
|
|
866
867
|
* @deprecated
|
|
867
868
|
*/
|
|
868
869
|
request(request: PHPRequest): Promise<PHPResponse>;
|
|
869
|
-
/**
|
|
870
|
+
/**
|
|
871
|
+
* Runs PHP code.
|
|
872
|
+
*
|
|
873
|
+
* This low-level method directly interacts with the WebAssembly
|
|
874
|
+
* PHP interpreter.
|
|
875
|
+
*
|
|
876
|
+
* Every time you call run(), it prepares the PHP
|
|
877
|
+
* environment and:
|
|
878
|
+
*
|
|
879
|
+
* * Resets the internal PHP state
|
|
880
|
+
* * Populates superglobals ($_SERVER, $_GET, etc.)
|
|
881
|
+
* * Handles file uploads
|
|
882
|
+
* * Populates input streams (stdin, argv, etc.)
|
|
883
|
+
* * Sets the current working directory
|
|
884
|
+
*
|
|
885
|
+
* You can use run() in two primary modes:
|
|
886
|
+
*
|
|
887
|
+
* ### Code snippet mode
|
|
888
|
+
*
|
|
889
|
+
* In this mode, you pass a string containing PHP code to run.
|
|
890
|
+
*
|
|
891
|
+
* ```ts
|
|
892
|
+
* const result = await php.run({
|
|
893
|
+
* code: `<?php echo "Hello world!";`
|
|
894
|
+
* });
|
|
895
|
+
* // result.text === "Hello world!"
|
|
896
|
+
* ```
|
|
897
|
+
*
|
|
898
|
+
* In this mode, information like __DIR__ or __FILE__ isn't very
|
|
899
|
+
* useful because the code is not associated with any file.
|
|
900
|
+
*
|
|
901
|
+
* Under the hood, the PHP snippet is passed to the `zend_eval_string`
|
|
902
|
+
* C function.
|
|
903
|
+
*
|
|
904
|
+
* ### File mode
|
|
905
|
+
*
|
|
906
|
+
* In the file mode, you pass a scriptPath and PHP executes a file
|
|
907
|
+
* found at a that path:
|
|
908
|
+
*
|
|
909
|
+
* ```ts
|
|
910
|
+
* php.writeFile(
|
|
911
|
+
* "/www/index.php",
|
|
912
|
+
* `<?php echo "Hello world!";"`
|
|
913
|
+
* );
|
|
914
|
+
* const result = await php.run({
|
|
915
|
+
* scriptPath: "/www/index.php"
|
|
916
|
+
* });
|
|
917
|
+
* // result.text === "Hello world!"
|
|
918
|
+
* ```
|
|
919
|
+
*
|
|
920
|
+
* In this mode, you can rely on path-related information like __DIR__
|
|
921
|
+
* or __FILE__.
|
|
922
|
+
*
|
|
923
|
+
* Under the hood, the PHP file is executed with the `php_execute_script`
|
|
924
|
+
* C function.
|
|
925
|
+
*
|
|
926
|
+
* The `run()` method cannot be used in conjunction with `cli()`.
|
|
927
|
+
*
|
|
928
|
+
* @example
|
|
929
|
+
* ```js
|
|
930
|
+
* const result = await php.run(`<?php
|
|
931
|
+
* $fp = fopen('php://stderr', 'w');
|
|
932
|
+
* fwrite($fp, "Hello, world!");
|
|
933
|
+
* `);
|
|
934
|
+
* // result.errors === "Hello, world!"
|
|
935
|
+
* ```
|
|
936
|
+
*
|
|
937
|
+
* @param options - PHP runtime options.
|
|
938
|
+
*/
|
|
939
|
+
run(request: PHPRunOptions): Promise<PHPResponse>;
|
|
940
|
+
/**
|
|
941
|
+
* Defines a constant in the PHP runtime.
|
|
942
|
+
* @param key - The name of the constant.
|
|
943
|
+
* @param value - The value of the constant.
|
|
944
|
+
*/
|
|
945
|
+
defineConstant(key: string, value: string | boolean | number | null): void;
|
|
946
|
+
/**
|
|
947
|
+
* Recursively creates a directory with the given path in the PHP filesystem.
|
|
948
|
+
* For example, if the path is `/root/php/data`, and `/root` already exists,
|
|
949
|
+
* it will create the directories `/root/php` and `/root/php/data`.
|
|
950
|
+
*
|
|
951
|
+
* @param path - The directory path to create.
|
|
952
|
+
*/
|
|
953
|
+
mkdir(path: string): void;
|
|
954
|
+
/**
|
|
955
|
+
* @deprecated Use mkdir instead.
|
|
956
|
+
*/
|
|
957
|
+
mkdirTree(path: string): void;
|
|
958
|
+
/**
|
|
959
|
+
* Reads a file from the PHP filesystem and returns it as a string.
|
|
960
|
+
*
|
|
961
|
+
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
962
|
+
* @param path - The file path to read.
|
|
963
|
+
* @returns The file contents.
|
|
964
|
+
*/
|
|
965
|
+
readFileAsText(path: string): string;
|
|
966
|
+
/**
|
|
967
|
+
* Reads a file from the PHP filesystem and returns it as an array buffer.
|
|
968
|
+
*
|
|
969
|
+
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
970
|
+
* @param path - The file path to read.
|
|
971
|
+
* @returns The file contents.
|
|
972
|
+
*/
|
|
973
|
+
readFileAsBuffer(path: string): Uint8Array;
|
|
974
|
+
/**
|
|
975
|
+
* Overwrites data in a file in the PHP filesystem.
|
|
976
|
+
* Creates a new file if one doesn't exist yet.
|
|
977
|
+
*
|
|
978
|
+
* @param path - The file path to write to.
|
|
979
|
+
* @param data - The data to write to the file.
|
|
980
|
+
*/
|
|
981
|
+
writeFile(path: string, data: string | Uint8Array): void;
|
|
982
|
+
/**
|
|
983
|
+
* Removes a file from the PHP filesystem.
|
|
984
|
+
*
|
|
985
|
+
* @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
|
|
986
|
+
* @param path - The file path to remove.
|
|
987
|
+
*/
|
|
988
|
+
unlink(path: string): void;
|
|
989
|
+
/**
|
|
990
|
+
* Moves a file or directory in the PHP filesystem to a
|
|
991
|
+
* new location.
|
|
992
|
+
*
|
|
993
|
+
* @param oldPath The path to rename.
|
|
994
|
+
* @param newPath The new path.
|
|
995
|
+
*/
|
|
996
|
+
mv(fromPath: string, toPath: string): void;
|
|
997
|
+
/**
|
|
998
|
+
* Removes a directory from the PHP filesystem.
|
|
999
|
+
*
|
|
1000
|
+
* @param path The directory path to remove.
|
|
1001
|
+
* @param options Options for the removal.
|
|
1002
|
+
*/
|
|
1003
|
+
rmdir(path: string, options?: RmDirOptions): void;
|
|
1004
|
+
/**
|
|
1005
|
+
* Lists the files and directories in the given directory.
|
|
1006
|
+
*
|
|
1007
|
+
* @param path - The directory path to list.
|
|
1008
|
+
* @param options - Options for the listing.
|
|
1009
|
+
* @returns The list of files and directories in the given directory.
|
|
1010
|
+
*/
|
|
1011
|
+
listFiles(path: string, options?: ListFilesOptions): string[];
|
|
1012
|
+
/**
|
|
1013
|
+
* Checks if a directory exists in the PHP filesystem.
|
|
1014
|
+
*
|
|
1015
|
+
* @param path – The path to check.
|
|
1016
|
+
* @returns True if the path is a directory, false otherwise.
|
|
1017
|
+
*/
|
|
1018
|
+
isDir(path: string): boolean;
|
|
1019
|
+
/**
|
|
1020
|
+
* Checks if a file (or a directory) exists in the PHP filesystem.
|
|
1021
|
+
*
|
|
1022
|
+
* @param path - The file path to check.
|
|
1023
|
+
* @returns True if the file exists, false otherwise.
|
|
1024
|
+
*/
|
|
1025
|
+
fileExists(path: string): boolean;
|
|
1026
|
+
/**
|
|
1027
|
+
* Hot-swaps the PHP runtime for a new one without
|
|
1028
|
+
* interrupting the operations of this PHP instance.
|
|
1029
|
+
*
|
|
1030
|
+
* @param runtime
|
|
1031
|
+
* @param cwd. Internal, the VFS path to recreate in the new runtime.
|
|
1032
|
+
* This arg is temporary and will be removed once BasePHP
|
|
1033
|
+
* is fully decoupled from the request handler and
|
|
1034
|
+
* accepts a constructor-level cwd argument.
|
|
1035
|
+
*/
|
|
1036
|
+
hotSwapPHPRuntime(runtime: number, cwd?: string): void;
|
|
1037
|
+
/**
|
|
1038
|
+
* Mounts a filesystem to a given path in the PHP filesystem.
|
|
1039
|
+
*
|
|
1040
|
+
* @param virtualFSPath - Where to mount it in the PHP virtual filesystem.
|
|
1041
|
+
* @param mountHandler - The mount handler to use.
|
|
1042
|
+
* @return Unmount function to unmount the filesystem.
|
|
1043
|
+
*/
|
|
1044
|
+
mount(virtualFSPath: string, mountHandler: MountHandler): Promise<UnmountFunction>;
|
|
1045
|
+
/**
|
|
1046
|
+
* Starts a PHP CLI session with given arguments.
|
|
1047
|
+
*
|
|
1048
|
+
* This method can only be used when PHP was compiled with the CLI SAPI
|
|
1049
|
+
* and it cannot be used in conjunction with `run()`.
|
|
1050
|
+
*
|
|
1051
|
+
* Once this method finishes running, the PHP instance is no
|
|
1052
|
+
* longer usable and should be discarded. This is because PHP
|
|
1053
|
+
* internally cleans up all the resources and calls exit().
|
|
1054
|
+
*
|
|
1055
|
+
* @param argv - The arguments to pass to the CLI.
|
|
1056
|
+
* @returns The exit code of the CLI session.
|
|
1057
|
+
*/
|
|
1058
|
+
cli(argv: string[]): Promise<number>;
|
|
1059
|
+
setSkipShebang(shouldSkip: boolean): void;
|
|
1060
|
+
exit(code?: number): void;
|
|
1061
|
+
[Symbol.dispose](): void;
|
|
1062
|
+
}
|
|
1063
|
+
export type LimitedPHPApi = Pick<PHP, "request" | "defineConstant" | "addEventListener" | "removeEventListener" | "mkdir" | "mkdirTree" | "readFileAsText" | "readFileAsBuffer" | "writeFile" | "unlink" | "mv" | "rmdir" | "listFiles" | "isDir" | "fileExists" | "chdir" | "run" | "onMessage"> & {
|
|
1064
|
+
documentRoot: PHP["documentRoot"];
|
|
1065
|
+
absoluteUrl: PHP["absoluteUrl"];
|
|
1066
|
+
};
|
|
1067
|
+
declare class PHPWorker implements LimitedPHPApi {
|
|
1068
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.absoluteUrl */
|
|
1069
|
+
absoluteUrl: string;
|
|
1070
|
+
/** @inheritDoc @php-wasm/universal!RequestHandler.documentRoot */
|
|
1071
|
+
documentRoot: string;
|
|
1072
|
+
/** @inheritDoc */
|
|
1073
|
+
constructor(requestHandler?: PHPRequestHandler, monitor?: EmscriptenDownloadMonitor);
|
|
1074
|
+
__internal_setRequestHandler(requestHandler: PHPRequestHandler): void;
|
|
1075
|
+
/**
|
|
1076
|
+
* @internal
|
|
1077
|
+
* @deprecated
|
|
1078
|
+
* Do not use this method directly in the code consuming
|
|
1079
|
+
* the web API. It will change or even be removed without
|
|
1080
|
+
* a warning.
|
|
1081
|
+
*/
|
|
1082
|
+
protected __internal_getPHP(): PHP | undefined;
|
|
1083
|
+
setPrimaryPHP(php: PHP): Promise<void>;
|
|
1084
|
+
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.pathToInternalUrl */
|
|
1085
|
+
pathToInternalUrl(path: string): string;
|
|
1086
|
+
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.internalUrlToPath */
|
|
1087
|
+
internalUrlToPath(internalUrl: string): string;
|
|
1088
|
+
/**
|
|
1089
|
+
* The onDownloadProgress event listener.
|
|
1090
|
+
*/
|
|
1091
|
+
onDownloadProgress(callback: (progress: CustomEvent<ProgressEvent>) => void): Promise<void>;
|
|
1092
|
+
/** @inheritDoc @php-wasm/universal!PHP.mv */
|
|
1093
|
+
mv(fromPath: string, toPath: string): Promise<void>;
|
|
1094
|
+
/** @inheritDoc @php-wasm/universal!PHP.rmdir */
|
|
1095
|
+
rmdir(path: string, options?: RmDirOptions): Promise<void>;
|
|
1096
|
+
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.request */
|
|
1097
|
+
request(request: PHPRequest): Promise<PHPResponse>;
|
|
1098
|
+
/** @inheritDoc @php-wasm/universal!/PHP.run */
|
|
870
1099
|
run(request: PHPRunOptions): Promise<PHPResponse>;
|
|
871
|
-
|
|
872
|
-
|
|
1100
|
+
/** @inheritDoc @php-wasm/universal!/PHP.chdir */
|
|
1101
|
+
chdir(path: string): void;
|
|
1102
|
+
/** @inheritDoc @php-wasm/universal!/PHP.setSapiName */
|
|
1103
|
+
setSapiName(newName: string): void;
|
|
1104
|
+
/** @inheritDoc @php-wasm/universal!/PHP.mkdir */
|
|
873
1105
|
mkdir(path: string): void;
|
|
874
|
-
/** @inheritDoc */
|
|
1106
|
+
/** @inheritDoc @php-wasm/universal!/PHP.mkdirTree */
|
|
875
1107
|
mkdirTree(path: string): void;
|
|
876
|
-
/** @inheritDoc */
|
|
1108
|
+
/** @inheritDoc @php-wasm/universal!/PHP.readFileAsText */
|
|
877
1109
|
readFileAsText(path: string): string;
|
|
878
|
-
/** @inheritDoc */
|
|
1110
|
+
/** @inheritDoc @php-wasm/universal!/PHP.readFileAsBuffer */
|
|
879
1111
|
readFileAsBuffer(path: string): Uint8Array;
|
|
880
|
-
/** @inheritDoc */
|
|
1112
|
+
/** @inheritDoc @php-wasm/universal!/PHP.writeFile */
|
|
881
1113
|
writeFile(path: string, data: string | Uint8Array): void;
|
|
882
|
-
/** @inheritDoc */
|
|
1114
|
+
/** @inheritDoc @php-wasm/universal!/PHP.unlink */
|
|
883
1115
|
unlink(path: string): void;
|
|
884
|
-
/** @inheritDoc */
|
|
885
|
-
mv(fromPath: string, toPath: string): void;
|
|
886
|
-
/** @inheritDoc */
|
|
887
|
-
rmdir(path: string, options?: RmDirOptions): void;
|
|
888
|
-
/** @inheritDoc */
|
|
1116
|
+
/** @inheritDoc @php-wasm/universal!/PHP.listFiles */
|
|
889
1117
|
listFiles(path: string, options?: ListFilesOptions): string[];
|
|
890
|
-
/** @inheritDoc */
|
|
1118
|
+
/** @inheritDoc @php-wasm/universal!/PHP.isDir */
|
|
891
1119
|
isDir(path: string): boolean;
|
|
892
|
-
/** @inheritDoc */
|
|
1120
|
+
/** @inheritDoc @php-wasm/universal!/PHP.fileExists */
|
|
893
1121
|
fileExists(path: string): boolean;
|
|
894
|
-
/**
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
* accepts a constructor-level cwd argument.
|
|
903
|
-
*/
|
|
904
|
-
hotSwapPHPRuntime(runtime: number, cwd?: string): void;
|
|
905
|
-
exit(code?: number): void;
|
|
906
|
-
[Symbol.dispose](): void;
|
|
1122
|
+
/** @inheritDoc @php-wasm/universal!/PHP.onMessage */
|
|
1123
|
+
onMessage(listener: MessageListener): void;
|
|
1124
|
+
/** @inheritDoc @php-wasm/universal!/PHP.defineConstant */
|
|
1125
|
+
defineConstant(key: string, value: string | boolean | number | null): void;
|
|
1126
|
+
/** @inheritDoc @php-wasm/universal!/PHP.addEventListener */
|
|
1127
|
+
addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
1128
|
+
/** @inheritDoc @php-wasm/universal!/PHP.removeEventListener */
|
|
1129
|
+
removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
907
1130
|
}
|
|
908
|
-
|
|
909
|
-
|
|
1131
|
+
/**
|
|
1132
|
+
* Represents an event related to the PHP request.
|
|
1133
|
+
*/
|
|
1134
|
+
export interface PHPRequestEndEvent {
|
|
1135
|
+
type: "request.end";
|
|
1136
|
+
}
|
|
1137
|
+
/**
|
|
1138
|
+
* Represents an error event related to the PHP request.
|
|
1139
|
+
*/
|
|
1140
|
+
export interface PHPRequestErrorEvent {
|
|
1141
|
+
type: "request.error";
|
|
1142
|
+
error: Error;
|
|
1143
|
+
source?: "request" | "php-wasm";
|
|
1144
|
+
}
|
|
1145
|
+
/**
|
|
1146
|
+
* Represents a PHP runtime initialization event.
|
|
1147
|
+
*/
|
|
1148
|
+
export interface PHPRuntimeInitializedEvent {
|
|
1149
|
+
type: "runtime.initialized";
|
|
1150
|
+
}
|
|
1151
|
+
/**
|
|
1152
|
+
* Represents a PHP runtime destruction event.
|
|
1153
|
+
*/
|
|
1154
|
+
export interface PHPRuntimeBeforeDestroyEvent {
|
|
1155
|
+
type: "runtime.beforedestroy";
|
|
1156
|
+
}
|
|
1157
|
+
/**
|
|
1158
|
+
* Represents an event related to the PHP instance.
|
|
1159
|
+
* This is intentionally not an extension of CustomEvent
|
|
1160
|
+
* to make it isomorphic between different JavaScript runtimes.
|
|
1161
|
+
*/
|
|
1162
|
+
export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
|
|
1163
|
+
/**
|
|
1164
|
+
* A callback function that handles PHP events.
|
|
1165
|
+
*/
|
|
1166
|
+
export type PHPEventListener = (event: PHPEvent) => void;
|
|
1167
|
+
export type UniversalPHP = LimitedPHPApi | Remote<LimitedPHPApi>;
|
|
1168
|
+
export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void;
|
|
1169
|
+
export interface EventEmitter {
|
|
1170
|
+
on(event: string, listener: (...args: any[]) => void): this;
|
|
1171
|
+
emit(event: string, ...args: any[]): boolean;
|
|
1172
|
+
}
|
|
1173
|
+
export type ChildProcess = EventEmitter & {
|
|
1174
|
+
stdout: EventEmitter;
|
|
1175
|
+
stderr: EventEmitter;
|
|
910
1176
|
};
|
|
911
|
-
export type
|
|
912
|
-
export
|
|
1177
|
+
export type SpawnHandler = (command: string, args: string[]) => ChildProcess;
|
|
1178
|
+
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
1179
|
+
export type PHPRequestHeaders = Record<string, string>;
|
|
1180
|
+
export interface PHPRequest {
|
|
913
1181
|
/**
|
|
914
|
-
*
|
|
915
|
-
* the same time.
|
|
1182
|
+
* Request method. Default: `GET`.
|
|
916
1183
|
*/
|
|
917
|
-
|
|
1184
|
+
method?: HTTPMethod;
|
|
918
1185
|
/**
|
|
919
|
-
*
|
|
920
|
-
* we have reached the maximum number of PHP instances and
|
|
921
|
-
* cannot spawn a new one. If the timeout is reached, we assume
|
|
922
|
-
* all the PHP instances are deadlocked and a throw MaxPhpInstancesError.
|
|
923
|
-
*
|
|
924
|
-
* Default: 5000
|
|
1186
|
+
* Request path or absolute URL.
|
|
925
1187
|
*/
|
|
926
|
-
|
|
1188
|
+
url: string;
|
|
927
1189
|
/**
|
|
928
|
-
*
|
|
929
|
-
* contains the reference filesystem used by all other PHP instances.
|
|
1190
|
+
* Request headers.
|
|
930
1191
|
*/
|
|
931
|
-
|
|
1192
|
+
headers?: PHPRequestHeaders;
|
|
932
1193
|
/**
|
|
933
|
-
*
|
|
1194
|
+
* Request body.
|
|
1195
|
+
* If an object is given, the request will be encoded as multipart
|
|
1196
|
+
* and sent with a `multipart/form-data` header.
|
|
934
1197
|
*/
|
|
935
|
-
|
|
936
|
-
}
|
|
937
|
-
export interface SpawnedPHP<PHP extends BasePHP> {
|
|
938
|
-
php: PHP;
|
|
939
|
-
reap: () => void;
|
|
1198
|
+
body?: string | Uint8Array | Record<string, string | Uint8Array | File>;
|
|
940
1199
|
}
|
|
941
|
-
|
|
942
|
-
private primaryPhp?;
|
|
943
|
-
private primaryIdle;
|
|
944
|
-
private nextInstance;
|
|
1200
|
+
export interface PHPRunOptions {
|
|
945
1201
|
/**
|
|
946
|
-
*
|
|
947
|
-
* Used for bookkeeping and reaping all instances on dispose.
|
|
1202
|
+
* Request path following the domain:port part.
|
|
948
1203
|
*/
|
|
949
|
-
|
|
950
|
-
private phpFactory?;
|
|
951
|
-
private maxPhpInstances;
|
|
952
|
-
private semaphore;
|
|
953
|
-
constructor(options?: ProcessManagerOptions<PHP>);
|
|
1204
|
+
relativeUri?: string;
|
|
954
1205
|
/**
|
|
955
|
-
*
|
|
956
|
-
*
|
|
957
|
-
* If the primary PHP instance is not set, it will be spawned
|
|
958
|
-
* using the provided phpFactory.
|
|
959
|
-
*
|
|
960
|
-
* @throws {Error} when called twice before the first call is resolved.
|
|
1206
|
+
* Path of the .php file to execute.
|
|
961
1207
|
*/
|
|
962
|
-
|
|
1208
|
+
scriptPath?: string;
|
|
963
1209
|
/**
|
|
964
|
-
*
|
|
965
|
-
*
|
|
966
|
-
* It could be either the primary PHP instance, an idle disposable PHP instance,
|
|
967
|
-
* or a newly spawned PHP instance – depending on the resource availability.
|
|
968
|
-
*
|
|
969
|
-
* @throws {MaxPhpInstancesError} when the maximum number of PHP instances is reached
|
|
970
|
-
* and the waiting timeout is exceeded.
|
|
1210
|
+
* Request protocol.
|
|
971
1211
|
*/
|
|
972
|
-
|
|
1212
|
+
protocol?: string;
|
|
973
1213
|
/**
|
|
974
|
-
*
|
|
975
|
-
* This function is synchronous on purpose – it needs to synchronously
|
|
976
|
-
* add the spawn promise to the allInstances array without waiting
|
|
977
|
-
* for PHP to spawn.
|
|
1214
|
+
* Request method. Default: `GET`.
|
|
978
1215
|
*/
|
|
979
|
-
|
|
1216
|
+
method?: HTTPMethod;
|
|
980
1217
|
/**
|
|
981
|
-
*
|
|
1218
|
+
* Request headers.
|
|
982
1219
|
*/
|
|
983
|
-
|
|
984
|
-
|
|
1220
|
+
headers?: PHPRequestHeaders;
|
|
1221
|
+
/**
|
|
1222
|
+
* Request body.
|
|
1223
|
+
*/
|
|
1224
|
+
body?: string | Uint8Array;
|
|
1225
|
+
/**
|
|
1226
|
+
* Environment variables to set for this run.
|
|
1227
|
+
*/
|
|
1228
|
+
env?: Record<string, string>;
|
|
1229
|
+
/**
|
|
1230
|
+
* $_SERVER entries to set for this run.
|
|
1231
|
+
*/
|
|
1232
|
+
$_SERVER?: Record<string, string>;
|
|
1233
|
+
/**
|
|
1234
|
+
* The code snippet to eval instead of a php file.
|
|
1235
|
+
*/
|
|
1236
|
+
code?: string;
|
|
1237
|
+
}
|
|
1238
|
+
/**
|
|
1239
|
+
* Output of the PHP.wasm runtime.
|
|
1240
|
+
*/
|
|
1241
|
+
export interface PHPOutput {
|
|
1242
|
+
/** Exit code of the PHP process. 0 means success, 1 and 2 mean error. */
|
|
1243
|
+
exitCode: number;
|
|
1244
|
+
/** Stdout data */
|
|
1245
|
+
stdout: ArrayBuffer;
|
|
1246
|
+
/** Stderr lines */
|
|
1247
|
+
stderr: string[];
|
|
985
1248
|
}
|
|
1249
|
+
/**
|
|
1250
|
+
* Rewrites the php.ini file with the given entries.
|
|
1251
|
+
*
|
|
1252
|
+
* @param php The PHP instance.
|
|
1253
|
+
* @param entries The entries to write to the php.ini file.
|
|
1254
|
+
*/
|
|
1255
|
+
export declare function setPhpIniEntries(php: UniversalPHP, entries: Record<string, unknown>): Promise<void>;
|
|
986
1256
|
/**
|
|
987
1257
|
* Emscripten's filesystem-related Exception.
|
|
988
1258
|
*
|
|
@@ -1253,10 +1523,10 @@ export interface DefineSiteUrlStep {
|
|
|
1253
1523
|
siteUrl: string;
|
|
1254
1524
|
}
|
|
1255
1525
|
/**
|
|
1256
|
-
* Sets WP_HOME and WP_SITEURL constants for the WordPress installation.
|
|
1526
|
+
* Sets [`WP_HOME`](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#blog-address-url) and [`WP_SITEURL`](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/#wp-siteurl) constants for the WordPress installation.
|
|
1257
1527
|
*
|
|
1258
|
-
*
|
|
1259
|
-
* It is useful when
|
|
1528
|
+
* Using this step on playground.wordpress.net is moot.
|
|
1529
|
+
* It is useful when building a custom Playground-based tool, like [`wp-now`](https://www.npmjs.com/package/@wp-now/wp-now),
|
|
1260
1530
|
* or deploying Playground on a custom domain.
|
|
1261
1531
|
*
|
|
1262
1532
|
* @param playground The playground client.
|
|
@@ -1407,8 +1677,8 @@ export type LoginStep = {
|
|
|
1407
1677
|
password?: string;
|
|
1408
1678
|
};
|
|
1409
1679
|
/**
|
|
1410
|
-
* Logs in to
|
|
1411
|
-
* Under the hood, this function submits the wp-login.php form
|
|
1680
|
+
* Logs in to Playground.
|
|
1681
|
+
* Under the hood, this function submits the [`wp-login.php`](https://developer.wordpress.org/reference/files/wp-login.php/) [form](https://developer.wordpress.org/reference/functions/wp_login_form/)
|
|
1412
1682
|
* just like a user would.
|
|
1413
1683
|
*/
|
|
1414
1684
|
export declare const login: StepHandler<LoginStep>;
|
|
@@ -1453,8 +1723,8 @@ export type SetSiteOptionsStep = {
|
|
|
1453
1723
|
options: Record<string, unknown>;
|
|
1454
1724
|
};
|
|
1455
1725
|
/**
|
|
1456
|
-
* Sets site options. This is equivalent to calling `update_option` for each
|
|
1457
|
-
* option in the `options` object.
|
|
1726
|
+
* Sets site options. This is equivalent to calling [`update_option`](https://developer.wordpress.org/reference/functions/update_option/) for each
|
|
1727
|
+
* option in the [`options`](https://developer.wordpress.org/apis/options/#available-options-by-category) object.
|
|
1458
1728
|
*/
|
|
1459
1729
|
export declare const setSiteOptions: StepHandler<SetSiteOptionsStep>;
|
|
1460
1730
|
/**
|
|
@@ -1482,7 +1752,7 @@ export interface UpdateUserMetaStep {
|
|
|
1482
1752
|
userId: number;
|
|
1483
1753
|
}
|
|
1484
1754
|
/**
|
|
1485
|
-
* Updates user meta. This is equivalent to calling `update_user_meta` for each
|
|
1755
|
+
* Updates user meta. This is equivalent to calling [`update_user_meta`](https://developer.wordpress.org/reference/functions/update_user_meta/) for each
|
|
1486
1756
|
* meta value in the `meta` object.
|
|
1487
1757
|
*/
|
|
1488
1758
|
export declare const updateUserMeta: StepHandler<UpdateUserMetaStep>;
|
|
@@ -1655,6 +1925,7 @@ export interface RunPHPStep {
|
|
|
1655
1925
|
}
|
|
1656
1926
|
/**
|
|
1657
1927
|
* Runs PHP code.
|
|
1928
|
+
* When running WordPress functions, the `code` key must first load [`wp-load.php`](https://github.com/WordPress/WordPress/blob/master/wp-load.php) and start with `"<?php require_once 'wordpress/wp-load.php'; "`.
|
|
1658
1929
|
*/
|
|
1659
1930
|
export declare const runPHP: StepHandler<RunPHPStep, Promise<PHPResponse>>;
|
|
1660
1931
|
/**
|
|
@@ -1677,7 +1948,7 @@ export declare const runPHP: StepHandler<RunPHPStep, Promise<PHPResponse>>;
|
|
|
1677
1948
|
export interface RunPHPWithOptionsStep {
|
|
1678
1949
|
step: "runPHPWithOptions";
|
|
1679
1950
|
/**
|
|
1680
|
-
* Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions)
|
|
1951
|
+
* Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions/))
|
|
1681
1952
|
*/
|
|
1682
1953
|
options: PHPRunOptions;
|
|
1683
1954
|
}
|
|
@@ -1714,7 +1985,7 @@ export interface RequestStep {
|
|
|
1714
1985
|
request: PHPRequest;
|
|
1715
1986
|
}
|
|
1716
1987
|
/**
|
|
1717
|
-
* Sends a HTTP request to
|
|
1988
|
+
* Sends a HTTP request to Playground.
|
|
1718
1989
|
*/
|
|
1719
1990
|
export declare const request: StepHandler<RequestStep, Promise<PHPResponse>>;
|
|
1720
1991
|
/**
|
|
@@ -1761,13 +2032,14 @@ export interface DefineWpConfigConstsStep {
|
|
|
1761
2032
|
/** The constants to define */
|
|
1762
2033
|
consts: Record<string, unknown>;
|
|
1763
2034
|
/**
|
|
1764
|
-
* The method of defining the constants. Possible values are:
|
|
2035
|
+
* The method of defining the constants in wp-config.php. Possible values are:
|
|
1765
2036
|
*
|
|
1766
2037
|
* - rewrite-wp-config: Default. Rewrites the wp-config.php file to
|
|
1767
2038
|
* explicitly call define() with the requested
|
|
1768
2039
|
* name and value. This method alters the file
|
|
1769
2040
|
* on the disk, but it doesn't conflict with
|
|
1770
2041
|
* existing define() calls in wp-config.php.
|
|
2042
|
+
*
|
|
1771
2043
|
* - define-before-run: Defines the constant before running the requested
|
|
1772
2044
|
* script. It doesn't alter any files on the disk, but
|
|
1773
2045
|
* constants defined this way may conflict with existing
|
|
@@ -1782,7 +2054,7 @@ export interface DefineWpConfigConstsStep {
|
|
|
1782
2054
|
virtualize?: boolean;
|
|
1783
2055
|
}
|
|
1784
2056
|
/**
|
|
1785
|
-
* Defines constants in a wp-config.php file.
|
|
2057
|
+
* Defines constants in a [`wp-config.php`](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/) file.
|
|
1786
2058
|
*
|
|
1787
2059
|
* This step can be called multiple times, and the constants will be merged.
|
|
1788
2060
|
*
|
|
@@ -1878,9 +2150,9 @@ export interface ImportWordPressFilesStep<ResourceType> {
|
|
|
1878
2150
|
}
|
|
1879
2151
|
/**
|
|
1880
2152
|
* Imports top-level WordPress files from a given zip file into
|
|
1881
|
-
* the documentRoot
|
|
2153
|
+
* the `documentRoot`. For example, if a zip file contains the
|
|
1882
2154
|
* `wp-content` and `wp-includes` directories, they will replace
|
|
1883
|
-
* the corresponding directories in Playground's documentRoot
|
|
2155
|
+
* the corresponding directories in Playground's `documentRoot`.
|
|
1884
2156
|
*
|
|
1885
2157
|
* Any files that Playground recognizes as "excluded from the export"
|
|
1886
2158
|
* will carry over from the existing document root into the imported
|
|
@@ -1931,7 +2203,7 @@ export interface EnableMultisiteStep {
|
|
|
1931
2203
|
step: "enableMultisite";
|
|
1932
2204
|
}
|
|
1933
2205
|
/**
|
|
1934
|
-
* Defines constants in a wp-config.php file.
|
|
2206
|
+
* Defines the [Multisite](https://developer.wordpress.org/advanced-administration/multisite/create-network/) constants in a `wp-config.php` file.
|
|
1935
2207
|
*
|
|
1936
2208
|
* This step can be called multiple times, and the constants will be merged.
|
|
1937
2209
|
*
|
|
@@ -1960,9 +2232,31 @@ export interface WPCLIStep {
|
|
|
1960
2232
|
wpCliPath?: string;
|
|
1961
2233
|
}
|
|
1962
2234
|
/**
|
|
1963
|
-
* Runs PHP code.
|
|
2235
|
+
* Runs PHP code using [WP-CLI](https://developer.wordpress.org/cli/commands/).
|
|
1964
2236
|
*/
|
|
1965
2237
|
export declare const wpCLI: StepHandler<WPCLIStep, Promise<PHPResponse>>;
|
|
2238
|
+
/**
|
|
2239
|
+
* Deletes WordPress posts and comments and sets the auto increment sequence for the
|
|
2240
|
+
* posts and comments tables to 0.
|
|
2241
|
+
*
|
|
2242
|
+
* @private
|
|
2243
|
+
* @internal
|
|
2244
|
+
* @inheritDoc resetData
|
|
2245
|
+
* @example
|
|
2246
|
+
*
|
|
2247
|
+
* <code>
|
|
2248
|
+
* {
|
|
2249
|
+
* "step": "resetData"
|
|
2250
|
+
* }
|
|
2251
|
+
* </code>
|
|
2252
|
+
*/
|
|
2253
|
+
export interface ResetDataStep {
|
|
2254
|
+
step: "resetData";
|
|
2255
|
+
}
|
|
2256
|
+
/**
|
|
2257
|
+
* @param playground Playground client.
|
|
2258
|
+
*/
|
|
2259
|
+
export declare const resetData: StepHandler<ResetDataStep>;
|
|
1966
2260
|
/**
|
|
1967
2261
|
* Used by the export step to exclude the Playground-specific files
|
|
1968
2262
|
* from the zip file. Keep it in sync with the list of files created
|
|
@@ -1980,7 +2274,7 @@ export type StepDefinition = Step & {
|
|
|
1980
2274
|
* If you add a step here, make sure to also
|
|
1981
2275
|
* add it to the exports below.
|
|
1982
2276
|
*/
|
|
1983
|
-
export type GenericStep<Resource> = ActivatePluginStep | ActivateThemeStep | CpStep | DefineWpConfigConstsStep | DefineSiteUrlStep | EnableMultisiteStep | ImportWxrStep<Resource> | ImportWordPressFilesStep<Resource> | InstallPluginStep<Resource> | InstallThemeStep<Resource> | LoginStep | MkdirStep | MvStep | RequestStep | RmStep | RmdirStep | RunPHPStep | RunPHPWithOptionsStep | RunWpInstallationWizardStep | RunSqlStep<Resource> | SetSiteOptionsStep | UnzipStep<Resource> | UpdateUserMetaStep | WriteFileStep<Resource> | WPCLIStep;
|
|
2277
|
+
export type GenericStep<Resource> = ActivatePluginStep | ActivateThemeStep | CpStep | DefineWpConfigConstsStep | DefineSiteUrlStep | EnableMultisiteStep | ImportWxrStep<Resource> | ImportWordPressFilesStep<Resource> | InstallPluginStep<Resource> | InstallThemeStep<Resource> | LoginStep | MkdirStep | MvStep | ResetDataStep | RequestStep | RmStep | RmdirStep | RunPHPStep | RunPHPWithOptionsStep | RunWpInstallationWizardStep | RunSqlStep<Resource> | SetSiteOptionsStep | UnzipStep<Resource> | UpdateUserMetaStep | WriteFileStep<Resource> | WPCLIStep;
|
|
1984
2278
|
/**
|
|
1985
2279
|
* Progress reporting details.
|
|
1986
2280
|
*/
|
|
@@ -2161,94 +2455,11 @@ export type WithAPIState = {
|
|
|
2161
2455
|
isReady: () => Promise<void>;
|
|
2162
2456
|
};
|
|
2163
2457
|
export type RemoteAPI<T> = Comlink.Remote<T> & WithAPIState;
|
|
2164
|
-
export interface
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
}
|
|
2170
|
-
declare class WebPHP extends BasePHP {
|
|
2171
|
-
/**
|
|
2172
|
-
* Creates a new PHP instance.
|
|
2173
|
-
*
|
|
2174
|
-
* Dynamically imports the PHP module, initializes the runtime,
|
|
2175
|
-
* and sets up networking. It's a shorthand for the lower-level
|
|
2176
|
-
* functions like `getPHPLoaderModule`, `loadPHPRuntime`, and
|
|
2177
|
-
* `PHP.initializeRuntime`
|
|
2178
|
-
*
|
|
2179
|
-
* @param phpVersion The PHP Version to load
|
|
2180
|
-
* @param options The options to use when loading PHP
|
|
2181
|
-
* @returns A new PHP instance
|
|
2182
|
-
*/
|
|
2183
|
-
static load(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): Promise<WebPHP>;
|
|
2184
|
-
static loadRuntime(phpVersion: SupportedPHPVersion, options?: PHPWebLoaderOptions): Promise<number>;
|
|
2185
|
-
}
|
|
2186
|
-
declare class WebPHPEndpoint implements Omit<IsomorphicLocalPHP, "setSapiName" | "setPhpIniEntry" | "setPhpIniPath"> {
|
|
2187
|
-
/** @inheritDoc @php-wasm/universal!RequestHandler.absoluteUrl */
|
|
2188
|
-
absoluteUrl: string;
|
|
2189
|
-
/** @inheritDoc @php-wasm/universal!RequestHandler.documentRoot */
|
|
2190
|
-
documentRoot: string;
|
|
2191
|
-
/** @inheritDoc */
|
|
2192
|
-
constructor(requestHandler: PHPRequestHandler<WebPHP>, monitor?: EmscriptenDownloadMonitor);
|
|
2193
|
-
/**
|
|
2194
|
-
* @internal
|
|
2195
|
-
* @deprecated
|
|
2196
|
-
* Do not use this method directly in the code consuming
|
|
2197
|
-
* the web API. It will change or even be removed without
|
|
2198
|
-
* a warning.
|
|
2199
|
-
*/
|
|
2200
|
-
protected __internal_getPHP(): WebPHP | undefined;
|
|
2201
|
-
setPrimaryPHP(php: WebPHP): Promise<void>;
|
|
2202
|
-
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.pathToInternalUrl */
|
|
2203
|
-
pathToInternalUrl(path: string): string;
|
|
2204
|
-
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.internalUrlToPath */
|
|
2205
|
-
internalUrlToPath(internalUrl: string): string;
|
|
2206
|
-
/**
|
|
2207
|
-
* The onDownloadProgress event listener.
|
|
2208
|
-
*/
|
|
2209
|
-
onDownloadProgress(callback: (progress: CustomEvent<ProgressEvent>) => void): Promise<void>;
|
|
2210
|
-
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.mv */
|
|
2211
|
-
mv(fromPath: string, toPath: string): Promise<void>;
|
|
2212
|
-
/** @inheritDoc @php-wasm/universal!IsomorphicLocalPHP.rmdir */
|
|
2213
|
-
rmdir(path: string, options?: RmDirOptions): Promise<void>;
|
|
2214
|
-
/** @inheritDoc @php-wasm/universal!PHPRequestHandler.request */
|
|
2215
|
-
request(request: PHPRequest): Promise<PHPResponse>;
|
|
2216
|
-
/** @inheritDoc @php-wasm/web!WebPHP.run */
|
|
2217
|
-
run(request: PHPRunOptions): Promise<PHPResponse>;
|
|
2218
|
-
/** @inheritDoc @php-wasm/web!WebPHP.chdir */
|
|
2219
|
-
chdir(path: string): void;
|
|
2220
|
-
/** @inheritDoc @php-wasm/web!WebPHP.setSapiName */
|
|
2221
|
-
setSapiName(newName: string): void;
|
|
2222
|
-
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniPath */
|
|
2223
|
-
setPhpIniPath(path: string): void;
|
|
2224
|
-
/** @inheritDoc @php-wasm/web!WebPHP.setPhpIniEntry */
|
|
2225
|
-
setPhpIniEntry(key: string, value: string): void;
|
|
2226
|
-
/** @inheritDoc @php-wasm/web!WebPHP.mkdir */
|
|
2227
|
-
mkdir(path: string): void;
|
|
2228
|
-
/** @inheritDoc @php-wasm/web!WebPHP.mkdirTree */
|
|
2229
|
-
mkdirTree(path: string): void;
|
|
2230
|
-
/** @inheritDoc @php-wasm/web!WebPHP.readFileAsText */
|
|
2231
|
-
readFileAsText(path: string): string;
|
|
2232
|
-
/** @inheritDoc @php-wasm/web!WebPHP.readFileAsBuffer */
|
|
2233
|
-
readFileAsBuffer(path: string): Uint8Array;
|
|
2234
|
-
/** @inheritDoc @php-wasm/web!WebPHP.writeFile */
|
|
2235
|
-
writeFile(path: string, data: string | Uint8Array): void;
|
|
2236
|
-
/** @inheritDoc @php-wasm/web!WebPHP.unlink */
|
|
2237
|
-
unlink(path: string): void;
|
|
2238
|
-
/** @inheritDoc @php-wasm/web!WebPHP.listFiles */
|
|
2239
|
-
listFiles(path: string, options?: ListFilesOptions): string[];
|
|
2240
|
-
/** @inheritDoc @php-wasm/web!WebPHP.isDir */
|
|
2241
|
-
isDir(path: string): boolean;
|
|
2242
|
-
/** @inheritDoc @php-wasm/web!WebPHP.fileExists */
|
|
2243
|
-
fileExists(path: string): boolean;
|
|
2244
|
-
/** @inheritDoc @php-wasm/web!WebPHP.onMessage */
|
|
2245
|
-
onMessage(listener: MessageListener): void;
|
|
2246
|
-
/** @inheritDoc @php-wasm/web!WebPHP.defineConstant */
|
|
2247
|
-
defineConstant(key: string, value: string | boolean | number | null): void;
|
|
2248
|
-
/** @inheritDoc @php-wasm/web!WebPHP.addEventListener */
|
|
2249
|
-
addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
2250
|
-
/** @inheritDoc @php-wasm/web!WebPHP.removeEventListener */
|
|
2251
|
-
removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
|
|
2458
|
+
export interface MountOptions {
|
|
2459
|
+
initialSync: {
|
|
2460
|
+
direction?: "opfs-to-memfs" | "memfs-to-opfs";
|
|
2461
|
+
onProgress?: SyncProgressCallback;
|
|
2462
|
+
};
|
|
2252
2463
|
}
|
|
2253
2464
|
export type SyncProgress = {
|
|
2254
2465
|
/** The number of files that have been synced. */
|
|
@@ -2257,6 +2468,13 @@ export type SyncProgress = {
|
|
|
2257
2468
|
total: number;
|
|
2258
2469
|
};
|
|
2259
2470
|
export type SyncProgressCallback = (progress: SyncProgress) => void;
|
|
2471
|
+
export type BindOpfsOptions = {
|
|
2472
|
+
php: PHP;
|
|
2473
|
+
opfs: FileSystemDirectoryHandle;
|
|
2474
|
+
initialSyncDirection?: MountOptions["initialSync"]["direction"];
|
|
2475
|
+
onProgress?: SyncProgressCallback;
|
|
2476
|
+
mountpoint: string;
|
|
2477
|
+
};
|
|
2260
2478
|
/**
|
|
2261
2479
|
* Represents the type of node in PHP file system.
|
|
2262
2480
|
*/
|
|
@@ -2306,22 +2524,26 @@ export type RenameOperation = {
|
|
|
2306
2524
|
nodeType: FSNodeType;
|
|
2307
2525
|
};
|
|
2308
2526
|
export type FilesystemOperation = CreateOperation | UpdateFileOperation | DeleteOperation | RenameOperation;
|
|
2309
|
-
declare class PlaygroundWorkerEndpoint extends
|
|
2527
|
+
declare class PlaygroundWorkerEndpoint extends PHPWorker {
|
|
2310
2528
|
/**
|
|
2311
2529
|
* A string representing the scope of the Playground instance.
|
|
2312
2530
|
*/
|
|
2313
2531
|
scope: string;
|
|
2314
2532
|
/**
|
|
2315
|
-
* A string representing the version of WordPress
|
|
2533
|
+
* A string representing the requested version of WordPress.
|
|
2534
|
+
*/
|
|
2535
|
+
requestedWordPressVersion: string;
|
|
2536
|
+
/**
|
|
2537
|
+
* A string representing the version of WordPress that was loaded.
|
|
2316
2538
|
*/
|
|
2317
|
-
|
|
2318
|
-
constructor(
|
|
2539
|
+
loadedWordPressVersion: string | undefined;
|
|
2540
|
+
constructor(monitor: EmscriptenDownloadMonitor, scope: string, requestedWordPressVersion: string);
|
|
2319
2541
|
/**
|
|
2320
2542
|
* @returns WordPress module details, including the static assets directory and default theme.
|
|
2321
2543
|
*/
|
|
2322
2544
|
getWordPressModuleDetails(): Promise<{
|
|
2323
2545
|
majorVersion: string;
|
|
2324
|
-
staticAssetsDirectory: string;
|
|
2546
|
+
staticAssetsDirectory: string | undefined;
|
|
2325
2547
|
}>;
|
|
2326
2548
|
getSupportedWordPressVersions(): Promise<{
|
|
2327
2549
|
all: {
|
|
@@ -2331,13 +2553,12 @@ declare class PlaygroundWorkerEndpoint extends WebPHPEndpoint {
|
|
|
2331
2553
|
"6.4": string;
|
|
2332
2554
|
"6.3": string;
|
|
2333
2555
|
"6.2": string;
|
|
2334
|
-
"6.1": string;
|
|
2335
2556
|
};
|
|
2336
2557
|
latest: string;
|
|
2337
2558
|
}>;
|
|
2338
2559
|
resetVirtualOpfs(): Promise<void>;
|
|
2339
2560
|
reloadFilesFromOpfs(): Promise<void>;
|
|
2340
|
-
bindOpfs(
|
|
2561
|
+
bindOpfs(options: Omit<BindOpfsOptions, "php" | "onProgress">, onProgress?: SyncProgressCallback): Promise<void>;
|
|
2341
2562
|
journalFSEvents(root: string, callback: (op: FilesystemOperation) => void): Promise<() => any>;
|
|
2342
2563
|
replayFSJournal(events: FilesystemOperation[]): Promise<void>;
|
|
2343
2564
|
}
|
|
@@ -2386,7 +2607,7 @@ export interface WebClientMixin extends ProgressReceiver {
|
|
|
2386
2607
|
removeEventListener: PlaygroundWorkerEndpoint["removeEventListener"];
|
|
2387
2608
|
/** @inheritDoc @php-wasm/universal!UniversalPHP.onMessage */
|
|
2388
2609
|
onMessage: PlaygroundWorkerEndpoint["onMessage"];
|
|
2389
|
-
bindOpfs(
|
|
2610
|
+
bindOpfs(options: Omit<BindOpfsOptions, "php" | "onProgress">, onProgress?: SyncProgressCallback): Promise<void>;
|
|
2390
2611
|
}
|
|
2391
2612
|
/**
|
|
2392
2613
|
* The Playground Client interface.
|
|
@@ -2414,6 +2635,15 @@ export interface StartPlaygroundOptions {
|
|
|
2414
2635
|
* @private
|
|
2415
2636
|
*/
|
|
2416
2637
|
sapiName?: string;
|
|
2638
|
+
/**
|
|
2639
|
+
* Called before the blueprint steps are run,
|
|
2640
|
+
* allows the caller to delay the Blueprint execution
|
|
2641
|
+
* once the Playground is booted.
|
|
2642
|
+
*
|
|
2643
|
+
* @returns
|
|
2644
|
+
*/
|
|
2645
|
+
onBeforeBlueprint?: () => Promise<void>;
|
|
2646
|
+
siteSlug?: string;
|
|
2417
2647
|
}
|
|
2418
2648
|
/**
|
|
2419
2649
|
* Loads playground in iframe and returns a PlaygroundClient instance.
|
|
@@ -2422,7 +2652,7 @@ export interface StartPlaygroundOptions {
|
|
|
2422
2652
|
* @param options Options for loading the playground.
|
|
2423
2653
|
* @returns A PlaygroundClient instance.
|
|
2424
2654
|
*/
|
|
2425
|
-
export declare function startPlaygroundWeb({ iframe, blueprint, remoteUrl, progressTracker, disableProgressBar, onBlueprintStepCompleted, onClientConnected, sapiName, }: StartPlaygroundOptions): Promise<PlaygroundClient>;
|
|
2655
|
+
export declare function startPlaygroundWeb({ iframe, blueprint, remoteUrl, progressTracker, disableProgressBar, onBlueprintStepCompleted, onClientConnected, sapiName, onBeforeBlueprint, siteSlug, }: StartPlaygroundOptions): Promise<PlaygroundClient>;
|
|
2426
2656
|
/**
|
|
2427
2657
|
* @deprecated Use `startPlayground` instead.
|
|
2428
2658
|
*
|