(
field: string,
value: unknown,
accepted: readonly T[],
opts: KindOpts = {},
)
| 124 | * @param opts.kind `'field'` (default) or `'flag'`. |
| 125 | */ |
| 126 | export function requireEnum<T extends string>( |
| 127 | field: string, |
| 128 | value: unknown, |
| 129 | accepted: readonly T[], |
| 130 | opts: KindOpts = {}, |
| 131 | ): asserts value is T { |
| 132 | const { kind = 'field' } = opts; |
| 133 | |
| 134 | // Use valibot picklist for structural detection. Custom message is |
| 135 | // composed here so the envelope text is explicit and stable. |
| 136 | const result = v.safeParse(v.picklist(accepted as [T, ...T[]]), value); |
| 137 | if (!result.success) { |
| 138 | const acceptedList = accepted.map(a => `"${a}"`).join(', '); |
| 139 | throw localValidationError(field, `must be one of: ${acceptedList}`, [...accepted], kind); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | /** |
| 144 | * Validate a caller-supplied `--idempotency-key` value before it is sent as |
no test coverage detected