UNPKG

jedison

Version:

JavaScript Library for JSON Validation and Editing

1 lines 512 kB
{"version":3,"file":"jedison.cjs","sources":["../../src/helpers/utils.js","../../src/helpers/schema.js","../../src/validation/constrains/allOf.js","../../src/validation/constrains/minLength.js","../../src/validation/constrains/anyOf.js","../../src/validation/constrains/enum.js","../../src/validation/constrains/exclusiveMaximum.js","../../src/validation/constrains/exclusiveMinimum.js","../../src/validation/constrains/format.js","../../src/validation/constrains/items.js","../../src/validation/constrains/maxItems.js","../../src/validation/constrains/maxLength.js","../../src/validation/constrains/maxProperties.js","../../src/validation/constrains/minimum.js","../../src/validation/constrains/minItems.js","../../src/validation/constrains/minProperties.js","../../src/validation/constrains/multipleOf.js","../../src/validation/constrains/not.js","../../src/validation/constrains/oneOf.js","../../src/validation/constrains/pattern.js","../../src/validation/constrains/patternProperties.js","../../src/validation/constrains/properties.js","../../src/validation/constrains/required.js","../../src/validation/constrains/type.js","../../src/validation/constrains/maximum.js","../../src/validation/constrains/uniqueItems.js","../../src/validation/constrains/additionalProperties.js","../../src/validation/drafts/draft-04.js","../../src/validation/constrains/const.js","../../src/validation/constrains/contains.js","../../src/validation/constrains/dependentRequired.js","../../src/validation/constrains/dependentSchemas.js","../../src/validation/constrains/if-then-else.js","../../src/validation/constrains/prefixItems.js","../../src/validation/drafts/draft-06.js","../../src/validation/drafts/draft-07.js","../../src/validation/constrains/unevaluatedProperties.js","../../src/validation/drafts/draft-2019-09.js","../../src/validation/drafts/draft-2020-12.js","../../src/validation/constrains/propertyNames.js","../../src/validation/validator.js","../../src/event-emitter.js","../../src/instances/instance.js","../../src/editors/editor.js","../../src/editors/if-then-else.js","../../src/instances/if-then-else.js","../../src/instances/multiple.js","../../src/instances/boolean.js","../../src/instances/object.js","../../src/instances/array.js","../../src/instances/string.js","../../src/instances/number.js","../../src/instances/null.js","../../src/themes/icons/icons.js","../../src/editors/boolean.js","../../src/editors/boolean-radios.js","../../src/editors/boolean-select.js","../../src/editors/boolean-checkbox.js","../../src/editors/string.js","../../src/editors/string-radios.js","../../src/editors/string-select.js","../../src/editors/string-textarea.js","../../src/editors/string-awesomplete.js","../../src/editors/string-emoji-button.js","../../src/editors/string-input.js","../../src/editors/number.js","../../src/editors/number-radios.js","../../src/editors/number-select.js","../../src/editors/number-input.js","../../src/editors/number-input-nullable.js","../../src/editors/object.js","../../src/editors/object-grid.js","../../src/editors/object-nav.js","../../src/editors/array.js","../../src/editors/array-table.js","../../src/editors/array-table-object.js","../../src/editors/array-choices.js","../../src/editors/array-nav.js","../../src/editors/multiple.js","../../src/editors/null.js","../../src/editors/string-simplemde.js","../../src/editors/string-quill.js","../../src/editors/string-jodit.js","../../src/editors/string-flatpickr.js","../../src/editors/string-imask.js","../../src/editors/number-imask.js","../../src/editors/number-raty.js","../../src/editors/array-checkboxes.js","../../src/editors/number-range.js","../../src/ui-resolver.js","../../src/i18n/default-translations.js","../../src/i18n/translations.js","../../src/i18n/translator.js","../../src/json-walker.js","../../src/jedison.js","../../src/themes/theme.js","../../src/index.js","../../src/themes/bootstrap3.js","../../src/themes/bootstrap4.js","../../src/themes/bootstrap5.js","../../src/ref-parser/ref-parser.js","../../src/schema-generator/schema-generator.js"],"sourcesContent":["/**\n * Utils.\n * @module utils\n */\n\n/**\n * Returns a clone of a thing\n * @param {*} thing - The thing to be cloned\n * @return {*} The clone of the thing\n */\nexport function clone (thing) {\n if (typeof thing === 'undefined') {\n return undefined\n }\n\n return JSON.parse(JSON.stringify(thing))\n}\n\n/**\n * Returns escaped regexp\n * @param {string} string - The string\n * @return {string} Escaped regexp\n */\nexport function escapeRegExp (string) {\n return string.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\$&') // $& means the whole matched string\n}\n\n/**\n * Multiple search and replace\n * @param {string} str - The string\n * @param {string} find - The part to be replaced\n * @param {string} replace - The replacement\n * @return {void}\n */\nexport function replaceAll (str, find, replace) {\n return str.replace(new RegExp(escapeRegExp(find), 'g'), replace)\n}\n\n/**\n * Formats a json path to be used as an html attribute value\n * @param {string} path - The json path\n * @return {string}\n */\nexport function pathToAttribute (path) {\n return replaceAll(replaceAll(path, '#', 'root'), '/', '-')\n}\n\n/**\n * Returns true if a given object has a given property\n * @param {object} obj - The object\n * @param {string} prop - The property\n * @return {boolean}\n */\nexport function hasOwn (obj, prop) {\n return Object.prototype.hasOwnProperty.call(obj, prop)\n}\n\n/**\n * Sort object properties\n * @param {object} obj - The object\n * @return {object}\n */\nexport function sortObject (obj) {\n return Object.keys(obj).sort().reduce((result, key) => {\n result[key] = obj[key]\n return result\n }, {})\n}\n\n/**\n * Returns true if the two values passed are equal\n * @param {*} a - Value A\n * @param {*} b - Value B\n * @return {boolean}\n */\nexport function equal (a, b) {\n if (isObject(a) && isObject(b)) {\n a = sortObject(a)\n b = sortObject(b)\n }\n return JSON.stringify(a) === JSON.stringify(b)\n}\n\n/**\n * Returns true if the two values passed are different\n * @param {*} a - Value A\n * @param {*} b - Value B\n * @return {boolean}\n */\nexport function different (a, b) {\n return !equal(a, b)\n}\n\n/**\n * Returns true if the value passed is null\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isNull (value) {\n return value === null\n}\n\n/**\n * Returns true if the value is defined\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isSet (value) {\n return typeof value !== 'undefined'\n}\n\n/**\n * Returns true if the value is undefined\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function notSet (value) {\n return typeof value === 'undefined'\n}\n\n/**\n * Returns true if the value passed is a number\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isNumber (value) {\n return typeof value === 'number'\n}\n\n/**\n * Returns true if the value passed is an integer\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isInteger (value) {\n return isNumber(value) && value === Math.floor(value)\n}\n\n/**\n * Returns true if the value passed is a string\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isString (value) {\n return typeof value === 'string'\n}\n\n/**\n * Returns true if the value passed is a boolean\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isBoolean (value) {\n return typeof value === 'boolean'\n}\n\n/**\n * Returns true if the value passed is an array\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isArray (value) {\n return Array.isArray(value)\n}\n\n/**\n * Returns true if the value passed is an object\n * @param {*} value - The value\n * @return {boolean}\n */\nexport function isObject (value) {\n return !isNull(value) && !isArray(value) && typeof value === 'object'\n}\n\n/**\n * Returns the type of a value\n * @param {*} value - The value\n * @return {string} The type of the value\n */\nexport function getType (value) {\n let type = 'any'\n\n if (isNumber(value)) {\n type = isInteger(value) ? 'integer' : 'number'\n } else if (isString(value)) {\n type = 'string'\n } else if (isBoolean(value)) {\n type = 'boolean'\n } else if (isArray(value)) {\n type = 'array'\n } else if (isNull(value)) {\n type = 'null'\n } else if (isObject(value)) {\n type = 'object'\n }\n\n return type\n}\n\n/**\n * Merges objects\n * @param {object} target - The target object\n * @param {object[]} sources - Objects to be merged into the target object\n * @return {object} The merged object\n */\nexport function mergeDeep (target, ...sources) {\n if (!sources.length) return target\n const source = sources.shift()\n\n if (isObject(target) && isObject(source)) {\n Object.keys(source).forEach((key) => {\n if (isObject(source[key])) {\n if (!target[key]) {\n Object.assign(target, {\n [key]: {}\n })\n }\n mergeDeep(target[key], source[key])\n } else {\n Object.assign(target, {\n [key]: source[key]\n })\n }\n })\n }\n return mergeDeep(target, ...sources)\n}\n\nexport function combineDeep (target, ...sources) {\n if (!sources.length) return target\n const source = sources.shift()\n\n if (Array.isArray(target) && Array.isArray(source)) {\n // Concatenate arrays instead of replacing them\n target.push(...source)\n } else if (isObject(target) && isObject(source)) {\n Object.keys(source).forEach((key) => {\n if (isObject(source[key])) {\n if (!target[key]) {\n Object.assign(target, {\n [key]: {}\n })\n }\n combineDeep(target[key], source[key])\n } else if (Array.isArray(source[key])) {\n // Handle array merging here\n if (!target[key]) {\n target[key] = []\n }\n target[key].push(...source[key])\n } else {\n Object.assign(target, {\n [key]: source[key]\n })\n }\n })\n }\n\n return combineDeep(target, ...sources)\n}\n\n/**\n * Merges objects but only the properties that exist in both objects\n * if they are the same type of value.\n * Handles nested objects recursively.\n * @param {object} obj1 - The target object\n * @param {object} obj2 - Object whose properties are the overrides\n * @return {object} The overwritten object\n */\nexport const overwriteExistingProperties = (obj1, obj2) => {\n Object.keys(obj2).forEach((key) => {\n if (key in obj1) {\n if (\n isSet(obj1[key]) &&\n isSet(obj2[key]) && (\n (isObject(obj1[key]) && isObject(obj2[key])) ||\n (isArray(obj1[key]) && isArray(obj2[key])) ||\n (isString(obj1[key]) && isString(obj2[key])) ||\n (isNumber(obj1[key]) && isNumber(obj2[key])) ||\n (isBoolean(obj1[key]) && isBoolean(obj2[key])) ||\n (isNull(obj1[key]) && isNull(obj2[key]))\n )\n ) {\n if (isObject(obj1[key]) && isObject(obj2[key])) {\n overwriteExistingProperties(obj1[key], obj2[key])\n } else {\n obj1[key] = obj2[key]\n }\n }\n }\n })\n\n return obj1\n}\n\n/**\n * Get some value by traversing the data using JSON path\n * @param {object} data - The data source\n * @param {string} path - JSON path\n * @return {*}\n */\nexport function getValueByJSONPath (data, path) {\n const keys = path.split('.') // Split the path into individual keys\n\n let value = data\n for (const key of keys) {\n if (Array.isArray(value) && /^\\d+$/.test(key)) {\n const index = parseInt(key)\n if (index >= 0 && index < value.length) {\n value = value[index]\n } else {\n return undefined // Index is out of bounds, return undefined\n }\n } else if (hasOwn(value, key)) {\n value = value[key]\n } else {\n return undefined // Key doesn't exist, return undefined\n }\n }\n\n return value\n}\n\n/**\n * Compiles a template by search and replace\n * @param {string} template - The template string\n * @param {object} data - Where template data lives\n * @return {string}\n */\nexport function compileTemplate (template, data) {\n return template.replace(/{{(.*?)}}/g, (match) => {\n match = match.replace(/\\s/g, '')\n const path = match.split(/{{|}}/)[1]\n return getValueByJSONPath(data, path)\n })\n}\n\nexport function clamp (number, min, max) {\n return Math.max(min, Math.min(number, max))\n}\n\nexport function removeDuplicatesFromArray (arr) {\n const uniqueObjects = []\n const uniqueValues = new Set()\n\n for (const obj of arr) {\n const objString = JSON.stringify(obj)\n if (!uniqueValues.has(objString)) {\n uniqueValues.add(objString)\n uniqueObjects.push(obj)\n }\n }\n\n return uniqueObjects\n}\n\nexport function generateRandomID (maxLength) {\n const chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'\n let randomID = ''\n for (let i = 0; i < maxLength; i++) {\n const randomIndex = Math.floor(Math.random() * chars.length)\n randomID += chars[randomIndex]\n }\n return randomID\n}\n\nexport default {\n clone,\n escapeRegExp,\n replaceAll,\n pathToAttribute,\n hasOwn,\n sortObject,\n equal,\n different,\n isNull,\n isSet,\n notSet,\n isNumber,\n isInteger,\n isString,\n isBoolean,\n isArray,\n isObject,\n getType,\n mergeDeep,\n combineDeep,\n overwriteExistingProperties,\n getValueByJSONPath,\n compileTemplate,\n clamp,\n removeDuplicatesFromArray,\n generateRandomID\n}\n","import { isString, isArray, isNumber, isInteger, isBoolean, isObject, isSet, clone } from './utils.js'\n\nexport function getSchemaX (schema, keyword) {\n const key = 'x-' + keyword\n return schema[key]\n}\n\nexport function getSchemaSchema (schema) {\n return isString(schema.$schema) ? clone(schema.$schema) : undefined\n}\n\nexport function getSchemaAdditionalProperties (schema) {\n return isObject(schema.additionalProperties) || isBoolean(schema.additionalProperties) ? clone(schema.additionalProperties) : undefined\n}\n\nexport function getSchemaPropertyNames (schema) {\n return isObject(schema.propertyNames) || isBoolean(schema.propertyNames) ? clone(schema.propertyNames) : undefined\n}\n\nexport function getSchemaAllOf (schema) {\n return isArray(schema.allOf) ? clone(schema.allOf) : undefined\n}\n\nexport function getSchemaAnyOf (schema) {\n return isArray(schema.anyOf) ? clone(schema.anyOf) : undefined\n}\n\nexport function getSchemaConst (schema) {\n return clone(schema.const)\n}\n\nexport function getSchemaContains (schema) {\n return (isObject(schema.contains) || isBoolean(schema.contains)) ? clone(schema.contains) : undefined\n}\n\nexport function getSchemaDefault (schema) {\n return clone(schema.default)\n}\n\nexport function getSchemaDependentRequired (schema) {\n return isObject(schema.dependentRequired) ? clone(schema.dependentRequired) : undefined\n}\n\nexport function getSchemaDependentSchemas (schema) {\n return isObject(schema.dependentSchemas) ? clone(schema.dependentSchemas) : undefined\n}\n\nexport function getSchemaDescription (schema) {\n return isString(schema.description) ? clone(schema.description) : undefined\n}\n\nexport function getSchemaElse (schema) {\n return (isObject(schema.else) || isBoolean(schema.else)) ? clone(schema.else) : undefined\n}\n\nexport function getSchemaEnum (schema) {\n if (isArray(schema.enum) && schema.enum.length > 0) {\n return clone(schema.enum)\n }\n\n return undefined\n}\n\nexport function getSchemaExclusiveMaximum (schema) {\n return isNumber(schema.exclusiveMaximum) ? clone(schema.exclusiveMaximum) : undefined\n}\n\nexport function getSchemaExclusiveMinimum (schema) {\n return isNumber(schema.exclusiveMinimum) ? schema.exclusiveMinimum : undefined\n}\n\nexport function getSchemaFormat (schema) {\n return isString(schema.format) ? clone(schema.format) : undefined\n}\n\nexport function getSchemaIf (schema) {\n if (isObject(schema.if)) {\n return clone(schema.if)\n }\n\n if (isBoolean(schema.if)) {\n return clone(schema.if)\n }\n\n return undefined\n}\n\nexport function getSchemaItems (schema) {\n return isObject(schema.items) || isBoolean(schema.items) ? clone(schema.items) : undefined\n}\n\nexport function getSchemaMaximum (schema) {\n return isNumber(schema.maximum) ? clone(schema.maximum) : undefined\n}\n\nexport function getSchemaMaxContains (schema) {\n if (isInteger(schema.maxContains) && schema.maxContains >= 0) {\n return clone(schema.maxContains)\n }\n\n return undefined\n}\n\nexport function getSchemaMaxItems (schema) {\n if (isInteger(schema.maxItems) && schema.maxItems >= 0) {\n return clone(schema.maxItems)\n }\n\n return undefined\n}\n\nexport function getSchemaMaxLength (schema) {\n if (isInteger(schema.maxLength) && schema.maxLength >= 0) {\n return clone(schema.maxLength)\n }\n\n return undefined\n}\n\nexport function getSchemaMaxProperties (schema) {\n if (isInteger(schema.maxProperties)) {\n return clone(schema.maxProperties)\n }\n\n return undefined\n}\n\nexport function getSchemaMinimum (schema) {\n return isNumber(schema.minimum) ? clone(schema.minimum) : undefined\n}\n\nexport function getSchemaMinContains (schema) {\n if (isInteger(schema.minContains) && schema.minContains >= 0) {\n return clone(schema.minContains)\n }\n\n return undefined\n}\n\nexport function getSchemaMinItems (schema) {\n if (isInteger(schema.minItems) && schema.minItems >= 0) {\n return clone(schema.minItems)\n }\n\n return undefined\n}\n\nexport function getSchemaMinLength (schema) {\n if (isInteger(schema.minLength) && schema.minLength >= 0) {\n return clone(schema.minLength)\n }\n\n return undefined\n}\n\nexport function getSchemaMinProperties (schema) {\n if (isInteger(schema.minProperties) && schema.minProperties >= 0) {\n return clone(schema.minProperties)\n }\n\n return undefined\n}\n\nexport function getSchemaMultipleOf (schema) {\n if (isNumber(schema.multipleOf) && schema.multipleOf >= 0) {\n return clone(schema.multipleOf)\n }\n\n return undefined\n}\n\nexport function getSchemaNot (schema) {\n return (isObject(schema.not) || isBoolean(schema.not)) ? clone(schema.not) : undefined\n}\n\nexport function getSchemaXOption (schema, option) {\n const xOption = 'x-' + option\n\n if (isSet(schema[xOption])) {\n return schema[xOption]\n }\n\n return (schema['x-options'] && isSet(schema['x-options'][option])) ? schema['x-options'][option] : undefined\n}\n\nexport function getSchemaPattern (schema) {\n return isString(schema.pattern) ? clone(schema.pattern) : undefined\n}\n\nexport function getSchemaPatternProperties (schema) {\n return isObject(schema.patternProperties) ? clone(schema.patternProperties) : undefined\n}\n\nexport function getSchemaPrefixItems (schema) {\n return isArray(schema.prefixItems) ? clone(schema.prefixItems) : undefined\n}\n\nexport function getSchemaProperties (schema) {\n return isObject(schema.properties) ? clone(schema.properties) : undefined\n}\n\nexport function getSchemaReadOnly (schema) {\n return isBoolean(schema.readOnly) ? clone(schema.readOnly) : undefined\n}\n\nexport function getSchemaRequired (schema) {\n return isArray(schema.required) ? [...new Set(schema.required)] : undefined\n}\n\nexport function getSchemaThen (schema) {\n return (isObject(schema.then) || isBoolean(schema.then)) ? clone(schema.then) : undefined\n}\n\nexport function getSchemaTitle (schema) {\n return isString(schema.title) ? clone(schema.title) : undefined\n}\n\nexport function getSchemaType (schema) {\n if (isString(schema.type) || isArray(schema.type)) {\n return clone(schema.type)\n }\n\n return undefined\n}\n\nexport function getSchemaOneOf (schema) {\n return isArray(schema.oneOf) ? clone(schema.oneOf) : undefined\n}\n\nexport function getSchemaUnevaluatedProperties (schema) {\n return isBoolean(schema.unevaluatedProperties) ? clone(schema.unevaluatedProperties) : undefined\n}\n\nexport function getSchemaUniqueItems (schema) {\n return isBoolean(schema.uniqueItems) ? clone(schema.uniqueItems) : undefined\n}\n\nexport default {\n getSchemaX,\n getSchemaSchema,\n getSchemaAdditionalProperties,\n getSchemaPropertyNames,\n getSchemaAllOf,\n getSchemaAnyOf,\n getSchemaConst,\n getSchemaContains,\n getSchemaDefault,\n getSchemaDependentRequired,\n getSchemaDependentSchemas,\n getSchemaDescription,\n getSchemaElse,\n getSchemaEnum,\n getSchemaExclusiveMaximum,\n getSchemaExclusiveMinimum,\n getSchemaFormat,\n getSchemaIf,\n getSchemaItems,\n getSchemaMaximum,\n getSchemaMaxContains,\n getSchemaMaxItems,\n getSchemaMaxLength,\n getSchemaMaxProperties,\n getSchemaMinimum,\n getSchemaMinContains,\n getSchemaMinItems,\n getSchemaMinLength,\n getSchemaMinProperties,\n getSchemaMultipleOf,\n getSchemaNot,\n getSchemaXOption,\n getSchemaPattern,\n getSchemaPatternProperties,\n getSchemaPrefixItems,\n getSchemaProperties,\n getSchemaReadOnly,\n getSchemaRequired,\n getSchemaThen,\n getSchemaTitle,\n getSchemaType,\n getSchemaOneOf,\n getSchemaUnevaluatedProperties,\n getSchemaUniqueItems\n}\n","import { isSet, removeDuplicatesFromArray } from '../../helpers/utils.js'\nimport Jedison from '../../jedison.js'\nimport { getSchemaAllOf } from '../../helpers/schema.js'\n\nexport function allOf (context) {\n// export function allOf (context) {\n let errors = []\n const allOf = getSchemaAllOf(context.schema)\n\n if (isSet(allOf)) {\n allOf.forEach((schema) => {\n const subSchemaEditor = new Jedison({ refParser: context.validator.refParser, schema, data: context.value, rootName: context.key })\n const subSchemaErrors = subSchemaEditor.getErrors()\n subSchemaEditor.destroy()\n\n subSchemaErrors.forEach((error) => {\n error.path = context.path\n })\n\n errors.push(...subSchemaErrors)\n })\n\n errors = removeDuplicatesFromArray(errors)\n }\n\n return errors\n}\n","import { compileTemplate, isSet, isString } from '../../helpers/utils.js'\nimport { getSchemaMinLength } from '../../helpers/schema.js'\n\nexport function minLength (context) {\n const errors = []\n const minLength = getSchemaMinLength(context.schema)\n\n if (isString(context.value) && isSet(minLength)) {\n context.value = context.value.replace(/[\\uDCA9]/g, '') // remove Unicode code points\n const invalid = (context.value.length < minLength)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'minLength',\n messages: [\n compileTemplate(context.translator.translate('errorMinLength'), {\n minLength: minLength\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import Jedison from '../../jedison.js'\nimport { isSet } from '../../helpers/utils.js'\nimport { getSchemaAnyOf } from '../../helpers/schema.js'\n\nexport function anyOf (context) {\n const errors = []\n const anyOf = getSchemaAnyOf(context.schema)\n\n if (isSet(anyOf)) {\n let valid = false\n\n anyOf.forEach((schema) => {\n const anyOfEditor = new Jedison({ refParser: context.validator.refParser, schema: schema, data: context.value })\n const anyOfErrors = anyOfEditor.getErrors()\n anyOfEditor.destroy()\n\n if (anyOfErrors.length === 0) {\n valid = true\n }\n })\n\n if (!valid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'anyOf',\n messages: [\n context.translator.translate('errorAnyOf')\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isSet } from '../../helpers/utils.js'\nimport { getSchemaEnum } from '../../helpers/schema.js'\n\nexport function _enum (context) {\n const errors = []\n const schemaEnum = getSchemaEnum(context.schema)\n\n if (isSet(schemaEnum)) {\n const invalid = !schemaEnum.some(e => JSON.stringify(context.value) === JSON.stringify(e))\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'enum',\n messages: [\n compileTemplate(context.translator.translate('errorEnum'), {\n enum: JSON.stringify(schemaEnum)\n })\n ]\n })\n }\n }\n return errors\n}\n","import { compileTemplate, isNumber, isSet } from '../../helpers/utils.js'\nimport { getSchemaExclusiveMaximum } from '../../helpers/schema.js'\n\nexport function exclusiveMaximum (context) {\n const errors = []\n const exclusiveMaximum = getSchemaExclusiveMaximum(context.schema)\n\n if (isNumber(context.value) && isSet(exclusiveMaximum)) {\n const invalid = (context.value >= exclusiveMaximum)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'exclusiveMaximum',\n messages: [\n compileTemplate(context.translator.translate('errorExclusiveMaximum'), {\n exclusiveMaximum: exclusiveMaximum\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isNumber, isSet } from '../../helpers/utils.js'\nimport { getSchemaExclusiveMinimum } from '../../helpers/schema.js'\n\nexport function exclusiveMinimum (context) {\n const errors = []\n const exclusiveMinimum = getSchemaExclusiveMinimum(context.schema)\n\n if (isNumber(context.value) && isSet(exclusiveMinimum)) {\n const invalid = (context.value <= exclusiveMinimum)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'exclusiveMinimum',\n messages: [\n compileTemplate(context.translator.translate('errorExclusiveMinimum'), {\n exclusiveMinimum: exclusiveMinimum\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isSet, isString } from '../../helpers/utils.js'\nimport { getSchemaFormat, getSchemaXOption } from '../../helpers/schema.js'\n\nexport function format (context) {\n const errors = []\n const format = getSchemaFormat(context.schema)\n let assertFormat = context.validator.assertFormat\n\n if (getSchemaXOption(context.schema, 'assertFormat')) {\n assertFormat = context.schema.options.assertFormat\n }\n\n if (isSet(format) && isString(context.value) && assertFormat) {\n let regexp\n\n if (format === 'email') {\n regexp = new RegExp(/^[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,}$/i)\n }\n\n if (format === 'url') {\n regexp = new RegExp(/^(?:https?|ftp):\\/\\/(?:[^\\s:@]+(?::[^\\s:@]*)?@)?(?:(?:[^\\s:@]+(?::[^\\s:@]*)?@)?(?:[^\\s:@](?:[^\\s:@-]*[^\\s:@])?\\.?)+[a-zA-Z]{2,}|(?:\\d{1,3}\\.){3}\\d{1,3})(?::\\d{2,5})?(?:\\/[^\\s]*)?$/i)\n }\n\n if (format === 'uuid') {\n regexp = new RegExp(/^(?:urn:uuid:)?[0-9a-fA-F]{8}-(?:[0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}$/i)\n }\n\n const invalid = isSet(regexp) && !regexp.test(context.value)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'format',\n messages: [\n compileTemplate(context.translator.translate('errorFormat'), { format: format })\n ]\n })\n }\n }\n\n return errors\n}\n","import { isArray, isSet } from '../../helpers/utils.js'\nimport { getSchemaItems, getSchemaPrefixItems } from '../../helpers/schema.js'\n\nexport function items (context) {\n const errors = []\n const items = getSchemaItems(context.schema)\n const prefixItems = getSchemaPrefixItems(context.schema)\n\n if (isArray(context.value) && isSet(items)) {\n const prefixItemsSchemasCount = isSet(prefixItems) ? prefixItems.length : 0\n\n if (items === false && context.value.length > 0 && context.value.length > prefixItemsSchemasCount) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'items',\n messages: [context.translator.translate('errorItems')]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isArray, isSet } from '../../helpers/utils.js'\nimport { getSchemaMaxItems } from '../../helpers/schema.js'\n\nexport function maxItems (context) {\n const errors = []\n const maxItems = getSchemaMaxItems(context.schema)\n\n if (isArray(context.value) && isSet(maxItems)) {\n const invalid = (context.value.length > maxItems)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'maxItems',\n messages: [\n compileTemplate(context.translator.translate('errorMaxItems'), {\n maxItems: maxItems\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isSet, isString } from '../../helpers/utils.js'\nimport { getSchemaMaxLength } from '../../helpers/schema.js'\n\nexport function maxLength (context) {\n const errors = []\n const maxLength = getSchemaMaxLength(context.schema)\n\n if (isString(context.value) && isSet(maxLength)) {\n context.value = context.value.replace(/[\\uDCA9]/g, '') // remove Unicode code points\n const invalid = (context.value.length > maxLength)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'maxLength',\n messages: [\n compileTemplate(context.translator.translate('errorMaxLength'), {\n maxLength: maxLength\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isObject, isSet } from '../../helpers/utils.js'\nimport { getSchemaMaxProperties } from '../../helpers/schema.js'\n\nexport function maxProperties (context) {\n const errors = []\n const maxProperties = getSchemaMaxProperties(context.schema)\n\n if (isObject(context.value) && isSet(maxProperties)) {\n const propertiesCount = Object.keys(context.value).length\n const invalid = (propertiesCount > maxProperties)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'maxProperties',\n messages: [\n compileTemplate(context.translator.translate('errorMaxProperties'), {\n maxProperties: maxProperties\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isNumber, isSet } from '../../helpers/utils.js'\nimport { getSchemaMinimum } from '../../helpers/schema.js'\n\nexport function minimum (context) {\n const errors = []\n const minimum = getSchemaMinimum(context.schema)\n\n if (isNumber(context.value) && isSet(minimum)) {\n const invalid = (context.value < minimum)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'minimum',\n messages: [\n compileTemplate(context.translator.translate('errorMinimum'), {\n minimum: minimum\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isArray, isSet } from '../../helpers/utils.js'\nimport { getSchemaMinItems } from '../../helpers/schema.js'\n\nexport function minItems (context) {\n const errors = []\n const minItems = getSchemaMinItems(context.schema)\n\n if (isArray(context.value) && isSet(minItems)) {\n const invalid = (context.value.length < minItems)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'minItems',\n messages: [\n compileTemplate(context.translator.translate('errorMinItems'), {\n minItems: minItems\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isObject, isSet } from '../../helpers/utils.js'\nimport { getSchemaMinProperties } from '../../helpers/schema.js'\n\nexport function minProperties (context) {\n const errors = []\n const minProperties = getSchemaMinProperties(context.schema)\n\n if (isObject(context.value) && isSet(minProperties)) {\n const propertiesCount = Object.keys(context.value).length\n const invalid = (propertiesCount < minProperties)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'minProperties',\n messages: [\n compileTemplate(context.translator.translate('errorMinProperties'), {\n minProperties: minProperties\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isNumber, isSet } from '../../helpers/utils.js'\nimport { getSchemaMultipleOf } from '../../helpers/schema.js'\n\nexport function multipleOf (context) {\n const errors = []\n const multipleOf = getSchemaMultipleOf(context.schema)\n\n if (isNumber(context.value) && isSet(multipleOf)) {\n if (context.value === 0) {\n return errors\n }\n\n const isMultipleOf = (context.value / multipleOf === Math.floor(context.value / multipleOf))\n const invalid = (!isMultipleOf || context.value.toString().includes('e'))\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'multipleOf',\n messages: [\n compileTemplate(context.translator.translate('errorMultipleOf'), {\n multipleOf: multipleOf\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isSet } from '../../helpers/utils.js'\nimport { getSchemaNot } from '../../helpers/schema.js'\n\nimport Jedison from '../../jedison.js'\n\nexport function not (context) {\n const errors = []\n const not = getSchemaNot(context.schema)\n\n if (isSet(not)) {\n const notEditor = new Jedison({ refParser: context.validator.refParser, schema: not, data: context.value })\n const notErrors = notEditor.getErrors()\n notEditor.destroy()\n\n const invalid = notErrors.length === 0\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'not',\n messages: [\n compileTemplate(context.translator.translate('errorNot'))\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isSet } from '../../helpers/utils.js'\nimport Jedison from '../../jedison.js'\nimport { getSchemaOneOf } from '../../helpers/schema.js'\n\nexport function oneOf (context) {\n const errors = []\n const oneOf = getSchemaOneOf(context.schema)\n\n if (isSet(oneOf)) {\n let counter = 0\n\n oneOf.forEach((schema) => {\n const oneOfEditor = new Jedison({ refParser: context.validator.refParser, schema: schema, data: context.value })\n const oneOfErrors = oneOfEditor.getErrors()\n oneOfEditor.destroy()\n\n if (oneOfErrors.length === 0) {\n counter++\n }\n })\n\n if (counter !== 1) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'oneOf',\n messages: [\n compileTemplate(context.translator.translate('errorOneOf'), {\n counter: counter\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isSet, isString } from '../../helpers/utils.js'\nimport { getSchemaPattern } from '../../helpers/schema.js'\n\nexport function pattern (context) {\n const errors = []\n const pattern = getSchemaPattern(context.schema)\n\n if (isString(context.value) && isSet(pattern)) {\n const regexp = new RegExp(pattern)\n const invalid = !regexp.test(context.value)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'pattern',\n messages: [\n compileTemplate(context.translator.translate('errorPattern'), {\n pattern: pattern\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { isObject, isSet } from '../../helpers/utils.js'\nimport Jedison from '../../jedison.js'\nimport { getSchemaPatternProperties } from '../../helpers/schema.js'\n\nexport function patternProperties (context) {\n let errors = []\n const patternProperties = getSchemaPatternProperties(context.schema)\n\n if (isObject(context.value) && isSet(patternProperties)) {\n Object.keys(context.value).forEach((propertyName) => {\n Object.keys(patternProperties).forEach((pattern) => {\n const regexp = new RegExp(pattern)\n if (regexp.test(propertyName)) {\n const schema = patternProperties[pattern]\n\n const editor = new Jedison({\n refParser: context.validator.refParser,\n schema: schema,\n data: context.value[propertyName]\n })\n\n const editorErrors = editor.getErrors().map((error) => {\n return {\n type: 'error',\n path: context.path + '/' + propertyName,\n constraint: 'patternProperties',\n messages: error.messages\n }\n })\n\n errors = [...errors, ...editorErrors]\n\n editor.destroy()\n }\n })\n })\n }\n\n return errors\n}\n","import { compileTemplate, hasOwn, isObject, isSet } from '../../helpers/utils.js'\nimport { getSchemaProperties } from '../../helpers/schema.js'\n\nexport function properties (context) {\n const schemaProperties = getSchemaProperties(context.schema)\n const invalidProperties = []\n\n if (isObject(context.value) && isSet(schemaProperties)) {\n Object.keys(schemaProperties).forEach((propertyName) => {\n if (hasOwn(context.value, propertyName)) {\n const propertySchema = schemaProperties[propertyName]\n\n const propertyErrors = context.validator.getErrors(\n context.value[propertyName],\n propertySchema,\n propertyName,\n context.path + '/' + propertyName\n )\n\n if (propertyErrors.length > 0) {\n invalidProperties.push(propertyName)\n }\n }\n })\n }\n\n if (invalidProperties.length > 0) {\n return [{\n type: 'error',\n path: context.path,\n constraint: 'properties',\n messages: [\n compileTemplate(context.translator.translate('errorProperties'), { properties: invalidProperties.join(', ') })\n ]\n }]\n }\n\n return []\n}\n","import { compileTemplate, isObject, isSet } from '../../helpers/utils.js'\nimport { getSchemaRequired } from '../../helpers/schema.js'\n\nexport function required (context) {\n const errors = []\n const required = getSchemaRequired(context.schema)\n\n if (isObject(context.value) && isSet(required)) {\n const missingProperties = []\n const keys = Object.keys(context.value)\n\n required.forEach((key) => {\n if (!keys.includes(key)) {\n missingProperties.push(key)\n }\n })\n\n const invalid = missingProperties.length > 0\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'required',\n messages: [\n compileTemplate(context.translator.translate('errorRequired'), {\n required: missingProperties.join(', ')\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import {\n compileTemplate, getType,\n isArray,\n isBoolean,\n isInteger,\n isNull,\n isNumber,\n isObject,\n isSet,\n isString\n} from '../../helpers/utils.js'\nimport { getSchemaType } from '../../helpers/schema.js'\n\nexport function type (context) {\n const errors = []\n const type = getSchemaType(context.schema)\n\n if (type === 'any') {\n return errors\n }\n\n if (isSet(type)) {\n const types = {\n string: value => isString(value),\n number: value => isNumber(value),\n integer: value => isInteger(value),\n boolean: value => isBoolean(value),\n array: value => isArray(value),\n object: value => isObject(value),\n null: value => isNull(value)\n }\n\n let valid = true\n\n if (isArray(type)) {\n valid = type.some((type) => {\n return types[type](context.value)\n })\n } else {\n valid = types[type](context.value)\n }\n\n if (!valid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'type',\n messages: [\n compileTemplate(context.translator.translate('errorType'), {\n type: type,\n valueType: getType(context.value)\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isNumber, isSet } from '../../helpers/utils.js'\nimport { getSchemaMaximum } from '../../helpers/schema.js'\n\nexport function maximum (context) {\n const errors = []\n const maximum = getSchemaMaximum(context.schema)\n\n if (isNumber(context.value) && isSet(maximum)) {\n const invalid = (context.value > maximum)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'maximum',\n messages: [\n compileTemplate(context.translator.translate('errorMaximum'), {\n maximum: maximum\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { isArray, isObject, isSet, sortObject } from '../../helpers/utils.js'\nimport { getSchemaUniqueItems } from '../../helpers/schema.js'\n\nexport function uniqueItems (context) {\n const errors = []\n const uniqueItems = getSchemaUniqueItems(context.schema)\n\n if (isArray(context.value) && isSet(uniqueItems) && uniqueItems === true) {\n const seen = []\n let hasDuplicatedItems = false\n\n for (let i = 0; i < context.value.length; i++) {\n let item = context.value[i]\n\n if (isObject(item)) {\n item = sortObject(item)\n }\n\n const itemStringified = JSON.stringify(item)\n hasDuplicatedItems = seen.some((seen) => seen === itemStringified)\n\n if (hasDuplicatedItems) {\n break\n } else {\n seen.push(itemStringified)\n }\n }\n\n const invalid = (hasDuplicatedItems)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'uniqueItems',\n messages: [\n context.translator.translate('errorUniqueItems')\n ]\n })\n }\n }\n\n return errors\n}\n","/**\n * Constrains additionalProperties\n */\n\nimport { compileTemplate, hasOwn, isObject, isSet } from '../../helpers/utils.js'\nimport Jedison from '../../jedison.js'\nimport { getSchemaAdditionalProperties, getSchemaPatternProperties, getSchemaProperties } from '../../helpers/schema.js'\n\nexport function additionalProperties (context) {\n const errors = []\n const schemaAdditionalProperties = getSchemaAdditionalProperties(context.schema)\n const schemaPatternProperties = getSchemaPatternProperties(context.schema)\n const schemaProperties = getSchemaProperties(context.schema)\n\n if (isObject(context.value) && isSet(schemaAdditionalProperties)) {\n const properties = schemaProperties || {}\n const additionalProperties = schemaAdditionalProperties\n const patternProperties = schemaPatternProperties || {}\n\n Object.keys(context.value).forEach((property) => {\n const definedInPatternProperty = Object.keys(patternProperties).some((pattern) => {\n const regexp = new RegExp(pattern)\n return regexp.test(property)\n })\n\n const isDefinedInProperties = hasOwn(properties, property)\n\n if (!definedInPatternProperty && !isDefinedInProperties) {\n if (additionalProperties === false) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'additionalProperties',\n messages: [\n compileTemplate(context.translator.translate('errorAdditionalProperties'), { property })\n ]\n })\n } else if (isObject(additionalProperties)) {\n const editor = new Jedison({\n refParser: context.validator.refParser,\n schema: additionalProperties,\n data: context.value[property]\n })\n\n const additionalPropertyErrors = editor.getErrors().map((error) => ({\n type: 'error',\n path: `${context.path}.${property}`,\n constraint: 'additionalProperties',\n messages: error.messages\n }))\n\n errors.push(...additionalPropertyErrors)\n editor.destroy()\n }\n }\n })\n }\n\n return errors\n}\n","import { allOf } from '../constrains/allOf.js'\nimport { minLength } from '../constrains/minLength.js'\nimport { anyOf } from '../constrains/anyOf.js'\nimport { _enum } from '../constrains/enum.js'\nimport { exclusiveMaximum } from '../constrains/exclusiveMaximum.js'\nimport { exclusiveMinimum } from '../constrains/exclusiveMinimum.js'\nimport { format } from '../constrains/format.js'\nimport { items } from '../constrains/items.js'\nimport { maxItems } from '../constrains/maxItems.js'\nimport { maxLength } from '../constrains/maxLength.js'\nimport { maxProperties } from '../constrains/maxProperties.js'\nimport { minimum } from '../constrains/minimum.js'\nimport { minItems } from '../constrains/minItems.js'\nimport { minProperties } from '../constrains/minProperties.js'\nimport { multipleOf } from '../constrains/multipleOf.js'\nimport { not } from '../constrains/not.js'\nimport { oneOf } from '../constrains/oneOf.js'\nimport { pattern } from '../constrains/pattern.js'\nimport { patternProperties } from '../constrains/patternProperties.js'\nimport { properties } from '../constrains/properties.js'\nimport { required } from '../constrains/required.js'\nimport { type } from '../constrains/type.js'\nimport { maximum } from '../constrains/maximum.js'\nimport { uniqueItems } from '../constrains/uniqueItems.js'\nimport { additionalProperties } from '../constrains/additionalProperties.js'\n\nexport default {\n additionalProperties: additionalProperties,\n allOf: allOf,\n anyOf: anyOf,\n enum: _enum,\n exclusiveMaximum: exclusiveMaximum,\n exclusiveMinimum: exclusiveMinimum,\n format: format,\n items: items,\n maximum: maximum,\n maxItems: maxItems,\n maxLength: maxLength,\n maxProperties: maxProperties,\n minimum: minimum,\n minItems: minItems,\n minLength: minLength,\n minProperties: minProperties,\n multipleOf: multipleOf,\n not: not,\n oneOf: oneOf,\n pattern: pattern,\n patternProperties: patternProperties,\n properties: properties,\n required: required,\n type: type,\n uniqueItems: uniqueItems\n}\n","import { isSet, different, compileTemplate } from '../../helpers/utils.js'\nimport { getSchemaConst } from '../../helpers/schema.js'\n\nexport function _const (context) {\n const errors = []\n const schemaConst = getSchemaConst(context.schema)\n\n if (isSet(schemaConst)) {\n const valueIsNotEqualConst = different(context.value, schemaConst)\n const invalid = (valueIsNotEqualConst)\n\n if (invalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'const',\n messages: [\n compileTemplate(context.translator.translate('errorConst'), {\n const: JSON.stringify(schemaConst)\n })\n ]\n })\n }\n }\n\n return errors\n}\n","import { compileTemplate, isArray, isSet } from '../../helpers/utils.js'\nimport Jedison from '../../jedison.js'\nimport { getSchemaContains, getSchemaMaxContains, getSchemaMinContains } from '../../helpers/schema.js'\n\nexport function contains (context) {\n const errors = []\n const contains = getSchemaContains(context.schema)\n const minContains = getSchemaMinContains(context.schema)\n const maxContains = getSchemaMaxContains(context.schema)\n\n if (isArray(context.value) && isSet(contains)) {\n let counter = 0\n\n context.value.forEach((item) => {\n const containsEditor = new Jedison({ refParser: context.validator.refParser, schema: contains, data: item })\n const containsErrors = containsEditor.getErrors()\n\n if (containsErrors.length === 0) {\n counter++\n }\n\n containsEditor.destroy()\n })\n\n const containsInvalid = (counter === 0)\n\n if (isSet(minContains)) {\n const minContainsInvalid = (counter < minContains)\n\n if (minContainsInvalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'minContains',\n messages: [\n compileTemplate(context.translator.translate('errorMinContains'), {\n counter: counter,\n minContains: minContains\n })\n ]\n })\n }\n } else {\n if (containsInvalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'contains',\n messages: [context.translator.translate('errorContains')]\n })\n }\n }\n\n if (isSet(maxContains)) {\n const maxContainsInvalid = (counter > maxContains)\n\n if (maxContainsInvalid) {\n errors.push({\n type: 'error',\n path: context.path,\n constraint: 'maxContains',\n messages: [\n compileTemplate(context.translator.translate('errorMaxContains'), {\n counter: counter,\n maxContains: maxContains\n })\n ]\n })\n }\n }\n }\n\n return errors\n}\n","import { compileTemplate, hasOwn, isObject, isSet } from '../../helpers/utils.js'\nimport { getSchemaDependentRequired } from '../../helpers/schema.js'\n\nexport function dependentRequired (context) {\n const errors = []\n const dependentRequired = getSchemaDependentRequired(context.schema)\n\n if (isObject(context.value) && isSet