Comparing version 0.13.0 to 0.13.1
# Changelog | ||
## 📦 [0.13.1](https://www.npmjs.com/package/v8r/v/0.13.1) - 2022-12-10 | ||
* Resolve external `$ref`s in local schemas | ||
## 📦 [0.13.0](https://www.npmjs.com/package/v8r/v/0.13.0) - 2022-06-11 | ||
@@ -4,0 +8,0 @@ |
{ | ||
"name": "v8r", | ||
"version": "0.13.0", | ||
"version": "0.13.1", | ||
"description": "A command-line JSON and YAML validator that's on your wavelength", | ||
@@ -18,2 +18,7 @@ "scripts": { | ||
"exports": "./src/index.js", | ||
"files": [ | ||
"src/**/!(*.spec).js", | ||
"config-schema.json", | ||
"CHANGELOG.md" | ||
], | ||
"repository": { | ||
@@ -20,0 +25,0 @@ "type": "git", |
@@ -9,3 +9,3 @@ # v8r | ||
A command-line JSON and YAML validator that's on your wavelength. | ||
v8r is a command-line JSON and YAML validator that uses [Schema Store](https://www.schemastore.org/) to detect a suitable schema for your input files based on the filename. | ||
@@ -12,0 +12,0 @@ ## Getting Started |
@@ -12,4 +12,8 @@ import { createRequire } from "module"; | ||
function _ajvFactory(schema, strictMode, cache) { | ||
const resolver = (url) => cache.fetch(url); | ||
function _ajvFactory( | ||
schema, | ||
strictMode, | ||
cache, | ||
resolver = (url) => cache.fetch(url) | ||
) { | ||
const opts = { allErrors: true, loadSchema: resolver, strict: strictMode }; | ||
@@ -57,4 +61,4 @@ | ||
async function validate(data, schema, strictMode, cache) { | ||
const ajv = _ajvFactory(schema, strictMode, cache); | ||
async function validate(data, schema, strictMode, cache, resolver) { | ||
const ajv = _ajvFactory(schema, strictMode, cache, resolver); | ||
addFormats(ajv); | ||
@@ -61,0 +65,0 @@ const validateFn = await ajv.compileAsync(schema); |
@@ -5,2 +5,3 @@ import flatCache from "flat-cache"; | ||
import path from "path"; | ||
import isUrl from "is-url"; | ||
import { validate } from "./ajv.js"; | ||
@@ -64,3 +65,13 @@ import { Cache } from "./cache.js"; | ||
const strictMode = config.verbose >= 2 ? "log" : false; | ||
const { valid, errors } = await validate(data, schema, strictMode, cache); | ||
const resolver = isUrl(schemaLocation) | ||
? (location) => getFromUrlOrFile(location, cache) | ||
: (location) => | ||
getFromUrlOrFile(location, cache, path.dirname(schemaLocation)); | ||
const { valid, errors } = await validate( | ||
data, | ||
schema, | ||
strictMode, | ||
cache, | ||
resolver | ||
); | ||
result.valid = valid; | ||
@@ -67,0 +78,0 @@ result.errors = errors; |
import fs from "fs"; | ||
import path from "path"; | ||
import isUrl from "is-url"; | ||
async function getFromUrlOrFile(location, cache) { | ||
return isUrl(location) | ||
? await cache.fetch(location) | ||
: JSON.parse(await fs.promises.readFile(location, "utf8")); | ||
async function getFromUrlOrFile(location, cache, base = null) { | ||
if (isUrl(location)) { | ||
return await cache.fetch(location); | ||
} else { | ||
if (base != null) { | ||
return JSON.parse( | ||
await fs.promises.readFile(path.join(base, location), "utf8") | ||
); | ||
} | ||
} | ||
return JSON.parse(await fs.promises.readFile(location, "utf8")); | ||
} | ||
export { getFromUrlOrFile }; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
39820
17
813
7