Skip to content

No null items

noNullItems validates that an array does not contain any null items.

It performs a strict structural array check and rejects any non‑array value. If the value is an array and contains at least one null element, the rule emits a single validation event. Otherwise, it produces no validation output.

Signature

Through the API:

.noNullItems()

And internally:

export const noNullItems: ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>

Events

Event code Description
array.not.array Value is not structurally an array.
array.has.null-items Array contains one or more null elements.

Design rationale

  • Enforces strict, predictable validation that disallows null entries.
  • Rejects non‑array values with a structural‑type diagnostic.
  • Uses direct equality (item === null) for clarity and zero ambiguity.
  • Emits exactly one event per failure for clarity and composability.
  • Never coerces, normalizes, or transforms — validation is explicit and opt‑in.
  • Async‑compatible and returns a readonly array of JaneEvent objects.

Invoke

noNullItems 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 and contains at least one null, emits array.has.null-items.
  • Otherwise, returns an empty result set.

Examples

Valid — no null items

await noNullItems([1, 2, 3], "$");
// → []

Invalid — contains null

await noNullItems([1, null, 3], "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "array.has.null-items",
//       path: "$",
//       ...
//     }
//   ]

Non‑array value

await noNullItems("not-an-array", "$");
// → [
//     JaneEvent{
//       kind: "error",
//       code: "array.not.array",
//       path: "$",
//       ...
//     }
//   ]