@php-wasm/node 0.1.60 → 0.2.0

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
@@ -120,7 +120,7 @@ export interface RequestHandler {
120
120
  * }
121
121
  * })
122
122
  * php.writeFile("/www/index.php", `<?php echo file_get_contents("php://input");`);
123
- * const result = await php.run({
123
+ * const result = await php.request({
124
124
  * method: "GET",
125
125
  * headers: {
126
126
  * "Content-Type": "text/plain"
@@ -350,7 +350,48 @@ export interface IsomorphicLocalPHP extends RequestHandler {
350
350
  * @param options - PHP runtime options.
351
351
  */
352
352
  run(options: PHPRunOptions): Promise<PHPResponse>;
353
+ /**
354
+ * Listens to message sent by the PHP code.
355
+ *
356
+ * To dispatch messages, call:
357
+ *
358
+ * post_message_to_js(string $data)
359
+ *
360
+ * Arguments:
361
+ * $data (string) – Data to pass to JavaScript.
362
+ *
363
+ * @example
364
+ *
365
+ * ```ts
366
+ * const php = await PHP.load('8.0');
367
+ *
368
+ * php.onMessage(
369
+ * // The data is always passed as a string
370
+ * function (data: string) {
371
+ * // Let's decode and log the data:
372
+ * console.log(JSON.parse(data));
373
+ * }
374
+ * );
375
+ *
376
+ * // Now that we have a listener in place, let's
377
+ * // dispatch a message:
378
+ * await php.run({
379
+ * code: `<?php
380
+ * post_message_to_js(
381
+ * json_encode([
382
+ * 'post_id' => '15',
383
+ * 'post_title' => 'This is a blog post!'
384
+ * ])
385
+ * ));
386
+ * `,
387
+ * });
388
+ * ```
389
+ *
390
+ * @param listener Callback function to handle the message.
391
+ */
392
+ onMessage(listener: MessageListener): void;
353
393
  }
394
+ export type MessageListener = (data: string) => void;
354
395
  export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
355
396
  export type PHPRequestHeaders = Record<string, string>;
356
397
  export interface PHPRequest {
@@ -550,7 +591,9 @@ export type EmscriptenOptions = {
550
591
  quit?: (status: number, toThrow: any) => void;
551
592
  onRuntimeInitialized?: () => void;
552
593
  monitorRunDependencies?: (left: number) => void;
594
+ onMessage?: (listener: EmscriptenMessageListener) => void;
553
595
  } & Record<string, any>;
596
+ export type EmscriptenMessageListener = (type: string, data: string) => void;
554
597
  declare const __private__dont__use: unique symbol;
555
598
  declare abstract class BasePHP implements IsomorphicLocalPHP {
556
599
  #private;
@@ -565,6 +608,8 @@ declare abstract class BasePHP implements IsomorphicLocalPHP {
565
608
  */
566
609
  constructor(PHPRuntimeId?: PHPRuntimeId, serverOptions?: PHPRequestHandlerConfiguration);
567
610
  /** @inheritDoc */
611
+ onMessage(listener: MessageListener): Promise<void>;
612
+ /** @inheritDoc */
568
613
  get absoluteUrl(): string;
569
614
  /** @inheritDoc */
570
615
  get documentRoot(): string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/node",
3
- "version": "0.1.60",
3
+ "version": "0.2.0",
4
4
  "description": "PHP.wasm for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,13 +28,17 @@
28
28
  "license": "GPL-2.0-or-later",
29
29
  "main": "index.cjs",
30
30
  "types": "index.d.ts",
31
- "gitHead": "3046803036b19d2c73c63cb01dfb37b1c222d847",
31
+ "gitHead": "cd4062de74f7f18058d3f962e124d0fdff78b5a7",
32
+ "engines": {
33
+ "node": ">=16.15.1",
34
+ "npm": ">=8.11.0"
35
+ },
32
36
  "dependencies": {
33
37
  "comlink": "^4.4.1",
34
38
  "express": "4.18.2",
35
39
  "ws": "8.13.0",
36
40
  "yargs": "17.7.2",
37
- "@php-wasm/universal": "0.1.60",
38
- "@php-wasm/util": "0.1.60"
41
+ "@php-wasm/universal": "0.2.0",
42
+ "@php-wasm/util": "0.2.0"
39
43
  }
40
44
  }
package/php_5_6.wasm CHANGED
Binary file
package/php_7_0.wasm CHANGED
Binary file
package/php_7_1.wasm CHANGED
Binary file
package/php_7_2.wasm CHANGED
Binary file
package/php_7_3.wasm CHANGED
Binary file
package/php_7_4.wasm CHANGED
Binary file
package/php_8_0.wasm CHANGED
Binary file
package/php_8_1.wasm CHANGED
Binary file
package/php_8_2.wasm CHANGED
Binary file