How to use the tv4.validateResult function in tv4

To help you get started, we’ve selected a few tv4 examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github nickclaw / alexa-ssml / src / validateProps.js View on Github external
export default function validateProps(props, schema) {
    const { children, ...itemProps } = props || {}; // TODO add child count validation too?
    const { error } = tv4.validateResult(itemProps, schema, false, true);

    if (error) {
        const { dataPath, srcPath, message } = error;

        if (dataPath) {
            throw new Error(`Unknown property: ${dataPath.slice(1)}`);
        }

        if (srcPath) {
            throw new Error(`Invalid value for property ${srcPath.slice(1)}: ${message}`);
        }

        throw new Error(message);
    }

    return itemProps;
github remotestorage / remotestorage.js / src / baseclient.js View on Github external
validate: function(object) {
    var schema = BaseClient.Types.getSchema(object['@context']);
    if (schema) {
      return tv4.validateResult(object, schema);
    } else {
      throw new SchemaNotFound(object['@context']);
    }
  },
github tlivings / enjoi / test / bench / tv4.js View on Github external
.time(function () {
    Tv4.validateResult({firstName: 'John', lastName: 'Doe', age: 45, tags: ['man', 'human']}, schema);
});
github toyatech / esschema / test / reflect.js View on Github external
function assertValid(code, done) {
    var result = tv4.validateResult(JSON.parse(JSON.stringify(esprima.parse(code), adjustRegexLiteral)), esschema);
    assert(result.valid);
    done();
}
describe('(function(){ var x = 1, y = 2, z = 3 })', function () {
github evmizulin / cms-api / src / entries / type / ReferenceEntryType.js View on Github external
_validateBySchema(entry, options) {
    const schema = getSchema(
      {
        type: { enum: ['reference'] },
        value: { type: 'string', minLength: 1 },
      },
      options
    )
    return tv4.validateResult(entry, schema)
  }
github evmizulin / cms-api / src / models / type / StringModelType.js View on Github external
_validateBySchema(model, options) {
    const schema = getBasicSchema(options)
    Object.assign(schema.properties, {
      type: { enum: ['string-line', 'string-multiline', 'string-html', 'string-markdown'] },
      default: { type: 'string', minLength: 1 },
      minLength: { type: 'integer', minimum: 0 },
      maxLength: { type: 'integer', minimum: 0 },
      pattern: { type: 'string', minLength: 1 },
    })
    return tv4.validateResult(model, schema)
  }
github nodecg / nodecg / lib / bundle-parser / config.js View on Github external
}

			const _foo = {};
			_foo[key] = defaultConfig[key];

			const _tempMerged = extend(true, _foo, clone(finalConfig));
			const result = tv4.validateResult(_tempMerged, schema);
			if (result.valid) {
				finalConfig = _tempMerged;
			}
		}
	} else {
		finalConfig = extend(true, defaultConfig, userConfig);
	}

	const result = tv4.validateResult(finalConfig, schema);
	if (result.valid) {
		return finalConfig;
	}

	throw new Error(`Config for bundle "${bundle.name}" is invalid:\n` +
		`${result.error.message} at ${result.error.dataPath}`);
};
github thingsboard / thingsboard / ui-ngx / src / app / shared / components / json-form / react / json-form-utils.ts View on Github external
function validateBySchema(schema: any, value: any): SchemaValidationResult {
  return tv.validateResult(value, schema);
}
github evmizulin / cms-api / src / models / type / ObjectModelType.js View on Github external
_validateBySchema(model, options) {
    const schema = getBasicSchema(options)
    schema.required.push('additionalProperties', 'required', 'properties')
    Object.assign(schema.properties, {
      type: { enum: ['object'] },
      additionalProperties: { enum: [false] },
      required: { type: 'array', uniqueItems: true, items: { type: 'string', minLength: 1 } },
      properties: { type: 'object' },
    })
    return tv4.validateResult(model, schema)
  }
github evmizulin / cms-api / src / models / type / BooleanModelType.js View on Github external
_validate(model, options) {
    const schema = getBasicSchema(options)
    schema.required.push('default')
    Object.assign(schema.properties, {
      type: { enum: ['boolean'] },
      default: { type: 'boolean' },
    })
    return tv4.validateResult(model, schema)
  }
}