@php-wasm/node 0.1.18 → 0.1.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.cjs +23 -23
- package/index.d.ts +116 -24
- package/package.json +11 -4
package/index.d.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
// Generated by dts-bundle-generator v7.2.0
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
* PHP response. Body is an `ArrayBuffer` because it can
|
|
5
|
-
* contain binary data.
|
|
6
|
-
*/
|
|
7
|
-
export declare class PHPResponse {
|
|
3
|
+
export interface PHPResponseData {
|
|
8
4
|
/**
|
|
9
5
|
* Response headers.
|
|
10
6
|
*/
|
|
@@ -13,7 +9,7 @@ export declare class PHPResponse {
|
|
|
13
9
|
* Response body. Contains the output from `echo`,
|
|
14
10
|
* `print`, inline HTML etc.
|
|
15
11
|
*/
|
|
16
|
-
|
|
12
|
+
readonly bytes: ArrayBuffer;
|
|
17
13
|
/**
|
|
18
14
|
* Stderr contents, if any.
|
|
19
15
|
*/
|
|
@@ -27,7 +23,28 @@ export declare class PHPResponse {
|
|
|
27
23
|
* Response HTTP status code, e.g. 200.
|
|
28
24
|
*/
|
|
29
25
|
readonly httpStatusCode: number;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* PHP response. Body is an `ArrayBuffer` because it can
|
|
29
|
+
* contain binary data.
|
|
30
|
+
*
|
|
31
|
+
* This type is used in Comlink.transferHandlers.set('PHPResponse', { ... })
|
|
32
|
+
* so be sure to update that if you change this type.
|
|
33
|
+
*/
|
|
34
|
+
export declare class PHPResponse implements PHPResponseData {
|
|
35
|
+
/** @inheritDoc */
|
|
36
|
+
readonly headers: Record<string, string[]>;
|
|
37
|
+
/** @inheritDoc */
|
|
38
|
+
readonly bytes: ArrayBuffer;
|
|
39
|
+
/** @inheritDoc */
|
|
40
|
+
readonly errors: string;
|
|
41
|
+
/** @inheritDoc */
|
|
42
|
+
readonly exitCode: number;
|
|
43
|
+
/** @inheritDoc */
|
|
44
|
+
readonly httpStatusCode: number;
|
|
30
45
|
constructor(httpStatusCode: number, headers: Record<string, string[]>, body: ArrayBuffer, errors?: string, exitCode?: number);
|
|
46
|
+
static fromRawData(data: PHPResponseData): PHPResponse;
|
|
47
|
+
toRawData(): PHPResponseData;
|
|
31
48
|
/**
|
|
32
49
|
* Response body as JSON.
|
|
33
50
|
*/
|
|
@@ -36,20 +53,36 @@ export declare class PHPResponse {
|
|
|
36
53
|
* Response body as text.
|
|
37
54
|
*/
|
|
38
55
|
get text(): string;
|
|
56
|
+
}
|
|
57
|
+
export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
|
|
58
|
+
export type PHPRequestHeaders = Record<string, string>;
|
|
59
|
+
export interface PHPRequest {
|
|
39
60
|
/**
|
|
40
|
-
*
|
|
61
|
+
* Request method. Default: `GET`.
|
|
62
|
+
*/
|
|
63
|
+
method?: HTTPMethod;
|
|
64
|
+
/**
|
|
65
|
+
* Request path or absolute URL.
|
|
41
66
|
*/
|
|
42
|
-
get bytes(): ArrayBuffer;
|
|
43
|
-
}
|
|
44
|
-
export type PHPRequest = Pick<PHPRunOptions, "method" | "headers"> & {
|
|
45
67
|
url: string;
|
|
68
|
+
/**
|
|
69
|
+
* Request headers.
|
|
70
|
+
*/
|
|
71
|
+
headers?: PHPRequestHeaders;
|
|
72
|
+
/**
|
|
73
|
+
* Uploaded files
|
|
74
|
+
*/
|
|
46
75
|
files?: Record<string, File>;
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
body?:
|
|
51
|
-
|
|
52
|
-
|
|
76
|
+
/**
|
|
77
|
+
* Request body without the files.
|
|
78
|
+
*/
|
|
79
|
+
body?: string;
|
|
80
|
+
/**
|
|
81
|
+
* Form data. If set, the request body will be ignored and
|
|
82
|
+
* the content-type header will be set to `application/x-www-form-urlencoded`.
|
|
83
|
+
*/
|
|
84
|
+
formData?: Record<string, unknown>;
|
|
85
|
+
}
|
|
53
86
|
export interface PHPRequestHandlerConfiguration {
|
|
54
87
|
/**
|
|
55
88
|
* The directory in the PHP filesystem where the server will look
|
|
@@ -66,7 +99,62 @@ export interface PHPRequestHandlerConfiguration {
|
|
|
66
99
|
*/
|
|
67
100
|
isStaticFilePath?: (path: string) => boolean;
|
|
68
101
|
}
|
|
69
|
-
|
|
102
|
+
/**
|
|
103
|
+
* A fake PHP server that handles HTTP requests but does not
|
|
104
|
+
* bind to any port.
|
|
105
|
+
*
|
|
106
|
+
* @public
|
|
107
|
+
* @example Use PHPRequestHandler implicitly with a new PHP instance:
|
|
108
|
+
* ```js
|
|
109
|
+
* import { PHP } from '@php-wasm/web';
|
|
110
|
+
*
|
|
111
|
+
* const php = await PHP.load( '7.4', {
|
|
112
|
+
* requestHandler: {
|
|
113
|
+
* // PHP FS path to serve the files from:
|
|
114
|
+
* documentRoot: '/www',
|
|
115
|
+
*
|
|
116
|
+
* // Used to populate $_SERVER['SERVER_NAME'] etc.:
|
|
117
|
+
* absoluteUrl: 'http://127.0.0.1'
|
|
118
|
+
* }
|
|
119
|
+
* } );
|
|
120
|
+
*
|
|
121
|
+
* php.mkdirTree('/www');
|
|
122
|
+
* php.writeFile('/www/index.php', '<?php echo "Hi from PHP!"; ');
|
|
123
|
+
*
|
|
124
|
+
* const response = await php.request({ path: '/index.php' });
|
|
125
|
+
* console.log(response.text);
|
|
126
|
+
* // "Hi from PHP!"
|
|
127
|
+
* ```
|
|
128
|
+
*
|
|
129
|
+
* @example Explicitly create a PHPRequestHandler instance and run a PHP script:
|
|
130
|
+
* ```js
|
|
131
|
+
* import {
|
|
132
|
+
* loadPHPRuntime,
|
|
133
|
+
* PHP,
|
|
134
|
+
* PHPRequestHandler,
|
|
135
|
+
* getPHPLoaderModule,
|
|
136
|
+
* } from '@php-wasm/web';
|
|
137
|
+
*
|
|
138
|
+
* const runtime = await loadPHPRuntime( await getPHPLoaderModule('7.4') );
|
|
139
|
+
* const php = new PHP( runtime );
|
|
140
|
+
*
|
|
141
|
+
* php.mkdirTree('/www');
|
|
142
|
+
* php.writeFile('/www/index.php', '<?php echo "Hi from PHP!"; ');
|
|
143
|
+
*
|
|
144
|
+
* const server = new PHPRequestHandler(php, {
|
|
145
|
+
* // PHP FS path to serve the files from:
|
|
146
|
+
* documentRoot: '/www',
|
|
147
|
+
*
|
|
148
|
+
* // Used to populate $_SERVER['SERVER_NAME'] etc.:
|
|
149
|
+
* absoluteUrl: 'http://127.0.0.1'
|
|
150
|
+
* });
|
|
151
|
+
*
|
|
152
|
+
* const response = server.request({ path: '/index.php' });
|
|
153
|
+
* console.log(response.text);
|
|
154
|
+
* // "Hi from PHP!"
|
|
155
|
+
* ```
|
|
156
|
+
*/
|
|
157
|
+
export declare class PHPRequestHandler {
|
|
70
158
|
#private;
|
|
71
159
|
/**
|
|
72
160
|
* The PHP instance
|
|
@@ -153,7 +241,6 @@ export declare class PHPBrowser implements WithRequestHandler {
|
|
|
153
241
|
request(request: PHPRequest, redirects?: number): Promise<PHPResponse>;
|
|
154
242
|
}
|
|
155
243
|
export type RuntimeType = "NODE" | "WEB" | "WORKER";
|
|
156
|
-
export type PHPRequestHeaders = Record<string, string>;
|
|
157
244
|
export interface FileInfo {
|
|
158
245
|
key: string;
|
|
159
246
|
name: string;
|
|
@@ -176,7 +263,7 @@ export interface PHPRunOptions {
|
|
|
176
263
|
/**
|
|
177
264
|
* Request method. Default: `GET`.
|
|
178
265
|
*/
|
|
179
|
-
method?:
|
|
266
|
+
method?: HTTPMethod;
|
|
180
267
|
/**
|
|
181
268
|
* Request headers.
|
|
182
269
|
*/
|
|
@@ -215,11 +302,11 @@ export interface WithNodeFilesystem {
|
|
|
215
302
|
/**
|
|
216
303
|
* Mounts a Node.js filesystem to a given path in the PHP filesystem.
|
|
217
304
|
*
|
|
218
|
-
* @param
|
|
219
|
-
* @param
|
|
305
|
+
* @param localPath - The path of a real local directory you want to mount.
|
|
306
|
+
* @param virtualFSPath - Where to mount it in the virtual filesystem.
|
|
220
307
|
* @see {@link https://emscripten.org/docs/api_reference/Filesystem-API.html#FS.mount}
|
|
221
308
|
*/
|
|
222
|
-
mount(
|
|
309
|
+
mount(localPath: string | MountSettings, virtualFSPath: string): void;
|
|
223
310
|
}
|
|
224
311
|
export interface WithFilesystem {
|
|
225
312
|
/**
|
|
@@ -229,6 +316,10 @@ export interface WithFilesystem {
|
|
|
229
316
|
*
|
|
230
317
|
* @param path - The directory path to create.
|
|
231
318
|
*/
|
|
319
|
+
mkdir(path: string): void;
|
|
320
|
+
/**
|
|
321
|
+
* @deprecated Use mkdir instead.
|
|
322
|
+
*/
|
|
232
323
|
mkdirTree(path: string): void;
|
|
233
324
|
/**
|
|
234
325
|
* Reads a file from the PHP filesystem and returns it as a string.
|
|
@@ -391,6 +482,8 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
|
|
|
391
482
|
setSkipShebang(shouldSkip: boolean): void;
|
|
392
483
|
addServerGlobalEntry(key: string, value: string): void;
|
|
393
484
|
/** @inheritDoc */
|
|
485
|
+
mkdir(path: string): void;
|
|
486
|
+
/** @inheritDoc */
|
|
394
487
|
mkdirTree(path: string): void;
|
|
395
488
|
/** @inheritDoc */
|
|
396
489
|
readFileAsText(path: string): string;
|
|
@@ -407,7 +500,7 @@ declare abstract class BasePHP implements WithPHPIniBindings, WithFilesystem, Wi
|
|
|
407
500
|
/** @inheritDoc */
|
|
408
501
|
fileExists(path: string): boolean;
|
|
409
502
|
/** @inheritDoc */
|
|
410
|
-
mount(
|
|
503
|
+
mount(localPath: string | MountSettings, virtualFSPath: string): void;
|
|
411
504
|
}
|
|
412
505
|
/**
|
|
413
506
|
* Output of the PHP.wasm runtime.
|
|
@@ -474,7 +567,6 @@ export declare class PHP extends BasePHP {
|
|
|
474
567
|
* resolves when the PHP instance is ready.
|
|
475
568
|
*
|
|
476
569
|
* @see load
|
|
477
|
-
* @inheritdoc load
|
|
478
570
|
*/
|
|
479
571
|
static loadSync(phpVersion: SupportedPHPVersion, options?: PHPLoaderOptions): {
|
|
480
572
|
php: PHP;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@php-wasm/node",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "PHP.wasm for Node.js",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,16 +15,23 @@
|
|
|
15
15
|
"url": "https://github.com/adamziel"
|
|
16
16
|
}
|
|
17
17
|
],
|
|
18
|
+
"typedoc": {
|
|
19
|
+
"entryPoint": "./src/index.ts",
|
|
20
|
+
"readmeFile": "./README.md",
|
|
21
|
+
"displayName": "@php-wasm/node",
|
|
22
|
+
"tsconfig": "./tsconfig.lib.json"
|
|
23
|
+
},
|
|
18
24
|
"publishConfig": {
|
|
19
25
|
"access": "public",
|
|
20
26
|
"directory": "../../../dist/packages/php-wasm/node"
|
|
21
27
|
},
|
|
22
28
|
"license": "(GPL-2.0-or-later OR MPL-2.0)",
|
|
23
|
-
"
|
|
29
|
+
"main": "index.cjs",
|
|
30
|
+
"types": "index.d.ts",
|
|
31
|
+
"gitHead": "bbe56ef04fa9740506efed428ef8c89de7223d96",
|
|
24
32
|
"dependencies": {
|
|
25
33
|
"comlink": "4.4.1",
|
|
26
34
|
"express": "4.18.2",
|
|
27
35
|
"ws": "8.13.0"
|
|
28
|
-
}
|
|
29
|
-
"main": "index.cjs"
|
|
36
|
+
}
|
|
30
37
|
}
|