Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
BaseTypeValidator.prototype.validate = function (obj, context, path) {
if (path === void 0) { path = ''; }
obj = cloneDeep(obj);
var validatorPromises = [];
// if the object under validation does not exist return default result
if (!json_pointer_1.has(obj, path))
return validatorPromises;
var targetValue = json_pointer_1.get(obj, path);
// loops over validators and build the validation result
Object.values(this.validationRules).forEach(function (validationRule) {
validatorPromises.push(validationRule(targetValue, obj, path, context));
});
return validatorPromises;
};
return BaseTypeValidator;
validate (value: any, context: Context, path: string = ''): Promise[] {
value = cloneDeep(value)
let results = super.validate(value, context, path)
if (has(value, path)) {
// validating each entry
results = results.concat(this.allItemsValidator.validate(value, context, path))
}
this.singleItemValidators.forEach(validator => {
results = results.concat(validator.validate(value, path, context))
})
return results
}
Object.keys(this.keyValidators).forEach(propertyName => {
const typeValidator = this.keyValidators[ propertyName ]
const propertyPath = [ path, propertyName ].join('/')
if (has(obj, propertyPath) && get(obj, propertyPath) !== null) {
propertiesResults = propertiesResults.concat(typeValidator.validate(obj, context, propertyPath))
}
})
this.requiredProps.forEach(function (property) {
if (!json_pointer_1.has(obj, path + "/" + property) || json_pointer_1.get(obj, path + "/" + property) === null) {
context.addError('object.requires', path, { property: property });
}
});
var superResult = _super.prototype.validate.call(this, obj, context, path);
confirmed: () => (value: string, obj: any, path: string): boolean => {
const confirmPath = `${path}_confirmation`
return (has(obj, path) && has(obj, confirmPath) && get(obj, path) === get(obj, confirmPath))
},
}
this.requiredProps.forEach(property => {
if (!has(obj, `${path}/${property}`) || get(obj, `${path}/${property}`) === null) {
context.addError('object.requires', path, { property })
}
})
export var getData = function (state, props) {
var schemaKey = props.schemaKey, mergeSchema = props.mergeSchema;
var _a = mergeSchema.keys, keys = _a === void 0 ? [] : _a;
var _b = state[props.schemaKey].data, data = _b === void 0 ? {} : _b;
return jpp.has(data, jpp.compile(keys)) ? jpp.get(data, jpp.compile(keys)) : undefined;
};
export var getMetaData = function (state, props) {
const getMetaData = (state, props) => {
const { schemaKey, mergeSchema } = props;
const { keys = [] } = mergeSchema;
let { meta = {} } = state[props.schemaKey];
return jpp.has(meta, jpp.compile(keys)) ? jpp.get(meta, jpp.compile(keys)) : { dirty: false };
};
const mapStateToProps = createSelector([getData, getMetaData], (formData, meta) => {
exports.getMetaData = (state, props) => {
const { schemaKey, mergeSchema } = props;
const { keys = [] } = mergeSchema;
let { meta = {} } = state[props.schemaKey];
return jpp.has(meta, jpp.compile(keys)) ? jpp.get(meta, jpp.compile(keys)) : { dirty: false };
};
/**
export function has(entity: any, path: string): boolean {
return jsonPointer.has(entity, path);
}