Function: validate()
ts
function validate(input, options): ValidateResult;Check a document received from a client before storing it. Never trust what the editor sends: a request can be crafted by hand.
The input is never mutated or passed through: the result is rebuilt from scratch using only what the schema allows.
Parameters
| Parameter | Type |
|---|---|
input | unknown |
options | ValidateOptions |
Returns
Example
ts
const result = validate(req.body.doc, { extensions })
if (!result.ok) return res.status(400).json(result.errors)
await db.save(result.doc)