"use strict";(self.webpackChunk=self.webpackChunk||[]).push([[859],{38290:function(n,t,r){function i(n,t){n||(console.assert(n,"Nerve - "+t),s("assert failed: ".concat(t)))}function e(n){return s("TODO: ".concat(n))}function u(){return s("to be overridden.")}function o(n){if(n="Nerve - warning: ".concat(n),console.warn(n),c){var t=new Error(n).stack;c(t)}}r.d(t,{$8:function(){return s},Lj:function(){return u},R8:function(){return o},dU:function(){return e},vA:function(){return i}});var c=null;function s(n){throw Error("Nerve - "+n)}},86230:function(n,t,r){r.d(t,{b:function(){return u},k:function(){return e}});var i=r(10529),e=function(){return function(n){void 0===n&&(n={}),u(this,n)}}();function u(n,t,r){void 0===r&&(r=!1),(0,i._0)(n,"__nerve__",t,r)}},80974:function(n,t,r){r.d(t,{AH:function(){return h},EY:function(){return w},QN:function(){return a},gu:function(){return l}});var i=r(76654),e=r(38290),u=r(86230),o=r(10529),c="Spec",s=Object.freeze({IsKeyField:!1,IsLocalField:!1,IsNumberTypeInDataSource:!1,IsSourceGenerated:!1});function f(n,t){var r=v();if(i.H.isObjectMasterClass(n))r.masterClassGetter=function(){return n};else{if(!(n instanceof Function))throw Error("The parameter of Spec.fromMasterClass should be a master class of a function.");r.masterClassGetter=n}return d(r,t)}function h(n){var t=n;return t&&t.__nerve__&&t.__nerve__.nerveObjectType===c}function a(n,t){t?Object.keys(t).forEach((function(r){return m(n+r,t[r])})):g(n,"there's no spec passed")}function l(n){return h(n)?n.__nerve__.attributes:s}function v(){return{attributes:s,basicTypeName:null,enumTypeGetter:null,isCollection:!1,isLeaf:!1,keyGetter:null,masterClassGetter:null,nullable:!1,nerveObjectType:c}}function d(n,t){var r={};return b(n,t),(0,u.b)(r,(0,o.yu)(n)),r}function b(n,t){if((t=t||{}).IsKeyField){switch(n.basicTypeName){case"boolean":case"string":case"number":break;default:(0,e.$8)('"isKeyField" only supported for basic type fields')}t.IsLocalField&&(0,e.$8)("a local field can't be key field.")}var r={IsSourceGenerated:!!t.IsSourceGenerated,IsExpandedField:!!t.IsExpandedField,IsKeyField:!!t.IsKeyField,IsLocalField:!!t.IsLocalField,IsNumberTypeInDataSource:!!t.IsNumberTypeInDataSource,SourceFieldName:t.SourceFieldName,IgnoreKeyWithEmptyValue:!!t.IgnoreKeyWithEmptyValue};n.attributes=Object.freeze(r)}function m(n,t){t?h(t)?t.__nerve__.isCollection&&m(n+"[0]",t[0]):a(n,t):g(n,"empty field spec")}function g(n,t){throw Error("Spec error of ".concat(n,": ").concat(t,"."))}function y(n){return function(t,r){return function(n,t,r){var i=v();return i.isLeaf=!0,i.basicTypeName=n,i.keyGetter=r||null,b(i,t),d(i,t)}(n,t,r)}}var w=Object.freeze({create:function(n,t){var r;return b(r=h(n)?(0,o.h2)(n.__nerve__):v(),t),(0,o.C5)(d(r,t),n)},boolean:y("boolean"),number:y("number"),string:y("string"),enumeration:function(n,t){var r=v();return r.isLeaf=!0,r.basicTypeName="enum",r.enumTypeGetter=n,b(r,t),d(r,t)},reference:y("reference"),collectionOf:function(n,t){var r;r=h(n)?n:i.H.isObjectMasterClass(n)||n instanceof Function?f(n):n;var e=v();e.isCollection=!0;var u=d(e,t);return(0,o._0)(u,0,r),u},fromMasterClass:f})},10529:function(n,t,r){r.d(t,{AX:function(){return h},Am:function(){return g},C5:function(){return c},EW:function(){return v},GT:function(){return a},Gk:function(){return l},HU:function(){return d},Ny:function(){return b},Xf:function(){return w},_0:function(){return e},h2:function(){return s},lF:function(){return m},n8:function(){return o},nh:function(){return S},xA:function(){return u},yu:function(){return f},z0:function(){return y}});var i=r(38290);function e(n,t,r,i){void 0===i&&(i=!0),p(n,t,{configurable:!1,enumerable:!!i,value:r,writable:!1})}function u(n,t,r){p(n,t,{configurable:!0,enumerable:!0,get:function(){var i=r();return delete n[t],e(n,t,i),i},set:function(){throw Error("Setting readonly field: ".concat(t))}})}function o(n,t,r,i){p(n,t,{configurable:!1,enumerable:!0,get:r,set:i=i||function(){throw new Error("Setting readonly field: ".concat(t))}})}function c(n,t){var r=n;for(var i in t)r[i]=t[i];return r}function s(n){return c({},n)}function f(n){(0,i.vA)(!Array.isArray(n),"array is not currently supported by readonly().");var t={};for(var r in n)e(t,r,n[r]);return t}function h(n,t){(0,i.vA)(t in n,"the field named ".concat(t," not been initialized yet.")),e(n,t,n[t])}function a(n){return Array.isArray(n)?n:function(n){return n?Array.prototype.slice.apply(n):[]}(n)}function l(n){var t=function(){return Promise.resolve(null)};return n?n.then(t,t):t()}function v(){for(var n=[],t=0;t.Model.*' for the parameter.")}function h(n){return function(n){if(n instanceof a)return n.constructor;(0,e.$8)("the parameter is not a nerve master object.")}(n).__nerve__.masterName}var a=function(n){function t(t){var r=n.call(this)||this,i=r.__nerve__,e=t&&t.Reserved&&t.Reserved.Membership;e&&(i.membership=(0,s.yu)(e),(0,s.AX)(i,"membership"));var u=!1;return(0,s.n8)(i,"deleted",(function(){return u}),(function(n){if(!u&&n){u=!0,i.dirtyChecker.updateDirtiness();var t=i.changeManager;t.startBulkEditMode(),i.markChildrenAsDeleted(),t.markAsDeleted(),t.endBulkEditMode()}})),i.instanceId=(++l).toString(),(0,s.AX)(i,"instanceId"),r}return(0,i.C6)(t,n),Object.defineProperty(t.prototype,"Schema",{get:function(){return(0,e.Lj)()},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Model",{get:function(){return this.__nerve__.model},set:function(n){this.setData(n,this.Schema.__nerve__.subFields.toArray())},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Parent",{get:function(){var n=this.__nerve__.membership;return n&&n.Parent},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Membership",{get:function(){var n=this.__nerve__.membership;return{Parent:n&&n.Parent,FieldSchema:n&&n.FieldSchema}},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Deleted",{get:function(){return this.__nerve__.deleted},set:function(n){this.__nerve__.deleted=n},enumerable:!1,configurable:!0}),t.prototype.getInstanceId=function(){return this.__nerve__.instanceId},t.prototype.getSnapshot=function(n){return this.__nerve__.changeManager.getSnapshot(n)},t.prototype.bulkEdit=function(n){var t=this.__nerve__.changeManager;t&&t.startBulkEditMode();try{return n(this.Model)}finally{t&&t.endBulkEditMode()}},t.prototype.observe=function(n,t){return this.__nerve__.changeManager.observe(n,t)},t.prototype.unobserve=function(n,t){return this.__nerve__.changeManager.unobserve(n,t)},t.prototype.addRule=function(n){return this.__nerve__.changeManager.addRule(n)},t.prototype.removeRule=function(n){return this.__nerve__.changeManager.removeRule(n)},t}(o.k),l=0,v=function(){function n(n){this.C=n,this.P=[],this.M=0,this.N=(0,s.Xf)(),this.D=new s.Ny(this.T.bind(this)),this.A=[],this.initializeSnapshot(),this.resetChangeInfo()}return n.prototype.getSnapshot=function(n){if(!this.R){for(var t in this.K)this.refreshSubSnapshot(this.K[t]);this.K={},this.R=this.createSnapshotCache()}return this.R},n.prototype.definitelyMarkAsChanged=function(n){this.G=!0,this.markAsChanged(n)},n.prototype.markAsChanged=function(n,t){this.U();var r=n.FieldSchema,i=new u([r]);if(this.L.addFieldSchema(r),t){this.V.push(t);var e=t.FieldSchemas.map(r.__nerve__.shadowMapper);i.addFieldSchemas(e)}this.markFieldsAsChanged(i)},n.prototype.markAsDeleted=function(){this.markFieldsAsChanged([this.C.Schema])},n.prototype.startBulkEditMode=function(){++this.M},n.prototype.endBulkEditMode=function(){--this.M<=0&&(this.M=0,this.D.flush())},n.prototype.observe=function(n,t){var r=this.P[this.W(n)];r?t?r.fieldSet.addFieldSchemas(t):r.fieldSet=this._().clone():this.P.push({callback:n,fieldSet:new u(t||this._())})},n.prototype.unobserve=function(n,t){var r=this.W(n),i=this.P[r];i&&(t?t.forEach((function(n){i.fieldSet.removeFieldSchemas(n.__nerve__.allContainedFields)})):i.fieldSet.clear(),0===i.fieldSet.Count&&this.P.splice(r,1))},n.prototype.addRule=function(n){this.A.indexOf(n)<0&&this.A.push(n)},n.prototype.removeRule=function(n){var t=this.A.indexOf(n);t>=0&&this.A.splice(t,1)},n.prototype.markSubSnapshotAsDirty=function(n){var t=this;if(n.length){this.R=void 0,n.forEach((function(n){return t.K[n.Name]=n}));var r=this.Master.__nerve__.membership,i=r&&r.Parent.__nerve__.changeManager;i&&i.markSubSnapshotAsDirty([r.Property])}},n.prototype.getChangingPeriod=function(){return this.N.promise()},Object.defineProperty(n.prototype,"Master",{get:function(){return this.C},enumerable:!1,configurable:!0}),n.prototype.createChange=function(n){var t=this.Master.__nerve__.deleted&&!this.J;return{BeingDeleted:t,DefinitelyMarked:this.G,FieldSchemas:Object.freeze(n.toArray()),Master:this.Master,NewValues:t?null:this.getSnapshot(),OldValues:this.B,SubChanges:Object.freeze(this.V),UpdateNeeded:t}},n.prototype.resetChangeInfo=function(){this.L=new u,this.V=[],this.B=this.getSnapshot(),this.J=this.C.Deleted,this.G=!1},n.prototype.notifyChangeIfNeed=function(){this.M>0?this.D.callOnceLater():this.D.callImmediately()},n.prototype.anythingChanged=function(){return this.L.Count>0||this.Master.__nerve__.deleted},n.prototype.markFieldsAsChanged=function(n,t){var r=this;this.L.addFieldSchemas(n),this.X?this.Y=!0:t?t.then((function(){return r.notifyChangeIfNeed()})):this.notifyChangeIfNeed()},n.prototype.shouldObserverBeNotified=function(n,t){return n.fieldSet.intersect(t.FieldSchemas)},n.prototype.removeUnchangedFields=function(n,t){},n.prototype.W=function(n){for(var t=0;t8*c.A.length)return c.Z(e),"break";var s=c.L,f=c.V;c.L=new u,c.V=[];var h=c.Master.__nerve__.deleted&&!c.J;o.forEach((function(t){n.Y=!1,t.onChange({Master:n.Master,BeingDeleted:h,FieldSchemas:s.toArray(),OldValues:n.B,SubChanges:f}),n.Y&&e.push(t)})),r.addFieldSchemas(c.L),i.push.apply(i,c.V)},c=this;do{if("break"===o())break}while(this.L.Count);this.X=!1,this.L=r,this.V=i},n.prototype.Z=function(n){(0,e.R8)("following rules might do against each other: ".concat(JSON.stringify(n.map((function(n){return n.Name})))," (master: ").concat(h(this.Master),")"))},n.prototype._=function(){return this.Master.Schema.__nerve__.allContainedFields},n.prototype.U=function(){this.N.states()!==s.HU.Pending&&(this.N=new s.z0)},n.prototype.q=function(){this.N.resolve()},n}(),d=function(){function n(n){this.nn=n}return n.prototype.updateDirtiness=function(){if(this.nn){var n=this.getProperty();n.ParentMaster.__nerve__.dirtyChecker.setMemberDirtiness(n.Name,this.isDirty())}},n}(),b=function(n){function t(t,r){var i=n.call(this,r)||this;return i.tn=t,i}return(0,i.C6)(t,n),t.prototype.isDirty=function(){return this.rn!==this.convertModelToSourceData()},t.prototype.initializeSourceData=function(n){this.setSourceData(n)},t.prototype.getDelta=function(){return this.convertModelToSourceData()},t.prototype.getSnapshotToUpdate=function(){return this.convertModelToSourceData()},t.prototype.getSourceData=function(){return this.rn},t.prototype.setSourceData=function(n){void 0===n&&(n=null),this.rn=n,this.updateDirtiness()},t.prototype.onSourceDataReceived=function(n){var t=this.isDirty();this.setSourceData(n),t||this.tn.setter(this.convertFromSourceData(n))},t.prototype.getProperty=function(){return this.tn},t.prototype.convertModelToSourceData=function(){return this.tn.getter()},t.prototype.convertFromSourceData=function(n){return n},t}(d),m=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return(0,i.C6)(t,n),t.prototype.convertModelToSourceData=function(){return this.en(this.getProperty().getter())},t.prototype.convertFromSourceData=function(n){return this.en(n)},t.prototype.en=function(n){return null==n?null:this.getProperty().FieldSchema.__nerve__.enumType[n]},t}(b),g=function(){function n(n,t,r){var i=this;this.un=n,this.on=t;var e=r.Reserved.Membership;this.cn=e.Parent,e.Property=this,this.sn=!1,r.Reserved.Mounted.then((function(){return i.sn=!0}))}return Object.defineProperty(n.prototype,"Name",{get:function(){return this.un},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"FieldSchema",{get:function(){return this.on},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"ParentMaster",{get:function(){return this.cn},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"Index",{get:function(){return this.fn},set:function(n){if(n!==this.fn){var t=this.fn;this.fn=n;var r=this.ParentMaster;this.indexDirtinessUpdateNeeded()&&r.__nerve__.dirtyChecker.updateDirtinessForIndexChange(this),this.Mounted&&r.__nerve__.changeManager.onPropertyIndexChange(this,t)}},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"Mounted",{get:function(){return this.sn},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"Deleted",{get:function(){return this.hn},enumerable:!1,configurable:!0}),Object.defineProperty(n.prototype,"ParentDirtyChecker",{get:function(){return this.ParentMaster.__nerve__.dirtyChecker},enumerable:!1,configurable:!0}),n.prototype.markAsDeleted=function(n){this.hn=!0,this.Index=void 0},n.prototype.getKey=function(){return this.on.__nerve__.getKey(this.getter())},n}(),y=function(n){function t(t,r,i){var e=n.call(this,t,r,i)||this;e.an=e.normalizeValue(i.InitialData);var u=!r.__nerve__.info.Attributes.IsLocalField;return e.ln=e.createDirtyChecker(u),e}return(0,i.C6)(t,n),t.prototype.getter=function(){return this.an},t.prototype.setter=function(n){if(n=this.normalizeValue(n),this.an!==n){this.an=n,this.ln.updateDirtiness();var t=this.ParentMaster.__nerve__.changeManager;t.markSubSnapshotAsDirty([this]),t.markAsChanged(this)}},t.prototype.getDirtyChecker=function(){return this.ln},t.prototype.normalizeValue=function(n){return null==n?null:n},t.prototype.createDirtyChecker=function(n){return new b(this,n)},t.prototype.indexDirtinessUpdateNeeded=function(){return!0},t}(g),w=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return(0,i.C6)(t,n),t.prototype.normalizeValue=function(n){var t=typeof n;if("string"===t||"number"===t){var r=this.FieldSchema.__nerve__.enumType;if(n in r)return"string"===t?r[n]:n}return null},t.prototype.createDirtyChecker=function(n){return new m(this,n)},t}(y),p=r(80974);function S(n){return n.__nerve__.info.IsLeaf}function O(n,t,r,i,e){var u=dn({enumTypeGetter:r.__nerve__.enumTypeGetter,getKeyForReferenceType:r.__nerve__.keyGetter,info:{Attributes:(0,p.gu)(r),FieldId:n,IsLeaf:!0,IsCollection:!1,Name:i,Path:e||i},parentMasterClass:t,parentSchema:t.__nerve__.schema,withDataSource:!1});return u.__nerve__.generateProperty=function(n){return n.__nerve__.asEnum?function(t,r){return new w(t,n,r)}:function(t,r){return new y(t,n,r)}}(u),(0,s.AX)(u.__nerve__,"generateProperty"),u}var j=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return(0,i.C6)(t,n),t.prototype.markAsChanged=function(t,r){r&&r.BeingDeleted?this.Master.deleteItems([t.getter()]):n.prototype.markAsChanged.call(this,t,r)},t.prototype.onPropertiesAdded=function(n,t){n.length&&(this.vn=this.vn.concat(n),this.dn=void 0,this.markSubSnapshotAsDirty(n),this.markFieldsAsChanged(this.Master.Schema.__nerve__.allContainedFields,t))},t.prototype.onPropertiesRemoved=function(n,t){var r=this;n.length&&(n.forEach((function(n){var t=r.vn.indexOf(n);t>=0?r.vn.splice(t,1):r.bn.push(n),r.mn[n.Name]&&(delete r.mn[n.Name],--r.gn)})),this.dn=void 0,this.markSubSnapshotAsDirty(n),this.markFieldsAsChanged(this.Master.Schema.__nerve__.allContainedFields,t))},t.prototype.onPropertyIndexChange=function(n,t){this.markSubSnapshotAsDirty([n]),this.mn[n.Name]?this.mn[n.Name].NewIndex=n.Index:(this.mn[n.Name]={OldIndex:t,NewIndex:n.Index},++this.gn),this.notifyChangeIfNeed()},t.prototype.initializeSnapshot=function(){S(this.Master.Schema[0])?this.yn=t.getSubSnapshotForLeafContent:this.yn=t.getSubSnapshotForMasterContent,this.wn()},t.prototype.refreshSubSnapshot=function(n){this.dn&&!n.Deleted&&(this.dn[n.Index]=this.yn(n.getter()))},t.prototype.createSnapshotCache=function(){return this.dn||this.wn(),this.dn.concat()},t.prototype.createChange=function(t){var r=this,i=n.prototype.createChange.call(this,t),e=function(n){return n.getter()},u=function(n){return r.yn(n)};i.AddedModels=Object.freeze(this.vn.map(e)),i.AddedItemsAsSnapshots=Object.freeze(i.AddedModels.map(u)),i.RemovedModels=Object.freeze(this.bn.map(e)),i.RemovedItemsAsSnapshots=Object.freeze(i.RemovedModels.map(u));var o={};Object.keys(this.mn).forEach((function(n){var t=r.mn[n];null!=t.NewIndex&&null!=t.OldIndex&&(o[t.NewIndex]=t.OldIndex)})),i.ChangedIndexMap=Object.freeze(o);var c=this.Master.Schema[0];return i.UpdateNeeded||c.__nerve__.info.Attributes.IsLocalField||(i.UpdateNeeded=i.AddedModels.length>0||i.RemovedModels.length>0||i.SubChanges.some((function(n){return n.UpdateNeeded}))),i},t.prototype.resetChangeInfo=function(){n.prototype.resetChangeInfo.call(this),this.vn=[],this.bn=[],this.mn={},this.gn=0},t.prototype.anythingChanged=function(){return this.vn.length>0||this.bn.length>0||this.gn>0||n.prototype.anythingChanged.call(this)},t.prototype.shouldObserverBeNotified=function(t,r){return!!Object.keys(r.ChangedIndexMap).length||n.prototype.shouldObserverBeNotified.call(this,t,r)},t.prototype.wn=function(){this.dn=[];for(var n=this.Master.Model,t=0;t=this.__nerve__.properties.length&&(0,e.$8)("Get item out of range. Index: ".concat(t,"; Length: ").concat(this.__nerve__.properties.length)),this.__nerve__.properties[t].getter()}),(function(n){t>=this.__nerve__.properties.length&&(0,e.$8)("Set item out of range. Index: ".concat(t,"; Length: ").concat(this.__nerve__.properties.length)),this.__nerve__.properties[t].setter(n)}))}function D(n,t,r){var i=t.length;if(i>0){var e=n.__nerve__.properties,u=e.length,o=n.__nerve__.master;o.bulkEdit((function(){for(;i>0;--i){for(var c=t[i-1];--u>c.Index;)e[u].Index-=i;e.splice(u,1),c.markAsDeleted(r)}var s=o.Schema[0],f=[n.ensureFieldsReadyPromiseChain];if(s.__nerve__.withKey){var h=n.__nerve__.keyToProperty;if(s.__nerve__.withDataSource){var a=s.__nerve__.keyFields.toArray();t.forEach((function(n){var t=n.Master;f.push(t.Synchronizer.ensureFieldsReady(a).then((function(){return T(h,n)})))}))}t.forEach((function(n){return T(h,n)}))}var l=Promise.all(f);n.ensureFieldsReadyPromiseChain=l,o.__nerve__.dirtyChecker.updateDirtinessForLength(e.length),o.__nerve__.changeManager.onPropertiesRemoved(t,l)}))}}function T(n,t){var r=t.getKey();r&&r in n&&t===n[r]&&delete n[r]}function E(n,t){t&&n.__nerve__.properties.sort(t),n.__nerve__.master.bulkEdit((function(){n.__nerve__.properties.forEach((function(n,t){n.Index=t}))}))}function A(n,t){var r=n.__nerve__.master,i=n.__nerve__.master.Schema[0],e=n.__nerve__.properties,u={};t.map(i.__nerve__.getKey).forEach((function(n,t){return u[n]=t}));var o={};e.forEach((function(n){return o[n.getKey()]=n}));var c={};r.bulkEdit((function(){var r=[];for(var i in u){var e=u[i];if(i in o){var s=o[i];s.setter(t[e]),c[s.Name]=e,delete o[i]}else r.push(e)}var f=[];for(var i in o)f.push(o[i]);f.length&&(f.sort((function(n,t){return n.Index-t.Index})),D(n,f,!1)),r.length&&n.__nerve__.addItems(r.map((function(n){return t[n]})),!1).forEach((function(n,t){return c[n.Name]=r[t]}));var h=function(n,t){return c[n.Name]-c[t.Name]},a=n.__nerve__.propertyComparer;E(n,a?function(n,t){return a(n,t)||h(n,t)}:h)}))}function k(n,t){for(var r=n.__nerve__.master,i={},u=(0,s.GT)(n.__nerve__.master.getSnapshot()).slice(),o=[],c={},f=0;ft.length){var o=n.__nerve__.properties.slice(t.length);D(n,o,!1)}}))}function K(n,t){var r=n.__nerve__.master;r.bulkEdit((function(){var i,e=r.Schema[0].__nerve__,u=n.__nerve__.keyToProperty,o={},c=[];t.map(e.getKeyFromSourceData).forEach((function(n,r){o[n]=r,n in u?u[n].getDirtyChecker().onSourceDataReceived(t[r]):c.push(t[r])})),i=e.withDataSource?function(n){return n.Master.Synchronizer.existingInDataSourcePromiseState()===s.HU.Resolved&&!(n.getKey()in o)}:function(n){return!(n.getKey()in o)};var f=n.__nerve__.properties.filter(i);D(n,f,!0);var h=hn(c,r.Schema);n.__nerve__.addItems(h,!0);var a=n.__nerve__.propertyComparer;a||(a=function(n,t){return o[n.getKey()]-o[t.getKey()]}),E(n,a)}))}function G(n,t){var r=n.__nerve__.master;r.bulkEdit((function(){for(var i=n.length,e=Math.min(i,t.length),u=n.__nerve__.properties,o=0;ot.length){var s=n.__nerve__.properties.slice(t.length);D(n,s,!0)}}))}var U="collection master";var x=function(n){function t(t){var r;t=t||{};var i=r=n.call(this,t)||this,e=r.__nerve__;e.markChildrenAsDeleted=function(){var n;S((n=i).Schema[0])||(0,s.GT)(n.Model).map(f).forEach((function(n){return n.Deleted=!0}))},(0,s.AX)(e,"markChildrenAsDeleted");var u=r.Schema.__nerve__,o=!u.withDataSource&&!u.info.Attributes.IsLocalField;return e.dirtyChecker=new F(i,t.ExistingInDataSource,o),(0,s.AX)(e,"dirtyChecker"),e.model=new C(i,t),(0,s.AX)(e,"model"),e.changeManager=new j(i),(0,s.AX)(e,"changeManager"),r}return(0,i.C6)(t,n),t.prototype.addItems=function(n){return this.Model.__nerve__.addItems(n,!1).map((function(n){return n.getter()}))},t.prototype.deleteItems=function(n){return this.Model.__nerve__.deleteItems(n,!1).map((function(n){return n.getter()}))},t.prototype.itemsAddedInSource=function(n){return this.Model.__nerve__.addItems(n,!0).map((function(n){return n.getter()}))},t.prototype.itemsDeletedInSource=function(n){return this.Model.__nerve__.deleteItems(n,!0).map((function(n){return n.getter()}))},t.prototype.getItemWithKeyFields=function(n){var t=this.Schema[0].__nerve__.getKey(n),r=this.Model.__nerve__.keyToProperty[t];return r&&r.getter()},t.prototype.getIndexWithKeyFields=function(n){var t=this.Schema[0].__nerve__.getKey(n),r=this.Model.__nerve__.keyToProperty[t];return r?r.Index:-1},t.prototype.markAsChanged=function(n){var t=this.Model.__nerve__.properties[n];t&&this.__nerve__.changeManager.definitelyMarkAsChanged(t)},t.prototype.setComparer=function(n){this.Model.__nerve__.setComparer(n)},t.prototype.setData=function(n){this.Model.__nerve__.setData((0,s.GT)(n))},t}(a);var L=function(n){function t(t,r,i){var e=n.call(this,t,r,i)||this,u=r.__nerve__.subMasterClassGetter();return e.C=new u(i),e}return(0,i.C6)(t,n),Object.defineProperty(t.prototype,"Master",{get:function(){return this.C},enumerable:!1,configurable:!0}),t.prototype.getter=function(){return this.C.Model},t.prototype.setter=function(n){this.C.setData(n,this.C.Schema.__nerve__.subFields.toArray())},t.prototype.markAsDeleted=function(t){n.prototype.markAsDeleted.call(this,t),t&&(this.getDirtyChecker().ExistingInSource=!1),this.C.Deleted=!0},t.prototype.getDirtyChecker=function(){return this.C.__nerve__.dirtyChecker},t.prototype.indexDirtinessUpdateNeeded=function(){return!this.FieldSchema.__nerve__.withDataSource},t}(g);function Q(n){return n.__nerve__.info.IsCollection}function z(n,t,r,i,u,o){var c=r.Schema,f=c.__nerve__,h=dn({enumTypeGetter:f.enumTypeGetter,getKeyForReferenceType:f.getKeyForReferenceType,info:{Attributes:o,FieldId:n,IsCollection:f.info.IsCollection,IsLeaf:f.info.IsLeaf,Name:i,Path:u||i},parentMasterClass:t,parentSchema:t.__nerve__.schema,shadowParent:c,shadowRoot:c,subMasterClassGetter:function(){return r},withDataSource:f.withDataSource}),a={};return a[on(r.__nerve__.schema)]=h,h.__nerve__.generateProperty=function(n){return function(t,r){return new L(t,n,r)}}(h),(0,s.AX)(h.__nerve__,"generateProperty"),h.__nerve__.shadowMapper=function(n,t){return function r(i){var u=on(i),o=t[u];if(!o){var c=i.__nerve__.parentSchema;o=(rn(c)?r(c):n)[cn(i)],(0,e.vA)(o===t[u],"the new shadow should be added into the shadow map.")}return o}}(h,a),(0,s.AX)(h.__nerve__,"shadowMapper"),V(h,r.Schema,a),h}function V(n,t,r){Object.keys(t).forEach((function(i){(0,s.xA)(n,i,function(n,t,r,i){return function(){var e=t[r],u=e.__nerve__,o=dn({enumTypeGetter:u.enumTypeGetter,getKeyForReferenceType:u.getKeyForReferenceType,info:{Attributes:u.info.Attributes,FieldId:mn(),IsCollection:u.info.IsCollection,IsLeaf:u.info.IsLeaf,Name:r,Path:bn(n.__nerve__.info.Path,r)},parentSchema:n,parentMasterClass:n.__nerve__.parentMasterClass,shadowParent:e,shadowRoot:u.shadowRoot,subMasterClassGetter:u.subMasterClassGetter,withDataSource:u.withDataSource});return i[on(e)]=o,V(o,e,i),o}}(n,t,i,r))}))}var W={ObjectSynchronizer:void 0},_=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return(0,i.C6)(t,n),t.prototype.getSnapshot=function(t){var r=n.prototype.getSnapshot.call(this,t);if(!t)return r;var i={};return this.Master.Schema.__nerve__.subFields.intersection(t).toArray().map(cn).forEach((function(n){return i[n]=r[n]})),i},t.prototype.initializeSnapshot=function(){var n=this;this.dn={};var t=this.Master,r=t.Schema.__nerve__.subFields.toArray();if(X(t)){var i=t;r=r.filter((function(n){return i.isFieldReady(n)}))}r.forEach((function(t){return n.Pn(t)}))},t.prototype.refreshSubSnapshot=function(n){this.Pn(n.FieldSchema)},t.prototype.createSnapshotCache=function(){return Object.freeze((0,s.h2)(this.dn))},t.prototype.createChange=function(t){var r=n.prototype.createChange.call(this,t);return r.UpdateNeeded||(r.UpdateNeeded=t.toArray().some((function(n){return n.__nerve__.info.IsLeaf&&!n.__nerve__.info.Attributes.IsLocalField}))),r.UpdateNeeded||(r.UpdateNeeded=r.SubChanges.filter((function(n){return n.UpdateNeeded})).some((function(n){var r=n.Master.Membership.FieldSchema;return t.has(r)&&!r.__nerve__.info.Attributes.IsLocalField}))),r},t.prototype.removeUnchangedFields=function(n,t){var r=this,i=this.Master.Schema,e=n.toArray().filter((function(n){if(n.__nerve__.parentSchema===i&&S(n)){var e=cn(n);return r.Master.Model[e]===t[e]}return!1}));n.removeFieldSchemas(e)},t.prototype.Pn=function(n){var t=cn(n),r=this.Master.Model[t];if(S(n))this.dn[t]=r;else{var i=f(r);this.dn[t]=i.getSnapshot()}},t}(v),J=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return(0,i.C6)(t,n),t.prototype.initializeSourceData=function(n){n=this.Mn(n);var t=this.Master.Schema,r=this.Master.Model.__nerve__.properties;for(var i in r){var e=t[i].__nerve__.sourceName;r[i].getDirtyChecker().initializeSourceData(n[e])}},t.prototype.getDelta=function(){var n=this;if(this.isDirty()){var t=this.Master.Schema,r={};return this.getDirtyKeys().sort().forEach((function(i){var e=t[i].__nerve__.sourceName;r[e]=n.Nn(i).getSnapshotToUpdate()})),r}},t.prototype.getSnapshotToUpdate=function(){var n={},t=this.Master.Schema,r=this.Dn();for(var i in r){n[t[i].__nerve__.sourceName]=r[i].getSnapshotToUpdate()}return n},t.prototype.getSourceData=function(){var n={},t=this.Master.Schema,r=this.Dn();for(var i in r){n[t[i].__nerve__.sourceName]=r[i].getSourceData()}return n},t.prototype.setSourceData=function(n){var t=this;n=this.Mn(n),Object.keys(n).forEach((function(r){t.Tn(r).setSourceData(n[r])}))},t.prototype.onSourceDataReceived=function(n){var t,r=this;n=this.Mn(n);var i=this.Master;if(X(i)){t=new s.z0;var e=this.Master.Schema.__nerve__.sourceNameToClientName,u=Object.keys(n).map((function(n){return e[n]})).filter((function(n){return n}));i.Synchronizer.markFieldsAsReady(u,t.promise())}i.bulkEdit((function(){Object.keys(n).forEach((function(t){r.Tn(t).onSourceDataReceived(n[t])}))})),t&&t.resolve()},t.prototype.Mn=function(n){var t=this.Master.Schema.__nerve__.sourceNameToClientName,r={};return n?Object.keys(n).filter((function(n){return n in t})).forEach((function(t){return r[t]=n[t]})):Object.keys(t).forEach((function(n){return r[n]=null})),r},t.prototype.Dn=function(){var n=this.Master.Model.__nerve__.properties,t={};return this.Master.Schema.__nerve__.subFields.toArray().filter((function(n){return!n.__nerve__.info.Attributes.IsLocalField})).map(cn).forEach((function(r){return t[r]=n[r].getDirtyChecker()})),t},t.prototype.Nn=function(n){return this.Master.Model.__nerve__.properties[n].getDirtyChecker()},t.prototype.Tn=function(n){var t=this.Master.Schema.__nerve__.sourceNameToClientName[n];return this.Nn(t)},t}(I),B=function(n){function t(t,r,i,u,o,c){var f,h={};f=n.call(this,{master:t,properties:h})||this;var a=function(n){return X(n)?function(t,r){var i=function(){if(!n.isFieldReady(r)){var t=sn(r);(0,e.$8)("The field (".concat(t,") not ready yet."))}};return{getter:function(){return i(),t.getter()},setter:function(n){i(),t.setter(n)}}}:function(n,t){return{getter:function(){return n.getter()},setter:function(t){return n.setter(t)}}}}(t);return Object.keys(t.Schema).forEach((function(n){var e=t.Schema[n],l=e.__nerve__.generateProperty(n,{InitialData:r[n],ExistingInDataSource:i,MasterTreeReady:o,Reserved:{Membership:{FieldSchema:e,Parent:t},ParentExistingInDataSource:c,Mounted:u}});h[n]=l;var v=a(l,e);(0,s.n8)(f,n,v.getter,v.setter)})),f}return(0,i.C6)(t,n),t}(c);var H="object master";function X(n){return n instanceof q}function Y(n,t,r){(0,p.QN)(n,t);var e=function(n){function t(t,i){return n.call(this,t,i,r)||this}return(0,i.C6)(t,n),Object.defineProperty(t,"Schema",{get:function(){return t.__nerve__.schema},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Schema",{get:function(){return t.__nerve__.schema},enumerable:!1,configurable:!0}),t}(r?q:$);return(0,o.b)(e,(0,s.yu)({nerveObjectType:H,masterName:n,dataSourceFactory:r}),!0),e.__nerve__.schema=vn(e,t),(0,s.AX)(e.__nerve__,"schema"),e}var $=function(n){function t(t,r,i){var e;t=t||{},r=r||{};var u=(e=n.call(this,t)||this).__nerve__;u.markChildrenAsDeleted=function(){var n;(n=e).Schema.__nerve__.subFields.toArray().filter((function(n){return!S(n)})).map(cn).map((function(t){return n.Model.__nerve__.properties[t]})).map((function(n){return n.Master})).forEach((function(n){return n.Deleted=!0}))},(0,s.AX)(u,"markChildrenAsDeleted");var o,c=new s.z0,f=(0,s.nh)(r.MasterReady,c.promise()),h=!i&&u.membership&&!u.membership.FieldSchema.__nerve__.info.Attributes.IsLocalField;if(u.dirtyChecker=new J(e,t.ExistingInDataSource,h),(0,s.AX)(u,"dirtyChecker"),i?(u.synchronizer=new W.ObjectSynchronizer(e,t,r,f,i),o=u.synchronizer.existingInDataSource()):(u.synchronizer=null,o=t.Reserved&&t.Reserved.ParentExistingInDataSource),(0,s.AX)(u,"synchronizer"),u.model=new B(e,t.InitialData||{},t.ExistingInDataSource,f,(0,s.nh)(t.MasterTreeReady,f).then((function(){})),o),(0,s.AX)(u,"model"),u.changeManager=new _(e),(0,s.AX)(u,"changeManager"),i){var a=an(t.ExistingInDataSource?t.InitialData:null,e.Schema);u.dirtyChecker.initializeSourceData(a)}return c.resolve(),e}return(0,i.C6)(t,n),t.prototype.setData=function(n,t){var r=this.Model;if(n!==r){var i;if(n=n||{},t)i=Z(this,t);else{var u=this.Schema;i=Object.keys(n).map((function(n){return u[n]})).filter((function(n){return n}))}var o=[];this.bulkEdit((function(){i.map(cn).forEach((function(t){t in r?r[t]=n[t]:o.push(t)}))})),o.length&&(0,e.R8)("following field(s) not found in ".concat(h(this),": ").concat(o))}},t.prototype.getModelByFieldSchema=function(n){var t=n;en(t),t=nn(this,t);for(var r=this.Schema,i=[];t!==r;){if(i.push(t),t.__nerve__.info.IsCollection)throw Error("unable to get model/value from collection ".concat(sn(t),"."));t=t.__nerve__.parentSchema}var e=this.Model;do{e=e[cn(t=i.pop())]}while(i.length);return e},t}(a),q=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return(0,i.C6)(t,n),Object.defineProperty(t.prototype,"Synchronizer",{get:function(){return this.__nerve__.synchronizer},enumerable:!1,configurable:!0}),t.prototype.isFieldReady=function(n){return this.Synchronizer.isFieldReady(n)},t.prototype.ensureFieldsReady=function(n){return this.Synchronizer.ensureFieldsReady(n)},t.prototype.fieldsReady=function(n){return this.Synchronizer.fieldsReady(n)},t.prototype.getRelatedSourceFields=function(n){return n},t.prototype.forceFieldsReady=function(n){return this.Synchronizer.forceFieldsReady(n)},t}($);function Z(n,t){return t.map((function(t){var r=n.Schema;if("string"==typeof t){var i=r[t];if(rn(i))return i}else if(rn(t))return nn(n,t);(0,e.$8)("field ".concat(t," doesn't exist in master ").concat(h(n)))}))}function nn(n,t){for(var r=n.Schema,i=[];t.__nerve__.shadowRoot!==r;){var u=cn(t);i.push(u),(t=t.__nerve__.parentSchema)||(0,e.$8)("field schema (".concat(sn(t),") is not a member schema of master (").concat(h(n),")"))}for(var o=r;i.length;){o=o[u=i.pop()]}return o}var tn="FieldSchema";function rn(n){var t=n&&n.__nerve__;return t&&t.nerveObjectType===tn}function en(n){if(!rn(n))throw Error("Invalid parameter: please use '.Schema.*' for the parameter.");return!0}function un(n){return en(n),n.__nerve__.info}function on(n){return un(n).FieldId}function cn(n){return un(n).Name}function sn(n){return un(n).Path}function fn(n){return yn[n]}function hn(n,t){if(S(t)){if(t.__nerve__.asEnum){var r=t.__nerve__.enumType;if(r&&"string"==typeof n&&n in r)return r[n]}return n}if(Q(t))return(0,s.GT)(n).map((function(n){return hn(n,t[0])}));if(n){var i={},e=t.__nerve__.sourceNameToClientName;return Object.keys(n).forEach((function(r){if(r in e){var u=e[r],o=t[u];i[u]=hn(n[r],o)}})),i}return null}function an(n,t){if(S(t)){if(t.__nerve__.asEnum){var r=t.__nerve__.enumType;if(r&&"number"==typeof n&&n in r)return r[n]}return n}if(Q(t))return(0,s.GT)(n).map((function(n){return an(n,t[0])}));if(n){var i={};return Object.keys(t).forEach((function(r){if(r in n){var e=t[r];if(!e.__nerve__.info.Attributes.IsLocalField){var u=e.__nerve__.sourceName;i[u]=an(n[r],e)}}})),i}return null}function ln(n,t){if(S(t))return n;if(Q(t))return(0,s.GT)(n).map((function(n){return ln(n,t[0])}));if(n){var r={},i=t.__nerve__.sourceNameToClientName;return Object.keys(n).forEach((function(e){if(e in i){var u=t[i[e]];r[e]=ln(n[e],u)}})),r}return null}function vn(n,t){var r=n.__nerve__.masterName,e={enumTypeGetter:null,getKeyForReferenceType:null,info:{Attributes:(0,p.gu)(t),FieldId:mn(),IsCollection:!(!(0,p.AH)(t)||!t.__nerve__.isCollection),IsLeaf:!1,Name:r,Path:r},parentMasterClass:n,shadowParent:null,withDataSource:!!n.__nerve__.dataSourceFactory};e.info.IsCollection&&(0,s.xA)(e,"withDataSource",(function(){return u[0].__nerve__.withDataSource}));var u=dn(e);return Object.keys(t).forEach((function(r){(0,s.xA)(u,r,function(n,t,r){var e=mn();return function(){var u,c=bn(n.__nerve__.masterName,t);if((0,p.AH)(r)){if(r.__nerve__.isLeaf)return O(e,n,r,t,c);r.__nerve__.isCollection?u=function(n,t){var r=function(n){function t(){return null!==n&&n.apply(this,arguments)||this}return(0,i.C6)(t,n),Object.defineProperty(t,"Schema",{get:function(){return t.__nerve__.schema},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"Schema",{get:function(){return t.__nerve__.schema},enumerable:!1,configurable:!0}),t}(x);return(0,o.b)(r,(0,s.yu)({nerveObjectType:U,masterName:n}),!0),r.__nerve__.schema=vn(r,t),(0,s.AX)(r.__nerve__,"schema"),r}(c,r):r.__nerve__.masterClassGetter&&(u=r.__nerve__.masterClassGetter())}u||(u=Y(c,r));var f=(0,p.gu)(r);return z(e,n,u,t,c,f)}}(n,r,t[r]))})),u}function dn(n){var t={};return n.info=(0,s.yu)(n.info),n.nerveObjectType=tn,n.shadowParent=n.shadowParent||null,n.shadowRoot=n.shadowRoot||t,(0,s.xA)(n,"sourceFieldSet",(function(){var t=n.subFields.toArray().filter((function(n){return!n.__nerve__.info.Attributes.IsLocalField}));return new u(t)})),(0,s.xA)(n,"sourceName",(function(){return n.info.Attributes.SourceFieldName||n.info.Name})),(0,s.xA)(n,"sourceNameToClientName",(function(){var t={};return n.sourceFieldSet.toArray().forEach((function(n){t[n.__nerve__.sourceName]=n.__nerve__.info.Name})),Object.freeze(t)})),(0,s.xA)(n,"subFields",(function(){var n=new u;return Object.keys(t).forEach((function(r){n.addFieldSchema(t[r])})),n})),(0,s.xA)(n,"allContainedFields",(function(){var n=new u([t]);return Object.keys(t).forEach((function(r){var i=t[r];n.addFieldSchemas(i.__nerve__.allContainedFields)})),n})),(0,s.xA)(n,"asEnum",(function(){return!!n.enumType&&!n.info.Attributes.IsNumberTypeInDataSource})),(0,s.xA)(n,"enumType",(function(){return n.enumTypeGetter&&n.enumTypeGetter()})),n.info.IsLeaf?(0,s.xA)(n,"getKey",(function(){return(0,e.vA)(n.getKeyForReferenceType,"getKey has been called but no keyGetter specified for ".concat(n.info.Path)),n.getKeyForReferenceType})):(0,s.xA)(n,"getKey",(function(){var t=n.keyFields.toArray().map(cn).sort();return(0,e.vA)(t.length>0,"getKey has been called but there's no key fields of ".concat(n.info.Path)),function(n){var r=t;if(n instanceof B){var i=n.__nerve__.master;if(X(i)){var e=i;if(!(r=t.filter((function(n){return e.isFieldReady(n)}))).length)return}}var u={};return r.forEach((function(t){return u[t]=n[t]})),JSON.stringify(u)}})),(0,s.xA)(n,"getKeyFromSourceData",(function(){var t=n.keyFields.toArray(),r=n.sourceNameToClientName,i=t.map((function(n){return n.__nerve__.sourceName}));return function(t){var e={};return i.forEach((function(n){var i=r[n];e[i]=t[n]})),n.getKey(e)}})),(0,s.xA)(n,"keyFields",(function(){return new u(n.subFields.toArray().filter((function(n){return n.__nerve__.info.Attributes.IsKeyField})))})),(0,s.xA)(n,"ignoreKeyWithEmptyValueFields",(function(){return new u(n.subFields.toArray().filter((function(n){return n.__nerve__.info.Attributes.IgnoreKeyWithEmptyValue}))).toArray().reduce((function(n,t){var r={};return r[t.__nerve__.sourceName]=null,n[JSON.stringify(r)]=!0,n}),{})})),n.info.IsLeaf?(0,s.xA)(n,"withKey",(function(){return!!n.getKeyForReferenceType})):(0,s.xA)(n,"withKey",(function(){return n.keyFields.Count>0})),(0,o.b)(t,n),(0,s._0)(t,"toJSON",(function(){return"[Nerve] FieldSchema: (".concat(n.info.Path,")>")}),!1),n.info.IsCollection&&(0,s._0)(t,"length",1,!1),yn[n.info.FieldId]=t,t}function bn(n,t){return"".concat(n,"/").concat(t)}function mn(){return(gn++).toString()}var gn=1,yn={},wn=function(n){function t(){var t=n.call(this,{InitialData:{InProcess:!1,AllSucceeded:!0,Scheduled:!1,CreationError:null,CreationFailed:!1,CreationInProcess:!1,CreationRetryScheduled:!1,CreationScheduled:!1,QueryError:null,QueryFailed:!1,QueryInProcess:!1,UpdateError:null,UpdateFailed:!1,UpdateInProcess:!1,UpdateRetryScheduled:!1,UpdateScheduled:!1}})||this;return t.addRule(pn),t.addRule(Sn),t.addRule(On),t}return(0,i.C6)(t,n),t}(Y("Nerve.ObjectSynchronizerMaster",{InProcess:p.EY.boolean(),AllSucceeded:p.EY.boolean(),Scheduled:p.EY.boolean(),CreationError:p.EY.reference(),CreationFailed:p.EY.boolean(),CreationInProcess:p.EY.boolean(),CreationScheduled:p.EY.boolean(),CreationRetryScheduled:p.EY.boolean(),QueryError:p.EY.reference(),QueryFailed:p.EY.boolean(),QueryInProcess:p.EY.boolean(),UpdateError:p.EY.reference(),UpdateFailed:p.EY.boolean(),UpdateInProcess:p.EY.boolean(),UpdateRetryScheduled:p.EY.boolean(),UpdateScheduled:p.EY.boolean()})),pn={Name:"InProcess",InterestedFields:[wn.Schema.CreationInProcess,wn.Schema.QueryInProcess,wn.Schema.UpdateInProcess],onChange:function(n){var t=n.Master.Model;t.InProcess=t.CreationInProcess||t.QueryInProcess||t.UpdateInProcess}},Sn={Name:"AllSucceeded",InterestedFields:[wn.Schema.CreationFailed,wn.Schema.QueryFailed,wn.Schema.UpdateFailed],onChange:function(n){var t=n.Master.Model;t.AllSucceeded=!(t.CreationFailed||t.QueryFailed||t.UpdateFailed)}},On={Name:"Scheduled",InterestedFields:[wn.Schema.CreationScheduled,wn.Schema.CreationRetryScheduled,wn.Schema.UpdateScheduled,wn.Schema.UpdateRetryScheduled],onChange:function(n){var t=n.Master.Model;t.Scheduled=t.CreationScheduled||t.CreationRetryScheduled||t.UpdateScheduled||t.UpdateRetryScheduled}},jn=function(){function n(n){n?(this.En=new In({retry:n.retryForCreation&&n.retryForCreation.bind(n),cancel:n.cancelRetryForCreation&&n.cancelRetryForCreation.bind(n)}),this.An=new In({retry:n.retryForUpdate&&n.retryForUpdate.bind(n),cancel:n.cancelRetryForUpdate&&n.cancelRetryForUpdate.bind(n)})):(this.En=new In,this.An=new In),this.kn=n||{}}return n.prototype.scheduleUpdate=function(){return this.Rn?(this.kn.postponeUpdate&&this.kn.postponeUpdate(),this.Rn.promise()):this.Kn()},n.prototype.postponeUpdate=function(){this.kn.postponeUpdate&&this.kn.postponeUpdate()},n.prototype.flush=function(){this.En.flush(),this.An.flush(),this.Gn&&(this.Gn.cancel(),this.Gn=void 0,this.kn.cancelUpdate&&this.kn.cancelUpdate()),this.Rn&&(this.Rn.resolve(),this.Rn=void 0)},n.prototype.cancelUpdate=function(){this.Rn&&(this.Rn.reject(),this.Rn=void 0,this.kn.cancelUpdate&&this.kn.cancelUpdate())},n.prototype.retryForCreation=function(n){return this.En.retry(n)},n.prototype.cancelRetryForCreation=function(){return this.En.cancel()},n.prototype.retryForUpdate=function(n){return this.An.retry(n)},n.prototype.cancelRetryForUpdate=function(){return this.An.cancel()},n.prototype.Kn=function(){var n=this;this.Rn||(this.Rn=new s.z0);var t,r=this.Rn;return t=this.kn.scheduleUpdate?this.kn.scheduleUpdate():Promise.resolve(),this.Gn=new s.lF(t),this.Gn.promise().finally((function(){n.Rn=void 0,n.Gn=void 0})).then((function(){r.resolve()}),(function(){r.reject(new Error("this.cancelableUpdateSchedule rejected."))})),r.promise()},n}(),In=function(){function n(n){this.kn=n||{}}return n.prototype.retry=function(n){var t=this;return this.kn.retry?(this.cancel(),this.Un=new s.lF(this.kn.retry(n)),this.xn=new Promise((function(n,r){t.Ln=n,t.Qn=r})),this.Un.promise().finally((function(){t.xn=void 0,t.Un=void 0})).then(this.Ln,this.Qn),this.xn):Promise.reject("Scheduler has no retry.")},n.prototype.flush=function(){this.Un&&(this.Un.cancel(),this.Un=void 0,this.kn.cancel&&this.kn.cancel()),this.xn&&(this.xn=void 0,this.Ln())},n.prototype.cancel=function(){this.Un&&(this.Un.cancel(),this.xn=void 0,this.Un=void 0,this.kn.cancel&&this.kn.cancel())},n}(),Fn=function(n){function t(t,r,i,e,u){var o=n.call(this)||this;o.zn=new s.z0,o.Vn=new s.z0,o.Wn={},o._n={},o.Jn={},o.Bn=Promise.resolve(),o.Hn=0,o.Xn=[],o.C=t,o.kn=new jn(i.Scheduler),o.Yn();var c=r.Reserved&&r.Reserved.ParentExistingInDataSource;o.$n=(0,s.nh)(r.MasterTreeReady,e,c).then((function(){return u(t,(function(n){return o.onSourceDataReceived(n)}),i.DataSourceContext)}));var f=o.qn(r);if(f.length){var h=(0,s.Xf)();f.forEach((function(n){o.Wn[n]=!0,o._n[n]=h}))}return e.then((function(){t.observe((function(n){n.UpdateNeeded&&o.Zn()}))})),!r.ExistingInDataSource?o.nt():(o.tt=new s.Am(e),e.then((function(){return o.Zn()}))),o}return(0,i.C6)(t,n),t.prototype.flush=function(){var n=this;return this.kn.flush(),this.tt.promise().then((function(){return n.Vn.promise()}))},t.prototype.existingInDataSource=function(){return this.tt.promise()},t.prototype.existingInDataSourcePromiseState=function(){return this.tt.states()},t.prototype.deletedFromDataSource=function(){var n=this;return this.tt.promise().then((function(){return n.zn.promise()}),(function(){return Promise.resolve()}))},t.prototype.isFieldReady=function(n){n=this.C.getRelatedSourceFields([n])[0];var t=cn(Z(this.C,[n])[0]);return!!this.Wn[t]},t.prototype.ensureFieldsReady=function(n){var t=this;n=this.C.getRelatedSourceFields(n);var r=Z(this.C,n);return r.filter((function(n){return!t.isFieldReady(n)})).length?this.tt.promise().then((function(){var n=r.filter((function(n){return!t.isFieldReady(n)}));if(n.length)return t.query(n)})).then((function(){return t.rt()})):Promise.resolve()},t.prototype.forceFieldsReady=function(n){var t=this;n=this.C.getRelatedSourceFields(n),Z(this.C,n).filter((function(n){return!t.isFieldReady(n)})).forEach((function(n){t.Wn[cn(n)]=!0}))},t.prototype.fieldsReady=function(n){var t=this;n=this.C.getRelatedSourceFields(n);var r=Z(this.C,n).map(cn).map((function(n){return t._n[n]||(t._n[n]=new s.z0),t._n[n].promise()}));return Promise.all(r).then((function(){return t.rt()}))},t.prototype.query=function(n){var t=this;n=this.C.getRelatedSourceFields(n);var r=Z(this.C,n);return this.tt.promise().then((function(){var n=[],i=new s.z0,e=new s.Am(i.promise().then((function(){return t.it(n)}))),u=[];return r.filter((function(n){return!n.__nerve__.info.Attributes.IsLocalField})).forEach((function(r){var i=cn(r),o=t.Jn[i];o&&o.states()===s.HU.Pending||(t.Jn[i]=e,n.push(r.__nerve__.sourceName)),u.push(t.Jn[i].promise())})),n.length?i.resolve():i.reject(new Error("FieldNamesToQuery is empty.")),Promise.all(u)})).then((function(){return t.rt()}))},t.prototype.onSourceDataReceived=function(n){var t=this,r=ln(n,this.C.Schema);return this.Xn.push(r),this.Bn.then((function(){return t.et()}))},t.prototype.onDeletedInDataSource=function(){this.ut().ExistingInSource=!1,this.C.Deleted=!0},t.prototype.setFieldsQueryJob=function(n,t){var r=this,i=Z(this.C,this.C.getRelatedSourceFields(n)).filter((function(n){return!n.__nerve__.info.Attributes.IsLocalField})),e=new s.z0,u=e.promise().then((function(){return t})).then((function(n){var t={};return i.map((function(n){return n.__nerve__.sourceName})).forEach((function(r){return t[r]=n[r]})),r.onSourceDataReceived(t)}));i.map(cn).forEach((function(n){var t=r.Jn[n];t&&t.states()===s.HU.Pending?r.Jn[n]=new s.Am((0,s.EW)(t.promise(),u)):r.Jn[n]=new s.Am(u)})),e.resolve()},t.prototype.markFieldsAsReady=function(n,t){var r=this;n.forEach((function(n){return r.Wn[n]=!0})),t.then((function(){var t=(0,s.Xf)();n.forEach((function(n){r._n[n]?r._n[n].resolve():r._n[n]=t}))}))},t.prototype.Yn=function(){var n=this;this.Vn=(0,s.Xf)(),this.observe((function(){return n.ot()}),[this.Schema.UpdateError,this.Schema.UpdateFailed,this.Schema.UpdateInProcess,this.Schema.UpdateScheduled])},t.prototype.ot=function(){var n=this.Model;n.UpdateScheduled||n.UpdateInProcess?this.Vn.states()!==s.HU.Pending&&(this.Vn=new s.z0):n.UpdateFailed?n.UpdateRetryScheduled||this.Vn.reject(n.UpdateError):this.Vn.resolve()},t.prototype.qn=function(n){var t=this.C.Schema.__nerve__.subFields;if(n.ExistingInDataSource){var r=n.InitialData||{},i=[];return t.toArray().forEach((function(n){var t=cn(n);(n.__nerve__.info.Attributes.IsLocalField||t in r)&&i.push(t)})),i}return t.toArray().filter((function(n){return!n.__nerve__.info.Attributes.IsSourceGenerated})).map(cn)},t.prototype.Zn=function(){var n=this;this.ut().isDirty()?(this.bulkEdit((function(){n.Model.UpdateScheduled=!0})),(0,s.nh)(this.tt.promise(),this.kn.scheduleUpdate()).then((function(){n.Hn=0,n.ct()}),(function(){}))):(this.kn.cancelUpdate(),this.Model.UpdateScheduled=!1)},t.prototype.ct=function(){if(this.st)this.ft=!0;else if(this.ut().isDirty()){if(this.ht(),this.ut().isDirty())return this.C.__nerve__.deleted?this.lt():this.vt();(0,e.R8)("onUpdateStart changes dirtiness."),this.dt()}else this.dt()},t.prototype.ut=function(){return this.C.__nerve__.dirtyChecker},t.prototype.nt=function(){var n=this,t=this.C,r=new Promise((function(r,i){n.bulkEdit((function(){n.Model.CreationScheduled=!0,n.$n.then((function(e){var u=function(){if(n.kn.cancelRetryForCreation(),t.__nerve__.deleted)return n.bulkEdit((function(){n.Model.CreationFailed=!1,n.Model.CreationInProcess=!1,n.Model.CreationRetryScheduled=!1,n.Model.CreationScheduled=!1}));n.bulkEdit((function(){n.Model.CreationError=null,n.Model.CreationFailed=!1,n.Model.CreationInProcess=!0,n.Model.CreationRetryScheduled=!1,n.Model.CreationScheduled=!1}));var c=n.ut(),s=c.getDelta()||{},f=c.getSnapshotToUpdate(),h=n.Bn.then((function(){return e.add(s,{Master:t,Snapshot:f})})).then((function(i){t.bulkEdit((function(){c.ExistingInSource=!0,c.setSourceData(s),i&&n.bt(i)})),n.bulkEdit((function(){n.Model.CreationInProcess=!1,n.Zn()})),r()})).catch((function(t){n.bulkEdit((function(){n.Model.CreationFailed=!0,n.Model.CreationError=t,n.Model.CreationInProcess=!1,n.Model.CreationRetryScheduled=!0,n.kn.retryForCreation(++o).then(u).catch((function(){n.Model.CreationRetryScheduled=!1,i(t)}))}))}));n.gt(h)},o=0;u()}))}))}));this.tt=new s.Am(r)},t.prototype.lt=function(){var n=this,t=this.ut(),r=this.Bn.then((function(){return n.$n})).then((function(r){var i=t.getSnapshotToUpdate();return r.delete(i,{Master:n.C,Snapshot:i})})).then((function(){return t.ExistingInSource=!1}));return this.gt(r),r.then((function(t){return n.dt(!1),n.zn.resolve(),t})).catch((function(t){throw n.yt(t,!1,(function(){n.zn.reject(t)})),t}))},t.prototype.it=function(n){var t=this,r=this.Bn.then((function(){return t.$n})).then((function(r){return t.bulkEdit((function(){t.Model.QueryError=null,t.Model.QueryInProcess=!0})),r.query(n,{Master:t.C,Snapshot:null})})).then((function(r){if(r){var i={};Object.keys(r).concat(n).forEach((function(n){return i[n]=r[n]})),t.bt(i)}}));return this.gt(r),r.then((function(){t.Model.QueryInProcess=!1})).catch((function(n){throw t.bulkEdit((function(){t.Model.QueryError=n,t.Model.QueryInProcess=!1})),n}))},t.prototype.vt=function(){var n=this,t=this.ut(),r=t.getDelta(),i=t.getSnapshotToUpdate(),u=t.getSourceData();null==r&&(0,e.R8)("data is null when it's dirty.");var o=this.Bn.then((function(){return n.$n})).then((function(t){return t.update(r,{Master:n.C,Snapshot:i,ValuesBefore:u})})).then((function(i){n.C.bulkEdit((function(){t.setSourceData(r),i&&n.bt(i)}))}));return this.gt(o),o.then((function(){return n.dt(!0)})).catch((function(t){throw n.yt(t,!0),t}))},t.prototype.ht=function(){var n=this;this.st=!0,this.ft=!1,this.kn.cancelRetryForUpdate(),this.bulkEdit((function(){n.Model.UpdateError=null,n.Model.UpdateFailed=!1,n.Model.UpdateInProcess=!0,n.Model.UpdateRetryScheduled=!1,n.Model.UpdateScheduled=!1}))},t.prototype.dt=function(n){var t=this;this.st=!1,this.Hn=0,this.kn.cancelRetryForUpdate(),this.bulkEdit((function(){t.Model.UpdateError=null,t.Model.UpdateFailed=!1,t.Model.UpdateInProcess=!1,t.Model.UpdateRetryScheduled=!1,t.Model.UpdateScheduled=!1,n&&(t.ft?t.ct():t.Zn())}))},t.prototype.yt=function(n,t,r){var i=this;this.ut().isDirty()?(this.st=!1,this.bulkEdit((function(){i.Model.UpdateError=n,i.Model.UpdateFailed=!0,i.Model.UpdateInProcess=!1,i.Model.UpdateRetryScheduled=!0,i.Model.UpdateScheduled=!0,t&&i.ft?i.ct():i.kn.retryForUpdate(++i.Hn).then((function(){return i.ct()})).catch((function(){i.bulkEdit((function(){i.Model.UpdateRetryScheduled=!1,i.Model.UpdateScheduled=!1})),r&&r()}))}))):this.dt()},t.prototype.bt=function(n){var t=ln(n,this.C.Schema);this.ut().onSourceDataReceived(t)},t.prototype.gt=function(n){var t=this;this.Bn=(0,s.Gk)(n).then((function(){return t.et()}))},t.prototype.et=function(){var n=this.ut(),t=this.Xn;this.Xn=[],this.C.bulkEdit((function(){t.forEach((function(t){return n.onSourceDataReceived(t)}))}))},t.prototype.rt=function(){return this.C.__nerve__.changeManager.getChangingPeriod()},t}(wn);W.ObjectSynchronizer=Fn;var Cn=function(){function n(){}return n.getSubFieldSchemas=function(n){return function(n){return en(n),n.__nerve__.subFields.toArray()}(n)},n.convertFromSourceData=function(n,t){return hn(n,t)},n.convertToSourceData=function(n,t){return an(n,t)},n.convertToArray=function(n){return(0,s.GT)(n)},n.getFieldSchemaInfo=function(n){return un(n)},n.getObjectMasterFromModel=function(n){return f(n)},n.getCollectionMasterFromModel=function(n){return f(n)},n.createObjectMasterClass=function(n,t,r){return Y(n,t,r)},n.isObjectMasterClass=function(n){return function(n){var t=n;return!!t.__nerve__&&t.__nerve__.nerveObjectType===H}(n)},n}();(0,s.AX)(Cn,"convertToArray"),(0,s.AX)(Cn,"getFieldSchemaInfo"),(0,s.AX)(Cn,"getSubFieldSchemas"),(0,s.AX)(Cn,"convertFromSourceData"),(0,s.AX)(Cn,"convertToSourceData"),(0,s.AX)(Cn,"createObjectMasterClass"),(0,s.AX)(Cn,"getObjectMasterFromModel"),(0,s.AX)(Cn,"getCollectionMasterFromModel"),(0,s.AX)(Cn,"isObjectMasterClass");var Pn={addItems:null,deleteItems:null,getIndexWithKeyFields:null,getItemWithKeyFields:null,itemsAddedInSource:null,itemsDeletedInSource:null,markAsChanged:null,setComparer:null};for(var Mn in Pn)Pn[Mn]=Nn(Mn);function Nn(n){return function(t){for(var r=[],i=1;i