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:
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user