UNPKG

better-ajv-errors

Version:
8 lines (7 loc) 2.53 kB
{ "version": 3, "sources": ["../../../src/validation-errors/base.js"], "sourcesContent": ["import { codeFrameColumns } from '@babel/code-frame';\nimport { getMetaFromPath, getDecoratedDataPath } from '../json/index';\n\nexport default class BaseValidationError {\n constructor(\n options = { isIdentifierLocation: false },\n { data, schema, jsonAst, jsonRaw }\n ) {\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(\n this.jsonAst,\n dataPath,\n isIdentifierLocation\n );\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 getCodeFrame(message, dataPath = this.instancePath) {\n return codeFrameColumns(this.jsonRaw, this.getLocation(dataPath), {\n highlightCode: true,\n message,\n });\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(\n `Implement the 'print' method inside ${this.constructor.name}!`\n );\n }\n\n getError() {\n throw new Error(\n `Implement the 'getError' method inside ${this.constructor.name}!`\n );\n }\n}\n"], "mappings": ";AAAA;AACA;AAEA,gCAAyC;AAAA,EACvC,YACE,UAAU,EAAE,sBAAsB,MAAM,GACxC,EAAE,MAAM,QAAQ,SAAS,WACzB;AACA,SAAK,UAAU;AACf,SAAK,OAAO;AACZ,SAAK,SAAS;AACd,SAAK,UAAU;AACf,SAAK,UAAU;AAAA,EACjB;AAAA,EAEA,YAAY,WAAW,KAAK,cAAc;AACxC,UAAM,EAAE,sBAAsB,sBAAsB,KAAK;AACzD,UAAM,EAAE,QAAQ,gBACd,KAAK,SACL,UACA,oBACF;AACA,WAAO;AAAA,MACL,OAAO,IAAI;AAAA,MACX,KAAK,oBAAoB,SAAY,IAAI;AAAA,IAC3C;AAAA,EACF;AAAA,EAEA,iBAAiB,WAAW,KAAK,cAAc;AAC7C,UAAM,gBAAgB,qBAAqB,KAAK,SAAS,QAAQ;AACjE,WAAO;AAAA,EACT;AAAA,EAEA,aAAa,SAAS,WAAW,KAAK,cAAc;AAClD,WAAO,iBAAiB,KAAK,SAAS,KAAK,YAAY,QAAQ,GAAG;AAAA,MAChE,eAAe;AAAA,MACf;AAAA,IACF,CAAC;AAAA,EACH;AAAA,MAKI,eAAe;AACjB,WAAO,OAAO,KAAK,QAAQ,iBAAiB,cACxC,KAAK,QAAQ,eACb,KAAK,QAAQ;AAAA,EACnB;AAAA,EAEA,QAAQ;AACN,UAAM,IAAI,MACR,uCAAuC,KAAK,YAAY,OAC1D;AAAA,EACF;AAAA,EAEA,WAAW;AACT,UAAM,IAAI,MACR,0CAA0C,KAAK,YAAY,OAC7D;AAAA,EACF;AACF;", "names": [] }