UNPKG

everything-dev

Version:

A consolidated product package for building Module Federation apps with oRPC APIs.

1 lines • 9.25 kB
{"version":3,"file":"digest.cjs","names":["createHash"],"sources":["../../../src/services/registry/digest.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport type { BosConfig, RuntimeConfig } from \"../../types\";\nimport { walkRemotes } from \"../remotes\";\n\n/**\n * The registry's identity module — every composition-plane digest derives\n * here so the planes can't drift apart (ADR 0046 ticket 04). Vocabulary: a\n * digest is any identity hash; the species are distinguished by what they\n * hash and who consumes them, never compared across.\n *\n * - `pointerDigest` — THE composition identity (what is pinned): a hash over\n * every remote's pin coordinates (digest manifest + integrity, or the\n * direct entry integrity). It is the lockfile's identity (ADR 0042), the\n * watch's change-detection hash, and what deployment records name. The\n * derivation never changes silently: stored lockfiles and boot snapshots\n * recompute and compare it.\n * - `deploymentDigest` — the serving-generation identity (what is served,\n * atomic-deploys 10): derived from the pointer inputs — the same pin\n * coordinates `pointerDigest` hashes, stamped onto the resolved slots at\n * resolution — plus the resolved entry coordinates (entryUrl, entry\n * integrity, SSR integrity) per slot. Stamped into the runtime config as\n * the client's soft-refresh signal (wire field `deploymentDigest`) and\n * used by the host's adopt comparison.\n *\n * The relation, and its limit: pointer stable + entries stable ⇒ deployment\n * stable, because deployment hashes exactly those inputs. The converse is\n * deliberately NOT a guarantee the code may rely on: deployment stability is\n * a serving-plane statement (\"keep serving this generation\"), pointer\n * stability is a provenance statement (\"the published pins moved\"). The\n * watch tracks the pointer independently; adopt treats an unchanged\n * deployment digest as skip — a heuristic, never proof that nothing was\n * republished.\n *\n * Species inventory (each answers one question; homes are authoritative):\n * - content digests — bytes-hash-to-SRI: the engine's `Digest` brand\n * (`services/verify/engine.ts`) is the only SRI primitive's output type.\n * `version id`/`dirId` (every-plugin `artifact-names`) are artifact\n * content hashes — versioned manifests and `versions/<dirId>/` dirs — not\n * composition identities; they stay in every-plugin.\n * - compose digest — `digestOf` (`everything-dev/ui/manifest`, wrapped by\n * the host's `digestOfSources`): SSR/client parity over sorted manifests\n * + keys; deliberately deployment-free so parity holds across pin churn.\n * - lockfile digest — `digestOfLockfile` (lockfile/schema.ts): content\n * digest of the serialized lockfile; what a deployment record names when\n * it answers \"what exact composition was live\". Its sibling\n * `lockfilePointerDigest` recomputes the pointer digest from the stored\n * `remotes` record — ≡ `pointerDigest` by construction; kept beside the\n * `pointerDigest` field it validates.\n * - compose variant cache key — host ui-compose `variantCacheKey`: SSR\n * integrity / local mtimes. A cache key, NOT an identity — it hashes the\n * dev filesystem, so it can never be compared across planes.\n *\n * Vocabulary cutover (ticket 04 + follow-up): the word \"fingerprint\" is\n * retired — the identities it named were `pointerDigest`/`deploymentDigest`\n * all along, every wire field it survived in (lockfile, boot snapshot, deploy\n * records, the version endpoint, the client payload) is renamed in the same\n * change, and the module's own subpath moved with it: this file is\n * `everything-dev/digest` (the old `everything-dev/fingerprint` subpath is\n * removed, not deprecated). Files written by older framework versions fail\n * the strict parse naming the field; they regenerate on the next `bos lock` /\n * first adopt.\n */\n\n/**\n * The composition-plane digest form: sha256 over \"|\"-joined parts, trimmed\n * to 16 hex chars. One helper so every producer of this form (this module,\n * the lockfile recompute) shares the exact serialization — the form is\n * load-bearing in stored files.\n */\nexport function digestOfParts(parts: Array<string>): string {\n return createHash(\"sha256\").update(parts.join(\"|\")).digest(\"hex\").slice(0, 16);\n}\n\n/**\n * The published pointer's version identity (atomic-deploys 08/12): a hash\n * over every remote's pin coordinates — cheap to compute (no version-manifest\n * fetch), and stable exactly when the deployed set is. Shared so the CLI and\n * the host compute the same identity for the same pointer.\n */\nexport function pointerDigest(config: BosConfig): string {\n const parts: Array<string> = [];\n walkRemotes(config as unknown as Record<string, unknown>, ({ remote, entry, isPluginRef }) => {\n if (isPluginRef) {\n parts.push(`${remote}:${entry as string}`);\n return;\n }\n const s = entry as { digest?: unknown; integrity?: unknown } | undefined;\n if (!s) return;\n const digest = s.digest as { manifest?: unknown; integrity?: unknown } | undefined;\n const digestPart =\n digest && typeof digest.manifest === \"string\" && typeof digest.integrity === \"string\"\n ? `${digest.manifest}:${digest.integrity}`\n : \"\";\n const directPart = typeof s.integrity === \"string\" ? s.integrity : \"\";\n parts.push(`${remote}:${digestPart}:${directPart}`);\n });\n return digestOfParts(parts);\n}\n\n/** Per-remote digest ids for display (remote → versioned manifest filename). */\nexport function remoteDigests(config: BosConfig): Record<string, string> {\n const digests: Record<string, string> = {};\n walkRemotes(config as unknown as Record<string, unknown>, ({ remote, entry, isPluginRef }) => {\n if (isPluginRef) return;\n const s = entry as { digest?: unknown } | undefined;\n if (!s) return;\n const manifest = (s.digest as { manifest?: unknown } | undefined)?.manifest;\n if (typeof manifest === \"string\") digests[remote] = manifest;\n });\n return digests;\n}\n\n/**\n * The serving-generation identity — see the module docstring for the\n * derivation contract versus `pointerDigest`. Per slot: the pointer inputs\n * (pin coordinates — what is pinned) then the resolved coordinates (what is\n * served). The pointer inputs ride the resolved slots because resolution\n * stamps them (`deriveVersionManifestFields`), so the runtime config is\n * self-describing and this stays a single-argument derivation.\n */\nexport function deploymentDigest(config: RuntimeConfig): string {\n const parts: Array<string> = [];\n const remote = (\n prefix: string,\n s:\n | {\n digest?: { manifest?: unknown; integrity?: unknown };\n integrity?: string;\n entryUrl?: string;\n ssrIntegrity?: string;\n }\n | undefined,\n ) => {\n if (!s) return;\n const digest = s.digest;\n const digestPart =\n digest && typeof digest.manifest === \"string\" && typeof digest.integrity === \"string\"\n ? `${digest.manifest}:${digest.integrity}`\n : \"\";\n const directPart = typeof s.integrity === \"string\" ? s.integrity : \"\";\n parts.push(\n `${prefix}:${digestPart}:${directPart}:${s.entryUrl ?? \"\"}:${s.integrity ?? \"\"}:${s.ssrIntegrity ?? \"\"}`,\n );\n };\n remote(\"ui\", config.ui);\n remote(\"api\", config.api);\n remote(\"auth\", config.auth);\n for (const [key, plugin] of Object.entries(config.plugins ?? {})) {\n remote(`plugin.${key}`, plugin);\n remote(`plugin.${key}.ui`, plugin.ui);\n }\n return digestOfParts(parts);\n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