Skip to content

Commit fe0a1fc

Browse files
committed
Preparing for napi-rs v3
1 parent 87b258f commit fe0a1fc

File tree

6 files changed

+1256
-174
lines changed

6 files changed

+1256
-174
lines changed

crates/lang_handler/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ default = []
1313
napi = ["dep:napi", "dep:napi-build"]
1414

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

1818
[dependencies]
1919
bytes = "1.10.1"
20-
napi = { version = "2.16.17", optional = true }
20+
napi = { version = "3.0.0-beta.8", default-features = false, features = ["napi4"], optional = true }
2121
regex = "1.11.1"
2222
url = "2.5.4"

crates/php_node/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ path = "src/lib.rs"
99

1010
[dependencies]
1111
# Default enable napi4 feature, see https://nodejs.org/api/n-api.html#node-api-version-matrix
12-
napi = { version = "2.16.17", default-features = false, features = ["napi4"] }
13-
napi-derive = "2.16.13"
12+
napi = { version = "3", default-features = false, features = ["napi4"] }
13+
napi-derive = "3"
1414
php = { path = "../php" }
1515

1616
[build-dependencies]
17-
napi-build = "2.0.1"
17+
napi-build = "2.2.1"

crates/php_node/src/headers.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,13 +332,13 @@ impl PhpHeaders {
332332
/// });
333333
/// ```
334334
#[napi]
335-
pub fn for_each<F: Fn(String, String, &This) -> Result<()>>(
335+
pub fn for_each<F: Fn(String, String, This) -> Result<()>>(
336336
&self,
337337
this: This,
338338
callback: F,
339339
) -> Result<()> {
340340
for entry in self.entries() {
341-
callback(entry.1, entry.0, &this)?;
341+
callback(entry.1, entry.0, this)?;
342342
}
343343
Ok(())
344344
}

index.d.ts

Lines changed: 157 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,5 @@
1-
/* tslint:disable */
2-
/* eslint-disable */
3-
41
/* auto-generated by NAPI-RS */
5-
6-
export interface PhpRequestSocketOptions {
7-
/** The string representation of the local IP address the remote client is connecting on. */
8-
localAddress: string
9-
/** The numeric representation of the local port. For example, 80 or 21. */
10-
localPort: number
11-
/** The string representation of the local IP family, e.g., "IPv4" or "IPv6". */
12-
localFamily: string
13-
/** The string representation of the remote IP address. */
14-
remoteAddress: string
15-
/** The numeric representation of the remote port. For example, 80 or 21. */
16-
remotePort: number
17-
/** The string representation of the remote IP family, e.g., "IPv4" or "IPv6". */
18-
remoteFamily: string
19-
}
20-
/** Options for creating a new PHP request. */
21-
export interface PhpRequestOptions {
22-
/** The HTTP method for the request. */
23-
method?: string
24-
/** The URL for the request. */
25-
url: string
26-
/** The headers for the request. */
27-
headers?: Headers
28-
/** The body for the request. */
29-
body?: Uint8Array
30-
/** The socket information for the request. */
31-
socket?: PhpRequestSocketOptions
32-
}
33-
/** Options for creating a new PHP response. */
34-
export interface PhpResponseOptions {
35-
/** The HTTP status code for the response. */
36-
status?: number
37-
/** The headers for the response. */
38-
headers?: Headers
39-
/** The body for the response. */
40-
body?: Uint8Array
41-
/** The log for the response. */
42-
log?: Uint8Array
43-
/** The exception for the response. */
44-
exception?: string
45-
}
46-
export interface PhpRewriteCondOptions {
47-
type: string
48-
args?: Array<string>
49-
}
50-
export interface PhpRewriterOptions {
51-
type: string
52-
args: Array<string>
53-
}
54-
export interface PhpConditionalRewriterOptions {
55-
operation?: string
56-
conditions?: Array<PhpRewriteCondOptions>
57-
rewriters: Array<PhpRewriterOptions>
58-
}
59-
/** Options for creating a new PHP instance. */
60-
export interface PhpOptions {
61-
/** The command-line arguments for the PHP instance. */
62-
argv?: Array<string>
63-
/** The document root for the PHP instance. */
64-
docroot?: string
65-
/** Throw request errors */
66-
throwRequestErrors?: boolean
67-
/** Request rewriter */
68-
rewriter?: Rewriter
69-
}
70-
export type PhpHeaders = Headers
2+
/* eslint-disable */
713
/**
724
* A multi-map of HTTP headers.
735
*
@@ -233,7 +165,7 @@ export declare class Headers {
233165
* }
234166
* ```
235167
*/
236-
entries(): Array<Entry>
168+
entries(): Array<Entry<string, string>>
237169
/**
238170
* Get an iterator over the header keys.
239171
*
@@ -283,7 +215,86 @@ export declare class Headers {
283215
*/
284216
forEach(this: this, callback: (arg0: string, arg1: string, arg2: this) => void): void
285217
}
286-
export type PhpRequest = Request
218+
export type PhpHeaders = Headers
219+
220+
/**
221+
* A PHP instance.
222+
*
223+
* # Examples
224+
*
225+
* ```js
226+
* const php = new Php({
227+
* code: 'echo "Hello, world!";'
228+
* });
229+
*
230+
* const response = php.handleRequest(new Request({
231+
* method: 'GET',
232+
* url: 'http://example.com'
233+
* }));
234+
*
235+
* console.log(response.status);
236+
* console.log(response.body);
237+
* ```
238+
*/
239+
export declare class Php {
240+
/**
241+
* Create a new PHP instance.
242+
*
243+
* # Examples
244+
*
245+
* ```js
246+
* const php = new Php({
247+
* docroot: process.cwd(),
248+
* argv: process.argv
249+
* });
250+
* ```
251+
*/
252+
constructor(options?: PhpOptions | undefined | null)
253+
/**
254+
* Handle a PHP request.
255+
*
256+
* # Examples
257+
*
258+
* ```js
259+
* const php = new Php({
260+
* docroot: process.cwd(),
261+
* argv: process.argv
262+
* });
263+
*
264+
* const response = php.handleRequest(new Request({
265+
* method: 'GET',
266+
* url: 'http://example.com'
267+
* }));
268+
*
269+
* console.log(response.status);
270+
* console.log(response.body);
271+
* ```
272+
*/
273+
handleRequest(request: Request, signal?: AbortSignal | undefined | null): Promise<unknown>
274+
/**
275+
* Handle a PHP request synchronously.
276+
*
277+
* # Examples
278+
*
279+
* ```js
280+
* const php = new Php({
281+
* docroot: process.cwd(),
282+
* argv: process.argv
283+
* });
284+
*
285+
* const response = php.handleRequestSync(new Request({
286+
* method: 'GET',
287+
* url: 'http://example.com'
288+
* }));
289+
*
290+
* console.log(response.status);
291+
* console.log(response.body);
292+
* ```
293+
*/
294+
handleRequestSync(request: Request): Response
295+
}
296+
export type PhpRuntime = Php
297+
287298
/**
288299
* A PHP request.
289300
*
@@ -379,7 +390,8 @@ export declare class Request {
379390
*/
380391
get body(): Buffer
381392
}
382-
export type PhpResponse = Response
393+
export type PhpRequest = Request
394+
383395
/** A PHP response. */
384396
export declare class Response {
385397
/**
@@ -473,85 +485,81 @@ export declare class Response {
473485
*/
474486
get exception(): string | null
475487
}
476-
export type PhpRewriter = Rewriter
488+
export type PhpResponse = Response
489+
477490
export declare class Rewriter {
478491
constructor(options: Array<PhpConditionalRewriterOptions>)
479492
rewrite(request: Request, docroot: string): Request
480493
}
481-
export type PhpRuntime = Php
482-
/**
483-
* A PHP instance.
484-
*
485-
* # Examples
486-
*
487-
* ```js
488-
* const php = new Php({
489-
* code: 'echo "Hello, world!";'
490-
* });
491-
*
492-
* const response = php.handleRequest(new Request({
493-
* method: 'GET',
494-
* url: 'http://example.com'
495-
* }));
496-
*
497-
* console.log(response.status);
498-
* console.log(response.body);
499-
* ```
500-
*/
501-
export declare class Php {
502-
/**
503-
* Create a new PHP instance.
504-
*
505-
* # Examples
506-
*
507-
* ```js
508-
* const php = new Php({
509-
* docroot: process.cwd(),
510-
* argv: process.argv
511-
* });
512-
* ```
513-
*/
514-
constructor(options?: PhpOptions | undefined | null)
515-
/**
516-
* Handle a PHP request.
517-
*
518-
* # Examples
519-
*
520-
* ```js
521-
* const php = new Php({
522-
* docroot: process.cwd(),
523-
* argv: process.argv
524-
* });
525-
*
526-
* const response = php.handleRequest(new Request({
527-
* method: 'GET',
528-
* url: 'http://example.com'
529-
* }));
530-
*
531-
* console.log(response.status);
532-
* console.log(response.body);
533-
* ```
534-
*/
535-
handleRequest(request: Request, signal?: AbortSignal | undefined | null): Promise<unknown>
536-
/**
537-
* Handle a PHP request synchronously.
538-
*
539-
* # Examples
540-
*
541-
* ```js
542-
* const php = new Php({
543-
* docroot: process.cwd(),
544-
* argv: process.argv
545-
* });
546-
*
547-
* const response = php.handleRequestSync(new Request({
548-
* method: 'GET',
549-
* url: 'http://example.com'
550-
* }));
551-
*
552-
* console.log(response.status);
553-
* console.log(response.body);
554-
* ```
555-
*/
556-
handleRequestSync(request: Request): Response
494+
export type PhpRewriter = Rewriter
495+
496+
export interface PhpConditionalRewriterOptions {
497+
operation?: string
498+
conditions?: Array<PhpRewriteCondOptions>
499+
rewriters: Array<PhpRewriterOptions>
500+
}
501+
502+
/** Options for creating a new PHP instance. */
503+
export interface PhpOptions {
504+
/** The command-line arguments for the PHP instance. */
505+
argv?: Array<string>
506+
/** The document root for the PHP instance. */
507+
docroot?: string
508+
/** Throw request errors */
509+
throwRequestErrors?: boolean
510+
/** Request rewriter */
511+
rewriter?: Rewriter
512+
}
513+
514+
/** Options for creating a new PHP request. */
515+
export interface PhpRequestOptions {
516+
/** The HTTP method for the request. */
517+
method?: string
518+
/** The URL for the request. */
519+
url: string
520+
/** The headers for the request. */
521+
headers?: Headers
522+
/** The body for the request. */
523+
body?: Uint8Array
524+
/** The socket information for the request. */
525+
socket?: PhpRequestSocketOptions
526+
}
527+
528+
export interface PhpRequestSocketOptions {
529+
/** The string representation of the local IP address the remote client is connecting on. */
530+
localAddress: string
531+
/** The numeric representation of the local port. For example, 80 or 21. */
532+
localPort: number
533+
/** The string representation of the local IP family, e.g., "IPv4" or "IPv6". */
534+
localFamily: string
535+
/** The string representation of the remote IP address. */
536+
remoteAddress: string
537+
/** The numeric representation of the remote port. For example, 80 or 21. */
538+
remotePort: number
539+
/** The string representation of the remote IP family, e.g., "IPv4" or "IPv6". */
540+
remoteFamily: string
541+
}
542+
543+
/** Options for creating a new PHP response. */
544+
export interface PhpResponseOptions {
545+
/** The HTTP status code for the response. */
546+
status?: number
547+
/** The headers for the response. */
548+
headers?: Headers
549+
/** The body for the response. */
550+
body?: Uint8Array
551+
/** The log for the response. */
552+
log?: Uint8Array
553+
/** The exception for the response. */
554+
exception?: string
555+
}
556+
557+
export interface PhpRewriteCondOptions {
558+
type: string
559+
args?: Array<string>
560+
}
561+
562+
export interface PhpRewriterOptions {
563+
type: string
564+
args: Array<string>
557565
}

0 commit comments

Comments
 (0)