@php-wasm/node
Advanced tools
Comparing version 0.6.16 to 0.7.0
278
index.d.ts
@@ -86,133 +86,13 @@ // Generated by dts-bundle-generator v7.2.0 | ||
export type PHPEventListener = (event: PHPEvent) => void; | ||
/** | ||
* Handles HTTP requests using PHP runtime as a backend. | ||
* | ||
* @public | ||
* @example Use PHPRequestHandler implicitly with a new PHP instance: | ||
* ```js | ||
* import { PHP } from '@php-wasm/web'; | ||
* | ||
* const php = await PHP.load( '7.4', { | ||
* requestHandler: { | ||
* // PHP FS path to serve the files from: | ||
* documentRoot: '/www', | ||
* | ||
* // Used to populate $_SERVER['SERVER_NAME'] etc.: | ||
* absoluteUrl: 'http://127.0.0.1' | ||
* } | ||
* } ); | ||
* | ||
* php.mkdirTree('/www'); | ||
* php.writeFile('/www/index.php', '<?php echo "Hi from PHP!"; '); | ||
* | ||
* const response = await php.request({ path: '/index.php' }); | ||
* console.log(response.text); | ||
* // "Hi from PHP!" | ||
* ``` | ||
* | ||
* @example Explicitly create a PHPRequestHandler instance and run a PHP script: | ||
* ```js | ||
* import { | ||
* loadPHPRuntime, | ||
* PHP, | ||
* PHPRequestHandler, | ||
* getPHPLoaderModule, | ||
* } from '@php-wasm/web'; | ||
* | ||
* const runtime = await loadPHPRuntime( await getPHPLoaderModule('7.4') ); | ||
* const php = new PHP( runtime ); | ||
* | ||
* php.mkdirTree('/www'); | ||
* php.writeFile('/www/index.php', '<?php echo "Hi from PHP!"; '); | ||
* | ||
* const server = new PHPRequestHandler(php, { | ||
* // PHP FS path to serve the files from: | ||
* documentRoot: '/www', | ||
* | ||
* // Used to populate $_SERVER['SERVER_NAME'] etc.: | ||
* absoluteUrl: 'http://127.0.0.1' | ||
* }); | ||
* | ||
* const response = server.request({ path: '/index.php' }); | ||
* console.log(response.text); | ||
* // "Hi from PHP!" | ||
* ``` | ||
*/ | ||
export interface RequestHandler { | ||
/** | ||
* Serves the request – either by serving a static file, or by | ||
* dispatching it to the PHP runtime. | ||
* | ||
* The request() method mode behaves like a web server and only works if | ||
* the PHP was initialized with a `requestHandler` option (which the online version | ||
* of WordPress Playground does by default). | ||
* | ||
* In the request mode, you pass an object containing the request information | ||
* (method, headers, body, etc.) and the path to the PHP file to run: | ||
* | ||
* ```ts | ||
* const php = PHP.load('7.4', { | ||
* requestHandler: { | ||
* documentRoot: "/www" | ||
* } | ||
* }) | ||
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`); | ||
* const result = await php.request({ | ||
* method: "GET", | ||
* headers: { | ||
* "Content-Type": "text/plain" | ||
* }, | ||
* body: "Hello world!", | ||
* path: "/www/index.php" | ||
* }); | ||
* // result.text === "Hello world!" | ||
* ``` | ||
* | ||
* The `request()` method cannot be used in conjunction with `cli()`. | ||
* | ||
* @example | ||
* ```js | ||
* const output = await php.request({ | ||
* method: 'GET', | ||
* url: '/index.php', | ||
* headers: { | ||
* 'X-foo': 'bar', | ||
* }, | ||
* body: { | ||
* foo: 'bar', | ||
* }, | ||
* }); | ||
* console.log(output.stdout); // "Hello world!" | ||
* ``` | ||
* | ||
* @param request - PHP Request data. | ||
*/ | ||
request(request: PHPRequest, maxRedirects?: number): Promise<PHPResponse>; | ||
/** | ||
* Converts a path to an absolute URL based at the PHPRequestHandler | ||
* root. | ||
* | ||
* @param path The server path to convert to an absolute URL. | ||
* @returns The absolute URL. | ||
*/ | ||
export interface IsomorphicLocalPHP { | ||
/** @deprecated Use PHPRequestHandler instead. */ | ||
request(request: PHPRequest): Promise<PHPResponse>; | ||
/** @deprecated Use PHPRequestHandler instead. */ | ||
pathToInternalUrl(path: string): string; | ||
/** | ||
* Converts an absolute URL based at the PHPRequestHandler to a relative path | ||
* without the server pathname and scope. | ||
* | ||
* @param internalUrl An absolute URL based at the PHPRequestHandler root. | ||
* @returns The relative path. | ||
*/ | ||
/** @deprecated Use PHPRequestHandler instead. */ | ||
internalUrlToPath(internalUrl: string): string; | ||
/** | ||
* The absolute URL of this PHPRequestHandler instance. | ||
*/ | ||
/** @deprecated Use PHPRequestHandler instead. */ | ||
absoluteUrl: string; | ||
/** | ||
* The directory in the PHP filesystem where the server will look | ||
* for the files to serve. Default: `/var/www`. | ||
*/ | ||
/** @deprecated Use PHPRequestHandler instead. */ | ||
documentRoot: string; | ||
} | ||
export interface IsomorphicLocalPHP extends RequestHandler { | ||
/** | ||
@@ -453,10 +333,2 @@ * Sets the SAPI name exposed by the PHP module. | ||
onMessage(listener: MessageListener): void; | ||
/** | ||
* Registers a handler to spawns a child process when | ||
* `proc_open()`, `popen()`, `exec()`, `system()`, or `passthru()` | ||
* is called. | ||
* | ||
* @param handler Callback function to spawn a process. | ||
*/ | ||
setSpawnHandler(handler: SpawnHandler | string): void; | ||
} | ||
@@ -525,2 +397,6 @@ export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void; | ||
/** | ||
* $_SERVER entries to set for this run. | ||
*/ | ||
$_SERVER?: Record<string, string>; | ||
/** | ||
* The code snippet to eval instead of a php file. | ||
@@ -575,3 +451,3 @@ */ | ||
} | ||
declare class PHPRequestHandler implements RequestHandler { | ||
declare class PHPRequestHandler { | ||
#private; | ||
@@ -588,58 +464,77 @@ rewriteRules: RewriteRule[]; | ||
constructor(php: BasePHP, config?: PHPRequestHandlerConfiguration); | ||
/** @inheritDoc */ | ||
/** | ||
* Converts a path to an absolute URL based at the PHPRequestHandler | ||
* root. | ||
* | ||
* @param path The server path to convert to an absolute URL. | ||
* @returns The absolute URL. | ||
*/ | ||
pathToInternalUrl(path: string): string; | ||
/** @inheritDoc */ | ||
/** | ||
* Converts an absolute URL based at the PHPRequestHandler to a relative path | ||
* without the server pathname and scope. | ||
* | ||
* @param internalUrl An absolute URL based at the PHPRequestHandler root. | ||
* @returns The relative path. | ||
*/ | ||
internalUrlToPath(internalUrl: string): string; | ||
get isRequestRunning(): boolean; | ||
/** @inheritDoc */ | ||
get absoluteUrl(): string; | ||
/** @inheritDoc */ | ||
get documentRoot(): string; | ||
/** @inheritDoc */ | ||
request(request: PHPRequest): Promise<PHPResponse>; | ||
} | ||
export interface PHPBrowserConfiguration { | ||
/** | ||
* Should handle redirects internally? | ||
* The absolute URL of this PHPRequestHandler instance. | ||
*/ | ||
handleRedirects?: boolean; | ||
get absoluteUrl(): string; | ||
/** | ||
* The maximum number of redirects to follow internally. Once | ||
* exceeded, request() will return the redirecting response. | ||
* The directory in the PHP filesystem where the server will look | ||
* for the files to serve. Default: `/var/www`. | ||
*/ | ||
maxRedirects?: number; | ||
} | ||
declare class PHPBrowser implements RequestHandler { | ||
#private; | ||
requestHandler: PHPRequestHandler; | ||
get documentRoot(): string; | ||
/** | ||
* @param server - The PHP server to browse. | ||
* @param config - The browser configuration. | ||
*/ | ||
constructor(requestHandler: PHPRequestHandler, config?: PHPBrowserConfiguration); | ||
/** | ||
* Sends the request to the server. | ||
* Serves the request – either by serving a static file, or by | ||
* dispatching it to the PHP runtime. | ||
* | ||
* When cookies are present in the response, this method stores | ||
* them and sends them with any subsequent requests. | ||
* The request() method mode behaves like a web server and only works if | ||
* the PHP was initialized with a `requestHandler` option (which the online version | ||
* of WordPress Playground does by default). | ||
* | ||
* When a redirection is present in the response, this method | ||
* follows it by discarding a response and sending a subsequent | ||
* request. | ||
* In the request mode, you pass an object containing the request information | ||
* (method, headers, body, etc.) and the path to the PHP file to run: | ||
* | ||
* @param request - The request. | ||
* @param redirects - Internal. The number of redirects handled so far. | ||
* @returns PHPRequestHandler response. | ||
* ```ts | ||
* const php = PHP.load('7.4', { | ||
* requestHandler: { | ||
* documentRoot: "/www" | ||
* } | ||
* }) | ||
* php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`); | ||
* const result = await php.request({ | ||
* method: "GET", | ||
* headers: { | ||
* "Content-Type": "text/plain" | ||
* }, | ||
* body: "Hello world!", | ||
* path: "/www/index.php" | ||
* }); | ||
* // result.text === "Hello world!" | ||
* ``` | ||
* | ||
* The `request()` method cannot be used in conjunction with `cli()`. | ||
* | ||
* @example | ||
* ```js | ||
* const output = await php.request({ | ||
* method: 'GET', | ||
* url: '/index.php', | ||
* headers: { | ||
* 'X-foo': 'bar', | ||
* }, | ||
* body: { | ||
* foo: 'bar', | ||
* }, | ||
* }); | ||
* console.log(output.stdout); // "Hello world!" | ||
* ``` | ||
* | ||
* @param request - PHP Request data. | ||
*/ | ||
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>; | ||
/** @inheritDoc */ | ||
pathToInternalUrl(path: string): string; | ||
/** @inheritDoc */ | ||
internalUrlToPath(internalUrl: string): string; | ||
/** @inheritDoc */ | ||
get absoluteUrl(): string; | ||
/** @inheritDoc */ | ||
get documentRoot(): string; | ||
setCookies(cookies: string[]): void; | ||
serializeCookies(): string; | ||
request(request: PHPRequest): Promise<PHPResponse>; | ||
} | ||
@@ -668,6 +563,14 @@ export type PHPRuntimeId = number; | ||
onMessage?: (listener: EmscriptenMessageListener) => void; | ||
instantiateWasm?: (info: WebAssembly.Imports, receiveInstance: (instance: WebAssembly.Instance, module: WebAssembly.Module) => void) => void; | ||
} & Record<string, any>; | ||
export type EmscriptenMessageListener = (type: string, data: string) => void; | ||
export interface SemaphoreOptions { | ||
/** | ||
* The maximum number of concurrent locks. | ||
*/ | ||
concurrency: number; | ||
/** | ||
* The maximum time to wait for a lock to become available. | ||
*/ | ||
timeout?: number; | ||
} | ||
@@ -677,4 +580,6 @@ declare class Semaphore { | ||
private concurrency; | ||
private timeout?; | ||
private queue; | ||
constructor({ concurrency }: SemaphoreOptions); | ||
constructor({ concurrency, timeout }: SemaphoreOptions); | ||
get remaining(): number; | ||
get running(): number; | ||
@@ -688,3 +593,3 @@ acquire(): Promise<() => void>; | ||
protected [__private__dont__use]: any; | ||
requestHandler?: PHPBrowser; | ||
requestHandler?: PHPRequestHandler; | ||
/** | ||
@@ -728,6 +633,5 @@ * An exclusive lock that prevent multiple requests from running at | ||
/** @inheritDoc */ | ||
request(request: PHPRequest, maxRedirects?: number): Promise<PHPResponse>; | ||
request(request: PHPRequest): Promise<PHPResponse>; | ||
/** @inheritDoc */ | ||
run(request: PHPRunOptions): Promise<PHPResponse>; | ||
addServerGlobalEntry(key: string, value: string): void; | ||
defineConstant(key: string, value: string | boolean | number | null): void; | ||
@@ -761,4 +665,8 @@ /** @inheritDoc */ | ||
* @param runtime | ||
* @param cwd. Internal, the VFS path to recreate in the new runtime. | ||
* This arg is temporary and will be removed once BasePHP | ||
* is fully decoupled from the request handler and | ||
* accepts a constructor-level cwd argument. | ||
*/ | ||
hotSwapPHPRuntime(runtime: number): void; | ||
hotSwapPHPRuntime(runtime: number, cwd?: string): void; | ||
exit(code?: number): void; | ||
@@ -765,0 +673,0 @@ } |
{ | ||
"name": "@php-wasm/node", | ||
"version": "0.6.16", | ||
"version": "0.7.0", | ||
"description": "PHP.wasm for Node.js", | ||
@@ -31,3 +31,3 @@ "repository": { | ||
"types": "index.d.ts", | ||
"gitHead": "1981567e7eacecbc4a18c870267c20bf489afd8f", | ||
"gitHead": "c5eba3d709f2821c4303521e8c81b962e3bcca23", | ||
"engines": { | ||
@@ -41,6 +41,6 @@ "node": ">=18.18.0", | ||
"yargs": "17.7.2", | ||
"@php-wasm/node-polyfills": "0.6.16", | ||
"@php-wasm/universal": "0.6.16", | ||
"@php-wasm/util": "0.6.16" | ||
"@php-wasm/node-polyfills": "0.7.0", | ||
"@php-wasm/universal": "0.7.0", | ||
"@php-wasm/util": "0.7.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
127973593
141104
+ Added@php-wasm/node-polyfills@0.7.0(transitive)
+ Added@php-wasm/universal@0.7.0(transitive)
+ Added@php-wasm/util@0.7.0(transitive)
- Removed@php-wasm/node-polyfills@0.6.16(transitive)
- Removed@php-wasm/universal@0.6.16(transitive)
- Removed@php-wasm/util@0.6.16(transitive)
Updated@php-wasm/universal@0.7.0
Updated@php-wasm/util@0.7.0