@gurezo/web-serial-rxjs 2.3.6 → 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.
- package/README.ja.md +1 -1
- package/README.md +1 -1
- package/dist/errors/serial-error-code.d.ts +92 -14
- package/dist/errors/serial-error-code.d.ts.map +1 -1
- package/dist/errors/serial-error-context.d.ts +47 -0
- package/dist/errors/serial-error-context.d.ts.map +1 -0
- package/dist/errors/serial-error.d.ts +30 -8
- package/dist/errors/serial-error.d.ts.map +1 -1
- package/dist/index.d.ts +13 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1327 -493
- package/dist/index.mjs.map +4 -4
- package/dist/internal/assert-never.d.ts +2 -0
- package/dist/internal/assert-never.d.ts.map +1 -0
- package/dist/internal/branded-numbers.d.ts +37 -0
- package/dist/internal/branded-numbers.d.ts.map +1 -0
- package/dist/internal/newline-tokenizer.d.ts +38 -0
- package/dist/internal/newline-tokenizer.d.ts.map +1 -0
- package/dist/session/create-serial-session.d.ts +7 -3
- package/dist/session/create-serial-session.d.ts.map +1 -1
- package/dist/session/index.d.ts +7 -2
- package/dist/session/index.d.ts.map +1 -1
- package/dist/session/internal/build-request-options.d.ts +7 -7
- package/dist/session/internal/build-request-options.d.ts.map +1 -1
- package/dist/session/internal/error-severity.d.ts +38 -0
- package/dist/session/internal/error-severity.d.ts.map +1 -0
- package/dist/session/internal/line-buffer.d.ts +37 -4
- package/dist/session/internal/line-buffer.d.ts.map +1 -1
- package/dist/session/internal/receive-pipeline.d.ts +34 -0
- package/dist/session/internal/receive-pipeline.d.ts.map +1 -0
- package/dist/session/internal/receive-replay-buffer.d.ts +38 -0
- package/dist/session/internal/receive-replay-buffer.d.ts.map +1 -0
- package/dist/session/internal/session-error-reporter.d.ts +32 -0
- package/dist/session/internal/session-error-reporter.d.ts.map +1 -0
- package/dist/session/internal/session-lifecycle.d.ts +44 -0
- package/dist/session/internal/session-lifecycle.d.ts.map +1 -0
- package/dist/session/internal/validate-serial-port-filters.d.ts +12 -0
- package/dist/session/internal/validate-serial-port-filters.d.ts.map +1 -0
- package/dist/session/read-pump.d.ts +9 -1
- package/dist/session/read-pump.d.ts.map +1 -1
- package/dist/session/serial-session-options.d.ts +133 -46
- package/dist/session/serial-session-options.d.ts.map +1 -1
- package/dist/session/serial-session-state.d.ts +50 -12
- package/dist/session/serial-session-state.d.ts.map +1 -1
- package/dist/session/serial-session.d.ts +44 -9
- package/dist/session/serial-session.d.ts.map +1 -1
- package/dist/session/session-runtime.d.ts +140 -0
- package/dist/session/session-runtime.d.ts.map +1 -0
- package/dist/terminal/create-terminal-buffer.d.ts +48 -1
- package/dist/terminal/create-terminal-buffer.d.ts.map +1 -1
- package/dist/types.d.ts +18 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +2 -1
- package/dist/index.js +0 -724
- package/dist/session/session-state-machine.d.ts +0 -39
- package/dist/session/session-state-machine.d.ts.map +0 -1
|
@@ -1,11 +1,9 @@
|
|
|
1
|
+
import type { SerialError } from '../errors/serial-error';
|
|
1
2
|
/**
|
|
2
|
-
*
|
|
3
|
+
* Canonical status literals for a {@link SerialSession} lifecycle.
|
|
3
4
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
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,22 +12,62 @@
|
|
|
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/
|
|
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
|
|
20
|
+
export declare const SerialSessionStatus: {
|
|
23
21
|
readonly Idle: "idle";
|
|
24
22
|
readonly Connecting: "connecting";
|
|
25
23
|
readonly Connected: "connected";
|
|
26
24
|
readonly Disconnecting: "disconnecting";
|
|
27
25
|
readonly Unsupported: "unsupported";
|
|
28
26
|
readonly Error: "error";
|
|
27
|
+
readonly Disposed: "disposed";
|
|
29
28
|
};
|
|
30
29
|
/**
|
|
31
|
-
* String union of allowed {@link
|
|
32
|
-
* (same set as the values on the {@link
|
|
30
|
+
* String union of allowed {@link SerialSessionStatus} runtime values
|
|
31
|
+
* (same set as the values on the {@link SerialSessionStatus} object).
|
|
33
32
|
*/
|
|
34
|
-
export type
|
|
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
|
+
/** @see {@link SerialSessionState} */
|
|
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$}.
|
|
66
|
+
*
|
|
67
|
+
* Each variant carries the lifecycle `status` plus optional detail fields
|
|
68
|
+
* (`portInfo` when connected, `error` when in a fatal error state).
|
|
69
|
+
*
|
|
70
|
+
* @see {@link https://github.com/gurezo/web-serial-rxjs/issues/406 | Issue #406}
|
|
71
|
+
*/
|
|
72
|
+
export type SerialSessionState = IdleSessionState | ConnectingSessionState | ConnectedSessionState | DisconnectingSessionState | UnsupportedSessionState | ErrorSessionState | DisposedSessionState;
|
|
35
73
|
//# 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
|
|
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,sCAAsC;AACtC,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;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAC1B,gBAAgB,GAChB,sBAAsB,GACtB,qBAAqB,GACrB,yBAAyB,GACzB,uBAAuB,GACvB,iBAAiB,GACjB,oBAAoB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
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
6
|
* v2 public API for interacting with the Web Serial API through a
|
|
@@ -51,20 +52,47 @@ export interface SerialSession {
|
|
|
51
52
|
/**
|
|
52
53
|
* Close the active serial port and stop the internal read pump.
|
|
53
54
|
*
|
|
54
|
-
* Safe to call when already disconnected
|
|
55
|
+
* Safe to call when already disconnected or while a disconnect is already
|
|
56
|
+
* in progress. When called during `'connecting'`, cancels the in-flight
|
|
57
|
+
* `connect$()` (closes any opened port) and returns the session to
|
|
58
|
+
* `'idle'` without reaching `'connected'`.
|
|
55
59
|
*
|
|
56
60
|
* @returns An Observable that completes when the port is fully closed.
|
|
57
61
|
*/
|
|
58
62
|
disconnect$(): Observable<void>;
|
|
59
63
|
/**
|
|
60
|
-
*
|
|
64
|
+
* Permanently tear down the session and complete all observables.
|
|
61
65
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
66
|
+
* Unlike {@link disconnect$}, which returns the session to `'idle'` for
|
|
67
|
+
* reuse, `dispose$` closes any active connection, releases internal
|
|
68
|
+
* resources, emits `'disposed'` on {@link state$}, and completes every
|
|
69
|
+
* session stream. After disposal, {@link connect$} and {@link send$}
|
|
70
|
+
* fail with {@link SerialErrorCode.SESSION_DISPOSED}; create a new
|
|
71
|
+
* session instead of reusing this instance.
|
|
72
|
+
*
|
|
73
|
+
* Safe to call multiple times; subsequent calls complete immediately.
|
|
74
|
+
*
|
|
75
|
+
* @returns An Observable that completes when disposal has finished.
|
|
76
|
+
*
|
|
77
|
+
* @see {@link https://github.com/gurezo/web-serial-rxjs/issues/373 | Issue #373}
|
|
78
|
+
*/
|
|
79
|
+
dispose$(): Observable<void>;
|
|
80
|
+
/**
|
|
81
|
+
* Alias for {@link dispose$}.
|
|
82
|
+
*
|
|
83
|
+
* @returns An Observable that completes when disposal has finished.
|
|
84
|
+
*/
|
|
85
|
+
destroy$(): Observable<void>;
|
|
86
|
+
/**
|
|
87
|
+
* Reactive session lifecycle state as a discriminated union.
|
|
88
|
+
*
|
|
89
|
+
* Replays the current state on subscribe. Switch on `state.status` and
|
|
90
|
+
* use the per-variant fields (`portInfo`, `error`) instead of correlating
|
|
91
|
+
* separate streams.
|
|
64
92
|
*/
|
|
65
93
|
readonly state$: Observable<SerialSessionState>;
|
|
66
94
|
/**
|
|
67
|
-
* `true` when {@link state$}
|
|
95
|
+
* `true` when {@link state$} has `status: 'connected'`, `false` otherwise.
|
|
68
96
|
*
|
|
69
97
|
* Derived from `state$` with `distinctUntilChanged` so UIs can bind
|
|
70
98
|
* connect/disabled flags without reimplementing the comparison.
|
|
@@ -72,8 +100,8 @@ export interface SerialSession {
|
|
|
72
100
|
readonly isConnected$: Observable<boolean>;
|
|
73
101
|
/**
|
|
74
102
|
* The active port’s {@link SerialPort.getInfo} snapshot, or `null` when no
|
|
75
|
-
* port is open (including {@link
|
|
76
|
-
* {@link
|
|
103
|
+
* port is open (including {@link SerialSessionStatus.Idle},
|
|
104
|
+
* {@link SerialSessionStatus.Error}, and {@link SerialSessionStatus.Unsupported}).
|
|
77
105
|
*
|
|
78
106
|
* Emits the current value on subscribe. Use with {@link state$} to know when
|
|
79
107
|
* the value is valid for your UI.
|
|
@@ -142,6 +170,8 @@ export interface SerialSession {
|
|
|
142
170
|
* This stream collapses carriage-return redraws (`\r`) and keeps normal
|
|
143
171
|
* newline behavior (`\n`, `\r\n`) so apps can bind terminal-like output
|
|
144
172
|
* directly without wrapping {@link createTerminalBuffer} in every consumer.
|
|
173
|
+
* By default, retains at most 10,000 completed lines and 1,048,576
|
|
174
|
+
* characters; configure via {@link SerialSessionOptions.terminalBuffer}.
|
|
145
175
|
*
|
|
146
176
|
* Equivalent behavior:
|
|
147
177
|
*
|
|
@@ -170,11 +200,16 @@ export interface SerialSession {
|
|
|
170
200
|
* rendering terminal text, prefer {@link terminalText$}.
|
|
171
201
|
*
|
|
172
202
|
* A trailing fragment without a line terminator is buffered until a later
|
|
173
|
-
* chunk completes a line, or discarded on disconnect.
|
|
203
|
+
* chunk completes a line, or discarded on disconnect. The incomplete tail is
|
|
204
|
+
* bounded by {@link SerialSessionOptions.lineBuffer} `maxChars` (default
|
|
205
|
+
* 1,048,576); when exceeded, leading characters are discarded and a
|
|
206
|
+
* non-fatal {@link SerialErrorCode.LINE_BUFFER_OVERFLOW} is emitted on
|
|
207
|
+
* {@link errors$}. Pass `{ maxChars: 0 }` for unlimited growth. It is **not**
|
|
174
208
|
* subscription-lazy: the same framing runs whenever the read pump is active,
|
|
175
209
|
* independent of subscribers.
|
|
176
210
|
*
|
|
177
211
|
* @see {@link https://github.com/gurezo/web-serial-rxjs/issues/273 | Issue #273}
|
|
212
|
+
* @see {@link https://github.com/gurezo/web-serial-rxjs/issues/371 | Issue #371}
|
|
178
213
|
*/
|
|
179
214
|
readonly lines$: Observable<string>;
|
|
180
215
|
/**
|
|
@@ -200,6 +235,6 @@ export interface SerialSession {
|
|
|
200
235
|
*
|
|
201
236
|
* @see {@link https://github.com/gurezo/web-serial-rxjs/issues/203 | Issue #203}
|
|
202
237
|
*/
|
|
203
|
-
send$(data:
|
|
238
|
+
send$(data: SerialPayload): Observable<void>;
|
|
204
239
|
}
|
|
205
240
|
//# 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
|
|
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,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OAUG;IACH,QAAQ,CAAC,cAAc,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAE5C;;;;;;;;;;;;;;;;;;OAkBG;IACH,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC,MAAM,CAAC,CAAC;IAEpC;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,KAAK,CAAC,IAAI,EAAE,aAAa,GAAG,UAAU,CAAC,IAAI,CAAC,CAAC;CAC9C"}
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
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,M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AAI,cAAc,CAAC;IAC9B,IAAI,MAAM,IAAI,uBAAuB,CAAC;IACtC,IAAI,MAAM,IAAI,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAC7C,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;
|
|
@@ -14,6 +15,27 @@ export interface TerminalBufferState {
|
|
|
14
15
|
export declare function applyTerminalChunk(state: TerminalBufferState, chunk: string): TerminalBufferState;
|
|
15
16
|
/** @internal */
|
|
16
17
|
export declare function terminalDisplayText(state: TerminalBufferState): string;
|
|
18
|
+
/** Resolved limits for {@link trimTerminalState}. `0` means unlimited. */
|
|
19
|
+
export interface TerminalBufferLimits {
|
|
20
|
+
maxLines: MaxLines;
|
|
21
|
+
maxChars: MaxChars;
|
|
22
|
+
}
|
|
23
|
+
/** @internal Count newline-terminated rows in `completed`. */
|
|
24
|
+
export declare function countCompletedLines(completed: string): number;
|
|
25
|
+
/**
|
|
26
|
+
* Drops oldest completed lines when `maxLines` is exceeded.
|
|
27
|
+
*
|
|
28
|
+
* @internal Exported for unit tests.
|
|
29
|
+
*/
|
|
30
|
+
export declare function trimCompletedByMaxLines(completed: string, maxLines: number): string;
|
|
31
|
+
/**
|
|
32
|
+
* Trims {@link TerminalBufferState} to respect memory limits. Oldest
|
|
33
|
+
* `completed` content is removed first; `currentLine` is trimmed only when
|
|
34
|
+
* the display text still exceeds `maxChars` after `completed` is empty.
|
|
35
|
+
*
|
|
36
|
+
* @internal Exported for unit tests.
|
|
37
|
+
*/
|
|
38
|
+
export declare function trimTerminalState(state: TerminalBufferState, limits: TerminalBufferLimits): TerminalBufferState;
|
|
17
39
|
export interface TerminalBuffer {
|
|
18
40
|
/**
|
|
19
41
|
* Cumulative text suitable for terminal-style display: completed lines plus
|
|
@@ -21,10 +43,35 @@ export interface TerminalBuffer {
|
|
|
21
43
|
*/
|
|
22
44
|
readonly text$: Observable<string>;
|
|
23
45
|
}
|
|
46
|
+
/** Options for {@link createTerminalBuffer} memory limits. `0` means unlimited. */
|
|
47
|
+
export interface TerminalBufferOptions {
|
|
48
|
+
/**
|
|
49
|
+
* Maximum number of completed lines to retain in the display buffer.
|
|
50
|
+
*
|
|
51
|
+
* @default 10000
|
|
52
|
+
*/
|
|
53
|
+
maxLines?: number;
|
|
54
|
+
/**
|
|
55
|
+
* Maximum total characters in the cumulative display text
|
|
56
|
+
* (`completed` + `currentLine`). Oldest content is dropped first.
|
|
57
|
+
*
|
|
58
|
+
* @default 1048576
|
|
59
|
+
*/
|
|
60
|
+
maxChars?: number;
|
|
61
|
+
}
|
|
62
|
+
/** Default limits applied when options are omitted. */
|
|
63
|
+
export declare const DEFAULT_TERMINAL_BUFFER_OPTIONS: Required<TerminalBufferOptions>;
|
|
24
64
|
/**
|
|
25
65
|
* Builds a terminal-oriented text stream from {@link SerialSession.receive$} (or any
|
|
26
66
|
* `Observable<string>` of decoded chunks). Uses internal buffering so callers need not
|
|
27
67
|
* implement carriage-return collapse themselves.
|
|
68
|
+
*
|
|
69
|
+
* By default, retains at most {@link DEFAULT_TERMINAL_BUFFER_OPTIONS.maxLines}
|
|
70
|
+
* completed lines and {@link DEFAULT_TERMINAL_BUFFER_OPTIONS.maxChars} characters
|
|
71
|
+
* so long-running sessions do not grow memory without bound. Pass `0` for either
|
|
72
|
+
* limit to disable that constraint.
|
|
73
|
+
*
|
|
74
|
+
* @see {@link https://github.com/gurezo/web-serial-rxjs/issues/370 | Issue #370}
|
|
28
75
|
*/
|
|
29
|
-
export declare function createTerminalBuffer(receive$: Observable<string
|
|
76
|
+
export declare function createTerminalBuffer(receive$: Observable<string>, options?: TerminalBufferOptions): TerminalBuffer;
|
|
30
77
|
//# sourceMappingURL=create-terminal-buffer.d.ts.map
|
|
@@ -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;
|
|
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;AAC/D,OAAO,EAGL,KAAK,QAAQ,EACb,KAAK,QAAQ,EACd,MAAM,6BAA6B,CAAC;AAGrC,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,QAAQ,CAAC;IACnB,QAAQ,EAAE,QAAQ,CAAC;CACpB;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,CAAC;IAElB;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED,uDAAuD;AACvD,eAAO,MAAM,+BAA+B,EAAE,QAAQ,CAAC,qBAAqB,CAIzE,CAAC;AAkBJ;;;;;;;;;;;GAWG;AACH,wBAAgB,oBAAoB,CAClC,QAAQ,EAAE,UAAU,CAAC,MAAM,CAAC,EAC5B,OAAO,CAAC,EAAE,qBAAqB,GAC9B,cAAc,CAahB"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Payload accepted by {@link SerialSession.send$}.
|
|
3
|
+
*
|
|
4
|
+
* Strings are UTF-8 encoded via a shared `TextEncoder`; `Uint8Array` values
|
|
5
|
+
* are passed through unchanged.
|
|
6
|
+
*/
|
|
7
|
+
export type SerialPayload = string | Uint8Array;
|
|
8
|
+
/**
|
|
9
|
+
* Connection parameters passed to `port.open` when opening a serial port.
|
|
10
|
+
*
|
|
11
|
+
* Derived from the W3C {@link SerialOptions} type. Excludes
|
|
12
|
+
* {@link SerialSessionOptions.filters}, which apply only to
|
|
13
|
+
* `navigator.serial.requestPort`.
|
|
14
|
+
*
|
|
15
|
+
* @see {@link SerialOptions}
|
|
16
|
+
*/
|
|
17
|
+
export type SerialConnectionOptions = Pick<SerialOptions, 'baudRate' | 'dataBits' | 'stopBits' | 'parity' | 'bufferSize' | 'flowControl'>;
|
|
18
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,MAAM,MAAM,aAAa,GAAG,MAAM,GAAG,UAAU,CAAC;AAEhD;;;;;;;;GAQG;AACH,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,aAAa,EACb,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,QAAQ,GAAG,YAAY,GAAG,aAAa,CAC/E,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@gurezo/web-serial-rxjs",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"description": "RxJS-based utilities for the Web Serial API, usable from Angular, React, Svelte, and Vanilla JavaScript/TypeScript.",
|
|
5
5
|
"author": "Akihiko Kigure <akihiko.kigure@gmail.com>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"build:bundle": "node esbuild.config.mjs",
|
|
27
27
|
"build:copy-files": "cp ../../LICENSE . 2>/dev/null || true",
|
|
28
28
|
"build:cleanup": "rm -rf dist/packages dist/package.json 2>/dev/null || true",
|
|
29
|
+
"verify:dist": "node scripts/verify-dist.mjs",
|
|
29
30
|
"clean": "rm -rf dist",
|
|
30
31
|
"prepublishOnly": "pnpm run build"
|
|
31
32
|
},
|