From 2affa683e2758e743b634f68f89df13fd163ae35 Mon Sep 17 00:00:00 2001 From: gcanti Date: Sat, 6 Dec 2014 10:14:16 +0100 Subject: [PATCH] v0.2.2 - added optimization of structs validation when `value` is an instance of `type` --- .gitignore | 1 - CHANGELOG.md | 4 ++++ bower.json | 3 +-- index.js | 31 ++++++++++++++++++------------- package.json | 2 +- tcomb-validation.min.js | 4 ++-- tcomb-validation.min.js.map | 2 +- test/test.js | 3 ++- 8 files changed, 29 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 5384500..3351ce2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ *.log node_modules -build diff --git a/CHANGELOG.md b/CHANGELOG.md index ee9f3eb..fc46dbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +v0.2.2 + +- added optimization of structs validation when `value` is an instance of `type` + v0.2.1 - update to tcomb v0.3.4 diff --git a/bower.json b/bower.json index 4682e7b..289120b 100644 --- a/bower.json +++ b/bower.json @@ -1,7 +1,7 @@ { "name": "tcomb-validation", "main": "index.js", - "version": "0.2.1", + "version": "0.2.2", "homepage": "https://github.com/gcanti/tcomb-validation", "authors": [ "gcanti " @@ -28,7 +28,6 @@ "package.json", "Gruntfile.js", ".jshintrc", - "CHANGELOG.md", "LICENSE", "README.md" ] diff --git a/index.js b/index.js index bdc9d9b..5edfb78 100644 --- a/index.js +++ b/index.js @@ -68,13 +68,13 @@ // validate // - function _validate(x, type, path) { - var kind = t.util.getKind(type); - return validators[kind](x, type, path); + function validate(x, type) { + return new ValidationResult(recurse(x, type, [])); } - function validate(x, type) { - return new ValidationResult(_validate(x, type, [])); + function recurse(x, type, path) { + var kind = t.util.getKind(type); + return validators[kind](x, type, path); } var validators = {}; @@ -98,7 +98,7 @@ var ret = {value: [], errors: []}; // every item should be of type `type.meta.type` for (var i = 0, len = x.length ; i < len ; i++ ) { - var item = _validate(x[i], type.meta.type, path.concat(i)); + var item = recurse(x[i], type.meta.type, path.concat(i)); ret.value[i] = item.value; ret.errors = ret.errors.concat(item.errors); } @@ -108,7 +108,7 @@ validators.subtype = function validateSubtype(x, type, path) { // x should be a valid inner type - var ret = _validate(x, type.meta.type, path); + var ret = recurse(x, type.meta.type, path); if (ret.errors.length) { return ret; } @@ -125,7 +125,7 @@ validators.maybe = function validateMaybe(x, type, path) { return t.Nil.is(x) ? {value: null, errors: []} : - _validate(x, type.meta.type, path); + recurse(x, type.meta.type, path); }; validators.struct = function validateStruct(x, type, path) { @@ -135,12 +135,17 @@ return {value: x, errors: [ValidationError.of(x, type, path)]}; } + // [optimization] + if (type.is(x)) { + return {value: x, errors: []}; + } + var ret = {value: {}, errors: []}; var props = type.meta.props; // every item should be of type `props[name]` for (var name in props) { if (props.hasOwnProperty(name)) { - var prop = _validate(x[name], props[name], path.concat(name)); + var prop = recurse(x[name], props[name], path.concat(name)); ret.value[name] = prop.value; ret.errors = ret.errors.concat(prop.errors); } @@ -164,7 +169,7 @@ var ret = {value: [], errors: []}; // every item should be of type `types[i]` for (var i = 0 ; i < len ; i++ ) { - var item = _validate(x[i], types[i], path.concat(i)); + var item = recurse(x[i], types[i], path.concat(i)); ret.value[i] = item.value; ret.errors = ret.errors.concat(item.errors); } @@ -184,8 +189,8 @@ for (var k in x) { if (x.hasOwnProperty(k)) { path = path.concat(k); - var key = _validate(k, type.meta.domain, path); - var item = _validate(x[k], type.meta.codomain, path); + var key = recurse(k, type.meta.domain, path); + var item = recurse(x[k], type.meta.codomain, path); ret.value[k] = item.value; ret.errors = ret.errors.concat(key.errors, item.errors); } @@ -196,7 +201,7 @@ validators.union = function validateUnion(x, type, path) { var ctor = type.dispatch(x); return t.Func.is(ctor)? - _validate(x, ctor, path.concat(type.meta.types.indexOf(ctor))) : + recurse(x, ctor, path.concat(type.meta.types.indexOf(ctor))) : {value: x, errors: [ValidationError.of(x, type, path)]}; }; diff --git a/package.json b/package.json index a79cff0..f9beda2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tcomb-validation", - "version": "0.2.1", + "version": "0.2.2", "description": "General purpose validation library for JavaScript", "main": "index.js", "scripts": { diff --git a/tcomb-validation.min.js b/tcomb-validation.min.js index a9c6068..b89be06 100644 --- a/tcomb-validation.min.js +++ b/tcomb-validation.min.js @@ -1,6 +1,6 @@ -// tcomb-validation 0.2.1 +// tcomb-validation 0.2.2 // https://github.com/gcanti/tcomb-validation // (c) 2014 Giulio Canti // tcomb-validation may be freely distributed under the MIT license. -!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["tcomb"],b):"object"==typeof exports?module.exports=b(require("tcomb")):a.t=b(a.t)}(this,function(a){"use strict";function b(a,b,c){return k("%s is `%j` should be a `%s`","/"+c.join("/"),a,b.meta.name)}function c(b,c,d){var e=a.util.getKind(c);return n[e](b,c,d)}function d(a,b){return new m(c(a,b,[]))}var e=a.Any,f=a.Obj,g=a.Str,h=a.Arr,i=a.struct,j=a.list,k=a.util.format,l=i({message:g,actual:e,expected:a.Type,path:j(a.union([g,a.Num]))},"ValidationError");l.of=function(a,c,d){return new l({message:b(a,c,d),actual:a,expected:c,path:d})};var m=i({errors:j(l),value:e},"ValidationResult");m.prototype.isValid=function(){return!this.errors.length},m.prototype.firstError=function(){return this.isValid()?null:this.errors[0]},m.prototype.toString=function(){return this.isValid()?k("[ValidationResult, true, %j]",this.value):k("[ValidationResult, false, (%s)]",this.errors.map(function(a){return a.message}).join(", "))};var n={};return n.irriducible=n.enums=function(a,b,c){return{value:a,errors:b.is(a)?[]:[l.of(a,b,c)]}},n.list=function(a,b,d){if(!h.is(a))return{value:a,errors:[l.of(a,b,d)]};for(var e={value:[],errors:[]},f=0,g=a.length;g>f;f++){var i=c(a[f],b.meta.type,d.concat(f));e.value[f]=i.value,e.errors=e.errors.concat(i.errors)}return e},n.subtype=function(a,b,d){var e=c(a,b.meta.type,d);return e.errors.length?e:(b.meta.predicate(e.value)||(e.errors=[l.of(a,b,d)]),e)},n.maybe=function(b,d,e){return a.Nil.is(b)?{value:null,errors:[]}:c(b,d.meta.type,e)},n.struct=function(a,b,d){if(!f.is(a))return{value:a,errors:[l.of(a,b,d)]};var e={value:{},errors:[]},g=b.meta.props;for(var h in g)if(g.hasOwnProperty(h)){var i=c(a[h],g[h],d.concat(h));e.value[h]=i.value,e.errors=e.errors.concat(i.errors)}return e.errors.length||(e.value=new b(e.value)),e},n.tuple=function(a,b,d){var e=b.meta.types,f=e.length;if(!h.is(a)||a.length>f)return{value:a,errors:[l.of(a,b,d)]};for(var g={value:[],errors:[]},i=0;f>i;i++){var j=c(a[i],e[i],d.concat(i));g.value[i]=j.value,g.errors=g.errors.concat(j.errors)}return g},n.dict=function(a,b,d){if(!f.is(a))return{value:a,errors:[l.of(a,b,d)]};var e={value:{},errors:[]};for(var g in a)if(a.hasOwnProperty(g)){d=d.concat(g);var h=c(g,b.meta.domain,d),i=c(a[g],b.meta.codomain,d);e.value[g]=i.value,e.errors=e.errors.concat(h.errors,i.errors)}return e},n.union=function(b,d,e){var f=d.dispatch(b);return a.Func.is(f)?c(b,f,e.concat(d.meta.types.indexOf(f))):{value:b,errors:[l.of(b,d,e)]}},a.util.mixin(a,{ValidationError:l,ValidationResult:m,validate:d}),a}); +!function(a,b){"use strict";"function"==typeof define&&define.amd?define(["tcomb"],b):"object"==typeof exports?module.exports=b(require("tcomb")):a.t=b(a.t)}(this,function(a){"use strict";function b(a,b,c){return k("%s is `%j` should be a `%s`","/"+c.join("/"),a,b.meta.name)}function c(a,b){return new m(d(a,b,[]))}function d(b,c,d){var e=a.util.getKind(c);return n[e](b,c,d)}var e=a.Any,f=a.Obj,g=a.Str,h=a.Arr,i=a.struct,j=a.list,k=a.util.format,l=i({message:g,actual:e,expected:a.Type,path:j(a.union([g,a.Num]))},"ValidationError");l.of=function(a,c,d){return new l({message:b(a,c,d),actual:a,expected:c,path:d})};var m=i({errors:j(l),value:e},"ValidationResult");m.prototype.isValid=function(){return!this.errors.length},m.prototype.firstError=function(){return this.isValid()?null:this.errors[0]},m.prototype.toString=function(){return this.isValid()?k("[ValidationResult, true, %j]",this.value):k("[ValidationResult, false, (%s)]",this.errors.map(function(a){return a.message}).join(", "))};var n={};return n.irriducible=n.enums=function(a,b,c){return{value:a,errors:b.is(a)?[]:[l.of(a,b,c)]}},n.list=function(a,b,c){if(!h.is(a))return{value:a,errors:[l.of(a,b,c)]};for(var e={value:[],errors:[]},f=0,g=a.length;g>f;f++){var i=d(a[f],b.meta.type,c.concat(f));e.value[f]=i.value,e.errors=e.errors.concat(i.errors)}return e},n.subtype=function(a,b,c){var e=d(a,b.meta.type,c);return e.errors.length?e:(b.meta.predicate(e.value)||(e.errors=[l.of(a,b,c)]),e)},n.maybe=function(b,c,e){return a.Nil.is(b)?{value:null,errors:[]}:d(b,c.meta.type,e)},n.struct=function(a,b,c){if(!f.is(a))return{value:a,errors:[l.of(a,b,c)]};if(b.is(a))return{value:a,errors:[]};var e={value:{},errors:[]},g=b.meta.props;for(var h in g)if(g.hasOwnProperty(h)){var i=d(a[h],g[h],c.concat(h));e.value[h]=i.value,e.errors=e.errors.concat(i.errors)}return e.errors.length||(e.value=new b(e.value)),e},n.tuple=function(a,b,c){var e=b.meta.types,f=e.length;if(!h.is(a)||a.length>f)return{value:a,errors:[l.of(a,b,c)]};for(var g={value:[],errors:[]},i=0;f>i;i++){var j=d(a[i],e[i],c.concat(i));g.value[i]=j.value,g.errors=g.errors.concat(j.errors)}return g},n.dict=function(a,b,c){if(!f.is(a))return{value:a,errors:[l.of(a,b,c)]};var e={value:{},errors:[]};for(var g in a)if(a.hasOwnProperty(g)){c=c.concat(g);var h=d(g,b.meta.domain,c),i=d(a[g],b.meta.codomain,c);e.value[g]=i.value,e.errors=e.errors.concat(h.errors,i.errors)}return e},n.union=function(b,c,e){var f=c.dispatch(b);return a.Func.is(f)?d(b,f,e.concat(c.meta.types.indexOf(f))):{value:b,errors:[l.of(b,c,e)]}},a.util.mixin(a,{ValidationError:l,ValidationResult:m,validate:c}),a}); //# sourceMappingURL=tcomb-validation.min.js.map \ No newline at end of file diff --git a/tcomb-validation.min.js.map b/tcomb-validation.min.js.map index 08438cd..fb8a900 100644 --- a/tcomb-validation.min.js.map +++ b/tcomb-validation.min.js.map @@ -1 +1 @@ -{"version":3,"file":"tcomb-validation.min.js","sources":["index.js"],"names":["root","factory","define","amd","exports","module","require","t","this","getDefaultMessage","actual","expected","path","format","join","meta","name","_validate","x","type","kind","util","getKind","validators","validate","ValidationResult","Any","Obj","Str","Arr","struct","list","ValidationError","message","Type","union","Num","of","errors","value","prototype","isValid","firstError","toString","map","err","irriducible","enums","is","ret","i","len","length","item","concat","subtype","predicate","maybe","Nil","props","hasOwnProperty","prop","tuple","types","dict","k","key","domain","codomain","ctor","dispatch","Func","indexOf","mixin"],"mappings":";;;;CAAC,SAAUA,EAAMC,GACf,YACsB,mBAAXC,SAAyBA,OAAOC,IACzCD,QAAQ,SAAUD,GACU,gBAAZG,SAChBC,OAAOD,QAAUH,EAAQK,QAAQ,UAEjCN,EAAKO,EAAIN,EAAQD,EAAKO,IAExBC,KAAM,SAAUD,GAEhB,YAqBA,SAASE,GAAkBC,EAAQC,EAAUC,GAC3C,MAAOC,GAAO,8BAA+B,IAAMD,EAAKE,KAAK,KAAMJ,EAAQC,EAASI,KAAKC,MAqC3F,QAASC,GAAUC,EAAGC,EAAMP,GAC1B,GAAIQ,GAAOb,EAAEc,KAAKC,QAAQH,EAC1B,OAAOI,GAAWH,GAAMF,EAAGC,EAAMP,GAGnC,QAASY,GAASN,EAAGC,GACnB,MAAO,IAAIM,GAAiBR,EAAUC,EAAGC,OA/D3C,GAAIO,GAAMnB,EAAEmB,IACRC,EAAMpB,EAAEoB,IACRC,EAAMrB,EAAEqB,IACRC,EAAMtB,EAAEsB,IACRC,EAASvB,EAAEuB,OACXC,EAAOxB,EAAEwB,KACTlB,EAASN,EAAEc,KAAKR,OAMhBmB,EAAkBF,GACpBG,QAASL,EACTlB,OAAQgB,EACRf,SAAUJ,EAAE2B,KACZtB,K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EAAEgC,GAAIa,EAAMb,GAAItC,EAAK0C,OAAOJ,GACjDD,GAAIV,MAAMW,GAAKG,EAAKd,MACpBU,EAAIX,OAASW,EAAIX,OAAOgB,OAAOD,EAAKf,QAEtC,MAAOW,IAGT1B,EAAWyC,KAAO,SAAsB9C,EAAGC,EAAMP,GAG/C,IAAKe,EAAIqB,GAAG9B,GACV,OAAQqB,MAAOrB,EAAGoB,QAASN,EAAgBK,GAAGnB,EAAGC,EAAMP,IAGzD,IAAIqC,IAAOV,SAAWD,UAGtB,KAAK,GAAI2B,KAAK/C,GACZ,GAAIA,EAAE0C,eAAeK,GAAI,CACvBrD,EAAOA,EAAK0C,OAAOW,EACnB,IAAIC,GAAMjD,EAAUgD,EAAG9C,EAAKJ,KAAKoD,OAAQvD,GACrCyC,EAAOpC,EAAUC,EAAE+C,GAAI9C,EAAKJ,KAAKqD,SAAUxD,EAC/CqC,GAAIV,MAAM0B,GAAKZ,EAAKd,MACpBU,EAAIX,OAASW,EAAIX,OAAOgB,OAAOY,EAAI5B,OAAQe,EAAKf,QAGpD,MAAOW,IAGT1B,EAAWY,MAAQ,SAAuBjB,EAAGC,EAAMP,GACjD,GAAIyD,GAAOlD,EAAKmD,SAASpD,EACzB,OAAOX,GAAEgE,KAAKvB,GAAGqB,GACfpD,EAAUC,EAAGmD,EAAMzD,EAAK0C,OAAOnC,EAAKJ,KAAKgD,MAAMS,QAAQH,MACtD9B,MAAOrB,EAAGoB,QAASN,EAAgBK,GAAGnB,EAAGC,EAAMP,MAIpDL,EAAEc,KAAKoD,MAAMlE,GACXyB,gBAAiBA,EACjBP,iBAAkBA,EAClBD,SAAUA,IAGLjB"} \ No newline at end of file +{"version":3,"file":"tcomb-validation.min.js","sources":["index.js"],"names":["root","factory","define","amd","exports","module","require","t","this","getDefaultMessage","actual","expected","path","format","join","meta","name","validate","x","type","ValidationResult","recurse","kind","util","getKind","validators","Any","Obj","Str","Arr","struct","list","ValidationError","message","Type","union","Num","of","errors","value","prototype","isValid","firstError","toString","map","err","irriducible","enums","is","ret","i","len","length","item","concat","subtype","predicate","maybe","Nil","props","hasOwnProperty","prop","tuple","types","dict","k","key","domain","codomain","ctor","dispatch","Func","indexOf","mixin"],"mappings":";;;;CAAC,SAAUA,EAAMC,GACf,YACsB,mBAAXC,SAAyBA,OAAOC,IACzCD,QAAQ,SAAUD,GACU,gBAAZG,SAChBC,OAAOD,QAAUH,EAAQK,QAAQ,UAEjCN,EAAKO,EAAIN,EAAQD,EAAKO,IAExBC,KAAM,SAAUD,GAEhB,YAqBA,SAASE,GAAkBC,EAAQC,EAAUC,GAC3C,MAAOC,GAAO,8BAA+B,IAAMD,EAAKE,KAAK,KAAMJ,EAAQC,EAASI,KAAKC,MAqC3F,QAASC,GAASC,EAAGC,GACnB,MAAO,IAAIC,GAAiBC,EAAQH,EAAGC,OAGzC,QAASE,GAAQH,EAAGC,EAAMP,GACxB,GAAIU,GAAOf,EAAEgB,KAAKC,QAAQL,EAC1B,OAAOM,GAAWH,GAAMJ,EAAGC,EAAMP,GA/DnC,GAAIc,GAAMnB,EAAEmB,IACRC,EAAMpB,EAAEoB,IACRC,EAAMrB,EAAEqB,IACRC,EAAMtB,EAAEsB,IACRC,EAASvB,EAAEuB,OACXC,EAAOxB,EAAEwB,KACTlB,EAASN,EAAEgB,KAAKV,OAMhBmB,EAAkBF,GACpBG,QAASL,EACTlB,OAAQgB,EACRf,SAAUJ,EAAE2B,KACZtB,KAAMmB,EAAKxB,EAAE4B,OAAOP,EAAKrB,EAAE6B,QAC1B,kBAMHJ,GAAgBK,GAAK,SAAY3B,EAAQC,EAAUC,GACjD,MAAO,IAAIoB,IACTC,QAASxB,EAAkBC,EAAQC,EAAUC,GAC7CF,OAAQA,EACRC,SAAUA,EACVC,KAAMA,IAIV,IAAIQ,GAAmBU,GACrBQ,OAAQP,EAAKC,GACbO,MAAOb,GACN,mBAEHN,GAAiBoB,UAAUC,QAAU,WACnC,OAASjC,KAAK8B,OAAa,QAG7BlB,EAAiB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nB,EAAGC,EAAMP,IAGzD,IAAIqC,IAAOV,SAAWD,UAGtB,KAAK,GAAI2B,KAAK/C,GACZ,GAAIA,EAAE0C,eAAeK,GAAI,CACvBrD,EAAOA,EAAK0C,OAAOW,EACnB,IAAIC,GAAM7C,EAAQ4C,EAAG9C,EAAKJ,KAAKoD,OAAQvD,GACnCyC,EAAOhC,EAAQH,EAAE+C,GAAI9C,EAAKJ,KAAKqD,SAAUxD,EAC7CqC,GAAIV,MAAM0B,GAAKZ,EAAKd,MACpBU,EAAIX,OAASW,EAAIX,OAAOgB,OAAOY,EAAI5B,OAAQe,EAAKf,QAGpD,MAAOW,IAGTxB,EAAWU,MAAQ,SAAuBjB,EAAGC,EAAMP,GACjD,GAAIyD,GAAOlD,EAAKmD,SAASpD,EACzB,OAAOX,GAAEgE,KAAKvB,GAAGqB,GACfhD,EAAQH,EAAGmD,EAAMzD,EAAK0C,OAAOnC,EAAKJ,KAAKgD,MAAMS,QAAQH,MACpD9B,MAAOrB,EAAGoB,QAASN,EAAgBK,GAAGnB,EAAGC,EAAMP,MAIpDL,EAAEgB,KAAKkD,MAAMlE,GACXyB,gBAAiBA,EACjBZ,iBAAkBA,EAClBH,SAAUA,IAGLV"} \ No newline at end of file diff --git a/test/test.js b/test/test.js index d623395..e89584a 100644 --- a/test/test.js +++ b/test/test.js @@ -28,7 +28,7 @@ function success(value) { // var ok = function (x) { assert.strictEqual(true, x); }; -var eq = assert.deepEqual; +var eq = assert.deepEqual; describe('validate()', function () { @@ -58,6 +58,7 @@ describe('validate()', function () { eq(validate({x: 0, y: 0}, Point), success({x: 0, y: 0})); ok(validate({x: 0, y: 0}, Point).value instanceof Point); eq(validate({x: 0, y: 'a'}, Point), failure('a', Num, ['y'], '/y is `"a"` should be a `Num`', {x: 0, y: 'a'})); + eq(validate(new Point({x: 0, y: 0}), Point), success({x: 0, y: 0})); }); it('list', function () {