everything-dev
Version:
A consolidated product package for building Module Federation apps with oRPC APIs.
42 lines (40 loc) • 1.48 kB
JavaScript
import { walkConfigSlots } from "../config-slots.mjs";
import { createHash } from "node:crypto";
//#region src/services/registry/fingerprint.ts
/**
* The published pointer's version identity (atomic-deploys 08/12): a hash
* over every slot's `pin` — cheap to compute (no version-manifest fetch), and
* stable exactly when the deployed set is. Shared so the CLI and the host
* compute the same identity for the same pointer.
*/
function pointerFingerprint(config) {
const parts = [];
walkConfigSlots(config, ({ slot, entry, isPluginRef }) => {
if (isPluginRef) {
parts.push(`${slot}:${entry}`);
return;
}
const s = entry;
if (!s) return;
const pin = s.pin;
const pinPart = pin && typeof pin.manifest === "string" && typeof pin.integrity === "string" ? `${pin.manifest}:${pin.integrity}` : "";
const directPart = typeof s.integrity === "string" ? s.integrity : "";
parts.push(`${slot}:${pinPart}:${directPart}`);
});
return createHash("sha256").update(parts.join("|")).digest("hex").slice(0, 16);
}
/** Per-slot pin ids for display (slot → versioned manifest filename). */
function slotPins(config) {
const pins = {};
walkConfigSlots(config, ({ slot, entry, isPluginRef }) => {
if (isPluginRef) return;
const s = entry;
if (!s) return;
const manifest = s.pin?.manifest;
if (typeof manifest === "string") pins[slot] = manifest;
});
return pins;
}
//#endregion
export { pointerFingerprint, slotPins };
//# sourceMappingURL=fingerprint.mjs.map