(input: unknown)
| 28 | } |
| 29 | |
| 30 | export function parseAskUserQuestionInput(input: unknown): { questions: AskUserQuestionQuestion[] } { |
| 31 | if (!isObject(input)) return { questions: [] } |
| 32 | |
| 33 | const rawQuestions = input.questions |
| 34 | if (!Array.isArray(rawQuestions)) return { questions: [] } |
| 35 | |
| 36 | const questions: AskUserQuestionQuestion[] = [] |
| 37 | for (const raw of rawQuestions) { |
| 38 | if (!isObject(raw)) continue |
| 39 | |
| 40 | const question = typeof raw.question === 'string' ? raw.question.trim() : '' |
| 41 | const header = typeof raw.header === 'string' ? raw.header.trim() : '' |
| 42 | const multiSelect = typeof raw.multiSelect === 'boolean' ? raw.multiSelect : false |
| 43 | |
| 44 | const rawOptions = Array.isArray(raw.options) ? raw.options : [] |
| 45 | const options: AskUserQuestionOption[] = [] |
| 46 | for (const opt of rawOptions) { |
| 47 | if (!isObject(opt)) continue |
| 48 | const label = typeof opt.label === 'string' ? opt.label.trim() : '' |
| 49 | if (!label) continue |
| 50 | const description = typeof opt.description === 'string' ? opt.description.trim() : null |
| 51 | options.push({ label, description }) |
| 52 | } |
| 53 | |
| 54 | if (!question && options.length === 0) continue |
| 55 | |
| 56 | questions.push({ |
| 57 | header: header.length > 0 ? header : null, |
| 58 | question, |
| 59 | options, |
| 60 | multiSelect |
| 61 | }) |
| 62 | } |
| 63 | |
| 64 | return { questions } |
| 65 | } |
| 66 | |
| 67 | export function extractAskUserQuestionQuestionsInfo(input: unknown): AskUserQuestionQuestionInfo[] | null { |
| 68 | if (!isObject(input)) return null |
no test coverage detected