Solid · Completion

Validation on completion (finalize)

With constraints: 'finalize' each constraint in the schema is validated once, against the completed value of its field. In the example the half-written booking string does not match its regex and no error is reported. seats is 6 where the schema allows at most 4, and that error is reported when the next key is named.

Stream
createStream({
  schema: z.object({
    booking: z.string().regex(/^B-\d{4}$/),
    seats: z.number().max(4),
    why: z.string(),
  }),
  initial: { booking: 'B-0000', seats: 1, why: '' },
  constraints: 'finalize',
})
Stream, chunk by chunk
Reply so far
{"booking":"B-20
booking, seats and errors
{ booking: 'B-20', seats: 1, errors: [] }
Output matches the expected value

Runs in this page on the installed package. The input and the expected output are defined by the example.