Files
homebrewery-oidc/tests/fork/git-memory-storage.js
dev-bot BotandClaude Sonnet 5.5 448c67912f
CI / App (npm ci + Build, ESLint, Stylelint, Jest) (push) Successful in 3m25s
CI / Storage (mongo) (push) Successful in 1m24s
CI / Storage (postgres) (push) Successful in 1m13s
Image / Image bauen und pushen (push) Successful in 1m3s
feat(git): Git-Backend über HTTPS + PAT (ADR 0003, FLW-86) (#19)
Repositories gitConnections/brewGitLinks (Mongo/PG), Krypto, SSRF-Policy mit net.BlockList, git-Client ohne Arbeitskopie, Sync/Konflikte, /api/git/*, Client (Verbindungen, Git-Status, Konfliktdialog), Autosave 60 s für Git-Brews (F6), Tests und Doku.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Dev (Paperclip) <dev-bot@noreply.git.morlana.online>
2026-11-25 21:16:42 +00:00

38 lines
2.6 KiB
JavaScript

import { randomUUID } from 'crypto';
// In-Memory-Storage mit dem Repository-Vertrag aus ADR 0002/0003 (nur für Tests ohne Datenbank).
export const createMemoryStorage = ()=>{
const users = new Map(); const brews = new Map(); const conns = new Map(); const links = new Map();
const clone = (o)=>o ? structuredClone(o) : null;
return {
users : {
async create(u) { const user = { id: randomUUID(), displayName: null, ...u }; users.set(user.id, user); return clone(user); },
async findById(id) { return clone(users.get(id)); }
},
brews : {
async create(b) { const brew = { ...b, id: randomUUID(), editId: b.editId ?? `e${randomUUID().slice(0, 11)}`, shareId: b.shareId ?? `s${randomUUID().slice(0, 11)}`, version: b.version ?? 1 }; brews.set(brew.id, brew); return clone(brew); },
async findByEditId(editId) { return clone([...brews.values()].find((b)=>b.editId === editId)); },
async update(b) { if(!brews.has(b.id)) return null; brews.set(b.id, { ...brews.get(b.id), ...b }); return clone(brews.get(b.id)); },
async deleteById(id) { links.delete(id); return brews.delete(id); }
},
gitConnections : {
async create(c) { const conn = { createdAt: new Date(), updatedAt: new Date(), lastVerifiedAt: null, authUsername: 'git', brewDir: 'brews', assetsDir: 'assets', ...c }; conns.set(conn.id, conn); return clone(conn); },
async findById(id) { return clone(conns.get(id)); },
async findByIdForOwner(id, uid) { const c = conns.get(id); return c && c.ownerUserId === uid ? clone(c) : null; },
async listByOwner(uid) { return [...conns.values()].filter((c)=>c.ownerUserId === uid).map(clone); },
async update(id, patch) { if(!conns.has(id)) return null; Object.assign(conns.get(id), patch); return clone(conns.get(id)); },
async delete(id) { for (const [k, l] of links)if(l.connectionId === id) links.delete(k); return conns.delete(id); }
},
brewGitLinks : {
async upsert({ brewId, ...rest }) {
for (const [k, l] of links)if(k !== brewId && l.connectionId === rest.connectionId && l.branch === rest.branch && l.path === rest.path) throw new Error('unique');
links.set(brewId, { lastCommitSha: null, lastBlobSha: null, lastSyncedAt: null, lastError: null, ...links.get(brewId), brewId, ...rest }); return clone(links.get(brewId));
},
async findByBrewId(id) { return clone(links.get(id)); },
async findByLocation(cid, branch, path) { return clone([...links.values()].find((l)=>l.connectionId === cid && l.branch === branch && l.path === path)); },
async update(id, patch) { if(!links.has(id)) return null; Object.assign(links.get(id), patch); return clone(links.get(id)); },
async delete(id) { return links.delete(id); }
}
};
};