mirror of
https://github.com/morluto/rea.git
synced 2026-11-03 21:36:13 +00:00
fix(reference): preserve distinct parse failures
This commit is contained in:
commit
e02cb2f877
4 files changed
+78
-14
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { isSecretLikePath } from "../domain/referenceSourceClassification.js";
|
||||
import {
|
||||
createHistoricalSourceGraph,
|
||||
historicalSourceParseFailureKey,
|
||||
type HistoricalSourceGraph,
|
||||
type HistoricalSourceGraphInput,
|
||||
} from "../domain/referenceSourceGraph.js";
|
||||
@@ -66,6 +67,27 @@ const deduplicateRelationships = (
|
||||
return result;
|
||||
};
|
||||
|
||||
/** Sort parse failures deterministically while retaining distinct reasons. */
|
||||
export const normalizeHistoricalSourceParseFailures = (
|
||||
failures: HistoricalSourceGraphInput["parse_failures"],
|
||||
): HistoricalSourceGraphInput["parse_failures"] =>
|
||||
[...failures]
|
||||
.sort((left, right) =>
|
||||
byCodePoint(
|
||||
historicalSourceParseFailureKey(left),
|
||||
historicalSourceParseFailureKey(right),
|
||||
),
|
||||
)
|
||||
.filter((value, index, array) => {
|
||||
if (index === 0) return true;
|
||||
const previous = array[index - 1];
|
||||
return (
|
||||
previous === undefined ||
|
||||
historicalSourceParseFailureKey(value) !==
|
||||
historicalSourceParseFailureKey(previous)
|
||||
);
|
||||
});
|
||||
|
||||
const buildProvenance = (
|
||||
options: ReferenceSourceImportOptions,
|
||||
): HistoricalSourceGraphInput["provenance"] => ({
|
||||
@@ -204,18 +226,7 @@ export const importReferenceSource = async (
|
||||
if (isAborted(options.signal)) return err(cancelled());
|
||||
|
||||
const uniqueRelationships = deduplicateRelationships(relationships);
|
||||
const uniqueFailures = [...parseFailures]
|
||||
.sort((left, right) => {
|
||||
const byPath = byCodePoint(left.path, right.path);
|
||||
if (byPath !== 0) return byPath;
|
||||
return byCodePoint(left.parser, right.parser);
|
||||
})
|
||||
.filter((value, index, array) => {
|
||||
if (index === 0) return true;
|
||||
const previous = array[index - 1];
|
||||
if (previous === undefined) return true;
|
||||
return value.path !== previous.path || value.parser !== previous.parser;
|
||||
});
|
||||
const uniqueFailures = normalizeHistoricalSourceParseFailures(parseFailures);
|
||||
|
||||
const sortedEntries = [...entries].sort((left, right) =>
|
||||
byCodePoint(left.path, right.path),
|
||||
|
||||
Reference in new issue
Block a user