Diffinery

codician/diffinerypublic

Open-source, agent-first GitHub and GitHub Actions alternative that runs on your own Cloudflare account: git hosting, pull requests, code review and drop-in GitHub Actions YAML on Workers, Durable Objects, R2 and Containers.

18 lines · 743 BRaw History
1import { hashObject, type GitObject, type ObjectType } from "./objects.js";
2import type { ObjectStore } from "./store.js";
3
4/** In-memory object store, used in tests and as a write buffer. */
5export class MemoryStore implements ObjectStore {
6 readonly objects = new Map<string, GitObject>();
7 constructor(private fallback?: { read(oid: string): Promise<GitObject | null> }) {}
8
9 async read(oid: string): Promise<GitObject | null> {
10 return this.objects.get(oid) ?? (this.fallback ? this.fallback.read(oid) : null);
11 }
12
13 async write(type: ObjectType, content: Uint8Array): Promise<string> {
14 const oid = await hashObject(type, content);
15 if (!this.objects.has(oid)) this.objects.set(oid, { type, content });
16 return oid;
17 }
18}