(fieldInfo: Sorting<L>, list: L[], prompt?: string)
| 78 | } |
| 79 | |
| 80 | export async function stringGetIdFromUser<L extends object>(fieldInfo: Sorting<L>, list: L[], prompt?: string): Promise<string> { |
| 81 | const primaryKeyName = fieldInfo.primaryKeyName |
| 82 | |
| 83 | const itemIdOrIndex: string = await stringInput(prompt ?? 'Enter id or index', { |
| 84 | validate: input => |
| 85 | convertToId(input, primaryKeyName, list) |
| 86 | ? true |
| 87 | : `Invalid id or index "${input}". Please enter an index or valid id.`, |
| 88 | }) |
| 89 | const inputId = convertToId(itemIdOrIndex, primaryKeyName, list) |
| 90 | if (inputId === false) { |
| 91 | throw Error(`unable to convert ${itemIdOrIndex} to id`) |
| 92 | } |
| 93 | return inputId |
| 94 | } |
no test coverage detected