Skip to content

Preparing for napi-rs v3 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions crates/lang_handler/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ default = []
napi = ["dep:napi", "dep:napi-build"]

[build-dependencies]
napi-build = { version = "2.0.1", optional = true }
napi-build = { version = "2.2.1", optional = true }

[dependencies]
bytes = "1.10.1"
napi = { version = "2.16.17", optional = true }
napi = { version = "3.0.0-beta.8", default-features = false, features = ["napi4"], optional = true }
regex = "1.11.1"
url = "2.5.4"
6 changes: 3 additions & 3 deletions crates/php_node/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ path = "src/lib.rs"

[dependencies]
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
napi = { version = "2.16.17", default-features = false, features = ["napi4"] }
napi-derive = "2.16.13"
napi = { version = "3.0.0-beta.8", default-features = false, features = ["napi4"] }
napi-derive = "3.0.0-beta.8"
php = { path = "../php" }

[build-dependencies]
napi-build = "2.0.1"
napi-build = "2.2.1"
4 changes: 2 additions & 2 deletions crates/php_node/src/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,13 @@ impl PhpHeaders {
/// });
/// ```
#[napi]
pub fn for_each<F: Fn(String, String, &This) -> Result<()>>(
pub fn for_each<F: Fn(String, String, This) -> Result<()>>(
&self,
this: This,
callback: F,
) -> Result<()> {
for entry in self.entries() {
callback(entry.1, entry.0, &this)?;
callback(entry.1, entry.0, this)?;
}
Ok(())
}
Expand Down
306 changes: 157 additions & 149 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -1,73 +1,5 @@
/* tslint:disable */
/* eslint-disable */

/* auto-generated by NAPI-RS */

export interface PhpRequestSocketOptions {
/** The string representation of the local IP address the remote client is connecting on. */
localAddress: string
/** The numeric representation of the local port. For example, 80 or 21. */
localPort: number
/** The string representation of the local IP family, e.g., "IPv4" or "IPv6". */
localFamily: string
/** The string representation of the remote IP address. */
remoteAddress: string
/** The numeric representation of the remote port. For example, 80 or 21. */
remotePort: number
/** The string representation of the remote IP family, e.g., "IPv4" or "IPv6". */
remoteFamily: string
}
/** Options for creating a new PHP request. */
export interface PhpRequestOptions {
/** The HTTP method for the request. */
method?: string
/** The URL for the request. */
url: string
/** The headers for the request. */
headers?: Headers
/** The body for the request. */
body?: Uint8Array
/** The socket information for the request. */
socket?: PhpRequestSocketOptions
}
/** Options for creating a new PHP response. */
export interface PhpResponseOptions {
/** The HTTP status code for the response. */
status?: number
/** The headers for the response. */
headers?: Headers
/** The body for the response. */
body?: Uint8Array
/** The log for the response. */
log?: Uint8Array
/** The exception for the response. */
exception?: string
}
export interface PhpRewriteCondOptions {
type: string
args?: Array<string>
}
export interface PhpRewriterOptions {
type: string
args: Array<string>
}
export interface PhpConditionalRewriterOptions {
operation?: string
conditions?: Array<PhpRewriteCondOptions>
rewriters: Array<PhpRewriterOptions>
}
/** Options for creating a new PHP instance. */
export interface PhpOptions {
/** The command-line arguments for the PHP instance. */
argv?: Array<string>
/** The document root for the PHP instance. */
docroot?: string
/** Throw request errors */
throwRequestErrors?: boolean
/** Request rewriter */
rewriter?: Rewriter
}
export type PhpHeaders = Headers
/* eslint-disable */
/**
* A multi-map of HTTP headers.
*
Expand Down Expand Up @@ -233,7 +165,7 @@ export declare class Headers {
* }
* ```
*/
entries(): Array<Entry>
entries(): Array<Entry<string, string>>
/**
* Get an iterator over the header keys.
*
Expand Down Expand Up @@ -283,7 +215,86 @@ export declare class Headers {
*/
forEach(this: this, callback: (arg0: string, arg1: string, arg2: this) => void): void
}
export type PhpRequest = Request
export type PhpHeaders = Headers

/**
* A PHP instance.
*
* # Examples
*
* ```js
* const php = new Php({
* code: 'echo "Hello, world!";'
* });
*
* const response = php.handleRequest(new Request({
* method: 'GET',
* url: 'http://example.com'
* }));
*
* console.log(response.status);
* console.log(response.body);
* ```
*/
export declare class Php {
/**
* Create a new PHP instance.
*
* # Examples
*
* ```js
* const php = new Php({
* docroot: process.cwd(),
* argv: process.argv
* });
* ```
*/
constructor(options?: PhpOptions | undefined | null)
/**
* Handle a PHP request.
*
* # Examples
*
* ```js
* const php = new Php({
* docroot: process.cwd(),
* argv: process.argv
* });
*
* const response = php.handleRequest(new Request({
* method: 'GET',
* url: 'http://example.com'
* }));
*
* console.log(response.status);
* console.log(response.body);
* ```
*/
handleRequest(request: Request, signal?: AbortSignal | undefined | null): Promise<unknown>
/**
* Handle a PHP request synchronously.
*
* # Examples
*
* ```js
* const php = new Php({
* docroot: process.cwd(),
* argv: process.argv
* });
*
* const response = php.handleRequestSync(new Request({
* method: 'GET',
* url: 'http://example.com'
* }));
*
* console.log(response.status);
* console.log(response.body);
* ```
*/
handleRequestSync(request: Request): Response
}
export type PhpRuntime = Php

/**
* A PHP request.
*
Expand Down Expand Up @@ -379,7 +390,8 @@ export declare class Request {
*/
get body(): Buffer
}
export type PhpResponse = Response
export type PhpRequest = Request

/** A PHP response. */
export declare class Response {
/**
Expand Down Expand Up @@ -473,85 +485,81 @@ export declare class Response {
*/
get exception(): string | null
}
export type PhpRewriter = Rewriter
export type PhpResponse = Response

export declare class Rewriter {
constructor(options: Array<PhpConditionalRewriterOptions>)
rewrite(request: Request, docroot: string): Request
}
export type PhpRuntime = Php
/**
* A PHP instance.
*
* # Examples
*
* ```js
* const php = new Php({
* code: 'echo "Hello, world!";'
* });
*
* const response = php.handleRequest(new Request({
* method: 'GET',
* url: 'http://example.com'
* }));
*
* console.log(response.status);
* console.log(response.body);
* ```
*/
export declare class Php {
/**
* Create a new PHP instance.
*
* # Examples
*
* ```js
* const php = new Php({
* docroot: process.cwd(),
* argv: process.argv
* });
* ```
*/
constructor(options?: PhpOptions | undefined | null)
/**
* Handle a PHP request.
*
* # Examples
*
* ```js
* const php = new Php({
* docroot: process.cwd(),
* argv: process.argv
* });
*
* const response = php.handleRequest(new Request({
* method: 'GET',
* url: 'http://example.com'
* }));
*
* console.log(response.status);
* console.log(response.body);
* ```
*/
handleRequest(request: Request, signal?: AbortSignal | undefined | null): Promise<unknown>
/**
* Handle a PHP request synchronously.
*
* # Examples
*
* ```js
* const php = new Php({
* docroot: process.cwd(),
* argv: process.argv
* });
*
* const response = php.handleRequestSync(new Request({
* method: 'GET',
* url: 'http://example.com'
* }));
*
* console.log(response.status);
* console.log(response.body);
* ```
*/
handleRequestSync(request: Request): Response
export type PhpRewriter = Rewriter

export interface PhpConditionalRewriterOptions {
operation?: string
conditions?: Array<PhpRewriteCondOptions>
rewriters: Array<PhpRewriterOptions>
}

/** Options for creating a new PHP instance. */
export interface PhpOptions {
/** The command-line arguments for the PHP instance. */
argv?: Array<string>
/** The document root for the PHP instance. */
docroot?: string
/** Throw request errors */
throwRequestErrors?: boolean
/** Request rewriter */
rewriter?: Rewriter
}

/** Options for creating a new PHP request. */
export interface PhpRequestOptions {
/** The HTTP method for the request. */
method?: string
/** The URL for the request. */
url: string
/** The headers for the request. */
headers?: Headers
/** The body for the request. */
body?: Uint8Array
/** The socket information for the request. */
socket?: PhpRequestSocketOptions
}

export interface PhpRequestSocketOptions {
/** The string representation of the local IP address the remote client is connecting on. */
localAddress: string
/** The numeric representation of the local port. For example, 80 or 21. */
localPort: number
/** The string representation of the local IP family, e.g., "IPv4" or "IPv6". */
localFamily: string
/** The string representation of the remote IP address. */
remoteAddress: string
/** The numeric representation of the remote port. For example, 80 or 21. */
remotePort: number
/** The string representation of the remote IP family, e.g., "IPv4" or "IPv6". */
remoteFamily: string
}

/** Options for creating a new PHP response. */
export interface PhpResponseOptions {
/** The HTTP status code for the response. */
status?: number
/** The headers for the response. */
headers?: Headers
/** The body for the response. */
body?: Uint8Array
/** The log for the response. */
log?: Uint8Array
/** The exception for the response. */
exception?: string
}

export interface PhpRewriteCondOptions {
type: string
args?: Array<string>
}

export interface PhpRewriterOptions {
type: string
args: Array<string>
}
Loading
Loading