Array min items¶
arrayMinItems validates that an array contains at least a specified minimum number of items.
It enforces strict structural array validation and rejects any non‑array value or array whose length is smaller than the configured minimum. If the value is not an array or is too short, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.arrayMinItems(min)
And internally:
export const arrayMinItems: (min: number) => ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
array.not.array |
Value is not structurally an array. |
array.too.short |
Array length is less than the minimum. |
Design rationale¶
- Enforces predictable, explicit minimum‑length validation for arrays.
- Rejects non‑array values with a structural‑type diagnostic.
- Never coerces or normalizes — validation is strict and opt‑in.
- Emits exactly one event per failure for clarity and composability.
- Async‑compatible and returns a readonly array of
JaneEventobjects.
Invoke¶
arrayMinItems runs only when explicitly included in a boundary or pipeline. It does not run automatically.
The rule activates when:
- The value is any JavaScript value.
- If the value is not an array, emits
array.not.array. - If the value is an array whose length is less than min, emits
array.too.short. - Otherwise, returns an empty result set.
Examples¶
Valid array length¶
const rule = arrayMinItems(2);
await rule([1, 2], "$");
// → []
Too few items¶
const rule = arrayMinItems(3);
await rule([1], "$");
// → [
// JaneEvent{
// kind: "error",
// code: "array.too.short",
// path: "$",
// ...
// }
// ]
Non‑array value¶
const rule = arrayMinItems(1);
await rule("not-an-array", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "array.not.array",
// path: "$",
// ...
// }
// ]