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>
This commit was merged in pull request #19.
This commit is contained in:
1 parent
06b7ad2c77
commit
448c67912f
44 files changed
+3081
-14
No files matched your search
@@ -0,0 +1,123 @@
|
||||
// Repositories für Git-Verbindungen und Brew-Verknüpfungen (PostgreSQL, ADR 0003 §2).
|
||||
// Gleicher Vertrag wie mongo/git.js. Ergebnisse: plain objects in camelCase.
|
||||
const UUID = /^[0-9a-f-]{36}$/i;
|
||||
|
||||
const CONN = {
|
||||
label : 'label',
|
||||
repoUrl : 'repo_url',
|
||||
authUsername : 'auth_username',
|
||||
tokenEnc : 'token_enc',
|
||||
defaultBranch : 'default_branch',
|
||||
brewDir : 'brew_dir',
|
||||
assetsDir : 'assets_dir',
|
||||
lastVerifiedAt : 'last_verified_at'
|
||||
};
|
||||
const LINK = {
|
||||
connectionId : 'connection_id',
|
||||
branch : 'branch',
|
||||
path : 'path',
|
||||
lastCommitSha : 'last_commit_sha',
|
||||
lastBlobSha : 'last_blob_sha',
|
||||
lastSyncedAt : 'last_synced_at',
|
||||
lastError : 'last_error'
|
||||
};
|
||||
|
||||
const toRow = (map, patch)=>{
|
||||
const row = {};
|
||||
for (const [field, column] of Object.entries(map)) {
|
||||
if(patch[field] !== undefined) row[column] = patch[field];
|
||||
}
|
||||
return row;
|
||||
};
|
||||
|
||||
const rowToConnection = (r)=>!r ? null : ({
|
||||
id : r.id,
|
||||
ownerUserId : r.owner_user_id,
|
||||
label : r.label,
|
||||
repoUrl : r.repo_url,
|
||||
authUsername : r.auth_username,
|
||||
tokenEnc : r.token_enc,
|
||||
defaultBranch : r.default_branch,
|
||||
brewDir : r.brew_dir,
|
||||
assetsDir : r.assets_dir,
|
||||
createdAt : r.created_at,
|
||||
updatedAt : r.updated_at,
|
||||
lastVerifiedAt : r.last_verified_at ?? null
|
||||
});
|
||||
|
||||
const rowToLink = (r)=>!r ? null : ({
|
||||
brewId : r.brew_id,
|
||||
connectionId : r.connection_id,
|
||||
branch : r.branch,
|
||||
path : r.path,
|
||||
lastCommitSha : r.last_commit_sha ?? null,
|
||||
lastBlobSha : r.last_blob_sha ?? null,
|
||||
lastSyncedAt : r.last_synced_at ?? null,
|
||||
lastError : r.last_error ?? null
|
||||
});
|
||||
|
||||
export const createGitConnectionRepository = (db)=>({
|
||||
async create({ id, ownerUserId, ...rest }) {
|
||||
const values = { owner_user_id: ownerUserId, ...toRow(CONN, rest) };
|
||||
if(id) values.id = id;
|
||||
return rowToConnection(await db.insertInto('git_connections').values(values).returningAll().executeTakeFirstOrThrow());
|
||||
},
|
||||
async findById(id) {
|
||||
if(!UUID.test(String(id))) return null;
|
||||
return rowToConnection(await db.selectFrom('git_connections').selectAll().where('id', '=', id).executeTakeFirst());
|
||||
},
|
||||
async findByIdForOwner(id, userId) {
|
||||
if(!UUID.test(String(id)) || !UUID.test(String(userId))) return null;
|
||||
return rowToConnection(await db.selectFrom('git_connections').selectAll().where('id', '=', id).where('owner_user_id', '=', userId).executeTakeFirst());
|
||||
},
|
||||
async listByOwner(userId) {
|
||||
if(!UUID.test(String(userId))) return [];
|
||||
const rows = await db.selectFrom('git_connections').selectAll().where('owner_user_id', '=', userId).orderBy('created_at').orderBy('id').execute();
|
||||
return rows.map(rowToConnection);
|
||||
},
|
||||
async update(id, patch) {
|
||||
if(!UUID.test(String(id))) return null;
|
||||
const row = toRow(CONN, patch);
|
||||
if(!Object.keys(row).length) return this.findById(id);
|
||||
row.updated_at = new Date();
|
||||
return rowToConnection(await db.updateTable('git_connections').set(row).where('id', '=', id).returningAll().executeTakeFirst());
|
||||
},
|
||||
async delete(id) {
|
||||
if(!UUID.test(String(id))) return false;
|
||||
const res = await db.deleteFrom('git_connections').where('id', '=', id).executeTakeFirst();
|
||||
return res.numDeletedRows > 0n;
|
||||
}
|
||||
});
|
||||
|
||||
export const createBrewGitLinkRepository = (db)=>({
|
||||
// Legt den Link an oder ersetzt ihn (höchstens einer pro Brew)
|
||||
async upsert({ brewId, ...rest }) {
|
||||
const set = toRow(LINK, rest);
|
||||
return rowToLink(await db.insertInto('brew_git_links').values({ brew_id: brewId, ...set })
|
||||
.onConflict((oc)=>oc.column('brew_id').doUpdateSet(set)).returningAll().executeTakeFirstOrThrow());
|
||||
},
|
||||
async findByBrewId(brewId) {
|
||||
if(!UUID.test(String(brewId))) return null;
|
||||
return rowToLink(await db.selectFrom('brew_git_links').selectAll().where('brew_id', '=', brewId).executeTakeFirst());
|
||||
},
|
||||
async findByLocation(connectionId, branch, path) {
|
||||
if(!UUID.test(String(connectionId))) return null;
|
||||
return rowToLink(await db.selectFrom('brew_git_links').selectAll()
|
||||
.where('connection_id', '=', connectionId).where('branch', '=', branch).where('path', '=', path).executeTakeFirst());
|
||||
},
|
||||
async listByConnection(connectionId) {
|
||||
if(!UUID.test(String(connectionId))) return [];
|
||||
return (await db.selectFrom('brew_git_links').selectAll().where('connection_id', '=', connectionId).execute()).map(rowToLink);
|
||||
},
|
||||
async update(brewId, patch) {
|
||||
if(!UUID.test(String(brewId))) return null;
|
||||
const row = toRow(LINK, patch);
|
||||
if(!Object.keys(row).length) return this.findByBrewId(brewId);
|
||||
return rowToLink(await db.updateTable('brew_git_links').set(row).where('brew_id', '=', brewId).returningAll().executeTakeFirst());
|
||||
},
|
||||
async delete(brewId) {
|
||||
if(!UUID.test(String(brewId))) return false;
|
||||
const res = await db.deleteFrom('brew_git_links').where('brew_id', '=', brewId).executeTakeFirst();
|
||||
return res.numDeletedRows > 0n;
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user