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

jsonpolice

Package Overview
Dependencies
Maintainers
1
Versions
65
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jsonpolice - npm Package Compare versions

Comparing version 2.0.3 to 3.0.0

17

lib/index.js

@@ -691,3 +691,3 @@ 'use strict';

function create(dataOrUri, store, retriever) {
function create(dataOrUri, opts) {
if ((typeof dataOrUri === 'undefined' ? 'undefined' : _typeof(dataOrUri)) === 'object' && dataOrUri[__schema] instanceof Schema) {

@@ -697,9 +697,10 @@ return Promise.resolve(dataOrUri[__schema]);

return vers.parseKnown().then(function (versions) {
if (!store) store = {};
_lodash2.default.defaults(store, versions);
return refs.parse(dataOrUri, store, retriever).then(function (data) {
return vers.get(data.$schema).then(function (schemaVersion) {
var _opts = opts || {};
if (!_opts.store) _opts.store = {};
_lodash2.default.defaults(_opts.store, versions);
return refs.parse(dataOrUri, _opts).then(function (data) {
return vers.get(data.$schema, opts).then(function (schemaVersion) {
var _schemaVersion = Schema.create(schemaVersion, refs.scope(schemaVersion));
_schemaVersion.validate(data);
return Schema.create(data, typeof dataOrUri === 'string' ? dataOrUri : '#');
return Schema.create(data, _opts.scope || (typeof dataOrUri === 'string' ? dataOrUri : '#'));
});

@@ -710,5 +711,5 @@ });

}
function addVersion(dataOrUri, retriever) {
function addVersion(dataOrUri, opts) {
return vers.parseKnown().then(function () {
return vers.add(dataOrUri, retriever);
return vers.add(dataOrUri, opts);
});

@@ -715,0 +716,0 @@ }

@@ -162,13 +162,23 @@ 'use strict';

function add(dataOrUri, retriever) {
return refs.parse(dataOrUri, parsedVersions, retriever);
function add(dataOrUri, opts) {
var _opts = opts || {};
return refs.parse(dataOrUri, {
scope: _opts.scope,
store: parsedVersions,
retriever: _opts.retriever
});
}
function get(dataOrUri, retriever) {
function get(dataOrUri, opts) {
var ver = dataOrUri || defaultVersion;
var _opts = opts || {};
if (typeof ver === 'string' && parsedVersions[ver]) {
return Promise.resolve(parsedVersions[ver]);
} else if (typeof ver === 'string' && knownVersions[ver]) {
return refs.parse(knownVersions[ver], parsedVersions, retriever);
return refs.parse(knownVersions[ver], {
scope: _opts.scope,
store: parsedVersions,
retriever: _opts.retriever
});
} else {
return addVersion(dataOrUri, retriever);
return addVersion(dataOrUri, opts);
}

@@ -181,3 +191,6 @@ }

p = p.then(function () {
refs.parse(data, parsedVersions);
refs.parse(data, {
scope: uri,
store: parsedVersions
});
});

@@ -184,0 +197,0 @@ }

{
"name": "jsonpolice",
"version": "2.0.3",
"version": "3.0.0",
"description": "JSON Schema parser and validator",

@@ -27,5 +27,5 @@ "main": "lib/index.js",

"dependencies": {
"jsonref": "^2.0.1",
"jsonref": "^3.0.0",
"lodash": "^4.5.1"
}
}

@@ -21,3 +21,3 @@ # jsonpolice

## create(dataOrUri, store, retriever)
## create(dataOrUri _[, options]_)

@@ -28,10 +28,12 @@ Create a new instance of schema validator. The schema itself is validated against the version of the specification

* `dataOrUri`, the schema to parse or a fully qualified URI to pass to `retriever` to download the schema
* `store` (optional), an object to use to cache resolved `id` and `$ref` values. If no store is passed,
* `options` (optional), parsing options, the following optional properties are supported:
* `scope`, the current resolution scope (base href) of URLs and paths.
* `store`, an object to use to cache resolved `id` and `$ref` values. If no store is passed,
one is automatically created. Pass a `store` if you are going to parse several schemas or URIs referencing
the same `id` and `$ref` values.
* `retriever` (optional), a function accepting a URL in input and returning a promise resolved to an object
* `retriever`, a function accepting a URL in input and returning a promise resolved to an object
representing the data downloaded for the URI. Whenever a `$ref` to a new URI is found, if the URI is not
already cached in the store in use, it'll be fetched using this `retriever`. If not `retriever` is passed
and a URI needs to be downloaded, a `no_retriever` exception is thrown. Refer to the documentation of
[jsonref](https://github.com/vivocha/jsonref) for sample retriever functions to use with the browser or
[jsonref](https://github.com/vivocha/jsonref) for sample retriever functions to use in the browser or
with Node.js.

@@ -73,3 +75,3 @@

## addVersion(dataOrUri, retriever)
## addVersion(dataOrUri _[, options]_)

@@ -80,3 +82,5 @@ Register a new version of the specification that can be later used to validate schemas against. You can use this

* `dataOrUri`, the data to parse or a fully qualified URI to pass to `retriever` to download the data
* `retriever` (optional), a function accepting a URL in input and returning a promise resolved to an object
* `options` (optional), parsing options, the following optional properties are supported:
* `scope`, the current resolution scope (base href) of URLs and paths.
* `retriever`, a function accepting a URL in input and returning a promise resolved to an object
representing the data downloaded for the URI. Whenever a `$ref` to a new URI is found, if the URI is not

@@ -83,0 +87,0 @@ already cached in the store in use, it'll be fetched using this `retriever`. If not `retriever` is passed

@@ -534,3 +534,3 @@ import _ from 'lodash';

export function create(dataOrUri, store, retriever) {
export function create(dataOrUri, opts) {
if (typeof dataOrUri === 'object' && dataOrUri[__schema] instanceof Schema) {

@@ -540,9 +540,10 @@ return Promise.resolve(dataOrUri[__schema]);

return vers.parseKnown().then(function(versions) {
if (!store) store = {};
_.defaults(store, versions);
return refs.parse(dataOrUri, store, retriever).then(function (data) {
return vers.get(data.$schema).then(function(schemaVersion) {
var _opts = opts || {};
if (!_opts.store) _opts.store = {};
_.defaults(_opts.store, versions);
return refs.parse(dataOrUri, _opts).then(function(data) {
return vers.get(data.$schema, opts).then(function(schemaVersion) {
var _schemaVersion = Schema.create(schemaVersion, refs.scope(schemaVersion));
_schemaVersion.validate(data);
return Schema.create(data, typeof dataOrUri === 'string' ? dataOrUri : '#');
return Schema.create(data, _opts.scope || (typeof dataOrUri === 'string' ? dataOrUri : '#'));
});

@@ -553,5 +554,5 @@ });

}
export function addVersion(dataOrUri, retriever) {
export function addVersion(dataOrUri, opts) {
return vers.parseKnown().then(function() {
return vers.add(dataOrUri, retriever);
return vers.add(dataOrUri, opts);
});

@@ -558,0 +559,0 @@ }

@@ -160,13 +160,23 @@ import _ from 'lodash';

export function add(dataOrUri, retriever) {
return refs.parse(dataOrUri, parsedVersions, retriever);
export function add(dataOrUri, opts) {
var _opts = opts || {};
return refs.parse(dataOrUri, {
scope: _opts.scope,
store: parsedVersions,
retriever: _opts.retriever
});
}
export function get(dataOrUri, retriever) {
export function get(dataOrUri, opts) {
var ver = dataOrUri || defaultVersion;
var _opts = opts || {};
if (typeof ver === 'string' && parsedVersions[ver]) {
return Promise.resolve(parsedVersions[ver]);
} else if (typeof ver === 'string' && knownVersions[ver]) {
return refs.parse(knownVersions[ver], parsedVersions, retriever);
return refs.parse(knownVersions[ver], {
scope: _opts.scope,
store: parsedVersions,
retriever: _opts.retriever
});
} else {
return addVersion(dataOrUri, retriever);
return addVersion(dataOrUri, opts);
}

@@ -179,3 +189,6 @@ }

p = p.then(function() {
refs.parse(data, parsedVersions);
refs.parse(data, {
scope: uri,
store: parsedVersions
});
})

@@ -182,0 +195,0 @@ }

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