Files
rea/src/domain/javascript/javascriptExportShapeComparisonIdentity.ts
T

22 lines
779 B
TypeScript
Raw Normal View History

2026-07-22 20:38:26 +08:00
import { createHash } from "node:crypto";
import canonicalize from "canonicalize";
/**
* Canonically encode one export-shape comparison value.
*
* Comparison identifiers hash the full result semantics, including each
* change's presence object and the per-variant property inventories.
*/
2026-07-22 20:38:26 +08:00
export const canonicalExportShapeValue = (value: unknown): string => {
const encoded = canonicalize(value);
if (encoded === undefined)
throw new TypeError(
"JavaScript export shape comparison could not canonicalize data",
);
return encoded;
};
/** Derive one deterministic SHA-256 comparison identifier component. */
export const digestExportShapeValue = (value: unknown): string =>
createHash("sha256").update(canonicalExportShapeValue(value)).digest("hex");