Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

datx

Package Overview
Dependencies
Maintainers
11
Versions
67
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

datx - npm Package Compare versions

Comparing version 2.0.0-beta.7 to 2.0.0-beta.8

2

dist/index.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("datx-utils"),n=require("mobx");(e=exports.ReferenceType||(exports.ReferenceType={}))[e.TO_ONE=0]="TO_ONE",e[e.TO_MANY=1]="TO_MANY",e[e.TO_ONE_OR_MANY=2]="TO_ONE_OR_MANY";var 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)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function o(e,t){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}).apply(this,arguments)};function a(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var u,l,s,c=/\$\{\s*([a-zA-Z0-9\-_]+)\s*\}/g;function f(e,t){return void 0===t&&(t={}),new Error(("[datx exception] "+function(e,t){for(var n=e,r=c.exec(n);r;)n=n.replace(r[0],t[r[1]]),r=c.exec(n);return n}(e,t)).replace(/\s+/g," "))}function d(e,n){var r=t.getMeta(e,"ref_"+n);return r?r.value:null}function p(e,n,r){var o;(null===(o=t.getMeta(e,u.Fields,{})[n])||void 0===o?void 0:o.referenceDef)&&(t.isArrayLike(e[n])?e[n].includes(r)||e[n].push(r):e[n]=r)}function _(e,n,r){t.isArrayLike(e[n])?e[n].remove(r):e[n]===r&&(e[n]=null)}function h(e){return 0===Object.keys(e).length}function y(e,n){var r=Object.assign({},e,{model:{id:j(n),type:V(n)}}),o=t.getMeta(n,u.PatchListeners,[]).slice(),i=F(n);i&&"__patchListeners"in i&&(i.__patchListeners||[]).forEach((function(e){o.push(e)})),o.forEach((function(e){e(r)}))}function v(e){var n=t.getMeta(e,u.Patch,{count:0,newValue:{},oldValue:{}});n.count++,t.setMeta(e,u.Patch,n)}function b(e,r){void 0===r&&(r=exports.PatchType.UPDATE);var o=t.getMeta(e,u.Patch,{count:0,newValue:{},oldValue:{}});if(o.count--,0===o.count){var i=n.toJS(o.newValue),a=n.toJS(o.oldValue);h(i)&&h(a)||y({newValue:i,oldValue:a,patchType:r},e),t.setMeta(e,u.Patch,{count:0,oldValue:{},newValue:{}})}else t.setMeta(e,u.Patch,o)}function M(e,n,r,o){v(e),function(e,n,r,o){var i=t.getMeta(e,u.Patch,{count:0,newValue:{},oldValue:{}});if(!(e[n]===r&&!o||o&&r===o.value)){var a=t.getMeta(e,u.Fields,{});n in i.oldValue||(o?i.oldValue[n]=o.value:n in a&&a[n].referenceDef?i.oldValue[n]=N(e[n]):i.oldValue[n]=e[n]),i.newValue[n]=n in a&&a[n].referenceDef?N(r):r,t.setMeta(e,u.Patch,i)}}(e,n,r,o),b(e)}function m(e,t,n,r,o){return"function"==typeof e?V(e(t,n,r,o)):e}function g(e,n,r,o,i){return t.mapItems(e,(function(e){return null==e?null:"object"!=typeof e||k(e)?"object"==typeof e&&k(e)?(null==n?void 0:n.findOne(e))||e:(null==n?void 0:n.findOne(m(r.referenceDef.model,e,o,i,n),e))||{id:e,type:m(r.referenceDef.model,e,o,i,n)}:(null==n?void 0:n.add(e,m(r.referenceDef.model,e,o,i,n)))||null}))}function O(e,r,o,i){var a=t.getMeta(e,u.Fields,{}),l=a[r]||{referenceDef:o},s=F(e);if(!s&&i)throw f("The model needs to be in a collection to be referenceable");if(o&&(a[r]={referenceDef:o}),l.referenceDef.property)t.assignComputed(e,r,(function(){return function(e,r){var o,i=null===(o=t.getMeta(e,u.Fields,{})[r])||void 0===o?void 0:o.referenceDef;if(!i||!i.property)return null;var a=F(e);if(!a)return null;var l=a.getAllModels().filter((function(t){return function(e,t,n){return null!==e[t]&&void 0!==e[t]&&(e[t]instanceof x?e[t]===n:e[t].includes(n))}(t,i.property,e)})),s=n.observable.array(l,{deep:!1});return n.intercept(s,(function(n){return function(e,n,r){var o,i=null===(o=t.getMeta(e,u.Fields,{})[n])||void 0===o?void 0:o.referenceDef;return i?"splice"===r.type?function(e,t,n,r){var o=r.property;return n.added.forEach((function(t){return p(t,o,e)})),e[t].slice(n.index,n.index+n.removedCount).forEach((function(t){return _(t,o,e)})),null}(e,n,r,i):function(e,n,r,o){var i=o.property,a=e[n].length>r.index?e[n][r.index]:null;return r.newValue&&p(r.newValue,i,e),a&&_(a,i,e),t.warn("This shouldn't have happened. Please open an issue: https://github.com/infinum/datx/issues/new"),null}(e,n,r,i):null}(e,r,n)})),s}(e,r)}),(function(e){!function(e,t,n){throw f("Back references are read only")}()}));else{var c=function(e){if(e===exports.ReferenceType.TO_ONE)return $;if(e===exports.ReferenceType.TO_ONE_OR_MANY)return G;if(e===exports.ReferenceType.TO_MANY)return Z;throw t.error("Unknown reference type")}(l.referenceDef.type),h=l.referenceDef.type===exports.ReferenceType.TO_MANY?[]:null;null!=i&&(h=g(i,s,l,e,r));var y=new c(h,s,!1,e,r,!0);M(e,r,y.value),t.setMeta(e,"ref_"+r,y),t.assignComputed(e,r,(function(){return d(e,r)}),(function(n){M(e,r,n),function(e,n,r){var o=t.getMeta(e,"ref_"+n);if(P(r)||t.isArrayLike(r)){var i=t.getMeta(e,u.Fields,{})[n],a=m(i.referenceDef.model,i.referenceDef.defaultValue,e,n,F(e));r=t.mapItems(r,(function(e){return P(e)?{id:e,type:a}:N(e)}))}o&&(o.value=r)}(e,r,g(n,s,l,e,r))}))}}function w(e,r,o){var i=t.getMeta(e,u.Fields,{})[r],a=t.getMeta(e.constructor,l.TypeField,"__datx__type__",!0),s=t.getMeta(e.constructor,l.IdField,"__datx__id__",!0);r===a?t.assignComputed(e,r,(function(){return V(e)}),(function(){throw f("Model type can't be changed after initialization.")})):r===s?t.assignComputed(e,r,(function(){return j(e)}),(function(){throw f("Model ID can't be updated directly. Use the `updateModelId` helper function instead.")})):i.referenceDef?O(e,r,void 0,o):(t.setMeta(e,"data__"+r,void 0),t.assignComputed(e,r,(function(){return t.getMeta(e,"data__"+r)}),(function(o){var i,a="object"!=typeof(i=o)||null===i||i instanceof x?o:n.observable(o);M(e,r,o),t.setMeta(e,"data__"+r,a)})),e[r]=o)}function T(e,n,r){var o=e.constructor,a=t.getMeta(e.constructor,l.Fields,{},!0,!0),s=null==n?void 0:n[t.META_FIELD],c=Object.assign({},a,null==s?void 0:s.fields);t.setMeta(e,u.Collection,r);var f=t.getMeta(e.constructor,l.TypeField,"__datx__type__",!0);t.setMeta(e,u.TypeField,I(n[f],null==s?void 0:s.type,o.type));var d=t.getMeta(e.constructor,l.IdField,"__datx__id__",!0);t.setMeta(e,u.IdField,I(n[d],null==s?void 0:s.id,(function(){return o.getAutoId()}))),t.setMeta(e,u.OriginalId,null==s?void 0:s.originalId),Object.keys(n).filter((function(e){return e!==t.META_FIELD})).filter((function(e){return!(e in c)})).forEach((function(e){var r=n[e],o=r instanceof x||t.isArrayLike(r)&&r.length&&(r[0]instanceof x||k(r[0]))||k(r);c[e]={referenceDef:!!o&&{type:exports.ReferenceType.TO_ONE_OR_MANY,model:V(r)}}})),t.setMeta(e,u.Fields,c),Object.keys(c).forEach((function(t){var r,a=c[t],u=i(((r={})[t]=a.defaultValue,r),n);w(e,t,A(o,u,t))})),Y(e)}!function(e){e.Fields="fields",e.IdField="id",e.TypeField="type",e.Collection="collection",e.OriginalId="originalId",e.Patch="patch",e.PatchListeners="patchListeners",e.Commit="commit"}(u||(u={})),function(e){e.Fields="fields",e.IdField="idField",e.TypeField="typeField",e.MapParse="parse",e.MapSerialize="serialize"}(l||(l={})),(s=exports.PatchType||(exports.PatchType={}))[s.CRATE=0]="CRATE",s[s.UPDATE=1]="UPDATE",s[s.REMOVE=2]="REMOVE";var x=function(){function e(e,t){void 0===e&&(e={}),v(this),T(this,e,t),b(this,exports.PatchType.CRATE)}return e.preprocess=function(e){return e},e.getAutoId=function(){return"number"==typeof this.autoIdValue?--this.autoIdValue:this.autoIdValue},e.toJSON=function(){return this.type},e.type=t.DEFAULT_TYPE,e.autoIdValue=0,e.enableAutoId=!0,e}(),L=function(e,t){return e};function A(e,n,r){return t.getMeta(e,l.MapParse+"_"+r,L,!0)(n[r],n)}function E(e,n,r){return t.getMeta(e,l.MapSerialize+"_"+r,L,!0)(n[r],n)}function k(e){return t.isArrayLike(e)?e.every(k):"object"==typeof e&&null!==e&&"type"in e&&"id"in e&&2===Object.keys(e).length}function P(e){return"string"==typeof e||"number"==typeof e}function I(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return null;for(var n=-1;++n<e.length;){var r=e[n];if("function"==typeof r&&(r=r()),null!=r)return r}return null}function V(e){return"function"==typeof e||k(e)?e.type:"object"==typeof e?t.getMeta(e,u.TypeField)||e.constructor.type:e}function j(e){if(e instanceof x){var n=t.getMeta(e,u.IdField);if(void 0!==n)return n;throw f("Model without an ID")}return e}function F(e){return t.getMeta(e,u.Collection)}function D(e){return!(e instanceof x)}function N(e){return e instanceof x?{id:j(e),type:V(e)}:e}var B=[u.Patch,u.PatchListeners,u.Collection,u.Commit,u.OriginalId,"get__","set__","data__","ref_"];function C(e){var r,o,i,a,l=t.getMetaObj(e),s=t.getMeta(e,u.Fields,{}),c=Object.keys(l).filter((function(e){return!B.some((function(t){return e.startsWith(t)}))})),f=((r={})[t.META_FIELD]=Object.assign({},(i=c.map((function(e){return[e,l[e]]})),a={},i.forEach((function(e){var t=e[0],n=e[1];a[t]=n})),a),((o={})[u.IdField]=j(e),o[u.TypeField]=V(e),o[u.Collection]=void 0,o)),r);return Object.keys(s).forEach((function(n){if(s[n].referenceDef){var r=t.getMeta(e,"ref_"+n);f[n]=(null==r?void 0:r.snapshot)||null}else f[n]=E(e.constructor,e,n)})),n.toJS(f)}function R(e){var n=C(e),r=n[t.META_FIELD]||{};r[u.OriginalId]=r[u.IdField],delete r[u.IdField];var o=F(e);if(o){var i=V(e);return o.add(n,i)}var a=e.constructor;return t.warn("The model is not in the collection. Referencing the original model won't be possible"),new a(n)}var S=[u.Fields,u.IdField,u.TypeField];function J(e,r,o){n.runInAction((function(){var i,a;if(!(e instanceof x))throw f("The given parameter is not a valid model");var l=t.getMeta(e,u.Fields,{}),s=t.isArrayLike(o)&&o.length>0&&o[0]instanceof x||o instanceof x;if(r in l){if(s&&!l[r].referenceDef)throw f("You should save this value as a reference.");e[r]=o}else s?n.extendObservable(l,((i={})[r]={referenceDef:{type:exports.ReferenceType.TO_ONE_OR_MANY,models:Array.from(new Set(t.mapItems(o,V)))}},i)):n.extendObservable(l,((a={})[r]={referenceDef:!1},a)),t.setMeta(e,u.Fields,l),w(e,r,o)}))}function z(e,n){v(e);var r=t.getMeta(e.constructor,l.IdField,"__datx__id__"),o=t.getMeta(e.constructor,l.TypeField,"__datx__type__"),i=Object.keys(n instanceof x?C(n):n);return t.mergeMeta(e,function(e,t){var n={};return Object.keys(e).filter((function(e){return!t.includes(e)})).forEach((function(t){n[t]=e[t]})),n}(n[t.META_FIELD]||{},S)),i.forEach((function(i){i!==t.META_FIELD&&i!==r&&i!==o?J(e,i,n[i]):i===t.META_FIELD&&Object.keys(n[i]||{}).forEach((function(r){S.includes(r)||t.setMeta(e,r,n[i][r])}))})),b(e),e}function q(e,n){t.setMeta(e,u.Collection,n);var r=t.getMeta(e,u.Fields,{});v(e),Object.keys(r).forEach((function(r){var o=t.getMeta(e,"ref_"+r);o&&o.setCollection(n)})),b(e)}function Y(e){t.setMeta(e,u.Commit,i(i({},C(e)),{__META__:void 0}))}function U(e){var n=t.getMeta(e,u.Commit);n&&z(e,n)}function W(e,n){var r,o,i=t.getMeta(e,u.Commit);return!(i&&(r=t.getMeta(e,u.Fields,{})[n].referenceDef?t.mapItems(e[n],N):e[n],o=i[n],JSON.stringify(r)===JSON.stringify(o)))}var Z=function(){function e(e,r,o,i,a,u){var l=this;if(void 0===e&&(e=[]),void 0===o&&(o=!1),void 0===u&&(u=!0),this.__readonly=o,this.__model=i,this.__key=a,this.__skipMissing=u,this.__rawList=n.observable.array([]),t.makeObservable(this),(null==e?void 0:e.length)>0&&!r)throw f("The model needs to be in a collection to be referenceable");if(e&&!t.isArrayLike(e))throw f("The reference must be an array of values.");n.runInAction((function(){l.__rawList.replace(e||[]),l.setCollection(r)}))}return e.prototype.setCollection=function(e){var t=this;this.__collection=e,this.__disposer&&this.__disposer(),e&&(this.__rawList.forEach((function(e,n){var r=t.__getModel(e);r&&(t.__rawList[n]=r)})),this.__disposer=n.reaction((function(){return t.__rawList.filter(D).filter(Boolean).filter((function(t){return e.findOne(t.type,t.id)})).length>0}),this.__reMap.bind(this)))},Object.defineProperty(e.prototype,"value",{get:function(){return this.__getList()},set:function(e){var r=this;if(this.__readonly)throw f("This is a read-only bucket");if(null===e)e=[];else if(!t.isArrayLike(e))throw f("The reference must be an array of values.");n.runInAction((function(){r.__rawList.replace(e),r.__model&&r.__key&&M(r.__model,r.__key,e)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.value.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refValue",{get:function(){return this.__rawList.map(N)},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.refValue.slice()},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),e.prototype.__getList=function(){var e=this,t=this.__rawList.map(this.__getModel.bind(this)).filter((function(t){return!e.__skipMissing||Boolean(t)})).filter((function(e){return Boolean(e&&F(e))})),r=n.observable.array(t,{deep:!1});return n.intercept(r,this.__partialRawListUpdate.bind(this)),r},e.prototype.__getModel=function(e){if(e instanceof x||null===e)return e;if(!this.__collection)throw f("The model needs to be in a collection to be referenceable");return this.__collection.findOne(e.type,e.id)},e.prototype.__partialRawListUpdate=function(e){var t=this;if(this.__readonly)throw f("This is a read-only bucket");if("splice"===e.type){var r=e.added;return n.runInAction((function(){t.__rawList.slice(e.index,e.removedCount),t.__rawList.splice.apply(t.__rawList,[e.index,e.removedCount].concat(r))})),null}return n.runInAction((function(){var n=t.__getModel(e.newValue);n&&(t.__rawList[e.index]=n)})),null},e.prototype.__reMap=function(){for(var e=0;e<this.__rawList.length;e++)if(D(this.__rawList[e])){var t=this.__getModel(this.__rawList[e]);t&&(this.__rawList[e]=t)}},a([n.computed],e.prototype,"value",null),a([n.computed],e.prototype,"length",null),a([n.computed],e.prototype,"refValue",null),a([n.computed],e.prototype,"snapshot",null),e}(),$=function(){function e(e,n,r,o,i,a){if(void 0===r&&(r=!1),void 0===a&&(a=!0),this.__collection=n,this.__readonly=r,this.__model=o,this.__key=i,this.__skipMissing=a,this.__rawValue=null,t.makeObservable(this),e&&!this.__collection)throw f("The model needs to be in a collection to be referenceable");if(t.isArrayLike(e))throw f("The reference can't be an array of values.");if(!(k(e)||e instanceof x||null===e))throw f("The value needs to be a reference");this.__rawValue=e}return e.prototype.setCollection=function(e){this.__collection=e},Object.defineProperty(e.prototype,"value",{get:function(){return this.__rawValue?this.__getModel(this.__rawValue):null},set:function(e){if(!this.__collection)throw f("The model needs to be in a collection to be referenceable");if(this.__readonly)throw f("This is a read-only bucket");if(t.isArrayLike(e))throw f("The reference can't be an array of values.");if(!(k(e)||e instanceof x||null===e))throw f("The value needs to be a reference");this.__rawValue=e,this.__model&&this.__key&&M(this.__model,this.__key,e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refValue",{get:function(){return this.__rawValue?N(this.__rawValue):null},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.refValue},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),e.prototype.__getModel=function(e){if(e instanceof x||null===e)return e;if(!this.__collection)throw f("The model needs to be in a collection to be referenceable");return this.__collection.findOne(e.type,e.id)||(this.__skipMissing?null:e)},a([n.observable],e.prototype,"__rawValue",void 0),a([n.computed],e.prototype,"value",null),a([n.computed],e.prototype,"refValue",null),a([n.computed],e.prototype,"snapshot",null),e}(),G=function(){function e(e,r,o,i,a,u){var l=this;void 0===o&&(o=!1),void 0===u&&(u=!0),this.__collection=r,this.__readonly=o,this.__model=i,this.__key=a,this.__skipMissing=u,this.__isList=!0,t.makeObservable(this),n.runInAction((function(){l.__isList=t.isArrayLike(e),l.__isList?l.__toManyBucket=new Z(e,r,o,i,a,u):l.__toOneBucket=new $(e,r,o,i,a,u)}))}return e.prototype.setCollection=function(e){this.__collection=e,this.__toManyBucket&&this.__toManyBucket.setCollection(e),this.__toOneBucket&&this.__toOneBucket.setCollection(e)},Object.defineProperty(e.prototype,"value",{get:function(){return this.__isList?this.__toManyBucket.value:this.__toOneBucket.value},set:function(e){var r=this;n.runInAction((function(){r.__isList=t.isArrayLike(e),r.__isList?r.__toManyBucket?r.__toManyBucket.value=e:r.__toManyBucket=new Z(e,r.__collection):r.__toOneBucket?r.__toOneBucket.value=e:r.__toOneBucket=new $(e,r.__collection)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"__readonlyValue",{set:function(e){var r=this;n.runInAction((function(){if(r.__isList=t.isArrayLike(e),r.__isList)if(r.__toManyBucket){var n=r.__toManyBucket.__readonly;r.__toManyBucket.__readonly=!1,r.__toManyBucket.value=e,r.__toManyBucket.__readonly=n}else r.__toManyBucket=new Z(e,r.__collection);else r.__toOneBucket?(n=r.__toOneBucket.__readonly,r.__toOneBucket.__readonly=!1,r.__toOneBucket.value=e,r.__toOneBucket.__readonly=n):r.__toOneBucket=new $(e,r.__collection)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refValue",{get:function(){return this.__isList?this.__toManyBucket.refValue:this.__toOneBucket.refValue},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.refValue},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),a([n.observable],e.prototype,"__isList",void 0),a([n.computed],e.prototype,"value",null),a([n.computed],e.prototype,"refValue",null),a([n.computed],e.prototype,"snapshot",null),e}();function H(e,n,r){var o,a,s;if(!n&&0!==n)throw f("The type needs to be defined if the object is not an instance of the model.");var c=r.constructor,d=c.types.find((function(e){return e.type===n}));if(!d){var p=c.defaultModel;if(p)return new p(Object.assign({},e,((o={})[t.META_FIELD]=Object.assign({},e[t.META_FIELD]||{},{type:n}),o)),r);throw f("No model is defined for the type "+n+".")}var _=null===(a=null==e?void 0:e[t.META_FIELD])||void 0===a?void 0:a[u.IdField],h=t.getMeta(d,l.IdField),y=h&&null!==(s=null==e?void 0:e[h])&&void 0!==s?s:_,v=y&&r.findOne(n,y);if(v){var b=t.getMeta(d,l.Fields),M=Object.keys(i(i({},e),b)),m={};return M.forEach((function(t){var n,r,o=Boolean(null===(r=null===(n=b[t])||void 0===n?void 0:n.referenceDef)||void 0===r?void 0:r.property),i=A(d,e,t);o&&void 0===i&&!(t in e)||(m[t]=i)})),z(v,m)}return new d(d.preprocess(e),r)}var K=function(e){function r(r,o,i,a,u){void 0===a&&(a=[]),void 0===u&&(u=!1);var l=e.call(this,a.map((function(e){return e instanceof x?e:{id:e,type:V(r)}})),o)||this;return l.__collection=o,l.unique=u,l.modelType=V(r),l.sortMethod=i,t.makeObservable(l,{sortMethod:n.observable,length:n.computed,list:n.computed}),l}return o(r,e),Object.defineProperty(r.prototype,"length",{get:function(){return this.value.length},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"list",{get:function(){var e=this,t=this.value.slice();if(this.sortMethod){var r="string"==typeof this.sortMethod?function(t){return t[e.sortMethod]}:this.sortMethod;t.sort((function(e,t){return r(e)===r(t)?0:r(e)>r(t)?1:-1}))}var o=n.observable.array(t,{deep:!1});return n.intercept(o,this.__partialListUpdate.bind(this)),o},enumerable:!1,configurable:!0}),r.prototype.toJSON=function(){return{modelType:this.modelType,models:this.__rawList.map(j).slice(),unique:this.unique}},r.prototype.add=function(e){var r=this,o=t.mapItems(e,(function(e){return r.__collection.add(e,r.modelType)}));return n.runInAction((function(){t.mapItems(o,(function(e){r.unique&&-1!==r.__indexOf(e)||r.__rawList.push(e)}))})),o},r.prototype.hasItem=function(e){var t=j(e);return Boolean(this.__getList().find((function(e){return j(e)===t})))},r.prototype.remove=function(e){var t=this;n.runInAction((function(){var n=t.__getModel(t.__normalizeModel(e));n&&t.__rawList.remove(n)}))},r.prototype.removeAll=function(){var e=this;n.runInAction((function(){e.__rawList.replace([])}))},r.prototype.__partialListUpdate=function(e){var t=this;if("splice"===e.type){if(this.sortMethod&&e.added.length>0)throw f("New models can't be added directly to a sorted view list");var r=e.added.map(this.__normalizeModel.bind(this)),o=this.__rawList.slice(e.index,e.removedCount);return this.unique&&r.forEach((function(e){if(-1!==t.__indexOf(e)&&-1===t.__indexOf(e,o))throw f("The models in this view need to be unique")})),n.runInAction((function(){t.__rawList.splice.apply(t.__rawList,[e.index,e.removedCount].concat(r))})),null}return n.runInAction((function(){if(t.sortMethod&&e.newValue)throw f("New models can't be added directly to a sorted view list");var n=t.__getModel(t.__normalizeModel(e.newValue));if(n){var r=t.__indexOf(n);if(t.unique&&-1!==r&&r!==e.index)throw f("The models in this view need to be unique");t.__rawList[e.index]=n}})),null},r.prototype.__normalizeModel=function(e){return e instanceof x?e:{id:e,type:this.modelType}},r.prototype.__indexOf=function(e,t){return void 0===t&&(t=this.__rawList),t.findIndex((function(t){return t instanceof x&&e instanceof x?t===e:!(!D(t)||e instanceof x)&&t.id===e.id&&t.type===e.type}))},a([n.observable],r.prototype,"sortMethod",void 0),a([n.computed],r.prototype,"length",null),a([n.computed],r.prototype,"list",null),r}(Z),Q=function(){function e(e){var r=this;void 0===e&&(e=[]),this.__data=n.observable.array([],{deep:!1}),this.__views=[],this.__dataMap=n.observable({},void 0,{deep:!1}),this.__dataList=n.observable({},void 0,{deep:!1}),n.extendObservable(this,{}),t.isArrayLike(e)?this.insert(e):e&&"models"in e&&this.insert(e.models);var o=this.constructor,i=e&&"views"in e?e.views:{};Object.keys(o.views).forEach((function(e){var t=o.views[e],n=i[e]||t;r.addView(e,n.modelType,{mixins:t.mixins,models:n.models||[],sortMethod:t.sortMethod,unique:n.unique})}))}return e.prototype.addView=function(e,t,n){var r=void 0===n?{}:n,o=r.sortMethod,i=r.models,a=void 0===i?[]:i,u=r.unique,l=r.mixins;if(e in this&&this[e])throw f("The name is already taken");var s=l?l.reduce((function(e,t){return t(e)}),K):K;return this.__views.push(e),this[e]=new s(t,this,o,a,u),this[e]},e.prototype.insert=function(e){var n=function(e,n){return n.map((function(n){return function(e,n){var r;return H(n,null===(r=null==n?void 0:n[t.META_FIELD])||void 0===r?void 0:r[u.TypeField],e)}(e,n)}))}(this,e);return this.__insertModel(n),n},e.prototype.hasItem=function(e){var t=j(e);return Boolean(this.findOne(e,t))},e.prototype.add=function(e,n){return t.isArrayLike(e)?this.__addArray(e,n):this.__addSingle(e,n)},e.prototype.filter=function(e){return this.__data.filter(e)},e.prototype.findOne=function(e,t){if(t instanceof x)return t;if(k(e))return this.__findOneByType(e.type,e.id);if(null==t)throw new Error("The identifier is missing");return this.__findOneByType(e,t)},e.prototype.findAll=function(e){var t=this;if(e){var r=V(e);return r in this.__dataList||n.runInAction((function(){var e;n.set(t.__dataList,((e={})[r]=n.observable.array([]),e))})),this.__dataList[r]}return this.__data},e.prototype.find=function(e){return this.__data.find(e)||null},e.prototype.removeOne=function(e,t){var n=null;"object"==typeof e?n=e:t&&(n=this.findOne(e,t)),n&&this.__removeModel(n)},e.prototype.removeAll=function(e){this.__removeModel(this.findAll(e).slice())},e.prototype.reset=function(){this.__data.forEach((function(e){t.setMeta(e,u.Collection,void 0),y({oldValue:C(e),patchType:exports.PatchType.REMOVE},e)})),this.__data.replace([]),this.__dataList=n.observable({},{},{deep:!1}),this.__dataMap=n.observable({},{},{deep:!1})},e.prototype.toJSON=function(){var e=this,t={};return this.__views.forEach((function(n){t[n]=e[n].toJSON()})),{models:this.__data.map(C),views:t}},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.__data.length},enumerable:!1,configurable:!0}),e.prototype.getAllModels=function(){return this.__data.slice()},e.prototype.__findOneByType=function(e,t){var r=this,o=V(e);if(!o)return null;var i=o.toString(),a=t.toString();return n.runInAction((function(){var e;o in r.__dataMap?a in r.__dataMap[i]||n.set(r.__dataMap[i],a,null):n.set(r.__dataMap,i,n.observable.object(((e={})[a]=null,e),{},{deep:!1}))})),this.__dataMap[i][a]||null},e.prototype.__addArray=function(e,t){var n=this;return e.filter(Boolean).map((function(e){return n.__addSingle(e,t)}))},e.prototype.__addSingle=function(e,t){if(!e||"number"==typeof e||"string"==typeof e||k(e))return e;if(e instanceof x)return this.hasItem(e)||this.__insertModel(e),e;if(!t&&0!==t)throw f("The type needs to be defined if the object is not an instance of the model.");var n=V(t),r=H(e,n,this);return this.__insertModel(r,n),r},e.prototype.__removeModel=function(e,r,o){var i=this;if(t.isArrayLike(e))e.forEach((function(e){i.__removeModel(e,r,o)}));else{var a=r||V(e),u=o||j(e);y({oldValue:n.toJS(C(e)),patchType:exports.PatchType.REMOVE},e),n.runInAction((function(){i.__data.remove(e),i.__dataList[a].remove(e),n.set(i.__dataMap[a],u.toString(),void 0)})),this.__data.forEach((function(e){var n=t.getMeta(e,l.Fields,{},!0,!0);Object.keys(n||{}).map((function(n){return t.getMeta(e,"ref_"+n)})).filter(Boolean).forEach((function(n){t.isArrayLike(n.value)&&n.value.includes(e)?n.value=n.value.filter((function(t){return t!==e})):n.value===e&&(n.value=null)}))})),q(e,void 0)}},e.prototype.__insertModel=function(e,r,o){var i=this;if(t.isArrayLike(e))e.forEach((function(e){i.__insertModel(e,r,o)}));else{var a=F(e);if(a&&a!==this)throw f("A model can be in a single collection at once");var u=r||V(e),l=o||j(e),s=u.toString(),c=this.findOne(u,l);c?c!==e&&z(c,e):(n.runInAction((function(){var t;i.__data.push(e),u in i.__dataList?i.__dataList[u].push(e):n.set(i.__dataList,s,n.observable.array([e],{deep:!1})),u in i.__dataMap?n.set(i.__dataMap[u],l.toString(),e):n.set(i.__dataMap,s,n.observable.object(((t={})[l]=e,t),{},{deep:!1})),q(e,i)})),y({newValue:C(e),patchType:exports.PatchType.CRATE},e))}},e.prototype.__changeModelId=function(e,t,n){this.__dataMap[n][t]=this.__dataMap[n][e],delete this.__dataMap[n][e]},e.types=[],e.defaultModel=x,e.views={},a([n.computed],e.prototype,"length",null),e}();function X(e,t){for(var n=e;n;){if(n===t)return!0;n=Object.getPrototypeOf(n)}return!1}function ee(e){return X(e,x)}function te(e){return X(e,Q)}function ne(e,t,n){n&&"initializer"in n&&(n.initializer=void 0)}function re(e){return e instanceof x||ee(e)||k(e)?V(e):e}function oe(e,t,n,r){return e?{type:exports.ReferenceType.TO_ONE,model:re(e)}:t?{type:exports.ReferenceType.TO_ONE_OR_MANY,model:re(t)}:!!n&&{type:exports.ReferenceType.TO_MANY,model:re(n),property:r}}function ie(e){var n=void 0===e?{}:e,r=n.defaultValue,o=n.isIdentifier,i=n.isType,a=n.toOne,u=n.toOneOrMany,s=n.toMany,c=n.referenceProperty,f=n.parse,d=n.serialize;return function(e,n,p){ne(0,0,p);var _=function(e){return"function"==typeof e?e:e.constructor}(e),h=t.getMeta(_,l.Fields,{});h[n]={referenceDef:oe(a,u,s,c),defaultValue:r},t.setMeta(_,l.Fields,h),t.setMeta(_,l.MapParse+"_"+n,f),t.setMeta(_,l.MapSerialize+"_"+n,d),o&&t.setMeta(_,l.IdField,n),i&&t.setMeta(_,l.TypeField,n)}}function ae(e,t){return void 0===t&&(t={}),function(n,r,o){ne(0,0,o),Object.hasOwnProperty.call(n.constructor,"views")||(n.constructor.views={}),n.constructor.views[r]=Object.assign({modelType:e},t)}}var ue="@prop was deprecated, use @Attribute instead",le=Object.assign((function(e,n,r){t.deprecated(ue),ie()(e,n,r)}),{defaultValue:function(e){return t.deprecated(ue),ie({defaultValue:e})},toOne:function(e){return t.deprecated(ue),ie({toOne:e})},toMany:function(e,n){return t.deprecated(ue),ie({toMany:e,referenceProperty:n})},toOneOrMany:function(e){return t.deprecated(ue),ie({toOneOrMany:e})},identifier:ie({isIdentifier:!0}),type:ie({isType:!0})}),se=ae;function ce(e){var t=function(e){switch(e){case exports.PatchType.CRATE:return exports.PatchType.REMOVE;case exports.PatchType.REMOVE:return exports.PatchType.CRATE;default:return exports.PatchType.UPDATE}}(e.patchType);return{model:e.model,newValue:e.oldValue,oldValue:e.newValue,patchType:t}}function fe(e){if(te(e))return function(e){function t(t){var n=e.call(this,t)||this;return n.__patchListeners=[],Object.defineProperty(n,"__patchListeners",{enumerable:!1}),n}return o(t,e),t.prototype.applyPatch=function(e){var t=this.findOne(e.model.type,e.model.id);if(e.patchType===exports.PatchType.REMOVE)t&&this.removeOne(t);else if(e.patchType===exports.PatchType.UPDATE){if(!t||!e.newValue)throw f(t?"New patch value isn't set for an update patch":"The model should already exist for an update patch");z(t,e.newValue)}else{if(t)throw f("The model shouldn't exist before a create patch");if(!e.newValue)throw f("New patch value isn't set for a create patch");this.add(e.newValue,e.model.type)}},t.prototype.undoPatch=function(e){this.applyPatch(ce(e))},t.prototype.onPatch=function(e){var t=this;return this.__patchListeners.push(e),function(){t.__patchListeners=t.__patchListeners.filter((function(t){return t!==e}))}},t}(e);if(ee(e))return function(e){function n(n,r){var o=e.call(this,n,r)||this;return t.setMeta(o,u.PatchListeners,[]),o}return o(n,e),n.prototype.applyPatch=function(e){e.model.type===V(this)&&e.model.id===j(this)&&z(this,e.newValue||{})},n.prototype.undoPatch=function(e){this.applyPatch(ce(e))},n.prototype.onPatch=function(e){var n=this,r=t.getMeta(this,u.PatchListeners,[]);return r.push(e),function(){t.setMeta(n,u.PatchListeners,r.filter((function(t){return t!==e})))}},n}(e);throw f("Only Models and Collections can be decorated with patches")}function de(e){var r=e;if(!ee(r))throw f("This mixin can only decorate models");var i=function(){function e(e){this.__instance=e}return Object.defineProperty(e.prototype,"collection",{get:function(){return F(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return j(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"original",{get:function(){var e=t.getMeta(this.__instance,u.OriginalId),n=F(this.__instance);return e&&(null==n?void 0:n.findOne(this.__instance,e))||void 0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refs",{get:function(){var e=this,n=t.getMeta(this.__instance,u.Fields,{}),r={};return Object.keys(n).filter((function(e){return n[e].referenceDef})).forEach((function(n){var o=t.getMeta(e.__instance,"ref_"+n);o&&(r[n]=o&&o.refValue||null)})),r},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dirty",{get:function(){var e=this,n=t.getMeta(this.__instance,u.Fields,{}),r={};return Object.keys(n).forEach((function(t){r[t]=W(e.__instance,t)})),r},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"snapshot",{get:function(){return C(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return V(this.__instance)},enumerable:!1,configurable:!0}),a([n.computed],e.prototype,"collection",null),a([n.computed],e.prototype,"id",null),a([n.computed],e.prototype,"original",null),a([n.computed],e.prototype,"refs",null),a([n.computed],e.prototype,"dirty",null),a([n.computed],e.prototype,"snapshot",null),a([n.computed],e.prototype,"type",null),e}();return function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.meta=new i(r),Object.defineProperty(r,"meta",{enumerable:!1}),r}return o(t,e),t}(r)}function pe(e){var t=e;if(!ee(e))throw f("This mixin can only decorate models");return function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.update=function(e){z(this,e)},t.prototype.clone=function(){return R(this)},t.prototype.assign=function(e,t){J(this,e,t)},t.prototype.addReference=function(e,t,n){O(this,e,{type:n.type,model:V(n.model)},t)},t.prototype.commit=function(){Y(this)},t.prototype.revert=function(){U(this)},t.prototype.toJSON=function(){return C(this)},t}(t)}var _e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return o(n,e),n.prototype.valueOf=function(){var e=this.meta.snapshot;return delete e[t.META_FIELD],Object.assign({},e,{meta:{id:this.meta.id,type:this.meta.type}})},n.prototype.toString=function(){return JSON.stringify(this.valueOf(),null,2)},n}(fe(pe(de(x)))),he=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.defaultModel=_e,t}(fe(Q)),ye={ToMany:Z,ToOne:$,ToOneOrMany:G};exports.Attribute=ie,exports.Bucket=ye,exports.Collection=he,exports.Model=_e,exports.PureCollection=Q,exports.PureModel=x,exports.View=K,exports.ViewAttribute=ae,exports.assignModel=J,exports.cloneModel=R,exports.commitModel=Y,exports.getModelCollection=F,exports.getModelId=j,exports.getModelType=V,exports.getOriginalModel=function(e){var n=F(e),r=t.getMeta(e,u.OriginalId);if(r){if(!n)throw f("The model needs to be in a collection to be referenceable");return n.findOne(e,r)}throw f("The given model is not a clone.")},exports.getRef=d,exports.getRefId=function(e,n){var r=t.getMeta(e,"ref_"+n);return r?r.refValue:null},exports.initModelRef=O,exports.isAttributeDirty=W,exports.isCollection=te,exports.isModel=ee,exports.isView=function(e){return X(e,K)},exports.modelMapParse=A,exports.modelMapSerialize=E,exports.modelToDirtyJSON=function(e){var t=i({},C(e));return Object.keys(e).forEach((function(n){W(e,n)||delete t[n]})),t},exports.modelToJSON=C,exports.prop=le,exports.revertModel=U,exports.updateModel=z,exports.updateModelId=function(e,r){n.runInAction((function(){var n=F(e),o=j(e),i=V(e);t.setMeta(e,u.IdField,r),n&&n.__changeModelId(o,r,i),function(e,n,r,o){var i=F(e);i&&i.getAllModels().forEach((function(e){(function(e,n){var r=t.getMeta(e,l.Fields,{},!0,!0);return Object.keys(r).filter((function(e){return r[e].referenceDef})).filter((function(e){return!r[e].referenceDef.property})).filter((function(e){return r[e].referenceDef.model===n}))})(e,o).map((function(n){return t.getMeta(e,"ref_"+n)})).filter(Boolean).forEach((function(e){if(t.isArrayLike(e.value)){var i=e.value.findIndex((function(e){return j(e)===r&&V(e)===o}));-1!==i&&(e.value[i]=n)}else e.value&&j(e.value)===r&&V(e.value)===o&&(e.value={id:n,type:o})}))}))}(e,r,o,i)}))},exports.view=se,exports.withActions=pe,exports.withMeta=de,exports.withPatches=fe;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e,t=require("datx-utils"),n=require("mobx");(e=exports.ReferenceType||(exports.ReferenceType={}))[e.TO_ONE=0]="TO_ONE",e[e.TO_MANY=1]="TO_MANY",e[e.TO_ONE_OR_MANY=2]="TO_ONE_OR_MANY";var 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])})(e,t)};function o(e,t){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}).apply(this,arguments)};function a(e,t,n,r){var o,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,n):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,n,r);else for(var u=e.length-1;u>=0;u--)(o=e[u])&&(a=(i<3?o(a):i>3?o(t,n,a):o(t,n))||a);return i>3&&a&&Object.defineProperty(t,n,a),a}var u,l,s,c=/\$\{\s*([a-zA-Z0-9\-_]+)\s*\}/g;function f(e,t){return void 0===t&&(t={}),new Error(("[datx exception] "+function(e,t){for(var n=e,r=c.exec(n);r;)n=n.replace(r[0],t[r[1]]),r=c.exec(n);return n}(e,t)).replace(/\s+/g," "))}function d(e,n){var r=t.getMeta(e,"ref_"+n);return r?r.value:null}function p(e,n,r){var o;(null===(o=t.getMeta(e,u.Fields,{})[n])||void 0===o?void 0:o.referenceDef)&&(t.isArrayLike(e[n])?e[n].includes(r)||e[n].push(r):e[n]=r)}function _(e,n,r){t.isArrayLike(e[n])?e[n].remove(r):e[n]===r&&(e[n]=null)}function h(e){return 0===Object.keys(e).length}function y(e,n){var r=Object.assign({},e,{model:{id:j(n),type:V(n)}}),o=t.getMeta(n,u.PatchListeners,[]).slice(),i=F(n);i&&"__patchListeners"in i&&(i.__patchListeners||[]).forEach((function(e){o.push(e)})),o.forEach((function(e){e(r)}))}function v(e){var n=t.getMeta(e,u.Patch,{count:0,newValue:{},oldValue:{}});n.count++,t.setMeta(e,u.Patch,n)}function b(e,r){void 0===r&&(r=exports.PatchType.UPDATE);var o=t.getMeta(e,u.Patch,{count:0,newValue:{},oldValue:{}});if(o.count--,0===o.count){var i=n.toJS(o.newValue),a=n.toJS(o.oldValue);h(i)&&h(a)||y({newValue:i,oldValue:a,patchType:r},e),t.setMeta(e,u.Patch,{count:0,oldValue:{},newValue:{}})}else t.setMeta(e,u.Patch,o)}function M(e,n,r,o){v(e),function(e,n,r,o){var i=t.getMeta(e,u.Patch,{count:0,newValue:{},oldValue:{}});if(!(e[n]===r&&!o||o&&r===o.value)){var a=t.getMeta(e,u.Fields,{});n in i.oldValue||(o?i.oldValue[n]=o.value:n in a&&a[n].referenceDef?i.oldValue[n]=N(e[n]):i.oldValue[n]=e[n]),i.newValue[n]=n in a&&a[n].referenceDef?N(r):r,t.setMeta(e,u.Patch,i)}}(e,n,r,o),b(e)}function m(e,t,n,r,o){return"function"==typeof e?V(e(t,n,r,o)):e}function g(e,n,r,o,i){return t.mapItems(e,(function(e){return null==e?null:"object"!=typeof e||k(e)?"object"==typeof e&&k(e)?(null==n?void 0:n.findOne(e))||e:(null==n?void 0:n.findOne(m(r.referenceDef.model,e,o,i,n),e))||{id:e,type:m(r.referenceDef.model,e,o,i,n)}:(null==n?void 0:n.add(e,m(r.referenceDef.model,e,o,i,n)))||null}))}function O(e,r,o,i){var a=t.getMeta(e,u.Fields,{}),l=a[r]||{referenceDef:o},s=F(e);if(!s&&i)throw f("The model needs to be in a collection to be referenceable");if(o&&(a[r]={referenceDef:o}),l.referenceDef.property)t.assignComputed(e,r,(function(){return function(e,r){var o,i=null===(o=t.getMeta(e,u.Fields,{})[r])||void 0===o?void 0:o.referenceDef;if(!i||!i.property)return null;var a=F(e);if(!a)return null;var l=a.getAllModels().filter((function(t){return function(e,t,n){return null!==e[t]&&void 0!==e[t]&&(e[t]instanceof x?e[t]===n:e[t].includes(n))}(t,i.property,e)})),s=n.observable.array(l,{deep:!1});return n.intercept(s,(function(n){return function(e,n,r){var o,i=null===(o=t.getMeta(e,u.Fields,{})[n])||void 0===o?void 0:o.referenceDef;return i?"splice"===r.type?function(e,t,n,r){var o=r.property;return n.added.forEach((function(t){return p(t,o,e)})),e[t].slice(n.index,n.index+n.removedCount).forEach((function(t){return _(t,o,e)})),null}(e,n,r,i):function(e,n,r,o){var i=o.property,a=e[n].length>r.index?e[n][r.index]:null;return r.newValue&&p(r.newValue,i,e),a&&_(a,i,e),t.warn("This shouldn't have happened. Please open an issue: https://github.com/infinum/datx/issues/new"),null}(e,n,r,i):null}(e,r,n)})),s}(e,r)}),(function(e){!function(e,t,n){throw f("Back references are read only")}()}));else{var c=function(e){if(e===exports.ReferenceType.TO_ONE)return $;if(e===exports.ReferenceType.TO_ONE_OR_MANY)return G;if(e===exports.ReferenceType.TO_MANY)return Z;throw t.error("Unknown reference type")}(l.referenceDef.type),h=l.referenceDef.type===exports.ReferenceType.TO_MANY?[]:null;null!=i&&(h=g(i,s,l,e,r));var y=new c(h,s,!1,e,r,!0);M(e,r,y.value),t.setMeta(e,"ref_"+r,y),t.assignComputed(e,r,(function(){return d(e,r)}),(function(n){M(e,r,n),function(e,n,r){var o=t.getMeta(e,"ref_"+n);if(P(r)||t.isArrayLike(r)){var i=t.getMeta(e,u.Fields,{})[n],a=m(i.referenceDef.model,i.referenceDef.defaultValue,e,n,F(e));r=t.mapItems(r,(function(e){return P(e)?{id:e,type:a}:N(e)}))}o&&(o.value=r)}(e,r,g(n,s,l,e,r))}))}}function w(e,r,o){var i=t.getMeta(e,u.Fields,{})[r],a=t.getMeta(e.constructor,l.TypeField,"__datx__type__",!0),s=t.getMeta(e.constructor,l.IdField,"__datx__id__",!0);r===a?t.assignComputed(e,r,(function(){return V(e)}),(function(){throw f("Model type can't be changed after initialization.")})):r===s?t.assignComputed(e,r,(function(){return j(e)}),(function(){throw f("Model ID can't be updated directly. Use the `updateModelId` helper function instead.")})):i.referenceDef?O(e,r,void 0,o):(t.setMeta(e,"data__"+r,void 0),t.assignComputed(e,r,(function(){return t.getMeta(e,"data__"+r)}),(function(o){var i,a="object"!=typeof(i=o)||null===i||i instanceof x?o:n.observable(o);M(e,r,o),t.setMeta(e,"data__"+r,a)})),e[r]=o)}function T(e,n,r){var o=e.constructor,a=t.getMeta(e.constructor,l.Fields,{},!0,!0),s=null==n?void 0:n[t.META_FIELD],c=Object.assign({},a,null==s?void 0:s.fields);t.setMeta(e,u.Collection,r);var f=t.getMeta(e.constructor,l.TypeField,"__datx__type__",!0);t.setMeta(e,u.TypeField,I(n[f],null==s?void 0:s.type,o.type));var d=t.getMeta(e.constructor,l.IdField,"__datx__id__",!0);t.setMeta(e,u.IdField,I(n[d],null==s?void 0:s.id,(function(){return o.getAutoId()}))),t.setMeta(e,u.OriginalId,null==s?void 0:s.originalId),Object.keys(n).filter((function(e){return e!==t.META_FIELD})).filter((function(e){return!(e in c)})).forEach((function(e){var r=n[e],o=r instanceof x||t.isArrayLike(r)&&r.length&&(r[0]instanceof x||k(r[0]))||k(r);c[e]={referenceDef:!!o&&{type:exports.ReferenceType.TO_ONE_OR_MANY,model:V(r)}}})),t.setMeta(e,u.Fields,c),Object.keys(c).forEach((function(t){var r,a=c[t],u=i(((r={})[t]=a.defaultValue,r),n);w(e,t,A(o,u,t))})),Y(e)}!function(e){e.Fields="fields",e.IdField="id",e.TypeField="type",e.Collection="collection",e.OriginalId="originalId",e.Patch="patch",e.PatchListeners="patchListeners",e.Commit="commit"}(u||(u={})),function(e){e.Fields="fields",e.IdField="idField",e.TypeField="typeField",e.MapParse="parse",e.MapSerialize="serialize"}(l||(l={})),(s=exports.PatchType||(exports.PatchType={}))[s.CRATE=0]="CRATE",s[s.UPDATE=1]="UPDATE",s[s.REMOVE=2]="REMOVE";var x=function(){function e(e,t){void 0===e&&(e={}),v(this),T(this,e,t),b(this,exports.PatchType.CRATE)}return e.preprocess=function(e){return e},e.getAutoId=function(){return"number"==typeof this.autoIdValue?--this.autoIdValue:this.autoIdValue},e.toJSON=function(){return this.type},e.type=t.DEFAULT_TYPE,e.autoIdValue=0,e.enableAutoId=!0,e}(),L=function(e,t){return e};function A(e,n,r){return t.getMeta(e,l.MapParse+"_"+r,L,!0)(n[r],n)}function E(e,n,r){return t.getMeta(e,l.MapSerialize+"_"+r,L,!0)(n[r],n)}function k(e){return t.isArrayLike(e)?e.every(k):"object"==typeof e&&null!==e&&"type"in e&&"id"in e&&2===Object.keys(e).length}function P(e){return"string"==typeof e||"number"==typeof e}function I(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];if(0===e.length)return null;for(var n=-1;++n<e.length;){var r=e[n];if("function"==typeof r&&(r=r()),null!=r)return r}return null}function V(e){return"function"==typeof e||k(e)?e.type:"object"==typeof e?t.getMeta(e,u.TypeField)||e.constructor.type:e}function j(e){if(e instanceof x){var n=t.getMeta(e,u.IdField);if(void 0!==n)return n;throw f("Model without an ID")}return e}function F(e){return t.getMeta(e,u.Collection)}function D(e){return!(e instanceof x)}function N(e){return e instanceof x?{id:j(e),type:V(e)}:e}var B=[u.Patch,u.PatchListeners,u.Collection,u.Commit,u.OriginalId,"get__","set__","data__","ref_"];function C(e){var r,o,i,a,l=t.getMetaObj(e),s=t.getMeta(e,u.Fields,{}),c=Object.keys(l).filter((function(e){return!B.some((function(t){return e.startsWith(t)}))})),f=((r={})[t.META_FIELD]=Object.assign({},(i=c.map((function(e){return[e,l[e]]})),a={},i.forEach((function(e){var t=e[0],n=e[1];a[t]=n})),a),((o={})[u.IdField]=j(e),o[u.TypeField]=V(e),o[u.Collection]=void 0,o)),r);return Object.keys(s).forEach((function(n){if(s[n].referenceDef){var r=t.getMeta(e,"ref_"+n);f[n]=(null==r?void 0:r.snapshot)||null}else f[n]=E(e.constructor,e,n)})),n.toJS(f)}function R(e){var n=C(e),r=n[t.META_FIELD]||{};r[u.OriginalId]=r[u.IdField],delete r[u.IdField];var o=F(e);if(o){var i=V(e);return o.add(n,i)}var a=e.constructor;return t.warn("The model is not in the collection. Referencing the original model won't be possible"),new a(n)}var S=[u.Fields,u.IdField,u.TypeField];function J(e,r,o){n.runInAction((function(){var i,a;if(!(e instanceof x))throw f("The given parameter is not a valid model");var l=t.getMeta(e,u.Fields,{}),s=t.isArrayLike(o)&&o.length>0&&o[0]instanceof x||o instanceof x;if(r in l){if(s&&!l[r].referenceDef)throw f("You should save this value as a reference.");e[r]=o}else s?n.extendObservable(l,((i={})[r]={referenceDef:{type:exports.ReferenceType.TO_ONE_OR_MANY,models:Array.from(new Set(t.mapItems(o,V)))}},i)):n.extendObservable(l,((a={})[r]={referenceDef:!1},a)),t.setMeta(e,u.Fields,l),w(e,r,o)}))}function z(e,n){v(e);var r=t.getMeta(e.constructor,l.IdField,"__datx__id__"),o=t.getMeta(e.constructor,l.TypeField,"__datx__type__"),i=Object.keys(n instanceof x?C(n):n);return t.mergeMeta(e,function(e,t){var n={};return Object.keys(e).filter((function(e){return!t.includes(e)})).forEach((function(t){n[t]=e[t]})),n}(n[t.META_FIELD]||{},S)),i.forEach((function(i){i!==t.META_FIELD&&i!==r&&i!==o?J(e,i,n[i]):i===t.META_FIELD&&Object.keys(n[i]||{}).forEach((function(r){S.includes(r)||t.setMeta(e,r,n[i][r])}))})),b(e),e}function q(e,n){t.setMeta(e,u.Collection,n);var r=t.getMeta(e,u.Fields,{});v(e),Object.keys(r).forEach((function(r){var o=t.getMeta(e,"ref_"+r);o&&o.setCollection(n)})),b(e)}function Y(e){t.setMeta(e,u.Commit,i(i({},C(e)),{__META__:void 0}))}function U(e){var n=t.getMeta(e,u.Commit);n&&z(e,n)}function W(e,n){var r,o,i=t.getMeta(e,u.Commit);if(i){var a=t.getMeta(e,u.Fields,{})[n];return void 0!==a&&(r=a.referenceDef?t.mapItems(e[n],N):e[n],o=i[n],!(JSON.stringify(r)===JSON.stringify(o)))}return!0}var Z=function(){function e(e,r,o,i,a,u){var l=this;if(void 0===e&&(e=[]),void 0===o&&(o=!1),void 0===u&&(u=!0),this.__readonly=o,this.__model=i,this.__key=a,this.__skipMissing=u,this.__rawList=n.observable.array([]),t.makeObservable(this),(null==e?void 0:e.length)>0&&!r)throw f("The model needs to be in a collection to be referenceable");if(e&&!t.isArrayLike(e))throw f("The reference must be an array of values.");n.runInAction((function(){l.__rawList.replace(e||[]),l.setCollection(r)}))}return e.prototype.setCollection=function(e){var t=this;this.__collection=e,this.__disposer&&this.__disposer(),e&&(this.__rawList.forEach((function(e,n){var r=t.__getModel(e);r&&(t.__rawList[n]=r)})),this.__disposer=n.reaction((function(){return t.__rawList.filter(D).filter(Boolean).filter((function(t){return e.findOne(t.type,t.id)})).length>0}),this.__reMap.bind(this)))},Object.defineProperty(e.prototype,"value",{get:function(){return this.__getList()},set:function(e){var r=this;if(this.__readonly)throw f("This is a read-only bucket");if(null===e)e=[];else if(!t.isArrayLike(e))throw f("The reference must be an array of values.");n.runInAction((function(){r.__rawList.replace(e),r.__model&&r.__key&&M(r.__model,r.__key,e)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.value.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refValue",{get:function(){return this.__rawList.map(N)},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.refValue.slice()},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),e.prototype.__getList=function(){var e=this,t=this.__rawList.map(this.__getModel.bind(this)).filter((function(t){return!e.__skipMissing||Boolean(t)})).filter((function(e){return Boolean(e&&F(e))})),r=n.observable.array(t,{deep:!1});return n.intercept(r,this.__partialRawListUpdate.bind(this)),r},e.prototype.__getModel=function(e){if(e instanceof x||null===e)return e;if(!this.__collection)throw f("The model needs to be in a collection to be referenceable");return this.__collection.findOne(e.type,e.id)},e.prototype.__partialRawListUpdate=function(e){var t=this;if(this.__readonly)throw f("This is a read-only bucket");if("splice"===e.type){var r=e.added;return n.runInAction((function(){t.__rawList.slice(e.index,e.removedCount),t.__rawList.splice.apply(t.__rawList,[e.index,e.removedCount].concat(r))})),null}return n.runInAction((function(){var n=t.__getModel(e.newValue);n&&(t.__rawList[e.index]=n)})),null},e.prototype.__reMap=function(){for(var e=0;e<this.__rawList.length;e++)if(D(this.__rawList[e])){var t=this.__getModel(this.__rawList[e]);t&&(this.__rawList[e]=t)}},a([n.computed],e.prototype,"value",null),a([n.computed],e.prototype,"length",null),a([n.computed],e.prototype,"refValue",null),a([n.computed],e.prototype,"snapshot",null),e}(),$=function(){function e(e,n,r,o,i,a){if(void 0===r&&(r=!1),void 0===a&&(a=!0),this.__collection=n,this.__readonly=r,this.__model=o,this.__key=i,this.__skipMissing=a,this.__rawValue=null,t.makeObservable(this),e&&!this.__collection)throw f("The model needs to be in a collection to be referenceable");if(t.isArrayLike(e))throw f("The reference can't be an array of values.");if(!(k(e)||e instanceof x||null===e))throw f("The value needs to be a reference");this.__rawValue=e}return e.prototype.setCollection=function(e){this.__collection=e},Object.defineProperty(e.prototype,"value",{get:function(){return this.__rawValue?this.__getModel(this.__rawValue):null},set:function(e){if(!this.__collection)throw f("The model needs to be in a collection to be referenceable");if(this.__readonly)throw f("This is a read-only bucket");if(t.isArrayLike(e))throw f("The reference can't be an array of values.");if(!(k(e)||e instanceof x||null===e))throw f("The value needs to be a reference");this.__rawValue=e,this.__model&&this.__key&&M(this.__model,this.__key,e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refValue",{get:function(){return this.__rawValue?N(this.__rawValue):null},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.refValue},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),e.prototype.__getModel=function(e){if(e instanceof x||null===e)return e;if(!this.__collection)throw f("The model needs to be in a collection to be referenceable");return this.__collection.findOne(e.type,e.id)||(this.__skipMissing?null:e)},a([n.observable],e.prototype,"__rawValue",void 0),a([n.computed],e.prototype,"value",null),a([n.computed],e.prototype,"refValue",null),a([n.computed],e.prototype,"snapshot",null),e}(),G=function(){function e(e,r,o,i,a,u){var l=this;void 0===o&&(o=!1),void 0===u&&(u=!0),this.__collection=r,this.__readonly=o,this.__model=i,this.__key=a,this.__skipMissing=u,this.__isList=!0,t.makeObservable(this),n.runInAction((function(){l.__isList=t.isArrayLike(e),l.__isList?l.__toManyBucket=new Z(e,r,o,i,a,u):l.__toOneBucket=new $(e,r,o,i,a,u)}))}return e.prototype.setCollection=function(e){this.__collection=e,this.__toManyBucket&&this.__toManyBucket.setCollection(e),this.__toOneBucket&&this.__toOneBucket.setCollection(e)},Object.defineProperty(e.prototype,"value",{get:function(){return this.__isList?this.__toManyBucket.value:this.__toOneBucket.value},set:function(e){var r=this;n.runInAction((function(){r.__isList=t.isArrayLike(e),r.__isList?r.__toManyBucket?r.__toManyBucket.value=e:r.__toManyBucket=new Z(e,r.__collection):r.__toOneBucket?r.__toOneBucket.value=e:r.__toOneBucket=new $(e,r.__collection)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"__readonlyValue",{set:function(e){var r=this;n.runInAction((function(){if(r.__isList=t.isArrayLike(e),r.__isList)if(r.__toManyBucket){var n=r.__toManyBucket.__readonly;r.__toManyBucket.__readonly=!1,r.__toManyBucket.value=e,r.__toManyBucket.__readonly=n}else r.__toManyBucket=new Z(e,r.__collection);else r.__toOneBucket?(n=r.__toOneBucket.__readonly,r.__toOneBucket.__readonly=!1,r.__toOneBucket.value=e,r.__toOneBucket.__readonly=n):r.__toOneBucket=new $(e,r.__collection)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refValue",{get:function(){return this.__isList?this.__toManyBucket.refValue:this.__toOneBucket.refValue},enumerable:!1,configurable:!0}),e.prototype.toJSON=function(){return this.refValue},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),a([n.observable],e.prototype,"__isList",void 0),a([n.computed],e.prototype,"value",null),a([n.computed],e.prototype,"refValue",null),a([n.computed],e.prototype,"snapshot",null),e}();function H(e,n,r){var o,a,s;if(!n&&0!==n)throw f("The type needs to be defined if the object is not an instance of the model.");var c=r.constructor,d=c.types.find((function(e){return e.type===n}));if(!d){var p=c.defaultModel;if(p)return new p(Object.assign({},e,((o={})[t.META_FIELD]=Object.assign({},e[t.META_FIELD]||{},{type:n}),o)),r);throw f("No model is defined for the type "+n+".")}var _=null===(a=null==e?void 0:e[t.META_FIELD])||void 0===a?void 0:a[u.IdField],h=t.getMeta(d,l.IdField),y=h&&null!==(s=null==e?void 0:e[h])&&void 0!==s?s:_,v=y&&r.findOne(n,y);if(v){var b=t.getMeta(d,l.Fields),M=Object.keys(i(i({},e),b)),m={};return M.forEach((function(t){var n,r,o=Boolean(null===(r=null===(n=b[t])||void 0===n?void 0:n.referenceDef)||void 0===r?void 0:r.property),i=A(d,e,t);o&&void 0===i&&!(t in e)||(m[t]=i)})),z(v,m)}return new d(d.preprocess(e),r)}var K=function(e){function r(r,o,i,a,u){void 0===a&&(a=[]),void 0===u&&(u=!1);var l=e.call(this,a.map((function(e){return e instanceof x?e:{id:e,type:V(r)}})),o)||this;return l.__collection=o,l.unique=u,l.modelType=V(r),l.sortMethod=i,t.makeObservable(l,{sortMethod:n.observable,length:n.computed,list:n.computed}),l}return o(r,e),Object.defineProperty(r.prototype,"length",{get:function(){return this.value.length},enumerable:!1,configurable:!0}),Object.defineProperty(r.prototype,"list",{get:function(){var e=this,t=this.value.slice();if(this.sortMethod){var r="string"==typeof this.sortMethod?function(t){return t[e.sortMethod]}:this.sortMethod;t.sort((function(e,t){return r(e)===r(t)?0:r(e)>r(t)?1:-1}))}var o=n.observable.array(t,{deep:!1});return n.intercept(o,this.__partialListUpdate.bind(this)),o},enumerable:!1,configurable:!0}),r.prototype.toJSON=function(){return{modelType:this.modelType,models:this.__rawList.map(j).slice(),unique:this.unique}},r.prototype.add=function(e){var r=this,o=t.mapItems(e,(function(e){return r.__collection.add(e,r.modelType)}));return n.runInAction((function(){t.mapItems(o,(function(e){r.unique&&-1!==r.__indexOf(e)||r.__rawList.push(e)}))})),o},r.prototype.hasItem=function(e){var t=j(e);return Boolean(this.__getList().find((function(e){return j(e)===t})))},r.prototype.remove=function(e){var t=this;n.runInAction((function(){var n=t.__getModel(t.__normalizeModel(e));n&&t.__rawList.remove(n)}))},r.prototype.removeAll=function(){var e=this;n.runInAction((function(){e.__rawList.replace([])}))},r.prototype.__partialListUpdate=function(e){var t=this;if("splice"===e.type){if(this.sortMethod&&e.added.length>0)throw f("New models can't be added directly to a sorted view list");var r=e.added.map(this.__normalizeModel.bind(this)),o=this.__rawList.slice(e.index,e.removedCount);return this.unique&&r.forEach((function(e){if(-1!==t.__indexOf(e)&&-1===t.__indexOf(e,o))throw f("The models in this view need to be unique")})),n.runInAction((function(){t.__rawList.splice.apply(t.__rawList,[e.index,e.removedCount].concat(r))})),null}return n.runInAction((function(){if(t.sortMethod&&e.newValue)throw f("New models can't be added directly to a sorted view list");var n=t.__getModel(t.__normalizeModel(e.newValue));if(n){var r=t.__indexOf(n);if(t.unique&&-1!==r&&r!==e.index)throw f("The models in this view need to be unique");t.__rawList[e.index]=n}})),null},r.prototype.__normalizeModel=function(e){return e instanceof x?e:{id:e,type:this.modelType}},r.prototype.__indexOf=function(e,t){return void 0===t&&(t=this.__rawList),t.findIndex((function(t){return t instanceof x&&e instanceof x?t===e:!(!D(t)||e instanceof x)&&t.id===e.id&&t.type===e.type}))},a([n.observable],r.prototype,"sortMethod",void 0),a([n.computed],r.prototype,"length",null),a([n.computed],r.prototype,"list",null),r}(Z),Q=function(){function e(e){var r=this;void 0===e&&(e=[]),this.__data=n.observable.array([],{deep:!1}),this.__views=[],this.__dataMap=n.observable({},void 0,{deep:!1}),this.__dataList=n.observable({},void 0,{deep:!1}),n.extendObservable(this,{}),t.isArrayLike(e)?this.insert(e):e&&"models"in e&&this.insert(e.models);var o=this.constructor,i=e&&"views"in e?e.views:{};Object.keys(o.views).forEach((function(e){var t=o.views[e],n=i[e]||t;r.addView(e,n.modelType,{mixins:t.mixins,models:n.models||[],sortMethod:t.sortMethod,unique:n.unique})}))}return e.prototype.addView=function(e,t,n){var r=void 0===n?{}:n,o=r.sortMethod,i=r.models,a=void 0===i?[]:i,u=r.unique,l=r.mixins;if(e in this&&this[e])throw f("The name is already taken");var s=l?l.reduce((function(e,t){return t(e)}),K):K;return this.__views.push(e),this[e]=new s(t,this,o,a,u),this[e]},e.prototype.insert=function(e){var n=function(e,n){return n.map((function(n){return function(e,n){var r;return H(n,null===(r=null==n?void 0:n[t.META_FIELD])||void 0===r?void 0:r[u.TypeField],e)}(e,n)}))}(this,e);return this.__insertModel(n),n},e.prototype.hasItem=function(e){var t=j(e);return Boolean(this.findOne(e,t))},e.prototype.add=function(e,n){return t.isArrayLike(e)?this.__addArray(e,n):this.__addSingle(e,n)},e.prototype.filter=function(e){return this.__data.filter(e)},e.prototype.findOne=function(e,t){if(t instanceof x)return t;if(k(e))return this.__findOneByType(e.type,e.id);if(null==t)throw new Error("The identifier is missing");return this.__findOneByType(e,t)},e.prototype.findAll=function(e){var t=this;if(e){var r=V(e);return r in this.__dataList||n.runInAction((function(){var e;n.set(t.__dataList,((e={})[r]=n.observable.array([]),e))})),this.__dataList[r]}return this.__data},e.prototype.find=function(e){return this.__data.find(e)||null},e.prototype.removeOne=function(e,t){var n=null;"object"==typeof e?n=e:t&&(n=this.findOne(e,t)),n&&this.__removeModel(n)},e.prototype.removeAll=function(e){this.__removeModel(this.findAll(e).slice())},e.prototype.reset=function(){this.__data.forEach((function(e){t.setMeta(e,u.Collection,void 0),y({oldValue:C(e),patchType:exports.PatchType.REMOVE},e)})),this.__data.replace([]),this.__dataList=n.observable({},{},{deep:!1}),this.__dataMap=n.observable({},{},{deep:!1})},e.prototype.toJSON=function(){var e=this,t={};return this.__views.forEach((function(n){t[n]=e[n].toJSON()})),{models:this.__data.map(C),views:t}},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"length",{get:function(){return this.__data.length},enumerable:!1,configurable:!0}),e.prototype.getAllModels=function(){return this.__data.slice()},e.prototype.__findOneByType=function(e,t){var r=this,o=V(e);if(!o)return null;var i=o.toString(),a=t.toString();return n.runInAction((function(){var e;o in r.__dataMap?a in r.__dataMap[i]||n.set(r.__dataMap[i],a,null):n.set(r.__dataMap,i,n.observable.object(((e={})[a]=null,e),{},{deep:!1}))})),this.__dataMap[i][a]||null},e.prototype.__addArray=function(e,t){var n=this;return e.filter(Boolean).map((function(e){return n.__addSingle(e,t)}))},e.prototype.__addSingle=function(e,t){if(!e||"number"==typeof e||"string"==typeof e||k(e))return e;if(e instanceof x)return this.hasItem(e)||this.__insertModel(e),e;if(!t&&0!==t)throw f("The type needs to be defined if the object is not an instance of the model.");var n=V(t),r=H(e,n,this);return this.__insertModel(r,n),r},e.prototype.__removeModel=function(e,r,o){var i=this;if(t.isArrayLike(e))e.forEach((function(e){i.__removeModel(e,r,o)}));else{var a=r||V(e),u=o||j(e);y({oldValue:n.toJS(C(e)),patchType:exports.PatchType.REMOVE},e),n.runInAction((function(){i.__data.remove(e),i.__dataList[a].remove(e),n.set(i.__dataMap[a],u.toString(),void 0)})),this.__data.forEach((function(e){var n=t.getMeta(e,l.Fields,{},!0,!0);Object.keys(n||{}).map((function(n){return t.getMeta(e,"ref_"+n)})).filter(Boolean).forEach((function(n){t.isArrayLike(n.value)&&n.value.includes(e)?n.value=n.value.filter((function(t){return t!==e})):n.value===e&&(n.value=null)}))})),q(e,void 0)}},e.prototype.__insertModel=function(e,r,o){var i=this;if(t.isArrayLike(e))e.forEach((function(e){i.__insertModel(e,r,o)}));else{var a=F(e);if(a&&a!==this)throw f("A model can be in a single collection at once");var u=r||V(e),l=o||j(e),s=u.toString(),c=this.findOne(u,l);c?c!==e&&z(c,e):(n.runInAction((function(){var t;i.__data.push(e),u in i.__dataList?i.__dataList[u].push(e):n.set(i.__dataList,s,n.observable.array([e],{deep:!1})),u in i.__dataMap?n.set(i.__dataMap[u],l.toString(),e):n.set(i.__dataMap,s,n.observable.object(((t={})[l]=e,t),{},{deep:!1})),q(e,i)})),y({newValue:C(e),patchType:exports.PatchType.CRATE},e))}},e.prototype.__changeModelId=function(e,t,n){this.__dataMap[n][t]=this.__dataMap[n][e],delete this.__dataMap[n][e]},e.types=[],e.defaultModel=x,e.views={},a([n.computed],e.prototype,"length",null),e}();function X(e,t){for(var n=e;n;){if(n===t)return!0;n=Object.getPrototypeOf(n)}return!1}function ee(e){return X(e,x)}function te(e){return X(e,Q)}function ne(e,t,n){n&&"initializer"in n&&(n.initializer=void 0)}function re(e){return e instanceof x||ee(e)||k(e)?V(e):e}function oe(e,t,n,r){return e?{type:exports.ReferenceType.TO_ONE,model:re(e)}:t?{type:exports.ReferenceType.TO_ONE_OR_MANY,model:re(t)}:!!n&&{type:exports.ReferenceType.TO_MANY,model:re(n),property:r}}function ie(e){var n=void 0===e?{}:e,r=n.defaultValue,o=n.isIdentifier,i=n.isType,a=n.toOne,u=n.toOneOrMany,s=n.toMany,c=n.referenceProperty,f=n.parse,d=n.serialize;return function(e,n,p){ne(0,0,p);var _=function(e){return"function"==typeof e?e:e.constructor}(e),h=t.getMeta(_,l.Fields,{});h[n]={referenceDef:oe(a,u,s,c),defaultValue:r},t.setMeta(_,l.Fields,h),t.setMeta(_,l.MapParse+"_"+n,f),t.setMeta(_,l.MapSerialize+"_"+n,d),o&&t.setMeta(_,l.IdField,n),i&&t.setMeta(_,l.TypeField,n)}}function ae(e,t){return void 0===t&&(t={}),function(n,r,o){ne(0,0,o),Object.hasOwnProperty.call(n.constructor,"views")||(n.constructor.views={}),n.constructor.views[r]=Object.assign({modelType:e},t)}}var ue="@prop was deprecated, use @Attribute instead",le=Object.assign((function(e,n,r){t.deprecated(ue),ie()(e,n,r)}),{defaultValue:function(e){return t.deprecated(ue),ie({defaultValue:e})},toOne:function(e){return t.deprecated(ue),ie({toOne:e})},toMany:function(e,n){return t.deprecated(ue),ie({toMany:e,referenceProperty:n})},toOneOrMany:function(e){return t.deprecated(ue),ie({toOneOrMany:e})},identifier:ie({isIdentifier:!0}),type:ie({isType:!0})}),se=ae;function ce(e){var t=function(e){switch(e){case exports.PatchType.CRATE:return exports.PatchType.REMOVE;case exports.PatchType.REMOVE:return exports.PatchType.CRATE;default:return exports.PatchType.UPDATE}}(e.patchType);return{model:e.model,newValue:e.oldValue,oldValue:e.newValue,patchType:t}}function fe(e){if(te(e))return function(e){function t(t){var n=e.call(this,t)||this;return n.__patchListeners=[],Object.defineProperty(n,"__patchListeners",{enumerable:!1}),n}return o(t,e),t.prototype.applyPatch=function(e){var t=this.findOne(e.model.type,e.model.id);if(e.patchType===exports.PatchType.REMOVE)t&&this.removeOne(t);else if(e.patchType===exports.PatchType.UPDATE){if(!t||!e.newValue)throw f(t?"New patch value isn't set for an update patch":"The model should already exist for an update patch");z(t,e.newValue)}else{if(t)throw f("The model shouldn't exist before a create patch");if(!e.newValue)throw f("New patch value isn't set for a create patch");this.add(e.newValue,e.model.type)}},t.prototype.undoPatch=function(e){this.applyPatch(ce(e))},t.prototype.onPatch=function(e){var t=this;return this.__patchListeners.push(e),function(){t.__patchListeners=t.__patchListeners.filter((function(t){return t!==e}))}},t}(e);if(ee(e))return function(e){function n(n,r){var o=e.call(this,n,r)||this;return t.setMeta(o,u.PatchListeners,[]),o}return o(n,e),n.prototype.applyPatch=function(e){e.model.type===V(this)&&e.model.id===j(this)&&z(this,e.newValue||{})},n.prototype.undoPatch=function(e){this.applyPatch(ce(e))},n.prototype.onPatch=function(e){var n=this,r=t.getMeta(this,u.PatchListeners,[]);return r.push(e),function(){t.setMeta(n,u.PatchListeners,r.filter((function(t){return t!==e})))}},n}(e);throw f("Only Models and Collections can be decorated with patches")}function de(e){var r=e;if(!ee(r))throw f("This mixin can only decorate models");var i=function(){function e(e){this.__instance=e}return Object.defineProperty(e.prototype,"collection",{get:function(){return F(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return j(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"original",{get:function(){var e=t.getMeta(this.__instance,u.OriginalId),n=F(this.__instance);return e&&(null==n?void 0:n.findOne(this.__instance,e))||void 0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refs",{get:function(){var e=this,n=t.getMeta(this.__instance,u.Fields,{}),r={};return Object.keys(n).filter((function(e){return n[e].referenceDef})).forEach((function(n){var o=t.getMeta(e.__instance,"ref_"+n);o&&(r[n]=o&&o.refValue||null)})),r},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dirty",{get:function(){var e=this,n=t.getMeta(this.__instance,u.Fields,{}),r={};return Object.keys(n).forEach((function(t){r[t]=W(e.__instance,t)})),r},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"snapshot",{get:function(){return C(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return V(this.__instance)},enumerable:!1,configurable:!0}),a([n.computed],e.prototype,"collection",null),a([n.computed],e.prototype,"id",null),a([n.computed],e.prototype,"original",null),a([n.computed],e.prototype,"refs",null),a([n.computed],e.prototype,"dirty",null),a([n.computed],e.prototype,"snapshot",null),a([n.computed],e.prototype,"type",null),e}();return function(e){function t(t,n){var r=e.call(this,t,n)||this;return r.meta=new i(r),Object.defineProperty(r,"meta",{enumerable:!1}),r}return o(t,e),t}(r)}function pe(e){var t=e;if(!ee(e))throw f("This mixin can only decorate models");return function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.prototype.update=function(e){z(this,e)},t.prototype.clone=function(){return R(this)},t.prototype.assign=function(e,t){J(this,e,t)},t.prototype.addReference=function(e,t,n){O(this,e,{type:n.type,model:V(n.model)},t)},t.prototype.commit=function(){Y(this)},t.prototype.revert=function(){U(this)},t.prototype.toJSON=function(){return C(this)},t}(t)}var _e=function(e){function n(){return null!==e&&e.apply(this,arguments)||this}return o(n,e),n.prototype.valueOf=function(){var e=this.meta.snapshot;return delete e[t.META_FIELD],Object.assign({},e,{meta:{id:this.meta.id,type:this.meta.type}})},n.prototype.toString=function(){return JSON.stringify(this.valueOf(),null,2)},n}(fe(pe(de(x)))),he=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return o(t,e),t.defaultModel=_e,t}(fe(Q)),ye={ToMany:Z,ToOne:$,ToOneOrMany:G};exports.Attribute=ie,exports.Bucket=ye,exports.Collection=he,exports.Model=_e,exports.PureCollection=Q,exports.PureModel=x,exports.View=K,exports.ViewAttribute=ae,exports.assignModel=J,exports.cloneModel=R,exports.commitModel=Y,exports.getModelCollection=F,exports.getModelId=j,exports.getModelType=V,exports.getOriginalModel=function(e){var n=F(e),r=t.getMeta(e,u.OriginalId);if(r){if(!n)throw f("The model needs to be in a collection to be referenceable");return n.findOne(e,r)}throw f("The given model is not a clone.")},exports.getRef=d,exports.getRefId=function(e,n){var r=t.getMeta(e,"ref_"+n);return r?r.refValue:null},exports.initModelRef=O,exports.isAttributeDirty=W,exports.isCollection=te,exports.isModel=ee,exports.isView=function(e){return X(e,K)},exports.modelMapParse=A,exports.modelMapSerialize=E,exports.modelToDirtyJSON=function(e){var t=i({},C(e));return Object.keys(e).forEach((function(n){W(e,n)||delete t[n]})),t},exports.modelToJSON=C,exports.prop=le,exports.revertModel=U,exports.updateModel=z,exports.updateModelId=function(e,r){n.runInAction((function(){var n=F(e),o=j(e),i=V(e);t.setMeta(e,u.IdField,r),n&&n.__changeModelId(o,r,i),function(e,n,r,o){var i=F(e);i&&i.getAllModels().forEach((function(e){(function(e,n){var r=t.getMeta(e,l.Fields,{},!0,!0);return Object.keys(r).filter((function(e){return r[e].referenceDef})).filter((function(e){return!r[e].referenceDef.property})).filter((function(e){return r[e].referenceDef.model===n}))})(e,o).map((function(n){return t.getMeta(e,"ref_"+n)})).filter(Boolean).forEach((function(e){if(t.isArrayLike(e.value)){var i=e.value.findIndex((function(e){return j(e)===r&&V(e)===o}));-1!==i&&(e.value[i]=n)}else e.value&&j(e.value)===r&&V(e.value)===o&&(e.value={id:n,type:o})}))}))}(e,r,o,i)}))},exports.view=se,exports.withActions=pe,exports.withMeta=de,exports.withPatches=fe;
{
"name": "datx",
"version": "2.0.0-beta.7",
"version": "2.0.0-beta.8",
"description": "A MobX data store",

@@ -62,4 +62,4 @@ "main": "dist/index.cjs.js",

"dependencies": {
"datx-utils": "^2.0.0-beta.7"
"datx-utils": "^2.0.0-beta.8"
}
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc