patch-id.ts
This file
Path
packages/git/src/patch-id.ts
29 lines · 1009 bytes · TypeScript
Last changed by
Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
History of this fileTake it
The walk stopped after 200 commits: lines older than 878da37 point at it.
Merge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37
lines 1–11why, one step back1import { PatchId } from "@repo/protocol/ids";2import { Array, Effect, Order } from "effect";34import type { Change } from "./tree-diff.ts";56const hex = (bytes: ArrayBuffer) =>7 [...new Uint8Array(bytes)]8 .map((byte) => byte.toString(16).padStart(2, "0"))9 .join("");1011/**Drop the private build plan's citations from the code, and fail verify if one comes backoscabrielbefore adoptiona29cef6
line 12why, one step back12 * An answer's patch id: SHA-256 over its change set as sortedMerge build/420-release-downloads: the CLI installs from the platform itself, with no GitHub in the release pathoscabrielbefore adoption878da37
lines 13–29why, one step back13 * `path\0before\0after\n` lines, an absent blob as the empty string. It14 * ignores order and moves exactly when a blob the answer touches moves. It15 * is the platform's own id, not `git patch-id`, so a Worker computes it with16 * WebCrypto and no diff.17 */18export const patchId = (changes: readonly Change[]): Effect.Effect<PatchId> => {19 const lines = Array.sort(20 changes.map(21 ({ after, before, path }) => `${path}\0${before ?? ""}\0${after ?? ""}\n`22 ),23 Order.String24 );2526 return Effect.promise(() =>27 crypto.subtle.digest("SHA-256", new TextEncoder().encode(lines.join("")))28 ).pipe(Effect.map((digest) => PatchId.make(hex(digest))));29};