import { Selectable } from 'kysely' import { Cid } from '@atproto/lex' import { AtUri, normalizeDatetimeAlways } from '@atproto/syntax' import { app } from '../../../../lexicons/index.js' import { BackgroundQueue } from '../../background.js' import { DatabaseSchema, DatabaseSchemaType } from '../../db/database-schema.js' import { Database } from '../../db/index.js' import { RecordProcessor } from '../processor.js' type IndexedStarterPack = Selectable const insertFn = async ( db: DatabaseSchema, uri: AtUri, cid: Cid, obj: app.bsky.graph.starterpack.Main, timestamp: string, ): Promise => { const inserted = await db .insertInto('starter_pack') .values({ uri: uri.toString(), cid: cid.toString(), creator: uri.host, name: obj.name, createdAt: normalizeDatetimeAlways(obj.createdAt), indexedAt: timestamp, }) .onConflict((oc) => oc.doNothing()) .returningAll() .executeTakeFirst() return inserted || null } const findDuplicate = async (): Promise => { return null } const notifsForInsert = () => { return [] } const deleteFn = async ( db: DatabaseSchema, uri: AtUri, ): Promise => { const deleted = await db .deleteFrom('starter_pack') .where('uri', '=', uri.toString()) .returningAll() .executeTakeFirst() return deleted || null } const notifsForDelete = () => { return { notifs: [], toDelete: [] } } export type PluginType = ReturnType export const makePlugin = (db: Database, background: BackgroundQueue) => { return new RecordProcessor(db, background, { schema: app.bsky.graph.starterpack.main, insertFn, findDuplicate, deleteFn, notifsForInsert, notifsForDelete, }) } export default makePlugin