( validate: Validate<TValue>, value: TValue | undefined )
| 43 | * @returns the validation result |
| 44 | */ |
| 45 | export function runValidation<TValue>( |
| 46 | validate: Validate<TValue>, |
| 47 | value: TValue | undefined |
| 48 | ): string | Error | undefined { |
| 49 | if ('~standard' in validate) { |
| 50 | const result = validate['~standard'].validate(value); |
| 51 | // https://standardschema.dev/schema#how-to-only-allow-synchronous-validation |
| 52 | // TODO: https://github.com/bombshell-dev/clack/issues/92 |
| 53 | if (result instanceof Promise) { |
| 54 | throw new TypeError( |
| 55 | 'Schema validation must be synchronous. Update `validate()` and remove any asynchronous logic.' |
| 56 | ); |
| 57 | } |
| 58 | return result.issues?.at(0)?.message; |
| 59 | } |
| 60 | return validate(value); |
| 61 | } |
no test coverage detected