MCPcopy
hub / github.com/imbrn/v8n / testSchema

Function testSchema

src/v8n.js:275–311  ·  view source on GitHub ↗
(schema)

Source from the content-addressed store, hash-verified

273}
274
275function testSchema(schema) {
276 return {
277 simple: value => {
278 const causes = [];
279 Object.keys(schema).forEach(key => {
280 const nestedValidation = schema[key];
281 try {
282 nestedValidation.check((value || {})[key]);
283 } catch (ex) {
284 ex.target = key;
285 causes.push(ex);
286 }
287 });
288 if (causes.length > 0) {
289 throw causes;
290 }
291 return true;
292 },
293 async: value => {
294 const causes = [];
295 const nested = Object.keys(schema).map(key => {
296 const nestedValidation = schema[key];
297 return nestedValidation.testAsync((value || {})[key]).catch(ex => {
298 ex.target = key;
299 causes.push(ex);
300 });
301 });
302 return Promise.all(nested).then(() => {
303 if (causes.length > 0) {
304 throw causes;
305 }
306
307 return true;
308 });
309 },
310 };
311}
312
313export default v8n;

Callers 1

v8n.jsFile · 0.85

Calls 2

checkMethod · 0.65
testAsyncMethod · 0.65

Tested by

no test coverage detected