Min keys¶
minKeys validates that a plain object contains at least a specified minimum number of own enumerable keys.
It performs a strict structural check ensuring the value is a plain object, then validates that it has at least the required number of keys. If the value is not a plain object or has too few keys, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.minKeys(minimum: number)
And internally:
export const minKeys = (minimum: number): ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
object.not.plain-object |
Value is not a JSON-compatible plain object |
object.too.few-keys |
Object contains fewer than the minimum required keys |
Design rationale¶
- Provides a strict, predictable minimum key count validation.
- First ensures the value is a plain object, then checks key count.
- Counts only own enumerable keys using
Object.keys(). - 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¶
minKeys 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 a plain object, emits
object.not.plain-object. - If the value is a plain object but has fewer than the minimum keys, emits
object.too.few-keys. - If the value is a plain object with at least the minimum keys → returns an empty result set.
Examples¶
Valid object with minimum keys¶
await minKeys(2)({ name: "John", age: 30, city: "NYC" }, "$");
// → []
Object with too few keys¶
await minKeys(2)({ name: "John" }, "$");
// → [
// JaneEvent{
// kind: "error",
// code: "object.too.few-keys",
// path: "$",
// ...
// }
// ]
Array (invalid)¶
await minKeys(2)([1, 2, 3], "$");
// → [
// JaneEvent{
// kind: "error",
// code: "object.not.plain-object",
// path: "$",
// ...
// }
// ]