@gurezo/web-serial-rxjs 2.4.0 → 3.1.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 (57) hide show
  1. package/README.ja.md +17 -10
  2. package/README.md +21 -12
  3. package/dist/errors/serial-error-code.d.ts +81 -37
  4. package/dist/errors/serial-error-code.d.ts.map +1 -1
  5. package/dist/errors/serial-error-context.d.ts +61 -0
  6. package/dist/errors/serial-error-context.d.ts.map +1 -0
  7. package/dist/errors/serial-error.d.ts +42 -21
  8. package/dist/errors/serial-error.d.ts.map +1 -1
  9. package/dist/index.d.ts +42 -12
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.mjs +1278 -635
  12. package/dist/index.mjs.map +4 -4
  13. package/dist/internal/assert-never.d.ts +11 -0
  14. package/dist/internal/assert-never.d.ts.map +1 -0
  15. package/dist/internal/branded-numbers.d.ts +37 -0
  16. package/dist/internal/branded-numbers.d.ts.map +1 -0
  17. package/dist/internal/strip-ansi-sequences.d.ts +25 -0
  18. package/dist/internal/strip-ansi-sequences.d.ts.map +1 -0
  19. package/dist/session/create-serial-session.d.ts +6 -3
  20. package/dist/session/create-serial-session.d.ts.map +1 -1
  21. package/dist/session/index.d.ts +7 -2
  22. package/dist/session/index.d.ts.map +1 -1
  23. package/dist/session/internal/build-request-options.d.ts +7 -7
  24. package/dist/session/internal/build-request-options.d.ts.map +1 -1
  25. package/dist/session/internal/error-severity.d.ts +38 -0
  26. package/dist/session/internal/error-severity.d.ts.map +1 -0
  27. package/dist/session/internal/line-buffer.d.ts +15 -4
  28. package/dist/session/internal/line-buffer.d.ts.map +1 -1
  29. package/dist/session/internal/receive-pipeline.d.ts +34 -0
  30. package/dist/session/internal/receive-pipeline.d.ts.map +1 -0
  31. package/dist/session/internal/receive-replay-buffer.d.ts +3 -2
  32. package/dist/session/internal/receive-replay-buffer.d.ts.map +1 -1
  33. package/dist/session/internal/session-error-reporter.d.ts +32 -0
  34. package/dist/session/internal/session-error-reporter.d.ts.map +1 -0
  35. package/dist/session/internal/session-lifecycle.d.ts +44 -0
  36. package/dist/session/internal/session-lifecycle.d.ts.map +1 -0
  37. package/dist/session/internal/validate-serial-port-filters.d.ts +12 -0
  38. package/dist/session/internal/validate-serial-port-filters.d.ts.map +1 -0
  39. package/dist/session/is-connected-session-state.d.ts +11 -0
  40. package/dist/session/is-connected-session-state.d.ts.map +1 -0
  41. package/dist/session/normalize-serial-error.d.ts +1 -1
  42. package/dist/session/normalize-serial-error.d.ts.map +1 -1
  43. package/dist/session/serial-session-options.d.ts +118 -65
  44. package/dist/session/serial-session-options.d.ts.map +1 -1
  45. package/dist/session/serial-session-state.d.ts +50 -12
  46. package/dist/session/serial-session-state.d.ts.map +1 -1
  47. package/dist/session/serial-session.d.ts +52 -18
  48. package/dist/session/serial-session.d.ts.map +1 -1
  49. package/dist/session/session-runtime.d.ts +140 -0
  50. package/dist/session/session-runtime.d.ts.map +1 -0
  51. package/dist/terminal/create-terminal-buffer.d.ts +15 -3
  52. package/dist/terminal/create-terminal-buffer.d.ts.map +1 -1
  53. package/dist/types.d.ts +18 -0
  54. package/dist/types.d.ts.map +1 -0
  55. package/package.json +1 -1
  56. package/dist/session/session-state-machine.d.ts +0 -40
  57. package/dist/session/session-state-machine.d.ts.map +0 -1
@@ -1,67 +1,15 @@
1
+ import { type BaudRate, type MaxChars, type MaxLines, type ReceiveReplayBufferSize, type SerialPortBufferSize } from '../internal/branded-numbers';
2
+ import type { SerialConnectionOptions } from '../types';
1
3
  import type { TerminalBufferOptions } from '../terminal/create-terminal-buffer';
2
4
  import { type LineBufferOptions } from './internal/line-buffer';
3
5
  /**
4
- * Options for creating a {@link SerialSession} via {@link createSerialSession}.
5
- *
6
- * These options configure the serial port connection parameters used when
7
- * calling `port.open` and `navigator.serial.requestPort`. All properties
8
- * are optional; omitted fields fall back to {@link DEFAULT_SERIAL_SESSION_OPTIONS}.
9
- *
10
- * @example
11
- * ```typescript
12
- * const session = createSerialSession({
13
- * baudRate: 115200,
14
- * dataBits: 8,
15
- * stopBits: 1,
16
- * parity: 'none',
17
- * flowControl: 'none',
18
- * filters: [{ usbVendorId: 0x1234, usbProductId: 0x5678 }],
19
- * });
20
- * ```
6
+ * Library-specific options for {@link createSerialSession} that are not passed
7
+ * to W3C `port.open`.
21
8
  *
22
- * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/199 | Issue #199}
23
- * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/200 | Issue #200}
9
+ * @see {@link SerialConnectionOptions} for W3C connection parameters
10
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/441 | Issue #441}
24
11
  */
25
- export interface SerialSessionOptions {
26
- /**
27
- * Baud rate for the serial port connection (bits per second).
28
- *
29
- * Common values include 9600, 19200, 38400, 57600, 115200, etc.
30
- * Must match the baud rate configured on the connected device.
31
- *
32
- * @default 9600
33
- */
34
- baudRate?: number;
35
- /**
36
- * Number of data bits per character (7 or 8).
37
- *
38
- * @default 8
39
- */
40
- dataBits?: 7 | 8;
41
- /**
42
- * Number of stop bits (1 or 2).
43
- *
44
- * @default 1
45
- */
46
- stopBits?: 1 | 2;
47
- /**
48
- * Parity checking mode.
49
- *
50
- * @default 'none'
51
- */
52
- parity?: 'none' | 'even' | 'odd';
53
- /**
54
- * Buffer size for the underlying read stream, in bytes.
55
- *
56
- * @default 255
57
- */
58
- bufferSize?: number;
59
- /**
60
- * Flow control mode.
61
- *
62
- * @default 'none'
63
- */
64
- flowControl?: 'none' | 'hardware';
12
+ export interface SerialSessionFeatureOptions {
65
13
  /**
66
14
  * Filters for port selection when requesting a port.
67
15
  *
@@ -96,6 +44,38 @@ export interface SerialSessionOptions {
96
44
  */
97
45
  lineBuffer?: LineBufferOptions;
98
46
  }
47
+ /**
48
+ * Options for creating a {@link SerialSession} via {@link createSerialSession}.
49
+ *
50
+ * Composes {@link Partial}<{@link SerialConnectionOptions}> (W3C connection
51
+ * parameters passed to `port.open`) with {@link SerialSessionFeatureOptions}
52
+ * (library-specific session features). All connection fields are optional;
53
+ * omitted values fall back to {@link DEFAULT_SERIAL_SESSION_OPTIONS}
54
+ * (`baudRate` 9600, `dataBits` 8, `stopBits` 1, `parity` `'none'`,
55
+ * `bufferSize` 255, `flowControl` `'none'`).
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * const session = createSerialSession({
60
+ * baudRate: 115200,
61
+ * dataBits: 8,
62
+ * stopBits: 1,
63
+ * parity: 'none',
64
+ * flowControl: 'none',
65
+ * filters: [{ usbVendorId: 0x1234, usbProductId: 0x5678 }],
66
+ * });
67
+ * ```
68
+ *
69
+ * @see {@link SerialConnectionOptions}
70
+ * @see {@link SerialSessionFeatureOptions}
71
+ * @see {@link SerialOptions}
72
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/199 | Issue #199}
73
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/200 | Issue #200}
74
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/402 | Issue #402}
75
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/441 | Issue #441}
76
+ */
77
+ export interface SerialSessionOptions extends Partial<SerialConnectionOptions>, SerialSessionFeatureOptions {
78
+ }
99
79
  /**
100
80
  * Options for {@link SerialSessionOptions.receiveReplay}.
101
81
  *
@@ -136,16 +116,89 @@ export declare const MAX_RECEIVE_REPLAY_MAX_CHARS = 1048576;
136
116
  * @throws {@link SerialError} with {@link SerialErrorCode.INVALID_RECEIVE_REPLAY_OPTIONS}
137
117
  * when `bufferSize` or `maxChars` are out of range.
138
118
  */
139
- export declare function resolveReceiveReplayOptions(options?: SerialSessionReceiveReplayOptions): Required<SerialSessionReceiveReplayOptions>;
119
+ /** Resolved receive replay options with validated branded numeric fields. */
120
+ export type ResolvedSerialSessionReceiveReplayOptions = {
121
+ enabled: boolean;
122
+ bufferSize: ReceiveReplayBufferSize;
123
+ maxChars: MaxChars;
124
+ };
125
+ export declare function resolveReceiveReplayOptions(options?: SerialSessionReceiveReplayOptions): ResolvedSerialSessionReceiveReplayOptions;
126
+ /**
127
+ * Merge and validate {@link TerminalBufferOptions}.
128
+ *
129
+ * @throws {@link SerialError} with {@link SerialErrorCode.INVALID_TERMINAL_BUFFER_OPTIONS}
130
+ * when `maxLines` or `maxChars` are out of range.
131
+ */
132
+ /** Resolved terminal buffer options with validated branded numeric fields. */
133
+ export type ResolvedTerminalBufferOptions = {
134
+ maxLines: MaxLines;
135
+ maxChars: MaxChars;
136
+ stripAnsi: boolean;
137
+ };
138
+ export declare function resolveTerminalBufferOptions(options?: TerminalBufferOptions): ResolvedTerminalBufferOptions;
139
+ /**
140
+ * Merge and validate {@link LineBufferOptions}.
141
+ *
142
+ * @throws {@link SerialError} with {@link SerialErrorCode.INVALID_LINE_BUFFER_OPTIONS}
143
+ * when `maxChars` is out of range.
144
+ */
145
+ /** Resolved line buffer options with validated branded numeric fields. */
146
+ export type ResolvedLineBufferOptions = {
147
+ maxChars: MaxChars;
148
+ };
149
+ export declare function resolveLineBufferOptions(options?: LineBufferOptions): ResolvedLineBufferOptions;
150
+ /**
151
+ * Fully resolved session options after merging {@link SerialSessionOptions}
152
+ * with {@link DEFAULT_SERIAL_SESSION_OPTIONS}. All invariant fields are
153
+ * required; `filters` remains optional.
154
+ */
155
+ export type ResolvedSerialSessionOptions = Required<Omit<SerialSessionOptions, 'filters' | 'receiveReplay' | 'terminalBuffer' | 'lineBuffer' | 'baudRate' | 'bufferSize'>> & {
156
+ baudRate: BaudRate;
157
+ bufferSize: SerialPortBufferSize;
158
+ filters?: SerialPortFilter[];
159
+ receiveReplay: ResolvedSerialSessionReceiveReplayOptions;
160
+ terminalBuffer: ResolvedTerminalBufferOptions;
161
+ lineBuffer: ResolvedLineBufferOptions;
162
+ };
140
163
  /**
141
164
  * Default values applied to omitted {@link SerialSessionOptions} fields.
142
165
  *
143
166
  * @internal
144
167
  */
145
- export declare const DEFAULT_SERIAL_SESSION_OPTIONS: Required<Omit<SerialSessionOptions, 'filters' | 'receiveReplay' | 'terminalBuffer' | 'lineBuffer'>> & {
146
- filters?: SerialPortFilter[];
147
- receiveReplay: Required<SerialSessionReceiveReplayOptions>;
148
- terminalBuffer: Required<TerminalBufferOptions>;
149
- lineBuffer: Required<LineBufferOptions>;
168
+ export declare const DEFAULT_SERIAL_SESSION_OPTIONS: {
169
+ baudRate: BaudRate;
170
+ dataBits: 8;
171
+ stopBits: 1;
172
+ parity: "none";
173
+ bufferSize: SerialPortBufferSize;
174
+ flowControl: "none";
175
+ receiveReplay: ResolvedSerialSessionReceiveReplayOptions;
176
+ terminalBuffer: ResolvedTerminalBufferOptions;
177
+ lineBuffer: ResolvedLineBufferOptions;
178
+ };
179
+ /** Resolved W3C connection fields for {@link ResolvedSerialSessionOptions}. */
180
+ export type ResolvedSerialSessionConnectionOptions = Required<Omit<SerialConnectionOptions, 'baudRate' | 'bufferSize'>> & {
181
+ baudRate: BaudRate;
182
+ bufferSize: SerialPortBufferSize;
150
183
  };
184
+ /**
185
+ * Merge and validate W3C connection fields from {@link SerialSessionOptions}.
186
+ *
187
+ * @throws {@link SerialError} with {@link SerialErrorCode.INVALID_CONNECTION_OPTIONS}
188
+ * when `baudRate` is out of range.
189
+ */
190
+ export declare function resolveConnectionOptions(options?: Partial<SerialConnectionOptions>): ResolvedSerialSessionConnectionOptions;
191
+ /**
192
+ * Merge and validate {@link SerialSessionOptions} into a fully resolved
193
+ * options object for internal session use.
194
+ *
195
+ * @throws {@link SerialError} when option values are out of range:
196
+ * {@link SerialErrorCode.INVALID_CONNECTION_OPTIONS},
197
+ * {@link SerialErrorCode.INVALID_FILTER_OPTIONS},
198
+ * {@link SerialErrorCode.INVALID_RECEIVE_REPLAY_OPTIONS},
199
+ * {@link SerialErrorCode.INVALID_TERMINAL_BUFFER_OPTIONS}, or
200
+ * {@link SerialErrorCode.INVALID_LINE_BUFFER_OPTIONS}.
201
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/403 | Issue #403}
202
+ */
203
+ export declare function resolveSerialSessionOptions(options?: SerialSessionOptions): ResolvedSerialSessionOptions;
151
204
  //# sourceMappingURL=serial-session-options.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serial-session-options.d.ts","sourceRoot":"","sources":["../../src/session/serial-session-options.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAC;AAIhF,OAAO,EAEL,KAAK,iBAAiB,EACvB,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,oBAAoB;IACnC;;;;;;;OAOG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAEjB;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC;IAEjB;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,KAAK,CAAC;IAEjC;;;;OAIG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAElC;;;;;;OAMG;IACH,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAE7B;;;;;;OAMG;IACH,aAAa,CAAC,EAAE,iCAAiC,CAAC;IAElD;;;;;;OAMG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC;IAEvC;;;;;;;OAOG;IACH,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED;;;;;GAKG;AACH,MAAM,WAAW,iCAAiC;IAChD;;;;OAIG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB;;;;;;OAMG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,4EAA4E;AAC5E,eAAO,MAAM,8BAA8B,QAAS,CAAC;AAErD,0E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U,GACV,YAAY,CACf,CACF,GAAG;IACF,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,oBAAoB,CAAC;IACjC,OAAO,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAC7B,aAAa,EAAE,yCAAyC,CAAC;IACzD,cAAc,EAAE,6BAA6B,CAAC;IAC9C,UAAU,EAAE,yBAAyB,CAAC;CACvC,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,8BAA8B;;;;;;;;;;CAUH,CAAC;AAEzC,+EAA+E;AAC/E,MAAM,MAAM,sCAAsC,GAAG,QAAQ,CAC3D,IAAI,CAAC,uBAAuB,EAAE,UAAU,GAAG,YAAY,CAAC,CACzD,GAAG;IACF,QAAQ,EAAE,QAAQ,CAAC;IACnB,UAAU,EAAE,oBAAoB,CAAC;CAClC,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,OAAO,CAAC,EAAE,OAAO,CAAC,uBAAuB,CAAC,GACzC,sCAAsC,CAqCxC;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,2BAA2B,CACzC,OAAO,CAAC,EAAE,oBAAoB,GAC7B,4BAA4B,CAW9B"}
@@ -1,11 +1,9 @@
1
+ import type { SerialError } from '../errors/serial-error';
1
2
  /**
2
- * Reactive lifecycle state for a {@link SerialSession}.
3
+ * Canonical status literals for a {@link SerialSession} lifecycle.
3
4
  *
4
- * This is the v2 API counterpart of the legacy `SerialState` used by
5
- * `SerialClient`. The runtime values are the same flat strings v1
6
- * consumers used for UI switches; the {@link SerialSessionState} const
7
- * object is the canonical source of those literals so call sites can
8
- * avoid string typos and get IDE completion.
5
+ * Use these constants when comparing {@link SerialSessionState.status}
6
+ * so call sites avoid string typos and get IDE completion.
9
7
  *
10
8
  * Lifecycle transitions:
11
9
  *
@@ -14,12 +12,12 @@
14
12
  * \-> error
15
13
  * (any) -> unsupported (when Web Serial API is unavailable)
16
14
  * (any) -> error (when an unrecoverable failure occurs)
15
+ * (any) -> disposed (when dispose$ completes)
17
16
  * ```
18
17
  *
19
- * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/199 | Issue #199}
20
- * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/200 | Issue #200}
18
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/406 | Issue #406}
21
19
  */
22
- export declare const SerialSessionState: {
20
+ export declare const SerialSessionStatus: {
23
21
  readonly Idle: "idle";
24
22
  readonly Connecting: "connecting";
25
23
  readonly Connected: "connected";
@@ -29,8 +27,48 @@ export declare const SerialSessionState: {
29
27
  readonly Disposed: "disposed";
30
28
  };
31
29
  /**
32
- * String union of allowed {@link SerialSessionState} runtime values
33
- * (same set as the values on the {@link SerialSessionState} object).
30
+ * String union of allowed {@link SerialSessionStatus} runtime values
31
+ * (same set as the values on the {@link SerialSessionStatus} object).
34
32
  */
35
- export type SerialSessionState = (typeof SerialSessionState)[keyof typeof SerialSessionState];
33
+ export type SerialSessionStatus = (typeof SerialSessionStatus)[keyof typeof SerialSessionStatus];
34
+ /** @see {@link SerialSessionState} */
35
+ export interface IdleSessionState {
36
+ readonly status: typeof SerialSessionStatus.Idle;
37
+ }
38
+ /** @see {@link SerialSessionState} */
39
+ export interface ConnectingSessionState {
40
+ readonly status: typeof SerialSessionStatus.Connecting;
41
+ }
42
+ /** Connected lifecycle variant with narrowed {@link SerialPortInfo} access via `portInfo`. */
43
+ export interface ConnectedSessionState {
44
+ readonly status: typeof SerialSessionStatus.Connected;
45
+ readonly portInfo: SerialPortInfo;
46
+ }
47
+ /** @see {@link SerialSessionState} */
48
+ export interface DisconnectingSessionState {
49
+ readonly status: typeof SerialSessionStatus.Disconnecting;
50
+ }
51
+ /** @see {@link SerialSessionState} */
52
+ export interface UnsupportedSessionState {
53
+ readonly status: typeof SerialSessionStatus.Unsupported;
54
+ }
55
+ /** @see {@link SerialSessionState} */
56
+ export interface ErrorSessionState {
57
+ readonly status: typeof SerialSessionStatus.Error;
58
+ readonly error: SerialError;
59
+ }
60
+ /** @see {@link SerialSessionState} */
61
+ export interface DisposedSessionState {
62
+ readonly status: typeof SerialSessionStatus.Disposed;
63
+ }
64
+ /**
65
+ * Discriminated union emitted by {@link SerialSession.state$} — the
66
+ * canonical lifecycle source.
67
+ *
68
+ * Each variant carries the lifecycle `status` plus optional detail fields
69
+ * (`portInfo` when connected, `error` when in a fatal error state).
70
+ *
71
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/406 | Issue #406}
72
+ */
73
+ export type SerialSessionState = IdleSessionState | ConnectingSessionState | ConnectedSessionState | DisconnectingSessionState | UnsupportedSessionState | ErrorSessionState | DisposedSessionState;
36
74
  //# sourceMappingURL=serial-session-state.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serial-session-state.d.ts","sourceRoot":"","sources":["../../src/session/serial-session-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,kBAAkB;;;;;;;;CAQrB,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,kBAAkB,GAC5B,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,OAAO,kBAAkB,CAAC,CAAC"}
1
+ {"version":3,"file":"serial-session-state.d.ts","sourceRoot":"","sources":["../../src/session/serial-session-state.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAE1D;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,mBAAmB;;;;;;;;CAQtB,CAAC;AAEX;;;GAGG;AACH,MAAM,MAAM,mBAAmB,GAC7B,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,OAAO,mBAAmB,CAAC,CAAC;AAEjE,sCAAsC;AACtC,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC,IAAI,CAAC;CAClD;AAED,sCAAsC;AACtC,MAAM,WAAW,sBAAsB;IACrC,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC,UAAU,CAAC;CACxD;AAED,8FAA8F;AAC9F,MAAM,WAAW,qBAAqB;IACpC,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC,SAAS,CAAC;IACtD,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC;CACnC;AAED,sCAAsC;AACtC,MAAM,WAAW,yBAAyB;IACxC,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC,aAAa,CAAC;CAC3D;AAED,sCAAsC;AACtC,MAAM,WAAW,uBAAuB;IACtC,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC,WAAW,CAAC;CACzD;AAED,sCAAsC;AACtC,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC,KAAK,CAAC;IAClD,QAAQ,CAAC,KAAK,EAAE,WAAW,CAAC;CAC7B;AAED,sCAAsC;AACtC,MAAM,WAAW,oBAAoB;IACnC,QAAQ,CAAC,MAAM,EAAE,OAAO,mBAAmB,CAAC,QAAQ,CAAC;CACtD;AAED;;;;;;;;GAQG;AACH,MAAM,MAAM,kBAAkB,GAC1B,gBAAgB,GAChB,sBAAsB,GACtB,qBAAqB,GACrB,yBAAyB,GACzB,uBAAuB,GACvB,iBAAiB,GACjB,oBAAoB,CAAC"}
@@ -1,12 +1,14 @@
1
1
  import type { Observable } from 'rxjs';
2
2
  import type { SerialError } from '../errors/serial-error';
3
+ import type { SerialPayload } from '../types';
3
4
  import type { SerialSessionState } from './serial-session-state';
4
5
  /**
5
- * v2 public API for interacting with the Web Serial API through a
6
+ * Public API for interacting with the Web Serial API through a
6
7
  * minimal, session-oriented surface.
7
8
  *
8
9
  * The session is intentionally slim so that apps (Angular, Vue, React, etc.)
9
- * can drive their UI purely from `state$` + `isConnected$` + `receive$` + `terminalText$` + `lines$` + `errors$` and never
10
+ * can drive their UI from `state$` (canonical lifecycle state) + `errors$`
11
+ * (error event channel) + `receive$` + `terminalText$` + `lines$` and never
10
12
  * have to rebuild BehaviorSubjects, manage a read loop, or serialize writes
11
13
  * themselves.
12
14
  *
@@ -15,9 +17,20 @@ import type { SerialSessionState } from './serial-session-state';
15
17
  *
16
18
  * @example
17
19
  * ```typescript
20
+ * import { createSerialSession, SerialSessionStatus } from '@gurezo/web-serial-rxjs';
21
+ *
18
22
  * const session = createSerialSession({ baudRate: 115200 });
19
23
  *
20
- * session.state$.subscribe((state) => console.log('state:', state));
24
+ * session.state$.subscribe((state) => {
25
+ * switch (state.status) {
26
+ * case SerialSessionStatus.Connected:
27
+ * console.log('connected:', state.portInfo);
28
+ * break;
29
+ * case SerialSessionStatus.Error:
30
+ * console.error('error:', state.error);
31
+ * break;
32
+ * }
33
+ * });
21
34
  * session.receive$.subscribe((chunk) => console.log('rx:', chunk));
22
35
  * session.errors$.subscribe((error) => console.error('err:', error));
23
36
  *
@@ -79,48 +92,69 @@ export interface SerialSession {
79
92
  /**
80
93
  * Alias for {@link dispose$}.
81
94
  *
95
+ * @deprecated Prefer {@link dispose$}. This alias is retained for backward
96
+ * compatibility and is scheduled for removal in the next major version.
97
+ *
82
98
  * @returns An Observable that completes when disposal has finished.
99
+ *
100
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/433 | Issue #433}
83
101
  */
84
102
  destroy$(): Observable<void>;
85
103
  /**
86
- * Reactive session lifecycle state.
104
+ * Canonical lifecycle source for the session.
87
105
  *
88
- * Replays the current state on subscribe. UIs should drive entirely from
89
- * this stream instead of reconstructing their own BehaviorSubject.
106
+ * Reactive session lifecycle state as a discriminated union. Replays the
107
+ * current state on subscribe. Switch on `state.status` and use the
108
+ * per-variant fields (`portInfo` when {@link SerialSessionStatus.Connected},
109
+ * `error` when {@link SerialSessionStatus.Error}) instead of correlating
110
+ * separate streams.
90
111
  */
91
112
  readonly state$: Observable<SerialSessionState>;
92
113
  /**
93
- * `true` when {@link state$} is `'connected'`, `false` for all other states.
114
+ * `true` when {@link state$} has `status: 'connected'`, `false` otherwise.
94
115
  *
95
116
  * Derived from `state$` with `distinctUntilChanged` so UIs can bind
96
117
  * connect/disabled flags without reimplementing the comparison.
118
+ *
119
+ * @deprecated Prefer narrowing {@link state$} with
120
+ * {@link SerialSessionStatus.Connected}. Retained for backward compatibility;
121
+ * scheduled for removal in the next major version.
122
+ *
123
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/435 | Issue #435}
97
124
  */
98
125
  readonly isConnected$: Observable<boolean>;
99
126
  /**
100
127
  * The active port’s {@link SerialPort.getInfo} snapshot, or `null` when no
101
- * port is open (including {@link SerialSessionState.Idle},
102
- * {@link SerialSessionState.Error}, and {@link SerialSessionState.Unsupported}).
128
+ * port is open (including {@link SerialSessionStatus.Idle},
129
+ * {@link SerialSessionStatus.Error}, and {@link SerialSessionStatus.Unsupported}).
103
130
  *
104
131
  * Emits the current value on subscribe. Use with {@link state$} to know when
105
132
  * the value is valid for your UI.
133
+ *
134
+ * @deprecated Prefer narrowing {@link state$} with
135
+ * {@link SerialSessionStatus.Connected} and using `state.portInfo`.
136
+ * Retained for backward compatibility; scheduled for removal in the next
137
+ * major version.
138
+ *
139
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/434 | Issue #434}
106
140
  */
107
141
  readonly portInfo$: Observable<SerialPortInfo | null>;
108
142
  /**
109
143
  * Synchronous read of the last {@link portInfo$} value.
110
144
  *
145
+ * @deprecated Prefer narrowing {@link state$} with
146
+ * {@link SerialSessionStatus.Connected} and using `state.portInfo`.
147
+ * Retained for backward compatibility; scheduled for removal in the next
148
+ * major version.
149
+ *
111
150
  * @returns The same as {@link SerialPort.getInfo} for the open port, or
112
151
  * `null` when not connected.
113
- */
114
- getPortInfo(): SerialPortInfo | null;
115
- /**
116
- * The underlying `SerialPort` while connected, or `null` otherwise.
117
152
  *
118
- * Avoid calling `port.close()` or replacing streams yourself; that conflicts
119
- * with session lifecycle. Prefer {@link getPortInfo} for identification.
153
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/434 | Issue #434}
120
154
  */
121
- getCurrentPort(): SerialPort | null;
155
+ getPortInfo(): SerialPortInfo | null;
122
156
  /**
123
- * Primary error channel.
157
+ * Canonical fatal / non-fatal error channel.
124
158
  *
125
159
  * All {@link SerialError} instances produced by the session (connect /
126
160
  * read / write / close) are multiplexed here. This is the main channel,
@@ -233,6 +267,6 @@ export interface SerialSession {
233
267
  *
234
268
  * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/203 | Issue #203}
235
269
  */
236
- send$(data: string | Uint8Array): Observable<void>;
270
+ send$(data: SerialPayload): Observable<void>;
237
271
  }
238
272
  //# sourceMappingURL=serial-session.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"serial-session.d.ts","sourceRoot":"","sources":["../../src/session/serial-session.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAC;AACvC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,wBAAwB,CAAC;AAEjE;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,MAAM,WAAW,aAAa;IAC5B;;;;;;OAMG;IACH,kBAAkB,IAAI,OAAO,CAAC;IAE9B;;;;;;;;OAQG;IACH,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAE7B;;;;;;;;;OASG;IACH,WAAW,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAEhC;;;;;;;;;;;;;;;OAeG;IACH,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAE7B;;;;OAIG;IACH,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC,CAAC;IAE7B;;;;;OAKG;IACH,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAEhD;;;;;OAKG;IACH,QAAQ,CAAC,YAAY,EAAE,UAAU,CAAC,OAAO,CAAC,CAAC;IAE3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 import { Observable } from 'rxjs';
2
+ import type { SerialError } from '../errors/serial-error';
3
+ import type { ReadPump } from './read-pump';
4
+ import { SerialSessionStatus, type SerialSessionState, type SerialSessionStatus as SerialSessionStatusType } from './serial-session-state';
5
+ /**
6
+ * Discriminated union representing the full internal runtime state of a
7
+ * {@link SerialSession}, including lifecycle status and any resources that
8
+ * are valid for that status.
9
+ *
10
+ * This is the single source of truth for session lifecycle + resources.
11
+ * Public consumers observe the mapped {@link SerialSessionState} via
12
+ * `state$`; this union is internal only.
13
+ *
14
+ * @internal
15
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/397 | Issue #397}
16
+ */
17
+ export type SessionRuntime = IdleRuntime | ConnectingRuntime | ConnectedRuntime | DisconnectingRuntime | ErrorRuntime | UnsupportedRuntime | DisposedRuntime;
18
+ /** @internal */
19
+ export interface IdleRuntime {
20
+ readonly status: typeof SerialSessionStatus.Idle;
21
+ }
22
+ /** @internal */
23
+ export interface ConnectingRuntime {
24
+ readonly status: typeof SerialSessionStatus.Connecting;
25
+ readonly cancel: () => void;
26
+ }
27
+ /** @internal */
28
+ export interface ConnectedRuntime {
29
+ readonly status: typeof SerialSessionStatus.Connected;
30
+ readonly port: SerialPort;
31
+ readonly pump: ReadPump;
32
+ }
33
+ /** @internal */
34
+ export interface DisconnectingRuntime {
35
+ readonly status: typeof SerialSessionStatus.Disconnecting;
36
+ readonly port: SerialPort | null;
37
+ }
38
+ /** @internal */
39
+ export interface ErrorRuntime {
40
+ readonly status: typeof SerialSessionStatus.Error;
41
+ readonly error: SerialError;
42
+ }
43
+ /** @internal */
44
+ export interface UnsupportedRuntime {
45
+ readonly status: typeof SerialSessionStatus.Unsupported;
46
+ }
47
+ /** @internal */
48
+ export interface DisposedRuntime {
49
+ readonly status: typeof SerialSessionStatus.Disposed;
50
+ }
51
+ /**
52
+ * Allowed transitions for the internal SerialSession state machine.
53
+ *
54
+ * `as const satisfies` keeps literal transition targets while ensuring every
55
+ * {@link SerialSessionStatus} key is present. Drift from the status union
56
+ * becomes a compile error.
57
+ *
58
+ * @internal
59
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/398 | Issue #398}
60
+ */
61
+ export declare const ALLOWED_TRANSITIONS: {
62
+ readonly idle: readonly ["connecting", "error", "disposed"];
63
+ readonly connecting: readonly ["connected", "error", "idle", "disposed"];
64
+ readonly connected: readonly ["disconnecting", "error", "disposed"];
65
+ readonly disconnecting: readonly ["idle", "error", "disposed"];
66
+ readonly error: readonly ["idle", "connecting", "disposed"];
67
+ readonly unsupported: readonly ["disposed"];
68
+ readonly disposed: readonly [];
69
+ };
70
+ /**
71
+ * Valid target states when transitioning from {@link T}.
72
+ *
73
+ * @internal
74
+ */
75
+ export type AllowedTransition<T extends SerialSessionStatusType> = (typeof ALLOWED_TRANSITIONS)[T][number];
76
+ /** @internal */
77
+ export declare function runtimeToSessionStatus(runtime: SessionRuntime): SerialSessionStatusType;
78
+ /**
79
+ * Map internal runtime to the public {@link SerialSessionState} payload.
80
+ *
81
+ * @internal
82
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/406 | Issue #406}
83
+ */
84
+ export declare function runtimeToPublicState(runtime: SessionRuntime): SerialSessionState;
85
+ /** @internal */
86
+ export declare function isValidTransition(from: SerialSessionStatusType, to: SerialSessionStatusType): boolean;
87
+ /** @internal */
88
+ export declare function createIdleRuntime(): IdleRuntime;
89
+ /** @internal */
90
+ export declare function createConnectingRuntime(cancel: () => void): ConnectingRuntime;
91
+ /** @internal */
92
+ export declare function createConnectedRuntime(port: SerialPort, pump: ReadPump): ConnectedRuntime;
93
+ /** @internal */
94
+ export declare function createDisconnectingRuntime(port: SerialPort | null): DisconnectingRuntime;
95
+ /** @internal */
96
+ export declare function createErrorRuntime(error: SerialError): ErrorRuntime;
97
+ /** @internal */
98
+ export declare function createUnsupportedRuntime(): UnsupportedRuntime;
99
+ /** @internal */
100
+ export declare function createDisposedRuntime(): DisposedRuntime;
101
+ /** @internal */
102
+ export declare function createInitialRuntime(supported: boolean): SessionRuntime;
103
+ /**
104
+ * Extract the active port from runtime when one is held.
105
+ *
106
+ * @internal
107
+ */
108
+ export declare function getRuntimePort(runtime: SessionRuntime): SerialPort | null;
109
+ /**
110
+ * Extract the active pump from runtime when one is held.
111
+ *
112
+ * @internal
113
+ */
114
+ export declare function getRuntimePump(runtime: SessionRuntime): ReadPump | null;
115
+ /**
116
+ * Controller that owns the {@link SessionRuntime} discriminated union and
117
+ * exposes the public `state$` stream derived from the runtime.
118
+ *
119
+ * @internal
120
+ */
121
+ export interface SessionRuntimeController {
122
+ get runtime(): SessionRuntime;
123
+ get status(): SerialSessionStatusType;
124
+ get state$(): Observable<SerialSessionState>;
125
+ transition(next: SessionRuntime): boolean;
126
+ complete(): void;
127
+ }
128
+ /**
129
+ * Create a controller for the internal session runtime.
130
+ *
131
+ * @internal
132
+ */
133
+ export declare function createSessionRuntimeController(initial: SessionRuntime): SessionRuntimeController;
134
+ /**
135
+ * Exhaustiveness helper for switch statements over {@link SessionRuntime}.
136
+ *
137
+ * @internal
138
+ */
139
+ export declare function assertNeverRuntime(value: never): never;
140
+ //# sourceMappingURL=session-runtime.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"session-runtime.d.ts","sourceRoot":"","sources":["../../src/session/session-runtime.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,UAAU,EAAE,MAAM,MAAM,CAAC;AAEnD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAC1D,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EACL,mBAAmB,EACnB,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,IAAI,uBAAuB,EACpD,MAAM,wBAAwB,CAAC;AAEhC;;;;;;;;;;;GAWG;AACH,MAAM,MAAM,cAAc,GACtB,WAAW,GACX,iBAAiB,GACjB,gBAAgB,GAChB,oBAAoB,GACpB,YAAY,GACZ,kBAAkB,GAClB,eAAe,CAAC;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C7C,UAAU,CAAC,IAAI,EAAE,cAAc,GAAG,OAAO,CAAC;IAC1C,QAAQ,IAAI,IAAI,CAAC;CAClB;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,cAAc,GACtB,wBAAwB,CA2C1B;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,KAAK,GAAG,KAAK,CAEtD"}
@@ -1,4 +1,5 @@
1
1
  import { type Observable } from 'rxjs';
2
+ import { type MaxChars, type MaxLines } from '../internal/branded-numbers';
2
3
  /** @internal Folded state between {@link createTerminalBuffer} emissions. */
3
4
  export interface TerminalBufferState {
4
5
  completed: string;
@@ -7,7 +8,9 @@ export interface TerminalBufferState {
7
8
  /**
8
9
  * Applies one raw decoder chunk to terminal display state.
9
10
  * Handles `\r\n` and lone `\n` as line endings, and lone `\r` as
10
- * carriage return (clear current line for redraw). Does not interpret ANSI escapes.
11
+ * carriage return (clear current line for redraw). When
12
+ * {@link TerminalBufferOptions.stripAnsi} is enabled (default), ANSI escape
13
+ * sequences are removed before line folding.
11
14
  *
12
15
  * @internal Exported for unit tests.
13
16
  */
@@ -16,8 +19,8 @@ export declare function applyTerminalChunk(state: TerminalBufferState, chunk: st
16
19
  export declare function terminalDisplayText(state: TerminalBufferState): string;
17
20
  /** Resolved limits for {@link trimTerminalState}. `0` means unlimited. */
18
21
  export interface TerminalBufferLimits {
19
- maxLines: number;
20
- maxChars: number;
22
+ maxLines: MaxLines;
23
+ maxChars: MaxChars;
21
24
  }
22
25
  /** @internal Count newline-terminated rows in `completed`. */
23
26
  export declare function countCompletedLines(completed: string): number;
@@ -57,6 +60,15 @@ export interface TerminalBufferOptions {
57
60
  * @default 1048576
58
61
  */
59
62
  maxChars?: number;
63
+ /**
64
+ * When `true`, strips ANSI escape sequences from incoming chunks before
65
+ * folding carriage-return redraws. Use `false` to preserve raw escape
66
+ * codes in {@link TerminalBuffer.text$}.
67
+ *
68
+ * @default true
69
+ * @see {@link https://github.com/gurezo/web-serial-rxjs/issues/428 | Issue #428}
70
+ */
71
+ stripAnsi?: boolean;
60
72
  }
61
73
  /** Default limits applied when options are omitted. */
62
74
  export declare const DEFAULT_TERMINAL_BUFFER_OPTIONS: Required<TerminalBufferOptions>;
@@ -1 +1 @@
1
- {"version":3,"file":"create-terminal-buffer.d.ts","sourceRoot":"","sources":["../../src/terminal/create-terminal-buffer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAA0B,MAAM,MAAM,CAAC;AAG/D,6EAA6E;AAC7E,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED;;;;;;GAMG;AACH,wBAAgB,kBAAkB,CAChC,KAAK,EAAE,mBAAmB,EAC1B,KAAK,EAAE,MAAM,GACZ,mBAAmB,CAgBrB;AAED,gBAAgB;AAChB,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,mBAAmB,GAAG,MAAM,CAEtE;AAED,0EAA0E;AAC1E,MAAM,WAAW,oBAAoB;IACnC,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,8DAA8D;AAC9D,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM,CAW7D;AAED;;;;GAIG;AACH,wBAAgB,uBAAuB,CACrC,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,GACf,MAAM,CAcR;AAED;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,mBAAmB,EAC1B,MAAM,EAAE,oBAAoB,GAC3B,mBAAmB,CAuBrB;AAED,MAAM,WAAW,cAAc;IAC7B;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;CACpC;AAED,mFAAmF;AACnF,MAAM,WAAW,qBAAqB;IACpC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,MAAM,CAA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