/** * Bulk Aggregation — bulk DL 結果から 4 パターン集計を計算するヘルパ。 * * 集計対象の 4 パターン: * - newDocs: 索引にあるが DB になかった(新規追加) * - updatedDocs: 既存 doc_id で content_hash が変化した(既存更新) * - orphanedDocs: DB にあるが索引から消えた(既存削除、DELETE せず保持) * - movedDocs: orphaned と new で同タイトルが存在するペア(既存移動の推定) * * 設計詳細: docs/RESILIENCE.md §5.2 */ import { type BaselineDocType, type BulkRunRecord } from './health-store.js'; import { type HealthEvaluation } from './health-thresholds.js'; /** * 1 件の document / clause の identity 情報。 * * before / after の snapshot を取って差分を出すための最小限の情報。 */ export interface DocSnapshot { /** doc_type 内の一意 ID(例: 'shohi/02/19' / '6101' / '1-4-13の2') */ doc_id: string; /** content_hash(SHA-1)。比較で UPDATE を検知 */ content_hash: string | null; /** タイトル文字列。movedDocs 推定で照合 */ title: string; } /** * 索引と DB を突き合わせて出した orphaned / moved の件数(Issue #30)。 * * `document` テーブルの 5 種別は索引から消えた行を DELETE しないため、bulk download の * 前後で DB を比べても orphaned は必ず 0 になる。索引側と突き合わせた件数をここから渡す。 */ export interface OrphanCounts { orphanedDocs: number; movedDocs: number; } /** * 4 パターン集計の入力。 */ export interface AggregationInput { /** bulk DL 開始前の DB スナップショット(doc_id → snapshot) */ before: Map; /** bulk DL 完了後の DB スナップショット(doc_id → snapshot) */ after: Map; /** 索引から得た総件数 */ totalEntries: number; /** fetch / parse 失敗件数 */ documentsFailed: number; /** bulk DL 全体の所要 ms */ durationMs: number; /** ISO 8601 timestamp(省略時は現在時刻) */ ranAt?: string; /** * 索引と突き合わせて出した orphaned / moved の件数(Issue #30)。 * * 渡すと `orphanedDocs` / `movedDocs` はこの値を使う。渡さなければ before / after の * 差から数える(clause テーブルはこちら。節ごとに DELETE してから入れ直すため、 * 前後の差で消えた条が分かる)。 */ orphanCounts?: OrphanCounts; } /** * 4 パターン集計を計算して BulkRunRecord を返す。 * * - newDocs: after にあって before にない doc_id * - updatedDocs: 両方にあるが content_hash が違う doc_id * - orphanedDocs: before にあって after にない doc_id(=DB に残るが索引から消えた) * - movedDocs: orphaned + new のうちタイトル一致するペアの推定件数 * * **注意**: orphaned は DB から DELETE せず、`document.orphaned_at` に印を付けて残す設計 * (過去の課税期間の判断では依然として意味を持つため。Issue #30)。印を付けるのは * `markOrphanedDocuments`(`index-status.ts`)で、その件数を `orphanCounts` で受け取る。 * * `document` テーブルの 5 種別は行を消さないので、bulk download の前後で DB を比べても * orphaned は必ず 0 になる。索引側と突き合わせた件数を使うのはこのため。`clause` テーブル * (基本通達)は節ごとに DELETE してから入れ直すので、前後の差で消えた条が分かる。 */ export declare function computeBulkAggregation(input: AggregationInput): BulkRunRecord; /** * BulkRunRecord を baseline ファイルに永続化し、threshold 評価を行う。 * * baseline 評価の警告は logger.warn で出すが、bulk DL 自体は成功扱いのまま * リターンする(呼び出し側で exit code を制御したい場合は warn フィールドを参照)。 * * @returns 評価結果(warn フラグ + 警告理由) */ export declare function recordBulkRun(doc_type: BaselineDocType, record: BulkRunRecord, baselinePath?: string): HealthEvaluation; /** * Map の差集合(A - B)を返す utility。 * * テスト容易性のため export。 */ export declare function diffKeys(a: Map, b: Map): string[]; //# sourceMappingURL=bulk-aggregation.d.ts.map