loco-js-model
Advanced tools
Comparing version 0.2.0 to 0.2.1
@@ -1,1 +0,1 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.LocoModel=e():t.LocoModel=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var s=r[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=7)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(3),o=r.n(s);n=function(){function t(){this.obj=null,this.attr=null,this.val=null,this.opts=null}return t.sharedInstances={},t.instance=function(t,e,r){var n,s;return s=this.identity,null==this.sharedInstances[s]&&(this.sharedInstances[s]=new o.a[s]),n=this.sharedInstances[s],n.assignAttribs(t,e,r),n},t.prototype.assignAttribs=function(t,e,r){return this.obj=t,this.attr=e,this.val=this.obj[this.attr],this.opts=r},t}(),e.default=n},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o="en",i=null,a=null,u=function(){function t(){n(this,t)}return s(t,[{key:"locale",get:function(){return o},set:function(t){return o=t}},{key:"protocolWithHost",get:function(){return i},set:function(t){return i=t?"/"===t[t.length-1]?t.slice(0,t.length-1):t:null}},{key:"scope",get:function(){return a},set:function(t){return a=t}}]),t}(),l=new u;e.default=l},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(10),s=function(t){return t&&t.__esModule?t:{default:t}}(n),o={en:s.default};e.default=o},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var s=r(9),o=n(s),i=r(11),a=n(i),u=r(12),l=n(u),c=r(13),p=n(c),h=r(14),f=n(h),d=r(4),_=n(d),g=r(15),y=n(g),v=r(16),m=n(v),b=r(17),M=n(b),E={Absence:o.default,Confirmation:a.default,Exclusion:l.default,Format:p.default,Inclusion:f.default,Length:_.default,Numericality:y.default,Presence:m.default,Size:M.default};e.default=E},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Length",e.prototype.validate=function(){var t;if(null!=this.val&&null!==(t=null!=this._range()[0]&&null!=this._range()[1]&&this._range()[0]===this._range()[1]&&this.val.length!==this._range()[0]?this._selectErrorMessage("wrong_length",this._range()[0]):null!=this._range()[0]&&this.val.length<this._range()[0]?this._selectErrorMessage("too_short",this._range()[0]):null!=this._range()[1]&&this.val.length>this._range()[1]?this._selectErrorMessage("too_long",this._range()[1]):null))return this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._range=function(){var t,e;return t=this.opts.minimum||this.opts.is||null!=this.opts.within&&this.opts.within[0]||null,e=this.opts.maximum||this.opts.is||null!=this.opts.within&&this.opts.within[1]||null,[t,e]},e.prototype._selectErrorMessage=function(t,e){var r,n,s,o,a;if(1===e)return i.a[u.a.locale].errors.messages[t].one;for(s=null,o=["few","many"],r=0,n=o.length;r<n;r++)if(a=o[r],this._checkVariant(a,e)){s=i.a[u.a.locale].errors.messages[t][a];break}return null==s&&(s=i.a[u.a.locale].errors.messages[t].other),null!=this.opts.message&&(s=this.opts.message),/%{count}/.exec(s)&&(s=s.replace("%{count}",e)),s},e.prototype._checkVariant=function(t,e){if(null!=i.a[u.a.locale].variants[t])return i.a[u.a.locale].variants[t](e)},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n=function(){function t(){}return t.imap={},t.clear=function(){return this.imap={}},t.add=function(t){var e;return e=t.getIdentity(),null==this.imap[e]&&(this.imap[e]={}),null==this.imap[e][t.id]&&(this.imap[e][t.id]=[]),this.imap[e][t.id][0]=t},t.connect=function(t,e){var r;return null==e&&(e={}),r=e.with,this.add(r),this.imap[r.getIdentity()][r.id].push(t)},t.addCollection=function(t,e){if(null==e&&(e={}),null==this.imap[t]&&(this.imap[t]={}),null==this.imap[t].collection&&(this.imap[t].collection=[]),-1===this.imap[t].collection.indexOf(e.to))return this.imap[t].collection.push(e.to)},t.all=function(t){var e,r,n,s;if(null==this.imap[t])return null;e=[],s=this.imap[t];for(r in s)n=s[r],"collection"!==r&&e.push(n[0]);return e},t.find=function(t,e){return this.imap[t]&&this.imap[t][e]?this.imap[t][e][0]:null},t.findConnected=function(t,e){var r;return this.imap[t]&&this.imap[t][e]&&this.imap[t][e].length>1?(r=this.imap[t][e],r.slice(1,+(r.length-1)+1||9e9)):[]},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n={};e.default=n},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.Validators=e.Models=e.IdentityMap=e.I18n=e.Config=e.Base=void 0;var s=r(8),o=n(s),i=r(5),a=n(i),u=r(0),l=n(u),c=r(3),p=n(c),h=r(1),f=n(h),d=r(2),_=n(d),g=r(6),y=n(g);p.default.Base=l.default,y.default.Base=o.default,e.Base=o.default,e.Config=f.default,e.I18n=_.default,e.IdentityMap=a.default,e.Models=y.default,e.Validators=p.default},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(3),o=r.n(s),i=r(1),a=r.n(i),u=r(18),l=r.n(u),c=r(5),p=r(6),h=r.n(p);n=function(){function t(t){null==t&&(t={}),this.id=null,this.errors=null,this.resource=t.resource,null!=this.constructor.attributes&&this.__initAttributes(),null!=t&&this.__assignAttributes(t)}return t.all=function(t){return null==t&&(t={}),this.get("all",t)},t.find=function(t){var e,r,n;return n={},"object"==typeof t?(n=t,e=t.id,delete n.id):e=t,r=new XMLHttpRequest,r.open("GET",this.__getResourcesUrl(n)+"/"+e),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),r.send(JSON.stringify(n)),new Promise(function(t){return function(e,n){return r.onerror=function(t){return n(t)},r.onload=function(r){var n,s;return s=JSON.parse(r.target.response),n=t.__initSubclass(s),c.default.add(n),e(n)}}}(this))},t.get=function(t,e){return null==e&&(e={}),this.__send("GET",t,e)},t.post=function(t,e){return null==e&&(e={}),this.__send("POST",t,e)},t.put=function(t,e){return null==e&&(e={}),this.__send("PUT",t,e)},t.delete=function(t,e){return null==e&&(e={}),this.__send("DELETE",t,e)},t.getIdentity=function(){if(null!=this.identity)return this.identity;throw"Specify Model's @identity!"},t.getRemoteName=function(){return null!=this.remoteName?this.remoteName:this.getIdentity()},t.getAttribRemoteName=function(t){return null==this.attributes?null:null==this.attributes[t]?null:null==this.attributes[t].remoteName?t:this.attributes[t].remoteName},t.getResourcesUrlParams=function(){var t,e,r,n;for(n=this.__getResourcesUrl(),r=/:(\w+)\/?/,e=[];t=r.exec(n);)e.push(t[1]),n=n.replace(t[0],t[1]);return e},t.__getResourcesUrl=function(t){var e,r;return null==t&&(t={}),r=null==this.resources?"/"+this.getRemoteName().toLowerCase()+"s":t.resource?this.resources[t.resource].url:null!=a.a.scope&&null!=this.resources[a.a.scope]?this.resources[a.a.scope].url:this.resources.url,null!=a.a.protocolWithHost&&(r=""+a.a.protocolWithHost+r),null==(e=/:(\w+)\/?/.exec(r))?r:(null!=t[e[1]]?(r=r.replace(":"+e[1],t[e[1]]),delete t[e[1]]):null!=t.obj&&null!=t.obj[e[1]]&&(r=r.replace(":"+e[1],t.obj[e[1]])),r)},t.__initSubclass=function(t){var e,r;return null==t&&(t={}),r=this.getIdentity().split("."),1===r.length?(e=h.a[r[0]],null==e?new this(t):new e(t)):new(e=h.a[r[0]][r[1]])(t)},t.__page=function(t,e,r,n){var s,o,i,a,u,p,h,f;if(null==e&&(e={}),null==r&&(r={}),null==n&&(n={resources:[],count:0}),o=r.method||"GET",h=r.url||this.__getResourcesUrl(e),s={},null!=r.data){a=r.data;for(i in a)f=a[i],"resource"!==i&&(s[i]=f)}return s[this.__getPaginationParam()]=t,"GET"===o&&(h=h+"?"+l.a.Obj.toURIParams(s)),p=new XMLHttpRequest,p.open(o,h),p.setRequestHeader("Accept","application/json"),p.setRequestHeader("Content-Type","application/json"),p.setRequestHeader("X-CSRF-Token",null!=(u=document.querySelector("meta[name='csrf-token']"))?u.content:void 0),p.send(JSON.stringify(s)),new Promise(function(t){return function(r,o){return p.onerror=function(t){return o(t)},p.onload=function(o){var a,u,l,p,h;s=JSON.parse(o.target.response),n.count=s.count;for(i in s)f=s[i],-1===["resources","count"].indexOf(i)&&(n[i]=f);for(h=s.resources,a=0,u=h.length;a<u;a++)p=h[a],l=t.__initSubclass(p),null!=e.resource&&(l.resource=e.resource),c.default.add(l),n.resources.push(l);return r(n)}}}(this))},t.__paginate=function(t,e){var r,n,s;return n=this.__getPaginationPer(),r=null!=(s=t.page)?s:1,this.__page(r,t,e).then(function(r){return function(s){var o,i,a,u,l;if(null!=t.page)return Promise.resolve(s);if(s.count<=n)return Promise.resolve(s);if(a=parseInt(s.count/n),a!==s.count/n&&(a+=1),u=Promise.resolve(s),1===a)return u;for(o=i=2,l=a;2<=l?i<=l:i>=l;o=2<=l?++i:--i)(function(n){return u=u.then(function(o){return r.__page(n,t,e,s)})})(o);return u}}(this))},t.__getPaginationParam=function(){var t,e,r,n,s,o;return t="page",null!=a.a.scope&&null!=this.resources&&null!=this.resources[a.a.scope]?(e=null!=(r=this.resources[a.a.scope])&&null!=(n=r.paginate)?n.param:void 0,null!=e?e:t):null!=(null!=(s=this.resources)&&null!=(o=s.paginate)?o.param:void 0)?this.resources.paginate.param:t},t.__getPaginationPer=function(){var t,e,r,n;return null!=a.a.scope&&null!=this.resources&&null!=this.resources[a.a.scope]?null!=(t=this.resources[a.a.scope])&&null!=(e=t.paginate)?e.per:void 0:null!=(null!=(r=this.resources)&&null!=(n=r.paginate)?n.per:void 0)?this.resources.paginate.per:null},t.__send=function(t,e,r){var n,s;return s=this.__getResourcesUrl(r),"all"!==e&&(s=s+"/"+e),n={method:t,url:s,data:r},this.__paginate(r,n)},t.prototype.setResource=function(t){return this.resource=t},t.prototype.getIdentity=function(){return this.constructor.getIdentity()},t.prototype.getAttrRemoteName=function(t){return null==this.constructor.attributes?null:null==this.constructor.attributes[t]?null:this.constructor.attributes[t].remoteName||t},t.prototype.getAttrName=function(t){var e,r,n;if(null==this.constructor.attributes)return t;if(null!=this.constructor.attributes[t])return t;n=this.constructor.attributes;for(r in n)if(e=n[r],e.remoteName===t)return r;return t},t.prototype.getAttrType=function(t){return null==this.constructor.attributes?null:null==this.constructor.attributes[t]?null:this.constructor.attributes[t].type},t.prototype.assignAttr=function(t,e){var r;if(r=this.getAttrType(t),null==e)return void(this[t]=null);switch(r){case"Date":e=new Date(Date.parse(e));break;case"Integer":case"Int":e=parseInt(e);break;case"Float":e=parseFloat(e);break;case"Boolean":case"Bool":e="boolean"==typeof e?e:Boolean(parseInt(e));break;case"Number":e=Number(e);break;case"String":e=String(e)}return this[t]=e},t.prototype.attributes=function(){var t,e,r;if(t={id:this.id},null==this.constructor.attributes)return t;r=this.constructor.attributes;for(e in r)r[e],t[e]=this[e];return t},t.prototype.isValid=function(){var t,e,r,n,s,i,a,u,l,c,p,h;if(null==this.constructor.attributes)return!0;this.errors=null,a=this.constructor.attributes;for(s in a)if(t=a[s],null!=t.validations){u=t.validations;for(c in u)p=u[c],null!=this.id&&"create"===p.on||null==this.id&&"update"===p.on||(null==p.if||p.if(this))&&(h=c.charAt(0).toUpperCase()+c.slice(1),null!=o.a[h]?(i=this.__processedValidationSettings(p),o.a[h].instance(this,s,i).validate()):console.log('Warning! "'+h+'" validator is not implemented!'))}if(null!=this.constructor.validate)for(l=this.constructor.validate,e=0,r=l.length;e<r;e++)n=l[e],this[n]();return null==this.errors},t.prototype.isInvalid=function(){return!this.isValid()},t.prototype.isEmpty=function(){var t,e;e=this.attributes();for(t in e)if(e[t],null!==this[t])return!1;return!0},t.prototype.addErrorMessage=function(t,e){return null==e&&(e={}),null==this.errors&&(this.errors={}),null==this.errors[e.for]&&(this.errors[e.for]=[]),this.errors[e.for].push(t)},t.prototype.save=function(){var t,e,r;return t=null!=this.id?"PUT":"POST",r=new XMLHttpRequest,r.open(t,this.__getResourceUrl()),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),r.setRequestHeader("X-CSRF-Token",null!=(e=document.querySelector("meta[name='csrf-token']"))?e.content:void 0),r.send(JSON.stringify(this.serialize())),new Promise(function(t){return function(e,n){return r.onerror=function(t){return n(t)},r.onload=function(r){var n;return n=JSON.parse(r.target.response),n.success?void e(n):(null!=n.errors&&t.__assignRemoteErrorMessages(n.errors),e(n))}}}(this))},t.prototype.updateAttribute=function(t){var e,r;return r=new XMLHttpRequest,r.open("PUT",this.__getResourceUrl()),r.setRequestHeader("Accept","application/json"),r.setRequestHeader("Content-Type","application/json"),r.setRequestHeader("X-CSRF-Token",null!=(e=document.querySelector("meta[name='csrf-token']"))?e.content:void 0),r.send(JSON.stringify(this.serialize(t))),new Promise(function(t){return function(e,n){return r.onerror=function(t){return n(t)},r.onload=function(r){var s;return r.target.status>=200&&r.target.status<400?(s=JSON.parse(r.target.response),s.success?void e(s):(null!=s.errors&&t.__assignRemoteErrorMessages(s.errors),e(s))):r.target.status>=500?n(r):void 0}}}(this))},t.prototype.serialize=function(t){var e,r,n,s;if(null==t&&(t=null),null==this.constructor.attributes)return{};r={},n=this.constructor.getRemoteName().toLowerCase(),r[n]={},e={},null!=t?e[t]=null:e=this.constructor.attributes;for(t in e)e[t],s=this.getAttrRemoteName(t),r[n][s]=this[t];return r},t.prototype.reload=function(){var t,e,r,n,s;for(t={id:this.id},s=this.constructor.getResourcesUrlParams(),e=0,r=s.length;e<r;e++)n=s[e],t[n]=this[n];return this.constructor.find(t)},t.prototype.changes=function(){var t,e,r,n,s;n={},t=c.default.find(this.getIdentity(),this.id),r=this.attributes();for(e in r)if((s=r[e])!==t[e]){if(null!=s&&s.constructor===Date&&t[e]-s==0)continue;s!==t[e]&&(n[e]={is:t[e],was:s})}return n},t.prototype.applyChanges=function(){var t,e,r,n;e=this.changes(),r=[];for(t in e)n=e[t],r.push(this[t]=n.is);return r},t.prototype.toKey=function(){return this.getIdentity().toLowerCase()+"_"+this.id},t.prototype.get=function(t,e){return null==e&&(e={}),this.__send("GET",t,e)},t.prototype.post=function(t,e){return null==e&&(e={}),this.__send("POST",t,e)},t.prototype.put=function(t,e){return null==e&&(e={}),this.__send("PUT",t,e)},t.prototype.patch=function(t,e){return null==e&&(e={}),this.__send("PATCH",t,e)},t.prototype.delete=function(t,e){return null==e&&(e={}),this.__send("DELETE",t,e)},t.prototype.__send=function(t,e,r){var n,s,o;return o=this.__getResourceUrl(),null!=e&&(o=o+"/"+e),s=new XMLHttpRequest,s.open(t,o),s.setRequestHeader("Accept","application/json"),s.setRequestHeader("Content-Type","application/json"),s.setRequestHeader("X-CSRF-Token",null!=(n=document.querySelector("meta[name='csrf-token']"))?n.content:void 0),s.send(JSON.stringify(r)),new Promise(function(t,e){return s.onerror=function(t){return e(t)},s.onload=function(n){return n.target.status>=200&&n.target.status<400?(r=JSON.parse(n.target.response),t(r)):n.target.status>=500?e(n):void 0}})},t.prototype.__assignAttributes=function(t){var e,r,n,s;n=[];for(r in t)s=t[r],e=this.getAttrName(r),n.push(this.assignAttr(e,s));return n},t.prototype.__initAttributes=function(){var t,e,r;e=this.constructor.attributes,r=[];for(t in e)e[t],r.push(this[t]=null);return r},t.prototype.__assignRemoteErrorMessages=function(t){var e,r,n,s,o;o=[];for(s in t)n=t[s],e=this.getAttrName(s),o.push(function(){var t,s,o;for(o=[],t=0,s=n.length;t<s;t++)r=n[t],o.push(this.addErrorMessage(r,{for:e}));return o}.call(this));return o},t.prototype.__getResourceUrl=function(){var t;return t=this.constructor.__getResourcesUrl({resource:this.resource,obj:this}),null==this.id?t:t+"/"+this.id},t.prototype.__processedValidationSettings=function(t){var e,r,n;n={};for(e in t)r=t[e],n[e]="function"==typeof r?r(this):r;return n},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Absence",e.prototype.validate=function(){switch(typeof this.val){case"string":if(null!=this.val&&0===this.val.length)return;break;default:if(null==this.val)return}return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.present,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n={variants:{},models:{},attributes:{},errors:{messages:{accepted:"must be accepted",blank:"can't be blank",confirmation:"doesn't match %{attribute}",empty:"can't be empty",equal_to:"must be equal to %{count}",even:"must be even",exclusion:"is reserved",greater_than:"must be greater than %{count}",greater_than_or_equal_to:"must be greater than or equal to %{count}",inclusion:"is not included in the list",invalid:"is invalid",less_than:"must be less than %{count}",less_than_or_equal_to:"must be less than or equal to %{count}",not_a_number:"is not a number",not_an_integer:"must be an integer",odd:"must be odd",present:"must be blank",too_long:{one:"is too long (maximum is 1 character)",other:"is too long (maximum is %{count} characters)"},too_short:{one:"is too short (minimum is 1 character)",other:"is too short (minimum is %{count} characters)"},wrong_length:{one:"is the wrong length (should be 1 character)",other:"is the wrong length (should be %{count} characters)"},other_than:"must be other than %{count}"}}},e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Confirmation",e.prototype.validate=function(){var t;if(t=this.obj[this._properAttr()],null==this.val||null==t||this.val!==t)return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t,e,r,n;return r=this.attr.charAt(0).toUpperCase()+this.attr.slice(1),e=i.a[u.a.locale].attributes[this.obj.getIdentity()],t=e&&e[this.attr]||r,n=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.confirmation,n=n.replace("%{attribute}",t),this.obj.addErrorMessage(n,{for:this._properAttr()})},e.prototype._properAttr=function(){return this.attr+"Confirmation"},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Exclusion",e.prototype.validate=function(){var t;if(t=this.opts.in||this.opts.within||[],-1!==t.indexOf(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.exclusion,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Format",e.prototype.validate=function(){if(null==this.opts.with.exec(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.invalid,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Inclusion",e.prototype.validate=function(){var t;if(t=this.opts.in||this.opts.within||[],-1===t.indexOf(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.inclusion,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Numericality",e.prototype.validate=function(){return isNaN(this.val)?this._addNaNErrorMessage():null!=this.opts.only_integer&&Number(this.val)!==parseInt(this.val)?this._addIntErrorMessage():null!=this.opts.greater_than&&Number(this.val)<=this.opts.greater_than?this._addGreatherThanErrorMessage():null!=this.opts.greater_than_or_equal_to&&Number(this.val)<this.opts.greater_than_or_equal_to?this._addGreatherThanOrEqualToErrorMessage():null!=this.opts.equal_to&&Number(this.val)!==this.opts.equal_to?this._addEqualToErrorMessage():null!=this.opts.less_than&&Number(this.val)>=this.opts.less_than?this._addLessThanErrorMessage():null!=this.opts.less_than_or_equal_to&&Number(this.val)>this.opts.less_than_or_equal_to?this._addLessThanOrEqualToErrorMessage():null!=this.opts.other_than&&Number(this.val)===this.opts.other_than?this._addOtherThanErrorMessage():null!=this.opts.odd&&Number(this.val)%2!=1?this._addOddErrorMessage():null!=this.opts.even&&Number(this.val)%2!=0?this._addEvenErrorMessage():void 0},e.prototype._addNaNErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.not_a_number,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addIntErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.not_an_integer,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addGreatherThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.greater_than,t=t.replace("%{count}",this.opts.greater_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addGreatherThanOrEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.greater_than_or_equal_to,t=t.replace("%{count}",this.opts.greater_than_or_equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.equal_to,t=t.replace("%{count}",this.opts.equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addLessThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.less_than,t=t.replace("%{count}",this.opts.less_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addLessThanOrEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.less_than_or_equal_to,t=t.replace("%{count}",this.opts.less_than_or_equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addOtherThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.other_than,t=t.replace("%{count}",this.opts.other_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addOddErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.odd,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addEvenErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.even,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Presence",e.prototype.validate=function(){switch(typeof this.val){case"string":if(null!=this.val&&this.val.length>0)return;break;default:if(null!=this.val)return}return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.blank,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(4),i=function(t,e){function r(){this.constructor=t}for(var n in e)a.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},a={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return i(e,t),e.identity="Size",e.prototype.validate=function(){return o.default.instance(this.obj,this.attr,this.opts).validate()},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(19),s=function(t){return t&&t.__esModule?t:{default:t}}(n),o={Obj:s.default};e.default=o},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n=function(){function t(){}return t.toURIParams=function(t){var e,r,n;r="";for(e in t)n=t[e],""!==r&&(r+="&"),r+=e+"="+encodeURIComponent(n);return r},t}(),e.default=n}])}); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e():"function"==typeof define&&define.amd?define([],e):"object"==typeof exports?exports.LocoModel=e():t.LocoModel=e()}("undefined"!=typeof self?self:this,function(){return function(t){function e(n){if(r[n])return r[n].exports;var s=r[n]={i:n,l:!1,exports:{}};return t[n].call(s.exports,s,s.exports,e),s.l=!0,s.exports}var r={};return e.m=t,e.c=r,e.d=function(t,r,n){e.o(t,r)||Object.defineProperty(t,r,{configurable:!1,enumerable:!0,get:n})},e.n=function(t){var r=t&&t.__esModule?function(){return t.default}:function(){return t};return e.d(r,"a",r),r},e.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},e.p="",e(e.s=7)}([function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(3),o=r.n(s);n=function(){function t(){this.obj=null,this.attr=null,this.val=null,this.opts=null}return t.sharedInstances={},t.instance=function(t,e,r){var n,s;return s=this.identity,null==this.sharedInstances[s]&&(this.sharedInstances[s]=new o.a[s]),n=this.sharedInstances[s],n.assignAttribs(t,e,r),n},t.prototype.assignAttribs=function(t,e,r){return this.obj=t,this.attr=e,this.val=this.obj[this.attr],this.opts=r},t}(),e.default=n},function(t,e,r){"use strict";function n(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}return function(e,r,n){return r&&t(e.prototype,r),n&&t(e,n),e}}(),o=function(){function t(){n(this,t),this.localeVar="en",this.protocolWithHostVar=null,this.scopeVar=null}return s(t,[{key:"locale",get:function(){return this.localeVar},set:function(t){return this.localeVar=t,this.localeVar}},{key:"protocolWithHost",get:function(){return this.protocolWithHostVar},set:function(t){return t?"/"===t[t.length-1]?(this.protocolWithHostVar=t.slice(0,t.length-1),this.protocolWithHostVar):(this.protocolWithHostVar=t,this.protocolWithHostVar):(this.protocolWithHostVar=null,this.protocolWithHostVar)}},{key:"scope",get:function(){return this.scopeVar},set:function(t){return this.scopeVar=t,this.scopeVar}}]),t}(),i=new o;e.default=i},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(10),s=function(t){return t&&t.__esModule?t:{default:t}}(n),o={en:s.default};e.default=o},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0});var s=r(9),o=n(s),i=r(11),a=n(i),u=r(12),l=n(u),c=r(13),h=n(c),p=r(14),f=n(p),d=r(4),_=n(d),g=r(15),m=n(g),v=r(16),y=n(v),b=r(17),M=n(b),E={Absence:o.default,Confirmation:a.default,Exclusion:l.default,Format:h.default,Inclusion:f.default,Length:_.default,Numericality:m.default,Presence:y.default,Size:M.default};e.default=E},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Length",e.prototype.validate=function(){var t;if(null!=this.val&&null!==(t=null!=this._range()[0]&&null!=this._range()[1]&&this._range()[0]===this._range()[1]&&this.val.length!==this._range()[0]?this._selectErrorMessage("wrong_length",this._range()[0]):null!=this._range()[0]&&this.val.length<this._range()[0]?this._selectErrorMessage("too_short",this._range()[0]):null!=this._range()[1]&&this.val.length>this._range()[1]?this._selectErrorMessage("too_long",this._range()[1]):null))return this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._range=function(){var t,e;return t=this.opts.minimum||this.opts.is||null!=this.opts.within&&this.opts.within[0]||null,e=this.opts.maximum||this.opts.is||null!=this.opts.within&&this.opts.within[1]||null,[t,e]},e.prototype._selectErrorMessage=function(t,e){var r,n,s,o,a;if(1===e)return i.a[u.a.locale].errors.messages[t].one;for(s=null,o=["few","many"],r=0,n=o.length;r<n;r++)if(a=o[r],this._checkVariant(a,e)){s=i.a[u.a.locale].errors.messages[t][a];break}return null==s&&(s=i.a[u.a.locale].errors.messages[t].other),null!=this.opts.message&&(s=this.opts.message),/%{count}/.exec(s)&&(s=s.replace("%{count}",e)),s},e.prototype._checkVariant=function(t,e){if(null!=i.a[u.a.locale].variants[t])return i.a[u.a.locale].variants[t](e)},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n=function(){function t(){}return t.imap={},t.clear=function(){return this.imap={}},t.add=function(t){var e;return e=t.getIdentity(),null==this.imap[e]&&(this.imap[e]={}),null==this.imap[e][t.id]&&(this.imap[e][t.id]=[]),this.imap[e][t.id][0]=t},t.connect=function(t,e){var r;return null==e&&(e={}),r=e.with,this.add(r),this.imap[r.getIdentity()][r.id].push(t)},t.addCollection=function(t,e){if(null==e&&(e={}),null==this.imap[t]&&(this.imap[t]={}),null==this.imap[t].collection&&(this.imap[t].collection=[]),-1===this.imap[t].collection.indexOf(e.to))return this.imap[t].collection.push(e.to)},t.all=function(t){var e,r,n,s;if(null==this.imap[t])return null;e=[],s=this.imap[t];for(r in s)n=s[r],"collection"!==r&&e.push(n[0]);return e},t.find=function(t,e){return this.imap[t]&&this.imap[t][e]?this.imap[t][e][0]:null},t.findConnected=function(t,e){var r;return this.imap[t]&&this.imap[t][e]&&this.imap[t][e].length>1?(r=this.imap[t][e],r.slice(1,+(r.length-1)+1||9e9)):[]},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n={};e.default=n},function(t,e,r){"use strict";function n(t){return t&&t.__esModule?t:{default:t}}Object.defineProperty(e,"__esModule",{value:!0}),e.Validators=e.Models=e.IdentityMap=e.I18n=e.Config=e.Base=void 0;var s=r(8),o=n(s),i=r(5),a=n(i),u=r(0),l=n(u),c=r(3),h=n(c),p=r(1),f=n(p),d=r(2),_=n(d),g=r(6),m=n(g);h.default.Base=l.default,m.default.Base=o.default,e.Base=o.default,e.Config=f.default,e.I18n=_.default,e.IdentityMap=a.default,e.Models=m.default,e.Validators=h.default},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(3),o=r.n(s),i=r(1),a=r.n(i),u=r(18),l=r.n(u),c=r(5),h=r(6),p=r.n(h),f=r(20);r.n(f);n=function(){function t(t){null==t&&(t={}),this.id=null,this.errors=null,this.resource=t.resource,null!=this.constructor.attributes&&this.__initAttributes(),null!=t&&this.__assignAttributes(t)}return t.getIdentity=function(){if(null!=this.identity)return this.identity;throw"Specify Model's @identity!"},t.getRemoteName=function(){return null!=this.remoteName?this.remoteName:this.getIdentity()},t.all=function(t){return null==t&&(t={}),this.get("all",t)},t.get=function(t,e){return null==e&&(e={}),this.__send("GET",t,e)},t.post=function(t,e){return null==e&&(e={}),this.__send("POST",t,e)},t.put=function(t,e){return null==e&&(e={}),this.__send("PUT",t,e)},t.patch=function(t,e){return null==e&&(e={}),this.__send("PATCH",t,e)},t.delete=function(t,e){return null==e&&(e={}),this.__send("DELETE",t,e)},t.find=function(t){var e,r,n;return n={},"object"==typeof t?(n=t,e=t.id,delete n.id):e=t,r=Object(f.sendReq)("GET",this.__getResourcesUrl(n)+"/"+e,n),new Promise(function(e){return function(n,s){return r.onerror=function(t){return s(t)},r.onload=function(r){var s;return s=JSON.parse(r.target.response),n(e.__initFromJSON(s,t.resource))}}}(this))},t.getAttribRemoteName=function(t){return null==this.attributes?null:null==this.attributes[t]?null:null==this.attributes[t].remoteName?t:this.attributes[t].remoteName},t.getResourcesUrlParams=function(t){var e,r,n,s;for(s=this.__getResourcesUrl({resource:t.resource}),n=/:(\w+)\/?/,r=[];e=n.exec(s);)r.push(e[1]),s=s.replace(e[0],e[1]);return r},t.__getResourcesUrl=function(t){var e,r;return r=null==this.resources?"/"+this.getRemoteName().toLowerCase()+"s":t.resource?this.resources[t.resource].url:null!=a.a.scope&&null!=this.resources[a.a.scope]?this.resources[a.a.scope].url:this.resources.url,null!=a.a.protocolWithHost&&(r=""+a.a.protocolWithHost+r),null==(e=/:(\w+)\/?/.exec(r))?r:(null!=t[e[1]]?(r=r.replace(":"+e[1],t[e[1]]),delete t[e[1]]):null!=t.obj&&null!=t.obj[e[1]]&&(r=r.replace(":"+e[1],t.obj[e[1]])),r)},t.__initSubclass=function(t){var e,r;return null==t&&(t={}),r=this.getIdentity().split("."),1===r.length?(e=p.a[r[0]],null==e?new this(t):new e(t)):new(e=p.a[r[0]][r[1]])(t)},t.__page=function(t,e,r){var n,s;return null==r&&(r={resources:[],count:0}),s=e.url,e.params[e.pageParam]=t,"GET"===e.method&&(s=s+"?"+l.a.Obj.toURIParams(e.params)),n=Object(f.sendReq)(e.method,s,e.params),new Promise(function(t){return function(s,o){return n.onerror=function(t){return o(t)},n.onload=function(n){var o,i,a,u,l,c,h,p;o=JSON.parse(n.target.response),r.count=o.count;for(a in o)p=o[a],-1===["resources","count"].indexOf(a)&&(r[a]=p);for(h=o.resources,i=0,u=h.length;i<u;i++)c=h[i],l=t.__initFromJSON(c,e.resource),r.resources.push(l);return s(r)}}}(this))},t.__paginate=function(t){var e;return e={method:t.method,url:t.url,params:t.params,pageParam:t.pageParam,resource:t.resource},this.__page(t.pageNum||1,e).then(function(r){return function(n){var s,o,i,a,u;if(a=Promise.resolve(n),null!=t.pageNum)return a;if(n.count<=t.perPage)return a;if(i=parseInt(n.count/t.perPage),i!==n.count/t.perPage&&(i+=1),1===i)return a;for(s=o=2,u=i;2<=u?o<=u:o>=u;s=2<=u?++o:--o)(function(t){return a=a.then(function(s){return r.__page(t,e,n)})})(s);return a}}(this))},t.__getPaginationParam=function(t){var e,r,n,s,o,i;return e="page",null!=t&&null!=this.resources&&this.resources[t]?(null!=(r=this.resources[t].paginate)?r.param:void 0)||e:null!=a.a.scope&&null!=this.resources&&null!=this.resources[a.a.scope]?(null!=(n=this.resources[a.a.scope])&&null!=(s=n.paginate)?s.param:void 0)||e:null!=(null!=(o=this.resources)&&null!=(i=o.paginate)?i.param:void 0)?this.resources.paginate.param:e},t.__getPaginationPer=function(t){var e,r,n,s,o;return null!=t&&null!=this.resources&&this.resources[t]?null!=(e=this.resources[t].paginate)?e.per:void 0:null!=a.a.scope&&null!=this.resources&&null!=this.resources[a.a.scope]?null!=(r=this.resources[a.a.scope])&&null!=(n=r.paginate)?n.per:void 0:null!=(null!=(s=this.resources)&&null!=(o=s.paginate)?o.per:void 0)?this.resources.paginate.per:null},t.__send=function(t,e,r){var n,s;return s=this.__getResourcesUrl(r),"all"!==e&&(s=s+"/"+e),n={method:t,url:s,params:Object(f.filterParams)(r),resource:r.resource,perPage:this.__getPaginationPer(r.resource),pageNum:r.page,pageParam:this.__getPaginationParam(r.resource)},this.__paginate(n)},t.__initFromJSON=function(t,e){var r;return r=this.__initSubclass(t),r.resource=e,c.default.add(r),r},t.prototype.setResource=function(t){return this.resource=t},t.prototype.getIdentity=function(){return this.constructor.getIdentity()},t.prototype.getAttrRemoteName=function(t){return null==this.constructor.attributes?null:null==this.constructor.attributes[t]?null:this.constructor.attributes[t].remoteName||t},t.prototype.getAttrName=function(t){var e,r,n;if(null==this.constructor.attributes)return t;if(null!=this.constructor.attributes[t])return t;n=this.constructor.attributes;for(r in n)if(e=n[r],e.remoteName===t)return r;return t},t.prototype.getAttrType=function(t){return null==this.constructor.attributes?null:null==this.constructor.attributes[t]?null:this.constructor.attributes[t].type},t.prototype.assignAttr=function(t,e){var r;if(r=this.getAttrType(t),null==e)return void(this[t]=null);switch(r){case"Date":e=new Date(Date.parse(e));break;case"Integer":case"Int":e=parseInt(e);break;case"Float":e=parseFloat(e);break;case"Boolean":case"Bool":e="boolean"==typeof e?e:Boolean(parseInt(e));break;case"Number":e=Number(e);break;case"String":e=String(e)}return this[t]=e},t.prototype.attributes=function(){var t,e,r;if(t={id:this.id},null==this.constructor.attributes)return t;r=this.constructor.attributes;for(e in r)r[e],t[e]=this[e];return t},t.prototype.isValid=function(){var t,e,r,n,s,i,a,u,l,c,h,p;if(null==this.constructor.attributes)return!0;this.errors=null,a=this.constructor.attributes;for(s in a)if(t=a[s],null!=t.validations){u=t.validations;for(c in u)h=u[c],null!=this.id&&"create"===h.on||null==this.id&&"update"===h.on||(null==h.if||h.if(this))&&(p=c.charAt(0).toUpperCase()+c.slice(1),null!=o.a[p]?(i=this.__processedValidationSettings(h),o.a[p].instance(this,s,i).validate()):console.log('Warning! "'+p+'" validator is not implemented!'))}if(null!=this.constructor.validate)for(l=this.constructor.validate,e=0,r=l.length;e<r;e++)n=l[e],this[n]();return null==this.errors},t.prototype.isInvalid=function(){return!this.isValid()},t.prototype.isEmpty=function(){var t,e;e=this.attributes();for(t in e)if(e[t],null!==this[t])return!1;return!0},t.prototype.addErrorMessage=function(t,e){return null==e&&(e={}),null==this.errors&&(this.errors={}),null==this.errors[e.for]&&(this.errors[e.for]=[]),this.errors[e.for].push(t)},t.prototype.save=function(){var t,e;return t=null!=this.id?"PUT":"POST",e=Object(f.sendReq)(t,this.__getResourceUrl(),this.serialize()),new Promise(function(t){return function(r,n){return e.onerror=function(t){return n(t)},e.onload=function(e){var n;return n=JSON.parse(e.target.response),n.success?void r(n):(null!=n.errors&&t.__assignRemoteErrorMessages(n.errors),r(n))}}}(this))},t.prototype.updateAttribute=function(t){var e;return e=Object(f.sendReq)("PUT",this.__getResourceUrl(),this.serialize(t)),new Promise(function(t){return function(r,n){return e.onerror=function(t){return n(t)},e.onload=function(e){var s;return e.target.status>=200&&e.target.status<400?(s=JSON.parse(e.target.response),s.success?void r(s):(null!=s.errors&&t.__assignRemoteErrorMessages(s.errors),r(s))):e.target.status>=500?n(e):void 0}}}(this))},t.prototype.serialize=function(t){var e,r,n,s;if(null==t&&(t=null),null==this.constructor.attributes)return{};r={},n=this.constructor.getRemoteName().toLowerCase(),r[n]={},e={},null!=t?e[t]=null:e=this.constructor.attributes;for(t in e)e[t],s=this.getAttrRemoteName(t),r[n][s]=this[t];return r},t.prototype.reload=function(){var t,e,r,n,s;for(t={id:this.id,resource:this.resource},s=this.constructor.getResourcesUrlParams({resource:this.resource}),e=0,r=s.length;e<r;e++)n=s[e],t[n]=this[n];return this.constructor.find(t)},t.prototype.changes=function(){var t,e,r,n,s;n={},t=c.default.find(this.getIdentity(),this.id),r=this.attributes();for(e in r)if((s=r[e])!==t[e]){if(null!=s&&s.constructor===Date&&t[e]-s==0)continue;s!==t[e]&&(n[e]={is:t[e],was:s})}return n},t.prototype.applyChanges=function(){var t,e,r,n;e=this.changes(),r=[];for(t in e)n=e[t],r.push(this[t]=n.is);return r},t.prototype.toKey=function(){return this.getIdentity().toLowerCase()+"_"+this.id},t.prototype.get=function(t,e){return null==e&&(e={}),this.__send("GET",t,e)},t.prototype.post=function(t,e){return null==e&&(e={}),this.__send("POST",t,e)},t.prototype.put=function(t,e){return null==e&&(e={}),this.__send("PUT",t,e)},t.prototype.patch=function(t,e){return null==e&&(e={}),this.__send("PATCH",t,e)},t.prototype.delete=function(t,e){return null==e&&(e={}),this.__send("DELETE",t,e)},t.prototype.__send=function(t,e,r){var n,s;return s=this.__getResourceUrl(),null!=e&&(s=s+"/"+e),n=Object(f.sendReq)(t,s,r),new Promise(function(t,e){return n.onerror=function(t){return e(t)},n.onload=function(n){return n.target.status>=200&&n.target.status<400?(r=JSON.parse(n.target.response),t(r)):n.target.status>=500?e(n):void 0}})},t.prototype.__assignAttributes=function(t){var e,r,n,s;n=[];for(r in t)s=t[r],e=this.getAttrName(r),n.push(this.assignAttr(e,s));return n},t.prototype.__initAttributes=function(){var t,e,r;e=this.constructor.attributes,r=[];for(t in e)e[t],r.push(this[t]=null);return r},t.prototype.__assignRemoteErrorMessages=function(t){var e,r,n,s,o;o=[];for(s in t)n=t[s],e=this.getAttrName(s),o.push(function(){var t,s,o;for(o=[],t=0,s=n.length;t<s;t++)r=n[t],o.push(this.addErrorMessage(r,{for:e}));return o}.call(this));return o},t.prototype.__getResourceUrl=function(){var t;return t=this.constructor.__getResourcesUrl({resource:this.resource,obj:this}),null==this.id?t:t+"/"+this.id},t.prototype.__processedValidationSettings=function(t){var e,r,n;n={};for(e in t)r=t[e],n[e]="function"==typeof r?r(this):r;return n},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Absence",e.prototype.validate=function(){switch(typeof this.val){case"string":if(null!=this.val&&0===this.val.length)return;break;default:if(null==this.val)return}return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.present,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n={variants:{},models:{},attributes:{},errors:{messages:{accepted:"must be accepted",blank:"can't be blank",confirmation:"doesn't match %{attribute}",empty:"can't be empty",equal_to:"must be equal to %{count}",even:"must be even",exclusion:"is reserved",greater_than:"must be greater than %{count}",greater_than_or_equal_to:"must be greater than or equal to %{count}",inclusion:"is not included in the list",invalid:"is invalid",less_than:"must be less than %{count}",less_than_or_equal_to:"must be less than or equal to %{count}",not_a_number:"is not a number",not_an_integer:"must be an integer",odd:"must be odd",present:"must be blank",too_long:{one:"is too long (maximum is 1 character)",other:"is too long (maximum is %{count} characters)"},too_short:{one:"is too short (minimum is 1 character)",other:"is too short (minimum is %{count} characters)"},wrong_length:{one:"is the wrong length (should be 1 character)",other:"is the wrong length (should be %{count} characters)"},other_than:"must be other than %{count}"}}},e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Confirmation",e.prototype.validate=function(){var t;if(t=this.obj[this._properAttr()],null==this.val||null==t||this.val!==t)return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t,e,r,n;return r=this.attr.charAt(0).toUpperCase()+this.attr.slice(1),e=i.a[u.a.locale].attributes[this.obj.getIdentity()],t=e&&e[this.attr]||r,n=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.confirmation,n=n.replace("%{attribute}",t),this.obj.addErrorMessage(n,{for:this._properAttr()})},e.prototype._properAttr=function(){return this.attr+"Confirmation"},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Exclusion",e.prototype.validate=function(){var t;if(t=this.opts.in||this.opts.within||[],-1!==t.indexOf(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.exclusion,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Format",e.prototype.validate=function(){if(null==this.opts.with.exec(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.invalid,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Inclusion",e.prototype.validate=function(){var t;if(t=this.opts.in||this.opts.within||[],-1===t.indexOf(this.val))return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.inclusion,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Numericality",e.prototype.validate=function(){return isNaN(this.val)?this._addNaNErrorMessage():null!=this.opts.only_integer&&Number(this.val)!==parseInt(this.val)?this._addIntErrorMessage():null!=this.opts.greater_than&&Number(this.val)<=this.opts.greater_than?this._addGreatherThanErrorMessage():null!=this.opts.greater_than_or_equal_to&&Number(this.val)<this.opts.greater_than_or_equal_to?this._addGreatherThanOrEqualToErrorMessage():null!=this.opts.equal_to&&Number(this.val)!==this.opts.equal_to?this._addEqualToErrorMessage():null!=this.opts.less_than&&Number(this.val)>=this.opts.less_than?this._addLessThanErrorMessage():null!=this.opts.less_than_or_equal_to&&Number(this.val)>this.opts.less_than_or_equal_to?this._addLessThanOrEqualToErrorMessage():null!=this.opts.other_than&&Number(this.val)===this.opts.other_than?this._addOtherThanErrorMessage():null!=this.opts.odd&&Number(this.val)%2!=1?this._addOddErrorMessage():null!=this.opts.even&&Number(this.val)%2!=0?this._addEvenErrorMessage():void 0},e.prototype._addNaNErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.not_a_number,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addIntErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.not_an_integer,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addGreatherThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.greater_than,t=t.replace("%{count}",this.opts.greater_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addGreatherThanOrEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.greater_than_or_equal_to,t=t.replace("%{count}",this.opts.greater_than_or_equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.equal_to,t=t.replace("%{count}",this.opts.equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addLessThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.less_than,t=t.replace("%{count}",this.opts.less_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addLessThanOrEqualToErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.less_than_or_equal_to,t=t.replace("%{count}",this.opts.less_than_or_equal_to),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addOtherThanErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.other_than,t=t.replace("%{count}",this.opts.other_than),this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addOddErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.odd,this.obj.addErrorMessage(t,{for:this.attr})},e.prototype._addEvenErrorMessage=function(){var t;return t=i.a[u.a.locale].errors.messages.even,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(2),i=r.n(o),a=r(1),u=r.n(a),l=function(t,e){function r(){this.constructor=t}for(var n in e)c.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},c={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return l(e,t),e.identity="Presence",e.prototype.validate=function(){switch(typeof this.val){case"string":if(null!=this.val&&this.val.length>0)return;break;default:if(null!=this.val)return}return this._addErrorMessage()},e.prototype._addErrorMessage=function(){var t;return t=null!=this.opts.message?this.opts.message:i.a[u.a.locale].errors.messages.blank,this.obj.addErrorMessage(t,{for:this.attr})},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n,s=r(0),o=r(4),i=function(t,e){function r(){this.constructor=t}for(var n in e)a.call(e,n)&&(t[n]=e[n]);return r.prototype=e.prototype,t.prototype=new r,t.__super__=e.prototype,t},a={}.hasOwnProperty;n=function(t){function e(){e.__super__.constructor.call(this)}return i(e,t),e.identity="Size",e.prototype.validate=function(){return o.default.instance(this.obj,this.attr,this.opts).validate()},e}(s.default),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n=r(19),s=function(t){return t&&t.__esModule?t:{default:t}}(n),o={Obj:s.default};e.default=o},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});var n;n=function(){function t(){}return t.toURIParams=function(t){var e,r,n;r="";for(e in t)n=t[e],""!==r&&(r+="&"),r+=e+"="+encodeURIComponent(n);return r},t}(),e.default=n},function(t,e,r){"use strict";Object.defineProperty(e,"__esModule",{value:!0});e.filterParams=function(t){var e={};return t?(Object.keys(t).forEach(function(r){"resource"!==r&&(e[r]=t[r])}),e):e},e.sendReq=function(t,e,r){var n=document.querySelector("meta[name='csrf-token']"),s=new XMLHttpRequest;return s.open(t,e),s.setRequestHeader("Accept","application/json"),s.setRequestHeader("Content-Type","application/json"),n&&s.setRequestHeader("X-CSRF-Token",n.content),s.send(JSON.stringify(r)),s}}])}); |
{ | ||
"name": "loco-js-model", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Model part of loco-js", | ||
@@ -8,3 +8,4 @@ "main": "dist/loco-model.js", | ||
"start": "node dev/server.js", | ||
"build": "webpack -p --config webpack.config.js" | ||
"build": "webpack -p --config webpack.config.js", | ||
"lint-staged": "lint-staged" | ||
}, | ||
@@ -26,2 +27,4 @@ "repository": { | ||
"babel-core": "^6.26.0", | ||
"babel-eslint": "^8.2.1", | ||
"babel-jest": "^22.1.0", | ||
"babel-loader": "^7.1.2", | ||
@@ -32,6 +35,19 @@ "babel-plugin-transform-object-rest-spread": "^6.26.0", | ||
"coffeescript": "^1.12.7", | ||
"eslint": "^4.16.0", | ||
"eslint-config-airbnb-base": "^12.1.0", | ||
"eslint-config-prettier": "^2.9.0", | ||
"eslint-plugin-import": "^2.8.0", | ||
"eslint-plugin-jest": "^21.7.0", | ||
"eslint-plugin-prettier": "^2.5.0", | ||
"express": "^4.16.2", | ||
"jest": "^22.1.4", | ||
"lint-staged": "^6.1.0", | ||
"pre-commit": "^1.2.2", | ||
"prettier": "^1.10.2", | ||
"webpack": "^3.10.0", | ||
"webpack-dev-middleware": "^2.0.3" | ||
} | ||
}, | ||
"pre-commit": [ | ||
"lint-staged" | ||
] | ||
} |
@@ -1,37 +0,46 @@ | ||
let locale = 'en'; | ||
let protocolWithHost = null; | ||
let scope = null; | ||
class Configurator { | ||
constructor() { | ||
this.localeVar = "en"; | ||
this.protocolWithHostVar = null; | ||
this.scopeVar = null; | ||
} | ||
class Configurator { | ||
get locale() { | ||
return locale; | ||
return this.localeVar; | ||
} | ||
set locale(val) { | ||
return locale = val; | ||
this.localeVar = val; | ||
return this.localeVar; | ||
} | ||
get protocolWithHost() { | ||
return protocolWithHost; | ||
return this.protocolWithHostVar; | ||
} | ||
set protocolWithHost(val) { | ||
if(!val) | ||
return protocolWithHost = null; | ||
if(val[val.length - 1] === '/') | ||
return protocolWithHost = val.slice(0, val.length - 1); | ||
return protocolWithHost = val; | ||
if (!val) { | ||
this.protocolWithHostVar = null; | ||
return this.protocolWithHostVar; | ||
} | ||
if (val[val.length - 1] === "/") { | ||
this.protocolWithHostVar = val.slice(0, val.length - 1); | ||
return this.protocolWithHostVar; | ||
} | ||
this.protocolWithHostVar = val; | ||
return this.protocolWithHostVar; | ||
} | ||
get scope() { | ||
return scope; | ||
return this.scopeVar; | ||
} | ||
set scope(val) { | ||
return scope = val; | ||
this.scopeVar = val; | ||
return this.scopeVar; | ||
} | ||
} | ||
const Config = new Configurator; | ||
const Config = new Configurator(); | ||
export default Config; | ||
export default Config; |
@@ -1,2 +0,2 @@ | ||
import en from './locales/en.coffee'; | ||
import en from "./locales/en.coffee"; | ||
@@ -7,2 +7,2 @@ const I18n = { | ||
export default I18n; | ||
export default I18n; |
@@ -1,8 +0,8 @@ | ||
import Base from './base.coffee'; | ||
import IdentityMap from './identity_map.coffee'; | ||
import BaseValidator from './validators/base.coffee'; | ||
import Validators from './validators.js'; | ||
import Config from './config'; | ||
import I18n from './i18n'; | ||
import Models from './models'; | ||
import Base from "./base.coffee"; | ||
import IdentityMap from "./identity_map.coffee"; | ||
import BaseValidator from "./validators/base.coffee"; | ||
import Validators from "./validators"; | ||
import Config from "./config"; | ||
import I18n from "./i18n"; | ||
import Models from "./models"; | ||
@@ -13,9 +13,2 @@ Validators.Base = BaseValidator; | ||
export { | ||
Base, | ||
Config, | ||
I18n, | ||
IdentityMap, | ||
Models, | ||
Validators | ||
}; | ||
export { Base, Config, I18n, IdentityMap, Models, Validators }; |
const Models = {}; | ||
export default Models; | ||
export default Models; |
@@ -1,2 +0,2 @@ | ||
import Obj from './utils/obj.coffee'; | ||
import Obj from "./utils/obj.coffee"; | ||
@@ -7,2 +7,2 @@ const Utils = { | ||
export default Utils; | ||
export default Utils; |
@@ -1,10 +0,10 @@ | ||
import Absence from './validators/absence.coffee'; | ||
import Confirmation from './validators/confirmation.coffee'; | ||
import Exclusion from './validators/exclusion.coffee'; | ||
import Format from './validators/format.coffee'; | ||
import Inclusion from './validators/inclusion.coffee'; | ||
import Length from './validators/length.coffee'; | ||
import Numericality from './validators/numericality.coffee'; | ||
import Presence from './validators/presence.coffee'; | ||
import Size from './validators/size.coffee'; | ||
import Absence from "./validators/absence.coffee"; | ||
import Confirmation from "./validators/confirmation.coffee"; | ||
import Exclusion from "./validators/exclusion.coffee"; | ||
import Format from "./validators/format.coffee"; | ||
import Inclusion from "./validators/inclusion.coffee"; | ||
import Length from "./validators/length.coffee"; | ||
import Numericality from "./validators/numericality.coffee"; | ||
import Presence from "./validators/presence.coffee"; | ||
import Size from "./validators/size.coffee"; | ||
@@ -23,2 +23,2 @@ const Validators = { | ||
export default Validators; | ||
export default Validators; |
@@ -1,5 +0,5 @@ | ||
var path = require('path'); | ||
var path = require("path"); | ||
module.exports = { | ||
entry: './src/index.js', | ||
entry: "./src/index.js", | ||
module: { | ||
@@ -11,6 +11,7 @@ rules: [ | ||
use: [ | ||
{ loader: 'coffee-loader', | ||
{ | ||
loader: "coffee-loader", | ||
options: { | ||
transpile: { | ||
presets: ['env'] | ||
presets: ["env"] | ||
} | ||
@@ -24,7 +25,7 @@ } | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
filename: 'loco-model.js', | ||
library: 'LocoModel', | ||
libraryTarget: 'umd' | ||
path: path.resolve(__dirname, "dist"), | ||
filename: "loco-model.js", | ||
library: "LocoModel", | ||
libraryTarget: "umd" | ||
} | ||
}; | ||
}; |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
71810
34
151
1
380
21