Comparing version 2.0.1 to 2.0.2
@@ -1,1 +0,1 @@ | ||
"use strict";require("@datx/utils").mobx.useMobx(!1); | ||
"use strict";function e(){for(var e=0,t=0,r=arguments.length;t<r;t++)e+=arguments[t].length;var n=Array(e),o=0;for(t=0;t<r;t++)for(var a=arguments[t],i=0,s=a.length;i<s;i++,o++)n[o]=a[i];return n}var t=function(){},r={autorun:function(e){return e(),t},isObservableArray:function(e){return!1},set:function(e,t,r){"string"==typeof t?e[t]=r:Object.assign(e,t)},extendObservable:function(e,t){var r=Object.getOwnPropertyDescriptors(t);return Object.defineProperties(e,r)},observable:function(e){for(var t=[],r=1;r<arguments.length;r++)t[r-1]=arguments[r]},computed:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e[2]},action:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1===e.length?e[0]:e[2]},makeObservable:function(e,t){},runInAction:function(e){e()},toJS:function(e){return e},reaction:function(e,r){return e(),r(),t},intercept:function(e,r,n){return Object.freeze("string"==typeof r?e[r]:e),t}};r.observable.object=function(e){return e},r.observable.array=function(e){return e},(new(function(){function t(){var t=this;this._useRealMobX=!0,this.access=!1,this.hasMobX=!1;try{var n=require("mobx");this.hasMobX=Boolean(null==n?void 0:n.observable)}catch(e){}var o=this;Object.keys(r).forEach((function(n){n in t||Object.defineProperty(t,n,{get:function(){return!o.hasMobX&&o._useRealMobX&&function(){for(var t=[],r=0;r<arguments.length;r++)t[r]=arguments[r];"production"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV&&console.warn.apply(console,e(["[datx warning]"],t))}("MobX not installed. Falling back to the static approach. Import `datx/disable-mobx` before the first `datx` import to disable this warning"),o.access=!0,o.useRealMobX?require("mobx")[n]:r[n]}})}))}return t.prototype.useMobx=function(e){if(this.access)throw new Error("[datx] MobX was already used. Please move this function call to somewhere earlier.");this._useRealMobX=e},Object.defineProperty(t.prototype,"useRealMobX",{get:function(){return this._useRealMobX&&this.hasMobX},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"makeObservable",{get:function(){if(this.useRealMobX)try{return require("mobx").makeObservable||r.makeObservable}catch(e){return r.makeObservable}return r.makeObservable},enumerable:!1,configurable:!0}),t}())).useMobx(!1); |
@@ -1,1 +0,1 @@ | ||
"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)t.hasOwnProperty(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; | ||
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=Symbol.for("datx administration");function t(){for(var e=0,t=0,n=arguments.length;t<n;t++)e+=arguments[t].length;var r=Array(e),o=0;for(t=0;t<n;t++)for(var i=arguments[t],a=0,u=i.length;a<u;a++,o++)r[o]=i[a];return r}var n=function(){},r={autorun:function(e){return e(),n},isObservableArray:function(e){return!1},set:function(e,t,n){"string"==typeof t?e[t]=n:Object.assign(e,t)},extendObservable:function(e,t){var n=Object.getOwnPropertyDescriptors(t);return Object.defineProperties(e,n)},observable:function(e){for(var t=[],n=1;n<arguments.length;n++)t[n-1]=arguments[n]},computed:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return e[2]},action:function(){for(var e=[],t=0;t<arguments.length;t++)e[t]=arguments[t];return 1===e.length?e[0]:e[2]},makeObservable:function(e,t){},runInAction:function(e){e()},toJS:function(e){return e},reaction:function(e,t){return e(),t(),n},intercept:function(e,t,r){return Object.freeze("string"==typeof t?e[t]:e),n}};r.observable.object=function(e){return e},r.observable.array=function(e){return e};var o,i=new(function(){function e(){var e=this;this._useRealMobX=!0,this.access=!1,this.hasMobX=!1;try{var t=require("mobx");this.hasMobX=Boolean(null==t?void 0:t.observable)}catch(e){}var n=this;Object.keys(r).forEach((function(t){t in e||Object.defineProperty(e,t,{get:function(){return!n.hasMobX&&n._useRealMobX&&_("MobX not installed. Falling back to the static approach. Import `datx/disable-mobx` before the first `datx` import to disable this warning"),n.access=!0,n.useRealMobX?require("mobx")[t]:r[t]}})}))}return e.prototype.useMobx=function(e){if(this.access)throw new Error("[datx] MobX was already used. Please move this function call to somewhere earlier.");this._useRealMobX=e},Object.defineProperty(e.prototype,"useRealMobX",{get:function(){return this._useRealMobX&&this.hasMobX},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"makeObservable",{get:function(){if(this.useRealMobX)try{return require("mobx").makeObservable||r.makeObservable}catch(e){return r.makeObservable}return r.makeObservable},enumerable:!1,configurable:!0}),e}());function a(e){return Array.isArray(e)||i.isObservableArray(e)}function u(e,t){return a(e)?e.map((function(e){return t(e)})):null===e?null:t(e)}function l(){}function c(){throw new Error("The setter is not defined for this property")}function s(t){return Object.prototype.hasOwnProperty.call(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!1,value:i.observable.object({},{},{deep:!1})}),t[e]}function f(e,t,n){var r=s(e);i.set(r,t,n)}function d(e,t,n,r,o){if(r)return function(e,t,n){for(var r=n,o=e;o;)r=t(r,o),o=Object.getPrototypeOf(o);return r}(e,(function(e,n){var r=d(n,t,o?{}:void 0);return o?Object.assign({},r,e):e||r}),o?{}:void 0)||n;var i=s(e);return void 0===i[t]?n:i[t]}function p(e,t,n,r){void 0===n&&(n=l),void 0===r&&(r=c);var o=i.extendObservable({},{get getter(){return n.call(e)}});Object.defineProperty(e,t,{get:function(){return o.getter},set:function(t){r.call(e,t)},enumerable:!0,configurable:!0})}function _(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];"production"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV&&console.warn.apply(console,t(["[datx warning]"],e))}function h(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];"production"!==process.env.NODE_ENV&&"test"!==process.env.NODE_ENV&&console.warn.apply(console,t(["[datx deprecated]"],e))}function y(e,t){return i.isObservableArray(e)?e.replace(t):(e.length=0,e.push.apply(e,t),e)}function v(e,t){if(i.isObservableArray(e))return e.remove(t);var n=e.indexOf(t);return e.splice(n,1)}(o=exports.ReferenceType||(exports.ReferenceType={}))[o.TO_ONE=0]="TO_ONE",o[o.TO_MANY=1]="TO_MANY",o[o.TO_ONE_OR_MANY=2]="TO_ONE_OR_MANY";var b=function(e,t){return(b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var n in t)t.hasOwnProperty(n)&&(e[n]=t[n])})(e,t)};function O(e,t){function n(){this.constructor=e}b(e,t),e.prototype=null===t?Object.create(t):(n.prototype=t.prototype,new n)}var m=function(){return(m=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 g(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 w,M,T,x=/\$\{\s*([a-zA-Z0-9\-_]+)\s*\}/g;function P(e,t){return void 0===t&&(t={}),new Error(("[datx exception] "+function(e,t){for(var n=e,r=x.exec(n);r;)n=n.replace(r[0],t[r[1]]),r=x.exec(n);return n}(e,t)).replace(/\s+/g," "))}function j(e,t){var n=d(e,"ref_"+t);return n?n.value:null}function E(e,t,n){var r;(null===(r=d(e,w.Fields,{})[t])||void 0===r?void 0:r.referenceDef)&&(a(e[t])?e[t].includes(n)||e[t].push(n):e[t]=n)}function A(e,t,n){a(e[t])?e[t].remove(n):e[t]===n&&(e[t]=null)}function V(e){return 0===Object.keys(e).length}function k(e,t){var n=Object.assign({},e,{model:{id:Z(t),type:W(t)}}),r=d(t,w.PatchListeners,[]).slice(),o=$(t);o&&"__patchListeners"in o&&(o.__patchListeners||[]).forEach((function(e){r.push(e)})),r.forEach((function(e){e(n)}))}function L(e){var t=d(e,w.Patch,{count:0,newValue:{},oldValue:{}});t.count++,f(e,w.Patch,t)}function I(e,t){void 0===t&&(t=exports.PatchType.UPDATE);var n=d(e,w.Patch,{count:0,newValue:{},oldValue:{}});if(n.count--,0===n.count){var r=i.toJS(n.newValue),o=i.toJS(n.oldValue);V(r)&&V(o)||k({newValue:r,oldValue:o,patchType:t},e),f(e,w.Patch,{count:0,oldValue:{},newValue:{}})}else f(e,w.Patch,n)}function F(e,t,n,r){L(e),function(e,t,n,r){var o=d(e,w.Patch,{count:0,newValue:{},oldValue:{}});if(!(e[t]===n&&!r||r&&n===r.value)){var i=d(e,w.Fields,{});t in o.oldValue||(r?o.oldValue[t]=r.value:t in i&&i[t].referenceDef?o.oldValue[t]=H(e[t]):o.oldValue[t]=e[t]),o.newValue[t]=t in i&&i[t].referenceDef?H(n):n,f(e,w.Patch,o)}}(e,t,n,r),I(e)}function N(e,t,n,r,o){return"function"==typeof e?W(e(t,n,r,o)):e}function R(e,t,n,r,o){return u(e,(function(e){return null==e?null:"object"!=typeof e||U(e)?"object"==typeof e&&U(e)?(null==t?void 0:t.findOne(e))||e:(null==t?void 0:t.findOne(N(n.referenceDef.model,e,r,o,t),e))||{id:e,type:N(n.referenceDef.model,e,r,o,t)}:(null==t?void 0:t.add(e,N(n.referenceDef.model,e,r,o,t)))||null}))}function D(e,n,r,o){var l=d(e,w.Fields,{}),c=l[n]||{referenceDef:r},s=$(e);if(!s&&o)throw P("The model needs to be in a collection to be referenceable");if(r&&(l[n]={referenceDef:r}),c.referenceDef.property)p(e,n,(function(){return function(e,t){var n,r=null===(n=d(e,w.Fields,{})[t])||void 0===n?void 0:n.referenceDef;if(!r||!r.property)return null;var o=$(e);if(!o)return null;var a=o.getAllModels().filter((function(t){return function(e,t,n){return null!==e[t]&&void 0!==e[t]&&(e[t]instanceof S?e[t]===n:e[t].includes(n))}(t,r.property,e)})),u=i.observable.array(a,{deep:!1});return i.intercept(u,(function(n){return function(e,t,n){var r,o=null===(r=d(e,w.Fields,{})[t])||void 0===r?void 0:r.referenceDef;return o?"splice"===n.type?function(e,t,n,r){var o=r.property;return n.added.forEach((function(t){return E(t,o,e)})),e[t].slice(n.index,n.index+n.removedCount).forEach((function(t){return A(t,o,e)})),null}(e,t,n,o):function(e,t,n,r){var o=r.property,i=e[t].length>n.index?e[t][n.index]:null;return n.newValue&&E(n.newValue,o,e),i&&A(i,o,e),_("This shouldn't have happened. Please open an issue: https://github.com/infinum/datx/issues/new"),null}(e,t,n,o):null}(e,t,n)})),u}(e,n)}),(function(e){!function(e,t,n){throw P("Back references are read only")}()}));else{var h=function(e){if(e===exports.ReferenceType.TO_ONE)return ce;if(e===exports.ReferenceType.TO_ONE_OR_MANY)return se;if(e===exports.ReferenceType.TO_MANY)return le;throw function(){for(var e=[],n=0;n<arguments.length;n++)e[n]=arguments[n];console.error.apply(console,t(["[datx error]"],e))}("Unknown reference type")}(c.referenceDef.type),y=c.referenceDef.type===exports.ReferenceType.TO_MANY?[]:null;null!=o&&(y=R(o,s,c,e,n));var v=new h(y,s,!1,e,n,!0);F(e,n,v.value),f(e,"ref_"+n,v),p(e,n,(function(){return j(e,n)}),(function(t){F(e,n,t),function(e,t,n){var r=d(e,"ref_"+t);if(X(n)||a(n)){var o=d(e,w.Fields,{})[t],i=N(o.referenceDef.model,o.referenceDef.defaultValue,e,t,$(e));n=u(n,(function(e){return X(e)?{id:e,type:i}:H(e)}))}r&&(r.value=n)}(e,n,R(t,s,c,e,n))}))}}function B(e,t,n){var r=d(e,w.Fields,{})[t],o=d(e.constructor,M.TypeField,"__datx__type__",!0),a=d(e.constructor,M.IdField,"__datx__id__",!0);t===o?p(e,t,(function(){return W(e)}),(function(){throw P("Model type can't be changed after initialization.")})):t===a?p(e,t,(function(){return Z(e)}),(function(){throw P("Model ID can't be updated directly. Use the `updateModelId` helper function instead.")})):r.referenceDef?D(e,t,void 0,n):(f(e,"data__"+t,void 0),p(e,t,(function(){return d(e,"data__"+t)}),(function(n){var r,o="object"!=typeof(r=n)||null===r||r instanceof S?n:i.observable.object(n);F(e,t,n),f(e,"data__"+t,o)})),e[t]=n)}function C(e,t,n){var r=e.constructor,o=d(e.constructor,M.Fields,{},!0,!0),i=null==t?void 0:t.__META__,u=Object.assign({},o,null==i?void 0:i.fields);f(e,w.Collection,n);var l=d(e.constructor,M.TypeField,"__datx__type__",!0);f(e,w.TypeField,Y(t[l],null==i?void 0:i.type,r.type));var c=d(e.constructor,M.IdField,"__datx__id__",!0);f(e,w.IdField,Y(t[c],null==i?void 0:i.id,(function(){return r.getAutoId()}))),f(e,w.OriginalId,null==i?void 0:i.originalId),Object.keys(t).filter((function(e){return"__META__"!==e})).filter((function(e){return!(e in u)})).forEach((function(e){var n=t[e],r=n instanceof S||a(n)&&n.length&&(n[0]instanceof S||U(n[0]))||U(n);u[e]={referenceDef:!!r&&{type:exports.ReferenceType.TO_ONE_OR_MANY,model:W(n)}}})),f(e,w.Fields,u),Object.keys(u).forEach((function(n){var o,i=u[n],a=m(((o={})[n]=i.defaultValue,o),t);B(e,n,z(r,a,n))})),ie(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"}(w||(w={})),function(e){e.Fields="fields",e.IdField="idField",e.TypeField="typeField",e.MapParse="parse",e.MapSerialize="serialize"}(M||(M={})),(T=exports.PatchType||(exports.PatchType={}))[T.CRATE=0]="CRATE",T[T.UPDATE=1]="UPDATE",T[T.REMOVE=2]="REMOVE";var S=function(){function e(e,t){void 0===e&&(e={}),L(this),C(this,e,t),I(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="__DEFAULT_TYPE__",e.autoIdValue=0,e.enableAutoId=!0,e}(),J=function(e,t){return e};function z(e,t,n){return d(e,M.MapParse+"_"+n,J,!0)(t[n],t)}function q(e,t,n){return d(e,M.MapSerialize+"_"+n,J,!0)(t[n],t)}function U(e){return a(e)?e.every(U):"object"==typeof e&&null!==e&&"type"in e&&"id"in e&&2===Object.keys(e).length}function X(e){return"string"==typeof e||"number"==typeof e}function Y(){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 W(e){return"function"==typeof e||U(e)?e.type:"object"==typeof e?d(e,w.TypeField)||e.constructor.type:e}function Z(e){if(e instanceof S){var t=d(e,w.IdField);if(void 0!==t)return t;throw P("Model without an ID")}return e}function $(e){return d(e,w.Collection)}function G(e){return!(e instanceof S)}function H(e){return e instanceof S?{id:Z(e),type:W(e)}:e}var K=[w.Patch,w.PatchListeners,w.Collection,w.Commit,w.OriginalId,"get__","set__","data__","ref_"];function Q(e){var t,n,r,o,a=s(e),u=d(e,w.Fields,{}),l=Object.keys(a).filter((function(e){return!K.some((function(t){return e.startsWith(t)}))})),c=((t={}).__META__=Object.assign({},(r=l.map((function(e){return[e,a[e]]})),o={},r.forEach((function(e){var t=e[0],n=e[1];o[t]=n})),o),((n={})[w.IdField]=Z(e),n[w.TypeField]=W(e),n[w.Collection]=void 0,n)),t);return Object.keys(u).forEach((function(t){if(u[t].referenceDef){var n=d(e,"ref_"+t);c[t]=(null==n?void 0:n.snapshot)||null}else c[t]=q(e.constructor,e,t)})),i.toJS(c)}function ee(e){var t=Q(e),n=t.__META__||{};n[w.OriginalId]=n[w.IdField],delete n[w.IdField];var r=$(e);if(r){var o=W(e);return r.add(t,o)}var i=e.constructor;return _("The model is not in the collection. Referencing the original model won't be possible"),new i(t)}var te=[w.Fields,w.IdField,w.TypeField];function ne(e,t,n){i.runInAction((function(){var r,o;if(!(e instanceof S))throw P("The given parameter is not a valid model");var l=d(e,w.Fields,{}),c=a(n)&&n.length>0&&n[0]instanceof S||n instanceof S;if(t in l){if(c&&!l[t].referenceDef)throw P("You should save this value as a reference.");e[t]=n}else c?i.extendObservable(l,((r={})[t]={referenceDef:{type:exports.ReferenceType.TO_ONE_OR_MANY,models:Array.from(new Set(u(n,W)))}},r)):i.extendObservable(l,((o={})[t]={referenceDef:!1},o)),f(e,w.Fields,l),B(e,t,n)}))}function re(e,t){L(e);var n,r,o,i=d(e.constructor,M.IdField,"__datx__id__"),a=d(e.constructor,M.TypeField,"__datx__type__"),u=Object.keys(t instanceof S?Q(t):t);return n=e,r=function(e,t){var n={};return Object.keys(e).filter((function(e){return!t.includes(e)})).forEach((function(t){n[t]=e[t]})),n}(t.__META__||{},te),o=s(n),Object.assign(o,r),u.forEach((function(n){"__META__"!==n&&n!==i&&n!==a?ne(e,n,t[n]):"__META__"===n&&Object.keys(t[n]||{}).forEach((function(r){te.includes(r)||f(e,r,t[n][r])}))})),I(e),e}function oe(e,t){f(e,w.Collection,t);var n=d(e,w.Fields,{});L(e),Object.keys(n).forEach((function(n){var r=d(e,"ref_"+n);r&&r.setCollection(t)})),I(e)}function ie(e){f(e,w.Commit,m(m({},Q(e)),{__META__:void 0}))}function ae(e){var t=d(e,w.Commit);t&&re(e,t)}function ue(e,t){var n,r,o=d(e,w.Commit);if(o){var i=d(e,w.Fields,{})[t];return void 0!==i&&(n=i.referenceDef?u(e[t],H):e[t],r=o[t],!(JSON.stringify(n)===JSON.stringify(r)))}return!0}var le=function(){function e(e,t,n,r,o,u){var l=this;if(void 0===e&&(e=[]),void 0===n&&(n=!1),void 0===u&&(u=!0),this.__readonly=n,this.__model=r,this.__key=o,this.__skipMissing=u,this.__rawList=i.observable.array([]),i.makeObservable(this),(null==e?void 0:e.length)>0&&!t)throw P("The model needs to be in a collection to be referenceable");if(e&&!a(e))throw P("The reference must be an array of values.");i.runInAction((function(){y(l.__rawList,e||[]),l.setCollection(t)}))}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=i.reaction((function(){return t.__rawList.filter(G).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 t=this;if(this.__readonly)throw P("This is a read-only bucket");if(null===e)e=[];else if(!a(e))throw P("The reference must be an array of values.");i.runInAction((function(){y(t.__rawList,e),t.__model&&t.__key&&F(t.__model,t.__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(H)},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&&$(e))})),n=i.observable.array(t,{deep:!1});return i.intercept(n,this.__partialRawListUpdate.bind(this)),n},e.prototype.__getModel=function(e){if(e instanceof S||null===e)return e;if(!this.__collection)throw P("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 P("This is a read-only bucket");if("splice"===e.type){var n=e.added;return i.runInAction((function(){t.__rawList.slice(e.index,e.removedCount),t.__rawList.splice.apply(t.__rawList,[e.index,e.removedCount].concat(n))})),null}return i.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(G(this.__rawList[e])){var t=this.__getModel(this.__rawList[e]);t&&(this.__rawList[e]=t)}},g([i.computed],e.prototype,"value",null),g([i.computed],e.prototype,"length",null),g([i.computed],e.prototype,"refValue",null),g([i.computed],e.prototype,"snapshot",null),e}(),ce=function(){function e(e,t,n,r,o,u){if(void 0===n&&(n=!1),void 0===u&&(u=!0),this.__collection=t,this.__readonly=n,this.__model=r,this.__key=o,this.__skipMissing=u,this.__rawValue=null,i.makeObservable(this),e&&!this.__collection)throw P("The model needs to be in a collection to be referenceable");if(a(e))throw P("The reference can't be an array of values.");if(!(U(e)||e instanceof S||null===e))throw P("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 P("The model needs to be in a collection to be referenceable");if(this.__readonly)throw P("This is a read-only bucket");if(a(e))throw P("The reference can't be an array of values.");if(!(U(e)||e instanceof S||null===e))throw P("The value needs to be a reference");this.__rawValue=e,this.__model&&this.__key&&F(this.__model,this.__key,e)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refValue",{get:function(){return this.__rawValue?H(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 S||null===e)return e;if(!this.__collection)throw P("The model needs to be in a collection to be referenceable");return this.__collection.findOne(e.type,e.id)||(this.__skipMissing?null:e)},g([i.observable],e.prototype,"__rawValue",void 0),g([i.computed],e.prototype,"value",null),g([i.computed],e.prototype,"refValue",null),g([i.computed],e.prototype,"snapshot",null),e}(),se=function(){function e(e,t,n,r,o,u){var l=this;void 0===n&&(n=!1),void 0===u&&(u=!0),this.__collection=t,this.__readonly=n,this.__model=r,this.__key=o,this.__skipMissing=u,this.__isList=!0,i.makeObservable(this),i.runInAction((function(){l.__isList=a(e),l.__isList?l.__toManyBucket=new le(e,t,n,r,o,u):l.__toOneBucket=new ce(e,t,n,r,o,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 t=this;i.runInAction((function(){t.__isList=a(e),t.__isList?t.__toManyBucket?t.__toManyBucket.value=e:t.__toManyBucket=new le(e,t.__collection):t.__toOneBucket?t.__toOneBucket.value=e:t.__toOneBucket=new ce(e,t.__collection)}))},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"__readonlyValue",{set:function(e){var t=this;i.runInAction((function(){if(t.__isList=a(e),t.__isList)if(t.__toManyBucket){var n=t.__toManyBucket.__readonly;t.__toManyBucket.__readonly=!1,t.__toManyBucket.value=e,t.__toManyBucket.__readonly=n}else t.__toManyBucket=new le(e,t.__collection);else t.__toOneBucket?(n=t.__toOneBucket.__readonly,t.__toOneBucket.__readonly=!1,t.__toOneBucket.value=e,t.__toOneBucket.__readonly=n):t.__toOneBucket=new ce(e,t.__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}),g([i.observable],e.prototype,"__isList",void 0),g([i.computed],e.prototype,"value",null),g([i.computed],e.prototype,"refValue",null),g([i.computed],e.prototype,"snapshot",null),e}();function fe(e,t,n){var r,o,i;if(!t&&0!==t)throw P("The type needs to be defined if the object is not an instance of the model.");var a=n.constructor,u=a.types.find((function(e){return e.type===t}));if(!u){var l=a.defaultModel;if(l)return new l(Object.assign({},e,((r={}).__META__=Object.assign({},e.__META__||{},{type:t}),r)),n);throw P("No model is defined for the type "+t+".")}var c=null===(o=null==e?void 0:e.__META__)||void 0===o?void 0:o[w.IdField],s=d(u,M.IdField),f=s&&null!==(i=null==e?void 0:e[s])&&void 0!==i?i:c,p=f&&n.findOne(t,f);if(p){var _=d(u,M.Fields),h=Object.keys(m(m({},e),_)),y={};return h.forEach((function(t){var n,r,o=Boolean(null===(r=null===(n=_[t])||void 0===n?void 0:n.referenceDef)||void 0===r?void 0:r.property),i=z(u,e,t);o&&void 0===i&&!(t in e)||(y[t]=i)})),re(p,y)}return new u(u.preprocess(e),n)}var de=function(e){function t(t,n,r,o,a){void 0===o&&(o=[]),void 0===a&&(a=!1);var u=e.call(this,o.map((function(e){return e instanceof S?e:{id:e,type:W(t)}})),n)||this;return u.__collection=n,u.unique=a,u.modelType=W(t),u.sortMethod=r,i.makeObservable(u,{sortMethod:i.observable,length:i.computed,list:i.computed}),u}return O(t,e),Object.defineProperty(t.prototype,"length",{get:function(){return this.value.length},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"list",{get:function(){var e=this,t=this.value.slice();if(this.sortMethod){var n="string"==typeof this.sortMethod?function(t){return t[e.sortMethod]}:this.sortMethod;t.sort((function(e,t){return n(e)===n(t)?0:n(e)>n(t)?1:-1}))}var r=i.observable.array(t,{deep:!1});return i.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}),t.prototype.toJSON=function(){return{modelType:this.modelType,models:this.__rawList.map(Z).slice(),unique:this.unique}},t.prototype.add=function(e){var t=this,n=u(e,(function(e){return t.__collection.add(e,t.modelType)}));return i.runInAction((function(){u(n,(function(e){t.unique&&-1!==t.__indexOf(e)||t.__rawList.push(e)}))})),n},t.prototype.hasItem=function(e){var t=Z(e);return Boolean(this.__getList().find((function(e){return Z(e)===t})))},t.prototype.remove=function(e){var t=this;i.runInAction((function(){var n=t.__getModel(t.__normalizeModel(e));n&&v(t.__rawList,n)}))},t.prototype.removeAll=function(){var e=this;i.runInAction((function(){y(e.__rawList,[])}))},t.prototype.__partialListUpdate=function(e){var t=this;if("splice"===e.type){if(this.sortMethod&&e.added.length>0)throw P("New models can't be added directly to a sorted view list");var n=e.added.map(this.__normalizeModel.bind(this)),r=this.__rawList.slice(e.index,e.removedCount);return this.unique&&n.forEach((function(e,o){if(-1!==t.__indexOf(e)&&(-1===t.__indexOf(e,r)||t.__indexOf(e,n)!==o))throw P("The models in this view need to be unique")})),i.runInAction((function(){t.__rawList.splice.apply(t.__rawList,[e.index,e.removedCount].concat(n))})),null}return i.runInAction((function(){if(t.sortMethod&&e.newValue)throw P("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 P("The models in this view need to be unique");t.__rawList[e.index]=n}})),null},t.prototype.__normalizeModel=function(e){return e instanceof S?e:{id:e,type:this.modelType}},t.prototype.__indexOf=function(e,t){return void 0===t&&(t=this.__rawList),t.findIndex((function(t){return t instanceof S&&e instanceof S?t===e:!(!G(t)||e instanceof S)&&t.id===e.id&&t.type===e.type}))},g([i.observable],t.prototype,"sortMethod",void 0),g([i.computed],t.prototype,"length",null),g([i.computed],t.prototype,"list",null),t}(le),pe=function(){function e(e){var t=this;void 0===e&&(e=[]),this.__data=i.observable.array([],{deep:!1}),this.__views=[],this.__dataMap=i.observable.object({},void 0,{deep:!1}),this.__dataList=i.observable.object({},void 0,{deep:!1}),i.extendObservable(this,{}),a(e)?this.insert(e):e&&"models"in e&&this.insert(e.models);var n=this.constructor,r=e&&"views"in e?e.views:{};Object.keys(n.views).forEach((function(e){var o=n.views[e],i=r[e]||o;t.addView(e,i.modelType,{mixins:o.mixins,models:i.models||[],sortMethod:o.sortMethod,unique:i.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 P("The name is already taken");var c=l?l.reduce((function(e,t){return t(e)}),de):de;return this.__views.push(e),this[e]=new c(t,this,o,a,u),this[e]},e.prototype.insert=function(e){var t=function(e,t){return t.map((function(t){return function(e,t){var n;return fe(t,null===(n=null==t?void 0:t.__META__)||void 0===n?void 0:n[w.TypeField],e)}(e,t)}))}(this,e);return this.__insertModel(t),t},e.prototype.hasItem=function(e){var t=Z(e);return Boolean(this.findOne(e,t))},e.prototype.add=function(e,t){return a(e)?this.__addArray(e,t):this.__addSingle(e,t)},e.prototype.filter=function(e){return this.__data.filter(e)},e.prototype.findOne=function(e,t){if(t instanceof S)return t;if(U(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 n=W(e);return n in this.__dataList||i.runInAction((function(){var e;i.set(t.__dataList,((e={})[n]=i.observable.array([]),e))})),this.__dataList[n]}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){f(e,w.Collection,void 0),k({oldValue:Q(e),patchType:exports.PatchType.REMOVE},e)})),y(this.__data,[]),this.__dataList=i.observable.object({},{},{deep:!1}),this.__dataMap=i.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(Q),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 n=this,r=W(e);if(!r)return null;var o=r.toString(),a=t.toString();return i.runInAction((function(){var e;r in n.__dataMap?a in n.__dataMap[o]||i.set(n.__dataMap[o],a,null):i.set(n.__dataMap,o,i.observable.object(((e={})[a]=null,e),{},{deep:!1}))})),this.__dataMap[o][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||U(e))return e;if(e instanceof S)return this.hasItem(e)||this.__insertModel(e),e;if(!t&&0!==t)throw P("The type needs to be defined if the object is not an instance of the model.");var n=W(t),r=fe(e,n,this);return this.__insertModel(r,n),r},e.prototype.__removeModel=function(e,t,n){var r=this;if(a(e))e.forEach((function(e){r.__removeModel(e,t,n)}));else{var o=t||W(e),u=n||Z(e);k({oldValue:i.toJS(Q(e)),patchType:exports.PatchType.REMOVE},e),i.runInAction((function(){v(r.__data,e),v(r.__dataList[o],e),i.set(r.__dataMap[o],u.toString(),void 0)})),this.__data.forEach((function(e){var t=d(e,M.Fields,{},!0,!0);Object.keys(t||{}).map((function(t){return d(e,"ref_"+t)})).filter(Boolean).forEach((function(t){a(t.value)&&t.value.includes(e)?t.value=t.value.filter((function(t){return t!==e})):t.value===e&&(t.value=null)}))})),oe(e,void 0)}},e.prototype.__insertModel=function(e,t,n){var r=this;if(a(e))e.forEach((function(e){r.__insertModel(e,t,n)}));else{var o=$(e);if(o&&o!==this)throw P("A model can be in a single collection at once");var u=t||W(e),l=n||Z(e),c=u.toString(),s=this.findOne(u,l);s?s!==e&&re(s,e):(i.runInAction((function(){var t;r.__data.push(e),u in r.__dataList?r.__dataList[u].push(e):i.set(r.__dataList,c,i.observable.array([e],{deep:!1})),u in r.__dataMap?i.set(r.__dataMap[u],l.toString(),e):i.set(r.__dataMap,c,i.observable.object(((t={})[l]=e,t),{},{deep:!1})),oe(e,r)})),k({newValue:Q(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=S,e.views={},g([i.computed],e.prototype,"length",null),e}();function _e(e,t){for(var n=e;n;){if(n===t)return!0;n=Object.getPrototypeOf(n)}return!1}function he(e){return _e(e,S)}function ye(e){return _e(e,pe)}function ve(e,t,n){n&&"initializer"in n&&(n.initializer=void 0)}function be(e){return e instanceof S||he(e)||U(e)?W(e):e}function Oe(e,t,n,r){return e?{type:exports.ReferenceType.TO_ONE,model:be(e)}:t?{type:exports.ReferenceType.TO_ONE_OR_MANY,model:be(t)}:!!n&&{type:exports.ReferenceType.TO_MANY,model:be(n),property:r}}function me(e){var t=void 0===e?{}:e,n=t.defaultValue,r=t.isIdentifier,o=t.isType,i=t.toOne,a=t.toOneOrMany,u=t.toMany,l=t.referenceProperty,c=t.parse,s=t.serialize;return function(e,t,p){ve(0,0,p);var _=function(e){return"function"==typeof e?e:e.constructor}(e),h=d(_,M.Fields,{});h[t]={referenceDef:Oe(i,a,u,l),defaultValue:n},f(_,M.Fields,h),f(_,M.MapParse+"_"+t,c),f(_,M.MapSerialize+"_"+t,s),r&&f(_,M.IdField,t),o&&f(_,M.TypeField,t)}}function ge(e,t){return void 0===t&&(t={}),function(n,r,o){ve(0,0,o),Object.hasOwnProperty.call(n.constructor,"views")||(n.constructor.views={}),n.constructor.views[r]=Object.assign({modelType:e},t)}}var we="@prop was deprecated, use @Attribute instead",Me=Object.assign((function(e,t,n){h(we),me()(e,t,n)}),{defaultValue:function(e){return h(we),me({defaultValue:e})},toOne:function(e){return h(we),me({toOne:e})},toMany:function(e,t){return h(we),me({toMany:e,referenceProperty:t})},toOneOrMany:function(e){return h(we),me({toOneOrMany:e})},identifier:me({isIdentifier:!0}),type:me({isType:!0})}),Te=ge;function xe(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 Pe(e){if(ye(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 P(t?"New patch value isn't set for an update patch":"The model should already exist for an update patch");re(t,e.newValue)}else{if(t)throw P("The model shouldn't exist before a create patch");if(!e.newValue)throw P("New patch value isn't set for a create patch");this.add(e.newValue,e.model.type)}},t.prototype.undoPatch=function(e){this.applyPatch(xe(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(he(e))return function(e){function t(t,n){var r=e.call(this,t,n)||this;return f(r,w.PatchListeners,[]),r}return O(t,e),t.prototype.applyPatch=function(e){e.model.type===W(this)&&e.model.id===Z(this)&&re(this,e.newValue||{})},t.prototype.undoPatch=function(e){this.applyPatch(xe(e))},t.prototype.onPatch=function(e){var t=this,n=d(this,w.PatchListeners,[]);return n.push(e),function(){f(t,w.PatchListeners,n.filter((function(t){return t!==e})))}},t}(e);throw P("Only Models and Collections can be decorated with patches")}function je(e){var t=e;if(!he(t))throw P("This mixin can only decorate models");var n=function(){function e(e){this.__instance=e}return Object.defineProperty(e.prototype,"collection",{get:function(){return $(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"id",{get:function(){return Z(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"original",{get:function(){var e=d(this.__instance,w.OriginalId),t=$(this.__instance);return e&&(null==t?void 0:t.findOne(this.__instance,e))||void 0},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"refs",{get:function(){var e=this,t=d(this.__instance,w.Fields,{}),n={};return Object.keys(t).filter((function(e){return t[e].referenceDef})).forEach((function(t){var r=d(e.__instance,"ref_"+t);r&&(n[t]=r&&r.refValue||null)})),n},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"dirty",{get:function(){var e=this,t=d(this.__instance,w.Fields,{}),n={};return Object.keys(t).forEach((function(t){n[t]=ue(e.__instance,t)})),n},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"snapshot",{get:function(){return Q(this.__instance)},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"type",{get:function(){return W(this.__instance)},enumerable:!1,configurable:!0}),g([i.computed],e.prototype,"collection",null),g([i.computed],e.prototype,"id",null),g([i.computed],e.prototype,"original",null),g([i.computed],e.prototype,"refs",null),g([i.computed],e.prototype,"dirty",null),g([i.computed],e.prototype,"snapshot",null),g([i.computed],e.prototype,"type",null),e}();return function(e){function t(t,r){var o=e.call(this,t,r)||this;return o.meta=new n(o),Object.defineProperty(o,"meta",{enumerable:!1}),o}return O(t,e),t}(t)}function Ee(e){var t=e;if(!he(e))throw P("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){re(this,e)},t.prototype.clone=function(){return ee(this)},t.prototype.assign=function(e,t){ne(this,e,t)},t.prototype.addReference=function(e,t,n){D(this,e,{type:n.type,model:W(n.model)},t)},t.prototype.commit=function(){ie(this)},t.prototype.revert=function(){ae(this)},t.prototype.toJSON=function(){return Q(this)},t}(t)}var Ae=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return O(t,e),t.prototype.valueOf=function(){var e=this.meta.snapshot;return delete e.__META__,Object.assign({},e,{meta:{id:this.meta.id,type:this.meta.type}})},t.prototype.toString=function(){return JSON.stringify(this.valueOf(),null,2)},t}(Pe(Ee(je(S)))),Ve=function(e){function t(){return null!==e&&e.apply(this,arguments)||this}return O(t,e),t.defaultModel=Ae,t}(Pe(pe)),ke={ToMany:le,ToOne:ce,ToOneOrMany:se};exports.Attribute=me,exports.Bucket=ke,exports.Collection=Ve,exports.Model=Ae,exports.PureCollection=pe,exports.PureModel=S,exports.View=de,exports.ViewAttribute=ge,exports.assignModel=ne,exports.cloneModel=ee,exports.commitModel=ie,exports.getModelCollection=$,exports.getModelId=Z,exports.getModelType=W,exports.getOriginalModel=function(e){var t=$(e),n=d(e,w.OriginalId);if(n){if(!t)throw P("The model needs to be in a collection to be referenceable");return t.findOne(e,n)}throw P("The given model is not a clone.")},exports.getRef=j,exports.getRefId=function(e,t){var n=d(e,"ref_"+t);return n?n.refValue:null},exports.initModelRef=D,exports.isAttributeDirty=ue,exports.isCollection=ye,exports.isModel=he,exports.isView=function(e){return _e(e,de)},exports.modelMapParse=z,exports.modelMapSerialize=q,exports.modelToDirtyJSON=function(e){var t=m({},Q(e));return Object.keys(e).forEach((function(n){ue(e,n)||delete t[n]})),t},exports.modelToJSON=Q,exports.prop=Me,exports.revertModel=ae,exports.updateModel=re,exports.updateModelId=function(e,t){i.runInAction((function(){var n=$(e),r=Z(e),o=W(e);f(e,w.IdField,t),n&&n.__changeModelId(r,t,o),function(e,t,n,r){var o=$(e);o&&o.getAllModels().forEach((function(e){(function(e,t){var n=d(e,M.Fields,{},!0,!0);return Object.keys(n).filter((function(e){return n[e].referenceDef})).filter((function(e){return!n[e].referenceDef.property})).filter((function(e){return n[e].referenceDef.model===t}))})(e,r).map((function(t){return d(e,"ref_"+t)})).filter(Boolean).forEach((function(e){if(a(e.value)){var o=e.value.findIndex((function(e){return Z(e)===n&&W(e)===r}));-1!==o&&(e.value[o]=t)}else e.value&&Z(e.value)===n&&W(e.value)===r&&(e.value={id:t,type:r})}))}))}(e,t,r,o)}))},exports.view=Te,exports.withActions=Ee,exports.withMeta=je,exports.withPatches=Pe; |
{ | ||
"name": "datx", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "A MobX data store", | ||
@@ -61,5 +61,4 @@ "main": "dist/index.cjs.js", | ||
"dependencies": { | ||
"datx": "2", | ||
"@datx/utils": "^2.0.0" | ||
"datx-utils": "^2.0.0" | ||
} | ||
} |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
168029
1
3132
2
10
+ Addeddatx-utils@^2.0.0
+ Addeddatx-utils@2.0.0(transitive)
- Removed@datx/utils@^2.0.0
- Removeddatx@2
- Removed@datx/utils@2.5.1(transitive)