ngx-airbrush
Version:
Angular client for jsonapi/Graphiti backends
2 lines • 23.1 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@angular/core"),require("jsona"),require("uuid"),require("rxjs/operators"),require("rxjs"),require("@angular/common/http")):"function"==typeof define&&define.amd?define("ngx-airbrush",["exports","@angular/core","jsona","uuid","rxjs/operators","rxjs","@angular/common/http"],t):t((e=e||self)["ngx-airbrush"]={},e.ng.core,e.Jsona,e.uuid,e.rxjs.operators,e.rxjs,e.ng.common.http)}(this,function(e,t,r,n,i,o,a){"use strict";r=r&&r.hasOwnProperty("default")?r["default"]:r;var s=function(){return(s=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var i in t=arguments[r])Object.prototype.hasOwnProperty.call(t,i)&&(e[i]=t[i]);return e}).apply(this,arguments)};function u(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,i,o=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=o.next()).done;)a.push(n.value)}catch(s){i={error:s}}finally{try{n&&!n.done&&(r=o["return"])&&r.call(o)}finally{if(i)throw i.error}}return a}function d(){for(var e=[],t=0;t<arguments.length;t++)e=e.concat(u(arguments[t]));return e}var p=function(){function e(){}return e.decorators=[{type:t.NgModule}],e}(),c=Symbol("ServiceMetadata"),f=Symbol("ModelMetadata"),l=Symbol("AttributeMetadata"),h=Symbol("BelongsToMetadata"),y=Symbol("HasManyMetadata");var m=function(){function e(){this._types={}}return e.getInstance=function(){return e.instance||(e.instance=new e),e.instance},e.add=function(t,r){e.getInstance().add(t,r)},e.find=function(t){return e.getInstance().find(t)},e.all=function(){return e.getInstance().all},e.prototype.add=function(e,t){this._types[e]=t},e.prototype.find=function(e){return this.all[e]},Object.defineProperty(e.prototype,"all",{get:function(){return this._types},enumerable:!0,configurable:!0}),e.instance=null,e}();var v=function(){function e(){}return e.prototype.deserialize=function(e){return e?new Date(e):null},e.prototype.serialize=function(e){return e?e.toJSON():null},e}();var b,g=function(){function e(){this.jsona=new r}return e.prototype.deserialize=function(e){return this.jsona.deserialize(e)},e.prototype.serialize=function(e,t){if(e){this.defineTempIds(e);var r=this.jsona.serialize({stuff:e,includeNames:t});if(r)return r.data.id||delete r.data.id,this.addMethodsInRelations(e,r),this.deleteMethodsInIncludes(r),this.renameTempIdKeys(r),r}},e.prototype.defineTempIds=function(e){var t=this;this.getRelationsKeys(e).forEach(function(r){var i=e[r];t.execOnElementOrArray(i,function(e){"create"===e.__method&&(e.id=e.id||n.v4()),t.defineTempIds(e)})})},e.prototype.addMethodsInRelations=function(e,t){var r=this;this.updateMethods(e,t.data),this.getRelationsKeys(e).filter(function(t){return e[t]}).forEach(function(n){r.execOnElementOrArray(e[n],function(e){return r.updateMethodsInculdes(e,t.included)})})},e.prototype.updateMethodsInculdes=function(e,t){var r=this,n=t&&t.find(function(t){return t.id===e.id&&t.type===e.type});n&&(this.updateMethods(e,n),this.getRelationsKeys(e).filter(function(t){return e[t]}).forEach(function(n){r.updateMethodsInculdes(e[n],t)}))},e.prototype.updateMethods=function(e,t){var r=this,n=t.relationships;n&&this.getRelationsKeys(e).filter(function(e){return n[e]}).forEach(function(t){r.execOnElementOrArray(n[t].data,function(r){return r.method=e[t].__method},function(r){var n=e[t].find(function(e){return e.id===r.id}).__method;r.method=n})})},e.prototype.deleteMethodsInIncludes=function(e){(e.included||[]).forEach(function(e){delete e.attributes.__method})},e.prototype.renameTempIdKeys=function(e){var t=this,r=e.included;r&&(this.setTempId(e.data,r),r.forEach(function(e){t.setTempId(e,r)}))},e.prototype.setTempId=function(e,t){var r=this,n=e.relationships;n&&Object.keys(n).filter(function(e){return n.hasOwnProperty(e)&&n[e]}).forEach(function(e){r.execOnElementOrArray(n[e].data,function(e){if("create"===e.method){var r=t.find(function(t){return t.id===e.id&&t.type===e.type});r["temp-id"]=r.id,e["temp-id"]=e.id,delete r.id,delete e.id}})})},e.prototype.getRelationsKeys=function(e){return e.relationshipNames||[]},e.prototype.execOnElementOrArray=function(e,t,r){r=r||t,Array.isArray(e)?e.forEach(function(e){return r(e)}):t(e)},e}(),_=function(){function e(e){this.model=e}return e.prototype.allKeys=function(e){return d(this.attributesKeys(e),this.relationshipKeys(e))},e.prototype.relationshipKeys=function(e){return d(this.belongsToKeys(e),this.hasManyKeys(e))},e.prototype.attributesKeys=function(e){var t=this,r=this.retrieveKeys(l);return e&&e.defined&&(r=r.filter(function(e){return t.model[e]!==undefined}),this.model.id||(r=r.filter(function(e){return null!==t.model[e]}))),r},e.prototype.belongsToKeys=function(e){return this.retrieveKeys(h,e)},e.prototype.hasManyKeys=function(e){return this.retrieveKeys(y,e)},e.prototype.allMetadata=function(){return d(this.attributesMetadata(),this.relationshipMetadata())},e.prototype.relationshipMetadata=function(){return d(this.belongsToMetadata(),this.hasManyMetadata())},e.prototype.attributesMetadata=function(){return this.retrieveMetadata(l)},e.prototype.belongsToMetadata=function(){return this.retrieveMetadata(h)},e.prototype.hasManyMetadata=function(){return this.retrieveMetadata(y)},e.prototype.isSidepostable=function(e){var t=Reflect.getMetadata(h,this.model),r=t&&t.find(function(t){return t.propertyName===e});return r?r.sidepostable:(r=(t=Reflect.getMetadata(y,this.model))&&t.find(function(t){return t.propertyName===e}))?r.sidepostable:void 0},e.prototype.isWritable=function(e){var t=this.allMetadata().find(function(t){return t.propertyName===e});if(t)return!t.readonly},e.prototype.backendPropName=function(e){var t=this.allMetadata().find(function(t){return t.propertyName===e});if(t)return t.backendName},e.prototype.frontendPropName=function(e){var t=this.allMetadata(),r=t.find(function(t){return t.backendName===e});return r?r.propertyName:(r=t.find(function(t){return t.propertyName===e}))?e:void 0},e.prototype.retrieveKeys=function(e,t){var r=this;this.model.modelSerialization=!0;var n=this.retrieveMetadata(e).map(function(e){return e.propertyName});return t&&t.defined&&(n=n.filter(function(e){return r.model[e]})),this.model.modelSerialization=!1,n},e.prototype.retrieveMetadata=function(e){return Reflect.getMetadata(e,this.model)||[]},e.prototype.getIncludedKeys=function(e){return e=(e||{})&&s({forBackend:!0},e),b(this.model,this,e)},e}();b=function(e,t,r){var n=r.forBackend?"backendPropName":"frontendPropName",i=t.relationshipKeys({defined:!0}).filter(function(e){return t.isSidepostable(e)}),o=[];return i.forEach(function(i){var a=e[i],s=[];if(Array.isArray(a))a.forEach(function(e){var t=new _(e),n=b(e,t,r);s.push.apply(s,d(n))});else{var u=new _(a),p=b(a,u,r);s.push.apply(s,d(p))}s=(s=s.map(function(e){return t[n](i)+"."+e})).filter(function(e,t){return s.indexOf(e)>=t}),o.push.apply(o,d(s))}),d(i=i.map(function(e){return t[n](e)}),o)};var M=function(){function e(e){this.model=e,this.mdwrapper=new _(e)}return e.prototype.toJsonapi=function(){var e=this.serialize(),t=this.mdwrapper.getIncludedKeys();return(new g).serialize(e,t)},e.prototype.serialize=function(){var e=this.model.type,t=u(this.serializeAll(),3),r=t[0],n=t[1],i=t[2],o=[];o.push.apply(o,d(Object.keys(n).filter(function(e){return n.hasOwnProperty(e)}))),o.push.apply(o,d(Object.keys(i).filter(function(e){return i.hasOwnProperty(e)})));var a=s({id:this.model.id,type:e},r,n,i,{relationshipNames:o});return this.model.isRelation&&(a.__method=this.model.relationMethod),a},e.prototype.toHash=function(){var e=this,t={id:this.model.id,type:this.model.type};return this.mdwrapper.attributesKeys({defined:!0}).forEach(function(r){return t[r]=e.model[r]}),this.mdwrapper.belongsToKeys({defined:!0}).forEach(function(r){return t[r]=e.model[r].toHash()}),this.mdwrapper.hasManyKeys({defined:!0}).forEach(function(r){e.model[r].forEach(function(e){t[r]=t[r]||[],t[r].push(e.toHash())})}),t},e.prototype.serializeAll=function(){return[this.serializeAttributes(),this.serializeBelongsTo(),this.serializeHasMany()]},e.prototype.serializeAttributes=function(){var e=this,t=this.mdwrapper.attributesKeys({defined:!0});t=t.filter(function(t){return e.mdwrapper.isWritable(t)});var r=this.model[l];t=this.model.id?t.filter(function(e){return r[e].hasDirtyAttributes}):t;var n={};return t.forEach(function(t){var i=e.mdwrapper.backendPropName(t);n[i]=r[t].serializedValue}),n},e.prototype.serializeBelongsTo=function(){var e=this,t=this.mdwrapper.belongsToKeys({defined:!0});t=(t=t.filter(function(t){return e.mdwrapper.isWritable(t)})).filter(function(t){return e.model[t].hasBeenTouched});var r={};return t.forEach(function(t){var n=e.mdwrapper.isSidepostable(t),i=e.mdwrapper.backendPropName(t);r[i]=n?e.model[t].serialize():e.model[t].sideload(),r[i]||delete r[i]}),r},e.prototype.serializeHasMany=function(){var e=this,t=this.mdwrapper.hasManyKeys({defined:!0});t=t.filter(function(t){return e.mdwrapper.isWritable(t)});var r={};return t.forEach(function(t){var n=e.mdwrapper.isSidepostable(t),i=e.mdwrapper.backendPropName(t);r[i]=n?e.model[t].filter(function(e){return e.hasBeenTouched}).map(function(e){return e.serialize()}):e.model[t].filter(function(e){return e.hasBeenTouched}).map(function(e){return e.sideload()}),0===r[i].length&&delete r[i]}),r},e}(),w=function(){function e(e){this.modelInitialization=!1,this.modelSerialization=!1,this.__isRelation=!1,e&&(this.modelInitialization=!0,this.id=e.id,this.assign(e),this.modelInitialization=!1)}return Object.defineProperty(e.prototype,"__wrapper",{get:function(){return this.__mdwrapper||(this.__mdwrapper=new _(this)),this.__mdwrapper},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"__serializer",{get:function(){return this.__resSerializer||(this.__resSerializer=new M(this)),this.__resSerializer},enumerable:!0,configurable:!0}),e.getModel=function(e,t){return new e((new g).deserialize(t))},e.getAsRelationship=function(e,t,r){return t?((r=s({method:"untouched",modelInit:!1},r)).modelInit?n=new e(t):((n=new e).id=t.id,n.assign(t)),n.__isRelation=!0,n.__method=r.method,n):null;var n},e.prototype.isModelInitialization=function(){return this.modelInitialization},Object.defineProperty(e.prototype,"modelOptions",{get:function(){return Reflect.getMetadata(f,this.constructor)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return this.modelOptions.type},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasBeenTouched",{get:function(){var e=this.__isRelation&&"untouched"!==this.__method;return this.hasDirtyAttributes||this.hasDirtyBelongsTos||this.hasDirtyHasManys||e},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasDirtyAttributes",{get:function(){var e=this[l];for(var t in e)if(e.hasOwnProperty(t)&&e[t].hasDirtyAttributes)return!0;return!1},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasDirtyBelongsTos",{get:function(){var e=this,t=this.__wrapper.belongsToKeys({defined:!0}),r=!1;return t.forEach(function(t){r=r||e[t].hasBeenTouched}),r},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"hasDirtyHasManys",{get:function(){var e=this,t=this.__wrapper.hasManyKeys({defined:!0}),r=!1;return t.forEach(function(t){r=r||e[t].map(function(e){return e.hasBeenTouched}).reduce(function(e,t){return e||t},!1)}),r},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"isRelation",{get:function(){return this.__isRelation},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"relationMethod",{get:function(){return"untouched"!==this.__method?this.__method:this.hasBeenTouched?this.id?"update":"create":"untouched"},enumerable:!0,configurable:!0}),e.prototype.rollbackAttributes=function(){var e=this[l];for(var t in e)e.hasOwnProperty(t)&&e[t].hasDirtyAttributes&&(this[t]=e[t].oldValue)},e.prototype.assign=function(e){var t=this.translateKeys(e);Object.assign(this,t),this.__isRelation&&(this.__method=this.relationMethod)},e.prototype.disassociate=function(){this.__method="disassociate"},e.prototype.destroy=function(){if(!this.isRelation)throw new Error("Destroying resource is not supported! Use the service instead.");this.__method="destroy"},e.prototype.toJsonapi=function(){return this.__serializer.toJsonapi()},e.prototype.toHash=function(){return this.__serializer.toHash()},e.prototype.sideload=function(){var e=this.relationMethod;if("create"!==e&&"untouched"!==e){var t=this.modelOptions.type;return{id:this.id,type:t,__method:e}}},e.prototype.serialize=function(){return this.__serializer.serialize()},e.prototype.translateKeys=function(e){e.toHash&&(e=e.toHash());var t={};for(var r in e)if(e.hasOwnProperty(r)){var n=this.__wrapper.frontendPropName(r.toString());n&&(t[n]=e[r])}return t},e}();var O=function(){function e(e){this._pagination={},this._filter={},this._sort={},this._fields={},this._include=[],this._stats={},this.service=e}return e.clone=function(t){var r=new e(t.service),n=function i(e,t){t=t||[];t="string"==typeof t?[t]:t;if(!e||"object"!=typeof e)return e;if(e instanceof Date){var r=new Date;return r.setTime(e.getTime()),r}if(e instanceof Array){for(var r=[],n=0,o=e.length;n<o;n++)r[n]=i(e[n]);return r}if(e instanceof Object){var a={};return Object.keys(e).filter(function(e){return!t.includes(e)}).forEach(function(t){a[t]=i(e[t])}),a}throw new Error("Unable to copy obj! Its type isn't supported.")}(t,"service");return r._pagination=n._pagination,r._filter=n._filter,r._sort=n._sort,r._fields=n._fields,r._include=n._include,r._stats=n._stats,r},e.prototype.all=function(e){var t=this.buildParams();return e=e||{},this.service.all(s({params:t},e))},e.prototype.find=function(e){var t=this.buildParams();return this.service.find(e,t)},e.prototype.page=function(t){var r=e.clone(this);return r._pagination.number=t,r},e.prototype.per=function(t){var r=e.clone(this);return r._pagination.size=t,r},e.prototype.where=function(t){var r=e.clone(this);for(var n in t)t.hasOwnProperty(n)&&(r._filter[n]=t[n]);return r},e.prototype.stats=function(t){var r=e.clone(this);for(var n in t)t.hasOwnProperty(n)&&(r._stats[n]=t[n]);return r},e.prototype.order=function(t){var r=e.clone(this);if("string"==typeof t)return r._sort[t]="asc",r;for(var n in t)t.hasOwnProperty(n)&&(r._sort[n]=t[n]);return r},e.prototype.select=function(t){var r=e.clone(this);if(Array.isArray(t)||"string"==typeof t){var n=r.service.getModelConfig().type;return r._fields[n]=t,r}for(var i in t)t.hasOwnProperty(i)&&(r._fields[i]=t[i]);return r},e.prototype.includes=function(t){var r,n=e.clone(this);return Array.isArray(t)?(r=n._include).push.apply(r,d(t)):n._include.push(t),n},e.prototype.buildParams=function(){var e={page:this._pagination,filter:this._filter,sort:this.stringifySorts(this._sort),fields:this._fields,stats:this._stats,include:this.stringifyIncludes(this._include)};return this.serializeParams(e)},e.prototype.stringifySorts=function(e){if(!e||0===Object.keys(e).length)return[];var t=[];for(var r in e)e.hasOwnProperty(r)&&("asc"!==e[r]&&(r="-"+r),t.push(r));return t},e.prototype.stringifyIncludes=function(e){var t=this;if(!e||0===Object.keys(e).length&&0===e.length)return[];var r=[];if(Array.isArray(e)){var n=e.map(function(e){return t.stringifyIncludes(e)}).reduce(function(e,t){return e.push.apply(e,d(t)),e},[]);return r.push.apply(r,d(n)),r}if("object"==typeof e){var i=function(t){if(e.hasOwnProperty(t)){var n=o.stringifyIncludes(e[t]).map(function(e){return t+"."+e});r.push.apply(r,d(n))}},o=this;for(var a in e)i(a);return r}return r.push(e),r},e.prototype.serializeParams=function(e,t){for(var r in t||(t=new a.HttpParams),e)if(e.hasOwnProperty(r)&&e[r]){var n=e[r];if(Array.isArray(n))n.length>0&&(t=t.append(r,n.join(",")));else if("object"!=typeof n)t=t.append(r,n);else for(var i in n)if(n.hasOwnProperty(i)){var o={};o[r+"["+i+"]"]=n[i],t=this.serializeParams(o,t)}}return t},e}();var z=function(){function e(e){this.http=e}return e.prototype.all=function(e){var t=this,r=this.buildUrl(),n=(e=e||{}).params,o=this.http.get(r,{params:n,observe:"response"}).pipe(i.map(function(e){return t.successful(e)}));return e.metadata?o.pipe(i.map(function(e){return{data:t.extract(e),meta:t.extractMeta(e)}}),i.catchError(function(e){return t.handleError(e)})):o.pipe(i.map(function(e){return t.extract(e)}),i.catchError(function(e){return t.handleError(e)}))},e.prototype.find=function(e,t){var r=this,n=this.buildUrl(e);return this.http.get(n,{params:t,observe:"response"}).pipe(i.map(function(e){return r.successful(e)}),i.map(function(e){return r.extract(e)}),i.catchError(function(e){return r.handleError(e)}))},e.prototype.save=function(e){var t=this,r=this.buildUrl(e.id),n=e.toJsonapi();return(e.id?this.http.put(r,n,{observe:"response"}):this.http.post(r,n,{observe:"response"})).pipe(i.map(function(e){return t.successful(e)}),i.map(function(e){return t.extract(e)}),i.catchError(function(e){return t.handleError(e)}))},e.prototype["delete"]=function(e){var t=this,r=this.buildUrl(e);return this.http["delete"](r,{observe:"response"}).pipe(i.map(function(e){return t.successful(e)}),i.catchError(function(e){return t.handleError(e)}))},e.prototype.extractMeta=function(e){return e.body.meta},e.prototype.extract=function(e){var t=this,r=e.body,n=r.data;if(Array.isArray(n)){var i=[];return n.forEach(function(e){var n=t.deserializeModel({data:e,included:r.included});i.push(n)}),i}return this.deserializeModel(r)},e.prototype.deserializeModel=function(e){var t=this.getModelType();return w.getModel(t,e)},e.prototype.handleError=function(e){return o.throwError(e)},e.prototype.buildUrl=function(e){var t=this.getServiceConfig(),r=this.getModelConfig();return[this.baseUrl,t.apiVersion,t.endpointUrl||r.type,e].filter(function(e){return!!e}).join("/")},e.prototype.getModelType=function(){return this.getServiceConfig().model()},e.prototype.getModelConfig=function(){return Reflect.getMetadata(f,this.getModelType())},e.prototype.getServiceConfig=function(){return Reflect.getMetadata(c,this.className)},e.prototype.successful=function(e){if(e.status<400)return e;throw e},e.prototype.page=function(e){return new O(this).page(e)},e.prototype.per=function(e){return new O(this).per(e)},e.prototype.where=function(e){return new O(this).where(e)},e.prototype.stats=function(e){return new O(this).stats(e)},e.prototype.order=function(e){return new O(this).order(e)},e.prototype.select=function(e){return new O(this).select(e)},e.prototype.includes=function(e){return new O(this).includes(e)},e}();e.Attribute=function(e){return void 0===e&&(e={}),function(t,r){var n,i=function(t){var r;if(e.converter)r=e.converter;else if(t===Date)r=new v;else{var n=new t;n.serialize&&n.deserialize&&(r=n)}return r},o=function(e,t,r){void 0===r&&(r=!1);var n=i(e);return n?r?n.serialize(t):n.deserialize(t):t},a=function(e,t,r){var n=i(e);return n?n.areEquals?n.areEquals(t,r):n.serialize(r)===n.serialize(t):t===r};delete t[r]&&((n=Reflect.getMetadata(l,t)||[]).push({propertyName:r,backendName:e.backendName||r,readonly:!!e.readonly,converter:e.converter}),Reflect.defineMetadata(l,n,t),Object.defineProperty(t,r,{get:function(){return this["_"+r]},set:function(n){var i=Reflect.getMetadata("design:type",t,r),s=o(i,n),u=null;this.isModelInitialization()&&this.id?u=s:this[l]&&this[l][r]&&(u=this[l][r].oldValue),this["_"+r]=s,function(n,i,s){var u=Reflect.getMetadata("design:type",t,r);n[l]=n[l]||{},n[l][r]={newValue:s,oldValue:i,backendName:e.backendName||r,hasDirtyAttributes:!a(u,i,s),serializedValue:o(u,s,!0)}}(this,u,s)},enumerable:!0,configurable:!0}))}},e.BelongsTo=function(e){return void 0===e&&(e={}),function(t,r){var n,i=function(t){if(!Array.isArray(e["class"]))return m.find(e["class"]);var r=e["class"].map(function(e){return m.find(e)});if(!t)return r[0];var n=t.type;if(!n)throw new Error("Object should be a subclass of ResourceBase or should have a type attribute!");var i=r.find(function(e){return(new e).type===n});if(!i)throw new Error("Object should be a subclass of ResourceBase or should have a type attribute!");return i};delete t[r]&&((n=Reflect.getMetadata(h,t)||[]).push({propertyName:r,backendName:e.backendName||r,readonly:!!e.readonly,sidepostable:!!e.sidepostable}),Reflect.defineMetadata(h,n,t),Object.defineProperty(t,r,{get:function(){if(!this["_"+r]&&!this.modelSerialization){var e=i();this["_"+r]=w.getAsRelationship(e,{})}return this["_"+r]},set:function(t){var n=i(t);if(this.isModelInitialization())this["_"+r]=w.getAsRelationship(n,t,{modelInit:!0});else{var o=this["_"+r];this["_"+r]=e.sidepostable?function(e,t,r){var n=!(!t||!t.id),i=!(!r||!r.id),o=!!(r&&Object.keys(r).filter(function(e){return"id"!==e&&"type"!==e}).length>0);return n&&i&&t.id===r.id?(r.deleteRelation&&t.disassociate(),r.destroyRelation&&t.destroy(),t.assign(r),t):i?w.getAsRelationship(e,r,{method:"update"}):o?w.getAsRelationship(e,r,{method:"create"}):t?(t.disassociate(),t):null}(n,o,t):function(e,t,r){var n=!(t&&t.id),i=!(r&&r.id),o=n&&i,a=!n&&!i&&t.id===r.id;if(o)return null;if(i||r.deleteRelation)return t.disassociate(),t;if(a){var s=t.type,u=r.type;if(!u||s===u)return t}return w.getAsRelationship(e,r,{method:"update"})}(n,o,t)}},enumerable:!0,configurable:!0}))}},e.HasMany=function(e){return void 0===e&&(e={}),function(t,r){var n;delete t[r]&&((n=Reflect.getMetadata(y,t)||[]).push({propertyName:r,backendName:e.backendName||r,readonly:!!e.readonly,sidepostable:!!e.sidepostable}),Reflect.defineMetadata(y,n,t),Object.defineProperty(t,r,{get:function(){return this["_"+r]||this.modelSerialization||(this["_"+r]=[]),this["_"+r]},set:function(t){var n=m.find(e["class"]);if(this.isModelInitialization())this["_"+r]=t.map(function(e){return w.getAsRelationship(n,e,{modelInit:!0})});else{var i=this["_"+r];this["_"+r]=e.sidepostable?function(e,t,r){if(!r)return t;var n=t&&t.filter(function(e){return-1===r.findIndex(function(t){return e.id===t.id})})||[];return r.forEach(function(r){var i=!(!r||!r.id),o=!!(r&&Object.keys(r).filter(function(e){return"id"!==e&&"type"!==e}).length>0);if(i||o)if(i){var a=t&&t.find(function(e){return e.id===r.id});if(a){if(r.deleteRelation||r.destroyRelation)return r.destroyRelation?a.destroy():a.disassociate(),void n.push(a);a.assign(r),n.push(a)}else n.push(w.getAsRelationship(e,r,{method:"update"}))}else n.push(w.getAsRelationship(e,r,{method:"create"}))}),n}(n,i,t):function(e,t,r){if(!r)return t;var n=t&&t.filter(function(e){return-1===r.findIndex(function(t){return e.id===t.id})})||[];return r.forEach(function(r){if(r.id){var i=t&&t.find(function(e){return e.id===r.id});i?(r.deleteRelation&&i.disassociate(),n.push(i)):n.push(w.getAsRelationship(e,r,{method:"update"}))}}),n}(n,i,t)}},enumerable:!0,configurable:!0}))}},e.JsonapiBaseService=z,e.Model=function(e){return function(t){Reflect.defineMetadata(f,e,t),m.add(e.type,t)}},e.NgxAirbrushModule=p,e.ResourceBase=w,e.Scope=O,e.ServiceDecorator=function(e){return function(t){Reflect.defineMetadata(c,e,t)}},Object.defineProperty(e,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-airbrush.umd.min.js.map