MCPcopy Create free account
hub / github.com/TestSprite/testsprite-cli / requireEnum

Function requireEnum

src/lib/validate.ts:126–141  ·  view source on GitHub ↗
(
  field: string,
  value: unknown,
  accepted: readonly T[],
  opts: KindOpts = {},
)

Source from the content-addressed store, hash-verified

124 * @param opts.kind `'field'` (default) or `'flag'`.
125 */
126export 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

Callers 3

assertPlanStepsShapeFunction · 0.85
assertPlanShapeFunction · 0.85
validate.spec.tsFile · 0.85

Calls 1

localValidationErrorFunction · 0.70

Tested by

no test coverage detected