A zero-dependency AT Protocol Personal Data Server written in JavaScript
atproto pds

feat: emit delete events on reset-repo

Delete each record through the normal flow before wiping,
so relays and indexers can clean up their indexes.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>

Changed files
+21 -5
src
+21 -5
src/pds.js
··· 2031 2031 } 2032 2032 2033 2033 async handleResetRepo() { 2034 - this.sql.exec(`DELETE FROM blocks`); 2035 - this.sql.exec(`DELETE FROM records`); 2036 - this.sql.exec(`DELETE FROM commits`); 2037 - this.sql.exec(`DELETE FROM seq_events`); 2034 + const did = await this.getDid(); 2035 + if (!did) { 2036 + return Response.json({ ok: true, message: 'no repo to reset', deleted: 0 }); 2037 + } 2038 + 2039 + // Get all records before deleting 2040 + const records = /** @type {{collection: string, rkey: string}[]} */ ( 2041 + this.sql.exec('SELECT collection, rkey FROM records').toArray() 2042 + ); 2043 + 2044 + // Delete each record through normal flow (emits events to firehose) 2045 + for (const { collection, rkey } of records) { 2046 + await this.deleteRecord(collection, rkey); 2047 + } 2048 + 2049 + // Clean up remaining state 2050 + this.sql.exec('DELETE FROM blocks'); 2051 + this.sql.exec('DELETE FROM commits'); 2052 + this.sql.exec('DELETE FROM seq_events'); 2038 2053 await this.state.storage.delete('head'); 2039 2054 await this.state.storage.delete('rev'); 2040 - return Response.json({ ok: true, message: 'repo data cleared' }); 2055 + 2056 + return Response.json({ ok: true, message: 'repo data cleared', deleted: records.length }); 2041 2057 } 2042 2058 2043 2059 /** @param {Request} request */