Object is deep¶
objectIsDeep is a built‑in scan rule that detects objects whose nesting depth exceeds a conservative structural threshold.
It computes the maximum depth of the object using measureDepth. When the observed depth exceeds 50, the rule emits a warn‑level object.is.deep scan event containing the measured and allowed depth. If the value is not a non‑array object or does not exceed the threshold, no events are emitted.
Signature¶
export const objectIsDeep: ScanRule (raw: unknown, path: FieldPath) => JaneEvent[]
Events¶
| Event code | Description |
|---|---|
object.is.deep |
Object nesting depth exceeded safe threshold. |
Design rationale¶
- Detects deeply nested object structures that may cause stack pressure or pathological traversal costs.
- Uses
measureDepthto compute structural depth deterministically. - Emits a warning when the depth exceeds the conservative limit (50).
- Surfaces hazardous shapes early so containment can replace or constrain them.
- Provides metadata (
{ depth, max }) for policy and analysis. - Performs no mutation or restructuring of the input.
Invoke
objectIsDeep 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, objectIsDeep does not run and no depth detection occurs.
Examples¶
Deep object detected¶
const value = { a: { b: { c: { d: { e: {} } } } } }; // depth > 50 in real cases
const result = objectIsDeep(value, "$");
// → [ JaneEvent{ kind: "warn", code: "object.is.deep", ... } ]
Shallow object¶
const result = objectIsDeep({ a: { b: 1 } }, "$");
// → []
Non‑object or array value¶
const result = objectIsDeep([1, 2, 3], "$");
// → []