EDlabsEDcheck

Several fields at once

One rule can look at two or more fields together, for example age and occupation.

Sometimes one field is not enough. “CEO” can be a valid job. “12 years old” can be a valid age. Together, they do not make sense.

That is what crossField is for. You declare which fields to look at, and you write a rule that talks about all of them.

Example: age and occupation

const PersonSemantic = edcheck.define(Person, {  rules: {    fullName: semantic("A plausible full name for a real person"),  },  crossField: [    {      paths: ["age", "occupation"],      rule: semantic({        intent: "The `occupation` is plausible for someone of the given `age`",        invalid: "The `occupation` needs more years than the `age` allows",        id: "occupation_age_coherence",      }),    },  ],});

Names in backticks

If intent, valid, or invalid mentions a field in backticks, that name must be in paths. If you mention a field you did not declare, define() throws EDcheckConfigError with the code unknown_reference.

Tokens with spaces or punctuation are ignored. They are not treated as fields.

One issue per field

If the rule fails or warns, EDcheck creates one issue for each path. The message is the same. Only path changes, so you can paint the error on both inputs.

Each issue also carries paths (every field in the rule) and the same ruleId. Your code can hide the duplicate if you want.

If a value is missing

If any of the fields is undefined or null, EDcheck skips that rule. It does not invent an error. Zod already handled it, or the field was optional.

You cannot put an array inside paths. define() rejects it.