Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: upgrade ajv to the latest version 7 release #40

Merged
merged 3 commits into from
Mar 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,6 @@ typings/

# next.js build output
.next

# ignore package lock
package-lock.json
31 changes: 26 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
'use strict'

const Ajv = require('ajv')
const ajv = new Ajv({ allErrors: true, removeAdditional: true, useDefaults: true, coerceTypes: true })
const Ajv = require('ajv').default

ajv.addKeyword('separator', {
const separator = {
type: 'string',
metaSchema: {
type: 'string',
Expand All @@ -13,9 +12,19 @@ ajv.addKeyword('separator', {
valid: true,
errors: false,
compile: (schema) => (data, dataPath, parentData, parentDataProperty) => {
parentData[parentDataProperty] = data === '' ? [] : data.split(schema)
// In some cases parentData and parentDataProperty will be undefined.
// We need to fall back to the dataPath object to provide those values.
if (parentData && parentDataProperty) {
parentData[parentDataProperty] = data === '' ? [] : data.split(schema)
} else {
const {
parentData: pData,
parentDataProperty: pDataProperty
} = dataPath
pData[pDataProperty] = data === '' ? [] : data.split(schema)
}
}
nigelhanlon marked this conversation as resolved.
Show resolved Hide resolved
})
}

const optsSchema = {
type: 'object',
Expand All @@ -34,6 +43,18 @@ const optsSchema = {
expandEnv: { type: ['boolean'], default: false }
}
}

const ajv = new Ajv({
allErrors: true,
removeAdditional: true,
useDefaults: true,
coerceTypes: true,
allowUnionTypes: true,
keywords: {
separator
}
})

const optsSchemaValidator = ajv.compile(optsSchema)

function loadAndValidateEnvironment (_opts) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"tsd": "^0.14.0"
},
"dependencies": {
"ajv": "^6.10.2",
"ajv": "^7.1.1",
"dotenv": "^8.2.0",
"dotenv-expand": "^5.1.0"
},
Expand Down