@hookstate/validation
Advanced tools
Comparing version 1.0.0-alpha.0 to 1.0.0-alpha.1
@@ -9,6 +9,3 @@ var ValidationSeverity; | ||
var ValidationPluginInstance = /** @class */ (function () { | ||
function ValidationPluginInstance(attachRule, message, severity) { | ||
this.attachRule = attachRule; | ||
this.message = message; | ||
this.severity = severity; | ||
function ValidationPluginInstance() { | ||
this.storeRules = {}; | ||
@@ -135,30 +132,16 @@ } | ||
}; | ||
Object.defineProperty(ValidationPluginInstance.prototype, "config", { | ||
get: function () { | ||
if (this.attachRule !== undefined && this.message !== undefined) { | ||
return { | ||
rule: this.attachRule, | ||
message: this.message, | ||
severity: this.severity || ValidationSeverity.ERROR | ||
}; | ||
} | ||
return undefined; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ValidationPluginInstance.prototype.onAttach = function (path, withArgument) { | ||
var config = withArgument.config; | ||
if (config) { | ||
this.addRule(path, config); | ||
} | ||
}; | ||
return ValidationPluginInstance; | ||
}()); | ||
function Validation(attachRuleOrSelf, message, severity) { | ||
if (attachRuleOrSelf && typeof attachRuleOrSelf !== 'function') { | ||
var self_1 = attachRuleOrSelf; | ||
var _a = self_1.with(PluginID), l_1 = _a[0], instance = _a[1]; | ||
function Validation(self) { | ||
if (self) { | ||
var _a = self.with(PluginID), l_1 = _a[0], instance = _a[1]; | ||
var inst_1 = instance; | ||
return { | ||
validate: function (r, m, s) { | ||
inst_1.addRule(l_1.path, { | ||
rule: r, | ||
message: m, | ||
severity: s || ValidationSeverity.ERROR | ||
}); | ||
}, | ||
validShallow: function () { | ||
@@ -188,7 +171,5 @@ return inst_1.getErrors(l_1, 1, undefined, true).length === 0; | ||
} | ||
return function () { | ||
return { | ||
id: PluginID, | ||
instanceFactory: function () { return new ValidationPluginInstance(attachRuleOrSelf, message, severity); } | ||
}; | ||
return { | ||
id: PluginID, | ||
instanceFactory: function () { return new ValidationPluginInstance(); } | ||
}; | ||
@@ -195,0 +176,0 @@ } |
@@ -12,6 +12,3 @@ 'use strict'; | ||
var ValidationPluginInstance = /** @class */ (function () { | ||
function ValidationPluginInstance(attachRule, message, severity) { | ||
this.attachRule = attachRule; | ||
this.message = message; | ||
this.severity = severity; | ||
function ValidationPluginInstance() { | ||
this.storeRules = {}; | ||
@@ -138,30 +135,16 @@ } | ||
}; | ||
Object.defineProperty(ValidationPluginInstance.prototype, "config", { | ||
get: function () { | ||
if (this.attachRule !== undefined && this.message !== undefined) { | ||
return { | ||
rule: this.attachRule, | ||
message: this.message, | ||
severity: this.severity || exports.ValidationSeverity.ERROR | ||
}; | ||
} | ||
return undefined; | ||
}, | ||
enumerable: true, | ||
configurable: true | ||
}); | ||
ValidationPluginInstance.prototype.onAttach = function (path, withArgument) { | ||
var config = withArgument.config; | ||
if (config) { | ||
this.addRule(path, config); | ||
} | ||
}; | ||
return ValidationPluginInstance; | ||
}()); | ||
function Validation(attachRuleOrSelf, message, severity) { | ||
if (attachRuleOrSelf && typeof attachRuleOrSelf !== 'function') { | ||
var self_1 = attachRuleOrSelf; | ||
var _a = self_1.with(PluginID), l_1 = _a[0], instance = _a[1]; | ||
function Validation(self) { | ||
if (self) { | ||
var _a = self.with(PluginID), l_1 = _a[0], instance = _a[1]; | ||
var inst_1 = instance; | ||
return { | ||
validate: function (r, m, s) { | ||
inst_1.addRule(l_1.path, { | ||
rule: r, | ||
message: m, | ||
severity: s || exports.ValidationSeverity.ERROR | ||
}); | ||
}, | ||
validShallow: function () { | ||
@@ -191,7 +174,5 @@ return inst_1.getErrors(l_1, 1, undefined, true).length === 0; | ||
} | ||
return function () { | ||
return { | ||
id: PluginID, | ||
instanceFactory: function () { return new ValidationPluginInstance(attachRuleOrSelf, message, severity); } | ||
}; | ||
return { | ||
id: PluginID, | ||
instanceFactory: function () { return new ValidationPluginInstance(); } | ||
}; | ||
@@ -198,0 +179,0 @@ } |
@@ -16,13 +16,12 @@ import { Plugin, Path, StateLink, StateValueAtPath } from '@hookstate/core'; | ||
} | ||
export interface ValidationExtensions { | ||
readonly validShallow: () => boolean; | ||
readonly valid: () => boolean; | ||
readonly invalidShallow: () => boolean; | ||
readonly invalid: () => boolean; | ||
export interface ValidationExtensions<S> { | ||
validate(attachRule: (value: S) => boolean, message: string | ((value: S) => string), severity?: ValidationSeverity): void; | ||
validShallow(): boolean; | ||
valid(): boolean; | ||
invalidShallow(): boolean; | ||
invalid(): boolean; | ||
firstError(filter?: (e: ValidationError) => boolean, depth?: number): Partial<ValidationError>; | ||
errors(filter?: (e: ValidationError) => boolean, depth?: number, first?: boolean): ReadonlyArray<ValidationError>; | ||
} | ||
export declare function Validation(): (() => Plugin); | ||
export declare function Validation<S>(attachRule: (value: S) => boolean, message: string | ((value: S) => string)): (() => Plugin); | ||
export declare function Validation<S>(attachRule: (value: S) => boolean, message: string | ((value: S) => string), severity: ValidationSeverity): (() => Plugin); | ||
export declare function Validation<S>(self: StateLink<S>): ValidationExtensions; | ||
export declare function Validation(): Plugin; | ||
export declare function Validation<S>(self: StateLink<S>): ValidationExtensions<S>; |
{ | ||
"name": "@hookstate/validation", | ||
"version": "1.0.0-alpha.0", | ||
"version": "1.0.0-alpha.1", | ||
"description": "Plugin for @hookstate/core to enable validation of data state.", | ||
@@ -37,6 +37,6 @@ "license": "MIT", | ||
"peerDependencies": { | ||
"@hookstate/core": "1.0.0-alpha.0" | ||
"@hookstate/core": "1.0.0-alpha.2" | ||
}, | ||
"devDependencies": { | ||
"@hookstate/core": "1.0.0-alpha.0", | ||
"@hookstate/core": "1.0.0-alpha.2", | ||
"@testing-library/react": "8.0.5", | ||
@@ -43,0 +43,0 @@ "@testing-library/react-hooks": "1.1.0", |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46790
378