Skip to content

Commit

Permalink
feat: make ajv-cmd optional
Browse files Browse the repository at this point in the history
  • Loading branch information
willfarrell committed Sep 17, 2023
1 parent b9430a5 commit 7364d6a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
18 changes: 16 additions & 2 deletions packages/validator/transpile.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*
import compileSchema from 'ajv-cmd/compile'
import transpileFTL from 'ajv-cmd/ftl'
Expand All @@ -17,8 +18,8 @@ export const transpileSchema = (schema, ajvOptions) => {
}
export const transpileLocale = transpileFTL
*/

/*
import Ajv from 'ajv/dist/2020.js'
import ajvFormats from 'ajv-formats'
import ajvFormatsDraft2019 from 'ajv-formats-draft2019'
Expand Down Expand Up @@ -56,4 +57,17 @@ const compileSchema = (schema, options = {}) => {
}
// *** End `ajv-cmd/compile` *** //

*/
const ajvDefaults = {
strict: true,
coerceTypes: 'array', // important for query string params
allErrors: true,
useDefaults: 'empty',
messages: true // needs to be true to allow multi-locale errorMessage to work
}

// This is pulled out due to it's performance cost (50-100ms on cold start)
// Precompile your schema during a build step is recommended.
export const transpileSchema = (schema, ajvOptions) => {
const options = { ...ajvDefaults, ...ajvOptions }
return compileSchema(schema, options)
}
1 change: 1 addition & 0 deletions website/docs/upgrade/4-5.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ No change
### [validator](/docs/middlewares/validator)

- Use `preferredLanguage` from `context` instead of `event` (See http-content-negotiation).
- `ajv-cmd` is no longer a required dependency, if you're pre-transpiling you'll need to run `npm i ajv-cmd`.

### [warmup](/docs/middlewares/warmup)

Expand Down

0 comments on commit 7364d6a

Please sign in to comment.