{"draft":null,"from":2,"to":318,"files":[{"path":"server/src/push-snapshot.ts","added":35,"removed":0,"diff":"--- /dev/null\n+++ b/server/src/push-snapshot.ts\n@@ -0,0 +1,35 @@\n+import type { FileModes } from \"../../worker/project/project-api.ts\";\n+\n+export interface PushSnapshotMetadata {\n+\tversion: number;\n+\tpaths: string[];\n+\tmodes: FileModes;\n+\tblobs: Record<string, string>;\n+\tlast?: { agent: string; message: string };\n+}\n+\n+/** Construct outside the read scope so detaching metadata never evaluates file text. */\n+export function pushSnapshot(\n+\tmetadata: PushSnapshotMetadata,\n+\treadText: (version: number, path: string) => string,\n+\treadBatch?: (version: number, paths: readonly string[]) => Record<string, string>,\n+) {\n+\tconst { paths, ...shared } = metadata;\n+\tconst files: Record<string, string> = Object.create(null);\n+\tlet cache: Record<string, string> = Object.create(null);\n+\tfor (let index = 0; index < paths.length; index++) {\n+\t\tconst path = paths[index]!;\n+\t\tObject.defineProperty(files, path, {\n+\t\t\tenumerable: true,\n+\t\t\tget: () => {\n+\t\t\t\tif (!readBatch) return readText(shared.version, path);\n+\t\t\t\tif (!Object.hasOwn(cache, path)) cache = readBatch(shared.version, paths.slice(index, index + 64));\n+\t\t\t\tif (!Object.hasOwn(cache, path)) throw Error(\"push batch omitted requested file\");\n+\t\t\t\tconst text = cache[path]!;\n+\t\t\t\tdelete cache[path];\n+\t\t\t\treturn text;\n+\t\t\t},\n+\t\t});\n+\t}\n+\treturn { ...shared, files };\n+}"}],"unmatched":[]}