the statusphere demo reworked into a vite/react app in a monorepo

Fix: handle firehose update events

+18 -3
+6 -1
src/firehose/firehose.ts
··· 57 57 if (isCommit(evt) && !this.opts.excludeCommit) { 58 58 const parsed = await parseCommit(evt) 59 59 for (const write of parsed) { 60 - if (!this.opts.filterCollections || this.opts.filterCollections.includes(write.uri.collection)) { 60 + if ( 61 + !this.opts.filterCollections || 62 + this.opts.filterCollections.includes(write.uri.collection) 63 + ) { 61 64 yield write 62 65 } 63 66 } ··· 167 170 168 171 type Update = CommitMeta & { 169 172 event: 'update' 173 + record: RepoRecord 174 + cid: CID 170 175 } 171 176 172 177 type Delete = CommitMeta & {
+12 -2
src/firehose/ingester.ts
··· 10 10 const firehose = new Firehose({}) 11 11 12 12 for await (const evt of firehose.run()) { 13 - if (evt.event === 'create') { 13 + // Watch for write events 14 + if (evt.event === 'create' || evt.event === 'update') { 14 15 const record = evt.record 16 + 17 + // If the write is a valid status update 15 18 if ( 16 19 evt.collection === 'com.example.status' && 17 20 Status.isRecord(record) && 18 21 Status.validateRecord(record).success 19 22 ) { 23 + // Store the status in our SQLite 20 24 await this.db 21 25 .insertInto('status') 22 26 .values({ ··· 25 29 updatedAt: record.updatedAt, 26 30 indexedAt: new Date().toISOString(), 27 31 }) 28 - .onConflict((oc) => oc.doNothing()) 32 + .onConflict((oc) => 33 + oc.column('authorDid').doUpdateSet({ 34 + status: record.status, 35 + updatedAt: record.updatedAt, 36 + indexedAt: new Date().toISOString(), 37 + }) 38 + ) 29 39 .execute() 30 40 } 31 41 }