MCPcopy
hub / github.com/bombshell-dev/clack / runValidation

Function runValidation

packages/core/src/utils/validation.ts:45–61  ·  view source on GitHub ↗
(
	validate: Validate<TValue>,
	value: TValue | undefined
)

Source from the content-addressed store, hash-verified

43 * @returns the validation result
44 */
45export 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}

Callers 3

validateFunction · 0.90
validateFunction · 0.90
onKeypressMethod · 0.85

Calls 1

validateFunction · 0.50

Tested by

no test coverage detected