fix(deps): update dependency ajv to v7 (#4748)

This commit is contained in:
renovate[bot]
2020-12-23 15:39:26 +02:00
committed by GitHub
parent a18e4286f0
commit a3f95b0d24
4 changed files with 76 additions and 40 deletions

View File

@ -26,9 +26,9 @@
"license": "MIT",
"dependencies": {
"@iarna/toml": "2.2.5",
"ajv": "^6.10.0",
"ajv-errors": "^1.0.1",
"ajv-keywords": "^3.4.1",
"ajv": "^7.0.0",
"ajv-errors": "^2.0.0",
"ajv-keywords": "^4.0.0",
"connected-react-router": "^6.8.0",
"copy-text-to-clipboard": "^2.0.0",
"diacritics": "^1.3.0",

View File

@ -334,7 +334,9 @@ describe('config', () => {
],
}),
);
}).toThrowError("'search_fields' should be array\n'display_fields' should be array");
}).toThrowError(
"'collections[0].fields[1].fields[1].search_fields' should be array\n'collections[0].fields[1].fields[1].display_fields' should be array",
);
});
it('should not throw if nested relation display_fields and search_fields are arrays', () => {
@ -378,7 +380,7 @@ describe('config', () => {
it('should throw if collection meta is an empty object', () => {
expect(() => {
validateConfig(merge({}, validConfig, { collections: [{ meta: {} }] }));
}).toThrowError("'collections[0].meta' should NOT have fewer than 1 properties");
}).toThrowError("'collections[0].meta' should NOT have fewer than 1 items");
});
it('should throw if collection meta is an empty object', () => {
@ -475,7 +477,7 @@ describe('config', () => {
},
}),
);
}).toThrowError(`'i18n.locales[1]' should NOT be shorter than 2 characters`);
}).toThrowError(`'i18n.locales[1]' should NOT have fewer than 2 characters`);
});
it('should throw error when locale is more than 10 characters', () => {
@ -488,7 +490,7 @@ describe('config', () => {
},
}),
);
}).toThrowError(`'i18n.locales[1]' should NOT be longer than 10 characters`);
}).toThrowError(`'i18n.locales[1]' should NOT have more than 10 characters`);
});
it('should allow valid locales strings', () => {

View File

@ -4,10 +4,11 @@ import {
uniqueItemProperties,
instanceof as instanceOf,
prohibited,
} from 'ajv-keywords/keywords';
} from 'ajv-keywords/dist/keywords';
import ajvErrors from 'ajv-errors';
import { formatExtensions, frontmatterFormats, extensionFormatters } from 'Formats/formats';
import { getWidgets } from 'Lib/registry';
import uuid from 'uuid/v4';
import { I18N_STRUCTURE, I18N_FIELD } from '../lib/i18n';
const localeType = { type: 'string', minLength: 2, maxLength: 10, pattern: '^[a-zA-Z-_]+$' };
@ -42,38 +43,41 @@ const i18nField = {
/**
* Config for fields in both file and folder collections.
*/
const fieldsConfig = () => ({
$id: 'fields',
type: 'array',
minItems: 1,
items: {
// ------- Each field: -------
$id: 'field',
type: 'object',
properties: {
name: { type: 'string' },
label: { type: 'string' },
widget: { type: 'string' },
required: { type: 'boolean' },
i18n: i18nField,
hint: { type: 'string' },
pattern: {
type: 'array',
minItems: 2,
items: [{ oneOf: [{ type: 'string' }, { instanceof: 'RegExp' }] }, { type: 'string' }],
const fieldsConfig = () => {
const id = uuid();
return {
$id: `fields_${id}`,
type: 'array',
minItems: 1,
items: {
// ------- Each field: -------
$id: `field_${id}`,
type: 'object',
properties: {
name: { type: 'string' },
label: { type: 'string' },
widget: { type: 'string' },
required: { type: 'boolean' },
i18n: i18nField,
hint: { type: 'string' },
pattern: {
type: 'array',
minItems: 2,
items: [{ oneOf: [{ type: 'string' }, { instanceof: 'RegExp' }] }, { type: 'string' }],
},
field: { $ref: `field_${id}` },
fields: { $ref: `fields_${id}` },
types: { $ref: `fields_${id}` },
},
field: { $ref: 'field' },
fields: { $ref: 'fields' },
types: { $ref: 'fields' },
select: { $data: '0/widget' },
selectCases: {
...getWidgetSchemas(),
},
required: ['name'],
},
select: { $data: '0/widget' },
selectCases: {
...getWidgetSchemas(),
},
required: ['name'],
},
uniqueItemProperties: ['name'],
});
uniqueItemProperties: ['name'],
};
};
const viewFilters = {
type: 'array',
@ -347,7 +351,7 @@ class ConfigError extends Error {
* the config that is passed in.
*/
export function validateConfig(config) {
const ajv = new AJV({ allErrors: true, jsonPointers: true, $data: true });
const ajv = new AJV({ allErrors: true, jsonPointers: true, $data: true, strict: false });
uniqueItemProperties(ajv);
select(ajv);
instanceOf(ajv);