Skip to content

Commit ff44279

Browse files
committed
Make types more resilient
1 parent 41578a9 commit ff44279

3 files changed

Lines changed: 130 additions & 123 deletions

File tree

header.d.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,35 @@
11
export type USBSpeed = 'low' | 'full' | 'high' | 'super' | 'superPlus';
2+
3+
export declare interface UsbDevice extends USBDevice {
4+
/**
5+
* The USB bus the device is connected to (e.g. `1-1`, `2-3.4`, etc.)
6+
*/
7+
bus: string;
8+
9+
/**
10+
* The USB address the device is connected to
11+
*/
12+
address: number;
13+
14+
/**
15+
* The USB port numbers the device is connected through (e.g. `[1]`, `[3, 4]`, etc.)
16+
*/
17+
ports: Array<number>
18+
19+
/**
20+
* The USB speed of the device (e.g. `Low`, `Full`, `High`, `Super`, `SuperPlus` or `undefined` if unknown)
21+
*/
22+
speed?: USBSpeed;
23+
24+
/**
25+
* Detaches the kernel driver from the specified interface number (Linux only)
26+
* @param interfaceNumber
27+
*/
28+
detachKernelDriver(interfaceNumber: number): Promise<void>;
29+
30+
/**
31+
* Attaches the kernel driver for the specified interface number (Linux only)
32+
* @param interfaceNumber
33+
*/
34+
attachKernelDriver(interfaceNumber: number): Promise<void>;
35+
}

src/webusb_device.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fn get_string(device: &nusb::Device, index: Option<std::num::NonZeroU8>) -> Opti
2020
}
2121
}
2222

23-
#[napi(object, js_name = "USBEndpoint")]
23+
#[napi(object)]
2424
pub struct UsbEndpoint {
2525
#[napi(writable = false)]
2626
pub endpointNumber: u8,
@@ -52,7 +52,7 @@ impl UsbEndpoint {
5252
}
5353
}
5454

55-
#[napi(object, js_name = "USBAlternateInterface")]
55+
#[napi(object)]
5656
pub struct UsbAlternateInterface {
5757
#[napi(writable = false)]
5858
pub alternateSetting: u8,
@@ -81,7 +81,7 @@ impl UsbAlternateInterface {
8181
}
8282
}
8383

84-
#[napi(object, js_name = "USBInterface")]
84+
#[napi(object)]
8585
pub struct UsbInterface {
8686
#[napi(writable = false)]
8787
pub interfaceNumber: u8,
@@ -104,7 +104,7 @@ impl UsbInterface {
104104
}
105105
}
106106

107-
#[napi(object, js_name = "USBConfiguration")]
107+
#[napi(object)]
108108
pub struct UsbConfiguration {
109109
#[napi(writable = false)]
110110
pub configurationValue: u8,
@@ -270,7 +270,7 @@ impl UsbDevice {
270270
self.device.is_some()
271271
}
272272

273-
#[napi(getter)]
273+
#[napi(getter, ts_return_type = "USBConfiguration")]
274274
pub unsafe fn configuration(&mut self) -> Option<UsbConfiguration> {
275275
let device = match self.device.as_ref() {
276276
Some(device) => device.clone(),
@@ -280,7 +280,7 @@ impl UsbDevice {
280280
Some(UsbConfiguration::new(&self, &device, device.active_configuration().unwrap()))
281281
}
282282

283-
#[napi(getter)]
283+
#[napi(getter, ts_return_type = "Array<USBConfiguration>")]
284284
pub unsafe fn configurations(&mut self) -> Vec<UsbConfiguration> {
285285
let device = match self.device.as_ref() {
286286
Some(device) => device.clone(),
@@ -499,12 +499,12 @@ impl UsbDevice {
499499
}
500500
}
501501

502-
#[napi(ts_return_type = "Promise<USBIsochronousInTransferResult>")]
502+
#[napi(js_name = "nativeIsochronousTransferIn", ts_return_type = "Promise<USBIsochronousInTransferResult>")]
503503
pub async fn isochronousTransferIn(&self, _endpointNumber: u8, _packetLengths: Vec<u32>) -> Result<()> {
504504
Err(napi::Error::from_reason("isochronousTransferIn error: method not implemented"))
505505
}
506506

507-
#[napi(ts_return_type = "Promise<USBIsochronousOutTransferResult>")]
507+
#[napi(js_name = "nativeIsochronousTransferOut", ts_return_type = "Promise<USBIsochronousOutTransferResult>")]
508508
pub async fn isochronousTransferOut(&self, _endpointNumber: u8, _data: Uint8Array, _packetLengths: Vec<u32>) -> Result<()> {
509509
Err(napi::Error::from_reason("isochronousTransferOut error: method not implemented"))
510510
}

0 commit comments

Comments
 (0)