Array max items¶
arrayMaxItems validates that an array does not exceed a specified maximum number of items.
It enforces strict structural array validation and rejects any non‑array value or array whose length is greater than the configured limit. If the value is not an array or exceeds the maximum, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.arrayMaxItems(max)
And internally:
export const arrayMaxItems: (max: number) => ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
array.not.array |
Value is not structurally an array. |
array.too.long |
Array length exceeds the allowed maximum. |
Design rationale¶
- Enforces strict, predictable array size validation.
- Rejects non‑array values with a structural‑type diagnostic.
- Never coerces or normalizes — validation is explicit and opt‑in.
- Emits exactly one event per failure for clarity and composability.
- Async‑compatible and returns a readonly array of
JaneEventobjects.
Invoke¶
arrayMaxItems 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 greater than max, emits
array.too.long. - Otherwise, returns an empty result set.
Examples¶
Valid array length¶
const rule = arrayMaxItems(3);
await rule([1, 2, 3], "$");
// → []
Too many items¶
const rule = arrayMaxItems(2);
await rule([1, 2, 3], "$");
// → [
// JaneEvent{
// kind: "error",
// code: "array.too.long",
// path: "$",
// ...
// }
// ]
Non‑array value¶
const rule = arrayMaxItems(5);
await rule("not-an-array", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "array.not.array",
// path: "$",
// ...
// }
// ]