@berish/validate
Advanced tools
Comparing version
export * from './pluginSystem'; | ||
export * from './globalModule'; | ||
export * from './rule'; | ||
export * from './validateMap'; |
@@ -6,7 +6,5 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const pluginSystem_1 = require("./pluginSystem"); | ||
const globalModule = require("./globalModule"); | ||
pluginSystem_1.callPlugin(globalModule, (plugin, mod) => pluginSystem_1.useUpgradeGlobalModule(plugin, mod)); | ||
__export(require("./pluginSystem")); | ||
__export(require("./globalModule")); | ||
__export(require("./rule")); | ||
__export(require("./validateMap")); | ||
//# sourceMappingURL=index.js.map |
import { IValidateRule } from '../rule'; | ||
import * as globalModule from '../globalModule'; | ||
import * as globalMethodsImport from '../index'; | ||
export interface IRulePlugin { | ||
upgradeRuleBeforeInit?(rule: IValidateRule<any>): IValidateRule<any> | void; | ||
upgradeRuleAfterInit?(rule: IValidateRule<any>): IValidateRule<any> | void; | ||
upgradeGlobalModule?(module: typeof globalModule): typeof globalModule | { | ||
upgradeMethods?(globalMethods: typeof globalMethodsImport): typeof globalMethodsImport | { | ||
[key: string]: any; | ||
@@ -8,0 +8,0 @@ } | void; |
import { IRulePlugin } from './abstract'; | ||
import { IValidateRule } from '../rule'; | ||
import * as globalModule from '../globalModule'; | ||
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 useUpgradeGlobalModule(plugin: IRulePlugin, module: typeof globalModule): typeof globalModule; | ||
export declare function useUpgradeMethods(plugin: IRulePlugin, globalMethods: typeof globalMethodsImport): typeof globalMethodsImport; |
@@ -21,14 +21,14 @@ "use strict"; | ||
exports.useUpgradeRuleAfterInit = useUpgradeRuleAfterInit; | ||
function useUpgradeGlobalModule(plugin, module) { | ||
function useUpgradeMethods(plugin, globalMethods) { | ||
try { | ||
const newModule = (plugin && plugin.upgradeGlobalModule && plugin.upgradeGlobalModule(module)) || module; | ||
if (newModule !== module) | ||
Object.entries(newModule).forEach(([key, value]) => Object.defineProperty(module, key, { value })); | ||
return module; | ||
const newGlobalMethods = (plugin && plugin.upgradeMethods && plugin.upgradeMethods(globalMethods)) || globalMethods; | ||
if (newGlobalMethods !== globalMethods) | ||
Object.entries(newGlobalMethods).forEach(([key, value]) => typeof globalMethods[key] === 'undefined' && Object.defineProperty(globalMethods, key, { value })); | ||
return globalMethods; | ||
} | ||
catch (err) { | ||
return module; | ||
return globalMethods; | ||
} | ||
} | ||
exports.useUpgradeGlobalModule = useUpgradeGlobalModule; | ||
exports.useUpgradeMethods = useUpgradeMethods; | ||
//# sourceMappingURL=system.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
const system_1 = require("./system"); | ||
const globalMethods = require("../index"); | ||
exports.plugins = []; | ||
function usePlugin(...include) { | ||
include = include.filter(m => exports.plugins.indexOf(m) === -1); | ||
exports.plugins.push(...include); | ||
if (include.length > 0) { | ||
exports.plugins.push(...include); | ||
include.reduce((out, plugin) => system_1.useUpgradeMethods(plugin, out), globalMethods); | ||
} | ||
} | ||
@@ -8,0 +13,0 @@ exports.usePlugin = usePlugin; |
{ | ||
"name": "@berish/validate", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"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
50602
-12.43%68
-26.09%641
-12.79%