33 lines
970 B
TypeScript
33 lines
970 B
TypeScript
|
|
import type { Document, DocumentRepresentation } from "@citation-evidence/engine/shared";
|
||
|
|
|
||
|
|
import { reconcileFingerprint, type ReconcileResult } from "./reconcile";
|
||
|
|
|
||
|
|
export interface IngestOutcome {
|
||
|
|
readonly document: Document;
|
||
|
|
readonly representation: DocumentRepresentation;
|
||
|
|
}
|
||
|
|
|
||
|
|
export type IngestFn<TOptions = void> = (
|
||
|
|
bytes: Uint8Array,
|
||
|
|
options?: TOptions,
|
||
|
|
) => Promise<IngestOutcome>;
|
||
|
|
|
||
|
|
export interface ReIngestInput<TOptions = void> {
|
||
|
|
readonly previous: Document;
|
||
|
|
readonly bytes: Uint8Array;
|
||
|
|
readonly options?: TOptions;
|
||
|
|
}
|
||
|
|
|
||
|
|
export interface ReIngestResult {
|
||
|
|
readonly outcome: IngestOutcome;
|
||
|
|
readonly reconcile: ReconcileResult;
|
||
|
|
}
|
||
|
|
|
||
|
|
export async function reIngestAndCompare<TOptions>(
|
||
|
|
input: ReIngestInput<TOptions>,
|
||
|
|
ingest: IngestFn<TOptions>,
|
||
|
|
): Promise<ReIngestResult> {
|
||
|
|
const outcome = await ingest(input.bytes, input.options);
|
||
|
|
const reconcile = reconcileFingerprint(input.previous, outcome.document);
|
||
|
|
return { outcome, reconcile };
|
||
|
|
}
|