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

datx

Package Overview
Dependencies
Maintainers
10
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 0.15.4 to 0.15.5

.rpt2_cache/rpt2_0dc677e292e0f2cb585cc326e8daf36f9a4ec1ce/code/cache_/1436d2481afeccafe1a8a88c5ada36544f32bd2b

2

dist/index.cjs.js

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

"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var mobx=require("mobx"),datxUtils=require("datx-utils"),extendStatics=function(e,t){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(e,t)};function __extends(e,t){function o(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var __assign=function(){return(__assign=Object.assign||function(e){for(var t,o=1,r=arguments.length;o<r;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)};function __decorate(e,t,o,r){var n,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var s=e.length-1;0<=s;s--)(n=e[s])&&(a=(i<3?n(a):3<i?n(t,o,a):n(t,o))||a);return 3<i&&a&&Object.defineProperty(t,o,a),a}!function(e){e[e.CRATE=0]="CRATE",e[e.UPDATE=1]="UPDATE",e[e.REMOVE=2]="REMOVE"}(exports.PatchType||(exports.PatchType={}));var REGEX=/\$\{\s*([a-zA-Z0-9\-\_]+)\s*\}/g;function msg(e,t){for(var o=e,r=REGEX.exec(o);r;)o=o.replace(r[0],t[r[1]]),r=REGEX.exec(o);return o}function error(e,t){return void 0===t&&(t={}),new Error("[datx exception] "+msg(e,t))}var FieldType,UNDEFINED_TYPE="The type needs to be defined if the object is not an instance of the model.",UNDEFINED_MODEL="No model is defined for the type ${type}.",NOT_A_CLONE="The given model is not a clone.",REF_NEEDS_COLLECTION="The model needs to be in a collection to be referenceable",REF_SINGLE="The reference ${key} can't be an array of values.",REF_ARRAY="The reference ${key} must be an array of values.",NO_REFS="You should save this value as a reference.",BACK_REF_READ_ONLY="Back references are read only",ID_READONLY="Model ID can't be updated directly. Use the `updateModelId` helper function instead.",TYPE_READONLY="Model type can't be changed after initialization.",MODEL_SINGLE_COLLECTION="A model can be in a single collection at once",ID_REQUIRED="Model id is required (autoincrement is disabled)",WRONG_REF_TYPE="The new reference type doesn't match to the declared one.",MODEL_REQUIRED="The model type is a required parameter. Do you maybe have a circular dependency?",SORTED_NO_WRITE="New models can't be added directly to a sorted view list",UNIQUE_MODEL="The models in this view need to be unique",VIEW_NAME_TAKEN="The name is already taken",DECORATE_MODEL="This mixin can only decorate models";function reducePrototypeChain(e,t,o){for(var r=o,n=e;n;)r=t(r,n),n=Object.getPrototypeOf(n);return r}!function(e){e[e.ID=0]="ID",e[e.TYPE=1]="TYPE",e[e.DATA=2]="DATA"}(FieldType||(FieldType={})),function(e){e[e.TO_ONE=0]="TO_ONE",e[e.TO_MANY=1]="TO_MANY",e[e.TO_ONE_OR_MANY=2]="TO_ONE_OR_MANY"}(exports.ReferenceType||(exports.ReferenceType={}));var DATX_KEY=Symbol.for("datx metadata");function setMeta(e,t){Object.defineProperty(e,DATX_KEY,{enumerable:!1,value:t,writable:!1})}var DataStorage=function(){function e(){}return e.prototype.initModel=function(e){var t=mobx.observable({data:{},meta:{}});return setMeta(e,t),t},e.prototype.getModelData=function(e){return this.__getModelData(e).data},e.prototype.getModelDataKey=function(e,t){return this.__getModelData(e).data[t]},e.prototype.setModelData=function(e,t){var o=this.__getModelData(e);mobx.set(o.data,t)},e.prototype.setModelDataKey=function(e,t,o){var r;this.setModelData(e,((r={})[t]=o,r))},e.prototype.getModelMeta=function(e){var t=e[DATX_KEY];return t?t.meta:this.setModelMeta(e,{})},e.prototype.getModelMetaKey=function(e,t){return this.getModelMeta(e)[t]},e.prototype.setModelMeta=function(e,t){var o=this.__getModelData(e);return mobx.set(o.meta,t),o.meta},e.prototype.setModelMetaKey=function(e,t,o){var r;this.setModelMeta(e,((r={})[t]=o,r))},e.prototype.setModelClassMetaKey=function(e,t,o){var r,n=e[DATX_KEY];n||setMeta(e,n={data:{},meta:{},references:{}}),Object.assign(n.meta,((r={})[t]=o,r))},e.prototype.getModelClassMetaKey=function(e,o){return reducePrototypeChain(e,function(e,t){return e||(t[DATX_KEY]||{meta:{}}).meta[o]||null},null)},e.prototype.addModelDefaultField=function(e,t,o){var r,n,i=e[DATX_KEY];i?Object.assign(i.data,((r={})[t]=o,r)):setMeta(e,{data:(n={},n[t]=o,n),meta:{},references:{}})},e.prototype.getModelDefaults=function(e){var t=reducePrototypeChain(e,function(e,t){return e.concat((t[DATX_KEY]||{data:[]}).data)},[]);return Object.assign.apply(Object,[{}].concat(t.reverse()))},e.prototype.addModelClassReference=function(e,t,o){var r,n;if(!o.model&&0!==o.model)throw error(MODEL_REQUIRED);var i=e[DATX_KEY];i?Object.assign(i.references,((r={})[t]=o,r)):setMeta(e,{data:{},meta:{},references:(n={},n[t]=o,n)})},e.prototype.getModelClassReferences=function(e){var t=reducePrototypeChain(e,function(e,t){return e.concat((t[DATX_KEY]||{references:{}}).references)},[]);return Object.assign.apply(Object,[{}].concat(t.reverse()))},e.prototype.getModelReferenceOptions=function(e,t){return this.getModelMetaKey(e,"refs")[t]},e.prototype.__getModelData=function(e){return e[DATX_KEY]||this.initModel(e)},e}(),storage=new DataStorage;function getModelType(e){return"function"==typeof e?e.type:"object"==typeof e?getModelMetaKey(e,"type")||e.constructor.type:e}function getModelId(e){return e instanceof PureModel?getModelMetaKey(e,"id"):e}function getModelCollection(e){return getModelMetaKey(e,"collection")}function cloneModel(e){var t=e.constructor,o=modelToJSON(e),r=o[datxUtils.META_FIELD]||{};r.originalId=r.id,delete r.id;var n=new t(o),i=getModelCollection(e);return i?i.add(n):datxUtils.warn("The model is not in the collection. Referencing the original model won't be possible"),n}function getOriginalModel(e){var t=getModelCollection(e),o=getModelMetaKey(e,"originalId");if(o){if(!t)throw error(REF_NEEDS_COLLECTION);return t.find(e,o)}throw error(NOT_A_CLONE)}var READ_ONLY_META=["fields","id","refs","type"];function updateModel(o,r){var e=storage.getModelClassMetaKey(o.constructor,"id")||"id",n=storage.getModelClassMetaKey(o.constructor,"type")||"type",t=Object.keys(r instanceof PureModel?modelToJSON(r):r);return startAction(o),t.forEach(function(t){if(t!==datxUtils.META_FIELD&&t!==e&&t!==n)assignModel(o,t,r[t]);else if(t===datxUtils.META_FIELD){Object.keys(r[t]||{}).forEach(function(e){READ_ONLY_META.includes(e)||setModelMetaKey(o,e,r[t][e])})}}),endAction(o),o}function assignModel(e,t,o){var r=getModelMetaKey(e,"refs");if(startAction(e),t in r)assignModelRef(e,t,o);else{if(o instanceof PureModel)throw endAction(e),error(NO_REFS,{key:t});assignModelField(e,t,o)}endAction(e)}function assignModelField(e,t,o){-1!==getModelMetaKey(e,"fields").indexOf(t)?e[t]=o:initModelField(e,t,o)}function assignModelRef(e,t,o){e[t]=o}function getMetaKeyFromRaw(e,t,o){if(datxUtils.META_FIELD in e&&"object"==typeof e[datxUtils.META_FIELD]&&void 0!==e[datxUtils.META_FIELD])return(e[datxUtils.META_FIELD]||{})[t];if(o){var r=storage.getModelClassMetaKey(o,t);return r&&e[r]}return e&&e[t]}function modelToJSON(e){var t,o=mobx.toJS(storage.getModelData(e)),r=Object.assign({},storage.getModelMeta(e));delete r.collection,delete r.patch;var n=mobx.toJS(r),i={};Object.keys(n.refs||{}).forEach(function(e){i[e]={model:getModelType(n.refs[e].model),type:n.refs[e].type}}),n.refs=i,delete n.collection;var a=Object.assign(o,((t={})[datxUtils.META_FIELD]=n,t)),s=e.constructor,d=storage.getModelClassMetaKey(s,"id"),l=storage.getModelClassMetaKey(s,"type");return n&&d&&(a[d]=n.id),n&&l&&(a[l]=n.type),a}function getModelMetaKey(e,t){return storage.getModelMetaKey(e,t)}function setModelMetaKey(e,t,o){storage.setModelMetaKey(e,t,o)}function getModelClassRefs(e){return storage.getModelClassReferences(e)}function isEmptyObject(e){return 0===Object.keys(e).length}function reverseAction(e){switch(e){case exports.PatchType.CRATE:return exports.PatchType.REMOVE;case exports.PatchType.REMOVE:return exports.PatchType.CRATE;default:return exports.PatchType.UPDATE}}function triggerAction(e,t){var o=__assign({},e,{model:{id:getModelId(t),type:getModelType(t)}}),r=[];"__patchListeners"in t&&r.push.apply(r,t.__patchListeners||[]);var n=getModelCollection(t);n&&"__patchListeners"in n&&r.push.apply(r,n.__patchListeners||[]),r.forEach(function(e){e(o)})}function startAction(e){var t=storage.getModelMetaKey(e,"patch")||{count:0,oldValue:{},newValue:{}};t.count++,storage.setModelMetaKey(e,"patch",t)}function updateAction(e,t,o){var r=storage.getModelMetaKey(e,"patch")||{count:0,oldValue:{},newValue:{}};e[t]!==o&&(t in r.oldValue||(r.oldValue[t]=e[t]),r.newValue[t]=o,storage.setModelMetaKey(e,"patch",r))}function endAction(e,t){void 0===t&&(t=exports.PatchType.UPDATE);var o=storage.getModelMetaKey(e,"patch")||{count:0,oldValue:{},newValue:{}};if(o.count--,0===o.count){var r=mobx.toJS(o.newValue),n=mobx.toJS(o.oldValue);isEmptyObject(r)&&isEmptyObject(n)||triggerAction({newValue:r,oldValue:n,patchType:t},e),storage.setModelMetaKey(e,"patch",{count:0,oldValue:{},newValue:{}})}else storage.setModelMetaKey(e,"patch",o)}function modelAddReference(e,t,o){var r=storage.getModelReferenceOptions(e,t),n=getModelId(o),i=storage.getModelDataKey(e,t);r.type===exports.ReferenceType.TO_ONE?storage.setModelDataKey(e,t,n):r.type===exports.ReferenceType.TO_MANY||mobx.isObservableArray(i)?i.push(n):storage.setModelDataKey(e,t,o)}function modelRemoveReference(e,t,o){var r=storage.getModelReferenceOptions(e,t),n=getModelId(o),i=storage.getModelDataKey(e,t);r.type===exports.ReferenceType.TO_ONE?storage.setModelDataKey(e,t,null):r.type===exports.ReferenceType.TO_MANY||mobx.isObservableArray(i)?i.remove(n):storage.setModelDataKey(e,t,null)}function ensureModel(o,r){return function(e){var t=e;if(!(e instanceof PureModel)&&"object"==typeof e){if(!r)throw error(REF_NEEDS_COLLECTION);t=r.add(e,o.model)}return getModelId(t)}}function partialRefUpdate(e,t,o){var r=storage.getModelReferenceOptions(e,t),n=storage.getModelDataKey(e,t),i=getModelCollection(e);if("splice"!==o.type)return n[o.index]=ensureModel(r,i)(o.newValue),null;var a=o.added.map(ensureModel(r,i));return n.splice.apply(n,[o.index,o.removedCount].concat(a)),null}function backRefSplice(t,e,o,r){var n=r.property;return o.added.forEach(function(e){modelAddReference(e,n,t)}),t[e].slice(o.index,o.index+o.removedCount).forEach(function(e){modelRemoveReference(e,n,t)}),null}function backRefChange(e,t,o,r){var n=r.property,i=e[t].length>o.index?e[t][o.index]:null;return o.newValue&&modelAddReference(o.newValue,n,e),i&&modelRemoveReference(i,n,e),datxUtils.warn("This shouldn't have happened. Please open an issue: https://github.com/infinum/datx/issues/new"),null}function partialBackRefUpdate(e,t,o){var r=storage.getModelReferenceOptions(e,t);return"splice"===o.type?backRefSplice(e,t,o,r):backRefChange(e,t,o,r)}function getField(e,t){return storage.getModelDataKey(e,t)}function updateField(e,t,o,r){if(r===FieldType.TYPE)throw error(TYPE_READONLY);if(r===FieldType.ID)throw error(ID_READONLY);startAction(e),t in getModelMetaKey(e,"refs")?updateRef(e,t,o):(updateAction(e,t,o),storage.setModelDataKey(e,t,o)),endAction(e)}function hasBackRef(e,t,o){return null!==e[t]&&void 0!==e[t]&&(e[t]instanceof PureModel?e[t]===o:-1!==e[t].indexOf(o))}function getBackRef(t,o,r){var e=getModelType(r.model),n=getModelCollection(t);if(!n)return null;var i=n.findAll(e).filter(function(e){return hasBackRef(e,r.property,t)}),a=mobx.observable.array(i,{deep:!1});return mobx.intercept(a,function(e){return partialBackRefUpdate(t,o,e)}),a}function getNormalRef(t,o,r){var e=storage.getModelDataKey(t,o),n=getModelCollection(t);if(!n)return null;var i=datxUtils.mapItems(e,function(e){return e?n.find(r.model,e):e});if(r.type!==exports.ReferenceType.TO_MANY||i instanceof Array||(i=[i]),i instanceof Array){var a=mobx.observable.array(i,{deep:!1});return mobx.intercept(a,function(e){return partialRefUpdate(t,o,e)}),a}return i}function getRef(e,t){var o=storage.getModelReferenceOptions(e,t);return"string"==typeof o.property?getBackRef(e,t,o):getNormalRef(e,t,o)}function validateRef(e,t,o){if(e.type===exports.ReferenceType.TO_ONE&&t)throw error(REF_SINGLE,{key:o});if(e.type===exports.ReferenceType.TO_MANY&&!t)throw error(REF_ARRAY,{key:o});if(e.property)throw error(BACK_REF_READ_ONLY)}function updateRef(o,e,t){var r=storage.getModelReferenceOptions(o,e),n=r.type===exports.ReferenceType.TO_MANY?t||[]:t,i=n instanceof Array||mobx.isObservableArray(n);validateRef(r,i,e);var a=getModelCollection(o);startAction(o);var s=datxUtils.mapItems(t,function(e){if(e&&a){if(e instanceof PureModel)if(getModelType(e)!==getModelType(r.model))throw endAction(o),error(WRONG_REF_TYPE);var t=a.find(r.model,e);return t||"object"!=typeof e||(t=a.add(e,r.model)),endAction(o),getModelId(t||e)}if(e instanceof PureModel)throw endAction(o),error(REF_NEEDS_COLLECTION);return e});r.type===exports.ReferenceType.TO_MANY&&(s=s||[]),updateAction(o,e,s),storage.setModelDataKey(o,e,s),endAction(o)}function getModelRefsByType(e,t){var o=getModelMetaKey(e,"refs");return Object.keys(o).filter(function(e){return!o[e].property}).filter(function(e){return getModelType(o[e].model)===t})}function updateModelReferences(e,n,i,t){var o=getModelCollection(e);if(o)o.getAllModels().map(function(r){getModelRefsByType(r,t).forEach(function(e){var t=storage.getModelDataKey(r,e);if(t instanceof Array||mobx.isObservableArray(t)){var o=t.indexOf(i);-1!==o&&(t[o]=n)}else t===i&&storage.setModelDataKey(r,e,n)})})}function updateModelId(e,t){var o=getModelCollection(e),r=getModelId(e),n=getModelType(e);setModelMetaKey(e,"id",t);var i=e.constructor,a=storage.getModelClassMetaKey(i,"id");a&&setRefId(e,a,t),o&&o.__changeModelId(r,t,n),updateModelReferences(e,t,r,n)}function getRefId(e,t){return storage.getModelDataKey(e,t)}function setRefId(e,t,o){storage.setModelDataKey(e,t,o)}function initModelField(t,o,e,r){void 0===r&&(r=FieldType.DATA);var n=getModelMetaKey(t,"fields");r===FieldType.ID&&o in t&&delete t[o],storage.setModelDataKey(t,o,e),updateAction(t,o,e),-1===n.indexOf(o)&&n.push(o),datxUtils.assignComputed(t,o,function(){return getField(t,o)},function(e){updateField(t,o,e,r)})}function initModelRef(t,o,e,r){var n=(getModelMetaKey(t,"refs")[o]=e).type===exports.ReferenceType.TO_MANY;storage.setModelDataKey(t,o,n?[]:void 0),updateAction(t,o,n?[]:void 0),datxUtils.assignComputed(t,o,function(){return getRef(t,o)},function(e){updateRef(t,o,e)}),e.property||void 0===r||(t[o]=r)}function prepareFields(e,t,o){var r=o.constructor,n=t.fields?t.fields.slice():[],i=storage.getModelClassReferences(r),a=Object.assign({},i,t.refs),s=storage.getModelDefaults(r);return Object.keys(e).concat(Object.keys(s)).forEach(function(e){e in a||-1!==n.indexOf(e)||n.push(e)}),{defaults:s,fields:n,refs:a}}function initModelData(n,i,r,a){var e=prepareFields(i,r,n),s=e.defaults,t=e.fields,d=e.refs,o=n.constructor,l=storage.getModelClassMetaKey(o,"id"),c=storage.getModelClassMetaKey(o,"type");t.forEach(function(e){var t=FieldType.DATA,o=i[e];void 0===o&&(o=s[e]),e===(l||"id")?(t=FieldType.ID,o=r.id):e===c&&(t=FieldType.TYPE,o=r.type),initModelField(n,e,o,t)}),!l||l in t||initModelField(n,l,r.id,FieldType.ID),Object.keys(d).forEach(function(e){var t=d[e],o=i[e]||s[e]||void 0,r=a?a.add(o,getModelType(t.model)):o;initModelRef(n,e,t,r)})}function initModelMeta(e,t,o){var r=e.constructor,n=storage.getModelClassMetaKey(r,"id")||"id",i=storage.getModelClassMetaKey(r,"type"),a=i&&t[i]||getModelType(e),s=n&&t[n];if(!s){if(!r.enableAutoId)throw new Error(ID_REQUIRED);for(s=r.getAutoId();o&&o.find(a,s);)s=r.getAutoId()}var d,l={fields:[],id:s,refs:{},type:a},c={fields:[],refs:{}};if(datxUtils.META_FIELD in t&&t[datxUtils.META_FIELD]){var p=t[datxUtils.META_FIELD]||{};c.fields=p.fields,delete p.fields,c.refs=p.refs,delete p.refs,"type"in p&&(l.type=p.type),d=storage.setModelMeta(e,Object.assign(l,p)),delete t[datxUtils.META_FIELD]}else d=storage.setModelMeta(e,l);return Object.assign({},d,c)}function initModel(e,t,o){var r=e.constructor,n=Object.assign({},r.preprocess(t,o));setModelMetaKey(e,"collection",o),initModelData(e,n,initModelMeta(e,n,o),o)}var PureModel=function(){function e(e,t){void 0===e&&(e={});var o=this.constructor;o.__datxInitProps&&o.__datxInitProps(),startAction(this),mobx.extendObservable(this,{}),initModel(this,e,t),endAction(this,exports.PatchType.CRATE)}return e.preprocess=function(e,t){return e},e.getAutoId=function(){return"number"==typeof this.autoIdValue?--this.autoIdValue:this.autoIdValue},e.toJSON=function(){return this.type},e.type=datxUtils.DEFAULT_TYPE,e.autoIdValue=0,e.enableAutoId=!0,e}();function initCollectionModel(e,t){return upsertModel(t,getMetaKeyFromRaw(t,"type"),e)}function upsertModel(e,t,o){var r;if(!t&&0!==t)throw error(UNDEFINED_TYPE);var n=o.constructor,i=n.types.find(function(e){return e.type===t});if(!i){var a=n.defaultModel;if(a)return new a(__assign({},e,((r={})[datxUtils.META_FIELD]=__assign({},e[datxUtils.META_FIELD]||{},{type:t}),r)),o);throw error(UNDEFINED_MODEL,{type:t})}var s=getMetaKeyFromRaw(e,"id",i),d=s&&o.find(t,s);return d?updateModel(d,e):new i(e,o)}function isSelectorFunction(e){return"function"==typeof e&&e!==PureModel&&!(e.prototype instanceof PureModel)}function initModels(t,e){return e.map(function(e){return initCollectionModel(t,e)})}var View=function(){function e(e,t,o,r,n){void 0===r&&(r=[]),void 0===n&&(n=!1),this.__collection=t,this.unique=n,this.__models=mobx.observable.array([]),this.__models.replace(r.map(getModelId)),this.sortMethod=o,this.modelType=getModelType(e),this.__collection.__viewList.push(this)}return Object.defineProperty(e.prototype,"length",{get:function(){return this.__models.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"list",{get:function(){var t=this,e=this.__models.map(function(e){return t.__collection.find(t.modelType,e)}).filter(Boolean);if(this.sortMethod){var o="string"==typeof this.sortMethod?function(e){return e[t.sortMethod]}:this.sortMethod;e.sort(function(e,t){return o(e)-o(t)})}var r=mobx.observable.array(e,{deep:!1});return mobx.intercept(r,this.__partialListUpdate.bind(this)),r},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){return{modelType:this.modelType,models:this.__models.slice(),unique:this.unique}},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!0,configurable:!0}),e.prototype.add=function(e){var o=this,t=datxUtils.mapItems(e,function(e){return o.__collection.add(e,o.modelType)});return datxUtils.mapItems(t,function(e){var t=getModelId(e);o.unique&&-1!==o.__models.indexOf(t)||o.__models.push(t)}),t},e.prototype.hasItem=function(e){var t=getModelId(e);return-1!==this.__models.indexOf(t)},e.prototype.remove=function(e){var t=getModelId(e);this.__models.remove(t)},e.prototype.removeAll=function(){this.__models.replace([])},e.prototype.__partialListUpdate=function(e){var t,o=this;if("splice"===e.type){if(this.sortMethod&&0<e.added.length)throw error(SORTED_NO_WRITE);var r=e.added.map(getModelId),n=this.__models.slice(e.index,e.removedCount);return this.unique&&r.forEach(function(e){if(-1!==o.__models.indexOf(e)&&-1===n.indexOf(e))throw error(UNIQUE_MODEL)}),(t=this.__models).splice.apply(t,[e.index,e.removedCount].concat(r)),null}if(this.sortMethod&&e.newValue)throw error(SORTED_NO_WRITE);var i=getModelId(e.newValue),a=this.__models.indexOf(i);if(this.unique&&-1!==a&&a!==e.index)throw error(UNIQUE_MODEL);return this.__models[e.index]=i,null},e.prototype.__changeModelId=function(e,t){var o=this.__models.indexOf(e);-1!==o&&(this.__models[o]=t)},__decorate([mobx.observable],e.prototype,"sortMethod",void 0),__decorate([mobx.computed],e.prototype,"length",null),__decorate([mobx.computed],e.prototype,"list",null),__decorate([mobx.computed],e.prototype,"snapshot",null),__decorate([mobx.action],e.prototype,"add",null),__decorate([mobx.action],e.prototype,"remove",null),__decorate([mobx.action],e.prototype,"removeAll",null),e}(),PureCollection=function(){function e(e){void 0===e&&(e=[]);var r=this;this.__data=mobx.observable.array([],{deep:!1}),this.__views=[],this.__viewList=[],this.__dataMap={},this.__dataList={},mobx.extendObservable(this,{}),e instanceof Array?this.insert(e):e&&"models"in e&&this.insert(e.models);var n=this.constructor,i=e&&"views"in e?e.views:{};Object.keys(n.views).forEach(function(e){var t=n.views[e],o=i[e]||t;r.addView(e,o.modelType,{mixins:t.mixins,models:o.models||[],sortMethod:t.sortMethod,unique:o.unique})})}return e.prototype.insert=function(e){var t=initModels(this,e);return this.__insertModel(t),t},e.prototype.add=function(e,t){return e instanceof Array?this.__addArray(e,t):this.__addSingle(e,t)},e.prototype.find=function(e,t){return t instanceof PureModel?t:isSelectorFunction(e)?this.__data.find(e)||null:this.__findByType(e,t)||null},e.prototype.filter=function(e){return this.__data.filter(e)},e.prototype.findAll=function(e){var t;if(e){var o=getModelType(e);return o in this.__dataList||mobx.set(this.__dataList,((t={})[o]=mobx.observable.array([]),t)),this.__dataList[o]}return this.__data},e.prototype.hasItem=function(e){var t=getModelId(e);return Boolean(this.find(e,t))},e.prototype.remove=function(e,t){var o="object"==typeof e?e:this.find(e,t);o&&this.__removeModel(o)},e.prototype.removeAll=function(e){this.__removeModel(this.findAll(e).slice())},Object.defineProperty(e.prototype,"length",{get:function(){return this.__data.length},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){var t=this,o={};return this.__views.forEach(function(e){o[e]=t[e].toJSON()}),{models:this.__data.map(modelToJSON),views:o}},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.__data.forEach(function(e){setModelMetaKey(e,"collection",void 0),triggerAction({oldValue:modelToJSON(e),patchType:exports.PatchType.REMOVE},e)}),this.__data.replace([]),this.__dataList=mobx.observable({},{},{deep:!1}),this.__dataMap=mobx.observable({},{},{deep:!1})},e.prototype.getAllModels=function(){return this.__data.slice()},e.prototype.addView=function(e,t,o){var r=void 0===o?{}:o,n=r.sortMethod,i=r.models,a=void 0===i?[]:i,s=r.unique,d=r.mixins;if(e in this)throw error(VIEW_NAME_TAKEN);var l=d?d.reduce(function(e,t){return t(e)},View):View;return this.__views.push(e),this[e]=new l(t,this,n,a,s),this[e]},e.prototype.__addArray=function(e,t){var o=this;return e.filter(Boolean).map(function(e){return o.__addSingle(e,t)})},e.prototype.__addSingle=function(e,t){if(!e||"number"==typeof e||"string"==typeof e)return e;if(e instanceof PureModel)return this.hasItem(e)||this.__insertModel(e),e;if(!t&&0!==t)throw error(UNDEFINED_TYPE);var o=getModelType(t),r=upsertModel(e,o,this);return this.__insertModel(r,o),r},e.prototype.__insertModel=function(e,t,o){var r,n=this;if(e instanceof Array)e.forEach(function(e){n.__insertModel(e,t,o)});else{var i=getModelCollection(e);if(i&&i!==this)throw error(MODEL_SINGLE_COLLECTION);var a=t||getModelType(e),s=o||getModelId(e),d=a.toString(),l=this.find(a,s);l?updateModel(l,e):(this.__data.push(e),a in this.__dataList?this.__dataList[a].push(e):mobx.set(this.__dataList,d,mobx.observable.array([e],{deep:!1})),a in this.__dataMap?mobx.set(this.__dataMap[a],s.toString(),e):mobx.set(this.__dataMap,d,mobx.observable.object(((r={})[s]=e,r),{},{deep:!1})),setModelMetaKey(e,"collection",this),triggerAction({newValue:modelToJSON(e),patchType:exports.PatchType.CRATE},e))}},e.prototype.__removeModel=function(e,t,o){var r=this;if(e instanceof Array)e.forEach(function(e){r.__removeModel(e,t,o)});else{var n=t||getModelType(e),i=o||getModelId(e);triggerAction({oldValue:mobx.toJS(modelToJSON(e)),patchType:exports.PatchType.REMOVE},e),this.__data.remove(e),this.__dataList[n].remove(e),mobx.set(this.__dataMap[n],i.toString(),void 0),this.__data.forEach(function(o){var r=getModelMetaKey(o,"refs");Object.keys(r||{}).forEach(function(e){if(getModelType(r[e].model)===n){var t=getRefId(o,e);t instanceof Array?t.includes(i)&&setRefId(o,e,t.filter(function(e){return e!==i})):t===i&&setRefId(o,e,void 0)}})}),setModelMetaKey(e,"collection",void 0)}},e.prototype.__findByType=function(e,t){var o,r=getModelType(e),n=r.toString();return t?(r in this.__dataMap?t in this.__dataMap[r]||mobx.set(this.__dataMap[r],t.toString(),void 0):mobx.set(this.__dataMap,n,mobx.observable.object(((o={})[t]=void 0,o),{},{deep:!1})),this.__dataMap[r][t]):(r in this.__dataList||mobx.set(this.__dataList,n,mobx.observable.array([],{deep:!1})),this.__dataList[r].length?this.__dataList[r][0]:null)},e.prototype.__changeModelId=function(t,o,r){this.__dataMap[r][o]=this.__dataMap[r][t],delete this.__dataMap[r][t],this.__viewList.filter(function(e){return e.modelType===r}).forEach(function(e){e.__changeModelId(t,o)})},e.types=[],e.views={},e.defaultModel=PureModel,__decorate([mobx.observable.shallow],e.prototype,"__dataMap",void 0),__decorate([mobx.observable.shallow],e.prototype,"__dataList",void 0),__decorate([mobx.action],e.prototype,"insert",null),__decorate([mobx.action],e.prototype,"add",null),__decorate([mobx.action],e.prototype,"remove",null),__decorate([mobx.action],e.prototype,"removeAll",null),__decorate([mobx.computed],e.prototype,"length",null),__decorate([mobx.action],e.prototype,"reset",null),e}();function isOfType(e,t){for(var o=e;o;){if(o===t)return!0;o=Object.getPrototypeOf(o)}return!1}function isModel(e){return isOfType(e,PureModel)}function isCollection(e){return isOfType(e,PureCollection)}function isView(e){return isOfType(e,View)}function inversePatch(e){var t=reverseAction(e.patchType);return{model:e.model,newValue:e.oldValue,oldValue:e.newValue,patchType:t}}function withPatches(e){if(isCollection(e))return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.__patchListeners=[],e}return __extends(e,t),e.prototype.applyPatch=function(e){var t=this.find(e.model.type,e.model.id);if(e.patchType===exports.PatchType.REMOVE)t&&this.remove(t);else if(e.patchType===exports.PatchType.UPDATE){if(!t||!e.newValue)throw error(t?"New patch value isn't set for an update patch":"The model should already exist for an update patch");updateModel(t,e.newValue)}else{if(t)throw error("The model shouldn't exist before a create patch");if(!e.newValue)throw error("New patch value isn't set for a create patch");this.add(e.newValue,e.model.type)}},e.prototype.undoPatch=function(e){this.applyPatch(inversePatch(e))},e.prototype.onPatch=function(t){var e=this;return this.__patchListeners.push(t),function(){e.__patchListeners=e.__patchListeners.filter(function(e){return e!==t})}},e}(e);if(isModel(e))return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.__patchListeners=[],e}return __extends(e,t),e.prototype.applyPatch=function(e){e.model.type===getModelType(this)&&e.model.id===getModelId(this)&&updateModel(this,e.newValue||{})},e.prototype.undoPatch=function(e){this.applyPatch(inversePatch(e))},e.prototype.onPatch=function(t){var e=this;return this.__patchListeners.push(t),function(){e.__patchListeners=e.__patchListeners.filter(function(e){return e!==t})}},e}(e);throw error("Only Models and Collections can be decorated with patches")}function withActions(e){var t=e;if(!isModel(e))throw error(DECORATE_MODEL);return function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.update=function(e){updateModel(this,e)},t.prototype.clone=function(){return cloneModel(this)},t.prototype.assign=function(e,t){assignModel(this,e,t)},t.prototype.addReference=function(e,t,o){initModelRef(this,e,o,t)},t.prototype.toJSON=function(){return modelToJSON(this)},t}(t)}function withMeta(e){var t=e;if(!isModel(t))throw error(DECORATE_MODEL);var o=function(){function e(e){this.__instance=e}return Object.defineProperty(e.prototype,"collection",{get:function(){return getModelCollection(this.__instance)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return getModelId(this.__instance)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"original",{get:function(){return getModelMetaKey(this.__instance,"originalId")?getOriginalModel(this.__instance):void 0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"refs",{get:function(){var t=this,e=getModelMetaKey(this.__instance,"refs")||{},o={};return Object.keys(e).forEach(function(e){o[e]=getRefId(t.__instance,e)}),o},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"snapshot",{get:function(){return modelToJSON(this.__instance)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return getModelType(this.__instance)},enumerable:!0,configurable:!0}),__decorate([mobx.computed],e.prototype,"collection",null),__decorate([mobx.computed],e.prototype,"id",null),__decorate([mobx.computed],e.prototype,"original",null),__decorate([mobx.computed],e.prototype,"refs",null),__decorate([mobx.computed],e.prototype,"snapshot",null),__decorate([mobx.computed],e.prototype,"type",null),e}();return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.meta=new o(e),e}return __extends(e,t),e}(t)}var Model=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.valueOf=function(){var e=this.meta.snapshot;return delete e[datxUtils.META_FIELD],__assign({},e,{meta:{id:this.meta.id,type:this.meta.type}})},t.prototype.toString=function(){return JSON.stringify(this.valueOf(),null,2)},t}(withPatches(withActions(withMeta(PureModel)))),Collection=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.defaultModel=Model,t}(withPatches(PureCollection)),CompatModel=function(o){function e(e,t){var r=o.call(this,e,t)||this;return datxUtils.deprecated("CompatModel is just a migration tool. Please move to Model or PureModel as soon as possible."),Object.keys(r.static.refs).forEach(function(e){if(!(e in getModelMetaKey(r,"refs"))){var t=r.static.refs[e],o=datxUtils.mapItems(r[e]||r.static.defaults[e],getModelId);delete r[e],initModelRef(r,e,"object"==typeof t?{model:t.model,property:t.property,type:exports.ReferenceType.TO_ONE_OR_MANY}:{model:t,type:exports.ReferenceType.TO_ONE_OR_MANY},o)}}),Object.keys(r.static.defaults).forEach(function(e){e in r.static.refs||e in r||initModelField(r,e,r.static.defaults[e])}),r}return __extends(e,o),e.__datxInitProps=function(){this.idAttribute&&storage.setModelClassMetaKey(this,"id",this.idAttribute),this.typeAttribute&&storage.setModelClassMetaKey(this,"type",this.typeAttribute)},e.prototype.getRecordId=function(){return datxUtils.deprecated("model.getRecordId is deprecated. Use getModelId() instead."),getModelId(this)},e.prototype.getRecordType=function(){return datxUtils.deprecated("model.getRecordType is deprecated. Use getModelType() instead."),getModelType(this)},e.prototype.assign=function(e,t){datxUtils.deprecated("model.assign is deprecated. Use assignModel() instead.");var o=FieldType.DATA,r=storage.getModelClassMetaKey(this.static,"id"),n=storage.getModelClassMetaKey(this.static,"type");return e===r?o=FieldType.ID:e===n&&(o=FieldType.TYPE),updateField(this,e,t,o),t},e.prototype.assignRef=function(e,t,o){if(datxUtils.deprecated("model.assignRef is deprecated. Use initModelRef() instead."),getModelMetaKey(this,"refs")[e])return this[e]=t;var r=o;if(r||(t instanceof Array||mobx.isObservableArray(t)?r=t.reduce(function(e,t){return e||getModelType(t)},null):t instanceof PureModel&&(r=getModelType(t))),!r)throw new Error("The type property is missing");return initModelRef(this,e,{model:r,type:exports.ReferenceType.TO_ONE_OR_MANY},t),this[e]},e.prototype.update=function(e){var t=this;datxUtils.deprecated("model.update is deprecated. Use updateModel() instead.");var o=Object.assign({},e);return Object.keys(o).forEach(function(e){"function"==typeof t[e]&&delete o[e]}),updateModel(this,o)},Object.defineProperty(e.prototype,"static",{get:function(){return datxUtils.deprecated("model.static is deprecated."),this.constructor},enumerable:!0,configurable:!0}),e.prototype.toJS=function(){return datxUtils.deprecated("model.toJS() is deprecated. Use modelToJSON() instead."),modelToJSON(this)},Object.defineProperty(e.prototype,"snapshot",{get:function(){return datxUtils.deprecated("model.snapshot is deprecated. Use modelToJSON() instead."),modelToJSON(this)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"__collection",{get:function(){return datxUtils.deprecated("model.__collection is deprecated. Use getModelCollection() instead."),getModelCollection(this)},enumerable:!0,configurable:!0}),e.refs={},e.defaults={},e.idAttribute="id",e.typeAttribute="__type__",e}(PureModel),CompatCollection=function(t){function e(e){var o=t.call(this,e)||this;return datxUtils.deprecated("CompatCollection is just a migration tool. Please move to Collection as soon as possible."),o.static.types.forEach(function(e){var t=getModelType(e);datxUtils.assignComputed(o,t.toString(),function(){return o.findAll(t)})}),o}return __extends(e,t),Object.defineProperty(e.prototype,"static",{get:function(){return datxUtils.deprecated("collection.static is deprecated."),this.constructor},enumerable:!0,configurable:!0}),e.prototype.toJS=function(){return datxUtils.deprecated("collection.toJS() is deprecated. Use collection.toJSON() instead"),this.toJSON()},e.types=[CompatModel],e}(Collection);function getClass(e){return"function"==typeof e?e:e.constructor}function propFn(e,t){storage.addModelDefaultField(getClass(e),t)}var prop=Object.assign(propFn,{defaultValue:function(o){return function(e,t){storage.addModelDefaultField(getClass(e),t,o)}},toOne:function(o){return function(e,t){storage.addModelClassReference(getClass(e),t,{model:o,type:exports.ReferenceType.TO_ONE})}},toMany:function(o,r){return function(e,t){storage.addModelClassReference(getClass(e),t,{model:o,property:r,type:exports.ReferenceType.TO_MANY})}},toOneOrMany:function(o){return function(e,t){storage.addModelClassReference(getClass(e),t,{model:o,type:exports.ReferenceType.TO_ONE_OR_MANY})}},identifier:function(e,t){storage.addModelDefaultField(getClass(e),t),storage.setModelClassMetaKey(getClass(e),"id",t)},type:function(e,t){storage.addModelDefaultField(getClass(e),t),storage.setModelClassMetaKey(getClass(e),"type",t)}});function setupModel(e,t){var o=void 0===t?{fields:{}}:t,r=o.fields,n=o.references,i=o.type,a=o.idAttribute,s=o.typeAttribute,d=e;if(!isModel(d))throw error(DECORATE_MODEL);var l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t}(d);return i&&(l.type=i),a&&prop.identifier(l.prototype,a),s&&prop.type(l.prototype,s),r&&Object.keys(r).forEach(function(e){prop.defaultValue(r[e])(l.prototype,e)}),n&&Object.keys(n).forEach(function(e){var t=n[e],o=t.model,r=t.property;switch(n[e].type){case exports.ReferenceType.TO_ONE:return void prop.toOne(o)(l.prototype,e);case exports.ReferenceType.TO_MANY:return void prop.toMany(o,r)(l.prototype,e);default:return void prop.toOneOrMany(o)(l.prototype,e)}}),l}exports.Collection=Collection,exports.Model=Model,exports.View=View,exports.PureCollection=PureCollection,exports.PureModel=PureModel,exports.CompatCollection=CompatCollection,exports.CompatModel=CompatModel,exports.getRefId=getRefId,exports.setRefId=setRefId,exports.updateModelId=updateModelId,exports.initModelRef=initModelRef,exports.assignModel=assignModel,exports.cloneModel=cloneModel,exports.getModelClassRefs=getModelClassRefs,exports.getModelCollection=getModelCollection,exports.getModelId=getModelId,exports.getModelMetaKey=getModelMetaKey,exports.getModelType=getModelType,exports.getOriginalModel=getOriginalModel,exports.modelToJSON=modelToJSON,exports.setModelMetaKey=setModelMetaKey,exports.updateModel=updateModel,exports.isCollection=isCollection,exports.isModel=isModel,exports.isView=isView,exports.setupModel=setupModel,exports.withActions=withActions,exports.withMeta=withMeta,exports.withPatches=withPatches,exports.prop=prop;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var mobx=require("mobx"),datxUtils=require("datx-utils"),extendStatics=function(e,t){return(extendStatics=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var o in t)t.hasOwnProperty(o)&&(e[o]=t[o])})(e,t)};function __extends(e,t){function o(){this.constructor=e}extendStatics(e,t),e.prototype=null===t?Object.create(t):(o.prototype=t.prototype,new o)}var __assign=function(){return(__assign=Object.assign||function(e){for(var t,o=1,r=arguments.length;o<r;o++)for(var n in t=arguments[o])Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n]);return e}).apply(this,arguments)};function __decorate(e,t,o,r){var n,i=arguments.length,a=i<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,o):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)a=Reflect.decorate(e,t,o,r);else for(var s=e.length-1;0<=s;s--)(n=e[s])&&(a=(i<3?n(a):3<i?n(t,o,a):n(t,o))||a);return 3<i&&a&&Object.defineProperty(t,o,a),a}!function(e){e[e.CRATE=0]="CRATE",e[e.UPDATE=1]="UPDATE",e[e.REMOVE=2]="REMOVE"}(exports.PatchType||(exports.PatchType={}));var REGEX=/\$\{\s*([a-zA-Z0-9\-\_]+)\s*\}/g;function msg(e,t){for(var o=e,r=REGEX.exec(o);r;)o=o.replace(r[0],t[r[1]]),r=REGEX.exec(o);return o}function error(e,t){return void 0===t&&(t={}),new Error("[datx exception] "+msg(e,t))}var FieldType,UNDEFINED_TYPE="The type needs to be defined if the object is not an instance of the model.",UNDEFINED_MODEL="No model is defined for the type ${type}.",NOT_A_CLONE="The given model is not a clone.",REF_NEEDS_COLLECTION="The model needs to be in a collection to be referenceable",REF_SINGLE="The reference ${key} can't be an array of values.",REF_ARRAY="The reference ${key} must be an array of values.",NO_REFS="You should save this value as a reference.",BACK_REF_READ_ONLY="Back references are read only",ID_READONLY="Model ID can't be updated directly. Use the `updateModelId` helper function instead.",TYPE_READONLY="Model type can't be changed after initialization.",MODEL_SINGLE_COLLECTION="A model can be in a single collection at once",ID_REQUIRED="Model id is required (autoincrement is disabled)",WRONG_REF_TYPE="The new reference type doesn't match to the declared one.",MODEL_REQUIRED="The model type is a required parameter. Do you maybe have a circular dependency?",SORTED_NO_WRITE="New models can't be added directly to a sorted view list",UNIQUE_MODEL="The models in this view need to be unique",VIEW_NAME_TAKEN="The name is already taken",DECORATE_MODEL="This mixin can only decorate models";function reducePrototypeChain(e,t,o){for(var r=o,n=e;n;)r=t(r,n),n=Object.getPrototypeOf(n);return r}!function(e){e[e.ID=0]="ID",e[e.TYPE=1]="TYPE",e[e.DATA=2]="DATA"}(FieldType||(FieldType={})),function(e){e[e.TO_ONE=0]="TO_ONE",e[e.TO_MANY=1]="TO_MANY",e[e.TO_ONE_OR_MANY=2]="TO_ONE_OR_MANY"}(exports.ReferenceType||(exports.ReferenceType={}));var DATX_KEY=Symbol.for("datx metadata");function setMeta(e,t){Object.defineProperty(e,DATX_KEY,{enumerable:!1,value:t,writable:!1})}var DataStorage=function(){function e(){}return e.prototype.initModel=function(e){var t=mobx.observable({data:{},meta:{}});return setMeta(e,t),t},e.prototype.getModelData=function(e){return this.__getModelData(e).data},e.prototype.getModelDataKey=function(e,t){return this.__getModelData(e).data[t]},e.prototype.setModelData=function(e,t){var o=this.__getModelData(e);mobx.set(o.data,t)},e.prototype.setModelDataKey=function(e,t,o){var r;this.setModelData(e,((r={})[t]=o,r))},e.prototype.getModelMeta=function(e){var t=e[DATX_KEY];return t?t.meta:this.setModelMeta(e,{})},e.prototype.getModelMetaKey=function(e,t){return this.getModelMeta(e)[t]},e.prototype.setModelMeta=function(e,t){var o=this.__getModelData(e);return mobx.set(o.meta,t),o.meta},e.prototype.setModelMetaKey=function(e,t,o){var r;this.setModelMeta(e,((r={})[t]=o,r))},e.prototype.setModelClassMetaKey=function(e,t,o){var r,n=e[DATX_KEY];n||setMeta(e,n={data:{},meta:{},references:{}}),Object.assign(n.meta,((r={})[t]=o,r))},e.prototype.getModelClassMetaKey=function(e,o){return reducePrototypeChain(e,function(e,t){return e||(t[DATX_KEY]||{meta:{}}).meta[o]||null},null)},e.prototype.addModelDefaultField=function(e,t,o){var r,n,i=e[DATX_KEY];i?Object.assign(i.data,((r={})[t]=o,r)):setMeta(e,{data:(n={},n[t]=o,n),meta:{},references:{}})},e.prototype.getModelDefaults=function(e){var t=reducePrototypeChain(e,function(e,t){return e.concat((t[DATX_KEY]||{data:[]}).data)},[]);return Object.assign.apply(Object,[{}].concat(t.reverse()))},e.prototype.addModelClassReference=function(e,t,o){var r,n;if(!o.model&&0!==o.model)throw error(MODEL_REQUIRED);var i=e[DATX_KEY];i?Object.assign(i.references,((r={})[t]=o,r)):setMeta(e,{data:{},meta:{},references:(n={},n[t]=o,n)})},e.prototype.getModelClassReferences=function(e){var t=reducePrototypeChain(e,function(e,t){return e.concat((t[DATX_KEY]||{references:{}}).references)},[]);return Object.assign.apply(Object,[{}].concat(t.reverse()))},e.prototype.getModelReferenceOptions=function(e,t){return this.getModelMetaKey(e,"refs")[t]},e.prototype.__getModelData=function(e){return e[DATX_KEY]||this.initModel(e)},e}(),storage=new DataStorage;function getModelType(e){return"function"==typeof e?e.type:"object"==typeof e?getModelMetaKey(e,"type")||e.constructor.type:e}function getModelId(e){return e instanceof PureModel?getModelMetaKey(e,"id"):e}function getModelCollection(e){return getModelMetaKey(e,"collection")}function cloneModel(e){var t=e.constructor,o=modelToJSON(e),r=o[datxUtils.META_FIELD]||{};r.originalId=r.id,delete r.id;var n=new t(o),i=getModelCollection(e);return i?i.add(n):datxUtils.warn("The model is not in the collection. Referencing the original model won't be possible"),n}function getOriginalModel(e){var t=getModelCollection(e),o=getModelMetaKey(e,"originalId");if(o){if(!t)throw error(REF_NEEDS_COLLECTION);return t.find(e,o)}throw error(NOT_A_CLONE)}var READ_ONLY_META=["fields","id","refs","type"];function updateModel(o,r){var e=storage.getModelClassMetaKey(o.constructor,"id")||"id",n=storage.getModelClassMetaKey(o.constructor,"type")||"type",t=Object.keys(r instanceof PureModel?modelToJSON(r):r);return startAction(o),t.forEach(function(t){if(t!==datxUtils.META_FIELD&&t!==e&&t!==n)assignModel(o,t,r[t]);else if(t===datxUtils.META_FIELD){Object.keys(r[t]||{}).forEach(function(e){READ_ONLY_META.includes(e)||setModelMetaKey(o,e,r[t][e])})}}),endAction(o),o}function assignModel(e,t,o){var r=getModelMetaKey(e,"refs");if(startAction(e),t in r)assignModelRef(e,t,o);else{if(o instanceof PureModel)throw endAction(e),error(NO_REFS,{key:t});assignModelField(e,t,o)}endAction(e)}function assignModelField(e,t,o){-1!==getModelMetaKey(e,"fields").indexOf(t)?e[t]=o:initModelField(e,t,o)}function assignModelRef(e,t,o){e[t]=o}function getMetaKeyFromRaw(e,t,o){if(datxUtils.META_FIELD in e&&"object"==typeof e[datxUtils.META_FIELD]&&void 0!==e[datxUtils.META_FIELD])return(e[datxUtils.META_FIELD]||{})[t];if(o){var r=storage.getModelClassMetaKey(o,t);return r&&e[r]}return e&&e[t]}function modelToJSON(e){var t,o=mobx.toJS(storage.getModelData(e)),r=Object.assign({},storage.getModelMeta(e));delete r.collection,delete r.patch;var n=mobx.toJS(r),i={};Object.keys(n.refs||{}).forEach(function(e){i[e]={model:getModelType(n.refs[e].model),type:n.refs[e].type}}),n.refs=i,delete n.collection;var a=Object.assign(o,((t={})[datxUtils.META_FIELD]=n,t)),s=e.constructor,d=storage.getModelClassMetaKey(s,"id"),l=storage.getModelClassMetaKey(s,"type");return n&&d&&(a[d]=n.id),n&&l&&(a[l]=n.type),a}function getModelMetaKey(e,t){return storage.getModelMetaKey(e,t)}function setModelMetaKey(e,t,o){storage.setModelMetaKey(e,t,o)}function getModelClassRefs(e){return storage.getModelClassReferences(e)}function isEmptyObject(e){return 0===Object.keys(e).length}function reverseAction(e){switch(e){case exports.PatchType.CRATE:return exports.PatchType.REMOVE;case exports.PatchType.REMOVE:return exports.PatchType.CRATE;default:return exports.PatchType.UPDATE}}function triggerAction(e,t){var o=__assign({},e,{model:{id:getModelId(t),type:getModelType(t)}}),r=[];"__patchListeners"in t&&r.push.apply(r,t.__patchListeners||[]);var n=getModelCollection(t);n&&"__patchListeners"in n&&r.push.apply(r,n.__patchListeners||[]),r.forEach(function(e){e(o)})}function startAction(e){var t=storage.getModelMetaKey(e,"patch")||{count:0,oldValue:{},newValue:{}};t.count++,storage.setModelMetaKey(e,"patch",t)}function updateAction(e,t,o){var r=storage.getModelMetaKey(e,"patch")||{count:0,oldValue:{},newValue:{}};e[t]!==o&&(t in r.oldValue||(r.oldValue[t]=e[t]),r.newValue[t]=o,storage.setModelMetaKey(e,"patch",r))}function endAction(e,t){void 0===t&&(t=exports.PatchType.UPDATE);var o=storage.getModelMetaKey(e,"patch")||{count:0,oldValue:{},newValue:{}};if(o.count--,0===o.count){var r=mobx.toJS(o.newValue),n=mobx.toJS(o.oldValue);isEmptyObject(r)&&isEmptyObject(n)||triggerAction({newValue:r,oldValue:n,patchType:t},e),storage.setModelMetaKey(e,"patch",{count:0,oldValue:{},newValue:{}})}else storage.setModelMetaKey(e,"patch",o)}function modelAddReference(e,t,o){var r=storage.getModelReferenceOptions(e,t),n=getModelId(o),i=storage.getModelDataKey(e,t);r.type===exports.ReferenceType.TO_ONE?storage.setModelDataKey(e,t,n):r.type===exports.ReferenceType.TO_MANY||mobx.isObservableArray(i)?i.push(n):storage.setModelDataKey(e,t,o)}function modelRemoveReference(e,t,o){var r=storage.getModelReferenceOptions(e,t),n=getModelId(o),i=storage.getModelDataKey(e,t);r.type===exports.ReferenceType.TO_ONE?storage.setModelDataKey(e,t,null):r.type===exports.ReferenceType.TO_MANY||mobx.isObservableArray(i)?i.remove(n):storage.setModelDataKey(e,t,null)}function ensureModel(o,r){return function(e){var t=e;if(!(e instanceof PureModel)&&"object"==typeof e){if(!r)throw error(REF_NEEDS_COLLECTION);t=r.add(e,o.model)}return getModelId(t)}}function partialRefUpdate(e,t,o){var r=storage.getModelReferenceOptions(e,t),n=storage.getModelDataKey(e,t),i=getModelCollection(e);if("splice"!==o.type)return n[o.index]=ensureModel(r,i)(o.newValue),null;var a=o.added.map(ensureModel(r,i));return n.splice.apply(n,[o.index,o.removedCount].concat(a)),null}function backRefSplice(t,e,o,r){var n=r.property;return o.added.forEach(function(e){modelAddReference(e,n,t)}),t[e].slice(o.index,o.index+o.removedCount).forEach(function(e){modelRemoveReference(e,n,t)}),null}function backRefChange(e,t,o,r){var n=r.property,i=e[t].length>o.index?e[t][o.index]:null;return o.newValue&&modelAddReference(o.newValue,n,e),i&&modelRemoveReference(i,n,e),datxUtils.warn("This shouldn't have happened. Please open an issue: https://github.com/infinum/datx/issues/new"),null}function partialBackRefUpdate(e,t,o){var r=storage.getModelReferenceOptions(e,t);return"splice"===o.type?backRefSplice(e,t,o,r):backRefChange(e,t,o,r)}function getField(e,t){return storage.getModelDataKey(e,t)}function updateField(e,t,o,r){if(r===FieldType.TYPE)throw error(TYPE_READONLY);if(r===FieldType.ID)throw error(ID_READONLY);startAction(e),t in getModelMetaKey(e,"refs")?updateRef(e,t,o):(updateAction(e,t,o),storage.setModelDataKey(e,t,o)),endAction(e)}function hasBackRef(e,t,o){return null!==e[t]&&void 0!==e[t]&&(e[t]instanceof PureModel?e[t]===o:-1!==e[t].indexOf(o))}function getBackRef(t,o,r){var e=getModelType(r.model),n=getModelCollection(t);if(!n)return null;var i=n.findAll(e).filter(function(e){return hasBackRef(e,r.property,t)}),a=mobx.observable.array(i,{deep:!1});return mobx.intercept(a,function(e){return partialBackRefUpdate(t,o,e)}),a}function getNormalRef(t,o,r){var e=storage.getModelDataKey(t,o),n=getModelCollection(t);if(!n)return null;var i=datxUtils.mapItems(e,function(e){return e?n.find(r.model,e):e});if(r.type!==exports.ReferenceType.TO_MANY||i instanceof Array||(i=[i]),i instanceof Array){var a=mobx.observable.array(i,{deep:!1});return mobx.intercept(a,function(e){return partialRefUpdate(t,o,e)}),a}return i}function getRef(e,t){var o=storage.getModelReferenceOptions(e,t);return"string"==typeof o.property?getBackRef(e,t,o):getNormalRef(e,t,o)}function validateRef(e,t,o){if(e.type===exports.ReferenceType.TO_ONE&&t)throw error(REF_SINGLE,{key:o});if(e.type===exports.ReferenceType.TO_MANY&&!t)throw error(REF_ARRAY,{key:o});if(e.property)throw error(BACK_REF_READ_ONLY)}function updateRef(o,e,t){var r=storage.getModelReferenceOptions(o,e),n=r.type===exports.ReferenceType.TO_MANY?t||[]:t,i=n instanceof Array||mobx.isObservableArray(n);validateRef(r,i,e);var a=getModelCollection(o);startAction(o);var s=datxUtils.mapItems(t,function(e){if(e&&a){if(e instanceof PureModel)if(getModelType(e)!==getModelType(r.model))throw endAction(o),error(WRONG_REF_TYPE);var t=a.find(r.model,e);return t||"object"!=typeof e||(t=a.add(e,r.model)),endAction(o),getModelId(t||e)}if(e instanceof PureModel)throw endAction(o),error(REF_NEEDS_COLLECTION);return e});r.type===exports.ReferenceType.TO_MANY&&(s=s||[]),updateAction(o,e,s),storage.setModelDataKey(o,e,s),endAction(o)}function getModelRefsByType(e,t){var o=getModelMetaKey(e,"refs");return Object.keys(o).filter(function(e){return!o[e].property}).filter(function(e){return getModelType(o[e].model)===t})}function updateModelReferences(e,n,i,t){var o=getModelCollection(e);o&&o.getAllModels().map(function(r){getModelRefsByType(r,t).forEach(function(e){var t=storage.getModelDataKey(r,e);if(t instanceof Array||mobx.isObservableArray(t)){var o=t.indexOf(i);-1!==o&&(t[o]=n)}else t===i&&storage.setModelDataKey(r,e,n)})})}function updateModelId(e,t){var o=getModelCollection(e),r=getModelId(e),n=getModelType(e);setModelMetaKey(e,"id",t);var i=e.constructor,a=storage.getModelClassMetaKey(i,"id");a&&setRefId(e,a,t),o&&o.__changeModelId(r,t,n),updateModelReferences(e,t,r,n)}function getRefId(e,t){return storage.getModelDataKey(e,t)}function setRefId(e,t,o){storage.setModelDataKey(e,t,o)}function initModelField(t,o,e,r){void 0===r&&(r=FieldType.DATA);var n=getModelMetaKey(t,"fields");r===FieldType.ID&&o in t&&storage.setModelDataKey(t,o,void 0),storage.setModelDataKey(t,o,e),updateAction(t,o,e),-1===n.indexOf(o)&&n.push(o),datxUtils.assignComputed(t,o,function(){return getField(t,o)},function(e){updateField(t,o,e,r)})}function initModelRef(t,o,e,r){var n=(getModelMetaKey(t,"refs")[o]=e).type===exports.ReferenceType.TO_MANY;storage.setModelDataKey(t,o,n?[]:void 0),updateAction(t,o,n?[]:void 0),datxUtils.assignComputed(t,o,function(){return getRef(t,o)},function(e){updateRef(t,o,e)}),e.property||void 0===r||(t[o]=r)}function prepareFields(e,t,o){var r=o.constructor,n=t.fields?t.fields.slice():[],i=storage.getModelClassReferences(r),a=Object.assign({},i,t.refs),s=storage.getModelDefaults(r);return Object.keys(e).concat(Object.keys(s)).forEach(function(e){e in a||-1!==n.indexOf(e)||n.push(e)}),{defaults:s,fields:n,refs:a}}function initModelData(n,i,r,a){var e=prepareFields(i,r,n),s=e.defaults,t=e.fields,d=e.refs,o=n.constructor,l=storage.getModelClassMetaKey(o,"id"),c=storage.getModelClassMetaKey(o,"type");t.forEach(function(e){var t=FieldType.DATA,o=i[e];void 0===o&&(o=s[e]),e===(l||"id")?(t=FieldType.ID,o=r.id):e===c&&(t=FieldType.TYPE,o=r.type),initModelField(n,e,o,t)}),!l||l in t||initModelField(n,l,r.id,FieldType.ID),Object.keys(d).forEach(function(e){var t=d[e],o=i[e]||s[e]||void 0,r=a?a.add(o,getModelType(t.model)):o;initModelRef(n,e,t,r)})}function initModelMeta(e,t,o){var r=e.constructor,n=storage.getModelClassMetaKey(r,"id")||"id",i=storage.getModelClassMetaKey(r,"type"),a=i&&t[i]||getModelType(e),s=n&&t[n];if(!s){if(!r.enableAutoId)throw new Error(ID_REQUIRED);for(s=r.getAutoId();o&&o.find(a,s);)s=r.getAutoId()}var d,l={fields:[],id:s,refs:{},type:a},c={fields:[],refs:{}};if(datxUtils.META_FIELD in t&&t[datxUtils.META_FIELD]){var p=t[datxUtils.META_FIELD]||{};c.fields=p.fields,delete p.fields,c.refs=p.refs,delete p.refs,"type"in p&&(l.type=p.type),d=storage.setModelMeta(e,Object.assign(l,p)),delete t[datxUtils.META_FIELD]}else d=storage.setModelMeta(e,l);return Object.assign({},d,c)}function initModel(e,t,o){var r=e.constructor,n=Object.assign({},r.preprocess(t,o));setModelMetaKey(e,"collection",o),initModelData(e,n,initModelMeta(e,n,o),o)}var PureModel=function(){function e(e,t){void 0===e&&(e={});var o=this.constructor;o.__datxInitProps&&o.__datxInitProps(),startAction(this),mobx.extendObservable(this,{}),initModel(this,e,t),endAction(this,exports.PatchType.CRATE)}return e.preprocess=function(e,t){return e},e.getAutoId=function(){return"number"==typeof this.autoIdValue?--this.autoIdValue:this.autoIdValue},e.toJSON=function(){return this.type},e.type=datxUtils.DEFAULT_TYPE,e.autoIdValue=0,e.enableAutoId=!0,e}();function initCollectionModel(e,t){return upsertModel(t,getMetaKeyFromRaw(t,"type"),e)}function upsertModel(e,t,o){var r;if(!t&&0!==t)throw error(UNDEFINED_TYPE);var n=o.constructor,i=n.types.find(function(e){return e.type===t});if(!i){var a=n.defaultModel;if(a)return new a(__assign({},e,((r={})[datxUtils.META_FIELD]=__assign({},e[datxUtils.META_FIELD]||{},{type:t}),r)),o);throw error(UNDEFINED_MODEL,{type:t})}var s=getMetaKeyFromRaw(e,"id",i),d=s&&o.find(t,s);return d?updateModel(d,e):new i(e,o)}function isSelectorFunction(e){return"function"==typeof e&&e!==PureModel&&!(e.prototype instanceof PureModel)}function initModels(t,e){return e.map(function(e){return initCollectionModel(t,e)})}var View=function(){function e(e,t,o,r,n){void 0===r&&(r=[]),void 0===n&&(n=!1),this.__collection=t,this.unique=n,this.__models=mobx.observable.array([]),this.__models.replace(r.map(getModelId)),this.sortMethod=o,this.modelType=getModelType(e),this.__collection.__viewList.push(this)}return Object.defineProperty(e.prototype,"length",{get:function(){return this.__models.length},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"list",{get:function(){var t=this,e=this.__models.map(function(e){return t.__collection.find(t.modelType,e)}).filter(Boolean);if(this.sortMethod){var o="string"==typeof this.sortMethod?function(e){return e[t.sortMethod]}:this.sortMethod;e.sort(function(e,t){return o(e)-o(t)})}var r=mobx.observable.array(e,{deep:!1});return mobx.intercept(r,this.__partialListUpdate.bind(this)),r},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){return{modelType:this.modelType,models:this.__models.slice(),unique:this.unique}},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!0,configurable:!0}),e.prototype.add=function(e){var o=this,t=datxUtils.mapItems(e,function(e){return o.__collection.add(e,o.modelType)});return datxUtils.mapItems(t,function(e){var t=getModelId(e);o.unique&&-1!==o.__models.indexOf(t)||o.__models.push(t)}),t},e.prototype.hasItem=function(e){var t=getModelId(e);return-1!==this.__models.indexOf(t)},e.prototype.remove=function(e){var t=getModelId(e);this.__models.remove(t)},e.prototype.removeAll=function(){this.__models.replace([])},e.prototype.__partialListUpdate=function(e){var t,o=this;if("splice"===e.type){if(this.sortMethod&&0<e.added.length)throw error(SORTED_NO_WRITE);var r=e.added.map(getModelId),n=this.__models.slice(e.index,e.removedCount);return this.unique&&r.forEach(function(e){if(-1!==o.__models.indexOf(e)&&-1===n.indexOf(e))throw error(UNIQUE_MODEL)}),(t=this.__models).splice.apply(t,[e.index,e.removedCount].concat(r)),null}if(this.sortMethod&&e.newValue)throw error(SORTED_NO_WRITE);var i=getModelId(e.newValue),a=this.__models.indexOf(i);if(this.unique&&-1!==a&&a!==e.index)throw error(UNIQUE_MODEL);return this.__models[e.index]=i,null},e.prototype.__changeModelId=function(e,t){var o=this.__models.indexOf(e);-1!==o&&(this.__models[o]=t)},__decorate([mobx.observable],e.prototype,"sortMethod",void 0),__decorate([mobx.computed],e.prototype,"length",null),__decorate([mobx.computed],e.prototype,"list",null),__decorate([mobx.computed],e.prototype,"snapshot",null),__decorate([mobx.action],e.prototype,"add",null),__decorate([mobx.action],e.prototype,"remove",null),__decorate([mobx.action],e.prototype,"removeAll",null),e}(),PureCollection=function(){function e(e){void 0===e&&(e=[]);var r=this;this.__data=mobx.observable.array([],{deep:!1}),this.__views=[],this.__viewList=[],this.__dataMap={},this.__dataList={},mobx.extendObservable(this,{}),e instanceof Array?this.insert(e):e&&"models"in e&&this.insert(e.models);var n=this.constructor,i=e&&"views"in e?e.views:{};Object.keys(n.views).forEach(function(e){var t=n.views[e],o=i[e]||t;r.addView(e,o.modelType,{mixins:t.mixins,models:o.models||[],sortMethod:t.sortMethod,unique:o.unique})})}return e.prototype.insert=function(e){var t=initModels(this,e);return this.__insertModel(t),t},e.prototype.add=function(e,t){return e instanceof Array?this.__addArray(e,t):this.__addSingle(e,t)},e.prototype.find=function(e,t){return t instanceof PureModel?t:isSelectorFunction(e)?this.__data.find(e)||null:this.__findByType(e,t)||null},e.prototype.filter=function(e){return this.__data.filter(e)},e.prototype.findAll=function(e){var t;if(e){var o=getModelType(e);return o in this.__dataList||mobx.set(this.__dataList,((t={})[o]=mobx.observable.array([]),t)),this.__dataList[o]}return this.__data},e.prototype.hasItem=function(e){var t=getModelId(e);return Boolean(this.find(e,t))},e.prototype.remove=function(e,t){var o="object"==typeof e?e:this.find(e,t);o&&this.__removeModel(o)},e.prototype.removeAll=function(e){this.__removeModel(this.findAll(e).slice())},Object.defineProperty(e.prototype,"length",{get:function(){return this.__data.length},enumerable:!0,configurable:!0}),e.prototype.toJSON=function(){var t=this,o={};return this.__views.forEach(function(e){o[e]=t[e].toJSON()}),{models:this.__data.map(modelToJSON),views:o}},Object.defineProperty(e.prototype,"snapshot",{get:function(){return this.toJSON()},enumerable:!0,configurable:!0}),e.prototype.reset=function(){this.__data.forEach(function(e){setModelMetaKey(e,"collection",void 0),triggerAction({oldValue:modelToJSON(e),patchType:exports.PatchType.REMOVE},e)}),this.__data.replace([]),this.__dataList=mobx.observable({},{},{deep:!1}),this.__dataMap=mobx.observable({},{},{deep:!1})},e.prototype.getAllModels=function(){return this.__data.slice()},e.prototype.addView=function(e,t,o){var r=void 0===o?{}:o,n=r.sortMethod,i=r.models,a=void 0===i?[]:i,s=r.unique,d=r.mixins;if(e in this)throw error(VIEW_NAME_TAKEN);var l=d?d.reduce(function(e,t){return t(e)},View):View;return this.__views.push(e),this[e]=new l(t,this,n,a,s),this[e]},e.prototype.__addArray=function(e,t){var o=this;return e.filter(Boolean).map(function(e){return o.__addSingle(e,t)})},e.prototype.__addSingle=function(e,t){if(!e||"number"==typeof e||"string"==typeof e)return e;if(e instanceof PureModel)return this.hasItem(e)||this.__insertModel(e),e;if(!t&&0!==t)throw error(UNDEFINED_TYPE);var o=getModelType(t),r=upsertModel(e,o,this);return this.__insertModel(r,o),r},e.prototype.__insertModel=function(e,t,o){var r,n=this;if(e instanceof Array)e.forEach(function(e){n.__insertModel(e,t,o)});else{var i=getModelCollection(e);if(i&&i!==this)throw error(MODEL_SINGLE_COLLECTION);var a=t||getModelType(e),s=o||getModelId(e),d=a.toString(),l=this.find(a,s);l?updateModel(l,e):(this.__data.push(e),a in this.__dataList?this.__dataList[a].push(e):mobx.set(this.__dataList,d,mobx.observable.array([e],{deep:!1})),a in this.__dataMap?mobx.set(this.__dataMap[a],s.toString(),e):mobx.set(this.__dataMap,d,mobx.observable.object(((r={})[s]=e,r),{},{deep:!1})),setModelMetaKey(e,"collection",this),triggerAction({newValue:modelToJSON(e),patchType:exports.PatchType.CRATE},e))}},e.prototype.__removeModel=function(e,t,o){var r=this;if(e instanceof Array)e.forEach(function(e){r.__removeModel(e,t,o)});else{var n=t||getModelType(e),i=o||getModelId(e);triggerAction({oldValue:mobx.toJS(modelToJSON(e)),patchType:exports.PatchType.REMOVE},e),this.__data.remove(e),this.__dataList[n].remove(e),mobx.set(this.__dataMap[n],i.toString(),void 0),this.__data.forEach(function(o){var r=getModelMetaKey(o,"refs");Object.keys(r||{}).forEach(function(e){if(getModelType(r[e].model)===n){var t=getRefId(o,e);t instanceof Array?t.includes(i)&&setRefId(o,e,t.filter(function(e){return e!==i})):t===i&&setRefId(o,e,void 0)}})}),setModelMetaKey(e,"collection",void 0)}},e.prototype.__findByType=function(e,t){var o,r=getModelType(e),n=r.toString();return t?(r in this.__dataMap?t in this.__dataMap[r]||mobx.set(this.__dataMap[r],t.toString(),void 0):mobx.set(this.__dataMap,n,mobx.observable.object(((o={})[t]=void 0,o),{},{deep:!1})),this.__dataMap[r][t]):(r in this.__dataList||mobx.set(this.__dataList,n,mobx.observable.array([],{deep:!1})),this.__dataList[r].length?this.__dataList[r][0]:null)},e.prototype.__changeModelId=function(t,o,r){this.__dataMap[r][o]=this.__dataMap[r][t],delete this.__dataMap[r][t],this.__viewList.filter(function(e){return e.modelType===r}).forEach(function(e){e.__changeModelId(t,o)})},e.types=[],e.views={},e.defaultModel=PureModel,__decorate([mobx.observable.shallow],e.prototype,"__dataMap",void 0),__decorate([mobx.observable.shallow],e.prototype,"__dataList",void 0),__decorate([mobx.action],e.prototype,"insert",null),__decorate([mobx.action],e.prototype,"add",null),__decorate([mobx.action],e.prototype,"remove",null),__decorate([mobx.action],e.prototype,"removeAll",null),__decorate([mobx.computed],e.prototype,"length",null),__decorate([mobx.action],e.prototype,"reset",null),e}();function isOfType(e,t){for(var o=e;o;){if(o===t)return!0;o=Object.getPrototypeOf(o)}return!1}function isModel(e){return isOfType(e,PureModel)}function isCollection(e){return isOfType(e,PureCollection)}function isView(e){return isOfType(e,View)}function inversePatch(e){var t=reverseAction(e.patchType);return{model:e.model,newValue:e.oldValue,oldValue:e.newValue,patchType:t}}function withPatches(e){if(isCollection(e))return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.__patchListeners=[],e}return __extends(e,t),e.prototype.applyPatch=function(e){var t=this.find(e.model.type,e.model.id);if(e.patchType===exports.PatchType.REMOVE)t&&this.remove(t);else if(e.patchType===exports.PatchType.UPDATE){if(!t||!e.newValue)throw error(t?"New patch value isn't set for an update patch":"The model should already exist for an update patch");updateModel(t,e.newValue)}else{if(t)throw error("The model shouldn't exist before a create patch");if(!e.newValue)throw error("New patch value isn't set for a create patch");this.add(e.newValue,e.model.type)}},e.prototype.undoPatch=function(e){this.applyPatch(inversePatch(e))},e.prototype.onPatch=function(t){var e=this;return this.__patchListeners.push(t),function(){e.__patchListeners=e.__patchListeners.filter(function(e){return e!==t})}},e}(e);if(isModel(e))return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.__patchListeners=[],e}return __extends(e,t),e.prototype.applyPatch=function(e){e.model.type===getModelType(this)&&e.model.id===getModelId(this)&&updateModel(this,e.newValue||{})},e.prototype.undoPatch=function(e){this.applyPatch(inversePatch(e))},e.prototype.onPatch=function(t){var e=this;return this.__patchListeners.push(t),function(){e.__patchListeners=e.__patchListeners.filter(function(e){return e!==t})}},e}(e);throw error("Only Models and Collections can be decorated with patches")}function withActions(e){var t=e;if(!isModel(e))throw error(DECORATE_MODEL);return function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.update=function(e){updateModel(this,e)},t.prototype.clone=function(){return cloneModel(this)},t.prototype.assign=function(e,t){assignModel(this,e,t)},t.prototype.addReference=function(e,t,o){initModelRef(this,e,o,t)},t.prototype.toJSON=function(){return modelToJSON(this)},t}(t)}function withMeta(e){var t=e;if(!isModel(t))throw error(DECORATE_MODEL);var o=function(){function e(e){this.__instance=e}return Object.defineProperty(e.prototype,"collection",{get:function(){return getModelCollection(this.__instance)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return getModelId(this.__instance)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"original",{get:function(){return getModelMetaKey(this.__instance,"originalId")?getOriginalModel(this.__instance):void 0},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"refs",{get:function(){var t=this,e=getModelMetaKey(this.__instance,"refs")||{},o={};return Object.keys(e).forEach(function(e){o[e]=getRefId(t.__instance,e)}),o},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"snapshot",{get:function(){return modelToJSON(this.__instance)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return getModelType(this.__instance)},enumerable:!0,configurable:!0}),__decorate([mobx.computed],e.prototype,"collection",null),__decorate([mobx.computed],e.prototype,"id",null),__decorate([mobx.computed],e.prototype,"original",null),__decorate([mobx.computed],e.prototype,"refs",null),__decorate([mobx.computed],e.prototype,"snapshot",null),__decorate([mobx.computed],e.prototype,"type",null),e}();return function(t){function e(){var e=null!==t&&t.apply(this,arguments)||this;return e.meta=new o(e),e}return __extends(e,t),e}(t)}var Model=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.prototype.valueOf=function(){var e=this.meta.snapshot;return delete e[datxUtils.META_FIELD],__assign({},e,{meta:{id:this.meta.id,type:this.meta.type}})},t.prototype.toString=function(){return JSON.stringify(this.valueOf(),null,2)},t}(withPatches(withActions(withMeta(PureModel)))),Collection=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t.defaultModel=Model,t}(withPatches(PureCollection)),CompatModel=function(o){function e(e,t){var r=o.call(this,e,t)||this;return datxUtils.deprecated("CompatModel is just a migration tool. Please move to Model or PureModel as soon as possible."),Object.keys(r.static.refs).forEach(function(e){if(!(e in getModelMetaKey(r,"refs"))){var t=r.static.refs[e],o=datxUtils.mapItems(r[e]||r.static.defaults[e],getModelId);datxUtils.assignComputed(r,e),initModelRef(r,e,"object"==typeof t?{model:t.model,property:t.property,type:exports.ReferenceType.TO_ONE_OR_MANY}:{model:t,type:exports.ReferenceType.TO_ONE_OR_MANY},o)}}),Object.keys(r.static.defaults).forEach(function(e){e in r.static.refs||e in r||initModelField(r,e,r.static.defaults[e])}),r}return __extends(e,o),e.__datxInitProps=function(){this.idAttribute&&storage.setModelClassMetaKey(this,"id",this.idAttribute),this.typeAttribute&&storage.setModelClassMetaKey(this,"type",this.typeAttribute)},e.prototype.getRecordId=function(){return datxUtils.deprecated("model.getRecordId is deprecated. Use getModelId() instead."),getModelId(this)},e.prototype.getRecordType=function(){return datxUtils.deprecated("model.getRecordType is deprecated. Use getModelType() instead."),getModelType(this)},e.prototype.assign=function(e,t){datxUtils.deprecated("model.assign is deprecated. Use assignModel() instead.");var o=FieldType.DATA,r=storage.getModelClassMetaKey(this.static,"id"),n=storage.getModelClassMetaKey(this.static,"type");return e===r?o=FieldType.ID:e===n&&(o=FieldType.TYPE),updateField(this,e,t,o),t},e.prototype.assignRef=function(e,t,o){if(datxUtils.deprecated("model.assignRef is deprecated. Use initModelRef() instead."),getModelMetaKey(this,"refs")[e])return this[e]=t;var r=o;if(r||(t instanceof Array||mobx.isObservableArray(t)?r=t.reduce(function(e,t){return e||getModelType(t)},null):t instanceof PureModel&&(r=getModelType(t))),!r)throw new Error("The type property is missing");return initModelRef(this,e,{model:r,type:exports.ReferenceType.TO_ONE_OR_MANY},t),this[e]},e.prototype.update=function(e){var t=this;datxUtils.deprecated("model.update is deprecated. Use updateModel() instead.");var o=Object.assign({},e);return Object.keys(o).forEach(function(e){"function"==typeof t[e]&&delete o[e]}),updateModel(this,o)},Object.defineProperty(e.prototype,"static",{get:function(){return datxUtils.deprecated("model.static is deprecated."),this.constructor},enumerable:!0,configurable:!0}),e.prototype.toJS=function(){return datxUtils.deprecated("model.toJS() is deprecated. Use modelToJSON() instead."),modelToJSON(this)},Object.defineProperty(e.prototype,"snapshot",{get:function(){return datxUtils.deprecated("model.snapshot is deprecated. Use modelToJSON() instead."),modelToJSON(this)},enumerable:!0,configurable:!0}),Object.defineProperty(e.prototype,"__collection",{get:function(){return datxUtils.deprecated("model.__collection is deprecated. Use getModelCollection() instead."),getModelCollection(this)},enumerable:!0,configurable:!0}),e.refs={},e.defaults={},e.idAttribute="id",e.typeAttribute="__type__",e}(PureModel),CompatCollection=function(t){function e(e){var o=t.call(this,e)||this;return datxUtils.deprecated("CompatCollection is just a migration tool. Please move to Collection as soon as possible."),o.static.types.forEach(function(e){var t=getModelType(e);datxUtils.assignComputed(o,t.toString(),function(){return o.findAll(t)})}),o}return __extends(e,t),Object.defineProperty(e.prototype,"static",{get:function(){return datxUtils.deprecated("collection.static is deprecated."),this.constructor},enumerable:!0,configurable:!0}),e.prototype.toJS=function(){return datxUtils.deprecated("collection.toJS() is deprecated. Use collection.toJSON() instead"),this.toJSON()},e.types=[CompatModel],e}(Collection);function getClass(e){return"function"==typeof e?e:e.constructor}function propFn(e,t){storage.addModelDefaultField(getClass(e),t)}var prop=Object.assign(propFn,{defaultValue:function(o){return function(e,t){storage.addModelDefaultField(getClass(e),t,o)}},toOne:function(o){return function(e,t){storage.addModelClassReference(getClass(e),t,{model:o,type:exports.ReferenceType.TO_ONE})}},toMany:function(o,r){return function(e,t){storage.addModelClassReference(getClass(e),t,{model:o,property:r,type:exports.ReferenceType.TO_MANY})}},toOneOrMany:function(o){return function(e,t){storage.addModelClassReference(getClass(e),t,{model:o,type:exports.ReferenceType.TO_ONE_OR_MANY})}},identifier:function(e,t){storage.addModelDefaultField(getClass(e),t),storage.setModelClassMetaKey(getClass(e),"id",t)},type:function(e,t){storage.addModelDefaultField(getClass(e),t),storage.setModelClassMetaKey(getClass(e),"type",t)}});function setupModel(e,t){var o=void 0===t?{fields:{}}:t,r=o.fields,n=o.references,i=o.type,a=o.idAttribute,s=o.typeAttribute,d=e;if(!isModel(d))throw error(DECORATE_MODEL);var l=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return __extends(t,e),t}(d);return i&&(l.type=i),a&&prop.identifier(l.prototype,a),s&&prop.type(l.prototype,s),r&&Object.keys(r).forEach(function(e){prop.defaultValue(r[e])(l.prototype,e)}),n&&Object.keys(n).forEach(function(e){var t=n[e],o=t.model,r=t.property;switch(n[e].type){case exports.ReferenceType.TO_ONE:return void prop.toOne(o)(l.prototype,e);case exports.ReferenceType.TO_MANY:return void prop.toMany(o,r)(l.prototype,e);default:return void prop.toOneOrMany(o)(l.prototype,e)}}),l}exports.Collection=Collection,exports.Model=Model,exports.View=View,exports.PureCollection=PureCollection,exports.PureModel=PureModel,exports.CompatCollection=CompatCollection,exports.CompatModel=CompatModel,exports.getRefId=getRefId,exports.setRefId=setRefId,exports.updateModelId=updateModelId,exports.initModelRef=initModelRef,exports.assignModel=assignModel,exports.cloneModel=cloneModel,exports.getModelClassRefs=getModelClassRefs,exports.getModelCollection=getModelCollection,exports.getModelId=getModelId,exports.getModelMetaKey=getModelMetaKey,exports.getModelType=getModelType,exports.getOriginalModel=getOriginalModel,exports.modelToJSON=modelToJSON,exports.setModelMetaKey=setModelMetaKey,exports.updateModel=updateModel,exports.isCollection=isCollection,exports.isModel=isModel,exports.isView=isView,exports.setupModel=setupModel,exports.withActions=withActions,exports.withMeta=withMeta,exports.withPatches=withPatches,exports.prop=prop;
{
"name": "datx",
"version": "0.15.4",
"version": "0.15.5",
"description": "A MobX data store",

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

"jest": "^23.6.0",
"mobx": "^5.8.0",
"mobx": "^5.9.0",
"rollup": "^1.1.0",

@@ -34,3 +34,3 @@ "rollup-plugin-typescript2": "^0.19.2",

"peerDependencies": {
"mobx": "^4.2.0 || ^5.5.0"
"mobx": "^5.9.0"
},

@@ -67,4 +67,4 @@ "scripts": {

"dependencies": {
"datx-utils": "^0.15.4"
"datx-utils": "^0.15.5"
}
}

Sorry, the diff of this file is not supported yet

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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