Has value¶
hasValue validates that an array or plain object contains a value that is deeply equal to the target value.
It performs a deep search through the collection (array or plain object) looking for any value that matches the target using deep equality. If the value is not a collection or doesn't contain the target, the rule emits a single validation event. Otherwise, it produces no validation output.
Signature¶
Through the API:
.hasValue(target: unknown)
And internally:
export const hasValue = (target: unknown): ValidationRule
(value: unknown, path: FieldPath) => Promise<ReadonlyArray<JaneEvent>>
Events¶
| Event code | Description |
|---|---|
object.has.missing-value |
Value is not an array or plain object |
value.not.found |
Target value not found in the collection |
Design rationale¶
- Provides deep value existence validation for collections.
- Works with both arrays and plain objects.
- Uses deep equality comparison for complex nested values.
- Searches recursively through nested collections.
- 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¶
hasValue 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 or plain object, emits
object.has.missing-value. - If the value is a collection but doesn't contain the target, emits
value.not.found. - If the value is a collection containing the target → returns an empty result set.
Examples¶
Valid array containing target¶
await hasValue("apple")(["banana", "apple", "cherry"], "$");
// → []
Valid object containing target¶
await hasValue(42)({ name: "John", age: 42 }, "$");
// → []
Collection missing target¶
await hasValue("grape")(["banana", "apple", "cherry"], "$");
// → [
// JaneEvent{
// kind: "error",
// code: "value.not.found",
// path: "$",
// ...
// }
// ]
Primitive value (invalid)¶
await hasValue("test")("hello", "$");
// → [
// JaneEvent{
// kind: "error",
// code: "object.has.missing-value",
// path: "$",
// ...
// }
// ]