@exodus/schemasafe
Advanced tools
Comparing version 1.0.0-rc.2 to 1.0.0-rc.3
{ | ||
"name": "@exodus/schemasafe", | ||
"version": "1.0.0-rc.2", | ||
"version": "1.0.0-rc.3", | ||
"description": "JSON Safe Parser & Schema Validator", | ||
"license": "MIT", | ||
"main": "src/index.js", | ||
"types": "index.d.ts", | ||
"repository": { | ||
@@ -16,2 +17,3 @@ "type": "git", | ||
"files": [ | ||
"index.d.ts", | ||
"src/compile.js", | ||
@@ -18,0 +20,0 @@ "src/formats.js", |
@@ -18,3 +18,3 @@ # `@exodus/schemasafe` | ||
* Optional `requireValidation: true` mode enforces full validation of the input object.\ | ||
**Using `mode: "strong"` is recommended, — it combines that option with additional schema safety checks.** | ||
**Using [`mode: "strong"`](./doc/Strong-mode.md) is recommended, — it combines that option with additional schema safety checks.** | ||
* Does not fail open on unknown or unprocessed keywords — instead throws at build time if schema was not fully understood. | ||
@@ -42,3 +42,3 @@ _That is implemented by tracking processed keywords and ensuring that none remain uncovered._ | ||
Simply pass a schema to compile it | ||
Simply pass a schema to compile it: | ||
@@ -62,2 +62,29 @@ ```js | ||
Or use the [parser mode](./doc/Parser-not-validator.md) (running in | ||
[strong mode](./doc/Strong-mode.md) by default): | ||
```js | ||
const { parser } = require('.') | ||
const parse = parser({ | ||
$schema: 'https://json-schema.org/draft/2019-09/schema', | ||
type: 'object', | ||
required: ['hello'], | ||
properties: { | ||
hello: { | ||
pattern: '^[a-z]+$', | ||
type: 'string' | ||
} | ||
}, | ||
additionalProperties: false | ||
}) | ||
console.log('returns { valid: true, value }:', parse('{"hello": "world" }')) | ||
console.log('returns { valid: false }:', parse('{}')) | ||
``` | ||
## Options | ||
See [options documentation](./doc/Options.md) for the full list of supported options. | ||
## Custom formats | ||
@@ -64,0 +91,0 @@ |
@@ -60,2 +60,3 @@ 'use strict' | ||
requireStringValidation = opts.mode === 'strong', | ||
forbidNoopValues = opts.mode === 'strong', // e.g. $recursiveAnchor: false (it's false by default) | ||
complexityChecks = opts.mode === 'strong', | ||
@@ -255,9 +256,5 @@ unmodifiedPrototypes = false, // assumes no mangled Object/Array prototypes | ||
if (node === schema && recursiveAnchor) handle('$recursiveAnchor', ['boolean'], null) // already applied | ||
handle('deprecated', ['boolean'], null) // unused, meta-only | ||
handle('description', ['string'], null) // unused, meta-only | ||
handle('title', ['string'], null) // unused, meta-only | ||
handle('$comment', ['string'], null) // unused, meta-only | ||
handle('examples', ['array'], null) // unused, meta-only | ||
for (const ignore of ['title', 'description', '$comment']) handle(ignore, ['string'], null) // unused, meta-only strings | ||
for (const ignore of ['deprecated', 'readOnly', 'writeOnly']) handle(ignore, ['boolean'], null) // unused, meta-only flags | ||
@@ -274,2 +271,5 @@ handle('$defs', ['object'], null) || handle('definitions', ['object'], null) // defs are allowed, those are validated on usage | ||
if (node === schema && (recursiveAnchor || !forbidNoopValues)) | ||
handle('$recursiveAnchor', ['boolean'], null) // already applied | ||
// evaluated: declare dynamic | ||
@@ -957,2 +957,11 @@ const needUnevaluated = (rule) => | ||
enforce($recursiveRef === '#', 'Behavior of $recursiveRef is defined only for "#"') | ||
// Resolve to recheck that recursive ref is enabled | ||
const resolved = resolveReference(root, schemas, '#', basePath()) | ||
const [sub, subRoot, path] = resolved[0] || [] | ||
laxMode(sub.$recursiveAnchor, '$recursiveRef without $recursiveAnchor') | ||
if (!sub.$recursiveAnchor || !recursiveAnchor) { | ||
// regular ref | ||
const n = getref(sub) || compileSchema(sub, subRoot, opts, scope, path) | ||
return applyRef(n, { path: ['$recursiveRef'] }) | ||
} | ||
// Apply deep recursion from here only if $recursiveAnchor is true, else just run self | ||
@@ -959,0 +968,0 @@ const n = recursiveAnchor ? format('(recursive || validate)') : format('validate') |
@@ -19,3 +19,4 @@ 'use strict' | ||
// https://json-schema.org/understanding-json-schema/reference/generic.html | ||
...['deprecated', 'description', 'title', 'examples', '$comment'], // unused | ||
// https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9 | ||
...['title', 'description', 'deprecated', 'readOnly', 'writeOnly', 'examples', '$comment'], // unused meta | ||
'discriminator', // optimization hint and error filtering only, does not affect validation result | ||
@@ -22,0 +23,0 @@ ] |
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
108045
15
1917
218