Array is large¶
arrayIsLarge is a built‑in scan rule that detects arrays whose length exceeds a conservative safety threshold.
When the array’s length is greater than 10_000, the rule emits a warn‑level array.is.large scan event containing the observed length and the configured maximum. If the value is not an array or does not exceed the threshold, no events are emitted.
Signature¶
export const arrayIsLarge: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]
Events¶
| Event code | Description |
|---|---|
array.is.large |
Array length exceeded the safe size threshold. |
Design rationale¶
- Detects unusually large arrays that may indicate malformed or adversarial input.
- Uses a fixed conservative threshold (10,000) to prevent excessive memory usage during scanning.
- Emits a warning when the array length exceeds the threshold.
- Provides size metadata (
{ length, max }) for policy and analysis. - Performs no mutation or restructuring of the input.
Invoke¶
arrayIsLarge runs automatically whenever the scan stage is enabled.
Activation methods:
- Enable scan explicitly:
jane.value(input).scan(). - Use a mode that enables scan:
strict()enables scan by default.moderate()andlax()do not enable scan unless.scan()is called.- Enable scan with policy:
jane.value(input).withPolicy({ mode: 'strict' }).
If scan is not enabled or the structural type is not an array, arrayIsLarge does not run and no size detection occurs.
Examples¶
Large array detected¶
const result = arrayIsLarge(new Array(15000).fill(0), "$");
// → [ JaneEvent{ kind: "warn", code: "array.is.large", ... } ]
Array within safe size¶
const result = arrayIsLarge([1, 2, 3], "$");
// → []
Non‑array value¶
const result = arrayIsLarge("not an array", "$");
// → []