Socket
Socket
Sign inDemoInstall

better-ajv-errors

Package Overview
Dependencies
Maintainers
3
Versions
33
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

better-ajv-errors - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

18

CHANGELOG.md
# better-ajv-errors
## 1.1.0
### Minor Changes
- ade58e0: :package: Swap `json-to-ast` with `momoa`
| | `json-to-ast` | `momoa` |
| ---------------------- | --------------: | --------------: |
| **Small JSON** `23B` | 254,556 ops/sec | 329,012 ops/sec |
| **Medium JSON** `55KB` | 226 ops/sec | 246 ops/sec |
| **Large JSON** `25MB` | 0.19 ops/sec | 0.29 ops/sec |
### Patch Changes
- abee681: :package: Restrict `leven` version to < 4
`leven@4` only ships `esm` module which is not compatible with this library.
## 1.0.0

@@ -4,0 +22,0 @@

4

lib/cjs/index.js

@@ -27,3 +27,3 @@ var __create = Object.create;

});
var import_json_to_ast = __toModule(require("json-to-ast"));
var import_momoa = __toModule(require("@humanwhocodes/momoa"));
var import_helpers = __toModule(require("./helpers"));

@@ -33,3 +33,3 @@ var src_default = (schema, data, errors, options = {}) => {

const jsonRaw = json || JSON.stringify(data, null, indent);
const jsonAst = (0, import_json_to_ast.default)(jsonRaw, { loc: true });
const jsonAst = (0, import_momoa.parse)(jsonRaw);
const customErrorToText = (error) => error.print().join("\n");

@@ -36,0 +36,0 @@ const customErrorToStructure = (error) => error.getError();

@@ -34,3 +34,3 @@ var __create = Object.create;

decoratedPath += `/${pointer}`;
const filtered = obj.children.filter((child) => child.key.value === pointer);
const filtered = obj.members.filter((child) => child.name.value === pointer);
if (filtered.length !== 1) {

@@ -41,16 +41,17 @@ throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);

}
case "Array":
decoratedPath += `/${pointer}${getTypeName(obj.children[pointer])}`;
return obj.children[pointer];
case "Array": {
decoratedPath += `/${pointer}${getTypeName(obj.elements[pointer])}`;
return obj.elements[pointer];
}
default:
console.log(obj);
}
}, jsonAst);
}, jsonAst.body);
return decoratedPath;
}
function getTypeName(obj) {
if (!obj || !obj.children) {
if (!obj || !obj.elements) {
return "";
}
const type = obj.children.filter((child) => child && child.key && child.key.value === "type");
const type = obj.elements.filter((child) => child && child.name && child.name.value === "type");
if (!type.length) {

@@ -57,0 +58,0 @@ return "";

@@ -28,3 +28,3 @@ var __create = Object.create;

var import_utils = __toModule(require("./utils"));
function getMetaFromPath(jsonAst, dataPath, isIdentifierLocation) {
function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {
const pointers = (0, import_utils.getPointers)(dataPath);

@@ -35,15 +35,15 @@ const lastPointerIndex = pointers.length - 1;

case "Object": {
const filtered = obj.children.filter((child) => child.key.value === pointer);
const filtered = obj.members.filter((child) => child.name.value === pointer);
if (filtered.length !== 1) {
throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);
}
const { key, value } = filtered[0];
return isIdentifierLocation && idx === lastPointerIndex ? key : value;
const { name, value } = filtered[0];
return includeIdentifierLocation && idx === lastPointerIndex ? name : value;
}
case "Array":
return obj.children[pointer];
return obj.elements[pointer];
default:
console.log(obj);
}
}, jsonAst);
}, jsonAst.body);
}

@@ -50,0 +50,0 @@ // Annotate the CommonJS export names for ESM import in node:

@@ -1,2 +0,2 @@

import parse from "json-to-ast";
import { parse } from "@humanwhocodes/momoa";
import prettify from "./helpers";

@@ -6,3 +6,3 @@ export default (schema, data, errors, options = {}) => {

const jsonRaw = json || JSON.stringify(data, null, indent);
const jsonAst = parse(jsonRaw, { loc: true });
const jsonAst = parse(jsonRaw);
const customErrorToText = (error) => error.print().join("\n");

@@ -9,0 +9,0 @@ const customErrorToStructure = (error) => error.getError();

@@ -8,3 +8,3 @@ import { getPointers } from "./utils";

decoratedPath += `/${pointer}`;
const filtered = obj.children.filter((child) => child.key.value === pointer);
const filtered = obj.members.filter((child) => child.name.value === pointer);
if (filtered.length !== 1) {

@@ -15,16 +15,17 @@ throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);

}
case "Array":
decoratedPath += `/${pointer}${getTypeName(obj.children[pointer])}`;
return obj.children[pointer];
case "Array": {
decoratedPath += `/${pointer}${getTypeName(obj.elements[pointer])}`;
return obj.elements[pointer];
}
default:
console.log(obj);
}
}, jsonAst);
}, jsonAst.body);
return decoratedPath;
}
function getTypeName(obj) {
if (!obj || !obj.children) {
if (!obj || !obj.elements) {
return "";
}
const type = obj.children.filter((child) => child && child.key && child.key.value === "type");
const type = obj.elements.filter((child) => child && child.name && child.name.value === "type");
if (!type.length) {

@@ -31,0 +32,0 @@ return "";

import { getPointers } from "./utils";
export default function getMetaFromPath(jsonAst, dataPath, isIdentifierLocation) {
export default function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {
const pointers = getPointers(dataPath);

@@ -8,16 +8,16 @@ const lastPointerIndex = pointers.length - 1;

case "Object": {
const filtered = obj.children.filter((child) => child.key.value === pointer);
const filtered = obj.members.filter((child) => child.name.value === pointer);
if (filtered.length !== 1) {
throw new Error(`Couldn't find property ${pointer} of ${dataPath}`);
}
const { key, value } = filtered[0];
return isIdentifierLocation && idx === lastPointerIndex ? key : value;
const { name, value } = filtered[0];
return includeIdentifierLocation && idx === lastPointerIndex ? name : value;
}
case "Array":
return obj.children[pointer];
return obj.elements[pointer];
default:
console.log(obj);
}
}, jsonAst);
}, jsonAst.body);
}
//# sourceMappingURL=get-meta-from-path.js.map
{
"name": "better-ajv-errors",
"version": "1.0.0",
"version": "1.1.0",
"description": "JSON Schema validation for Human",

@@ -44,2 +44,3 @@ "repository": "atlassian/better-ajv-errors",

"test-ci": "jest --coverage --colors && tsd",
"prescreenshot": "npm run build:cjs",
"screenshot": "svg-term --command='node screenshot' --out=./media/screenshot.svg --padding=5 --width=80 --height=13 --at=1000 --no-cursor --term iterm2 --profile='deep' --window",

@@ -51,6 +52,6 @@ "prepare": "is-ci || husky install",

"@babel/code-frame": "^7.16.0",
"@humanwhocodes/momoa": "^2.0.2",
"chalk": "^4.1.2",
"json-to-ast": "^2.0.3",
"jsonpointer": "^5.0.0",
"leven": "^3.1.0"
"leven": "^3.1.0 < 4"
},

@@ -60,5 +61,5 @@ "devDependencies": {

"@changesets/write": "^0.1.5",
"ajv": "^8.6.3",
"esbuild": "^0.13.12",
"esbuild-jest-transform": "^1.1.0",
"ajv": "^8.7.1",
"esbuild": "^0.13.13",
"esbuild-jest": "^0.5.0",
"eslint": "^8.2.0",

@@ -69,3 +70,3 @@ "eslint-config-prettier": "^8.3.0",

"fast-glob": "^3.2.7",
"flow-bin": "^0.163.0",
"flow-bin": "^0.164.0",
"git-format-staged": "^2.1.2",

@@ -88,7 +89,5 @@ "husky": "^7.0.0",

"transform": {
"^.+\\.js$": [
"esbuild-jest-transform"
]
"^.+\\.js$": "esbuild-jest"
}
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc