import type { FilesystemOperation } from '@php-wasm/fs-journal'; import type { EmscriptenDownloadMonitor } from '@php-wasm/progress'; import type { Email } from 'postal-mime'; import type { PHPWebExtension, SyncProgressCallback } from '@php-wasm/web'; import type { MountDevice } from '@wp-playground/storage'; import type { AllPHPVersion, PathAlias, PHP, PHPRequestHandler } from '@php-wasm/universal'; import { PHPWorker } from '@php-wasm/universal'; import type { BlueprintDeclaration } from '@wp-playground/blueprints'; import type { WordPressInstallMode } from '@wp-playground/wordpress'; export interface MountDescriptor { mountpoint: string; device: MountDevice; initialSyncDirection: 'opfs-to-memfs' | 'memfs-to-opfs'; } export type WorkerBootOptions = { wpVersion?: string; /** A caller-provided WordPress archive used instead of downloading one. */ wordPressZip?: File; sqliteDriverVersion?: string; phpVersion?: AllPHPVersion; sapiName?: string; scope: string; extensions?: PHPWebExtension[]; withNetworking: boolean; mounts?: Array; /** @deprecated Use `wordpressInstallMode` instead. */ shouldInstallWordPress?: boolean; corsProxyUrl?: string; /** Blueprint v2 declaration used for worker-side execution or preflight checks. */ blueprint?: BlueprintDeclaration; /** * How to handle WordPress installation. * Defaults to `download-and-install`. */ wordpressInstallMode?: WordPressInstallMode; /** * Path aliases that map URL prefixes to filesystem paths outside * the document root. Similar to Nginx's `alias` directive. */ pathAliases?: PathAlias[]; }; /** @inheritDoc PHPClient */ /** * Dispatched by the worker as the runtime boot advances to a new step. * Listen with `addEventListener('boot.progress', ...)`. */ export interface BootProgressEvent { type: 'boot.progress'; /** Human-readable description of the step that just started. */ caption: string; } export declare abstract class PlaygroundWorkerEndpoint extends PHPWorker { booted: boolean; /** * A string representing the scope of the Playground instance. */ scope: string | undefined; /** * A string representing the requested version of WordPress. */ requestedWordPressVersion: string | undefined; /** * A string representing the version of WordPress that was loaded. */ loadedWordPressVersion: string | undefined; unmounts: Record any>; private opfsMounts; private networkTransport; private requestHandler; private emails; private emailParsingQueue; protected downloadMonitor: EmscriptenDownloadMonitor; constructor(monitor: EmscriptenDownloadMonitor); /** Give PHP the same public WordPress origin used by its iframe and HTTP bridge. */ protected computeSiteUrl(scope: string): string; /** * Create the PHP runtime pool and route siteUrl requests into its WordPress files. * * siteUrl is WordPress's public scoped URL, even when PHP runs on the app origin. * For each PHP instance, define PLAYGROUND_PARENT_ORIGIN in split-origin mode. * The injected WordPress scripts use it to send navigation, pointer, thumbnail, * and tool messages back to remote.html instead of assuming their parent shares * WordPress's origin. The value comes from the app module URL, not user input. * * Known remote asset paths get a marked 404 when absent from the local files. * The service worker uses that marker to fetch the shared public asset instead * of treating every missing URL, including PHP routes, as a static download. * Existing runtime hooks set up networking, mail capture, and shared files. */ protected createRequestHandler({ siteUrl, sapiName, corsProxyUrl, knownRemoteAssetPaths, extensions, withNetworking, phpVersion, pathAliases, onProgress, }: { siteUrl: string; sapiName: string; corsProxyUrl?: string; knownRemoteAssetPaths: Set; extensions?: PHPWebExtension[]; withNetworking: boolean; phpVersion: AllPHPVersion; pathAliases?: PathAlias[]; onProgress?: (caption: string) => void; }): Promise; /** * Finish WordPress startup and identify static files omitted from minified builds. * * Enable outbound networking only after installation, then read the installed * WordPress version. A saved site may contain a different version than requested; * using the requested version could select the wrong public asset directory. * * Minified WordPress omits static files from its ZIP. wordpress-remote-asset-paths * tells createRequestHandler() which missing files to download, rather than * treating them as normal WordPress 404s. Older saved sites can lack this list; * this recovery also runs without a deployment. Fetch it for the installed WP * version from this app build's release directory and save it with the site. * Release URLs matter when reopening a saved site after an app deployment: * its list and asset pack must come from files that deployment actually serves. * If recovery fails, log a warning and continue startup without the missing list. */ protected finalizeAfterBoot(requestHandler: any, withNetworking: boolean, knownRemoteAssetPaths: Set): Promise; protected getRequestHandler(required?: true): PHPRequestHandler; protected getRequestHandler(required: false): PHPRequestHandler | undefined; /** * @returns WordPress module details, including the static assets directory and default theme. */ getWordPressModuleDetails(): Promise<{ releaseBase: string; majorVersion: string | undefined; staticAssetsDirectory: string | undefined; }>; getMinifiedWordPressVersions(): Promise<{ all: { trunk: string; beta: string; "7.1": string; "7.0": string; "6.9": string; "6.8": string; "6.7": string; "6.6": string; "6.5": string; "6.4": string; "6.3": string; }; latest: string; }>; /** * Returns the email inbox: every email this Playground has sent so far. * * Playground has no mail server. Each message WordPress hands to * sendmail – via wp_mail(), mail(), proc_open(), etc. – is captured * instead of being delivered, parsed, and appended to the inbox in * send order. A message still being written by PHP when this method * is called is awaited and included in the result. */ email(): Promise; hasOpfsMount(mountpoint: string): Promise; mountOpfs(options: MountDescriptor, onProgress?: SyncProgressCallback): Promise; flushOpfs(mountpoint: string): Promise; /** * Flushes and detaches an OPFS mount. * * On success, clears its tracking. If the final flush fails, keeps the mount * registered for retry and rejects with the original persistence error. * Other unmount failures clear tracking because the mount did not guarantee * that it remained live. */ unmountOpfs(mountpoint: string): Promise; backfillStaticFilesRemovedFromMinifiedBuild(): Promise; hasCachedStaticFilesRemovedFromMinifiedBuild(): Promise; abstract boot(_: any): Promise; /** * Pre-fetch the slow initial burst of wp_update_* requests to greatly * improve the first wp-admin load time. */ prefetchUpdateChecks(): Promise; journalFSEvents(root: string, callback: (op: FilesystemOperation) => void): Promise<() => any>; replayFSJournal(events: FilesystemOperation[]): Promise; protected mountOpfsIntoPhp(php: PHP, options: MountDescriptor, onProgress?: SyncProgressCallback): Promise; }