@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
package/README.ja.md
CHANGED
|
@@ -27,7 +27,7 @@ Web Serial API は**デスクトップ**ブラウザでのみサポートされ
|
|
|
27
27
|
|
|
28
28
|
## 受信の replay(`receive$` と `receiveReplay$`)
|
|
29
29
|
|
|
30
|
-
`receive$` は **non-replay** のままです。購読後に届くチャンクだけが見えます。接続ごとに直近 *N* 件のデコード済みテキスト**チャンク**(read pump の 1 回の `onChunk` あたり 1 件。文字数ではありません)を遅延購読者にも渡したい場合は、`createSerialSession` に `receiveReplay: { enabled: true, bufferSize: 512 }` を指定し、`receiveReplay$` を購読します。`bufferSize`
|
|
30
|
+
`receive$` は **non-replay** のままです。購読後に届くチャンクだけが見えます。接続ごとに直近 *N* 件のデコード済みテキスト**チャンク**(read pump の 1 回の `onChunk` あたり 1 件。文字数ではありません)を遅延購読者にも渡したい場合は、`createSerialSession` に `receiveReplay: { enabled: true, bufferSize: 512 }` を指定し、`receiveReplay$` を購読します。`bufferSize` は 1〜65536 の正の safe integer である必要があります。任意の `maxChars` で保持チャンク全体の文字数上限を指定でき、超過時は古いチャンクから破棄し non-fatal の `RECEIVE_REPLAY_BUFFER_OVERFLOW` を `errors$` に emit します。`bufferSize` やチャンクサイズを大きくするとメモリ負荷が増えます。receive replay が **無効**(既定)のとき、`receiveReplay$` は `receive$` と同じ hot ストリームです。`lines$` の行分割に replay は付きません。生チャンクの `receiveReplay$` のみが対象です。
|
|
31
31
|
|
|
32
32
|
## `receive$` と `lines$`
|
|
33
33
|
|
package/README.md
CHANGED
|
@@ -27,7 +27,7 @@ After a successful `connect$`, use `getPortInfo()` or subscribe to `portInfo$` f
|
|
|
27
27
|
|
|
28
28
|
## Receive replay (`receive$` vs `receiveReplay$`)
|
|
29
29
|
|
|
30
|
-
`receive$` is **non-replay**: late subscribers only see chunks emitted after they subscribe. To retain the last *N* decoded text **chunks** per open connection (same bytes as `receive$`, e.g. for boot logs), pass `receiveReplay: { enabled: true, bufferSize: 512 }` to `createSerialSession` and subscribe to `receiveReplay$`. Larger `bufferSize`
|
|
30
|
+
`receive$` is **non-replay**: late subscribers only see chunks emitted after they subscribe. To retain the last *N* decoded text **chunks** per open connection (same bytes as `receive$`, e.g. for boot logs), pass `receiveReplay: { enabled: true, bufferSize: 512 }` to `createSerialSession` and subscribe to `receiveReplay$`. `bufferSize` must be a positive safe integer up to 65536. Optional `maxChars` bounds total buffered characters by discarding oldest chunks (non-fatal `RECEIVE_REPLAY_BUFFER_OVERFLOW` on `errors$`). Larger `bufferSize` or chunk sizes use more memory. When receive replay is **off** (default), `receiveReplay$` is the same hot stream as `receive$`. This option does not add replay to `lines$`—only raw decoder chunks on `receiveReplay$`.
|
|
31
31
|
|
|
32
32
|
## `receive$` vs `lines$`
|
|
33
33
|
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
* }
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
|
-
export declare
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
111
|
+
readonly INVALID_FILTER_OPTIONS: "INVALID_FILTER_OPTIONS";
|
|
112
112
|
/**
|
|
113
113
|
* Operation was cancelled by the user.
|
|
114
114
|
*
|
|
@@ -118,14 +118,87 @@ 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
|
|
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
|
|
128
|
+
readonly OPERATION_TIMEOUT: "OPERATION_TIMEOUT";
|
|
129
|
+
/**
|
|
130
|
+
* Internal line buffer exceeded its configured size limit.
|
|
131
|
+
*
|
|
132
|
+
* This error occurs when the incomplete line tail held by the {@link SerialSession.lines$}
|
|
133
|
+
* framing buffer grows beyond {@link SerialSessionOptions.lineBuffer} `maxChars`.
|
|
134
|
+
* Leading characters are discarded to bound memory; the session remains connected.
|
|
135
|
+
*
|
|
136
|
+
* **Suggested action**: Increase `lineBuffer.maxChars`, handle framing on `receive$`,
|
|
137
|
+
* or ensure the device sends line terminators.
|
|
138
|
+
*/
|
|
139
|
+
readonly LINE_BUFFER_OVERFLOW: "LINE_BUFFER_OVERFLOW";
|
|
140
|
+
/**
|
|
141
|
+
* Invalid receive replay options provided.
|
|
142
|
+
*
|
|
143
|
+
* This error occurs when {@link SerialSessionOptions.receiveReplay} values are
|
|
144
|
+
* out of range, such as a non-integer `bufferSize` or `maxChars`.
|
|
145
|
+
*
|
|
146
|
+
* **Suggested action**: Verify `receiveReplay` options match the documented
|
|
147
|
+
* ranges and value types.
|
|
148
|
+
*/
|
|
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";
|
|
180
|
+
/**
|
|
181
|
+
* Receive replay buffer exceeded its configured character limit.
|
|
182
|
+
*
|
|
183
|
+
* This error occurs when buffered chunks on {@link SerialSession.receiveReplay$}
|
|
184
|
+
* exceed {@link SerialSessionOptions.receiveReplay} `maxChars`. Oldest chunks
|
|
185
|
+
* are discarded to bound memory; the session remains connected.
|
|
186
|
+
*
|
|
187
|
+
* **Suggested action**: Increase `receiveReplay.maxChars`, reduce chunk size at
|
|
188
|
+
* the source, or subscribe earlier to avoid relying on a large replay buffer.
|
|
189
|
+
*/
|
|
190
|
+
readonly RECEIVE_REPLAY_BUFFER_OVERFLOW: "RECEIVE_REPLAY_BUFFER_OVERFLOW";
|
|
191
|
+
/**
|
|
192
|
+
* Session has been disposed and can no longer be used.
|
|
193
|
+
*
|
|
194
|
+
* This error occurs when calling {@link SerialSession.connect$} or
|
|
195
|
+
* {@link SerialSession.send$} after {@link SerialSession.dispose$} has
|
|
196
|
+
* completed. Create a new session instead of reusing a disposed instance.
|
|
197
|
+
*
|
|
198
|
+
* **Suggested action**: Call {@link SerialSession.dispose$} only when
|
|
199
|
+
* permanently tearing down a session, then create a new one if needed.
|
|
200
|
+
*/
|
|
201
|
+
readonly SESSION_DISPOSED: "SESSION_DISPOSED";
|
|
129
202
|
/**
|
|
130
203
|
* Unknown error occurred.
|
|
131
204
|
*
|
|
@@ -134,6 +207,11 @@ export declare enum SerialErrorCode {
|
|
|
134
207
|
*
|
|
135
208
|
* **Suggested action**: Check the error message and originalError for more details.
|
|
136
209
|
*/
|
|
137
|
-
UNKNOWN
|
|
138
|
-
}
|
|
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];
|
|
139
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,
|
|
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,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC/C,CAAC,eAAe,CAAC,aAAa,CAAC,EAAE,SAAS,CAAC;IAC3C,CAAC,eAAe,CAAC,WAAW,CAAC,EAAE,uBAAuB,CAAC;IACvD,CAAC,eAAe,CAAC,YAAY,CAAC,EAAE,uBAAuB,CAAC;IACxD,CAAC,eAAe,CAAC,eAAe,CAAC,EAAE,uBAAuB,CAAC;IAC3D,CAAC,eAAe,CAAC,sBAAsB,CAAC,EAAE,SAAS,CAAC;IACpD,CAAC,eAAe,CAAC,mBAAmB,CAAC,EAAE,uBAAuB,CAAC;IAC/D,CAAC,eAAe,CAAC,iBAAiB,CAAC,EAAE,SAAS,CAAC;IAC/C,CAAC,eAAe,CAAC,oBAAoB,CAAC,EAAE;QACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;KAC3B,CAAC;IACF,CAAC,eAAe,CAAC,8BAA8B,CAAC,EAAE,SAAS,CAAC;IAC5D,CAAC,eAAe,CAAC,+BAA+B,CAAC,EAAE,SAAS,CAAC;IAC7D,CAAC,eAAe,CAAC,2BAA2B,CAAC,EAAE,SAAS,CAAC;IACzD,CAAC,eAAe,CAAC,0BAA0B,CAAC,EAAE,SAAS,CAAC;IACxD,CAAC,eAAe,CAAC,8BAA8B,CAAC,EAAE;QAChD,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;QAC1B,QAAQ,CAAC,UAAU,EAAE,MAAM,CAAC;KAC7B,CAAC;IACF,CAAC,eAAe,CAAC,gBAAgB,CAAC,EAAE,SAAS,CAAC;IAC9C,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,uBAAuB,CAAC;CACpD;AAYD;;GAEG;AACH,wBAAgB,kBAAkB,CAChC,IAAI,EAAE,eAAe,GACpB,IAAI,IAAI,MAAM;KACd,CAAC,IAAI,MAAM,qBAAqB,IAAI,qBAAqB,CAAC,CAAC,CAAC,SAAS,uBAAuB,GACzF,CAAC,GACD,KAAK,GAAG,qBAAqB,CAAC,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:
|
|
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:
|
|
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
|
|
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.
|
|
66
|
-
* //
|
|
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:
|
|
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;
|
|
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
|
@@ -15,10 +15,16 @@
|
|
|
15
15
|
*
|
|
16
16
|
* - {@link createSerialSession} - factory for a {@link SerialSession}
|
|
17
17
|
* - {@link createTerminalBuffer} - terminal-style display text from {@link SerialSession.receive$}
|
|
18
|
+
* - {@link TerminalBufferOptions} - memory limits for terminal display text
|
|
19
|
+
* - {@link LineBufferOptions} - memory limits for lines$ incomplete line tail
|
|
18
20
|
* - {@link SerialSession} - the runtime interface
|
|
19
21
|
* - {@link SerialSessionOptions} - connection options
|
|
20
|
-
* - {@link
|
|
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$`
|
|
21
26
|
* - {@link SerialError} / {@link SerialErrorCode} - unified error surface
|
|
27
|
+
* - {@link SerialErrorContextMap} - structured metadata per error code
|
|
22
28
|
*
|
|
23
29
|
* ## Browser Support
|
|
24
30
|
*
|
|
@@ -55,10 +61,12 @@
|
|
|
55
61
|
* }
|
|
56
62
|
* ```
|
|
57
63
|
*/
|
|
58
|
-
export {
|
|
59
|
-
export
|
|
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';
|
|
60
67
|
export { SerialError } from './errors/serial-error';
|
|
68
|
+
export type { SerialErrorCauseContext, SerialErrorContextMap } from './errors/serial-error';
|
|
61
69
|
export { SerialErrorCode } from './errors/serial-error-code';
|
|
62
|
-
export { createTerminalBuffer } from './terminal/create-terminal-buffer';
|
|
63
|
-
export type { TerminalBuffer } from './terminal/create-terminal-buffer';
|
|
70
|
+
export { createTerminalBuffer, DEFAULT_TERMINAL_BUFFER_OPTIONS } from './terminal/create-terminal-buffer';
|
|
71
|
+
export type { TerminalBuffer, TerminalBufferOptions } from './terminal/create-terminal-buffer';
|
|
64
72
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8DG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAEtD,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,2BAA2B,EAAE,2BAA2B,EAAE,8BAA8B,EAAE,4BAA4B,EAAE,MAAM,WAAW,CAAC;AAC7L,YAAY,EACV,aAAa,EACb,kBAAkB,EAClB,gBAAgB,EAChB,sBAAsB,EACtB,qBAAqB,EACrB,yBAAyB,EACzB,uBAAuB,EACvB,iBAAiB,EACjB,oBAAoB,EACpB,oBAAoB,EACpB,iCAAiC,EACjC,4BAA4B,EAC5B,aAAa,EACb,uBAAuB,EACvB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,YAAY,EAAE,uBAAuB,EAAE,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AAC5F,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAE7D,OAAO,EAAE,oBAAoB,EAAE,+BAA+B,EAAE,MAAM,mCAAmC,CAAC;AAC1G,YAAY,EAAE,cAAc,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC"}
|