refactor: use canonical implementations and types directly

Remove forwarding wrappers and shadow aliases, migrate callers and verification scripts to their owners, and share one exhaustive semantic resource-bound projection.
This commit is contained in:
morluto
2026-10-09 23:35:19 +08:00
parent 3283a45d09
commit 765e809e36
119 changed files with 577 additions and 629 deletions
@@ -1,5 +1,5 @@
import { compareCodePoints } from "../../domain/canonicalOrdering.js";
import { canonicalDigest } from "../../domain/comparisonSemantics.js";
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
import { digestCanonicalValue } from "../../domain/canonicalDigest.js";
import {
artifactEdgeId,
artifactIdForContent,
@@ -52,7 +52,7 @@ export const createOccurrence = (
path: string,
parent: string | null,
): MutableOccurrence => ({
occurrence_id: `occ_${canonicalDigest({ path, kind: entry.kind }, "Artifact")}`,
occurrence_id: `occ_${digestCanonicalValue({ path, kind: entry.kind }, "Artifact")}`,
artifact_id: null,
parent_occurrence_id: parent,
logical_path: path,
@@ -80,8 +80,6 @@ export const createOccurrence = (
});
/** Compare exact child names independently of host locale and traversal order. */
export const compareDirectoryChildNames = compareCodePoints;
export const materializeDirectoryNodes = (
occurrences: MutableOccurrence[],
nodes: Map<string, ArtifactNode>,
@@ -107,9 +105,9 @@ export const materializeDirectoryNodes = (
artifact_id,
entry_kind,
}))
.sort((left, right) => compareDirectoryChildNames(left.name, right.name));
.sort((left, right) => compareUnicodeCodePoints(left.name, right.name));
const node = createArtifactNode({
sha256: canonicalDigest({ kind: "directory", children }, "Artifact"),
sha256: digestCanonicalValue({ kind: "directory", children }, "Artifact"),
size: 0,
format: "directory",
contentState: "virtual",
@@ -131,7 +129,7 @@ export const createRootNode = (input: {
createArtifactNode({
sha256:
input.digest?.sha256 ??
canonicalDigest(
digestCanonicalValue(
{
kind: "directory-root",
children: input.occurrences
@@ -140,7 +138,7 @@ export const createRootNode = (input: {
artifact_id,
}))
.sort((left, right) =>
compareDirectoryChildNames(left.logical_path, right.logical_path),
compareUnicodeCodePoints(left.logical_path, right.logical_path),
),
},
"Artifact",
+6 -4
View File
@@ -1,5 +1,5 @@
import type { ArtifactInventorySnapshot } from "../../domain/artifactInventorySnapshot.js";
import { compareCodePoints } from "../../domain/canonicalOrdering.js";
import { compareUnicodeCodePoints } from "../../domain/unicodeCodePointOrder.js";
import { createReadStream } from "node:fs";
import { lstat } from "node:fs/promises";
@@ -253,18 +253,20 @@ const verifyRootDigest = async (
const sortNodes = (nodes: ArtifactNode[]): ArtifactNode[] =>
nodes.sort((left, right) =>
compareCodePoints(left.artifact_id, right.artifact_id),
compareUnicodeCodePoints(left.artifact_id, right.artifact_id),
);
const sortOccurrences = (
occurrences: MutableOccurrence[],
): MutableOccurrence[] =>
occurrences.sort((left, right) =>
compareCodePoints(left.logical_path, right.logical_path),
compareUnicodeCodePoints(left.logical_path, right.logical_path),
);
const sortEdges = <T extends { edge_id: string }>(edges: T[]): T[] =>
edges.sort((left, right) => compareCodePoints(left.edge_id, right.edge_id));
edges.sort((left, right) =>
compareUnicodeCodePoints(left.edge_id, right.edge_id),
);
const buildManifest = ({
rootNode,