claude-code-jsonl-parser 0.1.4-beta.3 → 0.1.4-beta.30

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.md CHANGED
@@ -1,22 +1,22 @@
1
1
  # claude-code-jsonl-parser
2
2
 
3
- Claude Code の JSONL 会話ログ (`~/.claude/projects/**/*.jsonl` など) を型安全にパースする、依存ゼロの TypeScript ライブラリ。
3
+ A zero-dependency TypeScript library that parses Claude Code JSONL conversation logs (such as `~/.claude/projects/**/*.jsonl`) in a type-safe way.
4
4
 
5
5
  ## ✨ Features
6
6
 
7
- - **依存ゼロ** — 実行時 dependencies なし
8
- - **例外を投げない** — 1 行ずつのパース結果を `known` / `unknown` / `error` の 3 値で判別
9
- - **ESM + CJS 両対応** — Node.js の ESM/CJS どちらからも利用可能
10
- - **診断可能な `unknown`** — 既知 type だが形状不一致の行は `typeHint`/`reason` 付きで表現され、データを失わない
11
- - **一括 API とストリーミング API** — ファイル全体を一括で読む API と、定数メモリで逐次処理する API の両方を提供
7
+ - **Zero dependencies**: no runtime dependencies
8
+ - **No exceptions on bad input**: each line is classified as `known` / `unknown` / `error`
9
+ - **Diagnosable `unknown`**: a line of a known type with a mismatched shape is represented with `typeHint` and `reason`, so no data is lost
10
+ - **Whole-file and streaming APIs**: read a whole file at once, or process it line by line in constant memory
11
+ - **ESM and CJS**: usable from both Node.js module systems
12
12
 
13
- ## 📦 インストール
13
+ ## 📦 Installation
14
14
 
15
15
  ```bash
16
16
  npm install claude-code-jsonl-parser
17
17
  ```
18
18
 
19
- ## 🚀 クイックスタート
19
+ ## 🚀 Quick start
20
20
 
21
21
  ```ts
22
22
  import { parseJsonlFile } from 'claude-code-jsonl-parser'
@@ -31,23 +31,22 @@ if (result.isOk) {
31
31
  }
32
32
  ```
33
33
 
34
- `parseJsonlFile` はファイル I/O エラー (存在しない、権限がない等) のみ `Err` を返す。
35
- JSON 構文エラーや未知の形状の行は例外にはならず、各行の `ParsedLine` 自体が
36
- `_kind: 'error'` / `_kind: 'unknown'` として表現される (後述)。
34
+ `parseJsonlFile` returns `Err` only for file I/O errors (the file does not exist, no permission, and so on).
35
+ A line with a JSON syntax error or an unknown shape does not cause an exception: the line itself is represented as a `ParsedLine` with `_kind: 'error'` or `_kind: 'unknown'` (see below).
37
36
 
38
37
  ## 📖 API
39
38
 
40
- ### 一括 API とストリーミング API
39
+ ### Whole-text, whole-file and streaming APIs
41
40
 
42
- | 関数 | 用途 |
41
+ | Function | Purpose |
43
42
  | --- | --- |
44
- | `parseJsonl(text)` | 文字列全体を一括パース (`Result<ParsedLine[], never>`) |
45
- | `parseJsonlLines(text)` | 文字列全体を行単位の同期イテレータでパース |
46
- | `parseJsonlFile(path)` | ファイルを一括読み込み・一括パース (`ResultAsync<ParsedLine[], FileReadError>`) |
47
- | `parseJsonlFileStream(path)` | ファイルを 1 行ずつ非同期イテレータでパース (定数メモリ) |
43
+ | `parseJsonl(text)` | Parses a whole string at once (`Result<ParsedLine[], never>`) |
44
+ | `parseJsonlLines(text)` | Parses a whole string with a synchronous line-by-line iterator |
45
+ | `parseJsonlFile(path)` | Reads and parses a whole file at once (`ResultAsync<ParsedLine[], FileReadError>`) |
46
+ | `parseJsonlFileStream(path)` | Parses a file line by line with an asynchronous iterator (constant memory); a read failure is thrown as a `FileReadError` during iteration |
48
47
 
49
- 数十 MB 以上の大きなログファイルを扱う場合は `parseJsonlFileStream` を使うと、
50
- 全行を配列に保持しないぶんメモリ使用量を抑えられる。
48
+ Blank lines are skipped and do not count towards line numbers.
49
+ For large log files (tens of MB or more), `parseJsonlFileStream` keeps memory usage down because it does not hold every line in an array.
51
50
 
52
51
  ```ts
53
52
  import { parseJsonlFileStream } from 'claude-code-jsonl-parser'
@@ -59,9 +58,9 @@ for await (const line of parseJsonlFileStream('/path/to/large-session.jsonl')) {
59
58
  }
60
59
  ```
61
60
 
62
- ### ParsedLine の 3 値判別
61
+ ### Discriminating a ParsedLine
63
62
 
64
- 行ごとのパース結果は `_kind` で判別する。
63
+ Discriminate the result of each line by `_kind`.
65
64
 
66
65
  ```ts
67
66
  import type { ParsedLine } from 'claude-code-jsonl-parser'
@@ -69,59 +68,61 @@ import type { ParsedLine } from 'claude-code-jsonl-parser'
69
68
  function handle(line: ParsedLine) {
70
69
  switch (line._kind) {
71
70
  case 'known': {
72
- // line.type で assistant / user / system / ... にさらに絞り込める
71
+ // line.type narrows further to assistant / user / system / ...
73
72
  break
74
73
  }
75
74
  case 'unknown': {
76
- // 未知 type、または既知 type だが形状不一致。
77
- // line.typeHint: 形状不一致なら元の type 値 (未知 type なら undefined)
78
- // line.reason: 形状不一致の場合、どのフィールドが原因かの診断メッセージ
75
+ // An unknown type, or a known type with a mismatched shape.
76
+ // line.raw: the parsed JSON value as is
77
+ // line.typeHint: the original type value for a shape mismatch (undefined for an unknown type)
78
+ // line.reason: for a shape mismatch, a diagnostic message naming the offending fields
79
79
  break
80
80
  }
81
81
  case 'error': {
82
- // JSON 構文エラー行。line.message に構文エラーメッセージ
82
+ // A line with a JSON syntax error. line.rawLine is the text and line.message the syntax error message
83
83
  break
84
84
  }
85
85
  }
86
86
  }
87
87
  ```
88
88
 
89
- `known` かつ既知 type だがガードの必須フィールドを満たさない行は、データを失わず
90
- `unknown` (`typeHint` に元の type、`reason` に不一致理由) として表現される。
91
- 例外は投げない。
89
+ A line of a known type that does not satisfy the guard's required fields is not dropped: it is represented as `unknown` (`typeHint` holds the original type and `reason` the cause), and no exception is thrown.
92
90
 
93
- ### content ブロックの絞り込み
91
+ ### Narrowing content blocks
94
92
 
95
- `assistant`/`user` の `message.content` 配列の要素 (`AssistantContentBlock` /
96
- `UserContentBlock`) も、既知ブロックと `UnknownContentBlock` の判別 union になっている。
97
- 先に `_kind` で `'unknown'` かどうかを判定してから `.type` で絞り込む。
93
+ The elements of `message.content` in `assistant` / `user` entries (`AssistantContentBlock` / `UserContentBlock`) are also discriminated unions of known blocks and `UnknownContentBlock`.
94
+ Check `_kind` for `'unknown'` first, then narrow by `.type`.
98
95
 
99
96
  ```ts
100
97
  import type { AssistantContentBlock } from 'claude-code-jsonl-parser'
101
98
 
102
99
  function describe(block: AssistantContentBlock): string {
103
- if (block._kind === 'unknown') return '(未知ブロック)'
100
+ if (block._kind === 'unknown') return '(unknown block)'
104
101
  if (block.type === 'text') return block.text
105
102
  if (block.type === 'thinking') return block.thinking
106
103
  return `tool_use: ${block.name}`
107
104
  }
108
105
  ```
109
106
 
110
- ### 公開されている型ガード (上級者向け)
107
+ ### Result
111
108
 
112
- `guards` / `guardByType` / `KNOWN_TYPES` / `normalizeAssistantContent` /
113
- `normalizeUserContent` は、独自のパースパイプラインを組みたい場合のために
114
- 公開されている。通常の利用では `parseJsonlFile` 系の API で十分。
109
+ `parseJsonl` and `parseJsonlFile` return a dependency-free `Result` / `ResultAsync`. Both expose `map`, `mapErr`, `andThen`, `match` and `unwrapOr`; `ok`, `err` and `ResultAsync` are exported.
110
+ A `Result` has `isOk` / `isErr` and either `value` or `error`; a `ResultAsync` can be awaited to obtain the `Result`.
111
+
112
+ ### Exported type guards (advanced)
113
+
114
+ `guards`, `guardByType`, `KNOWN_TYPES`, `normalizeAssistantContent` and `normalizeUserContent` are exported for building your own parsing pipeline.
115
+ For normal use, the `parseJsonlFile` family of APIs is enough.
115
116
 
116
117
  ```ts
117
118
  import { guardByType } from 'claude-code-jsonl-parser'
118
119
 
119
120
  const result = guardByType('assistant', someRawObject)
120
- // result === undefined → 'assistant' というガード自体が存在しない
121
- // result.ok === true → 形状一致
122
- // result.ok === false, result.reason → 形状不一致とその理由
121
+ // result === undefined -> there is no guard for 'assistant' (unknown type)
122
+ // result.ok === true -> the shape matches
123
+ // result.ok === false, result.reason -> the shape does not match, and why
123
124
  ```
124
125
 
125
- ## 📑 ライセンス
126
+ ## 📑 License
126
127
 
127
- このプロジェクトは [MIT License](./LICENSE) の下で公開されている。
128
+ This project is released under the [MIT License](./LICENSE).
package/dist/index.cjs CHANGED
@@ -2,7 +2,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  let node_fs = require("node:fs");
3
3
  let node_readline = require("node:readline");
4
4
  // src/result.ts
5
- /** `OkResult<T>` の実装。 */
5
+ /** Implementation of `OkResult<T>`. */
6
6
  var OkResultImpl = class OkResultImpl {
7
7
  value;
8
8
  isOk = true;
@@ -26,7 +26,7 @@ var OkResultImpl = class OkResultImpl {
26
26
  return this.value;
27
27
  }
28
28
  };
29
- /** `ErrResult<E>` の実装。 */
29
+ /** Implementation of `ErrResult<E>`. */
30
30
  var ErrResultImpl = class ErrResultImpl {
31
31
  error;
32
32
  isOk = false;
@@ -51,23 +51,23 @@ var ErrResultImpl = class ErrResultImpl {
51
51
  }
52
52
  };
53
53
  /**
54
- * 成功 `Result<T, never>` を生成する。
54
+ * Creates a success `Result<T, never>`.
55
55
  *
56
- * @param value - 成功値
56
+ * @param value - Success value
57
57
  */
58
58
  function ok(value) {
59
59
  return new OkResultImpl(value);
60
60
  }
61
61
  /**
62
- * 失敗 `Result<never, E>` を生成する。
62
+ * Creates a failure `Result<never, E>`.
63
63
  *
64
- * @param error - エラー値
64
+ * @param error - Error value
65
65
  */
66
66
  function err(error) {
67
67
  return new ErrResultImpl(error);
68
68
  }
69
69
  /**
70
- * `await` 可能で `map / mapErr / andThen` を連鎖できる `PromiseLike<Result<T, E>>`。
70
+ * A `PromiseLike<Result<T, E>>` that can be awaited and chained with `map` / `mapErr` / `andThen`.
71
71
  */
72
72
  var ResultAsync = class ResultAsync {
73
73
  _promise;
@@ -78,42 +78,42 @@ var ResultAsync = class ResultAsync {
78
78
  return this._promise.then(onfulfilled, onrejected);
79
79
  }
80
80
  /**
81
- * `Promise<T>` を `ResultAsync<T, E>` に包む。reject 時は `onError` で E に写像する。
81
+ * Wraps a `Promise<T>` in a `ResultAsync<T, E>`. A rejection is mapped to `E` with `onError`.
82
82
  *
83
- * @param promise - 対象 Promise
84
- * @param onError - エラー写像
83
+ * @param promise - Target promise
84
+ * @param onError - Error mapper
85
85
  */
86
86
  static fromPromise(promise, onError) {
87
87
  return new ResultAsync(promise.then((v) => ok(v), (error) => err(onError(error))));
88
88
  }
89
89
  /**
90
- * 解決済み `Result<T, E>` を `ResultAsync<T, E>` に包む。
90
+ * Wraps a resolved `Result<T, E>` in a `ResultAsync<T, E>`.
91
91
  *
92
- * @param result - 対象 Result
92
+ * @param result - Target result
93
93
  */
94
94
  static fromResult(result) {
95
95
  return new ResultAsync(Promise.resolve(result));
96
96
  }
97
97
  /**
98
- * 成功値を変換する。
98
+ * Transforms the success value.
99
99
  *
100
- * @param fn - 同期写像
100
+ * @param fn - Synchronous mapper
101
101
  */
102
102
  map(fn) {
103
103
  return new ResultAsync(this._promise.then((r) => r.map(fn)));
104
104
  }
105
105
  /**
106
- * エラー値を変換する。
106
+ * Transforms the error value.
107
107
  *
108
- * @param fn - 同期エラー写像
108
+ * @param fn - Synchronous error mapper
109
109
  */
110
110
  mapErr(fn) {
111
111
  return new ResultAsync(this._promise.then((r) => r.mapErr(fn)));
112
112
  }
113
113
  /**
114
- * 失敗しうる非同期処理を連鎖する。
114
+ * Chains a step that may fail.
115
115
  *
116
- * @param fn - `ResultAsync<U, F>` または `Result<U, F>` を返す写像
116
+ * @param fn - Mapper returning a `ResultAsync<U, F>` or `Result<U, F>`
117
117
  */
118
118
  andThen(fn) {
119
119
  return new ResultAsync(this._promise.then(async (r) => {
@@ -123,19 +123,19 @@ var ResultAsync = class ResultAsync {
123
123
  }));
124
124
  }
125
125
  /**
126
- * 成功 / 失敗でパターンマッチする。
126
+ * Pattern-matches on success / failure.
127
127
  *
128
- * @param onOk - 成功値ハンドラ
129
- * @param onErr - エラー値ハンドラ
128
+ * @param onOk - Success handler
129
+ * @param onErr - Error handler
130
130
  */
131
131
  async match(onOk, onErr) {
132
132
  const r = await this._promise;
133
133
  return r.isOk ? onOk(r.value) : onErr(r.error);
134
134
  }
135
135
  /**
136
- * 成功なら value、失敗なら fallback を返す。
136
+ * Returns the value on success, or `fallback` on failure.
137
137
  *
138
- * @param fallback - フォールバック値
138
+ * @param fallback - Fallback value
139
139
  */
140
140
  async unwrapOr(fallback) {
141
141
  const r = await this._promise;
@@ -143,28 +143,25 @@ var ResultAsync = class ResultAsync {
143
143
  }
144
144
  };
145
145
  // src/generated/guards.ts
146
- /** 配列でも null でもないプレーンオブジェクトかどうかを判定する。 */
146
+ /** Whether the value is a plain object (neither an array nor null). */
147
147
  function isObject(v) {
148
148
  return typeof v === "object" && v !== null && !Array.isArray(v);
149
149
  }
150
- /** `string` かどうかを判定する。 */
151
150
  function isString(v) {
152
151
  return typeof v === "string";
153
152
  }
154
- /** `number` かどうかを判定する。 */
155
153
  function isNumber(v) {
156
154
  return typeof v === "number";
157
155
  }
158
- /** `boolean` かどうかを判定する。 */
159
156
  function isBoolean(v) {
160
157
  return typeof v === "boolean";
161
158
  }
162
- /** `[フィールド名, 検査結果]` の配列から、不一致だったフィールド名をまとめた診断メッセージを作る。 */
159
+ /** Builds a diagnostic message listing the failing field names from `[field name, check result]` pairs. Returns undefined when all pass. */
163
160
  function fieldCheck(fields) {
164
161
  const failing = fields.filter(([, ok]) => !ok).map(([name]) => name);
165
162
  return failing.length > 0 ? `missing/invalid field(s): ${failing.join(", ")}` : void 0;
166
163
  }
167
- /** フルメタデータ系の共通必須フィールドを検査し、不一致理由を返す (一致なら undefined)。 */
164
+ /** Checks the required fields common to the full-metadata entries and returns the reason on mismatch (undefined on match). */
168
165
  function entryBaseReason(o) {
169
166
  return fieldCheck([
170
167
  ["cwd", isString(o.cwd)],
@@ -200,7 +197,12 @@ function isAssistant(v) {
200
197
  const reason = fieldCheck([
201
198
  ["message.role", isString(v.message.role)],
202
199
  ["message.id", isString(v.message.id)],
203
- ["message.model", isString(v.message.model)]
200
+ ["message.model", isString(v.message.model)],
201
+ ["message.type", isString(v.message.type)],
202
+ ["message.stop_reason", v.message.stop_reason === null || isString(v.message.stop_reason)],
203
+ ["message.stop_sequence", v.message.stop_sequence === null || isString(v.message.stop_sequence)],
204
+ ["message.stop_details", "stop_details" in v.message],
205
+ ["message.usage", "usage" in v.message]
204
206
  ]);
205
207
  return reason === void 0 ? { ok: true } : {
206
208
  ok: false,
@@ -523,7 +525,7 @@ function isResult(v) {
523
525
  reason
524
526
  };
525
527
  }
526
- /** type 文字列 → ガード関数のマップ。 */
528
+ /** Map from type string to guard function. */
527
529
  const guards = {
528
530
  assistant: isAssistant,
529
531
  user: isUser,
@@ -545,17 +547,18 @@ const guards = {
545
547
  started: isStarted,
546
548
  result: isResult
547
549
  };
548
- /** 既知 type 名の配列。 */
550
+ /** Names of the known types. */
549
551
  const KNOWN_TYPES = Object.keys(guards);
550
552
  /**
551
- * 指定 type のガードを適用する。ガードが存在しない type なら undefined。
552
- * 一致すれば `{ ok: true }`、不一致なら `{ ok: false, reason }` (reason に
553
- * 診断メッセージ、どのフィールドが原因で shape 不一致になったかを含む)。
553
+ * Applies the guard of the given type, or returns undefined if no guard exists for it.
554
+ * Returns `{ ok: true }` on a match and `{ ok: false, reason }` on a mismatch, where
555
+ * `reason` names the fields that caused it.
554
556
  *
555
- * @param type - 判別子
556
- * @param v - 検査対象の生 JSON
557
+ * @param type - Discriminator
558
+ * @param v - Raw JSON to check
557
559
  */
558
560
  function guardByType(type, v) {
561
+ if (!Object.hasOwn(guards, type)) return void 0;
559
562
  const g = guards[type];
560
563
  if (g === void 0) return void 0;
561
564
  return g(v);
@@ -576,12 +579,12 @@ function isToolUseBlock(v) {
576
579
  return v.type === "tool_use" && isString(v.id) && isString(v.name) && "input" in v;
577
580
  }
578
581
  function isImageBlock(v) {
579
- return v.type === "image" && isObject(v.source) && isString(v.source.media_type) && isString(v.source.data);
582
+ return v.type === "image" && isObject(v.source) && isString(v.source.type) && isString(v.source.media_type) && isString(v.source.data);
580
583
  }
581
584
  function isToolReferenceBlock(v) {
582
585
  return v.type === "tool_reference" && isString(v.tool_name);
583
586
  }
584
- /** tool_result の inner content 配列を正規化する。 */
587
+ /** Normalizes the inner content of a tool_result. */
585
588
  function normalizeToolResultContent(content) {
586
589
  if (isString(content)) return content;
587
590
  if (!Array.isArray(content)) return [unknownBlock(content)];
@@ -594,7 +597,7 @@ function normalizeToolResultContent(content) {
594
597
  return unknownBlock(el);
595
598
  });
596
599
  }
597
- /** tool_result ブロック全体を検査・正規化する。 */
600
+ /** Checks and normalizes a whole tool_result block. */
598
601
  function normalizeToolResultBlock(v) {
599
602
  if (v.type !== "tool_result" || !isString(v.tool_use_id)) return unknownBlock(v);
600
603
  const block = {
@@ -607,10 +610,11 @@ function normalizeToolResultBlock(v) {
607
610
  return block;
608
611
  }
609
612
  /**
610
- * assistant の message.content 配列を正規化する。
611
- * 既知ブロックはそのまま、未知は UnknownContentBlock に降格する。
613
+ * Normalizes the message.content of an assistant entry.
614
+ * Known blocks are kept as is; unknown ones are demoted to `UnknownContentBlock`.
615
+ * A non-array value becomes a single `UnknownContentBlock`.
612
616
  *
613
- * @param content - 生の content 配列
617
+ * @param content - Raw content
614
618
  */
615
619
  function normalizeAssistantContent(content) {
616
620
  if (!Array.isArray(content)) return [unknownBlock(content)];
@@ -624,9 +628,10 @@ function normalizeAssistantContent(content) {
624
628
  });
625
629
  }
626
630
  /**
627
- * user の message.content を正規化する。string ならそのまま、配列なら要素ごとに正規化。
631
+ * Normalizes the message.content of a user entry. A string is returned as is and an array is normalized per element.
632
+ * Any other value becomes a single `UnknownContentBlock`.
628
633
  *
629
- * @param content - 生の content (string または配列)
634
+ * @param content - Raw content (string or array)
630
635
  */
631
636
  function normalizeUserContent(content) {
632
637
  if (isString(content)) return content;
@@ -643,15 +648,15 @@ function normalizeUserContent(content) {
643
648
  }
644
649
  // src/parse-line.ts
645
650
  /**
646
- * JSONL 1 行を ParsedLine に変換する。
651
+ * Converts one JSONL line into a `ParsedLine`.
647
652
  *
648
- * - JSON 構文エラー: `LineParseError`
649
- * - 既知 type かつ shape 一致: `KnownEntry` (_kind='known' 付与、content 正規化)
650
- * - 既知 type だが shape 不一致: `UnknownEntry` (typeHint に type 値)
651
- * - 未知 type / type 無し: `UnknownEntry` (typeHint 無し)
653
+ * - JSON syntax error: `LineParseError`
654
+ * - Known type with a matching shape: `KnownEntry` (`_kind: 'known'` is added and content is normalized)
655
+ * - Known type with a mismatched shape: `UnknownEntry` (`typeHint` holds the type)
656
+ * - Unknown type or no type: `UnknownEntry` (no `typeHint`)
652
657
  *
653
- * @param rawLine - 1 行分の文字列 (改行を含まない)
654
- * @param lineNumber - 1 始まりの行番号
658
+ * @param rawLine - One line of text (without the line break)
659
+ * @param lineNumber - 1-based line number
655
660
  */
656
661
  function parseLine(rawLine, lineNumber) {
657
662
  let parsed;
@@ -701,10 +706,10 @@ function parseLine(rawLine, lineNumber) {
701
706
  }
702
707
  // src/errors.ts
703
708
  /**
704
- * FileReadError を生成する。
709
+ * Creates a `FileReadError`.
705
710
  *
706
- * @param path - 対象パス
707
- * @param error - 捕捉した例外
711
+ * @param path - Target path
712
+ * @param error - Caught exception
708
713
  */
709
714
  function fileReadError(path, error) {
710
715
  const rawCode = typeof error === "object" && error !== null && "code" in error ? error.code : void 0;
@@ -717,13 +722,12 @@ function fileReadError(path, error) {
717
722
  }
718
723
  // src/parse.ts
719
724
  /**
720
- * JSONL 文字列を行単位で逐次パースする同期イテレータ。
721
- * `text.split('\n')` で全行配列を作らず、`indexOf` で 1 行ずつ切り出すため、
722
- * 追加メモリは 1 行分にとどまる (全行配列分の追加確保が発生しない)。
725
+ * Synchronous iterator that parses a JSONL string line by line.
726
+ * It slices one line at a time with `indexOf` instead of building a full line array with `text.split('\n')`, so the extra memory stays at one line.
723
727
  *
724
- * 空行 (トリム後に空) はスキップし、行番号カウントには含めない。
728
+ * Blank lines (empty after trimming) are skipped and not counted in line numbers.
725
729
  *
726
- * @param text - JSONL テキスト全体
730
+ * @param text - Whole JSONL text
727
731
  */
728
732
  function* parseJsonlLines(text) {
729
733
  let lineNumber = 0;
@@ -742,25 +746,25 @@ function* parseJsonlLines(text) {
742
746
  }
743
747
  }
744
748
  /**
745
- * JSONL 文字列全体を一括パースして配列で返す。
746
- * 行単位のエラーは配列要素として表現されるため、この関数は Err を返さない。
749
+ * Parses a whole JSONL string and returns the lines as an array.
750
+ * Per-line errors are represented as array elements, so this function never returns `Err`.
747
751
  *
748
- * @param text - JSONL テキスト全体
752
+ * @param text - Whole JSONL text
749
753
  */
750
754
  function parseJsonl(text) {
751
755
  return ok([...parseJsonlLines(text)]);
752
756
  }
753
757
  /**
754
- * ファイルを行単位で逐次読み込み・パースする非同期イテレータ (定数メモリ)。
755
- * I/O エラーは反復時に FileReadError を throw する。
758
+ * Asynchronous iterator that reads and parses a file line by line (constant memory).
759
+ * An I/O error is thrown as a `FileReadError` during iteration.
756
760
  *
757
- * @param path - JSONL ファイルパス
761
+ * @param path - JSONL file path
758
762
  */
759
763
  async function* parseJsonlFileStream(path) {
760
764
  const stream = (0, node_fs.createReadStream)(path, { encoding: "utf8" });
761
765
  const rl = (0, node_readline.createInterface)({
762
766
  input: stream,
763
- crlfDelay: Infinity
767
+ crlfDelay: 1e400
764
768
  });
765
769
  let lineNumber = 0;
766
770
  try {
@@ -777,9 +781,9 @@ async function* parseJsonlFileStream(path) {
777
781
  }
778
782
  }
779
783
  /**
780
- * ファイル全体を読み込み一括パースする。I/O エラーのみ Err になる。
784
+ * Reads a whole file and parses it at once. Only I/O errors become `Err`.
781
785
  *
782
- * @param path - JSONL ファイルパス
786
+ * @param path - JSONL file path
783
787
  */
784
788
  function parseJsonlFile(path) {
785
789
  return ResultAsync.fromPromise((async () => {