@atlassian/better-ajv-errors 3.0.1 → 3.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/dist/index.cjs +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -17,6 +17,11 @@ Main goal of this library is to provide relevant error messages like the followi
|
|
|
17
17
|
npm i better-ajv-errors
|
|
18
18
|
```
|
|
19
19
|
|
|
20
|
+
### Atlassian internal
|
|
21
|
+
```bash
|
|
22
|
+
npm i @atlassian/better-ajv-errors
|
|
23
|
+
```
|
|
24
|
+
|
|
20
25
|
Also install [ajv](https://www.npmjs.com/package/ajv), version 4.11.8 to 8, to validate data against JSON schemas. `better-ajv-errors` requires Node.js 22 or later.
|
|
21
26
|
|
|
22
27
|
## Usage
|
package/dist/index.cjs
CHANGED
|
@@ -287,7 +287,7 @@ var EnumValidationError = class extends BaseValidationError {
|
|
|
287
287
|
value,
|
|
288
288
|
weight: typeof value === "string" ? (0, leven.default)(value, currentValue.toString()) : Infinity
|
|
289
289
|
})).sort((x, y) => x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0)[0];
|
|
290
|
-
return allowedValues.length === 1 || bestMatch.weight < bestMatch.value.length ? bestMatch.value : null;
|
|
290
|
+
return allowedValues.length === 1 || typeof bestMatch.value === "string" && bestMatch.weight < bestMatch.value.length ? bestMatch.value : null;
|
|
291
291
|
}
|
|
292
292
|
};
|
|
293
293
|
//#endregion
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["styleText","tokenize","styleText","styleText","styleText","pointer","styleText","parse","prettify"],"sources":["../src/utils.js","../src/code-frame.js","../src/json/utils.js","../src/json/get-meta-from-path.js","../src/json/get-decorated-data-path.js","../src/validation-errors/base.js","../src/validation-errors/required.js","../src/validation-errors/additional-prop.js","../src/validation-errors/enum.js","../src/validation-errors/default.js","../src/helpers.js","../src/index.js"],"sourcesContent":["// Basic\nconst eq = x => y => x === y;\nconst not = fn => x => !fn(x);\n\nconst getValues = o => Object.values(o);\n\nexport const notUndefined = x => x !== undefined;\n\n// Error\nconst isXError = x => error => error.keyword === x;\nexport const isRequiredError = isXError('required');\nexport const isAnyOfError = isXError('anyOf');\nexport const isEnumError = isXError('enum');\nexport const getErrors = node =>\n node && node.errors\n ? node.errors.map(e =>\n e.keyword === 'errorMessage' ? { ...e.params.errors[0], message: e.message } : e\n )\n : [];\n\n// Node\nexport const getChildren = node => (node && getValues(node.children)) || [];\n\nexport const getSiblings = parent => node => getChildren(parent).filter(not(eq(node)));\n\nexport const concatAll = xs => ys => ys.reduce((zs, z) => zs.concat(z), xs);\n","import { styleText } from 'node:util';\nimport { tokenize } from '@humanwhocodes/momoa';\n\nconst LINES_ABOVE = 2;\nconst LINES_BELOW = 3;\n\n// The line breaks momoa counts, so that its line numbers index into the split source.\nconst NEWLINE = /\\r\\n|[\\r\\n]/;\n\nconst TOKEN_STYLES = {\n String: 'green',\n Number: 'magenta',\n Boolean: 'cyan',\n Null: 'cyan',\n Colon: 'yellow',\n Comma: 'yellow',\n};\n\nconst MARKER_STYLE = ['red', 'bold'];\n\n// The check `styleText` makes for the headings, so that the frame is colored along with them.\nconst supportsColor = () => styleText('red', '-') !== '-';\n\n/**\n * Renders the lines of `source` around `location`, with carets under the located text and\n * `message` after the last caret.\n *\n * Lines and columns are 1-based and `end` is exclusive, as in momoa's locations. Without\n * `end`, a single caret marks `start`.\n *\n * @param {string} source\n * @param {{ start: { line: number, column: number }, end?: { line: number, column: number } }} location\n * @param {{ message?: string, color?: boolean }} [options]\n * @return {string}\n */\nexport default function codeFrame(\n source,\n { start, end = start },\n { message, color = supportsColor() } = {}\n) {\n const paint = color\n ? (format, text) => styleText(format, text, { validateStream: false })\n : (_format, text) => text;\n\n const lines = source.split(NEWLINE);\n const markers = getMarkers(lines, start, end);\n const first = Math.max(start.line - LINES_ABOVE, 1);\n const last = Math.min(end.line + LINES_BELOW, lines.length);\n const width = String(last).length;\n\n const rows = [];\n for (let number = first; number <= last; number++) {\n const line = lines[number - 1];\n const gutter = ` ${String(number).padStart(width)} |`;\n const code = line.length > 0 ? ` ${color ? highlight(line, paint) : line}` : '';\n const marker = markers.get(number);\n if (!marker) {\n rows.push(` ${paint('gray', gutter)}${code}`);\n continue;\n }\n\n const [column, count] = marker;\n const spacing = line.slice(0, column - 1).replace(/[^\\t]/g, ' ');\n let caretRow = ` ${paint('gray', gutter.replace(/\\d/g, ' '))} ${spacing}${paint(MARKER_STYLE, '^'.repeat(count))}`;\n if (message && number === end.line) {\n caretRow += ` ${paint(MARKER_STYLE, message)}`;\n }\n rows.push(`${paint(MARKER_STYLE, '>')}${paint('gray', gutter)}${code}`, caretRow);\n }\n\n return rows.join('\\n');\n}\n\n// Maps each marked line number to the column of its first caret and the number of carets.\nfunction getMarkers(lines, start, end) {\n const markers = new Map();\n if (start.line === end.line) {\n markers.set(start.line, [start.column, Math.max(end.column - start.column, 1)]);\n return markers;\n }\n\n markers.set(start.line, [start.column, lines[start.line - 1].length - start.column + 1]);\n for (let number = start.line + 1; number < end.line; number++) {\n markers.set(number, [1, Math.max(lines[number - 1].length, 1)]);\n }\n markers.set(end.line, [1, end.column - 1]);\n return markers;\n}\n\n// JSON strings can't contain raw line breaks, so each line holds whole tokens.\nfunction highlight(line, paint) {\n let output = '';\n let offset = 0;\n for (const { type, loc } of tokenize(line)) {\n const style = TOKEN_STYLES[type];\n if (style) {\n output +=\n line.slice(offset, loc.start.offset) +\n paint(style, line.slice(loc.start.offset, loc.end.offset));\n offset = loc.end.offset;\n }\n }\n return output + line.slice(offset);\n}\n","// TODO: Better error handling\nexport const getPointers = dataPath => {\n return dataPath\n .split('/')\n .slice(1)\n .map(pointer => pointer.split('~1').join('/').split('~0').join('~'));\n};\n","import { getPointers } from './utils';\n\nexport default function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {\n const pointers = getPointers(dataPath);\n const lastPointerIndex = pointers.length - 1;\n return pointers.reduce((obj, pointer, idx) => {\n switch (obj.type) {\n case 'Object': {\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n\n const { name, value } = member;\n return includeIdentifierLocation && idx === lastPointerIndex ? name : value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n return element && element.value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n}\n","import { getPointers } from './utils';\n\nexport default function getDecoratedDataPath(jsonAst, dataPath) {\n let decoratedPath = '';\n getPointers(dataPath).reduce((obj, pointer) => {\n switch (obj.type) {\n case 'Object': {\n decoratedPath += `/${pointer}`;\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n return member.value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n const value = element && element.value;\n decoratedPath += `/${pointer}${getTypeName(value)}`;\n return value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n return decoratedPath;\n}\n\nfunction getTypeName(obj) {\n if (!obj || !obj.elements) {\n return '';\n }\n const type = obj.elements.filter(child => child && child.name && child.name.value === 'type');\n\n if (!type.length) {\n return '';\n }\n\n return (type[0].value && `:${type[0].value.value}`) || '';\n}\n","import codeFrame from '../code-frame';\nimport { getMetaFromPath, getDecoratedDataPath } from '../json/index';\n\nexport default class BaseValidationError {\n constructor(options = { isIdentifierLocation: false }, { data, schema, jsonAst, jsonRaw }) {\n this.options = options;\n this.data = data;\n this.schema = schema;\n this.jsonAst = jsonAst;\n this.jsonRaw = jsonRaw;\n }\n\n getLocation(dataPath = this.instancePath) {\n const { isIdentifierLocation, isSkipEndLocation } = this.options;\n const { loc } = getMetaFromPath(this.jsonAst, dataPath, isIdentifierLocation);\n return {\n start: loc.start,\n end: isSkipEndLocation ? undefined : loc.end,\n };\n }\n\n getDecoratedPath(dataPath = this.instancePath) {\n const decoratedPath = getDecoratedDataPath(this.jsonAst, dataPath);\n return decoratedPath;\n }\n\n // The decorated path is empty at the root, where the message stands alone.\n withDecoratedPath(message, separator = ' ') {\n const decoratedPath = this.getDecoratedPath();\n return decoratedPath ? `${decoratedPath}${separator}${message}` : message;\n }\n\n getCodeFrame(message, dataPath = this.instancePath) {\n return codeFrame(this.jsonRaw, this.getLocation(dataPath), { message });\n }\n\n /**\n * @return {string}\n */\n get instancePath() {\n return typeof this.options.instancePath !== 'undefined'\n ? this.options.instancePath\n : this.options.dataPath;\n }\n\n print() {\n throw new Error(`Implement the 'print' method inside ${this.constructor.name}!`);\n }\n\n getError() {\n throw new Error(`Implement the 'getError' method inside ${this.constructor.name}!`);\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class RequiredValidationError extends BaseValidationError {\n getLocation(dataPath = this.instancePath) {\n const { start } = super.getLocation(dataPath);\n return { start };\n }\n\n print() {\n const { message, params } = this.options;\n const output = [styleText('red', styleText('bold', 'REQUIRED') + ' ' + message) + '\\n'];\n\n return output.concat(\n this.getCodeFrame(\n '☹️ ' + styleText('magentaBright', params.missingProperty) + ' is missing here!'\n )\n );\n }\n\n getError() {\n const { message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(message),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class AdditionalPropValidationError extends BaseValidationError {\n constructor(...args) {\n super(...args);\n this.options.isIdentifierLocation = true;\n }\n\n print() {\n const { message, params } = this.options;\n const output = [\n styleText('red', styleText('bold', 'ADDITIONAL PROPERTY') + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame(\n '😲 ' +\n styleText('magentaBright', params.additionalProperty) +\n ' is not expected to be here!',\n `${this.instancePath}/${params.additionalProperty}`\n )\n );\n }\n\n getError() {\n const { params } = this.options;\n\n return {\n ...this.getLocation(`${this.instancePath}/${params.additionalProperty}`),\n error: this.withDecoratedPath(\n `Property ${params.additionalProperty} is not expected to be here`\n ),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport leven from 'leven';\nimport pointer from 'jsonpointer';\nimport BaseValidationError from './base';\n\nexport default class EnumValidationError extends BaseValidationError {\n print() {\n const {\n message,\n params: { allowedValues },\n } = this.options;\n const bestMatch = this.findBestMatch();\n\n // Needed to handle nullable enums, as joining on null just prints \", \"\n const [firstValue, ...rest] = allowedValues;\n const allowedValuesMessage = rest.reduce((acc, value) => `${acc}, ${value}`, firstValue || '');\n\n const output = [\n styleText('red', styleText('bold', 'ENUM') + ' ' + message),\n styleText('red', `(${allowedValuesMessage})\\n`),\n ];\n\n return output.concat(\n this.getCodeFrame(\n bestMatch !== null\n ? '👈🏽 Did you mean ' + styleText('magentaBright', String(bestMatch)) + ' here?'\n : '👈🏽 Unexpected value, should be equal to one of the allowed values'\n )\n );\n }\n\n getError() {\n const { message, params } = this.options;\n const bestMatch = this.findBestMatch();\n const allowedValues = params.allowedValues.join(', ');\n\n const output = {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${message}: ${allowedValues}`),\n path: this.instancePath,\n };\n\n if (bestMatch !== null) {\n output.suggestion = `Did you mean ${bestMatch}?`;\n }\n\n return output;\n }\n\n findBestMatch() {\n const {\n params: { allowedValues },\n } = this.options;\n\n const currentValue =\n this.instancePath === '' ? this.data : pointer.get(this.data, this.instancePath);\n\n if (!currentValue) {\n return null;\n }\n\n const bestMatch = allowedValues\n .map(value => ({\n value,\n // leven compares strings, so other allowed values cannot be a close match.\n weight: typeof value === 'string' ? leven(value, currentValue.toString()) : Infinity,\n }))\n .sort((x, y) => (x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0))[0];\n\n return allowedValues.length === 1 || bestMatch.weight < bestMatch.value.length\n ? bestMatch.value\n : null;\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class DefaultValidationError extends BaseValidationError {\n print() {\n const { keyword, message } = this.options;\n const output = [\n styleText('red', styleText('bold', keyword.toUpperCase()) + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame('👈🏽 ' + styleText('magentaBright', keyword) + ' ' + message)\n );\n }\n\n getError() {\n const { keyword, message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${keyword} ${message}`, ': '),\n path: this.instancePath,\n };\n }\n}\n","import {\n getChildren,\n getErrors,\n getSiblings,\n isAnyOfError,\n isEnumError,\n isRequiredError,\n concatAll,\n notUndefined,\n} from './utils';\nimport {\n AdditionalPropValidationError,\n RequiredValidationError,\n EnumValidationError,\n DefaultValidationError,\n} from './validation-errors/index';\n\nconst JSON_POINTERS_REGEX = /\\/[\\w_-]+(\\/\\d+)?/g;\n\n// Make a tree of errors from ajv errors array\nexport function makeTree(ajvErrors = []) {\n const root = { children: {} };\n ajvErrors.forEach(ajvError => {\n const instancePath =\n typeof ajvError.instancePath !== 'undefined' ? ajvError.instancePath : ajvError.dataPath;\n\n // `dataPath === ''` is root\n const paths = instancePath === '' ? [''] : instancePath.match(JSON_POINTERS_REGEX);\n if (paths) {\n paths.reduce((obj, path, i) => {\n obj.children[path] = obj.children[path] || { children: {}, errors: [] };\n if (i === paths.length - 1) {\n obj.children[path].errors.push(ajvError);\n }\n return obj.children[path];\n }, root);\n }\n });\n return root;\n}\n\nexport function filterRedundantErrors(root, parent, key) {\n /**\n * Partition out the errors by kind for ease of proceessing\n */\n const { anyOfErrors, enumErrors, requiredErrors } = getErrors(root).reduce(\n (acc, error) => {\n if (isRequiredError(error)) {\n acc.requiredErrors.push(error);\n\n return acc;\n }\n\n if (isAnyOfError(error)) {\n acc.anyOfErrors.push(error);\n }\n\n if (isEnumError(error)) {\n acc.enumErrors.push(error);\n }\n\n return acc;\n },\n { anyOfErrors: [], enumErrors: [], requiredErrors: [] }\n );\n\n /**\n * If there is are `required` errors then we can just drop every non-required error.\n * And, also `required` should have more priority than `anyOf`. @see #8\n */\n\n if (requiredErrors.length > 0) {\n root.errors = requiredErrors;\n root.children = {};\n\n // No need for further processing, as we've emptied out children\n return;\n }\n\n /**\n * If there is an `anyOf` error that means we have more meaningful errors\n * inside children. So we will just remove all errors from this level.\n *\n * If there are no children, then we don't delete the errors since we should\n * have at least one error to report.\n */\n if (anyOfErrors.length > 0 && Object.keys(root.children).length > 0) {\n delete root.errors;\n }\n\n /**\n * If all errors are `enum` and siblings have any error then we can safely\n * ignore the node. As we return early if there's required errors, we only\n * need to check anyofErrors length\n *\n * **CAUTION**\n * Need explicit `root.errors` check because `[].every(fn) === true`\n * https://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics\n */\n if (enumErrors.length > 0 && anyOfErrors.length === 0) {\n if (\n getSiblings(parent)(root)\n // Remove any reference which becomes `undefined` later\n .filter(notUndefined)\n .some(getErrors)\n ) {\n delete parent.children[key];\n }\n }\n\n Object.entries(root.children).forEach(([key, child]) => filterRedundantErrors(child, root, key));\n}\n\nexport function createErrorInstances(root, options) {\n const errors = getErrors(root);\n if (errors.length && errors.every(isEnumError)) {\n const uniqueValues = new Set(concatAll([])(errors.map(e => e.params.allowedValues)));\n const allowedValues = [...uniqueValues];\n const error = errors[0];\n return [\n new EnumValidationError(\n {\n ...error,\n params: { allowedValues },\n },\n options\n ),\n ];\n } else {\n return concatAll(\n errors.reduce((ret, error) => {\n switch (error.keyword) {\n case 'additionalProperties':\n return ret.concat(new AdditionalPropValidationError(error, options));\n case 'required':\n return ret.concat(new RequiredValidationError(error, options));\n default:\n return ret.concat(new DefaultValidationError(error, options));\n }\n }, [])\n )(getChildren(root).map(child => createErrorInstances(child, options)));\n }\n}\n\nexport default (ajvErrors, options) => {\n const tree = makeTree(ajvErrors || []);\n filterRedundantErrors(tree);\n return createErrorInstances(tree, options);\n};\n","import { parse } from '@humanwhocodes/momoa';\nimport prettify from './helpers';\n\nexport default (schema, data, errors, options = {}) => {\n const { format = 'cli', indent = null, json = null } = options;\n\n const jsonRaw = json || JSON.stringify(data, null, indent);\n const jsonAst = parse(jsonRaw);\n\n const customErrorToText = error => error.print().join('\\n');\n const customErrorToStructure = error => error.getError();\n const customErrors = prettify(errors, {\n data,\n schema,\n jsonAst,\n jsonRaw,\n });\n\n if (format === 'cli') {\n return customErrors.map(customErrorToText).join('\\n\\n');\n } else {\n return customErrors.map(customErrorToStructure);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,MAAM,MAAK,OAAK,MAAK,MAAM;AAC3B,MAAM,OAAM,QAAM,MAAK,CAAC,GAAG,CAAC;AAE5B,MAAM,aAAY,MAAK,OAAO,OAAO,CAAC;AAEtC,MAAa,gBAAe,MAAK,MAAM,KAAA;AAGvC,MAAM,YAAW,OAAK,UAAS,MAAM,YAAY;AACjD,MAAa,kBAAkB,SAAS,UAAU;AAClD,MAAa,eAAe,SAAS,OAAO;AAC5C,MAAa,cAAc,SAAS,MAAM;AAC1C,MAAa,aAAY,SACvB,QAAQ,KAAK,SACT,KAAK,OAAO,KAAI,MACd,EAAE,YAAY,iBAAiB;CAAE,GAAG,EAAE,OAAO,OAAO;CAAI,SAAS,EAAE;AAAQ,IAAI,CACjF,IACA,CAAC;AAGP,MAAa,eAAc,SAAS,QAAQ,UAAU,KAAK,QAAQ,KAAM,CAAC;AAE1E,MAAa,eAAc,YAAU,SAAQ,YAAY,MAAM,CAAC,CAAC,OAAO,IAAI,GAAG,IAAI,CAAC,CAAC;AAErF,MAAa,aAAY,QAAM,OAAM,GAAG,QAAQ,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;;;ACtB1E,MAAM,cAAc;AACpB,MAAM,cAAc;AAGpB,MAAM,UAAU;AAEhB,MAAM,eAAe;CACnB,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,MAAM;CACN,OAAO;C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5B,QAAQ,MAAM,SAAd;GACE,KAAK,wBACH,OAAO,IAAI,OAAO,IAAI,8BAA8B,OAAO,OAAO,CAAC;GACrE,KAAK,YACH,OAAO,IAAI,OAAO,IAAI,wBAAwB,OAAO,OAAO,CAAC;GAC/D,SACE,OAAO,IAAI,OAAO,IAAI,uBAAuB,OAAO,OAAO,CAAC;EAChE;CACF,GAAG,CAAC,CAAC,CACP,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,KAAI,UAAS,qBAAqB,OAAO,OAAO,CAAC,CAAC;AAE1E;AAEA,IAAA,mBAAgB,WAAW,YAAY;CACrC,MAAM,OAAO,SAAS,aAAa,CAAC,CAAC;CACrC,sBAAsB,IAAI;CAC1B,OAAO,qBAAqB,MAAM,OAAO;AAC3C;;;ACjJA,IAAA,eAAgB,QAAQ,MAAM,QAAQ,UAAU,CAAC,MAAM;CACrD,MAAM,EAAE,SAAS,OAAO,SAAS,MAAM,OAAO,SAAS;CAEvD,MAAM,UAAU,QAAQ,KAAK,UAAU,MAAM,MAAM,MAAM;CACzD,MAAM,WAAA,GAAUC,qBAAAA,MAAAA,CAAM,OAAO;CAE7B,MAAM,qBAAoB,UAAS,MAAM,MAAM,CAAC,CAAC,KAAK,IAAI;CAC1D,MAAM,0BAAyB,UAAS,MAAM,SAAS;CACvD,MAAM,eAAeC,gBAAS,QAAQ;EACpC;EACA;EACA;EACA;CACF,CAAC;CAED,IAAI,WAAW,OACb,OAAO,aAAa,IAAI,iBAAiB,CAAC,CAAC,KAAK,MAAM;MAEtD,OAAO,aAAa,IAAI,sBAAsB;AAElD"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["styleText","tokenize","styleText","styleText","styleText","pointer","styleText","parse","prettify"],"sources":["../src/utils.js","../src/code-frame.js","../src/json/utils.js","../src/json/get-meta-from-path.js","../src/json/get-decorated-data-path.js","../src/validation-errors/base.js","../src/validation-errors/required.js","../src/validation-errors/additional-prop.js","../src/validation-errors/enum.js","../src/validation-errors/default.js","../src/helpers.js","../src/index.js"],"sourcesContent":["// Basic\nconst eq = x => y => x === y;\nconst not = fn => x => !fn(x);\n\nconst getValues = o => Object.values(o);\n\nexport const notUndefined = x => x !== undefined;\n\n// Error\nconst isXError = x => error => error.keyword === x;\nexport const isRequiredError = isXError('required');\nexport const isAnyOfError = isXError('anyOf');\nexport const isEnumError = isXError('enum');\nexport const getErrors = node =>\n node && node.errors\n ? node.errors.map(e =>\n e.keyword === 'errorMessage' ? { ...e.params.errors[0], message: e.message } : e\n )\n : [];\n\n// Node\nexport const getChildren = node => (node && getValues(node.children)) || [];\n\nexport const getSiblings = parent => node => getChildren(parent).filter(not(eq(node)));\n\nexport const concatAll = xs => ys => ys.reduce((zs, z) => zs.concat(z), xs);\n","import { styleText } from 'node:util';\nimport { tokenize } from '@humanwhocodes/momoa';\n\nconst LINES_ABOVE = 2;\nconst LINES_BELOW = 3;\n\n// The line breaks momoa counts, so that its line numbers index into the split source.\nconst NEWLINE = /\\r\\n|[\\r\\n]/;\n\nconst TOKEN_STYLES = {\n String: 'green',\n Number: 'magenta',\n Boolean: 'cyan',\n Null: 'cyan',\n Colon: 'yellow',\n Comma: 'yellow',\n};\n\nconst MARKER_STYLE = ['red', 'bold'];\n\n// The check `styleText` makes for the headings, so that the frame is colored along with them.\nconst supportsColor = () => styleText('red', '-') !== '-';\n\n/**\n * Renders the lines of `source` around `location`, with carets under the located text and\n * `message` after the last caret.\n *\n * Lines and columns are 1-based and `end` is exclusive, as in momoa's locations. Without\n * `end`, a single caret marks `start`.\n *\n * @param {string} source\n * @param {{ start: { line: number, column: number }, end?: { line: number, column: number } }} location\n * @param {{ message?: string, color?: boolean }} [options]\n * @return {string}\n */\nexport default function codeFrame(\n source,\n { start, end = start },\n { message, color = supportsColor() } = {}\n) {\n const paint = color\n ? (format, text) => styleText(format, text, { validateStream: false })\n : (_format, text) => text;\n\n const lines = source.split(NEWLINE);\n const markers = getMarkers(lines, start, end);\n const first = Math.max(start.line - LINES_ABOVE, 1);\n const last = Math.min(end.line + LINES_BELOW, lines.length);\n const width = String(last).length;\n\n const rows = [];\n for (let number = first; number <= last; number++) {\n const line = lines[number - 1];\n const gutter = ` ${String(number).padStart(width)} |`;\n const code = line.length > 0 ? ` ${color ? highlight(line, paint) : line}` : '';\n const marker = markers.get(number);\n if (!marker) {\n rows.push(` ${paint('gray', gutter)}${code}`);\n continue;\n }\n\n const [column, count] = marker;\n const spacing = line.slice(0, column - 1).replace(/[^\\t]/g, ' ');\n let caretRow = ` ${paint('gray', gutter.replace(/\\d/g, ' '))} ${spacing}${paint(MARKER_STYLE, '^'.repeat(count))}`;\n if (message && number === end.line) {\n caretRow += ` ${paint(MARKER_STYLE, message)}`;\n }\n rows.push(`${paint(MARKER_STYLE, '>')}${paint('gray', gutter)}${code}`, caretRow);\n }\n\n return rows.join('\\n');\n}\n\n// Maps each marked line number to the column of its first caret and the number of carets.\nfunction getMarkers(lines, start, end) {\n const markers = new Map();\n if (start.line === end.line) {\n markers.set(start.line, [start.column, Math.max(end.column - start.column, 1)]);\n return markers;\n }\n\n markers.set(start.line, [start.column, lines[start.line - 1].length - start.column + 1]);\n for (let number = start.line + 1; number < end.line; number++) {\n markers.set(number, [1, Math.max(lines[number - 1].length, 1)]);\n }\n markers.set(end.line, [1, end.column - 1]);\n return markers;\n}\n\n// JSON strings can't contain raw line breaks, so each line holds whole tokens.\nfunction highlight(line, paint) {\n let output = '';\n let offset = 0;\n for (const { type, loc } of tokenize(line)) {\n const style = TOKEN_STYLES[type];\n if (style) {\n output +=\n line.slice(offset, loc.start.offset) +\n paint(style, line.slice(loc.start.offset, loc.end.offset));\n offset = loc.end.offset;\n }\n }\n return output + line.slice(offset);\n}\n","// TODO: Better error handling\nexport const getPointers = dataPath => {\n return dataPath\n .split('/')\n .slice(1)\n .map(pointer => pointer.split('~1').join('/').split('~0').join('~'));\n};\n","import { getPointers } from './utils';\n\nexport default function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {\n const pointers = getPointers(dataPath);\n const lastPointerIndex = pointers.length - 1;\n return pointers.reduce((obj, pointer, idx) => {\n switch (obj.type) {\n case 'Object': {\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n\n const { name, value } = member;\n return includeIdentifierLocation && idx === lastPointerIndex ? name : value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n return element && element.value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n}\n","import { getPointers } from './utils';\n\nexport default function getDecoratedDataPath(jsonAst, dataPath) {\n let decoratedPath = '';\n getPointers(dataPath).reduce((obj, pointer) => {\n switch (obj.type) {\n case 'Object': {\n decoratedPath += `/${pointer}`;\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n return member.value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n const value = element && element.value;\n decoratedPath += `/${pointer}${getTypeName(value)}`;\n return value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n return decoratedPath;\n}\n\nfunction getTypeName(obj) {\n if (!obj || !obj.elements) {\n return '';\n }\n const type = obj.elements.filter(child => child && child.name && child.name.value === 'type');\n\n if (!type.length) {\n return '';\n }\n\n return (type[0].value && `:${type[0].value.value}`) || '';\n}\n","import codeFrame from '../code-frame';\nimport { getMetaFromPath, getDecoratedDataPath } from '../json/index';\n\nexport default class BaseValidationError {\n constructor(options = { isIdentifierLocation: false }, { data, schema, jsonAst, jsonRaw }) {\n this.options = options;\n this.data = data;\n this.schema = schema;\n this.jsonAst = jsonAst;\n this.jsonRaw = jsonRaw;\n }\n\n getLocation(dataPath = this.instancePath) {\n const { isIdentifierLocation, isSkipEndLocation } = this.options;\n const { loc } = getMetaFromPath(this.jsonAst, dataPath, isIdentifierLocation);\n return {\n start: loc.start,\n end: isSkipEndLocation ? undefined : loc.end,\n };\n }\n\n getDecoratedPath(dataPath = this.instancePath) {\n const decoratedPath = getDecoratedDataPath(this.jsonAst, dataPath);\n return decoratedPath;\n }\n\n // The decorated path is empty at the root, where the message stands alone.\n withDecoratedPath(message, separator = ' ') {\n const decoratedPath = this.getDecoratedPath();\n return decoratedPath ? `${decoratedPath}${separator}${message}` : message;\n }\n\n getCodeFrame(message, dataPath = this.instancePath) {\n return codeFrame(this.jsonRaw, this.getLocation(dataPath), { message });\n }\n\n /**\n * @return {string}\n */\n get instancePath() {\n return typeof this.options.instancePath !== 'undefined'\n ? this.options.instancePath\n : this.options.dataPath;\n }\n\n print() {\n throw new Error(`Implement the 'print' method inside ${this.constructor.name}!`);\n }\n\n getError() {\n throw new Error(`Implement the 'getError' method inside ${this.constructor.name}!`);\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class RequiredValidationError extends BaseValidationError {\n getLocation(dataPath = this.instancePath) {\n const { start } = super.getLocation(dataPath);\n return { start };\n }\n\n print() {\n const { message, params } = this.options;\n const output = [styleText('red', styleText('bold', 'REQUIRED') + ' ' + message) + '\\n'];\n\n return output.concat(\n this.getCodeFrame(\n '☹️ ' + styleText('magentaBright', params.missingProperty) + ' is missing here!'\n )\n );\n }\n\n getError() {\n const { message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(message),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class AdditionalPropValidationError extends BaseValidationError {\n constructor(...args) {\n super(...args);\n this.options.isIdentifierLocation = true;\n }\n\n print() {\n const { message, params } = this.options;\n const output = [\n styleText('red', styleText('bold', 'ADDITIONAL PROPERTY') + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame(\n '😲 ' +\n styleText('magentaBright', params.additionalProperty) +\n ' is not expected to be here!',\n `${this.instancePath}/${params.additionalProperty}`\n )\n );\n }\n\n getError() {\n const { params } = this.options;\n\n return {\n ...this.getLocation(`${this.instancePath}/${params.additionalProperty}`),\n error: this.withDecoratedPath(\n `Property ${params.additionalProperty} is not expected to be here`\n ),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport leven from 'leven';\nimport pointer from 'jsonpointer';\nimport BaseValidationError from './base';\n\nexport default class EnumValidationError extends BaseValidationError {\n print() {\n const {\n message,\n params: { allowedValues },\n } = this.options;\n const bestMatch = this.findBestMatch();\n\n // Needed to handle nullable enums, as joining on null just prints \", \"\n const [firstValue, ...rest] = allowedValues;\n const allowedValuesMessage = rest.reduce((acc, value) => `${acc}, ${value}`, firstValue || '');\n\n const output = [\n styleText('red', styleText('bold', 'ENUM') + ' ' + message),\n styleText('red', `(${allowedValuesMessage})\\n`),\n ];\n\n return output.concat(\n this.getCodeFrame(\n bestMatch !== null\n ? '👈🏽 Did you mean ' + styleText('magentaBright', String(bestMatch)) + ' here?'\n : '👈🏽 Unexpected value, should be equal to one of the allowed values'\n )\n );\n }\n\n getError() {\n const { message, params } = this.options;\n const bestMatch = this.findBestMatch();\n const allowedValues = params.allowedValues.join(', ');\n\n const output = {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${message}: ${allowedValues}`),\n path: this.instancePath,\n };\n\n if (bestMatch !== null) {\n output.suggestion = `Did you mean ${bestMatch}?`;\n }\n\n return output;\n }\n\n findBestMatch() {\n const {\n params: { allowedValues },\n } = this.options;\n\n const currentValue =\n this.instancePath === '' ? this.data : pointer.get(this.data, this.instancePath);\n\n if (!currentValue) {\n return null;\n }\n\n const bestMatch = allowedValues\n .map(value => ({\n value,\n // leven compares strings, so other allowed values cannot be a close match.\n weight: typeof value === 'string' ? leven(value, currentValue.toString()) : Infinity,\n }))\n .sort((x, y) => (x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0))[0];\n\n return allowedValues.length === 1 ||\n (typeof bestMatch.value === 'string' && bestMatch.weight < bestMatch.value.length)\n ? bestMatch.value\n : null;\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class DefaultValidationError extends BaseValidationError {\n print() {\n const { keyword, message } = this.options;\n const output = [\n styleText('red', styleText('bold', keyword.toUpperCase()) + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame('👈🏽 ' + styleText('magentaBright', keyword) + ' ' + message)\n );\n }\n\n getError() {\n const { keyword, message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${keyword} ${message}`, ': '),\n path: this.instancePath,\n };\n }\n}\n","import {\n getChildren,\n getErrors,\n getSiblings,\n isAnyOfError,\n isEnumError,\n isRequiredError,\n concatAll,\n notUndefined,\n} from './utils';\nimport {\n AdditionalPropValidationError,\n RequiredValidationError,\n EnumValidationError,\n DefaultValidationError,\n} from './validation-errors/index';\n\nconst JSON_POINTERS_REGEX = /\\/[\\w_-]+(\\/\\d+)?/g;\n\n// Make a tree of errors from ajv errors array\nexport function makeTree(ajvErrors = []) {\n const root = { children: {} };\n ajvErrors.forEach(ajvError => {\n const instancePath =\n typeof ajvError.instancePath !== 'undefined' ? ajvError.instancePath : ajvError.dataPath;\n\n // `dataPath === ''` is root\n const paths = instancePath === '' ? [''] : instancePath.match(JSON_POINTERS_REGEX);\n if (paths) {\n paths.reduce((obj, path, i) => {\n obj.children[path] = obj.children[path] || { children: {}, errors: [] };\n if (i === paths.length - 1) {\n obj.children[path].errors.push(ajvError);\n }\n return obj.children[path];\n }, root);\n }\n });\n return root;\n}\n\nexport function filterRedundantErrors(root, parent, key) {\n /**\n * Partition out the errors by kind for ease of proceessing\n */\n const { anyOfErrors, enumErrors, requiredErrors } = getErrors(root).reduce(\n (acc, error) => {\n if (isRequiredError(error)) {\n acc.requiredErrors.push(error);\n\n return acc;\n }\n\n if (isAnyOfError(error)) {\n acc.anyOfErrors.push(error);\n }\n\n if (isEnumError(error)) {\n acc.enumErrors.push(error);\n }\n\n return acc;\n },\n { anyOfErrors: [], enumErrors: [], requiredErrors: [] }\n );\n\n /**\n * If there is are `required` errors then we can just drop every non-required error.\n * And, also `required` should have more priority than `anyOf`. @see #8\n */\n\n if (requiredErrors.length > 0) {\n root.errors = requiredErrors;\n root.children = {};\n\n // No need for further processing, as we've emptied out children\n return;\n }\n\n /**\n * If there is an `anyOf` error that means we have more meaningful errors\n * inside children. So we will just remove all errors from this level.\n *\n * If there are no children, then we don't delete the errors since we should\n * have at least one error to report.\n */\n if (anyOfErrors.length > 0 && Object.keys(root.children).length > 0) {\n delete root.errors;\n }\n\n /**\n * If all errors are `enum` and siblings have any error then we can safely\n * ignore the node. As we return early if there's required errors, we only\n * need to check anyofErrors length\n *\n * **CAUTION**\n * Need explicit `root.errors` check because `[].every(fn) === true`\n * https://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics\n */\n if (enumErrors.length > 0 && anyOfErrors.length === 0) {\n if (\n getSiblings(parent)(root)\n // Remove any reference which becomes `undefined` later\n .filter(notUndefined)\n .some(getErrors)\n ) {\n delete parent.children[key];\n }\n }\n\n Object.entries(root.children).forEach(([key, child]) => filterRedundantErrors(child, root, key));\n}\n\nexport function createErrorInstances(root, options) {\n const errors = getErrors(root);\n if (errors.length && errors.every(isEnumError)) {\n const uniqueValues = new Set(concatAll([])(errors.map(e => e.params.allowedValues)));\n const allowedValues = [...uniqueValues];\n const error = errors[0];\n return [\n new EnumValidationError(\n {\n ...error,\n params: { allowedValues },\n },\n options\n ),\n ];\n } else {\n return concatAll(\n errors.reduce((ret, error) => {\n switch (error.keyword) {\n case 'additionalProperties':\n return ret.concat(new AdditionalPropValidationError(error, options));\n case 'required':\n return ret.concat(new RequiredValidationError(error, options));\n default:\n return ret.concat(new DefaultValidationError(error, options));\n }\n }, [])\n )(getChildren(root).map(child => createErrorInstances(child, options)));\n }\n}\n\nexport default (ajvErrors, options) => {\n const tree = makeTree(ajvErrors || []);\n filterRedundantErrors(tree);\n return createErrorInstances(tree, options);\n};\n","import { parse } from '@humanwhocodes/momoa';\nimport prettify from './helpers';\n\nexport default (schema, data, errors, options = {}) => {\n const { format = 'cli', indent = null, json = null } = options;\n\n const jsonRaw = json || JSON.stringify(data, null, indent);\n const jsonAst = parse(jsonRaw);\n\n const customErrorToText = error => error.print().join('\\n');\n const customErrorToStructure = error => error.getError();\n const customErrors = prettify(errors, {\n data,\n schema,\n jsonAst,\n jsonRaw,\n });\n\n if (format === 'cli') {\n return customErrors.map(customErrorToText).join('\\n\\n');\n } else {\n return customErrors.map(customErrorToStructure);\n }\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,MAAM,MAAK,OAAK,MAAK,MAAM;AAC3B,MAAM,OAAM,QAAM,MAAK,CAAC,GAAG,CAAC;AAE5B,MAAM,aAAY,MAAK,OAAO,OAAO,CAAC;AAEtC,MAAa,gBAAe,MAAK,MAAM,KAAA;AAGvC,MAAM,YAAW,OAAK,UAAS,MAAM,YAAY;AACjD,MAAa,kBAAkB,SAAS,UAAU;AAClD,MAAa,eAAe,SAAS,OAAO;AAC5C,MAAa,cAAc,SAAS,MAAM;AAC1C,MAAa,aAAY,SACvB,QAAQ,KAAK,SACT,KAAK,OAAO,KAAI,MACd,EAAE,YAAY,iBAAiB;CAAE,GAAG,EAAE,OAAO,OAAO;CAAI,SAAS,EAAE;AAAQ,IAAI,CACjF,IACA,CAAC;AAGP,MAAa,eAAc,SAAS,QAAQ,UAAU,KAAK,QAAQ,KAAM,CAAC;AAE1E,MAAa,eAAc,YAAU,SAAQ,YAAY,MAAM,CAAC,CAAC,OAAO,IAAI,GAAG,IAAI,CAAC,CAAC;AAErF,MAAa,aAAY,QAAM,OAAM,GAAG,QAAQ,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;;;ACtB1E,MAAM,cAAc;AACpB,MAAM,cAAc;AAGpB,MAAM,UAAU;AAEhB,MAAM,eAAe;CACnB,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,MAAM;CACN,OAAO;CACP,OAAO;AACT;AAEA,MAAM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5B,QAAQ,MAAM,SAAd;GACE,KAAK,wBACH,OAAO,IAAI,OAAO,IAAI,8BAA8B,OAAO,OAAO,CAAC;GACrE,KAAK,YACH,OAAO,IAAI,OAAO,IAAI,wBAAwB,OAAO,OAAO,CAAC;GAC/D,SACE,OAAO,IAAI,OAAO,IAAI,uBAAuB,OAAO,OAAO,CAAC;EAChE;CACF,GAAG,CAAC,CAAC,CACP,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,KAAI,UAAS,qBAAqB,OAAO,OAAO,CAAC,CAAC;AAE1E;AAEA,IAAA,mBAAgB,WAAW,YAAY;CACrC,MAAM,OAAO,SAAS,aAAa,CAAC,CAAC;CACrC,sBAAsB,IAAI;CAC1B,OAAO,qBAAqB,MAAM,OAAO;AAC3C;;;ACjJA,IAAA,eAAgB,QAAQ,MAAM,QAAQ,UAAU,CAAC,MAAM;CACrD,MAAM,EAAE,SAAS,OAAO,SAAS,MAAM,OAAO,SAAS;CAEvD,MAAM,UAAU,QAAQ,KAAK,UAAU,MAAM,MAAM,MAAM;CACzD,MAAM,WAAA,GAAUC,qBAAAA,MAAAA,CAAM,OAAO;CAE7B,MAAM,qBAAoB,UAAS,MAAM,MAAM,CAAC,CAAC,KAAK,IAAI;CAC1D,MAAM,0BAAyB,UAAS,MAAM,SAAS;CACvD,MAAM,eAAeC,gBAAS,QAAQ;EACpC;EACA;EACA;EACA;CACF,CAAC;CAED,IAAI,WAAW,OACb,OAAO,aAAa,IAAI,iBAAiB,CAAC,CAAC,KAAK,MAAM;MAEtD,OAAO,aAAa,IAAI,sBAAsB;AAElD"}
|
package/dist/index.mjs
CHANGED
|
@@ -259,7 +259,7 @@ var EnumValidationError = class extends BaseValidationError {
|
|
|
259
259
|
value,
|
|
260
260
|
weight: typeof value === "string" ? leven(value, currentValue.toString()) : Infinity
|
|
261
261
|
})).sort((x, y) => x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0)[0];
|
|
262
|
-
return allowedValues.length === 1 || bestMatch.weight < bestMatch.value.length ? bestMatch.value : null;
|
|
262
|
+
return allowedValues.length === 1 || typeof bestMatch.value === "string" && bestMatch.weight < bestMatch.value.length ? bestMatch.value : null;
|
|
263
263
|
}
|
|
264
264
|
};
|
|
265
265
|
//#endregion
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":["prettify"],"sources":["../src/utils.js","../src/code-frame.js","../src/json/utils.js","../src/json/get-meta-from-path.js","../src/json/get-decorated-data-path.js","../src/validation-errors/base.js","../src/validation-errors/required.js","../src/validation-errors/additional-prop.js","../src/validation-errors/enum.js","../src/validation-errors/default.js","../src/helpers.js","../src/index.js"],"sourcesContent":["// Basic\nconst eq = x => y => x === y;\nconst not = fn => x => !fn(x);\n\nconst getValues = o => Object.values(o);\n\nexport const notUndefined = x => x !== undefined;\n\n// Error\nconst isXError = x => error => error.keyword === x;\nexport const isRequiredError = isXError('required');\nexport const isAnyOfError = isXError('anyOf');\nexport const isEnumError = isXError('enum');\nexport const getErrors = node =>\n node && node.errors\n ? node.errors.map(e =>\n e.keyword === 'errorMessage' ? { ...e.params.errors[0], message: e.message } : e\n )\n : [];\n\n// Node\nexport const getChildren = node => (node && getValues(node.children)) || [];\n\nexport const getSiblings = parent => node => getChildren(parent).filter(not(eq(node)));\n\nexport const concatAll = xs => ys => ys.reduce((zs, z) => zs.concat(z), xs);\n","import { styleText } from 'node:util';\nimport { tokenize } from '@humanwhocodes/momoa';\n\nconst LINES_ABOVE = 2;\nconst LINES_BELOW = 3;\n\n// The line breaks momoa counts, so that its line numbers index into the split source.\nconst NEWLINE = /\\r\\n|[\\r\\n]/;\n\nconst TOKEN_STYLES = {\n String: 'green',\n Number: 'magenta',\n Boolean: 'cyan',\n Null: 'cyan',\n Colon: 'yellow',\n Comma: 'yellow',\n};\n\nconst MARKER_STYLE = ['red', 'bold'];\n\n// The check `styleText` makes for the headings, so that the frame is colored along with them.\nconst supportsColor = () => styleText('red', '-') !== '-';\n\n/**\n * Renders the lines of `source` around `location`, with carets under the located text and\n * `message` after the last caret.\n *\n * Lines and columns are 1-based and `end` is exclusive, as in momoa's locations. Without\n * `end`, a single caret marks `start`.\n *\n * @param {string} source\n * @param {{ start: { line: number, column: number }, end?: { line: number, column: number } }} location\n * @param {{ message?: string, color?: boolean }} [options]\n * @return {string}\n */\nexport default function codeFrame(\n source,\n { start, end = start },\n { message, color = supportsColor() } = {}\n) {\n const paint = color\n ? (format, text) => styleText(format, text, { validateStream: false })\n : (_format, text) => text;\n\n const lines = source.split(NEWLINE);\n const markers = getMarkers(lines, start, end);\n const first = Math.max(start.line - LINES_ABOVE, 1);\n const last = Math.min(end.line + LINES_BELOW, lines.length);\n const width = String(last).length;\n\n const rows = [];\n for (let number = first; number <= last; number++) {\n const line = lines[number - 1];\n const gutter = ` ${String(number).padStart(width)} |`;\n const code = line.length > 0 ? ` ${color ? highlight(line, paint) : line}` : '';\n const marker = markers.get(number);\n if (!marker) {\n rows.push(` ${paint('gray', gutter)}${code}`);\n continue;\n }\n\n const [column, count] = marker;\n const spacing = line.slice(0, column - 1).replace(/[^\\t]/g, ' ');\n let caretRow = ` ${paint('gray', gutter.replace(/\\d/g, ' '))} ${spacing}${paint(MARKER_STYLE, '^'.repeat(count))}`;\n if (message && number === end.line) {\n caretRow += ` ${paint(MARKER_STYLE, message)}`;\n }\n rows.push(`${paint(MARKER_STYLE, '>')}${paint('gray', gutter)}${code}`, caretRow);\n }\n\n return rows.join('\\n');\n}\n\n// Maps each marked line number to the column of its first caret and the number of carets.\nfunction getMarkers(lines, start, end) {\n const markers = new Map();\n if (start.line === end.line) {\n markers.set(start.line, [start.column, Math.max(end.column - start.column, 1)]);\n return markers;\n }\n\n markers.set(start.line, [start.column, lines[start.line - 1].length - start.column + 1]);\n for (let number = start.line + 1; number < end.line; number++) {\n markers.set(number, [1, Math.max(lines[number - 1].length, 1)]);\n }\n markers.set(end.line, [1, end.column - 1]);\n return markers;\n}\n\n// JSON strings can't contain raw line breaks, so each line holds whole tokens.\nfunction highlight(line, paint) {\n let output = '';\n let offset = 0;\n for (const { type, loc } of tokenize(line)) {\n const style = TOKEN_STYLES[type];\n if (style) {\n output +=\n line.slice(offset, loc.start.offset) +\n paint(style, line.slice(loc.start.offset, loc.end.offset));\n offset = loc.end.offset;\n }\n }\n return output + line.slice(offset);\n}\n","// TODO: Better error handling\nexport const getPointers = dataPath => {\n return dataPath\n .split('/')\n .slice(1)\n .map(pointer => pointer.split('~1').join('/').split('~0').join('~'));\n};\n","import { getPointers } from './utils';\n\nexport default function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {\n const pointers = getPointers(dataPath);\n const lastPointerIndex = pointers.length - 1;\n return pointers.reduce((obj, pointer, idx) => {\n switch (obj.type) {\n case 'Object': {\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n\n const { name, value } = member;\n return includeIdentifierLocation && idx === lastPointerIndex ? name : value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n return element && element.value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n}\n","import { getPointers } from './utils';\n\nexport default function getDecoratedDataPath(jsonAst, dataPath) {\n let decoratedPath = '';\n getPointers(dataPath).reduce((obj, pointer) => {\n switch (obj.type) {\n case 'Object': {\n decoratedPath += `/${pointer}`;\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n return member.value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n const value = element && element.value;\n decoratedPath += `/${pointer}${getTypeName(value)}`;\n return value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n return decoratedPath;\n}\n\nfunction getTypeName(obj) {\n if (!obj || !obj.elements) {\n return '';\n }\n const type = obj.elements.filter(child => child && child.name && child.name.value === 'type');\n\n if (!type.length) {\n return '';\n }\n\n return (type[0].value && `:${type[0].value.value}`) || '';\n}\n","import codeFrame from '../code-frame';\nimport { getMetaFromPath, getDecoratedDataPath } from '../json/index';\n\nexport default class BaseValidationError {\n constructor(options = { isIdentifierLocation: false }, { data, schema, jsonAst, jsonRaw }) {\n this.options = options;\n this.data = data;\n this.schema = schema;\n this.jsonAst = jsonAst;\n this.jsonRaw = jsonRaw;\n }\n\n getLocation(dataPath = this.instancePath) {\n const { isIdentifierLocation, isSkipEndLocation } = this.options;\n const { loc } = getMetaFromPath(this.jsonAst, dataPath, isIdentifierLocation);\n return {\n start: loc.start,\n end: isSkipEndLocation ? undefined : loc.end,\n };\n }\n\n getDecoratedPath(dataPath = this.instancePath) {\n const decoratedPath = getDecoratedDataPath(this.jsonAst, dataPath);\n return decoratedPath;\n }\n\n // The decorated path is empty at the root, where the message stands alone.\n withDecoratedPath(message, separator = ' ') {\n const decoratedPath = this.getDecoratedPath();\n return decoratedPath ? `${decoratedPath}${separator}${message}` : message;\n }\n\n getCodeFrame(message, dataPath = this.instancePath) {\n return codeFrame(this.jsonRaw, this.getLocation(dataPath), { message });\n }\n\n /**\n * @return {string}\n */\n get instancePath() {\n return typeof this.options.instancePath !== 'undefined'\n ? this.options.instancePath\n : this.options.dataPath;\n }\n\n print() {\n throw new Error(`Implement the 'print' method inside ${this.constructor.name}!`);\n }\n\n getError() {\n throw new Error(`Implement the 'getError' method inside ${this.constructor.name}!`);\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class RequiredValidationError extends BaseValidationError {\n getLocation(dataPath = this.instancePath) {\n const { start } = super.getLocation(dataPath);\n return { start };\n }\n\n print() {\n const { message, params } = this.options;\n const output = [styleText('red', styleText('bold', 'REQUIRED') + ' ' + message) + '\\n'];\n\n return output.concat(\n this.getCodeFrame(\n '☹️ ' + styleText('magentaBright', params.missingProperty) + ' is missing here!'\n )\n );\n }\n\n getError() {\n const { message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(message),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class AdditionalPropValidationError extends BaseValidationError {\n constructor(...args) {\n super(...args);\n this.options.isIdentifierLocation = true;\n }\n\n print() {\n const { message, params } = this.options;\n const output = [\n styleText('red', styleText('bold', 'ADDITIONAL PROPERTY') + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame(\n '😲 ' +\n styleText('magentaBright', params.additionalProperty) +\n ' is not expected to be here!',\n `${this.instancePath}/${params.additionalProperty}`\n )\n );\n }\n\n getError() {\n const { params } = this.options;\n\n return {\n ...this.getLocation(`${this.instancePath}/${params.additionalProperty}`),\n error: this.withDecoratedPath(\n `Property ${params.additionalProperty} is not expected to be here`\n ),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport leven from 'leven';\nimport pointer from 'jsonpointer';\nimport BaseValidationError from './base';\n\nexport default class EnumValidationError extends BaseValidationError {\n print() {\n const {\n message,\n params: { allowedValues },\n } = this.options;\n const bestMatch = this.findBestMatch();\n\n // Needed to handle nullable enums, as joining on null just prints \", \"\n const [firstValue, ...rest] = allowedValues;\n const allowedValuesMessage = rest.reduce((acc, value) => `${acc}, ${value}`, firstValue || '');\n\n const output = [\n styleText('red', styleText('bold', 'ENUM') + ' ' + message),\n styleText('red', `(${allowedValuesMessage})\\n`),\n ];\n\n return output.concat(\n this.getCodeFrame(\n bestMatch !== null\n ? '👈🏽 Did you mean ' + styleText('magentaBright', String(bestMatch)) + ' here?'\n : '👈🏽 Unexpected value, should be equal to one of the allowed values'\n )\n );\n }\n\n getError() {\n const { message, params } = this.options;\n const bestMatch = this.findBestMatch();\n const allowedValues = params.allowedValues.join(', ');\n\n const output = {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${message}: ${allowedValues}`),\n path: this.instancePath,\n };\n\n if (bestMatch !== null) {\n output.suggestion = `Did you mean ${bestMatch}?`;\n }\n\n return output;\n }\n\n findBestMatch() {\n const {\n params: { allowedValues },\n } = this.options;\n\n const currentValue =\n this.instancePath === '' ? this.data : pointer.get(this.data, this.instancePath);\n\n if (!currentValue) {\n return null;\n }\n\n const bestMatch = allowedValues\n .map(value => ({\n value,\n // leven compares strings, so other allowed values cannot be a close match.\n weight: typeof value === 'string' ? leven(value, currentValue.toString()) : Infinity,\n }))\n .sort((x, y) => (x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0))[0];\n\n return allowedValues.length === 1 || bestMatch.weight < bestMatch.value.length\n ? bestMatch.value\n : null;\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class DefaultValidationError extends BaseValidationError {\n print() {\n const { keyword, message } = this.options;\n const output = [\n styleText('red', styleText('bold', keyword.toUpperCase()) + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame('👈🏽 ' + styleText('magentaBright', keyword) + ' ' + message)\n );\n }\n\n getError() {\n const { keyword, message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${keyword} ${message}`, ': '),\n path: this.instancePath,\n };\n }\n}\n","import {\n getChildren,\n getErrors,\n getSiblings,\n isAnyOfError,\n isEnumError,\n isRequiredError,\n concatAll,\n notUndefined,\n} from './utils';\nimport {\n AdditionalPropValidationError,\n RequiredValidationError,\n EnumValidationError,\n DefaultValidationError,\n} from './validation-errors/index';\n\nconst JSON_POINTERS_REGEX = /\\/[\\w_-]+(\\/\\d+)?/g;\n\n// Make a tree of errors from ajv errors array\nexport function makeTree(ajvErrors = []) {\n const root = { children: {} };\n ajvErrors.forEach(ajvError => {\n const instancePath =\n typeof ajvError.instancePath !== 'undefined' ? ajvError.instancePath : ajvError.dataPath;\n\n // `dataPath === ''` is root\n const paths = instancePath === '' ? [''] : instancePath.match(JSON_POINTERS_REGEX);\n if (paths) {\n paths.reduce((obj, path, i) => {\n obj.children[path] = obj.children[path] || { children: {}, errors: [] };\n if (i === paths.length - 1) {\n obj.children[path].errors.push(ajvError);\n }\n return obj.children[path];\n }, root);\n }\n });\n return root;\n}\n\nexport function filterRedundantErrors(root, parent, key) {\n /**\n * Partition out the errors by kind for ease of proceessing\n */\n const { anyOfErrors, enumErrors, requiredErrors } = getErrors(root).reduce(\n (acc, error) => {\n if (isRequiredError(error)) {\n acc.requiredErrors.push(error);\n\n return acc;\n }\n\n if (isAnyOfError(error)) {\n acc.anyOfErrors.push(error);\n }\n\n if (isEnumError(error)) {\n acc.enumErrors.push(error);\n }\n\n return acc;\n },\n { anyOfErrors: [], enumErrors: [], requiredErrors: [] }\n );\n\n /**\n * If there is are `required` errors then we can just drop every non-required error.\n * And, also `required` should have more priority than `anyOf`. @see #8\n */\n\n if (requiredErrors.length > 0) {\n root.errors = requiredErrors;\n root.children = {};\n\n // No need for further processing, as we've emptied out children\n return;\n }\n\n /**\n * If there is an `anyOf` error that means we have more meaningful errors\n * inside children. So we will just remove all errors from this level.\n *\n * If there are no children, then we don't delete the errors since we should\n * have at least one error to report.\n */\n if (anyOfErrors.length > 0 && Object.keys(root.children).length > 0) {\n delete root.errors;\n }\n\n /**\n * If all errors are `enum` and siblings have any error then we can safely\n * ignore the node. As we return early if there's required errors, we only\n * need to check anyofErrors length\n *\n * **CAUTION**\n * Need explicit `root.errors` check because `[].every(fn) === true`\n * https://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics\n */\n if (enumErrors.length > 0 && anyOfErrors.length === 0) {\n if (\n getSiblings(parent)(root)\n // Remove any reference which becomes `undefined` later\n .filter(notUndefined)\n .some(getErrors)\n ) {\n delete parent.children[key];\n }\n }\n\n Object.entries(root.children).forEach(([key, child]) => filterRedundantErrors(child, root, key));\n}\n\nexport function createErrorInstances(root, options) {\n const errors = getErrors(root);\n if (errors.length && errors.every(isEnumError)) {\n const uniqueValues = new Set(concatAll([])(errors.map(e => e.params.allowedValues)));\n const allowedValues = [...uniqueValues];\n const error = errors[0];\n return [\n new EnumValidationError(\n {\n ...error,\n params: { allowedValues },\n },\n options\n ),\n ];\n } else {\n return concatAll(\n errors.reduce((ret, error) => {\n switch (error.keyword) {\n case 'additionalProperties':\n return ret.concat(new AdditionalPropValidationError(error, options));\n case 'required':\n return ret.concat(new RequiredValidationError(error, options));\n default:\n return ret.concat(new DefaultValidationError(error, options));\n }\n }, [])\n )(getChildren(root).map(child => createErrorInstances(child, options)));\n }\n}\n\nexport default (ajvErrors, options) => {\n const tree = makeTree(ajvErrors || []);\n filterRedundantErrors(tree);\n return createErrorInstances(tree, options);\n};\n","import { parse } from '@humanwhocodes/momoa';\nimport prettify from './helpers';\n\nexport default (schema, data, errors, options = {}) => {\n const { format = 'cli', indent = null, json = null } = options;\n\n const jsonRaw = json || JSON.stringify(data, null, indent);\n const jsonAst = parse(jsonRaw);\n\n const customErrorToText = error => error.print().join('\\n');\n const customErrorToStructure = error => error.getError();\n const customErrors = prettify(errors, {\n data,\n schema,\n jsonAst,\n jsonRaw,\n });\n\n if (format === 'cli') {\n return customErrors.map(customErrorToText).join('\\n\\n');\n } else {\n return customErrors.map(customErrorToStructure);\n }\n};\n"],"mappings":";;;;;AACA,MAAM,MAAK,OAAK,MAAK,MAAM;AAC3B,MAAM,OAAM,QAAM,MAAK,CAAC,GAAG,CAAC;AAE5B,MAAM,aAAY,MAAK,OAAO,OAAO,CAAC;AAEtC,MAAa,gBAAe,MAAK,MAAM,KAAA;AAGvC,MAAM,YAAW,OAAK,UAAS,MAAM,YAAY;AACjD,MAAa,kBAAkB,SAAS,UAAU;AAClD,MAAa,eAAe,SAAS,OAAO;AAC5C,MAAa,cAAc,SAAS,MAAM;AAC1C,MAAa,aAAY,SACvB,QAAQ,KAAK,SACT,KAAK,OAAO,KAAI,MACd,EAAE,YAAY,iBAAiB;CAAE,GAAG,EAAE,OAAO,OAAO;CAAI,SAAS,EAAE;AAAQ,IAAI,CACjF,IACA,CAAC;AAGP,MAAa,eAAc,SAAS,QAAQ,UAAU,KAAK,QAAQ,KA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,IAAI,OAAO,IAAI,8BAA8B,OAAO,OAAO,CAAC;GACrE,KAAK,YACH,OAAO,IAAI,OAAO,IAAI,wBAAwB,OAAO,OAAO,CAAC;GAC/D,SACE,OAAO,IAAI,OAAO,IAAI,uBAAuB,OAAO,OAAO,CAAC;EAChE;CACF,GAAG,CAAC,CAAC,CACP,CAAC,CAAC,YAAY,IAAI,CAAC,CAAC,KAAI,UAAS,qBAAqB,OAAO,OAAO,CAAC,CAAC;AAE1E;AAEA,IAAA,mBAAgB,WAAW,YAAY;CACrC,MAAM,OAAO,SAAS,aAAa,CAAC,CAAC;CACrC,sBAAsB,IAAI;CAC1B,OAAO,qBAAqB,MAAM,OAAO;AAC3C;;;ACjJA,IAAA,eAAgB,QAAQ,MAAM,QAAQ,UAAU,CAAC,MAAM;CACrD,MAAM,EAAE,SAAS,OAAO,SAAS,MAAM,OAAO,SAAS;CAEvD,MAAM,UAAU,QAAQ,KAAK,UAAU,MAAM,MAAM,MAAM;CACzD,MAAM,UAAU,MAAM,OAAO;CAE7B,MAAM,qBAAoB,UAAS,MAAM,MAAM,CAAC,CAAC,KAAK,IAAI;CAC1D,MAAM,0BAAyB,UAAS,MAAM,SAAS;CACvD,MAAM,eAAeA,gBAAS,QAAQ;EACpC;EACA;EACA;EACA;CACF,CAAC;CAED,IAAI,WAAW,OACb,OAAO,aAAa,IAAI,iBAAiB,CAAC,CAAC,KAAK,MAAM;MAEtD,OAAO,aAAa,IAAI,sBAAsB;AAElD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":["prettify"],"sources":["../src/utils.js","../src/code-frame.js","../src/json/utils.js","../src/json/get-meta-from-path.js","../src/json/get-decorated-data-path.js","../src/validation-errors/base.js","../src/validation-errors/required.js","../src/validation-errors/additional-prop.js","../src/validation-errors/enum.js","../src/validation-errors/default.js","../src/helpers.js","../src/index.js"],"sourcesContent":["// Basic\nconst eq = x => y => x === y;\nconst not = fn => x => !fn(x);\n\nconst getValues = o => Object.values(o);\n\nexport const notUndefined = x => x !== undefined;\n\n// Error\nconst isXError = x => error => error.keyword === x;\nexport const isRequiredError = isXError('required');\nexport const isAnyOfError = isXError('anyOf');\nexport const isEnumError = isXError('enum');\nexport const getErrors = node =>\n node && node.errors\n ? node.errors.map(e =>\n e.keyword === 'errorMessage' ? { ...e.params.errors[0], message: e.message } : e\n )\n : [];\n\n// Node\nexport const getChildren = node => (node && getValues(node.children)) || [];\n\nexport const getSiblings = parent => node => getChildren(parent).filter(not(eq(node)));\n\nexport const concatAll = xs => ys => ys.reduce((zs, z) => zs.concat(z), xs);\n","import { styleText } from 'node:util';\nimport { tokenize } from '@humanwhocodes/momoa';\n\nconst LINES_ABOVE = 2;\nconst LINES_BELOW = 3;\n\n// The line breaks momoa counts, so that its line numbers index into the split source.\nconst NEWLINE = /\\r\\n|[\\r\\n]/;\n\nconst TOKEN_STYLES = {\n String: 'green',\n Number: 'magenta',\n Boolean: 'cyan',\n Null: 'cyan',\n Colon: 'yellow',\n Comma: 'yellow',\n};\n\nconst MARKER_STYLE = ['red', 'bold'];\n\n// The check `styleText` makes for the headings, so that the frame is colored along with them.\nconst supportsColor = () => styleText('red', '-') !== '-';\n\n/**\n * Renders the lines of `source` around `location`, with carets under the located text and\n * `message` after the last caret.\n *\n * Lines and columns are 1-based and `end` is exclusive, as in momoa's locations. Without\n * `end`, a single caret marks `start`.\n *\n * @param {string} source\n * @param {{ start: { line: number, column: number }, end?: { line: number, column: number } }} location\n * @param {{ message?: string, color?: boolean }} [options]\n * @return {string}\n */\nexport default function codeFrame(\n source,\n { start, end = start },\n { message, color = supportsColor() } = {}\n) {\n const paint = color\n ? (format, text) => styleText(format, text, { validateStream: false })\n : (_format, text) => text;\n\n const lines = source.split(NEWLINE);\n const markers = getMarkers(lines, start, end);\n const first = Math.max(start.line - LINES_ABOVE, 1);\n const last = Math.min(end.line + LINES_BELOW, lines.length);\n const width = String(last).length;\n\n const rows = [];\n for (let number = first; number <= last; number++) {\n const line = lines[number - 1];\n const gutter = ` ${String(number).padStart(width)} |`;\n const code = line.length > 0 ? ` ${color ? highlight(line, paint) : line}` : '';\n const marker = markers.get(number);\n if (!marker) {\n rows.push(` ${paint('gray', gutter)}${code}`);\n continue;\n }\n\n const [column, count] = marker;\n const spacing = line.slice(0, column - 1).replace(/[^\\t]/g, ' ');\n let caretRow = ` ${paint('gray', gutter.replace(/\\d/g, ' '))} ${spacing}${paint(MARKER_STYLE, '^'.repeat(count))}`;\n if (message && number === end.line) {\n caretRow += ` ${paint(MARKER_STYLE, message)}`;\n }\n rows.push(`${paint(MARKER_STYLE, '>')}${paint('gray', gutter)}${code}`, caretRow);\n }\n\n return rows.join('\\n');\n}\n\n// Maps each marked line number to the column of its first caret and the number of carets.\nfunction getMarkers(lines, start, end) {\n const markers = new Map();\n if (start.line === end.line) {\n markers.set(start.line, [start.column, Math.max(end.column - start.column, 1)]);\n return markers;\n }\n\n markers.set(start.line, [start.column, lines[start.line - 1].length - start.column + 1]);\n for (let number = start.line + 1; number < end.line; number++) {\n markers.set(number, [1, Math.max(lines[number - 1].length, 1)]);\n }\n markers.set(end.line, [1, end.column - 1]);\n return markers;\n}\n\n// JSON strings can't contain raw line breaks, so each line holds whole tokens.\nfunction highlight(line, paint) {\n let output = '';\n let offset = 0;\n for (const { type, loc } of tokenize(line)) {\n const style = TOKEN_STYLES[type];\n if (style) {\n output +=\n line.slice(offset, loc.start.offset) +\n paint(style, line.slice(loc.start.offset, loc.end.offset));\n offset = loc.end.offset;\n }\n }\n return output + line.slice(offset);\n}\n","// TODO: Better error handling\nexport const getPointers = dataPath => {\n return dataPath\n .split('/')\n .slice(1)\n .map(pointer => pointer.split('~1').join('/').split('~0').join('~'));\n};\n","import { getPointers } from './utils';\n\nexport default function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {\n const pointers = getPointers(dataPath);\n const lastPointerIndex = pointers.length - 1;\n return pointers.reduce((obj, pointer, idx) => {\n switch (obj.type) {\n case 'Object': {\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n\n const { name, value } = member;\n return includeIdentifierLocation && idx === lastPointerIndex ? name : value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n return element && element.value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n}\n","import { getPointers } from './utils';\n\nexport default function getDecoratedDataPath(jsonAst, dataPath) {\n let decoratedPath = '';\n getPointers(dataPath).reduce((obj, pointer) => {\n switch (obj.type) {\n case 'Object': {\n decoratedPath += `/${pointer}`;\n // JSON.parse keeps the last of duplicate keys, so that is the one ajv validated.\n const member = obj.members.findLast(child => child.name.value === pointer);\n if (!member) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);\n }\n return member.value;\n }\n case 'Array': {\n const element = obj.elements[pointer];\n const value = element && element.value;\n decoratedPath += `/${pointer}${getTypeName(value)}`;\n return value;\n }\n default:\n console.log(obj);\n }\n }, jsonAst.body);\n return decoratedPath;\n}\n\nfunction getTypeName(obj) {\n if (!obj || !obj.elements) {\n return '';\n }\n const type = obj.elements.filter(child => child && child.name && child.name.value === 'type');\n\n if (!type.length) {\n return '';\n }\n\n return (type[0].value && `:${type[0].value.value}`) || '';\n}\n","import codeFrame from '../code-frame';\nimport { getMetaFromPath, getDecoratedDataPath } from '../json/index';\n\nexport default class BaseValidationError {\n constructor(options = { isIdentifierLocation: false }, { data, schema, jsonAst, jsonRaw }) {\n this.options = options;\n this.data = data;\n this.schema = schema;\n this.jsonAst = jsonAst;\n this.jsonRaw = jsonRaw;\n }\n\n getLocation(dataPath = this.instancePath) {\n const { isIdentifierLocation, isSkipEndLocation } = this.options;\n const { loc } = getMetaFromPath(this.jsonAst, dataPath, isIdentifierLocation);\n return {\n start: loc.start,\n end: isSkipEndLocation ? undefined : loc.end,\n };\n }\n\n getDecoratedPath(dataPath = this.instancePath) {\n const decoratedPath = getDecoratedDataPath(this.jsonAst, dataPath);\n return decoratedPath;\n }\n\n // The decorated path is empty at the root, where the message stands alone.\n withDecoratedPath(message, separator = ' ') {\n const decoratedPath = this.getDecoratedPath();\n return decoratedPath ? `${decoratedPath}${separator}${message}` : message;\n }\n\n getCodeFrame(message, dataPath = this.instancePath) {\n return codeFrame(this.jsonRaw, this.getLocation(dataPath), { message });\n }\n\n /**\n * @return {string}\n */\n get instancePath() {\n return typeof this.options.instancePath !== 'undefined'\n ? this.options.instancePath\n : this.options.dataPath;\n }\n\n print() {\n throw new Error(`Implement the 'print' method inside ${this.constructor.name}!`);\n }\n\n getError() {\n throw new Error(`Implement the 'getError' method inside ${this.constructor.name}!`);\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class RequiredValidationError extends BaseValidationError {\n getLocation(dataPath = this.instancePath) {\n const { start } = super.getLocation(dataPath);\n return { start };\n }\n\n print() {\n const { message, params } = this.options;\n const output = [styleText('red', styleText('bold', 'REQUIRED') + ' ' + message) + '\\n'];\n\n return output.concat(\n this.getCodeFrame(\n '☹️ ' + styleText('magentaBright', params.missingProperty) + ' is missing here!'\n )\n );\n }\n\n getError() {\n const { message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(message),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class AdditionalPropValidationError extends BaseValidationError {\n constructor(...args) {\n super(...args);\n this.options.isIdentifierLocation = true;\n }\n\n print() {\n const { message, params } = this.options;\n const output = [\n styleText('red', styleText('bold', 'ADDITIONAL PROPERTY') + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame(\n '😲 ' +\n styleText('magentaBright', params.additionalProperty) +\n ' is not expected to be here!',\n `${this.instancePath}/${params.additionalProperty}`\n )\n );\n }\n\n getError() {\n const { params } = this.options;\n\n return {\n ...this.getLocation(`${this.instancePath}/${params.additionalProperty}`),\n error: this.withDecoratedPath(\n `Property ${params.additionalProperty} is not expected to be here`\n ),\n path: this.instancePath,\n };\n }\n}\n","import { styleText } from 'node:util';\nimport leven from 'leven';\nimport pointer from 'jsonpointer';\nimport BaseValidationError from './base';\n\nexport default class EnumValidationError extends BaseValidationError {\n print() {\n const {\n message,\n params: { allowedValues },\n } = this.options;\n const bestMatch = this.findBestMatch();\n\n // Needed to handle nullable enums, as joining on null just prints \", \"\n const [firstValue, ...rest] = allowedValues;\n const allowedValuesMessage = rest.reduce((acc, value) => `${acc}, ${value}`, firstValue || '');\n\n const output = [\n styleText('red', styleText('bold', 'ENUM') + ' ' + message),\n styleText('red', `(${allowedValuesMessage})\\n`),\n ];\n\n return output.concat(\n this.getCodeFrame(\n bestMatch !== null\n ? '👈🏽 Did you mean ' + styleText('magentaBright', String(bestMatch)) + ' here?'\n : '👈🏽 Unexpected value, should be equal to one of the allowed values'\n )\n );\n }\n\n getError() {\n const { message, params } = this.options;\n const bestMatch = this.findBestMatch();\n const allowedValues = params.allowedValues.join(', ');\n\n const output = {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${message}: ${allowedValues}`),\n path: this.instancePath,\n };\n\n if (bestMatch !== null) {\n output.suggestion = `Did you mean ${bestMatch}?`;\n }\n\n return output;\n }\n\n findBestMatch() {\n const {\n params: { allowedValues },\n } = this.options;\n\n const currentValue =\n this.instancePath === '' ? this.data : pointer.get(this.data, this.instancePath);\n\n if (!currentValue) {\n return null;\n }\n\n const bestMatch = allowedValues\n .map(value => ({\n value,\n // leven compares strings, so other allowed values cannot be a close match.\n weight: typeof value === 'string' ? leven(value, currentValue.toString()) : Infinity,\n }))\n .sort((x, y) => (x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0))[0];\n\n return allowedValues.length === 1 ||\n (typeof bestMatch.value === 'string' && bestMatch.weight < bestMatch.value.length)\n ? bestMatch.value\n : null;\n }\n}\n","import { styleText } from 'node:util';\nimport BaseValidationError from './base';\n\nexport default class DefaultValidationError extends BaseValidationError {\n print() {\n const { keyword, message } = this.options;\n const output = [\n styleText('red', styleText('bold', keyword.toUpperCase()) + ' ' + message) + '\\n',\n ];\n\n return output.concat(\n this.getCodeFrame('👈🏽 ' + styleText('magentaBright', keyword) + ' ' + message)\n );\n }\n\n getError() {\n const { keyword, message } = this.options;\n\n return {\n ...this.getLocation(),\n error: this.withDecoratedPath(`${keyword} ${message}`, ': '),\n path: this.instancePath,\n };\n }\n}\n","import {\n getChildren,\n getErrors,\n getSiblings,\n isAnyOfError,\n isEnumError,\n isRequiredError,\n concatAll,\n notUndefined,\n} from './utils';\nimport {\n AdditionalPropValidationError,\n RequiredValidationError,\n EnumValidationError,\n DefaultValidationError,\n} from './validation-errors/index';\n\nconst JSON_POINTERS_REGEX = /\\/[\\w_-]+(\\/\\d+)?/g;\n\n// Make a tree of errors from ajv errors array\nexport function makeTree(ajvErrors = []) {\n const root = { children: {} };\n ajvErrors.forEach(ajvError => {\n const instancePath =\n typeof ajvError.instancePath !== 'undefined' ? ajvError.instancePath : ajvError.dataPath;\n\n // `dataPath === ''` is root\n const paths = instancePath === '' ? [''] : instancePath.match(JSON_POINTERS_REGEX);\n if (paths) {\n paths.reduce((obj, path, i) => {\n obj.children[path] = obj.children[path] || { children: {}, errors: [] };\n if (i === paths.length - 1) {\n obj.children[path].errors.push(ajvError);\n }\n return obj.children[path];\n }, root);\n }\n });\n return root;\n}\n\nexport function filterRedundantErrors(root, parent, key) {\n /**\n * Partition out the errors by kind for ease of proceessing\n */\n const { anyOfErrors, enumErrors, requiredErrors } = getErrors(root).reduce(\n (acc, error) => {\n if (isRequiredError(error)) {\n acc.requiredErrors.push(error);\n\n return acc;\n }\n\n if (isAnyOfError(error)) {\n acc.anyOfErrors.push(error);\n }\n\n if (isEnumError(error)) {\n acc.enumErrors.push(error);\n }\n\n return acc;\n },\n { anyOfErrors: [], enumErrors: [], requiredErrors: [] }\n );\n\n /**\n * If there is are `required` errors then we can just drop every non-required error.\n * And, also `required` should have more priority than `anyOf`. @see #8\n */\n\n if (requiredErrors.length > 0) {\n root.errors = requiredErrors;\n root.children = {};\n\n // No need for further processing, as we've emptied out children\n return;\n }\n\n /**\n * If there is an `anyOf` error that means we have more meaningful errors\n * inside children. So we will just remove all errors from this level.\n *\n * If there are no children, then we don't delete the errors since we should\n * have at least one error to report.\n */\n if (anyOfErrors.length > 0 && Object.keys(root.children).length > 0) {\n delete root.errors;\n }\n\n /**\n * If all errors are `enum` and siblings have any error then we can safely\n * ignore the node. As we return early if there's required errors, we only\n * need to check anyofErrors length\n *\n * **CAUTION**\n * Need explicit `root.errors` check because `[].every(fn) === true`\n * https://en.wikipedia.org/wiki/Vacuous_truth#Vacuous_truths_in_mathematics\n */\n if (enumErrors.length > 0 && anyOfErrors.length === 0) {\n if (\n getSiblings(parent)(root)\n // Remove any reference which becomes `undefined` later\n .filter(notUndefined)\n .some(getErrors)\n ) {\n delete parent.children[key];\n }\n }\n\n Object.entries(root.children).forEach(([key, child]) => filterRedundantErrors(child, root, key));\n}\n\nexport function createErrorInstances(root, options) {\n const errors = getErrors(root);\n if (errors.length && errors.every(isEnumError)) {\n const uniqueValues = new Set(concatAll([])(errors.map(e => e.params.allowedValues)));\n const allowedValues = [...uniqueValues];\n const error = errors[0];\n return [\n new EnumValidationError(\n {\n ...error,\n params: { allowedValues },\n },\n options\n ),\n ];\n } else {\n return concatAll(\n errors.reduce((ret, error) => {\n switch (error.keyword) {\n case 'additionalProperties':\n return ret.concat(new AdditionalPropValidationError(error, options));\n case 'required':\n return ret.concat(new RequiredValidationError(error, options));\n default:\n return ret.concat(new DefaultValidationError(error, options));\n }\n }, [])\n )(getChildren(root).map(child => createErrorInstances(child, options)));\n }\n}\n\nexport default (ajvErrors, options) => {\n const tree = makeTree(ajvErrors || []);\n filterRedundantErrors(tree);\n return createErrorInstances(tree, options);\n};\n","import { parse } from '@humanwhocodes/momoa';\nimport prettify from './helpers';\n\nexport default (schema, data, errors, options = {}) => {\n const { format = 'cli', indent = null, json = null } = options;\n\n const jsonRaw = json || JSON.stringify(data, null, indent);\n const jsonAst = parse(jsonRaw);\n\n const customErrorToText = error => error.print().join('\\n');\n const customErrorToStructure = error => error.getError();\n const customErrors = prettify(errors, {\n data,\n schema,\n jsonAst,\n jsonRaw,\n });\n\n if (format === 'cli') {\n return customErrors.map(customErrorToText).join('\\n\\n');\n } else {\n return customErrors.map(customErrorToStructure);\n }\n};\n"],"mappings":";;;;;AACA,MAAM,MAAK,OAAK,MAAK,MAAM;AAC3B,MAAM,OAAM,QAAM,MAAK,CAAC,GAAG,CAAC;AAE5B,MAAM,aAAY,MAAK,OAAO,OAAO,CAAC;AAEtC,MAAa,gBAAe,MAAK,MAAM,KAAA;AAGvC,MAAM,YAAW,OAAK,UAAS,MAAM,YAAY;AACjD,MAAa,kBAAkB,SAAS,UAAU;AAClD,MAAa,eAAe,SAAS,OAAO;AAC5C,MAAa,cAAc,SAAS,MAAM;AAC1C,MAAa,aAAY,SACvB,QAAQ,KAAK,SACT,KAAK,OAAO,KAAI,MACd,EAAE,YAAY,iBAAiB;CAAE,GAAG,EAAE,OAAO,OAAO;CAAI,SAAS,EAAE;AAAQ,IAAI,CACjF,IACA,CAAC;AAGP,MAAa,eAAc,SAAS,QAAQ,UAAU,KAAK,QAAQ,KAAM,CAAC;AAE1E,MAAa,eAAc,YAAU,SAAQ,YAAY,MAAM,CAAC,CAAC,OAAO,IAAI,GAAG,IAAI,CAAC,CAAC;AAErF,MAAa,aAAY,QAAM,OAAM,GAAG,QAAQ,IAAI,MAAM,GAAG,OAAO,CAAC,GAAG,EAAE;;;ACtB1E,MAAM,cAAc;AACpB,MAAM,cAAc;AAGpB,MAAM,UAAU;AAEhB,MAAM,eAAe;CACnB,QAAQ;CACR,QAAQ;CACR,SAAS;CACT,MAAM;CACN,OAAO;CACP,OAAO;AACT;AAEA,MAAM,eAAe,CAAC,OAAO,MAAM;AAGnC,MAAM,sBAAsB,UAAU,OAAO,GAAG,MAAM;;;;;;;;;;;;;AActD,SAAwB,UACtB,QACA,EAAE,OAAO,MAAM,SACf,EAAE,SA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