@gurezo/web-serial-rxjs 0.1.21 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.ja.md +82 -13
  2. package/README.md +82 -13
  3. package/dist/errors/serial-error-code.d.ts +7 -0
  4. package/dist/errors/serial-error-code.d.ts.map +1 -1
  5. package/dist/index.d.ts +31 -30
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +469 -449
  8. package/dist/index.mjs +469 -449
  9. package/dist/index.mjs.map +4 -4
  10. package/dist/session/create-serial-session.d.ts +49 -0
  11. package/dist/session/create-serial-session.d.ts.map +1 -0
  12. package/dist/session/index.d.ts +5 -0
  13. package/dist/session/index.d.ts.map +1 -0
  14. package/dist/session/internal/build-request-options.d.ts +18 -0
  15. package/dist/session/internal/build-request-options.d.ts.map +1 -0
  16. package/dist/session/internal/has-web-serial-support.d.ts +12 -0
  17. package/dist/session/internal/has-web-serial-support.d.ts.map +1 -0
  18. package/dist/session/internal/line-buffer.d.ts +14 -0
  19. package/dist/session/internal/line-buffer.d.ts.map +1 -0
  20. package/dist/session/normalize-serial-error.d.ts +55 -0
  21. package/dist/session/normalize-serial-error.d.ts.map +1 -0
  22. package/dist/session/read-pump.d.ts +74 -0
  23. package/dist/session/read-pump.d.ts.map +1 -0
  24. package/dist/session/send-queue.d.ts +58 -0
  25. package/dist/session/send-queue.d.ts.map +1 -0
  26. package/dist/session/serial-session-options.d.ts +80 -0
  27. package/dist/session/serial-session-options.d.ts.map +1 -0
  28. package/dist/session/serial-session-state.d.ts +35 -0
  29. package/dist/session/serial-session-state.d.ts.map +1 -0
  30. package/dist/session/serial-session.d.ts +143 -0
  31. package/dist/session/serial-session.d.ts.map +1 -0
  32. package/dist/session/session-state-machine.d.ts +39 -0
  33. package/dist/session/session-state-machine.d.ts.map +1 -0
  34. package/package.json +1 -1
  35. package/dist/browser/browser-detection.d.ts +0 -104
  36. package/dist/browser/browser-detection.d.ts.map +0 -1
  37. package/dist/browser/browser-support.d.ts +0 -57
  38. package/dist/browser/browser-support.d.ts.map +0 -1
  39. package/dist/client/index.d.ts +0 -250
  40. package/dist/client/index.d.ts.map +0 -1
  41. package/dist/client/serial-client.d.ts +0 -98
  42. package/dist/client/serial-client.d.ts.map +0 -1
  43. package/dist/filters/build-request-options.d.ts +0 -42
  44. package/dist/filters/build-request-options.d.ts.map +0 -1
  45. package/dist/io/observable-to-writable.d.ts +0 -65
  46. package/dist/io/observable-to-writable.d.ts.map +0 -1
  47. package/dist/io/readable-to-observable.d.ts +0 -44
  48. package/dist/io/readable-to-observable.d.ts.map +0 -1
  49. package/dist/lib/web-serial-rxjs.d.ts +0 -7
  50. package/dist/lib/web-serial-rxjs.d.ts.map +0 -1
  51. package/dist/types/options.d.ts +0 -107
  52. package/dist/types/options.d.ts.map +0 -1
package/README.ja.md CHANGED
@@ -1,13 +1,12 @@
1
- # web-serial-rxjs
2
-
3
1
  <p align="center">
4
2
  <img src="https://raw.githubusercontent.com/gurezo/web-serial-rxjs/main/assets/icon/web-serial-rxjs-icon.png" alt="web-serial-rxjs プロジェクトアイコン" width="512" />
5
3
  </p>
6
4
 
7
- Web Serial API RxJS ベースのリアクティブなラッパーで提供する TypeScript ライブラリです。Web アプリケーションでシリアルポート通信を簡単に実現できます。
5
+ Web Serial API を最小限の Session 指向 RxJS API でラップする TypeScript ライブラリです。v2 では単一の `SerialSession` を公開し、アプリケーション側は `state$` / `isConnected$` / `receive$` / `lines$` / `errors$` を購読するだけで UI を駆動できます。BehaviorSubject による状態再構築・read loop・送信キューの自前実装は一切不要です。
8
6
 
9
7
  ## 目次
10
8
 
9
+ - [SerialSession(v2)の全体像](#serialsessionv2の全体像)
11
10
  - [機能](#機能)
12
11
  - [対応フレームワーク](#対応フレームワーク)
13
12
  - [ブラウザサポート](#ブラウザサポート)
@@ -22,11 +21,13 @@ Web Serial API を RxJS ベースのリアクティブなラッパーで提供
22
21
 
23
22
  ## 機能
24
23
 
25
- - **RxJS ベースのリアクティブ API**: RxJS Observables を活用したリアクティブなシリアルポート通信
26
- - **TypeScript サポート**: 完全な TypeScript 型定義を含む
27
- - **ブラウザ検出**: ブラウザサポートの検出とエラーハンドリング機能を内蔵
28
- - **エラーハンドリング**: カスタムエラークラスとエラーコードによる包括的なエラーハンドリング
29
- - **フレームワーク非依存**: 任意の JavaScript/TypeScript フレームワークまたはバニラ JavaScript で使用可能
24
+ - **Session 指向のリアクティブ API**: 1 つの `SerialSession` が `state$` / `isConnected$` / `receive$` / `lines$` / `errors$` と `connect$` / `disconnect$` / `send$` を公開
25
+ - **UTF-8 テキストストリーム**: `receive$` は内部でストリーミング `TextDecoder` を用いてデコード済み。マルチバイト文字がチャンクにまたがっても正しく結合されます
26
+ - **順序保証された送信キュー**: 並行する `send$` 呼び出しも内部キューで FIFO 処理され、呼び出し順に書き込まれます
27
+ - **統一エラーチャネル**: すべての I/O エラーは `SerialError` に正規化され `errors$` に多重化されます
28
+ - **明示的なライフサイクル**: `state$` は `idle` / `connecting` / `connected` / `disconnecting` / `unsupported` / `error` を emit するので UI から直接駆動できます
29
+ - **TypeScript サポート**: 完全な TypeScript 型定義を同梱
30
+ - **フレームワーク非依存**: 任意の JavaScript/TypeScript フレームワークまたはバニラ JavaScript で利用可能
30
31
 
31
32
  ## 対応フレームワーク
32
33
 
@@ -45,7 +46,7 @@ Web Serial API は現在、Chromium ベースのブラウザでのみサポー
45
46
  - **Edge** 89+
46
47
  - **Opera** 75+
47
48
 
48
- このライブラリには、使用前に Web Serial API のサポートを確認するためのブラウザ検出ユーティリティが含まれています。
49
+ `connect$` を呼ぶ前の feature detection には `SerialSession.isBrowserSupported()` が使えます(同期的に `boolean` を返します)。
49
50
 
50
51
  ## インストール
51
52
 
@@ -69,23 +70,91 @@ pnpm add rxjs
69
70
 
70
71
  **最小要件バージョン**: RxJS ^7.8.0
71
72
 
73
+ ## SerialSession(v2)の全体像
74
+
75
+ `createSerialSession` が返す **SerialSession** だけを使います。公開 API は意図的に小さく、**標準の改行区切り**は組み込み `lines$`、独自区切りが必要なときだけ `receive$` 上に RxJS で組み立てます([高度な使用方法](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.ja.md))。接続真偽は `isConnected$` も利用できます。
76
+
77
+ | 公開面 | 役割 |
78
+ | --- | --- |
79
+ | `state$` | **接続ライフサイクル** — `idle` / `connecting` / `connected` / `disconnecting` / `error` / `unsupported`。購読時に現在値をリプレイ。分岐は文字列直書きではなく **`SerialSessionState`** との比較を推奨。 |
80
+ | `SerialSessionState` | **状態定数** — エクスポートされる const object(例: `SerialSessionState.Connected`, `SerialSessionState.Idle`)。`state$` が emit する値と同じ。 |
81
+ | `isConnected$` | **接続中かどうか** — `state$` が `SerialSessionState.Connected` のときだけ `true`、それ以外は `false`(`state$` から `distinctUntilChanged` 付きで派生)。 |
82
+ | `receive$` | **受信 UTF-8 テキスト**(デコード済みの**チャンク**列。行区切りではない。マルチバイト安全)。 |
83
+ | `lines$` | **行単位の受信** — 1 行完了ごとに emit。内部バッファで改行(`\n` / `\r\n` 等)を解釈。 |
84
+ | `errors$` | **すべての `SerialError`**(接続・読み取り・書き込み・クローズ)の主チャネル。 |
85
+ | `connect$()` | ポート選択 → オープン → 内部 read pump 開始。 |
86
+ | `disconnect$()` | ポートを閉じ、pump を停止。 |
87
+ | `send$(string \| Uint8Array)` | 送信を **FIFO** で直列化(並行 `send$` も呼び出し順)。 |
88
+ | `isBrowserSupported()` | `connect$` の前に使う、Web Serial 利用可否の同期的な `boolean`。 |
89
+
90
+ ### SerialSessionState(早見表)
91
+
92
+ `state$` が emit する文字列のユニオンです。コードでは **const オブジェクト**(例: `SerialSessionState.Connected` → `'connected'`)での比較を推奨します。有効な遷移・例外系の扱いの詳細は [API リファレンスの SerialSessionState](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/API_REFERENCE.ja.md#serialsessionstate) を参照してください。
93
+
94
+ | 定数 | 値 | 意味 |
95
+ | --- | --- | --- |
96
+ | `SerialSessionState.Idle` | `'idle'` | ポート未接続。Web Serial 利用可能な場合の初期値。 |
97
+ | `SerialSessionState.Connecting` | `'connecting'` | `connect$` 実行中。 |
98
+ | `SerialSessionState.Connected` | `'connected'` | ポートが開き、内部 read pump が動作中。 |
99
+ | `SerialSessionState.Disconnecting` | `'disconnecting'` | `disconnect$` 実行中。 |
100
+ | `SerialSessionState.Unsupported` | `'unsupported'` | セッション生成時点で Web Serial が利用できない。 |
101
+ | `SerialSessionState.Error` | `'error'` | 接続まわりの致命エラー。`disconnect$` か新しいセッションで復帰。 |
102
+
103
+ **`receive$` と `lines$`:** 改行区切りの定番利用では **`lines$`** を優先。**`receive$`** はチャンクの到着タイミングをそのまま扱う場合や、独自区切り・自前バッファが必要なとき向け([行単位のフレーミング](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.ja.md#行単位のフレーミング))。
104
+
105
+ **`isConnected$`(UI 用)** — 読み取り専用の `Observable<boolean>` です。`state$` を `SerialSessionState.Connected` と毎回比較しなくても接続有無の UI 分岐に使えます。独自ルールが必要な場合は、従来どおり `state$` から `map` で派生しても構いません。
106
+
107
+ **`lines$`(行区切り)** — 組み込みです。独自区切りが欲しい場合のみ `receive$` でフレーミングします([行単位のフレーミング](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.ja.md#行単位のフレーミング))。
108
+
109
+ ### 最小サンプル
110
+
111
+ ```typescript
112
+ import { createSerialSession, SerialSessionState } from '@gurezo/web-serial-rxjs';
113
+ import { filter } from 'rxjs';
114
+
115
+ const session = createSerialSession({ baudRate: 115200 });
116
+
117
+ if (!session.isBrowserSupported()) {
118
+ throw new Error('このブラウザでは Web Serial を利用できません');
119
+ }
120
+
121
+ session.lines$.subscribe(console.log);
122
+ session.errors$.subscribe(console.error);
123
+ session.state$
124
+ .pipe(filter((s) => s === SerialSessionState.Connected))
125
+ .subscribe(() => {
126
+ /* 例: ポートが開いてから有効化する UI */
127
+ });
128
+ session.connect$().subscribe();
129
+ session.send$('hello\r\n').subscribe();
130
+ ```
131
+
132
+ 実アプリでは `connect$` / `send$` の `subscribe` で `error` も扱ってください(`errors$` にも流れます)。手順の全体は [クイックスタート](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/QUICK_START.ja.md) を参照してください。
133
+
72
134
  ## ドキュメント
73
135
 
74
- - **[クイックスタート](docs/QUICK_START.ja.md)** - 基本的な例と使用方法で始める
75
- - **[API リファレンス](docs/API_REFERENCE.ja.md)** - 詳細な説明を含む完全な API ドキュメント
76
- - **[高度な使用方法](docs/ADVANCED_USAGE.ja.md)** - 高度なパターン、ストリーム処理、エラー回復
136
+ | ドキュメント | 用途 |
137
+ | --- | --- |
138
+ | **リポジトリ [README](https://github.com/gurezo/web-serial-rxjs/blob/main/README.ja.md)** | モノレポ全体の目次、サンプル索引、貢献の導線。 |
139
+ | **[クイックスタート](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/QUICK_START.ja.md)** | 最短でポートを開いて購読するところまで。 |
140
+ | **[高度な使用方法](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.ja.md)** | 行フレーミング、擬似リクエスト/レスポンス、リカバリ。 |
141
+ | **[API リファレンス](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/API_REFERENCE.ja.md)** | オプション、`SerialSessionState`、`SerialError` の詳細。 |
142
+ | **[v1 → v2 マイグレーション](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/MIGRATION_V2.ja.md)**([English](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/MIGRATION_V2.md)) | 削除された v1 API からの対応表。 |
143
+ | **[Phase 5(アーカイブ)](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/archive/MIGRATION_PHASE5.ja.md)** | 旧 v1 ドキュメントの参照用。 |
77
144
 
78
145
  ## サンプル
79
146
 
80
147
  以下の環境向けのサンプルを用意しています。
81
148
 
82
149
  - **[Angular](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-angular)** - Service を使用した Angular の例
83
- - **[React](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-react)** - カスタムフック(`useSerialClient`)を使用した React の例
150
+ - **[React](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-react)** - カスタムフック(`useSerialSession`)を使用した React の例
84
151
  - **[Svelte](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-svelte)** - Svelte Store を使用した Svelte の例
85
152
  - **[Vanilla JavaScript](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-vanilla-js)** - バニラ JavaScript での基本的な使用方法
86
153
  - **[Vanilla TypeScript](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-vanilla-ts)** - RxJS を使用した TypeScript の例
87
154
  - **[Vue](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-vue)** - Composition API を使用した Vue 3 の例
88
155
 
156
+ 各サンプルは **connect・受信(多くの例は `lines$` または `receive$` 派生の行区切り)・send・disconnect** の最小動作確認用です。応用は [高度な使用方法](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.ja.md) を参照してください。
157
+
89
158
  各例には、セットアップと使用方法の説明を含む README が含まれています。
90
159
 
91
160
  ## プロジェクトアイコンについて
package/README.md CHANGED
@@ -1,13 +1,12 @@
1
- # web-serial-rxjs
2
-
3
1
  <p align="center">
4
2
  <img src="https://raw.githubusercontent.com/gurezo/web-serial-rxjs/main/assets/icon/web-serial-rxjs-icon.png" alt="web-serial-rxjs project icon" width="512" />
5
3
  </p>
6
4
 
7
- A TypeScript library that provides a reactive RxJS-based wrapper for the Web Serial API, enabling easy serial port communication in web applications.
5
+ A TypeScript library that wraps the Web Serial API with a minimal, session-oriented RxJS surface. The v2 API exposes a single `SerialSession` so applications can drive their UI entirely from `state$` + `isConnected$` + `receive$` + `lines$` + `errors$`, without rebuilding state, read loops, or send queues themselves.
8
6
 
9
7
  ## Table of Contents
10
8
 
9
+ - [SerialSession (v2) at a glance](#serialsession-v2-at-a-glance)
11
10
  - [Features](#features)
12
11
  - [Framework Support](#framework-support)
13
12
  - [Browser Support](#browser-support)
@@ -23,11 +22,13 @@ A TypeScript library that provides a reactive RxJS-based wrapper for the Web Ser
23
22
 
24
23
  ## Features
25
24
 
26
- - **RxJS-based reactive API**: Leverage the power of RxJS Observables for reactive serial port communication
27
- - **TypeScript support**: Full TypeScript type definitions included
28
- - **Browser detection**: Built-in browser support detection and error handling
29
- - **Error handling**: Comprehensive error handling with custom error classes and error codes
30
- - **Framework agnostic**: Works with any JavaScript/TypeScript framework or vanilla JavaScript
25
+ - **Session-oriented reactive API**: a single `SerialSession` exposes `state$`, `isConnected$`, `receive$`, `lines$`, `errors$`, plus `connect$`, `disconnect$`, and `send$`
26
+ - **UTF-8 text stream**: `receive$` is already decoded with a streaming `TextDecoder`, so multi-byte characters split across chunks are joined correctly
27
+ - **Ordered send queue**: concurrent `send$` calls are serialized internally in call order, without the caller having to manage a writer
28
+ - **Unified error channel**: every I/O error is normalised into `SerialError` and multiplexed on `errors$`
29
+ - **Explicit lifecycle**: `state$` emits `idle` / `connecting` / `connected` / `disconnecting` / `unsupported` / `error` so UIs can drive directly from it
30
+ - **TypeScript support**: full TypeScript type definitions included
31
+ - **Framework agnostic**: works with any JavaScript/TypeScript framework or vanilla JavaScript
31
32
 
32
33
  ## Framework Support
33
34
 
@@ -46,7 +47,7 @@ The Web Serial API is currently only supported in Chromium-based browsers:
46
47
  - **Edge** 89+
47
48
  - **Opera** 75+
48
49
 
49
- The library includes built-in browser detection utilities to check for Web Serial API support before attempting to use it.
50
+ `SerialSession.isBrowserSupported()` returns a synchronous boolean for feature detection before calling `connect$`.
50
51
 
51
52
  ## Installation
52
53
 
@@ -70,23 +71,91 @@ pnpm add rxjs
70
71
 
71
72
  **Minimum required version**: RxJS ^7.8.0
72
73
 
74
+ ## SerialSession (v2) at a glance
75
+
76
+ `createSerialSession` returns a single **SerialSession**. All interaction goes through the fields below. The public API is intentionally small; when you need **custom** framing, compose plain RxJS on `receive$` (see [Advanced Usage](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.md)).
77
+
78
+ | Surface | Role |
79
+ | --- | --- |
80
+ | `state$` | **Connection lifecycle** — `idle` / `connecting` / `connected` / `disconnecting` / `error` / `unsupported`. Replays the current state on subscribe. Compare with **`SerialSessionState`** instead of string literals. |
81
+ | `SerialSessionState` | **State constants** — exported const object (e.g. `SerialSessionState.Connected`, `SerialSessionState.Idle`) with the same values `state$` emits. |
82
+ | `isConnected$` | **Connected flag** — `true` only when `state$` is `SerialSessionState.Connected`; `false` in every other state (derived from `state$` with `distinctUntilChanged`). |
83
+ | `receive$` | **Raw incoming UTF-8 text** as decoded string **chunks** (not line-delimited; multi-byte safe). |
84
+ | `lines$` | **Line-delimited UTF-8 text** — one string per complete line, using the built-in newline buffer (`\n` / `\r\n`). |
85
+ | `errors$` | **All `SerialError` instances** from connect / read / write / close (primary error channel). |
86
+ | `connect$()` | **Open** a user-selected port and start the internal read pump. |
87
+ | `disconnect$()` | **Close** the port and stop the pump. |
88
+ | `send$(string \| Uint8Array)` | **Enqueue** outgoing data; writes are **FIFO-ordered** when multiple `send$` run concurrently. |
89
+ | `isBrowserSupported()` | Synchronous `boolean` for Web Serial availability before `connect$`. |
90
+
91
+ ### SerialSessionState (quick reference)
92
+
93
+ `state$` uses the string union below. Prefer the **const object** (e.g. `SerialSessionState.Connected` → `'connected'`) in code. Full lifecycle diagram, transitions, and edge cases: [API Reference – SerialSessionState](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/API_REFERENCE.md#serialsessionstate).
94
+
95
+ | Constant | Value | Meaning |
96
+ | --- | --- | --- |
97
+ | `SerialSessionState.Idle` | `'idle'` | No open port; initial state when the browser supports Web Serial. |
98
+ | `SerialSessionState.Connecting` | `'connecting'` | `connect$` in progress. |
99
+ | `SerialSessionState.Connected` | `'connected'` | Port is open; internal read pump is running. |
100
+ | `SerialSessionState.Disconnecting` | `'disconnecting'` | `disconnect$` in progress. |
101
+ | `SerialSessionState.Unsupported` | `'unsupported'` | Web Serial was not available when the session was created. |
102
+ | `SerialSessionState.Error` | `'error'` | Fatal I/O or lifecycle failure; call `disconnect$` or build a new session. |
103
+
104
+ **`receive$` vs `lines$`:** prefer **`lines$`** for typical newline-framed text; use **`receive$`** when you need raw chunk timing, a custom delimiter, or a rolling buffer you control (recipes in [Advanced Usage](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.md#line-framing)).
105
+
106
+ **`isConnected$` (for simple UIs)** — a read-only `Observable<boolean>`. Use it for “port open?” toggles without comparing `state$` to `SerialSessionState.Connected` yourself. You can still derive your own boolean from `state$` with `map` if you need different rules.
107
+
108
+ **`lines$` (newline framing)** — built in; for non-standard delimiters, frame on `receive$` (recipes in [Advanced Usage](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.md#line-framing)).
109
+
110
+ ### Minimal example
111
+
112
+ ```typescript
113
+ import { createSerialSession, SerialSessionState } from '@gurezo/web-serial-rxjs';
114
+ import { filter } from 'rxjs';
115
+
116
+ const session = createSerialSession({ baudRate: 115200 });
117
+
118
+ if (!session.isBrowserSupported()) {
119
+ throw new Error('Web Serial is not available in this browser');
120
+ }
121
+
122
+ session.lines$.subscribe(console.log);
123
+ session.errors$.subscribe(console.error);
124
+ session.state$
125
+ .pipe(filter((s) => s === SerialSessionState.Connected))
126
+ .subscribe(() => {
127
+ /* e.g. enable UI that must wait until the port is open */
128
+ });
129
+ session.connect$().subscribe();
130
+ session.send$('hello\r\n').subscribe();
131
+ ```
132
+
133
+ In real apps, handle `connect$().subscribe({ next, error })` and `send$().subscribe({ error })` (errors are also on `errors$`). A fuller walkthrough is in [Quick Start](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/QUICK_START.md).
134
+
73
135
  ## Documentation
74
136
 
75
- - **[Quick Start](docs/QUICK_START.md)** - Get started with basic examples and usage patterns
76
- - **[API Reference](docs/API_REFERENCE.md)** - Complete API documentation with detailed descriptions
77
- - **[Advanced Usage](docs/ADVANCED_USAGE.md)** - Advanced patterns, stream processing, and error recovery
137
+ | Doc | Use it for |
138
+ | --- | --- |
139
+ | **Repository [README](https://github.com/gurezo/web-serial-rxjs/blob/main/README.md)** | Monorepo overview, examples index, and contribution links. |
140
+ | **[Quick Start](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/QUICK_START.md)** | Shortest path to a working open port and subscriptions. |
141
+ | **[Advanced Usage](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.md)** | Line framing, request/response-style flows, and recovery. |
142
+ | **[API Reference](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/API_REFERENCE.md)** | Options, `SerialSessionState`, and `SerialError` details. |
143
+ | **[v1 → v2 Migration Guide](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/MIGRATION_V2.md)** | Replacing the removed v1 `SerialClient` / `ShellClient` API. |
144
+ | **[Phase 5 archive (legacy v1 doc)](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/archive/MIGRATION_PHASE5.md)** | Historical v1 context only. |
78
145
 
79
146
  ## Examples
80
147
 
81
148
  Examples are available for the following environments:
82
149
 
83
150
  - **[Angular](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-angular)** - Angular example using a Service
84
- - **[React](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-react)** - React example with custom hook (`useSerialClient`)
151
+ - **[React](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-react)** - React example with custom hook (`useSerialSession`)
85
152
  - **[Svelte](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-svelte)** - Svelte example using Svelte Store
86
153
  - **[Vanilla JavaScript](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-vanilla-js)** - Basic usage with vanilla JavaScript
87
154
  - **[Vanilla TypeScript](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-vanilla-ts)** - TypeScript example with RxJS
88
155
  - **[Vue](https://github.com/gurezo/web-serial-rxjs/tree/main/apps/example-vue)** - Vue 3 example using Composition API
89
156
 
157
+ Each sample is a **minimal smoke test** for **connect**, **receive** (typically newline-delimited lines via `lines$` or a stream derived from `receive$`), **send**, and **disconnect**. See [Advanced Usage](https://github.com/gurezo/web-serial-rxjs/blob/main/packages/web-serial-rxjs/docs/ADVANCED_USAGE.md) for richer patterns.
158
+
90
159
  Each example includes a README with setup and usage instructions.
91
160
 
92
161
  ## Project Icon
@@ -119,6 +119,13 @@ export declare enum SerialErrorCode {
119
119
  * to inform the user that the operation was cancelled.
120
120
  */
121
121
  OPERATION_CANCELLED = "OPERATION_CANCELLED",
122
+ /**
123
+ * Operation timed out before completion.
124
+ *
125
+ * This error occurs when an operation waits for a condition (for example, prompt
126
+ * detection) and the timeout period elapses first.
127
+ */
128
+ OPERATION_TIMEOUT = "OPERATION_TIMEOUT",
122
129
  /**
123
130
  * Unknown error occurred.
124
131
  *
@@ -1 +1 @@
1
- {"version":3,"file":"serial-error-code.d.ts","sourceRoot":"","sources":["../../src/errors/serial-error-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,oBAAY,eAAe;IACzB;;;;;;;;OAQG;IACH,qBAAqB,0BAA0B;IAE/C;;;;;;;;OAQG;IACH,kBAAkB,uBAAuB;IAEzC;;;;;;;OAOG;IACH,gBAAgB,qBAAqB;IAErC;;;;;;;OAOG;IACH,iBAAiB,sBAAsB;IAEvC;;;;;;;OAOG;IACH,aAAa,kBAAkB;IAE/B;;;;;;;OAOG;IACH,WAAW,gBAAgB;IAE3B;;;;;;;OAOG;IACH,YAAY,iBAAiB;IAE7B;;;;;;;;OAQG;IACH,eAAe,oBAAoB;IAEnC;;;;;;;OAOG;IACH,sBAAsB,2BAA2B;IAEjD;;;;;;;;OAQG;IACH,mBAAmB,wBAAwB;IAE3C;;;;;;;OAOG;IACH,OAAO,YAAY;CACpB"}
1
+ {"version":3,"file":"serial-error-code.d.ts","sourceRoot":"","sources":["../../src/errors/serial-error-code.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,oBAAY,eAAe;IACzB;;;;;;;;OAQG;IACH,qBAAqB,0BAA0B;IAE/C;;;;;;;;OAQG;IACH,kBAAkB,uBAAuB;IAEzC;;;;;;;OAOG;IACH,gBAAgB,qBAAqB;IAErC;;;;;;;OAOG;IACH,iBAAiB,sBAAsB;IAEvC;;;;;;;OAOG;IACH,aAAa,kBAAkB;IAE/B;;;;;;;OAOG;IACH,WAAW,gBAAgB;IAE3B;;;;;;;OAOG;IACH,YAAY,iBAAiB;IAE7B;;;;;;;;OAQG;IACH,eAAe,oBAAoB;IAEnC;;;;;;;OAOG;IACH,sBAAsB,2BAA2B;IAEjD;;;;;;;;OAQG;IACH,mBAAmB,wBAAwB;IAE3C;;;;;OAKG;IACH,iBAAiB,sBAAsB;IAEvC;;;;;;;OAOG;IACH,OAAO,YAAY;CACpB"}
package/dist/index.d.ts CHANGED
@@ -3,52 +3,53 @@
3
3
  *
4
4
  * # web-serial-rxjs
5
5
  *
6
- * A TypeScript library that provides a reactive RxJS-based wrapper for the Web Serial API,
7
- * enabling easy serial port communication in web applications.
6
+ * A TypeScript library that wraps the Web Serial API with a minimal,
7
+ * RxJS-based session surface.
8
8
  *
9
- * ## Features
9
+ * ## Public API (v2)
10
10
  *
11
- * - **RxJS-based reactive API**: Leverage the power of RxJS Observables for reactive serial port communication
12
- * - **TypeScript support**: Full TypeScript type definitions included
13
- * - **Browser detection**: Built-in browser support detection and error handling
14
- * - **Error handling**: Comprehensive error handling with custom error classes and error codes
15
- * - **Framework agnostic**: Works with any JavaScript/TypeScript framework or vanilla JavaScript
11
+ * The v2 public API intentionally exposes a single, session-oriented surface
12
+ * so that apps (Angular, Vue, React, Svelte, vanilla JS/TS) can drive their
13
+ * UI entirely from `state$` + `isConnected$` + `receive$` + `lines$` + `errors$` without rebuilding any
14
+ * state, read loops, or write queues themselves.
15
+ *
16
+ * - {@link createSerialSession} - factory for a {@link SerialSession}
17
+ * - {@link SerialSession} - the runtime interface
18
+ * - {@link SerialSessionOptions} - connection options
19
+ * - {@link SerialSessionState} - `state$` payload values (const + type)
20
+ * - {@link SerialError} / {@link SerialErrorCode} - unified error surface
16
21
  *
17
22
  * ## Browser Support
18
23
  *
19
- * The Web Serial API is currently only supported in Chromium-based browsers:
24
+ * The Web Serial API is only available in Chromium-based browsers:
25
+ *
20
26
  * - Chrome 89+
21
27
  * - Edge 89+
22
28
  * - Opera 75+
23
29
  *
30
+ * Use {@link SerialSession.isBrowserSupported} for a synchronous feature
31
+ * check before calling {@link SerialSession.connect$}.
32
+ *
24
33
  * @example
25
34
  * ```typescript
26
- * import { createSerialClient, isBrowserSupported } from '@gurezo/web-serial-rxjs';
35
+ * import { createSerialSession } from '@gurezo/web-serial-rxjs';
27
36
  *
28
- * // Check browser support
29
- * if (!isBrowserSupported()) {
30
- * console.error('Web Serial API is not supported in this browser');
31
- * return;
32
- * }
37
+ * const session = createSerialSession({ baudRate: 115200 });
33
38
  *
34
- * // Create a serial client
35
- * const client = createSerialClient({ baudRate: 9600 });
39
+ * if (!session.isBrowserSupported()) {
40
+ * console.error('Web Serial API is not supported in this browser');
41
+ * } else {
42
+ * session.state$.subscribe((state) => console.log('state:', state));
43
+ * session.receive$.subscribe((chunk) => console.log('rx:', chunk));
44
+ * session.errors$.subscribe((error) => console.error('err:', error));
36
45
  *
37
- * // Connect to a serial port
38
- * client.connect().subscribe({
39
- * next: () => console.log('Connected!'),
40
- * error: (error) => console.error('Connection error:', error),
41
- * });
46
+ * session.connect$().subscribe();
47
+ * session.send$('hello\r\n').subscribe();
48
+ * }
42
49
  * ```
43
50
  */
44
- export { createSerialClient } from './client';
45
- export type { SerialClient } from './client';
51
+ export { createSerialSession, SerialSessionState } from './session';
52
+ export type { SerialSession, SerialSessionOptions } from './session';
46
53
  export { SerialError } from './errors/serial-error';
47
54
  export { SerialErrorCode } from './errors/serial-error-code';
48
- export type { SerialClientOptions } from './types/options';
49
- export { BrowserType, detectBrowserType, hasWebSerialSupport, isChromiumBased, } from './browser/browser-detection';
50
- export { checkBrowserSupport, isBrowserSupported, } from './browser/browser-support';
51
- export { observableToWritable, subscribeToWritable, } from './io/observable-to-writable';
52
- export { readableToObservable } from './io/readable-to-observable';
53
- export { buildRequestOptions } from './filters/build-request-options';
54
55
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0CG;AAGH,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAC;AAG9C,YAAY,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC;AAG7C,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC;AAG7D,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG3D,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,mBAAmB,EACnB,eAAe,GAChB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EACL,mBAAmB,EACnB,kBAAkB,GACnB,MAAM,2BAA2B,CAAC;AAGnC,OAAO,EACL,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AAGnE,OAAO,EAAE,mBAAmB,EAAE,MAAM,iCAAiC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,EAAE,mBAAmB,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AACpE,YAAY,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAC;AAErE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,4BAA4B,CAAC"}