// Executor for `content.list`. Resolves the input `type` to a KNOWN content // table (an unknown name can never reach a raw table string — it targets an // empty result instead), excludes archived rows, and orders newest-edited // first. The runtime AND-merges the tenant predicate (the table carries // `tenant()`), so this never leaks across tenants. import { eq, neq } from '@voltro/database' import type { AppContext } from '@voltro/runtime' import { contentTypeByName, contentTypes } from '../content' const execute = (input: { type: string; status?: 'draft' | 'published' }, _ctx: AppContext) => { const ct = contentTypeByName.get(input.type) const suffix = input.status === 'draft' ? 'drafts' : 'published' // Known type → its table + exclude archived; unknown → a never-matching // predicate on a real table (empty result, no injection). const fallback = contentTypes[0]?.name ?? 'blogPost' const table = `${ct?.name ?? fallback}_${suffix}` const predicate = ct ? neq('status', 'archived') : eq('id', 'none') return { descriptor: { table, predicate, order: [{ column: 'updatedAt' as const, direction: 'desc' as const }], take: 200, skip: undefined, projection: undefined, }, } } export default execute