refactor(reference): share graph index projections
This commit is contained in:
@@ -2,6 +2,8 @@ import { compareUnicodeCodePoints } from "../domain/unicodeCodePointOrder.js";
|
|||||||
import { isSecretLikePath } from "../domain/referenceSourceClassification.js";
|
import { isSecretLikePath } from "../domain/referenceSourceClassification.js";
|
||||||
import {
|
import {
|
||||||
createHistoricalSourceGraph,
|
createHistoricalSourceGraph,
|
||||||
|
historicalSourceLanguages,
|
||||||
|
historicalSourceManifests,
|
||||||
historicalSourceParseFailureKey,
|
historicalSourceParseFailureKey,
|
||||||
type HistoricalSourceGraph,
|
type HistoricalSourceGraph,
|
||||||
type HistoricalSourceGraphInput,
|
type HistoricalSourceGraphInput,
|
||||||
@@ -83,30 +85,6 @@ const buildProvenance = (
|
|||||||
caller: options.caller,
|
caller: options.caller,
|
||||||
});
|
});
|
||||||
|
|
||||||
const deriveLanguages = (
|
|
||||||
entries: HistoricalSourceGraphInput["entries"],
|
|
||||||
): string[] =>
|
|
||||||
[
|
|
||||||
...new Set(
|
|
||||||
entries.flatMap((entry) =>
|
|
||||||
entry.kind === "file" && entry.language !== null
|
|
||||||
? [entry.language]
|
|
||||||
: [],
|
|
||||||
),
|
|
||||||
),
|
|
||||||
].sort(compareUnicodeCodePoints);
|
|
||||||
|
|
||||||
const deriveManifests = (
|
|
||||||
entries: HistoricalSourceGraphInput["entries"],
|
|
||||||
): string[] =>
|
|
||||||
entries
|
|
||||||
.flatMap((entry) =>
|
|
||||||
entry.kind === "file" && entry.classifications.includes("manifest")
|
|
||||||
? [entry.path]
|
|
||||||
: [],
|
|
||||||
)
|
|
||||||
.sort(compareUnicodeCodePoints);
|
|
||||||
|
|
||||||
const deriveInventoryState = (
|
const deriveInventoryState = (
|
||||||
input: Pick<
|
input: Pick<
|
||||||
HistoricalSourceGraphInput,
|
HistoricalSourceGraphInput,
|
||||||
@@ -229,8 +207,8 @@ export const importReferenceSource = async (
|
|||||||
),
|
),
|
||||||
parse_failures: uniqueFailures,
|
parse_failures: uniqueFailures,
|
||||||
exclusions: sortedExclusions,
|
exclusions: sortedExclusions,
|
||||||
languages: deriveLanguages(sortedEntries),
|
languages: historicalSourceLanguages(sortedEntries),
|
||||||
manifests: deriveManifests(sortedEntries),
|
manifests: historicalSourceManifests(sortedEntries),
|
||||||
vcs,
|
vcs,
|
||||||
provenance: buildProvenance(options),
|
provenance: buildProvenance(options),
|
||||||
limitations: sortedLimitations,
|
limitations: sortedLimitations,
|
||||||
|
|||||||
@@ -255,7 +255,8 @@ const checkSortedUnique = (
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const expectedLanguages = (
|
/** Derive the canonical language index from inventoried source files. */
|
||||||
|
export const historicalSourceLanguages = (
|
||||||
entries: readonly z.infer<typeof sourceEntrySchema>[],
|
entries: readonly z.infer<typeof sourceEntrySchema>[],
|
||||||
): string[] =>
|
): string[] =>
|
||||||
[
|
[
|
||||||
@@ -268,7 +269,8 @@ const expectedLanguages = (
|
|||||||
),
|
),
|
||||||
].sort(compareUnicodeCodePoints);
|
].sort(compareUnicodeCodePoints);
|
||||||
|
|
||||||
const expectedManifests = (
|
/** Derive the canonical manifest path index from inventoried source files. */
|
||||||
|
export const historicalSourceManifests = (
|
||||||
entries: readonly z.infer<typeof sourceEntrySchema>[],
|
entries: readonly z.infer<typeof sourceEntrySchema>[],
|
||||||
): string[] =>
|
): string[] =>
|
||||||
entries
|
entries
|
||||||
@@ -408,7 +410,7 @@ function checkGraphInvariants(
|
|||||||
|
|
||||||
if (
|
if (
|
||||||
canonicalJson(graph.languages) !==
|
canonicalJson(graph.languages) !==
|
||||||
canonicalJson(expectedLanguages(graph.entries))
|
canonicalJson(historicalSourceLanguages(graph.entries))
|
||||||
)
|
)
|
||||||
context.addIssue({
|
context.addIssue({
|
||||||
code: "custom",
|
code: "custom",
|
||||||
@@ -417,7 +419,7 @@ function checkGraphInvariants(
|
|||||||
});
|
});
|
||||||
if (
|
if (
|
||||||
canonicalJson(graph.manifests) !==
|
canonicalJson(graph.manifests) !==
|
||||||
canonicalJson(expectedManifests(graph.entries))
|
canonicalJson(historicalSourceManifests(graph.entries))
|
||||||
)
|
)
|
||||||
context.addIssue({
|
context.addIssue({
|
||||||
code: "custom",
|
code: "custom",
|
||||||
|
|||||||
Reference in New Issue
Block a user