mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2026-01-04 20:14:52 +01:00
composer and npm
This commit is contained in:
207
conf/site/node_modules/schema-utils/dist/ValidationError.js
generated
vendored
207
conf/site/node_modules/schema-utils/dist/ValidationError.js
generated
vendored
@@ -5,7 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
||||
});
|
||||
exports.default = void 0;
|
||||
|
||||
const Range = require('./util/Range');
|
||||
const {
|
||||
stringHints,
|
||||
numberHints
|
||||
} = require('./util/hints');
|
||||
/** @typedef {import("json-schema").JSONSchema6} JSONSchema6 */
|
||||
|
||||
/** @typedef {import("json-schema").JSONSchema7} JSONSchema7 */
|
||||
@@ -191,6 +194,38 @@ function groupChildrenByFirstChild(children) {
|
||||
function indent(str, prefix) {
|
||||
return str.replace(/\n(?!$)/g, `\n${prefix}`);
|
||||
}
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @returns {schema is (Schema & {not: Schema})}
|
||||
*/
|
||||
|
||||
|
||||
function hasNotInSchema(schema) {
|
||||
return !!schema.not;
|
||||
}
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @return {Schema}
|
||||
*/
|
||||
|
||||
|
||||
function findFirstTypedSchema(schema) {
|
||||
if (hasNotInSchema(schema)) {
|
||||
return findFirstTypedSchema(schema.not);
|
||||
}
|
||||
|
||||
return schema;
|
||||
}
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @return {boolean}
|
||||
*/
|
||||
|
||||
|
||||
function canApplyNot(schema) {
|
||||
const typedSchema = findFirstTypedSchema(schema);
|
||||
return likeNumber(typedSchema) || likeInteger(typedSchema) || likeString(typedSchema) || likeNull(typedSchema) || likeBoolean(typedSchema);
|
||||
}
|
||||
/**
|
||||
* @param {any} maybeObj
|
||||
* @returns {boolean}
|
||||
@@ -219,7 +254,7 @@ function likeInteger(schema) {
|
||||
return schema.type === 'integer' || typeof schema.minimum !== 'undefined' || typeof schema.exclusiveMinimum !== 'undefined' || typeof schema.maximum !== 'undefined' || typeof schema.exclusiveMaximum !== 'undefined' || typeof schema.multipleOf !== 'undefined';
|
||||
}
|
||||
/**
|
||||
* @param {Schema & {formatMinimum?: string; formatMaximum?: string;}} schema
|
||||
* @param {Schema} schema
|
||||
* @returns {boolean}
|
||||
*/
|
||||
|
||||
@@ -307,48 +342,6 @@ function getSchemaNonTypes(schema) {
|
||||
|
||||
return '';
|
||||
}
|
||||
/**
|
||||
* @param {Schema=} schema
|
||||
* @returns {Array<string>}
|
||||
*/
|
||||
|
||||
|
||||
function numberHints(schema) {
|
||||
if (!schema) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const hints = [];
|
||||
const range = new Range();
|
||||
|
||||
if (typeof schema.minimum === 'number') {
|
||||
range.left(schema.minimum);
|
||||
}
|
||||
|
||||
if (typeof schema.exclusiveMinimum === 'number') {
|
||||
range.left(schema.exclusiveMinimum, true);
|
||||
}
|
||||
|
||||
if (typeof schema.maximum === 'number') {
|
||||
range.right(schema.maximum);
|
||||
}
|
||||
|
||||
if (typeof schema.exclusiveMaximum === 'number') {
|
||||
range.right(schema.exclusiveMaximum, true);
|
||||
}
|
||||
|
||||
const rangeFormat = range.format();
|
||||
|
||||
if (rangeFormat) {
|
||||
hints.push(rangeFormat);
|
||||
}
|
||||
|
||||
if (typeof schema.multipleOf === 'number') {
|
||||
hints.push(`should be multiple of ${schema.multipleOf}`);
|
||||
}
|
||||
|
||||
return hints;
|
||||
}
|
||||
/**
|
||||
* @param {Array<string>} hints
|
||||
* @returns {string}
|
||||
@@ -360,16 +353,19 @@ function formatHints(hints) {
|
||||
}
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @returns {string}
|
||||
* @param {boolean} logic
|
||||
* @returns {string[]}
|
||||
*/
|
||||
|
||||
|
||||
function getHints(schema) {
|
||||
function getHints(schema, logic) {
|
||||
if (likeNumber(schema) || likeInteger(schema)) {
|
||||
return formatHints(numberHints(schema));
|
||||
return numberHints(schema, logic);
|
||||
} else if (likeString(schema)) {
|
||||
return stringHints(schema, logic);
|
||||
}
|
||||
|
||||
return '';
|
||||
return [];
|
||||
}
|
||||
|
||||
class ValidationError extends Error {
|
||||
@@ -447,12 +443,15 @@ class ValidationError extends Error {
|
||||
}
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @param {boolean} logic
|
||||
* @param {Array<Object>} prevSchemas
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
formatSchema(schema, prevSchemas = []) {
|
||||
formatSchema(schema, logic = true, prevSchemas = []) {
|
||||
let newLogic = logic;
|
||||
|
||||
const formatInnerSchema =
|
||||
/**
|
||||
*
|
||||
@@ -462,18 +461,26 @@ class ValidationError extends Error {
|
||||
*/
|
||||
(innerSchema, addSelf) => {
|
||||
if (!addSelf) {
|
||||
return this.formatSchema(innerSchema, prevSchemas);
|
||||
return this.formatSchema(innerSchema, newLogic, prevSchemas);
|
||||
}
|
||||
|
||||
if (prevSchemas.includes(innerSchema)) {
|
||||
return '(recursive)';
|
||||
}
|
||||
|
||||
return this.formatSchema(innerSchema, prevSchemas.concat(schema));
|
||||
return this.formatSchema(innerSchema, newLogic, prevSchemas.concat(schema));
|
||||
};
|
||||
|
||||
if (schema.not && !likeObject(schema)) {
|
||||
return `non ${formatInnerSchema(schema.not)}`;
|
||||
if (hasNotInSchema(schema) && !likeObject(schema)) {
|
||||
if (canApplyNot(schema.not)) {
|
||||
newLogic = !logic;
|
||||
return formatInnerSchema(schema.not);
|
||||
}
|
||||
|
||||
const needApplyLogicHere = !schema.not.not;
|
||||
const prefix = logic ? '' : 'non ';
|
||||
newLogic = !logic;
|
||||
return needApplyLogicHere ? prefix + formatInnerSchema(schema.not) : formatInnerSchema(schema.not);
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -543,73 +550,24 @@ class ValidationError extends Error {
|
||||
}
|
||||
|
||||
if (likeNumber(schema) || likeInteger(schema)) {
|
||||
const type = schema.type === 'integer' ? 'integer' : 'number';
|
||||
const hints = getHints(schema);
|
||||
return `${type}${hints.length > 0 ? ` ${hints}` : ''}`;
|
||||
const [type, ...hints] = getHints(schema, logic);
|
||||
const str = `${type}${hints.length > 0 ? ` ${formatHints(hints)}` : ''}`;
|
||||
return logic ? str : hints.length > 0 ? `non-${type} | ${str}` : `non-${type}`;
|
||||
}
|
||||
|
||||
if (likeString(schema)) {
|
||||
let type = 'string';
|
||||
const hints = [];
|
||||
|
||||
if (typeof schema.minLength === 'number') {
|
||||
if (schema.minLength === 1) {
|
||||
type = 'non-empty string';
|
||||
} else if (schema.minLength !== 0) {
|
||||
/* if min length === 0 it does not make hint for user */
|
||||
const length = schema.minLength - 1;
|
||||
hints.push(`should be longer than ${length} character${length > 1 ? 's' : ''}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof schema.maxLength === 'number') {
|
||||
if (schema.maxLength === 0) {
|
||||
type = 'empty string';
|
||||
} else {
|
||||
hints.push(`should be shorter than ${schema.maxLength + 1} characters`);
|
||||
}
|
||||
}
|
||||
|
||||
if (schema.pattern) {
|
||||
hints.push(`should match pattern ${JSON.stringify(schema.pattern)}`);
|
||||
}
|
||||
|
||||
if (schema.format) {
|
||||
hints.push(`should match format ${JSON.stringify(schema.format)}`);
|
||||
}
|
||||
|
||||
if (
|
||||
/** @type {Schema & {formatMinimum?: string; formatExclusiveMinimum?: boolean;}} */
|
||||
schema.formatMinimum) {
|
||||
const {
|
||||
formatExclusiveMinimum,
|
||||
formatMinimum
|
||||
} =
|
||||
/** @type {Schema & {formatMinimum?: string; formatExclusiveMinimum?: boolean;}} */
|
||||
schema;
|
||||
hints.push(`should be ${formatExclusiveMinimum ? '>' : '>='} ${JSON.stringify(formatMinimum)}`);
|
||||
}
|
||||
|
||||
if (
|
||||
/** @type {Schema & {formatMaximum?: string; formatExclusiveMaximum?: boolean;}} */
|
||||
schema.formatMaximum) {
|
||||
const {
|
||||
formatExclusiveMaximum,
|
||||
formatMaximum
|
||||
} =
|
||||
/** @type {Schema & {formatMaximum?: string; formatExclusiveMaximum?: boolean;}} */
|
||||
schema;
|
||||
hints.push(`should be ${formatExclusiveMaximum ? '<' : '<='} ${JSON.stringify(formatMaximum)}`);
|
||||
}
|
||||
|
||||
return `${type}${hints.length > 0 ? ` (${hints.join(', ')})` : ''}`;
|
||||
const [type, ...hints] = getHints(schema, logic);
|
||||
const str = `${type}${hints.length > 0 ? ` ${formatHints(hints)}` : ''}`;
|
||||
return logic ? str : str === 'string' ? 'non-string' : `non-string | ${str}`;
|
||||
}
|
||||
|
||||
if (likeBoolean(schema)) {
|
||||
return 'boolean';
|
||||
return `${logic ? '' : 'non-'}boolean`;
|
||||
}
|
||||
|
||||
if (likeArray(schema)) {
|
||||
// not logic already applied in formatValidationError
|
||||
newLogic = true;
|
||||
const hints = [];
|
||||
|
||||
if (typeof schema.minItems === 'number') {
|
||||
@@ -658,6 +616,8 @@ class ValidationError extends Error {
|
||||
}
|
||||
|
||||
if (likeObject(schema)) {
|
||||
// not logic already applied in formatValidationError
|
||||
newLogic = true;
|
||||
const hints = [];
|
||||
|
||||
if (typeof schema.minProperties === 'number') {
|
||||
@@ -721,12 +681,14 @@ class ValidationError extends Error {
|
||||
}
|
||||
|
||||
if (likeNull(schema)) {
|
||||
return 'null';
|
||||
return `${logic ? '' : 'non-'}null`;
|
||||
}
|
||||
|
||||
if (Array.isArray(schema.type)) {
|
||||
// not logic already applied in formatValidationError
|
||||
return `${schema.type.join(' | ')}`;
|
||||
} // Fallback for unknown keywords
|
||||
// not logic already applied in formatValidationError
|
||||
|
||||
/* istanbul ignore next */
|
||||
|
||||
@@ -737,11 +699,12 @@ class ValidationError extends Error {
|
||||
* @param {Schema=} schemaPart
|
||||
* @param {(boolean | Array<string>)=} additionalPath
|
||||
* @param {boolean=} needDot
|
||||
* @param {boolean=} logic
|
||||
* @returns {string}
|
||||
*/
|
||||
|
||||
|
||||
getSchemaPartText(schemaPart, additionalPath, needDot = false) {
|
||||
getSchemaPartText(schemaPart, additionalPath, needDot = false, logic = true) {
|
||||
if (!schemaPart) {
|
||||
return '';
|
||||
}
|
||||
@@ -767,7 +730,7 @@ class ValidationError extends Error {
|
||||
schemaPart = this.getSchemaPart(schemaPart.$ref);
|
||||
}
|
||||
|
||||
let schemaText = `${this.formatSchema(schemaPart)}${needDot ? '.' : ''}`;
|
||||
let schemaText = `${this.formatSchema(schemaPart, logic)}${needDot ? '.' : ''}`;
|
||||
|
||||
if (schemaPart.description) {
|
||||
schemaText += `\n-> ${schemaPart.description}`;
|
||||
@@ -914,7 +877,9 @@ class ValidationError extends Error {
|
||||
} =
|
||||
/** @type {import("ajv").ComparisonParams} */
|
||||
params;
|
||||
const hints = numberHints(parentSchema);
|
||||
const [, ...hints] = getHints(
|
||||
/** @type {Schema} */
|
||||
parentSchema, true);
|
||||
|
||||
if (hints.length === 0) {
|
||||
hints.push(`should be ${comparison} ${limit}`);
|
||||
@@ -1020,7 +985,8 @@ class ValidationError extends Error {
|
||||
} =
|
||||
/** @type {import("ajv").LimitParams} */
|
||||
params;
|
||||
return `${dataPath} should be shorter than ${limit + 1} characters${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
|
||||
const max = limit + 1;
|
||||
return `${dataPath} should be shorter than ${max} character${max > 1 ? 's' : ''}${getSchemaNonTypes(parentSchema)}.${this.getSchemaPartDescription(parentSchema)}`;
|
||||
}
|
||||
|
||||
case 'maxItems':
|
||||
@@ -1181,6 +1147,15 @@ class ValidationError extends Error {
|
||||
|
||||
case 'not':
|
||||
{
|
||||
const postfix = likeObject(
|
||||
/** @type {Schema} */
|
||||
error.parentSchema) ? `\n${this.getSchemaPartText(error.parentSchema)}` : '';
|
||||
const schemaOutput = this.getSchemaPartText(error.schema, false, false, false);
|
||||
|
||||
if (canApplyNot(error.schema)) {
|
||||
return `${dataPath} should be any ${schemaOutput}${postfix}.`;
|
||||
}
|
||||
|
||||
const {
|
||||
schema,
|
||||
parentSchema
|
||||
|
||||
105
conf/site/node_modules/schema-utils/dist/util/hints.js
generated
vendored
Normal file
105
conf/site/node_modules/schema-utils/dist/util/hints.js
generated
vendored
Normal file
@@ -0,0 +1,105 @@
|
||||
"use strict";
|
||||
|
||||
const Range = require('./Range');
|
||||
/** @typedef {import("../validate").Schema} Schema */
|
||||
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @param {boolean} logic
|
||||
* @return {string[]}
|
||||
*/
|
||||
|
||||
|
||||
module.exports.stringHints = function stringHints(schema, logic) {
|
||||
const hints = [];
|
||||
let type = 'string';
|
||||
const currentSchema = { ...schema
|
||||
};
|
||||
|
||||
if (!logic) {
|
||||
const tmpLength = currentSchema.minLength;
|
||||
const tmpFormat = currentSchema.formatMinimum;
|
||||
const tmpExclusive = currentSchema.formatExclusiveMaximum;
|
||||
currentSchema.minLength = currentSchema.maxLength;
|
||||
currentSchema.maxLength = tmpLength;
|
||||
currentSchema.formatMinimum = currentSchema.formatMaximum;
|
||||
currentSchema.formatMaximum = tmpFormat;
|
||||
currentSchema.formatExclusiveMaximum = !currentSchema.formatExclusiveMinimum;
|
||||
currentSchema.formatExclusiveMinimum = !tmpExclusive;
|
||||
}
|
||||
|
||||
if (typeof currentSchema.minLength === 'number') {
|
||||
if (currentSchema.minLength === 1) {
|
||||
type = 'non-empty string';
|
||||
} else {
|
||||
const length = Math.max(currentSchema.minLength - 1, 0);
|
||||
hints.push(`should be longer than ${length} character${length > 1 ? 's' : ''}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof currentSchema.maxLength === 'number') {
|
||||
if (currentSchema.maxLength === 0) {
|
||||
type = 'empty string';
|
||||
} else {
|
||||
const length = currentSchema.maxLength + 1;
|
||||
hints.push(`should be shorter than ${length} character${length > 1 ? 's' : ''}`);
|
||||
}
|
||||
}
|
||||
|
||||
if (currentSchema.pattern) {
|
||||
hints.push(`should${logic ? '' : ' not'} match pattern ${JSON.stringify(currentSchema.pattern)}`);
|
||||
}
|
||||
|
||||
if (currentSchema.format) {
|
||||
hints.push(`should${logic ? '' : ' not'} match format ${JSON.stringify(currentSchema.format)}`);
|
||||
}
|
||||
|
||||
if (currentSchema.formatMinimum) {
|
||||
hints.push(`should be ${currentSchema.formatExclusiveMinimum ? '>' : '>='} ${JSON.stringify(currentSchema.formatMinimum)}`);
|
||||
}
|
||||
|
||||
if (currentSchema.formatMaximum) {
|
||||
hints.push(`should be ${currentSchema.formatExclusiveMaximum ? '<' : '<='} ${JSON.stringify(currentSchema.formatMaximum)}`);
|
||||
}
|
||||
|
||||
return [type].concat(hints);
|
||||
};
|
||||
/**
|
||||
* @param {Schema} schema
|
||||
* @param {boolean} logic
|
||||
* @return {string[]}
|
||||
*/
|
||||
|
||||
|
||||
module.exports.numberHints = function numberHints(schema, logic) {
|
||||
const hints = [schema.type === 'integer' ? 'integer' : 'number'];
|
||||
const range = new Range();
|
||||
|
||||
if (typeof schema.minimum === 'number') {
|
||||
range.left(schema.minimum);
|
||||
}
|
||||
|
||||
if (typeof schema.exclusiveMinimum === 'number') {
|
||||
range.left(schema.exclusiveMinimum, true);
|
||||
}
|
||||
|
||||
if (typeof schema.maximum === 'number') {
|
||||
range.right(schema.maximum);
|
||||
}
|
||||
|
||||
if (typeof schema.exclusiveMaximum === 'number') {
|
||||
range.right(schema.exclusiveMaximum, true);
|
||||
}
|
||||
|
||||
const rangeFormat = range.format(logic);
|
||||
|
||||
if (rangeFormat) {
|
||||
hints.push(rangeFormat);
|
||||
}
|
||||
|
||||
if (typeof schema.multipleOf === 'number') {
|
||||
hints.push(`should${logic ? '' : ' not'} be multiple of ${schema.multipleOf}`);
|
||||
}
|
||||
|
||||
return hints;
|
||||
};
|
||||
25
conf/site/node_modules/schema-utils/dist/validate.js
generated
vendored
25
conf/site/node_modules/schema-utils/dist/validate.js
generated
vendored
@@ -23,7 +23,15 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
||||
|
||||
/** @typedef {import("ajv").ErrorObject} ErrorObject */
|
||||
|
||||
/** @typedef {(JSONSchema4 | JSONSchema6 | JSONSchema7)} Schema */
|
||||
/**
|
||||
* @typedef {Object} Extend
|
||||
* @property {number=} formatMinimum
|
||||
* @property {number=} formatMaximum
|
||||
* @property {boolean=} formatExclusiveMinimum
|
||||
* @property {boolean=} formatExclusiveMaximum
|
||||
*/
|
||||
|
||||
/** @typedef {(JSONSchema4 | JSONSchema6 | JSONSchema7) & Extend} Schema */
|
||||
|
||||
/** @typedef {ErrorObject & { children?: Array<ErrorObject>}} SchemaUtilErrorObject */
|
||||
|
||||
@@ -59,7 +67,7 @@ function validate(schema, options, configuration) {
|
||||
let errors = [];
|
||||
|
||||
if (Array.isArray(options)) {
|
||||
errors = Array.from(options).map(nestedOptions => validateObject(schema, nestedOptions));
|
||||
errors = Array.from(options, nestedOptions => validateObject(schema, nestedOptions));
|
||||
errors.forEach((list, idx) => {
|
||||
const applyPrefix =
|
||||
/**
|
||||
@@ -76,7 +84,10 @@ function validate(schema, options, configuration) {
|
||||
|
||||
list.forEach(applyPrefix);
|
||||
});
|
||||
errors = errors.reduce((arr, items) => arr.concat(items), []);
|
||||
errors = errors.reduce((arr, items) => {
|
||||
arr.push(...items);
|
||||
return arr;
|
||||
}, []);
|
||||
} else {
|
||||
errors = validateObject(schema, options);
|
||||
}
|
||||
@@ -95,12 +106,8 @@ function validate(schema, options, configuration) {
|
||||
function validateObject(schema, options) {
|
||||
const compiledSchema = ajv.compile(schema);
|
||||
const valid = compiledSchema(options);
|
||||
|
||||
if (!compiledSchema.errors) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return valid ? [] : filterErrors(compiledSchema.errors);
|
||||
if (valid) return [];
|
||||
return compiledSchema.errors ? filterErrors(compiledSchema.errors) : [];
|
||||
}
|
||||
/**
|
||||
* @param {Array<ErrorObject>} errors
|
||||
|
||||
Reference in New Issue
Block a user