diff --git a/dist/amd/can-define-validate-validatejs.js b/dist/amd/can-define-validate-validatejs.js new file mode 100644 index 0000000..3e5c3ba --- /dev/null +++ b/dist/amd/can-define-validate-validatejs.js @@ -0,0 +1,86 @@ +/*can-define-validate-validatejs@1.0.0#can-define-validate-validatejs*/ +define([ + 'require', + 'exports', + 'module', + 'can-validate-validatejs', + 'can-define', + 'can-assign', + 'can-reflect', + 'can-validate', + 'can-util/js/is-empty-object' +], function (require, exports, module) { + var validate = require('can-validate-validatejs'); + var define = require('can-define'); + var assign = require('can-assign'); + var canReflect = require('can-reflect'); + var formatErrors = require('can-validate').formatErrors; + var isEmptyObject = require('can-util/js/is-empty-object'); + var getMapConstraints = function (Map) { + var constraints = {}; + canReflect.eachKey(Map.prototype._define.definitions, function (prop, key) { + if (prop.validate && !isEmptyObject(prop.validate)) { + constraints[key] = prop.validate; + } + }); + return constraints; + }; + var validateMap = function (Map, validator) { + var mapDefinition = Map.prototype._define; + Map.prototype.testSet = function () { + var values = {}; + var useNewObject = false; + if (arguments.length) { + if (typeof arguments[0] === 'object' && Boolean(arguments[0])) { + values = arguments[0]; + useNewObject = Boolean(arguments[1]); + } + if (typeof arguments[0] === 'string') { + values[arguments[0]] = arguments[1]; + } + if (useNewObject) { + values = new Map(values); + } else { + var mapClone = this.serialize(); + assign(mapClone, values); + values = mapClone; + } + return validator(values); + } else { + return this.errors(); + } + }; + Map.prototype.errors = function () { + var _errors = this._errors; + var errors; + if (arguments.length) { + var errorsObj = formatErrors(_errors, 'errors-object'); + errors = []; + canReflect.eachIndex(arguments, function (key) { + [].push.apply(errors, errorsObj ? errorsObj[key] : []); + }); + errors = errors.length > 0 ? errors : undefined; + } else { + errors = _errors; + } + return errors; + }; + define.property(Map.prototype, '_errors', { + get: function () { + var errors = validator(this); + return errors; + } + }, mapDefinition.dataInitializers, mapDefinition.computedInitializers); + }; + var decorator = function (Map) { + var constraints = getMapConstraints(Map); + var validator = validate.many(constraints); + validateMap(Map, function (map) { + var errors = validator(map); + return formatErrors(errors, 'errors'); + }); + }; + decorator.validatejs = validate.validatejs; + module.exports = decorator; +}); +//# sourceMappingURL=can-define-validate-validatejs.js.map \ No newline at end of file diff --git a/dist/amd/can-define-validate-validatejs.js.map b/dist/amd/can-define-validate-validatejs.js.map new file mode 100644 index 0000000..01469fb --- /dev/null +++ b/dist/amd/can-define-validate-validatejs.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../can-define-validate-validatejs.js"],"names":["validate","require","define","assign","canReflect","formatErrors","isEmptyObject","getMapConstraints","Map","constraints","eachKey","prototype","_define","definitions","prop","key","validateMap","validator","mapDefinition","testSet","values","useNewObject","arguments","length","Boolean","mapClone","serialize","errors","_errors","errorsObj","eachIndex","push","apply","undefined","property","get","dataInitializers","computedInitializers","decorator","many","map","validatejs","module","exports"],"mappings":";;;;;;;;;;;;IAAA,IAAIA,QAAA,GAAWC,OAAA,CAAQ,yBAAR,CAAf,C;IACA,IAAIC,MAAA,GAASD,OAAA,CAAQ,YAAR,CAAb,C;IACA,IAAIE,MAAA,GAASF,OAAA,CAAQ,YAAR,CAAb,C;IACA,IAAIG,UAAA,GAAaH,OAAA,CAAQ,aAAR,CAAjB,C;IACA,IAAII,YAAA,GAAeJ,OAAA,CAAQ,cAAR,EAAwBI,YAA3C,C;IACA,IAAIC,aAAA,GAAgBL,OAAA,CAAQ,6BAAR,CAApB,C;IAEA,IAAIM,iBAAA,GAAoB,UAASC,GAAT,EAAc;AAAA,QACrC,IAAIC,WAAA,GAAc,EAAlB,CADqC;AAAA,QAErCL,UAAA,CAAWM,OAAX,CAAmBF,GAAA,CAAIG,SAAJ,CAAcC,OAAd,CAAsBC,WAAzC,EAAsD,UAASC,IAAT,EAAeC,GAAf,EAAoB;AAAA,YACzE,IAAID,IAAA,CAAKd,QAAL,IAAiB,CAACM,aAAA,CAAcQ,IAAA,CAAKd,QAAnB,CAAtB,EAAoD;AAAA,gBACnDS,WAAA,CAAYM,GAAZ,IAAmBD,IAAA,CAAKd,Q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AAA,GAAcF,iBAAA,CAAkBC,GAAlB,CAAlB,CAD6B;AAAA,QAE7B,IAAIS,SAAA,GAAYjB,QAAA,CAASuC,IAAT,CAAc9B,WAAd,CAAhB,CAF6B;AAAA,QAI7BO,WAAA,CAAYR,GAAZ,EAAiB,UAASgC,GAAT,EAAc;AAAA,YAC9B,IAAIb,MAAA,GAASV,SAAA,CAAUuB,GAAV,CAAb,CAD8B;AAAA,YAE9B,OAAOnC,YAAA,CAAasB,MAAb,EAAqB,QAArB,CAAP,CAF8B;AAAA,SAA/B,EAJ6B;AAAA,KAA9B,C;IAUAW,SAAA,CAAUG,UAAV,GAAuBzC,QAAA,CAASyC,UAAhC,C;IAEAC,MAAA,CAAOC,OAAP,GAAiBL,SAAjB,C","file":"can-define-validate-validatejs.js"} \ No newline at end of file diff --git a/dist/cjs/can-define-validate-validatejs.js b/dist/cjs/can-define-validate-validatejs.js new file mode 100644 index 0000000..ac46761 --- /dev/null +++ b/dist/cjs/can-define-validate-validatejs.js @@ -0,0 +1,74 @@ +/*can-define-validate-validatejs@1.0.0#can-define-validate-validatejs*/ +var validate = require('can-validate-validatejs'); +var define = require('can-define'); +var assign = require('can-assign'); +var canReflect = require('can-reflect'); +var formatErrors = require('can-validate').formatErrors; +var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); +var getMapConstraints = function (Map) { + var constraints = {}; + canReflect.eachKey(Map.prototype._define.definitions, function (prop, key) { + if (prop.validate && !isEmptyObject(prop.validate)) { + constraints[key] = prop.validate; + } + }); + return constraints; +}; +var validateMap = function (Map, validator) { + var mapDefinition = Map.prototype._define; + Map.prototype.testSet = function () { + var values = {}; + var useNewObject = false; + if (arguments.length) { + if (typeof arguments[0] === 'object' && Boolean(arguments[0])) { + values = arguments[0]; + useNewObject = Boolean(arguments[1]); + } + if (typeof arguments[0] === 'string') { + values[arguments[0]] = arguments[1]; + } + if (useNewObject) { + values = new Map(values); + } else { + var mapClone = this.serialize(); + assign(mapClone, values); + values = mapClone; + } + return validator(values); + } else { + return this.errors(); + } + }; + Map.prototype.errors = function () { + var _errors = this._errors; + var errors; + if (arguments.length) { + var errorsObj = formatErrors(_errors, 'errors-object'); + errors = []; + canReflect.eachIndex(arguments, function (key) { + [].push.apply(errors, errorsObj ? errorsObj[key] : []); + }); + errors = errors.length > 0 ? errors : undefined; + } else { + errors = _errors; + } + return errors; + }; + define.property(Map.prototype, '_errors', { + get: function () { + var errors = validator(this); + return errors; + } + }, mapDefinition.dataInitializers, mapDefinition.computedInitializers); +}; +var decorator = function (Map) { + var constraints = getMapConstraints(Map); + var validator = validate.many(constraints); + validateMap(Map, function (map) { + var errors = validator(map); + return formatErrors(errors, 'errors'); + }); +}; +decorator.validatejs = validate.validatejs; +module.exports = decorator; +//# sourceMappingURL=can-define-validate-validatejs.js.map \ No newline at end of file diff --git a/dist/cjs/can-define-validate-validatejs.js.map b/dist/cjs/can-define-validate-validatejs.js.map new file mode 100644 index 0000000..3d6b784 --- /dev/null +++ b/dist/cjs/can-define-validate-validatejs.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../can-define-validate-validatejs.js"],"names":["validate","require","define","assign","canReflect","formatErrors","isEmptyObject","getMapConstraints","Map","constraints","eachKey","prototype","_define","definitions","prop","key","validateMap","validator","mapDefinition","testSet","values","useNewObject","arguments","length","Boolean","mapClone","serialize","errors","_errors","errorsObj","eachIndex","push","apply","undefined","property","get","dataInitializers","computedInitializers","decorator","many","map","validatejs","module","exports"],"mappings":";AAAA,IAAIA,QAAA,GAAWC,OAAA,CAAQ,yBAAR,CAAf;AACA,IAAIC,MAAA,GAASD,OAAA,CAAQ,YAAR,CAAb,CADA;AAEA,IAAIE,MAAA,GAASF,OAAA,CAAQ,YAAR,CAAb,CAFA;AAGA,IAAIG,UAAA,GAAaH,OAAA,CAAQ,aAAR,CAAjB,CAHA;AAIA,IAAII,YAAA,GAAeJ,OAAA,CAAQ,cAAR,EAAwBI,YAA3C,CAJA;AAKA,IAAIC,aAAA,GAAgBL,OAA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KAAlC,CAhC0C;AAAA,IAiD1CzB,MAAA,CAAOgC,QAAP,CACC1B,GAAA,CAAIG,SADL,EAEC,SAFD,EAGC;AAAA,QACCwB,GAAA,EAAK,YAAW;AAAA,YACf,IAAIR,MAAA,GAASV,SAAA,CAAU,IAAV,CAAb,CADe;AAAA,YAEf,OAAOU,MAAP,CAFe;AAAA,SADjB;AAAA,KAHD,EASCT,aAAA,CAAckB,gBATf,EAUClB,aAAA,CAAcmB,oBAVf,EAjD0C;AAAA,CAA3C,CAjBA;AAgFA,IAAIC,SAAA,GAAY,UAAS9B,GAAT,EAAc;AAAA,IAC7B,IAAIC,WAAA,GAAcF,iBAAA,CAAkBC,GAAlB,CAAlB,CAD6B;AAAA,IAE7B,IAAIS,SAAA,GAAYjB,QAAA,CAASuC,IAAT,CAAc9B,WAAd,CAAhB,CAF6B;AAAA,IAI7BO,WAAA,CAAYR,GAAZ,EAAiB,UAASgC,GAAT,EAAc;AAAA,QAC9B,IAAIb,MAAA,GAASV,SAAA,CAAUuB,GAAV,CAAb,CAD8B;AAAA,QAE9B,OAAOnC,YAAA,CAAasB,MAAb,EAAqB,QAArB,CAAP,CAF8B;AAAA,KAA/B,EAJ6B;AAAA,CAA9B,CAhFA;AA0FAW,SAAA,CAAUG,UAAV,GAAuBzC,QAAA,CAASyC,UAAhC,CA1FA;AA4FAC,MAAA,CAAOC,OAAP,GAAiBL,SAAjB","file":"can-define-validate-validatejs.js"} \ No newline at end of file diff --git a/dist/global/can-define-validate-validatejs.js b/dist/global/can-define-validate-validatejs.js new file mode 100644 index 0000000..af1730f --- /dev/null +++ b/dist/global/can-define-validate-validatejs.js @@ -0,0 +1,221 @@ +/*[global-shim-start]*/ +(function(exports, global, doEval) { + // jshint ignore:line + var origDefine = global.define; + + var get = function(name) { + var parts = name.split("."), + cur = global, + i; + for (i = 0; i < parts.length; i++) { + if (!cur) { + break; + } + cur = cur[parts[i]]; + } + return cur; + }; + var set = function(name, val) { + var parts = name.split("."), + cur = global, + i, + part, + next; + for (i = 0; i < parts.length - 1; i++) { + part = parts[i]; + next = cur[part]; + if (!next) { + next = cur[part] = {}; + } + cur = next; + } + part = parts[parts.length - 1]; + cur[part] = val; + }; + var useDefault = function(mod) { + if (!mod || !mod.__esModule) return false; + var esProps = { __esModule: true, default: true }; + for (var p in mod) { + if (!esProps[p]) return false; + } + return true; + }; + + var hasCjsDependencies = function(deps) { + return ( + deps[0] === "require" && deps[1] === "exports" && deps[2] === "module" + ); + }; + + var modules = + (global.define && global.define.modules) || + (global._define && global._define.modules) || + {}; + var ourDefine = (global.define = function(moduleName, deps, callback) { + var module; + if (typeof deps === "function") { + callback = deps; + deps = []; + } + var args = [], + i; + for (i = 0; i < deps.length; i++) { + args.push( + exports[deps[i]] + ? get(exports[deps[i]]) + : modules[deps[i]] || get(deps[i]) + ); + } + // CJS has no dependencies but 3 callback arguments + if (hasCjsDependencies(deps) || (!deps.length && callback.length)) { + module = { exports: {} }; + args[0] = function(name) { + return exports[name] ? get(exports[name]) : modules[name]; + }; + args[1] = module.exports; + args[2] = module; + } else if (!args[0] && deps[0] === "exports") { + // Babel uses the exports and module object. + module = { exports: {} }; + args[0] = module.exports; + if (deps[1] === "module") { + args[1] = module; + } + } else if (!args[0] && deps[0] === "module") { + args[0] = { id: moduleName }; + } + + global.define = origDefine; + var result = callback ? callback.apply(null, args) : undefined; + global.define = ourDefine; + + // Favor CJS module.exports over the return value + result = module && module.exports ? module.exports : result; + modules[moduleName] = result; + + // Set global exports + var globalExport = exports[moduleName]; + if (globalExport && !get(globalExport)) { + if (useDefault(result)) { + result = result["default"]; + } + set(globalExport, result); + } + }); + global.define.orig = origDefine; + global.define.modules = modules; + global.define.amd = true; + ourDefine("@loader", [], function() { + // shim for @@global-helpers + var noop = function() {}; + return { + get: function() { + return { prepareGlobal: noop, retrieveGlobal: noop }; + }, + global: global, + __exec: function(__load) { + doEval(__load.source, global); + } + }; + }); +})( + {}, + typeof self == "object" && self.Object == Object ? self : window, + function(__$source__, __$global__) { + // jshint ignore:line + eval("(function() { " + __$source__ + " \n }).call(__$global__);"); + } +); + +/*can-define-validate-validatejs@1.0.0#can-define-validate-validatejs*/ +define('can-define-validate-validatejs', [ + 'require', + 'exports', + 'module', + 'can-validate-validatejs', + 'can-define', + 'can-assign', + 'can-reflect', + 'can-validate', + 'can-util/js/is-empty-object/is-empty-object' +], function (require, exports, module) { + var validate = require('can-validate-validatejs'); + var define = require('can-define'); + var assign = require('can-assign'); + var canReflect = require('can-reflect'); + var formatErrors = require('can-validate').formatErrors; + var isEmptyObject = require('can-util/js/is-empty-object/is-empty-object'); + var getMapConstraints = function (Map) { + var constraints = {}; + canReflect.eachKey(Map.prototype._define.definitions, function (prop, key) { + if (prop.validate && !isEmptyObject(prop.validate)) { + constraints[key] = prop.validate; + } + }); + return constraints; + }; + var validateMap = function (Map, validator) { + var mapDefinition = Map.prototype._define; + Map.prototype.testSet = function () { + var values = {}; + var useNewObject = false; + if (arguments.length) { + if (typeof arguments[0] === 'object' && Boolean(arguments[0])) { + values = arguments[0]; + useNewObject = Boolean(arguments[1]); + } + if (typeof arguments[0] === 'string') { + values[arguments[0]] = arguments[1]; + } + if (useNewObject) { + values = new Map(values); + } else { + var mapClone = this.serialize(); + assign(mapClone, values); + values = mapClone; + } + return validator(values); + } else { + return this.errors(); + } + }; + Map.prototype.errors = function () { + var _errors = this._errors; + var errors; + if (arguments.length) { + var errorsObj = formatErrors(_errors, 'errors-object'); + errors = []; + canReflect.eachIndex(arguments, function (key) { + [].push.apply(errors, errorsObj ? errorsObj[key] : []); + }); + errors = errors.length > 0 ? errors : undefined; + } else { + errors = _errors; + } + return errors; + }; + define.property(Map.prototype, '_errors', { + get: function () { + var errors = validator(this); + return errors; + } + }, mapDefinition.dataInitializers, mapDefinition.computedInitializers); + }; + var decorator = function (Map) { + var constraints = getMapConstraints(Map); + var validator = validate.many(constraints); + validateMap(Map, function (map) { + var errors = validator(map); + return formatErrors(errors, 'errors'); + }); + }; + decorator.validatejs = validate.validatejs; + module.exports = decorator; +}); +/*[global-shim-end]*/ +(function(global) { // jshint ignore:line + global._define = global.define; + global.define = global.define.orig; +} +)(typeof self == "object" && self.Object == Object ? self : window); +//# sourceMappingURL=can-define-validate-validatejs.js.map \ No newline at end of file diff --git a/dist/global/can-define-validate-validatejs.js.map b/dist/global/can-define-validate-validatejs.js.map new file mode 100644 index 0000000..513645c --- /dev/null +++ b/dist/global/can-define-validate-validatejs.js.map @@ -0,0 +1 @@ +{"version":3,"sources":["../../../can-define-validate-validatejs.js"],"names":["validate","require","define","assign","canReflect","formatErrors","isEmptyObject","getMapConstraints","Map","constraints","eachKey","prototype","_define","definitions","prop","key","validateMap","validator","mapDefinition","testSet","values","useNewObject","arguments","length","Boolean","mapClone","serialize","errors","_errors","errorsObj","eachIndex","push","apply","undefined","property","get","dataInitializers","computedInitializers","decorator","many","map","validatejs","module","exports"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAAA,IAAIA,QAAA,GAAWC,OAAA,CAAQ,yBAAR,CAAf,C;IACA,IAAIC,MAAA,GAASD,OAAA,CAAQ,YAAR,CAAb,C;IACA,IAAIE,MAAA,GAASF,OAAA,CAAQ,YAAR,CAAb,C;IACA,IAAIG,UAAA,GAAaH,OAAA,CAAQ,aAAR,CAAjB,C;IACA,IAAII,YAAA,GAAeJ,OAAA,CAAQ,cAAR,EAAwBI,YAA3C,C;IACA,IAAIC,aAAA,GAAgBL,OAAA,CAAQ,6CAAR,CAApB,C;IAEA,IAAIM,iBAAA,GAAoB,UAASC,GAAT,EAAc;AAAA,QACrC,IAAIC,WAAA,GAAc,EAAlB,CADqC;AAAA,QAErCL,UAAA,CAAWM,OAAX,CAAmBF,GAAA,CAAIG,SAAJ,CAAcC,OAAd,CAAsBC,WAAzC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