@php-wasm/node 0.3.1 → 0.4.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
@@ -47,6 +47,22 @@ declare class PHPResponse implements PHPResponseData {
47
47
  */
48
48
  get text(): string;
49
49
  }
50
+ /**
51
+ * Represents an event related to the PHP filesystem.
52
+ */
53
+ export interface PHPRequestEndEvent {
54
+ type: "request.end";
55
+ }
56
+ /**
57
+ * Represents an event related to the PHP instance.
58
+ * This is intentionally not an extension of CustomEvent
59
+ * to make it isomorphic between different JavaScript runtimes.
60
+ */
61
+ export type PHPEvent = PHPRequestEndEvent;
62
+ /**
63
+ * A callback function that handles PHP events.
64
+ */
65
+ export type PHPEventListener = (event: PHPEvent) => void;
50
66
  /**
51
67
  * Handles HTTP requests using PHP runtime as a backend.
52
68
  *
@@ -178,6 +194,24 @@ export interface RequestHandler {
178
194
  documentRoot: string;
179
195
  }
180
196
  export interface IsomorphicLocalPHP extends RequestHandler {
197
+ /**
198
+ * Defines a constant in the PHP runtime.
199
+ * @param key - The name of the constant.
200
+ * @param value - The value of the constant.
201
+ */
202
+ defineConstant(key: string, value: string | number | null): void;
203
+ /**
204
+ * Adds an event listener for a PHP event.
205
+ * @param eventType - The type of event to listen for.
206
+ * @param listener - The listener function to be called when the event is triggered.
207
+ */
208
+ addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
209
+ /**
210
+ * Removes an event listener for a PHP event.
211
+ * @param eventType - The type of event to remove the listener from.
212
+ * @param listener - The listener function to be removed.
213
+ */
214
+ removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
181
215
  /**
182
216
  * Sets the path to the php.ini file to use for the PHP instance.
183
217
  *
@@ -390,8 +424,25 @@ export interface IsomorphicLocalPHP extends RequestHandler {
390
424
  * @param listener Callback function to handle the message.
391
425
  */
392
426
  onMessage(listener: MessageListener): void;
427
+ /**
428
+ * Registers a handler to spawns a child process when
429
+ * `proc_open()`, `popen()`, `exec()`, `system()`, or `passthru()`
430
+ * is called.
431
+ *
432
+ * @param handler Callback function to spawn a process.
433
+ */
434
+ setSpawnHandler(handler: SpawnHandler): void;
435
+ }
436
+ export type MessageListener = (data: string) => Promise<string | Uint8Array | void> | string | void;
437
+ export interface EventEmitter {
438
+ on(event: string, listener: (...args: any[]) => void): this;
439
+ emit(event: string, ...args: any[]): boolean;
393
440
  }
394
- export type MessageListener = (data: string) => void;
441
+ export type ChildProcess = EventEmitter & {
442
+ stdout: EventEmitter;
443
+ stderr: EventEmitter;
444
+ };
445
+ export type SpawnHandler = (command: string) => ChildProcess;
395
446
  export type HTTPMethod = "GET" | "POST" | "HEAD" | "OPTIONS" | "PATCH" | "PUT" | "DELETE";
396
447
  export type PHPRequestHeaders = Record<string, string>;
397
448
  export interface PHPRequest {
@@ -476,6 +527,7 @@ export interface ListFilesOptions {
476
527
  prependPath: boolean;
477
528
  }
478
529
  declare const SupportedPHPVersions: readonly [
530
+ "8.3",
479
531
  "8.2",
480
532
  "8.1",
481
533
  "8.0",
@@ -483,8 +535,7 @@ declare const SupportedPHPVersions: readonly [
483
535
  "7.3",
484
536
  "7.2",
485
537
  "7.1",
486
- "7.0",
487
- "5.6"
538
+ "7.0"
488
539
  ];
489
540
  export type SupportedPHPVersion = (typeof SupportedPHPVersions)[number];
490
541
  export interface PHPRequestHandlerConfiguration {
@@ -563,6 +614,8 @@ declare class PHPBrowser implements RequestHandler {
563
614
  get absoluteUrl(): string;
564
615
  /** @inheritDoc */
565
616
  get documentRoot(): string;
617
+ setCookies(cookies: string[]): void;
618
+ serializeCookies(): string;
566
619
  }
567
620
  export type PHPRuntimeId = number;
568
621
  export type PHPRuntime = any;
@@ -571,6 +624,11 @@ export type PHPLoaderModule = {
571
624
  dependenciesTotalSize: number;
572
625
  init: (jsRuntime: string, options: EmscriptenOptions) => PHPRuntime;
573
626
  };
627
+ export type DataModule = {
628
+ dependencyFilename: string;
629
+ dependenciesTotalSize: number;
630
+ default: (phpRuntime: PHPRuntime) => void;
631
+ };
574
632
  export type EmscriptenOptions = {
575
633
  onAbort?: (message: string) => void;
576
634
  /**
@@ -602,9 +660,14 @@ declare abstract class BasePHP implements IsomorphicLocalPHP {
602
660
  * @param serverOptions - Optional. Options for the PHPRequestHandler. If undefined, no request handler will be initialized.
603
661
  */
604
662
  constructor(PHPRuntimeId?: PHPRuntimeId, serverOptions?: PHPRequestHandlerConfiguration);
663
+ addEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
664
+ removeEventListener(eventType: PHPEvent["type"], listener: PHPEventListener): void;
665
+ dispatchEvent<Event extends PHPEvent>(event: Event): void;
605
666
  /** @inheritDoc */
606
667
  onMessage(listener: MessageListener): Promise<void>;
607
668
  /** @inheritDoc */
669
+ setSpawnHandler(handler: SpawnHandler): Promise<void>;
670
+ /** @inheritDoc */
608
671
  get absoluteUrl(): string;
609
672
  /** @inheritDoc */
610
673
  get documentRoot(): string;
@@ -624,6 +687,7 @@ declare abstract class BasePHP implements IsomorphicLocalPHP {
624
687
  /** @inheritDoc */
625
688
  run(request: PHPRunOptions): Promise<PHPResponse>;
626
689
  addServerGlobalEntry(key: string, value: string): void;
690
+ defineConstant(key: string, value: string | number | null): void;
627
691
  /** @inheritDoc */
628
692
  mkdir(path: string): void;
629
693
  /** @inheritDoc */
@@ -646,12 +710,14 @@ declare abstract class BasePHP implements IsomorphicLocalPHP {
646
710
  isDir(path: string): boolean;
647
711
  /** @inheritDoc */
648
712
  fileExists(path: string): boolean;
713
+ exit(code?: number): any;
649
714
  }
650
715
  export declare function getPHPLoaderModule(version?: SupportedPHPVersion): Promise<PHPLoaderModule>;
651
716
  export declare function withNetworking(phpModuleArgs?: EmscriptenOptions): Promise<EmscriptenOptions>;
652
717
  export interface PHPLoaderOptions {
653
718
  emscriptenOptions?: EmscriptenOptions;
654
719
  requestHandler?: PHPRequestHandlerConfiguration;
720
+ dataModules?: Array<DataModule | Promise<DataModule>>;
655
721
  }
656
722
  export type MountSettings = {
657
723
  root: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@php-wasm/node",
3
- "version": "0.3.1",
3
+ "version": "0.4.0",
4
4
  "description": "PHP.wasm for Node.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "license": "GPL-2.0-or-later",
29
29
  "main": "index.cjs",
30
30
  "types": "index.d.ts",
31
- "gitHead": "73b285f8b496c7442474fd7325b3f6b1287cbf95",
31
+ "gitHead": "0851e71512709843af0539f747caded8ea904fe6",
32
32
  "engines": {
33
33
  "node": ">=16.15.1",
34
34
  "npm": ">=8.11.0"
@@ -38,7 +38,8 @@
38
38
  "express": "4.18.2",
39
39
  "ws": "8.13.0",
40
40
  "yargs": "17.7.2",
41
- "@php-wasm/universal": "0.3.1",
42
- "@php-wasm/util": "0.3.1"
41
+ "@php-wasm/node-polyfills": "0.4.0",
42
+ "@php-wasm/universal": "0.4.0",
43
+ "@php-wasm/util": "0.4.0"
43
44
  }
44
45
  }