Object has many keys¶
objectHasManyKeys is a built‑in scan rule that detects objects whose number of own enumerable properties exceeds a conservative safety threshold.
When the value is a non‑array object and its key count is greater than 500, the rule emits a warn‑level object.has.many-keys scan event containing the observed count and the configured maximum. If the value is not an object or does not exceed the threshold, no events are emitted.
Signature¶
export const objectHasManyKeys: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]
Events¶
| Event code | Description |
|---|---|
object.has.many-keys |
Object contains more own keys than allowed. |
Design rationale¶
- Detects unusually wide objects that may indicate malformed payloads, accidental fan‑out, or adversarial input.
- Uses
Object.keys()to count own enumerable properties deterministically. - Emits a warning when the key count exceeds the conservative limit (500).
- Helps prevent memory pressure and downstream performance issues caused by extremely wide structures.
- Provides metadata (
{ count, maxKeys }) for policy and analysis. - Performs no mutation or restructuring of the input.
Invoke¶
objectHasManyKeys 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 value is not an object, objectHasManyKeys does not run and no key‑count detection occurs.
Examples¶
Many keys detected¶
const obj = Object.fromEntries(Array.from({ length: 600 }, (_, i) => [`k${i}`, i]));
const result = objectHasManyKeys(obj, "$");
// → [ JaneEvent{ kind: "warn", code: "object.has.many-keys", ... } ]
Object within safe key count¶
const result = objectHasManyKeys({ a: 1, b: 2 }, "$");
// → []
Non‑object or array value¶
const result = objectHasManyKeys([1, 2, 3], "$");
// → []