mobx-react-form
Advanced tools
Comparing version
import Base from "./Base"; | ||
import { OptionsModel } from "./models/OptionsModel"; | ||
import { FieldInterface, FieldConstructor } from "./models/FieldInterface"; | ||
interface ValidationAsyncDataInterface { | ||
valid?: boolean; | ||
message?: string; | ||
} | ||
export default class Field extends Base implements FieldInterface { | ||
@@ -60,3 +56,3 @@ hasInitialNestedFields: boolean; | ||
validationFunctionsData: any[]; | ||
validationAsyncData: ValidationAsyncDataInterface | undefined; | ||
validationAsyncData: any; | ||
debouncedValidation: any; | ||
@@ -197,3 +193,2 @@ disposeValidationOnBlur: any; | ||
} | ||
export {}; | ||
//# sourceMappingURL=Field.d.ts.map |
@@ -896,3 +896,3 @@ "use strict"; | ||
this.errorAsync = null; | ||
this.validationAsyncData = {}; | ||
this.validationAsyncData = undefined; | ||
this.validationFunctionsData = []; | ||
@@ -899,0 +899,0 @@ this.validationErrorStack = []; |
@@ -19,2 +19,6 @@ import { BaseInterface } from "./BaseInterface"; | ||
validationFunctionsData: any[]; | ||
validationAsyncData: { | ||
valid?: boolean; | ||
message?: string | null; | ||
}; | ||
debouncedValidation: any; | ||
@@ -62,3 +66,3 @@ autoFocus: boolean; | ||
invalidate(message?: string, deep?: boolean, async?: boolean): void; | ||
setValidationAsyncData(valid: boolean, message: string): void; | ||
setValidationAsyncData(valid?: boolean, message?: string): void; | ||
resetValidation(deep: boolean): void; | ||
@@ -65,0 +69,0 @@ clear(deep?: boolean): void; |
@@ -28,5 +28,28 @@ import Form from "../Form"; | ||
} | ||
export type ValidationPlugin = { | ||
export type ValidationPackage = any; | ||
export type ExtendPlugin<TValidator = ValidationPackage> = (args: { | ||
validator: TValidator; | ||
form: FormInterface; | ||
}) => void; | ||
export interface ValidationPluginConfig<TValidator = ValidationPackage> { | ||
package: TValidator; | ||
schema?: any; | ||
options?: any; | ||
extend?: ExtendPlugin<TValidator>; | ||
} | ||
export interface ValidationPluginConstructor<TValidator = ValidationPackage> { | ||
config: ValidationPluginConfig<TValidator>; | ||
state: StateInterface; | ||
promises: Promise<unknown>[]; | ||
} | ||
export interface ValidationPluginInterface<TValidator = ValidationPackage> extends ValidationPluginConstructor<TValidator> { | ||
validator: TValidator; | ||
schema?: any; | ||
extend?: ExtendPlugin<TValidator>; | ||
validate(field: FieldInterface): void; | ||
class?(constructor: ValidationPluginConstructor<TValidator>): void; | ||
} | ||
export type ValidationPlugin<TValidator = ValidationPackage> = { | ||
class: any; | ||
config?: ValidationPluginConfig; | ||
config?: ValidationPluginConfig<TValidator>; | ||
}; | ||
@@ -42,25 +65,2 @@ export interface ValidationPlugins { | ||
} | ||
export type ValidationPackage = any; | ||
export type ExtendPlugin = ({ validator, form }: { | ||
validator: any; | ||
form: FormInterface; | ||
}) => void; | ||
export interface ValidationPluginConfig { | ||
package: ValidationPackage; | ||
schema?: any; | ||
options?: any; | ||
extend?: ExtendPlugin; | ||
} | ||
export interface ValidationPluginConstructor { | ||
config: ValidationPluginConfig; | ||
state: StateInterface; | ||
promises: Promise<unknown>[]; | ||
} | ||
export interface ValidationPluginInterface extends ValidationPluginConstructor { | ||
validator: ValidatorInterface; | ||
schema?: any; | ||
extend?: ExtendPlugin; | ||
validate(field: FieldInterface): any; | ||
class?(constructor: ValidationPluginConstructor): void; | ||
} | ||
export type DriversMap = { | ||
@@ -67,0 +67,0 @@ [key in keyof ValidationPlugins]: ValidationPluginInterface; |
@@ -1,32 +0,27 @@ | ||
import { ValidationPlugin, ValidationPluginConfig, ValidationPluginConstructor, ValidationPluginInterface } from "../models/ValidatorInterface"; | ||
/** | ||
Declarative Validation Rules | ||
const plugins = { | ||
dvr: dvr({ | ||
package: validatorjs, | ||
extend: callback, | ||
}), | ||
}; | ||
*/ | ||
export declare class DVR implements ValidationPluginInterface { | ||
promises: any[]; | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { ValidationPlugin, ValidationPluginConfig, ValidationPluginConstructor, ValidationPluginInterface } from "src/models/ValidatorInterface"; | ||
export declare class DVR<TValidator = any> implements ValidationPluginInterface<TValidator> { | ||
promises: Promise<any>[]; | ||
config: any; | ||
state: any; | ||
extend: any; | ||
validator: any; | ||
constructor({ config, state, promises, }: ValidationPluginConstructor); | ||
extend?: (args: { | ||
validator: TValidator; | ||
form: FormInterface; | ||
}) => void; | ||
validator: TValidator; | ||
schema?: any; | ||
constructor({ config, state, promises, }: ValidationPluginConstructor<TValidator>); | ||
extendValidator(): void; | ||
validate(field: any): void; | ||
makeLabels(validation: any, field: any): void; | ||
validateFieldSync(field: any, data: any): void; | ||
validateFieldAsync(field: any, data: any): void; | ||
handleAsyncPasses(field: any, resolve: any): void; | ||
handleAsyncFails(field: any, validation: any, resolve: any): void; | ||
executeAsyncValidation(field: any): void; | ||
rules(rules: any, type: any): any[]; | ||
validate(field: FieldInterface): void; | ||
makeLabels(validation: any, field: FieldInterface): void; | ||
validateFieldSync(field: FieldInterface, data: any): void; | ||
validateFieldAsync(field: FieldInterface, data: any): void; | ||
handleAsyncPasses(field: FieldInterface, resolve: () => void): void; | ||
handleAsyncFails(field: FieldInterface, validation: any, resolve: () => void): void; | ||
executeAsyncValidation(field: FieldInterface): void; | ||
rules(rules: any, type: "sync" | "async"): any[]; | ||
} | ||
declare const _default: (config?: ValidationPluginConfig) => ValidationPlugin; | ||
declare const _default: <TValidator = any>(config?: ValidationPluginConfig<TValidator>) => ValidationPlugin<TValidator>; | ||
export default _default; | ||
//# sourceMappingURL=DVR.d.ts.map |
@@ -8,13 +8,2 @@ "use strict"; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
/** | ||
Declarative Validation Rules | ||
const plugins = { | ||
dvr: dvr({ | ||
package: validatorjs, | ||
extend: callback, | ||
}), | ||
}; | ||
*/ | ||
class DVR { | ||
@@ -26,3 +15,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -33,3 +22,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -40,3 +29,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -47,3 +36,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -54,4 +43,10 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "schema", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
@@ -64,4 +59,3 @@ this.promises = promises; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -74,3 +68,2 @@ validator: this.validator, | ||
validate(field) { | ||
// get form fields data | ||
const data = this.state.form.validatedValues; | ||
@@ -106,15 +99,9 @@ this.validateFieldAsync(field, data); | ||
const $rules = this.rules(field.rules, "sync"); | ||
// exit if no rules found | ||
if (lodash_1.default.isEmpty($rules[0])) | ||
return; | ||
// get field rules | ||
const rules = { [field.path]: $rules }; | ||
// create the validator instance | ||
const validation = new this.validator(data, rules); | ||
// set label into errors messages instead key | ||
this.makeLabels(validation, field); | ||
// check validation | ||
if (validation.passes()) | ||
return; | ||
// the validation is failed, set the field error | ||
field.invalidate(lodash_1.default.head(validation.errors.get(field.path)), false); | ||
@@ -124,10 +111,6 @@ } | ||
const $rules = this.rules(field.rules, "async"); | ||
// exit if no rules found | ||
if (lodash_1.default.isEmpty($rules[0])) | ||
return; | ||
// get field rules | ||
const rules = { [field.path]: $rules }; | ||
// create the validator instance | ||
const validation = new this.validator(data, rules); | ||
// set label into errors messages instead key | ||
this.makeLabels(validation, field); | ||
@@ -153,7 +136,9 @@ const $p = new Promise((resolve) => validation.checkAsync(() => this.handleAsyncPasses(field, resolve), () => this.handleAsyncFails(field, validation, resolve))); | ||
const $rules = lodash_1.default.isString(rules) ? lodash_1.default.split(rules, "|") : rules; | ||
// eslint-disable-next-line new-cap | ||
const v = new this.validator(); | ||
return lodash_1.default.filter($rules, ($rule) => type === "async" | ||
? v.getRule(lodash_1.default.split($rule, ":")[0]).async | ||
: !v.getRule(lodash_1.default.split($rule, ":")[0]).async); | ||
return lodash_1.default.filter($rules, ($rule) => { | ||
var _a, _b; | ||
return type === "async" | ||
? (_a = v.getRule(lodash_1.default.split($rule, ":")[0])) === null || _a === void 0 ? void 0 : _a.async | ||
: !((_b = v.getRule(lodash_1.default.split($rule, ":")[0])) === null || _b === void 0 ? void 0 : _b.async); | ||
}); | ||
} | ||
@@ -163,5 +148,5 @@ } | ||
exports.default = (config) => ({ | ||
class: DVR, | ||
class: (DVR), | ||
config, | ||
}); | ||
//# sourceMappingURL=DVR.js.map |
import { ValidationPlugin, ValidationPluginConfig } from "../models/ValidatorInterface"; | ||
declare const _default: (config?: ValidationPluginConfig) => ValidationPlugin; | ||
declare const _default: <TValidator = any>(config?: ValidationPluginConfig<TValidator>) => ValidationPlugin<TValidator>; | ||
export default _default; | ||
//# sourceMappingURL=JOI.d.ts.map |
@@ -9,3 +9,3 @@ "use strict"; | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -16,3 +16,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -23,3 +23,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -30,3 +30,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -37,3 +37,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -44,6 +44,7 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
@@ -55,3 +56,2 @@ this.validator = config.package; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === "function") { | ||
@@ -65,17 +65,18 @@ this.extend({ | ||
validate(field) { | ||
const { error } = this.schema.validate(field.state.form.validatedValues, { abortEarly: false }); | ||
const data = this.state.form.validatedValues; | ||
const { error } = this.schema.validate(data, { abortEarly: false }); | ||
if (!error) | ||
return; | ||
const fieldPathArray = field.path.split('.'); | ||
const fieldPathArray = field.path.split("."); | ||
const fieldErrors = error.details | ||
.filter(detail => { | ||
const errorPathString = detail.path.join('.'); | ||
const fieldPathString = fieldPathArray.join('.'); | ||
return errorPathString === fieldPathString || errorPathString.startsWith(`${fieldPathString}.`); | ||
.filter((detail) => { | ||
const errorPathString = detail.path.join("."); | ||
const fieldPathString = fieldPathArray.join("."); | ||
return (errorPathString === fieldPathString || | ||
errorPathString.startsWith(`${fieldPathString}.`)); | ||
}) | ||
.map(detail => { | ||
.map((detail) => { | ||
var _a; | ||
// Replace the path in the error message with the custom label | ||
const label = ((_a = detail.context) === null || _a === void 0 ? void 0 : _a.label) || detail.path.join('.'); | ||
const message = detail.message.replace(`${detail.path.join('.')}`, label); | ||
const label = ((_a = detail.context) === null || _a === void 0 ? void 0 : _a.label) || detail.path.join("."); | ||
const message = detail.message.replace(`${detail.path.join(".")}`, label); | ||
return message; | ||
@@ -89,5 +90,5 @@ }); | ||
exports.default = (config) => ({ | ||
class: JOI, | ||
class: (JOI), | ||
config, | ||
}); | ||
//# sourceMappingURL=JOI.js.map |
import { ValidationPlugin, ValidationPluginConfig } from "../models/ValidatorInterface"; | ||
declare const _default: (config?: ValidationPluginConfig) => ValidationPlugin; | ||
declare const _default: <TValidator = any>(config?: ValidationPluginConfig<TValidator>) => ValidationPlugin<TValidator>; | ||
export default _default; | ||
//# sourceMappingURL=SVK.d.ts.map |
@@ -7,16 +7,7 @@ "use strict"; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const isPromise = (obj) => !!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function"); | ||
/** | ||
Schema Validation Keywords | ||
const plugins = { | ||
svk: svk({ | ||
package: ajv, | ||
extend: callback, | ||
}), | ||
}; | ||
*/ | ||
function isPromise(obj) { | ||
return (!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function")); | ||
} | ||
class SVK { | ||
@@ -28,3 +19,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -35,3 +26,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -42,3 +33,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -49,3 +40,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -56,3 +47,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -63,70 +54,50 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
this.schema = config.schema; | ||
this.initAJV(config); | ||
this.initValidator(); | ||
} | ||
extendOptions(options = {}) { | ||
return Object.assign(options, { | ||
errorDataPath: "property", | ||
allErrors: true, | ||
coerceTypes: true, | ||
v5: true, | ||
}); | ||
return Object.assign(Object.assign({}, options), { errorDataPath: "property", allErrors: true, coerceTypes: true, v5: true }); | ||
} | ||
initAJV(config) { | ||
// get ajv package | ||
const ajv = config.package; | ||
// create ajv instance | ||
const validator = new ajv(this.extendOptions(config.options)); | ||
// extend ajv using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
initValidator() { | ||
const AJV = this.config.package; | ||
const validatorInstance = new AJV(this.extendOptions(this.config.options)); | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
form: this.state.form, | ||
validator, | ||
validator: validatorInstance, | ||
}); | ||
} | ||
// create ajv validator (compiling rules) | ||
this.validator = validator.compile(this.schema); | ||
this.validator = validatorInstance.compile(this.schema); | ||
} | ||
validate(field) { | ||
const validate = this.validator(field.state.form.validatedValues); | ||
// check if is $async schema | ||
if (isPromise(validate)) { | ||
const $p = validate | ||
const result = this.validator(field.state.form.validatedValues); | ||
if (isPromise(result)) { | ||
const $p = result | ||
.then(() => field.setValidationAsyncData(true)) | ||
.catch((err) => err && this.handleAsyncError(field, err.errors)) | ||
.then(() => this.executeAsyncValidation(field)); | ||
// push the promise into array | ||
this.promises.push($p); | ||
return; | ||
} | ||
// check sync errors | ||
this.handleSyncError(field, this.validator.errors); | ||
} | ||
handleSyncError(field, errors) { | ||
const fieldErrorObj = this.findError(field.path, errors); | ||
// if fieldErrorObj is not undefined, the current field is invalid. | ||
if (lodash_1.default.isUndefined(fieldErrorObj)) | ||
const fieldError = this.findError(field.path, errors); | ||
if (!fieldError) | ||
return; | ||
// the current field is now invalid | ||
// add additional info to the message | ||
const msg = `${field.label} ${fieldErrorObj.message}`; | ||
// invalidate the current field with message | ||
field.invalidate(msg, false); | ||
const message = `${field.label} ${fieldError.message}`; | ||
field.invalidate(message, false); | ||
} | ||
handleAsyncError(field, errors) { | ||
// find current field error message from ajv errors | ||
const fieldErrorObj = this.findError(field.path, errors); | ||
// if fieldErrorObj is not undefined, the current field is invalid. | ||
if (lodash_1.default.isUndefined(fieldErrorObj)) | ||
const fieldError = this.findError(field.path, errors); | ||
if (!fieldError) | ||
return; | ||
// the current field is now invalid | ||
// add additional info to the message | ||
const msg = `${field.label} ${fieldErrorObj.message}`; | ||
// set async validation data on the field | ||
field.setValidationAsyncData(false, msg); | ||
const message = `${field.label} ${fieldError.message}`; | ||
field.setValidationAsyncData(false, message); | ||
} | ||
@@ -143,4 +114,5 @@ findError(path, errors) { | ||
executeAsyncValidation(field) { | ||
if (field.validationAsyncData.valid === false) { | ||
field.invalidate(field.validationAsyncData.message, false, true); | ||
const asyncData = field.validationAsyncData; | ||
if (asyncData.valid === false) { | ||
field.invalidate(asyncData.message, false, true); | ||
} | ||
@@ -150,5 +122,5 @@ } | ||
exports.default = (config) => ({ | ||
class: SVK, | ||
class: (SVK), | ||
config, | ||
}); | ||
//# sourceMappingURL=SVK.js.map |
@@ -0,28 +1,23 @@ | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { ValidationPlugin, ValidationPluginConfig, ValidationPluginConstructor, ValidationPluginInterface } from "../models/ValidatorInterface"; | ||
/** | ||
Vanilla JavaScript Functions | ||
const plugins = { | ||
vkf: vkf({ | ||
package: validator, | ||
}), | ||
}; | ||
*/ | ||
export declare class VJF implements ValidationPluginInterface { | ||
promises: any[]; | ||
config: any; | ||
export declare class VJF<TValidator = any> implements ValidationPluginInterface<TValidator> { | ||
promises: Promise<any>[]; | ||
config: ValidationPluginConfig<TValidator>; | ||
state: any; | ||
extend: any; | ||
validator: any; | ||
constructor({ config, state, promises, }: ValidationPluginConstructor); | ||
extend?: (args: { | ||
validator: TValidator; | ||
form: FormInterface; | ||
}) => void; | ||
validator: TValidator; | ||
constructor({ config, state, promises, }: ValidationPluginConstructor<TValidator>); | ||
extendValidator(): void; | ||
validate(field: any): void; | ||
collectData($fn: any, field: any): void; | ||
executeValidation(field: any): void; | ||
executeAsyncValidation(field: any): void; | ||
handleFunctionResult($fn: any, field: any): any; | ||
validate(field: FieldInterface): void; | ||
collectData(fn: Function, field: FieldInterface): void; | ||
executeValidation(field: FieldInterface): void; | ||
executeAsyncValidation(field: FieldInterface): void; | ||
handleFunctionResult(fn: Function, field: FieldInterface): [boolean, string] | Promise<[boolean, string]>; | ||
} | ||
declare const _default: (config?: ValidationPluginConfig) => ValidationPlugin; | ||
declare const _default: <TValidator = any>(config?: ValidationPluginConfig<TValidator>) => ValidationPlugin<TValidator>; | ||
export default _default; | ||
//# sourceMappingURL=VJF.d.ts.map |
@@ -8,15 +8,7 @@ "use strict"; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
const isPromise = (obj) => !!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function"); | ||
/** | ||
Vanilla JavaScript Functions | ||
const plugins = { | ||
vkf: vkf({ | ||
package: validator, | ||
}), | ||
}; | ||
*/ | ||
function isPromise(obj) { | ||
return (!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function")); | ||
} | ||
class VJF { | ||
@@ -28,3 +20,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -35,3 +27,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -42,3 +34,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -49,3 +41,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -56,6 +48,7 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
@@ -66,4 +59,3 @@ this.validator = config === null || config === void 0 ? void 0 : config.package; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -76,47 +68,37 @@ validator: this.validator, | ||
validate(field) { | ||
// exit if field does not have validation functions | ||
if (!field.validators) | ||
return; | ||
// get validators from validate property | ||
const $fn = field.validators; | ||
// map only if is an array of validator functions | ||
if (Array.isArray($fn)) { | ||
$fn.map((fn) => this.collectData(fn, field)); | ||
} | ||
// it's just one function // DEPRECATED | ||
// if (typeof $fn === 'function') { | ||
// this.collectData($fn, field); | ||
// } | ||
// execute the validation function | ||
const validators = Array.isArray(field.validators) ? field.validators : [field.validators]; | ||
validators.forEach((fn) => this.collectData(fn, field)); | ||
this.executeValidation(field); | ||
} | ||
collectData($fn, field) { | ||
const res = this.handleFunctionResult($fn, field); | ||
// check and execute only if is a promise | ||
if (isPromise(res)) { | ||
const $p = res | ||
.then(($res) => field.setValidationAsyncData($res[0], $res[1])) | ||
collectData(fn, field) { | ||
const result = this.handleFunctionResult(fn, field); | ||
if (isPromise(result)) { | ||
const $p = result | ||
.then(([valid, message]) => field.setValidationAsyncData(valid, message)) | ||
.then(() => this.executeAsyncValidation(field)); | ||
// push the promise into array | ||
this.promises.push($p); | ||
return; | ||
} | ||
// is a plain function | ||
field.validationFunctionsData.unshift({ | ||
valid: res[0], | ||
message: res[1], | ||
valid: result[0], | ||
message: result[1], | ||
}); | ||
} | ||
executeValidation(field) { | ||
// otherwise find an error message to show | ||
field.validationFunctionsData.map((rule) => rule.valid === false && field.invalidate(rule.message, false)); | ||
field.validationFunctionsData.forEach(({ valid, message }) => { | ||
if (valid === false) { | ||
field.invalidate(message, false); | ||
} | ||
}); | ||
} | ||
executeAsyncValidation(field) { | ||
if (field.validationAsyncData.valid === false) { | ||
field.invalidate(field.validationAsyncData.message, false, true); | ||
const data = field.validationAsyncData; | ||
if (data.valid === false) { | ||
field.invalidate(data.message, false, true); | ||
} | ||
} | ||
handleFunctionResult($fn, field) { | ||
// executre validation function | ||
const res = $fn({ | ||
handleFunctionResult(fn, field) { | ||
const result = fn({ | ||
validator: this.validator, | ||
@@ -126,31 +108,14 @@ form: this.state.form, | ||
}); | ||
/** | ||
Handle "array" | ||
*/ | ||
if (Array.isArray(res)) { | ||
const isValid = res[0] || false; | ||
const message = res[1] || "Error"; | ||
return [isValid, message]; | ||
if (Array.isArray(result)) { | ||
return [result[0] || false, result[1] || "Error"]; | ||
} | ||
/** | ||
Handle "boolean" | ||
*/ | ||
if (lodash_1.default.isBoolean(res)) { | ||
return [res, "Error"]; | ||
if (lodash_1.default.isBoolean(result)) { | ||
return [result, "Error"]; | ||
} | ||
/** | ||
Handle "string" | ||
*/ | ||
if (lodash_1.default.isString(res)) { | ||
return [false, res]; | ||
if (lodash_1.default.isString(result)) { | ||
return [false, result]; | ||
} | ||
/** | ||
Handle "object / promise" | ||
*/ | ||
if (isPromise(res)) { | ||
return res; // the promise | ||
if (isPromise(result)) { | ||
return result; | ||
} | ||
/** | ||
Handle other cases | ||
*/ | ||
return [false, "Error"]; | ||
@@ -161,5 +126,5 @@ } | ||
exports.default = (config) => ({ | ||
class: VJF, | ||
class: (VJF), | ||
config, | ||
}); | ||
//# sourceMappingURL=VJF.js.map |
import { ValidationPlugin, ValidationPluginConfig } from "../models/ValidatorInterface"; | ||
declare const _default: (config?: ValidationPluginConfig) => ValidationPlugin; | ||
declare const _default: <TValidator = any>(config?: ValidationPluginConfig<TValidator>) => ValidationPlugin<TValidator>; | ||
export default _default; | ||
//# sourceMappingURL=YUP.d.ts.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/** | ||
YUP - Dead simple Object schema validation | ||
const plugins = { | ||
yup: $yup({ | ||
package: yup, | ||
schema: (y) => (), | ||
extend, | ||
}), | ||
}; | ||
*/ | ||
class YUP { | ||
@@ -27,3 +15,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -34,3 +22,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -41,3 +29,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -48,3 +36,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -55,3 +43,3 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -65,4 +53,4 @@ this.state = state; | ||
} | ||
// Metodo per estendere il validatore | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
@@ -75,4 +63,10 @@ this.extend({ | ||
} | ||
// Metodo di validazione principale | ||
validate(field) { | ||
const $p = new Promise((resolve) => this.validator | ||
const fieldValidationPromise = this.createValidationPromise(field); | ||
this.promises.push(fieldValidationPromise); | ||
} | ||
// Creazione della promise per la validazione | ||
createValidationPromise(field) { | ||
return new Promise((resolve) => this.validator | ||
.reach(this.schema, field.path) | ||
@@ -83,4 +77,4 @@ .label(field.label) | ||
.catch((error) => this.handleAsyncFails(field, resolve, error))); | ||
this.promises.push($p); | ||
} | ||
// Gestione dei successi della validazione asincrona | ||
handleAsyncPasses(field, resolve) { | ||
@@ -90,2 +84,3 @@ field.setValidationAsyncData(true); | ||
} | ||
// Gestione dei fallimenti della validazione asincrona | ||
handleAsyncFails(field, resolve, error) { | ||
@@ -96,2 +91,3 @@ field.setValidationAsyncData(false, error.errors[0]); | ||
} | ||
// Esecuzione della validazione asincrona | ||
executeAsyncValidation(field) { | ||
@@ -104,5 +100,5 @@ if (field.validationAsyncData.valid === false) { | ||
exports.default = (config) => ({ | ||
class: YUP, | ||
class: (YUP), | ||
config, | ||
}); | ||
//# sourceMappingURL=YUP.js.map |
@@ -1,4 +0,21 @@ | ||
import { ValidationPlugin, ValidationPluginConfig } from "../models/ValidatorInterface"; | ||
declare const _default: (config?: ValidationPluginConfig) => ValidationPlugin; | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { ZodSchema } from "zod"; | ||
import { ValidationPlugin, ValidationPluginConfig, ValidationPluginConstructor, ValidationPluginInterface } from "../models/ValidatorInterface"; | ||
export declare class ZOD<TValidator = any> implements ValidationPluginInterface { | ||
promises: Promise<any>[]; | ||
config: ValidationPluginConfig; | ||
state: any; | ||
extend?: (args: { | ||
validator: TValidator; | ||
form: FormInterface; | ||
}) => void; | ||
validator: any; | ||
schema: ZodSchema<any>; | ||
constructor({ config, state, promises, }: ValidationPluginConstructor); | ||
extendValidator(): void; | ||
validate(field: FieldInterface): void; | ||
} | ||
declare const _default: <TValidator = any>(config?: ValidationPluginConfig<TValidator>) => ValidationPlugin<TValidator>; | ||
export default _default; | ||
//# sourceMappingURL=ZOD.d.ts.map |
@@ -6,2 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ZOD = void 0; | ||
const lodash_1 = __importDefault(require("lodash")); | ||
@@ -14,3 +15,3 @@ class ZOD { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -21,3 +22,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -28,3 +29,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -35,3 +36,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -42,3 +43,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -49,6 +50,7 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
@@ -60,4 +62,3 @@ this.validator = config.package; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -74,11 +75,13 @@ validator: this.validator, | ||
return; | ||
const errors = (_a = lodash_1.default.get(result.error.format(), field.path)) === null || _a === void 0 ? void 0 : _a._errors; | ||
if (errors === null || errors === void 0 ? void 0 : errors.length) | ||
field.validationErrorStack = errors; | ||
const fieldErrors = (_a = lodash_1.default.get(result.error.format(), field.path)) === null || _a === void 0 ? void 0 : _a._errors; | ||
if (fieldErrors === null || fieldErrors === void 0 ? void 0 : fieldErrors.length) { | ||
field.validationErrorStack = fieldErrors; | ||
} | ||
} | ||
} | ||
exports.ZOD = ZOD; | ||
exports.default = (config) => ({ | ||
class: ZOD, | ||
class: (ZOD), | ||
config, | ||
}); | ||
//# sourceMappingURL=ZOD.js.map |
{ | ||
"name": "mobx-react-form", | ||
"license": "MIT", | ||
"version": "6.11.2", | ||
"version": "6.12.0", | ||
"author": "Claudio Savino <claudio.savino@me.com> (https://twitter.com/foxhound87)", | ||
@@ -6,0 +6,0 @@ "description": "Reactive MobX Form State Management", |
@@ -109,7 +109,2 @@ import { | ||
interface ValidationAsyncDataInterface { | ||
valid?: boolean; | ||
message?: string; | ||
} | ||
export default class Field extends Base implements FieldInterface { | ||
@@ -175,3 +170,3 @@ hasInitialNestedFields = false; | ||
validationFunctionsData: any[] = []; | ||
validationAsyncData: ValidationAsyncDataInterface | undefined; | ||
validationAsyncData: any; | ||
debouncedValidation: any; | ||
@@ -298,3 +293,3 @@ | ||
return ( | ||
(this.validationAsyncData?.valid === false && | ||
((this.validationAsyncData as any)?.valid === false && | ||
!_.isEmpty(this.validationAsyncData)) || | ||
@@ -762,3 +757,3 @@ !_.isEmpty(this.validationErrorStack) || | ||
this.errorAsync = null; | ||
this.validationAsyncData = {}; | ||
this.validationAsyncData = undefined; | ||
this.validationFunctionsData = []; | ||
@@ -765,0 +760,0 @@ this.validationErrorStack = []; |
@@ -19,2 +19,3 @@ import {BaseInterface} from "./BaseInterface"; | ||
validationFunctionsData: any[]; | ||
validationAsyncData: { valid?: boolean, message?: string | null;}; | ||
debouncedValidation: any; | ||
@@ -73,3 +74,3 @@ autoFocus: boolean; | ||
invalidate(message?: string, deep?: boolean, async?: boolean): void; | ||
setValidationAsyncData(valid: boolean, message: string): void; | ||
setValidationAsyncData(valid?: boolean, message?: string): void; | ||
resetValidation(deep: boolean): void; | ||
@@ -76,0 +77,0 @@ clear(deep?: boolean): void; |
import Form from "../Form"; | ||
import Field from "../Field"; | ||
import {FieldInterface} from "./FieldInterface"; | ||
import {FormInterface} from "./FormInterface"; | ||
import {StateInterface} from "./StateInterface"; | ||
import { FieldInterface } from "./FieldInterface"; | ||
import { FormInterface } from "./FormInterface"; | ||
import { StateInterface } from "./StateInterface"; | ||
@@ -13,6 +13,6 @@ export interface ValidatorConstructor { | ||
export interface ValidateOptionsInterface { | ||
showErrors?: boolean, | ||
related?: boolean, | ||
field?: FieldInterface, | ||
path?: string, | ||
showErrors?: boolean; | ||
related?: boolean; | ||
field?: FieldInterface; | ||
path?: string; | ||
} | ||
@@ -34,33 +34,18 @@ | ||
export type ValidationPlugin = { | ||
class: any, | ||
config?: ValidationPluginConfig, | ||
}; | ||
export interface ValidationPlugins { | ||
[key: string]: ValidationPlugin | undefined; | ||
vjf?: ValidationPlugin; | ||
dvr?: ValidationPlugin; | ||
svk?: ValidationPlugin; | ||
yup?: ValidationPlugin; | ||
zod?: ValidationPlugin; | ||
joi?: ValidationPlugin; | ||
} | ||
export type ValidationPackage = any; | ||
export type ExtendPlugin = ({ validator, form }: { | ||
validator: any, // the plugin instance | ||
form: FormInterface | ||
export type ExtendPlugin<TValidator = ValidationPackage> = (args: { | ||
validator: TValidator; | ||
form: FormInterface; | ||
}) => void; | ||
export interface ValidationPluginConfig { | ||
package: ValidationPackage; | ||
export interface ValidationPluginConfig<TValidator = ValidationPackage> { | ||
package: TValidator; | ||
schema?: any; | ||
options?: any; | ||
extend?: ExtendPlugin; | ||
extend?: ExtendPlugin<TValidator>; | ||
} | ||
export interface ValidationPluginConstructor { | ||
config: ValidationPluginConfig; | ||
export interface ValidationPluginConstructor<TValidator = ValidationPackage> { | ||
config: ValidationPluginConfig<TValidator>; | ||
state: StateInterface; | ||
@@ -70,10 +55,26 @@ promises: Promise<unknown>[]; | ||
export interface ValidationPluginInterface extends ValidationPluginConstructor { | ||
validator: ValidatorInterface; | ||
export interface ValidationPluginInterface<TValidator = ValidationPackage> | ||
extends ValidationPluginConstructor<TValidator> { | ||
validator: TValidator; | ||
schema?: any; | ||
extend?: ExtendPlugin; | ||
validate(field: FieldInterface); | ||
class?(constructor: ValidationPluginConstructor): void; | ||
extend?: ExtendPlugin<TValidator>; | ||
validate(field: FieldInterface): void; | ||
class?(constructor: ValidationPluginConstructor<TValidator>): void; | ||
} | ||
export type ValidationPlugin<TValidator = ValidationPackage> = { | ||
class: any; | ||
config?: ValidationPluginConfig<TValidator>; | ||
}; | ||
export interface ValidationPlugins { | ||
[key: string]: ValidationPlugin | undefined; | ||
vjf?: ValidationPlugin; | ||
dvr?: ValidationPlugin; | ||
svk?: ValidationPlugin; | ||
yup?: ValidationPlugin; | ||
zod?: ValidationPlugin; | ||
joi?: ValidationPlugin; | ||
} | ||
export type DriversMap = { | ||
@@ -88,3 +89,2 @@ [key in keyof ValidationPlugins]: ValidationPluginInterface; | ||
export default ValidatorInterface; |
import _ from "lodash"; | ||
import { | ||
ValidationPlugin, | ||
ValidationPluginConfig, | ||
ValidationPluginConstructor, | ||
ValidationPluginInterface, | ||
} from "../models/ValidatorInterface"; | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { ValidationPlugin, ValidationPluginConfig, ValidationPluginConstructor, ValidationPluginInterface } from "src/models/ValidatorInterface"; | ||
/** | ||
Declarative Validation Rules | ||
export class DVR<TValidator = any> implements ValidationPluginInterface<TValidator> { | ||
promises: Promise<any>[]; | ||
config: any; | ||
state: any; | ||
extend?: (args: { validator: TValidator; form: FormInterface }) => void; | ||
validator: TValidator; | ||
schema?: any; | ||
const plugins = { | ||
dvr: dvr({ | ||
package: validatorjs, | ||
extend: callback, | ||
}), | ||
}; | ||
*/ | ||
export class DVR implements ValidationPluginInterface { | ||
promises = []; | ||
config = null; | ||
state = null; | ||
extend = null; | ||
validator = null; | ||
constructor({ | ||
@@ -35,3 +18,3 @@ config, | ||
promises = [], | ||
}: ValidationPluginConstructor) { | ||
}: ValidationPluginConstructor<TValidator>) { | ||
this.state = state; | ||
@@ -45,4 +28,3 @@ this.promises = promises; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -55,4 +37,3 @@ validator: this.validator, | ||
validate(field) { | ||
// get form fields data | ||
validate(field: FieldInterface) { | ||
const data = this.state.form.validatedValues; | ||
@@ -63,3 +44,3 @@ this.validateFieldAsync(field, data); | ||
makeLabels(validation, field) { | ||
makeLabels(validation: any, field: FieldInterface) { | ||
const labels = { [field.path]: field.label }; | ||
@@ -92,30 +73,20 @@ _.forIn(validation.rules[field.path], (rule) => { | ||
validateFieldSync(field, data) { | ||
validateFieldSync(field: FieldInterface, data: any) { | ||
const $rules = this.rules(field.rules, "sync"); | ||
// exit if no rules found | ||
if (_.isEmpty($rules[0])) return; | ||
// get field rules | ||
const rules = { [field.path]: $rules }; | ||
// create the validator instance | ||
const validation = new this.validator(data, rules); | ||
// set label into errors messages instead key | ||
const validation = new (this.validator as any)(data, rules); | ||
this.makeLabels(validation, field); | ||
// check validation | ||
if (validation.passes()) return; | ||
// the validation is failed, set the field error | ||
field.invalidate(_.head(validation.errors.get(field.path)), false); | ||
} | ||
validateFieldAsync(field, data) { | ||
validateFieldAsync(field: FieldInterface, data: any) { | ||
const $rules = this.rules(field.rules, "async"); | ||
// exit if no rules found | ||
if (_.isEmpty($rules[0])) return; | ||
// get field rules | ||
const rules = { [field.path]: $rules }; | ||
// create the validator instance | ||
const validation = new this.validator(data, rules); | ||
// set label into errors messages instead key | ||
const validation = new (this.validator as any)(data, rules); | ||
this.makeLabels(validation, field); | ||
const $p = new Promise((resolve) => | ||
const $p = new Promise((resolve: any) => | ||
validation.checkAsync( | ||
@@ -130,3 +101,3 @@ () => this.handleAsyncPasses(field, resolve), | ||
handleAsyncPasses(field, resolve) { | ||
handleAsyncPasses(field: FieldInterface, resolve: () => void) { | ||
field.setValidationAsyncData(true); | ||
@@ -136,4 +107,7 @@ resolve(); | ||
handleAsyncFails(field, validation, resolve) { | ||
field.setValidationAsyncData(false, _.head(validation.errors.get(field.path))); | ||
handleAsyncFails(field: FieldInterface, validation: any, resolve: () => void) { | ||
field.setValidationAsyncData( | ||
false, | ||
_.head(validation.errors.get(field.path)) | ||
); | ||
this.executeAsyncValidation(field); | ||
@@ -143,3 +117,3 @@ resolve(); | ||
executeAsyncValidation(field) { | ||
executeAsyncValidation(field: FieldInterface) { | ||
if (field.validationAsyncData.valid === false) { | ||
@@ -150,10 +124,9 @@ field.invalidate(field.validationAsyncData.message, false, true); | ||
rules(rules, type) { | ||
rules(rules: any, type: "sync" | "async") { | ||
const $rules = _.isString(rules) ? _.split(rules, "|") : rules; | ||
// eslint-disable-next-line new-cap | ||
const v = new this.validator(); | ||
const v = new (this.validator as any)(); | ||
return _.filter($rules, ($rule) => | ||
type === "async" | ||
? v.getRule(_.split($rule, ":")[0]).async | ||
: !v.getRule(_.split($rule, ":")[0]).async | ||
? v.getRule(_.split($rule, ":")[0])?.async | ||
: !v.getRule(_.split($rule, ":")[0])?.async | ||
); | ||
@@ -163,5 +136,7 @@ } | ||
export default (config?: ValidationPluginConfig): ValidationPlugin => ({ | ||
class: DVR, | ||
config, | ||
}); | ||
export default <TValidator = any>( | ||
config?: ValidationPluginConfig<TValidator> | ||
): ValidationPlugin<TValidator> => ({ | ||
class: DVR<TValidator>, | ||
config, | ||
}); |
import _ from "lodash"; | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { | ||
@@ -9,15 +11,10 @@ ValidationPlugin, | ||
class JOI implements ValidationPluginInterface { | ||
promises = []; | ||
class JOI<TValidator = any> implements ValidationPluginInterface<TValidator> { | ||
promises: Promise<any>[]; | ||
config: ValidationPluginConfig<TValidator>; | ||
state: any; | ||
extend?: (args: { validator: TValidator; form: FormInterface }) => void; | ||
validator: TValidator; | ||
schema: any; | ||
config = null; | ||
state = null; | ||
extend = null; | ||
validator = null; | ||
schema = null; | ||
constructor({ | ||
@@ -27,5 +24,6 @@ config, | ||
promises = [], | ||
}: ValidationPluginConstructor) { | ||
}: ValidationPluginConstructor<TValidator>) { | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config?.extend; | ||
@@ -38,3 +36,2 @@ this.validator = config.package; | ||
extendValidator(): void { | ||
// extend using "extend" callback | ||
if (typeof this.extend === "function") { | ||
@@ -48,18 +45,22 @@ this.extend({ | ||
validate(field): void { | ||
const { error } = this.schema.validate(field.state.form.validatedValues, { abortEarly: false }); | ||
validate(field: FieldInterface): void { | ||
const data = this.state.form.validatedValues; | ||
const { error } = this.schema.validate(data, { abortEarly: false }); | ||
if (!error) return; | ||
const fieldPathArray = field.path.split('.'); | ||
const fieldPathArray = field.path.split("."); | ||
const fieldErrors = error.details | ||
.filter(detail => { | ||
const errorPathString = detail.path.join('.'); | ||
const fieldPathString = fieldPathArray.join('.'); | ||
return errorPathString === fieldPathString || errorPathString.startsWith(`${fieldPathString}.`); | ||
.filter((detail) => { | ||
const errorPathString = detail.path.join("."); | ||
const fieldPathString = fieldPathArray.join("."); | ||
return ( | ||
errorPathString === fieldPathString || | ||
errorPathString.startsWith(`${fieldPathString}.`) | ||
); | ||
}) | ||
.map(detail => { | ||
// Replace the path in the error message with the custom label | ||
const label = detail.context?.label || detail.path.join('.'); | ||
const message = detail.message.replace(`${detail.path.join('.')}`, label); | ||
.map((detail) => { | ||
const label = detail.context?.label || detail.path.join("."); | ||
const message = detail.message.replace(`${detail.path.join(".")}`, label); | ||
return message; | ||
@@ -74,5 +75,7 @@ }); | ||
export default (config?: ValidationPluginConfig): ValidationPlugin => ({ | ||
class: JOI, | ||
config, | ||
}); | ||
export default <TValidator = any>( | ||
config?: ValidationPluginConfig<TValidator> | ||
): ValidationPlugin<TValidator> => ({ | ||
class: JOI<TValidator>, | ||
config, | ||
}); |
import _ from "lodash"; | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { | ||
@@ -9,31 +11,18 @@ ValidationPlugin, | ||
const isPromise = (obj) => | ||
!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function"); | ||
function isPromise(obj: any): obj is Promise<any> { | ||
return ( | ||
!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function") | ||
); | ||
} | ||
/** | ||
Schema Validation Keywords | ||
class SVK<TValidator = any> implements ValidationPluginInterface<TValidator> { | ||
promises: Promise<any>[]; | ||
config: ValidationPluginConfig<TValidator>; | ||
state: any; | ||
extend?: (args: { validator: TValidator; form: FormInterface }) => void; | ||
validator: any; | ||
schema: any; | ||
const plugins = { | ||
svk: svk({ | ||
package: ajv, | ||
extend: callback, | ||
}), | ||
}; | ||
*/ | ||
class SVK implements ValidationPluginInterface { | ||
promises = []; | ||
config = null; | ||
state = null; | ||
extend = null; | ||
validator = null; | ||
schema = null; | ||
constructor({ | ||
@@ -43,12 +32,14 @@ config, | ||
promises = [], | ||
}: ValidationPluginConstructor) { | ||
}: ValidationPluginConstructor<TValidator>) { | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config?.extend; | ||
this.schema = config.schema; | ||
this.initAJV(config); | ||
this.initValidator(); | ||
} | ||
extendOptions(options = {}) { | ||
return Object.assign(options, { | ||
extendOptions(options: any = {}) { | ||
return { | ||
...options, | ||
errorDataPath: "property", | ||
@@ -58,26 +49,24 @@ allErrors: true, | ||
v5: true, | ||
}); | ||
}; | ||
} | ||
initAJV(config) { | ||
// get ajv package | ||
const ajv = config.package; | ||
// create ajv instance | ||
const validator = new ajv(this.extendOptions(config.options)); | ||
// extend ajv using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
initValidator(): void { | ||
const AJV = this.config.package as any; | ||
const validatorInstance = new AJV(this.extendOptions(this.config.options)); | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
form: this.state.form, | ||
validator, | ||
validator: validatorInstance, | ||
}); | ||
} | ||
// create ajv validator (compiling rules) | ||
this.validator = validator.compile(this.schema); | ||
this.validator = validatorInstance.compile(this.schema); | ||
} | ||
validate(field) { | ||
const validate = this.validator(field.state.form.validatedValues); | ||
// check if is $async schema | ||
if (isPromise(validate)) { | ||
const $p = validate | ||
validate(field: FieldInterface): void { | ||
const result = this.validator(field.state.form.validatedValues); | ||
if (isPromise(result)) { | ||
const $p = result | ||
.then(() => field.setValidationAsyncData(true)) | ||
@@ -87,34 +76,26 @@ .catch((err) => err && this.handleAsyncError(field, err.errors)) | ||
// push the promise into array | ||
this.promises.push($p); | ||
return; | ||
} | ||
// check sync errors | ||
this.handleSyncError(field, this.validator.errors); | ||
} | ||
handleSyncError(field, errors) { | ||
const fieldErrorObj = this.findError(field.path, errors); | ||
// if fieldErrorObj is not undefined, the current field is invalid. | ||
if (_.isUndefined(fieldErrorObj)) return; | ||
// the current field is now invalid | ||
// add additional info to the message | ||
const msg = `${field.label} ${fieldErrorObj.message}`; | ||
// invalidate the current field with message | ||
field.invalidate(msg, false); | ||
handleSyncError(field: FieldInterface, errors: any[]): void { | ||
const fieldError = this.findError(field.path, errors); | ||
if (!fieldError) return; | ||
const message = `${field.label} ${fieldError.message}`; | ||
field.invalidate(message, false); | ||
} | ||
handleAsyncError(field, errors) { | ||
// find current field error message from ajv errors | ||
const fieldErrorObj = this.findError(field.path, errors); | ||
// if fieldErrorObj is not undefined, the current field is invalid. | ||
if (_.isUndefined(fieldErrorObj)) return; | ||
// the current field is now invalid | ||
// add additional info to the message | ||
const msg = `${field.label} ${fieldErrorObj.message}`; | ||
// set async validation data on the field | ||
field.setValidationAsyncData(false, msg); | ||
handleAsyncError(field: FieldInterface, errors: any[]): void { | ||
const fieldError = this.findError(field.path, errors); | ||
if (!fieldError) return; | ||
const message = `${field.label} ${fieldError.message}`; | ||
field.setValidationAsyncData(false, message); | ||
} | ||
findError(path, errors) { | ||
findError(path: string, errors: any[]): any { | ||
return _.find(errors, ({ dataPath }) => { | ||
@@ -129,5 +110,6 @@ let $dataPath; | ||
executeAsyncValidation(field) { | ||
if (field.validationAsyncData.valid === false) { | ||
field.invalidate(field.validationAsyncData.message, false, true); | ||
executeAsyncValidation(field: FieldInterface): void { | ||
const asyncData = field.validationAsyncData; | ||
if (asyncData.valid === false) { | ||
field.invalidate(asyncData.message, false, true); | ||
} | ||
@@ -137,5 +119,7 @@ } | ||
export default (config?: ValidationPluginConfig): ValidationPlugin => ({ | ||
class: SVK, | ||
config, | ||
}); | ||
export default <TValidator = any>( | ||
config?: ValidationPluginConfig<TValidator> | ||
): ValidationPlugin<TValidator> => ({ | ||
class: SVK<TValidator>, | ||
config, | ||
}); |
@@ -0,1 +1,4 @@ | ||
import _ from "lodash"; | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { | ||
@@ -7,31 +10,18 @@ ValidationPlugin, | ||
} from "../models/ValidatorInterface"; | ||
import _ from "lodash"; | ||
import { toJS } from "mobx"; | ||
const isPromise = (obj) => | ||
!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function"); | ||
function isPromise(obj: any): obj is Promise<any> { | ||
return ( | ||
!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function") | ||
); | ||
} | ||
/** | ||
Vanilla JavaScript Functions | ||
export class VJF<TValidator = any> implements ValidationPluginInterface<TValidator> { | ||
promises: Promise<any>[]; | ||
config: ValidationPluginConfig<TValidator>; | ||
state: any; | ||
extend?: (args: { validator: TValidator; form: FormInterface }) => void; | ||
validator: TValidator; | ||
const plugins = { | ||
vkf: vkf({ | ||
package: validator, | ||
}), | ||
}; | ||
*/ | ||
export class VJF implements ValidationPluginInterface { | ||
promises = []; | ||
config = null; | ||
state = null; | ||
extend = null; | ||
validator = null; | ||
constructor({ | ||
@@ -41,5 +31,6 @@ config, | ||
promises = [], | ||
}: ValidationPluginConstructor) { | ||
}: ValidationPluginConstructor<TValidator>) { | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config?.extend; | ||
@@ -50,5 +41,4 @@ this.validator = config?.package; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
extendValidator(): void { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -61,53 +51,47 @@ validator: this.validator, | ||
validate(field) { | ||
// exit if field does not have validation functions | ||
validate(field: FieldInterface): void { | ||
if (!field.validators) return; | ||
// get validators from validate property | ||
const $fn = field.validators; | ||
// map only if is an array of validator functions | ||
if (Array.isArray($fn)) { | ||
$fn.map((fn) => this.collectData(fn, field)); | ||
} | ||
// it's just one function // DEPRECATED | ||
// if (typeof $fn === 'function') { | ||
// this.collectData($fn, field); | ||
// } | ||
// execute the validation function | ||
const validators = Array.isArray(field.validators) ? field.validators : [field.validators]; | ||
validators.forEach((fn) => this.collectData(fn, field)); | ||
this.executeValidation(field); | ||
} | ||
collectData($fn, field) { | ||
const res = this.handleFunctionResult($fn, field); | ||
// check and execute only if is a promise | ||
if (isPromise(res)) { | ||
const $p = res | ||
.then(($res) => field.setValidationAsyncData($res[0], $res[1])) | ||
collectData(fn: Function, field: FieldInterface): void { | ||
const result = this.handleFunctionResult(fn, field); | ||
if (isPromise(result)) { | ||
const $p = result | ||
.then(([valid, message]) => field.setValidationAsyncData(valid, message)) | ||
.then(() => this.executeAsyncValidation(field)); | ||
// push the promise into array | ||
this.promises.push($p); | ||
return; | ||
} | ||
// is a plain function | ||
field.validationFunctionsData.unshift({ | ||
valid: res[0], | ||
message: res[1], | ||
valid: result[0], | ||
message: result[1], | ||
}); | ||
} | ||
executeValidation(field) { | ||
// otherwise find an error message to show | ||
field.validationFunctionsData.map( | ||
(rule) => rule.valid === false && field.invalidate(rule.message, false) | ||
); | ||
executeValidation(field: FieldInterface): void { | ||
field.validationFunctionsData.forEach(({ valid, message }) => { | ||
if (valid === false) { | ||
field.invalidate(message, false); | ||
} | ||
}); | ||
} | ||
executeAsyncValidation(field) { | ||
if (field.validationAsyncData.valid === false) { | ||
field.invalidate(field.validationAsyncData.message, false, true); | ||
executeAsyncValidation(field: FieldInterface): void { | ||
const data = field.validationAsyncData; | ||
if (data.valid === false) { | ||
field.invalidate(data.message, false, true); | ||
} | ||
} | ||
handleFunctionResult($fn, field) { | ||
// executre validation function | ||
const res = $fn({ | ||
handleFunctionResult(fn: Function, field: FieldInterface): [boolean, string] | Promise<[boolean, string]> { | ||
const result = fn({ | ||
validator: this.validator, | ||
@@ -118,35 +102,18 @@ form: this.state.form, | ||
/** | ||
Handle "array" | ||
*/ | ||
if (Array.isArray(res)) { | ||
const isValid = res[0] || false; | ||
const message = res[1] || "Error"; | ||
return [isValid, message]; | ||
if (Array.isArray(result)) { | ||
return [result[0] || false, result[1] || "Error"]; | ||
} | ||
/** | ||
Handle "boolean" | ||
*/ | ||
if (_.isBoolean(res)) { | ||
return [res, "Error"]; | ||
if (_.isBoolean(result)) { | ||
return [result, "Error"]; | ||
} | ||
/** | ||
Handle "string" | ||
*/ | ||
if (_.isString(res)) { | ||
return [false, res]; | ||
if (_.isString(result)) { | ||
return [false, result]; | ||
} | ||
/** | ||
Handle "object / promise" | ||
*/ | ||
if (isPromise(res)) { | ||
return res; // the promise | ||
if (isPromise(result)) { | ||
return result; | ||
} | ||
/** | ||
Handle other cases | ||
*/ | ||
return [false, "Error"]; | ||
@@ -156,5 +123,7 @@ } | ||
export default (config?: ValidationPluginConfig): ValidationPlugin => ({ | ||
class: VJF, | ||
config, | ||
}); | ||
export default <TValidator = any>( | ||
config?: ValidationPluginConfig<TValidator> | ||
): ValidationPlugin<TValidator> => ({ | ||
class: VJF<TValidator>, | ||
config, | ||
}); |
@@ -8,29 +8,12 @@ import { | ||
import _ from "lodash"; | ||
import FormInterface from "src/models/FormInterface"; | ||
/** | ||
YUP - Dead simple Object schema validation | ||
class YUP<TValidator = any> implements ValidationPluginInterface { | ||
promises: Promise<any>[] = []; | ||
config: ValidationPluginConfig<TValidator>; | ||
state: any; | ||
extend?: (args: { validator: TValidator; form: FormInterface }) => void; | ||
validator: TValidator; | ||
schema: any; | ||
const plugins = { | ||
yup: $yup({ | ||
package: yup, | ||
schema: (y) => (), | ||
extend, | ||
}), | ||
}; | ||
*/ | ||
class YUP implements ValidationPluginInterface { | ||
promises = []; | ||
config = null; | ||
state = null; | ||
extend = null; | ||
validator = null; | ||
schema = null; | ||
constructor({ | ||
@@ -49,4 +32,4 @@ config, | ||
extendValidator() { | ||
// extend using "extend" callback | ||
// Metodo per estendere il validatore | ||
extendValidator(): void { | ||
if (typeof this.extend === 'function') { | ||
@@ -60,5 +43,12 @@ this.extend({ | ||
validate(field) { | ||
const $p = new Promise((resolve) => | ||
this.validator | ||
// Metodo di validazione principale | ||
validate(field: any): void { | ||
const fieldValidationPromise = this.createValidationPromise(field); | ||
this.promises.push(fieldValidationPromise); | ||
} | ||
// Creazione della promise per la validazione | ||
private createValidationPromise(field: any): Promise<any> { | ||
return new Promise((resolve) => | ||
(this.validator as any) | ||
.reach(this.schema, field.path) | ||
@@ -70,7 +60,6 @@ .label(field.label) | ||
); | ||
this.promises.push($p); | ||
} | ||
handleAsyncPasses(field, resolve) { | ||
// Gestione dei successi della validazione asincrona | ||
private handleAsyncPasses(field: any, resolve: Function): void { | ||
field.setValidationAsyncData(true); | ||
@@ -80,3 +69,4 @@ resolve(); | ||
handleAsyncFails(field, resolve, error) { | ||
// Gestione dei fallimenti della validazione asincrona | ||
private handleAsyncFails(field: any, resolve: Function, error: any): void { | ||
field.setValidationAsyncData(false, error.errors[0]); | ||
@@ -87,3 +77,4 @@ this.executeAsyncValidation(field); | ||
executeAsyncValidation(field) { | ||
// Esecuzione della validazione asincrona | ||
private executeAsyncValidation(field: any): void { | ||
if (field.validationAsyncData.valid === false) { | ||
@@ -95,5 +86,7 @@ field.invalidate(field.validationAsyncData.message, false, true); | ||
export default (config?: ValidationPluginConfig): ValidationPlugin => ({ | ||
class: YUP, | ||
config, | ||
}); | ||
export default <TValidator = any>( | ||
config?: ValidationPluginConfig<TValidator> | ||
): ValidationPlugin<TValidator> => ({ | ||
class: YUP<TValidator>, | ||
config, | ||
}); |
import _ from "lodash"; | ||
import FieldInterface from "src/models/FieldInterface"; | ||
import FormInterface from "src/models/FormInterface"; | ||
import { ZodSchema, ZodError } from "zod"; | ||
import { | ||
@@ -9,16 +12,10 @@ ValidationPlugin, | ||
class ZOD implements ValidationPluginInterface { | ||
export class ZOD<TValidator = any> implements ValidationPluginInterface { | ||
promises: Promise<any>[]; | ||
config: ValidationPluginConfig; | ||
state: any; | ||
extend?: (args: { validator: TValidator; form: FormInterface }) => void; | ||
validator: any; | ||
schema: ZodSchema<any>; | ||
promises = []; | ||
config = null; | ||
state = null; | ||
extend = null; | ||
validator = null; | ||
schema = null; | ||
constructor({ | ||
@@ -31,5 +28,7 @@ config, | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config?.extend; | ||
this.validator = config.package; | ||
this.schema = config.schema; | ||
this.schema = config.schema as ZodSchema<any>; | ||
this.extendValidator(); | ||
@@ -39,4 +38,3 @@ } | ||
extendValidator(): void { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -49,13 +47,21 @@ validator: this.validator, | ||
validate(field): void { | ||
validate(field: FieldInterface): void { | ||
const result = this.schema.safeParse(field.state.form.validatedValues); | ||
if (result.success) return; | ||
const errors = _.get(result.error.format(), field.path)?._errors; | ||
if (errors?.length) field.validationErrorStack = errors; | ||
const fieldErrors = _.get((result as any).error.format(), field.path)?._errors; | ||
if (fieldErrors?.length) { | ||
field.validationErrorStack = fieldErrors; | ||
} | ||
} | ||
} | ||
export default (config?: ValidationPluginConfig): ValidationPlugin => ({ | ||
class: ZOD, | ||
config, | ||
}); | ||
export default <TValidator = any>( | ||
config?: ValidationPluginConfig<TValidator> | ||
): ValidationPlugin<TValidator> => ({ | ||
class: ZOD<TValidator>, | ||
config, | ||
}); |
@@ -28,13 +28,2 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
const lodash_1 = __importDefault(__webpack_require__(/*! lodash */ "lodash")); | ||
/** | ||
Declarative Validation Rules | ||
const plugins = { | ||
dvr: dvr({ | ||
package: validatorjs, | ||
extend: callback, | ||
}), | ||
}; | ||
*/ | ||
class DVR { | ||
@@ -46,3 +35,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -53,3 +42,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -60,3 +49,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -67,3 +56,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -74,4 +63,10 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
Object.defineProperty(this, "schema", { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
@@ -84,4 +79,3 @@ this.promises = promises; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -94,3 +88,2 @@ validator: this.validator, | ||
validate(field) { | ||
// get form fields data | ||
const data = this.state.form.validatedValues; | ||
@@ -126,15 +119,9 @@ this.validateFieldAsync(field, data); | ||
const $rules = this.rules(field.rules, "sync"); | ||
// exit if no rules found | ||
if (lodash_1.default.isEmpty($rules[0])) | ||
return; | ||
// get field rules | ||
const rules = { [field.path]: $rules }; | ||
// create the validator instance | ||
const validation = new this.validator(data, rules); | ||
// set label into errors messages instead key | ||
this.makeLabels(validation, field); | ||
// check validation | ||
if (validation.passes()) | ||
return; | ||
// the validation is failed, set the field error | ||
field.invalidate(lodash_1.default.head(validation.errors.get(field.path)), false); | ||
@@ -144,10 +131,6 @@ } | ||
const $rules = this.rules(field.rules, "async"); | ||
// exit if no rules found | ||
if (lodash_1.default.isEmpty($rules[0])) | ||
return; | ||
// get field rules | ||
const rules = { [field.path]: $rules }; | ||
// create the validator instance | ||
const validation = new this.validator(data, rules); | ||
// set label into errors messages instead key | ||
this.makeLabels(validation, field); | ||
@@ -173,7 +156,9 @@ const $p = new Promise((resolve) => validation.checkAsync(() => this.handleAsyncPasses(field, resolve), () => this.handleAsyncFails(field, validation, resolve))); | ||
const $rules = lodash_1.default.isString(rules) ? lodash_1.default.split(rules, "|") : rules; | ||
// eslint-disable-next-line new-cap | ||
const v = new this.validator(); | ||
return lodash_1.default.filter($rules, ($rule) => type === "async" | ||
? v.getRule(lodash_1.default.split($rule, ":")[0]).async | ||
: !v.getRule(lodash_1.default.split($rule, ":")[0]).async); | ||
return lodash_1.default.filter($rules, ($rule) => { | ||
var _a, _b; | ||
return type === "async" | ||
? (_a = v.getRule(lodash_1.default.split($rule, ":")[0])) === null || _a === void 0 ? void 0 : _a.async | ||
: !((_b = v.getRule(lodash_1.default.split($rule, ":")[0])) === null || _b === void 0 ? void 0 : _b.async); | ||
}); | ||
} | ||
@@ -183,3 +168,3 @@ } | ||
exports["default"] = (config) => ({ | ||
class: DVR, | ||
class: (DVR), | ||
config, | ||
@@ -186,0 +171,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorDVR=t(require("_")):e.MobxReactFormValidatorDVR=t(e._)}(self,(e=>(()=>{"use strict";var t={823:function(e,t,a){var s=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.DVR=void 0;const i=s(a(479));class l{constructor({config:e,state:t=null,promises:a=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state=t,this.promises=a,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){const t=this.state.form.validatedValues;this.validateFieldAsync(e,t),this.validateFieldSync(e,t)}makeLabels(e,t){const a={[t.path]:t.label};i.default.forIn(e.rules[t.path],(e=>{if("string"==typeof e.value&&e.name.match(/^(required_|same|different)/))i.default.forIn(e.value.split(","),((t,s)=>{if(!e.name.match(/^required_(if|unless)/)||s%2==0){const e=this.state.form.$(t);e&&e.path&&e.label&&(a[e.path]=e.label)}}));else if("string"==typeof e.value&&e.name.match(/^(before|after)/)){const t=this.state.form.$(e.value);t&&t.path&&t.label&&(a[t.path]=t.label)}})),e.setAttributeNames(a)}validateFieldSync(e,t){const a=this.rules(e.rules,"sync");if(i.default.isEmpty(a[0]))return;const s={[e.path]:a},l=new this.validator(t,s);this.makeLabels(l,e),l.passes()||e.invalidate(i.default.head(l.errors.get(e.path)),!1)}validateFieldAsync(e,t){const a=this.rules(e.rules,"async");if(i.default.isEmpty(a[0]))return;const s={[e.path]:a},l=new this.validator(t,s);this.makeLabels(l,e);const n=new Promise((t=>l.checkAsync((()=>this.handleAsyncPasses(e,t)),(()=>this.handleAsyncFails(e,l,t)))));this.promises.push(n)}handleAsyncPasses(e,t){e.setValidationAsyncData(!0),t()}handleAsyncFails(e,t,a){e.setValidationAsyncData(!1,i.default.head(t.errors.get(e.path))),this.executeAsyncValidation(e),a()}executeAsyncValidation(e){!1===e.validationAsyncData.valid&&e.invalidate(e.validationAsyncData.message,!1,!0)}rules(e,t){const a=i.default.isString(e)?i.default.split(e,"|"):e,s=new this.validator;return i.default.filter(a,(e=>"async"===t?s.getRule(i.default.split(e,":")[0]).async:!s.getRule(i.default.split(e,":")[0]).async))}}t.DVR=l,t.default=e=>({class:l,config:e})},479:t=>{t.exports=e}},a={};return function e(s){var i=a[s];if(void 0!==i)return i.exports;var l=a[s]={exports:{}};return t[s].call(l.exports,l,l.exports,e),l.exports}(823)})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorDVR=t(require("_")):e.MobxReactFormValidatorDVR=t(e._)}(self,(e=>(()=>{"use strict";var t={823:function(e,t,a){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.DVR=void 0;const s=i(a(479));class l{constructor({config:e,state:t=null,promises:a=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.state=t,this.promises=a,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){const t=this.state.form.validatedValues;this.validateFieldAsync(e,t),this.validateFieldSync(e,t)}makeLabels(e,t){const a={[t.path]:t.label};s.default.forIn(e.rules[t.path],(e=>{if("string"==typeof e.value&&e.name.match(/^(required_|same|different)/))s.default.forIn(e.value.split(","),((t,i)=>{if(!e.name.match(/^required_(if|unless)/)||i%2==0){const e=this.state.form.$(t);e&&e.path&&e.label&&(a[e.path]=e.label)}}));else if("string"==typeof e.value&&e.name.match(/^(before|after)/)){const t=this.state.form.$(e.value);t&&t.path&&t.label&&(a[t.path]=t.label)}})),e.setAttributeNames(a)}validateFieldSync(e,t){const a=this.rules(e.rules,"sync");if(s.default.isEmpty(a[0]))return;const i={[e.path]:a},l=new this.validator(t,i);this.makeLabels(l,e),l.passes()||e.invalidate(s.default.head(l.errors.get(e.path)),!1)}validateFieldAsync(e,t){const a=this.rules(e.rules,"async");if(s.default.isEmpty(a[0]))return;const i={[e.path]:a},l=new this.validator(t,i);this.makeLabels(l,e);const r=new Promise((t=>l.checkAsync((()=>this.handleAsyncPasses(e,t)),(()=>this.handleAsyncFails(e,l,t)))));this.promises.push(r)}handleAsyncPasses(e,t){e.setValidationAsyncData(!0),t()}handleAsyncFails(e,t,a){e.setValidationAsyncData(!1,s.default.head(t.errors.get(e.path))),this.executeAsyncValidation(e),a()}executeAsyncValidation(e){!1===e.validationAsyncData.valid&&e.invalidate(e.validationAsyncData.message,!1,!0)}rules(e,t){const a=s.default.isString(e)?s.default.split(e,"|"):e,i=new this.validator;return s.default.filter(a,(e=>{var a,l;return"async"===t?null===(a=i.getRule(s.default.split(e,":")[0]))||void 0===a?void 0:a.async:!(null===(l=i.getRule(s.default.split(e,":")[0]))||void 0===l?void 0:l.async)}))}}t.DVR=l,t.default=e=>({class:l,config:e})},479:t=>{t.exports=e}},a={};return function e(i){var s=a[i];if(void 0!==s)return s.exports;var l=a[i]={exports:{}};return t[i].call(l.exports,l,l.exports,e),l.exports}(823)})())); | ||
//# sourceMappingURL=MobxReactFormValidatorDVR.umd.min.js.map |
@@ -28,3 +28,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -35,3 +35,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -42,3 +42,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -49,3 +49,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -56,3 +56,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -63,6 +63,7 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
@@ -74,3 +75,2 @@ this.validator = config.package; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === "function") { | ||
@@ -84,17 +84,18 @@ this.extend({ | ||
validate(field) { | ||
const { error } = this.schema.validate(field.state.form.validatedValues, { abortEarly: false }); | ||
const data = this.state.form.validatedValues; | ||
const { error } = this.schema.validate(data, { abortEarly: false }); | ||
if (!error) | ||
return; | ||
const fieldPathArray = field.path.split('.'); | ||
const fieldPathArray = field.path.split("."); | ||
const fieldErrors = error.details | ||
.filter(detail => { | ||
const errorPathString = detail.path.join('.'); | ||
const fieldPathString = fieldPathArray.join('.'); | ||
return errorPathString === fieldPathString || errorPathString.startsWith(`${fieldPathString}.`); | ||
.filter((detail) => { | ||
const errorPathString = detail.path.join("."); | ||
const fieldPathString = fieldPathArray.join("."); | ||
return (errorPathString === fieldPathString || | ||
errorPathString.startsWith(`${fieldPathString}.`)); | ||
}) | ||
.map(detail => { | ||
.map((detail) => { | ||
var _a; | ||
// Replace the path in the error message with the custom label | ||
const label = ((_a = detail.context) === null || _a === void 0 ? void 0 : _a.label) || detail.path.join('.'); | ||
const message = detail.message.replace(`${detail.path.join('.')}`, label); | ||
const label = ((_a = detail.context) === null || _a === void 0 ? void 0 : _a.label) || detail.path.join("."); | ||
const message = detail.message.replace(`${detail.path.join(".")}`, label); | ||
return message; | ||
@@ -108,3 +109,3 @@ }); | ||
exports["default"] = (config) => ({ | ||
class: JOI, | ||
class: (JOI), | ||
config, | ||
@@ -111,0 +112,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MobxReactFormValidatorJOI=t():e.MobxReactFormValidatorJOI=t()}(self,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0});class a{constructor({config:e,state:t=null,promises:a=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state=t,this.promises=a,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.schema=e.schema,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){const{error:t}=this.schema.validate(e.state.form.validatedValues,{abortEarly:!1});if(!t)return;const a=e.path.split("."),r=t.details.filter((e=>{const t=e.path.join("."),r=a.join(".");return t===r||t.startsWith(`${r}.`)})).map((e=>{var t;const a=(null===(t=e.context)||void 0===t?void 0:t.label)||e.path.join(".");return e.message.replace(`${e.path.join(".")}`,a)}));r.length&&(e.validationErrorStack=r)}}t.default=e=>({class:a,config:e})})(),e})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MobxReactFormValidatorJOI=t():e.MobxReactFormValidatorJOI=t()}(self,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0});class a{constructor({config:e,state:t=null,promises:a=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.state=t,this.promises=a,this.config=e,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.schema=e.schema,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){const t=this.state.form.validatedValues,{error:a}=this.schema.validate(t,{abortEarly:!1});if(!a)return;const i=e.path.split("."),o=a.details.filter((e=>{const t=e.path.join("."),a=i.join(".");return t===a||t.startsWith(`${a}.`)})).map((e=>{var t;const a=(null===(t=e.context)||void 0===t?void 0:t.label)||e.path.join(".");return e.message.replace(`${e.path.join(".")}`,a)}));o.length&&(e.validationErrorStack=o)}}t.default=e=>({class:a,config:e})})(),e})())); | ||
//# sourceMappingURL=MobxReactFormValidatorJOI.umd.min.js.map |
@@ -27,16 +27,7 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
const lodash_1 = __importDefault(__webpack_require__(/*! lodash */ "lodash")); | ||
const isPromise = (obj) => !!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function"); | ||
/** | ||
Schema Validation Keywords | ||
const plugins = { | ||
svk: svk({ | ||
package: ajv, | ||
extend: callback, | ||
}), | ||
}; | ||
*/ | ||
function isPromise(obj) { | ||
return (!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function")); | ||
} | ||
class SVK { | ||
@@ -48,3 +39,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -55,3 +46,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -62,3 +53,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -69,3 +60,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -76,3 +67,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -83,70 +74,50 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
this.schema = config.schema; | ||
this.initAJV(config); | ||
this.initValidator(); | ||
} | ||
extendOptions(options = {}) { | ||
return Object.assign(options, { | ||
errorDataPath: "property", | ||
allErrors: true, | ||
coerceTypes: true, | ||
v5: true, | ||
}); | ||
return Object.assign(Object.assign({}, options), { errorDataPath: "property", allErrors: true, coerceTypes: true, v5: true }); | ||
} | ||
initAJV(config) { | ||
// get ajv package | ||
const ajv = config.package; | ||
// create ajv instance | ||
const validator = new ajv(this.extendOptions(config.options)); | ||
// extend ajv using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
initValidator() { | ||
const AJV = this.config.package; | ||
const validatorInstance = new AJV(this.extendOptions(this.config.options)); | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
form: this.state.form, | ||
validator, | ||
validator: validatorInstance, | ||
}); | ||
} | ||
// create ajv validator (compiling rules) | ||
this.validator = validator.compile(this.schema); | ||
this.validator = validatorInstance.compile(this.schema); | ||
} | ||
validate(field) { | ||
const validate = this.validator(field.state.form.validatedValues); | ||
// check if is $async schema | ||
if (isPromise(validate)) { | ||
const $p = validate | ||
const result = this.validator(field.state.form.validatedValues); | ||
if (isPromise(result)) { | ||
const $p = result | ||
.then(() => field.setValidationAsyncData(true)) | ||
.catch((err) => err && this.handleAsyncError(field, err.errors)) | ||
.then(() => this.executeAsyncValidation(field)); | ||
// push the promise into array | ||
this.promises.push($p); | ||
return; | ||
} | ||
// check sync errors | ||
this.handleSyncError(field, this.validator.errors); | ||
} | ||
handleSyncError(field, errors) { | ||
const fieldErrorObj = this.findError(field.path, errors); | ||
// if fieldErrorObj is not undefined, the current field is invalid. | ||
if (lodash_1.default.isUndefined(fieldErrorObj)) | ||
const fieldError = this.findError(field.path, errors); | ||
if (!fieldError) | ||
return; | ||
// the current field is now invalid | ||
// add additional info to the message | ||
const msg = `${field.label} ${fieldErrorObj.message}`; | ||
// invalidate the current field with message | ||
field.invalidate(msg, false); | ||
const message = `${field.label} ${fieldError.message}`; | ||
field.invalidate(message, false); | ||
} | ||
handleAsyncError(field, errors) { | ||
// find current field error message from ajv errors | ||
const fieldErrorObj = this.findError(field.path, errors); | ||
// if fieldErrorObj is not undefined, the current field is invalid. | ||
if (lodash_1.default.isUndefined(fieldErrorObj)) | ||
const fieldError = this.findError(field.path, errors); | ||
if (!fieldError) | ||
return; | ||
// the current field is now invalid | ||
// add additional info to the message | ||
const msg = `${field.label} ${fieldErrorObj.message}`; | ||
// set async validation data on the field | ||
field.setValidationAsyncData(false, msg); | ||
const message = `${field.label} ${fieldError.message}`; | ||
field.setValidationAsyncData(false, message); | ||
} | ||
@@ -163,4 +134,5 @@ findError(path, errors) { | ||
executeAsyncValidation(field) { | ||
if (field.validationAsyncData.valid === false) { | ||
field.invalidate(field.validationAsyncData.message, false, true); | ||
const asyncData = field.validationAsyncData; | ||
if (asyncData.valid === false) { | ||
field.invalidate(asyncData.message, false, true); | ||
} | ||
@@ -170,3 +142,3 @@ } | ||
exports["default"] = (config) => ({ | ||
class: SVK, | ||
class: (SVK), | ||
config, | ||
@@ -173,0 +145,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorSVK=t(require("_")):e.MobxReactFormValidatorSVK=t(e._)}(self,(e=>(()=>{"use strict";var t={324:function(e,t,r){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const i=a(r(479));class n{constructor({config:e,state:t=null,promises:r=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state=t,this.promises=r,this.extend=null==e?void 0:e.extend,this.schema=e.schema,this.initAJV(e)}extendOptions(e={}){return Object.assign(e,{errorDataPath:"property",allErrors:!0,coerceTypes:!0,v5:!0})}initAJV(e){const t=new(0,e.package)(this.extendOptions(e.options));"function"==typeof this.extend&&this.extend({form:this.state.form,validator:t}),this.validator=t.compile(this.schema)}validate(e){const t=this.validator(e.state.form.validatedValues);if(!(r=t)||"function"!=typeof r.then||"object"!=typeof r&&"function"!=typeof r){var r;this.handleSyncError(e,this.validator.errors)}else{const r=t.then((()=>e.setValidationAsyncData(!0))).catch((t=>t&&this.handleAsyncError(e,t.errors))).then((()=>this.executeAsyncValidation(e)));this.promises.push(r)}}handleSyncError(e,t){const r=this.findError(e.path,t);if(i.default.isUndefined(r))return;const a=`${e.label} ${r.message}`;e.invalidate(a,!1)}handleAsyncError(e,t){const r=this.findError(e.path,t);if(i.default.isUndefined(r))return;const a=`${e.label} ${r.message}`;e.setValidationAsyncData(!1,a)}findError(e,t){return i.default.find(t,(({dataPath:t})=>{let r;return r=i.default.trimStart(t,"."),r=i.default.replace(r,"]",""),r=i.default.replace(r,"[","."),i.default.includes(r,e)}))}executeAsyncValidation(e){!1===e.validationAsyncData.valid&&e.invalidate(e.validationAsyncData.message,!1,!0)}}t.default=e=>({class:n,config:e})},479:t=>{t.exports=e}},r={};return function e(a){var i=r[a];if(void 0!==i)return i.exports;var n=r[a]={exports:{}};return t[a].call(n.exports,n,n.exports,e),n.exports}(324)})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorSVK=t(require("_")):e.MobxReactFormValidatorSVK=t(e._)}(self,(e=>(()=>{"use strict";var t={324:function(e,t,r){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const a=i(r(479));class o{constructor({config:e,state:t=null,promises:r=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.state=t,this.promises=r,this.config=e,this.extend=null==e?void 0:e.extend,this.schema=e.schema,this.initValidator()}extendOptions(e={}){return Object.assign(Object.assign({},e),{errorDataPath:"property",allErrors:!0,coerceTypes:!0,v5:!0})}initValidator(){const e=new(0,this.config.package)(this.extendOptions(this.config.options));"function"==typeof this.extend&&this.extend({form:this.state.form,validator:e}),this.validator=e.compile(this.schema)}validate(e){const t=this.validator(e.state.form.validatedValues);if(!(r=t)||"function"!=typeof r.then||"object"!=typeof r&&"function"!=typeof r){var r;this.handleSyncError(e,this.validator.errors)}else{const r=t.then((()=>e.setValidationAsyncData(!0))).catch((t=>t&&this.handleAsyncError(e,t.errors))).then((()=>this.executeAsyncValidation(e)));this.promises.push(r)}}handleSyncError(e,t){const r=this.findError(e.path,t);if(!r)return;const i=`${e.label} ${r.message}`;e.invalidate(i,!1)}handleAsyncError(e,t){const r=this.findError(e.path,t);if(!r)return;const i=`${e.label} ${r.message}`;e.setValidationAsyncData(!1,i)}findError(e,t){return a.default.find(t,(({dataPath:t})=>{let r;return r=a.default.trimStart(t,"."),r=a.default.replace(r,"]",""),r=a.default.replace(r,"[","."),a.default.includes(r,e)}))}executeAsyncValidation(e){const t=e.validationAsyncData;!1===t.valid&&e.invalidate(t.message,!1,!0)}}t.default=e=>({class:o,config:e})},479:t=>{t.exports=e}},r={};return function e(i){var a=r[i];if(void 0!==a)return a.exports;var o=r[i]={exports:{}};return t[i].call(o.exports,o,o.exports,e),o.exports}(324)})())); | ||
//# sourceMappingURL=MobxReactFormValidatorSVK.umd.min.js.map |
@@ -28,15 +28,7 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
const lodash_1 = __importDefault(__webpack_require__(/*! lodash */ "lodash")); | ||
const isPromise = (obj) => !!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function"); | ||
/** | ||
Vanilla JavaScript Functions | ||
const plugins = { | ||
vkf: vkf({ | ||
package: validator, | ||
}), | ||
}; | ||
*/ | ||
function isPromise(obj) { | ||
return (!!obj && | ||
typeof obj.then === "function" && | ||
(typeof obj === "object" || typeof obj === "function")); | ||
} | ||
class VJF { | ||
@@ -48,3 +40,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -55,3 +47,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -62,3 +54,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -69,3 +61,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -76,6 +68,7 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
@@ -86,4 +79,3 @@ this.validator = config === null || config === void 0 ? void 0 : config.package; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -96,47 +88,37 @@ validator: this.validator, | ||
validate(field) { | ||
// exit if field does not have validation functions | ||
if (!field.validators) | ||
return; | ||
// get validators from validate property | ||
const $fn = field.validators; | ||
// map only if is an array of validator functions | ||
if (Array.isArray($fn)) { | ||
$fn.map((fn) => this.collectData(fn, field)); | ||
} | ||
// it's just one function // DEPRECATED | ||
// if (typeof $fn === 'function') { | ||
// this.collectData($fn, field); | ||
// } | ||
// execute the validation function | ||
const validators = Array.isArray(field.validators) ? field.validators : [field.validators]; | ||
validators.forEach((fn) => this.collectData(fn, field)); | ||
this.executeValidation(field); | ||
} | ||
collectData($fn, field) { | ||
const res = this.handleFunctionResult($fn, field); | ||
// check and execute only if is a promise | ||
if (isPromise(res)) { | ||
const $p = res | ||
.then(($res) => field.setValidationAsyncData($res[0], $res[1])) | ||
collectData(fn, field) { | ||
const result = this.handleFunctionResult(fn, field); | ||
if (isPromise(result)) { | ||
const $p = result | ||
.then(([valid, message]) => field.setValidationAsyncData(valid, message)) | ||
.then(() => this.executeAsyncValidation(field)); | ||
// push the promise into array | ||
this.promises.push($p); | ||
return; | ||
} | ||
// is a plain function | ||
field.validationFunctionsData.unshift({ | ||
valid: res[0], | ||
message: res[1], | ||
valid: result[0], | ||
message: result[1], | ||
}); | ||
} | ||
executeValidation(field) { | ||
// otherwise find an error message to show | ||
field.validationFunctionsData.map((rule) => rule.valid === false && field.invalidate(rule.message, false)); | ||
field.validationFunctionsData.forEach(({ valid, message }) => { | ||
if (valid === false) { | ||
field.invalidate(message, false); | ||
} | ||
}); | ||
} | ||
executeAsyncValidation(field) { | ||
if (field.validationAsyncData.valid === false) { | ||
field.invalidate(field.validationAsyncData.message, false, true); | ||
const data = field.validationAsyncData; | ||
if (data.valid === false) { | ||
field.invalidate(data.message, false, true); | ||
} | ||
} | ||
handleFunctionResult($fn, field) { | ||
// executre validation function | ||
const res = $fn({ | ||
handleFunctionResult(fn, field) { | ||
const result = fn({ | ||
validator: this.validator, | ||
@@ -146,31 +128,14 @@ form: this.state.form, | ||
}); | ||
/** | ||
Handle "array" | ||
*/ | ||
if (Array.isArray(res)) { | ||
const isValid = res[0] || false; | ||
const message = res[1] || "Error"; | ||
return [isValid, message]; | ||
if (Array.isArray(result)) { | ||
return [result[0] || false, result[1] || "Error"]; | ||
} | ||
/** | ||
Handle "boolean" | ||
*/ | ||
if (lodash_1.default.isBoolean(res)) { | ||
return [res, "Error"]; | ||
if (lodash_1.default.isBoolean(result)) { | ||
return [result, "Error"]; | ||
} | ||
/** | ||
Handle "string" | ||
*/ | ||
if (lodash_1.default.isString(res)) { | ||
return [false, res]; | ||
if (lodash_1.default.isString(result)) { | ||
return [false, result]; | ||
} | ||
/** | ||
Handle "object / promise" | ||
*/ | ||
if (isPromise(res)) { | ||
return res; // the promise | ||
if (isPromise(result)) { | ||
return result; | ||
} | ||
/** | ||
Handle other cases | ||
*/ | ||
return [false, "Error"]; | ||
@@ -181,3 +146,3 @@ } | ||
exports["default"] = (config) => ({ | ||
class: VJF, | ||
class: (VJF), | ||
config, | ||
@@ -184,0 +149,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorVJF=t(require("_")):e.MobxReactFormValidatorVJF=t(e._)}(self,(e=>(()=>{"use strict";var t={69:function(e,t,a){var i=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.VJF=void 0;const o=i(a(479)),r=e=>!!e&&"function"==typeof e.then&&("object"==typeof e||"function"==typeof e);class n{constructor({config:e,state:t=null,promises:a=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state=t,this.promises=a,this.extend=null==e?void 0:e.extend,this.validator=null==e?void 0:e.package,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){if(!e.validators)return;const t=e.validators;Array.isArray(t)&&t.map((t=>this.collectData(t,e))),this.executeValidation(e)}collectData(e,t){const a=this.handleFunctionResult(e,t);if(r(a)){const e=a.then((e=>t.setValidationAsyncData(e[0],e[1]))).then((()=>this.executeAsyncValidation(t)));this.promises.push(e)}else t.validationFunctionsData.unshift({valid:a[0],message:a[1]})}executeValidation(e){e.validationFunctionsData.map((t=>!1===t.valid&&e.invalidate(t.message,!1)))}executeAsyncValidation(e){!1===e.validationAsyncData.valid&&e.invalidate(e.validationAsyncData.message,!1,!0)}handleFunctionResult(e,t){const a=e({validator:this.validator,form:this.state.form,field:t});return Array.isArray(a)?[a[0]||!1,a[1]||"Error"]:o.default.isBoolean(a)?[a,"Error"]:o.default.isString(a)?[!1,a]:r(a)?a:[!1,"Error"]}}t.VJF=n,t.default=e=>({class:n,config:e})},479:t=>{t.exports=e}},a={};return function e(i){var o=a[i];if(void 0!==o)return o.exports;var r=a[i]={exports:{}};return t[i].call(r.exports,r,r.exports,e),r.exports}(69)})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorVJF=t(require("_")):e.MobxReactFormValidatorVJF=t(e._)}(self,(e=>(()=>{"use strict";var t={69:function(e,t,i){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.VJF=void 0;const o=a(i(479));function r(e){return!!e&&"function"==typeof e.then&&("object"==typeof e||"function"==typeof e)}class n{constructor({config:e,state:t=null,promises:i=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.state=t,this.promises=i,this.config=e,this.extend=null==e?void 0:e.extend,this.validator=null==e?void 0:e.package,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){e.validators&&((Array.isArray(e.validators)?e.validators:[e.validators]).forEach((t=>this.collectData(t,e))),this.executeValidation(e))}collectData(e,t){const i=this.handleFunctionResult(e,t);if(r(i)){const e=i.then((([e,i])=>t.setValidationAsyncData(e,i))).then((()=>this.executeAsyncValidation(t)));this.promises.push(e)}else t.validationFunctionsData.unshift({valid:i[0],message:i[1]})}executeValidation(e){e.validationFunctionsData.forEach((({valid:t,message:i})=>{!1===t&&e.invalidate(i,!1)}))}executeAsyncValidation(e){const t=e.validationAsyncData;!1===t.valid&&e.invalidate(t.message,!1,!0)}handleFunctionResult(e,t){const i=e({validator:this.validator,form:this.state.form,field:t});return Array.isArray(i)?[i[0]||!1,i[1]||"Error"]:o.default.isBoolean(i)?[i,"Error"]:o.default.isString(i)?[!1,i]:r(i)?i:[!1,"Error"]}}t.VJF=n,t.default=e=>({class:n,config:e})},479:t=>{t.exports=e}},i={};return function e(a){var o=i[a];if(void 0!==o)return o.exports;var r=i[a]={exports:{}};return t[a].call(r.exports,r,r.exports,e),r.exports}(69)})())); | ||
//# sourceMappingURL=MobxReactFormValidatorVJF.umd.min.js.map |
@@ -22,14 +22,2 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
Object.defineProperty(exports, "__esModule", ({ value: true })); | ||
/** | ||
YUP - Dead simple Object schema validation | ||
const plugins = { | ||
yup: $yup({ | ||
package: yup, | ||
schema: (y) => (), | ||
extend, | ||
}), | ||
}; | ||
*/ | ||
class YUP { | ||
@@ -47,3 +35,3 @@ constructor({ config, state = null, promises = [], }) { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -54,3 +42,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -61,3 +49,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -68,3 +56,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -75,3 +63,3 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -85,4 +73,4 @@ this.state = state; | ||
} | ||
// Metodo per estendere il validatore | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
@@ -95,4 +83,10 @@ this.extend({ | ||
} | ||
// Metodo di validazione principale | ||
validate(field) { | ||
const $p = new Promise((resolve) => this.validator | ||
const fieldValidationPromise = this.createValidationPromise(field); | ||
this.promises.push(fieldValidationPromise); | ||
} | ||
// Creazione della promise per la validazione | ||
createValidationPromise(field) { | ||
return new Promise((resolve) => this.validator | ||
.reach(this.schema, field.path) | ||
@@ -103,4 +97,4 @@ .label(field.label) | ||
.catch((error) => this.handleAsyncFails(field, resolve, error))); | ||
this.promises.push($p); | ||
} | ||
// Gestione dei successi della validazione asincrona | ||
handleAsyncPasses(field, resolve) { | ||
@@ -110,2 +104,3 @@ field.setValidationAsyncData(true); | ||
} | ||
// Gestione dei fallimenti della validazione asincrona | ||
handleAsyncFails(field, resolve, error) { | ||
@@ -116,2 +111,3 @@ field.setValidationAsyncData(false, error.errors[0]); | ||
} | ||
// Esecuzione della validazione asincrona | ||
executeAsyncValidation(field) { | ||
@@ -124,3 +120,3 @@ if (field.validationAsyncData.valid === false) { | ||
exports["default"] = (config) => ({ | ||
class: YUP, | ||
class: (YUP), | ||
config, | ||
@@ -127,0 +123,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MobxReactFormValidatorYUP=t():e.MobxReactFormValidatorYUP=t()}(self,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0});class a{constructor({config:e,state:t=null,promises:a=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state=t,this.promises=a,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.schema=e.schema(this.validator),this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){const t=new Promise((t=>this.validator.reach(this.schema,e.path).label(e.label).validate(e.validatedValue,{strict:!0}).then((()=>this.handleAsyncPasses(e,t))).catch((a=>this.handleAsyncFails(e,t,a)))));this.promises.push(t)}handleAsyncPasses(e,t){e.setValidationAsyncData(!0),t()}handleAsyncFails(e,t,a){e.setValidationAsyncData(!1,a.errors[0]),this.executeAsyncValidation(e),t()}executeAsyncValidation(e){!1===e.validationAsyncData.valid&&e.invalidate(e.validationAsyncData.message,!1,!0)}}t.default=e=>({class:a,config:e})})(),e})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.MobxReactFormValidatorYUP=t():e.MobxReactFormValidatorYUP=t()}(self,(()=>(()=>{"use strict";var e={};return(()=>{var t=e;Object.defineProperty(t,"__esModule",{value:!0});class a{constructor({config:e,state:t=null,promises:a=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.state=t,this.promises=a,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.schema=e.schema(this.validator),this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){const t=this.createValidationPromise(e);this.promises.push(t)}createValidationPromise(e){return new Promise((t=>this.validator.reach(this.schema,e.path).label(e.label).validate(e.validatedValue,{strict:!0}).then((()=>this.handleAsyncPasses(e,t))).catch((a=>this.handleAsyncFails(e,t,a)))))}handleAsyncPasses(e,t){e.setValidationAsyncData(!0),t()}handleAsyncFails(e,t,a){e.setValidationAsyncData(!1,a.errors[0]),this.executeAsyncValidation(e),t()}executeAsyncValidation(e){!1===e.validationAsyncData.valid&&e.invalidate(e.validationAsyncData.message,!1,!0)}}t.default=e=>({class:a,config:e})})(),e})())); | ||
//# sourceMappingURL=MobxReactFormValidatorYUP.umd.min.js.map |
@@ -26,2 +26,3 @@ (function webpackUniversalModuleDefinition(root, factory) { | ||
Object.defineProperty(exports, "__esModule", ({ value: true })); | ||
exports.ZOD = void 0; | ||
const lodash_1 = __importDefault(__webpack_require__(/*! lodash */ "lodash")); | ||
@@ -34,3 +35,3 @@ class ZOD { | ||
writable: true, | ||
value: [] | ||
value: void 0 | ||
}); | ||
@@ -41,3 +42,3 @@ Object.defineProperty(this, "config", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -48,3 +49,3 @@ Object.defineProperty(this, "state", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -55,3 +56,3 @@ Object.defineProperty(this, "extend", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -62,3 +63,3 @@ Object.defineProperty(this, "validator", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
@@ -69,6 +70,7 @@ Object.defineProperty(this, "schema", { | ||
writable: true, | ||
value: null | ||
value: void 0 | ||
}); | ||
this.state = state; | ||
this.promises = promises; | ||
this.config = config; | ||
this.extend = config === null || config === void 0 ? void 0 : config.extend; | ||
@@ -80,4 +82,3 @@ this.validator = config.package; | ||
extendValidator() { | ||
// extend using "extend" callback | ||
if (typeof this.extend === 'function') { | ||
if (typeof this.extend === "function") { | ||
this.extend({ | ||
@@ -94,9 +95,11 @@ validator: this.validator, | ||
return; | ||
const errors = (_a = lodash_1.default.get(result.error.format(), field.path)) === null || _a === void 0 ? void 0 : _a._errors; | ||
if (errors === null || errors === void 0 ? void 0 : errors.length) | ||
field.validationErrorStack = errors; | ||
const fieldErrors = (_a = lodash_1.default.get(result.error.format(), field.path)) === null || _a === void 0 ? void 0 : _a._errors; | ||
if (fieldErrors === null || fieldErrors === void 0 ? void 0 : fieldErrors.length) { | ||
field.validationErrorStack = fieldErrors; | ||
} | ||
} | ||
} | ||
exports.ZOD = ZOD; | ||
exports["default"] = (config) => ({ | ||
class: ZOD, | ||
class: (ZOD), | ||
config, | ||
@@ -103,0 +106,0 @@ }); |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorZOD=t(require("_")):e.MobxReactFormValidatorZOD=t(e._)}(self,(e=>(()=>{"use strict";var t={847:function(e,t,r){var a=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0});const o=a(r(479));class i{constructor({config:e,state:t=null,promises:r=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:[]}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:null}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:null}),this.state=t,this.promises=r,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.schema=e.schema,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){var t;const r=this.schema.safeParse(e.state.form.validatedValues);if(r.success)return;const a=null===(t=o.default.get(r.error.format(),e.path))||void 0===t?void 0:t._errors;(null==a?void 0:a.length)&&(e.validationErrorStack=a)}}t.default=e=>({class:i,config:e})},479:t=>{t.exports=e}},r={};return function e(a){var o=r[a];if(void 0!==o)return o.exports;var i=r[a]={exports:{}};return t[a].call(i.exports,i,i.exports,e),i.exports}(847)})())); | ||
!function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t(require("_")):"function"==typeof define&&define.amd?define(["_"],t):"object"==typeof exports?exports.MobxReactFormValidatorZOD=t(require("_")):e.MobxReactFormValidatorZOD=t(e._)}(self,(e=>(()=>{"use strict";var t={847:function(e,t,r){var o=this&&this.__importDefault||function(e){return e&&e.__esModule?e:{default:e}};Object.defineProperty(t,"__esModule",{value:!0}),t.ZOD=void 0;const i=o(r(479));class a{constructor({config:e,state:t=null,promises:r=[]}){Object.defineProperty(this,"promises",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"config",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"state",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"extend",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"validator",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"schema",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),this.state=t,this.promises=r,this.config=e,this.extend=null==e?void 0:e.extend,this.validator=e.package,this.schema=e.schema,this.extendValidator()}extendValidator(){"function"==typeof this.extend&&this.extend({validator:this.validator,form:this.state.form})}validate(e){var t;const r=this.schema.safeParse(e.state.form.validatedValues);if(r.success)return;const o=null===(t=i.default.get(r.error.format(),e.path))||void 0===t?void 0:t._errors;(null==o?void 0:o.length)&&(e.validationErrorStack=o)}}t.ZOD=a,t.default=e=>({class:a,config:e})},479:t=>{t.exports=e}},r={};return function e(o){var i=r[o];if(void 0!==i)return i.exports;var a=r[o]={exports:{}};return t[o].call(a.exports,a,a.exports,e),a.exports}(847)})())); | ||
//# sourceMappingURL=MobxReactFormValidatorZOD.umd.min.js.map |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1265736
0.07%14376
-1.27%