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.8 to 2.0.0-beta.9

2

dist/buckets/ToMany.d.ts

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

import { IObservableArray } from 'mobx';
import { IObservableArray } from 'datx-utils';
import { IModelRef } from '../interfaces/IModelRef';

@@ -3,0 +3,0 @@ import { PureCollection } from '../PureCollection';

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

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

import { IArrayChange, IArraySplice } from 'mobx';
import { IArrayChange, IArraySplice } from 'datx-utils';
import { PureModel } from '../PureModel';
export declare type TChange = IArraySplice<PureModel> | IArrayChange<PureModel>;

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

import { IRawModel } from 'datx-utils';
import { IObservableArray } from 'mobx';
import { IRawModel, IObservableArray } from 'datx-utils';
import { PureModel } from './PureModel';

@@ -4,0 +3,0 @@ import { IType } from './interfaces/IType';

@@ -17,2 +17,3 @@ import { IRawModel } from 'datx-utils';

get list(): Array<T>;
set list(list: Array<T>);
toJSON(): IRawView;

@@ -19,0 +20,0 @@ add(data: T | IRawModel | Record<string, any>): T;

{
"name": "datx",
"version": "2.0.0-beta.8",
"version": "2.0.0-beta.9",
"description": "A MobX data store",

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

"jest": "^26.4.2",
"mobx": "^6.0.0",
"rollup": "^2.28.2",

@@ -33,5 +32,2 @@ "rollup-plugin-exclude-dependencies-from-bundle": "^1.1.13",

},
"peerDependencies": {
"mobx": "^4.2.0 || ^5.5.0 || ^6.0.0"
},
"scripts": {

@@ -52,3 +48,3 @@ "test": "jest --coverage",

],
"testRegex": "test/(.*).ts$",
"testRegex": "test/(.*).test.ts$",
"globals": {

@@ -62,7 +58,10 @@ "ts-jest": {

"preset": "ts-jest",
"testMatch": null
"testMatch": null,
"setupFilesAfterEnv": [
"./test/setup.ts"
]
},
"dependencies": {
"datx-utils": "^2.0.0-beta.8"
"datx-utils": "^2.0.0-beta.9"
}
}

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