loco-js-model
Advanced tools
Comparing version 0.2.1 to 0.3.0
@@ -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=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}}])}); | ||
!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 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,f,d;if(o=JSON.parse(n.target.response),o.constructor===Array)for(i=0,l=o.length;i<l;i++)p=o[i],h=t.__initFromJSON(p,e.resource),r.push(h);else if(null!=o.resources){for(r.constructor===Array&&(r={resources:[],count:0}),f=o.resources,a=0,c=f.length;a<c;a++)p=f[a],h=t.__initFromJSON(p,e.resource),r.resources.push(h);r.count=o.count}else for(u in o)d=o[u],r[u]=d;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,l;if(l=n.count||t.total,a=Promise.resolve(n),null!=t.pageNum)return a;if(l<=t.perPage)return a;if(i=parseInt(l/t.perPage),i!==l/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),total:r.total||r.count},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.warn('"'+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={};if(!t)return e;var r=["resource","total","count"];return Object.keys(t).forEach(function(n){-1===r.indexOf(n)&&(e[n]=t[n])}),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.1", | ||
"version": "0.3.0", | ||
"description": "Model part of loco-js", | ||
@@ -5,0 +5,0 @@ "main": "dist/loco-model.js", |
export const filterParams = data => { | ||
const params = {}; | ||
if (!data) return params; | ||
const forbidden = ["resource", "total", "count"]; | ||
Object.keys(data).forEach(prop => { | ||
if (prop !== "resource") { | ||
if (forbidden.indexOf(prop) === -1) { | ||
params[prop] = data[prop]; | ||
@@ -7,0 +8,0 @@ } |
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
72331
152