@wp-playground/blueprints 0.9.18 → 0.9.20

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.d.ts CHANGED
@@ -1,2280 +1,12 @@
1
- // Generated by dts-bundle-generator v7.2.0
2
-
3
- import { Remote } from 'comlink';
4
-
5
- /**
6
- * Options for customizing the progress tracker.
7
- */
8
- export interface ProgressTrackerOptions {
9
- /** The weight of the progress, a number between 0 and 1. */
10
- weight?: number;
11
- /** The caption to display during progress, a string. */
12
- caption?: string;
13
- /** The time in milliseconds to fill the progress, a number. */
14
- fillTime?: number;
15
- }
16
- /**
17
- * Custom event providing information about a loading process.
18
- */
19
- export type LoadingEvent = CustomEvent<{
20
- /** The number representing how much was loaded. */
21
- loaded: number;
22
- /** The number representing how much needs to loaded in total. */
23
- total: number;
24
- }>;
25
- /**
26
- * Custom event providing progress details.
27
- */
28
- export type ProgressTrackerEvent = CustomEvent<ProgressDetails>;
29
- export interface ProgressDetails {
30
- /** The progress percentage as a number between 0 and 100. */
31
- progress: number;
32
- /** The caption to display during progress, a string. */
33
- caption: string;
34
- }
35
- /**
36
- * ProgressObserver A function that receives progress updates.
37
- *
38
- * @param progress The progress percentage as a number between 0 and 100.
39
- */
40
- export type ProgressObserver = (progress: number) => void;
41
- /**
42
- * Listener A function for handling specific event types.
43
- *
44
- * @param event The event of type T.
45
- */
46
- export type Listener<T> = (event: T) => void;
47
- export type TSCompatibleListener<T> = EventListenerOrEventListenerObject | null | Listener<T>;
48
- export interface ProgressReceiver {
49
- setProgress(details: ProgressDetails): any;
50
- setLoaded(): any;
51
- }
52
- declare class ProgressTracker extends EventTarget {
53
- private _selfWeight;
54
- private _selfDone;
55
- private _selfProgress;
56
- private _selfCaption;
57
- private _weight;
58
- private _progressObserver?;
59
- private _loadingListener?;
60
- private _isFilling;
61
- private _fillTime;
62
- private _fillInterval?;
63
- private _subTrackers;
64
- constructor({ weight, caption, fillTime, }?: ProgressTrackerOptions);
65
- /**
66
- * Creates a new sub-tracker with a specific weight.
67
- *
68
- * The weight determines what percentage of the overall progress
69
- * the sub-tracker represents. For example, if the main tracker is
70
- * monitoring a process that has two stages, and the first stage
71
- * is expected to take twice as long as the second stage, you could
72
- * create the first sub-tracker with a weight of 0.67 and the second
73
- * sub-tracker with a weight of 0.33.
74
- *
75
- * The caption is an optional string that describes the current stage
76
- * of the operation. If provided, it will be used as the progress caption
77
- * for the sub-tracker. If not provided, the main tracker will look for
78
- * the next sub-tracker with a non-empty caption and use that as the progress
79
- * caption instead.
80
- *
81
- * Returns the newly-created sub-tracker.
82
- *
83
- * @throws {Error} If the weight of the new stage would cause the total weight of all stages to exceed 1.
84
- *
85
- * @param weight The weight of the new stage, as a decimal value between 0 and 1.
86
- * @param caption The caption for the new stage, which will be used as the progress caption for the sub-tracker.
87
- *
88
- * @example
89
- * ```ts
90
- * const tracker = new ProgressTracker();
91
- * const subTracker1 = tracker.stage(0.67, 'Slow stage');
92
- * const subTracker2 = tracker.stage(0.33, 'Fast stage');
93
- *
94
- * subTracker2.set(50);
95
- * subTracker1.set(75);
96
- * subTracker2.set(100);
97
- * subTracker1.set(100);
98
- * ```
99
- */
100
- stage(weight?: number, caption?: string): ProgressTracker;
101
- /**
102
- * Fills the progress bar slowly over time, simulating progress.
103
- *
104
- * The progress bar is filled in a 100 steps, and each step, the progress
105
- * is increased by 1. If `stopBeforeFinishing` is true, the progress bar
106
- * will stop filling when it reaches 99% so that you can call `finish()`
107
- * explicitly.
108
- *
109
- * If the progress bar is filling or already filled, this method does nothing.
110
- *
111
- * @example
112
- * ```ts
113
- * const progress = new ProgressTracker({ caption: 'Processing...' });
114
- * progress.fillSlowly();
115
- * ```
116
- *
117
- * @param options Optional options.
118
- */
119
- fillSlowly({ stopBeforeFinishing }?: {
120
- stopBeforeFinishing?: boolean | undefined;
121
- }): void;
122
- set(value: number): void;
123
- finish(): void;
124
- get caption(): string;
125
- setCaption(caption: string): void;
126
- get done(): boolean;
127
- get progress(): number;
128
- get weight(): number;
129
- get observer(): ProgressObserver;
130
- get loadingListener(): Listener<LoadingEvent>;
131
- pipe(receiver: ProgressReceiver): void;
132
- addEventListener(type: string, listener: TSCompatibleListener<ProgressTrackerEvent>): void;
133
- removeEventListener(type: string, listener: TSCompatibleListener<ProgressTrackerEvent>): void;
134
- private notifyProgress;
135
- private notifyDone;
136
- }
137
- export interface PHPResponseData {
138
- /**
139
- * Response headers.
140
- */
141
- readonly headers: Record<string, string[]>;
142
- /**
143
- * Response body. Contains the output from `echo`,
144
- * `print`, inline HTML etc.
145
- */
146
- readonly bytes: ArrayBuffer;
147
- /**
148
- * Stderr contents, if any.
149
- */
150
- readonly errors: string;
151
- /**
152
- * The exit code of the script. `0` is a success, while
153
- * `1` and `2` indicate an error.
154
- */
155
- readonly exitCode: number;
156
- /**
157
- * Response HTTP status code, e.g. 200.
158
- */
159
- readonly httpStatusCode: number;
160
- }
161
- declare class PHPResponse implements PHPResponseData {
162
- /** @inheritDoc */
163
- readonly headers: Record<string, string[]>;
164
- /** @inheritDoc */
165
- readonly bytes: ArrayBuffer;
166
- /** @inheritDoc */
167
- readonly errors: string;
168
- /** @inheritDoc */
169
- readonly exitCode: number;
170
- /** @inheritDoc */
171
- readonly httpStatusCode: number;
172
- constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
173
- static forHttpCode(httpStatusCode: number, text?: string): PHPResponse;
174
- static fromRawData(data: PHPResponseData): PHPResponse;
175
- toRawData(): PHPResponseData;
176
- /**
177
- * Response body as JSON.
178
- */
179
- get json(): any;
180
- /**
181
- * Response body as text.
182
- */
183
- get text(): string;
184
- }
185
- export type PHPRuntimeId = number;
186
- /** Other WebAssembly declarations, for compatibility with older versions of Typescript */
187
- export declare namespace Emscripten {
188
- export interface RootFS extends Emscripten.FileSystemInstance {
189
- filesystems: Record<string, Emscripten.FileSystemType>;
190
- }
191
- export interface FileSystemType {
192
- mount(mount: FS.Mount): FS.FSNode;
193
- syncfs(mount: FS.Mount, populate: () => unknown, done: (err?: number | null) => unknown): void;
194
- }
195
- export type EnvironmentType = "WEB" | "NODE" | "SHELL" | "WORKER";
196
- export type JSType = "number" | "string" | "array" | "boolean";
197
- export type TypeCompatibleWithC = number | string | any[] | boolean;
198
- export type CIntType = "i8" | "i16" | "i32" | "i64";
199
- export type CFloatType = "float" | "double";
200
- export type CPointerType = "i8*" | "i16*" | "i32*" | "i64*" | "float*" | "double*" | "*";
201
- export type CType = CIntType | CFloatType | CPointerType;
202
- export interface CCallOpts {
203
- async?: boolean | undefined;
204
- }
205
- type NamespaceToInstance<T> = {
206
- [K in keyof T]: T[K] extends (...args: any[]) => any ? T[K] : never;
207
- };
208
- export type FileSystemInstance = NamespaceToInstance<typeof FS> & {
209
- mkdirTree(path: string): void;
210
- lookupPath(path: string, opts?: any): FS.Lookup;
211
- };
212
- export interface EmscriptenModule {
213
- print(str: string): void;
214
- printErr(str: string): void;
215
- arguments: string[];
216
- environment: Emscripten.EnvironmentType;
217
- preInit: Array<{
218
- (): void;
219
- }>;
220
- preRun: Array<{
221
- (): void;
222
- }>;
223
- postRun: Array<{
224
- (): void;
225
- }>;
226
- onAbort: {
227
- (what: any): void;
228
- };
229
- onRuntimeInitialized: {
230
- (): void;
231
- };
232
- preinitializedWebGLContext: WebGLRenderingContext;
233
- noInitialRun: boolean;
234
- noExitRuntime: boolean;
235
- logReadFiles: boolean;
236
- filePackagePrefixURL: string;
237
- wasmBinary: ArrayBuffer;
238
- destroy(object: object): void;
239
- getPreloadedPackage(remotePackageName: string, remotePackageSize: number): ArrayBuffer;
240
- instantiateWasm(imports: WebAssembly.Imports, successCallback: (module: WebAssembly.Instance) => void): WebAssembly.Exports | undefined;
241
- locateFile(url: string, scriptDirectory: string): string;
242
- onCustomMessage(event: MessageEvent): void;
243
- HEAP: Int32Array;
244
- IHEAP: Int32Array;
245
- FHEAP: Float64Array;
246
- HEAP8: Int8Array;
247
- HEAP16: Int16Array;
248
- HEAP32: Int32Array;
249
- HEAPU8: Uint8Array;
250
- HEAPU16: Uint16Array;
251
- HEAPU32: Uint32Array;
252
- HEAPF32: Float32Array;
253
- HEAPF64: Float64Array;
254
- HEAP64: BigInt64Array;
255
- HEAPU64: BigUint64Array;
256
- TOTAL_STACK: number;
257
- TOTAL_MEMORY: number;
258
- FAST_MEMORY: number;
259
- addOnPreRun(cb: () => any): void;
260
- addOnInit(cb: () => any): void;
261
- addOnPreMain(cb: () => any): void;
262
- addOnExit(cb: () => any): void;
263
- addOnPostRun(cb: () => any): void;
264
- preloadedImages: any;
265
- preloadedAudios: any;
266
- _malloc(size: number): number;
267
- _free(ptr: number): void;
268
- }
269
- /**
270
- * A factory function is generated when setting the `MODULARIZE` build option
271
- * to `1` in your Emscripten build. It return a Promise that resolves to an
272
- * initialized, ready-to-call `EmscriptenModule` instance.
273
- *
274
- * By default, the factory function will be named `Module`. It's recommended to
275
- * use the `EXPORT_ES6` option, in which the factory function will be the
276
- * default export. If used without `EXPORT_ES6`, the factory function will be a
277
- * global variable. You can rename the variable using the `EXPORT_NAME` build
278
- * option. It's left to you to export any global variables as needed in your
279
- * application's types.
280
- * @param moduleOverrides Default properties for the initialized module.
281
- */
282
- export type EmscriptenModuleFactory<T extends EmscriptenModule = EmscriptenModule> = (moduleOverrides?: Partial<T>) => Promise<T>;
283
- export namespace FS {
284
- interface Lookup {
285
- path: string;
286
- node: FSNode;
287
- }
288
- interface Analyze {
289
- isRoot: boolean;
290
- exists: boolean;
291
- error: Error;
292
- name: string;
293
- path: Lookup["path"];
294
- object: Lookup["node"];
295
- parentExists: boolean;
296
- parentPath: Lookup["path"];
297
- parentObject: Lookup["node"];
298
- }
299
- interface Mount {
300
- type: Emscripten.FileSystemType;
301
- opts: object;
302
- mountpoint: string;
303
- mounts: Mount[];
304
- root: FSNode;
305
- }
306
- class FSStream {
307
- constructor();
308
- object: FSNode;
309
- readonly isRead: boolean;
310
- readonly isWrite: boolean;
311
- readonly isAppend: boolean;
312
- flags: number;
313
- position: number;
314
- }
315
- class FSNode {
316
- parent: FSNode;
317
- mount: Mount;
318
- mounted?: Mount;
319
- id: number;
320
- name: string;
321
- mode: number;
322
- rdev: number;
323
- readMode: number;
324
- writeMode: number;
325
- constructor(parent: FSNode, name: string, mode: number, rdev: number);
326
- read: boolean;
327
- write: boolean;
328
- readonly isFolder: boolean;
329
- readonly isDevice: boolean;
330
- }
331
- interface ErrnoError extends Error {
332
- name: "ErronoError";
333
- errno: number;
334
- code: string;
335
- }
336
- function lookupPath(path: string, opts: any): Lookup;
337
- function getPath(node: FSNode): string;
338
- function analyzePath(path: string, dontResolveLastLink?: boolean): Analyze;
339
- function isFile(mode: number): boolean;
340
- function isDir(mode: number): boolean;
341
- function isLink(mode: number): boolean;
342
- function isChrdev(mode: number): boolean;
343
- function isBlkdev(mode: number): boolean;
344
- function isFIFO(mode: number): boolean;
345
- function isSocket(mode: number): boolean;
346
- function major(dev: number): number;
347
- function minor(dev: number): number;
348
- function makedev(ma: number, mi: number): number;
349
- function registerDevice(dev: number, ops: any): void;
350
- function syncfs(populate: boolean, callback: (e: any) => any): void;
351
- function syncfs(callback: (e: any) => any, populate?: boolean): void;
352
- function mount(type: Emscripten.FileSystemType, opts: any, mountpoint: string): any;
353
- function unmount(mountpoint: string): void;
354
- function mkdir(path: string, mode?: number): any;
355
- function mkdev(path: string, mode?: number, dev?: number): any;
356
- function symlink(oldpath: string, newpath: string): any;
357
- function rename(old_path: string, new_path: string): void;
358
- function rmdir(path: string): void;
359
- function readdir(path: string): any;
360
- function unlink(path: string): void;
361
- function readlink(path: string): string;
362
- function stat(path: string, dontFollow?: boolean): any;
363
- function lstat(path: string): any;
364
- function chmod(path: string, mode: number, dontFollow?: boolean): void;
365
- function lchmod(path: string, mode: number): void;
366
- function fchmod(fd: number, mode: number): void;
367
- function chown(path: string, uid: number, gid: number, dontFollow?: boolean): void;
368
- function lchown(path: string, uid: number, gid: number): void;
369
- function fchown(fd: number, uid: number, gid: number): void;
370
- function truncate(path: string, len: number): void;
371
- function ftruncate(fd: number, len: number): void;
372
- function utime(path: string, atime: number, mtime: number): void;
373
- function open(path: string, flags: string, mode?: number, fd_start?: number, fd_end?: number): FSStream;
374
- function close(stream: FSStream): void;
375
- function llseek(stream: FSStream, offset: number, whence: number): any;
376
- function read(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position?: number): number;
377
- function write(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position?: number, canOwn?: boolean): number;
378
- function allocate(stream: FSStream, offset: number, length: number): void;
379
- function mmap(stream: FSStream, buffer: ArrayBufferView, offset: number, length: number, position: number, prot: number, flags: number): any;
380
- function ioctl(stream: FSStream, cmd: any, arg: any): any;
381
- function readFile(path: string, opts: {
382
- encoding: "binary";
383
- flags?: string | undefined;
384
- }): Uint8Array;
385
- function readFile(path: string, opts: {
386
- encoding: "utf8";
387
- flags?: string | undefined;
388
- }): string;
389
- function readFile(path: string, opts?: {
390
- flags?: string | undefined;
391
- }): Uint8Array;
392
- function writeFile(path: string, data: string | ArrayBufferView, opts?: {
393
- flags?: string | undefined;
394
- }): void;
395
- function cwd(): string;
396
- function chdir(path: string): void;
397
- function init(input: null | (() => number | null), output: null | ((c: number) => any), error: null | ((c: number) => any)): void;
398
- function createLazyFile(parent: string | FSNode, name: string, url: string, canRead: boolean, canWrite: boolean): FSNode;
399
- function createPreloadedFile(parent: string | FSNode, name: string, url: string, canRead: boolean, canWrite: boolean, onload?: () => void, onerror?: () => void, dontCreateFile?: boolean, canOwn?: boolean): void;
400
- function createDataFile(parent: string | FSNode, name: string, data: ArrayBufferView, canRead: boolean, canWrite: boolean, canOwn: boolean): FSNode;
401
- }
402
- export const MEMFS: Emscripten.FileSystemType;
403
- export const NODEFS: Emscripten.FileSystemType;
404
- export const IDBFS: Emscripten.FileSystemType;
405
- type StringToType<R> = R extends Emscripten.JSType ? {
406
- number: number;
407
- string: string;
408
- array: number[] | string[] | boolean[] | Uint8Array | Int8Array;
409
- boolean: boolean;
410
- null: null;
411
- }[R] : never;
412
- type ArgsToType<T extends Array<Emscripten.JSType | null>> = Extract<{
413
- [P in keyof T]: StringToType<T[P]>;
414
- }, any[]>;
415
- type ReturnToType<R extends Emscripten.JSType | null> = R extends null ? null : StringToType<Exclude<R, null>>;
416
- export function cwrap<I extends Array<Emscripten.JSType | null> | [
417
- ], R extends Emscripten.JSType | null>(ident: string, returnType: R, argTypes: I, opts?: Emscripten.CCallOpts): (...arg: ArgsToType<I>) => ReturnToType<R>;
418
- export function ccall<I extends Array<Emscripten.JSType | null> | [
419
- ], R extends Emscripten.JSType | null>(ident: string, returnType: R, argTypes: I, args: ArgsToType<I>, opts?: Emscripten.CCallOpts): ReturnToType<R>;
420
- export function setValue(ptr: number, value: any, type: Emscripten.CType, noSafe?: boolean): void;
421
- export function getValue(ptr: number, type: Emscripten.CType, noSafe?: boolean): number;
422
- export function allocate(slab: number[] | ArrayBufferView | number, types: Emscripten.CType | Emscripten.CType[], allocator: number, ptr?: number): number;
423
- export function stackAlloc(size: number): number;
424
- export function stackSave(): number;
425
- export function stackRestore(ptr: number): void;
426
- export function UTF8ToString(ptr: number, maxBytesToRead?: number): string;
427
- export function stringToUTF8(str: string, outPtr: number, maxBytesToRead?: number): void;
428
- export function lengthBytesUTF8(str: string): number;
429
- export function allocateUTF8(str: string): number;
430
- export function allocateUTF8OnStack(str: string): number;
431
- export function UTF16ToString(ptr: number): string;
432
- export function stringToUTF16(str: string, outPtr: number, maxBytesToRead?: number): void;
433
- export function lengthBytesUTF16(str: string): number;
434
- export function UTF32ToString(ptr: number): string;
435
- export function stringToUTF32(str: string, outPtr: number, maxBytesToRead?: number): void;
436
- export function lengthBytesUTF32(str: string): number;
437
- export function intArrayFromString(stringy: string, dontAddNull?: boolean, length?: number): number[];
438
- export function intArrayToString(array: number[]): string;
439
- export function writeStringToMemory(str: string, buffer: number, dontAddNull: boolean): void;
440
- export function writeArrayToMemory(array: number[], buffer: number): void;
441
- export function writeAsciiToMemory(str: string, buffer: number, dontAddNull: boolean): void;
442
- export function addRunDependency(id: any): void;
443
- export function removeRunDependency(id: any): void;
444
- export function addFunction(func: (...args: any[]) => any, signature?: string): number;
445
- export function removeFunction(funcPtr: number): void;
446
- export const ALLOC_NORMAL: number;
447
- export const ALLOC_STACK: number;
448
- export const ALLOC_STATIC: number;
449
- export const ALLOC_DYNAMIC: number;
450
- export const ALLOC_NONE: number;
451
- export {};
452
- }
453
- export interface RmDirOptions {
454
- /**
455
- * If true, recursively removes the directory and all its contents.
456
- * Default: true.
457
- */
458
- recursive?: boolean;
459
- }
460
- export interface ListFilesOptions {
461
- /**
462
- * If true, prepend given folder path to all file names.
463
- * Default: false.
464
- */
465
- prependPath: boolean;
466
- }
467
- export interface SemaphoreOptions {
468
- /**
469
- * The maximum number of concurrent locks.
470
- */
471
- concurrency: number;
472
- /**
473
- * The maximum time to wait for a lock to become available.
474
- */
475
- timeout?: number;
476
- }
477
- declare class Semaphore {
478
- private _running;
479
- private concurrency;
480
- private timeout?;
481
- private queue;
482
- constructor({ concurrency, timeout }: SemaphoreOptions);
483
- get remaining(): number;
484
- get running(): number;
485
- acquire(): Promise<() => void>;
486
- run<T>(fn: () => T | Promise<T>): Promise<T>;
487
- }
488
- export type PHPFactoryOptions = {
489
- isPrimary: boolean;
490
- };
491
- export type PHPFactory = (options: PHPFactoryOptions) => Promise<PHP>;
492
- export interface ProcessManagerOptions {
493
- /**
494
- * The maximum number of PHP instances that can exist at
495
- * the same time.
496
- */
497
- maxPhpInstances?: number;
498
- /**
499
- * The number of milliseconds to wait for a PHP instance when
500
- * we have reached the maximum number of PHP instances and
501
- * cannot spawn a new one. If the timeout is reached, we assume
502
- * all the PHP instances are deadlocked and a throw MaxPhpInstancesError.
503
- *
504
- * Default: 5000
505
- */
506
- timeout?: number;
507
- /**
508
- * The primary PHP instance that's never killed. This instance
509
- * contains the reference filesystem used by all other PHP instances.
510
- */
511
- primaryPhp?: PHP;
512
- /**
513
- * A factory function used for spawning new PHP instances.
514
- */
515
- phpFactory?: PHPFactory;
516
- }
517
- export interface SpawnedPHP {
518
- php: PHP;
519
- reap: () => void;
520
- }
521
- declare class PHPProcessManager implements AsyncDisposable {
522
- private primaryPhp?;
523
- private primaryIdle;
524
- private nextInstance;
525
- /**
526
- * All spawned PHP instances, including the primary PHP instance.
527
- * Used for bookkeeping and reaping all instances on dispose.
528
- */
529
- private allInstances;
530
- private phpFactory?;
531
- private maxPhpInstances;
532
- private semaphore;
533
- constructor(options?: ProcessManagerOptions);
534
- /**
535
- * Get the primary PHP instance.
536
- *
537
- * If the primary PHP instance is not set, it will be spawned
538
- * using the provided phpFactory.
539
- *
540
- * @throws {Error} when called twice before the first call is resolved.
541
- */
542
- getPrimaryPhp(): Promise<PHP>;
543
- /**
544
- * Get a PHP instance.
545
- *
546
- * It could be either the primary PHP instance, an idle disposable PHP instance,
547
- * or a newly spawned PHP instance – depending on the resource availability.
548
- *
549
- * @throws {MaxPhpInstancesError} when the maximum number of PHP instances is reached
550
- * and the waiting timeout is exceeded.
551
- */
552
- acquirePHPInstance(): Promise<SpawnedPHP>;
553
- /**
554
- * Initiated spawning of a new PHP instance.
555
- * This function is synchronous on purpose – it needs to synchronously
556
- * add the spawn promise to the allInstances array without waiting
557
- * for PHP to spawn.
558
- */
559
- private spawn;
560
- /**
561
- * Actually acquires the lock and spawns a new PHP instance.
562
- */
563
- private doSpawn;
564
- [Symbol.asyncDispose](): Promise<void>;
565
- }
566
- export type RewriteRule = {
567
- match: RegExp;
568
- replacement: string;
569
- };
570
- export interface BaseConfiguration {
571
- /**
572
- * The directory in the PHP filesystem where the server will look
573
- * for the files to serve. Default: `/var/www`.
574
- */
575
- documentRoot?: string;
576
- /**
577
- * Request Handler URL. Used to populate $_SERVER details like HTTP_HOST.
578
- */
579
- absoluteUrl?: string;
580
- /**
581
- * Rewrite rules
582
- */
583
- rewriteRules?: RewriteRule[];
584
- }
585
- export type PHPRequestHandlerFactoryArgs = PHPFactoryOptions & {
586
- requestHandler: PHPRequestHandler;
587
- };
588
- export type PHPRequestHandlerConfiguration = BaseConfiguration & ({
589
- /**
590
- * PHPProcessManager is required because the request handler needs
591
- * to make a decision for each request.
592
- *
593
- * Static assets are served using the primary PHP's filesystem, even
594
- * when serving 100 static files concurrently. No new PHP interpreter
595
- * is ever created as there's no need for it.
596
- *
597
- * Dynamic PHP requests, however, require grabbing an available PHP
598
- * interpreter, and that's where the PHPProcessManager comes in.
599
- */
600
- processManager: PHPProcessManager;
601
- } | {
602
- phpFactory: (requestHandler: PHPRequestHandlerFactoryArgs) => Promise<PHP>;
603
- /**
604
- * The maximum number of PHP instances that can exist at
605
- * the same time.
606
- */
607
- maxPhpInstances?: number;
608
- });
609
- declare class PHPRequestHandler {
610
- #private;
611
- rewriteRules: RewriteRule[];
612
- processManager: PHPProcessManager;
613
- /**
614
- * The request handler needs to decide whether to serve a static asset or
615
- * run the PHP interpreter. For static assets it should just reuse the primary
616
- * PHP even if there's 50 concurrent requests to serve. However, for
617
- * dynamic PHP requests, it needs to grab an available interpreter.
618
- * Therefore, it cannot just accept PHP as an argument as serving requests
619
- * requires access to ProcessManager.
620
- *
621
- * @param php - The PHP instance.
622
- * @param config - Request Handler configuration.
623
- */
624
- constructor(config: PHPRequestHandlerConfiguration);
625
- getPrimaryPhp(): Promise<PHP>;
626
- /**
627
- * Converts a path to an absolute URL based at the PHPRequestHandler
628
- * root.
629
- *
630
- * @param path The server path to convert to an absolute URL.
631
- * @returns The absolute URL.
632
- */
633
- pathToInternalUrl(path: string): string;
634
- /**
635
- * Converts an absolute URL based at the PHPRequestHandler to a relative path
636
- * without the server pathname and scope.
637
- *
638
- * @param internalUrl An absolute URL based at the PHPRequestHandler root.
639
- * @returns The relative path.
640
- */
641
- internalUrlToPath(internalUrl: string): string;
642
- /**
643
- * The absolute URL of this PHPRequestHandler instance.
644
- */
645
- get absoluteUrl(): string;
646
- /**
647
- * The directory in the PHP filesystem where the server will look
648
- * for the files to serve. Default: `/var/www`.
649
- */
650
- get documentRoot(): string;
651
- /**
652
- * Serves the request – either by serving a static file, or by
653
- * dispatching it to the PHP runtime.
654
- *
655
- * The request() method mode behaves like a web server and only works if
656
- * the PHP was initialized with a `requestHandler` option (which the online version
657
- * of WordPress Playground does by default).
658
- *
659
- * In the request mode, you pass an object containing the request information
660
- * (method, headers, body, etc.) and the path to the PHP file to run:
661
- *
662
- * ```ts
663
- * const php = PHP.load('7.4', {
664
- * requestHandler: {
665
- * documentRoot: "/www"
666
- * }
667
- * })
668
- * php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
669
- * const result = await php.request({
670
- * method: "GET",
671
- * headers: {
672
- * "Content-Type": "text/plain"
673
- * },
674
- * body: "Hello world!",
675
- * path: "/www/index.php"
676
- * });
677
- * // result.text === "Hello world!"
678
- * ```
679
- *
680
- * The `request()` method cannot be used in conjunction with `cli()`.
681
- *
682
- * @example
683
- * ```js
684
- * const output = await php.request({
685
- * method: 'GET',
686
- * url: '/index.php',
687
- * headers: {
688
- * 'X-foo': 'bar',
689
- * },
690
- * body: {
691
- * foo: 'bar',
692
- * },
693
- * });
694
- * console.log(output.stdout); // "Hello world!"
695
- * ```
696
- *
697
- * @param request - PHP Request data.
698
- */
699
- request(request: PHPRequest): Promise<PHPResponse>;
700
- }
701
- declare const __private__dont__use: unique symbol;
702
- export type UnmountFunction = (() => Promise<any>) | (() => any);
703
- export type MountHandler = (php: PHP, FS: Emscripten.RootFS, vfsMountPoint: string) => UnmountFunction | Promise<UnmountFunction>;
704
- declare class PHP implements Disposable {
705
- #private;
706
- protected [__private__dont__use]: any;
707
- requestHandler?: PHPRequestHandler;
708
- /**
709
- * An exclusive lock that prevent multiple requests from running at
710
- * the same time.
711
- */
712
- semaphore: Semaphore;
713
- /**
714
- * Initializes a PHP runtime.
715
- *
716
- * @internal
717
- * @param PHPRuntime - Optional. PHP Runtime ID as initialized by loadPHPRuntime.
718
- * @param requestHandlerOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
719
- */
720
- constructor(PHPRuntimeId?: PHPRuntimeId);
721
- /**
722
- * Adds an event listener for a PHP event.
723
- * @param eventType - The type of event to listen for.
724
- * @param listener - The listener function to be called when the event is triggered.
725
- */
726
- addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
727
- /**
728
- * Removes an event listener for a PHP event.
729
- * @param eventType - The type of event to remove the listener from.
730
- * @param listener - The listener function to be removed.
731
- */
732
- removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
733
- dispatchEvent<Event extends PHPEvent>(event: Event): void;
734
- /**
735
- * Listens to message sent by the PHP code.
736
- *
737
- * To dispatch messages, call:
738
- *
739
- * post_message_to_js(string $data)
740
- *
741
- * Arguments:
742
- * $data (string) – Data to pass to JavaScript.
743
- *
744
- * @example
745
- *
746
- * ```ts
747
- * const php = await PHP.load('8.0');
748
- *
749
- * php.onMessage(
750
- * // The data is always passed as a string
751
- * function (data: string) {
752
- * // Let's decode and log the data:
753
- * console.log(JSON.parse(data));
754
- * }
755
- * );
756
- *
757
- * // Now that we have a listener in place, let's
758
- * // dispatch a message:
759
- * await php.run({
760
- * code: `<?php
761
- * post_message_to_js(
762
- * json_encode([
763
- * 'post_id' => '15',
764
- * 'post_title' => 'This is a blog post!'
765
- * ])
766
- * ));
767
- * `,
768
- * });
769
- * ```
770
- *
771
- * @param listener Callback function to handle the message.
772
- */
773
- onMessage(listener: MessageListener): void;
774
- setSpawnHandler(handler: SpawnHandler | string): Promise<void>;
775
- /** @deprecated Use PHPRequestHandler instead. */
776
- get absoluteUrl(): string;
777
- /** @deprecated Use PHPRequestHandler instead. */
778
- get documentRoot(): string;
779
- /** @deprecated Use PHPRequestHandler instead. */
780
- pathToInternalUrl(path: string): string;
781
- /** @deprecated Use PHPRequestHandler instead. */
782
- internalUrlToPath(internalUrl: string): string;
783
- initializeRuntime(runtimeId: PHPRuntimeId): void;
784
- /** @inheritDoc */
785
- setSapiName(newName: string): Promise<void>;
786
- /**
787
- * Changes the current working directory in the PHP filesystem.
788
- * This is the directory that will be used as the base for relative paths.
789
- * For example, if the current working directory is `/root/php`, and the
790
- * path is `data`, the absolute path will be `/root/php/data`.
791
- *
792
- * @param path - The new working directory.
793
- */
794
- chdir(path: string): void;
795
- /**
796
- * Do not use. Use new PHPRequestHandler() instead.
797
- * @deprecated
798
- */
799
- request(request: PHPRequest): Promise<PHPResponse>;
800
- /**
801
- * Runs PHP code.
802
- *
803
- * This low-level method directly interacts with the WebAssembly
804
- * PHP interpreter.
805
- *
806
- * Every time you call run(), it prepares the PHP
807
- * environment and:
808
- *
809
- * * Resets the internal PHP state
810
- * * Populates superglobals ($_SERVER, $_GET, etc.)
811
- * * Handles file uploads
812
- * * Populates input streams (stdin, argv, etc.)
813
- * * Sets the current working directory
814
- *
815
- * You can use run() in two primary modes:
816
- *
817
- * ### Code snippet mode
818
- *
819
- * In this mode, you pass a string containing PHP code to run.
820
- *
821
- * ```ts
822
- * const result = await php.run({
823
- * code: `<?php echo "Hello world!";`
824
- * });
825
- * // result.text === "Hello world!"
826
- * ```
827
- *
828
- * In this mode, information like __DIR__ or __FILE__ isn't very
829
- * useful because the code is not associated with any file.
830
- *
831
- * Under the hood, the PHP snippet is passed to the `zend_eval_string`
832
- * C function.
833
- *
834
- * ### File mode
835
- *
836
- * In the file mode, you pass a scriptPath and PHP executes a file
837
- * found at a that path:
838
- *
839
- * ```ts
840
- * php.writeFile(
841
- * "/www/index.php",
842
- * `<?php echo "Hello world!";"`
843
- * );
844
- * const result = await php.run({
845
- * scriptPath: "/www/index.php"
846
- * });
847
- * // result.text === "Hello world!"
848
- * ```
849
- *
850
- * In this mode, you can rely on path-related information like __DIR__
851
- * or __FILE__.
852
- *
853
- * Under the hood, the PHP file is executed with the `php_execute_script`
854
- * C function.
855
- *
856
- * The `run()` method cannot be used in conjunction with `cli()`.
857
- *
858
- * @example
859
- * ```js
860
- * const result = await php.run(`<?php
861
- * $fp = fopen('php://stderr', 'w');
862
- * fwrite($fp, "Hello, world!");
863
- * `);
864
- * // result.errors === "Hello, world!"
865
- * ```
866
- *
867
- * @param options - PHP runtime options.
868
- */
869
- run(request: PHPRunOptions): Promise<PHPResponse>;
870
- /**
871
- * Defines a constant in the PHP runtime.
872
- * @param key - The name of the constant.
873
- * @param value - The value of the constant.
874
- */
875
- defineConstant(key: string, value: string | boolean | number | null): void;
876
- /**
877
- * Recursively creates a directory with the given path in the PHP filesystem.
878
- * For example, if the path is `/root/php/data`, and `/root` already exists,
879
- * it will create the directories `/root/php` and `/root/php/data`.
880
- *
881
- * @param path - The directory path to create.
882
- */
883
- mkdir(path: string): void;
884
- /**
885
- * @deprecated Use mkdir instead.
886
- */
887
- mkdirTree(path: string): void;
888
- /**
889
- * Reads a file from the PHP filesystem and returns it as a string.
890
- *
891
- * @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
892
- * @param path - The file path to read.
893
- * @returns The file contents.
894
- */
895
- readFileAsText(path: string): string;
896
- /**
897
- * Reads a file from the PHP filesystem and returns it as an array buffer.
898
- *
899
- * @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
900
- * @param path - The file path to read.
901
- * @returns The file contents.
902
- */
903
- readFileAsBuffer(path: string): Uint8Array;
904
- /**
905
- * Overwrites data in a file in the PHP filesystem.
906
- * Creates a new file if one doesn't exist yet.
907
- *
908
- * @param path - The file path to write to.
909
- * @param data - The data to write to the file.
910
- */
911
- writeFile(path: string, data: string | Uint8Array): void;
912
- /**
913
- * Removes a file from the PHP filesystem.
914
- *
915
- * @throws {@link @php-wasm/universal:ErrnoError} – If the file doesn't exist.
916
- * @param path - The file path to remove.
917
- */
918
- unlink(path: string): void;
919
- /**
920
- * Moves a file or directory in the PHP filesystem to a
921
- * new location.
922
- *
923
- * @param oldPath The path to rename.
924
- * @param newPath The new path.
925
- */
926
- mv(fromPath: string, toPath: string): void;
927
- /**
928
- * Removes a directory from the PHP filesystem.
929
- *
930
- * @param path The directory path to remove.
931
- * @param options Options for the removal.
932
- */
933
- rmdir(path: string, options?: RmDirOptions): void;
934
- /**
935
- * Lists the files and directories in the given directory.
936
- *
937
- * @param path - The directory path to list.
938
- * @param options - Options for the listing.
939
- * @returns The list of files and directories in the given directory.
940
- */
941
- listFiles(path: string, options?: ListFilesOptions): string[];
942
- /**
943
- * Checks if a directory exists in the PHP filesystem.
944
- *
945
- * @param path – The path to check.
946
- * @returns True if the path is a directory, false otherwise.
947
- */
948
- isDir(path: string): boolean;
949
- /**
950
- * Checks if a file (or a directory) exists in the PHP filesystem.
951
- *
952
- * @param path - The file path to check.
953
- * @returns True if the file exists, false otherwise.
954
- */
955
- fileExists(path: string): boolean;
956
- /**
957
- * Hot-swaps the PHP runtime for a new one without
958
- * interrupting the operations of this PHP instance.
959
- *
960
- * @param runtime
961
- * @param cwd. Internal, the VFS path to recreate in the new runtime.
962
- * This arg is temporary and will be removed once BasePHP
963
- * is fully decoupled from the request handler and
964
- * accepts a constructor-level cwd argument.
965
- */
966
- hotSwapPHPRuntime(runtime: number, cwd?: string): void;
967
- /**
968
- * Mounts a filesystem to a given path in the PHP filesystem.
969
- *
970
- * @param virtualFSPath - Where to mount it in the PHP virtual filesystem.
971
- * @param mountHandler - The mount handler to use.
972
- * @return Unmount function to unmount the filesystem.
973
- */
974
- mount(virtualFSPath: string, mountHandler: MountHandler): Promise<UnmountFunction>;
975
- /**
976
- * Starts a PHP CLI session with given arguments.
977
- *
978
- * This method can only be used when PHP was compiled with the CLI SAPI
979
- * and it cannot be used in conjunction with `run()`.
980
- *
981
- * Once this method finishes running, the PHP instance is no
982
- * longer usable and should be discarded. This is because PHP
983
- * internally cleans up all the resources and calls exit().
984
- *
985
- * @param argv - The arguments to pass to the CLI.
986
- * @returns The exit code of the CLI session.
987
- */
988
- cli(argv: string[]): Promise<number>;
989
- setSkipShebang(shouldSkip: boolean): void;
990
- exit(code?: number): void;
991
- [Symbol.dispose](): void;
992
- }
993
- export type LimitedPHPApi = Pick<PHP, "request" | "defineConstant" | "addEventListener" | "removeEventListener" | "mkdir" | "mkdirTree" | "readFileAsText" | "readFileAsBuffer" | "writeFile" | "unlink" | "mv" | "rmdir" | "listFiles" | "isDir" | "fileExists" | "chdir" | "run" | "onMessage"> & {
994
- documentRoot: PHP["documentRoot"];
995
- absoluteUrl: PHP["absoluteUrl"];
996
- };
997
- /**
998
- * Represents an event related to the PHP request.
999
- */
1000
- export interface PHPRequestEndEvent {
1001
- type: "request.end";
1002
- }
1003
- /**
1004
- * Represents an error event related to the PHP request.
1005
- */
1006
- export interface PHPRequestErrorEvent {
1007
- type: "request.error";
1008
- error: Error;
1009
- source?: "request" | "php-wasm";
1010
- }
1011
- /**
1012
- * Represents a PHP runtime initialization event.
1013
- */
1014
- export interface PHPRuntimeInitializedEvent {
1015
- type: "runtime.initialized";
1016
- }
1017
- /**
1018
- * Represents a PHP runtime destruction event.
1019
- */
1020
- export interface PHPRuntimeBeforeDestroyEvent {
1021
- type: "runtime.beforedestroy";
1022
- }
1023
- /**
1024
- * Represents an event related to the PHP instance.
1025
- * This is intentionally not an extension of CustomEvent
1026
- * to make it isomorphic between different JavaScript runtimes.
1027
- */
1028
- export type PHPEvent = PHPRequestEndEvent | PHPRequestErrorEvent | PHPRuntimeInitializedEvent | PHPRuntimeBeforeDestroyEvent;
1029
- /**
1030
- * A callback function that handles PHP events.
1031
- */
1032
- export type PHPEventListener = (event: PHPEvent) => void;
1033
- export type UniversalPHP = LimitedPHPApi | Remote<LimitedPHPApi>;
1034
- export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void;
1035
- export interface EventEmitter {
1036
- on(event: string, listener: (...args: any[]) => void): this;
1037
- emit(event: string, ...args: any[]): boolean;
1038
- }
1039
- export type ChildProcess = EventEmitter & {
1040
- stdout: EventEmitter;
1041
- stderr: EventEmitter;
1042
- };
1043
- export type SpawnHandler = (command: string, args: string[]) => ChildProcess;
1044
- export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
1045
- export type PHPRequestHeaders = Record<string, string>;
1046
- export interface PHPRequest {
1047
- /**
1048
- * Request method. Default: `GET`.
1049
- */
1050
- method?: HTTPMethod;
1051
- /**
1052
- * Request path or absolute URL.
1053
- */
1054
- url: string;
1055
- /**
1056
- * Request headers.
1057
- */
1058
- headers?: PHPRequestHeaders;
1059
- /**
1060
- * Request body.
1061
- * If an object is given, the request will be encoded as multipart
1062
- * and sent with a `multipart/form-data` header.
1063
- */
1064
- body?: string | Uint8Array | Record<string, string | Uint8Array | File>;
1065
- }
1066
- export interface PHPRunOptions {
1067
- /**
1068
- * Request path following the domain:port part.
1069
- */
1070
- relativeUri?: string;
1071
- /**
1072
- * Path of the .php file to execute.
1073
- */
1074
- scriptPath?: string;
1075
- /**
1076
- * Request protocol.
1077
- */
1078
- protocol?: string;
1079
- /**
1080
- * Request method. Default: `GET`.
1081
- */
1082
- method?: HTTPMethod;
1083
- /**
1084
- * Request headers.
1085
- */
1086
- headers?: PHPRequestHeaders;
1087
- /**
1088
- * Request body.
1089
- */
1090
- body?: string | Uint8Array;
1091
- /**
1092
- * Environment variables to set for this run.
1093
- */
1094
- env?: Record<string, string>;
1095
- /**
1096
- * $_SERVER entries to set for this run.
1097
- */
1098
- $_SERVER?: Record<string, string>;
1099
- /**
1100
- * The code snippet to eval instead of a php file.
1101
- */
1102
- code?: string;
1103
- }
1104
- declare const SupportedPHPVersions: readonly [
1105
- "8.3",
1106
- "8.2",
1107
- "8.1",
1108
- "8.0",
1109
- "7.4",
1110
- "7.3",
1111
- "7.2",
1112
- "7.1",
1113
- "7.0"
1114
- ];
1115
- export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
1116
- export type SupportedPHPExtension = "iconv" | "mbstring" | "xml-bundle" | "gd";
1117
- export type SupportedPHPExtensionBundle = "kitchen-sink" | "light";
1118
- export declare const ResourceTypes: readonly [
1119
- "vfs",
1120
- "literal",
1121
- "wordpress.org/themes",
1122
- "wordpress.org/plugins",
1123
- "url"
1124
- ];
1125
- export type VFSReference = {
1126
- /** Identifies the file resource as Virtual File System (VFS) */
1127
- resource: "vfs";
1128
- /** The path to the file in the VFS */
1129
- path: string;
1130
- };
1131
- export type LiteralReference = {
1132
- /** Identifies the file resource as a literal file */
1133
- resource: "literal";
1134
- /** The name of the file */
1135
- name: string;
1136
- /** The contents of the file */
1137
- contents: string | Uint8Array;
1138
- };
1139
- export type CoreThemeReference = {
1140
- /** Identifies the file resource as a WordPress Core theme */
1141
- resource: "wordpress.org/themes";
1142
- /** The slug of the WordPress Core theme */
1143
- slug: string;
1144
- };
1145
- export type CorePluginReference = {
1146
- /** Identifies the file resource as a WordPress Core plugin */
1147
- resource: "wordpress.org/plugins";
1148
- /** The slug of the WordPress Core plugin */
1149
- slug: string;
1150
- };
1151
- export type UrlReference = {
1152
- /** Identifies the file resource as a URL */
1153
- resource: "url";
1154
- /** The URL of the file */
1155
- url: string;
1156
- /** Optional caption for displaying a progress message */
1157
- caption?: string;
1158
- };
1159
- export type FileReference = VFSReference | LiteralReference | CoreThemeReference | CorePluginReference | UrlReference;
1160
- export interface ResourceOptions {
1161
- /** Optional semaphore to limit concurrent downloads */
1162
- semaphore?: Semaphore;
1163
- progress?: ProgressTracker;
1164
- }
1165
- export declare abstract class Resource {
1166
- /** Optional progress tracker to monitor progress */
1167
- abstract progress?: ProgressTracker;
1168
- /** A Promise that resolves to the file contents */
1169
- protected promise?: Promise<File>;
1170
- protected playground?: UniversalPHP;
1171
- /**
1172
- * Creates a new Resource based on the given file reference
1173
- *
1174
- * @param ref The file reference to create the Resource for
1175
- * @param options Additional options for the Resource
1176
- * @returns A new Resource instance
1177
- */
1178
- static create(ref: FileReference, { semaphore, progress }: ResourceOptions): Resource;
1179
- setPlayground(playground: UniversalPHP): void;
1180
- /**
1181
- * Resolves the file contents
1182
- * @returns The resolved file.
1183
- */
1184
- abstract resolve(): Promise<File>;
1185
- /** The name of the referenced file */
1186
- abstract get name(): string;
1187
- /** Whether this Resource is loaded asynchronously */
1188
- get isAsync(): boolean;
1189
- }
1190
- /**
1191
- * A `Resource` that represents a file in the VFS (virtual file system) of the playground.
1192
- */
1193
- export declare class VFSResource extends Resource {
1194
- private resource;
1195
- progress?: ProgressTracker | undefined;
1196
- /**
1197
- * Creates a new instance of `VFSResource`.
1198
- * @param playground The playground client.
1199
- * @param resource The VFS reference.
1200
- * @param progress The progress tracker.
1201
- */
1202
- constructor(resource: VFSReference, progress?: ProgressTracker | undefined);
1203
- /** @inheritDoc */
1204
- resolve(): Promise<File>;
1205
- /** @inheritDoc */
1206
- get name(): string;
1207
- }
1208
- /**
1209
- * A `Resource` that represents a literal file.
1210
- */
1211
- export declare class LiteralResource extends Resource {
1212
- private resource;
1213
- progress?: ProgressTracker | undefined;
1214
- /**
1215
- * Creates a new instance of `LiteralResource`.
1216
- * @param resource The literal reference.
1217
- * @param progress The progress tracker.
1218
- */
1219
- constructor(resource: LiteralReference, progress?: ProgressTracker | undefined);
1220
- /** @inheritDoc */
1221
- resolve(): Promise<File>;
1222
- /** @inheritDoc */
1223
- get name(): string;
1224
- }
1225
- /**
1226
- * A base class for `Resource`s that require fetching data from a remote URL.
1227
- */
1228
- export declare abstract class FetchResource extends Resource {
1229
- progress?: ProgressTracker | undefined;
1230
- /**
1231
- * Creates a new instance of `FetchResource`.
1232
- * @param progress The progress tracker.
1233
- */
1234
- constructor(progress?: ProgressTracker | undefined);
1235
- /** @inheritDoc */
1236
- resolve(): Promise<File>;
1237
- /**
1238
- * Gets the URL to fetch the data from.
1239
- * @returns The URL.
1240
- */
1241
- protected abstract getURL(): string;
1242
- /**
1243
- * Gets the caption for the progress tracker.
1244
- * @returns The caption.
1245
- */
1246
- protected get caption(): string;
1247
- /** @inheritDoc */
1248
- get name(): string;
1249
- /** @inheritDoc */
1250
- get isAsync(): boolean;
1251
- }
1252
- /**
1253
- * A `Resource` that represents a file available from a URL.
1254
- */
1255
- export declare class UrlResource extends FetchResource {
1256
- private resource;
1257
- /**
1258
- * Creates a new instance of `UrlResource`.
1259
- * @param resource The URL reference.
1260
- * @param progress The progress tracker.
1261
- */
1262
- constructor(resource: UrlReference, progress?: ProgressTracker);
1263
- /** @inheritDoc */
1264
- getURL(): string;
1265
- /** @inheritDoc */
1266
- protected get caption(): string;
1267
- }
1268
- /**
1269
- * A `Resource` that represents a WordPress core theme.
1270
- */
1271
- export declare class CoreThemeResource extends FetchResource {
1272
- private resource;
1273
- constructor(resource: CoreThemeReference, progress?: ProgressTracker);
1274
- get name(): string;
1275
- getURL(): string;
1276
- }
1277
- /**
1278
- * A resource that fetches a WordPress plugin from wordpress.org.
1279
- */
1280
- export declare class CorePluginResource extends FetchResource {
1281
- private resource;
1282
- constructor(resource: CorePluginReference, progress?: ProgressTracker);
1283
- /** @inheritDoc */
1284
- get name(): string;
1285
- /** @inheritDoc */
1286
- getURL(): string;
1287
- }
1288
- /**
1289
- * A decorator for a resource that adds functionality such as progress tracking and caching.
1290
- */
1291
- export declare class DecoratedResource<T extends Resource> extends Resource {
1292
- private resource;
1293
- constructor(resource: T);
1294
- /** @inheritDoc */
1295
- resolve(): Promise<File>;
1296
- /** @inheritDoc */
1297
- setPlayground(playground: UniversalPHP): Promise<void>;
1298
- /** @inheritDoc */
1299
- get progress(): ProgressTracker | undefined;
1300
- /** @inheritDoc */
1301
- set progress(value: ProgressTracker | undefined);
1302
- /** @inheritDoc */
1303
- get name(): string;
1304
- /** @inheritDoc */
1305
- get isAsync(): boolean;
1306
- }
1307
- /**
1308
- * A decorator for a resource that adds caching functionality.
1309
- */
1310
- export declare class CachedResource<T extends Resource> extends DecoratedResource<T> {
1311
- protected promise?: Promise<File>;
1312
- /** @inheritDoc */
1313
- resolve(): Promise<File>;
1314
- }
1315
- /**
1316
- * A decorator for a resource that adds concurrency control functionality through a semaphore.
1317
- */
1318
- export declare class SemaphoreResource<T extends Resource> extends DecoratedResource<T> {
1319
- private readonly semaphore;
1320
- constructor(resource: T, semaphore: Semaphore);
1321
- /** @inheritDoc */
1322
- resolve(): Promise<File>;
1323
- }
1324
- /**
1325
- * @inheritDoc activatePlugin
1326
- * @example
1327
- *
1328
- * <code>
1329
- * {
1330
- * "step": "activatePlugin",
1331
- * "pluginName": "Gutenberg",
1332
- * "pluginPath": "/wordpress/wp-content/plugins/gutenberg"
1333
- * }
1334
- * </code>
1335
- */
1336
- export interface ActivatePluginStep {
1337
- step: "activatePlugin";
1338
- /** Path to the plugin directory as absolute path (/wordpress/wp-content/plugins/plugin-name); or the plugin entry file relative to the plugins directory (plugin-name/plugin-name.php). */
1339
- pluginPath: string;
1340
- /** Optional. Plugin name to display in the progress bar. */
1341
- pluginName?: string;
1342
- }
1343
- /**
1344
- * Activates a WordPress plugin (if it's installed).
1345
- *
1346
- * @param playground The playground client.
1347
- */
1348
- export declare const activatePlugin: StepHandler<ActivatePluginStep>;
1349
- /**
1350
- * Changes the site URL of the WordPress installation.
1351
- *
1352
- * @inheritDoc defineSiteUrl
1353
- */
1354
- export interface DefineSiteUrlStep {
1355
- step: "defineSiteUrl";
1356
- /** The URL */
1357
- siteUrl: string;
1358
- }
1359
- /**
1360
- * 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.
1361
- *
1362
- * Using this step on playground.wordpress.net is moot.
1363
- * It is useful when building a custom Playground-based tool, like [`wp-now`](https://www.npmjs.com/package/@wp-now/wp-now),
1364
- * or deploying Playground on a custom domain.
1365
- *
1366
- * @param playground The playground client.
1367
- * @param siteUrl
1368
- */
1369
- export declare const defineSiteUrl: StepHandler<DefineSiteUrlStep>;
1370
- export interface InstallAssetOptions {
1371
- /**
1372
- * The zip file to install.
1373
- */
1374
- zipFile: File;
1375
- /**
1376
- * Target path to extract the main folder.
1377
- * @example
1378
- *
1379
- * <code>
1380
- * const targetPath = `${await playground.documentRoot}/wp-content/plugins`;
1381
- * </code>
1382
- */
1383
- targetPath: string;
1384
- /**
1385
- * What to do if the asset already exists.
1386
- */
1387
- ifAlreadyInstalled?: "overwrite" | "skip" | "error";
1388
- }
1389
- /**
1390
- * @inheritDoc installPlugin
1391
- * @hasRunnableExample
1392
- * @needsLogin
1393
- * @landingPage /wp-admin/plugins.php
1394
- * @example
1395
- *
1396
- * <code>
1397
- * {
1398
- * "step": "installPlugin",
1399
- * "pluginZipFile": {
1400
- * "resource": "wordpress.org/plugins",
1401
- * "slug": "gutenberg"
1402
- * },
1403
- * "options": {
1404
- * "activate": true
1405
- * }
1406
- * }
1407
- * </code>
1408
- */
1409
- export interface InstallPluginStep<ResourceType> extends Pick<InstallAssetOptions, "ifAlreadyInstalled"> {
1410
- /**
1411
- * The step identifier.
1412
- */
1413
- step: "installPlugin";
1414
- /**
1415
- * The plugin zip file to install.
1416
- */
1417
- pluginZipFile: ResourceType;
1418
- /**
1419
- * Optional installation options.
1420
- */
1421
- options?: InstallPluginOptions;
1422
- }
1423
- export interface InstallPluginOptions {
1424
- /**
1425
- * Whether to activate the plugin after installing it.
1426
- */
1427
- activate?: boolean;
1428
- }
1429
- /**
1430
- * Installs a WordPress plugin in the Playground.
1431
- *
1432
- * @param playground The playground client.
1433
- * @param pluginZipFile The plugin zip file.
1434
- * @param options Optional. Set `activate` to false if you don't want to activate the plugin.
1435
- */
1436
- export declare const installPlugin: StepHandler<InstallPluginStep<File>>;
1437
- /**
1438
- * @inheritDoc installTheme
1439
- * @hasRunnableExample
1440
- * @needsLogin
1441
- * @example
1442
- *
1443
- * <code>
1444
- * {
1445
- * "step": "installTheme",
1446
- * "themeZipFile": {
1447
- * "resource": "wordpress.org/themes",
1448
- * "slug": "pendant"
1449
- * },
1450
- * "options": {
1451
- * "activate": true
1452
- * }
1453
- * }
1454
- * </code>
1455
- */
1456
- export interface InstallThemeStep<ResourceType> extends Pick<InstallAssetOptions, "ifAlreadyInstalled"> {
1457
- /**
1458
- * The step identifier.
1459
- */
1460
- step: "installTheme";
1461
- /**
1462
- * The theme zip file to install.
1463
- */
1464
- themeZipFile: ResourceType;
1465
- /**
1466
- * Optional installation options.
1467
- */
1468
- options?: {
1469
- /**
1470
- * Whether to activate the theme after installing it.
1471
- */
1472
- activate?: boolean;
1473
- };
1474
- }
1475
- export interface InstallThemeOptions {
1476
- /**
1477
- * Whether to activate the theme after installing it.
1478
- */
1479
- activate?: boolean;
1480
- }
1481
- /**
1482
- * Installs a WordPress theme in the Playground.
1483
- *
1484
- * @param playground The playground client.
1485
- * @param themeZipFile The theme zip file.
1486
- * @param options Optional. Set `activate` to false if you don't want to activate the theme.
1487
- */
1488
- export declare const installTheme: StepHandler<InstallThemeStep<File>>;
1489
- /**
1490
- * @inheritDoc login
1491
- * @hasRunnableExample
1492
- * @example
1493
- *
1494
- * <code>
1495
- * {
1496
- * "step": "login",
1497
- * "username": "admin",
1498
- * "password": "password"
1499
- * }
1500
- * </code>
1501
- */
1502
- export type LoginStep = {
1503
- step: "login";
1504
- /**
1505
- * The user to log in as. Defaults to 'admin'.
1506
- */
1507
- username?: string;
1508
- /**
1509
- * The password to log in with. Defaults to 'password'.
1510
- */
1511
- password?: string;
1512
- };
1513
- /**
1514
- * Logs in to Playground.
1515
- * 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/)
1516
- * just like a user would.
1517
- */
1518
- export declare const login: StepHandler<LoginStep>;
1519
- /**
1520
- * @private
1521
- */
1522
- export interface RunWpInstallationWizardStep {
1523
- step: "runWpInstallationWizard";
1524
- options: WordPressInstallationOptions;
1525
- }
1526
- export interface WordPressInstallationOptions {
1527
- adminUsername?: string;
1528
- adminPassword?: string;
1529
- }
1530
- /**
1531
- * Installs WordPress
1532
- *
1533
- * @param playground The playground client.
1534
- * @param options Installation options.
1535
- */
1536
- export declare const runWpInstallationWizard: StepHandler<RunWpInstallationWizardStep>;
1537
- /**
1538
- * @inheritDoc setSiteOptions
1539
- * @hasRunnableExample
1540
- *
1541
- * @example
1542
- *
1543
- * <code>
1544
- * {
1545
- * "step": "setSiteOptions",
1546
- * "options": {
1547
- * "blogname": "My Blog",
1548
- * "blogdescription": "A great blog"
1549
- * }
1550
- * }
1551
- * </code>
1552
- */
1553
- export type SetSiteOptionsStep = {
1554
- /** The name of the step. Must be "setSiteOptions". */
1555
- step: "setSiteOptions";
1556
- /** The options to set on the site. */
1557
- options: Record<string, unknown>;
1558
- };
1559
- /**
1560
- * Sets site options. This is equivalent to calling [`update_option`](https://developer.wordpress.org/reference/functions/update_option/) for each
1561
- * option in the [`options`](https://developer.wordpress.org/apis/options/#available-options-by-category) object.
1562
- */
1563
- export declare const setSiteOptions: StepHandler<SetSiteOptionsStep>;
1564
- /**
1565
- * @inheritDoc updateUserMeta
1566
- * @hasRunnableExample
1567
- *
1568
- * @example
1569
- *
1570
- * <code>
1571
- * {
1572
- * "step": "updateUserMeta",
1573
- * "meta": {
1574
- * "first_name": "John",
1575
- * "last_name": "Doe"
1576
- * },
1577
- * "userId": 1
1578
- * }
1579
- * </code>
1580
- */
1581
- export interface UpdateUserMetaStep {
1582
- step: "updateUserMeta";
1583
- /** An object of user meta values to set, e.g. { "first_name": "John" } */
1584
- meta: Record<string, unknown>;
1585
- /** User ID */
1586
- userId: number;
1587
- }
1588
- /**
1589
- * Updates user meta. This is equivalent to calling [`update_user_meta`](https://developer.wordpress.org/reference/functions/update_user_meta/) for each
1590
- * meta value in the `meta` object.
1591
- */
1592
- export declare const updateUserMeta: StepHandler<UpdateUserMetaStep>;
1593
- /**
1594
- * @inheritDoc rm
1595
- * @hasRunnableExample
1596
- * @landingPage /index.php
1597
- * @example
1598
- *
1599
- * <code>
1600
- * {
1601
- * "step": "rm",
1602
- * "path": "/wordpress/index.php"
1603
- * }
1604
- * </code>
1605
- */
1606
- export interface RmStep {
1607
- step: "rm";
1608
- /** The path to remove */
1609
- path: string;
1610
- }
1611
- /**
1612
- * Removes a file at the specified path.
1613
- */
1614
- export declare const rm: StepHandler<RmStep>;
1615
- /**
1616
- * @inheritDoc cp
1617
- * @hasRunnableExample
1618
- * @landingPage /index2.php
1619
- * @example
1620
- *
1621
- * <code>
1622
- * {
1623
- * "step": "cp",
1624
- * "fromPath": "/wordpress/index.php",
1625
- * "toPath": "/wordpress/index2.php"
1626
- * }
1627
- * </code>
1628
- */
1629
- export interface CpStep {
1630
- step: "cp";
1631
- /** Source path */
1632
- fromPath: string;
1633
- /** Target path */
1634
- toPath: string;
1635
- }
1636
- /**
1637
- * Copies a file from one path to another.
1638
- */
1639
- export declare const cp: StepHandler<CpStep>;
1640
- /**
1641
- * @inheritDoc rmdir
1642
- * @hasRunnableExample
1643
- * @landingPage /wp-admin/
1644
- * @example
1645
- *
1646
- * <code>
1647
- * {
1648
- * "step": "rmdir",
1649
- * "path": "/wordpress/wp-admin"
1650
- * }
1651
- * </code>
1652
- */
1653
- export interface RmdirStep {
1654
- step: "rmdir";
1655
- /** The path to remove */
1656
- path: string;
1657
- }
1658
- /**
1659
- * Removes a directory at the specified path.
1660
- */
1661
- export declare const rmdir: StepHandler<RmdirStep>;
1662
- /**
1663
- * @inheritDoc runSql
1664
- * @hasRunnableExample
1665
- * @example
1666
- *
1667
- * <code>
1668
- * {
1669
- * "step": "runSql",
1670
- * "sql": {
1671
- * "resource": "literal",
1672
- * "name": "schema.sql",
1673
- * "contents": "DELETE FROM wp_posts"
1674
- * }
1675
- * }
1676
- * </code>
1677
- */
1678
- export interface RunSqlStep<ResourceType> {
1679
- /**
1680
- * The step identifier.
1681
- */
1682
- step: "runSql";
1683
- /**
1684
- * The SQL to run. Each non-empty line must contain a valid SQL query.
1685
- */
1686
- sql: ResourceType;
1687
- }
1688
- /**
1689
- * Run one or more SQL queries.
1690
- *
1691
- * This step will treat each non-empty line in the input SQL as a query and
1692
- * try to execute it using `$wpdb`. Queries spanning multiple lines are not
1693
- * yet supported.
1694
- */
1695
- export declare const runSql: StepHandler<RunSqlStep<File>>;
1696
- /**
1697
- * @inheritDoc mkdir
1698
- * @hasRunnableExample
1699
- * @example
1700
- *
1701
- * <code>
1702
- * {
1703
- * "step": "mkdir",
1704
- * "path": "/wordpress/my-new-folder"
1705
- * }
1706
- * </code>
1707
- */
1708
- export interface MkdirStep {
1709
- step: "mkdir";
1710
- /** The path of the directory you want to create */
1711
- path: string;
1712
- }
1713
- /**
1714
- * Creates a directory at the specified path.
1715
- */
1716
- export declare const mkdir: StepHandler<MkdirStep>;
1717
- /**
1718
- * @inheritDoc mv
1719
- * @hasRunnableExample
1720
- * @landingPage /index2.php
1721
- * @example
1722
- *
1723
- * <code>
1724
- * {
1725
- * "step": "mv",
1726
- * "fromPath": "/wordpress/index.php",
1727
- * "toPath": "/wordpress/index2.php"
1728
- * }
1729
- * </code>
1730
- */
1731
- export interface MvStep {
1732
- step: "mv";
1733
- /** Source path */
1734
- fromPath: string;
1735
- /** Target path */
1736
- toPath: string;
1737
- }
1738
- /**
1739
- * Moves a file or directory from one path to another.
1740
- */
1741
- export declare const mv: StepHandler<MvStep>;
1742
- /**
1743
- * @inheritDoc runPHP
1744
- * @hasRunnableExample
1745
- * @example
1746
- *
1747
- * <code>
1748
- * {
1749
- * "step": "runPHP",
1750
- * "code": "<?php require_once 'wordpress/wp-load.php'; wp_insert_post(array('post_title' => 'wp-load.php required for WP functionality', 'post_status' => 'publish')); ?>"
1751
- * }
1752
- * </code>
1753
- */
1754
- export interface RunPHPStep {
1755
- /** The step identifier. */
1756
- step: "runPHP";
1757
- /** The PHP code to run. */
1758
- code: string;
1759
- }
1760
- /**
1761
- * Runs PHP code.
1762
- * 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'; "`.
1763
- */
1764
- export declare const runPHP: StepHandler<RunPHPStep, Promise<PHPResponse>>;
1765
- /**
1766
- * @inheritDoc runPHP
1767
- * @hasRunnableExample
1768
- * @example
1769
- *
1770
- * <code>
1771
- * {
1772
- * "step": "runPHP",
1773
- * "options": {
1774
- * "code": "<?php echo $_SERVER['CONTENT_TYPE']; ?>",
1775
- * "headers": {
1776
- * "Content-type": "text/plain"
1777
- * }
1778
- * }
1779
- * }
1780
- * </code>
1781
- */
1782
- export interface RunPHPWithOptionsStep {
1783
- step: "runPHPWithOptions";
1784
- /**
1785
- * Run options (See /wordpress-playground/api/universal/interface/PHPRunOptions/))
1786
- */
1787
- options: PHPRunOptions;
1788
- }
1789
- /**
1790
- * Runs PHP code with the given options.
1791
- */
1792
- export declare const runPHPWithOptions: StepHandler<RunPHPWithOptionsStep>;
1793
- /**
1794
- * @private
1795
- * @inheritDoc request
1796
- * @needsLogin
1797
- * @hasRunnableExample
1798
- * @example
1799
- *
1800
- * <code>
1801
- * {
1802
- * "step": "request",
1803
- * "request": {
1804
- * "method": "POST",
1805
- * "url": "/wp-admin/admin-ajax.php",
1806
- * "formData": {
1807
- * "action": "my_action",
1808
- * "foo": "bar"
1809
- * }
1810
- * }
1811
- * }
1812
- * </code>
1813
- */
1814
- export interface RequestStep {
1815
- step: "request";
1816
- /**
1817
- * Request details (See /wordpress-playground/api/universal/interface/PHPRequest)
1818
- */
1819
- request: PHPRequest;
1820
- }
1821
- /**
1822
- * Sends a HTTP request to Playground.
1823
- */
1824
- export declare const request: StepHandler<RequestStep, Promise<PHPResponse>>;
1825
- /**
1826
- * @inheritDoc writeFile
1827
- * @hasRunnableExample
1828
- * @landingPage /test.php
1829
- * @example
1830
- *
1831
- * <code>
1832
- * {
1833
- * "step": "writeFile",
1834
- * "path": "/wordpress/test.php",
1835
- * "data": "<?php echo 'Hello World!'; ?>"
1836
- * }
1837
- * </code>
1838
- */
1839
- export interface WriteFileStep<ResourceType> {
1840
- step: "writeFile";
1841
- /** The path of the file to write to */
1842
- path: string;
1843
- /** The data to write */
1844
- data: ResourceType | string | Uint8Array;
1845
- }
1846
- /**
1847
- * Writes data to a file at the specified path.
1848
- */
1849
- export declare const writeFile: StepHandler<WriteFileStep<File>>;
1850
- /**
1851
- * @inheritDoc defineWpConfigConsts
1852
- * @hasRunnableExample
1853
- * @example
1854
- *
1855
- * <code>
1856
- * {
1857
- * "step": "defineWpConfigConsts",
1858
- * "consts": {
1859
- * "WP_DEBUG": true
1860
- * }
1861
- * }
1862
- * </code>
1863
- */
1864
- export interface DefineWpConfigConstsStep {
1865
- step: "defineWpConfigConsts";
1866
- /** The constants to define */
1867
- consts: Record<string, unknown>;
1868
- /**
1869
- * The method of defining the constants in wp-config.php. Possible values are:
1870
- *
1871
- * - rewrite-wp-config: Default. Rewrites the wp-config.php file to
1872
- * explicitly call define() with the requested
1873
- * name and value. This method alters the file
1874
- * on the disk, but it doesn't conflict with
1875
- * existing define() calls in wp-config.php.
1876
- *
1877
- * - define-before-run: Defines the constant before running the requested
1878
- * script. It doesn't alter any files on the disk, but
1879
- * constants defined this way may conflict with existing
1880
- * define() calls in wp-config.php.
1881
- */
1882
- method?: "rewrite-wp-config" | "define-before-run";
1883
- /**
1884
- * @deprecated This option is noop and will be removed in a future version.
1885
- * This option is only kept in here to avoid breaking Blueprint schema validation
1886
- * for existing apps using this option.
1887
- */
1888
- virtualize?: boolean;
1889
- }
1890
- /**
1891
- * Defines constants in a [`wp-config.php`](https://developer.wordpress.org/advanced-administration/wordpress/wp-config/) file.
1892
- *
1893
- * This step can be called multiple times, and the constants will be merged.
1894
- *
1895
- * @param playground The playground client.
1896
- * @param wpConfigConst
1897
- */
1898
- export declare const defineWpConfigConsts: StepHandler<DefineWpConfigConstsStep>;
1899
- /**
1900
- * @inheritDoc activateTheme
1901
- * @example
1902
- *
1903
- * <code>
1904
- * {
1905
- * "step": "activateTheme",
1906
- * "themeFolderName": "storefront"
1907
- * }
1908
- * </code>
1909
- */
1910
- export interface ActivateThemeStep {
1911
- step: "activateTheme";
1912
- /**
1913
- * The name of the theme folder inside wp-content/themes/
1914
- */
1915
- themeFolderName: string;
1916
- }
1917
- /**
1918
- * Activates a WordPress theme (if it's installed).
1919
- *
1920
- * @param playground The playground client.
1921
- * @param themeFolderName The theme folder name.
1922
- */
1923
- export declare const activateTheme: StepHandler<ActivateThemeStep>;
1924
- /**
1925
- * @inheritDoc unzip
1926
- * @example
1927
- *
1928
- * <code>
1929
- * {
1930
- * "step": "unzip",
1931
- * "zipFile": {
1932
- * "resource": "vfs",
1933
- * "path": "/wordpress/data.zip"
1934
- * },
1935
- * "extractToPath": "/wordpress"
1936
- * }
1937
- * </code>
1938
- */
1939
- export interface UnzipStep<ResourceType> {
1940
- step: "unzip";
1941
- /** The zip file to extract */
1942
- zipFile?: ResourceType;
1943
- /**
1944
- * The path of the zip file to extract
1945
- * @deprecated Use zipFile instead.
1946
- */
1947
- zipPath?: string;
1948
- /** The path to extract the zip file to */
1949
- extractToPath: string;
1950
- }
1951
- /**
1952
- * Unzip a zip file.
1953
- *
1954
- * @param playground Playground client.
1955
- * @param zipPath The zip file to unzip.
1956
- * @param extractTo The directory to extract the zip file to.
1957
- */
1958
- export declare const unzip: StepHandler<UnzipStep<File>>;
1959
- /**
1960
- * @inheritDoc importWordPressFiles
1961
- * @example
1962
- *
1963
- * <code>
1964
- * {
1965
- * "step": "importWordPressFiles",
1966
- * "wordPressFilesZip": {
1967
- * "resource": "url",
1968
- * "url": "https://mysite.com/import.zip"
1969
- * }
1970
- * }
1971
- * </code>
1972
- */
1973
- export interface ImportWordPressFilesStep<ResourceType> {
1974
- step: "importWordPressFiles";
1975
- /**
1976
- * The zip file containing the top-level WordPress files and
1977
- * directories.
1978
- */
1979
- wordPressFilesZip: ResourceType;
1980
- /**
1981
- * The path inside the zip file where the WordPress files are.
1982
- */
1983
- pathInZip?: string;
1984
- }
1985
- /**
1986
- * Imports top-level WordPress files from a given zip file into
1987
- * the `documentRoot`. For example, if a zip file contains the
1988
- * `wp-content` and `wp-includes` directories, they will replace
1989
- * the corresponding directories in Playground's `documentRoot`.
1990
- *
1991
- * Any files that Playground recognizes as "excluded from the export"
1992
- * will carry over from the existing document root into the imported
1993
- * directories. For example, the sqlite-database-integration plugin.
1994
- *
1995
- * @param playground Playground client.
1996
- * @param wordPressFilesZip Zipped WordPress site.
1997
- */
1998
- export declare const importWordPressFiles: StepHandler<ImportWordPressFilesStep<File>>;
1999
- /**
2000
- * @inheritDoc importWxr
2001
- * @example
2002
- *
2003
- * <code>
2004
- * {
2005
- * "step": "importWxr",
2006
- * "file": {
2007
- * "resource": "url",
2008
- * "url": "https://your-site.com/starter-content.wxr"
2009
- * }
2010
- * }
2011
- * </code>
2012
- */
2013
- export interface ImportWxrStep<ResourceType> {
2014
- step: "importWxr";
2015
- /** The file to import */
2016
- file: ResourceType;
2017
- }
2018
- /**
2019
- * Imports a WXR file into WordPress.
2020
- *
2021
- * @param playground Playground client.
2022
- * @param file The file to import.
2023
- */
2024
- export declare const importWxr: StepHandler<ImportWxrStep<File>>;
2025
- /**
2026
- * @inheritDoc enableMultisite
2027
- * @hasRunnableExample
2028
- * @example
2029
- *
2030
- * <code>
2031
- * {
2032
- * "step": "enableMultisite"
2033
- * }
2034
- * </code>
2035
- */
2036
- export interface EnableMultisiteStep {
2037
- step: "enableMultisite";
2038
- }
2039
- /**
2040
- * Defines the [Multisite](https://developer.wordpress.org/advanced-administration/multisite/create-network/) constants in a `wp-config.php` file.
2041
- *
2042
- * This step can be called multiple times, and the constants will be merged.
2043
- *
2044
- * @param playground The playground client.
2045
- * @param enableMultisite
2046
- */
2047
- export declare const enableMultisite: StepHandler<EnableMultisiteStep>;
2048
- /**
2049
- * @inheritDoc wpCLI
2050
- * @hasRunnableExample
2051
- * @example
2052
- *
2053
- * <code>
2054
- * {
2055
- * "step": "wp-cli",
2056
- * "command": "wp post create --post_title='Test post' --post_excerpt='Some content'"
2057
- * }
2058
- * </code>
2059
- */
2060
- export interface WPCLIStep {
2061
- /** The step identifier. */
2062
- step: "wp-cli";
2063
- /** The WP CLI command to run. */
2064
- command: string | string[];
2065
- /** wp-cli.phar path */
2066
- wpCliPath?: string;
2067
- }
2068
- /**
2069
- * Runs PHP code using [WP-CLI](https://developer.wordpress.org/cli/commands/).
2070
- */
2071
- export declare const wpCLI: StepHandler<WPCLIStep, Promise<PHPResponse>>;
2072
- /**
2073
- * Deletes WordPress posts and comments and sets the auto increment sequence for the
2074
- * posts and comments tables to 0.
2075
- *
2076
- * @private
2077
- * @internal
2078
- * @inheritDoc resetData
2079
- * @example
2080
- *
2081
- * <code>
2082
- * {
2083
- * "step": "resetData"
2084
- * }
2085
- * </code>
2086
- */
2087
- export interface ResetDataStep {
2088
- step: "resetData";
2089
- }
2090
- /**
2091
- * @param playground Playground client.
2092
- */
2093
- export declare const resetData: StepHandler<ResetDataStep>;
2094
- /**
2095
- * Used by the export step to exclude the Playground-specific files
2096
- * from the zip file. Keep it in sync with the list of files created
2097
- * by WordPressPatcher.
2098
- */
2099
- export declare const wpContentFilesExcludedFromExport: string[];
2100
- export type Step = GenericStep<FileReference>;
2101
- export type StepDefinition = Step & {
2102
- progress?: {
2103
- weight?: number;
2104
- caption?: string;
2105
- };
2106
- };
2107
- /**
2108
- * If you add a step here, make sure to also
2109
- * add it to the exports below.
2110
- */
2111
- 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;
2112
- /**
2113
- * Progress reporting details.
2114
- */
2115
- export type StepProgress = {
2116
- tracker: ProgressTracker;
2117
- initialCaption?: string;
2118
- };
2119
- export type StepHandler<S extends GenericStep<File>, Return = any> = (
2120
- /**
2121
- * A PHP instance or Playground client.
2122
- */
2123
- php: UniversalPHP, args: Omit<S, "step">, progressArgs?: StepProgress) => Return;
2124
- /**
2125
- * Exports the WordPress database as a WXR file using
2126
- * the core WordPress export tool.
2127
- *
2128
- * @param playground Playground client
2129
- * @returns WXR file
2130
- */
2131
- export declare function exportWXR(playground: UniversalPHP): Promise<File>;
2132
- export interface ZipWpContentOptions {
2133
- /**
2134
- * @private
2135
- * A temporary workaround to enable including the WordPress default theme
2136
- * in the exported zip file.
2137
- */
2138
- selfContained?: boolean;
2139
- }
2140
- /**
2141
- * Replace the current wp-content directory with one from the provided zip file.
2142
- *
2143
- * @param playground Playground client.
2144
- * @param wpContentZip Zipped WordPress site.
2145
- */
2146
- export declare const zipWpContent: (playground: UniversalPHP, { selfContained }?: ZipWpContentOptions) => Promise<Uint8Array>;
2147
- export interface Blueprint {
2148
- /**
2149
- * The URL to navigate to after the blueprint has been run.
2150
- */
2151
- landingPage?: string;
2152
- /**
2153
- * Optional description. It doesn't do anything but is exposed as
2154
- * a courtesy to developers who may want to document which blueprint
2155
- * file does what.
2156
- *
2157
- * @deprecated Use meta.description instead.
2158
- */
2159
- description?: string;
2160
- /**
2161
- * Optional metadata. Used by the Blueprints gallery at https://github.com/WordPress/blueprints
2162
- */
2163
- meta?: {
2164
- /**
2165
- * A clear and concise name for your Blueprint.
2166
- */
2167
- title: string;
2168
- /**
2169
- * A brief explanation of what your Blueprint offers.
2170
- */
2171
- description?: string;
2172
- /**
2173
- * A GitHub username of the author of this Blueprint.
2174
- */
2175
- author: string;
2176
- /**
2177
- * Relevant categories to help users find your Blueprint in the future Blueprints section on WordPress.org.
2178
- */
2179
- categories?: string[];
2180
- };
2181
- /**
2182
- * The preferred PHP and WordPress versions to use.
2183
- */
2184
- preferredVersions?: {
2185
- /**
2186
- * The preferred PHP version to use.
2187
- * If not specified, the latest supported version will be used
2188
- */
2189
- php: SupportedPHPVersion | "latest";
2190
- /**
2191
- * The preferred WordPress version to use.
2192
- * If not specified, the latest supported version will be used
2193
- */
2194
- wp: string | "latest";
2195
- };
2196
- features?: {
2197
- /** Should boot with support for network request via wp_safe_remote_get? */
2198
- networking?: boolean;
2199
- };
2200
- /**
2201
- * PHP Constants to define on every request
2202
- * @deprecated This experimental option will change without warning.
2203
- * Use `steps` instead.
2204
- */
2205
- constants?: Record<string, string>;
2206
- /**
2207
- * WordPress plugins to install and activate
2208
- * @deprecated This experimental option will change without warning.
2209
- * Use `steps` instead.
2210
- */
2211
- plugins?: Array<string | FileReference>;
2212
- /**
2213
- * WordPress site options to define
2214
- * @deprecated This experimental option will change without warning.
2215
- * Use `steps` instead.
2216
- */
2217
- siteOptions?: Record<string, string> & {
2218
- /** The site title */
2219
- blogname?: string;
2220
- };
2221
- /**
2222
- * User to log in as.
2223
- * If true, logs the user in as admin/password.
2224
- */
2225
- login?: boolean | {
2226
- username: string;
2227
- password: string;
2228
- };
2229
- /**
2230
- * The PHP extensions to use.
2231
- */
2232
- phpExtensionBundles?: SupportedPHPExtensionBundle[];
2233
- /**
2234
- * The steps to run after every other operation in this Blueprint was
2235
- * executed.
2236
- */
2237
- steps?: Array<StepDefinition | string | undefined | false | null>;
2238
- }
2239
- export type CompiledStep = (php: UniversalPHP) => Promise<void> | void;
2240
- export interface CompiledBlueprint {
2241
- /** The requested versions of PHP and WordPress for the blueprint */
2242
- versions: {
2243
- php: SupportedPHPVersion;
2244
- wp: string;
2245
- };
2246
- /** The requested PHP extensions to load */
2247
- phpExtensions: SupportedPHPExtension[];
2248
- features: {
2249
- /** Should boot with support for network request via wp_safe_remote_get? */
2250
- networking: boolean;
2251
- };
2252
- /** The compiled steps for the blueprint */
2253
- run: (playground: UniversalPHP) => Promise<void>;
2254
- }
2255
- export type OnStepCompleted = (output: any, step: StepDefinition) => any;
2256
- export interface CompileBlueprintOptions {
2257
- /** Optional progress tracker to monitor progress */
2258
- progress?: ProgressTracker;
2259
- /** Optional semaphore to control access to a shared resource */
2260
- semaphore?: Semaphore;
2261
- /** Optional callback with step output */
2262
- onStepCompleted?: OnStepCompleted;
2263
- }
2264
- /**
2265
- * Compiles Blueprint into a form that can be executed.
2266
- *
2267
- * @param playground The PlaygroundClient to use for the compilation
2268
- * @param blueprint The bBueprint to compile
2269
- * @param options Additional options for the compilation
2270
- * @returns The compiled blueprint
2271
- */
2272
- export declare function compileBlueprint(blueprint: Blueprint, { progress, semaphore, onStepCompleted, }?: CompileBlueprintOptions): CompiledBlueprint;
2273
- export declare function runBlueprintSteps(compiledBlueprint: CompiledBlueprint, playground: UniversalPHP): Promise<void>;
1
+ export * from './lib/steps';
2
+ export * from './lib/steps/handlers';
3
+ export { runBlueprintSteps, compileBlueprint } from './lib/compile';
4
+ export type { Blueprint } from './lib/blueprint';
5
+ export type { CompiledStep, CompiledBlueprint, CompileBlueprintOptions, OnStepCompleted, } from './lib/compile';
6
+ export type { CachedResource, CorePluginReference, CorePluginResource, CoreThemeReference, CoreThemeResource, DecoratedResource, FetchResource, FileReference, LiteralReference, LiteralResource, Resource, ResourceOptions, ResourceTypes, SemaphoreResource, UrlReference, UrlResource, VFSReference, VFSResource, } from './lib/resources';
7
+ export { wpContentFilesExcludedFromExport } from './lib/utils/wp-content-files-excluded-from-exports';
2274
8
  /**
2275
9
  * @deprecated This function is a no-op. Playground no longer uses a proxy to download plugins and themes.
2276
10
  * To be removed in v0.3.0
2277
11
  */
2278
12
  export declare function setPluginProxyURL(): void;
2279
-
2280
- export {};