( schema: any, )
| 48 | } |
| 49 | |
| 50 | export function asNonEmptyStringArray( |
| 51 | schema: any, |
| 52 | ): NonEmptyArray<string> | null { |
| 53 | const arraySchema = asArraySchema(schema); |
| 54 | |
| 55 | if (!arraySchema) { |
| 56 | return null; |
| 57 | } |
| 58 | |
| 59 | // For TaskList: items is an object with a "name" property holding the enum |
| 60 | const items = arraySchema.items as any; |
| 61 | if (items?.type === "object" && items?.properties?.name?.enum) { |
| 62 | const choices = items.properties.name.enum; |
| 63 | if (isStringArray(choices) && choices.length > 0) { |
| 64 | return choices as NonEmptyArray<string>; |
| 65 | } |
| 66 | return null; |
| 67 | } |
| 68 | |
| 69 | const choices = arraySchema.items.enum; |
| 70 | |
| 71 | if (!isStringArray(choices) || choices.length === 0) { |
| 72 | return null; |
| 73 | } |
| 74 | |
| 75 | return choices as NonEmptyArray<string>; |
| 76 | } |
| 77 | |
| 78 | const isStringArray = (arr: any): arr is string[] => |
| 79 | Array.isArray(arr) && arr.every((i) => typeof i === "string"); |
nothing calls this directly
no test coverage detected