umpire
I’m going to try to keep this one shorter because I think the docs site I’ve put together does a better job of explaining the concept.
I’ve put together enough web forms and seen applications that end up in messy spaghetti logic trying to express relationships between states and felt the classic “there has to be a better way” and I think I may have landed on it.
The umpire tooling allows you to express relational effects to represent availability.
In code:
import { requires, umpire } from '@umpire/core'
const ump = umpire({
fields: {
password: {},
confirmPassword: {},
},
rules: [requires('confirmPassword', 'password')],
})
ump.check({ password: '', confirmPassword: '' }).confirmPassword
// { enabled: false, satisfied: false, fair: true, required: false, reason: 'requires password', reasons: ['requires password'] }
ump.check({ password: 'hunter2', confirmPassword: '' }).confirmPassword
// { enabled: true, satisfied: false, fair: true, required: false, reason: null, reasons: [] }
You can sort of do this with discriminated unions, but there are limitations. A unioned type represents legal end states, but doesn’t help you get from A to B. umpire helps you represent every legal path along the way, which is exactly where the user lives.
The same rules stretched across a checkout flow:
const checkout = umpire({
fields: {
shipping: {}, payment: {}, review: {}, giftWrap: {}, giftMessage: {},
},
rules: [
enabledWhen('payment', check('shipping', Boolean),
{ reason: 'Pick a shipping address first' }),
enabledWhen('review', check('payment', Boolean),
{ reason: 'Add a payment method first' }),
enabledWhen('giftMessage', check('giftWrap', Boolean),
{ reason: 'This order is not a gift' }),
],
})
// mid-checkout: shipping done, payment picked, gift note half-typed
checkout.check({ shipping: true, payment: true, review: '', giftWrap: true, giftMessage: 'Happy b' })
// review -> { enabled: true, satisfied: false, reason: null }
// giftMessage -> { enabled: true, reason: null }
// the user unchecks giftWrap after typing the note
checkout.play(before, after)
// [{ field: 'giftMessage', suggestedValue: undefined }]
In a conventional app you’d write “business logic” to clear the giftMessage field in a couple places and then forget about it during a refactor or migration and hit a bug case where now your database has a bunch of gift messages with no gift wrap for some reason.
The docs break down the full rule set — requires, any-of, disables, enabled-when — along with the availability concept and adapters for React, Solid, and Zustand. There’s also a bigger signup example with conditions and play() transitions.