@berish/validate
Advanced tools
Comparing version 0.0.7 to 0.0.8
import { IValidateRule } from '../rule'; | ||
import * as globalMethodsImport from '../index'; | ||
export interface IRulePlugin { | ||
upgradeRuleBeforeInit?(rule: IValidateRule<any>): IValidateRule<any> | void; | ||
upgradeRuleAfterInit?(rule: IValidateRule<any>): IValidateRule<any> | void; | ||
upgradeRuleAfterRegister?(rule: IValidateRule<any>): IValidateRule<any> | void; | ||
upgradeMethods?(globalMethods: typeof globalMethodsImport): typeof globalMethodsImport | { | ||
@@ -7,0 +7,0 @@ [key: string]: any; |
import { IRulePlugin } from './abstract'; | ||
import { IValidateRule } from '../rule'; | ||
import * as globalMethodsImport from '../index'; | ||
export declare function useUpgradeRuleBeforeInit(plugin: IRulePlugin, rule: IValidateRule<any>): IValidateRule<any>; | ||
export declare function useUpgradeRuleAfterInit(plugin: IRulePlugin, rule: IValidateRule<any>): IValidateRule<any>; | ||
export declare function useUpgradeRuleAfterRegister(plugin: IRulePlugin, rule: IValidateRule<any>): IValidateRule<any>; | ||
export declare function useUpgradeMethods(plugin: IRulePlugin, globalMethods: typeof globalMethodsImport): typeof globalMethodsImport; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
function useUpgradeRuleBeforeInit(plugin, rule) { | ||
function useUpgradeRuleAfterInit(plugin, rule) { | ||
try { | ||
return (rule && plugin && plugin.upgradeRuleBeforeInit && plugin.upgradeRuleBeforeInit(rule)) || rule; | ||
return (rule && plugin && plugin.upgradeRuleAfterInit && plugin.upgradeRuleAfterInit(rule)) || rule; | ||
} | ||
@@ -11,6 +11,6 @@ catch (err) { | ||
} | ||
exports.useUpgradeRuleBeforeInit = useUpgradeRuleBeforeInit; | ||
function useUpgradeRuleAfterInit(plugin, rule) { | ||
exports.useUpgradeRuleAfterInit = useUpgradeRuleAfterInit; | ||
function useUpgradeRuleAfterRegister(plugin, rule) { | ||
try { | ||
return (rule && plugin && plugin.upgradeRuleAfterInit && plugin.upgradeRuleAfterInit(rule)) || rule; | ||
return (rule && plugin && plugin.upgradeRuleAfterRegister && plugin.upgradeRuleAfterRegister(rule)) || rule; | ||
} | ||
@@ -21,3 +21,3 @@ catch (err) { | ||
} | ||
exports.useUpgradeRuleAfterInit = useUpgradeRuleAfterInit; | ||
exports.useUpgradeRuleAfterRegister = useUpgradeRuleAfterRegister; | ||
function useUpgradeMethods(plugin, globalMethods) { | ||
@@ -24,0 +24,0 @@ try { |
@@ -5,3 +5,7 @@ "use strict"; | ||
const globalMethods = require("../index"); | ||
const rule_1 = require("../rule"); | ||
exports.plugins = []; | ||
function _callPlugin(plugins, initialValue, callbackPlugin) { | ||
return plugins.reduce((out, plugin) => callbackPlugin(plugin, out), initialValue); | ||
} | ||
function usePlugin(...include) { | ||
@@ -11,3 +15,9 @@ include = include.filter(m => exports.plugins.indexOf(m) === -1); | ||
exports.plugins.push(...include); | ||
include.reduce((out, plugin) => system_1.useUpgradeMethods(plugin, out), globalMethods); | ||
_callPlugin(include, globalMethods, (plugin, globalMethods) => system_1.useUpgradeMethods(plugin, globalMethods)); | ||
rule_1.getAllRules().forEach(rule => { | ||
_callPlugin(include, rule, (plugin, rule) => system_1.useUpgradeRuleAfterInit(plugin, rule)); | ||
}); | ||
rule_1.getRegisteredRules().forEach(rule => { | ||
_callPlugin(include, rule, (plugin, rule) => system_1.useUpgradeRuleAfterRegister(plugin, rule)); | ||
}); | ||
} | ||
@@ -17,5 +27,5 @@ } | ||
function callPlugin(initialValue, callbackPlugin) { | ||
return exports.plugins.reduce((out, plugin) => callbackPlugin(plugin, out), initialValue); | ||
return _callPlugin(exports.plugins, initialValue, callbackPlugin); | ||
} | ||
exports.callPlugin = callPlugin; | ||
//# sourceMappingURL=usePlugin.js.map |
@@ -24,3 +24,3 @@ "use strict"; | ||
const defaultErrorText = `${ruleName}-error`; | ||
const rule = pluginSystem_1.callPlugin(((...args) => _createRule(params, args)), (plugin, rule) => pluginSystem_1.useUpgradeRuleBeforeInit(plugin, rule)); | ||
const rule = (...args) => _createRule(params, args); | ||
rule.ruleName = ruleName; | ||
@@ -99,2 +99,3 @@ Object.defineProperty(rule, 'name', { value: rule.ruleName }); | ||
}; | ||
registrator_1.addRule(rule); | ||
return pluginSystem_1.callPlugin(rule, (plugin, rule) => pluginSystem_1.useUpgradeRuleAfterInit(plugin, rule)); | ||
@@ -104,5 +105,5 @@ }; | ||
registrator_1.registerRule(rule); | ||
return rule; | ||
return pluginSystem_1.callPlugin(rule, (plugin, rule) => pluginSystem_1.useUpgradeRuleAfterRegister(plugin, rule)); | ||
} | ||
exports.createRule = createRule; | ||
//# sourceMappingURL=createRule.js.map |
@@ -6,1 +6,5 @@ import { IValidateRule } from './types'; | ||
export declare function isRegisteredRule(name: string): boolean; | ||
export declare function getRegisteredRules(): IValidateRule<any>[]; | ||
export declare function addRule(rule: IValidateRule<any>): void; | ||
export declare function removeRule(rule: IValidateRule<any>): void; | ||
export declare function getAllRules(): IValidateRule<any>[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const rules = {}; | ||
const registeredRules = {}; | ||
let allRules = []; | ||
function registerRule(rule) { | ||
rules[rule.ruleName] = rule; | ||
registeredRules[rule.ruleName] = rule; | ||
} | ||
@@ -11,7 +12,7 @@ exports.registerRule = registerRule; | ||
if (rule) | ||
delete rules[name]; | ||
delete registeredRules[name]; | ||
} | ||
exports.unregisterRule = unregisterRule; | ||
function getRegisteredRule(name) { | ||
return rules[name]; | ||
return registeredRules[name]; | ||
} | ||
@@ -23,2 +24,19 @@ exports.getRegisteredRule = getRegisteredRule; | ||
exports.isRegisteredRule = isRegisteredRule; | ||
function getRegisteredRules() { | ||
return Object.values(registeredRules); | ||
} | ||
exports.getRegisteredRules = getRegisteredRules; | ||
function addRule(rule) { | ||
if (allRules.indexOf(rule) === -1) | ||
allRules.push(rule); | ||
} | ||
exports.addRule = addRule; | ||
function removeRule(rule) { | ||
allRules = allRules.filter(m => m !== rule); | ||
} | ||
exports.removeRule = removeRule; | ||
function getAllRules() { | ||
return allRules; | ||
} | ||
exports.getAllRules = getAllRules; | ||
//# sourceMappingURL=registrator.js.map |
{ | ||
"name": "@berish/validate", | ||
"version": "0.0.7", | ||
"version": "0.0.8", | ||
"description": "Validation of complex objects with support for validation maps, rules and decorators", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
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
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
80257
981