@gurezo/web-serial-rxjs 2.4.0 → 3.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 (49) hide show
  1. package/dist/errors/serial-error-code.d.ts +53 -18
  2. package/dist/errors/serial-error-code.d.ts.map +1 -1
  3. package/dist/errors/serial-error-context.d.ts +47 -0
  4. package/dist/errors/serial-error-context.d.ts.map +1 -0
  5. package/dist/errors/serial-error.d.ts +30 -8
  6. package/dist/errors/serial-error.d.ts.map +1 -1
  7. package/dist/index.d.ts +9 -3
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.mjs +1065 -594
  10. package/dist/index.mjs.map +4 -4
  11. package/dist/internal/assert-never.d.ts +2 -0
  12. package/dist/internal/assert-never.d.ts.map +1 -0
  13. package/dist/internal/branded-numbers.d.ts +37 -0
  14. package/dist/internal/branded-numbers.d.ts.map +1 -0
  15. package/dist/session/create-serial-session.d.ts +5 -2
  16. package/dist/session/create-serial-session.d.ts.map +1 -1
  17. package/dist/session/index.d.ts +6 -2
  18. package/dist/session/index.d.ts.map +1 -1
  19. package/dist/session/internal/build-request-options.d.ts +7 -7
  20. package/dist/session/internal/build-request-options.d.ts.map +1 -1
  21. package/dist/session/internal/error-severity.d.ts +38 -0
  22. package/dist/session/internal/error-severity.d.ts.map +1 -0
  23. package/dist/session/internal/line-buffer.d.ts +15 -4
  24. package/dist/session/internal/line-buffer.d.ts.map +1 -1
  25. package/dist/session/internal/receive-pipeline.d.ts +34 -0
  26. package/dist/session/internal/receive-pipeline.d.ts.map +1 -0
  27. package/dist/session/internal/receive-replay-buffer.d.ts +3 -2
  28. package/dist/session/internal/receive-replay-buffer.d.ts.map +1 -1
  29. package/dist/session/internal/session-error-reporter.d.ts +32 -0
  30. package/dist/session/internal/session-error-reporter.d.ts.map +1 -0
  31. package/dist/session/internal/session-lifecycle.d.ts +44 -0
  32. package/dist/session/internal/session-lifecycle.d.ts.map +1 -0
  33. package/dist/session/internal/validate-serial-port-filters.d.ts +12 -0
  34. package/dist/session/internal/validate-serial-port-filters.d.ts.map +1 -0
  35. package/dist/session/serial-session-options.d.ts +95 -49
  36. package/dist/session/serial-session-options.d.ts.map +1 -1
  37. package/dist/session/serial-session-state.d.ts +49 -12
  38. package/dist/session/serial-session-state.d.ts.map +1 -1
  39. package/dist/session/serial-session.d.ts +9 -7
  40. package/dist/session/serial-session.d.ts.map +1 -1
  41. package/dist/session/session-runtime.d.ts +140 -0
  42. package/dist/session/session-runtime.d.ts.map +1 -0
  43. package/dist/terminal/create-terminal-buffer.d.ts +3 -2
  44. package/dist/terminal/create-terminal-buffer.d.ts.map +1 -1
  45. package/dist/types.d.ts +18 -0
  46. package/dist/types.d.ts.map +1 -0
  47. package/package.json +1 -1
  48. package/dist/session/session-state-machine.d.ts +0 -40
  49. package/dist/session/session-state-machine.d.ts.map +0 -1
@@ -24,7 +24,7 @@
24
24
  * }
25
25
  * ```
26
26
  */
27
- export declare enum SerialErrorCode {
27
+ export declare const SerialErrorCode: {
28
28
  /**
29
29
  * Browser does not support the Web Serial API.
30
30
  *
@@ -34,7 +34,7 @@ export declare enum SerialErrorCode {
34
34
  *
35
35
  * **Suggested action**: Inform the user to use a supported browser.
36
36
  */
37
- BROWSER_NOT_SUPPORTED = "BROWSER_NOT_SUPPORTED",
37
+ readonly BROWSER_NOT_SUPPORTED: "BROWSER_NOT_SUPPORTED";
38
38
  /**
39
39
  * Serial port is not available.
40
40
  *
@@ -44,7 +44,7 @@ export declare enum SerialErrorCode {
44
44
  *
45
45
  * **Suggested action**: Check if the port is available or being used by another application.
46
46
  */
47
- PORT_NOT_AVAILABLE = "PORT_NOT_AVAILABLE",
47
+ readonly PORT_NOT_AVAILABLE: "PORT_NOT_AVAILABLE";
48
48
  /**
49
49
  * Failed to open the serial port.
50
50
  *
@@ -53,7 +53,7 @@ export declare enum SerialErrorCode {
53
53
  *
54
54
  * **Suggested action**: Verify connection parameters and check hardware connections.
55
55
  */
56
- PORT_OPEN_FAILED = "PORT_OPEN_FAILED",
56
+ readonly PORT_OPEN_FAILED: "PORT_OPEN_FAILED";
57
57
  /**
58
58
  * Serial port is already open.
59
59
  *
@@ -62,7 +62,7 @@ export declare enum SerialErrorCode {
62
62
  *
63
63
  * **Suggested action**: Disconnect the current port before connecting a new one.
64
64
  */
65
- PORT_ALREADY_OPEN = "PORT_ALREADY_OPEN",
65
+ readonly PORT_ALREADY_OPEN: "PORT_ALREADY_OPEN";
66
66
  /**
67
67
  * Serial port is not open.
68
68
  *
@@ -71,7 +71,7 @@ export declare enum SerialErrorCode {
71
71
  *
72
72
  * **Suggested action**: Call {@link SerialClient.connect} before reading or writing.
73
73
  */
74
- PORT_NOT_OPEN = "PORT_NOT_OPEN",
74
+ readonly PORT_NOT_OPEN: "PORT_NOT_OPEN";
75
75
  /**
76
76
  * Failed to read from the serial port.
77
77
  *
@@ -80,7 +80,7 @@ export declare enum SerialErrorCode {
80
80
  *
81
81
  * **Suggested action**: Check the connection and hardware, then retry the read operation.
82
82
  */
83
- READ_FAILED = "READ_FAILED",
83
+ readonly READ_FAILED: "READ_FAILED";
84
84
  /**
85
85
  * Failed to write to the serial port.
86
86
  *
@@ -89,7 +89,7 @@ export declare enum SerialErrorCode {
89
89
  *
90
90
  * **Suggested action**: Check the connection and hardware, then retry the write operation.
91
91
  */
92
- WRITE_FAILED = "WRITE_FAILED",
92
+ readonly WRITE_FAILED: "WRITE_FAILED";
93
93
  /**
94
94
  * Serial port connection was lost.
95
95
  *
@@ -99,7 +99,7 @@ export declare enum SerialErrorCode {
99
99
  *
100
100
  * **Suggested action**: Check the physical connection and reconnect if needed.
101
101
  */
102
- CONNECTION_LOST = "CONNECTION_LOST",
102
+ readonly CONNECTION_LOST: "CONNECTION_LOST";
103
103
  /**
104
104
  * Invalid filter options provided.
105
105
  *
@@ -108,7 +108,7 @@ export declare enum SerialErrorCode {
108
108
  *
109
109
  * **Suggested action**: Verify filter options match the expected format and value ranges.
110
110
  */
111
- INVALID_FILTER_OPTIONS = "INVALID_FILTER_OPTIONS",
111
+ readonly INVALID_FILTER_OPTIONS: "INVALID_FILTER_OPTIONS";
112
112
  /**
113
113
  * Operation was cancelled by the user.
114
114
  *
@@ -118,14 +118,14 @@ export declare enum SerialErrorCode {
118
118
  * **Suggested action**: This is a normal condition - no action required, but you may want
119
119
  * to inform the user that the operation was cancelled.
120
120
  */
121
- OPERATION_CANCELLED = "OPERATION_CANCELLED",
121
+ readonly OPERATION_CANCELLED: "OPERATION_CANCELLED";
122
122
  /**
123
123
  * Operation timed out before completion.
124
124
  *
125
125
  * This error occurs when an operation waits for a condition (for example, prompt
126
126
  * detection) and the timeout period elapses first.
127
127
  */
128
- OPERATION_TIMEOUT = "OPERATION_TIMEOUT",
128
+ readonly OPERATION_TIMEOUT: "OPERATION_TIMEOUT";
129
129
  /**
130
130
  * Internal line buffer exceeded its configured size limit.
131
131
  *
@@ -136,7 +136,7 @@ export declare enum SerialErrorCode {
136
136
  * **Suggested action**: Increase `lineBuffer.maxChars`, handle framing on `receive$`,
137
137
  * or ensure the device sends line terminators.
138
138
  */
139
- LINE_BUFFER_OVERFLOW = "LINE_BUFFER_OVERFLOW",
139
+ readonly LINE_BUFFER_OVERFLOW: "LINE_BUFFER_OVERFLOW";
140
140
  /**
141
141
  * Invalid receive replay options provided.
142
142
  *
@@ -146,7 +146,37 @@ export declare enum SerialErrorCode {
146
146
  * **Suggested action**: Verify `receiveReplay` options match the documented
147
147
  * ranges and value types.
148
148
  */
149
- INVALID_RECEIVE_REPLAY_OPTIONS = "INVALID_RECEIVE_REPLAY_OPTIONS",
149
+ readonly INVALID_RECEIVE_REPLAY_OPTIONS: "INVALID_RECEIVE_REPLAY_OPTIONS";
150
+ /**
151
+ * Invalid terminal buffer options provided.
152
+ *
153
+ * This error occurs when {@link SerialSessionOptions.terminalBuffer} values are
154
+ * out of range, such as a negative or non-integer `maxLines` or `maxChars`.
155
+ *
156
+ * **Suggested action**: Verify `terminalBuffer` options match the documented
157
+ * ranges and value types.
158
+ */
159
+ readonly INVALID_TERMINAL_BUFFER_OPTIONS: "INVALID_TERMINAL_BUFFER_OPTIONS";
160
+ /**
161
+ * Invalid line buffer options provided.
162
+ *
163
+ * This error occurs when {@link SerialSessionOptions.lineBuffer} values are
164
+ * out of range, such as a negative or non-integer `maxChars`.
165
+ *
166
+ * **Suggested action**: Verify `lineBuffer` options match the documented
167
+ * ranges and value types.
168
+ */
169
+ readonly INVALID_LINE_BUFFER_OPTIONS: "INVALID_LINE_BUFFER_OPTIONS";
170
+ /**
171
+ * Invalid connection options provided.
172
+ *
173
+ * This error occurs when connection fields such as `baudRate` are out of
174
+ * range at session creation time.
175
+ *
176
+ * **Suggested action**: Verify connection options match the documented
177
+ * ranges and value types.
178
+ */
179
+ readonly INVALID_CONNECTION_OPTIONS: "INVALID_CONNECTION_OPTIONS";
150
180
  /**
151
181
  * Receive replay buffer exceeded its configured character limit.
152
182
  *
@@ -157,7 +187,7 @@ export declare enum SerialErrorCode {
157
187
  * **Suggested action**: Increase `receiveReplay.maxChars`, reduce chunk size at
158
188
  * the source, or subscribe earlier to avoid relying on a large replay buffer.
159
189
  */
160
- RECEIVE_REPLAY_BUFFER_OVERFLOW = "RECEIVE_REPLAY_BUFFER_OVERFLOW",
190
+ readonly RECEIVE_REPLAY_BUFFER_OVERFLOW: "RECEIVE_REPLAY_BUFFER_OVERFLOW";
161
191
  /**
162
192
  * Session has been disposed and can no longer be used.
163
193
  *
@@ -168,7 +198,7 @@ export declare enum SerialErrorCode {
168
198
  * **Suggested action**: Call {@link SerialSession.dispose$} only when
169
199
  * permanently tearing down a session, then create a new one if needed.
170
200
  */
171
- SESSION_DISPOSED = "SESSION_DISPOSED",
201
+ readonly SESSION_DISPOSED: "SESSION_DISPOSED";
172
202
  /**
173
203
  * Unknown error occurred.
174
204
  *
@@ -177,6 +207,11 @@ export declare enum SerialErrorCode {
177
207
  *
178
208
  * **Suggested action**: Check the error message and originalError for more details.
179
209
  */
180
- UNKNOWN = "UNKNOWN"
181
- }
210
+ readonly UNKNOWN: "UNKNOWN";
211
+ };
212
+ /**
213
+ * String union of allowed {@link SerialErrorCode} runtime values
214
+ * (same set as the values on the {@link SerialErrorCode} object).
215
+ */
216
+ export type SerialErrorCode = (typeof SerialErrorCode)[keyof typeof SerialErrorCode];
182
217
  //# sourceMappingURL=serial-error-code.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serial-error-code.d.ts","sourceRoot":"","sources":["../../src/errors/serial-error-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,oBAAY,eAAe;IACzB;;;;;;;;OAQG;IACH,qBAAqB,0BAA0B;IAE/C;;;;;;;;OAQG;IACH,kBAAkB,uBAAuB;IAEzC;;;;;;;OAOG;IACH,gBAAgB,qBAAqB;IAErC;;;;;;;OAOG;IACH,iBAAiB,sBAAsB;IAEvC;;;;;;;OAOG;IACH,aAAa,kBAAkB;IAE/B;;;;;;;OAOG;IACH,WAAW,gBAAgB;IAE3B;;;;;;;OAOG;IACH,YAAY,iBAAiB;IAE7B;;;;;;;;OAQG;IACH,eAAe,oBAAoB;IAEnC;;;;;;;OAOG;IACH,sBAAsB,2BAA2B;IAEjD;;;;;;;;OAQG;IACH,mBAAmB,wBAAwB;IAE3C;;;;;OAKG;IACH,iBAAiB,sBAAsB;IAEvC;;;;;;;;;OASG;IACH,oBAAoB,yBAAyB;IAE7C;;;;;;;;OAQG;IACH,8BAA8B,mCAAmC;IAEjE;;;;;;;;;OASG;IACH,8BAA8B,mCAAmC;IAEjE;;;;;;;;;OASG;IACH,gBAAgB,qBAAqB;IAErC;;;;;;;OAOG;IACH,OAAO,YAAY;CACpB"}
1
+ {"version":3,"file":"serial-error-code.d.ts","sourceRoot":"","sources":["../../src/errors/serial-error-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,eAAO,MAAM,eAAe;IAC1B;;;;;;;;OAQG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;OAOG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;OAKG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;OAQG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;;;OASG;;IAGH;;;;;;;OAOG;;CAEK,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,eAAe,GACzB,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,OAAO,eAAe,CAAC,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { SerialErrorCode } from './serial-error-code';
2
+ /**
3
+ * Context payload for errors that wrap an underlying failure.
4
+ */
5
+ export type SerialErrorCauseContext = {
6
+ readonly cause: unknown;
7
+ };
8
+ /**
9
+ * Maps each {@link SerialErrorCode} to its structured context shape.
10
+ *
11
+ * Codes mapped to `undefined` have no machine-readable metadata beyond
12
+ * {@link SerialError.message}. Overflow codes expose configured limits so
13
+ * callers do not need to parse error messages.
14
+ */
15
+ export interface SerialErrorContextMap {
16
+ [SerialErrorCode.BROWSER_NOT_SUPPORTED]: undefined;
17
+ [SerialErrorCode.PORT_NOT_AVAILABLE]: SerialErrorCauseContext;
18
+ [SerialErrorCode.PORT_OPEN_FAILED]: SerialErrorCauseContext;
19
+ [SerialErrorCode.PORT_ALREADY_OPEN]: undefined;
20
+ [SerialErrorCode.PORT_NOT_OPEN]: undefined;
21
+ [SerialErrorCode.READ_FAILED]: SerialErrorCauseContext;
22
+ [SerialErrorCode.WRITE_FAILED]: SerialErrorCauseContext;
23
+ [SerialErrorCode.CONNECTION_LOST]: SerialErrorCauseContext;
24
+ [SerialErrorCode.INVALID_FILTER_OPTIONS]: undefined;
25
+ [SerialErrorCode.OPERATION_CANCELLED]: SerialErrorCauseContext;
26
+ [SerialErrorCode.OPERATION_TIMEOUT]: undefined;
27
+ [SerialErrorCode.LINE_BUFFER_OVERFLOW]: {
28
+ readonly maxChars: number;
29
+ };
30
+ [SerialErrorCode.INVALID_RECEIVE_REPLAY_OPTIONS]: undefined;
31
+ [SerialErrorCode.INVALID_TERMINAL_BUFFER_OPTIONS]: undefined;
32
+ [SerialErrorCode.INVALID_LINE_BUFFER_OPTIONS]: undefined;
33
+ [SerialErrorCode.INVALID_CONNECTION_OPTIONS]: undefined;
34
+ [SerialErrorCode.RECEIVE_REPLAY_BUFFER_OVERFLOW]: {
35
+ readonly maxChars: number;
36
+ readonly bufferSize: number;
37
+ };
38
+ [SerialErrorCode.SESSION_DISPOSED]: undefined;
39
+ [SerialErrorCode.UNKNOWN]: SerialErrorCauseContext;
40
+ }
41
+ /**
42
+ * @internal
43
+ */
44
+ export declare function isCauseContextCode(code: SerialErrorCode): code is keyof {
45
+ [K in keyof SerialErrorContextMap as SerialErrorContextMap[K] extends SerialErrorCauseContext ? K : never]: SerialErrorContextMap[K];
46
+ };
47
+ //# sourceMappingURL=serial-error-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"serial-error-context.d.ts","sourceRoot":"","sources":["../../src/errors/serial-error-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAEtD;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,qBAAqB;IACpC,CAAC,eAAe,CAAC,qBAAqB,CAAC,EAAE,SAAS,CAAC;IACnD,CAAC,eAAe,CAAC,kBAAkB,CAAC,EAAE,uBAAuB,CAAC;IAC9D,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAE,uBAAuB,CAAC;IAC5D,CAAC,eAAe,CAAC,iB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CAAC,CAAC;CACrC,CAEA"}
@@ -1,5 +1,7 @@
1
1
  import { SerialErrorCode } from './serial-error-code';
2
+ import { type SerialErrorCauseContext, type SerialErrorContextMap } from './serial-error-context';
2
3
  export { SerialErrorCode };
4
+ export type { SerialErrorCauseContext, SerialErrorContextMap };
3
5
  /**
4
6
  * Custom error class for serial port operations.
5
7
  *
@@ -19,6 +21,10 @@ export { SerialErrorCode };
19
21
  * console.error(`Original error:`, error.originalError);
20
22
  * }
21
23
  *
24
+ * if (error.is(SerialErrorCode.LINE_BUFFER_OVERFLOW)) {
25
+ * console.error(`maxChars: ${error.context.maxChars}`);
26
+ * }
27
+ *
22
28
  * // Check specific error code
23
29
  * if (error.is(SerialErrorCode.BROWSER_NOT_SUPPORTED)) {
24
30
  * // Handle browser not supported
@@ -27,7 +33,7 @@ export { SerialErrorCode };
27
33
  * }
28
34
  * ```
29
35
  */
30
- export declare class SerialError extends Error {
36
+ export declare class SerialError<TCode extends SerialErrorCode = SerialErrorCode> extends Error {
31
37
  /**
32
38
  * The error code identifying the type of error that occurred.
33
39
  *
@@ -35,12 +41,23 @@ export declare class SerialError extends Error {
35
41
  *
36
42
  * @see {@link SerialErrorCode} for all available error codes
37
43
  */
38
- readonly code: SerialErrorCode;
44
+ readonly code: TCode;
45
+ /**
46
+ * Structured metadata associated with {@link code}.
47
+ *
48
+ * When {@link is} returns `true`, TypeScript narrows this property to the
49
+ * context shape defined in {@link SerialErrorContextMap} for that code.
50
+ */
51
+ readonly context: SerialErrorContextMap[TCode];
39
52
  /**
40
53
  * The original error that caused this SerialError, if available.
41
54
  *
42
55
  * This property contains the underlying error (e.g., DOMException, TypeError)
43
56
  * that was wrapped in this SerialError. It may be undefined if no original error exists.
57
+ *
58
+ * @deprecated Prefer {@link context} for cause-bearing codes. This property is
59
+ * retained for backward compatibility and is kept in sync when a cause is
60
+ * provided.
44
61
  */
45
62
  readonly originalError?: Error;
46
63
  /**
@@ -49,24 +66,29 @@ export declare class SerialError extends Error {
49
66
  * @param code - The error code identifying the type of error
50
67
  * @param message - A human-readable error message
51
68
  * @param originalError - The original error that caused this SerialError, if any
69
+ * @param context - Structured metadata for the error code. When omitted, cause-bearing
70
+ * codes derive `{ cause }` from `originalError`.
52
71
  */
53
- constructor(code: SerialErrorCode, message: string, originalError?: Error);
72
+ constructor(code: TCode, message: string, originalError?: Error, context?: SerialErrorContextMap[TCode]);
54
73
  /**
55
74
  * Check if the error matches a specific error code.
56
75
  *
57
76
  * This is a convenience method for checking the error code without directly
58
- * comparing the code property.
77
+ * comparing the code property. When this method returns `true`, TypeScript
78
+ * narrows `this.code` and `this.context` to the shapes defined for the
79
+ * provided `code` argument.
59
80
  *
60
81
  * @param code - The error code to check against
61
- * @returns `true` if this error's code matches the provided code, `false` otherwise
82
+ * @returns Type predicate: `true` if this error's code matches the provided
83
+ * code (and `this.code` / `this.context` are narrowed), `false` otherwise
62
84
  *
63
85
  * @example
64
86
  * ```typescript
65
- * if (error.is(SerialErrorCode.PORT_NOT_OPEN)) {
66
- * // Handle port not open error
87
+ * if (error.is(SerialErrorCode.LINE_BUFFER_OVERFLOW)) {
88
+ * // error.code and error.context.maxChars are narrowed
67
89
  * }
68
90
  * ```
69
91
  */
70
- is(code: SerialErrorCode): boolean;
92
+ is<C extends SerialErrorCode>(code: C): this is SerialError<C>;
71
93
  }
72
94
  //# sourceMappingURL=serial-error.d.ts.map
@@ -1 +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"}
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;AACtD,OAAO,EAEL,KAAK,uBAAuB,EAC5B,KAAK,qBAAqB,EAC3B,MAAM,wBAAwB,CAAC;AAGhC,OAAO,EAAE,eAAe,EAAE,CAAC;AAC3B,YAAY,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,CAAC;AAY/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,WAAW,CACtB,KAAK,SAAS,eAAe,GAAG,eAAe,CAC/C,SAAQ,KAAK;IACb;;;;;;OAMG;IACH,SAAgB,IAAI,EAAE,KAAK,CAAC;IAE5B;;;;;OAKG;IACH,SAAgB,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;IAEtD;;;;;;;;;OASG;IACH,SAAgB,aAAa,CAAC,EAAE,KAAK,CAAC;IAEtC;;;;;;;;OAQG;gBAED,IAAI,EAAE,KAAK,EACX,OAAO,EAAE,MAAM,EACf,aAAa,CAAC,EAAE,KAAK,EACrB,OAAO,CAAC,EAAE,qBAAqB,CAAC,KAAK,CAAC;IA0BxC;;;;;;;;;;;;;;;;;;OAkBG;IACI,EAAE,CAAC,CAAC,SAAS,eAAe,EACjC,IAAI,EAAE,CAAC,GACN,IAAI,IAAI,WAAW,CAAC,CAAC,CAAC;CAG1B"}
package/dist/index.d.ts CHANGED
@@ -19,8 +19,12 @@
19
19
  * - {@link LineBufferOptions} - memory limits for lines$ incomplete line tail
20
20
  * - {@link SerialSession} - the runtime interface
21
21
  * - {@link SerialSessionOptions} - connection options
22
- * - {@link SerialSessionState} - `state$` payload values (const + type)
22
+ * - {@link SerialPayload} - payload accepted by {@link SerialSession.send$}
23
+ * - {@link SerialConnectionOptions} - `port.open` connection parameters (excluding filters)
24
+ * - {@link SerialSessionStatus} - lifecycle status literals for `state$.status`
25
+ * - {@link SerialSessionState} - discriminated union emitted by `state$`
23
26
  * - {@link SerialError} / {@link SerialErrorCode} - unified error surface
27
+ * - {@link SerialErrorContextMap} - structured metadata per error code
24
28
  *
25
29
  * ## Browser Support
26
30
  *
@@ -57,9 +61,11 @@
57
61
  * }
58
62
  * ```
59
63
  */
60
- export { createSerialSession, SerialSessionState, DEFAULT_LINE_BUFFER_OPTIONS } from './session';
61
- export type { SerialSession, SerialSessionOptions, SerialSessionReceiveReplayOptions, LineBufferOptions, } from './session';
64
+ export { assertNever } from './internal/assert-never';
65
+ export { createSerialSession, SerialSessionStatus, DEFAULT_LINE_BUFFER_OPTIONS, resolveSerialSessionOptions, MAX_RECEIVE_REPLAY_BUFFER_SIZE, MAX_RECEIVE_REPLAY_MAX_CHARS } from './session';
66
+ export type { SerialSession, SerialSessionState, IdleSessionState, ConnectingSessionState, ConnectedSessionState, DisconnectingSessionState, UnsupportedSessionState, ErrorSessionState, DisposedSessionState, SerialSessionOptions, SerialSessionReceiveReplayOptions, ResolvedSerialSessionOptions, SerialPayload, SerialConnectionOptions, LineBufferOptions, } from './session';
62
67
  export { SerialError } from './errors/serial-error';
68
+ export type { SerialErrorCauseContext, SerialErrorContextMap } from './errors/serial-error';
63
69
  export { SerialErrorCode } from './errors/serial-error-code';
64
70
  export { createTerminalBuffer, DEFAULT_TERMINAL_BUFFER_OPTIONS } from './terminal/create-terminal-buffer';
65
71
  export type { TerminalBuffer, TerminalBufferOptions } from './terminal/create-terminal-buffer';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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