Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

v8r

Package Overview
Dependencies
Maintainers
1
Versions
31
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

v8r - npm Package Compare versions

Comparing version 0.13.1 to 0.14.0

5

CHANGELOG.md
# Changelog
## 📦 [0.14.0](https://www.npmjs.com/package/v8r/v/0.14.0) - 2023-01-28
* Throw an error if multiple versions of a schema are found in the catalog,
instead of assuming the latest version
## 📦 [0.13.1](https://www.npmjs.com/package/v8r/v/0.13.1) - 2022-12-10

@@ -4,0 +9,0 @@

6

package.json
{
"name": "v8r",
"version": "0.13.1",
"version": "0.14.0",
"description": "A command-line JSON and YAML validator that's on your wavelength",

@@ -35,3 +35,3 @@ "scripts": {

"chalk": "^5.0.0",
"cosmiconfig": "^7.0.1",
"cosmiconfig": "^8.0.0",
"decamelize": "^6.0.0",

@@ -44,3 +44,3 @@ "flat-cache": "^3.0.4",

"json5": "^2.2.0",
"minimatch": "^5.0.1",
"minimatch": "^6.1.6",
"yargs": "^17.0.1"

@@ -47,0 +47,0 @@ },

@@ -42,2 +42,37 @@ import minimatch from "minimatch";

function getMatchLogMessage(match) {
let outStr = "";
outStr += ` ${match.name}\n`;
if (match.description) {
outStr += ` ${match.description}\n`;
}
outStr += ` ${match.url || match.location}\n`;
return outStr;
}
function getVersionLogMessage(match, versionId, versionSchemaUrl) {
let outStr = "";
outStr += ` ${match.name} (${versionId})\n`;
if (match.description) {
outStr += ` ${match.description}\n`;
}
outStr += ` ${versionSchemaUrl}\n`;
return outStr;
}
function getMultipleMatchesLogMessage(matches) {
return matches
.map(function (match) {
if (Object.keys(match.versions || {}).length > 1) {
return Object.entries(match.versions)
.map(function ([versionId, versionSchemaUrl]) {
return getVersionLogMessage(match, versionId, versionSchemaUrl);
})
.join("\n");
}
return getMatchLogMessage(match);
})
.join("\n");
}
async function getMatchForFilename(catalogs, filename, cache) {

@@ -71,28 +106,32 @@ for (const [i, rec] of catalogs.entries()) {

logger.debug(`Searching for schema in ${catalogLocation} ...`);
if (matches.length === 1) {
if (
(matches.length === 1 && matches[0].versions == null) ||
(matches.length === 1 && Object.keys(matches[0].versions).length === 1)
) {
logger.info(`Found schema in ${catalogLocation} ...`);
return coerceMatch(matches[0]); // Match found. We're done.
return coerceMatch(matches[0]); // Exactly one match found. We're done.
}
if (matches.length === 0 && i < catalogs.length - 1) {
continue; // No match found. Try the next catalog in the array.
continue; // No matches found. Try the next catalog in the array.
}
if (matches.length > 1) {
if (
matches.length > 1 ||
(matches.length === 1 &&
Object.keys(matches[0].versions || {}).length > 1)
) {
// We found >1 matches in the same catalog. This is always a hard error.
const matchesLog = matches
.map(function (match) {
let outStr = "";
outStr += ` ${match.name}\n`;
if (match.description) {
outStr += ` ${match.description}\n`;
}
outStr += ` ${match.url || match.location}\n`;
return outStr;
})
.join("\n");
const matchesLog = getMultipleMatchesLogMessage(matches);
logger.info(
`Found multiple possible schemas for ${filename}. Possible matches:\n${matchesLog}`
`Found multiple possible matches for ${filename}. Possible matches:\n\n${matchesLog}`
);
throw new Error(
`Found multiple possible schemas to validate ${filename}`
);
}
// Either we found >1 matches in the same catalog or we found 0 matches
// in the last catalog and there are no more catalogs left to try.
// We found 0 matches in the last catalog
// and there are no more catalogs left to try
throw new Error(`Could not find a schema to validate ${filename}`);

@@ -99,0 +138,0 @@ }

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