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.4
to
2.4.5
+1
-1
dist/index.cjs.js

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

"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}};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)||U)({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)||U;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);(Q=Q.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)||U,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=U);var r=Date.now()-1e3*t,o=Q.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){if(void 0===o&&(o=U),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 w(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 O(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,O(e[o],"".concat(o,"."))):r.push({key:"".concat(t).concat(o),value:e[o]})})),r}function j(e){return O(e).map((function(e){return"filter[".concat(e.key,"]=").concat(e.value)}))}function k(e){return encodeURIComponent(e).replace(/%3D/,"=")}function M(e,t,n,r){var o,i,a,s,u=n&&n.networkConfig&&n.networkConfig.headers||{},l=[].concat(j(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(k));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 P(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(),M(n?"".concat(c,"/").concat(n):"".concat(c),r,o,u)}function C(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)||F.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 x(e){return t.getMeta(e,"jsonapiLinks",{})}function T(e){return t.getMeta(e,"jsonapiRefLinks",{})}function A(t,n,r){if(!e.getModelCollection(t))throw l("The model needs to be in a collection");var o=T(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 R(e){return t.getMeta(e,"networkPersisted",!1)}function E(n,r){var o=n.constructor,i=r?e.modelToDirtyJSON(n):e.modelToJSON(n),a=o.useAutogeneratedIds,s={attributes:i,id:R(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 S(t,n){return P(e.getModelType(t),R(t)?e.getModelId(t):void 0,void 0,n,void 0,t).url}function q(t,n){var r=e.getModelCollection(t),o=R(t),i=E(t,o);return(o?_:m)(S(t,n),{data:i},r,n&&n.networkConfig&&n.networkConfig.headers).then(w(t)).then((function(n){return B(e.getModelType(t)),n}))}function I(n,r){var o=e.getModelCollection(n),i=R(n),a=S(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 L=["jsonapiLinks","jsonapiMeta","networkPersisted","jsonapiRefLinks","jsonapiRefMeta"];function D(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=C(p(e),r)),i=n.call(this,a,o)||this;var s=(null==a?void 0:a[t.META_FIELD])||{};return L.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 q(this,e)},r.prototype.destroy=function(e){return I(this,e)},r.useAutogeneratedIds=e.useAutogeneratedIds||!1,r}(e)}var F=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t}(D(e.PureModel));function N(e){if(e instanceof Array)return e;var t=[];return e.forEach((function(e,n){t.push([n,e])})),t}function H(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 F(C(void 0,i.data))}}}return new e.Bucket.ToOneOrMany(null,n,!0)}var U=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=H(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&&N(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=H(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 b(r,t.collection,o,t.views,n)}}}return this.__cache[e]},n}(),Q=[];function B(e){Q=Q.filter((function(t){return!t.types.includes(e)}))}function J(e){if(e.error)throw e.error;return e}function G(e,n){return t.mapItems(e&&e.included||[],n),t.mapItems(e&&e.data||null,n)}var z,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 b(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 W(n){return i(i({},n),{data:{data:t.mapItems(n.data,(function(t){return t instanceof e.PureModel?E(t,!0):t}))||void 0}})}!function(e){e.Asc="",e.Desc="-"}(z||(z={}));var K=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(W)(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=K,exports.GenericModel=F,exports.NetworkResponse=Y,exports.Response=U,exports.buildUrl=M,exports.config=f,exports.fetchLink=b,exports.fetchModelLink=function(n,r,o){var i=e.getModelCollection(n),a=x(n);if(!a||!(r in a))throw l("Link ".concat(r," doesn't exist on the model"));var s=b(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 b(A(t,n,r),i,o)},exports.getModelEndpointUrl=S,exports.getModelLinks=x,exports.getModelMeta=function(e){return t.getMeta(e,"jsonapiMeta",{})},exports.getModelRefLinks=T,exports.getModelRefMeta=function(e){return t.getMeta(e,"jsonapiRefMeta",{})},exports.isModelPersisted=R,exports.jsonapi=function(r){if(e.isModel(r))return D(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,Q.push.apply(Q,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=G(e,(function(e){return t.__addRecord(e)}));return G(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(J)},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(J)},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:M(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?I(a,"object"==typeof o?o:void 0):(a&&this.__removeModel(a),B(s),Promise.resolve())},c.prototype.removeAll=function(t){r.prototype.removeAll.call(this,t),B(e.getModelType(t))},c.prototype.reset=function(){r.prototype.reset.call(this),Q.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=C(p(n.types.find((function(t){return e.getModelType(t)===r}))||F),t);return i?(e.updateModel(i,a),e.commitModel(i)):i=n.types.filter((function(e){return e.type===r})).length?this.add(a,r):this.add(new F(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 P(e,t,n,r,this)},c.prototype.toJSON=function(){return Object.assign({},r.prototype.toJSON.call(this),{cache:(e=this,Q.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(F):[F],c.maxCacheAge=i.maxCacheAge,c.cache=i.cache,c.defaultModel=i.defaultModel||F,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=E,exports.prepareQuery=P,exports.saveModel=q,exports.saveRelationship=function(n,r,o){var i,a=e.getModelCollection(n),s=A(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(w(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])}}}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===(b=e.options)||void 0===b?void 0:b.fetchOptions,!0);if(C===n.CachingStrategy.StaleAndUpdate){var R=null===(_=null==T?void 0:T.response)||void 0===_?void 0:_.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 b(e,t,n,r,o){return v({collection:n,data:t,method:"PATCH",options:r,url:e,views:o})}function _(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.updateModel(i,a),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 b(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))};

@@ -33,2 +33,3 @@ import { View } from '@datx/core';

transformResponse(response: IRawResponse): IRawResponse;
usePatchWhenPossible: boolean;
}

@@ -73,2 +74,14 @@ export declare const config: IConfigType;

/**
* API call used to update data on the server with put
*
* @export
* @param {IJsonapiCollection} collection Related collection
* @param {string} url API call URL
* @param {object} [data] Request body
* @param {IRequestOptions} [options] Server options
* @param {Array<View>} [views] Request view
* @returns {Promise<Response>} Resolves with a Response object
*/
export declare function put<T extends IJsonapiModel = IJsonapiModel>(url: string, data?: object, collection?: IJsonapiCollection, options?: IRequestOptions, views?: Array<View>): Promise<LibResponse<T>>;
/**
* API call used to remove data from the server

@@ -75,0 +88,0 @@ *

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

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

"@types/lodash": "^4.14.182",
"@types/node": "^17.0.41",
"@types/node": "^18.7.6",
"@types/uuid": "^8.3.4",

@@ -74,7 +74,7 @@ "isomorphic-fetch": "^3.0.0",

"dependencies": {
"@datx/core": "2.4.4",
"@datx/network": "2.4.4",
"@datx/utils": "2.4.4"
"@datx/core": "2.4.5",
"@datx/network": "2.4.5",
"@datx/utils": "2.4.5"
},
"gitHead": "a9e8b0252ac0a02c9192b185d4b90200fc276f4d"
"gitHead": "23ec609f962cbc7b755e0f3c30e6e134f3a002a2"
}

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