@gurezo/web-serial-rxjs 0.1.0 → 0.1.1

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.
@@ -0,0 +1,72 @@
1
+ import { SerialErrorCode } from './serial-error-code';
2
+ export { SerialErrorCode };
3
+ /**
4
+ * Custom error class for serial port operations.
5
+ *
6
+ * This error class extends the standard Error class and includes additional information
7
+ * about the type of error that occurred. It provides an error code for programmatic
8
+ * error handling and may include the original error that caused the failure.
9
+ *
10
+ * @example
11
+ * ```typescript
12
+ * try {
13
+ * await client.connect().toPromise();
14
+ * } catch (error) {
15
+ * if (error instanceof SerialError) {
16
+ * console.error(`Error code: ${error.code}`);
17
+ * console.error(`Message: ${error.message}`);
18
+ * if (error.originalError) {
19
+ * console.error(`Original error:`, error.originalError);
20
+ * }
21
+ *
22
+ * // Check specific error code
23
+ * if (error.is(SerialErrorCode.BROWSER_NOT_SUPPORTED)) {
24
+ * // Handle browser not supported
25
+ * }
26
+ * }
27
+ * }
28
+ * ```
29
+ */
30
+ export declare class SerialError extends Error {
31
+ /**
32
+ * The error code identifying the type of error that occurred.
33
+ *
34
+ * Use this code to programmatically handle specific error conditions.
35
+ *
36
+ * @see {@link SerialErrorCode} for all available error codes
37
+ */
38
+ readonly code: SerialErrorCode;
39
+ /**
40
+ * The original error that caused this SerialError, if available.
41
+ *
42
+ * This property contains the underlying error (e.g., DOMException, TypeError)
43
+ * that was wrapped in this SerialError. It may be undefined if no original error exists.
44
+ */
45
+ readonly originalError?: Error;
46
+ /**
47
+ * Creates a new SerialError instance.
48
+ *
49
+ * @param code - The error code identifying the type of error
50
+ * @param message - A human-readable error message
51
+ * @param originalError - The original error that caused this SerialError, if any
52
+ */
53
+ constructor(code: SerialErrorCode, message: string, originalError?: Error);
54
+ /**
55
+ * Check if the error matches a specific error code.
56
+ *
57
+ * This is a convenience method for checking the error code without directly
58
+ * comparing the code property.
59
+ *
60
+ * @param code - The error code to check against
61
+ * @returns `true` if this error's code matches the provided code, `false` otherwise
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * if (error.is(SerialErrorCode.PORT_NOT_OPEN)) {
66
+ * // Handle port not open error
67
+ * }
68
+ * ```
69
+ */
70
+ is(code: SerialErrorCode): boolean;
71
+ }
72
+ //# sourceMappingURL=serial-error.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serial-error.d.ts","sourceRoot":"","sources":["../../src/errors/serial-error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAGtD,OAAO,EAAE,eAAe,EAAE,CAAC;AAE3B;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,qBAAa,WAAY,SAAQ,KAAK;IACpC;;;;;;OAMG;IACH,SAAgB,IAAI,EAAE,eAAe,CAAC;IAEtC;;;;;OAKG;IACH,SAAgB,aAAa,CAAC,EAAE,KAAK,CAAC;IAEtC;;;;;;OAMG;gBACS,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,EAAE,aAAa,CAAC,EAAE,KAAK;IAczE;;;;;;;;;;;;;;;OAeG;IACI,EAAE,CAAC,IAAI,EAAE,eAAe,GAAG,OAAO;CAG1C"}
@@ -0,0 +1,42 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * @packageDocumentation
3
+ *
4
+ * # web-serial-rxjs
5
+ *
6
+ * A TypeScript library that provides a reactive RxJS-based wrapper for the Web Serial API,
7
+ * enabling easy serial port communication in web applications.
8
+ *
9
+ * ## Features
10
+ *
11
+ * - **RxJS-based reactive API**: Leverage the power of RxJS Observables for reactive serial port communication
12
+ * - **TypeScript support**: Full TypeScript type definitions included
13
+ * - **Browser detection**: Built-in browser support detection and error handling
14
+ * - **Error handling**: Comprehensive error handling with custom error classes and error codes
15
+ * - **Framework agnostic**: Works with any JavaScript/TypeScript framework or vanilla JavaScript
16
+ *
17
+ * ## Browser Support
18
+ *
19
+ * The Web Serial API is currently only supported in Chromium-based browsers:
20
+ * - Chrome 89+
21
+ * - Edge 89+
22
+ * - Opera 75+
23
+ *
24
+ * @example
25
+ * ```typescript
26
+ * import { createSerialClient, isBrowserSupported } from '@gurezo/web-serial-rxjs';
27
+ *
28
+ * // Check browser support
29
+ * if (!isBrowserSupported()) {
30
+ * console.error('Web Serial API is not supported in this browser');
31
+ * return;
32
+ * }
33
+ *
34
+ * // Create a serial client
35
+ * const client = createSerialClient({ baudRate: 9600 });
36
+ *
37
+ * // Connect to a serial port
38
+ * client.connect().subscribe({
39
+ * next: () => console.log('Connected!'),
40
+ * error: (error) => console.error('Connection error:', error),
41
+ * });
42
+ * ```
43
+ */
44
+ export { createSerialClient } from './client';
45
+ export type { SerialClient } from './client';
46
+ export { SerialError } from './errors/serial-error';
47
+ export { SerialErrorCode } from './errors/serial-error-code';
48
+ export type { SerialClientOptions } from './types/options';
49
+ export { BrowserType, detectBrowserType, hasWebSerialSupport, isChromiumBased, } from './browser/browser-detection';
50
+ export { checkBrowserSupport, isBrowserSupported, } from './browser/browser-support';
51
+ export { observableToWritable, subscribeToWritable, } from './io/observable-to-writable';
52
+ export { readableToObservable } from './io/readable-to-observable';
53
+ export { buildRequestOptions } from './filters/build-request-options';
54
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,GAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC"}