Skip to content
← Public packages

@kody/kody-factory

Forkable multi-project software factory: signals, priority queue, project UI, sweep job. Agent runners and Sentry reach it by events.

FollowFork

Files

records.ts

35 lines · 1.3 KB · TypeScript
/**
 * Signal records export: list, get, and replay signals.
 *
 * @example
 * import records from 'kody:@kody/kody-factory/signals/records'
 * await records({ action: 'list' })
 * await records({ action: 'get', id: 'sig_abc123' })
 * await records({ action: 'replay', id: 'sig_abc123', dryRun: true })
 */
import { listRecords, getRecord, countRecords, type SignalStatus } from '../../signals/records/index.ts'
import { replaySignal } from '../../signals/pipeline.ts'

type RecordsInput =
	| { action: 'list'; sourceId?: string; status?: SignalStatus; projectId?: string; limit?: number; before?: string }
	| { action: 'get'; id: string }
	| { action: 'count'; sourceId?: string; status?: SignalStatus; projectId?: string }
	| { action: 'replay'; id: string; dryRun?: boolean }

export default async function records(input: RecordsInput) {
	switch (input.action) {
		case 'list':
			return { records: await listRecords(input) }
		case 'get': {
			const record = await getRecord(input.id)
			if (!record) return { found: false, record: null }
			return { found: true, record }
		}
		case 'count':
			return { count: await countRecords(input) }
		case 'replay':
			return replaySignal(input.id, { dryRun: input.dryRun })
		default:
			throw new Error(`Unknown action: ${(input as { action: string }).action}`)
	}
}