@sanity/validation
Advanced tools
Comparing version 0.133.0-next.ddda7af6 to 0.133.0-realtime-block-editor.410b182f
@@ -9,2 +9,6 @@ 'use strict'; | ||
var _require2 = require('./validators/blockValidator'); | ||
const blockValidator = _require2.blockValidator; | ||
// eslint-disable-next-line complexity | ||
@@ -48,2 +52,10 @@ | ||
if (type && type.name === 'block') { | ||
base = base.custom(blockValidator); | ||
} | ||
if (typeDef.annotations) { | ||
typeDef.annotations.forEach(annotation => inferFromSchemaType(annotation)); | ||
} | ||
if (typeDef.options && typeDef.options.list) { | ||
@@ -50,0 +62,0 @@ base = base.valid(typeDef.options.list.map(extractValueFromListOption)); |
@@ -10,3 +10,2 @@ 'use strict'; | ||
const genericValidator = require('./validators/genericValidator'); | ||
const promiseLimiter = require('./util/promiseLimiter'); | ||
@@ -37,10 +36,5 @@ const typeValidators = { | ||
const tasks = rules.map(createValidationTask); | ||
const tasks = rules.map(validateRule); | ||
return Promise.all(tasks).then(results => results.filter(Boolean)).then(flatten); | ||
function createValidationTask(curr) { | ||
const limiter = options.isChild ? promiseLimiter.children : promiseLimiter.root; | ||
return limiter(() => validateRule(curr)); | ||
} | ||
// eslint-disable-next-line complexity | ||
@@ -72,2 +66,6 @@ function validateRule(curr) { | ||
function processResult(result) { | ||
if (Array.isArray(result)) { | ||
return flatten(result.map(processResult)); | ||
} | ||
const hasError = result instanceof ValidationError; | ||
@@ -74,0 +72,0 @@ if (!hasError) { |
@@ -49,2 +49,4 @@ 'use strict'; | ||
module.exports.validateItem = validateItem; | ||
function validateObject(obj, type, path, options) { | ||
@@ -118,3 +120,2 @@ if (!type) { | ||
} | ||
// Validate items within array | ||
@@ -121,0 +122,0 @@ const itemChecks = items.map((item, i) => { |
@@ -87,2 +87,9 @@ 'use strict'; | ||
if (Array.isArray(result)) { | ||
if (result.length === 0) { | ||
return true; | ||
} | ||
return result; | ||
} | ||
if (result === true) { | ||
@@ -89,0 +96,0 @@ return true; |
{ | ||
"name": "@sanity/validation", | ||
"version": "0.133.0-next.ddda7af6", | ||
"version": "0.133.0-realtime-block-editor.410b182f", | ||
"description": "Validation and warning infrastructure for Sanity projects", | ||
@@ -38,3 +38,2 @@ "main": "lib/index.js", | ||
"es6-error": "^4.0.2", | ||
"throat": "^4.1.0", | ||
"type-of-is": "^3.5.1" | ||
@@ -41,0 +40,0 @@ }, |
const Rule = require('./Rule') | ||
const {slugValidator} = require('./validators/slugValidator') | ||
const {blockValidator} = require('./validators/blockValidator') | ||
@@ -43,2 +44,10 @@ // eslint-disable-next-line complexity | ||
if (type && type.name === 'block') { | ||
base = base.custom(blockValidator) | ||
} | ||
if (typeDef.annotations) { | ||
typeDef.annotations.forEach(annotation => inferFromSchemaType(annotation)) | ||
} | ||
if (typeDef.options && typeDef.options.list) { | ||
@@ -45,0 +54,0 @@ base = base.valid(typeDef.options.list.map(extractValueFromListOption)) |
const {get, flatten} = require('lodash') | ||
const ValidationError = require('./ValidationError') | ||
const genericValidator = require('./validators/genericValidator') | ||
const promiseLimiter = require('./util/promiseLimiter') | ||
@@ -30,3 +29,3 @@ const typeValidators = { | ||
const tasks = rules.map(createValidationTask) | ||
const tasks = rules.map(validateRule) | ||
return Promise.all(tasks) | ||
@@ -36,7 +35,2 @@ .then(results => results.filter(Boolean)) | ||
function createValidationTask(curr) { | ||
const limiter = options.isChild ? promiseLimiter.children : promiseLimiter.root | ||
return limiter(() => validateRule(curr)) | ||
} | ||
// eslint-disable-next-line complexity | ||
@@ -68,2 +62,6 @@ function validateRule(curr) { | ||
function processResult(result) { | ||
if (Array.isArray(result)) { | ||
return flatten(result.map(processResult)) | ||
} | ||
const hasError = result instanceof ValidationError | ||
@@ -70,0 +68,0 @@ if (!hasError) { |
@@ -33,2 +33,4 @@ const Type = require('type-of-is') | ||
module.exports.validateItem = validateItem | ||
function validateObject(obj, type, path, options) { | ||
@@ -90,3 +92,2 @@ if (!type) { | ||
} | ||
// Validate items within array | ||
@@ -93,0 +94,0 @@ const itemChecks = items.map((item, i) => { |
@@ -90,2 +90,9 @@ const Type = require('type-of-is') | ||
if (Array.isArray(result)) { | ||
if (result.length === 0) { | ||
return true | ||
} | ||
return result | ||
} | ||
if (result === true) { | ||
@@ -92,0 +99,0 @@ return true |
80660
3
45
2191
- Removedthroat@^4.1.0
- Removedthroat@4.1.0(transitive)