@gurezo/web-serial-rxjs 0.1.21 → 2.0.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 (52) hide show
  1. package/README.ja.md +82 -13
  2. package/README.md +82 -13
  3. package/dist/errors/serial-error-code.d.ts +7 -0
  4. package/dist/errors/serial-error-code.d.ts.map +1 -1
  5. package/dist/index.d.ts +31 -30
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +469 -449
  8. package/dist/index.mjs +469 -449
  9. package/dist/index.mjs.map +4 -4
  10. package/dist/session/create-serial-session.d.ts +49 -0
  11. package/dist/session/create-serial-session.d.ts.map +1 -0
  12. package/dist/session/index.d.ts +5 -0
  13. package/dist/session/index.d.ts.map +1 -0
  14. package/dist/session/internal/build-request-options.d.ts +18 -0
  15. package/dist/session/internal/build-request-options.d.ts.map +1 -0
  16. package/dist/session/internal/has-web-serial-support.d.ts +12 -0
  17. package/dist/session/internal/has-web-serial-support.d.ts.map +1 -0
  18. package/dist/session/internal/line-buffer.d.ts +14 -0
  19. package/dist/session/internal/line-buffer.d.ts.map +1 -0
  20. package/dist/session/normalize-serial-error.d.ts +55 -0
  21. package/dist/session/normalize-serial-error.d.ts.map +1 -0
  22. package/dist/session/read-pump.d.ts +74 -0
  23. package/dist/session/read-pump.d.ts.map +1 -0
  24. package/dist/session/send-queue.d.ts +58 -0
  25. package/dist/session/send-queue.d.ts.map +1 -0
  26. package/dist/session/serial-session-options.d.ts +80 -0
  27. package/dist/session/serial-session-options.d.ts.map +1 -0
  28. package/dist/session/serial-session-state.d.ts +35 -0
  29. package/dist/session/serial-session-state.d.ts.map +1 -0
  30. package/dist/session/serial-session.d.ts +143 -0
  31. package/dist/session/serial-session.d.ts.map +1 -0
  32. package/dist/session/session-state-machine.d.ts +39 -0
  33. package/dist/session/session-state-machine.d.ts.map +1 -0
  34. package/package.json +1 -1
  35. package/dist/browser/browser-detection.d.ts +0 -104
  36. package/dist/browser/browser-detection.d.ts.map +0 -1
  37. package/dist/browser/browser-support.d.ts +0 -57
  38. package/dist/browser/browser-support.d.ts.map +0 -1
  39. package/dist/client/index.d.ts +0 -250
  40. package/dist/client/index.d.ts.map +0 -1
  41. package/dist/client/serial-client.d.ts +0 -98
  42. package/dist/client/serial-client.d.ts.map +0 -1
  43. package/dist/filters/build-request-options.d.ts +0 -42
  44. package/dist/filters/build-request-options.d.ts.map +0 -1
  45. package/dist/io/observable-to-writable.d.ts +0 -65
  46. package/dist/io/observable-to-writable.d.ts.map +0 -1
  47. package/dist/io/readable-to-observable.d.ts +0 -44
  48. package/dist/io/readable-to-observable.d.ts.map +0 -1
  49. package/dist/lib/web-serial-rxjs.d.ts +0 -7
  50. package/dist/lib/web-serial-rxjs.d.ts.map +0 -1
  51. package/dist/types/options.d.ts +0 -107
  52. package/dist/types/options.d.ts.map +0 -1
@@ -1,250 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { SerialClientOptions } from '../types/options';
3
- /**
4
- * SerialClient interface for interacting with serial ports using RxJS Observables.
5
- *
6
- * This interface provides a reactive API for serial port communication, allowing you to
7
- * connect to serial devices, read and write data using RxJS Observables.
8
- *
9
- * @example
10
- * ```typescript
11
- * const client = createSerialClient({ baudRate: 9600 });
12
- *
13
- * // Connect to a port
14
- * client.connect().subscribe({
15
- * next: () => {
16
- * console.log('Connected!');
17
- *
18
- * // Read data
19
- * client.getReadStream().subscribe({
20
- * next: (data) => console.log('Received:', data),
21
- * });
22
- *
23
- * // Write data
24
- * const encoder = new TextEncoder();
25
- * client.write(encoder.encode('Hello')).subscribe();
26
- * },
27
- * error: (error) => console.error('Connection error:', error),
28
- * });
29
- * ```
30
- */
31
- export interface SerialClient {
32
- /**
33
- * Request a serial port from the user.
34
- *
35
- * This method opens the browser's port selection dialog and returns an Observable
36
- * that emits the selected SerialPort when the user chooses a port.
37
- *
38
- * @returns An Observable that emits the selected {@link SerialPort} when the user selects a port
39
- * @throws {@link SerialError} with code {@link SerialErrorCode.OPERATION_CANCELLED} if the user cancels the selection
40
- * @throws {@link SerialError} with code {@link SerialErrorCode.PORT_NOT_AVAILABLE} if the port request fails
41
- * @throws {@link SerialError} with code {@link SerialErrorCode.BROWSER_NOT_SUPPORTED} if the browser doesn't support Web Serial API
42
- *
43
- * @example
44
- * ```typescript
45
- * client.requestPort().subscribe({
46
- * next: (port) => console.log('Selected port:', port),
47
- * error: (error) => console.error('Port selection failed:', error),
48
- * });
49
- * ```
50
- */
51
- requestPort(): Observable<SerialPort>;
52
- /**
53
- * Get available serial ports that have been previously granted access.
54
- *
55
- * This method returns an Observable that emits an array of SerialPort instances
56
- * that the user has previously granted access to in this browser session.
57
- *
58
- * @returns An Observable that emits an array of available {@link SerialPort} instances
59
- * @throws {@link SerialError} with code {@link SerialErrorCode.PORT_NOT_AVAILABLE} if getting ports fails
60
- * @throws {@link SerialError} with code {@link SerialErrorCode.BROWSER_NOT_SUPPORTED} if the browser doesn't support Web Serial API
61
- *
62
- * @example
63
- * ```typescript
64
- * client.getPorts().subscribe({
65
- * next: (ports) => {
66
- * console.log(`Found ${ports.length} available ports`);
67
- * if (ports.length > 0) {
68
- * client.connect(ports[0]).subscribe();
69
- * }
70
- * },
71
- * });
72
- * ```
73
- */
74
- getPorts(): Observable<SerialPort[]>;
75
- /**
76
- * Connect to a serial port.
77
- *
78
- * Opens the specified port (or requests one if not provided) and configures it
79
- * with the options passed to {@link createSerialClient}. The port must be connected
80
- * before reading or writing data.
81
- *
82
- * @param port - Optional {@link SerialPort} to connect to. If not provided, will call {@link requestPort} to prompt the user.
83
- * @returns An Observable that completes when the port is successfully opened
84
- * @throws {@link SerialError} with code {@link SerialErrorCode.PORT_ALREADY_OPEN} if a port is already open
85
- * @throws {@link SerialError} with code {@link SerialErrorCode.PORT_OPEN_FAILED} if opening the port fails
86
- * @throws {@link SerialError} with code {@link SerialErrorCode.OPERATION_CANCELLED} if the user cancels port selection
87
- * @throws {@link SerialError} with code {@link SerialErrorCode.BROWSER_NOT_SUPPORTED} if the browser doesn't support Web Serial API
88
- *
89
- * @example
90
- * ```typescript
91
- * // Connect by requesting a port
92
- * client.connect().subscribe({
93
- * next: () => console.log('Connected!'),
94
- * error: (error) => console.error('Connection failed:', error),
95
- * });
96
- *
97
- * // Connect to a specific port
98
- * client.getPorts().subscribe({
99
- * next: (ports) => {
100
- * if (ports.length > 0) {
101
- * client.connect(ports[0]).subscribe();
102
- * }
103
- * },
104
- * });
105
- * ```
106
- */
107
- connect(port?: SerialPort): Observable<void>;
108
- /**
109
- * Disconnect from the serial port.
110
- *
111
- * Closes the currently open port and stops all active read/write streams.
112
- * This method is safe to call even if no port is currently open.
113
- *
114
- * @returns An Observable that completes when the port is successfully closed
115
- * @throws {@link SerialError} with code {@link SerialErrorCode.CONNECTION_LOST} if closing the port fails
116
- *
117
- * @example
118
- * ```typescript
119
- * client.disconnect().subscribe({
120
- * next: () => console.log('Disconnected'),
121
- * error: (error) => console.error('Disconnect failed:', error),
122
- * });
123
- * ```
124
- */
125
- disconnect(): Observable<void>;
126
- /**
127
- * Get an Observable that emits data read from the serial port.
128
- *
129
- * Returns an Observable stream that emits Uint8Array chunks as data is received
130
- * from the serial port. The stream will continue until the port is disconnected
131
- * or an error occurs.
132
- *
133
- * @returns An Observable that emits Uint8Array chunks containing data read from the serial port
134
- * @throws {@link SerialError} with code {@link SerialErrorCode.PORT_NOT_OPEN} if the port is not open
135
- *
136
- * @example
137
- * ```typescript
138
- * client.getReadStream().subscribe({
139
- * next: (data) => {
140
- * const text = new TextDecoder().decode(data);
141
- * console.log('Received:', text);
142
- * },
143
- * error: (error) => console.error('Read error:', error),
144
- * });
145
- * ```
146
- */
147
- getReadStream(): Observable<Uint8Array>;
148
- /**
149
- * Write data to the serial port from an Observable.
150
- *
151
- * Writes data from an Observable stream to the serial port. The Observable should
152
- * emit Uint8Array chunks that will be written sequentially to the port. If a previous
153
- * write stream is active, it will be cancelled before starting the new one.
154
- *
155
- * @param data$ - Observable that emits Uint8Array chunks to write to the serial port
156
- * @returns An Observable that completes when all data has been written and the stream completes
157
- * @throws {@link SerialError} with code {@link SerialErrorCode.PORT_NOT_OPEN} if the port is not open
158
- * @throws {@link SerialError} with code {@link SerialErrorCode.WRITE_FAILED} if writing fails
159
- *
160
- * @example
161
- * ```typescript
162
- * const data$ = from([
163
- * new TextEncoder().encode('Hello'),
164
- * new TextEncoder().encode('World'),
165
- * ]);
166
- *
167
- * client.writeStream(data$).subscribe({
168
- * next: () => console.log('Writing...'),
169
- * complete: () => console.log('All data written'),
170
- * error: (error) => console.error('Write error:', error),
171
- * });
172
- * ```
173
- */
174
- writeStream(data$: Observable<Uint8Array>): Observable<void>;
175
- /**
176
- * Write a single chunk of data to the serial port.
177
- *
178
- * Writes a single Uint8Array chunk to the serial port. For writing multiple chunks,
179
- * consider using {@link writeStream} with an Observable instead.
180
- *
181
- * @param data - Uint8Array data to write to the serial port
182
- * @returns An Observable that completes when the data has been written
183
- * @throws {@link SerialError} with code {@link SerialErrorCode.PORT_NOT_OPEN} if the port is not open
184
- * @throws {@link SerialError} with code {@link SerialErrorCode.WRITE_FAILED} if writing fails
185
- *
186
- * @example
187
- * ```typescript
188
- * const encoder = new TextEncoder();
189
- * const data = encoder.encode('Hello, Serial!');
190
- *
191
- * client.write(data).subscribe({
192
- * next: () => console.log('Data written'),
193
- * error: (error) => console.error('Write error:', error),
194
- * });
195
- * ```
196
- */
197
- write(data: Uint8Array): Observable<void>;
198
- /**
199
- * Check if the port is currently open and connected.
200
- *
201
- * @returns `true` if a port is currently open, `false` otherwise
202
- */
203
- readonly connected: boolean;
204
- /**
205
- * Get the current SerialPort instance.
206
- *
207
- * Returns the currently connected SerialPort instance, or `null` if no port is open.
208
- * This allows direct access to the underlying Web Serial API SerialPort object if needed.
209
- *
210
- * @returns The current {@link SerialPort} instance, or `null` if no port is open
211
- */
212
- readonly currentPort: SerialPort | null;
213
- }
214
- /**
215
- * Create a new SerialClient instance for interacting with serial ports.
216
- *
217
- * This is the main entry point for creating a serial client. The client provides
218
- * a reactive RxJS-based API for connecting to serial ports and reading/writing data.
219
- *
220
- * @param options - Optional configuration options for the serial port connection.
221
- * If not provided, default values will be used (9600 baud, 8 data bits, etc.)
222
- * @returns A new {@link SerialClient} instance
223
- * @throws {@link SerialError} with code {@link SerialErrorCode.BROWSER_NOT_SUPPORTED} if the browser doesn't support Web Serial API
224
- *
225
- * @example
226
- * ```typescript
227
- * // Create a client with default settings (9600 baud)
228
- * const client = createSerialClient();
229
- *
230
- * // Create a client with custom settings
231
- * const client = createSerialClient({
232
- * baudRate: 115200,
233
- * dataBits: 8,
234
- * stopBits: 1,
235
- * parity: 'none',
236
- * filters: [{ usbVendorId: 0x1234 }],
237
- * });
238
- *
239
- * // Check browser support before creating a client
240
- * import { isBrowserSupported } from '@gurezo/web-serial-rxjs';
241
- *
242
- * if (!isBrowserSupported()) {
243
- * console.error('Web Serial API is not supported');
244
- * } else {
245
- * const client = createSerialClient();
246
- * }
247
- * ```
248
- */
249
- export declare function createSerialClient(options?: SerialClientOptions): SerialClient;
250
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAClC,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAGvD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,YAAY;IAC3B;;;;;;;;;;;;;;;;;;OAkBG;IACH,WAAW,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IAEtC;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,QAAQ,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC,CAAC;IAErC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA+BG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAE7C;;;;;;;;;;;;;;;;OAgBG;IACH,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAE/B;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,aAAa,IAAI,UAAU,CAAC,UAAU,CAAC,CAAC;IAExC;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAE7D;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;IAE1C;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,OAAO,CAAC;IAE5B;;;;;;;OAOG;IACH,QAAQ,CAAC,WAAW,EAAE,UAAU,GAAG,IAAI,CAAC;CACzC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,kBAAkB,CAChC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,YAAY,CAEd"}
@@ -1,98 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- import { SerialClientOptions } from '../types/options';
3
- /**
4
- * Internal implementation of SerialClient interface.
5
- *
6
- * This class implements the {@link SerialClient} interface and provides the actual
7
- * functionality for serial port communication. Users should not instantiate this class
8
- * directly; instead, use {@link createSerialClient} to create a SerialClient instance.
9
- *
10
- * @internal
11
- */
12
- export declare class SerialClientImpl {
13
- /** @internal */
14
- private port;
15
- /** @internal */
16
- private isOpen;
17
- /** @internal */
18
- private readSubscription;
19
- /** @internal */
20
- private writeSubscription;
21
- /** @internal */
22
- private readonly options;
23
- /**
24
- * Creates a new SerialClientImpl instance.
25
- *
26
- * @param options - Optional configuration options for the serial port connection
27
- * @throws {@link SerialError} with code {@link SerialErrorCode.BROWSER_NOT_SUPPORTED} if the browser doesn't support Web Serial API
28
- * @internal
29
- */
30
- constructor(options?: SerialClientOptions);
31
- /**
32
- * Request a serial port from the user.
33
- *
34
- * @returns Observable that emits the selected SerialPort
35
- * @internal
36
- */
37
- requestPort(): Observable<SerialPort>;
38
- /**
39
- * Get available serial ports.
40
- *
41
- * @returns Observable that emits an array of available SerialPorts
42
- * @internal
43
- */
44
- getPorts(): Observable<SerialPort[]>;
45
- /**
46
- * Connect to a serial port.
47
- *
48
- * @param port - Optional SerialPort to connect to. If not provided, will request one.
49
- * @returns Observable that completes when the port is opened
50
- * @internal
51
- */
52
- connect(port?: SerialPort): Observable<void>;
53
- /**
54
- * Disconnect from the serial port.
55
- *
56
- * @returns Observable that completes when the port is closed
57
- * @internal
58
- */
59
- disconnect(): Observable<void>;
60
- /**
61
- * Get an Observable that emits data read from the serial port.
62
- *
63
- * @returns Observable that emits Uint8Array chunks
64
- * @internal
65
- */
66
- getReadStream(): Observable<Uint8Array>;
67
- /**
68
- * Write data to the serial port from an Observable.
69
- *
70
- * @param data$ - Observable that emits Uint8Array chunks to write
71
- * @returns Observable that completes when writing is finished
72
- * @internal
73
- */
74
- writeStream(data$: Observable<Uint8Array>): Observable<void>;
75
- /**
76
- * Write a single chunk of data to the serial port.
77
- *
78
- * @param data - Data to write
79
- * @returns Observable that completes when the data is written
80
- * @internal
81
- */
82
- write(data: Uint8Array): Observable<void>;
83
- /**
84
- * Check if the port is currently open.
85
- *
86
- * @returns `true` if a port is currently open, `false` otherwise
87
- * @internal
88
- */
89
- get connected(): boolean;
90
- /**
91
- * Get the current SerialPort instance.
92
- *
93
- * @returns The current SerialPort instance, or `null` if no port is open
94
- * @internal
95
- */
96
- get currentPort(): SerialPort | null;
97
- }
98
- //# sourceMappingURL=serial-client.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"serial-client.d.ts","sourceRoot":"","sources":["../../src/client/serial-client.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAoB,MAAM,MAAM,CAAC;AAMpD,OAAO,EAEL,mBAAmB,EACpB,MAAM,kBAAkB,CAAC;AAE1B;;;;;;;;GAQG;AACH,qBAAa,gBAAgB;IAC3B,gBAAgB;IAChB,OAAO,CAAC,IAAI,CAA2B;IACvC,gBAAgB;IAChB,OAAO,CAAC,MAAM,CAAS;IACvB,gBAAgB;IAChB,OAAO,CAAC,gBAAgB,CAA4C;IACpE,gBAAgB;IAChB,OAAO,CAAC,iBAAiB,CAA4C;IACrE,gBAAgB;IAChB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAEtB;IAEF;;;;;;OAMG;gBACS,OAAO,CAAC,EAAE,mBAAmB;IASzC;;;;;OAKG;IACH,WAAW,IAAI,UAAU,CAAC,UAAU,CAAC;IAuBrC;;;;;OAKG;IACH,QAAQ,IAAI,UAAU,CAAC,UAAU,EAAE,CAAC;IAcpC;;;;;;OAMG;IACH,OAAO,CAAC,IAAI,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC;IAyD5C;;;;;OAKG;IACH,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC;IAqC9B;;;;;OAKG;IACH,aAAa,IAAI,UAAU,CAAC,UAAU,CAAC;IAWvC;;;;;;OAMG;IACH,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC,IAAI,CAAC;IAuD5D;;;;;;OAMG;IACH,KAAK,CAAC,IAAI,EAAE,UAAU,GAAG,UAAU,CAAC,IAAI,CAAC;IA0BzC;;;;;OAKG;IACH,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED;;;;;OAKG;IACH,IAAI,WAAW,IAAI,UAAU,GAAG,IAAI,CAEnC;CACF"}
@@ -1,42 +0,0 @@
1
- import { SerialClientOptions } from '../types/options';
2
- /**
3
- * Build SerialPortRequestOptions from SerialClientOptions.
4
- *
5
- * This utility function converts filter options from {@link SerialClientOptions} into
6
- * the format expected by the Web Serial API's `navigator.serial.requestPort()` method.
7
- * It validates the filter options to ensure they are valid before returning them.
8
- *
9
- * If no filters are provided in the options, this function returns `undefined`, which
10
- * allows the port selection dialog to show all available ports.
11
- *
12
- * @param options - Optional SerialClientOptions containing filter configuration
13
- * @returns SerialPortRequestOptions object with validated filters, or `undefined` if no filters are provided
14
- * @throws {@link SerialError} with code {@link SerialErrorCode.INVALID_FILTER_OPTIONS} if filter validation fails
15
- *
16
- * @example
17
- * ```typescript
18
- * // With filters
19
- * const options = {
20
- * baudRate: 9600,
21
- * filters: [
22
- * { usbVendorId: 0x1234 },
23
- * { usbVendorId: 0x5678, usbProductId: 0x9abc },
24
- * ],
25
- * };
26
- * const requestOptions = buildRequestOptions(options);
27
- * // Returns: { filters: [...] }
28
- *
29
- * // Without filters
30
- * const requestOptions = buildRequestOptions({ baudRate: 9600 });
31
- * // Returns: undefined
32
- *
33
- * // Invalid filter (will throw)
34
- * try {
35
- * buildRequestOptions({ filters: [{ usbVendorId: -1 }] });
36
- * } catch (error) {
37
- * // SerialError with code INVALID_FILTER_OPTIONS
38
- * }
39
- * ```
40
- */
41
- export declare function buildRequestOptions(options?: SerialClientOptions): SerialPortRequestOptions | undefined;
42
- //# sourceMappingURL=build-request-options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"build-request-options.d.ts","sourceRoot":"","sources":["../../src/filters/build-request-options.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AACH,wBAAgB,mBAAmB,CACjC,OAAO,CAAC,EAAE,mBAAmB,GAC5B,wBAAwB,GAAG,SAAS,CA4CtC"}
@@ -1,65 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- /**
3
- * Convert an RxJS Observable to a WritableStream.
4
- *
5
- * This utility function converts an RxJS Observable into a Web Streams API WritableStream.
6
- * Values emitted by the Observable will be written to the returned WritableStream. The stream
7
- * will close when the Observable completes or abort if the Observable errors.
8
- *
9
- * Note: This function creates a new WritableStream. For directly subscribing to an Observable
10
- * and writing to an existing WritableStream, use {@link subscribeToWritable} instead.
11
- *
12
- * @param observable - The Observable to convert to a WritableStream
13
- * @returns A WritableStream that writes Uint8Array chunks emitted by the Observable
14
- *
15
- * @example
16
- * ```typescript
17
- * const data$ = from([
18
- * new TextEncoder().encode('Hello'),
19
- * new TextEncoder().encode('World'),
20
- * ]);
21
- *
22
- * const writableStream = observableToWritable(data$);
23
- * // Use the writable stream with other Web Streams APIs
24
- * ```
25
- */
26
- export declare function observableToWritable(observable: Observable<Uint8Array>): WritableStream<Uint8Array>;
27
- /**
28
- * Subscribe to an Observable and write its values to a WritableStream.
29
- *
30
- * This utility function subscribes to an RxJS Observable and writes all emitted values
31
- * to the provided WritableStream. This is commonly used to write Observable data to a
32
- * serial port's writable stream.
33
- *
34
- * The function returns a subscription object that can be used to unsubscribe and clean up.
35
- * When unsubscribed, the writer lock will be released properly.
36
- *
37
- * @param observable - The Observable to subscribe to and read data from
38
- * @param stream - The WritableStream to write data to
39
- * @returns A subscription object with an `unsubscribe` method for cleanup
40
- * @throws {@link SerialError} with code {@link SerialErrorCode.WRITE_FAILED} if writing to the stream fails
41
- *
42
- * @example
43
- * ```typescript
44
- * const data$ = from([
45
- * new TextEncoder().encode('Hello'),
46
- * new TextEncoder().encode('World'),
47
- * ]);
48
- *
49
- * const subscription = subscribeToWritable(data$, port.writable);
50
- *
51
- * // Later, to cancel and clean up:
52
- * subscription.unsubscribe();
53
- *
54
- * // Use with RxJS operators
55
- * const processedData$ = of('Hello, Serial!').pipe(
56
- * map((text) => new TextEncoder().encode(text))
57
- * );
58
- *
59
- * subscribeToWritable(processedData$, port.writable);
60
- * ```
61
- */
62
- export declare function subscribeToWritable(observable: Observable<Uint8Array>, stream: WritableStream<Uint8Array>): {
63
- unsubscribe: () => void;
64
- };
65
- //# sourceMappingURL=observable-to-writable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"observable-to-writable.d.ts","sourceRoot":"","sources":["../../src/io/observable-to-writable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,oBAAoB,CAClC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,GACjC,cAAc,CAAC,UAAU,CAAC,CAqE5B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,wBAAgB,mBAAmB,CACjC,UAAU,EAAE,UAAU,CAAC,UAAU,CAAC,EAClC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC;IAAE,WAAW,EAAE,MAAM,IAAI,CAAA;CAAE,CAiD7B"}
@@ -1,44 +0,0 @@
1
- import { Observable } from 'rxjs';
2
- /**
3
- * Convert a ReadableStream to an RxJS Observable.
4
- *
5
- * This utility function converts a Web Streams API ReadableStream into an RxJS Observable,
6
- * allowing you to use RxJS operators with stream data. The Observable will emit Uint8Array
7
- * chunks as they are read from the stream, complete when the stream ends, or error if
8
- * the stream encounters an error.
9
- *
10
- * The returned Observable handles stream cleanup automatically - if you unsubscribe before
11
- * the stream completes, the reader lock will be released properly.
12
- *
13
- * @param stream - The ReadableStream to convert to an Observable
14
- * @returns An Observable that emits Uint8Array chunks from the stream
15
- * @throws {@link SerialError} with code {@link SerialErrorCode.READ_FAILED} if reading from the stream fails
16
- *
17
- * @example
18
- * ```typescript
19
- * // Convert a serial port's readable stream to an Observable
20
- * const readable$ = readableToObservable(port.readable);
21
- *
22
- * readable$.subscribe({
23
- * next: (chunk) => {
24
- * console.log('Received chunk:', chunk);
25
- * },
26
- * complete: () => {
27
- * console.log('Stream completed');
28
- * },
29
- * error: (error) => {
30
- * console.error('Stream error:', error);
31
- * },
32
- * });
33
- *
34
- * // Use with RxJS operators
35
- * readableToObservable(port.readable)
36
- * .pipe(
37
- * map((chunk) => new TextDecoder().decode(chunk)),
38
- * filter((text) => text.includes('OK'))
39
- * )
40
- * .subscribe((text) => console.log('Filtered text:', text));
41
- * ```
42
- */
43
- export declare function readableToObservable(stream: ReadableStream<Uint8Array>): Observable<Uint8Array>;
44
- //# sourceMappingURL=readable-to-observable.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"readable-to-observable.d.ts","sourceRoot":"","sources":["../../src/io/readable-to-observable.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AAGlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE,cAAc,CAAC,UAAU,CAAC,GACjC,UAAU,CAAC,UAAU,CAAC,CAoDxB"}
@@ -1,7 +0,0 @@
1
- /**
2
- * Utility function that returns the library name.
3
- *
4
- * @returns The library name as a string: 'web-serial-rxjs'
5
- */
6
- export declare function webSerialRxjs(): string;
7
- //# sourceMappingURL=web-serial-rxjs.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"web-serial-rxjs.d.ts","sourceRoot":"","sources":["../../src/lib/web-serial-rxjs.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,wBAAgB,aAAa,IAAI,MAAM,CAEtC"}
@@ -1,107 +0,0 @@
1
- /**
2
- * Options for creating a SerialClient instance.
3
- *
4
- * These options configure the serial port connection parameters. All properties are optional
5
- * and will use default values if not specified. See {@link DEFAULT_SERIAL_CLIENT_OPTIONS} for
6
- * the default values used.
7
- *
8
- * @example
9
- * ```typescript
10
- * const client = createSerialClient({
11
- * baudRate: 115200,
12
- * dataBits: 8,
13
- * stopBits: 1,
14
- * parity: 'none',
15
- * flowControl: 'none',
16
- * filters: [{ usbVendorId: 0x1234, usbProductId: 0x5678 }],
17
- * });
18
- * ```
19
- */
20
- export interface SerialClientOptions {
21
- /**
22
- * Baud rate for the serial port connection (bits per second).
23
- *
24
- * Common values include 9600, 19200, 38400, 57600, 115200, etc.
25
- * Must match the baud rate configured on the connected device.
26
- *
27
- * @default 9600
28
- */
29
- baudRate?: number;
30
- /**
31
- * Number of data bits per character (7 or 8).
32
- *
33
- * - `7`: Seven data bits (used with parity)
34
- * - `8`: Eight data bits (most common, used without parity)
35
- *
36
- * @default 8
37
- */
38
- dataBits?: 7 | 8;
39
- /**
40
- * Number of stop bits (1 or 2).
41
- *
42
- * - `1`: One stop bit (most common)
43
- * - `2`: Two stop bits (less common, used for slower devices)
44
- *
45
- * @default 1
46
- */
47
- stopBits?: 1 | 2;
48
- /**
49
- * Parity checking mode.
50
- *
51
- * - `'none'`: No parity checking (most common)
52
- * - `'even'`: Even parity
53
- * - `'odd'`: Odd parity
54
- *
55
- * @default 'none'
56
- */
57
- parity?: 'none' | 'even' | 'odd';
58
- /**
59
- * Buffer size for reading data from the serial port, in bytes.
60
- *
61
- * This determines how much data can be buffered before it needs to be read.
62
- * Larger buffers can improve performance but use more memory.
63
- *
64
- * @default 255
65
- */
66
- bufferSize?: number;
67
- /**
68
- * Flow control mode.
69
- *
70
- * - `'none'`: No flow control (most common)
71
- * - `'hardware'`: Hardware flow control (RTS/CTS)
72
- *
73
- * @default 'none'
74
- */
75
- flowControl?: 'none' | 'hardware';
76
- /**
77
- * Filters for port selection when requesting a port.
78
- *
79
- * When specified, the port selection dialog will only show devices matching
80
- * these filters. Each filter can specify `usbVendorId` and/or `usbProductId`
81
- * to filter by USB device identifiers.
82
- *
83
- * @example
84
- * ```typescript
85
- * filters: [
86
- * { usbVendorId: 0x1234 },
87
- * { usbVendorId: 0x1234, usbProductId: 0x5678 },
88
- * ]
89
- * ```
90
- *
91
- * @see {@link SerialPortFilter} for the filter structure
92
- */
93
- filters?: SerialPortFilter[];
94
- }
95
- /**
96
- * Default options for SerialClient instances.
97
- *
98
- * These are the default values used when creating a SerialClient if no options
99
- * are provided or if specific options are omitted. The values are chosen to work
100
- * with most common serial devices.
101
- *
102
- * @see {@link SerialClientOptions} for details on each option
103
- */
104
- export declare const DEFAULT_SERIAL_CLIENT_OPTIONS: Required<Omit<SerialClientOptions, 'filters'>> & {
105
- filters?: SerialPortFilter[];
106
- };
107
- //# sourceMappingURL=options.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/types/options.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,WAAW,mBAAmB;IAClC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAEjB;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAEjB;;;;;;;;OAQG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IAEjC;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;;OAOG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAElC;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;CAC9B;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,EAAE,QAAQ,CAClD,IAAI,CAAC,mBAAmB,EAAE,SAAS,CAAC,CACrC,GAAG;IAAE,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAQjC,CAAC"}