New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@datx/jsonapi

Package Overview
Dependencies
Maintainers
7
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@datx/jsonapi - npm Package Compare versions

Comparing version
2.4.8
to
2.4.10
+1
-1
index.cjs.js

@@ -1,2 +0,2 @@

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@datx/core"),t=require("@datx/utils"),n=require("@datx/network"),r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)};function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},i.apply(this,arguments)};function a(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))}function s(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var c=/^((https?\:)?\/\/)/,u="undefined"!=typeof window;function l(e){return new Error("[datx exception] ".concat(e))}function p(e){var n=t.getMeta(e,"fields",{},!0,!0),r={};return Object.keys(n).forEach((function(e){n[e].referenceDef&&(r[e]=n[e].referenceDef)})),r}function d(e,t){return void 0===t&&(t=50),a(this,void 0,void 0,(function(){var n,r,o,i;return s(this,(function(a){switch(a.label){case 0:r=[],o=e,i=1,(n=[]).push.apply(n,e.data),r.push(e),a.label=1;case 1:return e.next?++i>t?[3,3]:[4,e.next()]:[3,3];case 2:return e=a.sent(),r.push(e),n.push.apply(n,e.data),[3,1];case 3:return o=r[r.length-1],[2,{data:n,responses:r,lastResponse:o}]}}))}))}var f={baseUrl:"/",cache:u?n.CachingStrategy.CacheFirst:n.CachingStrategy.NetworkOnly,maxCacheAge:1/0,defaultFetchOptions:{headers:{"content-type":"application/vnd.api+json"}},encodeQueryString:!1,fetchReference:u&&"fetch"in window&&"function"==typeof window.fetch&&window.fetch.bind(window)||void 0,paramArrayType:n.ParamArrayType.CommaSeparated,baseFetch:function(e,t,n,r,o){var i,a,s,c=this,u=Promise.resolve(),l=e.toUpperCase(),p="GET"!==l&&"HEAD"!==l;return u.then((function(){var o=f.defaultFetchOptions.headers||{},i=Object.assign({},o,r),a=Object.assign({},f.defaultFetchOptions,{body:p&&JSON.stringify(n)||void 0,headers:i,method:e});if(c.fetchReference)return c.fetchReference(t,a);throw new Error("Fetch reference needs to be defined before using the network")})).then((function(e){return a=e.status,s=e.headers,e.json()})).catch((function(e){if(204===a)return null;throw e})).then((function(e){if(i=e,a>=400)throw{message:"Invalid HTTP status: ".concat(a),status:a};return{data:i,headers:s,requestHeaders:r,status:a}})).catch((function(e){return c.onError({data:i,error:e,headers:s,requestHeaders:r,status:a})}))},onError:function(e){return e},transformRequest:function(e){return e},transformResponse:function(e){return e},usePatchWhenPossible:!0};function h(e,t,n){var r,o,i,a;return new((null===(o=null===(r=t.options)||void 0===r?void 0:r.fetchOptions)||void 0===o?void 0:o.Response)||Q)({error:new Error(e),requestHeaders:null===(a=null===(i=t.options)||void 0===i?void 0:i.networkConfig)||void 0===a?void 0:a.headers},n,t.options)}function y(n,r,o,i){var a,s;void 0===o&&(o=!1);var c=(null==r?void 0:r.Response)||Q;return f.baseFetch(n.method,n.url,n.data,null===(s=null===(a=null==n?void 0:n.options)||void 0===a?void 0:a.networkConfig)||void 0===s?void 0:s.headers,r).then((function(e){var t=Object.assign({},e,{collection:n.collection}),r=f.transformResponse(t);return i?(i.update(r,n.views),i):new c(r,n.collection,n.options,void 0,n.views)})).then((function(r){return o&&function(n,r){if((null==r?void 0:r.isSuccess)&&-1!==r.status&&(r.data||null===r.data)){var o=t.mapItems(r.data||[],e.getModelType);(B=B.filter((function(e){return e.url!==n}))).unshift({response:r.snapshot,collection:r.collection,time:Date.now(),types:[].concat(o),url:n})}}(n.url,r),r}))}function v(e){var t,r,o,i,a,s,c,u,l,p,d,v,g,m,_,b,w,O=(null===(r=null===(t=e.options)||void 0===t?void 0:t.fetchOptions)||void 0===r?void 0:r.Response)||Q,j=f.transformRequest(e),k=null===(o=null==j?void 0:j.collection)||void 0===o?void 0:o.constructor,M=k&&k.cache,P="GET"===j.method.toUpperCase(),C=(null===(a=null===(i=e.options)||void 0===i?void 0:i.cacheOptions)||void 0===a?void 0:a.skipCache)||!P?n.CachingStrategy.NetworkOnly:(null===(c=null===(s=e.options)||void 0===s?void 0:s.cacheOptions)||void 0===c?void 0:c.cachingStrategy)||M||f.cache,x=f.maxCacheAge||1/0;if(k&&void 0!==k.maxCacheAge&&(x=k.maxCacheAge),void 0!==(null===(l=null===(u=e.options)||void 0===u?void 0:u.cacheOptions)||void 0===l?void 0:l.maxAge)&&(x=null===(d=null===(p=e.options)||void 0===p?void 0:p.cacheOptions)||void 0===d?void 0:d.maxAge),C===n.CachingStrategy.NetworkOnly)return y(j,null===(v=e.options)||void 0===v?void 0:v.fetchOptions);var T=function(e,t,n){void 0===n&&(n=Q);var r=Date.now()-1e3*t,o=B.find((function(t){return t.url===e&&t.time>r}));if(o){var i=o.response;return{response:new n(i.response,o.collection,i.options),time:o.time,types:o.types,url:o.url}}}(j.url,x,O);if(C===n.CachingStrategy.NetworkFirst)return y(j,null===(g=e.options)||void 0===g?void 0:g.fetchOptions,!0).catch((function(e){if(T)return T.response;throw e}));if(C===n.CachingStrategy.StaleWhileRevalidate){var A=y(j,null===(m=e.options)||void 0===m?void 0:m.fetchOptions,!0);return T?(A.catch((function(){})),Promise.resolve(T.response)):A}if(C===n.CachingStrategy.CacheOnly)return T?Promise.resolve(T.response):Promise.reject(h("No cache for this request",e,null==j?void 0:j.collection));if(C===n.CachingStrategy.CacheFirst)return T?Promise.resolve(T.response):y(j,null===(_=e.options)||void 0===_?void 0:_.fetchOptions,!0);if(C===n.CachingStrategy.StaleAndUpdate){var R=null===(b=null==T?void 0:T.response)||void 0===b?void 0:b.clone();return A=y(j,null===(w=e.options)||void 0===w?void 0:w.fetchOptions,!0,R),R?(A.catch((function(){})),Promise.resolve(R)):A}return Promise.reject(h("Invalid caching strategy",e,null==j?void 0:j.collection))}function g(e,t,n,r){return v({collection:t,data:void 0,method:"GET",options:n,url:e,views:r})}function m(e,t,n,r,o){return v({collection:n,data:t,method:"POST",options:r,url:e,views:o})}function _(e,t,n,r,o){return v({collection:n,data:t,method:"PATCH",options:r,url:e,views:o})}function b(e,t,n,r,o){return v({collection:n,data:t,method:"PUT",options:r,url:e,views:o})}function w(e,t,n,r,o){if(void 0===o&&(o=Q),e){var i="object"==typeof e?e.href:e;if(i)return g(i,t,n,r)}return Promise.resolve(new o({data:void 0},t))}function O(n,r){return t.mobx.action((function(o){if(o.error)throw o.error;if(204===o.status)return t.setMeta(n,"networkPersisted",!0),n;if(202===o.status){var i=o.data;return t.setMeta(i,"jsonapiProp",r),t.setMeta(i,"jsonapiQueue",!0),t.setMeta(i,"jsonapiRelated",n),i}t.setMeta(n,"networkPersisted",!0);var a=o.replaceData(n).data;return e.commitModel(a),a}))}function j(e,t){void 0===t&&(t="");var r=[];return Object.keys(e).forEach((function(o){e[o]instanceof Array?f.paramArrayType===n.ParamArrayType.CommaSeparated?r.push({key:"".concat(t).concat(o),value:e[o].join(",")}):f.paramArrayType===n.ParamArrayType.MultipleParams?r.push.apply(r,e[o].map((function(e){return{key:"".concat(t).concat(o),value:e}}))):f.paramArrayType===n.ParamArrayType.ParamArray&&r.push.apply(r,e[o].map((function(e){return{key:"".concat(t).concat(o,"]["),value:e}}))):"object"==typeof e[o]?r.push.apply(r,j(e[o],"".concat(o,"."))):r.push({key:"".concat(t).concat(o),value:e[o]})})),r}function k(e){return j(e).map((function(e){return"filter[".concat(e.key,"]=").concat(e.value)}))}function M(e){return encodeURIComponent(e).replace(/%3D/,"=")}function P(e,t,n,r){var o,i,a,s,u=n&&n.networkConfig&&n.networkConfig.headers||{},l=[].concat(k(n&&n.queryParams&&n.queryParams.filter||{}),(s=n&&n.queryParams&&n.queryParams.sort)?["sort=".concat(s)]:[],(a=n&&n.queryParams&&n.queryParams.include)?["include=".concat(a)]:[],(o=n&&n.queryParams&&n.queryParams.fields||{},i=[],Object.keys(o).forEach((function(e){i.push("fields[".concat(e,"]=").concat(o[e]))})),i),function(e){return e.map((function(e){return"string"==typeof e?e:"".concat(e.key,"=").concat(e.value)}))}(n&&n.queryParams&&n.queryParams.custom||[]));f.encodeQueryString&&(l=l.map(M));var p=function(e,t){var n=e;if(t.length){var r=-1===n.indexOf("?")?"?":"&";n+=r+t.join("&")}return n}(function(e,t){return c.test(e)||t?e:"".concat(f.baseUrl).concat(e)}(e,r),l);return{data:t,headers:u,url:p}}function C(t,n,r,o,i,a){var s=a&&a.constructor;!s&&i&&(s=i.constructor.types.filter((function(e){return e.type===t}))[0]);var c,u=!1;return s?s.endpoint&&"function"==typeof s.endpoint?(u=!0,c=s.endpoint(f.baseUrl)):c=s.endpoint||s.baseUrl||e.getModelType(s):c=t.toString(),P(n?"".concat(c,"/").concat(n):"".concat(c),r,o,u)}function x(n,r){var o,i;if(!r)return null;var a=((o={})[t.META_FIELD]=((i={fields:Object.keys(r.attributes||{}).reduce((function(e,t){return e[t]={referenceDef:!1},e}),{}),id:r.id}).jsonapiLinks=r.links,i.jsonapiMeta=r.meta,i.networkPersisted=Boolean(r.id),i.type=r.type,i),o);if(r.relationships){var s={},c={},u={};Object.keys(r.relationships).forEach((function(t){var o,i=r.relationships[t];i&&"data"in i&&(i.data||null===i.data)&&(!(i.data instanceof Array)||i.data.length>0?(a[t]=i.data,n&&t in n||(u[t]={referenceDef:{model:(i.data instanceof Array?i.data[0].type:null===(o=i.data)||void 0===o?void 0:o.type)||N.type,type:i.data instanceof Array?e.ReferenceType.TO_MANY:e.ReferenceType.TO_ONE}})):a[t]=[]),i&&"links"in i&&(s[t]=i.links),i&&"meta"in i&&(c[t]=i.meta)})),Object.assign(a[t.META_FIELD].fields,u),a[t.META_FIELD].jsonapiRefLinks=s,a[t.META_FIELD].jsonapiRefMeta=c}return Object.assign(a,r.attributes)}function T(e){return t.getMeta(e,"jsonapiLinks",{})}function A(e){return t.getMeta(e,"jsonapiRefLinks",{})}function R(t,n,r){if(!e.getModelCollection(t))throw l("The model needs to be in a collection");var o=A(t);if(!o||!(n in o))throw l("The reference ".concat(n," doesn't have any links"));var i=o[n];if(!i||!(r in i))throw l("Link ".concat(r," doesn't exist on the model"));return i[r]}function E(e){return t.getMeta(e,"networkPersisted",!1)}function S(n,r){var o=n.constructor,i=r?e.modelToDirtyJSON(n):e.modelToJSON(n),a=o.useAutogeneratedIds,s={attributes:i,id:E(n)||a?e.getModelId(n).toString():void 0,type:e.getModelType(n)},c=p(n);return Object.keys(c).forEach((function(r){if(!c[r].property){s.relationships=s.relationships||{};var o=e.getRefId(n,r);s.relationships[r]={data:t.mapItems(o,(function(e){return{id:e.id.toString(),type:e.type}}))},s.attributes&&delete s.attributes[r]}})),s.attributes&&(delete s.attributes.id,delete s.attributes[t.META_FIELD]),s}function q(t,n){return C(e.getModelType(t),E(t)?e.getModelId(t):void 0,void 0,n,void 0,t).url}function I(t,n){var r,o=e.getModelCollection(t),i=null!==(r=null==f?void 0:f.usePatchWhenPossible)&&void 0!==r&&r,a=E(t),s=S(t,i&&a);return(a?i?_:b:m)(q(t,n),{data:s},o,n&&n.networkConfig&&n.networkConfig.headers).then(O(t)).then((function(n){return J(e.getModelType(t)),n}))}function L(n,r){var o=e.getModelCollection(n),i=E(n),a=q(n);return i?function(e,t,n,r){return v({collection:t,data:void 0,method:"DELETE",options:n,url:e,views:void 0})}(a,o,r&&r.networkConfig&&r.networkConfig.headers).then((function(e){if(e.error)throw e.error;!function(e,n){t.setMeta(e,"networkPersisted",!1)}(n),o&&o.__removeModel(n)})):(o&&o.__removeModel(n),Promise.resolve())}var D=["jsonapiLinks","jsonapiMeta","networkPersisted","jsonapiRefLinks","jsonapiRefMeta"];function F(e){return function(n){function r(r,o){void 0===r&&(r={});var i,a=r;r&&"type"in r&&("attributes"in r||"relationships"in r)&&(a=x(p(e),r)),i=n.call(this,a,o)||this;var s=(null==a?void 0:a[t.META_FIELD])||{};return D.forEach((function(e){e in s&&t.setMeta(i,e,s[e])})),i}return o(r,n),r.getAutoId=function(){return n.getAutoId.call(this).toString()},r.prototype.save=function(e){return I(this,e)},r.prototype.destroy=function(e){return L(this,e)},r.useAutogeneratedIds=e.useAutogeneratedIds||!1,r}(e)}var N=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(F(e.PureModel));function H(e){if(e instanceof Array)return e;var t=[];return e.forEach((function(e,n){t.push([n,e])})),t}function U(t,n,r){if(n&&t.data){var o=r||n.sync(t.data);return new e.Bucket.ToOneOrMany(o,n,!0)}if(t.data){var i=t.data;if(i.data){if(i.data instanceof Array)throw new Error("A save/remove operation should not return an array of results");return{value:r||new N(x(void 0,i.data))}}}return new e.Bucket.ToOneOrMany(null,n,!0)}var Q=function(){function n(e,t,n,r,o){var i=this;if(this.__internal={response:{},views:[]},this.__cache={},this.collection=t,this.__updateInternal(e,n,o),this.__data=U(e,t,r),this.views.forEach((function(e){i.__data.value&&e.add(i.__data.value)})),Object.freeze(this),this.error)throw this}return Object.defineProperty(n.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"headers",{get:function(){return this.__internal.headers},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"requestHeaders",{get:function(){return this.__internal.requestHeaders},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"error",{get:function(){return this.__internal.error},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"status",{get:function(){return this.__internal.status},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isSuccess",{get:function(){return!this.error},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"data",{get:function(){return this.__data.value},enumerable:!1,configurable:!0}),n.prototype.__updateInternal=function(e,n,r){var o,i,a,s,c,u=this;n&&(this.__internal.options=n),this.__internal.response=e,this.__internal.meta=(null===(o=e.data)||void 0===o?void 0:o.meta)||{},this.__internal.links=(null===(i=e.data)||void 0===i?void 0:i.links)||{},this.__internal.jsonapi=(null===(a=e.data)||void 0===a?void 0:a.jsonapi)||{},this.__internal.headers=e.headers&&((c=e.headers)instanceof Array?new t.Headers(c):c),this.__internal.requestHeaders=e.requestHeaders,this.__internal.error=(null===(s=e.data)||void 0===s?void 0:s.errors)||e.error,this.__internal.status=e.status,r&&(this.__internal.views=r),this.error||this.status||(this.__internal.error=new Error("Network not available")),this.links&&Object.keys(this.links).forEach((function(e){t.assignComputed(u,e,(function(){return u.__fetchLink(e)}))}))},n.prototype.replaceData=function(t){var n,r=this.data;if(r===t)return this;var o=e.getModelId(r).toString(),i=e.getModelType(r),a=this.views.map((function(e){return e.list.indexOf(r)}));this.collection&&(this.collection.removeOne(i,o),this.collection.add(t));var s=e.modelToJSON(r);return null===(n=null==s?void 0:s.__META__)||void 0===n||delete n.collection,e.updateModel(t,s),e.updateModelId(t,o),this.views.forEach((function(e,n){-1!==a[n]&&(e.list[a[n]]=t)})),new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,t)},n.prototype.clone=function(){return new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,this.data||void 0)},Object.defineProperty(n.prototype,"snapshot",{get:function(){return{response:Object.assign({},this.__internal.response,{headers:this.__internal.response.headers&&H(this.__internal.response.headers),collection:void 0}),options:this.__internal.options}},enumerable:!1,configurable:!0}),n.prototype.update=function(e,t){this.__updateInternal(e,void 0,t);var n=U(e,this.collection);return this.__data.__readonlyValue=n.value,this},n.prototype.__fetchLink=function(e){var t=this,n=this.constructor;if(!this.__cache[e]){var r=this.links&&e in this.links?this.links[e]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[e]=function(){return w(r,t.collection,o,t.views,n)}}}return this.__cache[e]},n}(),B=[];function J(e){B=B.filter((function(t){return!t.types.includes(e)}))}function G(e){if(e.error)throw e.error;return e}function z(e,n){return t.mapItems(e&&e.included||[],n),t.mapItems(e&&e.data||null,n)}var W,Y=function(e){function n(n,r,o,i){var a=e.call(this,n,r,o,i)||this;return a.links&&Object.keys(a.links).forEach((function(e){t.assignComputed(a,e,(function(){return a.__fetchLink(e)}))})),a}return o(n,e),Object.defineProperty(n.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),n.prototype.__fetchLink=function(e){var t=this;if(!this.__cache[e]){var r=this.links&&e in this.links?this.links[e]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[e]=function(){return w(r,t.collection,o,t.views).then((function(e){return new n(e.__internal.response,e.collection,void 0,e.views)}))}}}return this.__cache[e]},n}(n.Response);function V(e,t){return(e&&t.collection?t.collection.sync(e):e)||{}}function K(n){return i(i({},n),{data:{data:t.mapItems(n.data,(function(t){return t instanceof e.PureModel?S(t,!0):t}))||void 0}})}!function(e){e.Asc="",e.Desc="-"}(W||(W={}));var X=function(e){function t(t){var r,o=e.call(this,t)||this;return(r=o)._config.Response=Y,n.header("content-type","application/vnd.api+json")(r),n.parser(V)(r),n.serializer(K)(r),n.paramArrayType(n.ParamArrayType.CommaSeparated)(r),n.encodeQueryString(!1)(r),o}return o(t,e),t}(n.BaseRequest);Object.defineProperty(exports,"BaseRequest",{enumerable:!0,get:function(){return n.BaseRequest}}),Object.defineProperty(exports,"CachingStrategy",{enumerable:!0,get:function(){return n.CachingStrategy}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return n.HttpMethod}}),Object.defineProperty(exports,"ParamArrayType",{enumerable:!0,get:function(){return n.ParamArrayType}}),Object.defineProperty(exports,"addInterceptor",{enumerable:!0,get:function(){return n.addInterceptor}}),Object.defineProperty(exports,"body",{enumerable:!0,get:function(){return n.body}}),Object.defineProperty(exports,"cache",{enumerable:!0,get:function(){return n.cache}}),Object.defineProperty(exports,"clearAllCache",{enumerable:!0,get:function(){return n.clearAllCache}}),Object.defineProperty(exports,"clearCacheByType",{enumerable:!0,get:function(){return n.clearCacheByType}}),Object.defineProperty(exports,"collection",{enumerable:!0,get:function(){return n.collection}}),Object.defineProperty(exports,"encodeQueryString",{enumerable:!0,get:function(){return n.encodeQueryString}}),Object.defineProperty(exports,"fetchReference",{enumerable:!0,get:function(){return n.fetchReference}}),Object.defineProperty(exports,"header",{enumerable:!0,get:function(){return n.header}}),Object.defineProperty(exports,"method",{enumerable:!0,get:function(){return n.method}}),Object.defineProperty(exports,"paramArrayType",{enumerable:!0,get:function(){return n.paramArrayType}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(exports,"parser",{enumerable:!0,get:function(){return n.parser}}),Object.defineProperty(exports,"query",{enumerable:!0,get:function(){return n.query}}),Object.defineProperty(exports,"serializer",{enumerable:!0,get:function(){return n.serializer}}),Object.defineProperty(exports,"setUrl",{enumerable:!0,get:function(){return n.setUrl}}),exports.BaseJsonapiRequest=X,exports.GenericModel=N,exports.NetworkResponse=Y,exports.Response=Q,exports.buildUrl=P,exports.config=f,exports.fetchLink=w,exports.fetchModelLink=function(n,r,o){var i=e.getModelCollection(n),a=T(n);if(!a||!(r in a))throw l("Link ".concat(r," doesn't exist on the model"));var s=w(a[r],i,o);return t.getMeta(n,"jsonapiQueue")?s.then((function(r){var o=t.getMeta(n,"jsonapiRelated"),i=t.getMeta(n,"jsonapiProp"),a=r.data,s=a&&e.getModelType(a);return a&&s!==e.getModelType(n)&&s===e.getModelType(o)?i?(o[i]=a,r):(t.setMeta(o,"networkPersisted",!0),r.replaceData(o)):r})):s},exports.fetchModelRefLink=function(t,n,r,o){var i=e.getModelCollection(t);return w(R(t,n,r),i,o)},exports.getModelEndpointUrl=q,exports.getModelLinks=T,exports.getModelMeta=function(e){return t.getMeta(e,"jsonapiMeta",{})},exports.getModelRefLinks=A,exports.getModelRefMeta=function(e){return t.getMeta(e,"jsonapiRefMeta",{})},exports.isModelPersisted=E,exports.jsonapi=function(r){if(e.isModel(r))return F(r);if(e.isCollection(r))return function(r){function c(e){void 0===e&&(e=[]);var t,n,o=r.call(this,e)||this;return e instanceof Array||!(null==e?void 0:e.cache)||(t=e.cache,n=o,B.push.apply(B,t.map((function(e){return Object.assign({collection:n},e)})))),o}return o(c,r),c.prototype.sync=function(e){var t=this;if(!e)return null;var n=z(e,(function(e){return t.__addRecord(e)}));return z(e,this.__updateRelationships.bind(this)),n},c.prototype.fetch=function(e,r,o){return t.deprecated("fetch is deprecated, use getOne instead"),this.getOne(e,r,Object.assign({},o,{cacheOptions:Object.assign({},(null==o?void 0:o.cacheOptions)||{},{cachingStrategy:u?n.CachingStrategy.CacheFirst:n.CachingStrategy.NetworkOnly})}))},c.prototype.fetchAll=function(e,r){return t.deprecated("fetchAll is deprecated, use getMany instead"),this.getMany(e,Object.assign({},r,{cacheOptions:Object.assign({},(null==r?void 0:r.cacheOptions)||{},{cachingStrategy:u?n.CachingStrategy.CacheFirst:n.CachingStrategy.NetworkOnly})}))},c.prototype.getOne=function(t,n,r){var o=e.getModelType(t),i=this.__prepareQuery(o,n,void 0,r),a=r||{};return a.networkConfig=a.networkConfig||{},a.networkConfig.headers=i.headers,g(i.url,this,a).then(G)},c.prototype.getMany=function(t,n){var r=e.getModelType(t),o=this.__prepareQuery(r,void 0,void 0,n),i=n||{};return i.networkConfig=i.networkConfig||{},i.networkConfig.headers=o.headers,g(o.url,this,i).then(G)},c.prototype.getAll=function(e,t,n){return void 0===n&&(n=50),a(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:if(n<1)throw Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(e,t)];case 1:return[2,d(r.sent(),n)]}}))}))},c.prototype.request=function(e,t,n,r){return void 0===t&&(t="GET"),function(e){return v(e)}({url:P(e,n,r).url,options:r,data:n,method:t,collection:this})},c.prototype.removeOne=function(t,n,r){var o,i,a,s=e.getModelType(t);return"object"==typeof n||void 0===n||"boolean"==typeof n?(o=n,i=e.getModelId(t).toString(),a=t):(o=r,a=(i=e.getModelId(n).toString())?this.findOne(s,i):null),a&&o?L(a,"object"==typeof o?o:void 0):(a&&this.__removeModel(a),J(s),Promise.resolve())},c.prototype.removeAll=function(t){r.prototype.removeAll.call(this,t),J(e.getModelType(t))},c.prototype.reset=function(){r.prototype.reset.call(this),B.length=0},c.prototype.__addRecord=function(t){var n=this.constructor,r=t.type,o=t.id,i=void 0===o?null:this.findOne(r,o),a=x(p(n.types.find((function(t){return e.getModelType(t)===r}))||N),t);return i?(e.upsertModel(a,r,this),e.commitModel(i)):i=n.types.filter((function(e){return e.type===r})).length?this.add(a,r):this.add(new N(a,this)),i},c.prototype.__updateRelationships=function(n){var r=this,o=void 0===n.id?null:this.findOne(n.type,n.id);(n.relationships?Object.keys(n.relationships):[]).forEach((function(i){var a=n.relationships[i];if(a&&"data"in a){var s=a.data;if(!(t.isArrayLike(s)&&s.length<1)&&o)if(s){var c=t.mapItems(s,(function(e){return(void 0===e.id?null:r.findOne(e.type,e.id))||e}))||null,u=t.isArrayLike(s)?s[0].type:s.type;i in o?o[i]=c:e.initModelRef(o,i,{model:u,type:e.ReferenceType.TO_ONE_OR_MANY},c)}else{var l=t.getMeta(o,"refs");l&&i in l&&"__proto__"!==i&&(o[i]=l[i].type===e.ReferenceType.TO_MANY?[]:null)}}}))},c.prototype.__prepareQuery=function(e,t,n,r){return C(e,t,n,r,this)},c.prototype.toJSON=function(){return Object.assign({},r.prototype.toJSON.call(this),{cache:(e=this,B.filter((function(t){return t.collection===e})).map((function(e){return Object.assign({},e,{collection:void 0})})))});var e},c.types=i.types&&i.types.length?i.types.concat(N):[N],c.maxCacheAge=i.maxCacheAge,c.cache=i.cache,c.defaultModel=i.defaultModel||N,c}(i=r);var i;if(e.isView(r))return function(e){function t(t,n,r,o,i){void 0===o&&(o=[]),void 0===i&&(i=!1);var a=e.call(this,t,n,r,o,i)||this;return a.__collection=n,a}return o(t,e),t.prototype.sync=function(e){var t=this.__collection.sync(e);return t&&this.add(t),t},t.prototype.getOne=function(e,t){return this.__collection.getOne(this.modelType,e,t).then(this.__addFromResponse.bind(this))},t.prototype.getMany=function(e){return this.__collection.getMany(this.modelType,e).then(this.__addFromResponse.bind(this))},t.prototype.getAll=function(e,t){return void 0===t&&(t=50),a(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:if(t<1)throw new Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(e)];case 1:return[2,d(n.sent(),t)]}}))}))},t.prototype.__addFromResponse=function(e){return e.data&&this.add(e.data),e.views.push(this),e},t}(r);throw new Error("The instance needs to be a model, collection or a view")},exports.modelToJsonApi=S,exports.prepareQuery=C,exports.saveModel=I,exports.saveRelationship=function(n,r,o){var i,a=e.getModelCollection(n),s=R(n,r,"self"),c="object"==typeof s?s.href:s,u=e.getRefId(n,r),l=null===(i=t.getMeta(n,"fields"))||void 0===i?void 0:i[r],p=(null==l?void 0:l.referenceDef)?l.referenceDef.model:null;return _(c,{data:t.mapItems(u,(function(e){return{id:e.id,type:e.type||p}}))},a,o&&o.networkConfig&&o.networkConfig.headers).then(O(n,r))};
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("@datx/core"),t=require("@datx/utils"),n=require("@datx/network"),r=function(e,t){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},r(e,t)};function o(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var i=function(){return i=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},i.apply(this,arguments)};function a(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))}function s(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function c(e,t,n){if(n||2===arguments.length)for(var r,o=0,i=t.length;o<i;o++)!r&&o in t||(r||(r=Array.prototype.slice.call(t,0,o)),r[o]=t[o]);return e.concat(r||Array.prototype.slice.call(t))}var u=/^((https?\:)?\/\/)/,l="undefined"!=typeof window;function d(e){return new Error("[datx exception] ".concat(e))}function p(e){var n=t.getMeta(e,"fields",{},!0,!0),r={};return Object.keys(n).forEach((function(e){n[e].referenceDef&&(r[e]=n[e].referenceDef)})),r}function f(e,t){return void 0===t&&(t=50),a(this,void 0,void 0,(function(){var n,r,o,i;return s(this,(function(a){switch(a.label){case 0:r=[],o=e,i=1,(n=[]).push.apply(n,e.data),r.push(e),a.label=1;case 1:return e.next?++i>t?[3,3]:[4,e.next()]:[3,3];case 2:return e=a.sent(),r.push(e),n.push.apply(n,e.data),[3,1];case 3:return o=r[r.length-1],[2,{data:n,responses:r,lastResponse:o}]}}))}))}var h={baseUrl:"/",cache:l?n.CachingStrategy.CacheFirst:n.CachingStrategy.NetworkOnly,maxCacheAge:1/0,defaultFetchOptions:{headers:{"content-type":"application/vnd.api+json"}},encodeQueryString:!1,sortParams:!1,fetchReference:l&&"fetch"in window&&"function"==typeof window.fetch&&window.fetch.bind(window)||void 0,paramArrayType:n.ParamArrayType.CommaSeparated,baseFetch:function(e,t,n,r,o){var i,a,s,c=this,u=Promise.resolve(),l=e.toUpperCase(),d="GET"!==l&&"HEAD"!==l;return u.then((function(){var o=h.defaultFetchOptions.headers||{},i=Object.assign({},o,r),a=Object.assign({},h.defaultFetchOptions,{body:d&&JSON.stringify(n)||void 0,headers:i,method:e});if(c.fetchReference)return c.fetchReference(t,a);throw new Error("Fetch reference needs to be defined before using the network")})).then((function(e){return a=e.status,s=e.headers,e.json()})).catch((function(e){if(204===a)return null;throw e})).then((function(e){if(i=e,a>=400)throw{message:"Invalid HTTP status: ".concat(a),status:a};return{data:i,headers:s,requestHeaders:r,status:a}})).catch((function(e){return c.onError({data:i,error:e,headers:s,requestHeaders:r,status:a})}))},onError:function(e){return e},transformRequest:function(e){return e},transformResponse:function(e){return e},usePatchWhenPossible:!0};function y(e,t,n){var r,o,i,a;return new((null===(o=null===(r=t.options)||void 0===r?void 0:r.fetchOptions)||void 0===o?void 0:o.Response)||B)({error:new Error(e),requestHeaders:null===(a=null===(i=t.options)||void 0===i?void 0:i.networkConfig)||void 0===a?void 0:a.headers},n,t.options)}function v(n,r,o,i){var a,s;void 0===o&&(o=!1);var c=(null==r?void 0:r.Response)||B;return h.baseFetch(n.method,n.url,n.data,null===(s=null===(a=null==n?void 0:n.options)||void 0===a?void 0:a.networkConfig)||void 0===s?void 0:s.headers,r).then((function(e){var t=Object.assign({},e,{collection:n.collection}),r=h.transformResponse(t);return i?(i.update(r,n.views),i):new c(r,n.collection,n.options,void 0,n.views)})).then((function(r){return o&&function(n,r){if((null==r?void 0:r.isSuccess)&&-1!==r.status&&(r.data||null===r.data)){var o=t.mapItems(r.data||[],e.getModelType);(J=J.filter((function(e){return e.url!==n}))).unshift({response:r.snapshot,collection:r.collection,time:Date.now(),types:[].concat(o),url:n})}}(n.url,r),r}))}function g(e){var t,r,o,i,a,s,c,u,l,d,p,f,g,m,_,b,w,O=(null===(r=null===(t=e.options)||void 0===t?void 0:t.fetchOptions)||void 0===r?void 0:r.Response)||B,j=h.transformRequest(e),k=null===(o=null==j?void 0:j.collection)||void 0===o?void 0:o.constructor,M=k&&k.cache,P="GET"===j.method.toUpperCase(),C=(null===(a=null===(i=e.options)||void 0===i?void 0:i.cacheOptions)||void 0===a?void 0:a.skipCache)||!P?n.CachingStrategy.NetworkOnly:(null===(c=null===(s=e.options)||void 0===s?void 0:s.cacheOptions)||void 0===c?void 0:c.cachingStrategy)||M||h.cache,x=h.maxCacheAge||1/0;if(k&&void 0!==k.maxCacheAge&&(x=k.maxCacheAge),void 0!==(null===(l=null===(u=e.options)||void 0===u?void 0:u.cacheOptions)||void 0===l?void 0:l.maxAge)&&(x=null===(p=null===(d=e.options)||void 0===d?void 0:d.cacheOptions)||void 0===p?void 0:p.maxAge),C===n.CachingStrategy.NetworkOnly)return v(j,null===(f=e.options)||void 0===f?void 0:f.fetchOptions);var T=function(e,t,n){void 0===n&&(n=B);var r=Date.now()-1e3*t,o=J.find((function(t){return t.url===e&&t.time>r}));if(o){var i=o.response;return{response:new n(i.response,o.collection,i.options),time:o.time,types:o.types,url:o.url}}}(j.url,x,O);if(C===n.CachingStrategy.NetworkFirst)return v(j,null===(g=e.options)||void 0===g?void 0:g.fetchOptions,!0).catch((function(e){if(T)return T.response;throw e}));if(C===n.CachingStrategy.StaleWhileRevalidate){var A=v(j,null===(m=e.options)||void 0===m?void 0:m.fetchOptions,!0);return T?(A.catch((function(){})),Promise.resolve(T.response)):A}if(C===n.CachingStrategy.CacheOnly)return T?Promise.resolve(T.response):Promise.reject(y("No cache for this request",e,null==j?void 0:j.collection));if(C===n.CachingStrategy.CacheFirst)return T?Promise.resolve(T.response):v(j,null===(_=e.options)||void 0===_?void 0:_.fetchOptions,!0);if(C===n.CachingStrategy.StaleAndUpdate){var R=null===(b=null==T?void 0:T.response)||void 0===b?void 0:b.clone();return A=v(j,null===(w=e.options)||void 0===w?void 0:w.fetchOptions,!0,R),R?(A.catch((function(){})),Promise.resolve(R)):A}return Promise.reject(y("Invalid caching strategy",e,null==j?void 0:j.collection))}function m(e,t,n,r){return g({collection:t,data:void 0,method:"GET",options:n,url:e,views:r})}function _(e,t,n,r,o){return g({collection:n,data:t,method:"POST",options:r,url:e,views:o})}function b(e,t,n,r,o){return g({collection:n,data:t,method:"PATCH",options:r,url:e,views:o})}function w(e,t,n,r,o){return g({collection:n,data:t,method:"PUT",options:r,url:e,views:o})}function O(e,t,n,r,o){if(void 0===o&&(o=B),e){var i="object"==typeof e?e.href:e;if(i)return m(i,t,n,r)}return Promise.resolve(new o({data:void 0},t))}function j(n,r){return t.mobx.action((function(o){if(o.error)throw o.error;if(204===o.status)return t.setMeta(n,"networkPersisted",!0),n;if(202===o.status){var i=o.data;return t.setMeta(i,"jsonapiProp",r),t.setMeta(i,"jsonapiQueue",!0),t.setMeta(i,"jsonapiRelated",n),i}t.setMeta(n,"networkPersisted",!0);var a=o.replaceData(n).data;return e.commitModel(a),a}))}function k(e,t){void 0===t&&(t="");var r=[];return Object.keys(e).forEach((function(o){e[o]instanceof Array?h.paramArrayType===n.ParamArrayType.CommaSeparated?r.push({key:"".concat(t).concat(o),value:e[o].join(",")}):h.paramArrayType===n.ParamArrayType.MultipleParams?r.push.apply(r,e[o].map((function(e){return{key:"".concat(t).concat(o),value:e}}))):h.paramArrayType===n.ParamArrayType.ParamArray&&r.push.apply(r,e[o].map((function(e){return{key:"".concat(t).concat(o,"]["),value:e}}))):"object"==typeof e[o]?r.push.apply(r,k(e[o],"".concat(o,"."))):r.push({key:"".concat(t).concat(o),value:e[o]})})),r}function M(e){return k(e).map((function(e){return"filter[".concat(e.key,"]=").concat(e.value)}))}function P(e){return encodeURIComponent(e).replace(/%3D/,"=")}function C(e,t,n,r){var o,i,a,s,l,d,p,f,y,v=n&&n.networkConfig&&n.networkConfig.headers||{},g=[].concat(M((null===(o=null==n?void 0:n.queryParams)||void 0===o?void 0:o.filter)||{}),(y=null===(i=null==n?void 0:n.queryParams)||void 0===i?void 0:i.sort)?["sort=".concat(y)]:[],(f=null===(a=null==n?void 0:n.queryParams)||void 0===a?void 0:a.include)?h.sortParams&&Array.isArray(f)?["include=".concat(c([],f,!0).sort())]:["include=".concat(f)]:[],(d=(null===(s=null==n?void 0:n.queryParams)||void 0===s?void 0:s.fields)||{},p=[],Object.keys(d).forEach((function(e){p.push("fields[".concat(e,"]=").concat(d[e]))})),p),function(e){return e.map((function(e){return"string"==typeof e?e:"".concat(e.key,"=").concat(e.value)}))}((null===(l=null==n?void 0:n.queryParams)||void 0===l?void 0:l.custom)||[]));h.encodeQueryString&&(g=g.map(P));var m=function(e,t){var n=e;if(t.length){var r=-1===n.indexOf("?")?"?":"&";n+=r+t.join("&")}return n}(function(e,t){return u.test(e)||t?e:"".concat(h.baseUrl).concat(e)}(e,r),g);return h.sortParams&&(m=function(e){var t=e.split("?"),n=t[0],r=t[1];if(!r)return e;var o=new URLSearchParams(r);o.sort();var i=h.encodeQueryString?o.toString():decodeURIComponent(o.toString());return"".concat(n,"?").concat(i)}(m)),{data:t,headers:v,url:m}}function x(t,n,r,o,i,a){var s=a&&a.constructor;!s&&i&&(s=i.constructor.types.filter((function(e){return e.type===t}))[0]);var c,u=!1;return s?s.endpoint&&"function"==typeof s.endpoint?(u=!0,c=s.endpoint(h.baseUrl)):c=s.endpoint||s.baseUrl||e.getModelType(s):c=t.toString(),C(n?"".concat(c,"/").concat(n):"".concat(c),r,o,u)}function T(n,r){var o,i;if(!r)return null;var a=((o={})[t.META_FIELD]=((i={fields:Object.keys(r.attributes||{}).reduce((function(e,t){return e[t]={referenceDef:!1},e}),{}),id:r.id}).jsonapiLinks=r.links,i.jsonapiMeta=r.meta,i.networkPersisted=Boolean(r.id),i.type=r.type,i),o);if(r.relationships){var s={},c={},u={};Object.keys(r.relationships).forEach((function(t){var o,i=r.relationships[t];i&&"data"in i&&(i.data||null===i.data)&&(!(i.data instanceof Array)||i.data.length>0?(a[t]=i.data,n&&t in n||(u[t]={referenceDef:{model:(i.data instanceof Array?i.data[0].type:null===(o=i.data)||void 0===o?void 0:o.type)||H.type,type:i.data instanceof Array?e.ReferenceType.TO_MANY:e.ReferenceType.TO_ONE}})):a[t]=[]),i&&"links"in i&&(s[t]=i.links),i&&"meta"in i&&(c[t]=i.meta)})),Object.assign(a[t.META_FIELD].fields,u),a[t.META_FIELD].jsonapiRefLinks=s,a[t.META_FIELD].jsonapiRefMeta=c}return Object.assign(a,r.attributes)}function A(e){return t.getMeta(e,"jsonapiLinks",{})}function R(e){return t.getMeta(e,"jsonapiRefLinks",{})}function S(t,n,r){if(!e.getModelCollection(t))throw d("The model needs to be in a collection");var o=R(t);if(!o||!(n in o))throw d("The reference ".concat(n," doesn't have any links"));var i=o[n];if(!i||!(r in i))throw d("Link ".concat(r," doesn't exist on the model"));return i[r]}function E(e){return t.getMeta(e,"networkPersisted",!1)}function I(n,r){var o=n.constructor,i=r?e.modelToDirtyJSON(n):e.modelToJSON(n),a=o.useAutogeneratedIds,s={attributes:i,id:E(n)||a?e.getModelId(n).toString():void 0,type:e.getModelType(n)},c=p(n);return Object.keys(c).forEach((function(r){if(!c[r].property){s.relationships=s.relationships||{};var o=e.getRefId(n,r);s.relationships[r]={data:t.mapItems(o,(function(e){return{id:e.id.toString(),type:e.type}}))},s.attributes&&delete s.attributes[r]}})),s.attributes&&(delete s.attributes.id,delete s.attributes[t.META_FIELD]),s}function q(t,n){return x(e.getModelType(t),E(t)?e.getModelId(t):void 0,void 0,n,void 0,t).url}function L(t,n){var r,o=e.getModelCollection(t),i=null!==(r=null==h?void 0:h.usePatchWhenPossible)&&void 0!==r&&r,a=E(t),s=I(t,i&&a);return(a?i?b:w:_)(q(t,n),{data:s},o,n&&n.networkConfig&&n.networkConfig.headers).then(j(t)).then((function(n){return G(e.getModelType(t)),n}))}function D(n,r){var o=e.getModelCollection(n),i=E(n),a=q(n);return i?function(e,t,n,r){return g({collection:t,data:void 0,method:"DELETE",options:n,url:e,views:void 0})}(a,o,r&&r.networkConfig&&r.networkConfig.headers).then((function(e){if(e.error)throw e.error;!function(e,n){t.setMeta(e,"networkPersisted",!1)}(n),o&&o.__removeModel(n)})):(o&&o.__removeModel(n),Promise.resolve())}var F=["jsonapiLinks","jsonapiMeta","networkPersisted","jsonapiRefLinks","jsonapiRefMeta"];function N(e){return function(n){function r(r,o){void 0===r&&(r={});var i,a=r;r&&"type"in r&&("attributes"in r||"relationships"in r)&&(a=T(p(e),r)),i=n.call(this,a,o)||this;var s=(null==a?void 0:a[t.META_FIELD])||{};return F.forEach((function(e){e in s&&t.setMeta(i,e,s[e])})),i}return o(r,n),r.getAutoId=function(){return n.getAutoId.call(this).toString()},r.prototype.save=function(e){return L(this,e)},r.prototype.destroy=function(e){return D(this,e)},r.useAutogeneratedIds=e.useAutogeneratedIds||!1,r}(e)}var H=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(N(e.PureModel));function U(e){if(e instanceof Array)return e;var t=[];return e.forEach((function(e,n){t.push([n,e])})),t}function Q(t,n,r){if(n&&t.data){var o=r||n.sync(t.data);return new e.Bucket.ToOneOrMany(o,n,!0)}if(t.data){var i=t.data;if(i.data){if(i.data instanceof Array)throw new Error("A save/remove operation should not return an array of results");return{value:r||new H(T(void 0,i.data))}}}return new e.Bucket.ToOneOrMany(null,n,!0)}var B=function(){function n(e,t,n,r,o){var i=this;if(this.__internal={response:{},views:[]},this.__cache={},this.collection=t,this.__updateInternal(e,n,o),this.__data=Q(e,t,r),this.views.forEach((function(e){i.__data.value&&e.add(i.__data.value)})),Object.freeze(this),this.error)throw this}return Object.defineProperty(n.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"headers",{get:function(){return this.__internal.headers},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"requestHeaders",{get:function(){return this.__internal.requestHeaders},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"error",{get:function(){return this.__internal.error},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"status",{get:function(){return this.__internal.status},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"isSuccess",{get:function(){return!this.error},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"data",{get:function(){return this.__data.value},enumerable:!1,configurable:!0}),n.prototype.__updateInternal=function(e,n,r){var o,i,a,s,c,u=this;n&&(this.__internal.options=n),this.__internal.response=e,this.__internal.meta=(null===(o=e.data)||void 0===o?void 0:o.meta)||{},this.__internal.links=(null===(i=e.data)||void 0===i?void 0:i.links)||{},this.__internal.jsonapi=(null===(a=e.data)||void 0===a?void 0:a.jsonapi)||{},this.__internal.headers=e.headers&&((c=e.headers)instanceof Array?new t.Headers(c):c),this.__internal.requestHeaders=e.requestHeaders,this.__internal.error=(null===(s=e.data)||void 0===s?void 0:s.errors)||e.error,this.__internal.status=e.status,r&&(this.__internal.views=r),this.error||this.status||(this.__internal.error=new Error("Network not available")),this.links&&Object.keys(this.links).forEach((function(e){t.assignComputed(u,e,(function(){return u.__fetchLink(e)}))}))},n.prototype.replaceData=function(t){var n,r=this.data;if(r===t)return this;var o=e.getModelId(r).toString(),i=e.getModelType(r),a=this.views.map((function(e){return e.list.indexOf(r)}));this.collection&&(this.collection.removeOne(i,o),this.collection.add(t));var s=e.modelToJSON(r);return null===(n=null==s?void 0:s.__META__)||void 0===n||delete n.collection,e.updateModel(t,s),e.updateModelId(t,o),this.views.forEach((function(e,n){-1!==a[n]&&(e.list[a[n]]=t)})),new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,t)},n.prototype.clone=function(){return new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,this.data||void 0)},Object.defineProperty(n.prototype,"snapshot",{get:function(){return{response:Object.assign({},this.__internal.response,{headers:this.__internal.response.headers&&U(this.__internal.response.headers),collection:void 0}),options:this.__internal.options}},enumerable:!1,configurable:!0}),n.prototype.update=function(e,t){this.__updateInternal(e,void 0,t);var n=Q(e,this.collection);return this.__data.__readonlyValue=n.value,this},n.prototype.__fetchLink=function(e){var t=this,n=this.constructor;if(!this.__cache[e]){var r=this.links&&e in this.links?this.links[e]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[e]=function(){return O(r,t.collection,o,t.views,n)}}}return this.__cache[e]},n}(),J=[];function G(e){J=J.filter((function(t){return!t.types.includes(e)}))}function z(e){if(e.error)throw e.error;return e}function W(e,n){return t.mapItems(e&&e.included||[],n),t.mapItems(e&&e.data||null,n)}var Y,V=function(e){function n(n,r,o,i){var a=e.call(this,n,r,o,i)||this;return a.links&&Object.keys(a.links).forEach((function(e){t.assignComputed(a,e,(function(){return a.__fetchLink(e)}))})),a}return o(n,e),Object.defineProperty(n.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),n.prototype.__fetchLink=function(e){var t=this;if(!this.__cache[e]){var r=this.links&&e in this.links?this.links[e]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[e]=function(){return O(r,t.collection,o,t.views).then((function(e){return new n(e.__internal.response,e.collection,void 0,e.views)}))}}}return this.__cache[e]},n}(n.Response);function K(e,t){return(e&&t.collection?t.collection.sync(e):e)||{}}function X(n){return i(i({},n),{data:{data:t.mapItems(n.data,(function(t){return t instanceof e.PureModel?I(t,!0):t}))||void 0}})}!function(e){e.Asc="",e.Desc="-"}(Y||(Y={}));var Z=function(e){function t(t){var r,o=e.call(this,t)||this;return(r=o)._config.Response=V,n.header("content-type","application/vnd.api+json")(r),n.parser(K)(r),n.serializer(X)(r),n.paramArrayType(n.ParamArrayType.CommaSeparated)(r),n.encodeQueryString(!1)(r),o}return o(t,e),t}(n.BaseRequest);Object.defineProperty(exports,"BaseRequest",{enumerable:!0,get:function(){return n.BaseRequest}}),Object.defineProperty(exports,"CachingStrategy",{enumerable:!0,get:function(){return n.CachingStrategy}}),Object.defineProperty(exports,"HttpMethod",{enumerable:!0,get:function(){return n.HttpMethod}}),Object.defineProperty(exports,"ParamArrayType",{enumerable:!0,get:function(){return n.ParamArrayType}}),Object.defineProperty(exports,"addInterceptor",{enumerable:!0,get:function(){return n.addInterceptor}}),Object.defineProperty(exports,"body",{enumerable:!0,get:function(){return n.body}}),Object.defineProperty(exports,"cache",{enumerable:!0,get:function(){return n.cache}}),Object.defineProperty(exports,"clearAllCache",{enumerable:!0,get:function(){return n.clearAllCache}}),Object.defineProperty(exports,"clearCacheByType",{enumerable:!0,get:function(){return n.clearCacheByType}}),Object.defineProperty(exports,"collection",{enumerable:!0,get:function(){return n.collection}}),Object.defineProperty(exports,"encodeQueryString",{enumerable:!0,get:function(){return n.encodeQueryString}}),Object.defineProperty(exports,"fetchReference",{enumerable:!0,get:function(){return n.fetchReference}}),Object.defineProperty(exports,"header",{enumerable:!0,get:function(){return n.header}}),Object.defineProperty(exports,"method",{enumerable:!0,get:function(){return n.method}}),Object.defineProperty(exports,"paramArrayType",{enumerable:!0,get:function(){return n.paramArrayType}}),Object.defineProperty(exports,"params",{enumerable:!0,get:function(){return n.params}}),Object.defineProperty(exports,"parser",{enumerable:!0,get:function(){return n.parser}}),Object.defineProperty(exports,"query",{enumerable:!0,get:function(){return n.query}}),Object.defineProperty(exports,"serializer",{enumerable:!0,get:function(){return n.serializer}}),Object.defineProperty(exports,"setUrl",{enumerable:!0,get:function(){return n.setUrl}}),exports.BaseJsonapiRequest=Z,exports.GenericModel=H,exports.NetworkResponse=V,exports.Response=B,exports.buildUrl=C,exports.config=h,exports.fetchLink=O,exports.fetchModelLink=function(n,r,o){var i=e.getModelCollection(n),a=A(n);if(!a||!(r in a))throw d("Link ".concat(r," doesn't exist on the model"));var s=O(a[r],i,o);return t.getMeta(n,"jsonapiQueue")?s.then((function(r){var o=t.getMeta(n,"jsonapiRelated"),i=t.getMeta(n,"jsonapiProp"),a=r.data,s=a&&e.getModelType(a);return a&&s!==e.getModelType(n)&&s===e.getModelType(o)?i?(o[i]=a,r):(t.setMeta(o,"networkPersisted",!0),r.replaceData(o)):r})):s},exports.fetchModelRefLink=function(t,n,r,o){var i=e.getModelCollection(t);return O(S(t,n,r),i,o)},exports.getModelEndpointUrl=q,exports.getModelLinks=A,exports.getModelMeta=function(e){return t.getMeta(e,"jsonapiMeta",{})},exports.getModelRefLinks=R,exports.getModelRefMeta=function(e){return t.getMeta(e,"jsonapiRefMeta",{})},exports.isModelPersisted=E,exports.jsonapi=function(r){if(e.isModel(r))return N(r);if(e.isCollection(r))return function(r){function c(e){void 0===e&&(e=[]);var t,n,o=r.call(this,e)||this;return e instanceof Array||!(null==e?void 0:e.cache)||(t=e.cache,n=o,J.push.apply(J,t.map((function(e){return Object.assign({collection:n},e)})))),o}return o(c,r),c.prototype.sync=function(e){var t=this;if(!e)return null;var n=W(e,(function(e){return t.__addRecord(e)}));return W(e,this.__updateRelationships.bind(this)),n},c.prototype.fetch=function(e,r,o){return t.deprecated("fetch is deprecated, use getOne instead"),this.getOne(e,r,Object.assign({},o,{cacheOptions:Object.assign({},(null==o?void 0:o.cacheOptions)||{},{cachingStrategy:l?n.CachingStrategy.CacheFirst:n.CachingStrategy.NetworkOnly})}))},c.prototype.fetchAll=function(e,r){return t.deprecated("fetchAll is deprecated, use getMany instead"),this.getMany(e,Object.assign({},r,{cacheOptions:Object.assign({},(null==r?void 0:r.cacheOptions)||{},{cachingStrategy:l?n.CachingStrategy.CacheFirst:n.CachingStrategy.NetworkOnly})}))},c.prototype.getOne=function(t,n,r){var o=e.getModelType(t),i=this.__prepareQuery(o,n,void 0,r),a=r||{};return a.networkConfig=a.networkConfig||{},a.networkConfig.headers=i.headers,m(i.url,this,a).then(z)},c.prototype.getMany=function(t,n){var r=e.getModelType(t),o=this.__prepareQuery(r,void 0,void 0,n),i=n||{};return i.networkConfig=i.networkConfig||{},i.networkConfig.headers=o.headers,m(o.url,this,i).then(z)},c.prototype.getAll=function(e,t,n){return void 0===n&&(n=50),a(this,void 0,void 0,(function(){return s(this,(function(r){switch(r.label){case 0:if(n<1)throw Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(e,t)];case 1:return[2,f(r.sent(),n)]}}))}))},c.prototype.request=function(e,t,n,r){return void 0===t&&(t="GET"),function(e){return g(e)}({url:C(e,n,r).url,options:r,data:n,method:t,collection:this})},c.prototype.removeOne=function(t,n,r){var o,i,a,s=e.getModelType(t);return"object"==typeof n||void 0===n||"boolean"==typeof n?(o=n,i=e.getModelId(t).toString(),a=t):(o=r,a=(i=e.getModelId(n).toString())?this.findOne(s,i):null),a&&o?D(a,"object"==typeof o?o:void 0):(a&&this.__removeModel(a),G(s),Promise.resolve())},c.prototype.removeAll=function(t){r.prototype.removeAll.call(this,t),G(e.getModelType(t))},c.prototype.reset=function(){r.prototype.reset.call(this),J.length=0},c.prototype.__addRecord=function(t){var n=this.constructor,r=t.type,o=t.id,i=void 0===o?null:this.findOne(r,o),a=T(p(n.types.find((function(t){return e.getModelType(t)===r}))||H),t);return i?(e.upsertModel(a,r,this),e.commitModel(i)):i=n.types.filter((function(e){return e.type===r})).length?this.add(a,r):this.add(new H(a,this)),i},c.prototype.__updateRelationships=function(n){var r=this,o=void 0===n.id?null:this.findOne(n.type,n.id);(n.relationships?Object.keys(n.relationships):[]).forEach((function(i){var a=n.relationships[i];if(a&&"data"in a){var s=a.data;if(!(t.isArrayLike(s)&&s.length<1)&&o)if(s){var c=t.mapItems(s,(function(e){return(void 0===e.id?null:r.findOne(e.type,e.id))||e}))||null,u=t.isArrayLike(s)?s[0].type:s.type;i in o?o[i]=c:e.initModelRef(o,i,{model:u,type:e.ReferenceType.TO_ONE_OR_MANY},c)}else{var l=t.getMeta(o,"refs");l&&i in l&&"__proto__"!==i&&(o[i]=l[i].type===e.ReferenceType.TO_MANY?[]:null)}}}))},c.prototype.__prepareQuery=function(e,t,n,r){return x(e,t,n,r,this)},c.prototype.toJSON=function(){return Object.assign({},r.prototype.toJSON.call(this),{cache:(e=this,J.filter((function(t){return t.collection===e})).map((function(e){return Object.assign({},e,{collection:void 0})})))});var e},c.types=i.types&&i.types.length?i.types.concat(H):[H],c.maxCacheAge=i.maxCacheAge,c.cache=i.cache,c.defaultModel=i.defaultModel||H,c}(i=r);var i;if(e.isView(r))return function(e){function t(t,n,r,o,i){void 0===o&&(o=[]),void 0===i&&(i=!1);var a=e.call(this,t,n,r,o,i)||this;return a.__collection=n,a}return o(t,e),t.prototype.sync=function(e){var t=this.__collection.sync(e);return t&&this.add(t),t},t.prototype.getOne=function(e,t){return this.__collection.getOne(this.modelType,e,t).then(this.__addFromResponse.bind(this))},t.prototype.getMany=function(e){return this.__collection.getMany(this.modelType,e).then(this.__addFromResponse.bind(this))},t.prototype.getAll=function(e,t){return void 0===t&&(t=50),a(this,void 0,void 0,(function(){return s(this,(function(n){switch(n.label){case 0:if(t<1)throw new Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(e)];case 1:return[2,f(n.sent(),t)]}}))}))},t.prototype.__addFromResponse=function(e){return e.data&&this.add(e.data),e.views.push(this),e},t}(r);throw new Error("The instance needs to be a model, collection or a view")},exports.modelToJsonApi=I,exports.prepareQuery=x,exports.saveModel=L,exports.saveRelationship=function(n,r,o){var i,a=e.getModelCollection(n),s=S(n,r,"self"),c="object"==typeof s?s.href:s,u=e.getRefId(n,r),l=null===(i=t.getMeta(n,"fields"))||void 0===i?void 0:i[r],d=(null==l?void 0:l.referenceDef)?l.referenceDef.model:null;return b(c,{data:t.mapItems(u,(function(e){return{id:e.id,type:e.type||d}}))},a,o&&o.networkConfig&&o.networkConfig.headers).then(j(n,r))};
//# sourceMappingURL=index.cjs.js.map

@@ -14,4 +14,5 @@ export { jsonapi } from './mixin';

export { IRequestOptions } from './interfaces/IRequestOptions';
export { IResponse } from './interfaces/JsonApi';
export { config, fetchLink } from './NetworkUtils';
export { IResponseSnapshot } from './interfaces/IResponseSnapshot';
export { IResponse, IRecord, IDefinition } from './interfaces/JsonApi';
export { config, fetchLink, IConfigType } from './NetworkUtils';
export { BaseRequest, addInterceptor, cache, method, setUrl, body, query, header, params, fetchReference, encodeQueryString, paramArrayType, serializer, parser, collection, ParamArrayType, CachingStrategy, HttpMethod, IFetchOptions, IHeaders, IInterceptor, INetworkHandler, IPipeOperator, IResponseObject, clearAllCache, clearCacheByType, } from '@datx/network';

@@ -1,2 +0,2 @@

import{commitModel as e,getModelType as t,getModelCollection as n,modelToDirtyJSON as r,modelToJSON as o,getModelId as i,getRefId as a,ReferenceType as s,PureModel as c,updateModel as u,updateModelId as l,Bucket as f,upsertModel as d,initModelRef as p,isModel as h,isCollection as v,isView as y}from"@datx/core";import{getMeta as _,mobx as g,setMeta as m,mapItems as b,META_FIELD as w,assignComputed as O,Headers as k,deprecated as j,isArrayLike as P}from"@datx/utils";import{CachingStrategy as A,ParamArrayType as C,Response as E,header as R,parser as T,serializer as x,paramArrayType as S,encodeQueryString as q,BaseRequest as M}from"@datx/network";export{BaseRequest,CachingStrategy,HttpMethod,ParamArrayType,addInterceptor,body,cache,clearAllCache,clearCacheByType,collection,encodeQueryString,fetchReference,header,method,paramArrayType,params,parser,query,serializer,setUrl}from"@datx/network";var N=function(e,t){return N=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])},N(e,t)};function D(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Class extends value "+String(t)+" is not a constructor or null");function n(){this.constructor=e}N(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var F=function(){return F=Object.assign||function(e){for(var t,n=1,r=arguments.length;n<r;n++)for(var o in t=arguments[n])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},F.apply(this,arguments)};function H(e,t,n,r){return new(n||(n=Promise))((function(o,i){function a(e){try{c(r.next(e))}catch(e){i(e)}}function s(e){try{c(r.throw(e))}catch(e){i(e)}}function c(e){var t;e.done?o(e.value):(t=e.value,t instanceof n?t:new n((function(e){e(t)}))).then(a,s)}c((r=r.apply(e,t||[])).next())}))}function L(e,t){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=t.call(e,a)}catch(e){i=[6,e],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}var I=/^((https?\:)?\/\/)/,U="undefined"!=typeof window;function Q(e){return new Error("[datx exception] ".concat(e))}function G(e){var t=_(e,"fields",{},!0,!0),n={};return Object.keys(t).forEach((function(e){t[e].referenceDef&&(n[e]=t[e].referenceDef)})),n}function B(e,t){return void 0===t&&(t=50),H(this,void 0,void 0,(function(){var n,r,o,i;return L(this,(function(a){switch(a.label){case 0:r=[],o=e,i=1,(n=[]).push.apply(n,e.data),r.push(e),a.label=1;case 1:return e.next?++i>t?[3,3]:[4,e.next()]:[3,3];case 2:return e=a.sent(),r.push(e),n.push.apply(n,e.data),[3,1];case 3:return o=r[r.length-1],[2,{data:n,responses:r,lastResponse:o}]}}))}))}var J={baseUrl:"/",cache:U?A.CacheFirst:A.NetworkOnly,maxCacheAge:1/0,defaultFetchOptions:{headers:{"content-type":"application/vnd.api+json"}},encodeQueryString:!1,fetchReference:U&&"fetch"in window&&"function"==typeof window.fetch&&window.fetch.bind(window)||void 0,paramArrayType:C.CommaSeparated,baseFetch:function(e,t,n,r,o){var i,a,s,c=this,u=Promise.resolve(),l=e.toUpperCase(),f="GET"!==l&&"HEAD"!==l;return u.then((function(){var o=J.defaultFetchOptions.headers||{},i=Object.assign({},o,r),a=Object.assign({},J.defaultFetchOptions,{body:f&&JSON.stringify(n)||void 0,headers:i,method:e});if(c.fetchReference)return c.fetchReference(t,a);throw new Error("Fetch reference needs to be defined before using the network")})).then((function(e){return a=e.status,s=e.headers,e.json()})).catch((function(e){if(204===a)return null;throw e})).then((function(e){if(i=e,a>=400)throw{message:"Invalid HTTP status: ".concat(a),status:a};return{data:i,headers:s,requestHeaders:r,status:a}})).catch((function(e){return c.onError({data:i,error:e,headers:s,requestHeaders:r,status:a})}))},onError:function(e){return e},transformRequest:function(e){return e},transformResponse:function(e){return e},usePatchWhenPossible:!0};function W(e,t,n){var r,o,i,a;return new((null===(o=null===(r=t.options)||void 0===r?void 0:r.fetchOptions)||void 0===o?void 0:o.Response)||Pe)({error:new Error(e),requestHeaders:null===(a=null===(i=t.options)||void 0===i?void 0:i.networkConfig)||void 0===a?void 0:a.headers},n,t.options)}function Y(e,n,r,o){var i,a;void 0===r&&(r=!1);var s=(null==n?void 0:n.Response)||Pe;return J.baseFetch(e.method,e.url,e.data,null===(a=null===(i=null==e?void 0:e.options)||void 0===i?void 0:i.networkConfig)||void 0===a?void 0:a.headers,n).then((function(t){var n=Object.assign({},t,{collection:e.collection}),r=J.transformResponse(n);return o?(o.update(r,e.views),o):new s(r,e.collection,e.options,void 0,e.views)})).then((function(n){return r&&function(e,n){if((null==n?void 0:n.isSuccess)&&-1!==n.status&&(n.data||null===n.data)){var r=b(n.data||[],t);(Ae=Ae.filter((function(t){return t.url!==e}))).unshift({response:n.snapshot,collection:n.collection,time:Date.now(),types:[].concat(r),url:e})}}(e.url,n),n}))}function z(e){var t,n,r,o,i,a,s,c,u,l,f,d,p,h,v,y,_,g=(null===(n=null===(t=e.options)||void 0===t?void 0:t.fetchOptions)||void 0===n?void 0:n.Response)||Pe,m=J.transformRequest(e),b=null===(r=null==m?void 0:m.collection)||void 0===r?void 0:r.constructor,w=b&&b.cache,O="GET"===m.method.toUpperCase(),k=(null===(i=null===(o=e.options)||void 0===o?void 0:o.cacheOptions)||void 0===i?void 0:i.skipCache)||!O?A.NetworkOnly:(null===(s=null===(a=e.options)||void 0===a?void 0:a.cacheOptions)||void 0===s?void 0:s.cachingStrategy)||w||J.cache,j=J.maxCacheAge||1/0;if(b&&void 0!==b.maxCacheAge&&(j=b.maxCacheAge),void 0!==(null===(u=null===(c=e.options)||void 0===c?void 0:c.cacheOptions)||void 0===u?void 0:u.maxAge)&&(j=null===(f=null===(l=e.options)||void 0===l?void 0:l.cacheOptions)||void 0===f?void 0:f.maxAge),k===A.NetworkOnly)return Y(m,null===(d=e.options)||void 0===d?void 0:d.fetchOptions);var P=function(e,t,n){void 0===n&&(n=Pe);var r=Date.now()-1e3*t,o=Ae.find((function(t){return t.url===e&&t.time>r}));if(o){var i=o.response;return{response:new n(i.response,o.collection,i.options),time:o.time,types:o.types,url:o.url}}}(m.url,j,g);if(k===A.NetworkFirst)return Y(m,null===(p=e.options)||void 0===p?void 0:p.fetchOptions,!0).catch((function(e){if(P)return P.response;throw e}));if(k===A.StaleWhileRevalidate){var C=Y(m,null===(h=e.options)||void 0===h?void 0:h.fetchOptions,!0);return P?(C.catch((function(){})),Promise.resolve(P.response)):C}if(k===A.CacheOnly)return P?Promise.resolve(P.response):Promise.reject(W("No cache for this request",e,null==m?void 0:m.collection));if(k===A.CacheFirst)return P?Promise.resolve(P.response):Y(m,null===(v=e.options)||void 0===v?void 0:v.fetchOptions,!0);if(k===A.StaleAndUpdate){var E=null===(y=null==P?void 0:P.response)||void 0===y?void 0:y.clone();return C=Y(m,null===(_=e.options)||void 0===_?void 0:_.fetchOptions,!0,E),E?(C.catch((function(){})),Promise.resolve(E)):C}return Promise.reject(W("Invalid caching strategy",e,null==m?void 0:m.collection))}function V(e,t,n,r){return z({collection:t,data:void 0,method:"GET",options:n,url:e,views:r})}function K(e,t,n,r,o){return z({collection:n,data:t,method:"POST",options:r,url:e,views:o})}function X(e,t,n,r,o){return z({collection:n,data:t,method:"PATCH",options:r,url:e,views:o})}function Z(e,t,n,r,o){return z({collection:n,data:t,method:"PUT",options:r,url:e,views:o})}function $(e,t,n,r,o){if(void 0===o&&(o=Pe),e){var i="object"==typeof e?e.href:e;if(i)return V(i,t,n,r)}return Promise.resolve(new o({data:void 0},t))}function ee(t,n){return g.action((function(r){if(r.error)throw r.error;if(204===r.status)return m(t,"networkPersisted",!0),t;if(202===r.status){var o=r.data;return m(o,"jsonapiProp",n),m(o,"jsonapiQueue",!0),m(o,"jsonapiRelated",t),o}m(t,"networkPersisted",!0);var i=r.replaceData(t).data;return e(i),i}))}function te(e,t){void 0===t&&(t="");var n=[];return Object.keys(e).forEach((function(r){e[r]instanceof Array?J.paramArrayType===C.CommaSeparated?n.push({key:"".concat(t).concat(r),value:e[r].join(",")}):J.paramArrayType===C.MultipleParams?n.push.apply(n,e[r].map((function(e){return{key:"".concat(t).concat(r),value:e}}))):J.paramArrayType===C.ParamArray&&n.push.apply(n,e[r].map((function(e){return{key:"".concat(t).concat(r,"]["),value:e}}))):"object"==typeof e[r]?n.push.apply(n,te(e[r],"".concat(r,"."))):n.push({key:"".concat(t).concat(r),value:e[r]})})),n}function ne(e){return te(e).map((function(e){return"filter[".concat(e.key,"]=").concat(e.value)}))}function re(e){return encodeURIComponent(e).replace(/%3D/,"=")}function oe(e,t,n,r){var o,i,a,s,c=n&&n.networkConfig&&n.networkConfig.headers||{},u=[].concat(ne(n&&n.queryParams&&n.queryParams.filter||{}),(s=n&&n.queryParams&&n.queryParams.sort)?["sort=".concat(s)]:[],(a=n&&n.queryParams&&n.queryParams.include)?["include=".concat(a)]:[],(o=n&&n.queryParams&&n.queryParams.fields||{},i=[],Object.keys(o).forEach((function(e){i.push("fields[".concat(e,"]=").concat(o[e]))})),i),function(e){return e.map((function(e){return"string"==typeof e?e:"".concat(e.key,"=").concat(e.value)}))}(n&&n.queryParams&&n.queryParams.custom||[]));J.encodeQueryString&&(u=u.map(re));var l=function(e,t){var n=e;if(t.length){var r=-1===n.indexOf("?")?"?":"&";n+=r+t.join("&")}return n}(function(e,t){return I.test(e)||t?e:"".concat(J.baseUrl).concat(e)}(e,r),u);return{data:t,headers:c,url:l}}function ie(e,n,r,o,i,a){var s=a&&a.constructor;!s&&i&&(s=i.constructor.types.filter((function(t){return t.type===e}))[0]);var c,u=!1;return s?s.endpoint&&"function"==typeof s.endpoint?(u=!0,c=s.endpoint(J.baseUrl)):c=s.endpoint||s.baseUrl||t(s):c=e.toString(),oe(n?"".concat(c,"/").concat(n):"".concat(c),r,o,u)}function ae(e,t){var n,r;if(!t)return null;var o=((n={})[w]=((r={fields:Object.keys(t.attributes||{}).reduce((function(e,t){return e[t]={referenceDef:!1},e}),{}),id:t.id}).jsonapiLinks=t.links,r.jsonapiMeta=t.meta,r.networkPersisted=Boolean(t.id),r.type=t.type,r),n);if(t.relationships){var i={},a={},c={};Object.keys(t.relationships).forEach((function(n){var r,u=t.relationships[n];u&&"data"in u&&(u.data||null===u.data)&&(!(u.data instanceof Array)||u.data.length>0?(o[n]=u.data,e&&n in e||(c[n]={referenceDef:{model:(u.data instanceof Array?u.data[0].type:null===(r=u.data)||void 0===r?void 0:r.type)||Oe.type,type:u.data instanceof Array?s.TO_MANY:s.TO_ONE}})):o[n]=[]),u&&"links"in u&&(i[n]=u.links),u&&"meta"in u&&(a[n]=u.meta)})),Object.assign(o[w].fields,c),o[w].jsonapiRefLinks=i,o[w].jsonapiRefMeta=a}return Object.assign(o,t.attributes)}function se(e){return _(e,"jsonapiMeta",{})}function ce(e){return _(e,"jsonapiLinks",{})}function ue(e,r,o){var i=n(e),a=ce(e);if(!a||!(r in a))throw Q("Link ".concat(r," doesn't exist on the model"));var s=$(a[r],i,o);return _(e,"jsonapiQueue")?s.then((function(n){var r=_(e,"jsonapiRelated"),o=_(e,"jsonapiProp"),i=n.data,a=i&&t(i);return i&&a!==t(e)&&a===t(r)?o?(r[o]=i,n):(m(r,"networkPersisted",!0),n.replaceData(r)):n})):s}function le(e){return _(e,"jsonapiRefLinks",{})}function fe(e,t,r){if(!n(e))throw Q("The model needs to be in a collection");var o=le(e);if(!o||!(t in o))throw Q("The reference ".concat(t," doesn't have any links"));var i=o[t];if(!i||!(r in i))throw Q("Link ".concat(r," doesn't exist on the model"));return i[r]}function de(e,t,r,o){var i=n(e);return $(fe(e,t,r),i,o)}function pe(e){return _(e,"jsonapiRefMeta",{})}function he(e){return _(e,"networkPersisted",!1)}function ve(e,n){var s=e.constructor,c=n?r(e):o(e),u=s.useAutogeneratedIds,l={attributes:c,id:he(e)||u?i(e).toString():void 0,type:t(e)},f=G(e);return Object.keys(f).forEach((function(t){if(!f[t].property){l.relationships=l.relationships||{};var n=a(e,t);l.relationships[t]={data:b(n,(function(e){return{id:e.id.toString(),type:e.type}}))},l.attributes&&delete l.attributes[t]}})),l.attributes&&(delete l.attributes.id,delete l.attributes[w]),l}function ye(e,n){return ie(t(e),he(e)?i(e):void 0,void 0,n,void 0,e).url}function _e(e,r){var o,i=n(e),a=null!==(o=null==J?void 0:J.usePatchWhenPossible)&&void 0!==o&&o,s=he(e),c=ve(e,a&&s);return(s?a?X:Z:K)(ye(e,r),{data:c},i,r&&r.networkConfig&&r.networkConfig.headers).then(ee(e)).then((function(n){return Ce(t(e)),n}))}function ge(e,t){var r=n(e),o=he(e),i=ye(e);return o?function(e,t,n,r){return z({collection:t,data:void 0,method:"DELETE",options:n,url:e,views:void 0})}(i,r,t&&t.networkConfig&&t.networkConfig.headers).then((function(t){if(t.error)throw t.error;!function(e,t){m(e,"networkPersisted",!1)}(e),r&&r.__removeModel(e)})):(r&&r.__removeModel(e),Promise.resolve())}function me(e,t,r){var o,i=n(e),s=fe(e,t,"self"),c="object"==typeof s?s.href:s,u=a(e,t),l=null===(o=_(e,"fields"))||void 0===o?void 0:o[t],f=(null==l?void 0:l.referenceDef)?l.referenceDef.model:null;return X(c,{data:b(u,(function(e){return{id:e.id,type:e.type||f}}))},i,r&&r.networkConfig&&r.networkConfig.headers).then(ee(e,t))}var be=["jsonapiLinks","jsonapiMeta","networkPersisted","jsonapiRefLinks","jsonapiRefMeta"];function we(e){return function(t){function n(n,r){void 0===n&&(n={});var o,i=n;n&&"type"in n&&("attributes"in n||"relationships"in n)&&(i=ae(G(e),n)),o=t.call(this,i,r)||this;var a=(null==i?void 0:i[w])||{};return be.forEach((function(e){e in a&&m(o,e,a[e])})),o}return D(n,t),n.getAutoId=function(){return t.getAutoId.call(this).toString()},n.prototype.save=function(e){return _e(this,e)},n.prototype.destroy=function(e){return ge(this,e)},n.useAutogeneratedIds=e.useAutogeneratedIds||!1,n}(e)}var Oe=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return D(t,e),t}(we(c));function ke(e){if(e instanceof Array)return e;var t=[];return e.forEach((function(e,n){t.push([n,e])})),t}function je(e,t,n){if(t&&e.data){var r=n||t.sync(e.data);return new f.ToOneOrMany(r,t,!0)}if(e.data){var o=e.data;if(o.data){if(o.data instanceof Array)throw new Error("A save/remove operation should not return an array of results");return{value:n||new Oe(ae(void 0,o.data))}}}return new f.ToOneOrMany(null,t,!0)}var Pe=function(){function e(e,t,n,r,o){var i=this;if(this.__internal={response:{},views:[]},this.__cache={},this.collection=t,this.__updateInternal(e,n,o),this.__data=je(e,t,r),this.views.forEach((function(e){i.__data.value&&e.add(i.__data.value)})),Object.freeze(this),this.error)throw this}return Object.defineProperty(e.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"headers",{get:function(){return this.__internal.headers},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"requestHeaders",{get:function(){return this.__internal.requestHeaders},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"error",{get:function(){return this.__internal.error},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"status",{get:function(){return this.__internal.status},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"isSuccess",{get:function(){return!this.error},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"data",{get:function(){return this.__data.value},enumerable:!1,configurable:!0}),e.prototype.__updateInternal=function(e,t,n){var r,o,i,a,s,c=this;t&&(this.__internal.options=t),this.__internal.response=e,this.__internal.meta=(null===(r=e.data)||void 0===r?void 0:r.meta)||{},this.__internal.links=(null===(o=e.data)||void 0===o?void 0:o.links)||{},this.__internal.jsonapi=(null===(i=e.data)||void 0===i?void 0:i.jsonapi)||{},this.__internal.headers=e.headers&&((s=e.headers)instanceof Array?new k(s):s),this.__internal.requestHeaders=e.requestHeaders,this.__internal.error=(null===(a=e.data)||void 0===a?void 0:a.errors)||e.error,this.__internal.status=e.status,n&&(this.__internal.views=n),this.error||this.status||(this.__internal.error=new Error("Network not available")),this.links&&Object.keys(this.links).forEach((function(e){O(c,e,(function(){return c.__fetchLink(e)}))}))},e.prototype.replaceData=function(e){var n,r=this.data;if(r===e)return this;var a=i(r).toString(),s=t(r),c=this.views.map((function(e){return e.list.indexOf(r)}));this.collection&&(this.collection.removeOne(s,a),this.collection.add(e));var f=o(r);return null===(n=null==f?void 0:f.__META__)||void 0===n||delete n.collection,u(e,f),l(e,a),this.views.forEach((function(t,n){-1!==c[n]&&(t.list[c[n]]=e)})),new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,e)},e.prototype.clone=function(){return new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,this.data||void 0)},Object.defineProperty(e.prototype,"snapshot",{get:function(){return{response:Object.assign({},this.__internal.response,{headers:this.__internal.response.headers&&ke(this.__internal.response.headers),collection:void 0}),options:this.__internal.options}},enumerable:!1,configurable:!0}),e.prototype.update=function(e,t){this.__updateInternal(e,void 0,t);var n=je(e,this.collection);return this.__data.__readonlyValue=n.value,this},e.prototype.__fetchLink=function(e){var t=this,n=this.constructor;if(!this.__cache[e]){var r=this.links&&e in this.links?this.links[e]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[e]=function(){return $(r,t.collection,o,t.views,n)}}}return this.__cache[e]},e}(),Ae=[];function Ce(e){Ae=Ae.filter((function(t){return!t.types.includes(e)}))}function Ee(e){return Ae.filter((function(t){return t.collection===e})).map((function(e){return Object.assign({},e,{collection:void 0})}))}function Re(e){if(e.error)throw e.error;return e}function Te(e,t){return b(e&&e.included||[],t),b(e&&e.data||null,t)}function xe(n){if(h(n))return we(n);if(v(n))return function(n){function o(e){void 0===e&&(e=[]);var t=n.call(this,e)||this;return e instanceof Array||!(null==e?void 0:e.cache)||function(e,t){Ae.push.apply(Ae,e.map((function(e){return Object.assign({collection:t},e)})))}(e.cache,t),t}return D(o,n),o.prototype.sync=function(e){var t=this;if(!e)return null;var n=Te(e,(function(e){return t.__addRecord(e)}));return Te(e,this.__updateRelationships.bind(this)),n},o.prototype.fetch=function(e,t,n){return j("fetch is deprecated, use getOne instead"),this.getOne(e,t,Object.assign({},n,{cacheOptions:Object.assign({},(null==n?void 0:n.cacheOptions)||{},{cachingStrategy:U?A.CacheFirst:A.NetworkOnly})}))},o.prototype.fetchAll=function(e,t){return j("fetchAll is deprecated, use getMany instead"),this.getMany(e,Object.assign({},t,{cacheOptions:Object.assign({},(null==t?void 0:t.cacheOptions)||{},{cachingStrategy:U?A.CacheFirst:A.NetworkOnly})}))},o.prototype.getOne=function(e,n,r){var o=t(e),i=this.__prepareQuery(o,n,void 0,r),a=r||{};return a.networkConfig=a.networkConfig||{},a.networkConfig.headers=i.headers,V(i.url,this,a).then(Re)},o.prototype.getMany=function(e,n){var r=t(e),o=this.__prepareQuery(r,void 0,void 0,n),i=n||{};return i.networkConfig=i.networkConfig||{},i.networkConfig.headers=o.headers,V(o.url,this,i).then(Re)},o.prototype.getAll=function(e,t,n){return void 0===n&&(n=50),H(this,void 0,void 0,(function(){return L(this,(function(r){switch(r.label){case 0:if(n<1)throw Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(e,t)];case 1:return[2,B(r.sent(),n)]}}))}))},o.prototype.request=function(e,t,n,r){return void 0===t&&(t="GET"),function(e){return z(e)}({url:oe(e,n,r).url,options:r,data:n,method:t,collection:this})},o.prototype.removeOne=function(e,n,r){var o,a,s,c=t(e);return"object"==typeof n||void 0===n||"boolean"==typeof n?(o=n,a=i(e).toString(),s=e):(o=r,s=(a=i(n).toString())?this.findOne(c,a):null),s&&o?ge(s,"object"==typeof o?o:void 0):(s&&this.__removeModel(s),Ce(c),Promise.resolve())},o.prototype.removeAll=function(e){n.prototype.removeAll.call(this,e),Ce(t(e))},o.prototype.reset=function(){n.prototype.reset.call(this),Ae.length=0},o.prototype.__addRecord=function(n){var r=this.constructor,o=n.type,i=n.id,a=void 0===i?null:this.findOne(o,i),s=ae(G(r.types.find((function(e){return t(e)===o}))||Oe),n);return a?(d(s,o,this),e(a)):a=r.types.filter((function(e){return e.type===o})).length?this.add(s,o):this.add(new Oe(s,this)),a},o.prototype.__updateRelationships=function(e){var t=this,n=void 0===e.id?null:this.findOne(e.type,e.id);(e.relationships?Object.keys(e.relationships):[]).forEach((function(r){var o=e.relationships[r];if(o&&"data"in o){var i=o.data;if(!(P(i)&&i.length<1)&&n)if(i){var a=b(i,(function(e){return(void 0===e.id?null:t.findOne(e.type,e.id))||e}))||null,c=P(i)?i[0].type:i.type;r in n?n[r]=a:p(n,r,{model:c,type:s.TO_ONE_OR_MANY},a)}else{var u=_(n,"refs");u&&r in u&&"__proto__"!==r&&(n[r]=u[r].type===s.TO_MANY?[]:null)}}}))},o.prototype.__prepareQuery=function(e,t,n,r){return ie(e,t,n,r,this)},o.prototype.toJSON=function(){return Object.assign({},n.prototype.toJSON.call(this),{cache:Ee(this)})},o.types=r.types&&r.types.length?r.types.concat(Oe):[Oe],o.maxCacheAge=r.maxCacheAge,o.cache=r.cache,o.defaultModel=r.defaultModel||Oe,o}(r=n);var r;if(y(n))return function(e){function t(t,n,r,o,i){void 0===o&&(o=[]),void 0===i&&(i=!1);var a=e.call(this,t,n,r,o,i)||this;return a.__collection=n,a}return D(t,e),t.prototype.sync=function(e){var t=this.__collection.sync(e);return t&&this.add(t),t},t.prototype.getOne=function(e,t){return this.__collection.getOne(this.modelType,e,t).then(this.__addFromResponse.bind(this))},t.prototype.getMany=function(e){return this.__collection.getMany(this.modelType,e).then(this.__addFromResponse.bind(this))},t.prototype.getAll=function(e,t){return void 0===t&&(t=50),H(this,void 0,void 0,(function(){return L(this,(function(n){switch(n.label){case 0:if(t<1)throw new Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(e)];case 1:return[2,B(n.sent(),t)]}}))}))},t.prototype.__addFromResponse=function(e){return e.data&&this.add(e.data),e.views.push(this),e},t}(n);throw new Error("The instance needs to be a model, collection or a view")}var Se,qe=function(e){function t(t,n,r,o){var i=e.call(this,t,n,r,o)||this;return i.links&&Object.keys(i.links).forEach((function(e){O(i,e,(function(){return i.__fetchLink(e)}))})),i}return D(t,e),Object.defineProperty(t.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),t.prototype.__fetchLink=function(e){var n=this;if(!this.__cache[e]){var r=this.links&&e in this.links?this.links[e]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[e]=function(){return $(r,n.collection,o,n.views).then((function(e){return new t(e.__internal.response,e.collection,void 0,e.views)}))}}}return this.__cache[e]},t}(E);function Me(e,t){return(e&&t.collection?t.collection.sync(e):e)||{}}function Ne(e){return F(F({},e),{data:{data:b(e.data,(function(e){return e instanceof c?ve(e,!0):e}))||void 0}})}!function(e){e.Asc="",e.Desc="-"}(Se||(Se={}));var De=function(e){function t(t){var n,r=e.call(this,t)||this;return(n=r)._config.Response=qe,R("content-type","application/vnd.api+json")(n),T(Me)(n),x(Ne)(n),S(C.CommaSeparated)(n),q(!1)(n),r}return D(t,e),t}(M);export{De as BaseJsonapiRequest,Oe as GenericModel,qe as NetworkResponse,Pe as Response,oe as buildUrl,J as config,$ as fetchLink,ue as fetchModelLink,de as fetchModelRefLink,ye as getModelEndpointUrl,ce as getModelLinks,se as getModelMeta,le as getModelRefLinks,pe as getModelRefMeta,he as isModelPersisted,xe as jsonapi,ve as modelToJsonApi,ie as prepareQuery,_e as saveModel,me as saveRelationship};
import{commitModel as t,getModelType as e,getModelCollection as n,modelToDirtyJSON as r,modelToJSON as o,getModelId as i,getRefId as a,ReferenceType as s,PureModel as c,updateModel as u,updateModelId as l,Bucket as f,upsertModel as d,initModelRef as p,isModel as h,isCollection as v,isView as y}from"@datx/core";import{getMeta as _,mobx as g,setMeta as m,mapItems as b,META_FIELD as w,assignComputed as O,Headers as k,deprecated as j,isArrayLike as P}from"@datx/utils";import{CachingStrategy as A,ParamArrayType as C,Response as E,header as R,parser as S,serializer as T,paramArrayType as x,encodeQueryString as M,BaseRequest as q}from"@datx/network";export{BaseRequest,CachingStrategy,HttpMethod,ParamArrayType,addInterceptor,body,cache,clearAllCache,clearCacheByType,collection,encodeQueryString,fetchReference,header,method,paramArrayType,params,parser,query,serializer,setUrl}from"@datx/network";var N=function(t,e){return N=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},N(t,e)};function D(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function n(){this.constructor=t}N(t,e),t.prototype=null===e?Object.create(e):(n.prototype=e.prototype,new n)}var F=function(){return F=Object.assign||function(t){for(var e,n=1,r=arguments.length;n<r;n++)for(var o in e=arguments[n])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},F.apply(this,arguments)};function L(t,e,n,r){return new(n||(n=Promise))((function(o,i){function a(t){try{c(r.next(t))}catch(t){i(t)}}function s(t){try{c(r.throw(t))}catch(t){i(t)}}function c(t){var e;t.done?o(t.value):(e=t.value,e instanceof n?e:new n((function(t){t(e)}))).then(a,s)}c((r=r.apply(t,e||[])).next())}))}function H(t,e){var n,r,o,i,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return i={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(i[Symbol.iterator]=function(){return this}),i;function s(i){return function(s){return function(i){if(n)throw new TypeError("Generator is already executing.");for(;a;)try{if(n=1,r&&(o=2&i[0]?r.return:i[0]?r.throw||((o=r.return)&&o.call(r),0):r.next)&&!(o=o.call(r,i[1])).done)return o;switch(r=0,o&&(i=[2&i[0],o.value]),i[0]){case 0:case 1:o=i;break;case 4:return a.label++,{value:i[1],done:!1};case 5:a.label++,r=i[1],i=[0];continue;case 7:i=a.ops.pop(),a.trys.pop();continue;default:if(!((o=(o=a.trys).length>0&&o[o.length-1])||6!==i[0]&&2!==i[0])){a=0;continue}if(3===i[0]&&(!o||i[1]>o[0]&&i[1]<o[3])){a.label=i[1];break}if(6===i[0]&&a.label<o[1]){a.label=o[1],o=i;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(i);break}o[2]&&a.ops.pop(),a.trys.pop();continue}i=e.call(t,a)}catch(t){i=[6,t],r=0}finally{n=o=0}if(5&i[0])throw i[1];return{value:i[0]?i[1]:void 0,done:!0}}([i,s])}}}function I(t,e,n){if(n||2===arguments.length)for(var r,o=0,i=e.length;o<i;o++)!r&&o in e||(r||(r=Array.prototype.slice.call(e,0,o)),r[o]=e[o]);return t.concat(r||Array.prototype.slice.call(e))}var U=/^((https?\:)?\/\/)/,Q="undefined"!=typeof window;function G(t){return new Error("[datx exception] ".concat(t))}function B(t){var e=_(t,"fields",{},!0,!0),n={};return Object.keys(e).forEach((function(t){e[t].referenceDef&&(n[t]=e[t].referenceDef)})),n}function J(t,e){return void 0===e&&(e=50),L(this,void 0,void 0,(function(){var n,r,o,i;return H(this,(function(a){switch(a.label){case 0:r=[],o=t,i=1,(n=[]).push.apply(n,t.data),r.push(t),a.label=1;case 1:return t.next?++i>e?[3,3]:[4,t.next()]:[3,3];case 2:return t=a.sent(),r.push(t),n.push.apply(n,t.data),[3,1];case 3:return o=r[r.length-1],[2,{data:n,responses:r,lastResponse:o}]}}))}))}var W={baseUrl:"/",cache:Q?A.CacheFirst:A.NetworkOnly,maxCacheAge:1/0,defaultFetchOptions:{headers:{"content-type":"application/vnd.api+json"}},encodeQueryString:!1,sortParams:!1,fetchReference:Q&&"fetch"in window&&"function"==typeof window.fetch&&window.fetch.bind(window)||void 0,paramArrayType:C.CommaSeparated,baseFetch:function(t,e,n,r,o){var i,a,s,c=this,u=Promise.resolve(),l=t.toUpperCase(),f="GET"!==l&&"HEAD"!==l;return u.then((function(){var o=W.defaultFetchOptions.headers||{},i=Object.assign({},o,r),a=Object.assign({},W.defaultFetchOptions,{body:f&&JSON.stringify(n)||void 0,headers:i,method:t});if(c.fetchReference)return c.fetchReference(e,a);throw new Error("Fetch reference needs to be defined before using the network")})).then((function(t){return a=t.status,s=t.headers,t.json()})).catch((function(t){if(204===a)return null;throw t})).then((function(t){if(i=t,a>=400)throw{message:"Invalid HTTP status: ".concat(a),status:a};return{data:i,headers:s,requestHeaders:r,status:a}})).catch((function(t){return c.onError({data:i,error:t,headers:s,requestHeaders:r,status:a})}))},onError:function(t){return t},transformRequest:function(t){return t},transformResponse:function(t){return t},usePatchWhenPossible:!0};function Y(t,e,n){var r,o,i,a;return new((null===(o=null===(r=e.options)||void 0===r?void 0:r.fetchOptions)||void 0===o?void 0:o.Response)||At)({error:new Error(t),requestHeaders:null===(a=null===(i=e.options)||void 0===i?void 0:i.networkConfig)||void 0===a?void 0:a.headers},n,e.options)}function z(t,n,r,o){var i,a;void 0===r&&(r=!1);var s=(null==n?void 0:n.Response)||At;return W.baseFetch(t.method,t.url,t.data,null===(a=null===(i=null==t?void 0:t.options)||void 0===i?void 0:i.networkConfig)||void 0===a?void 0:a.headers,n).then((function(e){var n=Object.assign({},e,{collection:t.collection}),r=W.transformResponse(n);return o?(o.update(r,t.views),o):new s(r,t.collection,t.options,void 0,t.views)})).then((function(n){return r&&function(t,n){if((null==n?void 0:n.isSuccess)&&-1!==n.status&&(n.data||null===n.data)){var r=b(n.data||[],e);(Ct=Ct.filter((function(e){return e.url!==t}))).unshift({response:n.snapshot,collection:n.collection,time:Date.now(),types:[].concat(r),url:t})}}(t.url,n),n}))}function V(t){var e,n,r,o,i,a,s,c,u,l,f,d,p,h,v,y,_,g=(null===(n=null===(e=t.options)||void 0===e?void 0:e.fetchOptions)||void 0===n?void 0:n.Response)||At,m=W.transformRequest(t),b=null===(r=null==m?void 0:m.collection)||void 0===r?void 0:r.constructor,w=b&&b.cache,O="GET"===m.method.toUpperCase(),k=(null===(i=null===(o=t.options)||void 0===o?void 0:o.cacheOptions)||void 0===i?void 0:i.skipCache)||!O?A.NetworkOnly:(null===(s=null===(a=t.options)||void 0===a?void 0:a.cacheOptions)||void 0===s?void 0:s.cachingStrategy)||w||W.cache,j=W.maxCacheAge||1/0;if(b&&void 0!==b.maxCacheAge&&(j=b.maxCacheAge),void 0!==(null===(u=null===(c=t.options)||void 0===c?void 0:c.cacheOptions)||void 0===u?void 0:u.maxAge)&&(j=null===(f=null===(l=t.options)||void 0===l?void 0:l.cacheOptions)||void 0===f?void 0:f.maxAge),k===A.NetworkOnly)return z(m,null===(d=t.options)||void 0===d?void 0:d.fetchOptions);var P=function(t,e,n){void 0===n&&(n=At);var r=Date.now()-1e3*e,o=Ct.find((function(e){return e.url===t&&e.time>r}));if(o){var i=o.response;return{response:new n(i.response,o.collection,i.options),time:o.time,types:o.types,url:o.url}}}(m.url,j,g);if(k===A.NetworkFirst)return z(m,null===(p=t.options)||void 0===p?void 0:p.fetchOptions,!0).catch((function(t){if(P)return P.response;throw t}));if(k===A.StaleWhileRevalidate){var C=z(m,null===(h=t.options)||void 0===h?void 0:h.fetchOptions,!0);return P?(C.catch((function(){})),Promise.resolve(P.response)):C}if(k===A.CacheOnly)return P?Promise.resolve(P.response):Promise.reject(Y("No cache for this request",t,null==m?void 0:m.collection));if(k===A.CacheFirst)return P?Promise.resolve(P.response):z(m,null===(v=t.options)||void 0===v?void 0:v.fetchOptions,!0);if(k===A.StaleAndUpdate){var E=null===(y=null==P?void 0:P.response)||void 0===y?void 0:y.clone();return C=z(m,null===(_=t.options)||void 0===_?void 0:_.fetchOptions,!0,E),E?(C.catch((function(){})),Promise.resolve(E)):C}return Promise.reject(Y("Invalid caching strategy",t,null==m?void 0:m.collection))}function K(t,e,n,r){return V({collection:e,data:void 0,method:"GET",options:n,url:t,views:r})}function X(t,e,n,r,o){return V({collection:n,data:e,method:"POST",options:r,url:t,views:o})}function Z(t,e,n,r,o){return V({collection:n,data:e,method:"PATCH",options:r,url:t,views:o})}function $(t,e,n,r,o){return V({collection:n,data:e,method:"PUT",options:r,url:t,views:o})}function tt(t,e,n,r,o){if(void 0===o&&(o=At),t){var i="object"==typeof t?t.href:t;if(i)return K(i,e,n,r)}return Promise.resolve(new o({data:void 0},e))}function et(e,n){return g.action((function(r){if(r.error)throw r.error;if(204===r.status)return m(e,"networkPersisted",!0),e;if(202===r.status){var o=r.data;return m(o,"jsonapiProp",n),m(o,"jsonapiQueue",!0),m(o,"jsonapiRelated",e),o}m(e,"networkPersisted",!0);var i=r.replaceData(e).data;return t(i),i}))}function nt(t,e){void 0===e&&(e="");var n=[];return Object.keys(t).forEach((function(r){t[r]instanceof Array?W.paramArrayType===C.CommaSeparated?n.push({key:"".concat(e).concat(r),value:t[r].join(",")}):W.paramArrayType===C.MultipleParams?n.push.apply(n,t[r].map((function(t){return{key:"".concat(e).concat(r),value:t}}))):W.paramArrayType===C.ParamArray&&n.push.apply(n,t[r].map((function(t){return{key:"".concat(e).concat(r,"]["),value:t}}))):"object"==typeof t[r]?n.push.apply(n,nt(t[r],"".concat(r,"."))):n.push({key:"".concat(e).concat(r),value:t[r]})})),n}function rt(t){return nt(t).map((function(t){return"filter[".concat(t.key,"]=").concat(t.value)}))}function ot(t){return encodeURIComponent(t).replace(/%3D/,"=")}function it(t,e,n,r){var o,i,a,s,c,u,l,f,d,p=n&&n.networkConfig&&n.networkConfig.headers||{},h=[].concat(rt((null===(o=null==n?void 0:n.queryParams)||void 0===o?void 0:o.filter)||{}),(d=null===(i=null==n?void 0:n.queryParams)||void 0===i?void 0:i.sort)?["sort=".concat(d)]:[],(f=null===(a=null==n?void 0:n.queryParams)||void 0===a?void 0:a.include)?W.sortParams&&Array.isArray(f)?["include=".concat(I([],f,!0).sort())]:["include=".concat(f)]:[],(u=(null===(s=null==n?void 0:n.queryParams)||void 0===s?void 0:s.fields)||{},l=[],Object.keys(u).forEach((function(t){l.push("fields[".concat(t,"]=").concat(u[t]))})),l),function(t){return t.map((function(t){return"string"==typeof t?t:"".concat(t.key,"=").concat(t.value)}))}((null===(c=null==n?void 0:n.queryParams)||void 0===c?void 0:c.custom)||[]));W.encodeQueryString&&(h=h.map(ot));var v=function(t,e){var n=t;if(e.length){var r=-1===n.indexOf("?")?"?":"&";n+=r+e.join("&")}return n}(function(t,e){return U.test(t)||e?t:"".concat(W.baseUrl).concat(t)}(t,r),h);return W.sortParams&&(v=function(t){var e=t.split("?"),n=e[0],r=e[1];if(!r)return t;var o=new URLSearchParams(r);o.sort();var i=W.encodeQueryString?o.toString():decodeURIComponent(o.toString());return"".concat(n,"?").concat(i)}(v)),{data:e,headers:p,url:v}}function at(t,n,r,o,i,a){var s=a&&a.constructor;!s&&i&&(s=i.constructor.types.filter((function(e){return e.type===t}))[0]);var c,u=!1;return s?s.endpoint&&"function"==typeof s.endpoint?(u=!0,c=s.endpoint(W.baseUrl)):c=s.endpoint||s.baseUrl||e(s):c=t.toString(),it(n?"".concat(c,"/").concat(n):"".concat(c),r,o,u)}function st(t,e){var n,r;if(!e)return null;var o=((n={})[w]=((r={fields:Object.keys(e.attributes||{}).reduce((function(t,e){return t[e]={referenceDef:!1},t}),{}),id:e.id}).jsonapiLinks=e.links,r.jsonapiMeta=e.meta,r.networkPersisted=Boolean(e.id),r.type=e.type,r),n);if(e.relationships){var i={},a={},c={};Object.keys(e.relationships).forEach((function(n){var r,u=e.relationships[n];u&&"data"in u&&(u.data||null===u.data)&&(!(u.data instanceof Array)||u.data.length>0?(o[n]=u.data,t&&n in t||(c[n]={referenceDef:{model:(u.data instanceof Array?u.data[0].type:null===(r=u.data)||void 0===r?void 0:r.type)||kt.type,type:u.data instanceof Array?s.TO_MANY:s.TO_ONE}})):o[n]=[]),u&&"links"in u&&(i[n]=u.links),u&&"meta"in u&&(a[n]=u.meta)})),Object.assign(o[w].fields,c),o[w].jsonapiRefLinks=i,o[w].jsonapiRefMeta=a}return Object.assign(o,e.attributes)}function ct(t){return _(t,"jsonapiMeta",{})}function ut(t){return _(t,"jsonapiLinks",{})}function lt(t,r,o){var i=n(t),a=ut(t);if(!a||!(r in a))throw G("Link ".concat(r," doesn't exist on the model"));var s=tt(a[r],i,o);return _(t,"jsonapiQueue")?s.then((function(n){var r=_(t,"jsonapiRelated"),o=_(t,"jsonapiProp"),i=n.data,a=i&&e(i);return i&&a!==e(t)&&a===e(r)?o?(r[o]=i,n):(m(r,"networkPersisted",!0),n.replaceData(r)):n})):s}function ft(t){return _(t,"jsonapiRefLinks",{})}function dt(t,e,r){if(!n(t))throw G("The model needs to be in a collection");var o=ft(t);if(!o||!(e in o))throw G("The reference ".concat(e," doesn't have any links"));var i=o[e];if(!i||!(r in i))throw G("Link ".concat(r," doesn't exist on the model"));return i[r]}function pt(t,e,r,o){var i=n(t);return tt(dt(t,e,r),i,o)}function ht(t){return _(t,"jsonapiRefMeta",{})}function vt(t){return _(t,"networkPersisted",!1)}function yt(t,n){var s=t.constructor,c=n?r(t):o(t),u=s.useAutogeneratedIds,l={attributes:c,id:vt(t)||u?i(t).toString():void 0,type:e(t)},f=B(t);return Object.keys(f).forEach((function(e){if(!f[e].property){l.relationships=l.relationships||{};var n=a(t,e);l.relationships[e]={data:b(n,(function(t){return{id:t.id.toString(),type:t.type}}))},l.attributes&&delete l.attributes[e]}})),l.attributes&&(delete l.attributes.id,delete l.attributes[w]),l}function _t(t,n){return at(e(t),vt(t)?i(t):void 0,void 0,n,void 0,t).url}function gt(t,r){var o,i=n(t),a=null!==(o=null==W?void 0:W.usePatchWhenPossible)&&void 0!==o&&o,s=vt(t),c=yt(t,a&&s);return(s?a?Z:$:X)(_t(t,r),{data:c},i,r&&r.networkConfig&&r.networkConfig.headers).then(et(t)).then((function(n){return Et(e(t)),n}))}function mt(t,e){var r=n(t),o=vt(t),i=_t(t);return o?function(t,e,n,r){return V({collection:e,data:void 0,method:"DELETE",options:n,url:t,views:void 0})}(i,r,e&&e.networkConfig&&e.networkConfig.headers).then((function(e){if(e.error)throw e.error;!function(t,e){m(t,"networkPersisted",!1)}(t),r&&r.__removeModel(t)})):(r&&r.__removeModel(t),Promise.resolve())}function bt(t,e,r){var o,i=n(t),s=dt(t,e,"self"),c="object"==typeof s?s.href:s,u=a(t,e),l=null===(o=_(t,"fields"))||void 0===o?void 0:o[e],f=(null==l?void 0:l.referenceDef)?l.referenceDef.model:null;return Z(c,{data:b(u,(function(t){return{id:t.id,type:t.type||f}}))},i,r&&r.networkConfig&&r.networkConfig.headers).then(et(t,e))}var wt=["jsonapiLinks","jsonapiMeta","networkPersisted","jsonapiRefLinks","jsonapiRefMeta"];function Ot(t){return function(e){function n(n,r){void 0===n&&(n={});var o,i=n;n&&"type"in n&&("attributes"in n||"relationships"in n)&&(i=st(B(t),n)),o=e.call(this,i,r)||this;var a=(null==i?void 0:i[w])||{};return wt.forEach((function(t){t in a&&m(o,t,a[t])})),o}return D(n,e),n.getAutoId=function(){return e.getAutoId.call(this).toString()},n.prototype.save=function(t){return gt(this,t)},n.prototype.destroy=function(t){return mt(this,t)},n.useAutogeneratedIds=t.useAutogeneratedIds||!1,n}(t)}var kt=function(t){function e(){return null!==t&&t.apply(this,arguments)||this}return D(e,t),e}(Ot(c));function jt(t){if(t instanceof Array)return t;var e=[];return t.forEach((function(t,n){e.push([n,t])})),e}function Pt(t,e,n){if(e&&t.data){var r=n||e.sync(t.data);return new f.ToOneOrMany(r,e,!0)}if(t.data){var o=t.data;if(o.data){if(o.data instanceof Array)throw new Error("A save/remove operation should not return an array of results");return{value:n||new kt(st(void 0,o.data))}}}return new f.ToOneOrMany(null,e,!0)}var At=function(){function t(t,e,n,r,o){var i=this;if(this.__internal={response:{},views:[]},this.__cache={},this.collection=e,this.__updateInternal(t,n,o),this.__data=Pt(t,e,r),this.views.forEach((function(t){i.__data.value&&t.add(i.__data.value)})),Object.freeze(this),this.error)throw this}return Object.defineProperty(t.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"headers",{get:function(){return this.__internal.headers},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"requestHeaders",{get:function(){return this.__internal.requestHeaders},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"error",{get:function(){return this.__internal.error},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"status",{get:function(){return this.__internal.status},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"isSuccess",{get:function(){return!this.error},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"data",{get:function(){return this.__data.value},enumerable:!1,configurable:!0}),t.prototype.__updateInternal=function(t,e,n){var r,o,i,a,s,c=this;e&&(this.__internal.options=e),this.__internal.response=t,this.__internal.meta=(null===(r=t.data)||void 0===r?void 0:r.meta)||{},this.__internal.links=(null===(o=t.data)||void 0===o?void 0:o.links)||{},this.__internal.jsonapi=(null===(i=t.data)||void 0===i?void 0:i.jsonapi)||{},this.__internal.headers=t.headers&&((s=t.headers)instanceof Array?new k(s):s),this.__internal.requestHeaders=t.requestHeaders,this.__internal.error=(null===(a=t.data)||void 0===a?void 0:a.errors)||t.error,this.__internal.status=t.status,n&&(this.__internal.views=n),this.error||this.status||(this.__internal.error=new Error("Network not available")),this.links&&Object.keys(this.links).forEach((function(t){O(c,t,(function(){return c.__fetchLink(t)}))}))},t.prototype.replaceData=function(t){var n,r=this.data;if(r===t)return this;var a=i(r).toString(),s=e(r),c=this.views.map((function(t){return t.list.indexOf(r)}));this.collection&&(this.collection.removeOne(s,a),this.collection.add(t));var f=o(r);return null===(n=null==f?void 0:f.__META__)||void 0===n||delete n.collection,u(t,f),l(t,a),this.views.forEach((function(e,n){-1!==c[n]&&(e.list[c[n]]=t)})),new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,t)},t.prototype.clone=function(){return new(0,this.constructor)(this.__internal.response,this.collection,this.__internal.options,this.data||void 0)},Object.defineProperty(t.prototype,"snapshot",{get:function(){return{response:Object.assign({},this.__internal.response,{headers:this.__internal.response.headers&&jt(this.__internal.response.headers),collection:void 0}),options:this.__internal.options}},enumerable:!1,configurable:!0}),t.prototype.update=function(t,e){this.__updateInternal(t,void 0,e);var n=Pt(t,this.collection);return this.__data.__readonlyValue=n.value,this},t.prototype.__fetchLink=function(t){var e=this,n=this.constructor;if(!this.__cache[t]){var r=this.links&&t in this.links?this.links[t]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[t]=function(){return tt(r,e.collection,o,e.views,n)}}}return this.__cache[t]},t}(),Ct=[];function Et(t){Ct=Ct.filter((function(e){return!e.types.includes(t)}))}function Rt(t){return Ct.filter((function(e){return e.collection===t})).map((function(t){return Object.assign({},t,{collection:void 0})}))}function St(t){if(t.error)throw t.error;return t}function Tt(t,e){return b(t&&t.included||[],e),b(t&&t.data||null,e)}function xt(n){if(h(n))return Ot(n);if(v(n))return function(n){function o(t){void 0===t&&(t=[]);var e=n.call(this,t)||this;return t instanceof Array||!(null==t?void 0:t.cache)||function(t,e){Ct.push.apply(Ct,t.map((function(t){return Object.assign({collection:e},t)})))}(t.cache,e),e}return D(o,n),o.prototype.sync=function(t){var e=this;if(!t)return null;var n=Tt(t,(function(t){return e.__addRecord(t)}));return Tt(t,this.__updateRelationships.bind(this)),n},o.prototype.fetch=function(t,e,n){return j("fetch is deprecated, use getOne instead"),this.getOne(t,e,Object.assign({},n,{cacheOptions:Object.assign({},(null==n?void 0:n.cacheOptions)||{},{cachingStrategy:Q?A.CacheFirst:A.NetworkOnly})}))},o.prototype.fetchAll=function(t,e){return j("fetchAll is deprecated, use getMany instead"),this.getMany(t,Object.assign({},e,{cacheOptions:Object.assign({},(null==e?void 0:e.cacheOptions)||{},{cachingStrategy:Q?A.CacheFirst:A.NetworkOnly})}))},o.prototype.getOne=function(t,n,r){var o=e(t),i=this.__prepareQuery(o,n,void 0,r),a=r||{};return a.networkConfig=a.networkConfig||{},a.networkConfig.headers=i.headers,K(i.url,this,a).then(St)},o.prototype.getMany=function(t,n){var r=e(t),o=this.__prepareQuery(r,void 0,void 0,n),i=n||{};return i.networkConfig=i.networkConfig||{},i.networkConfig.headers=o.headers,K(o.url,this,i).then(St)},o.prototype.getAll=function(t,e,n){return void 0===n&&(n=50),L(this,void 0,void 0,(function(){return H(this,(function(r){switch(r.label){case 0:if(n<1)throw Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(t,e)];case 1:return[2,J(r.sent(),n)]}}))}))},o.prototype.request=function(t,e,n,r){return void 0===e&&(e="GET"),function(t){return V(t)}({url:it(t,n,r).url,options:r,data:n,method:e,collection:this})},o.prototype.removeOne=function(t,n,r){var o,a,s,c=e(t);return"object"==typeof n||void 0===n||"boolean"==typeof n?(o=n,a=i(t).toString(),s=t):(o=r,s=(a=i(n).toString())?this.findOne(c,a):null),s&&o?mt(s,"object"==typeof o?o:void 0):(s&&this.__removeModel(s),Et(c),Promise.resolve())},o.prototype.removeAll=function(t){n.prototype.removeAll.call(this,t),Et(e(t))},o.prototype.reset=function(){n.prototype.reset.call(this),Ct.length=0},o.prototype.__addRecord=function(n){var r=this.constructor,o=n.type,i=n.id,a=void 0===i?null:this.findOne(o,i),s=st(B(r.types.find((function(t){return e(t)===o}))||kt),n);return a?(d(s,o,this),t(a)):a=r.types.filter((function(t){return t.type===o})).length?this.add(s,o):this.add(new kt(s,this)),a},o.prototype.__updateRelationships=function(t){var e=this,n=void 0===t.id?null:this.findOne(t.type,t.id);(t.relationships?Object.keys(t.relationships):[]).forEach((function(r){var o=t.relationships[r];if(o&&"data"in o){var i=o.data;if(!(P(i)&&i.length<1)&&n)if(i){var a=b(i,(function(t){return(void 0===t.id?null:e.findOne(t.type,t.id))||t}))||null,c=P(i)?i[0].type:i.type;r in n?n[r]=a:p(n,r,{model:c,type:s.TO_ONE_OR_MANY},a)}else{var u=_(n,"refs");u&&r in u&&"__proto__"!==r&&(n[r]=u[r].type===s.TO_MANY?[]:null)}}}))},o.prototype.__prepareQuery=function(t,e,n,r){return at(t,e,n,r,this)},o.prototype.toJSON=function(){return Object.assign({},n.prototype.toJSON.call(this),{cache:Rt(this)})},o.types=r.types&&r.types.length?r.types.concat(kt):[kt],o.maxCacheAge=r.maxCacheAge,o.cache=r.cache,o.defaultModel=r.defaultModel||kt,o}(r=n);var r;if(y(n))return function(t){function e(e,n,r,o,i){void 0===o&&(o=[]),void 0===i&&(i=!1);var a=t.call(this,e,n,r,o,i)||this;return a.__collection=n,a}return D(e,t),e.prototype.sync=function(t){var e=this.__collection.sync(t);return e&&this.add(e),e},e.prototype.getOne=function(t,e){return this.__collection.getOne(this.modelType,t,e).then(this.__addFromResponse.bind(this))},e.prototype.getMany=function(t){return this.__collection.getMany(this.modelType,t).then(this.__addFromResponse.bind(this))},e.prototype.getAll=function(t,e){return void 0===e&&(e=50),L(this,void 0,void 0,(function(){return H(this,(function(n){switch(n.label){case 0:if(e<1)throw new Error("Please enter a meaningful amount of max requests.");return[4,this.getMany(t)];case 1:return[2,J(n.sent(),e)]}}))}))},e.prototype.__addFromResponse=function(t){return t.data&&this.add(t.data),t.views.push(this),t},e}(n);throw new Error("The instance needs to be a model, collection or a view")}var Mt,qt=function(t){function e(e,n,r,o){var i=t.call(this,e,n,r,o)||this;return i.links&&Object.keys(i.links).forEach((function(t){O(i,t,(function(){return i.__fetchLink(t)}))})),i}return D(e,t),Object.defineProperty(e.prototype,"meta",{get:function(){return this.__internal.meta},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"links",{get:function(){return this.__internal.links},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"jsonapi",{get:function(){return this.__internal.jsonapi},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"views",{get:function(){return this.__internal.views},enumerable:!1,configurable:!0}),e.prototype.__fetchLink=function(t){var n=this;if(!this.__cache[t]){var r=this.links&&t in this.links?this.links[t]:null;if(r){var o=Object.assign({},this.__internal.options);o.networkConfig=o.networkConfig||{},o.networkConfig.headers=this.requestHeaders,this.__cache[t]=function(){return tt(r,n.collection,o,n.views).then((function(t){return new e(t.__internal.response,t.collection,void 0,t.views)}))}}}return this.__cache[t]},e}(E);function Nt(t,e){return(t&&e.collection?e.collection.sync(t):t)||{}}function Dt(t){return F(F({},t),{data:{data:b(t.data,(function(t){return t instanceof c?yt(t,!0):t}))||void 0}})}!function(t){t.Asc="",t.Desc="-"}(Mt||(Mt={}));var Ft=function(t){function e(e){var n,r=t.call(this,e)||this;return(n=r)._config.Response=qt,R("content-type","application/vnd.api+json")(n),S(Nt)(n),T(Dt)(n),x(C.CommaSeparated)(n),M(!1)(n),r}return D(e,t),e}(q);export{Ft as BaseJsonapiRequest,kt as GenericModel,qt as NetworkResponse,At as Response,it as buildUrl,W as config,tt as fetchLink,lt as fetchModelLink,pt as fetchModelRefLink,_t as getModelEndpointUrl,ut as getModelLinks,ct as getModelMeta,ft as getModelRefLinks,ht as getModelRefMeta,vt as isModelPersisted,xt as jsonapi,yt as modelToJsonApi,at as prepareQuery,gt as saveModel,bt as saveRelationship};
//# sourceMappingURL=index.esm.js.map

@@ -34,2 +34,8 @@ import { View } from '@datx/core';

usePatchWhenPossible: boolean;
/**
* Enable stable sort of url search params using `URLSearchParams.sort()` method.
* It will also sort include params using `Array.sort()` method.
* @default false
*/
sortParams?: boolean;
}

@@ -36,0 +42,0 @@ export declare const config: IConfigType;

{
"name": "@datx/jsonapi",
"version": "2.4.8",
"version": "2.4.10",
"description": "DatX mixin for JSON API support",

@@ -29,3 +29,3 @@ "main": "./index.cjs.js",

},
"gitHead": "36ced89e0774de8dda366fc81e2b27b627a9c453"
"gitHead": "d7783faa41706ee33bae01a4e18ebcb490be004a"
}

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is too big to display