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

routing.ts

33 lines · 1.1 KB · TypeScript
/**
 * Signal routing config export: get, save, list, and delete routing configs.
 *
 * @example
 * import routing from 'kody:@kody/kody-factory/signals/routing'
 * await routing({ action: 'get', projectId: 'kody' })
 * await routing({ action: 'save', config: { projectId: 'kody', ... } })
 */
import { getRoutingConfig, saveRoutingConfig, listRoutingConfigs, deleteRoutingConfig } from '../../signals/routing/index.ts'
import type { RoutingConfig } from '../../signals/routing/types.ts'

type RoutingInput =
	| { action: 'get'; projectId: string }
	| { action: 'save'; config: RoutingConfig }
	| { action: 'list' }
	| { action: 'delete'; projectId: string }

export default async function routing(input: RoutingInput) {
	switch (input.action) {
		case 'get':
			return { config: await getRoutingConfig(input.projectId) }
		case 'save':
			await saveRoutingConfig(input.config)
			return { saved: true }
		case 'list':
			return { configs: await listRoutingConfigs() }
		case 'delete':
			await deleteRoutingConfig(input.projectId)
			return { deleted: true }
		default:
			throw new Error(`Unknown action: ${(input as { action: string }).action}`)
	}
}