Comparing version 9.7.1 to 9.7.2
@@ -115,4 +115,4 @@ /** | ||
case 'title': return !options.plural ? 'Anything' : 'Any Values'; | ||
case 'start': return !options.plural ? 'Value of any type' : 'Values of any types'; | ||
case 'fragment': return !options.plural ? 'value of any type' : 'values of any types'; | ||
case 'start': return !options.plural ? 'Value of any type' : 'Values of any type'; | ||
case 'fragment': return !options.plural ? 'value of any type' : 'values of any type'; | ||
} | ||
@@ -119,0 +119,0 @@ } |
@@ -8,3 +8,2 @@ /** | ||
var dehydrate = require('./dehydrate'); | ||
var buildSchemaIterator = require('./helpers/build-schema-iterator'); | ||
@@ -21,3 +20,3 @@ | ||
* | ||
* @param {*} schema - an exemplar or type schema | ||
* @param {*} schema - an exemplar | ||
* @param {String} path - a valid dot-deliminited path, where empty string ('') is the root (e.g. "" or "foo" or "foo.bar" or "foo.0.bar.0.baz") | ||
@@ -43,3 +42,3 @@ * | ||
// These variables are used by the iterator below. | ||
// These variables are used by the logic below. | ||
var currentExemplar = dehydratedSchema; | ||
@@ -64,2 +63,3 @@ // By default the path is not optional. | ||
// generic array | ||
// (same thing as `['*']`) | ||
if (_.isEqual(currentExemplar, [])) { | ||
@@ -66,0 +66,0 @@ optional = true; |
@@ -143,4 +143,4 @@ /** | ||
// (this is an exception... apparently doing `+''` in javascript results in `0`) | ||
if (value === '') return false; | ||
// (this is an exception... apparently doing `+''` and `+' '` in javascript results in `0`) | ||
if (value === '' || value.match(/\s/)) return false; | ||
@@ -163,3 +163,2 @@ // General case: | ||
} | ||
return +v; | ||
@@ -166,0 +165,0 @@ } |
@@ -8,3 +8,2 @@ /** | ||
var TYPES = require('./helpers/types'); | ||
var coerceExemplar = require('./coerce-exemplar'); | ||
@@ -17,6 +16,8 @@ | ||
* Given two rttc schemas, return the most specific schema that accepts the shared subset | ||
* of values accepted by both. Formally, this subset is the intersection of A and B (A ∩ B), | ||
* of values accepted by both, and that _does not_ accept any values that both schemas would | ||
* accept individually. Formally, this subset is the intersection of A and B (A ∩ B), | ||
* where A is the set of values accepted by `schema0` and B is the set of values accepted by | ||
* `schema1`. If `A ∩ B` is the empty set, then this function will return `null`. Otherwise it | ||
* will return the schema that precisely accepts `A ∩ B`. | ||
* `schema1`. If there is no schema that accepts only `A ∩ B` (e.g. 'boolean' ∩ `[{foo:['json']]`) | ||
* then this function will return `null`. Otherwise it will return the schema that precisely | ||
* accepts `A ∩ B`. | ||
* | ||
@@ -31,79 +32,2 @@ * @param {*} schema0 | ||
/* | ||
Type intersection: (using strict validation rules) | ||
// Special cases: | ||
// inside a generic dictionary keypath: act like 'json' | ||
// inside a generic array keypath: act like 'json' | ||
// inside a JSON keypath: act like 'json' | ||
// inside a ref keypath: act like 'ref' | ||
// inside any other keypath: not possible, that's an error (will be caught during stabilization, so we can ignore) | ||
// Types always intersect with themselves, with an identity result. | ||
'string' ∩ 'string' <====> 'string' | ||
'number' ∩ 'number' <====> 'number' | ||
'boolean' ∩ 'boolean' <====> 'boolean' | ||
'lamda' ∩ 'lamda' <====> 'lamda' | ||
{} ∩ {} <====> {} | ||
[] ∩ [] <====> [] | ||
'json' ∩ 'json' <====> 'json' | ||
'ref' ∩ 'ref' <====> 'ref' | ||
// Every type except "ref" and "lamda" intersects with "json", with an identity result. | ||
'string' ∩ 'json' <====> 'string' | ||
'number' ∩ 'json' <====> 'number' | ||
'boolean' ∩ 'json' <====> 'boolean' | ||
{} ∩ 'json' <====> {} | ||
[] ∩ 'json' <====> [] | ||
{x:'string'} ∩ 'json' <====> {x:'string'} | ||
['string'] ∩ 'json' <====> ['string'] | ||
// Every type intersects with "ref", with an identity result. | ||
'string' ∩ 'ref' <====> 'string' | ||
'number' ∩ 'ref' <====> 'number' | ||
'boolean' ∩ 'ref' <====> 'boolean' | ||
{} ∩ 'ref' <====> {} | ||
[] ∩ 'ref' <====> [] | ||
{x:'string'} ∩ 'ref' <====> {x:'string'} | ||
['string'] ∩ 'ref' <====> ['string'] | ||
'lamda' ∩ 'ref' <====> 'lamda' | ||
'json' ∩ 'ref' <====> 'json' | ||
// Strings, numbers, booleans, and lamdas do not intersect with each other, | ||
// or with any sort of dictionary or array type. | ||
'string' ∩ (anything else) <==/==> (ERROR) | ||
'number' ∩ (anything else) <==/==> (ERROR) | ||
'boolean' ∩ (anything else) <==/==> (ERROR) | ||
'lamda' ∩ (anything else) <==/==> (ERROR) | ||
// Faceted dictionaries intersect with generic dictionaries, with an identity result. | ||
{a:'string'} ∩ {} <====> {a:'string'} | ||
{a:{}} ∩ {} <====> {a:{}} | ||
// Patterned arrays intersect with generic arrays, with an identity result. | ||
['string'] ∩ [] <====> ['string'] | ||
[[{}]] ∩ [] <====> [[{}]] | ||
[{}] ∩ ['string'] <====> ['string'] | ||
// Faceted dictionaries intersect with other faceted dictionaries as long as recursive | ||
// types also successfully intersect. The result is the merged schema. | ||
// (extra keys are ok, since they'll just be ignored) | ||
{a:'string'} ∩ {a:'string',b:'string'} <====> {a:'string', b: 'string'} | ||
{x:'string'} ∩ {a:'string',b:'string'} <====> {a:'string', b: 'string', x: 'string'} | ||
{x:'string', a:'number'} ∩ {a:'string',b:'string'} <==/=> (ERROR) | ||
{x:'string', a:'json'} ∩ {a:'string',b:'string'} <====> {a:'string', b: 'string', x: 'string'} | ||
// Patterned arrays intersect with other patterned arrays as long as the recursive | ||
// types also successfully intersect. The result is the merged schema. | ||
['number'] ∩ ['json'] <====> ['number'] | ||
['number'] ∩ ['string'] <==/=> (ERROR) | ||
[{a:'number'}] ∩ [{}] <====> [{a:'number'}] | ||
// Exceptions when NOT using strict validation: | ||
'number' ∩ 'string' <====> 'number' | ||
'boolean' ∩ 'string' <====> 'boolean' | ||
'number' ∩ 'boolean' <====> 'boolean' | ||
*/ | ||
// exemplar-vs-type-schema-agnostic type check helper | ||
@@ -288,8 +212,15 @@ function thisSchema(schema){ | ||
// If either schema is void, then the intersection will always be the same. | ||
// (only relevant w/ exemplars) | ||
if (isExemplar && _.isNull(schema0) || _.isNull(schema1)) { | ||
return null; | ||
} | ||
// Run the iterator to get the schema intersection. | ||
var result = twoHeadedCursor(schema0, schema1); | ||
// This makes sure the resulting exemplar won't be `undefined`. | ||
if (isExemplar) { | ||
return coerceExemplar(result, true); | ||
if (_.isUndefined(result)) { | ||
throw new Error('Consistency violation: Result from rttc.intersection() should never be `undefined`.'); | ||
} | ||
@@ -296,0 +227,0 @@ |
@@ -57,3 +57,3 @@ /** | ||
if (expectedTypeSchema === 'lamda') { | ||
if (!unsafeMode) return humanString; | ||
if (!unsafeMode) { return humanString; } | ||
return hydrate(humanString, expectedTypeSchema); | ||
@@ -60,0 +60,0 @@ } |
@@ -160,3 +160,3 @@ /** | ||
// Configure two-headed type schema cursor and use it to recursively | ||
// determine the type schema intersection. | ||
// determine the type schema union. | ||
var twoHeadedCursor = buildTwoHeadedSchemaCursor( | ||
@@ -351,3 +351,3 @@ | ||
// Run the iterator to get the schema intersection. | ||
// Run the iterator to get the schema union. | ||
var result = twoHeadedCursor(schema0, schema1); | ||
@@ -354,0 +354,0 @@ |
{ | ||
"name": "rttc", | ||
"version": "9.7.1", | ||
"version": "9.7.2", | ||
"description": "Runtime type-checking for JavaScript.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -0,1 +1,15 @@ | ||
// ██████╗ ████████╗████████╗ ██████╗ ███████╗██████╗ ███████╗ ██████╗ | ||
// ██╔══██╗╚══██╔══╝╚══██╔══╝██╔════╝ ██╔════╝██╔══██╗██╔════╝██╔════╝ ██╗██╗ | ||
// ██████╔╝ ██║ ██║ ██║ ███████╗██████╔╝█████╗ ██║ ╚═╝╚═╝ | ||
// ██╔══██╗ ██║ ██║ ██║ ╚════██║██╔═══╝ ██╔══╝ ██║ ██╗██╗ | ||
// ██║ ██║ ██║ ██║ ╚██████╗ ███████║██║ ███████╗╚██████╗ ╚═╝╚═╝ | ||
// ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚══════╝ ╚═════╝ | ||
// | ||
// ██████╗ ██████╗ ███████╗██████╗ ██████╗██╗ ██████╗ ███╗ ██╗ | ||
// ██╔════╝██╔═══██╗██╔════╝██╔══██╗██╔════╝██║██╔═══██╗████╗ ██║ | ||
// ██║ ██║ ██║█████╗ ██████╔╝██║ ██║██║ ██║██╔██╗ ██║ | ||
// ██║ ██║ ██║██╔══╝ ██╔══██╗██║ ██║██║ ██║██║╚██╗██║ | ||
// ╚██████╗╚██████╔╝███████╗██║ ██║╚██████╗██║╚██████╔╝██║ ╚████║ | ||
// ╚═════╝ ╚═════╝ ╚══════╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝ | ||
// | ||
// Export the array of tests below. | ||
@@ -2,0 +16,0 @@ module.exports = [ |
@@ -41,2 +41,4 @@ /** | ||
} | ||
if (!_.isUndefined(test.example)) { | ||
@@ -43,0 +45,0 @@ msg += 'with a '+getDisplayType(test.example)+' example ('+getDisplayVal(test.example)+')'; |
@@ -0,1 +1,16 @@ | ||
// ██████╗ ████████╗████████╗ ██████╗ ███████╗██████╗ ███████╗ ██████╗ | ||
// ██╔══██╗╚══██╔══╝╚══██╔══╝██╔════╝ ██╔════╝██╔══██╗██╔════╝██╔════╝ ██╗██╗ | ||
// ██████╔╝ ██║ ██║ ██║ ███████╗██████╔╝█████╗ ██║ ╚═╝╚═╝ | ||
// ██╔══██╗ ██║ ██║ ██║ ╚════██║██╔═══╝ ██╔══╝ ██║ ██╗██╗ | ||
// ██║ ██║ ██║ ██║ ╚██████╗ ███████║██║ ███████╗╚██████╗ ╚═╝╚═╝ | ||
// ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝╚═╝ ╚══════╝ ╚═════╝ | ||
// | ||
// ██╗ ██╗ █████╗ ██╗ ██╗██████╗ █████╗ ████████╗██╗ ██████╗ ███╗ ██╗ | ||
// ██║ ██║██╔══██╗██║ ██║██╔══██╗██╔══██╗╚══██╔══╝██║██╔═══██╗████╗ ██║ | ||
// ██║ ██║███████║██║ ██║██║ ██║███████║ ██║ ██║██║ ██║██╔██╗ ██║ | ||
// ╚██╗ ██╔╝██╔══██║██║ ██║██║ ██║██╔══██║ ██║ ██║██║ ██║██║╚██╗██║ | ||
// ╚████╔╝ ██║ ██║███████╗██║██████╔╝██║ ██║ ██║ ██║╚██████╔╝██║ ╚████║ | ||
// ╚═══╝ ╚═╝ ╚═╝╚══════╝╚═╝╚═════╝ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═══╝ | ||
// | ||
// Export the array of tests below | ||
@@ -2,0 +17,0 @@ module.exports = [ |
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
280373
51
5511