react-native-web-serial-api 0.1.0 → 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.
Files changed (112) hide show
  1. package/README.md +188 -117
  2. package/TESTING.md +417 -176
  3. package/android/build.gradle +14 -0
  4. package/android/src/main/java/dev/webserialapi/NativeUsbSerialModule.java +74 -11
  5. package/android/src/main/java/dev/webserialapi/PortPickerActivity.java +61 -59
  6. package/bin/expose-serial.js +205 -0
  7. package/lib/commonjs/UsbSerial.js +1 -1
  8. package/lib/commonjs/WebSerial.js +110 -26
  9. package/lib/commonjs/WebSerial.js.map +1 -1
  10. package/lib/commonjs/index.js +2 -2
  11. package/lib/commonjs/index.js.map +1 -1
  12. package/lib/commonjs/lib/event-target.js +3 -1
  13. package/lib/commonjs/lib/event-target.js.map +1 -1
  14. package/lib/commonjs/lib/web-streams.js +42 -0
  15. package/lib/commonjs/lib/web-streams.js.map +1 -0
  16. package/lib/commonjs/testing/device-fixture.js +70 -0
  17. package/lib/commonjs/testing/device-fixture.js.map +1 -0
  18. package/lib/commonjs/testing/expose.js +91 -0
  19. package/lib/commonjs/testing/expose.js.map +1 -0
  20. package/lib/commonjs/testing/harness.js +98 -0
  21. package/lib/commonjs/testing/harness.js.map +1 -0
  22. package/lib/commonjs/testing/{virtual-serial.js → in-memory-serial-transport.js} +66 -28
  23. package/lib/commonjs/testing/in-memory-serial-transport.js.map +1 -0
  24. package/lib/commonjs/testing/index.js +100 -17
  25. package/lib/commonjs/testing/index.js.map +1 -1
  26. package/lib/commonjs/testing/install-in-memory-serial-transport.js +54 -0
  27. package/lib/commonjs/testing/install-in-memory-serial-transport.js.map +1 -0
  28. package/lib/commonjs/testing/serial-client.js +277 -0
  29. package/lib/commonjs/testing/serial-client.js.map +1 -0
  30. package/lib/commonjs/testing/{serial-device.js → simulated-device.js} +17 -17
  31. package/lib/commonjs/testing/simulated-device.js.map +1 -0
  32. package/lib/commonjs/testing/test-suite.js +142 -0
  33. package/lib/commonjs/testing/test-suite.js.map +1 -0
  34. package/lib/commonjs/transport.js +3 -3
  35. package/lib/commonjs/websocket/WebSocketSerialTransport.js +659 -0
  36. package/lib/commonjs/websocket/WebSocketSerialTransport.js.map +1 -0
  37. package/lib/commonjs/websocket/bridge.js +234 -0
  38. package/lib/commonjs/websocket/bridge.js.map +1 -0
  39. package/lib/commonjs/websocket/index.js +33 -0
  40. package/lib/commonjs/websocket/index.js.map +1 -0
  41. package/lib/commonjs/websocket/protocol.js +55 -0
  42. package/lib/commonjs/websocket/protocol.js.map +1 -0
  43. package/lib/commonjs/websocket/serial-device-bridge.js +130 -0
  44. package/lib/commonjs/websocket/serial-device-bridge.js.map +1 -0
  45. package/lib/typescript/src/UsbSerial.d.ts +1 -1
  46. package/lib/typescript/src/WebSerial.d.ts +7 -7
  47. package/lib/typescript/src/WebSerial.d.ts.map +1 -1
  48. package/lib/typescript/src/index.d.ts +1 -1
  49. package/lib/typescript/src/index.d.ts.map +1 -1
  50. package/lib/typescript/src/lib/event-target.d.ts +2 -0
  51. package/lib/typescript/src/lib/event-target.d.ts.map +1 -1
  52. package/lib/typescript/src/lib/web-streams.d.ts +9 -0
  53. package/lib/typescript/src/lib/web-streams.d.ts.map +1 -0
  54. package/lib/typescript/src/testing/device-fixture.d.ts +70 -0
  55. package/lib/typescript/src/testing/device-fixture.d.ts.map +1 -0
  56. package/lib/typescript/src/testing/expose.d.ts +71 -0
  57. package/lib/typescript/src/testing/expose.d.ts.map +1 -0
  58. package/lib/typescript/src/testing/harness.d.ts +34 -0
  59. package/lib/typescript/src/testing/harness.d.ts.map +1 -0
  60. package/lib/typescript/src/testing/{virtual-serial.d.ts → in-memory-serial-transport.d.ts} +37 -26
  61. package/lib/typescript/src/testing/in-memory-serial-transport.d.ts.map +1 -0
  62. package/lib/typescript/src/testing/index.d.ts +18 -8
  63. package/lib/typescript/src/testing/index.d.ts.map +1 -1
  64. package/lib/typescript/src/testing/install-in-memory-serial-transport.d.ts +25 -0
  65. package/lib/typescript/src/testing/install-in-memory-serial-transport.d.ts.map +1 -0
  66. package/lib/typescript/src/testing/serial-client.d.ts +62 -0
  67. package/lib/typescript/src/testing/serial-client.d.ts.map +1 -0
  68. package/lib/typescript/src/testing/{serial-device.d.ts → simulated-device.d.ts} +23 -23
  69. package/lib/typescript/src/testing/simulated-device.d.ts.map +1 -0
  70. package/lib/typescript/src/testing/test-suite.d.ts +75 -0
  71. package/lib/typescript/src/testing/test-suite.d.ts.map +1 -0
  72. package/lib/typescript/src/transport.d.ts +3 -3
  73. package/lib/typescript/src/websocket/WebSocketSerialTransport.d.ts +111 -0
  74. package/lib/typescript/src/websocket/WebSocketSerialTransport.d.ts.map +1 -0
  75. package/lib/typescript/src/websocket/bridge.d.ts +66 -0
  76. package/lib/typescript/src/websocket/bridge.d.ts.map +1 -0
  77. package/lib/typescript/src/websocket/index.d.ts +19 -0
  78. package/lib/typescript/src/websocket/index.d.ts.map +1 -0
  79. package/lib/typescript/src/websocket/protocol.d.ts +64 -0
  80. package/lib/typescript/src/websocket/protocol.d.ts.map +1 -0
  81. package/lib/typescript/src/websocket/serial-device-bridge.d.ts +32 -0
  82. package/lib/typescript/src/websocket/serial-device-bridge.d.ts.map +1 -0
  83. package/package.json +21 -3
  84. package/src/UsbSerial.ts +1 -1
  85. package/src/WebSerial.ts +134 -35
  86. package/src/index.ts +4 -1
  87. package/src/lib/event-target.ts +12 -0
  88. package/src/lib/web-streams.ts +43 -0
  89. package/src/testing/device-fixture.ts +150 -0
  90. package/src/testing/expose.ts +147 -0
  91. package/src/testing/harness.ts +124 -0
  92. package/src/testing/{virtual-serial.ts → in-memory-serial-transport.ts} +95 -56
  93. package/src/testing/index.ts +69 -21
  94. package/src/testing/install-in-memory-serial-transport.ts +65 -0
  95. package/src/testing/serial-client.ts +313 -0
  96. package/src/testing/{serial-device.ts → simulated-device.ts} +23 -23
  97. package/src/testing/test-suite.ts +186 -0
  98. package/src/transport.ts +3 -3
  99. package/src/websocket/WebSocketSerialTransport.ts +796 -0
  100. package/src/websocket/bridge.ts +299 -0
  101. package/src/websocket/index.ts +38 -0
  102. package/src/websocket/protocol.ts +101 -0
  103. package/src/websocket/serial-device-bridge.ts +160 -0
  104. package/lib/commonjs/testing/install.js +0 -54
  105. package/lib/commonjs/testing/install.js.map +0 -1
  106. package/lib/commonjs/testing/serial-device.js.map +0 -1
  107. package/lib/commonjs/testing/virtual-serial.js.map +0 -1
  108. package/lib/typescript/src/testing/install.d.ts +0 -25
  109. package/lib/typescript/src/testing/install.d.ts.map +0 -1
  110. package/lib/typescript/src/testing/serial-device.d.ts.map +0 -1
  111. package/lib/typescript/src/testing/virtual-serial.d.ts.map +0 -1
  112. package/src/testing/install.ts +0 -65
@@ -1 +1 @@
1
- {"version":3,"file":"event-target.d.ts","sourceRoot":"","sources":["../../../../src/lib/event-target.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,SAAS;IACxB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,qBAAa,KAAK;IAChB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;IAC1B,QAAQ,CAAC,UAAU,EAAE,OAAO,CAAC;IAC7B,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAE3B,MAAM,EAAE,WAAW,GAAG,IAAI,CAAQ;IAClC,aAAa,EAAE,WAAW,GAAG,IAAI,CAAQ;IAEzC,gBAAgB,EAAE,OAAO,CAAS;IAClC,YAAY,EAAE,OAAO,CAAS;IAC9B,6BAA6B,EAAE,OAAO,CAAS;IAE/C,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAc;IACxC,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAS;IAEpC,MAAM,CAAC,QAAQ,CAAC,IAAI,KAAK;IACzB,MAAM,CAAC,QAAQ,CAAC,eAAe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IAKhC,YAAY,IAAI,WAAW,EAAE;IAI7B,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,EAAE,UAAU,CAAC,EAAE,OAAO,GAAG,IAAI;CAKvE;AAID,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;AAE5C,UAAU,mBAAmB;IAC3B,WAAW,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACjC;AAED,KAAK,kCAAkC,GAAG,aAAa,GAAG,mBAAmB,CAAC;AAE9E,KAAK,eAAe,GAChB;IAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAAC,OAAO,CAAC,EAAE,OAAO,CAAA;CAAC,GACtD,OAAO,GACP,SAAS,CAAC;AAmBd,6EAA6E;AAC7E,wBAAgB,cAAc,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,WAAW,GAAG,IAAI,CAE5E;AAgCD,qBAAa,WAAW;;IAKtB,gBAAgB,CACd,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,OAAO,CAAC,EAAE,eAAe,GACxB,IAAI;IAeP,aAAa,CAAC,KAAK,EAAE,KAAK,GAAG,OAAO;IAoBpC,mBAAmB,CACjB,IAAI,EAAE,MAAM,EACZ,QAAQ,EAAE,kCAAkC,EAC5C,QAAQ,CAAC,EAAE,eAAe,GACzB,IAAI;CAYR;AAID,eAAO,MAAM,SAAS,cAGX,CAAC;AAEZ,eAAO,MAAM,eAAe,oBAGX,CAAC"}
@@ -0,0 +1,9 @@
1
+ import { ByteLengthQueuingStrategy as ByteLengthQueuingStrategyPolyfill, ReadableStream as ReadableStreamPolyfill, WritableStream as WritableStreamPolyfill } from 'web-streams-polyfill';
2
+ export { ByteLengthQueuingStrategyPolyfill, ReadableStreamPolyfill, WritableStreamPolyfill, };
3
+ export declare const ReadableStreamImpl: typeof ReadableStreamPolyfill;
4
+ export declare const WritableStreamImpl: typeof WritableStreamPolyfill;
5
+ export declare const ByteLengthQueuingStrategyImpl: typeof ByteLengthQueuingStrategyPolyfill;
6
+ export type ReadableStreamImpl<R = unknown> = ReadableStreamPolyfill<R>;
7
+ export type WritableStreamImpl<W = unknown> = WritableStreamPolyfill<W>;
8
+ export type ByteLengthQueuingStrategyImpl = ByteLengthQueuingStrategyPolyfill;
9
+ //# sourceMappingURL=web-streams.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-streams.d.ts","sourceRoot":"","sources":["../../../../src/lib/web-streams.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,IAAI,iCAAiC,EAC9D,cAAc,IAAI,sBAAsB,EACxC,cAAc,IAAI,sBAAsB,EACzC,MAAM,sBAAsB,CAAC;AAS9B,OAAO,EACL,iCAAiC,EACjC,sBAAsB,EACtB,sBAAsB,GACvB,CAAC;AAEF,eAAO,MAAM,kBAAkB,+BAG9B,CAAC;AAEF,eAAO,MAAM,kBAAkB,+BAG9B,CAAC;AAEF,eAAO,MAAM,6BAA6B,0CAGzC,CAAC;AAQF,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,OAAO,IAAI,sBAAsB,CAAC,CAAC,CAAC,CAAC;AACxE,MAAM,MAAM,kBAAkB,CAAC,CAAC,GAAG,OAAO,IAAI,sBAAsB,CAAC,CAAC,CAAC,CAAC;AACxE,MAAM,MAAM,6BAA6B,GAAG,iCAAiC,CAAC"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * `createDeviceFixture` — the one-call fixture for testing serial code. It wires a
3
+ * {@link SimulatedDevice} simulator to an {@link InMemorySerialTransport} + `Serial`,
4
+ * and hands back everything a test needs to drive *both* sides:
5
+ *
6
+ * - `serial`/`port` — what the app-under-test consumes,
7
+ * - `simulatedDevice` (typed) + `device` handle — drive the device (inject data,
8
+ * move the GPS, inject faults),
9
+ * - `client` — a host-side {@link SerialClient} (for protocol tests), and
10
+ * - `whenOpened()/whenClosed()` — `await` the app connecting.
11
+ *
12
+ * @example Test how your app reacts to a device event
13
+ * const {simulatedDevice, device, whenOpened} = await createDeviceFixture(new MyGps());
14
+ * renderMyApp(); // opens the port itself
15
+ * await whenOpened();
16
+ * simulatedDevice.update({latitude: 51.48, longitude: 0});
17
+ * // …assert your app's UI updated
18
+ */
19
+ import type { SerialPort } from '../WebSerial';
20
+ import { Serial } from '../WebSerial';
21
+ import type { DeviceOptions, InMemorySerialTransportOptions } from './in-memory-serial-transport';
22
+ import { type DeviceHandle, InMemorySerialTransport } from './in-memory-serial-transport';
23
+ import { SerialClient } from './serial-client';
24
+ import type { SimulatedDevice, SimulatedDeviceOpenOptions } from './simulated-device';
25
+ export type DeviceFixtureOptions = {
26
+ /** Per-device transport knobs (single-device form). */
27
+ device?: DeviceOptions;
28
+ /** Per-device transport knobs, by index (multi-device form). */
29
+ devices?: DeviceOptions[];
30
+ /** Transport-level options (latencyMs, chunkSize, autoGrantPermission). */
31
+ transport?: InMemorySerialTransportOptions;
32
+ /** Whether each device is already permitted. Defaults to true (so it lists). */
33
+ hasPermission?: boolean;
34
+ /** Also `setUsbSerial(transport)` so a running app's `serial` sees it. Default false. */
35
+ installGlobally?: boolean;
36
+ /** Options for the host-side {@link SerialClient}. */
37
+ client?: {
38
+ defaultTimeoutMs?: number;
39
+ };
40
+ };
41
+ export type MountedDeviceFixture<D extends SimulatedDevice = SimulatedDevice> = {
42
+ transport: InMemorySerialTransport;
43
+ serial: Serial;
44
+ port: SerialPort;
45
+ /** The transport-side handle: push/emitError/failNext/written/attach/detach/… */
46
+ device: DeviceHandle;
47
+ /** The concrete device simulator, typed (e.g. call `gps.update(...)`). */
48
+ simulatedDevice: D;
49
+ /** A host-side client bound to `port` — NOT opened (call `client.open()`). */
50
+ client: SerialClient;
51
+ /** Resolve when the app opens the port (now if already open). */
52
+ whenOpened(): Promise<SimulatedDeviceOpenOptions>;
53
+ /** Resolve when the app closes the port (now if not open). */
54
+ whenClosed(): Promise<void>;
55
+ };
56
+ export type MountedDeviceFixtures = {
57
+ transport: InMemorySerialTransport;
58
+ serial: Serial;
59
+ ports: SerialPort[];
60
+ devices: DeviceHandle[];
61
+ simulatedDevices: SimulatedDevice[];
62
+ clients: SerialClient[];
63
+ /** Resolve when device `index` opens, or any device when `index` is omitted. */
64
+ whenOpened(index?: number): Promise<SimulatedDeviceOpenOptions>;
65
+ /** Resolve when device `index` closes, or any device when `index` is omitted. */
66
+ whenClosed(index?: number): Promise<void>;
67
+ };
68
+ export declare function createDeviceFixture<D extends SimulatedDevice>(device: D, options?: DeviceFixtureOptions): Promise<MountedDeviceFixture<D>>;
69
+ export declare function createDeviceFixture(devices: SimulatedDevice[], options?: DeviceFixtureOptions): Promise<MountedDeviceFixtures>;
70
+ //# sourceMappingURL=device-fixture.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"device-fixture.d.ts","sourceRoot":"","sources":["../../../../src/testing/device-fixture.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAGH,OAAO,KAAK,EAAC,UAAU,EAAC,MAAM,cAAc,CAAC;AAC7C,OAAO,EAAC,MAAM,EAAC,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EACV,aAAa,EACb,8BAA8B,EAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,KAAK,YAAY,EACjB,uBAAuB,EACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAC,YAAY,EAAC,MAAM,iBAAiB,CAAC;AAC7C,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC3B,MAAM,oBAAoB,CAAC;AAE5B,MAAM,MAAM,oBAAoB,GAAG;IACjC,uDAAuD;IACvD,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,gEAAgE;IAChE,OAAO,CAAC,EAAE,aAAa,EAAE,CAAC;IAC1B,2EAA2E;IAC3E,SAAS,CAAC,EAAE,8BAA8B,CAAC;IAC3C,gFAAgF;IAChF,aAAa,CAAC,EA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,CACjC,OAAO,EAAE,eAAe,EAAE,EAC1B,OAAO,CAAC,EAAE,oBAAoB,GAC7B,OAAO,CAAC,qBAAqB,CAAC,CAAC"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * `exposeSimulatedDevice` — run a {@link SimulatedDevice} simulator behind a WebSocket
3
+ * server so a real app (on a device/emulator) can connect to it with
4
+ * `new Serial(new WebSocketSerialTransport(url))` and drive the *same* simulated
5
+ * peripheral your Jest tests drive. The test process keeps the
6
+ * {@link DeviceHandle} handle, so it can inject frames / move the GPS and
7
+ * `await whenOpened()` for the app to connect — turning an in-memory device
8
+ * suite into an on-device E2E without changing the device code.
9
+ *
10
+ * `ws` is an *optional* dependency: it is loaded lazily (and only in Node), via
11
+ * an indirect require so app bundlers never pull it into a mobile bundle. Pass
12
+ * `options.WebSocketServer` to inject your own (e.g. `import {WebSocketServer}
13
+ * from 'ws'`) and skip the lazy load entirely.
14
+ *
15
+ * @example
16
+ * import {WebSocketServer} from 'ws';
17
+ * const ex = exposeSimulatedDevice(new WMBusGateway('iU891A-XL'), {
18
+ * port: 8090,
19
+ * WebSocketServer,
20
+ * });
21
+ * // …app connects to ex.url…
22
+ * await ex.whenOpened();
23
+ * ex.simulatedDevice.addMeter(meter);
24
+ * meter.sendTelegram(); // the app receives the 0x20 telegram event
25
+ * await ex.close();
26
+ */
27
+ import { type WsLike } from '../websocket';
28
+ import type { DeviceOptions } from './in-memory-serial-transport';
29
+ import { type DeviceHandle, InMemorySerialTransport } from './in-memory-serial-transport';
30
+ import type { SimulatedDevice, SimulatedDeviceOpenOptions } from './simulated-device';
31
+ /** The `ws` WebSocketServer surface this helper uses. */
32
+ export type WebSocketServerLike = {
33
+ on(event: 'connection', listener: (socket: WsLike) => void): void;
34
+ close(cb?: () => void): void;
35
+ };
36
+ /** A `ws`-compatible `WebSocketServer` constructor. */
37
+ export type WebSocketServerCtor = new (options: {
38
+ port: number;
39
+ host?: string;
40
+ }) => WebSocketServerLike;
41
+ export type ExposeSimulatedDeviceOptions = {
42
+ /** TCP port for the WebSocket server. */
43
+ port: number;
44
+ /** Listen address. Defaults to `localhost`. Use `0.0.0.0` for an emulator. */
45
+ host?: string;
46
+ /** Inject a `ws`-compatible `WebSocketServer` (skips the lazy `require('ws')`). */
47
+ WebSocketServer?: WebSocketServerCtor;
48
+ /** Forward device→client data before the app sends startReading. Default true. */
49
+ readingByDefault?: boolean;
50
+ /** Diagnostics logger. */
51
+ log?: (message: string) => void;
52
+ /** Transport-side device options (hasPermission defaults to true). */
53
+ device?: DeviceOptions;
54
+ };
55
+ export type ExposedDevice<D extends SimulatedDevice = SimulatedDevice> = {
56
+ /** The URL the app connects to, e.g. `ws://localhost:8090`. */
57
+ url: string;
58
+ transport: InMemorySerialTransport;
59
+ /** The transport-side handle: push/emitError/whenOpened/whenClosed/… */
60
+ device: DeviceHandle;
61
+ /** The concrete device simulator, typed (drive it from the test). */
62
+ simulatedDevice: D;
63
+ /** Resolve when the app opens the port (now if already open). */
64
+ whenOpened(): Promise<SimulatedDeviceOpenOptions>;
65
+ /** Resolve when the app closes the port (now if not open). */
66
+ whenClosed(): Promise<void>;
67
+ /** Stop the WebSocket server. */
68
+ close(): Promise<void>;
69
+ };
70
+ export declare function exposeSimulatedDevice<D extends SimulatedDevice>(simulatedDevice: D, options: ExposeSimulatedDeviceOptions): ExposedDevice<D>;
71
+ //# sourceMappingURL=expose.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expose.d.ts","sourceRoot":"","sources":["../../../../src/testing/expose.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAIL,KAAK,MAAM,EACZ,MAAM,cAAc,CAAC;AACtB,OAAO,KAAK,EAAC,aAAa,EAAC,MAAM,8BAA8B,CAAC;AAChE,OAAO,EACL,KAAK,YAAY,EACjB,uBAAuB,EACxB,MAAM,8BAA8B,CAAC;AACtC,OAAO,KAAK,EACV,eAAe,EACf,0BAA0B,EAC3B,M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+BF,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,eAAe,EAC7D,eAAe,EAAE,CAAC,EAClB,OAAO,EAAE,4BAA4B,GACpC,aAAa,CAAC,CAAC,CAAC,CA4BlB"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Tiny, dependency-free test helpers for driving serial devices — shared by the
3
+ * library's own conformance suite, the {@link SerialClient}, and consumers' app
4
+ * tests. Free of `jest` and `react-native`, so they run under any test runner
5
+ * and on a real device (e.g. an on-device Self-Test screen).
6
+ */
7
+ /** Throw `message` if `condition` is falsy. */
8
+ export declare function assert(condition: unknown, message: string): asserts condition;
9
+ /** Throw if `actual !== expected`, including both values in the message. */
10
+ export declare function assertEqual<T>(actual: T, expected: T, message: string): void;
11
+ /** Byte-for-byte equality of two sequences. */
12
+ export declare function bytesEqual(a: ArrayLike<number>, b: ArrayLike<number>): boolean;
13
+ /** What {@link assertRejects} may additionally check about the thrown error. */
14
+ export type RejectionExpectation = {
15
+ name?: string;
16
+ type?: new (...args: never[]) => Error;
17
+ message?: string | RegExp;
18
+ };
19
+ /** Assert `fn()` rejects (optionally matching the error name/type/message). */
20
+ export declare function assertRejects(fn: () => Promise<unknown>, message: string, expected?: RejectionExpectation): Promise<void>;
21
+ /** Normalise any thrown value into a `"Name: message"` string. */
22
+ export declare function errorMessage(e: unknown): string;
23
+ /** Reject if `promise` doesn't settle within `ms`; `label` names it on timeout. */
24
+ export declare function withTimeout<T>(promise: Promise<T>, ms: number, label: string): Promise<T>;
25
+ /** The slice of `ReadableStreamDefaultReader` the helpers need. */
26
+ export type ByteReader = {
27
+ read(): Promise<{
28
+ done: boolean;
29
+ value?: Uint8Array;
30
+ }>;
31
+ };
32
+ /** Read exactly `count` bytes from a reader (accumulating chunks), with a timeout. */
33
+ export declare function readBytes(reader: ByteReader, count: number, timeoutMs?: number): Promise<number[]>;
34
+ //# sourceMappingURL=harness.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"harness.d.ts","sourceRoot":"","s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CAAA;KAAC,CAAC,CAAC;CACtD,CAAC;AAEF,sFAAsF;AACtF,wBAAsB,SAAS,CAC7B,MAAM,EAAE,UAAU,EAClB,KAAK,EAAE,MAAM,EACb,SAAS,SAAO,GACf,OAAO,CAAC,MAAM,EAAE,CAAC,CAYnB"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * VirtualSerialTransport — an in-memory {@link SerialTransport} for tests and
2
+ * InMemorySerialTransport — an in-memory {@link SerialTransport} for tests and
3
3
  * on-device demos.
4
4
  *
5
5
  * It implements the exact same interface the production `UsbSerialModule` does,
@@ -13,17 +13,17 @@
13
13
  * Inject it via `new Serial(transport)` or globally with `setUsbSerial(transport)`.
14
14
  *
15
15
  * @example
16
- * const transport = new VirtualSerialTransport();
17
- * transport.addDevice(new EchoDevice(), {hasPermission: true});
16
+ * const transport = new InMemorySerialTransport();
17
+ * transport.addDevice(new LoopbackDevice(), {hasPermission: true});
18
18
  * const serial = new Serial(transport);
19
19
  * const [port] = await serial.getPorts();
20
20
  * await port.open({baudRate: 115200});
21
21
  * // writes to port.writable now come back on port.readable (echo)
22
22
  */
23
23
  import type { ConnectEvent, ControlLine, DataEvent, ErrorEvent, FlowControl, OpenOptions, PortFilter, PortId, PortPickerLabels, SerialTransport, Subscription } from '../transport';
24
- import type { SerialDevice } from './serial-device';
25
- /** Transport-side knobs when registering a {@link SerialDevice}. */
26
- export type VirtualDeviceOptions = {
24
+ import type { SimulatedDevice } from './simulated-device';
25
+ /** Transport-side knobs when registering a {@link SimulatedDevice}. */
26
+ export type DeviceOptions = {
27
27
  /** Whether the app already holds USB permission. Defaults to false. */
28
28
  hasPermission?: boolean;
29
29
  /** Defaults to 0. A USB device may expose several ports. */
@@ -43,9 +43,9 @@ export type VirtualDeviceOptions = {
43
43
  */
44
44
  flowControlThreshold?: number;
45
45
  };
46
- export type VirtualSerialOptions = {
46
+ export type InMemorySerialTransportOptions = {
47
47
  /** Devices to register on construction (same as calling addDevice). */
48
- devices?: SerialDevice[];
48
+ devices?: SimulatedDevice[];
49
49
  /**
50
50
  * Delay (ms) applied to async operations and to inbound data delivery.
51
51
  * 0 (default) resolves on a microtask — deterministic for Jest. A small
@@ -78,11 +78,11 @@ type InputSignals = {
78
78
  dsr: boolean;
79
79
  };
80
80
  /**
81
- * A simulated USB-serial device. Returned by {@link VirtualSerialTransport.addDevice}.
81
+ * A simulated USB-serial device. Returned by {@link InMemorySerialTransport.addDevice}.
82
82
  * The mutable fields and the helper methods let a test or demo drive the device
83
83
  * the way physical hardware (and a human plugging cables) otherwise would.
84
84
  */
85
- export declare class VirtualDevice {
85
+ export declare class DeviceHandle {
86
86
  #private;
87
87
  readonly usbVendorId: number;
88
88
  readonly usbProductId: number;
@@ -95,7 +95,7 @@ export declare class VirtualDevice {
95
95
  isOpen: boolean;
96
96
  reading: boolean;
97
97
  /** The hosted behaviour. */
98
- readonly serialDevice: SerialDevice;
98
+ readonly simulatedDevice: SimulatedDevice;
99
99
  loopbackSignals: boolean;
100
100
  flowControl: FlowControl;
101
101
  flowControlThreshold: number;
@@ -112,7 +112,7 @@ export declare class VirtualDevice {
112
112
  readonly input: InputSignals;
113
113
  /** Every byte frame the host has written to this device, in order. */
114
114
  readonly written: number[][];
115
- constructor(transport: VirtualSerialTransport, deviceId: number, device: SerialDevice, options: VirtualDeviceOptions);
115
+ constructor(transport: InMemorySerialTransport, deviceId: number, device: SimulatedDevice, options: DeviceOptions);
116
116
  /** Push inbound bytes to the host as if the device sent them unprompted. */
117
117
  push(bytes: number[] | Uint8Array): void;
118
118
  /**
@@ -138,38 +138,49 @@ export declare class VirtualDevice {
138
138
  detach(): void;
139
139
  /** Simulate an unplug while open: errors the open stream, then disconnects. */
140
140
  loseDevice(): void;
141
+ /**
142
+ * Resolve when the host opens this port (immediately if already open). Lets a
143
+ * test `await` the app connecting before driving the device.
144
+ */
145
+ whenOpened(): Promise<Required<OpenOptions>>;
146
+ /** Resolve when the host closes this port (immediately if not open). */
147
+ whenClosed(): Promise<void>;
148
+ /** @internal The transport calls this right after the port opens. */
149
+ _notifyOpen(options: Required<OpenOptions>): void;
150
+ /** @internal The transport calls this right after the port closes/detaches. */
151
+ _notifyClose(): void;
141
152
  }
142
153
  type Listener<E> = (event: E) => void;
143
154
  /**
144
- * In-memory transport backing one or more {@link VirtualDevice}s.
155
+ * In-memory transport backing one or more {@link DeviceHandle}s.
145
156
  */
146
- export declare class VirtualSerialTransport implements SerialTransport {
157
+ export declare class InMemorySerialTransport implements SerialTransport {
147
158
  #private;
148
- constructor(options?: VirtualSerialOptions);
159
+ constructor(options?: InMemorySerialTransportOptions);
149
160
  /** All devices known to the transport (attached or not). */
150
- get devices(): readonly VirtualDevice[];
161
+ get devices(): readonly DeviceHandle[];
151
162
  /**
152
- * Register a {@link SerialDevice}. It starts attached but does not fire
163
+ * Register a {@link SimulatedDevice}. It starts attached but does not fire
153
164
  * "connect"; its identity (usbVendorId/usbProductId/serialNumber) is read from
154
165
  * the device, and `options` carries the transport-side knobs.
155
166
  */
156
- addDevice(serialDevice: SerialDevice, options?: VirtualDeviceOptions): VirtualDevice;
167
+ addDevice(simulatedDevice: SimulatedDevice, options?: DeviceOptions): DeviceHandle;
157
168
  /** Remove a device entirely; detaches it first if attached. */
158
- removeDevice(device: VirtualDevice): void;
169
+ removeDevice(device: DeviceHandle): void;
159
170
  /** (Re)attach a device, assigning it a fresh deviceId, and fire "connect". */
160
- attach(device: VirtualDevice): void;
171
+ attach(device: DeviceHandle): void;
161
172
  /** Detach a device and fire "disconnect"; any open port becomes closed. */
162
- detach(device: VirtualDevice): void;
173
+ detach(device: DeviceHandle, lost?: boolean): void;
163
174
  /** Simulate an unplug while open: error the stream first, then disconnect. */
164
- loseDevice(device: VirtualDevice): void;
175
+ loseDevice(device: DeviceHandle): void;
165
176
  /** Script the next showPortPicker() resolution (a device or a predicate). */
166
- selectNextPort(target: VirtualDevice | ((d: VirtualDevice) => boolean)): void;
177
+ selectNextPort(target: DeviceHandle | ((d: DeviceHandle) => boolean)): void;
167
178
  /** Make the next showPortPicker() reject (user cancelled / no port). */
168
179
  rejectNextPortPicker(): void;
169
180
  /** @internal deliver inbound bytes to the host's readable stream. */
170
- _deliver(device: VirtualDevice, data: number[]): void;
181
+ _deliver(device: DeviceHandle, data: number[]): void;
171
182
  /** @internal raise a read error for a device's open port. */
172
- _error(device: VirtualDevice, message: string, name?: string): void;
183
+ _error(device: DeviceHandle, message: string, name?: string): void;
173
184
  findAllDrivers(): Promise<ReadonlyArray<PortId>>;
174
185
  showPortPicker(filter: ReadonlyArray<PortFilter>, _labels?: PortPickerLabels): Promise<PortId>;
175
186
  requestPermission(deviceId: number): Promise<boolean>;
@@ -202,4 +213,4 @@ export declare class VirtualSerialTransport implements SerialTransport {
202
213
  onDisconnect(listener: Listener<ConnectEvent>): Subscription;
203
214
  }
204
215
  export {};
205
- //# sourceMappingURL=virtual-serial.d.ts.map
216
+ //# sourceMappingURL=in-memory-serial-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-memory-serial-transport.d.ts","sourceRoot":"","sources":["../../../../src/testing/in-memory-serial-transport.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EACV,YAAY,EACZ,WAAW,EACX,SAAS,EACT,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,MAAM,EACN,gBAAgB,EAChB,eAAe,EACf,YAAY,EACb,MAAM,cAAc,CAAC;AAEtB,OAAO,KAAK,EAEV,eAAe,EAEhB,MAAM,oBAAoB,CAAC;AAE5B,uEAAuE;AACvE,MAAM,MAAM,aAAa,GAAG;IAC1B,uEAAuE;IACvE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,4DAA4D;IAC5D,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB;;;;OAIG;IACH,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B;;;;OAIG;IACH,oBA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,QAAQ,CAAC,UAAU,CAAC,GAAG,YAAY;IAIrD,SAAS,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,YAAY;IAIzD,YAAY,CAAC,QAAQ,EAAE,QAAQ,CAAC,YAAY,CAAC,GAAG,YAAY;CAsG7D"}
@@ -3,21 +3,31 @@
3
3
  *
4
4
  * Imported via the package subpath:
5
5
  *
6
- * import {VirtualSerialTransport, installSerialMock}
6
+ * import {InMemorySerialTransport, installInMemorySerialTransport}
7
7
  * from 'react-native-web-serial-api/testing';
8
8
  *
9
9
  * These are reusable building blocks for *consumers'* tests and demos — an
10
- * in-memory transport and an authorable `SerialDevice` peripheral model — so
10
+ * in-memory transport and an authorable `SimulatedDevice` peripheral model — so
11
11
  * they ship with the package. The library's own spec-compliance suite is NOT
12
12
  * here: it lives in `src/__tests__/conformance-suite.ts` (test-only, excluded
13
13
  * from the build and the published package). None of this is in the main bundle.
14
14
  */
15
15
  export type { SerialTransport } from '../transport';
16
16
  export { getUsbSerial, resetUsbSerial, setUsbSerial } from '../UsbSerial';
17
- export type { InstallSerialMockOptions, SerialMockDevice } from './install';
18
- export { installSerialMock } from './install';
19
- export type { DeviceIdentity, SerialDeviceHost, SerialDeviceOpenOptions, SerialHostSignals, SerialInputSignals, } from './serial-device';
20
- export { EchoDevice, LineDevice, SerialDevice, SilentDevice, } from './serial-device';
21
- export type { FailableOp, VirtualDeviceOptions, VirtualSerialOptions, } from './virtual-serial';
22
- export { VirtualDevice, VirtualSerialTransport } from './virtual-serial';
17
+ export type { DeviceFixtureOptions, MountedDeviceFixture, MountedDeviceFixtures, } from './device-fixture';
18
+ export { createDeviceFixture } from './device-fixture';
19
+ export type { ExposedDevice, ExposeSimulatedDeviceOptions, WebSocketServerCtor, WebSocketServerLike, } from './expose';
20
+ export { exposeSimulatedDevice } from './expose';
21
+ export type { ByteReader, RejectionExpectation } from './harness';
22
+ export { assert, assertEqual, assertRejects, bytesEqual, errorMessage, readBytes, withTimeout, } from './harness';
23
+ export type { DeviceOptions, FailableOp, InMemorySerialTransportOptions, } from './in-memory-serial-transport';
24
+ export { DeviceHandle, InMemorySerialTransport, } from './in-memory-serial-transport';
25
+ export type { InstallInMemorySerialTransportOptions, SimulatedTransportDevice, } from './install-in-memory-serial-transport';
26
+ export { installInMemorySerialTransport } from './install-in-memory-serial-transport';
27
+ export type { ReadOptions, SerialClientOptions } from './serial-client';
28
+ export { createSerialClient, SerialClient, } from './serial-client';
29
+ export type { HostSignals, SerialInputSignals, SimulatedDeviceHost, SimulatedDeviceIdentity, SimulatedDeviceOpenOptions, } from './simulated-device';
30
+ export { LineBufferedDevice, LoopbackDevice, SimulatedDevice, SinkDevice, } from './simulated-device';
31
+ export type { RunTestSuiteOptions, SerialTest, SerialTestProgress, SerialTestResult, TestClient, } from './test-suite';
32
+ export { compareTestResults, runTestSuite } from './test-suite';
23
33
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,YAAY,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AACxE,YAAY,EAAC,wBAAwB,EAAE,gBAAgB,EAAC,MAAM,WAAW,CAAC;AAE1E,OAAO,EAAC,iBAAiB,EAAC,MAAM,WAAW,CAAC;AAC5C,YAAY,EACV,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EACL,UAAU,EACV,UAAU,EACV,YAAY,EACZ,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,UAAU,EACV,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAC,aAAa,EAAE,sBAAsB,EAAC,MAAM,kBAAkB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/testing/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,YAAY,EAAC,eAAe,EAAC,MAAM,cAAc,CAAC;AAGlD,OAAO,EAAC,YAAY,EAAE,cAAc,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC;AAExE,YAAY,EACV,oBAAoB,EACpB,oBAAoB,EACpB,qBAAqB,GACtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAC,mBAAmB,EAAC,MAAM,kBAAkB,CAAC;AAGrD,YAAY,EACV,aAAa,EACb,4BAA4B,EAC5B,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAC,qBAAqB,EAAC,MAAM,UAAU,CAAC;AAE/C,YAAY,EAAC,UAAU,EAAE,oBAAoB,EAAC,MAAM,WAAW,CAAC;AAChE,OAAO,EACL,MAAM,EACN,WAAW,EACX,aAAa,EACb,UAAU,EACV,YAAY,EACZ,SAAS,EACT,WAAW,GACZ,MAAM,WAAW,CAAC;AACnB,YAAY,EACV,aAAa,EACb,UAAU,EACV,8BAA8B,GAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EACL,YAAY,EACZ,uBAAuB,GACxB,MAAM,8BAA8B,CAAC;AACtC,YAAY,EACV,qCAAqC,EACrC,wBAAwB,GACzB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAC,8BAA8B,EAAC,MAAM,sCAAsC,CAAC;AAEpF,YAAY,EAAC,WAAW,EAAE,mBAAmB,EAAC,MAAM,iBAAiB,CAAC;AACtE,OAAO,EACL,kBAAkB,EAClB,YAAY,GACb,MAAM,iBAAiB,CAAC;AACzB,YAAY,EACV,WAAW,EACX,kBAAkB,EAClB,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,oBAAoB,CAAC;AAE5B,OAAO,EACL,kBAAkB,EAClB,cAAc,EACd,eAAe,EACf,UAAU,GACX,MAAM,oBAAoB,CAAC;AAE5B,YAAY,EACV,mBAAmB,EACnB,UAAU,EACV,kBAAkB,EAClB,gBAAgB,EAChB,UAAU,GACX,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,kBAAkB,EAAE,YAAY,EAAC,MAAM,cAAc,CAAC"}
@@ -0,0 +1,25 @@
1
+ import type { DeviceOptions, InMemorySerialTransportOptions } from './in-memory-serial-transport';
2
+ import { InMemorySerialTransport } from './in-memory-serial-transport';
3
+ import { SimulatedDevice } from './simulated-device';
4
+ /** A device to register: a SimulatedDevice, optionally with transport options. */
5
+ export type SimulatedTransportDevice = SimulatedDevice | {
6
+ device: SimulatedDevice;
7
+ options?: DeviceOptions;
8
+ };
9
+ export type InstallInMemorySerialTransportOptions = {
10
+ /** The simulated devices to expose. */
11
+ devices: SimulatedTransportDevice[];
12
+ /** When false, no mock is installed and `null` is returned. Defaults to true. */
13
+ enabled?: boolean;
14
+ /** Transport-level options (latency, chunkSize, …). */
15
+ transport?: InMemorySerialTransportOptions;
16
+ };
17
+ /**
18
+ * Build an {@link InMemorySerialTransport} from `devices` and install it globally
19
+ * via {@link setUsbSerial}. SimulatedDevices default to granted USB permission (so
20
+ * they show up immediately); pass the `{device, options}` form to override.
21
+ * Returns the transport (handy for driving devices in-test), or `null` when
22
+ * disabled.
23
+ */
24
+ export declare function installInMemorySerialTransport(options: InstallInMemorySerialTransportOptions): InMemorySerialTransport | null;
25
+ //# sourceMappingURL=install-in-memory-serial-transport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"install-in-memory-serial-transport.d.ts","sourceRoot":"","sources":["../../../../src/testing/install-in-memory-serial-transport.ts"],"names":[],"mappings":"AAiBA,OAAO,KAAK,EACV,aAAa,EACb,8BAA8B,EAC/B,MAAM,8BAA8B,CAAC;AACtC,OAAO,EAAC,uBAAuB,EAAC,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAC,eAAe,EAAC,MAAM,oBAAoB,CAAC;AAEnD,kFAAkF;AAClF,MAAM,MAAM,wBAAwB,GAChC,eAAe,GACf;IAAC,MAAM,EAAE,eAAe,CAAC;IAAC,OAAO,CAAC,EAAE,aAAa,CAAA;CAAC,CAAC;AAEvD,MAAM,MAAM,qCAAqC,GAAG;IAClD,uCAAuC;IACvC,OAAO,EAAE,wBAAwB,EAAE,CAAC;IACpC,iFAAiF;IACjF,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,uDAAuD;IACvD,SAAS,CAAC,EAAE,8BAA8B,CAAC;CAC5C,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,qCAAqC,GAC7C,uBAAuB,GAAG,IAAI,CAiBhC"}
@@ -0,0 +1,62 @@
1
+ /**
2
+ * A fluent request/response client over a {@link SerialPort} — the host-side
3
+ * driver every serial test otherwise hand-rolls (reader + writer, a pending
4
+ * byte buffer, framed reads with timeouts). Works on ANY SerialPort: the
5
+ * in-memory {@link InMemorySerialTransport}, a real USB device, or a
6
+ * WebSocket-backed one — so the same test runs in Jest and on a device.
7
+ *
8
+ * @example
9
+ * const {client} = await mountDeviceFixture(new MyDevice());
10
+ * await client.open({baudRate: 115200});
11
+ * await client.write('PING\n');
12
+ * expect(await client.readLine()).toBe('PONG');
13
+ * await client.close();
14
+ */
15
+ import type { SerialOptions, SerialPort } from '../WebSerial';
16
+ export type ReadOptions = {
17
+ /** Per-call timeout in ms (overrides the client default). */
18
+ timeout?: number;
19
+ };
20
+ export type SerialClientOptions = {
21
+ /** Default per-read timeout in ms. Default 2000. */
22
+ defaultTimeoutMs?: number;
23
+ };
24
+ export declare class SerialClient {
25
+ #private;
26
+ constructor(port: SerialPort, options?: SerialClientOptions);
27
+ get port(): SerialPort;
28
+ get isOpen(): boolean;
29
+ /** True once the underlying stream has ended (device closed or lost). */
30
+ get ended(): boolean;
31
+ /** Open the port (idempotent) and acquire reader + writer; start reading. */
32
+ open(options?: SerialOptions): Promise<this>;
33
+ /** Write bytes (string → char codes & 0xff). */
34
+ write(data: number[] | Uint8Array | string): Promise<void>;
35
+ /** Read exactly `n` bytes (fewer only if the stream ends first). */
36
+ readBytes(n: number, options?: ReadOptions): Promise<Uint8Array>;
37
+ /** Read up to and including `delimiter`; returns the slice (incl. delimiter). */
38
+ readUntil(delimiter: number[] | Uint8Array | string, options?: ReadOptions): Promise<Uint8Array>;
39
+ /** Read one `\n`-terminated line as text (trailing CR/LF stripped). */
40
+ readLine(options?: ReadOptions): Promise<string>;
41
+ /**
42
+ * Frame a message: `predicate(buffer)` returns the number of leading bytes the
43
+ * next frame occupies (consumed and returned), or `false` to wait for more.
44
+ */
45
+ readMatching(predicate: (buffer: Uint8Array) => number | false, options?: ReadOptions): Promise<Uint8Array>;
46
+ /**
47
+ * Resolve with the next chunk of buffered inbound bytes (one or more), or an
48
+ * empty array once the stream has ended. Rejects on timeout. Use this to layer
49
+ * your own framing/decoder (SLIP, COBS, length-prefix, …) on the byte stream;
50
+ * pair it with {@link ended} to stop when the device goes away.
51
+ */
52
+ readAvailable(options?: ReadOptions): Promise<Uint8Array>;
53
+ /** Assert no inbound bytes arrive for `ms`. Rejects if any do. */
54
+ expectIdle(ms: number): Promise<void>;
55
+ /** Drop any buffered-but-unread inbound bytes. */
56
+ drain(): void;
57
+ /** Release reader + writer locks and close the port. Safe to call twice. */
58
+ close(): Promise<void>;
59
+ }
60
+ /** Create a {@link SerialClient} for any SerialPort (virtual, real, or WS). */
61
+ export declare function createSerialClient(port: SerialPort, options?: SerialClientOptions): SerialClient;
62
+ //# sourceMappingURL=serial-client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serial-client.d.ts","sourceRoot":"","sources":["../../../../src/testing/serial-client.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,OAAO,KAAK,EAAC,aAAa,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AAG5D,MAAM,MAAM,WAAW,GAAG;IACxB,6DAA6D;IAC7D,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